如何从 MSIL 或 .NET PE 文件中提取资源内容
How to Extract the Resouce Content From MSIL OR .NET PE Files
请检查图像link,我需要从 MSIL 文件中提取资源内容。我已经使用 ILSpy 调试了该文件,但我需要以任何其他方式进行调试。无需使用任何手动拦截。
你可以用类似的东西来做到这一点:
public class LoadAssemblyInfo : MarshalByRefObject
{
public string AssemblyName { get; set; }
public Tuple<string, byte[]>[] Streams;
public void Load()
{
Assembly assembly = Assembly.ReflectionOnlyLoad(AssemblyName);
string[] resources = assembly.GetManifestResourceNames();
var streams = new List<Tuple<string, byte[]>>();
foreach (string resource in resources)
{
ManifestResourceInfo info = assembly.GetManifestResourceInfo(resource);
using (var stream = assembly.GetManifestResourceStream(resource))
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
streams.Add(Tuple.Create(resource, bytes));
}
}
Streams = streams.ToArray();
}
}
// Adapted from from
public static Tuple<string, byte[]>[] LoadAssembly(string assemblyName)
{
LoadAssemblyInfo lai = new LoadAssemblyInfo
{
AssemblyName = assemblyName,
};
AppDomain tempDomain = null;
try
{
tempDomain = AppDomain.CreateDomain("TemporaryAppDomain");
tempDomain.DoCallBack(lai.Load);
}
finally
{
if (tempDomain != null)
{
AppDomain.Unload(tempDomain);
}
}
return lai.Streams;
}
像这样使用它:
var streams = LoadAssembly("EntityFramework");
streams
是Tuple<string, byte[]>
的数组,其中Item1
是资源的名称,Item2
是资源的二进制内容
它非常复杂,因为它在另一个 AppDomain
中执行 Assembly.ReflectionOnlyLoad
,然后将其卸载 (AppDomain.CreateDomain
/AppDomain.Unload
)。
请检查图像link,我需要从 MSIL 文件中提取资源内容。我已经使用 ILSpy 调试了该文件,但我需要以任何其他方式进行调试。无需使用任何手动拦截。
你可以用类似的东西来做到这一点:
public class LoadAssemblyInfo : MarshalByRefObject
{
public string AssemblyName { get; set; }
public Tuple<string, byte[]>[] Streams;
public void Load()
{
Assembly assembly = Assembly.ReflectionOnlyLoad(AssemblyName);
string[] resources = assembly.GetManifestResourceNames();
var streams = new List<Tuple<string, byte[]>>();
foreach (string resource in resources)
{
ManifestResourceInfo info = assembly.GetManifestResourceInfo(resource);
using (var stream = assembly.GetManifestResourceStream(resource))
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
streams.Add(Tuple.Create(resource, bytes));
}
}
Streams = streams.ToArray();
}
}
// Adapted from from
public static Tuple<string, byte[]>[] LoadAssembly(string assemblyName)
{
LoadAssemblyInfo lai = new LoadAssemblyInfo
{
AssemblyName = assemblyName,
};
AppDomain tempDomain = null;
try
{
tempDomain = AppDomain.CreateDomain("TemporaryAppDomain");
tempDomain.DoCallBack(lai.Load);
}
finally
{
if (tempDomain != null)
{
AppDomain.Unload(tempDomain);
}
}
return lai.Streams;
}
像这样使用它:
var streams = LoadAssembly("EntityFramework");
streams
是Tuple<string, byte[]>
的数组,其中Item1
是资源的名称,Item2
是资源的二进制内容
它非常复杂,因为它在另一个 AppDomain
中执行 Assembly.ReflectionOnlyLoad
,然后将其卸载 (AppDomain.CreateDomain
/AppDomain.Unload
)。