1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

add UPX_F_VMLINUX_AMD64, UPX_F_VMLINUX_ARM

This commit is contained in:
John Reiser 2006-12-16 08:13:34 -08:00
parent d7837d9179
commit 112eff2509
18 changed files with 5723 additions and 7 deletions

View File

@ -433,6 +433,9 @@ private:
#define UPX_F_BSD_ELF_i386 25
#define UPX_F_BSD_SH_i386 26
#define UPX_F_VMLINUX_AMD64 27
#define UPX_F_VMLINUX_ARM 28
#define UPX_F_PLAIN_TEXT 127
#define UPX_F_ATARI_TOS 129

View File

@ -311,6 +311,16 @@ struct Shdr
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
};
enum { // sh_flags
SHF_WRITE = (1 << 0), /* Writable */
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
SHF_EXECINSTR = (1 << 2), /* Executable */
SHF_MERGE = (1 << 4), /* Might be merged */
SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */
SHF_INFO_LINK = (1 << 6), /* `sh_info' contains SHT index */
SHF_LINK_ORDER = (1 << 7), /* Preserve order after combining */
};
}
__attribute_packed;

File diff suppressed because it is too large Load Diff

View File

@ -73,6 +73,82 @@ protected:
Elf_LE32_Ehdr ehdri; // from input file
};
class PackVmlinuxARM : public Packer
{
typedef Packer super;
public:
PackVmlinuxARM(InputFile *f);
virtual ~PackVmlinuxARM();
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUX_ARM; }
virtual const char *getName() const { return "vmlinux/ARM"; }
virtual const char *getFullName(const options_t *) const { return "ARM-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
virtual bool canPack();
virtual int canUnpack();
protected:
virtual Elf_LE32_Shdr const *getElfSections();
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
// virtual const upx_byte *getLoader() const;
// virtual int getLoaderSize() const;
int n_ptload;
unsigned sz_ptload;
Elf_LE32_Phdr *phdri; // from input file
Elf_LE32_Shdr *shdri; // from input file
char *shstrtab; // from input file
Elf_LE32_Shdr *p_text;
Elf_LE32_Shdr *p_note0;
Elf_LE32_Shdr *p_note1;
Elf_LE32_Ehdr ehdri; // from input file
};
class PackVmlinuxAMD64 : public Packer
{
typedef Packer super;
public:
PackVmlinuxAMD64(InputFile *f);
virtual ~PackVmlinuxAMD64();
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUX_AMD64; }
virtual const char *getName() const { return "vmlinux/AMD64"; }
virtual const char *getFullName(const options_t *) const { return "amd64-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
virtual bool canPack();
virtual int canUnpack();
protected:
virtual Elf_LE64_Shdr const *getElfSections();
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
// virtual const upx_byte *getLoader() const;
// virtual int getLoaderSize() const;
int n_ptload;
unsigned sz_ptload;
Elf_LE64_Phdr *phdri; // from input file
Elf_LE64_Shdr *shdri; // from input file
char *shstrtab; // from input file
Elf_LE64_Shdr *p_text;
Elf_LE64_Shdr *p_note0;
Elf_LE64_Shdr *p_note1;
Elf_LE64_Ehdr ehdri; // from input file
};
#endif /* already included */

View File

