Compare commits
194 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fcc22a0aa3 | |||
| aabefff298 | |||
| ed25c64e97 | |||
| b7dc870c2d | |||
| 9bea608843 | |||
| 9db1732c36 | |||
| 39f1a70174 | |||
| 1810440355 | |||
| 37ac8f179e | |||
| 626a09328f | |||
| 8d489d0d77 | |||
| 776f3db0d7 | |||
| 6046057b88 | |||
| 7e85d9e549 | |||
| 01c8a8b1c2 | |||
| c9bf6ac9ae | |||
| 62e4d69be9 | |||
| 62ac733b09 | |||
| c3b3e1b1b9 | |||
| a791e96e00 | |||
| e87f5521c1 | |||
| 366a708f3a | |||
| 70ba662574 | |||
| b389abd99f | |||
| 4aa2d14fe3 | |||
| af7de75ad4 | |||
| d461ebbda1 | |||
| 55ef94abcd | |||
| afaf489d99 | |||
| 20e4cbfd13 | |||
| f3b8c9f34e | |||
| 45e8ff25a5 | |||
| 268e322e1c | |||
| d3bcba6a05 | |||
| cc4ef1944d | |||
| 5aa8486265 | |||
| fd181673cd | |||
| 62c9547c4e | |||
| cdd117bfb9 | |||
| 304ba57dad | |||
| 69eaaa4177 | |||
| 452ac52fcb | |||
| 40cf489290 | |||
| 891d6be4a6 | |||
| 5d45ce5cf7 | |||
| a0f2241f3a | |||
| aa513bf7d3 | |||
| b2d65febc8 | |||
| 23a6d326e8 | |||
| 5b2f1b6d8b | |||
| b4e9ad031b | |||
| 8b7ebcf040 | |||
| af05296631 | |||
| 29d693de2d | |||
| 51ac5172f5 | |||
| 24ce1ef5e7 | |||
| f6d1e269d1 | |||
| 62c2f5228d | |||
| 9882d9683b | |||
| 45ce89ee1f | |||
| bfb9df1553 | |||
| a5f79204ce | |||
| e322613d84 | |||
| fbb60f5191 | |||
| 899e7d2f39 | |||
| 8e2aa07747 | |||
| a0d262cd76 | |||
| b43a7edee4 | |||
| 7760bbd77c | |||
| 9c0f1b02a7 | |||
| 4ecfff4d8d | |||
| ac03b89f38 | |||
| 620174aea9 | |||
| ab50d28bc4 | |||
| b5318602d1 | |||
| bff2a63ea2 | |||
| aacfb8820e | |||
| 98e8c031d0 | |||
| beb4319d1e | |||
| 2558243c83 | |||
| b670e8d1ac | |||
| 68f8358f06 | |||
| db5a099097 | |||
| ce33ffb62a | |||
| 59a2fb9cfd | |||
| 75bba319de | |||
| f78e9261f3 | |||
| 5f77562333 | |||
| 5c4f01a68d | |||
| 35f6f998e6 | |||
| 6737a3ae09 | |||
| 09559bee8c | |||
| f487ea27a8 | |||
| a3d95f239a | |||
| 023c06e178 | |||
| 414a6c1c9e | |||
| 910e18fb22 | |||
| ac441fd1cf | |||
| 0c328372b5 | |||
| 55ef60a6d4 | |||
| c33584e683 | |||
| ee8c7453bd | |||
| 0330369603 | |||
| 3f7b642c7d | |||
| eb6c51426a | |||
| 0337bdb9fd | |||
| 7aedc62058 | |||
| bfc835cbbf | |||
| 5c6ba30c48 | |||
| 8fe4824ed2 | |||
| d40cb3bd55 | |||
| 4bcd3ac5d7 | |||
| e2b8e9dea9 | |||
| 572314bf3f | |||
| 14d303d331 | |||
| 24ffaa0738 | |||
| 5d9b6d056d | |||
| 5c28ff15ba | |||
| 06ceb2f2a1 | |||
| 7373e1dd8b | |||
| 4b1a9e714d | |||
| 9d76136358 | |||
| b3502420ad | |||
| dd7ac7cca9 | |||
| 31dfa18e9b | |||
| 3e785008d3 | |||
| 6b7c7f755c | |||
| c55a8a8703 | |||
| 64c97308ac | |||
| 3551b0b95a | |||
| 9f16b5c4af | |||
| 9777e549cb | |||
| fbfced1b93 | |||
| 1a84b4681c | |||
| 4bf81b8e1c | |||
| c282e7fdb4 | |||
| d339ee3135 | |||
| 1de95de299 | |||
| 96c998a1d7 | |||
| b5413c0156 | |||
| 7371c195ff | |||
| 0866a1996b | |||
| 41f44c4e78 | |||
| 131712c3bd | |||
| bae12aaab7 | |||
| 74d5844d8c | |||
| c87908266a | |||
| f788d76b8c | |||
| 41031e572e | |||
| f8a0864c1b | |||
| 949587334c | |||
| 0bc6a1a7f1 | |||
| 0d9cbfe927 | |||
| 8742a524c3 | |||
| 79bf2297b5 | |||
| 32e9e23630 | |||
| 7f1cecba92 | |||
| efd30c61c3 | |||
| 4c97b11207 | |||
| 58ea0ab745 | |||
| 3547c71ad5 | |||
| 044d6b2ce2 | |||
| a0b26b6c06 | |||
| 8e3bfde439 | |||
| 6507de959b | |||
| 56d09bf3b5 | |||
| 232754b978 | |||
| 75ef603308 | |||
| a5a2fcee4d | |||
| f86d57bfe3 | |||
| 615615b1df | |||
| aeba0ce170 | |||
| 5ce60aad53 | |||
| dbc01de9a0 | |||
| dfaf3f24fc | |||
| 14b0527e79 | |||
| f0148c3161 | |||
| 6a5e3d924d | |||
| 664a82e7c9 | |||
| e2763b4826 | |||
| afb29b19c2 | |||
| 8d60343940 | |||
| 67a77f1880 | |||
| c933974174 | |||
| 19715903fb | |||
| c88f72fd15 | |||
| 7818596271 | |||
| 9cb8d7bca6 | |||
| 46f9256114 | |||
| c26ef87202 | |||
| 89fee5b835 | |||
| f5795eb01b | |||
| dbf0c9f016 | |||
| 586b43048f |
+9
-3
@@ -1,7 +1,13 @@
|
||||
.bzr*
|
||||
.darcs*
|
||||
.git*
|
||||
.hg*
|
||||
_darcs
|
||||
B
|
||||
ChangeLog.cvs*
|
||||
TODO.*
|
||||
build
|
||||
build*
|
||||
doxygen
|
||||
maint
|
||||
ChangeLog.cvs*
|
||||
GNUmakefile
|
||||
MMakefile
|
||||
TODO.*
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Toplevel Makefile for UPX
|
||||
|
||||
SHELL = /bin/sh
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
export SHELL = /bin/sh
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = .
|
||||
@@ -18,22 +20,24 @@ all mostlyclean clean distclean maintainer-clean:
|
||||
dist: distclean
|
||||
false
|
||||
|
||||
zip:
|
||||
cd .. && rm -f upx-current.zip && zip -r upx-current.zip upx
|
||||
|
||||
ifneq ($(wildcard CVS/R*),)
|
||||
CVS_ROOT := $(shell cat CVS/Root)
|
||||
CVS_REPO := $(shell cat CVS/Repository)
|
||||
endif
|
||||
|
||||
cvs-info:
|
||||
@echo 'CVS info: $(CVS_ROOT) $(CVS_REPO)'
|
||||
|
||||
cvs-admin-ko:
|
||||
cvs admin -ko .
|
||||
cvs update -P -d
|
||||
cvs -q -z6 update -P -d
|
||||
|
||||
ChangeLog:
|
||||
# automatically generate ChangeLog from CVS
|
||||
ChangeLog ChangeLog.cvs:
|
||||
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
|
||||
|
||||
ChangeLog.cvsps:
|
||||
cvsps > $@
|
||||
|
||||
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
.PHONY: dist cvs-admin-ko ChangeLog
|
||||
|
||||
.NOEXPORT:
|
||||
.PHONY: dist cvs-info cvs-admin-ko ChangeLog ChangeLog.cvs
|
||||
|
||||
|
||||
@@ -4,8 +4,17 @@ User visible changes for UPX
|
||||
|
||||
[ UNSTABLE BETA VERSION - please see README.1ST for some more info ]
|
||||
|
||||
Changes in 1.93 beta (07 Feb 2005):
|
||||
Changes in 1.94 beta (11 Mar 2006):
|
||||
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
|
||||
* new format: added support for arm/pe (ARM executables running on WinCE)
|
||||
* new format: added support for linux elf/amd64
|
||||
* new format: added support for linux elf/ppc32
|
||||
* new format: added support for mach/ppc32 (Apple Mac OS X)
|
||||
* win32/pe: hopefully working "load config" support
|
||||
* win32/pe: R6002 runtime errors worked around
|
||||
* win32/pe: the stub now clears the dirty stack
|
||||
|
||||
Changes in 1.93 beta (07 Feb 2005):
|
||||
* vmlinuz/386: fixes to support more kernels
|
||||
|
||||
Changes in 1.92 beta (20 Jul 2004):
|
||||
@@ -93,7 +102,6 @@ Changes in 1.20 (23 May 2001)
|
||||
our unstable development releases 1.1x and 1.9x]
|
||||
|
||||
Changes in 1.08 (30 Apr 2001)
|
||||
* INFO: http://upx.sourceforge.net now is the new permanent UPX home page
|
||||
* new native port to atari/tos
|
||||
* win32/pe: shortened the identstring
|
||||
* source code: portability fixes - UPX now builds cleanly under m68k CPUs
|
||||
@@ -313,7 +321,7 @@ Changes in 0.40 (05 Oct 1998)
|
||||
* fixed a small but fatal bug in dos/sys introduced in 0.30
|
||||
* fixed a rare bug in dos/exe
|
||||
* worked around a bug in djgpp's strip 2.8
|
||||
* Allegro packfile support should work now
|
||||
* djgpp/coff: Allegro packfile support should work now
|
||||
* added dos/exeh compression method (works on 386+)
|
||||
|
||||
Changes in 0.30 (27 Jul 1998)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -42,8 +42,6 @@ More formats:
|
||||
- freebsd/386 (generic), freebsd/elf386 (specialized).
|
||||
Probably could share most of the linux code.
|
||||
|
||||
- Windows CE
|
||||
|
||||
- add support for self-extracting HTML pages using a Javascript stub
|
||||
(like the AlgART HTML Packer "AHP")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -25,11 +25,15 @@ will be called version 2.00.
|
||||
|
||||
The main news since 1.25 are:
|
||||
- slightly better compression using the new NRV2E algorithm
|
||||
- new options for compression tuining (e.g. `--brute')
|
||||
- new options for compression tuning (e.g. `--brute')
|
||||
- support for bootable Linux kernels ("vmlinuz/386")
|
||||
- support for Linux kernel building ("vmlinux/386")
|
||||
- direct Linux ELF-to-memory decompression ("linux/elf386") and
|
||||
shell-to-memory decompression ("linux/sh386")
|
||||
- support for arm/WinCE ("arm/pe") exes
|
||||
- support for mach/ppc32
|
||||
- support for Linux elf/ppc32
|
||||
- support for Linux elf/amd64
|
||||
- support for playstation exes ("ps1/exe")
|
||||
- lots of new bugs ;-) take care
|
||||
|
||||
@@ -129,8 +133,8 @@ THE FUTURE
|
||||
COPYRIGHT
|
||||
=========
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
@@ -149,7 +153,7 @@ Markus & Laszlo
|
||||
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
|
||||
|
||||
|
||||
|
||||
+7
-2
@@ -8,6 +8,8 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -23,11 +25,14 @@ will be called version 2.00.
|
||||
|
||||
The main news since 1.25 are:
|
||||
- slightly better compression using the new NRV2E algorithm
|
||||
- new options for compression tuining (e.g. `--brute')
|
||||
- new options for compression tuning (e.g. `--brute')
|
||||
- support for bootable Linux kernels ("vmlinuz/386")
|
||||
- support for Linux kernel building ("vmlinux/386")
|
||||
- direct Linux ELF-to-memory decompression ("linux/elf386") and
|
||||
shell-to-memory decompression ("linux/sh386")
|
||||
- support for arm/WinCE ("arm/pe") exes
|
||||
- support for mach/ppc32
|
||||
- support for Linux elf/ppc32
|
||||
- support for Linux elf/amd64
|
||||
- support for playstation exes ("ps1/exe")
|
||||
- lots of new bugs ;-) take care
|
||||
|
||||
|
||||
@@ -110,6 +110,12 @@ If you want to modify the stub sources you'll also need
|
||||
|
||||
- Linux (for the linux/386 stubs)
|
||||
|
||||
- Other cross compilers targeted at the following architectures:
|
||||
- powerpc-750-linux-gnu
|
||||
- x86_64-unknown-linux-gnu
|
||||
- arm-wince-pe
|
||||
|
||||
- ASM5900 - a MIPS R3000 assembler
|
||||
|
||||
Misc. notes
|
||||
-----------
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
UPX TODO list. Last updated 2005-01-08.
|
||||
UPX TODO list. Last updated 2006-03-11.
|
||||
|
||||
|
||||
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
|
||||
|
||||
- stub ctojr32 needs CPU 486 because of bswap
|
||||
- [None]
|
||||
|
||||
|
||||
OTHER:
|
||||
|
||||
- rewrite linker.cpp to allow arbitrary length section names
|
||||
- docs: convert docs from upx.pod to use AsciiDoc
|
||||
|
||||
- check all <const_cast> to make sure they are not invalid
|
||||
|
||||
@@ -108,8 +108,6 @@ FORMAT WIN32/PE
|
||||
2 - easy - mfx + ml) new switch(es) : do not compress resource types x,y,z
|
||||
or resource names a,b,c
|
||||
|
||||
3 - medium - ml) rebuild exports
|
||||
|
||||
3 - difficult) don't compress the BSS section and other holes.
|
||||
|
||||
4 - medium - ml) fix when objectalign < 0x1000
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ SHELL = /bin/sh
|
||||
top_srcdir = ..
|
||||
|
||||
PACKAGE = upx
|
||||
VERSION_DATE = 07 Feb 2005
|
||||
VERSION_DATE = 11 Mar 2006
|
||||
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||
|
||||
TRIMSPACE = cat
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ loads of cryptic comments like `__PERELOC2__'.
|
||||
|
||||
If you look at the C++ source files, however you can notice that these
|
||||
comment strings (without the leading and trailing underscores) are used
|
||||
in the following way (they are all 8 character length strings):
|
||||
in the following way:
|
||||
|
||||
addLoader("PEMAIN20",
|
||||
ih.entry ? "PEDOJUMP" : "PERETURN",
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
UPX and SELinux
|
||||
March 6, 2006
|
||||
|
||||
|
||||
When a program that has been compressed by UPX is run, the decompressor
|
||||
must create and write new memory pages of executable instructions.
|
||||
SELinux (Security Enhanced Linux) directly controls the conditions
|
||||
under which generating and/or executing new instructions is allowed,
|
||||
so the configuration settings of SELinux affect the running of programs
|
||||
that have been compressed by UPX.
|
||||
|
||||
In SELinux "strict enforcing" mode (the most restrictive), generating
|
||||
new instructions at runtime is not allowed at all: any page with
|
||||
PROT_EXEC permission must be mapped from a file in a mounted filesystem
|
||||
that has 'x' [eXecute] permission, and the generation of such files is
|
||||
also tightly controlled. A program that was compressed by UPX will not
|
||||
run in SELinux strict enforcing mode. Attempts will fail with exit
|
||||
code 127, and a record will be added to the history file
|
||||
/var/log/audit/audit.log.
|
||||
|
||||
In "targeted enforcing" mode, SELinux pays close attention mostly to
|
||||
designated processes that run with elevated privileges: web server,
|
||||
print server, login server, etc. Ordinary user excutables receive
|
||||
much less scrutiny. However, one of the eventual goals of SELinux is to
|
||||
eradicate runtime generation of instructions because of the possibility
|
||||
for exploitation by malware (virus, trojan, key logger, privilege
|
||||
elevation exploit, etc.) Thus targeted enforcing mode notices and
|
||||
logs the use of "execmem" capability that is used by a program which
|
||||
was compressed by UPX. In keeping with the goal of eventual prohibition,
|
||||
SELinux ordinarily would deny execmem. However, most current SELinux
|
||||
systems, including Fedora Core 5 [set for release March 15, 2006],
|
||||
override this with "allow_exemem=1" in /etc/selinux/targeted/booleans.
|
||||
Thus a program compressed by UPX will run in the default installed
|
||||
configuration (targeted enforcing, allow_execmem=1) of SELinux under
|
||||
Fedora Core 5. Each invocation will add a few lines to the log file
|
||||
/var/log/audit/audit.log, one line for each use of execmem. If the
|
||||
SELinux policy becomes more restrictive in the future, then a special
|
||||
SELinux class or other mechanism must be created for compressed programs,
|
||||
or else UPX-compressed executables will not run then.
|
||||
|
||||
In its "permissive" modes, SELinux just logs the potential problems,
|
||||
but otherwise does not interfere. A program compressed by UPX will run
|
||||
in any permissive mode.
|
||||
+10
-9
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
||||
=head1 ABSTRACT
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -77,6 +77,10 @@ B<UPX> is a versatile executable packer with the following features:
|
||||
* vmlinuz/386 [bootable Linux kernel]
|
||||
* watcom/le (supporting DOS4G, PMODE/W, DOS32a and CauseWay)
|
||||
* win32/pe
|
||||
* arm/pe
|
||||
* linux/elfamd64
|
||||
* linux/elfppc32
|
||||
* mach/elfppc32
|
||||
|
||||
- portable: UPX is written in portable endian-neutral C++
|
||||
|
||||
@@ -730,7 +734,7 @@ Extra options available for this executable format:
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR RTM32/PE
|
||||
=head2 NOTES FOR RTM32/PE and ARM/PE
|
||||
|
||||
Same as win32/pe.
|
||||
|
||||
@@ -865,9 +869,6 @@ Extra options available for this executable format:
|
||||
unexpected value in a header field.
|
||||
Use with care.
|
||||
|
||||
--strip-loadconf=0 Don't strip Structured Exception Handling load config [DEFAULT].
|
||||
--strip-loadconf=1 Strip Structured Exception Handling load config.
|
||||
|
||||
--strip-relocs=0 Don't strip relocation records.
|
||||
--strip-relocs=1 Strip relocation records. [DEFAULT]
|
||||
This option only works on executables with base
|
||||
@@ -920,13 +921,13 @@ Please report all bugs immediately to the authors.
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
|
||||
Copyright (C) 2000-2005 John F. Reiser
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
|
||||
Copyright (C) 2002-2005 Jens Medoch
|
||||
Copyright (C) 2002-2006 Jens Medoch
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
The GNU bfd binary file descriptor package, part of the GNU binutils package,
|
||||
contains code to recognize an Elf file by looking at fields in the file header.
|
||||
Many programs (such as gdb, size, objdump, objcopy, strip and others) use bfd.
|
||||
Unfortunately, bfd has been overly strict. In releases
|
||||
binutils-2.9.1.0.4, binutils-2.9.1.0.23, binutils-2.9.5.0.0,
|
||||
binutils-2.10.1,
|
||||
gdb-4.17, gdb-5.0,
|
||||
and probably others,
|
||||
bfd does not recognize a file with zero in Elf32_Ehdr.e_shoff, .e_shentsize,
|
||||
or .e_shnum, even though the operating system kernel does not care, and many
|
||||
bfd clients would work just fine in these cases.
|
||||
|
||||
Because of its desire to create small size compressed executables, UPX
|
||||
generates and uses Elf files with zero in .e_shoff, .e_shentsizes, and .e_shnum.
|
||||
As a result, many widely-distributed instances of gdb, size, objdump, etc.,
|
||||
refuse to work on UPX-packed executables.
|
||||
|
||||
Here is a patch to bfd/elfcode.h which enables many bfd clients to work
|
||||
with UPX-packed executables. The last two lines of the patch are
|
||||
if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
--- elfcode.h.orig Mon Jun 16 11:45:32 1997
|
||||
+++ elfcode.h Sat Apr 22 10:18:56 2000
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ELF executable support for BFD.
|
||||
- Copyright 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
|
||||
+ Copyright 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
|
||||
|
||||
Written by Fred Fish @ Cygnus Support, from information published
|
||||
in "UNIX System V Release 4, Programmers Guide: ANSI C and
|
||||
@@ -517,14 +517,14 @@
|
||||
elf_debug_file (i_ehdrp);
|
||||
#endif
|
||||
|
||||
- /* If there is no section header table, we're hosed. */
|
||||
- if (i_ehdrp->e_shoff == 0)
|
||||
+ /* If there is no section header table, and relocatable, then we're hosed. */
|
||||
+ if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
|
||||
goto got_wrong_format_error;
|
||||
|
||||
/* As a simple sanity check, verify that the what BFD thinks is the
|
||||
size of each section header table entry actually matches the size
|
||||
- recorded in the file. */
|
||||
- if (i_ehdrp->e_shentsize != sizeof (x_shdr))
|
||||
+ recorded in the file, but only if there are any sections. */
|
||||
+ if (i_ehdrp->e_shentsize != sizeof (x_shdr) && i_ehdrp->e_shnum != 0)
|
||||
goto got_wrong_format_error;
|
||||
|
||||
ebd = get_elf_backend_data (abfd);
|
||||
@@ -579,6 +579,7 @@
|
||||
/* Allocate space for a copy of the section header table in
|
||||
internal form, seek to the section header table in the file,
|
||||
read it in, and convert it to internal form. */
|
||||
+ if (i_ehdrp->e_shnum!=0) {
|
||||
i_shdrp = ((Elf_Internal_Shdr *)
|
||||
bfd_alloc (abfd, sizeof (*i_shdrp) * i_ehdrp->e_shnum));
|
||||
elf_elfsections (abfd) = ((Elf_Internal_Shdr **)
|
||||
@@ -609,6 +610,7 @@
|
||||
if (! bfd_section_from_shdr (abfd, i_ehdrp->e_shstrndx))
|
||||
goto got_no_match;
|
||||
}
|
||||
+ }
|
||||
|
||||
/* Read in the program headers. */
|
||||
if (i_ehdrp->e_phnum == 0)
|
||||
@@ -644,6 +646,7 @@
|
||||
bfd_section_from_shdr with it (since this particular strtab is
|
||||
used to find all of the ELF section names.) */
|
||||
|
||||
+ if (i_ehdrp->e_shstrndx != 0) {
|
||||
shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
|
||||
if (!shstrtab)
|
||||
goto got_no_match;
|
||||
@@ -657,6 +660,7 @@
|
||||
if (! bfd_section_from_shdr (abfd, shindex))
|
||||
goto got_no_match;
|
||||
}
|
||||
+ }
|
||||
|
||||
/* Let the backend double check the format and override global
|
||||
information. */
|
||||
@@ -930,7 +934,7 @@
|
||||
{
|
||||
Elf_Internal_Shdr *hdr;
|
||||
Elf_Internal_Shdr *verhdr;
|
||||
- long symcount; /* Number of external ELF symbols */
|
||||
+ unsigned long symcount; /* Number of external ELF symbols */
|
||||
elf_symbol_type *sym; /* Pointer to current bfd symbol */
|
||||
elf_symbol_type *symbase; /* Buffer for generated bfd symbols */
|
||||
Elf_Internal_Sym i_sym;
|
||||
@@ -978,7 +982,7 @@
|
||||
sym = symbase = NULL;
|
||||
else
|
||||
{
|
||||
- long i;
|
||||
+ unsigned long i;
|
||||
|
||||
if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
|
||||
return -1;
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
#! /usr/bin/perl -w
|
||||
#! /usr/bin/perl
|
||||
|
||||
|
||||
##############################################################
|
||||
@@ -7,9 +7,9 @@
|
||||
### ###
|
||||
##############################################################
|
||||
|
||||
## $Revision: 2.58 $
|
||||
## $Date: 2004/11/07 15:28:35 $
|
||||
## $Author: fluffy $
|
||||
## $Revision: 2.59 $
|
||||
## $Date: 2005/05/18 05:34:34 $
|
||||
## $Author: kfogel $
|
||||
##
|
||||
|
||||
use strict;
|
||||
@@ -141,7 +141,7 @@ use User::pwent qw( getpwnam );
|
||||
# Globals --------------------------------------------------------------------
|
||||
|
||||
# In case we have to print it out:
|
||||
my $VERSION = '$Revision: 2.58 $';
|
||||
my $VERSION = '$Revision: 2.59 $';
|
||||
$VERSION =~ s/\S+\s+(\S+)\s+\S+/$1/;
|
||||
|
||||
## Vars set by options:
|
||||
@@ -1317,9 +1317,9 @@ my $self = shift; my $class = ref $self;
|
||||
while (<OLD_LOG>) {
|
||||
if ( ! $passed_first_entry ) {
|
||||
if ( ( ! $started_first_entry )
|
||||
and /^(\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)/ ) {
|
||||
and /^(\d\d\d\d-\d\d-\d\d\s+(\w+\s+)?\d\d:\d\d)/ ) {
|
||||
$started_first_entry = 1;
|
||||
} elsif ( /^(\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)/ ) {
|
||||
} elsif ( /^(\d\d\d\d-\d\d-\d\d\s+(\w+\s+)?\d\d:\d\d)/ ) {
|
||||
$passed_first_entry = 1;
|
||||
print NEW_LOG $_;
|
||||
}
|
||||
@@ -2391,7 +2391,7 @@ sub maybe_grab_accumulation_date {
|
||||
my $boundary_date;
|
||||
while (<LOG>)
|
||||
{
|
||||
if (/^(\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)/)
|
||||
if (/^(\d\d\d\d-\d\d-\d\d\s+(\w+\s+)?\d\d:\d\d)/)
|
||||
{
|
||||
$boundary_date = "$1";
|
||||
last;
|
||||
|
||||
+3
-8
@@ -1,4 +1,3 @@
|
||||
GNUmakefile
|
||||
*.0??
|
||||
*.d
|
||||
*.dat
|
||||
@@ -10,15 +9,11 @@ GNUmakefile
|
||||
*.rel
|
||||
*.res
|
||||
*.pdb
|
||||
*.out
|
||||
*.upx
|
||||
.gdbinit
|
||||
.Attic
|
||||
.deps
|
||||
B
|
||||
GNUmakefile
|
||||
MMakefile
|
||||
compress_nrv.*
|
||||
upx
|
||||
upx_nrv
|
||||
upx_nrv.*
|
||||
upx_ucl
|
||||
upx_ucl.*
|
||||
version1*.h
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
ifeq ($(DEPS_DONE),)
|
||||
DEPS_DONE := 1
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // automated dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
ifeq ($(DEPMODE),gcc)
|
||||
EXTRA_CFLAGS += -Wp,-MMD,.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -Wp,-MMD,.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
ifeq ($(DEPMODE),linux-intelc)
|
||||
EXTRA_CFLAGS += -MMD -MF.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -MMD -MF.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
ifeq ($(DEPMODE),linux-pgi)
|
||||
## NOTE: -MMD does not work...
|
||||
EXTRA_CFLAGS += -MD.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -MD.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(HAVE_DEPS),1)
|
||||
ifeq ($(strip $(wildcard .deps)),)
|
||||
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
||||
else
|
||||
DEPS_FILES := $(wildcard .deps/*.d)
|
||||
ifneq ($(strip $(DEPS_FILES)),)
|
||||
include $(DEPS_FILES)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
endif # DEPS_DONE
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
DEPMODE := gcc
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // defaults for gcc
|
||||
# ************************************************************************/
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
|
||||
|
||||
CFLAGS_W =
|
||||
CFLAGS_M =
|
||||
CFLAGS_O =
|
||||
CXXFLAGS_W =
|
||||
CXXFLAGS_M =
|
||||
CXXFLAGS_O =
|
||||
|
||||
CFLAGS = $(call __mkflags,CFLAGS_W) $(call __mkflags,CFLAGS_M) $(call __mkflags,CFLAGS_O)
|
||||
CXXFLAGS = $(call __mkflags,CXXFLAGS_W) $(call __mkflags,CXXFLAGS_M) $(call __mkflags,CXXFLAGS_O)
|
||||
|
||||
|
||||
#
|
||||
# cflags
|
||||
#
|
||||
|
||||
##CFLAGS_WERROR = -Werror
|
||||
CFLAGS_WERROR =
|
||||
CFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wbad-function-cast -Wcast-align -Wcast-qual -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wwrite-strings
|
||||
CXXFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wcast-align -Wcast-qual -Winline -Woverloaded-virtual -Wpointer-arith -Wshadow -Wsign-promo -Wwrite-strings
|
||||
|
||||
##CFLAGS_M += -fno-builtin
|
||||
##CFLAGS_M += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
||||
CXXFLAGS_M = $(CFLAGS_M)
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS_O = -g -O0
|
||||
else
|
||||
##CFLAGS_O = -Os -fstrict-aliasing
|
||||
CFLAGS_O = -O2 -fstrict-aliasing
|
||||
##CFLAGS_O = -O2 -fno-strict-aliasing
|
||||
endif
|
||||
CXXFLAGS_O = $(CFLAGS_O) -fconserve-space
|
||||
##CXXFLAGS += -fasynchronous-exceptions
|
||||
|
||||
|
||||
#
|
||||
# cxxflags for g++ 3.2 or better
|
||||
|
||||
##CXXFLAGS_W += -Wdisabled-optimization -Wpacked
|
||||
|
||||
|
||||
#
|
||||
# ldflags
|
||||
#
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
LDFLAGS += -g
|
||||
else
|
||||
LDFLAGS += -s
|
||||
endif
|
||||
LDFLAGS += -Wl,-Map,$T.map
|
||||
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
|
||||
|
||||
# vi:nowrap
|
||||
@@ -1,48 +0,0 @@
|
||||
UDIR := $($(U)DIR)
|
||||
|
||||
ifneq ($(strip $(wildcard $(UDIR)/include)),) # { include
|
||||
DEFS += -DWITH_$(U)
|
||||
INCLUDES += -I$(UDIR)/include
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/debug/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/debug/src/.libs
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/$(release)/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/$(release)/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/$(target)/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/$(target)/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/release/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/release/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR))),)
|
||||
LIBDIRS += $(UDIR)
|
||||
DOS_LIBDIRS := $(DOS_LIBDIRS);$(UDIR)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
LDLIBS += -l$(u)
|
||||
DOS_LDLIBS += $(u).lib
|
||||
|
||||
|
||||
DEFS := $(DEFS)
|
||||
INCLUDES := $(INCLUDES)
|
||||
LIBDIRS := $(LIBDIRS)
|
||||
LDLIBS := $(LDLIBS)
|
||||
DOS_LDLIBS := $(DOS_LDLIBS)
|
||||
|
||||
endif # } include
|
||||
+41
-74
@@ -1,88 +1,55 @@
|
||||
#
|
||||
# UPX Makefile (GNU make) - works with unix/win32/djgpp2
|
||||
#
|
||||
# usage:
|
||||
# `make target=linux' # linux
|
||||
# `make target=dos32-djggp2' # dos32 - djggp2
|
||||
# `make target=win32-cygwin' # win32 - cygwin
|
||||
# `make target=win32-mingw32' # win32 - mingw32
|
||||
# `make target=win32-rsxnt' # win32 - rsxnt
|
||||
# `make target=win32-bc' # win32 - Borland C++
|
||||
# `make target=win32-dm' # win32 - Digital Mars C++
|
||||
# `make target=win32-ic' # win32 - Intel C++
|
||||
# `make target=win32-vc' # win32 - Visual C++
|
||||
# `make target=win32-wc' # win32 - Watcom C++
|
||||
# `make target=cross-amd64-linux' # x86_64-linux cross compiler
|
||||
# `make target=cross-mingw32' # i586-mingw32msvc cross compiler
|
||||
# `make target=cross-mint' # m68k-atari-mint cross compiler
|
||||
# `make target=gcc' # generic gcc
|
||||
#
|
||||
# you can also set the `UPX_MAKE_TARGET' environment variable.
|
||||
# UPX Makefile - needs GNU make 3.80 or better
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
export SHELL = /bin/sh
|
||||
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
|
||||
|
||||
# configuration section
|
||||
|
||||
ifeq ($(strip $(UCLDIR)),)
|
||||
# change this to reflect where the UCL library is
|
||||
UCLDIR = $(HOME)/local/src/ucl-1.03
|
||||
srcdir ?= $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
||||
ifneq ($(srcdir),./)
|
||||
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,')
|
||||
##$(info Info: using VPATH . $(srcdir))
|
||||
VPATH := . $(srcdir)
|
||||
endif
|
||||
|
||||
## you can set the default target here
|
||||
##target =
|
||||
ifeq ($(CXX),)
|
||||
CXX = g++
|
||||
endif
|
||||
ifeq ($(CXX),g++)
|
||||
CXXFLAGS += -O2 -MMD
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
|
||||
endif
|
||||
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
|
||||
CXXLD ?= $(CXX)
|
||||
|
||||
DEBUG = 0
|
||||
exeext ?= .out
|
||||
libext ?= .a
|
||||
objext ?= .o
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = ..
|
||||
# we need UCL and zlib - you can set envvar UCLDIR
|
||||
ifneq ($(wildcard $(UCLDIR)/include/ucl/ucl.h),)
|
||||
INCLUDES += -I$(UCLDIR)/include
|
||||
LIBS += $(addprefix -L,$(dir $(wildcard $(UCLDIR)/libucl$(libext) $(UCLDIR)/src/.libs/libucl$(libext))))
|
||||
endif
|
||||
LIBS += -lucl -lz
|
||||
|
||||
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
|
||||
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
|
||||
|
||||
##### You should not have to change anything below this line. #####
|
||||
all: upx$(exeext)
|
||||
|
||||
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
|
||||
$($(notdir $@).PRE_LINK_STEP)
|
||||
$(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS))
|
||||
$($(notdir $@).POST_LINK_STEP)
|
||||
|
||||
# /***********************************************************************
|
||||
# // object files
|
||||
# ************************************************************************/
|
||||
%.o : %.cpp
|
||||
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
|
||||
|
||||
# these use exceptions & RTTI
|
||||
OBJECTS1 = \
|
||||
compress$o except$o file$o lefile$o \
|
||||
filter$o linker$o mem$o msg$o stdcxx$o work$o ui$o \
|
||||
packer$o packerf$o packhead$o packmast$o \
|
||||
p_com$o p_djgpp2$o p_elks$o p_exe$o \
|
||||
p_lx_elf$o p_lx_exc$o p_lx_sep$o p_lx_sh$o \
|
||||
p_ps1$o p_sys$o p_tmt$o p_tos$o \
|
||||
p_unix$o p_vmlinz$o p_vmlinx$o p_w16ne$o p_w32pe$o p_wcle$o
|
||||
mostlyclean clean distclean maintainer-clean:
|
||||
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)
|
||||
|
||||
# no exceptions or RTTI
|
||||
OBJECTS2 = \
|
||||
filteri$o help$o main$o mygetopt$o snprintf$o util$o \
|
||||
c_init$o c_file$o c_none$o c_screen$o \
|
||||
s_object$o s_djgpp2$o s_vcsa$o s_win32$o
|
||||
|
||||
# pure C sources
|
||||
OBJECTS3 =
|
||||
|
||||
OBJECTS = $(OBJECTS1) $(OBJECTS2) $(OBJECTS3)
|
||||
LIBS =
|
||||
RESOURCES =
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // main
|
||||
# ************************************************************************/
|
||||
|
||||
override WITH_ZLIB = 1
|
||||
|
||||
include $(srcdir)/Makefile.bld
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
include $(srcdir)/Makedefs.dep
|
||||
|
||||
$(OBJECTS): miniacc.h
|
||||
|
||||
# vi:nowrap
|
||||
-include *.d
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
|
||||
@@ -1,720 +0,0 @@
|
||||
# /***********************************************************************
|
||||
# // prepare setup
|
||||
# ************************************************************************/
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .a .c .cpp .exe .lib .o .obj .rc .res .ttp
|
||||
|
||||
|
||||
ifeq ($(srcdir),)
|
||||
srcdir = .
|
||||
endif
|
||||
|
||||
VPATH = $(srcdir)
|
||||
|
||||
|
||||
# auto-detect the target unless given on the commandline
|
||||
ifeq ($(strip $(target)),)
|
||||
# try environment variable UPX_MAKE_TARGET
|
||||
target := $(UPX_MAKE_TARGET)
|
||||
endif
|
||||
ifeq ($(strip $(target)),)
|
||||
ifneq ($(strip $(wildcard /usr/include/linux)),)
|
||||
target = linux
|
||||
endif
|
||||
##ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),)
|
||||
##target = sparc-sun-solaris
|
||||
##endif
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(target)),)
|
||||
include please_specify_a_target
|
||||
endif
|
||||
|
||||
|
||||
# util var for use in the rules - basename of the current target
|
||||
override T = $(basename $@)
|
||||
|
||||
# expand "VAR" into "$(VAR) $(EXTRA_VAR) $(UPX_EXTRA_VAR)"
|
||||
override __mkflags = $(strip $($(1)) $(EXTRA_$(1)) $(UPX_EXTRA_$(1)))
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // compiler defaults
|
||||
# ************************************************************************/
|
||||
|
||||
CC_SRC = $<
|
||||
CXX_SRC = $<
|
||||
CC_COMPILE = $(CC) $(CCARCH) $(call __mkflags,DEFS) $(call __mkflags,INCLUDES) $(call __mkflags,CFLAGS) $(CFLAGS_OUTPUT) -c $(CC_SRC)
|
||||
CXX_COMPILE = $(CXX) $(CXXARCH) $(call __mkflags,DEFS) $(call __mkflags,INCLUDES) $(call __mkflags,CXXFLAGS) $(CXXFLAGS_OUTPUT) -c $(CXX_SRC)
|
||||
CXX_LINK_EXE = $(CXXLD) $(CXXLDARCH) $(call __mkflags,LDFLAGS) $(LINK_EXE_OUTPUT) $^ $(call __mkflags,LDLIBS)
|
||||
STUBEDIT_EXE =
|
||||
STUBIFY_EXE =
|
||||
CHMOD_EXE =
|
||||
|
||||
o = .o
|
||||
a = .a
|
||||
e =
|
||||
DEFS =
|
||||
INCLUDES =
|
||||
LIBDIRS =
|
||||
DOS_LDLIBS =
|
||||
DOS_LIBDIRS =
|
||||
|
||||
# CC defaults
|
||||
CC = INVALID_TARGET_CC
|
||||
CCARCH =
|
||||
CFLAGS =
|
||||
CFLAGS_OUTPUT =
|
||||
|
||||
# CXX defaults
|
||||
CXX = $(CC)
|
||||
CXXARCH = $(CCARCH)
|
||||
CXXFLAGS = $(CFLAGS)
|
||||
CXXFLAGS_OUTPUT = $(CFLAGS_OUTPUT)
|
||||
|
||||
# CXXLD defaults
|
||||
CXXLD = $(CXX)
|
||||
CXXLDARCH = $(CXXARCH)
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT =
|
||||
LDLIBS =
|
||||
LINK_EXE_LDFLAGS =
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
DEFS += -DDEBUG
|
||||
## DEFS += -DTESTING
|
||||
endif
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // compression libraries
|
||||
# ************************************************************************/
|
||||
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
DOS_LDLIBS += zlib.lib
|
||||
ZLIBDIR:=$(strip $(subst \,/,$(ZLIBDIR)))
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR))),)
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR)/include/zlib.h)),)
|
||||
INCLUDES += -I$(ZLIBDIR)/include
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR)/src/zlib.h)),)
|
||||
INCLUDES += -I$(ZLIBDIR)/src
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR)/zlib.h)),)
|
||||
INCLUDES += -I$(ZLIBDIR)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
UCLDIR:=$(strip $(subst \,/,$(UCLDIR)))
|
||||
NRVDIR:=$(strip $(subst \,/,$(NRVDIR)))
|
||||
u = ucl
|
||||
U = UCL
|
||||
upx_exe_tail =
|
||||
include $(srcdir)/Makedefs.inc
|
||||
ifneq ($(strip $(wildcard $(NRVDIR)/include/nrv)),)
|
||||
u = nrv
|
||||
U = NRV
|
||||
upx_exe_tail := _$(u)
|
||||
include $(srcdir)/Makedefs.inc
|
||||
endif
|
||||
upx_exe = upx$(upx_exe_tail)$(e)
|
||||
|
||||
override tmp := -Wl,--rpath,
|
||||
LDRPATH := $(addprefix $(tmp),$(LIBDIRS))
|
||||
LIBDIRS += .
|
||||
LDLIBDIRS := $(addprefix -L,$(LIBDIRS))
|
||||
|
||||
##LDFLAGS += $(LDRPATH)
|
||||
LDFLAGS += $(LDLIBDIRS)
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // compiler settings
|
||||
# ************************************************************************/
|
||||
|
||||
###
|
||||
### generic gcc
|
||||
###
|
||||
|
||||
ifeq ($(target),gcc)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### linux - gcc
|
||||
###
|
||||
|
||||
ifeq ($(target),linux)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
override arch := $(shell uname -m | sed -e 's/^i[3456789]86$$/i386/')
|
||||
ifeq ($(arch),i386)
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
endif
|
||||
DEFS += -D_FILE_OFFSET_BITS=64
|
||||
LDLIBS += -lmcheck
|
||||
##CFLAGS_WERROR = -Werror
|
||||
ifeq ($(DEBUG),1)
|
||||
else
|
||||
##LDFLAGS += -static
|
||||
STUBEDIT_EXE = objcopy -S -R .comment -R .note $@
|
||||
ifeq ($(arch),i386)
|
||||
## STUBIFY_EXE = perl $(srcdir)/stub/scripts/brandelf.pl $@
|
||||
endif
|
||||
endif
|
||||
CHMOD_EXE = chmod 755 $@
|
||||
endif # linux
|
||||
|
||||
|
||||
###
|
||||
### linux/i386 - Borland C++ 5.7 (Kylix 3)
|
||||
###
|
||||
|
||||
ifeq ($(target),linux-bc57)
|
||||
##DEPMODE := linux-XXX ## FIXME
|
||||
CC = bc++ -q -3
|
||||
CFLAGS = -w '-w!'
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS += -ls
|
||||
LINK_EXE_OUTPUT = -e$@
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
# warning: do not use option `-d' --> incorrect string merging will happen
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -dc
|
||||
else
|
||||
CFLAGS += -O2 -dc
|
||||
endif
|
||||
# transform `-lxx -lyy' into `libxx.a libyy.a'
|
||||
LDLIBS := $(shell echo "$(LDLIBS)" | perl -pe 's/-l(.+?)\b/lib\1.a/g')
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### linux/i386 - Intel C++
|
||||
###
|
||||
|
||||
ifeq ($(target),linux-intelc)
|
||||
DEPMODE := linux-intelc
|
||||
CC = icc
|
||||
CXX = icpc
|
||||
CCARCH += -march=i386 -mcpu=i686 -nolib_inline
|
||||
DEFS += -D_FILE_OFFSET_BITS=64
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
CFLAGS = $(CFLAGS_WERROR)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -g -O0
|
||||
else
|
||||
CFLAGS += -O2
|
||||
endif
|
||||
LDFLAGS += -Wl,-Map,$T.map
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### linux/i386 - Portland Group PGI C++ 5.x
|
||||
###
|
||||
|
||||
ifeq ($(target),linux-pgi)
|
||||
DEPMODE := linux-pgi
|
||||
CC = pgcc
|
||||
CXX = pgCC
|
||||
CCARCH += -tp=p6
|
||||
DEFS += -D_FILE_OFFSET_BITS=64
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
##CFLAGS += -Minform=info
|
||||
CXXFLAGS = $(CFLAGS) -tused
|
||||
ifeq ($(DEBUG),1)
|
||||
else
|
||||
CFLAGS += -O2
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### Linux cross compilers
|
||||
###
|
||||
|
||||
ifeq ($(target),cross-amd64-linux)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
CC = x86_64-linux-gcc
|
||||
CXX = x86_64-linux-g++
|
||||
LDLIBS += -lmcheck
|
||||
endif # cross-amd64-linux
|
||||
|
||||
ifeq ($(target),cross-m68k-linux)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
CC = m68k-linux-gcc
|
||||
CXX = m68k-linux-g++
|
||||
##LDLIBS += -lmcheck
|
||||
endif # cross-m68k-linux
|
||||
|
||||
|
||||
###
|
||||
### sparc-sun-solaris2.8
|
||||
###
|
||||
|
||||
ifeq ($(target),sparc-sun-solaris)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### Atari cross compilers
|
||||
###
|
||||
|
||||
ifeq ($(target),cross-mint)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .ttp
|
||||
CC = m68k-atari-mint-gcc
|
||||
CXX = m68k-atari-mint-g++
|
||||
CCARCH += -m68000
|
||||
endif
|
||||
|
||||
ifeq ($(target),cross-mint-m68040)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .ttp
|
||||
CC = m68k-atari-mint-gcc
|
||||
CXX = m68k-atari-mint-g++
|
||||
CCARCH += -m68040
|
||||
endif
|
||||
|
||||
ifeq ($(target),cross-mint-m68020-60)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .ttp
|
||||
CC = m68k-atari-mint-gcc
|
||||
CXX = m68k-atari-mint-g++
|
||||
CCARCH += -m68020-60 -m68881
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### dos32 - djgpp2 / emx
|
||||
###
|
||||
|
||||
ifeq ($(target),dos32-djgpp2)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CXX = gxx
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
CFLAGS_WERROR = -Werror
|
||||
STUBEDIT_EXE = stubedit $@ bufsize=0xfc00
|
||||
ifneq ($(strip $(wildcard $(DJDIR)/bin/mfxdjstubify.ex[eE])),)
|
||||
ifneq ($(strip $(wildcard $(DJDIR)/bin/cwsdstub.ex[eE])),)
|
||||
STUBIFY_EXE = mfxdjstubify -v -s $(DJDIR)/bin/cwsdstub.exe $@
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(target),dos32-emx)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CXX = gcc
|
||||
CFLAGS_O = -O2
|
||||
CCARCH += -mno-probe
|
||||
LDFLAGS = -L. -s
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### win32 - cygwin / mingw32 / rsxnt
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-cygwin)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
##CXX = g++-2
|
||||
e = .exe
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
LDLIBS += -lwinmm
|
||||
endif
|
||||
|
||||
ifeq ($(target),win32-mingw32)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
LDLIBS += -lwinmm
|
||||
endif
|
||||
|
||||
# mingw32 cross compiler
|
||||
ifeq ($(target),cross-mingw32)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CC = i586-mingw32msvc-gcc
|
||||
CXX = i586-mingw32msvc-g++
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
LDLIBS += -lwinmm
|
||||
endif
|
||||
|
||||
# rsxnt (g++ 2.8.1)
|
||||
ifeq ($(target),win32-rsxnt)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CXX = gcc
|
||||
CFLAGS_O = -O2
|
||||
CCARCH += -Zwin32 -Zsys -mno-probe
|
||||
LDFLAGS = -L. -s
|
||||
STUBEDIT_EXE = pestack -s1024 -c1024 $@
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### win32 - Borland C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-bc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = bcc32 -3
|
||||
ifeq ($(UPX_BROKEN_INCLUDES),1)
|
||||
ifneq ($(srcdir),.)
|
||||
INCLUDES += -I$(srcdir)
|
||||
endif
|
||||
INCLUDES += -I$(srcdir)/acc
|
||||
ifneq ($(strip $(wildcard $(srcdir)/filter)),)
|
||||
INCLUDES += -I$(srcdir)/filter
|
||||
endif
|
||||
endif
|
||||
CFLAGS = -w -w-inl -g1
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS = -ls
|
||||
LINK_EXE_OUTPUT = -e$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -d
|
||||
else
|
||||
CFLAGS += -O2 -d
|
||||
endif
|
||||
endif # win32-bc
|
||||
|
||||
|
||||
###
|
||||
### win32 - Digital Mars C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-dm)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = dmc -mn
|
||||
CFLAGS = -w- -wx
|
||||
CXXFLAGS = $(CFLAGS) -Aa -Ab -Ae -Ar
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS = -L/map
|
||||
LINK_EXE_OUTPUT = -o$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -o- -g -s
|
||||
else
|
||||
CFLAGS += -o
|
||||
endif
|
||||
endif # win32-dm
|
||||
|
||||
|
||||
###
|
||||
### win32 - Intel C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-ic)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = icl -nologo
|
||||
CFLAGS = -W3 -WX
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,2)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win32-ic
|
||||
|
||||
|
||||
###
|
||||
### win32 - Metrowerks C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-mwerks)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = mwcc -gccinc
|
||||
CFLAGS = -w on
|
||||
CXXFLAGS = $(CFLAGS)
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LDFLAGS = -lwinmm.lib -map $T.map
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -opt full
|
||||
else
|
||||
CFLAGS +=
|
||||
endif
|
||||
endif # win32-mwerks
|
||||
|
||||
|
||||
###
|
||||
### win32 - Symantec C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-sc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = sc -mn
|
||||
CFLAGS = -w- -wx
|
||||
CXXFLAGS = $(CFLAGS) -EH -ER
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS = -L/map
|
||||
LINK_EXE_OUTPUT = -o$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -o- -g -s
|
||||
else
|
||||
CFLAGS += -o
|
||||
endif
|
||||
endif # win32-sc
|
||||
|
||||
|
||||
###
|
||||
### win32 - Visual C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-vc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = cl -nologo
|
||||
CFLAGS = -W4 -WX
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,1)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
##LINK_EXE_LDFLAGS += /opt:nowin98
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win32-vc
|
||||
|
||||
|
||||
###
|
||||
### win32 - Watcom C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-wc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = wcl386 -zq -bt=nt -mf -5r
|
||||
##CC = wcl386 -zq -bt=dos -l=CauseWay -mf -5r
|
||||
CFLAGS = -zc -w5 -we
|
||||
CXXFLAGS = $(CFLAGS) -xs -xr
|
||||
CFLAGS_OUTPUT = -fo=$@
|
||||
LDFLAGS = -k0x100000 -fm
|
||||
LINK_EXE_OUTPUT = -fe=$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
CC_SRC = $(subst /,\\,$<)
|
||||
CXX_SRC = $(subst /,\\,$<)
|
||||
INCLUDES := $(strip $(subst /,\\,$(INCLUDES)))
|
||||
ifeq (1,2)
|
||||
WCL386 := $(INCLUDES)
|
||||
export WCL386
|
||||
INCLUDES :=
|
||||
endif
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS +=
|
||||
else
|
||||
# note: it seems that the optimizer is generating bad code with `-ox'
|
||||
CFLAGS += -olr
|
||||
endif
|
||||
endif # win32-wc
|
||||
|
||||
|
||||
###
|
||||
### win64 - Intel C++ [Itanium]
|
||||
###
|
||||
|
||||
ifeq ($(target),win64-ic)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = ecl -nologo
|
||||
CFLAGS = -W3
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,2)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win64-ic
|
||||
|
||||
|
||||
###
|
||||
### win64 - Visual C++ [AMD64 or Itanium]
|
||||
###
|
||||
|
||||
ifeq ($(target),win64-vc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = cl -nologo
|
||||
CFLAGS = -W4 -Wall
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,1)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win64-vc
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // malloc debuggers and memory checkers - obsolete, use valgrind
|
||||
# ************************************************************************/
|
||||
|
||||
ifeq (1,2)
|
||||
# compile in extra valgrind support
|
||||
DEFS += -DWITH_VALGRIND
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
LDLIBS += -lefence
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
DEFS += -DWITH_DMALLOC
|
||||
LDLIBS += -ldmalloc
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
DEFS += -DWITH_GC -DLINUX_THREADS -D_REENTRANT
|
||||
LDLIBS += -lgc -lpthread
|
||||
# only needed when using -static:
|
||||
##LDFLAGS += -Wl,-defsym,_DYNAMIC=0
|
||||
endif
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // main targets
|
||||
# ************************************************************************/
|
||||
|
||||
-include ./Makefile.local
|
||||
|
||||
all: $(upx_exe)
|
||||
|
||||
$(upx_exe): $(OBJECTS) $(LIBS) $(RESOURCES)
|
||||
$(strip $(CXX_LINK_EXE))
|
||||
$(strip $(STUBEDIT_EXE))
|
||||
$(strip $(STUBIFY_EXE))
|
||||
$(strip $(CHMOD_EXE))
|
||||
|
||||
mostlyclean:
|
||||
-rm -f *.d *.err *.i *.log *.map gdb-trans*
|
||||
|
||||
clean: mostlyclean
|
||||
-rm -f *.a *.lib *.o *.obj *.res *.tds tags TAGS ID
|
||||
-rm -f *.idb *.pdb
|
||||
-rm -f $(upx_exe) upx upx.exe upx.ttp upx_nrv upx_nrv.exe upx_nrv.ttp upx_ucl upx_ucl.exe upx_ucl.ttp
|
||||
-rm -rf .deps _deps
|
||||
|
||||
distclean: clean
|
||||
|
||||
maintainer-clean: distclean
|
||||
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // rules
|
||||
# ************************************************************************/
|
||||
|
||||
%$o : %.c
|
||||
$(strip $(CC_COMPILE))
|
||||
|
||||
%$o : %.cpp
|
||||
$(strip $(CXX_COMPILE))
|
||||
|
||||
%.res : %.rc
|
||||
rc -l 0x409 -fo$@ $<
|
||||
|
||||
|
||||
# vi:nowrap
|
||||
+264
-173
@@ -2,8 +2,8 @@
|
||||
|
||||
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) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -34,132 +34,147 @@
|
||||
// core
|
||||
**************************************************************************/
|
||||
|
||||
inline unsigned get_be16(const void *bb)
|
||||
inline unsigned get_be16(const void *p)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[1] << 0;
|
||||
v |= (unsigned) b[0] << 8;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be16(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[1] = (unsigned char) (v >> 0);
|
||||
b[0] = (unsigned char) (v >> 8);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_be24(const void *bb)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[2] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
v |= (unsigned) b[0] << 16;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be24(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[2] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
b[0] = (unsigned char) (v >> 16);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_be32(const void *bb)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[3] << 0;
|
||||
v |= (unsigned) b[2] << 8;
|
||||
v |= (unsigned) b[1] << 16;
|
||||
v |= (unsigned) b[0] << 24;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be32(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[3] = (unsigned char) (v >> 0);
|
||||
b[2] = (unsigned char) (v >> 8);
|
||||
b[1] = (unsigned char) (v >> 16);
|
||||
b[0] = (unsigned char) (v >> 24);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_le16(const void *bb)
|
||||
{
|
||||
#if defined(ACC_GET_LE16)
|
||||
return ACC_GET_LE16(bb);
|
||||
#if defined(ACC_UA_GET_BE16)
|
||||
return ACC_UA_GET_BE16(p);
|
||||
#else
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
return v;
|
||||
return acc_ua_get_be16(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le16(void *bb, unsigned v)
|
||||
inline void set_be16(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_SET_LE16)
|
||||
ACC_SET_LE16(bb, v);
|
||||
#if defined(ACC_UA_SET_BE16)
|
||||
ACC_UA_SET_BE16(p, v);
|
||||
#else
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
acc_ua_set_be16(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_le24(const void *bb)
|
||||
inline unsigned get_be24(const void *p)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
v |= (unsigned) b[2] << 16;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_le24(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
b[2] = (unsigned char) (v >> 16);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_le32(const void *bb)
|
||||
{
|
||||
#if defined(ACC_GET_LE32)
|
||||
return ACC_GET_LE32(bb);
|
||||
#if defined(ACC_UA_GET_BE24)
|
||||
return ACC_UA_GET_BE24(p);
|
||||
#else
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
v |= (unsigned) b[2] << 16;
|
||||
v |= (unsigned) b[3] << 24;
|
||||
return v;
|
||||
return acc_ua_get_be24(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le32(void *bb, unsigned v)
|
||||
inline void set_be24(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_SET_LE32)
|
||||
ACC_SET_LE32(bb, v);
|
||||
#if defined(ACC_UA_SET_BE24)
|
||||
ACC_UA_SET_BE24(p, v);
|
||||
#else
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
b[2] = (unsigned char) (v >> 16);
|
||||
b[3] = (unsigned char) (v >> 24);
|
||||
acc_ua_set_be24(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_be32(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_BE32)
|
||||
return ACC_UA_GET_BE32(p);
|
||||
#else
|
||||
return acc_ua_get_be32(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_be32(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_BE32)
|
||||
ACC_UA_SET_BE32(p, v);
|
||||
#else
|
||||
acc_ua_set_be32(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_be64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_BE64)
|
||||
return ACC_UA_GET_BE64(p);
|
||||
#else
|
||||
return acc_ua_get_be64(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_be64(void *p, acc_uint64l_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_BE64)
|
||||
ACC_UA_SET_BE64(p, v);
|
||||
#else
|
||||
acc_ua_set_be64(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_le16(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE16)
|
||||
return ACC_UA_GET_LE16(p);
|
||||
#else
|
||||
return acc_ua_get_le16(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le16(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE16)
|
||||
ACC_UA_SET_LE16(p, v);
|
||||
#else
|
||||
acc_ua_set_le16(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_le24(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE24)
|
||||
return ACC_UA_GET_LE24(p);
|
||||
#else
|
||||
return acc_ua_get_le24(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le24(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE24)
|
||||
ACC_UA_SET_LE24(p, v);
|
||||
#else
|
||||
acc_ua_set_le24(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_le32(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE32)
|
||||
return ACC_UA_GET_LE32(p);
|
||||
#else
|
||||
return acc_ua_get_le32(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le32(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE32)
|
||||
ACC_UA_SET_LE32(p, v);
|
||||
#else
|
||||
acc_ua_set_le32(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_le64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE64)
|
||||
return ACC_UA_GET_LE64(p);
|
||||
#else
|
||||
return acc_ua_get_le64(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le64(void *p, acc_uint64l_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE64)
|
||||
ACC_UA_SET_LE64(p, v);
|
||||
#else
|
||||
acc_ua_set_le64(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -170,47 +185,66 @@ inline void set_le32(void *bb, unsigned v)
|
||||
|
||||
inline int sign_extend(int v, int bits)
|
||||
{
|
||||
const int sign_bit = 1 << (bits - 1);
|
||||
v |= -(v & sign_bit);
|
||||
const unsigned sign_bit = 1u << (bits - 1);
|
||||
v |= 0u - (v & sign_bit);
|
||||
return v;
|
||||
}
|
||||
|
||||
inline int get_be16_signed(const void *bb)
|
||||
inline acc_int64l_t sign_extend(acc_int64l_t v, int bits)
|
||||
{
|
||||
int v = get_be16(bb);
|
||||
const acc_uint64l_t sign_bit = ACC_UINT64_C(1) << (bits - 1);
|
||||
v |= ACC_UINT64_C(0) - (v & sign_bit);
|
||||
return v;
|
||||
}
|
||||
|
||||
inline int get_be16_signed(const void *p)
|
||||
{
|
||||
int v = get_be16(p);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_be24_signed(const void *bb)
|
||||
inline int get_be24_signed(const void *p)
|
||||
{
|
||||
int v = get_be24(bb);
|
||||
int v = get_be24(p);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_be32_signed(const void *bb)
|
||||
inline int get_be32_signed(const void *p)
|
||||
{
|
||||
int v = get_be32(bb);
|
||||
int v = get_be32(p);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline int get_le16_signed(const void *bb)
|
||||
inline acc_int64l_t get_be64_signed(const void *p)
|
||||
{
|
||||
int v = get_le16(bb);
|
||||
acc_int64l_t v = get_be64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
inline int get_le16_signed(const void *p)
|
||||
{
|
||||
int v = get_le16(p);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_le24_signed(const void *bb)
|
||||
inline int get_le24_signed(const void *p)
|
||||
{
|
||||
int v = get_le24(bb);
|
||||
int v = get_le24(p);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_le32_signed(const void *bb)
|
||||
inline int get_le32_signed(const void *p)
|
||||
{
|
||||
int v = get_le32(bb);
|
||||
int v = get_le32(p);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline int get_le64_signed(const void *p)
|
||||
{
|
||||
acc_int64l_t v = get_le64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// classes for portable unaligned access
|
||||
@@ -227,8 +261,10 @@ struct BE16
|
||||
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
|
||||
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
|
||||
BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; }
|
||||
BE16& operator *= (unsigned v) { set_be16(d, get_be16(d) * v); return *this; }
|
||||
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
|
||||
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
|
||||
BE16& operator ^= (unsigned v) { set_be16(d, get_be16(d) ^ v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be16(d); }
|
||||
}
|
||||
@@ -242,14 +278,33 @@ struct BE32
|
||||
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
|
||||
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
|
||||
BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; }
|
||||
BE32& operator *= (unsigned v) { set_be32(d, get_be32(d) * v); return *this; }
|
||||
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
|
||||
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
|
||||
BE32& operator ^= (unsigned v) { set_be32(d, get_be32(d) ^ v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct BE64
|
||||
{
|
||||
unsigned char d[8];
|
||||
|
||||
BE64& operator = (acc_uint64l_t v) { set_be64(d, v); return *this; }
|
||||
BE64& operator += (acc_uint64l_t v) { set_be64(d, get_be64(d) + v); return *this; }
|
||||
BE64& operator -= (acc_uint64l_t v) { set_be64(d, get_be64(d) - v); return *this; }
|
||||
BE64& operator *= (acc_uint64l_t v) { set_be64(d, get_be64(d) * v); return *this; }
|
||||
BE64& operator &= (acc_uint64l_t v) { set_be64(d, get_be64(d) & v); return *this; }
|
||||
BE64& operator |= (acc_uint64l_t v) { set_be64(d, get_be64(d) | v); return *this; }
|
||||
BE64& operator ^= (acc_uint64l_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_be64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct LE16
|
||||
{
|
||||
unsigned char d[2];
|
||||
@@ -257,8 +312,10 @@ struct LE16
|
||||
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
|
||||
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
|
||||
LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; }
|
||||
LE16& operator *= (unsigned v) { set_le16(d, get_le16(d) * v); return *this; }
|
||||
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
|
||||
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
|
||||
LE16& operator ^= (unsigned v) { set_le16(d, get_le16(d) ^ v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le16(d); }
|
||||
}
|
||||
@@ -272,99 +329,133 @@ struct LE32
|
||||
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
|
||||
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
|
||||
LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; }
|
||||
LE32& operator *= (unsigned v) { set_le32(d, get_le32(d) * v); return *this; }
|
||||
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
|
||||
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
|
||||
LE32& operator ^= (unsigned v) { set_le32(d, get_le32(d) ^ v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct LE64
|
||||
{
|
||||
unsigned char d[8];
|
||||
|
||||
LE64& operator = (acc_uint64l_t v) { set_le64(d, v); return *this; }
|
||||
LE64& operator += (acc_uint64l_t v) { set_le64(d, get_le64(d) + v); return *this; }
|
||||
LE64& operator -= (acc_uint64l_t v) { set_le64(d, get_le64(d) - v); return *this; }
|
||||
LE64& operator *= (acc_uint64l_t v) { set_le64(d, get_le64(d) * v); return *this; }
|
||||
LE64& operator &= (acc_uint64l_t v) { set_le64(d, get_le64(d) & v); return *this; }
|
||||
LE64& operator |= (acc_uint64l_t v) { set_le64(d, get_le64(d) | v); return *this; }
|
||||
LE64& operator ^= (acc_uint64l_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_le64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// global operators
|
||||
**************************************************************************/
|
||||
|
||||
inline bool operator < (const BE16& v1, const BE16& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const BE32& v1, const BE32& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const LE16& v1, const LE16& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const LE32& v1, const LE32& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const BE16& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const BE32& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const BE32& v) { return ptr - (unsigned) v; }
|
||||
|
||||
// these are not implemented on purpose and will cause link-time errors
|
||||
template <class T> T* operator + (T* ptr, const BE64& v);
|
||||
template <class T> T* operator + (const BE64& v, T* ptr);
|
||||
template <class T> T* operator - (T* ptr, const BE64& v);
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const LE16& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const LE32& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }
|
||||
|
||||
// these are not implemented on purpose and will cause link-time errors
|
||||
template <class T> T* operator + (T* ptr, const LE64& v);
|
||||
template <class T> T* operator + (const LE64& v, T* ptr);
|
||||
template <class T> T* operator - (T* ptr, const LE64& v);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
// for use with qsort()
|
||||
int __acc_cdecl_qsort be16_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be24_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be32_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le16_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le24_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le32_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be16_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be24_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be32_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le16_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le24_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le32_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be16_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be24_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be32_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be64_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le16_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le24_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le32_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le64_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be16_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort be24_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort be32_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort be64_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le16_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le24_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le32_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
|
||||
// just for testing...
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_GNUC >= 0x030200)
|
||||
typedef unsigned short LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
#if !defined(ACC_CFG_NO_UNALIGNED)
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200)
|
||||
typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
# ifndef LE16
|
||||
# define LE32 LE32_unaligned
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_IA32) && (ACC_CC_INTELC)
|
||||
typedef __declspec(align(1)) unsigned short LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
#if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
# ifndef LE16
|
||||
# define LE32 LE32_unaligned
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
|
||||
typedef __declspec(align(1)) unsigned short LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
# ifndef LE16
|
||||
# define LE32 LE32_unaligned
|
||||
# endif
|
||||
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
+44
-8
@@ -26,6 +26,20 @@
|
||||
*/
|
||||
|
||||
|
||||
#if 1 && defined(UCL_USE_ASM)
|
||||
# include <ucl/ucl_asm.h>
|
||||
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
|
||||
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
|
||||
# define ucl_nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
|
||||
# define ucl_nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
|
||||
# define ucl_nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
|
||||
# define ucl_nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
|
||||
# define ucl_nrv2e_decompress_safe_8 ucl_nrv2e_decompress_asm_safe_8
|
||||
# define ucl_nrv2e_decompress_safe_le16 ucl_nrv2e_decompress_asm_safe_le16
|
||||
# define ucl_nrv2e_decompress_safe_le32 ucl_nrv2e_decompress_asm_safe_le32
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
@@ -89,15 +103,10 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
// prepare bit-buffer settings
|
||||
conf.bb_endian = 0;
|
||||
conf.bb_size = 0;
|
||||
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16)
|
||||
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
|
||||
{
|
||||
int n = (method - M_NRV2B_LE32) % 3;
|
||||
if (n == 0)
|
||||
conf.bb_size = 32;
|
||||
else if (n == 1)
|
||||
conf.bb_size = 8;
|
||||
else
|
||||
conf.bb_size = 16;
|
||||
static const unsigned char sizes[3]={32,8,16};
|
||||
conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
||||
}
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
@@ -119,6 +128,11 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
#endif
|
||||
#if 0 /*{*/
|
||||
else if M_IS_CL1B(method)
|
||||
r = cl1b_compress(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
#endif /*}*/
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
|
||||
@@ -171,6 +185,17 @@ int upx_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
#endif
|
||||
#if 0 /*{*/
|
||||
case M_CL1B_8:
|
||||
r = cl1b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE16:
|
||||
r = cl1b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE32:
|
||||
r = cl1b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
#endif /*}*/
|
||||
default:
|
||||
throwInternalError("unknown decompression method");
|
||||
break;
|
||||
@@ -225,6 +250,17 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
|
||||
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
#endif
|
||||
#if 0 /*{*/
|
||||
case M_CL1B_8:
|
||||
r = cl1b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE16:
|
||||
r = cl1b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE32:
|
||||
r = cl1b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
#endif /*}*/
|
||||
default:
|
||||
throwInternalError("unknown decompression method");
|
||||
break;
|
||||
|
||||
+2
-4
@@ -32,14 +32,12 @@
|
||||
#if defined(WITH_NRV)
|
||||
# include "compress_nrv.ch"
|
||||
#elif defined(WITH_UCL)
|
||||
# define ALG_NRV2E
|
||||
# define upx_adler32 upx_adler32
|
||||
//# define upx_crc32 upx_crc32
|
||||
# define upx_compress upx_compress
|
||||
# define upx_decompress upx_decompress
|
||||
# if (UPX_VERSION_HEX >= 0x019000)
|
||||
# define ALG_NRV2E
|
||||
# define upx_test_overlap upx_test_overlap
|
||||
# endif
|
||||
# define upx_test_overlap upx_test_overlap
|
||||
# include "compress.ch"
|
||||
#else
|
||||
# error
|
||||
|
||||
+25
-13
@@ -146,7 +146,7 @@
|
||||
|
||||
|
||||
#if !defined(WITH_UCL)
|
||||
# error "please set UCLDIR in the Makefile"
|
||||
# define WITH_UCL 1
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
# include <ucl/uclconf.h>
|
||||
@@ -295,10 +295,10 @@
|
||||
|
||||
#undef __attribute_packed
|
||||
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||
# if (1 && (ACC_ARCH_IA32))
|
||||
# if (1 && (ACC_ARCH_I386))
|
||||
# define __attribute_packed
|
||||
# else
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# endif
|
||||
#else
|
||||
# define __attribute_packed
|
||||
@@ -333,10 +333,10 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(acc_alignof)
|
||||
#if defined(__acc_alignof)
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \
|
||||
COMPILE_TIME_ASSERT(acc_alignof(a) == sizeof(b))
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(a) == sizeof(b))
|
||||
#else
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
|
||||
@@ -423,10 +423,14 @@ inline void operator delete[](void *p)
|
||||
#define M_NRV2E_LE32 8
|
||||
#define M_NRV2E_8 9
|
||||
#define M_NRV2E_LE16 10
|
||||
#define M_CL1B_LE32 11
|
||||
#define M_CL1B_8 12
|
||||
#define M_CL1B_LE16 13
|
||||
|
||||
#define M_IS_NRV2B(x) ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)
|
||||
#define M_IS_NRV2D(x) ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)
|
||||
#define M_IS_NRV2E(x) ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)
|
||||
#define M_IS_CL1B(x) ((x) >= M_CL1B_LE32 && (x) <= M_CL1B_LE16)
|
||||
|
||||
|
||||
// Executable formats. Note: big endian types are >= 128.
|
||||
@@ -449,8 +453,16 @@ inline void operator delete[](void *p)
|
||||
#define UPX_F_ELKS_8086 17
|
||||
#define UPX_F_PS1_EXE 18
|
||||
#define UPX_F_VMLINUX_i386 19
|
||||
#define UPX_F_LINUX_ELFI_i386 20
|
||||
#define UPX_F_WINCE_ARM_PE 21
|
||||
#define UPX_F_LINUX_ELF64_AMD 22
|
||||
|
||||
#define UPX_F_PLAIN_TEXT 127
|
||||
|
||||
#define UPX_F_ATARI_TOS 129
|
||||
#define UPX_F_SOLARIS_SPARC 130
|
||||
#define UPX_F_MACH_PPC32 131
|
||||
#define UPX_F_LINUX_ELFPPC32 132
|
||||
|
||||
|
||||
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
|
||||
@@ -477,7 +489,7 @@ inline void operator delete[](void *p)
|
||||
extern const char *progname;
|
||||
void init_options(struct options_t *o);
|
||||
bool set_ec(int ec);
|
||||
#if defined(__GNUC__)
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void e_exit(int ec) __attribute__((__noreturn__));
|
||||
#else
|
||||
void e_exit(int ec);
|
||||
@@ -489,23 +501,23 @@ void printSetNl(int need_nl);
|
||||
void printClearLine(FILE *f = NULL);
|
||||
void printErr(const char *iname, const Throwable *e);
|
||||
void printUnhandledException(const char *iname, const std::exception *e);
|
||||
#if defined(__GNUC__)
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(printf,2,3)));
|
||||
__attribute__((__format__(__printf__,2,3)));
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(printf,2,3)));
|
||||
__attribute__((__format__(__printf__,2,3)));
|
||||
#else
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void __acc_cdecl_va info(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
#else
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...);
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...);
|
||||
|
||||
@@ -40,6 +40,8 @@ void File::chmod(const char *name, int mode)
|
||||
#if defined(HAVE_CHMOD)
|
||||
if (::chmod(name,mode) != 0)
|
||||
throwIOException(name,errno);
|
||||
#else
|
||||
UNUSED(name); UNUSED(mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,6 @@ public:
|
||||
|
||||
off_t getBytesWritten() const { return bytes_written; }
|
||||
|
||||
#if (UPX_VERSION_HEX >= 0x019000)
|
||||
// FIXME - these won't work when using the `--stdout' option
|
||||
virtual void seek(off_t off, int whence)
|
||||
{
|
||||
@@ -144,7 +143,6 @@ public:
|
||||
write(buf, len);
|
||||
bytes_written -= len; // restore
|
||||
}
|
||||
#endif
|
||||
|
||||
// util
|
||||
static void dump(const char *name, const void *buf, int len, int flags=-1);
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/* ppcbxx.h -- PowerPC Branch trick
|
||||
|
||||
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) 2004-2005 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>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// filter / scan
|
||||
**************************************************************************/
|
||||
|
||||
#define W_CTO 4 /* width of cto; must match stub/ppc_bxx.S */
|
||||
|
||||
static int F(Filter *f)
|
||||
{
|
||||
#ifdef U
|
||||
// filter
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned addvalue = f->addvalue;
|
||||
#else
|
||||
// scan
|
||||
const upx_byte *b = f->buf;
|
||||
#endif
|
||||
const unsigned size = umin(f->buf_len, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = size -4;
|
||||
|
||||
unsigned ic;
|
||||
unsigned calls = 0, noncalls = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find 26-2-W_CTO bits of displacements that contain no targets
|
||||
{
|
||||
unsigned char buf[256];
|
||||
unsigned short wbuf[256];
|
||||
const size_t WW = (size_t)0 - (~(size_t)0) << W_CTO; // ???
|
||||
memset(wbuf, 0, sizeof(wbuf));
|
||||
memset(buf , 0, WW);
|
||||
memset(buf + WW, 1, 256 - WW);
|
||||
|
||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
||||
unsigned const off = (int)(get_be32(b+ic)<<6) >>6;
|
||||
if (size <= (off & (~0u<<2))+ic) {
|
||||
buf[(~(~0u<<W_CTO)) & (off>>(26 - W_CTO))] |= 1;
|
||||
++wbuf[0xff&(off>>18)];
|
||||
}
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0) {
|
||||
if (0!=W_CTO) // FIXME: what is this ???
|
||||
return -1;
|
||||
f->cto = 0;
|
||||
}
|
||||
}
|
||||
const unsigned char cto8 = f->cto;
|
||||
#ifdef U
|
||||
const unsigned cto = (unsigned)f->cto << (24+2 - W_CTO);
|
||||
#endif
|
||||
|
||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
||||
unsigned const word = get_be32(b+ic);
|
||||
unsigned const off = (int)(word<<6) >>6;
|
||||
unsigned const jc = (off & (~0u<<2))+ic;
|
||||
// try to detect 'real' calls only
|
||||
if (jc < size) {
|
||||
#ifdef U
|
||||
set_be32(b+ic,(0xfc000003&word) | (jc+addvalue+cto));
|
||||
#endif
|
||||
calls++;
|
||||
lastcall = ic;
|
||||
}
|
||||
else {
|
||||
assert(0==W_CTO // FIXME: what is this ???
|
||||
|| (~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
}
|
||||
}
|
||||
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#if 0
|
||||
printf("\ncalls=%d noncalls=%d text_size=%x calltrickoffset=%x\n",
|
||||
calls,noncalls,size,cto8);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// unfilter
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef U
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size4 = umin(f->buf_len - 4, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned addvalue = f->addvalue;
|
||||
|
||||
unsigned ic;
|
||||
|
||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
||||
unsigned const word = get_be32(b+ic);
|
||||
if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == f->cto) {
|
||||
unsigned const jc = word & (~(~0u<<(26 - W_CTO)) & (~0u<<2));
|
||||
set_be32(b+ic, (0xfc000003&word)|(0x03fffffc&(jc-ic-addvalue)));
|
||||
f->calls++;
|
||||
f->lastcall = ic;
|
||||
}
|
||||
else {
|
||||
f->noncalls++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#undef F
|
||||
#undef U
|
||||
|
||||
#undef W_CTO
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,12 @@
|
||||
#include "conf.h"
|
||||
#include "filter.h"
|
||||
|
||||
static unsigned
|
||||
umin(unsigned const a, unsigned const b)
|
||||
{
|
||||
return (a<=b) ? a : b;
|
||||
}
|
||||
|
||||
|
||||
#define set_dummy(p, v) ((void)0)
|
||||
#define get_8(p) (*(p))
|
||||
@@ -145,6 +151,19 @@
|
||||
#undef COND_CALL
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// PowerPC branch [incl. call] trick
|
||||
**************************************************************************/
|
||||
|
||||
#define COND(b,x) (18==(get_be32(b+x)>>26))
|
||||
#define F f_ppcbxx
|
||||
#define U u_ppcbxx
|
||||
#include "filter/ppcbxx.h"
|
||||
#define F s_ppcbxx
|
||||
#include "filter/ppcbxx.h"
|
||||
#undef COND
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// database for use in class Filter
|
||||
**************************************************************************/
|
||||
@@ -230,6 +249,9 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
||||
{ 0xb1,99, 0, f_sub32_2, u_sub32_2, s_sub32_2 },
|
||||
{ 0xb2,99, 0, f_sub32_3, u_sub32_3, s_sub32_3 },
|
||||
{ 0xb3,99, 0, f_sub32_4, u_sub32_4, s_sub32_4 },
|
||||
|
||||
// PowerPC branch+call trick
|
||||
{ 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx },
|
||||
};
|
||||
|
||||
const int FilterImp::n_filters = TABLESIZE(filters);
|
||||
|
||||
+15
-12
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -47,9 +47,9 @@ void show_head(void)
|
||||
#define V(x) (strcmp(UPX_VERSION_STRING, UPX_VERSION_STRING4) ? UPX_VERSION_STRING : UPX_VERSION_STRING x)
|
||||
fg = con_fg(f,FG_GREEN);
|
||||
con_fprintf(f,
|
||||
" Ultimate Packer for eXecutables\n"
|
||||
" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005\n"
|
||||
"UPX %-12s Markus F.X.J. Oberhumer & Laszlo Molnar %20s\n\n",
|
||||
" Ultimate Packer for eXecutables\n"
|
||||
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006\n"
|
||||
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||
V("d"),
|
||||
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
@@ -229,8 +229,6 @@ void show_help(int x)
|
||||
" --compress-icons=1 compress all but the first icon\n"
|
||||
" --compress-icons=2 compress all but the first icon directory [default]\n"
|
||||
" --compress-resources=0 do not compress any resources at all\n"
|
||||
" --strip-loadconf=0 do not strip SEH load config [default]\n"
|
||||
" --strip-loadconf=1 strip SEH load config [DANGEROUS]\n"
|
||||
" --strip-relocs=0 do not strip relocations\n"
|
||||
" --strip-relocs=1 strip relocations [default]\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
@@ -245,6 +243,11 @@ void show_help(int x)
|
||||
con_fprintf(f,"This version supports:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f," "
|
||||
// TODO:
|
||||
// support for mach/ppc32
|
||||
// support for linux elf/ppc32
|
||||
// support for linux elf/amd64
|
||||
" arm/pe,"
|
||||
" atari/tos,"
|
||||
" bvmlinuz/386,"
|
||||
" djgpp2/coff,"
|
||||
@@ -266,7 +269,7 @@ void show_help(int x)
|
||||
//" win16/ne,"
|
||||
" win32/pe"
|
||||
"\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net\n"
|
||||
//"\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details type `upx -L'.\n"
|
||||
// "\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details type `upx -L'.\n"
|
||||
"");
|
||||
|
||||
|
||||
@@ -348,10 +351,10 @@ void show_version(int x)
|
||||
#if defined(WITH_UCL)
|
||||
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
|
||||
#endif
|
||||
fprintf(f,"Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f,"Copyright (C) 1996-2005 Laszlo Molnar\n");
|
||||
fprintf(f,"Copyright (C) 2000-2005 John F. Reiser\n");
|
||||
fprintf(f,"Copyright (C) 2002-2005 Jens Medoch\n");
|
||||
fprintf(f,"Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f,"Copyright (C) 1996-2006 Laszlo Molnar\n");
|
||||
fprintf(f,"Copyright (C) 2000-2006 John F. Reiser\n");
|
||||
fprintf(f,"Copyright (C) 2002-2006 Jens Medoch\n");
|
||||
fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
|
||||
}
|
||||
|
||||
|
||||
+56
-29
@@ -2,8 +2,8 @@
|
||||
|
||||
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) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,33 +22,47 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "linker.h"
|
||||
|
||||
class LinkerLabel
|
||||
{
|
||||
enum { LINKER_MAX_LABEL_LEN = 32 };
|
||||
char label[LINKER_MAX_LABEL_LEN + 1];
|
||||
|
||||
public:
|
||||
unsigned set(const char *l)
|
||||
{
|
||||
strncpy(label, l, sizeof(label));
|
||||
return strlen(label) + 1;
|
||||
}
|
||||
operator const char *() const { return label; }
|
||||
};
|
||||
|
||||
|
||||
struct Linker::section
|
||||
{
|
||||
int istart;
|
||||
int ostart;
|
||||
int len;
|
||||
char name[8];
|
||||
int istart;
|
||||
int ostart;
|
||||
int len;
|
||||
LinkerLabel name;
|
||||
};
|
||||
|
||||
struct Linker::jump
|
||||
{
|
||||
int pos;
|
||||
int len;
|
||||
char tsect[8];
|
||||
int toffs;
|
||||
int pos;
|
||||
int len;
|
||||
int toffs;
|
||||
LinkerLabel tsect;
|
||||
};
|
||||
|
||||
Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
{
|
||||
iloader = new char[(ilen = plen) + 4096];
|
||||
iloader = new char[(ilen = plen) + 8192];
|
||||
memcpy(iloader,pdata,plen);
|
||||
oloader = new char[plen];
|
||||
olen = 0;
|
||||
@@ -57,7 +71,7 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
info = pinfo;
|
||||
njumps = nsections = frozen = 0;
|
||||
jumps = new jump[200];
|
||||
#define NSECTIONS 350
|
||||
#define NSECTIONS 550
|
||||
sections = new section[NSECTIONS];
|
||||
|
||||
char *p = iloader + info;
|
||||
@@ -65,10 +79,10 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
{
|
||||
if (get32(p))
|
||||
{
|
||||
memcpy(sections[nsections].name,p,8);
|
||||
sections[nsections].istart = get32(p+8);
|
||||
p += sections[nsections].name.set(p);
|
||||
sections[nsections].istart = get32(p);
|
||||
sections[nsections++].ostart = -1;
|
||||
p += 12;
|
||||
p += 4;
|
||||
assert(nsections < NSECTIONS);
|
||||
}
|
||||
else
|
||||
@@ -79,9 +93,9 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
|
||||
jumps[njumps].pos = l+1;
|
||||
jumps[njumps].len = get32(p+4)-jumps[njumps].pos;
|
||||
memcpy(jumps[njumps].tsect,p+8,8);
|
||||
jumps[njumps++].toffs = get32(p+16);
|
||||
p += 20;
|
||||
p += 8 + jumps[njumps].tsect.set(p + 8);
|
||||
jumps[njumps++].toffs = get32(p);
|
||||
p += 4;
|
||||
assert(njumps < 200);
|
||||
}
|
||||
}
|
||||
@@ -112,11 +126,21 @@ static int hex(char c)
|
||||
return (c & 0xf) + (c > '9' ? 9 : 0);
|
||||
}
|
||||
|
||||
int Linker::addSection(const char *sect)
|
||||
int Linker::addSection(const char *psect)
|
||||
{
|
||||
int ic;
|
||||
while (*sect)
|
||||
if (psect[0] == 0)
|
||||
return olen;
|
||||
char *begin = strdup(psect);
|
||||
char *end = begin + strlen(begin);
|
||||
for (char *sect = begin; sect < end; )
|
||||
{
|
||||
for (char *tokend = sect; *tokend; tokend++)
|
||||
if (*tokend == ' ' || *tokend == ',')
|
||||
{
|
||||
*tokend = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (*sect == '+') // alignment
|
||||
{
|
||||
if (sect[1] == '0')
|
||||
@@ -131,19 +155,22 @@ int Linker::addSection(const char *sect)
|
||||
}
|
||||
else
|
||||
{
|
||||
int ic;
|
||||
for (ic = 0; ic < nsections; ic++)
|
||||
if (memcmp(sect,sections[ic].name,8) == 0)
|
||||
if (strcmp(sect, sections[ic].name) == 0)
|
||||
{
|
||||
memcpy(oloader+olen,iloader+sections[ic].istart,sections[ic].len);
|
||||
sections[ic].ostart = olen;
|
||||
olen += sections[ic].len;
|
||||
break;
|
||||
}
|
||||
//printf("%8.8s",sect);
|
||||
assert(ic!=nsections);
|
||||
if (ic == nsections)
|
||||
printf("%s", sect);
|
||||
assert(ic != nsections);
|
||||
}
|
||||
sect += 8;
|
||||
sect += strlen(sect) + 1;
|
||||
}
|
||||
free(begin);
|
||||
return olen;
|
||||
}
|
||||
|
||||
@@ -151,7 +178,7 @@ int Linker::addSection(const char *sect)
|
||||
void Linker::addSection(const char *sname, const void *sdata, unsigned len)
|
||||
{
|
||||
// add a new section - can be used for adding stuff like ident or header
|
||||
memcpy(sections[nsections].name,sname,8);
|
||||
sections[nsections].name.set(sname);
|
||||
sections[nsections].istart = ilen;
|
||||
sections[nsections].len = len;
|
||||
sections[nsections++].ostart = olen;
|
||||
@@ -177,7 +204,7 @@ const char *Linker::getLoader(int *llen)
|
||||
continue;
|
||||
|
||||
for (kc = 0; kc < nsections-1; kc++)
|
||||
if (memcmp(jumps[ic].tsect,sections[kc].name,8) == 0)
|
||||
if (strcmp(jumps[ic].tsect,sections[kc].name) == 0)
|
||||
break;
|
||||
assert(kc!=nsections-1);
|
||||
|
||||
@@ -203,7 +230,7 @@ int Linker::getSection(const char *name, int *slen) const
|
||||
if (!frozen)
|
||||
return -1;
|
||||
for (int ic = 0; ic < nsections; ic++)
|
||||
if (memcmp(name,sections[ic].name,8) == 0)
|
||||
if (strcmp(name, sections[ic].name) == 0)
|
||||
{
|
||||
if (slen)
|
||||
*slen = sections[ic].len;
|
||||
|
||||
+108
-40
@@ -2,8 +2,8 @@
|
||||
|
||||
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) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -71,12 +71,11 @@ void init_options(struct options_t *o)
|
||||
for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++)
|
||||
o->win32_pe.compress_rt[i] = -1;
|
||||
o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
|
||||
o->win32_pe.strip_loadconf = -1;
|
||||
o->win32_pe.strip_relocs = -1;
|
||||
}
|
||||
|
||||
static struct options_t global_options;
|
||||
struct options_t * volatile opt = &global_options;
|
||||
struct options_t *opt = &global_options;
|
||||
|
||||
static int done_output_name = 0;
|
||||
static int done_script_name = 0;
|
||||
@@ -444,7 +443,7 @@ static int do_option(int optc, const char *arg)
|
||||
set_cmd(CMD_DECOMPRESS);
|
||||
break;
|
||||
case 'D':
|
||||
opt->debug++;
|
||||
opt->debug.debug_level++;
|
||||
break;
|
||||
case 'f':
|
||||
opt->force++;
|
||||
@@ -538,6 +537,23 @@ static int do_option(int optc, const char *arg)
|
||||
e_method(opt->method, 10);
|
||||
break;
|
||||
|
||||
// debug
|
||||
case 542:
|
||||
if (!mfx_optarg || strlen(mfx_optarg) != 4)
|
||||
e_optarg(arg);
|
||||
memcpy(opt->debug.fake_stub_version, mfx_optarg, 4);
|
||||
break;
|
||||
case 543:
|
||||
if (!mfx_optarg || strlen(mfx_optarg) != 4)
|
||||
e_optarg(arg);
|
||||
memcpy(opt->debug.fake_stub_year, mfx_optarg, 4);
|
||||
break;
|
||||
case 544:
|
||||
if (!mfx_optarg || !mfx_optarg[0])
|
||||
e_optarg(arg);
|
||||
opt->debug.dump_stub_loader = mfx_optarg;
|
||||
break;
|
||||
|
||||
// misc
|
||||
case 512:
|
||||
opt->console = CON_FILE;
|
||||
@@ -567,6 +583,7 @@ static int do_option(int optc, const char *arg)
|
||||
case 522: // --no-filter
|
||||
opt->filter = 0;
|
||||
opt->all_filters = false;
|
||||
opt->no_filter = true;
|
||||
break;
|
||||
case 523: // --all-filters
|
||||
opt->all_filters = true;
|
||||
@@ -677,10 +694,7 @@ static int do_option(int optc, const char *arg)
|
||||
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
|
||||
break;
|
||||
case 633:
|
||||
opt->win32_pe.strip_loadconf = 1;
|
||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||
opt->win32_pe.strip_loadconf = 0;
|
||||
//printf("strip_loadconf: %d\n", opt->win32_pe.strip_loadconf);
|
||||
// opt->win32_pe.strip_loadconf - OBSOLETE - IGNORED
|
||||
break;
|
||||
case 634:
|
||||
opt->win32_pe.strip_relocs = 1;
|
||||
@@ -703,7 +717,13 @@ static int do_option(int optc, const char *arg)
|
||||
set_script_name(mfx_optarg,1);
|
||||
break;
|
||||
case 663:
|
||||
opt->o_unix.ptinterp = true;
|
||||
opt->o_unix.is_ptinterp = true;
|
||||
break;
|
||||
case 664:
|
||||
opt->o_unix.use_ptinterp = true;
|
||||
break;
|
||||
case 665:
|
||||
opt->o_unix.make_ptinterp = true;
|
||||
break;
|
||||
case 670:
|
||||
opt->ps1_exe.boot_only = true;
|
||||
@@ -750,7 +770,6 @@ static const struct mfx_option longopts[] =
|
||||
{"version", 0, 0, 'V'+256}, // display version number
|
||||
|
||||
// options
|
||||
{"debug", 0x10, 0, 'D'},
|
||||
{"force", 0, 0, 'f'}, // force overwrite of output files
|
||||
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files
|
||||
{"info", 0, 0, 'i'}, // info mode
|
||||
@@ -766,6 +785,12 @@ static const struct mfx_option longopts[] =
|
||||
#endif
|
||||
{"verbose", 0, 0, 'v'}, // verbose mode
|
||||
|
||||
// debug options
|
||||
{"debug", 0x10, 0, 'D'},
|
||||
{"dump-stub-loader" ,0x31, 0, 544}, // for internal debugging
|
||||
{"fake-stub-version",0x31, 0, 542}, // for internal debugging
|
||||
{"fake-stub-year" ,0x31, 0, 543}, // for internal debugging
|
||||
|
||||
// backup options
|
||||
{"backup", 0, 0, 'k'},
|
||||
{"keep", 0, 0, 'k'},
|
||||
@@ -823,14 +848,16 @@ static const struct mfx_option longopts[] =
|
||||
#if 0
|
||||
{"script", 0x31, 0, 662}, // --script=
|
||||
#endif
|
||||
{"ptinterp", 0, 0, 663}, // linux/elf386 PT_INTERP program
|
||||
{"is_ptinterp", 0, 0, 663}, // linux/elf386 PT_INTERP program
|
||||
{"use_ptinterp", 0, 0, 664}, // linux/elf386 PT_INTERP program
|
||||
{"make_ptinterp", 0, 0, 665}, // linux/elf386 PT_INTERP program
|
||||
// watcom/le
|
||||
{"le", 0, 0, 620}, // produce LE output
|
||||
// win32/pe
|
||||
{"compress-exports", 2, 0, 630},
|
||||
{"compress-icons", 2, 0, 631},
|
||||
{"compress-resources", 2, 0, 632},
|
||||
{"strip-loadconf", 0x12, 0, 633},
|
||||
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
|
||||
{"strip-relocs", 0x12, 0, 634},
|
||||
// ps1/exe
|
||||
{"boot-only", 0x10, 0, 670},
|
||||
@@ -912,7 +939,7 @@ static const struct mfx_option longopts[] =
|
||||
{"compress-exports", 2, 0, 630},
|
||||
{"compress-icons", 2, 0, 631},
|
||||
{"compress-resources", 2, 0, 632},
|
||||
{"strip-loadconf", 0x12, 0, 633},
|
||||
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
|
||||
{"strip-relocs", 0x12, 0, 634},
|
||||
|
||||
{ NULL, 0, NULL, 0 }
|
||||
@@ -1028,6 +1055,25 @@ static void first_options(int argc, char **argv)
|
||||
// assert a sane architecture and compiler
|
||||
**************************************************************************/
|
||||
|
||||
template <class T> struct TestBELE {
|
||||
static int test(void)
|
||||
{
|
||||
T allbits; allbits = 0; allbits -= 1;
|
||||
T v1; v1 = 1; v1 *= 2; v1 -= 1;
|
||||
T v2; v2 = 1;
|
||||
assert( (v1 == v2)); assert(!(v1 != v2));
|
||||
assert( (v1 <= v2)); assert( (v1 >= v2));
|
||||
assert(!(v1 < v2)); assert(!(v1 > v2));
|
||||
v2 ^= allbits;
|
||||
assert(!(v1 == v2)); assert( (v1 != v2));
|
||||
assert( (v1 <= v2)); assert(!(v1 >= v2));
|
||||
assert( (v1 < v2)); assert(!(v1 > v2));
|
||||
v2 += 2;
|
||||
assert(v1 == 1); assert(v2 == 0);
|
||||
return (v1 ^ v2) == 1;
|
||||
}};
|
||||
|
||||
|
||||
#define ACC_WANT_ACC_CHK_CH 1
|
||||
#undef ACCCHK_ASSERT
|
||||
#include "miniacc.h"
|
||||
@@ -1051,40 +1097,67 @@ void upx_sanity_check(void)
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(BE64) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE64) == 8)
|
||||
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE64, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE64, char)
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
|
||||
assert(strlen(UPX_VERSION_STRING4) == 4);
|
||||
assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0);
|
||||
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_YEAR) == 4 + 1)
|
||||
assert(strlen(UPX_VERSION_YEAR) == 4);
|
||||
assert(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0);
|
||||
assert(memcmp(UPX_VERSION_DATE + strlen(UPX_VERSION_DATE) - 4, UPX_VERSION_YEAR, 4) == 0);
|
||||
|
||||
#if 1
|
||||
const unsigned char dd[4] = { 0xff, 0xfe, 0xfd, 0xfc };
|
||||
assert(upx_adler32(dd, 4) == 0x09f003f7);
|
||||
assert(upx_adler32(dd, 4, 0) == 0x09ec03f6);
|
||||
assert(upx_adler32(dd, 4, 1) == 0x09f003f7);
|
||||
|
||||
assert(get_be16(dd) == 0xfffe);
|
||||
assert(get_be16_signed(dd) == -2);
|
||||
assert(get_be24(dd) == 0xfffefd);
|
||||
assert(get_be24_signed(dd) == -259);
|
||||
assert(get_be32(dd) == 0xfffefdfc);
|
||||
assert(get_be32_signed(dd) == -66052);
|
||||
assert(get_le16(dd) == 0xfeff);
|
||||
assert(get_le16_signed(dd) == -257);
|
||||
assert(get_le24(dd) == 0xfdfeff);
|
||||
assert(get_le24_signed(dd) == -131329);
|
||||
assert(get_le32(dd) == 0xfcfdfeff);
|
||||
assert(get_le32_signed(dd) == -50462977);
|
||||
assert(find_be16(dd, sizeof(dd), 0xfffe) == 0);
|
||||
assert(find_le16(dd, sizeof(dd), 0xfeff) == 0);
|
||||
assert(find_be32(dd, sizeof(dd), 0xfffefdfc) == 0);
|
||||
assert(find_le32(dd, sizeof(dd), 0xfcfdfeff) == 0);
|
||||
# if 1
|
||||
assert(TestBELE<LE16>::test());
|
||||
assert(TestBELE<LE32>::test());
|
||||
assert(TestBELE<LE64>::test());
|
||||
assert(TestBELE<BE16>::test());
|
||||
assert(TestBELE<BE32>::test());
|
||||
assert(TestBELE<BE64>::test());
|
||||
# endif
|
||||
{
|
||||
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
0, 0, 0, 0, 0 };
|
||||
const unsigned char *d;
|
||||
d = dd + 7;
|
||||
assert(upx_adler32(d, 4) == 0x09f003f7);
|
||||
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
|
||||
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
|
||||
assert(get_be16(d) == 0xfffe);
|
||||
assert(get_be16_signed(d) == -2);
|
||||
assert(get_be24(d) == 0xfffefd);
|
||||
assert(get_be24_signed(d) == -259);
|
||||
assert(get_be32(d) == 0xfffefdfc);
|
||||
assert(get_be32_signed(d) == -66052);
|
||||
assert(get_le16(d) == 0xfeff);
|
||||
assert(get_le16_signed(d) == -257);
|
||||
assert(get_le24(d) == 0xfdfeff);
|
||||
assert(get_le24_signed(d) == -131329);
|
||||
assert(get_le32(d) == 0xfcfdfeff);
|
||||
assert(get_le32_signed(d) == -50462977);
|
||||
assert(find_be16(d, 2, 0xfffe) == 0);
|
||||
assert(find_le16(d, 2, 0xfeff) == 0);
|
||||
assert(find_be32(d, 4, 0xfffefdfc) == 0);
|
||||
assert(find_le32(d, 4, 0xfcfdfeff) == 0);
|
||||
d += 12;
|
||||
assert(get_be16_signed(d) == 32638);
|
||||
assert(get_be24_signed(d) == 8355453);
|
||||
assert(get_be32_signed(d) == 2138996092);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1104,11 +1177,6 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
#if 0 && defined(__DJGPP__)
|
||||
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
|
||||
putenv("LFN=y");
|
||||
#endif
|
||||
#if defined(__MINT__)
|
||||
__binmode(1);
|
||||
__set_binmode(stdout, 0);
|
||||
__set_binmode(stderr, 0);
|
||||
#endif
|
||||
acc_wildargv(&argc, &argv);
|
||||
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra
|
||||
unsigned size = uncompressed_size + extra;
|
||||
// size += 512; // 512 safety bytes
|
||||
// INFO: 3 bytes are the allowed overrun for the i386 asm_fast decompressors
|
||||
#if (ACC_ARCH_IA32)
|
||||
#if (ACC_ARCH_I386)
|
||||
size += 3;
|
||||
#endif
|
||||
alloc(size);
|
||||
|
||||
+2547
-1041
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -66,9 +66,9 @@ void printClearLine(FILE *f)
|
||||
static void pr_print(bool c, const char *msg)
|
||||
{
|
||||
if (c && !opt->to_stdout)
|
||||
con_fprintf(stderr,msg);
|
||||
con_fprintf(stderr, "%s", msg);
|
||||
else
|
||||
fprintf(stderr,msg);
|
||||
fprintf(stderr, "%s", msg);
|
||||
}
|
||||
|
||||
static void pr_error(const char *iname, const char *msg, bool is_warning)
|
||||
|
||||
+13
-4
@@ -51,11 +51,11 @@ struct options_t {
|
||||
int filter; // preferred filter from Packer::getFilters()
|
||||
bool all_methods; // try all available compression methods ?
|
||||
bool all_filters; // try all available filters ?
|
||||
bool no_filter; // force no filter
|
||||
|
||||
// other options
|
||||
int backup;
|
||||
int console;
|
||||
int debug;
|
||||
int force;
|
||||
int info_mode;
|
||||
bool ignorewarn;
|
||||
@@ -66,6 +66,14 @@ struct options_t {
|
||||
int verbose;
|
||||
bool to_stdout;
|
||||
|
||||
// debug options
|
||||
struct {
|
||||
int debug_level;
|
||||
const char *dump_stub_loader;
|
||||
char fake_stub_version[4+1]; // for internal debugging
|
||||
char fake_stub_year[4+1]; // for internal debugging
|
||||
} debug;
|
||||
|
||||
// overlay handling
|
||||
enum {
|
||||
SKIP_OVERLAY = 0,
|
||||
@@ -116,7 +124,9 @@ struct options_t {
|
||||
struct {
|
||||
unsigned blocksize;
|
||||
bool force_execve; // force the linux/386 execve format
|
||||
bool ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
bool use_ptinterp; // use PT_INTERP /opt/upx/run
|
||||
bool make_ptinterp; // make PT_INTERP [ignore current file!]
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
} o_unix;
|
||||
@@ -128,12 +138,11 @@ struct options_t {
|
||||
int compress_icons;
|
||||
int compress_resources;
|
||||
signed char compress_rt[25]; // 25 == RT_LAST
|
||||
int strip_loadconf;
|
||||
int strip_relocs;
|
||||
} win32_pe;
|
||||
};
|
||||
|
||||
extern struct options_t * volatile opt;
|
||||
extern struct options_t *opt;
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
+2042
File diff suppressed because it is too large
Load Diff
+251
@@ -0,0 +1,251 @@
|
||||
/* p_armpe.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
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
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_ARMPE_H
|
||||
#define __UPX_P_ARMPE_H
|
||||
|
||||
|
||||
class PackArmPe_Interval;
|
||||
class PackArmPe_Reloc;
|
||||
class PackArmPe_Resource;
|
||||
class PackArmPe_Export;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// w32/pe
|
||||
**************************************************************************/
|
||||
|
||||
class PackArmPe : public Packer
|
||||
{
|
||||
typedef Packer super;
|
||||
|
||||
public:
|
||||
PackArmPe(InputFile *f);
|
||||
~PackArmPe();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_WINCE_ARM_PE; }
|
||||
virtual const char *getName() const { return "arm/pe"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
virtual int canUnpack();
|
||||
|
||||
// unpacker capabilities
|
||||
virtual bool canUnpackVersion(int version) const
|
||||
{ UNUSED(version); return false; }
|
||||
|
||||
protected:
|
||||
virtual int readFileHeader();
|
||||
virtual bool testUnpackVersion(int version) const;
|
||||
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
|
||||
unsigned pe_offset;
|
||||
|
||||
unsigned processImports();
|
||||
void processImports(unsigned);
|
||||
void rebuildImports(upx_byte *&);
|
||||
upx_byte *oimport;
|
||||
unsigned soimport;
|
||||
upx_byte *oimpdlls;
|
||||
unsigned soimpdlls;
|
||||
|
||||
void processRelocs();
|
||||
void processRelocs(PackArmPe_Reloc *);
|
||||
void rebuildRelocs(upx_byte *&);
|
||||
upx_byte *orelocs;
|
||||
unsigned sorelocs;
|
||||
upx_byte *oxrelocs;
|
||||
unsigned soxrelocs;
|
||||
|
||||
void processExports(PackArmPe_Export *);
|
||||
void processExports(PackArmPe_Export *,unsigned);
|
||||
void rebuildExports();
|
||||
upx_byte *oexport;
|
||||
unsigned soexport;
|
||||
|
||||
void processResources(PackArmPe_Resource *);
|
||||
void processResources(PackArmPe_Resource *, unsigned);
|
||||
void rebuildResources(upx_byte *&);
|
||||
upx_byte *oresources;
|
||||
unsigned soresources;
|
||||
|
||||
void processTls(PackArmPe_Interval *);
|
||||
void processTls(PackArmPe_Reloc *,const PackArmPe_Interval *,unsigned);
|
||||
void rebuildTls();
|
||||
upx_byte *otls;
|
||||
unsigned sotls;
|
||||
|
||||
unsigned stripDebug(unsigned);
|
||||
|
||||
unsigned icondir_offset;
|
||||
int icondir_count;
|
||||
|
||||
bool importbyordinal;
|
||||
bool kernel32ordinal;
|
||||
unsigned tlsindex;
|
||||
unsigned rvamin;
|
||||
unsigned cimports; // rva of preprocessed imports
|
||||
unsigned crelocs; // rva of preprocessed fixups
|
||||
int big_relocs;
|
||||
|
||||
struct pe_header_t
|
||||
{
|
||||
// 0x0
|
||||
char _[4]; // pemagic
|
||||
LE16 cpu;
|
||||
LE16 objects;
|
||||
char __[12]; // timestamp + reserved
|
||||
LE16 opthdrsize;
|
||||
LE16 flags;
|
||||
// optional header
|
||||
char ___[4]; // coffmagic + linkerversion
|
||||
LE32 codesize;
|
||||
// 0x20
|
||||
LE32 datasize;
|
||||
LE32 bsssize;
|
||||
LE32 entry;
|
||||
LE32 codebase;
|
||||
// 0x30
|
||||
LE32 database;
|
||||
// nt specific fields
|
||||
LE32 imagebase;
|
||||
LE32 objectalign;
|
||||
LE32 filealign; // should set to 0x200 ?
|
||||
// 0x40
|
||||
char ____[16]; // versions
|
||||
// 0x50
|
||||
LE32 imagesize;
|
||||
LE32 headersize;
|
||||
LE32 chksum; // should set to 0
|
||||
LE16 subsystem;
|
||||
LE16 dllflags;
|
||||
// 0x60
|
||||
char _____[20]; // stack + heap sizes
|
||||
// 0x74
|
||||
LE32 ddirsentries; // usually 16
|
||||
|
||||
struct ddirs_t
|
||||
{
|
||||
LE32 vaddr;
|
||||
LE32 size;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct ddirs_t ddirs[16];
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct pe_section_t
|
||||
{
|
||||
char name[8];
|
||||
LE32 vsize;
|
||||
LE32 vaddr;
|
||||
LE32 size;
|
||||
LE32 rawdataptr;
|
||||
char _[12];
|
||||
LE32 flags;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
pe_header_t ih, oh;
|
||||
pe_section_t *isection;
|
||||
|
||||
static unsigned virta2objnum (unsigned, pe_section_t *, unsigned);
|
||||
unsigned tryremove (unsigned, unsigned);
|
||||
|
||||
enum {
|
||||
PEDIR_EXPORT = 0,
|
||||
PEDIR_IMPORT = 1,
|
||||
PEDIR_RESOURCE = 2,
|
||||
PEDIR_EXCEPTION = 3, // Exception table
|
||||
PEDIR_SEC = 4, // Certificate table (file pointer)
|
||||
PEDIR_RELOC = 5,
|
||||
PEDIR_DEBUG = 6,
|
||||
PEDIR_COPYRIGHT = 7, // Architecture-specific data
|
||||
PEDIR_GLOBALPTR = 8, // Global pointer
|
||||
PEDIR_TLS = 9,
|
||||
PEDIR_LOADCONF = 10, // Load Config Table
|
||||
PEDIR_BOUNDIM = 11,
|
||||
PEDIR_IAT = 12,
|
||||
PEDIR_DELAYIMP = 13, // Delay Import Descriptor
|
||||
PEDIR_COMRT = 14 // Com+ Runtime Header
|
||||
};
|
||||
|
||||
enum {
|
||||
PEFL_CODE = 0x20,
|
||||
PEFL_DATA = 0x40,
|
||||
PEFL_BSS = 0x80,
|
||||
PEFL_INFO = 0x200,
|
||||
PEFL_EXTRELS = 0x01000000, // extended relocations
|
||||
PEFL_DISCARD = 0x02000000,
|
||||
PEFL_NOCACHE = 0x04000000,
|
||||
PEFL_NOPAGE = 0x08000000,
|
||||
PEFL_SHARED = 0x10000000,
|
||||
PEFL_EXEC = 0x20000000,
|
||||
PEFL_READ = 0x40000000,
|
||||
PEFL_WRITE = 0x80000000
|
||||
};
|
||||
|
||||
enum {
|
||||
RELOCS_STRIPPED = 0x0001,
|
||||
EXECUTABLE = 0x0002,
|
||||
LNUM_STRIPPED = 0x0004,
|
||||
LSYMS_STRIPPED = 0x0008,
|
||||
AGGRESSIVE_TRIM = 0x0010,
|
||||
TWO_GIGS_AWARE = 0x0020,
|
||||
FLITTLE_ENDIAN = 0x0080,
|
||||
BITS_32_MACHINE = 0x0100,
|
||||
DEBUG_STRIPPED = 0x0200,
|
||||
REMOVABLE_SWAP = 0x0400,
|
||||
SYSTEM_PROGRAM = 0x1000,
|
||||
DLL_FLAG = 0x2000,
|
||||
FBIG_ENDIAN = 0x8000
|
||||
};
|
||||
|
||||
// predefined resource types
|
||||
enum {
|
||||
RT_CURSOR = 1, RT_BITMAP, RT_ICON, RT_MENU, RT_DIALOG, RT_STRING,
|
||||
RT_FONTDIR, RT_FONT, RT_ACCELERATOR, RT_RCDATA, RT_MESSAGETABLE,
|
||||
RT_GROUP_CURSOR, RT_GROUP_ICON = 14, RT_VERSION = 16, RT_DLGINCLUDE,
|
||||
RT_PLUGPLAY = 19, RT_VXD, RT_ANICURSOR, RT_ANIICON, RT_HTML,
|
||||
RT_MANIFEST, RT_LAST
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
+6
-6
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -142,15 +142,15 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
int PackCom::buildLoader(const Filter *ft)
|
||||
{
|
||||
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
|
||||
addLoader("COMMAIN1""COMSUBSI",
|
||||
addLoader("COMMAIN1,COMSUBSI",
|
||||
ph.first_offset_found == 1 ? "COMSBBBP" : "",
|
||||
"COMPSHDI",
|
||||
ft->id ? "COMCALLT" : "",
|
||||
"COMMAIN2""UPX1HEAD""COMCUTPO""NRV2B160",
|
||||
"COMMAIN2,UPX1HEAD,COMCUTPO,NRV2B160",
|
||||
ft->id ? "NRVDDONE" : "NRVDRETU",
|
||||
"NRVDECO1",
|
||||
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
|
||||
"NRVDECO2""NRV2B169",
|
||||
"NRVDECO2,NRV2B169",
|
||||
NULL
|
||||
);
|
||||
if (ft->id)
|
||||
@@ -170,7 +170,7 @@ void PackCom::addFilter16(int filter_id)
|
||||
if (filter_id % 3 == 0)
|
||||
addLoader("CALLTR16",
|
||||
filter_id < 4 ? "CT16SUB0" : "",
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286""CT16SUB0"),
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286,CT16SUB0"),
|
||||
"CALLTRI2",
|
||||
getFormat() == UPX_F_DOS_COM ? "CORETURN" : "",
|
||||
NULL
|
||||
@@ -180,7 +180,7 @@ void PackCom::addFilter16(int filter_id)
|
||||
"CALLTRI5",
|
||||
getFormat() == UPX_F_DOS_COM ? "CT16JEND" : "CT16JUL2",
|
||||
filter_id < 4 ? "CT16SUB1" : "",
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287""CT16SUB1"),
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287,CT16SUB1"),
|
||||
"CALLTRI6",
|
||||
NULL
|
||||
);
|
||||
|
||||
+5
-5
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ PackDjgpp2::PackDjgpp2(InputFile *f) :
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_ADLER32 == 0xbf689ba8);
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_CRC32 == 0x2ae982b2);
|
||||
//printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub)));
|
||||
assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
|
||||
//assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
addLoader("IDENTSTR""DJ2MAIN1",
|
||||
addLoader("IDENTSTR,DJ2MAIN1",
|
||||
ft->id ? "DJCALLT1" : "",
|
||||
"DJ2MAIN2",
|
||||
getDecompressor(),
|
||||
@@ -99,7 +99,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
addLoader("DJCALLT2", NULL);
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("DJRETURN+40DXXXXUPX1HEAD", NULL);
|
||||
addLoader("DJRETURN,+40DXXXX,UPX1HEAD", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ static void handle_allegropak(InputFile *fi, OutputFile *fo)
|
||||
if (memcmp(buf, "slh+", 4) != 0)
|
||||
return;
|
||||
pfsize = get_be32_signed(buf+4);
|
||||
if (pfsize <= 8 || pfsize >= fi->st.st_size)
|
||||
if (pfsize <= 8 || (off_t) pfsize >= (off_t) fi->st.st_size)
|
||||
return;
|
||||
fi->seek(-pfsize, SEEK_END);
|
||||
} catch (const IOException&) {
|
||||
|
||||
+286
-75
@@ -34,99 +34,153 @@
|
||||
// Some ELF type definitinons
|
||||
**************************************************************************/
|
||||
|
||||
namespace TT_Elf {
|
||||
|
||||
// The ELF file header. This appears at the start of every ELF file.
|
||||
struct Elf_LE32_Ehdr
|
||||
template <class Word, class Addr, class Off, class Half>
|
||||
struct Ehdr
|
||||
{
|
||||
unsigned char e_ident[16]; /* Magic number and other info */
|
||||
LE16 e_type; /* Object file type */
|
||||
LE16 e_machine; /* Architecture */
|
||||
LE32 e_version; /* Object file version */
|
||||
LE32 e_entry; /* Entry point virtual address */
|
||||
LE32 e_phoff; /* Program header table file offset */
|
||||
LE32 e_shoff; /* Section header table file offset */
|
||||
LE32 e_flags; /* Processor-specific flags */
|
||||
LE16 e_ehsize; /* ELF header size in bytes */
|
||||
LE16 e_phentsize; /* Program header table entry size */
|
||||
LE16 e_phnum; /* Program header table entry count */
|
||||
LE16 e_shentsize; /* Section header table entry size */
|
||||
LE16 e_shnum; /* Section header table entry count */
|
||||
LE16 e_shstrndx; /* Section header string table index */
|
||||
Half e_type; /* Object file type */
|
||||
Half e_machine; /* Architecture */
|
||||
Word e_version; /* Object file version */
|
||||
Addr e_entry; /* Entry point virtual address */
|
||||
Off e_phoff; /* Program header table file offset */
|
||||
Off e_shoff; /* Section header table file offset */
|
||||
Word e_flags; /* Processor-specific flags */
|
||||
Half e_ehsize; /* ELF header size in bytes */
|
||||
Half e_phentsize; /* Program header table entry size */
|
||||
Half e_phnum; /* Program header table entry count */
|
||||
Half e_shentsize; /* Section header table entry size */
|
||||
Half e_shnum; /* Section header table entry count */
|
||||
Half e_shstrndx; /* Section header string table index */
|
||||
|
||||
// Values for e_type
|
||||
enum {
|
||||
ET_NONE = 0, /* No file type */
|
||||
ET_REL = 1, /* Relocatable file */
|
||||
ET_EXEC = 2, /* Executable file */
|
||||
ET_DYN = 3, /* Shared object file */
|
||||
ET_CORE = 4 /* Core file */
|
||||
enum { // e_ident[]
|
||||
EI_CLASS = 4,
|
||||
EI_DATA = 5, /* Data encoding */
|
||||
EI_VERSION = 6,
|
||||
EI_OSABI = 7,
|
||||
EI_ABIVERSION = 8,
|
||||
};
|
||||
enum { // e_ident[EI_CLASS]
|
||||
ELFCLASS32 = 1, /* 32-bit objects */
|
||||
ELFCLASS64 = 2, /* 64-bit objects */
|
||||
};
|
||||
enum { // e_ident[EI_DATA]
|
||||
ELFDATA2LSB = 1, /* 2's complement, little endian */
|
||||
ELFDATA2MSB = 2 /* 2's complement, big endian */
|
||||
};
|
||||
enum { // e_ident[EI_OSABI]
|
||||
ELFOSABI_LINUX = 3
|
||||
};
|
||||
enum { // e_type
|
||||
ET_NONE = 0, /* No file type */
|
||||
ET_REL = 1, /* Relocatable file */
|
||||
ET_EXEC = 2, /* Executable file */
|
||||
ET_DYN = 3, /* Shared object file */
|
||||
ET_CORE = 4, /* Core file */
|
||||
};
|
||||
enum { // e_machine
|
||||
EM_386 = 3,
|
||||
EM_PPC = 20,
|
||||
EM_PPC64 = 21,
|
||||
EM_ARM = 40,
|
||||
EM_X86_64 = 62,
|
||||
};
|
||||
enum { // e_version
|
||||
EV_CURRENT = 1,
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
template <class Word, class Addr>
|
||||
struct Dyn
|
||||
{
|
||||
Word d_tag;
|
||||
Addr d_val;
|
||||
|
||||
enum { // d_tag
|
||||
DT_NULL = 0, /* End flag */
|
||||
DT_NEEDED = 1, /* Name of needed library */
|
||||
DT_HASH = 4, /* Hash table of symbol names */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_SYMTAB = 6, /* Symbol table */
|
||||
DT_STRSZ = 10, /* Sizeof string table */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
} // namespace TT_Elf
|
||||
|
||||
|
||||
namespace TT_Elf32 {
|
||||
|
||||
// Program segment header.
|
||||
struct Elf_LE32_Phdr
|
||||
template <class Word, class Addr, class Off>
|
||||
struct Phdr
|
||||
{
|
||||
LE32 p_type; /* Segment type */
|
||||
LE32 p_offset; /* Segment file offset */
|
||||
LE32 p_vaddr; /* Segment virtual address */
|
||||
LE32 p_paddr; /* Segment physical address */
|
||||
LE32 p_filesz; /* Segment size in file */
|
||||
LE32 p_memsz; /* Segment size in memory */
|
||||
LE32 p_flags; /* Segment flags */
|
||||
LE32 p_align; /* Segment alignment */
|
||||
Word p_type; /* Segment type */
|
||||
Off p_offset; /* Segment file offset */
|
||||
Addr p_vaddr; /* Segment virtual address */
|
||||
Addr p_paddr; /* Segment physical address */
|
||||
Word p_filesz; /* Segment size in file */
|
||||
Word p_memsz; /* Segment size in memory */
|
||||
Word p_flags; /* Segment flags */
|
||||
Word p_align; /* Segment alignment */
|
||||
|
||||
// Values for p_type
|
||||
enum {
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_PHDR = 6 /* Entry for header table itself */
|
||||
enum { // p_type
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_INTERP = 3, /* Name of program interpreter */
|
||||
PT_PHDR = 6, /* Entry for header table itself */
|
||||
};
|
||||
|
||||
// Values for p_flags
|
||||
enum { PF_X = (1 << 0) }; /* Segment is executable */
|
||||
enum { PF_W = (1 << 1) }; /* Segment is writable */
|
||||
enum { PF_R = (1 << 2) }; /* Segment is readable */
|
||||
enum { // p_flags
|
||||
PF_X = 1, /* Segment is executable */
|
||||
PF_W = 2, /* Segment is writable */
|
||||
PF_R = 4, /* Segment is readable */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct Elf_LE32_Shdr
|
||||
template <class Word, class Addr, class Off>
|
||||
struct Shdr
|
||||
{
|
||||
LE32 sh_name; /* Section name (string tbl index) */
|
||||
LE32 sh_type; /* Section type */
|
||||
LE32 sh_flags; /* Section flags */
|
||||
LE32 sh_addr; /* Section virtual addr at execution */
|
||||
LE32 sh_offset; /* Section file offset */
|
||||
LE32 sh_size; /* Section size in bytes */
|
||||
LE32 sh_link; /* Link to another section */
|
||||
LE32 sh_info; /* Additional section information */
|
||||
LE32 sh_addralign; /* Section alignment */
|
||||
LE32 sh_entsize; /* Entry size if section holds table */
|
||||
Word sh_name; /* Section name (string tbl index) */
|
||||
Word sh_type; /* Section type */
|
||||
Word sh_flags; /* Section flags */
|
||||
Addr sh_addr; /* Section virtual addr at execution */
|
||||
Off sh_offset; /* Section file offset */
|
||||
Word sh_size; /* Section size in bytes */
|
||||
Word sh_link; /* Link to another section */
|
||||
Word sh_info; /* Additional section information */
|
||||
Word sh_addralign; /* Section alignment */
|
||||
Word sh_entsize; /* Entry size if section holds table */
|
||||
|
||||
enum { // values for sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1,/* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
enum { // sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1, /* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
/* 12, 13 hole */
|
||||
SHT_INIT_ARRAY = 14, /* Array of constructors */
|
||||
SHT_FINI_ARRAY = 15, /* Array of destructors */
|
||||
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
|
||||
SHT_NUM = 19 /* Number of defined types. */
|
||||
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
|
||||
};
|
||||
|
||||
enum { // values for sh_flags
|
||||
enum { // sh_flags
|
||||
SHF_WRITE = (1 << 0), /* Writable */
|
||||
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
|
||||
SHF_EXECINSTR = (1 << 2), /* Executable */
|
||||
@@ -138,20 +192,177 @@ struct Elf_LE32_Shdr
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Elf_LE32_Dyn
|
||||
template <class TT16, class TT32, class TT64>
|
||||
struct Sym
|
||||
{
|
||||
LE32 d_tag;
|
||||
LE32 d_val;
|
||||
TT32 st_name; /* symbol name (index into string table) */
|
||||
TT32 st_value; /* symbol value */
|
||||
TT32 st_size; /* symbol size */
|
||||
unsigned char st_info; /* symbol type and binding */
|
||||
unsigned char st_other; /* symbol visibility */
|
||||
TT16 st_shndx; /* section index */
|
||||
|
||||
enum { // tags
|
||||
DT_NULL = 0, /* End flag */
|
||||
DT_NEEDED = 1, /* Name of needed library */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_STRSZ = 10 /* Sizeof string table */
|
||||
unsigned int st_bind(unsigned int x) const { return 0xf & (x>>4); }
|
||||
unsigned int st_type(unsigned int x) const { return 0xf & x ; }
|
||||
unsigned char St_info(unsigned bind, unsigned type) const { return (bind<<4) + (0xf & type); }
|
||||
|
||||
enum { // st_bind (high 4 bits of st_info)
|
||||
STB_LOCAL = 0, /* Local symbol */
|
||||
STB_GLOBAL = 1, /* Global symbol */
|
||||
STB_WEAK = 2, /* Weak symbol */
|
||||
};
|
||||
|
||||
enum { // st_type (low 4 bits of st_info)
|
||||
STT_NOTYPE = 0, /* Symbol type is unspecified */
|
||||
STT_OBJECT = 1, /* Symbol is a data object */
|
||||
STT_FUNC = 2, /* Symbol is a code object */
|
||||
STT_SECTION = 3, /* Symbol associated with a section */
|
||||
STT_FILE = 4, /* Symbol's name is file name */
|
||||
STT_COMMON = 5, /* Symbol is a common data object */
|
||||
STT_TLS = 6, /* Symbol is thread-local data object*/
|
||||
};
|
||||
|
||||
enum { // st_other (visibility)
|
||||
STV_DEFAULT = 0, /* Default symbol visibility rules */
|
||||
STV_INTERNAL = 1, /* Processor specific hidden class */
|
||||
STV_HIDDEN = 2, /* Sym unavailable in other modules */
|
||||
STV_PROTECTED= 3, /* Not preemptible, not exported */
|
||||
};
|
||||
|
||||
enum { // st_shndx
|
||||
SHN_UNDEF = 0, /* Undefined section */
|
||||
SHN_ABS = 0xfff1, /* Associated symbol is absolute */
|
||||
SHN_COMMON = 0xfff2, /* Associated symbol is common */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
} // namespace TT_Elf32
|
||||
|
||||
namespace TT_Elf64 {
|
||||
|
||||
// Program segment header.
|
||||
template <class Word, class Xword, class Addr, class Off>
|
||||
struct Phdr
|
||||
{
|
||||
Word p_type; /* Segment type */
|
||||
Word p_flags; /* Segment flags */
|
||||
Off p_offset; /* Segment file offset */
|
||||
Addr p_vaddr; /* Segment virtual address */
|
||||
Addr p_paddr; /* Segment physical address */
|
||||
Xword p_filesz; /* Segment size in file */
|
||||
Xword p_memsz; /* Segment size in memory */
|
||||
Xword p_align; /* Segment alignment */
|
||||
|
||||
enum { // p_type
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_INTERP = 3, /* Name of program interpreter */
|
||||
PT_PHDR = 6, /* Entry for header table itself */
|
||||
};
|
||||
|
||||
enum { // p_flags
|
||||
PF_X = 1, /* Segment is executable */
|
||||
PF_W = 2, /* Segment is writable */
|
||||
PF_R = 4, /* Segment is readable */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
template <class Word, class Xword, class Addr, class Off>
|
||||
struct Shdr
|
||||
{
|
||||
Word sh_name; /* Section name (string tbl index) */
|
||||
Word sh_type; /* Section type */
|
||||
Xword sh_flags; /* Section flags */
|
||||
Addr sh_addr; /* Section virtual addr at execution */
|
||||
Off sh_offset; /* Section file offset */
|
||||
Xword sh_size; /* Section size in bytes */
|
||||
Word sh_link; /* Link to another section */
|
||||
Word sh_info; /* Additional section information */
|
||||
Xword sh_addralign; /* Section alignment */
|
||||
Xword sh_entsize; /* Entry size if section holds table */
|
||||
|
||||
enum { // sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1, /* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
/* 12, 13 hole */
|
||||
SHT_INIT_ARRAY = 14, /* Array of constructors */
|
||||
SHT_FINI_ARRAY = 15, /* Array of destructors */
|
||||
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
|
||||
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
} // namespace TT_Elf64
|
||||
|
||||
/*************************************************************************
|
||||
// now for the actual types
|
||||
**************************************************************************/
|
||||
|
||||
typedef TT_Elf ::Ehdr<LE32,LE32,LE32,LE16> Elf_LE32_Ehdr;
|
||||
typedef TT_Elf32::Phdr<LE32,LE32,LE32> Elf_LE32_Phdr;
|
||||
typedef TT_Elf32::Shdr<LE32,LE32,LE32> Elf_LE32_Shdr;
|
||||
typedef TT_Elf ::Dyn <LE32,LE32> Elf_LE32_Dyn;
|
||||
typedef TT_Elf32::Sym <LE16,LE32,void> Elf_LE32_Sym;
|
||||
|
||||
typedef TT_Elf ::Ehdr<unsigned int,unsigned int,unsigned int,unsigned short> Elf32_Ehdr;
|
||||
typedef TT_Elf32::Phdr<unsigned int,unsigned int,unsigned int> Elf32_Phdr;
|
||||
typedef TT_Elf32::Shdr<unsigned int,unsigned int,unsigned int> Elf32_Shdr;
|
||||
typedef TT_Elf ::Dyn <unsigned int,unsigned int> Elf32_Dyn;
|
||||
typedef TT_Elf32::Sym <unsigned short,unsigned int,void> Elf32_Sym;
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Ehdr) == 52)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Phdr) == 32)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Shdr) == 40)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Dyn) == 8)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Sym) == 16)
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Ehdr) == 52)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Phdr) == 32)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Shdr) == 40)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Dyn) == 8)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Sym) == 16)
|
||||
|
||||
|
||||
typedef TT_Elf ::Ehdr<LE32,LE64,LE64,LE16> Elf_LE64_Ehdr;
|
||||
typedef TT_Elf64::Phdr<LE32,LE64,LE64,LE64> Elf_LE64_Phdr;
|
||||
typedef TT_Elf64::Shdr<LE32,LE64,LE64,LE64> Elf_LE64_Shdr;
|
||||
typedef TT_Elf ::Dyn <LE64,LE64> Elf_LE64_Dyn;
|
||||
|
||||
typedef TT_Elf ::Ehdr<unsigned int,unsigned long long,
|
||||
unsigned long long,unsigned short> Elf64_Ehdr;
|
||||
typedef TT_Elf64::Phdr<unsigned int,unsigned long long,
|
||||
unsigned long long,unsigned long long> Elf64_Phdr;
|
||||
typedef TT_Elf64::Shdr<unsigned int,unsigned long long,
|
||||
unsigned long long,unsigned long long> Elf64_Shdr;
|
||||
typedef TT_Elf ::Dyn <unsigned long long,unsigned long long> Elf64_Dyn;
|
||||
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Ehdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Phdr) == 56)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Shdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Dyn) == 16)
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Ehdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Phdr) == 56)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Shdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Dyn) == 16)
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
|
||||
+10
-8
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
addLoader("EXEENTRY",
|
||||
relocsize ? "EXERELPU" : "",
|
||||
"EXEMAIN4""+G5DXXXX""UPX1HEAD""EXECUTPO",
|
||||
"EXEMAIN4,+G5DXXXX,UPX1HEAD,EXECUTPO",
|
||||
NULL
|
||||
);
|
||||
if (ph.method == M_NRV2B_8)
|
||||
@@ -122,7 +122,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
opt->cpu == opt->CPU_8086 ? "N2BX8602" : "N2B28602",
|
||||
"NRV2BEX3",
|
||||
ph.c_len > 0xffff ? "N2B64K02" : "",
|
||||
"NRV2BEX9""NRV2B16E",
|
||||
"NRV2BEX9,NRV2B16E",
|
||||
NULL
|
||||
);
|
||||
else if (ph.method == M_NRV2D_8)
|
||||
@@ -134,7 +134,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
opt->cpu == opt->CPU_8086 ? "N2DX8602" : "N2D28602",
|
||||
"NRV2DEX3",
|
||||
ph.c_len > 0xffff ? "N2D64K02" : "",
|
||||
"NRV2DEX9""NRV2D16E",
|
||||
"NRV2DEX9,NRV2D16E",
|
||||
NULL
|
||||
);
|
||||
else if (ph.method == M_NRV2E_8)
|
||||
@@ -146,7 +146,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
opt->cpu == opt->CPU_8086 ? "N2EX8602" : "N2E28602",
|
||||
"NRV2EEX3",
|
||||
ph.c_len > 0xffff ? "N2E64K02" : "",
|
||||
"NRV2EEX9""NRV2E16E",
|
||||
"NRV2EEX9,NRV2E16E",
|
||||
NULL
|
||||
);
|
||||
else
|
||||
@@ -293,7 +293,9 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
|
||||
{
|
||||
addr = get_le32(relocs+4*i);
|
||||
//printf ("%x\n",es*16+di);
|
||||
if (addr - es*16 > 0xfffe)
|
||||
if ((addr - es*16 > 0xfffe)
|
||||
|| (i == nrelocs - 1 && addr - es * 16 > 0xff00)
|
||||
)
|
||||
{
|
||||
// segment change
|
||||
t = 1+(0xffff-di)/254;
|
||||
@@ -409,7 +411,7 @@ void PackExe::pack(OutputFile *fo)
|
||||
throwCantPack("decompressor limit exceeded, send a bugreport");
|
||||
|
||||
#ifdef TESTING
|
||||
if (opt->debug)
|
||||
if (opt->debug.debug_level)
|
||||
{
|
||||
printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len);
|
||||
printf("offsets: %d - %d\nmatches: %d - %d\nruns: %d - %d\n",
|
||||
@@ -525,7 +527,7 @@ void PackExe::pack(OutputFile *fo)
|
||||
|
||||
// write header + write loader + compressed file
|
||||
#ifdef TESTING
|
||||
if (opt->debug)
|
||||
if (opt->debug.debug_level)
|
||||
printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len);
|
||||
#endif
|
||||
fo->write(&oh,sizeof(oh));
|
||||
|
||||
+1458
-221
File diff suppressed because it is too large
Load Diff
+265
-14
@@ -31,6 +31,256 @@
|
||||
#define __UPX_P_LX_ELF_H
|
||||
|
||||
|
||||
class PackLinuxElf : public PackUnix
|
||||
{
|
||||
typedef PackUnix super;
|
||||
public:
|
||||
PackLinuxElf(InputFile *f);
|
||||
virtual ~PackLinuxElf();
|
||||
/*virtual int buildLoader(const Filter *);*/
|
||||
virtual bool canUnpackVersion(int version) const { return (version >= 11); }
|
||||
|
||||
protected:
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
|
||||
// All other virtual functions in this class must be pure virtual
|
||||
// because they depend on Elf32 or Elf64 data structures, which differ.
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &) = 0; // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &) = 0; // append compressed data
|
||||
//virtual void pack3(OutputFile *, Filter &) = 0; // append loader
|
||||
virtual void pack4(OutputFile *, Filter &) = 0; // append pack header
|
||||
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
) = 0;
|
||||
virtual int buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
unsigned const szfold,
|
||||
Filter const *ft
|
||||
) = 0;
|
||||
virtual void unpack(OutputFile *fo) = 0;
|
||||
|
||||
protected:
|
||||
unsigned sz_phdrs; // sizeof Phdr[]
|
||||
unsigned sz_elf_hdrs; // all Elf headers
|
||||
};
|
||||
|
||||
class PackLinuxElf32 : public PackLinuxElf
|
||||
{
|
||||
typedef PackLinuxElf super;
|
||||
public:
|
||||
PackLinuxElf32(InputFile *f);
|
||||
virtual ~PackLinuxElf32();
|
||||
protected:
|
||||
virtual int checkEhdr(
|
||||
Elf32_Ehdr const *ehdr,
|
||||
unsigned char e_machine,
|
||||
unsigned char ei_class,
|
||||
unsigned char ei_data) const;
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
//virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
virtual off_t getbrk(const Elf32_Phdr *phdr, int e_phnum) const;
|
||||
virtual void patchLoader();
|
||||
virtual void updateLoader(OutputFile *fo);
|
||||
virtual unsigned find_LOAD_gap(Elf32_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
|
||||
protected:
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // for input file
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr2 {
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 {
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
};
|
||||
|
||||
|
||||
class PackLinuxElf64 : public PackLinuxElf
|
||||
{
|
||||
typedef PackLinuxElf super;
|
||||
public:
|
||||
PackLinuxElf64(InputFile *f);
|
||||
virtual ~PackLinuxElf64();
|
||||
/*virtual int buildLoader(const Filter *);*/
|
||||
|
||||
protected:
|
||||
virtual int checkEhdr(
|
||||
Elf64_Ehdr const *ehdr,
|
||||
unsigned char e_machine,
|
||||
unsigned char ei_class,
|
||||
unsigned char ei_data) const;
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
//virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
virtual off_t getbrk(const Elf64_Phdr *phdr, int e_phnum) const;
|
||||
virtual void patchLoader();
|
||||
virtual void updateLoader(OutputFile *fo);
|
||||
virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
|
||||
protected:
|
||||
Elf64_Ehdr ehdri; // from input file
|
||||
Elf64_Phdr *phdri; // for input file
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr2 {
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 {
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
};
|
||||
|
||||
class PackLinuxElf32Be : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
};
|
||||
|
||||
class PackLinuxElf64Le : public PackLinuxElf64
|
||||
{
|
||||
typedef PackLinuxElf64 super;
|
||||
protected:
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf64amd
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxElf64amd : public PackLinuxElf64Le
|
||||
{
|
||||
typedef PackLinuxElf64Le super;
|
||||
public:
|
||||
PackLinuxElf64amd(InputFile *f);
|
||||
virtual ~PackLinuxElf64amd();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF64_AMD; }
|
||||
virtual const char *getName() const { return "linux/ElfAMD"; }
|
||||
virtual const int *getFilters() const;
|
||||
virtual bool canPack();
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual int buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
unsigned const szfold,
|
||||
Filter const *ft
|
||||
);
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf32ppc
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxElf32ppc : public PackLinuxElf32Be
|
||||
{
|
||||
typedef PackLinuxElf32Be super;
|
||||
public:
|
||||
PackLinuxElf32ppc(InputFile *f);
|
||||
virtual ~PackLinuxElf32ppc();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELFPPC32; }
|
||||
virtual const char *getName() const { return "linux/ElfPPC"; }
|
||||
virtual const int *getFilters() const;
|
||||
virtual bool canPack();
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual int buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
unsigned const szfold,
|
||||
Filter const *ft
|
||||
);
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf386
|
||||
**************************************************************************/
|
||||
@@ -53,29 +303,30 @@ public:
|
||||
virtual bool canUnpackVersion(int version) const
|
||||
{ return (version >= 11); }
|
||||
|
||||
protected:
|
||||
struct Extent {
|
||||
off_t offset;
|
||||
off_t size;
|
||||
};
|
||||
virtual void packExtent(const Extent &x,
|
||||
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *);
|
||||
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
unsigned &total_in, unsigned &total_out,
|
||||
unsigned &c_adler, unsigned &u_adler,
|
||||
bool first_PF_X, unsigned szb_info );
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
|
||||
virtual void patchLoader();
|
||||
|
||||
Elf_LE32_Ehdr ehdri; // from input file
|
||||
Elf_LE32_Phdr *phdri; // for input file
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // for input file
|
||||
unsigned sz_phdrs; // sizeof Phdr[]
|
||||
|
||||
char *file_image; // if ET_DYN investigation
|
||||
Elf32_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
char const *dynstr; // from DT_STRTAB
|
||||
Elf32_Sym const *dynsym; // from DT_SYMTAB
|
||||
|
||||
static unsigned elf_hash(char const *) /*const*/;
|
||||
virtual void const *elf_find_dynamic(unsigned) const;
|
||||
virtual Elf32_Sym const *elf_lookup(char const *) const;
|
||||
virtual unsigned elf_get_offset_from_address(unsigned) const;
|
||||
virtual unsigned find_LOAD_gap(Elf32_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+90
-59
@@ -2,9 +2,9 @@
|
||||
|
||||
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) 2001-2004 John F. Reiser
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2001-2006 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -37,12 +37,14 @@
|
||||
#include "p_unix.h"
|
||||
#include "p_lx_exc.h"
|
||||
|
||||
#define PT_LOAD Elf_LE32_Phdr::PT_LOAD
|
||||
#define PT_DYNAMIC Elf_LE32_Phdr::PT_DYNAMIC
|
||||
#define DT_NULL Elf_LE32_Dyn::DT_NULL
|
||||
#define DT_NEEDED Elf_LE32_Dyn::DT_NEEDED
|
||||
#define DT_STRTAB Elf_LE32_Dyn::DT_STRTAB
|
||||
#define DT_STRSZ Elf_LE32_Dyn::DT_STRSZ
|
||||
#define PT_LOAD Elf32_Phdr::PT_LOAD
|
||||
#define PT_DYNAMIC Elf32_Phdr::PT_DYNAMIC
|
||||
#if 0 // UNUSED
|
||||
#define DT_NULL Elf32_Dyn::DT_NULL
|
||||
#define DT_NEEDED Elf32_Dyn::DT_NEEDED
|
||||
#define DT_STRTAB Elf32_Dyn::DT_STRTAB
|
||||
#define DT_STRSZ Elf32_Dyn::DT_STRSZ
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -88,12 +90,13 @@ PackLinuxI386::generateElfHdr(
|
||||
{
|
||||
cprElfHdr1 *const h1 = (cprElfHdr1 *)&elfout;
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout;
|
||||
memcpy(h2, proto, sizeof(*h2));
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout;
|
||||
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
|
||||
|
||||
assert(h2->ehdr.e_phoff == sizeof(Elf_LE32_Ehdr));
|
||||
assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
|
||||
assert(h2->ehdr.e_shoff == 0);
|
||||
assert(h2->ehdr.e_ehsize == sizeof(Elf_LE32_Ehdr));
|
||||
assert(h2->ehdr.e_phentsize == sizeof(Elf_LE32_Phdr));
|
||||
assert(h2->ehdr.e_ehsize == sizeof(Elf32_Ehdr));
|
||||
assert(h2->ehdr.e_phentsize == sizeof(Elf32_Phdr));
|
||||
assert(h2->ehdr.e_shnum == 0);
|
||||
|
||||
#if 0 //{
|
||||
@@ -129,6 +132,11 @@ PackLinuxI386::generateElfHdr(
|
||||
memset(&h2->linfo, 0, sizeof(h2->linfo));
|
||||
fo->write(h2, sizeof(*h2));
|
||||
}
|
||||
else if (ph.format==UPX_F_LINUX_ELFI_i386) {
|
||||
assert(h3->ehdr.e_phnum==3);
|
||||
memset(&h3->linfo, 0, sizeof(h3->linfo));
|
||||
fo->write(h3, sizeof(*h3));
|
||||
}
|
||||
else {
|
||||
assert(false); // unknown ph.format, PackUnix::generateElfHdr
|
||||
}
|
||||
@@ -150,10 +158,10 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
|
||||
sizeof(l_info) +
|
||||
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ;
|
||||
unsigned len = fo->getBytesWritten();
|
||||
set_native32(&elfout.phdr[0].p_filesz, len);
|
||||
super::pack4(fo, ft); // write PackHeader and overlay_offset
|
||||
|
||||
unsigned eod = fo->getBytesWritten();
|
||||
elfout.phdr[0].p_filesz = eod;
|
||||
|
||||
#if 0 // {
|
||||
// /usr/bin/strip from RedHat 8.0 (binutils-2.13.90.0.2-2)
|
||||
@@ -170,10 +178,11 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
|
||||
// Supply a "linking view" that covers everything,
|
||||
// so that 'strip' does not omit everything.
|
||||
Elf_LE32_Shdr shdr;
|
||||
Elf32_Shdr shdr;
|
||||
// The section header string table.
|
||||
char const shstrtab[] = "\0.\0.shstrtab";
|
||||
|
||||
unsigned eod = elfout.phdr[0].p_filesz;
|
||||
set_native32(&elfout.ehdr.e_shoff, eod);
|
||||
set_native16(&elfout.ehdr.e_shentsize, sizeof(shdr));
|
||||
set_native16(&elfout.ehdr.e_shnum, 3);
|
||||
@@ -181,14 +190,14 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
|
||||
// An empty Elf32_Shdr for space as a null index.
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_NULL);
|
||||
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_NULL);
|
||||
fo->write(&shdr, sizeof(shdr));
|
||||
|
||||
// Cover all the bits we need at runtime.
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
set_native32(&shdr.sh_name, 1);
|
||||
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_PROGBITS);
|
||||
set_native32(&shdr.sh_flags, Elf_LE32_Shdr::SHF_ALLOC);
|
||||
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_PROGBITS);
|
||||
set_native32(&shdr.sh_flags, Elf32_Shdr::SHF_ALLOC);
|
||||
set_native32(&shdr.sh_addr, elfout.phdr[0].p_vaddr);
|
||||
set_native32(&shdr.sh_offset, overlay_offset);
|
||||
set_native32(&shdr.sh_size, eod - overlay_offset);
|
||||
@@ -198,7 +207,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
// A section header for the section header string table.
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
set_native32(&shdr.sh_name, 3);
|
||||
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_STRTAB);
|
||||
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_STRTAB);
|
||||
set_native32(&shdr.sh_offset, 3*sizeof(shdr) + eod);
|
||||
set_native32(&shdr.sh_size, sizeof(shstrtab));
|
||||
fo->write(&shdr, sizeof(shdr));
|
||||
@@ -206,6 +215,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
fo->write(shstrtab, sizeof(shstrtab));
|
||||
#endif // }
|
||||
|
||||
#undef PAGE_MASK
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
// pre-calculate for benefit of runtime disappearing act via munmap()
|
||||
elfout.phdr[0].p_memsz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
|
||||
@@ -213,9 +223,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
|
||||
// rewrite Elf header
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->rewrite(&elfout, sizeof(elfout.ehdr) +
|
||||
elfout.ehdr.e_phnum * sizeof(elfout.phdr[0]) +
|
||||
sizeof(l_info) );
|
||||
fo->rewrite(&elfout, overlay_offset);
|
||||
}
|
||||
|
||||
static unsigned
|
||||
@@ -238,21 +246,28 @@ PackLinuxI386::buildLinuxLoader(
|
||||
{
|
||||
initLoader(proto, szproto);
|
||||
|
||||
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
|
||||
unsigned const fold_hdrlen = umax(0x80, sizeof(hf->ehdr) +
|
||||
hf->ehdr.e_phentsize * hf->ehdr.e_phnum + sizeof(l_info) );
|
||||
struct b_info h; memset(&h, 0, sizeof(h));
|
||||
h.sz_unc = szfold - fold_hdrlen;
|
||||
unsigned fold_hdrlen = 0;
|
||||
if (0 < szfold) {
|
||||
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
|
||||
fold_hdrlen = umax(0x80, sizeof(hf->ehdr) +
|
||||
hf->ehdr.e_phentsize * hf->ehdr.e_phnum + sizeof(l_info) );
|
||||
h.sz_unc = (szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen);
|
||||
h.b_method = (unsigned char) ph.method;
|
||||
h.b_ftid = (unsigned char) ph.filter;
|
||||
h.b_cto8 = (unsigned char) ph.filter_cto;
|
||||
}
|
||||
unsigned char const *const uncLoader = fold_hdrlen + fold;
|
||||
|
||||
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
|
||||
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h.sz_cpr,
|
||||
if (0 < szfold) {
|
||||
unsigned sz_cpr;
|
||||
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
|
||||
NULL, ph.method, 10, NULL, NULL );
|
||||
h.sz_cpr = sz_cpr;
|
||||
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
|
||||
throwInternalError("loader compression failed");
|
||||
}
|
||||
memcpy(cprLoader, &h, sizeof(h));
|
||||
|
||||
// This adds the definition to the "library", to be used later.
|
||||
@@ -276,71 +291,71 @@ PackLinuxI386::buildLinuxLoader(
|
||||
// compressed data
|
||||
b_len + ph.c_len );
|
||||
// entry to stub
|
||||
addLoader("LEXEC000", 0);
|
||||
addLoader("LEXEC000", NULL);
|
||||
|
||||
if (ft->id) {
|
||||
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
|
||||
addLoader("LXUNF000", 0);
|
||||
addLoader("LXUNF002", 0);
|
||||
addLoader("LXUNF000", NULL);
|
||||
addLoader("LXUNF002", NULL);
|
||||
if (0x80==(ft->id & 0xF0)) {
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE0", 0);
|
||||
addLoader("MRUBYTE0", NULL);
|
||||
}
|
||||
else if (n_mru) {
|
||||
addLoader("LXMRU005", 0);
|
||||
addLoader("LXMRU005", NULL);
|
||||
}
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU006", 0);
|
||||
addLoader("LXMRU006", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU007", 0);
|
||||
addLoader("LXMRU007", NULL);
|
||||
}
|
||||
}
|
||||
else if (0x40==(ft->id & 0xF0)) {
|
||||
addLoader("LXUNF008", 0);
|
||||
addLoader("LXUNF008", NULL);
|
||||
}
|
||||
addLoader("LXUNF010", 0);
|
||||
addLoader("LXUNF010", NULL);
|
||||
}
|
||||
if (n_mru) {
|
||||
addLoader("LEXEC009", 0);
|
||||
addLoader("LEXEC009", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LEXEC010", 0);
|
||||
addLoader(getDecompressor(), 0);
|
||||
addLoader("LEXEC015", 0);
|
||||
addLoader("LEXEC010", NULL);
|
||||
addLoader(getDecompressor(), NULL);
|
||||
addLoader("LEXEC015", NULL);
|
||||
if (ft->id) {
|
||||
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
|
||||
if (0x80!=(ft->id & 0xF0)) {
|
||||
addLoader("LXUNF042", 0);
|
||||
addLoader("LXUNF042", NULL);
|
||||
}
|
||||
}
|
||||
else { // decompr, unfilter not separate
|
||||
if (0x80==(ft->id & 0xF0)) {
|
||||
addLoader("LEXEC110", 0);
|
||||
addLoader("LEXEC110", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LEXEC100", 0);
|
||||
addLoader("LEXEC100", NULL);
|
||||
}
|
||||
// bug in APP: jmp and label must be in same .asx/.asy
|
||||
addLoader("LEXEC016", 0);
|
||||
addLoader("LEXEC016", NULL);
|
||||
}
|
||||
}
|
||||
addFilter32(ft->id);
|
||||
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
|
||||
if (0x80==(ft->id & 0xF0)) {
|
||||
if (0==n_mru) {
|
||||
addLoader("LXMRU058", 0);
|
||||
addLoader("LXMRU058", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXUNF035", 0);
|
||||
addLoader("LXUNF035", NULL);
|
||||
}
|
||||
else { // decompr always unfilters
|
||||
addLoader("LEXEC017", 0);
|
||||
addLoader("LEXEC017", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
addLoader("IDENTSTR", 0);
|
||||
addLoader("LEXEC020", 0);
|
||||
addLoader("FOLDEXEC", 0);
|
||||
addLoader("IDENTSTR", NULL);
|
||||
addLoader("LEXEC020", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
|
||||
char *ptr_cto = (char *)const_cast<unsigned char *>(getLoader());
|
||||
int sz_cto = getLoaderSize();
|
||||
@@ -396,7 +411,7 @@ int PackLinuxI386::getLoaderPrefixSize() const
|
||||
**************************************************************************/
|
||||
|
||||
// basic check of an Linux ELF Ehdr
|
||||
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
int PackLinuxI386::checkEhdr(const Elf32_Ehdr *ehdr) const
|
||||
{
|
||||
const unsigned char * const buf = ehdr->e_ident;
|
||||
|
||||
@@ -404,17 +419,18 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
return -1;
|
||||
|
||||
// now check the ELF header
|
||||
if (!memcmp(buf+8, "FreeBSD", 7)) // branded
|
||||
if (!memcmp(buf+8, "FreeBSD", 7)) // branded
|
||||
return 1;
|
||||
if (ehdr->e_type != 2) // executable
|
||||
if (ehdr->e_type != Elf32_Ehdr::ET_EXEC
|
||||
&& ehdr->e_type != Elf32_Ehdr::ET_DYN ) // executable
|
||||
return 2;
|
||||
if (ehdr->e_machine != 3) // Intel 80386
|
||||
if (ehdr->e_machine != Elf32_Ehdr::EM_386) // Intel 80386
|
||||
return 3;
|
||||
if (ehdr->e_version != 1) // version
|
||||
if (ehdr->e_version != Elf32_Ehdr::EV_CURRENT) // version
|
||||
return 4;
|
||||
if (ehdr->e_phnum < 1)
|
||||
return 5;
|
||||
if (ehdr->e_phentsize != sizeof(Elf_LE32_Phdr))
|
||||
if (ehdr->e_phentsize != sizeof(Elf32_Phdr))
|
||||
return 6;
|
||||
|
||||
// check for Linux kernels
|
||||
@@ -435,7 +451,7 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
}
|
||||
|
||||
|
||||
off_t PackLinuxI386::getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) const
|
||||
off_t PackLinuxI386::getbrk(const Elf32_Phdr *phdr, int e_phnum) const
|
||||
{
|
||||
off_t brka = 0;
|
||||
for (int j = 0; j < e_phnum; ++phdr, ++j) {
|
||||
@@ -448,6 +464,21 @@ off_t PackLinuxI386::getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) const
|
||||
return brka;
|
||||
}
|
||||
|
||||
off_t PackLinuxI386::getbase(const Elf32_Phdr *phdr, int e_phnum) const
|
||||
{
|
||||
off_t base = ~0u;
|
||||
for (int j = 0; j < e_phnum; ++phdr, ++j) {
|
||||
if (phdr->PT_LOAD == phdr->p_type) {
|
||||
if (phdr->p_vaddr < (unsigned) base)
|
||||
base = phdr->p_vaddr;
|
||||
}
|
||||
}
|
||||
if (0!=base) {
|
||||
return base;
|
||||
}
|
||||
return 0x12000;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
@@ -458,7 +489,7 @@ bool PackLinuxI386::canPack()
|
||||
if (exetype != 0)
|
||||
return super::canPack();
|
||||
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf32_Ehdr ehdr;
|
||||
unsigned char *buf = ehdr.e_ident;
|
||||
|
||||
fi->readx(&ehdr, sizeof(ehdr));
|
||||
|
||||
+13
-12
@@ -74,8 +74,9 @@ protected:
|
||||
virtual void updateLoader(OutputFile *);
|
||||
|
||||
// ELF util
|
||||
virtual int checkEhdr(const Elf_LE32_Ehdr *ehdr) const;
|
||||
virtual off_t getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) const;
|
||||
virtual int checkEhdr(const Elf32_Ehdr *ehdr) const;
|
||||
virtual off_t getbrk(const Elf32_Phdr *phdr, int e_phnum) const;
|
||||
virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const;
|
||||
|
||||
enum {
|
||||
UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
|
||||
@@ -84,27 +85,27 @@ protected:
|
||||
unsigned n_mru;
|
||||
|
||||
struct cprElfHdr1 {
|
||||
struct Elf_LE32_Ehdr ehdr;
|
||||
struct Elf_LE32_Phdr phdr[1];
|
||||
struct l_info linfo;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr2 {
|
||||
struct Elf_LE32_Ehdr ehdr;
|
||||
struct Elf_LE32_Phdr phdr[2];
|
||||
struct l_info linfo;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 {
|
||||
struct Elf_LE32_Ehdr ehdr;
|
||||
struct Elf_LE32_Phdr phdr[3];
|
||||
struct l_info linfo;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 elfout;
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
/* p_lx_interp.cpp --
|
||||
|
||||
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 John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#include "file.h"
|
||||
#include "filter.h"
|
||||
#include "linker.h"
|
||||
#include "packer.h"
|
||||
#include "p_elf.h"
|
||||
#include "p_unix.h"
|
||||
#include "p_lx_exc.h"
|
||||
#include "p_lx_elf.h"
|
||||
#include "p_lx_interp.h"
|
||||
|
||||
#define PT_LOAD Elf32_Phdr::PT_LOAD
|
||||
#define PT_INTERP Elf32_Phdr::PT_INTERP
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
static const
|
||||
#include "stub/l_lx_pti86.h"
|
||||
static const
|
||||
#include "stub/fold_pti86.h"
|
||||
|
||||
PackLinuxI386interp::PackLinuxI386interp(InputFile *f) :
|
||||
super(f)
|
||||
{
|
||||
}
|
||||
|
||||
PackLinuxI386interp::~PackLinuxI386interp()
|
||||
{
|
||||
}
|
||||
|
||||
bool PackLinuxI386interp::canPack()
|
||||
{
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
return true;
|
||||
}
|
||||
if (!opt->o_unix.use_ptinterp) {
|
||||
return false;
|
||||
}
|
||||
return super::canPack();
|
||||
}
|
||||
|
||||
void PackLinuxI386interp::pack1(OutputFile *fo, Filter &)
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ehdri, sizeof(ehdri));
|
||||
assert(ehdri.e_phoff == sizeof(Elf32_Ehdr)); // checked by canPack()
|
||||
sz_phdrs = ehdri.e_phnum * ehdri.e_phentsize;
|
||||
|
||||
phdri = new Elf32_Phdr[(unsigned)ehdri.e_phnum];
|
||||
fi->seek(ehdri.e_phoff, SEEK_SET);
|
||||
fi->readx(phdri, sz_phdrs);
|
||||
|
||||
#define E Elf32_Ehdr
|
||||
cprElfHdr3 h3;
|
||||
memset(&h3, 0, sizeof(h3));
|
||||
memcpy(h3.ehdr.e_ident, "\177ELF", 4);
|
||||
h3.ehdr.e_ident[E::EI_CLASS] = E::ELFCLASS32;
|
||||
h3.ehdr.e_ident[E::EI_DATA] = E::ELFDATA2LSB;
|
||||
h3.ehdr.e_ident[E::EI_VERSION] = E::EV_CURRENT;
|
||||
h3.ehdr.e_ident[E::EI_OSABI] = E::ELFOSABI_LINUX;
|
||||
h3.ehdr.e_ident[E::EI_ABIVERSION] = E::EV_CURRENT;
|
||||
h3.ehdr.e_type = E::ET_EXEC;
|
||||
h3.ehdr.e_machine = E::EM_386;
|
||||
h3.ehdr.e_version = 1;
|
||||
h3.ehdr.e_phoff = sizeof(Elf32_Ehdr);
|
||||
h3.ehdr.e_ehsize = sizeof(Elf32_Ehdr);
|
||||
h3.ehdr.e_phentsize = sizeof(Elf32_Phdr);
|
||||
h3.ehdr.e_phnum = 3;
|
||||
h3.phdr[0].p_type = PT_LOAD;
|
||||
h3.phdr[0].p_flags = Elf32_Phdr::PF_X | Elf32_Phdr::PF_R;
|
||||
h3.phdr[0].p_align = 0x1000;
|
||||
h3.phdr[1].p_type = PT_LOAD;
|
||||
h3.phdr[1].p_flags = Elf32_Phdr::PF_W | Elf32_Phdr::PF_R;
|
||||
h3.phdr[1].p_align = 1;
|
||||
h3.phdr[2].p_type = PT_INTERP;
|
||||
h3.phdr[2].p_offset = (char *)&h3.phdr[2].p_vaddr - (char *)&h3;
|
||||
memcpy(&h3.phdr[2].p_vaddr, "/upxrun", h3.phdr[2].p_filesz = 8);
|
||||
h3.phdr[2].p_align = 1;
|
||||
|
||||
if (opt->o_unix.make_ptinterp) { // unusual "once per release"
|
||||
elfout = h3;
|
||||
elfout.ehdr.e_phnum = 1;
|
||||
fo->write(&elfout, elfout.ehdr.e_ehsize + elfout.ehdr.e_phentsize);
|
||||
}
|
||||
else { // usual case
|
||||
generateElfHdr(fo, &h3, getbrk(phdri, ehdri.e_phnum));
|
||||
}
|
||||
#undef E
|
||||
}
|
||||
|
||||
void PackLinuxI386interp::pack2(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
return; // ignore current input file!
|
||||
}
|
||||
super::pack2(fo, ft);
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
|
||||
void PackLinuxI386interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
{
|
||||
unsigned base = getbase(phdri, ehdri.e_phnum);
|
||||
unsigned sz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
|
||||
if (base < (0x11000 + sz)) {
|
||||
base = 0x11000 + sz;
|
||||
}
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
base = 0x10000;
|
||||
}
|
||||
elfout.phdr[0].p_paddr = elfout.phdr[0].p_vaddr = base - sz;
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
initLoader(linux_i386pti_loader, sizeof(linux_i386pti_loader));
|
||||
linker->addSection("FOLDEXEC", linux_i386pti_fold, sizeof(linux_i386pti_fold));
|
||||
|
||||
addLoader("LXPTI000", NULL);
|
||||
|
||||
addLoader("LXPTI040", NULL);
|
||||
ph.method = M_NRV2B_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI041", NULL);
|
||||
ph.method = M_NRV2D_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI042", NULL);
|
||||
ph.method = M_NRV2E_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI043", NULL);
|
||||
ph.method = M_CL1B_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI091", NULL);
|
||||
|
||||
addLoader("LXPTI140", NULL);
|
||||
|
||||
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL);
|
||||
addFilter32(0x46);
|
||||
addLoader("LXUNF042,LXUNF035", NULL);
|
||||
|
||||
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL);
|
||||
addFilter32(0x49);
|
||||
addLoader("LXUNF042,LXUNF035", NULL);
|
||||
|
||||
addLoader("LXPTI200", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
upx_byte const *p = getLoader();
|
||||
lsize = getLoaderSize();
|
||||
updateLoader(fo);
|
||||
fo->write(p, lsize);
|
||||
elfout.phdr[0].p_filesz = fo->getBytesWritten();
|
||||
}
|
||||
else {
|
||||
updateLoader(fo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PackLinuxI386interp::unpack(OutputFile *fo)
|
||||
{
|
||||
#define MAX_INTERP_HDR 512
|
||||
char bufehdr[MAX_INTERP_HDR];
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)bufehdr;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *)(1+ehdr);
|
||||
|
||||
unsigned szb_info = sizeof(b_info);
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(bufehdr, MAX_INTERP_HDR);
|
||||
unsigned const e_entry = get_native32(&ehdr->e_entry);
|
||||
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
}
|
||||
|
||||
fi->seek(overlay_offset, SEEK_SET);
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
|
||||
ibuf.alloc(blocksize + OVERHEAD);
|
||||
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
|
||||
fi->readx(&bhdr, szb_info);
|
||||
ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = get_native32(&bhdr.sz_cpr);
|
||||
ph.filter_cto = bhdr.b_cto8;
|
||||
|
||||
// Uncompress Ehdr and Phdrs.
|
||||
fi->readx(ibuf, ph.c_len);
|
||||
decompress(ibuf, (upx_byte *)ehdr, false);
|
||||
|
||||
unsigned total_in = 0;
|
||||
unsigned total_out = 0;
|
||||
unsigned c_adler = upx_adler32(NULL, 0);
|
||||
unsigned u_adler = upx_adler32(NULL, 0);
|
||||
off_t ptload0hi=0, ptload1lo=0, ptload1sz=0;
|
||||
|
||||
// decompress PT_LOAD
|
||||
bool first_PF_X = true;
|
||||
fi->seek(- (off_t) (szb_info + ph.c_len), SEEK_CUR);
|
||||
for (unsigned j=0; j < ehdr->e_phnum; ++phdr, ++j) {
|
||||
if (PT_LOAD==phdr->p_type) {
|
||||
if (0==ptload0hi) {
|
||||
ptload0hi = phdr->p_filesz + phdr->p_offset;
|
||||
}
|
||||
else if (0==ptload1lo) {
|
||||
ptload1lo = phdr->p_offset;
|
||||
ptload1sz = phdr->p_filesz;
|
||||
}
|
||||
if (fo)
|
||||
fo->seek(phdr->p_offset, SEEK_SET);
|
||||
if (Elf32_Phdr::PF_X & phdr->p_flags) {
|
||||
unpackExtent(phdr->p_filesz, fo, total_in, total_out,
|
||||
c_adler, u_adler, first_PF_X, szb_info);
|
||||
first_PF_X = false;
|
||||
}
|
||||
else {
|
||||
unpackExtent(phdr->p_filesz, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, szb_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0!=ptload1sz && ptload0hi < ptload1lo) { // alignment hole?
|
||||
if (fo)
|
||||
fo->seek(ptload0hi, SEEK_SET);
|
||||
unpackExtent(ptload1lo - ptload0hi, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, szb_info);
|
||||
}
|
||||
if (total_out != orig_file_size) { // non-PT_LOAD stuff
|
||||
if (fo)
|
||||
fo->seek(0, SEEK_END);
|
||||
unpackExtent(orig_file_size - total_out, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, szb_info);
|
||||
}
|
||||
|
||||
// check for end-of-file
|
||||
fi->readx(&bhdr, szb_info);
|
||||
unsigned const sz_unc = ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
|
||||
if (sz_unc == 0) { // uncompressed size 0 -> EOF
|
||||
// note: magic is always stored le32
|
||||
unsigned const sz_cpr = get_le32(&bhdr.sz_cpr);
|
||||
if (sz_cpr != UPX_MAGIC_LE32) // sz_cpr must be h->magic
|
||||
throwCompressedDataViolation();
|
||||
}
|
||||
else { // extra bytes after end?
|
||||
throwCompressedDataViolation();
|
||||
}
|
||||
|
||||
// update header with totals
|
||||
ph.c_len = total_in;
|
||||
ph.u_len = total_out;
|
||||
|
||||
// all bytes must be written
|
||||
if (total_out != orig_file_size)
|
||||
throwEOFException();
|
||||
|
||||
// finally test the checksums
|
||||
if (ph.c_adler != c_adler || ph.u_adler != u_adler)
|
||||
throwChecksumError();
|
||||
#undef MAX_INTERP_HDR
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* p_lx_interp.h --
|
||||
|
||||
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-2004 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 John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_INTERP_H //{
|
||||
#define __UPX_P_LX_INTERP_H
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/interp386
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxI386interp : public PackLinuxI386elf
|
||||
{
|
||||
typedef PackLinuxI386elf super;
|
||||
public:
|
||||
PackLinuxI386interp(InputFile *f);
|
||||
virtual ~PackLinuxI386interp();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELFI_i386; }
|
||||
virtual const char *getName() const { return "linux/elfi386"; }
|
||||
|
||||
virtual bool canPack();
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // build loader
|
||||
};
|
||||
|
||||
|
||||
#endif /*} already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
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-2004 John F. Reiser
|
||||
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
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
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-2004 John F. Reiser
|
||||
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
|
||||
|
||||
+378
@@ -0,0 +1,378 @@
|
||||
/* p_mach.cpp -- pack Mach Object executable
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2004 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
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#include "file.h"
|
||||
#include "filter.h"
|
||||
#include "linker.h"
|
||||
#include "packer.h"
|
||||
#include "p_mach.h"
|
||||
|
||||
static const
|
||||
#include "stub/l_mac_ppc32.h"
|
||||
|
||||
static const
|
||||
#include "stub/fold_machppc32.h"
|
||||
|
||||
PackMachPPC32::PackMachPPC32(InputFile *f) :
|
||||
super(f), n_segment(0), rawmseg(0), msegcmd(0)
|
||||
{
|
||||
}
|
||||
|
||||
PackMachPPC32::~PackMachPPC32()
|
||||
{
|
||||
delete [] msegcmd;
|
||||
delete [] rawmseg;
|
||||
}
|
||||
|
||||
const int *PackMachPPC32::getCompressionMethods(int /*method*/, int /*level*/) const
|
||||
{
|
||||
// There really is no LE bias in M_NRV2E_LE32.
|
||||
static const int m_nrv2e[] = { M_NRV2E_LE32, -1 };
|
||||
return m_nrv2e;
|
||||
}
|
||||
|
||||
|
||||
const int *PackMachPPC32::getFilters() const
|
||||
{
|
||||
static const int filters[] = { 0xd0, -1 };
|
||||
return filters;
|
||||
}
|
||||
|
||||
int
|
||||
PackMachPPC32::buildMachLoader(
|
||||
upx_byte const *const proto,
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold,
|
||||
unsigned const szfold,
|
||||
Filter const */*ft*/
|
||||
)
|
||||
{
|
||||
int eof_empty = -1;
|
||||
initLoader(&eof_empty, 4096, 0, 0);
|
||||
|
||||
struct b_info h; memset(&h, 0, sizeof(h));
|
||||
unsigned fold_hdrlen = 0;
|
||||
if (0 < szfold) {
|
||||
h.sz_unc = (szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen);
|
||||
h.b_method = (unsigned char) ph.method;
|
||||
h.b_ftid = (unsigned char) ph.filter;
|
||||
h.b_cto8 = (unsigned char) ph.filter_cto;
|
||||
}
|
||||
unsigned char const *const uncLoader = fold_hdrlen + fold;
|
||||
|
||||
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
|
||||
if (0 < szfold) {
|
||||
unsigned sz_cpr;
|
||||
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
|
||||
NULL, ph.method, 10, NULL, NULL );
|
||||
h.sz_cpr = sz_cpr;
|
||||
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
|
||||
throwInternalError("loader compression failed");
|
||||
}
|
||||
memcpy(cprLoader, &h, sizeof(h));
|
||||
|
||||
// This adds the definition to the "library", to be used later.
|
||||
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr);
|
||||
delete [] cprLoader;
|
||||
|
||||
int const GAP = 128; // must match stub/l_mac_ppc.S
|
||||
segcmdo.vmsize += h.sz_unc - h.sz_cpr + GAP + 64;
|
||||
|
||||
linker->addSection("MACOS000", proto, szproto);
|
||||
|
||||
addLoader("MACOS000", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
int
|
||||
PackMachPPC32::buildLoader(const Filter *ft)
|
||||
{
|
||||
return buildMachLoader(
|
||||
l_mac_ppc32_loader, sizeof(l_mac_ppc32_loader),
|
||||
fold_machppc32, sizeof(fold_machppc32), ft );
|
||||
}
|
||||
void PackMachPPC32::patchLoader() { }
|
||||
void PackMachPPC32::updateLoader(OutputFile *) {}
|
||||
|
||||
void
|
||||
PackMachPPC32::patchLoaderChecksum()
|
||||
{
|
||||
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
|
||||
l_info *const lp = &linfo;
|
||||
// checksum for loader; also some PackHeader info
|
||||
lp->l_checksum = 0;
|
||||
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
|
||||
lp->l_lsize = (unsigned short) lsize;
|
||||
lp->l_version = (unsigned char) ph.version;
|
||||
lp->l_format = (unsigned char) ph.format;
|
||||
// INFO: lp->l_checksum is currently unused
|
||||
lp->l_checksum = upx_adler32(ptr, lsize);
|
||||
}
|
||||
|
||||
static int __acc_cdecl_qsort
|
||||
compare_segment_command(void const *const aa, void const *const bb)
|
||||
{
|
||||
Mach_segment_command const *const a = (Mach_segment_command const *)aa;
|
||||
Mach_segment_command const *const b = (Mach_segment_command const *)bb;
|
||||
unsigned const xa = a->cmd - Mach_segment_command::LC_SEGMENT;
|
||||
unsigned const xb = b->cmd - Mach_segment_command::LC_SEGMENT;
|
||||
if (xa < xb) return -1; // LC_SEGMENT first
|
||||
if (xa > xb) return 1;
|
||||
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr
|
||||
if (a->vmaddr > b->vmaddr) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
|
||||
{
|
||||
// offset of p_info in compressed file
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
|
||||
|
||||
super::pack4(fo, ft);
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
segcmdo.vmsize += segcmdo.filesize;
|
||||
fo->seek(sizeof(mhdro), SEEK_SET);
|
||||
fo->write(&segcmdo, sizeof(segcmdo));
|
||||
fo->write(&threado, sizeof(threado));
|
||||
fo->write(&linfo, sizeof(linfo));
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
|
||||
{
|
||||
BE32 disp;
|
||||
unsigned const zero = 0;
|
||||
unsigned len = fo->getBytesWritten();
|
||||
fo->write(&zero, 3& -len);
|
||||
len += (3& -len) + sizeof(disp);
|
||||
set_be32(&disp, 4+ len - sz_mach_headers); // 4: sizeof(instruction)
|
||||
fo->write(&disp, sizeof(disp));
|
||||
|
||||
threado.state.srr0 = len + segcmdo.vmaddr; /* entry address */
|
||||
super::pack3(fo, ft);
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::pack2(OutputFile *fo, Filter &ft) // append compressed body
|
||||
{
|
||||
Extent x;
|
||||
unsigned k;
|
||||
|
||||
ui_total_passes = n_segment;
|
||||
|
||||
// compress extents
|
||||
unsigned total_in = 0;
|
||||
unsigned total_out = 0;
|
||||
|
||||
ui_pass = -1; // Compressing Mach headers is invisible to UI.
|
||||
x.offset = 0;
|
||||
x.size = mhdri.sizeofcmds;
|
||||
{
|
||||
int const old_level = ph.level; ph.level = 10;
|
||||
packExtent(x, total_in, total_out, 0, fo);
|
||||
ph.level = old_level;
|
||||
}
|
||||
|
||||
ui_pass = 0;
|
||||
ft.addvalue = 0;
|
||||
|
||||
int nx = 0;
|
||||
for (k = 0; k < n_segment; ++k)
|
||||
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd
|
||||
&& 0!=msegcmd[k].filesize ) {
|
||||
x.offset = msegcmd[k].fileoff;
|
||||
x.size = msegcmd[k].filesize;
|
||||
if (0 == nx) { // 1st LC_SEGMENT must cover Mach_header at 0==fileoffset
|
||||
unsigned const delta = mhdri.sizeofcmds;
|
||||
x.offset += delta;
|
||||
x.size -= delta;
|
||||
}
|
||||
packExtent(x, total_in, total_out,
|
||||
((Mach_segment_command::VM_PROT_EXECUTE & msegcmd[k].initprot)
|
||||
? &ft : 0 ), fo );
|
||||
++nx;
|
||||
}
|
||||
if ((off_t)total_in < file_size) { // non-LC_SEGMENT stuff
|
||||
x.offset = total_in;
|
||||
x.size = file_size - total_in;
|
||||
packExtent(x, total_in, total_out, 0, fo);
|
||||
}
|
||||
|
||||
if ((off_t)total_in != file_size)
|
||||
throwEOFException();
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
#undef PAGE_SIZE
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
#define PAGE_SIZE -PAGE_MASK
|
||||
void
|
||||
PackMachPPC32::pack1(OutputFile *fo, Filter &/*ft*/) // generate executable header
|
||||
{
|
||||
mhdro = mhdri;
|
||||
mhdro.ncmds = 2;
|
||||
mhdro.sizeofcmds = sizeof(segcmdo) + sizeof(threado);
|
||||
mhdro.flags = Mach_header::MH_NOUNDEFS;
|
||||
fo->write(&mhdro, sizeof(mhdro));
|
||||
|
||||
segcmdo.cmd = Mach_segment_command::LC_SEGMENT;
|
||||
segcmdo.cmdsize = sizeof(segcmdo);
|
||||
strncpy((char *)&segcmdo.segname, "__TEXT", sizeof(segcmdo.segname));
|
||||
segcmdo.vmaddr = PAGE_MASK & (~PAGE_MASK +
|
||||
msegcmd[n_segment -1].vmsize + msegcmd[n_segment -1].vmaddr );
|
||||
segcmdo.vmsize = 0; // adjust later
|
||||
segcmdo.fileoff = 0;
|
||||
segcmdo.filesize = 0; // adjust later
|
||||
segcmdo.initprot = segcmdo.maxprot =
|
||||
Mach_segment_command::VM_PROT_READ |
|
||||
Mach_segment_command::VM_PROT_WRITE |
|
||||
Mach_segment_command::VM_PROT_EXECUTE;
|
||||
segcmdo.nsects = 0;
|
||||
segcmdo.flags = 0;
|
||||
fo->write(&segcmdo, sizeof(segcmdo));
|
||||
|
||||
threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
|
||||
threado.cmdsize = sizeof(threado);
|
||||
threado.flavor = Mach_thread_command::PPC_THREAD_STATE;
|
||||
threado.count = Mach_thread_command::PPC_THREAD_STATE_COUNT;
|
||||
memset(&threado.state, 0, sizeof(threado.state));
|
||||
fo->write(&threado, sizeof(threado));
|
||||
sz_mach_headers = fo->getBytesWritten();
|
||||
|
||||
memset((char *)&linfo, 0, sizeof(linfo));
|
||||
fo->write(&linfo, sizeof(linfo));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::unpack(OutputFile *fo)
|
||||
{
|
||||
fi->seek(overlay_offset, SEEK_SET);
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
|
||||
ibuf.alloc(blocksize + OVERHEAD);
|
||||
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
|
||||
fi->readx(&bhdr, sizeof(bhdr));
|
||||
ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = get_native32(&bhdr.sz_cpr);
|
||||
ph.filter_cto = bhdr.b_cto8;
|
||||
|
||||
// Uncompress Macho headers
|
||||
fi->readx(ibuf, ph.c_len);
|
||||
Mach_header *const mhdr = (Mach_header *)new upx_byte[ph.u_len];
|
||||
decompress(ibuf, (upx_byte *)mhdr, false);
|
||||
|
||||
unsigned total_in = 0;
|
||||
unsigned total_out = 0;
|
||||
unsigned c_adler = upx_adler32(NULL, 0);
|
||||
unsigned u_adler = upx_adler32(NULL, 0);
|
||||
Mach_segment_command const *sc = (Mach_segment_command const *)(1+ mhdr);
|
||||
unsigned k;
|
||||
|
||||
fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR);
|
||||
for (
|
||||
k = 0;
|
||||
k < mhdr->ncmds;
|
||||
(++k), (sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc))
|
||||
) {
|
||||
if (Mach_segment_command::LC_SEGMENT==sc->cmd
|
||||
&& 0!=sc->filesize ) {
|
||||
unsigned filesize = get_be32(&sc->filesize);
|
||||
unpackExtent(filesize, fo, total_in, total_out, c_adler, u_adler, false, sizeof(bhdr));
|
||||
}
|
||||
}
|
||||
unsigned const rest = orig_file_size - total_out;
|
||||
if (0!=rest) { // non-LC_SEGMENT stuff
|
||||
if (fo)
|
||||
fo->seek(0, SEEK_END);
|
||||
unpackExtent(rest, fo, total_in, total_out, c_adler, u_adler, false, sizeof(bhdr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackMachPPC32::canPack()
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&mhdri, sizeof(mhdri));
|
||||
|
||||
if (Mach_header::MH_MAGIC !=mhdri.magic
|
||||
|| Mach_header::CPU_TYPE_POWERPC !=mhdri.cputype
|
||||
|| Mach_header::MH_EXECUTE !=mhdri.filetype
|
||||
)
|
||||
return false;
|
||||
|
||||
rawmseg = (Mach_segment_command *)new char[mhdri.sizeofcmds];
|
||||
fi->readx(rawmseg, mhdri.sizeofcmds);
|
||||
|
||||
msegcmd = new Mach_segment_command[mhdri.ncmds];
|
||||
unsigned char *ptr = (unsigned char *)rawmseg;
|
||||
for (unsigned j= 0; j < mhdri.ncmds; ++j) {
|
||||
msegcmd[j] = *(Mach_segment_command *)ptr;
|
||||
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize;
|
||||
}
|
||||
|
||||
|
||||
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
|
||||
qsort(msegcmd, mhdri.ncmds, sizeof(*msegcmd), compare_segment_command);
|
||||
|
||||
// Check that LC_SEGMENTs form one contiguous chunk of the file.
|
||||
for (unsigned j= 0; j < mhdri.ncmds; ++j) {
|
||||
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd) {
|
||||
if (0xfff & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) {
|
||||
return false;
|
||||
}
|
||||
if (0 < j) {
|
||||
unsigned const sz = ~0xfff
|
||||
& (0xfff + msegcmd[j-1].filesize);
|
||||
if ((sz + msegcmd[j-1].fileoff)!=msegcmd[j].fileoff) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
++n_segment;
|
||||
sz_segment = msegcmd[j].filesize + msegcmd[j].fileoff - msegcmd[0].fileoff;
|
||||
}
|
||||
}
|
||||
// set options
|
||||
opt->o_unix.blocksize = file_size;
|
||||
return 0 < n_segment;
|
||||
}
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
/* p_mach.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
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
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_MACHO_H
|
||||
#define __UPX_P_MACHO_H
|
||||
|
||||
/*************************************************************************
|
||||
// Mach Mach Object executable
|
||||
**************************************************************************/
|
||||
|
||||
struct Mach_header {
|
||||
BE32 magic;
|
||||
enum {
|
||||
MH_MAGIC = 0xfeedface
|
||||
};
|
||||
BE32 cputype;
|
||||
enum {
|
||||
CPU_TYPE_POWERPC = 18
|
||||
};
|
||||
BE32 cpysubtype;
|
||||
BE32 filetype;
|
||||
enum {
|
||||
MH_EXECUTE = 2
|
||||
};
|
||||
BE32 ncmds;
|
||||
BE32 sizeofcmds;
|
||||
BE32 flags;
|
||||
enum {
|
||||
MH_NOUNDEFS = 1
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Mach_segment_command {
|
||||
BE32 cmd;
|
||||
enum {
|
||||
LC_SEGMENT = 0x1,
|
||||
LC_THREAD = 0x4,
|
||||
LC_UNIXTHREAD = 0x5,
|
||||
LC_LOAD_DYLINKER = 0xe
|
||||
};
|
||||
BE32 cmdsize;
|
||||
char segname[16];
|
||||
BE32 vmaddr;
|
||||
BE32 vmsize;
|
||||
BE32 fileoff;
|
||||
BE32 filesize;
|
||||
BE32 maxprot;
|
||||
enum {
|
||||
VM_PROT_READ = 1,
|
||||
VM_PROT_WRITE = 2,
|
||||
VM_PROT_EXECUTE = 4
|
||||
};
|
||||
BE32 initprot;
|
||||
BE32 nsects;
|
||||
BE32 flags;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Mach_section {
|
||||
char sectname[16];
|
||||
char segname[16];
|
||||
BE32 addr; /* memory address */
|
||||
BE32 size; /* size in bytes */
|
||||
BE32 offset; /* file offset */
|
||||
BE32 align; /* power of 2 */
|
||||
BE32 reloff; /* file offset of relocation entries */
|
||||
BE32 nreloc; /* number of relocation entries */
|
||||
BE32 flags; /* section type and attributes */
|
||||
enum {
|
||||
S_REGULAR = 0,
|
||||
S_ZEROFILL,
|
||||
S_CSTRING_LITERALS,
|
||||
S_4BYTE_LITERALS,
|
||||
S_8BYTE_LITERALS,
|
||||
S_LITERAL_POINTERS,
|
||||
S_NON_LAZY_SYMBOL_POINTERS,
|
||||
S_LAZY_SYMBOL_POINTERS,
|
||||
S_SYMBOL_STUBS,
|
||||
S_MOD_INIT_FUNC_POINTERS,
|
||||
S_MOD_TERM_FNC_POINTERS,
|
||||
S_COALESCED
|
||||
};
|
||||
enum {
|
||||
S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
|
||||
S_ATTR_NO_TOC = 0x40000000,
|
||||
S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
|
||||
S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
|
||||
S_ATTR_EXT_RELOC = 0x00000200,
|
||||
S_ATTR_LOC_RELOC = 0x00000100
|
||||
};
|
||||
BE32 reserved1;
|
||||
BE32 reserved2;
|
||||
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Mach_ppc_thread_state {
|
||||
BE32 srr0; /* Instruction address register (PC; entry addr) */
|
||||
BE32 srr1; /* Machine state register (supervisor) */
|
||||
BE32 r0, r1, r2, r3, r4, r5, r6, r7;
|
||||
BE32 r8, r9,r10,r11,r12,r13,r14,r15;
|
||||
BE32 r16,r17,r18,r19,r20,r21,r22,r23;
|
||||
BE32 r24,r25,r26,r27,r28,r29,r30,r31;
|
||||
|
||||
BE32 cr; /* Condition register */
|
||||
BE32 xer; /* User's integer exception register */
|
||||
BE32 lr; /* Link register */
|
||||
BE32 ctr; /* Count register */
|
||||
BE32 mq; /* MQ register (601 only) */
|
||||
|
||||
BE32 vrsave; /* Vector Save Register */
|
||||
};
|
||||
|
||||
struct Mach_thread_command {
|
||||
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
BE32 cmdsize; /* total size of this command */
|
||||
BE32 flavor;
|
||||
enum {
|
||||
PPC_THREAD_STATE = 1
|
||||
};
|
||||
BE32 count; /* sizeof(following_thread_state)/4 */
|
||||
enum {
|
||||
PPC_THREAD_STATE_COUNT = sizeof(struct Mach_ppc_thread_state)/4
|
||||
};
|
||||
struct Mach_ppc_thread_state state;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
#include "p_unix.h"
|
||||
|
||||
|
||||
class PackMachPPC32 : public PackUnixBe32
|
||||
{
|
||||
typedef PackUnixBe32 super;
|
||||
public:
|
||||
PackMachPPC32(InputFile *f);
|
||||
virtual ~PackMachPPC32();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_MACH_PPC32; }
|
||||
virtual const char *getName() const { return "Mach/ppc32"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
// called by the generic pack()
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void patchLoader();
|
||||
virtual void patchLoaderChecksum();
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual int buildMachLoader(
|
||||
upx_byte const *const proto,
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold,
|
||||
unsigned const szfold,
|
||||
Filter const *ft );
|
||||
|
||||
unsigned n_segment;
|
||||
unsigned sz_segment;
|
||||
unsigned sz_mach_headers;
|
||||
Mach_segment_command *rawmseg; // as input, with sections
|
||||
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
|
||||
Mach_header mhdri;
|
||||
|
||||
Mach_header mhdro;
|
||||
Mach_segment_command segcmdo;
|
||||
Mach_thread_command threado;
|
||||
struct l_info linfo;
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+7
-7
@@ -2,9 +2,9 @@
|
||||
|
||||
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) 2002-2004 Jens Medoch
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2002-2006 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -84,10 +84,10 @@ PackPs1::PackPs1(InputFile *f) :
|
||||
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t));
|
||||
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40);
|
||||
#if 1 || defined(WITH_NRV)
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3918);
|
||||
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0xdf0cbd9e);
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2810);
|
||||
COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x31747f8b);
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3935);
|
||||
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0x0ac25782);
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2829);
|
||||
COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x923b55c4);
|
||||
#endif
|
||||
fdata_size = file_size - PS_HDR_SIZE;
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -107,12 +107,12 @@ int PackSys::buildLoader(const Filter *ft)
|
||||
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
|
||||
addLoader("SYSMAIN1",
|
||||
opt->cpu == opt->CPU_8086 ? "SYSI0861" : "SYSI2861",
|
||||
"SYSMAIN2""SYSSUBSI",
|
||||
"SYSMAIN2,SYSSUBSI",
|
||||
ph.first_offset_found == 1 ? "SYSSBBBP" : "",
|
||||
ft->id ? "SYSCALLT" : "",
|
||||
"SYSMAIN3""UPX1HEAD""SYSCUTPO""NRV2B160""NRVDDONE""NRVDECO1",
|
||||
"SYSMAIN3,UPX1HEAD,SYSCUTPO,NRV2B160,NRVDDONE,NRVDECO1",
|
||||
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
|
||||
"NRVDECO2""NRV2B169",
|
||||
"NRVDECO2,NRV2B169",
|
||||
NULL
|
||||
);
|
||||
if (ft->id)
|
||||
|
||||
+5
-5
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -78,9 +78,9 @@ int PackTmt::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
addLoader("IDENTSTR""TMTMAIN1",
|
||||
addLoader("IDENTSTR,TMTMAIN1",
|
||||
ft->id ? "TMTCALT1" : "",
|
||||
"TMTMAIN2""UPX1HEAD""TMTCUTPO""+0XXXXXX",
|
||||
"TMTMAIN2,UPX1HEAD,TMTCUTPO,+0XXXXXX",
|
||||
getDecompressor(),
|
||||
"TMTMAIN5",
|
||||
NULL
|
||||
@@ -91,9 +91,9 @@ int PackTmt::buildLoader(const Filter *ft)
|
||||
addLoader("TMTCALT2",NULL);
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("TMTRELOC""RELOC320",
|
||||
addLoader("TMTRELOC,RELOC320",
|
||||
big_relocs ? "REL32BIG" : "",
|
||||
"RELOC32J""TMTJUMP1",
|
||||
"RELOC32J,TMTJUMP1",
|
||||
NULL
|
||||
);
|
||||
return getLoaderSize();
|
||||
|
||||
@@ -547,6 +547,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
// patch loader
|
||||
int tmp = patchPackHeader(loader, o_text);
|
||||
assert(tmp + 32 == (int)o_text); UNUSED(tmp);
|
||||
patchVersionYear(loader, o_text);
|
||||
if (!opt->small)
|
||||
patchVersion(loader, o_text);
|
||||
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
|
||||
|
||||
+210
-5
@@ -45,8 +45,8 @@
|
||||
PackUnix::PackUnix(InputFile *f) :
|
||||
super(f), exetype(0), blocksize(0), overlay_offset(0), lsize(0)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf_LE32_Ehdr) == 52);
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf_LE32_Phdr) == 32);
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf32_Ehdr) == 52);
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf32_Phdr) == 32);
|
||||
COMPILE_TIME_ASSERT(sizeof(b_info) == 12);
|
||||
COMPILE_TIME_ASSERT(sizeof(l_info) == 12);
|
||||
COMPILE_TIME_ASSERT(sizeof(p_info) == 12);
|
||||
@@ -127,7 +127,7 @@ int PackUnix::getStrategy(Filter &/*ft*/)
|
||||
|
||||
// If user specified the filter, then use it (-2==strategy).
|
||||
// Else try the first two filters, and pick the better (2==strategy).
|
||||
return ((opt->filter > 0) ? -2 : 2);
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
@@ -222,6 +222,20 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PackUnix::patchLoaderChecksum()
|
||||
{
|
||||
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
|
||||
l_info *const lp = &linfo;
|
||||
// checksum for loader; also some PackHeader info
|
||||
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
|
||||
lp->l_lsize = (unsigned short) lsize;
|
||||
lp->l_version = (unsigned char) ph.version;
|
||||
lp->l_format = (unsigned char) ph.format;
|
||||
// INFO: lp->l_checksum is currently unused
|
||||
lp->l_checksum = upx_adler32(ptr, lsize);
|
||||
}
|
||||
|
||||
void PackUnix::pack3(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
upx_byte const *p = getLoader();
|
||||
@@ -285,6 +299,197 @@ void PackUnix::pack(OutputFile *fo)
|
||||
}
|
||||
|
||||
|
||||
void PackUnix::packExtent(
|
||||
const Extent &x,
|
||||
unsigned &total_in,
|
||||
unsigned &total_out,
|
||||
Filter *ft,
|
||||
OutputFile *fo,
|
||||
unsigned hdr_ulen
|
||||
)
|
||||
{
|
||||
unsigned const init_u_adler = ph.u_adler;
|
||||
unsigned const init_c_adler = ph.c_adler;
|
||||
MemBuffer hdr_ibuf;
|
||||
if (hdr_ulen) {
|
||||
hdr_ibuf.alloc(hdr_ulen);
|
||||
fi->seek(0, SEEK_SET);
|
||||
int l = fi->readx(hdr_ibuf, hdr_ulen);
|
||||
(void)l;
|
||||
}
|
||||
fi->seek(x.offset, SEEK_SET);
|
||||
for (off_t rest = x.size; 0 != rest; ) {
|
||||
int const strategy = getStrategy(*ft);
|
||||
int l = fi->readx(ibuf, UPX_MIN(rest, (off_t)blocksize));
|
||||
if (l == 0) {
|
||||
break;
|
||||
}
|
||||
rest -= l;
|
||||
|
||||
// Note: compression for a block can fail if the
|
||||
// file is e.g. blocksize + 1 bytes long
|
||||
|
||||
// compress
|
||||
ph.c_len = ph.u_len = l;
|
||||
ph.overlap_overhead = 0;
|
||||
unsigned end_u_adler = 0;
|
||||
if (ft) {
|
||||
// compressWithFilters() updates u_adler _inside_ compress();
|
||||
// that is, AFTER filtering. We want BEFORE filtering,
|
||||
// so that decompression checks the end-to-end checksum.
|
||||
end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler);
|
||||
ft->buf_len = l;
|
||||
|
||||
// compressWithFilters() requirements?
|
||||
ph.filter = 0;
|
||||
ph.filter_cto = 0;
|
||||
ft->id = 0;
|
||||
ft->cto = 0;
|
||||
|
||||
compressWithFilters(ft, OVERHEAD, strategy,
|
||||
NULL, 0, 0, 0, 0, // those 5 args are the defaults
|
||||
hdr_ibuf, hdr_ulen);
|
||||
}
|
||||
else {
|
||||
(void) compress(ibuf, obuf); // ignore return value
|
||||
}
|
||||
|
||||
if (ph.c_len < ph.u_len) {
|
||||
ph.overlap_overhead = OVERHEAD;
|
||||
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
|
||||
// not in-place compressible
|
||||
ph.c_len = ph.u_len;
|
||||
}
|
||||
}
|
||||
if (ph.c_len >= ph.u_len) {
|
||||
// block is not compressible
|
||||
ph.c_len = ph.u_len;
|
||||
memcpy(obuf, ibuf, ph.c_len);
|
||||
// must update checksum of compressed data
|
||||
ph.c_adler = upx_adler32(ibuf, ph.u_len, ph.saved_c_adler);
|
||||
}
|
||||
|
||||
// write block sizes
|
||||
b_info tmp;
|
||||
if (hdr_ulen) {
|
||||
unsigned hdr_clen;
|
||||
MemBuffer hdr_obuf;
|
||||
unsigned result[16];
|
||||
upx_compress_config_t conf;
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
hdr_obuf.allocForCompression(hdr_ulen);
|
||||
int r = upx_compress(hdr_ibuf, hdr_ulen, hdr_obuf, &hdr_clen, 0,
|
||||
ph.method, 10, &conf, result);
|
||||
(void)r;
|
||||
ph.saved_u_adler = upx_adler32(hdr_ibuf, hdr_ulen, init_u_adler);
|
||||
ph.saved_c_adler = upx_adler32(hdr_obuf, hdr_clen, init_c_adler);
|
||||
ph.u_adler = upx_adler32(ibuf, ph.u_len, ph.saved_u_adler);
|
||||
ph.c_adler = upx_adler32(obuf, ph.c_len, ph.saved_c_adler);
|
||||
end_u_adler = ph.u_adler;
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, hdr_ulen);
|
||||
set_native32(&tmp.sz_cpr, hdr_clen);
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
fo->write(hdr_obuf, hdr_clen);
|
||||
total_out += hdr_clen;
|
||||
total_in += hdr_ulen;
|
||||
hdr_ulen = 0; // compress hdr one time only
|
||||
}
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, ph.u_len);
|
||||
set_native32(&tmp.sz_cpr, ph.c_len);
|
||||
if (ph.c_len < ph.u_len) {
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
if (ft) {
|
||||
tmp.b_ftid = (unsigned char) ft->id;
|
||||
tmp.b_cto8 = ft->cto;
|
||||
}
|
||||
}
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
|
||||
// write compressed data
|
||||
if (ph.c_len < ph.u_len) {
|
||||
fo->write(obuf, ph.c_len);
|
||||
// Checks ph.u_adler after decompression, after unfiltering
|
||||
verifyOverlappingDecompression(ft);
|
||||
}
|
||||
else {
|
||||
fo->write(ibuf, ph.u_len);
|
||||
}
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
total_in += ph.u_len;
|
||||
total_out += ph.c_len;
|
||||
}
|
||||
}
|
||||
|
||||
void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
unsigned &total_in, unsigned &total_out,
|
||||
unsigned &c_adler, unsigned &u_adler,
|
||||
bool first_PF_X, unsigned szb_info
|
||||
)
|
||||
{
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
while (wanted) {
|
||||
fi->readx(&hdr, szb_info);
|
||||
int const sz_unc = ph.u_len = get_native32(&hdr.sz_unc);
|
||||
int const sz_cpr = ph.c_len = get_native32(&hdr.sz_cpr);
|
||||
ph.filter_cto = hdr.b_cto8;
|
||||
|
||||
if (sz_unc == 0) { // must never happen while 0!=wanted
|
||||
throwCompressedDataViolation();
|
||||
break;
|
||||
}
|
||||
if (sz_unc <= 0 || sz_cpr <= 0)
|
||||
throwCompressedDataViolation();
|
||||
if (sz_cpr > sz_unc || sz_unc > (int)blocksize)
|
||||
throwCompressedDataViolation();
|
||||
|
||||
int j = blocksize + OVERHEAD - sz_cpr;
|
||||
fi->readx(ibuf+j, sz_cpr);
|
||||
// update checksum of compressed data
|
||||
c_adler = upx_adler32(ibuf + j, sz_cpr, c_adler);
|
||||
// decompress
|
||||
if (sz_cpr < sz_unc)
|
||||
{
|
||||
decompress(ibuf+j, ibuf, false);
|
||||
if (12==szb_info) { // modern per-block filter
|
||||
if (hdr.b_ftid) {
|
||||
Filter ft(ph.level); // FIXME: ph.level for b_info?
|
||||
ft.init(hdr.b_ftid, 0);
|
||||
ft.cto = hdr.b_cto8;
|
||||
ft.unfilter(ibuf, sz_unc);
|
||||
}
|
||||
}
|
||||
else { // ancient per-file filter
|
||||
if (first_PF_X) { // Elf32_Ehdr is never filtered
|
||||
first_PF_X = false; // but everything else might be
|
||||
}
|
||||
else if (ph.filter) {
|
||||
Filter ft(ph.level);
|
||||
ft.init(ph.filter, 0);
|
||||
ft.cto = (unsigned char) ph.filter_cto;
|
||||
ft.unfilter(ibuf, sz_unc);
|
||||
}
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
// update checksum of uncompressed data
|
||||
u_adler = upx_adler32(ibuf + j, sz_unc, u_adler);
|
||||
total_in += sz_cpr;
|
||||
total_out += sz_unc;
|
||||
// write block
|
||||
if (fo)
|
||||
fo->write(ibuf + j, sz_unc);
|
||||
wanted -= sz_unc;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
// Generic Unix canUnpack().
|
||||
**************************************************************************/
|
||||
@@ -321,7 +526,7 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
{
|
||||
unsigned szb_info = sizeof(b_info);
|
||||
{
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf32_Ehdr ehdr;
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ehdr, sizeof(ehdr));
|
||||
unsigned const e_entry = get_native32(&ehdr.e_entry);
|
||||
@@ -329,7 +534,7 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
else {
|
||||
Elf_LE32_Phdr phdr;
|
||||
Elf32_Phdr phdr;
|
||||
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(&phdr, sizeof(phdr));
|
||||
unsigned const p_vaddr = get_native32(&phdr.p_vaddr);
|
||||
|
||||
+82
-24
@@ -59,19 +59,35 @@ protected:
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
|
||||
virtual void patchLoader() = 0;
|
||||
virtual void patchLoaderChecksum() {}
|
||||
virtual void patchLoaderChecksum();
|
||||
virtual void updateLoader(OutputFile *) = 0;
|
||||
|
||||
virtual void writePackHeader(OutputFile *fo);
|
||||
|
||||
// in order too share as much code as possible we introduce
|
||||
// an endian abstraction here
|
||||
virtual unsigned get_native32(const void *) = 0;
|
||||
virtual void set_native32(void *, unsigned) = 0;
|
||||
virtual void set_native16(void *, unsigned) = 0;
|
||||
virtual acc_uint64l_t get_native64(const void *) const = 0;
|
||||
virtual unsigned get_native32(const void *) const = 0;
|
||||
virtual unsigned get_native16(const void *) const = 0;
|
||||
virtual void set_native64(void *, acc_uint64l_t) const = 0;
|
||||
virtual void set_native32(void *, unsigned) const = 0;
|
||||
virtual void set_native16(void *, unsigned) const = 0;
|
||||
|
||||
virtual bool checkCompressionRatio(unsigned, unsigned) const;
|
||||
|
||||
protected:
|
||||
struct Extent {
|
||||
off_t offset;
|
||||
off_t size;
|
||||
};
|
||||
virtual void packExtent(const Extent &x,
|
||||
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *,
|
||||
unsigned hdr_len = 0);
|
||||
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
unsigned &total_in, unsigned &total_out,
|
||||
unsigned &c_adler, unsigned &u_adler,
|
||||
bool first_PF_X, unsigned szb_info );
|
||||
|
||||
int exetype;
|
||||
unsigned blocksize;
|
||||
unsigned progid; // program id
|
||||
@@ -94,7 +110,6 @@ protected:
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
unsigned l_checksum;
|
||||
unsigned l_magic;
|
||||
@@ -111,6 +126,8 @@ protected:
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct l_info linfo;
|
||||
|
||||
// do not change !!!
|
||||
enum { OVERHEAD = 2048 };
|
||||
};
|
||||
@@ -120,24 +137,44 @@ protected:
|
||||
// abstract classes encapsulating endian issues
|
||||
// note: UPX_MAGIC is always stored in le32 format
|
||||
**************************************************************************/
|
||||
|
||||
class PackUnixBe32 : public PackUnix
|
||||
{
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixBe32(InputFile *f) : super(f) { }
|
||||
virtual unsigned get_native32(const void *b)
|
||||
{
|
||||
return get_be32(b);
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
BE32 sz_unc; // uncompressed_size
|
||||
BE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
virtual void set_native32(void *b, unsigned v)
|
||||
{
|
||||
set_be32(b, v);
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
BE32 l_checksum;
|
||||
BE32 l_magic;
|
||||
BE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
virtual void set_native16(void *b, unsigned v)
|
||||
{
|
||||
set_be16(b, v);
|
||||
__attribute_packed;
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
BE32 p_progid;
|
||||
BE32 p_filesize;
|
||||
BE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -146,18 +183,39 @@ class PackUnixLe32 : public PackUnix
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixLe32(InputFile *f) : super(f) { }
|
||||
virtual unsigned get_native32(const void *b)
|
||||
{
|
||||
return get_le32(b);
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
LE32 sz_unc; // uncompressed_size
|
||||
LE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
virtual void set_native32(void *b, unsigned v)
|
||||
{
|
||||
set_le32(b, v);
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
virtual void set_native16(void *b, unsigned v)
|
||||
{
|
||||
set_le16(b, v);
|
||||
__attribute_packed;
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
LE32 p_progid;
|
||||
LE32 p_filesize;
|
||||
LE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
+57
-57
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
|
||||
John Reiser
|
||||
jreiser@users.sourceforge.net
|
||||
@@ -72,10 +72,10 @@ const int *PackVmlinuxI386::getFilters() const
|
||||
static int __acc_cdecl_qsort
|
||||
compare_Phdr(void const *aa, void const *bb)
|
||||
{
|
||||
Elf_LE32_Phdr const *const a = (Elf_LE32_Phdr const *)aa;
|
||||
Elf_LE32_Phdr const *const b = (Elf_LE32_Phdr const *)bb;
|
||||
unsigned const xa = a->p_type - Elf_LE32_Phdr::PT_LOAD;
|
||||
unsigned const xb = b->p_type - Elf_LE32_Phdr::PT_LOAD;
|
||||
Elf32_Phdr const *const a = (Elf32_Phdr const *)aa;
|
||||
Elf32_Phdr const *const b = (Elf32_Phdr const *)bb;
|
||||
unsigned const xa = a->p_type - Elf32_Phdr::PT_LOAD;
|
||||
unsigned const xb = b->p_type - Elf32_Phdr::PT_LOAD;
|
||||
if (xa < xb) return -1; // PT_LOAD first
|
||||
if (xa > xb) return 1;
|
||||
if (a->p_paddr < b->p_paddr) return -1; // ascending by .p_paddr
|
||||
@@ -118,14 +118,14 @@ bool PackVmlinuxI386::canPack()
|
||||
// additional requirements for vmlinux
|
||||
if (ehdri.e_ehsize != sizeof(ehdri) // different <elf.h> ?
|
||||
|| ehdri.e_phoff != sizeof(ehdri) // Phdrs not contiguous with Ehdr
|
||||
|| ehdri.e_phentsize!=sizeof(Elf_LE32_Phdr)
|
||||
|| ehdri.e_type!=Elf_LE32_Ehdr::ET_EXEC
|
||||
|| ehdri.e_phentsize!=sizeof(Elf32_Phdr)
|
||||
|| ehdri.e_type!=Elf32_Ehdr::ET_EXEC
|
||||
|| 0x00100000!=(0x001fffff & ehdri.e_entry) // entry not an odd 1MB
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
phdri = new Elf_LE32_Phdr[(unsigned) ehdri.e_phnum];
|
||||
phdri = new Elf32_Phdr[(unsigned) ehdri.e_phnum];
|
||||
fi->seek(ehdri.e_phoff, SEEK_SET);
|
||||
fi->readx(phdri, ehdri.e_phnum * sizeof(*phdri));
|
||||
|
||||
@@ -134,7 +134,7 @@ bool PackVmlinuxI386::canPack()
|
||||
|
||||
// Check that PT_LOADs form one contiguous chunk of the file.
|
||||
for (unsigned j = 0; j < ehdri.e_phnum; ++j) {
|
||||
if (Elf_LE32_Phdr::PT_LOAD==phdri[j].p_type) {
|
||||
if (Elf32_Phdr::PT_LOAD==phdri[j].p_type) {
|
||||
if (0xfff & (phdri[j].p_offset | phdri[j].p_paddr
|
||||
| phdri[j].p_align | phdri[j].p_vaddr) ) {
|
||||
return false;
|
||||
@@ -174,7 +174,7 @@ int PackVmlinuxI386::buildLoader(const Filter *ft)
|
||||
}
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUX990""IDENTSTR""UPX1HEAD", NULL);
|
||||
addLoader("LINUX990,IDENTSTR,UPX1HEAD", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -182,13 +182,13 @@ int PackVmlinuxI386::buildLoader(const Filter *ft)
|
||||
void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
{
|
||||
unsigned fo_off = 0;
|
||||
Elf_LE32_Ehdr ehdro;
|
||||
Elf32_Ehdr ehdro;
|
||||
LE32 tmp_le32;
|
||||
|
||||
// NULL
|
||||
// .text(PT_LOADs) .note(1st page) .note(rest)
|
||||
// .shstrtab /* .symtab .strtab */
|
||||
Elf_LE32_Shdr shdro[1+3+1/*+2*/];
|
||||
Elf32_Shdr shdro[1+3+1/*+2*/];
|
||||
memset(shdro, 0, sizeof(shdro));
|
||||
char const shstrtab[]= "\0.text\0.note\0.shstrtab\0.symtab\0.strtab";
|
||||
char const *p = shstrtab;
|
||||
@@ -198,7 +198,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
// .e_ident, .e_machine, .e_version, .e_flags
|
||||
memcpy(&ehdro, &ehdri, sizeof(ehdro));
|
||||
ehdro.e_type = Elf_LE32_Ehdr::ET_REL;
|
||||
ehdro.e_type = Elf32_Ehdr::ET_REL;
|
||||
ehdro.e_entry = 0;
|
||||
ehdro.e_phoff = 0;
|
||||
ehdro.e_shoff = 0; // later
|
||||
@@ -231,8 +231,8 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[1].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[1].sh_type = Elf_LE32_Shdr::SHT_PROGBITS;
|
||||
shdro[1].sh_flags = Elf_LE32_Shdr::SHF_ALLOC | Elf_LE32_Shdr::SHF_EXECINSTR;
|
||||
shdro[1].sh_type = Elf32_Shdr::SHT_PROGBITS;
|
||||
shdro[1].sh_flags = Elf32_Shdr::SHF_ALLOC | Elf32_Shdr::SHF_EXECINSTR;
|
||||
shdro[1].sh_offset = fo_off;
|
||||
shdro[1].sh_size = 1+ 4+ ph.c_len + lsize;
|
||||
shdro[1].sh_addralign = 1;
|
||||
@@ -257,7 +257,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[2].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[2].sh_type = Elf_LE32_Shdr::SHT_NOTE;
|
||||
shdro[2].sh_type = Elf32_Shdr::SHT_NOTE;
|
||||
shdro[2].sh_offset = fo_off;
|
||||
shdro[2].sh_size = sizeof(ph.u_len) + ph.c_len;
|
||||
shdro[2].sh_addralign = 1;
|
||||
@@ -283,7 +283,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
// while (0!=*p++) ; // name is the same
|
||||
shdro[3].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[3].sh_type = Elf_LE32_Shdr::SHT_NOTE;
|
||||
shdro[3].sh_type = Elf32_Shdr::SHT_NOTE;
|
||||
shdro[3].sh_offset = fo_off;
|
||||
shdro[3].sh_size = sizeof(ph.u_len) + ph.c_len;
|
||||
shdro[3].sh_addralign = 1;
|
||||
@@ -292,7 +292,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[4].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[4].sh_type = Elf_LE32_Shdr::SHT_STRTAB;
|
||||
shdro[4].sh_type = Elf32_Shdr::SHT_STRTAB;
|
||||
shdro[4].sh_offset = fo_off;
|
||||
shdro[4].sh_size = 1+ sizeof(shstrtab); // 1+: terminating '\0'
|
||||
shdro[4].sh_addralign = 1;
|
||||
@@ -302,7 +302,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
while (0!=*p++) ;
|
||||
fo_off = ~3 & (3+ fo_off);
|
||||
shdro[5].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[5].sh_type = Elf_LE32_Shdr::SHT_SYMTAB;
|
||||
shdro[5].sh_type = Elf32_Shdr::SHT_SYMTAB;
|
||||
shdro[5].sh_offset = fo_off;
|
||||
shdro[5].sh_size = 16; // XXX ?
|
||||
shdro[5].sh_link = 6; // to .strtab for symbols
|
||||
@@ -313,7 +313,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[6].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[6].sh_type = Elf_LE32_Shdr::SHT_STRTAB;
|
||||
shdro[6].sh_type = Elf32_Shdr::SHT_STRTAB;
|
||||
shdro[6].sh_offset = fo_off;
|
||||
shdro[6].sh_size = 1; // XXX ?
|
||||
shdro[6].sh_addralign = 1;
|
||||
@@ -347,21 +347,21 @@ int PackVmlinuxI386::canUnpack()
|
||||
|| !memcmp(&ehdri.e_ident[8], "FreeBSD", 7) // branded
|
||||
|| ehdri.e_machine != 3 // Intel 80386
|
||||
|| ehdri.e_version != 1 // version
|
||||
|| ehdri.e_type != Elf_LE32_Ehdr::ET_REL
|
||||
|| ehdri.e_type != Elf32_Ehdr::ET_REL
|
||||
|| ehdri.e_shnum < 4
|
||||
|| (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf_LE32_Shdr) + ehdri.e_shoff)
|
||||
|| (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf32_Shdr) + ehdri.e_shoff)
|
||||
)
|
||||
return false;
|
||||
|
||||
// find the .shstrtab section
|
||||
char shstrtab[40];
|
||||
Elf_LE32_Shdr *p, *p_shstrtab=0;
|
||||
shdri = new Elf_LE32_Shdr[(unsigned) ehdri.e_shnum];
|
||||
Elf32_Shdr *p, *p_shstrtab=0;
|
||||
shdri = new Elf32_Shdr[(unsigned) ehdri.e_shnum];
|
||||
fi->seek(ehdri.e_shoff, SEEK_SET);
|
||||
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
|
||||
int j;
|
||||
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
|
||||
if (Elf_LE32_Shdr::SHT_STRTAB==p->sh_type
|
||||
if (Elf32_Shdr::SHT_STRTAB==p->sh_type
|
||||
&& p->sh_size <= sizeof(shstrtab)
|
||||
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
|
||||
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
|
||||
@@ -487,37 +487,37 @@ void PackVmlinuxI386::unpack(OutputFile *fo)
|
||||
//-----
|
||||
//
|
||||
//----- arch/i386/boot/compressed/upx-head.S
|
||||
// .text
|
||||
// .text
|
||||
//startup_32: .globl startup_32 # In: %esi=0x90000 setup data "real_mode pointer"
|
||||
// #cli # this must be true already
|
||||
// #cli # this must be true already
|
||||
//
|
||||
// /* The only facts about segments here, that are true for all kernels:
|
||||
// * %cs is a valid "flat" code segment; no other segment reg is valid;
|
||||
// * the next segment after %cs is a valid "flat" data segment, but
|
||||
// * no segment register designates it yet.
|
||||
// */
|
||||
// movl %cs,%eax; addl $1<<3,%eax # the next segment after %cs
|
||||
// movl %eax,%ds
|
||||
// movl %eax,%es
|
||||
// leal 0x9000(%esi),%ecx # 0x99000 typical
|
||||
// movl %ecx,-8(%ecx) # 32-bit offset for stack pointer
|
||||
// movl %eax,-4(%ecx) # segment for stack pointer
|
||||
// lss -8(%ecx),%esp # %ss:%esp= %ds:0x99000
|
||||
// /* Linux Documentation/i386/boot.txt "SAMPLE BOOT CONFIGURATION" says
|
||||
// 0x8000-0x8FFF Stack and heap [inside the "real mode segment",
|
||||
// just below the command line at offset 0x9000].
|
||||
// /* The only facts about segments here, that are true for all kernels:
|
||||
// * %cs is a valid "flat" code segment; no other segment reg is valid;
|
||||
// * the next segment after %cs is a valid "flat" data segment, but
|
||||
// * no segment register designates it yet.
|
||||
// */
|
||||
// movl %cs,%eax; addl $1<<3,%eax # the next segment after %cs
|
||||
// movl %eax,%ds
|
||||
// movl %eax,%es
|
||||
// leal 0x9000(%esi),%ecx # 0x99000 typical
|
||||
// movl %ecx,-8(%ecx) # 32-bit offset for stack pointer
|
||||
// movl %eax,-4(%ecx) # segment for stack pointer
|
||||
// lss -8(%ecx),%esp # %ss:%esp= %ds:0x99000
|
||||
// /* Linux Documentation/i386/boot.txt "SAMPLE BOOT CONFIGURATION" says
|
||||
// 0x8000-0x8FFF Stack and heap [inside the "real mode segment",
|
||||
// just below the command line at offset 0x9000].
|
||||
//
|
||||
// arch/i386/boot/compressed/head.S "Do the decompression ..." says
|
||||
// %esi contains the "real mode pointer" [as a 32-bit addr].
|
||||
// arch/i386/boot/compressed/head.S "Do the decompression ..." says
|
||||
// %esi contains the "real mode pointer" [as a 32-bit addr].
|
||||
//
|
||||
// In any case, avoid EBDA (Extended BIOS Data Area) below 0xA0000.
|
||||
// boot.txt says 0x9A000 is the limit. LILO goes up to 0x9B000.
|
||||
// */
|
||||
// In any case, avoid EBDA (Extended BIOS Data Area) below 0xA0000.
|
||||
// boot.txt says 0x9A000 is the limit. LILO goes up to 0x9B000.
|
||||
// */
|
||||
//
|
||||
// pushl $0; popf # subsumes "cli; cld"; also clears NT for buggy BIOS
|
||||
// pushl $0; popf # subsumes "cli; cld"; also clears NT for buggy BIOS
|
||||
//
|
||||
// movl $ 0x100000,%eax # destination of uncompression (and entry point)
|
||||
// push %cs
|
||||
// movl $ 0x100000,%eax # destination of uncompression (and entry point)
|
||||
// push %cs
|
||||
/* Fall into .text of upx-compressed vmlinux. */
|
||||
//-----
|
||||
|
||||
@@ -550,17 +550,17 @@ void PackVmlinuxI386::unpack(OutputFile *fo)
|
||||
//all: vmlinux
|
||||
//
|
||||
//vmlinux: upx-piggy.o $(OBJECTS)
|
||||
// $(LD) $(ZLINKFLAGS) -o vmlinux $(OBJECTS) upx-piggy.o
|
||||
// $(LD) $(ZLINKFLAGS) -o vmlinux $(OBJECTS) upx-piggy.o
|
||||
//
|
||||
//bvmlinux: upx-piggy.o $(OBJECTS)
|
||||
// $(LD) $(BZLINKFLAGS) -o bvmlinux $(OBJECTS) upx-piggy.o
|
||||
// $(LD) $(BZLINKFLAGS) -o bvmlinux $(OBJECTS) upx-piggy.o
|
||||
//
|
||||
//upx-piggy.o: $(SYSTEM)
|
||||
// $(RM) -f $@
|
||||
// upx --best -o $@ $<
|
||||
//upx-piggy.o: $(SYSTEM)
|
||||
// $(RM) -f $@
|
||||
// upx --best -o $@ $<
|
||||
//
|
||||
//clean:
|
||||
// rm -f vmlinux bvmlinux _tmp_*
|
||||
// rm -f vmlinux bvmlinux _tmp_*
|
||||
//-----
|
||||
|
||||
//
|
||||
@@ -579,7 +579,7 @@ void PackVmlinuxI386::unpack(OutputFile *fo)
|
||||
// $ # Compare file 'dumped' with the portion of vmlinux that made piggy.o.
|
||||
// $ dd if=vmlinux bs=<leader_size> skip=1 | cmp - dumped
|
||||
// cmp: EOF on dumped
|
||||
// $
|
||||
// $
|
||||
//----- test-piggy.S
|
||||
//#include <asm/mman.h>
|
||||
//#include <asm/unistd.h>
|
||||
|
||||
+6
-6
@@ -60,12 +60,12 @@ protected:
|
||||
|
||||
int n_ptload;
|
||||
unsigned sz_ptload;
|
||||
Elf_LE32_Phdr *phdri; // from input file
|
||||
Elf_LE32_Shdr *shdri; // 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
|
||||
Elf32_Phdr *phdri; // from input file
|
||||
Elf32_Shdr *shdri; // from input file
|
||||
Elf32_Shdr *p_text;
|
||||
Elf32_Shdr *p_note0;
|
||||
Elf32_Shdr *p_note1;
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
};
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ int PackVmlinuzI386::buildLoader(const Filter *ft)
|
||||
addLoader("LZCALLT9", NULL);
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUZ990""IDENTSTR""UPX1HEAD", NULL);
|
||||
addLoader("LINUZ990,IDENTSTR,UPX1HEAD", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -319,10 +319,10 @@ int PackBvmlinuzI386::buildLoader(const Filter *ft)
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
addLoader("LINUZ000",
|
||||
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
|
||||
"LBZIMAGE""IDENTSTR",
|
||||
"LBZIMAGE,IDENTSTR",
|
||||
"+40D++++", // align the stuff to 4 byte boundary
|
||||
"UPX1HEAD", // 32 byte
|
||||
"LZCUTPOI""+0000000",
|
||||
"LZCUTPOI,+0000000",
|
||||
getDecompressor(),
|
||||
NULL
|
||||
);
|
||||
|
||||
+125
-28
@@ -2,8 +2,8 @@
|
||||
|
||||
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) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -152,12 +152,16 @@ PackW32Pe::PackW32Pe(InputFile *f) : super(f)
|
||||
otls = NULL;
|
||||
oresources = NULL;
|
||||
oxrelocs = NULL;
|
||||
oloadconf = NULL;
|
||||
icondir_offset = 0;
|
||||
icondir_count = 0;
|
||||
importbyordinal = false;
|
||||
kernel32ordinal = false;
|
||||
tlsindex = 0;
|
||||
big_relocs = 0;
|
||||
soloadconf = 0;
|
||||
use_dep_hack = true;
|
||||
use_clear_dirty_stack = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +175,7 @@ PackW32Pe::~PackW32Pe()
|
||||
delete [] otls;
|
||||
delete [] oresources;
|
||||
delete [] oxrelocs;
|
||||
delete [] oloadconf;
|
||||
//delete res;
|
||||
}
|
||||
|
||||
@@ -544,7 +549,9 @@ void PackW32Pe::processImports(unsigned myimport) // pass 2
|
||||
unsigned PackW32Pe::processImports() // pass 1
|
||||
{
|
||||
static const unsigned char kernel32dll[] = "KERNEL32.DLL";
|
||||
static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0""GetProcAddress\x0\x0";
|
||||
static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0"
|
||||
"GetProcAddress\x0\x0"
|
||||
"VirtualProtect\x0\x0";
|
||||
static const char exitp[] = "ExitProcess\x0\x0\x0";
|
||||
|
||||
unsigned dllnum = 0;
|
||||
@@ -648,7 +655,7 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
im = (import_desc*) oimpdlls;
|
||||
|
||||
LE32 *ordinals = (LE32*) (oimpdlls + (dllnum2 + 1) * sizeof(import_desc));
|
||||
LE32 *lookuptable = ordinals + 3 + k32o + (isdll ? 0 : 1);
|
||||
LE32 *lookuptable = ordinals + 4 + k32o + (isdll ? 0 : 1);
|
||||
upx_byte *dllnames = ((upx_byte*) lookuptable) + (dllnum2 - 1) * 8;
|
||||
upx_byte *importednames = dllnames + (dllnamelen &~ 1);
|
||||
|
||||
@@ -660,10 +667,11 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
strcpy(dllnames,kernel32dll);
|
||||
im->dllname = k32namepos;
|
||||
im->iat = ptr_diff(ordinals,oimpdlls);
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls);
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14;
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls); // LoadLibraryA
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14; // GetProcAddress
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14 + 16; // VirtualProtect
|
||||
if (!isdll)
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + sizeof(llgpa) - 3;
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + sizeof(llgpa) - 3; // ExitProcess
|
||||
dllnames += sizeof(kernel32dll);
|
||||
importednames += sizeof(llgpa) - 2 + (isdll ? 0 : sizeof(exitp) - 1);
|
||||
|
||||
@@ -758,7 +766,7 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
soimport = 0;
|
||||
|
||||
//OutputFile::dump("x0.imp", oimport, soimport);
|
||||
//OutputFile::dump("x1.imp", oimpdlls, soimpdlss);
|
||||
//OutputFile::dump("x1.imp", oimpdlls, soimpdlls);
|
||||
|
||||
unsigned ilen = 0;
|
||||
names.flatten();
|
||||
@@ -1475,6 +1483,52 @@ void PackW32Pe::processResources(Resource *res)
|
||||
info("Resources: compressed %u (%u bytes), not compressed %u (%u bytes)",cnum,csize,unum,usize);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
// Load Configuration handling
|
||||
**************************************************************************/
|
||||
|
||||
void PackW32Pe::processLoadConf(Interval *iv) // pass 1
|
||||
{
|
||||
if (IDSIZE(PEDIR_LOADCONF) == 0)
|
||||
return;
|
||||
|
||||
const unsigned lcaddr = IDADDR(PEDIR_LOADCONF);
|
||||
const upx_byte * const loadconf = ibuf + lcaddr;
|
||||
soloadconf = get_le32(loadconf);
|
||||
if (soloadconf == 0)
|
||||
return;
|
||||
if (soloadconf > 256)
|
||||
throwCantPack("size of Load Configuration directory unexpected");
|
||||
|
||||
// if there were relocation entries referring to the load config table
|
||||
// then we need them for the copy of the table too
|
||||
unsigned pos,type;
|
||||
Reloc rel(ibuf + IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC));
|
||||
while (rel.next(pos, type))
|
||||
if (pos >= lcaddr && pos < lcaddr + soloadconf)
|
||||
{
|
||||
iv->add(pos - lcaddr, type);
|
||||
// printf("loadconf reloc detected: %x\n", pos);
|
||||
}
|
||||
|
||||
oloadconf = new upx_byte[soloadconf];
|
||||
memcpy(oloadconf, loadconf, soloadconf);
|
||||
}
|
||||
|
||||
void PackW32Pe::processLoadConf(Reloc *rel, const Interval *iv,
|
||||
unsigned newaddr) // pass2
|
||||
{
|
||||
// now we have the address of the new load config table
|
||||
// so we can create the new relocation entries
|
||||
for (unsigned ic = 0; ic < iv->ivnum; ic++)
|
||||
{
|
||||
rel->add(iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
||||
//printf("loadconf reloc added: %x %d\n",
|
||||
// iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
unsigned PackW32Pe::virta2objnum(unsigned addr,pe_section_t *sect,unsigned objs)
|
||||
{
|
||||
@@ -1579,7 +1633,7 @@ int PackW32Pe::buildLoader(const Filter *ft)
|
||||
if (sorelocs)
|
||||
{
|
||||
addLoader(soimport == 0 || soimport + cimports != crelocs ? "PERELOC1" : "PERELOC2",
|
||||
"PERELOC3""RELOC320",
|
||||
"PERELOC3,RELOC320",
|
||||
big_relocs ? "REL32BIG" : "",
|
||||
"RELOC32J",
|
||||
NULL
|
||||
@@ -1591,9 +1645,14 @@ int PackW32Pe::buildLoader(const Filter *ft)
|
||||
NULL
|
||||
);
|
||||
}
|
||||
addLoader("PEMAIN20",
|
||||
ih.entry ? "PEDOJUMP" : "PERETURN",
|
||||
"IDENTSTR""UPX1HEAD",
|
||||
if (use_dep_hack)
|
||||
addLoader("PEDEPHAK", NULL);
|
||||
addLoader("PEMAIN20", NULL);
|
||||
if (use_clear_dirty_stack)
|
||||
addLoader(ih.entry ? "PEDOJUMP_CLEARSTACK" : "PERETURN_CLEARSTACK", NULL);
|
||||
addLoader("PEMAIN21", NULL);
|
||||
addLoader(ih.entry ? "PEDOJUMP" : "PERETURN",
|
||||
"IDENTSTR,UPX1HEAD",
|
||||
NULL
|
||||
);
|
||||
return getLoaderSize();
|
||||
@@ -1602,9 +1661,6 @@ int PackW32Pe::buildLoader(const Filter *ft)
|
||||
|
||||
void PackW32Pe::pack(OutputFile *fo)
|
||||
{
|
||||
if (opt->win32_pe.strip_loadconf < 0)
|
||||
opt->win32_pe.strip_loadconf = false;
|
||||
|
||||
const unsigned objs = ih.objects;
|
||||
isection = new pe_section_t[objs];
|
||||
fi->seek(pe_offset+sizeof(ih),SEEK_SET);
|
||||
@@ -1633,10 +1689,6 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
if (IDSIZE(PEDIR_COMRT))
|
||||
throwCantPack(".NET files (win32/net) are not yet supported");
|
||||
|
||||
// Structured Exception Handling
|
||||
if (!opt->win32_pe.strip_loadconf && IDSIZE(PEDIR_LOADCONF))
|
||||
throwCantPack("Structured Exception Handling present (try --strip-loadconf)");
|
||||
|
||||
if (isdll)
|
||||
opt->win32_pe.strip_relocs = false;
|
||||
else if (opt->win32_pe.strip_relocs < 0)
|
||||
@@ -1660,7 +1712,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
|
||||
handleStub(fi,fo,pe_offset);
|
||||
const unsigned usize = ih.imagesize;
|
||||
const unsigned xtrasize = 65536+IDSIZE(PEDIR_IMPORT)+IDSIZE(PEDIR_BOUNDIM)+IDSIZE(PEDIR_IAT)+IDSIZE(PEDIR_DELAYIMP)+IDSIZE(PEDIR_RELOC);
|
||||
const unsigned xtrasize = UPX_MAX(ih.datasize, 65536u) + IDSIZE(PEDIR_IMPORT) + IDSIZE(PEDIR_BOUNDIM) + IDSIZE(PEDIR_IAT) + IDSIZE(PEDIR_DELAYIMP) + IDSIZE(PEDIR_RELOC);
|
||||
ibuf.alloc(usize + xtrasize);
|
||||
|
||||
// BOUND IMPORT support. FIXME: is this ok?
|
||||
@@ -1697,6 +1749,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
jc = isection[ic].vsize;
|
||||
if (isection[ic].vsize == 0) // hack for some tricky programs - may this break other progs?
|
||||
jc = isection[ic].vsize = isection[ic].size;
|
||||
if (isection[ic].vaddr + jc > ibuf.getSize())
|
||||
throwInternalError("buffer too small 1");
|
||||
fi->readx(ibuf + isection[ic].vaddr,jc);
|
||||
jc += isection[ic].rawdataptr;
|
||||
}
|
||||
@@ -1720,12 +1774,14 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
|
||||
Resource res;
|
||||
Interval tlsiv(ibuf);
|
||||
Interval loadconfiv(ibuf);
|
||||
Export xport((char*)(unsigned char*)ibuf);
|
||||
|
||||
const unsigned dllstrings = processImports();
|
||||
processTls(&tlsiv); // call before processRelocs!!
|
||||
processResources(&res);
|
||||
processExports(&xport);
|
||||
processLoadConf(&loadconfiv);
|
||||
processRelocs();
|
||||
|
||||
//OutputFile::dump("x1", ibuf, usize);
|
||||
@@ -1748,6 +1804,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
unsigned newvsize = (isection[objs-1].vaddr + isection[objs-1].vsize + oam1) &~ oam1;
|
||||
|
||||
//fprintf(stderr,"newvsize=%x objs=%d\n",newvsize,objs);
|
||||
if (newvsize + soimport + sorelocs > ibuf.getSize())
|
||||
throwInternalError("buffer too small 2");
|
||||
memcpy(ibuf+newvsize,oimport,soimport);
|
||||
memcpy(ibuf+newvsize+soimport,orelocs,sorelocs);
|
||||
|
||||
@@ -1846,6 +1904,38 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
unsigned jmp_pos = find_le32(loader,codesize + 4,get_le32("JMPO"));
|
||||
patch_le32(loader,codesize + 4,"JMPO",ih.entry - upxsection - jmp_pos - 4);
|
||||
}
|
||||
if (use_dep_hack)
|
||||
{
|
||||
// This works around a "protection" introduced in MSVCRT80, which
|
||||
// works like this:
|
||||
// When the compiler detects that it would link in some code from its
|
||||
// C runtime library which references some data in a read only
|
||||
// section then it compiles in a runtime check whether that data is
|
||||
// still in a read only section by looking at the pe header of the
|
||||
// file. If this check fails the runtime does "interesting" things
|
||||
// like not running the floating point initialization code - the result
|
||||
// is an R6002 runtime error.
|
||||
// These supposed to be read only addresses are covered by the section
|
||||
// UPX0 in the compressed files, so we have to patch the PE header
|
||||
// in the memory. And the page on which the PE header is stored is read
|
||||
// only so we must make it rw, fix the flag (i.e. clear
|
||||
// PEFL_WRITE of osection[0].flags), and make it ro again.
|
||||
|
||||
// rva of the most significant byte of member "flags" in section "UPX0"
|
||||
const unsigned swri = pe_offset + sizeof(oh) + sizeof(pe_section_t) - 1;
|
||||
#if 0
|
||||
if (swri >= 0x1000)
|
||||
throwCantPack("swri >= 0x1000! Send a bug report please!");
|
||||
patch_le32(loader, codesize, "SWRI", swri);
|
||||
patch_le32(loader, codesize, "IMGB", 0u - rvamin);
|
||||
#else
|
||||
// make sure we only touch exactly one page
|
||||
const unsigned addr = 0u - rvamin + swri;
|
||||
patch_le32(loader, codesize, "SWRI", addr & 0xfff); // page offset
|
||||
patch_le32(loader, codesize, "IMGB", addr &~ 0xfff); // page mask
|
||||
#endif
|
||||
patch_le32(loader, codesize, "VPRO", myimport + get_le32(oimpdlls + 16) + 8);
|
||||
}
|
||||
if (big_relocs & 6)
|
||||
patch_le32(loader,codesize,"DELT", 0u - (unsigned) ih.imagebase - rvamin);
|
||||
if (sorelocs && (soimport == 0 || soimport + cimports != crelocs))
|
||||
@@ -1853,7 +1943,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
if (soimport)
|
||||
{
|
||||
if (!isdll)
|
||||
patch_le32(loader,codesize,"EXIT",myimport + get_le32(oimpdlls + 16) + 8);
|
||||
patch_le32(loader,codesize,"EXIT",myimport + get_le32(oimpdlls + 16) + 12);
|
||||
patch_le32(loader,codesize,"GETP",myimport + get_le32(oimpdlls + 16) + 4);
|
||||
if (kernel32ordinal)
|
||||
patch_le32(loader,codesize,"K32O",myimport);
|
||||
@@ -1911,12 +2001,6 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
ODADDR(PEDIR_BOUNDIM) = 0;
|
||||
ODSIZE(PEDIR_BOUNDIM) = 0;
|
||||
|
||||
if (opt->win32_pe.strip_loadconf)
|
||||
{
|
||||
ODADDR(PEDIR_LOADCONF) = 0;
|
||||
ODSIZE(PEDIR_LOADCONF) = 0;
|
||||
}
|
||||
|
||||
// tls is put into section 1
|
||||
|
||||
ic = s1addr + s1size - sotls;
|
||||
@@ -1933,10 +2017,12 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
ODADDR(PEDIR_RESOURCE) = soresources ? ic : 0;
|
||||
ODSIZE(PEDIR_RESOURCE) = soresources;
|
||||
ic += soresources;
|
||||
|
||||
processImports(ic);
|
||||
ODADDR(PEDIR_IMPORT) = ic;
|
||||
ODSIZE(PEDIR_IMPORT) = soimpdlls;
|
||||
ic += soimpdlls;
|
||||
|
||||
processExports(&xport,ic);
|
||||
ODADDR(PEDIR_EXPORT) = soexport ? ic : 0;
|
||||
ODSIZE(PEDIR_EXPORT) = soexport;
|
||||
@@ -1946,13 +2032,20 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT);
|
||||
}
|
||||
ic += soexport;
|
||||
|
||||
processLoadConf(&rel, &loadconfiv, ic);
|
||||
ODADDR(PEDIR_LOADCONF) = soloadconf ? ic : 0;
|
||||
ODSIZE(PEDIR_LOADCONF) = soloadconf;
|
||||
ic += soloadconf;
|
||||
|
||||
processRelocs(&rel);
|
||||
ODADDR(PEDIR_RELOC) = soxrelocs ? ic : 0;
|
||||
ODSIZE(PEDIR_RELOC) = soxrelocs;
|
||||
ic += soxrelocs;
|
||||
|
||||
// this is computed here, because soxrelocs changes some lines above
|
||||
const unsigned ncsize = soresources + soimpdlls + soexport + soxrelocs;
|
||||
const unsigned ncsize = soresources + soimpdlls + soexport + soloadconf
|
||||
+ soxrelocs;
|
||||
ic = oh.filealign - 1;
|
||||
|
||||
// this one is tricky: it seems windoze touches 4 bytes after
|
||||
@@ -2026,6 +2119,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
fo->write(obuf,clen);
|
||||
infoWriting("compressed data", clen);
|
||||
fo->write(loader,codesize);
|
||||
if (opt->debug.dump_stub_loader)
|
||||
OutputFile::dump(opt->debug.dump_stub_loader, loader, codesize);
|
||||
if ((ic = fo->getBytesWritten() & 3) != 0)
|
||||
fo->write(ibuf,4 - ic);
|
||||
fo->write(otls,sotls);
|
||||
@@ -2034,6 +2129,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
fo->write(oresources,soresources);
|
||||
fo->write(oimpdlls,soimpdlls);
|
||||
fo->write(oexport,soexport);
|
||||
fo->write(oloadconf, soloadconf);
|
||||
fo->write(oxrelocs,soxrelocs);
|
||||
|
||||
if ((ic = fo->getBytesWritten() & (oh.filealign-1)) != 0)
|
||||
@@ -2050,6 +2146,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
printf("%-13s: imports : %8ld bytes\n", getName(), (long) soimpdlls);
|
||||
printf("%-13s: exports : %8ld bytes\n", getName(), (long) soexport);
|
||||
printf("%-13s: relocs : %8ld bytes\n", getName(), (long) soxrelocs);
|
||||
printf("%-13s: loadconf : %8ld bytes\n", getName(), (long) soloadconf);
|
||||
#endif
|
||||
|
||||
// verify
|
||||
|
||||
+10
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
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) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -119,6 +119,14 @@ protected:
|
||||
unsigned crelocs; // rva of preprocessed fixups
|
||||
int big_relocs;
|
||||
|
||||
void processLoadConf(PackW32Pe_Reloc *, const PackW32Pe_Interval *, unsigned);
|
||||
void processLoadConf(PackW32Pe_Interval *);
|
||||
upx_byte *oloadconf;
|
||||
unsigned soloadconf;
|
||||
|
||||
bool use_dep_hack;
|
||||
bool use_clear_dirty_stack;
|
||||
|
||||
struct pe_header_t
|
||||
{
|
||||
// 0x0
|
||||
|
||||
+4
-4
@@ -48,8 +48,8 @@ static const
|
||||
#define LE_STUB_EDI (1)
|
||||
|
||||
#ifdef TESTING
|
||||
# define dputc(x,y) do { if (opt->debug) putc(x,y); } while (0)
|
||||
# define Opt_debug opt->debug
|
||||
# define dputc(x,y) do { if (opt->debug.debug_level) putc(x,y); } while (0)
|
||||
# define Opt_debug opt->debug.debug_level
|
||||
#else
|
||||
# define dputc(x,y) ((void)0)
|
||||
# define Opt_debug 0
|
||||
@@ -85,7 +85,7 @@ int PackWcle::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
addLoader("IDENTSTR""WCLEMAIN""UPX1HEAD""WCLECUTP""+0000000",
|
||||
addLoader("IDENTSTR,WCLEMAIN,UPX1HEAD,WCLECUTP,+0000000",
|
||||
getDecompressor(),
|
||||
"WCLEMAI2",
|
||||
NULL
|
||||
@@ -99,7 +99,7 @@ int PackWcle::buildLoader(const Filter *ft)
|
||||
#if 1
|
||||
// FIXME: if (has_relocation)
|
||||
{
|
||||
addLoader("WCRELOC1""RELOC320",
|
||||
addLoader("WCRELOC1,RELOC320",
|
||||
big_relocs ? "REL32BIG" : "",
|
||||
"RELOC32J",
|
||||
NULL
|
||||
|
||||
+192
-46
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const
|
||||
**************************************************************************/
|
||||
|
||||
void Packer::decompress(const upx_bytep in, upx_bytep out,
|
||||
bool verify_checksum)
|
||||
bool verify_checksum, Filter *fp)
|
||||
{
|
||||
unsigned adler;
|
||||
|
||||
@@ -316,6 +316,9 @@ void Packer::decompress(const upx_bytep in, upx_bytep out,
|
||||
// verify checksum of decompressed data
|
||||
if (verify_checksum)
|
||||
{
|
||||
if (fp) {
|
||||
fp->unfilter(out, ph.u_len);
|
||||
}
|
||||
adler = upx_adler32(out, ph.u_len, ph.saved_u_adler);
|
||||
if (adler != ph.u_adler)
|
||||
throwChecksumError();
|
||||
@@ -339,9 +342,9 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
||||
return false;
|
||||
|
||||
assert((int)overlap_overhead >= 0);
|
||||
// Because we are not using the asm_fast decompressor here
|
||||
// we must account for extra 3 bytes or else we may fail
|
||||
// at runtime decompression.
|
||||
// Because upx_test_overlap() does not use the asm_fast decompressor
|
||||
// we must account for extra 3 bytes that asm_fast does use,
|
||||
// or else we may fail at runtime decompression.
|
||||
if (overlap_overhead <= 4 + 3) // don't waste time here
|
||||
return false;
|
||||
overlap_overhead -= 3;
|
||||
@@ -355,7 +358,7 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
||||
}
|
||||
|
||||
|
||||
void Packer::verifyOverlappingDecompression()
|
||||
void Packer::verifyOverlappingDecompression(Filter *fp)
|
||||
{
|
||||
assert(ph.c_len < ph.u_len);
|
||||
assert((int)ph.overlap_overhead > 0);
|
||||
@@ -381,7 +384,7 @@ void Packer::verifyOverlappingDecompression()
|
||||
if (offset + ph.c_len > obuf.getSize())
|
||||
return;
|
||||
memmove(obuf + offset, obuf, ph.c_len);
|
||||
decompress(obuf + offset, obuf, true);
|
||||
decompress(obuf + offset, obuf, true, fp);
|
||||
obuf.checkState();
|
||||
#endif /* !UNUPX */
|
||||
}
|
||||
@@ -812,7 +815,26 @@ int Packer::patchVersion(void *b, int blen)
|
||||
checkPatch(b, blen, boff, 14);
|
||||
|
||||
unsigned char *p = (unsigned char *)b + boff + 9;
|
||||
memcpy(p, UPX_VERSION_STRING4, 4);
|
||||
if (opt->debug.fake_stub_version[0])
|
||||
memcpy(p, opt->debug.fake_stub_version, 4);
|
||||
else
|
||||
memcpy(p, UPX_VERSION_STRING4, 4);
|
||||
|
||||
return boff;
|
||||
}
|
||||
|
||||
|
||||
// patch year into stub/ident_[ns].ash
|
||||
int Packer::patchVersionYear(void *b, int blen)
|
||||
{
|
||||
int boff = find(b, blen, " 1996-UPXY ", 11);
|
||||
checkPatch(b, blen, boff, 11);
|
||||
|
||||
unsigned char *p = (unsigned char *)b + boff + 6;
|
||||
if (opt->debug.fake_stub_year[0])
|
||||
memcpy(p, opt->debug.fake_stub_year, 4);
|
||||
else
|
||||
memcpy(p, UPX_VERSION_YEAR, 4);
|
||||
|
||||
return boff;
|
||||
}
|
||||
@@ -920,7 +942,7 @@ unsigned Packer::unoptimizeReloc32(upx_byte **in, upx_byte *image,
|
||||
|
||||
bool Packer::isValidCompressionMethod(int method)
|
||||
{
|
||||
return (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16);
|
||||
return (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16);
|
||||
}
|
||||
|
||||
|
||||
@@ -929,6 +951,7 @@ const int *Packer::getDefaultCompressionMethods_8(int method, int level, int sma
|
||||
static const int m_nrv2b[] = { M_NRV2B_8, M_NRV2D_8, M_NRV2E_8, -1 };
|
||||
static const int m_nrv2d[] = { M_NRV2D_8, M_NRV2B_8, M_NRV2E_8, -1 };
|
||||
static const int m_nrv2e[] = { M_NRV2E_8, M_NRV2B_8, M_NRV2D_8, -1 };
|
||||
static const int m_cl1b[] = { M_CL1B_8, -1 };
|
||||
|
||||
if (small < 0)
|
||||
small = file_size <= 512*1024;
|
||||
@@ -938,6 +961,8 @@ const int *Packer::getDefaultCompressionMethods_8(int method, int level, int sma
|
||||
return m_nrv2d;
|
||||
if (M_IS_NRV2E(method))
|
||||
return m_nrv2e;
|
||||
if (M_IS_CL1B(method))
|
||||
return m_cl1b;
|
||||
if (level == 1 || small)
|
||||
return m_nrv2b;
|
||||
return m_nrv2e;
|
||||
@@ -949,6 +974,7 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
|
||||
static const int m_nrv2b[] = { M_NRV2B_LE32, M_NRV2D_LE32, M_NRV2E_LE32, -1 };
|
||||
static const int m_nrv2d[] = { M_NRV2D_LE32, M_NRV2B_LE32, M_NRV2E_LE32, -1 };
|
||||
static const int m_nrv2e[] = { M_NRV2E_LE32, M_NRV2B_LE32, M_NRV2D_LE32, -1 };
|
||||
static const int m_cl1b[] = { M_CL1B_LE32, -1 };
|
||||
|
||||
if (small < 0)
|
||||
small = file_size <= 512*1024;
|
||||
@@ -958,6 +984,8 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
|
||||
return m_nrv2d;
|
||||
if (M_IS_NRV2E(method))
|
||||
return m_nrv2e;
|
||||
if (M_IS_CL1B(method))
|
||||
return m_cl1b;
|
||||
if (level == 1 || small)
|
||||
return m_nrv2b;
|
||||
return m_nrv2e;
|
||||
@@ -970,21 +998,43 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
|
||||
|
||||
char const *Packer::getIdentstr(unsigned *size, int small)
|
||||
{
|
||||
static const char identbig[] =
|
||||
static char identbig[] =
|
||||
"\n\0"
|
||||
"$Info: "
|
||||
"This file is packed with the UPX executable packer http://upx.sf.net $"
|
||||
"\n\0"
|
||||
"$Id: UPX "
|
||||
UPX_VERSION_STRING4
|
||||
" Copyright (C) 1996-2005 the UPX Team. All Rights Reserved. $"
|
||||
" Copyright (C) 1996-" UPX_VERSION_YEAR " the UPX Team. All Rights Reserved. $"
|
||||
"\n";
|
||||
static const char identsmall[] =
|
||||
static char identsmall[] =
|
||||
"\n"
|
||||
"$Id: UPX "
|
||||
"(C) 1996-2005 the UPX Team. All Rights Reserved. http://upx.sf.net $"
|
||||
"(C) 1996-" UPX_VERSION_YEAR " the UPX Team. All Rights Reserved. http://upx.sf.net $"
|
||||
"\n";
|
||||
static const char identtiny[] = UPX_VERSION_STRING4;
|
||||
static char identtiny[] = UPX_VERSION_STRING4;
|
||||
|
||||
static int done;
|
||||
if (!done && (opt->debug.fake_stub_version[0] || opt->debug.fake_stub_year[0]))
|
||||
{
|
||||
struct strinfo_t { char *s; int size; };
|
||||
static const strinfo_t strlist[] = {
|
||||
{ identbig, (int)sizeof(identbig) },
|
||||
{ identsmall, (int)sizeof(identsmall) },
|
||||
{ identtiny, (int)sizeof(identtiny) },
|
||||
{ NULL, 0 } };
|
||||
const strinfo_t* iter;
|
||||
|
||||
for (iter = strlist; iter->s; ++iter)
|
||||
{
|
||||
if (opt->debug.fake_stub_version[0])
|
||||
mem_replace(iter->s, iter->size, UPX_VERSION_STRING4, 4, opt->debug.fake_stub_version);
|
||||
if (opt->debug.fake_stub_year[0])
|
||||
mem_replace(iter->s, iter->size, UPX_VERSION_YEAR, 4, opt->debug.fake_stub_year);
|
||||
}
|
||||
done = 1;
|
||||
}
|
||||
|
||||
|
||||
if (small < 0)
|
||||
small = opt->small;
|
||||
@@ -1027,13 +1077,15 @@ void Packer::initLoader(const void *pdata, int plen, int pinfo, int small)
|
||||
|
||||
void __acc_cdecl_va Packer::addLoader(const char *s, ...)
|
||||
{
|
||||
const char *p;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, s);
|
||||
linker->addSection(s);
|
||||
while((p = va_arg(ap, const char *)) != NULL)
|
||||
linker->addSection(p);
|
||||
while (s != NULL)
|
||||
{
|
||||
if (*s)
|
||||
linker->addSection(s);
|
||||
s = va_arg(ap, const char *);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -1086,29 +1138,87 @@ int Packer::getLoaderSize() const
|
||||
const char *Packer::getDecompressor() const
|
||||
{
|
||||
static const char nrv2b_le32_small[] =
|
||||
"N2BSMA10""N2BDEC10""N2BSMA20""N2BDEC20""N2BSMA30"
|
||||
"N2BDEC30""N2BSMA40""N2BSMA50""N2BDEC50""N2BSMA60"
|
||||
"N2BSMA10,N2BDEC10,N2BSMA20,N2BDEC20,N2BSMA30,"
|
||||
"N2BDEC30,N2BSMA40,N2BSMA50,N2BDEC50,N2BSMA60,"
|
||||
"N2BDEC60";
|
||||
static const char nrv2b_le32_fast[] =
|
||||
"N2BFAS10""+80CXXXX""N2BFAS11""N2BDEC10""N2BFAS20"
|
||||
"N2BDEC20""N2BFAS30""N2BDEC30""N2BFAS40""N2BFAS50"
|
||||
"N2BDEC50""N2BFAS60""+40CXXXX""N2BFAS61""N2BDEC60";
|
||||
"N2BFAS10,+80CXXXX,N2BFAS11,N2BDEC10,N2BFAS20,"
|
||||
"N2BDEC20,N2BFAS30,N2BDEC30,N2BFAS40,N2BFAS50,"
|
||||
"N2BDEC50,N2BFAS60,+40CXXXX,N2BFAS61,N2BDEC60";
|
||||
static const char nrv2d_le32_small[] =
|
||||
"N2DSMA10""N2DDEC10""N2DSMA20""N2DDEC20""N2DSMA30"
|
||||
"N2DDEC30""N2DSMA40""N2DSMA50""N2DDEC50""N2DSMA60"
|
||||
"N2DSMA10,N2DDEC10,N2DSMA20,N2DDEC20,N2DSMA30,"
|
||||
"N2DDEC30,N2DSMA40,N2DSMA50,N2DDEC50,N2DSMA60,"
|
||||
"N2DDEC60";
|
||||
static const char nrv2d_le32_fast[] =
|
||||
"N2DFAS10""+80CXXXX""N2DFAS11""N2DDEC10""N2DFAS20"
|
||||
"N2DDEC20""N2DFAS30""N2DDEC30""N2DFAS40""N2DFAS50"
|
||||
"N2DDEC50""N2DFAS60""+40CXXXX""N2DFAS61""N2DDEC60";
|
||||
"N2DFAS10,+80CXXXX,N2DFAS11,N2DDEC10,N2DFAS20,"
|
||||
"N2DDEC20,N2DFAS30,N2DDEC30,N2DFAS40,N2DFAS50,"
|
||||
"N2DDEC50,N2DFAS60,+40CXXXX,N2DFAS61,N2DDEC60";
|
||||
static const char nrv2e_le32_small[] =
|
||||
"N2ESMA10""N2EDEC10""N2ESMA20""N2EDEC20""N2ESMA30"
|
||||
"N2EDEC30""N2ESMA40""N2ESMA50""N2EDEC50""N2ESMA60"
|
||||
"N2ESMA10,N2EDEC10,N2ESMA20,N2EDEC20,N2ESMA30,"
|
||||
"N2EDEC30,N2ESMA40,N2ESMA50,N2EDEC50,N2ESMA60,"
|
||||
"N2EDEC60";
|
||||
static const char nrv2e_le32_fast[] =
|
||||
"N2EFAS10""+80CXXXX""N2EFAS11""N2EDEC10""N2EFAS20"
|
||||
"N2EDEC20""N2EFAS30""N2EDEC30""N2EFAS40""N2EFAS50"
|
||||
"N2EDEC50""N2EFAS60""+40CXXXX""N2EFAS61""N2EDEC60";
|
||||
"N2EFAS10,+80CXXXX,N2EFAS11,N2EDEC10,N2EFAS20,"
|
||||
"N2EDEC20,N2EFAS30,N2EDEC30,N2EFAS40,N2EFAS50,"
|
||||
"N2EDEC50,N2EFAS60,+40CXXXX,N2EFAS61,N2EDEC60";
|
||||
static const char cl1b_le32_small[] =
|
||||
"CL1ENTER,CL1SMA10,CL1RLOAD,"
|
||||
"CL1WID01,CL1SMA1B,"
|
||||
"CL1WID02,CL1SMA1B,"
|
||||
"CL1WID03,CL1SMA1B,"
|
||||
"CL1WID04,CL1SMA1B,"
|
||||
"CL1WID05,CL1SMA1B,"
|
||||
"CL1WID06,CL1SMA1B,"
|
||||
"CL1WID07,CL1SMA1B,"
|
||||
"CL1WID08,CL1SMA1B,"
|
||||
"CL1WID09,CL1SMA1B,"
|
||||
"CL1WID10,"
|
||||
"CL1START,"
|
||||
"CL1TOP00,CL1SMA1B,"
|
||||
"CL1TOP01,CL1SMA1B,"
|
||||
"CL1TOP02,CL1SMA1B,"
|
||||
"CL1TOP03,CL1SMA1B,"
|
||||
"CL1TOP04,CL1SMA1B,"
|
||||
"CL1TOP05,CL1SMA1B,"
|
||||
"CL1TOP06,CL1SMA1B,"
|
||||
"CL1TOP07,CL1SMA1B,"
|
||||
"CL1OFF01,CL1SMA1B,"
|
||||
"CL1OFF02,CL1SMA1B,"
|
||||
"CL1OFF03,CL1SMA1B,"
|
||||
"CL1OFF04,"
|
||||
"CL1LEN00,CL1SMA1B,"
|
||||
"CL1LEN01,CL1SMA1B,"
|
||||
"CL1LEN02,"
|
||||
"CL1COPY0";
|
||||
static const char cl1b_le32_fast[] =
|
||||
"CL1ENTER," "CL1RLOAD,"
|
||||
"CL1WID01,CL1FAS1B,"
|
||||
"CL1WID02,CL1FAS1B,"
|
||||
"CL1WID03,CL1FAS1B,"
|
||||
"CL1WID04,CL1FAS1B,"
|
||||
"CL1WID05,CL1FAS1B,"
|
||||
"CL1WID06,CL1FAS1B,"
|
||||
"CL1WID07,CL1FAS1B,"
|
||||
"CL1WID08,CL1FAS1B,"
|
||||
"CL1WID09,CL1FAS1B,"
|
||||
"CL1WID10,"
|
||||
"CL1START,"
|
||||
"CL1TOP00,CL1FAS1B,"
|
||||
"CL1TOP01,CL1FAS1B,"
|
||||
"CL1TOP02,CL1FAS1B,"
|
||||
"CL1TOP03,CL1FAS1B,"
|
||||
"CL1TOP04,CL1FAS1B,"
|
||||
"CL1TOP05,CL1FAS1B,"
|
||||
"CL1TOP06,CL1FAS1B,"
|
||||
"CL1TOP07,CL1FAS1B,"
|
||||
"CL1OFF01,CL1FAS1B,"
|
||||
"CL1OFF02,CL1FAS1B,"
|
||||
"CL1OFF03,CL1FAS1B,"
|
||||
"CL1OFF04,"
|
||||
"CL1LEN00,CL1FAS1B,"
|
||||
"CL1LEN01,CL1FAS1B,"
|
||||
"CL1LEN02,"
|
||||
"CL1COPY0";
|
||||
|
||||
if (ph.method == M_NRV2B_LE32)
|
||||
return opt->small ? nrv2b_le32_small : nrv2b_le32_fast;
|
||||
@@ -1116,6 +1226,8 @@ const char *Packer::getDecompressor() const
|
||||
return opt->small ? nrv2d_le32_small : nrv2d_le32_fast;
|
||||
if (ph.method == M_NRV2E_LE32)
|
||||
return opt->small ? nrv2e_le32_small : nrv2e_le32_fast;
|
||||
if (ph.method == M_CL1B_LE32)
|
||||
return opt->small ? cl1b_le32_small : cl1b_le32_fast;
|
||||
throwInternalError("bad decompressor");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1149,13 +1261,32 @@ const char *Packer::getDecompressor() const
|
||||
// executable formats.
|
||||
//
|
||||
// It will replace the tryFilters() / compress() call sequence.
|
||||
|
||||
// 2006-02-15: hdr_buf and hdr_u_len are default empty input "header" array
|
||||
// to fix a 2-pass problem with Elf headers. As of today there can be
|
||||
// only one decompression method per executable output file, and that method
|
||||
// is the one that gives best compression for .text and loader. However,
|
||||
// the Elf headers precede .text in the output file, and are written first.
|
||||
// "--brute" compression often compressed the Elf headers using nrv2b
|
||||
// but the .text (and loader) with nrv2e. This often resulted in SIGSEGV
|
||||
// during decompression.
|
||||
// The workaround is for hdr_buf and hdr_u_len to describe the Elf headers
|
||||
// (typically less than 512 bytes) when .text is passed in, and include
|
||||
// them in the calculation of shortest output. Then the result
|
||||
// this->ph.method will say which [single] method to use for everthing.
|
||||
// The Elf headers are never filtered. They are short enough (< 512 bytes)
|
||||
// that compressing them more than once per method (once here when choosing,
|
||||
// once again just before writing [because compressWithFilters discards])
|
||||
// is OK because of the simplicity of not having two output arrays.
|
||||
**************************************************************************/
|
||||
|
||||
void Packer::compressWithFilters(Filter *parm_ft,
|
||||
const unsigned overlap_range,
|
||||
int strategy, const int *parm_filters,
|
||||
unsigned max_offset, unsigned max_match,
|
||||
unsigned filter_off, unsigned compress_buf_off)
|
||||
unsigned filter_off, unsigned compress_buf_off,
|
||||
unsigned char *hdr_buf,
|
||||
unsigned hdr_u_len)
|
||||
{
|
||||
const int *f;
|
||||
//
|
||||
@@ -1171,6 +1302,7 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
best_ph.c_len = orig_ph.u_len;
|
||||
best_ph.overlap_overhead = 0;
|
||||
unsigned best_ph_lsize = 0;
|
||||
unsigned best_hdr_clen = 0;
|
||||
|
||||
// preconditions
|
||||
assert(orig_ph.filter == 0);
|
||||
@@ -1250,11 +1382,11 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
}
|
||||
assert(nmethods > 0);
|
||||
|
||||
// update total_passes
|
||||
// update total_passes; previous (0 < ui_total_passes) means incremental
|
||||
if (strategy < 0)
|
||||
ui_total_passes += 1 * nmethods;
|
||||
ui_total_passes += 1 * nmethods - (0 < ui_total_passes);
|
||||
else
|
||||
ui_total_passes += nfilters * nmethods;
|
||||
ui_total_passes += nfilters * nmethods - (0 < ui_total_passes);
|
||||
|
||||
// Working buffer for compressed data. Don't waste memory.
|
||||
MemBuffer *otemp = &obuf;
|
||||
@@ -1264,6 +1396,19 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
int nfilters_success = 0;
|
||||
for (int m = 0; m < nmethods; m++) // for all methods
|
||||
{
|
||||
unsigned hdr_clen = 0;
|
||||
if (hdr_buf && hdr_u_len) {
|
||||
unsigned result[16];
|
||||
upx_compress_config_t conf;
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
if (0 < m && otemp == &obuf) { // do not overwrite obuf
|
||||
otemp_buf.allocForCompression(compress_buf_len);
|
||||
otemp = &otemp_buf;
|
||||
}
|
||||
int r = upx_compress(hdr_buf, hdr_u_len, *otemp, &hdr_clen,
|
||||
0, methods[m], 10, &conf, result);
|
||||
(void)r;
|
||||
}
|
||||
for (int i = 0; i < nfilters; i++) // for all filters
|
||||
{
|
||||
ibuf.checkState();
|
||||
@@ -1319,19 +1464,19 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
lsize = buildLoader(&ft);
|
||||
}
|
||||
#if 0
|
||||
printf("\n%2d %02x: %d +%4d = %d (best: %d +%4d = %d)\n", ph.method, ph.filter,
|
||||
ph.c_len, lsize, ph.c_len + lsize,
|
||||
best_ph.c_len, best_ph_lsize, best_ph.c_len + best_ph_lsize);
|
||||
printf("\n%2d %02x: %d +%4d +%3d = %d (best: %d +%4d +%3d = %d)\n", ph.method, ph.filter,
|
||||
ph.c_len, lsize, hdr_clen, ph.c_len + lsize + hdr_clen,
|
||||
best_ph.c_len, best_ph_lsize, best_hdr_clen, best_ph.c_len + best_ph_lsize + best_hdr_clen);
|
||||
#endif
|
||||
bool update = false;
|
||||
if (ph.c_len + lsize < best_ph.c_len + best_ph_lsize)
|
||||
if (ph.c_len + lsize + hdr_clen < best_ph.c_len + best_ph_lsize + best_hdr_clen)
|
||||
update = true;
|
||||
else if (ph.c_len + lsize == best_ph.c_len + best_ph_lsize)
|
||||
else if (ph.c_len + lsize + hdr_clen == best_ph.c_len + best_ph_lsize + best_hdr_clen)
|
||||
{
|
||||
// prefer smaller loaders
|
||||
if (lsize < best_ph_lsize)
|
||||
if (lsize + hdr_clen < best_ph_lsize + best_hdr_clen)
|
||||
update = true;
|
||||
else if (lsize == best_ph_lsize)
|
||||
else if (lsize + hdr_clen == best_ph_lsize + best_hdr_clen)
|
||||
{
|
||||
// prefer less overlap_overhead
|
||||
if (ph.overlap_overhead < best_ph.overlap_overhead)
|
||||
@@ -1346,6 +1491,7 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
// save compression results
|
||||
best_ph = ph;
|
||||
best_ph_lsize = lsize;
|
||||
best_hdr_clen = hdr_clen;
|
||||
best_ft = ft;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-4
@@ -160,8 +160,8 @@ protected:
|
||||
// main compression drivers
|
||||
virtual bool compress(upx_bytep in, upx_bytep out,
|
||||
unsigned max_offset = 0, unsigned max_match = 0);
|
||||
virtual void decompress(const upx_bytep in,
|
||||
upx_bytep out, bool verify_checksum=true);
|
||||
virtual void decompress(const upx_bytep in, upx_bytep out,
|
||||
bool verify_checksum = true, Filter *fp = 0);
|
||||
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
|
||||
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
|
||||
|
||||
@@ -172,7 +172,9 @@ protected:
|
||||
const int *filters = NULL,
|
||||
unsigned max_offset = 0, unsigned max_match = 0,
|
||||
unsigned filter_buf_off = 0,
|
||||
unsigned compress_buf_off = 0);
|
||||
unsigned compress_buf_off = 0,
|
||||
unsigned char *header_buffer = 0,
|
||||
unsigned header_length = 0);
|
||||
|
||||
// util for verifying overlapping decompresion
|
||||
// non-destructive test
|
||||
@@ -183,7 +185,7 @@ protected:
|
||||
unsigned range = 0,
|
||||
unsigned upper_limit = ~0u) const;
|
||||
// destructive decompress + verify
|
||||
virtual void verifyOverlappingDecompression();
|
||||
virtual void verifyOverlappingDecompression(Filter *fp = 0);
|
||||
|
||||
|
||||
// packheader handling
|
||||
@@ -208,7 +210,11 @@ protected:
|
||||
virtual const upx_byte *getLoader() const;
|
||||
virtual int getLoaderSize() const;
|
||||
virtual void initLoader(const void *pdata, int plen, int pinfo=-1, int small=-1);
|
||||
#if 1 && (ACC_CC_GNUC >= 0x040100)
|
||||
virtual void __acc_cdecl_va addLoader(const char *s, ...) __attribute__((__sentinel__));
|
||||
#else
|
||||
virtual void __acc_cdecl_va addLoader(const char *s, ...);
|
||||
#endif
|
||||
virtual int getLoaderSection(const char *name, int *slen=NULL) const;
|
||||
virtual int getLoaderSectionStart(const char *name, int *slen=NULL) const;
|
||||
virtual const char *getDecompressor() const;
|
||||
@@ -233,6 +239,7 @@ protected:
|
||||
int patch_le32(void *b, int blen, unsigned old, unsigned new_);
|
||||
int patch_le32(void *b, int blen, const void * old, unsigned new_);
|
||||
int patchVersion(void *b, int blen);
|
||||
int patchVersionYear(void *b, int blen);
|
||||
void checkPatch(void *b, int blen, int boff, int size);
|
||||
|
||||
// relocation util
|
||||
|
||||
+75
-75
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -133,21 +133,21 @@ void Packer::addFilter32(int filter_id)
|
||||
addLoader("CALLTR00",
|
||||
(filter_id > 0x20) ? "CTCLEVE1" : "",
|
||||
"CALLTR01",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01""CTBSWA01" : "CTBROR01""CTBSWA01") : "",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01,CTBSWA01" : "CTBROR01,CTBSWA01") : "",
|
||||
"CALLTR02",
|
||||
NULL
|
||||
);
|
||||
}
|
||||
else if (0x40==(0xF0 & filter_id)) {
|
||||
addLoader("CKLLTR00", 0);
|
||||
addLoader("CKLLTR00", NULL);
|
||||
if (9<=(0xf & filter_id)) {
|
||||
addLoader("CKLLTR10", 0);
|
||||
addLoader("CKLLTR10", NULL);
|
||||
}
|
||||
addLoader("CKLLTR20", 0);
|
||||
addLoader("CKLLTR20", NULL);
|
||||
if (9<=(0xf & filter_id)) {
|
||||
addLoader("CKLLTR30", 0);
|
||||
addLoader("CKLLTR30", NULL);
|
||||
}
|
||||
addLoader("CKLLTR40", 0);
|
||||
addLoader("CKLLTR40", NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -156,7 +156,7 @@ void Packer::addFilter32(int filter_id)
|
||||
"CALLTR11",
|
||||
(filter_id > 0x20) ? "CTCLEVE2" : "",
|
||||
"CALLTR12",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11""CTBSWA11" : "CTBROR11""CTBSWA11") : "",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11,CTBSWA11" : "CTBROR11,CTBSWA11") : "",
|
||||
"CALLTR13",
|
||||
NULL
|
||||
);
|
||||
@@ -170,187 +170,187 @@ void Packer::addFilter32(int filter_id)
|
||||
unsigned const f_jcc2 = f80_jcc2(filter_id);
|
||||
|
||||
if (NOFILT!=f_jcc2) {
|
||||
addLoader("LXJCC010", 0);
|
||||
addLoader("LXJCC010", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU045", 0);
|
||||
addLoader("LXMRU045", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU046", 0);
|
||||
addLoader("LXMRU046", NULL);
|
||||
}
|
||||
if (0==n_mru || MRUFLT!=f_jcc2) {
|
||||
addLoader("LXJCC020", 0);
|
||||
addLoader("LXJCC020", NULL);
|
||||
}
|
||||
else { // 0!=n_mru
|
||||
addLoader("LXJCC021", 0);
|
||||
addLoader("LXJCC021", NULL);
|
||||
}
|
||||
if (NOFILT!=f_jcc2) {
|
||||
addLoader("LXJCC023", 0);
|
||||
addLoader("LXJCC023", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXUNF037", 0);
|
||||
addLoader("LXUNF037", NULL);
|
||||
if (x386) {
|
||||
if (n_mru) {
|
||||
addLoader("LXUNF386", 0);
|
||||
addLoader("LXUNF386", NULL);
|
||||
}
|
||||
addLoader("LXUNF387", 0);
|
||||
addLoader("LXUNF387", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXUNF388", 0);
|
||||
addLoader("LXUNF388", NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
addLoader("LXUNF486", 0);
|
||||
addLoader("LXUNF486", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXUNF487", 0);
|
||||
addLoader("LXUNF487", NULL);
|
||||
}
|
||||
}
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU065", 0);
|
||||
addLoader("LXMRU065", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE3", 0);
|
||||
addLoader("MRUBYTE3", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB30", 0);
|
||||
addLoader("MRUARB30", NULL);
|
||||
if (mrupwr2) {
|
||||
addLoader("MRUBITS3", 0);
|
||||
addLoader("MRUBITS3", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB40", 0);
|
||||
addLoader("MRUARB40", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXMRU070", 0);
|
||||
addLoader("LXMRU070", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE4", 0);
|
||||
addLoader("MRUBYTE4", NULL);
|
||||
}
|
||||
else if (mrupwr2) {
|
||||
addLoader("MRUBITS4", 0);
|
||||
addLoader("MRUBITS4", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB50", 0);
|
||||
addLoader("MRUARB50", NULL);
|
||||
}
|
||||
addLoader("LXMRU080", 0);
|
||||
addLoader("LXMRU080", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE5", 0);
|
||||
addLoader("MRUBYTE5", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB60", 0);
|
||||
addLoader("MRUARB60", NULL);
|
||||
if (mrupwr2) {
|
||||
addLoader("MRUBITS5", 0);
|
||||
addLoader("MRUBITS5", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB70", 0);
|
||||
addLoader("MRUARB70", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXMRU090", 0);
|
||||
addLoader("LXMRU090", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE6", 0);
|
||||
addLoader("MRUBYTE6", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB80", 0);
|
||||
addLoader("MRUARB80", NULL);
|
||||
if (mrupwr2) {
|
||||
addLoader("MRUBITS6", 0);
|
||||
addLoader("MRUBITS6", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB90", 0);
|
||||
addLoader("MRUARB90", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXMRU100", 0);
|
||||
addLoader("LXMRU100", NULL);
|
||||
}
|
||||
addLoader("LXUNF040", 0);
|
||||
addLoader("LXUNF040", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU110", 0);
|
||||
addLoader("LXMRU110", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU111", 0);
|
||||
addLoader("LXMRU111", NULL);
|
||||
}
|
||||
addLoader("LXUNF041", 0);
|
||||
addLoader("LXUNF042", 0);
|
||||
addLoader("LXUNF041", NULL);
|
||||
addLoader("LXUNF042", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU010", 0);
|
||||
addLoader("LXMRU010", NULL);
|
||||
if (NOFILT!=f_jmp1 && NOFILT==f_call) {
|
||||
addLoader("LXJMPA00", 0);
|
||||
addLoader("LXJMPA00", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCALLB0", 0);
|
||||
addLoader("LXCALLB0", NULL);
|
||||
}
|
||||
addLoader("LXUNF021", 0);
|
||||
addLoader("LXUNF021", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU022", 0);
|
||||
addLoader("LXMRU022", NULL);
|
||||
if (NOFILT!=f_jmp1 && NOFILT==f_call) {
|
||||
addLoader("LXJMPA01", 0);
|
||||
addLoader("LXJMPA01", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCALLB1", 0);
|
||||
addLoader("LXCALLB1", NULL);
|
||||
}
|
||||
}
|
||||
if (n_mru) {
|
||||
if (256!=n_mru && mrupwr2) {
|
||||
addLoader("MRUBITS1", 0);
|
||||
addLoader("MRUBITS1", NULL);
|
||||
}
|
||||
addLoader("LXMRU030", 0);
|
||||
addLoader("LXMRU030", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE1", 0);
|
||||
addLoader("MRUBYTE1", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB10", 0);
|
||||
addLoader("MRUARB10", NULL);
|
||||
}
|
||||
addLoader("LXMRU040", 0);
|
||||
addLoader("LXMRU040", NULL);
|
||||
}
|
||||
|
||||
addLoader("LXUNF030", 0);
|
||||
addLoader("LXUNF030", NULL);
|
||||
if (NOFILT!=f_jcc2) {
|
||||
addLoader("LXJCC000", 0);
|
||||
addLoader("LXJCC000", NULL);
|
||||
}
|
||||
if (NOFILT!=f_call || NOFILT!=f_jmp1) { // at least one is filtered
|
||||
// shift opcode origin to zero
|
||||
if (0==n_mru) {
|
||||
addLoader("LXCJ0MRU", 0);
|
||||
addLoader("LXCJ0MRU", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCJ1MRU", 0);
|
||||
addLoader("LXCJ1MRU", NULL);
|
||||
}
|
||||
|
||||
// determine if in range
|
||||
if ((NOFILT!=f_call) && (NOFILT!=f_jmp1)) { // unfilter both
|
||||
addLoader("LXCALJMP", 0);
|
||||
addLoader("LXCALJMP", NULL);
|
||||
}
|
||||
if ((NOFILT==f_call) ^ (NOFILT==f_jmp1)) { // unfilter just one
|
||||
if (0==n_mru) {
|
||||
addLoader("LXCALL00", 0);
|
||||
addLoader("LXCALL00", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCALL01", 0);
|
||||
addLoader("LXCALL01", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// determine if mru applies
|
||||
if (0==n_mru || ! ((FNOMRU==f_call) || (FNOMRU==f_jmp1)) ) {
|
||||
addLoader("LXCJ2MRU", 0); // no mru, or no exceptions
|
||||
addLoader("LXCJ2MRU", NULL); // no mru, or no exceptions
|
||||
}
|
||||
else { // mru on one, but not the other
|
||||
addLoader("LXCJ4MRU", 0);
|
||||
addLoader("LXCJ4MRU", NULL);
|
||||
if (MRUFLT==f_jmp1) { // JMP only
|
||||
addLoader("LXCJ6MRU", 0);
|
||||
addLoader("LXCJ6MRU", NULL);
|
||||
} else
|
||||
if (MRUFLT==f_call) { // CALL only
|
||||
addLoader("LXCJ7MRU", 0);
|
||||
addLoader("LXCJ7MRU", NULL);
|
||||
}
|
||||
addLoader("LXCJ8MRU", 0);
|
||||
addLoader("LXCJ8MRU", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXUNF034", 0);
|
||||
addLoader("LXUNF034", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU055", 0);
|
||||
addLoader("LXMRU055", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE2", 0);
|
||||
addLoader("MRUBYTE2", NULL);
|
||||
}
|
||||
else if (mrupwr2) {
|
||||
addLoader("MRUBITS2", 0);
|
||||
addLoader("MRUBITS2", NULL);
|
||||
}
|
||||
else if (n_mru) {
|
||||
addLoader("MRUARB20", 0);
|
||||
addLoader("MRUARB20", NULL);
|
||||
}
|
||||
addLoader("LXMRU057", 0);
|
||||
addLoader("LXMRU057", NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "p_lx_elf.h"
|
||||
#include "p_lx_sep.h"
|
||||
#include "p_lx_sh.h"
|
||||
#include "p_lx_interp.h"
|
||||
#include "p_sys.h"
|
||||
#include "p_tos.h"
|
||||
#include "p_wcle.h"
|
||||
@@ -51,6 +52,8 @@
|
||||
#include "p_vmlinz.h"
|
||||
#include "p_vmlinx.h"
|
||||
#include "p_ps1.h"
|
||||
#include "p_mach.h"
|
||||
#include "p_armpe.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -168,6 +171,8 @@ static Packer* try_packers(InputFile *f, try_function func)
|
||||
#endif
|
||||
if ((p = func(new PackW16Ne(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackArmPe(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackW32Pe(f),f)) != NULL)
|
||||
return p;
|
||||
}
|
||||
@@ -206,6 +211,14 @@ static Packer* try_packers(InputFile *f, try_function func)
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
if (opt->o_unix.use_ptinterp) {
|
||||
if ((p = func(new PackLinuxI386interp(f),f)) != NULL)
|
||||
return p;
|
||||
}
|
||||
if ((p = func(new PackLinuxElf64amd(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackLinuxElf32ppc(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackLinuxI386elf(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackLinuxI386sh(f),f)) != NULL)
|
||||
@@ -228,6 +241,10 @@ static Packer* try_packers(InputFile *f, try_function func)
|
||||
if ((p = func(new PackCom(f),f)) != NULL)
|
||||
return p;
|
||||
|
||||
// Mach (MacOS X PowerPC)
|
||||
if ((p = func(new PackMachPPC32(f), f)) != NULL)
|
||||
return p;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
+5
-22
@@ -1,3 +1,5 @@
|
||||
.*-stamp
|
||||
*.ah
|
||||
*.asx
|
||||
*.asy
|
||||
*.bin
|
||||
@@ -5,31 +7,12 @@
|
||||
*.i
|
||||
*.lst
|
||||
*.map
|
||||
*.out
|
||||
*.o
|
||||
*.tmp
|
||||
GNUmakefile
|
||||
fold_elf86.h
|
||||
fold_exec86.h
|
||||
fold_sh86.h
|
||||
l_com.h
|
||||
l_djgpp2.h
|
||||
l_exe.h
|
||||
l_lx_elf86.h
|
||||
l_lx_exec86.h
|
||||
l_lx_sh86.h
|
||||
l_sys.h
|
||||
l_t_n2b.h
|
||||
l_t_n2bs.h
|
||||
l_t_n2d.h
|
||||
l_t_n2ds.h
|
||||
l_t_n2e.h
|
||||
l_t_n2es.h
|
||||
l_tmt.h
|
||||
l_vmlinx.h
|
||||
l_vmlinz.h
|
||||
l_w32pe.h
|
||||
l_wcle.h
|
||||
MMakefile
|
||||
stamp-h
|
||||
stubify.exe
|
||||
stubify.h
|
||||
upxb
|
||||
upxd
|
||||
|
||||
+209
-44
@@ -5,24 +5,34 @@
|
||||
# for required build tools
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
SHELL = /bin/sh
|
||||
|
||||
ifeq ($(strip $(UCLDIR)),)
|
||||
# change this to reflect where the UCL library is
|
||||
UCLDIR = $(HOME)/local/src/ucl-1.03
|
||||
endif
|
||||
ifeq ($(wildcard $(UCLDIR)/upx),)
|
||||
$(error Please set UCLDIR in Makefile or environment)
|
||||
endif
|
||||
|
||||
# update path for our special stub build tools
|
||||
ifneq ($(wildcard $(HOME)/local/bin/bin-upx),)
|
||||
export PATH := $(HOME)/local/bin/bin-upx:$(PATH)
|
||||
endif
|
||||
|
||||
|
||||
# -------------------------------------------------------
|
||||
# You should not have to change anything below this line.
|
||||
# -------------------------------------------------------
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = ../..
|
||||
|
||||
|
||||
# These are the files we want to create.
|
||||
STUBS = \
|
||||
l_armpe.h \
|
||||
l_com.h \
|
||||
l_djgpp2.h stubify.h \
|
||||
l_exe.h \
|
||||
@@ -35,6 +45,10 @@ STUBS = \
|
||||
l_lx_exec86.h fold_exec86.h \
|
||||
l_lx_elf86.h fold_elf86.h \
|
||||
l_lx_sh86.h fold_sh86.h \
|
||||
l_lx_pti86.h fold_pti86.h \
|
||||
l_lx_elfppc32.h fold_elfppc32.h \
|
||||
l_lx_elf64amd.h fold_elf64amd.h \
|
||||
l_mac_ppc32.h fold_machppc32.h \
|
||||
l_vmlinz.h l_vmlinx.h
|
||||
|
||||
# experimental:
|
||||
@@ -46,6 +60,10 @@ endif
|
||||
# util var for use in the rules - basename of the current target
|
||||
override T = $(basename $@)
|
||||
|
||||
ifneq ($(strip $(USE_MAKEFILE_DEPS)),)
|
||||
MAKEFILE_DEPS = $(MAKEFILE_LIST)
|
||||
endif
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // source directories
|
||||
@@ -68,7 +86,7 @@ vpath %.ash $(UCL_MR3K)
|
||||
# // tools
|
||||
# ************************************************************************/
|
||||
|
||||
NASM = nasm -O15 -w+macro-params -w+macro-selfref -w+number-overflow -w+orphan-labels
|
||||
NASM = nasm -O99 -w+macro-params -w+macro-selfref -w+number-overflow -w+orphan-labels
|
||||
NASM += -I$(srcdir)/
|
||||
|
||||
APP_I386 = perl -w $(srcdir)/scripts/app_i386.pl
|
||||
@@ -77,29 +95,34 @@ BIN2H = perl -w $(srcdir)/scripts/bin2h.pl
|
||||
BRANDELF = perl -w $(srcdir)/scripts/brandelf.pl
|
||||
O2BIN = perl -w $(srcdir)/scripts/o2bin.pl
|
||||
##STRIPELF = perl -w $(srcdir)/scripts/stripelf.pl
|
||||
STRIPELF = ./util/sstrip/sstrip
|
||||
|
||||
|
||||
###
|
||||
### linux/i386
|
||||
### i386-linux
|
||||
###
|
||||
|
||||
LD_LINUX_I386 = ld-2.13.2
|
||||
LD_LINUX_I386 = ld
|
||||
OBJCOPY_LINUX_I386 = objcopy
|
||||
LD_LINUX_I386 = ld-2.13.2 -m elf_i386
|
||||
LD_LINUX_I386 = ld -m elf_i386
|
||||
OBJCOPY_LINUX_I386 = objcopy -F elf32-i386
|
||||
OBJSTRIP_LINUX_I386 = $(OBJCOPY_LINUX_I386) -R .comment -R .note
|
||||
STRIPELF_LINUX_I386 = ./util/sstrip/i386-linux-sstrip
|
||||
|
||||
# gcc 2.7.2.3 (fold_*.bin: 1839 / 1011 / 1390)
|
||||
# gcc 2.7.2.3 (fold_*86.bin: 1839 / 1011 / xxxx / 1390)
|
||||
CC_LINUX_I386_GCC272 = gcc-2.72 -m386 -O2 -MMD
|
||||
CC_LINUX_I386_GCC272 += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
||||
|
||||
# gcc 2.95.3 (fold_*.bin: 1721 / 995 / 1321)
|
||||
# gcc 2.95.3 (fold_*86.bin: 1721 / 995 / xxxx / 1321)
|
||||
CC_LINUX_I386_GCC295 = gcc-2.95.3 -march=i386 -mcpu=k6 -fno-exceptions -MMD
|
||||
CC_LINUX_I386_GCC295 += -Os -fno-omit-frame-pointer
|
||||
CC_LINUX_I386_GCC295 += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
||||
CC_LINUX_I386_GCC295 += -Werror
|
||||
|
||||
# gcc 3.4.3 (fold_*.bin: 1624 / 931 / 1207)
|
||||
CC_LINUX_I386_GCC34 = gcc-3.4.3
|
||||
# gcc 3.4.5 (fold_*86.bin: 1670 / 947 / 1552 / 1212)
|
||||
# gcc 3.4.6 (fold_*86.bin: 1670 / 947 / 1552 / 1212) [unchanged from 3.4.5]
|
||||
# gcc 4.0.3 (fold_*86.bin: 1741 / 995 / 1639 / 1202)
|
||||
# gcc 4.1.0 (fold_*86.bin: 1644 / 947 / 1524 / 1144)
|
||||
## ==> TODO: upgrade to 4.1.0
|
||||
CC_LINUX_I386_GCC34 = gcc-3.4.5
|
||||
CC_LINUX_I386_GCC34 += -m32 -march=i386 -mtune=k6 -fno-exceptions -MMD
|
||||
CC_LINUX_I386_GCC34 += -Os -fno-omit-frame-pointer
|
||||
CC_LINUX_I386_GCC34 += -momit-leaf-frame-pointer
|
||||
@@ -142,6 +165,62 @@ else
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### PowerPC 32
|
||||
###
|
||||
|
||||
GCC_PPC32 := false
|
||||
LD_PPC32 := false
|
||||
OBJCOPY_PPC32 := false
|
||||
OBJSTRIP_PPC32 = $(OBJCOPY_PPC32) -R .comment -R .note
|
||||
|
||||
d = /home2/crosstool/powerpc-750-linux-gnu/gcc-3.4.1-glibc-20040827/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_PPC32 := $d/powerpc-750-linux-gnu-gcc -m32 -nostdinc -MMD
|
||||
LD_PPC32 := $d/powerpc-750-linux-gnu-ld
|
||||
OBJCOPY_PPC32 := $d/powerpc-750-linux-gnu-objcopy
|
||||
endif
|
||||
d = /opt/cc-i386-linux/crosstool/powerpc-750-linux-gnu/gcc-3.4.3.20050210-glibc-2.2.5/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_PPC32 := $d/powerpc-750-linux-gnu-gcc -m32 -nostdinc -MMD
|
||||
LD_PPC32 := $d/powerpc-750-linux-gnu-ld
|
||||
OBJCOPY_PPC32 := $d/powerpc-750-linux-gnu-objcopy
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### AMD x86_64
|
||||
###
|
||||
|
||||
GCC_AMD64 := false
|
||||
LD_AMD64 := false
|
||||
OBJCOPY_AMD64 := false
|
||||
OBJSTRIP_AMD64 = $(OBJCOPY_AMD64) -R .comment -R .note
|
||||
|
||||
d = /home2/crosstool/gcc-4.0.1-glibc-2.3.5/x86_64-unknown-linux-gnu/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_AMD64 := $d/x86_64-unknown-linux-gnu-gcc -m64 -nostdinc -MMD
|
||||
LD_AMD64 := $d/x86_64-unknown-linux-gnu-ld -m elf_x86_64
|
||||
OBJCOPY_AMD64 := $d/x86_64-unknown-linux-gnu-objcopy -F elf64-x86-64
|
||||
endif
|
||||
d = /opt/cc-i386-linux/crosstool/x86_64-unknown-linux-gnu/gcc-3.4.3.20050507-glibc-2.3.5/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_AMD64 := $d/x86_64-unknown-linux-gnu-gcc -m64 -nostdinc -MMD
|
||||
LD_AMD64 := $d/x86_64-unknown-linux-gnu-ld -m elf_x86_64
|
||||
OBJCOPY_AMD64 := $d/x86_64-unknown-linux-gnu-objcopy -F elf64-x86-64
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### ARM-PE-WINCE
|
||||
###
|
||||
|
||||
GCC_WINCE := arm-wince-pe-gcc -Os
|
||||
LD_WINCE := arm-wince-pe-ld
|
||||
OBJCOPY_WINCE := arm-wince-pe-objcopy
|
||||
BIN2H_WINCE := perl -ne 'print "db\t", join(",", map { sprintf "%\#02x", $$_ } unpack("C*", $$_)), "\n"'
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // main targets
|
||||
# ************************************************************************/
|
||||
@@ -240,7 +319,6 @@ l_w32pe.h: l_w32pe.asx
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
$(BIN2H) $T.bin nrv_loader $@
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // atari/tos rules
|
||||
# ************************************************************************/
|
||||
@@ -305,7 +383,7 @@ l_ps1c.h: l_ps1.asm
|
||||
|
||||
upx_itoa.o: upx_itoa.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_elf86.h: l_lx_elf86.asx
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
@@ -319,88 +397,167 @@ l_lx_sh86.h: l_lx_sh86.asx
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
$(BIN2H) $T.bin linux_i386sh_loader $@
|
||||
|
||||
l_lx_elf.o: l_lx_elf.c linux.hh
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
l_lx_pti86.h: l_lx_pti86.asx
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
$(BIN2H) $T.bin linux_i386pti_loader $@
|
||||
|
||||
l_lx_exec.o: l_lx_exec.c linux.hh
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
l_mac_ppc32.h: l_mac_ppc32.S ppc_d_nrv2e.S
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $T.o
|
||||
$(LD_PPC32) -o $T.bin --oformat binary $T.o
|
||||
$(BIN2H) $T.bin l_mac_ppc32_loader $@
|
||||
|
||||
l_lx_sep.o: l_lx_sep.c linux.hh
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
l_lx_elfppc32.h: l_lx_elfppc32.S ppc_d_nrv2e.S
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $T.o
|
||||
$(LD_PPC32) -o $T.bin --oformat binary $T.o
|
||||
$(BIN2H) $T.bin linux_elfppc32_loader $@
|
||||
|
||||
l_lx_sh.o: l_lx_sh.c linux.hh
|
||||
l_lx_elf64amd.h: l_lx_elf64amd.S amd_d_nrv2e.S
|
||||
$(GCC_AMD64) -c $T.S
|
||||
$(LD_AMD64) -o $T.bin --oformat binary $T.o
|
||||
$(BIN2H) $T.bin linux_elf64amd_loader $@
|
||||
|
||||
l_lx_elf.o: l_lx_elf.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_exec.o: l_lx_exec.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_sep.o: l_lx_sep.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_sh.o: l_lx_sh.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_pti.o: l_lx_pti.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
|
||||
fold_elf86.o: fold_elf86.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_elf86.h: l_lx_elf.o fold_elf86.o l_lx_elf86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_elf86.lds -Map $T.map -o $T.bin $T.o l_lx_elf.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin
|
||||
$(STRIPELF) $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386elf_fold $@
|
||||
|
||||
m_lx_elfppc32.o: m_lx_elfppc32.c $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -Os -c $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
a_lx_elf64amd.o: a_lx_elf64.c $(MAKEFILE_DEPS)
|
||||
$(GCC_AMD64) -c -Os -o $@ $<
|
||||
|
||||
fold_elfppc32.o: fold_elfppc32.S ppc_bxx.S $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
fold_elf64amd.o: fold_elf64amd.S amd_bxx.S $(MAKEFILE_DEPS)
|
||||
$(GCC_AMD64) -c -O $T.S
|
||||
|
||||
fold_elfppc32.h: m_lx_elfppc32.o fold_elfppc32.o l_lx_elfppc32.lds
|
||||
$(LD_PPC32) -T $(srcdir)/l_lx_elfppc32.lds -Map $T.map -o $T.bin --strip-all \
|
||||
fold_elfppc32.o m_lx_elfppc32.o
|
||||
$(BIN2H) $T.bin linux_elfppc32_fold $@
|
||||
|
||||
fold_elf64amd.h: a_lx_elf64amd.o fold_elf64amd.o l_lx_elf64amd.lds amd_bxx.S
|
||||
$(LD_AMD64) -T $(srcdir)/l_lx_elf64amd.lds -Map $T.map -o $T.bin --strip-all \
|
||||
fold_elf64amd.o a_lx_elf64amd.o
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BIN2H) $T.bin linux_elf64amd_fold $@
|
||||
|
||||
fold_exec86.o: fold_exec86.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_exec86.h: l_lx_exec.o upx_itoa.o fold_exec86.o l_lx_exec86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_exec86.lds -Map $T.map -o $T.bin $T.o l_lx_exec.o upx_itoa.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin
|
||||
$(STRIPELF) $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386exec_fold $@
|
||||
|
||||
fold_sh86.o: fold_sh86.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_sh86.h: l_lx_sh.o fold_sh86.o l_lx_sh86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sh86.lds -Map $T.map -o $T.bin $T.o l_lx_sh.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin
|
||||
$(STRIPELF) $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386sh_fold $@
|
||||
|
||||
fold_pti86.o: fold_pti86.asm
|
||||
$(NASM) -i$(UCL_I386)/ -f elf -o $@ $<
|
||||
|
||||
fold_pti86.h: l_lx_pti.o fold_pti86.o l_lx_pti86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_pti86.lds -Map $T.map -o $T.bin $T.o l_lx_pti.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386pti_fold $@
|
||||
|
||||
fold_machppc32.h: m_mac_mach32.o fold_machppc32.o
|
||||
$(LD_PPC32) -Map $T.map -o $T.bin --oformat binary fold_machppc32.o m_mac_mach32.o
|
||||
chmod a-x $T.bin
|
||||
$(BIN2H) $T.bin fold_machppc32 $@
|
||||
|
||||
m_mac_mach32.o: m_mac_mach32.c $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -Os -c $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
fold_machppc32.o: fold_machppc32.S ppc_bxx.S $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
upxb: l_lx_sep.o l_lx_sep86.asm
|
||||
$(NASM) -i$(UCL_I386)/ -f elf -dNRV2B -o $T.o l_lx_sep86.asm
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $@
|
||||
$(STRIPELF) $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
$(STRIPELF_LINUX_I386) $@
|
||||
$(BRANDELF) $@
|
||||
|
||||
upxd: l_lx_sep.o l_lx_sep86.asm
|
||||
$(NASM) -i$(UCL_I386)/ -f elf -dNRV2D -o $T.o l_lx_sep86.asm
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $@
|
||||
$(STRIPELF) $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
$(STRIPELF_LINUX_I386) $@
|
||||
$(BRANDELF) $@
|
||||
|
||||
l_armpe.h: l_armpe.asx l_armpe_s.S l_armpe_c.c
|
||||
$(GCC_WINCE) -c l_armpe_s.S l_armpe_c.c
|
||||
$(LD_WINCE) -nostdlib -o l_armpe_.out l_armpe_s.o l_armpe_c.o
|
||||
$(OBJCOPY_WINCE) --only-section .text -O binary l_armpe_.out l_armpe_.bin
|
||||
$(BIN2H_WINCE) <l_armpe_.bin >l_armpe_.ah
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
$(BIN2H) $T.bin nrv_loader $@
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
DEPS_FILES := $(wildcard *.d)
|
||||
ifneq ($(strip $(DEPS_FILES)),)
|
||||
include $(DEPS_FILES)
|
||||
endif
|
||||
-include *.d
|
||||
|
||||
DEPS1 = header.ash macros.ash ident.ash ident_n.ash ident_s.ash
|
||||
DEPS2 = header.asy macros.asy
|
||||
DEPS3 = n2b_d32.asy n2d_d32.asy n2e_d32.asy
|
||||
DEPS3 = n2b_d32.asy n2d_d32.asy n2e_d32.asy cl1_d32.asy
|
||||
|
||||
$(STUBS): $(srcdir)/scripts/bin2h.pl
|
||||
|
||||
l_armpe.h: $(DEPS2) $(DEPS3)
|
||||
l_com.h: n2b_d16.asy $(DEPS2)
|
||||
l_djgpp2.h: $(DEPS2) $(DEPS3)
|
||||
l_exe.h: n2b_d8e.asy n2d_d8e.asy n2e_d8e.asy $(DEPS2)
|
||||
@@ -422,6 +579,14 @@ l_lx_elf86.h: l_lx_elf86.asm macros.ash macros.asy $(DEPS3)
|
||||
l_lx_exec86.h: l_lx_exec86.asm macros.ash macros.asy $(DEPS3)
|
||||
l_lx_sh86.h: l_lx_sh86.asm macros.ash macros.asy $(DEPS3)
|
||||
|
||||
.NOEXPORT:
|
||||
|
||||
# FIXME: what is this ???
|
||||
upxrun: start-interp.o interp.o
|
||||
gcc -nostartfiles -nostdlib -o $@ -Ttext=0x10000 $^
|
||||
start-interp.o: start-interp.S
|
||||
gcc -c $<
|
||||
interp.o: interp.c
|
||||
gcc -c -g $<
|
||||
|
||||
|
||||
# vi:nowrap
|
||||
|
||||
@@ -0,0 +1,359 @@
|
||||
/* a_lx_elf64.c -- stub loader for Linux 64-bit ELF executable
|
||||
|
||||
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-2005 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>
|
||||
*/
|
||||
|
||||
|
||||
#include "linux.hh"
|
||||
extern void exit(int);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// configuration section
|
||||
**************************************************************************/
|
||||
|
||||
// In order to make it much easier to move this code at runtime and execute
|
||||
// it at an address different from it load address: there must be no
|
||||
// static data, and no string constants.
|
||||
|
||||
#define MAX_ELF_HDR 1024 // Elf64_Ehdr + n*Elf64_Phdr must fit in this
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// "file" util
|
||||
**************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
size_t size; // must be first to match size[0] uncompressed size
|
||||
char *buf;
|
||||
} Extent;
|
||||
|
||||
|
||||
static void
|
||||
xread(Extent *x, char *buf, size_t count)
|
||||
{
|
||||
char *p=x->buf, *q=buf;
|
||||
size_t j;
|
||||
if (x->size < count) {
|
||||
exit(127);
|
||||
}
|
||||
for (j = count; 0!=j--; ++p, ++q) {
|
||||
*q = *p;
|
||||
}
|
||||
x->buf += count;
|
||||
x->size -= count;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// util
|
||||
**************************************************************************/
|
||||
|
||||
#if 1 //{ save space
|
||||
#define ERR_LAB error: exit(127);
|
||||
#define err_exit(a) goto error
|
||||
#else //}{ save debugging time
|
||||
#define ERR_LAB
|
||||
static void
|
||||
err_exit(int a)
|
||||
{
|
||||
(void)a; // debugging convenience
|
||||
exit(127);
|
||||
}
|
||||
#endif //}
|
||||
|
||||
/*************************************************************************
|
||||
// UPX & NRV stuff
|
||||
**************************************************************************/
|
||||
|
||||
typedef void f_unfilter(
|
||||
nrv_byte *, // also addvalue
|
||||
nrv_uint,
|
||||
unsigned cto8, // junk in high 24 bits
|
||||
unsigned ftid
|
||||
);
|
||||
typedef int f_expand(
|
||||
const nrv_byte *, nrv_uint,
|
||||
nrv_byte *, nrv_uint *, unsigned );
|
||||
|
||||
static void
|
||||
unpackExtent(
|
||||
Extent *const xi, // input
|
||||
Extent *const xo, // output
|
||||
f_expand *const f_decompress,
|
||||
f_unfilter *f_unf
|
||||
)
|
||||
{
|
||||
while (xo->size) {
|
||||
struct b_info h;
|
||||
// Note: if h.sz_unc == h.sz_cpr then the block was not
|
||||
// compressible and is stored in its uncompressed form.
|
||||
|
||||
// Read and check block sizes.
|
||||
xread(xi, (char *)&h, sizeof(h));
|
||||
if (h.sz_unc == 0) { // uncompressed size 0 -> EOF
|
||||
if (h.sz_cpr != UPX_MAGIC_LE32) // h.sz_cpr must be h->magic
|
||||
err_exit(2);
|
||||
if (xi->size != 0) // all bytes must be written
|
||||
err_exit(3);
|
||||
break;
|
||||
}
|
||||
if (h.sz_cpr <= 0) {
|
||||
err_exit(4);
|
||||
ERR_LAB
|
||||
}
|
||||
if (h.sz_cpr > h.sz_unc
|
||||
|| h.sz_unc > xo->size ) {
|
||||
err_exit(5);
|
||||
}
|
||||
// Now we have:
|
||||
// assert(h.sz_cpr <= h.sz_unc);
|
||||
// assert(h.sz_unc > 0 && h.sz_unc <= blocksize);
|
||||
// assert(h.sz_cpr > 0 && h.sz_cpr <= blocksize);
|
||||
|
||||
if (h.sz_cpr < h.sz_unc) { // Decompress block
|
||||
nrv_uint out_len;
|
||||
int const j = (*f_decompress)((unsigned char *)xi->buf, h.sz_cpr,
|
||||
(unsigned char *)xo->buf, &out_len, h.b_method );
|
||||
if (j != 0 || out_len != (nrv_uint)h.sz_unc)
|
||||
err_exit(7);
|
||||
// Skip Ehdr+Phdrs: separate 1st block, not filtered
|
||||
if (h.b_ftid!=0 && f_unf // have filter
|
||||
&& ((512 < out_len) // this block is longer than Ehdr+Phdrs
|
||||
|| (xo->size==(unsigned)h.sz_unc) ) // block is last in Extent
|
||||
) {
|
||||
(*f_unf)((unsigned char *)xo->buf, out_len, h.b_cto8, h.b_ftid);
|
||||
}
|
||||
xi->buf += h.sz_cpr;
|
||||
xi->size -= h.sz_cpr;
|
||||
}
|
||||
else { // copy literal block
|
||||
xread(xi, xo->buf, h.sz_cpr);
|
||||
}
|
||||
xo->buf += h.sz_unc;
|
||||
xo->size -= h.sz_unc;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 /*{*/
|
||||
static void
|
||||
upx_bzero(char *p, size_t len)
|
||||
{
|
||||
if (len) do {
|
||||
*p++= 0;
|
||||
} while (--len);
|
||||
}
|
||||
#define bzero upx_bzero
|
||||
#endif /*}*/
|
||||
|
||||
static void
|
||||
auxv_up(Elf64_auxv_t *av, unsigned const type, uint64_t const value)
|
||||
{
|
||||
if (av)
|
||||
for (;; ++av) {
|
||||
if (av->a_type==type || (av->a_type==AT_IGNORE && type!=AT_NULL)) {
|
||||
av->a_type = type;
|
||||
av->a_un.a_val = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The PF_* and PROT_* bits are {1,2,4}; the conversion table fits in 32 bits.
|
||||
#define REP8(x) \
|
||||
((x)|((x)<<4)|((x)<<8)|((x)<<12)|((x)<<16)|((x)<<20)|((x)<<24)|((x)<<28))
|
||||
#define EXP8(y) \
|
||||
((1&(y)) ? 0xf0f0f0f0 : (2&(y)) ? 0xff00ff00 : (4&(y)) ? 0xffff0000 : 0)
|
||||
#define PF_TO_PROT(pf) \
|
||||
((PROT_READ|PROT_WRITE|PROT_EXEC) & ( \
|
||||
( (REP8(PROT_EXEC ) & EXP8(PF_X)) \
|
||||
|(REP8(PROT_READ ) & EXP8(PF_R)) \
|
||||
|(REP8(PROT_WRITE) & EXP8(PF_W)) \
|
||||
) >> ((pf & (PF_R|PF_W|PF_X))<<2) ))
|
||||
|
||||
|
||||
// Find convex hull of PT_LOAD (the minimal interval which covers all PT_LOAD),
|
||||
// and mmap that much, to be sure that a kernel using exec-shield-randomize
|
||||
// won't place the first piece in a way that leaves no room for the rest.
|
||||
static unsigned long // returns relocation constant
|
||||
xfind_pages(unsigned mflags, Elf64_Phdr const *phdr, int phnum,
|
||||
char **const p_brk
|
||||
)
|
||||
{
|
||||
size_t lo= ~0, hi= 0, szlo= 0;
|
||||
char *addr;
|
||||
mflags += MAP_PRIVATE | MAP_ANONYMOUS; // '+' can optimize better than '|'
|
||||
for (; --phnum>=0; ++phdr) if (PT_LOAD==phdr->p_type) {
|
||||
if (phdr->p_vaddr < lo) {
|
||||
lo = phdr->p_vaddr;
|
||||
szlo = phdr->p_filesz;
|
||||
}
|
||||
if (hi < (phdr->p_memsz + phdr->p_vaddr)) {
|
||||
hi = phdr->p_memsz + phdr->p_vaddr;
|
||||
}
|
||||
}
|
||||
szlo += ~PAGE_MASK & lo; // page fragment on lo edge
|
||||
lo -= ~PAGE_MASK & lo; // round down to page boundary
|
||||
hi = PAGE_MASK & (hi - lo - PAGE_MASK -1); // page length
|
||||
szlo = PAGE_MASK & (szlo - PAGE_MASK -1); // page length
|
||||
addr = mmap((void *)lo, hi, PROT_READ|PROT_WRITE|PROT_EXEC, mflags, 0, 0);
|
||||
*p_brk = hi + addr; // the logical value of brk(0)
|
||||
munmap(szlo + addr, hi - szlo); // desirable if PT_LOAD non-contiguous
|
||||
return (unsigned long)addr - lo;
|
||||
}
|
||||
|
||||
static Elf64_Addr // entry address
|
||||
do_xmap(
|
||||
Elf64_Ehdr const *const ehdr,
|
||||
Extent *const xi,
|
||||
int const fdi,
|
||||
Elf64_auxv_t *const av,
|
||||
f_expand *const f_decompress,
|
||||
f_unfilter *const f_unf
|
||||
)
|
||||
{
|
||||
Elf64_Phdr const *phdr = (Elf64_Phdr const *) (ehdr->e_phoff +
|
||||
(char const *)ehdr);
|
||||
char *v_brk;
|
||||
unsigned long const reloc = xfind_pages(
|
||||
((ET_DYN!=ehdr->e_type) ? MAP_FIXED : 0), phdr, ehdr->e_phnum, &v_brk);
|
||||
int j;
|
||||
for (j=0; j < ehdr->e_phnum; ++phdr, ++j)
|
||||
if (xi && PT_PHDR==phdr->p_type) {
|
||||
auxv_up(av, AT_PHDR, phdr->p_vaddr + reloc);
|
||||
} else
|
||||
if (PT_LOAD==phdr->p_type) {
|
||||
unsigned const prot = PF_TO_PROT(phdr->p_flags);
|
||||
Extent xo;
|
||||
size_t mlen = xo.size = phdr->p_filesz;
|
||||
char *addr = xo.buf = reloc + (char *)phdr->p_vaddr;
|
||||
char *haddr = phdr->p_memsz + addr;
|
||||
size_t frag = (long)addr &~ PAGE_MASK;
|
||||
mlen += frag;
|
||||
addr -= frag;
|
||||
|
||||
if (addr != mmap(addr, mlen, PROT_READ | PROT_WRITE,
|
||||
MAP_FIXED | MAP_PRIVATE | (xi ? MAP_ANONYMOUS : 0),
|
||||
fdi, phdr->p_offset - frag) ) {
|
||||
err_exit(8);
|
||||
}
|
||||
if (xi) {
|
||||
unpackExtent(xi, &xo, f_decompress, f_unf);
|
||||
}
|
||||
bzero(addr, frag); // fragment at lo end
|
||||
frag = (-mlen) &~ PAGE_MASK; // distance to next page boundary
|
||||
bzero(mlen+addr, frag); // fragment at hi end
|
||||
if (xi && 0==phdr->p_offset) {
|
||||
Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)addr;
|
||||
*(int *)&ehdr->e_ident[12] = 0x90c3050f; // syscall; ret; nop
|
||||
}
|
||||
if (0!=mprotect(addr, mlen, prot)) {
|
||||
err_exit(10);
|
||||
ERR_LAB
|
||||
}
|
||||
addr += mlen + frag; /* page boundary on hi end */
|
||||
if (addr < haddr) { // need pages for .bss
|
||||
if (addr != mmap(addr, haddr - addr, prot,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0 ) ) {
|
||||
err_exit(9);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xi) { // 1st call (main); also have (0!=av) here
|
||||
if (ET_DYN!=ehdr->e_type) {
|
||||
// Needed only if compressed shell script invokes compressed shell.
|
||||
brk(v_brk);
|
||||
}
|
||||
}
|
||||
return ehdr->e_entry + reloc;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// upx_main - called by our entry code
|
||||
//
|
||||
// This function is optimized for size.
|
||||
**************************************************************************/
|
||||
|
||||
void *
|
||||
upx_main( // returns entry address
|
||||
struct b_info const *const bi, // 1st block header
|
||||
size_t const sz_compressed, // total length
|
||||
Elf64_Ehdr *const ehdr, // temp char[sz_ehdr] for decompressing
|
||||
Elf64_auxv_t *const av,
|
||||
f_expand *const f_decompress,
|
||||
f_unfilter *const f_unf
|
||||
)
|
||||
{
|
||||
Elf64_Phdr const *phdr = (Elf64_Phdr const *)(1+ ehdr);
|
||||
Elf64_Addr entry;
|
||||
|
||||
Extent xo, xi1, xi2;
|
||||
xo.buf = (char *)ehdr;
|
||||
xo.size = bi->sz_unc;
|
||||
xi2.buf = (char *)bi; xi2.size = sz_compressed;
|
||||
xi1.buf = (char *)bi; xi1.size = sz_compressed;
|
||||
|
||||
// ehdr = Uncompress Ehdr and Phdrs
|
||||
unpackExtent(&xi2, &xo, f_decompress, 0); // never filtered?
|
||||
|
||||
// AT_PHDR.a_un.a_val is set again by do_xmap if PT_PHDR is present.
|
||||
auxv_up(av, AT_PHDR , (unsigned long)(1+(Elf64_Ehdr *)phdr->p_vaddr));
|
||||
auxv_up(av, AT_PHNUM , ehdr->e_phnum);
|
||||
auxv_up(av, AT_ENTRY , (unsigned long)ehdr->e_entry);
|
||||
//auxv_up(av, AT_PHENT , ehdr->e_phentsize); /* this can never change */
|
||||
//auxv_up(av, AT_PAGESZ, PAGE_SIZE); /* ld-linux.so.2 does not need this */
|
||||
|
||||
entry = do_xmap(ehdr, &xi1, 0, av, f_decompress, f_unf); // "rewind"
|
||||
|
||||
{ // Map PT_INTERP program interpreter
|
||||
int j;
|
||||
for (j=0; j < ehdr->e_phnum; ++phdr, ++j) if (PT_INTERP==phdr->p_type) {
|
||||
char const *const iname = (char const *)phdr->p_vaddr;
|
||||
int const fdi = open(iname, O_RDONLY, 0);
|
||||
if (0 > fdi) {
|
||||
err_exit(18);
|
||||
}
|
||||
if (MAX_ELF_HDR!=read(fdi, (void *)ehdr, MAX_ELF_HDR)) {
|
||||
ERR_LAB
|
||||
err_exit(19);
|
||||
}
|
||||
entry = do_xmap(ehdr, 0, fdi, 0, 0, 0);
|
||||
close(fdi);
|
||||
}
|
||||
}
|
||||
|
||||
return (void *)entry;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* amd_bxx.S -- AMD x86_64 Call/Branch Trick unfilter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2005 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.
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "amd_regs.h"
|
||||
|
||||
amdbxx: # (*f_unf)(xo->buf, out_len, h.b_cto8, h.b_ftid);
|
||||
|
||||
#define ptr %arg1 /* known to be %rdi */
|
||||
#define len %arg2
|
||||
#define cto8 %arg3l /* known to be "%dl" */
|
||||
#define ftid %arg4l
|
||||
|
||||
cmpl $0x49,ftid; jne ckend # filter: JMP, CALL, 6-byte Jxx
|
||||
movq len,%rcx # byte count
|
||||
movq ptr,%rsi # remember start of buffer
|
||||
jmp ckstart
|
||||
ckloop3:
|
||||
movb (%rdi),%al; addq $1,%rdi
|
||||
cmpb $0x80,%al; jb ckloop2 # lo of 6-byte Jcc
|
||||
cmpb $0x8F,%al; ja ckloop2 # hi of 6-byte Jcc
|
||||
cmpb $0x0F,-2(%rdi); je ckmark # prefix of 6-byte Jcc
|
||||
ckloop2:
|
||||
subb $ 0xE8,%al
|
||||
cmpb $0xE9-0xE8,%al; ja ckcount # not JMP, not CALL
|
||||
ckmark:
|
||||
cmpb %dl,(%rdi); jne ckcount # not marked with cto8
|
||||
movl (%rdi),%eax # the marked, bswapped 32-bit displacement
|
||||
andl $~0<<8,%eax # clear the mark
|
||||
bswap %eax
|
||||
subl %edi,%eax
|
||||
addl %esi,%eax
|
||||
stosl # *%rdi++ = %eax;
|
||||
ckstart:
|
||||
subq $4,%rcx
|
||||
movb (%rdi),%al; addq $1,%rdi
|
||||
decq %rcx; jnz ckloop2 # prefix cannot overlap previous displacement
|
||||
jmp ckend
|
||||
ckcount:
|
||||
decq %rcx; jnz ckloop3
|
||||
ckend:
|
||||
ret
|
||||
@@ -0,0 +1,68 @@
|
||||
/* amd_d_nrv2b.S -- AMD64 decompressor for NRV2B
|
||||
|
||||
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-2005 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>
|
||||
*/
|
||||
|
||||
ALIGN(1<<3)
|
||||
lit_n2b:
|
||||
incq %rsi; movb %dl,(%rdi)
|
||||
incq %rdi
|
||||
top_n2b:
|
||||
movb (%rsi),%dl # speculate: literal, or bottom 8 bits of offset
|
||||
jnextb1yp lit_n2b
|
||||
lea 1(lenq),off # [len= 0] off= 1
|
||||
offmore_n2b:
|
||||
getnextbp(off)
|
||||
jnextb0np offmore_n2b
|
||||
|
||||
subl $ 3,off; jc len_n2b # use previous offset
|
||||
shll $ 8,off; movzbl %dl,%edx
|
||||
orl %edx,off; incq %rsi
|
||||
xorl $~0,off; jz eof
|
||||
movslq off,disp # XXX: 2GB
|
||||
len_n2b:
|
||||
lea 1(lenq),off # [len= 0] off= 1
|
||||
getnextb(len); getnextb(len) # two bits; cc set on result
|
||||
jnz gotlen_n2b # raw 1,2,3 ==> 2,3,4
|
||||
movl off,len # len= 1, the msb
|
||||
addl $3-1,off # raw 2.. ==> 5..
|
||||
lenmore_n2b:
|
||||
getnextb(len)
|
||||
jnextb0n lenmore_n2b
|
||||
gotlen_n2b:
|
||||
cmpq $-0xd00,disp
|
||||
adcl off,len # len += off + (disp < -0xd00)
|
||||
call copy
|
||||
bot_n2b: # In: 0==len
|
||||
jmp top_n2b
|
||||
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/* amd_d_nrv2e.S -- AMD64 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-2005 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>
|
||||
*/
|
||||
|
||||
ALIGN(1<<3)
|
||||
lit_n2e:
|
||||
incq %rsi; movb %dl,(%rdi)
|
||||
incq %rdi
|
||||
top_n2e:
|
||||
movb (%rsi),%dl # speculate: literal, or bottom 8 bits of offset
|
||||
jnextb1yp lit_n2e
|
||||
lea 1(lenq),off # [len= 0] off= 1
|
||||
jmp getoff_n2e
|
||||
|
||||
off_n2e:
|
||||
dec off
|
||||
getnextbp(off)
|
||||
getoff_n2e:
|
||||
getnextbp(off)
|
||||
jnextb0np off_n2e
|
||||
|
||||
subl $ 3,off; jc offprev_n2e
|
||||
shll $ 8,off; movzbl %dl,%edx
|
||||
orl %edx,off; incq %rsi
|
||||
xorl $~0,off; jz eof
|
||||
sarl off # Carry= original low bit
|
||||
movslq off,disp # XXX: 2GB
|
||||
jc lenlast_n2e
|
||||
jmp lenmore_n2e
|
||||
|
||||
offprev_n2e:
|
||||
jnextb1y lenlast_n2e
|
||||
lenmore_n2e:
|
||||
incl len # len= 1
|
||||
jnextb1y lenlast_n2e
|
||||
len_n2e:
|
||||
getnextb(len)
|
||||
jnextb0n len_n2e
|
||||
addl $6-2-2,len
|
||||
jmp gotlen_n2e
|
||||
|
||||
lenlast_n2e:
|
||||
getnextb(len) # 0,1,2,3
|
||||
gotlen_n2e:
|
||||
cmpq $-0x500,disp
|
||||
adcl $2,len # len += 2+ (disp < -0x500);
|
||||
call copy
|
||||
bot_n2e: # In: 0==len
|
||||
jmp top_n2e
|
||||
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/* NOTE: THE FIRST ARGUMENT IS arg1, NOT arg0. */
|
||||
#define arg1 rdi
|
||||
#define arg1l edi
|
||||
#define arg2 rsi
|
||||
#define arg2l esi
|
||||
#define arg3 rdx
|
||||
#define arg3l edx
|
||||
#define arg4 rcx
|
||||
#define arg4l ecx
|
||||
#define sys4 r10 # 4th arg to syscall is not in %rcx
|
||||
#define sys4l r10d
|
||||
#define arg5 r8
|
||||
#define arg5l r8d
|
||||
#define arg6 r9
|
||||
#define arg6l r9d
|
||||
@@ -0,0 +1,129 @@
|
||||
/* arm_nrv2b_d32.S -- ARM decompressor for NRV2B
|
||||
|
||||
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 src r0
|
||||
#define len r1
|
||||
#define dst r2
|
||||
#define tmp r3
|
||||
#define bits r4
|
||||
#define off r5
|
||||
#define g1b r6
|
||||
#define wrnk r7 /* 0xd00 M2_MAX_OFFSET before "wrinkle" */
|
||||
|
||||
/* r12 ("ip") is assumed to be a scratch register. */
|
||||
|
||||
#define GETBIT blx g1b
|
||||
|
||||
#define getnextb(reg) GETBIT; adc reg,reg
|
||||
#define jnextb0 GETBIT; bcc
|
||||
#define jnextb1 GETBIT; bcs
|
||||
|
||||
ucl_nrv2b_decompress_32: .globl ucl_nrv2b_decompress_32 @ ARM mode
|
||||
.type ucl_nrv2b_decompress_32, %function
|
||||
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst) */
|
||||
adr r12,1+go_thumb_n2b @ load pc-relative address
|
||||
bx r12 @ enter THUMB mode
|
||||
|
||||
.code 16 @ THUMB mode
|
||||
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,get1b @ load pc-relative address
|
||||
b top_n2b
|
||||
|
||||
eof_n2b:
|
||||
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
|
||||
sub src,r1 @ 0 if actual src length equals expected length
|
||||
sub dst,r3 @ actual dst length
|
||||
str dst,[r4]
|
||||
pop {r4,r5,r6,r7, pc} @ return
|
||||
|
||||
lit_n2b:
|
||||
ldrb tmp,[src]; add src,#1
|
||||
strb tmp,[dst]; add dst,#1
|
||||
top_n2b:
|
||||
jnextb1 lit_n2b
|
||||
|
||||
mov len,#1 @ the msb
|
||||
getoff_n2b: @ ss11 len= [2..)
|
||||
getnextb(len)
|
||||
jnextb0 getoff_n2b
|
||||
|
||||
sub tmp,len,#3 @ set Carry
|
||||
mov len,#0 @ Carry unaffected
|
||||
blo offprev_n2b @ ss11 returned 2
|
||||
lsl tmp,#8
|
||||
ldrb off,[src]; add src,#1 @ low 8 bits
|
||||
orr off,tmp
|
||||
mvn off,off; beq eof_n2b @ off= ~off
|
||||
offprev_n2b: @ In: 0==len
|
||||
getnextb(len); getnextb(len); bne plus1_n2b @ two bits; 1,2,3 ==> 2,3,4
|
||||
|
||||
mov len,#1 @ the msb
|
||||
getlen_n2b: @ ss11 len= [2..)
|
||||
getnextb(len)
|
||||
jnextb0 getlen_n2b
|
||||
|
||||
add len,#2 @ [2..) ==> [4..);
|
||||
plus1_n2b:
|
||||
add len,#1 @ 1,2,3 ==> 2,3,4; [4..) ==> [5..)
|
||||
/* 'cmn': add the inputs, set condition codes, discard the sum */
|
||||
cmn off,wrnk; bcs near_n2b @ within M2_MAX_OFFSET
|
||||
add len,#1 @ too far away, so minimum match length is 3
|
||||
near_n2b:
|
||||
ldrb tmp,[dst] @ force cacheline allocate
|
||||
copy_n2b:
|
||||
ldrb tmp,[dst,off]
|
||||
strb tmp,[dst]; add dst,#1
|
||||
sub len,#1; bne copy_n2b
|
||||
b top_n2b
|
||||
|
||||
.code 32 @ ARM mode
|
||||
get1b: @ Out: Carry= next_bit
|
||||
adds bits,bits,bits @ shift up, set Carry
|
||||
bxne lr @ return if reload is not needed
|
||||
/* In: Carry set (unchanged until final adcs) */
|
||||
ldrb bits,[src],#1
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #1*8
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #2*8
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #3*8
|
||||
adcs bits,bits,bits @ Carry= next_bit; set bit0 flag from CarryIn
|
||||
bx lr
|
||||
|
||||
.size ucl_nrv2b_decompress_32, .-ucl_nrv2b_decompress_32
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/* arm_nrv2b_d8.S -- ARM decompressor for NRV2B
|
||||
|
||||
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 src r0
|
||||
#define len r1
|
||||
#define dst r2
|
||||
#define tmp r3
|
||||
#define bits r4
|
||||
#define off r5
|
||||
#define g1b r6
|
||||
#define wrnk r7 /* 0xd00 M2_MAX_OFFSET before "wrinkle" */
|
||||
|
||||
/* r12 ("ip") is assumed to be a scratch register. */
|
||||
|
||||
#define GETBIT blx g1b
|
||||
|
||||
#define getnextb(reg) GETBIT; adc reg,reg
|
||||
#define jnextb0 GETBIT; bcc
|
||||
#define jnextb1 GETBIT; bcs
|
||||
|
||||
ucl_nrv2b_decompress_8: .globl ucl_nrv2b_decompress_8 @ ARM mode
|
||||
.type ucl_nrv2b_decompress_8, %function
|
||||
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst) */
|
||||
adr r12,1+go_thumb_n2b @ load pc-relative address
|
||||
bx r12 @ enter THUMB mode
|
||||
|
||||
.code 16 @ THUMB mode
|
||||
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:
|
||||
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
|
||||
sub src,r1 @ 0 if actual src length equals expected length
|
||||
sub dst,r3 @ actual dst length
|
||||
str dst,[r4]
|
||||
pop {r4,r5,r6,r7, pc} @ return
|
||||
|
||||
|
||||
.align 2 @ 1<<2 for benefit of loading address with 'adr' above
|
||||
get1_n2b:
|
||||
adc bits,bits; bne get1r_n2b @ CarryOut has data bit
|
||||
ldrb bits,[src] @ zero-extend next byte
|
||||
adc bits,bits @ double and insert CarryIn as low bit
|
||||
add src,#1
|
||||
lsl bits,#24 @ move to top byte, and set CarryOut from old bit 8
|
||||
get1r_n2b:
|
||||
bx lr
|
||||
|
||||
lit_n2b:
|
||||
ldrb tmp,[src]; add src,#1
|
||||
strb tmp,[dst]; add dst,#1
|
||||
top_n2b:
|
||||
jnextb1 lit_n2b
|
||||
|
||||
mov len,#1 @ the msb
|
||||
getoff_n2b: @ ss11 len= [2..)
|
||||
getnextb(len)
|
||||
jnextb0 getoff_n2b
|
||||
|
||||
sub tmp,len,#3 @ set Carry
|
||||
mov len,#0 @ Carry unaffected
|
||||
blo offprev_n2b @ ss11 returned 2
|
||||
lsl tmp,#8
|
||||
ldrb off,[src]; add src,#1 @ low 8 bits
|
||||
orr off,tmp
|
||||
mvn off,off; beq eof_n2b @ off= ~off
|
||||
offprev_n2b: @ In: 0==len
|
||||
getnextb(len); getnextb(len); bne plus1_n2b @ two bits; 1,2,3 ==> 2,3,4
|
||||
|
||||
mov len,#1 @ the msb
|
||||
getlen_n2b: @ ss11 len= [2..)
|
||||
getnextb(len)
|
||||
jnextb0 getlen_n2b
|
||||
|
||||
add len,#2 @ [2..) ==> [4..);
|
||||
plus1_n2b:
|
||||
add len,#1 @ 1,2,3 ==> 2,3,4; [4..) ==> [5..)
|
||||
/* 'cmn': add the inputs, set condition codes, discard the sum */
|
||||
cmn off,wrnk; bcs near_n2b @ within M2_MAX_OFFSET
|
||||
add len,#1 @ too far away, so minimum match length is 3
|
||||
near_n2b:
|
||||
ldrb tmp,[dst] @ force cacheline allocate
|
||||
copy_n2b:
|
||||
ldrb tmp,[dst,off]
|
||||
strb tmp,[dst]; add dst,#1
|
||||
sub len,#1; bne copy_n2b
|
||||
b top_n2b
|
||||
|
||||
.size ucl_nrv2b_decompress_8, .-ucl_nrv2b_decompress_8
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/* arm_nrv2e_d32.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 src r0
|
||||
#define len r1 /* overlaps 'cnt' */
|
||||
#define dst r2
|
||||
#define tmp r3
|
||||
#define bits r4
|
||||
#define off r5
|
||||
#define g32 r6
|
||||
#define wrnk r7 /* 0x500 M2_MAX_OFFSET before "wrinkle" */
|
||||
|
||||
#define cnt r1 /* overlaps 'len' while reading an offset */
|
||||
|
||||
#define GETBIT \
|
||||
add bits,bits; beq 1f; 0: \
|
||||
.subsection 1; \
|
||||
1: blx g32; b 0b; \
|
||||
.subsection 0
|
||||
|
||||
#define getnextb(reg) GETBIT; adc reg,reg
|
||||
#define jnextb0 GETBIT; bcc
|
||||
#define jnextb1 GETBIT; bcs
|
||||
|
||||
ucl_nrv2e_decompress_32: .globl ucl_nrv2e_decompress_32 @ ARM mode
|
||||
.type ucl_nrv2e_decompress_32, %function
|
||||
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst) */
|
||||
adr r12,1+thumb_nrv2e_d32; bx r12 @ enter THUMB mode
|
||||
.code 16 @ THUMB mode
|
||||
thumb_nrv2e_d32:
|
||||
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,#5
|
||||
lsl wrnk,#8 @ 0x500
|
||||
adr g32,get32 @ load pc-relative address
|
||||
b top_n2e
|
||||
|
||||
eof_n2e:
|
||||
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
|
||||
sub src,r1 @ 0 if actual src length equals expected length
|
||||
sub dst,r3 @ actual dst length
|
||||
str dst,[r4]
|
||||
pop {r4,r5,r6,r7, pc} @ return
|
||||
|
||||
lit_n2e:
|
||||
ldrb tmp,[src]; add src,#1
|
||||
strb tmp,[dst]; add dst,#1
|
||||
top_n2e:
|
||||
jnextb1 lit_n2e
|
||||
mov cnt,#1; b getoff_n2e
|
||||
|
||||
off_n2e:
|
||||
sub cnt,#1
|
||||
getnextb(cnt)
|
||||
getoff_n2e:
|
||||
getnextb(cnt)
|
||||
jnextb0 off_n2e
|
||||
|
||||
sub tmp,cnt,#3 @ set Carry
|
||||
mov len,#0 @ Carry unaffected
|
||||
blo offprev_n2e @ cnt was 2; tests Carry only
|
||||
lsl tmp,#8
|
||||
ldrb off,[src]; add src,#1 @ low 7+1 bits
|
||||
orr off,tmp
|
||||
mvn off,off; beq eof_n2e @ off= ~off
|
||||
asr off,#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
|
||||
add len,#6-2
|
||||
b gotlen_n2e
|
||||
|
||||
lenlast_n2e:
|
||||
getnextb(len) @ 0,1,2,3
|
||||
add len,#2
|
||||
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
|
||||
cmn off,wrnk; bcs near_n2e @ within M2_MAX_OFFSET
|
||||
add len,#1 @ too far away, so minimum match length is 3
|
||||
near_n2e:
|
||||
ldrb tmp,[dst] @ force cacheline allocate
|
||||
copy_n2e:
|
||||
ldrb tmp,[dst,off]
|
||||
strb tmp,[dst]; add dst,#1
|
||||
sub len,#1; bne copy_n2e
|
||||
b top_n2e
|
||||
|
||||
.code 32 @ ARM mode for ease of Carry manipulation
|
||||
get32: @ In: Carry set (unchanged until final adcs)
|
||||
ldrb bits,[src],#1
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #1*8
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #2*8
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #3*8
|
||||
adcs bits,bits,bits @ Set Carry out
|
||||
bx lr
|
||||
|
||||
.size ucl_nrv2e_decompress_32, .-ucl_nrv2e_decompress_32
|
||||
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/* arm_nrv2e_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 src r0
|
||||
#define len r1 /* overlaps 'cnt' */
|
||||
#define dst r2
|
||||
#define tmp r3
|
||||
#define bits r4
|
||||
#define off r5
|
||||
#define g1b r6
|
||||
#define wrnk r7 /* 0x500 M2_MAX_OFFSET before "wrinkle" */
|
||||
|
||||
#define cnt r1 /* overlaps 'len' while reading an offset */
|
||||
|
||||
#define GETBIT blx g1b
|
||||
|
||||
#define getnextb(reg) GETBIT; adc reg,reg
|
||||
#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) */
|
||||
adr r12,1+thumb_nrv2e_d8; bx r12 @ enter THUMB mode
|
||||
.code 16 @ THUMB mode
|
||||
thumb_nrv2e_d8:
|
||||
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,#5
|
||||
lsl wrnk,#8 @ 0x500
|
||||
adr g1b,get1_n2e @ load pc-relative address
|
||||
add g1b,#1 @ force THUMB mode
|
||||
b top_n2e
|
||||
eof_n2e:
|
||||
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
|
||||
sub src,r1 @ 0 if actual src length equals expected length
|
||||
sub dst,r3 @ actual dst length
|
||||
str dst,[r4]
|
||||
pop {r4,r5,r6,r7, pc} @ return
|
||||
|
||||
.align 2 @ 1<<2 for benefit of loading address with 'adr' above
|
||||
get1_n2e:
|
||||
adc bits,bits; bne get1r_n2e @ CarryOut has data bit
|
||||
ldrb bits,[src] @ zero-extend next byte
|
||||
adc bits,bits @ double and insert CarryIn as low bit
|
||||
add src,#1
|
||||
lsl bits,#24 @ move to top byte, and set CarryOut from old bit 8
|
||||
get1r_n2e:
|
||||
bx lr
|
||||
|
||||
lit_n2e:
|
||||
ldrb tmp,[src]; add src,#1
|
||||
strb tmp,[dst]; add dst,#1
|
||||
top_n2e:
|
||||
jnextb1 lit_n2e
|
||||
mov cnt,#1; b getoff_n2e
|
||||
|
||||
off_n2e:
|
||||
sub cnt,#1
|
||||
getnextb(cnt)
|
||||
getoff_n2e:
|
||||
getnextb(cnt)
|
||||
jnextb0 off_n2e
|
||||
|
||||
sub tmp,cnt,#3 @ set Carry
|
||||
mov len,#0 @ Carry unaffected
|
||||
blo offprev_n2e @ cnt was 2; tests Carry only
|
||||
lsl tmp,#8
|
||||
ldrb off,[src]; add src,#1 @ low 7+1 bits
|
||||
orr off,tmp
|
||||
mvn off,off; beq eof_n2e @ off= ~off
|
||||
asr off,#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
|
||||
add len,#6-2
|
||||
b gotlen_n2e
|
||||
|
||||
lenlast_n2e:
|
||||
getnextb(len) @ 0,1,2,3
|
||||
add len,#2
|
||||
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
|
||||
cmn off,wrnk; bcs near_n2e @ within M2_MAX_OFFSET
|
||||
add len,#1 @ too far away, so minimum match length is 3
|
||||
near_n2e:
|
||||
ldrb tmp,[dst] @ force cacheline allocate
|
||||
copy_n2e:
|
||||
ldrb tmp,[dst,off]
|
||||
strb tmp,[dst]; add dst,#1
|
||||
sub len,#1; bne copy_n2e
|
||||
b top_n2e
|
||||
|
||||
.size ucl_nrv2e_decompress_8, .-ucl_nrv2e_decompress_8
|
||||
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/* fold_elf64amd.S -- linkage to C code to process Elf binary
|
||||
*
|
||||
* This file is part of the UPX executable compressor.
|
||||
*
|
||||
* Copyright (C) 2000-2005 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>
|
||||
*/
|
||||
#include "amd_regs.h"
|
||||
|
||||
PAGE_SHIFT= 12
|
||||
PAGE_MASK= 0xffffffffffffffff<<PAGE_SHIFT
|
||||
|
||||
sz_b_info= 12
|
||||
sz_unc= 0
|
||||
sz_cpr= 4
|
||||
|
||||
sz_l_info= 12
|
||||
sz_p_info= 12
|
||||
|
||||
OVERHEAD=2048
|
||||
MAX_ELF_HDR=1024
|
||||
|
||||
/* 64-bit mode only! */
|
||||
__NR_read= 0
|
||||
__NR_open= 2
|
||||
__NR_close= 3
|
||||
|
||||
__NR_mmap= 9
|
||||
__NR_mprotect= 10
|
||||
__NR_munmap= 11
|
||||
__NR_brk= 12
|
||||
|
||||
__NR_exit= 60
|
||||
|
||||
/* In:
|
||||
cld
|
||||
%rbp= &decompress
|
||||
%rsp= &{LENX,ADRX,LENU,ADRU,JMPU,argc,argv...,0,env...,0,auxv...,0...,strings}
|
||||
*/
|
||||
fold_begin:
|
||||
call L90 # push &f_unfilter
|
||||
#include "amd_bxx.S"
|
||||
L90:
|
||||
lea (1+5+1)*8(%rsp),%rsi # &argv[0]
|
||||
0:
|
||||
lodsq; testq %rax,%rax; jnz 0b # %rsi= &env;
|
||||
0:
|
||||
lodsq; testq %rax,%rax; jnz 0b # %rsi= &Elf64_auxv
|
||||
|
||||
pop %arg6 # &amdbxx: f_unfilter
|
||||
movq %rsi,%arg4 # &Elf64_auxv
|
||||
pop %arg2 # LENX
|
||||
pop %arg1 # ADRX
|
||||
|
||||
subq $ OVERHEAD,%rsp
|
||||
movq %rsp,%arg3 # &ELf64_Ehdr temporary space
|
||||
movq %rbp,%arg5 # &decompress: f_expand
|
||||
call upx_main # Out: %rax= entry
|
||||
/* entry= upx_main(b_info *arg1, total_size arg2, Elf64_Ehdr *arg3,
|
||||
Elf32_Auxv_t *arg4, f_decompr arg5, f_unfilter arg6 )
|
||||
*/
|
||||
addq $OVERHEAD,%rsp
|
||||
pop %arg2 # LENU
|
||||
pop %arg1 # ADRU
|
||||
pop %rcx # JMPU
|
||||
push %rax # &entry
|
||||
push $ __NR_munmap; pop %rax
|
||||
jmp *%rcx # goto: syscall; ret
|
||||
|
||||
munmap: .globl munmap
|
||||
movb $ __NR_munmap,%al; jmp sysgo
|
||||
mprotect: .globl mprotect
|
||||
movb $ __NR_mprotect,%al; jmp sysgo
|
||||
brk: .globl brk
|
||||
movb $ __NR_brk,%al; jmp sysgo
|
||||
|
||||
mmap: .globl mmap
|
||||
movb $ __NR_mmap,%al
|
||||
sysarg4:
|
||||
movq %arg4,%sys4
|
||||
sysgo: # NOTE: kernel demands 4th arg in %sys4, NOT %arg4
|
||||
movzbl %al,%eax
|
||||
syscall
|
||||
cmpq $ PAGE_MASK,%rax; jc no_fail
|
||||
orq $~0,%rax # failure; IGNORE errno
|
||||
no_fail:
|
||||
ret
|
||||
|
||||
read: .globl read
|
||||
movb $ __NR_read,%al; jmp sysgo
|
||||
open: .globl open
|
||||
movb $ __NR_open,%al; jmp sysgo
|
||||
close: .globl close
|
||||
movb $ __NR_close,%al; jmp sysgo
|
||||
|
||||
exit: .globl exit
|
||||
movb $ __NR_exit,%al; jmp sysgo
|
||||
|
||||
# vi:ts=8:et:nowrap
|
||||
@@ -0,0 +1,158 @@
|
||||
/* fold_elf64amd.h -- created from fold_elf64amd.bin, 1964 (0x7ac) 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 LINUX_ELF64AMD_FOLD_SIZE 1964
|
||||
#define LINUX_ELF64AMD_FOLD_ADLER32 0xbcebb18a
|
||||
#define LINUX_ELF64AMD_FOLD_CRC32 0x2dba754c
|
||||
|
||||
unsigned char linux_elf64amd_fold[1964] = {
|
||||
127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */
|
||||
2, 0, 62, 0, 1, 0, 0, 0,188, 0, 16, 0, 0, 0, 0, 0, /* 0x 10 */
|
||||
64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 20 */
|
||||
0, 0, 0, 0, 64, 0, 56, 0, 2, 0, 0, 0, 0, 0, 0, 0, /* 0x 30 */
|
||||
1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 40 */
|
||||
0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, /* 0x 50 */
|
||||
172, 6, 0, 0, 0, 0, 0, 0,172, 6, 0, 0, 0, 0, 0, 0, /* 0x 60 */
|
||||
0, 0, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, /* 0x 70 */
|
||||
172, 6, 0, 0, 0, 0, 0, 0,172, 6, 16, 0, 0, 0, 0, 0, /* 0x 80 */
|
||||
172, 6, 16, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, /* 0x 90 */
|
||||
4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, /* 0x a0 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,232, 80, 0, 0, /* 0x b0 */
|
||||
0,131,249, 73,117, 74, 72,137,241, 72,137,254,235, 44,138, 7, /* 0x c0 */
|
||||
72,131,199, 1, 60,128,114, 10, 60,143,119, 6,128,127,254, 15, /* 0x d0 */
|
||||
116, 6, 44,232, 60, 1,119, 35, 56, 23,117, 31,139, 7, 37, 0, /* 0x e0 */
|
||||
255,255,255, 15,200, 41,248, 1,240,171, 72,131,233, 4,138, 7, /* 0x f0 */
|
||||
72,131,199, 1, 72,255,201,117,217,235, 5, 72,255,201,117,190, /* 0x 100 */
|
||||
195, 72,141,116, 36, 56, 72,173, 72,133,192,117,249, 72,173, 72, /* 0x 110 */
|
||||
133,192,117,249, 65, 89, 72,137,241, 94, 95, 72,129,236, 0, 8, /* 0x 120 */
|
||||
0, 0, 72,137,226, 73,137,232,232, 77, 4, 0, 0, 72,129,196, /* 0x 130 */
|
||||
0, 8, 0, 0, 94, 95, 89, 80,106, 11, 88,255,225,176, 11,235, /* 0x 140 */
|
||||
13,176, 10,235, 9,176, 12,235, 5,176, 9, 73,137,202, 15,182, /* 0x 150 */
|
||||
192, 15, 5, 72, 61, 0,240,255,255,114, 4, 72,131,200,255,195, /* 0x 160 */
|
||||
176, 0,235,234,176, 2,235,230,176, 3,235,226,176, 60,235,222, /* 0x 170 */
|
||||
81, 72, 57, 23, 76,139, 71, 8, 72,141, 74,255,115, 10,191,127, /* 0x 180 */
|
||||
0, 0, 0,232,228,255,255,255, 72,131,249,255,116, 17, 65, 15, /* 0x 190 */
|
||||
182, 0, 72,255,201, 73,255,192,136, 6, 72,255,198,235,233, 72, /* 0x 1a0 */
|
||||
1, 87, 8, 72, 41, 23, 88,195, 65, 85, 73,137,213, 65, 84, 73, /* 0x 1b0 */
|
||||
137,204, 85, 72,137,253, 83, 72,137,243, 72,131,236, 40, 72,131, /* 0x 1c0 */
|
||||
62, 0, 15,132,223, 0, 0, 0, 72,141,116, 36, 16,186, 12, 0, /* 0x 1d0 */
|
||||
0, 0, 72,137,239,232,150,255,255,255,139, 84, 36, 16,139,116, /* 0x 1e0 */
|
||||
36, 20,133,210,117, 21,129,254, 85, 80, 88, 33,117, 17, 72,131, /* 0x 1f0 */
|
||||
125, 0, 0, 15,132,174, 0, 0, 0,235, 4,133,246,117, 10,191, /* 0x 200 */
|
||||
127, 0, 0, 0,232, 99,255,255,255, 57,214,119,242,137,208, 72, /* 0x 210 */
|
||||
59, 3,119,235, 57,214, 72,139, 67, 8,115,101, 68, 15,182, 68, /* 0x 220 */
|
||||
36, 24, 72,139,125, 8, 72,141, 76, 36, 12, 72,137,194, 65,255, /* 0x 230 */
|
||||
213,133,192,117,202,139,116, 36, 12, 59,116, 36, 16,117,192, 15, /* 0x 240 */
|
||||
182, 76, 36, 25,132,201, 15,149,194, 49,192, 77,133,228, 15,149, /* 0x 250 */
|
||||
192,133,194,116, 30,129,254, 0, 2, 0, 0,119, 7,137,240, 72, /* 0x 260 */
|
||||
57, 3,117, 15, 15,182, 84, 36, 26, 15,182,201, 72,139,123, 8, /* 0x 270 */
|
||||
65,255,212,139, 68, 36, 20, 72, 1, 69, 8, 72, 41, 69, 0,235, /* 0x 280 */
|
||||
13,137,242, 72,137,239, 72,137,198,232,226,254,255,255,139, 84, /* 0x 290 */
|
||||
36, 16, 72,139, 3, 72, 1, 83, 8, 72, 41,208, 72,133,192, 72, /* 0x 2a0 */
|
||||
137, 3,233, 27,255,255,255, 72,131,196, 40, 91, 93, 65, 92, 65, /* 0x 2b0 */
|
||||
93,195, 72,133,255, 73,137,208,116, 41, 72,139, 7,137,241, 72, /* 0x 2c0 */
|
||||
57,200,116, 17, 72,255,200, 15,148,194, 49,192,133,246, 15,149, /* 0x 2d0 */
|
||||
192,133,194,116, 8, 72,137, 15, 76,137, 71, 8,195, 72,131,199, /* 0x 2e0 */
|
||||
16,235,215,195, 65, 87,184, 0, 0, 0, 0, 73,137,255, 65, 86, /* 0x 2f0 */
|
||||
73,137,254, 65, 85, 65, 84, 85, 83, 72,131,236, 88, 76, 3,119, /* 0x 300 */
|
||||
32,102,131,127, 16, 3, 72,137,116, 36, 48, 15,183,119, 56, 72, /* 0x 310 */
|
||||
137, 76, 36, 32,185, 16, 0, 0, 0,137, 84, 36, 44, 76,137, 68, /* 0x 320 */
|
||||
36, 24, 76,137, 76, 36, 16, 15, 68,200, 76,137,242, 73,131,205, /* 0x 330 */
|
||||
255, 49,237, 69, 49,228,131,193, 34,255,206,120, 38,131, 58, 1, /* 0x 340 */
|
||||
117, 27, 72,139, 66, 16, 76, 57,232,115, 7, 76,139, 98, 32, 73, /* 0x 350 */
|
||||
137,197, 72, 3, 66, 40, 72, 57,197, 72, 15, 66,232, 72,131,194, /* 0x 360 */
|
||||
56,235,214, 76,137,232, 73,129,229, 0,240,255,255, 69, 49,201, /* 0x 370 */
|
||||
76, 41,237, 37,255, 15, 0, 0, 69, 49,192, 72,129,197,255, 15, /* 0x 380 */
|
||||
0, 0, 77,141,164, 4,255, 15, 0, 0,186, 7, 0, 0, 0, 72, /* 0x 390 */
|
||||
129,229, 0,240,255,255, 76,137,239, 72,137,238, 73,129,228, 0, /* 0x 3a0 */
|
||||
240,255,255,232,161,253,255,255, 72,137,195, 72,141, 4, 40, 76, /* 0x 3b0 */
|
||||
41,229, 74,141, 60, 35, 72,137,238, 76, 41,235, 72,137, 68, 36, /* 0x 3c0 */
|
||||
56,232,119,253,255,255,102, 65,131,127, 56, 0, 72,137, 92, 36, /* 0x 3d0 */
|
||||
8,199, 68, 36, 4, 0, 0, 0, 0, 15,132,100, 1, 0, 0, 72, /* 0x 3e0 */
|
||||
131,124, 36, 48, 0,116, 35, 65,131, 62, 6,117, 29, 72,139, 84, /* 0x 3f0 */
|
||||
36, 8, 73, 3, 86, 16,190, 3, 0, 0, 0, 72,139,124, 36, 32, /* 0x 400 */
|
||||
232,173,254,255,255,233, 34, 1, 0, 0, 65,131, 62, 1, 15,133, /* 0x 410 */
|
||||
24, 1, 0, 0, 72,139,124, 36, 8, 73, 3,126, 16,186, 3, 0, /* 0x 420 */
|
||||
0, 0, 65,139, 78, 4,199, 4, 36, 64, 98, 81,115, 73,139, 70, /* 0x 430 */
|
||||
32, 77,139, 78, 8, 68,139, 68, 36, 44,131,225, 7, 72,137,253, /* 0x 440 */
|
||||
72,137,251,129,229,255, 15, 0, 0,193,225, 2,211, 44, 36, 72, /* 0x 450 */
|
||||
41,235,131, 36, 36, 7, 73,137,253, 77, 3,110, 40, 72,131,124, /* 0x 460 */
|
||||
36, 48, 1, 76,141, 36, 40, 72,137,124, 36, 72, 72,137,223, 76, /* 0x 470 */
|
||||
137,230, 72,137, 68, 36, 64, 25,201, 73, 41,233,131,225,224,131, /* 0x 480 */
|
||||
193, 50,232,194,252,255,255, 72, 57,195,117,105, 72,131,124, 36, /* 0x 490 */
|
||||
48, 0,116, 25, 72,139, 76, 36, 16, 72,139, 84, 36, 24, 72,141, /* 0x 4a0 */
|
||||
116, 36, 64, 72,139,124, 36, 48,232,251,252,255,255, 72,137,233, /* 0x 4b0 */
|
||||
76,137,229, 49,192, 72,247,221, 72,137,223,252,129,229,255, 15, /* 0x 4c0 */
|
||||
0, 0, 72,131,124, 36, 48, 0,243,170, 74,141, 60, 35, 72,137, /* 0x 4d0 */
|
||||
233,243,170,116, 14, 73,131,126, 8, 0,117, 7,199, 67, 12, 15, /* 0x 4e0 */
|
||||
5,195,144,139, 20, 36, 76,137,230, 72,137,223,232, 80,252,255, /* 0x 4f0 */
|
||||
255,133,192,116, 10,191,127, 0, 0, 0,232,109,252,255,255, 73, /* 0x 500 */
|
||||
141, 4, 44, 72, 1,195, 76, 57,235,115, 33,139, 20, 36, 73, 41, /* 0x 510 */
|
||||
221, 69, 49,201, 69, 49,192,185, 50, 0, 0, 0, 76,137,238, 72, /* 0x 520 */
|
||||
137,223,232, 34,252,255,255, 72, 57,195,117,201,255, 68, 36, 4, /* 0x 530 */
|
||||
65, 15,183, 71, 56, 73,131,198, 56, 57, 68, 36, 4, 15,140,156, /* 0x 540 */
|
||||
254,255,255, 72,131,124, 36, 48, 0,116, 18,102, 65,131,127, 16, /* 0x 550 */
|
||||
3,116, 10, 72,139,124, 36, 56,232,232,251,255,255, 73,139, 71, /* 0x 560 */
|
||||
24, 72, 1, 68, 36, 8, 72,139, 68, 36, 8, 72,131,196, 88, 91, /* 0x 570 */
|
||||
93, 65, 92, 65, 93, 65, 94, 65, 95,195, 65, 86, 76,141,114, 64, /* 0x 580 */
|
||||
65, 85, 77,137,205, 65, 84, 77,137,196, 85, 72,137,213, 83, 72, /* 0x 590 */
|
||||
137,203, 49,201, 72,131,236, 48,139, 7, 72,137, 52, 36, 72,137, /* 0x 5a0 */
|
||||
116, 36, 16, 72,141,116, 36, 32, 72,137, 84, 36, 40, 72,137,124, /* 0x 5b0 */
|
||||
36, 8, 76,137,194, 72,137,124, 36, 24, 72,137,231, 72,137, 68, /* 0x 5c0 */
|
||||
36, 32,232,225,251,255,255, 73,139, 86, 16,190, 3, 0, 0, 0, /* 0x 5d0 */
|
||||
72,137,223, 72,131,194, 64,232,214,252,255,255, 72, 15,183, 85, /* 0x 5e0 */
|
||||
56,190, 5, 0, 0, 0, 72,137,223,232,196,252,255,255, 72,139, /* 0x 5f0 */
|
||||
85, 24,190, 9, 0, 0, 0, 72,137,223,232,179,252,255,255, 72, /* 0x 600 */
|
||||
141,116, 36, 16, 77,137,233, 77,137,224, 49,210, 72,137,217, 72, /* 0x 610 */
|
||||
137,239,232,205,252,255,255, 69, 49,237,102,131,125, 56, 0, 73, /* 0x 620 */
|
||||
137,196,116,104, 65,131, 62, 3,117, 82, 73,139,126, 16, 49,210, /* 0x 630 */
|
||||
49,246,232, 45,251,255,255,133,192,137,195,120, 23,186, 0, 4, /* 0x 640 */
|
||||
0, 0, 72,137,238,137,199,232, 20,251,255,255, 72, 61, 0, 4, /* 0x 650 */
|
||||
0, 0,116, 10,191,127, 0, 0, 0,232, 14,251,255,255, 72,137, /* 0x 660 */
|
||||
239, 69, 49,201, 69, 49,192, 49,201,137,218, 49,246,232,114,252, /* 0x 670 */
|
||||
255,255,137,223, 73,137,196,232,236,250,255,255, 15,183, 69, 56, /* 0x 680 */
|
||||
65,255,197, 73,131,198, 56, 65, 57,197,124,152, 72,131,196, 48, /* 0x 690 */
|
||||
76,137,224, 91, 93, 65, 92, 65, 93, 65, 94,195, 0, 0, 0, 0, /* 0x 6a0 */
|
||||
20, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,120, 16, 12, 7, 8, /* 0x 6b0 */
|
||||
144, 1, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 28, 0, 0, 0, /* 0x 6c0 */
|
||||
128, 1, 16, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, /* 0x 6d0 */
|
||||
65, 14, 16, 46, 8, 87, 14, 8, 46, 0, 95, 14, 0, 0, 0, 0, /* 0x 6e0 */
|
||||
44, 0, 0, 0, 68, 0, 0, 0,184, 1, 16, 0, 0, 0, 0, 0, /* 0x 6f0 */
|
||||
10, 1, 0, 0, 0, 0, 0, 0, 66, 14, 16,141, 2, 69, 14, 24, /* 0x 700 */
|
||||
140, 3, 68, 14, 32,134, 4, 68, 14, 40,131, 5, 71, 14, 80, 0, /* 0x 710 */
|
||||
20, 0, 0, 0,116, 0, 0, 0,194, 2, 16, 0, 0, 0, 0, 0, /* 0x 720 */
|
||||
50, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0,140, 0, 0, 0, /* 0x 730 */
|
||||
244, 2, 16, 0, 0, 0, 0, 0,150, 2, 0, 0, 0, 0, 0, 0, /* 0x 740 */
|
||||
66, 14, 16,143, 2, 74, 14, 24,142, 3, 69, 14, 32, 66, 14, 40, /* 0x 750 */
|
||||
65, 14, 48, 65, 14, 56, 68, 14,144, 1,131, 7,134, 6,140, 5, /* 0x 760 */
|
||||
141, 4, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0,204, 0, 0, 0, /* 0x 770 */
|
||||
138, 5, 16, 0, 0, 0, 0, 0, 34, 1, 0, 0, 0, 0, 0, 0, /* 0x 780 */
|
||||
66, 14, 16,142, 2, 70, 14, 24,141, 3, 69, 14, 32,140, 4, 68, /* 0x 790 */
|
||||
14, 40,134, 5, 68, 14, 48,131, 6, 73, 14, 96 /* 0x 7a0 */
|
||||
};
|
||||
+23
-15
@@ -35,6 +35,7 @@
|
||||
%define PAGE_SIZE ( 1<<12)
|
||||
%define szElf32_Ehdr 0x34
|
||||
%define szElf32_Phdr 8*4
|
||||
%define e_type 16
|
||||
%define e_entry (16 + 2*2 + 4)
|
||||
%define p_memsz 5*4
|
||||
%define szb_info 12
|
||||
@@ -54,9 +55,6 @@ fold_begin: ; enter: %ebx= &Elf32_Ehdr of this program
|
||||
; dword sz_uncompressed, sz_compressed
|
||||
; byte compressed_data...
|
||||
|
||||
pop eax ; discard &sz_uncompressed
|
||||
pop eax ; discard sz_uncompressed
|
||||
|
||||
; ld-linux.so.2 depends on AT_PHDR and AT_ENTRY, for instance.
|
||||
; Move argc,argv,envp down to make room for Elf_auxv table.
|
||||
; Linux kernel 2.4.2 and earlier give only AT_HWCAP and AT_PLATFORM
|
||||
@@ -75,6 +73,8 @@ fold_begin: ; enter: %ebx= &Elf32_Ehdr of this program
|
||||
%define AT_PAGESZ 6
|
||||
%define AT_ENTRY 9
|
||||
|
||||
%define ET_DYN 3
|
||||
|
||||
sub ecx, ecx
|
||||
mov edx, (1<<AT_PHDR) | (1<<AT_PHENT) | (1<<AT_PHNUM) | (1<<AT_PAGESZ) | (1<<AT_ENTRY)
|
||||
mov esi, esp
|
||||
@@ -96,21 +96,34 @@ L50:
|
||||
%define OVERHEAD 2048
|
||||
%define MAX_ELF_HDR 512
|
||||
|
||||
sub esp, dword MAX_ELF_HDR + OVERHEAD ; alloca
|
||||
mov edx, esp ; %edx= &tmp
|
||||
push ebx ; save &Elf32_Ehdr of this stub
|
||||
sub esp, dword MAX_ELF_HDR + OVERHEAD
|
||||
xor ecx, ecx ; 0
|
||||
push ecx ; assume not ET_DYN
|
||||
lea eax, [szElf32_Ehdr + 2*szElf32_Phdr + szl_info + szp_info + ebx] ; 1st &b_info
|
||||
mov esi, [e_entry + ebx] ; beyond compressed data
|
||||
cmp word [e_type + ebx], byte ET_DYN
|
||||
jne L53
|
||||
pop ecx ; is ET_DYN: discard false assumption
|
||||
add esi, ebx ; relocate e_entry
|
||||
mov ch, PAGE_SIZE>>8 ; %ecx= PAGE_SIZE
|
||||
add ebx, [p_memsz + szElf32_Ehdr + ebx]
|
||||
add ebx, ecx
|
||||
push ebx ; dynbase
|
||||
L53:
|
||||
sub esi, eax ; length of compressed data
|
||||
mov ebx, [ eax] ; length of uncompressed ELF headers
|
||||
mov edx, esp ;
|
||||
mov ecx, [4+ eax] ; length of compressed ELF headers
|
||||
add ecx, byte szb_info
|
||||
pusha ; (AT_table, sz_cpr, f_expand, &tmp_ehdr, {sz_unc, &tmp}, {sz_cpr, &b1st_info} )
|
||||
inc edi ; swap with above 'pusha' to inhibit auxv_up for PT_INTERP
|
||||
EXTERN upx_main
|
||||
call upx_main ; returns entry address
|
||||
add esp, dword 8*4 + MAX_ELF_HDR + OVERHEAD ; remove 8 params, temp space
|
||||
add esp, byte 8*4 ; remove 8 params from pusha
|
||||
pop ecx ; dynbase
|
||||
pop ebx ; &Elf32_Ehdr of this stub
|
||||
add esp, dword MAX_ELF_HDR + OVERHEAD ; un-alloca
|
||||
push eax ; save entry address
|
||||
|
||||
dec edi ; auxv table
|
||||
@@ -127,9 +140,9 @@ L60:
|
||||
; See bug libc/1165 at http://bugs.gnu.org/cgi-bin/gnatsweb.pl
|
||||
; Found 1999-06-16 glibc-2.1.1
|
||||
; Fixed 1999-12-29 glibc-2.1.2
|
||||
|
||||
%define N_STKCLR (0x100 + MAX_ELF_HDR + OVERHEAD)/4
|
||||
%define N_STKCLR 8
|
||||
;
|
||||
;%define N_STKCLR (0x100 + MAX_ELF_HDR + OVERHEAD)/4
|
||||
;%define N_STKCLR 8
|
||||
; lea edi, [esp - 4*N_STKCLR]
|
||||
; pusha ; values will be zeroed
|
||||
; mov esi,esp ; save
|
||||
@@ -138,7 +151,6 @@ L60:
|
||||
; ; xor eax,eax ; eax already 0 from L60
|
||||
; rep stosd
|
||||
; mov esp,esi ; restore
|
||||
; xor ecx, ecx ; ecx already 0 from "rep stosd"
|
||||
|
||||
push eax
|
||||
push eax
|
||||
@@ -148,13 +160,9 @@ L60:
|
||||
push eax
|
||||
push eax
|
||||
push eax ; 32 bytes of zeroes now on stack
|
||||
push eax
|
||||
pop ecx ; 0
|
||||
|
||||
sub ecx, ebx ; length to unmap
|
||||
mov al, __NR_munmap ; eax was 0 from L60
|
||||
mov ch, PAGE_SIZE>>8 ; 0x1000
|
||||
add ecx, [p_memsz + szElf32_Ehdr + ebx] ; length to unmap
|
||||
mov bh, 0 ; from 0x401000 to 0x400000
|
||||
jmp [edi] ; unmap ourselves via escape hatch, then goto entry
|
||||
|
||||
; called twice:
|
||||
|
||||
+110
-105
@@ -1,9 +1,10 @@
|
||||
/* fold_elf86.h -- created from fold_elf86.bin, 1624 (0x658) bytes
|
||||
/* fold_elf86.h -- created from fold_elf86.bin, 1670 (0x686) bytes
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
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
|
||||
@@ -26,110 +27,114 @@
|
||||
*/
|
||||
|
||||
|
||||
#define LINUX_I386ELF_FOLD_ADLER32 0x9b9ac310
|
||||
#define LINUX_I386ELF_FOLD_CRC32 0xc9a476f9
|
||||
#define LINUX_I386ELF_FOLD_SIZE 1670
|
||||
#define LINUX_I386ELF_FOLD_ADLER32 0x2e7cd8c9
|
||||
#define LINUX_I386ELF_FOLD_CRC32 0x2993f845
|
||||
|
||||
unsigned char linux_i386elf_fold[1624] = {
|
||||
unsigned char linux_i386elf_fold[1670] = {
|
||||
127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */
|
||||
2, 0, 3, 0, 1, 0, 0, 0,128, 16, 0, 1, 52, 0, 0, 0, /* 0x 10 */
|
||||
2, 0, 3, 0, 1, 0, 0, 0,128, 0,192, 0, 52, 0, 0, 0, /* 0x 10 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 0, 0, /* 0x 20 */
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 1, /* 0x 30 */
|
||||
0, 16, 0, 1, 88, 6, 0, 0, 88, 6, 0, 0, 5, 0, 0, 0, /* 0x 40 */
|
||||
0, 16, 0, 0, 1, 0, 0, 0, 88, 6, 0, 0, 88, 22, 0, 1, /* 0x 50 */
|
||||
88, 22, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,192, 0, /* 0x 30 */
|
||||
0, 0,192, 0,134, 6, 0, 0,136, 6, 0, 0, 5, 0, 0, 0, /* 0x 40 */
|
||||
0, 16, 0, 0, 1, 0, 0, 0,134, 6, 0, 0,136, 6,192, 0, /* 0x 50 */
|
||||
136, 6,192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */
|
||||
0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */
|
||||
88, 88, 41,201,186,120, 2, 0, 0,137,230,137,231,232, 94, 0, /* 0x 80 */
|
||||
0, 0,137,230,209,234, 25,192, 41,193,141, 36,196,133,210,117, /* 0x 90 */
|
||||
243,137,231,232, 72, 0, 0, 0, 83,129,236, 0, 10, 0, 0,141, /* 0x a0 */
|
||||
131,140, 0, 0, 0,139,115, 24, 41,198,139, 24,137,226,139, 72, /* 0x b0 */
|
||||
4,131,193, 12, 96, 71,232,149, 4, 0, 0,129,196, 32, 10, 0, /* 0x c0 */
|
||||
0, 91, 80, 79, 41,192, 60,175,175,117,252, 80, 80, 80, 80, 80, /* 0x d0 */
|
||||
80, 80, 80, 80, 89,176, 91,181, 16, 3, 75, 72,183, 0,255, 39, /* 0x e0 */
|
||||
173,171,133,192,117,250,173,171,133,192,117,250, 87,173,171,131, /* 0x f0 */
|
||||
248, 32,115, 3, 15,179,194,133,192,173,171,117,240,131,239, 8, /* 0x 100 */
|
||||
1,201, 64,243,171, 72,171,171, 95,195, 0, 0, 85, 87,137,207, /* 0x 110 */
|
||||
86,137,198, 83, 57, 8,139,104, 4,115, 8,106,127, 91,106, 1, /* 0x 120 */
|
||||
88,205,128,133,255,116, 11,137,249,138, 69, 0, 69,136, 2, 66, /* 0x 130 */
|
||||
226,247, 91, 1,126, 4, 41, 62, 94, 95, 93,195, 83,141, 92, 36, /* 0x 140 */
|
||||
8,106, 90, 88,205,128, 91,195, 85,137,229, 87, 86,137,199, 83, /* 0x 150 */
|
||||
137,214,131,236, 24,139, 69, 8,131, 58, 0,137, 69,220, 15,132, /* 0x 160 */
|
||||
189, 0, 0, 0,141, 85,228,137,248,185, 12, 0, 0, 0,232,153, /* 0x 170 */
|
||||
255,255,255,131,125,228, 0,139, 69,232,117, 18, 61, 85, 80, 88, /* 0x 180 */
|
||||
33,117, 15,131, 63, 0, 15,132,149, 0, 0, 0,235, 4,133,192, /* 0x 190 */
|
||||
117, 8,106,127, 91,106, 1, 88,205,128,139, 77,232,139, 69,228, /* 0x 1a0 */
|
||||
57,193,119,238, 59, 6,119,234, 57,193,115, 88, 15,182, 69,236, /* 0x 1b0 */
|
||||
80,141, 69,224, 80,255,118, 4, 81,255,119, 4,255, 85,220,131, /* 0x 1c0 */
|
||||
196, 20,133,192,117,204,139, 85,224, 59, 85,228,117,196,138, 69, /* 0x 1d0 */
|
||||
237,132,192,116, 37,131,125, 12, 0,116, 31,129,250, 0, 2, 0, /* 0x 1e0 */
|
||||
0,119, 4, 57, 22,117, 19, 15,182,192, 80, 15,182, 69,238, 80, /* 0x 1f0 */
|
||||
82,255,118, 4,255, 85, 12,131,196, 16,139, 69,232, 1, 71, 4, /* 0x 200 */
|
||||
41, 7,235, 10,139, 86, 4,137,248,232,254,254,255,255,139, 85, /* 0x 210 */
|
||||
228,139, 6, 1, 86, 4, 41,208,133,192,137, 6,233, 61,255,255, /* 0x 220 */
|
||||
255,141,101,244, 91, 94, 95,201,195,133,210,137,209,116, 6,198, /* 0x 230 */
|
||||
0, 0, 64,226,250,195,133,192, 83,137,211,116, 29,168, 1,117, /* 0x 240 */
|
||||
25,139, 16, 57,218,116, 7, 74,117, 11,133,219,116, 7,137, 24, /* 0x 250 */
|
||||
137, 72, 4,235, 5,131,192, 8,235,231, 91,195, 85,137,229, 87, /* 0x 260 */
|
||||
86, 83,131,236, 72,137, 85,224,139, 77,224,137, 69,228,139, 93, /* 0x 270 */
|
||||
224,199, 69,208, 0, 0, 0, 0, 3, 73, 28,139, 69, 8,139, 85, /* 0x 280 */
|
||||
12,137, 69,220, 49,192,102,131,123, 16, 3,137, 85,216,137, 77, /* 0x 290 */
|
||||
212,137,202, 15,183, 75, 44, 15,149,192,131,206,255,193,224, 4, /* 0x 2a0 */
|
||||
137,207,131,192, 34, 49,219, 79,137, 69,188,120, 34,131, 58, 1, /* 0x 2b0 */
|
||||
117, 24,139, 66, 8, 57,240,115, 8,139,122, 16,137,198,137,125, /* 0x 2c0 */
|
||||
208, 3, 66, 20, 57,195,115, 2,137,195,131,194, 32,226,222,137, /* 0x 2d0 */
|
||||
247,106, 0,129,231, 0,240,255,255,106, 0, 41,251,255,117,188, /* 0x 2e0 */
|
||||
129,195,255, 15, 0, 0,106, 7,129,227, 0,240,255,255,139, 85, /* 0x 2f0 */
|
||||
208, 83,137,240, 37,255, 15, 0, 0, 87,141,180, 2,255, 15, 0, /* 0x 300 */
|
||||
0,232, 54,254,255,255,137,194,131,196, 24, 1,218,129,230, 0, /* 0x 310 */
|
||||
240,255,255,137, 85,240,137,194, 41,243, 1,242,137,217,137, 69, /* 0x 320 */
|
||||
176,137,211,106, 91, 88,205,128,139,117,176,139, 69,224, 41,254, /* 0x 330 */
|
||||
49,255,102,131,120, 44, 0, 15,132,218, 1, 0, 0,139, 85,212, /* 0x 340 */
|
||||
139, 2,131,248, 6,117, 23,139, 74, 8,186, 3, 0, 0, 0,139, /* 0x 350 */
|
||||
69,216, 1,241,232,221,254,255,255,233,165, 1, 0, 0, 72, 15, /* 0x 360 */
|
||||
133,158, 1, 0, 0,139, 93,212,199, 69,200, 64, 98, 81,115,139, /* 0x 370 */
|
||||
75, 24,139, 67, 8,131,225, 7,139, 83, 16,193,225, 2,137, 69, /* 0x 380 */
|
||||
236,211,109,200,137,193, 3, 75, 20,137,195,129,227,255, 15, 0, /* 0x 390 */
|
||||
0,137, 85,232, 1,218, 41,216,137, 85,196,139, 85,212, 1,240, /* 0x 3a0 */
|
||||
1,241,137, 69,184,139, 66, 4,131,101,200, 7, 41,216,131,125, /* 0x 3b0 */
|
||||
220, 1, 80,255,117,228, 25,192,137, 93,192,131,224,224,137, 77, /* 0x 3c0 */
|
||||
180,131,192, 50,131,125,220, 0, 80,139, 69,196,106, 3,116, 3, /* 0x 3d0 */
|
||||
131,192, 3, 80,255,117,184,232, 96,253,255,255,131,196, 24, 57, /* 0x 3e0 */
|
||||
69,184, 15,133,193, 0, 0, 0,131,125,220, 0,116, 34,139, 77, /* 0x 3f0 */
|
||||
212, 49,192,246, 65, 24, 1,116, 6,139, 69,228,131,192, 2, 80, /* 0x 400 */
|
||||
139, 69,220,255,117,228,141, 85,232,232, 58,253,255,255, 88, 90, /* 0x 410 */
|
||||
139, 85,192,139, 69,184,232, 14,254,255,255,139, 93,196,139, 69, /* 0x 420 */
|
||||
184,247,219, 3, 69,196,129,227,255, 15, 0, 0,137,218,137, 93, /* 0x 430 */
|
||||
192,232,243,253,255,255,131,125,220, 0,116, 91,139, 69,212,131, /* 0x 440 */
|
||||
56, 1,117, 83,246, 64, 24, 1,116, 77,139, 93,212,137,194,139, /* 0x 450 */
|
||||
64, 20, 59, 67, 16,139, 82, 8,141, 12, 16,117, 14,137,200,247, /* 0x 460 */
|
||||
216, 37,255, 15, 0, 0,131,248, 3,119, 12,139, 69,212,141, 74, /* 0x 470 */
|
||||
12,131,120, 4, 0,117, 15,139, 1, 61,205,128, 97,195,116, 6, /* 0x 480 */
|
||||
199, 1,205,128, 97,195,133,201,116, 13,139, 69,216, 49,210,131, /* 0x 490 */
|
||||
224,254,232,159,253,255,255,139, 93,184,139, 77,196,139, 85,200, /* 0x 4a0 */
|
||||
106,125, 88,205,128,133,192,116, 8,106,127, 91,106, 1, 88,205, /* 0x 4b0 */
|
||||
128,139, 69,196, 3, 69,192, 1, 69,184,139, 69,180, 57, 69,184, /* 0x 4c0 */
|
||||
115, 31,106, 0, 43, 69,184,106, 0,106, 50,255,117,200, 80,255, /* 0x 4d0 */
|
||||
117,184,232,101,252,255,255,131,196, 24, 57, 69,184,116, 36,235, /* 0x 4e0 */
|
||||
200,131,125,220, 0,116, 28,131, 69,196, 3,129,101,196,255, 15, /* 0x 4f0 */
|
||||
0, 0,131,125,196, 3,119, 11,139, 93,184,139, 77,196,106, 91, /* 0x 500 */
|
||||
88,205,128,139, 85,224, 71,131, 69,212, 32, 15,183, 66, 44, 57, /* 0x 510 */
|
||||
199, 15,140, 38,254,255,255,131,125,220, 0,117, 17,139, 93,228, /* 0x 520 */
|
||||
106, 6, 88,205,128,133,192,116, 23,233,123,255,255,255,139,125, /* 0x 530 */
|
||||
224,102,131,127, 16, 3,116, 8,139, 93,240,106, 45, 88,205,128, /* 0x 540 */
|
||||
139, 69,224, 3,112, 24,141,101,244, 91,137,240, 94, 95,201,195, /* 0x 550 */
|
||||
85,137,229, 87, 86, 83, 87, 87,139,125, 20,106, 0,139, 69, 16, /* 0x 560 */
|
||||
141, 87, 52,139, 93, 8, 80,139,117, 32,137, 69,240,137, 85,236, /* 0x 570 */
|
||||
141, 69, 32,141, 85, 24,232,205,251,255,255,139, 69, 12,186, 3, /* 0x 580 */
|
||||
0, 0, 0, 41,117, 36,137, 69, 32,139, 69,236,139, 72, 8,137, /* 0x 590 */
|
||||
216,131,193, 52,232,157,252,255,255, 15,183, 79, 42,137,216,186, /* 0x 5a0 */
|
||||
4, 0, 0, 0,232,141,252,255,255, 15,183, 79, 44,137,216,186, /* 0x 5b0 */
|
||||
5, 0, 0, 0,232,125,252,255,255,139, 79, 24,137,216,186, 9, /* 0x 5c0 */
|
||||
0, 0, 0,232,110,252,255,255,141, 69, 32, 83,137,250, 80,139, /* 0x 5d0 */
|
||||
69,240,232,133,252,255,255,102,139, 79, 44,131,196, 16, 49,210, /* 0x 5e0 */
|
||||
102,133,201,137,195,116, 87,139, 69,236,131, 56, 3,117, 67, 49, /* 0x 5f0 */
|
||||
201,139, 88, 8,137,202,106, 5, 88,205,128,133,192,137,198,120, /* 0x 600 */
|
||||
20,102,186, 0, 2,137,195,137,249,106, 3, 88,205,128, 61, 0, /* 0x 610 */
|
||||
2, 0, 0,116, 10,106,127, 91,106, 1, 88,205,128,235,246,106, /* 0x 620 */
|
||||
0,137,240,106, 0,137,250,232, 48,252,255,255, 89, 94,137,195, /* 0x 630 */
|
||||
235, 12, 66, 15,183,193,131, 69,236, 32, 57,194,124,169,141,101, /* 0x 640 */
|
||||
244,137,216, 91, 94, 95,201,195 /* 0x 650 */
|
||||
41,201,186,120, 2, 0, 0,137,230,137,231,232,112, 0, 0, 0, /* 0x 80 */
|
||||
137,230,209,234, 25,192, 41,193,141, 36,196,133,210,117,243,137, /* 0x 90 */
|
||||
231,232, 90, 0, 0, 0,129,236, 0, 10, 0, 0,137,226, 83, 49, /* 0x a0 */
|
||||
201, 81,141,131,140, 0, 0, 0,139,115, 24,102,131,123, 16, 3, /* 0x b0 */
|
||||
117, 11, 89, 1,222,181, 16, 3, 91, 72, 1,203, 83, 41,198,139, /* 0x c0 */
|
||||
24,139, 72, 4,131,193, 12, 96, 71,232,163, 4, 0, 0,131,196, /* 0x d0 */
|
||||
32, 89, 91,129,196, 0, 10, 0, 0, 80, 79, 41,192, 60,175,175, /* 0x e0 */
|
||||
117,252, 80, 80, 80, 80, 80, 80, 80, 80, 41,217,176, 91,255, 39, /* 0x f0 */
|
||||
173,171,133,192,117,250,173,171,133,192,117,250, 87,173,171,131, /* 0x 100 */
|
||||
248, 32,115, 3, 15,179,194,133,192,173,171,117,240,131,239, 8, /* 0x 110 */
|
||||
1,201, 64,243,171, 72,171,171, 95,195, 0, 0, 85, 87,137,207, /* 0x 120 */
|
||||
86,137,198, 83, 57, 8,139,104, 4,115, 8,106,127, 91,106, 1, /* 0x 130 */
|
||||
88,205,128,133,255,116, 11,137,249,138, 69, 0, 69,136, 2, 66, /* 0x 140 */
|
||||
226,247, 91, 1,126, 4, 41, 62, 94, 95, 93,195, 83,141, 92, 36, /* 0x 150 */
|
||||
8,106, 90, 88,205,128, 91,195, 85,137,229, 87, 86,137,199, 83, /* 0x 160 */
|
||||
137,214,131,236, 24,139, 69, 8,131, 58, 0,137, 69,220, 15,132, /* 0x 170 */
|
||||
189, 0, 0, 0,141, 85,228,137,248,185, 12, 0, 0, 0,232,153, /* 0x 180 */
|
||||
255,255,255,131,125,228, 0,139, 69,232,117, 18, 61, 85, 80, 88, /* 0x 190 */
|
||||
33,117, 15,131, 63, 0, 15,132,149, 0, 0, 0,235, 4,133,192, /* 0x 1a0 */
|
||||
117, 8,106,127, 91,106, 1, 88,205,128,139, 77,232,139, 69,228, /* 0x 1b0 */
|
||||
57,193,119,238, 59, 6,119,234, 57,193,115, 88, 15,182, 69,236, /* 0x 1c0 */
|
||||
80,141, 69,224, 80,255,118, 4, 81,255,119, 4,255, 85,220,131, /* 0x 1d0 */
|
||||
196, 20,133,192,117,204,139, 85,224, 59, 85,228,117,196,138, 69, /* 0x 1e0 */
|
||||
237,132,192,116, 37,131,125, 12, 0,116, 31,129,250, 0, 2, 0, /* 0x 1f0 */
|
||||
0,119, 4, 57, 22,117, 19, 15,182,192, 80, 15,182, 69,238, 80, /* 0x 200 */
|
||||
82,255,118, 4,255, 85, 12,131,196, 16,139, 69,232, 1, 71, 4, /* 0x 210 */
|
||||
41, 7,235, 10,139, 86, 4,137,248,232,254,254,255,255,139, 85, /* 0x 220 */
|
||||
228,139, 6, 1, 86, 4, 41,208,133,192,137, 6,233, 61,255,255, /* 0x 230 */
|
||||
255,141,101,244, 91, 94, 95,201,195,133,210,137,209,116, 6,198, /* 0x 240 */
|
||||
0, 0, 64,226,250,195,133,192, 83,137,211,116, 29,168, 1,117, /* 0x 250 */
|
||||
25,139, 16, 57,218,116, 7, 74,117, 11,133,219,116, 7,137, 24, /* 0x 260 */
|
||||
137, 72, 4,235, 5,131,192, 8,235,231, 91,195, 85,137,229, 87, /* 0x 270 */
|
||||
86, 83,131,236, 72,137, 85,224,139, 77,224,137, 69,228,139, 93, /* 0x 280 */
|
||||
224,199, 69,208, 0, 0, 0, 0, 3, 73, 28,139, 69, 8,139, 85, /* 0x 290 */
|
||||
12,137, 69,220, 49,192,102,131,123, 16, 2,137, 85,216,137, 77, /* 0x 2a0 */
|
||||
212,137,202, 15,183, 75, 44, 15,148,192,131,206,255,193,224, 4, /* 0x 2b0 */
|
||||
137,207,131,192, 34, 49,219, 79,137, 69,180,120, 34,131, 58, 1, /* 0x 2c0 */
|
||||
117, 24,139, 66, 8, 57,240,115, 8,139,122, 16,137,198,137,125, /* 0x 2d0 */
|
||||
208, 3, 66, 20, 57,195,115, 2,137,195,131,194, 32,226,222,137, /* 0x 2e0 */
|
||||
247,106, 0,129,231, 0,240,255,255,106, 0, 41,251,255,117,180, /* 0x 2f0 */
|
||||
129,195,255, 15, 0, 0,106, 7,129,227, 0,240,255,255,139, 85, /* 0x 300 */
|
||||
208, 83,137,240, 37,255, 15, 0, 0, 87,137, 93,172,141,180, 2, /* 0x 310 */
|
||||
255, 15, 0, 0,232, 51,254,255,255,137,194,131,196, 24, 1,218, /* 0x 320 */
|
||||
129,230, 0,240,255,255,137, 85,240,137,194, 41,243, 1,242,137, /* 0x 330 */
|
||||
217,137, 69,176,137,211,106, 91, 88,205,128,139,117,176,139, 69, /* 0x 340 */
|
||||
224, 41,254, 49,255,102,131,120, 44, 0, 15,132,221, 1, 0, 0, /* 0x 350 */
|
||||
139, 85,212,139, 2,131,248, 6,117, 23,139, 74, 8,186, 3, 0, /* 0x 360 */
|
||||
0, 0,139, 69,216, 1,241,232,218,254,255,255,233,168, 1, 0, /* 0x 370 */
|
||||
0, 72, 15,133,161, 1, 0, 0,139, 93,212,199, 69,200, 64, 98, /* 0x 380 */
|
||||
81,115,139, 75, 24,139, 67, 8,131,225, 7,139, 83, 16, 1,240, /* 0x 390 */
|
||||
193,225, 2,211,109,200,139, 75, 20,137,195,129,227,255, 15, 0, /* 0x 3a0 */
|
||||
0,137, 85,232, 1,218, 1,193,137, 85,196,139, 85,212,137, 69, /* 0x 3b0 */
|
||||
236, 41,216,137, 69,192,139, 66, 4,131,101,200, 7, 41,216,131, /* 0x 3c0 */
|
||||
125,220, 1, 80,255,117,228, 25,192,137, 77,188,131,224,224,137, /* 0x 3d0 */
|
||||
93,184,131,192, 50,131,125,220, 0, 80,139, 69,196,106, 3,116, /* 0x 3e0 */
|
||||
3,131,192, 3, 80,255,117,192,232, 95,253,255,255,131,196, 24, /* 0x 3f0 */
|
||||
57, 69,192, 15,133,198, 0, 0, 0,131,125,220, 0,116, 34,139, /* 0x 400 */
|
||||
77,212, 49,192,246, 65, 24, 1,116, 6,139, 69,228,131,192, 2, /* 0x 410 */
|
||||
80,139, 69,220,255,117,228,141, 85,232,232, 57,253,255,255, 88, /* 0x 420 */
|
||||
90,139, 85,184,139, 69,192,232, 13,254,255,255,139, 93,196,139, /* 0x 430 */
|
||||
69,192,247,219, 3, 69,196,129,227,255, 15, 0, 0,137,218,137, /* 0x 440 */
|
||||
93,184,232,242,253,255,255,131,125,220, 0,116, 96,139, 69,212, /* 0x 450 */
|
||||
131, 56, 1,117, 88,246, 64, 24, 1,116, 82,139, 80, 20,139, 88, /* 0x 460 */
|
||||
8,141, 4, 26,141, 12, 48,139, 69,212, 59, 80, 16,117, 14,137, /* 0x 470 */
|
||||
200,247,216, 37,255, 15, 0, 0,131,248, 3,119, 16,139, 85,212, /* 0x 480 */
|
||||
107,198, 52,131,122, 4, 0,141, 76, 3, 12,117, 15,139, 1, 61, /* 0x 490 */
|
||||
205,128, 97,195,116, 6,199, 1,205,128, 97,195,133,201,116, 13, /* 0x 4a0 */
|
||||
139, 69,216, 49,210,131,224,254,232,153,253,255,255,139, 93,192, /* 0x 4b0 */
|
||||
139, 77,196,139, 85,200,106,125, 88,205,128,133,192,116, 8,106, /* 0x 4c0 */
|
||||
127, 91,106, 1, 88,205,128,139, 69,196, 3, 69,184, 1, 69,192, /* 0x 4d0 */
|
||||
139, 69,188, 57, 69,192,115, 31,106, 0, 43, 69,192,106, 0,106, /* 0x 4e0 */
|
||||
50,255,117,200, 80,255,117,192,232, 95,252,255,255,131,196, 24, /* 0x 4f0 */
|
||||
57, 69,192,116, 36,235,200,131,125,220, 0,116, 28,131, 69,196, /* 0x 500 */
|
||||
3,129,101,196,255, 15, 0, 0,131,125,196, 3,119, 11,139, 93, /* 0x 510 */
|
||||
192,139, 77,196,106, 91, 88,205,128,139, 85,224, 71,131, 69,212, /* 0x 520 */
|
||||
32, 15,183, 66, 44, 57,199, 15,140, 35,254,255,255,131,125,220, /* 0x 530 */
|
||||
0,117, 17,139, 93,228,106, 6, 88,205,128,133,192,116, 23,233, /* 0x 540 */
|
||||
123,255,255,255,139,125,224,102,131,127, 16, 3,116, 8,139, 93, /* 0x 550 */
|
||||
240,106, 45, 88,205,128,131,125, 16, 0,116, 5,139, 69, 16,137, /* 0x 560 */
|
||||
48,139, 85,224, 3,114, 24,141,101,244, 91,137,240, 94, 95,201, /* 0x 570 */
|
||||
195, 85,137,229, 87, 86, 83,131,236, 12,139,125, 28,106, 0,139, /* 0x 580 */
|
||||
69, 16,141, 87, 52,139,117, 8, 80,139, 93, 32,137, 69,236,137, /* 0x 590 */
|
||||
85,232,141, 69, 32,141, 85, 24,232,187,251,255,255,139, 69, 12, /* 0x 5a0 */
|
||||
15,183, 79, 44,186, 5, 0, 0, 0,137, 69, 32,137,240, 41, 93, /* 0x 5b0 */
|
||||
36,232,144,252,255,255, 15,183, 79, 42,186, 4, 0, 0, 0,137, /* 0x 5c0 */
|
||||
240,232,128,252,255,255,139, 93,232,139, 77, 40,186, 3, 0, 0, /* 0x 5d0 */
|
||||
0, 3, 75, 8,137,240,131,193, 52,232,104,252,255,255,141, 69, /* 0x 5e0 */
|
||||
240,137,250, 80,141, 69, 32, 86, 80,139, 69,236,232,123,252,255, /* 0x 5f0 */
|
||||
255,186, 9, 0, 0, 0,137,193,137,195,137,240,232, 69,252,255, /* 0x 600 */
|
||||
255,102,139, 79, 44,131,196, 20, 49,210,102,133,201,116, 93,139, /* 0x 610 */
|
||||
69,232,131, 56, 3,117, 73,139, 93,240, 49,201, 3, 88, 8,137, /* 0x 620 */
|
||||
202,106, 5, 88,205,128,133,192,137,198,120, 20,102,186, 0, 2, /* 0x 630 */
|
||||
137,195,137,249,106, 3, 88,205,128, 61, 0, 2, 0, 0,116, 10, /* 0x 640 */
|
||||
106,127, 91,106, 1, 88,205,128,235,246,106, 0,137,250,106, 0, /* 0x 650 */
|
||||
137,240,106, 0,232, 19,252,255,255,131,196, 12,137,195,235, 12, /* 0x 660 */
|
||||
66, 15,183,193,131, 69,232, 32, 57,194,124,163,141,101,244,137, /* 0x 670 */
|
||||
216, 91, 94, 95,201,195 /* 0x 680 */
|
||||
};
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "ppc_regs.h"
|
||||
|
||||
sz_b_info= 12
|
||||
sz_unc= 0
|
||||
sz_cpr= 4
|
||||
|
||||
sz_l_info= 12
|
||||
sz_p_info= 12
|
||||
|
||||
OVERHEAD= 2048
|
||||
LINKAREA= 4*4 # SysV C linkage area: (sp, lr); but 16-byte align
|
||||
/* In:
|
||||
r31= &decompress; also 8+ (char *)&(offset to {l_info; p_info; b_info})
|
||||
*/
|
||||
fold_begin:
|
||||
call L90
|
||||
#include "ppc_bxx.S"
|
||||
|
||||
/* The SysV convention for argument registers after execve is nice:
|
||||
a0= argc
|
||||
a1= argv
|
||||
a2= envp
|
||||
a3= auxvp
|
||||
a4= fini
|
||||
sp= ~0xf & (-2*4 + (void *)&argc) # 0(sp): old_sp, pc
|
||||
Instead, Linux gives only
|
||||
sp= &{argc,argv...,0,env...,0,auxv...,strings} # 16-byte aligned?
|
||||
We must figure out the rest, particularly auxvp.
|
||||
*/
|
||||
zfind:
|
||||
lwz t0,0(a6); addi a6,a6,4
|
||||
cmpi cr7,t0,0; bne+ cr7,zfind
|
||||
ret
|
||||
L90:
|
||||
mflr a5 # &ppcbxx: f_unfilter
|
||||
lwz a6,0(sp) # sp at execve
|
||||
call zfind # a6= &env
|
||||
call zfind # a6= &Elf32_auxv
|
||||
lwz a1,-8(r31) # total size = offset to {l_info; p_info; b_info}
|
||||
rlwinm r30,a5,0,0,31-12 # r30= &this_page
|
||||
la a2,-OVERHEAD(sp) # &Elf32_Ehdr temporary space
|
||||
mr a4,r31 # &decompress: f_expand
|
||||
subf a0,a1,r31 # &l_info
|
||||
addi sp,sp,-(LINKAREA+OVERHEAD)
|
||||
rlwinm r29,a0,0,0,31-12 # r29= &our_Elf32_Ehdr
|
||||
lwz a3,sz_unc+sz_p_info+sz_l_info(a0) # sz_elf_headers
|
||||
call upx_main # Out: a0= entry
|
||||
/* entry= upx_main(l_info *a0, total_size a1, Elf32_Ehdr *a2, sz_ehdr a3,
|
||||
f_decomp a4, f_unf a5, Elf32_auxv_t *a6)
|
||||
*/
|
||||
mr r31,a0 # save &entry
|
||||
|
||||
mr a0,r29 # &our_Elf32_Ehdr
|
||||
subf a1,r29,r30 # size
|
||||
call munmap # unmap compressed program; /proc/self/exe disappears
|
||||
|
||||
mtlr r31 # entry address
|
||||
lmw r2,4+LINKAREA+OVERHEAD(sp) # restore registers r2 thru r31
|
||||
lwz r1, LINKAREA+OVERHEAD(sp) # restore r1; deallocate space
|
||||
ret # enter /lib/ld.so.1
|
||||
|
||||
SYS_exit= 1
|
||||
SYS_fork= 2
|
||||
SYS_read= 3
|
||||
SYS_write= 4
|
||||
SYS_open= 5
|
||||
SYS_close= 6
|
||||
|
||||
SYS_brk= 45
|
||||
SYS_mmap= 90
|
||||
SYS_munmap= 91
|
||||
SYS_mprotect= 125
|
||||
|
||||
mmap: .globl mmap
|
||||
li 0,SYS_mmap
|
||||
sysgo:
|
||||
sc
|
||||
bns+ no_fail # 'bns': branch if No Summary[Overflow]
|
||||
li a0,-1 # failure; IGNORE errno
|
||||
no_fail:
|
||||
ret
|
||||
|
||||
exit: .globl exit
|
||||
li 0,SYS_exit; b sysgo
|
||||
read: .globl read
|
||||
li 0,SYS_read; b sysgo
|
||||
open: .globl open
|
||||
li 0,SYS_open; b sysgo
|
||||
close: .globl close
|
||||
li 0,SYS_close; b sysgo
|
||||
mprotect: .globl mprotect
|
||||
li 0,SYS_mprotect; b sysgo
|
||||
munmap: .globl munmap
|
||||
li 0,SYS_munmap; b sysgo
|
||||
brk: .globl brk
|
||||
li 0,SYS_brk; b sysgo
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/* fold_elfppc32.h -- created from fold_elfppc32.bin, 2324 (0x914) 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 LINUX_ELFPPC32_FOLD_SIZE 2324
|
||||
#define LINUX_ELFPPC32_FOLD_ADLER32 0x0789a535
|
||||
#define LINUX_ELFPPC32_FOLD_CRC32 0x665028e2
|
||||
|
||||
unsigned char linux_elfppc32_fold[2324] = {
|
||||
127, 69, 76, 70, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */
|
||||
0, 2, 0, 20, 0, 0, 0, 1, 0, 16, 0,128, 0, 0, 0, 52, /* 0x 10 */
|
||||
0, 0, 7,252, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 40, /* 0x 20 */
|
||||
0, 7, 0, 6, 0, 0, 0, 1, 0, 0, 0, 0, 0, 16, 0, 0, /* 0x 30 */
|
||||
0, 16, 0, 0, 0, 0, 7,196, 0, 0, 7,196, 0, 0, 0, 5, /* 0x 40 */
|
||||
0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 7,196, 0, 16, 7,196, /* 0x 50 */
|
||||
0, 16, 7,196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, /* 0x 60 */
|
||||
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */
|
||||
72, 0, 0,125, 40, 6, 0,208, 76,130, 0, 32, 84,132,240,191, /* 0x 80 */
|
||||
77,130, 0, 32, 60, 0, 0, 16,124, 4, 0, 64, 65,128, 0, 8, /* 0x 90 */
|
||||
124, 4, 3,120, 56,165, 1, 32,124,103, 27,120, 56, 99,255,252, /* 0x a0 */
|
||||
124,137, 3,166, 72, 0, 0, 28, 84, 75, 2,186,125, 99, 88, 80, /* 0x b0 */
|
||||
125,107, 58, 20, 81, 98, 1,186,144, 67, 0, 0, 78, 64, 0, 32, /* 0x c0 */
|
||||
132, 67, 0, 4, 84, 75, 85,190,124, 11, 40, 64, 65,162,255,220, /* 0x d0 */
|
||||
66, 0,255,240, 78,128, 0, 32,128, 73, 0, 0, 57, 41, 0, 4, /* 0x e0 */
|
||||
47,130, 0, 0, 64,158,255,244, 78,128, 0, 32,125, 8, 2,166, /* 0x f0 */
|
||||
129, 33, 0, 0, 75,255,255,229, 75,255,255,225,128,159,255,248, /* 0x 100 */
|
||||
85, 30, 0, 38, 56,161,248, 0,127,231,251,120,124,100,248, 80, /* 0x 110 */
|
||||
56, 33,247,240, 84,125, 0, 38,128,195, 0, 24, 72, 0, 5, 73, /* 0x 120 */
|
||||
124,127, 27,120,127,163,235,120,124,157,240, 80, 72, 0, 0, 81, /* 0x 130 */
|
||||
127,232, 3,166,184, 65, 8, 20,128, 33, 8, 16, 78,128, 0, 32, /* 0x 140 */
|
||||
56, 0, 0, 90, 68, 0, 0, 2, 64,163, 0, 8, 56, 96,255,255, /* 0x 150 */
|
||||
78,128, 0, 32, 56, 0, 0, 1, 75,255,255,236, 56, 0, 0, 3, /* 0x 160 */
|
||||
75,255,255,228, 56, 0, 0, 5, 75,255,255,220, 56, 0, 0, 6, /* 0x 170 */
|
||||
75,255,255,212, 56, 0, 0,125, 75,255,255,204, 56, 0, 0, 91, /* 0x 180 */
|
||||
75,255,255,196, 56, 0, 0, 45, 75,255,255,188,124, 8, 2,166, /* 0x 190 */
|
||||
148, 33,255,240,144, 1, 0, 20,128, 3, 0, 0,129, 35, 0, 4, /* 0x 1a0 */
|
||||
127,128, 40, 64, 64,188, 0, 12, 56, 96, 0,127, 75,255,255,169, /* 0x 1b0 */
|
||||
47,133, 0, 0, 65,158, 0, 28,124,169, 3,166,136, 9, 0, 0, /* 0x 1c0 */
|
||||
57, 41, 0, 1,152, 4, 0, 0, 56,132, 0, 1, 66, 0,255,240, /* 0x 1d0 */
|
||||
128, 3, 0, 0,129, 35, 0, 4,124, 5, 0, 80,144, 3, 0, 0, /* 0x 1e0 */
|
||||
125, 41, 42, 20,128, 1, 0, 20, 56, 33, 0, 16,145, 35, 0, 4, /* 0x 1f0 */
|
||||
124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166,148, 33,255,192, /* 0x 200 */
|
||||
191,129, 0, 48,124,159, 35,120,124,126, 27,120,124,188, 43,120, /* 0x 210 */
|
||||
144, 1, 0, 68,124,221, 51,120,128, 4, 0, 0, 47,128, 0, 0, /* 0x 220 */
|
||||
65,158, 1, 32, 56,160, 0, 12,127,195,243,120, 56,129, 0, 16, /* 0x 230 */
|
||||
75,255,255, 93,129, 33, 0, 16,128,161, 0, 20, 47,137, 0, 0, /* 0x 240 */
|
||||
64,190, 0, 36, 60, 0, 33, 88, 96, 0, 80, 85,127,133, 0, 0, /* 0x 250 */
|
||||
64,190, 0, 28,128, 30, 0, 0, 47,128, 0, 0, 65,190, 0,228, /* 0x 260 */
|
||||
72, 0, 0, 12, 47,133, 0, 0, 64,190, 0, 12, 56, 96, 0,127, /* 0x 270 */
|
||||
75,255,254,229,127, 5, 72, 64, 65,185,255,244,128, 31, 0, 0, /* 0x 280 */
|
||||
127,137, 0, 64, 65,189,255,232,128, 31, 0, 4, 64,152, 0,132, /* 0x 290 */
|
||||
124,164, 43,120,128,126, 0, 4,124, 5, 3,120, 56,193, 0, 32, /* 0x 2a0 */
|
||||
136,225, 0, 24,127,136, 3,166, 78,128, 0, 33, 47,131, 0, 0, /* 0x 2b0 */
|
||||
64,190,255,188,128,129, 0, 32,128, 1, 0, 16,127,132, 0, 0, /* 0x 2c0 */
|
||||
64,190,255,172,136,193, 0, 25, 49, 61,255,255,124, 9,233, 16, /* 0x 2d0 */
|
||||
125, 38, 0,208, 85, 41, 15,254,125, 43, 0, 57, 65,162, 0, 20, /* 0x 2e0 */
|
||||
128,127, 0, 4,127,168, 3,166,136,161, 0, 26, 78,128, 0, 33, /* 0x 2f0 */
|
||||
128, 30, 0, 4,129, 97, 0, 20,129, 62, 0, 0,124, 0, 90, 20, /* 0x 300 */
|
||||
125, 43, 72, 80,144, 30, 0, 4,145, 62, 0, 0, 72, 0, 0, 16, /* 0x 310 */
|
||||
124, 4, 3,120,127,195,243,120, 75,255,254,117,129, 97, 0, 16, /* 0x 320 */
|
||||
129, 63, 0, 0,128, 31, 0, 4,125, 43, 72, 80, 47,137, 0, 0, /* 0x 330 */
|
||||
124, 0, 90, 20,144, 31, 0, 4,145, 63, 0, 0, 75,255,254,228, /* 0x 340 */
|
||||
128, 1, 0, 68,187,129, 0, 48, 56, 33, 0, 64,124, 8, 3,166, /* 0x 350 */
|
||||
78,128, 0, 32,124,128, 35,121,124, 9, 3,166, 77,130, 0, 32, /* 0x 360 */
|
||||
56, 0, 0, 0,152, 3, 0, 0, 56, 99, 0, 1, 66, 0,255,248, /* 0x 370 */
|
||||
78,128, 0, 32, 44, 3, 0, 0, 77,130, 0, 32, 48, 4,255,255, /* 0x 380 */
|
||||
125, 96, 33, 16,128, 3, 0, 0,127,128, 32, 0,104, 9, 0, 1, /* 0x 390 */
|
||||
33, 73, 0, 0,125, 42, 73, 20,125, 42, 88, 57, 65,158, 0, 8, /* 0x 3a0 */
|
||||
65,162, 0, 16,144,163, 0, 4,144,131, 0, 0, 78,128, 0, 32, /* 0x 3b0 */
|
||||
56, 99, 0, 8, 75,255,255,208,124, 8, 2,166,148, 33,255,160, /* 0x 3c0 */
|
||||
125,128, 0, 38,190, 65, 0, 40,124,121, 27,120,124,151, 35,120, /* 0x 3d0 */
|
||||
144, 1, 0,100,124,181, 43,120,161, 67, 0, 44,124,210, 51,120, /* 0x 3e0 */
|
||||
160, 3, 0, 16,124,243, 59,120, 53, 74,255,255,129, 35, 0, 28, /* 0x 3f0 */
|
||||
104, 0, 0, 3,145,129, 0, 36,124, 0, 0,208,127, 99, 74, 20, /* 0x 400 */
|
||||
84, 3, 46,246,125, 20, 67,120, 56, 99, 8, 34,127,107,219,120, /* 0x 410 */
|
||||
59,128,255,255, 59,192, 0, 0, 59,224, 0, 0, 65,128, 0, 72, /* 0x 420 */
|
||||
57, 74, 0, 1,125, 73, 3,166,128, 11, 0, 0, 47,128, 0, 1, /* 0x 430 */
|
||||
64,190, 0, 44,129, 43, 0, 8,127,137,224, 64, 64,156, 0, 12, /* 0x 440 */
|
||||
131,235, 0, 16,125, 60, 75,120,128, 11, 0, 20,124, 0, 74, 20, /* 0x 450 */
|
||||
127,158, 0, 64, 64,156, 0, 8,124, 30, 3,120, 57,107, 0, 32, /* 0x 460 */
|
||||
66, 0,255,200, 87,128, 5, 62, 87,156, 0, 38,125, 60,240, 80, /* 0x 470 */
|
||||
127,255, 2, 20, 57, 41, 15,255, 56, 31, 15,255, 85, 62, 0, 38, /* 0x 480 */
|
||||
84, 31, 0, 38,124,102, 27,120,127,196,243,120, 56,160, 0, 7, /* 0x 490 */
|
||||
126,167,171,120, 57, 0, 0, 0,127,131,227,120, 75,255,252,165, /* 0x 4a0 */
|
||||
124,159,240, 80,124, 3,242, 20,124,125, 27,120, 56,160, 0, 0, /* 0x 4b0 */
|
||||
124, 99,250, 20,144, 1, 0, 8, 75,255,252,189,160, 25, 0, 44, /* 0x 4c0 */
|
||||
58,192, 0, 0,127, 28,232, 80,127,150, 0, 0, 64,156, 1,116, /* 0x 4d0 */
|
||||
45,151, 0, 0, 65,142, 0, 40,128, 27, 0, 0, 47,128, 0, 6, /* 0x 4e0 */
|
||||
64,190, 0, 28,128,187, 0, 8,126, 67,147,120, 56,128, 0, 3, /* 0x 4f0 */
|
||||
124,165,194, 20, 75,255,254,129, 72, 0, 1, 52,128, 27, 0, 0, /* 0x 500 */
|
||||
47,128, 0, 1, 64,190, 1, 40,128, 27, 0, 24, 61, 32,115, 81, /* 0x 510 */
|
||||
129, 91, 0, 8, 97, 41, 98, 64, 84, 0, 22,250,129,123, 0, 20, /* 0x 520 */
|
||||
125, 41, 4, 48, 85, 94, 5, 62, 48, 23,255,255,124,160,185, 16, /* 0x 530 */
|
||||
128, 27, 0, 16, 85, 58, 7,126,127,170, 90, 20, 84,165, 8, 60, /* 0x 540 */
|
||||
127,254, 80, 80,144, 1, 0, 16,127,128,242, 20,145, 65, 0, 20, /* 0x 550 */
|
||||
127,255,194, 20,127,189,194, 20,124,165,211,120, 65,142, 0, 12, /* 0x 560 */
|
||||
56,192, 0, 50, 72, 0, 0, 8, 56,192, 0, 18,129, 27, 0, 4, /* 0x 570 */
|
||||
127,227,251,120,127,132,227,120,126,167,171,120,125, 30, 64, 80, /* 0x 580 */
|
||||
75,255,251,193,127,159, 24, 0, 64,158, 0,104, 65,174, 0, 24, /* 0x 590 */
|
||||
126,227,187,120, 56,129, 0, 16,126,101,155,120,126,134,163,120, /* 0x 5a0 */
|
||||
75,255,252, 89, 87, 64,255,254, 46, 0, 0, 0, 65,178, 0, 16, /* 0x 5b0 */
|
||||
127,196,243,120,127,227,251,120, 75,255,253,157,124, 28, 0,208, /* 0x 5c0 */
|
||||
84, 30, 5, 62, 65,178, 0, 16,124,127,226, 20,127,196,243,120, /* 0x 5d0 */
|
||||
75,255,253,133, 65,174, 0, 36,127,227,251,120,127,132,227,120, /* 0x 5e0 */
|
||||
127, 69,211,120, 75,255,251,145, 47,131, 0, 0, 65,190, 0, 12, /* 0x 5f0 */
|
||||
56, 96, 0,127, 75,255,251, 97,124, 28,242, 20,127,255, 2, 20, /* 0x 600 */
|
||||
127,159,232, 64, 64,188, 0, 40,124,159,232, 80,127, 69,211,120, /* 0x 610 */
|
||||
127,227,251,120, 56,192, 0, 50, 56,224, 0, 0, 57, 0, 0, 0, /* 0x 620 */
|
||||
75,255,251, 33,127,159, 24, 0, 64,190,255,200,160, 25, 0, 44, /* 0x 630 */
|
||||
58,214, 0, 1, 59,123, 0, 32,127,150, 0, 0, 75,255,254,144, /* 0x 640 */
|
||||
128,121, 0, 24,128, 1, 0,100,129,129, 0, 36,124, 99,194, 20, /* 0x 650 */
|
||||
124, 8, 3,166,186, 65, 0, 40,125,129,129, 32, 56, 33, 0, 96, /* 0x 660 */
|
||||
78,128, 0, 32,124, 8, 2,166,148, 33,255,192, 56,132,255,232, /* 0x 670 */
|
||||
191, 97, 0, 44,144,129, 0, 8,124,191, 43,120,144, 1, 0, 68, /* 0x 680 */
|
||||
56, 3, 0, 24,144, 1, 0, 12,124,229, 59,120,128, 3, 0, 24, /* 0x 690 */
|
||||
56,192, 0, 0,200, 1, 0, 8, 56, 97, 0, 8, 56,129, 0, 16, /* 0x 6a0 */
|
||||
59,223, 0, 52,125, 61, 75,120,124,251, 59,120,144, 1, 0, 16, /* 0x 6b0 */
|
||||
125, 28, 67,120,216, 1, 0, 24,147,225, 0, 20, 75,255,251, 61, /* 0x 6c0 */
|
||||
128,190, 0, 8,127,163,235,120, 56,128, 0, 3, 56,165, 0, 52, /* 0x 6d0 */
|
||||
75,255,252,165,160,191, 0, 44,127,163,235,120, 56,128, 0, 5, /* 0x 6e0 */
|
||||
75,255,252,149,128,191, 0, 24,127,163,235,120, 56,128, 0, 9, /* 0x 6f0 */
|
||||
75,255,252,133,127,103,219,120,127,136,227,120,127,227,251,120, /* 0x 700 */
|
||||
127,166,235,120, 56,129, 0, 24, 56,160, 0, 0, 59, 96, 0, 0, /* 0x 710 */
|
||||
75,255,252,169,160, 31, 0, 44,124,124, 27,120,127,155, 0, 0, /* 0x 720 */
|
||||
64,156, 0,124,128, 30, 0, 0, 59,123, 0, 1, 56,128, 0, 0, /* 0x 730 */
|
||||
56,160, 0, 0, 47,128, 0, 3, 64,190, 0, 88,128,126, 0, 8, /* 0x 740 */
|
||||
75,255,250, 37,127,228,251,120,124,125, 27,121, 56,160, 2, 0, /* 0x 750 */
|
||||
65,128, 0, 40, 75,255,250, 9, 56,128, 0, 0, 47,131, 2, 0, /* 0x 760 */
|
||||
127,165,235,120,127,227,251,120, 56,192, 0, 0, 56,224, 0, 0, /* 0x 770 */
|
||||
57, 0, 0, 0, 65,190, 0, 12, 56, 96, 0,127, 75,255,249,217, /* 0x 780 */
|
||||
75,255,252, 57,124,124, 27,120,127,163,235,120, 75,255,249,225, /* 0x 790 */
|
||||
160, 31, 0, 44, 59,222, 0, 32, 75,255,255,132,128, 1, 0, 68, /* 0x 7a0 */
|
||||
127,131,227,120,187, 97, 0, 44, 56, 33, 0, 64,124, 8, 3,166, /* 0x 7b0 */
|
||||
78,128, 0, 32, 0, 46,115,104,115,116,114,116, 97, 98, 0, 46, /* 0x 7c0 */
|
||||
116,101,120,116, 0, 46, 98,115,115, 0, 46,115,100, 97,116, 97, /* 0x 7d0 */
|
||||
0, 46,115,100, 97,116, 97, 50, 0, 46,110,111,116,101, 46, 71, /* 0x 7e0 */
|
||||
78, 85, 45,115,116, 97, 99,107, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 7f0 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 800 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 810 */
|
||||
0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 1, 0, 0, 0, 6, /* 0x 820 */
|
||||
0, 16, 0,128, 0, 0, 0,128, 0, 0, 7, 68, 0, 0, 0, 0, /* 0x 830 */
|
||||
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 17, /* 0x 840 */
|
||||
0, 0, 0, 8, 0, 0, 0, 3, 0, 16, 7,196, 0, 0, 7,196, /* 0x 850 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0x 860 */
|
||||
0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 1, 0, 0, 0, 3, /* 0x 870 */
|
||||
0, 16, 7,196, 0, 0, 7,196, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 880 */
|
||||
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 29, /* 0x 890 */
|
||||
0, 0, 0, 1, 0, 0, 0, 2, 0, 16, 7,196, 0, 0, 7,196, /* 0x 8a0 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, /* 0x 8b0 */
|
||||
0, 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 7, 0, 0, 0, 0, /* 0x 8c0 */
|
||||
0, 0, 0, 0, 0, 0, 7,196, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 8d0 */
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, /* 0x 8e0 */
|
||||
0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,196, /* 0x 8f0 */
|
||||
0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0x 900 */
|
||||
0, 0, 0, 0 /* 0x 910 */
|
||||
};
|
||||
+36
-33
@@ -1,9 +1,10 @@
|
||||
/* fold_exec86.h -- created from fold_exec86.bin, 931 (0x3a3) bytes
|
||||
/* fold_exec86.h -- created from fold_exec86.bin, 947 (0x3b3) bytes
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
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
|
||||
@@ -26,15 +27,16 @@
|
||||
*/
|
||||
|
||||
|
||||
#define LINUX_I386EXEC_FOLD_ADLER32 0x598e8b17
|
||||
#define LINUX_I386EXEC_FOLD_CRC32 0xe031336e
|
||||
#define LINUX_I386EXEC_FOLD_SIZE 947
|
||||
#define LINUX_I386EXEC_FOLD_ADLER32 0xf7998d99
|
||||
#define LINUX_I386EXEC_FOLD_CRC32 0x4ada49e8
|
||||
|
||||
unsigned char linux_i386exec_fold[931] = {
|
||||
unsigned char linux_i386exec_fold[947] = {
|
||||
127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */
|
||||
2, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, /* 0x 10 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 1, 0, 0, 0, /* 0x 20 */
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 64, 0, /* 0x 30 */
|
||||
0, 16, 64, 0,163, 3, 0, 0,164, 3, 0, 0, 7, 0, 0, 0, /* 0x 40 */
|
||||
0, 16, 64, 0,179, 3, 0, 0,180, 3, 0, 0, 7, 0, 0, 0, /* 0x 40 */
|
||||
0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 50 */
|
||||
88, 88, 88,137,225,141, 84,132, 4,139,115, 24,131,195, 96, 41, /* 0x 60 */
|
||||
222,141,125, 2, 96,232,197, 0, 0, 0,244, 0, 83,137,195,139, /* 0x 70 */
|
||||
@@ -44,8 +46,8 @@ unsigned char linux_i386exec_fold[931] = {
|
||||
229, 87, 86,137,202, 83,131,236, 32,139, 93, 8,106, 5, 88,205, /* 0x b0 */
|
||||
128,133,192,137,199,120,108,199, 69,212, 47,112,114,111,199, 69, /* 0x c0 */
|
||||
216, 99, 47, 0, 0,106, 20, 88,205,128,141, 85,218,141,117,212, /* 0x d0 */
|
||||
232,155, 2, 0, 0,141, 80, 4,137,243,199, 0, 47,102,100, 47, /* 0x e0 */
|
||||
137,248,232,137, 2, 0, 0,186, 1, 0, 0, 0,106, 33, 88,106, /* 0x f0 */
|
||||
232,171, 2, 0, 0,141, 80, 4,137,243,199, 0, 47,102,100, 47, /* 0x e0 */
|
||||
137,248,232,153, 2, 0, 0,186, 1, 0, 0, 0,106, 33, 88,106, /* 0x f0 */
|
||||
5, 89,205,128, 61, 85, 80, 88, 50,117, 33,139, 93, 8,106, 10, /* 0x 100 */
|
||||
88,205,128,185, 2, 0, 0, 0,137,251,106, 55, 88,205,128,137, /* 0x 110 */
|
||||
243,139, 77, 12,139, 85, 16,106, 11, 88,205,128,137,251,106, 6, /* 0x 120 */
|
||||
@@ -53,40 +55,41 @@ unsigned char linux_i386exec_fold[931] = {
|
||||
137,229, 87, 86, 83,131,236,112,141,125,228,139, 77, 24,139, 69, /* 0x 140 */
|
||||
16,139, 85, 12,137,203,129,227, 0,240,255,255,137, 69,156,137, /* 0x 150 */
|
||||
85,148,137,206,137, 77,152,137, 93,144,165,165,165,131,109,148, /* 0x 160 */
|
||||
12,129,125,228, 85, 80, 88, 51,137,117,152, 15,133, 95, 1, 0, /* 0x 170 */
|
||||
12,129,125,228, 85, 80, 88, 51,137,117,152, 15,133,100, 1, 0, /* 0x 170 */
|
||||
0,199, 69,196, 47,116,109,112,199, 69,200, 47,117,112,120,141, /* 0x 180 */
|
||||
77,215,106, 20, 88,205,128,137,194,106, 4,137,200,141,117,211, /* 0x 190 */
|
||||
232,215,254,255,255,141, 93,172,137,199,198, 69,215, 0, 51,125, /* 0x 1a0 */
|
||||
228, 49,201,106, 78, 88,205,128, 51,125,172,139, 85,176,137,240, /* 0x 1b0 */
|
||||
199, 4, 36, 7, 0, 0, 0,193,226, 12,141, 93,196, 49,250,232, /* 0x 1c0 */
|
||||
168,254,255,255, 88,106, 10, 88,205,128,131,248,254,116, 8,133, /* 0x 1d0 */
|
||||
192, 15,133,249, 0, 0, 0,185,194, 0, 0, 0,186,192, 1, 0, /* 0x 1e0 */
|
||||
192, 15,133,254, 0, 0, 0,185,194, 0, 0, 0,186,192, 1, 0, /* 0x 1e0 */
|
||||
0,141, 93,196,106, 5, 88,205,128,137, 69,136,139, 77,232,137, /* 0x 1f0 */
|
||||
195,106, 93, 88,205,128,133,192, 15,133,202, 0, 0, 0,106, 0, /* 0x 200 */
|
||||
195,106, 93, 88,205,128,133,192, 15,133,207, 0, 0, 0,106, 0, /* 0x 200 */
|
||||
83,106, 1,106, 3, 81,106, 0,232,131,254,255,255,131,196, 24, /* 0x 210 */
|
||||
61, 0,240,255,255,137, 69,132, 15,135,170, 0, 0, 0,139, 69, /* 0x 220 */
|
||||
61, 0,240,255,255,137, 69,132, 15,135,175, 0, 0, 0,139, 69, /* 0x 220 */
|
||||
232,106, 0,106, 0, 5,255, 15, 0, 0,106, 50, 37, 0,240,255, /* 0x 230 */
|
||||
255,106, 3, 3, 69,132,104, 0, 16, 0, 0, 80,232, 79,254,255, /* 0x 240 */
|
||||
255,131,196, 24,141,125,180,139,117,152,165,165,165,139, 77,180, /* 0x 250 */
|
||||
131,109,148, 12,133,201,137,117,152,139, 85,184,117, 20,129,250, /* 0x 260 */
|
||||
85, 80, 88, 33,117, 98,131,125,232, 0, 15,132,136, 0, 0, 0, /* 0x 270 */
|
||||
235, 86, 57,202,119, 82, 59, 85,236,119, 77, 57,202,115, 31,141, /* 0x 280 */
|
||||
69,168, 80,255,117,132, 82,255,117,152,255, 85,156,131,196, 16, /* 0x 290 */
|
||||
133,192,117, 52,139, 69,180, 57, 69,168,117, 44,235, 8,139,125, /* 0x 2a0 */
|
||||
132,139,117,152,243,164,139, 77,180,139, 93,132,106, 91, 88,205, /* 0x 2b0 */
|
||||
128,139, 69,184, 1,203, 41, 69,148, 41, 77,232, 1, 69,152,131, /* 0x 2c0 */
|
||||
125,148, 0,137, 93,132,121, 18,141, 93,196,106, 10, 88,205,128, /* 0x 2d0 */
|
||||
106,127, 91,106, 1, 88,205,128,235,246,139, 77,152,139, 93,144, /* 0x 2e0 */
|
||||
129,225, 0,240,255,255, 43, 77,144,106, 91, 88,205,128, 1,203, /* 0x 2f0 */
|
||||
137, 93,144,233, 76,255,255,255,139, 93,136,106, 6, 88,205,128, /* 0x 300 */
|
||||
133,192,117,196,255,117, 28,255,117, 32,141,117,196, 86,232,137, /* 0x 310 */
|
||||
253,255,255,133,192,120,177,106, 2, 88,205,128,133,192,117, 49, /* 0x 320 */
|
||||
106, 2, 88,205,128,133,192,137,193,117, 31,199, 69,160, 85, 80, /* 0x 330 */
|
||||
88, 52,184,162, 0, 0, 0,141, 93,160,199, 69,164, 0, 0, 0, /* 0x 340 */
|
||||
0,205,128,137,243,106, 10, 88,205,128, 49,219,106, 1, 88,205, /* 0x 350 */
|
||||
128, 49,201,131,203,255,137,202,106, 7, 88,205,128,141, 93,196, /* 0x 360 */
|
||||
139, 77, 32,139, 85, 28,106, 11, 88,205,128,233, 88,255,255,255, /* 0x 370 */
|
||||
87,137,215,106, 10,252, 89,232, 5, 0, 0, 0,136, 39,151, 95, /* 0x 380 */
|
||||
195,153,247,241, 82,133,192,116, 5,232,243,255,255,255, 88, 4, /* 0x 390 */
|
||||
48,170,195 /* 0x 3a0 */
|
||||
85, 80, 88, 33,117,103,131,125,232, 0, 15,132,141, 0, 0, 0, /* 0x 270 */
|
||||
235, 91, 57,202,119, 87, 59, 85,236,119, 82, 57,202,115, 36, 15, /* 0x 280 */
|
||||
182, 69,188, 80,141, 69,168, 80,255,117,132, 82,255,117,152,255, /* 0x 290 */
|
||||
85,156,131,196, 20,133,192,117, 52,139, 69,180, 57, 69,168,117, /* 0x 2a0 */
|
||||
44,235, 8,139,125,132,139,117,152,243,164,139, 77,180,139, 93, /* 0x 2b0 */
|
||||
132,106, 91, 88,205,128,139, 69,184, 1,203, 41, 69,148, 41, 77, /* 0x 2c0 */
|
||||
232, 1, 69,152,131,125,148, 0,137, 93,132,121, 18,141, 93,196, /* 0x 2d0 */
|
||||
106, 10, 88,205,128,106,127, 91,106, 1, 88,205,128,235,246,139, /* 0x 2e0 */
|
||||
77,152,139, 93,144,129,225, 0,240,255,255, 43, 77,144,106, 91, /* 0x 2f0 */
|
||||
88,205,128, 1,203,137, 93,144,233, 71,255,255,255,139, 93,136, /* 0x 300 */
|
||||
106, 6, 88,205,128,133,192,117,196,255,117, 28,255,117, 32,141, /* 0x 310 */
|
||||
117,196, 86,232,132,253,255,255,133,192,120,177,106, 2, 88,205, /* 0x 320 */
|
||||
128,133,192,117, 49,106, 2, 88,205,128,133,192,137,193,117, 31, /* 0x 330 */
|
||||
199, 69,160, 85, 80, 88, 52,184,162, 0, 0, 0,141, 93,160,199, /* 0x 340 */
|
||||
69,164, 0, 0, 0, 0,205,128,137,243,106, 10, 88,205,128, 49, /* 0x 350 */
|
||||
219,106, 1, 88,205,128, 49,201,131,203,255,137,202,106, 7, 88, /* 0x 360 */
|
||||
205,128,141, 93,196,139, 77, 32,139, 85, 28,106, 11, 88,205,128, /* 0x 370 */
|
||||
233, 88,255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 380 */
|
||||
87,137,215,106, 10,252, 89,232, 5, 0, 0, 0,136, 39,151, 95, /* 0x 390 */
|
||||
195,153,247,241, 82,133,192,116, 5,232,243,255,255,255, 88, 4, /* 0x 3a0 */
|
||||
48,170,195 /* 0x 3b0 */
|
||||
};
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/* fold_machppc32.S -- linkage to C code to process Mach-o binary
|
||||
*
|
||||
* 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-2005 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>
|
||||
*/
|
||||
#include "ppc_regs.h"
|
||||
|
||||
sz_b_info= 12
|
||||
sz_unc= 0
|
||||
sz_cpr= 4
|
||||
|
||||
sz_l_info= 12
|
||||
sz_p_info= 12
|
||||
|
||||
/* Mach_ppc_thread_state */
|
||||
srr0 = 0*4
|
||||
srr1 = 1*4
|
||||
reg0 = 2*4
|
||||
|
||||
reg_cr = 34*4
|
||||
reg_xer = 35*4
|
||||
reg_lr = 36*4
|
||||
reg_ctr = 37*4
|
||||
reg_mq = 38*4
|
||||
reg_vrsave = 39*4
|
||||
|
||||
|
||||
/* In:
|
||||
r31= &decompress; also 8+ (char *)&(offset to {l_info; p_info; b_info})
|
||||
*/
|
||||
fold_begin:
|
||||
call L90
|
||||
#include "ppc_bxx.S"
|
||||
|
||||
L90:
|
||||
li a6,0
|
||||
stwu a6,-4(sp) # default value
|
||||
movr a6,sp # &mhdrp
|
||||
mflr a5 # &ppcbxx: f_unfilter
|
||||
|
||||
lwz a1,-8(r31) # offset to {l_info; p_info; b_info}
|
||||
subf a0,a1,r31 # &l_info
|
||||
lwz a3,sz_unc+sz_p_info+sz_l_info(a0) # sz_mach_headers
|
||||
cmpli 0,a3,2048; bgt L100; li a3,2048 # at least 2KB for /usr/bin/dyld
|
||||
L100:
|
||||
movr r29,sp # remember for restoring later
|
||||
subf sp,a3,sp # alloca
|
||||
movr a2,sp # &temp char[sz_mach_headers]
|
||||
addi sp,sp,-4*6 # linkage area assumed by C code (sp,cr,lr, xx,yy,zz)
|
||||
movr a4,r31 # f_decompress
|
||||
call upx_main # Out: a0= &Mach_ppc_thread_state of dyld
|
||||
|
||||
movr sp,r29 # restore stack pointer
|
||||
lwz t0, srr0(a0); mtctr t0 # entry address
|
||||
/* Next 3 lines probably are not needed, but ... */
|
||||
lwz t0, reg_cr(a0); mtcr t0 # condition code
|
||||
lwz t0,reg_xer(a0); mtxer t0 # extended error reg (CArry, etc.)
|
||||
lwz t0, reg_lr(a0); mtlr t0 # link register
|
||||
|
||||
lmw 4,4*4+reg0(3) # reg 4 thru 31
|
||||
lwz 0,0*4+reg0(3)
|
||||
lwz 2,2*4+reg0(3)
|
||||
lwz 3,3*4+reg0(3)
|
||||
bctr # goto dyld
|
||||
|
||||
SYS_exit =1
|
||||
SYS_fork =2
|
||||
SYS_read =3
|
||||
SYS_write =4
|
||||
SYS_open =5
|
||||
SYS_close =6
|
||||
|
||||
SYS_mmap =197
|
||||
SYS_mprotect= 74
|
||||
|
||||
/* SYS_mmap takes a 64-bit off_t, but gcc-3.4.1-20040827 passes long long
|
||||
in wrong registers. So change C interface to use size_t (32-bits) instead
|
||||
of off_t (64 bits), and convert here.
|
||||
*/
|
||||
mmap: .globl mmap
|
||||
movr a6,a5; li a5,0 # zero extend 6th arg size_t to off_t
|
||||
li 0,SYS_mmap
|
||||
sysgo:
|
||||
sc
|
||||
li a0,-1 # failure return
|
||||
ret
|
||||
|
||||
exit: .globl exit
|
||||
li 0,SYS_exit; b sysgo
|
||||
read: .globl read
|
||||
li 0,SYS_read; b sysgo
|
||||
open: .globl open
|
||||
li 0,SYS_open; b sysgo
|
||||
close: .globl close
|
||||
li 0,SYS_close; b sysgo
|
||||
mprotect: .globl mprotect
|
||||
li 0,SYS_mprotect; b sysgo
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/* fold_machppc32.h -- created from fold_machppc32.bin, 1544 (0x608) 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 FOLD_MACHPPC32_SIZE 1544
|
||||
#define FOLD_MACHPPC32_ADLER32 0xa57805a9
|
||||
#define FOLD_MACHPPC32_CRC32 0x2fb8902f
|
||||
|
||||
unsigned char fold_machppc32[1544] = {
|
||||
72, 0, 0,105, 40, 6, 0,208, 76,130, 0, 32, 84,132,240,191, /* 0x 0 */
|
||||
77,130, 0, 32, 60, 0, 0, 16,124, 4, 0, 64, 65,128, 0, 8, /* 0x 10 */
|
||||
124, 4, 3,120, 56,165, 1, 32,124,103, 27,120, 56, 99,255,252, /* 0x 20 */
|
||||
124,137, 3,166, 72, 0, 0, 28, 84, 75, 2,186,125, 99, 88, 80, /* 0x 30 */
|
||||
125,107, 58, 20, 81, 98, 1,186,144, 67, 0, 0, 78, 64, 0, 32, /* 0x 40 */
|
||||
132, 67, 0, 4, 84, 75, 85,190,124, 11, 40, 64, 65,162,255,220, /* 0x 50 */
|
||||
66, 0,255,240, 78,128, 0, 32, 57, 32, 0, 0,149, 33,255,252, /* 0x 60 */
|
||||
124, 41, 11,120,125, 8, 2,166,128,159,255,248,124,100,248, 80, /* 0x 70 */
|
||||
128,195, 0, 24, 40, 6, 8, 0, 65,129, 0, 8, 56,192, 8, 0, /* 0x 80 */
|
||||
124, 61, 11,120,124, 38, 8, 80,124, 37, 11,120, 56, 33,255,232, /* 0x 90 */
|
||||
127,231,251,120, 72, 0, 4, 37,127,161,235,120,128, 67, 0, 0, /* 0x a0 */
|
||||
124, 73, 3,166,128, 67, 0,136,124, 79,241, 32,128, 67, 0,140, /* 0x b0 */
|
||||
124, 65, 3,166,128, 67, 0,144,124, 72, 3,166,184,131, 0, 24, /* 0x c0 */
|
||||
128, 3, 0, 8,128, 67, 0, 16,128, 99, 0, 20, 78,128, 4, 32, /* 0x d0 */
|
||||
125, 9, 67,120, 57, 0, 0, 0, 56, 0, 0,197, 68, 0, 0, 2, /* 0x e0 */
|
||||
56, 96,255,255, 78,128, 0, 32, 56, 0, 0, 1, 75,255,255,240, /* 0x f0 */
|
||||
56, 0, 0, 3, 75,255,255,232, 56, 0, 0, 5, 75,255,255,224, /* 0x 100 */
|
||||
56, 0, 0, 6, 75,255,255,216, 56, 0, 0, 74, 75,255,255,208, /* 0x 110 */
|
||||
124, 8, 2,166,148, 33,255,240,144, 1, 0, 20,128, 3, 0, 0, /* 0x 120 */
|
||||
129, 35, 0, 4,127,128, 40, 64, 64,188, 0, 12, 56, 96, 0,127, /* 0x 130 */
|
||||
75,255,255,185, 47,133, 0, 0, 65,158, 0, 28,124,169, 3,166, /* 0x 140 */
|
||||
136, 9, 0, 0, 57, 41, 0, 1,152, 4, 0, 0, 56,132, 0, 1, /* 0x 150 */
|
||||
66, 0,255,240,128, 3, 0, 0,129, 35, 0, 4,124, 5, 0, 80, /* 0x 160 */
|
||||
144, 3, 0, 0,125, 41, 42, 20,128, 1, 0, 20, 56, 33, 0, 16, /* 0x 170 */
|
||||
145, 35, 0, 4,124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166, /* 0x 180 */
|
||||
148, 33,255,192,191,129, 0, 48,124,159, 35,120,124,126, 27,120, /* 0x 190 */
|
||||
124,188, 43,120,144, 1, 0, 68,124,221, 51,120,128, 4, 0, 0, /* 0x 1a0 */
|
||||
47,128, 0, 0, 65,158, 1, 32, 56,160, 0, 12,127,195,243,120, /* 0x 1b0 */
|
||||
56,129, 0, 16, 75,255,255, 93,129, 33, 0, 16,128,161, 0, 20, /* 0x 1c0 */
|
||||
47,137, 0, 0, 64,190, 0, 36, 60, 0, 33, 88, 96, 0, 80, 85, /* 0x 1d0 */
|
||||
127,133, 0, 0, 64,190, 0, 28,128, 30, 0, 0, 47,128, 0, 0, /* 0x 1e0 */
|
||||
65,190, 0,228, 72, 0, 0, 12, 47,133, 0, 0, 64,190, 0, 12, /* 0x 1f0 */
|
||||
56, 96, 0,127, 75,255,254,245,127, 5, 72, 64, 65,185,255,244, /* 0x 200 */
|
||||
128, 31, 0, 0,127,137, 0, 64, 65,189,255,232,128, 31, 0, 4, /* 0x 210 */
|
||||
64,152, 0,132,124,164, 43,120,128,126, 0, 4,124, 5, 3,120, /* 0x 220 */
|
||||
56,193, 0, 32,136,225, 0, 24,127,136, 3,166, 78,128, 0, 33, /* 0x 230 */
|
||||
47,131, 0, 0, 64,190,255,188,128,129, 0, 32,128, 1, 0, 16, /* 0x 240 */
|
||||
127,132, 0, 0, 64,190,255,172,136,193, 0, 25, 49, 61,255,255, /* 0x 250 */
|
||||
124, 9,233, 16,125, 38, 0,208, 85, 41, 15,254,125, 43, 0, 57, /* 0x 260 */
|
||||
65,162, 0, 20,128,127, 0, 4,127,168, 3,166,136,161, 0, 26, /* 0x 270 */
|
||||
78,128, 0, 33,129, 97, 0, 20,128, 30, 0, 4,129, 62, 0, 0, /* 0x 280 */
|
||||
124, 0, 90, 20,125, 43, 72, 80,144, 30, 0, 4,145, 62, 0, 0, /* 0x 290 */
|
||||
72, 0, 0, 16,124, 4, 3,120,127,195,243,120, 75,255,254,117, /* 0x 2a0 */
|
||||
129, 97, 0, 16,129, 63, 0, 0,128, 31, 0, 4,125, 43, 72, 80, /* 0x 2b0 */
|
||||
47,137, 0, 0,124, 0, 90, 20,144, 31, 0, 4,145, 63, 0, 0, /* 0x 2c0 */
|
||||
75,255,254,228,128, 1, 0, 68,187,129, 0, 48, 56, 33, 0, 64, /* 0x 2d0 */
|
||||
124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166,148, 33,255,176, /* 0x 2e0 */
|
||||
190, 97, 0, 28,125,128, 0, 38, 58,224, 0, 0,124,122, 27,120, /* 0x 2f0 */
|
||||
144, 1, 0, 84,124,155, 35,120,128, 3, 0, 16,124,179, 43,120, /* 0x 300 */
|
||||
145,129, 0, 24,124,212, 51,120,127,151, 0, 64,124,245, 59,120, /* 0x 310 */
|
||||
125, 22, 67,120, 59,195, 0, 28, 59, 0, 0, 0, 64,156, 1,124, /* 0x 320 */
|
||||
129, 62, 0, 0, 47,137, 0, 1, 64,190, 1, 48,129, 62, 0, 24, /* 0x 330 */
|
||||
129,126, 0, 36, 85, 61, 5, 62,128, 30, 0, 28,127,139,234, 20, /* 0x 340 */
|
||||
145, 97, 0, 8, 46, 28, 0, 0,127, 41, 2, 20,145, 33, 0, 12, /* 0x 350 */
|
||||
127,253, 72, 80, 65,146, 0, 72, 47,155, 0, 0, 64,190, 0, 16, /* 0x 360 */
|
||||
47,139, 0, 0, 56,192, 0, 18, 64,158, 0, 8, 56,192, 16, 18, /* 0x 370 */
|
||||
47,139, 0, 0,126,103,155,120, 64,158, 0, 8, 56,224,255,255, /* 0x 380 */
|
||||
129, 30, 0, 32,127,227,251,120,127,132,227,120, 56,160, 0, 3, /* 0x 390 */
|
||||
75,255,253, 65,127,159, 24, 0, 64,158, 0,128, 47,155, 0, 0, /* 0x 3a0 */
|
||||
65,158, 0, 52,128, 30, 0, 36, 47,128, 0, 0, 65,158, 0, 40, /* 0x 3b0 */
|
||||
128, 30, 0, 32, 47,128, 0, 0, 64,158, 0, 8,147,244, 0, 0, /* 0x 3c0 */
|
||||
127, 99,219,120, 56,129, 0, 8,126,165,171,120,126,198,179,120, /* 0x 3d0 */
|
||||
75,255,253,173,124, 28, 0,208,125, 63,226, 20,112, 29, 15,255, /* 0x 3e0 */
|
||||
65,130, 0, 24,127,169, 3,166, 56, 0, 0, 0,152, 9, 0, 0, /* 0x 3f0 */
|
||||
57, 41, 0, 1, 66, 0,255,248, 65,178, 0, 40,128,190, 0, 44, /* 0x 400 */
|
||||
127,227,251,120,127,132,227,120, 76,198, 49,130, 75,255,252,253, /* 0x 410 */
|
||||
47,131, 0, 0, 65,190, 0, 12, 56, 96, 0,127, 75,255,252,205, /* 0x 420 */
|
||||
124, 28,234, 20,127,255, 2, 20,127,159,200, 64, 64,188, 0, 84, /* 0x 430 */
|
||||
128,190, 0, 44,124,159,200, 80,127,227,251,120, 56,192, 16, 18, /* 0x 440 */
|
||||
56,224,255,255, 57, 0, 0, 0, 75,255,252,137,127,159, 24, 0, /* 0x 450 */
|
||||
65,190, 0, 48, 75,255,255,196, 56, 9,255,252, 43,128, 0, 1, /* 0x 460 */
|
||||
65,157, 0, 32,128, 30, 0, 8, 47,128, 0, 1, 64,190, 0, 20, /* 0x 470 */
|
||||
128, 30, 0, 12, 47,128, 0, 40, 64,190, 0, 8, 58,254, 0, 16, /* 0x 480 */
|
||||
128, 26, 0, 16, 59, 24, 0, 1,127,152, 0, 64,128, 30, 0, 4, /* 0x 490 */
|
||||
127,222, 2, 20, 75,255,254,136,128, 1, 0, 84,126,227,187,120, /* 0x 4a0 */
|
||||
129,129, 0, 24,186, 97, 0, 28,124, 8, 3,166, 56, 33, 0, 80, /* 0x 4b0 */
|
||||
125,128,129, 32, 78,128, 0, 32,148, 33,255,192,124, 8, 2,166, /* 0x 4c0 */
|
||||
144,129, 0, 8,191, 65, 0, 40,129, 97, 0, 8,124,191, 43,120, /* 0x 4d0 */
|
||||
144, 1, 0, 68, 56, 3, 0, 24, 57,107,255,232,144, 1, 0, 20, /* 0x 4e0 */
|
||||
145, 97, 0, 16,124,253, 59,120,128, 3, 0, 24,125, 60, 75,120, /* 0x 4f0 */
|
||||
200, 1, 0, 16,125, 27, 67,120,124,229, 59,120, 56, 97, 0, 16, /* 0x 500 */
|
||||
56,129, 0, 24,124,218, 51,120, 56,192, 0, 0,144, 1, 0, 24, /* 0x 510 */
|
||||
216, 1, 0, 32, 59,192, 0, 0,147,225, 0, 28, 75,255,252, 97, /* 0x 520 */
|
||||
127,167,235,120,127,104,219,120,127,227,251,120,127,134,227,120, /* 0x 530 */
|
||||
56,129, 0, 32, 56,160,255,255, 75,255,253,161,128, 31, 0, 16, /* 0x 540 */
|
||||
124,123, 27,120, 59,191, 0, 28,127,158, 0, 64, 64,156, 0,148, /* 0x 550 */
|
||||
128, 29, 0, 0, 59,222, 0, 1, 56,128, 0, 0, 56,160, 0, 0, /* 0x 560 */
|
||||
47,128, 0, 14, 64,190, 0,104,128,125, 0, 8,124,125, 26, 20, /* 0x 570 */
|
||||
76,198, 49,130, 75,255,251,133,127,228,251,120,124,124, 27,121, /* 0x 580 */
|
||||
127, 69,211,120, 65,128, 0, 44, 76,198, 49,130, 75,255,251,101, /* 0x 590 */
|
||||
56,128, 0, 0,127,154, 24, 0,127,133,227,120,127,227,251,120, /* 0x 5a0 */
|
||||
56,192, 0, 0, 56,224, 0, 0, 57, 0, 0, 0, 65,190, 0, 12, /* 0x 5b0 */
|
||||
56, 96, 0,127, 75,255,251, 53, 75,255,253, 33,124,123, 27,120, /* 0x 5c0 */
|
||||
127,131,227,120, 76,198, 49,130, 75,255,251, 57,128, 31, 0, 16, /* 0x 5d0 */
|
||||
129, 61, 0, 4,127,158, 0, 64,127,189, 74, 20, 75,255,255,112, /* 0x 5e0 */
|
||||
128, 1, 0, 68,127, 99,219,120,187, 65, 0, 40, 56, 33, 0, 64, /* 0x 5f0 */
|
||||
124, 8, 3,166, 78,128, 0, 32 /* 0x 600 */
|
||||
};
|
||||
@@ -0,0 +1,119 @@
|
||||
; fold_pti86.asm -- linkage to C code to act as ELF PT_INTERP
|
||||
;
|
||||
; This file is part of the UPX executable compressor.
|
||||
;
|
||||
; Copyright (C) 2000-2004 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>
|
||||
;
|
||||
|
||||
|
||||
BITS 32
|
||||
SECTION .text
|
||||
CPU 386
|
||||
|
||||
|
||||
%define PAGE_SIZE ( 1<<12)
|
||||
|
||||
%define AT_NULL 0
|
||||
%define AT_PHDR 3
|
||||
|
||||
%define szElf32_Ehdr 0x34
|
||||
%define szElf32_Phdr 8*4
|
||||
%define e_entry (16 + 2*2 + 4)
|
||||
%define p_vaddr 2*4
|
||||
%define p_memsz 5*4
|
||||
%define szb_info 12
|
||||
%define szl_info 12
|
||||
%define szp_info 12
|
||||
%define a_type 0
|
||||
%define a_val 4
|
||||
%define sz_auxv 8
|
||||
|
||||
%define MAP_FIXED 0x10
|
||||
%define MAP_PRIVATE 0x02
|
||||
%define MAP_ANONYMOUS 0x20
|
||||
%define PROT_READ 1
|
||||
%define PROT_WRITE 2
|
||||
%define PROT_EXEC 4
|
||||
%define __NR_mmap 90
|
||||
%define __NR_munmap 91
|
||||
|
||||
%define OVERHEAD 2048
|
||||
%define MAX_ELF_HDR 512
|
||||
|
||||
pop ebp ; get_fexp
|
||||
pop ecx ; get_funf
|
||||
pop eax ; argc
|
||||
lea edi, [4+ 4*eax + esp] ; &environ
|
||||
push eax ; argc
|
||||
|
||||
sub eax,eax ; 0
|
||||
L310:
|
||||
scasd
|
||||
jne L310
|
||||
scasd ; edi= &Elf32_auxv_t
|
||||
|
||||
mov esi,edi
|
||||
L320:
|
||||
mov eax,[esi] ; a_type
|
||||
cmp eax, byte AT_PHDR
|
||||
je L330
|
||||
add esi, byte sz_auxv
|
||||
cmp eax, byte AT_NULL
|
||||
jne L320
|
||||
L330:
|
||||
mov ebx,[a_val + esi]
|
||||
push ebx ; save &Elf32_Phdr of compressed data
|
||||
|
||||
sub esp, dword MAX_ELF_HDR + OVERHEAD ; working storage
|
||||
mov edx, esp
|
||||
push ecx ; get_funf 9th param to pti_main
|
||||
lea eax, [2*szElf32_Phdr + szl_info + szp_info + ebx] ; 1st &b_info
|
||||
mov esi, [e_entry + ebx] ; beyond compressed data
|
||||
sub esi, eax ; length of compressed data
|
||||
mov ebx, [ eax] ; length of uncompressed ELF headers
|
||||
mov ecx, [4+ eax] ; length of compressed ELF headers
|
||||
add ecx, byte szb_info
|
||||
pusha ; (AT_table, sz_cpr, get_fexp, &tmp_ehdr, {sz_unc, &tmp}, {sz_cpr, &b1st_info} )
|
||||
EXTERN pti_main
|
||||
call pti_main ; returns entry address
|
||||
add esp, dword 9*4 + MAX_ELF_HDR + OVERHEAD ; remove 9 params, temp space
|
||||
pop ebx ; &Elf32_Phdr
|
||||
push eax ; save entry address
|
||||
mov ecx,[p_memsz + ebx]
|
||||
mov ebx,[p_vaddr + ebx]
|
||||
mov eax,__NR_munmap
|
||||
int 0x80 ; unmap compressed data
|
||||
|
||||
sub eax,eax
|
||||
sub ecx,ecx
|
||||
sub edx,edx
|
||||
sub ebx,ebx
|
||||
sub ebp,ebp
|
||||
sub esi,esi
|
||||
sub edi,edi
|
||||
ret ; goto entry point
|
||||
|
||||
; vi:ts=8:et:nowrap
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/* fold_pti86.h -- created from fold_pti86.bin, 1552 (0x610) 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 LINUX_I386PTI_FOLD_SIZE 1552
|
||||
#define LINUX_I386PTI_FOLD_ADLER32 0x7ae39f1d
|
||||
#define LINUX_I386PTI_FOLD_CRC32 0x67ccdc9d
|
||||
|
||||
unsigned char linux_i386pti_fold[1552] = {
|
||||
127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */
|
||||
2, 0, 3, 0, 1, 0, 0, 0,128, 0, 1, 0, 52, 0, 0, 0, /* 0x 10 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 0, 0, /* 0x 20 */
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, /* 0x 30 */
|
||||
0, 0, 1, 0, 16, 6, 0, 0, 16, 6, 0, 0, 5, 0, 0, 0, /* 0x 40 */
|
||||
0, 16, 0, 0, 1, 0, 0, 0, 16, 6, 0, 0, 16, 6, 1, 0, /* 0x 50 */
|
||||
16, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */
|
||||
0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */
|
||||
93, 89, 88,141,124,132, 4, 80, 41,192,175,117,253,175,137,254, /* 0x 80 */
|
||||
139, 6,131,248, 3,116, 8,131,198, 8,131,248, 0,117,241,139, /* 0x 90 */
|
||||
94, 4, 83,129,236, 0, 10, 0, 0,137,226, 81,141, 67, 88,139, /* 0x a0 */
|
||||
115, 24, 41,198,139, 24,139, 72, 4,131,193, 12, 96,232, 86, 4, /* 0x b0 */
|
||||
0, 0,129,196, 36, 10, 0, 0, 91, 80,139, 75, 20,139, 91, 8, /* 0x c0 */
|
||||
184, 91, 0, 0, 0,205,128, 41,192, 41,201, 41,210, 41,219, 41, /* 0x d0 */
|
||||
237, 41,246, 41,255,195, 0, 0, 85, 87,137,207, 86,137,198, 83, /* 0x e0 */
|
||||
57, 8,139,104, 4,115, 8,106,127, 91,106, 1, 88,205,128,133, /* 0x f0 */
|
||||
255,116, 11,137,249,138, 69, 0, 69,136, 2, 66,226,247, 91, 1, /* 0x 100 */
|
||||
126, 4, 41, 62, 94, 95, 93,195, 83,141, 92, 36, 8,106, 90, 88, /* 0x 110 */
|
||||
205,128, 91,195, 85,137,229, 87, 86,137,199, 83,137,214,131,236, /* 0x 120 */
|
||||
20,131, 58, 0, 15,132,188, 0, 0, 0,141, 85,228,137,248,185, /* 0x 130 */
|
||||
12, 0, 0, 0,232,159,255,255,255,131,125,228, 0,139, 69,232, /* 0x 140 */
|
||||
117, 18, 61, 85, 80, 88, 33,117, 15,131, 63, 0, 15,132,148, 0, /* 0x 150 */
|
||||
0, 0,235, 4,133,192,117, 8,106,127, 91,106, 1, 88,205,128, /* 0x 160 */
|
||||
139, 77,232,139, 69,228, 57,193,119,238, 59, 6,119,234, 57,193, /* 0x 170 */
|
||||
115, 87, 15,182, 69,236, 80,255, 85, 8, 15,182, 85,236,137, 20, /* 0x 180 */
|
||||
36,141, 85,224, 82,255,118, 4,255,117,232,255,119, 4,255, 16, /* 0x 190 */
|
||||
131,196, 20,133,192,117,193,139, 69,228, 57, 69,224,117,185,138, /* 0x 1a0 */
|
||||
69,237,132,192,116, 25, 15,182,192, 80,255, 85, 12, 15,182, 85, /* 0x 1b0 */
|
||||
238,137, 20, 36,255,117,224,255,118, 4,255, 16,131,196, 12,139, /* 0x 1c0 */
|
||||
69,232, 1, 71, 4, 41, 7,235, 10,139, 86, 4,137,248,232, 5, /* 0x 1d0 */
|
||||
255,255,255,139, 85,228,139, 6, 1, 86, 4, 41,208,133,192,137, /* 0x 1e0 */
|
||||
6,233, 62,255,255,255,141,101,244, 91, 94, 95,201,195,133,210, /* 0x 1f0 */
|
||||
137,209,116, 6,198, 0, 0, 64,226,250,195,133,192, 83,137,211, /* 0x 200 */
|
||||
116, 29,168, 1,117, 25,139, 16, 57,218,116, 7, 74,117, 11,133, /* 0x 210 */
|
||||
219,116, 7,137, 24,137, 72, 4,235, 5,131,192, 8,235,231, 91, /* 0x 220 */
|
||||
195, 85,137,229, 87, 86, 83,131,236, 76,137, 69,228,139, 69, 8, /* 0x 230 */
|
||||
137, 85,224,139, 77, 16,199, 69,204, 0, 0, 0, 0,137, 69,220, /* 0x 240 */
|
||||
3, 64, 28,139, 93,220,137, 77,212,139, 85, 12,137, 69,208, 49, /* 0x 250 */
|
||||
192,102,131,123, 16, 3,137, 85,216, 15,183, 75, 44,139, 85,208, /* 0x 260 */
|
||||
15,149,192,131,206,255,193,224, 4,137,207,131,192, 34, 49,219, /* 0x 270 */
|
||||
79,137, 69,184,120, 34,131, 58, 1,117, 24,139, 66, 8, 57,240, /* 0x 280 */
|
||||
115, 8,139,122, 16,137,198,137,125,204, 3, 66, 20, 57,195,115, /* 0x 290 */
|
||||
2,137,195,131,194, 32,226,222,137,247,106, 0,129,231, 0,240, /* 0x 2a0 */
|
||||
255,255,106, 0, 41,251,255,117,184,129,195,255, 15, 0, 0,106, /* 0x 2b0 */
|
||||
7,129,227, 0,240,255,255,139, 85,204, 83,137,240, 37,255, 15, /* 0x 2c0 */
|
||||
0, 0, 87,137, 93,168,141,180, 2,255, 15, 0, 0,232, 54,254, /* 0x 2d0 */
|
||||
255,255,137,194,131,196, 24, 1,218,129,230, 0,240,255,255,137, /* 0x 2e0 */
|
||||
85,240,137,194, 41,243, 1,242,137,217,137, 69,172,137,211,106, /* 0x 2f0 */
|
||||
91, 88,205,128,139,117,172,139, 69,220, 41,254, 49,255,102,131, /* 0x 300 */
|
||||
120, 44, 0, 15,132,198, 1, 0, 0,139, 85,208,139, 2,131,248, /* 0x 310 */
|
||||
6,117, 23,139, 74, 8,186, 3, 0, 0, 0,139, 69,212, 1,241, /* 0x 320 */
|
||||
232,214,254,255,255,233,145, 1, 0, 0, 72, 15,133,138, 1, 0, /* 0x 330 */
|
||||
0,139, 93,208,199, 69,196, 64, 98, 81,115,139, 75, 24,139, 67, /* 0x 340 */
|
||||
8,131,225, 7,139, 83, 16,193,225, 2,137, 69,236,211,109,196, /* 0x 350 */
|
||||
137,193, 3, 75, 20,137,195,129,227,255, 15, 0, 0,137, 85,232, /* 0x 360 */
|
||||
1,218, 41,216,137, 85,192,139, 85,208, 1,240, 1,241,137, 69, /* 0x 370 */
|
||||
180,139, 66, 4,131,101,196, 7, 41,216,131,125,216, 1, 80,255, /* 0x 380 */
|
||||
117,228, 25,192,137, 93,188,131,224,224,137, 77,176,131,192, 50, /* 0x 390 */
|
||||
131,125,216, 0, 80,139, 69,192,106, 3,116, 3,131,192, 3, 80, /* 0x 3a0 */
|
||||
255,117,180,232, 96,253,255,255,131,196, 24, 57, 69,180, 15,133, /* 0x 3b0 */
|
||||
173, 0, 0, 0,131,125,216, 0,116, 19,255,117,224,255,117,228, /* 0x 3c0 */
|
||||
141, 85,232,139, 69,216,232, 73,253,255,255, 88, 90,139, 85,188, /* 0x 3d0 */
|
||||
139, 69,180,232, 22,254,255,255,139, 77,192,139, 69,180,247,217, /* 0x 3e0 */
|
||||
3, 69,192,129,225,255, 15, 0, 0,137,202,137, 77,188,232,251, /* 0x 3f0 */
|
||||
253,255,255,131,125,216, 0,116, 86,139, 93,208,131, 59, 1,117, /* 0x 400 */
|
||||
78,246, 67, 24, 1,116, 72,139, 67, 20, 59, 67, 16,139, 83, 8, /* 0x 410 */
|
||||
141, 12, 16,117, 14,137,200,247,216, 37,255, 15, 0, 0,131,248, /* 0x 420 */
|
||||
3,119, 12,139, 69,208,141, 74, 12,131,120, 4, 0,117, 15,139, /* 0x 430 */
|
||||
1, 61,205,128, 97,195,116, 6,199, 1,205,128, 97,195,133,201, /* 0x 440 */
|
||||
116, 13,139, 69,212, 49,210,131,224,254,232,172,253,255,255,139, /* 0x 450 */
|
||||
93,180,139, 77,192,139, 85,196,106,125, 88,205,128,133,192,116, /* 0x 460 */
|
||||
8,106,127, 91,106, 1, 88,205,128,139, 69,192, 3, 69,188, 1, /* 0x 470 */
|
||||
69,180,139, 69,176, 57, 69,180,115, 31,106, 0, 43, 69,180,106, /* 0x 480 */
|
||||
0,106, 50,255,117,196, 80,255,117,180,232,121,252,255,255,131, /* 0x 490 */
|
||||
196, 24, 57, 69,180,116, 36,235,200,131,125,216, 0,116, 28,131, /* 0x 4a0 */
|
||||
69,192, 3,129,101,192,255, 15, 0, 0,131,125,192, 3,119, 11, /* 0x 4b0 */
|
||||
139, 93,180,139, 77,192,106, 91, 88,205,128,139, 85,220, 71,131, /* 0x 4c0 */
|
||||
69,208, 32, 15,183, 66, 44, 57,199, 15,140, 58,254,255,255,131, /* 0x 4d0 */
|
||||
125,216, 0,117, 17,139, 93,228,106, 6, 88,205,128,133,192,116, /* 0x 4e0 */
|
||||
23,233,123,255,255,255,139,125,220,102,131,127, 16, 3,116, 8, /* 0x 4f0 */
|
||||
139, 93,240,106, 45, 88,205,128,139, 69,220, 3,112, 24,141,101, /* 0x 500 */
|
||||
244, 91,137,240, 94, 95,201,195, 85,137,229, 87, 86, 83, 81,139, /* 0x 510 */
|
||||
125, 20,141, 85, 24,255,117, 40,141, 71, 52,139, 93, 8,255,117, /* 0x 520 */
|
||||
16,137, 69,240,139,117, 32,141, 69, 32,232,229,251,255,255,139, /* 0x 530 */
|
||||
85,240,139, 69, 12,139, 74, 8,186, 3, 0, 0, 0,137, 69, 32, /* 0x 540 */
|
||||
137,216,131,193, 52, 41,117, 36,232,174,252,255,255, 15,183, 79, /* 0x 550 */
|
||||
42,137,216,186, 4, 0, 0, 0,232,158,252,255,255, 15,183, 79, /* 0x 560 */
|
||||
44,137,216,186, 5, 0, 0, 0,232,142,252,255,255,139, 79, 24, /* 0x 570 */
|
||||
137,216,186, 9, 0, 0, 0,232,127,252,255,255,141, 69, 32, 83, /* 0x 580 */
|
||||
139, 85, 40, 80,139, 69, 16, 87,232,148,252,255,255,102,139, 79, /* 0x 590 */
|
||||
44,131,196, 20, 49,210,102,133,201,137,195,116, 89,139, 69,240, /* 0x 5a0 */
|
||||
131, 56, 3,117, 69, 49,201,139, 88, 8,137,202,106, 5, 88,205, /* 0x 5b0 */
|
||||
128,133,192,137,198,120, 20,102,186, 0, 2,137,195,137,249,106, /* 0x 5c0 */
|
||||
3, 88,205,128, 61, 0, 2, 0, 0,116, 10,106,127, 91,106, 1, /* 0x 5d0 */
|
||||
88,205,128,235,246,106, 0, 49,210,106, 0,137,240, 87,232, 62, /* 0x 5e0 */
|
||||
252,255,255,131,196, 12,137,195,235, 12, 66, 15,183,193,131, 69, /* 0x 5f0 */
|
||||
240, 32, 57,194,124,167,141,101,244,137,216, 91, 94, 95,201,195 /* 0x 600 */
|
||||
};
|
||||
+27
-25
@@ -1,9 +1,10 @@
|
||||
/* fold_sh86.h -- created from fold_sh86.bin, 1207 (0x4b7) bytes
|
||||
/* fold_sh86.h -- created from fold_sh86.bin, 1212 (0x4bc) bytes
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
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
|
||||
@@ -26,15 +27,16 @@
|
||||
*/
|
||||
|
||||
|
||||
#define LINUX_I386SH_FOLD_ADLER32 0x3bb5f6de
|
||||
#define LINUX_I386SH_FOLD_CRC32 0x513b2cd1
|
||||
#define LINUX_I386SH_FOLD_SIZE 1212
|
||||
#define LINUX_I386SH_FOLD_ADLER32 0x3f61f91a
|
||||
#define LINUX_I386SH_FOLD_CRC32 0x17eab497
|
||||
|
||||
unsigned char linux_i386sh_fold[1207] = {
|
||||
unsigned char linux_i386sh_fold[1212] = {
|
||||
127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */
|
||||
2, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, /* 0x 10 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 1, 0, 0, 0, /* 0x 20 */
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 1, /* 0x 30 */
|
||||
0, 0, 64, 1,183, 4, 0, 0,184, 4, 0, 0, 7, 0, 0, 0, /* 0x 40 */
|
||||
0, 0, 64, 1,188, 4, 0, 0,188, 4, 0, 0, 7, 0, 0, 0, /* 0x 40 */
|
||||
0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 50 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 60 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */
|
||||
@@ -86,24 +88,24 @@ unsigned char linux_i386sh_fold[1207] = {
|
||||
69, 8,141,117, 24,139, 85, 16,137, 69,212,139, 69, 20,137, 85, /* 0x 350 */
|
||||
208,137, 69,204,139, 69, 36, 5, 85, 80, 88, 50,137, 69,240,139, /* 0x 360 */
|
||||
69,240, 5, 85, 80, 88, 51,131,125, 32, 0,137, 69,236, 15,132, /* 0x 370 */
|
||||
136, 0, 0, 0,141, 85,220,137,240,106, 12,232,112,253,255,255, /* 0x 380 */
|
||||
141, 0, 0, 0,141, 85,220,137,240,106, 12,232,112,253,255,255, /* 0x 380 */
|
||||
131,125,220, 0, 88,139, 69,224,117, 14, 61, 85, 80, 88, 33,117, /* 0x 390 */
|
||||
11,131, 62, 0,116,102,235, 4,133,192,117, 8,106,127, 91,106, /* 0x 3a0 */
|
||||
11,131, 62, 0,116,107,235, 4,133,192,117, 8,106,127, 91,106, /* 0x 3a0 */
|
||||
1, 88,205,128,139, 77,224,139, 69,220, 57,193,119,238, 59, 7, /* 0x 3b0 */
|
||||
119,234, 57,193,115, 39,141, 69,216, 80,255,119, 4, 81,255,118, /* 0x 3c0 */
|
||||
4,255, 85,208,131,196, 16,133,192,117,209,139, 69,220, 57, 69, /* 0x 3d0 */
|
||||
216,117,201,139, 69,224, 1, 70, 4, 41, 6,235, 12,139, 87, 4, /* 0x 3e0 */
|
||||
137,240, 81,232, 8,253,255,255, 91,139, 85,220,139, 7, 1, 87, /* 0x 3f0 */
|
||||
4, 41,208,133,192,137, 7,233,114,255,255,255,139, 69,236,139, /* 0x 400 */
|
||||
85,204,138, 24,139, 69,236,198, 0, 0,255,117,212,139, 69,240, /* 0x 410 */
|
||||
232, 37,253,255,255,139, 85,212,137,198,139, 69,236,136, 24,199, /* 0x 420 */
|
||||
66, 16, 3, 0, 0, 0,199, 66, 24, 4, 0, 0, 0,139, 85,204, /* 0x 430 */
|
||||
15,183, 66, 42,139, 85,212,137, 66, 28,199, 66, 32, 5, 0, 0, /* 0x 440 */
|
||||
0,139, 85,204, 15,183, 66, 44,139, 85,212,137, 66, 36,139, 69, /* 0x 450 */
|
||||
204,199, 66, 44, 0, 16, 0, 0,137,114, 68,199, 66, 40, 6, 0, /* 0x 460 */
|
||||
0, 0,102,139, 88, 44,199, 66, 64, 9, 0, 0, 0,139, 85,204, /* 0x 470 */
|
||||
89, 49,201,131,194, 52,102,133,219,116, 34,131, 58, 3,117, 18, /* 0x 480 */
|
||||
139, 66, 8,106, 0,139, 85,204,232,173,252,255,255,137,198, 88, /* 0x 490 */
|
||||
235, 11, 65, 15,183,195,131,194, 32, 57,193,124,222,141,101,244, /* 0x 4a0 */
|
||||
137,240, 91, 94, 95,201,195 /* 0x 4b0 */
|
||||
119,234, 57,193,115, 44, 15,182, 69,228, 80,141, 69,216, 80,255, /* 0x 3c0 */
|
||||
119, 4, 81,255,118, 4,255, 85,208,131,196, 20,133,192,117,204, /* 0x 3d0 */
|
||||
139, 69,220, 57, 69,216,117,196,139, 69,224, 1, 70, 4, 41, 6, /* 0x 3e0 */
|
||||
235, 12,139, 87, 4,137,240, 81,232, 3,253,255,255, 91,139, 85, /* 0x 3f0 */
|
||||
220,139, 7, 1, 87, 4, 41,208,133,192,137, 7,233,109,255,255, /* 0x 400 */
|
||||
255,139, 69,236,139, 85,204,138, 24,139, 69,236,198, 0, 0,255, /* 0x 410 */
|
||||
117,212,139, 69,240,232, 32,253,255,255,139, 85,212,137,198,139, /* 0x 420 */
|
||||
69,236,136, 24,199, 66, 16, 3, 0, 0, 0,199, 66, 24, 4, 0, /* 0x 430 */
|
||||
0, 0,139, 85,204, 15,183, 66, 42,139, 85,212,137, 66, 28,199, /* 0x 440 */
|
||||
66, 32, 5, 0, 0, 0,139, 85,204, 15,183, 66, 44,139, 85,212, /* 0x 450 */
|
||||
137, 66, 36,139, 69,204,199, 66, 44, 0, 16, 0, 0,137,114, 68, /* 0x 460 */
|
||||
199, 66, 40, 6, 0, 0, 0,102,139, 88, 44,199, 66, 64, 9, 0, /* 0x 470 */
|
||||
0, 0,139, 85,204, 89, 49,201,131,194, 52,102,133,219,116, 34, /* 0x 480 */
|
||||
131, 58, 3,117, 18,139, 66, 8,106, 0,139, 85,204,232,168,252, /* 0x 490 */
|
||||
255,255,137,198, 88,235, 11, 65, 15,183,195,131,194, 32, 57,193, /* 0x 4a0 */
|
||||
124,222,141,101,244,137,240, 91, 94, 95,201,195 /* 0x 4b0 */
|
||||
};
|
||||
|
||||
+4
-2
@@ -2,8 +2,8 @@
|
||||
;
|
||||
; This file is part of the UPX executable compressor.
|
||||
;
|
||||
; Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
; Copyright (C) 1996-2005 Laszlo Molnar
|
||||
; Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
; Copyright (C) 1996-2006 Laszlo Molnar
|
||||
; All Rights Reserved.
|
||||
;
|
||||
; UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -33,3 +33,5 @@
|
||||
%else; __IDENTBIG__
|
||||
%include "ident_n.ash"
|
||||
%endif; __IDENTEND__
|
||||
|
||||
; vi:ts=8:et:nowrap
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
;
|
||||
; This file is part of the UPX executable compressor.
|
||||
;
|
||||
; Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
; Copyright (C) 1996-2005 Laszlo Molnar
|
||||
; Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
; Copyright (C) 1996-2006 Laszlo Molnar
|
||||
; All Rights Reserved.
|
||||
;
|
||||
; UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -29,10 +29,14 @@
|
||||
; ------------- COPYRIGHT -------------
|
||||
|
||||
db 10,0
|
||||
db '$Info: This file is packed with the UPX executable packer http://upx.sf.net $'
|
||||
db '$Info: '
|
||||
db 'This file is packed with the UPX executable packer '
|
||||
db 'http://upx.sf.net $'
|
||||
db 10,0
|
||||
db '$Id: UPX '
|
||||
db 'UPXV'
|
||||
db ' Copyright (C) 1996-2005 the UPX Team. All Rights Reserved. $'
|
||||
db ' Copyright (C) 1996-UPXY the UPX Team. All Rights Reserved. $'
|
||||
db 10,0
|
||||
|
||||
|
||||
; vi:ts=8:et:nowrap
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
;
|
||||
; This file is part of the UPX executable compressor.
|
||||
;
|
||||
; Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
; Copyright (C) 1996-2005 Laszlo Molnar
|
||||
; Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
; Copyright (C) 1996-2006 Laszlo Molnar
|
||||
; All Rights Reserved.
|
||||
;
|
||||
; UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -29,6 +29,9 @@
|
||||
; ------------- COPYRIGHT -------------
|
||||
|
||||
db 10
|
||||
db '$Id: UPX (C) 1996-2005 the UPX Team. All Rights Reserved. http://upx.sf.net $'
|
||||
db '$Id: UPX (C) 1996-UPXY the UPX Team. '
|
||||
db 'All Rights Reserved. http://upx.sf.net $'
|
||||
db 10,0
|
||||
|
||||
|
||||
; vi:ts=8:et:nowrap
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
; l_armwce.asm -- loader & decompressor for the arm/wince/pe format
|
||||
;
|
||||
; This file is part of the UPX executable compressor.
|
||||
;
|
||||
; Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
; Copyright (C) 1996-2004 Laszlo Molnar
|
||||
; 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 jmps jmp short
|
||||
%define jmpn jmp near
|
||||
%include "macros.ash"
|
||||
|
||||
BITS 32
|
||||
SECTION .text
|
||||
ORG 0
|
||||
CPU 386
|
||||
|
||||
; =============
|
||||
; ============= ENTRY POINT
|
||||
; =============
|
||||
|
||||
; __ARMWPE00__
|
||||
start:
|
||||
%include "l_armpe_.ah"
|
||||
%include "header.ash"
|
||||
eof:
|
||||
; __ARMWPE99__
|
||||
section .data
|
||||
dd -1
|
||||
dw eof
|
||||
|
||||
|
||||
; vi:ts=8:et:nowrap
|
||||
@@ -0,0 +1,100 @@
|
||||
/* l_armpe.h -- created from l_armpe.bin, 1069 (0x42d) bytes
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
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 NRV_LOADER_ADLER32 0x793a99ed
|
||||
#define NRV_LOADER_CRC32 0x90e7375f
|
||||
|
||||
unsigned char nrv_loader[1069] = {
|
||||
15, 64, 45,233, 12, 0,160,227, 0, 0,143,224, 11, 0, 0,235, /* 0x 0 */
|
||||
15, 64,189,232, 24,240,159,229, 88,120,120, 88, 83, 82, 67, 48, /* 0x 10 */
|
||||
68, 83, 84, 48, 66, 73, 77, 80, 79, 78, 65, 77, 71, 69, 84, 80, /* 0x 20 */
|
||||
76, 79, 65, 68, 69, 78, 84, 82, 83, 82, 67, 76, 68, 83, 84, 76, /* 0x 30 */
|
||||
240, 71, 45,233, 4, 80,144,228, 0, 48,160,227, 4,112,144,228, /* 0x 40 */
|
||||
136,208, 77,226, 4, 32,144,228, 4, 48,141,229, 4,144,144,228, /* 0x 50 */
|
||||
3, 64,160,225, 4,128,144,228, 0, 32,141,229, 0, 96,144,229, /* 0x 60 */
|
||||
3,192,160,225, 3, 0,160,225, 1,160,160,227, 4, 0, 0,234, /* 0x 70 */
|
||||
5, 48,132,224, 0, 48,211,229, 1, 64,132,226, 7, 48,192,231, /* 0x 80 */
|
||||
1, 0,128,226,127, 0, 28,227, 5, 48,212, 7,140, 48,160, 17, /* 0x 90 */
|
||||
131, 48,160, 1, 1, 48,131, 2, 1, 64,132, 2, 1, 12, 19,227, /* 0x a0 */
|
||||
3,192,160,225,241,255,255, 26, 1, 16,160,227,127, 0, 28,227, /* 0x b0 */
|
||||
5, 48,212, 7,140, 48,160, 17,131, 48,160, 1, 1, 48,131, 2, /* 0x c0 */
|
||||
1, 64,132, 2, 3,192,160,225,127, 0, 19,227,129, 32,160,225, /* 0x d0 */
|
||||
131, 59,160,225,163, 31,130,225, 5, 48,212, 7,140, 48,160, 17, /* 0x e0 */
|
||||
131, 48,160, 1, 1, 48,131, 2, 1, 64,132, 2, 1, 12, 19,227, /* 0x f0 */
|
||||
3,192,160,225, 11, 0, 0, 26,127, 0, 19,227, 5, 48,212, 7, /* 0x 100 */
|
||||
131, 48,160, 17,131, 48,160, 1, 1, 48,131, 2,129, 32,160,225, /* 0x 110 */
|
||||
3,192,160,225,131, 59,160,225,163, 63,130,225, 1, 64,132, 2, /* 0x 120 */
|
||||
2, 16, 67,226,224,255,255,234, 2, 0, 81,227, 10, 0, 0, 26, /* 0x 130 */
|
||||
127, 0, 19,227, 5, 48,212, 7,131, 48,160, 17,131, 48,160, 1, /* 0x 140 */
|
||||
1, 48,131, 2, 3,192,160,225, 35, 52,160,225, 10, 16,160,225, /* 0x 150 */
|
||||
1, 64,132, 2, 1, 32, 3,226, 10, 0, 0,234, 5, 48,212,231, /* 0x 160 */
|
||||
1, 64,132,226, 1, 52,131,224, 3, 28, 67,226, 1, 0,113,227, /* 0x 170 */
|
||||
71, 0, 0, 10, 1, 48,224,225,161, 16,160,225, 1, 16,129,226, /* 0x 180 */
|
||||
1, 32, 3,226, 1,160,160,225, 0, 0, 82,227,127, 48, 12,226, /* 0x 190 */
|
||||
10, 0, 0, 10, 0, 0, 83,227, 5, 48,212, 7,140, 48,160, 17, /* 0x 1a0 */
|
||||
131, 48,160, 1, 1, 48,131, 2, 3,192,160,225, 35, 52,160,225, /* 0x 1b0 */
|
||||
1, 48, 3,226, 1, 64,132, 2, 1, 32,131,226, 39, 0, 0,234, /* 0x 1c0 */
|
||||
0, 0, 83,227, 5, 48,212, 7,140, 48,160, 17,131, 48,160, 1, /* 0x 1d0 */
|
||||
1, 48,131, 2, 1, 64,132, 2, 1, 12, 19,227, 3,192,160,225, /* 0x 1e0 */
|
||||
1, 32,160, 3, 10, 0, 0, 10,127, 0, 19,227, 5, 48,212, 7, /* 0x 1f0 */
|
||||
131, 48,160, 17,131, 48,160, 1, 1, 48,131, 2, 3,192,160,225, /* 0x 200 */
|
||||
35, 52,160,225, 1, 48, 3,226, 1, 64,132, 2, 3, 32,131,226, /* 0x 210 */
|
||||
18, 0, 0,234,127, 0, 28,227,140, 48,160,225, 5, 48,212, 7, /* 0x 220 */
|
||||
130, 32,160,225,131, 48,160, 1, 1, 48,131, 2,131,224,160,225, /* 0x 230 */
|
||||
1, 64,132, 2,127, 0, 19,227,131, 59,160,225,163, 47,130,225, /* 0x 240 */
|
||||
5, 48,212, 7, 1, 64,132, 2,131, 48,160, 1, 1,224,131, 2, /* 0x 250 */
|
||||
1, 12, 30,227, 14,192,160,225,237,255,255, 10, 3, 32,130,226, /* 0x 260 */
|
||||
0, 48,135,224, 3,224, 97,224, 1, 48,222,228, 5, 12, 81,227, /* 0x 270 */
|
||||
1, 32,130,130, 0, 48,199,231, 1, 0,128,226, 1, 48,222,228, /* 0x 280 */
|
||||
1, 32, 82,226, 7, 48,192,231, 1, 0,128,226,250,255,255, 26, /* 0x 290 */
|
||||
123,255,255,234, 0,160,150,229, 0,128,152,229, 0, 64,157,229, /* 0x 2a0 */
|
||||
4, 0,141,229, 3, 16,212,229, 2, 48,212,229, 1, 32,212,229, /* 0x 2b0 */
|
||||
1, 52,131,224, 0, 16,212,229, 3, 36,130,224, 2,228,129,224, /* 0x 2c0 */
|
||||
0, 0, 94,227, 59, 0, 0, 10, 4, 48,132,226, 3, 16,211,229, /* 0x 2d0 */
|
||||
2, 32,211,229, 1, 48,211,229, 1, 36,130,224, 4, 16,212,229, /* 0x 2e0 */
|
||||
2, 52,131,224, 9,192,254,231, 3, 20,129,224, 8, 0,141,226, /* 0x 2f0 */
|
||||
0, 0, 92,227, 7, 80,129,224, 0, 48,160,225, 3, 0, 0, 10, /* 0x 300 */
|
||||
178,192,195,224, 1,192,254,229, 0, 0, 92,227,250,255,255,234, /* 0x 310 */
|
||||
0, 32,160,227,176, 32,195,225, 15,224,160,225, 10,240,160,225, /* 0x 320 */
|
||||
8, 48,244,229, 0, 96,160,225, 0, 0, 83,227, 31, 0, 0, 10, /* 0x 330 */
|
||||
255, 48, 3,226, 1, 0, 83,227, 1, 64,132,226, 2, 0, 0, 10, /* 0x 340 */
|
||||
255, 0, 83,227, 9, 0, 0, 10, 19, 0, 0,234, 6, 0,160,225, /* 0x 350 */
|
||||
4, 16,160,225, 15,224,160,225, 8,240,160,225, 4, 0,133,228, /* 0x 360 */
|
||||
1, 48,212,228, 0, 0, 83,227,252,255,255, 26, 13, 0, 0,234, /* 0x 370 */
|
||||
0, 48,212,229, 1, 16,212,229, 6, 0,160,225, 1, 20,131,224, /* 0x 380 */
|
||||
15,224,160,225, 8,240,160,225, 2, 64,132,226, 5, 48,160,225, /* 0x 390 */
|
||||
4, 80,133,226, 0, 0,131,229, 2, 0, 0,234, 0, 32,160,227, /* 0x 3a0 */
|
||||
1, 48,160,227, 0, 32,131,229, 0, 48,212,229,221,255,255,234, /* 0x 3b0 */
|
||||
1, 64,132,226,186,255,255,234,136,208,141,226,240,135,189,232, /* 0x 3c0 */
|
||||
255,255,255,255, 0, 0, 0, 0,255,255,255,255, 0, 0, 0, 0, /* 0x 3d0 */
|
||||
85, 80, 88, 33,161,216,208,213, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 3e0 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, /* 0x 3f0 */
|
||||
65, 82, 77, 87, 80, 69, 48, 48, 0, 0, 0, 0, 0, 85, 80, 88, /* 0x 400 */
|
||||
49, 72, 69, 65, 68, 0,224, 3, 0, 0, 65, 82, 77, 87, 80, 69, /* 0x 410 */
|
||||
57, 57, 0, 0, 4, 0, 0,255,255,255,255, 0, 4 /* 0x 420 */
|
||||
};
|
||||
@@ -0,0 +1,357 @@
|
||||
/* l_armpe_c.c -- ARM/PE decompressor for NRV2E
|
||||
|
||||
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>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#define WRITEFILE(name0, buf, len) \
|
||||
do { short b[3]; b[0] = '\\'; b[1] = name0; b[2] = 0; \
|
||||
typedef int (*CF)(short *, int, int, int, int, int, int); CF cf = (CF) 0x1f99c58; \
|
||||
typedef void (*WF)(int, const void *, int, int *, int); WF wf = (WF) 0x1f99d60; \
|
||||
typedef void (*CH)(int); CH ch = (CH) 0x1f9a2f0; \
|
||||
int h = cf(b, 0x40000000L, 3, 0, 2, 0x80, 0);\
|
||||
int l; wf(h, buf, len, &l, 0); \
|
||||
ch(h); } while (0)
|
||||
|
||||
|
||||
typedef unsigned int ucl_uint32;
|
||||
typedef int ucl_int32;
|
||||
typedef unsigned int ucl_uint;
|
||||
typedef int ucl_int;
|
||||
|
||||
static int
|
||||
ucl_nrv2e_decompress_8 ( const unsigned char * src, ucl_uint src_len,
|
||||
unsigned char * dst, ucl_uint * dst_len)
|
||||
{
|
||||
|
||||
{
|
||||
ucl_uint32 bb = 0;
|
||||
|
||||
|
||||
|
||||
ucl_uint ilen = 0, olen = 0, last_m_off = 1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
ucl_uint m_off, m_len;
|
||||
|
||||
while ((((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1))
|
||||
{
|
||||
;
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
dst[olen++] = src[ilen++];
|
||||
|
||||
}
|
||||
m_off = 1;
|
||||
for (;;)
|
||||
{
|
||||
m_off = m_off*2 + (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1);
|
||||
;
|
||||
;
|
||||
if ((((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1)) break;
|
||||
m_off = (m_off-1)*2 + (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1);
|
||||
}
|
||||
if (m_off == 2)
|
||||
{
|
||||
m_off = last_m_off;
|
||||
m_len = (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
;
|
||||
m_off = (m_off-3)*256 + src[ilen++];
|
||||
if (m_off == ((0xffffffff) + 0U))
|
||||
break;
|
||||
m_len = (m_off ^ ((0xffffffff) + 0U)) & 1;
|
||||
m_off >>= 1;
|
||||
last_m_off = ++m_off;
|
||||
}
|
||||
if (m_len)
|
||||
m_len = 1 + (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1);
|
||||
else if ((((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1))
|
||||
m_len = 3 + (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1);
|
||||
else
|
||||
{
|
||||
m_len++;
|
||||
do {
|
||||
m_len = m_len*2 + (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1);
|
||||
;
|
||||
;
|
||||
} while (!(((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1));
|
||||
m_len += 3;
|
||||
}
|
||||
m_len += (m_off > 0x500);
|
||||
;
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
const unsigned char * m_pos;
|
||||
m_pos = dst + olen - m_off;
|
||||
dst[olen++] = *m_pos++;
|
||||
do dst[olen++] = *m_pos++; while (--m_len > 0);
|
||||
}
|
||||
|
||||
}
|
||||
*dst_len = olen;
|
||||
return ilen == src_len ? 0 : (ilen < src_len ? (-205) : (-201));
|
||||
}
|
||||
}
|
||||
|
||||
typedef void *(*loadlibraryw)(unsigned short *);
|
||||
typedef void *(*getprocaddra)(void *, void *);
|
||||
|
||||
#define T(a,b,c,d) ((a) + ((b) * 0x100) + ((c) * 0x10000) + ((d) * 0x1000000))
|
||||
|
||||
static inline void *get_le32(unsigned char *p)
|
||||
{
|
||||
return (void*) T(p[0], p[1], p[2], p[3]);
|
||||
}
|
||||
|
||||
static void handle_imports(unsigned char *imp,
|
||||
unsigned name_offset,
|
||||
unsigned iat_offset,
|
||||
loadlibraryw ll,
|
||||
getprocaddra gpa)
|
||||
{
|
||||
unsigned short buf[64];
|
||||
while (1)
|
||||
{
|
||||
unsigned short *b;
|
||||
//printf("name=%p iat=%p\n", get_le32(imp), get_le32(imp + 4));
|
||||
unsigned char *name = get_le32(imp);
|
||||
if (name == 0)
|
||||
break;
|
||||
name += name_offset;
|
||||
unsigned *iat = get_le32(imp + 4) + iat_offset;
|
||||
//printf("name=%p iat=%p\n", name, iat);
|
||||
for (b = buf; *name; name++, b++)
|
||||
*b = *name;
|
||||
*b = 0;
|
||||
|
||||
void *dll = ll(buf);
|
||||
imp += 8;
|
||||
unsigned ord;
|
||||
|
||||
while (*imp)
|
||||
{
|
||||
switch (*imp++)
|
||||
{
|
||||
case 1:
|
||||
// by name
|
||||
*iat++ = (unsigned) gpa(dll, imp);
|
||||
while (*imp++)
|
||||
;
|
||||
break;
|
||||
case 0xff:
|
||||
// by ordinal
|
||||
ord = ((unsigned) imp[0]) + imp[1] * 0x100;
|
||||
imp += 2;
|
||||
*iat++ = (unsigned) gpa(dll, (void *) ord);
|
||||
break;
|
||||
default:
|
||||
*(int*) 1 = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
imp++;
|
||||
}
|
||||
}
|
||||
|
||||
void upx_main(unsigned *info)
|
||||
{
|
||||
int dlen = 0;
|
||||
unsigned src0 = *info++;
|
||||
unsigned dst0 = *info++;
|
||||
unsigned bimp = *info++;
|
||||
unsigned onam = *info++;
|
||||
unsigned getp = *info++;
|
||||
unsigned load = *info++;
|
||||
unsigned entr = *info++;
|
||||
unsigned srcl = *info++;
|
||||
unsigned dstl = *info++;
|
||||
|
||||
//WRITEFILE('1', (void*) 0x11000, load + 256 - 0x11000);
|
||||
ucl_nrv2e_decompress_8((void *) src0, srcl, (void *) dst0, &dlen);
|
||||
handle_imports((void *) bimp, onam, dst0, *(void**) load, *(void**) getp);
|
||||
//WRITEFILE('2', (void*) 0x11000, load + 256 - 0x11000);
|
||||
}
|
||||
|
||||
#ifndef __pe__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void *test_loadlibraryw(unsigned short *x)
|
||||
{
|
||||
printf("loadlibraryw called: ");
|
||||
while (*x)
|
||||
printf("%c", *x++);
|
||||
printf("\n");
|
||||
|
||||
static unsigned ret = 0x2a2a2a00;
|
||||
return (void*) ret++;
|
||||
}
|
||||
|
||||
static void *test_getprocaddra(void *a, void *x)
|
||||
{
|
||||
if ((unsigned) x < 0x10000)
|
||||
printf("getprocaddra called: %p %x\n", a, (unsigned) x);
|
||||
else
|
||||
printf("getprocaddra called: %p %s\n", a, (char*) x);
|
||||
|
||||
static unsigned ret = 1;
|
||||
return a + ret++;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
return printf("usage: %s <compressed.exe>\n", argv[0]);
|
||||
|
||||
void *mem = malloc(32*1024*1024);
|
||||
void *mem16m = (void*) ((((unsigned) mem) + 0xffffff) & 0xff000000);
|
||||
printf("mem: %p %p\n", mem, mem16m);
|
||||
|
||||
char command[100 + strlen(argv[1])];
|
||||
snprintf(command, sizeof(command),
|
||||
"arm-wince-pe-objdump -h '%s'|grep '2[*][*]2'", argv[1]);
|
||||
FILE *fp = popen(command, "r");
|
||||
if (fgets(command, 100, fp) == NULL)
|
||||
return printf("error while calling objdump\n");
|
||||
|
||||
unsigned start_uncompressed;
|
||||
if (sscanf(command, "%*d %*s %*x %x", &start_uncompressed) != 1)
|
||||
return printf("scanf failed on '%s'", command);
|
||||
printf("start_uncompressed=%x ", start_uncompressed);
|
||||
|
||||
if (fgets(command, 100, fp) == NULL)
|
||||
return printf("error while calling objdump\n");
|
||||
unsigned size;
|
||||
unsigned offset;
|
||||
unsigned vma;
|
||||
if (sscanf(command, "%*d %*s %x %x %*x %x", &size, &vma, &offset) != 3)
|
||||
return printf("scanf failed on '%s'" , command);
|
||||
printf("size=%x vma=%x offset=%x\n", size, vma, offset);
|
||||
|
||||
if (fgets(command, 100, fp) == NULL)
|
||||
return printf("error while calling objdump\n");
|
||||
|
||||
unsigned size2;
|
||||
unsigned offset2;
|
||||
unsigned vma2;
|
||||
if (sscanf(command, "%*d %*s %x %x %*x %x", &size2, &vma2, &offset2) != 3)
|
||||
return printf("scanf failed on '%s'" , command);
|
||||
printf("size2=%x vma2=%x offset2=%x\n", size2, vma2, offset2);
|
||||
|
||||
pclose(fp);
|
||||
|
||||
FILE *f1 = fopen(argv[1], "rb");
|
||||
if (f1 == NULL)
|
||||
return printf("can not open %s\n", argv[1]);
|
||||
if (fseek(f1, offset, SEEK_SET))
|
||||
return printf("fseek failed\n");
|
||||
if (fread(mem16m + vma, size, 1, f1) != 1)
|
||||
return printf("fread failed\n");
|
||||
if (fseek(f1, offset2, SEEK_SET))
|
||||
return printf("fseek failed\n");
|
||||
if (fread(mem16m + vma2, size2, 1, f1) != 1)
|
||||
return printf("fread failed\n");
|
||||
fclose(f1);
|
||||
|
||||
unsigned *info = (unsigned *) memmem(mem16m + vma, size, "XxxX", 4);
|
||||
if (info == NULL)
|
||||
return printf("decompression info not found\n");
|
||||
|
||||
info++;
|
||||
unsigned src0 = *info++;
|
||||
unsigned dst0 = *info++;
|
||||
unsigned bimp = *info++;
|
||||
unsigned onam = *info++;
|
||||
unsigned getp = *info++;
|
||||
unsigned load = *info++;
|
||||
unsigned entr = *info++;
|
||||
unsigned srcl = *info++;
|
||||
unsigned dstl = *info++;
|
||||
|
||||
printf("%x %x %x %x %x %x %x %x %x\n", src0, srcl, dst0, dstl, bimp, onam, load, getp, entr);
|
||||
|
||||
int dlen = 0;
|
||||
int ret = ucl_nrv2e_decompress_8(mem16m + src0, srcl, mem16m + dst0, &dlen);
|
||||
|
||||
printf("dlen=%x, ret=%d\n", dlen, ret);
|
||||
if (dlen != (int) dstl)
|
||||
return printf("corrupt compressed data\n");
|
||||
|
||||
f1 = fopen("/tmp/image.out", "w");
|
||||
fwrite(mem16m, vma + size + 0x10000, 1, f1);
|
||||
fclose(f1);
|
||||
|
||||
handle_imports(bimp + mem16m, onam + mem16m, dst0 + mem16m,
|
||||
test_loadlibraryw, test_getprocaddra);
|
||||
|
||||
f1 = fopen("/tmp/image.out", "w");
|
||||
fwrite(mem16m, vma2 + size2, 1, f1);
|
||||
fclose(f1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
int main(void)
|
||||
{
|
||||
FILE *f1 = fopen("/r", "w");
|
||||
int h = LoadLibraryW(L"coredll.dll");
|
||||
fprintf(f1, "%p\n", GetProcAddressA(h, "DeleteFileW"));
|
||||
fclose(f1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
typedef void (*df)(ushort *);
|
||||
df dfw = 0x1f99bc8;
|
||||
dfw(L"\\r");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/* l_armpe_s.S -- ARM/PE decompressor assembly startup
|
||||
|
||||
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>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
.text
|
||||
.align 0
|
||||
.global _mainCRTStartup
|
||||
|
||||
_mainCRTStartup:
|
||||
stmfd sp!, {r0 - r3, lr}
|
||||
mov r0, #L2 - L0 - 8
|
||||
L0:
|
||||
add r0, pc, r0
|
||||
bl _upx_main
|
||||
ldmfd sp!, {r0 - r3, lr}
|
||||
ldr pc, L21
|
||||
.ascii "XxxX"
|
||||
L2:
|
||||
.ascii "SRC0DST0BIMPONAMGETPLOAD"
|
||||
L21:
|
||||
.ascii "ENTRSRCLDSTL"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user