Browse Source

Adding Cecil 0.6 library

pull/1/head^2
David Srbecký 18 years ago
parent
commit
534b155fd7
  1. 1
      lib/cecil-0.6/src/Mono.Cecil.Mdb/AUTHORS
  2. 23
      lib/cecil-0.6/src/Mono.Cecil.Mdb/ChangeLog
  3. 12
      lib/cecil-0.6/src/Mono.Cecil.Mdb/Makefile
  4. 61
      lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb.csproj
  5. 8
      lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources
  6. 43
      lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs
  7. 49
      lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbFactory.cs
  8. 152
      lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs
  9. 179
      lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs
  10. 2
      lib/cecil-0.6/src/Mono.Cecil.Mdb/README
  11. 31
      lib/cecil-0.6/src/Mono.Cecil.Pdb/ChangeLog
  12. 61
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb.csproj
  13. 43
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/AssemblyInfo.cs
  14. 56
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/IMetadataDispenser.cs
  15. 43
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/IMetadataImport.cs
  16. 46
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbFactory.cs
  17. 130
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbHelper.cs
  18. 148
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbReader.cs
  19. 202
      lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbWriter.cs
  20. 49
      lib/cecil-0.6/src/Mono.Cecil.Pdb/default.build
  21. 1
      lib/cecil-0.6/src/Mono.Cecil/AUTHORS
  22. 3617
      lib/cecil-0.6/src/Mono.Cecil/ChangeLog
  23. 226
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-attributes.rb
  24. 14
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-sources.rb
  25. 61
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-tests.rb
  26. 262
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-types.rb
  27. 161
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen.rb
  28. 159
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-mig.rb
  29. 608
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil.xml
  30. 112
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/BaseMetadataVisitor.cs
  31. 37
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Code.cs
  32. 38
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/CodedIndex.cs
  33. 65
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/IMetadataVisitor.cs
  34. 296
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/IndexedCollection.cs
  35. 110
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataRowReader.cs
  36. 145
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataRowWriter.cs
  37. 97
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataTableReader.cs
  38. 98
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataTableWriter.cs
  39. 232
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/NamedCollection.cs
  40. 67
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/OpCodes.cs
  41. 81
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Table.cs
  42. 116
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Tests.cs
  43. 211
      lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Utilities.cs
  44. 12
      lib/cecil-0.6/src/Mono.Cecil/Makefile
  45. 101
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/BaseImageVisitor.cs
  46. 68
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/CLIHeader.cs
  47. 119
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/CopyImageVisitor.cs
  48. 75
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DOSHeader.cs
  49. 87
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DataDirectory.cs
  50. 73
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DebugHeader.cs
  51. 45
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DebugStoreType.cs
  52. 59
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ExportTable.cs
  53. 35
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitable.cs
  54. 51
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitor.cs
  55. 34
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/IHeader.cs
  56. 236
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/Image.cs
  57. 57
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageCharacteristics.cs
  58. 53
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageFormatException.cs
  59. 139
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageInitializer.cs
  60. 466
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageReader.cs
  61. 427
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageWriter.cs
  62. 98
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/Imports.cs
  63. 70
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/MemoryBinaryWriter.cs
  64. 58
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/PEFileHeader.cs
  65. 200
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/PEOptionalHeader.cs
  66. 115
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/RVA.cs
  67. 48
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDataEntry.cs
  68. 66
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryEntry.cs
  69. 45
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryString.cs
  70. 56
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryTable.cs
  71. 44
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceNode.cs
  72. 143
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceReader.cs
  73. 216
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceWriter.cs
  74. 37
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/RuntimeImage.cs
  75. 66
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/Section.cs
  76. 70
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/SectionCharacteristics.cs
  77. 114
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/SectionCollection.cs
  78. 45
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/SubSystem.cs
  79. 73
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/BaseCodeVisitor.cs
  80. 357
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/CilWorker.cs
  81. 255
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/Code.cs
  82. 355
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs
  83. 528
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs
  84. 78
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/Document.cs
  85. 36
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentHashAlgorithm.cs
  86. 45
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguage.cs
  87. 35
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguageVendor.cs
  88. 35
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs
  89. 95
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs
  90. 93
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerCollection.cs
  91. 37
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerType.cs
  92. 42
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/FlowControl.cs
  93. 91
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/GuidAttribute.cs
  94. 34
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitable.cs
  95. 45
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitor.cs
  96. 35
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/IScopeProvider.cs
  97. 37
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ISymbolReader.cs
  98. 36
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ISymbolStoreFactory.cs
  99. 37
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ISymbolWriter.cs
  100. 35
      lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/IVariableDefinitionProvider.cs
  101. Some files were not shown because too many files have changed in this diff Show More

1
lib/cecil-0.6/src/Mono.Cecil.Mdb/AUTHORS

@ -0,0 +1 @@ @@ -0,0 +1 @@
Jb Evain <jbevain@novell.com>

23
lib/cecil-0.6/src/Mono.Cecil.Mdb/ChangeLog

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
2007-08-28 Jb Evain <jbevain@novell.com>
* Mono.Cecil.Mdb/MdbWriter.cs:
Rewrite variables infos.
2007-08-27 Jb Evain <jbevain@novell.com>
* Mono.Cecil.Mdb/MdbWriter.cs:
Rewrite using the direct mdb api.
2007-02-21 Jb Evain <jb@nurv.fr>
* Start working on local var debug infos emitting.
2006-09-24 Jb Evain <jbevain@gmail.com>
* start some work on the reader.
2006-09-19 Jb Evain <jbevain@gmail.com>
* first checkin in SVN:
This is the assembly to support reading and writing
from Mono's mdb symbol store.

12
lib/cecil-0.6/src/Mono.Cecil.Mdb/Makefile

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
thisdir = class/Mono.Cecil.Mdb
include ../../build/rules.make
LIBRARY = Mono.Cecil.Mdb.dll
LIBRARY_SNK = ../mono.snk
LIBRARY_PACKAGE = none
LIB_MCS_FLAGS = /r:$(corlib) /r:Mono.Cecil.dll /d:CECIL -keyfile:$(LIBRARY_SNK)
NO_TEST = yes
include ../../build/library.make

61
lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb.csproj

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C5D12431-9C20-4789-8FEC-46094B0F81B5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Mdb</RootNamespace>
<AssemblyName>Mono.Cecil.Mdb</AssemblyName>
<StartupObject>
</StartupObject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\mcs\class\mono.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Compile Include="Mono.Cecil.Mdb\AssemblyInfo.cs" />
<Compile Include="Mono.Cecil.Mdb\MdbFactory.cs" />
<Compile Include="Mono.Cecil.Mdb\MdbReader.cs" />
<Compile Include="Mono.Cecil.Mdb\MdbWriter.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolFile.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolTable.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolWriter.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\SymbolWriterImpl.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\mcs\class\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
</ItemGroup>
</Project>

8
lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
./Mono.Cecil.Mdb/AssemblyInfo.cs
./Mono.Cecil.Mdb/MdbFactory.cs
./Mono.Cecil.Mdb/MdbReader.cs
./Mono.Cecil.Mdb/MdbWriter.cs
../Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs
../Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs
../Mono.CompilerServices.SymbolWriter/MonoSymbolWriter.cs
../Mono.CompilerServices.SymbolWriter/SymbolWriterImpl.cs

43
lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
//
// AssemblyInfo.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Mdb")]
[assembly: AssemblyDescription ("Support for the mdb symbols store in Cecil")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("(C) 2006, Jb Evain")]
[assembly: AssemblyCulture ("")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]
[assembly: AssemblyVersion ("0.2.0.0")]

49
lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbFactory.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
//
// MdbFactory.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Mdb {
using System;
using Mono.Cecil.Cil;
using Mono.CompilerServices.SymbolWriter;
public class MdbFactory : ISymbolStoreFactory {
public ISymbolReader CreateReader (ModuleDefinition module, string assembly)
{
return new MdbReader (MonoSymbolFile.ReadSymbolFile (module.Assembly, assembly));
}
public ISymbolWriter CreateWriter (ModuleDefinition module, string assembly)
{
return new MdbWriter (module.Mvid, assembly);
}
}
}

152
lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs

@ -0,0 +1,152 @@ @@ -0,0 +1,152 @@
//
// MdbReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Mdb {
using System.Collections;
using Mono.Cecil.Cil;
using Mono.CompilerServices.SymbolWriter;
class MdbReader : ISymbolReader {
MonoSymbolFile m_symFile;
Hashtable m_documents;
Hashtable m_scopes;
public MdbReader (MonoSymbolFile symFile)
{
m_symFile = symFile;
m_documents = new Hashtable ();
m_scopes = new Hashtable ();
}
Hashtable GetInstructions (MethodBody body)
{
Hashtable instructions = new Hashtable (body.Instructions.Count);
foreach (Instruction i in body.Instructions)
instructions.Add (i.Offset, i);
return instructions;
}
Instruction GetInstruction (MethodBody body, Hashtable instructions, int offset)
{
Instruction instr = (Instruction) instructions [offset];
if (instr != null)
return instr;
return body.Instructions.Outside;
}
public void Read (MethodBody body)
{
MethodEntry entry = m_symFile.GetMethodByToken ((int) body.Method.MetadataToken.ToUInt ());
if (entry == null)
return;
Hashtable instructions = GetInstructions(body);
ReadScopes (entry, body, instructions);
ReadLineNumbers (entry, instructions);
ReadLocalVariables (entry, body);
}
void ReadLocalVariables (MethodEntry entry, MethodBody body)
{
foreach (LocalVariableEntry loc in entry.Locals) {
Scope scope = m_scopes [loc.BlockIndex] as Scope;
if (scope == null)
continue;
VariableDefinition var = body.Variables [loc.Index];
var.Name = loc.Name;
scope.Variables.Add (var);
}
}
void ReadLineNumbers (MethodEntry entry, Hashtable instructions)
{
foreach (LineNumberEntry line in entry.LineNumbers) {
Instruction instr = instructions [line.Offset] as Instruction;
if (instr == null)
continue;
Document doc = GetDocument (entry.SourceFile);
instr.SequencePoint = new SequencePoint (doc);
instr.SequencePoint.StartLine = line.Row;
instr.SequencePoint.EndLine = line.Row;
}
}
Document GetDocument (SourceFileEntry file)
{
Document doc = m_documents [file.FileName] as Document;
if (doc != null)
return doc;
doc = new Document (file.FileName);
m_documents [file.FileName] = doc;
return doc;
}
void ReadScopes (MethodEntry entry, MethodBody body, Hashtable instructions)
{
foreach (LexicalBlockEntry scope in entry.LexicalBlocks) {
Scope s = new Scope ();
s.Start = GetInstruction (body, instructions, scope.StartOffset);
s.End = GetInstruction(body, instructions, scope.EndOffset);
m_scopes [scope.Index] = s;
if (!AddScope (body, s))
body.Scopes.Add (s);
}
}
bool AddScope (IScopeProvider provider, Scope s)
{
foreach (Scope scope in provider.Scopes) {
if (AddScope (scope, s))
return true;
if (s.Start.Offset >= scope.Start.Offset && s.End.Offset <= scope.End.Offset) {
scope.Scopes.Add (s);
return true;
}
}
return false;
}
public void Dispose ()
{
m_symFile.Dispose ();
}
}
}

179
lib/cecil-0.6/src/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs

@ -0,0 +1,179 @@ @@ -0,0 +1,179 @@
//
// MdbWriter.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Inspired by the pdb2mdb tool written by Robert Jordan, thanks Robert!
namespace Mono.Cecil.Mdb {
using System;
using System.Collections;
using Mono.CompilerServices.SymbolWriter;
using Mono.Cecil;
using Mono.Cecil.Cil;
class MdbWriter : ISymbolWriter {
Guid m_mvid;
MonoSymbolWriter m_writer;
Hashtable m_documents;
public MdbWriter (Guid mvid, string assembly)
{
m_mvid = mvid;
m_writer = new MonoSymbolWriter (assembly);
m_documents = new Hashtable ();
}
static Instruction [] GetInstructions (MethodBody body)
{
ArrayList list = new ArrayList ();
foreach (Instruction instruction in body.Instructions)
if (instruction.SequencePoint != null)
list.Add (instruction);
return list.ToArray (typeof (Instruction)) as Instruction [];
}
SourceFile GetSourceFile (Document document)
{
string url = document.Url;
SourceFile file = m_documents [url] as SourceFile;
if (file != null)
return file;
file = new SourceFile (m_writer.DefineDocument (url));
m_documents [url] = file;
return file;
}
void Populate (Instruction [] instructions, int [] offsets,
int [] startRows, int [] startCols, int [] endRows, int [] endCols,
out SourceFile file)
{
SourceFile document = null;
for (int i = 0; i < instructions.Length; i++) {
Instruction instr = (Instruction) instructions [i];
offsets [i] = instr.Offset;
if (document == null)
document = GetSourceFile (instr.SequencePoint.Document);
startRows [i] = instr.SequencePoint.StartLine;
startCols [i] = instr.SequencePoint.StartColumn;
endRows [i] = instr.SequencePoint.EndLine;
endCols [i] = instr.SequencePoint.EndColumn;
}
file = document;
}
public void Write (MethodBody body, byte [][] variables)
{
SourceMethod meth = new SourceMethod (body.Method);
SourceFile file;
Instruction [] instructions = GetInstructions (body);
int length = instructions.Length;
if (length == 0)
return;
int [] offsets = new int [length];
int [] startRows = new int [length];
int [] startCols = new int [length];
int [] endRows = new int [length];
int [] endCols = new int [length];
Populate (instructions, offsets, startRows, startCols, endRows, endCols, out file);
m_writer.OpenMethod (file, meth,
startRows [0], startCols [0],
endRows [length - 1], endCols [length - 1]);
for (int i = 0; i < length; i++)
m_writer.MarkSequencePoint (offsets [i], startRows [i], startCols [i]);
MarkVariables (body, variables);
m_writer.CloseMethod ();
}
void MarkVariables (MethodBody body, byte [][] variables)
{
for (int i = 0; i < body.Variables.Count; i++) {
VariableDefinition var = body.Variables [i];
m_writer.DefineLocalVariable (i, var.Name, variables [i]);
}
}
public void Dispose ()
{
m_writer.WriteSymbolFile (m_mvid);
}
class SourceFile : ISourceFile {
SourceFileEntry m_entry;
public SourceFileEntry Entry {
get { return m_entry; }
}
public SourceFile (SourceFileEntry entry)
{
m_entry = entry;
}
}
class SourceMethod : ISourceMethod {
MethodDefinition m_method;
public string Name {
get { return m_method.Name; }
}
public int NamespaceID {
get { return 0; }
}
public int Token {
get { return (int) m_method.MetadataToken.ToUInt (); }
}
public SourceMethod (MethodDefinition method)
{
m_method = method;
}
}
}
}

2
lib/cecil-0.6/src/Mono.Cecil.Mdb/README

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
Mono.Cecil.Mdb is an internal assembly used by Mono.Cecil to
read and write the Mono Debugging Symbols file format.

31
lib/cecil-0.6/src/Mono.Cecil.Pdb/ChangeLog

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
2007-02-21 Jb Evain <jb@nurv.fr>
* Start working on local var debug infos emitting.
2007-02-21 Jb Evain <jbevain@gmail.com>
* Mono.Cecil.Pdb/PdbReader.cs
Mono.Cecil.Pdb/PdbHelper.cs
Mono.Cecil.Pdb/IMetaDataDispenser.cs:
Refactor patches from:
Sverre Boschman <s.r.boschman@iego-development.nl>
- Force the release of the lock on the pdb on reading
- Implement the ability to read a pdb in memory
2006-09-24 Jb Evain <jbevain@gmail.com>
* Handle the fact that a scope end points outside the cil stream.
2006-09-20 Jb Evain <jbevain@gmail.com>
* implement somes bits of the writing stuff.
2006-09-19 Jb Evain <jbevain@gmail.com>
* first checkin in SVN:
This is the assembly to support reading and writing
from Microsoft's pdb symbols store.
It will only work on Windows until Microsoft release
the spec for the pdb files.

61
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb.csproj

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4FEBBB25-D5C0-48F0-A822-2E0D6F3D777E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Pdb</RootNamespace>
<AssemblyName>Mono.Cecil.Pdb</AssemblyName>
<StartupObject>
</StartupObject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\mcs\class\mono.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Compile Include="Mono.Cecil.Pdb\AssemblyInfo.cs" />
<Compile Include="Mono.Cecil.Pdb\IMetadataDispenser.cs" />
<Compile Include="Mono.Cecil.Pdb\IMetadataImport.cs" />
<Compile Include="Mono.Cecil.Pdb\PdbFactory.cs" />
<Compile Include="Mono.Cecil.Pdb\PdbReader.cs" />
<Compile Include="Mono.Cecil.Pdb\PdbWriter.cs" />
<Compile Include="Mono.Cecil.Pdb\PdbHelper.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="ISymWrapper" />
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\mcs\class\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
</ItemGroup>
</Project>

43
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/AssemblyInfo.cs

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
//
// AssemblyInfo.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Pdb")]
[assembly: AssemblyDescription ("Support for the pdb symbols store in Cecil")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("(C) 2006, Jb Evain")]
[assembly: AssemblyCulture ("")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]
[assembly: AssemblyVersion ("0.2.0.0")]

56
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/IMetadataDispenser.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
//
// IMetadataImport.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// from: http://blogs.msdn.com/jmstall/articles/sample_pdb2xml.aspx
namespace Mono.Cecil.Pdb {
using System;
using System.Runtime.InteropServices;
[Guid ("809c652e-7396-11d2-9771-00a0c9b4d50c")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
[ComVisible (true)]
interface IMetaDataDispenser {
void DefineScope_Placeholder();
void OpenScope (
[In, MarshalAs (UnmanagedType.LPWStr)] string szScope,
[In] int dwOpenFlags,
[In] ref Guid riid,
[Out, MarshalAs (UnmanagedType.IUnknown)] out object punk);
void OpenScopeOnMemory (
[In] IntPtr pData,
[In] uint cbData,
[In] uint dwOpenFlags,
[In] ref Guid riid,
[Out, MarshalAs (UnmanagedType.Interface)] out object punk);
}
}

43
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/IMetadataImport.cs

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
//
// IMetadataImport.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// from: http://blogs.msdn.com/jmstall/articles/sample_pdb2xml.aspx
namespace Mono.Cecil.Pdb {
using System;
using System.Runtime.InteropServices;
[Guid ("7DAC8207-D3AE-4c75-9B67-92801A497D44")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
[ComVisible (true)]
[CLSCompliant (true)]
public interface IMetadataImport {
void Placeholder();
}
}

46
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbFactory.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
//
// PdbFactory.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Pdb {
using Mono.Cecil.Cil;
public class PdbFactory : ISymbolStoreFactory {
public ISymbolReader CreateReader (ModuleDefinition module, string assembly)
{
return new PdbReader (PdbHelper.CreateReader (assembly));
}
public ISymbolWriter CreateWriter (ModuleDefinition module, string assembly)
{
string pdb = string.Concat(assembly.Substring(0, assembly.LastIndexOf(".")), ".pdb");
return new PdbWriter (PdbHelper.CreateWriter (assembly, pdb), module, pdb);
}
}
}

130
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbHelper.cs

@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
//
// PdbHelper.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// from: http://blogs.msdn.com/jmstall/articles/sample_pdb2xml.aspx
namespace Mono.Cecil.Pdb {
using System;
using System.Diagnostics.SymbolStore;
using System.IO;
using System.Runtime.InteropServices;
internal class PdbHelper {
[DllImport("ole32.dll")]
static extern int CoCreateInstance (
[In] ref Guid rclsid,
[In, MarshalAs (UnmanagedType.IUnknown)] object pUnkOuter,
[In] uint dwClsContext,
[In] ref Guid riid,
[Out, MarshalAs(UnmanagedType.Interface)] out object ppv);
static Guid s_dispenserClassID = new Guid (0xe5cb7a31, 0x7512, 0x11d2, 0x89, 0xce, 0x00, 0x80, 0xc7, 0x92, 0xe5, 0xd8);
static Guid s_dispenserIID = new Guid (0x809c652e, 0x7396, 0x11d2, 0x97, 0x71, 0x00, 0xa0, 0xc9, 0xb4, 0xd5, 0x0c);
static Guid s_importerIID = new Guid (0x7dac8207, 0xd3ae, 0x4c75, 0x9b, 0x67, 0x92, 0x80, 0x1a, 0x49, 0x7d, 0x44);
public static ISymbolReader CreateReader (string filename)
{
SymBinder binder;
object objImporter;
IMetaDataDispenser dispenser = InstantiateDispenser (out binder);
dispenser.OpenScope (filename, 0, ref s_importerIID, out objImporter);
return InstantiateReader (binder, filename, objImporter);
}
public static ISymbolReader CreateReader (string filename, byte [] binaryFile)
{
SymBinder binder;
object objImporter;
IntPtr filePtr = Marshal.AllocHGlobal (binaryFile.Length);
Marshal.Copy (binaryFile, 0, filePtr, binaryFile.Length);
IMetaDataDispenser dispenser = InstantiateDispenser (out binder);
dispenser.OpenScopeOnMemory (filePtr, (uint) binaryFile.Length, 0, ref s_importerIID, out objImporter);
return InstantiateReader (binder, filename, objImporter);
}
static IMetaDataDispenser InstantiateDispenser (out SymBinder binder)
{
binder = new SymBinder ();
object dispenser;
CoCreateInstance (ref s_dispenserClassID, null, 1, ref s_dispenserIID, out dispenser);
return (IMetaDataDispenser) dispenser;
}
static ISymbolReader InstantiateReader (SymBinder binder, string filename, object objImporter)
{
IntPtr importerPtr = IntPtr.Zero;
ISymbolReader reader;
try {
importerPtr = Marshal.GetComInterfaceForObject (objImporter, typeof (IMetadataImport));
reader = binder.GetReader (importerPtr, filename, null);
} finally {
if (importerPtr != IntPtr.Zero)
Marshal.Release (importerPtr);
}
return reader;
}
public static ISymbolWriter CreateWriter (string assembly, string pdb)
{
SymWriter writer = new SymWriter (false);
object objDispenser, objImporter;
CoCreateInstance (ref s_dispenserClassID, null, 1, ref s_dispenserIID, out objDispenser);
IMetaDataDispenser dispenser = (IMetaDataDispenser) objDispenser;
dispenser.OpenScope (assembly, 1, ref s_importerIID, out objImporter);
IntPtr importerPtr = Marshal.GetComInterfaceForObject (objImporter, typeof (IMetadataImport));
try {
if (File.Exists (pdb))
File.Delete (pdb);
writer.Initialize (importerPtr, pdb, false);
} finally {
if (importerPtr != IntPtr.Zero) {
Marshal.Release (importerPtr);
Marshal.ReleaseComObject (objDispenser);
Marshal.ReleaseComObject (objImporter);
Marshal.ReleaseComObject (dispenser);
}
}
return writer;
}
}
}

148
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbReader.cs

@ -0,0 +1,148 @@ @@ -0,0 +1,148 @@
//
// PdbReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Pdb {
using System;
using System.Collections;
using System.Diagnostics.SymbolStore;
using System.Runtime.InteropServices;
public class PdbReader : Cil.ISymbolReader {
ISymbolReader m_reader;
Hashtable m_documents;
internal PdbReader (ISymbolReader reader)
{
m_reader = reader;
m_documents = new Hashtable ();
}
public void Read (Cil.MethodBody body)
{
try {
ISymbolMethod method = m_reader.GetMethod (new SymbolToken ((int) body.Method.MetadataToken.ToUInt ()));
Hashtable instructions = GetInstructions (body);
ReadSequencePoints (method, instructions);
ReadScopeAndLocals (method.RootScope, null, body, instructions);
} catch (COMException) {}
}
static Hashtable GetInstructions (Cil.MethodBody body)
{
Hashtable instructions = new Hashtable (body.Instructions.Count);
foreach (Cil.Instruction i in body.Instructions)
instructions.Add (i.Offset, i);
return instructions;
}
static Cil.Instruction GetInstruction (Cil.MethodBody body, Hashtable instructions, int offset)
{
Cil.Instruction instr = (Cil.Instruction) instructions [offset];
if (instr != null)
return instr;
return body.Instructions.Outside;
}
static void ReadScopeAndLocals (ISymbolScope scope, Cil.Scope parent, Cil.MethodBody body, Hashtable instructions)
{
Cil.Scope s = new Cil.Scope ();
s.Start = GetInstruction (body, instructions, scope.StartOffset);
s.End = GetInstruction (body, instructions, scope.EndOffset);
if (parent != null)
parent.Scopes.Add (s);
else
body.Scopes.Add (s);
foreach (ISymbolVariable local in scope.GetLocals ()) {
Cil.VariableDefinition variable = body.Variables [local.AddressField1];
variable.Name = local.Name;
s.Variables.Add (variable);
}
foreach (ISymbolScope child in scope.GetChildren ())
ReadScopeAndLocals (child, s, body, instructions);
}
void ReadSequencePoints(ISymbolMethod method, Hashtable instructions)
{
int count = method.SequencePointCount;
int [] offsets = new int [count];
ISymbolDocument [] docs = new ISymbolDocument [count];
int [] startColumn = new int [count];
int [] endColumn = new int [count];
int [] startRow = new int [count];
int [] endRow = new int [count];
method.GetSequencePoints (offsets, docs, startRow, startColumn, endRow, endColumn);
for (int i = 0; i < offsets.Length; i++) {
Cil.Instruction instr = (Cil.Instruction) instructions [offsets [i]];
Cil.SequencePoint sp = new Cil.SequencePoint (GetDocument (docs [i]));
sp.StartLine = startRow [i];
sp.StartColumn = startColumn [i];
sp.EndLine = endRow [i];
sp.EndColumn = endColumn [i];
instr.SequencePoint = sp;
}
}
Cil.Document GetDocument (ISymbolDocument document)
{
Cil.Document doc = m_documents [document.URL] as Cil.Document;
if (doc != null)
return doc;
doc = new Cil.Document (document.URL);
doc.Type = (Cil.DocumentType) Cil.GuidAttribute.GetValueFromGuid (
document.DocumentType, typeof (Cil.DocumentType));
doc.Language = (Cil.DocumentLanguage) Cil.GuidAttribute.GetValueFromGuid (
document.Language, typeof (Cil.DocumentLanguage));
doc.LanguageVendor = (Cil.DocumentLanguageVendor) Cil.GuidAttribute.GetValueFromGuid (
document.LanguageVendor, typeof (Cil.DocumentLanguageVendor));
m_documents [doc.Url] = doc;
return doc;
}
public void Dispose ()
{
m_reader = null;
// force the release of the pdb lock
GC.Collect ();
}
}
}

202
lib/cecil-0.6/src/Mono.Cecil.Pdb/Mono.Cecil.Pdb/PdbWriter.cs

@ -0,0 +1,202 @@ @@ -0,0 +1,202 @@
//
// PdbWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Mono.Cecil.Cil;
namespace Mono.Cecil.Pdb {
using System;
using System.Collections;
using System.Diagnostics.SymbolStore;
using System.IO;
public class PdbWriter : Cil.ISymbolWriter {
ModuleDefinition m_module;
ISymbolWriter m_writer;
Hashtable m_documents;
string m_pdb;
internal PdbWriter (ISymbolWriter writer, ModuleDefinition module, string pdb)
{
m_writer = writer;
m_module = module;
m_documents = new Hashtable ();
m_pdb = pdb;
}
public void Write (MethodBody body, byte [][] variables)
{
CreateDocuments (body);
m_writer.OpenMethod (new SymbolToken ((int) body.Method.MetadataToken.ToUInt ()));
CreateScopes (body, body.Scopes, variables);
m_writer.CloseMethod ();
}
void CreateScopes (MethodBody body, ScopeCollection scopes, byte [][] variables)
{
foreach (Scope s in scopes) {
int startOffset = s.Start.Offset;
int endOffset = s.End == body.Instructions.Outside ?
body.Instructions[body.Instructions.Count - 1].Offset + 1 :
s.End.Offset;
m_writer.OpenScope (startOffset);
m_writer.UsingNamespace (body.Method.DeclaringType.Namespace);
m_writer.OpenNamespace (body.Method.DeclaringType.Namespace);
int start = body.Instructions.IndexOf (s.Start);
int end = s.End == body.Instructions.Outside ?
body.Instructions.Count - 1 :
body.Instructions.IndexOf (s.End);
ArrayList instructions = new ArrayList();
for (int i = start; i <= end; i++)
if (body.Instructions [i].SequencePoint != null)
instructions.Add (body.Instructions [i]);
Document doc = null;
int [] offsets = new int [instructions.Count];
int [] startRows = new int [instructions.Count];
int [] startCols = new int [instructions.Count];
int [] endRows = new int [instructions.Count];
int [] endCols = new int [instructions.Count];
for (int i = 0; i < instructions.Count; i++) {
Instruction instr = (Instruction) instructions [i];
offsets [i] = instr.Offset;
if (doc == null)
doc = instr.SequencePoint.Document;
startRows [i] = instr.SequencePoint.StartLine;
startCols [i] = instr.SequencePoint.StartColumn;
endRows [i] = instr.SequencePoint.EndLine;
endCols [i] = instr.SequencePoint.EndColumn;
}
m_writer.DefineSequencePoints (GetDocument (doc),
offsets, startRows, startCols, endRows, endCols);
CreateLocalVariable (s, startOffset, endOffset, variables);
CreateScopes (body, s.Scopes, variables);
m_writer.CloseNamespace ();
m_writer.CloseScope (endOffset);
}
}
void CreateLocalVariable (IVariableDefinitionProvider provider, int startOffset, int endOffset, byte [][] variables)
{
for (int i = 0; i < provider.Variables.Count; i++) {
VariableDefinition var = provider.Variables [i];
m_writer.DefineLocalVariable (
var.Name,
0,
variables [i],
SymAddressKind.ILOffset,
i,
0,
0,
startOffset,
endOffset);
}
}
void CreateDocuments (MethodBody body)
{
foreach (Instruction instr in body.Instructions) {
if (instr.SequencePoint == null)
continue;
GetDocument (instr.SequencePoint.Document);
}
}
ISymbolDocumentWriter GetDocument (Document document)
{
if (document == null)
return null;
ISymbolDocumentWriter docWriter = m_documents [document.Url] as ISymbolDocumentWriter;
if (docWriter != null)
return docWriter;
docWriter = m_writer.DefineDocument (
document.Url,
GuidAttribute.GetGuidFromValue ((int) document.Language, typeof (DocumentLanguage)),
GuidAttribute.GetGuidFromValue ((int) document.LanguageVendor, typeof (DocumentLanguageVendor)),
GuidAttribute.GetGuidFromValue ((int) document.Type, typeof (DocumentType)));
m_documents [document.Url] = docWriter;
return docWriter;
}
public void Dispose ()
{
m_writer.Close ();
Patch ();
}
void Patch ()
{
FileStream fs = new FileStream (m_pdb, FileMode.Open, FileAccess.ReadWrite);
uint age = m_module.Image.DebugHeader.Age;
Guid g = m_module.Image.DebugHeader.Signature;
BinaryReader reader = new BinaryReader (fs);
reader.BaseStream.Position = 32;
uint pageSize = reader.ReadUInt32 ();
reader.BaseStream.Position += 4;
uint pageCount = reader.ReadUInt32 ();
reader.BaseStream.Position += pageSize - 44;
uint magic = 0x1312e94;
int page = 0;
for (int i = 1; i < pageCount; i++) {
if (magic == reader.ReadUInt32 ()) {
page = i;
break;
}
reader.BaseStream.Position += pageSize - 4;
}
BinaryWriter writer = new BinaryWriter (fs);
writer.BaseStream.Position = page * pageSize + 8;
writer.Write (age);
writer.Write (g.ToByteArray ());
fs.Close ();
}
}
}

