Skip to content

Commit

Permalink
使用预生成的dll避免错误的引用
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Mar 1, 2023
1 parent 105595e commit 7941fa9
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 98 deletions.
15 changes: 15 additions & 0 deletions Il2CppDumper/Il2CppDumper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Binary file added Il2CppDumper/Libraries/Il2CppDummyDll.dll
Binary file not shown.
73 changes: 73 additions & 0 deletions Il2CppDumper/Resource1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions Il2CppDumper/Resource1.resx
Original file line number Diff line number Diff line change
@@ -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>
56 changes: 30 additions & 26 deletions Il2CppDumper/Utils/DummyAssemblyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Mono.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Il2CppDumper
Expand All @@ -18,6 +19,7 @@ public class DummyAssemblyGenerator
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>();
Expand All @@ -29,14 +31,16 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor, bool addToken)
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
Expand Down Expand Up @@ -217,7 +221,7 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor, bool addToken)
{
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
Expand Down Expand Up @@ -462,41 +466,41 @@ private TypeReference GetTypeReference(MemberReference memberReference, Il2CppTy
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:
{
Expand Down
Loading

0 comments on commit 7941fa9

Please sign in to comment.