aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthijs Lavrijsen <mattiwatti@gmail.com>2022-08-24 01:06:41 +0200
committerMatthijs Lavrijsen <mattiwatti@gmail.com>2022-08-24 01:06:41 +0200
commit50f82283e5f7ed3388cdc7de9e4a53bd40f26e2c (patch)
tree93066adcfc2a4986033974b97c7d9f6ca5d3d69d
parent25bb182026d24944713e36f129a93d08397de913 (diff)
Add StrniCmp implementation
-rw-r--r--EfiGuardDxe/PatchWinload.c2
-rw-r--r--EfiGuardDxe/util.c27
-rw-r--r--EfiGuardDxe/util.h11
3 files changed, 39 insertions, 1 deletions
diff --git a/EfiGuardDxe/PatchWinload.c b/EfiGuardDxe/PatchWinload.c
index eff1c91..e5bfd76 100644
--- a/EfiGuardDxe/PatchWinload.c
+++ b/EfiGuardDxe/PatchWinload.c
@@ -64,7 +64,7 @@ GetBootLoadedModule(
{
// This is fairly heavy abuse of CR(), but legal C because (only) the first field of a struct is guaranteed to be at offset 0 (C99 6.7.2.1, point 13)
CONST PBLDR_DATA_TABLE_ENTRY Entry = (PBLDR_DATA_TABLE_ENTRY)BASE_CR(ListEntry, KLDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
- if (Entry != NULL && StrnCmp(Entry->KldrEntry.BaseDllName.Buffer, ModuleName, (Entry->KldrEntry.BaseDllName.Length / sizeof(CHAR16))) == 0)
+ if (Entry != NULL && StrniCmp(Entry->KldrEntry.BaseDllName.Buffer, ModuleName, (Entry->KldrEntry.BaseDllName.Length / sizeof(CHAR16))) == 0)
return &Entry->KldrEntry;
}
return NULL;
diff --git a/EfiGuardDxe/util.c b/EfiGuardDxe/util.c
index 230f491..2bb406f 100644
--- a/EfiGuardDxe/util.c
+++ b/EfiGuardDxe/util.c
@@ -99,6 +99,33 @@ PrintKernelPatchInfo(
}
}
+INTN
+EFIAPI
+StrniCmp(
+ IN CONST CHAR16 *FirstString,
+ IN CONST CHAR16 *SecondString,
+ IN UINTN Length
+ )
+{
+ if (FirstString == NULL || SecondString == NULL || Length == 0)
+ return 0;
+
+ CHAR16 UpperFirstChar = CharToUpper(*FirstString);
+ CHAR16 UpperSecondChar = CharToUpper(*SecondString);
+ while ((*FirstString != L'\0') && (*SecondString != L'\0') &&
+ (UpperFirstChar == UpperSecondChar) &&
+ (Length > 1))
+ {
+ FirstString++;
+ SecondString++;
+ UpperFirstChar = CharToUpper(*FirstString);
+ UpperSecondChar = CharToUpper(*SecondString);
+ Length--;
+ }
+
+ return UpperFirstChar - UpperSecondChar;
+}
+
BOOLEAN
EFIAPI
WaitForKey(
diff --git a/EfiGuardDxe/util.h b/EfiGuardDxe/util.h
index 08e30e6..4565c79 100644
--- a/EfiGuardDxe/util.h
+++ b/EfiGuardDxe/util.h
@@ -46,6 +46,17 @@ PrintKernelPatchInfo(
);
//
+// Case-insensitive string comparison.
+//
+INTN
+EFIAPI
+StrniCmp(
+ IN CONST CHAR16 *FirstString,
+ IN CONST CHAR16 *SecondString,
+ IN UINTN Length
+ );
+
+//
// Waits for a key to be pressed before continuing execution.
// Returns FALSE if ESC was pressed to abort, TRUE otherwise.
//