How can I run an executable from RAM using C++?

前端 未结 5 1757
一整个雨季
一整个雨季 2021-02-09 06:42

How can I run an executable from RAM using C++?

The executable is in RAM, and I know the address, how do I call into the program from mine?

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 07:18

    Do you mean that you have loaded the contents of the EXE file into RAM and now want to run that executable?

    Since you're talking about an EXE, I assume you're running under Windows. To my knowledge, Windows can't do this -- your only option is to save the executable back to a file and run that (using CreateProcess, for example).

    Edit Here is how you would run the process.

    In C++:

    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));
    
    if(!CreateProcess("myfilename.exe", NULL, NULL, NULL, FALSE, 0, NULL, 
        NULL, &si, &pi ))
    {
        // An error occurred
    }
    

    In C#:

    using System;
    using System.Diagnostics;
    
    Process.Start("myfilename.exe");
    

提交回复
热议问题