Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 16:54

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Bot: DLL-Injection fails (but works with other programs)

Discussion on Bot: DLL-Injection fails (but works with other programs) within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2008
Posts: 11
Received Thanks: 1
Bot: DLL-Injection fails (but works with other programs)

Hi!

I'm not familiar with programming bots so I try to accomplish subgoals.

Currently I attempt to inject a DLL into Silkroad Online.
My program works fine with applications like Paint, Editor and Mozilla Firefox.

Unfortunately Silkroad is the only program it does not work with so far.

Programming language: C++
Game: Silkroad Online

Can you tell me why it doesn't work?

Thanks in advance!

My DLL:
Code:
#include <windows.h>

BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
	switch (reason)
	{
		case DLL_PROCESS_ATTACH:
			MessageBox(NULL, "Hi!", NULL, MB_OK);
			break;
		case DLL_PROCESS_DETACH:
			MessageBox(NULL, "See ya!", NULL, MB_OK);
			break;
	}

	return TRUE;
}
My program:
Code:
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string DLL = "..." + '\0';

	HWND SRO_Client;

	for (;;)
	{
		SRO_Client = FindWindow(NULL, "SRO_Client");

		if (SRO_Client != NULL)
		{
			break;
		}

		Sleep(5000);
	}

	DWORD PID;
	GetWindowThreadProcessId(SRO_Client, &PID);

	HANDLE hToken;
	TOKEN_PRIVILEGES tkp;

	if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
	{
		LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
		tkp.PrivilegeCount = 1;
		tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
		AdjustTokenPrivileges(hToken, 0, &tkp, sizeof(tkp), NULL, NULL);
	}

	HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
	LPVOID hRemoteMem = VirtualAllocEx(hProc, NULL, DLL.size(), MEM_COMMIT, PAGE_READWRITE);

	DWORD numBytesWritten;
	WriteProcessMemory(hProc, hRemoteMem, DLL.c_str(), DLL.size(), &numBytesWritten);

	HMODULE hLocKernel32 = GetModuleHandle("Kernel32");
	FARPROC hLocLoadLibrary = GetProcAddress(hLocKernel32, "LoadLibraryA");
	HANDLE hRemoteThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)hLocLoadLibrary, hRemoteMem, 0, NULL);

	WaitForSingleObject(hRemoteThread, 10000);

	VirtualFreeEx(hProc, hRemoteMem, DLL.size(), MEM_RELEASE);

	CloseHandle(hProc);

	Sleep(5000);
 
	return 1;
}
Improvement suggestions are welcome although I know this code is far from perfect.
nc10 is offline  
Old 01/09/2009, 09:21   #2
 
BlackFog's Avatar
 
elite*gold: 105
Join Date: Mar 2007
Posts: 5,073
Received Thanks: 558
Try to get the last Error with GetLastError() and look it up at

- Blackfog
BlackFog is offline  
Thanks
1 User
Old 01/09/2009, 14:48   #3
 
elite*gold: 0
Join Date: May 2008
Posts: 489
Received Thanks: 210
I suggest some logging and error checking to localize the problem. Once you did that use GetLastError() to find out what's wrong (if by this time you haven't figured it out yourself).

One thing I noticed: Is the Silkroad Wnd Title really "SRO_Client"? Sounds more like the class name to me, but I've never player Silkroad so...
schlurmann is offline  
Thanks
1 User
Old 01/09/2009, 17:15   #4
 
elite*gold: 0
Join Date: Dec 2008
Posts: 11
Received Thanks: 1
Thanks for your replies

Quote:
Try to get the last Error with GetLastError() and look it up at System Error Codes (Windows)
I'll do that this evening

Quote:
One thing I noticed: Is the Silkroad Wnd Title really "SRO_Client"? Sounds more like the class name to me, but I've never player Silkroad so...
Yes it's titled "SRO_Client".

Quote:
I suggest some logging and error checking to localize the problem. Once you did that use GetLastError() to find out what's wrong (if by this time you haven't figured it out yourself).
I haven't figured it out yet.

To describe the "error": When I try to inject the DLL while Silkroad is already open nothing happens. No error but my DLL doesn't display a message box.
When I try to inject the DLL right after executing Silkroad the game doesn't respond for a short while and then it responds again but my DLL doesn't display anything too.


>> EDIT >>

GetLastError in combination with FormatMessage helped me.
I'll do some research first and then post what was wrong.

>> EDIT >>

The OpenProcess function fails.
Error: Access denied

>> EDIT >>

Brainstorm!
Vista is to blame for my problem
You need to build the project and then check "run as administrator".
DLL-Injection works now.

Thanks!
nc10 is offline  
Reply


Similar Threads Similar Threads
Again Acclaim fails...
07/22/2010 - Dekaron - 18 Replies
this time when i changed the pass in the site everything is ok....but ingame is the same old password...i contact them before 10-12 hours :mad:....they didnt even reply...anyone other have this problem..or its only local for me..? :confused:
Fails
02/17/2010 - Cabal Online - 0 Replies
How I make cabal site
Can't click the programs listed in Start>All Programs
09/02/2009 - Technical Support - 2 Replies
Hi guys, i have a problem with my PC, sorry I can't understand german language so i'll write my concern in english. Ok, here's my problem, After I have run Online games (e.g. Rohan, Luna), I can't click anymore the listed applications/programs in All Programs menu (Start>All Programs). However if I didn't start any of those Online games, I don't encounter that kind of problems. Any solutions for this kind of problem? I have already tried, reformatting my PC, but still the problem...
To Those Who Say FHEo Fails
08/01/2008 - EO PServer Hosting - 44 Replies
First off, since i didnt get to say my 2 cents in the last thread twards the idiot who decided to flame FHEO i will do so now. First off all the donations we get are used speciffically for the server and for upkeeps. Those of who you have every owned a dedicated server (not one ran off your mommys PC) know they are not cheap to keep. We also have our Webhosting. for shits and giggles here is some of the specs of the dedicated we use. CPU: Xeon E4500 2.2GHz Quad Core Data...



All times are GMT +1. The time now is 16:54.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.