From 4465715c2c3abbd554f2ee09360532bcf257d34a Mon Sep 17 00:00:00 2001 From: Matthijs Lavrijsen Date: Sun, 26 Mar 2023 14:13:39 +0200 Subject: Add CopyWpMem and SetWpMem routines Additionally make SetServicePointer also clear and restore CR0.WP if needed --- EfiGuardDxe/util.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'EfiGuardDxe/util.h') diff --git a/EfiGuardDxe/util.h b/EfiGuardDxe/util.h index d69fc89..89c13e6 100644 --- a/EfiGuardDxe/util.h +++ b/EfiGuardDxe/util.h @@ -6,6 +6,9 @@ #include #endif +#define CR0_WP ((UINTN)0x10000) // CR0.WP + + // // Stalls CPU for N milliseconds // @@ -47,6 +50,28 @@ PrintKernelPatchInfo( VOID ); +// +// Wrapper for CopyMem() that disables write protection prior to copying if needed. +// +VOID* +EFIAPI +CopyWpMem( + OUT VOID *Destination, + IN CONST VOID *Source, + IN UINTN Length + ); + +// +// Wrapper for SetMem() that disables write protection prior to copying if needed. +// +VOID* +EFIAPI +SetWpMem( + OUT VOID *Destination, + IN UINTN Length, + IN UINT8 Value + ); + // // Case-insensitive string comparison. // -- cgit v1.2.3