From b7c91941b817b6f9647179f52696045e614f947a Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 31 May 2017 11:04:56 -0700 Subject: [PATCH] --android-shlib fix Elf64_Shdr.sh_offset https://github.com/upx/upx/issues/100 modified: ../p_lx_elf.cpp modified: ../p_lx_elf.h --- src/p_lx_elf.cpp | 10 +++++----- src/p_lx_elf.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index a3a12435..29e6a9ce 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -447,7 +447,7 @@ void PackLinuxElf64::pack3(OutputFile *fo, Filter &ft) unsigned off = fo->st_size(); unsigned off_init = 0; // where in file upx_uint64_t va_init = sz_pack2; // virtual address - upx_uint64_t rel = 0; + so_slide = 0; for (int j = e_phnum; --j>=0; ++phdr) { upx_uint64_t const len = get_te64(&phdr->p_filesz); upx_uint64_t const ioff = get_te64(&phdr->p_offset); @@ -477,8 +477,8 @@ void PackLinuxElf64::pack3(OutputFile *fo, Filter &ft) off += (align-1) & (ioff - off); fi->seek(ioff, SEEK_SET); fi->readx(ibuf, len); fo->seek( off, SEEK_SET); fo->write(ibuf, len); - rel = off - ioff; - set_te64(&phdr->p_offset, rel + ioff); + so_slide = off - ioff; + set_te64(&phdr->p_offset, so_slide + ioff); } else { // Change length of first PT_LOAD. va_init += get_te64(&phdr->p_vaddr); @@ -489,7 +489,7 @@ void PackLinuxElf64::pack3(OutputFile *fo, Filter &ft) } // Compute new offset of &DT_INIT.d_val. if (phdr->PT_DYNAMIC==type) { - off_init = rel + ioff; + off_init = so_slide + ioff; fi->seek(ioff, SEEK_SET); fi->read(ibuf, len); Elf64_Dyn *dyn = (Elf64_Dyn *)(void *)ibuf; @@ -504,7 +504,7 @@ void PackLinuxElf64::pack3(OutputFile *fo, Filter &ft) // fall through to relocate .p_offset } if (xct_off < ioff) - set_te64(&phdr->p_offset, rel + ioff); + set_te64(&phdr->p_offset, so_slide + ioff); } if (off_init) { // change DT_INIT.d_val fo->seek(off_init, SEEK_SET); diff --git a/src/p_lx_elf.h b/src/p_lx_elf.h index 6b7142e7..5ed4bd69 100644 --- a/src/p_lx_elf.h +++ b/src/p_lx_elf.h @@ -278,7 +278,7 @@ protected: Elf64_Phdr const *gnu_stack; // propagate NX upx_uint64_t e_phoff; upx_uint64_t e_shoff; - unsigned so_slide; + upx_uint64_t so_slide; unsigned char *note_body; // concatenated contents of PT_NOTEs, if any unsigned note_size; // total size of PT_NOTEs upx_uint64_t page_mask; // AND clears the offset-within-page