From: Lennart Poettering Date: Fri, 5 Jul 2024 08:31:20 +0000 (+0200) Subject: pe-binary: split pe_header_find_section() in two X-Git-Tag: v257-rc1~441^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e6c49f7f11cbee0fde345c60b610cd0d8b0d3e1e;p=thirdparty%2Fsystemd.git pe-binary: split pe_header_find_section() in two 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. --- diff --git a/src/shared/pe-binary.c b/src/shared/pe-binary.c index 448ace7571a..bfeaf3f1e1d 100644 --- a/src/shared/pe-binary.c +++ b/src/shared/pe-binary.c @@ -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, diff --git a/src/shared/pe-binary.h b/src/shared/pe-binary.h index 08cc6a75ad7..20f839e9a00 100644 --- a/src/shared/pe-binary.h +++ b/src/shared/pe-binary.h @@ -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);