Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Requesting MSVCP110D.dll even though staticly linked

I created a library injection method on my machine in C++ which works very well when I try to inject a specific dll into a process. However, when I run the program on my friend's computer (where Visual Studio's redistributables are not installed), I am warned that I need MSVCR, etc ... (the redistributables).

So I compiled in the release mode with the following setting in Visual Studio 2012 : Runtime Library : Multi-threaded /MT. Now when I run it on my friend's machine I am warned that I need only the library MSVCP110D.dll ( weird, asking for the debug version) (there is no antivirus, and UAC is disabled ). I copied the requested library manually in the release path and still wont work.

This is the injection code i made :

int inject(string lpLibraryPath)
{
    HANDLE      hProc;
    LPVOID      paramAddr;
    HINSTANCE   hDll;

    hDll = LoadLibrary(L"KERNEL32");

    fpLoadLibrary LoadLibraryAddr = (fpLoadLibrary)GetProcAddress(hDll, "LoadLibraryA");

    hProc = OpenProcess(PROCESS_ALL_ACCESS, false, id);

    paramAddr = VirtualAllocEx(hProc, 0, strlen(lpLibraryPath.c_str()) + 1, MEM_COMMIT, PAGE_READWRITE);

    if(WriteProcessMemory(hProc, paramAddr, lpLibraryPath.c_str(), strlen(lpLibraryPath.c_str()) + 1, NULL) == NULL)
    {
        return 0;
    }

    CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, paramAddr, 0, 0);

    CloseHandle(hProc);

    return 1;   
}
};

I found some references on stackoverflow but they were of no help . like msvcp110.dll, how do I get around it? or Fixing the "MSVCP110D.dll is missing from your computer" issue

like image 585
Reznicencu Bogdan Avatar asked Jan 04 '17 18:01

Reznicencu Bogdan


2 Answers

weird , asking for the debug version

Tells you what you did wrong, you accidentally copied the Debug build of the DLL instead of the Release build. Since you only changed the setting for the Release build, it still requires msvcp110d.dll. It is in general wise to change such a setting for all configurations and all platforms. Tedious, so it often gets skipped.

I copied the requested library manually in the release path and still wont work

Right, that cannot work since you injected the DLL. A different process. So when it is loaded, the install directory for the game is searched for the file, not the directory where your utility is installed.

like image 80
Hans Passant Avatar answered Oct 21 '22 11:10

Hans Passant


Your friend needs the Visual-C++ Redistributables in order to properly run your injector, and for the DLL to be loaded. However

After Injection, the dll is trying to LoadLibrary (if GetModuleHandle fails) the CRT dlls. There are a lot of them!

You have some options:

  1. Include the required DLLs inside your Injector (Resource, Bytecode, etc) and write them to the directory where the game is run from

  2. Download the DLLs from a server on the internet and put them in the directory where the game is run from

  3. Statically linking the CRT (to the injected DLL) also works, but you have to make sure you get all dependencies too!

The reason you need to have the required DLLs in the folder where the game is run from is because the LoadLibrary call will be made explicitly from the Game.exe itself, and it will only be looking for the DLLs in that directory.

You can choose to attach a Runtime-debugger such as WinDbg to the injected DLL, set a breakpoint at the DLL entry-point (wherever it is for you). Then check what sort of LoadLibrary/GetModuleHandle calls are made when your DLL is loaded, this will give you a hint as to what DLLs are required!

The problem here is because your friend doesn't have the Visual-C++ Redistributables installed, many of the CRT files also have dependencies of their own! Your injector will have to have a Win-Installer which in turn installs the redistributables MSI from the Microsoft website, a technique which many modern games (at install time) adapted.

like image 39
Droopy Avatar answered Oct 21 '22 10:10

Droopy