All pastes #1521 Raw Edit

Segosa

public cpp v1 · immutable
#1521 ·published 2004-10-17 07:45 UTC
rendered paste body
unsigned char bFindCRC[]      = {0x83, 0xF8, 0x02, 0x74, 0x1B, 0x83, 0xF8, 0x03};unsigned char bPatchCRC[]     = {0x83, 0xF8, 0x02, 0x74, 0x00, 0x83, 0xF8, 0x03};// ...bool patch(HANDLE hFile, unsigned char bFindPattern[], unsigned char bReplacePattern[]){	DWORD nRead=0,nWritten=0;		int nSize = GetFileSize(hFile,NULL); 		char *szFileContents = new char[nSize+1];	if (!ReadFile(hFile,szFileContents,nSize,&nRead,NULL))		return false;	bool fDone=false;	int nOffset = 0;	char *szTmp=new char[nSize+1];	for (int i=0; i < nSize; i++)	{		if (szFileContents[i] == bFindPattern[0])		{			memcpy((void*)szTmp,szFileContents+i,sizeof(bFindPattern));			if (memcmp((void*)szTmp,bFindPattern,sizeof(bFindPattern)) == 0)			{				fDone=true;				nOffset = i;			}		}	}	delete[] szTmp;	delete[] szFileContents;	display_d(nOffset,16);	if (fDone) 		if (SetFilePointer(hFile,nOffset,NULL,FILE_BEGIN))            if (WriteFile(hFile,bReplacePattern,sizeof(bReplacePattern),&nWritten,NULL))				if (nWritten==sizeof(bReplacePattern))					return true;	return false;}