AngryCreate Thread DLL Injection

Posts 1–7 of 7 · Page 1 of 1
Create Thread DLL Injection
Okay so I got all this code working FINE! However after I press F2 to execute the function a couple of seconds following I get a just in time debugger exception in my game detected by visual studio. The game still keeps running though and doesn't crash unless I acknowledge the error window then it terminates the process. I'm new to C++ so I'm probably fucking up somewhere and just missing it been on this for literally hours to no success I'm pretty sure it's something to do with my create thread but I can't be sure.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>

void popup()

{
if (GetAsyncKeyState(VK_F2))
{
((void(__cdecl*) (int, const char*))0x59DD70) (0, "popup_gamesetup");
}

}

void snip()
{
for (;; )
{
popup();

}

}



BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)snip, 0,0,0);
}
return TRUE;
}






ps. I have used this exact method of create thread to write to memory and it worked fine with no issues at all
So I have come to the conclusion that I'm fucking retarded.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>


void snip()
{
((void(__cdecl*) (int, const char*))0x59DD70) (0, "popup_gamesetup");

}


BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)snip, 0, 0, 0);

}
return TRUE;
}

Only calling snip once yet somehow it works then I get a just in time error this is why I sit my ass on vb.net and don't move.
Don't use API calls from DLLMain
Quote Originally Posted by SilentWarp View Post
Don't use API calls from DLLMain
Calling CreateThread from DLLMain is perfectly fine.
Quote Originally Posted by WasserEsser View Post
Calling CreateThread from DLLMain is perfectly fine.
AuT03x3C was nice enough to look at it for me and even go as far as to resolve it the problem is if you call a function with a thread that isnt allowed to call it, it crashes the game. To fix you can bypass the thread checking this isnt a huge problem for someone very experienced in debugging and reverse engineering but being someone that mainly codes in vb.net and is only able to find simple offsets this is quite annoying (especially when just trying to get this out before the game dies completely). The popup gamesetup function is from mw2 I have now converted it over to mw3 for my server control tool and ingame kick menu but am bound to run into this problem again. Does anyone have any idea of a more simple way to avoid this issue when calling functions? My issue with mw3 may be totally different so I can't be sure but I can already tell it's going to be the only thing that will be a nightmare I guess I'll see tomorrow when I try it out and see what I can do. Anyway here is the code to fix the crashing in mw2 due to the thread not being allowed to call the function, AuT03x3C came up with it so all credits to him.

DWORD threadId;

void MyThread()
{
BYTE* ptrFunc = (PBYTE)0x576398;
threadId = GetCurrentThreadId();
*(DWORD*)&ptrFunc[2] = (DWORD)&threadId;
Ill take a look and get back to you
Quote Originally Posted by winningisme View Post
Ill take a look and get back to you
I'm pretty sure I just have to hook the function haven't taken a look in a while though
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us