]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pe-binary: split pe_header_find_section() in two
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Jul 2024 08:31:20 +0000 (10:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 12 Sep 2024 08:02:15 +0000 (10:02 +0200)
This splits out the core part into a new function
pe_section_table_find().

pe_header_find_section() takes a PeHeader as input, while
pe_section_table_find() just takes the section table and its size.

src/shared/pe-binary.c
src/shared/pe-binary.h

index 448ace7571a7be807d3bc8e6dbe32e199fc27285..bfeaf3f1e1ded418cd6762fd592210726bb28517 100644 (file)
@@ -37,22 +37,21 @@ const IMAGE_DATA_DIRECTORY *pe_header_get_data_directory(
         return PE_HEADER_OPTIONAL_FIELD(h, DataDirectory) + i;
 }
 
-const IMAGE_SECTION_HEADER *pe_header_find_section(
-                const PeHeader *pe_header,
+const IMAGE_SECTION_HEADER *pe_section_table_find(
                 const IMAGE_SECTION_HEADER *sections,
+                size_t n_sections,
                 const char *name) {
 
         size_t n;
 
-        assert(pe_header);
         assert(name);
-        assert(sections || le16toh(pe_header->pe.NumberOfSections) == 0);
+        assert(sections || n_sections == 0);
 
         n = strlen(name);
         if (n > sizeof(sections[0].Name)) /* Too long? */
                 return NULL;
 
-        FOREACH_ARRAY(section, sections, le16toh(pe_header->pe.NumberOfSections))
+        FOREACH_ARRAY(section, sections, n_sections)
                 if (memcmp(section->Name, name, n) == 0 &&
                     memeqzero(section->Name + n, sizeof(section->Name) - n))
                         return section;
@@ -60,6 +59,16 @@ const IMAGE_SECTION_HEADER *pe_header_find_section(
         return NULL;
 }
 
+const IMAGE_SECTION_HEADER* pe_header_find_section(
+                const PeHeader *pe_header,
+                const IMAGE_SECTION_HEADER *sections,
+                const char *name) {
+
+        assert(pe_header);
+
+        return pe_section_table_find(sections, le16toh(pe_header->pe.NumberOfSections), name);
+}
+
 int pe_load_headers(
                 int fd,
                 IMAGE_DOS_HEADER **ret_dos_header,
index 08cc6a75ad76a839f74b404c844602a2484a5990..20f839e9a00b51118f357716293488ab5dd20274 100644 (file)
@@ -135,6 +135,7 @@ bool pe_header_is_64bit(const PeHeader *h);
 
 const IMAGE_DATA_DIRECTORY *pe_header_get_data_directory(const PeHeader *h, size_t i);
 const IMAGE_SECTION_HEADER *pe_header_find_section(const PeHeader *pe_header, const IMAGE_SECTION_HEADER *sections, const char *name);
+const IMAGE_SECTION_HEADER *pe_section_table_find(const IMAGE_SECTION_HEADER *sections, size_t n_sections, const char *name);
 
 int pe_load_headers(int fd, IMAGE_DOS_HEADER **ret_dos_header, PeHeader **ret_pe_header);