From 813349fd2376074bf0ac554630f3a99343165216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Moln=C3=A1r?= Date: Wed, 29 Mar 2006 06:45:38 +0000 Subject: [PATCH] arm/pe: support for nrv2b, support for cpu = 0x1c2, certificate info now removed committer: ml1050 1143614738 +0000 --- src/p_armpe.cpp | 27 ++++++++++++++-------- src/stub/Makefile | 16 ++++++++----- src/stub/arm_nrv2b_d8.S | 19 ++++++--------- src/stub/l_armpe.asm | 7 ++++-- src/stub/l_armpe.h | 51 ++++++++++++++++++++++++++++++++--------- src/stub/l_armpe_c.c | 18 +++++++++++---- src/stub/l_armpe_s.S | 2 ++ 7 files changed, 96 insertions(+), 44 deletions(-) diff --git a/src/p_armpe.cpp b/src/p_armpe.cpp index 4175ebc3..9c245e33 100644 --- a/src/p_armpe.cpp +++ b/src/p_armpe.cpp @@ -179,8 +179,14 @@ PackArmPe::~PackArmPe() const int *PackArmPe::getCompressionMethods(int method, int level) const { - static const int m_nrv2e[] = { M_NRV2E_8, -1 }; - UNUSED(method); UNUSED(level); + static const int m_nrv2b[] = { M_NRV2B_8, M_NRV2E_8, -1 }; + static const int m_nrv2e[] = { M_NRV2E_8, M_NRV2B_8, -1 }; + UNUSED(level); + + if (M_IS_NRV2B(method)) + return m_nrv2b; + if (M_IS_NRV2E(method)) + return m_nrv2e; return m_nrv2e; } @@ -1528,7 +1534,7 @@ unsigned PackArmPe::stripDebug(unsigned overlaystart) bool PackArmPe::canPack() { - if (!readFileHeader() || ih.cpu != 0x1c0) + if (!readFileHeader() || (ih.cpu != 0x1c0 && ih.cpu != 0x1c2)) return false; return true; } @@ -1539,10 +1545,11 @@ int PackArmPe::buildLoader(const Filter *ft) UNUSED(ft); // prepare loader initLoader(nrv_loader, sizeof(nrv_loader), -1, 2); - addLoader("ARMWPE00,ARMWPE99," - "IDENTSTR,UPX1HEAD", - NULL - ); + if (ph.method == M_NRV2E_8) + addLoader("ARMWPE2E", NULL); + else if (ph.method == M_NRV2B_8) + addLoader("ARMWPE2B", NULL); + addLoader("IDENTSTR,UPX1HEAD", NULL); return getLoaderSize(); } @@ -1561,7 +1568,7 @@ void PackArmPe::pack(OutputFile *fo) // check the PE header // FIXME: add more checks if (!opt->force && ( - (ih.cpu != 0x1c0) + (ih.cpu != 0x1c0 && ih.cpu != 0x1c2) || (ih.opthdrsize != 0xe0) || ((ih.flags & EXECUTABLE) == 0) || (ih.subsystem != 9) @@ -1573,7 +1580,9 @@ void PackArmPe::pack(OutputFile *fo) throwCantPack("unexpected value in PE header (try --force)"); if (IDSIZE(PEDIR_SEC)) - throwCantPack("compressing certificate info is not supported"); + IDSIZE(PEDIR_SEC) = IDADDR(PEDIR_SEC) = 0; + // throwCantPack("compressing certificate info is not supported"); + if (IDSIZE(PEDIR_COMRT)) throwCantPack(".NET files (win32/net) are not yet supported"); #if 1 diff --git a/src/stub/Makefile b/src/stub/Makefile index bc173786..bbe7e913 100644 --- a/src/stub/Makefile +++ b/src/stub/Makefile @@ -554,12 +554,16 @@ 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 $(MAKEFILE_LIST) - $(GCC_ARM) -mthumb-interwork -c l_armpe_s.S arm_nrv2e_d8.S - $(GCC_ARM) -mthumb -mthumb-interwork -Os -c l_armpe_c.c - $(LD_ARM) -o l_armpe_.out l_armpe_s.o l_armpe_c.o arm_nrv2e_d8.o - $(OBJCOPY_ARM) --only-section .text -O binary l_armpe_.out l_armpe_.bin - $(BIN2H_WINCE) l_armpe_.ah +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 + $(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.ah + $(GCC_ARM) -mthumb -mthumb-interwork -Os -c l_armpe_c.c -DNRV2B + $(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.ah $(NASM) -f bin -o $T.bin $< $(BIN2H) $T.bin nrv_loader $@ diff --git a/src/stub/arm_nrv2b_d8.S b/src/stub/arm_nrv2b_d8.S index fa1131ac..c2dee56b 100644 --- a/src/stub/arm_nrv2b_d8.S +++ b/src/stub/arm_nrv2b_d8.S @@ -40,7 +40,7 @@ /* r12 ("ip") is assumed to be a scratch register. */ -#define GETBIT blx g1b +#define GETBIT add bits,bits; mov lr,pc; beq get1_n2b #define getnextb(reg) GETBIT; adc reg,reg #define jnextb0 GETBIT; bcc @@ -53,15 +53,14 @@ ucl_nrv2b_decompress_8: .globl ucl_nrv2b_decompress_8 @ ARM mode bx r12 @ enter THUMB mode .code 16 @ THUMB mode -go_thumb_n2b: + .thumb_func +go_thumb_n2b: .globl go_thumb_n2b add r1,len,src @ r1= eof_src; push {r1,r2,r3, r4,r5,r6,r7, lr} mov bits,#1; neg off,bits @ off= -1 initial condition lsl bits,#31 @ 1<<31: refill next time mov wrnk,#0xd lsl wrnk,#8 @ 0xd00 - adr g1b,get1_n2b @ load pc-relative address - add g1b,#1 @ force THUMB mode b top_n2b eof_n2b: @@ -71,23 +70,19 @@ eof_n2b: str dst,[r4] pop {r4,r5,r6,r7, pc} @ return - - .align 2 @ 1<<2 for benefit of loading address with 'adr' above get1_n2b: - add bits,bits; bne get1r_n2b @ CarryOut has data bit - ldrb bits,[src] @ zero-extend next byte + ldrb bits,[src] @ zero-extend next byte adc bits,bits @ double and insert CarryIn as low bit - add src,#1 + add src,#1 lsl bits,#24 @ move to top byte, and set CarryOut from old bit 8 -get1r_n2b: - bx lr + mov pc,lr lit_n2b: ldrb tmp,[src]; add src,#1 strb tmp,[dst]; add dst,#1 top_n2b: - jnextb1 lit_n2b + jnextb1 lit_n2b mov len,#1 @ the msb getoff_n2b: @ ss11 len= [2..) getnextb(len) diff --git a/src/stub/l_armpe.asm b/src/stub/l_armpe.asm index 742dd2db..a31e93c9 100644 --- a/src/stub/l_armpe.asm +++ b/src/stub/l_armpe.asm @@ -39,9 +39,12 @@ ; ============= ENTRY POINT ; ============= -; __ARMWPE00__ +; __ARMWPE2E__ start: -%include "l_armpe_.ah" +%include "l_armpe2e.ah" +; __ARMWPE2B__ +%include "l_armpe2b.ah" +; __ARMWPEHE__ %include "header.ash" eof: ; __ARMWPE99__ diff --git a/src/stub/l_armpe.h b/src/stub/l_armpe.h index 95d378a2..71311c5d 100644 --- a/src/stub/l_armpe.h +++ b/src/stub/l_armpe.h @@ -1,4 +1,4 @@ -/* l_armpe.h -- created from l_armpe.bin, 561 (0x231) bytes +/* l_armpe.h -- created from l_armpe.bin, 1039 (0x40f) bytes This file is part of the UPX executable compressor. @@ -27,11 +27,11 @@ */ -#define NRV_LOADER_SIZE 561 -#define NRV_LOADER_ADLER32 0xa4adcc1c -#define NRV_LOADER_CRC32 0x5606a013 +#define NRV_LOADER_SIZE 1039 +#define NRV_LOADER_ADLER32 0xa2a48332 +#define NRV_LOADER_CRC32 0x9e9a3347 -unsigned char nrv_loader[561] = { +unsigned char nrv_loader[1039] = { 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 */ @@ -62,10 +62,39 @@ unsigned char nrv_loader[561] = { 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, 85, 80, 88, 33,161,216,208,213, 0, 0, 0, 0, /* 0x 1e0 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 1f0 */ - 0, 0, 0, 45, 65, 82, 77, 87, 80, 69, 48, 48, 0, 0, 0, 0, /* 0x 200 */ - 0, 85, 80, 88, 49, 72, 69, 65, 68, 0,228, 1, 0, 0, 65, 82, /* 0x 210 */ - 77, 87, 80, 69, 57, 57, 0, 4, 2, 0, 0,255,255,255,255, 4, /* 0x 220 */ - 2 /* 0x 230 */ +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 */ }; diff --git a/src/stub/l_armpe_c.c b/src/stub/l_armpe_c.c index fa103949..3bdb14d8 100644 --- a/src/stub/l_armpe_c.c +++ b/src/stub/l_armpe_c.c @@ -29,9 +29,16 @@ */ +#ifdef NRV2E int thumb_nrv2e_d8(const unsigned char * src, unsigned src_len, unsigned char * dst, unsigned * dst_len); -#define ucl_nrv2e_decompress_8 thumb_nrv2e_d8 +#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 +#endif + void *LoadLibraryW(const unsigned short *); void *GetProcAddressA(const void *, const void *); @@ -85,9 +92,9 @@ static void handle_imports(const unsigned char *imp, unsigned name_offset, } // debugging stuff -int CFWrap(short *, int, int, int, int, int, int); +int CFwrap(short *, int, int, int, int, int, int); void WFwrap(int, const void *, int, int *, int); -void CHWrap(int); +void CHwrap(int); #define WRITEFILE2(name0, buf, len) \ do { short b[3]; b[0] = '\\'; b[1] = name0; b[2] = 0; \ int h = CFwrap(b, 0x40000000L, 3, 0, 2, 0x80, 0);\ @@ -120,8 +127,11 @@ void upx_main(const unsigned *info) // unsigned entr = info[8]; #endif +#ifdef SAFE + dlen = info[3]; +#endif //WRITEFILE2('0', (void*) 0x11000, load + 256 - 0x11000); - ucl_nrv2e_decompress_8((void *) src0, srcl, (void *) dst0, &dlen); + ucl_decompress((void *) src0, srcl, (void *) dst0, &dlen); //WRITEFILE2('1', (void*) 0x11000, load + 256 - 0x11000); handle_imports((void *) bimp, onam, dst0); //WRITEFILE2('2', (void*) 0x11000, load + 256 - 0x11000); diff --git a/src/stub/l_armpe_s.S b/src/stub/l_armpe_s.S index e5bae4d2..bd14bf9b 100644 --- a/src/stub/l_armpe_s.S +++ b/src/stub/l_armpe_s.S @@ -84,8 +84,10 @@ LoadLibraryW: ldr r3, LLIB b t_callr3 +#ifdef __ARM_ARCH_4T__ call_upxmain: b upx_main +#endif @@@@@@@@@@@@@@@@