mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Fix arm64-linux.elf-*
modified: stub/src/amd64-linux.elf-main.c modified: stub/src/arm64-linux.elf-entry.S modified: stub/src/arm64-linux.elf-fold.S modified: stub/src/arm64-linux.elf-main.c modified: stub/arm64-linux.elf-entry.h modified: stub/arm64-linux.elf-fold.h modified: stub/tmp/arm64-linux.elf-entry.bin.dump modified: stub/tmp/arm64-linux.elf-fold.map
This commit is contained in:
parent
62815f5c3c
commit
e59ce39dc6
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
|||
/* arm64-linux.elf-fold.h
|
||||
created from arm64-linux.elf-fold.bin, 2356 (0x934) bytes
|
||||
created from arm64-linux.elf-fold.bin, 2496 (0x9c0) bytes
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
|
@ -31,20 +31,20 @@
|
|||
*/
|
||||
|
||||
|
||||
#define STUB_ARM64_LINUX_ELF_FOLD_SIZE 2356
|
||||
#define STUB_ARM64_LINUX_ELF_FOLD_ADLER32 0x0cc94769
|
||||
#define STUB_ARM64_LINUX_ELF_FOLD_CRC32 0x8f081e00
|
||||
#define STUB_ARM64_LINUX_ELF_FOLD_SIZE 2496
|
||||
#define STUB_ARM64_LINUX_ELF_FOLD_ADLER32 0x20a57b10
|
||||
#define STUB_ARM64_LINUX_ELF_FOLD_CRC32 0x0197c648
|
||||
|
||||
unsigned char stub_arm64_linux_elf_fold[2356] = {
|
||||
unsigned char stub_arm64_linux_elf_fold[2496] = {
|
||||
/* 0x0000 */ 127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0010 */ 2, 0,183, 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 */ 52, 9, 0, 0, 0, 0, 0, 0, 52, 9, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0060 */ 192, 9, 0, 0, 0, 0, 0, 0,192, 9, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0070 */ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0080 */ 52, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0080 */ 192, 9, 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, 1, 0, 0, 0, 0, 0,
|
||||
/* 0x00b0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,229, 35, 65,169,
|
||||
|
@ -58,9 +58,9 @@ unsigned char stub_arm64_linux_elf_fold[2356] = {
|
|||
/* 0x0130 */ 231, 3, 0,170, 34, 12,193,168, 2, 12,129,168,194,255,255,181,
|
||||
/* 0x0140 */ 224, 11, 0,249,225, 3, 6,170,129, 0, 0,249,162, 4, 0, 24,
|
||||
/* 0x0150 */ 34, 68, 0,184,226,255,129, 82, 96, 4, 0, 16, 88, 0, 0,148,
|
||||
/* 0x0160 */ 31, 4, 64,177, 66, 0, 0, 84, 95,104, 32, 56,230, 99, 0,145,
|
||||
/* 0x0160 */ 31, 4, 64,177, 66, 0, 0, 84, 95,104, 32, 56,230, 3, 26,170,
|
||||
/* 0x0170 */ 255, 3, 40,209, 5, 4, 0, 16,228, 3, 28,170,227, 3, 7,170,
|
||||
/* 0x0180 */ 226, 3, 0,145,225, 3, 26, 42,224, 3, 27,170,142, 1, 0,148,
|
||||
/* 0x0180 */ 226, 3, 0,145,225, 3, 29, 42,224, 3, 27,170,142, 1, 0,148,
|
||||
/* 0x0190 */ 255, 3, 40,145,224, 15, 0,249, 96, 2, 0, 16, 1, 0,128, 82,
|
||||
/* 0x01a0 */ 73, 0, 0,148,239, 3, 0, 42,229, 3, 31,170,228, 3, 0, 42,
|
||||
/* 0x01b0 */ 67, 0,128, 82, 34, 0,128, 82, 1, 0,130,210,224, 3, 31,170,
|
||||
|
@ -161,27 +161,35 @@ unsigned char stub_arm64_linux_elf_fold[2356] = {
|
|||
/* 0x07a0 */ 234, 47, 71,109,128, 2, 0,139,243, 83, 65,169,247, 99, 67,169,
|
||||
/* 0x07b0 */ 249,107, 68,169,251,115, 69,169,236, 67, 64,253,253,123,203,168,
|
||||
/* 0x07c0 */ 192, 3, 95,214,253,123,182,169,253, 3, 0,145,243, 83, 1,169,
|
||||
/* 0x07d0 */ 243, 3, 2,170, 84, 0, 1,145,162, 63, 0,249, 2, 0, 64,185,
|
||||
/* 0x07e0 */ 245, 91, 2,169,162, 59, 0,249,245, 3, 3,170,226, 3, 4,170,
|
||||
/* 0x07f0 */ 3, 0,128,210,160, 79, 0,249,161, 75, 0,249,160, 71, 0,249,
|
||||
/* 0x0800 */ 160, 67, 2,145,161, 67, 0,249,161,195, 1,145,165, 39, 0,249,
|
||||
/* 0x0810 */ 166, 47, 0,249,164, 43, 0,249,247, 99, 3,169,219,254,255,151,
|
||||
/* 0x0820 */ 23, 0,128, 82,130, 10, 64,249,224, 3, 21,170, 97, 0,128, 82,
|
||||
/* 0x0830 */ 66, 0, 1,145,176,254,255,151, 98,114, 64,121,224, 3, 21,170,
|
||||
/* 0x0840 */ 161, 0,128, 82,172,254,255,151,164, 43, 64,249,161, 3, 2,145,
|
||||
/* 0x0850 */ 165, 39, 64,249, 2, 0,128, 82,227, 3, 21,170,166, 99, 1,145,
|
||||
/* 0x0860 */ 224, 3, 19,170, 26,255,255,151,246, 3, 0,170, 33, 1,128, 82,
|
||||
/* 0x0870 */ 224, 3, 21,170,226, 3, 22,170,159,254,255,151, 96,114, 64,121,
|
||||
/* 0x0880 */ 255, 2, 0,107,202, 4, 0, 84,128, 2, 64,185, 31, 12, 0,113,
|
||||
/* 0x0890 */ 1, 4, 0, 84,129, 10, 64,249,160, 47, 64,249, 32, 0, 0,139,
|
||||
/* 0x08a0 */ 1, 0,128, 82,226, 3, 1, 42,135,254,255,151,248, 3, 0, 42,
|
||||
/* 0x08b0 */ 96, 0,248, 54,224, 15,128, 82, 96,254,255,151,225, 3, 19,170,
|
||||
/* 0x08c0 */ 2,128,128,210, 95,254,255,151, 31, 0, 16,241, 65,255,255, 84,
|
||||
/* 0x08d0 */ 1, 0,128,210,226, 3, 24, 42,227, 3, 1,170,228, 3, 1,170,
|
||||
/* 0x08e0 */ 229, 3, 1,170,166,163, 1,145,224, 3, 19,170,191, 55, 0,249,
|
||||
/* 0x08f0 */ 247,254,255,151,246, 3, 0,170,162, 55, 64,249,224, 3, 21,170,
|
||||
/* 0x0900 */ 225, 0,128, 82,124,254,255,151,224, 3, 24, 42, 83,254,255,151,
|
||||
/* 0x0910 */ 148,226, 0,145,247, 6, 0, 17,217,255,255, 23,224, 3, 22,170,
|
||||
/* 0x0920 */ 243, 83, 65,169,245, 91, 66,169,247, 99, 67,169,253,123,202,168,
|
||||
/* 0x0930 */ 192, 3, 95,214
|
||||
/* 0x07d0 */ 243, 3, 2,170,244, 3, 3,170,162, 63, 0,249, 3, 0,128,210,
|
||||
/* 0x07e0 */ 2, 0, 64,185,162, 59, 0,249,226, 3, 4,170,160, 79, 0,249,
|
||||
/* 0x07f0 */ 161, 75, 0,249,160, 71, 0,249,160, 67, 2,145,161, 67, 0,249,
|
||||
/* 0x0800 */ 161,195, 1,145,165, 39, 0,249,164, 43, 0,249,166, 47, 0,249,
|
||||
/* 0x0810 */ 245, 91, 2,169,247, 99, 3,169,220,254,255,151,117, 2, 1,145,
|
||||
/* 0x0820 */ 99, 18, 64,249,224, 3, 20,170,162, 47, 64,249, 97, 0,128, 82,
|
||||
/* 0x0830 */ 98, 0, 2,139,176,254,255,151, 98,114, 64,121,224, 3, 20,170,
|
||||
/* 0x0840 */ 161, 0,128, 82,172,254,255,151,119, 34, 64,121,164, 43, 64,249,
|
||||
/* 0x0850 */ 255, 14, 0,113,165, 39, 64,249,224, 1, 0, 84,224, 3, 19,170,
|
||||
/* 0x0860 */ 161, 3, 2,145, 2, 0,128, 82,227, 3, 20,170,166, 99, 1,145,
|
||||
/* 0x0870 */ 23,255,255,151,246, 3, 0,170,255, 14, 0,113, 64, 4, 0, 84,
|
||||
/* 0x0880 */ 224, 3, 20,170, 33, 1,128, 82,226, 3, 22,170,154,254,255,151,
|
||||
/* 0x0890 */ 29, 0, 0, 20, 64, 0,128, 82,162, 47, 64,249, 96, 34, 0,121,
|
||||
/* 0x08a0 */ 33, 1,128, 82, 96, 14, 64,249,165, 39, 0,249, 66, 0, 0,139,
|
||||
/* 0x08b0 */ 224, 3, 20,170, 98, 14, 0,249,164, 43, 0,249,142,254,255,151,
|
||||
/* 0x08c0 */ 102,114, 64,121,224, 3, 21,170,162, 47, 64,249, 1, 0,128, 82,
|
||||
/* 0x08d0 */ 164, 43, 64,249,165, 39, 64,249, 63, 0, 6,107, 2,252,255, 84,
|
||||
/* 0x08e0 */ 3, 8, 64,249, 33, 4, 0, 17, 0,224, 0,145, 99, 0, 2,139,
|
||||
/* 0x08f0 */ 3,128, 29,248, 3, 0, 94,248, 99, 0, 2,139, 3, 0, 30,248,
|
||||
/* 0x0900 */ 246,255,255, 23, 23, 0,128, 82, 96,114, 64,121,255, 2, 0,107,
|
||||
/* 0x0910 */ 194, 4, 0, 84,160, 2, 64,185, 31, 12, 0,113, 1, 4, 0, 84,
|
||||
/* 0x0920 */ 161, 10, 64,249,160, 47, 64,249, 32, 0, 0,139, 1, 0,128, 82,
|
||||
/* 0x0930 */ 226, 3, 1, 42,100,254,255,151,248, 3, 0, 42, 96, 0,248, 54,
|
||||
/* 0x0940 */ 224, 15,128, 82, 61,254,255,151,225, 3, 19,170, 2,128,128,210,
|
||||
/* 0x0950 */ 60,254,255,151, 31, 0, 16,241, 65,255,255, 84, 1, 0,128,210,
|
||||
/* 0x0960 */ 226, 3, 24, 42,227, 3, 1,170,228, 3, 1,170,229, 3, 1,170,
|
||||
/* 0x0970 */ 166,163, 1,145,224, 3, 19,170,191, 55, 0,249,212,254,255,151,
|
||||
/* 0x0980 */ 246, 3, 0,170,162, 55, 64,249,224, 3, 20,170,225, 0,128, 82,
|
||||
/* 0x0990 */ 89,254,255,151,224, 3, 24, 42, 48,254,255,151,181,226, 0,145,
|
||||
/* 0x09a0 */ 247, 6, 0, 17,217,255,255, 23,224, 3, 22,170,243, 83, 65,169,
|
||||
/* 0x09b0 */ 245, 91, 66,169,247, 99, 67,169,253,123,202,168,192, 3, 95,214
|
||||
};
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
/*und*/ : "lr"); \
|
||||
dprintf(r_fmt, args); \
|
||||
})
|
||||
#elif defined(__x86_64) //{
|
||||
#elif defined(__x86_64) //}{
|
||||
#define DPRINTF(fmt, args...) ({ \
|
||||
char const *r_fmt; \
|
||||
asm("call 0f; .asciz \"" fmt "\"; 0: pop %0" \
|
||||
|
|
|
@ -91,34 +91,37 @@ _start: .globl _start
|
|||
|
||||
adr x12,start_params -4 // &sz_pack2
|
||||
ldp w29,w10,[x12] // w29= sz_pack2; w10= LENF
|
||||
ldp w11,w13,[x12,#2*4] // w11= CPRO; w13= MFLG
|
||||
ldp w11,w3,[x12,#2*4] // w11= CPRO; w3= MFLG
|
||||
add x11,x11,x12 // cpr0
|
||||
ldr x0,[x12,#4*4] // ADRM
|
||||
add x10,x10,x12 // end_decompress
|
||||
ldr w3,[x11,# sz_unc]
|
||||
sub x12,x12,w29,uxtw // &our_Elf64_Ehdr
|
||||
add w1,w29,w3 // sz_pack2 + cpr0.sz_unc
|
||||
ldr w4,[x11,# sz_unc]
|
||||
ldr w27,[x11,#o_binfo - cpr0] // O_BINFO
|
||||
sub x26,x12,w29,uxtw // &our_Elf64_Ehdr
|
||||
add x27,x27,x26 // &b_info for Elf64_Ehdr
|
||||
add w1,w29,w4 // sz_pack2 + cpr0.sz_unc
|
||||
add x1,x1,# PAGE_SIZE
|
||||
section LUNMP000
|
||||
// unused
|
||||
section LUNMP001
|
||||
// unused
|
||||
|
||||
// It would be nice to choose a random address (x0= 0; x3 &~ MAP_FIXED).
|
||||
// But the kernel might put the region in the "hole" between compressed .text
|
||||
// and brk(0). The compressor could layout PT_LOAD[1] to cover that
|
||||
// entire region, but that might leave a mapping that covers a deliberate
|
||||
// hole between .text and .data. [Can be fixed with PROT_NONE for .p_flags ?]
|
||||
section ELFMAINXu
|
||||
PUSH4(x0,x26,x2,x13) // ADRU, LENU, space for sz_unc, MFLG
|
||||
SP_MFLG= 4*8
|
||||
D_sz_unc=2*8 // stack displacement to sz_unc
|
||||
mov w1,w26 // length
|
||||
mov w2,#PROT_READ | PROT_WRITE | PROT_EXEC
|
||||
orr w3,w13,#MAP_FIXED // MFLG: MAP_{PRIVATE|ANON}
|
||||
orr w3,w3,#MAP_FIXED // MFLG: MAP_{PRIVATE|ANON}
|
||||
mov x5,#0 // offset= 0
|
||||
mov w4,#-1 // fd= -1; cater to *BSD for fd when MAP_ANON
|
||||
do_sys __NR_mmap64
|
||||
PUSH4(x0,x1,x2,x3) // ADRU, LENU, space for sz_unc, MFLG
|
||||
SP_MFLG= 3*8
|
||||
D_sz_unc=2*8 // stack displacement to sz_unc
|
||||
#if DEBUG /*{*/
|
||||
TRACE(#2)
|
||||
#endif /*}*/
|
||||
cmn x0,#4096
|
||||
bcs msg_SELinux
|
||||
mov x9,x12 // &our_Elf64_Ehdr
|
||||
mov x9,x26 // &our_Elf64_Ehdr
|
||||
copy_cl: // copy decompressor and folded code
|
||||
add x5,x0,#64; // FIXME(memcheck) dc zva,x5 // clear FOLLOWING 64-byte line
|
||||
ldp x1,x2,[x9],#2*8
|
||||
|
|
|
@ -65,9 +65,10 @@ PATH_MAX= 4096
|
|||
fold_begin:
|
||||
//// brk #0 // DEBUG
|
||||
/* In:
|
||||
x28= f_decompress
|
||||
x26= &Elf64_Ehdr
|
||||
x27= &b_info of first compressed block (after move)
|
||||
w26= total size of compressed data
|
||||
x28= f_decompress
|
||||
w29= total size of compressed data
|
||||
sp/ ADRU,LENU,sz_unc,MFLG, argc,argv...
|
||||
*/
|
||||
POP4(x3,x4,x5,x8) // x3= ADRU; x4= LENU; x5= sz_unc; x8= MFLG
|
||||
|
@ -131,13 +132,13 @@ SP_argc= 4*8 // remember the hole from PUSH3
|
|||
0:
|
||||
|
||||
/* Construct arglist for upx_main */
|
||||
add x6,sp,#3*8 // &reloc
|
||||
mov x6,x26 // Elf64_Ehdr (reloc if ET_DYN and not pre-link)
|
||||
sub sp,sp,#MAX_ELF_HDR + OVERHEAD // alloca
|
||||
adr x5,f_unfilter
|
||||
mov x4,x28 // f_decompress
|
||||
mov x3,x7 // new &Elf64_auxv_t
|
||||
mov x2,sp // ehdr
|
||||
mov w1,w26 // total size of compressed data
|
||||
mov w1,w29 // total size of compressed data
|
||||
mov x0,x27 // &b_info
|
||||
bl upx_main
|
||||
add sp,sp,#MAX_ELF_HDR + OVERHEAD // un-alloca
|
||||
|
|
|
@ -32,6 +32,49 @@
|
|||
|
||||
#include "include/linux.h"
|
||||
|
||||
#ifndef DEBUG //{
|
||||
#define DEBUG 0
|
||||
#endif //}
|
||||
|
||||
#if !DEBUG //{
|
||||
#define DPRINTF(fmt, args...) /*empty*/
|
||||
#else //}{
|
||||
// DPRINTF is defined as an expression using "({ ... })"
|
||||
// so that DPRINTF can be invoked inside an expression,
|
||||
// and then followed by a comma to ignore the return value.
|
||||
// The only complication is that percent and backslash
|
||||
// must be doubled in the format string, because the format
|
||||
// string is processd twice: once at compile-time by 'asm'
|
||||
// to produce the assembled value, and once at runtime to use it.
|
||||
#if defined(__powerpc__) //{
|
||||
#define DPRINTF(fmt, args...) ({ \
|
||||
char const *r_fmt; \
|
||||
asm("bl 0f; .string \"" fmt "\"; .balign 4; 0: mflr %0" \
|
||||
/*out*/ : "=r"(r_fmt) \
|
||||
/* in*/ : \
|
||||
/*und*/ : "lr"); \
|
||||
dprintf(r_fmt, args); \
|
||||
})
|
||||
#elif defined(__x86_64) //}{
|
||||
#define DPRINTF(fmt, args...) ({ \
|
||||
char const *r_fmt; \
|
||||
asm("call 0f; .asciz \"" fmt "\"; 0: pop %0" \
|
||||
/*out*/ : "=r"(r_fmt) ); \
|
||||
dprintf(r_fmt, args); \
|
||||
})
|
||||
#elif defined(__AARCH64EL__) //}{
|
||||
#define DPRINTF(fmt, args...) ({ \
|
||||
char const *r_fmt; \
|
||||
asm("bl 0f; .string \"" fmt "\"; .balign 4; 0: mov %0,x30" \
|
||||
/*out*/ : "=r"(r_fmt) \
|
||||
/* in*/ : \
|
||||
/*und*/ : "x30"); \
|
||||
dprintf(r_fmt, args); \
|
||||
})
|
||||
#endif //}
|
||||
|
||||
static int dprintf(char const *fmt, ...); // forward
|
||||
#endif /*}*/
|
||||
|
||||
/*************************************************************************
|
||||
// configuration section
|
||||
|
@ -210,8 +253,11 @@ upx_bzero(char *p, size_t len)
|
|||
static void
|
||||
auxv_up(Elf64_auxv_t *av, unsigned const type, uint64_t const value)
|
||||
{
|
||||
if (av)
|
||||
if (!av)
|
||||
return;
|
||||
DPRINTF("\\nauxv_up %%d %%p\\n", type, value);
|
||||
for (;; ++av) {
|
||||
DPRINTF(" %%d %%p\\n", av->a_type, av->a_un.a_val);
|
||||
if (av->a_type==type || (av->a_type==AT_IGNORE && type!=AT_NULL)) {
|
||||
av->a_type = type;
|
||||
av->a_un.a_val = value;
|
||||
|
@ -279,6 +325,7 @@ do_xmap(
|
|||
char *v_brk;
|
||||
unsigned long const reloc = xfind_pages(
|
||||
((ET_DYN!=ehdr->e_type) ? MAP_FIXED : 0), phdr, ehdr->e_phnum, &v_brk);
|
||||
DPRINTF("do_xmap reloc=%%p", reloc);
|
||||
int j;
|
||||
for (j=0; j < ehdr->e_phnum; ++phdr, ++j)
|
||||
if (xi && PT_PHDR==phdr->p_type) {
|
||||
|
@ -355,12 +402,9 @@ upx_main( // returns entry address
|
|||
/*x3*/ Elf64_auxv_t *const av,
|
||||
/*x4*/ f_expand *const f_decompress,
|
||||
/*x5*/ f_unfilter *const f_unf,
|
||||
/*x6*/ Elf64_Addr reloc // IN OUT; value result for ET_DYN
|
||||
/*x6*/ Elf64_Addr reloc
|
||||
)
|
||||
{
|
||||
Elf64_Phdr const *phdr = (Elf64_Phdr const *)(1+ ehdr);
|
||||
Elf64_Addr entry;
|
||||
|
||||
Extent xo, xi1, xi2;
|
||||
xo.buf = (char *)ehdr;
|
||||
xo.size = bi->sz_unc;
|
||||
|
@ -371,16 +415,35 @@ upx_main( // returns entry address
|
|||
unpackExtent(&xi2, &xo, f_decompress, 0); // never filtered?
|
||||
|
||||
// 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_PHDR , reloc + ehdr->e_phoff);
|
||||
auxv_up(av, AT_PHNUM, ehdr->e_phnum);
|
||||
//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);
|
||||
DPRINTF("upx_main1 .e_entry=%%p reloc=%%p", ehdr->e_entry, reloc);
|
||||
Elf64_Phdr *phdr = (Elf64_Phdr *)(1+ ehdr);
|
||||
unsigned const orig_e_type = ehdr->e_type;
|
||||
if (ET_DYN==orig_e_type /*&& phdr->p_vaddr==0*/) { // -pie /*FIXME: and not pre-linked*/
|
||||
// Unpacked must start at same place as packed, so that brk(0) works.
|
||||
ehdr->e_type = ET_EXEC;
|
||||
auxv_up(av, AT_ENTRY, ehdr->e_entry += reloc);
|
||||
unsigned j;
|
||||
for (j=0; j < ehdr->e_phnum; ++phdr, ++j) {
|
||||
phdr->p_vaddr += reloc;
|
||||
phdr->p_paddr += reloc;
|
||||
}
|
||||
}
|
||||
|
||||
// De-compress Ehdr again into actual position, then de-compress the rest.
|
||||
Elf64_Addr entry = do_xmap(ehdr, &xi1, 0, av, f_decompress, f_unf, &reloc);
|
||||
DPRINTF("upx_main2 entry=%%p reloc=%%p", entry, reloc);
|
||||
if (ET_DYN!=orig_e_type) {
|
||||
auxv_up(av, AT_ENTRY , entry);
|
||||
}
|
||||
|
||||
{ // Map PT_INTERP program interpreter
|
||||
int j;
|
||||
phdr = (Elf64_Phdr *)(1+ ehdr);
|
||||
unsigned j;
|
||||
for (j=0; j < ehdr->e_phnum; ++phdr, ++j) if (PT_INTERP==phdr->p_type) {
|
||||
char const *const iname = reloc + (char const *)phdr->p_vaddr;
|
||||
int const fdi = open(iname, O_RDONLY, 0);
|
||||
|
@ -394,7 +457,7 @@ ERR_LAB
|
|||
{
|
||||
Elf64_Addr i_reloc = 0;
|
||||
entry = do_xmap(ehdr, 0, fdi, 0, 0, 0, &i_reloc);
|
||||
auxv_up(av, AT_BASE, i_reloc);
|
||||
auxv_up(av, AT_BASE, i_reloc); // musl
|
||||
}
|
||||
close(fdi);
|
||||
}
|
||||
|
@ -403,4 +466,111 @@ ERR_LAB
|
|||
return (void *)entry;
|
||||
}
|
||||
|
||||
#if DEBUG //{
|
||||
|
||||
static int
|
||||
unsimal(unsigned x, char *ptr, int n)
|
||||
{
|
||||
unsigned m = 10;
|
||||
while (10 <= (x / m)) m *= 10;
|
||||
while (10 <= x) {
|
||||
unsigned d = x / m;
|
||||
x -= m * d;
|
||||
m /= 10;
|
||||
ptr[n++] = '0' + d;
|
||||
}
|
||||
ptr[n++] = '0' + x;
|
||||
return n;
|
||||
}
|
||||
|
||||
static int
|
||||
decimal(int x, char *ptr, int n)
|
||||
{
|
||||
if (x < 0) {
|
||||
x = -x;
|
||||
ptr[n++] = '-';
|
||||
}
|
||||
return unsimal(x, ptr, n);
|
||||
}
|
||||
|
||||
static int
|
||||
heximal(unsigned long x, char *ptr, int n)
|
||||
{
|
||||
unsigned j = -1+ 2*sizeof(unsigned long);
|
||||
unsigned long m = 0xful << (4 * j);
|
||||
for (; j; --j, m >>= 4) { // omit leading 0 digits
|
||||
if (m & x) break;
|
||||
}
|
||||
for (; m; --j, m >>= 4) {
|
||||
unsigned d = 0xf & (x >> (4 * j));
|
||||
ptr[n++] = ((10<=d) ? ('a' - 10) : '0') + d;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
#define va_arg __builtin_va_arg
|
||||
#define va_end __builtin_va_end
|
||||
#define va_list __builtin_va_list
|
||||
#define va_start __builtin_va_start
|
||||
|
||||
static int
|
||||
dprintf(char const *fmt, ...)
|
||||
{
|
||||
int n= 0;
|
||||
char const *literal = 0; // NULL
|
||||
char buf[24]; // ~0ull == 18446744073709551615 ==> 20 chars
|
||||
va_list va; va_start(va, fmt);
|
||||
for (;;) {
|
||||
char c = *fmt++;
|
||||
if (!c) { // end of fmt
|
||||
if (literal) {
|
||||
goto finish;
|
||||
}
|
||||
break; // goto done
|
||||
}
|
||||
if ('%'!=c) {
|
||||
if (!literal) {
|
||||
literal = fmt; // 1 beyond start of literal
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// '%' == c
|
||||
if (literal) {
|
||||
finish:
|
||||
n += write(2, -1+ literal, fmt - literal);
|
||||
literal = 0; // NULL
|
||||
if (!c) { // fmt already ended
|
||||
break; // goto done
|
||||
}
|
||||
}
|
||||
switch (c= *fmt++) { // deficiency: does not handle _long_
|
||||
default: { // un-implemented conversion
|
||||
n+= write(2, -1+ fmt, 1);
|
||||
} break;
|
||||
case 0: { // fmt ends with "%\0" ==> ignore
|
||||
goto done;
|
||||
} break;
|
||||
case 'u': {
|
||||
n+= write(2, buf, unsimal(va_arg(va, unsigned), buf, 0));
|
||||
} break;
|
||||
case 'd': {
|
||||
n+= write(2, buf, decimal(va_arg(va, int), buf, 0));
|
||||
} break;
|
||||
case 'p': {
|
||||
buf[0] = '0';
|
||||
buf[1] = 'x';
|
||||
n+= write(2, buf, heximal((unsigned long)va_arg(va, void *), buf, 2));
|
||||
} break;
|
||||
case 'x': {
|
||||
buf[0] = '0';
|
||||
buf[1] = 'x';
|
||||
n+= write(2, buf, heximal(va_arg(va, int), buf, 2));
|
||||
} break;
|
||||
} // 'switch'
|
||||
}
|
||||
done:
|
||||
va_end(va);
|
||||
return n;
|
||||
}
|
||||
#endif //}
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
|
|
@ -2,27 +2,23 @@ file format elf64-littleaarch64
|
|||
|
||||
Sections:
|
||||
Idx Name Size VMA LMA File off Algn Flags
|
||||
0 ELFMAINX 0000003c 0000000000000000 0000000000000000 00000040 2**0 CONTENTS, RELOC, READONLY
|
||||
1 LUNMP000 00000000 0000000000000000 0000000000000000 0000007c 2**0 CONTENTS, READONLY
|
||||
2 LUNMP001 00000000 0000000000000000 0000000000000000 0000007c 2**0 CONTENTS, READONLY
|
||||
3 ELFMAINXu 000000a0 0000000000000000 0000000000000000 0000007c 2**0 CONTENTS, RELOC, READONLY
|
||||
4 NRV_HEAD 00000000 0000000000000000 0000000000000000 0000011c 2**0 CONTENTS, READONLY
|
||||
5 NRV_TAIL 00000000 0000000000000000 0000000000000000 0000011c 2**0 CONTENTS, READONLY
|
||||
6 NRV2E 00000128 0000000000000000 0000000000000000 0000011c 2**0 CONTENTS, READONLY
|
||||
7 NRV2D 0000011c 0000000000000000 0000000000000000 00000244 2**0 CONTENTS, READONLY
|
||||
8 NRV2B 000000f0 0000000000000000 0000000000000000 00000360 2**0 CONTENTS, READONLY
|
||||
9 LZMA_ELF00 000000d0 0000000000000000 0000000000000000 00000450 2**0 CONTENTS, RELOC, READONLY
|
||||
10 LZMA_DEC20 00000968 0000000000000000 0000000000000000 00000520 2**0 CONTENTS, READONLY
|
||||
11 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000e88 2**0 CONTENTS, READONLY
|
||||
12 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001324 2**0 CONTENTS, READONLY
|
||||
13 ELFMAINY 0000003e 0000000000000000 0000000000000000 00001324 2**0 CONTENTS, READONLY
|
||||
14 ELFMAINZ 00000004 0000000000000000 0000000000000000 00001362 2**0 CONTENTS, RELOC, READONLY
|
||||
0 ELFMAINX 00000044 0000000000000000 0000000000000000 00000040 2**0 CONTENTS, RELOC, READONLY
|
||||
1 ELFMAINXu 0000009c 0000000000000000 0000000000000000 00000084 2**0 CONTENTS, RELOC, READONLY
|
||||
2 NRV_HEAD 00000000 0000000000000000 0000000000000000 00000120 2**0 CONTENTS, READONLY
|
||||
3 NRV_TAIL 00000000 0000000000000000 0000000000000000 00000120 2**0 CONTENTS, READONLY
|
||||
4 NRV2E 00000128 0000000000000000 0000000000000000 00000120 2**0 CONTENTS, READONLY
|
||||
5 NRV2D 0000011c 0000000000000000 0000000000000000 00000248 2**0 CONTENTS, READONLY
|
||||
6 NRV2B 000000f0 0000000000000000 0000000000000000 00000364 2**0 CONTENTS, READONLY
|
||||
7 LZMA_ELF00 000000d0 0000000000000000 0000000000000000 00000454 2**0 CONTENTS, RELOC, READONLY
|
||||
8 LZMA_DEC20 00000968 0000000000000000 0000000000000000 00000524 2**0 CONTENTS, READONLY
|
||||
9 LZMA_DEC10 0000049c 0000000000000000 0000000000000000 00000e8c 2**0 CONTENTS, READONLY
|
||||
10 LZMA_DEC30 00000000 0000000000000000 0000000000000000 00001328 2**0 CONTENTS, READONLY
|
||||
11 ELFMAINY 0000003e 0000000000000000 0000000000000000 00001328 2**0 CONTENTS, READONLY
|
||||
12 ELFMAINZ 00000004 0000000000000000 0000000000000000 00001366 2**0 CONTENTS, RELOC, READONLY
|
||||
SYMBOL TABLE:
|
||||
0000000000000000 l d LZMA_DEC30 0000000000000000 LZMA_DEC30
|
||||
0000000000000000 l d ELFMAINY 0000000000000000 ELFMAINY
|
||||
0000000000000000 l d ELFMAINX 0000000000000000 ELFMAINX
|
||||
0000000000000000 l d LUNMP000 0000000000000000 LUNMP000
|
||||
0000000000000000 l d LUNMP001 0000000000000000 LUNMP001
|
||||
0000000000000000 l d ELFMAINXu 0000000000000000 ELFMAINXu
|
||||
0000000000000000 l d NRV_HEAD 0000000000000000 NRV_HEAD
|
||||
0000000000000000 l d NRV_TAIL 0000000000000000 NRV_TAIL
|
||||
|
@ -38,13 +34,13 @@ SYMBOL TABLE:
|
|||
0000000000000000 *UND* 0000000000000000 MFLG
|
||||
0000000000000000 *UND* 0000000000000000 ADRM
|
||||
0000000000000014 g ELFMAINX 0000000000000000 _start
|
||||
0000000000000004 g ELFMAINZ 0000000000000000 cpr0
|
||||
0000000000000000 g F NRV2E 0000000000000128 ucl_nrv2e_decompress_32
|
||||
0000000000000000 g F NRV2D 000000000000011c ucl_nrv2d_decompress_32
|
||||
0000000000000000 g F NRV2B 00000000000000f0 ucl_nrv2b_decompress_32
|
||||
0000000000000000 g LZMA_DEC10 0000000000000000 LzmaDecode
|
||||
0000000000000000 g ELFMAINY 0000000000000000 end_decompress
|
||||
0000000000000000 *UND* 0000000000000000 O_BINFO
|
||||
0000000000000004 g ELFMAINZ 0000000000000000 cpr0
|
||||
|
||||
RELOCATION RECORDS FOR [ELFMAINX]:
|
||||
OFFSET TYPE VALUE
|
||||
|
@ -55,7 +51,7 @@ OFFSET TYPE VALUE
|
|||
|
||||
RELOCATION RECORDS FOR [ELFMAINXu]:
|
||||
OFFSET TYPE VALUE
|
||||
0000000000000028 R_AARCH64_CONDBR19 ELFMAINY
|
||||
0000000000000024 R_AARCH64_CONDBR19 ELFMAINY
|
||||
|
||||
RELOCATION RECORDS FOR [LZMA_ELF00]:
|
||||
OFFSET TYPE VALUE
|
||||
|
|
|
@ -8,7 +8,7 @@ Linker script and memory map
|
|||
|
||||
0x00000000001000bc . = ((0x100000 + SIZEOF_HEADERS) + 0xc)
|
||||
|
||||
.text 0x00000000001000bc 0x878
|
||||
.text 0x00000000001000bc 0x904
|
||||
*(.text)
|
||||
.text 0x00000000001000bc 0x238 tmp/arm64-linux.elf-fold.o
|
||||
0x0000000000100230 my_bkpt
|
||||
|
@ -26,26 +26,26 @@ Linker script and memory map
|
|||
0x00000000001002bc readlink
|
||||
0x00000000001002c4 open
|
||||
0x00000000001002e0 __clear_cache
|
||||
.text 0x00000000001002f4 0x640 tmp/arm64-linux.elf-main.o
|
||||
.text 0x00000000001002f4 0x6cc tmp/arm64-linux.elf-main.o
|
||||
0x00000000001007c4 upx_main
|
||||
*(.data)
|
||||
.data 0x0000000000100934 0x0 tmp/arm64-linux.elf-fold.o
|
||||
.data 0x0000000000100934 0x0 tmp/arm64-linux.elf-main.o
|
||||
.data 0x00000000001009c0 0x0 tmp/arm64-linux.elf-fold.o
|
||||
.data 0x00000000001009c0 0x0 tmp/arm64-linux.elf-main.o
|
||||
|
||||
.iplt 0x0000000000100934 0x0
|
||||
.iplt 0x0000000000100934 0x0 tmp/arm64-linux.elf-fold.o
|
||||
.iplt 0x00000000001009c0 0x0
|
||||
.iplt 0x00000000001009c0 0x0 tmp/arm64-linux.elf-fold.o
|
||||
|
||||
.rela.dyn 0x0000000000100938 0x0
|
||||
.rela.iplt 0x0000000000100938 0x0 tmp/arm64-linux.elf-fold.o
|
||||
.rela.dyn 0x00000000001009c0 0x0
|
||||
.rela.iplt 0x00000000001009c0 0x0 tmp/arm64-linux.elf-fold.o
|
||||
|
||||
.data
|
||||
LOAD tmp/arm64-linux.elf-fold.o
|
||||
LOAD tmp/arm64-linux.elf-main.o
|
||||
OUTPUT(tmp/arm64-linux.elf-fold.bin elf64-littleaarch64)
|
||||
|
||||
.igot.plt 0x0000000000100938 0x0
|
||||
.igot.plt 0x0000000000100938 0x0 tmp/arm64-linux.elf-fold.o
|
||||
.igot.plt 0x00000000001009c0 0x0
|
||||
.igot.plt 0x00000000001009c0 0x0 tmp/arm64-linux.elf-fold.o
|
||||
|
||||
.bss 0x0000000000100934 0x0
|
||||
.bss 0x0000000000100934 0x0 tmp/arm64-linux.elf-fold.o
|
||||
.bss 0x0000000000100934 0x0 tmp/arm64-linux.elf-main.o
|
||||
.bss 0x00000000001009c0 0x0
|
||||
.bss 0x00000000001009c0 0x0 tmp/arm64-linux.elf-fold.o
|
||||
.bss 0x00000000001009c0 0x0 tmp/arm64-linux.elf-main.o
|
||||
|
|
Loading…
Reference in New Issue
Block a user