Results 1 to 8 of 8
  1. #1
    lilneo's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Canada
    Posts
    217
    Reputation
    8
    Thanks
    28

    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

  2. #2
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    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);
    Ah we-a blaze the fyah, make it bun dem!

  3. #3
    Stephen's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Engine.exe
    Posts
    4,689
    Reputation
    184
    Thanks
    1,149
    My Mood
    Aggressive
    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.

  4. #4
    lilneo's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Canada
    Posts
    217
    Reputation
    8
    Thanks
    28
    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

  5. #5
    Stephen's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Engine.exe
    Posts
    4,689
    Reputation
    184
    Thanks
    1,149
    My Mood
    Aggressive
    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

  6. The Following User Says Thank You to Stephen For This Useful Post:

    Hell_Demon (04-08-2011)

  7. #6
    lilneo's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Canada
    Posts
    217
    Reputation
    8
    Thanks
    28
    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

  8. #7
    Stephen's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Engine.exe
    Posts
    4,689
    Reputation
    184
    Thanks
    1,149
    My Mood
    Aggressive
    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;
    }
    Last edited by Stephen; 04-08-2011 at 10:32 AM.

  9. #8
    lilneo's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Canada
    Posts
    217
    Reputation
    8
    Thanks
    28
    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