[new] 新增 AOTAssemblyMetadataStripper用于剔除AOT dll中非泛型函数元数据
parent
a531a213c2
commit
f30e2f5b33
|
@ -0,0 +1,46 @@
|
|||
using dnlib.DotNet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HybridCLR.Editor.AOT
|
||||
{
|
||||
public class AOTAssemblyMetadataStripper
|
||||
{
|
||||
public static byte[] Strip(byte[] assemblyBytes)
|
||||
{
|
||||
var mod = ModuleDefMD.Load(assemblyBytes);
|
||||
foreach (var type in mod.GetTypes())
|
||||
{
|
||||
if (type.HasGenericParameters)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (var method in type.Methods)
|
||||
{
|
||||
if (!method.HasBody || method.HasGenericParameters)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
method.Body = null;
|
||||
}
|
||||
}
|
||||
var writer = new System.IO.MemoryStream();
|
||||
mod.Write(writer);
|
||||
writer.Flush();
|
||||
return writer.ToArray();
|
||||
}
|
||||
|
||||
public static void Strip(string originalAssemblyPath, string strippedAssemblyPath)
|
||||
{
|
||||
byte[] originDllBytes = System.IO.File.ReadAllBytes(originalAssemblyPath);
|
||||
byte[] strippedDllBytes = Strip(originDllBytes);
|
||||
UnityEngine.Debug.Log($"aot dll:{originalAssemblyPath}, length: {originDllBytes.Length} -> {strippedDllBytes.Length}, stripping rate:{(originDllBytes.Length - strippedDllBytes.Length)/(double)originDllBytes.Length} ");
|
||||
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(strippedAssemblyPath));
|
||||
System.IO.File.WriteAllBytes(strippedAssemblyPath, strippedDllBytes);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7e9e6a048682dcb4fab806251411f29f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue