从运行字节数组的程序,而无需创建一个临时文件。 C# [英] Run a program from an array of bytes without creating a temporary file . c#

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

问题描述

我有一个包含报告和访问服务器上的文件(S)存储在IIS服务器(MSSQL)许多.exe文件。 (这些文件将改变周日)

I have many .exe files stored on IIS server (MSSQL) that contain reports and access to the file(s) on the servers . (These files will be change on Sundays .)

连接到SQL Server,并选择一个.exe文件后,我下载(选择SQL),现在我有一个分配给一个变​​量的字节数组。
我不能在一个未知的目录中创建,如temp.exe临时文件,因为我知道有很多方法来了解一个新创建的文件目录,并...

After connecting to the SQL Server and choosing an .exe file , I am Downloading(Select in SQL) , Now I have an array of bytes that assigned to a variable . I cant creating a temporary file like "temp.exe" in an unknown directory because I know there are many ways to understand a new created file directory and ...

这是不安全的,因为我的用户是专业,如果其中一人知道这些方式...

It is not secure because my users are professional and if one of them know these ways ...

所以,我想知道是否有可能运行一个字节数组.exe文件(默认为从Windows资源管理器中运行),而无需创建一个temporay文件?!

So , I want know is it possible to run an .exe file from an array of bytes (as default as running from "Windows Explorer") without creating a temporay file ?!

TNX
更新:.exe的文件是.NET和经理将被上传新文件或更改文件

tnx update : Exe files are .net and Manager will be upload new files or change files .

推荐答案

但是要注意,您的任何额外的安全性的看法是虚幻的。如果用户访问本机读取文件,他们也将能够读取您的进程的内存。

Be warned that your belief of any extra security is illusory. If the user has access to the machine to read files, they will also be able to read the memory of your process.

不过,要回答你的问题,你问做的是非常简单和描述如下:加载一个EXE文件,并从内存运行它。

However, to answer your question, what you are asking to do is simple enough and described here: Load an EXE File and Run It from Memory.

在本质上,你做到以下几点:

In essence you do the following:


  1. 通过你的字节数组的Assembly.Load 以创建一个新的大会

  2. 阅读使用入口点属性,该属性集的入口点。

  3. 使用 Assembly.CreateInstance 创建一个实例,并调用该方法在该实例上。

  1. Pass your byte array to Assembly.Load to create a new Assembly.
  2. Read the entry point of that assembly using the EntryPoint property.
  3. Create an instance using Assembly.CreateInstance, and invoke the method on that instance.

在code是这样的:

Assembly a = Assembly.Load(bytes);
MethodInfo method = a.EntryPoint;
if (method != null)
    method.Invoke(a.CreateInstance(method.Name), null);

这篇关于从运行字节数组的程序,而无需创建一个临时文件。 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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