49
lib/cecil-0.6/src/Mono.Cecil.Pdb/default.build

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
<?xml version="1.0"?>
<project name="Mono.Cecil.Pdb" default="build">
<!-- allow properties to be customized in external file" -->
<include buildfile="build.properties" if="${file::exists('build.properties')}" />
<property name="Mono.Cecil.dll" value="../../mcs/class/Mono.Cecil/bin/Mono.Cecil.dll" />
<property name="build.dir" value="bin" />
<property name="optimize" value="false" />
<property name="debug" value="true" />
<property name="keyfile" value="../../mcs/class/mono.snk" />
<property name="csc.defines" value="NO_DEFINE" />
<target name="release" depends="clean, set-release, build">
</target>
<target name="set-release">
<property name="optimize" value="true" />
<property name="debug" value="false" />
</target>
<target name="build" depends="init">
<csc
target="library"
output="${build.dir}/Mono.Cecil.Pdb.dll"
debug="${debug}"
optimize="${optimize}"
keyfile="${keyfile}"
define="${csc.defines}">
<sources basedir="Mono.Cecil.Pdb">
<include name="**/*.cs" />
</sources>
<references basedir="${build.dir}">
<include name="Mono.Cecil.dll" />
<include name="ISymWrapper.dll" />
</references>
</csc>
</target>
<target name="init">
<mkdir dir="${build.dir}" unless="${directory::exists(build.dir)}" />
<copy todir="${build.dir}" file="${Mono.Cecil.dll}" />
</target>
<target name="clean">
<delete dir="${build.dir}" if="${directory::exists(build.dir)}" />
</target>
</project>

1
lib/cecil-0.6/src/Mono.Cecil/AUTHORS

@ -0,0 +1 @@ @@ -0,0 +1 @@
Jb Evain (jbevain@gmail.com)

3617
lib/cecil-0.6/src/Mono.Cecil/ChangeLog

File diff suppressed because it is too large Load Diff

226
lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-attributes.rb

@ -0,0 +1,226 @@ @@ -0,0 +1,226 @@
#!/usr/bin/env ruby
$providers = []
$mapping = {
"Assem" => "IsAssembly",
"FamORAssem" => "IsFamilyOrAssembly",
"FamANDAssem" => "IsFamilyAndAssembly",
"NestedFamORAssem" => "IsNestedFamilyOrAssembly",
"NestedFamANDAssem" => "IsNestedFamilyAndAssembly",
"RTSpecialName" => "IsRuntimeSpecialName",
"Compilercontrolled" => "IsCompilerControlled",
"NotNullableValueTypeConstraint" => "HasNotNullableValueTypeConstraint",
"ReferenceTypeConstraint" => "HasReferenceTypeConstraint",
"DefaultConstructorConstraint" => "HasDefaultConstructorConstraint",
"SupportsLastError" => "SupportsLastError",
"NoInlining" => "NoInlining",
}
$black_list = [
"None", "Unused", "RequireSecObject",
"HasFieldMarshal", "HasFieldRVA",
"OPTIL", "MaxMethodImplVal"
]
class Attribute
attr_accessor(:name)
attr_accessor(:type)
def initialize(name, type)
@name = name
@type = type
end
def full_name
"#{@type}.#{@name}"
end
def to_csharp
""" public bool #{get_name()} {
#{getter()}#{setter()} }
"""
end
def to_s
"Attribute #{full_name}"
end
protected
def getter
""" get { return (m_attributes & #{full_name()}) != 0; }
"""
end
def setter
""" set {
if (value)
m_attributes |= #{full_name()};
else
m_attributes &= ~#{full_name()};
}
"""
end
private
def get_name
name = @name
return $mapping[name] if $mapping.include?(name)
return name if name.rindex("Has") == 0
"Is#{name}"
end
end
class MaskedAttribute < Attribute
attr_accessor(:mask)
def initialize(name, type, mask)
super(name, type)
@mask = mask
end
def mask_full_name
"#{@type}.#{@mask}"
end
def to_s
"MaskedAttribute #{full_name()}, masked by #{mask_full_name()}"
end
protected
def getter
""" get { return (m_attributes & #{mask_full_name()}) == #{full_name()}; }
"""
end
def setter
""" set {
if (value) {
m_attributes &= ~#{mask_full_name()};
m_attributes |= #{full_name()};
} else
m_attributes &= ~(#{mask_full_name()} & #{full_name()});
}
"""
end
end
class Provider
attr_accessor(:type)
attr_accessor(:attributes_file)
attr_accessor(:target_file)
attr_accessor(:attributes)
def initialize(type, attributes_file, target_file)
@type = type
@attributes_file = attributes_file
@target_file = target_file
@attributes = []
end
def parse
f = File.open(@attributes_file, File::RDONLY)
have_mask = false
mask = ""
f.readlines.each { |line|
if line.chomp().length == 0
have_mask = false
else
name = get_name(line)
if not name.nil? and name.index("Mask")
mask = name
have_mask = true
elsif not name.nil?
attr = nil
if (have_mask)
attr = MaskedAttribute.new(name, @type, mask)
else
attr = Attribute.new(name, @type)
end
@attributes << attr
end
end
}
f.close
end
def patch
buffer = read_target_content()
buffer = patch_buffer(buffer)
if buffer != read_target_content()
puts("#{@target_file} patched")
write_target_content (buffer)
end
end
private
def patch_buffer(buffer)
region = "#region " + @type
endregion = "#endregion"
endpart = buffer[(buffer.index(endregion) - 3)..buffer.length]
rep = buffer[0..(buffer.index(region) + region.length)]
rep += "\n"
@attributes.each { |attr|
rep += attr.to_csharp
rep += "\n" if attr != @attributes.last
}
rep += endpart
rep
end
def read_target_content
f = File.new(@target_file, File::RDONLY)
content = f.readlines.join
f.close
content
end
def write_target_content(content)
File.open(@target_file, File::WRONLY | File::TRUNC) { |f|
f.write(content)
}
end
def get_name(line)
pos = line.index("=")
return nil if not pos
name = line[0..(pos - 1)].strip
return nil if $black_list.include?(name)
name
end
end
def to_cecil_file(file)
"../Mono.Cecil/#{file}.cs"
end
[ "Event", "Field", "Method", "Parameter", "Property", "Type" ].each { |name|
attributes = "#{name}Attributes"
definition = "#{name}Definition"
$providers << Provider.new(attributes, to_cecil_file(attributes), to_cecil_file(definition))
}
{ "GenericParameter" => "GenericParameter",
"ManifestResource" => "Resource",
"PInvoke" => "PInvokeInfo",
# "MethodImpl" => "MethodDefinition",
# "MethodSemantics" => "MethodDefinition",
}.each { |k, v|
attributes = "#{k}Attributes"
$providers << Provider.new(attributes, to_cecil_file(attributes), to_cecil_file(v))
}
$providers.each { |p|
p.parse
p.patch
}

14
lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-sources.rb

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
#!/usr/bin/env ruby
f = File.new("../Mono.Cecil.dll.sources", File::CREAT | File::WRONLY | File::TRUNC)
[ "Mono.Cecil", "Mono.Cecil.Binary",
"Mono.Cecil.Metadata", "Mono.Cecil.Cil",
"Mono.Cecil.Signatures", "Mono.Xml" ].each { |dir|
Dir.foreach("../" + dir) { |file|
f.print("./#{dir}/#{file}\n") if file[(file.length - 3)..file.length] == ".cs"
}
}
f.close

61
lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-tests.rb

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
#!/usr/bin/env ruby
require 'erb'
class Language
attr_reader(:name)
attr_reader(:compiler)
attr_reader(:ext)
attr_reader(:command)
def initialize(name, compiler, ext, command)
@name = name
@compiler = compiler
@ext = ext
@command = command
end
end
class TestCase
attr_reader(:lang)
attr_reader(:file)
def initialize(lang, file)
@lang = lang
@file = file
end
def method()
meth = @file.gsub(/[^a-zA-Z1-9]/, "_")
return meth[1..meth.length] if (meth[0].chr == "_")
return meth
end
end
$languages = [
Language.new("cil", "ilasm", ".il", "{0} /exe /output:{2} {1}"),
Language.new("csharp", "mcs", ".cs", "{0} /t:exe /o:{2} {1}")
]
$tests = [
]
def analyze(dir)
$languages.each { |l|
pattern = File.join(dir, "**", "*" + l.ext)
Dir[pattern].each { |file|
$tests.push(TestCase.new(l, File.expand_path(file)))
}
}
end
ARGV.each { |dir|
analyze(dir)
}
if $tests.length > 0
erb = ERB.new(IO.read("./templates/Tests.cs"))
print(erb.result)
end

262
lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen-types.rb

@ -0,0 +1,262 @@ @@ -0,0 +1,262 @@
# types used in templates
module Cecil
class Evolutive # abstract
attr_reader(:requ)
def initialize(requ)
@requ = requ
end
end
class FieldWorker # abstract
attr_reader(:field_name)
attr_reader(:property_name)
attr_reader(:type)
attr_reader(:ns)
attr_reader(:size)
attr_reader(:target)
def initialize(name, type, target)
@property_name = name
@target = target
@field_name = to_field(name)
@objtype = type
ar = type.name.split(".")
@type = ar.pop()
@ns = ar.join(".")
@size = type.size
end
def to_field(name)
name = String.new(name)
name[0] = name[0].chr.downcase
return "m_" + name
end
def write_binary(inst, writer)
pre = writer + ".Write ("
prp = inst + "." + @property_name
suf = ")"
return case @type
when "byte", "ushort", "short", "uint", "int"
pre + prp + suf
when "RVA"
pre + prp + ".Value" + suf
when "DataDirectory"
pre + prp + ".VirtualAddress" + suf + ";\n\t\t\t" + pre + prp + ".Size" + suf
else
pre + "(" + @objtype.underlying + ") " + prp + suf
end
end
def read_binary(inst)
return case @type
when "byte"
inst + ".ReadByte ()"
when "ushort"
inst + ".ReadUInt16 ()";
when "short"
inst + ".ReadInt16 ()";
when "uint"
inst + ".ReadUInt32 ()";
when "int"
inst + ".ReadInt32 ()";
when "RVA"
"new RVA (" + inst + ".ReadUInt32 ())"
when "DataDirectory"
"new DataDirectory (\n new RVA (" + inst + ".ReadUInt32 ()),\n " + inst + ".ReadUInt32 ())"
else
"(" + @objtype.name + ") " + case @objtype.underlying
when "int"
inst + ".ReadInt32 ()";
when "short"
inst + ".ReadInt16 ()";
when "ushort"
inst + ".ReadUInt16 ()";
when "uint"
inst + ".ReadUInt32 ()";
end
end
end
end
class Type
attr_reader(:name)
attr_reader(:size)
attr_reader(:underlying)
def initialize(name, size, underlying = nil)
@name = name
@size = size
@underlying = underlying
end
end
class Table < Evolutive
attr_reader(:ref_ns)
attr_reader(:rid)
attr_reader(:name)
attr_reader(:table_name)
attr_reader(:row_name)
attr_reader(:columns)
def initialize(name, rid, requ)
super(requ)
@name = name
@table_name = name + "Table"
@row_name = name + "Row"
@rid = rid
@ref_ns = Array.new
@columns = Array.new
end
def add_column(col)
if (!@ref_ns.include?(col.ns) && col.ns.length != 0 && col.ns != "Mono.Cecil.Metadata") then
@ref_ns.push(col.ns)
@ref_ns.sort!()
end
@columns.push(col)
end
def row_size()
size = 0
@columns.each { |col|
size += col.size
}
return size
end
end
class Column < FieldWorker
def initialize(name, type, target)
super(name, type, target)
end
end
class Collection
attr_reader(:type)
attr_reader(:intf)
attr_reader(:name)
attr_reader(:container)
attr_reader(:container_impl)
attr_reader(:item_name)
attr_reader(:visitable)
attr_reader(:visitor)
attr_reader(:visitThis)
attr_reader(:visitItem)
attr_reader(:lazyload)
attr_reader(:pathtoloader)
attr_reader(:target)
attr_reader(:indexed)
def initialize(type, container, visit, name, lazyload, pathtoloader, target, indexed = false, usecntintf = false)
@type = type
basename = (name.nil? ? type : name)
@intf = "I" + basename + "Collection"
@name = @intf[1..@intf.length]
@item_name = basename[0..basename.length]
@container = container
@container_impl = usecntintf ? @container : @container[0..@container.length]
if (!visit.nil?) then
@visitable = visit + "Visitable"
@visitor = visit + "Visitor"
@visitThis = "Visit" + @name
@visitItem = "Visit" + @item_name
end
@lazyload = lazyload
@pathtoloader = pathtoloader
@target = target
@indexed = indexed
end
end
class OpCode < Evolutive
attr_reader(:name)
attr_reader(:field_name)
attr_reader(:op1)
attr_reader(:op2)
attr_reader(:size)
attr_reader(:flowcontrol)
attr_reader(:opcodetype)
attr_reader(:operandtype)
attr_reader(:stackbehaviourpop)
attr_reader(:stackbehaviourpush)
def initialize(name, op1, op2, flowcontrol, opcodetype, operandtype, stackbehaviourpop, stackbehaviourpush, requ)
super(requ)
@name = name
@field_name = name_to_prop(name)
@op1 = op1 ; @op2 = op2
@size = @op1 == "0xff" ? 1 : 2
@flowcontrol = "FlowControl." + flowcontrol
@opcodetype = "OpCodeType." + opcodetype
@operandtype = "OperandType." + operandtype
@stackbehaviourpop = "StackBehaviour." + stackbehaviourpop
@stackbehaviourpush = "StackBehaviour." + stackbehaviourpush
end
def name_to_prop(name)
field = ""
ar = name.split(".")
ar.each { |part|
field += part.capitalize()
field += "_" unless ar.last == part
}
return field
end
end
class Field < FieldWorker
attr_reader(:default)
def initialize(name, type, default)
super(name, type, nil)
@default = default
end
end
class CodedIndexTable
attr_reader(:name)
attr_reader(:tag)
def initialize(name, tag)
@name = name
@tag = tag
end
end
class CodedIndex < Evolutive
attr_reader(:name)
attr_reader(:size)
attr_reader(:tables)
def initialize(name, size, requ)
super(requ)
@name = name
@size = size
@tables = Array.new
end
def add_table(name, tag)
@tables.push(CodedIndexTable.new(name, tag))
end
end
end

161
lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-gen.rb

@ -0,0 +1,161 @@ @@ -0,0 +1,161 @@
#!/usr/bin/env ruby
# extern libraries used by code generator
require 'erb'
require 'rexml/document'
# our library
require 'cecil-gen-types'
# time to generate code now
$types = Hash.new
$tables = Array.new
$colls = Array.new
$coded_indexes = Array.new
$ops = Array.new
doc = REXML::Document.new(File.open("cecil.xml"))
doc.root.each_element("/cecil/types//type") { |node|
type = Cecil::Type.new(
node.attribute("name").value,
node.attribute("size").value.to_i,
(node.attribute("underlying").nil? ? nil : node.attribute("underlying").value))
$types[type.name] = type
}
doc.root.each_element("/cecil/metadata/tables//table") { |node|
table = Cecil::Table.new(node.attribute("name").value,
node.attribute("rid").value,
node.attribute("requires").nil? ? nil : node.attribute("requires").value)
node.each_element("column") { |col|
column = Cecil::Column.new(col.attribute("name").value,
$types[col.attribute("type").value],
col.attribute("target").nil? ? nil : col.attribute("target").value)
table.add_column(column)
}
$tables.push(table)
}
$tables.sort!() { |a, b|
a.name <=> b.name
}
$stables = $tables.sort { |a, b|
eval(a.rid) <=> eval(b.rid)
}
doc.root.each_element("/cecil/metadata/codedindexes//codedindex") { |node|
ci = Cecil::CodedIndex.new(node.attribute("name").value,
node.attribute("size").value,
node.attribute("requires").nil? ? nil : node.attribute("requires").value)
node.each_element("table") { |table|
ci.add_table(table.attribute("name").value, table.attribute("tag").value)
}
$coded_indexes.push(ci)
}
doc.root.each_element("/cecil/metadata/opcodes//opcode") { |node|
$ops.push(Cecil::OpCode.new(node.attribute("name").value, node.attribute("op1").value,
node.attribute("op2").value, node.attribute("flowcontrol").value,
node.attribute("opcodetype").value, node.attribute("operandtype").value,
node.attribute("stackbehaviourpop").value, node.attribute("stackbehaviourpush").value,
node.attribute("requires").nil? ? nil : node.attribute("requires").value))
}
$ops.sort!() { |a, b|
if a.op1 == b.op1
eval(a.op2) <=> eval(b.op2)
elsif a.op1 == "0xff"
-1
else
1
end
}
doc.root.each_element("/cecil/collections//collection") { |node|
$colls.push(Cecil::Collection.new(node.attribute("type").value, node.attribute("container").value,
(node.attribute("visit").nil? ? nil : node.attribute("visit").value),
(node.attribute("name").nil? ? nil : node.attribute("name").value),
(node.attribute("lazyload").nil? ? false : node.attribute("lazyload").value == "true"),
(node.attribute("pathtoloader").nil? ? nil : node.attribute("pathtoloader").value),
node.attribute("target").value,
(node.attribute("indexed").nil? ? false : node.attribute("indexed").value == "true"),
(node.attribute("usecontainerinterface").nil? ? false : node.attribute("usecontainerinterface").value == "true")))
}
def cecil_compile(file, template)
erb = ERB.new(IO.read(template))
res = erb.result
if (!File.exists?(file))
File.open(file, File::CREAT|File::WRONLY|File::TRUNC) { |cur_file|
cur_file.write(res)
}
puts("#Created: #{file}")
else
ext = ".tmp"
File.open(file + ext, File::CREAT|File::WRONLY|File::TRUNC) { |temp_file|
temp_file.write(res)
}
save = Array.new
[file, file + ext].each { |fileloc|
File.open(fileloc, File::RDONLY) { |f|
buf = f.readlines
buf.each { |line|
line.chomp!()
}
buf = buf.join
buf = buf[buf.index("SOFTWARE."), buf.length]
save.push(buf)
}
}
if (save[0] != save[1]) then
File.delete(file) if File.exists?(file)
File.rename(file + ext, file)
puts("#Modified: #{file}")
else
File.delete(file + ext)
end
end
end
$tables.each { |table|
$cur_table = table
filename = "../Mono.Cecil.Metadata/" + table.name + ".cs"
cecil_compile(filename, "./templates/Table.cs")
}
$cur_table = nil
[ "MetadataTableReader.cs", "MetadataRowReader.cs",
"MetadataTableWriter.cs", "MetadataRowWriter.cs", "BaseMetadataVisitor.cs",
"CodedIndex.cs", "Utilities.cs" ].each { |file|
cecil_compile("../Mono.Cecil.Metadata/" + file, "./templates/" + file)
}
cecil_compile("../Mono.Cecil.Metadata/IMetadataVisitor.cs", "./templates/IMetadataVisitor.cs")
cecil_compile("../Mono.Cecil.Cil/OpCodes.cs", "./templates/OpCodes.cs")
cecil_compile("../Mono.Cecil.Cil/Code.cs", "./templates/Code.cs")
$colls.each { |coll|
$cur_coll = coll
file = "../#{coll.target}/" + coll.name + ".cs"
type = coll.indexed ? "Indexed" : "Named"
template = "./templates/#{type}Collection.cs"
cecil_compile(file, template)
}
$cur_coll = nil

159
lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil-mig.rb

@ -0,0 +1,159 @@ @@ -0,0 +1,159 @@
#!/usr/bin/env ruby
#
# usage cecil-mig.rb directory
#
dir = ARGV.length > 0 ? ARGV[0] : "."
$replaces = {
"GenericParamAttributes" => "GenericParameterAttributes",
"ParamAttributes" => "ParameterAttributes",
"IParameterReference" => "ParameterDefinition",
"IPropertyReference" => "PropertyDefinition",
"IEventReference" => "EventDefinition",
"IVariableReference" => "VariableDefinition",
"IMarshalDesc" => "MarshalSpec",
"MarshalDesc" => "MarshalSpec",
"IArrayMarshalDesc" => "ArrayMarshalSpec",
"ArrayMarshalDesc" => "ArrayMarshalSpec",
"ICustomMarshalerDesc" => "CustomMarshalerSpec",
"CustomMarshalerDesc" => "CustomMarshalerSpec",
"ISafeArrayDesc" => "SafeArraySpec",
"SafeArrayDesc" => "SafeArraySpec",
"IFixedArrayDesc" => "FixedArraySpec",
"FixedArrayDesc" => "FixedArraySpec",
"IFixedSysStringDesc" => "FixedSysStringSpec",
"FixedSysStringDesc" => "FixedSysStringSpec",
"IModifierType" => "ModType"
}
$collections = [
"AssemblyNameReferenceCollection",
"ModuleReferenceCollection",
"ModuleDefinitionCollection",
"ResourceCollection",
"TypeDefinitionCollection",
"TypeReferenceCollection",
"InterfaceCollection",
"ParameterDefinitionCollection",
"OverrideCollection",
"MethodDefinitionCollection",
"ConstructorCollection",
"EventDefinitionCollection",
"FieldDefinitionCollection",
"PropertyDefinitionCollection",
"InstructionCollection",
"ExceptionHandlerCollection",
"VariableDefinitionCollection",
"ArrayDimensionCollection",
"CustomAttributeCollection",
"ExternTypeCollection",
"NestedTypeCollection",
"SecurityDeclarationCollection",
"MemberReferenceCollection",
"GenericParameterCollection",
"GenericArgumentCollection",
"ConstraintCollection"
]
$types = [
"AssemblyDefinition",
"ArrayDimension",
"ArrayType",
"AssemblyLinkedResource",
"AssemblyNameReference",
"AssemblyNameDefinition",
"CallSite",
"CustomAttribute",
"EmbeddedResource",
"EventDefinition",
"EventReference",
"FieldDefinition",
"FieldReference",
"FunctionPointerType",
"GenericInstanceMethod",
"GenericInstanceType",
"GenericParameter",
"LinkedResource",
"MethodDefinition",
"MethodReference",
"MethodReturnType",
"ModifierOptional",
"ModifierRequired",
"ModuleDefinition",
"ModuleReference",
"ParameterDefinition",
"ParameterReference",
"PinnedType",
"PInvokeInfo",
"PropertyDefinition",
"PropertyReference",
"ReferenceType",
"Resource",
"SecurityDeclaration",
"TypeDefinition",
"TypeReference",
"TypeSpecification",
"Instruction",
"ExceptionHandler",
"MethodBody",
"VariableDefinition",
"VariableReference"
]
def iface(name)
return "I" + name
end
def bang(buffer, re, str)
nl = "([\\W])"
buffer.gsub!(Regexp.new("#{nl}(#{re})#{nl}"), "\\1" + str + "\\3")
end
def process_replaces(buffer)
$replaces.each_key { |key|
bang(buffer, key, $replaces[key])
}
end
def process_collections(buffer)
$collections.each { |name|
bang(buffer, iface(name), name)
}
end
def process_types(buffer)
$types.each { |name|
bang(buffer, iface(name), name)
}
end
def process_unbreak(buffer)
$unbreak.each { |name|
bang(buffer, name, iface(name))
}
end
def process(file)
buffer = ""
original = ""
File.open(file, File::RDONLY) { |f|
original = f.read()
buffer = original.clone
process_replaces(buffer)
process_collections(buffer)
process_types(buffer)
}
File.open(file, File::WRONLY | File::TRUNC) { |f|
f.write(buffer)
puts("#{file} processed")
} if (original != buffer)
end
Dir[File.join(dir, "**", "*.*")].each { |file|
process(file) if not File.directory?(file)
}

608
lib/cecil-0.6/src/Mono.Cecil/CodeGen/cecil.xml