@ -210,7 +210,11 @@ const char *Packer::getDecompressorSections() const
|| UPX_F_LINUX_ELF64_AMD ==ph.format
|| UPX_F_LINUX_ELF32_ARMLE==ph.format
|| UPX_F_LINUX_ELFPPC32 ==ph.format
|| UPX_F_LINUX_ELF32_ARMBE==ph.format ) {
|| UPX_F_LINUX_ELF32_ARMBE==ph.format
|| UPX_F_BSD_ELF_i386 ==ph.format
|| UPX_F_VMLINUX_AMD64 ==ph.format
|| UPX_F_VMLINUX_ARM ==ph.format
) {
return opt->small ? lzma_elf_small : lzma_elf_fast;
}
return opt->small ? lzma_small : lzma_fast;
@ -243,6 +247,8 @@ void Packer::defineDecompressorSymbols()
|| UPX_F_LINUX_ELFPPC32 ==ph.format
|| UPX_F_LINUX_ELF32_ARMBE==ph.format
|| UPX_F_BSD_ELF_i386 ==ph.format
|| UPX_F_VMLINUX_AMD64 ==ph.format
|| UPX_F_VMLINUX_ARM ==ph.format
) {
// ELF calls the decompressor many times; the parameters change!
return;
@ -257,6 +263,7 @@ void Packer::defineDecompressorSymbols()
(res->pos_bits << 16);
if (linker->bele->isBE()) // big endian - bswap32
acc_swab32s(&properties);
linker->defineSymbol("lzma_properties", properties);
// -2 for properties
linker->defineSymbol("lzma_c_len", ph.c_len - 2);

View File

@ -55,6 +55,7 @@
#include "p_ps1.h"
#include "p_mach.h"
#include "p_armpe.h"
#include "linker.h"
/*************************************************************************
@ -192,6 +193,10 @@ Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
//
// linux kernel
//
if ((p = func(new PackVmlinuxARM(f), user)) != NULL)
return p;
if ((p = func(new PackVmlinuxAMD64(f), user)) != NULL)
return p;
if ((p = func(new PackVmlinuxI386(f), user)) != NULL)
return p;
if ((p = func(new PackVmlinuzI386(f), user)) != NULL)

View File

@ -46,8 +46,13 @@ endif
ifndef STUBS
STUBS += amd64-linux.elf-entry.h
STUBS += amd64-linux.elf-fold.h
STUBS += amd64-linux.kernel.vmlinux.h
STUBS += amd64-linux.kernel.vmlinux-head.h
STUBS += amd64-linux.kernel.vmlinuz.h
STUBS += arm-linux.elf-entry.h
STUBS += arm-linux.elf-fold.h
STUBS += arm-linux.kernel.vmlinux.h
STUBS += arm-linux.kernel.vmlinux-head.h
STUBS += armeb-linux.elf-entry.h
STUBS += armeb-linux.elf-fold.h
STUBS += arm.v4a-wince.pe.h
@ -640,6 +645,49 @@ i386-linux.kernel.vmlinux-head.h : $(srcdir)/src/$$T.S
$(call tc,bin2h) tmp/$T.bin $@
# /***********************************************************************
# // amd64-linux.kernel.vmlinux
# // amd64-linux.kernel.vmlinuz
# // amd64-linux.kernel.vmlinux-head
# ************************************************************************/
amd64-linux.kernel.vmlinu%.h : tc_list = arch-i386 default
amd64-linux.kernel.vmlinu%.h : $(srcdir)/src/$$T.S
$(call tc,gcc) -c -x assembler-with-cpp $< -o tmp/$T.bin
$(call tc,f-embed_objinfo,tmp/$T.bin)
$(call tc,bin2h-c) tmp/$T.bin $@
amd64-linux.kernel.vmlinux-head.h : $(srcdir)/src/$$T.S
$(call tc,gcc) -c -x assembler-with-cpp $< -o tmp/$T.o
$(call tc,objcopy) --output-target binary --only-section .text tmp/$T.o tmp/$T.bin
$(call tc,bin2h) tmp/$T.bin $@
# /***********************************************************************
# // arm-linux.kernel.vmlinux
# // arm-linux.kernel.vmlinuz
# // arm-linux.kernel.vmlinux-head
# ************************************************************************/
tc.arm-linux.kernel.gcc = arm-linux-gcc-4.1.0 -march=armv5 -nostdinc -MMD -MT $@
tc.arm-linux.kernel.gcc += -fno-exceptions -fno-asynchronous-unwind-tables
tc.arm-linux.kernel.gcc += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
arm-linux.kernel.vmlinu%.h : tc_bfdname = elf32-littlearm
arm-linux.kernel.vmlinu%.h : tc_list = arm-linux.kernel default
arm-linux.kernel.vmlinu%.h : $(srcdir)/src/$$T.S
$(call tc,gcc) -c -x assembler-with-cpp $< -o tmp/$T.bin
$(call tc,f-embed_objinfo,tmp/$T.bin)
$(call tc,bin2h-c) tmp/$T.bin $@
arm-linux.kernel.vmlinux-head.h : $(srcdir)/src/$$T.S
$(call tc,gcc) -c -x assembler-with-cpp $< -o tmp/$T.o
$(call tc,objcopy) --output-target binary --only-section .text tmp/$T.o tmp/$T.bin
$(call tc,bin2h) tmp/$T.bin $@
# /***********************************************************************
# // i386-win32.pe
# ************************************************************************/

View File

@ -0,0 +1,39 @@
/* amd64-linux.kernel.vmlinux-head.h
created from amd64-linux.kernel.vmlinux-head.bin, 39 (0x27) bytes
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 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>
*/
#define STUB_AMD64_LINUX_KERNEL_VMLINUX_HEAD_SIZE 39
#define STUB_AMD64_LINUX_KERNEL_VMLINUX_HEAD_ADLER32 0x7a591357
#define STUB_AMD64_LINUX_KERNEL_VMLINUX_HEAD_CRC32 0xf4f6740a
unsigned char stub_amd64_linux_kernel_vmlinux_head[39] = {
140,200,131,192, 8,142,216,142,192,141,142, 0,144, 0, 0,137, /* 0x 0 */
73,248,137, 65,252, 15,178, 97,248,106, 0,157, 14,184, 0, 0, /* 0x 10 */
0, 0,232,252,255,255,255 /* 0x 20 */
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
/* arm-linux.kernel.vmlinux-head.h
created from arm-linux.kernel.vmlinux-head.bin, 20 (0x14) bytes
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 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>
*/
#define STUB_ARM_LINUX_KERNEL_VMLINUX_HEAD_SIZE 20
#define STUB_ARM_LINUX_KERNEL_VMLINUX_HEAD_ADLER32 0x621b0b3f
#define STUB_ARM_LINUX_KERNEL_VMLINUX_HEAD_CRC32 0x87e74167
unsigned char stub_arm_linux_kernel_vmlinux_head[20] = {
112, 0, 32,225, 1, 96, 34,233, 2,208,160,225,254,255,255,235, /* 0x 0 */
2,160,157,232 /* 0x 10 */
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
#include "i386-linux.kernel.vmlinux-head.S"

View File

@ -0,0 +1 @@
#include "i386-linux.kernel.vmlinux.S"

View File

@ -0,0 +1 @@
#include "i386-linux.kernel.vmlinuz.S"

View File

@ -72,8 +72,10 @@
#define CHECK_BYTE /*empty*/
#endif /*}*/
#undef GETBIT
#define GETBIT ADD2S(bits,bits); bleq get8_n2e
#undef getnextb
#define getnextb(reg) GETBIT; ADC2(reg,reg) /* Out: condition code not changed */
#define jnextb0 GETBIT; bcc
#define jnextb1 GETBIT; bcs

View File

@ -0,0 +1,40 @@
/*
; arm-linux.kernel.vmlinux-head.S -- set up stack for vmlinux/arm format
;
; This file is part of the UPX executable compressor.
;
; Copyright (C) 2006 John 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.
;
; John Reiser
; <jreiser@users.sourceforge.net>
*/
/* Calling sequence of equivalent code in arch/arm/boot/compressed/misc.c:
decompress_kernel: # (char *out, char *tmp, char *end_tmp, int arch_id)
*/
bkpt
stmdb r2!,{r0,sp,lr}
mov sp,r2
// PackVmlinuxARM::pack knows the format of the next instruction.
bl COMPRESSED_LENGTH
ldmia sp,{r1,sp,pc}
// Compressed data appears >here<, then decompressor.
// vi:ts=8:et:nowrap

View File

@ -0,0 +1,115 @@
/*
; i386-linux.kernel.vmlinux.S -- loader & decompressor for the vmlinux/i386 format
;
; This file is part of the UPX executable compressor.
;
; Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 1996-2006 Laszlo Molnar
; Copyright (C) 2004-2006 John 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 Reiser
; <jreiser@users.sourceforge.net>
*/
#include "arch/arm/v5a/macros.S"
/*
; =============
; ============= ENTRY POINT
; =============
; In:
; r0= outptr; r1= &tmp; r3= arch_id; lr= retaddr, inptr - N
How to debug: run under qemu (http://fabrice.bellard.free.fr/qemu/)
after un-commenting the bkpt opcode below. That opcode forces qemu
to stop in gdb. You'll have to "set $pc+=4" by hand.
*/
section LINUX000
bkpt // qemu breakpoint
ldr r1,[lr,#-4] // 'bl' instruction
str r3,[sp,$-4]! // push arch_id
bic r1,r1,#~0<<24 // word count
sub sp,sp,#4 // space for outsize
mov r1,r1,lsl #2 // byte count
mov r3,sp // &outsize
.long 0xe2411000 + BYTE_ADJ // sub r1,r1,#BYTE_ADJ // insize
mov r2,r0 // outptr
.long 0xe28e0000 + WORD_ADJ // add r0,lr,#WORD_ADJ // inptr
/*
r0= inptr
r1= insize
r2= outptr
r3= &outsize
*/
section LXCALLT1
mvn ip,#1
bkpt
section LXCKLLT1
mvn ip,#2
bkpt
.long filter_cto,filter_length
section LXMOVEUP
mvn ip,#3
bkpt
// =============
// ============= DECOMPRESSION
// =============
#include "arch/arm/v5a/nrv2b_d8.S"
#include "arch/arm/v5a/nrv2d_d8.S"
#include "arch/arm/v5a/nrv2e_d8.S"
#include "arch/arm/v5a/lzma_d.S"
// =============
// ============= UNFILTER
// =============
section LXCKLLT9
mvn ip,#4
bkpt
section LXCALLT9
mvn ip,#5
bkpt
section LINUX990
mvn ip,#6
bkpt
mov pc,lr
section LINUX991
mvn ip,#7
bkpt
#if 0 /*{*/
or ebp, -1 // decompressor assumption
#endif /*}*/
section LINUX992
mvn ip,#8
bkpt
#include "include/header.S"
// vi:ts=8:et:nowrap