Compare commits
346 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 89cfa22c3f | |||
| e7522f4bdf | |||
| 504deeff42 | |||
| b7785b64cf | |||
| f914cb6858 | |||
| 91051d2521 | |||
| 51536a7acd | |||
| 263ccab6e3 | |||
| 9f87755dcb | |||
| 60b4cca5e5 | |||
| d2718e99a4 | |||
| 69a00c0ab3 | |||
| 3272d23917 | |||
| 7f0545cae7 | |||
| 68f35deb86 | |||
| c4f4035072 | |||
| a7d8845952 | |||
| a3378393b0 | |||
| 3dfe0ad478 | |||
| 9a3b7a4f3f | |||
| 78579b1103 | |||
| 7d50344512 | |||
| 7a00c12065 | |||
| af71e67681 | |||
| b3e20fc324 | |||
| bd1014abb6 | |||
| 7f76664a5d | |||
| 0a5a80b05d | |||
| 2d63da0660 | |||
| 8387527d2e | |||
| 5d03ba7d63 | |||
| 0ece50c122 | |||
| f2ac297252 | |||
| 0ca8ae17d4 | |||
| 88ca87cf9e | |||
| 0d69d228e4 | |||
| a3afe95306 | |||
| 9fb4af8658 | |||
| 9bb6ba9311 | |||
| faa42ba341 | |||
| 596827a912 | |||
| 89b4292445 | |||
| dd88737414 | |||
| 5456cfc304 | |||
| 1e66096ea7 | |||
| 2b6ae3908c | |||
| 1924612479 | |||
| 2af5bdeaab | |||
| b28565b38d | |||
| fec602362b | |||
| 6753c5f45a | |||
| 2f3c108d42 | |||
| ce6d99bdb4 | |||
| 86d4125893 | |||
| 3a18f00379 | |||
| e6274904a7 | |||
| 3677395444 | |||
| 22ba35b3b5 | |||
| 9c1ab9979b | |||
| eaa463e1c9 | |||
| 6984be48c3 | |||
| b739bd3d79 | |||
| 23f3e4396c | |||
| c264750924 | |||
| c155f0a5d5 | |||
| 76734f086d | |||
| 4f2d1172dd | |||
| 75caf4e297 | |||
| 509ab8261f | |||
| 1e05b40d4f | |||
| 451390f835 | |||
| 58cce9d2f8 | |||
| 2eb6e3b0ea | |||
| fb1181ed26 | |||
| 6d5e1d529d | |||
| 0e0ca08924 | |||
| 5d948a67a8 | |||
| 6a4db2ecab | |||
| f700273624 | |||
| 0c198e0ccc | |||
| 71ffbbc420 | |||
| 4fd09b889d | |||
| 4cb2a3eebe | |||
| c25186b1f6 | |||
| 779033d0bc | |||
| 3e31560e7d | |||
| d23d7e8775 | |||
| f6fdf5cb7f | |||
| 1879ccd27d | |||
| 08c0796719 | |||
| edc7994ce5 | |||
| bcfcfbd064 | |||
| 9e79b3258d | |||
| 243873cd2d | |||
| c7b8a4b0c1 | |||
| e39e0c7140 | |||
| d4a3f11dbb | |||
| 0962f266b3 | |||
| 69e4d3fdad | |||
| c0908f463a | |||
| b00a61a17b | |||
| 553c2f886a | |||
| 4fd9c5772a | |||
| 04e0e06d85 | |||
| 4d7829d72b | |||
| 6b751aac57 | |||
| 813349fd23 | |||
| 16a2744782 | |||
| 7b6870db22 | |||
| 3e38e7d52c | |||
| 8142d3474d | |||
| 8773649de6 | |||
| c117920ff9 | |||
| c8dd2a3eb8 | |||
| 90b1817e92 | |||
| d6c3ff5997 | |||
| 984ec25132 | |||
| a7bff34784 | |||
| a6e7afbc91 | |||
| 33f1d63b64 | |||
| f95e171e11 | |||
| c82b50b212 | |||
| 2b402b77f1 | |||
| adcb551020 | |||
| 2680aabe06 | |||
| d5c0533b74 | |||
| 609307668b | |||
| cdaf36572a | |||
| 033c8d5d51 | |||
| 6216ec1d6a | |||
| 6c9c67f6c5 | |||
| 5bd32b5521 | |||
| 549336f75b | |||
| f0e75f30b3 | |||
| 144c09f175 | |||
| ee50c0f97c | |||
| ade921bf02 | |||
| 676cacff04 | |||
| a3097d5e25 | |||
| fd78148558 | |||
| a4d79d7375 | |||
| df04e8183d | |||
| c43c484a62 | |||
| 0608c35669 | |||
| 7dd4d06e26 | |||
| 1ee0310b86 | |||
| cc0a52038f | |||
| 6aed1fe231 | |||
| 680608fe18 | |||
| ec6acbc602 | |||
| cb7ee4c5d2 | |||
| 88d5798f45 | |||
| fcc22a0aa3 | |||
| aabefff298 | |||
| ed25c64e97 | |||
| b7dc870c2d | |||
| 9bea608843 | |||
| 9db1732c36 | |||
| 39f1a70174 | |||
| 1810440355 | |||
| 37ac8f179e | |||
| 626a09328f | |||
| 8d489d0d77 | |||
| 776f3db0d7 | |||
| 6046057b88 | |||
| 7e85d9e549 | |||
| 01c8a8b1c2 | |||
| c9bf6ac9ae | |||
| 62e4d69be9 | |||
| 62ac733b09 | |||
| c3b3e1b1b9 | |||
| a791e96e00 | |||
| e87f5521c1 | |||
| 366a708f3a | |||
| 70ba662574 | |||
| b389abd99f | |||
| 4aa2d14fe3 | |||
| af7de75ad4 | |||
| d461ebbda1 | |||
| 55ef94abcd | |||
| afaf489d99 | |||
| 20e4cbfd13 | |||
| f3b8c9f34e | |||
| 45e8ff25a5 | |||
| 268e322e1c | |||
| d3bcba6a05 | |||
| cc4ef1944d | |||
| 5aa8486265 | |||
| fd181673cd | |||
| 62c9547c4e | |||
| cdd117bfb9 | |||
| 304ba57dad | |||
| 69eaaa4177 | |||
| 452ac52fcb | |||
| 40cf489290 | |||
| 891d6be4a6 | |||
| 5d45ce5cf7 | |||
| a0f2241f3a | |||
| aa513bf7d3 | |||
| b2d65febc8 | |||
| 23a6d326e8 | |||
| 5b2f1b6d8b | |||
| b4e9ad031b | |||
| 8b7ebcf040 | |||
| af05296631 | |||
| 29d693de2d | |||
| 51ac5172f5 | |||
| 24ce1ef5e7 | |||
| f6d1e269d1 | |||
| 62c2f5228d | |||
| 9882d9683b | |||
| 45ce89ee1f | |||
| bfb9df1553 | |||
| a5f79204ce | |||
| e322613d84 | |||
| fbb60f5191 | |||
| 899e7d2f39 | |||
| 8e2aa07747 | |||
| a0d262cd76 | |||
| b43a7edee4 | |||
| 7760bbd77c | |||
| 9c0f1b02a7 | |||
| 4ecfff4d8d | |||
| ac03b89f38 | |||
| 620174aea9 | |||
| ab50d28bc4 | |||
| b5318602d1 | |||
| bff2a63ea2 | |||
| aacfb8820e | |||
| 98e8c031d0 | |||
| beb4319d1e | |||
| 2558243c83 | |||
| b670e8d1ac | |||
| 68f8358f06 | |||
| db5a099097 | |||
| ce33ffb62a | |||
| 59a2fb9cfd | |||
| 75bba319de | |||
| f78e9261f3 | |||
| 5f77562333 | |||
| 5c4f01a68d | |||
| 35f6f998e6 | |||
| 6737a3ae09 | |||
| 09559bee8c | |||
| f487ea27a8 | |||
| a3d95f239a | |||
| 023c06e178 | |||
| 414a6c1c9e | |||
| 910e18fb22 | |||
| ac441fd1cf | |||
| 0c328372b5 | |||
| 55ef60a6d4 | |||
| c33584e683 | |||
| ee8c7453bd | |||
| 0330369603 | |||
| 3f7b642c7d | |||
| eb6c51426a | |||
| 0337bdb9fd | |||
| 7aedc62058 | |||
| bfc835cbbf | |||
| 5c6ba30c48 | |||
| 8fe4824ed2 | |||
| d40cb3bd55 | |||
| 4bcd3ac5d7 | |||
| e2b8e9dea9 | |||
| 572314bf3f | |||
| 14d303d331 | |||
| 24ffaa0738 | |||
| 5d9b6d056d | |||
| 5c28ff15ba | |||
| 06ceb2f2a1 | |||
| 7373e1dd8b | |||
| 4b1a9e714d | |||
| 9d76136358 | |||
| b3502420ad | |||
| dd7ac7cca9 | |||
| 31dfa18e9b | |||
| 3e785008d3 | |||
| 6b7c7f755c | |||
| c55a8a8703 | |||
| 64c97308ac | |||
| 3551b0b95a | |||
| 9f16b5c4af | |||
| 9777e549cb | |||
| fbfced1b93 | |||
| 1a84b4681c | |||
| 4bf81b8e1c | |||
| c282e7fdb4 | |||
| d339ee3135 | |||
| 1de95de299 | |||
| 96c998a1d7 | |||
| b5413c0156 | |||
| 7371c195ff | |||
| 0866a1996b | |||
| 41f44c4e78 | |||
| 131712c3bd | |||
| bae12aaab7 | |||
| 74d5844d8c | |||
| c87908266a | |||
| f788d76b8c | |||
| 41031e572e | |||
| f8a0864c1b | |||
| 949587334c | |||
| 0bc6a1a7f1 | |||
| 0d9cbfe927 | |||
| 8742a524c3 | |||
| 79bf2297b5 | |||
| 32e9e23630 | |||
| 7f1cecba92 | |||
| efd30c61c3 | |||
| 4c97b11207 | |||
| 58ea0ab745 | |||
| 3547c71ad5 | |||
| 044d6b2ce2 | |||
| a0b26b6c06 | |||
| 8e3bfde439 | |||
| 6507de959b | |||
| 56d09bf3b5 | |||
| 232754b978 | |||
| 75ef603308 | |||
| a5a2fcee4d | |||
| f86d57bfe3 | |||
| 615615b1df | |||
| aeba0ce170 | |||
| 5ce60aad53 | |||
| dbc01de9a0 | |||
| dfaf3f24fc | |||
| 14b0527e79 | |||
| f0148c3161 | |||
| 6a5e3d924d | |||
| 664a82e7c9 | |||
| e2763b4826 | |||
| afb29b19c2 | |||
| 8d60343940 | |||
| 67a77f1880 | |||
| c933974174 | |||
| 19715903fb | |||
| c88f72fd15 | |||
| 7818596271 | |||
| 9cb8d7bca6 | |||
| 46f9256114 | |||
| c26ef87202 | |||
| 89fee5b835 | |||
| f5795eb01b | |||
| dbf0c9f016 | |||
| 586b43048f |
@@ -1,7 +0,0 @@
|
||||
_darcs
|
||||
B
|
||||
ChangeLog.cvs*
|
||||
TODO.*
|
||||
build
|
||||
doxygen
|
||||
maint
|
||||
@@ -0,0 +1,43 @@
|
||||
syntax: regexp
|
||||
|
||||
^ChangeLog
|
||||
^build
|
||||
^maint
|
||||
|
||||
syntax: glob
|
||||
|
||||
*.a
|
||||
*.d
|
||||
*.dll
|
||||
*.exe
|
||||
*.lib
|
||||
*.map
|
||||
*.o
|
||||
*.out
|
||||
*.py[cdo]
|
||||
*.so
|
||||
*.res
|
||||
*.ttp
|
||||
|
||||
doc/*.1
|
||||
doc/*.doc
|
||||
doc/*.html
|
||||
|
||||
src/MMakefile
|
||||
src/compress_nrv*
|
||||
src/*.rc
|
||||
|
||||
stub/MMakefile
|
||||
stub/l_t_*.i
|
||||
stub/stamp-h
|
||||
stub/*.ash
|
||||
stub/*.asx
|
||||
stub/*.asy
|
||||
stub/*.bin
|
||||
stub/*.lst
|
||||
|
||||
stub/util/armpe/armpe_tester
|
||||
|
||||
stub/util/sstrip/amd64-linux-sstrip
|
||||
stub/util/sstrip/i386-linux-sstrip
|
||||
stub/util/sstrip/sstrip
|
||||
@@ -0,0 +1,10 @@
|
||||
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
|
||||
223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190
|
||||
2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194
|
||||
2ee65b77f9117651e2e5517b2edede23698d73ca RELEASE_196
|
||||
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
|
||||
a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
|
||||
b0353253b0b3d062eb5adb50d4b665a96620da45 RELEASE_195
|
||||
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
|
||||
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
|
||||
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
Limitations and other things which are not (yet) supported:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Toplevel Makefile for UPX
|
||||
|
||||
SHELL = /bin/sh
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
export SHELL = /bin/sh
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = .
|
||||
@@ -10,30 +12,22 @@ default:
|
||||
@echo "UPX info: please choose a target for 'make'"
|
||||
|
||||
all mostlyclean clean distclean maintainer-clean:
|
||||
ifneq ($(wildcard $(HOME)/local/bin/bin-upx),)
|
||||
# these need special build tools
|
||||
$(MAKE) -C src/stub/util/sstrip $@
|
||||
$(MAKE) -C src/stub $@
|
||||
endif
|
||||
$(MAKE) -C src $@
|
||||
$(MAKE) -C doc $@
|
||||
|
||||
dist: distclean
|
||||
false
|
||||
|
||||
zip:
|
||||
cd .. && rm -f upx-current.zip && zip -r upx-current.zip upx
|
||||
|
||||
cvs-admin-ko:
|
||||
cvs admin -ko .
|
||||
cvs update -P -d
|
||||
|
||||
# automatically generate ChangeLog from hg
|
||||
ChangeLog:
|
||||
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
|
||||
|
||||
ChangeLog.cvsps:
|
||||
cvsps > $@
|
||||
hg log --style=changelog > $@
|
||||
|
||||
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
.PHONY: dist cvs-admin-ko ChangeLog
|
||||
|
||||
.NOEXPORT:
|
||||
.PHONY: default all mostlyclean clean distclean maintainer-clean
|
||||
.PHONY: dist ChangeLog
|
||||
|
||||
|
||||
@@ -2,15 +2,49 @@
|
||||
User visible changes for UPX
|
||||
==================================================================
|
||||
|
||||
[ UNSTABLE BETA VERSION - please see README.1ST for some more info ]
|
||||
Changes in 2.01 (06 Jun 2006):
|
||||
* arm/pe: better DLL support
|
||||
* dos/exe: device driver support added
|
||||
* linux/386: Fix --force-execve for PaX, grSecurity, and strict SELinux.
|
||||
/tmp must support execve(); therefore /tmp cannot be mounted 'noexec'.
|
||||
* win32/pe & arm/pe: added new option '--keep-resource=' for
|
||||
excluding selected resources from compression
|
||||
|
||||
Changes in 2.00 (27 Apr 2006):
|
||||
* linux/386: the stub now prints an error message if some strict
|
||||
SELinux mode does prevent runtime decompression and execution
|
||||
(for a fully SELinux-compatible but otherwise inferior compression
|
||||
format you can use the '--force-execve' option)
|
||||
* linux/386: worked around a problem where certain Linux kernels
|
||||
clobber the %ebx register during a syscall
|
||||
* win32/pe: disable filters for files with broken PE headers
|
||||
|
||||
Changes in 1.96 beta (13 Apr 2006):
|
||||
* arm/pe: added filter support
|
||||
* win32/pe: removed an unnecessary check so that Delphi 2006 and
|
||||
Digital Mars C++ programs finally are supported
|
||||
|
||||
Changes in 1.95 beta (09 Apr 2006):
|
||||
* arm/pe: added DLL support
|
||||
* arm/pe: added thumb mode stub support
|
||||
* arm/pe: added unpacking support
|
||||
* win32/pe: really worked around R6002 runtime errors
|
||||
|
||||
Changes in 1.94 beta (11 Mar 2006):
|
||||
* new format: added support for arm/pe (ARM executables running on WinCE)
|
||||
* new format: added support for linux elf/amd64
|
||||
* new format: added support for linux elf/ppc32
|
||||
* new format: added support for mach/ppc32 (Apple Mac OS X)
|
||||
* win32/pe: hopefully working "load config" support
|
||||
* win32/pe: R6002 runtime errors worked around
|
||||
* win32/pe: the stub now clears the dirty stack
|
||||
|
||||
Changes in 1.93 beta (07 Feb 2005):
|
||||
* 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: added option '--strip-loadconf' to strip the SEH load
|
||||
config section [NOTE: this option is obsolete since UPX 1.94]
|
||||
* 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
|
||||
@@ -21,7 +55,7 @@ Changes in 1.91 beta (30 Jun 2004):
|
||||
* 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'.
|
||||
* 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
|
||||
@@ -30,9 +64,9 @@ Changes in 1.91 beta (30 Jun 2004):
|
||||
|
||||
Changes in 1.90 beta (11 Nov 2002):
|
||||
* 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
|
||||
* linux/386: added the option `--force-execve'
|
||||
* linux/386: added the option '--force-execve'
|
||||
* vmlinuz/386: better kernel detection and sanity checks
|
||||
* re-synced with upx 1.24 branch
|
||||
* documentation updates
|
||||
@@ -77,9 +111,9 @@ Changes in 1.22 (27 Jun 2002)
|
||||
Digital Mars C++ and Watcom C++
|
||||
|
||||
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
|
||||
of higher memory requirements during compression.
|
||||
Try `upx --best --crp-ms=100000'. See the docs for more info.
|
||||
Try 'upx --best --crp-ms=100000'. See the docs for more info.
|
||||
* source code: portability fixes
|
||||
* source code: compile fixes for g++ 3.0 and g++ 3.1
|
||||
|
||||
@@ -93,7 +127,6 @@ Changes in 1.20 (23 May 2001)
|
||||
our unstable development releases 1.1x and 1.9x]
|
||||
|
||||
Changes in 1.08 (30 Apr 2001)
|
||||
* INFO: http://upx.sourceforge.net now is the new permanent UPX home page
|
||||
* new native port to atari/tos
|
||||
* win32/pe: shortened the identstring
|
||||
* source code: portability fixes - UPX now builds cleanly under m68k CPUs
|
||||
@@ -118,7 +151,7 @@ Changes in 1.05 (24 Jan 2001)
|
||||
at the unstable UPX 1.1x beta versions for that)
|
||||
|
||||
Changes in 1.04 (19 Dec 2000)
|
||||
* dos/exe: fixed an internal error when using `--no-reloc'
|
||||
* dos/exe: fixed an internal error when using '--no-reloc'
|
||||
* win32/pe: fixed a rare bug in the relocation handling code
|
||||
* some tunings for the default compression level
|
||||
|
||||
@@ -126,7 +159,7 @@ Changes in 1.03 (30 Nov 2000)
|
||||
* linked with a new version of the NRV compression library:
|
||||
- improved compression ratio a little bit
|
||||
- overall significantly faster compression
|
||||
- much faster when using high compression levels like `-9' or `--best'
|
||||
- much faster when using high compression levels like '-9' or '--best'
|
||||
- much faster with large files
|
||||
* atari/tos: added support for FreeMiNT
|
||||
* the 32-bit DOS version now uses the new CWSDSTUB extender
|
||||
@@ -134,7 +167,7 @@ Changes in 1.03 (30 Nov 2000)
|
||||
Changes in 1.02 (13 Sep 2000)
|
||||
* watcom/le: fixed a problem with the Causeway extender
|
||||
* win32/pe: don't automatically strip relocs if they seem needed
|
||||
* support multiple backup generations when using `-k'
|
||||
* support multiple backup generations when using '-k'
|
||||
* updated the console screen driver
|
||||
|
||||
Changes in 1.01 (09 Apr 2000)
|
||||
@@ -162,7 +195,7 @@ Changes in 0.99.1 (29 Feb 2000)
|
||||
|
||||
Changes in 0.99 (25 Feb 2000)
|
||||
* FULL SOURCE CODE RELEASED UNDER THE TERMS OF THE GNU GPL
|
||||
* win32/pe: changed default to `--strip-relocs=1'
|
||||
* win32/pe: changed default to '--strip-relocs=1'
|
||||
* dos/com and dos/sys: fixed a bad decompressor problem
|
||||
* linux/386: the counter for the progress indicator was off by one
|
||||
|
||||
@@ -185,7 +218,7 @@ Changes in 0.91 (13 Nov 1999)
|
||||
* dos/exe: correctly restore cs when uncompressing
|
||||
|
||||
Changes in 0.90 (10 Nov 1999)
|
||||
* all formats: `--overlay=copy' now is the default overlay mode
|
||||
* all formats: '--overlay=copy' now is the default overlay mode
|
||||
* improved compression ratio for most files
|
||||
* win32/pe: uncompression is finally supported
|
||||
* win32/pe: never compress REGISTRY resources
|
||||
@@ -195,7 +228,7 @@ Changes in 0.90 (10 Nov 1999)
|
||||
* win32/pe: somewhat less memory is required during compression
|
||||
* linux/386: fixed compression of scripts which was broken since 0.71
|
||||
* linux/386: more FreeBSD compatibility issues
|
||||
* changed option: `-i' now prints some more details during compression
|
||||
* changed option: '-i' now prints some more details during compression
|
||||
(not finished yet)
|
||||
|
||||
Changes in 0.84 (04 Oct 1999)
|
||||
@@ -211,7 +244,7 @@ Changes in 0.83 (17 Sep 1999)
|
||||
Changes in 0.82 (16 Aug 1999)
|
||||
* dos/exe: fixed a decompressor bug which could cause crash on some files
|
||||
* linux/386: section headers are now stripped from the stub so that
|
||||
`strip' won't ruin a compressed file any longer
|
||||
'strip' won't ruin a compressed file any longer
|
||||
* wc/le: support for stack not in the last object disabled again
|
||||
* win32/pe: removed some unneeded data
|
||||
|
||||
@@ -220,32 +253,32 @@ Changes in 0.81 (04 Aug 1999)
|
||||
* dos/com: fixed an internal error that could happen with very small files
|
||||
|
||||
Changes in 0.80 (03 Aug 1999)
|
||||
* you can set some default options in the environment var `UPX'
|
||||
* you can set some default options in the environment var 'UPX'
|
||||
* dos/com: the decompressor stub now checks for enough free memory
|
||||
* dos/exe: decompressor rewritten, some bugs are fixed
|
||||
* dos/exe: new option `--no-reloc': no relocation data is put into
|
||||
* dos/exe: new option '--no-reloc': no relocation data is put into
|
||||
the DOS header
|
||||
* tmt/adam: added support for more stubs, detect already packed files
|
||||
* tmt/adam: new option `--copy-overlay'
|
||||
* tmt/adam: new option '--copy-overlay'
|
||||
* wc/le: reduced memory requirement during uncompression
|
||||
* wc/le: support files which do not contain their stack in the last object
|
||||
* wc/le: fixed a bug which could cause a crash, improved relocation
|
||||
handling
|
||||
* wc/le: new option `--copy-overlay'
|
||||
* win32/pe: `--compress-icons=2' is now the default
|
||||
* wc/le: new option '--copy-overlay'
|
||||
* win32/pe: '--compress-icons=2' is now the default
|
||||
* win32/pe: even better TLS support
|
||||
* win32/pe: versioninfo works on NT
|
||||
* win32/pe: import by ordinal from kernel32.dll works
|
||||
* win32/pe: other import improvements: importing a nonexistant DLL
|
||||
results in a usual Windows message, importing a nonexistant function
|
||||
results in program exit (instead of crash ;-)
|
||||
* win32/pe: new option: `--compress-resources=0'
|
||||
* win32/pe: new option: '--compress-resources=0'
|
||||
* win32/pe: reduced memory requirement during uncompression, some
|
||||
files might even require LESS memory when they're compressed
|
||||
* win32/pe: TYPELIBs should work now
|
||||
* win32/pe: improved relocation handling, 16-bit relocations should work
|
||||
* win32/pe: new option `--strip-relocs' (only if you know what you are doing)
|
||||
* win32/pe: new option `--copy-overlay'
|
||||
* win32/pe: new option '--strip-relocs' (only if you know what you are doing)
|
||||
* win32/pe: new option '--copy-overlay'
|
||||
* important internal changes: now the stubs are built at runtime
|
||||
|
||||
Changes in 0.72 (12 May 1999)
|
||||
@@ -259,20 +292,20 @@ Changes in 0.72 (12 May 1999)
|
||||
* linux/386: minor decompressor stub updates, nicer progress bar
|
||||
|
||||
Changes in 0.71 (19 Apr 1999)
|
||||
* dos/exe: added option `--no-overlay'
|
||||
* dos/exe: added option '--no-overlay'
|
||||
* linux/386: various improvements in the stub, most notably the
|
||||
overhead for an extra cleanup process has been removed
|
||||
* win32/pe: added support for export forwarders
|
||||
* win32/pe: added support for DLLs without entry point or imports
|
||||
* win32/pe: yet another .bss fix
|
||||
* win32/pe: new option `--compress-icons=2': compress all icons
|
||||
* win32/pe: new option '--compress-icons=2': compress all icons
|
||||
which are not in the first icon directory
|
||||
* win32/pe: rearranged stub to avoid false alerts from some virus scanners
|
||||
|
||||
Changes in 0.70 (30 Mar 1999)
|
||||
* added support for linux/386 executables
|
||||
* improved compression ratio quite a bit
|
||||
* added new compression level `--best' to squeeze out even some more bytes
|
||||
* added new compression level '--best' to squeeze out even some more bytes
|
||||
* win32/pe: TLS support is much better now
|
||||
* win32/pe: --compress-icons=0 should now work as well
|
||||
* the usual minor fixes for win32/pe
|
||||
@@ -313,7 +346,7 @@ Changes in 0.40 (05 Oct 1998)
|
||||
* fixed a small but fatal bug in dos/sys introduced in 0.30
|
||||
* fixed a rare bug in dos/exe
|
||||
* worked around a bug in djgpp's strip 2.8
|
||||
* Allegro packfile support should work now
|
||||
* djgpp/coff: Allegro packfile support should work now
|
||||
* added dos/exeh compression method (works on 386+)
|
||||
|
||||
Changes in 0.30 (27 Jul 1998)
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
Here are some possible projects from which you can choose if you'd like to
|
||||
@@ -42,8 +42,6 @@ More formats:
|
||||
- freebsd/386 (generic), freebsd/elf386 (specialized).
|
||||
Probably could share most of the linux code.
|
||||
|
||||
- Windows CE
|
||||
|
||||
- add support for self-extracting HTML pages using a Javascript stub
|
||||
(like the AlgART HTML Packer "AHP")
|
||||
|
||||
@@ -58,8 +56,6 @@ Existing formats:
|
||||
|
||||
- dos/exe: implement filter support
|
||||
|
||||
- dos/sys: add support for sys/exe combos
|
||||
|
||||
- linux/i386:
|
||||
- use the new assembly preprocessor stuff (ie. process the file
|
||||
headers internally)
|
||||
@@ -70,8 +66,7 @@ Existing formats:
|
||||
|
||||
- win32/pe: display a nice dialog box in the stub in case
|
||||
of problems (like importing a DLL or function fails)
|
||||
- win32/pe: finer control over resource compression, per section
|
||||
compression
|
||||
- win32/pe: per section compression
|
||||
|
||||
|
||||
Compression ratio:
|
||||
|
||||
@@ -8,32 +8,11 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
WARNING - UNSTABLE BETA VERSION
|
||||
===============================
|
||||
|
||||
All versions 1.9x are unstable beta releases - use them only for testing,
|
||||
and never distribute a program that is packed with them !
|
||||
There will be hidden bugs. Really.
|
||||
|
||||
The current stable release is 1.25, and the next stable release
|
||||
will be called version 2.00.
|
||||
|
||||
The main news since 1.25 are:
|
||||
- slightly better compression using the new NRV2E algorithm
|
||||
- new options for compression tuining (e.g. `--brute')
|
||||
- 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
|
||||
=======
|
||||
|
||||
@@ -58,7 +37,7 @@ and run exactly as before, with no runtime or memory penalty for most
|
||||
of the supported formats.
|
||||
|
||||
UPX supports a number of different executable formats, including
|
||||
Windows 95/98/ME/NT/2000/XP programs and DLLs, DOS programs,
|
||||
Windows 95/98/ME/NT/2000/XP/CE programs and DLLs, DOS programs,
|
||||
and Linux executables and kernels.
|
||||
|
||||
UPX is free software distributed under the term of the GNU General
|
||||
@@ -76,8 +55,8 @@ UPX aims to be Commercial Quality Freeware.
|
||||
SHORT DOCUMENTATION
|
||||
===================
|
||||
|
||||
`upx program.exe' will compress a program or DLL. For best compression
|
||||
results try `upx --best program.exe'.
|
||||
'upx program.exe' will compress a program or DLL. For best compression
|
||||
results try 'upx --brute program.exe'.
|
||||
|
||||
Please see the file UPX.DOC for the full documentation. The files
|
||||
NEWS and BUGS also contain various tidbits of information.
|
||||
@@ -91,7 +70,7 @@ UPX comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
|
||||
Having said that, we think that 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.
|
||||
actually it's almost 8 years since our first public beta.
|
||||
|
||||
This is the first production quality release, and we plan that future
|
||||
releases will be backward compatible with this version.
|
||||
@@ -129,8 +108,9 @@ THE FUTURE
|
||||
COPYRIGHT
|
||||
=========
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
@@ -149,7 +129,7 @@ Markus & Laszlo
|
||||
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
|
||||
|
||||
|
||||
|
||||
+17
-17
@@ -8,26 +8,26 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
WARNING - UNSTABLE BETA VERSION
|
||||
===============================
|
||||
|
||||
All versions 1.9x are unstable beta releases - use them only for testing,
|
||||
and never distribute a program that is packed with them !
|
||||
There will be hidden bugs. Really.
|
||||
|
||||
The current stable release is 1.25, and the next stable release
|
||||
will be called version 2.00.
|
||||
MAJOR NEWS IN UPX 2
|
||||
===================
|
||||
|
||||
The main news since 1.25 are:
|
||||
- slightly better compression using the new NRV2E algorithm
|
||||
- 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
|
||||
|
||||
* new format: added support for arm/pe (ARM executables running on WinCE)
|
||||
* new format: added support for linux elf/amd64
|
||||
* new format: added support for linux elf/ppc32
|
||||
* new format: added support for mach/ppc32 (Apple Mac OS X)
|
||||
* new format: added support for bootable Linux kernels ("vmlinuz/386")
|
||||
* new format: added support for Playstation exes ("ps1/exe")
|
||||
|
||||
* slightly better compression using the new NRV2E algorithm
|
||||
* new options for compression tuning (e.g. '--brute')
|
||||
* improved win32/pe compatibility
|
||||
* direct ELF-to-memory decompression
|
||||
* various bug fixes
|
||||
|
||||
|
||||
+19
-13
@@ -69,11 +69,7 @@ Tools needed to build/modify the UPX sources
|
||||
- A C++ compiler supporting inner classes, templates, exceptions
|
||||
and RTTI.
|
||||
|
||||
- GNU make 3.80 for Win32
|
||||
http://www.cygwin.com/
|
||||
|
||||
- GNU make 3.80 for DOS
|
||||
http://www.delorie.com/djgpp/
|
||||
- GNU make 3.80 or better
|
||||
|
||||
|
||||
To compile the packer sources
|
||||
@@ -96,19 +92,30 @@ To compile the packer sources
|
||||
If you want to modify the stub sources you'll also need
|
||||
-------------------------------------------------------
|
||||
|
||||
- Nasm 0.98.38 - the Netwide Assembler
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
http://sourceforge.net/projects/nasm/
|
||||
|
||||
- A68K - a 68000 macro assembler
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
|
||||
- ASM5900 - a MIPS R3000 assembler
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
|
||||
- djasm - an assembler for the djgpp stub
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
|
||||
- Perl 5.6 or better
|
||||
- nasm 0.98.39 - the Netwide Assembler
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
http://sourceforge.net/projects/nasm/
|
||||
|
||||
- Linux (for the linux/386 stubs)
|
||||
- Perl & Python
|
||||
|
||||
- Certain versions of some i386-linux tools:
|
||||
- gcc-2.95.3
|
||||
- gcc-3.4.6
|
||||
- binutils-2.16.1
|
||||
|
||||
- Other cross compilers targeted at the following architectures:
|
||||
- arm-9tdmi-linux-gnu
|
||||
- powerpc-750-linux-gnu
|
||||
- x86_64-unknown-linux-gnu
|
||||
|
||||
|
||||
Misc. notes
|
||||
@@ -124,8 +131,7 @@ Misc. notes
|
||||
- Use gcc extensions and other compiler specific stuff only through
|
||||
macros.
|
||||
- Keep in mind that it should be possible to build UPX on braindead
|
||||
file systems (FAT). Don't use long file names or other things
|
||||
that break building under plain DOS.
|
||||
case insensitive file systems (FAT).
|
||||
|
||||
***
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
.___.. .
|
||||
@@ -39,12 +39,12 @@ Ice
|
||||
for debugging the PE headersize problem down
|
||||
Joergen Ibsen <jibz@hotmail.com> and d'b
|
||||
for the relocation & address optimization ideas
|
||||
John F. Reiser <jreiser@BitWagon.com>
|
||||
for the new Linux executable formats
|
||||
John S. Fine <johnfine@erols.com>
|
||||
for the new version of the dos/exe decompressor
|
||||
Lukundoo <Lukundoo@softhome.net>
|
||||
for beta testing
|
||||
Michael Devore
|
||||
for initial dos/exe device driver support
|
||||
Oleg V. Volkov <rover@lglobus.ru>
|
||||
for various FreeBSD specific informations
|
||||
The Owl & G-RoM
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
UPX TODO list. Last updated 2005-01-08.
|
||||
UPX TODO list. Last updated 2006-03-11.
|
||||
|
||||
|
||||
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
|
||||
|
||||
- stub ctojr32 needs CPU 486 because of bswap
|
||||
- [None]
|
||||
|
||||
|
||||
OTHER:
|
||||
|
||||
- rewrite linker.cpp to allow arbitrary length section names
|
||||
- docs: convert docs from upx.pod to use AsciiDoc
|
||||
|
||||
- check all <const_cast> to make sure they are not invalid
|
||||
|
||||
@@ -105,11 +105,6 @@ FORMAT WIN32/PE
|
||||
|
||||
- decrease runtime memory overhead
|
||||
|
||||
2 - easy - mfx + ml) new switch(es) : do not compress resource types x,y,z
|
||||
or resource names a,b,c
|
||||
|
||||
3 - medium - ml) rebuild exports
|
||||
|
||||
3 - difficult) don't compress the BSS section and other holes.
|
||||
|
||||
4 - medium - ml) fix when objectalign < 0x1000
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
upx.1
|
||||
upx.doc
|
||||
upx.html
|
||||
upx.man
|
||||
upx.ps
|
||||
upx.tex
|
||||
+6
-6
@@ -1,10 +1,12 @@
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
SHELL = /bin/sh
|
||||
|
||||
top_srcdir = ..
|
||||
|
||||
PACKAGE = upx
|
||||
VERSION_DATE = 07 Feb 2005
|
||||
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||
PACKAGE = upx
|
||||
VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\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 = sed -e 's/ *$$//'
|
||||
@@ -62,7 +64,5 @@ maintainer-clean: distclean
|
||||
### dependencies
|
||||
###
|
||||
|
||||
$(BUILT_SOURCES): $(top_srcdir)/src/version.h Makefile
|
||||
|
||||
.NOEXPORT:
|
||||
$(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ loads of cryptic comments like `__PERELOC2__'.
|
||||
|
||||
If you look at the C++ source files, however you can notice that these
|
||||
comment strings (without the leading and trailing underscores) are used
|
||||
in the following way (they are all 8 character length strings):
|
||||
in the following way:
|
||||
|
||||
addLoader("PEMAIN20",
|
||||
ih.entry ? "PEDOJUMP" : "PERETURN",
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
UPX and SELinux
|
||||
March 6, 2006
|
||||
|
||||
|
||||
When a program that has been compressed by UPX is run, the decompressor
|
||||
must create and write new memory pages of executable instructions.
|
||||
SELinux (Security Enhanced Linux) directly controls the conditions
|
||||
under which generating and/or executing new instructions is allowed,
|
||||
so the configuration settings of SELinux affect the running of programs
|
||||
that have been compressed by UPX.
|
||||
|
||||
In SELinux "strict enforcing" mode (the most restrictive), generating
|
||||
new instructions at runtime is not allowed at all: any page with
|
||||
PROT_EXEC permission must be mapped from a file in a mounted filesystem
|
||||
that has 'x' [eXecute] permission, and the generation of such files is
|
||||
also tightly controlled. A program that was compressed by UPX will not
|
||||
run in SELinux strict enforcing mode. Attempts will fail with exit
|
||||
code 127, and a record will be added to the history file
|
||||
/var/log/audit/audit.log.
|
||||
|
||||
In "targeted enforcing" mode, SELinux pays close attention mostly to
|
||||
designated processes that run with elevated privileges: web server,
|
||||
print server, login server, etc. Ordinary user excutables receive
|
||||
much less scrutiny. However, one of the eventual goals of SELinux is to
|
||||
eradicate runtime generation of instructions because of the possibility
|
||||
for exploitation by malware (virus, trojan, key logger, privilege
|
||||
elevation exploit, etc.) Thus targeted enforcing mode notices and
|
||||
logs the use of "execmem" capability that is used by a program which
|
||||
was compressed by UPX. In keeping with the goal of eventual prohibition,
|
||||
SELinux ordinarily would deny execmem. However, most current SELinux
|
||||
systems, including Fedora Core 5 [set for release March 15, 2006],
|
||||
override this with "allow_exemem=1" in /etc/selinux/targeted/booleans.
|
||||
Thus a program compressed by UPX will run in the default installed
|
||||
configuration (targeted enforcing, allow_execmem=1) of SELinux under
|
||||
Fedora Core 5. Each invocation will add a few lines to the log file
|
||||
/var/log/audit/audit.log, one line for each use of execmem. If the
|
||||
SELinux policy becomes more restrictive in the future, then a special
|
||||
SELinux class or other mechanism must be created for compressed programs,
|
||||
or else UPX-compressed executables will not run then.
|
||||
|
||||
In its "permissive" modes, SELinux just logs the potential problems,
|
||||
but otherwise does not interfere. A program compressed by UPX will run
|
||||
in any permissive mode.
|
||||
+38
-16
@@ -12,9 +12,9 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
||||
|
||||
=head1 ABSTRACT
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
B<UPX> is a portable, extendable, high-performance executable packer for
|
||||
@@ -75,8 +75,13 @@ B<UPX> is a versatile executable packer with the following features:
|
||||
* rtm32/pe
|
||||
* tmt/adam
|
||||
* vmlinuz/386 [bootable Linux kernel]
|
||||
* vmlinux/386
|
||||
* watcom/le (supporting DOS4G, PMODE/W, DOS32a and CauseWay)
|
||||
* win32/pe
|
||||
* win32/pe (exe and dll)
|
||||
* arm/pe (exe and dll)
|
||||
* linux/elfamd64
|
||||
* linux/elfppc32
|
||||
* mach/elfppc32
|
||||
|
||||
- portable: UPX is written in portable endian-neutral C++
|
||||
|
||||
@@ -335,9 +340,6 @@ Extra options available for this executable format:
|
||||
|
||||
=head2 NOTES FOR DOS/SYS
|
||||
|
||||
You can only compress plain sys files, sys/exe (two in one)
|
||||
combos are not supported.
|
||||
|
||||
Compressed programs only work on a 286+.
|
||||
|
||||
Packed programs will be byte-identical to the original after uncompression.
|
||||
@@ -730,7 +732,7 @@ Extra options available for this executable format:
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR RTM32/PE
|
||||
=head2 NOTES FOR RTM32/PE and ARM/PE
|
||||
|
||||
Same as win32/pe.
|
||||
|
||||
@@ -836,12 +838,19 @@ smaller, but it's still there.
|
||||
If you're running executables from network, then compressed programs
|
||||
will load faster, and require less bandwidth during execution.
|
||||
|
||||
DLLs are supported.
|
||||
DLLs are supported. But UPX compressed DLLs can not share common data and
|
||||
code when they got used by multiple applications. So compressing msvcrt.dll
|
||||
is a waste of memory, but compressing the dll plugins of a particular
|
||||
application may be a better idea.
|
||||
|
||||
Screensavers are supported, with the restriction that the filename
|
||||
must end with ".scr" (as screensavers are handled slightly different
|
||||
than normal exe files).
|
||||
|
||||
UPX compressed PE files has some minor memory overhead (usually in the
|
||||
10 - 30 kbytes range) which can be seen by specifying the "-i" command
|
||||
line switch during compression.
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
--compress-exports=0 Don't compress the export section.
|
||||
@@ -861,13 +870,26 @@ Extra options available for this executable format:
|
||||
|
||||
--compress-resources=0 Don't compress any resources at all.
|
||||
|
||||
--keep-resource=list Don't compress resources specified by the list.
|
||||
The members of the list are separated by commas.
|
||||
A list member has the following format: I<type[/name]>.
|
||||
I<Type> is the type of the resource. Standard types
|
||||
must be specified as decimal numbers, user types can be
|
||||
specified by decimal IDs or strings. I<Name> is the
|
||||
identifier of the resource. It can be a decimal number
|
||||
or a string. For example:
|
||||
|
||||
--keep-resource=2/MYBITMAP,5,6/12345
|
||||
|
||||
UPX won't compress the named bitmap resource "MYBITMAP",
|
||||
it leaves every dialog (5) resource uncompressed, and
|
||||
it won't touch the string table resource with identifier
|
||||
12345.
|
||||
|
||||
--force Force compression even when there is an
|
||||
unexpected value in a header field.
|
||||
Use with care.
|
||||
|
||||
--strip-loadconf=0 Don't strip Structured Exception Handling load config [DEFAULT].
|
||||
--strip-loadconf=1 Strip Structured Exception Handling load config.
|
||||
|
||||
--strip-relocs=0 Don't strip relocation records.
|
||||
--strip-relocs=1 Strip relocation records. [DEFAULT]
|
||||
This option only works on executables with base
|
||||
@@ -920,13 +942,13 @@ Please report all bugs immediately to the authors.
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
|
||||
Copyright (C) 2000-2005 John F. Reiser
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
|
||||
Copyright (C) 2002-2005 Jens Medoch
|
||||
Copyright (C) 2002-2006 Jens Medoch
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
The GNU bfd binary file descriptor package, part of the GNU binutils package,
|
||||
contains code to recognize an Elf file by looking at fields in the file header.
|
||||
Many programs (such as gdb, size, objdump, objcopy, strip and others) use bfd.
|
||||
Unfortunately, bfd has been overly strict. In releases
|
||||
binutils-2.9.1.0.4, binutils-2.9.1.0.23, binutils-2.9.5.0.0,
|
||||
binutils-2.10.1,
|
||||
gdb-4.17, gdb-5.0,
|
||||
and probably others,
|
||||
bfd does not recognize a file with zero in Elf32_Ehdr.e_shoff, .e_shentsize,
|
||||
or .e_shnum, even though the operating system kernel does not care, and many
|
||||
bfd clients would work just fine in these cases.
|
||||
|
||||
Because of its desire to create small size compressed executables, UPX
|
||||
generates and uses Elf files with zero in .e_shoff, .e_shentsizes, and .e_shnum.
|
||||
As a result, many widely-distributed instances of gdb, size, objdump, etc.,
|
||||
refuse to work on UPX-packed executables.
|
||||
|
||||
Here is a patch to bfd/elfcode.h which enables many bfd clients to work
|
||||
with UPX-packed executables. The last two lines of the patch are
|
||||
if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
--- elfcode.h.orig Mon Jun 16 11:45:32 1997
|
||||
+++ elfcode.h Sat Apr 22 10:18:56 2000
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ELF executable support for BFD.
|
||||
- Copyright 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
|
||||
+ Copyright 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
|
||||
|
||||
Written by Fred Fish @ Cygnus Support, from information published
|
||||
in "UNIX System V Release 4, Programmers Guide: ANSI C and
|
||||
@@ -517,14 +517,14 @@
|
||||
elf_debug_file (i_ehdrp);
|
||||
#endif
|
||||
|
||||
- /* If there is no section header table, we're hosed. */
|
||||
- if (i_ehdrp->e_shoff == 0)
|
||||
+ /* If there is no section header table, and relocatable, then we're hosed. */
|
||||
+ if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
|
||||
goto got_wrong_format_error;
|
||||
|
||||
/* As a simple sanity check, verify that the what BFD thinks is the
|
||||
size of each section header table entry actually matches the size
|
||||
- recorded in the file. */
|
||||
- if (i_ehdrp->e_shentsize != sizeof (x_shdr))
|
||||
+ recorded in the file, but only if there are any sections. */
|
||||
+ if (i_ehdrp->e_shentsize != sizeof (x_shdr) && i_ehdrp->e_shnum != 0)
|
||||
goto got_wrong_format_error;
|
||||
|
||||
ebd = get_elf_backend_data (abfd);
|
||||
@@ -579,6 +579,7 @@
|
||||
/* Allocate space for a copy of the section header table in
|
||||
internal form, seek to the section header table in the file,
|
||||
read it in, and convert it to internal form. */
|
||||
+ if (i_ehdrp->e_shnum!=0) {
|
||||
i_shdrp = ((Elf_Internal_Shdr *)
|
||||
bfd_alloc (abfd, sizeof (*i_shdrp) * i_ehdrp->e_shnum));
|
||||
elf_elfsections (abfd) = ((Elf_Internal_Shdr **)
|
||||
@@ -609,6 +610,7 @@
|
||||
if (! bfd_section_from_shdr (abfd, i_ehdrp->e_shstrndx))
|
||||
goto got_no_match;
|
||||
}
|
||||
+ }
|
||||
|
||||
/* Read in the program headers. */
|
||||
if (i_ehdrp->e_phnum == 0)
|
||||
@@ -644,6 +646,7 @@
|
||||
bfd_section_from_shdr with it (since this particular strtab is
|
||||
used to find all of the ELF section names.) */
|
||||
|
||||
+ if (i_ehdrp->e_shstrndx != 0) {
|
||||
shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
|
||||
if (!shstrtab)
|
||||
goto got_no_match;
|
||||
@@ -657,6 +660,7 @@
|
||||
if (! bfd_section_from_shdr (abfd, shindex))
|
||||
goto got_no_match;
|
||||
}
|
||||
+ }
|
||||
|
||||
/* Let the backend double check the format and override global
|
||||
information. */
|
||||
@@ -930,7 +934,7 @@
|
||||
{
|
||||
Elf_Internal_Shdr *hdr;
|
||||
Elf_Internal_Shdr *verhdr;
|
||||
- long symcount; /* Number of external ELF symbols */
|
||||
+ unsigned long symcount; /* Number of external ELF symbols */
|
||||
elf_symbol_type *sym; /* Pointer to current bfd symbol */
|
||||
elf_symbol_type *symbase; /* Buffer for generated bfd symbols */
|
||||
Elf_Internal_Sym i_sym;
|
||||
@@ -978,7 +982,7 @@
|
||||
sym = symbase = NULL;
|
||||
else
|
||||
{
|
||||
- long i;
|
||||
+ unsigned long i;
|
||||
|
||||
if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
|
||||
return -1;
|
||||
-3220
File diff suppressed because it is too large
Load Diff
@@ -1,24 +0,0 @@
|
||||
GNUmakefile
|
||||
*.0??
|
||||
*.d
|
||||
*.dat
|
||||
*.idb
|
||||
*.img
|
||||
*.map
|
||||
*.raw
|
||||
*.rc
|
||||
*.rel
|
||||
*.res
|
||||
*.pdb
|
||||
*.upx
|
||||
.gdbinit
|
||||
.Attic
|
||||
.deps
|
||||
B
|
||||
compress_nrv.*
|
||||
upx
|
||||
upx_nrv
|
||||
upx_nrv.*
|
||||
upx_ucl
|
||||
upx_ucl.*
|
||||
version1*.h
|
||||
@@ -1,42 +0,0 @@
|
||||
ifeq ($(DEPS_DONE),)
|
||||
DEPS_DONE := 1
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // automated dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
ifeq ($(DEPMODE),gcc)
|
||||
EXTRA_CFLAGS += -Wp,-MMD,.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -Wp,-MMD,.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
ifeq ($(DEPMODE),linux-intelc)
|
||||
EXTRA_CFLAGS += -MMD -MF.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -MMD -MF.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
ifeq ($(DEPMODE),linux-pgi)
|
||||
## NOTE: -MMD does not work...
|
||||
EXTRA_CFLAGS += -MD.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -MD.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(HAVE_DEPS),1)
|
||||
ifeq ($(strip $(wildcard .deps)),)
|
||||
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
||||
else
|
||||
DEPS_FILES := $(wildcard .deps/*.d)
|
||||
ifneq ($(strip $(DEPS_FILES)),)
|
||||
include $(DEPS_FILES)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
endif # DEPS_DONE
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
DEPMODE := gcc
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // defaults for gcc
|
||||
# ************************************************************************/
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
|
||||
|
||||
CFLAGS_W =
|
||||
CFLAGS_M =
|
||||
CFLAGS_O =
|
||||
CXXFLAGS_W =
|
||||
CXXFLAGS_M =
|
||||
CXXFLAGS_O =
|
||||
|
||||
CFLAGS = $(call __mkflags,CFLAGS_W) $(call __mkflags,CFLAGS_M) $(call __mkflags,CFLAGS_O)
|
||||
CXXFLAGS = $(call __mkflags,CXXFLAGS_W) $(call __mkflags,CXXFLAGS_M) $(call __mkflags,CXXFLAGS_O)
|
||||
|
||||
|
||||
#
|
||||
# cflags
|
||||
#
|
||||
|
||||
##CFLAGS_WERROR = -Werror
|
||||
CFLAGS_WERROR =
|
||||
CFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wbad-function-cast -Wcast-align -Wcast-qual -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wwrite-strings
|
||||
CXXFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wcast-align -Wcast-qual -Winline -Woverloaded-virtual -Wpointer-arith -Wshadow -Wsign-promo -Wwrite-strings
|
||||
|
||||
##CFLAGS_M += -fno-builtin
|
||||
##CFLAGS_M += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
||||
CXXFLAGS_M = $(CFLAGS_M)
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS_O = -g -O0
|
||||
else
|
||||
##CFLAGS_O = -Os -fstrict-aliasing
|
||||
CFLAGS_O = -O2 -fstrict-aliasing
|
||||
##CFLAGS_O = -O2 -fno-strict-aliasing
|
||||
endif
|
||||
CXXFLAGS_O = $(CFLAGS_O) -fconserve-space
|
||||
##CXXFLAGS += -fasynchronous-exceptions
|
||||
|
||||
|
||||
#
|
||||
# cxxflags for g++ 3.2 or better
|
||||
|
||||
##CXXFLAGS_W += -Wdisabled-optimization -Wpacked
|
||||
|
||||
|
||||
#
|
||||
# ldflags
|
||||
#
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
LDFLAGS += -g
|
||||
else
|
||||
LDFLAGS += -s
|
||||
endif
|
||||
LDFLAGS += -Wl,-Map,$T.map
|
||||
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
|
||||
|
||||
# vi:nowrap
|
||||
@@ -1,48 +0,0 @@
|
||||
UDIR := $($(U)DIR)
|
||||
|
||||
ifneq ($(strip $(wildcard $(UDIR)/include)),) # { include
|
||||
DEFS += -DWITH_$(U)
|
||||
INCLUDES += -I$(UDIR)/include
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/debug/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/debug/src/.libs
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/$(release)/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/$(release)/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/$(target)/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/$(target)/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/release/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/release/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/src/.libs
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR))),)
|
||||
LIBDIRS += $(UDIR)
|
||||
DOS_LIBDIRS := $(DOS_LIBDIRS);$(UDIR)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
LDLIBS += -l$(u)
|
||||
DOS_LDLIBS += $(u).lib
|
||||
|
||||
|
||||
DEFS := $(DEFS)
|
||||
INCLUDES := $(INCLUDES)
|
||||
LIBDIRS := $(LIBDIRS)
|
||||
LDLIBS := $(LDLIBS)
|
||||
DOS_LDLIBS := $(DOS_LDLIBS)
|
||||
|
||||
endif # } include
|
||||
+41
-74
@@ -1,88 +1,55 @@
|
||||
#
|
||||
# UPX Makefile (GNU make) - works with unix/win32/djgpp2
|
||||
#
|
||||
# usage:
|
||||
# `make target=linux' # linux
|
||||
# `make target=dos32-djggp2' # dos32 - djggp2
|
||||
# `make target=win32-cygwin' # win32 - cygwin
|
||||
# `make target=win32-mingw32' # win32 - mingw32
|
||||
# `make target=win32-rsxnt' # win32 - rsxnt
|
||||
# `make target=win32-bc' # win32 - Borland C++
|
||||
# `make target=win32-dm' # win32 - Digital Mars C++
|
||||
# `make target=win32-ic' # win32 - Intel C++
|
||||
# `make target=win32-vc' # win32 - Visual C++
|
||||
# `make target=win32-wc' # win32 - Watcom C++
|
||||
# `make target=cross-amd64-linux' # x86_64-linux cross compiler
|
||||
# `make target=cross-mingw32' # i586-mingw32msvc cross compiler
|
||||
# `make target=cross-mint' # m68k-atari-mint cross compiler
|
||||
# `make target=gcc' # generic gcc
|
||||
#
|
||||
# you can also set the `UPX_MAKE_TARGET' environment variable.
|
||||
# UPX Makefile - needs GNU make 3.80 or better
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
export SHELL = /bin/sh
|
||||
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
|
||||
|
||||
# configuration section
|
||||
|
||||
ifeq ($(strip $(UCLDIR)),)
|
||||
# change this to reflect where the UCL library is
|
||||
UCLDIR = $(HOME)/local/src/ucl-1.03
|
||||
srcdir ?= $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
||||
ifneq ($(srcdir),./)
|
||||
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,')
|
||||
##$(info Info: using VPATH . $(srcdir))
|
||||
VPATH := . $(srcdir)
|
||||
endif
|
||||
|
||||
## you can set the default target here
|
||||
##target =
|
||||
ifeq ($(CXX),)
|
||||
CXX = g++
|
||||
endif
|
||||
ifeq ($(CXX),g++)
|
||||
CXXFLAGS += -O2 -MMD
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
|
||||
endif
|
||||
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
|
||||
CXXLD ?= $(CXX)
|
||||
|
||||
DEBUG = 0
|
||||
exeext ?= .out
|
||||
libext ?= .a
|
||||
objext ?= .o
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = ..
|
||||
# we need UCL and zlib - you can set envvar UCLDIR
|
||||
ifneq ($(wildcard $(UCLDIR)/include/ucl/ucl.h),)
|
||||
INCLUDES += -I$(UCLDIR)/include
|
||||
LIBS += $(addprefix -L,$(dir $(wildcard $(UCLDIR)/libucl$(libext) $(UCLDIR)/src/.libs/libucl$(libext))))
|
||||
endif
|
||||
LIBS += -lucl -lz
|
||||
|
||||
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
|
||||
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
|
||||
|
||||
##### You should not have to change anything below this line. #####
|
||||
all: upx$(exeext)
|
||||
|
||||
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
|
||||
$($(notdir $@).PRE_LINK_STEP)
|
||||
$(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS))
|
||||
$($(notdir $@).POST_LINK_STEP)
|
||||
|
||||
# /***********************************************************************
|
||||
# // object files
|
||||
# ************************************************************************/
|
||||
%.o : %.cpp
|
||||
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
|
||||
|
||||
# these use exceptions & RTTI
|
||||
OBJECTS1 = \
|
||||
compress$o except$o file$o lefile$o \
|
||||
filter$o linker$o mem$o msg$o stdcxx$o work$o ui$o \
|
||||
packer$o packerf$o packhead$o packmast$o \
|
||||
p_com$o p_djgpp2$o p_elks$o p_exe$o \
|
||||
p_lx_elf$o p_lx_exc$o p_lx_sep$o p_lx_sh$o \
|
||||
p_ps1$o p_sys$o p_tmt$o p_tos$o \
|
||||
p_unix$o p_vmlinz$o p_vmlinx$o p_w16ne$o p_w32pe$o p_wcle$o
|
||||
mostlyclean clean distclean maintainer-clean:
|
||||
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)
|
||||
|
||||
# no exceptions or RTTI
|
||||
OBJECTS2 = \
|
||||
filteri$o help$o main$o mygetopt$o snprintf$o util$o \
|
||||
c_init$o c_file$o c_none$o c_screen$o \
|
||||
s_object$o s_djgpp2$o s_vcsa$o s_win32$o
|
||||
|
||||
# pure C sources
|
||||
OBJECTS3 =
|
||||
|
||||
OBJECTS = $(OBJECTS1) $(OBJECTS2) $(OBJECTS3)
|
||||
LIBS =
|
||||
RESOURCES =
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // main
|
||||
# ************************************************************************/
|
||||
|
||||
override WITH_ZLIB = 1
|
||||
|
||||
include $(srcdir)/Makefile.bld
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
include $(srcdir)/Makedefs.dep
|
||||
|
||||
$(OBJECTS): miniacc.h
|
||||
|
||||
# vi:nowrap
|
||||
-include *.d
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
|
||||
@@ -1,720 +0,0 @@
|
||||
# /***********************************************************************
|
||||
# // prepare setup
|
||||
# ************************************************************************/
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .a .c .cpp .exe .lib .o .obj .rc .res .ttp
|
||||
|
||||
|
||||
ifeq ($(srcdir),)
|
||||
srcdir = .
|
||||
endif
|
||||
|
||||
VPATH = $(srcdir)
|
||||
|
||||
|
||||
# auto-detect the target unless given on the commandline
|
||||
ifeq ($(strip $(target)),)
|
||||
# try environment variable UPX_MAKE_TARGET
|
||||
target := $(UPX_MAKE_TARGET)
|
||||
endif
|
||||
ifeq ($(strip $(target)),)
|
||||
ifneq ($(strip $(wildcard /usr/include/linux)),)
|
||||
target = linux
|
||||
endif
|
||||
##ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),)
|
||||
##target = sparc-sun-solaris
|
||||
##endif
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(target)),)
|
||||
include please_specify_a_target
|
||||
endif
|
||||
|
||||
|
||||
# util var for use in the rules - basename of the current target
|
||||
override T = $(basename $@)
|
||||
|
||||
# expand "VAR" into "$(VAR) $(EXTRA_VAR) $(UPX_EXTRA_VAR)"
|
||||
override __mkflags = $(strip $($(1)) $(EXTRA_$(1)) $(UPX_EXTRA_$(1)))
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // compiler defaults
|
||||
# ************************************************************************/
|
||||
|
||||
CC_SRC = $<
|
||||
CXX_SRC = $<
|
||||
CC_COMPILE = $(CC) $(CCARCH) $(call __mkflags,DEFS) $(call __mkflags,INCLUDES) $(call __mkflags,CFLAGS) $(CFLAGS_OUTPUT) -c $(CC_SRC)
|
||||
CXX_COMPILE = $(CXX) $(CXXARCH) $(call __mkflags,DEFS) $(call __mkflags,INCLUDES) $(call __mkflags,CXXFLAGS) $(CXXFLAGS_OUTPUT) -c $(CXX_SRC)
|
||||
CXX_LINK_EXE = $(CXXLD) $(CXXLDARCH) $(call __mkflags,LDFLAGS) $(LINK_EXE_OUTPUT) $^ $(call __mkflags,LDLIBS)
|
||||
STUBEDIT_EXE =
|
||||
STUBIFY_EXE =
|
||||
CHMOD_EXE =
|
||||
|
||||
o = .o
|
||||
a = .a
|
||||
e =
|
||||
DEFS =
|
||||
INCLUDES =
|
||||
LIBDIRS =
|
||||
DOS_LDLIBS =
|
||||
DOS_LIBDIRS =
|
||||
|
||||
# CC defaults
|
||||
CC = INVALID_TARGET_CC
|
||||
CCARCH =
|
||||
CFLAGS =
|
||||
CFLAGS_OUTPUT =
|
||||
|
||||
# CXX defaults
|
||||
CXX = $(CC)
|
||||
CXXARCH = $(CCARCH)
|
||||
CXXFLAGS = $(CFLAGS)
|
||||
CXXFLAGS_OUTPUT = $(CFLAGS_OUTPUT)
|
||||
|
||||
# CXXLD defaults
|
||||
CXXLD = $(CXX)
|
||||
CXXLDARCH = $(CXXARCH)
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT =
|
||||
LDLIBS =
|
||||
LINK_EXE_LDFLAGS =
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
DEFS += -DDEBUG
|
||||
## DEFS += -DTESTING
|
||||
endif
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // compression libraries
|
||||
# ************************************************************************/
|
||||
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
DOS_LDLIBS += zlib.lib
|
||||
ZLIBDIR:=$(strip $(subst \,/,$(ZLIBDIR)))
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR))),)
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR)/include/zlib.h)),)
|
||||
INCLUDES += -I$(ZLIBDIR)/include
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR)/src/zlib.h)),)
|
||||
INCLUDES += -I$(ZLIBDIR)/src
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(ZLIBDIR)/zlib.h)),)
|
||||
INCLUDES += -I$(ZLIBDIR)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
UCLDIR:=$(strip $(subst \,/,$(UCLDIR)))
|
||||
NRVDIR:=$(strip $(subst \,/,$(NRVDIR)))
|
||||
u = ucl
|
||||
U = UCL
|
||||
upx_exe_tail =
|
||||
include $(srcdir)/Makedefs.inc
|
||||
ifneq ($(strip $(wildcard $(NRVDIR)/include/nrv)),)
|
||||
u = nrv
|
||||
U = NRV
|
||||
upx_exe_tail := _$(u)
|
||||
include $(srcdir)/Makedefs.inc
|
||||
endif
|
||||
upx_exe = upx$(upx_exe_tail)$(e)
|
||||
|
||||
override tmp := -Wl,--rpath,
|
||||
LDRPATH := $(addprefix $(tmp),$(LIBDIRS))
|
||||
LIBDIRS += .
|
||||
LDLIBDIRS := $(addprefix -L,$(LIBDIRS))
|
||||
|
||||
##LDFLAGS += $(LDRPATH)
|
||||
LDFLAGS += $(LDLIBDIRS)
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // compiler settings
|
||||
# ************************************************************************/
|
||||
|
||||
###
|
||||
### generic gcc
|
||||
###
|
||||
|
||||
ifeq ($(target),gcc)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### linux - gcc
|
||||
###
|
||||
|
||||
ifeq ($(target),linux)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
override arch := $(shell uname -m | sed -e 's/^i[3456789]86$$/i386/')
|
||||
ifeq ($(arch),i386)
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
endif
|
||||
DEFS += -D_FILE_OFFSET_BITS=64
|
||||
LDLIBS += -lmcheck
|
||||
##CFLAGS_WERROR = -Werror
|
||||
ifeq ($(DEBUG),1)
|
||||
else
|
||||
##LDFLAGS += -static
|
||||
STUBEDIT_EXE = objcopy -S -R .comment -R .note $@
|
||||
ifeq ($(arch),i386)
|
||||
## STUBIFY_EXE = perl $(srcdir)/stub/scripts/brandelf.pl $@
|
||||
endif
|
||||
endif
|
||||
CHMOD_EXE = chmod 755 $@
|
||||
endif # linux
|
||||
|
||||
|
||||
###
|
||||
### linux/i386 - Borland C++ 5.7 (Kylix 3)
|
||||
###
|
||||
|
||||
ifeq ($(target),linux-bc57)
|
||||
##DEPMODE := linux-XXX ## FIXME
|
||||
CC = bc++ -q -3
|
||||
CFLAGS = -w '-w!'
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS += -ls
|
||||
LINK_EXE_OUTPUT = -e$@
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
# warning: do not use option `-d' --> incorrect string merging will happen
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -dc
|
||||
else
|
||||
CFLAGS += -O2 -dc
|
||||
endif
|
||||
# transform `-lxx -lyy' into `libxx.a libyy.a'
|
||||
LDLIBS := $(shell echo "$(LDLIBS)" | perl -pe 's/-l(.+?)\b/lib\1.a/g')
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### linux/i386 - Intel C++
|
||||
###
|
||||
|
||||
ifeq ($(target),linux-intelc)
|
||||
DEPMODE := linux-intelc
|
||||
CC = icc
|
||||
CXX = icpc
|
||||
CCARCH += -march=i386 -mcpu=i686 -nolib_inline
|
||||
DEFS += -D_FILE_OFFSET_BITS=64
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
CFLAGS = $(CFLAGS_WERROR)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -g -O0
|
||||
else
|
||||
CFLAGS += -O2
|
||||
endif
|
||||
LDFLAGS += -Wl,-Map,$T.map
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### linux/i386 - Portland Group PGI C++ 5.x
|
||||
###
|
||||
|
||||
ifeq ($(target),linux-pgi)
|
||||
DEPMODE := linux-pgi
|
||||
CC = pgcc
|
||||
CXX = pgCC
|
||||
CCARCH += -tp=p6
|
||||
DEFS += -D_FILE_OFFSET_BITS=64
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
ifeq ($(WITH_ZLIB),1)
|
||||
LDLIBS += -lz
|
||||
endif
|
||||
##CFLAGS += -Minform=info
|
||||
CXXFLAGS = $(CFLAGS) -tused
|
||||
ifeq ($(DEBUG),1)
|
||||
else
|
||||
CFLAGS += -O2
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### Linux cross compilers
|
||||
###
|
||||
|
||||
ifeq ($(target),cross-amd64-linux)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
CC = x86_64-linux-gcc
|
||||
CXX = x86_64-linux-g++
|
||||
LDLIBS += -lmcheck
|
||||
endif # cross-amd64-linux
|
||||
|
||||
ifeq ($(target),cross-m68k-linux)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
CC = m68k-linux-gcc
|
||||
CXX = m68k-linux-g++
|
||||
##LDLIBS += -lmcheck
|
||||
endif # cross-m68k-linux
|
||||
|
||||
|
||||
###
|
||||
### sparc-sun-solaris2.8
|
||||
###
|
||||
|
||||
ifeq ($(target),sparc-sun-solaris)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### Atari cross compilers
|
||||
###
|
||||
|
||||
ifeq ($(target),cross-mint)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .ttp
|
||||
CC = m68k-atari-mint-gcc
|
||||
CXX = m68k-atari-mint-g++
|
||||
CCARCH += -m68000
|
||||
endif
|
||||
|
||||
ifeq ($(target),cross-mint-m68040)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .ttp
|
||||
CC = m68k-atari-mint-gcc
|
||||
CXX = m68k-atari-mint-g++
|
||||
CCARCH += -m68040
|
||||
endif
|
||||
|
||||
ifeq ($(target),cross-mint-m68020-60)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .ttp
|
||||
CC = m68k-atari-mint-gcc
|
||||
CXX = m68k-atari-mint-g++
|
||||
CCARCH += -m68020-60 -m68881
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### dos32 - djgpp2 / emx
|
||||
###
|
||||
|
||||
ifeq ($(target),dos32-djgpp2)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CXX = gxx
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
CFLAGS_WERROR = -Werror
|
||||
STUBEDIT_EXE = stubedit $@ bufsize=0xfc00
|
||||
ifneq ($(strip $(wildcard $(DJDIR)/bin/mfxdjstubify.ex[eE])),)
|
||||
ifneq ($(strip $(wildcard $(DJDIR)/bin/cwsdstub.ex[eE])),)
|
||||
STUBIFY_EXE = mfxdjstubify -v -s $(DJDIR)/bin/cwsdstub.exe $@
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(target),dos32-emx)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CXX = gcc
|
||||
CFLAGS_O = -O2
|
||||
CCARCH += -mno-probe
|
||||
LDFLAGS = -L. -s
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### win32 - cygwin / mingw32 / rsxnt
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-cygwin)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
##CXX = g++-2
|
||||
e = .exe
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
LDLIBS += -lwinmm
|
||||
endif
|
||||
|
||||
ifeq ($(target),win32-mingw32)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
LDLIBS += -lwinmm
|
||||
endif
|
||||
|
||||
# mingw32 cross compiler
|
||||
ifeq ($(target),cross-mingw32)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CC = i586-mingw32msvc-gcc
|
||||
CXX = i586-mingw32msvc-g++
|
||||
CCARCH += -march=i386 -mcpu=i686
|
||||
LDLIBS += -lwinmm
|
||||
endif
|
||||
|
||||
# rsxnt (g++ 2.8.1)
|
||||
ifeq ($(target),win32-rsxnt)
|
||||
include $(srcdir)/Makedefs.gcc
|
||||
e = .exe
|
||||
CXX = gcc
|
||||
CFLAGS_O = -O2
|
||||
CCARCH += -Zwin32 -Zsys -mno-probe
|
||||
LDFLAGS = -L. -s
|
||||
STUBEDIT_EXE = pestack -s1024 -c1024 $@
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### win32 - Borland C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-bc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = bcc32 -3
|
||||
ifeq ($(UPX_BROKEN_INCLUDES),1)
|
||||
ifneq ($(srcdir),.)
|
||||
INCLUDES += -I$(srcdir)
|
||||
endif
|
||||
INCLUDES += -I$(srcdir)/acc
|
||||
ifneq ($(strip $(wildcard $(srcdir)/filter)),)
|
||||
INCLUDES += -I$(srcdir)/filter
|
||||
endif
|
||||
endif
|
||||
CFLAGS = -w -w-inl -g1
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS = -ls
|
||||
LINK_EXE_OUTPUT = -e$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -d
|
||||
else
|
||||
CFLAGS += -O2 -d
|
||||
endif
|
||||
endif # win32-bc
|
||||
|
||||
|
||||
###
|
||||
### win32 - Digital Mars C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-dm)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = dmc -mn
|
||||
CFLAGS = -w- -wx
|
||||
CXXFLAGS = $(CFLAGS) -Aa -Ab -Ae -Ar
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS = -L/map
|
||||
LINK_EXE_OUTPUT = -o$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -o- -g -s
|
||||
else
|
||||
CFLAGS += -o
|
||||
endif
|
||||
endif # win32-dm
|
||||
|
||||
|
||||
###
|
||||
### win32 - Intel C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-ic)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = icl -nologo
|
||||
CFLAGS = -W3 -WX
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,2)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win32-ic
|
||||
|
||||
|
||||
###
|
||||
### win32 - Metrowerks C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-mwerks)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = mwcc -gccinc
|
||||
CFLAGS = -w on
|
||||
CXXFLAGS = $(CFLAGS)
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LDFLAGS = -lwinmm.lib -map $T.map
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -opt full
|
||||
else
|
||||
CFLAGS +=
|
||||
endif
|
||||
endif # win32-mwerks
|
||||
|
||||
|
||||
###
|
||||
### win32 - Symantec C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-sc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = sc -mn
|
||||
CFLAGS = -w- -wx
|
||||
CXXFLAGS = $(CFLAGS) -EH -ER
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS = -L/map
|
||||
LINK_EXE_OUTPUT = -o$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -o- -g -s
|
||||
else
|
||||
CFLAGS += -o
|
||||
endif
|
||||
endif # win32-sc
|
||||
|
||||
|
||||
###
|
||||
### win32 - Visual C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-vc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = cl -nologo
|
||||
CFLAGS = -W4 -WX
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,1)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
##LINK_EXE_LDFLAGS += /opt:nowin98
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win32-vc
|
||||
|
||||
|
||||
###
|
||||
### win32 - Watcom C++
|
||||
###
|
||||
|
||||
ifeq ($(target),win32-wc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = wcl386 -zq -bt=nt -mf -5r
|
||||
##CC = wcl386 -zq -bt=dos -l=CauseWay -mf -5r
|
||||
CFLAGS = -zc -w5 -we
|
||||
CXXFLAGS = $(CFLAGS) -xs -xr
|
||||
CFLAGS_OUTPUT = -fo=$@
|
||||
LDFLAGS = -k0x100000 -fm
|
||||
LINK_EXE_OUTPUT = -fe=$@
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
CC_SRC = $(subst /,\\,$<)
|
||||
CXX_SRC = $(subst /,\\,$<)
|
||||
INCLUDES := $(strip $(subst /,\\,$(INCLUDES)))
|
||||
ifeq (1,2)
|
||||
WCL386 := $(INCLUDES)
|
||||
export WCL386
|
||||
INCLUDES :=
|
||||
endif
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS +=
|
||||
else
|
||||
# note: it seems that the optimizer is generating bad code with `-ox'
|
||||
CFLAGS += -olr
|
||||
endif
|
||||
endif # win32-wc
|
||||
|
||||
|
||||
###
|
||||
### win64 - Intel C++ [Itanium]
|
||||
###
|
||||
|
||||
ifeq ($(target),win64-ic)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = ecl -nologo
|
||||
CFLAGS = -W3
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,2)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win64-ic
|
||||
|
||||
|
||||
###
|
||||
### win64 - Visual C++ [AMD64 or Itanium]
|
||||
###
|
||||
|
||||
ifeq ($(target),win64-vc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
e = .exe
|
||||
CC = cl -nologo
|
||||
CFLAGS = -W4 -Wall
|
||||
CXXFLAGS = $(CFLAGS) -EHac -GR
|
||||
LDFLAGS =
|
||||
LINK_EXE_OUTPUT = -Fe$@
|
||||
LINK_EXE_LDFLAGS = /link /map:$T.map
|
||||
##LINK_EXE_LDFLAGS += /verbose
|
||||
ifeq (1,1)
|
||||
# statically link libcmt.lib
|
||||
CC += -MT
|
||||
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
endif
|
||||
LDLIBS = $(DOS_LDLIBS)
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_EXE_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O1 -GF
|
||||
LINK_EXE_LDFLAGS += /release
|
||||
endif
|
||||
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
|
||||
endif # win64-vc
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // malloc debuggers and memory checkers - obsolete, use valgrind
|
||||
# ************************************************************************/
|
||||
|
||||
ifeq (1,2)
|
||||
# compile in extra valgrind support
|
||||
DEFS += -DWITH_VALGRIND
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
LDLIBS += -lefence
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
DEFS += -DWITH_DMALLOC
|
||||
LDLIBS += -ldmalloc
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
DEFS += -DWITH_GC -DLINUX_THREADS -D_REENTRANT
|
||||
LDLIBS += -lgc -lpthread
|
||||
# only needed when using -static:
|
||||
##LDFLAGS += -Wl,-defsym,_DYNAMIC=0
|
||||
endif
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // main targets
|
||||
# ************************************************************************/
|
||||
|
||||
-include ./Makefile.local
|
||||
|
||||
all: $(upx_exe)
|
||||
|
||||
$(upx_exe): $(OBJECTS) $(LIBS) $(RESOURCES)
|
||||
$(strip $(CXX_LINK_EXE))
|
||||
$(strip $(STUBEDIT_EXE))
|
||||
$(strip $(STUBIFY_EXE))
|
||||
$(strip $(CHMOD_EXE))
|
||||
|
||||
mostlyclean:
|
||||
-rm -f *.d *.err *.i *.log *.map gdb-trans*
|
||||
|
||||
clean: mostlyclean
|
||||
-rm -f *.a *.lib *.o *.obj *.res *.tds tags TAGS ID
|
||||
-rm -f *.idb *.pdb
|
||||
-rm -f $(upx_exe) upx upx.exe upx.ttp upx_nrv upx_nrv.exe upx_nrv.ttp upx_ucl upx_ucl.exe upx_ucl.ttp
|
||||
-rm -rf .deps _deps
|
||||
|
||||
distclean: clean
|
||||
|
||||
maintainer-clean: distclean
|
||||
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // rules
|
||||
# ************************************************************************/
|
||||
|
||||
%$o : %.c
|
||||
$(strip $(CC_COMPILE))
|
||||
|
||||
%$o : %.cpp
|
||||
$(strip $(CXX_COMPILE))
|
||||
|
||||
%.res : %.rc
|
||||
rc -l 0x409 -fo$@ $<
|
||||
|
||||
|
||||
# vi:nowrap
|
||||
+282
-173
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -34,132 +34,147 @@
|
||||
// core
|
||||
**************************************************************************/
|
||||
|
||||
inline unsigned get_be16(const void *bb)
|
||||
inline unsigned get_be16(const void *p)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[1] << 0;
|
||||
v |= (unsigned) b[0] << 8;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be16(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[1] = (unsigned char) (v >> 0);
|
||||
b[0] = (unsigned char) (v >> 8);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_be24(const void *bb)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[2] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
v |= (unsigned) b[0] << 16;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be24(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[2] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
b[0] = (unsigned char) (v >> 16);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_be32(const void *bb)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[3] << 0;
|
||||
v |= (unsigned) b[2] << 8;
|
||||
v |= (unsigned) b[1] << 16;
|
||||
v |= (unsigned) b[0] << 24;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be32(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[3] = (unsigned char) (v >> 0);
|
||||
b[2] = (unsigned char) (v >> 8);
|
||||
b[1] = (unsigned char) (v >> 16);
|
||||
b[0] = (unsigned char) (v >> 24);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_le16(const void *bb)
|
||||
{
|
||||
#if defined(ACC_GET_LE16)
|
||||
return ACC_GET_LE16(bb);
|
||||
#if defined(ACC_UA_GET_BE16)
|
||||
return ACC_UA_GET_BE16(p);
|
||||
#else
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
return v;
|
||||
return acc_ua_get_be16(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le16(void *bb, unsigned v)
|
||||
inline void set_be16(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_SET_LE16)
|
||||
ACC_SET_LE16(bb, v);
|
||||
#if defined(ACC_UA_SET_BE16)
|
||||
ACC_UA_SET_BE16(p, v);
|
||||
#else
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
acc_ua_set_be16(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_le24(const void *bb)
|
||||
inline unsigned get_be24(const void *p)
|
||||
{
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
v |= (unsigned) b[2] << 16;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_le24(void *bb, unsigned v)
|
||||
{
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
b[2] = (unsigned char) (v >> 16);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_le32(const void *bb)
|
||||
{
|
||||
#if defined(ACC_GET_LE32)
|
||||
return ACC_GET_LE32(bb);
|
||||
#if defined(ACC_UA_GET_BE24)
|
||||
return ACC_UA_GET_BE24(p);
|
||||
#else
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
v |= (unsigned) b[2] << 16;
|
||||
v |= (unsigned) b[3] << 24;
|
||||
return v;
|
||||
return acc_ua_get_be24(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le32(void *bb, unsigned v)
|
||||
inline void set_be24(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_SET_LE32)
|
||||
ACC_SET_LE32(bb, v);
|
||||
#if defined(ACC_UA_SET_BE24)
|
||||
ACC_UA_SET_BE24(p, v);
|
||||
#else
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
b[2] = (unsigned char) (v >> 16);
|
||||
b[3] = (unsigned char) (v >> 24);
|
||||
acc_ua_set_be24(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_be32(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_BE32)
|
||||
return ACC_UA_GET_BE32(p);
|
||||
#else
|
||||
return acc_ua_get_be32(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_be32(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_BE32)
|
||||
ACC_UA_SET_BE32(p, v);
|
||||
#else
|
||||
acc_ua_set_be32(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_be64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_BE64)
|
||||
return ACC_UA_GET_BE64(p);
|
||||
#else
|
||||
return acc_ua_get_be64(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_be64(void *p, acc_uint64l_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_BE64)
|
||||
ACC_UA_SET_BE64(p, v);
|
||||
#else
|
||||
acc_ua_set_be64(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_le16(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE16)
|
||||
return ACC_UA_GET_LE16(p);
|
||||
#else
|
||||
return acc_ua_get_le16(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le16(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE16)
|
||||
ACC_UA_SET_LE16(p, v);
|
||||
#else
|
||||
acc_ua_set_le16(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_le24(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE24)
|
||||
return ACC_UA_GET_LE24(p);
|
||||
#else
|
||||
return acc_ua_get_le24(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le24(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE24)
|
||||
ACC_UA_SET_LE24(p, v);
|
||||
#else
|
||||
acc_ua_set_le24(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned get_le32(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE32)
|
||||
return ACC_UA_GET_LE32(p);
|
||||
#else
|
||||
return acc_ua_get_le32(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le32(void *p, unsigned v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE32)
|
||||
ACC_UA_SET_LE32(p, v);
|
||||
#else
|
||||
acc_ua_set_le32(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_le64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE64)
|
||||
return ACC_UA_GET_LE64(p);
|
||||
#else
|
||||
return acc_ua_get_le64(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le64(void *p, acc_uint64l_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE64)
|
||||
ACC_UA_SET_LE64(p, v);
|
||||
#else
|
||||
acc_ua_set_le64(p, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -170,47 +185,66 @@ inline void set_le32(void *bb, unsigned v)
|
||||
|
||||
inline int sign_extend(int v, int bits)
|
||||
{
|
||||
const int sign_bit = 1 << (bits - 1);
|
||||
v |= -(v & sign_bit);
|
||||
const unsigned sign_bit = 1u << (bits - 1);
|
||||
v |= 0u - (v & sign_bit);
|
||||
return v;
|
||||
}
|
||||
|
||||
inline int get_be16_signed(const void *bb)
|
||||
inline acc_int64l_t sign_extend(acc_int64l_t v, int bits)
|
||||
{
|
||||
int v = get_be16(bb);
|
||||
const acc_uint64l_t sign_bit = ACC_UINT64_C(1) << (bits - 1);
|
||||
v |= ACC_UINT64_C(0) - (v & sign_bit);
|
||||
return v;
|
||||
}
|
||||
|
||||
inline int get_be16_signed(const void *p)
|
||||
{
|
||||
int v = get_be16(p);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_be24_signed(const void *bb)
|
||||
inline int get_be24_signed(const void *p)
|
||||
{
|
||||
int v = get_be24(bb);
|
||||
int v = get_be24(p);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_be32_signed(const void *bb)
|
||||
inline int get_be32_signed(const void *p)
|
||||
{
|
||||
int v = get_be32(bb);
|
||||
int v = get_be32(p);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline int get_le16_signed(const void *bb)
|
||||
inline acc_int64l_t get_be64_signed(const void *p)
|
||||
{
|
||||
int v = get_le16(bb);
|
||||
acc_int64l_t v = get_be64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
inline int get_le16_signed(const void *p)
|
||||
{
|
||||
int v = get_le16(p);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_le24_signed(const void *bb)
|
||||
inline int get_le24_signed(const void *p)
|
||||
{
|
||||
int v = get_le24(bb);
|
||||
int v = get_le24(p);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_le32_signed(const void *bb)
|
||||
inline int get_le32_signed(const void *p)
|
||||
{
|
||||
int v = get_le32(bb);
|
||||
int v = get_le32(p);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline int get_le64_signed(const void *p)
|
||||
{
|
||||
acc_int64l_t v = get_le64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// classes for portable unaligned access
|
||||
@@ -227,8 +261,13 @@ struct BE16
|
||||
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
|
||||
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
|
||||
BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; }
|
||||
BE16& operator *= (unsigned v) { set_be16(d, get_be16(d) * v); return *this; }
|
||||
BE16& operator /= (unsigned v) { set_be16(d, get_be16(d) / v); return *this; }
|
||||
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
|
||||
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
|
||||
BE16& operator ^= (unsigned v) { set_be16(d, get_be16(d) ^ v); return *this; }
|
||||
BE16& operator <<= (unsigned v) { set_be16(d, get_be16(d) << v); return *this; }
|
||||
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be16(d); }
|
||||
}
|
||||
@@ -242,14 +281,39 @@ struct BE32
|
||||
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
|
||||
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
|
||||
BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; }
|
||||
BE32& operator *= (unsigned v) { set_be32(d, get_be32(d) * v); return *this; }
|
||||
BE32& operator /= (unsigned v) { set_be32(d, get_be32(d) / v); return *this; }
|
||||
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
|
||||
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
|
||||
BE32& operator ^= (unsigned v) { set_be32(d, get_be32(d) ^ v); return *this; }
|
||||
BE32& operator <<= (unsigned v) { set_be32(d, get_be32(d) << v); return *this; }
|
||||
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct BE64
|
||||
{
|
||||
unsigned char d[8];
|
||||
|
||||
BE64& operator = (acc_uint64l_t v) { set_be64(d, v); return *this; }
|
||||
BE64& operator += (acc_uint64l_t v) { set_be64(d, get_be64(d) + v); return *this; }
|
||||
BE64& operator -= (acc_uint64l_t v) { set_be64(d, get_be64(d) - v); return *this; }
|
||||
BE64& operator *= (acc_uint64l_t v) { set_be64(d, get_be64(d) * v); return *this; }
|
||||
BE64& operator /= (acc_uint64l_t v) { set_be64(d, get_be64(d) / v); return *this; }
|
||||
BE64& operator &= (acc_uint64l_t v) { set_be64(d, get_be64(d) & v); return *this; }
|
||||
BE64& operator |= (acc_uint64l_t v) { set_be64(d, get_be64(d) | v); return *this; }
|
||||
BE64& operator ^= (acc_uint64l_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
|
||||
BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; }
|
||||
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_be64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct LE16
|
||||
{
|
||||
unsigned char d[2];
|
||||
@@ -257,8 +321,13 @@ struct LE16
|
||||
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
|
||||
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
|
||||
LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; }
|
||||
LE16& operator *= (unsigned v) { set_le16(d, get_le16(d) * v); return *this; }
|
||||
LE16& operator /= (unsigned v) { set_le16(d, get_le16(d) / v); return *this; }
|
||||
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
|
||||
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
|
||||
LE16& operator ^= (unsigned v) { set_le16(d, get_le16(d) ^ v); return *this; }
|
||||
LE16& operator <<= (unsigned v) { set_le16(d, get_le16(d) << v); return *this; }
|
||||
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le16(d); }
|
||||
}
|
||||
@@ -272,99 +341,139 @@ struct LE32
|
||||
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
|
||||
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
|
||||
LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; }
|
||||
LE32& operator *= (unsigned v) { set_le32(d, get_le32(d) * v); return *this; }
|
||||
LE32& operator /= (unsigned v) { set_le32(d, get_le32(d) / v); return *this; }
|
||||
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
|
||||
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
|
||||
LE32& operator ^= (unsigned v) { set_le32(d, get_le32(d) ^ v); return *this; }
|
||||
LE32& operator <<= (unsigned v) { set_le32(d, get_le32(d) << v); return *this; }
|
||||
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct LE64
|
||||
{
|
||||
unsigned char d[8];
|
||||
|
||||
LE64& operator = (acc_uint64l_t v) { set_le64(d, v); return *this; }
|
||||
LE64& operator += (acc_uint64l_t v) { set_le64(d, get_le64(d) + v); return *this; }
|
||||
LE64& operator -= (acc_uint64l_t v) { set_le64(d, get_le64(d) - v); return *this; }
|
||||
LE64& operator *= (acc_uint64l_t v) { set_le64(d, get_le64(d) * v); return *this; }
|
||||
LE64& operator /= (acc_uint64l_t v) { set_le64(d, get_le64(d) / v); return *this; }
|
||||
LE64& operator &= (acc_uint64l_t v) { set_le64(d, get_le64(d) & v); return *this; }
|
||||
LE64& operator |= (acc_uint64l_t v) { set_le64(d, get_le64(d) | v); return *this; }
|
||||
LE64& operator ^= (acc_uint64l_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
|
||||
LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; }
|
||||
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_le64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// global operators
|
||||
**************************************************************************/
|
||||
|
||||
inline bool operator < (const BE16& v1, const BE16& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const BE32& v1, const BE32& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const LE16& v1, const LE16& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const LE32& v1, const LE32& v2)
|
||||
{
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const BE16& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const BE32& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const BE32& v) { return ptr - (unsigned) v; }
|
||||
|
||||
// these are not implemented on purpose and will cause link-time errors
|
||||
template <class T> T* operator + (T* ptr, const BE64& v);
|
||||
template <class T> T* operator + (const BE64& v, T* ptr);
|
||||
template <class T> T* operator - (T* ptr, const BE64& v);
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const LE16& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator + (const LE32& v, T* ptr) { return ptr + (unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }
|
||||
|
||||
// these are not implemented on purpose and will cause link-time errors
|
||||
template <class T> T* operator + (T* ptr, const LE64& v);
|
||||
template <class T> T* operator + (const LE64& v, T* ptr);
|
||||
template <class T> T* operator - (T* ptr, const LE64& v);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
// for use with qsort()
|
||||
int __acc_cdecl_qsort be16_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be24_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be32_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le16_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le24_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le32_compare(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be16_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be24_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be32_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le16_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le24_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort le32_compare_signed(const void *e1, const void *e2);
|
||||
int __acc_cdecl_qsort be16_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be24_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be32_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be64_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le16_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le24_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le32_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort le64_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be16_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort be24_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort be32_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort be64_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le16_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le24_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le32_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
|
||||
// just for testing...
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_GNUC >= 0x030200)
|
||||
typedef unsigned short LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
#if !defined(ACC_CFG_NO_UNALIGNED)
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200)
|
||||
typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
# ifndef LE32
|
||||
# define LE32 LE32_unaligned
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_IA32) && (ACC_CC_INTELC)
|
||||
typedef __declspec(align(1)) unsigned short LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
#if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
# ifndef LE32
|
||||
# define LE32 LE32_unaligned
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
|
||||
typedef __declspec(align(1)) unsigned short LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
# ifndef LE32
|
||||
# define LE32 LE32_unaligned
|
||||
# endif
|
||||
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
+44
-8
@@ -26,6 +26,20 @@
|
||||
*/
|
||||
|
||||
|
||||
#if 1 && defined(UCL_USE_ASM)
|
||||
# include <ucl/ucl_asm.h>
|
||||
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
|
||||
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
|
||||
# define ucl_nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
|
||||
# define ucl_nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
|
||||
# define ucl_nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
|
||||
# define ucl_nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
|
||||
# define ucl_nrv2e_decompress_safe_8 ucl_nrv2e_decompress_asm_safe_8
|
||||
# define ucl_nrv2e_decompress_safe_le16 ucl_nrv2e_decompress_asm_safe_le16
|
||||
# define ucl_nrv2e_decompress_safe_le32 ucl_nrv2e_decompress_asm_safe_le32
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
@@ -89,15 +103,10 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
// prepare bit-buffer settings
|
||||
conf.bb_endian = 0;
|
||||
conf.bb_size = 0;
|
||||
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16)
|
||||
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
|
||||
{
|
||||
int n = (method - M_NRV2B_LE32) % 3;
|
||||
if (n == 0)
|
||||
conf.bb_size = 32;
|
||||
else if (n == 1)
|
||||
conf.bb_size = 8;
|
||||
else
|
||||
conf.bb_size = 16;
|
||||
static const unsigned char sizes[3]={32,8,16};
|
||||
conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
||||
}
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
@@ -119,6 +128,11 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
#endif
|
||||
#if 0 /*{*/
|
||||
else if M_IS_CL1B(method)
|
||||
r = cl1b_compress(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
#endif /*}*/
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
|
||||
@@ -171,6 +185,17 @@ int upx_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
#endif
|
||||
#if 0 /*{*/
|
||||
case M_CL1B_8:
|
||||
r = cl1b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE16:
|
||||
r = cl1b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE32:
|
||||
r = cl1b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
#endif /*}*/
|
||||
default:
|
||||
throwInternalError("unknown decompression method");
|
||||
break;
|
||||
@@ -225,6 +250,17 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
|
||||
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
#endif
|
||||
#if 0 /*{*/
|
||||
case M_CL1B_8:
|
||||
r = cl1b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE16:
|
||||
r = cl1b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_CL1B_LE32:
|
||||
r = cl1b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
#endif /*}*/
|
||||
default:
|
||||
throwInternalError("unknown decompression method");
|
||||
break;
|
||||
|
||||
+2
-4
@@ -32,14 +32,12 @@
|
||||
#if defined(WITH_NRV)
|
||||
# include "compress_nrv.ch"
|
||||
#elif defined(WITH_UCL)
|
||||
# define ALG_NRV2E
|
||||
# define upx_adler32 upx_adler32
|
||||
//# define upx_crc32 upx_crc32
|
||||
# define upx_compress upx_compress
|
||||
# define upx_decompress upx_decompress
|
||||
# if (UPX_VERSION_HEX >= 0x019000)
|
||||
# define ALG_NRV2E
|
||||
# define upx_test_overlap upx_test_overlap
|
||||
# endif
|
||||
# define upx_test_overlap upx_test_overlap
|
||||
# include "compress.ch"
|
||||
#else
|
||||
# error
|
||||
|
||||
+28
-13
@@ -146,7 +146,7 @@
|
||||
|
||||
|
||||
#if !defined(WITH_UCL)
|
||||
# error "please set UCLDIR in the Makefile"
|
||||
# define WITH_UCL 1
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
# include <ucl/uclconf.h>
|
||||
@@ -292,13 +292,16 @@
|
||||
#define index upx_index
|
||||
#define outp upx_outp
|
||||
|
||||
#undef PAGE_MASK
|
||||
#undef PAGE_SIZE
|
||||
|
||||
|
||||
#undef __attribute_packed
|
||||
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||
# if (1 && (ACC_ARCH_IA32))
|
||||
# if (1 && (ACC_ARCH_I386))
|
||||
# define __attribute_packed
|
||||
# else
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# endif
|
||||
#else
|
||||
# define __attribute_packed
|
||||
@@ -333,10 +336,10 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(acc_alignof)
|
||||
#if defined(__acc_alignof)
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \
|
||||
COMPILE_TIME_ASSERT(acc_alignof(a) == sizeof(b))
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(a) == sizeof(b))
|
||||
#else
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
|
||||
@@ -423,10 +426,14 @@ inline void operator delete[](void *p)
|
||||
#define M_NRV2E_LE32 8
|
||||
#define M_NRV2E_8 9
|
||||
#define M_NRV2E_LE16 10
|
||||
#define M_CL1B_LE32 11
|
||||
#define M_CL1B_8 12
|
||||
#define M_CL1B_LE16 13
|
||||
|
||||
#define M_IS_NRV2B(x) ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)
|
||||
#define M_IS_NRV2D(x) ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)
|
||||
#define M_IS_NRV2E(x) ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)
|
||||
#define M_IS_CL1B(x) ((x) >= M_CL1B_LE32 && (x) <= M_CL1B_LE16)
|
||||
|
||||
|
||||
// Executable formats. Note: big endian types are >= 128.
|
||||
@@ -449,8 +456,16 @@ inline void operator delete[](void *p)
|
||||
#define UPX_F_ELKS_8086 17
|
||||
#define UPX_F_PS1_EXE 18
|
||||
#define UPX_F_VMLINUX_i386 19
|
||||
#define UPX_F_LINUX_ELFI_i386 20
|
||||
#define UPX_F_WINCE_ARM_PE 21
|
||||
#define UPX_F_LINUX_ELF64_AMD 22
|
||||
|
||||
#define UPX_F_PLAIN_TEXT 127
|
||||
|
||||
#define UPX_F_ATARI_TOS 129
|
||||
#define UPX_F_SOLARIS_SPARC 130
|
||||
#define UPX_F_MACH_PPC32 131
|
||||
#define UPX_F_LINUX_ELFPPC32 132
|
||||
|
||||
|
||||
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
|
||||
@@ -477,7 +492,7 @@ inline void operator delete[](void *p)
|
||||
extern const char *progname;
|
||||
void init_options(struct options_t *o);
|
||||
bool set_ec(int ec);
|
||||
#if defined(__GNUC__)
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void e_exit(int ec) __attribute__((__noreturn__));
|
||||
#else
|
||||
void e_exit(int ec);
|
||||
@@ -489,23 +504,23 @@ void printSetNl(int need_nl);
|
||||
void printClearLine(FILE *f = NULL);
|
||||
void printErr(const char *iname, const Throwable *e);
|
||||
void printUnhandledException(const char *iname, const std::exception *e);
|
||||
#if defined(__GNUC__)
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(printf,2,3)));
|
||||
__attribute__((__format__(__printf__,2,3)));
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(printf,2,3)));
|
||||
__attribute__((__format__(__printf__,2,3)));
|
||||
#else
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void __acc_cdecl_va info(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
#else
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...);
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...);
|
||||
|
||||
@@ -40,6 +40,8 @@ void File::chmod(const char *name, int mode)
|
||||
#if defined(HAVE_CHMOD)
|
||||
if (::chmod(name,mode) != 0)
|
||||
throwIOException(name,errno);
|
||||
#else
|
||||
UNUSED(name); UNUSED(mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,6 @@ public:
|
||||
|
||||
off_t getBytesWritten() const { return bytes_written; }
|
||||
|
||||
#if (UPX_VERSION_HEX >= 0x019000)
|
||||
// FIXME - these won't work when using the `--stdout' option
|
||||
virtual void seek(off_t off, int whence)
|
||||
{
|
||||
@@ -144,7 +143,6 @@ public:
|
||||
write(buf, len);
|
||||
bytes_written -= len; // restore
|
||||
}
|
||||
#endif
|
||||
|
||||
// util
|
||||
static void dump(const char *name, const void *buf, int len, int flags=-1);
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -383,6 +383,46 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
|
||||
|
||||
#undef CT32
|
||||
|
||||
/*************************************************************************
|
||||
// 24-bit ARM calltrick ("naive")
|
||||
**************************************************************************/
|
||||
|
||||
#define CT24ARM(f, cond, addvalue, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 4; \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b) + (addvalue)); \
|
||||
f->calls++; \
|
||||
} \
|
||||
b += 4; \
|
||||
} while (b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 4; \
|
||||
return 0;
|
||||
|
||||
|
||||
#define ARMCT_COND (((b[3] & 0x0f) == 0x0b))
|
||||
|
||||
static int f_ct24arm_le(Filter *f)
|
||||
{
|
||||
CT24ARM(f, ARMCT_COND, a / 4 + f->addvalue, get_le24, set_le24)
|
||||
}
|
||||
|
||||
static int u_ct24arm_le(Filter *f)
|
||||
{
|
||||
CT24ARM(f, ARMCT_COND, 0 - a / 4 - f->addvalue, get_le24, set_le24)
|
||||
}
|
||||
|
||||
static int s_ct24arm_le(Filter *f)
|
||||
{
|
||||
CT24ARM(f, ARMCT_COND, a + f->addvalue, get_le24, set_dummy)
|
||||
}
|
||||
|
||||
#undef CT24ARM
|
||||
#undef ARMCT_COND
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/* ppcbxx.h -- PowerPC Branch trick
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2004-2005 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// filter / scan
|
||||
**************************************************************************/
|
||||
|
||||
#define W_CTO 4 /* width of cto; must match stub/ppc_bxx.S */
|
||||
|
||||
static int F(Filter *f)
|
||||
{
|
||||
#ifdef U
|
||||
// filter
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned addvalue = f->addvalue;
|
||||
#else
|
||||
// scan
|
||||
const upx_byte *b = f->buf;
|
||||
#endif
|
||||
const unsigned size = umin(f->buf_len, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = size -4;
|
||||
|
||||
unsigned ic;
|
||||
unsigned calls = 0, noncalls = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find 26-2-W_CTO bits of displacements that contain no targets
|
||||
{
|
||||
unsigned char buf[256];
|
||||
unsigned short wbuf[256];
|
||||
const size_t WW = (size_t)0 - (~(size_t)0) << W_CTO; // ???
|
||||
memset(wbuf, 0, sizeof(wbuf));
|
||||
memset(buf , 0, WW);
|
||||
memset(buf + WW, 1, 256 - WW);
|
||||
|
||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
||||
unsigned const off = (int)(get_be32(b+ic)<<6) >>6;
|
||||
if (size <= (off & (~0u<<2))+ic) {
|
||||
buf[(~(~0u<<W_CTO)) & (off>>(26 - W_CTO))] |= 1;
|
||||
++wbuf[0xff&(off>>18)];
|
||||
}
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0) {
|
||||
if (0!=W_CTO) // FIXME: what is this ???
|
||||
return -1;
|
||||
f->cto = 0;
|
||||
}
|
||||
}
|
||||
const unsigned char cto8 = f->cto;
|
||||
#ifdef U
|
||||
const unsigned cto = (unsigned)f->cto << (24+2 - W_CTO);
|
||||
#endif
|
||||
|
||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
||||
unsigned const word = get_be32(b+ic);
|
||||
unsigned const off = (int)(word<<6) >>6;
|
||||
unsigned const jc = (off & (~0u<<2))+ic;
|
||||
// try to detect 'real' calls only
|
||||
if (jc < size) {
|
||||
#ifdef U
|
||||
set_be32(b+ic,(0xfc000003&word) | (jc+addvalue+cto));
|
||||
#endif
|
||||
calls++;
|
||||
lastcall = ic;
|
||||
}
|
||||
else {
|
||||
assert(0==W_CTO // FIXME: what is this ???
|
||||
|| (~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
}
|
||||
}
|
||||
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#if 0
|
||||
printf("\ncalls=%d noncalls=%d text_size=%x calltrickoffset=%x\n",
|
||||
calls,noncalls,size,cto8);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// unfilter
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef U
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size4 = umin(f->buf_len - 4, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned addvalue = f->addvalue;
|
||||
|
||||
unsigned ic;
|
||||
|
||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
||||
unsigned const word = get_be32(b+ic);
|
||||
if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == f->cto) {
|
||||
unsigned const jc = word & (~(~0u<<(26 - W_CTO)) & (~0u<<2));
|
||||
set_be32(b+ic, (0xfc000003&word)|(0x03fffffc&(jc-ic-addvalue)));
|
||||
f->calls++;
|
||||
f->lastcall = ic;
|
||||
}
|
||||
else {
|
||||
f->noncalls++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#undef F
|
||||
#undef U
|
||||
|
||||
#undef W_CTO
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
+26
-1
@@ -22,13 +22,19 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "filter.h"
|
||||
|
||||
static unsigned
|
||||
umin(unsigned const a, unsigned const b)
|
||||
{
|
||||
return (a<=b) ? a : b;
|
||||
}
|
||||
|
||||
|
||||
#define set_dummy(p, v) ((void)0)
|
||||
#define get_8(p) (*(p))
|
||||
@@ -145,6 +151,19 @@
|
||||
#undef COND_CALL
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// PowerPC branch [incl. call] trick
|
||||
**************************************************************************/
|
||||
|
||||
#define COND(b,x) (18==(get_be32(b+x)>>26))
|
||||
#define F f_ppcbxx
|
||||
#define U u_ppcbxx
|
||||
#include "filter/ppcbxx.h"
|
||||
#define F s_ppcbxx
|
||||
#include "filter/ppcbxx.h"
|
||||
#undef COND
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// database for use in class Filter
|
||||
**************************************************************************/
|
||||
@@ -205,6 +224,9 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
||||
{ 0x46, 6, 0x00ffffff, f_ctok32_e8e9_bswap_le, u_ctok32_e8e9_bswap_le, s_ctok32_e8e9_bswap_le },
|
||||
{ 0x49, 6, 0x00ffffff, f_ctok32_e8e9_bswap_le, u_ctok32_e8e9_bswap_le, s_ctok32_e8e9_bswap_le },
|
||||
|
||||
// 24-bit calltrick for arm
|
||||
{ 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le },
|
||||
|
||||
// 32-bit cto calltrick with jmp and jcc(swap 0x0f/0x8Y) and relative renumbering
|
||||
{ 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
{ 0x81, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
@@ -230,6 +252,9 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
||||
{ 0xb1,99, 0, f_sub32_2, u_sub32_2, s_sub32_2 },
|
||||
{ 0xb2,99, 0, f_sub32_3, u_sub32_3, s_sub32_3 },
|
||||
{ 0xb3,99, 0, f_sub32_4, u_sub32_4, s_sub32_4 },
|
||||
|
||||
// PowerPC branch+call trick
|
||||
{ 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx },
|
||||
};
|
||||
|
||||
const int FilterImp::n_filters = TABLESIZE(filters);
|
||||
|
||||
+21
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -47,9 +47,9 @@ void show_head(void)
|
||||
#define V(x) (strcmp(UPX_VERSION_STRING, UPX_VERSION_STRING4) ? UPX_VERSION_STRING : UPX_VERSION_STRING x)
|
||||
fg = con_fg(f,FG_GREEN);
|
||||
con_fprintf(f,
|
||||
" Ultimate Packer for eXecutables\n"
|
||||
" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005\n"
|
||||
"UPX %-12s Markus F.X.J. Oberhumer & Laszlo Molnar %20s\n\n",
|
||||
" Ultimate Packer for eXecutables\n"
|
||||
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006\n"
|
||||
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||
V("d"),
|
||||
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
@@ -229,8 +229,7 @@ void show_help(int x)
|
||||
" --compress-icons=1 compress all but the first icon\n"
|
||||
" --compress-icons=2 compress all but the first icon directory [default]\n"
|
||||
" --compress-resources=0 do not compress any resources at all\n"
|
||||
" --strip-loadconf=0 do not strip SEH load config [default]\n"
|
||||
" --strip-loadconf=1 strip SEH load config [DANGEROUS]\n"
|
||||
" --keep-resource=list do not compress resources specified by list\n"
|
||||
" --strip-relocs=0 do not strip relocations\n"
|
||||
" --strip-relocs=1 strip relocations [default]\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
@@ -245,6 +244,11 @@ void show_help(int x)
|
||||
con_fprintf(f,"This version supports:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f," "
|
||||
// TODO:
|
||||
// support for mach/ppc32
|
||||
// support for linux elf/ppc32
|
||||
// support for linux elf/amd64
|
||||
" arm/pe,"
|
||||
" atari/tos,"
|
||||
" bvmlinuz/386,"
|
||||
" djgpp2/coff,"
|
||||
@@ -253,20 +257,21 @@ void show_help(int x)
|
||||
" dos/sys,"
|
||||
"\n "
|
||||
//" elks/8086,"
|
||||
" linux/386,"
|
||||
" linux/elf386,"
|
||||
" linux/sh386,"
|
||||
" linux/amd64,"
|
||||
" linux/i386,"
|
||||
" linux/ppc32,"
|
||||
" mach/ppc32,"
|
||||
" ps1/exe,"
|
||||
" rtm32/pe,"
|
||||
" tmt/adam,"
|
||||
"\n "
|
||||
" tmt/adam,"
|
||||
" vmlinux/386,"
|
||||
" 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 type `upx -L'.\n"
|
||||
// "\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details type `upx -L'.\n"
|
||||
"");
|
||||
|
||||
|
||||
@@ -348,10 +353,10 @@ void show_version(int x)
|
||||
#if defined(WITH_UCL)
|
||||
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
|
||||
#endif
|
||||
fprintf(f,"Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f,"Copyright (C) 1996-2005 Laszlo Molnar\n");
|
||||
fprintf(f,"Copyright (C) 2000-2005 John F. Reiser\n");
|
||||
fprintf(f,"Copyright (C) 2002-2005 Jens Medoch\n");
|
||||
fprintf(f,"Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f,"Copyright (C) 1996-2006 Laszlo Molnar\n");
|
||||
fprintf(f,"Copyright (C) 2000-2006 John F. Reiser\n");
|
||||
fprintf(f,"Copyright (C) 2002-2006 Jens Medoch\n");
|
||||
fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
|
||||
}
|
||||
|
||||
|
||||
+56
-29
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,33 +22,47 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "linker.h"
|
||||
|
||||
class LinkerLabel
|
||||
{
|
||||
enum { LINKER_MAX_LABEL_LEN = 32 };
|
||||
char label[LINKER_MAX_LABEL_LEN + 1];
|
||||
|
||||
public:
|
||||
unsigned set(const char *l)
|
||||
{
|
||||
strncpy(label, l, sizeof(label));
|
||||
return strlen(label) + 1;
|
||||
}
|
||||
operator const char *() const { return label; }
|
||||
};
|
||||
|
||||
|
||||
struct Linker::section
|
||||
{
|
||||
int istart;
|
||||
int ostart;
|
||||
int len;
|
||||
char name[8];
|
||||
int istart;
|
||||
int ostart;
|
||||
int len;
|
||||
LinkerLabel name;
|
||||
};
|
||||
|
||||
struct Linker::jump
|
||||
{
|
||||
int pos;
|
||||
int len;
|
||||
char tsect[8];
|
||||
int toffs;
|
||||
int pos;
|
||||
int len;
|
||||
int toffs;
|
||||
LinkerLabel tsect;
|
||||
};
|
||||
|
||||
Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
{
|
||||
iloader = new char[(ilen = plen) + 4096];
|
||||
iloader = new char[(ilen = plen) + 8192];
|
||||
memcpy(iloader,pdata,plen);
|
||||
oloader = new char[plen];
|
||||
olen = 0;
|
||||
@@ -57,7 +71,7 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
info = pinfo;
|
||||
njumps = nsections = frozen = 0;
|
||||
jumps = new jump[200];
|
||||
#define NSECTIONS 350
|
||||
#define NSECTIONS 550
|
||||
sections = new section[NSECTIONS];
|
||||
|
||||
char *p = iloader + info;
|
||||
@@ -65,10 +79,10 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
{
|
||||
if (get32(p))
|
||||
{
|
||||
memcpy(sections[nsections].name,p,8);
|
||||
sections[nsections].istart = get32(p+8);
|
||||
p += sections[nsections].name.set(p);
|
||||
sections[nsections].istart = get32(p);
|
||||
sections[nsections++].ostart = -1;
|
||||
p += 12;
|
||||
p += 4;
|
||||
assert(nsections < NSECTIONS);
|
||||
}
|
||||
else
|
||||
@@ -79,9 +93,9 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
|
||||
jumps[njumps].pos = l+1;
|
||||
jumps[njumps].len = get32(p+4)-jumps[njumps].pos;
|
||||
memcpy(jumps[njumps].tsect,p+8,8);
|
||||
jumps[njumps++].toffs = get32(p+16);
|
||||
p += 20;
|
||||
p += 8 + jumps[njumps].tsect.set(p + 8);
|
||||
jumps[njumps++].toffs = get32(p);
|
||||
p += 4;
|
||||
assert(njumps < 200);
|
||||
}
|
||||
}
|
||||
@@ -112,11 +126,21 @@ static int hex(char c)
|
||||
return (c & 0xf) + (c > '9' ? 9 : 0);
|
||||
}
|
||||
|
||||
int Linker::addSection(const char *sect)
|
||||
int Linker::addSection(const char *psect)
|
||||
{
|
||||
int ic;
|
||||
while (*sect)
|
||||
if (psect[0] == 0)
|
||||
return olen;
|
||||
char *begin = strdup(psect);
|
||||
char *end = begin + strlen(begin);
|
||||
for (char *sect = begin; sect < end; )
|
||||
{
|
||||
for (char *tokend = sect; *tokend; tokend++)
|
||||
if (*tokend == ' ' || *tokend == ',')
|
||||
{
|
||||
*tokend = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (*sect == '+') // alignment
|
||||
{
|
||||
if (sect[1] == '0')
|
||||
@@ -131,19 +155,22 @@ int Linker::addSection(const char *sect)
|
||||
}
|
||||
else
|
||||
{
|
||||
int ic;
|
||||
for (ic = 0; ic < nsections; ic++)
|
||||
if (memcmp(sect,sections[ic].name,8) == 0)
|
||||
if (strcmp(sect, sections[ic].name) == 0)
|
||||
{
|
||||
memcpy(oloader+olen,iloader+sections[ic].istart,sections[ic].len);
|
||||
sections[ic].ostart = olen;
|
||||
olen += sections[ic].len;
|
||||
break;
|
||||
}
|
||||
//printf("%8.8s",sect);
|
||||
assert(ic!=nsections);
|
||||
if (ic == nsections)
|
||||
printf("%s", sect);
|
||||
assert(ic != nsections);
|
||||
}
|
||||
sect += 8;
|
||||
sect += strlen(sect) + 1;
|
||||
}
|
||||
free(begin);
|
||||
return olen;
|
||||
}
|
||||
|
||||
@@ -151,7 +178,7 @@ int Linker::addSection(const char *sect)
|
||||
void Linker::addSection(const char *sname, const void *sdata, unsigned len)
|
||||
{
|
||||
// add a new section - can be used for adding stuff like ident or header
|
||||
memcpy(sections[nsections].name,sname,8);
|
||||
sections[nsections].name.set(sname);
|
||||
sections[nsections].istart = ilen;
|
||||
sections[nsections].len = len;
|
||||
sections[nsections++].ostart = olen;
|
||||
@@ -177,7 +204,7 @@ const char *Linker::getLoader(int *llen)
|
||||
continue;
|
||||
|
||||
for (kc = 0; kc < nsections-1; kc++)
|
||||
if (memcmp(jumps[ic].tsect,sections[kc].name,8) == 0)
|
||||
if (strcmp(jumps[ic].tsect,sections[kc].name) == 0)
|
||||
break;
|
||||
assert(kc!=nsections-1);
|
||||
|
||||
@@ -203,7 +230,7 @@ int Linker::getSection(const char *name, int *slen) const
|
||||
if (!frozen)
|
||||
return -1;
|
||||
for (int ic = 0; ic < nsections; ic++)
|
||||
if (memcmp(name,sections[ic].name,8) == 0)
|
||||
if (strcmp(name, sections[ic].name) == 0)
|
||||
{
|
||||
if (slen)
|
||||
*slen = sections[ic].len;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+118
-40
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -71,12 +71,12 @@ void init_options(struct options_t *o)
|
||||
for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++)
|
||||
o->win32_pe.compress_rt[i] = -1;
|
||||
o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
|
||||
o->win32_pe.strip_loadconf = -1;
|
||||
o->win32_pe.strip_relocs = -1;
|
||||
o->win32_pe.keep_resource = "";
|
||||
}
|
||||
|
||||
static struct options_t global_options;
|
||||
struct options_t * volatile opt = &global_options;
|
||||
struct options_t *opt = &global_options;
|
||||
|
||||
static int done_output_name = 0;
|
||||
static int done_script_name = 0;
|
||||
@@ -444,7 +444,7 @@ static int do_option(int optc, const char *arg)
|
||||
set_cmd(CMD_DECOMPRESS);
|
||||
break;
|
||||
case 'D':
|
||||
opt->debug++;
|
||||
opt->debug.debug_level++;
|
||||
break;
|
||||
case 'f':
|
||||
opt->force++;
|
||||
@@ -538,6 +538,23 @@ static int do_option(int optc, const char *arg)
|
||||
e_method(opt->method, 10);
|
||||
break;
|
||||
|
||||
// debug
|
||||
case 542:
|
||||
if (!mfx_optarg || strlen(mfx_optarg) != 4)
|
||||
e_optarg(arg);
|
||||
memcpy(opt->debug.fake_stub_version, mfx_optarg, 4);
|
||||
break;
|
||||
case 543:
|
||||
if (!mfx_optarg || strlen(mfx_optarg) != 4)
|
||||
e_optarg(arg);
|
||||
memcpy(opt->debug.fake_stub_year, mfx_optarg, 4);
|
||||
break;
|
||||
case 544:
|
||||
if (!mfx_optarg || !mfx_optarg[0])
|
||||
e_optarg(arg);
|
||||
opt->debug.dump_stub_loader = mfx_optarg;
|
||||
break;
|
||||
|
||||
// misc
|
||||
case 512:
|
||||
opt->console = CON_FILE;
|
||||
@@ -567,6 +584,7 @@ static int do_option(int optc, const char *arg)
|
||||
case 522: // --no-filter
|
||||
opt->filter = 0;
|
||||
opt->all_filters = false;
|
||||
opt->no_filter = true;
|
||||
break;
|
||||
case 523: // --all-filters
|
||||
opt->all_filters = true;
|
||||
@@ -677,10 +695,7 @@ static int do_option(int optc, const char *arg)
|
||||
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
|
||||
break;
|
||||
case 633:
|
||||
opt->win32_pe.strip_loadconf = 1;
|
||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||
opt->win32_pe.strip_loadconf = 0;
|
||||
//printf("strip_loadconf: %d\n", opt->win32_pe.strip_loadconf);
|
||||
// opt->win32_pe.strip_loadconf - OBSOLETE - IGNORED
|
||||
break;
|
||||
case 634:
|
||||
opt->win32_pe.strip_relocs = 1;
|
||||
@@ -688,6 +703,11 @@ static int do_option(int optc, const char *arg)
|
||||
opt->win32_pe.strip_relocs = 0;
|
||||
//printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
|
||||
break;
|
||||
case 635:
|
||||
if (!mfx_optarg || !mfx_optarg[0])
|
||||
e_optarg(arg);
|
||||
opt->win32_pe.keep_resource = mfx_optarg;
|
||||
break;
|
||||
case 650:
|
||||
opt->atari_tos.split_segments = true;
|
||||
break;
|
||||
@@ -703,7 +723,13 @@ static int do_option(int optc, const char *arg)
|
||||
set_script_name(mfx_optarg,1);
|
||||
break;
|
||||
case 663:
|
||||
opt->o_unix.ptinterp = true;
|
||||
opt->o_unix.is_ptinterp = true;
|
||||
break;
|
||||
case 664:
|
||||
opt->o_unix.use_ptinterp = true;
|
||||
break;
|
||||
case 665:
|
||||
opt->o_unix.make_ptinterp = true;
|
||||
break;
|
||||
case 670:
|
||||
opt->ps1_exe.boot_only = true;
|
||||
@@ -750,7 +776,6 @@ static const struct mfx_option longopts[] =
|
||||
{"version", 0, 0, 'V'+256}, // display version number
|
||||
|
||||
// options
|
||||
{"debug", 0x10, 0, 'D'},
|
||||
{"force", 0, 0, 'f'}, // force overwrite of output files
|
||||
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files
|
||||
{"info", 0, 0, 'i'}, // info mode
|
||||
@@ -766,6 +791,12 @@ static const struct mfx_option longopts[] =
|
||||
#endif
|
||||
{"verbose", 0, 0, 'v'}, // verbose mode
|
||||
|
||||
// debug options
|
||||
{"debug", 0x10, 0, 'D'},
|
||||
{"dump-stub-loader" ,0x31, 0, 544}, // for internal debugging
|
||||
{"fake-stub-version",0x31, 0, 542}, // for internal debugging
|
||||
{"fake-stub-year" ,0x31, 0, 543}, // for internal debugging
|
||||
|
||||
// backup options
|
||||
{"backup", 0, 0, 'k'},
|
||||
{"keep", 0, 0, 'k'},
|
||||
@@ -823,15 +854,18 @@ static const struct mfx_option longopts[] =
|
||||
#if 0
|
||||
{"script", 0x31, 0, 662}, // --script=
|
||||
#endif
|
||||
{"ptinterp", 0, 0, 663}, // linux/elf386 PT_INTERP program
|
||||
{"is_ptinterp", 0, 0, 663}, // linux/elf386 PT_INTERP program
|
||||
{"use_ptinterp", 0, 0, 664}, // linux/elf386 PT_INTERP program
|
||||
{"make_ptinterp", 0, 0, 665}, // linux/elf386 PT_INTERP program
|
||||
// watcom/le
|
||||
{"le", 0, 0, 620}, // produce LE output
|
||||
// win32/pe
|
||||
{"compress-exports", 2, 0, 630},
|
||||
{"compress-icons", 2, 0, 631},
|
||||
{"compress-resources", 2, 0, 632},
|
||||
{"strip-loadconf", 0x12, 0, 633},
|
||||
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
|
||||
{"strip-relocs", 0x12, 0, 634},
|
||||
{"keep-resource", 0x31, 0, 635},
|
||||
// ps1/exe
|
||||
{"boot-only", 0x10, 0, 670},
|
||||
{"no-align", 0x10, 0, 671},
|
||||
@@ -912,8 +946,9 @@ static const struct mfx_option longopts[] =
|
||||
{"compress-exports", 2, 0, 630},
|
||||
{"compress-icons", 2, 0, 631},
|
||||
{"compress-resources", 2, 0, 632},
|
||||
{"strip-loadconf", 0x12, 0, 633},
|
||||
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
|
||||
{"strip-relocs", 0x12, 0, 634},
|
||||
{"keep-resource", 0x31, 0, 635},
|
||||
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
@@ -1028,6 +1063,27 @@ static void first_options(int argc, char **argv)
|
||||
// assert a sane architecture and compiler
|
||||
**************************************************************************/
|
||||
|
||||
template <class T> struct TestBELE {
|
||||
static int test(void)
|
||||
{
|
||||
T allbits; allbits = 0; allbits -= 1;
|
||||
T v1; v1 = 1; v1 *= 2; v1 -= 1;
|
||||
T v2; v2 = 1;
|
||||
assert( (v1 == v2)); assert(!(v1 != v2));
|
||||
assert( (v1 <= v2)); assert( (v1 >= v2));
|
||||
assert(!(v1 < v2)); assert(!(v1 > v2));
|
||||
v2 ^= allbits;
|
||||
assert(!(v1 == v2)); assert( (v1 != v2));
|
||||
assert( (v1 <= v2)); assert(!(v1 >= v2));
|
||||
assert( (v1 < v2)); assert(!(v1 > v2));
|
||||
v2 += 2;
|
||||
assert(v1 == 1); assert(v2 == 0);
|
||||
v1 <<= 1; v1 |= v2; v1 >>= 1; v2 &= v1; v2 /= v1; v2 *= v1;
|
||||
assert(v1 == 1); assert(v2 == 0);
|
||||
return (v1 ^ v2) == 1;
|
||||
}};
|
||||
|
||||
|
||||
#define ACC_WANT_ACC_CHK_CH 1
|
||||
#undef ACCCHK_ASSERT
|
||||
#include "miniacc.h"
|
||||
@@ -1051,40 +1107,67 @@ void upx_sanity_check(void)
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(BE64) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE64) == 8)
|
||||
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE64, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE64, char)
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
|
||||
assert(strlen(UPX_VERSION_STRING4) == 4);
|
||||
assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0);
|
||||
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_YEAR) == 4 + 1)
|
||||
assert(strlen(UPX_VERSION_YEAR) == 4);
|
||||
assert(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0);
|
||||
assert(memcmp(UPX_VERSION_DATE + strlen(UPX_VERSION_DATE) - 4, UPX_VERSION_YEAR, 4) == 0);
|
||||
|
||||
#if 1
|
||||
const unsigned char dd[4] = { 0xff, 0xfe, 0xfd, 0xfc };
|
||||
assert(upx_adler32(dd, 4) == 0x09f003f7);
|
||||
assert(upx_adler32(dd, 4, 0) == 0x09ec03f6);
|
||||
assert(upx_adler32(dd, 4, 1) == 0x09f003f7);
|
||||
|
||||
assert(get_be16(dd) == 0xfffe);
|
||||
assert(get_be16_signed(dd) == -2);
|
||||
assert(get_be24(dd) == 0xfffefd);
|
||||
assert(get_be24_signed(dd) == -259);
|
||||
assert(get_be32(dd) == 0xfffefdfc);
|
||||
assert(get_be32_signed(dd) == -66052);
|
||||
assert(get_le16(dd) == 0xfeff);
|
||||
assert(get_le16_signed(dd) == -257);
|
||||
assert(get_le24(dd) == 0xfdfeff);
|
||||
assert(get_le24_signed(dd) == -131329);
|
||||
assert(get_le32(dd) == 0xfcfdfeff);
|
||||
assert(get_le32_signed(dd) == -50462977);
|
||||
assert(find_be16(dd, sizeof(dd), 0xfffe) == 0);
|
||||
assert(find_le16(dd, sizeof(dd), 0xfeff) == 0);
|
||||
assert(find_be32(dd, sizeof(dd), 0xfffefdfc) == 0);
|
||||
assert(find_le32(dd, sizeof(dd), 0xfcfdfeff) == 0);
|
||||
# if 1 && !defined(UPX_OFFICIAL_BUILD)
|
||||
assert(TestBELE<LE16>::test());
|
||||
assert(TestBELE<LE32>::test());
|
||||
assert(TestBELE<LE64>::test());
|
||||
assert(TestBELE<BE16>::test());
|
||||
assert(TestBELE<BE32>::test());
|
||||
assert(TestBELE<BE64>::test());
|
||||
# endif
|
||||
{
|
||||
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
0, 0, 0, 0, 0 };
|
||||
const unsigned char *d;
|
||||
d = dd + 7;
|
||||
assert(upx_adler32(d, 4) == 0x09f003f7);
|
||||
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
|
||||
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
|
||||
assert(get_be16(d) == 0xfffe);
|
||||
assert(get_be16_signed(d) == -2);
|
||||
assert(get_be24(d) == 0xfffefd);
|
||||
assert(get_be24_signed(d) == -259);
|
||||
assert(get_be32(d) == 0xfffefdfc);
|
||||
assert(get_be32_signed(d) == -66052);
|
||||
assert(get_le16(d) == 0xfeff);
|
||||
assert(get_le16_signed(d) == -257);
|
||||
assert(get_le24(d) == 0xfdfeff);
|
||||
assert(get_le24_signed(d) == -131329);
|
||||
assert(get_le32(d) == 0xfcfdfeff);
|
||||
assert(get_le32_signed(d) == -50462977);
|
||||
assert(find_be16(d, 2, 0xfffe) == 0);
|
||||
assert(find_le16(d, 2, 0xfeff) == 0);
|
||||
assert(find_be32(d, 4, 0xfffefdfc) == 0);
|
||||
assert(find_le32(d, 4, 0xfcfdfeff) == 0);
|
||||
d += 12;
|
||||
assert(get_be16_signed(d) == 32638);
|
||||
assert(get_be24_signed(d) == 8355453);
|
||||
assert(get_be32_signed(d) == 2138996092);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1104,11 +1187,6 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
#if 0 && defined(__DJGPP__)
|
||||
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
|
||||
putenv("LFN=y");
|
||||
#endif
|
||||
#if defined(__MINT__)
|
||||
__binmode(1);
|
||||
__set_binmode(stdout, 0);
|
||||
__set_binmode(stderr, 0);
|
||||
#endif
|
||||
acc_wildargv(&argc, &argv);
|
||||
|
||||
|
||||
+6
-4
@@ -60,6 +60,8 @@ static int mcheck_init()
|
||||
MemBuffer::MemBuffer() :
|
||||
b(NULL), b_size(0)
|
||||
{
|
||||
if (use_mcheck < 0)
|
||||
mcheck_init();
|
||||
}
|
||||
|
||||
MemBuffer::MemBuffer(unsigned size) :
|
||||
@@ -87,7 +89,7 @@ void MemBuffer::dealloc()
|
||||
set_be32(b + b_size, 0);
|
||||
set_be32(b + b_size + 4, 0);
|
||||
//
|
||||
::free(b - 8);
|
||||
::free(b - 16);
|
||||
}
|
||||
else
|
||||
::free(b);
|
||||
@@ -115,7 +117,7 @@ void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra
|
||||
unsigned size = uncompressed_size + extra;
|
||||
// size += 512; // 512 safety bytes
|
||||
// INFO: 3 bytes are the allowed overrun for the i386 asm_fast decompressors
|
||||
#if (ACC_ARCH_IA32)
|
||||
#if (ACC_ARCH_I386)
|
||||
size += 3;
|
||||
#endif
|
||||
alloc(size);
|
||||
@@ -173,7 +175,7 @@ void MemBuffer::alloc(unsigned size)
|
||||
assert(b_size == 0);
|
||||
//
|
||||
assert((int)size > 0);
|
||||
unsigned total = use_mcheck ? size + 16 : size;
|
||||
unsigned total = use_mcheck ? size + 32 : size;
|
||||
assert((int)total > 0);
|
||||
unsigned char *p = (unsigned char *) malloc(total);
|
||||
if (!p)
|
||||
@@ -185,7 +187,7 @@ void MemBuffer::alloc(unsigned size)
|
||||
b_size = size;
|
||||
if (use_mcheck)
|
||||
{
|
||||
b = p + 8;
|
||||
b = p + 16;
|
||||
// store magic constants to detect buffer overruns
|
||||
set_be32(b - 8, b_size);
|
||||
set_be32(b - 4, MAGIC1(b));
|
||||
|
||||
+2636
-1053
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -66,9 +66,9 @@ void printClearLine(FILE *f)
|
||||
static void pr_print(bool c, const char *msg)
|
||||
{
|
||||
if (c && !opt->to_stdout)
|
||||
con_fprintf(stderr,msg);
|
||||
con_fprintf(stderr, "%s", msg);
|
||||
else
|
||||
fprintf(stderr,msg);
|
||||
fprintf(stderr, "%s", msg);
|
||||
}
|
||||
|
||||
static void pr_error(const char *iname, const char *msg, bool is_warning)
|
||||
|
||||
+14
-4
@@ -51,11 +51,11 @@ struct options_t {
|
||||
int filter; // preferred filter from Packer::getFilters()
|
||||
bool all_methods; // try all available compression methods ?
|
||||
bool all_filters; // try all available filters ?
|
||||
bool no_filter; // force no filter
|
||||
|
||||
// other options
|
||||
int backup;
|
||||
int console;
|
||||
int debug;
|
||||
int force;
|
||||
int info_mode;
|
||||
bool ignorewarn;
|
||||
@@ -66,6 +66,14 @@ struct options_t {
|
||||
int verbose;
|
||||
bool to_stdout;
|
||||
|
||||
// debug options
|
||||
struct {
|
||||
int debug_level;
|
||||
const char *dump_stub_loader;
|
||||
char fake_stub_version[4+1]; // for internal debugging
|
||||
char fake_stub_year[4+1]; // for internal debugging
|
||||
} debug;
|
||||
|
||||
// overlay handling
|
||||
enum {
|
||||
SKIP_OVERLAY = 0,
|
||||
@@ -116,7 +124,9 @@ struct options_t {
|
||||
struct {
|
||||
unsigned blocksize;
|
||||
bool force_execve; // force the linux/386 execve format
|
||||
bool ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
bool use_ptinterp; // use PT_INTERP /opt/upx/run
|
||||
bool make_ptinterp; // make PT_INTERP [ignore current file!]
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
} o_unix;
|
||||
@@ -128,12 +138,12 @@ struct options_t {
|
||||
int compress_icons;
|
||||
int compress_resources;
|
||||
signed char compress_rt[25]; // 25 == RT_LAST
|
||||
int strip_loadconf;
|
||||
int strip_relocs;
|
||||
const char *keep_resource;
|
||||
} win32_pe;
|
||||
};
|
||||
|
||||
extern struct options_t * volatile opt;
|
||||
extern struct options_t *opt;
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
+2532
File diff suppressed because it is too large
Load Diff
+257
@@ -0,0 +1,257 @@
|
||||
/* p_armpe.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_ARMPE_H
|
||||
#define __UPX_P_ARMPE_H
|
||||
|
||||
|
||||
class PackArmPe_Interval;
|
||||
class PackArmPe_Reloc;
|
||||
class PackArmPe_Resource;
|
||||
class PackArmPe_Export;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// arm/pe
|
||||
**************************************************************************/
|
||||
|
||||
class PackArmPe : public Packer
|
||||
{
|
||||
typedef Packer super;
|
||||
|
||||
public:
|
||||
PackArmPe(InputFile *f);
|
||||
~PackArmPe();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_WINCE_ARM_PE; }
|
||||
virtual const char *getName() const { return "arm/pe"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
virtual int canUnpack();
|
||||
|
||||
// unpacker capabilities
|
||||
virtual bool canUnpackVersion(int version) const
|
||||
{ return version == 13; }
|
||||
|
||||
protected:
|
||||
virtual int readFileHeader();
|
||||
virtual bool testUnpackVersion(int version) const;
|
||||
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
|
||||
unsigned pe_offset;
|
||||
|
||||
unsigned processImports();
|
||||
void processImports(unsigned, unsigned);
|
||||
void rebuildImports(upx_byte *&);
|
||||
upx_byte *oimport;
|
||||
unsigned soimport;
|
||||
upx_byte *oimpdlls;
|
||||
unsigned soimpdlls;
|
||||
|
||||
void processRelocs();
|
||||
void processRelocs(PackArmPe_Reloc *);
|
||||
void rebuildRelocs(upx_byte *&);
|
||||
upx_byte *orelocs;
|
||||
unsigned sorelocs;
|
||||
upx_byte *oxrelocs;
|
||||
unsigned soxrelocs;
|
||||
|
||||
void processExports(PackArmPe_Export *);
|
||||
void processExports(PackArmPe_Export *,unsigned);
|
||||
void rebuildExports();
|
||||
upx_byte *oexport;
|
||||
unsigned soexport;
|
||||
|
||||
void processResources(PackArmPe_Resource *);
|
||||
void processResources(PackArmPe_Resource *, unsigned);
|
||||
void rebuildResources(upx_byte *&);
|
||||
upx_byte *oresources;
|
||||
unsigned soresources;
|
||||
|
||||
void processTls(PackArmPe_Interval *);
|
||||
void processTls(PackArmPe_Reloc *,const PackArmPe_Interval *,unsigned);
|
||||
void rebuildTls();
|
||||
upx_byte *otls;
|
||||
unsigned sotls;
|
||||
|
||||
unsigned stripDebug(unsigned);
|
||||
|
||||
unsigned icondir_offset;
|
||||
int icondir_count;
|
||||
|
||||
bool importbyordinal;
|
||||
bool kernel32ordinal;
|
||||
unsigned tlsindex;
|
||||
unsigned rvamin;
|
||||
unsigned cimports; // rva of preprocessed imports
|
||||
unsigned crelocs; // rva of preprocessed fixups
|
||||
int big_relocs;
|
||||
|
||||
bool use_thumb_stub;
|
||||
|
||||
void createLinker(const void *pdata, int plen, int pinfo);
|
||||
int rpatch_le32(void *b, int blen, const void *old, unsigned new_,
|
||||
PackArmPe_Reloc &, unsigned);
|
||||
|
||||
struct pe_header_t
|
||||
{
|
||||
// 0x0
|
||||
char _[4]; // pemagic
|
||||
LE16 cpu;
|
||||
LE16 objects;
|
||||
char __[12]; // timestamp + reserved
|
||||
LE16 opthdrsize;
|
||||
LE16 flags;
|
||||
// optional header
|
||||
char ___[4]; // coffmagic + linkerversion
|
||||
LE32 codesize;
|
||||
// 0x20
|
||||
LE32 datasize;
|
||||
LE32 bsssize;
|
||||
LE32 entry;
|
||||
LE32 codebase;
|
||||
// 0x30
|
||||
LE32 database;
|
||||
// nt specific fields
|
||||
LE32 imagebase;
|
||||
LE32 objectalign;
|
||||
LE32 filealign; // should set to 0x200 ?
|
||||
// 0x40
|
||||
char ____[16]; // versions
|
||||
// 0x50
|
||||
LE32 imagesize;
|
||||
LE32 headersize;
|
||||
LE32 chksum; // should set to 0
|
||||
LE16 subsystem;
|
||||
LE16 dllflags;
|
||||
// 0x60
|
||||
char _____[20]; // stack + heap sizes
|
||||
// 0x74
|
||||
LE32 ddirsentries; // usually 16
|
||||
|
||||
struct ddirs_t
|
||||
{
|
||||
LE32 vaddr;
|
||||
LE32 size;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct ddirs_t ddirs[16];
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct pe_section_t
|
||||
{
|
||||
char name[8];
|
||||
LE32 vsize;
|
||||
LE32 vaddr;
|
||||
LE32 size;
|
||||
LE32 rawdataptr;
|
||||
char _[12];
|
||||
LE32 flags;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
pe_header_t ih, oh;
|
||||
pe_section_t *isection;
|
||||
|
||||
static unsigned virta2objnum (unsigned, pe_section_t *, unsigned);
|
||||
unsigned tryremove (unsigned, unsigned);
|
||||
|
||||
enum {
|
||||
PEDIR_EXPORT = 0,
|
||||
PEDIR_IMPORT = 1,
|
||||
PEDIR_RESOURCE = 2,
|
||||
PEDIR_EXCEPTION = 3, // Exception table
|
||||
PEDIR_SEC = 4, // Certificate table (file pointer)
|
||||
PEDIR_RELOC = 5,
|
||||
PEDIR_DEBUG = 6,
|
||||
PEDIR_COPYRIGHT = 7, // Architecture-specific data
|
||||
PEDIR_GLOBALPTR = 8, // Global pointer
|
||||
PEDIR_TLS = 9,
|
||||
PEDIR_LOADCONF = 10, // Load Config Table
|
||||
PEDIR_BOUNDIM = 11,
|
||||
PEDIR_IAT = 12,
|
||||
PEDIR_DELAYIMP = 13, // Delay Import Descriptor
|
||||
PEDIR_COMRT = 14 // Com+ Runtime Header
|
||||
};
|
||||
|
||||
enum {
|
||||
PEFL_CODE = 0x20,
|
||||
PEFL_DATA = 0x40,
|
||||
PEFL_BSS = 0x80,
|
||||
PEFL_INFO = 0x200,
|
||||
PEFL_EXTRELS = 0x01000000, // extended relocations
|
||||
PEFL_DISCARD = 0x02000000,
|
||||
PEFL_NOCACHE = 0x04000000,
|
||||
PEFL_NOPAGE = 0x08000000,
|
||||
PEFL_SHARED = 0x10000000,
|
||||
PEFL_EXEC = 0x20000000,
|
||||
PEFL_READ = 0x40000000,
|
||||
PEFL_WRITE = 0x80000000
|
||||
};
|
||||
|
||||
enum {
|
||||
RELOCS_STRIPPED = 0x0001,
|
||||
EXECUTABLE = 0x0002,
|
||||
LNUM_STRIPPED = 0x0004,
|
||||
LSYMS_STRIPPED = 0x0008,
|
||||
AGGRESSIVE_TRIM = 0x0010,
|
||||
TWO_GIGS_AWARE = 0x0020,
|
||||
FLITTLE_ENDIAN = 0x0080,
|
||||
BITS_32_MACHINE = 0x0100,
|
||||
DEBUG_STRIPPED = 0x0200,
|
||||
REMOVABLE_SWAP = 0x0400,
|
||||
SYSTEM_PROGRAM = 0x1000,
|
||||
DLL_FLAG = 0x2000,
|
||||
FBIG_ENDIAN = 0x8000
|
||||
};
|
||||
|
||||
// predefined resource types
|
||||
enum {
|
||||
RT_CURSOR = 1, RT_BITMAP, RT_ICON, RT_MENU, RT_DIALOG, RT_STRING,
|
||||
RT_FONTDIR, RT_FONT, RT_ACCELERATOR, RT_RCDATA, RT_MESSAGETABLE,
|
||||
RT_GROUP_CURSOR, RT_GROUP_ICON = 14, RT_VERSION = 16, RT_DLGINCLUDE,
|
||||
RT_PLUGPLAY = 19, RT_VXD, RT_ANICURSOR, RT_ANIICON, RT_HTML,
|
||||
RT_MANIFEST, RT_LAST
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
+6
-6
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -142,15 +142,15 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
int PackCom::buildLoader(const Filter *ft)
|
||||
{
|
||||
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
|
||||
addLoader("COMMAIN1""COMSUBSI",
|
||||
addLoader("COMMAIN1,COMSUBSI",
|
||||
ph.first_offset_found == 1 ? "COMSBBBP" : "",
|
||||
"COMPSHDI",
|
||||
ft->id ? "COMCALLT" : "",
|
||||
"COMMAIN2""UPX1HEAD""COMCUTPO""NRV2B160",
|
||||
"COMMAIN2,UPX1HEAD,COMCUTPO,NRV2B160",
|
||||
ft->id ? "NRVDDONE" : "NRVDRETU",
|
||||
"NRVDECO1",
|
||||
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
|
||||
"NRVDECO2""NRV2B169",
|
||||
"NRVDECO2,NRV2B169",
|
||||
NULL
|
||||
);
|
||||
if (ft->id)
|
||||
@@ -170,7 +170,7 @@ void PackCom::addFilter16(int filter_id)
|
||||
if (filter_id % 3 == 0)
|
||||
addLoader("CALLTR16",
|
||||
filter_id < 4 ? "CT16SUB0" : "",
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286""CT16SUB0"),
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286,CT16SUB0"),
|
||||
"CALLTRI2",
|
||||
getFormat() == UPX_F_DOS_COM ? "CORETURN" : "",
|
||||
NULL
|
||||
@@ -180,7 +180,7 @@ void PackCom::addFilter16(int filter_id)
|
||||
"CALLTRI5",
|
||||
getFormat() == UPX_F_DOS_COM ? "CT16JEND" : "CT16JUL2",
|
||||
filter_id < 4 ? "CT16SUB1" : "",
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287""CT16SUB1"),
|
||||
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287,CT16SUB1"),
|
||||
"CALLTRI6",
|
||||
NULL
|
||||
);
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ PackDjgpp2::PackDjgpp2(InputFile *f) :
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_ADLER32 == 0xbf689ba8);
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_CRC32 == 0x2ae982b2);
|
||||
//printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub)));
|
||||
assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
|
||||
//assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
addLoader("IDENTSTR""DJ2MAIN1",
|
||||
addLoader("IDENTSTR,DJ2MAIN1",
|
||||
ft->id ? "DJCALLT1" : "",
|
||||
"DJ2MAIN2",
|
||||
getDecompressor(),
|
||||
@@ -99,7 +99,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
addLoader("DJCALLT2", NULL);
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("DJRETURN+40DXXXXUPX1HEAD", NULL);
|
||||
addLoader("DJRETURN,+40DXXXX,UPX1HEAD", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ static void handle_allegropak(InputFile *fi, OutputFile *fo)
|
||||
if (memcmp(buf, "slh+", 4) != 0)
|
||||
return;
|
||||
pfsize = get_be32_signed(buf+4);
|
||||
if (pfsize <= 8 || pfsize >= fi->st.st_size)
|
||||
if (pfsize <= 8 || (off_t) pfsize >= (off_t) fi->st.st_size)
|
||||
return;
|
||||
fi->seek(-pfsize, SEEK_END);
|
||||
} catch (const IOException&) {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+287
-76
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -34,99 +34,153 @@
|
||||
// Some ELF type definitinons
|
||||
**************************************************************************/
|
||||
|
||||
namespace TT_Elf {
|
||||
|
||||
// The ELF file header. This appears at the start of every ELF file.
|
||||
struct Elf_LE32_Ehdr
|
||||
template <class Word, class Addr, class Off, class Half>
|
||||
struct Ehdr
|
||||
{
|
||||
unsigned char e_ident[16]; /* Magic number and other info */
|
||||
LE16 e_type; /* Object file type */
|
||||
LE16 e_machine; /* Architecture */
|
||||
LE32 e_version; /* Object file version */
|
||||
LE32 e_entry; /* Entry point virtual address */
|
||||
LE32 e_phoff; /* Program header table file offset */
|
||||
LE32 e_shoff; /* Section header table file offset */
|
||||
LE32 e_flags; /* Processor-specific flags */
|
||||
LE16 e_ehsize; /* ELF header size in bytes */
|
||||
LE16 e_phentsize; /* Program header table entry size */
|
||||
LE16 e_phnum; /* Program header table entry count */
|
||||
LE16 e_shentsize; /* Section header table entry size */
|
||||
LE16 e_shnum; /* Section header table entry count */
|
||||
LE16 e_shstrndx; /* Section header string table index */
|
||||
Half e_type; /* Object file type */
|
||||
Half e_machine; /* Architecture */
|
||||
Word e_version; /* Object file version */
|
||||
Addr e_entry; /* Entry point virtual address */
|
||||
Off e_phoff; /* Program header table file offset */
|
||||
Off e_shoff; /* Section header table file offset */
|
||||
Word e_flags; /* Processor-specific flags */
|
||||
Half e_ehsize; /* ELF header size in bytes */
|
||||
Half e_phentsize; /* Program header table entry size */
|
||||
Half e_phnum; /* Program header table entry count */
|
||||
Half e_shentsize; /* Section header table entry size */
|
||||
Half e_shnum; /* Section header table entry count */
|
||||
Half e_shstrndx; /* Section header string table index */
|
||||
|
||||
// Values for e_type
|
||||
enum {
|
||||
ET_NONE = 0, /* No file type */
|
||||
ET_REL = 1, /* Relocatable file */
|
||||
ET_EXEC = 2, /* Executable file */
|
||||
ET_DYN = 3, /* Shared object file */
|
||||
ET_CORE = 4 /* Core file */
|
||||
enum { // e_ident[]
|
||||
EI_CLASS = 4,
|
||||
EI_DATA = 5, /* Data encoding */
|
||||
EI_VERSION = 6,
|
||||
EI_OSABI = 7,
|
||||
EI_ABIVERSION = 8,
|
||||
};
|
||||
enum { // e_ident[EI_CLASS]
|
||||
ELFCLASS32 = 1, /* 32-bit objects */
|
||||
ELFCLASS64 = 2, /* 64-bit objects */
|
||||
};
|
||||
enum { // e_ident[EI_DATA]
|
||||
ELFDATA2LSB = 1, /* 2's complement, little endian */
|
||||
ELFDATA2MSB = 2 /* 2's complement, big endian */
|
||||
};
|
||||
enum { // e_ident[EI_OSABI]
|
||||
ELFOSABI_LINUX = 3
|
||||
};
|
||||
enum { // e_type
|
||||
ET_NONE = 0, /* No file type */
|
||||
ET_REL = 1, /* Relocatable file */
|
||||
ET_EXEC = 2, /* Executable file */
|
||||
ET_DYN = 3, /* Shared object file */
|
||||
ET_CORE = 4, /* Core file */
|
||||
};
|
||||
enum { // e_machine
|
||||
EM_386 = 3,
|
||||
EM_PPC = 20,
|
||||
EM_PPC64 = 21,
|
||||
EM_ARM = 40,
|
||||
EM_X86_64 = 62,
|
||||
};
|
||||
enum { // e_version
|
||||
EV_CURRENT = 1,
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
template <class Word, class Addr>
|
||||
struct Dyn
|
||||
{
|
||||
Word d_tag;
|
||||
Addr d_val;
|
||||
|
||||
enum { // d_tag
|
||||
DT_NULL = 0, /* End flag */
|
||||
DT_NEEDED = 1, /* Name of needed library */
|
||||
DT_HASH = 4, /* Hash table of symbol names */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_SYMTAB = 6, /* Symbol table */
|
||||
DT_STRSZ = 10, /* Sizeof string table */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
} // namespace TT_Elf
|
||||
|
||||
|
||||
namespace TT_Elf32 {
|
||||
|
||||
// Program segment header.
|
||||
struct Elf_LE32_Phdr
|
||||
template <class Word, class Addr, class Off>
|
||||
struct Phdr
|
||||
{
|
||||
LE32 p_type; /* Segment type */
|
||||
LE32 p_offset; /* Segment file offset */
|
||||
LE32 p_vaddr; /* Segment virtual address */
|
||||
LE32 p_paddr; /* Segment physical address */
|
||||
LE32 p_filesz; /* Segment size in file */
|
||||
LE32 p_memsz; /* Segment size in memory */
|
||||
LE32 p_flags; /* Segment flags */
|
||||
LE32 p_align; /* Segment alignment */
|
||||
Word p_type; /* Segment type */
|
||||
Off p_offset; /* Segment file offset */
|
||||
Addr p_vaddr; /* Segment virtual address */
|
||||
Addr p_paddr; /* Segment physical address */
|
||||
Word p_filesz; /* Segment size in file */
|
||||
Word p_memsz; /* Segment size in memory */
|
||||
Word p_flags; /* Segment flags */
|
||||
Word p_align; /* Segment alignment */
|
||||
|
||||
// Values for p_type
|
||||
enum {
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_PHDR = 6 /* Entry for header table itself */
|
||||
enum { // p_type
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_INTERP = 3, /* Name of program interpreter */
|
||||
PT_PHDR = 6, /* Entry for header table itself */
|
||||
};
|
||||
|
||||
// Values for p_flags
|
||||
enum { PF_X = (1 << 0) }; /* Segment is executable */
|
||||
enum { PF_W = (1 << 1) }; /* Segment is writable */
|
||||
enum { PF_R = (1 << 2) }; /* Segment is readable */
|
||||
enum { // p_flags
|
||||
PF_X = 1, /* Segment is executable */
|
||||
PF_W = 2, /* Segment is writable */
|
||||
PF_R = 4, /* Segment is readable */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
struct Elf_LE32_Shdr
|
||||
template <class Word, class Addr, class Off>
|
||||
struct Shdr
|
||||
{
|
||||
LE32 sh_name; /* Section name (string tbl index) */
|
||||
LE32 sh_type; /* Section type */
|
||||
LE32 sh_flags; /* Section flags */
|
||||
LE32 sh_addr; /* Section virtual addr at execution */
|
||||
LE32 sh_offset; /* Section file offset */
|
||||
LE32 sh_size; /* Section size in bytes */
|
||||
LE32 sh_link; /* Link to another section */
|
||||
LE32 sh_info; /* Additional section information */
|
||||
LE32 sh_addralign; /* Section alignment */
|
||||
LE32 sh_entsize; /* Entry size if section holds table */
|
||||
Word sh_name; /* Section name (string tbl index) */
|
||||
Word sh_type; /* Section type */
|
||||
Word sh_flags; /* Section flags */
|
||||
Addr sh_addr; /* Section virtual addr at execution */
|
||||
Off sh_offset; /* Section file offset */
|
||||
Word sh_size; /* Section size in bytes */
|
||||
Word sh_link; /* Link to another section */
|
||||
Word sh_info; /* Additional section information */
|
||||
Word sh_addralign; /* Section alignment */
|
||||
Word sh_entsize; /* Entry size if section holds table */
|
||||
|
||||
enum { // values for sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1,/* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
enum { // sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1, /* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
/* 12, 13 hole */
|
||||
SHT_INIT_ARRAY = 14, /* Array of constructors */
|
||||
SHT_FINI_ARRAY = 15, /* Array of destructors */
|
||||
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
|
||||
SHT_NUM = 19 /* Number of defined types. */
|
||||
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
|
||||
};
|
||||
|
||||
enum { // values for sh_flags
|
||||
enum { // sh_flags
|
||||
SHF_WRITE = (1 << 0), /* Writable */
|
||||
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
|
||||
SHF_EXECINSTR = (1 << 2), /* Executable */
|
||||
@@ -138,20 +192,177 @@ struct Elf_LE32_Shdr
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Elf_LE32_Dyn
|
||||
template <class TT16, class TT32, class TT64>
|
||||
struct Sym
|
||||
{
|
||||
LE32 d_tag;
|
||||
LE32 d_val;
|
||||
TT32 st_name; /* symbol name (index into string table) */
|
||||
TT32 st_value; /* symbol value */
|
||||
TT32 st_size; /* symbol size */
|
||||
unsigned char st_info; /* symbol type and binding */
|
||||
unsigned char st_other; /* symbol visibility */
|
||||
TT16 st_shndx; /* section index */
|
||||
|
||||
enum { // tags
|
||||
DT_NULL = 0, /* End flag */
|
||||
DT_NEEDED = 1, /* Name of needed library */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_STRSZ = 10 /* Sizeof string table */
|
||||
unsigned int st_bind(unsigned int x) const { return 0xf & (x>>4); }
|
||||
unsigned int st_type(unsigned int x) const { return 0xf & x ; }
|
||||
unsigned char St_info(unsigned bind, unsigned type) const { return (bind<<4) + (0xf & type); }
|
||||
|
||||
enum { // st_bind (high 4 bits of st_info)
|
||||
STB_LOCAL = 0, /* Local symbol */
|
||||
STB_GLOBAL = 1, /* Global symbol */
|
||||
STB_WEAK = 2, /* Weak symbol */
|
||||
};
|
||||
|
||||
enum { // st_type (low 4 bits of st_info)
|
||||
STT_NOTYPE = 0, /* Symbol type is unspecified */
|
||||
STT_OBJECT = 1, /* Symbol is a data object */
|
||||
STT_FUNC = 2, /* Symbol is a code object */
|
||||
STT_SECTION = 3, /* Symbol associated with a section */
|
||||
STT_FILE = 4, /* Symbol's name is file name */
|
||||
STT_COMMON = 5, /* Symbol is a common data object */
|
||||
STT_TLS = 6, /* Symbol is thread-local data object*/
|
||||
};
|
||||
|
||||
enum { // st_other (visibility)
|
||||
STV_DEFAULT = 0, /* Default symbol visibility rules */
|
||||
STV_INTERNAL = 1, /* Processor specific hidden class */
|
||||
STV_HIDDEN = 2, /* Sym unavailable in other modules */
|
||||
STV_PROTECTED= 3, /* Not preemptible, not exported */
|
||||
};
|
||||
|
||||
enum { // st_shndx
|
||||
SHN_UNDEF = 0, /* Undefined section */
|
||||
SHN_ABS = 0xfff1, /* Associated symbol is absolute */
|
||||
SHN_COMMON = 0xfff2, /* Associated symbol is common */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
} // namespace TT_Elf32
|
||||
|
||||
namespace TT_Elf64 {
|
||||
|
||||
// Program segment header.
|
||||
template <class Word, class Xword, class Addr, class Off>
|
||||
struct Phdr
|
||||
{
|
||||
Word p_type; /* Segment type */
|
||||
Word p_flags; /* Segment flags */
|
||||
Off p_offset; /* Segment file offset */
|
||||
Addr p_vaddr; /* Segment virtual address */
|
||||
Addr p_paddr; /* Segment physical address */
|
||||
Xword p_filesz; /* Segment size in file */
|
||||
Xword p_memsz; /* Segment size in memory */
|
||||
Xword p_align; /* Segment alignment */
|
||||
|
||||
enum { // p_type
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_INTERP = 3, /* Name of program interpreter */
|
||||
PT_PHDR = 6, /* Entry for header table itself */
|
||||
};
|
||||
|
||||
enum { // p_flags
|
||||
PF_X = 1, /* Segment is executable */
|
||||
PF_W = 2, /* Segment is writable */
|
||||
PF_R = 4, /* Segment is readable */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
template <class Word, class Xword, class Addr, class Off>
|
||||
struct Shdr
|
||||
{
|
||||
Word sh_name; /* Section name (string tbl index) */
|
||||
Word sh_type; /* Section type */
|
||||
Xword sh_flags; /* Section flags */
|
||||
Addr sh_addr; /* Section virtual addr at execution */
|
||||
Off sh_offset; /* Section file offset */
|
||||
Xword sh_size; /* Section size in bytes */
|
||||
Word sh_link; /* Link to another section */
|
||||
Word sh_info; /* Additional section information */
|
||||
Xword sh_addralign; /* Section alignment */
|
||||
Xword sh_entsize; /* Entry size if section holds table */
|
||||
|
||||
enum { // sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1, /* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
/* 12, 13 hole */
|
||||
SHT_INIT_ARRAY = 14, /* Array of constructors */
|
||||
SHT_FINI_ARRAY = 15, /* Array of destructors */
|
||||
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
|
||||
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
} // namespace TT_Elf64
|
||||
|
||||
/*************************************************************************
|
||||
// now for the actual types
|
||||
**************************************************************************/
|
||||
|
||||
typedef TT_Elf ::Ehdr<LE32,LE32,LE32,LE16> Elf_LE32_Ehdr;
|
||||
typedef TT_Elf32::Phdr<LE32,LE32,LE32> Elf_LE32_Phdr;
|
||||
typedef TT_Elf32::Shdr<LE32,LE32,LE32> Elf_LE32_Shdr;
|
||||
typedef TT_Elf ::Dyn <LE32,LE32> Elf_LE32_Dyn;
|
||||
typedef TT_Elf32::Sym <LE16,LE32,void> Elf_LE32_Sym;
|
||||
|
||||
typedef TT_Elf ::Ehdr<unsigned int,unsigned int,unsigned int,unsigned short> Elf32_Ehdr;
|
||||
typedef TT_Elf32::Phdr<unsigned int,unsigned int,unsigned int> Elf32_Phdr;
|
||||
typedef TT_Elf32::Shdr<unsigned int,unsigned int,unsigned int> Elf32_Shdr;
|
||||
typedef TT_Elf ::Dyn <unsigned int,unsigned int> Elf32_Dyn;
|
||||
typedef TT_Elf32::Sym <unsigned short,unsigned int,void> Elf32_Sym;
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Ehdr) == 52)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Phdr) == 32)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Shdr) == 40)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Dyn) == 8)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Sym) == 16)
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Ehdr) == 52)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Phdr) == 32)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Shdr) == 40)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Dyn) == 8)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Sym) == 16)
|
||||
|
||||
|
||||
typedef TT_Elf ::Ehdr<LE32,LE64,LE64,LE16> Elf_LE64_Ehdr;
|
||||
typedef TT_Elf64::Phdr<LE32,LE64,LE64,LE64> Elf_LE64_Phdr;
|
||||
typedef TT_Elf64::Shdr<LE32,LE64,LE64,LE64> Elf_LE64_Shdr;
|
||||
typedef TT_Elf ::Dyn <LE64,LE64> Elf_LE64_Dyn;
|
||||
|
||||
typedef TT_Elf ::Ehdr<unsigned int,unsigned long long,
|
||||
unsigned long long,unsigned short> Elf64_Ehdr;
|
||||
typedef TT_Elf64::Phdr<unsigned int,unsigned long long,
|
||||
unsigned long long,unsigned long long> Elf64_Phdr;
|
||||
typedef TT_Elf64::Shdr<unsigned int,unsigned long long,
|
||||
unsigned long long,unsigned long long> Elf64_Shdr;
|
||||
typedef TT_Elf ::Dyn <unsigned long long,unsigned long long> Elf64_Dyn;
|
||||
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Ehdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Phdr) == 56)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Shdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Dyn) == 16)
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Ehdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Phdr) == 56)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Shdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Dyn) == 16)
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+31
-10
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
||||
memset(&oh,0,sizeof(oh));
|
||||
oh.ident = 'M' + 'Z' * 256;
|
||||
oh.headsize16 = 2;
|
||||
oh.ip = 0;
|
||||
|
||||
oh.sp = ih.sp > 0x200 ? (unsigned) ih.sp : 0x200;
|
||||
|
||||
@@ -108,9 +107,13 @@ int PackExe::buildLoader(const Filter *)
|
||||
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
if (device_driver)
|
||||
addLoader("DEVICEENTRY", NULL);
|
||||
addLoader("EXEENTRY",
|
||||
device_driver ? "DEVICESUB" : "EXESUB",
|
||||
"JNCDOCOPY",
|
||||
relocsize ? "EXERELPU" : "",
|
||||
"EXEMAIN4""+G5DXXXX""UPX1HEAD""EXECUTPO",
|
||||
"EXEMAIN4,+G5DXXXX,UPX1HEAD,EXECUTPO",
|
||||
NULL
|
||||
);
|
||||
if (ph.method == M_NRV2B_8)
|
||||
@@ -122,7 +125,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
opt->cpu == opt->CPU_8086 ? "N2BX8602" : "N2B28602",
|
||||
"NRV2BEX3",
|
||||
ph.c_len > 0xffff ? "N2B64K02" : "",
|
||||
"NRV2BEX9""NRV2B16E",
|
||||
"NRV2BEX9,NRV2B16E",
|
||||
NULL
|
||||
);
|
||||
else if (ph.method == M_NRV2D_8)
|
||||
@@ -134,7 +137,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
opt->cpu == opt->CPU_8086 ? "N2DX8602" : "N2D28602",
|
||||
"NRV2DEX3",
|
||||
ph.c_len > 0xffff ? "N2D64K02" : "",
|
||||
"NRV2DEX9""NRV2D16E",
|
||||
"NRV2DEX9,NRV2D16E",
|
||||
NULL
|
||||
);
|
||||
else if (ph.method == M_NRV2E_8)
|
||||
@@ -146,7 +149,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
opt->cpu == opt->CPU_8086 ? "N2EX8602" : "N2E28602",
|
||||
"NRV2EEX3",
|
||||
ph.c_len > 0xffff ? "N2E64K02" : "",
|
||||
"NRV2EEX9""NRV2E16E",
|
||||
"NRV2EEX9,NRV2E16E",
|
||||
NULL
|
||||
);
|
||||
else
|
||||
@@ -162,6 +165,7 @@ int PackExe::buildLoader(const Filter *)
|
||||
NULL
|
||||
);
|
||||
addLoader("EXEMAIN8",
|
||||
device_driver ? "DEVICEEND" : "",
|
||||
(flag & SS) ? "EXESTACK" : "",
|
||||
(flag & SP) ? "EXESTASP" : "",
|
||||
(flag & USEJUMP) ? "EXEJUMPF" : "",
|
||||
@@ -293,7 +297,9 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
|
||||
{
|
||||
addr = get_le32(relocs+4*i);
|
||||
//printf ("%x\n",es*16+di);
|
||||
if (addr - es*16 > 0xfffe)
|
||||
if ((addr - es*16 > 0xfffe)
|
||||
|| (i == nrelocs - 1 && addr - es * 16 > 0xff00)
|
||||
)
|
||||
{
|
||||
// segment change
|
||||
t = 1+(0xffff-di)/254;
|
||||
@@ -365,6 +371,8 @@ void PackExe::pack(OutputFile *fo)
|
||||
|
||||
checkAlreadyPacked(ibuf, UPX_MIN(ih_imagesize, 127u));
|
||||
|
||||
device_driver = get_le32(ibuf) == 0xffffffffu;
|
||||
|
||||
// relocations
|
||||
has_9a = false;
|
||||
upx_byte *w = ibuf + ih_imagesize;
|
||||
@@ -409,7 +417,7 @@ void PackExe::pack(OutputFile *fo)
|
||||
throwCantPack("decompressor limit exceeded, send a bugreport");
|
||||
|
||||
#ifdef TESTING
|
||||
if (opt->debug)
|
||||
if (opt->debug.debug_level)
|
||||
{
|
||||
printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len);
|
||||
printf("offsets: %d - %d\nmatches: %d - %d\nruns: %d - %d\n",
|
||||
@@ -521,11 +529,24 @@ void PackExe::pack(OutputFile *fo)
|
||||
oh.m512 = outputlen & 511;
|
||||
oh.p512 = (outputlen + 511) >> 9;
|
||||
|
||||
oh.ip = 0;
|
||||
if (device_driver)
|
||||
{
|
||||
patch_le16(loader, e_len, "OP", oh.sp);
|
||||
patch_le16(loader, e_len, "OS", oh.ss);
|
||||
// copy .sys header
|
||||
memcpy(loader + 4, ibuf + 4, 2);
|
||||
memcpy(loader + 8, ibuf + 8, 2);
|
||||
// copy original strategy
|
||||
memcpy(loader + 10, ibuf + 6, 2);
|
||||
oh.ip = getLoaderSection("EXEENTRY") - 2;
|
||||
}
|
||||
|
||||
//fprintf(stderr,"\ne_len=%x d_len=%x clen=%x oo=%x ulen=%x destp=%x copys=%x images=%x",e_len,d_len,packedsize,ph.overlap_overhead,ph.u_len,destpara,copysize,ih_imagesize);
|
||||
|
||||
// write header + write loader + compressed file
|
||||
#ifdef TESTING
|
||||
if (opt->debug)
|
||||
if (opt->debug.debug_level)
|
||||
printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len);
|
||||
#endif
|
||||
fo->write(&oh,sizeof(oh));
|
||||
@@ -565,7 +586,7 @@ int PackExe::canUnpack()
|
||||
return false;
|
||||
const off_t off = ih.headsize16 * 16;
|
||||
fi->seek(off, SEEK_SET);
|
||||
bool b = readPackHeader(128);
|
||||
bool b = readPackHeader(256);
|
||||
return b && (off + (off_t) ph.c_len <= file_size);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ protected:
|
||||
unsigned relocsize;
|
||||
|
||||
bool has_9a;
|
||||
bool device_driver;
|
||||
|
||||
enum {
|
||||
NORELOC = 1,
|
||||
|
||||
+1707
-291
File diff suppressed because it is too large
Load Diff
+295
-21
@@ -22,8 +22,11 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -31,21 +34,278 @@
|
||||
#define __UPX_P_LX_ELF_H
|
||||
|
||||
|
||||
class PackLinuxElf : public PackUnix
|
||||
{
|
||||
typedef PackUnix super;
|
||||
public:
|
||||
PackLinuxElf(InputFile *f);
|
||||
virtual ~PackLinuxElf();
|
||||
/*virtual int buildLoader(const Filter *);*/
|
||||
virtual bool canUnpackVersion(int version) const { return (version >= 11); }
|
||||
|
||||
protected:
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
|
||||
// All other virtual functions in this class must be pure virtual
|
||||
// because they depend on Elf32 or Elf64 data structures, which differ.
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &) = 0; // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &) = 0; // append compressed data
|
||||
//virtual void pack3(OutputFile *, Filter &) = 0; // append loader
|
||||
virtual void pack4(OutputFile *, Filter &) = 0; // append pack header
|
||||
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
) = 0;
|
||||
virtual void unpack(OutputFile *fo) = 0;
|
||||
|
||||
protected:
|
||||
unsigned sz_phdrs; // sizeof Phdr[]
|
||||
unsigned sz_elf_hdrs; // all Elf headers
|
||||
};
|
||||
|
||||
class PackLinuxElf32 : public PackLinuxElf
|
||||
{
|
||||
typedef PackLinuxElf super;
|
||||
public:
|
||||
PackLinuxElf32(InputFile *f);
|
||||
virtual ~PackLinuxElf32();
|
||||
protected:
|
||||
virtual int checkEhdr(
|
||||
Elf32_Ehdr const *ehdr,
|
||||
unsigned char e_machine,
|
||||
unsigned char ei_class,
|
||||
unsigned char ei_data) const;
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
//virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
virtual off_t getbrk(const Elf32_Phdr *phdr, int e_phnum) const;
|
||||
virtual void patchLoader();
|
||||
virtual void updateLoader(OutputFile *fo);
|
||||
virtual unsigned find_LOAD_gap(Elf32_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const;
|
||||
|
||||
protected:
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // for input file
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr2 {
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 {
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
};
|
||||
|
||||
|
||||
class PackLinuxElf64 : public PackLinuxElf
|
||||
{
|
||||
typedef PackLinuxElf super;
|
||||
public:
|
||||
PackLinuxElf64(InputFile *f);
|
||||
virtual ~PackLinuxElf64();
|
||||
/*virtual int buildLoader(const Filter *);*/
|
||||
|
||||
protected:
|
||||
virtual int checkEhdr(
|
||||
Elf64_Ehdr const *ehdr,
|
||||
unsigned char e_machine,
|
||||
unsigned char ei_class,
|
||||
unsigned char ei_data) const;
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
//virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
virtual off_t getbrk(const Elf64_Phdr *phdr, int e_phnum) const;
|
||||
virtual void patchLoader();
|
||||
virtual void updateLoader(OutputFile *fo);
|
||||
virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
|
||||
protected:
|
||||
Elf64_Ehdr ehdri; // from input file
|
||||
Elf64_Phdr *phdri; // for input file
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr2 {
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 {
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
};
|
||||
|
||||
class PackLinuxElf32Be : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
};
|
||||
|
||||
class PackLinuxElf32Le : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Le(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
};
|
||||
|
||||
class PackLinuxElf64Le : public PackLinuxElf64
|
||||
{
|
||||
typedef PackLinuxElf64 super;
|
||||
protected:
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf64amd
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxElf64amd : public PackLinuxElf64Le
|
||||
{
|
||||
typedef PackLinuxElf64Le super;
|
||||
public:
|
||||
PackLinuxElf64amd(InputFile *f);
|
||||
virtual ~PackLinuxElf64amd();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF64_AMD; }
|
||||
virtual const char *getName() const { return "linux/ElfAMD"; }
|
||||
virtual const int *getFilters() const;
|
||||
virtual bool canPack();
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual int buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
unsigned const szfold,
|
||||
Filter const *ft
|
||||
);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf32ppc
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxElf32ppc : public PackLinuxElf32Be
|
||||
{
|
||||
typedef PackLinuxElf32Be super;
|
||||
public:
|
||||
PackLinuxElf32ppc(InputFile *f);
|
||||
virtual ~PackLinuxElf32ppc();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELFPPC32; }
|
||||
virtual const char *getName() const { return "linux/ElfPPC"; }
|
||||
virtual const int *getFilters() const;
|
||||
virtual bool canPack();
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual int buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
unsigned const szfold,
|
||||
Filter const *ft
|
||||
);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf386
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxI386elf : public PackLinuxI386
|
||||
class PackLinuxElf32x86 : public PackLinuxElf32Le
|
||||
{
|
||||
typedef PackLinuxI386 super;
|
||||
typedef PackLinuxElf32Le super;
|
||||
public:
|
||||
PackLinuxI386elf(InputFile *f);
|
||||
virtual ~PackLinuxI386elf();
|
||||
PackLinuxElf32x86(InputFile *f);
|
||||
virtual ~PackLinuxElf32x86();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF_i386; }
|
||||
virtual const char *getName() const { return "linux/elf386"; }
|
||||
virtual const int *getFilters() const;
|
||||
virtual int buildLoader(const Filter *);
|
||||
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
@@ -53,29 +313,43 @@ public:
|
||||
virtual bool canUnpackVersion(int version) const
|
||||
{ return (version >= 11); }
|
||||
|
||||
protected:
|
||||
struct Extent {
|
||||
off_t offset;
|
||||
off_t size;
|
||||
};
|
||||
virtual void packExtent(const Extent &x,
|
||||
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *);
|
||||
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
unsigned &total_in, unsigned &total_out,
|
||||
unsigned &c_adler, unsigned &u_adler,
|
||||
bool first_PF_X, unsigned szb_info );
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
|
||||
virtual void patchLoader();
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual int buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
unsigned const szfold,
|
||||
Filter const *ft
|
||||
);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
|
||||
Elf_LE32_Ehdr ehdri; // from input file
|
||||
Elf_LE32_Phdr *phdri; // for input file
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // for input file
|
||||
unsigned sz_phdrs; // sizeof Phdr[]
|
||||
|
||||
char *file_image; // if ET_DYN investigation
|
||||
Elf32_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
char const *dynstr; // from DT_STRTAB
|
||||
Elf32_Sym const *dynsym; // from DT_SYMTAB
|
||||
|
||||
static unsigned elf_hash(char const *) /*const*/;
|
||||
virtual void const *elf_find_dynamic(unsigned) const;
|
||||
virtual Elf32_Sym const *elf_lookup(char const *) const;
|
||||
virtual unsigned elf_get_offset_from_address(unsigned) const;
|
||||
virtual unsigned find_LOAD_gap(Elf32_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+103
-127
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2001-2004 John F. Reiser
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2001-2006 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,8 +22,11 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -37,12 +40,14 @@
|
||||
#include "p_unix.h"
|
||||
#include "p_lx_exc.h"
|
||||
|
||||
#define PT_LOAD Elf_LE32_Phdr::PT_LOAD
|
||||
#define PT_DYNAMIC Elf_LE32_Phdr::PT_DYNAMIC
|
||||
#define DT_NULL Elf_LE32_Dyn::DT_NULL
|
||||
#define DT_NEEDED Elf_LE32_Dyn::DT_NEEDED
|
||||
#define DT_STRTAB Elf_LE32_Dyn::DT_STRTAB
|
||||
#define DT_STRSZ Elf_LE32_Dyn::DT_STRSZ
|
||||
#define PT_LOAD Elf32_Phdr::PT_LOAD
|
||||
#define PT_DYNAMIC Elf32_Phdr::PT_DYNAMIC
|
||||
#if 0 // UNUSED
|
||||
#define DT_NULL Elf32_Dyn::DT_NULL
|
||||
#define DT_NEEDED Elf32_Dyn::DT_NEEDED
|
||||
#define DT_STRTAB Elf32_Dyn::DT_STRTAB
|
||||
#define DT_STRSZ Elf32_Dyn::DT_STRSZ
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -88,12 +93,13 @@ PackLinuxI386::generateElfHdr(
|
||||
{
|
||||
cprElfHdr1 *const h1 = (cprElfHdr1 *)&elfout;
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout;
|
||||
memcpy(h2, proto, sizeof(*h2));
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout;
|
||||
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
|
||||
|
||||
assert(h2->ehdr.e_phoff == sizeof(Elf_LE32_Ehdr));
|
||||
assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
|
||||
assert(h2->ehdr.e_shoff == 0);
|
||||
assert(h2->ehdr.e_ehsize == sizeof(Elf_LE32_Ehdr));
|
||||
assert(h2->ehdr.e_phentsize == sizeof(Elf_LE32_Phdr));
|
||||
assert(h2->ehdr.e_ehsize == sizeof(Elf32_Ehdr));
|
||||
assert(h2->ehdr.e_phentsize == sizeof(Elf32_Phdr));
|
||||
assert(h2->ehdr.e_shnum == 0);
|
||||
|
||||
#if 0 //{
|
||||
@@ -105,12 +111,22 @@ PackLinuxI386::generateElfHdr(
|
||||
|
||||
// Info for OS kernel to set the brk()
|
||||
if (brka) {
|
||||
#define PAGE_MASK (~0ul<<12)
|
||||
// linux-2.6.14 binfmt_elf.c: SIGKILL if (0==.p_memsz) on a page boundary
|
||||
unsigned const brkb = brka | ((0==(~PAGE_MASK & brka)) ? 0x20 : 0);
|
||||
h2->phdr[1].p_type = PT_LOAD; // be sure
|
||||
h2->phdr[1].p_offset = 0xfff&brka;
|
||||
h2->phdr[1].p_vaddr = brka;
|
||||
h2->phdr[1].p_paddr = brka;
|
||||
h2->phdr[1].p_offset = ~PAGE_MASK & brkb;
|
||||
h2->phdr[1].p_vaddr = brkb;
|
||||
h2->phdr[1].p_paddr = brkb;
|
||||
h2->phdr[1].p_filesz = 0;
|
||||
h2->phdr[1].p_memsz = 0;
|
||||
if (0==h2->phdr[1].p_flags) {
|
||||
h2->phdr[1].p_flags = Elf32_Phdr::PF_R|Elf32_Phdr::PF_W;
|
||||
}
|
||||
if (0==h2->phdr[1].p_align) {
|
||||
h2->phdr[1].p_align = 0x1000;
|
||||
}
|
||||
#undef PAGE_MASK
|
||||
}
|
||||
|
||||
if (ph.format==UPX_F_LINUX_i386 ) {
|
||||
@@ -118,16 +134,16 @@ PackLinuxI386::generateElfHdr(
|
||||
memset(&h1->linfo, 0, sizeof(h1->linfo));
|
||||
fo->write(h1, sizeof(*h1));
|
||||
}
|
||||
else if (ph.format==UPX_F_LINUX_ELF_i386) {
|
||||
assert(h2->ehdr.e_phnum==2);
|
||||
else if (ph.format==UPX_F_LINUX_SH_i386) {
|
||||
assert(h2->ehdr.e_phnum==1);
|
||||
h2->ehdr.e_phnum = 1;
|
||||
memset(&h2->linfo, 0, sizeof(h2->linfo));
|
||||
fo->write(h2, sizeof(*h2));
|
||||
}
|
||||
else if (ph.format==UPX_F_LINUX_SH_i386) {
|
||||
assert(h2->ehdr.e_phnum==1);
|
||||
h2->ehdr.e_phnum = 2;
|
||||
memset(&h2->linfo, 0, sizeof(h2->linfo));
|
||||
fo->write(h2, sizeof(*h2));
|
||||
else if (ph.format==UPX_F_LINUX_ELFI_i386) {
|
||||
assert(h3->ehdr.e_phnum==3);
|
||||
memset(&h3->linfo, 0, sizeof(h3->linfo));
|
||||
fo->write(h3, sizeof(*h3));
|
||||
}
|
||||
else {
|
||||
assert(false); // unknown ph.format, PackUnix::generateElfHdr
|
||||
@@ -150,10 +166,10 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
|
||||
sizeof(l_info) +
|
||||
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ;
|
||||
unsigned len = fo->getBytesWritten();
|
||||
set_native32(&elfout.phdr[0].p_filesz, len);
|
||||
super::pack4(fo, ft); // write PackHeader and overlay_offset
|
||||
|
||||
unsigned eod = fo->getBytesWritten();
|
||||
elfout.phdr[0].p_filesz = eod;
|
||||
|
||||
#if 0 // {
|
||||
// /usr/bin/strip from RedHat 8.0 (binutils-2.13.90.0.2-2)
|
||||
@@ -170,10 +186,11 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
|
||||
// Supply a "linking view" that covers everything,
|
||||
// so that 'strip' does not omit everything.
|
||||
Elf_LE32_Shdr shdr;
|
||||
Elf32_Shdr shdr;
|
||||
// The section header string table.
|
||||
char const shstrtab[] = "\0.\0.shstrtab";
|
||||
|
||||
unsigned eod = elfout.phdr[0].p_filesz;
|
||||
set_native32(&elfout.ehdr.e_shoff, eod);
|
||||
set_native16(&elfout.ehdr.e_shentsize, sizeof(shdr));
|
||||
set_native16(&elfout.ehdr.e_shnum, 3);
|
||||
@@ -181,14 +198,14 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
|
||||
// An empty Elf32_Shdr for space as a null index.
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_NULL);
|
||||
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_NULL);
|
||||
fo->write(&shdr, sizeof(shdr));
|
||||
|
||||
// Cover all the bits we need at runtime.
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
set_native32(&shdr.sh_name, 1);
|
||||
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_PROGBITS);
|
||||
set_native32(&shdr.sh_flags, Elf_LE32_Shdr::SHF_ALLOC);
|
||||
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_PROGBITS);
|
||||
set_native32(&shdr.sh_flags, Elf32_Shdr::SHF_ALLOC);
|
||||
set_native32(&shdr.sh_addr, elfout.phdr[0].p_vaddr);
|
||||
set_native32(&shdr.sh_offset, overlay_offset);
|
||||
set_native32(&shdr.sh_size, eod - overlay_offset);
|
||||
@@ -198,7 +215,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
// A section header for the section header string table.
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
set_native32(&shdr.sh_name, 3);
|
||||
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_STRTAB);
|
||||
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_STRTAB);
|
||||
set_native32(&shdr.sh_offset, 3*sizeof(shdr) + eod);
|
||||
set_native32(&shdr.sh_size, sizeof(shstrtab));
|
||||
fo->write(&shdr, sizeof(shdr));
|
||||
@@ -206,16 +223,23 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
fo->write(shstrtab, sizeof(shstrtab));
|
||||
#endif // }
|
||||
|
||||
|
||||
// Cannot pre-round .p_memsz. If .p_filesz < .p_memsz, then kernel
|
||||
// tries to make .bss, which requires PF_W.
|
||||
// But strict SELinux (or PaX, grSecurity) disallows PF_W with PF_X.
|
||||
#if 0 /*{*/
|
||||
#undef PAGE_MASK
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
// pre-calculate for benefit of runtime disappearing act via munmap()
|
||||
elfout.phdr[0].p_memsz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
|
||||
#undef PAGE_MASK
|
||||
#else /*}{*/
|
||||
elfout.phdr[0].p_memsz = elfout.phdr[0].p_filesz;
|
||||
#endif /*}*/
|
||||
|
||||
// rewrite Elf header
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->rewrite(&elfout, sizeof(elfout.ehdr) +
|
||||
elfout.ehdr.e_phnum * sizeof(elfout.phdr[0]) +
|
||||
sizeof(l_info) );
|
||||
fo->rewrite(&elfout, overlay_offset);
|
||||
}
|
||||
|
||||
static unsigned
|
||||
@@ -238,25 +262,31 @@ PackLinuxI386::buildLinuxLoader(
|
||||
{
|
||||
initLoader(proto, szproto);
|
||||
|
||||
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
|
||||
unsigned const fold_hdrlen = umax(0x80, sizeof(hf->ehdr) +
|
||||
hf->ehdr.e_phentsize * hf->ehdr.e_phnum + sizeof(l_info) );
|
||||
struct b_info h; memset(&h, 0, sizeof(h));
|
||||
h.sz_unc = szfold - fold_hdrlen;
|
||||
unsigned fold_hdrlen = 0;
|
||||
if (0 < szfold) {
|
||||
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
|
||||
fold_hdrlen = sizeof(hf->ehdr) + hf->ehdr.e_phentsize * hf->ehdr.e_phnum +
|
||||
sizeof(l_info);
|
||||
if (0 == get_le32(fold_hdrlen + fold)) {
|
||||
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
|
||||
fold_hdrlen = umax(0x80, fold_hdrlen);
|
||||
}
|
||||
h.sz_unc = (szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen);
|
||||
h.b_method = (unsigned char) ph.method;
|
||||
h.b_ftid = (unsigned char) ph.filter;
|
||||
h.b_cto8 = (unsigned char) ph.filter_cto;
|
||||
}
|
||||
unsigned char const *const uncLoader = fold_hdrlen + fold;
|
||||
|
||||
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
|
||||
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h.sz_cpr,
|
||||
NULL, ph.method, 10, NULL, NULL );
|
||||
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
|
||||
throwInternalError("loader compression failed");
|
||||
memcpy(cprLoader, &h, sizeof(h));
|
||||
|
||||
unsigned char *const cprLoader = new unsigned char[h.sz_unc];
|
||||
if (0 < szfold) {
|
||||
unsigned sz_cpr = h.sz_unc;
|
||||
memcpy(cprLoader, uncLoader, sz_cpr);
|
||||
h.sz_cpr = sz_cpr;
|
||||
}
|
||||
// This adds the definition to the "library", to be used later.
|
||||
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr);
|
||||
linker->addSection("FOLDEXEC", cprLoader, h.sz_cpr);
|
||||
delete [] cprLoader;
|
||||
|
||||
n_mru = ft->n_mru;
|
||||
@@ -276,71 +306,39 @@ PackLinuxI386::buildLinuxLoader(
|
||||
// compressed data
|
||||
b_len + ph.c_len );
|
||||
// entry to stub
|
||||
addLoader("LEXEC000", 0);
|
||||
addLoader("LEXEC000", NULL);
|
||||
|
||||
if (ft->id) {
|
||||
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
|
||||
addLoader("LXUNF000", 0);
|
||||
addLoader("LXUNF002", 0);
|
||||
if (0x80==(ft->id & 0xF0)) {
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE0", 0);
|
||||
}
|
||||
else if (n_mru) {
|
||||
addLoader("LXMRU005", 0);
|
||||
}
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU006", 0);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU007", 0);
|
||||
}
|
||||
}
|
||||
else if (0x40==(ft->id & 0xF0)) {
|
||||
addLoader("LXUNF008", 0);
|
||||
}
|
||||
addLoader("LXUNF010", 0);
|
||||
}
|
||||
if (n_mru) {
|
||||
addLoader("LEXEC009", 0);
|
||||
addLoader("LEXEC009", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LEXEC010", 0);
|
||||
addLoader(getDecompressor(), 0);
|
||||
addLoader("LEXEC015", 0);
|
||||
addLoader("LEXEC010", NULL);
|
||||
addLoader(getDecompressor(), NULL);
|
||||
addLoader("LEXEC015", NULL);
|
||||
if (ft->id) {
|
||||
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
|
||||
if (0x80!=(ft->id & 0xF0)) {
|
||||
addLoader("LXUNF042", 0);
|
||||
}
|
||||
}
|
||||
else { // decompr, unfilter not separate
|
||||
{ // decompr, unfilter not separate
|
||||
if (0x80==(ft->id & 0xF0)) {
|
||||
addLoader("LEXEC110", 0);
|
||||
addLoader("LEXEC110", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LEXEC100", 0);
|
||||
addLoader("LEXEC100", NULL);
|
||||
}
|
||||
// bug in APP: jmp and label must be in same .asx/.asy
|
||||
addLoader("LEXEC016", 0);
|
||||
addLoader("LEXEC016", NULL);
|
||||
}
|
||||
}
|
||||
addFilter32(ft->id);
|
||||
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
|
||||
if (0x80==(ft->id & 0xF0)) {
|
||||
if (0==n_mru) {
|
||||
addLoader("LXMRU058", 0);
|
||||
}
|
||||
}
|
||||
addLoader("LXUNF035", 0);
|
||||
}
|
||||
else { // decompr always unfilters
|
||||
addLoader("LEXEC017", 0);
|
||||
{ // decompr always unfilters
|
||||
addLoader("LEXEC017", NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
addLoader("LEXEC017", NULL);
|
||||
}
|
||||
|
||||
addLoader("IDENTSTR", 0);
|
||||
addLoader("LEXEC020", 0);
|
||||
addLoader("FOLDEXEC", 0);
|
||||
addLoader("IDENTSTR", NULL);
|
||||
addLoader("LEXEC020", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
|
||||
char *ptr_cto = (char *)const_cast<unsigned char *>(getLoader());
|
||||
int sz_cto = getLoaderSize();
|
||||
@@ -369,22 +367,12 @@ PackLinuxI386::buildLoader(Filter const *ft)
|
||||
patch_le32(buf,sz_fold,"UPX3",progid);
|
||||
patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff);
|
||||
|
||||
// get fresh filter
|
||||
Filter fold_ft = *ft;
|
||||
fold_ft.init(ft->id, ft->addvalue);
|
||||
int preferred_ctos[2] = {ft->cto, -1};
|
||||
fold_ft.preferred_ctos = preferred_ctos;
|
||||
|
||||
// filter
|
||||
optimizeFilter(&fold_ft, buf, sz_fold);
|
||||
bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2));
|
||||
(void)success;
|
||||
|
||||
return buildLinuxLoader(
|
||||
linux_i386exec_loader, sizeof(linux_i386exec_loader),
|
||||
buf, sz_fold, ft );
|
||||
}
|
||||
|
||||
// FIXME: getLoaderPrefixSize is unused?
|
||||
int PackLinuxI386::getLoaderPrefixSize() const
|
||||
{
|
||||
return 116;
|
||||
@@ -396,7 +384,7 @@ int PackLinuxI386::getLoaderPrefixSize() const
|
||||
**************************************************************************/
|
||||
|
||||
// basic check of an Linux ELF Ehdr
|
||||
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
int PackLinuxI386::checkEhdr(const Elf32_Ehdr *ehdr) const
|
||||
{
|
||||
const unsigned char * const buf = ehdr->e_ident;
|
||||
|
||||
@@ -404,17 +392,18 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
return -1;
|
||||
|
||||
// now check the ELF header
|
||||
if (!memcmp(buf+8, "FreeBSD", 7)) // branded
|
||||
if (!memcmp(buf+8, "FreeBSD", 7)) // branded
|
||||
return 1;
|
||||
if (ehdr->e_type != 2) // executable
|
||||
if (ehdr->e_type != Elf32_Ehdr::ET_EXEC
|
||||
&& ehdr->e_type != Elf32_Ehdr::ET_DYN ) // executable
|
||||
return 2;
|
||||
if (ehdr->e_machine != 3) // Intel 80386
|
||||
if (ehdr->e_machine != Elf32_Ehdr::EM_386) // Intel 80386
|
||||
return 3;
|
||||
if (ehdr->e_version != 1) // version
|
||||
if (ehdr->e_version != Elf32_Ehdr::EV_CURRENT) // version
|
||||
return 4;
|
||||
if (ehdr->e_phnum < 1)
|
||||
return 5;
|
||||
if (ehdr->e_phentsize != sizeof(Elf_LE32_Phdr))
|
||||
if (ehdr->e_phentsize != sizeof(Elf32_Phdr))
|
||||
return 6;
|
||||
|
||||
// check for Linux kernels
|
||||
@@ -435,19 +424,6 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
}
|
||||
|
||||
|
||||
off_t PackLinuxI386::getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) const
|
||||
{
|
||||
off_t brka = 0;
|
||||
for (int j = 0; j < e_phnum; ++phdr, ++j) {
|
||||
if (phdr->PT_LOAD == phdr->p_type) {
|
||||
off_t b = phdr->p_vaddr + phdr->p_memsz;
|
||||
if (b > brka)
|
||||
brka = b;
|
||||
}
|
||||
}
|
||||
return brka;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
@@ -458,7 +434,7 @@ bool PackLinuxI386::canPack()
|
||||
if (exetype != 0)
|
||||
return super::canPack();
|
||||
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf32_Ehdr ehdr;
|
||||
unsigned char *buf = ehdr.e_ident;
|
||||
|
||||
fi->readx(&ehdr, sizeof(ehdr));
|
||||
|
||||
+16
-14
@@ -21,8 +21,11 @@
|
||||
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
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -74,8 +77,7 @@ protected:
|
||||
virtual void updateLoader(OutputFile *);
|
||||
|
||||
// ELF util
|
||||
virtual int checkEhdr(const Elf_LE32_Ehdr *ehdr) const;
|
||||
virtual off_t getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) const;
|
||||
virtual int checkEhdr(const Elf32_Ehdr *ehdr) const;
|
||||
|
||||
enum {
|
||||
UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
|
||||
@@ -84,27 +86,27 @@ protected:
|
||||
unsigned n_mru;
|
||||
|
||||
struct cprElfHdr1 {
|
||||
struct Elf_LE32_Ehdr ehdr;
|
||||
struct Elf_LE32_Phdr phdr[1];
|
||||
struct l_info linfo;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr2 {
|
||||
struct Elf_LE32_Ehdr ehdr;
|
||||
struct Elf_LE32_Phdr phdr[2];
|
||||
struct l_info linfo;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 {
|
||||
struct Elf_LE32_Ehdr ehdr;
|
||||
struct Elf_LE32_Phdr phdr[3];
|
||||
struct l_info linfo;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct cprElfHdr3 elfout;
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
/* p_lx_interp.cpp --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#include "file.h"
|
||||
#include "filter.h"
|
||||
#include "linker.h"
|
||||
#include "packer.h"
|
||||
#include "p_elf.h"
|
||||
#include "p_unix.h"
|
||||
#include "p_lx_exc.h"
|
||||
#include "p_lx_elf.h"
|
||||
#include "p_lx_interp.h"
|
||||
|
||||
#define PT_LOAD Elf32_Phdr::PT_LOAD
|
||||
#define PT_INTERP Elf32_Phdr::PT_INTERP
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
static const
|
||||
#include "stub/l_lx_pti86.h"
|
||||
static const
|
||||
#include "stub/fold_pti86.h"
|
||||
|
||||
PackLinuxElf32x86interp::PackLinuxElf32x86interp(InputFile *f) :
|
||||
super(f)
|
||||
{
|
||||
}
|
||||
|
||||
PackLinuxElf32x86interp::~PackLinuxElf32x86interp()
|
||||
{
|
||||
}
|
||||
|
||||
bool PackLinuxElf32x86interp::canPack()
|
||||
{
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
return true;
|
||||
}
|
||||
if (!opt->o_unix.use_ptinterp) {
|
||||
return false;
|
||||
}
|
||||
return super::canPack();
|
||||
}
|
||||
|
||||
void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ehdri, sizeof(ehdri));
|
||||
assert(ehdri.e_phoff == sizeof(Elf32_Ehdr)); // checked by canPack()
|
||||
sz_phdrs = ehdri.e_phnum * ehdri.e_phentsize;
|
||||
|
||||
phdri = new Elf32_Phdr[(unsigned)ehdri.e_phnum];
|
||||
fi->seek(ehdri.e_phoff, SEEK_SET);
|
||||
fi->readx(phdri, sz_phdrs);
|
||||
|
||||
#define E Elf32_Ehdr
|
||||
cprElfHdr3 h3;
|
||||
memset(&h3, 0, sizeof(h3));
|
||||
memcpy(h3.ehdr.e_ident, "\177ELF", 4);
|
||||
h3.ehdr.e_ident[E::EI_CLASS] = E::ELFCLASS32;
|
||||
h3.ehdr.e_ident[E::EI_DATA] = E::ELFDATA2LSB;
|
||||
h3.ehdr.e_ident[E::EI_VERSION] = E::EV_CURRENT;
|
||||
h3.ehdr.e_ident[E::EI_OSABI] = E::ELFOSABI_LINUX;
|
||||
h3.ehdr.e_ident[E::EI_ABIVERSION] = E::EV_CURRENT;
|
||||
h3.ehdr.e_type = E::ET_EXEC;
|
||||
h3.ehdr.e_machine = E::EM_386;
|
||||
h3.ehdr.e_version = 1;
|
||||
h3.ehdr.e_phoff = sizeof(Elf32_Ehdr);
|
||||
h3.ehdr.e_ehsize = sizeof(Elf32_Ehdr);
|
||||
h3.ehdr.e_phentsize = sizeof(Elf32_Phdr);
|
||||
h3.ehdr.e_phnum = 3;
|
||||
h3.phdr[0].p_type = PT_LOAD;
|
||||
h3.phdr[0].p_flags = Elf32_Phdr::PF_X | Elf32_Phdr::PF_R;
|
||||
h3.phdr[0].p_align = 0x1000;
|
||||
h3.phdr[1].p_type = PT_LOAD;
|
||||
h3.phdr[1].p_flags = Elf32_Phdr::PF_W | Elf32_Phdr::PF_R;
|
||||
h3.phdr[1].p_align = 1;
|
||||
h3.phdr[2].p_type = PT_INTERP;
|
||||
h3.phdr[2].p_offset = (char *)&h3.phdr[2].p_vaddr - (char *)&h3;
|
||||
memcpy(&h3.phdr[2].p_vaddr, "/upxrun", h3.phdr[2].p_filesz = 8);
|
||||
h3.phdr[2].p_align = 1;
|
||||
|
||||
if (opt->o_unix.make_ptinterp) { // unusual "once per release"
|
||||
elfout = h3;
|
||||
elfout.ehdr.e_phnum = 1;
|
||||
fo->write(&elfout, elfout.ehdr.e_ehsize + elfout.ehdr.e_phentsize);
|
||||
}
|
||||
else { // usual case
|
||||
generateElfHdr(fo, &h3, getbrk(phdri, ehdri.e_phnum));
|
||||
}
|
||||
#undef E
|
||||
}
|
||||
|
||||
void PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
return; // ignore current input file!
|
||||
}
|
||||
super::pack2(fo, ft);
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
|
||||
void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
{
|
||||
unsigned base = getbase(phdri, ehdri.e_phnum);
|
||||
unsigned sz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
|
||||
if (base < (0x11000 + sz)) {
|
||||
base = 0x11000 + sz;
|
||||
}
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
base = 0x10000;
|
||||
}
|
||||
elfout.phdr[0].p_paddr = elfout.phdr[0].p_vaddr = base - sz;
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
initLoader(linux_i386pti_loader, sizeof(linux_i386pti_loader));
|
||||
linker->addSection("FOLDEXEC", linux_i386pti_fold, sizeof(linux_i386pti_fold));
|
||||
|
||||
addLoader("LXPTI000", NULL);
|
||||
|
||||
addLoader("LXPTI040", NULL);
|
||||
ph.method = M_NRV2B_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI041", NULL);
|
||||
ph.method = M_NRV2D_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI042", NULL);
|
||||
ph.method = M_NRV2E_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI043", NULL);
|
||||
ph.method = M_CL1B_LE32; addLoader(getDecompressor(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI091", NULL);
|
||||
|
||||
addLoader("LXPTI140", NULL);
|
||||
|
||||
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL);
|
||||
addFilter32(0x46);
|
||||
addLoader("LXUNF042,LXUNF035", NULL);
|
||||
|
||||
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL);
|
||||
addFilter32(0x49);
|
||||
addLoader("LXUNF042,LXUNF035", NULL);
|
||||
|
||||
addLoader("LXPTI200", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
upx_byte const *p = getLoader();
|
||||
lsize = getLoaderSize();
|
||||
updateLoader(fo);
|
||||
fo->write(p, lsize);
|
||||
elfout.phdr[0].p_filesz = fo->getBytesWritten();
|
||||
}
|
||||
else {
|
||||
updateLoader(fo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
{
|
||||
#define MAX_INTERP_HDR 512
|
||||
char bufehdr[MAX_INTERP_HDR];
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)bufehdr;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *)(1+ehdr);
|
||||
|
||||
unsigned szb_info = sizeof(b_info);
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(bufehdr, MAX_INTERP_HDR);
|
||||
unsigned const e_entry = get_native32(&ehdr->e_entry);
|
||||
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
}
|
||||
|
||||
fi->seek(overlay_offset, SEEK_SET);
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
|
||||
ibuf.alloc(blocksize + OVERHEAD);
|
||||
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
|
||||
fi->readx(&bhdr, szb_info);
|
||||
ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = get_native32(&bhdr.sz_cpr);
|
||||
ph.filter_cto = bhdr.b_cto8;
|
||||
|
||||
// Uncompress Ehdr and Phdrs.
|
||||
fi->readx(ibuf, ph.c_len);
|
||||
decompress(ibuf, (upx_byte *)ehdr, false);
|
||||
|
||||
unsigned total_in = 0;
|
||||
unsigned total_out = 0;
|
||||
unsigned c_adler = upx_adler32(NULL, 0);
|
||||
unsigned u_adler = upx_adler32(NULL, 0);
|
||||
off_t ptload0hi=0, ptload1lo=0, ptload1sz=0;
|
||||
|
||||
// decompress PT_LOAD
|
||||
bool first_PF_X = true;
|
||||
fi->seek(- (off_t) (szb_info + ph.c_len), SEEK_CUR);
|
||||
for (unsigned j=0; j < ehdr->e_phnum; ++phdr, ++j) {
|
||||
if (PT_LOAD==phdr->p_type) {
|
||||
if (0==ptload0hi) {
|
||||
ptload0hi = phdr->p_filesz + phdr->p_offset;
|
||||
}
|
||||
else if (0==ptload1lo) {
|
||||
ptload1lo = phdr->p_offset;
|
||||
ptload1sz = phdr->p_filesz;
|
||||
}
|
||||
if (fo)
|
||||
fo->seek(phdr->p_offset, SEEK_SET);
|
||||
if (Elf32_Phdr::PF_X & phdr->p_flags) {
|
||||
unpackExtent(phdr->p_filesz, fo, total_in, total_out,
|
||||
c_adler, u_adler, first_PF_X, szb_info);
|
||||
first_PF_X = false;
|
||||
}
|
||||
else {
|
||||
unpackExtent(phdr->p_filesz, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, szb_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0!=ptload1sz && ptload0hi < ptload1lo) { // alignment hole?
|
||||
if (fo)
|
||||
fo->seek(ptload0hi, SEEK_SET);
|
||||
unpackExtent(ptload1lo - ptload0hi, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, szb_info);
|
||||
}
|
||||
if (total_out != orig_file_size) { // non-PT_LOAD stuff
|
||||
if (fo)
|
||||
fo->seek(0, SEEK_END);
|
||||
unpackExtent(orig_file_size - total_out, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, szb_info);
|
||||
}
|
||||
|
||||
// check for end-of-file
|
||||
fi->readx(&bhdr, szb_info);
|
||||
unsigned const sz_unc = ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
|
||||
if (sz_unc == 0) { // uncompressed size 0 -> EOF
|
||||
// note: magic is always stored le32
|
||||
unsigned const sz_cpr = get_le32(&bhdr.sz_cpr);
|
||||
if (sz_cpr != UPX_MAGIC_LE32) // sz_cpr must be h->magic
|
||||
throwCompressedDataViolation();
|
||||
}
|
||||
else { // extra bytes after end?
|
||||
throwCompressedDataViolation();
|
||||
}
|
||||
|
||||
// update header with totals
|
||||
ph.c_len = total_in;
|
||||
ph.u_len = total_out;
|
||||
|
||||
// all bytes must be written
|
||||
if (total_out != orig_file_size)
|
||||
throwEOFException();
|
||||
|
||||
// finally test the checksums
|
||||
if (ph.c_adler != c_adler || ph.u_adler != u_adler)
|
||||
throwChecksumError();
|
||||
#undef MAX_INTERP_HDR
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* p_lx_interp.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2000-2004 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_INTERP_H //{
|
||||
#define __UPX_P_LX_INTERP_H
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/interp386
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxElf32x86interp : public PackLinuxElf32x86
|
||||
{
|
||||
typedef PackLinuxElf32x86 super;
|
||||
public:
|
||||
PackLinuxElf32x86interp(InputFile *f);
|
||||
virtual ~PackLinuxElf32x86interp();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELFI_i386; }
|
||||
virtual const char *getName() const { return "linux/elfi386"; }
|
||||
|
||||
virtual bool canPack();
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // build loader
|
||||
};
|
||||
|
||||
|
||||
#endif /*} already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+8
-5
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2000-2004 John F. Reiser
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,8 +22,11 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+7
-4
@@ -22,8 +22,11 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -35,9 +38,9 @@
|
||||
// linux/sep386
|
||||
**************************************************************************/
|
||||
|
||||
class PackLinuxI386sep : public PackLinuxI386elf
|
||||
class PackLinuxI386sep : public PackLinuxI386
|
||||
{
|
||||
typedef PackLinuxI386elf super;
|
||||
typedef PackLinuxI386 super;
|
||||
public:
|
||||
PackLinuxI386sep(InputFile *f) : super(f) { }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_SEP_i386; }
|
||||
|
||||
+24
-6
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2000-2004 John F. Reiser
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,8 +22,11 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -59,6 +62,15 @@ PackLinuxI386sh::~PackLinuxI386sh()
|
||||
{
|
||||
}
|
||||
|
||||
static unsigned
|
||||
umax(unsigned a, unsigned b)
|
||||
{
|
||||
if (a <= b) {
|
||||
return b;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
int
|
||||
PackLinuxI386sh::buildLoader(Filter const *ft)
|
||||
{
|
||||
@@ -78,7 +90,13 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
|
||||
|
||||
// filter
|
||||
optimizeFilter(&fold_ft, buf, sz_fold);
|
||||
bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2));
|
||||
unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) +
|
||||
sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
|
||||
if (0 == get_le32(fold_hdrlen + buf)) {
|
||||
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
|
||||
fold_hdrlen = umax(0x80, fold_hdrlen);
|
||||
}
|
||||
bool success = fold_ft.filter(buf + fold_hdrlen, sz_fold - fold_hdrlen);
|
||||
UNUSED(success);
|
||||
|
||||
return buildLinuxLoader(
|
||||
|
||||
+5
-2
@@ -22,8 +22,11 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+443
@@ -0,0 +1,443 @@
|
||||
/* p_mach.cpp -- pack Mach Object executable
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2004 John Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
John Reiser
|
||||
jreiser@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#include "file.h"
|
||||
#include "filter.h"
|
||||
#include "linker.h"
|
||||
#include "packer.h"
|
||||
#include "p_mach.h"
|
||||
|
||||
static const
|
||||
#include "stub/l_mac_ppc32.h"
|
||||
|
||||
static const
|
||||
#include "stub/fold_machppc32.h"
|
||||
|
||||
PackMachPPC32::PackMachPPC32(InputFile *f) :
|
||||
super(f), n_segment(0), rawmseg(0), msegcmd(0)
|
||||
{
|
||||
}
|
||||
|
||||
PackMachPPC32::~PackMachPPC32()
|
||||
{
|
||||
delete [] msegcmd;
|
||||
delete [] rawmseg;
|
||||
}
|
||||
|
||||
const int *PackMachPPC32::getCompressionMethods(int /*method*/, int /*level*/) const
|
||||
{
|
||||
// There really is no LE bias in M_NRV2E_LE32.
|
||||
static const int m_nrv2e[] = { M_NRV2E_LE32, -1 };
|
||||
return m_nrv2e;
|
||||
}
|
||||
|
||||
|
||||
const int *PackMachPPC32::getFilters() const
|
||||
{
|
||||
static const int filters[] = { 0xd0, -1 };
|
||||
return filters;
|
||||
}
|
||||
|
||||
int
|
||||
PackMachPPC32::buildMachLoader(
|
||||
upx_byte const *const proto,
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold,
|
||||
unsigned const szfold,
|
||||
Filter const */*ft*/
|
||||
)
|
||||
{
|
||||
int eof_empty = -1;
|
||||
initLoader(&eof_empty, 4096, 0, 0);
|
||||
|
||||
struct b_info h; memset(&h, 0, sizeof(h));
|
||||
unsigned fold_hdrlen = 0;
|
||||
if (0 < szfold) {
|
||||
h.sz_unc = (szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen);
|
||||
h.b_method = (unsigned char) ph.method;
|
||||
h.b_ftid = (unsigned char) ph.filter;
|
||||
h.b_cto8 = (unsigned char) ph.filter_cto;
|
||||
}
|
||||
unsigned char const *const uncLoader = fold_hdrlen + fold;
|
||||
|
||||
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
|
||||
if (0 < szfold) {
|
||||
unsigned sz_cpr;
|
||||
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
|
||||
NULL, ph.method, 10, NULL, NULL );
|
||||
h.sz_cpr = sz_cpr;
|
||||
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
|
||||
throwInternalError("loader compression failed");
|
||||
}
|
||||
memcpy(cprLoader, &h, sizeof(h));
|
||||
|
||||
// This adds the definition to the "library", to be used later.
|
||||
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr);
|
||||
delete [] cprLoader;
|
||||
|
||||
int const GAP = 128; // must match stub/l_mac_ppc.S
|
||||
segcmdo.vmsize += h.sz_unc - h.sz_cpr + GAP + 64;
|
||||
|
||||
linker->addSection("MACOS000", proto, szproto);
|
||||
|
||||
addLoader("MACOS000", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
int
|
||||
PackMachPPC32::buildLoader(const Filter *ft)
|
||||
{
|
||||
return buildMachLoader(
|
||||
l_mac_ppc32_loader, sizeof(l_mac_ppc32_loader),
|
||||
fold_machppc32, sizeof(fold_machppc32), ft );
|
||||
}
|
||||
void PackMachPPC32::patchLoader() { }
|
||||
void PackMachPPC32::updateLoader(OutputFile *) {}
|
||||
|
||||
void
|
||||
PackMachPPC32::patchLoaderChecksum()
|
||||
{
|
||||
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
|
||||
l_info *const lp = &linfo;
|
||||
// checksum for loader; also some PackHeader info
|
||||
lp->l_checksum = 0;
|
||||
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
|
||||
lp->l_lsize = (unsigned short) lsize;
|
||||
lp->l_version = (unsigned char) ph.version;
|
||||
lp->l_format = (unsigned char) ph.format;
|
||||
// INFO: lp->l_checksum is currently unused
|
||||
lp->l_checksum = upx_adler32(ptr, lsize);
|
||||
}
|
||||
|
||||
static int __acc_cdecl_qsort
|
||||
compare_segment_command(void const *const aa, void const *const bb)
|
||||
{
|
||||
Mach_segment_command const *const a = (Mach_segment_command const *)aa;
|
||||
Mach_segment_command const *const b = (Mach_segment_command const *)bb;
|
||||
unsigned const xa = a->cmd - Mach_segment_command::LC_SEGMENT;
|
||||
unsigned const xb = b->cmd - Mach_segment_command::LC_SEGMENT;
|
||||
if (xa < xb) return -1; // LC_SEGMENT first
|
||||
if (xa > xb) return 1;
|
||||
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr
|
||||
if (a->vmaddr > b->vmaddr) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
|
||||
{
|
||||
// offset of p_info in compressed file
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
|
||||
|
||||
super::pack4(fo, ft);
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
segcmdo.vmsize += segcmdo.filesize;
|
||||
fo->seek(sizeof(mhdro), SEEK_SET);
|
||||
fo->write(&segcmdo, sizeof(segcmdo));
|
||||
fo->write(&threado, sizeof(threado));
|
||||
fo->write(&linfo, sizeof(linfo));
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
|
||||
{
|
||||
BE32 disp;
|
||||
unsigned const zero = 0;
|
||||
unsigned len = fo->getBytesWritten();
|
||||
fo->write(&zero, 3& -len);
|
||||
len += (3& -len) + sizeof(disp);
|
||||
set_be32(&disp, 4+ len - sz_mach_headers); // 4: sizeof(instruction)
|
||||
fo->write(&disp, sizeof(disp));
|
||||
|
||||
threado.state.srr0 = len + segcmdo.vmaddr; /* entry address */
|
||||
super::pack3(fo, ft);
|
||||
}
|
||||
|
||||
// Determine length of gap between PT_LOAD phdri[k] and closest PT_LOAD
|
||||
// which follows in the file (or end-of-file). Optimize for common case
|
||||
// where the PT_LOAD are adjacent ascending by .p_offset. Assume no overlap.
|
||||
|
||||
unsigned PackMachPPC32::find_SEGMENT_gap(
|
||||
unsigned const k
|
||||
)
|
||||
{
|
||||
if (Mach_segment_command::LC_SEGMENT!=msegcmd[k].cmd
|
||||
|| 0==msegcmd[k].filesize ) {
|
||||
return 0;
|
||||
}
|
||||
unsigned const hi = get_native32(&msegcmd[k].fileoff) +
|
||||
get_native32(&msegcmd[k].filesize);
|
||||
unsigned lo = ph.u_file_size;
|
||||
unsigned j = k;
|
||||
for (;;) { // circular search, optimize for adjacent ascending
|
||||
++j;
|
||||
if (n_segment==j) {
|
||||
j = 0;
|
||||
}
|
||||
if (k==j) {
|
||||
break;
|
||||
}
|
||||
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd
|
||||
&& 0!=msegcmd[j].filesize ) {
|
||||
unsigned const t = get_native32(&msegcmd[j].fileoff);
|
||||
if ((t - hi) < (lo - hi)) {
|
||||
lo = t;
|
||||
if (hi==lo) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return lo - hi;
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::pack2(OutputFile *fo, Filter &ft) // append compressed body
|
||||
{
|
||||
Extent x;
|
||||
unsigned k;
|
||||
|
||||
// count passes, set ptload vars
|
||||
ui_total_passes = 0;
|
||||
for (k = 0; k < n_segment; ++k) {
|
||||
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd
|
||||
&& 0!=msegcmd[k].filesize ) {
|
||||
ui_total_passes++;
|
||||
if (find_SEGMENT_gap(k)) {
|
||||
ui_total_passes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// compress extents
|
||||
unsigned total_in = 0;
|
||||
unsigned total_out = 0;
|
||||
|
||||
unsigned hdr_ulen = mhdri.sizeofcmds;
|
||||
|
||||
ui_pass = 0;
|
||||
ft.addvalue = 0;
|
||||
|
||||
int nx = 0;
|
||||
for (k = 0; k < n_segment; ++k)
|
||||
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd
|
||||
&& 0!=msegcmd[k].filesize ) {
|
||||
x.offset = msegcmd[k].fileoff;
|
||||
x.size = msegcmd[k].filesize;
|
||||
if (0 == nx) { // 1st LC_SEGMENT must cover Mach_header at 0==fileoffset
|
||||
unsigned const delta = mhdri.sizeofcmds;
|
||||
x.offset += delta;
|
||||
x.size -= delta;
|
||||
}
|
||||
packExtent(x, total_in, total_out,
|
||||
((Mach_segment_command::VM_PROT_EXECUTE & msegcmd[k].initprot)
|
||||
? &ft : 0 ), fo, hdr_ulen );
|
||||
hdr_ulen = 0;
|
||||
++nx;
|
||||
}
|
||||
for (k = 0; k < n_segment; ++k) {
|
||||
x.size = find_SEGMENT_gap(k);
|
||||
if (x.size) {
|
||||
x.offset = get_native32(&msegcmd[k].fileoff) +
|
||||
get_native32(&msegcmd[k].filesize);
|
||||
packExtent(x, total_in, total_out, 0, fo);
|
||||
}
|
||||
}
|
||||
|
||||
if ((off_t)total_in != file_size)
|
||||
throwEOFException();
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
#undef PAGE_SIZE
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
#define PAGE_SIZE -PAGE_MASK
|
||||
void
|
||||
PackMachPPC32::pack1(OutputFile *fo, Filter &/*ft*/) // generate executable header
|
||||
{
|
||||
mhdro = mhdri;
|
||||
mhdro.ncmds = 2;
|
||||
mhdro.sizeofcmds = sizeof(segcmdo) + sizeof(threado);
|
||||
mhdro.flags = Mach_header::MH_NOUNDEFS;
|
||||
fo->write(&mhdro, sizeof(mhdro));
|
||||
|
||||
segcmdo.cmd = Mach_segment_command::LC_SEGMENT;
|
||||
segcmdo.cmdsize = sizeof(segcmdo);
|
||||
strncpy((char *)&segcmdo.segname, "__TEXT", sizeof(segcmdo.segname));
|
||||
segcmdo.vmaddr = PAGE_MASK & (~PAGE_MASK +
|
||||
msegcmd[n_segment -1].vmsize + msegcmd[n_segment -1].vmaddr );
|
||||
segcmdo.vmsize = 0; // adjust later
|
||||
segcmdo.fileoff = 0;
|
||||
segcmdo.filesize = 0; // adjust later
|
||||
segcmdo.initprot = segcmdo.maxprot =
|
||||
Mach_segment_command::VM_PROT_READ |
|
||||
Mach_segment_command::VM_PROT_WRITE |
|
||||
Mach_segment_command::VM_PROT_EXECUTE;
|
||||
segcmdo.nsects = 0;
|
||||
segcmdo.flags = 0;
|
||||
fo->write(&segcmdo, sizeof(segcmdo));
|
||||
|
||||
threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
|
||||
threado.cmdsize = sizeof(threado);
|
||||
threado.flavor = Mach_thread_command::PPC_THREAD_STATE;
|
||||
threado.count = Mach_thread_command::PPC_THREAD_STATE_COUNT;
|
||||
memset(&threado.state, 0, sizeof(threado.state));
|
||||
fo->write(&threado, sizeof(threado));
|
||||
sz_mach_headers = fo->getBytesWritten();
|
||||
|
||||
memset((char *)&linfo, 0, sizeof(linfo));
|
||||
fo->write(&linfo, sizeof(linfo));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
PackMachPPC32::unpack(OutputFile *fo)
|
||||
{
|
||||
fi->seek(overlay_offset, SEEK_SET);
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
|
||||
ibuf.alloc(blocksize + OVERHEAD);
|
||||
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
|
||||
fi->readx(&bhdr, sizeof(bhdr));
|
||||
ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = get_native32(&bhdr.sz_cpr);
|
||||
ph.filter_cto = bhdr.b_cto8;
|
||||
|
||||
// Uncompress Macho headers
|
||||
fi->readx(ibuf, ph.c_len);
|
||||
Mach_header *const mhdr = (Mach_header *)new upx_byte[ph.u_len];
|
||||
decompress(ibuf, (upx_byte *)mhdr, false);
|
||||
unsigned const ncmds = mhdr->ncmds;
|
||||
|
||||
msegcmd = new Mach_segment_command[ncmds];
|
||||
unsigned char *ptr = (unsigned char *)(1+mhdr);
|
||||
for (unsigned j= 0; j < ncmds; ++j) {
|
||||
msegcmd[j] = *(Mach_segment_command *)ptr;
|
||||
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize;
|
||||
}
|
||||
|
||||
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
|
||||
qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command);
|
||||
n_segment = 0;
|
||||
for (unsigned j= 0; j < ncmds; ++j) {
|
||||
n_segment += (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd);
|
||||
}
|
||||
|
||||
unsigned total_in = 0;
|
||||
unsigned total_out = 0;
|
||||
unsigned c_adler = upx_adler32(NULL, 0);
|
||||
unsigned u_adler = upx_adler32(NULL, 0);
|
||||
Mach_segment_command const *sc = (Mach_segment_command const *)(1+ mhdr);
|
||||
unsigned k;
|
||||
|
||||
fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR);
|
||||
for (
|
||||
k = 0;
|
||||
k < ncmds;
|
||||
(++k), (sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc))
|
||||
) {
|
||||
if (Mach_segment_command::LC_SEGMENT==sc->cmd
|
||||
&& 0!=sc->filesize ) {
|
||||
unsigned filesize = get_be32(&sc->filesize);
|
||||
unpackExtent(filesize, fo, total_in, total_out, c_adler, u_adler, false, sizeof(bhdr));
|
||||
}
|
||||
}
|
||||
for (unsigned j = 0; j < ncmds; ++j) {
|
||||
unsigned const size = find_SEGMENT_gap(j);
|
||||
if (size) {
|
||||
unsigned const where = get_native32(&msegcmd[k].fileoff) +
|
||||
get_native32(&msegcmd[k].filesize);
|
||||
if (fo)
|
||||
fo->seek(where, SEEK_SET);
|
||||
unpackExtent(size, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, sizeof(bhdr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackMachPPC32::canPack()
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&mhdri, sizeof(mhdri));
|
||||
|
||||
if (Mach_header::MH_MAGIC !=mhdri.magic
|
||||
|| Mach_header::CPU_TYPE_POWERPC !=mhdri.cputype
|
||||
|| Mach_header::MH_EXECUTE !=mhdri.filetype
|
||||
)
|
||||
return false;
|
||||
|
||||
rawmseg = (Mach_segment_command *)new char[mhdri.sizeofcmds];
|
||||
fi->readx(rawmseg, mhdri.sizeofcmds);
|
||||
|
||||
msegcmd = new Mach_segment_command[mhdri.ncmds];
|
||||
unsigned char *ptr = (unsigned char *)rawmseg;
|
||||
for (unsigned j= 0; j < mhdri.ncmds; ++j) {
|
||||
msegcmd[j] = *(Mach_segment_command *)ptr;
|
||||
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize;
|
||||
}
|
||||
|
||||
|
||||
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
|
||||
qsort(msegcmd, mhdri.ncmds, sizeof(*msegcmd), compare_segment_command);
|
||||
|
||||
// Check that LC_SEGMENTs form one contiguous chunk of the file.
|
||||
for (unsigned j= 0; j < mhdri.ncmds; ++j) {
|
||||
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd) {
|
||||
if (0xfff & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) {
|
||||
return false;
|
||||
}
|
||||
if (0 < j) {
|
||||
unsigned const sz = ~0xfff
|
||||
& (0xfff + msegcmd[j-1].filesize);
|
||||
if ((sz + msegcmd[j-1].fileoff)!=msegcmd[j].fileoff) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
++n_segment;
|
||||
sz_segment = msegcmd[j].filesize + msegcmd[j].fileoff - msegcmd[0].fileoff;
|
||||
}
|
||||
}
|
||||
// set options
|
||||
opt->o_unix.blocksize = file_size;
|
||||
return 0 < n_segment;
|
||||
}
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
/* p_mach.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_MACHO_H
|
||||
#define __UPX_P_MACHO_H
|
||||
|
||||
/*************************************************************************
|
||||
// Mach Mach Object executable
|
||||
**************************************************************************/
|
||||
|
||||
struct Mach_header {
|
||||
BE32 magic;
|
||||
enum {
|
||||
MH_MAGIC = 0xfeedface
|
||||
};
|
||||
BE32 cputype;
|
||||
enum {
|
||||
CPU_TYPE_POWERPC = 18
|
||||
};
|
||||
BE32 cpysubtype;
|
||||
BE32 filetype;
|
||||
enum {
|
||||
MH_EXECUTE = 2
|
||||
};
|
||||
BE32 ncmds;
|
||||
BE32 sizeofcmds;
|
||||
BE32 flags;
|
||||
enum {
|
||||
MH_NOUNDEFS = 1
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Mach_segment_command {
|
||||
BE32 cmd;
|
||||
enum {
|
||||
LC_SEGMENT = 0x1,
|
||||
LC_THREAD = 0x4,
|
||||
LC_UNIXTHREAD = 0x5,
|
||||
LC_LOAD_DYLINKER = 0xe
|
||||
};
|
||||
BE32 cmdsize;
|
||||
char segname[16];
|
||||
BE32 vmaddr;
|
||||
BE32 vmsize;
|
||||
BE32 fileoff;
|
||||
BE32 filesize;
|
||||
BE32 maxprot;
|
||||
enum {
|
||||
VM_PROT_READ = 1,
|
||||
VM_PROT_WRITE = 2,
|
||||
VM_PROT_EXECUTE = 4
|
||||
};
|
||||
BE32 initprot;
|
||||
BE32 nsects;
|
||||
BE32 flags;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Mach_section {
|
||||
char sectname[16];
|
||||
char segname[16];
|
||||
BE32 addr; /* memory address */
|
||||
BE32 size; /* size in bytes */
|
||||
BE32 offset; /* file offset */
|
||||
BE32 align; /* power of 2 */
|
||||
BE32 reloff; /* file offset of relocation entries */
|
||||
BE32 nreloc; /* number of relocation entries */
|
||||
BE32 flags; /* section type and attributes */
|
||||
enum {
|
||||
S_REGULAR = 0,
|
||||
S_ZEROFILL,
|
||||
S_CSTRING_LITERALS,
|
||||
S_4BYTE_LITERALS,
|
||||
S_8BYTE_LITERALS,
|
||||
S_LITERAL_POINTERS,
|
||||
S_NON_LAZY_SYMBOL_POINTERS,
|
||||
S_LAZY_SYMBOL_POINTERS,
|
||||
S_SYMBOL_STUBS,
|
||||
S_MOD_INIT_FUNC_POINTERS,
|
||||
S_MOD_TERM_FNC_POINTERS,
|
||||
S_COALESCED
|
||||
};
|
||||
enum {
|
||||
S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
|
||||
S_ATTR_NO_TOC = 0x40000000,
|
||||
S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
|
||||
S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
|
||||
S_ATTR_EXT_RELOC = 0x00000200,
|
||||
S_ATTR_LOC_RELOC = 0x00000100
|
||||
};
|
||||
BE32 reserved1;
|
||||
BE32 reserved2;
|
||||
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct Mach_ppc_thread_state {
|
||||
BE32 srr0; /* Instruction address register (PC; entry addr) */
|
||||
BE32 srr1; /* Machine state register (supervisor) */
|
||||
BE32 r0, r1, r2, r3, r4, r5, r6, r7;
|
||||
BE32 r8, r9,r10,r11,r12,r13,r14,r15;
|
||||
BE32 r16,r17,r18,r19,r20,r21,r22,r23;
|
||||
BE32 r24,r25,r26,r27,r28,r29,r30,r31;
|
||||
|
||||
BE32 cr; /* Condition register */
|
||||
BE32 xer; /* User's integer exception register */
|
||||
BE32 lr; /* Link register */
|
||||
BE32 ctr; /* Count register */
|
||||
BE32 mq; /* MQ register (601 only) */
|
||||
|
||||
BE32 vrsave; /* Vector Save Register */
|
||||
};
|
||||
|
||||
struct Mach_thread_command {
|
||||
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
BE32 cmdsize; /* total size of this command */
|
||||
BE32 flavor;
|
||||
enum {
|
||||
PPC_THREAD_STATE = 1
|
||||
};
|
||||
BE32 count; /* sizeof(following_thread_state)/4 */
|
||||
enum {
|
||||
PPC_THREAD_STATE_COUNT = sizeof(struct Mach_ppc_thread_state)/4
|
||||
};
|
||||
struct Mach_ppc_thread_state state;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
#include "p_unix.h"
|
||||
|
||||
|
||||
class PackMachPPC32 : public PackUnixBe32
|
||||
{
|
||||
typedef PackUnixBe32 super;
|
||||
public:
|
||||
PackMachPPC32(InputFile *f);
|
||||
virtual ~PackMachPPC32();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_MACH_PPC32; }
|
||||
virtual const char *getName() const { return "Mach/ppc32"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
// called by the generic pack()
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
virtual unsigned find_SEGMENT_gap(unsigned const k);
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void patchLoader();
|
||||
virtual void patchLoaderChecksum();
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual int buildMachLoader(
|
||||
upx_byte const *const proto,
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold,
|
||||
unsigned const szfold,
|
||||
Filter const *ft );
|
||||
|
||||
unsigned n_segment;
|
||||
unsigned sz_segment;
|
||||
unsigned sz_mach_headers;
|
||||
Mach_segment_command *rawmseg; // as input, with sections
|
||||
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
|
||||
Mach_header mhdri;
|
||||
|
||||
Mach_header mhdro;
|
||||
Mach_segment_command segcmdo;
|
||||
Mach_thread_command threado;
|
||||
struct l_info linfo;
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+8
-8
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2002-2004 Jens Medoch
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2002-2006 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -77,17 +77,17 @@ static const
|
||||
|
||||
PackPs1::PackPs1(InputFile *f) :
|
||||
super(f),
|
||||
isCon(true^opt->ps1_exe.boot_only), is32Bit(true^opt->ps1_exe.do_8bit),
|
||||
isCon(!opt->ps1_exe.boot_only), is32Bit(!opt->ps1_exe.do_8bit),
|
||||
overlap(0), sa_cnt(0)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 188);
|
||||
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t));
|
||||
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40);
|
||||
#if 1 || defined(WITH_NRV)
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3918);
|
||||
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0xdf0cbd9e);
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2810);
|
||||
COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x31747f8b);
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3935);
|
||||
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0x0ac25782);
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2829);
|
||||
COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x923b55c4);
|
||||
#endif
|
||||
fdata_size = file_size - PS_HDR_SIZE;
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -107,12 +107,12 @@ int PackSys::buildLoader(const Filter *ft)
|
||||
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
|
||||
addLoader("SYSMAIN1",
|
||||
opt->cpu == opt->CPU_8086 ? "SYSI0861" : "SYSI2861",
|
||||
"SYSMAIN2""SYSSUBSI",
|
||||
"SYSMAIN2,SYSSUBSI",
|
||||
ph.first_offset_found == 1 ? "SYSSBBBP" : "",
|
||||
ft->id ? "SYSCALLT" : "",
|
||||
"SYSMAIN3""UPX1HEAD""SYSCUTPO""NRV2B160""NRVDDONE""NRVDECO1",
|
||||
"SYSMAIN3,UPX1HEAD,SYSCUTPO,NRV2B160,NRVDDONE,NRVDECO1",
|
||||
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
|
||||
"NRVDECO2""NRV2B169",
|
||||
"NRVDECO2,NRV2B169",
|
||||
NULL
|
||||
);
|
||||
if (ft->id)
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -78,9 +78,9 @@ int PackTmt::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
addLoader("IDENTSTR""TMTMAIN1",
|
||||
addLoader("IDENTSTR,TMTMAIN1",
|
||||
ft->id ? "TMTCALT1" : "",
|
||||
"TMTMAIN2""UPX1HEAD""TMTCUTPO""+0XXXXXX",
|
||||
"TMTMAIN2,UPX1HEAD,TMTCUTPO,+0XXXXXX",
|
||||
getDecompressor(),
|
||||
"TMTMAIN5",
|
||||
NULL
|
||||
@@ -91,9 +91,9 @@ int PackTmt::buildLoader(const Filter *ft)
|
||||
addLoader("TMTCALT2",NULL);
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("TMTRELOC""RELOC320",
|
||||
addLoader("TMTRELOC,RELOC320",
|
||||
big_relocs ? "REL32BIG" : "",
|
||||
"RELOC32J""TMTJUMP1",
|
||||
"RELOC32J,TMTJUMP1",
|
||||
NULL
|
||||
);
|
||||
return getLoaderSize();
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -547,6 +547,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
// patch loader
|
||||
int tmp = patchPackHeader(loader, o_text);
|
||||
assert(tmp + 32 == (int)o_text); UNUSED(tmp);
|
||||
patchVersionYear(loader, o_text);
|
||||
if (!opt->small)
|
||||
patchVersion(loader, o_text);
|
||||
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
|
||||
|
||||
+211
-6
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
PackUnix::PackUnix(InputFile *f) :
|
||||
super(f), exetype(0), blocksize(0), overlay_offset(0), lsize(0)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf_LE32_Ehdr) == 52);
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf_LE32_Phdr) == 32);
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf32_Ehdr) == 52);
|
||||
COMPILE_TIME_ASSERT(sizeof(Elf32_Phdr) == 32);
|
||||
COMPILE_TIME_ASSERT(sizeof(b_info) == 12);
|
||||
COMPILE_TIME_ASSERT(sizeof(l_info) == 12);
|
||||
COMPILE_TIME_ASSERT(sizeof(p_info) == 12);
|
||||
@@ -127,7 +127,7 @@ int PackUnix::getStrategy(Filter &/*ft*/)
|
||||
|
||||
// If user specified the filter, then use it (-2==strategy).
|
||||
// Else try the first two filters, and pick the better (2==strategy).
|
||||
return ((opt->filter > 0) ? -2 : 2);
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
@@ -222,6 +222,20 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PackUnix::patchLoaderChecksum()
|
||||
{
|
||||
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
|
||||
l_info *const lp = &linfo;
|
||||
// checksum for loader; also some PackHeader info
|
||||
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
|
||||
lp->l_lsize = (unsigned short) lsize;
|
||||
lp->l_version = (unsigned char) ph.version;
|
||||
lp->l_format = (unsigned char) ph.format;
|
||||
// INFO: lp->l_checksum is currently unused
|
||||
lp->l_checksum = upx_adler32(ptr, lsize);
|
||||
}
|
||||
|
||||
void PackUnix::pack3(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
upx_byte const *p = getLoader();
|
||||
@@ -285,6 +299,197 @@ void PackUnix::pack(OutputFile *fo)
|
||||
}
|
||||
|
||||
|
||||
void PackUnix::packExtent(
|
||||
const Extent &x,
|
||||
unsigned &total_in,
|
||||
unsigned &total_out,
|
||||
Filter *ft,
|
||||
OutputFile *fo,
|
||||
unsigned hdr_ulen
|
||||
)
|
||||
{
|
||||
unsigned const init_u_adler = ph.u_adler;
|
||||
unsigned const init_c_adler = ph.c_adler;
|
||||
MemBuffer hdr_ibuf;
|
||||
if (hdr_ulen) {
|
||||
hdr_ibuf.alloc(hdr_ulen);
|
||||
fi->seek(0, SEEK_SET);
|
||||
int l = fi->readx(hdr_ibuf, hdr_ulen);
|
||||
(void)l;
|
||||
}
|
||||
fi->seek(x.offset, SEEK_SET);
|
||||
for (off_t rest = x.size; 0 != rest; ) {
|
||||
int const strategy = getStrategy(*ft);
|
||||
int l = fi->readx(ibuf, UPX_MIN(rest, (off_t)blocksize));
|
||||
if (l == 0) {
|
||||
break;
|
||||
}
|
||||
rest -= l;
|
||||
|
||||
// Note: compression for a block can fail if the
|
||||
// file is e.g. blocksize + 1 bytes long
|
||||
|
||||
// compress
|
||||
ph.c_len = ph.u_len = l;
|
||||
ph.overlap_overhead = 0;
|
||||
unsigned end_u_adler = 0;
|
||||
if (ft) {
|
||||
// compressWithFilters() updates u_adler _inside_ compress();
|
||||
// that is, AFTER filtering. We want BEFORE filtering,
|
||||
// so that decompression checks the end-to-end checksum.
|
||||
end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler);
|
||||
ft->buf_len = l;
|
||||
|
||||
// compressWithFilters() requirements?
|
||||
ph.filter = 0;
|
||||
ph.filter_cto = 0;
|
||||
ft->id = 0;
|
||||
ft->cto = 0;
|
||||
|
||||
compressWithFilters(ft, OVERHEAD, strategy,
|
||||
NULL, 0, 0, 0, 0, // those 5 args are the defaults
|
||||
hdr_ibuf, hdr_ulen);
|
||||
}
|
||||
else {
|
||||
(void) compress(ibuf, obuf); // ignore return value
|
||||
}
|
||||
|
||||
if (ph.c_len < ph.u_len) {
|
||||
ph.overlap_overhead = OVERHEAD;
|
||||
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
|
||||
// not in-place compressible
|
||||
ph.c_len = ph.u_len;
|
||||
}
|
||||
}
|
||||
if (ph.c_len >= ph.u_len) {
|
||||
// block is not compressible
|
||||
ph.c_len = ph.u_len;
|
||||
memcpy(obuf, ibuf, ph.c_len);
|
||||
// must update checksum of compressed data
|
||||
ph.c_adler = upx_adler32(ibuf, ph.u_len, ph.saved_c_adler);
|
||||
}
|
||||
|
||||
// write block sizes
|
||||
b_info tmp;
|
||||
if (hdr_ulen) {
|
||||
unsigned hdr_clen;
|
||||
MemBuffer hdr_obuf;
|
||||
unsigned result[16];
|
||||
upx_compress_config_t conf;
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
hdr_obuf.allocForCompression(hdr_ulen);
|
||||
int r = upx_compress(hdr_ibuf, hdr_ulen, hdr_obuf, &hdr_clen, 0,
|
||||
ph.method, 10, &conf, result);
|
||||
(void)r;
|
||||
ph.saved_u_adler = upx_adler32(hdr_ibuf, hdr_ulen, init_u_adler);
|
||||
ph.saved_c_adler = upx_adler32(hdr_obuf, hdr_clen, init_c_adler);
|
||||
ph.u_adler = upx_adler32(ibuf, ph.u_len, ph.saved_u_adler);
|
||||
ph.c_adler = upx_adler32(obuf, ph.c_len, ph.saved_c_adler);
|
||||
end_u_adler = ph.u_adler;
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, hdr_ulen);
|
||||
set_native32(&tmp.sz_cpr, hdr_clen);
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
fo->write(hdr_obuf, hdr_clen);
|
||||
total_out += hdr_clen;
|
||||
total_in += hdr_ulen;
|
||||
hdr_ulen = 0; // compress hdr one time only
|
||||
}
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, ph.u_len);
|
||||
set_native32(&tmp.sz_cpr, ph.c_len);
|
||||
if (ph.c_len < ph.u_len) {
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
if (ft) {
|
||||
tmp.b_ftid = (unsigned char) ft->id;
|
||||
tmp.b_cto8 = ft->cto;
|
||||
}
|
||||
}
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
|
||||
// write compressed data
|
||||
if (ph.c_len < ph.u_len) {
|
||||
fo->write(obuf, ph.c_len);
|
||||
// Checks ph.u_adler after decompression, after unfiltering
|
||||
verifyOverlappingDecompression(ft);
|
||||
}
|
||||
else {
|
||||
fo->write(ibuf, ph.u_len);
|
||||
}
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
total_in += ph.u_len;
|
||||
total_out += ph.c_len;
|
||||
}
|
||||
}
|
||||
|
||||
void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
unsigned &total_in, unsigned &total_out,
|
||||
unsigned &c_adler, unsigned &u_adler,
|
||||
bool first_PF_X, unsigned szb_info
|
||||
)
|
||||
{
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
while (wanted) {
|
||||
fi->readx(&hdr, szb_info);
|
||||
int const sz_unc = ph.u_len = get_native32(&hdr.sz_unc);
|
||||
int const sz_cpr = ph.c_len = get_native32(&hdr.sz_cpr);
|
||||
ph.filter_cto = hdr.b_cto8;
|
||||
|
||||
if (sz_unc == 0) { // must never happen while 0!=wanted
|
||||
throwCompressedDataViolation();
|
||||
break;
|
||||
}
|
||||
if (sz_unc <= 0 || sz_cpr <= 0)
|
||||
throwCompressedDataViolation();
|
||||
if (sz_cpr > sz_unc || sz_unc > (int)blocksize)
|
||||
throwCompressedDataViolation();
|
||||
|
||||
int j = blocksize + OVERHEAD - sz_cpr;
|
||||
fi->readx(ibuf+j, sz_cpr);
|
||||
// update checksum of compressed data
|
||||
c_adler = upx_adler32(ibuf + j, sz_cpr, c_adler);
|
||||
// decompress
|
||||
if (sz_cpr < sz_unc)
|
||||
{
|
||||
decompress(ibuf+j, ibuf, false);
|
||||
if (12==szb_info) { // modern per-block filter
|
||||
if (hdr.b_ftid) {
|
||||
Filter ft(ph.level); // FIXME: ph.level for b_info?
|
||||
ft.init(hdr.b_ftid, 0);
|
||||
ft.cto = hdr.b_cto8;
|
||||
ft.unfilter(ibuf, sz_unc);
|
||||
}
|
||||
}
|
||||
else { // ancient per-file filter
|
||||
if (first_PF_X) { // Elf32_Ehdr is never filtered
|
||||
first_PF_X = false; // but everything else might be
|
||||
}
|
||||
else if (ph.filter) {
|
||||
Filter ft(ph.level);
|
||||
ft.init(ph.filter, 0);
|
||||
ft.cto = (unsigned char) ph.filter_cto;
|
||||
ft.unfilter(ibuf, sz_unc);
|
||||
}
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
// update checksum of uncompressed data
|
||||
u_adler = upx_adler32(ibuf + j, sz_unc, u_adler);
|
||||
total_in += sz_cpr;
|
||||
total_out += sz_unc;
|
||||
// write block
|
||||
if (fo)
|
||||
fo->write(ibuf + j, sz_unc);
|
||||
wanted -= sz_unc;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
// Generic Unix canUnpack().
|
||||
**************************************************************************/
|
||||
@@ -321,7 +526,7 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
{
|
||||
unsigned szb_info = sizeof(b_info);
|
||||
{
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf32_Ehdr ehdr;
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ehdr, sizeof(ehdr));
|
||||
unsigned const e_entry = get_native32(&ehdr.e_entry);
|
||||
@@ -329,7 +534,7 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
else {
|
||||
Elf_LE32_Phdr phdr;
|
||||
Elf32_Phdr phdr;
|
||||
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(&phdr, sizeof(phdr));
|
||||
unsigned const p_vaddr = get_native32(&phdr.p_vaddr);
|
||||
|
||||
+82
-24
@@ -59,19 +59,35 @@ protected:
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
|
||||
virtual void patchLoader() = 0;
|
||||
virtual void patchLoaderChecksum() {}
|
||||
virtual void patchLoaderChecksum();
|
||||
virtual void updateLoader(OutputFile *) = 0;
|
||||
|
||||
virtual void writePackHeader(OutputFile *fo);
|
||||
|
||||
// in order too share as much code as possible we introduce
|
||||
// an endian abstraction here
|
||||
virtual unsigned get_native32(const void *) = 0;
|
||||
virtual void set_native32(void *, unsigned) = 0;
|
||||
virtual void set_native16(void *, unsigned) = 0;
|
||||
virtual acc_uint64l_t get_native64(const void *) const = 0;
|
||||
virtual unsigned get_native32(const void *) const = 0;
|
||||
virtual unsigned get_native16(const void *) const = 0;
|
||||
virtual void set_native64(void *, acc_uint64l_t) const = 0;
|
||||
virtual void set_native32(void *, unsigned) const = 0;
|
||||
virtual void set_native16(void *, unsigned) const = 0;
|
||||
|
||||
virtual bool checkCompressionRatio(unsigned, unsigned) const;
|
||||
|
||||
protected:
|
||||
struct Extent {
|
||||
off_t offset;
|
||||
off_t size;
|
||||
};
|
||||
virtual void packExtent(const Extent &x,
|
||||
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *,
|
||||
unsigned hdr_len = 0);
|
||||
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
unsigned &total_in, unsigned &total_out,
|
||||
unsigned &c_adler, unsigned &u_adler,
|
||||
bool first_PF_X, unsigned szb_info );
|
||||
|
||||
int exetype;
|
||||
unsigned blocksize;
|
||||
unsigned progid; // program id
|
||||
@@ -94,7 +110,6 @@ protected:
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
unsigned l_checksum;
|
||||
unsigned l_magic;
|
||||
@@ -111,6 +126,8 @@ protected:
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct l_info linfo;
|
||||
|
||||
// do not change !!!
|
||||
enum { OVERHEAD = 2048 };
|
||||
};
|
||||
@@ -120,24 +137,44 @@ protected:
|
||||
// abstract classes encapsulating endian issues
|
||||
// note: UPX_MAGIC is always stored in le32 format
|
||||
**************************************************************************/
|
||||
|
||||
class PackUnixBe32 : public PackUnix
|
||||
{
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixBe32(InputFile *f) : super(f) { }
|
||||
virtual unsigned get_native32(const void *b)
|
||||
{
|
||||
return get_be32(b);
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
BE32 sz_unc; // uncompressed_size
|
||||
BE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
virtual void set_native32(void *b, unsigned v)
|
||||
{
|
||||
set_be32(b, v);
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
BE32 l_checksum;
|
||||
BE32 l_magic;
|
||||
BE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
virtual void set_native16(void *b, unsigned v)
|
||||
{
|
||||
set_be16(b, v);
|
||||
__attribute_packed;
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
BE32 p_progid;
|
||||
BE32 p_filesize;
|
||||
BE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -146,18 +183,39 @@ class PackUnixLe32 : public PackUnix
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixLe32(InputFile *f) : super(f) { }
|
||||
virtual unsigned get_native32(const void *b)
|
||||
{
|
||||
return get_le32(b);
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
LE32 sz_unc; // uncompressed_size
|
||||
LE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
virtual void set_native32(void *b, unsigned v)
|
||||
{
|
||||
set_le32(b, v);
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
virtual void set_native16(void *b, unsigned v)
|
||||
{
|
||||
set_le16(b, v);
|
||||
__attribute_packed;
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
LE32 p_progid;
|
||||
LE32 p_filesize;
|
||||
LE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
+57
-57
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
|
||||
John Reiser
|
||||
jreiser@users.sourceforge.net
|
||||
@@ -72,10 +72,10 @@ const int *PackVmlinuxI386::getFilters() const
|
||||
static int __acc_cdecl_qsort
|
||||
compare_Phdr(void const *aa, void const *bb)
|
||||
{
|
||||
Elf_LE32_Phdr const *const a = (Elf_LE32_Phdr const *)aa;
|
||||
Elf_LE32_Phdr const *const b = (Elf_LE32_Phdr const *)bb;
|
||||
unsigned const xa = a->p_type - Elf_LE32_Phdr::PT_LOAD;
|
||||
unsigned const xb = b->p_type - Elf_LE32_Phdr::PT_LOAD;
|
||||
Elf32_Phdr const *const a = (Elf32_Phdr const *)aa;
|
||||
Elf32_Phdr const *const b = (Elf32_Phdr const *)bb;
|
||||
unsigned const xa = a->p_type - Elf32_Phdr::PT_LOAD;
|
||||
unsigned const xb = b->p_type - Elf32_Phdr::PT_LOAD;
|
||||
if (xa < xb) return -1; // PT_LOAD first
|
||||
if (xa > xb) return 1;
|
||||
if (a->p_paddr < b->p_paddr) return -1; // ascending by .p_paddr
|
||||
@@ -118,14 +118,14 @@ bool PackVmlinuxI386::canPack()
|
||||
// additional requirements for vmlinux
|
||||
if (ehdri.e_ehsize != sizeof(ehdri) // different <elf.h> ?
|
||||
|| ehdri.e_phoff != sizeof(ehdri) // Phdrs not contiguous with Ehdr
|
||||
|| ehdri.e_phentsize!=sizeof(Elf_LE32_Phdr)
|
||||
|| ehdri.e_type!=Elf_LE32_Ehdr::ET_EXEC
|
||||
|| ehdri.e_phentsize!=sizeof(Elf32_Phdr)
|
||||
|| ehdri.e_type!=Elf32_Ehdr::ET_EXEC
|
||||
|| 0x00100000!=(0x001fffff & ehdri.e_entry) // entry not an odd 1MB
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
phdri = new Elf_LE32_Phdr[(unsigned) ehdri.e_phnum];
|
||||
phdri = new Elf32_Phdr[(unsigned) ehdri.e_phnum];
|
||||
fi->seek(ehdri.e_phoff, SEEK_SET);
|
||||
fi->readx(phdri, ehdri.e_phnum * sizeof(*phdri));
|
||||
|
||||
@@ -134,7 +134,7 @@ bool PackVmlinuxI386::canPack()
|
||||
|
||||
// Check that PT_LOADs form one contiguous chunk of the file.
|
||||
for (unsigned j = 0; j < ehdri.e_phnum; ++j) {
|
||||
if (Elf_LE32_Phdr::PT_LOAD==phdri[j].p_type) {
|
||||
if (Elf32_Phdr::PT_LOAD==phdri[j].p_type) {
|
||||
if (0xfff & (phdri[j].p_offset | phdri[j].p_paddr
|
||||
| phdri[j].p_align | phdri[j].p_vaddr) ) {
|
||||
return false;
|
||||
@@ -174,7 +174,7 @@ int PackVmlinuxI386::buildLoader(const Filter *ft)
|
||||
}
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUX990""IDENTSTR""UPX1HEAD", NULL);
|
||||
addLoader("LINUX990,IDENTSTR,UPX1HEAD", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -182,13 +182,13 @@ int PackVmlinuxI386::buildLoader(const Filter *ft)
|
||||
void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
{
|
||||
unsigned fo_off = 0;
|
||||
Elf_LE32_Ehdr ehdro;
|
||||
Elf32_Ehdr ehdro;
|
||||
LE32 tmp_le32;
|
||||
|
||||
// NULL
|
||||
// .text(PT_LOADs) .note(1st page) .note(rest)
|
||||
// .shstrtab /* .symtab .strtab */
|
||||
Elf_LE32_Shdr shdro[1+3+1/*+2*/];
|
||||
Elf32_Shdr shdro[1+3+1/*+2*/];
|
||||
memset(shdro, 0, sizeof(shdro));
|
||||
char const shstrtab[]= "\0.text\0.note\0.shstrtab\0.symtab\0.strtab";
|
||||
char const *p = shstrtab;
|
||||
@@ -198,7 +198,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
// .e_ident, .e_machine, .e_version, .e_flags
|
||||
memcpy(&ehdro, &ehdri, sizeof(ehdro));
|
||||
ehdro.e_type = Elf_LE32_Ehdr::ET_REL;
|
||||
ehdro.e_type = Elf32_Ehdr::ET_REL;
|
||||
ehdro.e_entry = 0;
|
||||
ehdro.e_phoff = 0;
|
||||
ehdro.e_shoff = 0; // later
|
||||
@@ -231,8 +231,8 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[1].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[1].sh_type = Elf_LE32_Shdr::SHT_PROGBITS;
|
||||
shdro[1].sh_flags = Elf_LE32_Shdr::SHF_ALLOC | Elf_LE32_Shdr::SHF_EXECINSTR;
|
||||
shdro[1].sh_type = Elf32_Shdr::SHT_PROGBITS;
|
||||
shdro[1].sh_flags = Elf32_Shdr::SHF_ALLOC | Elf32_Shdr::SHF_EXECINSTR;
|
||||
shdro[1].sh_offset = fo_off;
|
||||
shdro[1].sh_size = 1+ 4+ ph.c_len + lsize;
|
||||
shdro[1].sh_addralign = 1;
|
||||
@@ -257,7 +257,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[2].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[2].sh_type = Elf_LE32_Shdr::SHT_NOTE;
|
||||
shdro[2].sh_type = Elf32_Shdr::SHT_NOTE;
|
||||
shdro[2].sh_offset = fo_off;
|
||||
shdro[2].sh_size = sizeof(ph.u_len) + ph.c_len;
|
||||
shdro[2].sh_addralign = 1;
|
||||
@@ -283,7 +283,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
// while (0!=*p++) ; // name is the same
|
||||
shdro[3].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[3].sh_type = Elf_LE32_Shdr::SHT_NOTE;
|
||||
shdro[3].sh_type = Elf32_Shdr::SHT_NOTE;
|
||||
shdro[3].sh_offset = fo_off;
|
||||
shdro[3].sh_size = sizeof(ph.u_len) + ph.c_len;
|
||||
shdro[3].sh_addralign = 1;
|
||||
@@ -292,7 +292,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[4].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[4].sh_type = Elf_LE32_Shdr::SHT_STRTAB;
|
||||
shdro[4].sh_type = Elf32_Shdr::SHT_STRTAB;
|
||||
shdro[4].sh_offset = fo_off;
|
||||
shdro[4].sh_size = 1+ sizeof(shstrtab); // 1+: terminating '\0'
|
||||
shdro[4].sh_addralign = 1;
|
||||
@@ -302,7 +302,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
while (0!=*p++) ;
|
||||
fo_off = ~3 & (3+ fo_off);
|
||||
shdro[5].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[5].sh_type = Elf_LE32_Shdr::SHT_SYMTAB;
|
||||
shdro[5].sh_type = Elf32_Shdr::SHT_SYMTAB;
|
||||
shdro[5].sh_offset = fo_off;
|
||||
shdro[5].sh_size = 16; // XXX ?
|
||||
shdro[5].sh_link = 6; // to .strtab for symbols
|
||||
@@ -313,7 +313,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
|
||||
|
||||
while (0!=*p++) ;
|
||||
shdro[6].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[6].sh_type = Elf_LE32_Shdr::SHT_STRTAB;
|
||||
shdro[6].sh_type = Elf32_Shdr::SHT_STRTAB;
|
||||
shdro[6].sh_offset = fo_off;
|
||||
shdro[6].sh_size = 1; // XXX ?
|
||||
shdro[6].sh_addralign = 1;
|
||||
@@ -347,21 +347,21 @@ int PackVmlinuxI386::canUnpack()
|
||||
|| !memcmp(&ehdri.e_ident[8], "FreeBSD", 7) // branded
|
||||
|| ehdri.e_machine != 3 // Intel 80386
|
||||
|| ehdri.e_version != 1 // version
|
||||
|| ehdri.e_type != Elf_LE32_Ehdr::ET_REL
|
||||
|| ehdri.e_type != Elf32_Ehdr::ET_REL
|
||||
|| ehdri.e_shnum < 4
|
||||
|| (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf_LE32_Shdr) + ehdri.e_shoff)
|
||||
|| (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf32_Shdr) + ehdri.e_shoff)
|
||||
)
|
||||
return false;
|
||||
|
||||
// find the .shstrtab section
|
||||
char shstrtab[40];
|
||||
Elf_LE32_Shdr *p, *p_shstrtab=0;
|
||||
shdri = new Elf_LE32_Shdr[(unsigned) ehdri.e_shnum];
|
||||
Elf32_Shdr *p, *p_shstrtab=0;
|
||||
shdri = new Elf32_Shdr[(unsigned) ehdri.e_shnum];
|
||||
fi->seek(ehdri.e_shoff, SEEK_SET);
|
||||
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
|
||||
int j;
|
||||
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
|
||||
if (Elf_LE32_Shdr::SHT_STRTAB==p->sh_type
|
||||
if (Elf32_Shdr::SHT_STRTAB==p->sh_type
|
||||
&& p->sh_size <= sizeof(shstrtab)
|
||||
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
|
||||
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
|
||||
@@ -487,37 +487,37 @@ void PackVmlinuxI386::unpack(OutputFile *fo)
|
||||
//-----
|
||||
//
|
||||
//----- arch/i386/boot/compressed/upx-head.S
|
||||
// .text
|
||||
// .text
|
||||
//startup_32: .globl startup_32 # In: %esi=0x90000 setup data "real_mode pointer"
|
||||
// #cli # this must be true already
|
||||
// #cli # this must be true already
|
||||
//
|
||||
// /* The only facts about segments here, that are true for all kernels:
|
||||
// * %cs is a valid "flat" code segment; no other segment reg is valid;
|
||||
// * the next segment after %cs is a valid "flat" data segment, but
|
||||
// * no segment register designates it yet.
|
||||
// */
|
||||
// movl %cs,%eax; addl $1<<3,%eax # the next segment after %cs
|
||||
// movl %eax,%ds
|
||||
// movl %eax,%es
|
||||
// leal 0x9000(%esi),%ecx # 0x99000 typical
|
||||
// movl %ecx,-8(%ecx) # 32-bit offset for stack pointer
|
||||
// movl %eax,-4(%ecx) # segment for stack pointer
|
||||
// lss -8(%ecx),%esp # %ss:%esp= %ds:0x99000
|
||||
// /* Linux Documentation/i386/boot.txt "SAMPLE BOOT CONFIGURATION" says
|
||||
// 0x8000-0x8FFF Stack and heap [inside the "real mode segment",
|
||||
// just below the command line at offset 0x9000].
|
||||
// /* The only facts about segments here, that are true for all kernels:
|
||||
// * %cs is a valid "flat" code segment; no other segment reg is valid;
|
||||
// * the next segment after %cs is a valid "flat" data segment, but
|
||||
// * no segment register designates it yet.
|
||||
// */
|
||||
// movl %cs,%eax; addl $1<<3,%eax # the next segment after %cs
|
||||
// movl %eax,%ds
|
||||
// movl %eax,%es
|
||||
// leal 0x9000(%esi),%ecx # 0x99000 typical
|
||||
// movl %ecx,-8(%ecx) # 32-bit offset for stack pointer
|
||||
// movl %eax,-4(%ecx) # segment for stack pointer
|
||||
// lss -8(%ecx),%esp # %ss:%esp= %ds:0x99000
|
||||
// /* Linux Documentation/i386/boot.txt "SAMPLE BOOT CONFIGURATION" says
|
||||
// 0x8000-0x8FFF Stack and heap [inside the "real mode segment",
|
||||
// just below the command line at offset 0x9000].
|
||||
//
|
||||
// arch/i386/boot/compressed/head.S "Do the decompression ..." says
|
||||
// %esi contains the "real mode pointer" [as a 32-bit addr].
|
||||
// arch/i386/boot/compressed/head.S "Do the decompression ..." says
|
||||
// %esi contains the "real mode pointer" [as a 32-bit addr].
|
||||
//
|
||||
// In any case, avoid EBDA (Extended BIOS Data Area) below 0xA0000.
|
||||
// boot.txt says 0x9A000 is the limit. LILO goes up to 0x9B000.
|
||||
// */
|
||||
// In any case, avoid EBDA (Extended BIOS Data Area) below 0xA0000.
|
||||
// boot.txt says 0x9A000 is the limit. LILO goes up to 0x9B000.
|
||||
// */
|
||||
//
|
||||
// pushl $0; popf # subsumes "cli; cld"; also clears NT for buggy BIOS
|
||||
// pushl $0; popf # subsumes "cli; cld"; also clears NT for buggy BIOS
|
||||
//
|
||||
// movl $ 0x100000,%eax # destination of uncompression (and entry point)
|
||||
// push %cs
|
||||
// movl $ 0x100000,%eax # destination of uncompression (and entry point)
|
||||
// push %cs
|
||||
/* Fall into .text of upx-compressed vmlinux. */
|
||||
//-----
|
||||
|
||||
@@ -550,17 +550,17 @@ void PackVmlinuxI386::unpack(OutputFile *fo)
|
||||
//all: vmlinux
|
||||
//
|
||||
//vmlinux: upx-piggy.o $(OBJECTS)
|
||||
// $(LD) $(ZLINKFLAGS) -o vmlinux $(OBJECTS) upx-piggy.o
|
||||
// $(LD) $(ZLINKFLAGS) -o vmlinux $(OBJECTS) upx-piggy.o
|
||||
//
|
||||
//bvmlinux: upx-piggy.o $(OBJECTS)
|
||||
// $(LD) $(BZLINKFLAGS) -o bvmlinux $(OBJECTS) upx-piggy.o
|
||||
// $(LD) $(BZLINKFLAGS) -o bvmlinux $(OBJECTS) upx-piggy.o
|
||||
//
|
||||
//upx-piggy.o: $(SYSTEM)
|
||||
// $(RM) -f $@
|
||||
// upx --best -o $@ $<
|
||||
//upx-piggy.o: $(SYSTEM)
|
||||
// $(RM) -f $@
|
||||
// upx --best -o $@ $<
|
||||
//
|
||||
//clean:
|
||||
// rm -f vmlinux bvmlinux _tmp_*
|
||||
// rm -f vmlinux bvmlinux _tmp_*
|
||||
//-----
|
||||
|
||||
//
|
||||
@@ -579,7 +579,7 @@ void PackVmlinuxI386::unpack(OutputFile *fo)
|
||||
// $ # Compare file 'dumped' with the portion of vmlinux that made piggy.o.
|
||||
// $ dd if=vmlinux bs=<leader_size> skip=1 | cmp - dumped
|
||||
// cmp: EOF on dumped
|
||||
// $
|
||||
// $
|
||||
//----- test-piggy.S
|
||||
//#include <asm/mman.h>
|
||||
//#include <asm/unistd.h>
|
||||
|
||||
+7
-7
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -60,12 +60,12 @@ protected:
|
||||
|
||||
int n_ptload;
|
||||
unsigned sz_ptload;
|
||||
Elf_LE32_Phdr *phdri; // from input file
|
||||
Elf_LE32_Shdr *shdri; // from input file
|
||||
Elf_LE32_Shdr *p_text;
|
||||
Elf_LE32_Shdr *p_note0;
|
||||
Elf_LE32_Shdr *p_note1;
|
||||
Elf_LE32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // from input file
|
||||
Elf32_Shdr *shdri; // from input file
|
||||
Elf32_Shdr *p_text;
|
||||
Elf32_Shdr *p_note0;
|
||||
Elf32_Shdr *p_note1;
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
};
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ int PackVmlinuzI386::buildLoader(const Filter *ft)
|
||||
addLoader("LZCALLT9", NULL);
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUZ990""IDENTSTR""UPX1HEAD", NULL);
|
||||
addLoader("LINUZ990,IDENTSTR,UPX1HEAD", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -319,10 +319,10 @@ int PackBvmlinuzI386::buildLoader(const Filter *ft)
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
addLoader("LINUZ000",
|
||||
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
|
||||
"LBZIMAGE""IDENTSTR",
|
||||
"LBZIMAGE,IDENTSTR",
|
||||
"+40D++++", // align the stuff to 4 byte boundary
|
||||
"UPX1HEAD", // 32 byte
|
||||
"LZCUTPOI""+0000000",
|
||||
"LZCUTPOI,+0000000",
|
||||
getDecompressor(),
|
||||
NULL
|
||||
);
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+235
-62
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -152,12 +152,18 @@ PackW32Pe::PackW32Pe(InputFile *f) : super(f)
|
||||
otls = NULL;
|
||||
oresources = NULL;
|
||||
oxrelocs = NULL;
|
||||
oloadconf = NULL;
|
||||
icondir_offset = 0;
|
||||
icondir_count = 0;
|
||||
importbyordinal = false;
|
||||
kernel32ordinal = false;
|
||||
tlsindex = 0;
|
||||
big_relocs = 0;
|
||||
sorelocs = 0;
|
||||
soxrelocs = 0;
|
||||
soloadconf = 0;
|
||||
use_dep_hack = true;
|
||||
use_clear_dirty_stack = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +177,7 @@ PackW32Pe::~PackW32Pe()
|
||||
delete [] otls;
|
||||
delete [] oresources;
|
||||
delete [] oxrelocs;
|
||||
delete [] oloadconf;
|
||||
//delete res;
|
||||
}
|
||||
|
||||
@@ -475,37 +482,42 @@ void PackW32Pe::processRelocs() // pass1
|
||||
for (; ic; ic--)
|
||||
fix[ic] = new LE32 [counts[ic]];
|
||||
|
||||
unsigned xcounts[4];
|
||||
memset(xcounts, 0, sizeof(xcounts));
|
||||
|
||||
// prepare sorting
|
||||
unsigned pos,type;
|
||||
while (rel.next(pos,type))
|
||||
{
|
||||
if (pos >= ih.imagesize)
|
||||
continue; // skip out-of-bounds record
|
||||
if (type == 3)
|
||||
set_le32(ibuf + pos,get_le32(ibuf + pos) - ih.imagebase - rvamin);
|
||||
if (type < 4)
|
||||
*fix[type]++ = pos - rvamin;
|
||||
fix[type][xcounts[type]++] = pos - rvamin;
|
||||
}
|
||||
fix[3] -= counts[3];
|
||||
|
||||
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
||||
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], xcounts[3],
|
||||
orelocs, ibuf + rvamin,1, &big_relocs),
|
||||
orelocs);
|
||||
delete [] fix[3];
|
||||
|
||||
// append relocs type "LOW" then "HIGH"
|
||||
for (ic = 2; ic ; ic--)
|
||||
{
|
||||
fix[ic] -= counts[ic];
|
||||
memcpy(orelocs + sorelocs,fix[ic],4 * counts[ic]);
|
||||
sorelocs += 4 * counts[ic];
|
||||
memcpy(orelocs + sorelocs,fix[ic],4 * xcounts[ic]);
|
||||
sorelocs += 4 * xcounts[ic];
|
||||
delete [] fix[ic];
|
||||
|
||||
set_le32(orelocs + sorelocs,0);
|
||||
if (counts[ic])
|
||||
if (xcounts[ic])
|
||||
{
|
||||
sorelocs += 4;
|
||||
big_relocs |= 2 * ic;
|
||||
}
|
||||
}
|
||||
delete [] fix[3];
|
||||
info("Relocations: original size: %u bytes, preprocessed size: %u bytes",(unsigned) IDSIZE(PEDIR_RELOC),sorelocs);
|
||||
}
|
||||
|
||||
@@ -544,7 +556,9 @@ void PackW32Pe::processImports(unsigned myimport) // pass 2
|
||||
unsigned PackW32Pe::processImports() // pass 1
|
||||
{
|
||||
static const unsigned char kernel32dll[] = "KERNEL32.DLL";
|
||||
static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0""GetProcAddress\x0\x0";
|
||||
static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0"
|
||||
"GetProcAddress\x0\x0"
|
||||
"VirtualProtect\x0\x0";
|
||||
static const char exitp[] = "ExitProcess\x0\x0\x0";
|
||||
|
||||
unsigned dllnum = 0;
|
||||
@@ -566,7 +580,6 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
LE32 *lookupt;
|
||||
unsigned npos;
|
||||
bool isk32;
|
||||
unsigned _; // padding to 32
|
||||
|
||||
static int __acc_cdecl_qsort compare(const void *p1, const void *p2)
|
||||
{
|
||||
@@ -582,8 +595,7 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
if (!u2->shname) return -1;
|
||||
return strlen(u1->shname) - strlen(u2->shname);
|
||||
}
|
||||
}
|
||||
__attribute_packed;
|
||||
};
|
||||
|
||||
// +1 for dllnum=0
|
||||
Array(struct udll, dlls, dllnum+1);
|
||||
@@ -648,22 +660,23 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
im = (import_desc*) oimpdlls;
|
||||
|
||||
LE32 *ordinals = (LE32*) (oimpdlls + (dllnum2 + 1) * sizeof(import_desc));
|
||||
LE32 *lookuptable = ordinals + 3 + k32o + (isdll ? 0 : 1);
|
||||
LE32 *lookuptable = ordinals + 4 + k32o + (isdll ? 0 : 1);
|
||||
upx_byte *dllnames = ((upx_byte*) lookuptable) + (dllnum2 - 1) * 8;
|
||||
upx_byte *importednames = dllnames + (dllnamelen &~ 1);
|
||||
|
||||
unsigned k32namepos = ptr_diff(dllnames,oimpdlls);
|
||||
|
||||
memcpy(importednames,llgpa,sizeof(llgpa));
|
||||
memcpy(importednames, llgpa, sizeof(llgpa));
|
||||
if (!isdll)
|
||||
memcpy(importednames + sizeof(llgpa) - 1,exitp,sizeof(exitp));
|
||||
memcpy(importednames + sizeof(llgpa) - 1, exitp, sizeof(exitp));
|
||||
strcpy(dllnames,kernel32dll);
|
||||
im->dllname = k32namepos;
|
||||
im->iat = ptr_diff(ordinals,oimpdlls);
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls);
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14;
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls); // LoadLibraryA
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14; // GetProcAddress
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14 + 16; // VirtualProtect
|
||||
if (!isdll)
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + sizeof(llgpa) - 3;
|
||||
*ordinals++ = ptr_diff(importednames,oimpdlls) + sizeof(llgpa) - 3; // ExitProcess
|
||||
dllnames += sizeof(kernel32dll);
|
||||
importednames += sizeof(llgpa) - 2 + (isdll ? 0 : sizeof(exitp) - 1);
|
||||
|
||||
@@ -758,7 +771,7 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
soimport = 0;
|
||||
|
||||
//OutputFile::dump("x0.imp", oimport, soimport);
|
||||
//OutputFile::dump("x1.imp", oimpdlls, soimpdlss);
|
||||
//OutputFile::dump("x1.imp", oimpdlls, soimpdlls);
|
||||
|
||||
unsigned ilen = 0;
|
||||
names.flatten();
|
||||
@@ -1165,11 +1178,10 @@ public:
|
||||
bool clear();
|
||||
|
||||
void dump() const { dump(root,0); }
|
||||
/*
|
||||
unsigned iname() const {return current->parent->id;}
|
||||
unsigned iname() const {return current->parent->id;}
|
||||
const upx_byte *nname() const {return current->parent->name;}
|
||||
|
||||
unsigned ilang() const {return current->id;}
|
||||
/*
|
||||
unsigned ilang() const {return current->id;}
|
||||
const upx_byte *nlang() const {return current->name;}
|
||||
*/
|
||||
};
|
||||
@@ -1191,10 +1203,7 @@ void Resource::check(const res_dir *node,unsigned level)
|
||||
{
|
||||
int ic = node->identr + node->namedentr;
|
||||
if (ic == 0)
|
||||
{
|
||||
//throwCantPack("unsupported resource structure");
|
||||
throwCantPack("empty resource sections are not supported");
|
||||
}
|
||||
return;
|
||||
for (const res_dir_entry *rde = node->entries; --ic >= 0; rde++)
|
||||
if (((rde->child & 0x80000000) == 0) ^ (level == 2))
|
||||
throwCantPack("unsupported resource structure");
|
||||
@@ -1220,10 +1229,14 @@ Resource::upx_rnode *Resource::convert(const void *rnode,upx_rnode *parent,unsig
|
||||
}
|
||||
|
||||
const res_dir *node = (const res_dir *) rnode;
|
||||
int ic = node->identr + node->namedentr;
|
||||
if (ic == 0)
|
||||
return NULL;
|
||||
|
||||
upx_rbranch *branch = new upx_rbranch;
|
||||
branch->name = NULL;
|
||||
branch->parent = parent;
|
||||
int ic = branch->nc = node->identr + node->namedentr;
|
||||
branch->nc = ic;
|
||||
branch->children = new upx_rnode*[ic];
|
||||
branch->data = *node;
|
||||
|
||||
@@ -1290,12 +1303,14 @@ upx_byte *Resource::build()
|
||||
void Resource::destroy(upx_rnode *node,unsigned level)
|
||||
{
|
||||
delete [] node->name; node->name = NULL;
|
||||
if (level == 3)
|
||||
return;
|
||||
upx_rbranch * const branch = (upx_rbranch *) node;
|
||||
for (int ic = branch->nc; --ic >= 0; )
|
||||
destroy(branch->children[ic],level + 1);
|
||||
delete [] branch->children; branch->children = NULL;
|
||||
if (level != 3)
|
||||
{
|
||||
upx_rbranch * const branch = (upx_rbranch *) node;
|
||||
for (int ic = branch->nc; --ic >= 0; )
|
||||
destroy(branch->children[ic],level + 1);
|
||||
delete [] branch->children; branch->children = NULL;
|
||||
}
|
||||
delete node;
|
||||
}
|
||||
|
||||
static void lame_print_unicode(const upx_byte *p)
|
||||
@@ -1365,6 +1380,52 @@ void PackW32Pe::processResources(Resource *res,unsigned newaddr)
|
||||
delete [] p;
|
||||
}
|
||||
|
||||
static bool match(unsigned itype, const unsigned char *ntype,
|
||||
unsigned iname, const unsigned char *nname,
|
||||
const char *keep)
|
||||
{
|
||||
// format of string keep: type1[/name1],type2[/name2], ....
|
||||
// typex and namex can be string or number
|
||||
// hopefully resource names do not have '/' or ',' characters inside
|
||||
|
||||
struct helper
|
||||
{
|
||||
static bool match(unsigned num, const unsigned char *unistr,
|
||||
const char *keep)
|
||||
{
|
||||
if (!unistr)
|
||||
return (unsigned) atoi(keep) == num;
|
||||
|
||||
unsigned ic;
|
||||
for (ic = 0; ic < get_le16(unistr); ic++)
|
||||
if (unistr[2 + ic * 2] != (unsigned char) keep[ic])
|
||||
return false;
|
||||
return keep[ic] == 0 || keep[ic] == ',' || keep[ic] == '/';
|
||||
};
|
||||
};
|
||||
|
||||
// FIXME this comparison is not too exact
|
||||
while (1)
|
||||
{
|
||||
char *delim1 = strchr(keep, '/');
|
||||
char *delim2 = strchr(keep, ',');
|
||||
if (helper::match(itype, ntype, keep))
|
||||
{
|
||||
if (!delim1)
|
||||
return true;
|
||||
if (delim2 && delim2 < delim1)
|
||||
return true;
|
||||
if (helper::match(iname, nname, delim1 + 1))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (delim2 == NULL)
|
||||
break;
|
||||
keep = delim2 + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PackW32Pe::processResources(Resource *res)
|
||||
{
|
||||
const unsigned vaddr = IDADDR(PEDIR_RESOURCE);
|
||||
@@ -1433,6 +1494,10 @@ void PackW32Pe::processResources(Resource *res)
|
||||
do_compress = false; // u"REGISTRY"
|
||||
}
|
||||
|
||||
if (do_compress && opt->win32_pe.keep_resource[0])
|
||||
do_compress ^= match(res->itype(), res->ntype(), res->iname(),
|
||||
res->nname(), opt->win32_pe.keep_resource);
|
||||
|
||||
if (do_compress)
|
||||
{
|
||||
csize += res->size();
|
||||
@@ -1476,6 +1541,53 @@ void PackW32Pe::processResources(Resource *res)
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Load Configuration handling
|
||||
**************************************************************************/
|
||||
|
||||
void PackW32Pe::processLoadConf(Interval *iv) // pass 1
|
||||
{
|
||||
if (IDSIZE(PEDIR_LOADCONF) == 0)
|
||||
return;
|
||||
|
||||
const unsigned lcaddr = IDADDR(PEDIR_LOADCONF);
|
||||
const upx_byte * const loadconf = ibuf + lcaddr;
|
||||
soloadconf = get_le32(loadconf);
|
||||
if (soloadconf == 0)
|
||||
return;
|
||||
if (soloadconf > 256)
|
||||
throwCantPack("size of Load Configuration directory unexpected");
|
||||
|
||||
// if there were relocation entries referring to the load config table
|
||||
// then we need them for the copy of the table too
|
||||
unsigned pos,type;
|
||||
Reloc rel(ibuf + IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC));
|
||||
while (rel.next(pos, type))
|
||||
if (pos >= lcaddr && pos < lcaddr + soloadconf)
|
||||
{
|
||||
iv->add(pos - lcaddr, type);
|
||||
// printf("loadconf reloc detected: %x\n", pos);
|
||||
}
|
||||
|
||||
oloadconf = new upx_byte[soloadconf];
|
||||
memcpy(oloadconf, loadconf, soloadconf);
|
||||
}
|
||||
|
||||
void PackW32Pe::processLoadConf(Reloc *rel, const Interval *iv,
|
||||
unsigned newaddr) // pass2
|
||||
{
|
||||
// now we have the address of the new load config table
|
||||
// so we can create the new relocation entries
|
||||
for (unsigned ic = 0; ic < iv->ivnum; ic++)
|
||||
{
|
||||
rel->add(iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
||||
//printf("loadconf reloc added: %x %d\n",
|
||||
// iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
unsigned PackW32Pe::virta2objnum(unsigned addr,pe_section_t *sect,unsigned objs)
|
||||
{
|
||||
unsigned ic;
|
||||
@@ -1579,7 +1691,7 @@ int PackW32Pe::buildLoader(const Filter *ft)
|
||||
if (sorelocs)
|
||||
{
|
||||
addLoader(soimport == 0 || soimport + cimports != crelocs ? "PERELOC1" : "PERELOC2",
|
||||
"PERELOC3""RELOC320",
|
||||
"PERELOC3,RELOC320",
|
||||
big_relocs ? "REL32BIG" : "",
|
||||
"RELOC32J",
|
||||
NULL
|
||||
@@ -1591,9 +1703,14 @@ int PackW32Pe::buildLoader(const Filter *ft)
|
||||
NULL
|
||||
);
|
||||
}
|
||||
addLoader("PEMAIN20",
|
||||
ih.entry ? "PEDOJUMP" : "PERETURN",
|
||||
"IDENTSTR""UPX1HEAD",
|
||||
if (use_dep_hack)
|
||||
addLoader("PEDEPHAK", NULL);
|
||||
addLoader("PEMAIN20", NULL);
|
||||
if (use_clear_dirty_stack)
|
||||
addLoader(ih.entry ? "PEDOJUMP_CLEARSTACK" : "PERETURN_CLEARSTACK", NULL);
|
||||
addLoader("PEMAIN21", NULL);
|
||||
addLoader(ih.entry ? "PEDOJUMP" : "PERETURN",
|
||||
"IDENTSTR,UPX1HEAD",
|
||||
NULL
|
||||
);
|
||||
return getLoaderSize();
|
||||
@@ -1602,9 +1719,6 @@ int PackW32Pe::buildLoader(const Filter *ft)
|
||||
|
||||
void PackW32Pe::pack(OutputFile *fo)
|
||||
{
|
||||
if (opt->win32_pe.strip_loadconf < 0)
|
||||
opt->win32_pe.strip_loadconf = false;
|
||||
|
||||
const unsigned objs = ih.objects;
|
||||
isection = new pe_section_t[objs];
|
||||
fi->seek(pe_offset+sizeof(ih),SEEK_SET);
|
||||
@@ -1617,12 +1731,12 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
// check the PE header
|
||||
// FIXME: add more checks
|
||||
if (!opt->force && (
|
||||
ih.cpu < 0x14c || ih.cpu > 0x150
|
||||
|| ih.opthdrsize != 0xE0
|
||||
|| (ih.flags & EXECUTABLE) == 0
|
||||
(ih.cpu < 0x14c || ih.cpu > 0x150)
|
||||
|| (ih.opthdrsize != 0xe0)
|
||||
|| ((ih.flags & EXECUTABLE) == 0)
|
||||
|| (ih.subsystem != 2 && ih.subsystem != 3 && ih.subsystem != 1)
|
||||
|| (ih.entry == 0 && !isdll)
|
||||
|| ih.ddirsentries != 16
|
||||
|| (ih.ddirsentries != 16)
|
||||
|| IDSIZE(PEDIR_EXCEPTION) // is this used on i386?
|
||||
// || IDSIZE(PEDIR_COPYRIGHT)
|
||||
))
|
||||
@@ -1633,10 +1747,6 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
if (IDSIZE(PEDIR_COMRT))
|
||||
throwCantPack(".NET files (win32/net) are not yet supported");
|
||||
|
||||
// Structured Exception Handling
|
||||
if (!opt->win32_pe.strip_loadconf && IDSIZE(PEDIR_LOADCONF))
|
||||
throwCantPack("Structured Exception Handling present (try --strip-loadconf)");
|
||||
|
||||
if (isdll)
|
||||
opt->win32_pe.strip_relocs = false;
|
||||
else if (opt->win32_pe.strip_relocs < 0)
|
||||
@@ -1649,7 +1759,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
|
||||
if (memcmp(isection[0].name,"UPX",3) == 0)
|
||||
throwAlreadyPackedByUPX();
|
||||
if (!opt->force && (IDSIZE(15) || ih.entry > isection[1].vaddr))
|
||||
if (!opt->force && IDSIZE(15))
|
||||
throwCantPack("file is possibly packed/protected (try --force)");
|
||||
if (ih.entry && ih.entry < rvamin)
|
||||
throwCantPack("run a virus scanner on this file!");
|
||||
@@ -1660,7 +1770,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
|
||||
handleStub(fi,fo,pe_offset);
|
||||
const unsigned usize = ih.imagesize;
|
||||
const unsigned xtrasize = 65536+IDSIZE(PEDIR_IMPORT)+IDSIZE(PEDIR_BOUNDIM)+IDSIZE(PEDIR_IAT)+IDSIZE(PEDIR_DELAYIMP)+IDSIZE(PEDIR_RELOC);
|
||||
const unsigned xtrasize = UPX_MAX(ih.datasize, 65536u) + IDSIZE(PEDIR_IMPORT) + IDSIZE(PEDIR_BOUNDIM) + IDSIZE(PEDIR_IAT) + IDSIZE(PEDIR_DELAYIMP) + IDSIZE(PEDIR_RELOC);
|
||||
ibuf.alloc(usize + xtrasize);
|
||||
|
||||
// BOUND IMPORT support. FIXME: is this ok?
|
||||
@@ -1697,6 +1807,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
jc = isection[ic].vsize;
|
||||
if (isection[ic].vsize == 0) // hack for some tricky programs - may this break other progs?
|
||||
jc = isection[ic].vsize = isection[ic].size;
|
||||
if (isection[ic].vaddr + jc > ibuf.getSize())
|
||||
throwInternalError("buffer too small 1");
|
||||
fi->readx(ibuf + isection[ic].vaddr,jc);
|
||||
jc += isection[ic].rawdataptr;
|
||||
}
|
||||
@@ -1720,12 +1832,14 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
|
||||
Resource res;
|
||||
Interval tlsiv(ibuf);
|
||||
Interval loadconfiv(ibuf);
|
||||
Export xport((char*)(unsigned char*)ibuf);
|
||||
|
||||
const unsigned dllstrings = processImports();
|
||||
processTls(&tlsiv); // call before processRelocs!!
|
||||
processResources(&res);
|
||||
processExports(&xport);
|
||||
processLoadConf(&loadconfiv);
|
||||
processRelocs();
|
||||
|
||||
//OutputFile::dump("x1", ibuf, usize);
|
||||
@@ -1748,6 +1862,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
unsigned newvsize = (isection[objs-1].vaddr + isection[objs-1].vsize + oam1) &~ oam1;
|
||||
|
||||
//fprintf(stderr,"newvsize=%x objs=%d\n",newvsize,objs);
|
||||
if (newvsize + soimport + sorelocs > ibuf.getSize())
|
||||
throwInternalError("buffer too small 2");
|
||||
memcpy(ibuf+newvsize,oimport,soimport);
|
||||
memcpy(ibuf+newvsize+soimport,orelocs,sorelocs);
|
||||
|
||||
@@ -1794,6 +1910,14 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
ft.addvalue = ih.codebase - rvamin;
|
||||
// compress
|
||||
int strategy = allow_filter ? 0 : -3;
|
||||
|
||||
// disable filters for files with broken headers
|
||||
if (ih.codebase + ih.codesize > ph.u_len)
|
||||
{
|
||||
ft.buf_len = 1;
|
||||
strategy = -3;
|
||||
}
|
||||
|
||||
compressWithFilters(&ft, 2048, strategy,
|
||||
NULL, 0, 0, ih.codebase, rvamin);
|
||||
// info: see buildLoader()
|
||||
@@ -1846,6 +1970,45 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
unsigned jmp_pos = find_le32(loader,codesize + 4,get_le32("JMPO"));
|
||||
patch_le32(loader,codesize + 4,"JMPO",ih.entry - upxsection - jmp_pos - 4);
|
||||
}
|
||||
if (use_dep_hack)
|
||||
{
|
||||
// This works around a "protection" introduced in MSVCRT80, which
|
||||
// works like this:
|
||||
// When the compiler detects that it would link in some code from its
|
||||
// C runtime library which references some data in a read only
|
||||
// section then it compiles in a runtime check whether that data is
|
||||
// still in a read only section by looking at the pe header of the
|
||||
// file. If this check fails the runtime does "interesting" things
|
||||
// like not running the floating point initialization code - the result
|
||||
// is an R6002 runtime error.
|
||||
// These supposed to be read only addresses are covered by the sections
|
||||
// UPX0 & UPX1 in the compressed files, so we have to patch the PE header
|
||||
// in the memory. And the page on which the PE header is stored is read
|
||||
// only so we must make it rw, fix the flags (i.e. clear
|
||||
// PEFL_WRITE of osection[x].flags), and make it ro again.
|
||||
|
||||
// rva of the most significant byte of member "flags" in section "UPX0"
|
||||
const unsigned swri = pe_offset + sizeof(oh) + sizeof(pe_section_t) - 1;
|
||||
#if 0
|
||||
if (swri >= 0x1000)
|
||||
throwCantPack("swri >= 0x1000! Send a bug report please!");
|
||||
patch_le32(loader, codesize, "SWRI", swri);
|
||||
patch_le32(loader, codesize, "IMGL", 0x1000); // one page
|
||||
patch_le32(loader, codesize, "IMGB", 0u - rvamin);
|
||||
#else
|
||||
// make sure we only touch the minimum number of pages
|
||||
const unsigned addr = 0u - rvamin + swri;
|
||||
patch_le32(loader, codesize, "SWRI", addr & 0xfff); // page offset
|
||||
// check whether osection[0].flags and osection[1].flags
|
||||
// are on the same page
|
||||
if ((addr & 0xfff) + 0x28 >= 0x1000)
|
||||
patch_le32(loader, codesize, "IMGL", 0x2000); // two pages
|
||||
else
|
||||
patch_le32(loader, codesize, "IMGL", 0x1000); // one page
|
||||
patch_le32(loader, codesize, "IMGB", addr &~ 0xfff); // page mask
|
||||
#endif
|
||||
patch_le32(loader, codesize, "VPRO", myimport + get_le32(oimpdlls + 16) + 8);
|
||||
}
|
||||
if (big_relocs & 6)
|
||||
patch_le32(loader,codesize,"DELT", 0u - (unsigned) ih.imagebase - rvamin);
|
||||
if (sorelocs && (soimport == 0 || soimport + cimports != crelocs))
|
||||
@@ -1853,7 +2016,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
if (soimport)
|
||||
{
|
||||
if (!isdll)
|
||||
patch_le32(loader,codesize,"EXIT",myimport + get_le32(oimpdlls + 16) + 8);
|
||||
patch_le32(loader,codesize,"EXIT",myimport + get_le32(oimpdlls + 16) + 12);
|
||||
patch_le32(loader,codesize,"GETP",myimport + get_le32(oimpdlls + 16) + 4);
|
||||
if (kernel32ordinal)
|
||||
patch_le32(loader,codesize,"K32O",myimport);
|
||||
@@ -1911,12 +2074,6 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
ODADDR(PEDIR_BOUNDIM) = 0;
|
||||
ODSIZE(PEDIR_BOUNDIM) = 0;
|
||||
|
||||
if (opt->win32_pe.strip_loadconf)
|
||||
{
|
||||
ODADDR(PEDIR_LOADCONF) = 0;
|
||||
ODSIZE(PEDIR_LOADCONF) = 0;
|
||||
}
|
||||
|
||||
// tls is put into section 1
|
||||
|
||||
ic = s1addr + s1size - sotls;
|
||||
@@ -1933,10 +2090,12 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
ODADDR(PEDIR_RESOURCE) = soresources ? ic : 0;
|
||||
ODSIZE(PEDIR_RESOURCE) = soresources;
|
||||
ic += soresources;
|
||||
|
||||
processImports(ic);
|
||||
ODADDR(PEDIR_IMPORT) = ic;
|
||||
ODSIZE(PEDIR_IMPORT) = soimpdlls;
|
||||
ic += soimpdlls;
|
||||
|
||||
processExports(&xport,ic);
|
||||
ODADDR(PEDIR_EXPORT) = soexport ? ic : 0;
|
||||
ODSIZE(PEDIR_EXPORT) = soexport;
|
||||
@@ -1946,13 +2105,20 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT);
|
||||
}
|
||||
ic += soexport;
|
||||
|
||||
processLoadConf(&rel, &loadconfiv, ic);
|
||||
ODADDR(PEDIR_LOADCONF) = soloadconf ? ic : 0;
|
||||
ODSIZE(PEDIR_LOADCONF) = soloadconf;
|
||||
ic += soloadconf;
|
||||
|
||||
processRelocs(&rel);
|
||||
ODADDR(PEDIR_RELOC) = soxrelocs ? ic : 0;
|
||||
ODSIZE(PEDIR_RELOC) = soxrelocs;
|
||||
ic += soxrelocs;
|
||||
|
||||
// this is computed here, because soxrelocs changes some lines above
|
||||
const unsigned ncsize = soresources + soimpdlls + soexport + soxrelocs;
|
||||
const unsigned ncsize = soresources + soimpdlls + soexport + soloadconf
|
||||
+ soxrelocs;
|
||||
ic = oh.filealign - 1;
|
||||
|
||||
// this one is tricky: it seems windoze touches 4 bytes after
|
||||
@@ -2009,6 +2175,9 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
// set_le32(ibuf + ic,get_le32("UPX "));
|
||||
ibuf.clear(0, oh.filealign);
|
||||
|
||||
info("Image size change: %u -> %u kBytes",
|
||||
ih.imagesize / 1024, oh.imagesize / 1024);
|
||||
|
||||
infoHeader("[Writing compressed file]");
|
||||
|
||||
// write loader + compressed file
|
||||
@@ -2026,6 +2195,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
fo->write(obuf,clen);
|
||||
infoWriting("compressed data", clen);
|
||||
fo->write(loader,codesize);
|
||||
if (opt->debug.dump_stub_loader)
|
||||
OutputFile::dump(opt->debug.dump_stub_loader, loader, codesize);
|
||||
if ((ic = fo->getBytesWritten() & 3) != 0)
|
||||
fo->write(ibuf,4 - ic);
|
||||
fo->write(otls,sotls);
|
||||
@@ -2034,6 +2205,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
fo->write(oresources,soresources);
|
||||
fo->write(oimpdlls,soimpdlls);
|
||||
fo->write(oexport,soexport);
|
||||
fo->write(oloadconf, soloadconf);
|
||||
fo->write(oxrelocs,soxrelocs);
|
||||
|
||||
if ((ic = fo->getBytesWritten() & (oh.filealign-1)) != 0)
|
||||
@@ -2050,6 +2222,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
printf("%-13s: imports : %8ld bytes\n", getName(), (long) soimpdlls);
|
||||
printf("%-13s: exports : %8ld bytes\n", getName(), (long) soexport);
|
||||
printf("%-13s: relocs : %8ld bytes\n", getName(), (long) soxrelocs);
|
||||
printf("%-13s: loadconf : %8ld bytes\n", getName(), (long) soloadconf);
|
||||
#endif
|
||||
|
||||
// verify
|
||||
@@ -2322,7 +2495,7 @@ void PackW32Pe::rebuildTls()
|
||||
|
||||
void PackW32Pe::rebuildResources(upx_byte *& extrainfo)
|
||||
{
|
||||
if (ODSIZE(PEDIR_RESOURCE) == 0)
|
||||
if (ODSIZE(PEDIR_RESOURCE) == 0 || IDSIZE(PEDIR_RESOURCE) == 0)
|
||||
return;
|
||||
|
||||
icondir_count = get_le16(extrainfo);
|
||||
|
||||
+11
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -119,6 +119,14 @@ protected:
|
||||
unsigned crelocs; // rva of preprocessed fixups
|
||||
int big_relocs;
|
||||
|
||||
void processLoadConf(PackW32Pe_Reloc *, const PackW32Pe_Interval *, unsigned);
|
||||
void processLoadConf(PackW32Pe_Interval *);
|
||||
upx_byte *oloadconf;
|
||||
unsigned soloadconf;
|
||||
|
||||
bool use_dep_hack;
|
||||
bool use_clear_dirty_stack;
|
||||
|
||||
struct pe_header_t
|
||||
{
|
||||
// 0x0
|
||||
|
||||
+4
-4
@@ -48,8 +48,8 @@ static const
|
||||
#define LE_STUB_EDI (1)
|
||||
|
||||
#ifdef TESTING
|
||||
# define dputc(x,y) do { if (opt->debug) putc(x,y); } while (0)
|
||||
# define Opt_debug opt->debug
|
||||
# define dputc(x,y) do { if (opt->debug.debug_level) putc(x,y); } while (0)
|
||||
# define Opt_debug opt->debug.debug_level
|
||||
#else
|
||||
# define dputc(x,y) ((void)0)
|
||||
# define Opt_debug 0
|
||||
@@ -85,7 +85,7 @@ int PackWcle::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
addLoader("IDENTSTR""WCLEMAIN""UPX1HEAD""WCLECUTP""+0000000",
|
||||
addLoader("IDENTSTR,WCLEMAIN,UPX1HEAD,WCLECUTP,+0000000",
|
||||
getDecompressor(),
|
||||
"WCLEMAI2",
|
||||
NULL
|
||||
@@ -99,7 +99,7 @@ int PackWcle::buildLoader(const Filter *ft)
|
||||
#if 1
|
||||
// FIXME: if (has_relocation)
|
||||
{
|
||||
addLoader("WCRELOC1""RELOC320",
|
||||
addLoader("WCRELOC1,RELOC320",
|
||||
big_relocs ? "REL32BIG" : "",
|
||||
"RELOC32J",
|
||||
NULL
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+209
-51
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2005 Laszlo Molnar
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const
|
||||
**************************************************************************/
|
||||
|
||||
void Packer::decompress(const upx_bytep in, upx_bytep out,
|
||||
bool verify_checksum)
|
||||
bool verify_checksum, Filter *ft)
|
||||
{
|
||||
unsigned adler;
|
||||
|
||||
@@ -316,6 +316,9 @@ void Packer::decompress(const upx_bytep in, upx_bytep out,
|
||||
// verify checksum of decompressed data
|
||||
if (verify_checksum)
|
||||
{
|
||||
if (ft) {
|
||||
ft->unfilter(out, ph.u_len);
|
||||
}
|
||||
adler = upx_adler32(out, ph.u_len, ph.saved_u_adler);
|
||||
if (adler != ph.u_adler)
|
||||
throwChecksumError();
|
||||
@@ -339,9 +342,9 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
||||
return false;
|
||||
|
||||
assert((int)overlap_overhead >= 0);
|
||||
// Because we are not using the asm_fast decompressor here
|
||||
// we must account for extra 3 bytes or else we may fail
|
||||
// at runtime decompression.
|
||||
// Because upx_test_overlap() does not use the asm_fast decompressor
|
||||
// we must account for extra 3 bytes that asm_fast does use,
|
||||
// or else we may fail at runtime decompression.
|
||||
if (overlap_overhead <= 4 + 3) // don't waste time here
|
||||
return false;
|
||||
overlap_overhead -= 3;
|
||||
@@ -355,7 +358,7 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
||||
}
|
||||
|
||||
|
||||
void Packer::verifyOverlappingDecompression()
|
||||
void Packer::verifyOverlappingDecompression(Filter *ft)
|
||||
{
|
||||
assert(ph.c_len < ph.u_len);
|
||||
assert((int)ph.overlap_overhead > 0);
|
||||
@@ -381,7 +384,7 @@ void Packer::verifyOverlappingDecompression()
|
||||
if (offset + ph.c_len > obuf.getSize())
|
||||
return;
|
||||
memmove(obuf + offset, obuf, ph.c_len);
|
||||
decompress(obuf + offset, obuf, true);
|
||||
decompress(obuf + offset, obuf, true, ft);
|
||||
obuf.checkState();
|
||||
#endif /* !UNUPX */
|
||||
}
|
||||
@@ -812,7 +815,26 @@ int Packer::patchVersion(void *b, int blen)
|
||||
checkPatch(b, blen, boff, 14);
|
||||
|
||||
unsigned char *p = (unsigned char *)b + boff + 9;
|
||||
memcpy(p, UPX_VERSION_STRING4, 4);
|
||||
if (opt->debug.fake_stub_version[0])
|
||||
memcpy(p, opt->debug.fake_stub_version, 4);
|
||||
else
|
||||
memcpy(p, UPX_VERSION_STRING4, 4);
|
||||
|
||||
return boff;
|
||||
}
|
||||
|
||||
|
||||
// patch year into stub/ident_[ns].ash
|
||||
int Packer::patchVersionYear(void *b, int blen)
|
||||
{
|
||||
int boff = find(b, blen, " 1996-UPXY ", 11);
|
||||
checkPatch(b, blen, boff, 11);
|
||||
|
||||
unsigned char *p = (unsigned char *)b + boff + 6;
|
||||
if (opt->debug.fake_stub_year[0])
|
||||
memcpy(p, opt->debug.fake_stub_year, 4);
|
||||
else
|
||||
memcpy(p, UPX_VERSION_YEAR, 4);
|
||||
|
||||
return boff;
|
||||
}
|
||||
@@ -920,7 +942,7 @@ unsigned Packer::unoptimizeReloc32(upx_byte **in, upx_byte *image,
|
||||
|
||||
bool Packer::isValidCompressionMethod(int method)
|
||||
{
|
||||
return (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16);
|
||||
return (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16);
|
||||
}
|
||||
|
||||
|
||||
@@ -929,6 +951,7 @@ const int *Packer::getDefaultCompressionMethods_8(int method, int level, int sma
|
||||
static const int m_nrv2b[] = { M_NRV2B_8, M_NRV2D_8, M_NRV2E_8, -1 };
|
||||
static const int m_nrv2d[] = { M_NRV2D_8, M_NRV2B_8, M_NRV2E_8, -1 };
|
||||
static const int m_nrv2e[] = { M_NRV2E_8, M_NRV2B_8, M_NRV2D_8, -1 };
|
||||
static const int m_cl1b[] = { M_CL1B_8, -1 };
|
||||
|
||||
if (small < 0)
|
||||
small = file_size <= 512*1024;
|
||||
@@ -938,6 +961,8 @@ const int *Packer::getDefaultCompressionMethods_8(int method, int level, int sma
|
||||
return m_nrv2d;
|
||||
if (M_IS_NRV2E(method))
|
||||
return m_nrv2e;
|
||||
if (M_IS_CL1B(method))
|
||||
return m_cl1b;
|
||||
if (level == 1 || small)
|
||||
return m_nrv2b;
|
||||
return m_nrv2e;
|
||||
@@ -949,6 +974,7 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
|
||||
static const int m_nrv2b[] = { M_NRV2B_LE32, M_NRV2D_LE32, M_NRV2E_LE32, -1 };
|
||||
static const int m_nrv2d[] = { M_NRV2D_LE32, M_NRV2B_LE32, M_NRV2E_LE32, -1 };
|
||||
static const int m_nrv2e[] = { M_NRV2E_LE32, M_NRV2B_LE32, M_NRV2D_LE32, -1 };
|
||||
static const int m_cl1b[] = { M_CL1B_LE32, -1 };
|
||||
|
||||
if (small < 0)
|
||||
small = file_size <= 512*1024;
|
||||
@@ -958,6 +984,8 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
|
||||
return m_nrv2d;
|
||||
if (M_IS_NRV2E(method))
|
||||
return m_nrv2e;
|
||||
if (M_IS_CL1B(method))
|
||||
return m_cl1b;
|
||||
if (level == 1 || small)
|
||||
return m_nrv2b;
|
||||
return m_nrv2e;
|
||||
@@ -970,21 +998,43 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
|
||||
|
||||
char const *Packer::getIdentstr(unsigned *size, int small)
|
||||
{
|
||||
static const char identbig[] =
|
||||
static char identbig[] =
|
||||
"\n\0"
|
||||
"$Info: "
|
||||
"This file is packed with the UPX executable packer http://upx.sf.net $"
|
||||
"\n\0"
|
||||
"$Id: UPX "
|
||||
UPX_VERSION_STRING4
|
||||
" Copyright (C) 1996-2005 the UPX Team. All Rights Reserved. $"
|
||||
" Copyright (C) 1996-" UPX_VERSION_YEAR " the UPX Team. All Rights Reserved. $"
|
||||
"\n";
|
||||
static const char identsmall[] =
|
||||
static char identsmall[] =
|
||||
"\n"
|
||||
"$Id: UPX "
|
||||
"(C) 1996-2005 the UPX Team. All Rights Reserved. http://upx.sf.net $"
|
||||
"(C) 1996-" UPX_VERSION_YEAR " the UPX Team. All Rights Reserved. http://upx.sf.net $"
|
||||
"\n";
|
||||
static const char identtiny[] = UPX_VERSION_STRING4;
|
||||
static char identtiny[] = UPX_VERSION_STRING4;
|
||||
|
||||
static int done;
|
||||
if (!done && (opt->debug.fake_stub_version[0] || opt->debug.fake_stub_year[0]))
|
||||
{
|
||||
struct strinfo_t { char *s; int size; };
|
||||
static const strinfo_t strlist[] = {
|
||||
{ identbig, (int)sizeof(identbig) },
|
||||
{ identsmall, (int)sizeof(identsmall) },
|
||||
{ identtiny, (int)sizeof(identtiny) },
|
||||
{ NULL, 0 } };
|
||||
const strinfo_t* iter;
|
||||
|
||||
for (iter = strlist; iter->s; ++iter)
|
||||
{
|
||||
if (opt->debug.fake_stub_version[0])
|
||||
mem_replace(iter->s, iter->size, UPX_VERSION_STRING4, 4, opt->debug.fake_stub_version);
|
||||
if (opt->debug.fake_stub_year[0])
|
||||
mem_replace(iter->s, iter->size, UPX_VERSION_YEAR, 4, opt->debug.fake_stub_year);
|
||||
}
|
||||
done = 1;
|
||||
}
|
||||
|
||||
|
||||
if (small < 0)
|
||||
small = opt->small;
|
||||
@@ -1005,6 +1055,14 @@ char const *Packer::getIdentstr(unsigned *size, int small)
|
||||
}
|
||||
}
|
||||
|
||||
void Packer::createLinker(const void *pdata, int plen, int pinfo)
|
||||
{
|
||||
if (getFormat() < 128)
|
||||
linker = new Linker(pdata, plen, pinfo); // little endian
|
||||
else
|
||||
linker = new BeLinker(pdata, plen, pinfo); // big endian
|
||||
}
|
||||
|
||||
void Packer::initLoader(const void *pdata, int plen, int pinfo, int small)
|
||||
{
|
||||
if (pinfo < 0)
|
||||
@@ -1014,10 +1072,7 @@ void Packer::initLoader(const void *pdata, int plen, int pinfo, int small)
|
||||
}
|
||||
|
||||
delete linker; linker = NULL;
|
||||
if (getFormat() < 128)
|
||||
linker = new Linker(pdata, plen, pinfo); // little endian
|
||||
else
|
||||
linker = new BeLinker(pdata, plen, pinfo); // big endian
|
||||
createLinker(pdata, plen, pinfo);
|
||||
|
||||
unsigned size;
|
||||
char const * const ident = getIdentstr(&size, small);
|
||||
@@ -1027,13 +1082,15 @@ void Packer::initLoader(const void *pdata, int plen, int pinfo, int small)
|
||||
|
||||
void __acc_cdecl_va Packer::addLoader(const char *s, ...)
|
||||
{
|
||||
const char *p;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, s);
|
||||
linker->addSection(s);
|
||||
while((p = va_arg(ap, const char *)) != NULL)
|
||||
linker->addSection(p);
|
||||
while (s != NULL)
|
||||
{
|
||||
if (*s)
|
||||
linker->addSection(s);
|
||||
s = va_arg(ap, const char *);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -1086,29 +1143,87 @@ int Packer::getLoaderSize() const
|
||||
const char *Packer::getDecompressor() const
|
||||
{
|
||||
static const char nrv2b_le32_small[] =
|
||||
"N2BSMA10""N2BDEC10""N2BSMA20""N2BDEC20""N2BSMA30"
|
||||
"N2BDEC30""N2BSMA40""N2BSMA50""N2BDEC50""N2BSMA60"
|
||||
"N2BSMA10,N2BDEC10,N2BSMA20,N2BDEC20,N2BSMA30,"
|
||||
"N2BDEC30,N2BSMA40,N2BSMA50,N2BDEC50,N2BSMA60,"
|
||||
"N2BDEC60";
|
||||
static const char nrv2b_le32_fast[] =
|
||||
"N2BFAS10""+80CXXXX""N2BFAS11""N2BDEC10""N2BFAS20"
|
||||
"N2BDEC20""N2BFAS30""N2BDEC30""N2BFAS40""N2BFAS50"
|
||||
"N2BDEC50""N2BFAS60""+40CXXXX""N2BFAS61""N2BDEC60";
|
||||
"N2BFAS10,+80CXXXX,N2BFAS11,N2BDEC10,N2BFAS20,"
|
||||
"N2BDEC20,N2BFAS30,N2BDEC30,N2BFAS40,N2BFAS50,"
|
||||
"N2BDEC50,N2BFAS60,+40CXXXX,N2BFAS61,N2BDEC60";
|
||||
static const char nrv2d_le32_small[] =
|
||||
"N2DSMA10""N2DDEC10""N2DSMA20""N2DDEC20""N2DSMA30"
|
||||
"N2DDEC30""N2DSMA40""N2DSMA50""N2DDEC50""N2DSMA60"
|
||||
"N2DSMA10,N2DDEC10,N2DSMA20,N2DDEC20,N2DSMA30,"
|
||||
"N2DDEC30,N2DSMA40,N2DSMA50,N2DDEC50,N2DSMA60,"
|
||||
"N2DDEC60";
|
||||
static const char nrv2d_le32_fast[] =
|
||||
"N2DFAS10""+80CXXXX""N2DFAS11""N2DDEC10""N2DFAS20"
|
||||
"N2DDEC20""N2DFAS30""N2DDEC30""N2DFAS40""N2DFAS50"
|
||||
"N2DDEC50""N2DFAS60""+40CXXXX""N2DFAS61""N2DDEC60";
|
||||
"N2DFAS10,+80CXXXX,N2DFAS11,N2DDEC10,N2DFAS20,"
|
||||
"N2DDEC20,N2DFAS30,N2DDEC30,N2DFAS40,N2DFAS50,"
|
||||
"N2DDEC50,N2DFAS60,+40CXXXX,N2DFAS61,N2DDEC60";
|
||||
static const char nrv2e_le32_small[] =
|
||||
"N2ESMA10""N2EDEC10""N2ESMA20""N2EDEC20""N2ESMA30"
|
||||
"N2EDEC30""N2ESMA40""N2ESMA50""N2EDEC50""N2ESMA60"
|
||||
"N2ESMA10,N2EDEC10,N2ESMA20,N2EDEC20,N2ESMA30,"
|
||||
"N2EDEC30,N2ESMA40,N2ESMA50,N2EDEC50,N2ESMA60,"
|
||||
"N2EDEC60";
|
||||
static const char nrv2e_le32_fast[] =
|
||||
"N2EFAS10""+80CXXXX""N2EFAS11""N2EDEC10""N2EFAS20"
|
||||
"N2EDEC20""N2EFAS30""N2EDEC30""N2EFAS40""N2EFAS50"
|
||||
"N2EDEC50""N2EFAS60""+40CXXXX""N2EFAS61""N2EDEC60";
|
||||
"N2EFAS10,+80CXXXX,N2EFAS11,N2EDEC10,N2EFAS20,"
|
||||
"N2EDEC20,N2EFAS30,N2EDEC30,N2EFAS40,N2EFAS50,"
|
||||
"N2EDEC50,N2EFAS60,+40CXXXX,N2EFAS61,N2EDEC60";
|
||||
static const char cl1b_le32_small[] =
|
||||
"CL1ENTER,CL1SMA10,CL1RLOAD,"
|
||||
"CL1WID01,CL1SMA1B,"
|
||||
"CL1WID02,CL1SMA1B,"
|
||||
"CL1WID03,CL1SMA1B,"
|
||||
"CL1WID04,CL1SMA1B,"
|
||||
"CL1WID05,CL1SMA1B,"
|
||||
"CL1WID06,CL1SMA1B,"
|
||||
"CL1WID07,CL1SMA1B,"
|
||||
"CL1WID08,CL1SMA1B,"
|
||||
"CL1WID09,CL1SMA1B,"
|
||||
"CL1WID10,"
|
||||
"CL1START,"
|
||||
"CL1TOP00,CL1SMA1B,"
|
||||
"CL1TOP01,CL1SMA1B,"
|
||||
"CL1TOP02,CL1SMA1B,"
|
||||
"CL1TOP03,CL1SMA1B,"
|
||||
"CL1TOP04,CL1SMA1B,"
|
||||
"CL1TOP05,CL1SMA1B,"
|
||||
"CL1TOP06,CL1SMA1B,"
|
||||
"CL1TOP07,CL1SMA1B,"
|
||||
"CL1OFF01,CL1SMA1B,"
|
||||
"CL1OFF02,CL1SMA1B,"
|
||||
"CL1OFF03,CL1SMA1B,"
|
||||
"CL1OFF04,"
|
||||
"CL1LEN00,CL1SMA1B,"
|
||||
"CL1LEN01,CL1SMA1B,"
|
||||
"CL1LEN02,"
|
||||
"CL1COPY0";
|
||||
static const char cl1b_le32_fast[] =
|
||||
"CL1ENTER," "CL1RLOAD,"
|
||||
"CL1WID01,CL1FAS1B,"
|
||||
"CL1WID02,CL1FAS1B,"
|
||||
"CL1WID03,CL1FAS1B,"
|
||||
"CL1WID04,CL1FAS1B,"
|
||||
"CL1WID05,CL1FAS1B,"
|
||||
"CL1WID06,CL1FAS1B,"
|
||||
"CL1WID07,CL1FAS1B,"
|
||||
"CL1WID08,CL1FAS1B,"
|
||||
"CL1WID09,CL1FAS1B,"
|
||||
"CL1WID10,"
|
||||
"CL1START,"
|
||||
"CL1TOP00,CL1FAS1B,"
|
||||
"CL1TOP01,CL1FAS1B,"
|
||||
"CL1TOP02,CL1FAS1B,"
|
||||
"CL1TOP03,CL1FAS1B,"
|
||||
"CL1TOP04,CL1FAS1B,"
|
||||
"CL1TOP05,CL1FAS1B,"
|
||||
"CL1TOP06,CL1FAS1B,"
|
||||
"CL1TOP07,CL1FAS1B,"
|
||||
"CL1OFF01,CL1FAS1B,"
|
||||
"CL1OFF02,CL1FAS1B,"
|
||||
"CL1OFF03,CL1FAS1B,"
|
||||
"CL1OFF04,"
|
||||
"CL1LEN00,CL1FAS1B,"
|
||||
"CL1LEN01,CL1FAS1B,"
|
||||
"CL1LEN02,"
|
||||
"CL1COPY0";
|
||||
|
||||
if (ph.method == M_NRV2B_LE32)
|
||||
return opt->small ? nrv2b_le32_small : nrv2b_le32_fast;
|
||||
@@ -1116,6 +1231,8 @@ const char *Packer::getDecompressor() const
|
||||
return opt->small ? nrv2d_le32_small : nrv2d_le32_fast;
|
||||
if (ph.method == M_NRV2E_LE32)
|
||||
return opt->small ? nrv2e_le32_small : nrv2e_le32_fast;
|
||||
if (ph.method == M_CL1B_LE32)
|
||||
return opt->small ? cl1b_le32_small : cl1b_le32_fast;
|
||||
throwInternalError("bad decompressor");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1149,13 +1266,32 @@ const char *Packer::getDecompressor() const
|
||||
// executable formats.
|
||||
//
|
||||
// It will replace the tryFilters() / compress() call sequence.
|
||||
|
||||
// 2006-02-15: hdr_buf and hdr_u_len are default empty input "header" array
|
||||
// to fix a 2-pass problem with Elf headers. As of today there can be
|
||||
// only one decompression method per executable output file, and that method
|
||||
// is the one that gives best compression for .text and loader. However,
|
||||
// the Elf headers precede .text in the output file, and are written first.
|
||||
// "--brute" compression often compressed the Elf headers using nrv2b
|
||||
// but the .text (and loader) with nrv2e. This often resulted in SIGSEGV
|
||||
// during decompression.
|
||||
// The workaround is for hdr_buf and hdr_u_len to describe the Elf headers
|
||||
// (typically less than 512 bytes) when .text is passed in, and include
|
||||
// them in the calculation of shortest output. Then the result
|
||||
// this->ph.method will say which [single] method to use for everthing.
|
||||
// The Elf headers are never filtered. They are short enough (< 512 bytes)
|
||||
// that compressing them more than once per method (once here when choosing,
|
||||
// once again just before writing [because compressWithFilters discards])
|
||||
// is OK because of the simplicity of not having two output arrays.
|
||||
**************************************************************************/
|
||||
|
||||
void Packer::compressWithFilters(Filter *parm_ft,
|
||||
const unsigned overlap_range,
|
||||
int strategy, const int *parm_filters,
|
||||
unsigned max_offset, unsigned max_match,
|
||||
unsigned filter_off, unsigned compress_buf_off)
|
||||
unsigned filter_off, unsigned compress_buf_off,
|
||||
unsigned char *hdr_buf,
|
||||
unsigned hdr_u_len)
|
||||
{
|
||||
const int *f;
|
||||
//
|
||||
@@ -1171,6 +1307,7 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
best_ph.c_len = orig_ph.u_len;
|
||||
best_ph.overlap_overhead = 0;
|
||||
unsigned best_ph_lsize = 0;
|
||||
unsigned best_hdr_c_len = 0;
|
||||
|
||||
// preconditions
|
||||
assert(orig_ph.filter == 0);
|
||||
@@ -1250,11 +1387,11 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
}
|
||||
assert(nmethods > 0);
|
||||
|
||||
// update total_passes
|
||||
// update total_passes; previous (0 < ui_total_passes) means incremental
|
||||
if (strategy < 0)
|
||||
ui_total_passes += 1 * nmethods;
|
||||
ui_total_passes += 1 * nmethods - (0 < ui_total_passes);
|
||||
else
|
||||
ui_total_passes += nfilters * nmethods;
|
||||
ui_total_passes += nfilters * nmethods - (0 < ui_total_passes);
|
||||
|
||||
// Working buffer for compressed data. Don't waste memory.
|
||||
MemBuffer *otemp = &obuf;
|
||||
@@ -1264,6 +1401,23 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
int nfilters_success = 0;
|
||||
for (int m = 0; m < nmethods; m++) // for all methods
|
||||
{
|
||||
unsigned hdr_c_len = 0;
|
||||
if (hdr_buf && hdr_u_len)
|
||||
{
|
||||
unsigned result[16];
|
||||
upx_compress_config_t conf;
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
if (0 < m && otemp == &obuf) { // do not overwrite obuf
|
||||
otemp_buf.allocForCompression(compress_buf_len);
|
||||
otemp = &otemp_buf;
|
||||
}
|
||||
int r = upx_compress(hdr_buf, hdr_u_len, *otemp, &hdr_c_len,
|
||||
0, methods[m], 10, &conf, result);
|
||||
if (r != UPX_E_OK)
|
||||
throwInternalError("header compression failed");
|
||||
if (hdr_c_len >= hdr_u_len)
|
||||
throwInternalError("header compression size increase");
|
||||
}
|
||||
for (int i = 0; i < nfilters; i++) // for all filters
|
||||
{
|
||||
ibuf.checkState();
|
||||
@@ -1272,6 +1426,7 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
ph = orig_ph;
|
||||
ph.method = methods[m];
|
||||
ph.filter = filters[i];
|
||||
ph.overlap_overhead = 0;
|
||||
// get fresh filter
|
||||
Filter ft = orig_ft;
|
||||
ft.init(ph.filter, orig_ft.addvalue);
|
||||
@@ -1312,26 +1467,27 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
if (compress(ibuf + compress_buf_off, *otemp, max_offset, max_match))
|
||||
{
|
||||
unsigned lsize = 0;
|
||||
if (ph.c_len + lsize < best_ph.c_len + best_ph_lsize)
|
||||
if (ph.c_len + lsize + hdr_c_len <= best_ph.c_len + best_ph_lsize + best_hdr_c_len)
|
||||
{
|
||||
// get results
|
||||
ph.overlap_overhead = findOverlapOverhead(*otemp, overlap_range);
|
||||
lsize = buildLoader(&ft);
|
||||
assert(lsize > 0);
|
||||
}
|
||||
#if 0
|
||||
printf("\n%2d %02x: %d +%4d = %d (best: %d +%4d = %d)\n", ph.method, ph.filter,
|
||||
ph.c_len, lsize, ph.c_len + lsize,
|
||||
best_ph.c_len, best_ph_lsize, best_ph.c_len + best_ph_lsize);
|
||||
printf("\n%2d %02x: %d +%4d +%3d = %d (best: %d +%4d +%3d = %d)\n", ph.method, ph.filter,
|
||||
ph.c_len, lsize, hdr_c_len, ph.c_len + lsize + hdr_c_len,
|
||||
best_ph.c_len, best_ph_lsize, best_hdr_c_len, best_ph.c_len + best_ph_lsize + best_hdr_c_len);
|
||||
#endif
|
||||
bool update = false;
|
||||
if (ph.c_len + lsize < best_ph.c_len + best_ph_lsize)
|
||||
if (ph.c_len + lsize + hdr_c_len < best_ph.c_len + best_ph_lsize + best_hdr_c_len)
|
||||
update = true;
|
||||
else if (ph.c_len + lsize == best_ph.c_len + best_ph_lsize)
|
||||
else if (ph.c_len + lsize + hdr_c_len == best_ph.c_len + best_ph_lsize + best_hdr_c_len)
|
||||
{
|
||||
// prefer smaller loaders
|
||||
if (lsize < best_ph_lsize)
|
||||
if (lsize + hdr_c_len < best_ph_lsize + best_hdr_c_len)
|
||||
update = true;
|
||||
else if (lsize == best_ph_lsize)
|
||||
else if (lsize + hdr_c_len == best_ph_lsize + best_hdr_c_len)
|
||||
{
|
||||
// prefer less overlap_overhead
|
||||
if (ph.overlap_overhead < best_ph.overlap_overhead)
|
||||
@@ -1340,12 +1496,14 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
||||
}
|
||||
if (update)
|
||||
{
|
||||
assert((int)ph.overlap_overhead > 0);
|
||||
// update obuf[] with best version
|
||||
if (otemp != &obuf)
|
||||
memcpy(obuf, *otemp, ph.c_len);
|
||||
// save compression results
|
||||
best_ph = ph;
|
||||
best_ph_lsize = lsize;
|
||||
best_hdr_c_len = hdr_c_len;
|
||||
best_ft = ft;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-5
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -160,8 +160,8 @@ protected:
|
||||
// main compression drivers
|
||||
virtual bool compress(upx_bytep in, upx_bytep out,
|
||||
unsigned max_offset = 0, unsigned max_match = 0);
|
||||
virtual void decompress(const upx_bytep in,
|
||||
upx_bytep out, bool verify_checksum=true);
|
||||
virtual void decompress(const upx_bytep in, upx_bytep out,
|
||||
bool verify_checksum = true, Filter *ft = NULL);
|
||||
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
|
||||
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
|
||||
|
||||
@@ -172,7 +172,9 @@ protected:
|
||||
const int *filters = NULL,
|
||||
unsigned max_offset = 0, unsigned max_match = 0,
|
||||
unsigned filter_buf_off = 0,
|
||||
unsigned compress_buf_off = 0);
|
||||
unsigned compress_buf_off = 0,
|
||||
unsigned char *header_buffer = 0,
|
||||
unsigned header_length = 0);
|
||||
|
||||
// util for verifying overlapping decompresion
|
||||
// non-destructive test
|
||||
@@ -183,7 +185,7 @@ protected:
|
||||
unsigned range = 0,
|
||||
unsigned upper_limit = ~0u) const;
|
||||
// destructive decompress + verify
|
||||
virtual void verifyOverlappingDecompression();
|
||||
virtual void verifyOverlappingDecompression(Filter *ft = NULL);
|
||||
|
||||
|
||||
// packheader handling
|
||||
@@ -208,7 +210,11 @@ protected:
|
||||
virtual const upx_byte *getLoader() const;
|
||||
virtual int getLoaderSize() const;
|
||||
virtual void initLoader(const void *pdata, int plen, int pinfo=-1, int small=-1);
|
||||
#if 1 && (ACC_CC_GNUC >= 0x040100)
|
||||
virtual void __acc_cdecl_va addLoader(const char *s, ...) __attribute__((__sentinel__));
|
||||
#else
|
||||
virtual void __acc_cdecl_va addLoader(const char *s, ...);
|
||||
#endif
|
||||
virtual int getLoaderSection(const char *name, int *slen=NULL) const;
|
||||
virtual int getLoaderSectionStart(const char *name, int *slen=NULL) const;
|
||||
virtual const char *getDecompressor() const;
|
||||
@@ -233,6 +239,7 @@ protected:
|
||||
int patch_le32(void *b, int blen, unsigned old, unsigned new_);
|
||||
int patch_le32(void *b, int blen, const void * old, unsigned new_);
|
||||
int patchVersion(void *b, int blen);
|
||||
int patchVersionYear(void *b, int blen);
|
||||
void checkPatch(void *b, int blen, int boff, int size);
|
||||
|
||||
// relocation util
|
||||
@@ -264,6 +271,7 @@ protected:
|
||||
protected:
|
||||
// linker
|
||||
Linker *linker;
|
||||
virtual void createLinker(const void *pdata, int plen, int pinfo);
|
||||
|
||||
private:
|
||||
// private to checkPatch()
|
||||
|
||||
+75
-75
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -133,21 +133,21 @@ void Packer::addFilter32(int filter_id)
|
||||
addLoader("CALLTR00",
|
||||
(filter_id > 0x20) ? "CTCLEVE1" : "",
|
||||
"CALLTR01",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01""CTBSWA01" : "CTBROR01""CTBSWA01") : "",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01,CTBSWA01" : "CTBROR01,CTBSWA01") : "",
|
||||
"CALLTR02",
|
||||
NULL
|
||||
);
|
||||
}
|
||||
else if (0x40==(0xF0 & filter_id)) {
|
||||
addLoader("CKLLTR00", 0);
|
||||
addLoader("CKLLTR00", NULL);
|
||||
if (9<=(0xf & filter_id)) {
|
||||
addLoader("CKLLTR10", 0);
|
||||
addLoader("CKLLTR10", NULL);
|
||||
}
|
||||
addLoader("CKLLTR20", 0);
|
||||
addLoader("CKLLTR20", NULL);
|
||||
if (9<=(0xf & filter_id)) {
|
||||
addLoader("CKLLTR30", 0);
|
||||
addLoader("CKLLTR30", NULL);
|
||||
}
|
||||
addLoader("CKLLTR40", 0);
|
||||
addLoader("CKLLTR40", NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -156,7 +156,7 @@ void Packer::addFilter32(int filter_id)
|
||||
"CALLTR11",
|
||||
(filter_id > 0x20) ? "CTCLEVE2" : "",
|
||||
"CALLTR12",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11""CTBSWA11" : "CTBROR11""CTBSWA11") : "",
|
||||
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11,CTBSWA11" : "CTBROR11,CTBSWA11") : "",
|
||||
"CALLTR13",
|
||||
NULL
|
||||
);
|
||||
@@ -170,187 +170,187 @@ void Packer::addFilter32(int filter_id)
|
||||
unsigned const f_jcc2 = f80_jcc2(filter_id);
|
||||
|
||||
if (NOFILT!=f_jcc2) {
|
||||
addLoader("LXJCC010", 0);
|
||||
addLoader("LXJCC010", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU045", 0);
|
||||
addLoader("LXMRU045", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU046", 0);
|
||||
addLoader("LXMRU046", NULL);
|
||||
}
|
||||
if (0==n_mru || MRUFLT!=f_jcc2) {
|
||||
addLoader("LXJCC020", 0);
|
||||
addLoader("LXJCC020", NULL);
|
||||
}
|
||||
else { // 0!=n_mru
|
||||
addLoader("LXJCC021", 0);
|
||||
addLoader("LXJCC021", NULL);
|
||||
}
|
||||
if (NOFILT!=f_jcc2) {
|
||||
addLoader("LXJCC023", 0);
|
||||
addLoader("LXJCC023", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXUNF037", 0);
|
||||
addLoader("LXUNF037", NULL);
|
||||
if (x386) {
|
||||
if (n_mru) {
|
||||
addLoader("LXUNF386", 0);
|
||||
addLoader("LXUNF386", NULL);
|
||||
}
|
||||
addLoader("LXUNF387", 0);
|
||||
addLoader("LXUNF387", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXUNF388", 0);
|
||||
addLoader("LXUNF388", NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
addLoader("LXUNF486", 0);
|
||||
addLoader("LXUNF486", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXUNF487", 0);
|
||||
addLoader("LXUNF487", NULL);
|
||||
}
|
||||
}
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU065", 0);
|
||||
addLoader("LXMRU065", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE3", 0);
|
||||
addLoader("MRUBYTE3", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB30", 0);
|
||||
addLoader("MRUARB30", NULL);
|
||||
if (mrupwr2) {
|
||||
addLoader("MRUBITS3", 0);
|
||||
addLoader("MRUBITS3", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB40", 0);
|
||||
addLoader("MRUARB40", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXMRU070", 0);
|
||||
addLoader("LXMRU070", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE4", 0);
|
||||
addLoader("MRUBYTE4", NULL);
|
||||
}
|
||||
else if (mrupwr2) {
|
||||
addLoader("MRUBITS4", 0);
|
||||
addLoader("MRUBITS4", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB50", 0);
|
||||
addLoader("MRUARB50", NULL);
|
||||
}
|
||||
addLoader("LXMRU080", 0);
|
||||
addLoader("LXMRU080", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE5", 0);
|
||||
addLoader("MRUBYTE5", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB60", 0);
|
||||
addLoader("MRUARB60", NULL);
|
||||
if (mrupwr2) {
|
||||
addLoader("MRUBITS5", 0);
|
||||
addLoader("MRUBITS5", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB70", 0);
|
||||
addLoader("MRUARB70", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXMRU090", 0);
|
||||
addLoader("LXMRU090", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE6", 0);
|
||||
addLoader("MRUBYTE6", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB80", 0);
|
||||
addLoader("MRUARB80", NULL);
|
||||
if (mrupwr2) {
|
||||
addLoader("MRUBITS6", 0);
|
||||
addLoader("MRUBITS6", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB90", 0);
|
||||
addLoader("MRUARB90", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXMRU100", 0);
|
||||
addLoader("LXMRU100", NULL);
|
||||
}
|
||||
addLoader("LXUNF040", 0);
|
||||
addLoader("LXUNF040", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU110", 0);
|
||||
addLoader("LXMRU110", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU111", 0);
|
||||
addLoader("LXMRU111", NULL);
|
||||
}
|
||||
addLoader("LXUNF041", 0);
|
||||
addLoader("LXUNF042", 0);
|
||||
addLoader("LXUNF041", NULL);
|
||||
addLoader("LXUNF042", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU010", 0);
|
||||
addLoader("LXMRU010", NULL);
|
||||
if (NOFILT!=f_jmp1 && NOFILT==f_call) {
|
||||
addLoader("LXJMPA00", 0);
|
||||
addLoader("LXJMPA00", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCALLB0", 0);
|
||||
addLoader("LXCALLB0", NULL);
|
||||
}
|
||||
addLoader("LXUNF021", 0);
|
||||
addLoader("LXUNF021", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXMRU022", 0);
|
||||
addLoader("LXMRU022", NULL);
|
||||
if (NOFILT!=f_jmp1 && NOFILT==f_call) {
|
||||
addLoader("LXJMPA01", 0);
|
||||
addLoader("LXJMPA01", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCALLB1", 0);
|
||||
addLoader("LXCALLB1", NULL);
|
||||
}
|
||||
}
|
||||
if (n_mru) {
|
||||
if (256!=n_mru && mrupwr2) {
|
||||
addLoader("MRUBITS1", 0);
|
||||
addLoader("MRUBITS1", NULL);
|
||||
}
|
||||
addLoader("LXMRU030", 0);
|
||||
addLoader("LXMRU030", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE1", 0);
|
||||
addLoader("MRUBYTE1", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("MRUARB10", 0);
|
||||
addLoader("MRUARB10", NULL);
|
||||
}
|
||||
addLoader("LXMRU040", 0);
|
||||
addLoader("LXMRU040", NULL);
|
||||
}
|
||||
|
||||
addLoader("LXUNF030", 0);
|
||||
addLoader("LXUNF030", NULL);
|
||||
if (NOFILT!=f_jcc2) {
|
||||
addLoader("LXJCC000", 0);
|
||||
addLoader("LXJCC000", NULL);
|
||||
}
|
||||
if (NOFILT!=f_call || NOFILT!=f_jmp1) { // at least one is filtered
|
||||
// shift opcode origin to zero
|
||||
if (0==n_mru) {
|
||||
addLoader("LXCJ0MRU", 0);
|
||||
addLoader("LXCJ0MRU", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCJ1MRU", 0);
|
||||
addLoader("LXCJ1MRU", NULL);
|
||||
}
|
||||
|
||||
// determine if in range
|
||||
if ((NOFILT!=f_call) && (NOFILT!=f_jmp1)) { // unfilter both
|
||||
addLoader("LXCALJMP", 0);
|
||||
addLoader("LXCALJMP", NULL);
|
||||
}
|
||||
if ((NOFILT==f_call) ^ (NOFILT==f_jmp1)) { // unfilter just one
|
||||
if (0==n_mru) {
|
||||
addLoader("LXCALL00", 0);
|
||||
addLoader("LXCALL00", NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LXCALL01", 0);
|
||||
addLoader("LXCALL01", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// determine if mru applies
|
||||
if (0==n_mru || ! ((FNOMRU==f_call) || (FNOMRU==f_jmp1)) ) {
|
||||
addLoader("LXCJ2MRU", 0); // no mru, or no exceptions
|
||||
addLoader("LXCJ2MRU", NULL); // no mru, or no exceptions
|
||||
}
|
||||
else { // mru on one, but not the other
|
||||
addLoader("LXCJ4MRU", 0);
|
||||
addLoader("LXCJ4MRU", NULL);
|
||||
if (MRUFLT==f_jmp1) { // JMP only
|
||||
addLoader("LXCJ6MRU", 0);
|
||||
addLoader("LXCJ6MRU", NULL);
|
||||
} else
|
||||
if (MRUFLT==f_call) { // CALL only
|
||||
addLoader("LXCJ7MRU", 0);
|
||||
addLoader("LXCJ7MRU", NULL);
|
||||
}
|
||||
addLoader("LXCJ8MRU", 0);
|
||||
addLoader("LXCJ8MRU", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("LXUNF034", 0);
|
||||
addLoader("LXUNF034", NULL);
|
||||
if (n_mru) {
|
||||
addLoader("LXMRU055", 0);
|
||||
addLoader("LXMRU055", NULL);
|
||||
if (256==n_mru) {
|
||||
addLoader("MRUBYTE2", 0);
|
||||
addLoader("MRUBYTE2", NULL);
|
||||
}
|
||||
else if (mrupwr2) {
|
||||
addLoader("MRUBITS2", 0);
|
||||
addLoader("MRUBITS2", NULL);
|
||||
}
|
||||
else if (n_mru) {
|
||||
addLoader("MRUARB20", 0);
|
||||
addLoader("MRUARB20", NULL);
|
||||
}
|
||||
addLoader("LXMRU057", 0);
|
||||
addLoader("LXMRU057", NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+19
-2
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "p_lx_elf.h"
|
||||
#include "p_lx_sep.h"
|
||||
#include "p_lx_sh.h"
|
||||
#include "p_lx_interp.h"
|
||||
#include "p_sys.h"
|
||||
#include "p_tos.h"
|
||||
#include "p_wcle.h"
|
||||
@@ -51,6 +52,8 @@
|
||||
#include "p_vmlinz.h"
|
||||
#include "p_vmlinx.h"
|
||||
#include "p_ps1.h"
|
||||
#include "p_mach.h"
|
||||
#include "p_armpe.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -168,6 +171,8 @@ static Packer* try_packers(InputFile *f, try_function func)
|
||||
#endif
|
||||
if ((p = func(new PackW16Ne(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackArmPe(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackW32Pe(f),f)) != NULL)
|
||||
return p;
|
||||
}
|
||||
@@ -206,7 +211,15 @@ static Packer* try_packers(InputFile *f, try_function func)
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
if ((p = func(new PackLinuxI386elf(f),f)) != NULL)
|
||||
if (opt->o_unix.use_ptinterp) {
|
||||
if ((p = func(new PackLinuxElf32x86interp(f),f)) != NULL)
|
||||
return p;
|
||||
}
|
||||
if ((p = func(new PackLinuxElf64amd(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackLinuxElf32ppc(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackLinuxElf32x86(f),f)) != NULL)
|
||||
return p;
|
||||
if ((p = func(new PackLinuxI386sh(f),f)) != NULL)
|
||||
return p;
|
||||
@@ -228,6 +241,10 @@ static Packer* try_packers(InputFile *f, try_function func)
|
||||
if ((p = func(new PackCom(f),f)) != NULL)
|
||||
return p;
|
||||
|
||||
// Mach (MacOS X PowerPC)
|
||||
if ((p = func(new PackMachPPC32(f), f)) != NULL)
|
||||
return p;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
*.asx
|
||||
*.asy
|
||||
*.bin
|
||||
*.d
|
||||
*.i
|
||||
*.lst
|
||||
*.map
|
||||
*.o
|
||||
GNUmakefile
|
||||
fold_elf86.h
|
||||
fold_exec86.h
|
||||
fold_sh86.h
|
||||
l_com.h
|
||||
l_djgpp2.h
|
||||
l_exe.h
|
||||
l_lx_elf86.h
|
||||
l_lx_exec86.h
|
||||
l_lx_sh86.h
|
||||
l_sys.h
|
||||
l_t_n2b.h
|
||||
l_t_n2bs.h
|
||||
l_t_n2d.h
|
||||
l_t_n2ds.h
|
||||
l_t_n2e.h
|
||||
l_t_n2es.h
|
||||
l_tmt.h
|
||||
l_vmlinx.h
|
||||
l_vmlinz.h
|
||||
l_w32pe.h
|
||||
l_wcle.h
|
||||
stamp-h
|
||||
stubify.exe
|
||||
stubify.h
|
||||
upxb
|
||||
upxd
|
||||
+234
-51
@@ -5,24 +5,34 @@
|
||||
# for required build tools
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
SHELL = /bin/sh
|
||||
|
||||
ifeq ($(strip $(UCLDIR)),)
|
||||
# change this to reflect where the UCL library is
|
||||
UCLDIR = $(HOME)/local/src/ucl-1.03
|
||||
endif
|
||||
ifeq ($(wildcard $(UCLDIR)/upx),)
|
||||
$(error Please set UCLDIR in Makefile or environment)
|
||||
endif
|
||||
|
||||
# update path for our special stub build tools
|
||||
ifneq ($(wildcard $(HOME)/local/bin/bin-upx),)
|
||||
export PATH := $(HOME)/local/bin/bin-upx:$(PATH)
|
||||
endif
|
||||
|
||||
|
||||
# -------------------------------------------------------
|
||||
# You should not have to change anything below this line.
|
||||
# -------------------------------------------------------
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = ../..
|
||||
|
||||
|
||||
# These are the files we want to create.
|
||||
STUBS = \
|
||||
l_armpea.h l_armpet.h \
|
||||
l_com.h \
|
||||
l_djgpp2.h stubify.h \
|
||||
l_exe.h \
|
||||
@@ -35,6 +45,10 @@ STUBS = \
|
||||
l_lx_exec86.h fold_exec86.h \
|
||||
l_lx_elf86.h fold_elf86.h \
|
||||
l_lx_sh86.h fold_sh86.h \
|
||||
l_lx_pti86.h fold_pti86.h \
|
||||
l_lx_elfppc32.h fold_elfppc32.h \
|
||||
l_lx_elf64amd.h fold_elf64amd.h \
|
||||
l_mac_ppc32.h fold_machppc32.h \
|
||||
l_vmlinz.h l_vmlinx.h
|
||||
|
||||
# experimental:
|
||||
@@ -46,6 +60,10 @@ endif
|
||||
# util var for use in the rules - basename of the current target
|
||||
override T = $(basename $@)
|
||||
|
||||
ifneq ($(strip $(USE_MAKEFILE_DEPS)),)
|
||||
MAKEFILE_DEPS = $(MAKEFILE_LIST)
|
||||
endif
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // source directories
|
||||
@@ -68,7 +86,7 @@ vpath %.ash $(UCL_MR3K)
|
||||
# // tools
|
||||
# ************************************************************************/
|
||||
|
||||
NASM = nasm -O15 -w+macro-params -w+macro-selfref -w+number-overflow -w+orphan-labels
|
||||
NASM = nasm -O99 -w+macro-params -w+macro-selfref -w+number-overflow -w+orphan-labels
|
||||
NASM += -I$(srcdir)/
|
||||
|
||||
APP_I386 = perl -w $(srcdir)/scripts/app_i386.pl
|
||||
@@ -77,29 +95,29 @@ BIN2H = perl -w $(srcdir)/scripts/bin2h.pl
|
||||
BRANDELF = perl -w $(srcdir)/scripts/brandelf.pl
|
||||
O2BIN = perl -w $(srcdir)/scripts/o2bin.pl
|
||||
##STRIPELF = perl -w $(srcdir)/scripts/stripelf.pl
|
||||
STRIPELF = ./util/sstrip/sstrip
|
||||
|
||||
|
||||
###
|
||||
### linux/i386
|
||||
### i386-linux
|
||||
###
|
||||
|
||||
LD_LINUX_I386 = ld-2.13.2
|
||||
LD_LINUX_I386 = ld
|
||||
OBJCOPY_LINUX_I386 = objcopy
|
||||
LD_LINUX_I386 = i386-linux-ld-2.16.1 -m elf_i386
|
||||
OBJCOPY_LINUX_I386 = i386-linux-objcopy-2.16.1 -F elf32-i386
|
||||
OBJSTRIP_LINUX_I386 = $(OBJCOPY_LINUX_I386) -R .comment -R .note
|
||||
STRIPELF_LINUX_I386 = ./util/sstrip/i386-linux-sstrip
|
||||
|
||||
# gcc 2.7.2.3 (fold_*.bin: 1839 / 1011 / 1390)
|
||||
CC_LINUX_I386_GCC272 = gcc-2.72 -m386 -O2 -MMD
|
||||
# gcc 2.7.2.3 (fold_*86.bin: 1900 / 1011 / 1786 / 1401)
|
||||
CC_LINUX_I386_GCC272 = i386-linux-gcc-2.72 -m386 -O2 -MMD
|
||||
CC_LINUX_I386_GCC272 += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
||||
|
||||
# gcc 2.95.3 (fold_*.bin: 1721 / 995 / 1321)
|
||||
CC_LINUX_I386_GCC295 = gcc-2.95.3 -march=i386 -mcpu=k6 -fno-exceptions -MMD
|
||||
# gcc 2.95.3 (fold_*86.bin: 1770 / 995 / 1661 / 1314)
|
||||
CC_LINUX_I386_GCC295 = i386-linux-gcc-2.95.3 -march=i386 -mcpu=k6 -fno-exceptions -MMD
|
||||
CC_LINUX_I386_GCC295 += -Os -fno-omit-frame-pointer
|
||||
CC_LINUX_I386_GCC295 += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
||||
CC_LINUX_I386_GCC295 += -Werror
|
||||
|
||||
# gcc 3.4.3 (fold_*.bin: 1624 / 931 / 1207)
|
||||
CC_LINUX_I386_GCC34 = gcc-3.4.3
|
||||
# gcc 3.4.6 (fold_*86.bin: 1651 / 947 / 1537 / 1190)
|
||||
CC_LINUX_I386_GCC34 = i386-linux-gcc-3.4.6
|
||||
CC_LINUX_I386_GCC34 += -m32 -march=i386 -mtune=k6 -fno-exceptions -MMD
|
||||
CC_LINUX_I386_GCC34 += -Os -fno-omit-frame-pointer
|
||||
CC_LINUX_I386_GCC34 += -momit-leaf-frame-pointer
|
||||
@@ -108,8 +126,20 @@ CC_LINUX_I386_GCC34 += -mpreferred-stack-boundary=2
|
||||
CC_LINUX_I386_GCC34 += -fweb
|
||||
CC_LINUX_I386_GCC34 += -Werror
|
||||
|
||||
# gcc 4.1.0 (fold_*86.bin: 1725 / 963 / 1620 / 1202)
|
||||
# gcc 4.0.3 (fold_*86.bin: 1731 / 995 / 1625 / 1195)
|
||||
CC_LINUX_I386_GCC41 = i386-linux-gcc-4.1.0
|
||||
CC_LINUX_I386_GCC41 += -m32 -march=i386 -mtune=k6 -fno-exceptions -MMD
|
||||
CC_LINUX_I386_GCC41 += -Os -fno-omit-frame-pointer
|
||||
CC_LINUX_I386_GCC41 += -momit-leaf-frame-pointer
|
||||
CC_LINUX_I386_GCC41 += -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
|
||||
CC_LINUX_I386_GCC41 += -mpreferred-stack-boundary=2
|
||||
CC_LINUX_I386_GCC41 += -fweb
|
||||
CC_LINUX_I386_GCC41 += -Werror
|
||||
|
||||
CC_LINUX_I386 = $(CC_LINUX_I386_GCC272)
|
||||
CC_LINUX_I386 = $(CC_LINUX_I386_GCC295)
|
||||
CC_LINUX_I386 = $(CC_LINUX_I386_GCC41)
|
||||
CC_LINUX_I386 = $(CC_LINUX_I386_GCC34)
|
||||
CC_LINUX_I386 += -nostdinc
|
||||
CC_LINUX_I386 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings
|
||||
@@ -120,7 +150,7 @@ CC_LINUX_I386 += -funsigned-char
|
||||
### MIPS R3000
|
||||
###
|
||||
|
||||
CPP_MR3K = gcc-2.95.3 -nostdinc -I$(UCL_UPX) -I$(srcdir) -E -x assembler-with-cpp -Wall -Wp,-P,-C,-traditional
|
||||
CPP_MR3K = i386-linux-gcc-2.95.3 -nostdinc -I$(UCL_UPX) -I$(srcdir) -E -x assembler-with-cpp -Wall -Wp,-P,-C,-traditional
|
||||
APP_MR3K = perl -w $(srcdir)/scripts/app_mr3k.pl
|
||||
ASM_MR3K = asm5900 --nologo -q
|
||||
|
||||
@@ -142,6 +172,64 @@ else
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### PowerPC 32
|
||||
###
|
||||
|
||||
GCC_PPC32 := false
|
||||
LD_PPC32 := false
|
||||
OBJCOPY_PPC32 := false
|
||||
OBJSTRIP_PPC32 = $(OBJCOPY_PPC32) -R .comment -R .note
|
||||
|
||||
d = /home2/crosstool/powerpc-750-linux-gnu/gcc-3.4.1-glibc-20040827/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_PPC32 := $d/powerpc-750-linux-gnu-gcc -m32 -nostdinc -MMD
|
||||
LD_PPC32 := $d/powerpc-750-linux-gnu-ld
|
||||
OBJCOPY_PPC32 := $d/powerpc-750-linux-gnu-objcopy
|
||||
endif
|
||||
d = /opt/cc-i386-linux/crosstool/powerpc-750-linux-gnu/gcc-3.4.3.20050210-glibc-2.2.5/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_PPC32 := $d/powerpc-750-linux-gnu-gcc -m32 -nostdinc -MMD -fno-exceptions -fno-asynchronous-unwind-tables
|
||||
LD_PPC32 := $d/powerpc-750-linux-gnu-ld
|
||||
OBJCOPY_PPC32 := $d/powerpc-750-linux-gnu-objcopy
|
||||
endif
|
||||
GCC_PPC32 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
|
||||
|
||||
|
||||
###
|
||||
### AMD x86_64
|
||||
###
|
||||
|
||||
GCC_AMD64 := false
|
||||
LD_AMD64 := false
|
||||
OBJCOPY_AMD64 := false
|
||||
OBJSTRIP_AMD64 = $(OBJCOPY_AMD64) -R .comment -R .note
|
||||
|
||||
d = /home2/crosstool/gcc-4.0.1-glibc-2.3.5/x86_64-unknown-linux-gnu/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_AMD64 := $d/x86_64-unknown-linux-gnu-gcc -m64 -nostdinc -MMD
|
||||
LD_AMD64 := $d/x86_64-unknown-linux-gnu-ld -m elf_x86_64
|
||||
OBJCOPY_AMD64 := $d/x86_64-unknown-linux-gnu-objcopy -F elf64-x86-64
|
||||
endif
|
||||
d = /opt/cc-i386-linux/crosstool/x86_64-unknown-linux-gnu/gcc-3.4.3.20050507-glibc-2.3.5/bin
|
||||
ifneq ($(wildcard $d),)
|
||||
GCC_AMD64 := $d/x86_64-unknown-linux-gnu-gcc -m64 -nostdinc -MMD
|
||||
LD_AMD64 := $d/x86_64-unknown-linux-gnu-ld -m elf_x86_64
|
||||
OBJCOPY_AMD64 := $d/x86_64-unknown-linux-gnu-objcopy -F elf64-x86-64
|
||||
endif
|
||||
GCC_AMD64 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
|
||||
|
||||
|
||||
###
|
||||
### ARM-PE-WINCE
|
||||
###
|
||||
|
||||
GCC_ARM := arm-9tdmi-linux-gnu-gcc -march=armv4 -nostdinc -MMD
|
||||
GCC_ARM += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
|
||||
GCC_ARM_T := $(GCC_ARM) -march=armv4t
|
||||
OBJCOPY_ARM := arm-9tdmi-linux-gnu-objcopy
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // main targets
|
||||
# ************************************************************************/
|
||||
@@ -159,7 +247,7 @@ stubs: $(STUBS)
|
||||
|
||||
mostlyclean:
|
||||
-rm -f *.bin *.bkp *.d *.i *.lst *.map stubify.exe
|
||||
-rm -f *.o *.asx *.asy
|
||||
-rm -f *.ah *.asx *.asy *.o *.out
|
||||
|
||||
clean: mostlyclean
|
||||
ifneq ($(strip $(wildcard stamp-h)),)
|
||||
@@ -185,10 +273,10 @@ strings: all
|
||||
# // rules
|
||||
# ************************************************************************/
|
||||
|
||||
%.asx : %.asm
|
||||
%.asx : %.asm $(srcdir)/scripts/app_i386.pl
|
||||
$(APP_I386) $< $@
|
||||
|
||||
%.asy : %.ash
|
||||
%.asy : %.ash $(srcdir)/scripts/app_i386.pl
|
||||
$(APP_I386) $< $@
|
||||
|
||||
|
||||
@@ -305,7 +393,7 @@ l_ps1c.h: l_ps1.asm
|
||||
|
||||
upx_itoa.o: upx_itoa.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_elf86.h: l_lx_elf86.asx
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
@@ -319,88 +407,175 @@ l_lx_sh86.h: l_lx_sh86.asx
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
$(BIN2H) $T.bin linux_i386sh_loader $@
|
||||
|
||||
l_lx_elf.o: l_lx_elf.c linux.hh
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
l_lx_pti86.h: l_lx_pti86.asx
|
||||
$(NASM) -f bin -o $T.bin $<
|
||||
$(BIN2H) $T.bin linux_i386pti_loader $@
|
||||
|
||||
l_lx_exec.o: l_lx_exec.c linux.hh
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
l_mac_ppc32.h: l_mac_ppc32.S ppc_d_nrv2e.S
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $T.o
|
||||
$(LD_PPC32) -o $T.bin --oformat binary $T.o
|
||||
$(BIN2H) $T.bin l_mac_ppc32_loader $@
|
||||
|
||||
l_lx_sep.o: l_lx_sep.c linux.hh
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
l_lx_elfppc32.h: l_lx_elfppc32.S ppc_d_nrv2e.S
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $T.o
|
||||
$(LD_PPC32) -o $T.bin --oformat binary $T.o
|
||||
$(BIN2H) $T.bin linux_elfppc32_loader $@
|
||||
|
||||
l_lx_sh.o: l_lx_sh.c linux.hh
|
||||
l_lx_elf64amd.h: l_lx_elf64amd.S amd_d_nrv2e.S
|
||||
$(GCC_AMD64) -c $<
|
||||
$(OBJSTRIP_AMD64) $T.o
|
||||
$(LD_AMD64) -o $T.bin --oformat binary $T.o
|
||||
$(BIN2H) $T.bin linux_elf64amd_loader $@
|
||||
|
||||
l_lx_elf.o: l_lx_elf.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_exec.o: l_lx_exec.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_sep.o: l_lx_sep.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_sh.o: l_lx_sh.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
l_lx_pti.o: l_lx_pti.c linux.hh $(MAKEFILE_DEPS)
|
||||
$(CC_LINUX_I386) -c $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_elf86.o: fold_elf86.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_elf86.h: l_lx_elf.o fold_elf86.o l_lx_elf86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_elf86.lds -Map $T.map -o $T.bin $T.o l_lx_elf.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin
|
||||
$(STRIPELF) $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386elf_fold $@
|
||||
|
||||
m_lx_elfppc32.o: m_lx_elfppc32.c $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -c -Os $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
a_lx_elf64amd.o: a_lx_elf64.c $(MAKEFILE_DEPS)
|
||||
$(GCC_AMD64) -c -Os -fno-exceptions -fno-asynchronous-unwind-tables -o $@ $<
|
||||
$(OBJSTRIP_AMD64) $@
|
||||
|
||||
fold_elfppc32.o: fold_elfppc32.S ppc_bxx.S $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
fold_elf64amd.o: fold_elf64amd.S amd_bxx.S $(MAKEFILE_DEPS)
|
||||
$(GCC_AMD64) -c $<
|
||||
$(OBJSTRIP_AMD64) $@
|
||||
|
||||
fold_elfppc32.h: m_lx_elfppc32.o fold_elfppc32.o l_lx_elfppc32.lds
|
||||
$(LD_PPC32) -T $(srcdir)/l_lx_elfppc32.lds -Map $T.map -o $T.bin --strip-all \
|
||||
fold_elfppc32.o m_lx_elfppc32.o
|
||||
$(BIN2H) $T.bin linux_elfppc32_fold $@
|
||||
|
||||
fold_elf64amd.h: a_lx_elf64amd.o fold_elf64amd.o l_lx_elf64amd.lds amd_bxx.S
|
||||
$(LD_AMD64) -T $(srcdir)/l_lx_elf64amd.lds -Map $T.map -o $T.bin --strip-all \
|
||||
fold_elf64amd.o a_lx_elf64amd.o
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BIN2H) $T.bin linux_elf64amd_fold $@
|
||||
|
||||
fold_exec86.o: fold_exec86.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_exec86.h: l_lx_exec.o upx_itoa.o fold_exec86.o l_lx_exec86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_exec86.lds -Map $T.map -o $T.bin $T.o l_lx_exec.o upx_itoa.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin
|
||||
$(STRIPELF) $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386exec_fold $@
|
||||
|
||||
fold_sh86.o: fold_sh86.asm
|
||||
$(NASM) -f elf -o $@ $<
|
||||
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_sh86.h: l_lx_sh.o fold_sh86.o l_lx_sh86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sh86.lds -Map $T.map -o $T.bin $T.o l_lx_sh.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin
|
||||
$(STRIPELF) $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386sh_fold $@
|
||||
|
||||
fold_pti86.o: fold_pti86.asm
|
||||
$(NASM) -f elf -i$(UCL_I386)/ -o $@ $<
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
|
||||
fold_pti86.h: l_lx_pti.o fold_pti86.o l_lx_pti86.lds
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_pti86.lds -Map $T.map -o $T.bin $T.o l_lx_pti.o
|
||||
chmod a-x $T.bin
|
||||
$(OBJSTRIP_LINUX_I386) $T.bin
|
||||
$(STRIPELF_LINUX_I386) $T.bin
|
||||
$(BRANDELF) $T.bin
|
||||
$(BIN2H) $T.bin linux_i386pti_fold $@
|
||||
|
||||
fold_machppc32.h: m_mac_mach32.o fold_machppc32.o
|
||||
$(LD_PPC32) -Map $T.map -o $T.bin --oformat binary fold_machppc32.o m_mac_mach32.o
|
||||
chmod a-x $T.bin
|
||||
$(BIN2H) $T.bin fold_machppc32 $@
|
||||
|
||||
m_mac_mach32.o: m_mac_mach32.c $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -Os -c $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
fold_machppc32.o: fold_machppc32.S ppc_bxx.S $(MAKEFILE_DEPS)
|
||||
$(GCC_PPC32) -c $<
|
||||
$(OBJSTRIP_PPC32) $@
|
||||
|
||||
upxb: l_lx_sep.o l_lx_sep86.asm
|
||||
$(NASM) -i$(UCL_I386)/ -f elf -dNRV2B -o $T.o l_lx_sep86.asm
|
||||
$(NASM) -f elf -i$(UCL_I386)/ -dNRV2B -o $T.o l_lx_sep86.asm
|
||||
$(OBJSTRIP_LINUX_I386) $T.o
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $@
|
||||
$(STRIPELF) $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
$(STRIPELF_LINUX_I386) $@
|
||||
$(BRANDELF) $@
|
||||
|
||||
upxd: l_lx_sep.o l_lx_sep86.asm
|
||||
$(NASM) -i$(UCL_I386)/ -f elf -dNRV2D -o $T.o l_lx_sep86.asm
|
||||
$(NASM) -f elf -i$(UCL_I386)/ -dNRV2D -o $T.o l_lx_sep86.asm
|
||||
$(OBJSTRIP_LINUX_I386) $T.o
|
||||
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o
|
||||
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $@
|
||||
$(STRIPELF) $@
|
||||
$(OBJSTRIP_LINUX_I386) $@
|
||||
$(STRIPELF_LINUX_I386) $@
|
||||
$(BRANDELF) $@
|
||||
|
||||
l_armpea.h: l_armpea.S armv4_n2e_d8.S $(MAKEFILE_LIST)
|
||||
$(GCC_ARM) $T.S -o $T.out -nostdlib
|
||||
$(OBJCOPY_ARM) --only-section .text -O binary $T.out $T.bin
|
||||
$(BIN2H) $T.bin nrv_loader_arm $@
|
||||
|
||||
l_armpet.h: l_armpet.S arm_nrv2e_d8.S arm_nrv2b_d8.S $(MAKEFILE_LIST)
|
||||
$(GCC_ARM_T) $T.S -o $T.out -nostdlib
|
||||
$(OBJCOPY_ARM) --only-section .text -O binary $T.out $T.bin
|
||||
$(BIN2H) $T.bin nrv_loader_thumb $@
|
||||
|
||||
# /***********************************************************************
|
||||
# // dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
DEPS_FILES := $(wildcard *.d)
|
||||
ifneq ($(strip $(DEPS_FILES)),)
|
||||
include $(DEPS_FILES)
|
||||
endif
|
||||
-include *.d
|
||||
|
||||
DEPS1 = header.ash macros.ash ident.ash ident_n.ash ident_s.ash
|
||||
DEPS2 = header.asy macros.asy
|
||||
DEPS3 = n2b_d32.asy n2d_d32.asy n2e_d32.asy
|
||||
DEPS3 = n2b_d32.asy n2d_d32.asy n2e_d32.asy cl1_d32.asy
|
||||
|
||||
$(STUBS): $(srcdir)/scripts/bin2h.pl
|
||||
|
||||
l_armpe.h: $(DEPS2) $(DEPS3)
|
||||
l_com.h: n2b_d16.asy $(DEPS2)
|
||||
l_djgpp2.h: $(DEPS2) $(DEPS3)
|
||||
l_exe.h: n2b_d8e.asy n2d_d8e.asy n2e_d8e.asy $(DEPS2)
|
||||
@@ -420,8 +595,16 @@ l_w32pe.h: $(DEPS2) $(DEPS3)
|
||||
|
||||
l_lx_elf86.h: l_lx_elf86.asm macros.ash macros.asy $(DEPS3)
|
||||
l_lx_exec86.h: l_lx_exec86.asm macros.ash macros.asy $(DEPS3)
|
||||
l_lx_pti86.h: l_lx_pti86.asm macros.ash macros.asy $(DEPS3)
|
||||
l_lx_sh86.h: l_lx_sh86.asm macros.ash macros.asy $(DEPS3)
|
||||
|
||||
.NOEXPORT:
|
||||
|
||||
# FIXME: what is this ???
|
||||
upxrun: start-interp.o interp.o
|
||||
gcc -nostartfiles -nostdlib -o $@ -Ttext=0x10000 $^
|
||||
start-interp.o: start-interp.S
|
||||
gcc -c $<
|
||||
interp.o: interp.c
|
||||
gcc -c -g $<
|
||||
|
||||
# vi:nowrap
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
/* a_lx_elf64.c -- stub loader for Linux 64-bit ELF executable
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2000-2005 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "linux.hh"
|
||||
extern void exit(int);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// configuration section
|
||||
**************************************************************************/
|
||||
|
||||
// In order to make it much easier to move this code at runtime and execute
|
||||
// it at an address different from it load address: there must be no
|
||||
// static data, and no string constants.
|
||||
|
||||
#define MAX_ELF_HDR 1024 // Elf64_Ehdr + n*Elf64_Phdr must fit in this
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// "file" util
|
||||
**************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
size_t size; // must be first to match size[0] uncompressed size
|
||||
char *buf;
|
||||
} Extent;
|
||||
|
||||
|
||||
static void
|
||||
xread(Extent *x, char *buf, size_t count)
|
||||
{
|
||||
char *p=x->buf, *q=buf;
|
||||
size_t j;
|
||||
if (x->size < count) {
|
||||
exit(127);
|
||||
}
|
||||
for (j = count; 0!=j--; ++p, ++q) {
|
||||
*q = *p;
|
||||
}
|
||||
x->buf += count;
|
||||
x->size -= count;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// util
|
||||
**************************************************************************/
|
||||
|
||||
#if 1 //{ save space
|
||||
#define ERR_LAB error: exit(127);
|
||||
#define err_exit(a) goto error
|
||||
#else //}{ save debugging time
|
||||
#define ERR_LAB
|
||||
static void
|
||||
err_exit(int a)
|
||||
{
|
||||
(void)a; // debugging convenience
|
||||
exit(127);
|
||||
}
|
||||
#endif //}
|
||||
|
||||
/*************************************************************************
|
||||
// UPX & NRV stuff
|
||||
**************************************************************************/
|
||||
|
||||
typedef void f_unfilter(
|
||||
nrv_byte *, // also addvalue
|
||||
nrv_uint,
|
||||
unsigned cto8, // junk in high 24 bits
|
||||
unsigned ftid
|
||||
);
|
||||
typedef int f_expand(
|
||||
const nrv_byte *, nrv_uint,
|
||||
nrv_byte *, nrv_uint *, unsigned );
|
||||
|
||||
static void
|
||||
unpackExtent(
|
||||
Extent *const xi, // input
|
||||
Extent *const xo, // output
|
||||
f_expand *const f_decompress,
|
||||
f_unfilter *f_unf
|
||||
)
|
||||
{
|
||||
while (xo->size) {
|
||||
struct b_info h;
|
||||
// Note: if h.sz_unc == h.sz_cpr then the block was not
|
||||
// compressible and is stored in its uncompressed form.
|
||||
|
||||
// Read and check block sizes.
|
||||
xread(xi, (char *)&h, sizeof(h));
|
||||
if (h.sz_unc == 0) { // uncompressed size 0 -> EOF
|
||||
if (h.sz_cpr != UPX_MAGIC_LE32) // h.sz_cpr must be h->magic
|
||||
err_exit(2);
|
||||
if (xi->size != 0) // all bytes must be written
|
||||
err_exit(3);
|
||||
break;
|
||||
}
|
||||
if (h.sz_cpr <= 0) {
|
||||
err_exit(4);
|
||||
ERR_LAB
|
||||
}
|
||||
if (h.sz_cpr > h.sz_unc
|
||||
|| h.sz_unc > xo->size ) {
|
||||
err_exit(5);
|
||||
}
|
||||
// Now we have:
|
||||
// assert(h.sz_cpr <= h.sz_unc);
|
||||
// assert(h.sz_unc > 0 && h.sz_unc <= blocksize);
|
||||
// assert(h.sz_cpr > 0 && h.sz_cpr <= blocksize);
|
||||
|
||||
if (h.sz_cpr < h.sz_unc) { // Decompress block
|
||||
nrv_uint out_len;
|
||||
int const j = (*f_decompress)((unsigned char *)xi->buf, h.sz_cpr,
|
||||
(unsigned char *)xo->buf, &out_len, h.b_method );
|
||||
if (j != 0 || out_len != (nrv_uint)h.sz_unc)
|
||||
err_exit(7);
|
||||
// Skip Ehdr+Phdrs: separate 1st block, not filtered
|
||||
if (h.b_ftid!=0 && f_unf // have filter
|
||||
&& ((512 < out_len) // this block is longer than Ehdr+Phdrs
|
||||
|| (xo->size==(unsigned)h.sz_unc) ) // block is last in Extent
|
||||
) {
|
||||
(*f_unf)((unsigned char *)xo->buf, out_len, h.b_cto8, h.b_ftid);
|
||||
}
|
||||
xi->buf += h.sz_cpr;
|
||||
xi->size -= h.sz_cpr;
|
||||
}
|
||||
else { // copy literal block
|
||||
xread(xi, xo->buf, h.sz_cpr);
|
||||
}
|
||||
xo->buf += h.sz_unc;
|
||||
xo->size -= h.sz_unc;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 /*{*/
|
||||
static void
|
||||
upx_bzero(char *p, size_t len)
|
||||
{
|
||||
if (len) do {
|
||||
*p++= 0;
|
||||
} while (--len);
|
||||
}
|
||||
#define bzero upx_bzero
|
||||
#else
|
||||
#define bzero(a,b) __builtin_memset(a,0,b)
|
||||
#endif /*}*/
|
||||
|
||||
static void
|
||||
auxv_up(Elf64_auxv_t *av, unsigned const type, uint64_t const value)
|
||||
{
|
||||
if (av)
|
||||
for (;; ++av) {
|
||||
if (av->a_type==type || (av->a_type==AT_IGNORE && type!=AT_NULL)) {
|
||||
av->a_type = type;
|
||||
av->a_un.a_val = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The PF_* and PROT_* bits are {1,2,4}; the conversion table fits in 32 bits.
|
||||
#define REP8(x) \
|
||||
((x)|((x)<<4)|((x)<<8)|((x)<<12)|((x)<<16)|((x)<<20)|((x)<<24)|((x)<<28))
|
||||
#define EXP8(y) \
|
||||
((1&(y)) ? 0xf0f0f0f0 : (2&(y)) ? 0xff00ff00 : (4&(y)) ? 0xffff0000 : 0)
|
||||
#define PF_TO_PROT(pf) \
|
||||
((PROT_READ|PROT_WRITE|PROT_EXEC) & ( \
|
||||
( (REP8(PROT_EXEC ) & EXP8(PF_X)) \
|
||||
|(REP8(PROT_READ ) & EXP8(PF_R)) \
|
||||
|(REP8(PROT_WRITE) & EXP8(PF_W)) \
|
||||
) >> ((pf & (PF_R|PF_W|PF_X))<<2) ))
|
||||
|
||||
|
||||
// Find convex hull of PT_LOAD (the minimal interval which covers all PT_LOAD),
|
||||
// and mmap that much, to be sure that a kernel using exec-shield-randomize
|
||||
// won't place the first piece in a way that leaves no room for the rest.
|
||||
static unsigned long // returns relocation constant
|
||||
xfind_pages(unsigned mflags, Elf64_Phdr const *phdr, int phnum,
|
||||
char **const p_brk
|
||||
)
|
||||
{
|
||||
size_t lo= ~0, hi= 0, szlo= 0;
|
||||
char *addr;
|
||||
mflags += MAP_PRIVATE | MAP_ANONYMOUS; // '+' can optimize better than '|'
|
||||
for (; --phnum>=0; ++phdr) if (PT_LOAD==phdr->p_type) {
|
||||
if (phdr->p_vaddr < lo) {
|
||||
lo = phdr->p_vaddr;
|
||||
szlo = phdr->p_filesz;
|
||||
}
|
||||
if (hi < (phdr->p_memsz + phdr->p_vaddr)) {
|
||||
hi = phdr->p_memsz + phdr->p_vaddr;
|
||||
}
|
||||
}
|
||||
szlo += ~PAGE_MASK & lo; // page fragment on lo edge
|
||||
lo -= ~PAGE_MASK & lo; // round down to page boundary
|
||||
hi = PAGE_MASK & (hi - lo - PAGE_MASK -1); // page length
|
||||
szlo = PAGE_MASK & (szlo - PAGE_MASK -1); // page length
|
||||
addr = mmap((void *)lo, hi, PROT_NONE, mflags, -1, 0);
|
||||
*p_brk = hi + addr; // the logical value of brk(0)
|
||||
//mprotect(szlo + addr, hi - szlo, PROT_NONE); // no access, but keep the frames!
|
||||
return (unsigned long)addr - lo;
|
||||
}
|
||||
|
||||
static Elf64_Addr // entry address
|
||||
do_xmap(
|
||||
Elf64_Ehdr const *const ehdr,
|
||||
Extent *const xi,
|
||||
int const fdi,
|
||||
Elf64_auxv_t *const av,
|
||||
f_expand *const f_decompress,
|
||||
f_unfilter *const f_unf
|
||||
)
|
||||
{
|
||||
Elf64_Phdr const *phdr = (Elf64_Phdr const *) (ehdr->e_phoff +
|
||||
(char const *)ehdr);
|
||||
char *v_brk;
|
||||
unsigned long const reloc = xfind_pages(
|
||||
((ET_DYN!=ehdr->e_type) ? MAP_FIXED : 0), phdr, ehdr->e_phnum, &v_brk);
|
||||
int j;
|
||||
for (j=0; j < ehdr->e_phnum; ++phdr, ++j)
|
||||
if (xi && PT_PHDR==phdr->p_type) {
|
||||
auxv_up(av, AT_PHDR, phdr->p_vaddr + reloc);
|
||||
} else
|
||||
if (PT_LOAD==phdr->p_type) {
|
||||
unsigned const prot = PF_TO_PROT(phdr->p_flags);
|
||||
Extent xo;
|
||||
size_t mlen = xo.size = phdr->p_filesz;
|
||||
char *addr = xo.buf = reloc + (char *)phdr->p_vaddr;
|
||||
char *haddr = phdr->p_memsz + addr;
|
||||
size_t frag = (long)addr &~ PAGE_MASK;
|
||||
mlen += frag;
|
||||
addr -= frag;
|
||||
|
||||
if (addr != mmap(addr, mlen, prot | (xi ? PROT_WRITE : 0),
|
||||
MAP_FIXED | MAP_PRIVATE | (xi ? MAP_ANONYMOUS : 0),
|
||||
(xi ? -1 : fdi), phdr->p_offset - frag) ) {
|
||||
err_exit(8);
|
||||
}
|
||||
if (xi) {
|
||||
unpackExtent(xi, &xo, f_decompress, f_unf);
|
||||
}
|
||||
// Linux does not fixup the low end, so neither do we.
|
||||
//if (PROT_WRITE & prot) {
|
||||
// bzero(addr, frag); // fragment at lo end
|
||||
//}
|
||||
frag = (-mlen) &~ PAGE_MASK; // distance to next page boundary
|
||||
if (PROT_WRITE & prot) { // note: read-only .bss not supported here
|
||||
bzero(mlen+addr, frag); // fragment at hi end
|
||||
}
|
||||
if (xi) {
|
||||
if (0==phdr->p_offset) {
|
||||
Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)addr;
|
||||
*(int *)&ehdr->e_ident[12] = 0x90c3050f; // syscall; ret; nop
|
||||
}
|
||||
if (0!=mprotect(addr, mlen, prot)) {
|
||||
err_exit(10);
|
||||
ERR_LAB
|
||||
}
|
||||
}
|
||||
addr += mlen + frag; /* page boundary on hi end */
|
||||
if (addr < haddr) { // need pages for .bss
|
||||
if (addr != mmap(addr, haddr - addr, prot,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0 ) ) {
|
||||
err_exit(9);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xi) { // 1st call (main); also have (0!=av) here
|
||||
if (ET_DYN!=ehdr->e_type) {
|
||||
// Needed only if compressed shell script invokes compressed shell.
|
||||
brk(v_brk);
|
||||
}
|
||||
}
|
||||
return ehdr->e_entry + reloc;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// upx_main - called by our entry code
|
||||
//
|
||||
// This function is optimized for size.
|
||||
**************************************************************************/
|
||||
|
||||
void *
|
||||
upx_main( // returns entry address
|
||||
struct b_info const *const bi, // 1st block header
|
||||
size_t const sz_compressed, // total length
|
||||
Elf64_Ehdr *const ehdr, // temp char[sz_ehdr] for decompressing
|
||||
Elf64_auxv_t *const av,
|
||||
f_expand *const f_decompress,
|
||||
f_unfilter *const f_unf
|
||||
)
|
||||
{
|
||||
Elf64_Phdr const *phdr = (Elf64_Phdr const *)(1+ ehdr);
|
||||
Elf64_Addr entry;
|
||||
|
||||
Extent xo, xi1, xi2;
|
||||
xo.buf = (char *)ehdr;
|
||||
xo.size = bi->sz_unc;
|
||||
xi2.buf = CONST_CAST(char *, bi); xi2.size = sz_compressed;
|
||||
xi1.buf = CONST_CAST(char *, bi); xi1.size = sz_compressed;
|
||||
|
||||
// ehdr = Uncompress Ehdr and Phdrs
|
||||
unpackExtent(&xi2, &xo, f_decompress, 0); // never filtered?
|
||||
|
||||
// AT_PHDR.a_un.a_val is set again by do_xmap if PT_PHDR is present.
|
||||
auxv_up(av, AT_PHDR , (unsigned long)(1+(Elf64_Ehdr *)phdr->p_vaddr));
|
||||
auxv_up(av, AT_PHNUM , ehdr->e_phnum);
|
||||
auxv_up(av, AT_ENTRY , (unsigned long)ehdr->e_entry);
|
||||
//auxv_up(av, AT_PHENT , ehdr->e_phentsize); /* this can never change */
|
||||
//auxv_up(av, AT_PAGESZ, PAGE_SIZE); /* ld-linux.so.2 does not need this */
|
||||
|
||||
entry = do_xmap(ehdr, &xi1, 0, av, f_decompress, f_unf); // "rewind"
|
||||
|
||||
{ // Map PT_INTERP program interpreter
|
||||
int j;
|
||||
for (j=0; j < ehdr->e_phnum; ++phdr, ++j) if (PT_INTERP==phdr->p_type) {
|
||||
char const *const iname = (char const *)phdr->p_vaddr;
|
||||
int const fdi = open(iname, O_RDONLY, 0);
|
||||
if (0 > fdi) {
|
||||
err_exit(18);
|
||||
}
|
||||
if (MAX_ELF_HDR!=read(fdi, (void *)ehdr, MAX_ELF_HDR)) {
|
||||
ERR_LAB
|
||||
err_exit(19);
|
||||
}
|
||||
entry = do_xmap(ehdr, 0, fdi, 0, 0, 0);
|
||||
close(fdi);
|
||||
}
|
||||
}
|
||||
|
||||
return (void *)entry;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* amd_bxx.S -- AMD x86_64 Call/Branch Trick unfilter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2005 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "amd_regs.h"
|
||||
|
||||
amdbxx: # (*f_unf)(xo->buf, out_len, h.b_cto8, h.b_ftid);
|
||||
|
||||
#define ptr %arg1 /* known to be %rdi */
|
||||
#define len %arg2
|
||||
#define cto8 %arg3l /* known to be "%dl" */
|
||||
#define ftid %arg4l
|
||||
|
||||
cmpl $0x49,ftid; jne ckend # filter: JMP, CALL, 6-byte Jxx
|
||||
movq len,%rcx # byte count
|
||||
movq ptr,%rsi # remember start of buffer
|
||||
jmp ckstart
|
||||
ckloop3:
|
||||
movb (%rdi),%al; addq $1,%rdi
|
||||
cmpb $0x80,%al; jb ckloop2 # lo of 6-byte Jcc
|
||||
cmpb $0x8F,%al; ja ckloop2 # hi of 6-byte Jcc
|
||||
cmpb $0x0F,-2(%rdi); je ckmark # prefix of 6-byte Jcc
|
||||
ckloop2:
|
||||
subb $ 0xE8,%al
|
||||
cmpb $0xE9-0xE8,%al; ja ckcount # not JMP, not CALL
|
||||
ckmark:
|
||||
cmpb %dl,(%rdi); jne ckcount # not marked with cto8
|
||||
movl (%rdi),%eax # the marked, bswapped 32-bit displacement
|
||||
andl $~0<<8,%eax # clear the mark
|
||||
bswap %eax
|
||||
subl %edi,%eax
|
||||
addl %esi,%eax
|
||||
stosl # *%rdi++ = %eax;
|
||||
ckstart:
|
||||
subq $4,%rcx
|
||||
movb (%rdi),%al; addq $1,%rdi
|
||||
decq %rcx; jnz ckloop2 # prefix cannot overlap previous displacement
|
||||
jmp ckend
|
||||
ckcount:
|
||||
decq %rcx; jnz ckloop3
|
||||
ckend:
|
||||
ret
|
||||
@@ -0,0 +1,68 @@
|
||||
/* amd_d_nrv2b.S -- AMD64 decompressor for NRV2B
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2000-2005 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
.p2align 3
|
||||
lit_n2b:
|
||||
incq %rsi; movb %dl,(%rdi)
|
||||
incq %rdi
|
||||
top_n2b:
|
||||
movb (%rsi),%dl # speculate: literal, or bottom 8 bits of offset
|
||||
jnextb1yp lit_n2b
|
||||
lea 1(lenq),off # [len= 0] off= 1
|
||||
offmore_n2b:
|
||||
getnextbp(off)
|
||||
jnextb0np offmore_n2b
|
||||
|
||||
subl $ 3,off; jc len_n2b # use previous offset
|
||||
shll $ 8,off; movzbl %dl,%edx
|
||||
orl %edx,off; incq %rsi
|
||||
xorl $~0,off; jz eof
|
||||
movslq off,disp # XXX: 2GB
|
||||
len_n2b:
|
||||
lea 1(lenq),off # [len= 0] off= 1
|
||||
getnextb(len); getnextb(len) # two bits; cc set on result
|
||||
jnz gotlen_n2b # raw 1,2,3 ==> 2,3,4
|
||||
movl off,len # len= 1, the msb
|
||||
addl $3-1,off # raw 2.. ==> 5..
|
||||
lenmore_n2b:
|
||||
getnextb(len)
|
||||
jnextb0n lenmore_n2b
|
||||
gotlen_n2b:
|
||||
cmpq $-0xd00,disp
|
||||
adcl off,len # len += off + (disp < -0xd00)
|
||||
call copy
|
||||
bot_n2b: # In: 0==len
|
||||
jmp top_n2b
|
||||
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/* amd_d_nrv2e.S -- AMD64 decompressor for NRV2E
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2000-2005 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
.p2align 3
|
||||
lit_n2e:
|
||||
incq %rsi; movb %dl,(%rdi)
|
||||
incq %rdi
|
||||
top_n2e:
|
||||
movb (%rsi),%dl # speculate: literal, or bottom 8 bits of offset
|
||||
jnextb1yp lit_n2e
|
||||
lea 1(lenq),off # [len= 0] off= 1
|
||||
jmp getoff_n2e
|
||||
|
||||
off_n2e:
|
||||
dec off
|
||||
getnextbp(off)
|
||||
getoff_n2e:
|
||||
getnextbp(off)
|
||||
jnextb0np off_n2e
|
||||
|
||||
subl $ 3,off; jc offprev_n2e
|
||||
shll $ 8,off; movzbl %dl,%edx
|
||||
orl %edx,off; incq %rsi
|
||||
xorl $~0,off; jz eof
|
||||
sarl off # Carry= original low bit
|
||||
movslq off,disp # XXX: 2GB
|
||||
jc lenlast_n2e
|
||||
jmp lenmore_n2e
|
||||
|
||||
offprev_n2e:
|
||||
jnextb1y lenlast_n2e
|
||||
lenmore_n2e:
|
||||
incl len # len= 1
|
||||
jnextb1y lenlast_n2e
|
||||
len_n2e:
|
||||
getnextb(len)
|
||||
jnextb0n len_n2e
|
||||
addl $6-2-2,len
|
||||
jmp gotlen_n2e
|
||||
|
||||
lenlast_n2e:
|
||||
getnextb(len) # 0,1,2,3
|
||||
gotlen_n2e:
|
||||
cmpq $-0x500,disp
|
||||
adcl $2,len # len += 2+ (disp < -0x500);
|
||||
call copy
|
||||
bot_n2e: # In: 0==len
|
||||
jmp top_n2e
|
||||
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/* NOTE: THE FIRST ARGUMENT IS arg1, NOT arg0. */
|
||||
#define arg1 rdi
|
||||
#define arg1l edi
|
||||
#define arg2 rsi
|
||||
#define arg2l esi
|
||||
#define arg3 rdx
|
||||
#define arg3l edx
|
||||
#define arg4 rcx
|
||||
#define arg4l ecx
|
||||
#define sys4 r10 # 4th arg to syscall is not in %rcx
|
||||
#define sys4l r10d
|
||||
#define arg5 r8
|
||||
#define arg5l r8d
|
||||
#define arg6 r9
|
||||
#define arg6l r9d
|
||||
@@ -0,0 +1,129 @@
|
||||
/* arm_nrv2b_d32.S -- ARM decompressor for NRV2B
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#define src r0
|
||||
#define len r1
|
||||
#define dst r2
|
||||
#define tmp r3
|
||||
#define bits r4
|
||||
#define off r5
|
||||
#define g1b r6
|
||||
#define wrnk r7 /* 0xd00 M2_MAX_OFFSET before "wrinkle" */
|
||||
|
||||
/* r12 ("ip") is assumed to be a scratch register. */
|
||||
|
||||
#define GETBIT blx g1b
|
||||
|
||||
#define getnextb(reg) GETBIT; adc reg,reg
|
||||
#define jnextb0 GETBIT; bcc
|
||||
#define jnextb1 GETBIT; bcs
|
||||
|
||||
ucl_nrv2b_decompress_32: .globl ucl_nrv2b_decompress_32 @ ARM mode
|
||||
.type ucl_nrv2b_decompress_32, %function
|
||||
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst) */
|
||||
adr r12,1+go_thumb_n2b @ load pc-relative address
|
||||
bx r12 @ enter THUMB mode
|
||||
|
||||
.code 16 @ THUMB mode
|
||||
go_thumb_n2b:
|
||||
add r1,len,src @ r1= eof_src;
|
||||
push {r1,r2,r3, r4,r5,r6,r7, lr}
|
||||
mov bits,#1; neg off,bits @ off= -1 initial condition
|
||||
lsl bits,#31 @ 1<<31: refill next time
|
||||
mov wrnk,#0xd
|
||||
lsl wrnk,#8 @ 0xd00
|
||||
adr g1b,get1b @ load pc-relative address
|
||||
b top_n2b
|
||||
|
||||
eof_n2b:
|
||||
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
|
||||
sub src,r1 @ 0 if actual src length equals expected length
|
||||
sub dst,r3 @ actual dst length
|
||||
str dst,[r4]
|
||||
pop {r4,r5,r6,r7, pc} @ return
|
||||
|
||||
lit_n2b:
|
||||
ldrb tmp,[src]; add src,#1
|
||||
strb tmp,[dst]; add dst,#1
|
||||
top_n2b:
|
||||
jnextb1 lit_n2b
|
||||
|
||||
mov len,#1 @ the msb
|
||||
getoff_n2b: @ ss11 len= [2..)
|
||||
getnextb(len)
|
||||
jnextb0 getoff_n2b
|
||||
|
||||
sub tmp,len,#3 @ set Carry
|
||||
mov len,#0 @ Carry unaffected
|
||||
blo offprev_n2b @ ss11 returned 2
|
||||
lsl tmp,#8
|
||||
ldrb off,[src]; add src,#1 @ low 8 bits
|
||||
orr off,tmp
|
||||
mvn off,off; beq eof_n2b @ off= ~off
|
||||
offprev_n2b: @ In: 0==len
|
||||
getnextb(len); getnextb(len); bne plus1_n2b @ two bits; 1,2,3 ==> 2,3,4
|
||||
|
||||
mov len,#1 @ the msb
|
||||
getlen_n2b: @ ss11 len= [2..)
|
||||
getnextb(len)
|
||||
jnextb0 getlen_n2b
|
||||
|
||||
add len,#2 @ [2..) ==> [4..);
|
||||
plus1_n2b:
|
||||
add len,#1 @ 1,2,3 ==> 2,3,4; [4..) ==> [5..)
|
||||
/* 'cmn': add the inputs, set condition codes, discard the sum */
|
||||
cmn off,wrnk; bcs near_n2b @ within M2_MAX_OFFSET
|
||||
add len,#1 @ too far away, so minimum match length is 3
|
||||
near_n2b:
|
||||
ldrb tmp,[dst] @ force cacheline allocate
|
||||
copy_n2b:
|
||||
ldrb tmp,[dst,off]
|
||||
strb tmp,[dst]; add dst,#1
|
||||
sub len,#1; bne copy_n2b
|
||||
b top_n2b
|
||||
|
||||
.code 32 @ ARM mode
|
||||
get1b: @ Out: Carry= next_bit
|
||||
adds bits,bits,bits @ shift up, set Carry
|
||||
bxne lr @ return if reload is not needed
|
||||
/* In: Carry set (unchanged until final adcs) */
|
||||
ldrb bits,[src],#1
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #1*8
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #2*8
|
||||
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #3*8
|
||||
adcs bits,bits,bits @ Carry= next_bit; set bit0 flag from CarryIn
|
||||
bx lr
|
||||
|
||||
.size ucl_nrv2b_decompress_32, .-ucl_nrv2b_decompress_32
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user