Forum > General

How to run a EXE (Win32 any) starting from memory

<< < (2/4) > >>

LazaruX:
i see, now, well a bit similar to Resources then maybe....

Laksen:
It's probably easiest to store it in a temporary file and then delete it when it's done executing with TProcess

JuhaManninen:

--- Quote from: Eric.Developer on June 26, 2010, 12:55:49 pm ---anyone, any tips (EXE starting memory)?
Those who understand C + + or assembly and can convert to Pascal, I can search by codes

--- End quote ---

You got some answers already. Like:
- You can't execute code from a data segment in a modern processor.
- You can use a compressor upx if the binary size is the problem.
- You can create a temporary executable file and run it.

What do you actually want to do? It sounds you want some "normal" operation done in a tricky way.
Let me guess: You are making some kind of plugin system where code modules are loaded dynamically when needed. Those modules can be added and changed without recompiling your program.
Ok, dynamic libraries are meant to solve your problem! They are even multi-platform (.dll in windows, .so in *nix systems). There are functions to load them dynamically on-demand from your program (Loadlibrary func). You can still store those binary libraries into a DB if you want, and then save them to disk only when needed.

I have not made dynamic libraries myself using FPC but it should be possible.

Juha

Laksen:
As far as I can tell you won't get around having a stub executable somewhere, atleast to create the process itself. You cannot create an empty process and load data into it yourself

You can either load the code and data from the executable yourself by parsing the PE-COFF structure, and then have it execute in a thread in the same process space of the calling process, or the stub process. Probably about 1k lines of code

Or you can just save it to a temporary file(GetTempFilename, TProcess, etc). 10 lines of code :)

Is there any reason you won't use a temporary file?

JuhaManninen:

--- Quote from: Eric.Developer on June 27, 2010, 05:08:08 am ---As described in the topic, do not want to save to disk (temporary, etc.).
If someone has some information in context, please inform us here
I've seen on the Internet, DLLs starting memory (codes pascal), EXE starting the memory (codes C ++), let's wait for a "positive" response

--- End quote ---

You still don't tell us why you can't use a temporary file. Let's guess some more:
... you are making a JIT compiler ... no, even a JIT compiler could save the executable to a file.
Executing data, Windows only ... the only remaining alternative is a virus or other malicious program. No wonder you didn't want to mention it!

This Lazarus / Pascal forum may not be the best place to ask such info. I don't know how to code viruses but I think it requires some advanced assembly programming.
A google search gave me a link to a Win API function related to the issue:
http://msdn.microsoft.com/en-us/library/aa366899.aspx

Good luck with your virus. I use Linux myself and I am not likely to be hit by it.

Juha

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version