From 8bca8629be93ef8a312b5b4917571deca3ca8e6c Mon Sep 17 00:00:00 2001 From: John Reiser Date: Thu, 6 Apr 2017 23:08:35 -0700 Subject: [PATCH] Preserve symlink /proc/self/exe by mapping one page into the stack. modified: stub/src/amd64-linux.elf-fold.S modified: stub/amd64-linux.elf-fold.h modified: stub/tmp/amd64-linux.elf-fold.map --- src/stub/amd64-linux.elf-fold.h | 228 +++++++++++++------------- src/stub/src/amd64-linux.elf-fold.S | 85 +++++++--- src/stub/tmp/amd64-linux.elf-fold.map | 37 +++-- 3 files changed, 203 insertions(+), 147 deletions(-) diff --git a/src/stub/amd64-linux.elf-fold.h b/src/stub/amd64-linux.elf-fold.h index a383810d..90aadd5e 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, 1920 (0x780) bytes + created from amd64-linux.elf-fold.bin, 2036 (0x7f4) bytes This file is part of the UPX executable compressor. @@ -31,20 +31,20 @@ */ -#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 1920 -#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0xc4cbd98b -#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0xd4393110 +#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 2036 +#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0x9382090d +#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0x31eb4b3d -unsigned char stub_amd64_linux_elf_fold[1920] = { +unsigned char stub_amd64_linux_elf_fold[2036] = { /* 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 */ 128, 7, 0, 0, 0, 0, 0, 0,128, 7, 0, 0, 0, 0, 0, 0, +/* 0x0060 */ 244, 7, 0, 0, 0, 0, 0, 0,244, 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 */ 128, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0x0080 */ 244, 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, 89, 0, 0, @@ -53,107 +53,115 @@ unsigned char stub_amd64_linux_elf_fold[1920] = { /* 0x00e0 */ 47, 72, 57,206,115, 50, 86, 94,172, 60,128,114, 10, 60,143,119, /* 0x00f0 */ 6,128,126,254, 15,116, 6, 44,232, 60, 1,119,228, 72, 57,206, /* 0x0100 */ 115, 22, 86,173, 40,208,117,223, 95, 15,200, 41,248, 1,216,171, -/* 0x0110 */ 72, 57,206,115, 3,172,235,223, 91,195, 65, 89, 72,137,230, 72, -/* 0x0120 */ 141,190,240,239,255,255, 72,137,252,106, 6, 89,243, 72,165, 72, -/* 0x0130 */ 131, 62, 0, 72,165,117,248, 72,137,250, 72,171, 72,131, 62, 0, -/* 0x0140 */ 72,165,117,248, 87, 72,131, 62, 0, 72,165, 72,165,117,246, 76, -/* 0x0150 */ 141,127,248, 72,137, 58,184, 32, 32, 32, 61,171,186, 0, 16, 0, -/* 0x0160 */ 0, 72,137,254, 76,137,207,106, 89, 88, 15, 5,133,192,120, 4, -/* 0x0170 */ 198, 4, 6, 0, 73,131,193, 15, 89, 94, 95, 72,139, 68, 36, 16, -/* 0x0180 */ 72,129,236, 0, 8, 0, 0, 72,137,226, 73,137,232, 80,232, 87, -/* 0x0190 */ 4, 0, 0, 90, 72,129,196, 0, 8, 0, 0, 94, 95, 89, 80,106, -/* 0x01a0 */ 11, 88, 65,255, 39,176, 11,235, 13,176, 10,235, 9,176, 12,235, -/* 0x01b0 */ 5,176, 9, 73,137,202, 15,182,192, 15, 5, 72, 61, 0,240,255, -/* 0x01c0 */ 255,114, 4, 72,131,200,255,195,176, 0,235,234,176, 2,235,230, -/* 0x01d0 */ 176, 3,235,226,176, 60,235,222, 81, 72, 57, 23, 76,139, 71, 8, -/* 0x01e0 */ 72,141, 74,255,115, 10,191,127, 0, 0, 0,232,228,255,255,255, -/* 0x01f0 */ 72,131,249,255,116, 17, 65, 15,182, 0, 72,255,201, 73,255,192, -/* 0x0200 */ 136, 6, 72,255,198,235,233, 72, 1, 87, 8, 72, 41, 23, 88,195, -/* 0x0210 */ 65, 85, 73,137,213, 65, 84, 73,137,204, 85, 72,137,253, 83, 72, -/* 0x0220 */ 137,243, 72,131,236, 40, 72,131, 62, 0, 15,132,226, 0, 0, 0, -/* 0x0230 */ 72,141,116, 36, 16,186, 12, 0, 0, 0, 72,137,239,232,150,255, -/* 0x0240 */ 255,255,139, 84, 36, 16,139,116, 36, 20,133,210,117, 21,129,254, -/* 0x0250 */ 85, 80, 88, 33,117, 17, 72,131,125, 0, 0, 15,132,177, 0, 0, -/* 0x0260 */ 0,235, 4,133,246,117, 10,191,127, 0, 0, 0,232, 99,255,255, -/* 0x0270 */ 255, 57,214,119,242,137,208, 72, 59, 3,119,235, 57,214, 72,139, -/* 0x0280 */ 67, 8,115,104,137, 84, 36, 12, 72,139,125, 8, 72,141, 76, 36, -/* 0x0290 */ 12, 68,139, 68, 36, 24, 72,137,194, 65,255,213,133,192,117,199, -/* 0x02a0 */ 139,116, 36, 12, 59,116, 36, 16,117,189, 15,182, 76, 36, 25,132, -/* 0x02b0 */ 201, 15,149,194, 49,192, 77,133,228, 15,149,192,133,194,116, 30, -/* 0x02c0 */ 129,254, 0, 2, 0, 0,119, 7,137,240, 72, 57, 3,117, 15, 15, -/* 0x02d0 */ 182, 84, 36, 26, 15,182,201, 72,139,123, 8, 65,255,212,139, 68, -/* 0x02e0 */ 36, 20, 72, 1, 69, 8, 72, 41, 69, 0,235, 13,137,242, 72,137, -/* 0x02f0 */ 239, 72,137,198,232,223,254,255,255,139, 84, 36, 16, 72,139, 3, -/* 0x0300 */ 72, 1, 83, 8, 72, 41,208, 72,133,192, 72,137, 3,233, 24,255, -/* 0x0310 */ 255,255, 72,131,196, 40, 91, 93, 65, 92, 65, 93,195, 72,133,255, -/* 0x0320 */ 73,137,208,116, 41, 72,139, 7,137,241, 72, 57,200,116, 17, 72, -/* 0x0330 */ 255,200, 15,148,194, 49,192,133,246, 15,149,192,133,194,116, 8, -/* 0x0340 */ 72,137, 15, 76,137, 71, 8,195, 72,131,199, 16,235,215,195, 65, -/* 0x0350 */ 87,184, 0, 0, 0, 0, 73,137,255, 65, 86, 65, 85, 65, 84, 73, -/* 0x0360 */ 137,252, 85, 83, 72,131,236,104, 76, 3,103, 32,102,131,127, 16, -/* 0x0370 */ 3,137, 84, 36, 60, 15,183, 87, 56, 72,137, 76, 36, 48,185, 16, -/* 0x0380 */ 0, 0, 0, 72,137,116, 36, 64, 76,137, 68, 36, 40, 76,137, 76, -/* 0x0390 */ 36, 32, 15, 68,200, 76,137,230, 72,131,205,255, 49,219,131,193, -/* 0x03a0 */ 34,255,202,120, 33,131, 62, 1,117, 22, 72,139, 70, 16, 72, 57, -/* 0x03b0 */ 232, 72, 15, 66,232, 72, 3, 70, 40, 72, 57,195, 72, 15, 66,216, -/* 0x03c0 */ 72,131,198, 56,235,219, 72,129,229, 0,240,255,255, 49,210, 69, -/* 0x03d0 */ 49,201, 72, 41,235, 65,131,200,255, 72,137,239, 72,129,195,255, -/* 0x03e0 */ 15, 0, 0, 72,129,227, 0,240,255,255, 72,137,222,232,191,253, -/* 0x03f0 */ 255,255, 72,141, 20, 24, 72, 41,232,102, 65,131,127, 56, 0, 72, -/* 0x0400 */ 137, 68, 36, 24,199, 68, 36, 20, 0, 0, 0, 0, 72,137, 84, 36, -/* 0x0410 */ 72, 15,132,155, 1, 0, 0, 72,131,124, 36, 64, 0,116, 37, 65, -/* 0x0420 */ 131, 60, 36, 6,117, 30, 72,139, 84, 36, 24, 73, 3, 84, 36, 16, -/* 0x0430 */ 190, 3, 0, 0, 0, 72,139,124, 36, 48,232,222,254,255,255,233, -/* 0x0440 */ 87, 1, 0, 0, 65,131, 60, 36, 1, 15,133, 76, 1, 0, 0, 72, -/* 0x0450 */ 139, 68, 36, 24, 73, 3, 68, 36, 16, 65,190, 64, 98, 81,115, 65, -/* 0x0460 */ 139, 76, 36, 4, 65,131,200,255, 73,139, 84, 36, 32, 72,137,197, -/* 0x0470 */ 72,137, 68, 36, 88, 73,139, 68, 36, 40,131,225, 7, 72,137,235, -/* 0x0480 */ 72,137, 84, 36, 80,193,225, 2,129,227,255, 15, 0, 0, 72, 1, -/* 0x0490 */ 232, 65,211,238, 72, 41,221, 72,137, 68, 36, 8, 73,139, 68, 36, -/* 0x04a0 */ 8, 65,131,230, 7, 76,141, 44, 26,185, 50, 0, 0, 0, 72, 41, -/* 0x04b0 */ 216, 72,131,124, 36, 64, 0,117, 7, 68,139, 68, 36, 60,177, 18, -/* 0x04c0 */ 68,137,242, 73,137,193, 76,137,238,131,202, 2, 72,131,124, 36, -/* 0x04d0 */ 64, 0, 72,137,239, 65, 15, 68,214,232,211,252,255,255, 72, 57, -/* 0x04e0 */ 197,117,121, 72,131,124, 36, 64, 0,116, 25, 72,139, 76, 36, 32, -/* 0x04f0 */ 72,139, 84, 36, 40, 72,141,116, 36, 80, 72,139,124, 36, 64,232, -/* 0x0500 */ 12,253,255,255, 76,137,235, 72,247,219,129,227,255, 15, 0, 0, -/* 0x0510 */ 65,246,198, 2,116, 13, 74,141,124, 45, 0, 49,192, 72,137,217, -/* 0x0520 */ 252,243,170, 72,131,124, 36, 64, 0,116, 59, 73,131,124, 36, 8, -/* 0x0530 */ 0,117, 23, 72,139,124, 36, 48, 72,141, 85, 12,199, 69, 12, 15, -/* 0x0540 */ 5,195,144, 49,246,232,211,253,255,255, 68,137,242, 76,137,238, -/* 0x0550 */ 72,137,239,232, 81,252,255,255,133,192,116, 10,191,127, 0, 0, -/* 0x0560 */ 0,232,110,252,255,255, 73,141, 68, 29, 0, 72, 1,197, 72, 59, -/* 0x0570 */ 108, 36, 8,115, 38, 72, 41,108, 36, 8, 69, 49,201, 65,131,200, -/* 0x0580 */ 255, 72,139,116, 36, 8,185, 50, 0, 0, 0, 68,137,242, 72,137, -/* 0x0590 */ 239,232, 27,252,255,255, 72, 57,197,117,193,255, 68, 36, 20, 65, -/* 0x05a0 */ 15,183, 71, 56, 73,131,196, 56, 57, 68, 36, 20, 15,140,101,254, -/* 0x05b0 */ 255,255, 72,131,188, 36,160, 0, 0, 0, 0,116, 16, 72,139, 68, -/* 0x05c0 */ 36, 24, 72,139,148, 36,160, 0, 0, 0, 72,137, 2, 73,139, 87, -/* 0x05d0 */ 24, 72, 1, 84, 36, 24, 72,139, 68, 36, 24, 72,131,196,104, 91, -/* 0x05e0 */ 93, 65, 92, 65, 93, 65, 94, 65, 95,195, 65, 87, 77,137,207, 65, -/* 0x05f0 */ 86, 65, 85, 77,137,197, 65, 84, 73,137,212, 85, 72,141,106, 64, -/* 0x0600 */ 83, 72,137,203, 49,201, 72,131,236, 56,139, 7, 72,137, 52, 36, -/* 0x0610 */ 72,137,116, 36, 16, 72,141,116, 36, 32, 72,137, 84, 36, 40, 72, -/* 0x0620 */ 137,124, 36, 8, 76,137,194, 72,137,124, 36, 24, 72,137,231, 72, -/* 0x0630 */ 137, 68, 36, 32,232,215,251,255,255, 72,139, 85, 16,190, 3, 0, -/* 0x0640 */ 0, 0, 72,137,223, 72,131,194, 64,232,207,252,255,255, 73, 15, -/* 0x0650 */ 183, 84, 36, 56,190, 5, 0, 0, 0, 72,137,223,232,188,252,255, -/* 0x0660 */ 255, 69, 15,183,116, 36, 16, 65,131,254, 3,117, 62, 72,139, 84, -/* 0x0670 */ 36,112, 73, 3, 84, 36, 24,190, 9, 0, 0, 0,102, 65,199, 68, -/* 0x0680 */ 36, 16, 2, 0, 72,137,223,232,145,252,255,255, 65, 15,183, 68, -/* 0x0690 */ 36, 56,133,192,116, 21, 72,139, 84, 36,112, 72, 1, 85, 16, 72, -/* 0x06a0 */ 1, 85, 24, 72,131,197, 56,255,200,117,240, 65, 83, 77,137,249, -/* 0x06b0 */ 77,137,232, 49,210, 72,137,217, 72,141, 68, 36,120, 72,141,116, -/* 0x06c0 */ 36, 24, 76,137,231, 80,232,132,252,255,255, 65, 89, 65,131,254, -/* 0x06d0 */ 3, 73,137,197, 65, 90,116, 16, 72,137,194,190, 9, 0, 0, 0, -/* 0x06e0 */ 72,137,223,232, 53,252,255,255, 69, 49,246,102, 65,131,124, 36, -/* 0x06f0 */ 56, 0, 73,141,108, 36, 64,116,117,131,125, 0, 3,117, 93, 72, -/* 0x0700 */ 139,124, 36,112, 72, 3,125, 16, 49,210, 49,246,232,187,250,255, -/* 0x0710 */ 255,133,192,137,195,120, 23,186, 0, 4, 0, 0, 76,137,230,137, -/* 0x0720 */ 199,232,162,250,255,255, 72, 61, 0, 4, 0, 0,116, 10,191,127, -/* 0x0730 */ 0, 0, 0,232,156,250,255,255, 65, 80, 49,246, 69, 49,201, 69, -/* 0x0740 */ 49,192, 49,201,106, 0,137,218, 76,137,231,232,255,251,255,255, -/* 0x0750 */ 137,223, 73,137,197,232,118,250,255,255, 94, 95, 65, 15,183, 68, -/* 0x0760 */ 36, 56, 65,255,198, 72,131,197, 56, 65, 57,198,114,139, 72,131, -/* 0x0770 */ 196, 56, 76,137,232, 91, 93, 65, 92, 65, 93, 65, 94, 65, 95,195 +/* 0x0110 */ 72, 57,206,115, 3,172,235,223, 91,195, 91, 72,141, 67, 15, 80, +/* 0x0120 */ 72,137,230, 72,129,236, 0, 48, 0, 0, 84, 95,106, 7, 89,243, +/* 0x0130 */ 72,165, 72,131, 62, 0, 72,165,117,248, 73,137,254, 72,171, 72, +/* 0x0140 */ 131, 62, 0, 72,165,117,248, 73,137,252, 72,131, 62, 0, 72,165, +/* 0x0150 */ 72,165,117,246, 73,137,255, 73,137,245, 77, 41,252,106, 89,186, +/* 0x0160 */ 255, 15, 0, 0, 87, 94, 83, 95, 88, 15, 5,133,192,121, 5, 83, +/* 0x0170 */ 94,106, 14, 88,145,253, 73,141,125,255,176, 0,170, 72,141,116, +/* 0x0180 */ 14,255,243,164, 72,131,239, 3,199, 7, 32, 32, 32, 61, 73,137, +/* 0x0190 */ 62, 72,193,239, 12, 72,255,207, 72,193,231, 12, 73,137,254,106, +/* 0x01a0 */ 2, 41,246, 83, 95, 88, 15, 5,147,106, 9, 69, 41,201, 65,137, +/* 0x01b0 */ 216,106, 18, 65, 90,106, 1, 90,190, 0, 16, 0, 0, 65, 86, 95, +/* 0x01c0 */ 88, 15, 5,106, 3,137,223, 88, 15, 5, 73,141,119,248, 73,141, +/* 0x01d0 */ 126,248, 76,137,249, 72, 41,225, 72,193,233, 3,243, 72,165, 72, +/* 0x01e0 */ 141,103, 8,252, 75,141, 12, 38, 65, 89, 94, 95, 72,139, 68, 36, +/* 0x01f0 */ 16, 72,129,236, 0, 8, 0, 0, 72,137,226, 73,137,232, 80,232, +/* 0x0200 */ 90, 4, 0, 0, 90, 72,129,196, 0, 8, 0, 0, 94, 95, 89, 80, +/* 0x0210 */ 106, 11, 88, 65,255,102,248,176, 11,235, 13,176, 10,235, 9,176, +/* 0x0220 */ 12,235, 5,176, 9, 73,137,202, 15,182,192, 15, 5, 72, 61, 0, +/* 0x0230 */ 240,255,255,114, 4, 72,131,200,255,195,176, 0,235,234,176, 2, +/* 0x0240 */ 235,230,176, 3,235,226,176, 60,235,222, 0, 0, 81, 72, 57, 23, +/* 0x0250 */ 76,139, 71, 8, 72,141, 74,255,115, 10,191,127, 0, 0, 0,232, +/* 0x0260 */ 226,255,255,255, 72,131,249,255,116, 17, 65, 15,182, 0, 72,255, +/* 0x0270 */ 201, 73,255,192,136, 6, 72,255,198,235,233, 72, 1, 87, 8, 72, +/* 0x0280 */ 41, 23, 88,195, 65, 85, 73,137,213, 65, 84, 73,137,204, 85, 72, +/* 0x0290 */ 137,253, 83, 72,137,243, 72,131,236, 40, 72,131, 62, 0, 15,132, +/* 0x02a0 */ 226, 0, 0, 0, 72,141,116, 36, 16,186, 12, 0, 0, 0, 72,137, +/* 0x02b0 */ 239,232,150,255,255,255,139, 84, 36, 16,139,116, 36, 20,133,210, +/* 0x02c0 */ 117, 21,129,254, 85, 80, 88, 33,117, 17, 72,131,125, 0, 0, 15, +/* 0x02d0 */ 132,177, 0, 0, 0,235, 4,133,246,117, 10,191,127, 0, 0, 0, +/* 0x02e0 */ 232, 97,255,255,255, 57,214,119,242,137,208, 72, 59, 3,119,235, +/* 0x02f0 */ 57,214, 72,139, 67, 8,115,104,137, 84, 36, 12, 72,139,125, 8, +/* 0x0300 */ 72,141, 76, 36, 12, 68,139, 68, 36, 24, 72,137,194, 65,255,213, +/* 0x0310 */ 133,192,117,199,139,116, 36, 12, 59,116, 36, 16,117,189, 15,182, +/* 0x0320 */ 76, 36, 25,132,201, 15,149,194, 49,192, 77,133,228, 15,149,192, +/* 0x0330 */ 133,194,116, 30,129,254, 0, 2, 0, 0,119, 7,137,240, 72, 57, +/* 0x0340 */ 3,117, 15, 15,182, 84, 36, 26, 15,182,201, 72,139,123, 8, 65, +/* 0x0350 */ 255,212,139, 68, 36, 20, 72, 1, 69, 8, 72, 41, 69, 0,235, 13, +/* 0x0360 */ 137,242, 72,137,239, 72,137,198,232,223,254,255,255,139, 84, 36, +/* 0x0370 */ 16, 72,139, 3, 72, 1, 83, 8, 72, 41,208, 72,133,192, 72,137, +/* 0x0380 */ 3,233, 24,255,255,255, 72,131,196, 40, 91, 93, 65, 92, 65, 93, +/* 0x0390 */ 195, 72,133,255, 73,137,208,116, 41, 72,139, 7,137,241, 72, 57, +/* 0x03a0 */ 200,116, 17, 72,255,200, 15,148,194, 49,192,133,246, 15,149,192, +/* 0x03b0 */ 133,194,116, 8, 72,137, 15, 76,137, 71, 8,195, 72,131,199, 16, +/* 0x03c0 */ 235,215,195, 65, 87,184, 0, 0, 0, 0, 73,137,255, 65, 86, 65, +/* 0x03d0 */ 85, 65, 84, 73,137,252, 85, 83, 72,131,236,104, 76, 3,103, 32, +/* 0x03e0 */ 102,131,127, 16, 3,137, 84, 36, 60, 15,183, 87, 56, 72,137, 76, +/* 0x03f0 */ 36, 48,185, 16, 0, 0, 0, 72,137,116, 36, 64, 76,137, 68, 36, +/* 0x0400 */ 40, 76,137, 76, 36, 32, 15, 68,200, 76,137,230, 72,131,205,255, +/* 0x0410 */ 49,219,131,193, 34,255,202,120, 33,131, 62, 1,117, 22, 72,139, +/* 0x0420 */ 70, 16, 72, 57,232, 72, 15, 66,232, 72, 3, 70, 40, 72, 57,195, +/* 0x0430 */ 72, 15, 66,216, 72,131,198, 56,235,219, 72,129,229, 0,240,255, +/* 0x0440 */ 255, 49,210, 69, 49,201, 72, 41,235, 65,131,200,255, 72,137,239, +/* 0x0450 */ 72,129,195,255, 15, 0, 0, 72,129,227, 0,240,255,255, 72,137, +/* 0x0460 */ 222,232,189,253,255,255, 72,141, 20, 24, 72, 41,232,102, 65,131, +/* 0x0470 */ 127, 56, 0, 72,137, 68, 36, 24,199, 68, 36, 20, 0, 0, 0, 0, +/* 0x0480 */ 72,137, 84, 36, 72, 15,132,155, 1, 0, 0, 72,131,124, 36, 64, +/* 0x0490 */ 0,116, 37, 65,131, 60, 36, 6,117, 30, 72,139, 84, 36, 24, 73, +/* 0x04a0 */ 3, 84, 36, 16,190, 3, 0, 0, 0, 72,139,124, 36, 48,232,222, +/* 0x04b0 */ 254,255,255,233, 87, 1, 0, 0, 65,131, 60, 36, 1, 15,133, 76, +/* 0x04c0 */ 1, 0, 0, 72,139, 68, 36, 24, 73, 3, 68, 36, 16, 65,190, 64, +/* 0x04d0 */ 98, 81,115, 65,139, 76, 36, 4, 65,131,200,255, 73,139, 84, 36, +/* 0x04e0 */ 32, 72,137,197, 72,137, 68, 36, 88, 73,139, 68, 36, 40,131,225, +/* 0x04f0 */ 7, 72,137,235, 72,137, 84, 36, 80,193,225, 2,129,227,255, 15, +/* 0x0500 */ 0, 0, 72, 1,232, 65,211,238, 72, 41,221, 72,137, 68, 36, 8, +/* 0x0510 */ 73,139, 68, 36, 8, 65,131,230, 7, 76,141, 44, 26,185, 50, 0, +/* 0x0520 */ 0, 0, 72, 41,216, 72,131,124, 36, 64, 0,117, 7, 68,139, 68, +/* 0x0530 */ 36, 60,177, 18, 68,137,242, 73,137,193, 76,137,238,131,202, 2, +/* 0x0540 */ 72,131,124, 36, 64, 0, 72,137,239, 65, 15, 68,214,232,209,252, +/* 0x0550 */ 255,255, 72, 57,197,117,121, 72,131,124, 36, 64, 0,116, 25, 72, +/* 0x0560 */ 139, 76, 36, 32, 72,139, 84, 36, 40, 72,141,116, 36, 80, 72,139, +/* 0x0570 */ 124, 36, 64,232, 12,253,255,255, 76,137,235, 72,247,219,129,227, +/* 0x0580 */ 255, 15, 0, 0, 65,246,198, 2,116, 13, 74,141,124, 45, 0, 49, +/* 0x0590 */ 192, 72,137,217,252,243,170, 72,131,124, 36, 64, 0,116, 59, 73, +/* 0x05a0 */ 131,124, 36, 8, 0,117, 23, 72,139,124, 36, 48, 72,141, 85, 12, +/* 0x05b0 */ 199, 69, 12, 15, 5,195,144, 49,246,232,211,253,255,255, 68,137, +/* 0x05c0 */ 242, 76,137,238, 72,137,239,232, 79,252,255,255,133,192,116, 10, +/* 0x05d0 */ 191,127, 0, 0, 0,232,108,252,255,255, 73,141, 68, 29, 0, 72, +/* 0x05e0 */ 1,197, 72, 59,108, 36, 8,115, 38, 72, 41,108, 36, 8, 69, 49, +/* 0x05f0 */ 201, 65,131,200,255, 72,139,116, 36, 8,185, 50, 0, 0, 0, 68, +/* 0x0600 */ 137,242, 72,137,239,232, 25,252,255,255, 72, 57,197,117,193,255, +/* 0x0610 */ 68, 36, 20, 65, 15,183, 71, 56, 73,131,196, 56, 57, 68, 36, 20, +/* 0x0620 */ 15,140,101,254,255,255, 72,131,188, 36,160, 0, 0, 0, 0,116, +/* 0x0630 */ 16, 72,139, 68, 36, 24, 72,139,148, 36,160, 0, 0, 0, 72,137, +/* 0x0640 */ 2, 73,139, 87, 24, 72, 1, 84, 36, 24, 72,139, 68, 36, 24, 72, +/* 0x0650 */ 131,196,104, 91, 93, 65, 92, 65, 93, 65, 94, 65, 95,195, 65, 87, +/* 0x0660 */ 77,137,207, 65, 86, 65, 85, 77,137,197, 65, 84, 73,137,212, 85, +/* 0x0670 */ 72,141,106, 64, 83, 72,137,203, 49,201, 72,131,236, 56,139, 7, +/* 0x0680 */ 72,137, 52, 36, 72,137,116, 36, 16, 72,141,116, 36, 32, 72,137, +/* 0x0690 */ 84, 36, 40, 72,137,124, 36, 8, 76,137,194, 72,137,124, 36, 24, +/* 0x06a0 */ 72,137,231, 72,137, 68, 36, 32,232,215,251,255,255, 72,139, 85, +/* 0x06b0 */ 16,190, 3, 0, 0, 0, 72,137,223, 72,131,194, 64,232,207,252, +/* 0x06c0 */ 255,255, 73, 15,183, 84, 36, 56,190, 5, 0, 0, 0, 72,137,223, +/* 0x06d0 */ 232,188,252,255,255, 69, 15,183,116, 36, 16, 65,131,254, 3,117, +/* 0x06e0 */ 62, 72,139, 84, 36,112, 73, 3, 84, 36, 24,190, 9, 0, 0, 0, +/* 0x06f0 */ 102, 65,199, 68, 36, 16, 2, 0, 72,137,223,232,145,252,255,255, +/* 0x0700 */ 65, 15,183, 68, 36, 56,133,192,116, 21, 72,139, 84, 36,112, 72, +/* 0x0710 */ 1, 85, 16, 72, 1, 85, 24, 72,131,197, 56,255,200,117,240, 65, +/* 0x0720 */ 83, 77,137,249, 77,137,232, 49,210, 72,137,217, 72,141, 68, 36, +/* 0x0730 */ 120, 72,141,116, 36, 24, 76,137,231, 80,232,132,252,255,255, 65, +/* 0x0740 */ 89, 65,131,254, 3, 73,137,197, 65, 90,116, 16, 72,137,194,190, +/* 0x0750 */ 9, 0, 0, 0, 72,137,223,232, 53,252,255,255, 69, 49,246,102, +/* 0x0760 */ 65,131,124, 36, 56, 0, 73,141,108, 36, 64,116,117,131,125, 0, +/* 0x0770 */ 3,117, 93, 72,139,124, 36,112, 72, 3,125, 16, 49,210, 49,246, +/* 0x0780 */ 232,185,250,255,255,133,192,137,195,120, 23,186, 0, 4, 0, 0, +/* 0x0790 */ 76,137,230,137,199,232,160,250,255,255, 72, 61, 0, 4, 0, 0, +/* 0x07a0 */ 116, 10,191,127, 0, 0, 0,232,154,250,255,255, 65, 80, 49,246, +/* 0x07b0 */ 69, 49,201, 69, 49,192, 49,201,106, 0,137,218, 76,137,231,232, +/* 0x07c0 */ 255,251,255,255,137,223, 73,137,197,232,116,250,255,255, 94, 95, +/* 0x07d0 */ 65, 15,183, 68, 36, 56, 65,255,198, 72,131,197, 56, 65, 57,198, +/* 0x07e0 */ 114,139, 72,131,196, 56, 76,137,232, 91, 93, 65, 92, 65, 93, 65, +/* 0x07f0 */ 94, 65, 95,195 }; diff --git a/src/stub/src/amd64-linux.elf-fold.S b/src/stub/src/amd64-linux.elf-fold.S index 01057f80..0f808204 100644 --- a/src/stub/src/amd64-linux.elf-fold.S +++ b/src/stub/src/amd64-linux.elf-fold.S @@ -40,6 +40,13 @@ sz_b_info= 12 sz_l_info= 12 sz_p_info= 12 +MAP_PRIVATE= 0x02 +MAP_FIXED= 0x10 + +PROT_READ= 0x1 + +O_RDONLY= 0 + OVERHEAD=2048 MAX_ELF_HDR=1024 @@ -68,33 +75,73 @@ L90a: L90b: #include "arch/amd64/bxx.S" L90: - pop %arg6 # L90a; later, &amdbxx: f_unfilter - movq %rsp,%rsi - leaq -8 -4 -4 -4096(%rsi),%rdi # 8:ptr, 4:" =", 4:align, 4096:buffer - movq %rdi,%rsp - push $6; pop %rcx; rep movsq # move LENX,ADRX,LENU,ADRU,slide,argc + pop %rbx # L90a + lea L90b - L90a(%rbx),%rax; push %rax # &amdbxx: f_unfilter + mov %rsp,%rsi + sub $3*4096,%rsp + push %rsp; pop %rdi + push $7; pop %rcx; rep movsq # f_unfilter,LENX,ADRX,LENU,ADRU,slide,argc 0: cmpq $0,(%rsi); movsq; jne 0b # move past argv - movq %rdi,%arg3 # remember &new_env[0] + movq %rdi,%r14 # remember &new_env[0] stosq # space for new_env[0] 0: cmpq $0,(%rsi); movsq; jne 0b # move past env - pushq %rdi # &Elf64_auxv + mov %rdi,%r12 # &old Elf64_auxv 0: cmpq $0,(%rsi); movsq; movsq; jne 0b # move past auxv - lea -8(%rdi),%r15 # &auxv[N].a_un + mov %rdi,%r15 # beyond auxv + mov %rsi,%r13 # beginning of strings + sub %r15,%r12 # -length of auxv - movq %rdi,(%arg3) # new_env[0] - movl $('='<<24)|(' '<<16)|(' '<<8)|(' '<<0),%eax # " =" - stosl - movl $4096,%arg3l # buflen - movq %rdi,%arg2 # buffer - movq %arg6,%arg1 # "/proc/self/exe" - push $ __NR_readlink; pop %rax - syscall; testl %eax,%eax; js 0f; movb $0,(%arg2,%rax) + push $ __NR_readlink + movl $-1+ 4096,%arg3l # buflen + push %rdi; pop %arg2 #buffer + push %rbx; pop %arg1 # "/proc/self/exe" + pop %rax; syscall; testl %eax,%eax; jns 0f +// readlink() failed. Set the result equal to the argument. + push %rbx; pop %arg2 # result= "/proc/self/exe" + push $-1+ (L90b - L90a); pop %rax 0: - addq $ L90b - L90a,%arg6 # &amdbxx: f_unfilter - pop %arg4 # &Elf64_auxv + xchg %eax,%ecx # %ecx= byte count + std + lea -1(%r13),%rdi # dst last byte + movb $0,%al; stosb # terminate + lea -1(%arg2,%rcx),%rsi # src last byte + rep movsb # slide up + sub $3,%rdi; movl $('='<<24)|(' '<<16)|(' '<<8)|(' '<<0),(%rdi) # env var name + mov %rdi,(%r14) # new_env[0] + shr $12,%rdi; dec %rdi; shl $12,%rdi; mov %rdi,%r14 # &page + + push $__NR_open + sub %arg2l,%arg2l # O_RDONLY + push %rbx; pop %arg1 # "/proc/self/exe" + pop %rax; syscall; xchg %eax,%ebx # %ebx= fd + + push $__NR_mmap + sub %arg6l,%arg6l # 0 offset + mov %ebx,%arg5l + push $MAP_PRIVATE|MAP_FIXED; pop %sys4 # BEWARE: %sys4 + push $PROT_READ; pop %arg3 + mov $4096,%arg2l + push %r14; pop %arg1 + pop %rax; syscall + + push $__NR_close + mov %ebx,%edi # fd + pop %rax; syscall + + lea -8(%r15),%rsi # &last qword of old auxv + lea -8(%r14),%rdi # &last qword of new auxv + + mov %r15,%rcx + sub %rsp,%rcx + shr $3,%rcx; rep movsq + lea 8(%rdi),%rsp + cld + + lea (%r14,%r12),%arg4 # &new Elf64_auxv + pop %arg6 # f_unfilter pop %arg2 # LENX pop %arg1 # ADRX mov 2*8(%rsp),%rax // slide @@ -115,7 +162,7 @@ L90: pop %rcx # slide [unused] push %rax # &entry push $ __NR_munmap; pop %rax - jmp *(%r15) # goto: syscall; ret + jmp *-8(%r14) # goto: syscall; ret munmap: .globl munmap movb $ __NR_munmap,%al; jmp sysgo diff --git a/src/stub/tmp/amd64-linux.elf-fold.map b/src/stub/tmp/amd64-linux.elf-fold.map index 67257a2d..b602318c 100644 --- a/src/stub/tmp/amd64-linux.elf-fold.map +++ b/src/stub/tmp/amd64-linux.elf-fold.map @@ -8,30 +8,31 @@ Linker script and memory map 0x00000000001000bc . = ((0x100000 + SIZEOF_HEADERS) + 0xc) -.text 0x00000000001000bc 0x6c4 +.text 0x00000000001000bc 0x738 *(.text) - .text 0x00000000001000bc 0x11c tmp/amd64-linux.elf-fold.o - 0x00000000001001a5 munmap - 0x00000000001001b1 mmap - 0x00000000001001c8 read - 0x00000000001001d4 exit - 0x00000000001001ad brk - 0x00000000001001cc open - 0x00000000001001a9 mprotect - 0x00000000001001d0 close - .text 0x00000000001001d8 0x5a8 tmp/amd64-linux.elf-main.o - 0x00000000001005ea upx_main + .text 0x00000000001000bc 0x18e tmp/amd64-linux.elf-fold.o + 0x0000000000100217 munmap + 0x0000000000100223 mmap + 0x000000000010023a read + 0x0000000000100246 exit + 0x000000000010021f brk + 0x000000000010023e open + 0x000000000010021b mprotect + 0x0000000000100242 close + *fill* 0x000000000010024a 0x2 00 + .text 0x000000000010024c 0x5a8 tmp/amd64-linux.elf-main.o + 0x000000000010065e upx_main *(.data) - .data 0x0000000000100780 0x0 tmp/amd64-linux.elf-fold.o - .data 0x0000000000100780 0x0 tmp/amd64-linux.elf-main.o + .data 0x00000000001007f4 0x0 tmp/amd64-linux.elf-fold.o + .data 0x00000000001007f4 0x0 tmp/amd64-linux.elf-main.o .data -.bss 0x0000000000100780 0x0 - .bss 0x0000000000100780 0x0 tmp/amd64-linux.elf-fold.o - .bss 0x0000000000100780 0x0 tmp/amd64-linux.elf-main.o +.bss 0x00000000001007f4 0x0 + .bss 0x00000000001007f4 0x0 tmp/amd64-linux.elf-fold.o + .bss 0x00000000001007f4 0x0 tmp/amd64-linux.elf-main.o -.rela.dyn 0x0000000000100780 0x0 +.rela.dyn 0x00000000001007f8 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