我遇到了最困难的时候。我在谷歌上搜索了几个小时,在这里遇到了很多不同的问题,但我就是找不到
static void Main(string[] args)
{
AppDomainSetup domainSetup = new AppDomainSetup { PrivateBinPath = typeof(Program).Assembly.Location };
AppDomain domain = AppDomain.CreateDomain("TempDomain", null, domainSetup);
InstanceProxy proxy = domain.CreateInstanceFromAndUnwrap(typeof(Program).Assembly.Location, typeof(InstanceProxy).ToString()) as InstanceProxy;
if (proxy != null)
{
proxy.LoadAssembly(Properties.Resources.mfX3DAu);
}
AppDomain.Unload(domain);
Console.Read();
}
public class InstanceProxy : MarshalByRefObject
{
public void LoadAssembly(byte[] buffer)
{
Assembly asm = Assembly.Load(buffer);
asm.EntryPoint.Invoke(null, null);
}
}
资源"mfX3DAu"是一个。Net Assembly被Confuser混淆。
它加载良好,并且在新的AppDomain中,但每次我尝试调用它时,我都会得到
类型为"System"的未处理异常。发生ExecutionEngineException
之前和我交谈过的人说,他们通过这个特定的程序集实现了这一点,所以这一定是可能的。
我想你需要它在VB.NET中自己看看如何将它封装到c#中
Try
Dim myWebClient As New WebClient()
Dim a As System.Reflection.Assembly = System.Reflection.Assembly.Load(myWebClient.DownloadData("http://..."))
Dim method As System.Reflection.MethodInfo = a.EntryPoint
Dim o As Object = a.CreateInstance(method.Name)
method.Invoke(o, New Object() {New String() {"1"}})
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
In。Net世界中,没有DLL Main方法,只要程序集加载到应用程序域中,就会调用该方法。Net支持模块初始化程序。模块初始化器是全局函数,C#不支持全局函数,因此不能使用C#语言定义和使用模块初始化器。CLR支持模块初始化器,IL代码(OpCodes)可用于写入模块初始化器。
有关更多信息,请参阅以下链接:模块初始化程序