@ -0,0 +1,608 @@ @@ -0,0 +1,608 @@
<?xml version="1.0" encoding="utf-8"?>
<cecil>
<types>
<type name="byte" size="1" />
<type name="ushort" size="2" />
<type name="short" size="2" />
<type name="uint" size="4" />
<type name="int" size="4" />
<type name="Mono.Cecil.Binary.DataDirectory" size="8" />
<type name="Mono.Cecil.Binary.ImageCharacteristics" underlying="ushort" size="2" />
<type name="Mono.Cecil.Binary.DebugStoreType" underlying="uint" size="4" />
<type name="Mono.Cecil.Binary.SubSystem" underlying="ushort" size="2" />
<type name="Mono.Cecil.Binary.SectionCharacteristics" underlying="uint" size="4" />
<type name="Mono.Cecil.Binary.RVA" size="4" />
<type name="Mono.Cecil.Binary.RuntimeImage" underlying="uint" size="4" />
<type name="Mono.Cecil.AssemblyHashAlgorithm" underlying="uint" size="4" />
<type name="Mono.Cecil.AssemblyFlags" underlying="uint" size="4" />
<type name="Mono.Cecil.EventAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.TypeAttributes" underlying="uint" size="4" />
<type name="Mono.Cecil.FieldAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.FileAttributes" underlying="uint" size="4" />
<type name="Mono.Cecil.GenericParameterAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.PInvokeAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.ParameterAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.PropertyAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.ManifestResourceAttributes" underlying="uint" size="4" />
<type name="Mono.Cecil.MethodAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.MethodImplAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.MethodSemanticsAttributes" underlying="ushort" size="2" />
<type name="Mono.Cecil.SecurityAction" underlying="short" size="2" />
<type name="Mono.Cecil.Metadata.ElementType" underlying="ushort" size="2" />
<type name="Mono.Cecil.Metadata.MetadataToken" underlying="uint" size="4" />
</types>
<!--
All details about the Metadata
reader and writer of Cecil
-->
<metadata>
<!--
This part contains ECMA spec
about CIL tables and rows positions
in a valid CLI image
-->
<tables>
<table name="Assembly" rid="0x20">
<column name="HashAlgId" type="Mono.Cecil.AssemblyHashAlgorithm" />
<column name="MajorVersion" type="ushort" />
<column name="MinorVersion" type="ushort" />
<column name="BuildNumber" type="ushort" />
<column name="RevisionNumber" type="ushort" />
<column name="Flags" type="Mono.Cecil.AssemblyFlags" />
<column name="PublicKey" type="uint" target="BlobHeap" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Culture" type="uint" target="StringsHeap" />
</table>
<table name="AssemblyOS" rid="0x22">
<column name="OSPlatformID" type="uint" />
<column name="OSMajorVersion" type="uint" />
<column name="OSMinorVersion" type="uint" />
</table>
<table name="AssemblyProcessor" rid="0x21">
<column name="Processor" type="uint" />
</table>
<table name="AssemblyRef" rid="0x23">
<column name="MajorVersion" type="ushort" />
<column name="MinorVersion" type="ushort" />
<column name="BuildNumber" type="ushort" />
<column name="RevisionNumber" type="ushort" />
<column name="Flags" type="Mono.Cecil.AssemblyFlags" />
<column name="PublicKeyOrToken" type="uint" target="BlobHeap" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Culture" type="uint" target="StringsHeap" />
<column name="HashValue" type="uint" target="BlobHeap" />
</table>
<table name="AssemblyRefOS" rid="0x25">
<column name="OSPlatformID" type="uint" />
<column name="OSMajorVersion" type="uint" />
<column name="OSMinorVersion" type="uint" />
<column name="AssemblyRef" type="uint" target="AssemblyRef" />
</table>
<table name="AssemblyRefProcessor" rid="0x24">
<column name="Processor" type="uint" />
<column name="AssemblyRef" type="uint" target="AssemblyRef" />
</table>
<table name="ClassLayout" rid="0x0f">
<column name="PackingSize" type="ushort" />
<column name="ClassSize" type="uint" />
<column name="Parent" type="uint" target="TypeDef" />
</table>
<table name="Constant" rid="0x0b">
<column name="Type" type="Mono.Cecil.Metadata.ElementType" />
<column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasConstant" />
<column name="Value" type="uint" target="BlobHeap" />
</table>
<table name="CustomAttribute" rid="0x0c">
<column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasCustomAttribute" />
<column name="Type" type="Mono.Cecil.Metadata.MetadataToken" target="CustomAttributeType" />
<column name="Value" type="uint" target="BlobHeap" />
</table>
<table name="DeclSecurity" rid="0x0e">
<column name="Action" type="Mono.Cecil.SecurityAction" />
<column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasDeclSecurity" />
<column name="PermissionSet" type="uint" target="BlobHeap" />
</table>
<table name="EventMap" rid="0x12">
<column name="Parent" type="uint" target="TypeDef" />
<column name="EventList" type="uint" target="Event" />
</table>
<table name="Event" rid="0x14">
<column name="EventFlags" type="Mono.Cecil.EventAttributes" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="EventType" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" />
</table>
<table name="EventPtr" rid="0x13">
<column name="Event" type="uint" target="Event" />
</table>
<table name="ExportedType" rid="0x27">
<column name="Flags" type="Mono.Cecil.TypeAttributes" />
<column name="TypeDefId" type="uint" />
<column name="TypeName" type="uint" target="StringsHeap" />
<column name="TypeNamespace" type="uint" target="StringsHeap" />
<column name="Implementation" type="Mono.Cecil.Metadata.MetadataToken" target="Implementation" />
</table>
<table name="Field" rid="0x04">
<column name="Flags" type="Mono.Cecil.FieldAttributes" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Signature" type="uint" target="BlobHeap" />
</table>
<table name="FieldLayout" rid="0x10">
<column name="Offset" type="uint" />
<column name="Field" type="uint" target="Field" />
</table>
<table name="FieldMarshal" rid="0x0d">
<column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasFieldMarshal" />
<column name="NativeType" type="uint" target="BlobHeap" />
</table>
<table name="FieldPtr" rid="0x03">
<column name="Field" type="uint" target="Field" />
</table>
<table name="FieldRVA" rid="0x1d">
<column name="RVA" type="Mono.Cecil.Binary.RVA" />
<column name="Field" type="uint" target="Field" />
</table>
<table name="File" rid="0x26">
<column name="Flags" type="Mono.Cecil.FileAttributes" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="HashValue" type="uint" target="BlobHeap" />
</table>
<table name="GenericParam" rid="0x2a" requires="NET_2_0">
<column name="Number" type="ushort" />
<column name="Flags" type="Mono.Cecil.GenericParameterAttributes" />
<column name="Owner" type="Mono.Cecil.Metadata.MetadataToken" target="TypeOrMethodDef" />
<column name="Name" type="uint" target="StringsHeap" />
</table>
<table name="GenericParamConstraint" rid="0x2c" requires="NET_2_0">
<column name="Owner" type="uint" target="GenericParam" />
<column name="Constraint" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" />
</table>
<table name="ImplMap" rid="0x1c">
<column name="MappingFlags" type="Mono.Cecil.PInvokeAttributes" />
<column name="MemberForwarded" type="Mono.Cecil.Metadata.MetadataToken" target="MemberForwarded" />
<column name="ImportName" type="uint" target="StringsHeap" />
<column name="ImportScope" type="uint" target="ModuleRef" />
</table>
<table name="InterfaceImpl" rid="0x09">
<column name="Class" type="uint" target="TypeDef" />
<column name="Interface" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" />
</table>
<table name="ManifestResource" rid="0x28">
<column name="Offset" type="uint" />
<column name="Flags" type="Mono.Cecil.ManifestResourceAttributes" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Implementation" type="Mono.Cecil.Metadata.MetadataToken" target="Implementation" />
</table>
<table name="MemberRef" rid="0x0a">
<column name="Class" type="Mono.Cecil.Metadata.MetadataToken" target="MemberRefParent" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Signature" type="uint" target="BlobHeap" />
</table>
<table name="Method" rid="0x06">
<column name="RVA" type="Mono.Cecil.Binary.RVA" />
<column name="ImplFlags" type="Mono.Cecil.MethodImplAttributes" />
<column name="Flags" type="Mono.Cecil.MethodAttributes" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Signature" type="uint" target="BlobHeap" />
<column name="ParamList" type="uint" target="Param" />
</table>
<table name="MethodImpl" rid="0x19">
<column name="Class" type="uint" target="TypeDef" />
<column name="MethodBody" type="Mono.Cecil.Metadata.MetadataToken" target="MethodDefOrRef" />
<column name="MethodDeclaration" type="Mono.Cecil.Metadata.MetadataToken" target="MethodDefOrRef" />
</table>
<table name="MethodPtr" rid="0x05">
<column name="Method" type="uint" target="Method" />
</table>
<table name="MethodSemantics" rid="0x18">
<column name="Semantics" type="Mono.Cecil.MethodSemanticsAttributes" />
<column name="Method" type="uint" target="Method" />
<column name="Association" type="Mono.Cecil.Metadata.MetadataToken" target="HasSemantics" />
</table>
<table name="MethodSpec" rid="0x2b" requires="NET_2_0">
<column name="Method" type="Mono.Cecil.Metadata.MetadataToken" target="MethodDefOrRef" />
<column name="Instantiation" type="uint" target="BlobHeap" />
</table>
<table name="Module" rid="0x00">
<column name="Generation" type="ushort" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Mvid" type="uint" target="GuidHeap" />
<column name="EncId" type="uint" target="GuidHeap" />
<column name="EncBaseId" type="uint" target="GuidHeap" />
</table>
<table name="ModuleRef" rid="0x1a">
<column name="Name" type="uint" target="StringsHeap" />
</table>
<table name="NestedClass" rid="0x29">
<column name="NestedClass" type="uint" target="TypeDef" />
<column name="EnclosingClass" type="uint" target="TypeDef" />
</table>
<table name="Param" rid="0x08">
<column name="Flags" type="Mono.Cecil.ParameterAttributes" />
<column name="Sequence" type="ushort" />
<column name="Name" type="uint" target="StringsHeap" />
</table>
<table name="ParamPtr" rid="0x07">
<column name="Param" type="uint" target="Param" />
</table>
<table name="Property" rid="0x17">
<column name="Flags" type="Mono.Cecil.PropertyAttributes" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Type" type="uint" target="BlobHeap" />
</table>
<table name="PropertyMap" rid="0x15">
<column name="Parent" type="uint" target="TypeDef" />
<column name="PropertyList" type="uint" target="Property" />
</table>
<table name="PropertyPtr" rid="0x16">
<column name="Property" type="uint" target="Property" />
</table>
<table name="StandAloneSig" rid="0x11">
<column name="Signature" type="uint" target="BlobHeap" />
</table>
<table name="TypeDef" rid="0x02">
<column name="Flags" type="Mono.Cecil.TypeAttributes" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Namespace" type="uint" target="StringsHeap" />
<column name="Extends" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" />
<column name="FieldList" type="uint" target="Field" />
<column name="MethodList" type="uint" target="Method" />
</table>
<table name="TypeRef" rid="0x01">
<column name="ResolutionScope" type="Mono.Cecil.Metadata.MetadataToken" target="ResolutionScope" />
<column name="Name" type="uint" target="StringsHeap" />
<column name="Namespace" type="uint" target="StringsHeap" />
</table>
<table name="TypeSpec" rid="0x1b">
<column name="Signature" type="uint" target="BlobHeap" />
</table>
</tables>
<codedindexes>
<codedindex name="TypeDefOrRef" size="2">
<table name="TypeDef" tag="0" />
<table name="TypeRef" tag="1" />
<table name="TypeSpec" tag="2" />
</codedindex>
<codedindex name="HasConstant" size="2">
<table name="Field" tag="0" />
<table name="Param" tag="1" />
<table name="Property" tag="2" />
</codedindex>
<codedindex name="HasCustomAttribute" size="5">
<table name="Method" tag="0" />
<table name="Field" tag="1" />
<table name="TypeRef" tag="2" />
<table name="TypeDef" tag="3" />
<table name="Param" tag="4" />
<table name="InterfaceImpl" tag="5" />
<table name="MemberRef" tag="6" />
<table name="Module" tag="7" />
<table name="DeclSecurity" tag="8" />
<table name="Property" tag="9" />
<table name="Event" tag="10" />
<table name="StandAloneSig" tag="11" />
<table name="ModuleRef" tag="12" />
<table name="TypeSpec" tag="13" />
<table name="Assembly" tag="14" />
<table name="AssemblyRef" tag="15" />
<table name="File" tag="16" />
<table name="ExportedType" tag="17" />
<table name="ManifestResource" tag="18" />
<table name="GenericParam" tag="19" />
</codedindex>
<codedindex name="HasFieldMarshal" size="1">
<table name="Field" tag="0" />
<table name="Param" tag="1" />
</codedindex>
<codedindex name="HasDeclSecurity" size="2">
<table name="TypeDef" tag="0" />
<table name="Method" tag="1" />
<table name="Assembly" tag="2" />
</codedindex>
<codedindex name="MemberRefParent" size="3">
<table name="TypeDef" tag="0" />
<table name="TypeRef" tag="1" />
<table name="ModuleRef" tag="2" />
<table name="Method" tag="3" />
<table name="TypeSpec" tag="4" />
</codedindex>
<codedindex name="HasSemantics" size="1">
<table name="Event" tag="0" />
<table name="Property" tag="1" />
</codedindex>
<codedindex name="MethodDefOrRef" size="1">
<table name="Method" tag="0" />
<table name="MemberRef" tag="1" />
</codedindex>
<codedindex name="MemberForwarded" size="1">
<table name="Field" tag="0" />
<table name="Method" tag="1" />
</codedindex>
<codedindex name="Implementation" size="2">
<table name="File" tag="0" />
<table name="AssemblyRef" tag="1" />
<table name="ExportedType" tag="2" />
</codedindex>
<codedindex name="CustomAttributeType" size="3">
<table name="Method" tag="2" />
<table name="MemberRef" tag="3" />
</codedindex>
<codedindex name="ResolutionScope" size="2">
<table name="Module" tag="0" />
<table name="ModuleRef" tag="1" />
<table name="AssemblyRef" tag="2" />
<table name="TypeRef" tag="3" />
</codedindex>
<codedindex name="TypeOrMethodDef" size="1" requires="NET_2_0">
<table name="TypeDef" tag="0" />
<table name="Method" tag="1" />
</codedindex>
</codedindexes>
<!--
This part contains all the standards opcodes
-->
<opcodes>
<opcode name="nop" op1="0xff" op2="0x00" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="break" op1="0xff" op2="0x01" flowcontrol="Break" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="ldarg.0" op1="0xff" op2="0x02" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldarg.1" op1="0xff" op2="0x03" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldarg.2" op1="0xff" op2="0x04" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldarg.3" op1="0xff" op2="0x05" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldloc.0" op1="0xff" op2="0x06" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldloc.1" op1="0xff" op2="0x07" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldloc.2" op1="0xff" op2="0x08" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldloc.3" op1="0xff" op2="0x09" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="stloc.0" op1="0xff" op2="0x0a" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="stloc.1" op1="0xff" op2="0x0b" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="stloc.2" op1="0xff" op2="0x0c" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="stloc.3" op1="0xff" op2="0x0d" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="ldarg.s" op1="0xff" op2="0x0e" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldarga.s" op1="0xff" op2="0x0f" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="starg.s" op1="0xff" op2="0x10" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineParam" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="ldloc.s" op1="0xff" op2="0x11" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldloca.s" op1="0xff" op2="0x12" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="stloc.s" op1="0xff" op2="0x13" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineVar" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="ldnull" op1="0xff" op2="0x14" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushref" />
<opcode name="ldc.i4.m1" op1="0xff" op2="0x15" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.0" op1="0xff" op2="0x16" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.1" op1="0xff" op2="0x17" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.2" op1="0xff" op2="0x18" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.3" op1="0xff" op2="0x19" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.4" op1="0xff" op2="0x1a" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.5" op1="0xff" op2="0x1b" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.6" op1="0xff" op2="0x1c" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.7" op1="0xff" op2="0x1d" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.8" op1="0xff" op2="0x1e" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4.s" op1="0xff" op2="0x1f" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i4" op1="0xff" op2="0x20" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldc.i8" op1="0xff" op2="0x21" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineI8" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi8" />
<opcode name="ldc.r4" op1="0xff" op2="0x22" flowcontrol="Next" opcodetype="Primitive" operandtype="ShortInlineR" stackbehaviourpop="Pop0" stackbehaviourpush="Pushr4" />
<opcode name="ldc.r8" op1="0xff" op2="0x23" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineR" stackbehaviourpop="Pop0" stackbehaviourpush="Pushr8" />
<opcode name="dup" op1="0xff" op2="0x25" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push1_push1" />
<opcode name="pop" op1="0xff" op2="0x26" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="jmp" op1="0xff" op2="0x27" flowcontrol="Call" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="call" op1="0xff" op2="0x28" flowcontrol="Call" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Varpop" stackbehaviourpush="Varpush" />
<opcode name="calli" op1="0xff" op2="0x29" flowcontrol="Call" opcodetype="Primitive" operandtype="InlineSig" stackbehaviourpop="Varpop" stackbehaviourpush="Varpush" />
<opcode name="ret" op1="0xff" op2="0x2a" flowcontrol="Return" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Varpop" stackbehaviourpush="Push0" />
<opcode name="br.s" op1="0xff" op2="0x2b" flowcontrol="Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="brfalse.s" op1="0xff" op2="0x2c" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" />
<opcode name="brtrue.s" op1="0xff" op2="0x2d" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" />
<opcode name="beq.s" op1="0xff" op2="0x2e" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bge.s" op1="0xff" op2="0x2f" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bgt.s" op1="0xff" op2="0x30" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="ble.s" op1="0xff" op2="0x31" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="blt.s" op1="0xff" op2="0x32" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bne.un.s" op1="0xff" op2="0x33" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bge.un.s" op1="0xff" op2="0x34" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bgt.un.s" op1="0xff" op2="0x35" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="ble.un.s" op1="0xff" op2="0x36" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="blt.un.s" op1="0xff" op2="0x37" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="br" op1="0xff" op2="0x38" flowcontrol="Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="brfalse" op1="0xff" op2="0x39" flowcontrol="Cond_Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" />
<opcode name="brtrue" op1="0xff" op2="0x3a" flowcontrol="Cond_Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" />
<opcode name="beq" op1="0xff" op2="0x3b" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bge" op1="0xff" op2="0x3c" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bgt" op1="0xff" op2="0x3d" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="ble" op1="0xff" op2="0x3e" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="blt" op1="0xff" op2="0x3f" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bne.un" op1="0xff" op2="0x40" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bge.un" op1="0xff" op2="0x41" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="bgt.un" op1="0xff" op2="0x42" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="ble.un" op1="0xff" op2="0x43" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="blt.un" op1="0xff" op2="0x44" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" />
<opcode name="switch" op1="0xff" op2="0x45" flowcontrol="Cond_Branch" opcodetype="Primitive" operandtype="InlineSwitch" stackbehaviourpop="Popi" stackbehaviourpush="Push0" />
<opcode name="ldind.i1" op1="0xff" op2="0x46" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="ldind.u1" op1="0xff" op2="0x47" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="ldind.i2" op1="0xff" op2="0x48" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="ldind.u2" op1="0xff" op2="0x49" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="ldind.i4" op1="0xff" op2="0x4a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="ldind.u4" op1="0xff" op2="0x4b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="ldind.i8" op1="0xff" op2="0x4c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi8" />
<opcode name="ldind.i" op1="0xff" op2="0x4d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="ldind.r4" op1="0xff" op2="0x4e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushr4" />
<opcode name="ldind.r8" op1="0xff" op2="0x4f" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushr8" />
<opcode name="ldind.ref" op1="0xff" op2="0x50" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushref" />
<opcode name="stind.ref" op1="0xff" op2="0x51" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" />
<opcode name="stind.i1" op1="0xff" op2="0x52" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" />
<opcode name="stind.i2" op1="0xff" op2="0x53" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" />
<opcode name="stind.i4" op1="0xff" op2="0x54" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" />
<opcode name="stind.i8" op1="0xff" op2="0x55" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi8" stackbehaviourpush="Push0" />
<opcode name="stind.r4" op1="0xff" op2="0x56" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popr4" stackbehaviourpush="Push0" />
<opcode name="stind.r8" op1="0xff" op2="0x57" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popr8" stackbehaviourpush="Push0" />
<opcode name="add" op1="0xff" op2="0x58" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="sub" op1="0xff" op2="0x59" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="mul" op1="0xff" op2="0x5a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="div" op1="0xff" op2="0x5b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="div.un" op1="0xff" op2="0x5c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="rem" op1="0xff" op2="0x5d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="rem.un" op1="0xff" op2="0x5e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="and" op1="0xff" op2="0x5f" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="or" op1="0xff" op2="0x60" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="xor" op1="0xff" op2="0x61" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="shl" op1="0xff" op2="0x62" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="shr" op1="0xff" op2="0x63" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="shr.un" op1="0xff" op2="0x64" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="neg" op1="0xff" op2="0x65" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push1" />
<opcode name="not" op1="0xff" op2="0x66" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push1" />
<opcode name="conv.i1" op1="0xff" op2="0x67" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.i2" op1="0xff" op2="0x68" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.i4" op1="0xff" op2="0x69" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.i8" op1="0xff" op2="0x6a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" />
<opcode name="conv.r4" op1="0xff" op2="0x6b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr4" />
<opcode name="conv.r8" op1="0xff" op2="0x6c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr8" />
<opcode name="conv.u4" op1="0xff" op2="0x6d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.u8" op1="0xff" op2="0x6e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" />
<opcode name="callvirt" op1="0xff" op2="0x6f" flowcontrol="Call" opcodetype="Objmodel" operandtype="InlineMethod" stackbehaviourpop="Varpop" stackbehaviourpush="Varpush" />
<opcode name="cpobj" op1="0xff" op2="0x70" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" />
<opcode name="ldobj" op1="0xff" op2="0x71" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Push1" />
<opcode name="ldstr" op1="0xff" op2="0x72" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineString" stackbehaviourpop="Pop0" stackbehaviourpush="Pushref" />
<opcode name="newobj" op1="0xff" op2="0x73" flowcontrol="Call" opcodetype="Objmodel" operandtype="InlineMethod" stackbehaviourpop="Varpop" stackbehaviourpush="Pushref" />
<opcode name="castclass" op1="0xff" op2="0x74" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Pushref" />
<opcode name="isinst" op1="0xff" op2="0x75" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" />
<opcode name="conv.r.un" op1="0xff" op2="0x76" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr8" />
<opcode name="unbox" op1="0xff" op2="0x79" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" />
<opcode name="throw" op1="0xff" op2="0x7a" flowcontrol="Throw" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref" stackbehaviourpush="Push0" />
<opcode name="ldfld" op1="0xff" op2="0x7b" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Popref" stackbehaviourpush="Push1" />
<opcode name="ldflda" op1="0xff" op2="0x7c" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" />
<opcode name="stfld" op1="0xff" op2="0x7d" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Popref_pop1" stackbehaviourpush="Push0" />
<opcode name="ldsfld" op1="0xff" op2="0x7e" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldsflda" op1="0xff" op2="0x7f" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="stsfld" op1="0xff" op2="0x80" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="stobj" op1="0xff" op2="0x81" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi_pop1" stackbehaviourpush="Push0" />
<opcode name="conv.ovf.i1.un" op1="0xff" op2="0x82" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.i2.un" op1="0xff" op2="0x83" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.i4.un" op1="0xff" op2="0x84" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.i8.un" op1="0xff" op2="0x85" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" />
<opcode name="conv.ovf.u1.un" op1="0xff" op2="0x86" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u2.un" op1="0xff" op2="0x87" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u4.un" op1="0xff" op2="0x88" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u8.un" op1="0xff" op2="0x89" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" />
<opcode name="conv.ovf.i.un" op1="0xff" op2="0x8a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u.un" op1="0xff" op2="0x8b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="box" op1="0xff" op2="0x8c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Pop1" stackbehaviourpush="Pushref" />
<opcode name="newarr" op1="0xff" op2="0x8d" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Pushref" />
<opcode name="ldlen" op1="0xff" op2="0x8e" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" />
<opcode name="ldelema" op1="0xff" op2="0x8f" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.i1" op1="0xff" op2="0x90" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.u1" op1="0xff" op2="0x91" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.i2" op1="0xff" op2="0x92" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.u2" op1="0xff" op2="0x93" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.i4" op1="0xff" op2="0x94" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.u4" op1="0xff" op2="0x95" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.i8" op1="0xff" op2="0x96" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi8" />
<opcode name="ldelem.i" op1="0xff" op2="0x97" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" />
<opcode name="ldelem.r4" op1="0xff" op2="0x98" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushr4" />
<opcode name="ldelem.r8" op1="0xff" op2="0x99" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushr8" />
<opcode name="ldelem.ref" op1="0xff" op2="0x9a" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushref" />
<opcode name="stelem.i" op1="0xff" op2="0x9b" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" />
<opcode name="stelem.i1" op1="0xff" op2="0x9c" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" />
<opcode name="stelem.i2" op1="0xff" op2="0x9d" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" />
<opcode name="stelem.i4" op1="0xff" op2="0x9e" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" />
<opcode name="stelem.i8" op1="0xff" op2="0x9f" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi8" stackbehaviourpush="Push0" />
<opcode name="stelem.r4" op1="0xff" op2="0xa0" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popr4" stackbehaviourpush="Push0" />
<opcode name="stelem.r8" op1="0xff" op2="0xa1" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popr8" stackbehaviourpush="Push0" />
<opcode name="stelem.ref" op1="0xff" op2="0xa2" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popref" stackbehaviourpush="Push0" />
<opcode name="ldelem.any" op1="0xff" op2="0xa3" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref_popi" stackbehaviourpush="Push1" requires="NET_2_0" />
<opcode name="stelem.any" op1="0xff" op2="0xa4" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref_popi_popref" stackbehaviourpush="Push0" requires="NET_2_0" />
<opcode name="unbox.any" op1="0xff" op2="0xa5" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Push1" requires="NET_2_0" />
<opcode name="conv.ovf.i1" op1="0xff" op2="0xb3" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u1" op1="0xff" op2="0xb4" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.i2" op1="0xff" op2="0xb5" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u2" op1="0xff" op2="0xb6" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.i4" op1="0xff" op2="0xb7" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u4" op1="0xff" op2="0xb8" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.i8" op1="0xff" op2="0xb9" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" />
<opcode name="conv.ovf.u8" op1="0xff" op2="0xba" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" />
<opcode name="refanyval" op1="0xff" op2="0xc2" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="ckfinite" op1="0xff" op2="0xc3" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr8" />
<opcode name="mkrefany" op1="0xff" op2="0xc6" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Push1" />
<opcode name="ldtoken" op1="0xff" op2="0xd0" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineTok" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="conv.u2" op1="0xff" op2="0xd1" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.u1" op1="0xff" op2="0xd2" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.i" op1="0xff" op2="0xd3" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.i" op1="0xff" op2="0xd4" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="conv.ovf.u" op1="0xff" op2="0xd5" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="add.ovf" op1="0xff" op2="0xd6" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="add.ovf.un" op1="0xff" op2="0xd7" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="mul.ovf" op1="0xff" op2="0xd8" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="mul.ovf.un" op1="0xff" op2="0xd9" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="sub.ovf" op1="0xff" op2="0xda" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="sub.ovf.un" op1="0xff" op2="0xdb" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" />
<opcode name="endfinally" op1="0xff" op2="0xdc" flowcontrol="Return" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="leave" op1="0xff" op2="0xdd" flowcontrol="Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="PopAll" stackbehaviourpush="Push0" />
<opcode name="leave.s" op1="0xff" op2="0xde" flowcontrol="Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="PopAll" stackbehaviourpush="Push0" />
<opcode name="stind.i" op1="0xff" op2="0xdf" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" />
<opcode name="conv.u" op1="0xff" op2="0xe0" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="arglist" op1="0xfe" op2="0x00" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ceq" op1="0xfe" op2="0x01" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" />
<opcode name="cgt" op1="0xfe" op2="0x02" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" />
<opcode name="cgt.un" op1="0xfe" op2="0x03" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" />
<opcode name="clt" op1="0xfe" op2="0x04" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" />
<opcode name="clt.un" op1="0xfe" op2="0x05" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" />
<opcode name="ldftn" op1="0xfe" op2="0x06" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="ldvirtftn" op1="0xfe" op2="0x07" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" />
<opcode name="ldarg" op1="0xfe" op2="0x09" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldarga" op1="0xfe" op2="0x0a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="starg" op1="0xfe" op2="0x0b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineParam" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="ldloc" op1="0xfe" op2="0x0c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" />
<opcode name="ldloca" op1="0xfe" op2="0x0d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="stloc" op1="0xfe" op2="0x0e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineVar" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" />
<opcode name="localloc" op1="0xfe" op2="0x0f" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" />
<opcode name="endfilter" op1="0xfe" op2="0x11" flowcontrol="Return" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Push0" />
<opcode name="unaligned." op1="0xfe" op2="0x12" flowcontrol="Meta" opcodetype="Prefix" operandtype="ShortInlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="volatile." op1="0xfe" op2="0x13" flowcontrol="Meta" opcodetype="Prefix" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="tail." op1="0xfe" op2="0x14" flowcontrol="Meta" opcodetype="Prefix" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="initobj" op1="0xfe" op2="0x15" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Push0" />
<opcode name="constrained." op1="0xfe" op2="0x16" flowcontrol="Next" opcodetype="Prefix" operandtype="InlineTok" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="cpblk" op1="0xfe" op2="0x17" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi_popi" stackbehaviourpush="Push0" />
<opcode name="initblk" op1="0xfe" op2="0x18" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi_popi" stackbehaviourpush="Push0" />
<opcode name="no." op1="0xfe" op2="0x19" flowcontrol="Next" opcodetype="Prefix" operandtype="ShortInlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="rethrow" op1="0xfe" op2="0x1a" flowcontrol="Throw" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
<opcode name="sizeof" op1="0xfe" op2="0x1c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" />
<opcode name="refanytype" op1="0xfe" op2="0x1d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" />
<opcode name="readonly." op1="0xfe" op2="0x1e" flowcontrol="Next" opcodetype="Prefix" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" />
</opcodes>
</metadata>
<!--
This part contains all the collections
that will be used in the Reflection ns
-->
<collections>
<collection type="AssemblyNameReference" container="ModuleDefinition" visit="IReflectionStructure" target="Mono.Cecil" indexed="true" />
<collection type="ModuleReference" container="ModuleDefinition" visit="IReflectionStructure" indexed="true" target="Mono.Cecil" />
<collection type="ModuleDefinition" container="AssemblyDefinition" visit="IReflectionStructure" indexed="true" target="Mono.Cecil" />
<collection type="Resource" container="ModuleDefinition" visit="IReflectionStructure" target="Mono.Cecil" indexed="true" />
<collection type="TypeDefinition" container="ModuleDefinition" visit="IReflection" target="Mono.Cecil" />
<collection type="TypeReference" container="ModuleDefinition" visit="IReflection" target="Mono.Cecil" />
<collection type="TypeReference" container="TypeDefinition" visit="IReflection" name="Interface" indexed="true" target="Mono.Cecil" />
<collection type="ParameterDefinition" container="IMemberReference" visit="IReflection" indexed="true" target="Mono.Cecil" />
<collection type="MethodReference" container="MethodDefinition" visit="IReflection" name="Override" indexed="true" target="Mono.Cecil" />
<collection type="MethodDefinition" container="TypeDefinition" visit="IReflection" indexed="true" target="Mono.Cecil" />
<collection type="MethodDefinition" container="TypeDefinition" visit="IReflection" name="Constructor" indexed="true" target="Mono.Cecil" />
<collection type="EventDefinition" container="TypeDefinition" visit="IReflection" target="Mono.Cecil" indexed="true" />
<collection type="FieldDefinition" container="TypeDefinition" visit="IReflection" target="Mono.Cecil" indexed="true" />
<collection type="PropertyDefinition" container="TypeDefinition" visit="IReflection" target="Mono.Cecil" indexed="true" />
<collection type="Instruction" container="MethodBody" visit="ICode" indexed="true" target="Mono.Cecil.Cil" />
<collection type="ExceptionHandler" container="MethodBody" visit="ICode" indexed="true" target="Mono.Cecil.Cil" />
<collection type="VariableDefinition" container="IVariableDefinitionProvider" visit="ICode" indexed="true" target="Mono.Cecil.Cil" />
<collection type="ArrayDimension" container="ArrayType" target="Mono.Cecil" indexed="true" />
<!-- modified behaviour
<collection type="SecurityDeclaration" container="IHasSecurity" usecontainerinterface="true" target="Mono.Cecil" indexed="true" visit="IReflection" />
-->
<collection type="CustomAttribute" container="ICustomAttributeProvider" usecontainerinterface="true" target="Mono.Cecil" indexed="true" visit="IReflection" />
<collection type="TypeReference" container="ModuleDefinition" target="Mono.Cecil" visit="IReflection" name="ExternType" />
<collection type="TypeDefinition" container="TypeDefinition" target="Mono.Cecil" visit="IReflection" name="NestedType" indexed="true" />
<collection type="MemberReference" container="ModuleDefinition" target="Mono.Cecil" visit="IReflection" indexed="true" />
<collection type="GenericParameter" container="IGenericParameterProvider" usecontainerinterface="true" target="Mono.Cecil" indexed="true" visit="IReflection" />
<collection type="TypeReference" name="GenericArgument" container="IGenericInstance" target="Mono.Cecil" indexed="true" />
<collection type="TypeReference" name="Constraint" container="GenericParameter" target="Mono.Cecil" indexed="true" />
<collection type="Scope" container="IScopeProvider" visit="ICode" target="Mono.Cecil.Cil" indexed="true" />
</collections>
</cecil>

112
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/BaseMetadataVisitor.cs

