Write with ReadProcessMemory to samp.dll

whoonga

Active member
Joined
Nov 6, 2014
Messages
52
Reaction score
0
Hi,

i want to read out the server name, when i am on a samp.
This is what i found in CE:
btkq95g8.png


There are so many tutorials out there for reading memory from a window, but not from a .dll.
Also i got a pointer to mange, not that easy for me getting started with c++.
This is what i got in c++:
Code:
int main()
{
	while (hWnd == 0) {
		hWnd = FindWindow(0, L"GTA:SA:MP");
		Sleep(100);
	}
	cout << "The window GTA:SA:MP was found!" << endl;

	GetWindowThreadProcessId(hWnd, &pId);
	pHandle = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION, TRUE, pId);

	DWORD ADDR;
	const char* ServerString;
	DWORD SAMPDLLBASE = GetModuleBaseAddress(L"GTA:SA:MP", L"samp.dll");

	ReadProcessMemory(pHandle, (LPVOID)((SAMPDLLBASE + 0x21A0F8) + 121), (LPVOID)&ServerString, sizeof(ServerString), NULL);
	cout << ServerString;
	
	std::cin.get();
}

Thanks in advance for helping me and taking you time!
 

0x_

Wtf I'm not new....
Administrator
Joined
Feb 18, 2013
Messages
1,116
Reaction score
167
1) You need to DE-reference the pointer, means first read +0x21A0F8.
2) Then take the output of that +121 and the max size of the array.
 

whoonga

Active member
Joined
Nov 6, 2014
Messages
52
Reaction score
0
0x688 said:
1) You need to DE-reference the pointer, means first read +0x21A0F8.
2) Then take the output of that +121 and the max size of the array.

you mean like this:
Code:
int main()
{
	while (hWnd == 0) {
		hWnd = FindWindow(0, L"GTA:SA:MP");
		Sleep(100);
	}
	cout << "The window GTA:SA:MP was found!" << endl;

	GetWindowThreadProcessId(hWnd, &pId);
	pHandle = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION, TRUE, pId);

	DWORD ADDR;
	const char* ServerString;
	DWORD SAMPDLLBASE = GetModuleBaseAddress(L"GTA:SA:MP", L"samp.dll");
	DWORD SNDOUT;

	ReadProcessMemory(pHandle, (LPVOID)(SAMPDLLBASE + 0x21A0F8), (LPVOID)&SNDOUT, sizeof(SNDOUT), NULL);
	ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 121), (LPVOID)&ServerString, sizeof(ServerString), NULL);
	cout << ServerString;
	
	std::cin.get();
}

prob. still fucked up, because it's not working.
hanging on that problem for too many hours, lost the focus.. need sleep :D
 

y0mike

Active member
Joined
May 10, 2014
Messages
97
Reaction score
41
Location
mizus girl's house
whoonga said:
0x688 said:
1) You need to DE-reference the pointer, means first read +0x21A0F8.
2) Then take the output of that +121 and the max size of the array.

you mean like this:
Code:
int main()
{
	while (hWnd == 0) {
		hWnd = FindWindow(0, L"GTA:SA:MP");
		Sleep(100);
	}
	cout << "The window GTA:SA:MP was found!" << endl;

	GetWindowThreadProcessId(hWnd, &pId);
	pHandle = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION, TRUE, pId);

	DWORD ADDR;
	const char* ServerString;
	DWORD SAMPDLLBASE = GetModuleBaseAddress(L"GTA:SA:MP", L"samp.dll");
	DWORD SNDOUT;

	ReadProcessMemory(pHandle, (LPVOID)(SAMPDLLBASE + 0x21A0F8), (LPVOID)&SNDOUT, sizeof(SNDOUT), NULL);
	ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 121), (LPVOID)&ServerString, sizeof(ServerString), NULL);
	cout << ServerString;
	
	std::cin.get();
}

prob. still fucked up, because it's not working.
hanging on that problem for too many hours, lost the focus.. need sleep :D
Code:
[code] 
ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 121), (LPVOID)&ServerString, sizeof(ServerString), NULL);

try changing that to
Code:
char ServerString[128];
ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 0x121), &ServerString, 128, NULL);

also one of your problems was that u were using SNDOUT + 121, 0x121 is not = 121
[/code]
 

whoonga

Active member
Joined
Nov 6, 2014
Messages
52
Reaction score
0
y0mike said:
whoonga said:
0x688 said:
1) You need to DE-reference the pointer, means first read +0x21A0F8.
2) Then take the output of that +121 and the max size of the array.

