Dylib/ppc32 format works.

This commit is contained in:
John Reiser
2009-05-31 12:57:10 -07:00
parent a187cb6c9c
commit d8345a44a4
5 changed files with 64 additions and 38 deletions
+3 -2
View File
@@ -3,8 +3,9 @@ User visible changes for UPX
================================================================== ==================================================================
Changes in 3.05 (01 XXX 2009): Changes in 3.05 (01 XXX 2009):
* new format Dylib/i386 supports shared libraries on Darwin (Mach-o); * new formats Dylib/i386 and Dylib/ppc32 support shared libraries
an existing -init function (LC_ROUTINES command) is required. [such as browser plugins] on Darwin (Apple Macintosh). An existing
-init function (LC_ROUTINES command) is required.
Changes in 3.04 (27 Apr 2009): Changes in 3.04 (27 Apr 2009):
* new format vmlinuz/armel for Debian NSLU2 (etc.) linux kernel * new format vmlinuz/armel for Debian NSLU2 (etc.) linux kernel
+45 -32
View File
@@ -70,6 +70,11 @@ SZ_DLINE=128 # size of data cache line in Apple G5
#include "arch/powerpc/32/lzma_d.S" #include "arch/powerpc/32/lzma_d.S"
#undef off
#undef len
#undef bits
#undef disp
section NRV_TAIL section NRV_TAIL
eof_nrv: eof_nrv:
#define dst0 a4 #define dst0 a4
@@ -121,17 +126,18 @@ sz_b_info= 12
// register numbers during entry // register numbers during entry
#define f_unc 31 #define f_unc 31
#define f_unf 30 #define f_uini 30
#define l_unm 29 #define l_unm 29
#define a_unm 28 #define a_unm 28
#define unc 27 #define r_unc 27
#define cpr 26 #define r_cpr 26
#define unc2 25 #define s_unc 25
#define cpr2 24 #define s_cpr 24
#define l_unc 23 #define l_unc 23
#define l_cpr 22 #define l_cpr 22
#define f_uini 21 #define t_h 21 /* temporary */
#define t_h 20 /* temporary */
LINKAREA= 6*4 // (sp,pc,cr, xx,yy.zz) save area per calling convention
PROT_NONE =0x00 PROT_NONE =0x00
PROT_READ =0x01 PROT_READ =0x01
@@ -188,40 +194,46 @@ movup2: # descending copy [base, movup2)
lbzu r0,-1(a0) lbzu r0,-1(a0)
stbu r0,-1(a1) stbu r0,-1(a1)
bdnz+ movup2 bdnz+ movup2
lwz f_uini,-4*4+ _start - decompress(f_unc) # offset(user_init_fn)
subf f_unc,a0,f_unc subf f_unc,a0,f_unc
add f_unc,a1,f_unc # relocated decompress add f_unc,a1,f_unc # relocated decompress
add f_uini,f_uini,a0
lwz t0,-4*3+ _start - decompress(f_unc) # offset(b_info) lwz t0,-4*3+ _start - decompress(f_unc) # offset(b_info)
add cpr,a1,t0 # &b_info add r_cpr,a1,t0 # &b_info
add unc,a0,t0 # &b_info add r_unc,a0,t0 # &b_info
addi unc,unc,-sz_l_info -sz_p_info addi r_unc,r_unc,-sz_l_info -sz_p_info
// skip compressed Mach headers // skip compressed Mach headers
lwz t0,sz_cpr(cpr) lwz t0,sz_cpr(r_cpr)
addi cpr,cpr,sz_b_info addi r_cpr,r_cpr,sz_b_info
add cpr,cpr,t0 add r_cpr,r_cpr,t0
dy_uncpr: dy_uncpr:
mr cpr2,cpr mr s_cpr,r_cpr
mr unc2,unc mr s_unc,r_unc
addi a0,cpr,sz_unc; call get4; beq dy_done; add unc,unc,a0; mr l_unc,a0 addi a0,r_cpr,sz_unc; call get4; beq dy_done
addi a0,cpr,sz_cpr; call get4; add cpr,cpr,a0; mr l_cpr,a0 add r_unc,r_unc,a0; mr l_unc,a0
addi cpr,cpr,sz_b_info addi a0,r_cpr,sz_cpr; call get4
add r_cpr,r_cpr,a0; mr l_cpr,a0
addi r_cpr,r_cpr,sz_b_info
stwu l_unc,-4(sp) stwu l_unc,-8(sp) # keep stack 8-byte aligned
mtlr f_unc mtlr f_unc
addi a0,cpr2,sz_b_info # src addi a0,s_cpr,sz_b_info # src
mr a1,l_cpr mr a1,l_cpr
mr a2,unc2 # dst mr a2,s_unc # dst
mr a3,sp # &l_dst mr a3,sp # &l_dst
lbz a4,b_method(cpr2) lbz a4,b_method(s_cpr)
la sp,-LINKAREA(sp)
blrl # uncompress blrl # uncompress
addi sp,sp,4 la sp,8+LINKAREA(sp)
// FIXME: check status // FIXME: check status
lbz a3,b_ftid(cpr2); cmpli cr0,a3,0; beq dy_uncpr lbz a3,b_ftid(s_cpr); cmpli cr0,a3,0; beq dy_uncpr
lbz a2,b_cto8(cpr2) lbz a2,b_cto8(s_cpr)
lwz a1,sz_unc(cpr2) lwz a1,sz_unc(s_cpr)
mr a0,unc2 mr a0,s_unc
bl unfilter bl unfilter
b dy_uncpr b dy_uncpr
@@ -239,15 +251,15 @@ dy_done2:
mtctr t0 mtctr t0
dy_done3: dy_done3:
lwzu t0,-4(a0) lwzu t0,-4(a0)
stwu t0,-4(unc2) stwu t0,-4(s_unc)
bdnz+ dy_done3 bdnz+ dy_done3
mtlr unc2 mtlr s_unc
mtctr f_uini # user_init_function mtctr f_uini # user_init_function
mr a0,a_unm mr a0,a_unm
mr a1,l_unm mr a1,l_unm
li 0,SYS_munmap li 0,SYS_munmap
blr # goto relocted dy_done1 blr # goto relocated dy_done1
get4: get4:
lbz t0,3(a0) lbz t0,3(a0)
@@ -257,8 +269,9 @@ get4:
mr. a0,t0 # set condition codes mr. a0,t0 # set condition codes
blr blr
unfilter: # FIXME unfilter:
ret #include "arch/powerpc/32/bxx.S"
main: main:
b main2 b main2
dy_top: dy_top:
+13 -1
View File
@@ -167,9 +167,21 @@ unfold:
mtlr a0 // &continuation mtlr a0 // &continuation
lwz lsrc,sz_cpr(r30) lwz lsrc,sz_cpr(r30)
addi src,r30,sz_b_info addi src,r30,sz_b_info
la sp,-6*4(sp) // (sp,cr,pc, xx,yy,zz) save area per calling convention la sp,-6*4(sp) // (sp,pc,cr, xx,yy,zz) save area per calling convention
bctr // goto decomrpess; return to link register (mmap'ed page) bctr // goto decomrpess; return to link register (mmap'ed page)
// Example code at entrypoint of C-language subroutine:
// mflr r0 # r0= return address
// stwu sp,-96(sp) # allocate local frame; chain to previous frame
// stmw r14,24(sp) # save 18 regs r14,r15,...,r31; 4*18 == (96 - 24)
// stw r0,100(sp) # save return address into caller's frame (100 >= 96)
// Example code at exit:
// lwz r0,100(sp) # r0= return address
// lmw r14,24(sp) # restore 18 regs r14,r15,...,r31
// mtlr r0 # prepare for indirect jump
// addi sp,sp,96 # de-allocate local frame
// blr # goto return address
main: main:
//// teq r0,r0 // debugging //// teq r0,r0 // debugging
stwu r1,-32*4(sp) // allocate space (keeping 0 mod 16), save r1 stwu r1,-32*4(sp) // allocate space (keeping 0 mod 16), save r1
+1 -1
View File
@@ -43,7 +43,7 @@ sz_l_info= 12
sz_p_info= 12 sz_p_info= 12
OVERHEAD= 2048 OVERHEAD= 2048
LINKAREA= 6*4 // (sp,cr,pc, xx,yy.zz) save area per calling convention LINKAREA= 6*4 // (sp,pc,cr, xx,yy.zz) save area per calling convention
/* In: /* In:
r31= &decompress; also 8+ (char *)&(#bytes which preceed &-8(r31) r31= &decompress; also 8+ (char *)&(#bytes which preceed &-8(r31)
*/ */
@@ -14,7 +14,7 @@ Idx Name Size VMA LMA File off Algn Flags
9 NRV_TAIL 0000001c 00000000 00000000 00001784 2**0 CONTENTS, READONLY 9 NRV_TAIL 0000001c 00000000 00000000 00001784 2**0 CONTENTS, READONLY
10 CFLUSH 00000024 00000000 00000000 000017a0 2**0 CONTENTS, READONLY 10 CFLUSH 00000024 00000000 00000000 000017a0 2**0 CONTENTS, READONLY
11 ELFMAINY 00000000 00000000 00000000 000017c4 2**0 CONTENTS, READONLY 11 ELFMAINY 00000000 00000000 00000000 000017c4 2**0 CONTENTS, READONLY
12 ELFMAINZ 0000019c 00000000 00000000 000017c4 2**0 CONTENTS, READONLY 12 ELFMAINZ 00000204 00000000 00000000 000017c4 2**0 CONTENTS, READONLY
SYMBOL TABLE: SYMBOL TABLE:
00000000 l d LZMA_DEC30 00000000 LZMA_DEC30 00000000 l d LZMA_DEC30 00000000 LZMA_DEC30
00000000 l d NRV_TAIL 00000000 NRV_TAIL 00000000 l d NRV_TAIL 00000000 NRV_TAIL
@@ -33,7 +33,7 @@ SYMBOL TABLE:
RELOCATION RECORDS FOR [MACOS000]: RELOCATION RECORDS FOR [MACOS000]:
OFFSET TYPE VALUE OFFSET TYPE VALUE
00000004 R_PPC_REL24 ELFMAINZ+0x00000198 00000004 R_PPC_REL24 ELFMAINZ+0x00000200
RELOCATION RECORDS FOR [NRV2E]: RELOCATION RECORDS FOR [NRV2E]:
OFFSET TYPE VALUE OFFSET TYPE VALUE