]> git.proxmox.com Git - efi-boot-shim.git/commitdiff
Add some more PE helpers we need for SBAT
authorPeter Jones <pjones@redhat.com>
Wed, 2 Dec 2020 19:29:14 +0000 (14:29 -0500)
committerPeter Jones <pjones@redhat.com>
Sat, 13 Feb 2021 16:02:59 +0000 (11:02 -0500)
Signed-off-by: Peter Jones <pjones@redhat.com>
pe.c

diff --git a/pe.c b/pe.c
index 10f763a4389114c2c8ba64846cd871f4823f1c7c..6da8fceb601b77a146cf72d4dd2ee75602df9862 100644 (file)
--- a/pe.c
+++ b/pe.c
@@ -240,6 +240,60 @@ get_section_vma (UINTN section_num,
        return EFI_SUCCESS;
 }
 
+EFI_STATUS
+get_section_vma_by_name (char *name, size_t namesz,
+                        char *buffer, size_t bufsz,
+                        PE_COFF_LOADER_IMAGE_CONTEXT *context,
+                        char **basep, size_t *sizep,
+                        EFI_IMAGE_SECTION_HEADER **sectionp)
+{
+       UINTN i;
+       char namebuf[9];
+
+       if (!name || namesz == 0 || !buffer || bufsz < namesz || !context
+           || !basep || !sizep || !sectionp)
+               return EFI_INVALID_PARAMETER;
+
+       /*
+        * This code currently is only used for ".reloc\0\0" and
+        * ".sbat\0\0\0", and it doesn't know how to look up longer section
+        * names.
+        */
+       if (namesz > 8)
+               return EFI_UNSUPPORTED;
+
+       SetMem(namebuf, sizeof(namebuf), 0);
+       CopyMem(namebuf, name, MIN(namesz, 8));
+
+       /*
+        * Copy the executable's sections to their desired offsets
+        */
+       for (i = 0; i < context->NumberOfSections; i++) {
+               EFI_STATUS status;
+               EFI_IMAGE_SECTION_HEADER *section = NULL;
+               char *base = NULL;
+               size_t size = 0;
+
+               status = get_section_vma(i, buffer, bufsz, context, &base, &size, &section);
+               if (!EFI_ERROR(status)) {
+                       if (CompareMem(section->Name, namebuf, 8) == 0) {
+                               *basep = base;
+                               *sizep = size;
+                               *sectionp = section;
+                               return EFI_SUCCESS;
+                       }
+                       continue;
+               }
+
+               switch(status) {
+               case EFI_NOT_FOUND:
+                       break;
+               }
+       }
+
+       return EFI_NOT_FOUND;
+}
+
 /*
  * Calculate the SHA1 and SHA256 hashes of a binary
  */