Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to execute a raw EXE stored in a byte array, without writing it to disk. Like putting it in memory and executing it in the same way as the EXE on disk would be double clicked
Posted
Comments
gggustafson 24-Jul-14 12:49pm    
Are you writing the machine code or c opying it from some place?
mehdimughal 24-Jul-14 12:56pm    
Copying it
mehdimughal 24-Jul-14 12:58pm    
e.g I read an executable into byte array. Now i want to execute it from memory. Without making new exe on disk
gggustafson 24-Jul-14 13:14pm    
How familiar are you with the format of an executable file? Do you have control over the contents of the executable that you copied into the byte array?
Sergey Alexandrovich Kryukov 24-Jul-14 12:59pm    
It means that you need to write a loaded, but you have no access to the kernel mode, except for a kernel-mode driver. It's possible that you will have to write your own "disk" driver to let the application load the "file" from memory.
—SA

Please see my comment to the question. These difficulties would make the whole problem impractical to address. I would create a temporary file in a system "temp" directory, write a file and loaded the PE image.

Sounds non-professional? Then look at Microsoft. In their implementation of .NET CodeDOM, they have an option to compile some code into memory and load the assembly without using some PE file. And look how it is implemented: the executable module is created by a compiler in a temporary directory and then this file is loaded into the calling process. Why can't you allow yourself to do something like that?

—SA
 
Share this answer
 
Comments
mehdimughal 24-Jul-14 13:25pm    
writing it back to temp means making an executable? that's what i can't afford to do. I want to keep the code away from disk.
Sergey Alexandrovich Kryukov 24-Jul-14 21:47pm    
I know. I just say it's a realistic way, and loading the file from memory by yourself is not. Maybe there is a way I don't know...
—SA
See CODYQX4's answer in [C#] Run non .NET exe from memory [^]. Make sure you include credit.

Hope that helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900