1

I like to attach a dll to a game to add more features.

The DLL is 95% done, the problem is find the best and easy way to load this dll from the Game.

My idea is use this technique:

dinput_ori.dll  (old dll).
dinput.dll      (my dll that point to dinput_ori.dll)

I don't need to access to any member of original DLL, but only load my dll.

I searching for a generic dll source code that do this:

bool WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{

    std::string DLLFileOri = "dinput_ori.dll";

    switch (dwReason)
    {
    case DLL_PROCESS_ATTACH:
        // Load dll

        LoadOriDll(DLLFileOri);

        MsgBox("This DLL was loaded.");

        break;

    case DLL_PROCESS_DETACH:

        // Close the DLL
        
        UnloadOriDll(DLLFileOri);

        break;
    }

    return true;
}

in this case the name of my DLL is "dinput.dll".

There is a generic source code that do this ?

Thanks !

6
  • 1
    This won't work if the original dll export anything. You need to replicate all that exported functions and forward calls to original dll.
    – morsisko
    Oct 13, 2020 at 11:18
  • thank you morsisko ! there is a external tool that automatically read all export to original DLL and you can do a copy and paste to c++ code ? if no, there is another way to attach the DLL without modify the exe ? Oct 13, 2020 at 13:48
  • Unfortunately it's not that easy. If it's not known dll without symbols, it will be hard to deduce parameters of each function. However as dinput is rather common dll, the function signatures might be already public.
    – morsisko
    Oct 13, 2020 at 14:21
  • Thank you again morsisko, Can you please suggest me a good "DLL injector" tool that don't make my exe detected as virus ? Oct 13, 2020 at 15:54
  • You can make your own injection, it is very easy using LoadLibrary and CreateRemoteThread
    – morsisko
    Oct 13, 2020 at 16:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.