you mean like this:
Code:
int main()
{
	while (hWnd == 0) {
		hWnd = FindWindow(0, L"GTA:SA:MP");
		Sleep(100);
	}
	cout << "The window GTA:SA:MP was found!" << endl;

	GetWindowThreadProcessId(hWnd, &pId);
	pHandle = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION, TRUE, pId);

	DWORD ADDR;
	const char* ServerString;
	DWORD SAMPDLLBASE = GetModuleBaseAddress(L"GTA:SA:MP", L"samp.dll");
	DWORD SNDOUT;

	ReadProcessMemory(pHandle, (LPVOID)(SAMPDLLBASE + 0x21A0F8), (LPVOID)&SNDOUT, sizeof(SNDOUT), NULL);
	ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 121), (LPVOID)&ServerString, sizeof(ServerString), NULL);
	cout << ServerString;
	
	std::cin.get();
}

prob. still fucked up, because it's not working.
hanging on that problem for too many hours, lost the focus.. need sleep :D
Code:
[code] 
ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 121), (LPVOID)&ServerString, sizeof(ServerString), NULL);

try changing that to
Code:
char ServerString[128];
ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 0x121), &ServerString, 128, NULL);

also one of your problems was that u were using SNDOUT + 121, 0x121 is not = 121
[/code]

The reading of the adress is now working, but not the GetModuleBaseAddress. So the string im viewing in my console is not the server string.
Got this now to give me everything out:
Code:
int main()
{
	while (hWnd == 0) {
		hWnd = FindWindow(0, L"GTA:SA:MP");
		Sleep(100);
	}
	cout << "The window GTA:SA:MP was found!" << endl;

	GetWindowThreadProcessId(hWnd, &pId);
	pHandle = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION, TRUE, pId);

	DWORD ADDR;
	DWORD SAMPDLLBASE = GetModuleBaseAddress(L"GTA:SA:MP", L"samp.dll");
	DWORD SNDOUT;
	std::cout << SAMPDLLBASE << "\n";

	ReadProcessMemory(pHandle, (LPVOID)(SAMPDLLBASE + 0x21A0F8), (LPVOID)&SNDOUT, sizeof(SNDOUT), NULL);
	char ServerString[128];
	ReadProcessMemory(pHandle, (LPVOID)(SNDOUT + 0x121), &ServerString, 128, NULL);
	cout << ServerString;
	
	std::cin.get();
}

This is the console output:
pirc73ji.png
 
Joined
Feb 18, 2005
Messages
2,963
Reaction score
267
Maybe your GetModuleBaseAddress doesn't work or you have UAC enabled and need to run your program as admin.
 

whoonga

Active member
Joined
Nov 6, 2014
Messages
52
Reaction score
0
springfield said:
Maybe your GetModuleBaseAddress doesn't work or you have UAC enabled and need to run your program as admin.

UAC was enabled but is now disabled, with no differece.
The GetModuleBaseAddress is giving me a 0 out, so its clearly not working.
Here is my GetModuleBaseAddress function:
Code:
DWORD GetModuleBaseAddress(LPCWSTR szProcessName, LPCWSTR szModuleName)
{
	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	PROCESSENTRY32 pe32;

	if (hSnap == INVALID_HANDLE_VALUE)
	{
		return 0;
	}
	pe32.dwSize = sizeof(PROCESSENTRY32);
	if (Process32First(hSnap, &pe32) == 0)
	{
		CloseHandle(hSnap);
		return 0;
	}

	do
	{
		if (lstrcmp(pe32.szExeFile, szProcessName) == 0)
		{
			int PID;
			PID = pe32.th32ProcessID;

			HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
			MODULEENTRY32 xModule;

			if (hSnap == INVALID_HANDLE_VALUE)
			{
				return 0;
			}
			xModule.dwSize = sizeof(MODULEENTRY32);
			if (Module32First(hSnap, &xModule) == 0)
			{
				CloseHandle(hSnap);
				return 0;
			}

			do
			{
				if (lstrcmp(xModule.szModule, szModuleName) == 0)
				{
					CloseHandle(hSnap);
					return (DWORD)xModule.modBaseAddr;
				}
			} while (Module32Next(hSnap, &xModule));
			CloseHandle(hSnap);
			return 0;
		}
	} while (Process32Next(hSnap, &pe32));
	CloseHandle(hSnap);
	return 0;
}

and here how i call it:
Code:
DWORD SAMPDLLBASE = GetModuleBaseAddress(L"GTA:SA:MP", L"samp.dll");
cout << SAMPDLLBASE << "\n";

it would be a lot easier, if i would inject it as a .dll but its external..
 
Top