Compare commits
247 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63b9ee61d2 | |||
| 3b9eff7f34 | |||
| 59668c5fc1 | |||
| 3ed786fb5c | |||
| 0cd5eb5472 | |||
| ff571b96cb | |||
| 36b852e6bf | |||
| f0c21c7203 | |||
| 0516d8260c | |||
| 1418f57b96 | |||
| b24fb59c94 | |||
| 8fcf2bcd59 | |||
| 079b808a56 | |||
| a4e01e28db | |||
| ec1ef9099f | |||
| ac724c7e6c | |||
| ec25835525 | |||
| d4841a641c | |||
| 5612460720 | |||
| 465ea6429f | |||
| ed9057ca83 | |||
| 14ced962db | |||
| 1aff6b862d | |||
| ef490c4220 | |||
| 0dda83cbbc | |||
| fa4efec3b5 | |||
| 814eabb88e | |||
| 95021e4977 | |||
| d17fb7ebf0 | |||
| df9aa9ac32 | |||
| 9110517893 | |||
| 8204c7deb6 | |||
| 6662f8985e | |||
| a2b305ed3b | |||
| ce3d3a850c | |||
| 212b674bc2 | |||
| 2980a6b4bb | |||
| 435c0a9e82 | |||
| 4102cd7c91 | |||
| b4b603819d | |||
| 20e3707e69 | |||
| fc6eeaaea8 | |||
| 41799955ce | |||
| efb4ec9cb8 | |||
| 4dbda29f82 | |||
| befaa3c501 | |||
| f41edf9e21 | |||
| 754f10f0b0 | |||
| 5d331fdf69 | |||
| cbf1dbe2cb | |||
| 3177de92fb | |||
| 3878890783 | |||
| 61594f7873 | |||
| f412b5e0cd | |||
| f14d594a1a | |||
| f0279d23d3 | |||
| 18ef55ac14 | |||
| 0010c50de6 | |||
| 130699a33b | |||
| 5a8d60d3e0 | |||
| 603dc83c1a | |||
| 51106e730b | |||
| 23ec864130 | |||
| 5349bd0b2a | |||
| 74d70fe1d9 | |||
| 041865c320 | |||
| 6a7d555ad7 | |||
| 18262f79c7 | |||
| 9769599f1d | |||
| aee150474c | |||
| 0e45021a5a | |||
| 241abcc89c | |||
| 90fc32a56e | |||
| 7ce85ab712 | |||
| 55cde23f10 | |||
| a19e6cd4f5 | |||
| 06f8c55908 | |||
| b10f68d20a | |||
| ed8a71bba1 | |||
| fee6f17caf | |||
| 767e4e2ce6 | |||
| 23f5370dcf | |||
| 37ae689328 | |||
| 123b33efd4 | |||
| 736ec9d9e5 | |||
| 5a94136764 | |||
| 1555be40b7 | |||
| 60b7a3c33b | |||
| a5d8e575bd | |||
| 23db1d375c | |||
| e06722d121 | |||
| 81e77a8b2b | |||
| 5c567c5a76 | |||
| b8e698bde3 | |||
| 440b5b2608 | |||
| 8b2e7ffe0b | |||
| 1018a96b31 | |||
| 5f87e9891b | |||
| 19564ed27e | |||
| f4022af48a | |||
| 2d1de8b9e9 | |||
| cdbfdee725 | |||
| ac64126a66 | |||
| 97153e8e09 | |||
| b9c976304a | |||
| 670b67cc98 | |||
| ccecaa741c | |||
| 07230edec0 | |||
| de1a4b4da4 | |||
| aba5c40b17 | |||
| a55b3480ef | |||
| bcb5e7d852 | |||
| e4f6378dfe | |||
| f616d2edf1 | |||
| bffb138b9c | |||
| b49fc6c081 | |||
| 570b195ed6 | |||
| b0e961b90b | |||
| 919a899c39 | |||
| 655094239c | |||
| 8eda698a9c | |||
| d1753c6df9 | |||
| 3db0b0e8fe | |||
| 8d5d6bd1a5 | |||
| 05f6f4d2ff | |||
| 9e154e33c3 | |||
| 5125f4d4ac | |||
| 365a3c0432 | |||
| ab37b5ea0c | |||
| 20ddd8590d | |||
| 69d9aa6c69 | |||
| 2163231401 | |||
| f513373693 | |||
| ed0e3b9af4 | |||
| 4205c699ac | |||
| 4e64cdac15 | |||
| bbbea34d74 | |||
| 66565f7238 | |||
| 9cb922425e | |||
| 268e13c572 | |||
| 03f1f615e5 | |||
| 94152391b1 | |||
| 2d403e07bb | |||
| 48ec581539 | |||
| f9054529c1 | |||
| 67d9ff987c | |||
| a3bb8f00fd | |||
| 48846c7226 | |||
| ad8648f668 | |||
| c7224c7727 | |||
| b2949259c5 | |||
| 757bdd1264 | |||
| ec1e5849eb | |||
| 1752fab911 | |||
| b0748388b2 | |||
| 175899013e | |||
| c448d15a8f | |||
| 5c7bca5b3e | |||
| 390cdbba2d | |||
| 256b8f066f | |||
| 30915862cd | |||
| eeb1dfaf8f | |||
| 90161bc3a7 | |||
| a1064dc2cb | |||
| b8a9b321fa | |||
| a3e80b1628 | |||
| 350ebfc47d | |||
| b9b75c536c | |||
| 8b74704bbf | |||
| bead894e49 | |||
| 502f9b5a00 | |||
| cd15b7d5af | |||
| 0c1d544e98 | |||
| 728be1867f | |||
| 09578df46b | |||
| b29f5b7c09 | |||
| 10f602fca7 | |||
| 2f8917f450 | |||
| b57f48d543 | |||
| 87a4d8455d | |||
| b14df392fa | |||
| 437c34a68c | |||
| b218cec3d7 | |||
| f19c91243a | |||
| 882e1be2db | |||
| 8e21c1e965 | |||
| f3970eaed9 | |||
| ac4b8f8617 | |||
| 51c28020de | |||
| fd525ae7df | |||
| a282171318 | |||
| c3040d1636 | |||
| c76c07aea0 | |||
| 1282ed333a | |||
| 32e76e88cf | |||
| fc0d3ff118 | |||
| 0bd05c0d67 | |||
| ff2c5300b8 | |||
| a38989dfbf | |||
| e387c6bc56 | |||
| 5eb81c0ec4 | |||
| f92b617c43 | |||
| 8f25c72085 | |||
| 7860e7a249 | |||
| a2e3ceb8c8 | |||
| e96ad21db1 | |||
| 888ac8a220 | |||
| 29db8bca3a | |||
| 63d49f0143 | |||
| 378224c6ba | |||
| 2f3e7a82b5 | |||
| 960f020277 | |||
| 6962da718c | |||
| 42575d9f57 | |||
| 03fb0d95c6 | |||
| beb766b005 | |||
| 29c1f67057 | |||
| a709b38065 | |||
| ec5840fb2a | |||
| 9511e3c9b1 | |||
| 9190e7d51a | |||
| cff830c43b | |||
| e31c45dc10 | |||
| e1da733810 | |||
| b8c34036a5 | |||
| d771f219f0 | |||
| d8280343f9 | |||
| c7b9395866 | |||
| 992ceee52b | |||
| 2162a01848 | |||
| 102e0f0a98 | |||
| 4e0967e0a1 | |||
| 73dc4eede0 | |||
| 5e5ea9f6e4 | |||
| e537f25857 | |||
| 47aea88c27 | |||
| 0237bf8915 | |||
| 3a7032f21c | |||
| 54d01790b5 | |||
| fb3375112e | |||
| 554f22a14f | |||
| eb6a6e3909 | |||
| 041947507f | |||
| ff03ac17b2 | |||
| 12c6cd8021 | |||
| de6e8c8020 | |||
| f3b64cfe78 |
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
.cvsignore
|
_darcs
|
||||||
|
B
|
||||||
ChangeLog.cvs*
|
ChangeLog.cvs*
|
||||||
|
TODO.*
|
||||||
build
|
build
|
||||||
|
doxygen
|
||||||
maint
|
maint
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2002 Markus Oberhumer & Laszlo Molnar
|
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||||
http://upx.sourceforge.net
|
http://upx.sourceforge.net
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ srcdir = .
|
|||||||
top_srcdir = .
|
top_srcdir = .
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
@echo "UPX info: please choose a target for 'make'"
|
||||||
|
|
||||||
all mostlyclean clean distclean maintainer-clean:
|
all mostlyclean clean distclean maintainer-clean:
|
||||||
$(MAKE) -C src/stub/util/sstrip $@
|
$(MAKE) -C src/stub/util/sstrip $@
|
||||||
$(MAKE) -C src/stub $@
|
$(MAKE) -C src/stub $@
|
||||||
@@ -20,11 +23,14 @@ zip:
|
|||||||
|
|
||||||
cvs-admin-ko:
|
cvs-admin-ko:
|
||||||
cvs admin -ko .
|
cvs admin -ko .
|
||||||
cvs update
|
cvs update -P -d
|
||||||
|
|
||||||
ChangeLog:
|
ChangeLog:
|
||||||
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
|
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
|
||||||
|
|
||||||
|
ChangeLog.cvsps:
|
||||||
|
cvsps > $@
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||||
.PHONY: dist cvs-admin-ko ChangeLog
|
.PHONY: dist cvs-admin-ko ChangeLog
|
||||||
|
|||||||
@@ -2,19 +2,42 @@
|
|||||||
User visible changes for UPX
|
User visible changes for UPX
|
||||||
==================================================================
|
==================================================================
|
||||||
|
|
||||||
[ BETA VERSION - please see README.1ST for some more info ]
|
[ UNSTABLE BETA VERSION - please see README.1ST for some more info ]
|
||||||
|
|
||||||
|
Changes in 1.93 beta (07 Feb 2005):
|
||||||
|
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
|
||||||
|
* vmlinuz/386: fixes to support more kernels
|
||||||
|
|
||||||
|
Changes in 1.92 beta (20 Jul 2004):
|
||||||
|
* win32/pe: added option `--strip-loadconf' to strip the SEH
|
||||||
|
load config section
|
||||||
|
* win32/pe: try to detect .NET (win32/net) files [not yet supported by UPX]
|
||||||
|
* vmlinux/386: new format that directly supports building Linux kernels
|
||||||
|
* source code: now compiles cleanly under Win64
|
||||||
|
|
||||||
|
Changes in 1.91 beta (30 Jun 2004):
|
||||||
|
* djgpp2/coff: added support for recent binutils versions
|
||||||
|
* linux/elf386, linux/sh386: lots of improvements
|
||||||
|
* vmlinuz/386: added support for recent kernels
|
||||||
|
* watcom/le: don't crash on files without relocations
|
||||||
|
* win32/pe: stricter checks of some PE values
|
||||||
|
* option `--brute' now implies `--crp-ms=999999'.
|
||||||
|
* source code: much improved portability using ACC, the
|
||||||
|
Automatic Compiler Configuration
|
||||||
|
* source code: compile fixes for strict ISO C++ compilers
|
||||||
|
* source code: compile fixes for Win64
|
||||||
|
* re-synced with upx 1.25 branch
|
||||||
|
|
||||||
Changes in 1.90 beta (11 Nov 2002):
|
Changes in 1.90 beta (11 Nov 2002):
|
||||||
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
|
|
||||||
* implemented several new options for finer compression control:
|
* implemented several new options for finer compression control:
|
||||||
`--all-methods', `--all-filters' and `--brute'
|
`--all-methods', `--all-filters' and `--brute'
|
||||||
* ps1/exe: new format - UPX now supports PlayStation One programs
|
* ps1/exe: new format - UPX now supports PlayStation One programs
|
||||||
* linux/386: added the option `--force-execve'
|
* linux/386: added the option `--force-execve'
|
||||||
* vmlinuz/386: better kernel detection and sanity checks
|
* vmlinuz/386: better kernel detection and sanity checks
|
||||||
|
* re-synced with upx 1.24 branch
|
||||||
* documentation updates
|
* documentation updates
|
||||||
|
|
||||||
Changes in 1.11 beta (20 Dec 2000):
|
Changes in 1.11 beta (20 Dec 2000):
|
||||||
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
|
|
||||||
* vmlinuz/386: new format - UPX now supports bootable linux kernels
|
* vmlinuz/386: new format - UPX now supports bootable linux kernels
|
||||||
* linux/elf386: added the new ELF direct-to-memory executable format - no
|
* linux/elf386: added the new ELF direct-to-memory executable format - no
|
||||||
more temp files are needed for decompression!
|
more temp files are needed for decompression!
|
||||||
@@ -25,6 +48,15 @@ Changes in 1.11 beta (20 Dec 2000):
|
|||||||
|
|
||||||
==================================================================
|
==================================================================
|
||||||
|
|
||||||
|
Changes in 1.25 (29 Jun 2004)
|
||||||
|
* INFO: http://upx.sourceforge.net is the permanent UPX home page
|
||||||
|
* watcom/le: don't crash on files without relocations
|
||||||
|
* win32/pe: stricter checks of some PE values
|
||||||
|
* source code: much improved portability using ACC, the
|
||||||
|
Automatic Compiler Configuration
|
||||||
|
* source code: compile fixes for strict ISO C++ compilers
|
||||||
|
* source code: compile fixes for Win64
|
||||||
|
|
||||||
Changes in 1.24 (07 Nov 2002)
|
Changes in 1.24 (07 Nov 2002)
|
||||||
* djgpp2/coff: stricter check of the COFF header to work around a
|
* djgpp2/coff: stricter check of the COFF header to work around a
|
||||||
problem with certain binutils versions
|
problem with certain binutils versions
|
||||||
@@ -41,8 +73,8 @@ Changes in 1.23 (05 Sep 2002)
|
|||||||
Changes in 1.22 (27 Jun 2002)
|
Changes in 1.22 (27 Jun 2002)
|
||||||
* atari/tos: the stub now flushes the CPU cache to avoid
|
* atari/tos: the stub now flushes the CPU cache to avoid
|
||||||
problems on 68030+ machines
|
problems on 68030+ machines
|
||||||
* source code: additional compiler support for Borland C++ 5.5.1,
|
* source code: additional compiler support for Borland C++,
|
||||||
Digital Mars C++ 8.28 and Watcom C++ 11.0c
|
Digital Mars C++ and Watcom C++
|
||||||
|
|
||||||
Changes in 1.21 (01 Jun 2002)
|
Changes in 1.21 (01 Jun 2002)
|
||||||
* New option `--crp-ms=' for slightly better compression at the cost
|
* New option `--crp-ms=' for slightly better compression at the cost
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2002 Markus Oberhumer & Laszlo Molnar
|
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||||
http://upx.sourceforge.net
|
http://upx.sourceforge.net
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2002 Markus Oberhumer & Laszlo Molnar
|
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||||
http://upx.sourceforge.net
|
http://upx.sourceforge.net
|
||||||
|
|
||||||
|
|
||||||
@@ -20,12 +20,18 @@ All versions 1.9x are unstable beta releases - use them only for testing,
|
|||||||
and never distribute a program that is packed with them !
|
and never distribute a program that is packed with them !
|
||||||
There will be hidden bugs. Really.
|
There will be hidden bugs. Really.
|
||||||
|
|
||||||
The current stable release is 1.22, and the next stable release
|
The current stable release is 1.25, and the next stable release
|
||||||
will be called version 2.00.
|
will be called version 2.00.
|
||||||
|
|
||||||
The main news since 1.22 are support for bootable Linux kernels ("vmlinuz/386")
|
The main news since 1.25 are:
|
||||||
and direct Linux ELF-to-memory decompression ("linux/elf386"), so there's
|
- slightly better compression using the new NRV2E algorithm
|
||||||
no reason to use the unstable versions unless you want to try the new formats.
|
- new options for compression tuining (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 playstation exes ("ps1/exe")
|
||||||
|
- lots of new bugs ;-) take care
|
||||||
|
|
||||||
|
|
||||||
WELCOME
|
WELCOME
|
||||||
@@ -123,8 +129,8 @@ THE FUTURE
|
|||||||
COPYRIGHT
|
COPYRIGHT
|
||||||
=========
|
=========
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2005 Laszlo Molnar
|
||||||
|
|
||||||
This program may be used freely, and you are welcome to
|
This program may be used freely, and you are welcome to
|
||||||
redistribute it under certain conditions.
|
redistribute it under certain conditions.
|
||||||
|
|||||||
+5
-3
@@ -18,14 +18,16 @@ All versions 1.9x are unstable beta releases - use them only for testing,
|
|||||||
and never distribute a program that is packed with them !
|
and never distribute a program that is packed with them !
|
||||||
There will be hidden bugs. Really.
|
There will be hidden bugs. Really.
|
||||||
|
|
||||||
The current stable release is 1.24, and the next stable release
|
The current stable release is 1.25, and the next stable release
|
||||||
will be called version 2.00.
|
will be called version 2.00.
|
||||||
|
|
||||||
The main news since 1.24 are:
|
The main news since 1.25 are:
|
||||||
- slightly better compression using the new NRV2E algorithm
|
- slightly better compression using the new NRV2E algorithm
|
||||||
- new options for compression tuining (e.g. `--brute')
|
- new options for compression tuining (e.g. `--brute')
|
||||||
- support for bootable Linux kernels ("vmlinuz/386")
|
- support for bootable Linux kernels ("vmlinuz/386")
|
||||||
- direct Linux ELF-to-memory decompression ("linux/elf386")
|
- support for Linux kernel building ("vmlinux/386")
|
||||||
|
- direct Linux ELF-to-memory decompression ("linux/elf386") and
|
||||||
|
shell-to-memory decompression ("linux/sh386")
|
||||||
- support for playstation exes ("ps1/exe")
|
- support for playstation exes ("ps1/exe")
|
||||||
- lots of new bugs ;-) take care
|
- lots of new bugs ;-) take care
|
||||||
|
|
||||||
|
|||||||
+16
-16
@@ -66,13 +66,14 @@ Prerequisites
|
|||||||
Tools needed to build/modify the UPX sources
|
Tools needed to build/modify the UPX sources
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
- A modern C++ compiler like gcc 2.95.3 or Visual C++ 6
|
- A C++ compiler supporting inner classes, templates, exceptions
|
||||||
|
and RTTI.
|
||||||
|
|
||||||
- GNU make for Win32
|
- GNU make 3.80 for Win32
|
||||||
http://upx.sourceforge.net/download/tools/
|
http://www.cygwin.com/
|
||||||
|
|
||||||
- GNU make for DOS
|
- GNU make 3.80 for DOS
|
||||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/
|
http://www.delorie.com/djgpp/
|
||||||
|
|
||||||
|
|
||||||
To compile the packer sources
|
To compile the packer sources
|
||||||
@@ -80,25 +81,24 @@ To compile the packer sources
|
|||||||
|
|
||||||
set the environment variable UCLDIR to point to your UCL installation, e.g.
|
set the environment variable UCLDIR to point to your UCL installation, e.g.
|
||||||
|
|
||||||
set UCLDIR=c:\src\ucl-1.01 (DOS / Windows)
|
set UCLDIR=c:\src\ucl-1.03 (DOS / Windows)
|
||||||
export UCLDIR=$HOME/local/src/ucl-1.01 (Unix)
|
export UCLDIR=$HOME/local/src/ucl-1.03 (Unix)
|
||||||
|
|
||||||
then type
|
then type
|
||||||
|
|
||||||
make target=linux # on linux
|
make target=linux # linux
|
||||||
make target=djgpp2 # for djgpp2
|
make target=djgpp2 # dos32 - djgpp2
|
||||||
make target=mingw32 # for mingw32
|
make target=cygwin # win32 - cygwin 1.3.x
|
||||||
make target=cygwin # cygwin 1.3.x
|
make target=mingw32 # win32 - mingw32
|
||||||
make target=no-cygwin # for mingw32 as included in cygwin
|
make target=no-cygwin # win32 - mingw32 as included in cygwin
|
||||||
make target=vc6 # for Visual C++ 6.0
|
|
||||||
|
|
||||||
|
|
||||||
If you want to modify the stub sources you'll also need
|
If you want to modify the stub sources you'll also need
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
|
|
||||||
- Nasm 0.98.34 - the Netwide Assembler
|
- Nasm 0.98.38 - the Netwide Assembler
|
||||||
http://upx.sourceforge.net/download/tools/
|
http://upx.sourceforge.net/download/tools/
|
||||||
http://nasm.sourceforge.net/
|
http://sourceforge.net/projects/nasm/
|
||||||
|
|
||||||
- A68K - a 68000 macro assembler
|
- A68K - a 68000 macro assembler
|
||||||
http://upx.sourceforge.net/download/tools/
|
http://upx.sourceforge.net/download/tools/
|
||||||
@@ -106,7 +106,7 @@ If you want to modify the stub sources you'll also need
|
|||||||
- djasm - an assembler for the djgpp stub
|
- djasm - an assembler for the djgpp stub
|
||||||
http://upx.sourceforge.net/download/tools/
|
http://upx.sourceforge.net/download/tools/
|
||||||
|
|
||||||
- Perl 5.004 or better
|
- Perl 5.6 or better
|
||||||
|
|
||||||
- Linux (for the linux/386 stubs)
|
- Linux (for the linux/386 stubs)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2002 Markus Oberhumer & Laszlo Molnar
|
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||||
http://upx.sourceforge.net
|
http://upx.sourceforge.net
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
UPX TODO list. Last updated 2002-11-11.
|
UPX TODO list. Last updated 2005-01-08.
|
||||||
|
|
||||||
|
|
||||||
|
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
|
||||||
|
|
||||||
|
- stub ctojr32 needs CPU 486 because of bswap
|
||||||
|
|
||||||
|
|
||||||
|
OTHER:
|
||||||
|
|
||||||
|
- rewrite linker.cpp to allow arbitrary length section names
|
||||||
|
|
||||||
- check all <const_cast> to make sure they are not invalid
|
- check all <const_cast> to make sure they are not invalid
|
||||||
|
|
||||||
@@ -6,6 +16,8 @@ UPX TODO list. Last updated 2002-11-11.
|
|||||||
(info: bla bla). Also ui.cpp (total_*).
|
(info: bla bla). Also ui.cpp (total_*).
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
IMPROVED COMPRESSION RATIO
|
IMPROVED COMPRESSION RATIO
|
||||||
==========================
|
==========================
|
||||||
@@ -65,6 +77,8 @@ FORMAT TMT/ADAM
|
|||||||
FORMAT WATCOM/LE
|
FORMAT WATCOM/LE
|
||||||
================
|
================
|
||||||
|
|
||||||
|
- handle files without relocations
|
||||||
|
|
||||||
- the decompressors are already aligned, no need for an
|
- the decompressors are already aligned, no need for an
|
||||||
extra alignment
|
extra alignment
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ SHELL = /bin/sh
|
|||||||
top_srcdir = ..
|
top_srcdir = ..
|
||||||
|
|
||||||
PACKAGE = upx
|
PACKAGE = upx
|
||||||
VERSION_DATE = 11 Nov 2002
|
VERSION_DATE = 07 Feb 2005
|
||||||
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||||
|
|
||||||
TRIMSPACE = cat
|
TRIMSPACE = cat
|
||||||
|
|||||||
+66
-39
@@ -13,14 +13,15 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
|||||||
=head1 ABSTRACT
|
=head1 ABSTRACT
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2002 Markus Oberhumer & Laszlo Molnar
|
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||||
http://upx.sourceforge.net
|
http://upx.sourceforge.net
|
||||||
|
|
||||||
|
|
||||||
B<UPX> is a portable, extendable, high-performance executable packer for
|
B<UPX> is a portable, extendable, high-performance executable packer for
|
||||||
several different executable formats. It achieves an excellent compression
|
several different executable formats. It achieves an excellent compression
|
||||||
ratio and offers I<*very*> fast decompression. Your executables suffer
|
ratio and offers I<*very*> fast decompression. Your executables suffer
|
||||||
no memory overhead or other drawbacks for most of the formats supported.
|
no memory overhead or other drawbacks for most of the formats supported,
|
||||||
|
because of in-place decompression.
|
||||||
|
|
||||||
While you may use B<UPX> freely for both non-commercial and commercial
|
While you may use B<UPX> freely for both non-commercial and commercial
|
||||||
executables (for details see the file LICENSE), we would highly
|
executables (for details see the file LICENSE), we would highly
|
||||||
@@ -36,11 +37,6 @@ is considered not politically correct ;-) ]
|
|||||||
|
|
||||||
B<UPX> comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
|
B<UPX> comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
|
||||||
|
|
||||||
Having said that, we think that B<UPX> is quite stable now. Indeed we
|
|
||||||
have compressed lots of files without any problems. Also, the
|
|
||||||
current version has undergone several months of beta testing -
|
|
||||||
actually it's more than 4 years since our first public beta back in 1998.
|
|
||||||
|
|
||||||
This is the first production quality release, and we plan that future 1.xx
|
This is the first production quality release, and we plan that future 1.xx
|
||||||
releases will be backward compatible with this version.
|
releases will be backward compatible with this version.
|
||||||
|
|
||||||
@@ -55,7 +51,8 @@ B<UPX> is a versatile executable packer with the following features:
|
|||||||
- excellent compression ratio: compresses better than zip/gzip,
|
- excellent compression ratio: compresses better than zip/gzip,
|
||||||
use UPX to decrease the size of your distribution !
|
use UPX to decrease the size of your distribution !
|
||||||
|
|
||||||
- very fast decompression: about 10 MB/sec even on my old Pentium 133
|
- very fast decompression: about 10 MB/sec on an ancient Pentium 133,
|
||||||
|
about 200 MB/sec on an Athlon XP 2000+.
|
||||||
|
|
||||||
- no memory overhead for your compressed executables for most of the
|
- no memory overhead for your compressed executables for most of the
|
||||||
supported formats
|
supported formats
|
||||||
@@ -166,16 +163,19 @@ Compression level B<--best> may take a long time.
|
|||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
Note that compression level B<-9> can be somewhat slow for large
|
Note that compression level B<--best> can be somewhat slow for large
|
||||||
files, but you definitely should use it when releasing a final version
|
files, but you definitely should use it when releasing a final version
|
||||||
of your program.
|
of your program.
|
||||||
|
|
||||||
Since UPX 0.70 there is also an extra compression level B<--best> which
|
Quick start for achieving the best compression ratio:
|
||||||
squeezes out even some more compression ratio. While it is usually fine
|
|
||||||
to use this option with your favorite .com file it may take a long time
|
|
||||||
to compress a multi-megabyte program. You have been warned.
|
|
||||||
|
|
||||||
Tips for achieving the best compression ratio:
|
=over 4
|
||||||
|
|
||||||
|
Try B<upx --brute myfile.exe>.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
Details for achieving the best compression ratio:
|
||||||
|
|
||||||
=over 4
|
=over 4
|
||||||
|
|
||||||
@@ -187,8 +187,18 @@ Use the compression level B<--best>.
|
|||||||
|
|
||||||
Try one or both of the options B<--all-methods> and B<--all-filters>.
|
Try one or both of the options B<--all-methods> and B<--all-filters>.
|
||||||
|
|
||||||
Info: the option B<--brute> is an abbrevation for all the options
|
=item *
|
||||||
B<S<--best> S<--all-methods> S<--all-filters>>.
|
|
||||||
|
Try the option B<--crp-ms=NUMBER>. This uses more memory during compression
|
||||||
|
to achieve a (slightly) better compression ratio.
|
||||||
|
|
||||||
|
NUMBER must be a decimal value from 10000 to 999999, inclusive.
|
||||||
|
The default value is 10000 (ten thousand).
|
||||||
|
|
||||||
|
=item *
|
||||||
|
|
||||||
|
Info: the option B<--brute> is an abbrevation for the options
|
||||||
|
B<S<--best> S<--all-methods> S<--all-filters> S<--crp-ms=999999>>.
|
||||||
|
|
||||||
=item *
|
=item *
|
||||||
|
|
||||||
@@ -204,12 +214,15 @@ For win32/pe programs there's B<--strip-relocs=0>. See notes below.
|
|||||||
|
|
||||||
=head1 OVERLAY HANDLING OPTIONS
|
=head1 OVERLAY HANDLING OPTIONS
|
||||||
|
|
||||||
|
Info: An "overlay" means auxillary data atached after the logical end of
|
||||||
|
an executable, and it often contains application specific data
|
||||||
|
(this is a common practice to avoid an extra data file, though
|
||||||
|
it would be better to use resource sections).
|
||||||
|
|
||||||
B<UPX> handles overlays like many other executable packers do: it simply
|
B<UPX> handles overlays like many other executable packers do: it simply
|
||||||
copies the overlay after the compressed image. This works with some
|
copies the overlay after the compressed image. This works with some
|
||||||
files, but doesn't work with others.
|
files, but doesn't work with others, depending on how an application
|
||||||
|
actually accesses this overlayed data.
|
||||||
Since version 0.90 UPX defaults to B<--overlay=copy> for
|
|
||||||
all executable formats.
|
|
||||||
|
|
||||||
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
||||||
|
|
||||||
@@ -238,7 +251,8 @@ environment variable because of a COMMAND.COM limitation.
|
|||||||
Not all of the options are valid in the environment variable -
|
Not all of the options are valid in the environment variable -
|
||||||
B<UPX> will tell you.
|
B<UPX> will tell you.
|
||||||
|
|
||||||
You can use the B<--no-env> option to turn this support off.
|
You can explicitly use the B<--no-env> option to ignore the
|
||||||
|
environment variable.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -250,6 +264,7 @@ This is the executable format used by the Atari ST/TT, a Motorola 68000
|
|||||||
based personal computer which was popular in the late '80s. Support
|
based personal computer which was popular in the late '80s. Support
|
||||||
of this format is only because of nostalgic feelings of one of
|
of this format is only because of nostalgic feelings of one of
|
||||||
the authors and serves no practical purpose :-).
|
the authors and serves no practical purpose :-).
|
||||||
|
See http://www.freemint.de for more info.
|
||||||
|
|
||||||
Packed programs will be byte-identical to the original after uncompression.
|
Packed programs will be byte-identical to the original after uncompression.
|
||||||
All debug information will be stripped, though.
|
All debug information will be stripped, though.
|
||||||
@@ -354,7 +369,7 @@ will fix the 4 KByte aligment of the stub.
|
|||||||
|
|
||||||
B<UPX> includes the full functionality of stubify. This means it will
|
B<UPX> includes the full functionality of stubify. This means it will
|
||||||
automatically stubify your COFF files. Use the option B<--coff> to
|
automatically stubify your COFF files. Use the option B<--coff> to
|
||||||
disable this behaviour (see below).
|
disable this functionality (see below).
|
||||||
|
|
||||||
B<UPX> automatically handles Allegro packfiles.
|
B<UPX> automatically handles Allegro packfiles.
|
||||||
|
|
||||||
@@ -677,15 +692,18 @@ Extra options available for this executable format:
|
|||||||
This is the executable format used by the Sony PlayStation (PSone),
|
This is the executable format used by the Sony PlayStation (PSone),
|
||||||
a Mips R3000 based gaming console which is popular since the late '90s.
|
a Mips R3000 based gaming console which is popular since the late '90s.
|
||||||
Support of this format is very similar to the Atari one, because of
|
Support of this format is very similar to the Atari one, because of
|
||||||
nostalgic feelings of one of the authors, but this format maybe serves
|
nostalgic feelings of one of the authors.
|
||||||
a practical purpose ;-).
|
|
||||||
|
|
||||||
Packed programs will be byte-identical to the original after uncompression.
|
Packed programs will be byte-identical to the original after uncompression,
|
||||||
|
until further notice.
|
||||||
|
|
||||||
Maximum uncompressed size: ~1998848 bytes.
|
Maximum uncompressed size: ~1998848 bytes.
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
|
- UPX creates as default a 'CD-Rom only' PS1/PS2 compatible executable.
|
||||||
|
For transfer between client/target use options below.
|
||||||
|
|
||||||
- Normally the packed files use the same memory areas like the uncompressed
|
- Normally the packed files use the same memory areas like the uncompressed
|
||||||
versions, so they will not override other memory areas while unpacking.
|
versions, so they will not override other memory areas while unpacking.
|
||||||
If this isn't possible UPX will abort showing a 'packed data overlap'
|
If this isn't possible UPX will abort showing a 'packed data overlap'
|
||||||
@@ -700,10 +718,15 @@ Extra options available for this executable format:
|
|||||||
the compression ratio in some cases, but usually
|
the compression ratio in some cases, but usually
|
||||||
the default method gives the best results anyway.
|
the default method gives the best results anyway.
|
||||||
|
|
||||||
|
--boot-only The format will only run from a CD and may slightly
|
||||||
|
improves the compression ratio. The decompression
|
||||||
|
routines are faster than default ones.
|
||||||
|
But it cannot be used for host/client transfer !
|
||||||
|
|
||||||
--no-align This option disables CD mode 2 data sector format
|
--no-align This option disables CD mode 2 data sector format
|
||||||
alignment. This will slightly increase the compression
|
alignment. May slightly improves the compression ratio,
|
||||||
ratio, but the compressed executable will not work
|
but the compressed executable will not boot from a CD.
|
||||||
when started from a CD.
|
Use it for client/target transfer only !
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -758,8 +781,8 @@ Benefits:
|
|||||||
641073 bzImage [original]
|
641073 bzImage [original]
|
||||||
560755 bzImage.upx [compressed by "upx -9"]
|
560755 bzImage.upx [compressed by "upx -9"]
|
||||||
|
|
||||||
- Much faster decompression at kernel boot time (but decompression
|
- Much faster decompression at kernel boot time (but kernel
|
||||||
speed is not really an issue these days).
|
decompression speed is not really an issue these days).
|
||||||
|
|
||||||
Drawbacks:
|
Drawbacks:
|
||||||
|
|
||||||
@@ -801,10 +824,11 @@ The PE support in B<UPX> is quite stable now, but probably there are
|
|||||||
still some incompabilities with some files.
|
still some incompabilities with some files.
|
||||||
|
|
||||||
Because of the way B<UPX> (and other packers for this format) works, you
|
Because of the way B<UPX> (and other packers for this format) works, you
|
||||||
can see increased memory usage of your compressed files. If you start
|
can see increased memory usage of your compressed files because the whole
|
||||||
several instances of huge compressed programs you're wasting memory
|
program is loaded into memory at startup.
|
||||||
because the common segements of the program won't get shared
|
If you start several instances of huge compressed programs you're
|
||||||
across the instances.
|
wasting memory because the common segements of the program won't
|
||||||
|
get shared across the instances.
|
||||||
On the other hand if you're compressing only smaller programs, or
|
On the other hand if you're compressing only smaller programs, or
|
||||||
running only one instance of larger programs, then this penalty is
|
running only one instance of larger programs, then this penalty is
|
||||||
smaller, but it's still there.
|
smaller, but it's still there.
|
||||||
@@ -841,13 +865,16 @@ Extra options available for this executable format:
|
|||||||
unexpected value in a header field.
|
unexpected value in a header field.
|
||||||
Use with care.
|
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=0 Don't strip relocation records.
|
||||||
--strip-relocs=1 Strip relocation records. [DEFAULT]
|
--strip-relocs=1 Strip relocation records. [DEFAULT]
|
||||||
This option only works on executables with base
|
This option only works on executables with base
|
||||||
address greater or equal to 0x400000. Usually the
|
address greater or equal to 0x400000. Usually the
|
||||||
compressed files becomes smaller, but some files
|
compressed files becomes smaller, but some files
|
||||||
may become larger. Note that the resulting file will
|
may become larger. Note that the resulting file will
|
||||||
not work under Win32s.
|
not work under Windows 3.x (Win32s).
|
||||||
UPX never strips relocations from a DLL
|
UPX never strips relocations from a DLL
|
||||||
regardless of this option.
|
regardless of this option.
|
||||||
|
|
||||||
@@ -893,13 +920,13 @@ Please report all bugs immediately to the authors.
|
|||||||
|
|
||||||
=head1 COPYRIGHT
|
=head1 COPYRIGHT
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2005 Laszlo Molnar
|
||||||
|
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2005 John F. Reiser
|
||||||
|
|
||||||
Copyright (C) 2002 Jens Medoch
|
Copyright (C) 2002-2005 Jens Medoch
|
||||||
|
|
||||||
This program may be used freely, and you are welcome to
|
This program may be used freely, and you are welcome to
|
||||||
redistribute it under certain conditions.
|
redistribute it under certain conditions.
|
||||||
|
|||||||
+2591
-1236
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,24 @@
|
|||||||
GNUmakefile
|
GNUmakefile
|
||||||
*.0??
|
*.0??
|
||||||
|
*.d
|
||||||
*.dat
|
*.dat
|
||||||
*.idb
|
*.idb
|
||||||
*.img
|
*.img
|
||||||
*.map
|
*.map
|
||||||
*.raw
|
*.raw
|
||||||
|
*.rc
|
||||||
*.rel
|
*.rel
|
||||||
|
*.res
|
||||||
*.pdb
|
*.pdb
|
||||||
*.upx
|
*.upx
|
||||||
.gdbinit
|
.gdbinit
|
||||||
.Attic
|
.Attic
|
||||||
.deps
|
.deps
|
||||||
|
B
|
||||||
compress_nrv.*
|
compress_nrv.*
|
||||||
upx
|
upx
|
||||||
upx_nrv
|
upx_nrv
|
||||||
upx_nrv.*
|
upx_nrv.*
|
||||||
upx_ucl
|
upx_ucl
|
||||||
upx_ucl.*
|
upx_ucl.*
|
||||||
|
version1*.h
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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
|
||||||
|
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
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
|
||||||
@@ -4,27 +4,36 @@ ifneq ($(strip $(wildcard $(UDIR)/include)),) # { include
|
|||||||
DEFS += -DWITH_$(U)
|
DEFS += -DWITH_$(U)
|
||||||
INCLUDES += -I$(UDIR)/include
|
INCLUDES += -I$(UDIR)/include
|
||||||
|
|
||||||
ifneq ($(strip $(wildcard $(UDIR)/build/$(target)/src/.libs)),)
|
|
||||||
LIBDIRS += $(UDIR)/build/$(target)/src/.libs
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(wildcard $(UDIR)/src/.libs)),)
|
|
||||||
LIBDIRS += $(UDIR)/src/.libs
|
|
||||||
endif
|
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
ifneq ($(strip $(wildcard $(UDIR)/build/debug/src/.libs)),)
|
ifneq ($(strip $(wildcard $(UDIR)/build/debug/src/.libs)),)
|
||||||
LIBDIRS += $(UDIR)/build/debug/src/.libs
|
LIBDIRS += $(UDIR)/build/debug/src/.libs
|
||||||
endif
|
endif
|
||||||
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)),)
|
ifneq ($(strip $(wildcard $(UDIR)/build/release/src/.libs)),)
|
||||||
LIBDIRS += $(UDIR)/build/release/src/.libs
|
LIBDIRS += $(UDIR)/build/release/src/.libs
|
||||||
endif
|
else
|
||||||
ifneq ($(strip $(wildcard $(UDIR)/build/src/.libs)),)
|
ifneq ($(strip $(wildcard $(UDIR)/build/src/.libs)),)
|
||||||
LIBDIRS += $(UDIR)/build/src/.libs
|
LIBDIRS += $(UDIR)/build/src/.libs
|
||||||
endif
|
else
|
||||||
ifneq ($(strip $(wildcard $(UDIR))),)
|
ifneq ($(strip $(wildcard $(UDIR))),)
|
||||||
LIBDIRS += $(UDIR)
|
LIBDIRS += $(UDIR)
|
||||||
DOS_LIBDIRS := $(DOS_LIBDIRS);$(UDIR)
|
DOS_LIBDIRS := $(DOS_LIBDIRS);$(UDIR)
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
LDLIBS += -l$(u)
|
LDLIBS += -l$(u)
|
||||||
DOS_LDLIBS += $(u).lib
|
DOS_LDLIBS += $(u).lib
|
||||||
+23
-560
@@ -3,17 +3,21 @@
|
|||||||
#
|
#
|
||||||
# usage:
|
# usage:
|
||||||
# `make target=linux' # linux
|
# `make target=linux' # linux
|
||||||
# `make target=djggp2' # dos32 - djggp2 2.03
|
# `make target=dos32-djggp2' # dos32 - djggp2
|
||||||
# `make target=cygwin' # win32 - cygwin 1.3.x
|
# `make target=win32-cygwin' # win32 - cygwin
|
||||||
# `make target=mingw32' # win32 - mingw32
|
# `make target=win32-mingw32' # win32 - mingw32
|
||||||
# `make target=no-cygwin' # win32 - mingw32 as included in cygwin 1.3.x
|
# `make target=win32-rsxnt' # win32 - rsxnt
|
||||||
# `make target=bcc' # win32 - Borland C++ 5.5.1
|
# `make target=win32-bc' # win32 - Borland C++
|
||||||
# `make target=dmc' # win32 - Digital Mars C++ 8.30
|
# `make target=win32-dm' # win32 - Digital Mars C++
|
||||||
# `make target=vc6' # win32 - Visual C++ 6.0
|
# `make target=win32-ic' # win32 - Intel C++
|
||||||
# `make target=wcc' # win32 - Watcom C++ 11.0c
|
# `make target=win32-vc' # win32 - Visual C++
|
||||||
# `make target=cross-m68k-linux' # m68k-linux cross compiler
|
# `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-mingw32' # i586-mingw32msvc cross compiler
|
||||||
# `make target=cross-mint' # m68k-atari-mint 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.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@@ -21,49 +25,19 @@
|
|||||||
|
|
||||||
ifeq ($(strip $(UCLDIR)),)
|
ifeq ($(strip $(UCLDIR)),)
|
||||||
# change this to reflect where the UCL library is
|
# change this to reflect where the UCL library is
|
||||||
UCLDIR = $(HOME)/local/src/ucl-1.01
|
UCLDIR = $(HOME)/local/src/ucl-1.03
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
## you can set the default target here
|
||||||
##target =
|
##target =
|
||||||
|
|
||||||
DEBUG = 0
|
DEBUG = 0
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------
|
|
||||||
# You should not have to change anything below this line.
|
|
||||||
# -------------------------------------------------------
|
|
||||||
|
|
||||||
SHELL = /bin/sh
|
|
||||||
|
|
||||||
|
|
||||||
.SUFFIXES:
|
|
||||||
.SUFFIXES: .a .c .cpp .exe .lib .o .obj .rc .res .ttp
|
|
||||||
|
|
||||||
|
|
||||||
srcdir = .
|
srcdir = .
|
||||||
top_srcdir = ..
|
top_srcdir = ..
|
||||||
|
|
||||||
VPATH = $(srcdir)
|
|
||||||
|
|
||||||
|
##### You should not have to change anything below this line. #####
|
||||||
# auto-detect the target unless given on the commandline
|
|
||||||
ifeq ($(strip $(target)),)
|
|
||||||
##target = djgpp2
|
|
||||||
ifneq ($(strip $(wildcard /usr/include/linux)),)
|
|
||||||
target = linux
|
|
||||||
endif
|
|
||||||
##ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),)
|
|
||||||
##target = sparc
|
|
||||||
##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 $@)
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
@@ -78,7 +52,7 @@ OBJECTS1 = \
|
|||||||
p_com$o p_djgpp2$o p_elks$o p_exe$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_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_ps1$o p_sys$o p_tmt$o p_tos$o \
|
||||||
p_unix$o p_vmlinz$o p_w16ne$o p_w32pe$o p_wcle$o
|
p_unix$o p_vmlinz$o p_vmlinx$o p_w16ne$o p_w32pe$o p_wcle$o
|
||||||
|
|
||||||
# no exceptions or RTTI
|
# no exceptions or RTTI
|
||||||
OBJECTS2 = \
|
OBJECTS2 = \
|
||||||
@@ -95,531 +69,20 @@ RESOURCES =
|
|||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
# // compiler settings
|
# // main
|
||||||
# ************************************************************************/
|
# ************************************************************************/
|
||||||
|
|
||||||
###
|
override WITH_ZLIB = 1
|
||||||
### default compiler (gcc under unix)
|
|
||||||
###
|
|
||||||
|
|
||||||
o = .o
|
include $(srcdir)/Makefile.bld
|
||||||
a = .a
|
|
||||||
e =
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
DEFS =
|
|
||||||
INCLUDES =
|
|
||||||
##INCLUDES = -I. -I$(srcdir)
|
|
||||||
CFLAGS_OUTPUT = -o $@
|
|
||||||
|
|
||||||
LINK_EXE = $(CXXLD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
|
||||||
STUBEDIT_EXE =
|
|
||||||
STUBIFY_EXE =
|
|
||||||
CHMOD_EXE =
|
|
||||||
|
|
||||||
# C++ defaults are set later
|
|
||||||
CXX =
|
|
||||||
CXXLD =
|
|
||||||
CXXFLAGS_OUTPUT =
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### gcc defaults
|
|
||||||
###
|
|
||||||
|
|
||||||
##CFLAGS_WERROR = -Werror
|
|
||||||
CFLAGS_WERROR =
|
|
||||||
CFLAGS_W = $(CFLAGS_WERROR)
|
|
||||||
CFLAGS_W += -Wall -W -Wcast-align -Wcast-qual -Wmissing-prototypes -Wpointer-arith -Wshadow -Wwrite-strings
|
|
||||||
CFLAGS_M =
|
|
||||||
##CFLAGS_M += -fno-builtin
|
|
||||||
##CFLAGS_M += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
|
||||||
##CFLAGS_O = -Os -fstrict-aliasing
|
|
||||||
##CFLAGS_O = -O2 -fstrict-aliasing
|
|
||||||
CFLAGS_O = -O2 -fno-strict-aliasing
|
|
||||||
|
|
||||||
CFLAGS = $(CFLAGS_W) $(CFLAGS_M) $(CFLAGS_O)
|
|
||||||
CXXFLAGS = $(CFLAGS) -Wsynth -fconserve-space
|
|
||||||
CXXFLAGS1 = $(CXXFLAGS)
|
|
||||||
##CXXFLAGS1 += -fasynchronous-exceptions
|
|
||||||
CXXFLAGS2 = $(CXXFLAGS) -fno-exceptions -fno-rtti
|
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
|
||||||
DEFS += -DDEBUG
|
|
||||||
## DEFS += -DTESTING
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
|
||||||
LDFLAGS = -g
|
|
||||||
else
|
|
||||||
LDFLAGS = -s
|
|
||||||
endif
|
|
||||||
LDFLAGS += -Wl,-Map,$T.map
|
|
||||||
LDLIBS = -lz
|
|
||||||
LIBDIRS =
|
|
||||||
DOS_LDLIBS =
|
|
||||||
DOS_LIBDIRS =
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### compression library
|
|
||||||
###
|
|
||||||
|
|
||||||
UCLDIR:=$(strip $(subst \,/,$(UCLDIR)))
|
|
||||||
NRVDIR:=$(strip $(subst \,/,$(NRVDIR)))
|
|
||||||
u = ucl
|
|
||||||
U = UCL
|
|
||||||
upx_exe_tail =
|
|
||||||
include $(srcdir)/Makefile.inc
|
|
||||||
ifneq ($(strip $(wildcard $(NRVDIR)/include/nrv)),)
|
|
||||||
u = nrv
|
|
||||||
U = NRV
|
|
||||||
upx_exe_tail = _$(u)
|
|
||||||
include $(srcdir)/Makefile.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)
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Linux
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),linux)
|
|
||||||
override arch := $(shell uname -m | sed -e 's/^i[3456789]86$$/i386/')
|
|
||||||
DEFS += '-DUPX_CONFIG_H="config_h/linux.h"'
|
|
||||||
DEFS += -D_FILE_OFFSET_BITS=64
|
|
||||||
LDLIBS += -lmcheck
|
|
||||||
ifeq ($(arch),i386)
|
|
||||||
CC += -march=i386 -mcpu=i586
|
|
||||||
##CFLAGS_M += -mno-schedule-prologue
|
|
||||||
endif
|
|
||||||
##CFLAGS_WERROR = -Werror
|
|
||||||
|
|
||||||
ifeq (1,2) # checkergcc
|
|
||||||
CC = checkergcc
|
|
||||||
CXX = checkerg++
|
|
||||||
else
|
|
||||||
ifeq ($(DEBUG),1)
|
|
||||||
##CFLAGS += -O0 -gstabs+3
|
|
||||||
##CFLAGS += -O0 -gdwarf-2
|
|
||||||
CFLAGS += -O0 -g
|
|
||||||
else
|
|
||||||
##LDFLAGS += -static
|
|
||||||
STUBEDIT_EXE = objcopy -S -R .comment -R .note $@
|
|
||||||
ifeq ($(arch),i386)
|
|
||||||
STUBIFY_EXE = perl $(srcdir)/stub/scripts/brandelf.pl $@
|
|
||||||
CHMOD_EXE = chmod 755 $@
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
endif # linux
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Linux cross compilers
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),cross-m68k-linux)
|
|
||||||
CC = m68k-linux-gcc
|
|
||||||
DEFS += '-DUPX_CONFIG_H="config_h/linux.h"'
|
|
||||||
##LDLIBS += -lmcheck
|
|
||||||
endif # cross-m68k-linux
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### sparc-sun-solaris2.8
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),sparc)
|
|
||||||
CC = gcc
|
|
||||||
DEFS += '-DUPX_CONFIG_H="config_h/sparc_sun_solaris28.h"'
|
|
||||||
endif # sparc
|
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(target),XXX-sparc)
|
|
||||||
DEFS += '-DUPX_CONFIG_H="config_h/sparc_sun_solaris28.h"'
|
|
||||||
INCLUDES += -I/home/ethmola/local/include
|
|
||||||
|
|
||||||
ifeq (1,2) # native compiler
|
|
||||||
CFLAGS = -O0 -g
|
|
||||||
CXXFLAGS1 =
|
|
||||||
CXXFLAGS2 =
|
|
||||||
DEFS += -DUSE_STDNAMESPACE
|
|
||||||
else # gcc
|
|
||||||
CFLAGS += -O0 -gstabs+
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq (1,2) # purify
|
|
||||||
DEFS += -D__PURIFY__
|
|
||||||
CXXLD := purify $(CXXLD)
|
|
||||||
endif
|
|
||||||
|
|
||||||
endif # XXX-sparc
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Atari cross compiler
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),cross-mint)
|
|
||||||
e = .ttp
|
|
||||||
CC = m68k-atari-mint-gcc
|
|
||||||
CC += -m68000
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(target),cross-mint-m68040)
|
|
||||||
e = .ttp
|
|
||||||
CC = m68k-atari-mint-gcc
|
|
||||||
CC += -m68040
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(target),cross-mint-m68020-60)
|
|
||||||
e = .ttp
|
|
||||||
CC = m68k-atari-mint-gcc
|
|
||||||
CC += -m68020-60 -m68881
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### djgpp2
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),djgpp2)
|
|
||||||
e = .exe
|
|
||||||
CC += -march=i386 -mcpu=i586
|
|
||||||
##CFLAGS_M += -mno-schedule-prologue
|
|
||||||
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 $(upx_exe)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif # djgpp2
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### cygwin / mingw32
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),cygwin)
|
|
||||||
e = .exe
|
|
||||||
CC += -march=i386 -mcpu=i586
|
|
||||||
CXXLD = g++
|
|
||||||
##CFLAGS_M += -mno-schedule-prologue
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(target),mingw32)
|
|
||||||
e = .exe
|
|
||||||
CC = gcc -mno-cygwin
|
|
||||||
CC += -march=i386 -mcpu=i586
|
|
||||||
CXXLD = g++ -mno-cygwin
|
|
||||||
##CFLAGS_M += -mno-schedule-prologue
|
|
||||||
endif
|
|
||||||
|
|
||||||
# mingw32 as included in cygwin
|
|
||||||
ifeq ($(target),no-cygwin)
|
|
||||||
e = .exe
|
|
||||||
CC = gcc -mno-cygwin
|
|
||||||
CC += -march=i386 -mcpu=i586
|
|
||||||
CXXLD = g++ -mno-cygwin
|
|
||||||
##CFLAGS_M += -mno-schedule-prologue
|
|
||||||
endif
|
|
||||||
|
|
||||||
# mingw32 cross compiler
|
|
||||||
ifeq ($(target),cross-mingw32)
|
|
||||||
e = .exe
|
|
||||||
CC = i586-mingw32msvc-gcc
|
|
||||||
CC += -march=i386 -mcpu=i586
|
|
||||||
CXXLD = i586-mingw32msvc-g++
|
|
||||||
##CFLAGS_M += -mno-schedule-prologue
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Borland C++ 5.5.1
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),bcc)
|
|
||||||
o = .obj
|
|
||||||
a = .lib
|
|
||||||
e = .exe
|
|
||||||
CC = bcc32 -q
|
|
||||||
CFLAGS = -w -w-aus -g1
|
|
||||||
CXXFLAGS1 = $(CFLAGS)
|
|
||||||
CXXFLAGS2 = $(CFLAGS) -x- -xd- -RT-
|
|
||||||
CFLAGS_OUTPUT = -o$@
|
|
||||||
LDFLAGS =
|
|
||||||
LDLIBS = $(DOS_LDLIBS) zlib114.lib
|
|
||||||
|
|
||||||
ifneq ($(strip $(DOS_LIBDIRS)),)
|
|
||||||
LIB := $(DOS_LIBDIRS);$(LIB)
|
|
||||||
endif
|
|
||||||
export LIB
|
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
|
||||||
CFLAGS += -Od -d
|
|
||||||
else
|
|
||||||
CFLAGS += -O2 -d
|
|
||||||
endif
|
|
||||||
|
|
||||||
LINK_EXE = $(CXXLD) $(LDFLAGS) -e$@ $^ $(LDLIBS)
|
|
||||||
|
|
||||||
endif # bcc
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Digital Mars C++ 8.30
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),dmc)
|
|
||||||
o = .obj
|
|
||||||
a = .lib
|
|
||||||
e = .exe
|
|
||||||
CC = dmc -mn
|
|
||||||
CFLAGS = -w- -wx
|
|
||||||
CXXFLAGS1 = $(CFLAGS) -Aa -Ab -Ae -Ar
|
|
||||||
CXXFLAGS2 = $(CFLAGS) -Aa -Ab
|
|
||||||
CFLAGS_OUTPUT = -o$@
|
|
||||||
LDFLAGS =
|
|
||||||
LDLIBS = $(DOS_LDLIBS)
|
|
||||||
|
|
||||||
ifneq ($(strip $(DOS_LIBDIRS)),)
|
|
||||||
LIB := $(DOS_LIBDIRS);$(LIB)
|
|
||||||
endif
|
|
||||||
export LIB
|
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
|
||||||
CFLAGS += -o- -g -s
|
|
||||||
else
|
|
||||||
CFLAGS += -o
|
|
||||||
endif
|
|
||||||
|
|
||||||
LINK_EXE = $(CXXLD) $(LDFLAGS) -o$@ $^ $(LDLIBS)
|
|
||||||
|
|
||||||
endif # dmc
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Visual C++ 6 (aka Microsoft C/C++ Compiler 12.00)
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),vc6)
|
|
||||||
o = .obj
|
|
||||||
a = .lib
|
|
||||||
e = .exe
|
|
||||||
CC = cl -nologo
|
|
||||||
CFLAGS = -W4 -WX
|
|
||||||
CXXFLAGS1 = $(CFLAGS) -EHac -GR
|
|
||||||
CXXFLAGS2 = $(CFLAGS)
|
|
||||||
LDFLAGS =
|
|
||||||
LINK_LDFLAGS = /link /map:$T.map
|
|
||||||
|
|
||||||
ifneq ($(strip $(DOS_LIBDIRS)),)
|
|
||||||
LIB := $(DOS_LIBDIRS);$(LIB)
|
|
||||||
endif
|
|
||||||
export LIB
|
|
||||||
|
|
||||||
ifeq (1,2)
|
|
||||||
# statically link libc.lib
|
|
||||||
CC += -ML
|
|
||||||
LDLIBS = $(u)_s.lib setargv.obj
|
|
||||||
else
|
|
||||||
# link against msvcrt.dll
|
|
||||||
CC += -MD
|
|
||||||
LDLIBS = $(DOS_LDLIBS) zlib114.lib setargv.obj
|
|
||||||
endif
|
|
||||||
ifeq ($(DEBUG),1)
|
|
||||||
CFLAGS += -Od -ZI
|
|
||||||
LINK_LDFLAGS += /debug
|
|
||||||
else
|
|
||||||
CFLAGS += -O2 -GF
|
|
||||||
LINK_LDFLAGS += /release
|
|
||||||
endif
|
|
||||||
RESOURCES = upx.res
|
|
||||||
|
|
||||||
##LINK_LDFLAGS += /verbose
|
|
||||||
LINK_EXE = $(CXXLD) $(LDFLAGS) -Fe$@ $^ $(LDLIBS) $(LINK_LDFLAGS)
|
|
||||||
|
|
||||||
endif # vc6
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### Watcom C++ 11.0c
|
|
||||||
###
|
|
||||||
|
|
||||||
ifeq ($(target),wcc)
|
|
||||||
o = .obj
|
|
||||||
a = .lib
|
|
||||||
e = .exe
|
|
||||||
CC = wcl386 -zq -bt=nt -mf -5r
|
|
||||||
CFLAGS = -zc -w5 -we
|
|
||||||
CXXFLAGS1 = $(CFLAGS) -xs -xr
|
|
||||||
CXXFLAGS2 = $(CFLAGS)
|
|
||||||
CFLAGS_OUTPUT = -fo=$@
|
|
||||||
LDFLAGS = -k0x100000 -fm
|
|
||||||
LDLIBS = $(DOS_LDLIBS)
|
|
||||||
|
|
||||||
INCLUDES:=$(strip $(subst /,\\,$(INCLUDES)))
|
|
||||||
ifeq (1,2)
|
|
||||||
WCL386:=$(INCLUDES)
|
|
||||||
export WCL386
|
|
||||||
INCLUDES:=
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq ($(strip $(DOS_LIBDIRS)),)
|
|
||||||
LIB := $(DOS_LIBDIRS);$(LIB)
|
|
||||||
endif
|
|
||||||
export LIB
|
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
|
||||||
CFLAGS +=
|
|
||||||
else
|
|
||||||
# note: it seems that the optimizer is generating bad code with `-ox'
|
|
||||||
CFLAGS += -olr
|
|
||||||
endif
|
|
||||||
|
|
||||||
LINK_EXE = $(CXXLD) $(LDFLAGS) -fe=$@ $^ $(LDLIBS)
|
|
||||||
|
|
||||||
endif # wcc
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // malloc debuggers and memory checkers - somewhat obsolete, use valgrind
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
ifeq (1,2)
|
|
||||||
# compile in extra valgrind support
|
|
||||||
CFLAGS += -DWITH_VALGRIND
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq (1,2)
|
|
||||||
LDLIBS += -lefence
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq (1,2)
|
|
||||||
CFLAGS += -DWITH_DMALLOC
|
|
||||||
LDLIBS += -ldmalloc
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq (1,2)
|
|
||||||
CFLAGS += -DWITH_GC -DLINUX_THREADS -D_REENTRANT
|
|
||||||
LDLIBS += -lgc -lpthread
|
|
||||||
# only needed when using -static:
|
|
||||||
##LDFLAGS += -Wl,-defsym,_DYNAMIC=0
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // finish settings
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
# C++ defaults
|
|
||||||
ifeq ($(strip $(CXX)),)
|
|
||||||
ifeq ($(strip $(CC)),gcc)
|
|
||||||
CXX = g++
|
|
||||||
else
|
|
||||||
CXX = $(CC)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
ifeq ($(strip $(CXXLD)),)
|
|
||||||
CXXLD = $(CXX)
|
|
||||||
endif
|
|
||||||
ifeq ($(strip $(CXXFLAGS_OUTPUT)),)
|
|
||||||
CXXFLAGS_OUTPUT = $(CFLAGS_OUTPUT)
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
# extra flags
|
|
||||||
DEFS += $(EXTRA_DEFS)
|
|
||||||
CFLAGS += $(EXTRA_CFLAGS)
|
|
||||||
CFLAGS_W += $(EXTRA_CFLAGS_W)
|
|
||||||
CFLAGS_M += $(EXTRA_CFLAGS_M)
|
|
||||||
CFLAGS_O += $(EXTRA_CFLAGS_O)
|
|
||||||
CXXFLAGS1 += $(EXTRA_CXXFLAGS1)
|
|
||||||
CXXFLAGS2 += $(EXTRA_CXXFLAGS2)
|
|
||||||
LDFLAGS += $(EXTRA_LDFLAGS)
|
|
||||||
LDLIBS += $(EXTRA_LDLIBS)
|
|
||||||
|
|
||||||
|
|
||||||
# To better deal with asynchronous exceptions we compile all source
|
|
||||||
# files with exception handling and RTTI enabled - the size overhead
|
|
||||||
# is negligible.
|
|
||||||
CXXFLAGS2 = $(CXXFLAGS1)
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // main targets
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
all: $(upx_exe)
|
|
||||||
|
|
||||||
.PHONY: all mostlyclean clean distclean maintainer-clean untabify tags
|
|
||||||
|
|
||||||
$(upx_exe): $(OBJECTS) $(LIBS) $(RESOURCES)
|
|
||||||
$(LINK_EXE)
|
|
||||||
$(STUBEDIT_EXE)
|
|
||||||
$(STUBIFY_EXE)
|
|
||||||
$(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
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
|
|
||||||
maintainer-clean: distclean
|
|
||||||
|
|
||||||
|
|
||||||
untabify:
|
|
||||||
mfxtu -d4 -t *.h *.cpp *.ch
|
|
||||||
mfxtu -d8 -t stub/[ln]*.asm stub/*.ash stub/*.[cs]
|
|
||||||
|
|
||||||
tags TAGS:
|
|
||||||
ctags *.h *.cpp *.ch
|
|
||||||
|
|
||||||
ID:
|
|
||||||
mkid *.h *.cpp *.ch
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // rules
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
%$o : %.c
|
|
||||||
$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) $(CFLAGS_OUTPUT) -c $<
|
|
||||||
|
|
||||||
%$o : %.cpp
|
|
||||||
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS1) $(CXXFLAGS_OUTPUT) -c $<
|
|
||||||
|
|
||||||
ifneq ($(strip $(OBJECTS2)),)
|
|
||||||
$(OBJECTS2): %$o : %.cpp
|
|
||||||
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS2) $(CXXFLAGS_OUTPUT) -c $<
|
|
||||||
endif
|
|
||||||
|
|
||||||
%.res : %.rc
|
|
||||||
rc -l 0x409 -fo$@ $<
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
# // dependencies
|
# // dependencies
|
||||||
# ************************************************************************/
|
# ************************************************************************/
|
||||||
|
|
||||||
include $(srcdir)/Makefile.dep
|
include $(srcdir)/Makedefs.dep
|
||||||
|
|
||||||
|
$(OBJECTS): miniacc.h
|
||||||
|
|
||||||
# vi:nowrap
|
# vi:nowrap
|
||||||
|
|||||||
@@ -0,0 +1,720 @@
|
|||||||
|
# /***********************************************************************
|
||||||
|
# // 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
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // automated dependencies
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
CFLAGS += -Wp,-MMD,.deps/$(*F).pp
|
|
||||||
|
|
||||||
ifeq ($(strip $(wildcard .deps)),)
|
|
||||||
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
|
||||||
else
|
|
||||||
DEP_FILES := $(wildcard .deps/*.pp)
|
|
||||||
ifneq ($(strip $(DEP_FILES)),)
|
|
||||||
include $(DEP_FILES)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
+94
-91
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
inline unsigned get_be16(const void *bb)
|
inline unsigned get_be16(const void *bb)
|
||||||
{
|
{
|
||||||
const upx_bytep b = (const upx_bytep) bb;
|
const unsigned char* b = (const unsigned char*) bb;
|
||||||
unsigned v;
|
unsigned v;
|
||||||
v = (unsigned) b[1] << 0;
|
v = (unsigned) b[1] << 0;
|
||||||
v |= (unsigned) b[0] << 8;
|
v |= (unsigned) b[0] << 8;
|
||||||
@@ -45,7 +45,7 @@ inline unsigned get_be16(const void *bb)
|
|||||||
|
|
||||||
inline void set_be16(void *bb, unsigned v)
|
inline void set_be16(void *bb, unsigned v)
|
||||||
{
|
{
|
||||||
upx_bytep b = (upx_bytep) bb;
|
unsigned char* b = (unsigned char*) bb;
|
||||||
b[1] = (unsigned char) (v >> 0);
|
b[1] = (unsigned char) (v >> 0);
|
||||||
b[0] = (unsigned char) (v >> 8);
|
b[0] = (unsigned char) (v >> 8);
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ inline void set_be16(void *bb, unsigned v)
|
|||||||
|
|
||||||
inline unsigned get_be24(const void *bb)
|
inline unsigned get_be24(const void *bb)
|
||||||
{
|
{
|
||||||
const upx_bytep b = (const upx_bytep) bb;
|
const unsigned char* b = (const unsigned char*) bb;
|
||||||
unsigned v;
|
unsigned v;
|
||||||
v = (unsigned) b[2] << 0;
|
v = (unsigned) b[2] << 0;
|
||||||
v |= (unsigned) b[1] << 8;
|
v |= (unsigned) b[1] << 8;
|
||||||
@@ -63,7 +63,7 @@ inline unsigned get_be24(const void *bb)
|
|||||||
|
|
||||||
inline void set_be24(void *bb, unsigned v)
|
inline void set_be24(void *bb, unsigned v)
|
||||||
{
|
{
|
||||||
upx_bytep b = (upx_bytep) bb;
|
unsigned char* b = (unsigned char*) bb;
|
||||||
b[2] = (unsigned char) (v >> 0);
|
b[2] = (unsigned char) (v >> 0);
|
||||||
b[1] = (unsigned char) (v >> 8);
|
b[1] = (unsigned char) (v >> 8);
|
||||||
b[0] = (unsigned char) (v >> 16);
|
b[0] = (unsigned char) (v >> 16);
|
||||||
@@ -72,7 +72,7 @@ inline void set_be24(void *bb, unsigned v)
|
|||||||
|
|
||||||
inline unsigned get_be32(const void *bb)
|
inline unsigned get_be32(const void *bb)
|
||||||
{
|
{
|
||||||
const upx_bytep b = (const upx_bytep) bb;
|
const unsigned char* b = (const unsigned char*) bb;
|
||||||
unsigned v;
|
unsigned v;
|
||||||
v = (unsigned) b[3] << 0;
|
v = (unsigned) b[3] << 0;
|
||||||
v |= (unsigned) b[2] << 8;
|
v |= (unsigned) b[2] << 8;
|
||||||
@@ -83,7 +83,7 @@ inline unsigned get_be32(const void *bb)
|
|||||||
|
|
||||||
inline void set_be32(void *bb, unsigned v)
|
inline void set_be32(void *bb, unsigned v)
|
||||||
{
|
{
|
||||||
upx_bytep b = (upx_bytep) bb;
|
unsigned char* b = (unsigned char*) bb;
|
||||||
b[3] = (unsigned char) (v >> 0);
|
b[3] = (unsigned char) (v >> 0);
|
||||||
b[2] = (unsigned char) (v >> 8);
|
b[2] = (unsigned char) (v >> 8);
|
||||||
b[1] = (unsigned char) (v >> 16);
|
b[1] = (unsigned char) (v >> 16);
|
||||||
@@ -93,10 +93,10 @@ inline void set_be32(void *bb, unsigned v)
|
|||||||
|
|
||||||
inline unsigned get_le16(const void *bb)
|
inline unsigned get_le16(const void *bb)
|
||||||
{
|
{
|
||||||
#if defined(__i386__)
|
#if defined(ACC_GET_LE16)
|
||||||
return * (const unsigned short *) bb;
|
return ACC_GET_LE16(bb);
|
||||||
#else
|
#else
|
||||||
const upx_bytep b = (const upx_bytep) bb;
|
const unsigned char* b = (const unsigned char*) bb;
|
||||||
unsigned v;
|
unsigned v;
|
||||||
v = (unsigned) b[0] << 0;
|
v = (unsigned) b[0] << 0;
|
||||||
v |= (unsigned) b[1] << 8;
|
v |= (unsigned) b[1] << 8;
|
||||||
@@ -106,10 +106,10 @@ inline unsigned get_le16(const void *bb)
|
|||||||
|
|
||||||
inline void set_le16(void *bb, unsigned v)
|
inline void set_le16(void *bb, unsigned v)
|
||||||
{
|
{
|
||||||
#if defined(__i386__)
|
#if defined(ACC_SET_LE16)
|
||||||
(* (unsigned short *) bb) = (unsigned short) (v & 0xffff);
|
ACC_SET_LE16(bb, v);
|
||||||
#else
|
#else
|
||||||
upx_bytep b = (upx_bytep) bb;
|
unsigned char* b = (unsigned char*) bb;
|
||||||
b[0] = (unsigned char) (v >> 0);
|
b[0] = (unsigned char) (v >> 0);
|
||||||
b[1] = (unsigned char) (v >> 8);
|
b[1] = (unsigned char) (v >> 8);
|
||||||
#endif
|
#endif
|
||||||
@@ -118,7 +118,7 @@ inline void set_le16(void *bb, unsigned v)
|
|||||||
|
|
||||||
inline unsigned get_le24(const void *bb)
|
inline unsigned get_le24(const void *bb)
|
||||||
{
|
{
|
||||||
const upx_bytep b = (const upx_bytep) bb;
|
const unsigned char* b = (const unsigned char*) bb;
|
||||||
unsigned v;
|
unsigned v;
|
||||||
v = (unsigned) b[0] << 0;
|
v = (unsigned) b[0] << 0;
|
||||||
v |= (unsigned) b[1] << 8;
|
v |= (unsigned) b[1] << 8;
|
||||||
@@ -128,7 +128,7 @@ inline unsigned get_le24(const void *bb)
|
|||||||
|
|
||||||
inline void set_le24(void *bb, unsigned v)
|
inline void set_le24(void *bb, unsigned v)
|
||||||
{
|
{
|
||||||
upx_bytep b = (upx_bytep) bb;
|
unsigned char* b = (unsigned char*) bb;
|
||||||
b[0] = (unsigned char) (v >> 0);
|
b[0] = (unsigned char) (v >> 0);
|
||||||
b[1] = (unsigned char) (v >> 8);
|
b[1] = (unsigned char) (v >> 8);
|
||||||
b[2] = (unsigned char) (v >> 16);
|
b[2] = (unsigned char) (v >> 16);
|
||||||
@@ -137,10 +137,10 @@ inline void set_le24(void *bb, unsigned v)
|
|||||||
|
|
||||||
inline unsigned get_le32(const void *bb)
|
inline unsigned get_le32(const void *bb)
|
||||||
{
|
{
|
||||||
#if defined(__i386__)
|
#if defined(ACC_GET_LE32)
|
||||||
return * (const unsigned *) bb;
|
return ACC_GET_LE32(bb);
|
||||||
#else
|
#else
|
||||||
const upx_bytep b = (const upx_bytep) bb;
|
const unsigned char* b = (const unsigned char*) bb;
|
||||||
unsigned v;
|
unsigned v;
|
||||||
v = (unsigned) b[0] << 0;
|
v = (unsigned) b[0] << 0;
|
||||||
v |= (unsigned) b[1] << 8;
|
v |= (unsigned) b[1] << 8;
|
||||||
@@ -152,10 +152,10 @@ inline unsigned get_le32(const void *bb)
|
|||||||
|
|
||||||
inline void set_le32(void *bb, unsigned v)
|
inline void set_le32(void *bb, unsigned v)
|
||||||
{
|
{
|
||||||
#if defined(__i386__)
|
#if defined(ACC_SET_LE32)
|
||||||
(* (unsigned *) bb) = v;
|
ACC_SET_LE32(bb, v);
|
||||||
#else
|
#else
|
||||||
upx_bytep b = (upx_bytep) bb;
|
unsigned char* b = (unsigned char*) bb;
|
||||||
b[0] = (unsigned char) (v >> 0);
|
b[0] = (unsigned char) (v >> 0);
|
||||||
b[1] = (unsigned char) (v >> 8);
|
b[1] = (unsigned char) (v >> 8);
|
||||||
b[2] = (unsigned char) (v >> 16);
|
b[2] = (unsigned char) (v >> 16);
|
||||||
@@ -214,76 +214,68 @@ inline int get_le32_signed(const void *bb)
|
|||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// classes for portable unaligned access
|
// classes for portable unaligned access
|
||||||
|
//
|
||||||
|
// Important: these classes must be PODs (Plain Old Data), i.e. no
|
||||||
|
// constructor, no destructor, no virtual functions and no default
|
||||||
|
// assignment operator, and all fields must be public(!).
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class BE16
|
struct BE16
|
||||||
{
|
{
|
||||||
unsigned char d[2];
|
unsigned char d[2];
|
||||||
|
|
||||||
public:
|
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
|
||||||
BE16& operator = (const BE16 &v) { memcpy(d, v.d, sizeof(d)); 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, v); return *this; }
|
operator unsigned () const { return get_be16(d); }
|
||||||
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 const unsigned () const { return get_be16(d); }
|
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
|
|
||||||
class BE32
|
struct BE32
|
||||||
{
|
{
|
||||||
unsigned char d[4];
|
unsigned char d[4];
|
||||||
|
|
||||||
public:
|
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
|
||||||
BE32& operator = (const BE32 &v) { memcpy(d, v.d, sizeof(d)); 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, v); return *this; }
|
operator unsigned () const { return get_be32(d); }
|
||||||
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 const unsigned () const { return get_be32(d); }
|
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
|
|
||||||
class LE16
|
struct LE16
|
||||||
{
|
{
|
||||||
unsigned char d[2];
|
unsigned char d[2];
|
||||||
|
|
||||||
public:
|
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
|
||||||
LE16& operator = (const LE16 &v) { memcpy(d, v.d, sizeof(d)); 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, v); return *this; }
|
operator unsigned () const { return get_le16(d); }
|
||||||
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 const unsigned () const { return get_le16(d); }
|
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
|
|
||||||
class LE32
|
struct LE32
|
||||||
{
|
{
|
||||||
unsigned char d[4];
|
unsigned char d[4];
|
||||||
|
|
||||||
public:
|
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
|
||||||
LE32& operator = (const LE32 &v) { memcpy(d, v.d, sizeof(d)); 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, v); return *this; }
|
operator unsigned () const { return get_le32(d); }
|
||||||
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 const unsigned () const { return get_le32(d); }
|
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
@@ -294,44 +286,44 @@ __attribute_packed;
|
|||||||
|
|
||||||
inline bool operator < (const BE16& v1, const BE16& v2)
|
inline bool operator < (const BE16& v1, const BE16& v2)
|
||||||
{
|
{
|
||||||
return (const unsigned)v1 < (const unsigned)v2;
|
return (unsigned)v1 < (unsigned)v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator < (const BE32& v1, const BE32& v2)
|
inline bool operator < (const BE32& v1, const BE32& v2)
|
||||||
{
|
{
|
||||||
return (const unsigned)v1 < (const unsigned)v2;
|
return (unsigned)v1 < (unsigned)v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator < (const LE16& v1, const LE16& v2)
|
inline bool operator < (const LE16& v1, const LE16& v2)
|
||||||
{
|
{
|
||||||
return (const unsigned)v1 < (const unsigned)v2;
|
return (unsigned)v1 < (unsigned)v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator < (const LE32& v1, const LE32& v2)
|
inline bool operator < (const LE32& v1, const LE32& v2)
|
||||||
{
|
{
|
||||||
return (const unsigned)v1 < (const unsigned)v2;
|
return (unsigned)v1 < (unsigned)v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator + (T* ptr, const BE16& v) { return ptr + (const unsigned) v; }
|
inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator - (T* ptr, const BE16& v) { return ptr - (const unsigned) v; }
|
inline T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator + (T* ptr, const BE32& v) { return ptr + (const unsigned) v; }
|
inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; }
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator - (T* ptr, const BE32& v) { return ptr - (const unsigned) v; }
|
inline T* operator - (T* ptr, const BE32& v) { return ptr - (unsigned) v; }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator + (T* ptr, const LE16& v) { return ptr + (const unsigned) v; }
|
inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; }
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator - (T* ptr, const LE16& v) { return ptr - (const unsigned) v; }
|
inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator + (T* ptr, const LE32& v) { return ptr + (const unsigned) v; }
|
inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; }
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T* operator - (T* ptr, const LE32& v) { return ptr - (const unsigned) v; }
|
inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -339,28 +331,39 @@ inline T* operator - (T* ptr, const LE32& v) { return ptr - (const unsigned) v;
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
// for use with qsort()
|
// for use with qsort()
|
||||||
int be16_compare(const void *e1, const void *e2);
|
int __acc_cdecl_qsort be16_compare(const void *e1, const void *e2);
|
||||||
int be24_compare(const void *e1, const void *e2);
|
int __acc_cdecl_qsort be24_compare(const void *e1, const void *e2);
|
||||||
int be32_compare(const void *e1, const void *e2);
|
int __acc_cdecl_qsort be32_compare(const void *e1, const void *e2);
|
||||||
int le16_compare(const void *e1, const void *e2);
|
int __acc_cdecl_qsort le16_compare(const void *e1, const void *e2);
|
||||||
int le24_compare(const void *e1, const void *e2);
|
int __acc_cdecl_qsort le24_compare(const void *e1, const void *e2);
|
||||||
int le32_compare(const void *e1, const void *e2);
|
int __acc_cdecl_qsort le32_compare(const void *e1, const void *e2);
|
||||||
int be16_compare_signed(const void *e1, const void *e2);
|
int __acc_cdecl_qsort be16_compare_signed(const void *e1, const void *e2);
|
||||||
int be24_compare_signed(const void *e1, const void *e2);
|
int __acc_cdecl_qsort be24_compare_signed(const void *e1, const void *e2);
|
||||||
int be32_compare_signed(const void *e1, const void *e2);
|
int __acc_cdecl_qsort be32_compare_signed(const void *e1, const void *e2);
|
||||||
int le16_compare_signed(const void *e1, const void *e2);
|
int __acc_cdecl_qsort le16_compare_signed(const void *e1, const void *e2);
|
||||||
int le24_compare_signed(const void *e1, const void *e2);
|
int __acc_cdecl_qsort le24_compare_signed(const void *e1, const void *e2);
|
||||||
int le32_compare_signed(const void *e1, const void *e2);
|
int __acc_cdecl_qsort le32_compare_signed(const void *e1, const void *e2);
|
||||||
|
|
||||||
|
|
||||||
// just for testing...
|
// just for testing...
|
||||||
#if 0 && defined(__i386__) && defined(__GNUC_VERSION_HEX__)
|
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_GNUC >= 0x030200)
|
||||||
# if (__GNUC_VERSION_HEX__ >= 0x030100)
|
typedef unsigned short LE16_unaligned __attribute__((__aligned__(1)));
|
||||||
typedef unsigned short LE16_unaligned __attribute__((__packed__,__aligned__(1)));
|
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||||
typedef unsigned int LE32_unaligned __attribute__((__packed__,__aligned__(1)));
|
|
||||||
# define LE16 LE16_unaligned
|
# define LE16 LE16_unaligned
|
||||||
# define LE32 LE32_unaligned
|
# 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
|
||||||
|
#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
|
||||||
|
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
/* bptr.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
|
||||||
|
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __UPX_BPTR_H
|
||||||
|
#define __UPX_BPTR_H
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// BoundedPtr
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class BoundedPtr
|
||||||
|
{
|
||||||
|
// typedef BoundedPtr<T> Self;
|
||||||
|
public:
|
||||||
|
typedef T* StoredType;
|
||||||
|
typedef T* PointerType;
|
||||||
|
typedef T& ReferenceType;
|
||||||
|
|
||||||
|
~BoundedPtr() { }
|
||||||
|
|
||||||
|
explicit BoundedPtr(void* base, unsigned size, T* ptr=0)
|
||||||
|
: ptr_(ptr), base_(base), size_(size) { check(); }
|
||||||
|
BoundedPtr& operator= (const BoundedPtr& other) {
|
||||||
|
assert(base_ == other.base_); assert(size_ == other.size_);
|
||||||
|
ptr_ = other.ptr_; check(); return *this;
|
||||||
|
}
|
||||||
|
BoundedPtr& operator= (T* other) {
|
||||||
|
ptr_ = other; check(); return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T* () { check(); return ptr_; }
|
||||||
|
operator const T* () const { check(); return ptr_; }
|
||||||
|
|
||||||
|
BoundedPtr& operator += (size_t n) {
|
||||||
|
checkStrict(); ptr_ += n; checkStrict(); return *this;
|
||||||
|
}
|
||||||
|
BoundedPtr& operator -= (size_t n) {
|
||||||
|
checkStrict(); ptr_ -= n; checkStrict(); return *this;
|
||||||
|
}
|
||||||
|
BoundedPtr& operator ++ (void) {
|
||||||
|
checkStrict(); ptr_ += 1; checkStrict(); return *this;
|
||||||
|
}
|
||||||
|
// T* operator ++ (int) {
|
||||||
|
// T* p = ptr_; checkStrict(); ptr_ += 1; checkStrict(); return p;
|
||||||
|
// }
|
||||||
|
// BoundedPtr& operator -- (void) {
|
||||||
|
// checkStrict(); ptr_ -= 1; checkStrict(); return *this;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
void checkNULL() const {
|
||||||
|
if (!ptr_)
|
||||||
|
throwCantUnpack("unexpected NULL pointer; take care!");
|
||||||
|
}
|
||||||
|
void checkRange(size_t extra=0) const {
|
||||||
|
size_t off = (const char *) ptr_ - (const char *) base_;
|
||||||
|
if (off > size_ || off + extra > size_)
|
||||||
|
throwCantUnpack("pointer out of range; take care!");
|
||||||
|
}
|
||||||
|
void checkStrict(size_t extra=0) const {
|
||||||
|
checkNULL();
|
||||||
|
checkRange(extra);
|
||||||
|
}
|
||||||
|
void check(size_t extra=0) const {
|
||||||
|
if (ptr_) checkRange(extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
T* ptr_;
|
||||||
|
void* base_;
|
||||||
|
size_t size_;
|
||||||
|
|
||||||
|
// disable copy
|
||||||
|
BoundedPtr(const BoundedPtr&); // {}
|
||||||
|
// BoundedPtr& operator= (const BoundedPtr&); // { return *this; }
|
||||||
|
|
||||||
|
// disable dynamic allocation
|
||||||
|
DISABLE_NEW_DELETE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* already included */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
vi:ts=4:et
|
||||||
|
*/
|
||||||
|
|
||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+4
-4
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -81,7 +81,7 @@ static int do_init(FILE *f)
|
|||||||
if (opt->console == CON_NONE || opt->to_stdout)
|
if (opt->console == CON_NONE || opt->to_stdout)
|
||||||
return con_mode;
|
return con_mode;
|
||||||
try_init(&console_file,f);
|
try_init(&console_file,f);
|
||||||
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO) || !isatty(STDERR_FILENO))
|
if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO))
|
||||||
return con_mode;
|
return con_mode;
|
||||||
|
|
||||||
#if defined(USE_ANSI)
|
#if defined(USE_ANSI)
|
||||||
@@ -142,7 +142,7 @@ console_t console_init =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void con_fprintf(FILE *f, const char *format, ...)
|
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[80*25];
|
char buf[80*25];
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+4
-4
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -88,7 +88,7 @@ static screen_t *do_construct(screen_t *s, int fd)
|
|||||||
|
|
||||||
static screen_t *screen = NULL;
|
static screen_t *screen = NULL;
|
||||||
|
|
||||||
static void do_destroy(void)
|
static void __acc_cdecl_atexit do_destroy(void)
|
||||||
{
|
{
|
||||||
if (screen)
|
if (screen)
|
||||||
{
|
{
|
||||||
@@ -130,7 +130,7 @@ static int init(FILE *f, int o, int now)
|
|||||||
if (!screen)
|
if (!screen)
|
||||||
screen = do_construct(screen_djgpp2_construct(),fd);
|
screen = do_construct(screen_djgpp2_construct(),fd);
|
||||||
#endif
|
#endif
|
||||||
#if defined(__MFX_WIN32)
|
#if defined(USE_SCREEN_WIN32)
|
||||||
if (!screen)
|
if (!screen)
|
||||||
screen = do_construct(screen_win32_construct(),fd);
|
screen = do_construct(screen_win32_construct(),fd);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+174
-236
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -29,51 +29,99 @@
|
|||||||
#ifndef __UPX_CONF_H
|
#ifndef __UPX_CONF_H
|
||||||
#define __UPX_CONF_H
|
#define __UPX_CONF_H
|
||||||
|
|
||||||
#if 0 && defined(__EMX__)
|
|
||||||
# include <sys/emx.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(UPX_CONFIG_H)
|
|
||||||
# include UPX_CONFIG_H
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_STDINT_H)
|
|
||||||
# if !defined(__STDC_LIMIT_MACROS)
|
|
||||||
# define __STDC_LIMIT_MACROS 1
|
|
||||||
# endif
|
|
||||||
# if !defined(__STDC_CONSTANT_MACROS)
|
|
||||||
# define __STDC_CONSTANT_MACROS 1
|
|
||||||
# endif
|
|
||||||
# include <stdint.h>
|
|
||||||
#endif
|
|
||||||
#include <limits.h>
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "tailor.h"
|
|
||||||
|
|
||||||
// upx_int64l is int_least64_t in <stdint.h> terminology
|
|
||||||
#if !defined(upx_int64l)
|
/*************************************************************************
|
||||||
# if defined(HAVE_STDINT_H)
|
// ACC
|
||||||
# define upx_int64l int_least64_t
|
**************************************************************************/
|
||||||
# define upx_uint64l uint_least64_t
|
|
||||||
# elif (ULONG_MAX > 0xffffffffL)
|
#include "miniacc.h"
|
||||||
# define upx_int64l long int
|
#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__)
|
||||||
# define upx_uint64l unsigned long int
|
# undef HAVE_UTIME_H /* this pulls in <windows.h> */
|
||||||
# elif defined(__GNUC__) || defined(__DMC__)
|
#endif
|
||||||
# define upx_int64l long long int
|
|
||||||
# define upx_uint64l unsigned long long int
|
|
||||||
# elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__WATCOMC__)
|
#if (ACC_CC_BORLANDC)
|
||||||
# define upx_int64l __int64
|
# if (__BORLANDC__ < 0x0500)
|
||||||
# define upx_uint64l unsigned __int64
|
# error "need Borland C++ 5.0 or newer"
|
||||||
|
# endif
|
||||||
|
# pragma warn -aus // 8004: 'x' is assigned a value that is never used
|
||||||
|
# pragma warn -inl // 8026+8027: Function not expanded inline
|
||||||
|
// Borland compilers typically produce a number of bogus warnings, and
|
||||||
|
// the actual diagnostics vary from version to version...
|
||||||
|
# if (__BORLANDC__ < 0x0530)
|
||||||
|
# pragma warn -csu // 8012: Comparing signed and unsigned values
|
||||||
|
# endif
|
||||||
|
# if (__BORLANDC__ >= 0x0530 && __BORLANDC__ < 0x0560)
|
||||||
|
# pragma warn -osh // 8055: Possible overflow in shift operation
|
||||||
|
# endif
|
||||||
|
# if (__BORLANDC__ >= 0x0560)
|
||||||
|
# pragma warn -use // 8080: 'x' is declared but never used
|
||||||
|
# endif
|
||||||
|
#elif (ACC_CC_DMC)
|
||||||
|
# if (__DMC__ < 0x829)
|
||||||
|
# error "need Digital Mars C++ 8.29 or newer"
|
||||||
|
# endif
|
||||||
|
#elif (ACC_CC_INTELC)
|
||||||
|
# if (__INTEL_COMPILER < 450)
|
||||||
|
# error "need Intel C++ 4.5 or newer"
|
||||||
|
# endif
|
||||||
|
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
|
# elif defined(__linux__)
|
||||||
|
# pragma warning(error: 424) // #424: extra ";" ignored
|
||||||
|
# pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier
|
||||||
|
# pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits
|
||||||
|
# pragma warning(disable: 981) // #981: operands are evaluated in unspecified order
|
||||||
|
# pragma warning(disable: 1418) // #1418: external definition with no prior declaration
|
||||||
# else
|
# else
|
||||||
# error "need a 64-bit integer type"
|
# error "untested platform"
|
||||||
|
# endif
|
||||||
|
#elif (ACC_CC_MSC)
|
||||||
|
# if (_MSC_VER < 1100)
|
||||||
|
# error "need Visual C++ 5.0 or newer"
|
||||||
|
# endif
|
||||||
|
# pragma warning(error: 4096) // W2: '__cdecl' must be used with '...'
|
||||||
|
# pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B'
|
||||||
|
# pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated
|
||||||
|
# pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated
|
||||||
|
# pragma warning(disable: 4514) // W4: 'function': unreferenced inline function has been removed
|
||||||
|
# pragma warning(disable: 4710) // W4: 'function': function not inlined
|
||||||
|
# if (_MSC_VER >= 1300)
|
||||||
|
# pragma warning(disable: 4625) // W4: 'class' : copy constructor could not be generated because a base class copy constructor is inaccessible
|
||||||
|
# pragma warning(disable: 4626) // W4: 'class' : assignment operator could not be generated because a base class assignment operator is inaccessible
|
||||||
|
# pragma warning(disable: 4711) // W4: 'function' selected for automatic inline expansion
|
||||||
|
# pragma warning(disable: 4820) // W4: 'struct' : 'x' bytes padding added after member 'member'
|
||||||
|
# endif
|
||||||
|
# if (_MSC_VER >= 1400)
|
||||||
|
# pragma warning(disable: 4996) // W1: 'function': was declared deprecated
|
||||||
|
# endif
|
||||||
|
#elif (ACC_CC_WATCOMC)
|
||||||
|
# if (__WATCOMC__ < 1100)
|
||||||
|
# error "need Watcom C++ 11.0c or newer"
|
||||||
|
# endif
|
||||||
|
# if defined(__cplusplus)
|
||||||
|
# pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__i386__)
|
|
||||||
# if defined(__386__) || defined(_M_IX86)
|
#define ACC_WANT_ACC_INCD_H 1
|
||||||
# define __i386__ 1
|
#define ACC_WANT_ACC_INCE_H 1
|
||||||
|
#define ACC_WANT_ACC_LIB_H 1
|
||||||
|
#define ACC_WANT_ACC_CXX_H 1
|
||||||
|
#include "miniacc.h"
|
||||||
|
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
|
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
|
||||||
|
# error "something pulled in <windows.h>"
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
#if defined(__linux__) && !defined(__unix__)
|
#if defined(__linux__) && !defined(__unix__)
|
||||||
# define __unix__ 1
|
# define __unix__ 1
|
||||||
#endif
|
#endif
|
||||||
@@ -84,16 +132,26 @@
|
|||||||
#undef linux
|
#undef linux
|
||||||
#undef small
|
#undef small
|
||||||
#undef tos
|
#undef tos
|
||||||
#undef unix
|
#if defined(ACC_CC_DMC)
|
||||||
|
# undef tell
|
||||||
|
#endif
|
||||||
|
#if !defined(ACC_CC_PGI)
|
||||||
|
# undef unix
|
||||||
|
#endif
|
||||||
|
#if defined(__DJGPP__)
|
||||||
|
# undef sopen
|
||||||
|
# undef __unix__
|
||||||
|
# undef __unix
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(WITH_UCL)
|
#if !defined(WITH_UCL)
|
||||||
# error "you lose"
|
# error "please set UCLDIR in the Makefile"
|
||||||
#endif
|
#endif
|
||||||
#if defined(WITH_UCL)
|
#if defined(WITH_UCL)
|
||||||
# include <ucl/uclconf.h>
|
# include <ucl/uclconf.h>
|
||||||
# include <ucl/ucl.h>
|
# include <ucl/ucl.h>
|
||||||
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010100L)
|
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010200L)
|
||||||
# error "please upgrade your UCL installation"
|
# error "please upgrade your UCL installation"
|
||||||
# endif
|
# endif
|
||||||
# if !defined(UPX_UINT_MAX)
|
# if !defined(UPX_UINT_MAX)
|
||||||
@@ -109,7 +167,7 @@
|
|||||||
# define UPX_E_OK UCL_E_OK
|
# define UPX_E_OK UCL_E_OK
|
||||||
# define UPX_E_ERROR UCL_E_ERROR
|
# define UPX_E_ERROR UCL_E_ERROR
|
||||||
# define UPX_E_OUT_OF_MEMORY UCL_E_OUT_OF_MEMORY
|
# define UPX_E_OUT_OF_MEMORY UCL_E_OUT_OF_MEMORY
|
||||||
# define __UPX_ENTRY __UCL_ENTRY
|
# define __UPX_CDECL __UCL_CDECL
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(WITH_NRV)
|
#if defined(WITH_NRV)
|
||||||
@@ -121,7 +179,7 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
|
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
|
||||||
# error "you lose"
|
# error "UINT_MAX"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -129,65 +187,9 @@
|
|||||||
// system includes
|
// system includes
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if !defined(NO_SYS_TYPES_H)
|
|
||||||
# include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NDEBUG
|
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#if !defined(NO_FCNTL_H)
|
|
||||||
# include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
#if !defined(NO_SYS_STAT_H)
|
|
||||||
# include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_IO_H) && !defined(NO_IO_H)
|
|
||||||
# include <io.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_DOS_H) && !defined(NO_DOS_H)
|
|
||||||
# include <dos.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_MALLOC_H) && !defined(NO_MALLOC_H)
|
|
||||||
# include <malloc.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_ALLOCA_H) && !defined(NO_ALLOCA_H)
|
|
||||||
# include <alloca.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_SIGNAL_H)
|
|
||||||
# include <signal.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_UNISTD_H)
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#if defined(TIME_WITH_SYS_TIME)
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <time.h>
|
|
||||||
#else
|
|
||||||
# include <time.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_UTIME_H)
|
|
||||||
# include <utime.h>
|
|
||||||
#elif defined(HAVE_SYS_UTIME_H)
|
|
||||||
# include <sys/utime.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_SHARE_H)
|
|
||||||
# include <share.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// malloc debuggers
|
// malloc debuggers
|
||||||
#if defined(WITH_VALGRIND)
|
#if defined(WITH_VALGRIND)
|
||||||
# include <valgrind.h>
|
# include <valgrind/memcheck.h>
|
||||||
#elif defined(WITH_DMALLOC)
|
#elif defined(WITH_DMALLOC)
|
||||||
# define DMALLOC_FUNC_CHECK
|
# define DMALLOC_FUNC_CHECK
|
||||||
# include <dmalloc.h>
|
# include <dmalloc.h>
|
||||||
@@ -207,73 +209,24 @@
|
|||||||
#endif
|
#endif
|
||||||
#if !defined(VALGRIND_MAKE_READABLE)
|
#if !defined(VALGRIND_MAKE_READABLE)
|
||||||
# if 0
|
# if 0
|
||||||
# define VALGRIND_MAKE_READABLE(addr,len) memset(addr,0,len), 0
|
# define VALGRIND_MAKE_READABLE(addr,len) (memset(addr,0,len), 0)
|
||||||
# else
|
# else
|
||||||
# define VALGRIND_MAKE_READABLE(addr,len) 0
|
# define VALGRIND_MAKE_READABLE(addr,len) 0
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if !defined(VALGRIND_DISCARD)
|
#if !defined(VALGRIND_DISCARD)
|
||||||
# define VALGRIND_DISCARD(handle) ((void) &handle)
|
# define VALGRIND_DISCARD(handle) ((void)(&handle))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// portab
|
// portab
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__GNUC_VERSION_HEX__)
|
|
||||||
# if !defined(__GNUC_MINOR__)
|
|
||||||
# error
|
|
||||||
# endif
|
|
||||||
# if !defined(__GNUC_PATCHLEVEL__)
|
|
||||||
# define __GNUC_PATCHLEVEL__ 0
|
|
||||||
# endif
|
|
||||||
# define __GNUC_VERSION_HEX__ \
|
|
||||||
(__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(PATH_MAX)
|
|
||||||
# define PATH_MAX 512
|
|
||||||
#elif (PATH_MAX < 512)
|
|
||||||
# undef PATH_MAX
|
|
||||||
# define PATH_MAX 512
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef RETSIGTYPE
|
|
||||||
# define RETSIGTYPE void
|
|
||||||
#endif
|
|
||||||
#ifndef SIGTYPEENTRY
|
|
||||||
# define SIGTYPEENTRY
|
|
||||||
#endif
|
|
||||||
typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
|
||||||
|
|
||||||
|
|
||||||
#undef MODE_T
|
|
||||||
#if defined(HAVE_MODE_T)
|
|
||||||
# define MODE_T mode_t
|
|
||||||
#else
|
|
||||||
# define MODE_T int
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(HAVE_STRCASECMP)
|
|
||||||
# if defined(HAVE_STRICMP)
|
|
||||||
# define strcasecmp stricmp
|
|
||||||
# else
|
|
||||||
# define strcasecmp strcmp
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#if !defined(HAVE_STRNCASECMP)
|
|
||||||
# if defined(HAVE_STRNICMP)
|
|
||||||
# define strncasecmp strnicmp
|
|
||||||
# else
|
|
||||||
# define strncasecmp strncmp
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef STDIN_FILENO
|
#ifndef STDIN_FILENO
|
||||||
# define STDIN_FILENO (fileno(stdin))
|
# define STDIN_FILENO (fileno(stdin))
|
||||||
#endif
|
#endif
|
||||||
@@ -285,6 +238,14 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(HAVE_STRCASECMP) && defined(HAVE_STRICMP)
|
||||||
|
# define strcasecmp stricmp
|
||||||
|
#endif
|
||||||
|
#if !defined(HAVE_STRNCASECMP) && defined(HAVE_STRNICMP)
|
||||||
|
# define strncasecmp strnicmp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(S_IWUSR) && defined(_S_IWUSR)
|
#if !defined(S_IWUSR) && defined(_S_IWUSR)
|
||||||
# define S_IWUSR _S_IWUSR
|
# define S_IWUSR _S_IWUSR
|
||||||
#elif !defined(S_IWUSR) && defined(_S_IWRITE)
|
#elif !defined(S_IWUSR) && defined(_S_IWRITE)
|
||||||
@@ -308,14 +269,14 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
|||||||
# if defined(S_IFMT) && defined(S_IFREG)
|
# if defined(S_IFMT) && defined(S_IFREG)
|
||||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||||
# else
|
# else
|
||||||
# error S_ISREG
|
# error "S_ISREG"
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if !defined(S_ISDIR)
|
#if !defined(S_ISDIR)
|
||||||
# if defined(S_IFMT) && defined(S_IFDIR)
|
# if defined(S_IFMT) && defined(S_IFDIR)
|
||||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||||
# else
|
# else
|
||||||
# error S_ISDIR
|
# error "S_ISDIR"
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if !defined(S_ISCHR)
|
#if !defined(S_ISCHR)
|
||||||
@@ -326,32 +287,15 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
|||||||
|
|
||||||
|
|
||||||
// avoid warnings about shadowing global functions
|
// avoid warnings about shadowing global functions
|
||||||
|
#undef index
|
||||||
#define basename upx_basename
|
#define basename upx_basename
|
||||||
#define index upx_index
|
#define index upx_index
|
||||||
#define outp upx_outp
|
#define outp upx_outp
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
# define COMPILE_TIME_ASSERT(expr) \
|
|
||||||
{ typedef char __upx_compile_time_assert_fail[1 - 2 * !(expr)]; \
|
|
||||||
switch (sizeof(__upx_compile_time_assert_fail)) { \
|
|
||||||
case 1: case !(expr): break; \
|
|
||||||
} }
|
|
||||||
#elif defined(__SC__)
|
|
||||||
# define COMPILE_TIME_ASSERT(expr) \
|
|
||||||
{ switch (1) { case 1: case !(expr): break; } }
|
|
||||||
#elif 0
|
|
||||||
# define COMPILE_TIME_ASSERT(expr) \
|
|
||||||
{ typedef int __upx_compile_time_assert_fail[1 - 2 * !(expr)]; typedef int a[sizeof(__upx_compile_time_assert_fail]; }
|
|
||||||
#else
|
|
||||||
# define COMPILE_TIME_ASSERT(expr) \
|
|
||||||
{ typedef int __upx_compile_time_assert_fail[1 - 2 * !(expr)]; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#undef __attribute_packed
|
#undef __attribute_packed
|
||||||
#if defined(__GNUC__)
|
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||||
# if 1 && defined(__i386__)
|
# if (1 && (ACC_ARCH_IA32))
|
||||||
# define __attribute_packed
|
# define __attribute_packed
|
||||||
# else
|
# else
|
||||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||||
@@ -360,61 +304,49 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
|||||||
# define __attribute_packed
|
# define __attribute_packed
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#undef NOTHROW
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
# define NOTHROW throw()
|
|
||||||
#else
|
|
||||||
# define NOTHROW
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
// file io
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#if defined(HAVE_SETMODE)
|
|
||||||
# if !defined(O_BINARY)
|
|
||||||
# error "setmode without O_BINARY"
|
|
||||||
# endif
|
|
||||||
# define USE_SETMODE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(O_BINARY)
|
#if !defined(O_BINARY)
|
||||||
# define O_BINARY 0
|
# define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__DMC__)
|
#ifndef OPTIONS_VAR
|
||||||
# undef tell
|
# define OPTIONS_VAR "UPX"
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__DJGPP__)
|
|
||||||
# undef sopen
|
|
||||||
# undef USE_SETMODE
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// memory util
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#undef UNUSED
|
#define UNUSED(var) ACC_UNUSED(var)
|
||||||
|
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
# define UNUSED(var) ((void) &(var))
|
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||||
#elif 1 && defined(__GNUC__)
|
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
|
||||||
# define UNUSED(var) { typedef int __upx_unused[sizeof(var) ? 1 : -1]; }
|
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z[7]; } __attribute_packed; \
|
||||||
#elif 0
|
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
|
||||||
# define UNUSED(var) do { } while (!sizeof(var))
|
}
|
||||||
#elif defined(__BORLANDC__)
|
|
||||||
# define UNUSED(parm) ((void)(parm))
|
|
||||||
#else
|
#else
|
||||||
# define UNUSED(parm) (parm = parm)
|
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||||
|
struct acc_tmp_t { b x; a y; b z[7]; } __attribute_packed; \
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HIGH(array) ((unsigned) (sizeof(array)/sizeof((array)[0])))
|
#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))
|
||||||
|
#else
|
||||||
|
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||||
|
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TABLESIZE(table) ((sizeof(table)/sizeof((table)[0])))
|
||||||
|
|
||||||
#define ALIGN_DOWN(a,b) (((a) / (b)) * (b))
|
#define ALIGN_DOWN(a,b) (((a) / (b)) * (b))
|
||||||
#define ALIGN_UP(a,b) ALIGN_DOWN((a) + ((b) - 1), b)
|
#define ALIGN_UP(a,b) ALIGN_DOWN((a) + ((b) - 1), b)
|
||||||
|
#define ALIGN_GAP(a,b) (ALIGN_UP(a,b) - (a))
|
||||||
|
|
||||||
#define UPX_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
#define UPX_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
||||||
#define UPX_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
#define UPX_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
||||||
@@ -455,12 +387,10 @@ inline void operator delete[](void *p)
|
|||||||
|
|
||||||
// An Array allocates memory on the heap, but automatically
|
// An Array allocates memory on the heap, but automatically
|
||||||
// gets destructed when leaving scope or on exceptions.
|
// gets destructed when leaving scope or on exceptions.
|
||||||
// "var" is declared as a read-only reference to a pointer
|
|
||||||
// and behaves exactly like an array "var[]".
|
|
||||||
#define Array(type, var, size) \
|
#define Array(type, var, size) \
|
||||||
assert((int)(size) > 0); \
|
assert((int)(size) > 0); \
|
||||||
MemBuffer var ## _membuf((size)*(sizeof(type))); \
|
MemBuffer var ## _membuf((size)*(sizeof(type))); \
|
||||||
type * const & var = ((type *) var ## _membuf.getVoidPtr())
|
type * const var = ((type *) var ## _membuf.getVoidPtr())
|
||||||
|
|
||||||
#define ByteArray(var, size) Array(unsigned char, var, size)
|
#define ByteArray(var, size) Array(unsigned char, var, size)
|
||||||
|
|
||||||
@@ -504,7 +434,7 @@ inline void operator delete[](void *p)
|
|||||||
#define UPX_F_DOS_SYS 2
|
#define UPX_F_DOS_SYS 2
|
||||||
#define UPX_F_DOS_EXE 3
|
#define UPX_F_DOS_EXE 3
|
||||||
#define UPX_F_DJGPP2_COFF 4
|
#define UPX_F_DJGPP2_COFF 4
|
||||||
#define UPX_F_WC_LE 5
|
#define UPX_F_WATCOM_LE 5
|
||||||
#define UPX_F_VXD_LE 6
|
#define UPX_F_VXD_LE 6
|
||||||
#define UPX_F_DOS_EXEH 7 /* OBSOLETE */
|
#define UPX_F_DOS_EXEH 7 /* OBSOLETE */
|
||||||
#define UPX_F_TMT_ADAM 8
|
#define UPX_F_TMT_ADAM 8
|
||||||
@@ -518,6 +448,7 @@ inline void operator delete[](void *p)
|
|||||||
#define UPX_F_BVMLINUZ_i386 16
|
#define UPX_F_BVMLINUZ_i386 16
|
||||||
#define UPX_F_ELKS_8086 17
|
#define UPX_F_ELKS_8086 17
|
||||||
#define UPX_F_PS1_EXE 18
|
#define UPX_F_PS1_EXE 18
|
||||||
|
#define UPX_F_VMLINUX_i386 19
|
||||||
#define UPX_F_ATARI_TOS 129
|
#define UPX_F_ATARI_TOS 129
|
||||||
#define UPX_F_SOLARIS_SPARC 130
|
#define UPX_F_SOLARIS_SPARC 130
|
||||||
|
|
||||||
@@ -547,7 +478,7 @@ extern const char *progname;
|
|||||||
void init_options(struct options_t *o);
|
void init_options(struct options_t *o);
|
||||||
bool set_ec(int ec);
|
bool set_ec(int ec);
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
void e_exit(int ec) __attribute__((noreturn));
|
void e_exit(int ec) __attribute__((__noreturn__));
|
||||||
#else
|
#else
|
||||||
void e_exit(int ec);
|
void e_exit(int ec);
|
||||||
#endif
|
#endif
|
||||||
@@ -559,26 +490,26 @@ void printClearLine(FILE *f = NULL);
|
|||||||
void printErr(const char *iname, const Throwable *e);
|
void printErr(const char *iname, const Throwable *e);
|
||||||
void printUnhandledException(const char *iname, const std::exception *e);
|
void printUnhandledException(const char *iname, const std::exception *e);
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
void printErr(const char *iname, const char *format, ...)
|
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||||
__attribute__((format(printf,2,3)));
|
__attribute__((__format__(printf,2,3)));
|
||||||
void printWarn(const char *iname, const char *format, ...)
|
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||||
__attribute__((format(printf,2,3)));
|
__attribute__((__format__(printf,2,3)));
|
||||||
#else
|
#else
|
||||||
void printErr(const char *iname, const char *format, ...);
|
void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
|
||||||
void printWarn(const char *iname, const char *format, ...);
|
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
void infoWarning(const char *format, ...)
|
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||||
__attribute__((format(printf,1,2)));
|
__attribute__((__format__(printf,1,2)));
|
||||||
void infoHeader(const char *format, ...)
|
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||||
__attribute__((format(printf,1,2)));
|
__attribute__((__format__(printf,1,2)));
|
||||||
void info(const char *format, ...)
|
void __acc_cdecl_va info(const char *format, ...)
|
||||||
__attribute__((format(printf,1,2)));
|
__attribute__((__format__(printf,1,2)));
|
||||||
#else
|
#else
|
||||||
void infoWarning(const char *format, ...);
|
void __acc_cdecl_va infoWarning(const char *format, ...);
|
||||||
void infoHeader(const char *format, ...);
|
void __acc_cdecl_va infoHeader(const char *format, ...);
|
||||||
void info(const char *format, ...);
|
void __acc_cdecl_va info(const char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
void infoHeader();
|
void infoHeader();
|
||||||
void infoWriting(const char *what, long size);
|
void infoWriting(const char *what, long size);
|
||||||
@@ -618,6 +549,13 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
|
|||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
|
||||||
|
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
|
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
|
||||||
|
# error "something pulled in <windows.h>"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,229 +0,0 @@
|
|||||||
/* pseudo <config.h> for Linux */
|
|
||||||
|
|
||||||
#ifndef __UPX_CONFIG_H
|
|
||||||
#define __UPX_CONFIG_H
|
|
||||||
|
|
||||||
/* $TOP$ */
|
|
||||||
|
|
||||||
/* Define to empty if the keyword does not work. */
|
|
||||||
/* #undef const */
|
|
||||||
|
|
||||||
/* Define if your C compiler doesn't accept -c and -o together. */
|
|
||||||
/* #undef NO_MINUS_C_MINUS_O */
|
|
||||||
|
|
||||||
/* Define as the return type of signal handlers (int or void). */
|
|
||||||
#define RETSIGTYPE void
|
|
||||||
|
|
||||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
|
||||||
/* #undef size_t */
|
|
||||||
|
|
||||||
/* Define if you have the ANSI C header files. */
|
|
||||||
#define STDC_HEADERS 1
|
|
||||||
|
|
||||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
|
||||||
#define TIME_WITH_SYS_TIME 1
|
|
||||||
|
|
||||||
/* Define if your memcmp is broken. */
|
|
||||||
/* #undef NO_MEMCMP */
|
|
||||||
|
|
||||||
/* Define to `long' if <stddef.h> doesn't define. */
|
|
||||||
/* #undef ptrdiff_t */
|
|
||||||
|
|
||||||
/* Define when using the dmalloc package. */
|
|
||||||
/* #undef WITH_DMALLOC */
|
|
||||||
|
|
||||||
/* Define if you have the access function. */
|
|
||||||
#define HAVE_ACCESS 1
|
|
||||||
|
|
||||||
/* Define if you have the atoi function. */
|
|
||||||
#define HAVE_ATOI 1
|
|
||||||
|
|
||||||
/* Define if you have the chmod function. */
|
|
||||||
#define HAVE_CHMOD 1
|
|
||||||
|
|
||||||
/* Define if you have the chown function. */
|
|
||||||
#define HAVE_CHOWN 1
|
|
||||||
|
|
||||||
/* Define if you have the ctime function. */
|
|
||||||
#define HAVE_CTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the difftime function. */
|
|
||||||
#define HAVE_DIFFTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the fchmod function. */
|
|
||||||
#define HAVE_FCHMOD 1
|
|
||||||
|
|
||||||
/* Define if you have the fileno function. */
|
|
||||||
#define HAVE_FILENO 1
|
|
||||||
|
|
||||||
/* Define if you have the fstat function. */
|
|
||||||
#define HAVE_FSTAT 1
|
|
||||||
|
|
||||||
/* Define if you have the XXX function. */
|
|
||||||
#define HAVE_GETPID 1
|
|
||||||
|
|
||||||
/* Define if you have the XXX function. */
|
|
||||||
#define HAVE_GETTIMEOFDAY 1
|
|
||||||
|
|
||||||
/* Define if you have the getumask function. */
|
|
||||||
/* #undef HAVE_GETUMASK */
|
|
||||||
|
|
||||||
/* Define if you have the gmtime function. */
|
|
||||||
#define HAVE_GMTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the index function. */
|
|
||||||
#define HAVE_INDEX 1
|
|
||||||
|
|
||||||
/* Define if you have the isatty function. */
|
|
||||||
#define HAVE_ISATTY 1
|
|
||||||
|
|
||||||
/* Define if you have the lstat function. */
|
|
||||||
#define HAVE_LSTAT 1
|
|
||||||
|
|
||||||
/* Define if you have the localtime function. */
|
|
||||||
#define HAVE_LOCALTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the memcmp function. */
|
|
||||||
#define HAVE_MEMCMP 1
|
|
||||||
|
|
||||||
/* Define if you have the memcpy function. */
|
|
||||||
#define HAVE_MEMCPY 1
|
|
||||||
|
|
||||||
/* Define if you have the memmove function. */
|
|
||||||
#define HAVE_MEMMOVE 1
|
|
||||||
|
|
||||||
/* Define if you have the memset function. */
|
|
||||||
#define HAVE_MEMSET 1
|
|
||||||
|
|
||||||
/* Define if you have the mktime function. */
|
|
||||||
#define HAVE_MKTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the setmode function. */
|
|
||||||
/* #undef HAVE_SETMODE */
|
|
||||||
|
|
||||||
/* Define if you have the stat function. */
|
|
||||||
#define HAVE_STAT 1
|
|
||||||
|
|
||||||
/* Define if you have the strcasecmp function. */
|
|
||||||
#define HAVE_STRCASECMP 1
|
|
||||||
|
|
||||||
/* Define if you have the strchr function. */
|
|
||||||
#define HAVE_STRCHR 1
|
|
||||||
|
|
||||||
/* Define if you have the strdup function. */
|
|
||||||
#define HAVE_STRDUP 1
|
|
||||||
|
|
||||||
/* Define if you have the strftime function. */
|
|
||||||
#define HAVE_STRFTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the stricmp function. */
|
|
||||||
/* #undef HAVE_STRICMP */
|
|
||||||
|
|
||||||
/* Define if you have the strncasecmp function. */
|
|
||||||
#define HAVE_STRNCASECMP 1
|
|
||||||
|
|
||||||
/* Define if you have the strnicmp function. */
|
|
||||||
/* #undef HAVE_STRNICMP */
|
|
||||||
|
|
||||||
/* Define if you have the strstr function. */
|
|
||||||
#define HAVE_STRSTR 1
|
|
||||||
|
|
||||||
/* Define if you have the tzset function. */
|
|
||||||
#define HAVE_TZSET 1
|
|
||||||
|
|
||||||
/* Define if you have the umask function. */
|
|
||||||
#define HAVE_UMASK 1
|
|
||||||
|
|
||||||
/* Define if you have the utime function. */
|
|
||||||
#define HAVE_UTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the vsnprintf function. */
|
|
||||||
#define HAVE_VSNPRINTF 1
|
|
||||||
|
|
||||||
/* Define if you have the <assert.h> header file. */
|
|
||||||
#define HAVE_ASSERT_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <ctype.h> header file. */
|
|
||||||
#define HAVE_CTYPE_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <curses.h> header file. */
|
|
||||||
#define HAVE_CURSES_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <limits.h> header file. */
|
|
||||||
#define HAVE_LIMITS_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <linux/kd.h> header file. */
|
|
||||||
#define HAVE_LINUX_KD_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <linux/kdev_t.h> header file. */
|
|
||||||
#define HAVE_LINUX_KDEV_T_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <linux/major.h> header file. */
|
|
||||||
#define HAVE_LINUX_MAJOR_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <memory.h> header file. */
|
|
||||||
#define HAVE_MEMORY_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <ncurses.h> header file. */
|
|
||||||
#define HAVE_NCURSES_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <signal.h> header file. */
|
|
||||||
#define HAVE_SIGNAL_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <stddef.h> header file. */
|
|
||||||
#define HAVE_STDDEF_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <stdint.h> header file. */
|
|
||||||
#define HAVE_STDINT_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/param.h> header file. */
|
|
||||||
#define HAVE_SYS_PARAM_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/resource.h> header file. */
|
|
||||||
#define HAVE_SYS_RESOURCE_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/time.h> header file. */
|
|
||||||
#define HAVE_SYS_TIME_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/times.h> header file. */
|
|
||||||
#define HAVE_SYS_TIMES_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/utime.h> header file. */
|
|
||||||
/* #undef HAVE_SYS_UTIME_H */
|
|
||||||
|
|
||||||
/* Define if you have the <time.h> header file. */
|
|
||||||
#define HAVE_TIME_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <unistd.h> header file. */
|
|
||||||
#define HAVE_UNISTD_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <utime.h> header file. */
|
|
||||||
#define HAVE_UTIME_H 1
|
|
||||||
|
|
||||||
/* $BOTTOM$ */
|
|
||||||
|
|
||||||
#if defined(HAVE_GMTIME) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_GMTIME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_LOCALTIME) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_LOCALTIME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_STRFTIME) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_STRFTIME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_SYS_RESOURCE_H) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_SYS_RESOURCE_H
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_SYS_TIMES_H) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_SYS_TIMES_H
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/*
|
|
||||||
vi:ts=4
|
|
||||||
*/
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
/* pseudo <config.h> for sparc-sun-solaris2.8 */
|
|
||||||
|
|
||||||
#ifndef __UPX_CONFIG_H
|
|
||||||
#define __UPX_CONFIG_H
|
|
||||||
|
|
||||||
/* $TOP$ */
|
|
||||||
|
|
||||||
/* Define to empty if the keyword does not work. */
|
|
||||||
/* #undef const */
|
|
||||||
|
|
||||||
/* Define if your C compiler doesn't accept -c and -o together. */
|
|
||||||
/* #undef NO_MINUS_C_MINUS_O */
|
|
||||||
|
|
||||||
/* Define as the return type of signal handlers (int or void). */
|
|
||||||
#define RETSIGTYPE void
|
|
||||||
|
|
||||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
|
||||||
/* #undef size_t */
|
|
||||||
|
|
||||||
/* Define if you have the ANSI C header files. */
|
|
||||||
#define STDC_HEADERS 1
|
|
||||||
|
|
||||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
|
||||||
#define TIME_WITH_SYS_TIME 1
|
|
||||||
|
|
||||||
/* Define if your memcmp is broken. */
|
|
||||||
/* #undef NO_MEMCMP */
|
|
||||||
|
|
||||||
/* Define to `long' if <stddef.h> doesn't define. */
|
|
||||||
/* #undef ptrdiff_t */
|
|
||||||
|
|
||||||
/* Define when using the dmalloc package. */
|
|
||||||
/* #undef WITH_DMALLOC */
|
|
||||||
|
|
||||||
/* Define if you have the access function. */
|
|
||||||
#define HAVE_ACCESS 1
|
|
||||||
|
|
||||||
/* Define if you have the atoi function. */
|
|
||||||
#define HAVE_ATOI 1
|
|
||||||
|
|
||||||
/* Define if you have the chmod function. */
|
|
||||||
#define HAVE_CHMOD 1
|
|
||||||
|
|
||||||
/* Define if you have the chown function. */
|
|
||||||
#define HAVE_CHOWN 1
|
|
||||||
|
|
||||||
/* Define if you have the ctime function. */
|
|
||||||
#define HAVE_CTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the difftime function. */
|
|
||||||
#define HAVE_DIFFTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the fchmod function. */
|
|
||||||
#define HAVE_FCHMOD 1
|
|
||||||
|
|
||||||
/* Define if you have the fileno function. */
|
|
||||||
#define HAVE_FILENO 1
|
|
||||||
|
|
||||||
/* Define if you have the fstat function. */
|
|
||||||
#define HAVE_FSTAT 1
|
|
||||||
|
|
||||||
/* Define if you have the XXX function. */
|
|
||||||
#define HAVE_GETPID 1
|
|
||||||
|
|
||||||
/* Define if you have the XXX function. */
|
|
||||||
#define HAVE_GETTIMEOFDAY 1
|
|
||||||
|
|
||||||
/* Define if you have the getumask function. */
|
|
||||||
/* #undef HAVE_GETUMASK */
|
|
||||||
|
|
||||||
/* Define if you have the gmtime function. */
|
|
||||||
#define HAVE_GMTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the index function. */
|
|
||||||
#define HAVE_INDEX 1
|
|
||||||
|
|
||||||
/* Define if you have the isatty function. */
|
|
||||||
#define HAVE_ISATTY 1
|
|
||||||
|
|
||||||
/* Define if you have the lstat function. */
|
|
||||||
#define HAVE_LSTAT 1
|
|
||||||
|
|
||||||
/* Define if you have the localtime function. */
|
|
||||||
#define HAVE_LOCALTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the memcmp function. */
|
|
||||||
#define HAVE_MEMCMP 1
|
|
||||||
|
|
||||||
/* Define if you have the memcpy function. */
|
|
||||||
#define HAVE_MEMCPY 1
|
|
||||||
|
|
||||||
/* Define if you have the memmove function. */
|
|
||||||
#define HAVE_MEMMOVE 1
|
|
||||||
|
|
||||||
/* Define if you have the memset function. */
|
|
||||||
#define HAVE_MEMSET 1
|
|
||||||
|
|
||||||
/* Define if you have the mktime function. */
|
|
||||||
#define HAVE_MKTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the setmode function. */
|
|
||||||
/* #undef HAVE_SETMODE */
|
|
||||||
|
|
||||||
/* Define if you have the stat function. */
|
|
||||||
#define HAVE_STAT 1
|
|
||||||
|
|
||||||
/* Define if you have the strcasecmp function. */
|
|
||||||
#define HAVE_STRCASECMP 1
|
|
||||||
|
|
||||||
/* Define if you have the strchr function. */
|
|
||||||
#define HAVE_STRCHR 1
|
|
||||||
|
|
||||||
/* Define if you have the strdup function. */
|
|
||||||
#define HAVE_STRDUP 1
|
|
||||||
|
|
||||||
/* Define if you have the strftime function. */
|
|
||||||
#define HAVE_STRFTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the stricmp function. */
|
|
||||||
/* #undef HAVE_STRICMP */
|
|
||||||
|
|
||||||
/* Define if you have the strncasecmp function. */
|
|
||||||
#define HAVE_STRNCASECMP 1
|
|
||||||
|
|
||||||
/* Define if you have the strnicmp function. */
|
|
||||||
/* #undef HAVE_STRNICMP */
|
|
||||||
|
|
||||||
/* Define if you have the strstr function. */
|
|
||||||
#define HAVE_STRSTR 1
|
|
||||||
|
|
||||||
/* Define if you have the tzset function. */
|
|
||||||
#define HAVE_TZSET 1
|
|
||||||
|
|
||||||
/* Define if you have the umask function. */
|
|
||||||
#define HAVE_UMASK 1
|
|
||||||
|
|
||||||
/* Define if you have the utime function. */
|
|
||||||
#define HAVE_UTIME 1
|
|
||||||
|
|
||||||
/* Define if you have the vsnprintf function. */
|
|
||||||
#define HAVE_VSNPRINTF 1
|
|
||||||
|
|
||||||
/* Define if you have the <assert.h> header file. */
|
|
||||||
#define HAVE_ASSERT_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <ctype.h> header file. */
|
|
||||||
#define HAVE_CTYPE_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <curses.h> header file. */
|
|
||||||
#define HAVE_CURSES_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <limits.h> header file. */
|
|
||||||
#define HAVE_LIMITS_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <linux/kd.h> header file. */
|
|
||||||
#define HAVE_LINUX_KD_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <linux/kdev_t.h> header file. */
|
|
||||||
#define HAVE_LINUX_KDEV_T_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <linux/major.h> header file. */
|
|
||||||
#define HAVE_LINUX_MAJOR_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <memory.h> header file. */
|
|
||||||
#define HAVE_MEMORY_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <ncurses.h> header file. */
|
|
||||||
#define HAVE_NCURSES_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <signal.h> header file. */
|
|
||||||
#define HAVE_SIGNAL_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <stddef.h> header file. */
|
|
||||||
#define HAVE_STDDEF_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/param.h> header file. */
|
|
||||||
#define HAVE_SYS_PARAM_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/resource.h> header file. */
|
|
||||||
#define HAVE_SYS_RESOURCE_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/time.h> header file. */
|
|
||||||
#define HAVE_SYS_TIME_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/times.h> header file. */
|
|
||||||
#define HAVE_SYS_TIMES_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <sys/utime.h> header file. */
|
|
||||||
/* #undef HAVE_SYS_UTIME_H */
|
|
||||||
|
|
||||||
/* Define if you have the <time.h> header file. */
|
|
||||||
#define HAVE_TIME_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <unistd.h> header file. */
|
|
||||||
#define HAVE_UNISTD_H 1
|
|
||||||
|
|
||||||
/* Define if you have the <utime.h> header file. */
|
|
||||||
#define HAVE_UTIME_H 1
|
|
||||||
|
|
||||||
/* $BOTTOM$ */
|
|
||||||
|
|
||||||
#if defined(HAVE_GMTIME) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_GMTIME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_LOCALTIME) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_LOCALTIME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_STRFTIME) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_STRFTIME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_SYS_RESOURCE_H) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_SYS_RESOURCE_H
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_SYS_TIMES_H) && !defined(TIME_WITH_SYS_TIME)
|
|
||||||
# undef /**/ HAVE_SYS_TIMES_H
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/*
|
|
||||||
vi:ts=4
|
|
||||||
*/
|
|
||||||
+12
-9
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -34,8 +34,9 @@
|
|||||||
#undef USE_CONSOLE
|
#undef USE_CONSOLE
|
||||||
#undef USE_ANSI
|
#undef USE_ANSI
|
||||||
#undef USE_SCREEN
|
#undef USE_SCREEN
|
||||||
#undef USE_SCREEN_VCSA
|
|
||||||
#undef USE_SCREEN_CURSES
|
#undef USE_SCREEN_CURSES
|
||||||
|
#undef USE_SCREEN_VCSA
|
||||||
|
#undef USE_SCREEN_WIN32
|
||||||
#undef USE_FRAMES
|
#undef USE_FRAMES
|
||||||
|
|
||||||
#if defined(WITH_GUI) && !defined(NO_CONSOLE)
|
#if defined(WITH_GUI) && !defined(NO_CONSOLE)
|
||||||
@@ -57,10 +58,12 @@
|
|||||||
|
|
||||||
#if 1 && defined(__DJGPP__)
|
#if 1 && defined(__DJGPP__)
|
||||||
# define USE_SCREEN
|
# define USE_SCREEN
|
||||||
#endif
|
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
|
|
||||||
#if 1 && defined(__MFX_WIN32)
|
|
||||||
# define USE_SCREEN
|
# define USE_SCREEN
|
||||||
|
# define USE_SCREEN_WIN32
|
||||||
|
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
|
||||||
|
# define USE_SCREEN
|
||||||
|
# define USE_SCREEN_WIN32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -120,10 +123,10 @@ console_t;
|
|||||||
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
void con_fprintf(FILE *f, const char *format, ...)
|
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
|
||||||
__attribute__((format(printf,2,3)));
|
__attribute__((__format__(printf,2,3)));
|
||||||
#else
|
#else
|
||||||
void con_fprintf(FILE *f, const char *format, ...);
|
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+17
-15
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
long Throwable::counter = 0;
|
long Throwable::counter = 0;
|
||||||
|
|
||||||
Throwable::Throwable(const char *m, int e, bool w)
|
Throwable::Throwable(const char *m, int e, bool w) NOTHROW
|
||||||
: super(), msg(NULL), err(e), is_warning(w)
|
: super(), msg(NULL), err(e), is_warning(w)
|
||||||
{
|
{
|
||||||
if (m)
|
if (m)
|
||||||
@@ -47,7 +47,7 @@ Throwable::Throwable(const char *m, int e, bool w)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Throwable::Throwable(Throwable const &other)
|
Throwable::Throwable(const Throwable &other) NOTHROW
|
||||||
: super(other), msg(NULL), err(other.err), is_warning(other.is_warning)
|
: super(other), msg(NULL), err(other.err), is_warning(other.is_warning)
|
||||||
{
|
{
|
||||||
if (other.msg)
|
if (other.msg)
|
||||||
@@ -174,22 +174,24 @@ void throwEOFException(const char *msg, int e)
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
const char *prettyName(const char *n)
|
const char *prettyName(const char *n) NOTHROW
|
||||||
{
|
{
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
return "";
|
return "(null)";
|
||||||
while (*n >= '0' && *n <= '9') // gcc
|
while (*n)
|
||||||
n++;
|
{
|
||||||
if (strncmp(n, "class ", 6) == 0) // Visual C++
|
if (*n >= '0' && *n <= '9') // Linux ABI
|
||||||
n += 6;
|
n++;
|
||||||
|
else if (*n == ' ')
|
||||||
|
n++;
|
||||||
|
else if (strncmp(n, "class ", 6) == 0) // Visual C++
|
||||||
|
n += 6;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *prettyName(const std::type_info &ti)
|
|
||||||
{
|
|
||||||
return prettyName(ti.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
vi:ts=4:et
|
vi:ts=4:et
|
||||||
|
|||||||
+25
-29
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -31,8 +31,7 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
const char *prettyName(const char *n);
|
const char *prettyName(const char *n) NOTHROW;
|
||||||
const char *prettyName(const std::type_info &ti);
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -43,13 +42,13 @@ class Throwable : public std::exception
|
|||||||
{
|
{
|
||||||
typedef std::exception super;
|
typedef std::exception super;
|
||||||
protected:
|
protected:
|
||||||
Throwable(const char *m = 0, int e = 0, bool w = false);
|
Throwable(const char *m = 0, int e = 0, bool w = false) NOTHROW;
|
||||||
public:
|
public:
|
||||||
Throwable(Throwable const &);
|
Throwable(const Throwable &) NOTHROW;
|
||||||
virtual ~Throwable() NOTHROW;
|
virtual ~Throwable() NOTHROW;
|
||||||
const char *getMsg() const { return msg; }
|
const char *getMsg() const NOTHROW { return msg; }
|
||||||
int getErrno() const { return err; }
|
int getErrno() const NOTHROW { return err; }
|
||||||
bool isWarning() const { return is_warning; }
|
bool isWarning() const NOTHROW { return is_warning; }
|
||||||
private:
|
private:
|
||||||
char *msg;
|
char *msg;
|
||||||
int err;
|
int err;
|
||||||
@@ -58,12 +57,9 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// disable assignment
|
// disable assignment
|
||||||
Throwable& operator= (Throwable const &);
|
Throwable& operator= (const Throwable &);
|
||||||
// disable dynamic allocation
|
// disable dynamic allocation
|
||||||
#ifndef new
|
DISABLE_NEW_DELETE
|
||||||
static void *operator new (size_t); // {}
|
|
||||||
static void *operator new[] (size_t); // {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static long counter; // for debugging
|
static long counter; // for debugging
|
||||||
@@ -75,7 +71,7 @@ class Exception : public Throwable
|
|||||||
{
|
{
|
||||||
typedef Throwable super;
|
typedef Throwable super;
|
||||||
public:
|
public:
|
||||||
Exception(const char *m = 0, int e = 0, bool w = false) : super(m,e,w) { }
|
Exception(const char *m = 0, int e = 0, bool w = false) NOTHROW : super(m,e,w) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +80,7 @@ class Error : public Throwable
|
|||||||
{
|
{
|
||||||
typedef Throwable super;
|
typedef Throwable super;
|
||||||
public:
|
public:
|
||||||
Error(const char *m = 0, int e = 0) : super(m,e) { }
|
Error(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +92,7 @@ class OutOfMemoryException : public Exception
|
|||||||
{
|
{
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
public:
|
public:
|
||||||
OutOfMemoryException(const char *m = 0, int e = 0) : super(m,e) { }
|
OutOfMemoryException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -104,7 +100,7 @@ class IOException : public Exception
|
|||||||
{
|
{
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
public:
|
public:
|
||||||
IOException(const char *m = 0, int e = 0) : super(m,e) { }
|
IOException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +108,7 @@ class EOFException : public IOException
|
|||||||
{
|
{
|
||||||
typedef IOException super;
|
typedef IOException super;
|
||||||
public:
|
public:
|
||||||
EOFException(const char *m = 0, int e = 0) : super(m,e) { }
|
EOFException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -120,7 +116,7 @@ class FileNotFoundException : public IOException
|
|||||||
{
|
{
|
||||||
typedef IOException super;
|
typedef IOException super;
|
||||||
public:
|
public:
|
||||||
FileNotFoundException(const char *m = 0, int e = 0) : super(m,e) { }
|
FileNotFoundException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +124,7 @@ class FileAlreadyExistsException : public IOException
|
|||||||
{
|
{
|
||||||
typedef IOException super;
|
typedef IOException super;
|
||||||
public:
|
public:
|
||||||
FileAlreadyExistsException(const char *m = 0, int e = 0) : super(m,e) { }
|
FileAlreadyExistsException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -140,35 +136,35 @@ class OverlayException : public Exception
|
|||||||
{
|
{
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
public:
|
public:
|
||||||
OverlayException(const char *m = 0, bool w = false) : super(m,0,w) { }
|
OverlayException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CantPackException : public Exception
|
class CantPackException : public Exception
|
||||||
{
|
{
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
public:
|
public:
|
||||||
CantPackException(const char *m = 0, bool w = false) : super(m,0,w) { }
|
CantPackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class UnknownExecutableFormatException : public CantPackException
|
class UnknownExecutableFormatException : public CantPackException
|
||||||
{
|
{
|
||||||
typedef CantPackException super;
|
typedef CantPackException super;
|
||||||
public:
|
public:
|
||||||
UnknownExecutableFormatException(const char *m = 0, bool w = false) : super(m,w) { }
|
UnknownExecutableFormatException(const char *m = 0, bool w = false) NOTHROW : super(m,w) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class AlreadyPackedException : public CantPackException
|
class AlreadyPackedException : public CantPackException
|
||||||
{
|
{
|
||||||
typedef CantPackException super;
|
typedef CantPackException super;
|
||||||
public:
|
public:
|
||||||
AlreadyPackedException(const char *m = 0) : super(m) { is_warning = true; }
|
AlreadyPackedException(const char *m = 0) NOTHROW : super(m) { is_warning = true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotCompressibleException : public CantPackException
|
class NotCompressibleException : public CantPackException
|
||||||
{
|
{
|
||||||
typedef CantPackException super;
|
typedef CantPackException super;
|
||||||
public:
|
public:
|
||||||
NotCompressibleException(const char *m = 0) : super(m) { }
|
NotCompressibleException(const char *m = 0) NOTHROW : super(m) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -176,14 +172,14 @@ class CantUnpackException : public Exception
|
|||||||
{
|
{
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
public:
|
public:
|
||||||
CantUnpackException(const char *m = 0, bool w = false) : super(m,0,w) { }
|
CantUnpackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotPackedException : public CantUnpackException
|
class NotPackedException : public CantUnpackException
|
||||||
{
|
{
|
||||||
typedef CantUnpackException super;
|
typedef CantUnpackException super;
|
||||||
public:
|
public:
|
||||||
NotPackedException(const char *m = 0) : super(m,true) { }
|
NotPackedException(const char *m = 0) NOTHROW : super(m,true) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -195,7 +191,7 @@ class InternalError : public Error
|
|||||||
{
|
{
|
||||||
typedef Error super;
|
typedef Error super;
|
||||||
public:
|
public:
|
||||||
InternalError(const char *m = 0) : super(m,0) { }
|
InternalError(const char *m = 0) NOTHROW : super(m,0) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+37
-64
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -46,7 +46,7 @@ void File::chmod(const char *name, int mode)
|
|||||||
|
|
||||||
void File::rename(const char *old_, const char *new_)
|
void File::rename(const char *old_, const char *new_)
|
||||||
{
|
{
|
||||||
#if 1 && defined(__DJGPP__)
|
#if defined(__DJGPP__)
|
||||||
if (::_rename(old_,new_) != 0)
|
if (::_rename(old_,new_) != 0)
|
||||||
#else
|
#else
|
||||||
if (::rename(old_,new_) != 0)
|
if (::rename(old_,new_) != 0)
|
||||||
@@ -128,29 +128,13 @@ void FileBase::closex()
|
|||||||
|
|
||||||
int FileBase::read(void *buf, int len)
|
int FileBase::read(void *buf, int len)
|
||||||
{
|
{
|
||||||
int l;
|
|
||||||
if (!isOpen() || len < 0)
|
if (!isOpen() || len < 0)
|
||||||
throwIOException("bad read");
|
throwIOException("bad read");
|
||||||
if (len == 0)
|
errno = 0;
|
||||||
return 0;
|
long l = acc_safe_hread(_fd, buf, len);
|
||||||
for (;;)
|
if (errno)
|
||||||
{
|
throwIOException("read error",errno);
|
||||||
#if 1 && defined(__DJGPP__)
|
return (int) l;
|
||||||
l = ::_read(_fd, buf, len);
|
|
||||||
#else
|
|
||||||
l = ::read(_fd, buf, len);
|
|
||||||
#endif
|
|
||||||
if (l < 0)
|
|
||||||
{
|
|
||||||
#if defined(EINTR)
|
|
||||||
if (errno == EINTR)
|
|
||||||
continue;
|
|
||||||
#endif
|
|
||||||
throwIOException("read error",errno);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -165,26 +149,12 @@ int FileBase::readx(void *buf, int len)
|
|||||||
|
|
||||||
void FileBase::write(const void *buf, int len)
|
void FileBase::write(const void *buf, int len)
|
||||||
{
|
{
|
||||||
int l;
|
|
||||||
if (!isOpen() || len < 0)
|
if (!isOpen() || len < 0)
|
||||||
throwIOException("bad write");
|
throwIOException("bad write");
|
||||||
if (len == 0)
|
errno = 0;
|
||||||
return;
|
long l = acc_safe_hwrite(_fd, buf, len);
|
||||||
for (;;)
|
if (l != len)
|
||||||
{
|
throwIOException("write error",errno);
|
||||||
#if 1 && defined(__DJGPP__)
|
|
||||||
l = ::_write(_fd,buf,len);
|
|
||||||
#else
|
|
||||||
l = ::write(_fd,buf,len);
|
|
||||||
#endif
|
|
||||||
#if defined(EINTR)
|
|
||||||
if (l < 0 && errno == EINTR)
|
|
||||||
continue;
|
|
||||||
#endif
|
|
||||||
if (l != len)
|
|
||||||
throwIOException("write error",errno);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -259,14 +229,16 @@ int InputFile::readx(void *buf, int len)
|
|||||||
|
|
||||||
int InputFile::read(MemBuffer *buf, int len)
|
int InputFile::read(MemBuffer *buf, int len)
|
||||||
{
|
{
|
||||||
|
buf->checkState();
|
||||||
assert((unsigned)len <= buf->getSize());
|
assert((unsigned)len <= buf->getSize());
|
||||||
return super::read(buf->getVoidPtr(), len);
|
return read(buf->getVoidPtr(), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int InputFile::readx(MemBuffer *buf, int len)
|
int InputFile::readx(MemBuffer *buf, int len)
|
||||||
{
|
{
|
||||||
|
buf->checkState();
|
||||||
assert((unsigned)len <= buf->getSize());
|
assert((unsigned)len <= buf->getSize());
|
||||||
return super::readx(buf->getVoidPtr(), len);
|
return read(buf->getVoidPtr(), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -335,29 +307,16 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
|
|||||||
bool OutputFile::openStdout(int flags, bool force)
|
bool OutputFile::openStdout(int flags, bool force)
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
if (!force)
|
int fd = STDOUT_FILENO;
|
||||||
{
|
if (!force && acc_isatty(fd))
|
||||||
if (!isafile(STDOUT_FILENO))
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_fd = STDOUT_FILENO;
|
|
||||||
_name = "<stdout>";
|
_name = "<stdout>";
|
||||||
_flags = flags;
|
_flags = flags;
|
||||||
_shflags = -1;
|
_shflags = -1;
|
||||||
_mode = 0;
|
_mode = 0;
|
||||||
if (flags != 0)
|
if (flags && acc_set_binmode(fd, 1) == -1)
|
||||||
{
|
throwIOException(_name, errno);
|
||||||
assert(flags == O_BINARY);
|
_fd = fd;
|
||||||
#if defined(__MINT__)
|
|
||||||
__set_binmode(stdout, 1);
|
|
||||||
#elif defined(HAVE_SETMODE) && defined(USE_SETMODE)
|
|
||||||
if (setmode(_fd, O_BINARY) == -1)
|
|
||||||
throwIOException(_name,errno);
|
|
||||||
#if defined(__DJGPP__)
|
|
||||||
__djgpp_set_ctrl_c(1);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,13 +328,27 @@ void OutputFile::write(const void *buf, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OutputFile::write(const MemBuffer *buf, int len)
|
||||||
|
{
|
||||||
|
buf->checkState();
|
||||||
|
assert((unsigned)len <= buf->getSize());
|
||||||
|
write(buf->getVoidPtr(), len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OutputFile::write(const MemBuffer &buf, int len)
|
||||||
|
{
|
||||||
|
write(&buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
||||||
{
|
{
|
||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
flags = O_CREAT | O_BINARY | O_TRUNC;
|
flags = O_CREAT | O_BINARY | O_TRUNC;
|
||||||
flags |= O_WRONLY;
|
flags |= O_WRONLY;
|
||||||
OutputFile f;
|
OutputFile f;
|
||||||
f.open(name, flags, 0666);
|
f.open(name, flags, 0600);
|
||||||
f.write(buf, len);
|
f.write(buf, len);
|
||||||
f.closex();
|
f.closex();
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-3
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -38,6 +38,9 @@ class MemBuffer;
|
|||||||
|
|
||||||
class File
|
class File
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
File() { }
|
||||||
|
virtual ~File() { }
|
||||||
public:
|
public:
|
||||||
static void chmod(const char *name, int mode);
|
static void chmod(const char *name, int mode);
|
||||||
static void rename(const char *old_, const char *new_);
|
static void rename(const char *old_, const char *new_);
|
||||||
@@ -123,6 +126,8 @@ public:
|
|||||||
virtual bool openStdout(int flags=0, bool force=false);
|
virtual bool openStdout(int flags=0, bool force=false);
|
||||||
|
|
||||||
virtual void write(const void *buf, int len);
|
virtual void write(const void *buf, int len);
|
||||||
|
virtual void write(const MemBuffer *buf, int len);
|
||||||
|
virtual void write(const MemBuffer &buf, int len);
|
||||||
|
|
||||||
off_t getBytesWritten() const { return bytes_written; }
|
off_t getBytesWritten() const { return bytes_written; }
|
||||||
|
|
||||||
@@ -153,7 +158,7 @@ protected:
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if 0
|
#if 0 /* NOT USED */
|
||||||
class MemoryOutputFile : public FileBase
|
class MemoryOutputFile : public FileBase
|
||||||
{
|
{
|
||||||
typedef FileBase super;
|
typedef FileBase super;
|
||||||
|
|||||||
+4
-4
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
If not, write to the Free Software Foundation, Inc.,
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+10
-3
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -36,11 +36,11 @@ static int F(Filter *f)
|
|||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
upx_byte *b = f->buf;
|
||||||
const unsigned addvalue = f->addvalue;
|
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const upx_byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
|
|
||||||
unsigned ic, jc, kc;
|
unsigned ic, jc, kc;
|
||||||
@@ -52,6 +52,11 @@ static int F(Filter *f)
|
|||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
memset(buf,0,256);
|
memset(buf,0,256);
|
||||||
|
|
||||||
|
// A call to a destination that is inside the buffer
|
||||||
|
// will be rewritten and marked with cto8 as first byte.
|
||||||
|
// So, a call to a destination that is outside the buffer
|
||||||
|
// must not conflict with the mark.
|
||||||
|
// Note that unsigned comparison checks both edges of buffer.
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++)
|
||||||
if (COND(b,ic) && get_le32(b+ic+1)+ic+1 >= size)
|
if (COND(b,ic) && get_le32(b+ic+1)+ic+1 >= size)
|
||||||
{
|
{
|
||||||
@@ -74,6 +79,8 @@ static int F(Filter *f)
|
|||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size)
|
||||||
{
|
{
|
||||||
|
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||||
|
return 1; // fail - buffer not restored
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b+ic+1,jc+addvalue+cto);
|
set_be32(b+ic+1,jc+addvalue+cto);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-7
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -40,11 +40,11 @@ static int F(Filter *f)
|
|||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
upx_byte *b = f->buf;
|
||||||
const unsigned addvalue = f->addvalue;
|
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const upx_byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
|
|
||||||
unsigned ic, jc, kc;
|
unsigned ic, jc, kc;
|
||||||
@@ -78,6 +78,8 @@ static int F(Filter *f)
|
|||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size)
|
||||||
{
|
{
|
||||||
|
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||||
|
return 1; // fail - buffer not restored
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b+ic+1,jc+addvalue+cto);
|
set_be32(b+ic+1,jc+addvalue+cto);
|
||||||
#endif
|
#endif
|
||||||
@@ -134,8 +136,7 @@ static int U(Filter *f)
|
|||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned cto = (unsigned)f->cto << 24;
|
const unsigned cto = (unsigned)f->cto << 24;
|
||||||
unsigned lastcall = 0;
|
// unsigned lastcall = 0; // lastcall is not used in COND macro
|
||||||
|
|
||||||
unsigned ic, jc;
|
unsigned ic, jc;
|
||||||
|
|
||||||
for (ic = 0; ic < size5; ic++)
|
for (ic = 0; ic < size5; ic++)
|
||||||
@@ -147,7 +148,7 @@ static int U(Filter *f)
|
|||||||
set_le32(b+ic+1,jc-ic-1-addvalue-cto);
|
set_le32(b+ic+1,jc-ic-1-addvalue-cto);
|
||||||
f->calls++;
|
f->calls++;
|
||||||
ic += 4;
|
ic += 4;
|
||||||
f->lastcall = lastcall = ic+1;
|
f->lastcall = ic+1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
f->noncalls++;
|
f->noncalls++;
|
||||||
|
|||||||
+8
-3
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -30,6 +30,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1300))
|
||||||
|
# pragma warning(disable: 4702) // W4: unreachable code
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// filter / scan
|
// filter / scan
|
||||||
@@ -131,6 +135,7 @@ static int F(Filter *f)
|
|||||||
{
|
{
|
||||||
buf[b[ic+1]] |= 1;
|
buf[b[ic+1]] |= 1;
|
||||||
}
|
}
|
||||||
|
UNUSED(which);
|
||||||
|
|
||||||
if (getcto(f, buf) < 0)
|
if (getcto(f, buf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
+6
-4
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -40,11 +40,11 @@ static int F(Filter *f)
|
|||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
upx_byte *b = f->buf;
|
||||||
const unsigned addvalue = f->addvalue;
|
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const upx_byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
unsigned const id = f->id;
|
unsigned const id = f->id;
|
||||||
|
|
||||||
@@ -79,6 +79,8 @@ static int F(Filter *f)
|
|||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size)
|
||||||
{
|
{
|
||||||
|
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||||
|
return 1; // fail - buffer not restored
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b+ic+1,jc+addvalue+cto);
|
set_be32(b+ic+1,jc+addvalue+cto);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+3
-3
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -232,7 +232,7 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
|||||||
{ 0xb3,99, 0, f_sub32_4, u_sub32_4, s_sub32_4 },
|
{ 0xb3,99, 0, f_sub32_4, u_sub32_4, s_sub32_4 },
|
||||||
};
|
};
|
||||||
|
|
||||||
const int FilterImp::n_filters = HIGH(filters);
|
const int FilterImp::n_filters = TABLESIZE(filters);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+46
-41
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2005 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -48,11 +48,11 @@ void show_head(void)
|
|||||||
fg = con_fg(f,FG_GREEN);
|
fg = con_fg(f,FG_GREEN);
|
||||||
con_fprintf(f,
|
con_fprintf(f,
|
||||||
" Ultimate Packer for eXecutables\n"
|
" Ultimate Packer for eXecutables\n"
|
||||||
" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002\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",
|
"UPX %-12s Markus F.X.J. Oberhumer & Laszlo Molnar %20s\n\n",
|
||||||
#if defined(__MFX_DOS)
|
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||||
V("d"),
|
V("d"),
|
||||||
#elif defined(__MFX_WIN32)
|
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
V("w"),
|
V("w"),
|
||||||
#elif 0 && defined(__linux__)
|
#elif 0 && defined(__linux__)
|
||||||
V("l"),
|
V("l"),
|
||||||
@@ -62,6 +62,8 @@ void show_head(void)
|
|||||||
UPX_VERSION_DATE);
|
UPX_VERSION_DATE);
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
#undef V
|
#undef V
|
||||||
|
|
||||||
|
UNUSED(fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +105,7 @@ void show_help(int x)
|
|||||||
" -d decompress -l list compressed file\n"
|
" -d decompress -l list compressed file\n"
|
||||||
" -t test compressed file -V display version number\n"
|
" -t test compressed file -V display version number\n"
|
||||||
" -h give %s help -L display software license\n%s",
|
" -h give %s help -L display software license\n%s",
|
||||||
x == 0 ? "" : " --best compress best (can be very slow for big files)\n",
|
x == 0 ? "" : " --best compress best (can be slow for big files)\n",
|
||||||
x == 0 ? "more" : "this", x == 0 ? "" : "\n");
|
x == 0 ? "more" : "this", x == 0 ? "" : "\n");
|
||||||
|
|
||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
@@ -138,17 +140,15 @@ void show_help(int x)
|
|||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
con_fprintf(f,
|
con_fprintf(f,
|
||||||
" --overlay=copy copy any extra data attached to the file [default]\n"
|
" --overlay=copy copy any extra data attached to the file [default]\n"
|
||||||
" --overlay=strip strip any extra data attached to the file [dangerous]\n"
|
" --overlay=strip strip any extra data attached to the file [DANGEROUS]\n"
|
||||||
" --overlay=skip don't compress a file with an overlay\n"
|
" --overlay=skip don't compress a file with an overlay\n"
|
||||||
"\n");
|
"\n");
|
||||||
#if 1
|
|
||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
con_fprintf(f,"Options for atari/tos:\n");
|
con_fprintf(f,"Options for atari/tos:\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
con_fprintf(f,
|
con_fprintf(f,
|
||||||
" --all-methods try all available compression methods\n"
|
" --all-methods try all available compression methods\n"
|
||||||
"\n");
|
"\n");
|
||||||
#endif
|
|
||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
con_fprintf(f,"Options for djgpp2/coff:\n");
|
con_fprintf(f,"Options for djgpp2/coff:\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
@@ -190,16 +190,15 @@ void show_help(int x)
|
|||||||
" --script=/path/upxX use path/upxX as decompressor\n"
|
" --script=/path/upxX use path/upxX as decompressor\n"
|
||||||
"\n");
|
"\n");
|
||||||
#endif
|
#endif
|
||||||
#if 1
|
|
||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
con_fprintf(f,"Options for ps1/exe:\n");
|
con_fprintf(f,"Options for ps1/exe:\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
con_fprintf(f,
|
con_fprintf(f,
|
||||||
" --all-methods try all available compression methods\n"
|
" --all-methods try all available compression methods\n"
|
||||||
" --no-align don't align to mode2 sector format\n"
|
" --8-bit uses 8 bit size compression [default: 32 bit]\n"
|
||||||
|
" --console-run enables client/host transfer compatibility\n"
|
||||||
|
" --no-align don't align to 2048 bytes [enables: --console-run]\n"
|
||||||
"\n");
|
"\n");
|
||||||
#endif
|
|
||||||
#if 1
|
|
||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
con_fprintf(f,"Options for tmt/adam:\n");
|
con_fprintf(f,"Options for tmt/adam:\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
@@ -207,16 +206,13 @@ void show_help(int x)
|
|||||||
" --all-methods try all available compression methods\n"
|
" --all-methods try all available compression methods\n"
|
||||||
" --all-filters try all available preprocessing filters\n"
|
" --all-filters try all available preprocessing filters\n"
|
||||||
"\n");
|
"\n");
|
||||||
#endif
|
|
||||||
#if 1
|
|
||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
con_fprintf(f,"Options for [b]vmlinuz/386\n");
|
con_fprintf(f,"Options for vmlinuz/386\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
con_fprintf(f,
|
con_fprintf(f,
|
||||||
" --all-methods try all available compression methods\n"
|
" --all-methods try all available compression methods\n"
|
||||||
" --all-filters try all available preprocessing filters\n"
|
" --all-filters try all available preprocessing filters\n"
|
||||||
"\n");
|
"\n");
|
||||||
#endif
|
|
||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
con_fprintf(f,"Options for watcom/le:\n");
|
con_fprintf(f,"Options for watcom/le:\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
@@ -233,6 +229,8 @@ void show_help(int x)
|
|||||||
" --compress-icons=1 compress all but the first icon\n"
|
" --compress-icons=1 compress all but the first icon\n"
|
||||||
" --compress-icons=2 compress all but the first icon directory [default]\n"
|
" --compress-icons=2 compress all but the first icon directory [default]\n"
|
||||||
" --compress-resources=0 do not compress any resources at all\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=0 do not strip relocations\n"
|
||||||
" --strip-relocs=1 strip relocations [default]\n"
|
" --strip-relocs=1 strip relocations [default]\n"
|
||||||
" --all-methods try all available compression methods\n"
|
" --all-methods try all available compression methods\n"
|
||||||
@@ -246,24 +244,27 @@ void show_help(int x)
|
|||||||
fg = con_fg(f,FG_YELLOW);
|
fg = con_fg(f,FG_YELLOW);
|
||||||
con_fprintf(f,"This version supports:\n");
|
con_fprintf(f,"This version supports:\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
con_fprintf(f," "
|
con_fprintf(f," "
|
||||||
"atari/tos, "
|
" atari/tos,"
|
||||||
"bvmlinuz/386, "
|
" bvmlinuz/386,"
|
||||||
"djgpp2/coff, "
|
" djgpp2/coff,"
|
||||||
"dos/com, "
|
" dos/com,"
|
||||||
"dos/exe, "
|
" dos/exe,"
|
||||||
"dos/sys,\n "
|
" dos/sys,"
|
||||||
//"elks/8086, "
|
"\n "
|
||||||
"linux/386, "
|
//" elks/8086,"
|
||||||
"linux/elf386, "
|
" linux/386,"
|
||||||
"linux/sh386, "
|
" linux/elf386,"
|
||||||
"ps1/exe, "
|
" linux/sh386,"
|
||||||
"rtm32/pe, "
|
" ps1/exe,"
|
||||||
"tmt/adam,\n "
|
" rtm32/pe,"
|
||||||
"vmlinuz/386, "
|
" tmt/adam,"
|
||||||
"watcom/le, "
|
"\n "
|
||||||
//"win16/ne, "
|
" vmlinux/386,"
|
||||||
"win32/pe"
|
" vmlinuz/386,"
|
||||||
|
" watcom/le,"
|
||||||
|
//" 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 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"
|
||||||
"");
|
"");
|
||||||
@@ -281,6 +282,8 @@ void show_help(int x)
|
|||||||
"\n");
|
"\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
UNUSED(fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -320,6 +323,8 @@ void show_license(void)
|
|||||||
" <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>\n"
|
" <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>\n"
|
||||||
);
|
);
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
|
|
||||||
|
UNUSED(fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -332,8 +337,8 @@ void show_version(int x)
|
|||||||
FILE *f = stdout;
|
FILE *f = stdout;
|
||||||
UNUSED(x);
|
UNUSED(x);
|
||||||
|
|
||||||
#if 0 && defined(__GNUC__)
|
#if (0 && ACC_CC_GNUC)
|
||||||
fprintf(f,"upx %s (gcc 0x%lx)\n", UPX_VERSION_STRING, __GNUC_VERSION_HEX__);
|
fprintf(f,"upx %s (gcc 0x%06lx)\n", UPX_VERSION_STRING, ACC_CC_GNUC);
|
||||||
#else
|
#else
|
||||||
fprintf(f,"upx %s\n", UPX_VERSION_STRING);
|
fprintf(f,"upx %s\n", UPX_VERSION_STRING);
|
||||||
#endif
|
#endif
|
||||||
@@ -343,10 +348,10 @@ void show_version(int x)
|
|||||||
#if defined(WITH_UCL)
|
#if defined(WITH_UCL)
|
||||||
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
|
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
|
||||||
#endif
|
#endif
|
||||||
fprintf(f,"Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer\n");
|
fprintf(f,"Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer\n");
|
||||||
fprintf(f,"Copyright (C) 1996-2002 Laszlo Molnar\n");
|
fprintf(f,"Copyright (C) 1996-2005 Laszlo Molnar\n");
|
||||||
fprintf(f,"Copyright (C) 2000-2002 John F. Reiser\n");
|
fprintf(f,"Copyright (C) 2000-2005 John F. Reiser\n");
|
||||||
fprintf(f,"Copyright (C) 2002 Jens Medoch\n");
|
fprintf(f,"Copyright (C) 2002-2005 Jens Medoch\n");
|
||||||
fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
|
fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+4
-4
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -219,8 +219,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// disable copy and assignment
|
// disable copy and assignment
|
||||||
LeFile(LeFile const &); // {}
|
LeFile(const LeFile &); // {}
|
||||||
LeFile& operator= (LeFile const &); // { return *this; }
|
LeFile& operator= (const LeFile &); // { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -57,7 +57,8 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
|||||||
info = pinfo;
|
info = pinfo;
|
||||||
njumps = nsections = frozen = 0;
|
njumps = nsections = frozen = 0;
|
||||||
jumps = new jump[200];
|
jumps = new jump[200];
|
||||||
sections = new section[200];
|
#define NSECTIONS 350
|
||||||
|
sections = new section[NSECTIONS];
|
||||||
|
|
||||||
char *p = iloader + info;
|
char *p = iloader + info;
|
||||||
while (get32(p) != (unsigned)(-1))
|
while (get32(p) != (unsigned)(-1))
|
||||||
@@ -68,7 +69,7 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
|||||||
sections[nsections].istart = get32(p+8);
|
sections[nsections].istart = get32(p+8);
|
||||||
sections[nsections++].ostart = -1;
|
sections[nsections++].ostart = -1;
|
||||||
p += 12;
|
p += 12;
|
||||||
assert(nsections < 200);
|
assert(nsections < NSECTIONS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -154,7 +155,7 @@ void Linker::addSection(const char *sname, const void *sdata, unsigned len)
|
|||||||
sections[nsections].istart = ilen;
|
sections[nsections].istart = ilen;
|
||||||
sections[nsections].len = len;
|
sections[nsections].len = len;
|
||||||
sections[nsections++].ostart = olen;
|
sections[nsections++].ostart = olen;
|
||||||
assert(nsections < 200);
|
assert(nsections < NSECTIONS);
|
||||||
memcpy(iloader+ilen,sdata,len);
|
memcpy(iloader+ilen,sdata,len);
|
||||||
ilen += len;
|
ilen += len;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -64,8 +64,8 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// disable copy and assignment
|
// disable copy and assignment
|
||||||
Linker(Linker const &); // {}
|
Linker(const Linker &); // {}
|
||||||
Linker& operator= (Linker const &); // { return *this; }
|
Linker& operator= (const Linker &); // { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -83,8 +83,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// disable copy and assignment
|
// disable copy and assignment
|
||||||
BeLinker(BeLinker const &); // {}
|
BeLinker(const BeLinker &); // {}
|
||||||
BeLinker& operator= (BeLinker const &); // { return *this; }
|
BeLinker& operator= (const BeLinker &); // { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+113
-130
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -56,20 +56,23 @@ void init_options(struct options_t *o)
|
|||||||
o->overlay = -1;
|
o->overlay = -1;
|
||||||
|
|
||||||
o->console = CON_FILE;
|
o->console = CON_FILE;
|
||||||
#if defined(__MFX_DOS) || defined(__MFX_WIN)
|
#if defined(__DJGPP__)
|
||||||
|
o->console = CON_INIT;
|
||||||
|
#elif defined(USE_SCREEN_WIN32)
|
||||||
o->console = CON_INIT;
|
o->console = CON_INIT;
|
||||||
#elif 1 && defined(__linux__)
|
#elif 1 && defined(__linux__)
|
||||||
o->console = CON_INIT;
|
o->console = CON_INIT;
|
||||||
#endif
|
#endif
|
||||||
o->verbose = 2;
|
o->verbose = 2;
|
||||||
|
|
||||||
o->w32pe.compress_exports = 1;
|
o->win32_pe.compress_exports = 1;
|
||||||
o->w32pe.compress_icons = 2;
|
o->win32_pe.compress_icons = 2;
|
||||||
o->w32pe.compress_resources = -1;
|
o->win32_pe.compress_resources = -1;
|
||||||
for (unsigned i = 0; i < HIGH(opt->w32pe.compress_rt); i++)
|
for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++)
|
||||||
opt->w32pe.compress_rt[i] = -1;
|
o->win32_pe.compress_rt[i] = -1;
|
||||||
opt->w32pe.compress_rt[24] = false; // 24 == RT_MANIFEST
|
o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
|
||||||
o->w32pe.strip_relocs = -1;
|
o->win32_pe.strip_loadconf = -1;
|
||||||
|
o->win32_pe.strip_relocs = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct options_t global_options;
|
static struct options_t global_options;
|
||||||
@@ -92,7 +95,7 @@ static int exit_code = EXIT_OK;
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
static void do_exit(void) __attribute__((noreturn));
|
static void do_exit(void) __attribute__((__noreturn__));
|
||||||
#endif
|
#endif
|
||||||
static void do_exit(void)
|
static void do_exit(void)
|
||||||
{
|
{
|
||||||
@@ -206,7 +209,7 @@ void e_envopt(const char *n)
|
|||||||
#endif /* defined(OPTIONS_VAR) */
|
#endif /* defined(OPTIONS_VAR) */
|
||||||
|
|
||||||
|
|
||||||
RETSIGTYPE SIGTYPEENTRY e_sighandler(int signum)
|
void __acc_cdecl_sighandler e_sighandler(int signum)
|
||||||
{
|
{
|
||||||
UNUSED(signum);
|
UNUSED(signum);
|
||||||
e_exit(EXIT_FATAL);
|
e_exit(EXIT_FATAL);
|
||||||
@@ -278,7 +281,7 @@ static void set_term(FILE *f)
|
|||||||
if (f)
|
if (f)
|
||||||
con_term = f;
|
con_term = f;
|
||||||
else
|
else
|
||||||
con_term = isafile(STDIN_FILENO) ? stderr : stdout;
|
con_term = acc_isatty(STDIN_FILENO) ? stderr : stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -319,7 +322,7 @@ static void set_output_name(const char *n, bool allow_m)
|
|||||||
fprintf(stderr,"%s: missing output name\n",argv0);
|
fprintf(stderr,"%s: missing output name\n",argv0);
|
||||||
e_usage();
|
e_usage();
|
||||||
}
|
}
|
||||||
if (strlen(n) >= PATH_MAX - 4)
|
if (strlen(n) >= ACC_FN_PATH_MAX - 4)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s: output name too long\n",argv0);
|
fprintf(stderr,"%s: output name too long\n",argv0);
|
||||||
e_usage();
|
e_usage();
|
||||||
@@ -342,12 +345,12 @@ static void set_script_name(const char *n, bool allow_m)
|
|||||||
fprintf(stderr,"%s: missing script name\n",argv0);
|
fprintf(stderr,"%s: missing script name\n",argv0);
|
||||||
e_usage();
|
e_usage();
|
||||||
}
|
}
|
||||||
if (strlen(n) >= (size_t)opt->unix.SCRIPT_MAX - 3)
|
if (strlen(n) >= (size_t)opt->o_unix.SCRIPT_MAX - 3)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s: script name too long\n",argv0);
|
fprintf(stderr,"%s: script name too long\n",argv0);
|
||||||
e_usage();
|
e_usage();
|
||||||
}
|
}
|
||||||
opt->unix.script_name = n;
|
opt->o_unix.script_name = n;
|
||||||
done_script_name++;
|
done_script_name++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +404,7 @@ char* prepare_shortopts(char *buf, const char *n,
|
|||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
int getoptvar(T *var, T minval, T maxval)
|
int getoptvar(T *var, const T minval, const T maxval)
|
||||||
{
|
{
|
||||||
const char *p = mfx_optarg;
|
const char *p = mfx_optarg;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
@@ -528,6 +531,7 @@ static int do_option(int optc, const char *arg)
|
|||||||
opt->method = -1;
|
opt->method = -1;
|
||||||
opt->all_filters = true;
|
opt->all_filters = true;
|
||||||
opt->filter = -1;
|
opt->filter = -1;
|
||||||
|
opt->crp.m_size = 999999;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case 900: // --best
|
case 900: // --best
|
||||||
if (!set_method(-1, 10))
|
if (!set_method(-1, 10))
|
||||||
@@ -592,7 +596,7 @@ static int do_option(int optc, const char *arg)
|
|||||||
getoptvar(&opt->crp.max_match, 16u, ~0u);
|
getoptvar(&opt->crp.max_match, 16u, ~0u);
|
||||||
break;
|
break;
|
||||||
case 537:
|
case 537:
|
||||||
if (getoptvar(&opt->crp.m_size, 10000u, (unsigned)999999u) != 0)
|
if (getoptvar(&opt->crp.m_size, 10000u, 999999u) != 0)
|
||||||
e_optval("--crp-ms=");
|
e_optval("--crp-ms=");
|
||||||
break;
|
break;
|
||||||
// backup
|
// backup
|
||||||
@@ -645,58 +649,71 @@ static int do_option(int optc, const char *arg)
|
|||||||
break;
|
break;
|
||||||
//
|
//
|
||||||
case 600:
|
case 600:
|
||||||
opt->dos.force_stub = true;
|
opt->dos_exe.force_stub = true;
|
||||||
break;
|
break;
|
||||||
case 601:
|
case 601:
|
||||||
opt->dos.no_reloc = true;
|
opt->dos_exe.no_reloc = true;
|
||||||
break;
|
break;
|
||||||
case 610:
|
case 610:
|
||||||
opt->djgpp2.coff = true;
|
opt->djgpp2_coff.coff = true;
|
||||||
break;
|
break;
|
||||||
case 620:
|
case 620:
|
||||||
opt->wcle.le = true;
|
opt->watcom_le.le = true;
|
||||||
break;
|
break;
|
||||||
case 630:
|
case 630:
|
||||||
opt->w32pe.compress_exports = 1;
|
opt->win32_pe.compress_exports = 1;
|
||||||
getoptvar(&opt->w32pe.compress_exports, 0, 1);
|
getoptvar(&opt->win32_pe.compress_exports, 0, 1);
|
||||||
//printf("compress_exports: %d\n", opt->w32pe.compress_exports);
|
//printf("compress_exports: %d\n", opt->win32_pe.compress_exports);
|
||||||
break;
|
break;
|
||||||
case 631:
|
case 631:
|
||||||
opt->w32pe.compress_icons = 1;
|
opt->win32_pe.compress_icons = 1;
|
||||||
getoptvar(&opt->w32pe.compress_icons, 0, 2);
|
getoptvar(&opt->win32_pe.compress_icons, 0, 2);
|
||||||
//printf("compress_icons: %d\n", opt->w32pe.compress_icons);
|
//printf("compress_icons: %d\n", opt->win32_pe.compress_icons);
|
||||||
break;
|
break;
|
||||||
case 632:
|
case 632:
|
||||||
opt->w32pe.compress_resources = true;
|
opt->win32_pe.compress_resources = true;
|
||||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||||
opt->w32pe.compress_resources = false;
|
opt->win32_pe.compress_resources = false;
|
||||||
//printf("compress_resources: %d\n", opt->w32pe.compress_resources);
|
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
|
||||||
break;
|
break;
|
||||||
case 633:
|
case 633:
|
||||||
opt->w32pe.strip_relocs = 1;
|
opt->win32_pe.strip_loadconf = 1;
|
||||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||||
opt->w32pe.strip_relocs = 0;
|
opt->win32_pe.strip_loadconf = 0;
|
||||||
//printf("strip_relocs: %d\n", opt->w32pe.strip_relocs);
|
//printf("strip_loadconf: %d\n", opt->win32_pe.strip_loadconf);
|
||||||
|
break;
|
||||||
|
case 634:
|
||||||
|
opt->win32_pe.strip_relocs = 1;
|
||||||
|
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||||
|
opt->win32_pe.strip_relocs = 0;
|
||||||
|
//printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
|
||||||
break;
|
break;
|
||||||
case 650:
|
case 650:
|
||||||
opt->tos.split_segments = true;
|
opt->atari_tos.split_segments = true;
|
||||||
break;
|
break;
|
||||||
case 660:
|
case 660:
|
||||||
getoptvar(&opt->unix.blocksize, 8192u, ~0u);
|
getoptvar(&opt->o_unix.blocksize, 8192u, ~0u);
|
||||||
break;
|
break;
|
||||||
case 661:
|
case 661:
|
||||||
opt->unix.force_execve = true;
|
opt->o_unix.force_execve = true;
|
||||||
break;
|
break;
|
||||||
case 662:
|
case 662:
|
||||||
opt->unix.script_name = "/usr/local/lib/upx/upxX";
|
opt->o_unix.script_name = "/usr/local/lib/upx/upxX";
|
||||||
if (mfx_optarg && mfx_optarg[0])
|
if (mfx_optarg && mfx_optarg[0])
|
||||||
set_script_name(mfx_optarg,1);
|
set_script_name(mfx_optarg,1);
|
||||||
break;
|
break;
|
||||||
case 663:
|
case 663:
|
||||||
opt->unix.ptinterp = true;
|
opt->o_unix.ptinterp = true;
|
||||||
break;
|
break;
|
||||||
case 670:
|
case 670:
|
||||||
opt->ps1.no_align = true;
|
opt->ps1_exe.boot_only = true;
|
||||||
|
break;
|
||||||
|
case 671:
|
||||||
|
opt->ps1_exe.no_align = true;
|
||||||
|
opt->ps1_exe.boot_only = false;
|
||||||
|
break;
|
||||||
|
case 672:
|
||||||
|
opt->ps1_exe.do_8bit = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\0':
|
case '\0':
|
||||||
@@ -724,6 +741,7 @@ static const struct mfx_option longopts[] =
|
|||||||
{"decompress", 0, 0, 'd'}, // decompress
|
{"decompress", 0, 0, 'd'}, // decompress
|
||||||
{"fast", 0x10, 0, '1'}, // compress faster
|
{"fast", 0x10, 0, '1'}, // compress faster
|
||||||
{"fileinfo", 0x10, 0, 902}, // display info about file
|
{"fileinfo", 0x10, 0, 902}, // display info about file
|
||||||
|
{"file-info", 0x10, 0, 902}, // display info about file
|
||||||
{"help", 0, 0, 'h'+256}, // give help
|
{"help", 0, 0, 'h'+256}, // give help
|
||||||
{"license", 0, 0, 'L'}, // display software license
|
{"license", 0, 0, 'L'}, // display software license
|
||||||
{"list", 0, 0, 'l'}, // list compressed exe
|
{"list", 0, 0, 'l'}, // list compressed exe
|
||||||
@@ -812,9 +830,12 @@ static const struct mfx_option longopts[] =
|
|||||||
{"compress-exports", 2, 0, 630},
|
{"compress-exports", 2, 0, 630},
|
||||||
{"compress-icons", 2, 0, 631},
|
{"compress-icons", 2, 0, 631},
|
||||||
{"compress-resources", 2, 0, 632},
|
{"compress-resources", 2, 0, 632},
|
||||||
{"strip-relocs", 2, 0, 633},
|
{"strip-loadconf", 0x12, 0, 633},
|
||||||
|
{"strip-relocs", 0x12, 0, 634},
|
||||||
// ps1/exe
|
// ps1/exe
|
||||||
{"no-align", 0x10, 0, 670},
|
{"boot-only", 0x10, 0, 670},
|
||||||
|
{"no-align", 0x10, 0, 671},
|
||||||
|
{"8-bit", 0x10, 0, 672},
|
||||||
|
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
@@ -878,11 +899,21 @@ static const struct mfx_option longopts[] =
|
|||||||
{"mono", 0, 0, 513},
|
{"mono", 0, 0, 513},
|
||||||
{"color", 0, 0, 514},
|
{"color", 0, 0, 514},
|
||||||
|
|
||||||
|
// compression runtime parameters
|
||||||
|
{"crp-cf", 0x31, 0, 531},
|
||||||
|
{"crp-sl", 0x31, 0, 532},
|
||||||
|
{"crp-hl", 0x31, 0, 533},
|
||||||
|
{"crp-pl", 0x31, 0, 534},
|
||||||
|
{"crp-mo", 0x31, 0, 535},
|
||||||
|
{"crp-mm", 0x31, 0, 536},
|
||||||
|
{"crp-ms", 0x31, 0, 537},
|
||||||
|
|
||||||
// win32/pe
|
// win32/pe
|
||||||
{"compress-exports", 2, 0, 630},
|
{"compress-exports", 2, 0, 630},
|
||||||
{"compress-icons", 2, 0, 631},
|
{"compress-icons", 2, 0, 631},
|
||||||
{"compress-resources", 2, 0, 632},
|
{"compress-resources", 2, 0, 632},
|
||||||
{"strip-relocs", 2, 0, 633},
|
{"strip-loadconf", 0x12, 0, 633},
|
||||||
|
{"strip-relocs", 0x12, 0, 634},
|
||||||
|
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
@@ -997,87 +1028,47 @@ static void first_options(int argc, char **argv)
|
|||||||
// assert a sane architecture and compiler
|
// assert a sane architecture and compiler
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
#define ACC_WANT_ACC_CHK_CH 1
|
||||||
|
#undef ACCCHK_ASSERT
|
||||||
|
#include "miniacc.h"
|
||||||
|
|
||||||
void upx_sanity_check(void)
|
void upx_sanity_check(void)
|
||||||
{
|
{
|
||||||
COMPILE_TIME_ASSERT(sizeof(char) == 1);
|
#define ACC_WANT_ACC_CHK_CH 1
|
||||||
COMPILE_TIME_ASSERT(sizeof(short) == 2);
|
#undef ACCCHK_ASSERT
|
||||||
COMPILE_TIME_ASSERT(sizeof(int) == 4);
|
#define ACCCHK_ASSERT(expr) ACC_COMPILE_TIME_ASSERT(expr)
|
||||||
COMPILE_TIME_ASSERT(sizeof(long) >= 4);
|
#include "miniacc.h"
|
||||||
COMPILE_TIME_ASSERT(sizeof(void *) >= 4);
|
#undef ACCCHK_ASSERT
|
||||||
COMPILE_TIME_ASSERT(sizeof(long) >= sizeof(void *));
|
|
||||||
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(upx_int64l) >= 8);
|
COMPILE_TIME_ASSERT(sizeof(char) == 1)
|
||||||
COMPILE_TIME_ASSERT(sizeof(upx_int64l) >= sizeof(long));
|
COMPILE_TIME_ASSERT(sizeof(short) == 2)
|
||||||
COMPILE_TIME_ASSERT(sizeof(upx_int64l) == sizeof(upx_uint64l));
|
COMPILE_TIME_ASSERT(sizeof(int) == 4)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(long) >= 4)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(void *) >= 4)
|
||||||
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(off_t) >= sizeof(long));
|
COMPILE_TIME_ASSERT(sizeof(off_t) >= sizeof(long))
|
||||||
COMPILE_TIME_ASSERT(((off_t) -1) < 0);
|
COMPILE_TIME_ASSERT(((off_t) -1) < 0)
|
||||||
COMPILE_TIME_ASSERT(sizeof(ptrdiff_t) >= sizeof(int));
|
|
||||||
COMPILE_TIME_ASSERT(((ptrdiff_t) -1) < 0);
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(size_t) >= sizeof(int));
|
|
||||||
COMPILE_TIME_ASSERT(((size_t) -1) > 0);
|
|
||||||
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(BE16) == 2);
|
COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
|
||||||
COMPILE_TIME_ASSERT(sizeof(BE32) == 4);
|
COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
|
||||||
COMPILE_TIME_ASSERT(sizeof(LE16) == 2);
|
COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
|
||||||
COMPILE_TIME_ASSERT(sizeof(LE32) == 4);
|
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
COMPILE_TIME_ASSERT_ALIGNOF(BE16, char)
|
||||||
COMPILE_TIME_ASSERT(__alignof__(BE16) == 1);
|
COMPILE_TIME_ASSERT_ALIGNOF(BE32, char)
|
||||||
COMPILE_TIME_ASSERT(__alignof__(BE32) == 1);
|
COMPILE_TIME_ASSERT_ALIGNOF(LE16, char)
|
||||||
COMPILE_TIME_ASSERT(__alignof__(LE16) == 1);
|
COMPILE_TIME_ASSERT_ALIGNOF(LE32, char)
|
||||||
COMPILE_TIME_ASSERT(__alignof__(LE32) == 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(__WATCOMC__)
|
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
|
||||||
struct align_assertion_1a_t
|
|
||||||
{
|
|
||||||
struct foo_t {
|
|
||||||
char c1;
|
|
||||||
LE16 v[4];
|
|
||||||
} __attribute_packed;
|
|
||||||
foo_t d[3];
|
|
||||||
} __attribute_packed;
|
|
||||||
struct align_assertion_1b_t
|
|
||||||
{
|
|
||||||
struct foo_t {
|
|
||||||
char c1;
|
|
||||||
char v[4*2];
|
|
||||||
} __attribute_packed;
|
|
||||||
foo_t d[3];
|
|
||||||
} __attribute_packed;
|
|
||||||
struct align_assertion_2a_t
|
|
||||||
{
|
|
||||||
struct foo_t {
|
|
||||||
char c1;
|
|
||||||
LE32 v[4];
|
|
||||||
} __attribute_packed;
|
|
||||||
foo_t d[3];
|
|
||||||
} __attribute_packed;
|
|
||||||
struct align_assertion_2b_t
|
|
||||||
{
|
|
||||||
struct foo_t {
|
|
||||||
char c1;
|
|
||||||
char v[4*4];
|
|
||||||
} __attribute_packed;
|
|
||||||
foo_t d[3];
|
|
||||||
} __attribute_packed;
|
|
||||||
|
|
||||||
//printf("%d\n", (int) sizeof(align_assertion_1a_t));
|
|
||||||
//printf("%d\n", (int) sizeof(align_assertion_1b_t));
|
|
||||||
//printf("%d\n", (int) sizeof(align_assertion_2a_t));
|
|
||||||
//printf("%d\n", (int) sizeof(align_assertion_2b_t));
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(align_assertion_1a_t) == sizeof(align_assertion_1b_t));
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == sizeof(align_assertion_2b_t));
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(align_assertion_1a_t) == 3*9);
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(align_assertion_2a_t) == 3*17);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1);
|
|
||||||
assert(strlen(UPX_VERSION_STRING4) == 4);
|
assert(strlen(UPX_VERSION_STRING4) == 4);
|
||||||
assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0);
|
assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0);
|
||||||
|
|
||||||
|
#if 1
|
||||||
const unsigned char dd[4] = { 0xff, 0xfe, 0xfd, 0xfc };
|
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(dd) == 0xfffe);
|
||||||
assert(get_be16_signed(dd) == -2);
|
assert(get_be16_signed(dd) == -2);
|
||||||
assert(get_be24(dd) == 0xfffefd);
|
assert(get_be24(dd) == 0xfffefd);
|
||||||
@@ -1094,6 +1085,7 @@ void upx_sanity_check(void)
|
|||||||
assert(find_le16(dd, sizeof(dd), 0xfeff) == 0);
|
assert(find_le16(dd, sizeof(dd), 0xfeff) == 0);
|
||||||
assert(find_be32(dd, sizeof(dd), 0xfffefdfc) == 0);
|
assert(find_be32(dd, sizeof(dd), 0xfffefdfc) == 0);
|
||||||
assert(find_le32(dd, sizeof(dd), 0xfcfdfeff) == 0);
|
assert(find_le32(dd, sizeof(dd), 0xfcfdfeff) == 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1103,7 +1095,7 @@ void upx_sanity_check(void)
|
|||||||
|
|
||||||
#if !defined(WITH_GUI)
|
#if !defined(WITH_GUI)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int __acc_cdecl_main main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static char default_argv0[] = "upx";
|
static char default_argv0[] = "upx";
|
||||||
@@ -1113,15 +1105,12 @@ int main(int argc, char *argv[])
|
|||||||
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
|
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
|
||||||
putenv("LFN=y");
|
putenv("LFN=y");
|
||||||
#endif
|
#endif
|
||||||
#if defined(__EMX__)
|
|
||||||
_response(&argc,&argv);
|
|
||||||
_wildcard(&argc,&argv);
|
|
||||||
#endif
|
|
||||||
#if defined(__MINT__)
|
#if defined(__MINT__)
|
||||||
__binmode(1);
|
__binmode(1);
|
||||||
__set_binmode(stdout, 0);
|
__set_binmode(stdout, 0);
|
||||||
__set_binmode(stderr, 0);
|
__set_binmode(stderr, 0);
|
||||||
#endif
|
#endif
|
||||||
|
acc_wildargv(&argc, &argv);
|
||||||
|
|
||||||
upx_sanity_check();
|
upx_sanity_check();
|
||||||
init_options(opt);
|
init_options(opt);
|
||||||
@@ -1129,7 +1118,7 @@ int main(int argc, char *argv[])
|
|||||||
if (!argv[0] || !argv[0][0])
|
if (!argv[0] || !argv[0][0])
|
||||||
argv[0] = default_argv0;
|
argv[0] = default_argv0;
|
||||||
argv0 = argv[0];
|
argv0 = argv[0];
|
||||||
#if defined(DOSISH)
|
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
{
|
{
|
||||||
char *prog = fn_basename(argv0);
|
char *prog = fn_basename(argv0);
|
||||||
char *p;
|
char *p;
|
||||||
@@ -1150,6 +1139,8 @@ int main(int argc, char *argv[])
|
|||||||
#else
|
#else
|
||||||
progname = fn_basename(argv0);
|
progname = fn_basename(argv0);
|
||||||
#endif
|
#endif
|
||||||
|
while (progname[0] == '.' && progname[1] == '/' && progname[2])
|
||||||
|
progname += 2;
|
||||||
|
|
||||||
set_term(stderr);
|
set_term(stderr);
|
||||||
|
|
||||||
@@ -1188,7 +1179,7 @@ int main(int argc, char *argv[])
|
|||||||
i = get_options(argc,argv);
|
i = get_options(argc,argv);
|
||||||
assert(i <= argc);
|
assert(i <= argc);
|
||||||
|
|
||||||
set_term(0);
|
set_term(NULL);
|
||||||
// cmdline_cmd = opt->cmd;
|
// cmdline_cmd = opt->cmd;
|
||||||
switch (opt->cmd)
|
switch (opt->cmd)
|
||||||
{
|
{
|
||||||
@@ -1249,27 +1240,19 @@ int main(int argc, char *argv[])
|
|||||||
set_term(stdout);
|
set_term(stdout);
|
||||||
do_files(i,argc,argv);
|
do_files(i,argc,argv);
|
||||||
|
|
||||||
#if 1 && (UPX_VERSION_HEX < 0x020000)
|
#if 0 && (UPX_VERSION_HEX < 0x020000)
|
||||||
{
|
{
|
||||||
FILE *f = stdout;
|
FILE *f = stdout;
|
||||||
int fg = con_fg(f,FG_RED);
|
int fg = con_fg(f,FG_RED);
|
||||||
con_fprintf(f,"\nWARNING: this is an unstable beta version - use for testing only! Really.\n");
|
con_fprintf(f,"\nWARNING: this is an unstable beta version - use for testing only! Really.\n");
|
||||||
fg = con_fg(f,fg);
|
fg = con_fg(f,fg);
|
||||||
}
|
UNUSED(fg);
|
||||||
#endif
|
|
||||||
#if 0 && !defined(WITH_NRV)
|
|
||||||
{
|
|
||||||
FILE *f = stdout;
|
|
||||||
int fg = con_fg(f,FG_GREEN);
|
|
||||||
con_fprintf(f,"\nINFO: this version does not use the NRV library - compression ratio is worse\n");
|
|
||||||
fg = con_fg(f,fg);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 && defined(__GLIBC__)
|
#if 0 && defined(__GLIBC__)
|
||||||
//malloc_stats();
|
//malloc_stats();
|
||||||
#endif
|
#endif
|
||||||
do_exit();
|
|
||||||
return exit_code;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+143
-51
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -34,11 +34,38 @@
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
MemBuffer::MemBuffer(unsigned size) :
|
static int use_mcheck = -1;
|
||||||
ptr(NULL), alloc_ptr(NULL), alloc_size(0)
|
|
||||||
|
static int mcheck_init()
|
||||||
{
|
{
|
||||||
if (size > 0)
|
if (use_mcheck < 0)
|
||||||
alloc(size, 0);
|
{
|
||||||
|
use_mcheck = 1;
|
||||||
|
#if defined(WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
|
||||||
|
if (RUNNING_ON_VALGRIND)
|
||||||
|
{
|
||||||
|
//fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n");
|
||||||
|
use_mcheck = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return use_mcheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
MemBuffer::MemBuffer() :
|
||||||
|
b(NULL), b_size(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MemBuffer::MemBuffer(unsigned size) :
|
||||||
|
b(NULL), b_size(0)
|
||||||
|
{
|
||||||
|
alloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -49,59 +76,124 @@ MemBuffer::~MemBuffer()
|
|||||||
|
|
||||||
void MemBuffer::dealloc()
|
void MemBuffer::dealloc()
|
||||||
{
|
{
|
||||||
if (alloc_ptr)
|
if (b)
|
||||||
::free(alloc_ptr);
|
|
||||||
alloc_ptr = ptr = NULL;
|
|
||||||
alloc_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned MemBuffer::getSize() const
|
|
||||||
{
|
|
||||||
if (!alloc_ptr)
|
|
||||||
return 0;
|
|
||||||
unsigned size = alloc_size - (ptr - alloc_ptr);
|
|
||||||
assert((int)size > 0);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MemBuffer::alloc(unsigned size, unsigned base_offset)
|
|
||||||
{
|
|
||||||
// NOTE: we don't automaticlly free a used buffer
|
|
||||||
assert(alloc_ptr == NULL);
|
|
||||||
assert((int)size > 0);
|
|
||||||
size = base_offset + size;
|
|
||||||
alloc_ptr = (unsigned char *) malloc(size);
|
|
||||||
if (!alloc_ptr)
|
|
||||||
{
|
{
|
||||||
//throw bad_alloc();
|
checkState();
|
||||||
throwCantPack("out of memory");
|
if (use_mcheck)
|
||||||
//exit(1);
|
{
|
||||||
|
// remove magic constants
|
||||||
|
set_be32(b - 8, 0);
|
||||||
|
set_be32(b - 4, 0);
|
||||||
|
set_be32(b + b_size, 0);
|
||||||
|
set_be32(b + b_size + 4, 0);
|
||||||
|
//
|
||||||
|
::free(b - 8);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
::free(b);
|
||||||
|
b = NULL;
|
||||||
|
b_size = 0;
|
||||||
}
|
}
|
||||||
alloc_size = size;
|
else
|
||||||
ptr = alloc_ptr + base_offset;
|
assert(b_size == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MemBuffer::allocForCompression(unsigned uncompressed_size, unsigned extra)
|
||||||
|
{
|
||||||
|
assert((int)uncompressed_size > 0);
|
||||||
|
assert((int)extra >= 0);
|
||||||
|
unsigned size = uncompressed_size + uncompressed_size/8 + 256 + extra;
|
||||||
|
alloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra)
|
||||||
|
{
|
||||||
|
assert((int)uncompressed_size > 0);
|
||||||
|
assert((int)extra >= 0);
|
||||||
|
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)
|
||||||
|
size += 3;
|
||||||
|
#endif
|
||||||
|
alloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MemBuffer::fill(unsigned off, unsigned len, int value)
|
||||||
|
{
|
||||||
|
checkState();
|
||||||
|
assert((int)off >= 0);
|
||||||
|
assert((int)len >= 0);
|
||||||
|
assert(off <= b_size);
|
||||||
|
assert(len <= b_size);
|
||||||
|
assert(off + len <= b_size);
|
||||||
|
if (len > 0)
|
||||||
|
memset(b + off, value, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#define PTR(p) ((unsigned) ((acc_uintptr_t)(p) & 0xffffffff))
|
||||||
|
#define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb)
|
||||||
|
#define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001)
|
||||||
|
|
||||||
|
unsigned MemBuffer::global_alloc_counter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void MemBuffer::checkState() const
|
||||||
|
{
|
||||||
|
if (!b)
|
||||||
|
throwInternalError("block not allocated");
|
||||||
|
if (use_mcheck)
|
||||||
|
{
|
||||||
|
if (get_be32(b - 4) != MAGIC1(b))
|
||||||
|
throwInternalError("memory clobbered before allocated block 1");
|
||||||
|
if (get_be32(b - 8) != b_size)
|
||||||
|
throwInternalError("memory clobbered before allocated block 2");
|
||||||
|
if (get_be32(b + b_size) != MAGIC2(b))
|
||||||
|
throwInternalError("memory clobbered past end of allocated block");
|
||||||
|
}
|
||||||
|
assert((int)b_size > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MemBuffer::alloc(unsigned size)
|
void MemBuffer::alloc(unsigned size)
|
||||||
{
|
{
|
||||||
alloc(size, 0);
|
if (use_mcheck < 0)
|
||||||
}
|
mcheck_init();
|
||||||
|
|
||||||
|
// NOTE: we don't automatically free a used buffer
|
||||||
void MemBuffer::allocForCompression(unsigned uncompressed_size)
|
assert(b == NULL);
|
||||||
{
|
assert(b_size == 0);
|
||||||
assert((int)uncompressed_size > 0);
|
//
|
||||||
alloc(uncompressed_size + uncompressed_size/8 + 256, 0);
|
assert((int)size > 0);
|
||||||
}
|
unsigned total = use_mcheck ? size + 16 : size;
|
||||||
|
assert((int)total > 0);
|
||||||
|
unsigned char *p = (unsigned char *) malloc(total);
|
||||||
void MemBuffer::allocForUncompression(unsigned uncompressed_size)
|
if (!p)
|
||||||
{
|
{
|
||||||
assert((int)uncompressed_size > 0);
|
//throw bad_alloc();
|
||||||
//alloc(uncompressed_size + 3 + 512, 0); // 512 safety bytes
|
throw OutOfMemoryException("out of memory");
|
||||||
alloc(uncompressed_size + 3, 0); // 3 bytes for asm_fast decompresion
|
//exit(1);
|
||||||
|
}
|
||||||
|
b_size = size;
|
||||||
|
if (use_mcheck)
|
||||||
|
{
|
||||||
|
b = p + 8;
|
||||||
|
// store magic constants to detect buffer overruns
|
||||||
|
set_be32(b - 8, b_size);
|
||||||
|
set_be32(b - 4, MAGIC1(b));
|
||||||
|
set_be32(b + b_size, MAGIC2(b));
|
||||||
|
set_be32(b + b_size + 4, global_alloc_counter++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
b = p ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -37,46 +37,41 @@
|
|||||||
class MemBuffer
|
class MemBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MemBuffer(unsigned size=0);
|
MemBuffer();
|
||||||
|
MemBuffer(unsigned size);
|
||||||
~MemBuffer();
|
~MemBuffer();
|
||||||
|
|
||||||
void alloc(unsigned size);
|
void alloc(unsigned size);
|
||||||
void allocForCompression(unsigned uncompressed_size);
|
void allocForCompression(unsigned uncompressed_size, unsigned extra=0);
|
||||||
void allocForUncompression(unsigned uncompressed_size);
|
void allocForUncompression(unsigned uncompressed_size, unsigned extra=0);
|
||||||
|
|
||||||
void dealloc();
|
void dealloc();
|
||||||
|
|
||||||
const unsigned char *getBuf() const { return ptr; }
|
void checkState() const;
|
||||||
unsigned getSize() const;
|
|
||||||
|
|
||||||
operator unsigned char * () { return ptr; }
|
unsigned getSize() const { return b_size; }
|
||||||
//operator const unsigned char * () const { return ptr; }
|
|
||||||
|
|
||||||
void *getVoidPtr() { return (void *) ptr; }
|
operator unsigned char * () { return b; }
|
||||||
const void *getVoidPtr() const { return (const void *) ptr; }
|
//operator const unsigned char * () const { return b; }
|
||||||
|
void *getVoidPtr() { return (void *) b; }
|
||||||
|
const void *getVoidPtr() const { return (const void *) b; }
|
||||||
|
|
||||||
|
void fill(unsigned off, unsigned len, int value);
|
||||||
|
void clear(unsigned off, unsigned len) { fill(off, len, 0); }
|
||||||
|
void clear() { fill(0, b_size, 0); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void alloc(unsigned size, unsigned base_offset);
|
unsigned char *b;
|
||||||
|
unsigned b_size;
|
||||||
|
|
||||||
protected:
|
static unsigned global_alloc_counter;
|
||||||
unsigned char *ptr;
|
|
||||||
unsigned char *alloc_ptr;
|
|
||||||
unsigned alloc_size;
|
|
||||||
|
|
||||||
private:
|
|
||||||
// disable copy and assignment
|
// disable copy and assignment
|
||||||
MemBuffer(MemBuffer const &); // {}
|
MemBuffer(const MemBuffer &); // {}
|
||||||
MemBuffer& operator= (MemBuffer const &); // { return *this; }
|
MemBuffer& operator= (const MemBuffer &); // { return *this; }
|
||||||
|
|
||||||
// disable dynamic allocation
|
// disable dynamic allocation
|
||||||
#ifndef new
|
DISABLE_NEW_DELETE
|
||||||
static void *operator new (size_t); // {}
|
|
||||||
static void *operator new[] (size_t); // {}
|
|
||||||
#endif
|
|
||||||
#ifndef delete
|
|
||||||
//static void operator delete (void *) {}
|
|
||||||
//static void operator delete[] (void *) {}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|||||||
+4774
File diff suppressed because it is too large
Load Diff
+25
-13
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -88,7 +88,7 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
|
|||||||
// This hack is needed, otherwise error messages may get lost
|
// This hack is needed, otherwise error messages may get lost
|
||||||
// when the cursor is not yet at the bottom of the screen.
|
// when the cursor is not yet at the bottom of the screen.
|
||||||
// At least I can use some colors then...
|
// At least I can use some colors then...
|
||||||
bool c = isatty(STDERR_FILENO) ? 1 : 0;
|
bool c = acc_isatty(STDERR_FILENO) ? 1 : 0;
|
||||||
|
|
||||||
int fg = con_fg(stderr,FG_BRTRED);
|
int fg = con_fg(stderr,FG_BRTRED);
|
||||||
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"%s: ", progname);
|
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"%s: ", progname);
|
||||||
@@ -103,23 +103,35 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
|
|||||||
fg = con_fg(stderr,fg);
|
fg = con_fg(stderr,fg);
|
||||||
|
|
||||||
UNUSED(is_warning);
|
UNUSED(is_warning);
|
||||||
|
UNUSED(fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printErr(const char *iname, const Throwable *e)
|
void printErr(const char *iname, const Throwable *e)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
size_t l;
|
||||||
|
|
||||||
upx_snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e)));
|
upx_snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e).name()));
|
||||||
if (e->getMsg())
|
l = strlen(buf);
|
||||||
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),": %s", e->getMsg());
|
if (l < sizeof(buf) && e->getMsg())
|
||||||
if (e->getErrno())
|
upx_snprintf(buf+l, sizeof(buf)-l, ": %s", e->getMsg());
|
||||||
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),": %s", strerror(e->getErrno()));
|
l = strlen(buf);
|
||||||
|
if (l < sizeof(buf) && e->getErrno()) {
|
||||||
|
upx_snprintf(buf+l, sizeof(buf)-l, ": %s", strerror(e->getErrno()));
|
||||||
|
#if 1
|
||||||
|
// some compilers (e.g. Borland C++) put a trailing '\n'
|
||||||
|
// into strerror() result
|
||||||
|
l = strlen(buf);
|
||||||
|
while (l-- > 0 && (buf[l] == '\n' || buf[l] == ' '))
|
||||||
|
buf[l] = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
pr_error(iname,buf,e->isWarning());
|
pr_error(iname,buf,e->isWarning());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printErr(const char *iname, const char *format, ...)
|
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
@@ -132,7 +144,7 @@ void printErr(const char *iname, const char *format, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printWarn(const char *iname, const char *format, ...)
|
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
@@ -189,7 +201,7 @@ void infoHeader()
|
|||||||
info_header = 0;
|
info_header = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void infoHeader(const char *format, ...)
|
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||||
{
|
{
|
||||||
if (opt->info_mode <= 0)
|
if (opt->info_mode <= 0)
|
||||||
return;
|
return;
|
||||||
@@ -203,7 +215,7 @@ void infoHeader(const char *format, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void info(const char *format, ...)
|
void __acc_cdecl_va info(const char *format, ...)
|
||||||
{
|
{
|
||||||
if (opt->info_mode <= 0)
|
if (opt->info_mode <= 0)
|
||||||
return;
|
return;
|
||||||
@@ -218,7 +230,7 @@ void info(const char *format, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void infoWarning(const char *format, ...)
|
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||||
{
|
{
|
||||||
if (opt->info_mode <= 0)
|
if (opt->info_mode <= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
+40
-30
@@ -21,11 +21,22 @@
|
|||||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||||
|
|
||||||
|
|
||||||
#include "tailor.h"
|
|
||||||
|
#undef PROGNAME
|
||||||
|
#if 0
|
||||||
#ifndef EOF
|
#ifndef EOF
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
#define PROGNAME(x) (x)
|
||||||
|
#else
|
||||||
|
#include "conf.h"
|
||||||
|
static const char *my_progname(const char *argv0)
|
||||||
|
{
|
||||||
|
return progname ? progname : argv0;
|
||||||
|
}
|
||||||
|
#define PROGNAME(x) my_progname(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
|
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
|
||||||
@@ -54,8 +65,6 @@
|
|||||||
#define optind mfx_optind
|
#define optind mfx_optind
|
||||||
#define opterr mfx_opterr
|
#define opterr mfx_opterr
|
||||||
#define optopt mfx_optopt
|
#define optopt mfx_optopt
|
||||||
#define my_index strchr
|
|
||||||
#define my_strlen strlen
|
|
||||||
#undef BAD_OPTION
|
#undef BAD_OPTION
|
||||||
|
|
||||||
/* For communication from `getopt' to the caller.
|
/* For communication from `getopt' to the caller.
|
||||||
@@ -167,7 +176,7 @@ static int last_nonopt;
|
|||||||
|
|
||||||
static void exchange (char **argv)
|
static void exchange (char **argv)
|
||||||
{
|
{
|
||||||
char *temp, **first, **last;
|
char *temp; char **first, **last;
|
||||||
|
|
||||||
/* Reverse all the elements [first_nonopt, optind) */
|
/* Reverse all the elements [first_nonopt, optind) */
|
||||||
first = &argv[first_nonopt];
|
first = &argv[first_nonopt];
|
||||||
@@ -382,15 +391,10 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
int indfound = 0;
|
int indfound = 0;
|
||||||
int needexact = 0;
|
int needexact = 0;
|
||||||
|
|
||||||
#if defined(DOSISH)
|
|
||||||
/* allow `--option#value' because you cannout assign a '='
|
/* allow `--option#value' because you cannout assign a '='
|
||||||
to an environment variable under DOS command.com */
|
to an environment variable under DOS command.com */
|
||||||
while (*s && *s != '=' && * s != '#')
|
while (*s && *s != '=' && * s != '#')
|
||||||
s++;
|
s++;
|
||||||
#else
|
|
||||||
while (*s && *s != '=')
|
|
||||||
s++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Test all options for either exact match or abbreviated matches. */
|
/* Test all options for either exact match or abbreviated matches. */
|
||||||
for (p = longopts, option_index = 0; p->name;
|
for (p = longopts, option_index = 0; p->name;
|
||||||
@@ -399,7 +403,7 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
{
|
{
|
||||||
if (p->has_arg & 0x10)
|
if (p->has_arg & 0x10)
|
||||||
needexact = 1;
|
needexact = 1;
|
||||||
if ((unsigned) (s - nextchar) == my_strlen (p->name))
|
if ((unsigned) (s - nextchar) == strlen (p->name))
|
||||||
{
|
{
|
||||||
/* Exact match found. */
|
/* Exact match found. */
|
||||||
pfound = p;
|
pfound = p;
|
||||||
@@ -423,8 +427,8 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
{
|
{
|
||||||
if (opterr)
|
if (opterr)
|
||||||
fprintf (stderr, "%s: unrecognized option `%s'\n",
|
fprintf (stderr, "%s: unrecognized option `%s'\n",
|
||||||
argv[0], argv[optind]);
|
PROGNAME(argv[0]), argv[optind]);
|
||||||
nextchar += my_strlen (nextchar);
|
nextchar += strlen (nextchar);
|
||||||
optind++;
|
optind++;
|
||||||
return BAD_OPTION;
|
return BAD_OPTION;
|
||||||
}
|
}
|
||||||
@@ -432,8 +436,8 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
{
|
{
|
||||||
if (opterr)
|
if (opterr)
|
||||||
fprintf (stderr, "%s: option `%s' is ambiguous\n",
|
fprintf (stderr, "%s: option `%s' is ambiguous\n",
|
||||||
argv[0], argv[optind]);
|
PROGNAME(argv[0]), argv[optind]);
|
||||||
nextchar += my_strlen (nextchar);
|
nextchar += strlen (nextchar);
|
||||||
optind++;
|
optind++;
|
||||||
return BAD_OPTION;
|
return BAD_OPTION;
|
||||||
}
|
}
|
||||||
@@ -459,14 +463,14 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
/* --option */
|
/* --option */
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"%s: option `--%s' doesn't allow an argument\n",
|
"%s: option `--%s' doesn't allow an argument\n",
|
||||||
argv[0], pfound->name);
|
PROGNAME(argv[0]), pfound->name);
|
||||||
else
|
else
|
||||||
/* +option or -option */
|
/* +option or -option */
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"%s: option `%c%s' doesn't allow an argument\n",
|
"%s: option `%c%s' doesn't allow an argument\n",
|
||||||
argv[0], argv[optind - 1][0], pfound->name);
|
PROGNAME(argv[0]), argv[optind - 1][0], pfound->name);
|
||||||
}
|
}
|
||||||
nextchar += my_strlen (nextchar);
|
nextchar += strlen (nextchar);
|
||||||
return BAD_OPTION;
|
return BAD_OPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -482,13 +486,13 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
{
|
{
|
||||||
if (opterr)
|
if (opterr)
|
||||||
fprintf (stderr, "%s: option `--%s%s' requires an argument\n",
|
fprintf (stderr, "%s: option `--%s%s' requires an argument\n",
|
||||||
argv[0], pfound->name,
|
PROGNAME(argv[0]), pfound->name,
|
||||||
(pfound->has_arg & 0x20) ? "=" : "");
|
(pfound->has_arg & 0x20) ? "=" : "");
|
||||||
nextchar += my_strlen (nextchar);
|
nextchar += strlen (nextchar);
|
||||||
return optstring[0] == ':' ? ':' : BAD_OPTION;
|
return optstring[0] == ':' ? ':' : BAD_OPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nextchar += my_strlen (nextchar);
|
nextchar += strlen (nextchar);
|
||||||
if (longind != NULL)
|
if (longind != NULL)
|
||||||
*longind = option_index;
|
*longind = option_index;
|
||||||
if (pfound->flag)
|
if (pfound->flag)
|
||||||
@@ -506,31 +510,31 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
#ifdef GETOPT_COMPAT
|
#ifdef GETOPT_COMPAT
|
||||||
|| argv[optind][0] == '+'
|
|| argv[optind][0] == '+'
|
||||||
#endif /* GETOPT_COMPAT */
|
#endif /* GETOPT_COMPAT */
|
||||||
|| my_index (optstring, *nextchar) == NULL)
|
|| strchr (optstring, *nextchar) == NULL)
|
||||||
{
|
{
|
||||||
if (opterr)
|
if (opterr)
|
||||||
{
|
{
|
||||||
if (argv[optind][1] == '-')
|
if (argv[optind][1] == '-')
|
||||||
/* --option */
|
/* --option */
|
||||||
fprintf (stderr, "%s: unrecognized option `--%s'\n",
|
fprintf (stderr, "%s: unrecognized option `--%s'\n",
|
||||||
argv[0], nextchar);
|
PROGNAME(argv[0]), nextchar);
|
||||||
else
|
else
|
||||||
/* +option or -option */
|
/* +option or -option */
|
||||||
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
|
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
|
||||||
argv[0], argv[optind][0], nextchar);
|
PROGNAME(argv[0]), argv[optind][0], nextchar);
|
||||||
}
|
}
|
||||||
nextchar = empty_string;
|
nextchar = empty_string;
|
||||||
optind++;
|
optind++;
|
||||||
return BAD_OPTION;
|
return BAD_OPTION;
|
||||||
}
|
}
|
||||||
ambig = ambig;
|
(void) &ambig; /* UNUSED */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look at and handle the next option-character. */
|
/* Look at and handle the next option-character. */
|
||||||
|
|
||||||
{
|
{
|
||||||
char c = *nextchar++;
|
char c = *nextchar++;
|
||||||
const char *temp = my_index (optstring, c);
|
const char *temp = strchr (optstring, c);
|
||||||
|
|
||||||
/* Increment `optind' when we start to process its last character. */
|
/* Increment `optind' when we start to process its last character. */
|
||||||
if (*nextchar == '\0')
|
if (*nextchar == '\0')
|
||||||
@@ -543,12 +547,12 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
#if 0
|
#if 0
|
||||||
if (c < 040 || c >= 0177)
|
if (c < 040 || c >= 0177)
|
||||||
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
|
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
|
||||||
argv[0], c);
|
PROGNAME(argv[0]), c);
|
||||||
else
|
else
|
||||||
fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
|
fprintf (stderr, "%s: unrecognized option `-%c'\n", PROGNAME(argv[0]), c);
|
||||||
#else
|
#else
|
||||||
/* 1003.2 specifies the format of this message. */
|
/* 1003.2 specifies the format of this message. */
|
||||||
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
|
fprintf (stderr, "%s: illegal option -- %c\n", PROGNAME(argv[0]), c);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
optopt = c;
|
optopt = c;
|
||||||
@@ -584,11 +588,11 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
|||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
fprintf (stderr, "%s: option `-%c' requires an argument\n",
|
fprintf (stderr, "%s: option `-%c' requires an argument\n",
|
||||||
argv[0], c);
|
PROGNAME(argv[0]), c);
|
||||||
#else
|
#else
|
||||||
/* 1003.2 specifies the format of this message. */
|
/* 1003.2 specifies the format of this message. */
|
||||||
fprintf (stderr, "%s: option requires an argument -- %c\n",
|
fprintf (stderr, "%s: option requires an argument -- %c\n",
|
||||||
argv[0], c);
|
PROGNAME(argv[0]), c);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
optopt = c;
|
optopt = c;
|
||||||
@@ -694,3 +698,9 @@ main (argc, argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* TEST */
|
#endif /* TEST */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
vi:ts=4:et:nowrap
|
||||||
|
*/
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -19,7 +19,7 @@
|
|||||||
#define __MFX_GETOPT_H 1
|
#define __MFX_GETOPT_H 1
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
//extern "C" {
|
/* extern "C" { */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* For communication from `getopt' to the caller.
|
/* For communication from `getopt' to the caller.
|
||||||
@@ -96,7 +96,7 @@ int mfx_getopt_long(int argc, char **argv, const char *shortopts,
|
|||||||
const struct mfx_option *longopts, int *longind);
|
const struct mfx_option *longopts, int *longind);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
//}
|
/* } */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _GETOPT_H */
|
#endif /* __MFX_GETOPT_H */
|
||||||
|
|||||||
+16
-13
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -99,35 +99,38 @@ struct options_t {
|
|||||||
|
|
||||||
// options for various executable formats
|
// options for various executable formats
|
||||||
struct {
|
struct {
|
||||||
bool force_stub;
|
bool split_segments;
|
||||||
bool no_reloc;
|
} atari_tos;
|
||||||
} dos;
|
|
||||||
struct {
|
struct {
|
||||||
bool coff;
|
bool coff;
|
||||||
} djgpp2;
|
} djgpp2_coff;
|
||||||
struct {
|
struct {
|
||||||
|
bool force_stub;
|
||||||
|
bool no_reloc;
|
||||||
|
} dos_exe;
|
||||||
|
struct {
|
||||||
|
bool boot_only;
|
||||||
bool no_align;
|
bool no_align;
|
||||||
} ps1;
|
bool do_8bit;
|
||||||
struct {
|
} ps1_exe;
|
||||||
bool split_segments;
|
|
||||||
} tos;
|
|
||||||
struct {
|
struct {
|
||||||
unsigned blocksize;
|
unsigned blocksize;
|
||||||
bool force_execve; // force the linux/386 execve format
|
bool force_execve; // force the linux/386 execve format
|
||||||
bool ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
bool ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||||
enum { SCRIPT_MAX = 32 };
|
enum { SCRIPT_MAX = 32 };
|
||||||
const char *script_name;
|
const char *script_name;
|
||||||
} unix;
|
} o_unix;
|
||||||
struct {
|
struct {
|
||||||
bool le;
|
bool le;
|
||||||
} wcle;
|
} watcom_le;
|
||||||
struct {
|
struct {
|
||||||
int compress_exports;
|
int compress_exports;
|
||||||
int compress_icons;
|
int compress_icons;
|
||||||
int compress_resources;
|
int compress_resources;
|
||||||
signed char compress_rt[25]; // 25 == RT_LAST
|
signed char compress_rt[25]; // 25 == RT_LAST
|
||||||
|
int strip_loadconf;
|
||||||
int strip_relocs;
|
int strip_relocs;
|
||||||
} w32pe;
|
} win32_pe;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct options_t * volatile opt;
|
extern struct options_t * volatile opt;
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+3
-3
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
virtual int canUnpack();
|
virtual int canUnpack();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const unsigned getCallTrickOffset() const { return 0x100; }
|
virtual unsigned getCallTrickOffset() const { return 0x100; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int buildLoader(const Filter *ft);
|
virtual int buildLoader(const Filter *ft);
|
||||||
|
|||||||
+98
-68
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -32,11 +32,10 @@
|
|||||||
#include "packer.h"
|
#include "packer.h"
|
||||||
#include "p_djgpp2.h"
|
#include "p_djgpp2.h"
|
||||||
|
|
||||||
static const
|
|
||||||
#include "stub/stubify.h"
|
|
||||||
|
|
||||||
static const
|
static const
|
||||||
#include "stub/l_djgpp2.h"
|
#include "stub/l_djgpp2.h"
|
||||||
|
static const
|
||||||
|
#include "stub/stubify.h"
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -49,10 +48,12 @@ PackDjgpp2::PackDjgpp2(InputFile *f) :
|
|||||||
COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40);
|
COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40);
|
||||||
COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8);
|
COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8);
|
||||||
COMPILE_TIME_ASSERT(sizeof(stubify_stub) == 2048);
|
COMPILE_TIME_ASSERT(sizeof(stubify_stub) == 2048);
|
||||||
#if defined(STUBIFY_STUB_ADLER32)
|
COMPILE_TIME_ASSERT_ALIGNOF(external_scnhdr_t, char)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNOF(coff_header_t, char)
|
||||||
|
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)));
|
//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);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf,
|
|||||||
int PackDjgpp2::buildLoader(const Filter *ft)
|
int PackDjgpp2::buildLoader(const Filter *ft)
|
||||||
{
|
{
|
||||||
// prepare loader
|
// prepare loader
|
||||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||||
addLoader("IDENTSTR""DJ2MAIN1",
|
addLoader("IDENTSTR""DJ2MAIN1",
|
||||||
ft->id ? "DJCALLT1" : "",
|
ft->id ? "DJCALLT1" : "",
|
||||||
"DJ2MAIN2",
|
"DJ2MAIN2",
|
||||||
@@ -95,10 +96,10 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
|||||||
if (ft->id)
|
if (ft->id)
|
||||||
{
|
{
|
||||||
assert(ft->calls > 0);
|
assert(ft->calls > 0);
|
||||||
addLoader("DJCALLT2",NULL);
|
addLoader("DJCALLT2", NULL);
|
||||||
addFilter32(ft->id);
|
addFilter32(ft->id);
|
||||||
}
|
}
|
||||||
addLoader("DJRETURN+40DXXXXUPX1HEAD",NULL);
|
addLoader("DJRETURN+40DXXXXUPX1HEAD", NULL);
|
||||||
return getLoaderSize();
|
return getLoaderSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,18 +110,18 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
|||||||
|
|
||||||
void PackDjgpp2::handleStub(OutputFile *fo)
|
void PackDjgpp2::handleStub(OutputFile *fo)
|
||||||
{
|
{
|
||||||
if (fo && !opt->djgpp2.coff)
|
if (fo && !opt->djgpp2_coff.coff)
|
||||||
{
|
{
|
||||||
if (coff_offset > 0)
|
if (coff_offset > 0)
|
||||||
{
|
{
|
||||||
// copy stub from exe
|
// copy stub from exe
|
||||||
Packer::handleStub(fi,fo,coff_offset);
|
Packer::handleStub(fi, fo, coff_offset);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// "stubify" stub
|
// "stubify" stub
|
||||||
info("Adding stub: %ld bytes", (long)sizeof(stubify_stub));
|
info("Adding stub: %ld bytes", (long)sizeof(stubify_stub));
|
||||||
fo->write(stubify_stub,sizeof(stubify_stub));
|
fo->write(stubify_stub, sizeof(stubify_stub));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,14 +133,14 @@ static bool is_dlm(InputFile *fi, long coff_offset)
|
|||||||
long off;
|
long off;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fi->seek(coff_offset,SEEK_SET);
|
fi->seek(coff_offset, SEEK_SET);
|
||||||
fi->readx(buf,4);
|
fi->readx(buf, 4);
|
||||||
off = get_le32(buf);
|
off = get_le32(buf);
|
||||||
if (off < 0 || off > coff_offset + 4)
|
if (off < 0 || off > coff_offset + 4)
|
||||||
return false;
|
return false;
|
||||||
fi->seek(off,SEEK_SET);
|
fi->seek(off, SEEK_SET);
|
||||||
fi->readx(buf,4);
|
fi->readx(buf, 4);
|
||||||
if (memcmp(buf,"DLMF",4) == 0)
|
if (memcmp(buf, "DLMF", 4) == 0)
|
||||||
return true;
|
return true;
|
||||||
} catch (const IOException&) {
|
} catch (const IOException&) {
|
||||||
}
|
}
|
||||||
@@ -179,25 +180,25 @@ int PackDjgpp2::readFileHeader()
|
|||||||
unsigned char hdr[0x1c];
|
unsigned char hdr[0x1c];
|
||||||
unsigned char magic[8];
|
unsigned char magic[8];
|
||||||
|
|
||||||
fi->seek(0,SEEK_SET);
|
fi->seek(0, SEEK_SET);
|
||||||
fi->readx(hdr,sizeof(hdr));
|
fi->readx(hdr, sizeof(hdr));
|
||||||
if (get_le16(hdr) == 0x5a4d) // MZ exe signature, stubbed?
|
if (get_le16(hdr) == 0x5a4d) // MZ exe signature, stubbed?
|
||||||
{
|
{
|
||||||
coff_offset = 512 * get_le16(hdr+4);
|
coff_offset = 512 * get_le16(hdr+4);
|
||||||
if (get_le16(hdr+2) != 0)
|
if (get_le16(hdr+2) != 0)
|
||||||
coff_offset += get_le16(hdr+2) - 512;
|
coff_offset += get_le16(hdr+2) - 512;
|
||||||
fi->seek(512,SEEK_SET);
|
fi->seek(512, SEEK_SET);
|
||||||
fi->readx(magic,8);
|
fi->readx(magic, 8);
|
||||||
if (memcmp("go32stub",magic,8) != 0)
|
if (memcmp("go32stub", magic, 8) != 0)
|
||||||
return 0; // not V2 image
|
return 0; // not V2 image
|
||||||
fi->seek(coff_offset,SEEK_SET);
|
fi->seek(coff_offset, SEEK_SET);
|
||||||
if (fi->read(&coff_hdr,sizeof(coff_hdr)) != sizeof(coff_hdr))
|
if (fi->read(&coff_hdr, sizeof(coff_hdr)) != sizeof(coff_hdr))
|
||||||
throwCantPack("skipping djgpp symlink");
|
throwCantPack("skipping djgpp symlink");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fi->seek(coff_offset,SEEK_SET);
|
fi->seek(coff_offset, SEEK_SET);
|
||||||
fi->readx(&coff_hdr,0xa8);
|
fi->readx(&coff_hdr, 0xa8);
|
||||||
}
|
}
|
||||||
if (coff_hdr.f_magic != 0x014c) // I386MAGIC
|
if (coff_hdr.f_magic != 0x014c) // I386MAGIC
|
||||||
return 0;
|
return 0;
|
||||||
@@ -220,7 +221,7 @@ void PackDjgpp2::stripDebug()
|
|||||||
coff_hdr.f_symptr = 0;
|
coff_hdr.f_symptr = 0;
|
||||||
coff_hdr.f_nsyms = 0;
|
coff_hdr.f_nsyms = 0;
|
||||||
coff_hdr.f_flags = 0x10f; // 0x100: "32 bit machine: LSB first"
|
coff_hdr.f_flags = 0x10f; // 0x100: "32 bit machine: LSB first"
|
||||||
memset(text->misc,0,12);
|
memset(text->misc, 0, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -232,7 +233,7 @@ bool PackDjgpp2::canPack()
|
|||||||
{
|
{
|
||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
if (is_dlm(fi,coff_offset))
|
if (is_dlm(fi, coff_offset))
|
||||||
throwCantPack("can't handle DLM");
|
throwCantPack("can't handle DLM");
|
||||||
|
|
||||||
if (opt->force == 0)
|
if (opt->force == 0)
|
||||||
@@ -269,28 +270,25 @@ void PackDjgpp2::pack(OutputFile *fo)
|
|||||||
// read file
|
// read file
|
||||||
const unsigned size = text->size + data->size;
|
const unsigned size = text->size + data->size;
|
||||||
const unsigned tpos = text->scnptr;
|
const unsigned tpos = text->scnptr;
|
||||||
const unsigned usize = size + (tpos & 0x1ff);
|
const unsigned hdrsize = 20 + 28 + sizeof(external_scnhdr_t) * coff_hdr.f_nscns;
|
||||||
const unsigned hdrsize = 20 + 28 + (40 * coff_hdr.f_nscns);
|
const unsigned usize = size + hdrsize;
|
||||||
if (hdrsize < sizeof(coff_hdr) || hdrsize > tpos)
|
if (hdrsize < sizeof(coff_hdr) || hdrsize > tpos)
|
||||||
throwCantPack("coff header error");
|
throwCantPack("coff header error");
|
||||||
if (hdrsize > (tpos & 0x1ff))
|
|
||||||
throwCantPack("unsupported coff header");
|
|
||||||
|
|
||||||
ibuf.alloc(usize);
|
ibuf.alloc(usize);
|
||||||
obuf.allocForCompression(usize);
|
obuf.allocForCompression(usize);
|
||||||
|
|
||||||
fi->seek(coff_offset,SEEK_SET);
|
fi->seek(coff_offset, SEEK_SET);
|
||||||
fi->readx(ibuf,hdrsize); // orig. coff header
|
fi->readx(ibuf, hdrsize); // orig. coff header
|
||||||
memset(ibuf + hdrsize, 0, tpos - hdrsize);
|
fi->seek(coff_offset + tpos, SEEK_SET);
|
||||||
fi->seek(coff_offset+tpos,SEEK_SET);
|
fi->readx(ibuf + hdrsize, size);
|
||||||
fi->readx(ibuf + (tpos & 0x1ff),size);
|
|
||||||
|
|
||||||
// prepare packheader
|
// prepare packheader
|
||||||
ph.u_len = usize;
|
ph.u_len = usize;
|
||||||
// prepare filter
|
// prepare filter
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.buf_len = usize - data->size;
|
ft.buf_len = usize - data->size;
|
||||||
ft.addvalue = text->vaddr & ~0x1ff;
|
ft.addvalue = text->vaddr - hdrsize;
|
||||||
// compress
|
// compress
|
||||||
compressWithFilters(&ft, 512);
|
compressWithFilters(&ft, 512);
|
||||||
|
|
||||||
@@ -309,16 +307,21 @@ void PackDjgpp2::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// prepare loader
|
// prepare loader
|
||||||
MemBuffer loader(lsize);
|
MemBuffer loader(lsize);
|
||||||
memcpy(loader,getLoader(),lsize);
|
memcpy(loader, getLoader(), lsize);
|
||||||
|
|
||||||
// patch loader
|
// patch loader
|
||||||
patchPackHeader(loader,lsize);
|
patchPackHeader(loader, lsize);
|
||||||
patch_le32(loader,lsize,"ENTR",coff_hdr.a_entry);
|
patch_le32(loader, lsize, "ENTR", coff_hdr.a_entry);
|
||||||
patchFilter32(loader, lsize, &ft);
|
patchFilter32(loader, lsize, &ft);
|
||||||
patch_le32(loader,lsize,"BSSL",ph.overlap_overhead/4);
|
patch_le32(loader, lsize, "BSSL", ph.overlap_overhead / 4);
|
||||||
assert(bss->vaddr == ((size + 0x1ff) &~ 0x1ff) + (text->vaddr &~ 0x1ff));
|
assert(bss->vaddr == ((size + 0x1ff) &~ 0x1ff) + (text->vaddr &~ 0x1ff));
|
||||||
patch_le32(loader,lsize,"OUTP",text->vaddr &~ 0x1ff);
|
patch_le32(loader, lsize, "OUTP", text->vaddr - hdrsize);
|
||||||
patch_le32(loader,lsize,"INPP",data->vaddr);
|
patch_le32(loader, lsize, "INPP", data->vaddr);
|
||||||
|
|
||||||
|
// we should not overwrite our decompressor during unpacking
|
||||||
|
// the original coff header (which is put just before the
|
||||||
|
// beginning of the original .text section)
|
||||||
|
assert(text->vaddr > hdrsize + lsize + sizeof(coff_hdr));
|
||||||
|
|
||||||
// patch coff header #3
|
// patch coff header #3
|
||||||
text->vaddr = sizeof(coff_hdr);
|
text->vaddr = sizeof(coff_hdr);
|
||||||
@@ -327,13 +330,13 @@ void PackDjgpp2::pack(OutputFile *fo)
|
|||||||
bss->size -= ph.overlap_overhead;
|
bss->size -= ph.overlap_overhead;
|
||||||
|
|
||||||
// because of a feature (bug?) in stub.asm we need some padding
|
// because of a feature (bug?) in stub.asm we need some padding
|
||||||
memcpy(obuf+data->size,"UPX",3);
|
memcpy(obuf+data->size, "UPX", 3);
|
||||||
data->size = ALIGN_UP(data->size,4);
|
data->size = ALIGN_UP(data->size, 4);
|
||||||
|
|
||||||
// write coff header, loader and compressed file
|
// write coff header, loader and compressed file
|
||||||
fo->write(&coff_hdr,sizeof(coff_hdr));
|
fo->write(&coff_hdr, sizeof(coff_hdr));
|
||||||
fo->write(loader,lsize);
|
fo->write(loader, lsize);
|
||||||
fo->write(obuf,data->size);
|
fo->write(obuf, data->size);
|
||||||
#if 0
|
#if 0
|
||||||
printf("%-13s: coff hdr : %8ld bytes\n", getName(), (long) sizeof(coff_hdr));
|
printf("%-13s: coff hdr : %8ld bytes\n", getName(), (long) sizeof(coff_hdr));
|
||||||
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
|
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
|
||||||
@@ -345,7 +348,7 @@ void PackDjgpp2::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// handle overlay
|
// handle overlay
|
||||||
// FIXME: only Allegro pakfiles are supported
|
// FIXME: only Allegro pakfiles are supported
|
||||||
handle_allegropak(fi,fo);
|
handle_allegropak(fi, fo);
|
||||||
|
|
||||||
// finally check the compression ratio
|
// finally check the compression ratio
|
||||||
if (!checkFinalCompressionRatio(fo))
|
if (!checkFinalCompressionRatio(fo))
|
||||||
@@ -361,7 +364,7 @@ int PackDjgpp2::canUnpack()
|
|||||||
{
|
{
|
||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
if (is_dlm(fi,coff_offset))
|
if (is_dlm(fi, coff_offset))
|
||||||
throwCantUnpack("can't handle DLM");
|
throwCantUnpack("can't handle DLM");
|
||||||
fi->seek(coff_offset, SEEK_SET);
|
fi->seek(coff_offset, SEEK_SET);
|
||||||
return readPackHeader(1024) ? 1 : -1;
|
return readPackHeader(1024) ? 1 : -1;
|
||||||
@@ -379,19 +382,30 @@ void PackDjgpp2::unpack(OutputFile *fo)
|
|||||||
ibuf.alloc(ph.c_len);
|
ibuf.alloc(ph.c_len);
|
||||||
obuf.allocForUncompression(ph.u_len);
|
obuf.allocForUncompression(ph.u_len);
|
||||||
|
|
||||||
fi->seek(coff_offset + ph.buf_offset + ph.getPackHeaderSize(),SEEK_SET);
|
fi->seek(coff_offset + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
|
||||||
fi->readx(ibuf,ph.c_len);
|
fi->readx(ibuf, ph.c_len);
|
||||||
|
|
||||||
// decompress
|
// decompress
|
||||||
decompress(ibuf,obuf);
|
decompress(ibuf, obuf);
|
||||||
|
|
||||||
|
coff_header_t *chdr = (coff_header_t*) obuf.getVoidPtr();
|
||||||
|
text = chdr->sh;
|
||||||
|
data = text + 1;
|
||||||
|
|
||||||
|
const unsigned hdrsize = 20 + 28
|
||||||
|
+ sizeof(external_scnhdr_t) * chdr->f_nscns;
|
||||||
|
|
||||||
|
unsigned addvalue;
|
||||||
|
if (ph.version >= 14)
|
||||||
|
addvalue = text->vaddr - hdrsize;
|
||||||
|
else
|
||||||
|
addvalue = text->vaddr &~ 0x1ff; // for old versions
|
||||||
|
|
||||||
// unfilter
|
// unfilter
|
||||||
if (ph.filter)
|
if (ph.filter)
|
||||||
{
|
{
|
||||||
memcpy(&coff_hdr,obuf,sizeof(coff_hdr));
|
|
||||||
|
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.init(ph.filter, text->vaddr &~ 0x1ff);
|
ft.init(ph.filter, addvalue);
|
||||||
ft.cto = (unsigned char) ph.filter_cto;
|
ft.cto = (unsigned char) ph.filter_cto;
|
||||||
if (ph.version < 11)
|
if (ph.version < 11)
|
||||||
{
|
{
|
||||||
@@ -402,18 +416,34 @@ void PackDjgpp2::unpack(OutputFile *fo)
|
|||||||
ft.unfilter(obuf, ph.u_len - data->size);
|
ft.unfilter(obuf, ph.u_len - data->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixup for the aligning bug in strip 2.8+
|
if (ph.version < 14)
|
||||||
text = ((coff_header_t*) (unsigned char *) obuf)->sh;
|
|
||||||
data = text + 1;
|
|
||||||
text->scnptr &= 0x1ff;
|
|
||||||
data->scnptr = text->scnptr + text->size;
|
|
||||||
|
|
||||||
// write decompressed file
|
|
||||||
if (fo)
|
|
||||||
{
|
{
|
||||||
fo->write(obuf,ph.u_len);
|
// fixup for the aligning bug in strip 2.8+
|
||||||
handle_allegropak(fi,fo);
|
text->scnptr &= 0x1ff;
|
||||||
|
data->scnptr = text->scnptr + text->size;
|
||||||
|
// write decompressed file
|
||||||
|
if (fo)
|
||||||
|
fo->write(obuf, ph.u_len);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// write the header
|
||||||
|
// some padding might be required between the end
|
||||||
|
// of the header and the start of the .text section
|
||||||
|
|
||||||
|
const unsigned padding = text->scnptr - hdrsize;
|
||||||
|
ibuf.clear(0, padding);
|
||||||
|
|
||||||
|
if (fo)
|
||||||
|
{
|
||||||
|
fo->write(obuf, hdrsize);
|
||||||
|
fo->write(ibuf, padding);
|
||||||
|
fo->write(obuf + hdrsize, ph.u_len - hdrsize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fo)
|
||||||
|
handle_allegropak(fi, fo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -40,7 +40,7 @@ class PackDjgpp2 : public Packer
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PackDjgpp2(InputFile *f);
|
PackDjgpp2(InputFile *f);
|
||||||
virtual int getVersion() const { return 13; }
|
virtual int getVersion() const { return 14; }
|
||||||
virtual int getFormat() const { return UPX_F_DJGPP2_COFF; }
|
virtual int getFormat() const { return UPX_F_DJGPP2_COFF; }
|
||||||
virtual const char *getName() const { return "djgpp2/coff"; }
|
virtual const char *getName() const { return "djgpp2/coff"; }
|
||||||
virtual const int *getCompressionMethods(int method, int level) const;
|
virtual const int *getCompressionMethods(int method, int level) const;
|
||||||
|
|||||||
+58
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -51,6 +51,15 @@ struct Elf_LE32_Ehdr
|
|||||||
LE16 e_shentsize; /* Section header table entry size */
|
LE16 e_shentsize; /* Section header table entry size */
|
||||||
LE16 e_shnum; /* Section header table entry count */
|
LE16 e_shnum; /* Section header table entry count */
|
||||||
LE16 e_shstrndx; /* Section header string table index */
|
LE16 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 */
|
||||||
|
};
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
@@ -82,6 +91,53 @@ struct Elf_LE32_Phdr
|
|||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
|
|
||||||
|
struct Elf_LE32_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 */
|
||||||
|
|
||||||
|
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 */
|
||||||
|
/* 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_NUM = 19 /* Number of defined types. */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum { // values for sh_flags
|
||||||
|
SHF_WRITE = (1 << 0), /* Writable */
|
||||||
|
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
|
||||||
|
SHF_EXECINSTR = (1 << 2), /* Executable */
|
||||||
|
SHF_MERGE = (1 << 4), /* Might be merged */
|
||||||
|
SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */
|
||||||
|
SHF_INFO_LINK = (1 << 6), /* `sh_info' contains SHT index */
|
||||||
|
SHF_LINK_ORDER = (1 << 7), /* Preserve order after combining */
|
||||||
|
};
|
||||||
|
}
|
||||||
|
__attribute_packed;
|
||||||
|
|
||||||
struct Elf_LE32_Dyn
|
struct Elf_LE32_Dyn
|
||||||
{
|
{
|
||||||
LE32 d_tag;
|
LE32 d_tag;
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+18
-19
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -72,7 +72,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
|||||||
#define oh (*eh)
|
#define oh (*eh)
|
||||||
// fill new exe header
|
// fill new exe header
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
if (!opt->dos.no_reloc)
|
if (!opt->dos_exe.no_reloc)
|
||||||
flag |= USEJUMP;
|
flag |= USEJUMP;
|
||||||
if (ih.relocs == 0)
|
if (ih.relocs == 0)
|
||||||
flag |= NORELOC;
|
flag |= NORELOC;
|
||||||
@@ -82,7 +82,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
|||||||
oh.headsize16 = 2;
|
oh.headsize16 = 2;
|
||||||
oh.ip = 0;
|
oh.ip = 0;
|
||||||
|
|
||||||
oh.sp = ih.sp > 0x200 ? ih.sp : 0x200;
|
oh.sp = ih.sp > 0x200 ? (unsigned) ih.sp : 0x200;
|
||||||
|
|
||||||
unsigned destpara = (ph.u_len + ph.overlap_overhead - ph.c_len + 31) / 16;
|
unsigned destpara = (ph.u_len + ph.overlap_overhead - ph.c_len + 31) / 16;
|
||||||
oh.ss = ph.c_len/16 + destpara;
|
oh.ss = ph.c_len/16 + destpara;
|
||||||
@@ -213,7 +213,7 @@ bool PackExe::canPack()
|
|||||||
fi->readx(&offs,sizeof (offs));
|
fi->readx(&offs,sizeof (offs));
|
||||||
if (ih.relocoffs >= 0x40 && offs)
|
if (ih.relocoffs >= 0x40 && offs)
|
||||||
{
|
{
|
||||||
if (opt->dos.force_stub)
|
if (opt->dos_exe.force_stub)
|
||||||
opt->overlay = opt->COPY_OVERLAY;
|
opt->overlay = opt->COPY_OVERLAY;
|
||||||
else
|
else
|
||||||
throwCantPack("can't pack new-exe");
|
throwCantPack("can't pack new-exe");
|
||||||
@@ -338,7 +338,7 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
|
|||||||
set_le16 (crel_save+2,seg_high);
|
set_le16 (crel_save+2,seg_high);
|
||||||
|
|
||||||
//OutputFile::dump("x.rel", crel_save, crel - crel_save);
|
//OutputFile::dump("x.rel", crel_save, crel - crel_save);
|
||||||
return crel - crel_save;
|
return (unsigned) (crel - crel_save);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -437,8 +437,8 @@ void PackExe::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// set oh.min & oh.max
|
// set oh.min & oh.max
|
||||||
ic = ih.min*16 + ih_imagesize;
|
ic = ih.min*16 + ih_imagesize;
|
||||||
if (ic < oh.ss*16 + oh.sp)
|
if (ic < oh.ss*16u + oh.sp)
|
||||||
ic = oh.ss*16 + oh.sp;
|
ic = oh.ss*16u + oh.sp;
|
||||||
oh.min = (ic - (packedsize + lsize)) / 16;
|
oh.min = (ic - (packedsize + lsize)) / 16;
|
||||||
ic = oh.min + (ih.max - ih.min);
|
ic = oh.min + (ih.max - ih.min);
|
||||||
oh.max = ic < 0xffff && ih.max != 0xffff ? ic : 0xffff;
|
oh.max = ic < 0xffff && ih.max != 0xffff ? ic : 0xffff;
|
||||||
@@ -605,12 +605,11 @@ void PackExe::unpack(OutputFile *fo)
|
|||||||
{
|
{
|
||||||
relocs -= get_le16(obuf+ph.u_len-2);
|
relocs -= get_le16(obuf+ph.u_len-2);
|
||||||
ph.u_len -= 2;
|
ph.u_len -= 2;
|
||||||
upx_byte *p;
|
|
||||||
|
|
||||||
wrkmem.alloc(4*MAXRELOCS);
|
wrkmem.alloc(4*MAXRELOCS);
|
||||||
unsigned es = 0,ones = get_le16(relocs);
|
unsigned es = 0, ones = get_le16(relocs);
|
||||||
unsigned seghi = get_le16(relocs+2);
|
const unsigned seghi = get_le16(relocs+2);
|
||||||
p = relocs + 4;
|
const upx_byte *p = relocs + 4;
|
||||||
|
|
||||||
while (ones)
|
while (ones)
|
||||||
{
|
{
|
||||||
@@ -628,10 +627,10 @@ void PackExe::unpack(OutputFile *fo)
|
|||||||
dorel = true;
|
dorel = true;
|
||||||
if (*p == 0)
|
if (*p == 0)
|
||||||
{
|
{
|
||||||
upx_byte *q;
|
const upx_byte *q;
|
||||||
for (q = obuf+es*16+di; !(*q == 0x9a && get_le16(q+3) <= seghi); q++)
|
for (q = obuf+es*16+di; !(*q == 0x9a && get_le16(q+3) <= seghi); q++)
|
||||||
;
|
;
|
||||||
di = q - (obuf+es*16) + 3;
|
di = ptr_diff(q, obuf+es*16) + 3;
|
||||||
}
|
}
|
||||||
else if (*p == 1)
|
else if (*p == 1)
|
||||||
{
|
{
|
||||||
@@ -668,15 +667,15 @@ void PackExe::unpack(OutputFile *fo)
|
|||||||
oh.ss = ih.ss;
|
oh.ss = ih.ss;
|
||||||
|
|
||||||
if (flag & MAXMEM)
|
if (flag & MAXMEM)
|
||||||
imagesize -= 2, oh.max = get_le16(ibuf+imagesize);
|
{ imagesize -= 2; oh.max = get_le16(ibuf+imagesize); }
|
||||||
if (flag & MINMEM)
|
if (flag & MINMEM)
|
||||||
imagesize -= 2, oh.min = get_le16(ibuf+imagesize);
|
{ imagesize -= 2; oh.min = get_le16(ibuf+imagesize); }
|
||||||
if (flag & SP)
|
if (flag & SP)
|
||||||
imagesize -= 2, oh.sp = get_le16(ibuf+imagesize);
|
{ imagesize -= 2; oh.sp = get_le16(ibuf+imagesize); }
|
||||||
if (flag & SS)
|
if (flag & SS)
|
||||||
imagesize -= 2, oh.ss = get_le16(ibuf+imagesize);
|
{ imagesize -= 2; oh.ss = get_le16(ibuf+imagesize); }
|
||||||
|
|
||||||
unsigned ip = (flag & USEJUMP) ? get_le32(ibuf+imagesize-4) : ih.firstreloc;
|
unsigned ip = (flag & USEJUMP) ? get_le32(ibuf+imagesize-4) : (unsigned) ih.firstreloc;
|
||||||
oh.ip = ip & 0xffff;
|
oh.ip = ip & 0xffff;
|
||||||
oh.cs = ip >> 16;
|
oh.cs = ip >> 16;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+36
-9
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -66,9 +66,14 @@ PackLinuxI386elf::getFilters() const
|
|||||||
{
|
{
|
||||||
static const int filters[] = {
|
static const int filters[] = {
|
||||||
0x49, 0x46,
|
0x49, 0x46,
|
||||||
#if 1
|
// FIXME 2002-11-11: We use stub/fold_elf86.asm, which calls the
|
||||||
|
// decompressor multiple times, and unfilter is independent of decompress.
|
||||||
|
// Currently only filters 0x49, 0x46, 0x80..0x87 can handle this;
|
||||||
|
// and 0x80..0x87 are regarded as "untested".
|
||||||
|
#if 0
|
||||||
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
||||||
#else
|
#endif
|
||||||
|
#if 0
|
||||||
0x83, 0x36, 0x26,
|
0x83, 0x36, 0x26,
|
||||||
0x86, 0x80,
|
0x86, 0x80,
|
||||||
0x84, 0x87, 0x81,
|
0x84, 0x87, 0x81,
|
||||||
@@ -85,7 +90,7 @@ PackLinuxI386elf::buildLoader(const Filter *ft)
|
|||||||
unsigned char tmp[sizeof(linux_i386elf_fold)];
|
unsigned char tmp[sizeof(linux_i386elf_fold)];
|
||||||
memcpy(tmp, linux_i386elf_fold, sizeof(linux_i386elf_fold));
|
memcpy(tmp, linux_i386elf_fold, sizeof(linux_i386elf_fold));
|
||||||
checkPatch(NULL, 0, 0, 0); // reset
|
checkPatch(NULL, 0, 0, 0); // reset
|
||||||
if (opt->unix.ptinterp) {
|
if (opt->o_unix.ptinterp) {
|
||||||
unsigned j;
|
unsigned j;
|
||||||
for (j = 0; j < sizeof(linux_i386elf_fold)-1; ++j) {
|
for (j = 0; j < sizeof(linux_i386elf_fold)-1; ++j) {
|
||||||
if (0x60==tmp[ j]
|
if (0x60==tmp[ j]
|
||||||
@@ -157,12 +162,12 @@ bool PackLinuxI386elf::canPack()
|
|||||||
assert(exetype == 1);
|
assert(exetype == 1);
|
||||||
|
|
||||||
// set options
|
// set options
|
||||||
opt->unix.blocksize = blocksize = file_size;
|
opt->o_unix.blocksize = blocksize = file_size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackLinuxI386elf::packExtent(
|
void PackLinuxI386elf::packExtent(
|
||||||
Extent const &x,
|
const Extent &x,
|
||||||
unsigned &total_in,
|
unsigned &total_in,
|
||||||
unsigned &total_out,
|
unsigned &total_out,
|
||||||
Filter *ft,
|
Filter *ft,
|
||||||
@@ -252,7 +257,7 @@ void PackLinuxI386elf::pack1(OutputFile *fo, Filter &)
|
|||||||
assert(ehdri.e_phoff == sizeof(Elf_LE32_Ehdr)); // checked by canPack()
|
assert(ehdri.e_phoff == sizeof(Elf_LE32_Ehdr)); // checked by canPack()
|
||||||
sz_phdrs = ehdri.e_phnum * ehdri.e_phentsize;
|
sz_phdrs = ehdri.e_phnum * ehdri.e_phentsize;
|
||||||
|
|
||||||
phdri = new Elf_LE32_Phdr[ehdri.e_phnum];
|
phdri = new Elf_LE32_Phdr[(unsigned)ehdri.e_phnum];
|
||||||
fi->seek(ehdri.e_phoff, SEEK_SET);
|
fi->seek(ehdri.e_phoff, SEEK_SET);
|
||||||
fi->readx(phdri, sz_phdrs);
|
fi->readx(phdri, sz_phdrs);
|
||||||
|
|
||||||
@@ -335,6 +340,28 @@ void PackLinuxI386elf::pack2(OutputFile *fo, Filter &ft)
|
|||||||
throwEOFException();
|
throwEOFException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PackLinuxI386elf::pack3(OutputFile *fo, Filter &ft)
|
||||||
|
{
|
||||||
|
// We have packed multiple blocks, so PackLinuxI386::buildLinuxLoader
|
||||||
|
// needs an adjusted ph.c_len in order to get alignment correct.
|
||||||
|
unsigned const save_c_len = ph.c_len;
|
||||||
|
ph.c_len = fo->getBytesWritten() - (
|
||||||
|
// Elf32_Edhr
|
||||||
|
sizeof(elfout.ehdr) +
|
||||||
|
// Elf32_Phdr: 1 for exec86, 2 for sh86, 3 for elf86
|
||||||
|
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
|
||||||
|
// checksum UPX! lsize version format
|
||||||
|
sizeof(l_info) +
|
||||||
|
// PT_DYNAMIC with DT_NEEDED "forwarded" from original file
|
||||||
|
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0u) +
|
||||||
|
// p_progid, p_filesize, p_blocksize
|
||||||
|
sizeof(p_info) +
|
||||||
|
// compressed data
|
||||||
|
b_len );
|
||||||
|
buildLoader(&ft); /* redo for final .align constraints */
|
||||||
|
ph.c_len = save_c_len;
|
||||||
|
super::pack3(fo, ft);
|
||||||
|
}
|
||||||
|
|
||||||
void PackLinuxI386elf::unpackExtent(unsigned wanted, OutputFile *fo,
|
void PackLinuxI386elf::unpackExtent(unsigned wanted, OutputFile *fo,
|
||||||
unsigned &total_in, unsigned &total_out,
|
unsigned &total_in, unsigned &total_out,
|
||||||
|
|||||||
+5
-4
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -58,7 +58,7 @@ protected:
|
|||||||
off_t offset;
|
off_t offset;
|
||||||
off_t size;
|
off_t size;
|
||||||
};
|
};
|
||||||
virtual void packExtent(Extent const &x,
|
virtual void packExtent(const Extent &x,
|
||||||
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *);
|
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *);
|
||||||
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
|
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
|
||||||
unsigned &total_in, unsigned &total_out,
|
unsigned &total_in, unsigned &total_out,
|
||||||
@@ -68,6 +68,7 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||||
|
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||||
|
|
||||||
virtual void patchLoader();
|
virtual void patchLoader();
|
||||||
|
|
||||||
|
|||||||
+71
-14
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2001-2002 John F. Reiser
|
Copyright (C) 2001-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -63,10 +63,15 @@ const int *PackLinuxI386::getCompressionMethods(int method, int level) const
|
|||||||
const int *PackLinuxI386::getFilters() const
|
const int *PackLinuxI386::getFilters() const
|
||||||
{
|
{
|
||||||
static const int filters[] = {
|
static const int filters[] = {
|
||||||
#if 1
|
|
||||||
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
|
||||||
#else
|
|
||||||
0x49, 0x46,
|
0x49, 0x46,
|
||||||
|
// FIXME 2002-11-11: We use stub/fold_exec86.asm, which calls the
|
||||||
|
// decompressor multiple times, and unfilter is independent of decompress.
|
||||||
|
// Currently only filters 0x49, 0x46, 0x80..0x87 can handle this;
|
||||||
|
// and 0x80..0x87 are regarded as "untested".
|
||||||
|
#if 0
|
||||||
|
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
0x83, 0x86, 0x80, 0x84, 0x87, 0x81, 0x82, 0x85,
|
0x83, 0x86, 0x80, 0x84, 0x87, 0x81, 0x82, 0x85,
|
||||||
0x24, 0x16, 0x13, 0x14, 0x11, 0x25, 0x15, 0x12,
|
0x24, 0x16, 0x13, 0x14, 0x11, 0x25, 0x15, 0x12,
|
||||||
#endif
|
#endif
|
||||||
@@ -76,8 +81,8 @@ const int *PackLinuxI386::getFilters() const
|
|||||||
|
|
||||||
void
|
void
|
||||||
PackLinuxI386::generateElfHdr(
|
PackLinuxI386::generateElfHdr(
|
||||||
OutputFile *const fo,
|
OutputFile *fo,
|
||||||
void const *const proto,
|
void const *proto,
|
||||||
unsigned const brka
|
unsigned const brka
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -144,12 +149,64 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
|||||||
overlay_offset = sizeof(elfout.ehdr) +
|
overlay_offset = sizeof(elfout.ehdr) +
|
||||||
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
|
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
|
||||||
sizeof(l_info) +
|
sizeof(l_info) +
|
||||||
((elfout.ehdr.e_phnum==3) ? elfout.phdr[2].p_memsz : 0) ;
|
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ;
|
||||||
super::pack4(fo, ft); // write PackHeader and overlay_offset
|
super::pack4(fo, ft); // write PackHeader and overlay_offset
|
||||||
|
|
||||||
elfout.phdr[0].p_filesz = fo->getBytesWritten();
|
unsigned eod = fo->getBytesWritten();
|
||||||
|
elfout.phdr[0].p_filesz = eod;
|
||||||
|
|
||||||
#define PAGE_MASK (~0<<12)
|
#if 0 // {
|
||||||
|
// /usr/bin/strip from RedHat 8.0 (binutils-2.13.90.0.2-2)
|
||||||
|
// generates a 92-byte [only] output, because the "linking view"
|
||||||
|
// is empty. This code supplies a "linking view".
|
||||||
|
// However, 'strip' then generates _plausible_ junk that gets
|
||||||
|
// "Illegal instruction" because 'strip' changes p_hdr[1].p_align,
|
||||||
|
// .p_offset, and .p_vaddr incorrectly. So the "cure" is worse than
|
||||||
|
// the disease. It is obvious that a 92-byte file is bad,
|
||||||
|
// but it is not obvious that the changed .p_align is bad.
|
||||||
|
// Also, having a totally empty "linking view" is easier for 'strip'
|
||||||
|
// to fix: just detect that, and do nothing.
|
||||||
|
// So, we don't use this code for now [2003-01-11].
|
||||||
|
|
||||||
|
// Supply a "linking view" that covers everything,
|
||||||
|
// so that 'strip' does not omit everything.
|
||||||
|
Elf_LE32_Shdr shdr;
|
||||||
|
// The section header string table.
|
||||||
|
char const shstrtab[] = "\0.\0.shstrtab";
|
||||||
|
|
||||||
|
set_native32(&elfout.ehdr.e_shoff, eod);
|
||||||
|
set_native16(&elfout.ehdr.e_shentsize, sizeof(shdr));
|
||||||
|
set_native16(&elfout.ehdr.e_shnum, 3);
|
||||||
|
set_native16(&elfout.ehdr.e_shstrndx, 2);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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_addr, elfout.phdr[0].p_vaddr);
|
||||||
|
set_native32(&shdr.sh_offset, overlay_offset);
|
||||||
|
set_native32(&shdr.sh_size, eod - overlay_offset);
|
||||||
|
set_native32(&shdr.sh_addralign, 4096);
|
||||||
|
fo->write(&shdr, sizeof(shdr));
|
||||||
|
|
||||||
|
// 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_offset, 3*sizeof(shdr) + eod);
|
||||||
|
set_native32(&shdr.sh_size, sizeof(shstrtab));
|
||||||
|
fo->write(&shdr, sizeof(shdr));
|
||||||
|
|
||||||
|
fo->write(shstrtab, sizeof(shstrtab));
|
||||||
|
#endif // }
|
||||||
|
|
||||||
|
#define PAGE_MASK (~0u<<12)
|
||||||
// pre-calculate for benefit of runtime disappearing act via munmap()
|
// pre-calculate for benefit of runtime disappearing act via munmap()
|
||||||
elfout.phdr[0].p_memsz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
|
elfout.phdr[0].p_memsz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
|
||||||
#undef PAGE_MASK
|
#undef PAGE_MASK
|
||||||
@@ -200,7 +257,7 @@ PackLinuxI386::buildLinuxLoader(
|
|||||||
|
|
||||||
// This adds the definition to the "library", to be used later.
|
// This adds the definition to the "library", to be used later.
|
||||||
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr);
|
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr);
|
||||||
delete cprLoader;
|
delete [] cprLoader;
|
||||||
|
|
||||||
n_mru = ft->n_mru;
|
n_mru = ft->n_mru;
|
||||||
|
|
||||||
@@ -213,7 +270,7 @@ PackLinuxI386::buildLinuxLoader(
|
|||||||
// checksum UPX! lsize version format
|
// checksum UPX! lsize version format
|
||||||
sizeof(l_info) +
|
sizeof(l_info) +
|
||||||
// PT_DYNAMIC with DT_NEEDED "forwarded" from original file
|
// PT_DYNAMIC with DT_NEEDED "forwarded" from original file
|
||||||
((elfout.ehdr.e_phnum==3) ? elfout.phdr[2].p_memsz : 0) +
|
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) +
|
||||||
// p_progid, p_filesize, p_blocksize
|
// p_progid, p_filesize, p_blocksize
|
||||||
sizeof(p_info) +
|
sizeof(p_info) +
|
||||||
// compressed data
|
// compressed data
|
||||||
@@ -415,7 +472,7 @@ bool PackLinuxI386::canPack()
|
|||||||
{
|
{
|
||||||
// NOTE: ELF executables are now handled by p_lx_elf.cpp,
|
// NOTE: ELF executables are now handled by p_lx_elf.cpp,
|
||||||
// so we only handle them here if force_execve
|
// so we only handle them here if force_execve
|
||||||
if (elf == 0 && opt->unix.force_execve)
|
if (elf == 0 && opt->o_unix.force_execve)
|
||||||
exetype = 1;
|
exetype = 1;
|
||||||
}
|
}
|
||||||
else if (l == 0x00640107 || l == 0x00640108 || l == 0x0064010b || l == 0x006400cc)
|
else if (l == 0x00640107 || l == 0x00640108 || l == 0x0064010b || l == 0x006400cc)
|
||||||
|
|||||||
+7
-7
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
virtual void generateElfHdr(
|
virtual void generateElfHdr(
|
||||||
OutputFile *,
|
OutputFile *,
|
||||||
void const *proto,
|
void const *proto,
|
||||||
unsigned brka
|
unsigned const brka
|
||||||
);
|
);
|
||||||
virtual int getFormat() const { return UPX_F_LINUX_i386; }
|
virtual int getFormat() const { return UPX_F_LINUX_i386; }
|
||||||
virtual const char *getName() const { return "linux/386"; }
|
virtual const char *getName() const { return "linux/386"; }
|
||||||
@@ -86,25 +86,25 @@ protected:
|
|||||||
struct cprElfHdr1 {
|
struct cprElfHdr1 {
|
||||||
struct Elf_LE32_Ehdr ehdr;
|
struct Elf_LE32_Ehdr ehdr;
|
||||||
struct Elf_LE32_Phdr phdr[1];
|
struct Elf_LE32_Phdr phdr[1];
|
||||||
struct PackUnix::l_info linfo;
|
struct l_info linfo;
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
struct cprElfHdr2 {
|
struct cprElfHdr2 {
|
||||||
struct Elf_LE32_Ehdr ehdr;
|
struct Elf_LE32_Ehdr ehdr;
|
||||||
struct Elf_LE32_Phdr phdr[2];
|
struct Elf_LE32_Phdr phdr[2];
|
||||||
struct PackUnix::l_info linfo;
|
struct l_info linfo;
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
struct cprElfHdr3 {
|
struct cprElfHdr3 {
|
||||||
struct Elf_LE32_Ehdr ehdr;
|
struct Elf_LE32_Ehdr ehdr;
|
||||||
struct Elf_LE32_Phdr phdr[3];
|
struct Elf_LE32_Phdr phdr[3];
|
||||||
struct PackUnix::l_info linfo;
|
struct l_info linfo;
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
cprElfHdr3 elfout;
|
struct cprElfHdr3 elfout;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
//#define SCRIPT_SIZE (opt->unix.SCRIPT_MAX + sizeof(l_info))
|
//#define SCRIPT_SIZE (opt->o_unix.SCRIPT_MAX + sizeof(l_info))
|
||||||
#define SCRIPT_SIZE (32 + sizeof(l_info))
|
#define SCRIPT_SIZE (32 + sizeof(l_info))
|
||||||
|
|
||||||
const upx_byte *PackLinuxI386sep::getLoader() const
|
const upx_byte *PackLinuxI386sep::getLoader() const
|
||||||
@@ -50,7 +50,7 @@ const upx_byte *PackLinuxI386sep::getLoader() const
|
|||||||
static char script[SCRIPT_SIZE];
|
static char script[SCRIPT_SIZE];
|
||||||
|
|
||||||
memset(script, 0, sizeof(script));
|
memset(script, 0, sizeof(script));
|
||||||
char const *name = opt->unix.script_name;
|
char const *name = opt->o_unix.script_name;
|
||||||
if (0==name) {
|
if (0==name) {
|
||||||
name = "/usr/local/lib/upxX";
|
name = "/usr/local/lib/upxX";
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ int PackLinuxI386sep::getLoaderSize() const
|
|||||||
|
|
||||||
int PackLinuxI386sep::getLoaderPrefixSize() const
|
int PackLinuxI386sep::getLoaderPrefixSize() const
|
||||||
{
|
{
|
||||||
return opt->unix.SCRIPT_MAX;
|
return opt->o_unix.SCRIPT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackLinuxI386sep::patchLoader()
|
void PackLinuxI386sep::patchLoader()
|
||||||
|
|||||||
+3
-3
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+17
-6
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -92,11 +92,11 @@ void PackLinuxI386sh::patchLoader() { }
|
|||||||
bool PackLinuxI386sh::getShellName(char *buf)
|
bool PackLinuxI386sh::getShellName(char *buf)
|
||||||
{
|
{
|
||||||
exetype = -1;
|
exetype = -1;
|
||||||
l_shname = strcspn(buf, " \t\n\v\f\r");
|
l_shname = (int) strcspn(buf, " \t\n\v\f\r");
|
||||||
buf[l_shname] = 0;
|
buf[l_shname] = 0;
|
||||||
static char const *const shname[] = { // known shells that accept "-c" arg
|
static char const *const shname[] = { // known shells that accept "-c" arg
|
||||||
"ash", "bash", "bsh", "csh", "ksh", "pdksh", "sh", "tcsh", "zsh",
|
"ash", "bash", "bsh", "csh", "ksh", "pdksh", "sh", "tcsh", "zsh",
|
||||||
//"python", // FIXME: does python work ???
|
"python",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
const char *bname = strrchr(buf, '/');
|
const char *bname = strrchr(buf, '/');
|
||||||
@@ -104,7 +104,11 @@ bool PackLinuxI386sh::getShellName(char *buf)
|
|||||||
return false;
|
return false;
|
||||||
for (int j = 0; NULL != shname[j]; ++j) {
|
for (int j = 0; NULL != shname[j]; ++j) {
|
||||||
if (0 == strcmp(shname[j], bname + 1)) {
|
if (0 == strcmp(shname[j], bname + 1)) {
|
||||||
return super::canPack();
|
bool const s = super::canPack();
|
||||||
|
if (s) {
|
||||||
|
opt->o_unix.blocksize = blocksize = file_size;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -139,6 +143,13 @@ PackLinuxI386sh::pack1(OutputFile *fo, Filter &)
|
|||||||
generateElfHdr(fo, linux_i386sh_fold, 0x08048000);
|
generateElfHdr(fo, linux_i386sh_fold, 0x08048000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackLinuxI386sh::pack3(OutputFile *fo, Filter &ft)
|
||||||
|
{
|
||||||
|
super::pack3(fo,ft);
|
||||||
|
elfout.phdr[0].p_filesz = fo->getBytesWritten();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
vi:ts=4:et
|
vi:ts=4:et
|
||||||
*/
|
*/
|
||||||
|
|||||||
+4
-3
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2000-2002 John F. Reiser
|
Copyright (C) 2000-2004 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
virtual int buildLoader(const Filter *);
|
virtual int buildLoader(const Filter *);
|
||||||
|
|
||||||
virtual void pack1(OutputFile *fo, Filter &ft);
|
virtual void pack1(OutputFile *fo, Filter &ft);
|
||||||
|
virtual void pack3(OutputFile *fo, Filter &ft);
|
||||||
|
|
||||||
virtual bool canPack();
|
virtual bool canPack();
|
||||||
// virtual void unpack(OutputFile *fo) { super::unpack(fo); }
|
// virtual void unpack(OutputFile *fo) { super::unpack(fo); }
|
||||||
|
|||||||
+303
-168
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2002 Jens Medoch
|
Copyright (C) 2002-2004 Jens Medoch
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
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
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
@@ -36,74 +37,158 @@
|
|||||||
#include "p_ps1.h"
|
#include "p_ps1.h"
|
||||||
|
|
||||||
static const
|
static const
|
||||||
#include "stub/l_ps1.h"
|
#include "stub/l_ps1b.h"
|
||||||
|
static const
|
||||||
|
#include "stub/l_ps1c.h"
|
||||||
|
|
||||||
|
|
||||||
#define MIPS_HI(a) (((a) >> 16) /* + (((a)&0x8000)>>15) */ )
|
#define MIPS_HI(a) ((a) >> 16)
|
||||||
#define MIPS_LO(a) ((a) & 0xffff)
|
#define MIPS_LO(a) ((a) & 0xffff)
|
||||||
#define MIPS_JP(a) ((0x08 << 24) | (((a) & 0x0fffffff) >> 2))
|
#define MIPS_JP(a) ((0x08 << 24) | (((a) & 0x0fffffff) >> 2))
|
||||||
#define CHK_ALIGNED(a,b) ((b) - ((a) % (b)))
|
#define TIL_ALIGNED(a,b) (((b) - ((a) & ((b) - 1))) & (b) - 1)
|
||||||
#define NOCACHE(a) ((a) & 0x1FFFFFFF)
|
|
||||||
|
|
||||||
#define PS_HDR_SIZE 2048 // one CD sector in bytes
|
#define CD_SEC 2048
|
||||||
#define PS_MAX_SIZE 0x1e8000
|
#define PS_HDR_SIZE CD_SEC
|
||||||
|
#define PS_RAM_SIZE 0x200000
|
||||||
|
#define PS_MIN_SIZE (PS_HDR_SIZE*3)
|
||||||
|
#define PS_MAX_SIZE 0x1e8000
|
||||||
|
|
||||||
#define IH_BKUP (10 * sizeof(LE32))
|
#define SZ_IH_BKUP (10 * sizeof(LE32))
|
||||||
#define EIGHTBIT
|
#define HD_CODE_OFS (sizeof(ps1_exe_t))
|
||||||
|
|
||||||
|
#define K0_BS (0x80000000)
|
||||||
|
#define K1_BS (0xa0000000)
|
||||||
|
#define FIX_PSVR (K1_BS - (ih.epc & K0_BS)) + (PS_HDR_SIZE - HD_CODE_OFS)
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
// ps1 exe looks like this:
|
||||||
|
// 1. <header> 2048 bytes
|
||||||
|
// 2. <body> plain binary
|
||||||
//
|
//
|
||||||
|
// header: contains the ps1_exe_t structure 188 bytes at offset zero
|
||||||
|
// rest is filled with zeros to reach the required
|
||||||
|
// cd mode 2 data sector size of 2048 bytes
|
||||||
|
// body: contains the binary data / code of the executable
|
||||||
|
// reqiures: executable code must be aligned to 4
|
||||||
|
// must be aligned to 2048 to run from a CD
|
||||||
|
// optional: not aligned to 2048 (for console run only)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
PackPs1::PackPs1(InputFile *f) :
|
PackPs1::PackPs1(InputFile *f) :
|
||||||
super(f)
|
super(f),
|
||||||
|
isCon(true^opt->ps1_exe.boot_only), is32Bit(true^opt->ps1_exe.do_8bit),
|
||||||
|
overlap(0), sa_cnt(0)
|
||||||
{
|
{
|
||||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 188);
|
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 188);
|
||||||
COMPILE_TIME_ASSERT(IH_BKUP == 40);
|
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t));
|
||||||
|
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40);
|
||||||
overlap = 0;
|
#if 1 || defined(WITH_NRV)
|
||||||
sa_cnt = 0;
|
COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3918);
|
||||||
fdata_size = cfile_size = 0;
|
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0xdf0cbd9e);
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2810);
|
||||||
|
COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x31747f8b);
|
||||||
|
#endif
|
||||||
|
fdata_size = file_size - PS_HDR_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const int *PackPs1::getCompressionMethods(int method, int level) const
|
const int *PackPs1::getCompressionMethods(int method, int level) const
|
||||||
{
|
{
|
||||||
#ifdef EIGHTBIT
|
if (is32Bit)
|
||||||
return Packer::getDefaultCompressionMethods_8(method, level);
|
return Packer::getDefaultCompressionMethods_le32(method, level);
|
||||||
#else
|
else
|
||||||
return Packer::getDefaultCompressionMethods_le32(method, level);
|
return Packer::getDefaultCompressionMethods_8(method, level);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const int *PackPs1::getFilters() const
|
const int *PackPs1::getFilters() const
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// functions for marker handling
|
/*************************************************************************
|
||||||
int PackPs1::patch_mips_le16(void *b, int blen, const void *old, unsigned new_)
|
// util
|
||||||
{
|
// readFileHeader() reads ih and checks for illegal values
|
||||||
unsigned char w[2];
|
// checkFileHeader() checks ih for legal but unsupported values
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
set_le16(w, get_be16(old));
|
int PackPs1::readFileHeader()
|
||||||
return patch_le16(b, blen, w, new_);
|
{
|
||||||
|
fi->seek(0, SEEK_SET);
|
||||||
|
fi->readx(&ih, sizeof(ih));
|
||||||
|
if (memcmp(&ih.id,"PS-X EXE",8) != 0 &&
|
||||||
|
memcmp(&ih.id,"EXE X-SP",8) != 0)
|
||||||
|
return 0;
|
||||||
|
if (ih.text != 0 || ih.data != 0)
|
||||||
|
return 0;
|
||||||
|
return UPX_F_PS1_EXE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PackPs1::patch_mips_le32(void *b, int blen, const void *old, unsigned new_)
|
|
||||||
{
|
|
||||||
unsigned char w[4];
|
|
||||||
|
|
||||||
set_le32(w, get_be32(old));
|
bool PackPs1::checkFileHeader()
|
||||||
return patch_le32(b, blen, w, new_);
|
{
|
||||||
|
if (fdata_size != ih.tx_len || (ih.tx_len & 3))
|
||||||
|
{
|
||||||
|
if (!opt->force)
|
||||||
|
throwCantPack("file size entry damaged (try --force)");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
opt->info_mode += !opt->info_mode ? 1 : 0;
|
||||||
|
infoWarning("fixing damaged header, keeping backup file");
|
||||||
|
opt->backup = 1;
|
||||||
|
ih.tx_len = fdata_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!opt->force &&
|
||||||
|
(ih.da_ptr != 0 || ih.da_len != 0 ||
|
||||||
|
ih.bs_ptr != 0 || ih.bs_len != 0))
|
||||||
|
{
|
||||||
|
infoWarning("unsupported header field entry");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!opt->force && ih.is_ptr == 0)
|
||||||
|
{
|
||||||
|
infoWarning("stack pointer field empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PackPs1::patch_hi_lo(void *b, int blen, const void *old_hi, const void *old_lo, unsigned new_)
|
|
||||||
|
/*************************************************************************
|
||||||
|
// patch util
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
void PackPs1::patch_mips_le(void *b, int blen, const void *old, unsigned new_)
|
||||||
{
|
{
|
||||||
patch_mips_le16(b, blen, old_lo, MIPS_LO(new_));
|
size_t patch_len = strlen((const char*)old);
|
||||||
patch_mips_le16(b, blen, old_hi, MIPS_HI(new_));
|
|
||||||
return 1;
|
if (patch_len == 2)
|
||||||
|
{
|
||||||
|
unsigned char w[2];
|
||||||
|
|
||||||
|
set_le16(w, get_be16(old));
|
||||||
|
patch_le16(b, blen, w, MIPS_LO(new_));
|
||||||
|
}
|
||||||
|
else if (patch_len == 4)
|
||||||
|
{
|
||||||
|
unsigned char w[4];
|
||||||
|
|
||||||
|
set_le32(w, get_be32(old));
|
||||||
|
int boff = find(b, blen, w, 4);
|
||||||
|
|
||||||
|
if (boff == -1)
|
||||||
|
{
|
||||||
|
patch_le16(b, blen, &w[0], MIPS_LO(new_));
|
||||||
|
patch_le16(b, blen, &w[2], MIPS_HI(new_));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
patch_le32((unsigned char *)b + boff, (blen-boff), &w, new_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throwInternalError("bad marker length");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -113,25 +198,30 @@ int PackPs1::patch_hi_lo(void *b, int blen, const void *old_hi, const void *old_
|
|||||||
|
|
||||||
bool PackPs1::canPack()
|
bool PackPs1::canPack()
|
||||||
{
|
{
|
||||||
unsigned char buf[256];
|
unsigned char buf[PS_HDR_SIZE-HD_CODE_OFS];
|
||||||
fdata_size = file_size-PS_HDR_SIZE;
|
|
||||||
|
|
||||||
fi->seek(0, SEEK_SET);
|
if (!readFileHeader())
|
||||||
fi->readx(&ih, sizeof(ih));
|
|
||||||
|
|
||||||
if ((memcmp(&ih.id,"PS-X EXE",8) != 0) && (memcmp(&ih.id,"EXE X-SP",8) != 0))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fi->readx(buf, sizeof(buf));
|
fi->readx(buf, sizeof(buf));
|
||||||
checkAlreadyPacked(buf, sizeof(buf));
|
checkAlreadyPacked(buf, sizeof(buf));
|
||||||
if (fdata_size != ih.tx_len || (ih.tx_len & 3))
|
|
||||||
{
|
for (unsigned i = 0; i < sizeof(buf); i++)
|
||||||
if (!opt->force)
|
if (buf[i] != 0)
|
||||||
throwCantPack("check header for file size (try --force)");
|
if (!opt->force)
|
||||||
cfile_size = fdata_size;
|
throwCantPack("unknown data in header (try --force)");
|
||||||
}
|
else
|
||||||
if (file_size <= (PS_HDR_SIZE*3) && !opt->force)
|
{
|
||||||
|
opt->info_mode += !opt->info_mode ? 1 : 0;
|
||||||
|
infoWarning("clearing header, keeping backup file");
|
||||||
|
opt->backup = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!checkFileHeader())
|
||||||
|
throwCantPack("unsupported header flags (try --force)");
|
||||||
|
if (!opt->force && file_size < PS_MIN_SIZE)
|
||||||
throwCantPack("file is too small (try --force)");
|
throwCantPack("file is too small (try --force)");
|
||||||
if (file_size > PS_MAX_SIZE && !opt->force)
|
if (!opt->force && file_size > PS_MAX_SIZE)
|
||||||
throwCantPack("file is too big (try --force)");
|
throwCantPack("file is too big (try --force)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -143,33 +233,41 @@ bool PackPs1::canPack()
|
|||||||
|
|
||||||
int PackPs1::buildLoader(const Filter *)
|
int PackPs1::buildLoader(const Filter *)
|
||||||
{
|
{
|
||||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
if (isCon)
|
||||||
addLoader("PSXPREP0","PSXSTSZ0","PSXMAIN0",
|
initLoader(nrv_con_loader,sizeof(nrv_con_loader));
|
||||||
ih.tx_ptr & 0xffff ? "PSXJSTA0" : "PSXJSTH0",
|
else
|
||||||
"PSXDECO0",
|
initLoader(nrv_boot_loader,sizeof(nrv_boot_loader));
|
||||||
|
|
||||||
|
addLoader("PS1START",
|
||||||
|
isCon ? ph.c_len & 3 ? "PS1PADCD" : "" : "PS1ENTRY",
|
||||||
|
ih.tx_ptr & 0xffff ? "PS1CONHL" : "PS1CONHI",
|
||||||
|
isCon ? "PS1ENTRY" : "",
|
||||||
NULL);
|
NULL);
|
||||||
#ifdef EIGHTBIT
|
|
||||||
if (ph.method == M_NRV2B_8)
|
if (ph.method == M_NRV2B_8)
|
||||||
addLoader("PSXN2BD0", NULL);
|
addLoader("PS1N2B08", NULL);
|
||||||
else if (ph.method == M_NRV2D_8)
|
else if (ph.method == M_NRV2D_8)
|
||||||
addLoader("PSXN2DD0", NULL);
|
addLoader("PS1N2D08", NULL);
|
||||||
else if (ph.method == M_NRV2E_8)
|
else if (ph.method == M_NRV2E_8)
|
||||||
addLoader("PSXN2ED0", NULL);
|
addLoader("PS1N2E08", NULL);
|
||||||
#else
|
else if (ph.method == M_NRV2B_LE32)
|
||||||
if (ph.method == M_NRV2B_LE32)
|
addLoader("PS1N2B32", NULL);
|
||||||
addLoader("PSXN2BD0", NULL);
|
|
||||||
else if (ph.method == M_NRV2D_LE32)
|
else if (ph.method == M_NRV2D_LE32)
|
||||||
addLoader("PSXN2DD0", NULL);
|
addLoader("PS1N2D32", NULL);
|
||||||
else if (ph.method == M_NRV2E_LE32)
|
else if (ph.method == M_NRV2E_LE32)
|
||||||
addLoader("PSXN2ED0", NULL);
|
addLoader("PS1N2E32", NULL);
|
||||||
#endif
|
|
||||||
else
|
else
|
||||||
throwInternalError("unknown compression method");
|
throwInternalError("unknown compression method");
|
||||||
|
|
||||||
if (sa_cnt)
|
if (sa_cnt)
|
||||||
addLoader((sa_cnt > 0xfffc) ? "MSETBIG0" : "MSETSML0", // set small/big memset
|
addLoader(sa_cnt > (0x10000 << 2) ? "PS1MSETB" : "PS1MSETS",
|
||||||
(ih.tx_len & 3) ? "MSETUAL0" : "MSETALG0", // un/aligned memset
|
ih.tx_len & 3 ? "PS1MSETU" : "PS1MSETA",
|
||||||
NULL);
|
NULL);
|
||||||
addLoader("PSXEXIT0", "IDENTSTR", "PSXPHDR0", NULL);
|
|
||||||
|
addLoader("PS1EXITC", "IDENTSTR", "PS1PAHDR",
|
||||||
|
isCon ? "PS1SREGS" : "",
|
||||||
|
NULL);
|
||||||
|
|
||||||
return getLoaderSize();
|
return getLoaderSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,130 +280,163 @@ void PackPs1::pack(OutputFile *fo)
|
|||||||
{
|
{
|
||||||
ibuf.alloc(fdata_size);
|
ibuf.alloc(fdata_size);
|
||||||
obuf.allocForCompression(fdata_size);
|
obuf.allocForCompression(fdata_size);
|
||||||
const upx_byte *p_scan = ibuf+(fdata_size-1);
|
const upx_byte *p_scan = ibuf+fdata_size;
|
||||||
|
|
||||||
// read file
|
// read file
|
||||||
fi->seek(PS_HDR_SIZE,SEEK_SET);
|
fi->seek(PS_HDR_SIZE,SEEK_SET);
|
||||||
fi->readx(ibuf,fdata_size);
|
fi->readx(ibuf,fdata_size);
|
||||||
|
|
||||||
// this scans the end of file for 2048 bytes sector alignment
|
// scan EOF for 2048 bytes sector alignment
|
||||||
// this should be padded with zeros
|
// the removed space will secure in-place decompression
|
||||||
while (!(*p_scan--)) { if ((sa_cnt += 1) > (0xfffc<<3)) break; }
|
while (!(*--p_scan)) { if (sa_cnt++ > (0x10000<<5) || sa_cnt >= fdata_size-1024) break; }
|
||||||
if (sa_cnt > 0xfffc)
|
|
||||||
sa_cnt = ALIGN_DOWN(sa_cnt,8);
|
if (sa_cnt > (0x10000<<2))
|
||||||
|
sa_cnt = ALIGN_DOWN(sa_cnt,32);
|
||||||
else
|
else
|
||||||
sa_cnt = ALIGN_DOWN(sa_cnt,4);
|
sa_cnt = ALIGN_DOWN(sa_cnt,4);
|
||||||
|
|
||||||
// prepare packheader
|
// prepare packheader
|
||||||
ph.u_len = (fdata_size - sa_cnt);
|
ph.u_len = (fdata_size - sa_cnt);
|
||||||
ph.filter = 0;
|
ph.filter = 0;
|
||||||
|
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
|
|
||||||
// compress (max_match = 65535)
|
// compress (max_match = 65535)
|
||||||
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
|
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
|
||||||
|
|
||||||
if (ph.overlap_overhead <= sa_cnt)
|
if (ph.overlap_overhead > sa_cnt)
|
||||||
overlap = 0;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (!opt->force)
|
if (!opt->force)
|
||||||
|
{
|
||||||
|
infoWarning("not in-place decompressible");
|
||||||
throwCantPack("packed data overlap (try --force)");
|
throwCantPack("packed data overlap (try --force)");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
overlap = ALIGN_UP((ph.overlap_overhead-sa_cnt),4);
|
overlap = ALIGN_UP((ph.overlap_overhead-sa_cnt),4);
|
||||||
opt->info_mode += !opt->info_mode ? 1 : 0;
|
opt->info_mode += !opt->info_mode ? 1 : 0;
|
||||||
infoWarning("%s will load to a %d bytes higher offset",fi->getName(),overlap);
|
infoWarning("%s: memory overlap %d bytes",fi->getName(),overlap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&oh, &ih, sizeof(ih));
|
memcpy(&oh, &ih, sizeof(ih));
|
||||||
memcpy(&oh.ih_bkup, &ih.epc, IH_BKUP);
|
memcpy(&oh.ih_bkup, &ih.epc, SZ_IH_BKUP);
|
||||||
oh.ih_csum = upx_adler32(&ih.epc, IH_BKUP);
|
oh.ih_csum = upx_adler32(&ih.epc, SZ_IH_BKUP);
|
||||||
|
|
||||||
|
if (ih.is_ptr == 0)
|
||||||
|
oh.is_ptr = PS_RAM_SIZE-0x10;
|
||||||
|
|
||||||
|
if (ih.da_ptr != 0 || ih.da_len != 0 ||
|
||||||
|
ih.bs_ptr != 0 || ih.bs_len != 0)
|
||||||
|
oh.da_ptr = oh.da_len =
|
||||||
|
oh.bs_ptr = oh.bs_len = 0;
|
||||||
|
|
||||||
const int lsize = getLoaderSize();
|
const int lsize = getLoaderSize();
|
||||||
const int h_len = lsize-getLoaderSectionStart("IDENTSTR");
|
|
||||||
const int e_len = lsize-h_len;
|
|
||||||
const int d_len = e_len-getLoaderSectionStart("PSXDECO0");
|
|
||||||
int s_len;
|
|
||||||
getLoaderSection("PSXSTSZ0",&s_len); // get size of pushed/poped regs
|
|
||||||
|
|
||||||
MemBuffer loader(lsize);
|
MemBuffer loader(lsize);
|
||||||
memcpy(loader,getLoader(),lsize);
|
memcpy(loader, getLoader(), lsize);
|
||||||
|
|
||||||
unsigned pad, pad_code;
|
|
||||||
pad = ALIGN_UP((cfile_size ? cfile_size : ih.tx_len), 4);
|
|
||||||
pad_code = CHK_ALIGNED(ph.c_len, 4);
|
|
||||||
|
|
||||||
const unsigned decomp_data_start = NOCACHE(ih.tx_ptr);
|
|
||||||
|
|
||||||
// set the offset for compressed stuff at the very end of file
|
|
||||||
const unsigned comp_data_start = NOCACHE(((decomp_data_start+pad+overlap)-ph.c_len));
|
|
||||||
|
|
||||||
if (!opt->ps1.no_align)
|
|
||||||
// align the packed file to mode 2 data sector size (2048)
|
|
||||||
pad = CHK_ALIGNED(ph.c_len+pad_code+e_len+overlap, 2048);
|
|
||||||
else
|
|
||||||
// no align
|
|
||||||
pad = 0;
|
|
||||||
|
|
||||||
const unsigned entry = NOCACHE(comp_data_start - e_len - pad_code);
|
|
||||||
patchPackHeader(loader,lsize);
|
patchPackHeader(loader,lsize);
|
||||||
patch_mips_le32(loader,e_len,"JPEP",MIPS_JP(ih.epc));
|
|
||||||
if (sa_cnt)
|
unsigned pad = 0;
|
||||||
patch_mips_le16(loader,e_len,"SC",
|
unsigned filelen = ALIGN_UP(ih.tx_len, 4);
|
||||||
MIPS_LO(sa_cnt > 0xfffc ? sa_cnt >> 3 : sa_cnt));
|
unsigned pad_code = TIL_ALIGNED(ph.c_len, 4);
|
||||||
if (ih.tx_ptr & 0xffff)
|
|
||||||
//we have to set the high/low value of the offset
|
const unsigned decomp_data_start = ih.tx_ptr;
|
||||||
patch_hi_lo(loader,e_len,"OH","OL",decomp_data_start);
|
const unsigned comp_data_start = ((decomp_data_start + filelen + overlap) - ph.c_len);
|
||||||
|
|
||||||
|
const int h_len = lsize - getLoaderSectionStart("IDENTSTR");
|
||||||
|
const int c_len = lsize - h_len;
|
||||||
|
int d_len = 0;
|
||||||
|
int e_len = 0;
|
||||||
|
|
||||||
|
if (isCon)
|
||||||
|
{
|
||||||
|
e_len = lsize - h_len;
|
||||||
|
d_len = e_len - getLoaderSectionStart("PS1ENTRY");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
//only high has to be set, this will save 4 bytes
|
{
|
||||||
patch_mips_le16(loader,e_len,"OH",decomp_data_start>>16);
|
d_len = (lsize - h_len) - getLoaderSectionStart("PS1ENTRY");
|
||||||
patch_hi_lo(loader,e_len,"CH","CL",comp_data_start);
|
e_len = (lsize - d_len) - h_len;
|
||||||
patch_hi_lo(loader,e_len,"DH","DL",entry+(e_len-d_len));
|
}
|
||||||
patch_mips_le16(loader,e_len,"LS",d_len+s_len);
|
|
||||||
|
|
||||||
// set the file load address
|
patch_mips_le(loader,c_len,"JPEP",MIPS_JP(ih.epc));
|
||||||
oh.tx_ptr = entry - pad;
|
if (sa_cnt)
|
||||||
// set the correct file len in header
|
patch_mips_le(loader,c_len,"SC",
|
||||||
oh.tx_len = ph.c_len + e_len + pad + pad_code;
|
MIPS_LO(sa_cnt > (0x10000 << 2) ? sa_cnt >> 5 : sa_cnt >> 2));
|
||||||
// set the code entry
|
if (ih.tx_ptr & 0xffff)
|
||||||
oh.epc = entry;
|
patch_mips_le(loader,c_len,"DECO",decomp_data_start);
|
||||||
|
else
|
||||||
|
patch_mips_le(loader,c_len,"DE",MIPS_HI(decomp_data_start));
|
||||||
|
|
||||||
// write loader + compressed file
|
const unsigned entry = comp_data_start - e_len - pad_code;
|
||||||
|
oh.tx_ptr = entry;
|
||||||
|
oh.tx_len = ph.c_len + e_len + pad_code;
|
||||||
|
oh.epc = comp_data_start - e_len - pad_code;
|
||||||
|
|
||||||
|
if (!opt->ps1_exe.no_align)
|
||||||
|
{
|
||||||
|
pad = oh.tx_len;
|
||||||
|
oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC);
|
||||||
|
pad = oh.tx_len - pad;
|
||||||
|
oh.tx_ptr -= pad;
|
||||||
|
}
|
||||||
|
|
||||||
|
ibuf.clear(0,fdata_size);
|
||||||
upx_bytep paddata = ibuf;
|
upx_bytep paddata = ibuf;
|
||||||
memset(paddata,0,fdata_size);
|
|
||||||
|
|
||||||
fo->write(&oh,sizeof(oh));
|
if (isCon)
|
||||||
|
{
|
||||||
|
if (pad_code)
|
||||||
|
patch_mips_le(loader, c_len, "PC", pad_code);
|
||||||
|
patch_mips_le(loader, c_len, "DCRT", entry + (e_len - d_len));
|
||||||
|
patch_mips_le(loader, c_len, "LS",
|
||||||
|
d_len + get_le32(&loader[getLoaderSectionStart("PS1SREGS")]));
|
||||||
|
|
||||||
// id & upx header
|
// ps1_exe_t structure 188 bytes
|
||||||
fo->write(loader+e_len,h_len);
|
fo->write(&oh,sizeof(oh));
|
||||||
// align the ps exe header (mode 2 sector data size)
|
// id & upx header
|
||||||
fo->write(paddata,PS_HDR_SIZE-fo->getBytesWritten());
|
fo->write(loader + e_len,h_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
patch_mips_le(loader, c_len, "CPDO", comp_data_start);
|
||||||
|
patch_mips_le(loader, e_len, "PSVR", FIX_PSVR);
|
||||||
|
|
||||||
|
// ps1_exe_t structure 188 bytes
|
||||||
|
fo->write(&oh,sizeof(oh));
|
||||||
|
// decompressor
|
||||||
|
fo->write(loader + e_len, d_len);
|
||||||
|
// id & upx header
|
||||||
|
fo->write(loader + e_len + d_len, h_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
// header size is 2048 bytes
|
||||||
|
fo->write(paddata, PS_HDR_SIZE - fo->getBytesWritten());
|
||||||
|
// sector alignment
|
||||||
if (pad)
|
if (pad)
|
||||||
// align the file
|
fo->write(paddata, pad);
|
||||||
fo->write(paddata,pad);
|
|
||||||
// entry
|
// entry
|
||||||
fo->write(loader,e_len);
|
fo->write(loader, e_len);
|
||||||
|
// code must be aligned to 4!
|
||||||
if (pad_code)
|
if (pad_code)
|
||||||
// align the mips runtime code
|
fo->write(paddata, pad_code);
|
||||||
fo->write(paddata,pad_code);
|
// compressed binary / data
|
||||||
fo->write(obuf,ph.c_len);
|
fo->write(obuf, ph.c_len);
|
||||||
|
|
||||||
// verify
|
|
||||||
verifyOverlappingDecompression();
|
verifyOverlappingDecompression();
|
||||||
|
|
||||||
// finally check the compression ratio
|
|
||||||
if (!checkFinalCompressionRatio(fo))
|
if (!checkFinalCompressionRatio(fo))
|
||||||
throwNotCompressible();
|
throwNotCompressible();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
printf("%-13s: uncompressed : %8ld bytes\n", getName(), (long) ph.u_len);
|
||||||
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
|
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
|
||||||
printf("%-13s: decompressor : %8ld bytes\n", getName(), (long) e_len);
|
printf("%-13s: decompressor : %8ld bytes\n", getName(), (long) lsize - h_len);
|
||||||
printf("%-13s: code entry : %08X bytes\n", getName(), (unsigned int) oh.epc);
|
printf("%-13s: code entry : %08X bytes\n", getName(), (unsigned int) oh.epc);
|
||||||
printf("%-13s: load address : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr);
|
printf("%-13s: load address : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr);
|
||||||
printf("%-13s: section size : %8ld bytes\n", getName(), (long) oh.tx_len);
|
|
||||||
printf("%-13s: eof in mem IF: %08X bytes\n", getName(), (unsigned int) ih.tx_ptr+ih.tx_len);
|
printf("%-13s: eof in mem IF: %08X bytes\n", getName(), (unsigned int) ih.tx_ptr+ih.tx_len);
|
||||||
printf("%-13s: eof in mem OF: %08X bytes\n", getName(), (unsigned int) oh.tx_ptr+oh.tx_len);
|
printf("%-13s: eof in mem OF: %08X bytes\n", getName(), (unsigned int) oh.tx_ptr+oh.tx_len);
|
||||||
|
char method_name[32+1]; set_method_name(method_name, sizeof(method_name), ph.method, ph.level);
|
||||||
|
printf("%-13s: compressor : %s\n", getName(), method_name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,10 +447,17 @@ void PackPs1::pack(OutputFile *fo)
|
|||||||
|
|
||||||
int PackPs1::canUnpack()
|
int PackPs1::canUnpack()
|
||||||
{
|
{
|
||||||
if (!readPackHeader(0x400))
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
if (file_size <= (off_t) ph.c_len)
|
if (!readPackHeader(1024))
|
||||||
return false;
|
return false;
|
||||||
|
// check header as set by packer
|
||||||
|
if (ih.ih_csum != upx_adler32(&ih.ih_bkup, SZ_IH_BKUP) &&
|
||||||
|
(ph.c_len >= fdata_size))
|
||||||
|
throwCantUnpack("header damaged");
|
||||||
|
// generic check
|
||||||
|
if (!checkFileHeader())
|
||||||
|
throwCantUnpack("unsupported header flags");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,40 +468,37 @@ int PackPs1::canUnpack()
|
|||||||
|
|
||||||
void PackPs1::unpack(OutputFile *fo)
|
void PackPs1::unpack(OutputFile *fo)
|
||||||
{
|
{
|
||||||
fdata_size = file_size-PS_HDR_SIZE;
|
// restore orig exec hdr
|
||||||
ibuf.alloc(file_size);
|
|
||||||
|
|
||||||
fi->seek(0x0,SEEK_SET);
|
|
||||||
fi->readx(&ih,sizeof(ih));
|
|
||||||
fi->seek(PS_HDR_SIZE,SEEK_SET);
|
|
||||||
fi->readx(ibuf,fdata_size);
|
|
||||||
|
|
||||||
// test & restore orig exec hdr
|
|
||||||
if (ih.ih_csum != upx_adler32(&ih.ih_bkup,IH_BKUP))
|
|
||||||
throwCantUnpack("file is possibly modified/hacked/protected; take care!");
|
|
||||||
|
|
||||||
memcpy(&oh, &ih, sizeof(ih));
|
memcpy(&oh, &ih, sizeof(ih));
|
||||||
memcpy(&oh.epc, &ih.ih_bkup, IH_BKUP);
|
memcpy(&oh.epc, &ih.ih_bkup, SZ_IH_BKUP);
|
||||||
|
|
||||||
// clear backup and checksum of header
|
|
||||||
memset(&oh.ih_bkup,0,IH_BKUP+4);
|
|
||||||
|
|
||||||
// check for removed sector alignment
|
// check for removed sector alignment
|
||||||
|
assert(oh.tx_len >= ph.u_len);
|
||||||
const unsigned pad = oh.tx_len - ph.u_len;
|
const unsigned pad = oh.tx_len - ph.u_len;
|
||||||
|
|
||||||
obuf.allocForUncompression(ph.u_len+pad);
|
ibuf.alloc(fdata_size > PS_HDR_SIZE ? fdata_size : PS_HDR_SIZE);
|
||||||
memset(obuf,0,obuf.getSize());
|
obuf.allocForUncompression(ph.u_len, pad);
|
||||||
|
|
||||||
|
fi->seek(PS_HDR_SIZE, SEEK_SET);
|
||||||
|
fi->readx(ibuf, fdata_size);
|
||||||
|
|
||||||
|
// clear backup and checksum of header
|
||||||
|
memset(&oh.ih_bkup, 0, SZ_IH_BKUP+4);
|
||||||
|
|
||||||
// decompress
|
// decompress
|
||||||
decompress(ibuf+(fdata_size-ph.c_len),obuf);
|
decompress(ibuf + (fdata_size - ph.c_len), obuf);
|
||||||
|
|
||||||
// write decompressed file
|
// write decompressed file
|
||||||
if (fo)
|
if (fo)
|
||||||
{
|
{
|
||||||
fo->write(&oh,sizeof(oh));
|
// write header
|
||||||
memset(ibuf,0,fdata_size);
|
fo->write(&oh, sizeof(oh));
|
||||||
fo->write(ibuf,PS_HDR_SIZE-fo->getBytesWritten());
|
// align the ps exe header (mode 2 sector data size)
|
||||||
fo->write(obuf,ph.u_len+pad);
|
ibuf.clear();
|
||||||
|
// write uncompressed data + pad
|
||||||
|
fo->write(ibuf, PS_HDR_SIZE - sizeof(oh));
|
||||||
|
obuf.clear(ph.u_len, pad);
|
||||||
|
fo->write(obuf, ph.u_len + pad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+30
-25
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
Copyright (C) 2002 Jens Medoch
|
Copyright (C) 2002-2004 Jens Medoch
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
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
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
@@ -55,50 +56,54 @@ public:
|
|||||||
virtual int canUnpack();
|
virtual int canUnpack();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void patch_mips_le(void *b, int blen, const void *old, unsigned new_);
|
||||||
virtual int buildLoader(const Filter *ft);
|
virtual int buildLoader(const Filter *ft);
|
||||||
virtual int patch_mips_le16(void *b, int blen, const void *old, unsigned new_);
|
|
||||||
virtual int patch_mips_le32(void *b, int blen, const void *old, unsigned new_);
|
virtual int readFileHeader();
|
||||||
virtual int patch_hi_lo(void *b, int blen, const void *old_hi, const void *old_lo, unsigned new_);
|
virtual bool checkFileHeader();
|
||||||
|
|
||||||
struct ps1_exe_t
|
struct ps1_exe_t
|
||||||
{
|
{
|
||||||
|
// ident string
|
||||||
char id[8];
|
char id[8];
|
||||||
|
// is NULL
|
||||||
LE32 text;
|
LE32 text;
|
||||||
|
// is NULL
|
||||||
LE32 data;
|
LE32 data;
|
||||||
|
// initial program counter
|
||||||
LE32 epc;
|
LE32 epc;
|
||||||
|
// initial gp register value
|
||||||
LE32 gp;
|
LE32 gp;
|
||||||
LE32 tx_ptr;
|
// load offset of binary data
|
||||||
LE32 tx_len;
|
LE32 tx_ptr, tx_len;
|
||||||
LE32 da_ptr;
|
LE32 da_ptr, da_len;
|
||||||
LE32 da_len;
|
LE32 bs_ptr, bs_len;
|
||||||
LE32 bs_ptr;
|
// initial stack params
|
||||||
LE32 bs_len;
|
LE32 is_ptr, is_len;
|
||||||
LE32 sd_ptr;
|
// saved regs on execution
|
||||||
LE32 sd_len;
|
LE32 sp, fp, gp0, ra, k0;
|
||||||
LE32 sp,fp,gp0,ra,k0;
|
// origin Jap/USA/Europe
|
||||||
char origin[60];
|
char origin[60];
|
||||||
|
|
||||||
// some safety space after that
|
// some safety space after that
|
||||||
char pad[8];
|
char pad[8];
|
||||||
// i'll place the backup of the original
|
// backup of the original header (epc - is_len)
|
||||||
// execution file structure here (epc - sd_len)
|
|
||||||
LE32 ih_bkup[10];
|
LE32 ih_bkup[10];
|
||||||
// plus checksum for the backup
|
// plus checksum for the backup
|
||||||
LE32 ih_csum;
|
LE32 ih_csum;
|
||||||
// here will find the id & the upx header it's place.
|
// id & the upx header.
|
||||||
// btw only the 'epc - sd_len' entries init the executable.
|
|
||||||
// so stuff placed here will not load and waste memory.
|
|
||||||
}
|
}
|
||||||
__attribute_packed;
|
__attribute_packed;
|
||||||
|
|
||||||
ps1_exe_t ih, oh;
|
ps1_exe_t ih, oh;
|
||||||
|
|
||||||
upx_uint overlap;
|
bool isCon;
|
||||||
upx_uint sa_cnt;
|
bool is32Bit;
|
||||||
|
unsigned overlap;
|
||||||
|
unsigned sa_cnt;
|
||||||
|
|
||||||
// filesize-PS_HDR_SIZE
|
// filesize-PS_HDR_SIZE
|
||||||
upx_uint fdata_size;
|
unsigned fdata_size;
|
||||||
// calculated filesize
|
|
||||||
upx_uint cfile_size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+3
-3
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
virtual bool canPack();
|
virtual bool canPack();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const unsigned getCallTrickOffset() const { return 0; }
|
virtual unsigned getCallTrickOffset() const { return 0; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int buildLoader(const Filter *ft);
|
virtual int buildLoader(const Filter *ft);
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+28
-20
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -136,6 +136,8 @@ int PackTos::getLoaderSize() const
|
|||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
|
// readFileHeader() reads ih and checks for illegal values
|
||||||
|
// checkFileHeader() checks ih for legal but unsupported values
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int PackTos::readFileHeader()
|
int PackTos::readFileHeader()
|
||||||
@@ -221,6 +223,7 @@ static unsigned OP_MOVEQ(int value, int d_reg)
|
|||||||
|
|
||||||
static unsigned OP_SUBQ_L(int value, int d_reg)
|
static unsigned OP_SUBQ_L(int value, int d_reg)
|
||||||
{
|
{
|
||||||
|
// subq.l #X,d0
|
||||||
assert(value >= 1 && value <= 8);
|
assert(value >= 1 && value <= 8);
|
||||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||||
return 0x5180 | ((value & 7) << 9) | (d_reg & 7);
|
return 0x5180 | ((value & 7) << 9) | (d_reg & 7);
|
||||||
@@ -228,6 +231,7 @@ static unsigned OP_SUBQ_L(int value, int d_reg)
|
|||||||
|
|
||||||
static unsigned OP_SUBQ_W(int value, int d_reg)
|
static unsigned OP_SUBQ_W(int value, int d_reg)
|
||||||
{
|
{
|
||||||
|
// subq.w #X,d0
|
||||||
assert(value >= 1 && value <= 8);
|
assert(value >= 1 && value <= 8);
|
||||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||||
return 0x5140 | ((value & 7) << 9) | (d_reg & 7);
|
return 0x5140 | ((value & 7) << 9) | (d_reg & 7);
|
||||||
@@ -365,14 +369,15 @@ bool PackTos::canPack()
|
|||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned char buf[512];
|
unsigned char buf[768];
|
||||||
fi->readx(buf, sizeof(buf));
|
fi->readx(buf, sizeof(buf));
|
||||||
checkAlreadyPacked(buf, sizeof(buf));
|
checkAlreadyPacked(buf, sizeof(buf));
|
||||||
|
|
||||||
if (!checkFileHeader())
|
if (!checkFileHeader())
|
||||||
throwCantPack("unsupported header flags");
|
throwCantPack("unsupported header flags");
|
||||||
if (file_size < 256)
|
if (file_size < 1024)
|
||||||
throwCantPack("program too small");
|
throwCantPack("program is too small");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,13 +404,6 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
unsigned relocsize = 0;
|
unsigned relocsize = 0;
|
||||||
unsigned overlay = 0;
|
unsigned overlay = 0;
|
||||||
|
|
||||||
const unsigned lsize = getLoaderSize();
|
|
||||||
const unsigned e_len = get_be16(getLoader()+lsize-6);
|
|
||||||
const unsigned d_len = get_be16(getLoader()+lsize-4);
|
|
||||||
const unsigned decomp_offset = get_be16(getLoader()+lsize-2);
|
|
||||||
assert(e_len + d_len == lsize - 6);
|
|
||||||
assert((e_len & 3) == 0 && (d_len & 1) == 0);
|
|
||||||
|
|
||||||
const unsigned i_text = ih.fh_text;
|
const unsigned i_text = ih.fh_text;
|
||||||
const unsigned i_data = ih.fh_data;
|
const unsigned i_data = ih.fh_data;
|
||||||
const unsigned i_sym = ih.fh_sym;
|
const unsigned i_sym = ih.fh_sym;
|
||||||
@@ -474,8 +472,8 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
// After compression this will become the first part of the
|
// After compression this will become the first part of the
|
||||||
// data segement. The second part will be the decompressor.
|
// data segement. The second part will be the decompressor.
|
||||||
|
|
||||||
// alloc buffer
|
// alloc buffer (2048 is for decompressor and the various alignments)
|
||||||
obuf.allocForCompression(t + d_len + 512);
|
obuf.allocForCompression(t, 2048);
|
||||||
|
|
||||||
// prepare packheader
|
// prepare packheader
|
||||||
ph.u_len = t;
|
ph.u_len = t;
|
||||||
@@ -484,6 +482,14 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
// compress (max_match = 65535)
|
// compress (max_match = 65535)
|
||||||
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
|
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
|
||||||
|
|
||||||
|
// get loader
|
||||||
|
const unsigned lsize = getLoaderSize();
|
||||||
|
const unsigned e_len = get_be16(getLoader()+lsize-6);
|
||||||
|
const unsigned d_len = get_be16(getLoader()+lsize-4);
|
||||||
|
const unsigned decomp_offset = get_be16(getLoader()+lsize-2);
|
||||||
|
assert(e_len + d_len == lsize - 6);
|
||||||
|
assert((e_len & 3) == 0 && (d_len & 1) == 0);
|
||||||
|
|
||||||
// The decompressed data will now get placed at this offset:
|
// The decompressed data will now get placed at this offset:
|
||||||
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
||||||
|
|
||||||
@@ -536,12 +542,13 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// prepare loader
|
// prepare loader
|
||||||
MemBuffer loader(o_text);
|
MemBuffer loader(o_text);
|
||||||
memcpy(loader,getLoader(),o_text);
|
memcpy(loader, getLoader(), o_text);
|
||||||
|
|
||||||
// patch loader
|
// patch loader
|
||||||
patchPackHeader(loader,o_text);
|
int tmp = patchPackHeader(loader, o_text);
|
||||||
|
assert(tmp + 32 == (int)o_text); UNUSED(tmp);
|
||||||
if (!opt->small)
|
if (!opt->small)
|
||||||
patchVersion(loader,o_text);
|
patchVersion(loader, o_text);
|
||||||
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
|
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
|
||||||
const unsigned dirty_bss_d6 =
|
const unsigned dirty_bss_d6 =
|
||||||
patch_d_subq(loader, o_text, REG_D6, dirty_bss / dirty_bss_align, "u4");
|
patch_d_subq(loader, o_text, REG_D6, dirty_bss / dirty_bss_align, "u4");
|
||||||
@@ -575,7 +582,7 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// set new file_hdr
|
// set new file_hdr
|
||||||
memcpy(&oh, &ih, FH_SIZE);
|
memcpy(&oh, &ih, FH_SIZE);
|
||||||
if (opt->tos.split_segments)
|
if (opt->atari_tos.split_segments)
|
||||||
{
|
{
|
||||||
oh.fh_text = o_text;
|
oh.fh_text = o_text;
|
||||||
oh.fh_data = o_data;
|
oh.fh_data = o_data;
|
||||||
@@ -635,6 +642,7 @@ int PackTos::canUnpack()
|
|||||||
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0
|
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0
|
||||||
|| ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1)
|
|| ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1)
|
||||||
throwCantUnpack("program header damaged");
|
throwCantUnpack("program header damaged");
|
||||||
|
// generic check
|
||||||
if (!checkFileHeader())
|
if (!checkFileHeader())
|
||||||
throwCantUnpack("unsupported header flags");
|
throwCantUnpack("unsupported header flags");
|
||||||
return true;
|
return true;
|
||||||
@@ -650,8 +658,8 @@ void PackTos::unpack(OutputFile *fo)
|
|||||||
ibuf.alloc(ph.c_len);
|
ibuf.alloc(ph.c_len);
|
||||||
obuf.allocForUncompression(ph.u_len);
|
obuf.allocForUncompression(ph.u_len);
|
||||||
|
|
||||||
fi->seek(ph.buf_offset + ph.getPackHeaderSize(),SEEK_SET);
|
fi->seek(FH_SIZE + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
|
||||||
fi->readx(ibuf,ph.c_len);
|
fi->readx(ibuf, ph.c_len);
|
||||||
|
|
||||||
// decompress
|
// decompress
|
||||||
decompress(ibuf,obuf);
|
decompress(ibuf,obuf);
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+4
-5
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -120,8 +120,7 @@ void PackUnix::pack1(OutputFile * /*fo*/, Filter & /*ft*/)
|
|||||||
// derived class usually provides this
|
// derived class usually provides this
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int PackUnix::getStrategy(Filter &/*ft*/)
|
||||||
PackUnix::getStrategy(Filter &/*ft*/)
|
|
||||||
{
|
{
|
||||||
// Called just before reading and compressing each block.
|
// Called just before reading and compressing each block.
|
||||||
// Might want to adjust blocksize, etc.
|
// Might want to adjust blocksize, etc.
|
||||||
@@ -250,7 +249,7 @@ void PackUnix::pack(OutputFile *fo)
|
|||||||
progid = 0;
|
progid = 0;
|
||||||
|
|
||||||
// set options
|
// set options
|
||||||
blocksize = opt->unix.blocksize;
|
blocksize = opt->o_unix.blocksize;
|
||||||
if (blocksize <= 0)
|
if (blocksize <= 0)
|
||||||
blocksize = BLOCKSIZE;
|
blocksize = BLOCKSIZE;
|
||||||
if ((off_t)blocksize > file_size)
|
if ((off_t)blocksize > file_size)
|
||||||
|
|||||||
+11
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -68,6 +68,7 @@ protected:
|
|||||||
// an endian abstraction here
|
// an endian abstraction here
|
||||||
virtual unsigned get_native32(const void *) = 0;
|
virtual unsigned get_native32(const void *) = 0;
|
||||||
virtual void set_native32(void *, unsigned) = 0;
|
virtual void set_native32(void *, unsigned) = 0;
|
||||||
|
virtual void set_native16(void *, unsigned) = 0;
|
||||||
|
|
||||||
virtual bool checkCompressionRatio(unsigned, unsigned) const;
|
virtual bool checkCompressionRatio(unsigned, unsigned) const;
|
||||||
|
|
||||||
@@ -133,6 +134,10 @@ protected:
|
|||||||
{
|
{
|
||||||
set_be32(b, v);
|
set_be32(b, v);
|
||||||
}
|
}
|
||||||
|
virtual void set_native16(void *b, unsigned v)
|
||||||
|
{
|
||||||
|
set_be16(b, v);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -149,6 +154,10 @@ protected:
|
|||||||
{
|
{
|
||||||
set_le32(b, v);
|
set_le32(b, v);
|
||||||
}
|
}
|
||||||
|
virtual void set_native16(void *b, unsigned v)
|
||||||
|
{
|
||||||
|
set_le16(b, v);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,622 @@
|
|||||||
|
/* p_vmlinx.cpp -- pack vmlinux ET_EXEC file (before bootsect or setup)
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 2004 John Reiser
|
||||||
|
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
|
||||||
|
|
||||||
|
John Reiser
|
||||||
|
jreiser@users.sourceforge.net
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
|
#include "file.h"
|
||||||
|
#include "filter.h"
|
||||||
|
#include "packer.h"
|
||||||
|
#include "p_vmlinx.h"
|
||||||
|
|
||||||
|
static const
|
||||||
|
#include "stub/l_vmlinx.h"
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
PackVmlinuxI386::PackVmlinuxI386(InputFile *f) :
|
||||||
|
super(f), n_ptload(0), phdri(NULL), shdri(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PackVmlinuxI386::~PackVmlinuxI386()
|
||||||
|
{
|
||||||
|
delete [] phdri;
|
||||||
|
delete [] shdri;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int *PackVmlinuxI386::getCompressionMethods(int method, int level) const
|
||||||
|
{
|
||||||
|
return Packer::getDefaultCompressionMethods_le32(method, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const int *PackVmlinuxI386::getFilters() const
|
||||||
|
{
|
||||||
|
static const int filters[] = {
|
||||||
|
0x49,
|
||||||
|
-1 };
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
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
|
||||||
|
if (a->p_paddr > b->p_paddr) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Examples as of 2004-07-16 [readelf --segments vmlinux # before fiddling]:
|
||||||
|
//
|
||||||
|
//----- kernel-2.6.7 plain [defconfig?]
|
||||||
|
//Program Headers(2):
|
||||||
|
// Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
||||||
|
// LOAD 0x001000 0x00100000 0x00100000 0x1c7e61 0x1c7e61 R E 0x1000
|
||||||
|
// LOAD 0x1c8e64 0x002c8e64 0x002c8e64 0x00000 0x00000 RW 0x1000
|
||||||
|
//
|
||||||
|
//----- kernel-2.6.7-1.488 Fedora Core 3 test 1
|
||||||
|
//Program Headers(5):
|
||||||
|
// Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
||||||
|
// LOAD 0x001000 0x02100000 0x02100000 0x202246 0x202246 R E 0x1000
|
||||||
|
// LOAD 0x204000 0xffff3000 0x02303000 0x00664 0x00664 R E 0x1000
|
||||||
|
// LOAD 0x205000 0x02304000 0x02304000 0x43562 0x43562 R 0x1000
|
||||||
|
// LOAD 0x249000 0x02348000 0x02348000 0x81800 0xcb0fc RWE 0x1000
|
||||||
|
// STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
|
||||||
|
//
|
||||||
|
|
||||||
|
bool PackVmlinuxI386::canPack()
|
||||||
|
{
|
||||||
|
fi->seek(0, SEEK_SET);
|
||||||
|
fi->readx(&ehdri, sizeof(ehdri));
|
||||||
|
|
||||||
|
// now check the ELF header
|
||||||
|
if (memcmp(&ehdri, "\x7f\x45\x4c\x46\x01\x01\x01", 7) // ELF 32-bit LSB
|
||||||
|
|| !memcmp(&ehdri.e_ident[8], "FreeBSD", 7) // branded
|
||||||
|
|| ehdri.e_machine != 3 // Intel 80386
|
||||||
|
|| ehdri.e_version != 1 // version
|
||||||
|
)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|| 0x00100000!=(0x001fffff & ehdri.e_entry) // entry not an odd 1MB
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
phdri = new Elf_LE32_Phdr[(unsigned) ehdri.e_phnum];
|
||||||
|
fi->seek(ehdri.e_phoff, SEEK_SET);
|
||||||
|
fi->readx(phdri, ehdri.e_phnum * sizeof(*phdri));
|
||||||
|
|
||||||
|
// Put PT_LOAD together at the beginning, ascending by .p_paddr.
|
||||||
|
qsort(phdri, ehdri.e_phnum, sizeof(*phdri), compare_Phdr);
|
||||||
|
|
||||||
|
// 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 (0xfff & (phdri[j].p_offset | phdri[j].p_paddr
|
||||||
|
| phdri[j].p_align | phdri[j].p_vaddr) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (0 < j) {
|
||||||
|
unsigned const sz = (0u - phdri[j-1].p_align)
|
||||||
|
& (phdri[j-1].p_align -1 + phdri[j-1].p_filesz);
|
||||||
|
if ((sz + phdri[j-1].p_offset)!=phdri[j].p_offset) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++n_ptload;
|
||||||
|
sz_ptload = phdri[j].p_filesz + phdri[j].p_offset - phdri[0].p_offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0 < n_ptload;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PackVmlinuxI386::buildLoader(const Filter *ft)
|
||||||
|
{
|
||||||
|
// prepare loader
|
||||||
|
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||||
|
addLoader("LINUX000",
|
||||||
|
(0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""),
|
||||||
|
"LXMOVEUP",
|
||||||
|
getDecompressor(),
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if (ft->id)
|
||||||
|
{
|
||||||
|
assert(ft->calls > 0);
|
||||||
|
if (0x40==(0xf0 & ft->id)) {
|
||||||
|
addLoader("LXCKLLT9", NULL);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addLoader("LXCALLT9", NULL);
|
||||||
|
}
|
||||||
|
addFilter32(ft->id);
|
||||||
|
}
|
||||||
|
addLoader("LINUX990""IDENTSTR""UPX1HEAD", NULL);
|
||||||
|
return getLoaderSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PackVmlinuxI386::pack(OutputFile *fo)
|
||||||
|
{
|
||||||
|
unsigned fo_off = 0;
|
||||||
|
Elf_LE32_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*/];
|
||||||
|
memset(shdro, 0, sizeof(shdro));
|
||||||
|
char const shstrtab[]= "\0.text\0.note\0.shstrtab\0.symtab\0.strtab";
|
||||||
|
char const *p = shstrtab;
|
||||||
|
|
||||||
|
ibuf.alloc(file_size);
|
||||||
|
obuf.allocForCompression(file_size);
|
||||||
|
|
||||||
|
// .e_ident, .e_machine, .e_version, .e_flags
|
||||||
|
memcpy(&ehdro, &ehdri, sizeof(ehdro));
|
||||||
|
ehdro.e_type = Elf_LE32_Ehdr::ET_REL;
|
||||||
|
ehdro.e_entry = 0;
|
||||||
|
ehdro.e_phoff = 0;
|
||||||
|
ehdro.e_shoff = 0; // later
|
||||||
|
ehdro.e_phentsize = 0;
|
||||||
|
ehdro.e_phnum = 0;
|
||||||
|
ehdro.e_shnum = 1+3+1/*+2*/;
|
||||||
|
ehdro.e_shstrndx = 4;
|
||||||
|
fo->write(&ehdro, sizeof(ehdro)); fo_off+= sizeof(ehdro);
|
||||||
|
|
||||||
|
ph.u_len = sz_ptload;
|
||||||
|
fi->seek(phdri[0].p_offset, SEEK_SET);
|
||||||
|
fi->readx(ibuf, ph.u_len);
|
||||||
|
checkAlreadyPacked(ibuf + ph.u_len - 1024, 1024);
|
||||||
|
|
||||||
|
// prepare filter
|
||||||
|
ph.filter = 0;
|
||||||
|
Filter ft(ph.level);
|
||||||
|
ft.buf_len = ph.u_len;
|
||||||
|
ft.addvalue = 0; // we are independent of actual runtime address; see ckt32
|
||||||
|
|
||||||
|
compressWithFilters(&ft, 1 << 20);
|
||||||
|
|
||||||
|
const unsigned lsize = getLoaderSize();
|
||||||
|
MemBuffer loader(lsize);
|
||||||
|
memcpy(loader, getLoader(), lsize);
|
||||||
|
|
||||||
|
patchPackHeader(loader, lsize);
|
||||||
|
patch_le32(loader, lsize, "ULEN", ph.u_len);
|
||||||
|
patchFilter32(loader, lsize, &ft);
|
||||||
|
|
||||||
|
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_offset = fo_off;
|
||||||
|
shdro[1].sh_size = 1+ 4+ ph.c_len + lsize;
|
||||||
|
shdro[1].sh_addralign = 1;
|
||||||
|
|
||||||
|
unsigned char const call = 0xE8; // opcode for CALL d32
|
||||||
|
fo->write(&call, 1); fo_off+=1;
|
||||||
|
tmp_le32 = ph.c_len; fo->write(&tmp_le32, 4); fo_off += 4;
|
||||||
|
fo->write(obuf, ph.c_len); fo_off += ph.c_len;
|
||||||
|
fo->write(loader, lsize); fo_off += lsize;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
printf("%-13s: compressed : %8u bytes\n", getName(), ph.c_len);
|
||||||
|
printf("%-13s: decompressor : %8u bytes\n", getName(), lsize);
|
||||||
|
#endif
|
||||||
|
verifyOverlappingDecompression();
|
||||||
|
|
||||||
|
// .note with 1st page --------------------------------
|
||||||
|
ph.u_len = phdri[0].p_offset;
|
||||||
|
fi->seek(0, SEEK_SET);
|
||||||
|
fi->readx(ibuf, ph.u_len);
|
||||||
|
compress(ibuf, obuf);
|
||||||
|
|
||||||
|
while (0!=*p++) ;
|
||||||
|
shdro[2].sh_name = ptr_diff(p, shstrtab);
|
||||||
|
shdro[2].sh_type = Elf_LE32_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;
|
||||||
|
tmp_le32 = ph.u_len; fo->write(&tmp_le32, 4);
|
||||||
|
fo->write(obuf, ph.c_len); fo_off += shdro[2].sh_size;
|
||||||
|
|
||||||
|
// .note with rest --------------------------------
|
||||||
|
ph.u_len = file_size - (sz_ptload + phdri[0].p_offset);
|
||||||
|
fi->seek(sz_ptload + phdri[0].p_offset, SEEK_SET);
|
||||||
|
fi->readx(ibuf, ph.u_len);
|
||||||
|
|
||||||
|
// Temporarily decrease ph.level by about (1+ log2(sz_rest / sz_ptload))
|
||||||
|
// to avoid spending unreasonable effort compressing large symbol tables
|
||||||
|
// that are discarded 99.9% of the time anyway.
|
||||||
|
int const old_level = ph.level;
|
||||||
|
for (unsigned v = ((ph.u_len>>3) + ph.u_len) / sz_ptload; 0 < v; v>>=1) {
|
||||||
|
if (0== --ph.level) {
|
||||||
|
ph.level = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compress(ibuf, obuf);
|
||||||
|
ph.level = old_level;
|
||||||
|
|
||||||
|
// 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_offset = fo_off;
|
||||||
|
shdro[3].sh_size = sizeof(ph.u_len) + ph.c_len;
|
||||||
|
shdro[3].sh_addralign = 1;
|
||||||
|
tmp_le32 = ph.u_len; fo->write(&tmp_le32, 4);
|
||||||
|
fo->write(obuf, ph.c_len); fo_off += shdro[3].sh_size;
|
||||||
|
|
||||||
|
while (0!=*p++) ;
|
||||||
|
shdro[4].sh_name = ptr_diff(p, shstrtab);
|
||||||
|
shdro[4].sh_type = Elf_LE32_Shdr::SHT_STRTAB;
|
||||||
|
shdro[4].sh_offset = fo_off;
|
||||||
|
shdro[4].sh_size = 1+ sizeof(shstrtab); // 1+: terminating '\0'
|
||||||
|
shdro[4].sh_addralign = 1;
|
||||||
|
fo->write(shstrtab, shdro[4].sh_size); fo_off += shdro[4].sh_size;
|
||||||
|
|
||||||
|
#if 0 /*{ no symbols! */
|
||||||
|
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_offset = fo_off;
|
||||||
|
shdro[5].sh_size = 16; // XXX ?
|
||||||
|
shdro[5].sh_link = 6; // to .strtab for symbols
|
||||||
|
shdro[5].sh_addralign = 4;
|
||||||
|
shdro[5].sh_entsize = 16; // XXX Elf32_Sym
|
||||||
|
fo->seek(fo_off, SEEK_SET);
|
||||||
|
fo->write("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16); fo_off += 16;
|
||||||
|
|
||||||
|
while (0!=*p++) ;
|
||||||
|
shdro[6].sh_name = ptr_diff(p, shstrtab);
|
||||||
|
shdro[6].sh_type = Elf_LE32_Shdr::SHT_STRTAB;
|
||||||
|
shdro[6].sh_offset = fo_off;
|
||||||
|
shdro[6].sh_size = 1; // XXX ?
|
||||||
|
shdro[6].sh_addralign = 1;
|
||||||
|
fo->write("", 1); fo_off += 1;
|
||||||
|
#endif /*}*/
|
||||||
|
|
||||||
|
fo_off = ~3 & (3+ fo_off);
|
||||||
|
fo->seek(fo_off, SEEK_SET);
|
||||||
|
ehdro.e_shoff = fo_off;
|
||||||
|
fo->write(shdro, sizeof(shdro));
|
||||||
|
|
||||||
|
fo->seek(0, SEEK_SET);
|
||||||
|
fo->write(&ehdro, sizeof(ehdro));
|
||||||
|
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// unpack
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int PackVmlinuxI386::canUnpack()
|
||||||
|
{
|
||||||
|
fi->seek(0, SEEK_SET);
|
||||||
|
fi->readx(&ehdri, sizeof(ehdri));
|
||||||
|
|
||||||
|
// now check the ELF header
|
||||||
|
if (memcmp(&ehdri, "\x7f\x45\x4c\x46\x01\x01\x01", 7) // ELF 32-bit LSB
|
||||||
|
|| !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_shnum < 4
|
||||||
|
|| (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf_LE32_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];
|
||||||
|
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
|
||||||
|
&& p->sh_size <= sizeof(shstrtab)
|
||||||
|
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
|
||||||
|
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
|
||||||
|
) {
|
||||||
|
fi->seek(p->sh_offset, SEEK_SET);
|
||||||
|
fi->readx(shstrtab, p->sh_size);
|
||||||
|
if (0==strcmp(".shstrtab", shstrtab + p->sh_name)) {
|
||||||
|
p_shstrtab = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0==p_shstrtab) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for .text .note .note and sane (.sh_size + .sh_offset)
|
||||||
|
p_note0 = p_note1 = p_text = 0;
|
||||||
|
for (p= shdri, j= ehdri.e_shnum; --j>=0; ++p) {
|
||||||
|
if ((unsigned)file_size < (p->sh_size + p->sh_offset)
|
||||||
|
|| p_shstrtab->sh_size < (5+ p->sh_name) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (0==strcmp(".text", shstrtab + p->sh_name)) {
|
||||||
|
p_text = p;
|
||||||
|
}
|
||||||
|
if (0==strcmp(".note", shstrtab + p->sh_name)) {
|
||||||
|
if (0==p_note0) {
|
||||||
|
p_note0 = p;
|
||||||
|
} else
|
||||||
|
if (0==p_note1) {
|
||||||
|
p_note1 = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0==p_text || 0==p_note0 || 0==p_note1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
fi->seek(p_text->sh_offset + p_text->sh_size - sizeof(buf), SEEK_SET);
|
||||||
|
fi->readx(buf, sizeof(buf));
|
||||||
|
if (!getPackHeader(buf, sizeof(buf)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PackVmlinuxI386::unpack(OutputFile *fo)
|
||||||
|
{
|
||||||
|
unsigned char buf[5];
|
||||||
|
PackHeader const ph_tmp(ph);
|
||||||
|
|
||||||
|
fi->seek(p_note0->sh_offset, SEEK_SET);
|
||||||
|
fi->readx(&buf[0], 4);
|
||||||
|
ph.u_len = get_le32(buf);
|
||||||
|
ph.c_len = p_note0->sh_size - 4;
|
||||||
|
ibuf.alloc(ph.c_len);
|
||||||
|
fi->readx(ibuf, ph.c_len);
|
||||||
|
obuf.allocForUncompression(ph.u_len);
|
||||||
|
decompress(ibuf, obuf, false);
|
||||||
|
fo->write(obuf, ph.u_len);
|
||||||
|
obuf.dealloc();
|
||||||
|
ibuf.dealloc();
|
||||||
|
|
||||||
|
ph = ph_tmp;
|
||||||
|
fi->seek(p_text->sh_offset, SEEK_SET);
|
||||||
|
fi->readx(&buf[0], 5);
|
||||||
|
if (0xE8!=buf[0] || get_le32(&buf[1]) != ph.c_len)
|
||||||
|
{
|
||||||
|
throwCantUnpack(".text corrupted");
|
||||||
|
}
|
||||||
|
ibuf.alloc(ph.c_len);
|
||||||
|
fi->readx(ibuf, ph.c_len);
|
||||||
|
obuf.allocForUncompression(ph.u_len);
|
||||||
|
decompress(ibuf, obuf);
|
||||||
|
|
||||||
|
Filter ft(ph.level);
|
||||||
|
ft.init(ph.filter, 0);
|
||||||
|
ft.cto = (unsigned char) ph.filter_cto;
|
||||||
|
ft.unfilter(obuf, ph.u_len);
|
||||||
|
fo->write(obuf, ph.u_len);
|
||||||
|
obuf.dealloc();
|
||||||
|
ibuf.dealloc();
|
||||||
|
|
||||||
|
fi->seek(p_note1->sh_offset, SEEK_SET);
|
||||||
|
fi->readx(&buf[0], 4);
|
||||||
|
ph.u_len = get_le32(buf);
|
||||||
|
ph.c_len = p_note1->sh_size - 4;
|
||||||
|
ibuf.alloc(ph.c_len);
|
||||||
|
fi->readx(ibuf, p_note1->sh_size - sizeof(ph.u_len));
|
||||||
|
obuf.allocForUncompression(ph.u_len);
|
||||||
|
decompress(ibuf, obuf, false);
|
||||||
|
fo->write(obuf, ph.u_len);
|
||||||
|
obuf.dealloc();
|
||||||
|
ibuf.dealloc();
|
||||||
|
|
||||||
|
ph = ph_tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Example usage within build system of Linux kernel-2.6.7:
|
||||||
|
//
|
||||||
|
//----- arch/i386/boot/compressed/Makefile
|
||||||
|
//#
|
||||||
|
//# linux/arch/i386/boot/compressed/Makefile
|
||||||
|
//#
|
||||||
|
//# create a compressed vmlinux image from the original vmlinux
|
||||||
|
//#
|
||||||
|
//
|
||||||
|
//targets := vmlinux upx-head.o upx-piggy.o
|
||||||
|
//
|
||||||
|
//LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32
|
||||||
|
//
|
||||||
|
//$(obj)/vmlinux: $(obj)/upx-head.o $(obj)/upx-piggy.o FORCE
|
||||||
|
// $(call if_changed,ld)
|
||||||
|
// @:
|
||||||
|
//
|
||||||
|
//$(obj)/upx-piggy.o: vmlinux FORCE
|
||||||
|
// rm -f $@
|
||||||
|
// upx --best -o $@ $<
|
||||||
|
//-----
|
||||||
|
//
|
||||||
|
//----- arch/i386/boot/compressed/upx-head.S
|
||||||
|
// .text
|
||||||
|
//startup_32: .globl startup_32 # In: %esi=0x90000 setup data "real_mode pointer"
|
||||||
|
// #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].
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
// */
|
||||||
|
//
|
||||||
|
// pushl $0; popf # subsumes "cli; cld"; also clears NT for buggy BIOS
|
||||||
|
//
|
||||||
|
// movl $ 0x100000,%eax # destination of uncompression (and entry point)
|
||||||
|
// push %cs
|
||||||
|
/* Fall into .text of upx-compressed vmlinux. */
|
||||||
|
//-----
|
||||||
|
|
||||||
|
// Approximate translation for Linux 2.4.x:
|
||||||
|
// - - -
|
||||||
|
// arch/i386/Makefile: LD_FLAGS=-e startup_32
|
||||||
|
//----- arch/i386/boot/compressed/Makefile
|
||||||
|
//# linux/arch/i386/boot/compressed/Makefile
|
||||||
|
//#
|
||||||
|
//# create a compressed vmlinux image from the original vmlinux
|
||||||
|
//#
|
||||||
|
//
|
||||||
|
//HEAD = upx-head.o
|
||||||
|
//SYSTEM = $(TOPDIR)/vmlinux
|
||||||
|
//
|
||||||
|
//OBJECTS = $(HEAD)
|
||||||
|
//
|
||||||
|
//ZLDFLAGS = -e startup_32
|
||||||
|
//
|
||||||
|
//#
|
||||||
|
//# ZIMAGE_OFFSET is the load offset of the compression loader
|
||||||
|
//# BZIMAGE_OFFSET is the load offset of the high loaded compression loader
|
||||||
|
//#
|
||||||
|
//ZIMAGE_OFFSET = 0x1000
|
||||||
|
//BZIMAGE_OFFSET = 0x100000
|
||||||
|
//
|
||||||
|
//ZLINKFLAGS = -Ttext $(ZIMAGE_OFFSET) $(ZLDFLAGS)
|
||||||
|
//BZLINKFLAGS = -Ttext $(BZIMAGE_OFFSET) $(ZLDFLAGS)
|
||||||
|
//
|
||||||
|
//all: vmlinux
|
||||||
|
//
|
||||||
|
//vmlinux: upx-piggy.o $(OBJECTS)
|
||||||
|
// $(LD) $(ZLINKFLAGS) -o vmlinux $(OBJECTS) upx-piggy.o
|
||||||
|
//
|
||||||
|
//bvmlinux: upx-piggy.o $(OBJECTS)
|
||||||
|
// $(LD) $(BZLINKFLAGS) -o bvmlinux $(OBJECTS) upx-piggy.o
|
||||||
|
//
|
||||||
|
//upx-piggy.o: $(SYSTEM)
|
||||||
|
// $(RM) -f $@
|
||||||
|
// upx --best -o $@ $<
|
||||||
|
//
|
||||||
|
//clean:
|
||||||
|
// rm -f vmlinux bvmlinux _tmp_*
|
||||||
|
//-----
|
||||||
|
|
||||||
|
//
|
||||||
|
// Example test jig:
|
||||||
|
// $ gcc -o test-piggy -nostartfiles -nostdlib test-piggy.o piggy.o
|
||||||
|
// $ gdb test-piggy
|
||||||
|
// (gdb) run >dumped
|
||||||
|
// (gdb) /* Execute [single step, etc.; the decompressor+unfilter moves!]
|
||||||
|
// * until reaching the 'lret' at the end of unfilter.
|
||||||
|
// */
|
||||||
|
// (gdb) set $pc= &dump
|
||||||
|
// (gdb) stepi
|
||||||
|
// (gdb) set $edx=<actual_uncompressed_length>
|
||||||
|
// (gdb) continue
|
||||||
|
// (gdb) q
|
||||||
|
// $ # 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>
|
||||||
|
//
|
||||||
|
//dump:
|
||||||
|
// movl $0x456789,%edx # length MODIFY THIS VALUE TO SUIT YOUR CASE
|
||||||
|
// movl $0x100000,%ecx # base
|
||||||
|
// movl $1,%ebx # stdout
|
||||||
|
// movl $ __NR_write,%eax
|
||||||
|
// int $0x80
|
||||||
|
// nop
|
||||||
|
// hlt
|
||||||
|
//mmap:
|
||||||
|
// pushl %ebx
|
||||||
|
// leal 2*4(%esp),%ebx
|
||||||
|
// pushl $ __NR_mmap; popl %eax
|
||||||
|
// int $0x80
|
||||||
|
// popl %ebx
|
||||||
|
// ret $6*4
|
||||||
|
//
|
||||||
|
//_start: .globl _start
|
||||||
|
// nop
|
||||||
|
// int3 # enter debugger!
|
||||||
|
// pushl $0
|
||||||
|
// pushl $0
|
||||||
|
// pushl $ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED
|
||||||
|
// pushl $ PROT_EXEC | PROT_WRITE | PROT_READ
|
||||||
|
// pushl $0x600000 # 6MB length
|
||||||
|
// pushl $0x100000 # 1MB address
|
||||||
|
// call mmap
|
||||||
|
// leal -0x9000(%esp),%esi # expect "lea 0x9000(%esi),%esp" later
|
||||||
|
// push %cs
|
||||||
|
///* Fall into .text of upx-compressed vmlinux. */
|
||||||
|
//-----
|
||||||
|
|
||||||
|
/*
|
||||||
|
vi:ts=4:et
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/* p_vmlinx.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_VMLINX_H
|
||||||
|
#define __UPX_P_VMLINX_H
|
||||||
|
|
||||||
|
#include "p_elf.h"
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// vmlinx/i386 (bare binary Linux kernel image)
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
class PackVmlinuxI386 : public Packer
|
||||||
|
{
|
||||||
|
typedef Packer super;
|
||||||
|
public:
|
||||||
|
PackVmlinuxI386(InputFile *f);
|
||||||
|
virtual ~PackVmlinuxI386();
|
||||||
|
virtual int getVersion() const { return 13; }
|
||||||
|
virtual int getFormat() const { return UPX_F_VMLINUX_i386; }
|
||||||
|
virtual const char *getName() const { return "vmlinux/386"; }
|
||||||
|
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();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual int buildLoader(const Filter *ft);
|
||||||
|
// virtual const upx_byte *getLoader() const;
|
||||||
|
// virtual int getLoaderSize() const;
|
||||||
|
|
||||||
|
int n_ptload;
|
||||||
|
unsigned sz_ptload;
|
||||||
|
Elf_LE32_Phdr *phdri; // from input file
|
||||||
|
Elf_LE32_Shdr *shdri; // from input file
|
||||||
|
Elf_LE32_Shdr *p_text;
|
||||||
|
Elf_LE32_Shdr *p_note0;
|
||||||
|
Elf_LE32_Shdr *p_note1;
|
||||||
|
Elf_LE32_Ehdr ehdri; // from input file
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* already included */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
vi:ts=4:et
|
||||||
|
*/
|
||||||
|
|
||||||
+31
-12
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -38,7 +38,8 @@ static const
|
|||||||
#include "stub/l_vmlinz.h"
|
#include "stub/l_vmlinz.h"
|
||||||
|
|
||||||
static const unsigned kernel_entry = 0x100000;
|
static const unsigned kernel_entry = 0x100000;
|
||||||
static const unsigned stack_during_uncompression = 0x90000;
|
static const unsigned stack_offset_during_uncompression = 0x9000;
|
||||||
|
// add to "real mode pointer" in %esi; total 0x99000 is typical
|
||||||
|
|
||||||
// from /usr/src/linux/arch/i386/boot/compressed/Makefile
|
// from /usr/src/linux/arch/i386/boot/compressed/Makefile
|
||||||
static const unsigned zimage_offset = 0x1000;
|
static const unsigned zimage_offset = 0x1000;
|
||||||
@@ -65,6 +66,7 @@ const int *PackVmlinuzI386::getCompressionMethods(int method, int level) const
|
|||||||
const int *PackVmlinuzI386::getFilters() const
|
const int *PackVmlinuzI386::getFilters() const
|
||||||
{
|
{
|
||||||
static const int filters[] = {
|
static const int filters[] = {
|
||||||
|
0x49,
|
||||||
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
||||||
-1 };
|
-1 };
|
||||||
return filters;
|
return filters;
|
||||||
@@ -197,9 +199,18 @@ int PackVmlinuzI386::decompressKernel()
|
|||||||
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
|
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
|
||||||
throwCantPack("trailing bytes after kernel image; use option `-f' to force packing");
|
throwCantPack("trailing bytes after kernel image; use option `-f' to force packing");
|
||||||
}
|
}
|
||||||
// see /usr/src/linux/arch/i386/kernel/head.S:
|
|
||||||
if (memcmp(ibuf, "\xFC\xB8", 2) != 0)
|
|
||||||
throwCantPack("unrecognized kernel architecture; use option `-f' to force packing");
|
// see /usr/src/linux/arch/i386/kernel/head.S
|
||||||
|
// 2.4.x: cld; mov $...,%eax
|
||||||
|
if (memcmp(ibuf, "\xFC\xB8", 2) == 0) goto head_ok;
|
||||||
|
// 2.6.x: cld; lgdt ...
|
||||||
|
if (memcmp(ibuf, "\xFC\x0F\x01", 3) == 0) goto head_ok;
|
||||||
|
// 2.6.x+grsecurity+strongswan+openwall+trustix: ljmp $0x10,...
|
||||||
|
if (ibuf[0] == 0xEA && memcmp(ibuf+5, "\x10\x00", 2) == 0) goto head_ok;
|
||||||
|
|
||||||
|
throwCantPack("unrecognized kernel architecture; use option `-f' to force packing");
|
||||||
|
head_ok:
|
||||||
|
|
||||||
// FIXME: more checks for special magic bytes in ibuf ???
|
// FIXME: more checks for special magic bytes in ibuf ???
|
||||||
// FIXME: more checks for kernel architecture ???
|
// FIXME: more checks for kernel architecture ???
|
||||||
@@ -263,7 +274,7 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
|||||||
// prepare filter
|
// prepare filter
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.buf_len = ph.u_len;
|
ft.buf_len = ph.u_len;
|
||||||
ft.addvalue = kernel_entry;
|
ft.addvalue = kernel_entry; // saves 4 bytes in unfilter code
|
||||||
// compress
|
// compress
|
||||||
compressWithFilters(&ft, 1 << 20);
|
compressWithFilters(&ft, 1 << 20);
|
||||||
|
|
||||||
@@ -275,7 +286,7 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
|||||||
patchFilter32(loader, lsize, &ft);
|
patchFilter32(loader, lsize, &ft);
|
||||||
patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
|
patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
|
||||||
patch_le32(loader, lsize, "KEIP", kernel_entry);
|
patch_le32(loader, lsize, "KEIP", kernel_entry);
|
||||||
patch_le32(loader, lsize, "STAK", stack_during_uncompression);
|
patch_le32(loader, lsize, "STAK", stack_offset_during_uncompression);
|
||||||
|
|
||||||
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||||
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16) / 16;
|
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16) / 16;
|
||||||
@@ -307,7 +318,7 @@ int PackBvmlinuzI386::buildLoader(const Filter *ft)
|
|||||||
// prepare loader
|
// prepare loader
|
||||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||||
addLoader("LINUZ000",
|
addLoader("LINUZ000",
|
||||||
ft->id ? "LZCALLT1" : "",
|
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
|
||||||
"LBZIMAGE""IDENTSTR",
|
"LBZIMAGE""IDENTSTR",
|
||||||
"+40D++++", // align the stuff to 4 byte boundary
|
"+40D++++", // align the stuff to 4 byte boundary
|
||||||
"UPX1HEAD", // 32 byte
|
"UPX1HEAD", // 32 byte
|
||||||
@@ -318,7 +329,12 @@ int PackBvmlinuzI386::buildLoader(const Filter *ft)
|
|||||||
if (ft->id)
|
if (ft->id)
|
||||||
{
|
{
|
||||||
assert(ft->calls > 0);
|
assert(ft->calls > 0);
|
||||||
addLoader("LZCALLT9", NULL);
|
if (0x40==(0xf0 & ft->id)) {
|
||||||
|
addLoader("LZCKLLT9", NULL);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addLoader("LZCALLT9", NULL);
|
||||||
|
}
|
||||||
addFilter32(ft->id);
|
addFilter32(ft->id);
|
||||||
}
|
}
|
||||||
addLoader("LINUZ990", NULL);
|
addLoader("LINUZ990", NULL);
|
||||||
@@ -333,7 +349,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
|||||||
// prepare filter
|
// prepare filter
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.buf_len = ph.u_len;
|
ft.buf_len = ph.u_len;
|
||||||
ft.addvalue = kernel_entry;
|
ft.addvalue = kernel_entry; // saves 4 bytes in unfilter code
|
||||||
// compress
|
// compress
|
||||||
compressWithFilters(&ft, 512);
|
compressWithFilters(&ft, 512);
|
||||||
|
|
||||||
@@ -366,8 +382,11 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
|||||||
patch_le32(loader, e_len, "EDI0", bzimage_offset + edi);
|
patch_le32(loader, e_len, "EDI0", bzimage_offset + edi);
|
||||||
patch_le32(loader, e_len, "ESI0", bzimage_offset + esi);
|
patch_le32(loader, e_len, "ESI0", bzimage_offset + esi);
|
||||||
|
|
||||||
|
if (0x40==(0xf0 & ft.id)) {
|
||||||
|
patch_le32(loader, e_len, "ULEN", ph.u_len);
|
||||||
|
}
|
||||||
patch_le32(loader, e_len, "KEIP", kernel_entry);
|
patch_le32(loader, e_len, "KEIP", kernel_entry);
|
||||||
patch_le32(loader, e_len, "STAK", stack_during_uncompression);
|
patch_le32(loader, e_len, "STAK", stack_offset_during_uncompression);
|
||||||
|
|
||||||
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||||
bs->sys_size = (ALIGN_UP(lsize + clen, 16) / 16) & 0xffff;
|
bs->sys_size = (ALIGN_UP(lsize + clen, 16) / 16) & 0xffff;
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
+211
-118
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
If not, write to the Free Software Foundation, Inc.,
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -63,7 +63,20 @@ static const
|
|||||||
|
|
||||||
#if defined(__BORLANDC__)
|
#if defined(__BORLANDC__)
|
||||||
# undef strcpy
|
# undef strcpy
|
||||||
# define strcpy(a,b) std::strcpy((char *)(a),(const char *)(b))
|
# define strcpy(a,b) strcpy((char *)(a),(const char *)(b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
static unsigned my_strlen(const char *s)
|
||||||
|
{
|
||||||
|
size_t l = strlen((const char*)s); assert((unsigned) l == l); return (unsigned) l;
|
||||||
|
}
|
||||||
|
static unsigned my_strlen(const unsigned char *s)
|
||||||
|
{
|
||||||
|
size_t l = strlen((const char*)s); assert((unsigned) l == l); return (unsigned) l;
|
||||||
|
}
|
||||||
|
#undef strlen
|
||||||
|
#define strlen my_strlen
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +91,47 @@ static bool ustrsame(const void *s1, const void *s2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if (__ACC_CXX_HAVE_PLACEMENT_DELETE) || defined(__DJGPP__)
|
||||||
|
#include "bptr.h"
|
||||||
|
#define IPTR(type, var) BoundedPtr<type> var(ibuf, ibuf.getSize())
|
||||||
|
#define OPTR(type, var) BoundedPtr<type> var(obuf, obuf.getSize())
|
||||||
|
#define IPTR_I(type, var, v) BoundedPtr<type> var(ibuf, ibuf.getSize(), v)
|
||||||
|
#define OPTR_I(type, var, v) BoundedPtr<type> var(obuf, obuf.getSize(), v)
|
||||||
|
#define IPTR_C(type, var, v) const BoundedPtr<type> var(ibuf, ibuf.getSize(), v)
|
||||||
|
#define OPTR_C(type, var, v) const BoundedPtr<type> var(obuf, obuf.getSize(), v)
|
||||||
|
#else
|
||||||
|
#define IPTR(type, var) type* var = 0
|
||||||
|
#define OPTR(type, var) type* var = 0
|
||||||
|
#define IPTR_I(type, var, v) type* var = (v)
|
||||||
|
#define OPTR_I(type, var, v) type* var = (v)
|
||||||
|
#define IPTR_C(type, var, v) type* const var = (v)
|
||||||
|
#define OPTR_C(type, var, v) type* const var = (v)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void xcheck(const void *p, size_t plen, const void *b, size_t blen)
|
||||||
|
{
|
||||||
|
const char *pp = (const char *) p;
|
||||||
|
const char *bb = (const char *) b;
|
||||||
|
if (pp < bb || pp > bb + blen || pp + plen > bb + blen)
|
||||||
|
throwCantUnpack("pointer out of range; take care!");
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
static void xcheck(size_t poff, size_t plen, const void *b, size_t blen)
|
||||||
|
{
|
||||||
|
ACC_UNUSED(b);
|
||||||
|
if (poff > blen || poff + plen > blen)
|
||||||
|
throwCantUnpack("pointer out of range; take care!");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#define ICHECK(x, size) xcheck(x, size, ibuf, ibuf.getSize())
|
||||||
|
#define OCHECK(x, size) xcheck(x, size, obuf, obuf.getSize())
|
||||||
|
|
||||||
|
#define imemset(a,b,c) ICHECK(a,c), memset(a,b,c)
|
||||||
|
#define omemset(a,b,c) OCHECK(a,c), memset(a,b,c)
|
||||||
|
#define imemcpy(a,b,c) ICHECK(a,c), memcpy(a,b,c)
|
||||||
|
#define omemcpy(a,b,c) OCHECK(a,c), memcpy(a,b,c)
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -88,7 +142,7 @@ PackW32Pe::PackW32Pe(InputFile *f) : super(f)
|
|||||||
//printf("pe_section_t %d\n", (int) sizeof(pe_section_t));
|
//printf("pe_section_t %d\n", (int) sizeof(pe_section_t));
|
||||||
COMPILE_TIME_ASSERT(sizeof(pe_header_t) == 248);
|
COMPILE_TIME_ASSERT(sizeof(pe_header_t) == 248);
|
||||||
COMPILE_TIME_ASSERT(sizeof(pe_section_t) == 40);
|
COMPILE_TIME_ASSERT(sizeof(pe_section_t) == 40);
|
||||||
COMPILE_TIME_ASSERT(RT_LAST == HIGH(opt->w32pe.compress_rt));
|
COMPILE_TIME_ASSERT(RT_LAST == TABLESIZE(opt->win32_pe.compress_rt));
|
||||||
|
|
||||||
isection = NULL;
|
isection = NULL;
|
||||||
oimport = NULL;
|
oimport = NULL;
|
||||||
@@ -214,7 +268,7 @@ public:
|
|||||||
|
|
||||||
unsigned ivnum;
|
unsigned ivnum;
|
||||||
|
|
||||||
Interval(void *b) : capacity(0),base(b),ivarr(0),ivnum(0) {}
|
Interval(void *b) : capacity(0),base(b),ivarr(NULL),ivnum(0) {}
|
||||||
~Interval() {free(ivarr);}
|
~Interval() {free(ivarr);}
|
||||||
|
|
||||||
void add(unsigned start,unsigned len);
|
void add(unsigned start,unsigned len);
|
||||||
@@ -227,7 +281,7 @@ public:
|
|||||||
void dump() const;
|
void dump() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int compare(const void *p1,const void *p2)
|
static int __acc_cdecl_qsort compare(const void *p1,const void *p2)
|
||||||
{
|
{
|
||||||
const interval *i1 = (const interval*) p1;
|
const interval *i1 = (const interval*) p1;
|
||||||
const interval *i2 = (const interval*) p2;
|
const interval *i2 = (const interval*) p2;
|
||||||
@@ -391,7 +445,7 @@ void Reloc::finish(upx_byte *&p,unsigned &siz)
|
|||||||
void PackW32Pe::processRelocs(Reloc *rel) // pass2
|
void PackW32Pe::processRelocs(Reloc *rel) // pass2
|
||||||
{
|
{
|
||||||
rel->finish(oxrelocs,soxrelocs);
|
rel->finish(oxrelocs,soxrelocs);
|
||||||
if (opt->w32pe.strip_relocs && !isdll)
|
if (opt->win32_pe.strip_relocs && !isdll)
|
||||||
soxrelocs = 0;
|
soxrelocs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,10 +457,10 @@ void PackW32Pe::processRelocs() // pass1
|
|||||||
const unsigned *counts = rel.getcounts();
|
const unsigned *counts = rel.getcounts();
|
||||||
const unsigned rnum = counts[1] + counts[2] + counts[3];
|
const unsigned rnum = counts[1] + counts[2] + counts[3];
|
||||||
|
|
||||||
if ((opt->w32pe.strip_relocs && !isdll) || rnum == 0)
|
if ((opt->win32_pe.strip_relocs && !isdll) || rnum == 0)
|
||||||
{
|
{
|
||||||
if (IDSIZE(PEDIR_RELOC))
|
if (IDSIZE(PEDIR_RELOC))
|
||||||
memset(ibuf + IDADDR(PEDIR_RELOC),FILLVAL,IDSIZE(PEDIR_RELOC));
|
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
||||||
orelocs = new upx_byte [1];
|
orelocs = new upx_byte [1];
|
||||||
sorelocs = 0;
|
sorelocs = 0;
|
||||||
return;
|
return;
|
||||||
@@ -432,7 +486,7 @@ void PackW32Pe::processRelocs() // pass1
|
|||||||
}
|
}
|
||||||
fix[3] -= counts[3];
|
fix[3] -= counts[3];
|
||||||
|
|
||||||
memset(ibuf + IDADDR(PEDIR_RELOC),FILLVAL,IDSIZE(PEDIR_RELOC));
|
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
||||||
orelocs = new upx_byte [rnum * 4 + 1024]; // 1024 - safety
|
orelocs = new upx_byte [rnum * 4 + 1024]; // 1024 - safety
|
||||||
sorelocs = ptr_diff(optimizeReloc32((upx_byte*) fix[3],counts[3],orelocs,ibuf + rvamin,1,&big_relocs),orelocs);
|
sorelocs = ptr_diff(optimizeReloc32((upx_byte*) fix[3],counts[3],orelocs,ibuf + rvamin,1,&big_relocs),orelocs);
|
||||||
|
|
||||||
@@ -489,7 +543,7 @@ void PackW32Pe::processImports(unsigned myimport) // pass 2
|
|||||||
|
|
||||||
unsigned PackW32Pe::processImports() // pass 1
|
unsigned PackW32Pe::processImports() // pass 1
|
||||||
{
|
{
|
||||||
static const upx_byte kernel32dll[] = "KERNEL32.DLL";
|
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";
|
||||||
static const char exitp[] = "ExitProcess\x0\x0\x0";
|
static const char exitp[] = "ExitProcess\x0\x0\x0";
|
||||||
|
|
||||||
@@ -514,7 +568,7 @@ unsigned PackW32Pe::processImports() // pass 1
|
|||||||
bool isk32;
|
bool isk32;
|
||||||
unsigned _; // padding to 32
|
unsigned _; // padding to 32
|
||||||
|
|
||||||
static int compare(const void *p1, const void *p2)
|
static int __acc_cdecl_qsort compare(const void *p1, const void *p2)
|
||||||
{
|
{
|
||||||
const udll *u1 = * (const udll * const *) p1;
|
const udll *u1 = * (const udll * const *) p1;
|
||||||
const udll *u2 = * (const udll * const *) p2;
|
const udll *u2 = * (const udll * const *) p2;
|
||||||
@@ -687,11 +741,11 @@ unsigned PackW32Pe::processImports() // pass 1
|
|||||||
}
|
}
|
||||||
ppi++;
|
ppi++;
|
||||||
|
|
||||||
unsigned esize = ptr_diff(tarr,idlls[ic]->lookupt);
|
unsigned esize = ptr_diff((char *)tarr, (char *)idlls[ic]->lookupt);
|
||||||
lookups.add(idlls[ic]->lookupt,esize);
|
lookups.add(idlls[ic]->lookupt,esize);
|
||||||
if (ptr_diff(ibuf + idlls[ic]->iat,idlls[ic]->lookupt))
|
if (ptr_diff(ibuf + idlls[ic]->iat, (char *)idlls[ic]->lookupt))
|
||||||
{
|
{
|
||||||
memcpy(ibuf + idlls[ic]->iat,idlls[ic]->lookupt,esize);
|
memcpy(ibuf + idlls[ic]->iat, idlls[ic]->lookupt, esize);
|
||||||
iats.add(idlls[ic]->iat,esize);
|
iats.add(idlls[ic]->iat,esize);
|
||||||
}
|
}
|
||||||
names.add(idlls[ic]->name,strlen(idlls[ic]->name) + 1 + 1);
|
names.add(idlls[ic]->name,strlen(idlls[ic]->name) + 1 + 1);
|
||||||
@@ -777,7 +831,7 @@ class Export
|
|||||||
Interval iv;
|
Interval iv;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Export(char *base);
|
Export(char *_base);
|
||||||
~Export();
|
~Export();
|
||||||
|
|
||||||
void convert(unsigned eoffs,unsigned esize);
|
void convert(unsigned eoffs,unsigned esize);
|
||||||
@@ -785,6 +839,7 @@ public:
|
|||||||
unsigned getsize() const { return size; }
|
unsigned getsize() const { return size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// disable copy and assignment
|
||||||
Export(const Export&);
|
Export(const Export&);
|
||||||
Export& operator=(const Export&);
|
Export& operator=(const Export&);
|
||||||
};
|
};
|
||||||
@@ -850,7 +905,7 @@ void Export::convert(unsigned eoffs,unsigned esize)
|
|||||||
names[ic + edir.names] = strdup(forw);
|
names[ic + edir.names] = strdup(forw);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
names[ic + edir.names] = 0;
|
names[ic + edir.names] = NULL;
|
||||||
|
|
||||||
len = 2 * edir.names;
|
len = 2 * edir.names;
|
||||||
ordinals = new char[len + 1];
|
ordinals = new char[len + 1];
|
||||||
@@ -866,26 +921,26 @@ void Export::convert(unsigned eoffs,unsigned esize)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Export::build(char *newbase,unsigned newoffs)
|
void Export::build(char *newbase, unsigned newoffs)
|
||||||
{
|
{
|
||||||
char *functionp = newbase + sizeof(edir);
|
char * const functionp = newbase + sizeof(edir);
|
||||||
char *namep = functionp + 4 * edir.functions;
|
char * const namep = functionp + 4 * edir.functions;
|
||||||
char *ordinalp = namep + 4 * edir.names;
|
char * const ordinalp = namep + 4 * edir.names;
|
||||||
char *enamep = ordinalp + 2 * edir.names;
|
char * const enamep = ordinalp + 2 * edir.names;
|
||||||
char *exports = enamep + strlen(ename) + 1;
|
char * exports = enamep + strlen(ename) + 1;
|
||||||
|
|
||||||
edir.addrtable = newoffs + functionp - newbase;
|
edir.addrtable = newoffs + ptr_diff(functionp, newbase);
|
||||||
edir.ordinaltable = newoffs + ordinalp - newbase;
|
edir.ordinaltable = newoffs + ptr_diff(ordinalp, newbase);
|
||||||
memcpy(ordinalp,ordinals,2 * edir.names);
|
memcpy(ordinalp,ordinals,2 * edir.names);
|
||||||
|
|
||||||
edir.name = newoffs + enamep - newbase;
|
edir.name = newoffs + ptr_diff(enamep, newbase);
|
||||||
strcpy(enamep,ename);
|
strcpy(enamep,ename);
|
||||||
edir.nameptrtable = newoffs + namep - newbase;
|
edir.nameptrtable = newoffs + ptr_diff(namep, newbase);
|
||||||
unsigned ic;
|
unsigned ic;
|
||||||
for (ic = 0; ic < edir.names; ic++)
|
for (ic = 0; ic < edir.names; ic++)
|
||||||
{
|
{
|
||||||
strcpy(exports,names[ic]);
|
strcpy(exports,names[ic]);
|
||||||
set_le32(namep + 4 * ic,newoffs + exports - newbase);
|
set_le32(namep + 4 * ic,newoffs + ptr_diff(exports, newbase));
|
||||||
exports += strlen(exports) + 1;
|
exports += strlen(exports) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -894,7 +949,7 @@ void Export::build(char *newbase,unsigned newoffs)
|
|||||||
if (names[edir.names + ic])
|
if (names[edir.names + ic])
|
||||||
{
|
{
|
||||||
strcpy(exports,names[edir.names + ic]);
|
strcpy(exports,names[edir.names + ic]);
|
||||||
set_le32(functionp + 4 * ic,newoffs + exports - newbase);
|
set_le32(functionp + 4 * ic,newoffs + ptr_diff(exports, newbase));
|
||||||
exports += strlen(exports) + 1;
|
exports += strlen(exports) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,7 +962,7 @@ void PackW32Pe::processExports(Export *xport) // pass1
|
|||||||
soexport = ALIGN_UP(IDSIZE(PEDIR_EXPORT),4);
|
soexport = ALIGN_UP(IDSIZE(PEDIR_EXPORT),4);
|
||||||
if (soexport == 0)
|
if (soexport == 0)
|
||||||
return;
|
return;
|
||||||
if (!isdll && opt->w32pe.compress_exports)
|
if (!isdll && opt->win32_pe.compress_exports)
|
||||||
{
|
{
|
||||||
infoWarning("exports compressed, --compress-exports=0 might be needed");
|
infoWarning("exports compressed, --compress-exports=0 might be needed");
|
||||||
soexport = 0;
|
soexport = 0;
|
||||||
@@ -1063,13 +1118,13 @@ class Resource
|
|||||||
upx_byte *name;
|
upx_byte *name;
|
||||||
upx_rnode *parent;
|
upx_rnode *parent;
|
||||||
};
|
};
|
||||||
struct upx_rbranch : upx_rnode
|
struct upx_rbranch : public upx_rnode
|
||||||
{
|
{
|
||||||
unsigned nc;
|
unsigned nc;
|
||||||
upx_rnode **children;
|
upx_rnode **children;
|
||||||
res_dir data;
|
res_dir data;
|
||||||
};
|
};
|
||||||
struct upx_rleaf : upx_rnode
|
struct upx_rleaf : public upx_rnode
|
||||||
{
|
{
|
||||||
upx_rleaf *next;
|
upx_rleaf *next;
|
||||||
unsigned newoffset;
|
unsigned newoffset;
|
||||||
@@ -1098,7 +1153,7 @@ public:
|
|||||||
void init(const upx_byte *);
|
void init(const upx_byte *);
|
||||||
|
|
||||||
unsigned dirsize() const {return ALIGN_UP(dsize + ssize,4);}
|
unsigned dirsize() const {return ALIGN_UP(dsize + ssize,4);}
|
||||||
bool next() {return (current = current ? current->next : head) != 0;} // wow, builtin autorewind... :-)
|
bool next() {return (current = current ? current->next : head) != NULL;} // wow, builtin autorewind... :-)
|
||||||
|
|
||||||
unsigned itype() const {return current->parent->parent->id;}
|
unsigned itype() const {return current->parent->parent->id;}
|
||||||
const upx_byte *ntype() const {return current->parent->parent->name;}
|
const upx_byte *ntype() const {return current->parent->parent->name;}
|
||||||
@@ -1126,10 +1181,10 @@ void Resource::init(const upx_byte *res)
|
|||||||
COMPILE_TIME_ASSERT(sizeof(res_data) == 16);
|
COMPILE_TIME_ASSERT(sizeof(res_data) == 16);
|
||||||
|
|
||||||
start = res;
|
start = res;
|
||||||
root = head = current = 0;
|
root = head = current = NULL;
|
||||||
dsize = ssize = 0;
|
dsize = ssize = 0;
|
||||||
check((const res_dir*) start,0);
|
check((const res_dir*) start,0);
|
||||||
root = convert(start,0,0);
|
root = convert(start,NULL,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::check(const res_dir *node,unsigned level)
|
void Resource::check(const res_dir *node,unsigned level)
|
||||||
@@ -1153,7 +1208,7 @@ Resource::upx_rnode *Resource::convert(const void *rnode,upx_rnode *parent,unsig
|
|||||||
{
|
{
|
||||||
const res_data *node = (const res_data *) rnode;
|
const res_data *node = (const res_data *) rnode;
|
||||||
upx_rleaf *leaf = new upx_rleaf;
|
upx_rleaf *leaf = new upx_rleaf;
|
||||||
leaf->name = 0;
|
leaf->name = NULL;
|
||||||
leaf->parent = parent;
|
leaf->parent = parent;
|
||||||
leaf->next = head;
|
leaf->next = head;
|
||||||
leaf->newoffset = 0;
|
leaf->newoffset = 0;
|
||||||
@@ -1166,7 +1221,7 @@ Resource::upx_rnode *Resource::convert(const void *rnode,upx_rnode *parent,unsig
|
|||||||
|
|
||||||
const res_dir *node = (const res_dir *) rnode;
|
const res_dir *node = (const res_dir *) rnode;
|
||||||
upx_rbranch *branch = new upx_rbranch;
|
upx_rbranch *branch = new upx_rbranch;
|
||||||
branch->name = 0;
|
branch->name = NULL;
|
||||||
branch->parent = parent;
|
branch->parent = parent;
|
||||||
int ic = branch->nc = node->identr + node->namedentr;
|
int ic = branch->nc = node->identr + node->namedentr;
|
||||||
branch->children = new upx_rnode*[ic];
|
branch->children = new upx_rnode*[ic];
|
||||||
@@ -1317,20 +1372,20 @@ void PackW32Pe::processResources(Resource *res)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// setup default options for resource compression
|
// setup default options for resource compression
|
||||||
if (opt->w32pe.compress_resources < 0)
|
if (opt->win32_pe.compress_resources < 0)
|
||||||
opt->w32pe.compress_resources = true;
|
opt->win32_pe.compress_resources = true;
|
||||||
if (!opt->w32pe.compress_resources)
|
if (!opt->win32_pe.compress_resources)
|
||||||
{
|
{
|
||||||
opt->w32pe.compress_icons = false;
|
opt->win32_pe.compress_icons = false;
|
||||||
for (int i = 0; i < RT_LAST; i++)
|
for (int i = 0; i < RT_LAST; i++)
|
||||||
opt->w32pe.compress_rt[i] = false;
|
opt->win32_pe.compress_rt[i] = false;
|
||||||
}
|
}
|
||||||
if (opt->w32pe.compress_rt[RT_STRING] < 0)
|
if (opt->win32_pe.compress_rt[RT_STRING] < 0)
|
||||||
{
|
{
|
||||||
// by default, don't compress RT_STRINGs of screensavers (".scr")
|
// by default, don't compress RT_STRINGs of screensavers (".scr")
|
||||||
opt->w32pe.compress_rt[RT_STRING] = true;
|
opt->win32_pe.compress_rt[RT_STRING] = true;
|
||||||
if (fn_has_ext(fi->getName(),"scr"))
|
if (fn_has_ext(fi->getName(),"scr"))
|
||||||
opt->w32pe.compress_rt[RT_STRING] = false;
|
opt->win32_pe.compress_rt[RT_STRING] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
res->init(ibuf + vaddr);
|
res->init(ibuf + vaddr);
|
||||||
@@ -1341,7 +1396,7 @@ void PackW32Pe::processResources(Resource *res)
|
|||||||
upx_byte *ores = oresources + res->dirsize();
|
upx_byte *ores = oresources + res->dirsize();
|
||||||
|
|
||||||
unsigned iconsin1stdir = 0;
|
unsigned iconsin1stdir = 0;
|
||||||
if (opt->w32pe.compress_icons == 2)
|
if (opt->win32_pe.compress_icons == 2)
|
||||||
while (res->next()) // there is no rewind() in Resource
|
while (res->next()) // there is no rewind() in Resource
|
||||||
if (res->itype() == RT_GROUP_ICON && iconsin1stdir == 0)
|
if (res->itype() == RT_GROUP_ICON && iconsin1stdir == 0)
|
||||||
iconsin1stdir = get_le16(ibuf + res->offs() + 4);
|
iconsin1stdir = get_le16(ibuf + res->offs() + 4);
|
||||||
@@ -1359,16 +1414,16 @@ void PackW32Pe::processResources(Resource *res)
|
|||||||
{
|
{
|
||||||
const unsigned rtype = res->itype();
|
const unsigned rtype = res->itype();
|
||||||
bool do_compress = true;
|
bool do_compress = true;
|
||||||
if (!opt->w32pe.compress_resources)
|
if (!opt->win32_pe.compress_resources)
|
||||||
do_compress = false;
|
do_compress = false;
|
||||||
else if (rtype == RT_VERSION) // version info
|
else if (rtype == RT_VERSION) // version info
|
||||||
do_compress = false;
|
do_compress = false;
|
||||||
else if (rtype == RT_ICON) // icon
|
else if (rtype == RT_ICON) // icon
|
||||||
do_compress = compress_icon && opt->w32pe.compress_icons;
|
do_compress = compress_icon && opt->win32_pe.compress_icons;
|
||||||
else if (rtype == RT_GROUP_ICON) // icon directory
|
else if (rtype == RT_GROUP_ICON) // icon directory
|
||||||
do_compress = compress_idir && opt->w32pe.compress_icons;
|
do_compress = compress_idir && opt->win32_pe.compress_icons;
|
||||||
else if (rtype > 0 && rtype < RT_LAST)
|
else if (rtype > 0 && rtype < RT_LAST)
|
||||||
do_compress = opt->w32pe.compress_rt[rtype] ? true : false;
|
do_compress = opt->win32_pe.compress_rt[rtype] ? true : false;
|
||||||
else if (res->ntype()) // named resource type
|
else if (res->ntype()) // named resource type
|
||||||
{
|
{
|
||||||
const upx_byte * const t = res->ntype();
|
const upx_byte * const t = res->ntype();
|
||||||
@@ -1390,14 +1445,15 @@ void PackW32Pe::processResources(Resource *res)
|
|||||||
|
|
||||||
set_le32(ores,res->offs()); // save original offset
|
set_le32(ores,res->offs()); // save original offset
|
||||||
ores += 4;
|
ores += 4;
|
||||||
memcpy(ores,ibuf + res->offs(),res->size());
|
ICHECK(ibuf + res->offs(), res->size());
|
||||||
memset(ibuf + res->offs(),FILLVAL,res->size());
|
memcpy(ores, ibuf + res->offs(), res->size());
|
||||||
|
ibuf.fill(res->offs(), res->size(), FILLVAL);
|
||||||
res->newoffs() = ptr_diff(ores,oresources);
|
res->newoffs() = ptr_diff(ores,oresources);
|
||||||
if (rtype == RT_ICON)
|
if (rtype == RT_ICON)
|
||||||
compress_icon = (++iconcnt >= iconsin1stdir || opt->w32pe.compress_icons == 1);
|
compress_icon = (++iconcnt >= iconsin1stdir || opt->win32_pe.compress_icons == 1);
|
||||||
else if (rtype == RT_GROUP_ICON)
|
else if (rtype == RT_GROUP_ICON)
|
||||||
{
|
{
|
||||||
if (opt->w32pe.compress_icons == 1)
|
if (opt->win32_pe.compress_icons == 1)
|
||||||
{
|
{
|
||||||
icondir_offset = 4 + ptr_diff(ores,oresources);
|
icondir_offset = 4 + ptr_diff(ores,oresources);
|
||||||
icondir_count = get_le16(oresources + icondir_offset);
|
icondir_count = get_le16(oresources + icondir_offset);
|
||||||
@@ -1465,7 +1521,7 @@ unsigned PackW32Pe::stripDebug(unsigned overlaystart)
|
|||||||
for (unsigned ic = 0; ic < IDSIZE(PEDIR_DEBUG) / sizeof(debug_dir_t); ic++, dd++)
|
for (unsigned ic = 0; ic < IDSIZE(PEDIR_DEBUG) / sizeof(debug_dir_t); ic++, dd++)
|
||||||
if (overlaystart == dd->fpos)
|
if (overlaystart == dd->fpos)
|
||||||
overlaystart += dd->size;
|
overlaystart += dd->size;
|
||||||
memset(ibuf + IDADDR(PEDIR_DEBUG),FILLVAL,IDSIZE(PEDIR_DEBUG));
|
ibuf.fill(IDADDR(PEDIR_DEBUG), IDSIZE(PEDIR_DEBUG), FILLVAL);
|
||||||
return overlaystart;
|
return overlaystart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1484,12 +1540,19 @@ bool PackW32Pe::canPack()
|
|||||||
|
|
||||||
int PackW32Pe::buildLoader(const Filter *ft)
|
int PackW32Pe::buildLoader(const Filter *ft)
|
||||||
{
|
{
|
||||||
|
// recompute tlsindex (see pack() below)
|
||||||
|
unsigned tmp_tlsindex = tlsindex;
|
||||||
|
const unsigned oam1 = ih.objectalign - 1;
|
||||||
|
const unsigned newvsize = (ph.u_len + rvamin + ph.overlap_overhead + oam1) &~ oam1;
|
||||||
|
if (tlsindex && ((newvsize - ph.c_len - 1024 + oam1) &~ oam1) > tlsindex + 4)
|
||||||
|
tmp_tlsindex = 0;
|
||||||
|
|
||||||
// prepare loader
|
// prepare loader
|
||||||
initLoader(nrv_loader, sizeof(nrv_loader), -1, 2);
|
initLoader(nrv_loader, sizeof(nrv_loader), -1, 2);
|
||||||
addLoader(isdll ? "PEISDLL1" : "",
|
addLoader(isdll ? "PEISDLL1" : "",
|
||||||
"PEMAIN01",
|
"PEMAIN01",
|
||||||
icondir_count > 1 ? (icondir_count == 2 ? "PEICONS1" : "PEICONS2") : "",
|
icondir_count > 1 ? (icondir_count == 2 ? "PEICONS1" : "PEICONS2") : "",
|
||||||
tlsindex ? "PETLSHAK" : "",
|
tmp_tlsindex ? "PETLSHAK" : "",
|
||||||
"PEMAIN02",
|
"PEMAIN02",
|
||||||
getDecompressor(),
|
getDecompressor(),
|
||||||
/*multipass ? "PEMULTIP" : */ "",
|
/*multipass ? "PEMULTIP" : */ "",
|
||||||
@@ -1539,7 +1602,10 @@ int PackW32Pe::buildLoader(const Filter *ft)
|
|||||||
|
|
||||||
void PackW32Pe::pack(OutputFile *fo)
|
void PackW32Pe::pack(OutputFile *fo)
|
||||||
{
|
{
|
||||||
unsigned objs = ih.objects;
|
if (opt->win32_pe.strip_loadconf < 0)
|
||||||
|
opt->win32_pe.strip_loadconf = false;
|
||||||
|
|
||||||
|
const unsigned objs = ih.objects;
|
||||||
isection = new pe_section_t[objs];
|
isection = new pe_section_t[objs];
|
||||||
fi->seek(pe_offset+sizeof(ih),SEEK_SET);
|
fi->seek(pe_offset+sizeof(ih),SEEK_SET);
|
||||||
fi->readx(isection,sizeof(pe_section_t)*objs);
|
fi->readx(isection,sizeof(pe_section_t)*objs);
|
||||||
@@ -1550,8 +1616,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// check the PE header
|
// check the PE header
|
||||||
// FIXME: add more checks
|
// FIXME: add more checks
|
||||||
if (!opt->force
|
if (!opt->force && (
|
||||||
&& (ih.cpu < 0x14c || ih.cpu > 0x150
|
ih.cpu < 0x14c || ih.cpu > 0x150
|
||||||
|| ih.opthdrsize != 0xE0
|
|| ih.opthdrsize != 0xE0
|
||||||
|| (ih.flags & EXECUTABLE) == 0
|
|| (ih.flags & EXECUTABLE) == 0
|
||||||
|| (ih.subsystem != 2 && ih.subsystem != 3 && ih.subsystem != 1)
|
|| (ih.subsystem != 2 && ih.subsystem != 3 && ih.subsystem != 1)
|
||||||
@@ -1559,20 +1625,23 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
|| ih.ddirsentries != 16
|
|| ih.ddirsentries != 16
|
||||||
|| IDSIZE(PEDIR_EXCEPTION) // is this used on i386?
|
|| IDSIZE(PEDIR_EXCEPTION) // is this used on i386?
|
||||||
// || IDSIZE(PEDIR_COPYRIGHT)
|
// || IDSIZE(PEDIR_COPYRIGHT)
|
||||||
|| IDSIZE(PEDIR_LOADCONF)
|
|
||||||
|| IDSIZE(PEDIR_COMRT)
|
|
||||||
))
|
))
|
||||||
throwCantPack("unexpected value in PE header (try --force)");
|
throwCantPack("unexpected value in PE header (try --force)");
|
||||||
|
|
||||||
if (IDSIZE(PEDIR_SEC))
|
if (IDSIZE(PEDIR_SEC))
|
||||||
throwCantPack("compressing certificate info is not supported");
|
throwCantPack("compressing certificate info is not supported");
|
||||||
//if (IDSIZE(PEDIR_DELAYIMP))
|
if (IDSIZE(PEDIR_COMRT))
|
||||||
// throwCantPack("delay load imports are not supported");
|
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)
|
if (isdll)
|
||||||
opt->w32pe.strip_relocs = 0;
|
opt->win32_pe.strip_relocs = false;
|
||||||
else if (opt->w32pe.strip_relocs < 0)
|
else if (opt->win32_pe.strip_relocs < 0)
|
||||||
opt->w32pe.strip_relocs = (ih.imagebase >= 0x400000);
|
opt->win32_pe.strip_relocs = (ih.imagebase >= 0x400000);
|
||||||
if (opt->w32pe.strip_relocs)
|
if (opt->win32_pe.strip_relocs)
|
||||||
if (ih.imagebase < 0x400000)
|
if (ih.imagebase < 0x400000)
|
||||||
throwCantPack("--strip-relocs is not allowed when imagebase < 0x400000");
|
throwCantPack("--strip-relocs is not allowed when imagebase < 0x400000");
|
||||||
else
|
else
|
||||||
@@ -1601,7 +1670,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
Interval holes(ibuf);
|
Interval holes(ibuf);
|
||||||
|
|
||||||
unsigned ic,jc,overlaystart = 0;
|
unsigned ic,jc,overlaystart = 0;
|
||||||
memset(ibuf,0,usize);
|
ibuf.clear(0, usize);
|
||||||
for (ic = jc = 0; ic < objs; ic++)
|
for (ic = jc = 0; ic < objs; ic++)
|
||||||
{
|
{
|
||||||
if (isection[ic].rawdataptr && overlaystart < isection[ic].rawdataptr + isection[ic].size)
|
if (isection[ic].rawdataptr && overlaystart < isection[ic].rawdataptr + isection[ic].size)
|
||||||
@@ -1668,7 +1737,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
|| (isection[virta2objnum(ih.codebase,isection,objs)].flags & PEFL_CODE) == 0)
|
|| (isection[virta2objnum(ih.codebase,isection,objs)].flags & PEFL_CODE) == 0)
|
||||||
allow_filter = false;
|
allow_filter = false;
|
||||||
|
|
||||||
const unsigned oam1 = ih.objectalign-1;
|
const unsigned oam1 = ih.objectalign - 1;
|
||||||
|
|
||||||
// FIXME: disabled: the uncompressor would not allocate enough memory
|
// FIXME: disabled: the uncompressor would not allocate enough memory
|
||||||
//objs = tryremove(IDADDR(PEDIR_RELOC),objs);
|
//objs = tryremove(IDADDR(PEDIR_RELOC),objs);
|
||||||
@@ -1727,7 +1796,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
int strategy = allow_filter ? 0 : -3;
|
int strategy = allow_filter ? 0 : -3;
|
||||||
compressWithFilters(&ft, 2048, strategy,
|
compressWithFilters(&ft, 2048, strategy,
|
||||||
NULL, 0, 0, ih.codebase, rvamin);
|
NULL, 0, 0, ih.codebase, rvamin);
|
||||||
|
// info: see buildLoader()
|
||||||
newvsize = (ph.u_len + rvamin + ph.overlap_overhead + oam1) &~ oam1;
|
newvsize = (ph.u_len + rvamin + ph.overlap_overhead + oam1) &~ oam1;
|
||||||
if (tlsindex && ((newvsize - ph.c_len - 1024 + oam1) &~ oam1) > tlsindex + 4)
|
if (tlsindex && ((newvsize - ph.c_len - 1024 + oam1) &~ oam1) > tlsindex + 4)
|
||||||
tlsindex = 0;
|
tlsindex = 0;
|
||||||
@@ -1758,11 +1827,11 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
else if (((identsplit + identsize) ^ identsplit) < 0x200)
|
else if (((identsplit + identsize) ^ identsplit) < 0x200)
|
||||||
identsplit = identsize;
|
identsplit = identsize;
|
||||||
else
|
else
|
||||||
identsplit = ALIGN_UP(identsplit, 0x200) - identsplit;
|
identsplit = ALIGN_GAP(identsplit, 0x200);
|
||||||
ic = identsize - identsplit;
|
ic = identsize - identsplit;
|
||||||
|
|
||||||
const unsigned clen = ((ph.c_len + ic) & 15) == 0 ? ph.c_len : ph.c_len + 16 - ((ph.c_len + ic) & 15);
|
const unsigned clen = ((ph.c_len + ic) & 15) == 0 ? ph.c_len : ph.c_len + 16 - ((ph.c_len + ic) & 15);
|
||||||
memset(obuf + ph.c_len, 0, clen - ph.c_len);
|
obuf.clear(ph.c_len, clen - ph.c_len);
|
||||||
|
|
||||||
const unsigned s1size = ALIGN_UP(ic + clen + codesize,4) + sotls;
|
const unsigned s1size = ALIGN_UP(ic + clen + codesize,4) + sotls;
|
||||||
const unsigned s1addr = (newvsize - (ic + clen) + oam1) &~ oam1;
|
const unsigned s1addr = (newvsize - (ic + clen) + oam1) &~ oam1;
|
||||||
@@ -1778,7 +1847,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
patch_le32(loader,codesize + 4,"JMPO",ih.entry - upxsection - jmp_pos - 4);
|
patch_le32(loader,codesize + 4,"JMPO",ih.entry - upxsection - jmp_pos - 4);
|
||||||
}
|
}
|
||||||
if (big_relocs & 6)
|
if (big_relocs & 6)
|
||||||
patch_le32(loader,codesize,"DELT", 0u -ih.imagebase - rvamin);
|
patch_le32(loader,codesize,"DELT", 0u - (unsigned) ih.imagebase - rvamin);
|
||||||
if (sorelocs && (soimport == 0 || soimport + cimports != crelocs))
|
if (sorelocs && (soimport == 0 || soimport + cimports != crelocs))
|
||||||
patch_le32(loader,codesize,"BREL",crelocs);
|
patch_le32(loader,codesize,"BREL",crelocs);
|
||||||
if (soimport)
|
if (soimport)
|
||||||
@@ -1818,8 +1887,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const unsigned esi0 = s1addr + ic;
|
const unsigned esi0 = s1addr + ic;
|
||||||
patch_le32(loader,codesize,"EDI0", 0u-esi0 + rvamin);
|
patch_le32(loader,codesize,"EDI0", 0u - esi0 + rvamin);
|
||||||
patch_le32(loader,codesize,"ESI0",esi0 + ih.imagebase);
|
patch_le32(loader,codesize,"ESI0", esi0 + ih.imagebase);
|
||||||
ic = getLoaderSection("PEMAIN01") + 2 + upxsection;
|
ic = getLoaderSection("PEMAIN01") + 2 + upxsection;
|
||||||
|
|
||||||
Reloc rel(1024); // new relocations are put here
|
Reloc rel(1024); // new relocations are put here
|
||||||
@@ -1831,7 +1900,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
memset(osection,0,sizeof(osection));
|
memset(osection,0,sizeof(osection));
|
||||||
|
|
||||||
oh.entry = upxsection;
|
oh.entry = upxsection;
|
||||||
oh.objects = HIGH(osection);
|
oh.objects = 3;
|
||||||
oh.chksum = 0;
|
oh.chksum = 0;
|
||||||
|
|
||||||
// fill the data directory
|
// fill the data directory
|
||||||
@@ -1842,6 +1911,12 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
ODADDR(PEDIR_BOUNDIM) = 0;
|
ODADDR(PEDIR_BOUNDIM) = 0;
|
||||||
ODSIZE(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
|
// tls is put into section 1
|
||||||
|
|
||||||
ic = s1addr + s1size - sotls;
|
ic = s1addr + s1size - sotls;
|
||||||
@@ -1865,7 +1940,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
processExports(&xport,ic);
|
processExports(&xport,ic);
|
||||||
ODADDR(PEDIR_EXPORT) = soexport ? ic : 0;
|
ODADDR(PEDIR_EXPORT) = soexport ? ic : 0;
|
||||||
ODSIZE(PEDIR_EXPORT) = soexport;
|
ODSIZE(PEDIR_EXPORT) = soexport;
|
||||||
if (!isdll && opt->w32pe.compress_exports)
|
if (!isdll && opt->win32_pe.compress_exports)
|
||||||
{
|
{
|
||||||
ODADDR(PEDIR_EXPORT) = IDADDR(PEDIR_EXPORT);
|
ODADDR(PEDIR_EXPORT) = IDADDR(PEDIR_EXPORT);
|
||||||
ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT);
|
ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT);
|
||||||
@@ -1927,13 +2002,12 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
// oh.headersize = osection[0].rawdataptr;
|
// oh.headersize = osection[0].rawdataptr;
|
||||||
oh.headersize = rvamin;
|
oh.headersize = rvamin;
|
||||||
|
|
||||||
if (opt->w32pe.strip_relocs && !isdll)
|
if (opt->win32_pe.strip_relocs && !isdll)
|
||||||
oh.flags |= RELOCS_STRIPPED;
|
oh.flags |= RELOCS_STRIPPED;
|
||||||
|
|
||||||
//for (ic = 0; ic < oh.filealign; ic += 4)
|
//for (ic = 0; ic < oh.filealign; ic += 4)
|
||||||
// set_le32(ibuf + ic,get_le32("UPX "));
|
// set_le32(ibuf + ic,get_le32("UPX "));
|
||||||
assert(oh.filealign <= ibuf.getSize());
|
ibuf.clear(0, oh.filealign);
|
||||||
memset(ibuf,0,oh.filealign);
|
|
||||||
|
|
||||||
infoHeader("[Writing compressed file]");
|
infoHeader("[Writing compressed file]");
|
||||||
|
|
||||||
@@ -2027,14 +2101,14 @@ int PackW32Pe::canUnpack()
|
|||||||
if (is_packed && ih.entry < isection[2].vaddr)
|
if (is_packed && ih.entry < isection[2].vaddr)
|
||||||
{
|
{
|
||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
bool x = false;
|
bool x = false;
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
try {
|
try {
|
||||||
fi->seek(ih.entry - isection[1].vaddr + isection[1].rawdataptr, SEEK_SET);
|
fi->seek(ih.entry - isection[1].vaddr + isection[1].rawdataptr, SEEK_SET);
|
||||||
fi->read(buf, sizeof(buf));
|
fi->read(buf, sizeof(buf));
|
||||||
|
|
||||||
static const char magic[] = "\x8b\x1e\x83\xee\xfc\x11\xdb";
|
static const unsigned char magic[] = "\x8b\x1e\x83\xee\xfc\x11\xdb";
|
||||||
// mov ebx, [esi]; sub esi, -4; adc ebx,ebx
|
// mov ebx, [esi]; sub esi, -4; adc ebx,ebx
|
||||||
|
|
||||||
int offset = find(buf, sizeof(buf), magic, 7);
|
int offset = find(buf, sizeof(buf), magic, 7);
|
||||||
@@ -2052,7 +2126,7 @@ int PackW32Pe::canUnpack()
|
|||||||
|
|
||||||
// FIXME: what should we say here ?
|
// FIXME: what should we say here ?
|
||||||
//throwCantUnpack("file is possibly modified/hacked/protected; take care!");
|
//throwCantUnpack("file is possibly modified/hacked/protected; take care!");
|
||||||
return false; // not reached
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2061,18 +2135,25 @@ void PackW32Pe::rebuildImports(upx_byte *& extrainfo)
|
|||||||
if (ODADDR(PEDIR_IMPORT) == 0)
|
if (ODADDR(PEDIR_IMPORT) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const upx_byte * const idata = obuf + get_le32(extrainfo);
|
// const upx_byte * const idata = obuf + get_le32(extrainfo);
|
||||||
|
OPTR_C(const upx_byte, idata, obuf + get_le32(extrainfo));
|
||||||
const unsigned inamespos = get_le32(extrainfo + 4);
|
const unsigned inamespos = get_le32(extrainfo + 4);
|
||||||
extrainfo += 8;
|
extrainfo += 8;
|
||||||
|
|
||||||
unsigned sdllnames = 0;
|
unsigned sdllnames = 0;
|
||||||
|
|
||||||
const upx_byte *import = ibuf + IDADDR(PEDIR_IMPORT) - isection[2].vaddr;
|
// const upx_byte *import = ibuf + IDADDR(PEDIR_IMPORT) - isection[2].vaddr;
|
||||||
const upx_byte *p = idata;
|
// const upx_byte *p;
|
||||||
|
IPTR_I(const upx_byte, import, ibuf + IDADDR(PEDIR_IMPORT) - isection[2].vaddr);
|
||||||
|
OPTR(const upx_byte, p);
|
||||||
|
|
||||||
while (get_le32(p))
|
for (p = idata; get_le32(p) != 0; ++p)
|
||||||
{
|
{
|
||||||
sdllnames += strlen(get_le32(p) + import) + 1;
|
const upx_byte *dname = get_le32(p) + import;
|
||||||
|
const unsigned dlen = strlen(dname);
|
||||||
|
ICHECK(dname, dlen + 1);
|
||||||
|
|
||||||
|
sdllnames += dlen + 1;
|
||||||
for (p += 8; *p;)
|
for (p += 8; *p;)
|
||||||
if (*p == 1)
|
if (*p == 1)
|
||||||
p += strlen(++p) + 1;
|
p += strlen(++p) + 1;
|
||||||
@@ -2080,8 +2161,6 @@ void PackW32Pe::rebuildImports(upx_byte *& extrainfo)
|
|||||||
p += 3; // ordinal
|
p += 3; // ordinal
|
||||||
else
|
else
|
||||||
p += 5;
|
p += 5;
|
||||||
|
|
||||||
p++;
|
|
||||||
}
|
}
|
||||||
sdllnames = ALIGN_UP(sdllnames,2);
|
sdllnames = ALIGN_UP(sdllnames,2);
|
||||||
|
|
||||||
@@ -2091,40 +2170,53 @@ void PackW32Pe::rebuildImports(upx_byte *& extrainfo)
|
|||||||
upx_byte *dllnames = Obuf + inamespos;
|
upx_byte *dllnames = Obuf + inamespos;
|
||||||
upx_byte *importednames = dllnames + sdllnames;
|
upx_byte *importednames = dllnames + sdllnames;
|
||||||
|
|
||||||
for (p = idata; get_le32(p); p++)
|
for (p = idata; get_le32(p) != 0; ++p)
|
||||||
{
|
{
|
||||||
// restore the name of the dll
|
// restore the name of the dll
|
||||||
|
const upx_byte *dname = get_le32(p) + import;
|
||||||
|
const unsigned dlen = strlen(dname);
|
||||||
|
ICHECK(dname, dlen + 1);
|
||||||
|
|
||||||
const unsigned iatoffs = get_le32(p + 4) + rvamin;
|
const unsigned iatoffs = get_le32(p + 4) + rvamin;
|
||||||
if (inamespos)
|
if (inamespos)
|
||||||
{
|
{
|
||||||
// now I rebuild the dll names
|
// now I rebuild the dll names
|
||||||
|
OCHECK(dllnames, dlen + 1);
|
||||||
|
strcpy(dllnames, dname);
|
||||||
im->dllname = ptr_diff(dllnames,Obuf);
|
im->dllname = ptr_diff(dllnames,Obuf);
|
||||||
strcpy(dllnames,get_le32(p) + import);
|
|
||||||
//;;;printf("\ndll: %s:",dllnames);
|
//;;;printf("\ndll: %s:",dllnames);
|
||||||
dllnames += strlen(dllnames) + 1;
|
dllnames += dlen + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(Obuf + im->dllname,get_le32(p) + import);
|
{
|
||||||
|
OCHECK(Obuf + im->dllname, dlen + 1);
|
||||||
|
strcpy(Obuf + im->dllname, dname);
|
||||||
|
}
|
||||||
im->iat = iatoffs;
|
im->iat = iatoffs;
|
||||||
LE32 *newiat = (LE32 *) (Obuf + iatoffs);
|
|
||||||
|
// LE32 *newiat = (LE32 *) (Obuf + iatoffs);
|
||||||
|
OPTR_I(LE32, newiat, (LE32 *) (Obuf + iatoffs));
|
||||||
|
|
||||||
// restore the imported names+ordinals
|
// restore the imported names+ordinals
|
||||||
for (p += 8; *p; newiat++)
|
for (p += 8; *p; ++newiat)
|
||||||
if (*p == 1)
|
if (*p == 1)
|
||||||
{
|
{
|
||||||
unsigned len = strlen(++p) + 1;
|
const unsigned ilen = strlen(++p) + 1;
|
||||||
if (inamespos)
|
if (inamespos)
|
||||||
{
|
{
|
||||||
if (ptr_diff(importednames,oimpdlls) & 1)
|
if (ptr_diff(importednames,oimpdlls) & 1)
|
||||||
importednames--;
|
importednames -= 1;
|
||||||
memcpy(importednames + 2,p,len);
|
omemcpy(importednames + 2, p, ilen);
|
||||||
//;;;printf(" %s",importednames+2);
|
//;;;printf(" %s",importednames+2);
|
||||||
*newiat = ptr_diff(importednames,Obuf);
|
*newiat = ptr_diff(importednames, Obuf);
|
||||||
importednames += 2 + len;
|
importednames += 2 + ilen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(Obuf + *newiat + 2,p);
|
{
|
||||||
p += len;
|
OCHECK(Obuf + *newiat + 2, ilen + 1);
|
||||||
|
strcpy(Obuf + *newiat + 2, p);
|
||||||
|
}
|
||||||
|
p += ilen;
|
||||||
}
|
}
|
||||||
else if (*p == 0xff)
|
else if (*p == 0xff)
|
||||||
{
|
{
|
||||||
@@ -2151,7 +2243,7 @@ void PackW32Pe::rebuildRelocs(upx_byte *& extrainfo)
|
|||||||
|
|
||||||
if (ODSIZE(PEDIR_RELOC) == 8) // some tricky dlls use this
|
if (ODSIZE(PEDIR_RELOC) == 8) // some tricky dlls use this
|
||||||
{
|
{
|
||||||
memcpy(obuf + ODADDR(PEDIR_RELOC) - rvamin, "\x0\x0\x0\x0\x8\x0\x0\x0", 8);
|
omemcpy(obuf + ODADDR(PEDIR_RELOC) - rvamin, "\x0\x0\x0\x0\x8\x0\x0\x0", 8);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2159,13 +2251,14 @@ void PackW32Pe::rebuildRelocs(upx_byte *& extrainfo)
|
|||||||
const upx_byte big = extrainfo[4];
|
const upx_byte big = extrainfo[4];
|
||||||
extrainfo += 5;
|
extrainfo += 5;
|
||||||
|
|
||||||
upx_byte *p = rdata;
|
// upx_byte *p = rdata;
|
||||||
|
OPTR_I(upx_byte, p, rdata);
|
||||||
MemBuffer wrkmem;
|
MemBuffer wrkmem;
|
||||||
unsigned relocn = unoptimizeReloc32(&rdata,obuf,&wrkmem,1);
|
unsigned relocn = unoptimizeReloc32(&rdata,obuf,&wrkmem,1);
|
||||||
unsigned r16 = 0;
|
unsigned r16 = 0;
|
||||||
if (big & 6) // 16 bit relocations
|
if (big & 6) // 16 bit relocations
|
||||||
{
|
{
|
||||||
LE32 *q = (LE32*) rdata;
|
const LE32 *q = (LE32*) rdata;
|
||||||
while (*q++)
|
while (*q++)
|
||||||
r16++;
|
r16++;
|
||||||
if ((big & 6) == 6)
|
if ((big & 6) == 6)
|
||||||
@@ -2190,20 +2283,20 @@ void PackW32Pe::rebuildRelocs(upx_byte *& extrainfo)
|
|||||||
for (unsigned ic = 0; ic < relocn; ic++)
|
for (unsigned ic = 0; ic < relocn; ic++)
|
||||||
{
|
{
|
||||||
p = obuf + get_le32(wrkmem + 4 * ic);
|
p = obuf + get_le32(wrkmem + 4 * ic);
|
||||||
set_le32(p,get_le32(p) + oh.imagebase + rvamin);
|
set_le32(p, get_le32((unsigned char *)p) + oh.imagebase + rvamin);
|
||||||
rel.add(rvamin + get_le32(wrkmem + 4 * ic),3);
|
rel.add(rvamin + get_le32(wrkmem + 4 * ic),3);
|
||||||
}
|
}
|
||||||
rel.finish (oxrelocs,soxrelocs);
|
rel.finish (oxrelocs,soxrelocs);
|
||||||
|
|
||||||
if (opt->w32pe.strip_relocs && !isdll)
|
if (opt->win32_pe.strip_relocs && !isdll)
|
||||||
{
|
{
|
||||||
memset(obuf + ODADDR(PEDIR_RELOC) - rvamin,0,ODSIZE(PEDIR_RELOC));
|
obuf.clear(ODADDR(PEDIR_RELOC) - rvamin, ODSIZE(PEDIR_RELOC));
|
||||||
ODADDR(PEDIR_RELOC) = 0;
|
ODADDR(PEDIR_RELOC) = 0;
|
||||||
soxrelocs = 0;
|
soxrelocs = 0;
|
||||||
// FIXME: try to remove the original relocation section somehow
|
// FIXME: try to remove the original relocation section somehow
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy (obuf + ODADDR(PEDIR_RELOC) - rvamin,oxrelocs,soxrelocs);
|
omemcpy(obuf + ODADDR(PEDIR_RELOC) - rvamin,oxrelocs,soxrelocs);
|
||||||
delete [] oxrelocs; oxrelocs = NULL;
|
delete [] oxrelocs; oxrelocs = NULL;
|
||||||
wrkmem.dealloc();
|
wrkmem.dealloc();
|
||||||
|
|
||||||
@@ -2215,11 +2308,11 @@ void PackW32Pe::rebuildExports()
|
|||||||
if (ODSIZE(PEDIR_EXPORT) == 0 || ODADDR(PEDIR_EXPORT) == IDADDR(PEDIR_EXPORT))
|
if (ODSIZE(PEDIR_EXPORT) == 0 || ODADDR(PEDIR_EXPORT) == IDADDR(PEDIR_EXPORT))
|
||||||
return; // nothing to do
|
return; // nothing to do
|
||||||
|
|
||||||
opt->w32pe.compress_exports = 0;
|
opt->win32_pe.compress_exports = 0;
|
||||||
Export xport((char*)(unsigned char*) ibuf - isection[2].vaddr);
|
Export xport((char*)(unsigned char*) ibuf - isection[2].vaddr);
|
||||||
processExports(&xport);
|
processExports(&xport);
|
||||||
processExports(&xport,ODADDR(PEDIR_EXPORT));
|
processExports(&xport,ODADDR(PEDIR_EXPORT));
|
||||||
memcpy(obuf + ODADDR(PEDIR_EXPORT) - rvamin,oexport,soexport);
|
omemcpy(obuf + ODADDR(PEDIR_EXPORT) - rvamin,oexport,soexport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackW32Pe::rebuildTls()
|
void PackW32Pe::rebuildTls()
|
||||||
@@ -2243,7 +2336,7 @@ void PackW32Pe::rebuildResources(upx_byte *& extrainfo)
|
|||||||
{
|
{
|
||||||
unsigned origoffs = get_le32(r + res.offs() - 4);
|
unsigned origoffs = get_le32(r + res.offs() - 4);
|
||||||
res.newoffs() = origoffs;
|
res.newoffs() = origoffs;
|
||||||
memcpy(obuf + origoffs - rvamin,r + res.offs(),res.size());
|
omemcpy(obuf + origoffs - rvamin,r + res.offs(),res.size());
|
||||||
if (icondir_count && res.itype() == RT_GROUP_ICON)
|
if (icondir_count && res.itype() == RT_GROUP_ICON)
|
||||||
{
|
{
|
||||||
set_le16(obuf + origoffs - rvamin + 4,icondir_count);
|
set_le16(obuf + origoffs - rvamin + 4,icondir_count);
|
||||||
@@ -2253,7 +2346,7 @@ void PackW32Pe::rebuildResources(upx_byte *& extrainfo)
|
|||||||
upx_byte *p = res.build();
|
upx_byte *p = res.build();
|
||||||
// write back when the original is zeroed
|
// write back when the original is zeroed
|
||||||
if (get_le32(obuf + ODADDR(PEDIR_RESOURCE) - rvamin + 12) == 0)
|
if (get_le32(obuf + ODADDR(PEDIR_RESOURCE) - rvamin + 12) == 0)
|
||||||
memcpy(obuf + ODADDR(PEDIR_RESOURCE) - rvamin,p,res.dirsize());
|
omemcpy(obuf + ODADDR(PEDIR_RESOURCE) - rvamin,p,res.dirsize());
|
||||||
delete [] p;
|
delete [] p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2324,7 +2417,7 @@ void PackW32Pe::unpack(OutputFile *fo)
|
|||||||
oh.chksum = 0;
|
oh.chksum = 0;
|
||||||
|
|
||||||
// FIXME: ih.flags is checked here because of a bug in UPX 0.92
|
// FIXME: ih.flags is checked here because of a bug in UPX 0.92
|
||||||
if ((opt->w32pe.strip_relocs && !isdll) || (ih.flags & RELOCS_STRIPPED))
|
if ((opt->win32_pe.strip_relocs && !isdll) || (ih.flags & RELOCS_STRIPPED))
|
||||||
{
|
{
|
||||||
oh.flags |= RELOCS_STRIPPED;
|
oh.flags |= RELOCS_STRIPPED;
|
||||||
ODADDR(PEDIR_RELOC) = 0;
|
ODADDR(PEDIR_RELOC) = 0;
|
||||||
@@ -2336,7 +2429,7 @@ void PackW32Pe::unpack(OutputFile *fo)
|
|||||||
{
|
{
|
||||||
ibuf.dealloc();
|
ibuf.dealloc();
|
||||||
ibuf.alloc(osection[0].rawdataptr);
|
ibuf.alloc(osection[0].rawdataptr);
|
||||||
memset(ibuf,0,osection[0].rawdataptr);
|
ibuf.clear();
|
||||||
infoHeader("[Writing uncompressed file]");
|
infoHeader("[Writing uncompressed file]");
|
||||||
|
|
||||||
// write loader + compressed file
|
// write loader + compressed file
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2002 Laszlo Molnar
|
Copyright (C) 1996-2004 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user