Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int PatchFile(LPCSTR FileName,char* sP_,char* sM_,char* rP_,char* rM_,int pSize)
- {
- int retvalue,filesize;
- HANDLE hFile,hFileMapping,hViewOfFile;
- retvalue=0;
- hFile = CreateFile(FileName,GENERIC_READ+GENERIC_WRITE,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL+FILE_ATTRIBUTE_HIDDEN,0);
- if(hFile!=INVALID_HANDLE_VALUE)
- {
- hFileMapping = CreateFileMapping(hFile,0,PAGE_READWRITE,0,0,0);
- if(hFileMapping)
- {
- hViewOfFile = MapViewOfFile(hFileMapping,FILE_MAP_WRITE,0,0,0);
- if(hViewOfFile)
- {
- filesize = GetFileSize(hFile,0);
- retvalue = Search((PBYTE)hViewOfFile,(char*)sP_,(char*)sM_,(char*)rP_,(char*)rM_,pSize,filesize,1);
- UnmapViewOfFile(hViewOfFile);
- }
- CloseHandle(hFileMapping);
- }
- CloseHandle(hFile);
- }
- return retvalue;
- }
- int Search( PBYTE lpTargetAddress,
- char* lpSearchPattern,
- char* lpSearchMask,
- char* lpReplacePattern,
- char* lpReplacehMask,
- UINT cbPatternSize,
- UINT cbSearchSize,
- BOOL bOffset )
- {
- ULONG ReturnValue = 0; // Set return value to 0
- int RetV;
- UINT i = 0; // Set counter 'i' to 0
- UINT j = 0; // Set counter 'j' to 0
- RetV = 0;
- do // Do {STEPS} while {CONDITION == TRUE}
- {
- j = 0; // In loop, set counter 'j' to 0;
- do // Do {STEPS} while {CONDITION == TRUE}
- {
- if ( lpSearchMask[j] == 0 ) // If byte is 0x00, check byte, else skip
- {
- if ( lpTargetAddress[i+j] != lpSearchPattern[j] )// If current byte isn't a match, break loop
- {
- break; // Break loop
- }
- }
- j++; // Else, check next mask byte in pattern
- } while ( j < cbPatternSize ); // CONDITION: While counter 'j' is less than pattern size
- if (j ==cbPatternSize )
- {
- ReturnValue = i; // If it makes it here, we've got a match
- ReturnValue += ( ( UINT ) lpTargetAddress ); // Add lpTargetAddress to return value
- __asm {
- mov esi,lpReplacePattern
- mov edi,ReturnValue
- mov ecx,cbPatternSize
- rep movsb
- }
- RetV = 1;
- break; // Break loop
- }
- i++; // Next byte in search buffer
- } while ( i <= cbSearchSize - cbPatternSize ); // CONDITION: While we havent searched the entire search range
- return RetV; // Return result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement