Esempio n. 1
0
// Invalidates an instruction cache for the specified region.
_Use_decl_annotations_ EXTERN_C void UtilInvalidateInstructionCache(
    void *BaseAddress, SIZE_T Length) {
#ifdef _AMD64_
  UNREFERENCED_PARAMETER(BaseAddress);
  UNREFERENCED_PARAMETER(Length);
  __faststorefence();
#else
  KeSweepIcacheRange(TRUE, BaseAddress, Length);
#endif
}
VOID DoPatches( PBYTE pBuffer, DWORD dwLength )
{
	DbgPrint( "Doing patches...\n" );
	PDWORD pdwData = ( PDWORD )pBuffer;

	// Sanity check
	if ( pdwData[ ( dwLength / 4 ) - 1 ] != -1 )
	{
		DbgPrint( "Bad patch file. End is not FFFFFFFF but is %08X\n", pdwData[ ( dwLength / 4 ) - 1 ] );
		return;
	}

	while ( TRUE )
	{
		DWORD dwAddress = *pdwData++;

		if ( dwAddress == -1 )
			break;

		DWORD dwPatchCount = *pdwData++;

		DbgPrint( "Patch found. Memory location 0x%08X Patch count %d\n", dwAddress, dwPatchCount );

		for ( DWORD i = 0; i < dwPatchCount; i++ )
		{
			DWORD dwAddrToPatch = dwAddress + ( i * 4 );

			DbgPrint( "Data in address %08X\n", *( DWORD* )dwAddrToPatch );
			DbgPrint( "Patching %08X data patching to %08X\n", dwAddrToPatch, *pdwData );

			*( DWORD* )( dwAddrToPatch ) = *pdwData++;
		}

		KeSweepIcacheRange( ( PVOID )dwAddress, dwPatchCount * 4 );
	}

	DbgPrint( "Patching complete\n" );
}