Get SA-MP server's IP

johnwayne

New member
Joined
Nov 10, 2013
Messages
3
Reaction score
0
Hi,
I hope someone can help me out. Im new in c++, and I'd like to get the hostname and the ip of the server, where I am connected.

I found this topic: http://ugbase.eu/notessnippets/(-collection-of-0-3-7-0-*-*-offsets-)/
But i need more info other than that. I know the basic stuffs like ReadProcessMemory, WriteProcessMemory, but this one is hard for me.

thanks
 

0B36

Expert
Joined
Jan 6, 2014
Messages
1,324
Reaction score
8
SAMP_INFO + 0x20 = szIP (size 257)
SAMP_INFO + 0x121 = szHostname (size 259)
SAMP_INFO + 0x225 = ulPort

^You need to use that if you already know about Read and WriteProcessMemory.
 

johnwayne

New member
Joined
Nov 10, 2013
Messages
3
Reaction score
0
Thanks!
I guees I need this: "samp.dll"+0x215B40" to get the SAMP_INFO. So i think i have to get the samp.dll's base address first. How to do that? I did some research on Google, and found the GetModuleHandle function, but it doesn't want to work.

Code:
DWORD Address = (DWORD)GetModuleHandle(L"samp.dll") + 0x215B40;

char ServerIP[255];
DWORD valami = Address + 0x20;

ReadProcessMemory(process, (LPCVOID)valami, &ServerIP, sizeof(ServerIP), 0);
printf("IP: %s\n", ServerIP);
 

T3KTONIT

Well-known member
Joined
Sep 2, 2013
Messages
308
Reaction score
5
johnwayne link said:
Thanks!
I guees I need this: "samp.dll"+0x215B40" to get the SAMP_INFO. So i think i have to get the samp.dll's base address first. How to do that? I did some research on Google, and found the GetModuleHandle function, but it doesn't want to work.

Getting SAMP Entry Point:
Code:
DWORD SAMP = (DWORD)GetModuleHandleA("samp.dll");

Getting SAMP_INFO:
Code:
SAMP_INFO = *(DWORD*)(SAMP + SAMP_INFO_OFFSET); // SAMP_INFO_OFFSET : 0x21A0F8

Getting Info:
Code:
char * szIP = (char*)(SAMP_INFO + 0x20);
char * szHostName = (char*)(SAMP_INFO + 0x121);
unsigned short ulPort = *(unsigned short*)(SAMP_INFO + 0x225);



PS : Not tested.
 

johnwayne

New member
Joined
Nov 10, 2013
Messages
3
Reaction score
0
Thanks again!

Getting the base address gave me an error, so I modified the code and only worked like this:
Code:
DWORD SAMP = (DWORD) GetModuleHandleA("samp.dll");

And it gave me an empty address: 0x0. I tried with "HANDLE SAMP = ..." as well, but it did not work.
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
You'd need to be in the process for that.
Use this function from Google.
Code:
HMODULE GetModuleHandleExtern(char *szModuleName, DWORD dwProcessId)
{
	if (!szModuleName || !dwProcessId) { return NULL; } 
	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
	if (hSnap == INVALID_HANDLE_VALUE) { return NULL; }
	MODULEENTRY32 me;
	me.dwSize = sizeof(MODULEENTRY32);
	if (Module32First(hSnap, &me))
	{
		while (Module32Next(hSnap, &me)) 
		{
			if (!strcmp(me.szModule, szModuleName)) 
			{
				CloseHandle(hSnap);
				return me.hModule; 
			}
		}
	}
	CloseHandle(hSnap);
	return NULL; 
}
 
Top