hacking UPX_F_LINUX_ELF32_MIPSEL

This commit is contained in:
John Reiser
2007-05-06 14:21:25 -07:00
parent 573009eeb6
commit 10a6370738
4 changed files with 694 additions and 700 deletions
+2 -2
View File
@@ -837,12 +837,12 @@ mipsel.r3000-linux.elf%.h : tc_bfdname = elf32-littlemips
mipsel.r3000-linux.elf-entry.h : $(srcdir)/src/$$T.S mipsel.r3000-linux.elf-entry.h : $(srcdir)/src/$$T.S
ifeq (1,1) ifeq (1,1)
# info: we really need as-2.17 here # info: we really need as-2.17 here
$(call tc,pp-as) -DPS1 $< -o - | $(RTRIM) > tmp/$T.i $(call tc,pp-as) $< -o - | $(RTRIM) > tmp/$T.i
$(call tc,as) tmp/$T.i -o tmp/$T.bin $(call tc,as) tmp/$T.i -o tmp/$T.bin
$(call tc,gpp_mkdep) --mode=c --MMD=$@ $< --MF=tmp/$T.d $(call tc,gpp_mkdep) --mode=c --MMD=$@ $< --MF=tmp/$T.d
else else
# info: as-2.16.1 as used by gcc-4.1.1 does _not_ work # info: as-2.16.1 as used by gcc-4.1.1 does _not_ work
$(call tc,gcc) -c -DPS1 -Wa,-O,-mno-pdr $< -o tmp/$T.bin $(call tc,gcc) -c -Wa,-O,-mno-pdr $< -o tmp/$T.bin
endif endif
$(call tc,f-embed_objinfo,tmp/$T.bin) $(call tc,f-embed_objinfo,tmp/$T.bin)
$(call tc,bin2h-c) tmp/$T.bin $@ $(call tc,bin2h-c) tmp/$T.bin $@
File diff suppressed because it is too large Load Diff
+39 -45
View File
@@ -59,11 +59,7 @@ PROT_EXEC= 4
MAP_PRIVATE= 2 MAP_PRIVATE= 2
MAP_FIXED= 0x10 MAP_FIXED= 0x10
MAP_ANONYMOUS= 0x1000 MAP_ANONYMOUS= 0x800
PAGE_SHIFT= 12
PAGE_MASK= (~0<<PAGE_SHIFT)
PAGE_SIZE= -PAGE_MASK
M_NRV2B_LE32=2 // ../conf.h M_NRV2B_LE32=2 // ../conf.h
M_NRV2D_LE32=5 M_NRV2D_LE32=5
@@ -82,6 +78,7 @@ lenu: .long LENU
adrx: .long ADRX adrx: .long ADRX
lenx: .long LENX lenx: .long LENX
_start: .globl _start _start: .globl _start
break
bal main bal main
addiu s7,ra, decompressor - 0f // s7= &decompress addiu s7,ra, decompressor - 0f // s7= &decompress
0: 0:
@@ -123,44 +120,46 @@ LZMA_BASE_NUM = 1846
LZMA_LIT_NUM = 768 LZMA_LIT_NUM = 768
lxlzma_szframe = 12*4 lxlzma_szframe = 12*4
lxlzma_oldsp = 11*4 lxlzma_sv_pc = 11*4
lxlzma_origdst = 10*4 lxlzma_sv_sp = 10*4
lxlzma_origsrc = 9*4 /* 9 */
lxlzma_dstdone = 8*4 lxlzma_dstdone = 8*4
lxlzma_srcdone = 7*4 lxlzma_srcdone = 7*4
lxlzma_pdstdone = 6*4 lxlzma_pdstdone = 6*4
lxlzma_dstlen = 5*4 lxlzma_dstlen = 5*4
lxlzma_dst = 4*4 lxlzma_dst = 4*4
lbu t0,0(lxsrc) # ((lit_context_bits + lit_pos_bits)<<3) | pos_bits lbu t0,0(lxsrc) # ((lit_context_bits + lit_pos_bits)<<3) | pos_bits
li tmp,-2*LZMA_LIT_NUM
lbu t1,1(lxsrc) # (lit_pos_bits<<4) | lit_context_bits lbu t1,1(lxsrc) # (lit_pos_bits<<4) | lit_context_bits
andi v0,t0,7 # pos_bits andi v0,t0,7 # pos_bits
srl t0,t0,3 # (lit_context_bits + lit_pos_bits) srl t0,t0,3 # (lit_context_bits + lit_pos_bits)
li tmp,-2*LZMA_LIT_NUM
sllv tmp,tmp,t0 sllv tmp,tmp,t0
addiu tmp,tmp,-4 - 2*LZMA_BASE_NUM - lxlzma_szframe addiu tmp,tmp,-4 - 2*LZMA_BASE_NUM - lxlzma_szframe
addu sp,sp,tmp addu sp,sp,tmp # alloca
sw tmp, lxlzma_oldsp(sp) # dynamic frame size sw tmp, lxlzma_sv_sp(sp) # dynamic frame size
addiu tmp,sp,lxlzma_dstdone addiu tmp,sp,lxlzma_dstdone
sw tmp, lxlzma_pdstdone(sp)
sw lxdstlen,lxlzma_dstlen(sp) sw lxdstlen,lxlzma_dstlen(sp)
sw lxdst, lxlzma_dst(sp) sw lxdst, lxlzma_dst(sp)
addiu a3,sp,lxlzma_srcdone addiu a3,sp,lxlzma_srcdone
move a2,lxsrclen sw ra,lxlzma_sv_pc(sp)
addiu a1,lxsrc,2 addiu a2,lxsrclen,-2 # 2 header bytes
sw tmp, lxlzma_pdstdone(sp)
addiu a1,lxsrc,2 # 2 header bytes
addiu a0,sp,lxlzma_szframe # &CLzamDecoderState addiu a0,sp,lxlzma_szframe # &CLzamDecoderState
sb v0,2(a0) # pos_bits sb v0,2(a0) # pos_bits
andi tmp,t1,0xf andi tmp,t1,0xf
sb tmp,0(a0) # lit_context_bits sb tmp,0(a0) # lit_context_bits
srl t1,t1,4 srl t1,t1,4
bal lzma_decode
sb t1,1(a0) # lit_pos_bits sb t1,1(a0) # lit_pos_bits
jalr s7 lw ra,lxlzma_sv_pc(sp)
lw tmp,lxlzma_sv_sp(sp)
lw tmp, lxlzma_oldsp(sp) jr ra
lw lxdst, lxlzma_origdst(sp) subu sp,sp,tmp # un_alloca
lw lxdstlen,lxlzma_dstdone(sp)
subu sp,tmp
lzma_decode:
#include "arch/mips/mipsel.r3000/lzma_d.S" #include "arch/mips/mipsel.r3000/lzma_d.S"
section LZMA_DEC30 section LZMA_DEC30
@@ -181,11 +180,11 @@ eof:
pop t0; sw s0,(t0) // actual length used t0 dst pop t0; sw s0,(t0) // actual length used t0 dst
pop t0; jr t0; nop pop t0; jr t0; nop
/* These from /usr/include/sys/syscall.h */ /* These from /usr/include/asm/unistd.h */
SYS_write = 4 __NR_Linux = 4000
SYS_exit = 1 __NR_write = 4+ __NR_Linux
SYS_mmap = 197 __NR_exit = 1+ __NR_Linux
SYS___syscall= 198 __NR_mmap = 90+ __NR_Linux
msg_SELinux: msg_SELinux:
addiu a2,zero,L71 - L70 // length addiu a2,zero,L71 - L70 // length
@@ -199,11 +198,11 @@ L71:
section ELFMAINZ section ELFMAINZ
L72: L72:
li a0,2 // fd stderr li a0,2 // fd stderr
li v0,SYS_write li v0,__NR_write
syscall syscall
die: die:
li a0,127 li a0,127
li v0,SYS_exit li v0,__NR_exit
syscall syscall
/* Decompress the rest of this loader, and jump to it. /* Decompress the rest of this loader, and jump to it.
@@ -226,26 +225,17 @@ unfold: // s7= &decompress; s6= &b_info(fold); s5= sz_pack2
the brk() of the _un_compressed program. The address and length are pre- the brk() of the _un_compressed program. The address and length are pre-
calculated by PackLinuxElf64amd::defineSymbols(). calculated by PackLinuxElf64amd::defineSymbols().
*/ */
#define a0_mmap a2 #define a4 0x10
#define a1_mmap a3 #define a5 0x14
#define a2_mmap 0x10
#define a3_mmap 0x14
#define a4_mmap 0x18
#define a5_mmap 0x1c
#define sp_frame 0x20 #define sp_frame 0x20
lw a0_mmap,adrm - decompressor(s7)
addiu sp,sp,-sp_frame addiu sp,sp,-sp_frame
lw a1_mmap,lenm - decompressor(s7) lw a0,adrm - decompressor(s7)
li t0, PROT_READ | PROT_WRITE | PROT_EXEC li a2, PROT_READ | PROT_WRITE | PROT_EXEC
sw t0,a2_mmap(sp) lw a1,lenm - decompressor(s7)
li t0, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS li a3, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS
sw t0,a3_mmap(sp) sw zero,a4(sp) //; sw zero,a5_mmap(sp) // MAP_ANON ==> ignore offset
li a1,0 li v0,__NR_mmap; syscall; bnez a3,err_syscall
sw zero,a4_mmap(sp) //; sw zero,a5_mmap(sp) // MAP_ANON ==> ignore offset
li a0,SYS_mmap
li v0,SYS___syscall
syscall // FIXME: check for error
move a0,v0 // &new page(s) move a0,v0 // &new page(s)
lw a1,adrc - decompressor(s7) lw a1,adrc - decompressor(s7)
@@ -269,9 +259,13 @@ L80:
lw t0,sz_unc(s6); move a3,sp; sw t0,0(sp) // &dst_len lw t0,sz_unc(s6); move a3,sp; sw t0,0(sp) // &dst_len
move a2,v0 // &dst move a2,v0 // &dst
lw a1,sz_cpr(s6) // src_len lw a1,sz_cpr(s6) // src_len
move a0,s6 // &b_info(fold) addiu a0,s6,sz_b_info
jr s7 // decompress(src, srclen, dst, &dstlen /*, method*/) jr s7 // decompress(src, srclen, dst, &dstlen /*, method*/)
move ra,a2 // return to decompressed code move ra,a2 // return to decompressed code
err_syscall:
b err_syscall
nop
main: main:
lw s5,sz_pack2 - decompressor(s7) // length before stub lw s5,sz_pack2 - decompressor(s7) // length before stub
bal unfold bal unfold
@@ -2,17 +2,17 @@ tmp/mipsel.r3000-linux.elf-entry.bin: file format elf32-littlemips
Sections: Sections:
Idx Name Size VMA LMA File off Algn Flags Idx Name Size VMA LMA File off Algn Flags
0 ELFMAINX 00000028 00000000 00000000 00000034 2**0 CONTENTS, RELOC, READONLY 0 ELFMAINX 0000002c 00000000 00000000 00000034 2**0 CONTENTS, RELOC, READONLY
1 NRV2E 00000218 00000000 00000000 0000005c 2**0 CONTENTS, RELOC, READONLY 1 NRV2E 00000218 00000000 00000000 00000060 2**0 CONTENTS, RELOC, READONLY
2 NRV2D 000001f0 00000000 00000000 00000274 2**0 CONTENTS, RELOC, READONLY 2 NRV2D 000001f0 00000000 00000000 00000278 2**0 CONTENTS, RELOC, READONLY
3 NRV2B 000001b4 00000000 00000000 00000464 2**0 CONTENTS, RELOC, READONLY 3 NRV2B 000001b4 00000000 00000000 00000468 2**0 CONTENTS, RELOC, READONLY
4 LZMA_ELF00 0000006c 00000000 00000000 00000618 2**0 CONTENTS, READONLY 4 LZMA_ELF00 00000070 00000000 00000000 0000061c 2**0 CONTENTS, READONLY
5 LZMA_DEC10 00000ad8 00000000 00000000 00000684 2**0 CONTENTS, READONLY 5 LZMA_DEC10 00000ad8 00000000 00000000 0000068c 2**0 CONTENTS, READONLY
6 LZMA_DEC20 00000ad8 00000000 00000000 0000115c 2**0 CONTENTS, READONLY 6 LZMA_DEC20 00000ad8 00000000 00000000 00001164 2**0 CONTENTS, READONLY
7 LZMA_DEC30 00000004 00000000 00000000 00001c34 2**0 CONTENTS, READONLY 7 LZMA_DEC30 00000004 00000000 00000000 00001c3c 2**0 CONTENTS, READONLY
8 NRV_TAIL 00000000 00000000 00000000 00001c38 2**0 CONTENTS, READONLY 8 NRV_TAIL 00000000 00000000 00000000 00001c40 2**0 CONTENTS, READONLY
9 ELFMAINY 0000005e 00000000 00000000 00001c38 2**0 CONTENTS, RELOC, READONLY 9 ELFMAINY 0000005e 00000000 00000000 00001c40 2**0 CONTENTS, RELOC, READONLY
10 ELFMAINZ 000000c0 00000000 00000000 00001c96 2**0 CONTENTS, READONLY 10 ELFMAINZ 000000bc 00000000 00000000 00001c9e 2**0 CONTENTS, READONLY
SYMBOL TABLE: SYMBOL TABLE:
00000000 l d ELFMAINY 00000000 ELFMAINY 00000000 l d ELFMAINY 00000000 ELFMAINY
00000000 l d ELFMAINZ 00000000 ELFMAINZ 00000000 l d ELFMAINZ 00000000 ELFMAINZ
@@ -45,7 +45,7 @@ OFFSET TYPE VALUE
00000014 R_MIPS_32 LENU 00000014 R_MIPS_32 LENU
00000018 R_MIPS_32 ADRX 00000018 R_MIPS_32 ADRX
0000001c R_MIPS_32 LENX 0000001c R_MIPS_32 LENX
00000020 R_MIPS_PC16 ELFMAINZ 00000024 R_MIPS_PC16 ELFMAINZ
RELOCATION RECORDS FOR [NRV2E]: RELOCATION RECORDS FOR [NRV2E]:
OFFSET TYPE VALUE OFFSET TYPE VALUE