@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
//
// BaseMetadataVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
public abstract class BaseMetadataVisitor : IMetadataVisitor {
public virtual void VisitMetadataRoot (MetadataRoot root)
{
}
public virtual void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header)
{
}
public virtual void VisitMetadataStreamCollection (MetadataStreamCollection streams)
{
}
public virtual void VisitMetadataStream (MetadataStream stream)
{
}
public virtual void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header)
{
}
public virtual void VisitGuidHeap (GuidHeap heap)
{
}
public virtual void VisitStringsHeap (StringsHeap heap)
{
}
public virtual void VisitTablesHeap (TablesHeap heap)
{
}
public virtual void VisitBlobHeap (BlobHeap heap)
{
}
public virtual void VisitUserStringsHeap (UserStringsHeap heap)
{
}
public virtual void TerminateMetadataRoot (MetadataRoot root)
{
}
}
public abstract class BaseMetadataTableVisitor : IMetadataTableVisitor {
public virtual void VisitTableCollection (TableCollection coll)
{
}
<% $tables.each { |table| %> public virtual void Visit<%=table.table_name%> (<%=table.table_name%> table)
{
}
<% } %> public virtual void TerminateTableCollection (TableCollection coll)
{
}
public abstract IMetadataRowVisitor GetRowVisitor();
}
public abstract class BaseMetadataRowVisitor : IMetadataRowVisitor {
public virtual void VisitRowCollection (RowCollection coll)
{
}
<% $tables.each { |table| %> public virtual void Visit<%=table.row_name%> (<%=table.row_name%> row)
{
}
<% } %> public virtual void TerminateRowCollection (RowCollection coll)
{
}
}
}

37
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Code.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
//
// Code.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public enum Code {
<% $ops.each { |op| %> <%=op.field_name%>,
<% } %> }
}

38
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/CodedIndex.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
//
// CodedIndex.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
public enum CodedIndex {
<% $coded_indexes.each { |ci| %> <%=ci.name%><% if ci != $coded_indexes.last %>,<% end %>
<% }
%> }
}

65
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/IMetadataVisitor.cs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
//
// IMetadataVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
public interface IMetadataVisitor {
void VisitMetadataRoot (MetadataRoot root);
void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header);
void VisitMetadataStreamCollection (MetadataStreamCollection streams);
void VisitMetadataStream (MetadataStream stream);
void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header);
void VisitGuidHeap (GuidHeap heap);
void VisitStringsHeap (StringsHeap heap);
void VisitTablesHeap (TablesHeap heap);
void VisitBlobHeap (BlobHeap heap);
void VisitUserStringsHeap (UserStringsHeap heap);
void TerminateMetadataRoot (MetadataRoot root);
}
public interface IMetadataTableVisitor {
void VisitTableCollection (TableCollection coll);
<% $tables.each { |table| %> void Visit<%=table.table_name%> (<%=table.table_name%> table);
<% } %>
void TerminateTableCollection (TableCollection coll);
IMetadataRowVisitor GetRowVisitor();
}
public interface IMetadataRowVisitor {
void VisitRowCollection (RowCollection coll);
<% $tables.each { |table| %> void Visit<%=table.row_name%> (<%=table.row_name%> row);
<% } %>
void TerminateRowCollection (RowCollection coll);
}
}

296
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/IndexedCollection.cs

@ -0,0 +1,296 @@ @@ -0,0 +1,296 @@
//
// <%=$cur_coll.name%>.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
<%
def member_visibility()
return $cur_coll.type == "Instruction" ? "internal" : "public"
end
def use_event?()
case $cur_coll.name
when "NestedTypeCollection", "MethodDefinitionCollection", "ConstructorCollection", "FieldDefinitionCollection", "EventDefinitionCollection", "PropertyDefinitionCollection"
return true
end
return false
end
%>
namespace <%=$cur_coll.target%> {
using System;
using System.Collections;
using Mono.Cecil.Cil;
public sealed class <%=$cur_coll.name%> : CollectionBase<% if (!$cur_coll.visitable.nil?) then %>, <%=$cur_coll.visitable%><% end %> {
<%=$cur_coll.container_impl%> m_container;<%
if $cur_coll.type == "Instruction" %>
public readonly Instruction Outside = new Instruction (int.MaxValue, OpCodes.Nop);<% end %>
public <%=$cur_coll.type%> this [int index] {
get { return List [index] as <%=$cur_coll.type%>; }
set { List [index] = value; }
}
public <%=$cur_coll.container%> Container {
get { return m_container; }
}
public <%=$cur_coll.name%> (<%=$cur_coll.container_impl%> container)
{
m_container = container;
}
<%= member_visibility() %> void Add (<%=$cur_coll.type%> value)
{<%
if use_event?() %>
Attach (value);
<% end %>
List.Add (value);
}
<%
if use_event?() %>
public new void Clear ()
{
foreach (<%=$cur_coll.type%> item in this)
Detach (item);
base.Clear ();
}
<% end %>
public bool Contains (<%=$cur_coll.type%> value)
{
return List.Contains (value);
}
public int IndexOf (<%=$cur_coll.type%> value)
{
return List.IndexOf (value);
}
<%= member_visibility() %> void Insert (int index, <%=$cur_coll.type%> value)
{<%
if use_event?() %>
Attach (value);
<% end %>
List.Insert (index, value);
}
<%= member_visibility() %> void Remove (<%=$cur_coll.type%> value)
{
List.Remove (value);
<% if use_event?() %>
Detach (value);
<% end %> }
<%
if use_event?() %>
<%= member_visibility() %> new void RemoveAt (int index)
{
<%=$cur_coll.type%> item = this [index];
Remove (item);
}
<% end %>
protected override void OnValidate (object o)
{
if (! (o is <%=$cur_coll.type%>))
throw new ArgumentException ("Must be of type " + typeof (<%=$cur_coll.type%>).FullName);
}
<%
case $cur_coll.item_name
when "MethodDefinition"
%>
public MethodDefinition [] GetMethod (string name)
{
ArrayList ret = new ArrayList ();
foreach (MethodDefinition meth in this)
if (meth.Name == name)
ret.Add (meth);
return ret.ToArray (typeof (MethodDefinition)) as MethodDefinition [];
}
internal MethodDefinition GetMethodInternal (string name, IList parameters)
{
foreach (MethodDefinition meth in this) {
if (meth.Name != name || meth.Parameters.Count != parameters.Count)
continue;
bool match = true;
for (int i = 0; i < parameters.Count; i++) {
string pname;
object param = parameters [i];
if (param is Type)
pname = ReflectionHelper.GetTypeSignature (param as Type);
else if (param is TypeReference)
pname = (param as TypeReference).FullName;
else if (param is ParameterDefinition)
pname = (param as ParameterDefinition).ParameterType.FullName;
else
throw new NotSupportedException ();
if (meth.Parameters [i].ParameterType.FullName != pname) {
match = false;
break;
}
}
if (match)
return meth;
}
return null;
}
public MethodDefinition GetMethod (string name, Type [] parameters)
{
return GetMethodInternal (name, parameters);
}
public MethodDefinition GetMethod (string name, TypeReference [] parameters)
{
return GetMethodInternal (name, parameters);
}
public MethodDefinition GetMethod (string name, ParameterDefinitionCollection parameters)
{
return GetMethodInternal (name, parameters);
}
<%
when "FieldDefinition"
%>
public FieldDefinition GetField (string name)
{
foreach (FieldDefinition field in this)
if (field.Name == name)
return field;
return null;
}
<%
when "Constructor"
%>
internal MethodDefinition GetConstructorInternal (bool isStatic, IList parameters)
{
foreach (MethodDefinition ctor in this) {
if (ctor.IsStatic != isStatic || ctor.Parameters.Count != parameters.Count)
continue;
bool match = true;
for (int i = 0; i < parameters.Count; i++) {
string pname;
object param = parameters [i];
if (param is Type)
pname = ReflectionHelper.GetTypeSignature (param as Type);
else if (param is TypeReference)
pname = (param as TypeReference).FullName;
else if (param is ParameterDefinition)
pname = (param as ParameterDefinition).ParameterType.FullName;
else
throw new NotSupportedException ();
if (ctor.Parameters [i].ParameterType.FullName != pname) {
match = false;
break;
}
}
if (match)
return ctor;
}
return null;
}
public MethodDefinition GetConstructor (bool isStatic, Type [] parameters)
{
return GetConstructorInternal (isStatic, parameters);
}
public MethodDefinition GetConstructor (bool isStatic, TypeReference [] parameters)
{
return GetConstructorInternal (isStatic, parameters);
}
public MethodDefinition GetConstructor (bool isStatic, ParameterDefinitionCollection parameters)
{
return GetConstructorInternal (isStatic, parameters);
}
<%
when "EventDefinition"
%>
public EventDefinition GetEvent (string name)
{
foreach (EventDefinition evt in this)
if (evt.Name == name)
return evt;
return null;
}
<%
when "PropertyDefinition"
%>
public PropertyDefinition [] GetProperties (string name)
{
ArrayList ret = new ArrayList ();
foreach (PropertyDefinition prop in this)
if (prop.Name == name)
ret.Add (prop);
return ret.ToArray (typeof (PropertyDefinition)) as PropertyDefinition [];
}
<%
end
if use_event?()
%>
void Attach (MemberReference member)
{
if (member.DeclaringType != null)
throw new ReflectionException ("Member already attached, clone it instead");
member.DeclaringType = m_container;
}
void Detach (MemberReference member)
{
member.DeclaringType = null;
}
<% end
if !$cur_coll.visitor.nil? then %>
public void Accept (<%=$cur_coll.visitor%> visitor)
{
visitor.<%=$cur_coll.visitThis%> (this);
}
<% end %> }
}

110
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataRowReader.cs

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
//
// MetadataRowReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
using System;
using System.Collections;
using System.IO;
using Mono.Cecil.Binary;
class MetadataRowReader : BaseMetadataRowVisitor {
MetadataTableReader m_mtrv;
BinaryReader m_binaryReader;
MetadataRoot m_metadataRoot;
IDictionary m_ciCache;
int m_blobHeapIdxSz;
int m_stringsHeapIdxSz;
int m_guidHeapIdxSz;
public MetadataRowReader (MetadataTableReader mtrv)
{
m_mtrv = mtrv;
m_binaryReader = mtrv.GetReader ();
m_metadataRoot = mtrv.GetMetadataRoot ();
m_ciCache = new Hashtable ();
}
int GetIndexSize (int rid)
{
return m_mtrv.GetNumberOfRows (rid) < (1 << 16) ? 2 : 4;
}
int GetCodedIndexSize (CodedIndex ci)
{
return Utilities.GetCodedIndexSize (ci,
new Utilities.TableRowCounter (m_mtrv.GetNumberOfRows), m_ciCache);
}
uint ReadByIndexSize (int size)
{
if (size == 2) {
return (uint) m_binaryReader.ReadUInt16 ();
} else if (size == 4) {
return m_binaryReader.ReadUInt32 ();
} else {
throw new MetadataFormatException ("Non valid size for indexing");
}
}
public override void VisitRowCollection (RowCollection coll)
{
m_blobHeapIdxSz = m_metadataRoot.Streams.BlobHeap != null ?
m_metadataRoot.Streams.BlobHeap.IndexSize : 2;
m_stringsHeapIdxSz = m_metadataRoot.Streams.StringsHeap != null ?
m_metadataRoot.Streams.StringsHeap.IndexSize : 2;
m_guidHeapIdxSz = m_metadataRoot.Streams.GuidHeap != null ?
m_metadataRoot.Streams.GuidHeap.IndexSize : 2;
}
<% $tables.each { |table| %> public override void Visit<%=table.row_name%> (<%=table.row_name%> row)
{
<% table.columns.each { |col|
if (col.target.nil?)
%> row.<%=col.property_name%> = <%=col.read_binary("m_binaryReader")%>;
<% elsif (col.target == "BlobHeap")
%> row.<%=col.property_name%> = ReadByIndexSize (m_blobHeapIdxSz);
<% elsif (col.target == "StringsHeap")
%> row.<%=col.property_name%> = ReadByIndexSize (m_stringsHeapIdxSz);
<% elsif (col.target == "GuidHeap")
%> row.<%=col.property_name%> = ReadByIndexSize (m_guidHeapIdxSz);
<% elsif (col.type == "MetadataToken")
%> row.<%=col.property_name%> = Utilities.GetMetadataToken (CodedIndex.<%=col.target%>,
ReadByIndexSize (GetCodedIndexSize (CodedIndex.<%=col.target%>)));
<% else
%> row.<%=col.property_name%> = ReadByIndexSize (GetIndexSize (<%=col.target%>Table.RId));
<% end
}%> }
<% } %> }
}

145
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataRowWriter.cs

@ -0,0 +1,145 @@ @@ -0,0 +1,145 @@
//
// MetadataRowWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
using System;
using System.Collections;
using Mono.Cecil.Binary;
class MetadataRowWriter : BaseMetadataRowVisitor {
MetadataRoot m_root;
MemoryBinaryWriter m_binaryWriter;
IDictionary m_ciCache;
int m_blobHeapIdxSz;
int m_stringsHeapIdxSz;
int m_guidHeapIdxSz;
public MetadataRowWriter (MetadataTableWriter mtwv)
{
m_binaryWriter = mtwv.GetWriter ();
m_root = mtwv.GetMetadataRoot ();
m_ciCache = new Hashtable ();
}
void WriteBlobPointer (uint pointer)
{
WriteByIndexSize (pointer, m_blobHeapIdxSz);
}
void WriteStringPointer (uint pointer)
{
WriteByIndexSize (pointer, m_stringsHeapIdxSz);
}
void WriteGuidPointer (uint pointer)
{
WriteByIndexSize (pointer, m_guidHeapIdxSz);
}
void WriteTablePointer (uint pointer, int rid)
{
WriteByIndexSize (pointer, GetNumberOfRows (rid) < (1 << 16) ? 2 : 4);
}
void WriteMetadataToken (MetadataToken token, CodedIndex ci)
{
WriteByIndexSize (Utilities.CompressMetadataToken (ci, token),
Utilities.GetCodedIndexSize (
ci, new Utilities.TableRowCounter (GetNumberOfRows), m_ciCache));
}
int GetNumberOfRows (int rid)
{
IMetadataTable t = m_root.Streams.TablesHeap [rid];
if (t == null || t.Rows == null)
return 0;
return t.Rows.Count;
}
void WriteByIndexSize (uint value, int size)
{
if (size == 4)
m_binaryWriter.Write (value);
else if (size == 2)
m_binaryWriter.Write ((ushort) value);
else
throw new MetadataFormatException ("Non valid size for indexing");
}
<% $tables.each { |table|
parameters = ""
table.columns.each { |col|
parameters += col.type
parameters += " "
parameters += col.field_name[1..col.field_name.length]
parameters += ", " if (table.columns.last != col)
}
%> public <%=table.row_name%> Create<%=table.row_name%> (<%=parameters%>)
{
<%=table.row_name%> row = new <%=table.row_name%> ();
<% table.columns.each { |col| %> row.<%=col.property_name%> = <%=col.field_name[1..col.field_name.length]%>;
<% } %> return row;
}
<% } %> public override void VisitRowCollection (RowCollection coll)
{
m_blobHeapIdxSz = m_root.Streams.BlobHeap != null ?
m_root.Streams.BlobHeap.IndexSize : 2;
m_stringsHeapIdxSz = m_root.Streams.StringsHeap != null ?
m_root.Streams.StringsHeap.IndexSize : 2;
m_guidHeapIdxSz = m_root.Streams.GuidHeap != null ?
m_root.Streams.GuidHeap.IndexSize : 2;
}
<% $tables.each { |table| %> public override void Visit<%=table.row_name%> (<%=table.row_name%> row)
{
<% table.columns.each { |col|
if (col.target.nil?)
%> <%=col.write_binary("row", "m_binaryWriter")%>;
<% elsif (col.target == "BlobHeap")
%> WriteBlobPointer (row.<%=col.property_name%>);
<% elsif (col.target == "StringsHeap")
%> WriteStringPointer (row.<%=col.property_name%>);
<% elsif (col.target == "GuidHeap")
%> WriteGuidPointer (row.<%=col.property_name%>);
<% elsif (col.type == "MetadataToken")
%> WriteMetadataToken (row.<%=col.property_name%>, CodedIndex.<%=col.target%>);
<% else
%> WriteTablePointer (row.<%=col.property_name%>, <%=col.target%>Table.RId);
<% end
}%> }
<% } %> }
}

97
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataTableReader.cs

@ -0,0 +1,97 @@ @@ -0,0 +1,97 @@
//
// MetadataTableReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
using System;
using System.Collections;
using System.IO;
class MetadataTableReader : BaseMetadataTableVisitor {
MetadataRoot m_metadataRoot;
TablesHeap m_heap;
MetadataRowReader m_mrrv;
BinaryReader m_binaryReader;
int [] m_rows = new int [TablesHeap.MaxTableCount];
public MetadataTableReader (MetadataReader mrv)
{
m_metadataRoot = mrv.GetMetadataRoot ();
m_heap = m_metadataRoot.Streams.TablesHeap;
m_binaryReader = new BinaryReader (new MemoryStream (m_heap.Data));
m_binaryReader.BaseStream.Position = 24;
m_mrrv = new MetadataRowReader (this);
}
public MetadataRoot GetMetadataRoot ()
{
return m_metadataRoot;
}
public BinaryReader GetReader ()
{
return m_binaryReader;
}
public override IMetadataRowVisitor GetRowVisitor ()
{
return m_mrrv;
}
public int GetNumberOfRows (int rid)
{
return m_rows [rid];
}
<% $tables.each { |table| %>
public <%=table.table_name%> Get<%=table.table_name%> ()
{
return (<%=table.table_name%>) m_heap [<%=table.table_name%>.RId];
}
<% } %>
public override void VisitTableCollection (TableCollection coll)
{
<% $stables.each { |table| %> if (m_heap.HasTable (<%=table.table_name%>.RId)) {
coll.Add (new <%=table.table_name%> ());
m_rows [<%=table.table_name%>.RId] = m_binaryReader.ReadInt32 ();
}
<% } %> }
<% $tables.each { |table| %> public override void Visit<%=table.table_name%> (<%=table.table_name%> table)
{
int number = m_rows [<%=table.table_name%>.RId];
table.Rows = new RowCollection (number);
for (int i = 0; i < number; i++)
table.Rows.Add (new <%=table.row_name%> ());
}
<% } %> }
}

98
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/MetadataTableWriter.cs

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
//
// MetadataTableWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
using System;
using System.Collections;
using Mono.Cecil.Binary;
internal sealed class MetadataTableWriter : BaseMetadataTableVisitor {
MetadataRoot m_root;
TablesHeap m_heap;
MetadataRowWriter m_mrrw;
MemoryBinaryWriter m_binaryWriter;
public MetadataTableWriter (MetadataWriter mrv, MemoryBinaryWriter writer)
{
m_root = mrv.GetMetadataRoot ();
m_heap = m_root.Streams.TablesHeap;
m_binaryWriter = writer;
m_mrrw = new MetadataRowWriter (this);
}
public MetadataRoot GetMetadataRoot ()
{
return m_root;
}
public override IMetadataRowVisitor GetRowVisitor ()
{
return m_mrrw;
}
public MemoryBinaryWriter GetWriter ()
{
return m_binaryWriter;
}
void InitializeTable (IMetadataTable table)
{
table.Rows = new RowCollection ();
m_heap.Valid |= 1L << table.Id;
m_heap.Tables.Add (table);
}
void WriteCount (int rid)
{
if (m_heap.HasTable (rid))
m_binaryWriter.Write (m_heap [rid].Rows.Count);
}
<% $tables.each { |table| %> public <%=table.table_name%> Get<%=table.table_name%> ()
{
<%=table.table_name%> table = m_heap [<%=table.table_name%>.RId] as <%=table.table_name%>;
if (table != null)
return table;
table = new <%=table.table_name%> ();
InitializeTable (table);
return table;
}
<% } %> public override void VisitTableCollection (TableCollection coll)
{
<% $stables.each { |table| %> WriteCount (<%=table.table_name%>.RId);
<% } %> }
}
}

232
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/NamedCollection.cs

@ -0,0 +1,232 @@ @@ -0,0 +1,232 @@
//
// <%=$cur_coll.name%>.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
<%
def use_event?()
case $cur_coll.name
when "TypeDefinitionCollection", "TypeReferenceCollection", "ExternTypeCollection"
return true
end
return false
end
%>
namespace <%=$cur_coll.target%> {
using System;
using System.Collections;
using System.Collections.Specialized;
using Mono.Cecil.Cil;
using Hcp = Mono.Cecil.HashCodeProvider;
using Cmp = System.Collections.Comparer;
public sealed class <%=$cur_coll.name%> : NameObjectCollectionBase, IList<% if (!$cur_coll.visitable.nil?) then %>, <%=$cur_coll.visitable%><% end %> {
<%=$cur_coll.container%> m_container;
public <%=$cur_coll.type%> this [int index] {
get { return this.BaseGet (index) as <%=$cur_coll.type%>; }
set { this.BaseSet (index, value); }
}
public <%=$cur_coll.type%> this [string fullName] {
get { return this.BaseGet (fullName) as <%=$cur_coll.type%>; }
set { this.BaseSet (fullName, value); }
}
public <%=$cur_coll.container%> Container {
get { return m_container; }
}
public bool IsSynchronized {
get { return false; }
}
public object SyncRoot {
get { return this; }
}
bool IList.IsReadOnly {
get { return false; }
}
bool IList.IsFixedSize {
get { return false; }
}
object IList.this [int index] {
get { return BaseGet (index); }
set {
Check (value);
BaseSet (index, value);
}
}
public <%=$cur_coll.name%> (<%=$cur_coll.container%> container) :
base (Hcp.Instance, Cmp.Default)
{
m_container = container;
}
public void Add (<%=$cur_coll.type%> value)
{
if (value == null)
throw new ArgumentNullException ("value");
<% if use_event?() %>Attach (value);<% end %>
this.BaseAdd (value.FullName, value);
}
public void Clear ()
{<%
if use_event?() %>
foreach (<%=$cur_coll.type%> item in this)
Detach (item);
<% end %>
this.BaseClear ();
}
public bool Contains (<%=$cur_coll.type%> value)
{
return Contains (value.FullName);
}
public bool Contains (string fullName)
{
return this.BaseGet (fullName) != null;
}
public int IndexOf (<%=$cur_coll.type%> value)
{
string [] keys = this.BaseGetAllKeys ();
return Array.IndexOf (keys, value.FullName, 0, keys.Length);
}
public void Remove (<%=$cur_coll.type%> value)
{
this.BaseRemove (value.FullName);
<% if use_event?() %>
Detach (value);
<% end %> }
public void RemoveAt (int index)
{
<%=$cur_coll.type%> item = this [index];
Remove (item);
<% if use_event?() %>
Detach (item);
<% end %> }
public void CopyTo (Array ary, int index)
{
this.BaseGetAllValues ().CopyTo (ary, index);
}
public new IEnumerator GetEnumerator ()
{
return this.BaseGetAllValues ().GetEnumerator ();
}
<% if !$cur_coll.visitor.nil? then %>
public void Accept (<%=$cur_coll.visitor%> visitor)
{
visitor.<%=$cur_coll.visitThis%> (this);
}
<% end %>
#if CF_1_0 || CF_2_0
internal object [] BaseGetAllValues ()
{
object [] values = new object [this.Count];
for (int i=0; i < values.Length; ++i) {
values [i] = this.BaseGet (i);
}
return values;
}
#endif
void Check (object value)
{
if (!(value is <%=$cur_coll.type%>))
throw new ArgumentException ();
}
int IList.Add (object value)
{
Check (value);
Add (value as <%=$cur_coll.type%>);
return 0;
}
bool IList.Contains (object value)
{
Check (value);
return Contains (value as <%=$cur_coll.type%>);
}
int IList.IndexOf (object value)
{
throw new NotSupportedException ();
}
void IList.Insert (int index, object value)
{
throw new NotSupportedException ();
}
void IList.Remove (object value)
{
Check (value);
Remove (value as <%=$cur_coll.type%>);
}
<%
if use_event?()
%>
void Detach (TypeReference type)
{
type.Module = null;
}
void Attach (TypeReference type)
{
if (type.Module != null)
throw new ReflectionException ("Type is already attached, clone it instead");
type.Module = m_container;<%
if $cur_coll.type == "TypeDefinition" %>
type.AttachToScope (m_container);
<% end %>
}<%
end
%>
}
}

67
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/OpCodes.cs

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
//
// OpCodes.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
<%
oboc = Array.new
tboc = Array.new
$ops.each { |op|
if op.op1 == "0xff"
oboc.push(op)
else
tboc.push(op)
end
}
%>
namespace Mono.Cecil.Cil {
public sealed class OpCodes {
internal static readonly OpCode [] OneByteOpCode = new OpCode [<%=oboc[oboc.length - 1].op2%> + 1];
internal static readonly OpCode [] TwoBytesOpCode = new OpCode [<%=tboc[tboc.length - 1].op2%> + 1];
<% $ops.each { |op| %> public static readonly OpCode <%=op.field_name%> = new OpCode (
"<%=op.name%>", <%=op.op1%>, <%=op.op2%>, <%=op.size%>,
Code.<%=op.field_name%>, <%=op.flowcontrol%>,
<%=op.opcodetype%>, <%=op.operandtype%>,
<%=op.stackbehaviourpop%>, <%=op.stackbehaviourpush%>);
<% } %> OpCodes()
{
}
public static OpCode GetOpCode (Code code)
{
switch (code) {
<% $ops.each { |op| %> case Code.<%=op.field_name%> : return OpCodes.<%=op.field_name%>;
<% } %> default : return OpCodes.Nop;
}
}
}
}

81
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Table.cs

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
//
// <%=$cur_table.table_name%>.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
<% $cur_table.ref_ns.each { |ns| %>
using <%=ns%>;
<% }
%>
public sealed class <%=$cur_table.table_name%> : IMetadataTable {
public const int RId = <%=$cur_table.rid%>;
RowCollection m_rows;
public <%=$cur_table.row_name%> this [int index] {
get { return m_rows [index] as <%=$cur_table.row_name%>; }
set { m_rows [index] = value; }
}
public RowCollection Rows {
get { return m_rows; }
set { m_rows = value; }
}
public int Id {
get { return RId; }
}
internal <%=$cur_table.table_name%> ()
{
}
public void Accept (IMetadataTableVisitor visitor)
{
visitor.Visit<%=$cur_table.table_name%> (this);
this.Rows.Accept (visitor.GetRowVisitor ());
}
}
public sealed class <%=$cur_table.row_name%> : IMetadataRow {
<% $cur_table.columns.each { |col| %> public <%=col.type%> <%=col.property_name%>;
<% } %>
internal <%=$cur_table.row_name%> ()
{
}
public void Accept (IMetadataRowVisitor visitor)
{
visitor.Visit<%=$cur_table.row_name%> (this);
}
}
}

116
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Tests.cs

@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
//
// Tests.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen-tests.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Tests {
using System;
using System.IO;
using System.Collections;
using NUnit.Framework;
using Mono.Cecil;
class Language {
string m_compiler;
string m_command;
public string Compiler {
get { return m_compiler; }
}
public string Command {
get { return m_command; }
}
public Language (string compiler, string command)
{
m_compiler = compiler;
m_command = command;
}
static IDictionary m_languages = new Hashtable ();
static Language ()
{
<%
$languages.each { |l|
%>
m_languages.Add ("<%= l.name %>", new Language (
"<%= l.compiler %>",
"<%= l.command %>"
));
<%
}
%>
}
public static Language GetLanguage (string name)
{
return (Language) m_languages [name];
}
}
class TestCase {
Language m_lang;
FileInfo m_file;
public TestCase (Language lang, string file)
{
m_lang = lang;
m_file = new FileInfo (file);
}
}
[TestFixture]
class GeneratedTests {
void Test (TestCase test)
{
}
<%
$tests.each { |test|
%>
[Test]
public void <%= test.method %> ()
{
Test (new TestCase (
Language.GetLanguage ("<%= test.lang.name %>"),
@"<%= test.file %>"));
}
<%
}
%>
}
}

211
lib/cecil-0.6/src/Mono.Cecil/CodeGen/templates/Utilities.cs

