From 608662d73ba1dddabf2e4c344842e94995a90500 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 11 Oct 2017 08:45:21 -0700 Subject: [PATCH] x86_64 stub also needs make_hatch() https://github.com/upx/upx/issues/133 modified: stub/src/amd64-linux.elf-main.c --- src/stub/amd64-linux.elf-fold.h | 160 +++++++++++++------------- src/stub/src/amd64-linux.elf-main.c | 42 +++++-- src/stub/tmp/amd64-linux.elf-fold.map | 19 +-- 3 files changed, 123 insertions(+), 98 deletions(-) diff --git a/src/stub/amd64-linux.elf-fold.h b/src/stub/amd64-linux.elf-fold.h index 3a06452f..364cdbbc 100644 --- a/src/stub/amd64-linux.elf-fold.h +++ b/src/stub/amd64-linux.elf-fold.h @@ -1,5 +1,5 @@ /* amd64-linux.elf-fold.h - created from amd64-linux.elf-fold.bin, 2084 (0x824) bytes + created from amd64-linux.elf-fold.bin, 2149 (0x865) bytes This file is part of the UPX executable compressor. @@ -31,20 +31,20 @@ */ -#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 2084 -#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0x6305132a -#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0x904ce818 +#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 2149 +#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0x3e782201 +#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0x0980a7d1 -unsigned char stub_amd64_linux_elf_fold[2084] = { +unsigned char stub_amd64_linux_elf_fold[2149] = { /* 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 */ 36, 8, 0, 0, 0, 0, 0, 0, 36, 8, 0, 0, 0, 0, 0, 0, +/* 0x0060 */ 101, 8, 0, 0, 0, 0, 0, 0,104, 8, 0, 0, 0, 0, 0, 0, /* 0x0070 */ 0, 0, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -/* 0x0080 */ 36, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0x0080 */ 101, 8, 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, 89, 0, 0, @@ -65,7 +65,7 @@ unsigned char stub_amd64_linux_elf_fold[2084] = { /* 0x01a0 */ 200, 49,248,131,224, 8, 72, 41,199, 73,137,254, 72,131,239, 8, /* 0x01b0 */ 73,141,119,248, 72,193,233, 3,243, 72,165, 72,141,103, 8,252, /* 0x01c0 */ 75,141, 12, 38, 65, 89, 94, 95, 88, 72,129,236, 0, 8, 0, 0, -/* 0x01d0 */ 72,137,226, 80, 73,137,232,232, 4, 5, 0, 0, 72,129,196, 8, +/* 0x01d0 */ 72,137,226, 80, 73,137,232,232, 69, 5, 0, 0, 72,129,196, 8, /* 0x01e0 */ 8, 0, 0, 72,137, 68, 36, 24, 91, 69, 41,201, 65,137,216,106, /* 0x01f0 */ 2, 65, 90,106, 1, 90,190, 0, 16, 0, 0,106, 0, 95,106, 9, /* 0x0200 */ 88, 15, 5,137,223,106, 3, 88, 15, 5, 95, 94,106, 11, 88, 65, @@ -97,74 +97,78 @@ unsigned char stub_amd64_linux_elf_fold[2084] = { /* 0x03a0 */ 137,241, 72, 57,200,116, 17, 72,255,200, 15,148,194, 49,192,133, /* 0x03b0 */ 246, 15,149,192,133,194,116, 8, 72,137, 15, 76,137, 71, 8,195, /* 0x03c0 */ 72,131,199, 16,235,215,195, 65, 87,184, 0, 0, 0, 0, 65, 86, -/* 0x03d0 */ 65, 85, 65, 84, 73,137,252, 85, 83, 72,131,236,104, 76, 3,103, -/* 0x03e0 */ 32,102,131,127, 16, 3, 72,137, 76, 36, 40,185, 16, 0, 0, 0, -/* 0x03f0 */ 76,137, 68, 36, 32, 72,137,124, 36, 64, 72,137,116, 36, 56,137, -/* 0x0400 */ 84, 36, 52, 76,137, 76, 36, 24, 15, 68,200, 72,139,132, 36,160, -/* 0x0410 */ 0, 0, 0, 15,183, 87, 56, 76,137,230, 72,131,205,255, 49,219, -/* 0x0420 */ 49,255,131,193, 34, 76,139, 0,255,202,120, 33,131, 62, 1,117, -/* 0x0430 */ 22, 72,139, 70, 16, 72, 57,232, 72, 15, 66,232, 72, 3, 70, 40, -/* 0x0440 */ 72, 57,195, 72, 15, 66,216, 72,131,198, 56,235,219, 72,129,229, -/* 0x0450 */ 0,240,255,255, 72, 41,235, 72,129,195,255, 15, 0, 0, 72,129, -/* 0x0460 */ 227, 0,240,255,255,246,193, 16,116, 5, 72,137,239,235, 19, 72, -/* 0x0470 */ 133,237,117, 14,137,200, 76,137,199,131,200, 16, 77,133,192, 15, -/* 0x0480 */ 69,200, 49,210, 69, 49,201, 65,131,200,255, 72,137,222,232,128, -/* 0x0490 */ 253,255,255, 72,139, 84, 36, 64, 72,137,199, 72,141, 4, 3, 73, -/* 0x04a0 */ 137,255,199, 68, 36, 20, 0, 0, 0, 0, 73, 41,239, 72,137, 68, -/* 0x04b0 */ 36, 72,102,131,122, 56, 0, 15,132,253, 1, 0, 0, 72,131,124, -/* 0x04c0 */ 36, 56, 0,116, 35, 65,131, 60, 36, 6,117, 28, 73,139, 84, 36, -/* 0x04d0 */ 16, 72,139,124, 36, 40,190, 3, 0, 0, 0, 76, 1,250,232,178, -/* 0x04e0 */ 254,255,255,233,183, 1, 0, 0, 65,131, 60, 36, 1, 15,133,172, -/* 0x04f0 */ 1, 0, 0, 72,131,124, 36, 56, 0,116, 90, 73,131,124, 36, 8, -/* 0x0500 */ 0,117, 82, 72,139, 68, 36, 64, 73,139, 84, 36, 16,190, 3, 0, -/* 0x0510 */ 0, 0, 72,139,124, 36, 40, 76, 1,250, 72, 3, 80, 32,232,114, -/* 0x0520 */ 254,255,255, 72,139, 68, 36, 64, 72,139,124, 36, 40,190, 5, 0, -/* 0x0530 */ 0, 0, 72, 15,183, 80, 56,232, 89,254,255,255, 72,139, 68, 36, -/* 0x0540 */ 64, 72,139,124, 36, 40,190, 4, 0, 0, 0, 72, 15,183, 80, 54, -/* 0x0550 */ 232, 64,254,255,255, 73,139, 68, 36, 16, 65,139, 76, 36, 4, 65, -/* 0x0560 */ 190, 64, 98, 81,115, 65,131,200,255, 73,139, 84, 36, 32, 76, 1, -/* 0x0570 */ 248,131,225, 7, 72,137,197, 72,137, 68, 36, 88, 73,139, 68, 36, -/* 0x0580 */ 40,193,225, 2, 72,137,235, 72,137, 84, 36, 80,129,227,255, 15, -/* 0x0590 */ 0, 0, 65,211,238,185, 50, 0, 0, 0, 72, 1,232, 65,131,230, -/* 0x05a0 */ 7, 72, 41,221, 72,137, 68, 36, 8, 73,139, 68, 36, 8, 76,141, -/* 0x05b0 */ 44, 26, 72, 41,216, 72,131,124, 36, 56, 0,117, 7, 68,139, 68, -/* 0x05c0 */ 36, 52,177, 18, 68,137,242, 73,137,193, 76,137,238,131,202, 2, -/* 0x05d0 */ 72,131,124, 36, 56, 0, 72,137,239, 65, 15, 68,214,232, 49,252, -/* 0x05e0 */ 255,255, 72, 57,197,117,121, 72,131,124, 36, 56, 0,116, 25, 72, -/* 0x05f0 */ 139, 76, 36, 24, 72,139, 84, 36, 32, 72,141,116, 36, 80, 72,139, -/* 0x0600 */ 124, 36, 56,232,124,252,255,255, 76,137,235, 72,247,219,129,227, -/* 0x0610 */ 255, 15, 0, 0, 65,246,198, 2,116, 13, 74,141,124, 45, 0, 49, -/* 0x0620 */ 192, 72,137,217,252,243,170, 72,131,124, 36, 56, 0,116, 59, 73, -/* 0x0630 */ 131,124, 36, 8, 0,117, 23, 72,139,124, 36, 40, 72,141, 85, 12, -/* 0x0640 */ 199, 69, 12, 15, 5,195,144, 49,246,232, 71,253,255,255, 68,137, -/* 0x0650 */ 242, 76,137,238, 72,137,239,232,226,251,255,255,133,192,116, 10, -/* 0x0660 */ 191,127, 0, 0, 0,232,192,251,255,255, 73,141, 68, 29, 0, 72, -/* 0x0670 */ 1,197, 72, 59,108, 36, 8,115, 38, 72, 41,108, 36, 8, 69, 49, -/* 0x0680 */ 201, 65,131,200,255, 72,139,116, 36, 8,185, 50, 0, 0, 0, 68, -/* 0x0690 */ 137,242, 72,137,239,232,121,251,255,255, 72, 57,197,117,193, 72, -/* 0x06a0 */ 139, 84, 36, 64,255, 68, 36, 20, 73,131,196, 56, 15,183, 66, 56, -/* 0x06b0 */ 57, 68, 36, 20, 15,140, 3,254,255,255, 72,139,132, 36,160, 0, -/* 0x06c0 */ 0, 0, 72,139, 84, 36, 64, 76,137, 56, 76, 3,122, 24, 72,131, -/* 0x06d0 */ 196,104, 91, 93, 65, 92, 65, 93, 65, 94, 76,137,248, 65, 95,195, -/* 0x06e0 */ 65, 87, 65, 86, 73,137,206, 49,201, 65, 85, 65, 84, 77,137,204, -/* 0x06f0 */ 85, 72,137,213, 76,141,109, 64, 83, 76,137,195, 72,131,236, 72, -/* 0x0700 */ 139, 7, 72,137,124, 36, 24, 72,137,124, 36, 40, 76,141,188, 36, -/* 0x0710 */ 128, 0, 0, 0, 72,137,116, 36, 32, 72,141,116, 36, 48, 72,137, -/* 0x0720 */ 84, 36, 56, 76,137,194, 72,137, 68, 36, 48,139, 71, 4, 72,141, -/* 0x0730 */ 124, 36, 16, 72,137, 68, 36, 16,232, 71,251,255,255, 65, 83, 77, -/* 0x0740 */ 137,225, 49,210, 73,137,216, 76,137,241, 72,137,239, 72,141,116, -/* 0x0750 */ 36, 40, 65, 87,232,110,252,255,255,190, 9, 0, 0, 0, 72,137, -/* 0x0760 */ 194, 76,137,247, 73,137,196,232, 41,252,255,255, 65, 89, 65, 90, -/* 0x0770 */ 102,131,125, 56, 0,199, 68, 36, 12, 0, 0, 0, 0, 15,132,143, -/* 0x0780 */ 0, 0, 0, 65,131,125, 0, 3,117,114, 73,139, 63, 73, 3,125, -/* 0x0790 */ 16, 49,210, 49,246,232,156,250,255,255,133,192,137,195,120, 23, -/* 0x07a0 */ 186, 0, 4, 0, 0, 72,137,238,137,199,232,151,250,255,255, 72, -/* 0x07b0 */ 61, 0, 4, 0, 0,116, 10,191,127, 0, 0, 0,232,105,250,255, -/* 0x07c0 */ 255, 73,199, 7, 0, 0, 0, 0, 65, 80, 69, 49,201, 69, 49,192, -/* 0x07d0 */ 49,201, 65, 87,137,218, 49,246, 72,137,239,232,231,251,255,255, -/* 0x07e0 */ 73,139, 23,190, 7, 0, 0, 0, 76,137,247, 73,137,196,232,162, -/* 0x07f0 */ 251,255,255,137,223,232, 56,250,255,255, 94, 95,255, 68, 36, 12, -/* 0x0800 */ 15,183, 69, 56, 73,131,197, 56, 57, 68, 36, 12, 15,130,113,255, -/* 0x0810 */ 255,255, 72,131,196, 72, 76,137,224, 91, 93, 65, 92, 65, 93, 65, -/* 0x0820 */ 94, 65, 95,195 +/* 0x03d0 */ 73,137,254, 65, 85, 65, 84, 73,137,252, 85, 83, 72,131,236, 88, +/* 0x03e0 */ 76, 3,103, 32,102,131,127, 16, 3, 72,137, 76, 36, 32,185, 16, +/* 0x03f0 */ 0, 0, 0, 76,137, 68, 36, 24, 72,137,116, 36, 48,137, 84, 36, +/* 0x0400 */ 44, 76,137, 76, 36, 16, 15,183, 87, 56, 15, 68,200, 72,139,132, +/* 0x0410 */ 36,144, 0, 0, 0, 76,137,230, 72,131,205,255, 49,219, 49,255, +/* 0x0420 */ 131,193, 34, 76,139, 0,255,202,120, 33,131, 62, 1,117, 22, 72, +/* 0x0430 */ 139, 70, 16, 72, 57,232, 72, 15, 66,232, 72, 3, 70, 40, 72, 57, +/* 0x0440 */ 195, 72, 15, 66,216, 72,131,198, 56,235,219, 72,129,229, 0,240, +/* 0x0450 */ 255,255, 72, 41,235, 72,129,195,255, 15, 0, 0, 72,129,227, 0, +/* 0x0460 */ 240,255,255,246,193, 16,116, 5, 72,137,239,235, 19, 72,133,237, +/* 0x0470 */ 117, 14,137,200, 76,137,199,131,200, 16, 77,133,192, 15, 69,200, +/* 0x0480 */ 69, 49,201, 65,131,200,255, 49,210, 72,137,222,232,130,253,255, +/* 0x0490 */ 255, 72,137,199, 72,141, 4, 3,199, 68, 36, 12, 0, 0, 0, 0, +/* 0x04a0 */ 73,137,253, 73, 41,237,102, 65,131,126, 56, 0, 72,137, 68, 36, +/* 0x04b0 */ 56, 15,132, 73, 2, 0, 0, 72,131,124, 36, 48, 0,116, 35, 65, +/* 0x04c0 */ 131, 60, 36, 6,117, 28, 73,139, 84, 36, 16, 72,139,124, 36, 32, +/* 0x04d0 */ 190, 3, 0, 0, 0, 76, 1,234,232,184,254,255,255,233, 7, 2, +/* 0x04e0 */ 0, 0, 65,131, 60, 36, 1, 15,133,252, 1, 0, 0, 72,131,124, +/* 0x04f0 */ 36, 48, 0,116, 75, 73,131,124, 36, 8, 0,117, 67, 73,139, 84, +/* 0x0500 */ 36, 16, 72,139,124, 36, 32,190, 3, 0, 0, 0, 76, 1,234, 73, +/* 0x0510 */ 3, 86, 32,232,125,254,255,255, 73, 15,183, 86, 56, 72,139,124, +/* 0x0520 */ 36, 32,190, 5, 0, 0, 0,232,105,254,255,255, 73, 15,183, 86, +/* 0x0530 */ 54, 72,139,124, 36, 32,190, 4, 0, 0, 0,232, 85,254,255,255, +/* 0x0540 */ 73,139, 68, 36, 16, 65,139, 76, 36, 4, 65,131,200,255,199, 68, +/* 0x0550 */ 36, 8, 64, 98, 81,115, 73,139, 84, 36, 32, 76, 1,232,131,225, +/* 0x0560 */ 7, 72,137,197, 72,137, 68, 36, 72, 73,139, 68, 36, 40, 72,137, +/* 0x0570 */ 235,193,225, 2,211,108, 36, 8,129,227,255, 15, 0, 0,131,100, +/* 0x0580 */ 36, 8, 7, 72,137, 84, 36, 64, 72, 1,232, 72, 41,221, 76,141, +/* 0x0590 */ 60, 26, 72,137, 4, 36,185, 50, 0, 0, 0, 73,139, 68, 36, 8, +/* 0x05a0 */ 72, 41,216, 72,131,124, 36, 48, 0,117, 7, 68,139, 68, 36, 44, +/* 0x05b0 */ 177, 18,139, 84, 36, 8, 73,137,193, 76,137,254, 72,137,239,131, +/* 0x05c0 */ 202, 2, 72,131,124, 36, 48, 0, 15, 68, 84, 36, 8,232, 65,252, +/* 0x05d0 */ 255,255, 72, 57,197, 15,133,210, 0, 0, 0, 72,131,124, 36, 48, +/* 0x05e0 */ 0,116, 25, 72,139, 76, 36, 16, 72,139, 84, 36, 24, 72,141,116, +/* 0x05f0 */ 36, 64, 72,139,124, 36, 48,232,136,252,255,255, 76,137,251, 72, +/* 0x0600 */ 247,219,129,227,255, 15, 0, 0,246, 68, 36, 8, 2,116, 13, 74, +/* 0x0610 */ 141,124, 61, 0, 49,192, 72,137,217,252,243,170, 72,131,124, 36, +/* 0x0620 */ 48, 0, 15,132,143, 0, 0, 0, 72,184,255,255,255,255, 1, 0, +/* 0x0630 */ 0, 0, 73, 35, 4, 36, 72,186, 1, 0, 0, 0, 1, 0, 0, 0, +/* 0x0640 */ 72, 57,208,117, 85, 73,139, 84, 36, 40, 73,139,116, 36, 16, 73, +/* 0x0650 */ 59, 84, 36, 32, 72,141, 4, 50, 74,141, 12, 40,117, 14,137,200, +/* 0x0660 */ 247,216, 37,255, 15, 0, 0,131,248, 3,119, 20, 76,137,232, 72, +/* 0x0670 */ 193,224, 6, 73,131,124, 36, 8, 0, 72,141, 76, 6, 12,117, 26, +/* 0x0680 */ 72,133,201,199, 1, 15, 5,195,144,116, 15, 72,139,124, 36, 32, +/* 0x0690 */ 72,137,202, 49,246,232,251,252,255,255,139, 84, 36, 8, 76,137, +/* 0x06a0 */ 254, 72,137,239,232,149,251,255,255,133,192,116, 10,191,127, 0, +/* 0x06b0 */ 0, 0,232,115,251,255,255, 73,141, 4, 31, 72, 1,197, 72, 59, +/* 0x06c0 */ 44, 36,115, 37, 72, 41, 44, 36,139, 84, 36, 8, 69, 49,201, 72, +/* 0x06d0 */ 139, 52, 36, 65,131,200,255,185, 50, 0, 0, 0, 72,137,239,232, +/* 0x06e0 */ 47,251,255,255, 72, 57,197,117,196,255, 68, 36, 12, 65, 15,183, +/* 0x06f0 */ 70, 56, 73,131,196, 56, 57, 68, 36, 12, 15,140,183,253,255,255, +/* 0x0700 */ 72,139,132, 36,144, 0, 0, 0, 76,137, 40, 77, 3,110, 24, 72, +/* 0x0710 */ 131,196, 88, 91, 93, 65, 92, 76,137,232, 65, 93, 65, 94, 65, 95, +/* 0x0720 */ 195, 65, 87, 65, 86, 73,137,206, 49,201, 65, 85, 65, 84, 77,137, +/* 0x0730 */ 204, 85, 72,137,213, 76,141,109, 64, 83, 76,137,195, 72,131,236, +/* 0x0740 */ 72,139, 7, 72,137,124, 36, 24, 72,137,124, 36, 40, 76,141,188, +/* 0x0750 */ 36,128, 0, 0, 0, 72,137,116, 36, 32, 72,141,116, 36, 48, 72, +/* 0x0760 */ 137, 84, 36, 56, 76,137,194, 72,137, 68, 36, 48,139, 71, 4, 72, +/* 0x0770 */ 141,124, 36, 16, 72,137, 68, 36, 16,232, 6,251,255,255, 65, 83, +/* 0x0780 */ 77,137,225, 49,210, 73,137,216, 76,137,241, 72,137,239, 72,141, +/* 0x0790 */ 116, 36, 40, 65, 87,232, 45,252,255,255,190, 9, 0, 0, 0, 72, +/* 0x07a0 */ 137,194, 76,137,247, 73,137,196,232,232,251,255,255, 65, 89, 65, +/* 0x07b0 */ 90,102,131,125, 56, 0,199, 68, 36, 12, 0, 0, 0, 0, 15,132, +/* 0x07c0 */ 143, 0, 0, 0, 65,131,125, 0, 3,117,114, 73,139, 63, 73, 3, +/* 0x07d0 */ 125, 16, 49,210, 49,246,232, 91,250,255,255,133,192,137,195,120, +/* 0x07e0 */ 23,186, 0, 4, 0, 0, 72,137,238,137,199,232, 86,250,255,255, +/* 0x07f0 */ 72, 61, 0, 4, 0, 0,116, 10,191,127, 0, 0, 0,232, 40,250, +/* 0x0800 */ 255,255, 73,199, 7, 0, 0, 0, 0, 65, 80, 69, 49,201, 69, 49, +/* 0x0810 */ 192, 49,201, 65, 87,137,218, 49,246, 72,137,239,232,166,251,255, +/* 0x0820 */ 255, 73,139, 23,190, 7, 0, 0, 0, 76,137,247, 73,137,196,232, +/* 0x0830 */ 97,251,255,255,137,223,232,247,249,255,255, 94, 95,255, 68, 36, +/* 0x0840 */ 12, 15,183, 69, 56, 73,131,197, 56, 57, 68, 36, 12, 15,130,113, +/* 0x0850 */ 255,255,255, 72,131,196, 72, 76,137,224, 91, 93, 65, 92, 65, 93, +/* 0x0860 */ 65, 94, 65, 95,195 }; diff --git a/src/stub/src/amd64-linux.elf-main.c b/src/stub/src/amd64-linux.elf-main.c index 8b23cb04..8fa2bb84 100644 --- a/src/stub/src/amd64-linux.elf-main.c +++ b/src/stub/src/amd64-linux.elf-main.c @@ -213,7 +213,35 @@ ERR_LAB } } -#if defined(__powerpc64__) //{ +#if defined(__x86_64__) //{ +static void * +make_hatch_x86_64( + Elf64_Phdr const *const phdr, + Elf64_Addr reloc, + unsigned const frag_mask +) +{ + unsigned *hatch = 0; + DPRINTF("make_hatch %%p %%x %%x\\n",phdr,reloc,frag_mask); + if (phdr->p_type==PT_LOAD && phdr->p_flags & PF_X) { + // Try page fragmentation just beyond .text . + if ( ( (hatch = (void *)(phdr->p_memsz + phdr->p_vaddr + reloc)), + ( phdr->p_memsz==phdr->p_filesz // don't pollute potential .bss + && (1*4)<=(frag_mask & -(int)(size_t)hatch) ) ) // space left on page + // Try Elf64_Ehdr.e_ident[12..15] . warning: 'const' cast away + || ( (hatch = (void *)(&((Elf64_Ehdr *)phdr->p_vaddr + reloc)->e_ident[12])), + (phdr->p_offset==0) ) + ) + { + hatch[0] = 0x90c3050f; // syscall; ret; nop + } + else { + hatch = 0; + } + } + return hatch; +} +#elif defined(__powerpc64__) //}{ static void * make_hatch_ppc64( Elf64_Phdr const *const phdr, @@ -430,23 +458,15 @@ do_xmap( } if (xi) { #if defined(__x86_64) //{ - if (0==phdr->p_offset) { - Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)addr; - *(int *)&ehdr->e_ident[12] = 0x90c3050f; // syscall; ret; nop - auxv_up(av, AT_NULL, (uint64_t)&ehdr->e_ident[12]); - } + void *const hatch = make_hatch_x86_64(phdr, reloc, ~PAGE_MASK); #elif defined(__powerpc64__) //}{ void *const hatch = make_hatch_ppc64(phdr, reloc, ~PAGE_MASK); - if (0!=hatch) { - auxv_up(av, AT_NULL, (size_t)hatch); - } #elif defined(__aarch64__) //}{ void *const hatch = make_hatch_arm64(phdr, reloc, ~PAGE_MASK); +#endif //} if (0!=hatch) { auxv_up(av, AT_NULL, (size_t)hatch); } - -#endif //} if (0!=mprotect(addr, mlen, prot)) { err_exit(10); ERR_LAB diff --git a/src/stub/tmp/amd64-linux.elf-fold.map b/src/stub/tmp/amd64-linux.elf-fold.map index 95912bec..81eb1e45 100644 --- a/src/stub/tmp/amd64-linux.elf-fold.map +++ b/src/stub/tmp/amd64-linux.elf-fold.map @@ -8,7 +8,7 @@ Linker script and memory map 0x00000000001000bc . = ((0x100000 + SIZEOF_HEADERS) + 0xc) -.text 0x00000000001000bc 0x768 +.text 0x00000000001000bc 0x7ac *(.text) .text 0x00000000001000bc 0x18e tmp/amd64-linux.elf-fold.o 0x000000000010023a munmap @@ -21,19 +21,20 @@ Linker script and memory map 0x000000000010023e mprotect 0x0000000000100232 close *fill* 0x000000000010024a 0x2 00 - .text 0x000000000010024c 0x5d8 tmp/amd64-linux.elf-main.o - 0x00000000001006e0 upx_main + .text 0x000000000010024c 0x619 tmp/amd64-linux.elf-main.o + 0x0000000000100721 upx_main *(.data) - .data 0x0000000000100824 0x0 tmp/amd64-linux.elf-fold.o - .data 0x0000000000100824 0x0 tmp/amd64-linux.elf-main.o + *fill* 0x0000000000100865 0x3 00 + .data 0x0000000000100868 0x0 tmp/amd64-linux.elf-fold.o + .data 0x0000000000100868 0x0 tmp/amd64-linux.elf-main.o .data -.bss 0x0000000000100824 0x0 - .bss 0x0000000000100824 0x0 tmp/amd64-linux.elf-fold.o - .bss 0x0000000000100824 0x0 tmp/amd64-linux.elf-main.o +.bss 0x0000000000100868 0x0 + .bss 0x0000000000100868 0x0 tmp/amd64-linux.elf-fold.o + .bss 0x0000000000100868 0x0 tmp/amd64-linux.elf-main.o -.rela.dyn 0x0000000000100828 0x0 +.rela.dyn 0x0000000000100868 0x0 .rela.text 0x0000000000000000 0x0 tmp/amd64-linux.elf-fold.o LOAD tmp/amd64-linux.elf-fold.o LOAD tmp/amd64-linux.elf-main.o