msync() and UMF_LINUX fiddling
modified: p_lx_elf.cpp modified: stub/src/amd64-linux.elf-entry.S modified: stub/src/amd64-linux.elf-so_fold.S modified: stub/src/arm.v4a-linux.elf-entry.S modified: stub/src/arm.v4a-linux.elf-entry.lds modified: stub/src/arm.v4a-linux.elf-fold.S modified: stub/src/arm.v4a-linux.elf-so_entry.S modified: stub/src/arm64-linux.elf-so_fold.S modified: stub/src/mips.r3000-linux.elf-entry.lds modified: stub/src/mipsel.r3000-linux.elf-entry.S modified: stub/src/mipsel.r3000-linux.elf-entry.lds modified: stub/src/mipsel.r3000-linux.elf-fold.S modified: stub/src/upxfd_linux.c
This commit is contained in:
parent
f7f08be312
commit
68b31d31c3
@ -1487,14 +1487,10 @@ PackLinuxElf32::buildLinuxLoader(
|
|||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "EXP_TAIL");
|
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "EXP_TAIL");
|
||||||
// End of daisy-chain fall-through.
|
// End of daisy-chain fall-through.
|
||||||
|
|
||||||
if (this->e_machine==Elf32_Ehdr::EM_386
|
len += snprintf(&sec[len], sizeof(sec) - len, ",%s",
|
||||||
|| this->e_machine==Elf32_Ehdr::EM_ARM) {
|
(sec_arm_attr || is_asl || opt->o_unix.android_shlib)
|
||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s",
|
? "UMF_ANDROID"
|
||||||
(opt->o_unix.android_old ? "UMF_ANDROID" : "UMF_LINUX"));
|
: "UMF_LINUX");
|
||||||
}
|
|
||||||
else {
|
|
||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "UMF_LINUX");
|
|
||||||
}
|
|
||||||
if (hasLoaderSection("STRCON")) {
|
if (hasLoaderSection("STRCON")) {
|
||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "STRCON");
|
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "STRCON");
|
||||||
}
|
}
|
||||||
@ -1536,14 +1532,10 @@ PackLinuxElf32::buildLinuxLoader(
|
|||||||
"LZMA_DAISY,LZMA_ELF00,LZMA_DEC20,LZMA_DEC30");
|
"LZMA_DAISY,LZMA_ELF00,LZMA_DEC20,LZMA_DEC30");
|
||||||
}
|
}
|
||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "EXP_TAIL");
|
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "EXP_TAIL");
|
||||||
if (this->e_machine==Elf32_Ehdr::EM_386
|
len += snprintf(&sec[len], sizeof(sec) - len, ",%s",
|
||||||
|| this->e_machine==Elf32_Ehdr::EM_ARM) {
|
(sec_arm_attr || is_asl || opt->o_unix.android_shlib)
|
||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s",
|
? "UMF_ANDROID"
|
||||||
(opt->o_unix.android_old ? "UMF_ANDROID" : "UMF_LINUX"));
|
: "UMF_LINUX");
|
||||||
}
|
|
||||||
else {
|
|
||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "UMF_LINUX");
|
|
||||||
}
|
|
||||||
if (hasLoaderSection("SYSCALLS")) {
|
if (hasLoaderSection("SYSCALLS")) {
|
||||||
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "SYSCALLS");
|
len += snprintf(&sec[len], sizeof(sec) - len, ",%s", "SYSCALLS");
|
||||||
}
|
}
|
||||||
@ -1605,13 +1597,9 @@ PackLinuxElf32::buildLinuxLoader(
|
|||||||
)
|
)
|
||||||
) { // shlib with ELF2 de-compressor
|
) { // shlib with ELF2 de-compressor
|
||||||
addLoader("ELFMAINX");
|
addLoader("ELFMAINX");
|
||||||
if (this->e_machine==Elf32_Ehdr::EM_386
|
addLoader((sec_arm_attr || is_asl || opt->o_unix.android_shlib)
|
||||||
|| this->e_machine==Elf32_Ehdr::EM_ARM) {
|
? "UMF_ANDROID"
|
||||||
addLoader((opt->o_unix.android_old ? "UMF_ANDROID" : "UMF_LINUX"));
|
: "UMF_LINUX");
|
||||||
}
|
|
||||||
else {
|
|
||||||
addLoader("UMF_LINUX");
|
|
||||||
}
|
|
||||||
addLoader("ELFMAINZ,FOLDEXEC,IDENTSTR");
|
addLoader("ELFMAINZ,FOLDEXEC,IDENTSTR");
|
||||||
}
|
}
|
||||||
else if (this->e_machine==Elf32_Ehdr::EM_NONE
|
else if (this->e_machine==Elf32_Ehdr::EM_NONE
|
||||||
@ -1621,10 +1609,9 @@ PackLinuxElf32::buildLinuxLoader(
|
|||||||
|| this->e_machine==Elf32_Ehdr::EM_MIPS
|
|| this->e_machine==Elf32_Ehdr::EM_MIPS
|
||||||
) { // main program with ELF2 de-compressor
|
) { // main program with ELF2 de-compressor
|
||||||
addLoader("ELFMAINX");
|
addLoader("ELFMAINX");
|
||||||
if (this->e_machine==Elf32_Ehdr::EM_386
|
addLoader((sec_arm_attr || is_asl || opt->o_unix.android_shlib)
|
||||||
|| this->e_machine==Elf32_Ehdr::EM_ARM) {
|
? "UMF_ANDROID"
|
||||||
addLoader((opt->o_unix.android_old ? "UMF_ANDROID" : "UMF_LINUX"));
|
: "UMF_LINUX");
|
||||||
}
|
|
||||||
addLoader("ELFMAINZ,FOLDEXEC,IDENTSTR");
|
addLoader("ELFMAINZ,FOLDEXEC,IDENTSTR");
|
||||||
defineSymbols(ft);
|
defineSymbols(ft);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,7 @@ __NR_ftruncate= 77
|
|||||||
__NR_exit= 60
|
__NR_exit= 60
|
||||||
__NR_mprotect= 10
|
__NR_mprotect= 10
|
||||||
__NR_mmap= 9
|
__NR_mmap= 9
|
||||||
|
__NR_msync= 26 // 0x1a
|
||||||
__NR_close= 3
|
__NR_close= 3
|
||||||
__NR_open= 2
|
__NR_open= 2
|
||||||
__NR_write= 1
|
__NR_write= 1
|
||||||
|
|||||||
@ -103,6 +103,7 @@ __NR_close= 3
|
|||||||
|
|
||||||
__NR_mmap= 9
|
__NR_mmap= 9
|
||||||
__NR_mprotect= 10
|
__NR_mprotect= 10
|
||||||
|
__NR_msync= 26 // 0x1a
|
||||||
__NR_munmap= 11
|
__NR_munmap= 11
|
||||||
__NR_mremap= 216
|
__NR_mremap= 216
|
||||||
__NR_memfd_create= 0x13f // 319
|
__NR_memfd_create= 0x13f // 319
|
||||||
@ -169,6 +170,8 @@ ftruncate: .globl ftruncate
|
|||||||
push $__NR_ftruncate; 5: jmp 5f
|
push $__NR_ftruncate; 5: jmp 5f
|
||||||
memfd_create: .globl memfd_create
|
memfd_create: .globl memfd_create
|
||||||
push $__NR_memfd_create; 5: jmp 5f
|
push $__NR_memfd_create; 5: jmp 5f
|
||||||
|
msync: .globl msync
|
||||||
|
push $__NR_msync; 5: jmp 5f
|
||||||
close: .globl close
|
close: .globl close
|
||||||
push $ __NR_close; 5: jmp 5f
|
push $ __NR_close; 5: jmp 5f
|
||||||
openat: .globl openat
|
openat: .globl openat
|
||||||
|
|||||||
@ -93,6 +93,7 @@ __NR_memfd_create= 385 + __NR_SYSCALL_BASE
|
|||||||
__NR_mkdir= 39 + __NR_SYSCALL_BASE
|
__NR_mkdir= 39 + __NR_SYSCALL_BASE
|
||||||
__NR_mmap2= 192 + __NR_SYSCALL_BASE
|
__NR_mmap2= 192 + __NR_SYSCALL_BASE
|
||||||
__NR_mprotect=125 + __NR_SYSCALL_BASE
|
__NR_mprotect=125 + __NR_SYSCALL_BASE
|
||||||
|
__NR_msync= 144 + __NR_SYSCALL_BASE // 0x90
|
||||||
__NR_open= 5 + __NR_SYSCALL_BASE
|
__NR_open= 5 + __NR_SYSCALL_BASE
|
||||||
__NR_read= 3 + __NR_SYSCALL_BASE
|
__NR_read= 3 + __NR_SYSCALL_BASE
|
||||||
__NR_stat= 106 + __NR_SYSCALL_BASE
|
__NR_stat= 106 + __NR_SYSCALL_BASE
|
||||||
@ -377,6 +378,7 @@ mempcpy: .globl mempcpy // (dst, src, n)
|
|||||||
.globl getpid; getpid: do_sys __NR_getpid; ret
|
.globl getpid; getpid: do_sys __NR_getpid; ret
|
||||||
.globl lseek; lseek: do_sys __NR_lseek; ret
|
.globl lseek; lseek: do_sys __NR_lseek; ret
|
||||||
.globl mkdir; mkdir: do_sys __NR_mkdir; ret
|
.globl mkdir; mkdir: do_sys __NR_mkdir; ret
|
||||||
|
.globl msync; msync: do_sys __NR_msync; ret
|
||||||
.globl open; open: do_sys __NR_open; ret
|
.globl open; open: do_sys __NR_open; ret
|
||||||
.globl read; read: do_sys __NR_read; ret
|
.globl read; read: do_sys __NR_read; ret
|
||||||
.globl stat; stat: do_sys __NR_stat; ret
|
.globl stat; stat: do_sys __NR_stat; ret
|
||||||
|
|||||||
@ -9,4 +9,7 @@ SECTIONS
|
|||||||
*(ELFMAINX)
|
*(ELFMAINX)
|
||||||
*(.text)
|
*(.text)
|
||||||
}
|
}
|
||||||
|
ELFMAINZ : {
|
||||||
|
*(ELFMAINZ)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -472,6 +472,7 @@ getpid:.globl getpid;do_sys __NR_getpid; ret
|
|||||||
lseek: .globl lseek; do_sys __NR_lseek; ret
|
lseek: .globl lseek; do_sys __NR_lseek; ret
|
||||||
memfd_create: .globl memfd_create; do_sys2 __NR_memfd_create; ret
|
memfd_create: .globl memfd_create; do_sys2 __NR_memfd_create; ret
|
||||||
mkdir: .globl mkdir; do_sys __NR_mkdir; ret
|
mkdir: .globl mkdir; do_sys __NR_mkdir; ret
|
||||||
|
msync: .globl msync; do_sys __NR_msync; ret
|
||||||
munmap: .globl munmap; do_sys __NR_munmap; ret // BEWARE: get_sys_munmap knows where 'svc' lives!
|
munmap: .globl munmap; do_sys __NR_munmap; ret // BEWARE: get_sys_munmap knows where 'svc' lives!
|
||||||
open: .globl open; do_sys __NR_open; ret
|
open: .globl open; do_sys __NR_open; ret
|
||||||
read: .globl read; do_sys __NR_read; ret
|
read: .globl read; do_sys __NR_read; ret
|
||||||
|
|||||||
@ -246,6 +246,7 @@ f_decompress:
|
|||||||
// MATCH_07 envp
|
// MATCH_07 envp
|
||||||
|
|
||||||
upx_mmap_and_fd: .globl upx_mmap_and_fd
|
upx_mmap_and_fd: .globl upx_mmap_and_fd
|
||||||
|
// UMF_LINX or UMF_ANDROID goes here
|
||||||
|
|
||||||
// IDENTSTR goes here
|
// IDENTSTR goes here
|
||||||
|
|
||||||
|
|||||||
@ -103,6 +103,7 @@ __NR_unlinkat = 0x23 + __NR_SYSCALL_BASE // 35
|
|||||||
|
|
||||||
__NR_mmap = 0xde + __NR_SYSCALL_BASE // 222
|
__NR_mmap = 0xde + __NR_SYSCALL_BASE // 222
|
||||||
__NR_mprotect = 0xe2 + __NR_SYSCALL_BASE // 226
|
__NR_mprotect = 0xe2 + __NR_SYSCALL_BASE // 226
|
||||||
|
__NR_msync = 0xe3 + __NR_SYSCALL_BASE // 227
|
||||||
__NR_munmap = 0xd7 + __NR_SYSCALL_BASE // 215
|
__NR_munmap = 0xd7 + __NR_SYSCALL_BASE // 215
|
||||||
__NR_memfd_create = 0x117 + __NR_SYSCALL_BASE // 279
|
__NR_memfd_create = 0x117 + __NR_SYSCALL_BASE // 279
|
||||||
__NR_ftruncate= 0x2e + __NR_SYSCALL_BASE // 46
|
__NR_ftruncate= 0x2e + __NR_SYSCALL_BASE // 46
|
||||||
@ -154,6 +155,9 @@ Punmap: .globl Punmap
|
|||||||
munmap: .globl munmap
|
munmap: .globl munmap
|
||||||
do_sys __NR_munmap; ret
|
do_sys __NR_munmap; ret
|
||||||
|
|
||||||
|
msync: .globl msync
|
||||||
|
do_sys __NR_msync; ret
|
||||||
|
|
||||||
// Sometimes Linux enforces page-aligned address
|
// Sometimes Linux enforces page-aligned address
|
||||||
Pprotect: .globl Pprotect
|
Pprotect: .globl Pprotect
|
||||||
mprotect: .globl mprotect
|
mprotect: .globl mprotect
|
||||||
|
|||||||
@ -9,4 +9,7 @@ SECTIONS
|
|||||||
*(ELFMAINX)
|
*(ELFMAINX)
|
||||||
*(.text)
|
*(.text)
|
||||||
}
|
}
|
||||||
|
ELFMAINZ : {
|
||||||
|
*(ELFMAINZ)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,9 +114,11 @@ M_NRV2E_LE32=8
|
|||||||
__NR_Linux = 4000
|
__NR_Linux = 4000
|
||||||
__NR_close = 6+ __NR_Linux
|
__NR_close = 6+ __NR_Linux
|
||||||
__NR_exit = 1+ __NR_Linux
|
__NR_exit = 1+ __NR_Linux
|
||||||
__NR_memfd_create= 354 + __NR_Linux
|
__NR_ftruncate= 93+ __NR_Linux
|
||||||
|
__NR_memfd_create= 354+ __NR_Linux
|
||||||
__NR_mmap = 90+ __NR_Linux
|
__NR_mmap = 90+ __NR_Linux
|
||||||
__NR_mprotect = 125+ __NR_Linux
|
__NR_mprotect = 125+ __NR_Linux
|
||||||
|
__NR_msync = 144+ __NR_LINUX
|
||||||
__NR_open = 5+ __NR_Linux
|
__NR_open = 5+ __NR_Linux
|
||||||
__NR_write = 4+ __NR_Linux
|
__NR_write = 4+ __NR_Linux
|
||||||
__NR_cacheflush = 147+ __NR_Linux
|
__NR_cacheflush = 147+ __NR_Linux
|
||||||
@ -185,10 +187,9 @@ eof_n2b:
|
|||||||
addiu sp,4
|
addiu sp,4
|
||||||
|
|
||||||
.balign 4
|
.balign 4
|
||||||
upx_mmap_and_fd:
|
upx_mmap_and_fd: .globl upx_mmap_and_fd
|
||||||
// section UMF_LINUX or UMF_ANDROID goes here
|
// section UMF_LINUX or UMF_ANDROID goes here
|
||||||
|
|
||||||
section ELFMAINZ
|
|
||||||
section ELFMAINZ; .set noreorder
|
section ELFMAINZ; .set noreorder
|
||||||
L72:
|
L72:
|
||||||
li a0,2 # fd stderr
|
li a0,2 # fd stderr
|
||||||
@ -261,6 +262,16 @@ unfold: # IN: $r_fexp,$r_auxv,$r_PMASK,$r_FOLD
|
|||||||
jr ra
|
jr ra
|
||||||
addu $r_ADRX,$r_elfa,$r_ADRX # compressed data
|
addu $r_ADRX,$r_elfa,$r_ADRX # compressed data
|
||||||
|
|
||||||
|
memfd_create: .globl memfd_create
|
||||||
|
li v0,__NR_memfd_create; syscall
|
||||||
|
j ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
ftruncate: .globl ftruncate
|
||||||
|
li v0,__NR_ftruncate; syscall
|
||||||
|
j ra
|
||||||
|
nop
|
||||||
|
|
||||||
zfind: # result in $r_auxv
|
zfind: # result in $r_auxv
|
||||||
lw v1,(a0); addiu a0,a0,NBPW
|
lw v1,(a0); addiu a0,a0,NBPW
|
||||||
bnez v1,zfind
|
bnez v1,zfind
|
||||||
|
|||||||
@ -9,4 +9,7 @@ SECTIONS
|
|||||||
*(ELFMAINX)
|
*(ELFMAINX)
|
||||||
*(.text)
|
*(.text)
|
||||||
}
|
}
|
||||||
|
ELFMAINZ : {
|
||||||
|
*(ELFMAINZ)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -391,7 +391,8 @@ mmap: .globl mmap
|
|||||||
b sysret
|
b sysret
|
||||||
addiu sp,sp,sp_frame
|
addiu sp,sp,sp_frame
|
||||||
|
|
||||||
sysgo:
|
sysgo: // src/mipsel.r3000-linux.elf-fold.S
|
||||||
|
sysgo2:
|
||||||
syscall
|
syscall
|
||||||
sysret:
|
sysret:
|
||||||
bgez a3,sysOK
|
bgez a3,sysOK
|
||||||
|
|||||||
@ -30,7 +30,7 @@ extern void my_bkpt(void const *, ...);
|
|||||||
#define ANDROID_FRIEND 0
|
#define ANDROID_FRIEND 0
|
||||||
#define addr_string(string) ({ \
|
#define addr_string(string) ({ \
|
||||||
char const *str; \
|
char const *str; \
|
||||||
asm("bal 0f; .asciz \"" string "\"; .balign 4\n0: move %0,$31" \
|
asm(".set noreorder; bal 0f; .asciz \"" string "\"; .balign 4\n0: move %0,$31; .set reorder" \
|
||||||
/*out*/ : "=r"(str) \
|
/*out*/ : "=r"(str) \
|
||||||
/* in*/ : \
|
/* in*/ : \
|
||||||
/*und*/ : "ra"); \
|
/*und*/ : "ra"); \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user