PDA

Click to See Complete Forum and Search --> : run exe in memory


Tygur
Sep 13th, 2002, 06:14 PM
Is there any way I could get the contents of a regular windows exe file and put it into a byte array, then run it? It doesn't have to run in its own process. I just sorta wanna run the code in it...

Getting the contents into the array is easy. It's running it that's giving me trouble.

Before the why-would-you-do-that questions come up, I'd like to mention that the final code will actually be more complicated than that, and that is only part of the story.

ChuckB
Sep 15th, 2002, 11:05 PM
Hi
Don't know C++ answer. I have used DOS debug to write some assembler in which you punch a program into a memory segment and run it using all sorts of interrupts.

I then wrote a mouse function in QBASIC in which I had to load assembly code (in bytes) into a variable and then had calls which executed this code.

So, you might search for some QBASIC or Debug stuff to get some answers...or even ask on this Assembly Language forum.

Regards,
ChuckB

CornedBee
Sep 16th, 2002, 09:12 AM
The tricky part about running it is that all addresses in the exe assume that the exe is loaded at the address 0x00040000. If this is not the case the loader runs over it and replaces all addresses with correct ones (so if the exe references 0x000400A0 but is loaded at 0x00050000 the loader will make this address 0x000500A0).

Since you app is probably loaded at 0x00040000 there is no chance that the other exe ca be loaded at 0x00040000 too. So you have to emulate the loader and replace addresses.

plenderj
Sep 16th, 2002, 11:34 AM
Search on planetsourcecode, under vb for code on using ASM from inside VB.
Its an image fading example.

Anyway, he's loading executable data into memory and causing the computer to execute it