Anyone knows anything about running executable from memory in OSX? anything like this:

char *exeFile[size];
loadFromFile(exeFile, "/path/to/data");
execute(exeFile);

I want do that for security reasons. for example It is possible to encrypt exe and decrypt it before launch.

有帮助吗?

解决方案

Well, yes, you can do it but its complex. I don't have access to working code right now but I do know others that are/have used it. The key is "NSCreateObjectFileImageFromMemory()", which is deprecated, but that said a few big apps like Skype reputed use it so its probably not going to disappear anytime soon (YMMV).

You have to allocate a memory buffer that's a multiple of the pagesize with vm_allocate. Copy the mach-o executable of the same architecture as the current process to there. Call NSCreateObjectFileImageFromMemory() which returns an object image. Then call successively NSLinkModule, NSLookupSymbolInModule and NSAddressOfSymbol. That last one gets you an actual function pointer to call.

This should give you most of what you need to know, and if you search you may find code that does it too. Good luck!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top