Add class to unload assembly
This commit is contained in:
parent
a1b2ddb020
commit
54393a3267
@ -191,6 +191,7 @@
|
||||
<Compile Include="Helper\IconInjector.cs" />
|
||||
<Compile Include="Helper\ListViewColumnSorter.cs" />
|
||||
<Compile Include="Helper\Methods.cs" />
|
||||
<Compile Include="Helper\ReferenceLoader.cs" />
|
||||
<Compile Include="MessagePack\BytesTools.cs" />
|
||||
<Compile Include="MessagePack\MsgPack.cs" />
|
||||
<Compile Include="MessagePack\MsgPackType.cs" />
|
||||
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using AsyncRAT_Sharp.Helper;
|
||||
|
||||
namespace AsyncRAT_Sharp
|
||||
{
|
||||
@ -58,7 +59,7 @@ namespace AsyncRAT_Sharp
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly.LoadFile(O.FileName);
|
||||
new ReferenceLoader().AppDomainSetup(O.FileName);
|
||||
isOK = true;
|
||||
}
|
||||
catch
|
||||
|
48
AsyncRAT-C#/AsyncRAT-Sharp/Helper/ReferenceLoader.cs
Normal file
48
AsyncRAT-C#/AsyncRAT-Sharp/Helper/ReferenceLoader.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsyncRAT_Sharp.Helper
|
||||
{
|
||||
public class ReferenceLoader : MarshalByRefObject
|
||||
{
|
||||
public string[] LoadReferences(string assemblyPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath);
|
||||
var paths = assembly.GetReferencedAssemblies().Select(x => x.FullName).ToArray();
|
||||
return paths;
|
||||
}
|
||||
catch { return null; }
|
||||
}
|
||||
|
||||
public void AppDomainSetup(string assemblyPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = new AppDomainSetup
|
||||
{
|
||||
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
|
||||
};
|
||||
var childDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, settings);
|
||||
|
||||
var handle = Activator.CreateInstance(childDomain,
|
||||
typeof(ReferenceLoader).Assembly.FullName,
|
||||
typeof(ReferenceLoader).FullName,
|
||||
false, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, CultureInfo.CurrentCulture, new object[0]);
|
||||
|
||||
var loader = (ReferenceLoader)handle.Unwrap();
|
||||
//This operation is executed in the new AppDomain
|
||||
var paths = loader.LoadReferences(assemblyPath);
|
||||
AppDomain.Unload(childDomain);
|
||||
return;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user