@ -0,0 +1,211 @@ @@ -0,0 +1,211 @@
//
// Utilities.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// <%=Time.now%>
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Metadata {
using System;
using System.Collections;
using System.IO;
class Utilities {
Utilities ()
{
}
public static int ReadCompressedInteger (byte [] data, int pos, out int start)
{
int integer = 0;
start = pos;
if ((data [pos] & 0x80) == 0) {
integer = data [pos];
start++;
} else if ((data [pos] & 0x40) == 0) {
integer = (data [start] & ~0x80) << 8;
integer |= data [pos + 1];
start += 2;
} else {
integer = (data [start] & ~0xc0) << 24;
integer |= data [pos + 1] << 16;
integer |= data [pos + 2] << 8;
integer |= data [pos + 3];
start += 4;
}
return integer;
}
public static int WriteCompressedInteger (BinaryWriter writer, int value)
{
if (value < 0x80)
writer.Write ((byte) value);
else if (value < 0x4000) {
writer.Write ((byte) (0x80 | (value >> 8)));
writer.Write ((byte) (value & 0xff));
} else {
writer.Write ((byte) ((value >> 24) | 0xc0));
writer.Write ((byte) ((value >> 16) & 0xff));
writer.Write ((byte) ((value >> 8) & 0xff));
writer.Write ((byte) (value & 0xff));
}
return (int) writer.BaseStream.Position;
}
public static MetadataToken GetMetadataToken (CodedIndex cidx, uint data)
{
uint rid = 0;
switch (cidx) {
<% $coded_indexes.each { |ci| %> case CodedIndex.<%=ci.name%> :
rid = data >> <%=ci.size%>;
switch (data & <%=(2 ** ci.size.to_i - 1).to_s%>) {
<% ci.tables.each { |tbl|
name = tbl.name
if (name == "DeclSecurity")
name = "Permission"
elsif (name == "StandAloneSig")
name = "Signature"
end
%> case <%=tbl.tag%> :
return new MetadataToken (TokenType.<%=name%>, rid);
<% }
%> default :
return MetadataToken.Zero;
}
<% } %> default :
return MetadataToken.Zero;
}
}
public static uint CompressMetadataToken (CodedIndex cidx, MetadataToken token)
{
uint ret = 0;
if (token.RID == 0)
return ret;
switch (cidx) {
<% $coded_indexes.each { |ci| %> case CodedIndex.<%=ci.name%> :
ret = token.RID << <%=ci.size%>;
switch (token.TokenType) {
<% ci.tables.each { |tbl|
name = tbl.name
if (name == "DeclSecurity")
name = "Permission"
elsif (name == "StandAloneSig")
name = "Signature"
end
%> case TokenType.<%=name%> :
return ret | <%=tbl.tag%>;
<% }
%> default :
throw new MetadataFormatException("Non valid Token for <%=ci.name%>");
}
<% } %> default :
throw new MetadataFormatException ("Non valid CodedIndex");
}
}
internal static Type GetCorrespondingTable (TokenType t)
{
switch (t) {
case TokenType.Assembly :
return typeof (AssemblyTable);
case TokenType.AssemblyRef :
return typeof (AssemblyRefTable);
case TokenType.CustomAttribute :
return typeof (CustomAttributeTable);
case TokenType.Event :
return typeof (EventTable);
case TokenType.ExportedType :
return typeof (ExportedTypeTable);
case TokenType.Field :
return typeof (FieldTable);
case TokenType.File :
return typeof (FileTable);
case TokenType.InterfaceImpl :
return typeof (InterfaceImplTable);
case TokenType.MemberRef :
return typeof (MemberRefTable);
case TokenType.Method :
return typeof (MethodTable);
case TokenType.Module :
return typeof (ModuleTable);
case TokenType.ModuleRef :
return typeof (ModuleRefTable);
case TokenType.Param :
return typeof (ParamTable);
case TokenType.Permission :
return typeof (DeclSecurityTable);
case TokenType.Property :
return typeof (PropertyTable);
case TokenType.Signature :
return typeof (StandAloneSigTable);
case TokenType.TypeDef :
return typeof (TypeDefTable);
case TokenType.TypeRef :
return typeof (TypeRefTable);
case TokenType.TypeSpec :
return typeof (TypeSpecTable);
default :
return null;
}
}
internal delegate int TableRowCounter (int rid);
internal static int GetCodedIndexSize (CodedIndex ci, TableRowCounter rowCounter, IDictionary codedIndexCache)
{
int bits = 0, max = 0;
if (codedIndexCache [ci] != null)
return (int) codedIndexCache [ci];
int res = 0;
int [] rids;
switch (ci) {
<% $coded_indexes.each { |ci| %> case CodedIndex.<%=ci.name%> :
bits = <%=ci.size%>;
rids = new int [<%=ci.tables.length%>];
<% ci.tables.each_with_index { |tbl, i|
%> rids [<%=i%>] = <%=tbl.name%>Table.RId;
<% }
%> break;
<% } %> default :
throw new MetadataFormatException ("Non valid CodedIndex");
}
for (int i = 0; i < rids.Length; i++) {
int rows = rowCounter (rids [i]);
if (rows > max) max = rows;
}
res = max < (1 << (16 - bits)) ? 2 : 4;
codedIndexCache [ci] = res;
return res;
}
}
}

12
lib/cecil-0.6/src/Mono.Cecil/Makefile

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
thisdir = class/Mono.Cecil
include ../../build/rules.make
LIBRARY = Mono.Cecil.dll
LIBRARY_SNK = ../mono.snk
LIBRARY_PACKAGE = none
LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll -keyfile:$(LIBRARY_SNK)
NO_TEST = yes
include ../../build/library.make

101
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/BaseImageVisitor.cs

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
//
// BaseImageVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public abstract class BaseImageVisitor : IBinaryVisitor {
public virtual void VisitImage (Image img)
{
}
public virtual void VisitDOSHeader (DOSHeader header)
{
}
public virtual void VisitPEFileHeader (PEFileHeader header)
{
}
public virtual void VisitPEOptionalHeader (PEOptionalHeader header)
{
}
public virtual void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
{
}
public virtual void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
{
}
public virtual void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
{
}
public virtual void VisitSectionCollection (SectionCollection coll)
{
}
public virtual void VisitSection (Section section)
{
}
public virtual void VisitImportAddressTable (ImportAddressTable iat)
{
}
public virtual void VisitDebugHeader (DebugHeader dh)
{
}
public virtual void VisitCLIHeader (CLIHeader header)
{
}
public virtual void VisitImportTable (ImportTable it)
{
}
public virtual void VisitImportLookupTable (ImportLookupTable ilt)
{
}
public virtual void VisitHintNameTable (HintNameTable hnt)
{
}
public virtual void VisitExportTable (ExportTable et)
{
}
public virtual void TerminateImage (Image img)
{
}
}
}

68
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/CLIHeader.cs

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
//
// CLIHeader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public sealed class CLIHeader : IHeader, IBinaryVisitable {
public uint Cb;
public ushort MajorRuntimeVersion;
public ushort MinorRuntimeVersion;
public DataDirectory Metadata;
public RuntimeImage Flags;
public uint EntryPointToken;
public DataDirectory Resources;
public DataDirectory StrongNameSignature;
public DataDirectory CodeManagerTable;
public DataDirectory VTableFixups;
public DataDirectory ExportAddressTableJumps;
public DataDirectory ManagedNativeHeader;
public byte [] ImageHash;
internal CLIHeader ()
{
}
public void SetDefaultValues ()
{
Cb = 0x48;
MajorRuntimeVersion = 2;
MinorRuntimeVersion = 0;
Flags = RuntimeImage.ILOnly;
CodeManagerTable = DataDirectory.Zero;
ExportAddressTableJumps = DataDirectory.Zero;
ManagedNativeHeader = DataDirectory.Zero;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitCLIHeader (this);
}
}
}

119
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/CopyImageVisitor.cs

@ -0,0 +1,119 @@ @@ -0,0 +1,119 @@
//
// CopyImageVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
class CopyImageVisitor : BaseImageVisitor {
Image m_newImage;
Image m_originalImage;
public CopyImageVisitor (Image originalImage)
{
m_originalImage = originalImage;
}
public override void VisitImage (Image img)
{
m_newImage = img;
if (m_originalImage.DebugHeader != null)
m_newImage.AddDebugHeader ();
}
public override void VisitDebugHeader (DebugHeader dbgHeader)
{
DebugHeader old = m_originalImage.DebugHeader;
dbgHeader.Age = old.Age;
dbgHeader.Characteristics = old.Characteristics;
dbgHeader.FileName = old.FileName;
dbgHeader.Signature = old.Signature;
dbgHeader.TimeDateStamp = ImageInitializer.TimeDateStampFromEpoch();
dbgHeader.Type = old.Type;
}
public override void VisitSectionCollection (SectionCollection sections)
{
Section old = null;
foreach (Section s in m_originalImage.Sections)
if (s.Name == Section.Resources)
old = s;
if (old == null)
return;
Section rsrc = new Section ();
rsrc.Characteristics = old.Characteristics;
rsrc.Name = old.Name;
sections.Add (rsrc);
}
public override void TerminateImage (Image img)
{
if (m_originalImage.ResourceDirectoryRoot == null)
return;
m_newImage.ResourceDirectoryRoot = CloneResourceDirectoryTable (m_originalImage.ResourceDirectoryRoot);
}
ResourceDirectoryTable CloneResourceDirectoryTable (ResourceDirectoryTable old)
{
ResourceDirectoryTable rdt = new ResourceDirectoryTable ();
foreach (ResourceDirectoryEntry oldEntry in old.Entries)
rdt.Entries.Add (CloneResourceDirectoryEntry (oldEntry));
return rdt;
}
ResourceDirectoryEntry CloneResourceDirectoryEntry (ResourceDirectoryEntry old)
{
ResourceDirectoryEntry rde;
if (old.IdentifiedByName)
rde = new ResourceDirectoryEntry(old.Name);
else
rde = new ResourceDirectoryEntry (old.ID);
if (old.Child is ResourceDirectoryTable)
rde.Child = CloneResourceDirectoryTable (old.Child as ResourceDirectoryTable);
else
rde.Child = CloneResourceDataEntry (old.Child as ResourceDataEntry);
return rde;
}
ResourceDataEntry CloneResourceDataEntry (ResourceDataEntry old)
{
ResourceDataEntry rde = new ResourceDataEntry ();
rde.Size = old.Size;
rde.Codepage = old.Codepage;
rde.ResourceData = old.ResourceData;
return rde;
}
}
}

75
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DOSHeader.cs

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
//
// DOSHeader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public sealed class DOSHeader : IHeader, IBinaryVisitable {
public byte [] Start;
public byte [] End;
public uint Lfanew;
internal DOSHeader ()
{
}
public void SetDefaultValues ()
{
Start = new byte [60] {
0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff,
0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
Lfanew = 128;
End = new byte [64] {
0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09,
0xcd, 0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21,
0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x72,
0x6f, 0x67, 0x72, 0x61, 0x6d, 0x20, 0x63,
0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x62,
0x65, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x69,
0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20, 0x6d,
0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00
};
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitDOSHeader (this);
}
}
}

87
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DataDirectory.cs

@ -0,0 +1,87 @@ @@ -0,0 +1,87 @@
//
// DataDirectory.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using Mono.Cecil.Metadata;
public struct DataDirectory {
public static readonly DataDirectory Zero = new DataDirectory(RVA.Zero, 0);
RVA m_virtualAddress;
uint m_size;
public RVA VirtualAddress {
get { return m_virtualAddress; }
set { m_virtualAddress = value; }
}
public uint Size {
get { return m_size; }
set { m_size = value; }
}
public DataDirectory (RVA virtualAddress, uint size)
{
m_virtualAddress = virtualAddress;
m_size = size;
}
public override int GetHashCode ()
{
return (m_virtualAddress.GetHashCode () ^ (int) m_size << 1);
}
public override bool Equals (object other)
{
if (other is DataDirectory) {
DataDirectory odd = (DataDirectory)other;
return (this.m_virtualAddress == odd.m_virtualAddress &&
this.m_size == odd.m_size);
}
return false;
}
public override string ToString ()
{
return string.Format ("{0} [{1}]",
m_virtualAddress.ToString (), m_size.ToString ("X"));
}
public static bool operator == (DataDirectory one, DataDirectory other)
{
return one.Equals (other);
}
public static bool operator != (DataDirectory one, DataDirectory other)
{
return !one.Equals (other);
}
}
}

73
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DebugHeader.cs

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
//
// DebugHeader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
public sealed class DebugHeader : IHeader, IBinaryVisitable {
public uint Characteristics;
public uint TimeDateStamp;
public ushort MajorVersion;
public ushort MinorVersion;
public DebugStoreType Type;
public uint SizeOfData;
public RVA AddressOfRawData;
public uint PointerToRawData;
public uint Magic;
public Guid Signature;
public uint Age;
public string FileName;
internal DebugHeader ()
{
}
public void SetDefaultValues ()
{
Characteristics = 0;
this.Magic = 0x53445352;
this.Age = 0;
this.Type = DebugStoreType.CodeView;
this.FileName = string.Empty;
}
public uint GetSize ()
{
return 0x34 + (uint) FileName.Length + 1;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitDebugHeader (this);
}
}
}

45
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/DebugStoreType.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
//
// DebugStoreType.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public enum DebugStoreType : uint {
Unknown = 0x00000000,
COFF = 0x00000001,
CodeView = 0x00000002,
FPO = 0x00000003,
Misc = 0x00000004,
Exception = 0x00000005,
Fixup = 0x00000006,
OMAPToSrc = 0x00000007,
OMAPFromSrc = 0x00000008,
Borland = 0x00000009,
Reserved10 = 0x0000000a,
CLSID = 0x0000000b
}
}

59
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ExportTable.cs

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
//
// ExportTable.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public sealed class ExportTable : IBinaryVisitable {
public uint Characteristics;
public uint TimeDateStamp;
public ushort MajorVersion;
public ushort MinorVersion;
public string Name;
public uint Base;
public uint NumberOfFunctions;
public uint NumberOfNames;
public RVA AddressOfFunctions;
public RVA AddressOfNames;
public RVA AddressOfNameOrdinals;
public RVA [] AddressesOfFunctions;
public RVA [] AddressesOfNames;
public ushort [] NameOrdinals;
public string [] Names;
internal ExportTable ()
{
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitExportTable (this);
}
}
}

35
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitable.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
//
// IBinaryVisitable.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public interface IBinaryVisitable {
void Accept (IBinaryVisitor visitor);
}
}

51
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitor.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
//
// IBinaryVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public interface IBinaryVisitor {
void VisitImage (Image img);
void VisitDOSHeader (DOSHeader header);
void VisitPEFileHeader (PEFileHeader header);
void VisitPEOptionalHeader (PEOptionalHeader header);
void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header);
void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header);
void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header);
void VisitSectionCollection (SectionCollection coll);
void VisitSection (Section section);
void VisitImportAddressTable (ImportAddressTable iat);
void VisitDebugHeader (DebugHeader dh);
void VisitCLIHeader (CLIHeader header);
void VisitImportTable (ImportTable it);
void VisitImportLookupTable (ImportLookupTable ilt);
void VisitHintNameTable (HintNameTable hnt);
void VisitExportTable (ExportTable et);
void TerminateImage (Image img);
}
}

34
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/IHeader.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
//
// IHeader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
internal interface IHeader {
void SetDefaultValues ();
}
}

236
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/Image.cs

@ -0,0 +1,236 @@ @@ -0,0 +1,236 @@
//
// Image.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
using System.IO;
using Mono.Cecil.Metadata;
public sealed class Image : IBinaryVisitable {
DOSHeader m_dosHeader;
PEFileHeader m_peFileHeader;
PEOptionalHeader m_peOptionalHeader;
SectionCollection m_sections;
Section m_textSection;
ImportAddressTable m_importAddressTable;
CLIHeader m_cliHeader;
ImportTable m_importTable;
ImportLookupTable m_importLookupTable;
HintNameTable m_hintNameTable;
ExportTable m_exportTable;
DebugHeader m_debugHeader;
MetadataRoot m_mdRoot;
ResourceDirectoryTable m_rsrcRoot;
FileInfo m_img;
public DOSHeader DOSHeader {
get { return m_dosHeader; }
}
public PEFileHeader PEFileHeader {
get { return m_peFileHeader; }
}
public PEOptionalHeader PEOptionalHeader {
get { return m_peOptionalHeader; }
}
public SectionCollection Sections {
get { return m_sections; }
}
public Section TextSection {
get { return m_textSection; }
set { m_textSection = value; }
}
public ImportAddressTable ImportAddressTable {
get { return m_importAddressTable; }
}
public CLIHeader CLIHeader {
get { return m_cliHeader; }
set { m_cliHeader = value; }
}
public DebugHeader DebugHeader {
get { return m_debugHeader; }
set { m_debugHeader = value; }
}
public MetadataRoot MetadataRoot {
get { return m_mdRoot; }
}
public ImportTable ImportTable {
get { return m_importTable; }
}
public ImportLookupTable ImportLookupTable {
get { return m_importLookupTable; }
}
public HintNameTable HintNameTable {
get { return m_hintNameTable; }
}
public ExportTable ExportTable {
get { return m_exportTable; }
set { m_exportTable = value; }
}
internal ResourceDirectoryTable ResourceDirectoryRoot {
get { return m_rsrcRoot; }
set { m_rsrcRoot = value; }
}
public FileInfo FileInformation {
get { return m_img; }
}
internal Image ()
{
m_dosHeader = new DOSHeader ();
m_peFileHeader = new PEFileHeader ();
m_peOptionalHeader = new PEOptionalHeader ();
m_sections = new SectionCollection ();
m_importAddressTable = new ImportAddressTable ();
m_importTable = new ImportTable ();
m_importLookupTable = new ImportLookupTable ();
m_hintNameTable = new HintNameTable ();
m_mdRoot = new MetadataRoot (this);
}
internal Image (FileInfo img) : this ()
{
m_img = img;
}
public long ResolveVirtualAddress (RVA rva)
{
foreach (Section sect in this.Sections) {
if (rva >= sect.VirtualAddress &&
rva < sect.VirtualAddress + sect.SizeOfRawData)
return rva + sect.PointerToRawData - sect.VirtualAddress;
}
throw new ArgumentOutOfRangeException ("Cannot map the rva to any section");
}
public BinaryReader GetReaderAtVirtualAddress (RVA rva)
{
foreach (Section sect in this.Sections) {
if (rva >= sect.VirtualAddress &&
rva < sect.VirtualAddress + sect.SizeOfRawData) {
BinaryReader br = new BinaryReader (new MemoryStream (sect.Data));
br.BaseStream.Position = rva - sect.VirtualAddress;
return br;
}
}
return null;
}
public void AddDebugHeader ()
{
m_debugHeader = new DebugHeader ();
m_debugHeader.SetDefaultValues ();
}
internal void SetFileInfo (FileInfo file)
{
m_img = file;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitImage (this);
m_dosHeader.Accept (visitor);
m_peFileHeader.Accept (visitor);
m_peOptionalHeader.Accept (visitor);
m_sections.Accept (visitor);
m_importAddressTable.Accept (visitor);
AcceptIfNotNull (m_cliHeader, visitor);
AcceptIfNotNull (m_debugHeader, visitor);
m_importTable.Accept (visitor);
m_importLookupTable.Accept (visitor);
m_hintNameTable.Accept (visitor);
AcceptIfNotNull (m_exportTable, visitor);
visitor.TerminateImage (this);
}
static void AcceptIfNotNull (IBinaryVisitable visitable, IBinaryVisitor visitor)
{
if (visitable == null)
return;
visitable.Accept (visitor);
}
public static Image CreateImage ()
{
Image img = new Image ();
ImageInitializer init = new ImageInitializer (img);
img.Accept (init);
return img;
}
public static Image GetImage (string file)
{
return ImageReader.Read (file).Image;
}
public static Image GetImage (byte [] image)
{
return ImageReader.Read (image).Image;
}
public static Image GetImage (Stream stream)
{
return ImageReader.Read (stream).Image;
}
}
}

57
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageCharacteristics.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
//
// ImageCharacteristics.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
[Flags]
public enum ImageCharacteristics : ushort {
RelocsStripped = 0x0001,
ExecutableImage = 0x0002,
LineNumsStripped = 0x0004,
LocalSymsStripped = 0x0008,
AggressiveWSTrim = 0x0010,
LargeAddressAware = 0x0020,
ReservedForFutureUse = 0x0040,
BytesReversedLo = 0x0080,
_32BitsMachine = 0x0100,
DebugStripped = 0x0200,
RemovableRunFromSwap = 0x0400,
NetRunFromSwap = 0x0800,
System = 0x1000,
Dll = 0x2000,
UPSystemOnly = 0x4000,
BytesReversedHI = 0x8000,
__flags = 0x0002 | 0x0004 | 0x0008 | 0x0100,
CILOnlyDll = 0x2000 | (ushort) __flags,
CILOnlyExe = __flags
}
}

53
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageFormatException.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
//
// ImageFormatException.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
public class ImageFormatException : Exception {
internal ImageFormatException () : base()
{
}
internal ImageFormatException (string message) : base(message)
{
}
internal ImageFormatException (string message, params string[] parameters) :
base(string.Format(message, parameters))
{
}
internal ImageFormatException (string message, Exception inner) :
base(message, inner)
{
}
}
}

139
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageInitializer.cs

@ -0,0 +1,139 @@ @@ -0,0 +1,139 @@
//
// ImageInitializer.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
using Mono.Cecil.Metadata;
class ImageInitializer : BaseImageVisitor {
Image m_image;
MetadataInitializer m_mdinit;
public Image Image {
get { return m_image; }
}
public MetadataInitializer Metadata {
get { return m_mdinit; }
}
public ImageInitializer (Image image)
{
m_image = image;
m_image.CLIHeader = new CLIHeader ();
m_mdinit = new MetadataInitializer (this);
}
public override void VisitDOSHeader (DOSHeader header)
{
header.SetDefaultValues ();
}
public override void VisitPEOptionalHeader (PEOptionalHeader header)
{
header.SetDefaultValues ();
}
public override void VisitPEFileHeader (PEFileHeader header)
{
header.SetDefaultValues ();
header.TimeDateStamp = TimeDateStampFromEpoch ();
}
public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
{
header.SetDefaultValues ();
}
public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
{
header.SetDefaultValues ();
}
public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
{
header.SetDefaultValues ();
}
public override void VisitSectionCollection (SectionCollection coll)
{
Section text = new Section ();
text.Name = Section.Text;
text.Characteristics = SectionCharacteristics.ContainsCode |
SectionCharacteristics.MemoryRead | SectionCharacteristics.MemExecute;
m_image.TextSection = text;
Section reloc = new Section ();
reloc.Name = Section.Relocs;
reloc.Characteristics = SectionCharacteristics.ContainsInitializedData |
SectionCharacteristics.MemDiscardable | SectionCharacteristics.MemoryRead;
coll.Add (text);
coll.Add (reloc);
}
public override void VisitSection (Section sect)
{
sect.SetDefaultValues ();
}
public override void VisitDebugHeader (DebugHeader dh)
{
if (dh != null)
dh.SetDefaultValues ();
}
public override void VisitCLIHeader (CLIHeader header)
{
header.SetDefaultValues ();
m_image.MetadataRoot.Accept (m_mdinit);
}
public override void VisitImportTable (ImportTable it)
{
it.ImportAddressTable = new RVA (0x2000);
}
public override void VisitHintNameTable (HintNameTable hnt)
{
hnt.Hint = 0;
hnt.RuntimeLibrary = HintNameTable.RuntimeCorEE;
hnt.EntryPoint = 0x25ff;
hnt.RVA = new RVA (0x402000);
}
public static uint TimeDateStampFromEpoch ()
{
return (uint) DateTime.UtcNow.Subtract (
new DateTime (1970, 1, 1)).TotalSeconds;
}
}
}

466
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageReader.cs

@ -0,0 +1,466 @@ @@ -0,0 +1,466 @@
//
// ImageReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
using System.IO;
using System.Text;
using Mono.Cecil.Metadata;
class ImageReader : BaseImageVisitor {
MetadataReader m_mdReader;
BinaryReader m_binaryReader;
Image m_image;
public MetadataReader MetadataReader {
get { return m_mdReader; }
}
public Image Image {
get { return m_image; }
}
ImageReader (Image img, BinaryReader reader)
{
m_image = img;
m_binaryReader = reader;
}
static ImageReader Read (Image img, Stream stream)
{
ImageReader reader = new ImageReader (img, new BinaryReader (stream));
img.Accept (reader);
return reader;
}
public static ImageReader Read (string file)
{
if (file == null)
throw new ArgumentNullException ("file");
FileInfo fi = new FileInfo (file);
if (!File.Exists (fi.FullName))
#if CF_1_0 || CF_2_0
throw new FileNotFoundException (fi.FullName);
#else
throw new FileNotFoundException (string.Format ("File '{0}' not found.", fi.FullName), fi.FullName);
#endif
return Read (new Image (fi), new FileStream (
fi.FullName, FileMode.Open,
FileAccess.Read, FileShare.Read));
}
public static ImageReader Read (byte [] image)
{
if (image == null)
throw new ArgumentNullException ("image");
if (image.Length == 0)
throw new ArgumentException ("Empty image array");
return Read (new Image (), new MemoryStream (image));
}
public static ImageReader Read (Stream stream)
{
if (stream == null)
throw new ArgumentNullException ("stream");
if (!stream.CanRead)
throw new ArgumentException ("Can not read from stream");
return Read (new Image (), stream);
}
public BinaryReader GetReader ()
{
return m_binaryReader;
}
public override void VisitImage (Image img)
{
m_mdReader = new MetadataReader (this);
}
void SetPositionToAddress (RVA address)
{
m_binaryReader.BaseStream.Position = m_image.ResolveVirtualAddress (address);
}
public override void VisitDOSHeader (DOSHeader header)
{
header.Start = m_binaryReader.ReadBytes (60);
header.Lfanew = m_binaryReader.ReadUInt32 ();
header.End = m_binaryReader.ReadBytes (64);
m_binaryReader.BaseStream.Position = header.Lfanew;
if (m_binaryReader.ReadUInt16 () != 0x4550 ||
m_binaryReader.ReadUInt16 () != 0)
throw new ImageFormatException ("Invalid PE File Signature");
}
public override void VisitPEFileHeader (PEFileHeader header)
{
header.Machine = m_binaryReader.ReadUInt16 ();
header.NumberOfSections = m_binaryReader.ReadUInt16 ();
header.TimeDateStamp = m_binaryReader.ReadUInt32 ();
header.PointerToSymbolTable = m_binaryReader.ReadUInt32 ();
header.NumberOfSymbols = m_binaryReader.ReadUInt32 ();
header.OptionalHeaderSize = m_binaryReader.ReadUInt16 ();
header.Characteristics = (ImageCharacteristics) m_binaryReader.ReadUInt16 ();
}
ulong ReadIntOrLong ()
{
return m_image.PEOptionalHeader.StandardFields.IsPE64 ?
m_binaryReader.ReadUInt64 () :
m_binaryReader.ReadUInt32 ();
}
RVA ReadRVA ()
{
return m_binaryReader.ReadUInt32 ();
}
DataDirectory ReadDataDirectory ()
{
return new DataDirectory (ReadRVA (), m_binaryReader.ReadUInt32 ());
}
public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
{
header.ImageBase = ReadIntOrLong ();
header.SectionAlignment = m_binaryReader.ReadUInt32 ();
header.FileAlignment = m_binaryReader.ReadUInt32 ();
header.OSMajor = m_binaryReader.ReadUInt16 ();
header.OSMinor = m_binaryReader.ReadUInt16 ();
header.UserMajor = m_binaryReader.ReadUInt16 ();
header.UserMinor = m_binaryReader.ReadUInt16 ();
header.SubSysMajor = m_binaryReader.ReadUInt16 ();
header.SubSysMinor = m_binaryReader.ReadUInt16 ();
header.Reserved = m_binaryReader.ReadUInt32 ();
header.ImageSize = m_binaryReader.ReadUInt32 ();
header.HeaderSize = m_binaryReader.ReadUInt32 ();
header.FileChecksum = m_binaryReader.ReadUInt32 ();
header.SubSystem = (SubSystem) m_binaryReader.ReadUInt16 ();
header.DLLFlags = m_binaryReader.ReadUInt16 ();
header.StackReserveSize = ReadIntOrLong ();
header.StackCommitSize = ReadIntOrLong ();
header.HeapReserveSize = ReadIntOrLong ();
header.HeapCommitSize = ReadIntOrLong ();
header.LoaderFlags = m_binaryReader.ReadUInt32 ();
header.NumberOfDataDir = m_binaryReader.ReadUInt32 ();
}
public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
{
header.Magic = m_binaryReader.ReadUInt16 ();
header.LMajor = m_binaryReader.ReadByte ();
header.LMinor = m_binaryReader.ReadByte ();
header.CodeSize = m_binaryReader.ReadUInt32 ();
header.InitializedDataSize = m_binaryReader.ReadUInt32 ();
header.UninitializedDataSize = m_binaryReader.ReadUInt32 ();
header.EntryPointRVA = ReadRVA ();
header.BaseOfCode = ReadRVA ();
if (!header.IsPE64)
header.BaseOfData = ReadRVA ();
}
public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
{
header.ExportTable = ReadDataDirectory ();
header.ImportTable = ReadDataDirectory ();
header.ResourceTable = ReadDataDirectory ();
header.ExceptionTable = ReadDataDirectory ();
header.CertificateTable = ReadDataDirectory ();
header.BaseRelocationTable = ReadDataDirectory ();
header.Debug = ReadDataDirectory ();
header.Copyright = ReadDataDirectory ();
header.GlobalPtr = ReadDataDirectory ();
header.TLSTable = ReadDataDirectory ();
header.LoadConfigTable = ReadDataDirectory ();
header.BoundImport = ReadDataDirectory ();
header.IAT = ReadDataDirectory ();
header.DelayImportDescriptor = ReadDataDirectory ();
header.CLIHeader = ReadDataDirectory ();
header.Reserved = ReadDataDirectory ();
if (header.CLIHeader != DataDirectory.Zero)
m_image.CLIHeader = new CLIHeader ();
if (header.ExportTable != DataDirectory.Zero)
m_image.ExportTable = new ExportTable ();
}
public override void VisitSectionCollection (SectionCollection coll)
{
for (int i = 0; i < m_image.PEFileHeader.NumberOfSections; i++)
coll.Add (new Section ());
}
public override void VisitSection (Section sect)
{
char [] buffer = new char [8];
int read = 0;
while (read < 8) {
char cur = (char) m_binaryReader.ReadSByte ();
if (cur == '\0') {
m_binaryReader.BaseStream.Position += 8 - read - 1;
break;
}
buffer [read++] = cur;
}
sect.Name = read == 0 ? string.Empty : new string (buffer, 0, read);
if (sect.Name == Section.Text)
m_image.TextSection = sect;
sect.VirtualSize = m_binaryReader.ReadUInt32 ();
sect.VirtualAddress = ReadRVA ();
sect.SizeOfRawData = m_binaryReader.ReadUInt32 ();
sect.PointerToRawData = ReadRVA ();
sect.PointerToRelocations = ReadRVA ();
sect.PointerToLineNumbers = ReadRVA ();
sect.NumberOfRelocations = m_binaryReader.ReadUInt16 ();
sect.NumberOfLineNumbers = m_binaryReader.ReadUInt16 ();
sect.Characteristics = (SectionCharacteristics) m_binaryReader.ReadUInt32 ();
long pos = m_binaryReader.BaseStream.Position;
m_binaryReader.BaseStream.Position = sect.PointerToRawData;
sect.Data = m_binaryReader.ReadBytes ((int) sect.SizeOfRawData);
m_binaryReader.BaseStream.Position = pos;
}
public override void VisitImportAddressTable (ImportAddressTable iat)
{
if (m_image.PEOptionalHeader.DataDirectories.IAT.VirtualAddress == RVA.Zero)
return;
SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.IAT.VirtualAddress);
iat.HintNameTableRVA = ReadRVA ();
}
public override void VisitCLIHeader (CLIHeader header)
{
if (m_image.PEOptionalHeader.DataDirectories.Debug != DataDirectory.Zero) {
m_image.DebugHeader = new DebugHeader ();
VisitDebugHeader (m_image.DebugHeader);
}
SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.CLIHeader.VirtualAddress);
header.Cb = m_binaryReader.ReadUInt32 ();
header.MajorRuntimeVersion = m_binaryReader.ReadUInt16 ();
header.MinorRuntimeVersion = m_binaryReader.ReadUInt16 ();
header.Metadata = ReadDataDirectory ();
header.Flags = (RuntimeImage) m_binaryReader.ReadUInt32 ();
header.EntryPointToken = m_binaryReader.ReadUInt32 ();
header.Resources = ReadDataDirectory ();
header.StrongNameSignature = ReadDataDirectory ();
header.CodeManagerTable = ReadDataDirectory ();
header.VTableFixups = ReadDataDirectory ();
header.ExportAddressTableJumps = ReadDataDirectory ();
header.ManagedNativeHeader = ReadDataDirectory ();
if (header.StrongNameSignature != DataDirectory.Zero) {
SetPositionToAddress (header.StrongNameSignature.VirtualAddress);
header.ImageHash = m_binaryReader.ReadBytes ((int) header.StrongNameSignature.Size);
} else
header.ImageHash = new byte [0];
SetPositionToAddress (m_image.CLIHeader.Metadata.VirtualAddress);
m_image.MetadataRoot.Accept (m_mdReader);
}
public override void VisitDebugHeader (DebugHeader header)
{
if (m_image.PEOptionalHeader.DataDirectories.Debug == DataDirectory.Zero)
return;
long pos = m_binaryReader.BaseStream.Position;
SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.Debug.VirtualAddress);
header.Characteristics = m_binaryReader.ReadUInt32 ();
header.TimeDateStamp = m_binaryReader.ReadUInt32 ();
header.MajorVersion = m_binaryReader.ReadUInt16 ();
header.MinorVersion = m_binaryReader.ReadUInt16 ();
header.Type = (DebugStoreType) m_binaryReader.ReadUInt32 ();
header.SizeOfData = m_binaryReader.ReadUInt32 ();
header.AddressOfRawData = ReadRVA ();
header.PointerToRawData = m_binaryReader.ReadUInt32 ();
m_binaryReader.BaseStream.Position = header.PointerToRawData;
header.Magic = m_binaryReader.ReadUInt32 ();
header.Signature = new Guid (m_binaryReader.ReadBytes (16));
header.Age = m_binaryReader.ReadUInt32 ();
header.FileName = ReadZeroTerminatedString ();
m_binaryReader.BaseStream.Position = pos;
}
string ReadZeroTerminatedString ()
{
StringBuilder sb = new StringBuilder ();
while (true) {
byte chr = m_binaryReader.ReadByte ();
if (chr == 0)
break;
sb.Append ((char) chr);
}
return sb.ToString ();
}
public override void VisitImportTable (ImportTable it)
{
if (m_image.PEOptionalHeader.DataDirectories.ImportTable.VirtualAddress == RVA.Zero)
return;
SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.ImportTable.VirtualAddress);
it.ImportLookupTable = ReadRVA ();
it.DateTimeStamp = m_binaryReader.ReadUInt32 ();
it.ForwardChain = m_binaryReader.ReadUInt32 ();
it.Name = ReadRVA ();
it.ImportAddressTable = ReadRVA ();
}
public override void VisitImportLookupTable (ImportLookupTable ilt)
{
if (m_image.ImportTable.ImportLookupTable == RVA.Zero)
return;
SetPositionToAddress (m_image.ImportTable.ImportLookupTable);
ilt.HintNameRVA = ReadRVA ();
}
public override void VisitHintNameTable (HintNameTable hnt)
{
if (m_image.ImportAddressTable.HintNameTableRVA == RVA.Zero)
return;
SetPositionToAddress (m_image.ImportAddressTable.HintNameTableRVA);
hnt.Hint = m_binaryReader.ReadUInt16 ();
byte [] bytes = m_binaryReader.ReadBytes (11);
hnt.RuntimeMain = Encoding.ASCII.GetString (bytes, 0, bytes.Length);
SetPositionToAddress (m_image.ImportTable.Name);
bytes = m_binaryReader.ReadBytes (11);
hnt.RuntimeLibrary = Encoding.ASCII.GetString (bytes, 0, bytes.Length);
SetPositionToAddress (m_image.PEOptionalHeader.StandardFields.EntryPointRVA);
hnt.EntryPoint = m_binaryReader.ReadUInt16 ();
hnt.RVA = ReadRVA ();
}
public override void VisitExportTable (ExportTable et)
{
SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.ExportTable.VirtualAddress);
et.Characteristics = m_binaryReader.ReadUInt32 ();
et.TimeDateStamp = m_binaryReader.ReadUInt32 ();
et.MajorVersion = m_binaryReader.ReadUInt16 ();
et.MinorVersion = m_binaryReader.ReadUInt16 ();
//et.Name =
m_binaryReader.ReadUInt32 ();
et.Base = m_binaryReader.ReadUInt32 ();
et.NumberOfFunctions = m_binaryReader.ReadUInt32 ();
et.NumberOfNames = m_binaryReader.ReadUInt32 ();
et.AddressOfFunctions = m_binaryReader.ReadUInt32 ();
et.AddressOfNames = m_binaryReader.ReadUInt32 ();
et.AddressOfNameOrdinals = m_binaryReader.ReadUInt32 ();
et.AddressesOfFunctions = ReadArrayOfRVA (et.AddressOfFunctions, et.NumberOfFunctions);
et.AddressesOfNames = ReadArrayOfRVA (et.AddressOfNames, et.NumberOfNames);
et.NameOrdinals = ReadArrayOfUInt16 (et.AddressOfNameOrdinals, et.NumberOfNames);
et.Names = new string [et.NumberOfFunctions];
for (int i = 0; i < et.NumberOfFunctions; i++) {
if (et.AddressesOfFunctions [i] == 0)
continue;
et.Names [i] = ReadFunctionName (et, i);
}
}
string ReadFunctionName (ExportTable et, int index)
{
for (int i = 0; i < et.NumberOfNames; i++) {
if (et.NameOrdinals [i] != index)
continue;
SetPositionToAddress (et.AddressesOfNames [i]);
return ReadZeroTerminatedString ();
}
return string.Empty;
}
ushort [] ReadArrayOfUInt16 (RVA position, uint length)
{
SetPositionToAddress (position);
ushort [] array = new ushort [length];
for (int i = 0; i < length; i++)
array [i] = m_binaryReader.ReadUInt16 ();
return array;
}
RVA [] ReadArrayOfRVA (RVA position, uint length)
{
SetPositionToAddress (position);
RVA [] addresses = new RVA [length];
for (int i = 0; i < length; i++)
addresses [i] = m_binaryReader.ReadUInt32 ();
return addresses;
}
public override void TerminateImage(Image img)
{
m_binaryReader.Close ();
try {
ResourceReader resReader = new ResourceReader (img);
img.ResourceDirectoryRoot = resReader.Read ();
} catch {
img.ResourceDirectoryRoot = null;
}
}
}
}

