-1

I found this code for injecting dll files and call functions from them. I got an exe and the source code. The exe is working but when i try to compile the source code i get this error:

LoadDll.cpp: In Funktion »bool ExecuteRemoteThread(HANDLE, BOOL, BOOL, wchar_t*, wchar_t*)«:
LoadDll.cpp:313:62: Fehler: ungültige Umwandlung von »DWORD (__attribute__((__stdcall__)) *)(RemoteThreadBlock*) {aka long unsigned int (__attribute__((__stdcall__)) *)(RemoteThreadBlock*)}« in »LPCVOID {aka const void*}« [-fpermissive]
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/windows.h:50:0,
                 from LoadDll.cpp:16:
c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/winbase.h:2215:24: Fehler:   Argument 3 von »BOOL WriteProcessMemory(HANDLE, LPVOID, LPCVOID, SIZE_T, SIZE_T*)« wird initialisiert [-fpermissive]

The source code can be found at: https://pastebin.com/AuZpy57U

It seems like the error is in line 313

if ( ! WriteProcessMemory( hProcess, p, &RemoteThread, 0, 0 ) )

I hope you can help me compiling this.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182

1 Answers1

1
if ( ! WriteProcessMemory( hProcess, p, &RemoteThread, 0, 0 ) )

You have to cast the third parameter:

if ( !WriteProcessMemory( hProcess, p, reinterpret_cast<LPCVOID>(&RemoteThread), 0, 0 ) )

Update:

To get rid of undefined reference to 'WinMain@16' you should use

int main()
{
    int argc;
    wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);

    // ...

instead of

int wmain(int argc, wchar_t *argv[])
{
    // ...
Swordfish
  • 12,971
  • 3
  • 21
  • 43
  • It seems like an syntax error (even if i change the paranthesis): LoadDll.cpp: In Funktion »bool ExecuteRemoteThread(HANDLE, BOOL, BOOL, wchar_t*, wchar_t*)«: LoadDll.cpp:313:58: Fehler: expected type-specifier before »(« token LoadDll.cpp:313:58: Fehler: expected »>« before »(« token LoadDll.cpp:313:66: Fehler: expected primary-expression before »)« token – PrinzPorno Sep 08 '18 at 22:29
  • @PrinzPorno what syntax error. you said you fixed the brackets already. – Swordfish Sep 08 '18 at 22:45
  • No i tried to play around with the brackets (make it like in your answer now) but had no sucess :( – PrinzPorno Sep 08 '18 at 22:46
  • @PrinzPorno you won't have much luck learning C++ by trial and error. i've fixed the mistake in my answer. – Swordfish Sep 08 '18 at 22:47
  • I did it the exact same way as you.. now i get errors again like: undefined reference to `WinMain@16'. Sorry, to be honest for now i just want to compile this program. I still learn C++ but i am far away of understanding this code :( – PrinzPorno Sep 08 '18 at 22:49
  • @PrinzPorno I've updated my answer regarding "undefined reference to 'WinMain@16'". – Swordfish Sep 08 '18 at 23:22