mirror of
https://github.com/Perfare/Il2CppDumper.git
synced 2025-01-09 11:17:35 -03:00
使用预生成的dll避免错误的引用
This commit is contained in:
parent
105595e421
commit
7941fa9975
6 changed files with 242 additions and 98 deletions
|
@ -15,6 +15,21 @@
|
|||
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resource1.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resource1.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resource1.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="config.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
|
BIN
Il2CppDumper/Libraries/Il2CppDummyDll.dll
Normal file
BIN
Il2CppDumper/Libraries/Il2CppDummyDll.dll
Normal file
Binary file not shown.
73
Il2CppDumper/Resource1.Designer.cs
generated
Normal file
73
Il2CppDumper/Resource1.Designer.cs
generated
Normal file
|
@ -0,0 +1,73 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Il2CppDumper {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||
/// </summary>
|
||||
// 此类是由 StronglyTypedResourceBuilder
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resource1 {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resource1() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Il2CppDumper.Resource1", typeof(Resource1).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写当前线程的 CurrentUICulture 属性,对
|
||||
/// 使用此强类型资源类的所有资源查找执行重写。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Byte[] 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static byte[] Il2CppDummyDll {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("Il2CppDummyDll", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
124
Il2CppDumper/Resource1.resx
Normal file
124
Il2CppDumper/Resource1.resx
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="Il2CppDummyDll" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Libraries\Il2CppDummyDll.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
|
@ -3,6 +3,7 @@ using Mono.Cecil.Cil;
|
|||
using Mono.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Il2CppDumper
|
||||
|
@ -18,6 +19,7 @@ namespace Il2CppDumper
|
|||
private Dictionary<Il2CppGenericParameter, GenericParameter> genericParameterDic = new Dictionary<Il2CppGenericParameter, GenericParameter>();
|
||||
private MethodDefinition attributeAttribute;
|
||||
private TypeReference stringType;
|
||||
private TypeSystem typeSystem;
|
||||
private Dictionary<int, FieldDefinition> fieldDefinitionDic = new Dictionary<int, FieldDefinition>();
|
||||
private Dictionary<int, PropertyDefinition> propertyDefinitionDic = new Dictionary<int, PropertyDefinition>();
|
||||
private Dictionary<int, MethodDefinition> methodDefinitionDic = new Dictionary<int, MethodDefinition>();
|
||||
|
@ -29,14 +31,16 @@ namespace Il2CppDumper
|
|||
il2Cpp = il2CppExecutor.il2Cpp;
|
||||
|
||||
//Il2CppDummyDll
|
||||
var il2CppDummyDll = Il2CppDummyDll.Create();
|
||||
var il2CppDummyDll = AssemblyDefinition.ReadAssembly(new MemoryStream(Resource1.Il2CppDummyDll));
|
||||
Assemblies.Add(il2CppDummyDll);
|
||||
var addressAttribute = il2CppDummyDll.MainModule.Types.First(x => x.Name == "AddressAttribute").Methods[0];
|
||||
var fieldOffsetAttribute = il2CppDummyDll.MainModule.Types.First(x => x.Name == "FieldOffsetAttribute").Methods[0];
|
||||
attributeAttribute = il2CppDummyDll.MainModule.Types.First(x => x.Name == "AttributeAttribute").Methods[0];
|
||||
var metadataOffsetAttribute = il2CppDummyDll.MainModule.Types.First(x => x.Name == "MetadataOffsetAttribute").Methods[0];
|
||||
var tokenAttribute = il2CppDummyDll.MainModule.Types.First(x => x.Name == "TokenAttribute").Methods[0];
|
||||
stringType = il2CppDummyDll.MainModule.TypeSystem.String;
|
||||
var dummyMD = il2CppDummyDll.MainModule;
|
||||
var addressAttribute = dummyMD.Types.First(x => x.Name == "AddressAttribute").Methods[0];
|
||||
var fieldOffsetAttribute = dummyMD.Types.First(x => x.Name == "FieldOffsetAttribute").Methods[0];
|
||||
attributeAttribute = dummyMD.Types.First(x => x.Name == "AttributeAttribute").Methods[0];
|
||||
var metadataOffsetAttribute = dummyMD.Types.First(x => x.Name == "MetadataOffsetAttribute").Methods[0];
|
||||
var tokenAttribute = dummyMD.Types.First(x => x.Name == "TokenAttribute").Methods[0];
|
||||
stringType = dummyMD.TypeSystem.String;
|
||||
typeSystem = dummyMD.TypeSystem;
|
||||
|
||||
var resolver = new MyAssemblyResolver();
|
||||
var moduleParameters = new ModuleParameters
|
||||
|
@ -217,7 +221,7 @@ namespace Il2CppDumper
|
|||
{
|
||||
var methodDef = metadata.methodDefs[i];
|
||||
var methodName = metadata.GetStringFromIndex(methodDef.nameIndex);
|
||||
var methodDefinition = new MethodDefinition(methodName, (MethodAttributes)methodDef.flags, typeDefinition.Module.ImportReference(typeof(void)));
|
||||
var methodDefinition = new MethodDefinition(methodName, (MethodAttributes)methodDef.flags, typeDefinition.Module.ImportReference(typeSystem.Void));
|
||||
methodDefinition.ImplAttributes = (MethodImplAttributes)methodDef.iflags;
|
||||
typeDefinition.Methods.Add(methodDefinition);
|
||||
//genericParameter
|
||||
|
@ -462,41 +466,41 @@ namespace Il2CppDumper
|
|||
switch (il2CppType.type)
|
||||
{
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT:
|
||||
return moduleDefinition.ImportReference(typeof(object));
|
||||
return moduleDefinition.ImportReference(typeSystem.Object);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_VOID:
|
||||
return moduleDefinition.ImportReference(typeof(void));
|
||||
return moduleDefinition.ImportReference(typeSystem.Void);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
|
||||
return moduleDefinition.ImportReference(typeof(bool));
|
||||
return moduleDefinition.ImportReference(typeSystem.Boolean);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
|
||||
return moduleDefinition.ImportReference(typeof(char));
|
||||
return moduleDefinition.ImportReference(typeSystem.Char);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_I1:
|
||||
return moduleDefinition.ImportReference(typeof(sbyte));
|
||||
return moduleDefinition.ImportReference(typeSystem.SByte);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_U1:
|
||||
return moduleDefinition.ImportReference(typeof(byte));
|
||||
return moduleDefinition.ImportReference(typeSystem.Byte);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_I2:
|
||||
return moduleDefinition.ImportReference(typeof(short));
|
||||
return moduleDefinition.ImportReference(typeSystem.Int16);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_U2:
|
||||
return moduleDefinition.ImportReference(typeof(ushort));
|
||||
return moduleDefinition.ImportReference(typeSystem.UInt16);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_I4:
|
||||
return moduleDefinition.ImportReference(typeof(int));
|
||||
return moduleDefinition.ImportReference(typeSystem.Int32);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_U4:
|
||||
return moduleDefinition.ImportReference(typeof(uint));
|
||||
return moduleDefinition.ImportReference(typeSystem.UInt32);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_I:
|
||||
return moduleDefinition.ImportReference(typeof(IntPtr));
|
||||
return moduleDefinition.ImportReference(typeSystem.IntPtr);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_U:
|
||||
return moduleDefinition.ImportReference(typeof(UIntPtr));
|
||||
return moduleDefinition.ImportReference(typeSystem.UIntPtr);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_I8:
|
||||
return moduleDefinition.ImportReference(typeof(long));
|
||||
return moduleDefinition.ImportReference(typeSystem.Int64);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_U8:
|
||||
return moduleDefinition.ImportReference(typeof(ulong));
|
||||
return moduleDefinition.ImportReference(typeSystem.UInt64);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_R4:
|
||||
return moduleDefinition.ImportReference(typeof(float));
|
||||
return moduleDefinition.ImportReference(typeSystem.Single);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_R8:
|
||||
return moduleDefinition.ImportReference(typeof(double));
|
||||
return moduleDefinition.ImportReference(typeSystem.Double);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
|
||||
return moduleDefinition.ImportReference(typeof(string));
|
||||
return moduleDefinition.ImportReference(typeSystem.String);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF:
|
||||
return moduleDefinition.ImportReference(typeof(TypedReference));
|
||||
return moduleDefinition.ImportReference(typeSystem.TypedReference);
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
|
||||
case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
|
||||
{
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using FieldAttributes = Mono.Cecil.FieldAttributes;
|
||||
using MethodAttributes = Mono.Cecil.MethodAttributes;
|
||||
using TypeAttributes = Mono.Cecil.TypeAttributes;
|
||||
|
||||
namespace Il2CppDumper
|
||||
{
|
||||
internal static class Il2CppDummyDll
|
||||
{
|
||||
private static Type attributeType;
|
||||
private static ConstructorInfo attributeConstructor;
|
||||
|
||||
static Il2CppDummyDll()
|
||||
{
|
||||
attributeType = typeof(Attribute);
|
||||
attributeConstructor = attributeType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0];
|
||||
}
|
||||
|
||||
public static AssemblyDefinition Create()
|
||||
{
|
||||
var assemblyName = new AssemblyNameDefinition("Il2CppDummyDll", new Version("3.7.1.6"));
|
||||
var assemblyDefinition = AssemblyDefinition.CreateAssembly(assemblyName, "Il2CppDummyDll.dll", ModuleKind.Dll);
|
||||
var stringTypeReference = assemblyDefinition.MainModule.TypeSystem.String;
|
||||
var attributeTypeReference = assemblyDefinition.MainModule.ImportReference(attributeType);
|
||||
var types = assemblyDefinition.MainModule.Types;
|
||||
var namespaceName = "Il2CppDummyDll";
|
||||
var addressAttribute = new TypeDefinition(namespaceName, "AddressAttribute", (TypeAttributes)0x100001, attributeTypeReference);
|
||||
addressAttribute.Fields.Add(new FieldDefinition("RVA", FieldAttributes.Public, stringTypeReference));
|
||||
addressAttribute.Fields.Add(new FieldDefinition("Offset", FieldAttributes.Public, stringTypeReference));
|
||||
addressAttribute.Fields.Add(new FieldDefinition("VA", FieldAttributes.Public, stringTypeReference));
|
||||
addressAttribute.Fields.Add(new FieldDefinition("Slot", FieldAttributes.Public, stringTypeReference));
|
||||
types.Add(addressAttribute);
|
||||
CreateDefaultConstructor(addressAttribute);
|
||||
var fieldOffsetAttribute = new TypeDefinition(namespaceName, "FieldOffsetAttribute", (TypeAttributes)0x100001, attributeTypeReference);
|
||||
fieldOffsetAttribute.Fields.Add(new FieldDefinition("Offset", FieldAttributes.Public, stringTypeReference));
|
||||
types.Add(fieldOffsetAttribute);
|
||||
CreateDefaultConstructor(fieldOffsetAttribute);
|
||||
var attributeAttribute = new TypeDefinition(namespaceName, "AttributeAttribute", (TypeAttributes)0x100001, attributeTypeReference);
|
||||
attributeAttribute.Fields.Add(new FieldDefinition("Name", FieldAttributes.Public, stringTypeReference));
|
||||
attributeAttribute.Fields.Add(new FieldDefinition("RVA", FieldAttributes.Public, stringTypeReference));
|
||||
attributeAttribute.Fields.Add(new FieldDefinition("Offset", FieldAttributes.Public, stringTypeReference));
|
||||
types.Add(attributeAttribute);
|
||||
CreateDefaultConstructor(attributeAttribute);
|
||||
var metadataOffsetAttribute = new TypeDefinition(namespaceName, "MetadataOffsetAttribute", (TypeAttributes)0x100001, attributeTypeReference);
|
||||
metadataOffsetAttribute.Fields.Add(new FieldDefinition("Offset", FieldAttributes.Public, stringTypeReference));
|
||||
types.Add(metadataOffsetAttribute);
|
||||
CreateDefaultConstructor(metadataOffsetAttribute);
|
||||
var tokenAttribute = new TypeDefinition(namespaceName, "TokenAttribute", (TypeAttributes)0x100001, attributeTypeReference);
|
||||
tokenAttribute.Fields.Add(new FieldDefinition("Token", FieldAttributes.Public, stringTypeReference));
|
||||
types.Add(tokenAttribute);
|
||||
CreateDefaultConstructor(tokenAttribute);
|
||||
return assemblyDefinition;
|
||||
}
|
||||
|
||||
private static void CreateDefaultConstructor(TypeDefinition typeDefinition)
|
||||
{
|
||||
var module = typeDefinition.Module;
|
||||
var defaultConstructor = new MethodDefinition(".ctor",
|
||||
MethodAttributes.Public | MethodAttributes.HideBySig |
|
||||
MethodAttributes.SpecialName | MethodAttributes.RTSpecialName,
|
||||
module.ImportReference(typeof(void)));
|
||||
var processor = defaultConstructor.Body.GetILProcessor();
|
||||
processor.Emit(OpCodes.Ldarg_0);
|
||||
processor.Emit(OpCodes.Call, module.ImportReference(attributeConstructor));
|
||||
processor.Emit(OpCodes.Ret);
|
||||
typeDefinition.Methods.Add(defaultConstructor);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue