• Trainer
  • Forums
  • Suche
  • Members
  • Kalender
  • Hilfe
  • Extras
Forum stats
Show team
Neue Beiträge ansehen
Heutige Beiträge ansehen
Home of Gamehacking - Archiv
Login to account Create an account
Login
Benutzername:
Passwort: Passwort vergessen?
 



  Home of Gamehacking - Archiv Coding C, C#, C++, Visual C++
1 2 Weiter »
[C++] WriteMemory Funktion

Ansichts-Optionen
[C++] WriteMemory Funktion
Acubra Offline
Trainermaker
****
Beiträge: 904
Themen: 127
Registriert seit: Oct 2010
Bewertung: 6
#1
10.01.2012, 21:17 (Dieser Beitrag wurde zuletzt bearbeitet: 21.06.2016, 01:46 von iNvIcTUs oRCuS.)
Hey,
da ich grade an einer Trainerbase in C++ arbeite, habe ich mir gedacht das ich ja die wichtigsten Funktionen hier veröffentlichen kann.
Vllt. mach ich dann auch die komplette Base publik.

Nun zur Funktion (die Kommentare sollten alles erklären):

C Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//////////////////////////////////////////////////////////////////////////
//WriteMemory
//This function will write specific code at a specific memory location. It will need the process and module name of the target,
//Furthermore you need to pass the offset relative to your base address to the function.
//Function will return 1 if everything went correctly. If not it will show you an error and return 0.
//////////////////////////////////////////////////////////////////////////

int WriteMemory(LPCWSTR szProcessName, LPCWSTR szModuleName, DWORD dwOffset, BYTE szOrigCode[], int nOrigCode, BYTE szModCode[], int nModCode)
{
	HANDLE hProcess; //Process handle.
	DWORD BaseAddress, lpAddress, dwOldProtect; //BaseAddress of the module and the real address we want to know.
	char* BytesRead[255]; //Buffer

	
	hProcess = GetProcessHandle(szProcessName); //Get the process handle for WPM/RPM.
	if (hProcess == 0)
	{
		MessageBox(NULL, _T("Couldn't get process handle!"), szErrorTitle, NULL);
		return 0;
	}
	BaseAddress = GetModuleBaseAddress(szProcessName, szModuleName); //Get the base address of the specific module.
	if (BaseAddress == 0)
	{
		MessageBox(NULL, _T("Couldn't get module base address!"), szErrorTitle, NULL);
		return 0;
	}

	lpAddress = (DWORD)BaseAddress + dwOffset; //Calculate real address.

	//Read code and compare it. If it's szOrigCode, then we need to write our Code. If it's szModCode, then we need to write the original code
	//If it's neither one of these two, then the user has probably a wrong version.
	//First VirtualProtectEx to make the code read/writeable.
	if (VirtualProtectEx(hProcess, (LPVOID)lpAddress, nOrigCode, PAGE_EXECUTE_READWRITE, &dwOldProtect) == 0)
	{
		MessageBox(NULL, _T("VirtualProtectEx failed!"), szErrorTitle, NULL);
		return 0;
	}
	//Now ReadProcessMemory and the byte comparism.
	if(ReadProcessMemory(hProcess, (LPVOID)lpAddress, (LPVOID)BytesRead, nOrigCode, 0) == 0)
	{
		MessageBox(NULL, _T("ReadProcessMemory failed!"), szErrorTitle, NULL);
		return 0;
	}
	//Compare original bytes with those standing in memory.
	if(memcmp((const void*)BytesRead, szOrigCode, nOrigCode) == 0) //Bytes match.
	{
		//We got the original bytes standing in memory, so we activate the cheat now.
		if ((WriteProcessMemory(hProcess, (LPVOID)lpAddress, (LPCVOID)szModCode, nModCode, 0)) == 0)
		{ 
			//Oh noes, WPM error.
			MessageBox(NULL, _T("Failed to write to process memory.."), szErrorTitle, NULL);
			return 0;
		}
		else //Everything went fine.
		{
			Beep(0x1000,200); //Activated sound.
			return 1;
		}
	}
	else if (memcmp((const void*)BytesRead, szModCode, nModCode) == 0)
	{
		//We got the modified bytes standing in memory. So the user wants to deactivate the option now. Therefore we need to write
		//the original bytes.
		if ((WriteProcessMemory(hProcess, (LPVOID)lpAddress, (LPCVOID)szOrigCode, nOrigCode, 0)) == 0)
		{ 
			//Oh noes, WPM error.
			MessageBox(NULL, _T("Failed to write to process memory.."), szErrorTitle, NULL);
			return 0;
		}
		else //Everything went fine.
		{
			Beep(0x500,200); //Deactivated sound.
			return 1;
		}
	}
	else
	{
		//Neither modified bytes nor original bytes found. So the user has a wrong/currupted version.
		MessageBox(NULL, _T("You have the wrong gameversion!"), szErrorTitle, NULL);
		return 0;
	}
	return 0;
}

"Auf dieser Welt gibt es mehr Scheisse als auf Festivalklos"
[Bild: hoglogo_smalpxga.jpg]
Homepage Suchen
Antworten
Share Thread:            


Nachrichten in diesem Thema
[C++] WriteMemory Funktion - von Acubra - 10.01.2012, 21:17
RE: [C++] WriteMemory Funktion - von fr33k - 11.01.2012, 00:28

  • Druckversion anzeigen
  • Thema abonnieren


Benutzer, die gerade dieses Thema anschauen:
1 Gast/Gäste

  • Kontakt
  • Forum team
  • Forum stats
  • Nach oben
 
  • RSS-Synchronisation
  • Lite mode
  • Home of Gamehacking - Archiv
  • Help
 
Forum software by © MyBB - Theme © iAndrew 2014



Linearer Modus
Baumstrukturmodus