Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read exe file in memory and execute it

Tags:

java

c++

windows

Is it possible using Windows to read a file into memory (keep data in byte array), delete original file from filesystem and execute it from memory?


EDIT

My goals is to protect my java code from reverse enginering.

I wrote a launcher in C++ that take my encrypted jar file, decrypt it and launch it. The little problem is that i have to write my decrypted jar file somewhere in the filesystem, so it can be easily captured and decompiled... there is no way to prevent this?

like image 551
blow Avatar asked Feb 22 '23 12:02

blow


1 Answers

No, it's not possible to do like that. There's no system call that says "take this chunk of my memory and use just that part of it as the image of a new process".

You can load code into memory and jump to it within the current process, but that's an ugly thing to do because you have to handle all of the relocations.

With regards to the Java specific part:

You can embed a Java interpreter within your C++ executable. You can write your own class loader for Java (through the C++ interface to the JVM) that will load classes from your encrypted Jar file. That way you could avoid ever writing the unencrypted Jar file to disk. It will of course be visible in memory to anyone with a debugger...

like image 89
Flexo Avatar answered Mar 02 '23 19:03

Flexo