From d979e19315d29ef70ea33e53c5e2725f0b638359 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Tue, 30 May 2017 11:32:05 -0700 Subject: [PATCH] fpad8() for --android-shlib in PackLinuxElf64::pack4() https://github.com/upx/upx/issues/100 modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 58e746b2..4fdefb47 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -87,6 +87,16 @@ fpad4(OutputFile *fo) return d + len; } +static unsigned +fpad8(OutputFile *fo) +{ + unsigned len = fo->st_size(); + unsigned d = 7u & (0 - len); + upx_uint64_t zero = 0; + fo->write(&zero, d); + return d + len; +} + static unsigned funpad4(InputFile *fi) { @@ -3714,7 +3724,7 @@ void PackLinuxElf64::pack4(OutputFile *fo, Filter &ft) } } if (k && fo) { - set_te64(&ehdri.e_shoff, fpad4(fo)); + set_te64(&ehdri.e_shoff, fpad8(fo)); set_te16(&ehdri.e_shentsize, sizeof(*shdri)); set_te16(&ehdri.e_shnum, 1+ k); Elf64_Shdr shdr_undef; memset(&shdr_undef, 0, sizeof(shdr_undef));