diff options
author | Matthijs Lavrijsen <mattiwatti@gmail.com> | 2021-05-25 21:08:07 +0200 |
---|---|---|
committer | Matthijs Lavrijsen <mattiwatti@gmail.com> | 2021-05-25 21:08:07 +0200 |
commit | 1cc497f053c9345b78167840f5e4a48951db8268 (patch) | |
tree | 0bb37e4c0e31209c167ff53e481610dd1915eb6c /Application/EfiDSEFix/src/pe.cpp | |
parent | d1d9d858565d53f2b76249554765a7ed10e234c6 (diff) |
EfiDSEFix: improve g_CiOptions address validationv1.2.1
- Verify expected lengths of instructions
- Verify CipInitialize is in PAGE
- Verify g_CiOptions is in either .data or CiPolicy
Fixes #31 (regression due to KB5003173 fix)
Diffstat (limited to 'Application/EfiDSEFix/src/pe.cpp')
-rw-r--r-- | Application/EfiDSEFix/src/pe.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Application/EfiDSEFix/src/pe.cpp b/Application/EfiDSEFix/src/pe.cpp index 2187537..97d2333 100644 --- a/Application/EfiDSEFix/src/pe.cpp +++ b/Application/EfiDSEFix/src/pe.cpp @@ -110,6 +110,35 @@ MapFileSectionView( return Status; } +BOOLEAN +AddressIsInSection( + _In_ PUCHAR ImageBase, + _In_ PUCHAR Address, + _In_ PIMAGE_NT_HEADERS NtHeaders, + _In_ PCCH SectionName + ) +{ + if (ImageBase > Address) + return FALSE; + if (Address >= ImageBase + NtHeaders->OptionalHeader.SizeOfImage) + return FALSE; + + const ULONG Rva = static_cast<ULONG>(static_cast<ULONG_PTR>(Address - ImageBase)); + PIMAGE_SECTION_HEADER Section = IMAGE_FIRST_SECTION(NtHeaders); + const USHORT NumberOfSections = NtHeaders->FileHeader.NumberOfSections; + for (USHORT i = 0; i < NumberOfSections; ++i) + { + if (Section->VirtualAddress <= Rva && + Section->VirtualAddress + Section->Misc.VirtualSize > Rva) + { + if (strncmp(reinterpret_cast<PCCH>(Section->Name), SectionName, IMAGE_SIZEOF_SHORT_NAME) == 0) + return TRUE; + } + Section++; + } + return FALSE; +} + PVOID GetProcedureAddress( _In_ ULONG_PTR DllBase, |