从字节数组运行程序 [英] Run Program from byte array

查看:123
本文介绍了从字节数组运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有存储在字节数组的程序。

I have a program stored in byte array.

是否有可能运行它里面的C#?

Is it possible to run it inside C#?

推荐答案

是的。 <一href=\"http://stackoverflow.com/questions/959087/is-it-possible-to-execute-an-x86-assembly-sequence-from-within-c/959144#959144\">This答案表明您可以直接执行字节数组的内容。基本上,你可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/aa366887%28VS.85%29.aspx\"><$c$c>VirtualAlloc用一个已知的地址在堆中分配可执行区域(A <一个href=\"http://msdn.microsoft.com/en-us/library/system.intptr%28VS.71%29.aspx\"><$c$c>IntPtr).然后,你的字节数组到该地址与 Marshal.Copy 。您的指针转换为委托与<一个href=\"http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getdelegateforfunctionpointer.aspx\"><$c$c>GetDelegateForFunctionPointer,终于把它作为一个正常的委托。

Yes. This answer shows you can directly execute the contents of a byte array. Basically, you use VirtualAlloc to allocate an executable region on the heap with a known address (a IntPtr). You then copy your byte array to that address with Marshal.Copy. You convert the pointer to a delegate with GetDelegateForFunctionPointer, and finally call it as a normal delegate.

这篇关于从字节数组运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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