首页 > 解决方案 > Run binary exe in python script without writing it to a disk

问题描述

Now even tough this question kinda already exists (Run in-memory binary executable from bytes object)
I am going to create this question as that question has been dead for years

How do i run exe bytes directly thru python
So basically this:

Bytes = bytesFile.read()   
"Execute Bytes as exe in memory"

In theory, this should be possible
Maybe by later on hard coding it in with a hex editor somehow (would have to code in binary and holy fuck I would prefer not)
Or by running it into Pyinstaller or some alternative
Or maybe creating a special sort of thread that doesn't run python but runs applications (in bytes form)

Just post your crazy ideas in the comments
But please please please don't be like: "why?, why would you want that?, Your best option is just to create it in a temporary directory"
Because TRUST ME I KNOW I CAN CREATE A TEMPORARY DIRECTORY. I am creating this question because there is no alternative for me
If you found a matrix way out then sure post about it
But please respect my original question and don't find some way out of this, just try to help me

A few things to note:
Exe as in windows 10 64 bit app executable
I am not creating a virus! I'm making a PERSONAL merging application. But I won't make the end result public, and I won't use it to make anything malicious, just some fun game engine projects
I am using windows 10 as stated before
And I am using python 3.10

Edit:
I saw a comment from @Mihai that told me about ramDisk
The only problem is: that would take too much memory!
As I would have to resave the bytes (that are already in the main program) into an empty executable and run that, but then (if I take an example of the bytes being 1 gigabyte), this would happen:
1 gigabyte on disk (the program and the bytes as a variable in that program)
1 gigabyte on memory (to save the bytes as an executable on a ramdisk)
1 more gigabyte on memory (when the executable (of 1 gigabyte) is ren it will take 1 gigabyte of memory space)
Any fix for this?

标签: pythonwindowswindows-10exe

解决方案


推荐阅读