Hallo,
ich habe aus dem Internet einen Code für ein Patternscan:
Functions.h
source.cpp
so diesen code habe ich auch verstanden.
Jetzt ist es so, dass das Pattern das gefunden werden soll, nicht in einem Modul vorhanden ist.
Ein bekannter gab mir als Tipp, Pages zu durchsuchen mit VirtualQuery(Ex)
Kann mir einer erklären wie ich das auf den Code anwenden kann?
Danke schonmal
Mit freundlichen Grüßen
Moritz ;)
ich habe aus dem Internet einen Code für ein Patternscan:
Functions.h
Code:
#include <iostream>
#include <Windows.h>
#include <tlhelp32.h>
#include <Psapi.h>
//Print our pattern scan results if necessary
void MsgBoxAddy(DWORD addy)
{
char szBuffer[1024];
sprintf(szBuffer, "Addy: %02x", addy);
MessageBox(NULL, szBuffer, "Title", MB_OK);
}
//Get all module related info, this will include the base DLL.
//and the size of the module
MODULEINFO GetModuleInfo( char *szModule )
{
MODULEINFO modinfo = {0};
HMODULE hModule = GetModuleHandle(szModule);
if(hModule == 0)
return modinfo;
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
return modinfo;
}
void WriteToMemory(uintptr_t addressToWrite, char* valueToWrite, int byteNum)
{
//used to change our file access type, stores the old
//access type and restores it after memory is written
unsigned long OldProtection;
//give that address read and write permissions and store the old permissions at oldProtection
VirtualProtect((LPVOID)(addressToWrite), byteNum, PAGE_EXECUTE_READWRITE, &OldProtection);
//write the memory into the program and overwrite previous value
memcpy( (LPVOID)addressToWrite, valueToWrite, byteNum);
//reset the permissions of the address back to oldProtection after writting memory
VirtualProtect((LPVOID)(addressToWrite), byteNum, OldProtection, NULL);
}
DWORD FindPattern(char *module, char *pattern, char *mask)
{
//Get all module related information
MODULEINFO mInfo = GetModuleInfo(module);
//Assign our base and module size
//Having the values right is ESSENTIAL, this makes sure
//that we don't scan unwanted memory and leading our game to crash
DWORD base = (DWORD)mInfo.lpBaseOfDll;
DWORD size = (DWORD)mInfo.SizeOfImage;
//Get length for our mask, this will allow us to loop through our array
DWORD patternLength = (DWORD)strlen(mask);
for(DWORD i = 0; i < size - patternLength; i++)
{
bool found = true;
for(DWORD j = 0; j < patternLength; j++)
{
//if we have a ? in our mask then we have true by default,
//or if the bytes match then we keep searching until finding it or not
found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
}
//found = true, our entire pattern was found
//return the memory addy so we can write to it
if(found)
{
return base + i;
}
}
return NULL;
}
Code:
#include <Windows.h>
#include <iostream>
#include "Functions.h"
using namespace std;
char AmmoOpCode[] = "\x90\x90\x90\x90\x90\x90\x90\x90\x90";
void InitiateHooks()
{
///*-----UNLIMITED AMMO--------*/
//SCAN FOR THIS IN CHEAT ENGINE SEARCH
DWORD ammoAddy = FindPattern("plugin-container.exe",
"\xD9\x58\x58\xD9\x45\xE4\xD9\x58\x50", "xxxxxxxx");
//ammoAddy+=8;
MsgBoxAddy(ammoAddy);
WriteToMemory(ammoAddy, AmmoOpCode, 9);
}
#pragma endregion
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpReserved) // reserved
{
// Perform actions based on the reason for calling.
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
//MessageBoxA(NULL, "Attached successfuly", "", 0);
InitiateHooks();
break;
}
// Successful DLL_PROCESS_ATTACH.
return TRUE;
}
Jetzt ist es so, dass das Pattern das gefunden werden soll, nicht in einem Modul vorhanden ist.
Ein bekannter gab mir als Tipp, Pages zu durchsuchen mit VirtualQuery(Ex)
Kann mir einer erklären wie ich das auf den Code anwenden kann?
Danke schonmal
Mit freundlichen Grüßen
Moritz ;)