1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Allow ET_DYN on amd64-linux.elf

This commit is contained in:
John Reiser 2009-10-16 17:47:16 -07:00
parent 22a95ad8ea
commit 5085f3a15e
4 changed files with 35 additions and 35 deletions

View File

@ -685,7 +685,7 @@ PackLinuxElf64amd::defineSymbols(Filter const *)
unsigned lenu;
len += (7&-lsize) + lsize;
bool const is_big = (lo_va_user < (lo_va_stub + len + 2*page_size));
if (is_big) {
if (is_big && ehdri.ET_EXEC==get_te16(&ehdri.e_type)) {
set_te64( &elfout.ehdr.e_entry,
get_te64(&elfout.ehdr.e_entry) + lo_va_user - lo_va_stub);
set_te64(&elfout.phdr[0].p_vaddr, lo_va_user);
@ -1389,6 +1389,7 @@ PackLinuxElf64::generateElfHdr(
cprElfHdr2 *const h2 = (cprElfHdr2 *)(void *)&elfout;
cprElfHdr3 *const h3 = (cprElfHdr3 *)(void *)&elfout;
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
h3->ehdr.e_type = ehdri.e_type; // ET_EXEC vs ET_DYN (gcc -pie -fPIC)
h3->ehdr.e_ident[Elf32_Ehdr::EI_OSABI] = ei_osabi;
assert(get_te32(&h2->ehdr.e_phoff) == sizeof(Elf64_Ehdr));

View File

@ -1,5 +1,5 @@
/* amd64-linux.elf-fold.h
created from amd64-linux.elf-fold.bin, 1831 (0x727) bytes
created from amd64-linux.elf-fold.bin, 1830 (0x726) bytes
This file is part of the UPX executable compressor.
@ -31,20 +31,20 @@
*/
#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 1831
#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0x9644bb8e
#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0x1b987516
#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 1830
#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0x084ab9da
#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0x51fa8cc6
unsigned char stub_amd64_linux_elf_fold[1831] = {
unsigned char stub_amd64_linux_elf_fold[1830] = {
/* 0x0000 */ 127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0010 */ 2, 0, 62, 0, 1, 0, 0, 0,188, 0, 16, 0, 0, 0, 0, 0,
/* 0x0020 */ 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0030 */ 0, 0, 0, 0, 64, 0, 56, 0, 2, 0, 0, 0, 0, 0, 0, 0,
/* 0x0040 */ 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0050 */ 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0,
/* 0x0060 */ 39, 7, 0, 0, 0, 0, 0, 0, 40, 7, 0, 0, 0, 0, 0, 0,
/* 0x0060 */ 38, 7, 0, 0, 0, 0, 0, 0, 40, 7, 0, 0, 0, 0, 0, 0,
/* 0x0070 */ 0, 0, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
/* 0x0080 */ 39, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0080 */ 38, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0090 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x00a0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0,
/* 0x00b0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,232, 95, 0, 0,
@ -62,12 +62,12 @@ unsigned char stub_amd64_linux_elf_fold[1831] = {
/* 0x0170 */ 15, 5,133,192,120, 4,198, 4, 6, 0, 73,131,193, 15, 89, 94,
/* 0x0180 */ 95, 72,129,236, 0, 8, 0, 0, 72,137,226, 73,137,232,106, 0,
/* 0x0190 */ 232, 89, 4, 0, 0, 90, 72,129,196, 0, 8, 0, 0, 94, 95, 89,
/* 0x01a0 */ 80,106, 11, 88, 65,255, 39,255,225,176, 11,235, 13,176, 10,235,
/* 0x01b0 */ 9,176, 12,235, 5,176, 9, 73,137,202, 15,182,192, 15, 5, 72,
/* 0x01c0 */ 61, 0,240,255,255,114, 4, 72,131,200,255,195,176, 0,235,234,
/* 0x01d0 */ 176, 2,235,230,176, 3,235,226,176, 60,235,222, 81, 72, 57, 23,
/* 0x01a0 */ 80,106, 11, 88, 65,255, 39,176, 11,235, 13,176, 10,235, 9,176,
/* 0x01b0 */ 12,235, 5,176, 9, 73,137,202, 15,182,192, 15, 5, 72, 61, 0,
/* 0x01c0 */ 240,255,255,114, 4, 72,131,200,255,195,176, 0,235,234,176, 2,
/* 0x01d0 */ 235,230,176, 3,235,226,176, 60,235,222, 0, 0, 81, 72, 57, 23,
/* 0x01e0 */ 76,139, 71, 8, 72,141, 74,255,115, 10,191,127, 0, 0, 0,232,
/* 0x01f0 */ 228,255,255,255, 72,131,249,255,116, 17, 65, 15,182, 0, 72,255,
/* 0x01f0 */ 226,255,255,255, 72,131,249,255,116, 17, 65, 15,182, 0, 72,255,
/* 0x0200 */ 201, 73,255,192,136, 6, 72,255,198,235,233, 72, 1, 87, 8, 72,
/* 0x0210 */ 41, 23, 88,195, 65, 85, 73,137,213, 65, 84, 73,137,204, 85, 72,
/* 0x0220 */ 137,253, 83, 72,137,243, 72,131,236, 40, 72,131, 62, 0, 15,132,
@ -75,7 +75,7 @@ unsigned char stub_amd64_linux_elf_fold[1831] = {
/* 0x0240 */ 239,232,150,255,255,255,139, 84, 36, 16,139,116, 36, 20,133,210,
/* 0x0250 */ 117, 21,129,254, 85, 80, 88, 33,117, 17, 72,131,125, 0, 0, 15,
/* 0x0260 */ 132,177, 0, 0, 0,235, 4,133,246,117, 10,191,127, 0, 0, 0,
/* 0x0270 */ 232, 99,255,255,255, 57,214,119,242,137,208, 72, 59, 3,119,235,
/* 0x0270 */ 232, 97,255,255,255, 57,214,119,242,137,208, 72, 59, 3,119,235,
/* 0x0280 */ 57,214, 72,139, 67, 8,115,104,137, 84, 36, 12, 72,139,125, 8,
/* 0x0290 */ 72,141, 76, 36, 12, 68,139, 68, 36, 24, 72,137,194, 65,255,213,
/* 0x02a0 */ 133,192,117,199,139,116, 36, 12, 59,116, 36, 16,117,189, 15,182,
@ -99,7 +99,7 @@ unsigned char stub_amd64_linux_elf_fold[1831] = {
/* 0x03c0 */ 72, 15, 66,216, 72,131,198, 56,235,219, 72,129,229, 0,240,255,
/* 0x03d0 */ 255, 49,210, 69, 49,201, 72, 41,235, 65,131,200,255, 72,137,239,
/* 0x03e0 */ 72,129,195,255, 15, 0, 0, 72,129,227, 0,240,255,255, 72,137,
/* 0x03f0 */ 222,232,191,253,255,255, 72,141, 20, 24, 72, 41,232,102, 65,131,
/* 0x03f0 */ 222,232,189,253,255,255, 72,141, 20, 24, 72, 41,232,102, 65,131,
/* 0x0400 */ 127, 56, 0, 72,137, 68, 36, 24,199, 68, 36, 20, 0, 0, 0, 0,
/* 0x0410 */ 72,137, 84, 36, 72, 15,132,155, 1, 0, 0, 72,131,124, 36, 64,
/* 0x0420 */ 0,116, 37, 65,131, 60, 36, 6,117, 30, 72,139, 84, 36, 24, 73,
@ -113,7 +113,7 @@ unsigned char stub_amd64_linux_elf_fold[1831] = {
/* 0x04a0 */ 73,139, 68, 36, 8, 65,131,230, 7, 76,141, 44, 26,185, 50, 0,
/* 0x04b0 */ 0, 0, 72, 41,216, 72,131,124, 36, 64, 0,117, 7, 68,139, 68,
/* 0x04c0 */ 36, 60,177, 18, 68,137,242, 73,137,193, 76,137,238,131,202, 2,
/* 0x04d0 */ 72,131,124, 36, 64, 0, 72,137,239, 65, 15, 68,214,232,211,252,
/* 0x04d0 */ 72,131,124, 36, 64, 0, 72,137,239, 65, 15, 68,214,232,209,252,
/* 0x04e0 */ 255,255, 72, 57,197,117,121, 72,131,124, 36, 64, 0,116, 25, 72,
/* 0x04f0 */ 139, 76, 36, 32, 72,139, 84, 36, 40, 72,141,116, 36, 80, 72,139,
/* 0x0500 */ 124, 36, 64,232, 12,253,255,255, 76,137,235, 72,247,219,129,227,
@ -121,11 +121,11 @@ unsigned char stub_amd64_linux_elf_fold[1831] = {
/* 0x0520 */ 192, 72,137,217,252,243,170, 72,131,124, 36, 64, 0,116, 59, 73,
/* 0x0530 */ 131,124, 36, 8, 0,117, 23, 72,139,124, 36, 48, 72,141, 85, 12,
/* 0x0540 */ 199, 69, 12, 15, 5,195,144, 49,246,232,211,253,255,255, 68,137,
/* 0x0550 */ 242, 76,137,238, 72,137,239,232, 81,252,255,255,133,192,116, 10,
/* 0x0560 */ 191,127, 0, 0, 0,232,110,252,255,255, 73,141, 68, 29, 0, 72,
/* 0x0550 */ 242, 76,137,238, 72,137,239,232, 79,252,255,255,133,192,116, 10,
/* 0x0560 */ 191,127, 0, 0, 0,232,108,252,255,255, 73,141, 68, 29, 0, 72,
/* 0x0570 */ 1,197, 72, 59,108, 36, 8,115, 38, 72, 41,108, 36, 8, 69, 49,
/* 0x0580 */ 201, 65,131,200,255, 72,139,116, 36, 8,185, 50, 0, 0, 0, 68,
/* 0x0590 */ 137,242, 72,137,239,232, 27,252,255,255, 72, 57,197,117,193,255,
/* 0x0590 */ 137,242, 72,137,239,232, 25,252,255,255, 72, 57,197,117,193,255,
/* 0x05a0 */ 68, 36, 20, 65, 15,183, 71, 56, 73,131,196, 56, 57, 68, 36, 20,
/* 0x05b0 */ 15,140,101,254,255,255, 72,131,188, 36,160, 0, 0, 0, 0,116,
/* 0x05c0 */ 16, 72,139, 68, 36, 24, 72,139,148, 36,160, 0, 0, 0, 72,137,
@ -138,17 +138,17 @@ unsigned char stub_amd64_linux_elf_fold[1831] = {
/* 0x0630 */ 231, 72,137, 68, 36, 32,232,217,251,255,255, 73,139, 86, 16,190,
/* 0x0640 */ 3, 0, 0, 0, 72,137,223, 72,131,194, 64,232,209,252,255,255,
/* 0x0650 */ 72, 15,183, 85, 56,190, 5, 0, 0, 0, 72,137,223,232,191,252,
/* 0x0660 */ 255,255, 72,139, 85, 24,190, 9, 0, 0, 0, 72,137,223,232,174,
/* 0x0670 */ 252,255,255, 65, 83, 77,137,233, 77,137,224, 49,210, 72,137,217,
/* 0x0680 */ 72,137,239, 72,141, 68, 36,104, 72,141,116, 36, 24, 69, 49,237,
/* 0x0690 */ 80,232,189,252,255,255,102,131,125, 56, 0, 73,137,196, 65, 89,
/* 0x06a0 */ 65, 90,116,115, 65,131, 62, 3,117, 93, 72,139,124, 36, 96, 73,
/* 0x06b0 */ 3,126, 16, 49,210, 49,246,232, 20,251,255,255,133,192,137,195,
/* 0x06c0 */ 120, 23,186, 0, 4, 0, 0, 72,137,238,137,199,232,251,250,255,
/* 0x06d0 */ 255, 72, 61, 0, 4, 0, 0,116, 10,191,127, 0, 0, 0,232,245,
/* 0x06e0 */ 250,255,255, 65, 80, 49,246, 69, 49,201, 69, 49,192, 49,201,106,
/* 0x06f0 */ 0,137,218, 72,137,239,232, 88,252,255,255,137,223, 73,137,196,
/* 0x0700 */ 232,207,250,255,255, 94, 95, 15,183, 69, 56, 65,255,197, 73,131,
/* 0x0710 */ 198, 56, 65, 57,197,124,141, 72,131,196, 48, 76,137,224, 91, 93,
/* 0x0720 */ 65, 92, 65, 93, 65, 94,195
/* 0x0660 */ 255,255, 65, 83, 77,137,233, 77,137,224, 49,210, 72,137,217, 72,
/* 0x0670 */ 137,239, 72,141, 68, 36,104, 72,141,116, 36, 24, 69, 49,237, 80,
/* 0x0680 */ 232,206,252,255,255,190, 9, 0, 0, 0, 72,137,194, 72,137,223,
/* 0x0690 */ 73,137,196,232,137,252,255,255,102,131,125, 56, 0, 65, 89, 65,
/* 0x06a0 */ 90,116,115, 65,131, 62, 3,117, 93, 72,139,124, 36, 96, 73, 3,
/* 0x06b0 */ 126, 16, 49,210, 49,246,232, 19,251,255,255,133,192,137,195,120,
/* 0x06c0 */ 23,186, 0, 4, 0, 0, 72,137,238,137,199,232,250,250,255,255,
/* 0x06d0 */ 72, 61, 0, 4, 0, 0,116, 10,191,127, 0, 0, 0,232,244,250,
/* 0x06e0 */ 255,255, 65, 80, 49,246, 69, 49,201, 69, 49,192, 49,201,106, 0,
/* 0x06f0 */ 137,218, 72,137,239,232, 89,252,255,255,137,223, 73,137,196,232,
/* 0x0700 */ 206,250,255,255, 94, 95, 15,183, 69, 56, 65,255,197, 73,131,198,
/* 0x0710 */ 56, 65, 57,197,124,141, 72,131,196, 48, 76,137,224, 91, 93, 65,
/* 0x0720 */ 92, 65, 93, 65, 94,195
};

View File

@ -114,8 +114,7 @@ L90:
pop %rcx # JMPU
push %rax # &entry
push $ __NR_munmap; pop %rax
jmp *(%r15)
jmp *%rcx # goto: syscall; ret
jmp *(%r15) # goto: syscall; ret
munmap: .globl munmap
movb $ __NR_munmap,%al; jmp sysgo

View File

@ -340,11 +340,11 @@ upx_main( // returns entry address
// AT_PHDR.a_un.a_val is set again by do_xmap if PT_PHDR is present.
auxv_up(av, AT_PHDR , (unsigned long)(1+(Elf64_Ehdr *)phdr->p_vaddr));
auxv_up(av, AT_PHNUM , ehdr->e_phnum);
auxv_up(av, AT_ENTRY , (unsigned long)ehdr->e_entry);
//auxv_up(av, AT_PHENT , ehdr->e_phentsize); /* this can never change */
//auxv_up(av, AT_PAGESZ, PAGE_SIZE); /* ld-linux.so.2 does not need this */
entry = do_xmap(ehdr, &xi1, 0, av, f_decompress, f_unf, &reloc); // "rewind"
auxv_up(av, AT_ENTRY , entry);
{ // Map PT_INTERP program interpreter
int j;