Read exe file in memory and execute it

Is it possible to use Windows to read a file in memory (store data in an array of bytes), delete the original file from the file system and execute it from memory?


EDIT

My goals are to protect my Java code from being translated back.

I wrote a C ++ launcher that picks up my encrypted jar file, decrypts it, and runs it. The little problem is that I have to write my decrypted jar file somewhere on the file system, so it can be easily grabbed and decompiled ... is there no way to prevent this?

+4
source share
1 answer

No, that doesn't work. There is no system call that says: "Take this piece of my memory and use this particular part of it as an image of a new process."

You can load the code into memory and go to it in the current process, but this is an ugly thing, because you need to handle all movements.

As for the specific part of Java:

You can embed a Java interpreter in your C ++ executable . You can write your own class loader for Java (via the C ++ interface for the JVM) that will load the classes from your encrypted Jar file. That way, you could avoid writing an unencrypted Jar file to disk. This, of course, will be visible in memory to everyone who has a debugger ...

+8
source

Source: https://habr.com/ru/post/1379894/


All Articles