在Node.js中运行Buffer(.exe)而不写入文件。

huangapple go评论64阅读模式
英文:

Run Buffer(.exe) without writing files in Nodejs

问题

假设我在终端中创建了一个使用C语言编写的控制台应用程序,它会喊出"Hello world!"。
这个程序叫做hello.exe
我将hello.exe上传到静态服务器。

现在,我可以通过在Chrome中输入以下地址来下载该文件。
http://localhost:8080/hello.exe

或者,我可以使用Nodejs中的http方法获取一个Blob对象。
是否有一种方法可以立即运行获取的Blob对象,而不必创建一个文件?并获取字符串Hello world!

未找到类似的主题。
我需要创建并立即运行文件然后将其删除吗?
我想要的是运行文件,而不让它们保留在我的电脑上。

英文:

Suppose I had a console app in the terminal I created using C language, shouting "Hello world!"
The program is called hello.exe.
I upload hello.exe to static server.

Now I can download the file by typing the following address in the chrome.
http://localhost:8080/hello.exe

Or I can get a Blob object using the http method in Nodejs.
Is there a way to run this obtained Blob object right away without making a file? And get string Hello world!

No similar topics were found.
Do I need to create and run the file and erase it right away?
I want is for the files to run and not remain on my PC.

答案1

得分: 1

我不知道任何不将.exe文件放在磁盘上就能运行它的方法。您基本上需要编写自己的.exe加载器,它可以从内存中运行而不是从磁盘上运行,这需要相当大的工作量。

请记住,一个客户端如果自动运行从URL获取的可执行文件,比如http://somedomain.com/hello.exe,而不需要用户干预,那么这个客户端可能会非常危险,因为恶意的Web服务器可能会发送任意的可执行文件,造成各种危害(病毒、勒索软件等)。

我需要创建并运行文件,然后立即擦除吗?

是的,在程序运行完成后擦除它。

我想要的是文件运行后不保留在我的电脑上。

您只需在文件运行后的某个时刻清理它。如果您有一个程序化的客户端,将文件放在应用程序级别的临时目录中,然后您的应用程序可以定期清理,这应该不是什么大问题。如果这是从浏览器中进行的操作,那么用户会控制文件存储在磁盘上的位置,用户还可以控制何时删除它 - 您无法从网页内部自行管理这些操作。

或者我可以在Node.js中使用HTTP方法获取Blob对象。

您可以下载一个二进制文件。不太确定您的具体问题是什么。

英文:

I'm not aware of any way to run an .exe file without first putting it on disk. You would essentially need to write your own exe loader that worked from memory instead of disk and that would be no small effort.

Keep in mind that a client that just automatically runs some executable it gets from a URL like http://somedomain.com/hello.exe without any user intervention could be a very dangerous client as rogue web servers could send it any arbitrary executable that did all sorts of harm (viruses, ransom-ware, etc...).

> Do I need to create and run the file and erase it right away?

Yes, erase it after the program is done running.

> I want is for the files to run and not remain on my PC.

You will just have to clean it up at some point after it has run. If you have a programmatic client, it should be no big deal to put the file in an application-level temporary directory that your app can regular clean up. If this is from a browser, then he user controls where the file goes on disk and the user controls when it gets deleted - you can't manage that yourself from within a webpage.

> Or I can get a Blob object using the http method in Nodejs.

You can download a binary. Not sure exactly what you're asking here.

huangapple
  • 本文由 发表于 2020年1月6日 15:34:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608268.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定