427
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ImageWriter.cs

@ -0,0 +1,427 @@ @@ -0,0 +1,427 @@
//
// ImageWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System.IO;
using System.Text;
using Mono.Cecil.Metadata;
class ImageWriter : BaseImageVisitor {
Image m_img;
AssemblyKind m_kind;
MetadataWriter m_mdWriter;
BinaryWriter m_binaryWriter;
Section m_textSect;
MemoryBinaryWriter m_textWriter;
Section m_relocSect;
MemoryBinaryWriter m_relocWriter;
Section m_rsrcSect;
MemoryBinaryWriter m_rsrcWriter;
public ImageWriter (MetadataWriter writer, AssemblyKind kind, BinaryWriter bw)
{
m_mdWriter= writer;
m_img = writer.GetMetadataRoot ().GetImage ();
m_kind = kind;
m_binaryWriter = bw;
m_textWriter = new MemoryBinaryWriter ();
m_textWriter.BaseStream.Position = 80;
m_relocWriter = new MemoryBinaryWriter ();
}
public Image GetImage ()
{
return m_img;
}
public MemoryBinaryWriter GetTextWriter ()
{
return m_textWriter;
}
public uint GetAligned (uint integer, uint alignWith)
{
return (integer + alignWith - 1) & ~(alignWith - 1);
}
public void Initialize ()
{
Image img = m_img;
ResourceWriter resWriter = null;
uint sectAlign = img.PEOptionalHeader.NTSpecificFields.SectionAlignment;
uint fileAlign = img.PEOptionalHeader.NTSpecificFields.FileAlignment;
m_textSect = img.TextSection;
foreach (Section s in img.Sections) {
if (s.Name == Section.Relocs)
m_relocSect = s;
else if (s.Name == Section.Resources) {
m_rsrcSect = s;
m_rsrcWriter = new MemoryBinaryWriter ();
resWriter = new ResourceWriter (img, m_rsrcSect, m_rsrcWriter);
resWriter.Write ();
}
}
// size computations, fields setting, etc.
uint nbSects = (uint) img.Sections.Count;
img.PEFileHeader.NumberOfSections = (ushort) nbSects;
// build the reloc section data
uint relocSize = 12;
m_relocWriter.Write ((uint) 0);
m_relocWriter.Write (relocSize);
m_relocWriter.Write ((ushort) 0);
m_relocWriter.Write ((ushort) 0);
m_textSect.VirtualSize = (uint) m_textWriter.BaseStream.Length;
m_relocSect.VirtualSize = (uint) m_relocWriter.BaseStream.Length;
if (m_rsrcSect != null)
m_rsrcSect.VirtualSize = (uint) m_rsrcWriter.BaseStream.Length;
// start counting before sections headers
// section start + section header sixe * number of sections
uint headersEnd = 0x178 + 0x28 * nbSects;
uint fileOffset = headersEnd;
uint sectOffset = sectAlign;
uint imageSize = 0;
foreach (Section sect in img.Sections) {
fileOffset = GetAligned (fileOffset, fileAlign);
sectOffset = GetAligned (sectOffset, sectAlign);
sect.PointerToRawData = new RVA (fileOffset);
sect.VirtualAddress = new RVA (sectOffset);
sect.SizeOfRawData = GetAligned (sect.VirtualSize, fileAlign);
fileOffset += sect.SizeOfRawData;
sectOffset += sect.SizeOfRawData;
imageSize += GetAligned (sect.SizeOfRawData, sectAlign);
}
if (m_textSect.VirtualAddress.Value != 0x2000)
throw new ImageFormatException ("Wrong RVA for .text section");
if (resWriter != null)
resWriter.Patch ();
img.PEOptionalHeader.StandardFields.CodeSize = GetAligned (
m_textSect.SizeOfRawData, fileAlign);
img.PEOptionalHeader.StandardFields.InitializedDataSize = m_textSect.SizeOfRawData;
if (m_rsrcSect != null)
img.PEOptionalHeader.StandardFields.InitializedDataSize += m_rsrcSect.SizeOfRawData;
img.PEOptionalHeader.StandardFields.BaseOfCode = m_textSect.VirtualAddress;
img.PEOptionalHeader.StandardFields.BaseOfData = m_relocSect.VirtualAddress;
imageSize += headersEnd;
img.PEOptionalHeader.NTSpecificFields.ImageSize = GetAligned (imageSize, sectAlign);
img.PEOptionalHeader.DataDirectories.BaseRelocationTable = new DataDirectory (
m_relocSect.VirtualAddress, m_relocSect.VirtualSize);
if (m_rsrcSect != null)
img.PEOptionalHeader.DataDirectories.ResourceTable = new DataDirectory (
m_rsrcSect.VirtualAddress, (uint) m_rsrcWriter.BaseStream.Length);
if (m_kind == AssemblyKind.Dll) {
img.PEFileHeader.Characteristics = ImageCharacteristics.CILOnlyDll;
img.HintNameTable.RuntimeMain = HintNameTable.RuntimeMainDll;
img.PEOptionalHeader.NTSpecificFields.DLLFlags = 0x400;
} else {
img.PEFileHeader.Characteristics = ImageCharacteristics.CILOnlyExe;
img.HintNameTable.RuntimeMain = HintNameTable.RuntimeMainExe;
}
switch (m_kind) {
case AssemblyKind.Dll :
case AssemblyKind.Console :
img.PEOptionalHeader.NTSpecificFields.SubSystem = SubSystem.WindowsCui;
break;
case AssemblyKind.Windows :
img.PEOptionalHeader.NTSpecificFields.SubSystem = SubSystem.WindowsGui;
break;
}
RVA importTable = new RVA (img.TextSection.VirtualAddress + m_mdWriter.ImportTablePosition);
img.PEOptionalHeader.DataDirectories.ImportTable = new DataDirectory (importTable, 0x57);
img.ImportTable.ImportLookupTable = new RVA ((uint) importTable + 0x28);
img.ImportLookupTable.HintNameRVA = img.ImportAddressTable.HintNameTableRVA =
new RVA ((uint) img.ImportTable.ImportLookupTable + 0x14);
img.ImportTable.Name = new RVA ((uint) img.ImportLookupTable.HintNameRVA + 0xe);
}
public override void VisitDOSHeader (DOSHeader header)
{
m_binaryWriter.Write (header.Start);
m_binaryWriter.Write (header.Lfanew);
m_binaryWriter.Write (header.End);
m_binaryWriter.Write ((ushort) 0x4550);
m_binaryWriter.Write ((ushort) 0);
}
public override void VisitPEFileHeader (PEFileHeader header)
{
m_binaryWriter.Write (header.Machine);
m_binaryWriter.Write (header.NumberOfSections);
m_binaryWriter.Write (header.TimeDateStamp);
m_binaryWriter.Write (header.PointerToSymbolTable);
m_binaryWriter.Write (header.NumberOfSymbols);
m_binaryWriter.Write (header.OptionalHeaderSize);
m_binaryWriter.Write ((ushort) header.Characteristics);
}
public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
{
WriteIntOrLong (header.ImageBase);
m_binaryWriter.Write (header.SectionAlignment);
m_binaryWriter.Write (header.FileAlignment);
m_binaryWriter.Write (header.OSMajor);
m_binaryWriter.Write (header.OSMinor);
m_binaryWriter.Write (header.UserMajor);
m_binaryWriter.Write (header.UserMinor);
m_binaryWriter.Write (header.SubSysMajor);
m_binaryWriter.Write (header.SubSysMinor);
m_binaryWriter.Write (header.Reserved);
m_binaryWriter.Write (header.ImageSize);
m_binaryWriter.Write (header.HeaderSize);
m_binaryWriter.Write (header.FileChecksum);
m_binaryWriter.Write ((ushort) header.SubSystem);
m_binaryWriter.Write (header.DLLFlags);
WriteIntOrLong (header.StackReserveSize);
WriteIntOrLong (header.StackCommitSize);
WriteIntOrLong (header.HeapReserveSize);
WriteIntOrLong (header.HeapCommitSize);
m_binaryWriter.Write (header.LoaderFlags);
m_binaryWriter.Write (header.NumberOfDataDir);
}
public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
{
m_binaryWriter.Write (header.Magic);
m_binaryWriter.Write (header.LMajor);
m_binaryWriter.Write (header.LMinor);
m_binaryWriter.Write (header.CodeSize);
m_binaryWriter.Write (header.InitializedDataSize);
m_binaryWriter.Write (header.UninitializedDataSize);
m_binaryWriter.Write (header.EntryPointRVA.Value);
m_binaryWriter.Write (header.BaseOfCode.Value);
if (!header.IsPE64)
m_binaryWriter.Write (header.BaseOfData.Value);
}
void WriteIntOrLong (ulong value)
{
if (m_img.PEOptionalHeader.StandardFields.IsPE64)
m_binaryWriter.Write (value);
else
m_binaryWriter.Write ((uint) value);
}
public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
{
m_binaryWriter.Write (header.ExportTable.VirtualAddress);
m_binaryWriter.Write (header.ExportTable.Size);
m_binaryWriter.Write (header.ImportTable.VirtualAddress);
m_binaryWriter.Write (header.ImportTable.Size);
m_binaryWriter.Write (header.ResourceTable.VirtualAddress);
m_binaryWriter.Write (header.ResourceTable.Size);
m_binaryWriter.Write (header.ExceptionTable.VirtualAddress);
m_binaryWriter.Write (header.ExceptionTable.Size);
m_binaryWriter.Write (header.CertificateTable.VirtualAddress);
m_binaryWriter.Write (header.CertificateTable.Size);
m_binaryWriter.Write (header.BaseRelocationTable.VirtualAddress);
m_binaryWriter.Write (header.BaseRelocationTable.Size);
m_binaryWriter.Write (header.Debug.VirtualAddress);
m_binaryWriter.Write (header.Debug.Size);
m_binaryWriter.Write (header.Copyright.VirtualAddress);
m_binaryWriter.Write (header.Copyright.Size);
m_binaryWriter.Write (header.GlobalPtr.VirtualAddress);
m_binaryWriter.Write (header.GlobalPtr.Size);
m_binaryWriter.Write (header.TLSTable.VirtualAddress);
m_binaryWriter.Write (header.TLSTable.Size);
m_binaryWriter.Write (header.LoadConfigTable.VirtualAddress);
m_binaryWriter.Write (header.LoadConfigTable.Size);
m_binaryWriter.Write (header.BoundImport.VirtualAddress);
m_binaryWriter.Write (header.BoundImport.Size);
m_binaryWriter.Write (header.IAT.VirtualAddress);
m_binaryWriter.Write (header.IAT.Size);
m_binaryWriter.Write (header.DelayImportDescriptor.VirtualAddress);
m_binaryWriter.Write (header.DelayImportDescriptor.Size);
m_binaryWriter.Write (header.CLIHeader.VirtualAddress);
m_binaryWriter.Write (header.CLIHeader.Size);
m_binaryWriter.Write (header.Reserved.VirtualAddress);
m_binaryWriter.Write (header.Reserved.Size);
}
public override void VisitSection (Section sect)
{
m_binaryWriter.Write (Encoding.ASCII.GetBytes (sect.Name));
int more = 8 - sect.Name.Length;
for (int i = 0; i < more; i++)
m_binaryWriter.Write ((byte) 0);
m_binaryWriter.Write (sect.VirtualSize);
m_binaryWriter.Write (sect.VirtualAddress.Value);
m_binaryWriter.Write (sect.SizeOfRawData);
m_binaryWriter.Write (sect.PointerToRawData.Value);
m_binaryWriter.Write (sect.PointerToRelocations.Value);
m_binaryWriter.Write (sect.PointerToLineNumbers.Value);
m_binaryWriter.Write (sect.NumberOfRelocations);
m_binaryWriter.Write (sect.NumberOfLineNumbers);
m_binaryWriter.Write ((uint) sect.Characteristics);
}
public override void VisitImportAddressTable (ImportAddressTable iat)
{
m_textWriter.BaseStream.Position = 0;
m_textWriter.Write (iat.HintNameTableRVA.Value);
m_textWriter.Write (new byte [4]);
}
public override void VisitCLIHeader (CLIHeader header)
{
m_textWriter.Write (header.Cb);
m_textWriter.Write (header.MajorRuntimeVersion);
m_textWriter.Write (header.MinorRuntimeVersion);
m_textWriter.Write (header.Metadata.VirtualAddress);
m_textWriter.Write (header.Metadata.Size);
m_textWriter.Write ((uint) header.Flags);
m_textWriter.Write (header.EntryPointToken);
m_textWriter.Write (header.Resources.VirtualAddress);
m_textWriter.Write (header.Resources.Size);
m_textWriter.Write (header.StrongNameSignature.VirtualAddress);
m_textWriter.Write (header.StrongNameSignature.Size);
m_textWriter.Write (header.CodeManagerTable.VirtualAddress);
m_textWriter.Write (header.CodeManagerTable.Size);
m_textWriter.Write (header.VTableFixups.VirtualAddress);
m_textWriter.Write (header.VTableFixups.Size);
m_textWriter.Write (header.ExportAddressTableJumps.VirtualAddress);
m_textWriter.Write (header.ExportAddressTableJumps.Size);
m_textWriter.Write (header.ManagedNativeHeader.VirtualAddress);
m_textWriter.Write (header.ManagedNativeHeader.Size);
}
public override void VisitDebugHeader (DebugHeader header)
{
m_textWriter.BaseStream.Position = m_mdWriter.DebugHeaderPosition;
uint sizeUntilData = 0x1c;
header.AddressOfRawData = m_img.TextSection.VirtualAddress + m_mdWriter.DebugHeaderPosition + sizeUntilData;
header.PointerToRawData = 0x200 + m_mdWriter.DebugHeaderPosition + sizeUntilData;
header.SizeOfData = 0x18 + (uint) header.FileName.Length + 1;
m_textWriter.Write (header.Characteristics);
m_textWriter.Write (header.TimeDateStamp);
m_textWriter.Write (header.MajorVersion);
m_textWriter.Write (header.MinorVersion);
m_textWriter.Write ((uint) header.Type);
m_textWriter.Write (header.SizeOfData);
m_textWriter.Write (header.AddressOfRawData.Value);
m_textWriter.Write (header.PointerToRawData);
m_textWriter.Write (header.Magic);
m_textWriter.Write (header.Signature.ToByteArray ());
m_textWriter.Write (header.Age);
m_textWriter.Write (Encoding.ASCII.GetBytes (header.FileName));
m_textWriter.Write ((byte) 0);
}
public override void VisitImportTable (ImportTable it)
{
m_textWriter.BaseStream.Position = m_mdWriter.ImportTablePosition;
m_textWriter.Write (it.ImportLookupTable.Value);
m_textWriter.Write (it.DateTimeStamp);
m_textWriter.Write (it.ForwardChain);
m_textWriter.Write (it.Name.Value);
m_textWriter.Write (it.ImportAddressTable.Value);
m_textWriter.Write (new byte [20]);
}
public override void VisitImportLookupTable (ImportLookupTable ilt)
{
m_textWriter.Write (ilt.HintNameRVA.Value);
m_textWriter.Write (new byte [16]);
}
public override void VisitHintNameTable (HintNameTable hnt)
{
m_textWriter.Write (hnt.Hint);
m_textWriter.Write (Encoding.ASCII.GetBytes (hnt.RuntimeMain));
m_textWriter.Write ('\0');
m_textWriter.Write (Encoding.ASCII.GetBytes (hnt.RuntimeLibrary));
m_textWriter.Write ('\0');
m_textWriter.Write (new byte [4]);
// patch header with ep rva
RVA ep = m_img.TextSection.VirtualAddress +
(uint) m_textWriter.BaseStream.Position;
long pos = m_binaryWriter.BaseStream.Position;
m_binaryWriter.BaseStream.Position = 0xa8;
m_binaryWriter.Write (ep.Value);
m_binaryWriter.BaseStream.Position = pos;
// patch reloc Sect with ep
uint reloc = (ep.Value + 2) % 0x1000;
uint rva = (ep.Value + 2) - reloc;
m_relocWriter.BaseStream.Position = 0;
m_relocWriter.Write (rva);
m_relocWriter.BaseStream.Position = 8;
m_relocWriter.Write ((ushort) ((3 << 12) | reloc));
m_textWriter.Write (hnt.EntryPoint);
m_textWriter.Write (hnt.RVA);
}
public override void TerminateImage (Image img)
{
m_binaryWriter.BaseStream.Position = 0x200;
WriteSection (m_textSect, m_textWriter);
WriteSection (m_relocSect, m_relocWriter);
if (m_rsrcSect != null)
WriteSection (m_rsrcSect, m_rsrcWriter);
}
void WriteSection (Section sect, MemoryBinaryWriter sectWriter)
{
sectWriter.MemoryStream.WriteTo (m_binaryWriter.BaseStream);
m_binaryWriter.Write (new byte [
sect.SizeOfRawData - sectWriter.BaseStream.Length]);
}
}
}

98
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/Imports.cs

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
//
// Imports.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public sealed class ImportAddressTable : IBinaryVisitable {
public RVA HintNameTableRVA;
internal ImportAddressTable ()
{
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitImportAddressTable (this);
}
}
public sealed class ImportTable : IBinaryVisitable {
public RVA ImportLookupTable;
public uint DateTimeStamp;
public uint ForwardChain;
public RVA Name;
public RVA ImportAddressTable;
internal ImportTable ()
{
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitImportTable (this);
}
}
public sealed class ImportLookupTable : IBinaryVisitable {
public RVA HintNameRVA;
internal ImportLookupTable ()
{
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitImportLookupTable (this);
}
}
public sealed class HintNameTable : IBinaryVisitable {
public const string RuntimeMainExe = "_CorExeMain";
public const string RuntimeMainDll = "_CorDllMain";
public const string RuntimeCorEE = "mscoree.dll";
public ushort Hint;
public string RuntimeMain;
public string RuntimeLibrary;
public ushort EntryPoint;
public RVA RVA;
internal HintNameTable ()
{
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitHintNameTable (this);
}
}
}

70
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/MemoryBinaryWriter.cs

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
//
// MemoryBinaryWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System.IO;
using System.Text;
internal sealed class MemoryBinaryWriter : BinaryWriter {
public MemoryStream MemoryStream {
get { return (MemoryStream) this.BaseStream; }
}
public MemoryBinaryWriter () : base (new MemoryStream ())
{
}
public MemoryBinaryWriter (Encoding enc) : base (new MemoryStream (), enc)
{
}
public void Empty ()
{
this.BaseStream.Position = 0;
this.BaseStream.SetLength (0);
}
public void Write (MemoryBinaryWriter writer)
{
writer.MemoryStream.WriteTo (this.BaseStream);
}
public byte [] ToArray ()
{
return this.MemoryStream.ToArray ();
}
public void QuadAlign ()
{
this.BaseStream.Position += 3;
this.BaseStream.Position &= ~3;
}
}
}

58
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/PEFileHeader.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
//
// PEFileHeader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public sealed class PEFileHeader : IHeader, IBinaryVisitable {
public ushort Machine;
public ushort NumberOfSections;
public uint TimeDateStamp;
public uint PointerToSymbolTable;
public uint NumberOfSymbols;
public ushort OptionalHeaderSize;
public ImageCharacteristics Characteristics;
internal PEFileHeader ()
{
}
public void SetDefaultValues ()
{
Machine = 0x14c;
PointerToSymbolTable = 0;
NumberOfSymbols = 0;
OptionalHeaderSize = 0xe0;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitPEFileHeader (this);
}
}
}

200
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/PEOptionalHeader.cs

@ -0,0 +1,200 @@ @@ -0,0 +1,200 @@
//
// PEOptionalHeader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public sealed class PEOptionalHeader : IHeader, IBinaryVisitable {
public StandardFieldsHeader StandardFields;
public NTSpecificFieldsHeader NTSpecificFields;
public DataDirectoriesHeader DataDirectories;
internal PEOptionalHeader ()
{
StandardFields = new StandardFieldsHeader ();
NTSpecificFields = new NTSpecificFieldsHeader ();
DataDirectories = new DataDirectoriesHeader ();
}
public void SetDefaultValues ()
{
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitPEOptionalHeader (this);
StandardFields.Accept (visitor);
NTSpecificFields.Accept (visitor);
DataDirectories.Accept (visitor);
}
public sealed class StandardFieldsHeader : IHeader, IBinaryVisitable {
public ushort Magic;
public byte LMajor;
public byte LMinor;
public uint CodeSize;
public uint InitializedDataSize;
public uint UninitializedDataSize;
public RVA EntryPointRVA;
public RVA BaseOfCode;
public RVA BaseOfData;
public bool IsPE64 {
get { return Magic == 0x20b; }
set {
if (value)
Magic = 0x20b;
else
Magic = 0x10b;
}
}
internal StandardFieldsHeader ()
{
}
public void SetDefaultValues ()
{
Magic = 0x10b;
LMajor = 6;
LMinor = 0;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitStandardFieldsHeader (this);
}
}
public sealed class NTSpecificFieldsHeader : IHeader, IBinaryVisitable {
public ulong ImageBase;
public uint SectionAlignment;
public uint FileAlignment;
public ushort OSMajor;
public ushort OSMinor;
public ushort UserMajor;
public ushort UserMinor;
public ushort SubSysMajor;
public ushort SubSysMinor;
public uint Reserved;
public uint ImageSize;
public uint HeaderSize;
public uint FileChecksum;
public SubSystem SubSystem;
public ushort DLLFlags;
public ulong StackReserveSize;
public ulong StackCommitSize;
public ulong HeapReserveSize;
public ulong HeapCommitSize;
public uint LoaderFlags;
public uint NumberOfDataDir;
internal NTSpecificFieldsHeader ()
{
}
public void SetDefaultValues ()
{
ImageBase = 0x400000;
SectionAlignment = 0x2000;
FileAlignment = 0x200;
OSMajor = 4;
OSMinor = 0;
UserMajor = 0;
UserMinor = 0;
SubSysMajor = 4;
SubSysMinor = 0;
Reserved = 0;
HeaderSize = 0x200;
FileChecksum = 0;
DLLFlags = 0;
StackReserveSize = 0x100000;
StackCommitSize = 0x1000;
HeapReserveSize = 0x100000;
HeapCommitSize = 0x1000;
LoaderFlags = 0;
NumberOfDataDir = 0x10;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitNTSpecificFieldsHeader (this);
}
}
public sealed class DataDirectoriesHeader : IHeader, IBinaryVisitable {
public DataDirectory ExportTable;
public DataDirectory ImportTable;
public DataDirectory ResourceTable;
public DataDirectory ExceptionTable;
public DataDirectory CertificateTable;
public DataDirectory BaseRelocationTable;
public DataDirectory Debug;
public DataDirectory Copyright;
public DataDirectory GlobalPtr;
public DataDirectory TLSTable;
public DataDirectory LoadConfigTable;
public DataDirectory BoundImport;
public DataDirectory IAT;
public DataDirectory DelayImportDescriptor;
public DataDirectory CLIHeader;
public DataDirectory Reserved;
internal DataDirectoriesHeader ()
{
}
public void SetDefaultValues ()
{
ExportTable = DataDirectory.Zero;
ResourceTable = DataDirectory.Zero;
ExceptionTable = DataDirectory.Zero;
CertificateTable = DataDirectory.Zero;
Debug = DataDirectory.Zero;
Copyright = DataDirectory.Zero;
GlobalPtr = DataDirectory.Zero;
TLSTable = DataDirectory.Zero;
LoadConfigTable = DataDirectory.Zero;
BoundImport = DataDirectory.Zero;
IAT = new DataDirectory (new RVA (0x2000), 8);
DelayImportDescriptor = DataDirectory.Zero;
CLIHeader = new DataDirectory (new RVA (0x2008), 0x48);
Reserved = DataDirectory.Zero;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitDataDirectoriesHeader (this);
}
}
}
}

