从字节数组运行程序 [英] Run Program from byte array
本文介绍了从字节数组运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个存储在字节数组中的程序.
I have a program stored in byte array.
是否可以在 C# 中运行它?
Is it possible to run it inside C#?
推荐答案
是的.这个答案 显示您可以直接执行字节数组的内容.基本上,您使用 VirtualAlloc
在堆上分配一个具有已知地址的可执行区域(a IntPtr
).然后使用 Marshal.Copy将字节数组复制到该地址代码>
.您可以使用 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屋!
查看全文