execute from memory
BlitzMax Forums/BlitzMax Programming/execute from memory
| ||
Hi Is it possible to execute a program directly from a bank in memory? Ie. if i createbank(size of binary file) and read contents of the binary file into the bank, how can i then execute the binary file directly from the bank? |
| ||
The processor on most computer these days supports DEP (data execution prevention) , which is enabled by default under Windows and would prevent such a thing from running. It's a good thing, since that is how a lot of viruses would otherwise manage to compromise your computer if they get on there through some buffer overflow. |
| ||
If you have the file, why don't you execute it directly? I mean, if you want to execute a file, there's a way to do it. If you're trying to make something specific, maybe a bit more of information would help us helping you. |
| ||
I see... But I would like to know how anyway, I'm not into making viruses, but I support the other side... This would help me in making an elf encrypter.... anyone? |
| ||
Can anyone contribute to this? Ram streams? |
| ||
Surely there's a programmatic way to do this, for like when apps run plugins? |
| ||
At the very least could you not save it to disk, then run it from there? |
| ||
executing from memory is not difficult. just write your code to memory and set the function pointer. You just have to be careful. Check the post in my sig for an example. |
| ||
I know this topic is old, but I'm trying to achieve this. I've incbinned an encrypted elf file, I then decrypt it to memory.... Does anyone know how to execute it from memory? |
| ||
...Did you learn anything from GW's "interpreter"? Because that's exactly what that code does. Other things you might want to take a look at include TCC and GNU lightning, both of which build and execute code directly in memory. There are BlitzMax wrappers for both floating around somewhere. |
| ||
Yes i learned alot there. Does anyone know at which offset the start address of an elf is? Oh and I didn't find the wrapper for gnu lightning |
| ||
Does anyone know at which offset the start address of an elf is? http://wiki.osdev.org/ELF |
| ||
There is a world of difference between just executing some code on the fly and executing a proper exe file on the fly.. Im not even sure if that is possible in a >0 ring environment since you (afaik) must be able to set up memory mapping and stuff yourself. Although I havent tried it so I might be wrong :) Id look around for the source/documentation on how other file compressors or encrypters do it. |
| ||
Yeah I know you are right, there's extractions of elements from the elf file, relocating the data (i remember relocating from the old 6510 days), and possibly flag the memory as executeable with write permission. The relocation is important, as jmp and such instructions has to be relocated properly. Wish i had some of my old code from the 64 and maybe a cody of turbo assembler to have a look at it. http://docs.oracle.com/cd/E19082-01/819-0690/chapter6-62988/index.html |
| ||
Well, the operating system would have to load the executable to ram before doing any funky stuff too, so I guess its a question of if that functionality is exposed to the users or not. For unix stuff I wouldnt be suprised if it is :) I tried a bit of googling but couldnt find anything useful though. |