C# Sandbox
ЗАДАЧА
загрузите приложение с любого места на компьютере в массив байтов (byte[])
using (FileStream fs = new FileStream(path, FileMode.Open))
using (BinaryReader br = new BinaryReader(fs))
var bin = br.ReadBytes(Convert.ToInt32(fs.Length));
Укажите путь к библиотекам
создайте домен AppDomain.CreateDomain
установить события nameDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve; для загрузки библиотек
загрузите массив байтов nameDomain.Load(bytes)
и запустите приложение Invoke метод Main
Вот код для примера
public static void Run()
{
var path = Path.Combine(assemblyDependencyPath, "WpfApp1.exe");
if (File.Exists(path))
{
// read the bytes from the application exe file
using (FileStream fs = new FileStream(path, FileMode.Open))
using (BinaryReader br = new BinaryReader(fs))
{
var bin = br.ReadBytes(Convert.ToInt32(fs.Length));
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
// load the bytes into Assembly
var a = Assembly.Load(bin);
// search for the Entry Point
// *** Indirectly call the remote interface
var result = a.EntryPoint.Invoke("ExecuteDynamicCode", null);// this is the object to return
}
}
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs argss)
{
var domain = sender as AppDomain;
if (argss.Name.Contains(".resources"))
return null;
var di = new DirectoryInfo(assemblyDependencyPath);
var module = di.GetFiles().FirstOrDefault(i => i.Name == argss.Name + ".dll");
if (module != null)
{
return domain.Load(module.FullName);
}
return null;
}
Нужно его доработать или модифицировать
-
224 2 0 Готов сделать. пишите в лс, обсудим все более детально.
Skype: olehspidey
Telegram: @olehspidey
Current freelance projects in the category C#
Improvement in the existing version of 1C retail block for the distribution center (DC)In general, I will explain what kind of database we have - There is a main server where there is a retail database (where all receipts are recorded) - a UTP database - where all sales are transferred - it calculates the markup and stock balances - small databases of retail… C & C++, C# ∙ 3 days 18 hours back ∙ 6 proposals |
It is necessary to migrate the current working program from FoxPro to C#.Hello everyone! We have a program in FoxPro (it has several modules, it's an accounting program), we have the source code of the program, and if necessary, we can consult with people who support the current program. What needs to be done: 1. Analyze how everything works,… C#, Desktop Apps ∙ 6 days 9 hours back ∙ 18 proposals |
Junior C#We are looking for a talented and ambitious Junior C# developer who is eager for professional growth and new challenges. Your future tasks: - Development and support of backend solutions with frontend (Telegram bot); - Automation of routine processes in Android development,… C# ∙ 6 days 23 hours back ∙ 8 proposals |