hello i have some c program that use from those in my c# program. i dont want send those c exe to client. that mean i dont want user can see those exe. i want to load those byte to memory and run its from memory.
how i can do that.
thanks a lot.
hello i have some c program that use from those in my c# program. i dont want send those c exe to client. that mean i dont want user can see those exe. i want to load those byte to memory and run its from memory.
how i can do that.
thanks a lot.
If the program is unmanaged code, which a C program is, you cannot launch it directly from within .Net memory. What you can do is pack it as a resource, stream it to disk (a temp folder) and then start it with the System.Diagnostics.Process class. But it would show up in the process list.
But I agree with the comment from @tdammers, why can't you just include it alongside your program? Why do you have to hide it?
If it had been managed, you could get hold of the embedded resource (exe file), get it into a byte array and load it with Assembly.Load.
If your C program was a dll, you could embed as a resource, stream to disk and use p/invoke to execute it.
This is not possible, a hard requirement for Windows is that an EXE is started and loaded from a file on disk. This is core to the way Windows is designed, associated with memory mapped files.
You will have to ship the unmanaged EXE along with your C# program. Doing something nasty like extracting the EXE from your resources at runtime is not going to be appreciated by either your customer, the virus scanner she uses nor UAC. You can run it silently by using the ProcessStartInfo.CreateNoWindow property.
EXE program can't be run from memory - Windows requires it to be stored on the disk. So you need to save it somewhere - either on regular disk or possibly on the virtual disk, such as the one created by our CallbackDisk or SolFS products.
However, as comments said, your request and your actions would look suspicious to the end user.
Doing what you want is the key to create a virus. Windows doesn't want you to
I'm in agreement with all the people telling you this is a bad idea. But it's far from impossible.
The only thing standing between you and running code that you have in some buffer in memory is DEP, and a call to VirtualProtectEx will fix that (if you're loading the code in-process rather than into a new process, VirtualProtect (not -Ex) will be sufficient). Do make sure the buffer is pinned and not subject to being moved by the garbage collector though (using a native allocator is probably a good idea).