]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pe-binary: add helper pe_is_addon() for detecting whether we are looking at PE EFI...
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Jul 2024 08:05:59 +0000 (10:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 12 Sep 2024 08:02:15 +0000 (10:02 +0200)
src/shared/pe-binary.c
src/shared/pe-binary.h

index 997e0e49a611fe54c2834f1dbec2e4c213875c23..a3aceb909e4529aec0c3c689271e00bc9a83a9dd 100644 (file)
@@ -240,3 +240,17 @@ bool pe_is_uki(const PeHeader *pe_header, const IMAGE_SECTION_HEADER *sections)
                 pe_header_find_section(pe_header, sections, ".osrel") &&
                 pe_header_find_section(pe_header, sections, ".linux");
 }
+
+bool pe_is_addon(const PeHeader *pe_header, const IMAGE_SECTION_HEADER *sections) {
+        assert(pe_header);
+        assert(sections || le16toh(pe_header->pe.NumberOfSections) == 0);
+
+        if (le16toh(pe_header->optional.Subsystem) != IMAGE_SUBSYSTEM_EFI_APPLICATION)
+                return false;
+
+        /* Add-ons do not have a Linux kernel, but do have either .cmdline or .dtb (currently) */
+        return !pe_header_find_section(pe_header, sections, ".linux") &&
+                (pe_header_find_section(pe_header, sections, ".cmdline") ||
+                 pe_header_find_section(pe_header, sections, ".dtb") ||
+                 pe_header_find_section(pe_header, sections, ".ucode"));
+}
index 2ef44d7e492e3d7b4d83a17e0348650aecd51e41..f0979711c8355d3387eef51b00fe2b5d0b343cc9 100644 (file)
@@ -142,3 +142,4 @@ int pe_load_sections(int fd, const IMAGE_DOS_HEADER *dos_header, const PeHeader
 int pe_read_section_data(int fd, const PeHeader *pe_header, const IMAGE_SECTION_HEADER *sections, const char *name, size_t max_size, void **ret, size_t *ret_size);
 
 bool pe_is_uki(const PeHeader *pe_header, const IMAGE_SECTION_HEADER *sections);
+bool pe_is_addon(const PeHeader *pe_header, const IMAGE_SECTION_HEADER *sections);