115
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/RVA.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
//
// RVA.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public struct RVA {
public static readonly RVA Zero = new RVA (0);
uint m_rva;
public uint Value {
get { return m_rva; }
set { m_rva = value; }
}
public RVA (uint rva)
{
m_rva = rva;
}
public override int GetHashCode ()
{
return (int) m_rva;
}
public override bool Equals (object other)
{
if (other is RVA)
return this.m_rva == ((RVA) other).m_rva;
return false;
}
public override string ToString ()
{
return string.Format ("0x{0}", m_rva.ToString ("X"));
}
public static bool operator == (RVA one, RVA other)
{
return one.Equals (other);
}
public static bool operator != (RVA one, RVA other)
{
return !one.Equals (other);
}
public static bool operator < (RVA one, RVA other)
{
return one.m_rva < other.m_rva;
}
public static bool operator > (RVA one, RVA other)
{
return one.m_rva > other.m_rva;
}
public static bool operator <= (RVA one, RVA other)
{
return one.m_rva <= other.m_rva;
}
public static bool operator >= (RVA one, RVA other)
{
return one.m_rva >= other.m_rva;
}
public static RVA operator + (RVA rva, uint x)
{
return new RVA (rva.m_rva + x);
}
public static RVA operator - (RVA rva, uint x)
{
return new RVA (rva.m_rva - x);
}
public static implicit operator RVA (uint val)
{
return val == 0 ? RVA.Zero : new RVA (val);
}
public static implicit operator uint (RVA rva)
{
return rva.m_rva;
}
}
}

48
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDataEntry.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
//
// ResourceDataEntry.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public class ResourceDataEntry : ResourceNode {
public RVA Data;
public uint Size;
public uint Codepage;
public uint Reserved = 0;
public byte [] ResourceData;
public ResourceDataEntry (int offset) : base (offset)
{
}
public ResourceDataEntry ()
{
}
}
}

66
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryEntry.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
//
// ResourceDirectoryEntry.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public class ResourceDirectoryEntry : ResourceNode {
private bool m_idByName;
public int ID;
public ResourceDirectoryString Name;
public bool IdentifiedByName {
get { return m_idByName; }
}
public ResourceNode Child;
public ResourceDirectoryEntry (ResourceDirectoryString name)
{
this.Name = name;
m_idByName = true;
}
public ResourceDirectoryEntry (ResourceDirectoryString name, int offset) : base (offset)
{
this.Name = name;
m_idByName = true;
}
public ResourceDirectoryEntry (int id)
{
this.ID = id;
}
public ResourceDirectoryEntry (int id, int offset) : base (offset)
{
this.ID = id;
}
}
}

45
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryString.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
//
// ResourceDirectoryString.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public class ResourceDirectoryString : ResourceNode {
public string String;
public ResourceDirectoryString (string str)
{
this.String = str;
}
public ResourceDirectoryString (string str, int offset) : base (offset)
{
this.String = str;
}
}
}

56
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryTable.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
//
// ResourceDirectoryTable.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System.Collections;
public class ResourceDirectoryTable : ResourceNode {
private ArrayList m_entries;
public uint Characteristics;
public uint TimeDateStamp;
public ushort MajorVersion;
public ushort MinorVersion;
public IList Entries {
get { return m_entries; }
}
public ResourceDirectoryTable (int offset) : base (offset)
{
m_entries = new ArrayList ();
}
public ResourceDirectoryTable ()
{
m_entries = new ArrayList ();
}
}
}

44
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceNode.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
//
// ResourceNode.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public abstract class ResourceNode {
public int Offset;
internal ResourceNode (int offset)
{
this.Offset = offset;
}
internal ResourceNode ()
{
}
}
}

143
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceReader.cs

@ -0,0 +1,143 @@ @@ -0,0 +1,143 @@
//
// ResourceReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System.IO;
using System.Text;
class ResourceReader {
Image m_img;
Section m_rsrc;
BinaryReader m_reader;
public ResourceReader (Image img)
{
m_img = img;
}
public ResourceDirectoryTable Read ()
{
m_rsrc = GetResourceSection ();
if (m_rsrc == null)
return null;
m_reader = new BinaryReader (new MemoryStream (m_rsrc.Data));
return ReadDirectoryTable ();
}
Section GetResourceSection ()
{
foreach (Section s in m_img.Sections)
if (s.Name == Section.Resources)
return s;
return null;
}
int GetOffset ()
{
return (int) m_reader.BaseStream.Position;
}
ResourceDirectoryTable ReadDirectoryTable ()
{
ResourceDirectoryTable rdt = new ResourceDirectoryTable (GetOffset ());
rdt.Characteristics = m_reader.ReadUInt32 ();
rdt.TimeDateStamp = m_reader.ReadUInt32 ();
rdt.MajorVersion = m_reader.ReadUInt16 ();
rdt.MinorVersion = m_reader.ReadUInt16 ();
ushort nameEntries = m_reader.ReadUInt16 ();
ushort idEntries = m_reader.ReadUInt16 ();
for (int i = 0; i < nameEntries; i++)
rdt.Entries.Add (ReadDirectoryEntry ());
for (int i = 0; i < idEntries; i++)
rdt.Entries.Add (ReadDirectoryEntry ());
return rdt;
}
ResourceDirectoryEntry ReadDirectoryEntry ()
{
uint name = m_reader.ReadUInt32 ();
uint child = m_reader.ReadUInt32 ();
ResourceDirectoryEntry rde;
if ((name & 0x80000000) != 0)
rde = new ResourceDirectoryEntry (ReadDirectoryString ((int) name & 0x7fffffff), GetOffset ());
else
rde = new ResourceDirectoryEntry ((int) name & 0x7fffffff, GetOffset ());
long pos = m_reader.BaseStream.Position;
m_reader.BaseStream.Position = child & 0x7fffffff;
if ((child & 0x80000000) != 0)
rde.Child = ReadDirectoryTable ();
else
rde.Child = ReadDataEntry ();
m_reader.BaseStream.Position = pos;
return rde;
}
ResourceDirectoryString ReadDirectoryString (int offset)
{
long pos = m_reader.BaseStream.Position;
m_reader.BaseStream.Position = offset;
byte [] str = m_reader.ReadBytes (m_reader.ReadUInt16 ());
ResourceDirectoryString rds = new ResourceDirectoryString (
Encoding.Unicode.GetString (str, 0, str.Length),
GetOffset ());
m_reader.BaseStream.Position = pos;
return rds;
}
ResourceNode ReadDataEntry ()
{
ResourceDataEntry rde = new ResourceDataEntry (GetOffset ());
rde.Data = m_reader.ReadUInt32 ();
rde.Size = m_reader.ReadUInt32 ();
rde.Codepage = m_reader.ReadUInt32 ();
rde.Reserved = m_reader.ReadUInt32 ();
BinaryReader dataReader = m_img.GetReaderAtVirtualAddress (rde.Data);
rde.ResourceData = dataReader.ReadBytes ((int) rde.Size);
dataReader.Close ();
return rde;
}
}
}

216
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/ResourceWriter.cs

@ -0,0 +1,216 @@ @@ -0,0 +1,216 @@
//
// ResourceWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Text;
namespace Mono.Cecil.Binary {
using System.Collections;
class ResourceWriter {
Image m_img;
Section m_rsrc;
MemoryBinaryWriter m_writer;
ArrayList m_dataEntries;
ArrayList m_stringEntries;
long m_pos;
public ResourceWriter (Image img, Section rsrc, MemoryBinaryWriter writer)
{
m_img = img;
m_rsrc = rsrc;
m_writer = writer;
m_dataEntries = new ArrayList ();
m_stringEntries = new ArrayList ();
}
public void Write ()
{
if (m_img.ResourceDirectoryRoot == null)
return;
ComputeOffset (m_img.ResourceDirectoryRoot);
WriteResourceDirectoryTable (m_img.ResourceDirectoryRoot);
}
public void Patch ()
{
foreach (ResourceDataEntry rde in m_dataEntries) {
GotoOffset (rde.Offset);
m_writer.Write ((uint) rde.Data + m_rsrc.VirtualAddress);
RestoreOffset ();
}
}
void ComputeOffset (ResourceDirectoryTable root)
{
int offset = 0;
Queue directoryTables = new Queue ();
directoryTables.Enqueue (root);
while (directoryTables.Count > 0) {
ResourceDirectoryTable rdt = directoryTables.Dequeue () as ResourceDirectoryTable;
rdt.Offset = offset;
offset += 16;
foreach (ResourceDirectoryEntry rde in rdt.Entries) {
rde.Offset = offset;
offset += 8;
if (rde.IdentifiedByName)
m_stringEntries.Add (rde.Name);
if (rde.Child is ResourceDirectoryTable)
directoryTables.Enqueue (rde.Child);
else
m_dataEntries.Add (rde.Child);
}
}
foreach (ResourceDataEntry rde in m_dataEntries) {
rde.Offset = offset;
offset += 16;
}
foreach (ResourceDirectoryString rds in m_stringEntries) {
rds.Offset = offset;
byte [] str = Encoding.Unicode.GetBytes (rds.String);
offset += 2 + str.Length;
offset += 3;
offset &= ~3;
}
foreach (ResourceDataEntry rde in m_dataEntries) {
rde.Data = (uint) offset;
offset += rde.ResourceData.Length;
offset += 3;
offset &= ~3;
}
m_writer.Write (new byte [offset]);
}
void WriteResourceDirectoryTable (ResourceDirectoryTable rdt)
{
GotoOffset (rdt.Offset);
m_writer.Write (rdt.Characteristics);
m_writer.Write (rdt.TimeDateStamp);
m_writer.Write (rdt.MajorVersion);
m_writer.Write (rdt.MinorVersion);
ResourceDirectoryEntry [] namedEntries = GetEntries (rdt, true);
ResourceDirectoryEntry [] idEntries = GetEntries (rdt, false);
m_writer.Write ((ushort) namedEntries.Length);
m_writer.Write ((ushort) idEntries.Length);
foreach (ResourceDirectoryEntry rde in namedEntries)
WriteResourceDirectoryEntry (rde);
foreach (ResourceDirectoryEntry rde in idEntries)
WriteResourceDirectoryEntry (rde);
RestoreOffset ();
}
ResourceDirectoryEntry [] GetEntries (ResourceDirectoryTable rdt, bool identifiedByName)
{
ArrayList entries = new ArrayList ();
foreach (ResourceDirectoryEntry rde in rdt.Entries)
if (rde.IdentifiedByName == identifiedByName)
entries.Add (rde);
return entries.ToArray (typeof (ResourceDirectoryEntry)) as ResourceDirectoryEntry [];
}
void WriteResourceDirectoryEntry (ResourceDirectoryEntry rde)
{
GotoOffset (rde.Offset);
if (rde.IdentifiedByName) {
m_writer.Write ((uint) rde.Name.Offset | 0x80000000);
WriteResourceDirectoryString (rde.Name);
} else
m_writer.Write ((uint) rde.ID);
if (rde.Child is ResourceDirectoryTable) {
m_writer.Write((uint) rde.Child.Offset | 0x80000000);
WriteResourceDirectoryTable (rde.Child as ResourceDirectoryTable);
} else {
m_writer.Write (rde.Child.Offset);
WriteResourceDataEntry (rde.Child as ResourceDataEntry);
}
RestoreOffset ();
}
void WriteResourceDataEntry (ResourceDataEntry rde)
{
GotoOffset (rde.Offset);
m_writer.Write (0);
m_writer.Write ((uint) rde.ResourceData.Length);
m_writer.Write (rde.Codepage);
m_writer.Write (rde.Reserved);
m_writer.BaseStream.Position = rde.Data;
m_writer.Write (rde.ResourceData);
RestoreOffset ();
}
void WriteResourceDirectoryString (ResourceDirectoryString name)
{
GotoOffset (name.Offset);
byte [] str = Encoding.Unicode.GetBytes (name.String);
m_writer.Write ((ushort) str.Length);
m_writer.Write (str);
RestoreOffset ();
}
void GotoOffset (int offset)
{
m_pos = m_writer.BaseStream.Position;
m_writer.BaseStream.Position = offset;
}
void RestoreOffset ()
{
m_writer.BaseStream.Position = m_pos;
}
}
}

37
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/RuntimeImage.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
//
// RuntimeImage.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public enum RuntimeImage : uint {
ILOnly = 0x0000001,
F32BitsRequired = 0x0000002,
StrongNameSigned = 0x0000008,
TrackDebugData = 0x00010000
}
}

66
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/Section.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
//
// Section.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public sealed class Section : IHeader, IBinaryVisitable {
public const string Text = ".text";
public const string Resources = ".rsrc";
public const string Relocs = ".reloc";
public const string SData = ".sdata";
public uint VirtualSize;
public RVA VirtualAddress;
public uint SizeOfRawData;
public RVA PointerToRawData;
public RVA PointerToRelocations;
public RVA PointerToLineNumbers;
public ushort NumberOfRelocations;
public ushort NumberOfLineNumbers;
public SectionCharacteristics Characteristics;
public string Name;
public byte [] Data;
internal Section ()
{
}
public void SetDefaultValues ()
{
PointerToLineNumbers = RVA.Zero;
NumberOfLineNumbers = 0;
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitSection (this);
}
}
}

70
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/SectionCharacteristics.cs

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
//
// SectionCharacteristics.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
[Flags]
public enum SectionCharacteristics : uint {
TypeNoPad = 0x0000008,
ContainsCode = 0x00000020,
ContainsInitializedData = 0x00000040,
ContainsUninitializedData = 0x00000080,
LnkOther = 0x0000100,
LnkInfo = 0x000200,
LnkRemove = 0x0000800,
LnkCOMDAT = 0x00001000,
GPRel = 0x00008000,
MemPurgeable = 0x00020000,
MemLocked = 0x00040000,
MemPreload = 0x00080000,
Align1Bytes = 0x00100000,
Align2Bytes = 0x00200000,
Align4Bytes = 0x00300000,
Align8Bytes = 0x00400000,
Align16Bytes = 0x00500000,
Align32Bytes = 0x00600000,
Align64Bytes = 0x00700000,
Align128Bytes = 0x00800000,
Align256Bytes = 0x00900000,
Align512Bytes = 0x00a00000,
Align1024Bytes = 0x00b00000,
Align2048Bytes = 0x00c00000,
Align4096Bytes = 0x00d00000,
Align8192Bytes = 0x00e00000,
LnkNRelocOvfl = 0x01000000,
MemDiscardable = 0x02000000,
MemNotCached = 0x04000000,
MemNotPaged = 0x08000000,
MemShared = 0x10000000,
MemExecute = 0x20000000,
MemoryRead = 0x40000000,
MemoryWrite = 0x80000000
}
}

114
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/SectionCollection.cs

@ -0,0 +1,114 @@ @@ -0,0 +1,114 @@
//
// SectionCollection.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
using System;
using System.Collections;
public sealed class SectionCollection : ICollection, IBinaryVisitable {
IList m_items;
public Section this [int index]
{
get { return m_items [index] as Section; }
set { m_items [index] = value; }
}
public int Count {
get { return m_items.Count; }
}
public bool IsSynchronized {
get { return false; }
}
public object SyncRoot {
get { return this; }
}
internal SectionCollection ()
{
m_items = new ArrayList (4);
}
internal void Add (Section value)
{
m_items.Add (value);
}
internal void Clear ()
{
m_items.Clear ();
}
public bool Contains (Section value)
{
return m_items.Contains (value);
}
public int IndexOf (Section value)
{
return m_items.IndexOf (value);
}
internal void Insert (int index, Section value)
{
m_items.Insert (index, value);
}
internal void Remove (Section value)
{
m_items.Remove (value);
}
internal void RemoveAt (int index)
{
m_items.Remove (index);
}
public void CopyTo (Array ary, int index)
{
m_items.CopyTo (ary, index);
}
public IEnumerator GetEnumerator ()
{
return m_items.GetEnumerator ();
}
public void Accept (IBinaryVisitor visitor)
{
visitor.VisitSectionCollection (this);
for (int i = 0; i < m_items.Count; i++)
this [i].Accept (visitor);
}
}
}

45
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Binary/SubSystem.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
//
// SubSystem.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Binary {
public enum SubSystem : ushort {
Unknown = 0x0,
Native = 0x1,
WindowsGui = 0x2,
WindowsCui = 0x3,
PosixCui = 0x7,
WindowsCeGui = 0x9,
EfiApplication = 0x10,
EfiBootServiceDriver = 0x11,
EfiRuntimeDriver = 0x12,
EfiRom = 0x13,
Xbox = 0x14,
NexusAgent = 0x15
}
}

73
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/BaseCodeVisitor.cs

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
//
// BaseCodeVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public abstract class BaseCodeVisitor : ICodeVisitor {
public virtual void VisitMethodBody (MethodBody body)
{
}
public virtual void VisitInstructionCollection (InstructionCollection instructions)
{
}
public virtual void VisitInstruction (Instruction instr)
{
}
public virtual void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh)
{
}
public virtual void VisitExceptionHandler (ExceptionHandler eh)
{
}
public virtual void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
{
}
public virtual void VisitVariableDefinition (VariableDefinition var)
{
}
public virtual void VisitScopeCollection (ScopeCollection scopes)
{
}
public virtual void VisitScope (Scope s)
{
}
public virtual void TerminateMethodBody (MethodBody body)
{
}
}
}

357
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/CilWorker.cs

@ -0,0 +1,357 @@ @@ -0,0 +1,357 @@
//
// CilWorker.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using SR = System.Reflection;
public sealed class CilWorker {
MethodBody m_mbody;
InstructionCollection m_instrs;
internal CilWorker (MethodBody body)
{
m_mbody = body;
m_instrs = m_mbody.Instructions;
}
public MethodBody GetBody ()
{
return m_mbody;
}
public Instruction Create (OpCode opcode)
{
if (opcode.OperandType != OperandType.InlineNone)
throw new ArgumentException ("opcode");
return FinalCreate (opcode);
}
public Instruction Create (OpCode opcode, TypeReference type)
{
if (opcode.OperandType != OperandType.InlineType &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, type);
}
public Instruction Create (OpCode opcode, MethodReference meth)
{
if (opcode.OperandType != OperandType.InlineMethod &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, meth);
}
public Instruction Create (OpCode opcode, FieldReference field)
{
if (opcode.OperandType != OperandType.InlineField &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, field);
}
public Instruction Create (OpCode opcode, string str)
{
if (opcode.OperandType != OperandType.InlineString)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, str);
}
public Instruction Create (OpCode opcode, sbyte b)
{
if (opcode.OperandType != OperandType.ShortInlineI &&
opcode != OpCodes.Ldc_I4_S)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, b);
}
public Instruction Create (OpCode opcode, byte b)
{
if (opcode.OperandType != OperandType.ShortInlineI ||
opcode == OpCodes.Ldc_I4_S)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, b);
}
public Instruction Create (OpCode opcode, int i)
{
if (opcode.OperandType != OperandType.InlineI)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, i);
}
public Instruction Create (OpCode opcode, long l)
{
if (opcode.OperandType != OperandType.InlineI8)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, l);
}
public Instruction Create (OpCode opcode, float f)
{
if (opcode.OperandType != OperandType.ShortInlineR)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, f);
}
public Instruction Create (OpCode opcode, double d)
{
if (opcode.OperandType != OperandType.InlineR)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, d);
}
public Instruction Create (OpCode opcode, Instruction label)
{
if (opcode.OperandType != OperandType.InlineBrTarget &&
opcode.OperandType != OperandType.ShortInlineBrTarget)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, label);
}
public Instruction Create (OpCode opcode, Instruction [] labels)
{
if (opcode.OperandType != OperandType.InlineSwitch)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, labels);
}
public Instruction Create (OpCode opcode, VariableDefinition var)
{
if (opcode.OperandType != OperandType.ShortInlineVar &&
opcode.OperandType != OperandType.InlineVar)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, var);
}
public Instruction Create (OpCode opcode, ParameterDefinition param)
{
if (opcode.OperandType != OperandType.ShortInlineParam &&
opcode.OperandType != OperandType.InlineParam)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, param);
}
Instruction FinalCreate (OpCode opcode)
{
return FinalCreate (opcode, null);
}
Instruction FinalCreate (OpCode opcode, object operand)
{
return new Instruction (opcode, operand);
}
public Instruction Emit (OpCode opcode)
{
Instruction instr = Create (opcode);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, TypeReference type)
{
Instruction instr = Create (opcode, type);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, MethodReference meth)
{
Instruction instr = Create (opcode, meth);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, FieldReference field)
{
Instruction instr = Create (opcode, field);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, string str)
{
Instruction instr = Create (opcode, str);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, byte b)
{
Instruction instr = Create (opcode, b);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, sbyte b)
{
Instruction instr = Create (opcode, b);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, int i)
{
Instruction instr = Create (opcode, i);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, long l)
{
Instruction instr = Create (opcode, l);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, float f)
{
Instruction instr = Create (opcode, f);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, double d)
{
Instruction instr = Create (opcode, d);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, Instruction target)
{
Instruction instr = Create (opcode, target);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, Instruction [] targets)
{
Instruction instr = Create (opcode, targets);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, VariableDefinition var)
{
Instruction instr = Create (opcode, var);
Append (instr);
return instr;
}
public Instruction Emit (OpCode opcode, ParameterDefinition param)
{
Instruction instr = Create (opcode, param);
Append (instr);
return instr;
}
public void InsertBefore (Instruction target, Instruction instr)
{
int index = m_instrs.IndexOf (target);
if (index == -1)
throw new ArgumentOutOfRangeException ("Target instruction not in method body");
m_instrs.Insert (index, instr);
instr.Previous = target.Previous;
if (target.Previous != null)
target.Previous.Next = instr;
target.Previous = instr;
instr.Next = target;
}
public void InsertAfter (Instruction target, Instruction instr)
{
int index = m_instrs.IndexOf (target);
if (index == -1)
throw new ArgumentOutOfRangeException ("Target instruction not in method body");
m_instrs.Insert (index + 1, instr);
instr.Next = target.Next;
if (target.Next != null)
target.Next.Previous = instr;
target.Next = instr;
instr.Previous = target;
}
public void Append (Instruction instr)
{
Instruction last = null, current = instr;
if (m_instrs.Count > 0)
last = m_instrs [m_instrs.Count - 1];
if (last != null) {
last.Next = instr;
current.Previous = last;
}
m_instrs.Add (current);
}
public void Replace (Instruction old, Instruction instr)
{
int index = m_instrs.IndexOf (old);
if (index == -1)
throw new ArgumentOutOfRangeException ("Target instruction not in method body");
InsertAfter (old, instr);
Remove (old);
}
public void Remove (Instruction instr)
{
if (!m_instrs.Contains (instr))
throw new ArgumentException ("Instruction not in method body");
if (instr.Previous != null)
instr.Previous.Next = instr.Next;
if (instr.Next != null)
instr.Next.Previous = instr.Previous;
m_instrs.Remove (instr);
}
}
}

255
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/Code.cs

@ -0,0 +1,255 @@ @@ -0,0 +1,255 @@
//
// Code.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// Fri Mar 16 15:37:23 +0100 2007
//
// (C) 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
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,
}
}

355
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs

