My pattern finding function

Posts 1618 of 18 · Page 2 of 2
A little bit of an update, I don't know if it works yet, my hack still crashes the game even if I just declare the correct addresses. Please let me know if it works for you.

The point of this update it to make the function easier to C+P... since pretty much everyone uses the function with the prototype:

Code:
DWORD FindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char *szMask)
This is my method:

Includes:

Code:
#include <Windows.h>
#include <string.h>

And the functions:


Code:
#define realAddy( cast, base, offset ) (cast)((DWORD)(base) + (DWORD)(offset))
bool bExist(BYTE part, BYTE *whole, char *mask)
{
	BYTE *start = (BYTE*)(whole + sizeof(whole) - 1);
	for(DWORD loc = 0; loc < sizeof(whole); loc++)
		if((*(BYTE*)(start - loc) == part) || (*(mask + (strlen(mask) - 1) - loc) == '?')) return true;
	return false;
}
DWORD lastLocationOfByte(BYTE part, BYTE *whole, char *mask)
{
	BYTE *start = (BYTE*)(whole + sizeof(whole) - 1);
	for(DWORD loc = 0; loc < sizeof(whole); loc++)
		if((*(BYTE*)(start - loc) == part) || (*(mask + (strlen(mask) - 1) - loc) == '?')) return (sizeof(whole) - loc);
}
DWORD FindPattern(DWORD first, DWORD total, BYTE *val, char *mask)
{
	size_t next = sizeof(*val);
	BYTE *addy = (BYTE*)((val + next) - 1);
	bool exist = false;
	BYTE *loc;
	for(DWORD n = (next - 1); n < total;)
	{
		DWORD spot;
		for(spot = 0; (*(unsigned char*)(first + n - spot) == *(unsigned char*)(addy - spot)) || (*(mask + (strlen(mask) - 1) - spot) == '?'); spot++);
		if(spot == next) return realAddy( DWORD, first, n );
		else if(bExist(*(BYTE*)(first + n), val, mask))
			n += lastLocationOfByte(*(BYTE*)(first + n), val, mask);
		else n += next;
	}
	return false;
}
i'll test it when i come to my home yoda and i really like your work brother
Posts 1618 of 18 · Page 2 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?