加载一个EXE文件,并从内存中运行它 [英] Load an EXE file and run it from memory

查看:509
本文介绍了加载一个EXE文件,并从内存中运行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行从内存中的可执行文件,如文章。我可以运行任何.NET /管理的前男友很容易。但是,我不能运行可执行文件,如 NOTEPAD.EXE 的calc.exe 。我怎样才能得到它,所以我也可以运行非托管的前男友?

I'm trying to run an executable from memory such as outlined in this article. I can run any .net/managed exes quite easily. But I cannot run executables such as notepad.exe or calc.exe. How can I get it so I can also run unmanaged exes?

推荐答案

在从内存中,图书馆和CLR本身运行.NET可执行文件的情况下,都在做很多繁重的你。对于像NOTEPAD.EXE和的calc.exe机可执行程序,你必须做很多事情来得到它的发生。基本上,你必须像在Windows加载器。

In the case of running .NET executables from memory, the libraries and CLR itself are doing a lot of heavy lifting for you. For native executables like notepad.exe and calc.exe, you'll have to do a lot of manual work to get it to happen. Basically, you have to act like the Windows loader.

有可能是警告的页面在这里,但对此进行了深入的文章有你需要加载一个PE到内存中,并做了正确的重订基期和调整信息的步骤。然后,你应该能够找到切入点(如文章),然后运行它。

There's probably pages of caveats here, but this in-depth article has the steps you need to load a PE into memory and do the correct rebasing and fixups. Then, you should be able to find the entry point (like in the article) and run it.

如果你真的只是想NOTEPAD.EXE运行和的calc.exe,最简单的方法,当然,是使用的 的Process.Start 并运行它们从磁盘。否则,如果您有嵌入在你的进程资源的可执行文件,那么下一个最简单的方法是只写内容到磁盘在一个临时位置(见<一href="http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename.aspx"><$c$c>Path.GetTempFileName)然后从那里执行它。

If you're really just wanting to run notepad.exe and calc.exe, the easiest way, of course, would be to use Process.Start and run them off disk. Otherwise, if you have an executable embedded as a resource in your process, then the next easiest way would be to just write the contents out to disk in a temporary location (see Path.GetTempFileName) and then execute it from there.

这篇关于加载一个EXE文件,并从内存中运行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