使用“包装器”或“exe代理”在不同的exe上下文中运行可执行文件

时间:2017-10-09 20:26:05

标签: c# .net dll .net-assembly code-injection

我试过这个

byte[] bytes = File.ReadAllBytes("Program.exe");
Assembly assembly = Assembly.Load(bytes);
assembly.EntryPoint.Invoke(null, new object[0]);

编译好,但是当我运行它时,它说

  

“程序不重新......”

在imeproxy.exe的上下文中,在没有管理员的情况下运行dll是什么尝试todo 也不知何故,如果这可能是某种功能,那将是伟大的。我将代码更改为Visual c ++

我使用以下

using System;
using System.IO;
using System.Reflection;

namespace exeproxy
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: exeproxy <exe>");
                Environment.Exit(1);
            }
            string exe = args['0'];
            byte[] bytes = File.ReadAllBytes(exe);
            Assembly assembly = Assembly.Load(bytes);
            assembly.EntryPoint.Invoke(null, new object[] { new string[0] });
        }
    }
}

有用的链接 http://www.c-sharpcorner.com/UploadFile/ajyadav123/executing-assembly-code-in-C-Sharp/

使用C ++或VC ++查看asm()的链接可能更有意义。 您可以使用Calc.exe来测试它是否有效;它不仅仅是运行.net程序。

1 个答案:

答案 0 :(得分:0)

您应该更改将参数传递给EntryPoint的方式。要调用的第二个参数是一个对象数组,它被解析为Main的参数。但是Main采用了一系列字符串。所以你的电话应该是这样的:

assembly.EntryPoint.Invoke(null, new object[] { new string[0] });

它适用于打印到控制台的简单Program.exe。如果程序更复杂,可能会有更多问题需要处理。