Home of Gamehacking - Archiv

Normale Version: [C++] External ScanPattern/WritePattern
Sie sehen gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hey,
mir ist aufgefallen das ich die Scan/WritePattern Funktion aus meiner Trainerbase noch nicht released hab. Die Funktion ist relativ simple und kann nicht mit Wildcards umgehen, doch das kann man sehr einfach implementieren.

C++ Code
lpStartAddress = dwBaseAddress; //Start Address
	lpEndAddress = lpStartAddress + dwScanLength;

	//Calculate allocsize
	lpAllocSize = lpEndAddress - lpStartAddress;
	//Allocate memory
	AllocAddress = VirtualAlloc(0, lpAllocSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

	//Read whole code and store it in Allocaddress
	ReadProcessMemory(hProcess, (LPVOID)lpStartAddress, AllocAddress, lpAllocSize, 0);
	int i = 0, j = 0;
        //i suck at coding ;X
	__asm
	{
			push eax
			mov eax, AllocAddress
			mov pointer, eax
			pop eax
	}

	while (i != dwScanLength)
	{
		if (pointer[i] == szOrigCode[j])
		{
			if (j+1 == nOrigCode)
			{
				//Calculate beginning of the byte sequence
				i++;
				i = i - nOrigCode;
				lpStartAddress += i;
				//Patch memory
				if((WriteProcessMemory(hProcess, (LPVOID)lpStartAddress, (LPCVOID)szModCode, nOrigCode, 0)) == 0)
				{
					//Oh noes, WPM error.
					PlaySoundFromResource(IDR_ERROR);
					MessageBox(NULL, _T("Failed to write to process memory.."), szErrorTitle, NULL);
					return 0;
				}
				else //Everything went fine.
				{
					PlaySoundFromResource(IDR_KILLEDXLIVE); //Activated sound.
					return 1;
				}
			}
			lpStartAddress += i;
			//std::cout << "Found one matching byte at %x" << lpStartAddress;
			lpStartAddress = dwBaseAddress;
			i++; //increase counter
			j++;
		}
		else
		{

			j = 0;
			i++;
		}

	}
	PlaySoundFromResource(IDR_ERROR);
	MessageBox(NULL, _T("Failed to find pattern!"), szErrorTitle, NULL);
	//Function failed
	return 0;