@ -0,0 +1,355 @@ @@ -0,0 +1,355 @@
//
// CodeReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using System.Collections;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Metadata;
using Mono.Cecil.Signatures;
class CodeReader : BaseCodeVisitor {
ReflectionReader m_reflectReader;
MetadataRoot m_root;
public CodeReader (ReflectionReader reflectReader)
{
m_reflectReader = reflectReader;
m_root = m_reflectReader.MetadataRoot;
}
public override void VisitMethodBody (MethodBody body)
{
MethodDefinition meth = body.Method;
MethodBody methBody = body;
BinaryReader br = m_reflectReader.Module.ImageReader.MetadataReader.GetDataReader (meth.RVA);
// lets read the method
IDictionary instrs;
int flags = br.ReadByte ();
switch (flags & 0x3) {
case (int) MethodHeader.TinyFormat :
methBody.CodeSize = flags >> 2;
methBody.MaxStack = 8;
ReadCilBody (methBody, br, out instrs);
break;
case (int) MethodHeader.FatFormat :
br.BaseStream.Position--;
int fatflags = br.ReadUInt16 ();
//int headersize = (fatflags >> 12) & 0xf;
methBody.MaxStack = br.ReadUInt16 ();
methBody.CodeSize = br.ReadInt32 ();
methBody.LocalVarToken = br.ReadInt32 ();
body.InitLocals = (fatflags & (int) MethodHeader.InitLocals) != 0;
VisitVariableDefinitionCollection (methBody.Variables);
ReadCilBody (methBody, br, out instrs);
if ((fatflags & (int) MethodHeader.MoreSects) != 0)
ReadSection (methBody, br, instrs);
break;
}
if (m_reflectReader.SymbolReader != null)
m_reflectReader.SymbolReader.Read (methBody);
}
public static uint GetRid (int token)
{
return (uint) token & 0x00ffffff;
}
public static ParameterDefinition GetParameter (MethodBody body, int index)
{
if (body.Method.HasThis) {
if (index == 0)
return body.Method.This;
index--;
}
return body.Method.Parameters [index];
}
public static VariableDefinition GetVariable (MethodBody body, int index)
{
return body.Variables [index];
}
void ReadCilBody (MethodBody body, BinaryReader br, out IDictionary instructions)
{
long start = br.BaseStream.Position;
Instruction last = null;
InstructionCollection code = body.Instructions;
instructions = new Hashtable ();
GenericContext context = new GenericContext (body.Method);
while (br.BaseStream.Position < start + body.CodeSize) {
OpCode op;
long offset = br.BaseStream.Position - start;
int cursor = br.ReadByte ();
if (cursor == 0xfe)
op = OpCodes.TwoBytesOpCode [br.ReadByte ()];
else
op = OpCodes.OneByteOpCode [cursor];
Instruction instr = new Instruction ((int) offset, op);
switch (op.OperandType) {
case OperandType.InlineNone :
break;
case OperandType.InlineSwitch :
uint length = br.ReadUInt32 ();
int [] branches = new int [length];
int [] buf = new int [length];
for (int i = 0; i < length; i++)
buf [i] = br.ReadInt32 ();
for (int i = 0; i < length; i++)
branches [i] = Convert.ToInt32 (br.BaseStream.Position - start + buf [i]);
instr.Operand = branches;
break;
case OperandType.ShortInlineBrTarget :
sbyte sbrtgt = br.ReadSByte ();
instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + sbrtgt);
break;
case OperandType.InlineBrTarget :
int brtgt = br.ReadInt32 ();
instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + brtgt);
break;
case OperandType.ShortInlineI :
if (op == OpCodes.Ldc_I4_S)
instr.Operand = br.ReadSByte ();
else
instr.Operand = br.ReadByte ();
break;
case OperandType.ShortInlineVar :
instr.Operand = GetVariable (body, br.ReadByte ());
break;
case OperandType.ShortInlineParam :
instr.Operand = GetParameter (body, br.ReadByte ());
break;
case OperandType.InlineSig :
instr.Operand = GetCallSiteAt (br.ReadInt32 (), context);
break;
case OperandType.InlineI :
instr.Operand = br.ReadInt32 ();
break;
case OperandType.InlineVar :
instr.Operand = GetVariable (body, br.ReadInt16 ());
break;
case OperandType.InlineParam :
instr.Operand = GetParameter (body, br.ReadInt16 ());
break;
case OperandType.InlineI8 :
instr.Operand = br.ReadInt64 ();
break;
case OperandType.ShortInlineR :
instr.Operand = br.ReadSingle ();
break;
case OperandType.InlineR :
instr.Operand = br.ReadDouble ();
break;
case OperandType.InlineString :
instr.Operand = m_root.Streams.UserStringsHeap [GetRid (br.ReadInt32 ())];
break;
case OperandType.InlineField :
case OperandType.InlineMethod :
case OperandType.InlineType :
case OperandType.InlineTok :
MetadataToken token = new MetadataToken (br.ReadInt32 ());
switch (token.TokenType) {
case TokenType.TypeDef:
instr.Operand = m_reflectReader.GetTypeDefAt (token.RID);
break;
case TokenType.TypeRef:
instr.Operand = m_reflectReader.GetTypeRefAt (token.RID);
break;
case TokenType.TypeSpec:
instr.Operand = m_reflectReader.GetTypeSpecAt (token.RID, context);
break;
case TokenType.Field:
instr.Operand = m_reflectReader.GetFieldDefAt (token.RID);
break;
case TokenType.Method:
instr.Operand = m_reflectReader.GetMethodDefAt (token.RID);
break;
case TokenType.MethodSpec:
instr.Operand = m_reflectReader.GetMethodSpecAt (token.RID, context);
break;
case TokenType.MemberRef:
instr.Operand = m_reflectReader.GetMemberRefAt (token.RID, context);
break;
default:
throw new ReflectionException ("Wrong token: " + token);
}
break;
}
instructions.Add (instr.Offset, instr);
if (last != null) {
last.Next = instr;
instr.Previous = last;
}
last = instr;
code.Add (instr);
}
// resolve branches
foreach (Instruction i in code) {
switch (i.OpCode.OperandType) {
case OperandType.ShortInlineBrTarget:
case OperandType.InlineBrTarget:
i.Operand = GetInstruction (body, instructions, (int) i.Operand);
break;
case OperandType.InlineSwitch:
int [] lbls = (int []) i.Operand;
Instruction [] instrs = new Instruction [lbls.Length];
for (int j = 0; j < lbls.Length; j++)
instrs [j] = GetInstruction (body, instructions, lbls [j]);
i.Operand = instrs;
break;
}
}
}
static Instruction GetInstruction (MethodBody body, IDictionary instructions, int offset)
{
Instruction instruction = instructions [offset] as Instruction;
if (instruction != null)
return instruction;
return body.Instructions.Outside;
}
void ReadSection (MethodBody body, BinaryReader br, IDictionary instructions)
{
br.BaseStream.Position += 3;
br.BaseStream.Position &= ~3;
byte flags = br.ReadByte ();
if ((flags & (byte) MethodDataSection.FatFormat) == 0) {
int length = br.ReadByte () / 12;
br.ReadBytes (2);
for (int i = 0; i < length; i++) {
ExceptionHandler eh = new ExceptionHandler (
(ExceptionHandlerType) (br.ReadInt16 () & 0x7));
eh.TryStart = GetInstruction (body, instructions, Convert.ToInt32 (br.ReadInt16 ()));
eh.TryEnd = GetInstruction (body, instructions, eh.TryStart.Offset + Convert.ToInt32 (br.ReadByte ()));
eh.HandlerStart = GetInstruction (body, instructions, Convert.ToInt32 (br.ReadInt16 ()));
eh.HandlerEnd = GetInstruction (body, instructions, eh.HandlerStart.Offset + Convert.ToInt32 (br.ReadByte ()));
ReadExceptionHandlerEnd (eh, br, body, instructions);
body.ExceptionHandlers.Add (eh);
}
} else {
br.BaseStream.Position--;
int length = (br.ReadInt32 () >> 8) / 24;
if ((flags & (int) MethodDataSection.EHTable) == 0)
br.ReadBytes (length * 24);
for (int i = 0; i < length; i++) {
ExceptionHandler eh = new ExceptionHandler (
(ExceptionHandlerType) (br.ReadInt32 () & 0x7));
eh.TryStart = GetInstruction (body, instructions, br.ReadInt32 ());
eh.TryEnd = GetInstruction (body, instructions, eh.TryStart.Offset + br.ReadInt32 ());
eh.HandlerStart = GetInstruction (body, instructions, br.ReadInt32 ());
eh.HandlerEnd = GetInstruction (body, instructions, eh.HandlerStart.Offset + br.ReadInt32 ());
ReadExceptionHandlerEnd(eh, br, body, instructions);
body.ExceptionHandlers.Add (eh);
}
}
if ((flags & (byte) MethodDataSection.MoreSects) != 0)
ReadSection (body, br, instructions);
}
void ReadExceptionHandlerEnd (ExceptionHandler eh, BinaryReader br, MethodBody body, IDictionary instructions)
{
switch (eh.Type) {
case ExceptionHandlerType.Catch :
MetadataToken token = new MetadataToken (br.ReadInt32 ());
eh.CatchType = m_reflectReader.GetTypeDefOrRef (token, new GenericContext (body.Method));
break;
case ExceptionHandlerType.Filter :
eh.FilterStart = GetInstruction (body, instructions, br.ReadInt32 ());
eh.FilterEnd = GetInstruction (body, instructions, eh.HandlerStart.Previous.Offset);
break;
default :
br.ReadInt32 ();
break;
}
}
CallSite GetCallSiteAt (int token, GenericContext context)
{
StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable ();
MethodSig ms = m_reflectReader.SigReader.GetStandAloneMethodSig (
sasTable [(int) GetRid (token) - 1].Signature);
CallSite cs = new CallSite (ms.HasThis, ms.ExplicitThis,
ms.MethCallConv, m_reflectReader.GetMethodReturnType (ms, context));
cs.MetadataToken = new MetadataToken (token);
for (int i = 0; i < ms.ParamCount; i++) {
Param p = ms.Parameters [i];
cs.Parameters.Add (m_reflectReader.BuildParameterDefinition (i, p, context));
}
ReflectionReader.CreateSentinelIfNeeded (cs, ms);
return cs;
}
public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
{
MethodBody body = variables.Container as MethodBody;
if (body == null || body.LocalVarToken == 0)
return;
StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable ();
StandAloneSigRow sasRow = sasTable [(int) GetRid (body.LocalVarToken) - 1];
LocalVarSig sig = m_reflectReader.SigReader.GetLocalVarSig (sasRow.Signature);
for (int i = 0; i < sig.Count; i++) {
LocalVarSig.LocalVariable lv = sig.LocalVariables [i];
TypeReference varType = m_reflectReader.GetTypeRefFromSig (
lv.Type, new GenericContext (body.Method));
if (lv.ByRef)
varType = new ReferenceType (varType);
if ((lv.Constraint & Constraint.Pinned) != 0)
varType = new PinnedType (varType);
varType = m_reflectReader.GetModifierType (lv.CustomMods, varType);
body.Variables.Add (new VariableDefinition (
string.Concat ("V_", i), i, body.Method, varType));
}
}
}
}

528
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs

@ -0,0 +1,528 @@ @@ -0,0 +1,528 @@
//
// CodeWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using System.Collections;
using Mono.Cecil;
using Mono.Cecil.Binary;
using Mono.Cecil.Metadata;
using Mono.Cecil.Signatures;
class CodeWriter : BaseCodeVisitor {
ReflectionWriter m_reflectWriter;
MemoryBinaryWriter m_binaryWriter;
MemoryBinaryWriter m_codeWriter;
IDictionary m_localSigCache;
IDictionary m_standaloneSigCache;
public CodeWriter (ReflectionWriter reflectWriter, MemoryBinaryWriter writer)
{
m_reflectWriter = reflectWriter;
m_binaryWriter = writer;
m_codeWriter = new MemoryBinaryWriter ();
m_localSigCache = new Hashtable ();
m_standaloneSigCache = new Hashtable ();
}
public RVA WriteMethodBody (MethodDefinition meth)
{
if (meth.Body == null)
return RVA.Zero;
RVA ret = m_reflectWriter.MetadataWriter.GetDataCursor ();
meth.Body.Accept (this);
return ret;
}
public override void VisitMethodBody (MethodBody body)
{
m_codeWriter.Empty ();
}
void WriteToken (MetadataToken token)
{
if (token.RID == 0)
m_codeWriter.Write (0);
else
m_codeWriter.Write (token.ToUInt ());
}
static int GetParameterIndex (MethodBody body, ParameterDefinition p)
{
int idx = body.Method.Parameters.IndexOf (p);
if (idx == -1 && p == body.Method.This)
return 0;
if (body.Method.HasThis)
idx++;
return idx;
}
public override void VisitInstructionCollection (InstructionCollection instructions)
{
MethodBody body = instructions.Container;
long start = m_codeWriter.BaseStream.Position;
ComputeMaxStack (instructions);
foreach (Instruction instr in instructions) {
instr.Offset = (int) (m_codeWriter.BaseStream.Position - start);
if (instr.OpCode.Size == 1)
m_codeWriter.Write (instr.OpCode.Op2);
else {
m_codeWriter.Write (instr.OpCode.Op1);
m_codeWriter.Write (instr.OpCode.Op2);
}
if (instr.OpCode.OperandType != OperandType.InlineNone &&
instr.Operand == null)
throw new ReflectionException ("OpCode {0} have null operand", instr.OpCode.Name);
switch (instr.OpCode.OperandType) {
case OperandType.InlineNone :
break;
case OperandType.InlineSwitch :
Instruction [] targets = (Instruction []) instr.Operand;
for (int i = 0; i < targets.Length + 1; i++)
m_codeWriter.Write ((uint) 0);
break;
case OperandType.ShortInlineBrTarget :
m_codeWriter.Write ((byte) 0);
break;
case OperandType.InlineBrTarget :
m_codeWriter.Write (0);
break;
case OperandType.ShortInlineI :
if (instr.OpCode == OpCodes.Ldc_I4_S)
m_codeWriter.Write ((sbyte) instr.Operand);
else
m_codeWriter.Write ((byte) instr.Operand);
break;
case OperandType.ShortInlineVar :
m_codeWriter.Write ((byte) body.Variables.IndexOf (
(VariableDefinition) instr.Operand));
break;
case OperandType.ShortInlineParam :
m_codeWriter.Write ((byte) GetParameterIndex (body, (ParameterDefinition) instr.Operand));
break;
case OperandType.InlineSig :
WriteToken (GetCallSiteToken ((CallSite) instr.Operand));
break;
case OperandType.InlineI :
m_codeWriter.Write ((int) instr.Operand);
break;
case OperandType.InlineVar :
m_codeWriter.Write ((short) body.Variables.IndexOf (
(VariableDefinition) instr.Operand));
break;
case OperandType.InlineParam :
m_codeWriter.Write ((short) GetParameterIndex (
body, (ParameterDefinition) instr.Operand));
break;
case OperandType.InlineI8 :
m_codeWriter.Write ((long) instr.Operand);
break;
case OperandType.ShortInlineR :
m_codeWriter.Write ((float) instr.Operand);
break;
case OperandType.InlineR :
m_codeWriter.Write ((double) instr.Operand);
break;
case OperandType.InlineString :
WriteToken (new MetadataToken (TokenType.String,
m_reflectWriter.MetadataWriter.AddUserString (instr.Operand as string)));
break;
case OperandType.InlineField :
case OperandType.InlineMethod :
case OperandType.InlineType :
case OperandType.InlineTok :
if (instr.Operand is TypeReference)
WriteToken (m_reflectWriter.GetTypeDefOrRefToken (
instr.Operand as TypeReference));
else if (instr.Operand is GenericInstanceMethod)
WriteToken (m_reflectWriter.GetMethodSpecToken (instr.Operand as GenericInstanceMethod));
else if (instr.Operand is MemberReference)
WriteToken (m_reflectWriter.GetMemberRefToken ((MemberReference) instr.Operand));
else if (instr.Operand is IMetadataTokenProvider)
WriteToken (((IMetadataTokenProvider) instr.Operand).MetadataToken);
else
throw new ReflectionException (
string.Format ("Wrong operand for {0} OpCode: {1}",
instr.OpCode.OperandType,
instr.Operand.GetType ().FullName));
break;
}
}
// patch branches
long pos = m_codeWriter.BaseStream.Position;
foreach (Instruction instr in instructions) {
switch (instr.OpCode.OperandType) {
case OperandType.InlineSwitch :
m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size;
Instruction [] targets = (Instruction []) instr.Operand;
m_codeWriter.Write ((uint) targets.Length);
foreach (Instruction tgt in targets)
m_codeWriter.Write ((tgt.Offset - (instr.Offset +
instr.OpCode.Size + (4 * (targets.Length + 1)))));
break;
case OperandType.ShortInlineBrTarget :
m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size;
m_codeWriter.Write ((byte) (((Instruction) instr.Operand).Offset -
(instr.Offset + instr.OpCode.Size + 1)));
break;
case OperandType.InlineBrTarget :
m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size;
m_codeWriter.Write(((Instruction) instr.Operand).Offset -
(instr.Offset + instr.OpCode.Size + 4));
break;
}
}
m_codeWriter.BaseStream.Position = pos;
}
MetadataToken GetCallSiteToken (CallSite cs)
{
uint sig;
int sentinel = cs.GetSentinel ();
if (sentinel > 0)
sig = m_reflectWriter.SignatureWriter.AddMethodDefSig (
m_reflectWriter.GetMethodDefSig (cs));
else
sig = m_reflectWriter.SignatureWriter.AddMethodRefSig (
m_reflectWriter.GetMethodRefSig (cs));
if (m_standaloneSigCache.Contains (sig))
return (MetadataToken) m_standaloneSigCache [sig];
StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable ();
StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow (sig);
sasTable.Rows.Add(sasRow);
MetadataToken token = new MetadataToken (TokenType.Signature, (uint) sasTable.Rows.Count);
m_standaloneSigCache [sig] = token;
return token;
}
static int GetLength (Instruction start, Instruction end, InstructionCollection instructions)
{
Instruction last = instructions [instructions.Count - 1];
return (end == instructions.Outside ? last.Offset + GetSize (last) : end.Offset) - start.Offset;
}
static int GetSize (Instruction i)
{
int size = i.OpCode.Size;
switch (i.OpCode.OperandType) {
case OperandType.InlineSwitch:
size += ((Instruction []) i.Operand).Length * 4;
break;
case OperandType.InlineI8:
case OperandType.InlineR:
size += 8;
break;
case OperandType.InlineBrTarget:
case OperandType.InlineField:
case OperandType.InlineI:
case OperandType.InlineMethod:
case OperandType.InlineString:
case OperandType.InlineTok:
case OperandType.InlineType:
case OperandType.ShortInlineR:
size += 4;
break;
case OperandType.InlineParam:
case OperandType.InlineVar:
size += 2;
break;
case OperandType.ShortInlineBrTarget:
case OperandType.ShortInlineI:
case OperandType.ShortInlineParam:
case OperandType.ShortInlineVar:
size += 1;
break;
}
return size;
}
static bool IsRangeFat (Instruction start, Instruction end, InstructionCollection instructions)
{
return GetLength (start, end, instructions) >= 256 ||
start.Offset >= 65536;
}
static bool IsFat (ExceptionHandlerCollection seh)
{
for (int i = 0; i < seh.Count; i++) {
ExceptionHandler eh = seh [i];
if (IsRangeFat (eh.TryStart, eh.TryEnd, seh.Container.Instructions))
return true;
if (IsRangeFat (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions))
return true;
switch (eh.Type) {
case ExceptionHandlerType.Filter :
if (IsRangeFat (eh.FilterStart, eh.FilterEnd, seh.Container.Instructions))
return true;
break;
}
}
return false;
}
void WriteExceptionHandlerCollection (ExceptionHandlerCollection seh)
{
m_codeWriter.QuadAlign ();
if (seh.Count < 0x15 && !IsFat (seh)) {
m_codeWriter.Write ((byte) MethodDataSection.EHTable);
m_codeWriter.Write ((byte) (seh.Count * 12 + 4));
m_codeWriter.Write (new byte [2]);
foreach (ExceptionHandler eh in seh) {
m_codeWriter.Write ((ushort) eh.Type);
m_codeWriter.Write ((ushort) eh.TryStart.Offset);
m_codeWriter.Write ((byte) (eh.TryEnd.Offset - eh.TryStart.Offset));
m_codeWriter.Write ((ushort) eh.HandlerStart.Offset);
m_codeWriter.Write ((byte) GetLength (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions));
WriteHandlerSpecific (eh);
}
} else {
m_codeWriter.Write ((byte) (MethodDataSection.FatFormat | MethodDataSection.EHTable));
WriteFatBlockSize (seh);
foreach (ExceptionHandler eh in seh) {
m_codeWriter.Write ((uint) eh.Type);
m_codeWriter.Write ((uint) eh.TryStart.Offset);
m_codeWriter.Write ((uint) (eh.TryEnd.Offset - eh.TryStart.Offset));
m_codeWriter.Write ((uint) eh.HandlerStart.Offset);
m_codeWriter.Write ((uint) GetLength (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions));
WriteHandlerSpecific (eh);
}
}
}
void WriteFatBlockSize (ExceptionHandlerCollection seh)
{
int size = seh.Count * 24 + 4;
m_codeWriter.Write ((byte) (size & 0xff));
m_codeWriter.Write ((byte) ((size >> 8) & 0xff));
m_codeWriter.Write ((byte) ((size >> 16) & 0xff));
}
void WriteHandlerSpecific (ExceptionHandler eh)
{
switch (eh.Type) {
case ExceptionHandlerType.Catch :
WriteToken (eh.CatchType.MetadataToken);
break;
case ExceptionHandlerType.Filter :
m_codeWriter.Write ((uint) eh.FilterStart.Offset);
break;
default :
m_codeWriter.Write (0);
break;
}
}
public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
{
MethodBody body = variables.Container as MethodBody;
if (body == null)
return;
uint sig = m_reflectWriter.SignatureWriter.AddLocalVarSig (
GetLocalVarSig (variables));
if (m_localSigCache.Contains (sig)) {
body.LocalVarToken = (int) m_localSigCache [sig];
return;
}
StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable ();
StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow (
sig);
sasTable.Rows.Add (sasRow);
body.LocalVarToken = sasTable.Rows.Count;
m_localSigCache [sig] = body.LocalVarToken;
}
public override void TerminateMethodBody (MethodBody body)
{
long pos = m_binaryWriter.BaseStream.Position;
if (body.Variables.Count > 0 || body.ExceptionHandlers.Count > 0
|| m_codeWriter.BaseStream.Length >= 64 || body.MaxStack > 8) {
MethodHeader header = MethodHeader.FatFormat;
if (body.InitLocals)
header |= MethodHeader.InitLocals;
if (body.ExceptionHandlers.Count > 0)
header |= MethodHeader.MoreSects;
m_binaryWriter.Write ((byte) header);
m_binaryWriter.Write ((byte) 0x30); // (header size / 4) << 4
m_binaryWriter.Write ((short) body.MaxStack);
m_binaryWriter.Write ((int) m_codeWriter.BaseStream.Length);
m_binaryWriter.Write (((int) TokenType.Signature | body.LocalVarToken));
WriteExceptionHandlerCollection (body.ExceptionHandlers);
} else
m_binaryWriter.Write ((byte) ((byte) MethodHeader.TinyFormat |
m_codeWriter.BaseStream.Length << 2));
m_binaryWriter.Write (m_codeWriter);
m_binaryWriter.QuadAlign ();
m_reflectWriter.MetadataWriter.AddData (
(int) (m_binaryWriter.BaseStream.Position - pos));
}
public LocalVarSig.LocalVariable GetLocalVariableSig (VariableDefinition var)
{
LocalVarSig.LocalVariable lv = new LocalVarSig.LocalVariable ();
TypeReference type = var.VariableType;
lv.CustomMods = m_reflectWriter.GetCustomMods (type);
if (type is PinnedType) {
lv.Constraint |= Constraint.Pinned;
type = (type as PinnedType).ElementType;
}
if (type is ReferenceType) {
lv.ByRef = true;
type = (type as ReferenceType).ElementType;
}
lv.Type = m_reflectWriter.GetSigType (type);
return lv;
}
public LocalVarSig GetLocalVarSig (VariableDefinitionCollection vars)
{
LocalVarSig lvs = new LocalVarSig ();
lvs.CallingConvention |= 0x7;
lvs.Count = vars.Count;
lvs.LocalVariables = new LocalVarSig.LocalVariable [lvs.Count];
for (int i = 0; i < lvs.Count; i++) {
lvs.LocalVariables [i] = GetLocalVariableSig (vars [i]);
}
return lvs;
}
static void ComputeMaxStack (InstructionCollection instructions)
{
InstructionCollection ehs = new InstructionCollection (null);
foreach (ExceptionHandler eh in instructions.Container.ExceptionHandlers) {
switch (eh.Type) {
case ExceptionHandlerType.Catch :
ehs.Add (eh.HandlerStart);
break;
case ExceptionHandlerType.Filter :
ehs.Add (eh.FilterStart);
break;
}
}
int max = 0, current = 0;
foreach (Instruction instr in instructions) {
if (ehs.Contains (instr))
current++;
switch (instr.OpCode.StackBehaviourPush) {
case StackBehaviour.Push1:
case StackBehaviour.Pushi:
case StackBehaviour.Pushi8:
case StackBehaviour.Pushr4:
case StackBehaviour.Pushr8:
case StackBehaviour.Pushref:
case StackBehaviour.Varpush:
current++;
break;
case StackBehaviour.Push1_push1:
current += 2;
break;
}
if (max < current)
max = current;
switch (instr.OpCode.StackBehaviourPop) {
case StackBehaviour.Varpop:
break;
case StackBehaviour.Pop1:
case StackBehaviour.Popi:
case StackBehaviour.Popref:
current--;
break;
case StackBehaviour.Pop1_pop1:
case StackBehaviour.Popi_pop1:
case StackBehaviour.Popi_popi:
case StackBehaviour.Popi_popi8:
case StackBehaviour.Popi_popr4:
case StackBehaviour.Popi_popr8:
case StackBehaviour.Popref_pop1:
case StackBehaviour.Popref_popi:
current -= 2;
break;
case StackBehaviour.Popi_popi_popi:
case StackBehaviour.Popref_popi_popi:
case StackBehaviour.Popref_popi_popi8:
case StackBehaviour.Popref_popi_popr4:
case StackBehaviour.Popref_popi_popr8:
case StackBehaviour.Popref_popi_popref:
current -= 3;
break;
}
if (current < 0)
current = 0;
}
instructions.Container.MaxStack = max;
}
}
}

78
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/Document.cs

@ -0,0 +1,78 @@ @@ -0,0 +1,78 @@
//
// Document.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public class Document {
string m_url;
DocumentType m_type;
DocumentHashAlgorithm m_hashAlgorithm;
DocumentLanguage m_language;
DocumentLanguageVendor m_languageVendor;
byte [] m_hash;
public string Url {
get { return m_url; }
set { m_url = value; }
}
public DocumentType Type {
get { return m_type; }
set { m_type = value; }
}
public DocumentHashAlgorithm HashAlgorithm {
get { return m_hashAlgorithm; }
set { m_hashAlgorithm = value; }
}
public DocumentLanguage Language {
get { return m_language; }
set { m_language = value; }
}
public DocumentLanguageVendor LanguageVendor {
get { return m_languageVendor; }
set { m_languageVendor = value; }
}
public byte [] Hash {
get { return m_hash; }
set { m_hash = value; }
}
public Document (string url)
{
m_url = url;
m_hash = new byte [0];
}
}
}

36
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentHashAlgorithm.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
//
// DocumentHashAlgorithm.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public enum DocumentHashAlgorithm {
[Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)] None,
[Guid (0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99)] MD5,
[Guid (0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60)] SHA1
}
}

45
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguage.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
//
// DocumentLanguage.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public enum DocumentLanguage {
[Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00)] None,
[Guid (0x63a08714, 0xfc37, 0x11d2, 0x90, 0x4c, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1)] C,
[Guid (0x3a12d0b7, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2)] Cpp,
[Guid (0x3f5162f8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1)] CSharp,
[Guid (0x3a12d0b8, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2)] Basic,
[Guid (0x3a12d0b4, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2)] Java,
[Guid (0xaf046cd1, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc)] Cobol,
[Guid (0xaf046cd2, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc)] Pascal,
[Guid (0xaf046cd3, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc)] CIL,
[Guid (0x3a12d0b6, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2)] JScript,
[Guid (0xd9b9f7b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x0, 0x0, 0xf8, 0x8, 0x49, 0xbd)] SMC,
[Guid (0x4b35fde8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1)] MCpp
}
}

35
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguageVendor.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
//
// DocumentLanguageVendor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public enum DocumentLanguageVendor {
[Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)] Other,
[Guid (0x994b45c4, 0xe6e9, 0x11d2, 0x90, 0x3f, 0x00, 0xc0, 0x4f, 0xa3, 0x02, 0xa1)] Microsoft
}
}

35
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
//
// DocumentType.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public enum DocumentType {
[Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)] Other,
[Guid (0x5a869d0b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x00, 0x00, 0xf8, 0x08, 0x49, 0xbd)] Text
}
}

95
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs

@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
//
// ExceptionHandler.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using Mono.Cecil;
public sealed class ExceptionHandler : ICodeVisitable {
Instruction m_tryStart;
Instruction m_tryEnd;
Instruction m_filterStart;
Instruction m_filterEnd;
Instruction m_handlerStart;
Instruction m_handlerEnd;
TypeReference m_catchType;
ExceptionHandlerType m_type;
public Instruction TryStart {
get { return m_tryStart; }
set { m_tryStart = value; }
}
public Instruction TryEnd {
get { return m_tryEnd; }
set { m_tryEnd = value; }
}
public Instruction FilterStart {
get { return m_filterStart; }
set { m_filterStart = value; }
}
public Instruction FilterEnd {
get { return m_filterEnd; }
set { m_filterEnd = value; }
}
public Instruction HandlerStart {
get { return m_handlerStart; }
set { m_handlerStart = value; }
}
public Instruction HandlerEnd {
get { return m_handlerEnd; }
set { m_handlerEnd = value; }
}
public TypeReference CatchType {
get { return m_catchType; }
set { m_catchType = value; }
}
public ExceptionHandlerType Type {
get { return m_type; }
set { m_type = value; }
}
public ExceptionHandler (ExceptionHandlerType type)
{
m_type = type;
}
public void Accept (ICodeVisitor visitor)
{
visitor.VisitExceptionHandler (this);
}
}
}

93
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerCollection.cs

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
//
// ExceptionHandlerCollection.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Generated by /CodeGen/cecil-gen.rb do not edit
// Wed Sep 27 12:46:53 CEST 2006
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using System.Collections;
using Mono.Cecil.Cil;
public sealed class ExceptionHandlerCollection : CollectionBase, ICodeVisitable {
MethodBody m_container;
public ExceptionHandler this [int index] {
get { return List [index] as ExceptionHandler; }
set { List [index] = value; }
}
public MethodBody Container {
get { return m_container; }
}
public ExceptionHandlerCollection (MethodBody container)
{
m_container = container;
}
public void Add (ExceptionHandler value)
{
List.Add (value);
}
public bool Contains (ExceptionHandler value)
{
return List.Contains (value);
}
public int IndexOf (ExceptionHandler value)
{
return List.IndexOf (value);
}
public void Insert (int index, ExceptionHandler value)
{
List.Insert (index, value);
}
public void Remove (ExceptionHandler value)
{
List.Remove (value);
}
protected override void OnValidate (object o)
{
if (! (o is ExceptionHandler))
throw new ArgumentException ("Must be of type " + typeof (ExceptionHandler).FullName);
}
public void Accept (ICodeVisitor visitor)
{
visitor.VisitExceptionHandlerCollection (this);
}
}
}

37
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerType.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
//
// ExceptionHandlerType.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public enum ExceptionHandlerType {
Catch = 0x0000,
Filter = 0x0001,
Finally = 0x0002,
Fault = 0x0004
}
}

42
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/FlowControl.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
//
// FlowControl.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public enum FlowControl {
Branch,
Break,
Call,
Cond_Branch,
Meta,
Next,
Phi,
Return,
Throw
}
}

91
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/GuidAttribute.cs

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
//
// GuidAttribute.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
using System.Reflection;
[AttributeUsage (AttributeTargets.Field)]
public class GuidAttribute : Attribute {
private Guid m_guid;
public Guid Guid {
get { return m_guid; }
}
GuidAttribute ()
{
m_guid = new Guid ();
}
public GuidAttribute (
uint a,
ushort b,
ushort c,
byte d,
byte e,
byte f,
byte g,
byte h,
byte i,
byte j,
byte k)
{
m_guid = new Guid ((int) a, (short) b, (short) c, d, e, f, g, h, i, j, k);
}
public static int GetValueFromGuid (Guid id, Type enumeration)
{
foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public))
if (id == GetGuidAttribute (fi).Guid)
return (int) fi.GetValue (null);
return -1;
}
public static Guid GetGuidFromValue (int value, Type enumeration)
{
foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public))
if (value == (int) fi.GetValue (null))
return GetGuidAttribute (fi).Guid;
return new Guid ();
}
static GuidAttribute GetGuidAttribute (FieldInfo fi)
{
GuidAttribute [] attributes = fi.GetCustomAttributes (typeof (GuidAttribute), false) as GuidAttribute [];
if (attributes == null || attributes.Length != 1)
return new GuidAttribute ();
return attributes [0];
}
}
}

34
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitable.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
//
// ICodeVisitable.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public interface ICodeVisitable {
void Accept (ICodeVisitor visitor);
}
}

45
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitor.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
//
// ICodeVisitor.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2005 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public interface ICodeVisitor {
void VisitMethodBody (MethodBody body);
void VisitInstructionCollection (InstructionCollection instructions);
void VisitInstruction (Instruction instr);
void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh);
void VisitExceptionHandler (ExceptionHandler eh);
void VisitVariableDefinitionCollection (VariableDefinitionCollection variables);
void VisitVariableDefinition (VariableDefinition var);
void VisitScopeCollection (ScopeCollection scopes);
void VisitScope (Scope scope);
void TerminateMethodBody (MethodBody body);
}
}

35
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/IScopeProvider.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
//
// Document.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public interface IScopeProvider {
ScopeCollection Scopes { get; }
}
}

37
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ISymbolReader.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
//
// ISymbolReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
public interface ISymbolReader : IDisposable {
void Read (MethodBody body);
}
}

36
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ISymbolStoreFactory.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
//
// ISymbolStoreFactory.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public interface ISymbolStoreFactory {
ISymbolReader CreateReader (ModuleDefinition module, string assemblyFileName);
ISymbolWriter CreateWriter (ModuleDefinition module, string assemblyFileName);
}
}

37
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/ISymbolWriter.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
//
// ISymbolWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 - 2007 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
using System;
public interface ISymbolWriter : IDisposable {
void Write (MethodBody body, byte [][] variables);
}
}

35
lib/cecil-0.6/src/Mono.Cecil/Mono.Cecil.Cil/IVariableDefinitionProvider.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
//
// IVariableDefinitionProvider.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Cecil.Cil {
public interface IVariableDefinitionProvider {
VariableDefinitionCollection Variables { get; }
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save