From 35333403efee065c046c680de836088d3b088bbe Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 15 Mar 2023 08:44:59 -0700 Subject: [PATCH] Zero ElfXX_Ehdr.e_sh* info when removing ElfXX_Shdr The aim is less confusion by static linkers: the _Shdr are gone! https://github.com/upx/upx/issues/659 modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 32fb1803..99e473de 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -5507,6 +5507,14 @@ void PackLinuxElf32::pack4(OutputFile *fo, Filter &ft) set_te32(&phdro->p_flags, Elf32_Phdr::PF_X | get_te32(&phdro->p_flags)); } } + if (!sec_arm_attr && !saved_opt_android_shlib) { + // Make it abunantly clear that there are no Elf32_Shdr in this shlib + Elf32_Ehdr *ehdro = (Elf32_Ehdr *)lowmem.getVoidPtr(); + ehdro->e_shoff = 0; + ehdro->e_shentsize = 0; + ehdro->e_shnum = 0; + ehdro->e_shstrndx = 0; + } fo->rewrite(&lowmem[0], sizeof(ehdri) + e_phnum * sizeof(*phdri)); fo->seek(linfo_off, SEEK_SET); fo->rewrite(&linfo, sizeof(linfo)); // new info: l_checksum, l_size @@ -5581,6 +5589,13 @@ void PackLinuxElf64::pack4(OutputFile *fo, Filter &ft) set_te64(&phdro->p_flags, Elf64_Phdr::PF_X | get_te64(&phdro->p_flags)); } } + // Make it abundantly clear that there are no Elf64_Shdr in a compressed shlib + Elf64_Ehdr *ehdro = (Elf64_Ehdr *)lowmem.getVoidPtr(); + ehdro->e_shoff = 0; + ehdro->e_shentsize = 0; + ehdro->e_shnum = 0; + ehdro->e_shstrndx = 0; + fo->rewrite(&lowmem[0], sizeof(ehdri) + e_phnum * sizeof(*phdri)); fo->seek(linfo_off, SEEK_SET); fo->rewrite(&linfo, sizeof(linfo)); // new info: l_checksum, l_size