diff --git a/src/compress.cpp b/src/compress.cpp index 554acf0b..c23aef60 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -87,7 +87,7 @@ int upx_compress ( const upx_bytep src, upx_uint src_len, result[5] = src_len; // max_run_found result[6] = 1; // first_offset_found //result[7] = 999999; // same_match_offsets_found - NOT USED - result[8] = 0; + result[8] = 0; // LzmaGetNumProbs() #if defined(WITH_LZMA) if (M_IS_LZMA(method)) diff --git a/src/stub/armv4_n2e_d8.S b/src/stub/armv4_n2e_d8.S index 471617b8..12f3c621 100644 --- a/src/stub/armv4_n2e_d8.S +++ b/src/stub/armv4_n2e_d8.S @@ -107,6 +107,20 @@ eof_n2e: SUB2(src,srclim) @ 0 if actual src length equals expected length SUB2(dst,r3) @ actual dst length str dst,[r4] + +#if defined(LINUX_ARM_CACHEFLUSH) /*{*/ +/* linux/include/asm-arm/unistd.h */ +#define __NR_SYSCALL_BASE 0x900000 +#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) +#define __ARM_NR_cacheflush (__ARM_NR_BASE+2) + mov r4,r0 @ save result value + mov r0,r3 @ orig_dst + add r1,r3,dst @ orig_dst + dst_len + mov r2,#0 + swi __ARM_NR_cacheflush @ decompressed region + mov r0,r4 @ result value +#endif /*}*/ + POP {r4,r5,r6,r7 ,pc} get8_n2e: @ In: Carry set [from adding 0x80000000 (1<<31) to itself] diff --git a/src/stub/fold_elf32arm.S b/src/stub/fold_elf32arm.S index c628fedc..1fdc33e0 100644 --- a/src/stub/fold_elf32arm.S +++ b/src/stub/fold_elf32arm.S @@ -126,6 +126,10 @@ exit: read: swi 0x00900003; mov pc,lr + .globl write +write: + swi 0x00900004; mov pc,lr + .globl open open: swi 0x00900005; mov pc,lr @@ -156,5 +160,61 @@ mmap: ldr r5,[sp],#4 mov pc,lr +#if 0 /*{ "gcc-3.4 -fPIC" botches string constants when code moves! */ + .globl STR_0x +STR_0x: + mov r0,pc; mov pc,lr + .asciz "0x" + .balign 4 + + .globl STR_hex +STR_hex: + mov r0,pc; mov pc,lr + .asciz "0123456789abcdef" + .balign 4 + + .globl STR_xread +STR_xread: + mov r0,pc; mov pc,lr + .asciz "xread %p(%x %p) %p %x\n" + .balign 4 + + .globl STR_unpackExtent +STR_unpackExtent: + mov r0,pc; mov pc,lr + .asciz "unpackExtent in=%p(%x %p) out=%p(%x %p) %p %p\n" + .balign 4 + + .globl STR_make_hatch_arm +STR_make_hatch_arm: + mov r0,pc; mov pc,lr + .asciz "make_hatch_arm %p %x\n" + .balign 4 + + .globl STR_auxv_up +STR_auxv_up: + mov r0,pc; mov pc,lr + .asciz "auxv_up %p %x %x\n" + .balign 4 + + .globl STR_xfind_pages +STR_xfind_pages: + mov r0,pc; mov pc,lr + .asciz "xfind_pages %x %p %d %p\n" + .balign 4 + + .globl STR_do_xmap +STR_do_xmap: + mov r0,pc; mov pc,lr + .asciz "do_xmap fdi=%x ehdr=%p xi=%p(%x %p) av=%p p_reloc=%p f_unf=%p\n" + .balign 4 + + .globl STR_upx_main +STR_upx_main: + mov r0,pc; mov pc,lr + .asciz "upx_main av=%p szc=%x f_dec=%p f_unf=%p xo=%p(%x %p) xi=%p(%x %p) dynbase=%x\n", + .balign 4 +#endif /*}*/ + @ vi:ts=8:et:nowrap diff --git a/src/stub/fold_elf32arm.h b/src/stub/fold_elf32arm.h index d3810e8d..826efc8a 100644 --- a/src/stub/fold_elf32arm.h +++ b/src/stub/fold_elf32arm.h @@ -1,4 +1,4 @@ -/* fold_elf32arm.h -- created from fold_elf32arm.bin, 2088 (0x828) bytes +/* fold_elf32arm.h -- created from fold_elf32arm.bin, 2080 (0x820) bytes This file is part of the UPX executable compressor. @@ -27,39 +27,39 @@ */ -#define LINUX_ELF32ARM_FOLD_SIZE 2088 -#define LINUX_ELF32ARM_FOLD_ADLER32 0x08175692 -#define LINUX_ELF32ARM_FOLD_CRC32 0x96d7f689 +#define LINUX_ELF32ARM_FOLD_SIZE 2080 +#define LINUX_ELF32ARM_FOLD_ADLER32 0xbb4d53cf +#define LINUX_ELF32ARM_FOLD_CRC32 0x44605956 -unsigned char linux_elf32arm_fold[2088] = { +unsigned char linux_elf32arm_fold[2080] = { 127, 69, 76, 70, 1, 1, 1, 97, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */ 2, 0, 40, 0, 1, 0, 0, 0,128,128, 0, 0, 52, 0, 0, 0, /* 0x 10 */ 0, 0, 0, 0, 2, 0, 0, 0, 52, 0, 32, 0, 2, 0, 0, 0, /* 0x 20 */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, /* 0x 30 */ - 0,128, 0, 0, 40, 8, 0, 0, 40, 8, 0, 0, 5, 0, 0, 0, /* 0x 40 */ - 0,128, 0, 0, 1, 0, 0, 0, 40, 8, 0, 0, 40,136, 0, 0, /* 0x 50 */ - 40,136, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */ + 0,128, 0, 0, 32, 8, 0, 0, 32, 8, 0, 0, 5, 0, 0, 0, /* 0x 40 */ + 0,128, 0, 0, 1, 0, 0, 0, 32, 8, 0, 0, 32,136, 0, 0, /* 0x 50 */ + 32,136, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */ 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */ 12, 48,157,229, 3, 49,141,224, 20, 48,131,226, 4, 0,147,228, /* 0x 80 */ 0, 0, 80,227,252,255,255, 26, 3, 32,160,225, 8, 0,146,228, /* 0x 90 */ 0, 0, 80,227,252,255,255, 26, 8, 32,141,229, 10,220, 77,226, /* 0x a0 */ 9, 64,160,225, 4,144,154,229, 13,128,160,225, 0,112,154,229, /* 0x b0 */ 36, 96,143,226, 12,144,137,226, 0,176,160,227,248, 15, 45,233, /* 0x c0 */ - 15, 0,189,232,125, 1, 0,235, 0,224,160,225, 20,208,141,226, /* 0x d0 */ + 15, 0,189,232,123, 1, 0,235, 0,224,160,225, 20,208,141,226, /* 0x d0 */ 10,220,141,226, 7, 0,189,232, 4,240, 18,229,255, 48, 3,226, /* 0x e0 */ 80, 0, 83,227, 14,240,160, 17, 33, 17,176,225, 0, 0, 80, 19, /* 0x f0 */ 14,240,160, 1, 1, 16, 65,226, 1, 33,144,231, 15, 52, 2,226, /* 0x 100 */ - 11, 4, 83,227, 6, 0, 0, 26,255, 52, 2,226, 1, 32, 66,224, /* 0x 110 */ -255, 36,194,227, 3, 32,130,225, 1, 33,128,231, 1, 49,128,224, /* 0x 120 */ - 0, 0,160,225, 0, 0, 81,227,241,255,255, 26, 14,240,160,225, /* 0x 130 */ - 1, 0,144,239, 3, 0,144,239, 14,240,160,225, 5, 0,144,239, /* 0x 140 */ + 11, 4, 83,227, 4, 0, 0, 26,255, 52, 2,226, 1, 32, 66,224, /* 0x 110 */ +255, 36,194,227, 3, 32,130,225, 1, 33,128,231, 0, 0, 81,227, /* 0x 120 */ +243,255,255, 26, 14,240,160,225, 1, 0,144,239, 3, 0,144,239, /* 0x 130 */ + 14,240,160,225, 4, 0,144,239, 14,240,160,225, 5, 0,144,239, /* 0x 140 */ 14,240,160,225, 6, 0,144,239, 14,240,160,225, 45, 0,144,239, /* 0x 150 */ 14,240,160,225, 91, 0,144,239, 14,240,160,225,125, 0,144,239, /* 0x 160 */ 14,240,160,225, 4, 80, 45,229, 8, 80,157,229, 4, 64, 45,229, /* 0x 170 */ 8, 64,157,229, 37, 86,160,225,192, 0,144,239, 4, 64,157,228, /* 0x 180 */ 4, 80,157,228, 14,240,160,225, 4,224, 45,229, 0, 48,144,229, /* 0x 190 */ 2, 0, 83,225, 2,192,160,225, 4,224,144,229,127, 0,160, 51, /* 0x 1a0 */ -226,255,255, 59, 1, 32, 66,226, 1, 0,114,227, 4, 0, 0, 10, /* 0x 1b0 */ +224,255,255, 59, 1, 32, 66,226, 1, 0,114,227, 4, 0, 0, 10, /* 0x 1b0 */ 1, 48,222,228, 1, 32, 66,226, 1, 48,193,228, 1, 0,114,227, /* 0x 1c0 */ 249,255,255,234, 4, 32,144,229, 0, 48,144,229, 12, 32,130,224, /* 0x 1d0 */ 3, 48,108,224, 0, 48,128,229, 4, 32,128,229, 4,240,157,228, /* 0x 1e0 */ @@ -69,7 +69,7 @@ unsigned char linux_elf32arm_fold[2088] = { 220,255,255,235, 8, 16,157,229, 0, 0, 81,227, 12, 32,157,229, /* 0x 220 */ 6, 0, 0, 26,252, 48,159,229, 3, 0, 82,225, 5, 0, 0, 26, /* 0x 230 */ 0, 48,149,229, 0, 0, 83,227, 56, 0, 0, 10, 1, 0, 0,234, /* 0x 240 */ - 0, 0, 82,227, 1, 0, 0, 26,127, 0,160,227,183,255,255,235, /* 0x 250 */ + 0, 0, 82,227, 1, 0, 0, 26,127, 0,160,227,181,255,255,235, /* 0x 250 */ 1, 0, 82,225,251,255,255,138, 0, 48,148,229, 3, 0, 81,225, /* 0x 260 */ 248,255,255,138, 1, 0, 82,225, 4, 48,148,229, 33, 0, 0, 42, /* 0x 270 */ 16,192,221,229, 4, 0,149,229, 2, 16,160,225, 0,192,141,229, /* 0x 280 */ @@ -84,83 +84,82 @@ unsigned char linux_elf32arm_fold[2088] = { 160,255,255,235, 8, 16,157,229, 12, 0,148,232, 2, 32, 97,224, /* 0x 310 */ 1, 48,131,224, 0, 0, 82,227, 12, 0,132,232,183,255,255,234, /* 0x 320 */ 20,208,141,226,240,128,189,232, 85, 80, 88, 33, 0, 0, 80,227, /* 0x 330 */ - 14,240,160, 1, 1, 0, 16,227, 14,240,160, 17, 0, 48,144,229, /* 0x 340 */ - 1, 0, 83,225, 6, 0, 0, 10, 1, 0, 83,227, 0, 48,160, 19, /* 0x 350 */ - 1, 48,160, 3, 0, 0, 81,227, 0, 48,160, 3, 0, 0, 83,227, /* 0x 360 */ - 1, 0, 0, 10, 6, 0,128,232, 14,240,160,225, 8, 0,128,226, /* 0x 370 */ -241,255,255,234,240, 79, 45,233, 40,208, 77,226, 1,144,160,225, /* 0x 380 */ - 28,192,145,229, 2,176,160,225,176, 17,209,225, 80, 32,157,229, /* 0x 390 */ -188,226,217,225, 2, 0, 81,227, 12,112,137,224, 24, 0,141,229, /* 0x 3a0 */ - 20, 48,141,229, 16, 32,141,229, 50,128,160, 3, 34,128,160, 19, /* 0x 3b0 */ - 7, 16,160,225, 1,224, 94,226, 0, 96,224,227, 0, 80,160,227, /* 0x 3c0 */ - 12, 0, 0, 74, 0, 48,145,229, 1, 0, 83,227, 6, 0, 0, 26, /* 0x 3d0 */ - 8, 32,145,229, 20, 48,145,229, 2, 48,131,224, 3, 0, 85,225, /* 0x 3e0 */ - 3, 80,160, 49, 2, 0, 86,225, 2, 96,160, 33, 1,224, 94,226, /* 0x 3f0 */ - 32, 16,129,226,241,255,255,234,255,110,198,227, 15, 96,198,227, /* 0x 400 */ - 5, 48,102,224,255, 62,131,226, 15, 48,131,226,255, 94,195,227, /* 0x 410 */ - 0, 64,160,227, 15, 80,197,227, 8, 48,160,225, 6, 0,160,225, /* 0x 420 */ - 0,192,224,227, 5, 16,160,225, 4, 32,160,225, 0,192,141,229, /* 0x 430 */ - 4, 64,141,229, 74,255,255,235,188, 50,217,225, 3, 0, 84,225, /* 0x 440 */ - 5, 48,128,224, 12, 64,141,229, 36, 48,141,229, 0, 96,102,224, /* 0x 450 */ -133, 0, 0,170, 0, 48,151,229, 6, 0, 83,227, 5, 0, 0, 26, /* 0x 460 */ - 8, 32,151,229, 20, 0,157,229, 6, 32,130,224, 3, 16,160,227, /* 0x 470 */ -173,255,255,235,117, 0, 0,234, 1, 0, 83,227,115, 0, 0, 26, /* 0x 480 */ - 24, 48,151,229, 8, 16,151,229, 7, 48, 3,226, 32, 34,159,229, /* 0x 490 */ - 6, 16,129,224, 3, 49,160,225, 16, 0,151,229, 50, 35,160,225, /* 0x 4a0 */ - 1, 74,160,225, 20, 48,151,229, 0, 0, 91,227, 4,192,151,229, /* 0x 4b0 */ - 36, 74,160,225, 3, 48,129,224, 1, 80,100,224, 24,224,157, 5, /* 0x 4c0 */ - 7,128, 2,226, 4,160,128,224, 2, 32,160, 19, 0, 32,160, 3, /* 0x 4d0 */ - 8, 48,141,229, 0,224,224, 19, 28, 0,141,229, 32, 16,141,229, /* 0x 4e0 */ - 18, 48,160, 3, 50, 48,160, 19, 12,192,100,224, 8, 32,130,225, /* 0x 4f0 */ - 5, 0,160,225, 10, 16,160,225, 0,224,141,229, 4,192,141,229, /* 0x 500 */ - 23,255,255,235, 0, 0, 85,225, 62, 0, 0, 26, 0, 0, 91,227, /* 0x 510 */ - 6, 0, 0, 10, 16, 32,157,229, 40, 49,176,225, 2, 48,160, 17, /* 0x 520 */ - 28, 16,141,226, 11, 0,160,225, 24, 32,157,229, 43,255,255,235, /* 0x 530 */ - 0, 48,106,226, 3, 74,160,225, 2, 0, 24,227, 36, 74,160,225, /* 0x 540 */ - 7, 0, 0, 10, 0, 0, 84,227, 10, 16,133,224, 4, 32,160,225, /* 0x 550 */ - 3, 0, 0, 10, 0, 48,160,227, 1, 32, 82,226, 1, 48,193,228, /* 0x 560 */ -251,255,255, 26, 0, 0, 91,227, 40, 0, 0, 10, 0, 48,151,229, /* 0x 570 */ - 1, 0, 83,227, 29, 0, 0, 26, 24, 48,151,229, 1, 0, 19,227, /* 0x 580 */ - 26, 0, 0, 10, 16, 32,135,226, 12, 0,146,232, 8, 16,151,229, /* 0x 590 */ - 2, 0, 83,225, 1, 48,131,224, 6, 32,131,224, 4, 0, 0, 26, /* 0x 5a0 */ - 0, 48, 98,226, 3, 58,160,225, 35, 58,160,225, 7, 0, 83,227, /* 0x 5b0 */ - 6, 0, 0,138, 4, 32,151,229,134, 48,134,224, 3, 49,134,224, /* 0x 5c0 */ - 3, 49,129,224, 0, 0, 82,227, 8, 32,131,226, 3, 0, 0, 26, /* 0x 5d0 */ -224, 48,159,229, 0, 48,130,229,220, 48,159,229, 4, 48,130,229, /* 0x 5e0 */ - 0, 0, 82,227, 20, 0,157, 21, 0, 16,160, 19, 78,255,255, 27, /* 0x 5f0 */ - 5, 0,160,225, 10, 16,160,225, 8, 32,160,225,214,254,255,235, /* 0x 600 */ - 0, 0, 80,227, 1, 0, 0, 10,127, 0,160,227,199,254,255,235, /* 0x 610 */ - 4, 48,138,224, 3, 80,133,224, 8, 48,157,229, 3, 0, 85,225, /* 0x 620 */ - 10, 0, 0, 42, 0,192,224,227, 3, 16,101,224, 0,192,141,229, /* 0x 630 */ - 8, 32,160,225, 1,192,140,226, 5, 0,160,225, 50, 48,160,227, /* 0x 640 */ - 4,192,141,229,198,254,255,235, 0, 0, 85,225,237,255,255, 26, /* 0x 650 */ - 12, 32,157,229,188, 50,217,225, 1, 32,130,226, 3, 0, 82,225, /* 0x 660 */ - 32,112,135,226, 12, 32,141,229,120,255,255,234, 0, 0, 91,227, /* 0x 670 */ - 4, 0, 0, 26, 24, 0,157,229,177,254,255,235, 0, 0, 80,227, /* 0x 680 */ - 4, 0, 0, 10,223,255,255,234,176, 49,217,225, 3, 0, 83,227, /* 0x 690 */ - 36, 0,157, 21,172,254,255, 27, 76, 48,157,229, 0, 0, 83,227, /* 0x 6a0 */ - 0, 96,131, 21, 24, 0,153,229, 6, 0,128,224, 40,208,141,226, /* 0x 6b0 */ -240,143,189,232, 64, 98, 81,115, 91, 0,144,239, 14,240,160,225, /* 0x 6c0 */ -240, 71, 45,233, 12,208, 77,226, 44,192,141,226, 52,112,141,226, /* 0x 6d0 */ - 0, 80,160,225, 1, 96,160,225, 3,160,160,225, 12, 16,160,225, /* 0x 6e0 */ - 0, 48,160,227, 7, 0,160,225, 4,144,156,229, 2,128,160,225, /* 0x 6f0 */ - 52, 64,157,229,185,254,255,235, 56, 48,157,229, 5, 0,160,225, /* 0x 700 */ - 3, 48,100,224, 5, 16,160,227,188, 34,217,225, 56, 48,141,229, /* 0x 710 */ - 52, 96,141,229, 4,255,255,235, 52, 96,137,226, 5, 0,160,225, /* 0x 720 */ - 4, 16,160,227,186, 34,217,225,255,254,255,235, 8, 48,150,229, /* 0x 730 */ - 60, 32,157,229, 3, 32,130,224, 52, 32,130,226, 5, 0,160,225, /* 0x 740 */ - 3, 16,160,227,248,254,255,235, 8,192,141,226, 7, 32,160,225, /* 0x 750 */ - 9, 16,160,225, 5, 48,160,225, 8, 0,160,225, 0,192,141,229, /* 0x 760 */ - 4,160,141,229, 2,255,255,235, 0, 64,160,225, 9, 16,160,227, /* 0x 770 */ - 4, 32,160,225, 5, 0,160,225,235,254,255,235,188, 18,217,225, /* 0x 780 */ - 0, 32,160,227, 1, 0, 82,225, 31, 0, 0,170, 0, 48,150,229, /* 0x 790 */ - 3, 0, 83,227, 1, 32,130,226, 24, 0, 0, 26, 8, 48,150,229, /* 0x 7a0 */ - 8, 0,157,229, 0, 16,160,227, 0, 0,131,224, 1, 32,160,225, /* 0x 7b0 */ - 97,254,255,235, 0, 64, 80,226, 4, 0, 0,186, 9, 16,160,225, /* 0x 7c0 */ - 2, 44,160,227, 90,254,255,235, 2, 12, 80,227, 1, 0, 0, 10, /* 0x 7d0 */ -127, 0,160,227, 85,254,255,235, 0,192,160,227, 4, 0,160,225, /* 0x 7e0 */ - 12, 32,160,225, 9, 16,160,225, 12, 48,160,225, 0,192,141,229, /* 0x 7f0 */ - 4,192,141,229,222,254,255,235, 0, 64,160,225, 2, 0, 0,234, /* 0x 800 */ - 1, 0, 82,225, 32, 96,134,226,222,255,255,234, 4, 0,160,225, /* 0x 810 */ - 12,208,141,226,240,135,189,232 /* 0x 820 */ + 14,240,160, 1, 0, 48,144,229, 1, 0, 83,225, 6, 0, 0, 10, /* 0x 340 */ + 1, 0, 83,227, 0, 48,160, 19, 1, 48,160, 3, 0, 0, 81,227, /* 0x 350 */ + 0, 48,160, 3, 0, 0, 83,227, 1, 0, 0, 10, 6, 0,128,232, /* 0x 360 */ + 14,240,160,225, 8, 0,128,226,241,255,255,234,240, 79, 45,233, /* 0x 370 */ + 40,208, 77,226, 1,144,160,225, 28,192,145,229, 2,176,160,225, /* 0x 380 */ +176, 17,209,225, 80, 32,157,229,188,226,217,225, 2, 0, 81,227, /* 0x 390 */ + 12,112,137,224, 24, 0,141,229, 20, 48,141,229, 16, 32,141,229, /* 0x 3a0 */ + 50,128,160, 3, 34,128,160, 19, 7, 16,160,225, 1,224, 94,226, /* 0x 3b0 */ + 0, 96,224,227, 0, 80,160,227, 12, 0, 0, 74, 0, 48,145,229, /* 0x 3c0 */ + 1, 0, 83,227, 6, 0, 0, 26, 8, 32,145,229, 20, 48,145,229, /* 0x 3d0 */ + 2, 48,131,224, 3, 0, 85,225, 3, 80,160, 49, 2, 0, 86,225, /* 0x 3e0 */ + 2, 96,160, 33, 1,224, 94,226, 32, 16,129,226,241,255,255,234, /* 0x 3f0 */ +255,110,198,227, 15, 96,198,227, 5, 48,102,224,255, 62,131,226, /* 0x 400 */ + 15, 48,131,226,255, 94,195,227, 0, 64,160,227, 15, 80,197,227, /* 0x 410 */ + 8, 48,160,225, 6, 0,160,225, 0,192,224,227, 5, 16,160,225, /* 0x 420 */ + 4, 32,160,225, 0,192,141,229, 4, 64,141,229, 76,255,255,235, /* 0x 430 */ +188, 50,217,225, 3, 0, 84,225, 5, 48,128,224, 12, 64,141,229, /* 0x 440 */ + 36, 48,141,229, 0, 96,102,224,133, 0, 0,170, 0, 48,151,229, /* 0x 450 */ + 6, 0, 83,227, 5, 0, 0, 26, 8, 32,151,229, 20, 0,157,229, /* 0x 460 */ + 6, 32,130,224, 3, 16,160,227,175,255,255,235,117, 0, 0,234, /* 0x 470 */ + 1, 0, 83,227,115, 0, 0, 26, 24, 48,151,229, 8, 16,151,229, /* 0x 480 */ + 7, 48, 3,226, 32, 34,159,229, 6, 16,129,224, 3, 49,160,225, /* 0x 490 */ + 16, 0,151,229, 50, 35,160,225, 1, 74,160,225, 20, 48,151,229, /* 0x 4a0 */ + 0, 0, 91,227, 4,192,151,229, 36, 74,160,225, 3, 48,129,224, /* 0x 4b0 */ + 1, 80,100,224, 24,224,157, 5, 7,128, 2,226, 4,160,128,224, /* 0x 4c0 */ + 2, 32,160, 19, 0, 32,160, 3, 8, 48,141,229, 0,224,224, 19, /* 0x 4d0 */ + 28, 0,141,229, 32, 16,141,229, 18, 48,160, 3, 50, 48,160, 19, /* 0x 4e0 */ + 12,192,100,224, 8, 32,130,225, 5, 0,160,225, 10, 16,160,225, /* 0x 4f0 */ + 0,224,141,229, 4,192,141,229, 25,255,255,235, 0, 0, 85,225, /* 0x 500 */ + 62, 0, 0, 26, 0, 0, 91,227, 6, 0, 0, 10, 16, 32,157,229, /* 0x 510 */ + 40, 49,176,225, 2, 48,160, 17, 28, 16,141,226, 11, 0,160,225, /* 0x 520 */ + 24, 32,157,229, 45,255,255,235, 0, 48,106,226, 3, 74,160,225, /* 0x 530 */ + 2, 0, 24,227, 36, 74,160,225, 7, 0, 0, 10, 0, 0, 84,227, /* 0x 540 */ + 10, 16,133,224, 4, 32,160,225, 3, 0, 0, 10, 0, 48,160,227, /* 0x 550 */ + 1, 32, 82,226, 1, 48,193,228,251,255,255, 26, 0, 0, 91,227, /* 0x 560 */ + 40, 0, 0, 10, 0, 48,151,229, 1, 0, 83,227, 29, 0, 0, 26, /* 0x 570 */ + 24, 48,151,229, 1, 0, 19,227, 26, 0, 0, 10, 16, 32,135,226, /* 0x 580 */ + 12, 0,146,232, 8, 16,151,229, 2, 0, 83,225, 1, 48,131,224, /* 0x 590 */ + 6, 32,131,224, 4, 0, 0, 26, 0, 48, 98,226, 3, 58,160,225, /* 0x 5a0 */ + 35, 58,160,225, 7, 0, 83,227, 6, 0, 0,138, 4, 32,151,229, /* 0x 5b0 */ +134, 48,134,224, 3, 49,134,224, 3, 49,129,224, 0, 0, 82,227, /* 0x 5c0 */ + 8, 32,131,226, 3, 0, 0, 26,224, 48,159,229, 0, 48,130,229, /* 0x 5d0 */ +220, 48,159,229, 4, 48,130,229, 0, 0, 82,227, 20, 0,157, 21, /* 0x 5e0 */ + 0, 16,160, 19, 80,255,255, 27, 5, 0,160,225, 10, 16,160,225, /* 0x 5f0 */ + 8, 32,160,225,216,254,255,235, 0, 0, 80,227, 1, 0, 0, 10, /* 0x 600 */ +127, 0,160,227,199,254,255,235, 4, 48,138,224, 3, 80,133,224, /* 0x 610 */ + 8, 48,157,229, 3, 0, 85,225, 10, 0, 0, 42, 0,192,224,227, /* 0x 620 */ + 3, 16,101,224, 0,192,141,229, 8, 32,160,225, 1,192,140,226, /* 0x 630 */ + 5, 0,160,225, 50, 48,160,227, 4,192,141,229,200,254,255,235, /* 0x 640 */ + 0, 0, 85,225,237,255,255, 26, 12, 32,157,229,188, 50,217,225, /* 0x 650 */ + 1, 32,130,226, 3, 0, 82,225, 32,112,135,226, 12, 32,141,229, /* 0x 660 */ +120,255,255,234, 0, 0, 91,227, 4, 0, 0, 26, 24, 0,157,229, /* 0x 670 */ +179,254,255,235, 0, 0, 80,227, 4, 0, 0, 10,223,255,255,234, /* 0x 680 */ +176, 49,217,225, 3, 0, 83,227, 36, 0,157, 21,174,254,255, 27, /* 0x 690 */ + 76, 48,157,229, 0, 0, 83,227, 0, 96,131, 21, 24, 0,153,229, /* 0x 6a0 */ + 6, 0,128,224, 40,208,141,226,240,143,189,232, 64, 98, 81,115, /* 0x 6b0 */ + 91, 0,144,239, 14,240,160,225,240, 71, 45,233, 12,208, 77,226, /* 0x 6c0 */ + 44,192,141,226, 52,112,141,226, 0, 80,160,225, 1, 96,160,225, /* 0x 6d0 */ + 3,160,160,225, 12, 16,160,225, 0, 48,160,227, 7, 0,160,225, /* 0x 6e0 */ + 4,144,156,229, 2,128,160,225, 52, 64,157,229,187,254,255,235, /* 0x 6f0 */ + 56, 48,157,229, 5, 0,160,225, 3, 48,100,224, 5, 16,160,227, /* 0x 700 */ +188, 34,217,225, 56, 48,141,229, 52, 96,141,229, 6,255,255,235, /* 0x 710 */ + 52, 96,137,226, 5, 0,160,225, 4, 16,160,227,186, 34,217,225, /* 0x 720 */ + 1,255,255,235, 8, 48,150,229, 60, 32,157,229, 3, 32,130,224, /* 0x 730 */ + 52, 32,130,226, 5, 0,160,225, 3, 16,160,227,250,254,255,235, /* 0x 740 */ + 8,192,141,226, 7, 32,160,225, 9, 16,160,225, 5, 48,160,225, /* 0x 750 */ + 8, 0,160,225, 0,192,141,229, 4,160,141,229, 2,255,255,235, /* 0x 760 */ + 0, 64,160,225, 9, 16,160,227, 4, 32,160,225, 5, 0,160,225, /* 0x 770 */ +237,254,255,235,188, 18,217,225, 0, 32,160,227, 1, 0, 82,225, /* 0x 780 */ + 31, 0, 0,170, 0, 48,150,229, 3, 0, 83,227, 1, 32,130,226, /* 0x 790 */ + 24, 0, 0, 26, 8, 48,150,229, 8, 0,157,229, 0, 16,160,227, /* 0x 7a0 */ + 0, 0,131,224, 1, 32,160,225, 99,254,255,235, 0, 64, 80,226, /* 0x 7b0 */ + 4, 0, 0,186, 9, 16,160,225, 2, 44,160,227, 90,254,255,235, /* 0x 7c0 */ + 2, 12, 80,227, 1, 0, 0, 10,127, 0,160,227, 85,254,255,235, /* 0x 7d0 */ + 0,192,160,227, 4, 0,160,225, 12, 32,160,225, 9, 16,160,225, /* 0x 7e0 */ + 12, 48,160,225, 0,192,141,229, 4,192,141,229,222,254,255,235, /* 0x 7f0 */ + 0, 64,160,225, 2, 0, 0,234, 1, 0, 82,225, 32, 96,134,226, /* 0x 800 */ +222,255,255,234, 4, 0,160,225, 12,208,141,226,240,135,189,232 /* 0x 810 */ }; diff --git a/src/stub/l_lx_elf.c b/src/stub/l_lx_elf.c index 5994b5b0..d8622058 100644 --- a/src/stub/l_lx_elf.c +++ b/src/stub/l_lx_elf.c @@ -41,6 +41,89 @@ // it at an address different from it load address: there must be no // static data, and no string constants. +#if 1 /*{*/ +#define DPRINTF(a) /* empty: no debug drivel */ +#else /*}{*/ +#include "stdarg.h" + +static int +unsimal(unsigned x, char *ptr, int n) +{ + if (10<=x) { + n = unsimal(x/10, ptr, n); + x %= 10; + } + ptr[n] = '0' + x; + return 1+ n; +} + +static int +decimal(int x, char *ptr, int n) +{ + if (x < 0) { + *ptr++ = '-'; ++n; + x = -x; + } + return unsimal(x, ptr, n); +} + +extern char const *STR_hex(); + +static int +heximal(unsigned x, char *ptr, int n) +{ + if (16<=x) { + n = heximal(x>>4, ptr, n); + x &= 0xf; + } + ptr[n] = STR_hex()[x]; + return 1+ n; +} + + +#define DPRINTF(a) dprintf a +extern char const *STR_0x(); +extern char const *STR_xread(); +extern char const *STR_unpackExtent(); +extern char const *STR_make_hatch_arm(); +extern char const *STR_auxv_up(); +extern char const *STR_xfind_pages(); +extern char const *STR_do_xmap(); +extern char const *STR_upx_main(); + +extern int write(int fd, char const *buf, size_t n); + +static int +dprintf(char const *fmt, ...) +{ + char c; + int n= 0; + char *ptr; + char buf[20]; + va_list va; va_start(va, fmt); + ptr= &buf[0]; + while (0!=(c= *fmt++)) if ('%'!=c) n+= write(2, fmt-1, 1); + else switch (c= *fmt++) { + default: { + n+= write(2, fmt-1, 1); + } break; + case 0: goto done; /* early */ + case 'd': { + n+= write(2, buf, decimal(va_arg(va, int), buf, 0)); + } break; + case 'p': { + n+= write(2, STR_0x(), 2); + } /* fall through into 'x' */ + case 'x': { + n+= write(2, buf, heximal(va_arg(va, int), buf, 0)); + } break; + } +done: + va_end(va); + return n; +} +#endif /*}*/ + #define MAX_ELF_HDR 512 // Elf32_Ehdr + n*Elf32_Phdr must fit in this @@ -62,6 +145,7 @@ xread(struct Extent *x, char *buf, size_t count) { char *p=x->buf, *q=buf; size_t j; + DPRINTF((STR_xread(), x, x->size, x->buf, buf, count)); if (x->size < count) { exit(127); } @@ -121,6 +205,8 @@ unpackExtent( f_unfilter *f_unf ) { + DPRINTF((STR_unpackExtent(), + xi, xi->size, xi->buf, xo, xo->size, xo->buf, f_decompress, f_unf)); while (xo->size) { struct b_info h; // Note: if h.sz_unc == h.sz_cpr then the block was not @@ -210,7 +296,7 @@ static void * make_hatch_arm(Elf32_Phdr const *const phdr, unsigned const reloc) { unsigned *hatch = 0; - + DPRINTF((STR_make_hatch_arm(),phdr,reloc)); if (phdr->p_type==PT_LOAD && phdr->p_flags & PF_X) { // The format of the 'if' is // if ( ( (hatch = loc1), test_loc1 ) @@ -255,7 +341,12 @@ __attribute__((regparm(3), stdcall)) #endif /*}*/ auxv_up(Elf32_auxv_t *av, unsigned const type, unsigned const value) { - if (av && 0==(1&(int)av)) /* PT_INTERP usually inhibits, except for hatch */ + DPRINTF((STR_auxv_up(),av,type,value)); + if (av +#if defined(__i386__) /*{*/ + && 0==(1&(int)av) /* PT_INTERP usually inhibits, except for hatch */ +#endif /*}*/ + ) for (;; ++av) { if (av->a_type==type || (av->a_type==AT_IGNORE && type!=AT_NULL)) { av->a_type = type; @@ -291,6 +382,7 @@ xfind_pages(unsigned mflags, Elf32_Phdr const *phdr, int phnum, { size_t lo= ~0, hi= 0, szlo= 0; char *addr; + DPRINTF((STR_xfind_pages(), mflags, phdr, phnum, p_brk)); mflags += MAP_PRIVATE | MAP_ANONYMOUS; // '+' can optimize better than '|' for (; --phnum>=0; ++phdr) if (PT_LOAD==phdr->p_type) { if (phdr->p_vaddr < lo) { @@ -321,6 +413,8 @@ do_xmap(int const fdi, Elf32_Ehdr const *const ehdr, struct Extent *const xi, unsigned const reloc = xfind_pages( ((ET_EXEC==ehdr->e_type) ? MAP_FIXED : 0), phdr, ehdr->e_phnum, &v_brk); int j; + DPRINTF((STR_do_xmap(), + fdi, ehdr, xi, (xi? xi->size: 0), (xi? xi->buf: 0), av, p_reloc, f_unf)); for (j=0; j < ehdr->e_phnum; ++phdr, ++j) if (PT_PHDR==phdr->p_type) { auxv_up(av, AT_PHDR, phdr->p_vaddr + reloc); @@ -443,6 +537,9 @@ void *upx_main( // sizeof(Ehdr+Phdrs), compressed; including b_info header size_t const sz_pckhdrs = xi.size; + DPRINTF((STR_upx_main(), + av, sz_compressed, f_decompress, f_unf, &xo, xo.size, xo.buf, + &xi, xi.size, xi.buf, dynbase)); #if defined(__i386__) /*{*/ f_unf = (f_unfilter *)(2+ (long)f_decompress); #endif /*}*/ diff --git a/src/stub/l_lx_elf32arm.S b/src/stub/l_lx_elf32arm.S index fff9ab86..90d8cc59 100644 --- a/src/stub/l_lx_elf32arm.S +++ b/src/stub/l_lx_elf32arm.S @@ -79,14 +79,26 @@ copy: mov lr,r9 @ dst for unfolded code sub r11,r9,r8 @ relocation amount ldmia r12!,{r9,r10} @ LENX,ADRX + add r5,r12,r11 @ relocated f_decompress - ldrb r4,b_method+cpr0 +/* linux/include/asm-arm/unistd.h */ +#define __NR_SYSCALL_BASE 0x900000 +#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) +#define __ARM_NR_cacheflush (__ARM_NR_BASE+2) + + mov r0,r5 + adr r1,end_decompress + sub r1,r1,r12 @ len(f_decompress) + add r1,r1,r0 @ relocated end_decompress + mov r2,#0 + swi __ARM_NR_cacheflush @ relocated decompressor + + ldrb r4,b_method +cpr0 add r3,sp,#2*4 @ &sz_unc mov r2,lr @ dst ldr r1,sz_cpr +cpr0 adr r0,sz_b_info +cpr0 - add r5,r12,r11 @ relocated f_decompress - add pc,r12,r11 @ goto there; return to unfolded code + mov pc,r5 @ decompress folded code; go there (lr) start_params: .ascii "ADRM" @ dst for map @@ -98,7 +110,9 @@ start_params: .ascii "LENX" @ total size of compressed data .ascii "ADRX" @ &b_info of 1st compressed block (after moving) f_decompress: +#define LINUX_ARM_CACHEFLUSH 1 #include "armv4_n2e_d8.S" +end_decompress: .subsection 2 msg_SELinux: diff --git a/src/stub/l_lx_elf32arm.h b/src/stub/l_lx_elf32arm.h index ebc41f57..5ed80359 100644 --- a/src/stub/l_lx_elf32arm.h +++ b/src/stub/l_lx_elf32arm.h @@ -1,4 +1,4 @@ -/* l_lx_elf32arm.h -- created from l_lx_elf32arm.bin, 536 (0x218) bytes +/* l_lx_elf32arm.h -- created from l_lx_elf32arm.bin, 584 (0x248) bytes This file is part of the UPX executable compressor. @@ -27,43 +27,46 @@ */ -#define LINUX_ELF32ARM_LOADER_SIZE 536 -#define LINUX_ELF32ARM_LOADER_ADLER32 0xbfbae653 -#define LINUX_ELF32ARM_LOADER_CRC32 0x2728e7c0 +#define LINUX_ELF32ARM_LOADER_SIZE 584 +#define LINUX_ELF32ARM_LOADER_ADLER32 0xeb17f976 +#define LINUX_ELF32ARM_LOADER_CRC32 0xe6d5a92e -unsigned char linux_elf32arm_loader[536] = { - 88,192,143,226, 3, 5,188,232, 7, 0, 45,233, 7, 32,160,227, /* 0x 0 */ +unsigned char linux_elf32arm_loader[584] = { +112,192,143,226, 3, 5,188,232, 7, 0, 45,233, 7, 32,160,227, /* 0x 0 */ 50, 48,160,227, 0, 64,224,227,192, 0,144,239, 1, 10,112,227, /* 0x 10 */ - 89, 0, 0, 42, 0,144,160,225,255, 0,184,232, 1,160, 90,226, /* 0x 20 */ +101, 0, 0, 42, 0,144,160,225,255, 0,184,232, 1,160, 90,226, /* 0x 20 */ 255, 0,169,232,251,255,255, 26, 9,224,160,225, 8,176, 73,224, /* 0x 30 */ - 0, 6,188,232,212, 65,223,229, 8, 48,141,226, 14, 32,160,225, /* 0x 40 */ -196, 17,159,229,114, 15,143,226, 11, 80,140,224, 11,240,140,224, /* 0x 50 */ - 65, 68, 82, 77, 76, 69, 78, 77, 65, 68, 82, 67, 67, 78, 84, 67, /* 0x 60 */ - 76, 69, 78, 88, 65, 68, 82, 88,252, 64, 45,233, 0,112,129,224, /* 0x 70 */ - 0, 80,224,227, 2, 65,160,227, 10, 0, 0,234, 24, 0,189,232, /* 0x 80 */ - 7, 0, 64,224, 3, 32, 66,224, 0, 32,132,229,240,128,189,232, /* 0x 90 */ - 1, 64,208,228, 4, 64,164,224, 4, 76,176,225, 14,240,160,225, /* 0x a0 */ - 1, 48,208,228, 1, 48,194,228, 4, 64,148,224,247,255,255, 11, /* 0x b0 */ -250,255,255, 42, 1, 16,160,227, 3, 0, 0,234, 1, 16, 65,226, /* 0x c0 */ - 4, 64,148,224,241,255,255, 11, 1, 16,161,224, 4, 64,148,224, /* 0x d0 */ -238,255,255, 11, 1, 16,161,224, 4, 64,148,224,235,255,255, 11, /* 0x e0 */ -245,255,255, 58, 3, 48, 81,226, 0, 16,160,227, 6, 0, 0, 58, /* 0x f0 */ - 1, 80,208,228, 3, 84,133,225, 5, 80,240,225,222,255,255, 10, /* 0x 100 */ -197, 80,176,225, 15, 0, 0, 42, 2, 0, 0,234, 4, 64,148,224, /* 0x 110 */ -222,255,255, 11, 11, 0, 0, 42, 1, 16,160,227, 4, 64,148,224, /* 0x 120 */ -218,255,255, 11, 7, 0, 0, 42, 4, 64,148,224,215,255,255, 11, /* 0x 130 */ - 1, 16,161,224, 4, 64,148,224,212,255,255, 11,249,255,255, 58, /* 0x 140 */ - 4, 16,129,226, 3, 0, 0,234, 4, 64,148,224,207,255,255, 11, /* 0x 150 */ - 1, 16,161,224, 2, 16,129,226, 5, 12,117,227, 0, 0, 0, 42, /* 0x 160 */ - 1, 16,129,226, 0, 48,210,229, 5, 48,210,231, 1, 48,194,228, /* 0x 170 */ - 1, 16, 81,226,251,255,255, 26,202,255,255,234, 30, 32,160,227, /* 0x 180 */ - 96, 16,143,226, 2, 0,160,227, 4, 0,144,239,127, 0,160,227, /* 0x 190 */ - 1, 0,144,239,252,255,255,234, 10, 36, 73,100, 58, 32, 85, 80, /* 0x 1a0 */ - 88, 32, 40, 67, 41, 32, 49, 57, 57, 54, 45, 50, 48, 48, 54, 32, /* 0x 1b0 */ -116,104,101, 32, 85, 80, 88, 32, 84,101, 97,109, 46, 32, 65,108, /* 0x 1c0 */ -108, 32, 82,105,103,104,116,115, 32, 82,101,115,101,114,118,101, /* 0x 1d0 */ -100, 46, 32,104,116,116,112, 58, 47, 47,117,112,120, 46,115,102, /* 0x 1e0 */ - 46,110,101,116, 32, 36, 10, 0, 80, 82, 79, 84, 95, 69, 88, 69, /* 0x 1f0 */ - 67,124, 80, 82, 79, 84, 95, 87, 82, 73, 84, 69, 32,102, 97,105, /* 0x 200 */ -108,101,100, 46, 10, 0, 0, 0 /* 0x 210 */ + 0, 6,188,232, 11, 80,140,224, 5, 0,160,225, 90, 31,143,226, /* 0x 40 */ + 12, 16, 65,224, 0, 16,129,224, 0, 32,160,227, 2, 0,159,239, /* 0x 50 */ +232, 65,223,229, 8, 48,141,226, 14, 32,160,225,216, 17,159,229, /* 0x 60 */ +119, 15,143,226, 5,240,160,225, 65, 68, 82, 77, 76, 69, 78, 77, /* 0x 70 */ + 65, 68, 82, 67, 67, 78, 84, 67, 76, 69, 78, 88, 65, 68, 82, 88, /* 0x 80 */ +252, 64, 45,233, 0,112,129,224, 0, 80,224,227, 2, 65,160,227, /* 0x 90 */ + 16, 0, 0,234, 24, 0,189,232, 7, 0, 64,224, 3, 32, 66,224, /* 0x a0 */ + 0, 32,132,229, 0, 64,160,225, 3, 0,160,225, 2, 16,131,224, /* 0x b0 */ + 0, 32,160,227, 2, 0,159,239, 4, 0,160,225,240,128,189,232, /* 0x c0 */ + 1, 64,208,228, 4, 64,164,224, 4, 76,176,225, 14,240,160,225, /* 0x d0 */ + 1, 48,208,228, 1, 48,194,228, 4, 64,148,224,247,255,255, 11, /* 0x e0 */ +250,255,255, 42, 1, 16,160,227, 3, 0, 0,234, 1, 16, 65,226, /* 0x f0 */ + 4, 64,148,224,241,255,255, 11, 1, 16,161,224, 4, 64,148,224, /* 0x 100 */ +238,255,255, 11, 1, 16,161,224, 4, 64,148,224,235,255,255, 11, /* 0x 110 */ +245,255,255, 58, 3, 48, 81,226, 0, 16,160,227, 6, 0, 0, 58, /* 0x 120 */ + 1, 80,208,228, 3, 84,133,225, 5, 80,240,225,216,255,255, 10, /* 0x 130 */ +197, 80,176,225, 15, 0, 0, 42, 2, 0, 0,234, 4, 64,148,224, /* 0x 140 */ +222,255,255, 11, 11, 0, 0, 42, 1, 16,160,227, 4, 64,148,224, /* 0x 150 */ +218,255,255, 11, 7, 0, 0, 42, 4, 64,148,224,215,255,255, 11, /* 0x 160 */ + 1, 16,161,224, 4, 64,148,224,212,255,255, 11,249,255,255, 58, /* 0x 170 */ + 4, 16,129,226, 3, 0, 0,234, 4, 64,148,224,207,255,255, 11, /* 0x 180 */ + 1, 16,161,224, 2, 16,129,226, 5, 12,117,227, 0, 0, 0, 42, /* 0x 190 */ + 1, 16,129,226, 0, 48,210,229, 5, 48,210,231, 1, 48,194,228, /* 0x 1a0 */ + 1, 16, 81,226,251,255,255, 26,202,255,255,234, 30, 32,160,227, /* 0x 1b0 */ + 96, 16,143,226, 2, 0,160,227, 4, 0,144,239,127, 0,160,227, /* 0x 1c0 */ + 1, 0,144,239,252,255,255,234, 10, 36, 73,100, 58, 32, 85, 80, /* 0x 1d0 */ + 88, 32, 40, 67, 41, 32, 49, 57, 57, 54, 45, 50, 48, 48, 54, 32, /* 0x 1e0 */ +116,104,101, 32, 85, 80, 88, 32, 84,101, 97,109, 46, 32, 65,108, /* 0x 1f0 */ +108, 32, 82,105,103,104,116,115, 32, 82,101,115,101,114,118,101, /* 0x 200 */ +100, 46, 32,104,116,116,112, 58, 47, 47,117,112,120, 46,115,102, /* 0x 210 */ + 46,110,101,116, 32, 36, 10, 0, 80, 82, 79, 84, 95, 69, 88, 69, /* 0x 220 */ + 67,124, 80, 82, 79, 84, 95, 87, 82, 73, 84, 69, 32,102, 97,105, /* 0x 230 */ +108,101,100, 46, 10, 0, 0, 0 /* 0x 240 */ };