v4 ARM mode stub support with assembly decompressor by John
dll support for v4 ARM mode
unpacking support

committer: ml1050 <ml1050> 1144249762 +0000
This commit is contained in:
László Molnár
2006-04-05 15:09:22 +00:00
parent 04e0e06d85
commit 4fd9c5772a
8 changed files with 945 additions and 136 deletions
+16 -5
View File
@@ -224,8 +224,9 @@ GCC_AMD64 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
### ARM-PE-WINCE
###
GCC_ARM := arm-9tdmi-linux-gnu-gcc -march=armv4t -nostdinc -MMD
GCC_ARM := arm-9tdmi-linux-gnu-gcc -march=armv4 -nostdinc -MMD
GCC_ARM += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
GCC_ARM_T := $(GCC_ARM) -march=armv4t -mthumb-interwork -mthumb
LD_ARM := arm-9tdmi-linux-gnu-ld
OBJCOPY_ARM := arm-9tdmi-linux-gnu-objcopy
BIN2H_WINCE := perl -ne 'print "db\t", join(",", map { sprintf "%\#02x", $$_ } unpack("C*", $$_)), "\n"'
@@ -554,16 +555,26 @@ upxd: l_lx_sep.o l_lx_sep86.asm
$(STRIPELF_LINUX_I386) $@
$(BRANDELF) $@
l_armpe.h: l_armpe.asx l_armpe_s.S l_armpe_c.c arm_nrv2e_d8.S arm_nrv2b_d8.S $(MAKEFILE_LIST)
$(GCC_ARM) -mthumb-interwork -c l_armpe_s.S arm_nrv2e_d8.S arm_nrv2b_d8.S
$(GCC_ARM) -mthumb -mthumb-interwork -Os -c l_armpe_c.c -DNRV2E
l_armpe.h: l_armpe.asx l_armpe_s.S l_armpe_c.c arm_nrv2e_d8.S arm_nrv2b_d8.S armv4_n2e_d8.S $(MAKEFILE_LIST)
$(GCC_ARM_T) -c l_armpe_s.S arm_nrv2e_d8.S arm_nrv2b_d8.S
$(GCC_ARM_T) -Os -c l_armpe_c.c -DUCL_DECOMPRESS=thumb_nrv2e_d8
$(LD_ARM) -o l_armpe2e.out l_armpe_s.o l_armpe_c.o arm_nrv2e_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe2e.out l_armpe2e.bin
$(BIN2H_WINCE) <l_armpe2e.bin >l_armpe2e.ah
$(GCC_ARM) -mthumb -mthumb-interwork -Os -c l_armpe_c.c -DNRV2B
$(GCC_ARM_T) -Os -c l_armpe_c.c -DUCL_DECOMPRESS=go_thumb_n2b
$(LD_ARM) -o l_armpe2b.out l_armpe_s.o l_armpe_c.o arm_nrv2b_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe2b.out l_armpe2b.bin
$(BIN2H_WINCE) <l_armpe2b.bin >l_armpe2b.ah
$(GCC_ARM) -Os -S l_armpe_c.c -DUCL_DECOMPRESS=ucl_nrv2e_decompress_8
$(GCC_ARM) -c armv4_n2e_d8.S l_armpe_s.S
$(LD_ARM) -o l_armpe2e_v4.out l_armpe_s.o armv4_n2e_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe2e_v4.out l_armpe2e_v4.bin
$(BIN2H_WINCE) <l_armpe2e_v4.bin >l_armpe2e_v4.ah
$(GCC_ARM) -DSTUB_FOR_DLL -Os -S l_armpe_c.c -DUCL_DECOMPRESS=ucl_nrv2e_decompress_8
$(GCC_ARM) -DSTUB_FOR_DLL -c armv4_n2e_d8.S l_armpe_s.S
$(LD_ARM) -o l_armpe2e_v4dll.out l_armpe_s.o armv4_n2e_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe2e_v4dll.out l_armpe2e_v4dll.bin
$(BIN2H_WINCE) <l_armpe2e_v4dll.bin >l_armpe2e_v4dll.ah
$(NASM) -f bin -o $T.bin $<
$(BIN2H) $T.bin nrv_loader $@
+181
View File
@@ -0,0 +1,181 @@
/* armv4_n2e_d8.S -- ARM decompressor for NRV2E
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#define SAFE 0 /* 1 for src+dst bounds checking: cost 76 bytes */
#define src r0
#define len r1 /* overlaps 'cnt' */
#define dst r2
#define tmp r3
#define bits r4
#define off r5
/* r6 UNUSED in ARM code unless DEBUG mode */
#define srclim r7
#if 1==SAFE /*{*/
#define dstlim r12
#endif /*}*/
#define cnt r1 /* overlaps 'len' while reading an offset */
/* macros reduce "noise" when comparing this ARM code to corresponding THUMB code */
#define PUSH stmdb sp!,
#define POP ldmia sp!,
#define ADD2( dst,src) add dst,dst,src
#define ADD2S(dst,src) adds dst,dst,src
#define ADC2( dst,src) adc dst,dst,src
#define ADC2S(dst,src) adcs dst,dst,src
#define SUB2( dst,src) sub dst,dst,src
#define SUB2S(dst,src) subs dst,dst,src
#define LDRB3(reg,psrc,incr) ldrb reg,psrc,incr
#define STRB3(reg,pdst,incr) strb reg,pdst,incr
#if 1==SAFE /*{*/
#define CHECK_SRC cmp srclim,src; bls bad_src_n2e /* Out: 1==Carry for get8_n2e */
#define CHECK_DST cmp dst,dstlim; bhs bad_dst_n2e
#else /*}{*/
#define CHECK_SRC /*empty*/
#define CHECK_DST /*empty*/
#endif /*}*/
#if 0 /*{ DEBUG only: check newly-decompressed against original dst */
#define CHECK_BYTE \
ldrb r6,[dst]; \
cmp r6,tmp; beq 0f; bkpt; 0:
#else /*}{*/
#define CHECK_BYTE /*empty*/
#endif /*}*/
#define GETBIT ADD2S(bits,bits); bleq get8_n2e
#define getnextb(reg) GETBIT; ADC2(reg,reg) /* Out: condition code not changed */
#define jnextb0 GETBIT; bcc
#define jnextb1 GETBIT; bcs
ucl_nrv2e_decompress_8: .globl ucl_nrv2e_decompress_8 @ ARM mode
.type ucl_nrv2e_decompress_8, %function
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst)
Actual decompressed length is stored through plen_dst.
For SAFE mode: at call, *plen_dst must be allowed length of output buffer.
*/
PUSH {r2,r3, r4,r5,r6,r7, lr}
#define sp_DST0 0 /* stack offset of original dst */
add srclim,len,src @ srclim= eof_src;
#if 1==SAFE /*{*/
ldr tmp,[r3] @ len_dst
add dstlim,tmp,dst
#endif /*}*/
mvn off,#~-1 @ off= -1 initial condition
mov bits,#1<<31 @ refill next time
b top_n2e
#if 1==SAFE /*{*/
bad_dst_n2e: # return value will be 2
bkpt
add src,srclim,#1
bad_src_n2e: # return value will be 1
ADD2(src,#1)
#endif /*}*/
eof_n2e:
POP {r3,r4} @ r3= orig_dst; r4= plen_dst
SUB2(src,srclim) @ 0 if actual src length equals expected length
SUB2(dst,r3) @ actual dst length
str dst,[r4]
POP {r4,r5,r6,r7 ,pc}
get8_n2e: @ In: Carry set [from adding 0x80000000 (1<<31) to itself]
CHECK_SRC; LDRB3(bits,[src],#1) @ zero-extend next byte
adc bits,bits,bits @ double and insert CarryIn as low bit
movs bits,bits,lsl #24 @ move to top byte, and set CarryOut from old bit 8
mov pc,lr
lit_n2e:
CHECK_SRC; LDRB3(tmp,[src],#1)
CHECK_BYTE
CHECK_DST; STRB3(tmp,[dst],#1)
top_n2e:
jnextb1 lit_n2e
mov cnt,#1; b getoff_n2e
off_n2e:
SUB2(cnt,#1)
getnextb(cnt)
getoff_n2e:
getnextb(cnt)
jnextb0 off_n2e
subs tmp,cnt,#3 @ set Carry
mov len,#0 @ Carry unaffected
blo offprev_n2e @ cnt was 2; tests Carry only
CHECK_SRC; LDRB3(off,[src],#1) @ low 7+1 bits
orr off,off,tmp,lsl #8
mvns off,off; beq eof_n2e @ off= ~off
movs off,off,asr #1; bcs lenlast_n2e
b lenmore_n2e
offprev_n2e:
jnextb1 lenlast_n2e
lenmore_n2e:
mov len,#1
jnextb1 lenlast_n2e
len_n2e:
getnextb(len)
jnextb0 len_n2e
ADD2(len,#6-2)
b gotlen_n2e
lenlast_n2e:
getnextb(len) @ 0,1,2,3
ADD2(len,#2)
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
cmn off,#5<<8; bcs near_n2e @ within M2_MAX_OFFSET
ADD2(len,#1) @ too far away, so minimum match length is 3
near_n2e:
#if 1==SAFE /*{*/
ldr tmp,[sp,#sp_DST0]
SUB2( tmp,dst)
SUB2S(tmp,off); bhi bad_dst_n2e @ reaching back too far
add tmp,dst,cnt
cmp tmp,dstlim; bhi bad_dst_n2e @ too much output
#endif /*}*/
ldrb tmp,[dst] @ force cacheline allocate
copy_n2e:
ldrb tmp,[dst,off]
CHECK_BYTE
STRB3(tmp,[dst],#1)
SUB2S(len,#1); bne copy_n2e
b top_n2e
.size ucl_nrv2e_decompress_8, .-ucl_nrv2e_decompress_8
/*
vi:ts=8:et:nowrap
*/
+4
View File
@@ -42,6 +42,10 @@
; __ARMWPE2E__
start:
%include "l_armpe2e.ah"
; __ARMWPE2EV4__
%include "l_armpe2e_v4.ah"
; __ARMWPE2EV4DLL__
%include "l_armpe2e_v4dll.ah"
; __ARMWPE2B__
%include "l_armpe2b.ah"
; __ARMWPEHE__
+154 -64
View File
@@ -1,4 +1,4 @@
/* l_armpe.h -- created from l_armpe.bin, 1039 (0x40f) bytes
/* l_armpe.h -- created from l_armpe.bin, 2472 (0x9a8) bytes
This file is part of the UPX executable compressor.
@@ -27,74 +27,164 @@
*/
#define NRV_LOADER_SIZE 1039
#define NRV_LOADER_ADLER32 0xa2a48332
#define NRV_LOADER_CRC32 0x9e9a3347
#define NRV_LOADER_SIZE 2472
#define NRV_LOADER_ADLER32 0xf7af0ea2
#define NRV_LOADER_CRC32 0x70a87499
unsigned char nrv_loader[1039] = {
unsigned char nrv_loader[2472] = {
15, 64, 45,233, 72, 0,143,226, 14, 0,144,232, 2, 16,129,224, /* 0x 0 */
0, 32,147,229, 1, 58,131,226, 1, 0, 83,225,251,255,255,154, /* 0x 10 */
4,224,143,226, 23,192,143,226, 28,255, 47,225, 15, 64,189,232, /* 0x 20 */
60,192,159,229, 28,255, 47,225, 12, 75, 27,104, 24, 71, 12, 75, /* 0x 30 */
251,231, 25,224, 3, 33, 67, 92, 18, 2,210, 24, 1, 57,250,213, /* 0x 40 */
251,231, 27,224, 3, 33, 67, 92, 18, 2,210, 24, 1, 57,250,213, /* 0x 40 */
16, 28,112, 71, 83, 82, 67, 48, 83, 82, 67, 76, 68, 83, 84, 48, /* 0x 50 */
68, 83, 84, 76, 66, 73, 77, 80, 79, 78, 65, 77, 71, 69, 84, 80, /* 0x 60 */
76, 79, 65, 68, 69, 78, 84, 82,240,181,163,176, 0, 34, 2,146, /* 0x 70 */
130,104, 1,146, 66,105, 3, 28, 4,105, 0,146, 89,104, 0,104, /* 0x 80 */
1,154, 2,171, 0,240, 76,248, 37, 28, 40, 28,255,247,210,255, /* 0x 90 */
4, 30, 61,208, 0,155, 40, 29,228, 24,255,247,203,255, 1,154, /* 0x a0 */
134, 24, 3,168, 2, 28, 35,120, 27, 6, 0, 43, 4,208, 27, 14, /* 0x b0 */
19,128, 1, 52, 2, 50,246,231, 0, 35, 19,128,255,247,183,255, /* 0x c0 */
8, 53, 7, 28, 43,120, 27, 6, 0, 43, 31,208, 27, 14, 1, 53, /* 0x d0 */
1, 43, 2,208,255, 43, 13,208,244,231, 56, 28, 41, 28,255,247, /* 0x e0 */
163,255, 52, 28, 32, 96, 4, 54, 43,120, 27, 6, 1, 53, 0, 43, /* 0x f0 */
250,209,231,231,105,120, 43,120, 9, 2, 56, 28, 89, 24,255,247, /* 0x 100 */
147,255, 52, 28, 2, 53, 4, 54, 32, 96,219,231, 1, 53,188,231, /* 0x 110 */
35,176,240,188, 1,188, 0, 71, 1,192,143,226, 28,255, 47,225, /* 0x 120 */
252,181, 15, 24, 1, 36,101, 66,228, 7, 5, 38, 54, 2, 15,224, /* 0x 130 */
24,188,192, 27,210, 26, 34, 96,240,188, 2,188, 8, 71, 4,120, /* 0x 140 */
100, 65, 1, 48, 36, 6,247, 70, 3,120, 1, 48, 19,112, 1, 50, /* 0x 150 */
36, 25,254, 70,243,208,247,210, 1, 33, 4,224, 1, 57, 36, 25, /* 0x 160 */
254, 70,236,208, 73, 65, 36, 25,254, 70,232,208, 73, 65, 36, 25, /* 0x 170 */
254, 70,228,208,242,211,203, 30, 0, 33, 8,211, 27, 2, 5,120, /* 0x 180 */
1, 48, 29, 67,237, 67,211,208,109, 16, 19,210, 3,224, 36, 25, /* 0x 190 */
254, 70,212,208, 14,210, 1, 33, 36, 25,254, 70,207,208, 9,210, /* 0x 1a0 */
36, 25,254, 70,203,208, 73, 65, 36, 25,254, 70,199,208,247,211, /* 0x 1b0 */
4, 49, 4,224, 36, 25,254, 70,193,208, 73, 65, 2, 49,238, 66, /* 0x 1c0 */
0,210, 1, 49, 19,120, 83, 93, 19,112, 1, 50, 1, 57,250,209, /* 0x 1d0 */
190,231, 0, 0, 15, 64, 45,233, 72, 0,143,226, 14, 0,144,232, /* 0x 1e0 */
2, 16,129,224, 0, 32,147,229, 1, 58,131,226, 1, 0, 83,225, /* 0x 1f0 */
251,255,255,154, 4,224,143,226, 23,192,143,226, 28,255, 47,225, /* 0x 200 */
15, 64,189,232, 60,192,159,229, 28,255, 47,225, 12, 75, 27,104, /* 0x 210 */
24, 71, 12, 75,251,231, 25,224, 3, 33, 67, 92, 18, 2,210, 24, /* 0x 220 */
1, 57,250,213, 16, 28,112, 71, 83, 82, 67, 48, 83, 82, 67, 76, /* 0x 230 */
68, 83, 84, 48, 68, 83, 84, 76, 66, 73, 77, 80, 79, 78, 65, 77, /* 0x 240 */
71, 69, 84, 80, 76, 79, 65, 68, 69, 78, 84, 82,240,181,163,176, /* 0x 250 */
0, 34, 2,146,130,104, 1,146, 66,105, 3, 28, 4,105, 0,146, /* 0x 260 */
89,104, 0,104, 1,154, 2,171, 0,240, 76,248, 37, 28, 40, 28, /* 0x 270 */
255,247,210,255, 4, 30, 61,208, 0,155, 40, 29,228, 24,255,247, /* 0x 280 */
203,255, 1,154,134, 24, 3,168, 2, 28, 35,120, 27, 6, 0, 43, /* 0x 290 */
4,208, 27, 14, 19,128, 1, 52, 2, 50,246,231, 0, 35, 19,128, /* 0x 2a0 */
255,247,183,255, 8, 53, 7, 28, 43,120, 27, 6, 0, 43, 31,208, /* 0x 2b0 */
27, 14, 1, 53, 1, 43, 2,208,255, 43, 13,208,244,231, 56, 28, /* 0x 2c0 */
41, 28,255,247,163,255, 52, 28, 32, 96, 4, 54, 43,120, 27, 6, /* 0x 2d0 */
1, 53, 0, 43,250,209,231,231,105,120, 43,120, 9, 2, 56, 28, /* 0x 2e0 */
89, 24,255,247,147,255, 52, 28, 2, 53, 4, 54, 32, 96,219,231, /* 0x 2f0 */
1, 53,188,231, 35,176,240,188, 1,188, 0, 71, 1,192,143,226, /* 0x 300 */
28,255, 47,225, 9, 24,254,181, 1, 36,101, 66,228, 7, 13, 39, /* 0x 310 */
63, 2, 13,224, 26,188, 64, 26,210, 26, 34, 96,240,189, 4,120, /* 0x 320 */
100, 65, 1, 48, 36, 6,247, 70, 3,120, 1, 48, 19,112, 1, 50, /* 0x 330 */
36, 25,254, 70,243,208,247,210, 1, 33, 36, 25,254, 70,238,208, /* 0x 340 */
73, 65, 36, 25,254, 70,234,208,247,211,203, 30, 0, 33, 5,211, /* 0x 350 */
27, 2, 5,120, 1, 48, 29, 67,237, 67,219,208, 36, 25,254, 70, /* 0x 360 */
221,208, 73, 65, 36, 25,254, 70,217,208, 73, 65, 9,209, 1, 33, /* 0x 370 */
36, 25,254, 70,211,208, 73, 65, 36, 25,254, 70,207,208,247,211, /* 0x 380 */
2, 49, 1, 49,253, 66, 0,210, 1, 49, 19,120, 83, 93, 19,112, /* 0x 390 */
1, 50, 1, 57,250,209,203,231, 85, 80, 88, 33,161,216,208,213, /* 0x 3a0 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 3b0 */
0, 0, 0, 0, 0, 0, 0, 45, 65, 82, 77, 87, 80, 69, 50, 69, /* 0x 3c0 */
0, 0, 0, 0, 0, 65, 82, 77, 87, 80, 69, 50, 66, 0,228, 1, /* 0x 3d0 */
0, 0, 65, 82, 77, 87, 80, 69, 72, 69, 0,168, 3, 0, 0, 85, /* 0x 3e0 */
80, 88, 49, 72, 69, 65, 68, 0,168, 3, 0, 0, 65, 82, 77, 87, /* 0x 3f0 */
80, 69, 57, 57, 0,200, 3, 0, 0,255,255,255,255,200, 3 /* 0x 400 */
76, 79, 65, 68, 69, 78, 84, 82, 66, 82, 69, 76,240,181,163,176, /* 0x 70 */
0, 34, 2,146,130,104, 1,146, 66,105, 3, 28, 4,105, 0,146, /* 0x 80 */
89,104, 0,104, 1,154, 2,171, 0,240, 76,248, 37, 28, 40, 28, /* 0x 90 */
255,247,208,255, 4, 30, 61,208, 0,155, 40, 29,228, 24,255,247, /* 0x a0 */
201,255, 1,154,134, 24, 3,168, 2, 28, 35,120, 27, 6, 0, 43, /* 0x b0 */
4,208, 27, 14, 19,128, 1, 52, 2, 50,246,231, 0, 35, 19,128, /* 0x c0 */
255,247,181,255, 8, 53, 7, 28, 43,120, 27, 6, 0, 43, 31,208, /* 0x d0 */
27, 14, 1, 53, 1, 43, 2,208,255, 43, 13,208,244,231, 56, 28, /* 0x e0 */
41, 28,255,247,161,255, 52, 28, 32, 96, 4, 54, 43,120, 27, 6, /* 0x f0 */
1, 53, 0, 43,250,209,231,231,105,120, 43,120, 9, 2, 56, 28, /* 0x 100 */
89, 24,255,247,145,255, 52, 28, 2, 53, 4, 54, 32, 96,219,231, /* 0x 110 */
1, 53,188,231, 35,176,240,188, 1,188, 0, 71, 1,192,143,226, /* 0x 120 */
28,255, 47,225,252,181, 15, 24, 1, 36,101, 66,228, 7, 5, 38, /* 0x 130 */
54, 2, 15,224, 24,188,192, 27,210, 26, 34, 96,240,188, 2,188, /* 0x 140 */
8, 71, 4,120,100, 65, 1, 48, 36, 6,247, 70, 3,120, 1, 48, /* 0x 150 */
19,112, 1, 50, 36, 25,254, 70,243,208,247,210, 1, 33, 4,224, /* 0x 160 */
1, 57, 36, 25,254, 70,236,208, 73, 65, 36, 25,254, 70,232,208, /* 0x 170 */
73, 65, 36, 25,254, 70,228,208,242,211,203, 30, 0, 33, 8,211, /* 0x 180 */
27, 2, 5,120, 1, 48, 29, 67,237, 67,211,208,109, 16, 19,210, /* 0x 190 */
3,224, 36, 25,254, 70,212,208, 14,210, 1, 33, 36, 25,254, 70, /* 0x 1a0 */
207,208, 9,210, 36, 25,254, 70,203,208, 73, 65, 36, 25,254, 70, /* 0x 1b0 */
199,208,247,211, 4, 49, 4,224, 36, 25,254, 70,193,208, 73, 65, /* 0x 1c0 */
2, 49,238, 66, 0,210, 1, 49, 19,120, 83, 93, 19,112, 1, 50, /* 0x 1d0 */
1, 57,250,209,190,231, 0, 0, 15, 64, 45,233, 52, 0,143,226, /* 0x 1e0 */
22, 0, 0,235, 15, 64,189,232, 72,240,159,229, 64, 48,159,229, /* 0x 1f0 */
0,240,147,229, 52, 48,159,229, 0,240,147,229, 3, 32,160,227, /* 0x 200 */
2, 48,208,231, 1, 32, 82,226, 1, 20,131,224,251,255,255, 90, /* 0x 210 */
1, 0,160,225, 14,240,160,225, 83, 82, 67, 48, 83, 82, 67, 76, /* 0x 220 */
68, 83, 84, 48, 68, 83, 84, 76, 66, 73, 77, 80, 79, 78, 65, 77, /* 0x 230 */
71, 69, 84, 80, 76, 79, 65, 68, 69, 78, 84, 82, 66, 82, 69, 76, /* 0x 240 */
240, 65, 45,233, 0,224,160,227, 8,112,144,229,132,208, 77,226, /* 0x 250 */
0,192,160,225, 3, 0,144,232, 0,224,141,229, 7, 32,160,225, /* 0x 260 */
13, 48,160,225, 16, 64,140,226, 16, 1,148,232, 52, 0, 0,235, /* 0x 270 */
4, 0,160,225,224,255,255,235, 0, 80, 80,226, 46, 0, 0, 10, /* 0x 280 */
4, 0,132,226,220,255,255,235, 8, 80,133,224, 0, 48,213,229, /* 0x 290 */
4, 16,141,226, 0, 0, 83,227, 7, 96,128,224, 1, 32,160,225, /* 0x 2a0 */
3, 0, 0, 10,178, 48,194,224, 1, 48,245,229, 0, 0, 83,227, /* 0x 2b0 */
250,255,255,234, 0, 48,160,227,176, 48,194,225, 1, 0,160,225, /* 0x 2c0 */
201,255,255,235, 8, 48,244,229, 0, 80,160,225, 0, 0, 83,227, /* 0x 2d0 */
23, 0, 0, 10,255, 48, 3,226, 1, 0, 83,227, 1, 64,132,226, /* 0x 2e0 */
2, 0, 0, 10,255, 0, 83,227, 8, 0, 0, 10, 14, 0, 0,234, /* 0x 2f0 */
5, 0,160,225, 4, 16,160,225,189,255,255,235, 4, 0,134,228, /* 0x 300 */
1, 48,212,228, 0, 0, 83,227,252,255,255, 26, 6, 0, 0,234, /* 0x 310 */
0, 48,212,229, 1, 16,212,229, 5, 0,160,225, 1, 20,131,224, /* 0x 320 */
179,255,255,235, 2, 64,132,226, 4, 0,134,228, 0, 48,212,229, /* 0x 330 */
229,255,255,234, 1, 64,132,226,204,255,255,234,132,208,141,226, /* 0x 340 */
240,129,189,232,252, 64, 45,233, 0,112,129,224, 0, 80,224,227, /* 0x 350 */
2, 65,160,227, 10, 0, 0,234, 24, 0,189,232, 7, 0, 64,224, /* 0x 360 */
3, 32, 66,224, 0, 32,132,229,240,128,189,232, 1, 64,208,228, /* 0x 370 */
4, 64,164,224, 4, 76,176,225, 14,240,160,225, 1, 48,208,228, /* 0x 380 */
1, 48,194,228, 4, 64,148,224,247,255,255, 11,250,255,255, 42, /* 0x 390 */
1, 16,160,227, 3, 0, 0,234, 1, 16, 65,226, 4, 64,148,224, /* 0x 3a0 */
241,255,255, 11, 1, 16,161,224, 4, 64,148,224,238,255,255, 11, /* 0x 3b0 */
1, 16,161,224, 4, 64,148,224,235,255,255, 11,245,255,255, 58, /* 0x 3c0 */
3, 48, 81,226, 0, 16,160,227, 6, 0, 0, 58, 1, 80,208,228, /* 0x 3d0 */
3, 84,133,225, 5, 80,240,225,222,255,255, 10,197, 80,176,225, /* 0x 3e0 */
15, 0, 0, 42, 2, 0, 0,234, 4, 64,148,224,222,255,255, 11, /* 0x 3f0 */
11, 0, 0, 42, 1, 16,160,227, 4, 64,148,224,218,255,255, 11, /* 0x 400 */
7, 0, 0, 42, 4, 64,148,224,215,255,255, 11, 1, 16,161,224, /* 0x 410 */
4, 64,148,224,212,255,255, 11,249,255,255, 58, 4, 16,129,226, /* 0x 420 */
3, 0, 0,234, 4, 64,148,224,207,255,255, 11, 1, 16,161,224, /* 0x 430 */
2, 16,129,226, 5, 12,117,227, 0, 0, 0, 42, 1, 16,129,226, /* 0x 440 */
0, 48,210,229, 5, 48,210,231, 1, 48,194,228, 1, 16, 81,226, /* 0x 450 */
251,255,255, 26,202,255,255,234, 1, 0, 81,227, 3, 0, 0, 26, /* 0x 460 */
15, 64, 45,233,148, 0,143,226, 46, 0, 0,235, 15, 64,189,232, /* 0x 470 */
168,240,159,229,160, 48,159,229, 0,240,147,229,148, 48,159,229, /* 0x 480 */
0,240,147,229, 3, 32,160,227, 2, 48,208,231, 1, 32, 82,226, /* 0x 490 */
1, 20,131,224,251,255,255, 90, 1, 0,160,225, 14,240,160,225, /* 0x 4a0 */
124, 0,159,229, 92, 32,159,229, 4, 16, 66,226, 1, 48,208,228, /* 0x 4b0 */
0, 0, 83,227,248,255,255, 10,240, 0, 83,227,240,192,195, 35, /* 0x 4c0 */
1, 48,208, 37, 12,196,131, 32, 2, 48,208, 36, 12, 52,131, 32, /* 0x 4d0 */
3, 16,129,224, 0, 48,209,229, 12,196,131,224, 1, 48,209,229, /* 0x 4e0 */
12,196,131,224, 2, 48,209,229, 12,196,131,224, 3, 48,209,229, /* 0x 4f0 */
12,196,131,224, 2,192,140,224, 0,192,129,229,234,255,255,234, /* 0x 500 */
83, 82, 67, 48, 83, 82, 67, 76, 68, 83, 84, 48, 68, 83, 84, 76, /* 0x 510 */
66, 73, 77, 80, 79, 78, 65, 77, 71, 69, 84, 80, 76, 79, 65, 68, /* 0x 520 */
69, 78, 84, 82, 66, 82, 69, 76,240, 65, 45,233, 0,224,160,227, /* 0x 530 */
8,112,144,229,132,208, 77,226, 0,192,160,225, 3, 0,144,232, /* 0x 540 */
0,224,141,229, 7, 32,160,225, 13, 48,160,225, 16, 64,140,226, /* 0x 550 */
16, 1,148,232, 53, 0, 0,235, 4, 0,160,225,200,255,255,235, /* 0x 560 */
0, 80, 80,226, 46, 0, 0, 10, 4, 0,132,226,196,255,255,235, /* 0x 570 */
8, 80,133,224, 0, 48,213,229, 4, 16,141,226, 0, 0, 83,227, /* 0x 580 */
7, 96,128,224, 1, 32,160,225, 3, 0, 0, 10,178, 48,194,224, /* 0x 590 */
1, 48,245,229, 0, 0, 83,227,250,255,255,234, 0, 48,160,227, /* 0x 5a0 */
176, 48,194,225, 1, 0,160,225,177,255,255,235, 8, 48,244,229, /* 0x 5b0 */
0, 80,160,225, 0, 0, 83,227, 23, 0, 0, 10,255, 48, 3,226, /* 0x 5c0 */
1, 0, 83,227, 1, 64,132,226, 2, 0, 0, 10,255, 0, 83,227, /* 0x 5d0 */
8, 0, 0, 10, 14, 0, 0,234, 5, 0,160,225, 4, 16,160,225, /* 0x 5e0 */
165,255,255,235, 4, 0,134,228, 1, 48,212,228, 0, 0, 83,227, /* 0x 5f0 */
252,255,255, 26, 6, 0, 0,234, 0, 48,212,229, 1, 16,212,229, /* 0x 600 */
5, 0,160,225, 1, 20,131,224,155,255,255,235, 2, 64,132,226, /* 0x 610 */
4, 0,134,228, 0, 48,212,229,229,255,255,234, 1, 64,132,226, /* 0x 620 */
204,255,255,234,157,255,255,235,132,208,141,226,240,129,189,232, /* 0x 630 */
252, 64, 45,233, 0,112,129,224, 0, 80,224,227, 2, 65,160,227, /* 0x 640 */
10, 0, 0,234, 24, 0,189,232, 7, 0, 64,224, 3, 32, 66,224, /* 0x 650 */
0, 32,132,229,240,128,189,232, 1, 64,208,228, 4, 64,164,224, /* 0x 660 */
4, 76,176,225, 14,240,160,225, 1, 48,208,228, 1, 48,194,228, /* 0x 670 */
4, 64,148,224,247,255,255, 11,250,255,255, 42, 1, 16,160,227, /* 0x 680 */
3, 0, 0,234, 1, 16, 65,226, 4, 64,148,224,241,255,255, 11, /* 0x 690 */
1, 16,161,224, 4, 64,148,224,238,255,255, 11, 1, 16,161,224, /* 0x 6a0 */
4, 64,148,224,235,255,255, 11,245,255,255, 58, 3, 48, 81,226, /* 0x 6b0 */
0, 16,160,227, 6, 0, 0, 58, 1, 80,208,228, 3, 84,133,225, /* 0x 6c0 */
5, 80,240,225,222,255,255, 10,197, 80,176,225, 15, 0, 0, 42, /* 0x 6d0 */
2, 0, 0,234, 4, 64,148,224,222,255,255, 11, 11, 0, 0, 42, /* 0x 6e0 */
1, 16,160,227, 4, 64,148,224,218,255,255, 11, 7, 0, 0, 42, /* 0x 6f0 */
4, 64,148,224,215,255,255, 11, 1, 16,161,224, 4, 64,148,224, /* 0x 700 */
212,255,255, 11,249,255,255, 58, 4, 16,129,226, 3, 0, 0,234, /* 0x 710 */
4, 64,148,224,207,255,255, 11, 1, 16,161,224, 2, 16,129,226, /* 0x 720 */
5, 12,117,227, 0, 0, 0, 42, 1, 16,129,226, 0, 48,210,229, /* 0x 730 */
5, 48,210,231, 1, 48,194,228, 1, 16, 81,226,251,255,255, 26, /* 0x 740 */
202,255,255,234, 15, 64, 45,233, 72, 0,143,226, 14, 0,144,232, /* 0x 750 */
2, 16,129,224, 0, 32,147,229, 1, 58,131,226, 1, 0, 83,225, /* 0x 760 */
251,255,255,154, 4,224,143,226, 23,192,143,226, 28,255, 47,225, /* 0x 770 */
15, 64,189,232, 60,192,159,229, 28,255, 47,225, 12, 75, 27,104, /* 0x 780 */
24, 71, 12, 75,251,231, 27,224, 3, 33, 67, 92, 18, 2,210, 24, /* 0x 790 */
1, 57,250,213, 16, 28,112, 71, 83, 82, 67, 48, 83, 82, 67, 76, /* 0x 7a0 */
68, 83, 84, 48, 68, 83, 84, 76, 66, 73, 77, 80, 79, 78, 65, 77, /* 0x 7b0 */
71, 69, 84, 80, 76, 79, 65, 68, 69, 78, 84, 82, 66, 82, 69, 76, /* 0x 7c0 */
240,181,163,176, 0, 34, 2,146,130,104, 1,146, 66,105, 3, 28, /* 0x 7d0 */
4,105, 0,146, 89,104, 0,104, 1,154, 2,171, 0,240, 76,248, /* 0x 7e0 */
37, 28, 40, 28,255,247,208,255, 4, 30, 61,208, 0,155, 40, 29, /* 0x 7f0 */
228, 24,255,247,201,255, 1,154,134, 24, 3,168, 2, 28, 35,120, /* 0x 800 */
27, 6, 0, 43, 4,208, 27, 14, 19,128, 1, 52, 2, 50,246,231, /* 0x 810 */
0, 35, 19,128,255,247,181,255, 8, 53, 7, 28, 43,120, 27, 6, /* 0x 820 */
0, 43, 31,208, 27, 14, 1, 53, 1, 43, 2,208,255, 43, 13,208, /* 0x 830 */
244,231, 56, 28, 41, 28,255,247,161,255, 52, 28, 32, 96, 4, 54, /* 0x 840 */
43,120, 27, 6, 1, 53, 0, 43,250,209,231,231,105,120, 43,120, /* 0x 850 */
9, 2, 56, 28, 89, 24,255,247,145,255, 52, 28, 2, 53, 4, 54, /* 0x 860 */
32, 96,219,231, 1, 53,188,231, 35,176,240,188, 1,188, 0, 71, /* 0x 870 */
1,192,143,226, 28,255, 47,225, 9, 24,254,181, 1, 36,101, 66, /* 0x 880 */
228, 7, 13, 39, 63, 2, 15,224, 26,188, 64, 26,210, 26, 34, 96, /* 0x 890 */
240,188, 2,188, 8, 71, 4,120,100, 65, 1, 48, 36, 6,247, 70, /* 0x 8a0 */
3,120, 1, 48, 19,112, 1, 50, 36, 25,254, 70,243,208,247,210, /* 0x 8b0 */
1, 33, 36, 25,254, 70,238,208, 73, 65, 36, 25,254, 70,234,208, /* 0x 8c0 */
247,211,203, 30, 0, 33, 5,211, 27, 2, 5,120, 1, 48, 29, 67, /* 0x 8d0 */
237, 67,217,208, 36, 25,254, 70,221,208, 73, 65, 36, 25,254, 70, /* 0x 8e0 */
217,208, 73, 65, 9,209, 1, 33, 36, 25,254, 70,211,208, 73, 65, /* 0x 8f0 */
36, 25,254, 70,207,208,247,211, 2, 49, 1, 49,253, 66, 0,210, /* 0x 900 */
1, 49, 19,120, 83, 93, 19,112, 1, 50, 1, 57,250,209,203,231, /* 0x 910 */
85, 80, 88, 33,161,216,208,213, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 920 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, /* 0x 930 */
65, 82, 77, 87, 80, 69, 50, 69, 0, 0, 0, 0, 0, 65, 82, 77, /* 0x 940 */
87, 80, 69, 50, 69, 86, 52, 0,232, 1, 0, 0, 65, 82, 77, 87, /* 0x 950 */
80, 69, 50, 69, 86, 52, 68, 76, 76, 0,104, 4, 0, 0, 65, 82, /* 0x 960 */
77, 87, 80, 69, 50, 66, 0, 84, 7, 0, 0, 65, 82, 77, 87, 80, /* 0x 970 */
69, 72, 69, 0, 32, 9, 0, 0, 85, 80, 88, 49, 72, 69, 65, 68, /* 0x 980 */
0, 32, 9, 0, 0, 65, 82, 77, 87, 80, 69, 57, 57, 0, 64, 9, /* 0x 990 */
0, 0,255,255,255,255, 64, 9 /* 0x 9a0 */
};
+13 -12
View File
@@ -29,20 +29,17 @@
<jreiser@users.sourceforge.net>
*/
#ifdef NRV2E
int thumb_nrv2e_d8(const unsigned char * src, unsigned src_len,
unsigned char * dst, unsigned * dst_len);
#define ucl_decompress thumb_nrv2e_d8
#elif defined(NRV2B)
int go_thumb_n2b(const unsigned char * src, unsigned src_len,
unsigned char * dst, unsigned * dst_len);
#define ucl_decompress go_thumb_n2b
#ifndef UCL_DECOMPRESS
# error please define UCL_DECOMPRESS
#endif
int UCL_DECOMPRESS(const unsigned char * src, unsigned src_len,
unsigned char * dst, unsigned * dst_len);
void *LoadLibraryW(const unsigned short *);
void *GetProcAddressA(const void *, const void *);
void *get_le32(const void *);
void reloc_main();
static void handle_imports(const unsigned char *imp, unsigned name_offset,
unsigned iat_offset)
@@ -130,9 +127,13 @@ void upx_main(const unsigned *info)
#ifdef SAFE
dlen = info[3];
#endif
//WRITEFILE2('0', (void*) 0x11000, load + 256 - 0x11000);
ucl_decompress((void *) src0, srcl, (void *) dst0, &dlen);
//WRITEFILE2('1', (void*) 0x11000, load + 256 - 0x11000);
//WRITEFILE2('0', (void*) dst0, info[7] + 256 - dst0);
UCL_DECOMPRESS((void *) src0, srcl, (void *) dst0, &dlen);
//WRITEFILE2('1', (void*) dst0, info[7] + 256 - dst0);
handle_imports((void *) bimp, onam, dst0);
//WRITEFILE2('2', (void*) 0x11000, load + 256 - 0x11000);
//WRITEFILE2('2', (void*) dst0, info[7] + 256 - dst0);
#ifdef STUB_FOR_DLL
reloc_main();
//WRITEFILE2('3', (void*) dst0, info[7] + 256 - dst0);
#endif
}
+142 -14
View File
@@ -29,11 +29,18 @@
<jreiser@users.sourceforge.net>
*/
#undef STUB_IN_THUMB_MODE
#if defined(__ARM_ARCH_4T__) || defined(__ARM_ARCH_5T__)
# define STUB_IN_THUMB_MODE
#endif
.text
.align 0
.globl upx_main
.globl _start
#ifdef STUB_IN_THUMB_MODE
_start:
stmfd sp!, {r0 - r3, lr}
@@ -41,27 +48,28 @@ _start:
@ otherwise the THUMB mode stuff fails
adr r0, SRC0
ldmia r0, {r1, r2, r3} @ r1 - src, r2 - slen, r3 - dst
add r1, r1, r2
L01:
.L01:
ldr r2, [r3]
add r3, r3, #4096
cmp r3, r1
bls L01
bls .L01
#ifdef __ARM_ARCH_4T__
adr lr, armret
# ifdef __ARM_ARCH_4T__
adr lr, .Larmret
adr ip, call_upxmain + 1
bx ip
armret:
.Larmret:
ldmfd sp!, {r0 - r3, lr}
ldr ip, ENTR
bx ip
#else
# else
blx upx_main @ call thumb armv5t style
ldmfd sp!, {r0 - r3, lr}
ldr pc, ENTR @ original entry
#endif
# endif
@@@@@@@@@@@@@@@@
@@ -71,7 +79,7 @@ armret:
GetProcAddressA:
ldr r3, GETP
t_callr3:
.Lcallr3:
ldr r3, [r3]
bx r3
@@ -82,12 +90,12 @@ t_callr3:
LoadLibraryW:
ldr r3, LLIB
b t_callr3
b .Lcallr3
#ifdef __ARM_ARCH_4T__
# ifdef __ARM_ARCH_4T__
call_upxmain:
b upx_main
#endif
# endif
@@@@@@@@@@@@@@@@
@@ -95,16 +103,16 @@ call_upxmain:
.thumb_func
get_le32: @ optimized for size
mov r1, #3
g0:
.Lg0:
ldrb r3, [r0, r1]
lsl r2, r2, #8
add r2, r2, r3
sub r1, #1
bpl g0
bpl .Lg0
mov r0, r2
bx lr
#if 0
# if 0
// debugging stuff - helpers for dumping memory to a file or deleting a file
@@ -159,8 +167,123 @@ writefile:
filename:
.byte '\\', 0, 'r', 0, 0, 0
# endif
#else // stub in ARM mode
_start:
# ifdef STUB_FOR_DLL
cmp r1, #1
bne .Lstart_orig
# endif
stmfd sp!, {r0 - r3, lr}
adr r0, SRC0
bl upx_main
ldmfd sp!, {r0 - r3, lr}
.Lstart_orig:
ldr pc, ENTR
.global LoadLibraryW
LoadLibraryW:
ldr r3, LLIB
ldr pc, [r3]
.global GetProcAddressA
GetProcAddressA:
ldr r3, GETP
ldr pc, [r3]
.global get_le32
get_le32: @ optimized for size
mov r2, #3
.Lg0:
ldrb r3, [r0, r2]
subs r2, r2, #1
add r1, r3, r1, asl #8
bpl .Lg0
mov r0, r1
gret:
mov pc, lr
# ifdef STUB_FOR_DLL
.global reloc_main
buffer .req r0
dest .req r1
addval .req r2
reloc_main:
ldr buffer, BREL
ldr addval, DST0
sub dest, addval, #4
.Lreloc_loop:
ldrb r3, [buffer], #1
cmp r3, #0
beq gret
cmp r3, #0xf0
bichs ip, r3, #0xf0
ldrhsb r3, [buffer, #1] @ get_le16
addhs ip, r3, ip, lsl #8
ldrhsb r3, [buffer], #2
addhs r3, r3, ip, lsl #8
add dest, dest, r3
ldrb r3, [dest] @ get_be32
add ip, r3, ip, lsl #8
ldrb r3, [dest, #1]
add ip, r3, ip, lsl #8
ldrb r3, [dest, #2]
add ip, r3, ip, lsl #8
ldrb r3, [dest, #3]
add ip, r3, ip, lsl #8
add ip, ip, addval
str ip, [dest]
b .Lreloc_loop
# endif
# if 0
// debugging stuff - helpers for dumping memory to a file or deleting a file
// !!!!! check the lines with "system dependent" below before trying
.global CFwrap
CFwrap:
ldr pc, createfilew
.global WFwrap
WFwrap:
ldr pc, writefile
.global CHwrap
CHwrap:
ldr pc, closehandle
.global DelFile
DelFile:
adr r1, filename
strb r0, [r1, #2]
mov r0, r1
ldr pc, deleteffilew
.code 32
createfilew:
.word 0x1f7927c @ system dependent
closehandle:
.word 0x1f71594 @ system dependent
deleteffilew:
.word 0x1f7b920 @ system dependent
writefile:
.word 0x1f79434 @ system dependent
filename:
.byte '\\', 0, 'r', 0, 0, 0
# endif
#endif
@@@@@@@@@@@@@@@@ paramater area for UPX
.code 32
@@ -173,3 +296,8 @@ DST0: .ascii "DST0"
GETP: .ascii "GETP"
LLIB: .ascii "LOAD"
ENTR: .ascii "ENTR"
BREL: .ascii "BREL"
#ifndef STUB_IN_THUMB_MODE
# include "l_armpe_c.s"
#endif