DLL Injection + Create Thread Wtf?

Posts 18 of 8 · Page 1 of 1
DLL Injection + Create Thread Wtf?
Okay so basically I am injecting my dll into a game and then creating a thread within the game so I may have access, now my code is like 38 lines long and it's as BASIC as it can get, yet, whenever I inject it crashes. I have determined the reason for crashing is the CreateThread call, but I can't see what I've done wrong with it. Can someone look at my code because I've been at this for hours.

Code:
#include <windows.h>

#define game "League of Legends (TM) Client"
#define game2 "PVP.net Client"
HWND hWnd;
HANDLE HndThread;

int Thread()
{
	hWnd = FindWindow(NULL,game);
	while(1)
	{
		if(GetAsyncKeyState(VK_F12)&1)
		{
			ShowWindow(hWnd,SW_MINIMIZE);
		}
		if(GetAsyncKeyState(VK_F10)&1)
		{
			return 0;
		}
		Sleep(1);
	}
}

BOOL APIENTRY DllMain( HMODULE hModule,DWORD reason,LPVOID lpReserved)
{
	if(reason == DLL_PROCESS_ATTACH)
	{
		hWnd = FindWindow(NULL,game);
		if(hWnd == NULL)
		{
			MessageBox(hWnd,"Could not find window.","Not Found",0);
			return 0;
		}
		else
		{
			HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Thread,NULL,0,NULL);
		}
	}
	return 0;
}
Now I realize the only purpose of this code is to minimize the game, but that's not my issue. Yes the game is a bitch to minimize because it is set to always on top etc. But my real problem is the fact I can't even inject it. Whenever I inject it crashes, and it's for sure the line
Code:
HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Thread,NULL,0,NULL);
Because when I comment it out the game doesn't crash, but it still crashes even if I call nothing in CreateThread, or if I comment everything inside Thread()

Any help is appreciated.

Edit: It's also not the injector, I've been using it for years.

~lilneo
Try this:
Code:
HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)Thread,NULL,0,NULL);
instead of
Code:
HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Thread,NULL,0,NULL);
Quote Originally Posted by Hell_Demon View Post
Try this:
Code:
HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)Thread,NULL,0,NULL);
instead of
Code:
HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Thread,NULL,0,NULL);
Beat me too it.
Quote Originally Posted by Hell_Demon View Post
Try this:
Code:
HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)Thread,NULL,0,NULL);
instead of
Code:
HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Thread,NULL,0,NULL);
I've tried that, it still crashes a second after injection. Even when I do
Code:
HndThread = CreateThread(0,0,0,NULL,0,NULL);
It crashes.

~lilneo
Quote Originally Posted by lilneo View Post
I've tried that, it still crashes a second after injection. Even when I do
Code:
HndThread = CreateThread(0,0,0,NULL,0,NULL);
It crashes.

~lilneo
When your NULL'ng it out, your not calling anything. You expect that to work? :S
Quote Originally Posted by Stephen View Post


When your NULL'ng it out, your not calling anything. You expect that to work? :S
No but I guess I was pointing out the fact it crashes as if it wasn't calling a thread, worded it wrong I guess.
~lilneo
Hmm. When I try it In D3D9 Test Window, I crash.

Code:
// Lilneo.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include <windows.h>

#define game "Test D3D9 Window"

HWND hWnd;
HANDLE HndThread;

int Thread()
{
	hWnd = FindWindowA(NULL,game);
	while(1)
	{
		if(GetAsyncKeyState(VK_F12)&1)
		{
			ShowWindow(hWnd,SW_MINIMIZE);
		}
		if(GetAsyncKeyState(VK_F10)&1)
		{
			return 0;
		}
		Sleep(1);
	}
}

BOOL APIENTRY DllMain( HMODULE hModule,DWORD reason,LPVOID lpReserved)
{
	if(reason == DLL_PROCESS_ATTACH)
	{
		hWnd = FindWindowA(NULL,game);
		if(hWnd == NULL)
		{
			MessageBoxA(hWnd,"Could not find window.","Not Found",0);
			return 0;
		}
		else
		{
			HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Thread,NULL,0,NULL);
		}
	}
	return 0;
}
Quote Originally Posted by Stephen View Post
Hmm. When I try it In D3D9 Test Window, I crash.

Code:
// Lilneo.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include <windows.h>

#define game "Test D3D9 Window"

HWND hWnd;
HANDLE HndThread;

int Thread()
{
	hWnd = FindWindowA(NULL,game);
	while(1)
	{
		if(GetAsyncKeyState(VK_F12)&1)
		{
			ShowWindow(hWnd,SW_MINIMIZE);
		}
		if(GetAsyncKeyState(VK_F10)&1)
		{
			return 0;
		}
		Sleep(1);
	}
}

BOOL APIENTRY DllMain( HMODULE hModule,DWORD reason,LPVOID lpReserved)
{
	if(reason == DLL_PROCESS_ATTACH)
	{
		hWnd = FindWindowA(NULL,game);
		if(hWnd == NULL)
		{
			MessageBoxA(hWnd,"Could not find window.","Not Found",0);
			return 0;
		}
		else
		{
			HndThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Thread,NULL,0,NULL);
		}
	}
	return 0;
}
Yeah I'm doing something wrong I just can't figure it out.

Found it... It's the return 0 at the end, supposed to be true.
~lilneo
Posts 18 of 8 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?