Compare commits
477 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 814eabb88e | |||
| 95021e4977 | |||
| d17fb7ebf0 | |||
| df9aa9ac32 | |||
| 9110517893 | |||
| 8204c7deb6 | |||
| 6662f8985e | |||
| a2b305ed3b | |||
| ce3d3a850c | |||
| 212b674bc2 | |||
| 2980a6b4bb | |||
| 435c0a9e82 | |||
| 4102cd7c91 | |||
| b4b603819d | |||
| 20e3707e69 | |||
| fc6eeaaea8 | |||
| 41799955ce | |||
| efb4ec9cb8 | |||
| 4dbda29f82 | |||
| befaa3c501 | |||
| f41edf9e21 | |||
| 754f10f0b0 | |||
| 5d331fdf69 | |||
| cbf1dbe2cb | |||
| 3177de92fb | |||
| 3878890783 | |||
| 61594f7873 | |||
| f412b5e0cd | |||
| f14d594a1a | |||
| f0279d23d3 | |||
| 18ef55ac14 | |||
| 0010c50de6 | |||
| 130699a33b | |||
| 5a8d60d3e0 | |||
| 603dc83c1a | |||
| 51106e730b | |||
| 23ec864130 | |||
| 5349bd0b2a | |||
| 74d70fe1d9 | |||
| 041865c320 | |||
| 6a7d555ad7 | |||
| 18262f79c7 | |||
| 9769599f1d | |||
| aee150474c | |||
| 0e45021a5a | |||
| 241abcc89c | |||
| 90fc32a56e | |||
| 7ce85ab712 | |||
| 55cde23f10 | |||
| a19e6cd4f5 | |||
| 06f8c55908 | |||
| b10f68d20a | |||
| ed8a71bba1 | |||
| fee6f17caf | |||
| 767e4e2ce6 | |||
| 23f5370dcf | |||
| 37ae689328 | |||
| 123b33efd4 | |||
| 736ec9d9e5 | |||
| 5a94136764 | |||
| 1555be40b7 | |||
| 60b7a3c33b | |||
| a5d8e575bd | |||
| 23db1d375c | |||
| e06722d121 | |||
| 81e77a8b2b | |||
| 5c567c5a76 | |||
| b8e698bde3 | |||
| 440b5b2608 | |||
| 8b2e7ffe0b | |||
| 1018a96b31 | |||
| 5f87e9891b | |||
| 19564ed27e | |||
| f4022af48a | |||
| 2d1de8b9e9 | |||
| cdbfdee725 | |||
| ac64126a66 | |||
| 97153e8e09 | |||
| b9c976304a | |||
| 670b67cc98 | |||
| ccecaa741c | |||
| 07230edec0 | |||
| de1a4b4da4 | |||
| aba5c40b17 | |||
| a55b3480ef | |||
| bcb5e7d852 | |||
| e4f6378dfe | |||
| f616d2edf1 | |||
| bffb138b9c | |||
| b49fc6c081 | |||
| 570b195ed6 | |||
| b0e961b90b | |||
| 919a899c39 | |||
| 655094239c | |||
| 8eda698a9c | |||
| d1753c6df9 | |||
| 3db0b0e8fe | |||
| 8d5d6bd1a5 | |||
| 05f6f4d2ff | |||
| 9e154e33c3 | |||
| 5125f4d4ac | |||
| 365a3c0432 | |||
| ab37b5ea0c | |||
| 20ddd8590d | |||
| 69d9aa6c69 | |||
| 2163231401 | |||
| f513373693 | |||
| ed0e3b9af4 | |||
| 4205c699ac | |||
| 4e64cdac15 | |||
| bbbea34d74 | |||
| 66565f7238 | |||
| 9cb922425e | |||
| 268e13c572 | |||
| 03f1f615e5 | |||
| 94152391b1 | |||
| 2d403e07bb | |||
| 48ec581539 | |||
| f9054529c1 | |||
| 67d9ff987c | |||
| a3bb8f00fd | |||
| 48846c7226 | |||
| ad8648f668 | |||
| c7224c7727 | |||
| b2949259c5 | |||
| 757bdd1264 | |||
| ec1e5849eb | |||
| 1752fab911 | |||
| b0748388b2 | |||
| 175899013e | |||
| c448d15a8f | |||
| 5c7bca5b3e | |||
| 390cdbba2d | |||
| 256b8f066f | |||
| 30915862cd | |||
| eeb1dfaf8f | |||
| 90161bc3a7 | |||
| a1064dc2cb | |||
| b8a9b321fa | |||
| a3e80b1628 | |||
| 350ebfc47d | |||
| b9b75c536c | |||
| 8b74704bbf | |||
| bead894e49 | |||
| 502f9b5a00 | |||
| cd15b7d5af | |||
| 0c1d544e98 | |||
| 728be1867f | |||
| 09578df46b | |||
| b29f5b7c09 | |||
| 10f602fca7 | |||
| 2f8917f450 | |||
| b57f48d543 | |||
| 87a4d8455d | |||
| b14df392fa | |||
| 437c34a68c | |||
| b218cec3d7 | |||
| f19c91243a | |||
| 882e1be2db | |||
| 8e21c1e965 | |||
| f3970eaed9 | |||
| ac4b8f8617 | |||
| 51c28020de | |||
| fd525ae7df | |||
| a282171318 | |||
| c3040d1636 | |||
| c76c07aea0 | |||
| 1282ed333a | |||
| 32e76e88cf | |||
| fc0d3ff118 | |||
| 0bd05c0d67 | |||
| ff2c5300b8 | |||
| a38989dfbf | |||
| e387c6bc56 | |||
| 5eb81c0ec4 | |||
| f92b617c43 | |||
| 8f25c72085 | |||
| 7860e7a249 | |||
| a2e3ceb8c8 | |||
| e96ad21db1 | |||
| 888ac8a220 | |||
| 29db8bca3a | |||
| 63d49f0143 | |||
| 378224c6ba | |||
| 2f3e7a82b5 | |||
| 960f020277 | |||
| 6962da718c | |||
| 42575d9f57 | |||
| 03fb0d95c6 | |||
| beb766b005 | |||
| 29c1f67057 | |||
| a709b38065 | |||
| ec5840fb2a | |||
| 9511e3c9b1 | |||
| 9190e7d51a | |||
| cff830c43b | |||
| e31c45dc10 | |||
| e1da733810 | |||
| b8c34036a5 | |||
| d771f219f0 | |||
| d8280343f9 | |||
| c7b9395866 | |||
| 992ceee52b | |||
| 2162a01848 | |||
| 102e0f0a98 | |||
| 4e0967e0a1 | |||
| 73dc4eede0 | |||
| 5e5ea9f6e4 | |||
| e537f25857 | |||
| 47aea88c27 | |||
| 0237bf8915 | |||
| 3a7032f21c | |||
| 54d01790b5 | |||
| fb3375112e | |||
| 554f22a14f | |||
| eb6a6e3909 | |||
| 041947507f | |||
| ff03ac17b2 | |||
| 12c6cd8021 | |||
| de6e8c8020 | |||
| f3b64cfe78 | |||
| 1e8214cd3f | |||
| 7802257700 | |||
| 60031bed47 | |||
| d7e795a731 | |||
| c0cccd6196 | |||
| 6cd0d5d779 | |||
| f66d8f98c9 | |||
| a94a3e9741 | |||
| c798242bfe | |||
| 80622d4037 | |||
| 5ac2eed3d9 | |||
| 33ec757c41 | |||
| b6c84d19ab | |||
| f91849ec4b | |||
| 46ae6e1c2a | |||
| 7cbf7af6e8 | |||
| 7f69f5937a | |||
| e0ad859eef | |||
| f5a2641ea1 | |||
| ccaff85870 | |||
| af65e40986 | |||
| f41e3c01f4 | |||
| e8b97a12a9 | |||
| 8744f6bd7f | |||
| 204f4eefd8 | |||
| 7af193df77 | |||
| b082a6f1da | |||
| ce1e5b5ae1 | |||
| 565360a3f2 | |||
| 69cec874a1 | |||
| 66206e8dd7 | |||
| 44c1879e27 | |||
| a9bb95fefd | |||
| 4ad2242e96 | |||
| 1e1e333d61 | |||
| 81efdd41f4 | |||
| ac245b39d5 | |||
| cecfaaf63e | |||
| 8d37bb4469 | |||
| b710f2d69f | |||
| d96646b0e0 | |||
| c069efaa1b | |||
| 25b12eb38a | |||
| 6779559ba2 | |||
| 4e411eab59 | |||
| 1ba9ce283b | |||
| bd191af41b | |||
| 13f4f7ffdd | |||
| db62588d47 | |||
| 17325c7939 | |||
| e275e7614e | |||
| d383b1e1a3 | |||
| 973579f462 | |||
| 05db38225a | |||
| 3b771656bb | |||
| fe531960ab | |||
| accbc5d809 | |||
| fa5b74b763 | |||
| 124cdfda37 | |||
| 8ad3d01d81 | |||
| 448baac0f4 | |||
| e225d77146 | |||
| 74a2d9486b | |||
| 6b74aa2673 | |||
| 9f4a0fedbf | |||
| 9b079b371d | |||
| 1439dace83 | |||
| 44a6ac4c2a | |||
| 08826398af | |||
| 5fccfc65ec | |||
| 91d64a8871 | |||
| b9e92ba9fa | |||
| d88078aa28 | |||
| 188b952621 | |||
| 804a8bb853 | |||
| ab229ac261 | |||
| ff2bbb7a31 | |||
| c8fb0994ed | |||
| fd13f41294 | |||
| 4b15d30c2a | |||
| 076d862ee0 | |||
| f7d66c8b50 | |||
| 1ef25b356c | |||
| 7e06892ad7 | |||
| f1ccb85658 | |||
| a08b3ee882 | |||
| f0fafa3ba7 | |||
| 9c1feb24e6 | |||
| f4aa80e6b4 | |||
| 14d22d29b1 | |||
| 666e8c2f2f | |||
| 4a462f3c9a | |||
| 789cfea682 | |||
| ead8daf26c | |||
| 2dfb82d5b9 | |||
| 83bcbb8299 | |||
| d85f48fb97 | |||
| e4660b8608 | |||
| 96141d82f4 | |||
| ef17dc10ca | |||
| caca5ffa12 | |||
| e08d3858be | |||
| 0e063b9759 | |||
| 6dbdef9d57 | |||
| 81c58d9727 | |||
| 54701e0c46 | |||
| 069417499f | |||
| 5aec670621 | |||
| 16e9f168b9 | |||
| 8897c3d4cb | |||
| 48a520708b | |||
| 4a142f35f5 | |||
| a30bb7db20 | |||
| 61842b4bcb | |||
| 0cae01772c | |||
| 6a95c11cf9 | |||
| 401567f852 | |||
| 475326691d | |||
| a63b02ab69 | |||
| 2ff824e631 | |||
| e866b2231f | |||
| 451487ef80 | |||
| 4d64bd7e66 | |||
| 2e21de073d | |||
| 8675f378b6 | |||
| 238a369948 | |||
| 7db6c25c6a | |||
| bcbc59f04e | |||
| 1f1f03eaf4 | |||
| c9a1173698 | |||
| 3ba4cd5919 | |||
| 2c9f6b28f7 | |||
| 79aff4c12d | |||
| 40fddf1715 | |||
| 9005e50049 | |||
| dc7493e283 | |||
| 8f65fc1ab7 | |||
| 3d732625a7 | |||
| 5f678d10cb | |||
| 2a55ac04ce | |||
| 2feb5a47ac | |||
| 27deeccdb3 | |||
| c7f12f3a74 | |||
| 99f0f0120b | |||
| 34070f0b93 | |||
| f300b31d8d | |||
| bc5f9fb0a3 | |||
| 7371c219b1 | |||
| d5dd445a06 | |||
| b7f0187e9c | |||
| e982426885 | |||
| 6447666284 | |||
| ea4fcebf33 | |||
| 94f7d49522 | |||
| bbf2938719 | |||
| df9db96bd1 | |||
| 4d45677160 | |||
| 2981596fc3 | |||
| ecce4d6578 | |||
| bf52b5eb06 | |||
| d8baf6d1e8 | |||
| 4322931d97 | |||
| ad4bf703f0 | |||
| 342679b6d3 | |||
| 4a52be76fe | |||
| afc55d76e7 | |||
| 9e53f19b02 | |||
| 8614bca405 | |||
| 5f3bdaeebe | |||
| fd81cd2ae0 | |||
| bc6599ae51 | |||
| 6c2c174926 | |||
| 9205d0be65 | |||
| 199e274cac | |||
| c9a36d51c4 | |||
| 7bffc86777 | |||
| ce1b58d293 | |||
| 4d2b35c9ee | |||
| 47168972da | |||
| dee289e2d9 | |||
| 1fc7c7898b | |||
| dfc8a0d548 | |||
| daa0fe353b | |||
| 766b3edeee | |||
| 8e90fd0b63 | |||
| 9a00a9027d | |||
| e2a45c8f97 | |||
| ee69861fb5 | |||
| 5b97d3ee09 | |||
| 38ab492030 | |||
| 266d992017 | |||
| 0979848bdc | |||
| 3d371be0e5 | |||
| f96955b9f0 | |||
| 794d048bf2 | |||
| 595afd8964 | |||
| da8fadb203 | |||
| ca7c07e817 | |||
| bf95f93cad | |||
| 7766b08f08 | |||
| 823ac11eb3 | |||
| c5e61413a4 | |||
| df4726eb95 | |||
| 25a6da5638 | |||
| 5ddec963d0 | |||
| 597143df7f | |||
| 572082ac2b | |||
| d328e834b1 | |||
| aa540f85fa | |||
| 1084d86063 | |||
| a43d93512d | |||
| a8177201ef | |||
| 85bebf0b43 | |||
| f36feee0dc | |||
| c0bbc2216e | |||
| 8ce23f15e8 | |||
| 0b01be7b29 | |||
| ceebd3518b | |||
| a9249c6335 | |||
| dc22e6f158 | |||
| 1c7a34b367 | |||
| 526ae77b08 | |||
| 82698fb4b0 | |||
| 63ead04054 | |||
| 5727461522 | |||
| cd4292dd55 | |||
| 11ee8627b8 | |||
| 65ad79d727 | |||
| 85920ea8b1 | |||
| f4d2287e57 | |||
| 8a77a477df | |||
| 5a497e2dac | |||
| 7d5042012b | |||
| d2625d8607 | |||
| c3ec6b73e5 | |||
| 0ffe40c621 | |||
| 537f9111ae | |||
| d168d85650 | |||
| dbbc47a334 | |||
| 47760c37fc | |||
| 9fc785199a | |||
| f4f70634a1 | |||
| 046df6da76 | |||
| facca7b891 | |||
| a254e81ba9 | |||
| 09eb201b76 | |||
| b0226b54bd | |||
| 1d948c839d | |||
| 5d74b7252d | |||
| e787805b81 | |||
| 166d91ac48 | |||
| 2bb2124356 | |||
| 29ae1b7231 | |||
| 06dc67da49 | |||
| 42fe803a39 | |||
| 1dcaedab30 |
+4
-2
@@ -1,5 +1,7 @@
|
||||
.cvsignore
|
||||
.mfxcvsup
|
||||
_darcs
|
||||
B
|
||||
ChangeLog.cvs*
|
||||
TODO.*
|
||||
build
|
||||
doxygen
|
||||
maint
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
|
||||
http://upx.tsx.org
|
||||
Copyright (c) 1996-2004 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
Limitations and other things which are not (yet) supported:
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
# Toplevel Makefile for UPX
|
||||
|
||||
all:
|
||||
$(MAKE) -C src/stub
|
||||
$(MAKE) -C src
|
||||
$(MAKE) -C doc
|
||||
SHELL = /bin/sh
|
||||
|
||||
mostlyclean clean distclean maintainer-clean:
|
||||
srcdir = .
|
||||
top_srcdir = .
|
||||
|
||||
|
||||
default:
|
||||
@echo "UPX info: please choose a target for 'make'"
|
||||
|
||||
all mostlyclean clean distclean maintainer-clean:
|
||||
$(MAKE) -C src/stub/util/sstrip $@
|
||||
$(MAKE) -C src/stub $@
|
||||
$(MAKE) -C src $@
|
||||
$(MAKE) -C doc $@
|
||||
@@ -13,12 +18,16 @@ mostlyclean clean distclean maintainer-clean:
|
||||
dist: distclean
|
||||
false
|
||||
|
||||
zip:
|
||||
cd .. && rm -f upx-current.zip && zip -r upx-current.zip upx
|
||||
|
||||
cvs-admin-ko:
|
||||
cvs admin -ko .
|
||||
cvs update
|
||||
cvs update -P -d
|
||||
|
||||
ChangeLog:
|
||||
perl scripts/cvs2cl.pl --utc -f ChangeLog.cvs
|
||||
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
|
||||
|
||||
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
.PHONY: dist cvs-admin-ko ChangeLog
|
||||
|
||||
@@ -2,14 +2,119 @@
|
||||
User visible changes for UPX
|
||||
==================================================================
|
||||
|
||||
[ UNSTABLE BETA VERSION - please see README.1ST for some more info ]
|
||||
|
||||
Changes in 1.92 beta (20 Jul 2004):
|
||||
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
|
||||
* win32/pe: added option `--strip-loadconf' to strip the SEH load config section
|
||||
* win32/pe: try to detect .NET (win32/net) files [not yet supported by UPX]
|
||||
* vmlinux/386: new format that directly supports building Linux kernels
|
||||
* source code: now compiles cleanly under Win64
|
||||
|
||||
Changes in 1.91 beta (30 Jun 2004):
|
||||
* djgpp2/coff: added support for recent binutils versions
|
||||
* linux/elf386, linux/sh386: lots of improvements
|
||||
* vmlinuz/386: added support for recent kernels
|
||||
* watcom/le: don't crash on files without relocations
|
||||
* win32/pe: stricter checks of some PE values
|
||||
* option `--brute' now implies `--crp-ms=999999'.
|
||||
* source code: much improved portability using ACC, the
|
||||
Automatic Compiler Configuration
|
||||
* source code: compile fixes for strict ISO C++ compilers
|
||||
* source code: compile fixes for Win64
|
||||
* re-synced with upx 1.25 branch
|
||||
|
||||
Changes in 1.90 beta (11 Nov 2002):
|
||||
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
|
||||
* implemented several new options for finer compression control:
|
||||
`--all-methods', `--all-filters' and `--brute'
|
||||
* ps1/exe: new format - UPX now supports PlayStation One programs
|
||||
* linux/386: added the option `--force-execve'
|
||||
* vmlinuz/386: better kernel detection and sanity checks
|
||||
* re-synced with upx 1.24 branch
|
||||
* documentation updates
|
||||
|
||||
Changes in 1.11 beta (20 Dec 2000):
|
||||
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING!!! REALLY.
|
||||
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
|
||||
* vmlinuz/386: new format - UPX now supports bootable linux kernels
|
||||
* linux/386: added the new direct-to-memory executable formats - no
|
||||
* linux/elf386: added the new ELF direct-to-memory executable format - no
|
||||
more temp files are needed for decompression!
|
||||
* linux/sh386: added the new shell direct-to-memory executable format - no
|
||||
more temp files are needed for decompression!
|
||||
* reduced overall memory requirements during packing
|
||||
* quite a number of internal source code rearrangements
|
||||
|
||||
==================================================================
|
||||
|
||||
Changes in 1.25 (29 Jun 2004)
|
||||
* INFO: http://upx.sourceforge.net is the permanent UPX home page
|
||||
* watcom/le: don't crash on files without relocations
|
||||
* win32/pe: stricter checks of some PE values
|
||||
* source code: much improved portability using ACC, the
|
||||
Automatic Compiler Configuration
|
||||
* source code: compile fixes for strict ISO C++ compilers
|
||||
* source code: compile fixes for Win64
|
||||
|
||||
Changes in 1.24 (07 Nov 2002)
|
||||
* djgpp2/coff: stricter check of the COFF header to work around a
|
||||
problem with certain binutils versions
|
||||
|
||||
Changes in 1.23 (05 Sep 2002)
|
||||
* atari/tos: fixed an unpacking problem where a buffer was too
|
||||
small (introduced in 1.22)
|
||||
* linux/386: don't give up too early if a single block turns out
|
||||
to be incompressible
|
||||
* documentation: added some quick tips how to achieve the best
|
||||
compression ratio for the final release of your application
|
||||
* fixed a rare situation where the exit code was not set correctly
|
||||
|
||||
Changes in 1.22 (27 Jun 2002)
|
||||
* atari/tos: the stub now flushes the CPU cache to avoid
|
||||
problems on 68030+ machines
|
||||
* source code: additional compiler support for Borland C++,
|
||||
Digital Mars C++ and Watcom C++
|
||||
|
||||
Changes in 1.21 (01 Jun 2002)
|
||||
* 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.
|
||||
* source code: portability fixes
|
||||
* source code: compile fixes for g++ 3.0 and g++ 3.1
|
||||
|
||||
Changes in 1.20 (23 May 2001)
|
||||
* slightly faster compression
|
||||
* work around a gcc problem in the latest djgpp2 distribution
|
||||
* watcom/le: fixed detection of already compressed files
|
||||
* win32/pe: do not compress RT_MANIFEST resource types
|
||||
* win32/pe: improved the error message for empty resource sections
|
||||
* [NOTE: the jump from 1.08 to 1.20 is to avoid confusion with
|
||||
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
|
||||
|
||||
Changes in 1.07 (20 Feb 2001)
|
||||
* win32/pe: corrected the TLS callback check
|
||||
* win32/pe: really fixed that rare bug in relocation handling
|
||||
* win32/pe: experimental support for SizeOfHeaders > 0x1000
|
||||
* win32/pe: check for superfluous data between sections
|
||||
* win32/pe: compressing screensavers (.scr) should finally work
|
||||
|
||||
Changes in 1.06 (27 Jan 2001)
|
||||
* win32/pe: the check for TLS callbacks introduced in 1.05
|
||||
was too strict - disabled for now
|
||||
* dos/com: decreased the decompressor stack size a little bit
|
||||
|
||||
Changes in 1.05 (24 Jan 2001)
|
||||
* win32/pe: refuse to compress programs with TLS callbacks
|
||||
* win32/pe: stub changes to avoid slowdowns with some virus monitors
|
||||
* win32/pe: reverted the relocation handling changes in 1.04
|
||||
* linux/386: dont try to compress Linux kernel images (have a look
|
||||
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'
|
||||
* win32/pe: fixed a rare bug in the relocation handling code
|
||||
@@ -188,7 +293,7 @@ Changes in 0.60 (06 Mar 1999)
|
||||
* fixed a bug which could make UPX hang when an exe header contained
|
||||
an illegal value
|
||||
* added some compression flags for the win32/pe format
|
||||
* added support for Atari ST executables (atari/tos)
|
||||
* added support for Atari ST/TT executables (atari/tos)
|
||||
* improved compression ratio
|
||||
* improved compression speed
|
||||
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
|
||||
http://upx.tsx.org
|
||||
Copyright (c) 1996-2004 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
Here are some possible projects from which you can choose if you'd like to
|
||||
@@ -31,8 +30,19 @@ User interface:
|
||||
More formats:
|
||||
-------------
|
||||
|
||||
- add more file formats / platforms (there were volunteers for FreeBSD,
|
||||
BeOS, Windows CE, Amiga, C64, ...)
|
||||
- Amiga
|
||||
|
||||
- BeOS
|
||||
|
||||
- C64
|
||||
|
||||
- elks/8086 (this is a 16-bit linux-8086 kernel)
|
||||
See http://www.elks.ecs.soton.ac.uk/
|
||||
|
||||
- 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")
|
||||
@@ -41,23 +51,20 @@ More formats:
|
||||
Existing formats:
|
||||
-----------------
|
||||
|
||||
- dos/com: add support for very long files - convert to exe if necessary
|
||||
- djgpp2/coff: add support for DLX dynamic loading
|
||||
(see SEAL http://www.home.sk/public/seal/ )
|
||||
|
||||
- dos/sys: add support for sys/exe combos
|
||||
- dos/com: add support for very long files - convert to exe if necessary
|
||||
|
||||
- dos/exe: implement filter support
|
||||
|
||||
- djgpp2/coff: add support for DLX dynamic loading
|
||||
(see SEAL http://www.home.sk/public/seal/ )
|
||||
- dos/sys: add support for sys/exe combos
|
||||
|
||||
- linux/i386:
|
||||
- use the new assembly preprocessor stuff (ie. process the file
|
||||
headers internally)
|
||||
- UPX uncompressor daemon
|
||||
- rewrite the stub in assembly (not sure if this is a good idea...)
|
||||
- etc...
|
||||
- linux/i386: add a special elf/i386 format that understands
|
||||
ELF files and has filter support
|
||||
|
||||
- watcom/le: add support for per section compression, LX support, VXD
|
||||
|
||||
@@ -65,8 +72,6 @@ Existing formats:
|
||||
of problems (like importing a DLL or function fails)
|
||||
- win32/pe: finer control over resource compression, per section
|
||||
compression
|
||||
- win32/pe: compressing screensavers looses the description - probably
|
||||
should not compress a special resource type
|
||||
|
||||
|
||||
Compression ratio:
|
||||
|
||||
@@ -8,34 +8,38 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
|
||||
http://upx.tsx.org
|
||||
Copyright (c) 1996-2004 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
WARNING - UNSTABLE BETA VERSION
|
||||
===============================
|
||||
|
||||
All versions 1.1x are unstable beta releases - use them only for testing,
|
||||
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.04, and the next stable release
|
||||
will be called version 1.20.
|
||||
The current stable release is 1.25, and the next stable release
|
||||
will be called version 2.00.
|
||||
|
||||
The main news since 1.04 are support for bootable Linux kernels ("vmlinuz/386")
|
||||
and direct Linux ELF-to-memory decompression ("linux/elf386"), so there's
|
||||
no reason to use the unstable versions unless you want to try the new formats.
|
||||
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
|
||||
=======
|
||||
|
||||
Welcome to UPX 1.0x, the first production release after almost two years
|
||||
of beta testing.
|
||||
Welcome to UPX !
|
||||
|
||||
Please don't forget to read the new LICENSE - UPX is now distributed
|
||||
Please don't forget to read the file LICENSE - UPX is distributed
|
||||
under the GNU General Public License (GPL) with special exceptions
|
||||
allowing the distribution of all compressed executables, including
|
||||
commercial programs.
|
||||
@@ -54,8 +58,8 @@ 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
|
||||
Win95/98/ME/NT/2000 programs and DLLs, DOS programs, and Linux
|
||||
executables and kernels.
|
||||
Windows 95/98/ME/NT/2000/XP programs and DLLs, DOS programs,
|
||||
and Linux executables and kernels.
|
||||
|
||||
UPX is free software distributed under the term of the GNU General
|
||||
Public License. Full source code is available.
|
||||
@@ -64,7 +68,7 @@ UPX may be distributed and used freely, even with commercial applications.
|
||||
See the UPX License Agreement for details.
|
||||
|
||||
UPX is rated number one in the well known Archive Comparison Test. Visit
|
||||
http://web.act.by.net/~act/act-exepack.html
|
||||
http://compression.ca/ .
|
||||
|
||||
UPX aims to be Commercial Quality Freeware.
|
||||
|
||||
@@ -87,7 +91,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 almost 2 years since our first public beta.
|
||||
actually it's more than 4 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.
|
||||
@@ -114,8 +118,7 @@ THE FUTURE
|
||||
This only gives people a false feeling of security because
|
||||
by definition all protectors/compressors can be broken.
|
||||
And don't trust any advertisment of authors of other executable
|
||||
compressors about this topic - just do a websearch on something
|
||||
like "procdump"...
|
||||
compressors about this topic - just do a websearch on "unpackers"...
|
||||
|
||||
- Fix all remaining bugs - keep your reports coming ;-)
|
||||
|
||||
@@ -126,8 +129,8 @@ THE FUTURE
|
||||
COPYRIGHT
|
||||
=========
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
@@ -146,7 +149,7 @@ Markus & Laszlo
|
||||
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
|
||||
|
||||
|
||||
|
||||
+12
-7
@@ -14,15 +14,20 @@
|
||||
WARNING - UNSTABLE BETA VERSION
|
||||
===============================
|
||||
|
||||
All versions 1.1x are unstable beta releases - use them only for testing,
|
||||
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.04, and the next stable release
|
||||
will be called version 1.20.
|
||||
|
||||
The main news since 1.04 are support for bootable Linux kernels ("vmlinuz/386")
|
||||
and direct Linux ELF-to-memory decompression ("linux/elf386"), so there's
|
||||
no reason to use the unstable versions unless you want to try the new formats.
|
||||
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
|
||||
|
||||
|
||||
+22
-22
@@ -60,20 +60,20 @@ Prerequisites
|
||||
-------------
|
||||
|
||||
- first of all you need to build the UCL compression library
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/ucl.html
|
||||
http://www.oberhumer.com/opensource/ucl/
|
||||
|
||||
|
||||
Tools needed to build/modify the UPX sources
|
||||
--------------------------------------------
|
||||
|
||||
- A modern C++ compiler like gcc 2.95.2 or Visual C++ 6
|
||||
(egcs 1.1.x may work, half-baked implementations like Borland C++ 5.5 won't)
|
||||
- A C++ compiler supporting inner classes, templates, exceptions
|
||||
and RTTI.
|
||||
|
||||
- GNU make for Win32
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/download/upx/tools/
|
||||
- GNU make 3.80 for Win32
|
||||
http://www.cygwin.com/
|
||||
|
||||
- GNU make for DOS
|
||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/
|
||||
- GNU make 3.80 for DOS
|
||||
http://www.delorie.com/djgpp/
|
||||
|
||||
|
||||
To compile the packer sources
|
||||
@@ -81,34 +81,34 @@ To compile the packer sources
|
||||
|
||||
set the environment variable UCLDIR to point to your UCL installation, e.g.
|
||||
|
||||
set UCLDIR=c:\src\ucl-0.92 (DOS / Windows)
|
||||
export UCLDIR=$HOME/local/src/ucl-0.92 (Unix)
|
||||
set UCLDIR=c:\src\ucl-1.02 (DOS / Windows)
|
||||
export UCLDIR=$HOME/local/src/ucl-1.02 (Unix)
|
||||
|
||||
then type
|
||||
|
||||
make target=linux # on linux
|
||||
make target=djgpp2 # for djgpp2
|
||||
make target=mingw32 # for mingw32
|
||||
make target=no-cygwin # for mingw32 as included in cygwin
|
||||
make target=msc # for Visual C++ 6.0
|
||||
make target=linux # linux
|
||||
make target=djgpp2 # dos32 - djgpp2
|
||||
make target=cygwin # win32 - cygwin 1.3.x
|
||||
make target=mingw32 # win32 - mingw32
|
||||
make target=no-cygwin # win32 - mingw32 as included in cygwin
|
||||
|
||||
|
||||
If you want to modify the stub sources you'll also need
|
||||
-------------------------------------------------------
|
||||
|
||||
- Nasm - the Netwide Assembler
|
||||
http://www.cryogen.com/Nasm
|
||||
|
||||
- Perl 5.004 or better
|
||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/perl*b.zip
|
||||
- Nasm 0.98.38 - the Netwide Assembler
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
http://sourceforge.net/projects/nasm/
|
||||
|
||||
- A68K - a 68000 macro assembler
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/download/upx/tools/
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
|
||||
- djasm - an assembler for the djgpp stub
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/download/upx/tools/
|
||||
http://upx.sourceforge.net/download/tools/
|
||||
|
||||
- Linux (for the linux/i386 stubs)
|
||||
- Perl 5.6 or better
|
||||
|
||||
- Linux (for the linux/386 stubs)
|
||||
|
||||
|
||||
Misc. notes
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
|
||||
http://upx.tsx.org
|
||||
Copyright (c) 1996-2004 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
.___.. .
|
||||
|
||||
@@ -1,187 +1,123 @@
|
||||
NOTE: this TODO list is completely out of date (~ Dec 1999)
|
||||
|
||||
===================================================================
|
||||
|
||||
- Rearrange this TODO list, sort by categories, add a priority (1-5)
|
||||
UPX TODO list. Last updated 2004-07-19.
|
||||
|
||||
|
||||
For 0.95:
|
||||
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
|
||||
|
||||
- FIXME: what do we want in 1.00 ???
|
||||
|
||||
- add NRV2D for dos/exe (use by default when >= 400 kB)
|
||||
|
||||
- implement switch `-m' for method: 1 NRV2B, 2 NRV2D
|
||||
|
||||
- DLL problem under NT ? is this fixed ???
|
||||
- stub ctojr32 needs CPU 486 because of bswap
|
||||
|
||||
|
||||
PE
|
||||
==
|
||||
OTHER:
|
||||
|
||||
- check all <const_cast> to make sure they are not invalid
|
||||
|
||||
- throwNotCompressible() is not a real error, so make the output nicer
|
||||
(info: bla bla). Also ui.cpp (total_*).
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
|
||||
IMPROVED COMPRESSION RATIO
|
||||
==========================
|
||||
|
||||
- experiment with new filters
|
||||
|
||||
- implement filters for dos/exe
|
||||
|
||||
- filters: could we exploit a f->firstcall info field ?
|
||||
|
||||
- for small programs (e.g. < 64k), try an additional algorithm
|
||||
to see if it gives better compression
|
||||
|
||||
|
||||
ALL FORMATS
|
||||
===========
|
||||
|
||||
- more thoroughly test the exe-header in canPack()
|
||||
and throw exceptions when encountering bad values.
|
||||
|
||||
- implement `--cpu=486' option to use bswap on the 32-bit formats
|
||||
(if cpu >= 486)
|
||||
|
||||
- consider removing "or ebp,-1" when not needed
|
||||
|
||||
|
||||
FORMAT DJGPP2/COFF
|
||||
==================
|
||||
|
||||
- handle overlays
|
||||
|
||||
- fix default file extension handling when the --coff option is set
|
||||
|
||||
|
||||
FORMAT DOS/EXE
|
||||
==============
|
||||
|
||||
- implement filters
|
||||
|
||||
- add a check so that we don't pack djgpp1 binaries
|
||||
|
||||
|
||||
FORMAT LINUX/386
|
||||
================
|
||||
|
||||
- don't mmap() the temporary output file - this seems to improve
|
||||
file io speed
|
||||
|
||||
|
||||
FORMAT TMT/ADAM
|
||||
===============
|
||||
|
||||
- the decompressors are already aligned, no need for an
|
||||
extra alignment
|
||||
|
||||
|
||||
FORMAT WATCOM/LE
|
||||
================
|
||||
|
||||
- handle files without relocations
|
||||
|
||||
- the decompressors are already aligned, no need for an
|
||||
extra alignment
|
||||
|
||||
- fix default file extension handling when the --le option is set
|
||||
|
||||
- handle holes in the file
|
||||
|
||||
- implement compressWithFilters()
|
||||
|
||||
- add a call to verifyOverlappingDecompression()
|
||||
|
||||
|
||||
FORMAT WIN16/NE
|
||||
===============
|
||||
|
||||
- implement readFileHeader() to correctly identify a win16/ne
|
||||
executable, so that the call for contribution will get thrown
|
||||
|
||||
|
||||
FORMAT WIN32/PE
|
||||
===============
|
||||
|
||||
- fix the section alignment with the Intel compiler
|
||||
|
||||
- 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
|
||||
|
||||
4 - easy - ml) put the original offset of moved resources somewhere into
|
||||
the res.dir. (if it's safe to do)
|
||||
|
||||
4 - ??? - ml) fix FIXMEs
|
||||
|
||||
5 - medium - ml) try to put the preprocessed imports & relocs back to their
|
||||
original section if possible this could save some virtual memory
|
||||
address space
|
||||
|
||||
|
||||
COM
|
||||
===
|
||||
|
||||
|
||||
EXE
|
||||
===
|
||||
|
||||
|
||||
|
||||
LE
|
||||
==
|
||||
|
||||
4 - easy - ml) the decompressors are already aligned, no need for an
|
||||
extra alignment
|
||||
|
||||
4 - difficult - ml) handle holes in the file
|
||||
|
||||
|
||||
TMT
|
||||
===
|
||||
|
||||
4 - easy - ml) the decompressors are already aligned, no need for an
|
||||
extra alignment
|
||||
|
||||
|
||||
LINUX
|
||||
=====
|
||||
|
||||
4 - ???)
|
||||
- test with AOUT binaries
|
||||
- test with Java binaries
|
||||
- make a compressed program suid. what happens ?
|
||||
|
||||
5 - difficult) rewrite the whole stub in assembly
|
||||
|
||||
|
||||
SPARC
|
||||
=====
|
||||
|
||||
3 - easy - ml) finish support - should generate byte-identical versions
|
||||
for all formats (except those which are using Packer::getRandomId())
|
||||
|
||||
|
||||
DJGPP2
|
||||
======
|
||||
|
||||
1 - ???) do we support overlays at all ???
|
||||
|
||||
5 - ???) fix file extension handling when the --coff option is set
|
||||
|
||||
|
||||
FOR 0.95
|
||||
========
|
||||
|
||||
- enable automatic dependency tracking
|
||||
|
||||
1 - mfx) determine when to use NRV2D, find best c_flags values for
|
||||
NRV2B & NRV2D (see util/runtest.sh)
|
||||
|
||||
5 - boring - mfx) Finally fix all screen and UI problems. How boring...
|
||||
Probably should think about the whole system (printf vs. fprintf vs.
|
||||
con_fprintf...)
|
||||
|
||||
5 - policy - ml+mfx) Discuss a default C++ style (GNU indent 2.2.3)
|
||||
with Laszlo and use it. Or maybe Artistic Style?
|
||||
|
||||
10) Examine why pod2text breaks lines within something like `B<--coff>'.
|
||||
(pod sucks anyway. unfortunately all alternatives as well.)
|
||||
|
||||
|
||||
MISC
|
||||
====
|
||||
|
||||
3 - difficult ml) The first two sentences of the README look too much like
|
||||
those from the aspack docs. Laszlo, could you rewrite this ?
|
||||
|
||||
1 - easy - mfx) Check whether the compressed size of the executable is
|
||||
really smaller than the uncompressed
|
||||
|
||||
1 - ??? - mfx) Implement a more informational interface.
|
||||
Probably add some global functions in msg.cpp.
|
||||
Should think about the requirements first, i.e. should there be
|
||||
some simple hierarchies (header1, header2, ...) etc. ?
|
||||
Could use the `-v' switch for enabling this (or `-i' ??).
|
||||
- Something like this would be fine: (with colors :-)
|
||||
[Processing kernel32.dll]
|
||||
[Import]
|
||||
3 DLL.
|
||||
Original size: 12345 bytes.
|
||||
Preprocessed size: 6789 bytes.
|
||||
[Relocations]
|
||||
Original size: 50000 bytes.
|
||||
Preprocessed size: 25000 bytes.
|
||||
[Exports]
|
||||
<warning> exports compressed (try --compress-export=0 if needed)
|
||||
[TLS]
|
||||
Added 56 bytes TLS data.
|
||||
Added 5 fixup records.
|
||||
[Resources]
|
||||
Directory size: 1234 bytes.
|
||||
Resource data size: 100000 bytes.
|
||||
Compressed resources: 8 (99900 bytes).
|
||||
Not compressed resources: 1 (100 bytes).
|
||||
|
||||
3 - ???) delete temporary files when something wrong happens
|
||||
|
||||
4 - easy - ml) Add a `--486' option to use bswap on the 32-bit formats.
|
||||
|
||||
4 - easy - ml) consider removing 'sbb bp,bp' or "or ebp,-1" when not needed
|
||||
|
||||
5 - ???) idea: --subfile=xx compress xx. subfile: we'd need a list_subfiles
|
||||
for this...
|
||||
|
||||
|
||||
FIXME: classify
|
||||
|
||||
GOALS FOR 0.90
|
||||
==============
|
||||
|
||||
- Provide additional NRV2D stubs for all 32-bit formats. Try to do this
|
||||
in a generic way so that we can possibly add more algorithms.
|
||||
Start by adding a `--nrv2d' switch.
|
||||
|
||||
FOR 0.90
|
||||
========
|
||||
|
||||
/ update the output of `--help'
|
||||
|
||||
- filters: implement the missing scan() function for f_cto32.
|
||||
Maybe could use this to try to find an optimal filter (e.g.
|
||||
if level >= 9) based on the counts.
|
||||
|
||||
- filters: could we have use for a f->firstcall info field ?
|
||||
|
||||
TODO
|
||||
====
|
||||
|
||||
- all formats: more thoroughly test the exe-header in canPack()
|
||||
and throw exceptions when encountering bad values.
|
||||
|
||||
- experiment with filters
|
||||
|
||||
- for small programs (e.g. < 64k) try an additional algorithm (like
|
||||
the non yet finished NRV2C) to see if it gives better compression ?
|
||||
|
||||
/ make checkerg++ work -> test
|
||||
|
||||
- fix file extension handling when the --coff option is set
|
||||
|
||||
- set up an "official" test suite
|
||||
|
||||
- finish documentation
|
||||
original section if possible. this could save some virtual memory
|
||||
address space.
|
||||
|
||||
|
||||
+3
-3
@@ -3,14 +3,14 @@ SHELL = /bin/sh
|
||||
top_srcdir = ..
|
||||
|
||||
PACKAGE = upx
|
||||
VERSION_DATE = 20 Dec 2000
|
||||
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING.*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||
VERSION_DATE = 20 Jul 2004
|
||||
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||
|
||||
TRIMSPACE = cat
|
||||
TRIMSPACE = sed -e 's/ *$$//'
|
||||
|
||||
BUILT_SOURCES = upx.1 upx.doc upx.html upx.man upx.ps upx.tex
|
||||
BUILT_SOURCES = upx.1 upx.doc upx.html upx.man
|
||||
BUILT_SOURCES = upx.1 upx.doc upx.html
|
||||
|
||||
|
||||
###
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
This documentation was written for those brave souls who want to
|
||||
This documentation is written for those brave souls who want to
|
||||
understand and/or modify the UPX assembly stubs - the small snippets
|
||||
that do the runtime decompression when a compressed program is started.
|
||||
|
||||
|
||||
+218
-78
@@ -12,36 +12,30 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
||||
|
||||
=head1 ABSTRACT
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996, 1997, 1998, 1999, 2000
|
||||
Markus F.X.J. Oberhumer, Laszlo Molnar & John F. Reiser
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
|
||||
http://upx.tsx.org
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2004 Markus Oberhumer & Laszlo Molnar
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
B<UPX> is a portable, extendable, high-performance executable packer for
|
||||
several different executable formats. It achieves an excellent compression
|
||||
ratio and offers I<*very*> fast decompression. Your executables suffer
|
||||
no memory overhead or other drawbacks for most of the formats supported.
|
||||
no memory overhead or other drawbacks for most of the formats supported,
|
||||
because of in-place decompression.
|
||||
|
||||
While you may use UPX freely for both non-commercial and commercial
|
||||
While you may use B<UPX> freely for both non-commercial and commercial
|
||||
executables (for details see the file LICENSE), we would highly
|
||||
appreciate if you credit UPX and ourselves in the documentation,
|
||||
possibly including a reference to the UPX home page. Thanks.
|
||||
appreciate if you credit B<UPX> and ourselves in the documentation,
|
||||
possibly including a reference to the B<UPX> home page. Thanks.
|
||||
|
||||
[ Using UPX in non-OpenSource applications without proper credits
|
||||
[ Using B<UPX> in non-OpenSource applications without proper credits
|
||||
is considered not politically correct ;-) ]
|
||||
|
||||
|
||||
|
||||
=head1 DISCLAIMER
|
||||
|
||||
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 2 1/2 years since our first public beta.
|
||||
B<UPX> comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
|
||||
|
||||
This is the first production quality release, and we plan that future 1.xx
|
||||
releases will be backward compatible with this version.
|
||||
@@ -57,7 +51,8 @@ B<UPX> is a versatile executable packer with the following features:
|
||||
- excellent compression ratio: compresses better than zip/gzip,
|
||||
use UPX to decrease the size of your distribution !
|
||||
|
||||
- very fast decompression: about 10 MB/sec even on my old Pentium 133
|
||||
- very fast decompression: about 10 MB/sec on an ancient Pentium 133,
|
||||
about 200 MB/sec on an Athlon XP 2000+.
|
||||
|
||||
- no memory overhead for your compressed executables for most of the
|
||||
supported formats
|
||||
@@ -76,6 +71,7 @@ B<UPX> is a versatile executable packer with the following features:
|
||||
* linux/386
|
||||
* linux/elf386
|
||||
* linux/sh386
|
||||
* ps1/exe
|
||||
* rtm32/pe
|
||||
* tmt/adam
|
||||
* vmlinuz/386 [bootable Linux kernel]
|
||||
@@ -91,7 +87,7 @@ B<UPX> is a versatile executable packer with the following features:
|
||||
the full source code of UPX is released under the GNU General Public
|
||||
License (GPL) !
|
||||
|
||||
You probably understand now why we call UPX the "I<ultimate>"
|
||||
You probably understand now why we call B<UPX> the "I<ultimate>"
|
||||
executable packer.
|
||||
|
||||
|
||||
@@ -105,7 +101,7 @@ specified on the command line.
|
||||
|
||||
=head2 Decompress
|
||||
|
||||
All UPX supported file formats can be unpacked using the B<-d> switch, eg.
|
||||
All B<UPX> supported file formats can be unpacked using the B<-d> switch, eg.
|
||||
B<upx -d yourfile.exe> will uncompress the file you've just compressed.
|
||||
|
||||
=head2 Test
|
||||
@@ -135,9 +131,7 @@ B<-q -q -q> (or B<-qqq>): produce no output at all
|
||||
|
||||
B<--help>: prints the help
|
||||
|
||||
B<--version>: print the version of UPX
|
||||
|
||||
B<--stdout>: writes all output to stdout
|
||||
B<--version>: print the version of B<UPX>
|
||||
|
||||
[ ...to be written... - type `B<upx --help>' for now ]
|
||||
|
||||
@@ -169,19 +163,43 @@ Compression level B<--best> may take a long time.
|
||||
|
||||
=back
|
||||
|
||||
Note that compression level B<-9> can be somewhat slow for large
|
||||
Note that compression level B<--best> can be somewhat slow for large
|
||||
files, but you definitely should use it when releasing a final version
|
||||
of your program.
|
||||
|
||||
Since UPX 0.70 there is also an extra compression level B<--best> which
|
||||
squeezes out even some more compression ratio. While it is usually fine
|
||||
to use this option with your favorite .com file it may take a long time
|
||||
to compress a multi-megabyte program. You have been warned.
|
||||
|
||||
Tips for even better compression:
|
||||
Quick start for achieving the best compression ratio:
|
||||
|
||||
=over 4
|
||||
|
||||
Try B<upx --brute myfile.exe>.
|
||||
|
||||
=back
|
||||
|
||||
Details for achieving the best compression ratio:
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Use the compression level B<--best>.
|
||||
|
||||
=item *
|
||||
|
||||
Try one or both of the options B<--all-methods> and B<--all-filters>.
|
||||
|
||||
=item *
|
||||
|
||||
Try the option B<--crp-ms=NUMBER>. This uses more memory during compression
|
||||
to achieve a (slightly) better compression ratio.
|
||||
|
||||
NUMBER must be a decimal value from 10000 to 999999, inclusive.
|
||||
The default value is 10000 (ten thousand).
|
||||
|
||||
=item *
|
||||
|
||||
Info: the option B<--brute> is an abbrevation for the options
|
||||
B<S<--best> S<--all-methods> S<--all-filters> S<--crp-ms=999999>>.
|
||||
|
||||
=item *
|
||||
|
||||
Try if B<--overlay=strip> works.
|
||||
@@ -196,9 +214,15 @@ For win32/pe programs there's B<--strip-relocs=0>. See notes below.
|
||||
|
||||
=head1 OVERLAY HANDLING OPTIONS
|
||||
|
||||
Info: An "overlay" means auxillary data atached after the logical end of
|
||||
an executable, and it often contains application specific data
|
||||
(this is a common practice to avoid an extra data file, though
|
||||
it would be better to use resource sections).
|
||||
|
||||
B<UPX> handles overlays like many other executable packers do: it simply
|
||||
copies the overlay after the compressed image. This works with some
|
||||
files, but doesn't work with others.
|
||||
files, but doesn't work with others, depending on how an application
|
||||
actually accesses this overlayed data.
|
||||
|
||||
Since version 0.90 UPX defaults to B<--overlay=copy> for
|
||||
all executable formats.
|
||||
@@ -216,25 +240,22 @@ all executable formats.
|
||||
=head1 ENVIRONMENT
|
||||
|
||||
The environment variable B<UPX> can hold a set of default
|
||||
options for UPX. These options are interpreted first and
|
||||
options for B<UPX>. These options are interpreted first and
|
||||
can be overwritten by explicit command line parameters.
|
||||
For example:
|
||||
|
||||
for DOS/Windows: set UPX=-9 --compress-icons#1
|
||||
for sh/ksh/zsh: UPX="-9 --compress-icons=1"; export UPX
|
||||
for csh/tcsh: setenv UPX "-9 --compress-icons=1"
|
||||
for DOS/Windows: set UPX=-9 --compress-icons#0
|
||||
for sh/ksh/zsh: UPX="-9 --compress-icons=0"; export UPX
|
||||
for csh/tcsh: setenv UPX "-9 --compress-icons=0"
|
||||
|
||||
Under DOS/Windows you must use '#' instead of '=' when setting the
|
||||
environment variable because of a COMMAND.COM limitation.
|
||||
|
||||
On Vax/VMS, the name of the environment variable is
|
||||
UPX_OPT, to avoid a conflict with the symbol set for
|
||||
invocation of the program.
|
||||
|
||||
Not all of the options are valid in the environment variable -
|
||||
UPX will tell you.
|
||||
B<UPX> will tell you.
|
||||
|
||||
You can use the B<--no-env> option to turn this support off.
|
||||
You can explicitly use the B<--no-env> option to ignore the
|
||||
environment variable.
|
||||
|
||||
|
||||
|
||||
@@ -242,17 +263,21 @@ You can use the B<--no-env> option to turn this support off.
|
||||
|
||||
=head2 NOTES FOR ATARI/TOS
|
||||
|
||||
This is the executable format used by the Atari ST/TT, a 68000 based
|
||||
personal computer which was popular in the late '80s. Support
|
||||
This is the executable format used by the Atari ST/TT, a Motorola 68000
|
||||
based personal computer which was popular in the late '80s. Support
|
||||
of this format is only because of nostalgic feelings of one of
|
||||
the authors and serves no practical purpose :-).
|
||||
See http://www.freemint.de for more info.
|
||||
|
||||
Packed programs will be byte-identical to the original after uncompression.
|
||||
All debug information will be stripped, though.
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
(none)
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
@@ -264,7 +289,7 @@ Same as vmlinuz/i386.
|
||||
|
||||
=head2 NOTES FOR DOS/COM
|
||||
|
||||
Obviously UPX won't work with executables that want to read data from
|
||||
Obviously B<UPX> won't work with executables that want to read data from
|
||||
themselves (like some commandline utilities that ship with Win95/98/ME).
|
||||
|
||||
Compressed programs only work on a 286+.
|
||||
@@ -277,13 +302,23 @@ Extra options available for this executable format:
|
||||
|
||||
--8086 Create an executable that works on any 8086 CPU.
|
||||
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
--all-filters Compress the program several times, using all
|
||||
available preprocessing filters. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default filter gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR DOS/EXE
|
||||
|
||||
dos/exe stands for all "normal" 16-bit DOS executables.
|
||||
|
||||
Obviously UPX won't work with executables that want to read data from
|
||||
Obviously B<UPX> won't work with executables that want to read data from
|
||||
themselves (like some command line utilities that ship with Win95/98/ME).
|
||||
|
||||
Compressed programs only work on a 286+.
|
||||
@@ -294,6 +329,11 @@ Extra options available for this executable format:
|
||||
|
||||
--no-reloc Use no relocation records in the exe header.
|
||||
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR DOS/SYS
|
||||
@@ -311,33 +351,51 @@ Extra options available for this executable format:
|
||||
|
||||
--8086 Create an executable that works on any 8086 CPU.
|
||||
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
--all-filters Compress the program several times, using all
|
||||
available preprocessing filters. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default filter gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR DJGPP2/COFF
|
||||
|
||||
First of all, it is recommended to use UPX *instead* of B<strip>. strip has
|
||||
First of all, it is recommended to use B<UPX> *instead* of B<strip>. strip has
|
||||
the very bad habit of replacing your stub with its own (outdated) version.
|
||||
Additionally UPX corrects a bug/feature in strip v2.8.x: it
|
||||
Additionally B<UPX> corrects a bug/feature in strip v2.8.x: it
|
||||
will fix the 4 KByte aligment of the stub.
|
||||
|
||||
UPX includes the full functionality of stubify. This means it will
|
||||
B<UPX> includes the full functionality of stubify. This means it will
|
||||
automatically stubify your COFF files. Use the option B<--coff> to
|
||||
disable this behaviour (see below).
|
||||
disable this functionality (see below).
|
||||
|
||||
UPX automatically handles Allegro packfiles.
|
||||
B<UPX> automatically handles Allegro packfiles.
|
||||
|
||||
The DLM format (a rather exotic shared library extension) is not supported.
|
||||
|
||||
Packed programs will be byte-identical to the original after uncompression.
|
||||
All debug information and trailing garbage will be stripped, though.
|
||||
|
||||
BTW, UPX is the successor of the DJP executable packer.
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
--coff Produce COFF output instead of EXE. By default
|
||||
UPX keeps your current stub.
|
||||
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
--all-filters Compress the program several times, using all
|
||||
available preprocessing filters. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default filter gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR LINUX [general]
|
||||
@@ -520,7 +578,7 @@ Extra options available for this executable format:
|
||||
Please read the general Linux description first.
|
||||
|
||||
Shell scripts where the underling shell accepts a ``-c'' argument
|
||||
can use the Linux/sh386 format. UPX decompresses the shell script
|
||||
can use the Linux/sh386 format. B<UPX> decompresses the shell script
|
||||
into low memory, then maps the shell and passes the entire text of the
|
||||
script as an argument with a leading ``-c''.
|
||||
It does not use space in /tmp, and does not use /proc.
|
||||
@@ -566,8 +624,9 @@ Extra options available for this executable format:
|
||||
|
||||
Please read the general Linux description first.
|
||||
|
||||
The generic linux/386 format deompresses to /tmp
|
||||
and needs /proc filesystem support.
|
||||
The generic linux/386 format decompresses to /tmp and needs
|
||||
/proc filesystem support. It starts the decompressed program
|
||||
via the execve() syscall.
|
||||
|
||||
Linux/386 is only selected if the specialized linux/elf386
|
||||
and linux/sh386 won't recognize a file.
|
||||
@@ -577,7 +636,7 @@ Packed programs will be byte-identical to the original after uncompression.
|
||||
How it works:
|
||||
|
||||
For files which are not ELF and not a script for a known "-c" shell,
|
||||
UPX uses kernel exec(), which first requires decompressing to a
|
||||
UPX uses kernel execve(), which first requires decompressing to a
|
||||
temporary file in the filesystem. Interestingly -
|
||||
because of the good memory management of the Linux kernel - this
|
||||
often does not introduce a noticable delay, and in fact there
|
||||
@@ -625,7 +684,54 @@ Specific drawbacks:
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
(none)
|
||||
--force-execve Force the use of the generic linux/386 "execve"
|
||||
format, i.e. do not try the linux/elf386 and
|
||||
linux/sh386 formats.
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR PS1/EXE
|
||||
|
||||
This is the executable format used by the Sony PlayStation (PSone),
|
||||
a Mips R3000 based gaming console which is popular since the late '90s.
|
||||
Support of this format is very similar to the Atari one, because of
|
||||
nostalgic feelings of one of the authors, but this format maybe serves
|
||||
a practical purpose ;-).
|
||||
|
||||
Packed programs will be byte-identical to the original after uncompression.
|
||||
|
||||
Maximum uncompressed size: ~1998848 bytes.
|
||||
|
||||
Notes:
|
||||
|
||||
- UPX creates as default a 'CD-Rom only' PS1/PS2 compatible executable.
|
||||
For transfer between client/target use options below.
|
||||
|
||||
- Normally the packed files use the same memory areas like the uncompressed
|
||||
versions, so they will not override other memory areas while unpacking.
|
||||
If this isn't possible UPX will abort showing a 'packed data overlap'
|
||||
error. With the "--force" option UPX will set a few 'bytes higher' loading
|
||||
offset for the packed file, but this isn't a real problem if it is a
|
||||
single or boot-only executable.
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
--console-run This enables client/target transfer compatibility.
|
||||
This format also run from a CD, except the "--no-align"
|
||||
option is used. Upto 2024 bytes larger files
|
||||
than [default] will be the result, also a
|
||||
slower decompression speed can be expected.
|
||||
|
||||
--no-align This option disables CD mode 2 data sector format
|
||||
alignment, and enables "--console-run".
|
||||
This will slightly improve the compression ratio,
|
||||
but the compressed executable will not boot from a CD.
|
||||
So use it for client/target transfer only!.
|
||||
|
||||
|
||||
|
||||
@@ -641,15 +747,23 @@ This format is used by the TMT Pascal compiler - see http://www.tmt.com/ .
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
(none)
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
--all-filters Compress the program several times, using all
|
||||
available preprocessing filters. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default filter gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR VMLINUZ/386
|
||||
|
||||
The vmlinuz/386 and bvmlinuz/386 formats take a gzip-compressed
|
||||
bootable kernel image ("vmlinuz", "zImage", "bzImage"), gzip-decompress
|
||||
it and re-compress it with the UPX compression method.
|
||||
bootable Linux kernel image ("vmlinuz", "zImage", "bzImage"),
|
||||
gzip-decompress it and re-compress it with the B<UPX> compression method.
|
||||
|
||||
vmlinuz/386 is completely unrelated to the other Linux executable
|
||||
formats, and it does not share any of their drawbacks.
|
||||
@@ -672,7 +786,8 @@ Benefits:
|
||||
641073 bzImage [original]
|
||||
560755 bzImage.upx [compressed by "upx -9"]
|
||||
|
||||
- Much faster decompression at kernel boot time.
|
||||
- Much faster decompression at kernel boot time (but kernel
|
||||
decompression speed is not really an issue these days).
|
||||
|
||||
Drawbacks:
|
||||
|
||||
@@ -680,22 +795,26 @@ Drawbacks:
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
(none)
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
--all-filters Compress the program several times, using all
|
||||
available preprocessing filters. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default filter gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
=head2 NOTES FOR WATCOM/LE
|
||||
|
||||
UPX has been successfully tested with the following extenders:
|
||||
B<UPX> has been successfully tested with the following extenders:
|
||||
DOS4G, DOS4GW, PMODE/W, DOS32a, CauseWay.
|
||||
The WDOS/X extender is partly supported (for details
|
||||
see the file bugs BUGS).
|
||||
|
||||
Yes, you can use your compressed executables with DOS4GW.
|
||||
|
||||
The LX format is not yet supported.
|
||||
|
||||
DLLs are not supported.
|
||||
DLLs and the LX format are not supported.
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
@@ -706,10 +825,10 @@ Extra options available for this executable format:
|
||||
|
||||
=head2 NOTES FOR WIN32/PE
|
||||
|
||||
The PE support in UPX is quite stable now, but probably there are
|
||||
The PE support in B<UPX> is quite stable now, but probably there are
|
||||
still some incompabilities with some files.
|
||||
|
||||
Because of the way UPX (and other packers for this format) works, you
|
||||
Because of the way B<UPX> (and other packers for this format) works, you
|
||||
can see increased memory usage of your compressed files. If you start
|
||||
several instances of huge compressed programs you're wasting memory
|
||||
because the common segements of the program won't get shared
|
||||
@@ -723,6 +842,10 @@ will load faster, and require less bandwidth during execution.
|
||||
|
||||
DLLs are supported.
|
||||
|
||||
Screensavers are supported, with the restriction that the filename
|
||||
must end in ".scr" (as screensavers are handled slightly different
|
||||
than normal exe files).
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
--compress-exports=0 Don't compress the export section.
|
||||
@@ -746,16 +869,29 @@ Extra options available for this executable format:
|
||||
unexpected value in a header field.
|
||||
Use with care.
|
||||
|
||||
--strip-loadconf=0 Don't strip Structured Exception Handling load config [DEFAULT].
|
||||
--strip-loadconf=1 Strip Structured Exception Handling load config.
|
||||
|
||||
--strip-relocs=0 Don't strip relocation records.
|
||||
--strip-relocs=1 Strip relocation records. [DEFAULT]
|
||||
This option only works on executables with base
|
||||
address greater or equal to 0x400000. Usually the
|
||||
compressed files becomes smaller, but some files
|
||||
may become larger. Note that the resulting file will
|
||||
not work under Win32s.
|
||||
not work under Windows 3.x (Win32s).
|
||||
UPX never strips relocations from a DLL
|
||||
regardless of this option.
|
||||
|
||||
--all-methods Compress the program several times, using all
|
||||
available compression methods. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default method gives the best results anyway.
|
||||
|
||||
--all-filters Compress the program several times, using all
|
||||
available preprocessing filters. This may improve
|
||||
the compression ratio in some cases, but usually
|
||||
the default filter gives the best results anyway.
|
||||
|
||||
|
||||
|
||||
=head1 DIAGNOSTICS
|
||||
@@ -775,22 +911,26 @@ Please report all bugs immediately to the authors.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>
|
||||
http://wildsau.idv.uni-linz.ac.at/mfx/
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com
|
||||
|
||||
Laszlo Molnar <ml1050@cdata.tvnet.hu>
|
||||
Laszlo Molnar <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser <jreiser@BitWagon.com>
|
||||
|
||||
Jens Medoch <jssg@users.sourceforge.net>
|
||||
|
||||
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
|
||||
Copyright (C) 2000 John Reiser
|
||||
Copyright (C) 2000-2004 John F. Reiser
|
||||
|
||||
Copyright (C) 2002-2004 Jens Medoch
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
@@ -798,7 +938,7 @@ redistribute it under certain conditions.
|
||||
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
|
||||
UPX License Agreement for more details.
|
||||
B<UPX License Agreement> for more details.
|
||||
|
||||
You should have received a copy of the UPX License Agreement along
|
||||
with this program; see the file LICENSE. If not, visit the UPX home page.
|
||||
|
||||
+2632
-1207
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,24 @@
|
||||
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
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
ifeq ($(DEPS_DONE),)
|
||||
DEPS_DONE := 1
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // automated dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
ifeq ($(DEPMODE),gcc)
|
||||
EXTRA_CFLAGS += -Wp,-MMD,.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -Wp,-MMD,.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
ifeq ($(DEPMODE),linux-intelc)
|
||||
EXTRA_CFLAGS += -MMD -MF.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -MMD -MF.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
ifeq ($(DEPMODE),linux-pgi)
|
||||
## NOTE: -MMD does not work...
|
||||
EXTRA_CFLAGS += -MD.deps/$(*F).d
|
||||
EXTRA_CXXFLAGS += -MD.deps/$(*F).d
|
||||
HAVE_DEPS := 1
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(HAVE_DEPS),1)
|
||||
ifeq ($(strip $(wildcard .deps)),)
|
||||
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
||||
else
|
||||
DEPS_FILES := $(wildcard .deps/*.d)
|
||||
ifneq ($(strip $(DEPS_FILES)),)
|
||||
include $(DEPS_FILES)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
endif # DEPS_DONE
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
DEPMODE := gcc
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // defaults for gcc
|
||||
# ************************************************************************/
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
LINK_EXE_OUTPUT = -o $@
|
||||
|
||||
|
||||
CFLAGS_W =
|
||||
CFLAGS_M =
|
||||
CFLAGS_O =
|
||||
CXXFLAGS_W =
|
||||
CXXFLAGS_M =
|
||||
CXXFLAGS_O =
|
||||
|
||||
CFLAGS = $(call __mkflags,CFLAGS_W) $(call __mkflags,CFLAGS_M) $(call __mkflags,CFLAGS_O)
|
||||
CXXFLAGS = $(call __mkflags,CXXFLAGS_W) $(call __mkflags,CXXFLAGS_M) $(call __mkflags,CXXFLAGS_O)
|
||||
|
||||
|
||||
#
|
||||
# cflags
|
||||
#
|
||||
|
||||
##CFLAGS_WERROR = -Werror
|
||||
CFLAGS_WERROR =
|
||||
CFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wbad-function-cast -Wcast-align -Wcast-qual -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wwrite-strings
|
||||
CXXFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wcast-align -Wcast-qual -Winline -Woverloaded-virtual -Wpointer-arith -Wshadow -Wsign-promo -Wsynth -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,29 +1,39 @@
|
||||
UDIR := $($(U)DIR)
|
||||
|
||||
ifneq ($(strip $(wildcard $(UDIR)/include)),) # { include
|
||||
DEFS += -DWITH_$(U)
|
||||
|
||||
ifneq ($(strip $(wildcard $(UDIR)/include)),)
|
||||
INCLUDES += -I$(UDIR)/include
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(wildcard $(UDIR)/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/src/.libs
|
||||
endif
|
||||
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
|
||||
endif
|
||||
else
|
||||
ifneq ($(strip $(wildcard $(UDIR)/build/src/.libs)),)
|
||||
LIBDIRS += $(UDIR)/build/src/.libs
|
||||
endif
|
||||
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
|
||||
@@ -35,3 +45,4 @@ LIBDIRS := $(LIBDIRS)
|
||||
LDLIBS := $(LDLIBS)
|
||||
DOS_LDLIBS := $(DOS_LDLIBS)
|
||||
|
||||
endif # } include
|
||||
+36
-432
@@ -1,12 +1,23 @@
|
||||
# UPX Makefile (GNU make) - works with djgpp2/win32/unix
|
||||
#
|
||||
# UPX Makefile (GNU make) - works with unix/win32/djgpp2
|
||||
#
|
||||
# usage:
|
||||
# `make target=linux' # linux
|
||||
# `make target=djggp2' # djggp2 2.03
|
||||
# `make target=cygwin' # cygwin 1.1.x
|
||||
# `make target=mingw32' # mingw32
|
||||
# `make target=no-cygwin' # mingw32 as included in cygwin 1.1.x
|
||||
# `make target=vc6' # Visual C++ 6.0
|
||||
# `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.
|
||||
#
|
||||
|
||||
|
||||
@@ -14,42 +25,19 @@
|
||||
|
||||
ifeq ($(strip $(UCLDIR)),)
|
||||
# change this to reflect where the UCL library is
|
||||
UCLDIR = $(HOME)/local/src/ucl-0.92
|
||||
UCLDIR = $(HOME)/local/src/ucl-1.02
|
||||
endif
|
||||
|
||||
## you can set the default target here
|
||||
##target =
|
||||
|
||||
DEBUG = 0
|
||||
|
||||
|
||||
# -------------------------------------------------------
|
||||
# You should not have to change anything below this line.
|
||||
# -------------------------------------------------------
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .a .c .cpp .exe .lib .o .obj
|
||||
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = ..
|
||||
|
||||
|
||||
# auto-detect the target unless given on the commandline
|
||||
target = djgpp2
|
||||
ifneq ($(strip $(wildcard /usr/include/linux)),)
|
||||
target = linux
|
||||
endif
|
||||
ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),)
|
||||
target = sparc
|
||||
endif
|
||||
ifeq ($(target),msc)
|
||||
override target = vc6
|
||||
endif
|
||||
|
||||
|
||||
# util var for use in the rules - basename of the current target
|
||||
override T = $(basename $@)
|
||||
##### You should not have to change anything below this line. #####
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
@@ -59,15 +47,16 @@ override T = $(basename $@)
|
||||
# these use exceptions & RTTI
|
||||
OBJECTS1 = \
|
||||
compress$o except$o file$o lefile$o \
|
||||
filter$o mem$o msg$o stdcxx$o work$o ui$o \
|
||||
packer$o packhead$o packmast$o \
|
||||
p_com$o p_djgpp2$o p_exe$o p_lx_elf$o p_lx_sep$o p_lx_sh$o \
|
||||
p_sys$o p_tmt$o p_tos$o \
|
||||
p_unix$o p_vmlinz$o p_w32pe$o p_wcle$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
|
||||
|
||||
# no exceptions or RTTI
|
||||
OBJECTS2 = \
|
||||
filteri$o help$o main$o mygetopt$o util$o linker$o \
|
||||
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
|
||||
|
||||
@@ -75,408 +64,23 @@ OBJECTS2 = \
|
||||
OBJECTS3 =
|
||||
|
||||
OBJECTS = $(OBJECTS1) $(OBJECTS2) $(OBJECTS3)
|
||||
LIBS =
|
||||
RESOURCES =
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // compiler settings
|
||||
# // main
|
||||
# ************************************************************************/
|
||||
|
||||
# default to a gcc unix-type compiler
|
||||
CC = gcc
|
||||
CXX = $(CC)
|
||||
DEFS =
|
||||
INCLUDES = -I$(srcdir)
|
||||
CFLAGS_OUTPUT = -o $@
|
||||
CXXFLAGS_OUTPUT = $(CFLAGS_OUTPUT)
|
||||
override WITH_ZLIB = 1
|
||||
|
||||
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LDLIBS)
|
||||
STUBEDIT_EXE =
|
||||
|
||||
o = .o
|
||||
a = .a
|
||||
e = .exe
|
||||
|
||||
|
||||
###
|
||||
### gcc defaults
|
||||
###
|
||||
|
||||
##CFLAGS_O = -Os
|
||||
CFLAGS_O = -O2
|
||||
##CFLAGS_WERROR = -Werror
|
||||
CFLAGS_W = $(CFLAGS_WERROR)
|
||||
CFLAGS_W += -Wall -W -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wwrite-strings
|
||||
##CFLAGS_M = -fno-builtin
|
||||
## CFLAGS_M += -malign-functions=0 -malign-jumps=0 -malign-loops=0
|
||||
|
||||
CFLAGS = $(CFLAGS_W) $(CFLAGS_O) $(CFLAGS_M)
|
||||
CXXFLAGS = $(CFLAGS) -Wsynth -fconserve-space
|
||||
CXXFLAGS1 = $(CXXFLAGS)
|
||||
CXXFLAGS2 = $(CXXFLAGS) -fno-exceptions -fno-rtti
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
DEFS += -DDEBUG
|
||||
## DEFS += -DTESTING
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
LDFLAGS = -g
|
||||
else
|
||||
LDFLAGS = -s
|
||||
endif
|
||||
LDFLAGS += -Wl,-Map,$T.map
|
||||
LDLIBS =
|
||||
LDLIBS = -lz
|
||||
LIBDIRS =
|
||||
DOS_LIBDIRS =
|
||||
|
||||
|
||||
###
|
||||
### compression library
|
||||
###
|
||||
|
||||
UCLDIR:=$(strip $(subst \,/,$(UCLDIR)))
|
||||
NRVDIR:=$(strip $(subst \,/,$(NRVDIR)))
|
||||
u = ucl
|
||||
U = UCL
|
||||
upx_exe = upx$e
|
||||
include $(srcdir)/Makefile.inc
|
||||
ifneq ($(strip $(wildcard $(NRVDIR)/include/nrv)),)
|
||||
u = nrv
|
||||
U = NRV
|
||||
upx_exe = upx_$u$e
|
||||
include $(srcdir)/Makefile.inc
|
||||
endif
|
||||
|
||||
tmp := -Wl,--rpath,
|
||||
LDRPATH := $(addprefix $(tmp),$(LIBDIRS))
|
||||
LIBDIRS += .
|
||||
LDLIBDIRS := $(addprefix -L,$(LIBDIRS))
|
||||
|
||||
##LDFLAGS += $(LDRPATH)
|
||||
LDFLAGS += $(LDLIBDIRS)
|
||||
|
||||
|
||||
###
|
||||
### linux/i386
|
||||
###
|
||||
|
||||
ifeq ($(target),linux)
|
||||
e =
|
||||
###CC = /usr/local/packages/gcc-cvs/bin/g++
|
||||
DEFS += '-DUPX_CONFIG_H="config_h/linux.h"'
|
||||
##CFLAGS_M += -mno-schedule-prologue
|
||||
CFLAGS_M += -march=i386 -mcpu=pentium
|
||||
CFLAGS_WERROR = -Werror
|
||||
LDLIBS += -lmcheck
|
||||
|
||||
ifeq (1,2) # checkergcc
|
||||
CC = checkergcc
|
||||
CXX = checkerg++
|
||||
else
|
||||
ifeq ($(DEBUG),1)
|
||||
##CFLAGS += -O0 -gstabs+3
|
||||
CFLAGS += -O0 -gdwarf-2
|
||||
else
|
||||
##LDFLAGS += -static
|
||||
STUBEDIT_EXE = objcopy -S -R .comment -R .note $@ && perl $(srcdir)/stub/scripts/brandelf.pl $@ && chmod 755 $@
|
||||
endif
|
||||
endif
|
||||
|
||||
endif # linux
|
||||
|
||||
|
||||
###
|
||||
### djgpp2
|
||||
###
|
||||
|
||||
ifeq ($(target),djgpp2)
|
||||
CFLAGS_M += -mno-schedule-prologue
|
||||
CFLAGS_M += -march=i386 -mcpu=pentium
|
||||
CFLAGS_WERROR = -Werror
|
||||
STUBEDIT_EXE = stubedit $@ bufsize=0xfc00
|
||||
endif # djgpp2
|
||||
|
||||
|
||||
###
|
||||
### cygwin / mingw32
|
||||
###
|
||||
|
||||
ifeq ($(target),cygwin)
|
||||
CFLAGS_M += -mno-schedule-prologue
|
||||
CFLAGS_M += -march=i386 -mcpu=pentium
|
||||
CFLAGS_WERROR = -Werror
|
||||
endif
|
||||
|
||||
ifeq ($(target),mingw32)
|
||||
CFLAGS_M += -mno-schedule-prologue
|
||||
CFLAGS_M += -march=i386 -mcpu=pentium
|
||||
endif
|
||||
|
||||
# mingw32 as included in cygwin
|
||||
ifeq ($(target),no-cygwin)
|
||||
CC = gcc -mno-cygwin
|
||||
CFLAGS_M += -mno-schedule-prologue
|
||||
CFLAGS_M += -march=i386 -mcpu=pentium
|
||||
CFLAGS_WERROR = -Werror
|
||||
endif
|
||||
|
||||
|
||||
###
|
||||
### Microsoft 32-bit C/C++ Compiler 12.00 (aka Visual C++ 6)
|
||||
###
|
||||
|
||||
ifeq ($(target),vc6)
|
||||
o = .obj
|
||||
a = .lib
|
||||
CC = cl -nologo
|
||||
CFLAGS = -W4 -WX
|
||||
CXXFLAGS1 = $(CFLAGS) -GR -GX -EHa
|
||||
CXXFLAGS2 = $(CFLAGS)
|
||||
LDFLAGS =
|
||||
LINK_LDFLAGS = /link /map:$T.map
|
||||
|
||||
ifneq ($(strip $(DOS_LIBDIRS)),)
|
||||
LIB := $(DOS_LIBDIRS);$(LIB)
|
||||
endif
|
||||
export LIB
|
||||
|
||||
ifeq (1,2)
|
||||
# statically link libc.lib
|
||||
CC += -ML
|
||||
##LDLIBS = $(u)_s.lib zlib_s.lib setargv.obj
|
||||
LDLIBS = $(u)_s.lib setargv.obj
|
||||
else
|
||||
# link against msvcrt.dll
|
||||
CC += -MD
|
||||
LDLIBS = $(DOS_LDLIBS) zlib.lib setargv.obj
|
||||
endif
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -ZI
|
||||
LINK_LDFLAGS += /debug
|
||||
else
|
||||
CFLAGS += -O2 -GF
|
||||
LINK_LDFLAGS += /release
|
||||
endif
|
||||
|
||||
##LINK_LDFLAGS += /verbose
|
||||
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -Fe$@ $^ $(LDLIBS) $(LINK_LDFLAGS)
|
||||
|
||||
endif # vc6
|
||||
|
||||
|
||||
###
|
||||
### sparc
|
||||
###
|
||||
|
||||
ifeq ($(target),sparc)
|
||||
e =
|
||||
DEFS += '-DUPX_CONFIG_H="config_h/sparc.h"'
|
||||
INCLUDES += -I/home/ethmola/local/include
|
||||
|
||||
ifeq (1,2) # native compiler
|
||||
CFLAGS = -O0 -g
|
||||
CXXFLAGS1 =
|
||||
CXXFLAGS2 =
|
||||
CFLAGS_M =
|
||||
DEFS += -DUSE_STDNAMESPACE
|
||||
else # gcc
|
||||
CFLAGS += -O0 -gstabs+
|
||||
endif
|
||||
|
||||
ifeq (1,2) # purify
|
||||
DEFS += -D__PURIFY__
|
||||
LDFLAGS = -g -L/home/ethmola/local/lib
|
||||
LINK_EXE = purify $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LDLIBS)
|
||||
else
|
||||
LDFLAGS += -g -L/home/ethmola/local/lib
|
||||
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LDLIBS)
|
||||
endif
|
||||
|
||||
endif # sparc
|
||||
|
||||
|
||||
###
|
||||
### Borland C++ 5.5 (DOES NOT WORK - INCOMPLETE C++ IMPLEMENTATION)
|
||||
###
|
||||
|
||||
ifeq ($(target),bcc)
|
||||
o = .obj
|
||||
a = .lib
|
||||
CC = bcc32
|
||||
CFLAGS = -w -w-par
|
||||
CXXFLAGS1 = $(CFLAGS)
|
||||
CXXFLAGS2 = $(CFLAGS)
|
||||
CFLAGS_OUTPUT = -o$@
|
||||
LDFLAGS =
|
||||
LDLIBS = $(DOS_LDLIBS) zlib.lib
|
||||
|
||||
ifneq ($(strip $(DOS_LIBDIRS)),)
|
||||
LIB := $(DOS_LIBDIRS);$(LIB)
|
||||
endif
|
||||
export LIB
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -Od -d
|
||||
else
|
||||
CFLAGS += -O2 -d
|
||||
endif
|
||||
|
||||
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -e$@ $^ $(LDLIBS)
|
||||
|
||||
endif # bcc
|
||||
|
||||
|
||||
###
|
||||
### malloc debuggers (Linux only)
|
||||
###
|
||||
|
||||
ifeq (1,2)
|
||||
LDLIBS += -lefence
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
CFLAGS += -DWITH_DMALLOC
|
||||
LDLIBS += -ldmalloc
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
CFLAGS += -DWITH_GC -DLINUX_THREADS -D_REENTRANT
|
||||
LDLIBS += -lgc -lpthread
|
||||
# only needed when using -static:
|
||||
##LDFLAGS += -Wl,-defsym,_DYNAMIC=0
|
||||
endif
|
||||
|
||||
ifeq (1,2)
|
||||
CFLAGS += -DWITH_MSS
|
||||
LDLIBS += -lmss
|
||||
endif
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // main targets
|
||||
# ************************************************************************/
|
||||
|
||||
all: $(upx_exe)
|
||||
|
||||
.PHONY: all unupx mostlyclean clean distclean maintainer-clean untabify tags
|
||||
|
||||
$(upx_exe): $(OBJECTS) $(LIBS)
|
||||
$(LINK_EXE)
|
||||
$(STUBEDIT_EXE)
|
||||
|
||||
|
||||
ifeq ($(target),djgpp2)
|
||||
cwsbind: $(upx_exe)
|
||||
-rm -f $T.cof
|
||||
$(upx_exe) -1 --coff -o $T.cof $(upx_exe)
|
||||
cat $(DJDIR)/bin/cwsdstub.exe $T.cof > $(upx_exe)
|
||||
$(upx_exe) -d $(upx_exe)
|
||||
$(upx_exe) --best $(upx_exe)
|
||||
endif
|
||||
|
||||
|
||||
unupx:
|
||||
$(MAKE) target=vc6 unupx.dll
|
||||
|
||||
unupx.dll: $(OBJECTS) $(LIBS)
|
||||
$(LINK_DLL)
|
||||
|
||||
|
||||
mostlyclean:
|
||||
-rm -f *.d *.err *.i *.log *.map *~ gdb-trans*
|
||||
|
||||
clean: mostlyclean
|
||||
-rm -f *.a *.lib *.o *.obj tags TAGS ID
|
||||
-rm -f *.idb *.pdb
|
||||
-rm -f upx upx.exe upx_nrv upx_nrv.exe upx_ucl upx_ucl.exe
|
||||
|
||||
distclean: clean
|
||||
|
||||
maintainer-clean: distclean
|
||||
|
||||
|
||||
untabify:
|
||||
mfxtu -d4 -t *.h *.cpp *.ch
|
||||
mfxtu -d8 -t stub/[ln]*.asm stub/*.ash stub/*.[cs]
|
||||
|
||||
tags TAGS:
|
||||
ctags *.h *.cpp *.ch
|
||||
|
||||
ID:
|
||||
mkid *.h *.cpp *.ch
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // rules
|
||||
# ************************************************************************/
|
||||
|
||||
.c$o:
|
||||
$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) $(CFLAGS_OUTPUT) -c $<
|
||||
|
||||
.cpp$o:
|
||||
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS1) $(CXXFLAGS_OUTPUT) -c $<
|
||||
|
||||
$(OBJECTS1): %$o : %.cpp
|
||||
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS1) $(CXXFLAGS_OUTPUT) -c $<
|
||||
|
||||
$(OBJECTS2): %$o : %.cpp
|
||||
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS2) $(CXXFLAGS_OUTPUT) -c $<
|
||||
|
||||
ifneq ($(strip $(OBJECTS3)),)
|
||||
$(OBJECTS3): %$o : %.c
|
||||
$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) $(CFLAGS_OUTPUT) -c $<
|
||||
endif
|
||||
include $(srcdir)/Makefile.bld
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
# // dependencies
|
||||
# ************************************************************************/
|
||||
|
||||
# FIXME: use automated dependencies
|
||||
|
||||
main$o: mygetopt.h version.h
|
||||
filter$o: filter.h
|
||||
filteri$o: filter.h fcto_ml.ch fcto_ml2.ch fcto_ml3.ch
|
||||
help$o: version.h
|
||||
msg$o: ui.h
|
||||
lefile$o: lefile.h
|
||||
linker$o: linker.h
|
||||
mygetopt$o: mygetopt.h
|
||||
packer$o: packer.h filter.h linker.h ui.h version.h
|
||||
packhead$o: packer.h
|
||||
packmast$o: packmast.h packer.h lefile.h \
|
||||
p_com.h p_djgpp2.h p_exe.h p_lx_elf.h p_lx_sep.h p_lx_sh.h \
|
||||
p_sys.h p_tmt.h p_tos.h \
|
||||
p_unix.h p_vmlinz.h p_vxd.h p_w32pe.h p_wcle.h
|
||||
ui$o: packer.h ui.h
|
||||
work$o: packer.h ui.h packmast.h
|
||||
|
||||
p_com$o: packer.h p_com.h \
|
||||
stub/l_com.h
|
||||
p_djgpp2$o: packer.h p_djgpp2.h stub/stubify.h \
|
||||
stub/l_djgpp2.h
|
||||
p_exe$o: packer.h p_exe.h \
|
||||
stub/l_exe.h
|
||||
p_lx_elf$o: packer.h p_lx_elf.h p_unix.h p_elf.h \
|
||||
stub/l_le_n2b.h stub/l_le_n2d.h
|
||||
p_lx_sep$o: packer.h p_lx_sep.h p_lx_elf.h p_unix.h p_elf.h
|
||||
p_lx_sh$o: packer.h p_lx_sh.h p_lx_elf.h p_unix.h p_elf.h \
|
||||
stub/l_sh_n2b.h stub/l_sh_n2d.h
|
||||
p_sys$o: packer.h p_sys.h p_com.h \
|
||||
stub/l_sys.h
|
||||
p_tmt$o: packer.h p_tmt.h \
|
||||
stub/l_tmt.h
|
||||
p_tos$o: packer.h p_tos.h \
|
||||
stub/l_t_n2b.h stub/l_t_n2bs.h \
|
||||
stub/l_t_n2d.h stub/l_t_n2ds.h
|
||||
p_unix$o: packer.h p_unix.h p_elf.h \
|
||||
stub/l_lx_n2b.h stub/l_lx_n2d.h
|
||||
p_vmlinz$o: packer.h p_vmlinz.h \
|
||||
stub/l_vmlinz.h
|
||||
p_w32pe$o: packer.h p_w32pe.h \
|
||||
stub/l_w32pe.h
|
||||
p_wcle$o: packer.h p_wcle.h lefile.h \
|
||||
stub/l_wcle.h
|
||||
include $(srcdir)/Makedefs.dep
|
||||
|
||||
# vi:nowrap
|
||||
|
||||
@@ -0,0 +1,720 @@
|
||||
# /***********************************************************************
|
||||
# // perpare 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
|
||||
@@ -0,0 +1 @@
|
||||
GNUmakefile
|
||||
@@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it 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; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
@@ -0,0 +1,94 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Possible configuration values:
|
||||
*
|
||||
* ACC_CONFIG_NO_HEADER
|
||||
* ACC_CONFIG_HEADER if given, then use this as <config.h>
|
||||
* ACC_CONFIG_INCLUDE include path to acc_ files
|
||||
*
|
||||
* ACC_CONFIG_PREFER___INT64 [acc_type.h]
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ACC_H_INCLUDED
|
||||
#define __ACC_H_INCLUDED 1
|
||||
|
||||
#define ACC_VERSION 20040715L
|
||||
|
||||
#if !defined(ACC_CONFIG_INCLUDE)
|
||||
# define ACC_CONFIG_INCLUDE(file) file
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__CYGWIN32__) && !defined(__CYGWIN__)
|
||||
# define __CYGWIN__ __CYGWIN32__
|
||||
#endif
|
||||
#if defined(__IBMCPP__) && !defined(__IBMC__)
|
||||
# define __IBMC__ __IBMCPP__
|
||||
#endif
|
||||
#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER)
|
||||
# define __INTEL_COMPILER __ICL
|
||||
#endif
|
||||
|
||||
#if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE)
|
||||
# define _ALL_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* disable pedantic warnings for undefined preprocessing symbols */
|
||||
#if defined(__INTEL_COMPILER) && defined(__linux__)
|
||||
# pragma warning(disable: 193)
|
||||
#endif
|
||||
#if defined(__KEIL__) && defined(__C166__)
|
||||
# pragma warning disable = 322
|
||||
#elif 0 && defined(__C251__)
|
||||
# pragma warning disable = 322
|
||||
#endif
|
||||
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__)
|
||||
# if (_MSC_VER >= 1300)
|
||||
# pragma warning(disable: 4668)
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && defined(__WATCOMC__)
|
||||
# if (__WATCOMC__ < 1060)
|
||||
# pragma warning 203 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
#include ACC_CONFIG_INCLUDE("acc_init.h")
|
||||
#include ACC_CONFIG_INCLUDE("acc_os.h")
|
||||
#include ACC_CONFIG_INCLUDE("acc_cc.h")
|
||||
#include ACC_CONFIG_INCLUDE("acc_arch.h")
|
||||
#include ACC_CONFIG_INCLUDE("acc_mm.h")
|
||||
#include ACC_CONFIG_INCLUDE("acc_defs.h")
|
||||
|
||||
#if defined(ACC_CONFIG_NO_HEADER)
|
||||
#elif defined(ACC_CONFIG_HEADER)
|
||||
# include ACC_CONFIG_HEADER
|
||||
#else
|
||||
# include ACC_CONFIG_INCLUDE("acc_auto.h")
|
||||
#endif
|
||||
|
||||
#include ACC_CONFIG_INCLUDE("acc_type.h")
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,124 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* CPU architecture - exactly one of:
|
||||
*
|
||||
* ACC_ARCH_UNKNOWN [default]
|
||||
* ACC_ARCH_ALPHA
|
||||
* ACC_ARCH_AMD64 aka x86-64 or ia32e
|
||||
* ACC_ARCH_C166
|
||||
* ACC_ARCH_IA16 Intel Architecture (8088, 8086, 80186, 80286)
|
||||
* ACC_ARCH_IA32 Intel Architecture (80386+)
|
||||
* ACC_ARCH_IA64 Intel Architecture (Itanium)
|
||||
* ACC_ARCH_M68K Motorola 680x0
|
||||
* ACC_ARCH_MCS251
|
||||
* ACC_ARCH_MCS51
|
||||
* ACC_ARCH_PPC64 Power PC
|
||||
* ACC_ARCH_SPARC64
|
||||
*
|
||||
* Optionally define one of:
|
||||
* ACC_ENDIAN_LITTLE_ENDIAN
|
||||
* ACC_ENDIAN_BIG_ENDIAN
|
||||
*
|
||||
* Note that this list is not exhaustive - actually we only really care
|
||||
* about architectures which allow unaligned memory access at reasonable
|
||||
* speed (for the moment this means IA16, IA32 and AMD64).
|
||||
*/
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
|
||||
# define ACC_ARCH_IA16 1
|
||||
# define ACC_INFO_ARCH "ia16"
|
||||
#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)
|
||||
# define ACC_ARCH_AMD64 1
|
||||
# define ACC_INFO_ARCH "amd64"
|
||||
#elif (UINT_MAX <= ACC_0xffffL) && defined(__AVR__)
|
||||
# define ACC_ARCH_AVR 1
|
||||
# define ACC_INFO_ARCH "avr"
|
||||
#elif (UINT_MAX == ACC_0xffffL) && defined(__C166__)
|
||||
# define ACC_ARCH_C166 1
|
||||
# define ACC_INFO_ARCH "c166"
|
||||
#elif (UINT_MAX == ACC_0xffffL) && defined(__C251__)
|
||||
# define ACC_ARCH_MCS251 1
|
||||
# define ACC_INFO_ARCH "mcs-251"
|
||||
#elif (UINT_MAX == ACC_0xffffL) && defined(__C51__)
|
||||
# define ACC_ARCH_MCS51 1
|
||||
# define ACC_INFO_ARCH "mcs-51"
|
||||
#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386)
|
||||
# define ACC_ARCH_IA32 1
|
||||
# define ACC_INFO_ARCH "ia32"
|
||||
#elif (ACC_CC_ZORTECHC && defined(__I86__))
|
||||
# define ACC_ARCH_IA32 1
|
||||
# define ACC_INFO_ARCH "ia32"
|
||||
#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
|
||||
# define ACC_ARCH_IA64 1
|
||||
# define ACC_INFO_ARCH "ia64"
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_HIGHC) && defined(_I386)
|
||||
# define ACC_ARCH_IA32 1
|
||||
# define ACC_INFO_ARCH "ia32"
|
||||
#elif (ACC_OS_DOS32 || ACC_OS_OS2)
|
||||
# error "missing define for CPU architecture"
|
||||
#elif (ACC_OS_WIN32)
|
||||
# error "missing define for CPU architecture"
|
||||
#elif (ACC_OS_WIN64)
|
||||
/* # error "missing define for CPU architecture" */
|
||||
#elif (ACC_OS_TOS) || defined(__m68000__)
|
||||
# define ACC_ARCH_M68K 1
|
||||
# define ACC_INFO_ARCH "m68k"
|
||||
#elif defined(__alpha__) || defined(__alpha)
|
||||
# define ACC_ARCH_ALPHA 1
|
||||
# define ACC_INFO_ARCH "alpha"
|
||||
#elif defined(__ppc64__) || defined(__ppc64)
|
||||
# define ACC_ARCH_PPC64 1
|
||||
# define ACC_INFO_ARCH "ppc64"
|
||||
#elif defined(__sparc64__) || defined(__sparc64)
|
||||
# define ACC_ARCH_SPARC64 1
|
||||
# define ACC_INFO_ARCH "sparc64"
|
||||
#else
|
||||
# define ACC_ARCH_UNKNOWN 1
|
||||
# define ACC_INFO_ARCH "unknown"
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA16 || ACC_ARCH_IA32)
|
||||
# define ACC_ENDIAN_LITTLE_ENDIAN 1
|
||||
# define ACC_INFO_ENDIAN "little-endian"
|
||||
#elif (ACC_ARCH_M68K)
|
||||
# define ACC_ENDIAN_BIG_ENDIAN 1
|
||||
# define ACC_INFO_ENDIAN "big-endian"
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_ARCH_IA16)
|
||||
# if (UINT_MAX != ACC_0xffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
# if (ULONG_MAX != ACC_0xffffffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
#endif
|
||||
#if (ACC_ARCH_IA32)
|
||||
# if (UINT_MAX != ACC_0xffffffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
# if (ULONG_MAX != ACC_0xffffffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,660 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Possible configuration values:
|
||||
*
|
||||
* ACC_CONFIG_AUTO_NO_HEADERS
|
||||
* ACC_CONFIG_AUTO_NO_FUNCTIONS
|
||||
* ACC_CONFIG_AUTO_NO_SIZES
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Checks for <stdint.h>
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(ACC_CONFIG_AUTO_NO_HEADERS)
|
||||
|
||||
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
|
||||
# if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1))
|
||||
# define HAVE_STDINT_H 1
|
||||
# endif
|
||||
#elif defined(__dietlibc__)
|
||||
# undef HAVE_STDINT_H /* incomplete */
|
||||
#elif (ACC_CC_BORLANDC) && (__BORLANDC__ >= 0x560)
|
||||
# undef HAVE_STDINT_H /* broken & incomplete */
|
||||
#elif (ACC_CC_DMC) && (__DMC__ >= 0x825)
|
||||
# define HAVE_STDINT_H 1
|
||||
#endif
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#endif /* !defined(ACC_CONFIG_AUTO_NO_HEADERS) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Checks for header files
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(ACC_CONFIG_AUTO_NO_HEADERS)
|
||||
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
#define HAVE_ASSERT_H 1
|
||||
#define HAVE_CTYPE_H 1
|
||||
#define HAVE_DIRENT_H 1
|
||||
#define HAVE_ERRNO_H 1
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_LIMITS_H 1
|
||||
#define HAVE_MALLOC_H 1
|
||||
#define HAVE_MEMORY_H 1
|
||||
#define HAVE_SETJMP_H 1
|
||||
#define HAVE_SIGNAL_H 1
|
||||
#define HAVE_STDARG_H 1
|
||||
#define HAVE_STDDEF_H 1
|
||||
#define HAVE_STDIO_H 1
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_TIME_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
#define HAVE_UTIME_H 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
#undef HAVE_ALLOCA_H
|
||||
#undef HAVE_CONIO_H
|
||||
#undef HAVE_DIRECT_H
|
||||
#undef HAVE_DOS_H
|
||||
#undef HAVE_IO_H
|
||||
#undef HAVE_SHARE_H
|
||||
#undef HAVE_STDINT_H
|
||||
#undef HAVE_STRINGS_H
|
||||
#undef HAVE_SYS_UTIME_H
|
||||
|
||||
|
||||
#if (ACC_OS_POSIX)
|
||||
# define HAVE_STRINGS_H 1
|
||||
# if (ACC_OS_POSIX_FREEBSD || ACC_OS_POSIX_MACOSX || ACC_OS_POSIX_OPENBSD)
|
||||
# undef HAVE_MALLOC_H /* deprecated */
|
||||
# elif (ACC_OS_POSIX_HPUX || ACC_OS_POSIX_INTERIX)
|
||||
# define HAVE_ALLOCA_H 1
|
||||
# endif
|
||||
# if (ACC_OS_POSIX_MACOSX && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
/* FIXME ??? */
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# undef HAVE_SYS_TYPES_H
|
||||
# endif
|
||||
#elif (ACC_OS_CYGWIN)
|
||||
# define HAVE_IO_H 1
|
||||
#elif (ACC_OS_EMX)
|
||||
# define HAVE_ALLOCA_H 1
|
||||
# define HAVE_IO_H 1
|
||||
#elif (ACC_OS_TOS && ACC_CC_GNUC)
|
||||
# if !defined(__MINT__)
|
||||
# undef HAVE_MALLOC_H
|
||||
# endif
|
||||
#elif (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_FCNTL_H
|
||||
# undef HAVE_MALLOC_H
|
||||
# undef HAVE_MEMORY_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_STAT_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# undef HAVE_SYS_TYPES_H
|
||||
#endif
|
||||
|
||||
|
||||
/* DOS, OS/2 & Windows */
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
|
||||
#define HAVE_CONIO_H 1
|
||||
#define HAVE_DIRECT_H 1
|
||||
#define HAVE_DOS_H 1
|
||||
#define HAVE_IO_H 1
|
||||
#define HAVE_SHARE_H 1
|
||||
|
||||
#if (ACC_CC_AZTECC)
|
||||
# undef HAVE_CONIO_H
|
||||
# undef HAVE_DIRECT_H
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_MALLOC_H
|
||||
# undef HAVE_SHARE_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_STAT_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# undef HAVE_SYS_TYPES_H
|
||||
#elif (ACC_CC_BORLANDC)
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# undef HAVE_DIRENT_H /* pulls in <windows.h>; use <dir.h> instead */
|
||||
# endif
|
||||
# if (__BORLANDC__ < 0x0400)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_UTIME_H
|
||||
# endif
|
||||
#elif (ACC_CC_DMC)
|
||||
# undef HAVE_DIRENT_H /* not working */
|
||||
# undef HAVE_UNISTD_H /* not working */
|
||||
# define HAVE_SYS_DIRENT_H 1
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_HIGHC)
|
||||
# define HAVE_ALLOCA_H 1
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_UNISTD_H
|
||||
#elif (ACC_CC_IBMC && ACC_OS_OS2)
|
||||
# undef HAVE_DOS_H
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# define HAVE_SYS_UTIME_H 1
|
||||
#elif (ACC_CC_INTELC || ACC_CC_MSC)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# define HAVE_SYS_UTIME_H 1
|
||||
#elif (ACC_CC_LCC)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_DOS_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__MINGW32__)
|
||||
# undef HAVE_UTIME_H
|
||||
# define HAVE_SYS_UTIME_H 1
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
# define HAVE_ALLOCA_H 1
|
||||
# undef HAVE_DOS_H
|
||||
# undef HAVE_SHARE_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
#elif (ACC_CC_NDPC)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_DOS_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
#elif (ACC_CC_PACIFICC)
|
||||
# undef HAVE_DIRECT_H
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_FCNTL_H
|
||||
# undef HAVE_IO_H
|
||||
# undef HAVE_MALLOC_H
|
||||
# undef HAVE_MEMORY_H
|
||||
# undef HAVE_SHARE_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_STAT_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# undef HAVE_SYS_TYPES_H
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_PELLESC)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_DOS_H
|
||||
# undef HAVE_MALLOC_H
|
||||
# undef HAVE_SHARE_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# if (__POCC__ < 280)
|
||||
# else
|
||||
# define HAVE_SYS_UTIME_H 1
|
||||
# endif
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_PGI) && defined(__MINGW32__)
|
||||
# undef HAVE_UTIME_H
|
||||
# define HAVE_SYS_UTIME_H 1
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
#elif (ACC_CC_SYMANTECC)
|
||||
# undef HAVE_DIRENT_H /* opendir() not implemented in libc */
|
||||
# undef HAVE_UNISTD_H /* not working */
|
||||
# if (__SC__ < 0x700)
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# endif
|
||||
#elif (ACC_CC_TOPSPEEDC)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_STAT_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# undef HAVE_SYS_TYPES_H
|
||||
#elif (ACC_CC_TURBOC)
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# undef HAVE_SYS_TYPES_H /* useless */
|
||||
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# undef HAVE_DIRENT_H /* pulls in <windows.h>; use <dir.h> instead */
|
||||
# endif
|
||||
# if (__TURBOC__ < 0x0200)
|
||||
# undef HAVE_SIGNAL_H /* not working */
|
||||
# endif
|
||||
# if (__TURBOC__ < 0x0400)
|
||||
# undef HAVE_DIRECT_H
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_MALLOC_H
|
||||
# undef HAVE_MEMORY_H
|
||||
# undef HAVE_UTIME_H
|
||||
# endif
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
# define HAVE_SYS_UTIME_H 1
|
||||
# if (__WATCOMC__ < 950)
|
||||
# undef HAVE_UNISTD_H
|
||||
# endif
|
||||
#elif (ACC_CC_ZORTECHC)
|
||||
# undef HAVE_DIRENT_H
|
||||
# undef HAVE_MEMORY_H
|
||||
# undef HAVE_UNISTD_H
|
||||
# undef HAVE_UTIME_H
|
||||
# undef HAVE_SYS_TIME_H
|
||||
#endif
|
||||
|
||||
#endif /* DOS, OS/2 & Windows */
|
||||
|
||||
|
||||
#if (HAVE_SYS_TIME_H && HAVE_TIME_H)
|
||||
# define TIME_WITH_SYS_TIME 1
|
||||
#endif
|
||||
|
||||
#endif /* !defined(ACC_CONFIG_AUTO_NO_HEADERS) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Checks for library functions
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(ACC_CONFIG_AUTO_NO_FUNCTIONS)
|
||||
|
||||
#define HAVE_ACCESS 1
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_ATEXIT 1
|
||||
#define HAVE_ATOI 1
|
||||
#define HAVE_ATOL 1
|
||||
#define HAVE_CHMOD 1
|
||||
#define HAVE_CHOWN 1
|
||||
#define HAVE_CTIME 1
|
||||
#define HAVE_DIFFTIME 1
|
||||
#define HAVE_FILENO 1
|
||||
#define HAVE_FSTAT 1
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
#define HAVE_GMTIME 1
|
||||
#define HAVE_LOCALTIME 1
|
||||
#define HAVE_LONGJMP 1
|
||||
#define HAVE_LSTAT 1
|
||||
#define HAVE_MEMCMP 1
|
||||
#define HAVE_MEMCPY 1
|
||||
#define HAVE_MEMMOVE 1
|
||||
#define HAVE_MEMSET 1
|
||||
#define HAVE_MKTIME 1
|
||||
#define HAVE_QSORT 1
|
||||
#define HAVE_RAISE 1
|
||||
#define HAVE_SETJMP 1
|
||||
#define HAVE_SIGNAL 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#define HAVE_STAT 1
|
||||
#define HAVE_STRCHR 1
|
||||
#define HAVE_STRDUP 1
|
||||
#define HAVE_STRERROR 1
|
||||
#define HAVE_STRFTIME 1
|
||||
#define HAVE_STRRCHR 1
|
||||
#define HAVE_STRSTR 1
|
||||
#define HAVE_TIME 1
|
||||
#define HAVE_UMASK 1
|
||||
#define HAVE_UTIME 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
|
||||
#if (ACC_OS_BEOS || ACC_OS_CYGWIN || ACC_OS_POSIX || ACC_OS_QNX)
|
||||
# define HAVE_STRCASECMP 1
|
||||
# define HAVE_STRNCASECMP 1
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
# define HAVE_STRCASECMP 1
|
||||
# define HAVE_STRNCASECMP 1
|
||||
#else
|
||||
# define HAVE_STRICMP 1
|
||||
# define HAVE_STRNICMP 1
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_POSIX)
|
||||
# if (ACC_CC_TINYC)
|
||||
# undef HAVE_ALLOCA
|
||||
# elif defined(__dietlibc__)
|
||||
# endif
|
||||
# if (ACC_OS_POSIX_MACOSX && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
/* FIXME ??? */
|
||||
# undef HAVE_CHOWN
|
||||
# undef HAVE_LSTAT
|
||||
# endif
|
||||
#elif (ACC_OS_CYGWIN)
|
||||
# if (ACC_CC_GNUC < 0x025a00ul)
|
||||
# undef HAVE_GETTIMEOFDAY
|
||||
# undef HAVE_LSTAT
|
||||
# endif
|
||||
# if (ACC_CC_GNUC < 0x025f00ul)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# endif
|
||||
#elif (ACC_OS_EMX)
|
||||
# undef HAVE_CHOWN
|
||||
# undef HAVE_LSTAT
|
||||
#elif (ACC_OS_TOS && ACC_CC_GNUC)
|
||||
# if !defined(__MINT__)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# endif
|
||||
#elif (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
|
||||
# undef HAVE_ALLOCA
|
||||
# undef HAVE_ACCESS
|
||||
# undef HAVE_CHMOD
|
||||
# undef HAVE_CHOWN
|
||||
# undef HAVE_FSTAT
|
||||
# undef HAVE_GETTIMEOFDAY
|
||||
# undef HAVE_LSTAT
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_UMASK
|
||||
# undef HAVE_UTIME
|
||||
# undef HAVE_VSNPRINTF
|
||||
#endif
|
||||
|
||||
|
||||
/* DOS, OS/2 & Windows */
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
|
||||
#undef HAVE_CHOWN
|
||||
#undef HAVE_GETTIMEOFDAY
|
||||
#undef HAVE_LSTAT
|
||||
#undef HAVE_UMASK
|
||||
|
||||
#if (ACC_CC_AZTECC)
|
||||
# undef HAVE_ALLOCA
|
||||
# undef HAVE_DIFFTIME /* difftime() is in the math library */
|
||||
# undef HAVE_FSTAT
|
||||
# undef HAVE_STRDUP /* missing in 5.2a */
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_UTIME /* struct utimbuf is missing */
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_CC_BORLANDC)
|
||||
# if (__BORLANDC__ < 0x0400)
|
||||
# undef HAVE_ALLOCA
|
||||
# undef HAVE_UTIME
|
||||
# endif
|
||||
# if ((__BORLANDC__ < 0x0410) && ACC_OS_WIN16)
|
||||
# undef HAVE_ALLOCA
|
||||
# endif
|
||||
# if (__BORLANDC__ < 0x0550)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# endif
|
||||
#elif (ACC_CC_DMC)
|
||||
# if (ACC_OS_WIN16)
|
||||
# undef HAVE_ALLOCA
|
||||
# endif
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_HIGHC)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_CC_IBMC)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_CC_INTELC)
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
#elif (ACC_CC_LCC)
|
||||
# define utime _utime
|
||||
#elif (ACC_CC_MSC)
|
||||
# if (_MSC_VER < 600)
|
||||
# undef HAVE_STRFTIME
|
||||
# endif
|
||||
# if (_MSC_VER < 700)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# else
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# if ((_MSC_VER < 800) && ACC_OS_WIN16)
|
||||
# undef HAVE_ALLOCA
|
||||
# endif
|
||||
# if (ACC_ARCH_IA16) && defined(__cplusplus)
|
||||
# undef HAVE_LONGJMP
|
||||
# undef HAVE_SETJMP
|
||||
# endif
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__MINGW32__)
|
||||
# if (ACC_CC_GNUC < 0x025f00ul)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# else
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
# if (__MSL__ < 0x8000ul)
|
||||
# undef HAVE_CHMOD /* <unix.h> which in turn pulls in <windows.h> */
|
||||
# endif
|
||||
#elif (ACC_CC_NDPC)
|
||||
# undef HAVE_ALLOCA
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_STRNICMP
|
||||
# undef HAVE_UTIME
|
||||
# undef HAVE_VSNPRINTF
|
||||
# if defined(__cplusplus)
|
||||
# undef HAVE_STAT
|
||||
# endif
|
||||
#elif (ACC_CC_PACIFICC)
|
||||
# undef HAVE_ACCESS
|
||||
# undef HAVE_ALLOCA
|
||||
# undef HAVE_CHMOD
|
||||
# undef HAVE_DIFFTIME
|
||||
# undef HAVE_FSTAT
|
||||
# undef HAVE_MKTIME
|
||||
# undef HAVE_RAISE
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_STRFTIME
|
||||
# undef HAVE_UTIME
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_PELLESC)
|
||||
# if (__POCC__ < 280)
|
||||
# define alloca _alloca
|
||||
# undef HAVE_UTIME
|
||||
# endif
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_PGI) && defined(__MINGW32__)
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_CC_SYMANTECC)
|
||||
# if (ACC_OS_WIN16 && (ACC_MM_MEDIUM || ACC_MM_LARGE || ACC_MM_HUGE))
|
||||
# undef HAVE_ALLOCA
|
||||
# endif
|
||||
# if (__SC__ < 0x600)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# else
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# if (__SC__ < 0x700)
|
||||
# undef HAVE_DIFFTIME /* difftime() is broken */
|
||||
# undef HAVE_UTIME /* struct utimbuf is missing */
|
||||
# endif
|
||||
#elif (ACC_CC_TOPSPEEDC)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_CC_TURBOC)
|
||||
# undef HAVE_ALLOCA
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# if (__TURBOC__ < 0x0200)
|
||||
# undef HAVE_RAISE
|
||||
# undef HAVE_SIGNAL
|
||||
# endif
|
||||
# if (__TURBOC__ < 0x0295)
|
||||
# undef HAVE_MKTIME
|
||||
# undef HAVE_STRFTIME
|
||||
# endif
|
||||
# if (__TURBOC__ < 0x0400)
|
||||
# undef HAVE_UTIME
|
||||
# endif
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# if (__WATCOMC__ < 1100)
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# elif (__WATCOMC__ < 1200)
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
#elif (ACC_CC_ZORTECHC)
|
||||
# if (ACC_OS_WIN16 && (ACC_MM_MEDIUM || ACC_MM_LARGE || ACC_MM_HUGE))
|
||||
# undef HAVE_ALLOCA
|
||||
# endif
|
||||
# undef HAVE_DIFFTIME /* difftime() is broken */
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_UTIME /* struct utimbuf is missing */
|
||||
# undef HAVE_VSNPRINTF
|
||||
#endif
|
||||
|
||||
#endif /* DOS, OS/2 & Windows */
|
||||
|
||||
|
||||
#endif /* !defined(ACC_CONFIG_AUTO_NO_FUNCTIONS) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Checks for sizes
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(ACC_CONFIG_AUTO_NO_SIZES)
|
||||
|
||||
#define SIZEOF_SHORT (__ACC_SHORT_BIT / 8)
|
||||
#define SIZEOF_INT (__ACC_INT_BIT / 8)
|
||||
#define SIZEOF_LONG (__ACC_LONG_BIT / 8)
|
||||
|
||||
#if (ACC_OS_WIN64) /* LLP64 programming model */
|
||||
# define SIZEOF_PTRDIFF_T 8
|
||||
# define SIZEOF_SIZE_T 8
|
||||
# define SIZEOF_VOID_P 8
|
||||
#elif (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
|
||||
# define SIZEOF_SIZE_T 2
|
||||
# if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
# define SIZEOF_VOID_P 2
|
||||
# elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
|
||||
# define SIZEOF_VOID_P 4
|
||||
# else
|
||||
# error "ACC_MM"
|
||||
# endif
|
||||
# if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
# define SIZEOF_PTRDIFF_T 2
|
||||
# elif (ACC_MM_COMPACT || ACC_MM_LARGE)
|
||||
# if (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
# define SIZEOF_PTRDIFF_T 4
|
||||
# else
|
||||
# define SIZEOF_PTRDIFF_T 2
|
||||
# endif
|
||||
# elif (ACC_MM_HUGE)
|
||||
# define SIZEOF_PTRDIFF_T 4
|
||||
# else
|
||||
# error "ACC_MM"
|
||||
# endif
|
||||
#elif (ACC_ARCH_AVR || ACC_ARCH_C166 || ACC_ARCH_MCS51 || ACC_ARCH_MCS251)
|
||||
# define SIZEOF_PTRDIFF_T 2
|
||||
# define SIZEOF_SIZE_T 2
|
||||
# define SIZEOF_VOID_P 2
|
||||
#else
|
||||
# define SIZEOF_PTRDIFF_T SIZEOF_LONG
|
||||
# define SIZEOF_SIZE_T SIZEOF_LONG
|
||||
# define SIZEOF_VOID_P SIZEOF_LONG
|
||||
#endif
|
||||
|
||||
#if !defined(SIZEOF_CHAR_P) && (SIZEOF_VOID_P > 0)
|
||||
# define SIZEOF_CHAR_P SIZEOF_VOID_P
|
||||
#endif
|
||||
|
||||
|
||||
#if ((SIZEOF_LONG) > 0 && (SIZEOF_LONG) < 8)
|
||||
#if (ACC_ARCH_IA16 && ACC_CC_DMC)
|
||||
#elif (ACC_CC_GNUC)
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
#elif ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MSC && (_MSC_VER >= 1400))
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
#elif (ACC_OS_WIN64)
|
||||
# define SIZEOF___INT64 8
|
||||
# define SIZEOF_UNSIGNED___INT64 8
|
||||
#elif (ACC_ARCH_IA32 && (ACC_CC_DMC))
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
#elif (ACC_ARCH_IA32 && (ACC_CC_SYMANTECC && (__SC__ >= 0x700)))
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
#elif (ACC_ARCH_IA32 && (ACC_CC_INTELC && defined(__linux__)))
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
#elif (ACC_ARCH_IA32 && (ACC_CC_MWERKS || ACC_CC_PELLESC || ACC_CC_PGI))
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
#elif (ACC_ARCH_IA32 && (ACC_CC_INTELC || ACC_CC_MSC))
|
||||
# define SIZEOF___INT64 8
|
||||
# define SIZEOF_UNSIGNED___INT64 8
|
||||
#elif (ACC_ARCH_IA32 && (ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0520)))
|
||||
/* INFO: unsigned __int64 is somewhat broken in 0x0520; fixed in 0x0530 */
|
||||
# define SIZEOF___INT64 8
|
||||
# define SIZEOF_UNSIGNED___INT64 8
|
||||
#elif (ACC_ARCH_IA32 && (ACC_CC_WATCOMC && (__WATCOMC__ >= 1100)))
|
||||
# define SIZEOF___INT64 8
|
||||
# define SIZEOF_UNSIGNED___INT64 8
|
||||
#elif (ACC_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64))
|
||||
# define SIZEOF___INT64 8
|
||||
# define SIZEOF_UNSIGNED___INT64 8
|
||||
#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus) && defined(ACC_CC_GNUC)
|
||||
# if (ACC_CC_GNUC < 0x020800ul)
|
||||
# undef SIZEOF_LONG_LONG
|
||||
# undef SIZEOF_UNSIGNED_LONG_LONG
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* !defined(ACC_CONFIG_AUTO_NO_SIZES) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(HAVE_SIGNAL) && !defined(RETSIGTYPE)
|
||||
# define RETSIGTYPE void
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,143 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* C/C++ Compiler - exactly one of:
|
||||
*
|
||||
* ACC_CC_UNKNOWN [default]
|
||||
* ACC_CC_GNUC
|
||||
* ...
|
||||
*/
|
||||
|
||||
#if defined(CIL) && defined(_GNUCC) && defined(__GNUC__)
|
||||
# define ACC_CC_CILLY 1
|
||||
# define ACC_INFO_CC "Cilly"
|
||||
# define ACC_INFO_CCVER "unknown"
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
# define ACC_CC_INTELC 1
|
||||
# define ACC_INFO_CC "Intel C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__INTEL_COMPILER)
|
||||
#elif defined(__POCC__)
|
||||
# define ACC_CC_PELLESC 1
|
||||
# define ACC_INFO_CC "Pelles C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__POCC__)
|
||||
#elif defined(__GNUC__) && defined(__VERSION__)
|
||||
# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
|
||||
# define ACC_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
|
||||
# elif defined(__GNUC_MINOR__)
|
||||
# define ACC_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
|
||||
# else
|
||||
# define ACC_CC_GNUC (__GNUC__ * 0x10000L)
|
||||
# endif
|
||||
# define ACC_INFO_CC "gcc"
|
||||
# define ACC_INFO_CCVER __VERSION__
|
||||
#elif defined(__AZTEC_C__)
|
||||
# define ACC_CC_AZTECC 1
|
||||
# define ACC_INFO_CC "Aztec C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__AZTEC_C__)
|
||||
#elif defined(__BORLANDC__)
|
||||
# define ACC_CC_BORLANDC 1
|
||||
# define ACC_INFO_CC "Borland C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__BORLANDC__)
|
||||
#elif defined(__DMC__)
|
||||
# define ACC_CC_DMC 1
|
||||
# define ACC_INFO_CC "Digital Mars C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__DMC__)
|
||||
#elif defined(__DECC)
|
||||
# define ACC_CC_DECC 1
|
||||
# define ACC_INFO_CC "DEC C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__DECC)
|
||||
#elif defined(__HIGHC__)
|
||||
# define ACC_CC_HIGHC 1
|
||||
# define ACC_INFO_CC "MetaWare High C"
|
||||
# define ACC_INFO_CCVER "unknown"
|
||||
#elif defined(__IBMC__)
|
||||
# define ACC_CC_IBMC 1
|
||||
# define ACC_INFO_CC "IBM C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__IBMC__)
|
||||
#elif defined(__KEIL__) && defined(__C166__)
|
||||
# define ACC_CC_KEILC 1
|
||||
# define ACC_INFO_CC "Keil C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__C166__)
|
||||
#elif defined(__LCC__)
|
||||
# define ACC_CC_LCC 1
|
||||
# define ACC_INFO_CC "lcc"
|
||||
# define ACC_INFO_CCVER "unknown"
|
||||
#elif defined(_MSC_VER)
|
||||
# define ACC_CC_MSC 1
|
||||
# define ACC_INFO_CC "Microsoft C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(_MSC_VER)
|
||||
#elif defined(__MWERKS__)
|
||||
# define ACC_CC_MWERKS 1
|
||||
# define ACC_INFO_CC "Metrowerks C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__MWERKS__)
|
||||
#elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386)
|
||||
# define ACC_CC_NDPC 1
|
||||
# define ACC_INFO_CC "Microway NDP C"
|
||||
# define ACC_INFO_CCVER "unknown"
|
||||
#elif defined(__PACIFIC__)
|
||||
# define ACC_CC_PACIFICC 1
|
||||
# define ACC_INFO_CC "Pacific C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__PACIFIC__)
|
||||
#elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__))
|
||||
# define ACC_CC_PGI 1
|
||||
# define ACC_INFO_CC "Portland Group PGI C"
|
||||
# define ACC_INFO_CCVER "unknown"
|
||||
#elif defined(__PUREC__)
|
||||
# define ACC_CC_PUREC 1
|
||||
# define ACC_INFO_CC "Pure C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__PUREC__)
|
||||
#elif defined(__SC__)
|
||||
# define ACC_CC_SYMANTECC 1
|
||||
# define ACC_INFO_CC "Symantec C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__SC__)
|
||||
#elif defined(__SUNPRO_C)
|
||||
# define ACC_CC_SUNPROC 1
|
||||
# define ACC_INFO_CC "Sun C"
|
||||
# define ACC_INFO_CCVER "unknown"
|
||||
#elif defined(__TINYC__)
|
||||
# define ACC_CC_TINYC 1
|
||||
# define ACC_INFO_CC "Tiny C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__TINYC__)
|
||||
#elif defined(__TSC__)
|
||||
# define ACC_CC_TOPSPEEDC 1
|
||||
# define ACC_INFO_CC "TopSpeed C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__TSC__)
|
||||
#elif defined(__WATCOMC__)
|
||||
# define ACC_CC_WATCOMC 1
|
||||
# define ACC_INFO_CC "Watcom C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__WATCOMC__)
|
||||
#elif defined(__TURBOC__)
|
||||
# define ACC_CC_TURBOC 1
|
||||
# define ACC_INFO_CC "Turbo C"
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__TURBOC__)
|
||||
#elif defined(__ZTC__)
|
||||
# define ACC_CC_ZORTECHC 1
|
||||
# define ACC_INFO_CC "Zortech C"
|
||||
# if (__ZTC__ == 0x310)
|
||||
# define ACC_INFO_CCVER "0x310"
|
||||
# else
|
||||
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__ZTC__)
|
||||
# endif
|
||||
#else
|
||||
# define ACC_CC_UNKNOWN 1
|
||||
# define ACC_INFO_CC "unknown"
|
||||
# define ACC_INFO_CCVER "unknown"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,455 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(ACCCHK_ASSERT)
|
||||
# define ACCCHK_ASSERT(expr) ACC_COMPILE_TIME_ASSERT(expr)
|
||||
#endif
|
||||
|
||||
/* compile-time sign */
|
||||
#if !defined(ACCCHK_ASSERT_SIGN_T)
|
||||
# define ACCCHK_ASSERT_SIGN_T(type,relop) \
|
||||
ACCCHK_ASSERT( (type) (-1) relop (type) 0 ) \
|
||||
ACCCHK_ASSERT( (type) (~(type)0) relop (type) 0 ) \
|
||||
ACCCHK_ASSERT( (type) (~(type)0) == (type) (-1) )
|
||||
#endif
|
||||
|
||||
#if !defined(ACCCHK_IS_SIGNED_T)
|
||||
# define ACCCHK_ASSERT_IS_SIGNED_T(type) ACCCHK_ASSERT_SIGN_T(type,<)
|
||||
#endif
|
||||
|
||||
#if !defined(ACCCHK_IS_UNSIGNED_T)
|
||||
# if (ACC_BROKEN_INTEGRAL_PROMOTION)
|
||||
# define ACCCHK_ASSERT_IS_UNSIGNED_T(type) \
|
||||
ACCCHK_ASSERT( (type) (-1) > (type) 0 )
|
||||
# else
|
||||
# define ACCCHK_ASSERT_IS_UNSIGNED_T(type) ACCCHK_ASSERT_SIGN_T(type,>)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// check preprocessor
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_0xffffffffL - ACC_UINT32L_C(4294967294) != 1)
|
||||
# error "preprocessor error 1"
|
||||
#endif
|
||||
#if (ACC_0xffffffffL - ACC_UINT32L_C(0xfffffffd) != 2)
|
||||
# error "preprocessor error 2"
|
||||
#endif
|
||||
|
||||
|
||||
#define ACCCHK_VAL 1
|
||||
#define ACCCHK_TMP1 ACCCHK_VAL
|
||||
#undef ACCCHK_VAL
|
||||
#define ACCCHK_VAL 2
|
||||
#define ACCCHK_TMP2 ACCCHK_VAL
|
||||
#if (ACCCHK_TMP1 != 2)
|
||||
# error "preprocessor error 3a"
|
||||
#endif
|
||||
#if (ACCCHK_TMP2 != 2)
|
||||
# error "preprocessor error 3b"
|
||||
#endif
|
||||
#undef ACCCHK_VAL
|
||||
#if (ACCCHK_TMP2)
|
||||
# error "preprocessor error 3c"
|
||||
#endif
|
||||
#if (ACCCHK_TMP2 + 0 != 0)
|
||||
# error "preprocessor error 3d"
|
||||
#endif
|
||||
#undef ACCCHK_TMP1
|
||||
#undef ACCCHK_TMP2
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// check basic arithmetics
|
||||
**************************************************************************/
|
||||
|
||||
ACCCHK_ASSERT(1 == 1)
|
||||
|
||||
ACCCHK_ASSERT(__ACC_INT_MAX(2) == 1)
|
||||
ACCCHK_ASSERT(__ACC_INT_MAX(8) == 127)
|
||||
ACCCHK_ASSERT(__ACC_INT_MAX(16) == 32767)
|
||||
|
||||
ACCCHK_ASSERT(__ACC_UINT_MAX(2) == 3)
|
||||
ACCCHK_ASSERT(__ACC_UINT_MAX(16) == 0xffffU)
|
||||
ACCCHK_ASSERT(__ACC_UINT_MAX(32) == 0xffffffffUL)
|
||||
#if !defined(ACC_BROKEN_INTEGRAL_PROMOTION)
|
||||
ACCCHK_ASSERT(__ACC_UINT_MAX(__ACC_INT_BIT) == ~(0u))
|
||||
ACCCHK_ASSERT(__ACC_UINT_MAX(__ACC_LONG_BIT) == ~(0ul))
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// check basic types
|
||||
**************************************************************************/
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(signed char)
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(unsigned char)
|
||||
ACCCHK_ASSERT(sizeof(signed char) == sizeof(char))
|
||||
ACCCHK_ASSERT(sizeof(unsigned char) == sizeof(char))
|
||||
ACCCHK_ASSERT(sizeof(char) == 1)
|
||||
#if (ACC_CC_CILLY)
|
||||
/* CIL is broken */
|
||||
#else
|
||||
ACCCHK_ASSERT(sizeof(char) == sizeof((char)0))
|
||||
#endif
|
||||
#if defined(__cplusplus)
|
||||
ACCCHK_ASSERT(sizeof('\0') == sizeof(char))
|
||||
#else
|
||||
# if (ACC_CC_DMC)
|
||||
/* Digital Mars C is broken */
|
||||
# else
|
||||
ACCCHK_ASSERT(sizeof('\0') == sizeof(int))
|
||||
# endif
|
||||
#endif
|
||||
#if defined(acc_alignof)
|
||||
ACCCHK_ASSERT(acc_alignof(char) == 1)
|
||||
ACCCHK_ASSERT(acc_alignof(signed char) == 1)
|
||||
ACCCHK_ASSERT(acc_alignof(unsigned char) == 1)
|
||||
#endif
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(short)
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(unsigned short)
|
||||
ACCCHK_ASSERT(sizeof(short) == sizeof(unsigned short))
|
||||
ACCCHK_ASSERT(sizeof(short) >= 2)
|
||||
ACCCHK_ASSERT(sizeof(short) >= sizeof(char))
|
||||
#if (ACC_CC_CILLY)
|
||||
/* CIL is broken */
|
||||
#else
|
||||
ACCCHK_ASSERT(sizeof(short) == sizeof((short)0))
|
||||
#endif
|
||||
#if (SIZEOF_SHORT > 0)
|
||||
ACCCHK_ASSERT(sizeof(short) == SIZEOF_SHORT)
|
||||
#endif
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(int)
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(unsigned int)
|
||||
ACCCHK_ASSERT(sizeof(int) == sizeof(unsigned int))
|
||||
ACCCHK_ASSERT(sizeof(int) >= 2)
|
||||
ACCCHK_ASSERT(sizeof(int) >= sizeof(short))
|
||||
ACCCHK_ASSERT(sizeof(int) == sizeof(0))
|
||||
ACCCHK_ASSERT(sizeof(int) == sizeof((int)0))
|
||||
#if (SIZEOF_INT > 0)
|
||||
ACCCHK_ASSERT(sizeof(int) == SIZEOF_INT)
|
||||
#endif
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(long)
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(unsigned long)
|
||||
ACCCHK_ASSERT(sizeof(long) == sizeof(unsigned long))
|
||||
ACCCHK_ASSERT(sizeof(long) >= 4)
|
||||
ACCCHK_ASSERT(sizeof(long) >= sizeof(int))
|
||||
ACCCHK_ASSERT(sizeof(long) == sizeof(0L))
|
||||
ACCCHK_ASSERT(sizeof(long) == sizeof((long)0))
|
||||
#if (SIZEOF_LONG > 0)
|
||||
ACCCHK_ASSERT(sizeof(long) == SIZEOF_LONG)
|
||||
#endif
|
||||
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(size_t)
|
||||
ACCCHK_ASSERT(sizeof(size_t) >= sizeof(int))
|
||||
ACCCHK_ASSERT(sizeof(size_t) == sizeof(sizeof(0))) /* sizeof() returns size_t */
|
||||
#if (SIZEOF_SIZE_T > 0)
|
||||
ACCCHK_ASSERT(sizeof(size_t) == SIZEOF_SIZE_T)
|
||||
#endif
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(ptrdiff_t)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) >= sizeof(int))
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) >= sizeof(size_t))
|
||||
#if !defined(ACC_BROKEN_SIZEOF)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) == sizeof((char*)0 - (char*)0))
|
||||
# if (ACC_HAVE_MM_HUGE_PTR)
|
||||
ACCCHK_ASSERT(4 == sizeof((char __huge*)0 - (char __huge*)0))
|
||||
# endif
|
||||
#endif
|
||||
#if (SIZEOF_PTRDIFF_T > 0)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) == SIZEOF_PTRDIFF_T)
|
||||
#endif
|
||||
|
||||
ACCCHK_ASSERT(sizeof(void*) >= sizeof(char*))
|
||||
#if (SIZEOF_VOID_P > 0)
|
||||
ACCCHK_ASSERT(sizeof(void*) == SIZEOF_VOID_P)
|
||||
#endif
|
||||
#if (SIZEOF_CHAR_P > 0)
|
||||
ACCCHK_ASSERT(sizeof(char*) == SIZEOF_CHAR_P)
|
||||
#endif
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
ACCCHK_ASSERT(4 == sizeof(void __huge*))
|
||||
ACCCHK_ASSERT(4 == sizeof(char __huge*))
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// check arithmetics
|
||||
**************************************************************************/
|
||||
|
||||
ACCCHK_ASSERT((((1u << 15) + 1) >> 15) == 1)
|
||||
ACCCHK_ASSERT((((1ul << 31) + 1) >> 31) == 1)
|
||||
|
||||
#if (ACC_CC_TURBOC && (__TURBOC__ < 0x0150))
|
||||
/* TC 1.0 bug, probably due to ACC_BROKEN_INTEGRAL_PROMOTION ?? */
|
||||
#else
|
||||
ACCCHK_ASSERT((1 << (8*SIZEOF_INT-1)) < 0)
|
||||
#endif
|
||||
ACCCHK_ASSERT((1u << (8*SIZEOF_INT-1)) > 0)
|
||||
|
||||
ACCCHK_ASSERT((1l << (8*SIZEOF_LONG-1)) < 0)
|
||||
ACCCHK_ASSERT((1ul << (8*SIZEOF_LONG-1)) > 0)
|
||||
|
||||
#if defined(acc_int32e_t)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32e_t) == 4)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32e_t) == SIZEOF_ACC_INT32E_T)
|
||||
ACCCHK_ASSERT(sizeof(acc_uint32e_t) == 4)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32e_t) == sizeof(acc_uint32e_t))
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(acc_int32e_t)
|
||||
ACCCHK_ASSERT(((( (acc_int32e_t)1 << 30) + 1) >> 30) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_INT32E_C(1) << 30) + 1) >> 30) == 1)
|
||||
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(acc_uint32e_t)
|
||||
ACCCHK_ASSERT(((( (acc_uint32e_t)1 << 31) + 1) >> 31) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_UINT32E_C(1) << 31) + 1) >> 31) == 1)
|
||||
|
||||
ACCCHK_ASSERT( (acc_int32e_t) (1 + ~(acc_int32e_t)0) == 0)
|
||||
#if defined(ACCCHK_CONFIG_PEDANTIC)
|
||||
/* compiler may warn about overflow */
|
||||
ACCCHK_ASSERT( (acc_uint32e_t)(1 + ~(acc_uint32e_t)0) == 0)
|
||||
#endif /* ACCCHK_CONFIG_PEDANTIC */
|
||||
|
||||
#if (SIZEOF_ACC_INT32E_T < SIZEOF_INT)
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT32E_C(0)) == sizeof(int))
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT32E_C(0)) == sizeof(int))
|
||||
#else
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT32E_C(0)) == SIZEOF_ACC_INT32E_T)
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT32E_C(0)) == SIZEOF_ACC_INT32E_T)
|
||||
#endif
|
||||
ACCCHK_ASSERT((ACC_INT32E_C(1) << (8*SIZEOF_ACC_INT32E_T-1)) < 0)
|
||||
ACCCHK_ASSERT((ACC_UINT32E_C(1) << (8*SIZEOF_ACC_INT32E_T-1)) > 0)
|
||||
ACCCHK_ASSERT((ACC_INT32E_C(1) << (int)(8*sizeof(ACC_INT32E_C(1))-1)) < 0)
|
||||
ACCCHK_ASSERT((ACC_UINT32E_C(1) << (int)(8*sizeof(ACC_UINT32E_C(1))-1)) > 0)
|
||||
ACCCHK_ASSERT(ACC_INT32E_C(2147483647) > 0)
|
||||
ACCCHK_ASSERT(ACC_INT32E_C(-2147483647) -1 < 0)
|
||||
ACCCHK_ASSERT(ACC_UINT32E_C(4294967295) > 0)
|
||||
ACCCHK_ASSERT(ACC_UINT32E_C(4294967295) == ACC_0xffffffffL)
|
||||
#endif
|
||||
|
||||
|
||||
ACCCHK_ASSERT(sizeof(acc_int32l_t) >= sizeof(int))
|
||||
#if defined(acc_int32e_t)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32l_t) >= sizeof(acc_int32e_t))
|
||||
#endif
|
||||
|
||||
ACCCHK_ASSERT(sizeof(acc_int32l_t) >= 4)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32l_t) == SIZEOF_ACC_INT32L_T)
|
||||
ACCCHK_ASSERT(sizeof(acc_uint32l_t) >= 4)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32l_t) == sizeof(acc_uint32l_t))
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(acc_int32l_t)
|
||||
ACCCHK_ASSERT(((( (acc_int32l_t)1 << 30) + 1) >> 30) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_INT32L_C(1) << 30) + 1) >> 30) == 1)
|
||||
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(acc_uint32l_t)
|
||||
ACCCHK_ASSERT(((( (acc_uint32l_t)1 << 31) + 1) >> 31) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_UINT32L_C(1) << 31) + 1) >> 31) == 1)
|
||||
|
||||
#if (SIZEOF_ACC_INT32L_T < SIZEOF_INT)
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT32L_C(0)) == sizeof(int))
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT32L_C(0)) == sizeof(int))
|
||||
#else
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT32L_C(0)) == SIZEOF_ACC_INT32L_T)
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT32L_C(0)) == SIZEOF_ACC_INT32L_T)
|
||||
#endif
|
||||
ACCCHK_ASSERT((ACC_INT32L_C(1) << (8*SIZEOF_ACC_INT32L_T-1)) < 0)
|
||||
ACCCHK_ASSERT((ACC_UINT32L_C(1) << (8*SIZEOF_ACC_INT32L_T-1)) > 0)
|
||||
ACCCHK_ASSERT((ACC_INT32L_C(1) << (int)(8*sizeof(ACC_INT32L_C(1))-1)) < 0)
|
||||
ACCCHK_ASSERT((ACC_UINT32L_C(1) << (int)(8*sizeof(ACC_UINT32L_C(1))-1)) > 0)
|
||||
ACCCHK_ASSERT(ACC_INT32L_C(2147483647) > 0)
|
||||
ACCCHK_ASSERT(ACC_INT32L_C(-2147483647) -1 < 0)
|
||||
ACCCHK_ASSERT(ACC_UINT32L_C(4294967295) > 0)
|
||||
ACCCHK_ASSERT(ACC_UINT32L_C(4294967295) == ACC_0xffffffffL)
|
||||
|
||||
|
||||
ACCCHK_ASSERT(sizeof(acc_int32f_t) >= sizeof(int))
|
||||
#if defined(acc_int32e_t)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32f_t) >= sizeof(acc_int32e_t))
|
||||
#endif
|
||||
ACCCHK_ASSERT(sizeof(acc_int32f_t) >= sizeof(acc_int32l_t))
|
||||
|
||||
ACCCHK_ASSERT(sizeof(acc_int32f_t) >= 4)
|
||||
ACCCHK_ASSERT(sizeof(acc_int32f_t) >= sizeof(acc_int32l_t))
|
||||
ACCCHK_ASSERT(sizeof(acc_int32f_t) == SIZEOF_ACC_INT32F_T)
|
||||
ACCCHK_ASSERT(sizeof(acc_uint32f_t) >= 4)
|
||||
ACCCHK_ASSERT(sizeof(acc_uint32f_t) >= sizeof(acc_uint32l_t))
|
||||
ACCCHK_ASSERT(sizeof(acc_int32f_t) == sizeof(acc_uint32f_t))
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(acc_int32f_t)
|
||||
ACCCHK_ASSERT(((( (acc_int32f_t)1 << 30) + 1) >> 30) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_INT32F_C(1) << 30) + 1) >> 30) == 1)
|
||||
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(acc_uint32f_t)
|
||||
ACCCHK_ASSERT(((( (acc_uint32f_t)1 << 31) + 1) >> 31) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_UINT32F_C(1) << 31) + 1) >> 31) == 1)
|
||||
|
||||
#if (SIZEOF_ACC_INT32F_T < SIZEOF_INT)
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT32F_C(0)) == sizeof(int))
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT32F_C(0)) == sizeof(int))
|
||||
#else
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT32F_C(0)) == SIZEOF_ACC_INT32F_T)
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT32F_C(0)) == SIZEOF_ACC_INT32F_T)
|
||||
#endif
|
||||
ACCCHK_ASSERT((ACC_INT32F_C(1) << (8*SIZEOF_ACC_INT32F_T-1)) < 0)
|
||||
ACCCHK_ASSERT((ACC_UINT32F_C(1) << (8*SIZEOF_ACC_INT32F_T-1)) > 0)
|
||||
ACCCHK_ASSERT((ACC_INT32F_C(1) << (int)(8*sizeof(ACC_INT32F_C(1))-1)) < 0)
|
||||
ACCCHK_ASSERT((ACC_UINT32F_C(1) << (int)(8*sizeof(ACC_UINT32F_C(1))-1)) > 0)
|
||||
ACCCHK_ASSERT(ACC_INT32F_C(2147483647) > 0)
|
||||
ACCCHK_ASSERT(ACC_INT32F_C(-2147483647) -1 < 0)
|
||||
ACCCHK_ASSERT(ACC_UINT32F_C(4294967295) > 0)
|
||||
ACCCHK_ASSERT(ACC_UINT32F_C(4294967295) == ACC_0xffffffffL)
|
||||
|
||||
|
||||
#if defined(acc_int64l_t)
|
||||
ACCCHK_ASSERT(sizeof(acc_int64l_t) >= 8)
|
||||
ACCCHK_ASSERT(sizeof(acc_int64l_t) == SIZEOF_ACC_INT64L_T)
|
||||
ACCCHK_ASSERT(sizeof(acc_uint64l_t) >= 8)
|
||||
ACCCHK_ASSERT(sizeof(acc_int64l_t) == sizeof(acc_uint64l_t))
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(acc_int64l_t)
|
||||
ACCCHK_ASSERT(((( (acc_int64l_t)1 << 62) + 1) >> 62) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_INT64L_C(1) << 62) + 1) >> 62) == 1)
|
||||
|
||||
#if (ACC_CC_BORLANDC && (__BORLANDC__ < 0x0530))
|
||||
/* Borland C is broken */
|
||||
#else
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(acc_uint64l_t)
|
||||
ACCCHK_ASSERT(ACC_UINT64L_C(18446744073709551615) > 0)
|
||||
#endif
|
||||
ACCCHK_ASSERT(((( (acc_uint64l_t)1 << 63) + 1) >> 63) == 1)
|
||||
ACCCHK_ASSERT(((( ACC_UINT64L_C(1) << 63) + 1) >> 63) == 1)
|
||||
|
||||
#if defined(ACCCHK_CONFIG_PEDANTIC)
|
||||
#if (ACC_CC_BORLANDC && (__BORLANDC__ < 0x0560))
|
||||
/* Borland C is broken */
|
||||
#elif (SIZEOF_ACC_INT64L_T < SIZEOF_INT)
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT64L_C(0)) == sizeof(int))
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT64L_C(0)) == sizeof(int))
|
||||
#else
|
||||
ACCCHK_ASSERT(sizeof(ACC_INT64L_C(0)) == SIZEOF_ACC_INT64L_T)
|
||||
ACCCHK_ASSERT(sizeof(ACC_UINT64L_C(0)) == SIZEOF_ACC_INT64L_T)
|
||||
#endif
|
||||
#endif /* ACCCHK_CONFIG_PEDANTIC */
|
||||
ACCCHK_ASSERT((ACC_INT64L_C(1) << (8*SIZEOF_ACC_INT64L_T-1)) < 0)
|
||||
ACCCHK_ASSERT((ACC_UINT64L_C(1) << (8*SIZEOF_ACC_INT64L_T-1)) > 0)
|
||||
#if (ACC_CC_GNUC && (ACC_CC_GNUC < 0x020600ul))
|
||||
/* avoid pedantic warning */
|
||||
ACCCHK_ASSERT(ACC_INT64L_C(9223372036854775807) > ACC_INT64L_C(0))
|
||||
#else
|
||||
ACCCHK_ASSERT(ACC_INT64L_C(9223372036854775807) > 0)
|
||||
#endif
|
||||
ACCCHK_ASSERT(ACC_INT64L_C(-9223372036854775807) - 1 < 0)
|
||||
|
||||
ACCCHK_ASSERT( ACC_INT64L_C(9223372036854775807) % 2147483629l == 721)
|
||||
ACCCHK_ASSERT( ACC_INT64L_C(9223372036854775807) % 2147483647l == 1)
|
||||
ACCCHK_ASSERT(ACC_UINT64L_C(9223372036854775807) % 2147483629ul == 721)
|
||||
ACCCHK_ASSERT(ACC_UINT64L_C(9223372036854775807) % 2147483647ul == 1)
|
||||
#endif /* acc_int64l_t */
|
||||
|
||||
|
||||
ACCCHK_ASSERT_IS_SIGNED_T(acc_intptr_t)
|
||||
ACCCHK_ASSERT_IS_UNSIGNED_T(acc_uintptr_t)
|
||||
ACCCHK_ASSERT(sizeof(acc_intptr_t) >= sizeof(void *))
|
||||
ACCCHK_ASSERT(sizeof(acc_intptr_t) == SIZEOF_ACC_INTPTR_T)
|
||||
ACCCHK_ASSERT(sizeof(acc_intptr_t) == sizeof(acc_uintptr_t))
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// check memory model ACC_MM
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_MM_FLAT)
|
||||
#if 0
|
||||
/* this is not a valid assumption -- disabled */
|
||||
ACCCHK_ASSERT(sizeof(void*) == sizeof(void (*)(void)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
ACCCHK_ASSERT(sizeof(void*) == 2)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) == 2)
|
||||
#elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
|
||||
ACCCHK_ASSERT(sizeof(void*) == 4)
|
||||
#endif
|
||||
#if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_COMPACT)
|
||||
ACCCHK_ASSERT(sizeof(void (*)(void)) == 2)
|
||||
#elif (ACC_MM_MEDIUM || ACC_MM_LARGE || ACC_MM_HUGE)
|
||||
ACCCHK_ASSERT(sizeof(void (*)(void)) == 4)
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// check ACC_ARCH and ACC_OS
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_ARCH_IA16)
|
||||
ACCCHK_ASSERT(sizeof(size_t) == 2)
|
||||
ACCCHK_ASSERT(sizeof(acc_intptr_t) == sizeof(void *))
|
||||
#elif (ACC_ARCH_IA32 || ACC_ARCH_M68K)
|
||||
ACCCHK_ASSERT(sizeof(size_t) == 4)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) == 4)
|
||||
ACCCHK_ASSERT(sizeof(acc_intptr_t) == sizeof(void *))
|
||||
#elif (ACC_ARCH_AMD64 || ACC_ARCH_IA64)
|
||||
ACCCHK_ASSERT(sizeof(size_t) == 8)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) == 8)
|
||||
ACCCHK_ASSERT(sizeof(acc_intptr_t) == sizeof(void *))
|
||||
#endif
|
||||
|
||||
#if (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_WIN32)
|
||||
ACCCHK_ASSERT(sizeof(size_t) == 4)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) == 4)
|
||||
ACCCHK_ASSERT(sizeof(void (*)(void)) == 4)
|
||||
#elif (ACC_OS_WIN64)
|
||||
ACCCHK_ASSERT(sizeof(size_t) == 8)
|
||||
ACCCHK_ASSERT(sizeof(ptrdiff_t) == 8)
|
||||
ACCCHK_ASSERT(sizeof(void (*)(void)) == 8)
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// check promotion rules
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_CC_NDPC)
|
||||
/* NDP C is broken */
|
||||
#else
|
||||
/* check that the compiler correctly casts signed to unsigned */
|
||||
ACCCHK_ASSERT( (int) ((unsigned char) ((signed char) -1)) == 255)
|
||||
#endif
|
||||
|
||||
#if (ACC_CC_KEILC)
|
||||
/* Keil C is broken */
|
||||
#elif (ACC_CC_NDPC)
|
||||
/* NDP C is broken */
|
||||
#elif !defined(ACC_BROKEN_INTEGRAL_PROMOTION) && (SIZEOF_INT > 1)
|
||||
/* check that the compiler correctly promotes integrals */
|
||||
ACCCHK_ASSERT( (((unsigned char)128) << (int)(8*sizeof(int)-8)) < 0)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,126 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(__ACCCHKR_FUNCNAME)
|
||||
# define __ACCCHKR_FUNCNAME(f) accchkr_ ## f
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(ACCCHKR_ASSERT)
|
||||
|
||||
#if 0 || defined(ACCCHKR_CONFIG_DEBUG)
|
||||
|
||||
#include <stdio.h>
|
||||
static int __ACCCHKR_FUNCNAME(assert_fail)(const char* s, unsigned l)
|
||||
{
|
||||
fprintf(stderr, "ACCCHKR assertion failed in line %u: `%s'\n", l, s);
|
||||
return 0;
|
||||
}
|
||||
#define ACCCHKR_ASSERT(expr) ((expr) ? 1 : __ACCCHKR_FUNCNAME(assert_fail)(#expr,__LINE__))
|
||||
|
||||
#else
|
||||
|
||||
#define ACCCHKR_ASSERT(expr) ((expr) ? 1 : 0)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* avoid inlining */
|
||||
static int __ACCCHKR_FUNCNAME(schedule_insns_bug)(void);
|
||||
static int __ACCCHKR_FUNCNAME(strength_reduce_bug)(int*);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// main entry
|
||||
**************************************************************************/
|
||||
|
||||
static int __ACCCHKR_FUNCNAME(check)(int r)
|
||||
{
|
||||
#if defined(ACC_ENDIAN_BIG_ENDIAN)
|
||||
{
|
||||
union { long l; unsigned char c[sizeof(long)]; } u;
|
||||
u.l = 0; u.c[sizeof(long)-1] = 0x80;
|
||||
r &= ACCCHKR_ASSERT(u.l == 128);
|
||||
u.l = 0; u.c[0] = 0x80;
|
||||
r &= ACCCHKR_ASSERT(u.l < 0);
|
||||
ACC_UNUSED(u);
|
||||
}
|
||||
#endif
|
||||
#if defined(ACC_ENDIAN_LITTLE_ENDIAN)
|
||||
{
|
||||
union { long l; unsigned char c[sizeof(long)]; } u;
|
||||
u.l = 0; u.c[0] = 0x80;
|
||||
r &= ACCCHKR_ASSERT(u.l == 128);
|
||||
u.l = 0; u.c[sizeof(long)-1] = 0x80;
|
||||
r &= ACCCHKR_ASSERT(u.l < 0);
|
||||
ACC_UNUSED(u);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* check for the gcc schedule-insns optimization bug */
|
||||
if (r == 1)
|
||||
{
|
||||
r &= ACCCHKR_ASSERT(!__ACCCHKR_FUNCNAME(schedule_insns_bug()));
|
||||
}
|
||||
|
||||
/* check for the gcc strength-reduce optimization bug */
|
||||
if (r == 1)
|
||||
{
|
||||
static int x[3];
|
||||
static unsigned xn = 3;
|
||||
register unsigned j;
|
||||
|
||||
for (j = 0; j < xn; j++)
|
||||
x[j] = (int)j - 3;
|
||||
r &= ACCCHKR_ASSERT(!__ACCCHKR_FUNCNAME(strength_reduce_bug(x)));
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
static int __ACCCHKR_FUNCNAME(schedule_insns_bug)(void)
|
||||
{
|
||||
const int a[] = {1, 2, 0}; const int* b;
|
||||
b = a; return (*b) ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
static int __ACCCHKR_FUNCNAME(strength_reduce_bug)(int* x)
|
||||
{
|
||||
#if 0 && (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
|
||||
ACC_UNUSED(x); return 0;
|
||||
#else
|
||||
return x[0] != -3 || x[1] != -2 || x[2] != -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,157 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ACC_CXX_H_INCLUDED
|
||||
#define __ACC_CXX_H_INCLUDED 1
|
||||
#if defined(__cplusplus)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// exception specification
|
||||
// ACC_CXX_NOTHROW
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(ACC_CXX_NOTHROW)
|
||||
#elif (ACC_CC_GNUC && (ACC_CC_GNUC < 0x020800ul))
|
||||
#elif (ACC_CC_BORLANDC && (__BORLANDC__ < 0x0450))
|
||||
#elif (ACC_CC_HIGHC)
|
||||
#elif (ACC_CC_MSC && (_MSC_VER < 1100))
|
||||
#elif (ACC_CC_NDPC)
|
||||
#elif (ACC_CC_TURBOC)
|
||||
#elif (ACC_CC_WATCOMC && !defined(_CPPUNWIND))
|
||||
#elif (ACC_CC_ZORTECHC)
|
||||
#else
|
||||
# define ACC_CXX_NOTHROW throw()
|
||||
#endif
|
||||
|
||||
#if !defined(ACC_CXX_NOTHROW)
|
||||
# define ACC_CXX_NOTHROW
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// disable dynamic allocation of an object - private helpers
|
||||
// __ACC_CXX_DO_NEW
|
||||
// __ACC_CXX_DO_DELETE
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(__ACC_CXX_DO_NEW)
|
||||
#elif (ACC_CC_NDPC || ACC_CC_PGI)
|
||||
# define __ACC_CXX_DO_NEW { return 0; }
|
||||
#else
|
||||
# define __ACC_CXX_DO_NEW ;
|
||||
#endif
|
||||
|
||||
|
||||
/* need an implementation in case a class has virtual members */
|
||||
#if defined(__ACC_CXX_DO_DELETE)
|
||||
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
# define __ACC_CXX_DO_DELETE { }
|
||||
#else
|
||||
# define __ACC_CXX_DO_DELETE ACC_CXX_NOTHROW { }
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// disable dynamic allocation of an object
|
||||
// ACC_CXX_DISABLE_NEW_DELETE
|
||||
**************************************************************************/
|
||||
|
||||
/*
|
||||
#undef __ACC_CXX_HAVE_ARRAY_NEW
|
||||
#undef __ACC_CXX_HAVE_PLACEMENT_NEW
|
||||
#undef __ACC_CXX_HAVE_PLACEMENT_DELETE
|
||||
*/
|
||||
|
||||
#if (ACC_CC_BORLANDC && (__BORLANDC__ < 0x0450))
|
||||
#elif (ACC_CC_MSC && ACC_MM_HUGE)
|
||||
# define ACC_CXX_DISABLE_NEW_DELETE private:
|
||||
#elif (ACC_CC_MSC && (_MSC_VER < 1100))
|
||||
#elif (ACC_CC_NDPC)
|
||||
#elif (ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
|
||||
#elif (ACC_CC_TURBOC)
|
||||
#elif (ACC_CC_WATCOMC && (__WATCOMC__ < 1100))
|
||||
#else
|
||||
# define __ACC_CXX_HAVE_ARRAY_NEW 1
|
||||
#endif
|
||||
|
||||
#if (__ACC_CXX_HAVE_ARRAY_NEW)
|
||||
# define __ACC_CXX_HAVE_PLACEMENT_NEW 1
|
||||
#endif
|
||||
|
||||
#if (__ACC_CXX_HAVE_PLACEMENT_NEW)
|
||||
# if (ACC_CC_GNUC >= 0x030000ul)
|
||||
# define __ACC_CXX_HAVE_PLACEMENT_DELETE 1
|
||||
# elif (ACC_CC_INTELC)
|
||||
# define __ACC_CXX_HAVE_PLACEMENT_DELETE 1
|
||||
# elif (ACC_CC_MSC && (_MSC_VER >= 1200))
|
||||
# define __ACC_CXX_HAVE_PLACEMENT_DELETE 1
|
||||
# elif (ACC_CC_PGI)
|
||||
# define __ACC_CXX_HAVE_PLACEMENT_DELETE 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(ACC_CXX_DISABLE_NEW_DELETE)
|
||||
#elif defined(new) || defined(delete)
|
||||
# define ACC_CXX_DISABLE_NEW_DELETE private:
|
||||
#elif (ACC_CC_GNUC && (ACC_CC_GNUC < 0x025b00ul))
|
||||
# define ACC_CXX_DISABLE_NEW_DELETE private:
|
||||
#elif (ACC_CC_HIGHC)
|
||||
# define ACC_CXX_DISABLE_NEW_DELETE private:
|
||||
#elif !defined(__ACC_CXX_HAVE_ARRAY_NEW)
|
||||
/* for old compilers use `protected' instead of `private' */
|
||||
# define ACC_CXX_DISABLE_NEW_DELETE \
|
||||
protected: static void operator delete(void*) __ACC_CXX_DO_DELETE \
|
||||
protected: static void* operator new(size_t) __ACC_CXX_DO_NEW \
|
||||
private:
|
||||
#else
|
||||
# define ACC_CXX_DISABLE_NEW_DELETE \
|
||||
protected: static void operator delete(void*) __ACC_CXX_DO_DELETE \
|
||||
static void operator delete[](void*) __ACC_CXX_DO_DELETE \
|
||||
private: static void* operator new(size_t) __ACC_CXX_DO_NEW \
|
||||
static void* operator new[](size_t) __ACC_CXX_DO_NEW
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Assist the compiler by defining a unique location for vtables and RTTI.
|
||||
// Every class which has virtual member functions or derives from a class
|
||||
// with virtual members should put this macro at the very top of its
|
||||
// class declaration.
|
||||
// ACC_CXX_TRIGGER_FUNCTION
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(ACC_CXX_TRIGGER_FUNCTION)
|
||||
#else
|
||||
# define ACC_CXX_TRIGGER_FUNCTION \
|
||||
protected: virtual const void* acc_cxx_trigger_function() const; \
|
||||
private:
|
||||
#endif
|
||||
|
||||
#if defined(ACC_CXX_TRIGGER_FUNCTION_IMPL)
|
||||
#else
|
||||
# define ACC_CXX_TRIGGER_FUNCTION_IMPL(klass) \
|
||||
const void* klass::acc_cxx_trigger_function() const { return 0; }
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __cplusplus */
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,191 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// acc_alignof() / acc_inline
|
||||
************************************************************************/
|
||||
|
||||
#if (ACC_CC_CILLY || ACC_CC_GNUC || ACC_CC_PGI)
|
||||
# define acc_alignof(e) __alignof__(e)
|
||||
#elif (ACC_CC_INTELC && (__INTEL_COMPILER >= 700))
|
||||
# define acc_alignof(e) __alignof__(e)
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 1300))
|
||||
# define acc_alignof(e) __alignof(e)
|
||||
#endif
|
||||
|
||||
#if (ACC_CC_TURBOC && (__TURBOC__ <= 0x0295))
|
||||
#elif defined(__cplusplus)
|
||||
# define acc_inline inline
|
||||
#elif (ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0550))
|
||||
# define acc_inline __inline
|
||||
#elif (ACC_CC_CILLY || ACC_CC_GNUC || ACC_CC_PGI)
|
||||
# define acc_inline __inline__
|
||||
#elif (ACC_CC_DMC)
|
||||
# define acc_inline __inline
|
||||
#elif (ACC_CC_INTELC)
|
||||
# define acc_inline __inline
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 900))
|
||||
# define acc_inline __inline
|
||||
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||
# define acc_inline inline
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// ACC_UNUSED / ACC_UNUSED_FUNC
|
||||
************************************************************************/
|
||||
|
||||
#if !defined(ACC_UNUSED)
|
||||
# if (ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
|
||||
# define ACC_UNUSED(var) ((void) &var)
|
||||
# elif (ACC_CC_BORLANDC || ACC_CC_HIGHC || ACC_CC_NDPC || ACC_CC_TURBOC)
|
||||
# define ACC_UNUSED(var) if (&var) ; else
|
||||
# elif (ACC_CC_MSC && (_MSC_VER < 900))
|
||||
# define ACC_UNUSED(var) if (&var) ; else
|
||||
# elif (ACC_CC_GNUC)
|
||||
# define ACC_UNUSED(var) ((void) var)
|
||||
# elif (ACC_CC_KEILC)
|
||||
# define ACC_UNUSED(var)
|
||||
# else
|
||||
# define ACC_UNUSED(var) ((void) &var)
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(ACC_UNUSED_FUNC)
|
||||
# if (ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
|
||||
# define ACC_UNUSED_FUNC(func) ((void) func)
|
||||
# elif (ACC_CC_BORLANDC || ACC_CC_NDPC || ACC_CC_TURBOC)
|
||||
# define ACC_UNUSED_FUNC(func) if (func) ; else
|
||||
# elif (ACC_CC_GNUC == 0x030400ul) && defined(__llvm__)
|
||||
# define ACC_UNUSED_FUNC(func) ((void) &func)
|
||||
# elif (ACC_CC_MSC && (_MSC_VER < 900))
|
||||
# define ACC_UNUSED_FUNC(func) if (func) ; else
|
||||
# elif (ACC_CC_MSC)
|
||||
# define ACC_UNUSED_FUNC(func) ((void) &func)
|
||||
# elif (ACC_CC_KEILC)
|
||||
# define ACC_UNUSED_FUNC(func)
|
||||
# else
|
||||
# define ACC_UNUSED_FUNC(func) ((void) func)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// compile-time-assertions
|
||||
************************************************************************/
|
||||
|
||||
/* This can be put into a header file but may get ignored by some compilers. */
|
||||
#if !defined(ACC_COMPILE_TIME_ASSERT_HEADER)
|
||||
# if (ACC_CC_AZTECC || ACC_CC_ZORTECHC)
|
||||
# define ACC_COMPILE_TIME_ASSERT_HEADER(e) extern int __acc_cta[1-!(e)];
|
||||
# elif (ACC_CC_DMC || ACC_CC_SYMANTECC)
|
||||
# define ACC_COMPILE_TIME_ASSERT_HEADER(e) extern int __acc_cta[1u-2*!(e)];
|
||||
# elif (ACC_CC_TURBOC && (__TURBOC__ == 0x0295))
|
||||
# define ACC_COMPILE_TIME_ASSERT_HEADER(e) extern int __acc_cta[1-!(e)];
|
||||
# else
|
||||
# define ACC_COMPILE_TIME_ASSERT_HEADER(e) extern int __acc_cta[1-2*!(e)];
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This must appear within a function body. */
|
||||
#if !defined(ACC_COMPILE_TIME_ASSERT)
|
||||
# if (ACC_CC_AZTECC)
|
||||
# define ACC_COMPILE_TIME_ASSERT(e) {typedef int __acc_cta_t[1-!(e)];}
|
||||
# elif (ACC_CC_DMC || ACC_CC_PACIFICC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
|
||||
# define ACC_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
|
||||
# elif (ACC_CC_MSC && (_MSC_VER < 900))
|
||||
# define ACC_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
|
||||
# elif (ACC_CC_TURBOC && (__TURBOC__ == 0x0295))
|
||||
# define ACC_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
|
||||
# else
|
||||
# define ACC_COMPILE_TIME_ASSERT(e) {typedef int __acc_cta_t[1-2*!(e)];}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// macros
|
||||
************************************************************************/
|
||||
|
||||
#if !defined(__ACC_UINT_MAX)
|
||||
# define __ACC_INT_MAX(b) ((((1l << ((b)-2)) - 1l) * 2l) + 1l)
|
||||
# define __ACC_UINT_MAX(b) ((((1ul << ((b)-1)) - 1ul) * 2ul) + 1ul)
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// get sizes of builtin integral types from <limits.h>
|
||||
************************************************************************/
|
||||
|
||||
#if !defined(__ACC_SHORT_BIT)
|
||||
# if (USHRT_MAX == ACC_0xffffL)
|
||||
# define __ACC_SHORT_BIT 16
|
||||
# elif (USHRT_MAX == ACC_0xffffffffL)
|
||||
# define __ACC_SHORT_BIT 32
|
||||
# elif (USHRT_MAX == __ACC_UINT_MAX(64))
|
||||
# define __ACC_SHORT_BIT 64
|
||||
# elif (USHRT_MAX == __ACC_UINT_MAX(128))
|
||||
# define __ACC_SHORT_BIT 128
|
||||
# else
|
||||
# error "check your compiler installation: USHRT_MAX"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(__ACC_INT_BIT)
|
||||
# if (UINT_MAX == ACC_0xffffL)
|
||||
# define __ACC_INT_BIT 16
|
||||
# elif (UINT_MAX == ACC_0xffffffffL)
|
||||
# define __ACC_INT_BIT 32
|
||||
# elif (UINT_MAX == __ACC_UINT_MAX(64))
|
||||
# define __ACC_INT_BIT 64
|
||||
# elif (UINT_MAX == __ACC_UINT_MAX(128))
|
||||
# define __ACC_INT_BIT 128
|
||||
# else
|
||||
# error "check your compiler installation: UINT_MAX"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(__ACC_LONG_BIT)
|
||||
# if (ULONG_MAX == ACC_0xffffffffL)
|
||||
# define __ACC_LONG_BIT 32
|
||||
# elif (ULONG_MAX == __ACC_UINT_MAX(64))
|
||||
# define __ACC_LONG_BIT 64
|
||||
# elif (ULONG_MAX == __ACC_UINT_MAX(128))
|
||||
# define __ACC_LONG_BIT 128
|
||||
# else
|
||||
# error "check your compiler installation: ULONG_MAX"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// acc_auto.h supplements
|
||||
************************************************************************/
|
||||
|
||||
#if (ACC_OS_CYGWIN || (ACC_OS_EMX && defined(__RSXNT__)) || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# if (ACC_CC_WATCOMC && (__WATCOMC__ < 1000))
|
||||
# elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
/* ancient pw32 version */
|
||||
# elif ((ACC_OS_CYGWIN || defined(__MINGW32__)) && (ACC_CC_GNUC && (ACC_CC_GNUC < 0x025f00ul)))
|
||||
/* ancient cygwin/mingw version */
|
||||
# else
|
||||
# define ACC_HAVE_WINDOWS_H 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,67 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ACC_INCD_H_INCLUDED
|
||||
#define __ACC_INCD_H_INCLUDED 1
|
||||
|
||||
/* default system includes */
|
||||
/* see Autoconf:
|
||||
* headers.m4, _AC_INCLUDES_DEFAULT_REQUIREMENTS ac_includes_default
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#if defined(HAVE_TIME_H) && defined(__MSL__) && defined(__cplusplus)
|
||||
# include <time.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#if HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <stddef.h>
|
||||
#else
|
||||
# if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
# endif
|
||||
#endif
|
||||
#if HAVE_STRING_H
|
||||
# if !STDC_HEADERS && HAVE_MEMORY_H
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# include <string.h>
|
||||
#endif
|
||||
#if HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#else
|
||||
# if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,87 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ACC_INCE_H_INCLUDED
|
||||
#define __ACC_INCE_H_INCLUDED 1
|
||||
|
||||
/* extra system includes */
|
||||
|
||||
#if defined(HAVE_STDARG_H)
|
||||
# include <stdarg.h>
|
||||
#endif
|
||||
#if defined(HAVE_CTYPE_H)
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
#if defined(HAVE_ERRNO_H)
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#if defined(HAVE_MALLOC_H)
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
#if defined(HAVE_ALLOCA_H)
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
#if defined(HAVE_FCNTL_H)
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
#if defined(HAVE_DIRENT_H)
|
||||
# include <dirent.h>
|
||||
#endif
|
||||
#if defined(HAVE_SETJMP_H)
|
||||
# include <setjmp.h>
|
||||
#endif
|
||||
#if defined(HAVE_SIGNAL_H)
|
||||
# include <signal.h>
|
||||
#endif
|
||||
#if defined(TIME_WITH_SYS_TIME)
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#elif defined(HAVE_TIME_H)
|
||||
# include <time.h>
|
||||
#endif
|
||||
#if defined(HAVE_UTIME_H)
|
||||
# include <utime.h>
|
||||
#elif defined(HAVE_SYS_UTIME_H)
|
||||
# include <sys/utime.h>
|
||||
#endif
|
||||
|
||||
/* DOS, OS/2 & Windows */
|
||||
#if defined(HAVE_IO_H)
|
||||
# include <io.h>
|
||||
#endif
|
||||
#if defined(HAVE_DOS_H)
|
||||
# include <dos.h>
|
||||
#endif
|
||||
#if defined(HAVE_DIRECT_H)
|
||||
# include <direct.h>
|
||||
#endif
|
||||
#if defined(HAVE_SHARE_H)
|
||||
# include <share.h>
|
||||
#endif
|
||||
#if defined(ACC_CC_NDPC)
|
||||
# include <os.h>
|
||||
#endif
|
||||
|
||||
/* TOS */
|
||||
#if defined(__TOS__) && (defined(__PUREC__) || defined(__TURBOC__))
|
||||
# include <ext.h>
|
||||
#endif
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,103 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ACC_INCI_H_INCLUDED
|
||||
#define __ACC_INCI_H_INCLUDED 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// internal system includes
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
|
||||
# include <tos.h>
|
||||
#elif (ACC_HAVE_WINDOWS_H)
|
||||
# if 1 && !defined(WIN32_LEAN_AND_MEAN)
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# endif
|
||||
# if 1 && !defined(_WIN32_WINNT)
|
||||
/* Restrict to a subset of Windows NT 4.0 header files */
|
||||
# define _WIN32_WINNT 0x0400
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# if (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
# include <dir.h>
|
||||
# endif
|
||||
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16)
|
||||
# if (ACC_CC_AZTECC)
|
||||
# include <model.h>
|
||||
# include <stat.h>
|
||||
# elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
# include <alloc.h>
|
||||
# include <dir.h>
|
||||
# elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
# include <sys/exceptn.h>
|
||||
# elif (ACC_CC_PACIFICC)
|
||||
# include <unixio.h>
|
||||
# include <stat.h>
|
||||
# include <sys.h>
|
||||
# elif (ACC_CC_WATCOMC)
|
||||
# include <i86.h>
|
||||
# endif
|
||||
#elif (ACC_OS_OS216)
|
||||
# if (ACC_CC_WATCOMC)
|
||||
# include <i86.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
|
||||
# if defined(FP_OFF)
|
||||
# define ACC_FP_OFF(x) FP_OFF(x)
|
||||
# elif defined(_FP_OFF)
|
||||
# define ACC_FP_OFF(x) _FP_OFF(x)
|
||||
# else
|
||||
# define ACC_FP_OFF(x) (((const unsigned __far*)&(x))[0])
|
||||
# endif
|
||||
# if defined(FP_SEG)
|
||||
# define ACC_FP_SEG(x) FP_SEG(x)
|
||||
# elif defined(_FP_SEG)
|
||||
# define ACC_FP_SEG(x) _FP_SEG(x)
|
||||
# else
|
||||
# define ACC_FP_SEG(x) (((const unsigned __far*)&(x))[1])
|
||||
# endif
|
||||
# if defined(MK_FP)
|
||||
# define ACC_MK_FP(s,o) MK_FP(s,o)
|
||||
# elif defined(_MK_FP)
|
||||
# define ACC_MK_FP(s,o) _MK_FP(s,o)
|
||||
# else
|
||||
# define ACC_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
|
||||
# endif
|
||||
# if 0
|
||||
# undef ACC_FP_OFF
|
||||
# undef ACC_FP_SEG
|
||||
# undef ACC_MK_FP
|
||||
# define ACC_FP_OFF(x) (((const unsigned __far*)&(x))[0])
|
||||
# define ACC_FP_SEG(x) (((const unsigned __far*)&(x))[1])
|
||||
# define ACC_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,237 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// preprocessor
|
||||
************************************************************************/
|
||||
|
||||
/* workaround for preprocessor bugs in some compilers */
|
||||
#if 0
|
||||
#define ACC_0xffffL 0xfffful
|
||||
#define ACC_0xffffffffL 0xfffffffful
|
||||
#else
|
||||
#define ACC_0xffffL 65535ul
|
||||
#define ACC_0xffffffffL 4294967295ul
|
||||
#endif
|
||||
|
||||
/* some things we cannot work around */
|
||||
#if (ACC_0xffffL == ACC_0xffffffffL)
|
||||
# error "your preprocessor is broken 1"
|
||||
#endif
|
||||
#if (16ul * 16384ul != 262144ul)
|
||||
# error "your preprocessor is broken 2"
|
||||
#endif
|
||||
#if 0
|
||||
#if (32767 >= 4294967295ul)
|
||||
# error "your preprocessor is broken 3"
|
||||
#endif
|
||||
#if (65535u >= 4294967295ul)
|
||||
# error "your preprocessor is broken 4"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// try to detect specific compilers
|
||||
************************************************************************/
|
||||
|
||||
#if (UINT_MAX == ACC_0xffffL)
|
||||
#if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__)
|
||||
# if !defined(MSDOS)
|
||||
# define MSDOS 1
|
||||
# endif
|
||||
# if !defined(_MSDOS)
|
||||
# define _MSDOS 1
|
||||
# endif
|
||||
#elif defined(__VERSION) && defined(MB_LEN_MAX)
|
||||
# if (__VERSION == 520) && (MB_LEN_MAX == 1)
|
||||
# if !defined(__AZTEC_C__)
|
||||
# define __AZTEC_C__ __VERSION
|
||||
# endif
|
||||
# if !defined(__DOS__)
|
||||
# define __DOS__ 1
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// fix incorrect and missing stuff
|
||||
************************************************************************/
|
||||
|
||||
/* Microsoft C does not correctly define ptrdiff_t for
|
||||
* the 16-bit huge memory model.
|
||||
*/
|
||||
#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == ACC_0xffffL)
|
||||
# define ptrdiff_t long
|
||||
# define _PTRDIFF_T_DEFINED
|
||||
#endif
|
||||
|
||||
|
||||
/* Fix old compiler versions. */
|
||||
#if (UINT_MAX == ACC_0xffffL)
|
||||
# undef __ACC_RENAME_A
|
||||
# undef __ACC_RENAME_B
|
||||
# if defined(__AZTEC_C__) && defined(__DOS__)
|
||||
# define __ACC_RENAME_A 1
|
||||
# elif defined(_MSC_VER) && defined(MSDOS)
|
||||
# if (_MSC_VER < 600)
|
||||
# define __ACC_RENAME_A 1
|
||||
# elif (_MSC_VER < 700)
|
||||
# define __ACC_RENAME_B 1
|
||||
# endif
|
||||
# elif defined(__TSC__) && defined(__OS2__)
|
||||
# define __ACC_RENAME_A 1
|
||||
# elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410)
|
||||
# define __ACC_RENAME_A 1
|
||||
# elif defined(__PACIFIC__) && defined(DOS)
|
||||
# if !defined(__far)
|
||||
# define __far far
|
||||
# endif
|
||||
# if !defined(__near)
|
||||
# define __near near
|
||||
# endif
|
||||
# endif
|
||||
# if defined(__ACC_RENAME_A)
|
||||
# if !defined(__cdecl)
|
||||
# define __cdecl cdecl
|
||||
# endif
|
||||
# if !defined(__far)
|
||||
# define __far far
|
||||
# endif
|
||||
# if !defined(__huge)
|
||||
# define __huge huge
|
||||
# endif
|
||||
# if !defined(__near)
|
||||
# define __near near
|
||||
# endif
|
||||
# if !defined(__pascal)
|
||||
# define __pascal pascal
|
||||
# endif
|
||||
# if !defined(__huge)
|
||||
# define __huge huge
|
||||
# endif
|
||||
# elif defined(__ACC_RENAME_B)
|
||||
# if !defined(__cdecl)
|
||||
# define __cdecl _cdecl
|
||||
# endif
|
||||
# if !defined(__far)
|
||||
# define __far _far
|
||||
# endif
|
||||
# if !defined(__huge)
|
||||
# define __huge _huge
|
||||
# endif
|
||||
# if !defined(__near)
|
||||
# define __near _near
|
||||
# endif
|
||||
# if !defined(__pascal)
|
||||
# define __pascal _pascal
|
||||
# endif
|
||||
# elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
|
||||
# if !defined(__cdecl)
|
||||
# define __cdecl cdecl
|
||||
# endif
|
||||
# if !defined(__pascal)
|
||||
# define __pascal pascal
|
||||
# endif
|
||||
# endif
|
||||
# undef __ACC_RENAME_A
|
||||
# undef __ACC_RENAME_B
|
||||
#endif
|
||||
|
||||
|
||||
#if (UINT_MAX == ACC_0xffffL)
|
||||
#if defined(__AZTEC_C__) && defined(__DOS__)
|
||||
# define ACC_BROKEN_CDECL_ALT_SYNTAX 1
|
||||
#elif defined(_MSC_VER) && defined(MSDOS)
|
||||
# if (_MSC_VER < 600)
|
||||
# define ACC_BROKEN_INTEGRAL_CONSTANTS 1
|
||||
# endif
|
||||
# if (_MSC_VER < 700)
|
||||
# define ACC_BROKEN_INTEGRAL_PROMOTION 1
|
||||
# define ACC_BROKEN_SIZEOF 1
|
||||
# endif
|
||||
#elif defined(__PACIFIC__) && defined(DOS)
|
||||
# define ACC_BROKEN_INTEGRAL_CONSTANTS 1
|
||||
#elif defined(__TURBOC__) && defined(__MSDOS__)
|
||||
# if (__TURBOC__ < 0x0150)
|
||||
# define ACC_BROKEN_CDECL_ALT_SYNTAX 1
|
||||
# define ACC_BROKEN_INTEGRAL_CONSTANTS 1
|
||||
# define ACC_BROKEN_INTEGRAL_PROMOTION 1
|
||||
# endif
|
||||
# if (__TURBOC__ < 0x0200)
|
||||
# define ACC_BROKEN_SIZEOF 1
|
||||
# endif
|
||||
# if (__TURBOC__ < 0x0400) && defined(__cplusplus)
|
||||
# define ACC_BROKEN_CDECL_ALT_SYNTAX 1
|
||||
# endif
|
||||
#elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
|
||||
# define ACC_BROKEN_CDECL_ALT_SYNTAX 1
|
||||
# define ACC_BROKEN_SIZEOF 1
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__WATCOMC__) && (__WATCOMC__ < 900)
|
||||
# define ACC_BROKEN_INTEGRAL_CONSTANTS 1
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// ANSI C preprocessor macros (cpp)
|
||||
************************************************************************/
|
||||
|
||||
#define ACC_CPP_STRINGIZE(x) #x
|
||||
#define ACC_CPP_MACRO_EXPAND(x) ACC_CPP_STRINGIZE(x)
|
||||
|
||||
/* concatenate */
|
||||
#define ACC_CPP_CONCAT2(a,b) a ## b
|
||||
#define ACC_CPP_CONCAT3(a,b,c) a ## b ## c
|
||||
#define ACC_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d
|
||||
#define ACC_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
|
||||
|
||||
/* expand and concatenate (by using one level of indirection) */
|
||||
#define ACC_CPP_ECONCAT2(a,b) ACC_CPP_CONCAT2(a,b)
|
||||
#define ACC_CPP_ECONCAT3(a,b,c) ACC_CPP_CONCAT3(a,b,c)
|
||||
#define ACC_CPP_ECONCAT4(a,b,c,d) ACC_CPP_CONCAT4(a,b,c,d)
|
||||
#define ACC_CPP_ECONCAT5(a,b,c,d,e) ACC_CPP_CONCAT5(a,b,c,d,e)
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// stdc macros
|
||||
************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# undef __STDC_CONSTANT_MACROS
|
||||
# undef __STDC_LIMIT_MACROS
|
||||
# define __STDC_CONSTANT_MACROS 1
|
||||
# define __STDC_LIMIT_MACROS 1
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// misc macros
|
||||
************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# define ACC_EXTERN_C extern "C"
|
||||
#else
|
||||
# define ACC_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,61 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if !defined(ACC_VERSION)
|
||||
# if defined ACC_CONFIG_INCLUDE
|
||||
# include ACC_CONFIG_INCLUDE("acc.h")
|
||||
# else
|
||||
# include "acc.h"
|
||||
# endif
|
||||
#endif
|
||||
#ifndef __ACC_INCD_H_INCLUDED
|
||||
# include ACC_CONFIG_INCLUDE("acc_incd.h")
|
||||
#endif
|
||||
#ifndef __ACC_INCE_H_INCLUDED
|
||||
# include ACC_CONFIG_INCLUDE("acc_ince.h")
|
||||
#endif
|
||||
#ifndef __ACC_INCI_H_INCLUDED
|
||||
# include ACC_CONFIG_INCLUDE("acc_inci.h")
|
||||
#endif
|
||||
#ifndef __ACC_LIB_H_INCLUDED
|
||||
# include ACC_CONFIG_INCLUDE("acc_lib.h")
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
#include ACC_CONFIG_INCLUDE("acclib/bele.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/hmemcpy.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/hstring.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/halloc.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/dosalloc.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/hfread.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/hread.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/opendir.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/rand.ch")
|
||||
#include ACC_CONFIG_INCLUDE("acclib/misc.ch")
|
||||
|
||||
#if 0
|
||||
/* modules which use floating point are not included by default */
|
||||
#include ACC_CONFIG_INCLUDE("acclib/uclock.ch")
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,526 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ACC_LIB_H_INCLUDED
|
||||
#define __ACC_LIB_H_INCLUDED 1
|
||||
|
||||
|
||||
#if !defined(__ACCLIB_FUNCNAME)
|
||||
# define __ACCLIB_FUNCNAME(f) f
|
||||
#endif
|
||||
#if !defined(ACCLIB_EXTERN)
|
||||
# define ACCLIB_EXTERN(r,f) extern r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(__ACCLIB_CONST_CAST_RETURN)
|
||||
#if (ACC_CC_GNUC)
|
||||
# define __ACCLIB_CONST_CAST_RETURN(type,var) \
|
||||
{ union { type a; const type b; } u; u.b = (var); return u.a; }
|
||||
#else
|
||||
# define __ACCLIB_CONST_CAST_RETURN(type,var) return (type) (var);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_WIN64)
|
||||
# define acclib_handle_t acc_int64l_t
|
||||
# define acclib_uhandle_t acc_uint64l_t
|
||||
#elif (ACC_ARCH_IA32 && ACC_CC_MSC && (_MSC_VER >= 1300))
|
||||
typedef __w64 long acclib_handle_t;
|
||||
typedef __w64 unsigned long acclib_uhandle_t;
|
||||
# define acclib_handle_t acclib_handle_t
|
||||
# define acclib_uhandle_t acclib_uhandle_t
|
||||
#else
|
||||
# define acclib_handle_t long
|
||||
# define acclib_uhandle_t unsigned long
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// wrap <ctype.h>
|
||||
**************************************************************************/
|
||||
|
||||
#if 0
|
||||
ACCLIB_EXTERN(int, acc_ascii_digit) (int);
|
||||
ACCLIB_EXTERN(int, acc_ascii_islower) (int);
|
||||
ACCLIB_EXTERN(int, acc_ascii_isupper) (int);
|
||||
ACCLIB_EXTERN(int, acc_ascii_tolower) (int);
|
||||
ACCLIB_EXTERN(int, acc_ascii_toupper) (int);
|
||||
ACCLIB_EXTERN(int, acc_ascii_utolower) (int);
|
||||
ACCLIB_EXTERN(int, acc_ascii_utoupper) (int);
|
||||
#endif
|
||||
|
||||
#define acc_ascii_isdigit(c) (((unsigned)(c) - 48) < 10)
|
||||
#define acc_ascii_islower(c) (((unsigned)(c) - 97) < 26)
|
||||
#define acc_ascii_isupper(c) (((unsigned)(c) - 65) < 26)
|
||||
#define acc_ascii_tolower(c) ((int)(c) + (acc_ascii_isupper(c) << 5))
|
||||
#define acc_ascii_toupper(c) ((int)(c) - (acc_ascii_islower(c) << 5))
|
||||
|
||||
#define acc_ascii_utolower(c) acc_ascii_tolower((unsigned char)(c))
|
||||
#define acc_ascii_utoupper(c) acc_ascii_toupper((unsigned char)(c))
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// huge pointer layer
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef acc_hsize_t
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
# define acc_hsize_t unsigned long
|
||||
# define acc_hvoid_p void __huge *
|
||||
# define acc_hchar_p char __huge *
|
||||
# define acc_hchar_pp char __huge * __huge *
|
||||
# define acc_hbyte_p unsigned char __huge *
|
||||
#else
|
||||
# define acc_hsize_t size_t
|
||||
# define acc_hvoid_p void *
|
||||
# define acc_hchar_p char *
|
||||
# define acc_hchar_pp char **
|
||||
# define acc_hbyte_p unsigned char *
|
||||
#endif
|
||||
#endif
|
||||
#ifndef ACC_FILE_P
|
||||
#define ACC_FILE_P FILE *
|
||||
#endif
|
||||
|
||||
/* halloc */
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_halloc) (acc_hsize_t);
|
||||
ACCLIB_EXTERN(void, acc_hfree) (acc_hvoid_p);
|
||||
|
||||
/* dos_alloc */
|
||||
#if (ACC_OS_DOS16 || ACC_OS_OS216)
|
||||
ACCLIB_EXTERN(void __far*, acc_dos_alloc) (unsigned long);
|
||||
ACCLIB_EXTERN(int, acc_dos_free) (void __far*);
|
||||
#endif
|
||||
|
||||
/* string */
|
||||
ACCLIB_EXTERN(int, acc_hmemcmp) (const acc_hvoid_p, const acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_hmemcpy) (acc_hvoid_p, const acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_hmemmove) (acc_hvoid_p, const acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_hmemset) (acc_hvoid_p, int, acc_hsize_t);
|
||||
|
||||
/* string */
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hstrlen) (const acc_hchar_p);
|
||||
ACCLIB_EXTERN(int, acc_hstrcmp) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(int, acc_hstrncmp)(const acc_hchar_p, const acc_hchar_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(int, acc_ascii_hstricmp) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(int, acc_ascii_hstrnicmp)(const acc_hchar_p, const acc_hchar_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(int, acc_ascii_hmemicmp) (const acc_hvoid_p, const acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrstr) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_ascii_hstristr) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_hmemmem) (const acc_hvoid_p, acc_hsize_t, const acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_ascii_hmemimem) (const acc_hvoid_p, acc_hsize_t, const acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrcpy) (acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrcat) (acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hstrlcpy) (acc_hchar_p, const acc_hchar_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hstrlcat) (acc_hchar_p, const acc_hchar_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(int, acc_hstrscpy) (acc_hchar_p, const acc_hchar_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(int, acc_hstrscat) (acc_hchar_p, const acc_hchar_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrccpy) (acc_hchar_p, const acc_hchar_p, int);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_hmemccpy) (acc_hvoid_p, const acc_hvoid_p, int, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrchr) (const acc_hchar_p, int);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrrchr) (const acc_hchar_p, int);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_ascii_hstrichr) (const acc_hchar_p, int);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_ascii_hstrrichr) (const acc_hchar_p, int);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_hmemchr) (const acc_hvoid_p, int, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_hmemrchr) (const acc_hvoid_p, int, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_ascii_hmemichr) (const acc_hvoid_p, int, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_ascii_hmemrichr) (const acc_hvoid_p, int, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hstrspn) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hstrrspn) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hstrcspn) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hstrrcspn) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrpbrk) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrrpbrk) (const acc_hchar_p, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrsep) (acc_hchar_pp, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_hstrrsep) (acc_hchar_pp, const acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_ascii_hstrlwr) (acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hchar_p, acc_ascii_hstrupr) (acc_hchar_p);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_ascii_hmemlwr) (acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hvoid_p, acc_ascii_hmemupr) (acc_hvoid_p, acc_hsize_t);
|
||||
|
||||
/* stdio */
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hfread) (ACC_FILE_P, acc_hvoid_p, acc_hsize_t);
|
||||
ACCLIB_EXTERN(acc_hsize_t, acc_hfwrite) (ACC_FILE_P, const acc_hvoid_p, acc_hsize_t);
|
||||
|
||||
/* io */
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
ACCLIB_EXTERN(long, acc_hread) (int, acc_hvoid_p, long);
|
||||
ACCLIB_EXTERN(long, acc_hwrite) (int, const acc_hvoid_p, long);
|
||||
#endif
|
||||
ACCLIB_EXTERN(long, acc_safe_hread) (int, acc_hvoid_p, long);
|
||||
ACCLIB_EXTERN(long, acc_safe_hwrite) (int, const acc_hvoid_p, long);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// wrap filename limits
|
||||
**************************************************************************/
|
||||
|
||||
/* maximum length of full pathname (excl. '\0') */
|
||||
#if !defined(ACC_FN_PATH_MAX)
|
||||
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
|
||||
# define ACC_FN_PATH_MAX 143
|
||||
#elif (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# define ACC_FN_PATH_MAX 259
|
||||
#elif (ACC_OS_TOS)
|
||||
# define ACC_FN_PATH_MAX 259
|
||||
#endif
|
||||
#endif
|
||||
#if !defined(ACC_FN_PATH_MAX)
|
||||
/* arbitrary limit for acclib implementation */
|
||||
# define ACC_FN_PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
/* maximum length of a filename (a single path component) (excl. '\0') */
|
||||
#if !defined(ACC_FN_NAME_MAX)
|
||||
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
|
||||
# define ACC_FN_NAME_MAX 12
|
||||
#elif (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
|
||||
# define ACC_FN_NAME_MAX 12
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
#elif (ACC_OS_DOS32)
|
||||
# define ACC_FN_NAME_MAX 12
|
||||
#endif
|
||||
#endif
|
||||
#if !defined(ACC_FN_NAME_MAX)
|
||||
# define ACC_FN_NAME_MAX ACC_FN_PATH_MAX
|
||||
#endif
|
||||
|
||||
|
||||
#define ACC_FNMATCH_NOESCAPE 1
|
||||
#define ACC_FNMATCH_PATHNAME 2
|
||||
#define ACC_FNMATCH_PATHSTAR 4
|
||||
#define ACC_FNMATCH_PERIOD 8
|
||||
#define ACC_FNMATCH_ASCII_CASEFOLD 16
|
||||
ACCLIB_EXTERN(int, acc_fnmatch) (const acc_hchar_p, const acc_hchar_p, int);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// wrap <dirent.h>
|
||||
**************************************************************************/
|
||||
|
||||
#undef __ACCLIB_USE_OPENDIR
|
||||
#if (HAVE_DIRENT_H || ACC_CC_WATCOMC)
|
||||
# define __ACCLIB_USE_OPENDIR 1
|
||||
# if (ACC_OS_DOS32 && defined(__BORLANDC__))
|
||||
# elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
# elif (ACC_OS_OS2 || ACC_OS_OS216)
|
||||
# elif (ACC_OS_TOS && ACC_CC_GNUC)
|
||||
# elif (ACC_OS_WIN32 && !defined(ACC_HAVE_WINDOWS_H))
|
||||
# elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# undef __ACCLIB_USE_OPENDIR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#if defined(__ACCLIB_USE_OPENDIR)
|
||||
void *u_dirp; /* private */
|
||||
# if (ACC_CC_WATCOMC)
|
||||
unsigned short f_time;
|
||||
unsigned short f_date;
|
||||
unsigned long f_size;
|
||||
# endif
|
||||
char f_name[ACC_FN_NAME_MAX+1];
|
||||
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
acclib_handle_t u_handle; /* private */
|
||||
unsigned f_attr;
|
||||
unsigned f_size_low;
|
||||
unsigned f_size_high;
|
||||
char f_name[ACC_FN_NAME_MAX+1];
|
||||
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_TOS || ACC_OS_WIN16)
|
||||
char u_dta[21]; /* private */
|
||||
unsigned char f_attr;
|
||||
unsigned short f_time;
|
||||
unsigned short f_date;
|
||||
unsigned short f_size_low;
|
||||
unsigned short f_size_high;
|
||||
char f_name[ACC_FN_NAME_MAX+1];
|
||||
char u_dirp; /* private */
|
||||
#else
|
||||
void *u_dirp; /* private */
|
||||
char f_name[ACC_FN_NAME_MAX+1];
|
||||
#endif
|
||||
} acc_dir_t;
|
||||
|
||||
#ifndef acc_dir_p
|
||||
#define acc_dir_p acc_dir_t *
|
||||
#endif
|
||||
|
||||
ACCLIB_EXTERN(int, acc_opendir) (acc_dir_p, const char*);
|
||||
ACCLIB_EXTERN(int, acc_readdir) (acc_dir_p);
|
||||
ACCLIB_EXTERN(int, acc_closedir) (acc_dir_p);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// wrap misc
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_CC_GNUC) && (defined(__CYGWIN__) || defined(__MINGW32__))
|
||||
# define acc_alloca(x) __builtin_alloca((x))
|
||||
#elif (ACC_CC_BORLANDC) && defined(__linux__)
|
||||
/* FIXME: alloca does not work */
|
||||
#elif (HAVE_ALLOCA)
|
||||
# define acc_alloca(x) alloca((x))
|
||||
#endif
|
||||
|
||||
#if (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
# define acc_stackavail() stackavail()
|
||||
#elif (ACC_ARCH_IA16 && ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0410))
|
||||
# define acc_stackavail() stackavail()
|
||||
#elif (ACC_ARCH_IA16 && ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0400))
|
||||
# if (ACC_OS_WIN16) && (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
# else
|
||||
# define acc_stackavail() stackavail()
|
||||
# endif
|
||||
#elif ((ACC_ARCH_IA16 || ACC_ARCH_IA32) && (ACC_CC_DMC || ACC_CC_SYMANTECC))
|
||||
# define acc_stackavail() stackavail()
|
||||
#elif ((ACC_ARCH_IA16) && ACC_CC_MSC && (_MSC_VER >= 700))
|
||||
# define acc_stackavail() _stackavail()
|
||||
#elif ((ACC_ARCH_IA16) && ACC_CC_MSC)
|
||||
# define acc_stackavail() stackavail()
|
||||
#elif ((ACC_ARCH_IA16 || ACC_ARCH_IA32) && ACC_CC_TURBOC && (__TURBOC__ >= 0x0450))
|
||||
# define acc_stackavail() stackavail()
|
||||
#elif (ACC_ARCH_IA16 && ACC_CC_TURBOC && (__TURBOC__ >= 0x0400))
|
||||
ACC_EXTERN_C size_t __cdecl stackavail(void);
|
||||
# define acc_stackavail() stackavail()
|
||||
#elif ((ACC_ARCH_IA16 || ACC_ARCH_IA32) && (ACC_CC_WATCOMC))
|
||||
# define acc_stackavail() stackavail()
|
||||
#elif (ACC_ARCH_IA16 && ACC_CC_ZORTECHC)
|
||||
# define acc_stackavail() _chkstack()
|
||||
#endif
|
||||
|
||||
ACCLIB_EXTERN(acclib_handle_t, acc_get_osfhandle) (int);
|
||||
ACCLIB_EXTERN(int, acc_isatty) (int);
|
||||
ACCLIB_EXTERN(int, acc_mkdir) (const char*, unsigned);
|
||||
ACCLIB_EXTERN(int, acc_response) (int*, char***);
|
||||
ACCLIB_EXTERN(int, acc_set_binmode) (int, int);
|
||||
|
||||
ACCLIB_EXTERN(acc_int32l_t, acc_muldiv32) (acc_int32l_t, acc_int32l_t, acc_int32l_t);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_umuldiv32) (acc_uint32l_t, acc_uint32l_t, acc_uint32l_t);
|
||||
|
||||
ACCLIB_EXTERN(void, acc_wildargv) (int*, char***);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// uclock (real, i.e. "wall" clock)
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(acc_int32e_t)
|
||||
ACCLIB_EXTERN(int, acc_tsc_read) (acc_uint32e_t*);
|
||||
ACCLIB_EXTERN(int, acc_tsc_read_add) (acc_uint32e_t*);
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct { /* all private */
|
||||
acclib_handle_t h;
|
||||
int mode;
|
||||
#if (ACC_HAVE_WINDOWS_H) && defined(acc_int64l_t)
|
||||
double qpf;
|
||||
#endif
|
||||
} acc_uclock_handle_t;
|
||||
|
||||
typedef struct { /* all private */
|
||||
union {
|
||||
acc_uint32l_t t32;
|
||||
#if !(ACC_OS_DOS16 || ACC_OS_WIN16)
|
||||
double td;
|
||||
# if defined(acc_int64l_t)
|
||||
acc_int64l_t t64;
|
||||
# endif
|
||||
#endif
|
||||
} ticks;
|
||||
#if (ACC_HAVE_WINDOWS_H) && defined(acc_int64l_t)
|
||||
acc_int64l_t qpc;
|
||||
#endif
|
||||
} acc_uclock_t;
|
||||
|
||||
#ifndef acc_uclock_handle_p
|
||||
#define acc_uclock_handle_p acc_uclock_handle_t *
|
||||
#endif
|
||||
#ifndef acc_uclock_p
|
||||
#define acc_uclock_p acc_uclock_t *
|
||||
#endif
|
||||
|
||||
ACCLIB_EXTERN(int, acc_uclock_open) (acc_uclock_handle_p);
|
||||
ACCLIB_EXTERN(int, acc_uclock_close) (acc_uclock_handle_p);
|
||||
ACCLIB_EXTERN(void, acc_uclock_read) (acc_uclock_handle_p, acc_uclock_p);
|
||||
ACCLIB_EXTERN(double, acc_uclock_get_elapsed) (acc_uclock_handle_p, const acc_uclock_p, const acc_uclock_p);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// performance counters (virtual clock)
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(acc_int64l_t)
|
||||
|
||||
typedef struct { /* all private */
|
||||
void* h;
|
||||
unsigned cpu_type, cpu_features, cpu_khz, cpu_nrctrs;
|
||||
const char* cpu_name;
|
||||
} acc_perfctr_handle_t;
|
||||
|
||||
typedef struct {
|
||||
acc_uint64l_t tsc;
|
||||
#if (ACC_OS_POSIX_LINUX)
|
||||
acc_uint64l_t pmc[18];
|
||||
#else
|
||||
acc_uint64l_t pmc[1];
|
||||
#endif
|
||||
} acc_perfctr_clock_t;
|
||||
|
||||
#ifndef acc_perfctr_handle_p
|
||||
#define acc_perfctr_handle_p acc_perfctr_handle_t *
|
||||
#endif
|
||||
#ifndef acc_perfctr_clock_p
|
||||
#define acc_perfctr_clock_p acc_perfctr_clock_t *
|
||||
#endif
|
||||
|
||||
ACCLIB_EXTERN(int, acc_perfctr_open) (acc_perfctr_handle_p);
|
||||
ACCLIB_EXTERN(int, acc_perfctr_close) (acc_perfctr_handle_p);
|
||||
ACCLIB_EXTERN(void, acc_perfctr_read) (acc_perfctr_handle_p, acc_perfctr_clock_p);
|
||||
ACCLIB_EXTERN(double, acc_perfctr_get_elapsed) (acc_perfctr_handle_p, const acc_perfctr_clock_p, const acc_perfctr_clock_p);
|
||||
ACCLIB_EXTERN(double, acc_perfctr_get_elapsed_tsc) (acc_perfctr_handle_p, acc_uint64l_t);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Big Endian / Little Endian
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_EXTERN(unsigned, acc_get_be16) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_get_be24) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_get_be32) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(void, acc_set_be16) (acc_hvoid_p, unsigned);
|
||||
ACCLIB_EXTERN(void, acc_set_be24) (acc_hvoid_p, acc_uint32l_t);
|
||||
ACCLIB_EXTERN(void, acc_set_be32) (acc_hvoid_p, acc_uint32l_t);
|
||||
ACCLIB_EXTERN(unsigned, acc_get_le16) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_get_le24) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_get_le32) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(void, acc_set_le16) (acc_hvoid_p, unsigned);
|
||||
ACCLIB_EXTERN(void, acc_set_le24) (acc_hvoid_p, acc_uint32l_t);
|
||||
ACCLIB_EXTERN(void, acc_set_le32) (acc_hvoid_p, acc_uint32l_t);
|
||||
#if defined(acc_uint64l_t)
|
||||
ACCLIB_EXTERN(acc_uint64l_t, acc_get_be64) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(void, acc_set_be64) (acc_hvoid_p, acc_uint64l_t);
|
||||
ACCLIB_EXTERN(acc_uint64l_t, acc_get_le64) (const acc_hvoid_p);
|
||||
ACCLIB_EXTERN(void, acc_set_le64) (acc_hvoid_p, acc_uint64l_t);
|
||||
#endif
|
||||
|
||||
/* inline versions */
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
# define ACC_GET_LE16(p) (* (const unsigned short *) (p))
|
||||
# define ACC_GET_LE32(p) (* (const acc_uint32e_t *) (p))
|
||||
# define ACC_SET_LE16(p,v) (* (unsigned short *) (p) = (unsigned short) (v))
|
||||
# define ACC_SET_LE32(p,v) (* (acc_uint32e_t *) (p) = (acc_uint32e_t) (v))
|
||||
#endif
|
||||
#if (ACC_ARCH_AMD64)
|
||||
# define ACC_GET_LE64(p) (* (const acc_uint64l_t *) (p))
|
||||
# define ACC_SET_LE64(p,v) (* (acc_uint64l_t *) (p) = (acc_uint64l_t) (v))
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// getopt
|
||||
**************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
int has_arg;
|
||||
int* flag;
|
||||
int val;
|
||||
} acc_getopt_longopt_t;
|
||||
#ifndef acc_getopt_longopt_p
|
||||
#define acc_getopt_longopt_p acc_getopt_longopt_t *
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int go_argc;
|
||||
char** go_argv;
|
||||
const char* go_shortopts;
|
||||
const acc_getopt_longopt_p longopts;
|
||||
#if (ACC_BROKEN_CDECL_ALT_SYNTAX)
|
||||
int __acc_cdecl_va (*go_error)(const char *, ...);
|
||||
#else
|
||||
int (__acc_cdecl_va *go_error)(const char *, ...);
|
||||
#endif
|
||||
} acc_getopt_t;
|
||||
#ifndef acc_getopt_p
|
||||
#define acc_getopt_p acc_getopt_t *
|
||||
#endif
|
||||
|
||||
ACCLIB_EXTERN(void, acc_getopt_init) (acc_getopt_p);
|
||||
ACCLIB_EXTERN(int, acc_getopt) (acc_getopt_p);
|
||||
ACCLIB_EXTERN(void, acc_getopt_close)(acc_getopt_p);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// rand
|
||||
**************************************************************************/
|
||||
|
||||
typedef struct { /* all private */
|
||||
acc_uint32l_t seed;
|
||||
} acc_rand31_t;
|
||||
#ifndef acc_rand31_p
|
||||
#define acc_rand31_p acc_rand31_t *
|
||||
#endif
|
||||
ACCLIB_EXTERN(void, acc_srand31) (acc_rand31_p, acc_uint32l_t);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_rand31) (acc_rand31_p);
|
||||
|
||||
#if defined(acc_uint64l_t)
|
||||
typedef struct { /* all private */
|
||||
acc_uint64l_t seed;
|
||||
} acc_rand48_t;
|
||||
#ifndef acc_rand48_p
|
||||
#define acc_rand48_p acc_rand48_t *
|
||||
#endif
|
||||
ACCLIB_EXTERN(void, acc_srand48) (acc_rand48_p, acc_uint32l_t);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_rand48) (acc_rand48_p);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_rand48_r32) (acc_rand48_p);
|
||||
#endif
|
||||
|
||||
#if defined(acc_uint64l_t)
|
||||
typedef struct { /* all private */
|
||||
acc_uint64l_t seed;
|
||||
} acc_rand64_t;
|
||||
#ifndef acc_rand64_p
|
||||
#define acc_rand64_p acc_rand64_t *
|
||||
#endif
|
||||
ACCLIB_EXTERN(void, acc_srand64) (acc_rand64_p, acc_uint64l_t);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_rand64) (acc_rand64_p);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_rand64_r32) (acc_rand64_p);
|
||||
#endif
|
||||
|
||||
typedef struct { /* all private */
|
||||
unsigned n;
|
||||
acc_uint32l_t s[624];
|
||||
} acc_randmt_t;
|
||||
#ifndef acc_randmt_p
|
||||
#define acc_randmt_p acc_randmt_t *
|
||||
#endif
|
||||
ACCLIB_EXTERN(void, acc_srandmt) (acc_randmt_p, acc_uint32l_t);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_randmt) (acc_randmt_p);
|
||||
ACCLIB_EXTERN(acc_uint32l_t, acc_randmt_r32) (acc_randmt_p);
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,199 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Memory Model - exactly one of:
|
||||
*
|
||||
* ACC_MM_FLAT [default]
|
||||
* ACC_MM_TINY
|
||||
* ACC_MM_SMALL
|
||||
* ACC_MM_MEDIUM
|
||||
* ACC_MM_COMPACT
|
||||
* ACC_MM_LARGE
|
||||
* ACC_MM_HUGE
|
||||
*/
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
|
||||
|
||||
#if (UINT_MAX != ACC_0xffffL)
|
||||
# error "this should not happen"
|
||||
#endif
|
||||
#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM)
|
||||
# define ACC_MM_TINY 1
|
||||
#elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM)
|
||||
# define ACC_MM_HUGE 1
|
||||
#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL)
|
||||
# define ACC_MM_SMALL 1
|
||||
#elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM)
|
||||
# define ACC_MM_MEDIUM 1
|
||||
#elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM)
|
||||
# define ACC_MM_COMPACT 1
|
||||
#elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL)
|
||||
# define ACC_MM_LARGE 1
|
||||
#elif (ACC_CC_AZTECC)
|
||||
# if defined(_LARGE_CODE) && defined(_LARGE_DATA)
|
||||
# define ACC_MM_LARGE 1
|
||||
# elif defined(_LARGE_CODE)
|
||||
# define ACC_MM_MEDIUM 1
|
||||
# elif defined(_LARGE_DATA)
|
||||
# define ACC_MM_COMPACT 1
|
||||
# else
|
||||
# define ACC_MM_SMALL 1
|
||||
# endif
|
||||
#elif (ACC_CC_ZORTECHC && defined(__VCM__))
|
||||
# define ACC_MM_LARGE 1
|
||||
#else
|
||||
# error "unknown memory model"
|
||||
#endif
|
||||
|
||||
|
||||
/* ACC_HAVE_MM_HUGE_PTR ... working __huge pointers
|
||||
* ACC_HAVE_MM_HUGE_ARRAY ... char __huge x[256*1024L] works */
|
||||
#define ACC_HAVE_MM_HUGE_PTR 1
|
||||
#define ACC_HAVE_MM_HUGE_ARRAY 1
|
||||
|
||||
#if (ACC_MM_TINY)
|
||||
# undef ACC_HAVE_MM_HUGE_ARRAY
|
||||
#endif
|
||||
|
||||
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC || ACC_CC_ZORTECHC)
|
||||
# undef ACC_HAVE_MM_HUGE_PTR
|
||||
# undef ACC_HAVE_MM_HUGE_ARRAY
|
||||
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC)
|
||||
# undef ACC_HAVE_MM_HUGE_ARRAY
|
||||
#elif (ACC_CC_MSC && defined(_QC))
|
||||
# undef ACC_HAVE_MM_HUGE_ARRAY
|
||||
# if (_MSC_VER < 600)
|
||||
# undef ACC_HAVE_MM_HUGE_PTR
|
||||
# endif
|
||||
#elif (ACC_CC_TURBOC && (__TURBOC__ < 0x0295))
|
||||
# undef ACC_HAVE_MM_HUGE_ARRAY
|
||||
#elif (ACC_CC_WATCOMC && (__WATCOMC__ >= 1200))
|
||||
/* pointer arithmetics with __huge arrays seems broken in OpenWatcom 1.x */
|
||||
# undef ACC_HAVE_MM_HUGE_ARRAY
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if (ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0200))
|
||||
extern void __near __cdecl _AHSHIFT(void);
|
||||
# define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
|
||||
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
|
||||
extern void __near __cdecl _AHSHIFT(void);
|
||||
# define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
|
||||
#elif (ACC_CC_MSC || ACC_CC_TOPSPEEDC)
|
||||
extern void __near __cdecl _AHSHIFT(void);
|
||||
# define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
|
||||
#elif (ACC_CC_TURBOC && (__TURBOC__ >= 0x0295))
|
||||
extern void __near __cdecl _AHSHIFT(void);
|
||||
# define ACC_MM_AHSHIFT ((unsigned) _AHSHIFT)
|
||||
#elif ((ACC_CC_AZTECC || ACC_CC_PACIFICC || ACC_CC_TURBOC) && ACC_OS_DOS16)
|
||||
# define ACC_MM_AHSHIFT 12
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
extern unsigned char _HShift;
|
||||
# define ACC_MM_AHSHIFT ((unsigned) _HShift)
|
||||
#else
|
||||
# error "FIXME - implement ACC_MM_AHSHIFT"
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#elif (ACC_ARCH_C166)
|
||||
#if !defined(__MODEL__)
|
||||
# error "FIXME - C166 __MODEL__"
|
||||
#elif ((__MODEL__) == 0)
|
||||
# define ACC_MM_SMALL 1
|
||||
#elif ((__MODEL__) == 1)
|
||||
# define ACC_MM_SMALL 1
|
||||
#elif ((__MODEL__) == 2)
|
||||
# define ACC_MM_LARGE 1
|
||||
#elif ((__MODEL__) == 3)
|
||||
# define ACC_MM_TINY 1
|
||||
#elif ((__MODEL__) == 4)
|
||||
# define ACC_MM_XTINY 1
|
||||
#elif ((__MODEL__) == 5)
|
||||
# define ACC_MM_XSMALL 1
|
||||
#else
|
||||
# error "FIXME - C166 __MODEL__"
|
||||
#endif
|
||||
|
||||
|
||||
#elif (ACC_ARCH_MCS251)
|
||||
#if !defined(__MODEL__)
|
||||
# error "FIXME - MCS251 __MODEL__"
|
||||
#elif ((__MODEL__) == 0)
|
||||
# define ACC_MM_SMALL 1
|
||||
#elif ((__MODEL__) == 2)
|
||||
# define ACC_MM_LARGE 1
|
||||
#elif ((__MODEL__) == 3)
|
||||
# define ACC_MM_TINY 1
|
||||
#elif ((__MODEL__) == 4)
|
||||
# define ACC_MM_XTINY 1
|
||||
#elif ((__MODEL__) == 5)
|
||||
# define ACC_MM_XSMALL 1
|
||||
#else
|
||||
# error "FIXME - MCS251 __MODEL__"
|
||||
#endif
|
||||
|
||||
|
||||
#elif (ACC_ARCH_MCS51)
|
||||
#if !defined(__MODEL__)
|
||||
# error "FIXME - MCS51 __MODEL__"
|
||||
#elif ((__MODEL__) == 1)
|
||||
# define ACC_MM_SMALL 1
|
||||
#elif ((__MODEL__) == 2)
|
||||
# define ACC_MM_LARGE 1
|
||||
#elif ((__MODEL__) == 3)
|
||||
# define ACC_MM_TINY 1
|
||||
#elif ((__MODEL__) == 4)
|
||||
# define ACC_MM_XTINY 1
|
||||
#elif ((__MODEL__) == 5)
|
||||
# define ACC_MM_XSMALL 1
|
||||
#else
|
||||
# error "FIXME - MCS51 __MODEL__"
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
# define ACC_MM_FLAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_MM_FLAT)
|
||||
# define ACC_INFO_MM "flat"
|
||||
#elif (ACC_MM_TINY)
|
||||
# define ACC_INFO_MM "tiny"
|
||||
#elif (ACC_MM_SMALL)
|
||||
# define ACC_INFO_MM "small"
|
||||
#elif (ACC_MM_MEDIUM)
|
||||
# define ACC_INFO_MM "medium"
|
||||
#elif (ACC_MM_COMPACT)
|
||||
# define ACC_INFO_MM "compact"
|
||||
#elif (ACC_MM_LARGE)
|
||||
# define ACC_INFO_MM "large"
|
||||
#elif (ACC_MM_HUGE)
|
||||
# define ACC_INFO_MM "huge"
|
||||
#else
|
||||
# error "unknown memory model"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,203 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Operating System - exactly one of:
|
||||
*
|
||||
* ACC_OS_POSIX [default]
|
||||
* ACC_OS_AMIGAOS
|
||||
* ACC_OS_BEOS
|
||||
* ACC_OS_CYGWIN hybrid WIN32 and POSIX
|
||||
* ACC_OS_DOS16 16-bit DOS (segmented memory model)
|
||||
* ACC_OS_DOS32
|
||||
* ACC_OS_EMX hybrid OS/2, DOS32, WIN32 (with RSX) and POSIX
|
||||
* ACC_OS_MACCLASSIC Macintosh Classic
|
||||
* ACC_OS_PALMOS
|
||||
* ACC_OS_OS2 OS/2
|
||||
* ACC_OS_OS216 16-bit OS/2 1.x (segmented memory model)
|
||||
* ACC_OS_QNX
|
||||
* ACC_OS_RISCOS
|
||||
* ACC_OS_TOS Atari TOS / MiNT
|
||||
* ACC_OS_VMS
|
||||
* ACC_OS_WIN16 16-bit Windows 3.x (segmented memory model)
|
||||
* ACC_OS_WIN32
|
||||
* ACC_OS_WIN64 64-bit Windows (LLP64 programming model)
|
||||
*/
|
||||
|
||||
|
||||
#if defined(__CYGWIN__) && defined(__GNUC__)
|
||||
# define ACC_OS_CYGWIN 1
|
||||
# define ACC_INFO_OS "cygwin"
|
||||
#elif defined(__EMX__) && defined(__GNUC__)
|
||||
# define ACC_OS_EMX 1
|
||||
# define ACC_INFO_OS "emx"
|
||||
#elif defined(__BEOS__)
|
||||
# define ACC_OS_BEOS 1
|
||||
# define ACC_INFO_OS "beos"
|
||||
#elif defined(__QNX__)
|
||||
# define ACC_OS_QNX 1
|
||||
# define ACC_INFO_OS "qnx"
|
||||
#elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460)
|
||||
# define ACC_OS_DOS32 1
|
||||
# define ACC_INFO_OS "dos32"
|
||||
#elif defined(__BORLANDC__) && defined(__DPMI16__)
|
||||
# define ACC_OS_DOS16 1
|
||||
# define ACC_INFO_OS "dos16"
|
||||
#elif defined(__ZTC__) && defined(DOS386)
|
||||
# define ACC_OS_DOS32 1
|
||||
# define ACC_INFO_OS "dos32"
|
||||
#elif defined(__OS2__) || defined(__OS2V2__)
|
||||
# if (UINT_MAX == ACC_0xffffL)
|
||||
# define ACC_OS_OS216 1
|
||||
# define ACC_INFO_OS "os216"
|
||||
# elif (UINT_MAX == ACC_0xffffffffL)
|
||||
# define ACC_OS_OS2 1
|
||||
# define ACC_INFO_OS "os2"
|
||||
# else
|
||||
# error "check your limits.h header"
|
||||
# endif
|
||||
#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64)
|
||||
# define ACC_OS_WIN64 1
|
||||
# define ACC_INFO_OS "win64"
|
||||
#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__)
|
||||
# define ACC_OS_WIN32 1
|
||||
# define ACC_INFO_OS "win32"
|
||||
#elif defined(__MWERKS__) && defined(__INTEL__)
|
||||
# define ACC_OS_WIN32 1
|
||||
# define ACC_INFO_OS "win32"
|
||||
#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows)
|
||||
# if (UINT_MAX == ACC_0xffffL)
|
||||
# define ACC_OS_WIN16 1
|
||||
# define ACC_INFO_OS "win16"
|
||||
# elif (UINT_MAX == ACC_0xffffffffL)
|
||||
# define ACC_OS_WIN32 1
|
||||
# define ACC_INFO_OS "win32"
|
||||
# else
|
||||
# error "check your limits.h header"
|
||||
# endif
|
||||
#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS))
|
||||
# if (UINT_MAX == ACC_0xffffL)
|
||||
# define ACC_OS_DOS16 1
|
||||
# define ACC_INFO_OS "dos16"
|
||||
# elif (UINT_MAX == ACC_0xffffffffL)
|
||||
# define ACC_OS_DOS32 1
|
||||
# define ACC_INFO_OS "dos32"
|
||||
# else
|
||||
# error "check your limits.h header"
|
||||
# endif
|
||||
#elif defined(__WATCOMC__)
|
||||
# if defined(__NT__) && (UINT_MAX == ACC_0xffffL)
|
||||
/* wcl: NT host defaults to DOS target */
|
||||
# define ACC_OS_DOS16 1
|
||||
# define ACC_INFO_OS "dos16"
|
||||
# elif defined(__NT__) && (__WATCOMC__ < 1100)
|
||||
/* wcl386: Watcom C 11 defines _WIN32 */
|
||||
# define ACC_OS_WIN32 1
|
||||
# define ACC_INFO_OS "win32"
|
||||
# else
|
||||
# error "please specify a target using the -bt compiler option"
|
||||
# endif
|
||||
#elif defined(__palmos__)
|
||||
# if (UINT_MAX == ACC_0xffffL)
|
||||
# define ACC_OS_PALMOS 1
|
||||
# define ACC_INFO_OS "palmos"
|
||||
# else
|
||||
# error "check your limits.h header"
|
||||
# endif
|
||||
#elif defined(__TOS__) || defined(__atarist__)
|
||||
# define ACC_OS_TOS 1
|
||||
# define ACC_INFO_OS "tos"
|
||||
#elif defined(macintosh) && !defined(__ppc__)
|
||||
# define ACC_OS_MACCLASSIC 1
|
||||
# define ACC_INFO_OS "macclassic"
|
||||
#elif defined(__VMS)
|
||||
# define ACC_OS_VMS 1
|
||||
# define ACC_INFO_OS "vms"
|
||||
#else
|
||||
# define ACC_OS_POSIX 1
|
||||
# define ACC_INFO_OS "posix"
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_POSIX)
|
||||
# if defined(_AIX) || defined(__AIX__) || defined(__aix__)
|
||||
# define ACC_OS_POSIX_AIX 1
|
||||
# define ACC_INFO_OS_POSIX "aix"
|
||||
# elif defined(__FreeBSD__)
|
||||
# define ACC_OS_POSIX_FREEBSD 1
|
||||
# define ACC_INFO_OS_POSIX "freebsd"
|
||||
# elif defined(__hpux__) || defined(__hpux)
|
||||
# define ACC_OS_POSIX_HPUX 1
|
||||
# define ACC_INFO_OS_POSIX "hpux"
|
||||
# elif defined(__INTERIX)
|
||||
# define ACC_OS_POSIX_INTERIX 1
|
||||
# define ACC_INFO_OS_POSIX "interix"
|
||||
# elif defined(__IRIX__) || defined(__irix__)
|
||||
# define ACC_OS_POSIX_IRIX 1
|
||||
# define ACC_INFO_OS_POSIX "irix"
|
||||
# elif defined(__linux__) || defined(__linux)
|
||||
# define ACC_OS_POSIX_LINUX 1
|
||||
# define ACC_INFO_OS_POSIX "linux"
|
||||
# elif defined(__APPLE__) || defined(__MACOS__)
|
||||
# define ACC_OS_POSIX_MACOSX 1
|
||||
# define ACC_INFO_OS_POSIX "macosx"
|
||||
# elif defined(__NetBSD__)
|
||||
# define ACC_OS_POSIX_NETBSD 1
|
||||
# define ACC_INFO_OS_POSIX "netbsd"
|
||||
# elif defined(__OpenBSD__)
|
||||
# define ACC_OS_POSIX_OPENBSD 1
|
||||
# define ACC_INFO_OS_POSIX "openbsd"
|
||||
# elif defined(__osf__)
|
||||
# define ACC_OS_POSIX_OSF 1
|
||||
# define ACC_INFO_OS_POSIX "osf"
|
||||
# elif defined(__solaris__) || defined(__sun)
|
||||
# if defined(__SVR4) || defined(__svr4__)
|
||||
# define ACC_OS_POSIX_SOLARIS 1
|
||||
# define ACC_INFO_OS_POSIX "solaris"
|
||||
# else
|
||||
# define ACC_OS_POSIX_SUNOS 1
|
||||
# define ACC_INFO_OS_POSIX "sunos"
|
||||
# endif
|
||||
# elif defined(__ultrix__) || defined(__ultrix)
|
||||
# define ACC_OS_POSIX_ULTRIX 1
|
||||
# define ACC_INFO_OS_POSIX "ultrix"
|
||||
# else
|
||||
# define ACC_OS_POSIX_UNKNOWN 1
|
||||
# define ACC_INFO_OS_POSIX "unknown"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
|
||||
# if (UINT_MAX != ACC_0xffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
# if (ULONG_MAX != ACC_0xffffffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
#endif
|
||||
#if (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# if (UINT_MAX != ACC_0xffffffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
# if (ULONG_MAX != ACC_0xffffffffL)
|
||||
# error "this should not happen"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,321 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
|
||||
#if (ACC_CC_GNUC >= 0x020800ul) /* 2.8.0 */
|
||||
# define __acc_gnuc_extension__ __extension__
|
||||
#else
|
||||
# define __acc_gnuc_extension__
|
||||
#endif
|
||||
|
||||
#if (SIZEOF_LONG_LONG > 0)
|
||||
__acc_gnuc_extension__ typedef long long acc_llong_t;
|
||||
#endif
|
||||
#if (SIZEOF_UNSIGNED_LONG_LONG > 0)
|
||||
__acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
|
||||
#endif
|
||||
|
||||
#if (!(SIZEOF_SHORT > 0 && SIZEOF_INT > 0 && SIZEOF_LONG > 0))
|
||||
# error "missing defines for sizes"
|
||||
#endif
|
||||
#if (!(SIZEOF_PTRDIFF_T > 0 && SIZEOF_SIZE_T > 0 && SIZEOF_VOID_P > 0 && SIZEOF_CHAR_P > 0))
|
||||
# error "missing defines for sizes"
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// some <stdint.h> types:
|
||||
// required: least & fast: acc_int32l_t, acc_int32f_t
|
||||
// optional: exact32 acc_int32e_t
|
||||
// optional: least64 acc_int64l_t
|
||||
************************************************************************/
|
||||
|
||||
/* acc_int32e_t is int32_t in <stdint.h> terminology */
|
||||
#if !defined(acc_int32e_t)
|
||||
#if (SIZEOF_INT == 4)
|
||||
# define acc_int32e_t int
|
||||
# define acc_uint32e_t unsigned int
|
||||
# define ACC_INT32E_C(c) c
|
||||
# define ACC_UINT32E_C(c) c##U
|
||||
#elif (SIZEOF_LONG == 4)
|
||||
# define acc_int32e_t long int
|
||||
# define acc_uint32e_t unsigned long int
|
||||
# define ACC_INT32E_C(c) c##L
|
||||
# define ACC_UINT32E_C(c) c##UL
|
||||
#elif (SIZEOF_SHORT == 4)
|
||||
# define acc_int32e_t short int
|
||||
# define acc_uint32e_t unsigned short int
|
||||
# define ACC_INT32E_C(c) c
|
||||
# define ACC_UINT32E_C(c) c##U
|
||||
#elif (SIZEOF_LONG_LONG == 4 && SIZEOF_UNSIGNED_LONG_LONG == 4)
|
||||
# define acc_int32e_t acc_llong_t
|
||||
# define acc_uint32e_t acc_ullong_t
|
||||
# define ACC_INT32E_C(c) c##LL
|
||||
# define ACC_UINT32E_C(c) c##ULL
|
||||
#elif (SIZEOF___INT32 == 4 && SIZEOF_UNSIGNED___INT32 == 4)
|
||||
# define acc_int32e_t __int32
|
||||
# define acc_uint32e_t unsigned __int32
|
||||
# if (SIZEOF_INT > 4)
|
||||
# define ACC_INT32E_C(c) c
|
||||
# define ACC_UINT32E_C(c) c##U
|
||||
# elif (SIZEOF_LONG > 4)
|
||||
# define ACC_INT32E_C(c) c##L
|
||||
# define ACC_UINT32E_C(c) c##UL
|
||||
# else
|
||||
# define ACC_INT32E_C(c) c##i32
|
||||
# define ACC_UINT32E_C(c) c##ui32
|
||||
# endif
|
||||
#else
|
||||
/* no exact 32-bit integral type on this machine */
|
||||
#endif
|
||||
#endif
|
||||
#if defined(acc_int32e_t)
|
||||
# define SIZEOF_ACC_INT32E_T 4
|
||||
#endif
|
||||
|
||||
|
||||
/* acc_int32l_t is int_least32_t in <stdint.h> terminology */
|
||||
#if !defined(acc_int32l_t)
|
||||
#if defined(acc_int32e_t)
|
||||
# define acc_int32l_t acc_int32e_t
|
||||
# define acc_uint32l_t acc_uint32e_t
|
||||
# define ACC_INT32L_C(c) ACC_INT32E_C(c)
|
||||
# define ACC_UINT32L_C(c) ACC_UINT32E_C(c)
|
||||
# define SIZEOF_ACC_INT32L_T SIZEOF_ACC_INT32E_T
|
||||
#elif (SIZEOF_INT > 4)
|
||||
# define acc_int32l_t int
|
||||
# define acc_uint32l_t unsigned int
|
||||
# define ACC_INT32L_C(c) c
|
||||
# define ACC_UINT32L_C(c) c##U
|
||||
# define SIZEOF_ACC_INT32L_T SIZEOF_INT
|
||||
#elif (SIZEOF_LONG > 4)
|
||||
# define acc_int32l_t long int
|
||||
# define acc_uint32l_t unsigned long int
|
||||
# define ACC_INT32L_C(c) c##L
|
||||
# define ACC_UINT32L_C(c) c##UL
|
||||
# define SIZEOF_ACC_INT32L_T SIZEOF_LONG
|
||||
#else
|
||||
# error "acc_int32l_t"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* acc_int32f_t is int_fast32_t in <stdint.h> terminology */
|
||||
#if !defined(acc_int32f_t)
|
||||
#if (SIZEOF_INT >= 4)
|
||||
# define acc_int32f_t int
|
||||
# define acc_uint32f_t unsigned int
|
||||
# define ACC_INT32F_C(c) c
|
||||
# define ACC_UINT32F_C(c) c##U
|
||||
# define SIZEOF_ACC_INT32F_T SIZEOF_INT
|
||||
#elif (SIZEOF_LONG >= 4)
|
||||
# define acc_int32f_t long int
|
||||
# define acc_uint32f_t unsigned long int
|
||||
# define ACC_INT32F_C(c) c##L
|
||||
# define ACC_UINT32F_C(c) c##UL
|
||||
# define SIZEOF_ACC_INT32F_T SIZEOF_LONG
|
||||
#elif defined(acc_int32e_t)
|
||||
# define acc_int32f_t acc_int32e_t
|
||||
# define acc_uint32f_t acc_uint32e_t
|
||||
# define ACC_INT32F_C(c) ACC_INT32E_C(c)
|
||||
# define ACC_UINT32F_C(c) ACC_UINT32E_C(c)
|
||||
# define SIZEOF_ACC_INT32F_T SIZEOF_ACC_INT32E_T
|
||||
#else
|
||||
# error "acc_int32f_t"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* acc_int64l_t is int_least64_t in <stdint.h> terminology */
|
||||
#if !defined(acc_int64l_t)
|
||||
#if (SIZEOF___INT64 >= 8 && SIZEOF_UNSIGNED___INT64 >= 8)
|
||||
# if (ACC_CC_BORLANDC) && !defined(ACC_CONFIG_PREFER___INT64)
|
||||
# define ACC_CONFIG_PREFER___INT64 1
|
||||
# endif
|
||||
#endif
|
||||
#if (SIZEOF_INT >= 8)
|
||||
# define acc_int64l_t int
|
||||
# define acc_uint64l_t unsigned int
|
||||
# define ACC_INT64L_C(c) c
|
||||
# define ACC_UINT64L_C(c) c##U
|
||||
# define SIZEOF_ACC_INT64L_T SIZEOF_INT
|
||||
#elif (SIZEOF_LONG >= 8)
|
||||
# define acc_int64l_t long int
|
||||
# define acc_uint64l_t unsigned long int
|
||||
# define ACC_INT64L_C(c) c##L
|
||||
# define ACC_UINT64L_C(c) c##UL
|
||||
# define SIZEOF_ACC_INT64L_T SIZEOF_LONG
|
||||
#elif (SIZEOF_LONG_LONG >= 8 && SIZEOF_UNSIGNED_LONG_LONG >= 8) && !defined(ACC_CONFIG_PREFER___INT64)
|
||||
# define acc_int64l_t acc_llong_t
|
||||
# define acc_uint64l_t acc_ullong_t
|
||||
# if (ACC_CC_BORLANDC)
|
||||
# define ACC_INT64L_C(c) ((c) + 0ll)
|
||||
# define ACC_UINT64L_C(c) ((c) + 0ull)
|
||||
# else
|
||||
# define ACC_INT64L_C(c) c##LL
|
||||
# define ACC_UINT64L_C(c) c##ULL
|
||||
# endif
|
||||
# define SIZEOF_ACC_INT64L_T SIZEOF_LONG_LONG
|
||||
#elif (SIZEOF___INT64 >= 8 && SIZEOF_UNSIGNED___INT64 >= 8)
|
||||
# define acc_int64l_t __int64
|
||||
# define acc_uint64l_t unsigned __int64
|
||||
# if (ACC_CC_BORLANDC)
|
||||
# define ACC_INT64L_C(c) ((c) + 0i64)
|
||||
# define ACC_UINT64L_C(c) ((c) + 0ui64)
|
||||
# else
|
||||
# define ACC_INT64L_C(c) c##i64
|
||||
# define ACC_UINT64L_C(c) c##ui64
|
||||
# endif
|
||||
# define SIZEOF_ACC_INT64L_T SIZEOF___INT64
|
||||
#else
|
||||
/* no least 64-bit integral type on this machine */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(acc_intptr_t)
|
||||
#if (ACC_ARCH_IA32 && ACC_CC_MSC && (_MSC_VER >= 1300))
|
||||
typedef __w64 int acc_intptr_t;
|
||||
typedef __w64 unsigned int acc_uintptr_t;
|
||||
# define acc_intptr_t acc_intptr_t
|
||||
# define acc_uintptr_t acc_uintptr_t
|
||||
# define SIZEOF_ACC_INTPTR_T SIZEOF_INT
|
||||
#elif (SIZEOF_INT >= SIZEOF_VOID_P)
|
||||
# define acc_intptr_t int
|
||||
# define acc_uintptr_t unsigned int
|
||||
# define SIZEOF_ACC_INTPTR_T SIZEOF_INT
|
||||
#elif (SIZEOF_LONG >= SIZEOF_VOID_P)
|
||||
# define acc_intptr_t long
|
||||
# define acc_uintptr_t unsigned long
|
||||
# define SIZEOF_ACC_INTPTR_T SIZEOF_LONG
|
||||
#elif (SIZEOF_ACC_INT64L_T >= SIZEOF_VOID_P)
|
||||
# define acc_intptr_t acc_int64l_t
|
||||
# define acc_uintptr_t acc_uint64l_t
|
||||
# define SIZEOF_ACC_INTPTR_T SIZEOF_ACC_INT64L_T
|
||||
#else
|
||||
# error "acc_intptr_t"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* workaround for broken compilers */
|
||||
#if (ACC_BROKEN_INTEGRAL_CONSTANTS)
|
||||
# undef ACC_INT32E_C
|
||||
# undef ACC_UINT32E_C
|
||||
# undef ACC_INT32L_C
|
||||
# undef ACC_UINT32L_C
|
||||
# undef ACC_INT32F_C
|
||||
# undef ACC_UINT32F_C
|
||||
# if (SIZEOF_INT == 4)
|
||||
# define ACC_INT32E_C(c) ((c) + 0)
|
||||
# define ACC_UINT32E_C(c) ((c) + 0U)
|
||||
# define ACC_INT32L_C(c) ((c) + 0)
|
||||
# define ACC_UINT32L_C(c) ((c) + 0U)
|
||||
# define ACC_INT32F_C(c) ((c) + 0)
|
||||
# define ACC_UINT32F_C(c) ((c) + 0U)
|
||||
# elif (SIZEOF_LONG == 4)
|
||||
# define ACC_INT32E_C(c) ((c) + 0L)
|
||||
# define ACC_UINT32E_C(c) ((c) + 0UL)
|
||||
# define ACC_INT32L_C(c) ((c) + 0L)
|
||||
# define ACC_UINT32L_C(c) ((c) + 0UL)
|
||||
# define ACC_INT32F_C(c) ((c) + 0L)
|
||||
# define ACC_UINT32F_C(c) ((c) + 0UL)
|
||||
# else
|
||||
# error "integral constants"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// calling conventions
|
||||
************************************************************************/
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# if (ACC_CC_GNUC || ACC_CC_HIGHC || ACC_CC_NDPC || ACC_CC_PACIFICC)
|
||||
# elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
|
||||
# define __acc_cdecl __cdecl
|
||||
# define __acc_cdecl_atexit
|
||||
# define __acc_cdecl_main __cdecl
|
||||
# if (ACC_OS_OS2 && (ACC_CC_DMC || ACC_CC_SYMANTECC))
|
||||
# define __acc_cdecl_qsort __pascal
|
||||
# elif (ACC_OS_OS2 && (ACC_CC_ZORTECHC))
|
||||
# define __acc_cdecl_qsort _stdcall
|
||||
# else
|
||||
# define __acc_cdecl_qsort __cdecl
|
||||
# endif
|
||||
# elif (ACC_CC_WATCOMC)
|
||||
# define __acc_cdecl __cdecl
|
||||
# else
|
||||
# define __acc_cdecl __cdecl
|
||||
# define __acc_cdecl_atexit __cdecl
|
||||
# define __acc_cdecl_main __cdecl
|
||||
# define __acc_cdecl_qsort __cdecl
|
||||
# endif
|
||||
# if (ACC_CC_GNUC || ACC_CC_HIGHC || ACC_CC_NDPC || ACC_CC_PACIFICC || ACC_CC_WATCOMC)
|
||||
# elif (ACC_OS_OS2 && (ACC_CC_DMC || ACC_CC_SYMANTECC))
|
||||
# define __acc_cdecl_sighandler __pascal
|
||||
# elif (ACC_OS_OS2 && (ACC_CC_ZORTECHC))
|
||||
# define __acc_cdecl_sighandler _stdcall
|
||||
# elif (ACC_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE)
|
||||
# define __acc_cdecl_sighandler __clrcall
|
||||
# elif (ACC_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700))
|
||||
# if defined(_DLL)
|
||||
# define __acc_cdecl_sighandler _far _cdecl _loadds
|
||||
# elif defined(_MT)
|
||||
# define __acc_cdecl_sighandler _far _cdecl
|
||||
# else
|
||||
# define __acc_cdecl_sighandler _cdecl
|
||||
# endif
|
||||
# else
|
||||
# define __acc_cdecl_sighandler __cdecl
|
||||
# endif
|
||||
#elif (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
|
||||
# define __acc_cdecl cdecl
|
||||
#endif
|
||||
|
||||
#if !defined(__acc_cdecl)
|
||||
# define __acc_cdecl
|
||||
#endif
|
||||
#if !defined(__acc_cdecl_atexit)
|
||||
# define __acc_cdecl_atexit
|
||||
#endif
|
||||
#if !defined(__acc_cdecl_main)
|
||||
# define __acc_cdecl_main
|
||||
#endif
|
||||
#if !defined(__acc_cdecl_qsort)
|
||||
# define __acc_cdecl_qsort
|
||||
#endif
|
||||
#if !defined(__acc_cdecl_sighandler)
|
||||
# define __acc_cdecl_sighandler
|
||||
#endif
|
||||
#if !defined(__acc_cdecl_va)
|
||||
# define __acc_cdecl_va __acc_cdecl
|
||||
#endif
|
||||
|
||||
#if (ACC_BROKEN_CDECL_ALT_SYNTAX)
|
||||
typedef void __acc_cdecl_sighandler (*acc_sighandler_t)(int);
|
||||
#elif defined(RETSIGTYPE)
|
||||
typedef RETSIGTYPE (__acc_cdecl_sighandler *acc_sighandler_t)(int);
|
||||
#else
|
||||
typedef void (__acc_cdecl_sighandler *acc_sighandler_t)(int);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,3 @@
|
||||
fnmatch.ch
|
||||
getopt.ch
|
||||
perfctr.ch
|
||||
@@ -0,0 +1,250 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_BELE_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// be16 / be24 / be32
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(unsigned, acc_get_be16) (const acc_hvoid_p p)
|
||||
{
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
return ((unsigned)b[1]) | ((unsigned)b[0] << 8);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be24) (const acc_hvoid_p p)
|
||||
{
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
return ((acc_uint32l_t)b[2]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[0] << 16);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be32) (const acc_hvoid_p p)
|
||||
{
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
return ((acc_uint32l_t)b[3]) | ((acc_uint32l_t)b[2] << 8) | ((acc_uint32l_t)b[1] << 16) | ((acc_uint32l_t)b[0] << 24);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_be16) (acc_hvoid_p p, unsigned v)
|
||||
{
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
b[1] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[0] = (unsigned char) ((v >> 8) & 0xff);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_be24) (acc_hvoid_p p, acc_uint32l_t v)
|
||||
{
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
b[2] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[1] = (unsigned char) ((v >> 8) & 0xff);
|
||||
b[0] = (unsigned char) ((v >> 16) & 0xff);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_be32) (acc_hvoid_p p, acc_uint32l_t v)
|
||||
{
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
b[3] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[2] = (unsigned char) ((v >> 8) & 0xff);
|
||||
b[1] = (unsigned char) ((v >> 16) & 0xff);
|
||||
b[0] = (unsigned char) ((v >> 24) & 0xff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(unsigned, acc_get_le16) (const acc_hvoid_p p)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
return (* (const unsigned short *) (p));
|
||||
#else
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
return ((unsigned)b[0]) | ((unsigned)b[1] << 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le24) (const acc_hvoid_p p)
|
||||
{
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
return ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le32) (const acc_hvoid_p p)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
return (* (const acc_uint32e_t *) (p));
|
||||
#else
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
return ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16) | ((acc_uint32l_t)b[3] << 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// le16 / le24 / le32
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_le16) (acc_hvoid_p p, unsigned v)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
(* (unsigned short *) (p) = (unsigned short) (v));
|
||||
#else
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
b[0] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[1] = (unsigned char) ((v >> 8) & 0xff);
|
||||
#endif
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_le24) (acc_hvoid_p p, acc_uint32l_t v)
|
||||
{
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
b[0] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[1] = (unsigned char) ((v >> 8) & 0xff);
|
||||
b[2] = (unsigned char) ((v >> 16) & 0xff);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_le32) (acc_hvoid_p p, acc_uint32l_t v)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
(* (acc_uint32e_t *) (p) = (acc_uint32e_t) (v));
|
||||
#else
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
b[0] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[1] = (unsigned char) ((v >> 8) & 0xff);
|
||||
b[2] = (unsigned char) ((v >> 16) & 0xff);
|
||||
b[3] = (unsigned char) ((v >> 24) & 0xff);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// be64
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(acc_uint64l_t)
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint64l_t, acc_get_be64) (const acc_hvoid_p p)
|
||||
{
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
#if (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8)
|
||||
return ((acc_uint64l_t)b[7]) | ((acc_uint64l_t)b[6] << 8) | ((acc_uint64l_t)b[5] << 16) | ((acc_uint64l_t)b[4] << 24) | ((acc_uint64l_t)b[3] << 32) | ((acc_uint64l_t)b[2] << 40) | ((acc_uint64l_t)b[1] << 48) | ((acc_uint64l_t)b[0] << 56);
|
||||
#else
|
||||
acc_uint32l_t v0, v1;
|
||||
v1 = ((acc_uint32l_t)b[3]) | ((acc_uint32l_t)b[2] << 8) | ((acc_uint32l_t)b[1] << 16) | ((acc_uint32l_t)b[0] << 24);
|
||||
b += 4;
|
||||
v0 = ((acc_uint32l_t)b[3]) | ((acc_uint32l_t)b[2] << 8) | ((acc_uint32l_t)b[1] << 16) | ((acc_uint32l_t)b[0] << 24);
|
||||
return ((acc_uint64l_t)v0) | ((acc_uint64l_t)v1 << 32);
|
||||
#endif
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_be64) (acc_hvoid_p p, acc_uint64l_t v)
|
||||
{
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
#if (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8)
|
||||
b[7] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[6] = (unsigned char) ((v >> 8) & 0xff);
|
||||
b[5] = (unsigned char) ((v >> 16) & 0xff);
|
||||
b[4] = (unsigned char) ((v >> 24) & 0xff);
|
||||
b[3] = (unsigned char) ((v >> 32) & 0xff);
|
||||
b[2] = (unsigned char) ((v >> 40) & 0xff);
|
||||
b[1] = (unsigned char) ((v >> 48) & 0xff);
|
||||
b[0] = (unsigned char) ((v >> 56) & 0xff);
|
||||
#else
|
||||
acc_uint32l_t x;
|
||||
x = (acc_uint32l_t) (v >> 0);
|
||||
b[7] = (unsigned char) ((x >> 0) & 0xff);
|
||||
b[6] = (unsigned char) ((x >> 8) & 0xff);
|
||||
b[5] = (unsigned char) ((x >> 16) & 0xff);
|
||||
b[4] = (unsigned char) ((x >> 24) & 0xff);
|
||||
x = (acc_uint32l_t) (v >> 32);
|
||||
b[3] = (unsigned char) ((x >> 0) & 0xff);
|
||||
b[2] = (unsigned char) ((x >> 8) & 0xff);
|
||||
b[1] = (unsigned char) ((x >> 16) & 0xff);
|
||||
b[0] = (unsigned char) ((x >> 24) & 0xff);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* acc_uint64l_t */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// le64
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(acc_uint64l_t)
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint64l_t, acc_get_le64) (const acc_hvoid_p p)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64)
|
||||
return (* (const acc_uint64l_t *) (p));
|
||||
#elif (ACC_ARCH_IA32)
|
||||
const acc_uint32e_t* b = (const acc_uint32e_t*) p;
|
||||
return ((acc_uint64l_t)b[0]) | ((acc_uint64l_t)b[1] << 32);
|
||||
#elif (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8)
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
return ((acc_uint64l_t)b[0]) | ((acc_uint64l_t)b[1] << 8) | ((acc_uint64l_t)b[2] << 16) | ((acc_uint64l_t)b[3] << 24) | ((acc_uint64l_t)b[4] << 32) | ((acc_uint64l_t)b[5] << 40) | ((acc_uint64l_t)b[6] << 48) | ((acc_uint64l_t)b[7] << 56);
|
||||
#else
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) p;
|
||||
acc_uint32l_t v0, v1;
|
||||
v0 = ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16) | ((acc_uint32l_t)b[3] << 24);
|
||||
b += 4;
|
||||
v1 = ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16) | ((acc_uint32l_t)b[3] << 24);
|
||||
return ((acc_uint64l_t)v0) | ((acc_uint64l_t)v1 << 32);
|
||||
#endif
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_set_le64) (acc_hvoid_p p, acc_uint64l_t v)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64)
|
||||
(* (acc_uint64l_t *) (p)) = v;
|
||||
#elif (ACC_ARCH_IA32)
|
||||
(((acc_uint32e_t *)(p))[0] = (acc_uint32e_t) (v >> 0));
|
||||
(((acc_uint32e_t *)(p))[1] = (acc_uint32e_t) (v >> 32));
|
||||
#elif (SIZEOF_LONG >= 8) || (SIZEOF_SIZE_T >= 8)
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
b[0] = (unsigned char) ((v >> 0) & 0xff);
|
||||
b[1] = (unsigned char) ((v >> 8) & 0xff);
|
||||
b[2] = (unsigned char) ((v >> 16) & 0xff);
|
||||
b[3] = (unsigned char) ((v >> 24) & 0xff);
|
||||
b[4] = (unsigned char) ((v >> 32) & 0xff);
|
||||
b[5] = (unsigned char) ((v >> 40) & 0xff);
|
||||
b[6] = (unsigned char) ((v >> 48) & 0xff);
|
||||
b[7] = (unsigned char) ((v >> 56) & 0xff);
|
||||
#else
|
||||
acc_hbyte_p b = (acc_hbyte_p) p;
|
||||
acc_uint32l_t x;
|
||||
x = (acc_uint32l_t) (v >> 0);
|
||||
b[0] = (unsigned char) ((x >> 0) & 0xff);
|
||||
b[1] = (unsigned char) ((x >> 8) & 0xff);
|
||||
b[2] = (unsigned char) ((x >> 16) & 0xff);
|
||||
b[3] = (unsigned char) ((x >> 24) & 0xff);
|
||||
x = (acc_uint32l_t) (v >> 32);
|
||||
b[4] = (unsigned char) ((x >> 0) & 0xff);
|
||||
b[5] = (unsigned char) ((x >> 8) & 0xff);
|
||||
b[6] = (unsigned char) ((x >> 16) & 0xff);
|
||||
b[7] = (unsigned char) ((x >> 24) & 0xff);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* acc_uint64l_t */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,106 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_DOSALLOC_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_OS216)
|
||||
ACC_EXTERN_C unsigned short __far __pascal DosAllocHuge(unsigned short, unsigned short, unsigned short __far *, unsigned short, unsigned short);
|
||||
ACC_EXTERN_C unsigned short __far __pascal DosFreeSeg(unsigned short);
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// dos_alloc
|
||||
************************************************************************/
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
|
||||
#if !defined(ACC_CC_AZTECC)
|
||||
|
||||
ACCLIB_PUBLIC(void __far*, acc_dos_alloc) (unsigned long size)
|
||||
{
|
||||
void __far* p = 0;
|
||||
union REGS ri, ro;
|
||||
|
||||
if ((long)size <= 0)
|
||||
return p;
|
||||
size = (size + 15) >> 4;
|
||||
if (size > 0xffffu)
|
||||
return p;
|
||||
ri.x.ax = 0x4800;
|
||||
ri.x.bx = (unsigned short) size;
|
||||
int86(0x21, &ri, &ro);
|
||||
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
|
||||
p = (void __far*) ACC_MK_FP(ro.x.ax, 0);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_dos_free) (void __far* p)
|
||||
{
|
||||
union REGS ri, ro;
|
||||
struct SREGS rs;
|
||||
|
||||
if (!p)
|
||||
return 0;
|
||||
if (ACC_FP_OFF(p) != 0)
|
||||
return -1;
|
||||
segread(&rs);
|
||||
ri.x.ax = 0x4900;
|
||||
rs.es = ACC_FP_SEG(p);
|
||||
int86x(0x21, &ri, &ro, &rs);
|
||||
if (ro.x.cflag & 1) /* if carry flag set */
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_OS216)
|
||||
|
||||
ACCLIB_PUBLIC(void __far*, acc_dos_alloc) (unsigned long size)
|
||||
{
|
||||
void __far* p = 0;
|
||||
unsigned short sel = 0;
|
||||
|
||||
if ((long)size <= 0)
|
||||
return p;
|
||||
if (DosAllocHuge((unsigned short)(size >> 16), (unsigned short)size, &sel, 0, 0) == 0)
|
||||
p = (void __far*) ACC_MK_FP(sel, 0);
|
||||
return p;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_dos_free) (void __far* p)
|
||||
{
|
||||
if (!p)
|
||||
return 0;
|
||||
if (ACC_FP_OFF(p) != 0)
|
||||
return -1;
|
||||
if (DosFreeSeg(ACC_FP_SEG(p)) != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,157 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_HALLOC_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
#if 1 && (ACC_OS_DOS16 && defined(BLX286))
|
||||
# define __ACCLIB_HALLOC_USE_DAH 1
|
||||
#elif 1 && (ACC_OS_DOS16 && defined(DOSX286))
|
||||
# define __ACCLIB_HALLOC_USE_DAH 1
|
||||
#elif 1 && (ACC_OS_OS216)
|
||||
# define __ACCLIB_HALLOC_USE_DAH 1
|
||||
#elif 1 && (ACC_OS_WIN16)
|
||||
# define __ACCLIB_HALLOC_USE_GA 1
|
||||
#elif 1 && (ACC_OS_DOS16) && (ACC_CC_BORLANDC) && defined(__DPMI16__)
|
||||
# define __ACCLIB_HALLOC_USE_GA 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (__ACCLIB_HALLOC_USE_DAH)
|
||||
#if 0 && (ACC_OS_OS216)
|
||||
#include <os2.h>
|
||||
#else
|
||||
ACC_EXTERN_C unsigned short __far __pascal DosAllocHuge(unsigned short, unsigned short, unsigned short __far *, unsigned short, unsigned short);
|
||||
ACC_EXTERN_C unsigned short __far __pascal DosFreeSeg(unsigned short);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (__ACCLIB_HALLOC_USE_GA)
|
||||
#if 0
|
||||
#define STRICT 1
|
||||
#include <windows.h>
|
||||
#else
|
||||
ACC_EXTERN_C const void __near* __far __pascal GlobalAlloc(unsigned, unsigned long);
|
||||
ACC_EXTERN_C const void __near* __far __pascal GlobalFree(const void __near*);
|
||||
ACC_EXTERN_C unsigned long __far __pascal GlobalHandle(unsigned);
|
||||
ACC_EXTERN_C void __far* __far __pascal GlobalLock(const void __near*);
|
||||
ACC_EXTERN_C int __far __pascal GlobalUnlock(const void __near*);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// halloc
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_halloc) (acc_hsize_t size)
|
||||
{
|
||||
acc_hvoid_p p = 0;
|
||||
|
||||
if (size <= 0)
|
||||
return p;
|
||||
|
||||
#if 0 && defined(__palmos__)
|
||||
p = MemPtrNew(size);
|
||||
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
|
||||
if (size < (size_t) -1)
|
||||
p = malloc((size_t) size);
|
||||
#else
|
||||
if ((long)size <= 0)
|
||||
return p;
|
||||
{
|
||||
#if (__ACCLIB_HALLOC_USE_DAH)
|
||||
unsigned short sel = 0;
|
||||
if (DosAllocHuge((unsigned short)(size >> 16), (unsigned short)size, &sel, 0, 0) == 0)
|
||||
p = (acc_hvoid_p) ACC_MK_FP(sel, 0);
|
||||
#elif (__ACCLIB_HALLOC_USE_GA)
|
||||
const void __near* h = GlobalAlloc(2, size);
|
||||
if (h) {
|
||||
p = GlobalLock(h);
|
||||
if (p && ACC_FP_OFF(p) != 0) {
|
||||
GlobalUnlock(h);
|
||||
p = 0;
|
||||
}
|
||||
if (!p)
|
||||
GlobalFree(h);
|
||||
}
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 700))
|
||||
p = _halloc(size, 1);
|
||||
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
|
||||
p = halloc(size, 1);
|
||||
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
|
||||
p = farmalloc(size);
|
||||
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
p = farmalloc(size);
|
||||
#elif defined(ACC_CC_AZTECC)
|
||||
p = lmalloc(size);
|
||||
#else
|
||||
if (size < (size_t) -1)
|
||||
p = malloc((size_t) size);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_hfree) (acc_hvoid_p p)
|
||||
{
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
#if 0 && defined(__palmos__)
|
||||
MemPtrFree(p);
|
||||
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
|
||||
free(p);
|
||||
#else
|
||||
#if (__ACCLIB_HALLOC_USE_DAH)
|
||||
if (ACC_FP_OFF(p) == 0)
|
||||
DosFreeSeg((unsigned short) ACC_FP_SEG(p));
|
||||
#elif (__ACCLIB_HALLOC_USE_GA)
|
||||
if (ACC_FP_OFF(p) == 0) {
|
||||
const void __near* h = (const void __near*) (unsigned) GlobalHandle(ACC_FP_SEG(p));
|
||||
if (h) {
|
||||
GlobalUnlock(h);
|
||||
GlobalFree(h);
|
||||
}
|
||||
}
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 700))
|
||||
_hfree(p);
|
||||
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
|
||||
hfree(p);
|
||||
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
|
||||
farfree((void __far*) p);
|
||||
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
farfree((void __far*) p);
|
||||
#elif defined(ACC_CC_AZTECC)
|
||||
lfree(p);
|
||||
#else
|
||||
free(p);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,114 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_HFREAD_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// huge pointer layer - stdio.h
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hfread) (ACC_FILE_P fp, acc_hvoid_p buf, acc_hsize_t size)
|
||||
{
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
#if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
#define __ACCLIB_REQUIRE_HMEMCPY_CH 1
|
||||
unsigned char tmp[512];
|
||||
acc_hsize_t l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l);
|
||||
n = fread(tmp, 1, n, fp);
|
||||
if (n == 0)
|
||||
break;
|
||||
__ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
|
||||
l += n;
|
||||
}
|
||||
return l;
|
||||
#elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
|
||||
acc_hbyte_p b = (acc_hbyte_p) buf;
|
||||
acc_hsize_t l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
size_t n;
|
||||
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
|
||||
if ((acc_hsize_t) n > size - l)
|
||||
n = (size_t) (size - l);
|
||||
n = fread((void __far*)b, 1, n, fp);
|
||||
if (n == 0)
|
||||
break;
|
||||
b += n; l += n;
|
||||
}
|
||||
return l;
|
||||
#else
|
||||
# error "unknown memory model"
|
||||
#endif
|
||||
#else
|
||||
return fread(buf, 1, size, fp);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hfwrite) (ACC_FILE_P fp, const acc_hvoid_p buf, acc_hsize_t size)
|
||||
{
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
#if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
#define __ACCLIB_REQUIRE_HMEMCPY_CH 1
|
||||
unsigned char tmp[512];
|
||||
acc_hsize_t l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
size_t n = size - l > sizeof(tmp) ? sizeof(tmp) : (size_t) (size - l);
|
||||
__ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
|
||||
n = fwrite(tmp, 1, n, fp);
|
||||
if (n == 0)
|
||||
break;
|
||||
l += n;
|
||||
}
|
||||
return l;
|
||||
#elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) buf;
|
||||
acc_hsize_t l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
size_t n;
|
||||
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
|
||||
if ((acc_hsize_t) n > size - l)
|
||||
n = (size_t) (size - l);
|
||||
n = fwrite((void __far*)b, 1, n, fp);
|
||||
if (n == 0)
|
||||
break;
|
||||
b += n; l += n;
|
||||
}
|
||||
return l;
|
||||
#else
|
||||
# error "unknown memory model"
|
||||
#endif
|
||||
#else
|
||||
return fwrite(buf, 1, size, fp);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,111 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_HMEMCPY_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// memcmp, memcpy, memmove, memset
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_hmemcmp) (const acc_hvoid_p s1, const acc_hvoid_p s2, acc_hsize_t len)
|
||||
{
|
||||
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCMP)
|
||||
const acc_hbyte_p p1 = (const acc_hbyte_p) s1;
|
||||
const acc_hbyte_p p2 = (const acc_hbyte_p) s2;
|
||||
|
||||
if (len > 0) do
|
||||
{
|
||||
int d = *p1 - *p2;
|
||||
if (d != 0)
|
||||
return d;
|
||||
p1++; p2++;
|
||||
} while (--len > 0);
|
||||
return 0;
|
||||
#else
|
||||
return memcmp(s1, s2, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemcpy) (acc_hvoid_p dest, const acc_hvoid_p src, acc_hsize_t len)
|
||||
{
|
||||
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCPY)
|
||||
acc_hbyte_p p1 = (acc_hbyte_p) dest;
|
||||
const acc_hbyte_p p2 = (const acc_hbyte_p) src;
|
||||
|
||||
if (len <= 0 || p1 == p2)
|
||||
return dest;
|
||||
do
|
||||
*p1++ = *p2++;
|
||||
while (--len > 0);
|
||||
return dest;
|
||||
#else
|
||||
return memcpy(dest, src, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemmove) (acc_hvoid_p dest, const acc_hvoid_p src, acc_hsize_t len)
|
||||
{
|
||||
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMMOVE)
|
||||
acc_hbyte_p p1 = (acc_hbyte_p) dest;
|
||||
const acc_hbyte_p p2 = (const acc_hbyte_p) src;
|
||||
|
||||
if (len <= 0 || p1 == p2)
|
||||
return dest;
|
||||
|
||||
if (p1 < p2)
|
||||
{
|
||||
do
|
||||
*p1++ = *p2++;
|
||||
while (--len > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
p1 += len;
|
||||
p2 += len;
|
||||
do
|
||||
*--p1 = *--p2;
|
||||
while (--len > 0);
|
||||
}
|
||||
return dest;
|
||||
#else
|
||||
return memmove(dest, src, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemset) (acc_hvoid_p s, int c, acc_hsize_t len)
|
||||
{
|
||||
#if (ACC_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMSET)
|
||||
acc_hbyte_p p = (acc_hbyte_p) s;
|
||||
|
||||
if (len > 0) do
|
||||
*p++ = (unsigned char) c;
|
||||
while (--len > 0);
|
||||
return s;
|
||||
#else
|
||||
return memset(s, c, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,118 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_HREAD_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// huge pointer layer - read/write
|
||||
************************************************************************/
|
||||
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
|
||||
ACCLIB_PUBLIC(long, acc_hread) (int fd, acc_hvoid_p buf, long size)
|
||||
{
|
||||
#if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
#define __ACCLIB_REQUIRE_HMEMCPY_CH 1
|
||||
unsigned char tmp[512];
|
||||
long l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l);
|
||||
n = read(fd, tmp, n);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0)
|
||||
return -1;
|
||||
__ACCLIB_FUNCNAME(acc_hmemcpy)((acc_hbyte_p)buf + l, tmp, (acc_hsize_t)n);
|
||||
l += n;
|
||||
}
|
||||
return l;
|
||||
#elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
|
||||
acc_hbyte_p b = (acc_hbyte_p) buf;
|
||||
long l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
unsigned n;
|
||||
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
|
||||
if ((long) n > size - l)
|
||||
n = (unsigned) (size - l);
|
||||
n = read(fd, (void __far*)b, n);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n == (unsigned)-1)
|
||||
return -1;
|
||||
b += n; l += n;
|
||||
}
|
||||
return l;
|
||||
#else
|
||||
# error "unknown memory model"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(long, acc_hwrite) (int fd, const acc_hvoid_p buf, long size)
|
||||
{
|
||||
#if (ACC_MM_TINY || ACC_MM_SMALL || ACC_MM_MEDIUM)
|
||||
#define __ACCLIB_REQUIRE_HMEMCPY_CH 1
|
||||
unsigned char tmp[512];
|
||||
long l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
int n = size - l > (long)sizeof(tmp) ? (int) sizeof(tmp) : (int) (size - l);
|
||||
__ACCLIB_FUNCNAME(acc_hmemcpy)(tmp, (const acc_hbyte_p)buf + l, (acc_hsize_t)n);
|
||||
n = write(fd, tmp, n);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0)
|
||||
return -1;
|
||||
l += n;
|
||||
}
|
||||
return l;
|
||||
#elif (ACC_MM_COMPACT || ACC_MM_LARGE || ACC_MM_HUGE)
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) buf;
|
||||
long l = 0;
|
||||
|
||||
while (l < size)
|
||||
{
|
||||
unsigned n;
|
||||
n = ACC_FP_OFF(b); n = (n <= 1) ? 0x8000u : (0u - n);
|
||||
if ((long) n > size - l)
|
||||
n = (unsigned) (size - l);
|
||||
n = write(fd, (void __far*)b, n);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n == (unsigned)-1)
|
||||
return -1;
|
||||
b += n; l += n;
|
||||
}
|
||||
return l;
|
||||
#else
|
||||
# error "unknown memory model"
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* #if (ACC_HAVE_MM_HUGE_PTR) */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,97 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_HSREAD_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// huge pointer layer - safe read/write
|
||||
// handles partial pipe writes and interrupted system calls
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(long, acc_safe_hread) (int fd, acc_hvoid_p buf, long size)
|
||||
{
|
||||
acc_hbyte_p b = (acc_hbyte_p) buf;
|
||||
long l = 0;
|
||||
int saved_errno;
|
||||
|
||||
saved_errno = errno;
|
||||
while (l < size)
|
||||
{
|
||||
long n = size - l;
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
# define __ACCLIB_REQUIRE_HREAD_CH 1
|
||||
errno = 0; n = acc_hread(fd, b, n);
|
||||
#elif (ACC_OS_DOS32) && defined(__DJGPP__)
|
||||
errno = 0; n = _read(fd, b, n);
|
||||
#else
|
||||
errno = 0; n = read(fd, b, n);
|
||||
#endif
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
#if defined(EINTR)
|
||||
if (errno == (EINTR)) continue;
|
||||
#endif
|
||||
if (errno == 0) errno = 1;
|
||||
return l;
|
||||
}
|
||||
b += n; l += n;
|
||||
}
|
||||
errno = saved_errno;
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(long, acc_safe_hwrite) (int fd, const acc_hvoid_p buf, long size)
|
||||
{
|
||||
const acc_hbyte_p b = (const acc_hbyte_p) buf;
|
||||
long l = 0;
|
||||
int saved_errno;
|
||||
|
||||
saved_errno = errno;
|
||||
while (l < size)
|
||||
{
|
||||
long n = size - l;
|
||||
#if (ACC_HAVE_MM_HUGE_PTR)
|
||||
# define __ACCLIB_REQUIRE_HREAD_CH 1
|
||||
errno = 0; n = acc_hwrite(fd, b, n);
|
||||
#elif (ACC_OS_DOS32) && defined(__DJGPP__)
|
||||
errno = 0; n = _write(fd, b, n);
|
||||
#else
|
||||
errno = 0; n = write(fd, b, n);
|
||||
#endif
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
#if defined(EINTR)
|
||||
if (errno == (EINTR)) continue;
|
||||
#endif
|
||||
if (errno == 0) errno = 1;
|
||||
return l;
|
||||
}
|
||||
b += n; l += n;
|
||||
}
|
||||
errno = saved_errno;
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,566 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_HSTRING_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strlen
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hstrlen) (const acc_hchar_p s)
|
||||
{
|
||||
/* TODO: which one is the fastest generic version? */
|
||||
#if 1
|
||||
const acc_hchar_p start = s; while (*s) ++s;
|
||||
return (acc_hsize_t) (s - start);
|
||||
#elif 1
|
||||
acc_hsize_t n = 0; while (*s) ++s, ++n; return n;
|
||||
#elif 1
|
||||
acc_hsize_t n = 0; while (s[n]) ++n; return n;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strcmp, strncmp, ascii_stricmp, ascii_strnicmp, ascii_memicmp
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_hstrcmp) (const acc_hchar_p p, const acc_hchar_p s)
|
||||
{
|
||||
for ( ; *p; ++p, ++s) {
|
||||
if (*p != *s)
|
||||
break;
|
||||
}
|
||||
return (unsigned char)*p - (unsigned char)*s;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_hstrncmp) (const acc_hchar_p p, const acc_hchar_p s, acc_hsize_t n)
|
||||
{
|
||||
for ( ; *p && n > 0; ++p, ++s, --n) {
|
||||
if (*p != *s)
|
||||
break;
|
||||
}
|
||||
return (unsigned char)*p - (unsigned char)*s;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_ascii_hstricmp) (const acc_hchar_p p, const acc_hchar_p s)
|
||||
{
|
||||
for ( ; *p; ++p, ++s) {
|
||||
if (*p != *s) {
|
||||
int d = acc_ascii_utolower(*p) - acc_ascii_utolower(*s);
|
||||
if (d != 0)
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return acc_ascii_utolower(*p) - acc_ascii_utolower(*s);
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_ascii_hstrnicmp) (const acc_hchar_p p, const acc_hchar_p s, acc_hsize_t n)
|
||||
{
|
||||
for ( ; *p && n > 0; ++p, ++s, --n) {
|
||||
if (*p != *s) {
|
||||
int d = acc_ascii_utolower(*p) - acc_ascii_utolower(*s);
|
||||
if (d != 0)
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return acc_ascii_utolower(*p) - acc_ascii_utolower(*s);
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_ascii_hmemicmp) (const acc_hvoid_p pp, const acc_hvoid_p ss, acc_hsize_t n)
|
||||
{
|
||||
const acc_hbyte_p p = (const acc_hbyte_p) pp;
|
||||
const acc_hbyte_p s = (const acc_hbyte_p) ss;
|
||||
for ( ; n > 0; ++p, ++s, --n) {
|
||||
if (*p != *s) {
|
||||
int d = acc_ascii_utolower(*p) - acc_ascii_utolower(*s);
|
||||
if (d != 0)
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return acc_ascii_utolower(*p) - acc_ascii_utolower(*s);
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strstr, ascii_stristr, memmem, ascii_memimem
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrstr) (const acc_hchar_p p, const acc_hchar_p s)
|
||||
{
|
||||
acc_hsize_t pn = __ACCLIB_FUNCNAME(acc_hstrlen)(p);
|
||||
acc_hsize_t sn = __ACCLIB_FUNCNAME(acc_hstrlen)(s);
|
||||
return (acc_hchar_p) __ACCLIB_FUNCNAME(acc_hmemmem)(p, pn, s, sn);
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_ascii_hstristr) (const acc_hchar_p p, const acc_hchar_p s)
|
||||
{
|
||||
acc_hsize_t pn = __ACCLIB_FUNCNAME(acc_hstrlen)(p);
|
||||
acc_hsize_t sn = __ACCLIB_FUNCNAME(acc_hstrlen)(s);
|
||||
return (acc_hchar_p) __ACCLIB_FUNCNAME(acc_ascii_hmemimem)(p, pn, s, sn);
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemmem) (const acc_hvoid_p p, acc_hsize_t pn, const acc_hvoid_p s, acc_hsize_t sn)
|
||||
{
|
||||
#define __ACCLIB_REQUIRE_HMEMCPY_CH 1
|
||||
if (sn == 0) __ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
for ( ; pn >= sn; --pn) {
|
||||
if (__ACCLIB_FUNCNAME(acc_hmemcmp)(p, s, sn) == 0)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
p = (const acc_hbyte_p)p + 1;
|
||||
}
|
||||
return (acc_hvoid_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_ascii_hmemimem) (const acc_hvoid_p p, acc_hsize_t pn, const acc_hvoid_p s, acc_hsize_t sn)
|
||||
{
|
||||
if (sn == 0) __ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
for ( ; pn >= sn; --pn) {
|
||||
if (__ACCLIB_FUNCNAME(acc_ascii_hmemicmp)(p, s, sn) == 0)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
p = (const acc_hbyte_p)p + 1;
|
||||
}
|
||||
return (acc_hvoid_p) 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strcpy, strcat
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrcpy) (acc_hchar_p d, const acc_hchar_p s)
|
||||
{
|
||||
acc_hchar_p dest = d;
|
||||
while ((*d = *s) != 0) {
|
||||
++d; ++s;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrcat) (acc_hchar_p d, const acc_hchar_p s)
|
||||
{
|
||||
acc_hchar_p dest = d;
|
||||
while (*d) ++d;
|
||||
while ((*d = *s) != 0) {
|
||||
++d; ++s;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strlcpy, strlcat
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hstrlcpy) (acc_hchar_p d, const acc_hchar_p s, acc_hsize_t size)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
if (n != size) {
|
||||
do {
|
||||
if ((*d = *s) == 0) return n;
|
||||
++d; ++s; ++n;
|
||||
} while (n != size);
|
||||
d[-1] = 0;
|
||||
}
|
||||
while (*s) ++s, ++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hstrlcat) (acc_hchar_p d, const acc_hchar_p s, acc_hsize_t size)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
while (*d && n != size) ++d, ++n;
|
||||
if (n != size) {
|
||||
do {
|
||||
if ((*d = *s) == 0) return n;
|
||||
++d; ++s; ++n;
|
||||
} while (n != size);
|
||||
d[-1] = 0;
|
||||
}
|
||||
while (*s) ++s, ++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strscpy, strscat
|
||||
// (same as strlcpy/strlcat, but just return -1 in case of failure)
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_hstrscpy) (acc_hchar_p d, const acc_hchar_p s, acc_hsize_t size)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
if (n != size) {
|
||||
do {
|
||||
if ((*d = *s) == 0) return 0;
|
||||
++d; ++s; ++n;
|
||||
} while (n != size);
|
||||
d[-1] = 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_hstrscat) (acc_hchar_p d, const acc_hchar_p s, acc_hsize_t size)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
while (*d && n != size) ++d, ++n;
|
||||
if (n != size) {
|
||||
do {
|
||||
if ((*d = *s) == 0) return 0;
|
||||
++d; ++s; ++n;
|
||||
} while (n != size);
|
||||
d[-1] = 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strccpy, memccpy
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrccpy) (acc_hchar_p d, const acc_hchar_p s, int c)
|
||||
{
|
||||
for (;;) {
|
||||
if ((*d = *s) == 0) break;
|
||||
if (*d++ == (char) c) return d;
|
||||
++s;
|
||||
}
|
||||
return (acc_hchar_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemccpy) (acc_hvoid_p d, const acc_hvoid_p s, int c, acc_hsize_t n)
|
||||
{
|
||||
acc_hbyte_p a = (acc_hbyte_p) d;
|
||||
const acc_hbyte_p p = (const acc_hbyte_p) s;
|
||||
const acc_hbyte_p e = (const acc_hbyte_p) s + n;
|
||||
while (p != e) {
|
||||
if ((*a++ = *p++) == (unsigned char) c)
|
||||
return a;
|
||||
}
|
||||
return (acc_hvoid_p) 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strchr, strrchr, ascii_strichr, ascii_strrichr
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrchr) (const acc_hchar_p s, int c)
|
||||
{
|
||||
for ( ; *s; ++s) {
|
||||
if (*s == (char) c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
}
|
||||
if ((char) c == 0) __ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
return (acc_hchar_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrrchr) (const acc_hchar_p s, int c)
|
||||
{
|
||||
const acc_hchar_p start = s;
|
||||
while (*s) ++s;
|
||||
if ((char) c == 0) __ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
for (;;) {
|
||||
if (s == start) break; --s;
|
||||
if (*s == (char) c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
}
|
||||
return (acc_hchar_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_ascii_hstrichr) (const acc_hchar_p s, int c)
|
||||
{
|
||||
c = acc_ascii_utolower(c);
|
||||
for ( ; *s; ++s) {
|
||||
if (acc_ascii_utolower(*s) == c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
}
|
||||
if (c == 0) __ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
return (acc_hchar_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_ascii_hstrrichr) (const acc_hchar_p s, int c)
|
||||
{
|
||||
const acc_hchar_p start = s;
|
||||
c = acc_ascii_utolower(c);
|
||||
while (*s) ++s;
|
||||
if (c == 0) __ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
for (;;) {
|
||||
if (s == start) break; --s;
|
||||
if (acc_ascii_utolower(*s) == c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
}
|
||||
return (acc_hchar_p) 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// memchr, memrchr, ascii_memichr, ascii_memrichr
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemchr) (const acc_hvoid_p s, int c, acc_hsize_t n)
|
||||
{
|
||||
const acc_hbyte_p p = (const acc_hbyte_p) s;
|
||||
const acc_hbyte_p e = (const acc_hbyte_p) s + n;
|
||||
while (p != e) {
|
||||
if (*p == (unsigned char) c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
++p;
|
||||
}
|
||||
return (acc_hvoid_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_hmemrchr) (const acc_hvoid_p s, int c, acc_hsize_t n)
|
||||
{
|
||||
const acc_hbyte_p p = (const acc_hbyte_p) s + n;
|
||||
const acc_hbyte_p e = (const acc_hbyte_p) s;
|
||||
while (p != e) {
|
||||
--p;
|
||||
if (*p == (unsigned char) c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
}
|
||||
return (acc_hvoid_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_ascii_hmemichr) (const acc_hvoid_p s, int c, acc_hsize_t n)
|
||||
{
|
||||
const acc_hbyte_p p = (const acc_hbyte_p) s;
|
||||
const acc_hbyte_p e = (const acc_hbyte_p) s + n;
|
||||
c = acc_ascii_utolower(c);
|
||||
while (p != e) {
|
||||
if (acc_ascii_utolower(*p) == c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
++p;
|
||||
}
|
||||
return (acc_hvoid_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_ascii_hmemrichr) (const acc_hvoid_p s, int c, acc_hsize_t n)
|
||||
{
|
||||
const acc_hbyte_p p = (const acc_hbyte_p) s + n;
|
||||
const acc_hbyte_p e = (const acc_hbyte_p) s;
|
||||
c = acc_ascii_utolower(c);
|
||||
while (p != e) {
|
||||
--p;
|
||||
if (acc_ascii_utolower(*p) == c)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hvoid_p, p)
|
||||
}
|
||||
return (acc_hvoid_p) 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strspn, strrspn
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hstrspn) (const acc_hchar_p s, const acc_hchar_p accept)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
for ( ; *s; ++s) {
|
||||
const acc_hchar_p a;
|
||||
for (a = accept; *a; ++a)
|
||||
if (*s == *a)
|
||||
goto acc_label_next;
|
||||
break;
|
||||
acc_label_next:
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hstrrspn) (const acc_hchar_p s, const acc_hchar_p accept)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
const acc_hchar_p start = s;
|
||||
while (*s) ++s;
|
||||
for (;;) {
|
||||
const acc_hchar_p a;
|
||||
if (s == start) break; --s;
|
||||
for (a = accept; *a; ++a)
|
||||
if (*s == *a)
|
||||
goto acc_label_next;
|
||||
break;
|
||||
acc_label_next:
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strcspn, strrcspn
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hstrcspn) (const acc_hchar_p s, const acc_hchar_p reject)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
for ( ; *s; ++s, ++n) {
|
||||
const acc_hchar_p r;
|
||||
for (r = reject; *r; ++r)
|
||||
if (*s == *r)
|
||||
return n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hsize_t, acc_hstrrcspn) (const acc_hchar_p s, const acc_hchar_p reject)
|
||||
{
|
||||
acc_hsize_t n = 0;
|
||||
const acc_hchar_p start = s;
|
||||
while (*s) ++s;
|
||||
for ( ; ; ++n) {
|
||||
const acc_hchar_p r;
|
||||
if (s == start) break; --s;
|
||||
for (r = reject; *r; ++r)
|
||||
if (*s == *r)
|
||||
return n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strpbrk, strrpbrk
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrpbrk) (const acc_hchar_p s, const acc_hchar_p accept)
|
||||
{
|
||||
for ( ; *s; ++s) {
|
||||
const acc_hchar_p a;
|
||||
for (a = accept; *a; ++a) {
|
||||
if (*s == *a)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
}
|
||||
}
|
||||
return (acc_hchar_p) 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrrpbrk) (const acc_hchar_p s, const acc_hchar_p accept)
|
||||
{
|
||||
const acc_hchar_p start = s;
|
||||
while (*s) ++s;
|
||||
for (;;) {
|
||||
const acc_hchar_p a;
|
||||
if (s == start) break; --s;
|
||||
for (a = accept; *a; ++a) {
|
||||
if (*s == *a)
|
||||
__ACCLIB_CONST_CAST_RETURN(acc_hchar_p, s)
|
||||
}
|
||||
}
|
||||
return (acc_hchar_p) 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// strsep, strrsep
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrsep) (acc_hchar_pp ss, const acc_hchar_p delim)
|
||||
{
|
||||
acc_hchar_p s = *ss;
|
||||
if (s) {
|
||||
acc_hchar_p p = __ACCLIB_FUNCNAME(acc_hstrpbrk)(s, delim);
|
||||
if (p) *p++ = 0;
|
||||
*ss = p;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_hstrrsep) (acc_hchar_pp ss, const acc_hchar_p delim)
|
||||
{
|
||||
acc_hchar_p s = *ss;
|
||||
if (s) {
|
||||
acc_hchar_p p = __ACCLIB_FUNCNAME(acc_hstrrpbrk)(s, delim);
|
||||
if (p) {
|
||||
*p++ = 0;
|
||||
return p;
|
||||
}
|
||||
*ss = (acc_hchar_p) 0;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// ascii_strlwr, ascii_strupr, ascii_memlwr, ascii_memupr
|
||||
************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_ascii_hstrlwr) (acc_hchar_p s)
|
||||
{
|
||||
acc_hbyte_p p = (acc_hbyte_p) s;
|
||||
for ( ; *p; ++p)
|
||||
*p = (unsigned char) acc_ascii_utolower(*p);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hchar_p, acc_ascii_hstrupr) (acc_hchar_p s)
|
||||
{
|
||||
acc_hbyte_p p = (acc_hbyte_p) s;
|
||||
for ( ; *p; ++p)
|
||||
*p = (unsigned char) acc_ascii_utoupper(*p);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_ascii_hmemlwr) (acc_hvoid_p s, acc_hsize_t n)
|
||||
{
|
||||
acc_hbyte_p p = (acc_hbyte_p) s;
|
||||
acc_hbyte_p e = (acc_hbyte_p) s + n;
|
||||
for ( ; p != e; ++p)
|
||||
*p = (unsigned char) acc_ascii_utolower(*p);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_hvoid_p, acc_ascii_hmemupr) (acc_hvoid_p s, acc_hsize_t n)
|
||||
{
|
||||
acc_hbyte_p p = (acc_hbyte_p) s;
|
||||
acc_hbyte_p e = (acc_hbyte_p) s + n;
|
||||
for ( ; p != e; ++p)
|
||||
*p = (unsigned char) acc_ascii_utoupper(*p);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,199 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_MISC_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// wrap misc
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(acclib_handle_t, acc_get_osfhandle) (int fd)
|
||||
{
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
#if (ACC_OS_CYGWIN)
|
||||
return get_osfhandle(fd);
|
||||
#elif (ACC_OS_EMX && defined(__RSXNT__))
|
||||
return -1; /* FIXME */
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
return -1; /* FIXME */
|
||||
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# if (ACC_CC_PELLESC && (__POCC__ < 280))
|
||||
return -1; /* FIXME */
|
||||
# elif (ACC_CC_WATCOMC && (__WATCOMC__ < 1000))
|
||||
return -1; /* FIXME */
|
||||
# elif (ACC_CC_WATCOMC && (__WATCOMC__ < 1100))
|
||||
return _os_handle(fd);
|
||||
# else
|
||||
return _get_osfhandle(fd);
|
||||
# endif
|
||||
#else
|
||||
return fd;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_set_binmode) (int fd, int binary)
|
||||
{
|
||||
#if (ACC_OS_TOS && defined(__MINT__))
|
||||
FILE* fp; int old_binary;
|
||||
if (fd == STDIN_FILENO) fp = stdin;
|
||||
else if (fd == STDOUT_FILENO) fp = stdout;
|
||||
else if (fd == STDERR_FILENO) fp = stderr;
|
||||
else return -1;
|
||||
old_binary = fp->__mode.__binary;
|
||||
__set_binmode(fp, binary ? 1 : 0);
|
||||
return old_binary ? 1 : 0;
|
||||
#elif (ACC_OS_TOS)
|
||||
ACC_UNUSED(fd); ACC_UNUSED(binary);
|
||||
return -1; /* FIXME */
|
||||
#elif (ACC_OS_DOS16 && (ACC_CC_AZTECC || ACC_CC_PACIFICC))
|
||||
ACC_UNUSED(fd); ACC_UNUSED(binary);
|
||||
return -1; /* FIXME */
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
int r; unsigned old_flags = __djgpp_hwint_flags;
|
||||
ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
|
||||
ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
|
||||
if (fd < 0) return -1;
|
||||
r = setmode(fd, binary ? O_BINARY : O_TEXT);
|
||||
if ((old_flags & 1u) != (__djgpp_hwint_flags & 1u))
|
||||
__djgpp_set_ctrl_c(!(old_flags & 1));
|
||||
if (r == -1) return -1;
|
||||
return (r & O_TEXT) ? 0 : 1;
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
if (fd < 0) return -1;
|
||||
ACC_UNUSED(binary);
|
||||
return 1;
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_HIGHC)
|
||||
FILE* fp; int r;
|
||||
if (fd == fileno(stdin)) fp = stdin;
|
||||
else if (fd == fileno(stdout)) fp = stdout;
|
||||
else if (fd == fileno(stderr)) fp = stderr;
|
||||
else return -1;
|
||||
r = _setmode(fp, binary ? _BINARY : _TEXT);
|
||||
if (r == -1) return -1;
|
||||
return (r & _BINARY) ? 1 : 0;
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
ACC_UNUSED(fd); ACC_UNUSED(binary);
|
||||
return -1; /* FIXME */
|
||||
#elif (ACC_OS_CYGWIN && (ACC_CC_GNUC < 0x025a00ul))
|
||||
ACC_UNUSED(fd); ACC_UNUSED(binary);
|
||||
return -1; /* FIXME */
|
||||
#elif (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
int r;
|
||||
#if !defined(ACC_CC_ZORTECHC)
|
||||
ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
|
||||
#endif
|
||||
ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
|
||||
if (fd < 0) return -1;
|
||||
r = setmode(fd, binary ? O_BINARY : O_TEXT);
|
||||
if (r == -1) return -1;
|
||||
return (r & O_TEXT) ? 0 : 1;
|
||||
#else
|
||||
if (fd < 0) return -1;
|
||||
ACC_UNUSED(binary);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_isatty) (int fd)
|
||||
{
|
||||
/* work around library implementations that think that
|
||||
* any character device like `nul' is a tty */
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
#if (ACC_OS_DOS16 && !defined(ACC_CC_AZTECC))
|
||||
{
|
||||
union REGS ri, ro;
|
||||
ri.x.ax = 0x4400; ri.x.bx = fd;
|
||||
int86(0x21, &ri, &ro);
|
||||
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
|
||||
if ((ro.x.ax & 0x83) != 0x83)
|
||||
return 0;
|
||||
}
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_WATCOMC)
|
||||
{
|
||||
union REGS ri, ro;
|
||||
ri.w.ax = 0x4400; ri.w.bx = (unsigned short) fd;
|
||||
int386(0x21, &ri, &ro);
|
||||
if ((ro.w.cflag & 1) == 0) /* if carry flag not set */
|
||||
if ((ro.w.ax & 0x83) != 0x83)
|
||||
return 0;
|
||||
}
|
||||
#elif (ACC_HAVE_WINDOWS_H)
|
||||
{
|
||||
acclib_handle_t h = __ACCLIB_FUNCNAME(acc_get_osfhandle)(fd);
|
||||
if ((HANDLE)h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD d = 0;
|
||||
if (GetConsoleMode((HANDLE)h, &d) == 0)
|
||||
return 0; /* GetConsoleMode failed -> not a tty */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return (isatty(fd)) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_mkdir) (const char* name, unsigned mode)
|
||||
{
|
||||
#if (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
|
||||
ACC_UNUSED(mode);
|
||||
return Dcreate(name);
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
return mkdir(name, mode);
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
return mkdir(name, mode);
|
||||
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
ACC_UNUSED(mode);
|
||||
# if (ACC_CC_HIGHC || ACC_CC_PACIFICC)
|
||||
return mkdir((char*) name);
|
||||
# else
|
||||
return mkdir(name);
|
||||
# endif
|
||||
#else
|
||||
return mkdir(name, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_int32l_t, acc_muldiv32) (acc_int32l_t a, acc_int32l_t b, acc_int32l_t x)
|
||||
{
|
||||
acc_int32l_t r = 0;
|
||||
if (x == 0) return x;
|
||||
/* FIXME */
|
||||
ACC_UNUSED(a); ACC_UNUSED(b);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_umuldiv32) (acc_uint32l_t a, acc_uint32l_t b, acc_uint32l_t x)
|
||||
{
|
||||
acc_uint32l_t r = 0;
|
||||
if (x == 0) return x;
|
||||
/* FIXME */
|
||||
ACC_UNUSED(a); ACC_UNUSED(b);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,255 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_OPENDIR_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// wrap <dirent.h>
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(__ACCLIB_USE_OPENDIR)
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
|
||||
static int __ACCLIB_FUNCNAME(acc_opendir_init)(acc_dir_p f, const char* path, char* buf, size_t bufsize)
|
||||
{
|
||||
size_t l; char* p;
|
||||
f->f_name[0] = 0; buf[0] = 0;
|
||||
l = strlen(path);
|
||||
if (l == 0 || bufsize <= 4 || l >= bufsize - 4)
|
||||
return -1;
|
||||
strcpy(buf, path); p = buf + l;
|
||||
if (p[-1] == ':' || p[-1] == '\\' || p[-1] == '/')
|
||||
strcpy(p, "*.*");
|
||||
else
|
||||
strcpy(p, "\\*.*");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__ACCLIB_USE_OPENDIR)
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
|
||||
{
|
||||
f->u_dirp = opendir(path);
|
||||
if (!f->u_dirp)
|
||||
return -2;
|
||||
return __ACCLIB_FUNCNAME(acc_readdir)(f);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
|
||||
{
|
||||
const struct dirent* dp;
|
||||
f->f_name[0] = 0;
|
||||
if (!f->u_dirp)
|
||||
return -1;
|
||||
dp = (const struct dirent*) readdir((DIR*) f->u_dirp);
|
||||
if (!dp)
|
||||
return -1;
|
||||
if (!dp->d_name[0] || strlen(dp->d_name) >= sizeof(f->f_name))
|
||||
return -1;
|
||||
strcpy(f->f_name, dp->d_name);
|
||||
#if (ACC_CC_WATCOMC)
|
||||
ACC_COMPILE_TIME_ASSERT(sizeof(f->f_name) >= sizeof(dp->d_name))
|
||||
f->f_time = dp->d_time;
|
||||
f->f_date = dp->d_date;
|
||||
f->f_size = dp->d_size;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
|
||||
{
|
||||
int r = -1;
|
||||
if (f->u_dirp)
|
||||
r = closedir((DIR*) f->u_dirp);
|
||||
f->u_dirp = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
|
||||
{
|
||||
WIN32_FIND_DATAA d;
|
||||
HANDLE h;
|
||||
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, f->f_name, sizeof(f->f_name)) != 0)
|
||||
return -1;
|
||||
h = FindFirstFileA(f->f_name, &d);
|
||||
f->f_name[0] = 0;
|
||||
if ((f->u_handle = (acclib_handle_t) h) == -1)
|
||||
return -1;
|
||||
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
|
||||
return -1;
|
||||
strcpy(f->f_name, d.cFileName);
|
||||
f->f_attr = d.dwFileAttributes;
|
||||
f->f_size_high = d.nFileSizeHigh;
|
||||
f->f_size_low = d.nFileSizeLow;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
|
||||
{
|
||||
WIN32_FIND_DATAA d;
|
||||
f->f_name[0] = 0;
|
||||
if (f->u_handle == -1 || FindNextFileA((HANDLE) f->u_handle, &d) == 0)
|
||||
return -1;
|
||||
if (!d.cFileName[0] || strlen(d.cFileName) >= sizeof(f->f_name))
|
||||
return -1;
|
||||
strcpy(f->f_name, d.cFileName);
|
||||
f->f_attr = d.dwFileAttributes;
|
||||
f->f_size_high = d.nFileSizeHigh;
|
||||
f->f_size_low = d.nFileSizeLow;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
|
||||
{
|
||||
int r = -1;
|
||||
if (f->u_handle != -1)
|
||||
r = FindClose((HANDLE) f->u_handle);
|
||||
f->u_handle = -1;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_WIN16)
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
|
||||
{
|
||||
char tmp[ACC_FN_PATH_MAX+1];
|
||||
int r;
|
||||
f->u_dirp = 0;
|
||||
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
|
||||
return -1;
|
||||
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
|
||||
r = -1;
|
||||
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
r = findfirst(tmp, (struct ffblk*) f->u_dta, FA_HIDDEN|FA_SYSTEM|FA_RDONLY|FA_DIREC);
|
||||
#else
|
||||
r = _dos_findfirst(tmp, _A_HIDDEN|_A_SYSTEM|_A_RDONLY|_A_SUBDIR, (struct find_t*) f->u_dta);
|
||||
#endif
|
||||
if (r != 0) f->f_name[0] = 0;
|
||||
if (!f->f_name[0]) return -1;
|
||||
f->u_dirp = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
|
||||
{
|
||||
int r;
|
||||
f->f_name[0] = 0;
|
||||
if (!f->u_dirp)
|
||||
return -1;
|
||||
#if (ACC_CC_AZTECC || ACC_CC_PACIFICC)
|
||||
r = -1;
|
||||
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
|
||||
r = findnext((struct ffblk*) f->u_dta);
|
||||
#else
|
||||
r = _dos_findnext((struct find_t*) f->u_dta);
|
||||
#endif
|
||||
if (r != 0) f->f_name[0] = 0;
|
||||
if (!f->f_name[0]) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
|
||||
{
|
||||
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
|
||||
f->f_name[0] = 0;
|
||||
f->u_dirp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#elif (ACC_OS_TOS)
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
|
||||
{
|
||||
char tmp[ACC_FN_PATH_MAX+1];
|
||||
int r;
|
||||
DTA* olddta;
|
||||
f->u_dirp = 0;
|
||||
if (__ACCLIB_FUNCNAME(acc_opendir_init)(f, path, tmp, sizeof(tmp)) != 0)
|
||||
return -1;
|
||||
olddta = Fgetdta();
|
||||
Fsetdta((DTA*) f->u_dta);
|
||||
r = Fsfirst(tmp, FA_HIDDEN|FA_SYSTEM|FA_READONLY|FA_SUBDIR);
|
||||
Fsetdta(olddta);
|
||||
if (r != 0) f->f_name[0] = 0;
|
||||
if (!f->f_name[0]) return -1;
|
||||
f->u_dirp = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
|
||||
{
|
||||
int r;
|
||||
DTA* olddta;
|
||||
f->f_name[0] = 0;
|
||||
if (!f->u_dirp)
|
||||
return -1;
|
||||
olddta = Fgetdta();
|
||||
Fsetdta((DTA*) f->u_dta);
|
||||
r = Fsnext();
|
||||
Fsetdta(olddta);
|
||||
if (r != 0) f->f_name[0] = 0;
|
||||
if (!f->f_name[0]) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
|
||||
{
|
||||
ACC_COMPILE_TIME_ASSERT(sizeof(*f) == 44);
|
||||
f->f_name[0] = 0;
|
||||
f->u_dirp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_opendir) (acc_dir_p f, const char* path)
|
||||
{
|
||||
ACC_UNUSED(path);
|
||||
f->f_name[0] = 0;
|
||||
return -3;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_readdir) (acc_dir_p f)
|
||||
{
|
||||
f->f_name[0] = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_closedir) (acc_dir_p f)
|
||||
{
|
||||
f->u_dirp = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,135 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_RAND_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// some linear congruential pseudo random number generators (PRNG)
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_srand31) (acc_rand31_p r, acc_uint32l_t seed)
|
||||
{
|
||||
r->seed = seed & ACC_UINT32L_C(0xffffffff);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand31) (acc_rand31_p r)
|
||||
{
|
||||
r->seed = r->seed * ACC_UINT32L_C(1103515245) + 12345;
|
||||
r->seed &= ACC_UINT32L_C(0x7fffffff);
|
||||
return r->seed;
|
||||
}
|
||||
|
||||
|
||||
#if defined(acc_uint64l_t)
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_srand48) (acc_rand48_p r, acc_uint32l_t seed)
|
||||
{
|
||||
r->seed = seed & ACC_UINT32L_C(0xffffffff);
|
||||
r->seed <<= 16; r->seed |= 0x330e;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand48) (acc_rand48_p r)
|
||||
{
|
||||
r->seed = r->seed * ACC_UINT64L_C(25214903917) + 11;
|
||||
r->seed &= ACC_UINT64L_C(0xffffffffffff);
|
||||
return (acc_uint32l_t) (r->seed >> 17);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand48_r32) (acc_rand48_p r)
|
||||
{
|
||||
r->seed = r->seed * ACC_UINT64L_C(25214903917) + 11;
|
||||
r->seed &= ACC_UINT64L_C(0xffffffffffff);
|
||||
return (acc_uint32l_t) (r->seed >> 16);
|
||||
}
|
||||
|
||||
#endif /* acc_uint64l_t */
|
||||
|
||||
|
||||
#if defined(acc_uint64l_t)
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_srand64) (acc_rand64_p r, acc_uint64l_t seed)
|
||||
{
|
||||
r->seed = seed & ACC_UINT64L_C(0xffffffffffffffff);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand64) (acc_rand64_p r)
|
||||
{
|
||||
r->seed = r->seed * ACC_UINT64L_C(6364136223846793005) + 1;
|
||||
#if (SIZEOF_ACC_INT64L_T > 8)
|
||||
r->seed &= ACC_UINT64L_C(0xffffffffffffffff);
|
||||
#endif
|
||||
return (acc_uint32l_t) (r->seed >> 33);
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand64_r32) (acc_rand64_p r)
|
||||
{
|
||||
r->seed = r->seed * ACC_UINT64L_C(6364136223846793005) + 1;
|
||||
#if (SIZEOF_ACC_INT64L_T > 8)
|
||||
r->seed &= ACC_UINT64L_C(0xffffffffffffffff);
|
||||
#endif
|
||||
return (acc_uint32l_t) (r->seed >> 32);
|
||||
}
|
||||
|
||||
#endif /* acc_uint64l_t */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// mersenne twister PRNG
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_srandmt) (acc_randmt_p r, acc_uint32l_t seed)
|
||||
{
|
||||
unsigned i = 0;
|
||||
do {
|
||||
r->s[i++] = (seed &= ACC_UINT32L_C(0xffffffff));
|
||||
seed ^= seed >> 30;
|
||||
seed = seed * ACC_UINT32L_C(0x6c078965) + i;
|
||||
} while (i != 624);
|
||||
r->n = i;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_randmt) (acc_randmt_p r)
|
||||
{
|
||||
return (__ACCLIB_FUNCNAME(acc_randmt_r32)(r)) >> 1;
|
||||
}
|
||||
|
||||
ACCLIB_PUBLIC(acc_uint32l_t, acc_randmt_r32) (acc_randmt_p r)
|
||||
{
|
||||
acc_uint32l_t v;
|
||||
if (r->n == 624) {
|
||||
int i = 0, j;
|
||||
r->n = 0;
|
||||
do {
|
||||
j = i - 623; if (j < 0) j += 624;
|
||||
v = (r->s[i] & ACC_UINT32L_C(0x80000000)) ^ (r->s[j] & ACC_UINT32L_C(0x7fffffff));
|
||||
j = i - 227; if (j < 0) j += 624;
|
||||
r->s[i] = r->s[j] ^ (v >> 1);
|
||||
if (v & 1) r->s[i] ^= ACC_UINT32L_C(0x9908b0df);
|
||||
} while (++i != 624);
|
||||
}
|
||||
v = r->s[r->n++];
|
||||
v ^= v >> 11; v ^= (v & ACC_UINT32L_C(0x013a58ad)) << 7;
|
||||
v ^= (v & ACC_UINT32L_C(0x0001df8c)) << 15; v ^= v >> 18;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,116 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_RDTSC_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
#if defined(acc_int32e_t)
|
||||
|
||||
|
||||
#if ((ACC_ARCH_AMD64 || ACC_ARCH_IA32) && ACC_CC_GNUC)
|
||||
# if (ACC_CC_GNUC >= 0x020000ul)
|
||||
# define __ACCLIB_RDTSC_REGS : : "r" (t) : "cc", "memory", "eax", "edx"
|
||||
# else
|
||||
# define __ACCLIB_RDTSC_REGS : : "r" (t) : "ax", "dx"
|
||||
# endif
|
||||
#elif (ACC_ARCH_IA32 && ACC_CC_INTELC) && defined(__linux__)
|
||||
# define __ACCLIB_RDTSC_REGS : : "r" (t) : "memory", "eax", "edx"
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// read TSC
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_tsc_read) (acc_uint32e_t* t)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && defined(__ACCLIB_RDTSC_REGS)
|
||||
__asm__ __volatile__(
|
||||
"clc \n" ".byte 0x0f, 0x31\n"
|
||||
"movl %%eax,(%0)\n" "movl %%edx,4(%0)\n"
|
||||
__ACCLIB_RDTSC_REGS
|
||||
);
|
||||
return 0;
|
||||
#elif (ACC_ARCH_IA32 && (ACC_OS_DOS32 || ACC_OS_WIN32) && (ACC_CC_DMC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_PELLESC))
|
||||
ACC_UNUSED(t);
|
||||
__asm {
|
||||
mov ecx, t
|
||||
clc
|
||||
# if (ACC_CC_MSC && (_MSC_VER < 1200))
|
||||
_emit 0x0f
|
||||
_emit 0x31
|
||||
# else
|
||||
rdtsc
|
||||
# endif
|
||||
mov [ecx], eax
|
||||
mov [ecx+4], edx
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
t[0] = t[1] = 0;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// read and add TSC
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_tsc_read_add) (acc_uint32e_t* t)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && defined(__ACCLIB_RDTSC_REGS)
|
||||
__asm__ __volatile__(
|
||||
"clc \n" ".byte 0x0f, 0x31\n"
|
||||
"addl %%eax,(%0)\n" "adcl $0,%%edx\n" "addl %%edx,4(%0)\n"
|
||||
__ACCLIB_RDTSC_REGS
|
||||
);
|
||||
return 0;
|
||||
#elif (ACC_ARCH_IA32 && (ACC_OS_DOS32 || ACC_OS_WIN32) && (ACC_CC_DMC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_PELLESC))
|
||||
ACC_UNUSED(t);
|
||||
__asm {
|
||||
mov ecx, t
|
||||
clc
|
||||
# if (ACC_CC_MSC && (_MSC_VER < 1200))
|
||||
_emit 0x0f
|
||||
_emit 0x31
|
||||
# else
|
||||
rdtsc
|
||||
# endif
|
||||
add [ecx], eax
|
||||
adc edx, 0
|
||||
add [ecx+4], edx
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
acc_uint32e_t v[2];
|
||||
int r;
|
||||
r = acc_tsc_read(v);
|
||||
t[0] += v[0];
|
||||
if (t[0] < v[0]) t[1] += 1;
|
||||
t[1] += v[1];
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif /* defined(acc_int32e_t) */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,230 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_UCLOCK_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
#elif (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_HAVE_WINDOWS_H)
|
||||
# if defined(acc_int64l_t)
|
||||
/* See also: KB Q274323: PRB: Performance Counter Value May
|
||||
* Unexpectedly Leap Forward */
|
||||
# define __ACCLIB_UCLOCK_USE_QPC 1
|
||||
# endif
|
||||
/* fallbacks */
|
||||
# if ((ACC_CC_DMC && (__DMC__ < 0x838)) || ACC_CC_LCC)
|
||||
/* winmm.lib is missing */
|
||||
# define __ACCLIB_UCLOCK_USE_CLOCK 1
|
||||
# else
|
||||
# define __ACCLIB_UCLOCK_USE_WINMM 1
|
||||
# if (ACC_CC_MSC && (_MSC_VER >= 900))
|
||||
/* avoid `-W4' warnings in <mmsystem.h> */
|
||||
# pragma warning(disable: 4201)
|
||||
# elif (ACC_CC_MWERKS)
|
||||
/* avoid duplicate typedef in <mmsystem.h> */
|
||||
# define LPUINT __ACC_MMSYSTEM_H_LPUINT
|
||||
# endif
|
||||
# if 1
|
||||
# include <mmsystem.h>
|
||||
# else
|
||||
# if (ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_PELLESC)
|
||||
ACC_EXTERN_C __declspec(dllimport) unsigned long __stdcall timeGetTime(void);
|
||||
# else
|
||||
ACC_EXTERN_C unsigned long __stdcall timeGetTime(void);
|
||||
# endif
|
||||
# endif
|
||||
# if (ACC_CC_DMC)
|
||||
# pragma DMC includelib "winmm.lib"
|
||||
# elif (ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_PELLESC)
|
||||
# pragma comment(lib, "winmm.lib")
|
||||
# elif (ACC_CC_MWERKS && (__MWERKS__ >= 0x3000))
|
||||
# pragma comment(lib, "winmm.lib")
|
||||
# elif (ACC_CC_SYMANTECC)
|
||||
# pragma SC includelib "winmm.lib"
|
||||
# elif (ACC_CC_WATCOMC && (__WATCOMC__ >= 1050))
|
||||
# pragma library("winmm.lib")
|
||||
# endif
|
||||
# endif
|
||||
#elif (ACC_OS_EMX) && (ACC_HAVE_WINDOWS_H) && defined(acc_int64l_t)
|
||||
# define __ACCLIB_UCLOCK_USE_QPC 1
|
||||
#elif (ACC_OS_CYGWIN || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_TOS || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# define __ACCLIB_UCLOCK_USE_CLOCK 1
|
||||
#endif
|
||||
|
||||
#if (__ACCLIB_UCLOCK_USE_CLOCK) && !defined(CLOCKS_PER_SEC)
|
||||
# if defined(CLK_TCK)
|
||||
# define CLOCKS_PER_SEC CLK_TCK
|
||||
# else
|
||||
# undef __ACCLIB_UCLOCK_USE_CLOCK
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_uclock_open) (acc_uclock_handle_p h)
|
||||
{
|
||||
acc_uclock_t c;
|
||||
int i;
|
||||
|
||||
#if (__ACCLIB_UCLOCK_USE_QPC)
|
||||
LARGE_INTEGER li;
|
||||
h->qpf = 0.0;
|
||||
if (QueryPerformanceFrequency(&li) != 0) {
|
||||
h->qpf = (double) li.QuadPart;
|
||||
if (h->qpf <= 0.0 || QueryPerformanceCounter(&li) == 0) {
|
||||
h->qpf = 0.0;
|
||||
}
|
||||
}
|
||||
#elif (ACC_HAVE_WINDOWS_H) && defined(acc_int64l_t)
|
||||
h->qpf = 0.0;
|
||||
#endif
|
||||
h->h = 1;
|
||||
h->mode = 0;
|
||||
|
||||
/* warm up */
|
||||
i = 100;
|
||||
do {
|
||||
acc_uclock_read(h, &c);
|
||||
#if (__ACCLIB_UCLOCK_USE_QPC)
|
||||
if (h->qpf > 0.0 && c.qpc == 0) { h->qpf = 0.0; i = 100; }
|
||||
#endif
|
||||
} while (--i > 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ACCLIB_PUBLIC(int, acc_uclock_close) (acc_uclock_handle_p h)
|
||||
{
|
||||
h->h = 0;
|
||||
h->mode = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(void, acc_uclock_read) (acc_uclock_handle_p h, acc_uclock_p c)
|
||||
{
|
||||
#if (__ACCLIB_UCLOCK_USE_QPC)
|
||||
if (h->qpf > 0.0) {
|
||||
LARGE_INTEGER li;
|
||||
if (QueryPerformanceCounter(&li) != 0) {
|
||||
c->qpc = (acc_int64l_t) li.QuadPart;
|
||||
if (c->qpc > 0)
|
||||
return;
|
||||
}
|
||||
c->qpc = 0; /* failed */
|
||||
}
|
||||
#elif (ACC_HAVE_WINDOWS_H) && defined(acc_int64l_t)
|
||||
/* c->qpc = 0; */
|
||||
#endif
|
||||
|
||||
{
|
||||
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
|
||||
# if (ACC_CC_AZTECC)
|
||||
c->ticks.t32 = 0;
|
||||
# else
|
||||
union REGS ri, ro;
|
||||
ri.x.ax = 0x2c00; int86(0x21, &ri, &ro);
|
||||
c->ticks.t32 = ro.h.ch*60UL*60UL*100UL + ro.h.cl*60UL*100UL + ro.h.dh*100UL + ro.h.dl;
|
||||
# endif
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
c->ticks.t64 = uclock();
|
||||
#elif (__ACCLIB_UCLOCK_USE_CLOCK) && defined(acc_int64l_t)
|
||||
c->ticks.t64 = clock();
|
||||
#elif (__ACCLIB_UCLOCK_USE_CLOCK)
|
||||
c->ticks.t32 = clock();
|
||||
#elif (__ACCLIB_UCLOCK_USE_WINMM)
|
||||
c->ticks.t32 = timeGetTime();
|
||||
#elif (__ACCLIB_UCLOCK_USE_GETRUSAGE)
|
||||
struct rusage ru;
|
||||
if (getrusage(RUSAGE_SELF, &ru) != 0) c->ticks.rd = 0;
|
||||
else c->ticks.td = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1000000.0;
|
||||
#elif (HAVE_GETTIMEOFDAY)
|
||||
struct timeval tv;
|
||||
if (gettimeofday(&tv, 0) != 0) c->ticks.td = 0;
|
||||
else c->ticks.td = tv.tv_sec + tv.tv_usec / 1000000.0;
|
||||
#else
|
||||
ACC_UNUSED(c);
|
||||
#endif
|
||||
}
|
||||
ACC_UNUSED(h);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
ACCLIB_PUBLIC(double, acc_uclock_get_elapsed) (acc_uclock_handle_p h, const acc_uclock_p start, const acc_uclock_p stop)
|
||||
{
|
||||
double d;
|
||||
|
||||
if (!h->h) {
|
||||
h->mode = -1;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
#if (__ACCLIB_UCLOCK_USE_QPC)
|
||||
if (h->qpf > 0.0) {
|
||||
h->mode = 1;
|
||||
if (start->qpc == 0 || stop->qpc == 0) return 0.0;
|
||||
return (double) (stop->qpc - start->qpc) / h->qpf;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
|
||||
h->mode = 2;
|
||||
d = (double) (stop->ticks.t32 - start->ticks.t32) / 100.0;
|
||||
if (d < 0.0) d += 86400.0; /* midnight passed */
|
||||
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
|
||||
h->mode = 3;
|
||||
d = (double) (stop->ticks.t64 - start->ticks.t64) / (UCLOCKS_PER_SEC);
|
||||
#elif (__ACCLIB_UCLOCK_USE_CLOCK) && defined(acc_int64l_t)
|
||||
h->mode = 4;
|
||||
d = (double) (stop->ticks.t64 - start->ticks.t64) / (CLOCKS_PER_SEC);
|
||||
#elif (__ACCLIB_UCLOCK_USE_CLOCK)
|
||||
h->mode = 5;
|
||||
d = (double) (stop->ticks.t32 - start->ticks.t32) / (CLOCKS_PER_SEC);
|
||||
#elif (__ACCLIB_UCLOCK_USE_WINMM)
|
||||
h->mode = 6;
|
||||
d = (double) (stop->ticks.t32 - start->ticks.t32) / 1000.0;
|
||||
#elif (__ACCLIB_UCLOCK_USE_GETRUSAGE)
|
||||
h->mode = 7;
|
||||
d = stop->ticks.td - start->ticks.td;
|
||||
#elif (HAVE_GETTIMEOFDAY)
|
||||
h->mode = 8;
|
||||
d = stop->ticks.td - start->ticks.td;
|
||||
#else
|
||||
h->mode = 0;
|
||||
d = 0.0;
|
||||
#endif
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
@@ -0,0 +1,72 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
This software is a copyrighted work licensed under the terms of
|
||||
the GNU General Public License. Please consult the file "ACC_LICENSE"
|
||||
for details.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/
|
||||
*/
|
||||
|
||||
|
||||
#define __ACCLIB_WILDARGV_CH_INCLUDED 1
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_OS_DOS16 || ACC_OS216 || ACC_OS_WIN16)
|
||||
#if 0 && (ACC_CC_MSC)
|
||||
|
||||
/* FIXME */
|
||||
ACC_EXTERN_C int __acc_cdecl __setargv(void);
|
||||
ACC_EXTERN_C int __acc_cdecl _setargv(void);
|
||||
ACC_EXTERN_C int __acc_cdecl _setargv(void) { return __setargv(); }
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
#if (ACC_CC_INTELC || ACC_CC_MSC)
|
||||
|
||||
ACC_EXTERN_C int __acc_cdecl __setargv(void);
|
||||
ACC_EXTERN_C int __acc_cdecl _setargv(void);
|
||||
ACC_EXTERN_C int __acc_cdecl _setargv(void) { return __setargv(); }
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_OS_EMX)
|
||||
|
||||
#define __ACCLIB_HAVE_ACC_WILDARGV 1
|
||||
ACCLIB_PUBLIC(void, acc_wildargv) (int* argc, char*** argv)
|
||||
{
|
||||
_response(argc, argv);
|
||||
_wildcard(argc, argv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(__ACCLIB_HAVE_ACC_WILDARGV)
|
||||
#define __ACCLIB_HAVE_ACC_WILDARGV 1
|
||||
ACCLIB_PUBLIC(void, acc_wildargv) (int* argc, char*** argv)
|
||||
{
|
||||
ACC_UNUSED(argc); ACC_UNUSED(argv);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
+213
-59
@@ -1,9 +1,9 @@
|
||||
/* bele.h --
|
||||
/* bele.h -- access memory in BigEndian and LittleEndian byte order
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -31,29 +31,48 @@
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// access memory in BigEndian and LittleEndian byte order
|
||||
// core
|
||||
**************************************************************************/
|
||||
|
||||
inline unsigned short get_be16(const void *bb, int off=0)
|
||||
inline unsigned get_be16(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[1] << 0;
|
||||
v |= (unsigned) b[0] << 8;
|
||||
return (unsigned short) v;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be16(void *bb, unsigned v, int off=0)
|
||||
inline void set_be16(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[1] = (unsigned char) (v >> 0);
|
||||
b[0] = (unsigned char) (v >> 8);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_be32(const void *bb, int off=0)
|
||||
inline unsigned get_be24(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
|
||||
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;
|
||||
@@ -62,9 +81,9 @@ inline unsigned get_be32(const void *bb, int off=0)
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be32(void *bb, unsigned v, int off=0)
|
||||
inline void set_be32(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[3] = (unsigned char) (v >> 0);
|
||||
b[2] = (unsigned char) (v >> 8);
|
||||
b[1] = (unsigned char) (v >> 16);
|
||||
@@ -72,34 +91,34 @@ inline void set_be32(void *bb, unsigned v, int off=0)
|
||||
}
|
||||
|
||||
|
||||
inline unsigned short get_le16(const void *bb, int off=0)
|
||||
inline unsigned get_le16(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
|
||||
unsigned v;
|
||||
#if defined(__i386__)
|
||||
v = * (const unsigned short *) b;
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
return * (const unsigned short *) bb;
|
||||
#else
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
return v;
|
||||
#endif
|
||||
return (unsigned short) v;
|
||||
}
|
||||
|
||||
inline void set_le16(void *bb, unsigned v, int off=0)
|
||||
inline void set_le16(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
|
||||
#if defined(__i386__)
|
||||
(* (unsigned short *) b) = (unsigned short) v;
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
(* (unsigned short *) bb) = (unsigned short) (v & 0xffff);
|
||||
#else
|
||||
unsigned char* b = (unsigned char*) bb;
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline unsigned get_le24(const void *bb, int off=0)
|
||||
inline unsigned get_le24(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
|
||||
const unsigned char* b = (const unsigned char*) bb;
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
@@ -107,36 +126,36 @@ inline unsigned get_le24(const void *bb, int off=0)
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_le24(void *bb, unsigned v, int off=0)
|
||||
inline void set_le24(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
|
||||
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, int off=0)
|
||||
inline unsigned get_le32(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
|
||||
unsigned v;
|
||||
#if defined(__i386__)
|
||||
v = * (const unsigned *) b;
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
return * (const acc_uint32e_t *) bb;
|
||||
#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;
|
||||
#endif
|
||||
return v;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le32(void *bb, unsigned v, int off=0)
|
||||
inline void set_le32(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
|
||||
#if defined(__i386__)
|
||||
(* (unsigned *) b) = v;
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
(* (acc_uint32e_t *) bb) = 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);
|
||||
@@ -145,6 +164,54 @@ inline void set_le32(void *bb, unsigned v, int off=0)
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// get signed values, i.e. sign-extend
|
||||
**************************************************************************/
|
||||
|
||||
inline int sign_extend(int v, int bits)
|
||||
{
|
||||
const int sign_bit = 1 << (bits - 1);
|
||||
v |= -(v & sign_bit);
|
||||
return v;
|
||||
}
|
||||
|
||||
inline int get_be16_signed(const void *bb)
|
||||
{
|
||||
int v = get_be16(bb);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_be24_signed(const void *bb)
|
||||
{
|
||||
int v = get_be24(bb);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_be32_signed(const void *bb)
|
||||
{
|
||||
int v = get_be32(bb);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline int get_le16_signed(const void *bb)
|
||||
{
|
||||
int v = get_le16(bb);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_le24_signed(const void *bb)
|
||||
{
|
||||
int v = get_le24(bb);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_le32_signed(const void *bb)
|
||||
{
|
||||
int v = get_le32(bb);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// classes for portable unaligned access
|
||||
**************************************************************************/
|
||||
@@ -154,7 +221,15 @@ class BE16
|
||||
unsigned char d[2];
|
||||
|
||||
public:
|
||||
BE16& operator = (const BE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
|
||||
BE16() { }
|
||||
BE16& operator = (const BE16 &v) {
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
* (acc_uint32e_t *) d = * (const acc_uint32e_t *) v.d;
|
||||
#else
|
||||
memcpy(d, v.d, sizeof(d));
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
|
||||
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
|
||||
@@ -162,8 +237,9 @@ public:
|
||||
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
|
||||
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_be16(d); }
|
||||
};
|
||||
operator unsigned () const { return get_be16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
class BE32
|
||||
@@ -171,7 +247,15 @@ class BE32
|
||||
unsigned char d[4];
|
||||
|
||||
public:
|
||||
BE32& operator = (const BE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
|
||||
BE32() { }
|
||||
BE32& operator = (const BE32 &v) {
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
* (unsigned int *) d = * (const unsigned int *) v.d;
|
||||
#else
|
||||
memcpy(d, v.d, sizeof(d));
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
|
||||
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
|
||||
@@ -179,8 +263,9 @@ public:
|
||||
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
|
||||
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_be32(d); }
|
||||
};
|
||||
operator unsigned () const { return get_be32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
class LE16
|
||||
@@ -188,7 +273,15 @@ class LE16
|
||||
unsigned char d[2];
|
||||
|
||||
public:
|
||||
LE16& operator = (const LE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
|
||||
LE16() { }
|
||||
LE16& operator = (const LE16 &v) {
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
* (unsigned short *) d = * (const unsigned short *) v.d;
|
||||
#else
|
||||
memcpy(d, v.d, sizeof(d));
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
|
||||
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
|
||||
@@ -196,8 +289,9 @@ public:
|
||||
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
|
||||
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_le16(d); }
|
||||
};
|
||||
operator unsigned () const { return get_le16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
class LE32
|
||||
@@ -205,7 +299,15 @@ class LE32
|
||||
unsigned char d[4];
|
||||
|
||||
public:
|
||||
LE32& operator = (const LE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
|
||||
LE32() { }
|
||||
LE32& operator = (const LE32 &v) {
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_IA32)
|
||||
* (acc_uint32e_t *) d = * (const acc_uint32e_t *) v.d;
|
||||
#else
|
||||
memcpy(d, v.d, sizeof(d));
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
|
||||
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
|
||||
@@ -213,8 +315,9 @@ public:
|
||||
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
|
||||
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_le32(d); }
|
||||
};
|
||||
operator unsigned () const { return get_le32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -223,34 +326,85 @@ public:
|
||||
|
||||
inline bool operator < (const BE16& v1, const BE16& v2)
|
||||
{
|
||||
return (const unsigned)v1 < (const unsigned)v2;
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const BE32& v1, const BE32& v2)
|
||||
{
|
||||
return (const unsigned)v1 < (const unsigned)v2;
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const LE16& v1, const LE16& v2)
|
||||
{
|
||||
return (const unsigned)v1 < (const unsigned)v2;
|
||||
return (unsigned)v1 < (unsigned)v2;
|
||||
}
|
||||
|
||||
inline bool operator < (const LE32& v1, const LE32& v2)
|
||||
{
|
||||
return (const unsigned)v1 < (const unsigned)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 - (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 - (T* ptr, const BE32& v) { 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 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 - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
// for use with qsort()
|
||||
int be16_compare(const void *e1, const void *e2);
|
||||
int be32_compare(const void *e1, const void *e2);
|
||||
int le16_compare(const void *e1, const void *e2);
|
||||
int le32_compare(const void *e1, const void *e2);
|
||||
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);
|
||||
|
||||
|
||||
// just for testing...
|
||||
#if 1 && (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
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_IA32) && (ACC_CC_INTELC)
|
||||
typedef __declspec(align(1)) unsigned short LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
|
||||
typedef __declspec(align(1)) unsigned short LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/* bptr.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_BPTR_H
|
||||
#define __UPX_BPTR_H
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// BoundedPtr
|
||||
**************************************************************************/
|
||||
|
||||
template <class T>
|
||||
class BoundedPtr
|
||||
{
|
||||
// typedef BoundedPtr<T> Self;
|
||||
public:
|
||||
typedef T* StoredType;
|
||||
typedef T* PointerType;
|
||||
typedef T& ReferenceType;
|
||||
|
||||
~BoundedPtr() { }
|
||||
|
||||
explicit BoundedPtr(void* base, unsigned size, T* ptr=0)
|
||||
: ptr_(ptr), base_(base), size_(size) { check(); }
|
||||
BoundedPtr& operator= (const BoundedPtr& other) {
|
||||
assert(base_ == other.base_); assert(size_ == other.size_);
|
||||
ptr_ = other.ptr_; check(); return *this;
|
||||
}
|
||||
BoundedPtr& operator= (T* other) {
|
||||
ptr_ = other; check(); return *this;
|
||||
}
|
||||
|
||||
operator T* () { check(); return ptr_; }
|
||||
operator const T* () const { check(); return ptr_; }
|
||||
|
||||
BoundedPtr& operator += (size_t n) {
|
||||
checkStrict(); ptr_ += n; checkStrict(); return *this;
|
||||
}
|
||||
BoundedPtr& operator -= (size_t n) {
|
||||
checkStrict(); ptr_ -= n; checkStrict(); return *this;
|
||||
}
|
||||
BoundedPtr& operator ++ (void) {
|
||||
checkStrict(); ptr_ += 1; checkStrict(); return *this;
|
||||
}
|
||||
// T* operator ++ (int) {
|
||||
// T* p = ptr_; checkStrict(); ptr_ += 1; checkStrict(); return p;
|
||||
// }
|
||||
// BoundedPtr& operator -- (void) {
|
||||
// checkStrict(); ptr_ -= 1; checkStrict(); return *this;
|
||||
// }
|
||||
|
||||
|
||||
private:
|
||||
void checkNULL() const {
|
||||
if (!ptr_)
|
||||
throwCantUnpack("unexpected NULL pointer; take care!");
|
||||
}
|
||||
void checkRange(size_t extra=0) const {
|
||||
size_t off = (const char *) ptr_ - (const char *) base_;
|
||||
if (off > size_ || off + extra > size_)
|
||||
throwCantUnpack("pointer out of range; take care!");
|
||||
}
|
||||
void checkStrict(size_t extra=0) const {
|
||||
checkNULL();
|
||||
checkRange(extra);
|
||||
}
|
||||
void check(size_t extra=0) const {
|
||||
if (ptr_) checkRange(extra);
|
||||
}
|
||||
|
||||
T* ptr_;
|
||||
void* base_;
|
||||
size_t size_;
|
||||
|
||||
// disable copy
|
||||
BoundedPtr(const BoundedPtr&); // {}
|
||||
// BoundedPtr& operator= (const BoundedPtr&); // { return *this; }
|
||||
|
||||
// disable dynamic allocation
|
||||
DISABLE_NEW_DELETE
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
/* c_file.cpp -- file console output
|
||||
/* c_file.cpp --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+9
-9
@@ -1,9 +1,9 @@
|
||||
/* c_init.cpp -- console initialization
|
||||
/* c_init.cpp --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ static int do_init(FILE *f)
|
||||
if (opt->console == CON_NONE || opt->to_stdout)
|
||||
return con_mode;
|
||||
try_init(&console_file,f);
|
||||
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO) || !isatty(STDERR_FILENO))
|
||||
if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO))
|
||||
return con_mode;
|
||||
|
||||
#if defined(USE_ANSI)
|
||||
@@ -142,13 +142,13 @@ console_t console_init =
|
||||
};
|
||||
|
||||
|
||||
void con_fprintf(FILE *f, const char *format, ...)
|
||||
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[80*25];
|
||||
|
||||
va_start(args,format);
|
||||
upx_vsnprintf(buf,sizeof(buf),format,args);
|
||||
va_start(args, format);
|
||||
upx_vsnprintf(buf, sizeof(buf), format,args);
|
||||
va_end(args);
|
||||
|
||||
if (con == me)
|
||||
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
/* c_none.cpp -- dummy console output
|
||||
/* c_none.cpp --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+7
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ static screen_t *do_construct(screen_t *s, int fd)
|
||||
|
||||
static screen_t *screen = NULL;
|
||||
|
||||
static void do_destroy(void)
|
||||
static void __acc_cdecl_atexit do_destroy(void)
|
||||
{
|
||||
if (screen)
|
||||
{
|
||||
@@ -130,7 +130,7 @@ static int init(FILE *f, int o, int now)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_djgpp2_construct(),fd);
|
||||
#endif
|
||||
#if defined(__MFX_WIN32)
|
||||
#if defined(USE_SCREEN_WIN32)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_win32_construct(),fd);
|
||||
#endif
|
||||
@@ -196,7 +196,7 @@ static void print0(FILE *f, const char *ss)
|
||||
|
||||
// Note:
|
||||
// We use 2 passes to avoid unnecessary system calls because
|
||||
// scrollUp() under Win95/98 is *extremely* slow.
|
||||
// scrollUp() under Win32 is *extremely* slow.
|
||||
UNUSED(f);
|
||||
|
||||
screen->getCursor(screen,&old_cx,&old_cy);
|
||||
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
/* compress.ch --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(upx_adler32)
|
||||
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
|
||||
{
|
||||
if (len == 0)
|
||||
return adler;
|
||||
assert(buf != NULL);
|
||||
return ucl_adler32(adler, (const ucl_bytep)buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(upx_crc32)
|
||||
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
|
||||
{
|
||||
if (len == 0)
|
||||
return crc;
|
||||
assert(buf != NULL);
|
||||
return ucl_crc32(crc, (const ucl_bytep)buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(upx_compress)
|
||||
|
||||
int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
upx_progress_callback_t *cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf_parm,
|
||||
upx_uintp result )
|
||||
{
|
||||
struct upx_compress_config_t conf;
|
||||
upx_uint result_buffer[16];
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
assert(level > 0);
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
if (conf_parm)
|
||||
conf = *conf_parm; // struct copy
|
||||
if (!result)
|
||||
result = result_buffer;
|
||||
|
||||
// assume no info available - fill in worst case results
|
||||
//result[0] = 1; // min_offset_found - NOT USED
|
||||
result[1] = src_len - 1; // max_offset_found
|
||||
//result[2] = 2; // min_match_found - NOT USED
|
||||
result[3] = src_len - 1; // max_match_found
|
||||
//result[4] = 1; // min_run_found - NOT USED
|
||||
result[5] = src_len; // max_run_found
|
||||
result[6] = 1; // first_offset_found
|
||||
//result[7] = 999999; // same_match_offsets_found - NOT USED
|
||||
|
||||
// prepare bit-buffer settings
|
||||
conf.bb_endian = 0;
|
||||
conf.bb_size = 0;
|
||||
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_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;
|
||||
}
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
|
||||
// optimize compression parms
|
||||
if (level <= 3 && conf.max_offset == UPX_UINT_MAX)
|
||||
conf.max_offset = 8*1024-1;
|
||||
else if (level == 4 && conf.max_offset == UPX_UINT_MAX)
|
||||
conf.max_offset = 32*1024-1;
|
||||
|
||||
if M_IS_NRV2B(method)
|
||||
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
else if M_IS_NRV2D(method)
|
||||
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
#if defined(ALG_NRV2E)
|
||||
else if M_IS_NRV2E(method)
|
||||
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
#endif
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* upx_compress */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(upx_decompress)
|
||||
|
||||
int upx_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
int method )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case M_NRV2B_8:
|
||||
r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2B_LE16:
|
||||
r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2B_LE32:
|
||||
r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2D_8:
|
||||
r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2D_LE16:
|
||||
r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2D_LE32:
|
||||
r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
#if defined(ALG_NRV2E)
|
||||
case M_NRV2E_8:
|
||||
r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2E_LE16:
|
||||
r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2E_LE32:
|
||||
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
throwInternalError("unknown decompression method");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* upx_decompress */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(upx_test_overlap)
|
||||
|
||||
int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
|
||||
upx_uint src_len, upx_uintp dst_len,
|
||||
int method )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case M_NRV2B_8:
|
||||
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2B_LE16:
|
||||
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2B_LE32:
|
||||
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2D_8:
|
||||
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2D_LE16:
|
||||
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2D_LE32:
|
||||
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
#if defined(ALG_NRV2E)
|
||||
case M_NRV2E_8:
|
||||
r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2E_LE16:
|
||||
r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
case M_NRV2E_LE32:
|
||||
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
throwInternalError("unknown decompression method");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* upx_test_overlap */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
+17
-235
@@ -1,9 +1,9 @@
|
||||
/* compress.cpp -- interface to the compression library
|
||||
/* compress.cpp --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,248 +21,30 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#if defined(WITH_UCL) && !defined(WITH_NRV)
|
||||
# define nrv2b_99_compress_internal ucl_nrv2b_99_compress
|
||||
# define nrv2d_99_compress_internal ucl_nrv2d_99_compress
|
||||
# if 0 && defined(__i386__)
|
||||
# include <ucl/ucl_asm.h>
|
||||
# define nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
|
||||
# define nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
|
||||
# define nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
|
||||
# define nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
|
||||
# define nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
|
||||
# define nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
|
||||
# else
|
||||
# define nrv2b_decompress_safe_8 ucl_nrv2b_decompress_safe_8
|
||||
# define nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_safe_le16
|
||||
# define nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_safe_le32
|
||||
# define nrv2d_decompress_safe_8 ucl_nrv2d_decompress_safe_8
|
||||
# define nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_safe_le16
|
||||
# define nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_safe_le32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WITH_NRV)
|
||||
# include <nrv/nrv2b.h>
|
||||
# include <nrv/nrv2d.h>
|
||||
# if !defined(NRV_VERSION) || (NRV_VERSION < 0x007300L)
|
||||
# error
|
||||
# include "compress_nrv.ch"
|
||||
#elif defined(WITH_UCL)
|
||||
# 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
|
||||
# if 1 && defined(__i386__)
|
||||
# define nrv2b_decompress_safe_8 nrv2b_decompress_asm_safe_8
|
||||
# define nrv2b_decompress_safe_le16 nrv2b_decompress_asm_safe_le16
|
||||
# define nrv2d_decompress_safe_8 nrv2d_decompress_asm_safe_8
|
||||
# define nrv2d_decompress_safe_le16 nrv2d_decompress_asm_safe_le16
|
||||
# if (NRV_VERSION < 0x008000L)
|
||||
# define nrv2b_decompress_safe_le32 nrv2b_decompress_asm_safe
|
||||
# define nrv2d_decompress_safe_le32 nrv2d_decompress_asm_safe
|
||||
# else
|
||||
# define nrv2b_decompress_safe_le32 nrv2b_decompress_asm_safe_le32
|
||||
# define nrv2d_decompress_safe_le32 nrv2d_decompress_asm_safe_le32
|
||||
# endif
|
||||
# endif
|
||||
NRV_EXTERN_CDECL(int) nrv2b_99_compress_internal(...);
|
||||
NRV_EXTERN_CDECL(int) nrv2d_99_compress_internal(...);
|
||||
NRV_EXTERN_CDECL(int) nrv2b_decompress_safe_8(...);
|
||||
NRV_EXTERN_CDECL(int) nrv2b_decompress_safe_le16(...);
|
||||
NRV_EXTERN_CDECL(int) nrv2b_decompress_safe_le32(...);
|
||||
NRV_EXTERN_CDECL(int) nrv2d_decompress_safe_8(...);
|
||||
NRV_EXTERN_CDECL(int) nrv2d_decompress_safe_le16(...);
|
||||
NRV_EXTERN_CDECL(int) nrv2d_decompress_safe_le32(...);
|
||||
# include "compress.ch"
|
||||
#else
|
||||
# error
|
||||
#endif
|
||||
|
||||
#if 0 && defined(WITH_ZLIB) && defined(M_ZLIB)
|
||||
# include <zlib.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_compress ( const upx_byte *src, upx_uint src_len,
|
||||
upx_byte *dst, upx_uint *dst_len,
|
||||
upx_progress_callback_t *cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf_parm,
|
||||
upx_uintp result)
|
||||
{
|
||||
struct upx_compress_config_t conf;
|
||||
upx_uint result_buffer[16];
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
assert(level > 0);
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
if (conf_parm)
|
||||
conf = *conf_parm; // struct copy
|
||||
if (!result)
|
||||
result = result_buffer;
|
||||
|
||||
// assume no info available - fill in worst case results
|
||||
//result[0] = 1; // min_offset_found - NOT USED
|
||||
result[1] = src_len - 1; // max_offset_found
|
||||
//result[2] = 2; // min_match_found - NOT USED
|
||||
result[3] = src_len - 1; // max_match_found
|
||||
//result[4] = 1; // min_run_found - NOT USED
|
||||
result[5] = src_len; // max_run_found
|
||||
result[6] = 1; // first_offset_found
|
||||
//result[7] = 999999; // same_match_offsets_found - NOT USED
|
||||
|
||||
#if 0 && defined(WITH_ZLIB) && defined(M_ZLIB)
|
||||
if (method == M_ZLIB)
|
||||
{
|
||||
uLong destLen = src_len + src_len / 8 + 256;
|
||||
r = compress2(dst, &destLen, src, src_len, UPX_MIN(level, 9));
|
||||
*dst_len = destLen;
|
||||
if (r == Z_MEM_ERROR)
|
||||
return UPX_E_OUT_OF_MEMORY;
|
||||
if (r != Z_OK)
|
||||
return UPX_E_ERROR;
|
||||
return UPX_E_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
// prepare bit-buffer settings
|
||||
conf.bb_endian = 0;
|
||||
conf.bb_size = 0;
|
||||
if (method == M_NRV2B_LE32 || method == M_NRV2D_LE32)
|
||||
conf.bb_size = 32;
|
||||
else if (method == M_NRV2B_8 || method == M_NRV2D_8)
|
||||
conf.bb_size = 8;
|
||||
else if (method == M_NRV2B_LE16 || method == M_NRV2D_LE16)
|
||||
conf.bb_size = 16;
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
|
||||
#if 1 && defined(WITH_NRV)
|
||||
if (level == 1 && conf.bb_size == 32 &&
|
||||
conf.max_offset == UPX_UINT_MAX && conf.max_match == UPX_UINT_MAX)
|
||||
{
|
||||
if (method == M_NRV2B_LE32)
|
||||
{
|
||||
upx_byte wrkmem[NRV2B_1_16_MEM_COMPRESS];
|
||||
#if defined(__UPX_CHECKER)
|
||||
memset(wrkmem,0,NRV2B_1_16_MEM_COMPRESS);
|
||||
#endif
|
||||
r = nrv2b_1_16_compress(src, src_len, dst, dst_len, wrkmem);
|
||||
}
|
||||
else if (method == M_NRV2D_LE32)
|
||||
{
|
||||
upx_byte wrkmem[NRV2D_1_16_MEM_COMPRESS];
|
||||
#if defined(__UPX_CHECKER)
|
||||
memset(wrkmem,0,NRV2D_1_16_MEM_COMPRESS);
|
||||
#endif
|
||||
r = nrv2d_1_16_compress(src, src_len, dst, dst_len, wrkmem);
|
||||
}
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
// optimize compression parms
|
||||
if (level <= 3 && conf.max_offset == UPX_UINT_MAX)
|
||||
conf.max_offset = 8*1024-1;
|
||||
else if (level == 4 && conf.max_offset == UPX_UINT_MAX)
|
||||
conf.max_offset = 32*1024-1;
|
||||
#if defined(WITH_NRV)
|
||||
else if (level <= 7 && conf.max_offset == UPX_UINT_MAX)
|
||||
conf.max_offset = 1024*1024-1;
|
||||
else if (level <= 8 && conf.max_offset == UPX_UINT_MAX)
|
||||
conf.max_offset = 2048*1024-1;
|
||||
else if (level <= 10 && conf.max_offset == UPX_UINT_MAX)
|
||||
conf.max_offset = 4096*1024-1;
|
||||
#endif
|
||||
|
||||
if M_IS_NRV2B(method)
|
||||
r = nrv2b_99_compress_internal(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
else if M_IS_NRV2D(method)
|
||||
r = nrv2d_99_compress_internal(src, src_len, dst, dst_len,
|
||||
cb, level, &conf, result);
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_decompress ( const upx_byte *src, upx_uint src_len,
|
||||
upx_byte *dst, upx_uint *dst_len,
|
||||
int method )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
#if 0 && defined(WITH_ZLIB) && defined(M_ZLIB)
|
||||
if (method == M_ZLIB)
|
||||
{
|
||||
uLong destLen = *dst_len;
|
||||
r = uncompress(dst, &destLen, src, src_len);
|
||||
*dst_len = destLen;
|
||||
if (r == Z_MEM_ERROR)
|
||||
return UPX_E_OUT_OF_MEMORY;
|
||||
if (r != Z_OK)
|
||||
return UPX_E_ERROR;
|
||||
return UPX_E_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (method == M_NRV2B_LE32)
|
||||
r = nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
else if (method == M_NRV2B_8)
|
||||
r = nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
|
||||
else if (method == M_NRV2B_LE16)
|
||||
r = nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
|
||||
else if (method == M_NRV2D_LE32)
|
||||
r = nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
|
||||
else if (method == M_NRV2D_8)
|
||||
r = nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL);
|
||||
else if (method == M_NRV2D_LE16)
|
||||
r = nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
|
||||
else
|
||||
throwInternalError("unknown decompression method");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_test_overlap ( const upx_byte *buf, upx_uint src_off,
|
||||
upx_uint src_len, upx_uint *dst_len,
|
||||
int method )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
if (method == M_NRV2B_LE32)
|
||||
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
else if (method == M_NRV2B_8)
|
||||
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
|
||||
else if (method == M_NRV2B_LE16)
|
||||
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
|
||||
else if (method == M_NRV2D_LE32)
|
||||
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
|
||||
else if (method == M_NRV2D_8)
|
||||
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
|
||||
else if (method == M_NRV2D_LE16)
|
||||
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
|
||||
else
|
||||
throwInternalError("unknown decompression method");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
|
||||
+257
-329
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,31 +21,105 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_CONF_H
|
||||
#define __UPX_CONF_H
|
||||
|
||||
#if 0 && defined(__EMX__)
|
||||
# include <sys/emx.h>
|
||||
#endif
|
||||
|
||||
#if defined(UPX_CONFIG_H)
|
||||
# include UPX_CONFIG_H
|
||||
#endif
|
||||
#include <limits.h>
|
||||
|
||||
#include "version.h"
|
||||
#include "tailor.h"
|
||||
|
||||
#if !defined(__i386__)
|
||||
# if defined(__386__) || defined(_M_IX86)
|
||||
# define __i386__ 1
|
||||
|
||||
/*************************************************************************
|
||||
// ACC
|
||||
**************************************************************************/
|
||||
|
||||
#include "acc/acc.h"
|
||||
#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
# undef HAVE_UTIME_H /* this pulls in <windows.h> */
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_CC_BORLANDC)
|
||||
# if (__BORLANDC__ < 0x0500)
|
||||
# error "need Borland C++ 5.0 or newer"
|
||||
# endif
|
||||
# pragma warn -aus // 8004: 'x' is assigned a value that is never used
|
||||
# pragma warn -inl // 8026+8027: Function not expanded inline
|
||||
// Borland compilers typically produce a number of bogus warnings, and
|
||||
// the actual diagnostics vary from version to version...
|
||||
# if (__BORLANDC__ < 0x0530)
|
||||
# pragma warn -csu // 8012: Comparing signed and unsigned values
|
||||
# endif
|
||||
# if (__BORLANDC__ >= 0x0530 && __BORLANDC__ < 0x0560)
|
||||
# pragma warn -osh // 8055: Possible overflow in shift operation
|
||||
# endif
|
||||
# if (__BORLANDC__ >= 0x0560)
|
||||
# pragma warn -use // 8080: 'x' is declared but never used
|
||||
# endif
|
||||
#elif (ACC_CC_DMC)
|
||||
# if (__DMC__ < 0x829)
|
||||
# error "need Digital Mars C++ 8.29 or newer"
|
||||
# endif
|
||||
#elif (ACC_CC_INTELC)
|
||||
# if (__INTEL_COMPILER < 450)
|
||||
# error "need Intel C++ 4.5 or newer"
|
||||
# endif
|
||||
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# elif defined(__linux__)
|
||||
# pragma warning(error: 424) // #424: extra ";" ignored
|
||||
# pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier
|
||||
# pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits
|
||||
# pragma warning(disable: 981) // #981: operands are evaluated in unspecified order
|
||||
# pragma warning(disable: 1418) // #1418: external definition with no prior declaration
|
||||
# else
|
||||
# error "untested platform"
|
||||
# endif
|
||||
#elif (ACC_CC_MSC)
|
||||
# if (_MSC_VER < 1100)
|
||||
# error "need Visual C++ 5.0 or newer"
|
||||
# endif
|
||||
# pragma warning(error: 4096) // W2: '__cdecl' must be used with '...'
|
||||
# pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B'
|
||||
# pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated
|
||||
# pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated
|
||||
# pragma warning(disable: 4514) // W4: 'function': unreferenced inline function has been removed
|
||||
# pragma warning(disable: 4710) // W4: 'function': function not inlined
|
||||
# if (_MSC_VER >= 1300)
|
||||
# pragma warning(disable: 4625) // W4: 'class' : copy constructor could not be generated because a base class copy constructor is inaccessible
|
||||
# pragma warning(disable: 4626) // W4: 'class' : assignment operator could not be generated because a base class assignment operator is inaccessible
|
||||
# pragma warning(disable: 4711) // W4: 'function' selected for automatic inline expansion
|
||||
# pragma warning(disable: 4820) // W4: 'struct' : 'x' bytes padding added after member 'member'
|
||||
# endif
|
||||
# if (_MSC_VER >= 1400)
|
||||
# pragma warning(disable: 4996) // W1: 'function': was declared deprecated
|
||||
# endif
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# if (__WATCOMC__ < 1100)
|
||||
# error "need Watcom C++ 11.0c or newer"
|
||||
# endif
|
||||
# if defined(__cplusplus)
|
||||
# pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#include "acc/acc_incd.h"
|
||||
#include "acc/acc_ince.h"
|
||||
#include "acc/acc_lib.h"
|
||||
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
|
||||
# error "something pulled in <windows.h>"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(__linux__) && !defined(__unix__)
|
||||
# define __unix__ 1
|
||||
#endif
|
||||
@@ -56,12 +130,28 @@
|
||||
#undef linux
|
||||
#undef small
|
||||
#undef tos
|
||||
#undef unix
|
||||
#if defined(ACC_CC_DMC)
|
||||
# undef tell
|
||||
#endif
|
||||
#if !defined(ACC_CC_PGI)
|
||||
# undef unix
|
||||
#endif
|
||||
#if defined(__DJGPP__)
|
||||
# undef sopen
|
||||
# undef __unix__
|
||||
# undef __unix
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(WITH_UCL)
|
||||
# error "please set UCLDIR in the Makefile"
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
# include <ucl/uclconf.h>
|
||||
# include <ucl/ucl.h>
|
||||
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010200L)
|
||||
# error "please upgrade your UCL installation"
|
||||
# endif
|
||||
# if !defined(UPX_UINT_MAX)
|
||||
# define UPX_UINT_MAX UCL_UINT_MAX
|
||||
# define upx_uint ucl_uint
|
||||
@@ -70,49 +160,24 @@
|
||||
# define upx_byte ucl_byte
|
||||
# define upx_bytep ucl_bytep
|
||||
# define upx_bool ucl_bool
|
||||
# define upx_compress_config_t ucl_compress_config_t
|
||||
# define upx_progress_callback_t ucl_progress_callback_t
|
||||
# define upx_adler32 ucl_adler32
|
||||
# define UPX_E_OK UCL_E_OK
|
||||
# define UPX_E_ERROR UCL_E_ERROR
|
||||
# define UPX_E_OUT_OF_MEMORY UCL_E_OUT_OF_MEMORY
|
||||
# define __UPX_ENTRY __UCL_ENTRY
|
||||
# define __UPX_CDECL __UCL_CDECL
|
||||
# endif
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
# include <nrv/nrvconf.h>
|
||||
# if !defined(UPX_UINT_MAX)
|
||||
# define UPX_UINT_MAX NRV_UINT_MAX
|
||||
# define upx_uint nrv_uint
|
||||
# define upx_voidp nrv_voidp
|
||||
# define upx_uintp nrv_uintp
|
||||
# define upx_byte nrv_byte
|
||||
# define upx_bytep nrv_bytep
|
||||
# define upx_bool nrv_bool
|
||||
# define upx_progress_callback_t nrv_progress_callback_t
|
||||
# define upx_adler32 nrv_adler32
|
||||
# define UPX_E_OK NRV_E_OK
|
||||
# define UPX_E_ERROR NRV_E_ERROR
|
||||
# define UPX_E_OUT_OF_MEMORY NRV_E_OUT_OF_MEMORY
|
||||
# define __UPX_ENTRY __NRV_ENTRY
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(__UPX_CHECKER)
|
||||
# if defined(__UCL_CHECKER) || defined(__NRV_CHECKER)
|
||||
# define __UPX_CHECKER
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(UPX_UINT_MAX) || (UINT_MAX < 0xffffffffL)
|
||||
# error "you lose"
|
||||
#endif
|
||||
#if !defined(WITH_UCL)
|
||||
# error "you lose"
|
||||
#endif
|
||||
#if !defined(UCL_VERSION) || (UCL_VERSION < 0x009200L)
|
||||
# error "please upgrade your UCL installation"
|
||||
#endif
|
||||
|
||||
#ifndef WITH_ZLIB
|
||||
# define WITH_ZLIB 1
|
||||
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
|
||||
# error "UINT_MAX"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -120,64 +185,10 @@
|
||||
// system includes
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(NO_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define NDEBUG
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#if !defined(NO_FCNTL_H)
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
#if !defined(NO_SYS_STAT_H)
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#if defined(HAVE_IO_H) && !defined(NO_IO_H)
|
||||
# include <io.h>
|
||||
#endif
|
||||
#if defined(HAVE_DOS_H) && !defined(NO_DOS_H)
|
||||
# include <dos.h>
|
||||
#endif
|
||||
#if defined(HAVE_MALLOC_H) && !defined(NO_MALLOC_H)
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
#if defined(HAVE_ALLOCA_H) && !defined(NO_ALLOCA_H)
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
#if defined(HAVE_SIGNAL_H)
|
||||
# include <signal.h>
|
||||
#endif
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#if defined(TIME_WITH_SYS_TIME)
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# include <time.h>
|
||||
#endif
|
||||
#if defined(HAVE_UTIME_H)
|
||||
# include <utime.h>
|
||||
#elif defined(HAVE_SYS_UTIME_H)
|
||||
# include <sys/utime.h>
|
||||
#endif
|
||||
#if defined(HAVE_SHARE_H)
|
||||
# include <share.h>
|
||||
#endif
|
||||
|
||||
|
||||
// malloc debuggers
|
||||
#if defined(WITH_DMALLOC)
|
||||
#if defined(WITH_VALGRIND)
|
||||
# include <valgrind/memcheck.h>
|
||||
#elif defined(WITH_DMALLOC)
|
||||
# define DMALLOC_FUNC_CHECK
|
||||
# include <dmalloc.h>
|
||||
#elif defined(WITH_GC)
|
||||
@@ -189,60 +200,31 @@
|
||||
# define malloc GC_MALLOC
|
||||
# define realloc GC_REALLOC
|
||||
# define free GC_FREE
|
||||
#elif defined(WITH_MSS)
|
||||
# define MSS
|
||||
# include <mss.h>
|
||||
#endif
|
||||
|
||||
#if !defined(VALGRIND_MAKE_WRITABLE)
|
||||
# define VALGRIND_MAKE_WRITABLE(addr,len) 0
|
||||
#endif
|
||||
#if !defined(VALGRIND_MAKE_READABLE)
|
||||
# if 0
|
||||
# define VALGRIND_MAKE_READABLE(addr,len) (memset(addr,0,len), 0)
|
||||
# else
|
||||
# define VALGRIND_MAKE_READABLE(addr,len) 0
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(VALGRIND_DISCARD)
|
||||
# define VALGRIND_DISCARD(handle) ((void)(&handle))
|
||||
#endif
|
||||
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// portab
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(NO_BOOL)
|
||||
typedef int bool;
|
||||
enum { false, true };
|
||||
#endif
|
||||
|
||||
#if !defined(PATH_MAX)
|
||||
# define PATH_MAX 512
|
||||
#elif (PATH_MAX < 512)
|
||||
# undef PATH_MAX
|
||||
# define PATH_MAX 512
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
#endif
|
||||
#ifndef SIGTYPEENTRY
|
||||
# define SIGTYPEENTRY
|
||||
#endif
|
||||
typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
||||
|
||||
#undef MODE_T
|
||||
#if defined(HAVE_MODE_T)
|
||||
# define MODE_T mode_t
|
||||
#else
|
||||
# define MODE_T int
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRCASECMP)
|
||||
# if defined(HAVE_STRICMP)
|
||||
# define strcasecmp stricmp
|
||||
# else
|
||||
# define strcasecmp strcmp
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(HAVE_STRNCASECMP)
|
||||
# if defined(HAVE_STRNICMP)
|
||||
# define strncasecmp strnicmp
|
||||
# else
|
||||
# define strncasecmp strncmp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
# define STDIN_FILENO (fileno(stdin))
|
||||
#endif
|
||||
@@ -254,6 +236,14 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(HAVE_STRCASECMP) && defined(HAVE_STRICMP)
|
||||
# define strcasecmp stricmp
|
||||
#endif
|
||||
#if !defined(HAVE_STRNCASECMP) && defined(HAVE_STRNICMP)
|
||||
# define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(S_IWUSR) && defined(_S_IWUSR)
|
||||
# define S_IWUSR _S_IWUSR
|
||||
#elif !defined(S_IWUSR) && defined(_S_IWRITE)
|
||||
@@ -277,14 +267,14 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
||||
# if defined(S_IFMT) && defined(S_IFREG)
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
# else
|
||||
# error S_ISREG
|
||||
# error "S_ISREG"
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(S_ISDIR)
|
||||
# if defined(S_IFMT) && defined(S_IFDIR)
|
||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
# else
|
||||
# error S_ISDIR
|
||||
# error "S_ISDIR"
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(S_ISCHR)
|
||||
@@ -299,49 +289,61 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
||||
#define index upx_index
|
||||
#define outp upx_outp
|
||||
|
||||
// a dummy statement
|
||||
#define nop ((void)0)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// file io
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(HAVE_SETMODE)
|
||||
# if !defined(O_BINARY)
|
||||
# error "setmode without O_BINARY"
|
||||
#undef __attribute_packed
|
||||
#if (ACC_CC_GNUC || ACC_CC_INTELC)
|
||||
# if (1 && (ACC_ARCH_IA32))
|
||||
# define __attribute_packed
|
||||
# else
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# endif
|
||||
# define USE_SETMODE 1
|
||||
#else
|
||||
# define __attribute_packed
|
||||
#endif
|
||||
|
||||
#if !defined(O_BINARY)
|
||||
# define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#if defined(__DJGPP__)
|
||||
# undef sopen
|
||||
# undef USE_SETMODE
|
||||
#ifndef OPTIONS_VAR
|
||||
# define OPTIONS_VAR "UPX"
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// memory util
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#undef FREE
|
||||
#define FREE(ptr) if (ptr) { free(ptr); ptr = NULL; }
|
||||
#define UNUSED(var) ACC_UNUSED(var)
|
||||
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
|
||||
|
||||
#undef UNUSED
|
||||
#if defined(__BORLANDC__)
|
||||
#define UNUSED(parm) ((void)(parm))
|
||||
#if 1
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
|
||||
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z[7]; }; \
|
||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
|
||||
}
|
||||
#else
|
||||
#define UNUSED(parm) (parm = parm)
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||
struct acc_tmp_t { b x; a y; b z[7]; }; \
|
||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define HIGH(array) ((unsigned) (sizeof(array)/sizeof((array)[0])))
|
||||
#if defined(acc_alignof)
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \
|
||||
COMPILE_TIME_ASSERT(acc_alignof(a) == sizeof(b))
|
||||
#else
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
|
||||
#endif
|
||||
|
||||
#define TABLESIZE(table) ((sizeof(table)/sizeof((table)[0])))
|
||||
|
||||
#define ALIGN_DOWN(a,b) (((a) / (b)) * (b))
|
||||
#define ALIGN_UP(a,b) ALIGN_DOWN((a) + ((b) - 1), b)
|
||||
#define ALIGN_GAP(a,b) (ALIGN_UP(a,b) - (a))
|
||||
|
||||
#define UPX_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
||||
#define UPX_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
||||
@@ -349,56 +351,49 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
|
||||
#define UPX_MIN3(a,b,c) ((a) <= (b) ? UPX_MIN(a,c) : UPX_MIN(b,c))
|
||||
|
||||
|
||||
#if 0 && defined(__cplusplus)
|
||||
#if 0 && defined(__cplusplus) && !defined(new) && !defined(delete)
|
||||
// global operators - debug
|
||||
inline void *operator new(size_t l)
|
||||
{
|
||||
void *p = malloc(l);
|
||||
printf("new %6ld %p\n",(long)l,p);
|
||||
printf("new %6ld %p\n",(long)l,p);
|
||||
fflush(stdout);
|
||||
return p;
|
||||
}
|
||||
inline void *operator new[](size_t l)
|
||||
{
|
||||
void *p = malloc(l);
|
||||
printf("new %6ld %p\n",(long)l,p);
|
||||
printf("new[] %6ld %p\n",(long)l,p);
|
||||
fflush(stdout);
|
||||
return p;
|
||||
}
|
||||
inline void operator delete(void *p)
|
||||
{
|
||||
printf("delete %p\n",p);
|
||||
printf("delete %p\n",p);
|
||||
fflush(stdout);
|
||||
if (p) free(p);
|
||||
}
|
||||
inline void operator delete[](void *p)
|
||||
{
|
||||
printf("delete %p\n",p);
|
||||
printf("delete[] %p\n",p);
|
||||
fflush(stdout);
|
||||
if (p) free(p);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// A autoheap_array allocates memory on the heap, but automatically
|
||||
// An Array allocates memory on the heap, but automatically
|
||||
// gets destructed when leaving scope or on exceptions.
|
||||
// "var" is declared as a read-only reference to a pointer
|
||||
// and behaves exactly like an array "var[]".
|
||||
#if 0
|
||||
# define autoheap_array(type, var, size) \
|
||||
#define Array(type, var, size) \
|
||||
assert((int)(size) > 0); \
|
||||
vector<type> var ## _autoheap_vec((size)); \
|
||||
type * const & var = & var ## _autoheap_vec[0]
|
||||
#else
|
||||
# define autoheap_array(type, var, size) \
|
||||
assert((int)(size) > 0); \
|
||||
MemBuffer var ## _autoheap_buf((size)*(sizeof(type))); \
|
||||
type * const & var = (type *) (unsigned char *) var ## _autoheap_buf
|
||||
#endif
|
||||
MemBuffer var ## _membuf((size)*(sizeof(type))); \
|
||||
type * const var = ((type *) var ## _membuf.getVoidPtr())
|
||||
|
||||
#define ByteArray(var, size) Array(unsigned char, var, size)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
// constants
|
||||
**************************************************************************/
|
||||
|
||||
/* exit codes of this program: 0 ok, 1 error, 2 warning */
|
||||
@@ -422,124 +417,65 @@ inline void operator delete[](void *p)
|
||||
#define M_NRV2D_LE32 5
|
||||
#define M_NRV2D_8 6
|
||||
#define M_NRV2D_LE16 7
|
||||
#define M_NRV2E_LE32 8
|
||||
#define M_NRV2E_8 9
|
||||
#define M_NRV2E_LE16 10
|
||||
|
||||
#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)
|
||||
|
||||
|
||||
// Executable formats. Note: big endian types are >= 128.
|
||||
#define UPX_F_DOS_COM 1
|
||||
#define UPX_F_DOS_SYS 2
|
||||
#define UPX_F_DOS_EXE 3
|
||||
#define UPX_F_DJGPP2_COFF 4
|
||||
#define UPX_F_WATCOM_LE 5
|
||||
#define UPX_F_VXD_LE 6
|
||||
#define UPX_F_DOS_EXEH 7 /* OBSOLETE */
|
||||
#define UPX_F_TMT_ADAM 8
|
||||
#define UPX_F_WIN32_PE 9
|
||||
#define UPX_F_LINUX_i386 10
|
||||
#define UPX_F_WIN16_NE 11
|
||||
#define UPX_F_LINUX_ELF_i386 12
|
||||
#define UPX_F_LINUX_SEP_i386 13
|
||||
#define UPX_F_LINUX_SH_i386 14
|
||||
#define UPX_F_VMLINUZ_i386 15
|
||||
#define UPX_F_BVMLINUZ_i386 16
|
||||
#define UPX_F_ELKS_8086 17
|
||||
#define UPX_F_PS1_EXE 18
|
||||
#define UPX_F_VMLINUX_i386 19
|
||||
#define UPX_F_ATARI_TOS 129
|
||||
#define UPX_F_SOLARIS_SPARC 130
|
||||
|
||||
|
||||
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
|
||||
#define UPX_MAGIC2_LE32 0xD5D0D8A1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// globals
|
||||
**************************************************************************/
|
||||
|
||||
#include "unupx.h"
|
||||
|
||||
#include "snprintf.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
#include "stdcxx.h"
|
||||
#include "options.h"
|
||||
#include "except.h"
|
||||
#include "bele.h"
|
||||
#include "util.h"
|
||||
#include "console.h"
|
||||
|
||||
// options
|
||||
enum {
|
||||
CMD_NONE,
|
||||
CMD_COMPRESS, CMD_DECOMPRESS, CMD_TEST, CMD_LIST, CMD_FILEINFO,
|
||||
CMD_HELP, CMD_LICENSE, CMD_VERSION
|
||||
};
|
||||
|
||||
struct options_t {
|
||||
int cmd;
|
||||
|
||||
// compression options
|
||||
int method;
|
||||
int level; // compression level 1..10
|
||||
int mem_level; // memory level 1..9
|
||||
int filter; // preferred filter from Packer::getFilters()
|
||||
bool all_filters; // try all filters ?
|
||||
|
||||
// other options
|
||||
int backup;
|
||||
int console;
|
||||
int debug;
|
||||
int force;
|
||||
int info_mode;
|
||||
bool ignorewarn;
|
||||
bool no_env;
|
||||
bool no_progress;
|
||||
const char *output_name;
|
||||
int small;
|
||||
int verbose;
|
||||
bool to_stdout;
|
||||
|
||||
// overlay handling
|
||||
enum {
|
||||
SKIP_OVERLAY = 0,
|
||||
COPY_OVERLAY = 1,
|
||||
STRIP_OVERLAY = 2
|
||||
};
|
||||
int overlay;
|
||||
|
||||
// compression runtime parameters - see struct ucl_compress_config_t
|
||||
struct {
|
||||
upx_uint max_offset;
|
||||
upx_uint max_match;
|
||||
int s_level;
|
||||
int h_level;
|
||||
int p_level;
|
||||
int c_flags;
|
||||
upx_uint m_size;
|
||||
} crp;
|
||||
|
||||
// CPU
|
||||
enum {
|
||||
CPU_DEFAULT = 0,
|
||||
CPU_8086 = 1,
|
||||
CPU_286 = 2,
|
||||
CPU_386 = 3,
|
||||
CPU_486 = 4,
|
||||
CPU_586 = 5,
|
||||
CPU_686 = 6
|
||||
};
|
||||
int cpu;
|
||||
|
||||
// options for various executable formats
|
||||
struct {
|
||||
bool force_stub;
|
||||
bool no_reloc;
|
||||
} dos;
|
||||
struct {
|
||||
bool coff;
|
||||
} djgpp2;
|
||||
struct {
|
||||
bool split_segments;
|
||||
} tos;
|
||||
struct {
|
||||
unsigned blocksize;
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
} unix;
|
||||
struct {
|
||||
bool le;
|
||||
} wcle;
|
||||
struct {
|
||||
int compress_exports;
|
||||
int compress_icons;
|
||||
bool compress_resources;
|
||||
int strip_relocs;
|
||||
} w32pe;
|
||||
};
|
||||
|
||||
extern struct options_t * volatile opt;
|
||||
|
||||
|
||||
// main.cpp
|
||||
extern const char *progname;
|
||||
void init_options(struct options_t *o);
|
||||
bool set_ec(int ec);
|
||||
#if defined(__GNUC__)
|
||||
void e_exit(int ec) __attribute__((noreturn));
|
||||
void e_exit(int ec) __attribute__((__noreturn__));
|
||||
#else
|
||||
void e_exit(int ec);
|
||||
#endif
|
||||
@@ -549,28 +485,28 @@ void e_exit(int ec);
|
||||
void printSetNl(int need_nl);
|
||||
void printClearLine(FILE *f = NULL);
|
||||
void printErr(const char *iname, const Throwable *e);
|
||||
void printUnhandledException(const char *iname, const exception *e);
|
||||
void printUnhandledException(const char *iname, const std::exception *e);
|
||||
#if defined(__GNUC__)
|
||||
void printErr(const char *iname, const char *format, ...)
|
||||
__attribute__((format(printf,2,3)));
|
||||
void printWarn(const char *iname, const char *format, ...)
|
||||
__attribute__((format(printf,2,3)));
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(printf,2,3)));
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(printf,2,3)));
|
||||
#else
|
||||
void printErr(const char *iname, const char *format, ...);
|
||||
void printWarn(const char *iname, const char *format, ...);
|
||||
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__)
|
||||
void infoWarning(const char *format, ...)
|
||||
__attribute__((format(printf,1,2)));
|
||||
void infoHeader(const char *format, ...)
|
||||
__attribute__((format(printf,1,2)));
|
||||
void info(const char *format, ...)
|
||||
__attribute__((format(printf,1,2)));
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
void __acc_cdecl_va info(const char *format, ...)
|
||||
__attribute__((__format__(printf,1,2)));
|
||||
#else
|
||||
void infoWarning(const char *format, ...);
|
||||
void infoHeader(const char *format, ...);
|
||||
void info(const char *format, ...);
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...);
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...);
|
||||
void __acc_cdecl_va info(const char *format, ...);
|
||||
#endif
|
||||
void infoHeader();
|
||||
void infoWriting(const char *what, long size);
|
||||
@@ -590,41 +526,33 @@ void show_version(int);
|
||||
|
||||
|
||||
// compress.cpp
|
||||
#if defined(WITH_UCL)
|
||||
#define upx_compress_config_t ucl_compress_config_t
|
||||
#elif defined(WITH_NRV)
|
||||
struct nrv_compress_config_t;
|
||||
struct nrv_compress_config_t
|
||||
{
|
||||
int bb_endian;
|
||||
int bb_size;
|
||||
nrv_uint max_offset;
|
||||
nrv_uint max_match;
|
||||
int s_level;
|
||||
int h_level;
|
||||
int p_level;
|
||||
int c_flags;
|
||||
nrv_uint m_size;
|
||||
};
|
||||
#define upx_compress_config_t nrv_compress_config_t
|
||||
#endif
|
||||
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler=1);
|
||||
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc=0);
|
||||
|
||||
int upx_compress ( const upx_byte *src, upx_uint src_len,
|
||||
upx_byte *dst, upx_uint *dst_len,
|
||||
int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
upx_progress_callback_t *cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
upx_uintp result);
|
||||
int upx_decompress ( const upx_byte *src, upx_uint src_len,
|
||||
upx_byte *dst, upx_uint *dst_len,
|
||||
upx_uintp result );
|
||||
int upx_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
int method );
|
||||
int upx_test_overlap ( const upx_byte *buf, upx_uint src_off,
|
||||
upx_uint src_len, upx_uint *dst_len,
|
||||
int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
|
||||
upx_uint src_len, upx_uintp dst_len,
|
||||
int method );
|
||||
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
|
||||
# error "something pulled in <windows.h>"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
|
||||
@@ -1,240 +0,0 @@
|
||||
/* pseudo <config.h> for Linux */
|
||||
|
||||
#ifndef __UPX_CONFIG_H
|
||||
#define __UPX_CONFIG_H
|
||||
|
||||
/* $TOP$ */
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define if your C compiler doesn't accept -c and -o together. */
|
||||
/* #undef NO_MINUS_C_MINUS_O */
|
||||
|
||||
/* Define as the return type of signal handlers (int or void). */
|
||||
#define RETSIGTYPE void
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define if your memcmp is broken. */
|
||||
/* #undef NO_MEMCMP */
|
||||
|
||||
/* Define to `long' if <stddef.h> doesn't define. */
|
||||
/* #undef ptrdiff_t */
|
||||
|
||||
/* The number of bytes in a ptrdiff_t. */
|
||||
#define SIZEOF_PTRDIFF_T 4
|
||||
|
||||
/* The number of bytes in a size_t. */
|
||||
#define SIZEOF_SIZE_T 4
|
||||
|
||||
/* Define when using the dmalloc package. */
|
||||
/* #undef WITH_DMALLOC */
|
||||
|
||||
/* Define if you have the access function. */
|
||||
#define HAVE_ACCESS 1
|
||||
|
||||
/* Define if you have the atoi function. */
|
||||
#define HAVE_ATOI 1
|
||||
|
||||
/* Define if you have the chmod function. */
|
||||
#define HAVE_CHMOD 1
|
||||
|
||||
/* Define if you have the chown function. */
|
||||
#define HAVE_CHOWN 1
|
||||
|
||||
/* Define if you have the ctime function. */
|
||||
#define HAVE_CTIME 1
|
||||
|
||||
/* Define if you have the difftime function. */
|
||||
#define HAVE_DIFFTIME 1
|
||||
|
||||
/* Define if you have the fchmod function. */
|
||||
#define HAVE_FCHMOD 1
|
||||
|
||||
/* Define if you have the fileno function. */
|
||||
#define HAVE_FILENO 1
|
||||
|
||||
/* Define if you have the fstat function. */
|
||||
#define HAVE_FSTAT 1
|
||||
|
||||
/* Define if you have the XXX function. */
|
||||
#define HAVE_GETPID 1
|
||||
|
||||
/* Define if you have the XXX function. */
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
|
||||
/* Define if you have the getumask function. */
|
||||
/* #undef HAVE_GETUMASK */
|
||||
|
||||
/* Define if you have the gmtime function. */
|
||||
#define HAVE_GMTIME 1
|
||||
|
||||
/* Define if you have the index function. */
|
||||
#define HAVE_INDEX 1
|
||||
|
||||
/* Define if you have the isatty function. */
|
||||
#define HAVE_ISATTY 1
|
||||
|
||||
/* Define if you have the lstat function. */
|
||||
#define HAVE_LSTAT 1
|
||||
|
||||
/* Define if you have the localtime function. */
|
||||
#define HAVE_LOCALTIME 1
|
||||
|
||||
/* Define if you have the memcmp function. */
|
||||
#define HAVE_MEMCMP 1
|
||||
|
||||
/* Define if you have the memcpy function. */
|
||||
#define HAVE_MEMCPY 1
|
||||
|
||||
/* Define if you have the memmove function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define if you have the memset function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define if you have the mktime function. */
|
||||
#define HAVE_MKTIME 1
|
||||
|
||||
/* Define if you have the setmode function. */
|
||||
/* #undef HAVE_SETMODE */
|
||||
|
||||
/* Define if you have the stat function. */
|
||||
#define HAVE_STAT 1
|
||||
|
||||
/* Define if you have the strcasecmp function. */
|
||||
#define HAVE_STRCASECMP 1
|
||||
|
||||
/* Define if you have the strchr function. */
|
||||
#define HAVE_STRCHR 1
|
||||
|
||||
/* Define if you have the strdup function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define if you have the strftime function. */
|
||||
#define HAVE_STRFTIME 1
|
||||
|
||||
/* Define if you have the stricmp function. */
|
||||
/* #undef HAVE_STRICMP */
|
||||
|
||||
/* Define if you have the strncasecmp function. */
|
||||
#define HAVE_STRNCASECMP 1
|
||||
|
||||
/* Define if you have the strnicmp function. */
|
||||
/* #undef HAVE_STRNICMP */
|
||||
|
||||
/* Define if you have the strstr function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define if you have the tzset function. */
|
||||
#define HAVE_TZSET 1
|
||||
|
||||
/* Define if you have the umask function. */
|
||||
#define HAVE_UMASK 1
|
||||
|
||||
/* Define if you have the utime function. */
|
||||
#define HAVE_UTIME 1
|
||||
|
||||
/* Define if you have the vsnprintf function. */
|
||||
#define HAVE_VSNPRINTF 1
|
||||
|
||||
/* Define if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define if you have the <ctype.h> header file. */
|
||||
#define HAVE_CTYPE_H 1
|
||||
|
||||
/* Define if you have the <curses.h> header file. */
|
||||
#define HAVE_CURSES_H 1
|
||||
|
||||
/* Define if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define if you have the <linux/kd.h> header file. */
|
||||
#define HAVE_LINUX_KD_H 1
|
||||
|
||||
/* Define if you have the <linux/kdev_t.h> header file. */
|
||||
#define HAVE_LINUX_KDEV_T_H 1
|
||||
|
||||
/* Define if you have the <linux/major.h> header file. */
|
||||
#define HAVE_LINUX_MAJOR_H 1
|
||||
|
||||
/* Define if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define if you have the <ncurses.h> header file. */
|
||||
#define HAVE_NCURSES_H 1
|
||||
|
||||
/* Define if you have the <signal.h> header file. */
|
||||
#define HAVE_SIGNAL_H 1
|
||||
|
||||
/* Define if you have the <stddef.h> header file. */
|
||||
#define HAVE_STDDEF_H 1
|
||||
|
||||
/* Define if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define if you have the <sys/resource.h> header file. */
|
||||
#define HAVE_SYS_RESOURCE_H 1
|
||||
|
||||
/* Define if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define if you have the <sys/times.h> header file. */
|
||||
#define HAVE_SYS_TIMES_H 1
|
||||
|
||||
/* Define if you have the <sys/utime.h> header file. */
|
||||
/* #undef HAVE_SYS_UTIME_H */
|
||||
|
||||
/* Define if you have the <time.h> header file. */
|
||||
#define HAVE_TIME_H 1
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define if you have the <utime.h> header file. */
|
||||
#define HAVE_UTIME_H 1
|
||||
|
||||
/* $BOTTOM$ */
|
||||
|
||||
#if defined(HAVE_GMTIME) && !defined(TIME_WITH_SYS_TIME)
|
||||
# undef /**/ HAVE_GMTIME
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LOCALTIME) && !defined(TIME_WITH_SYS_TIME)
|
||||
# undef /**/ HAVE_LOCALTIME
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRFTIME) && !defined(TIME_WITH_SYS_TIME)
|
||||
# undef /**/ HAVE_STRFTIME
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_RESOURCE_H) && !defined(TIME_WITH_SYS_TIME)
|
||||
# undef /**/ HAVE_SYS_RESOURCE_H
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TIMES_H) && !defined(TIME_WITH_SYS_TIME)
|
||||
# undef /**/ HAVE_SYS_TIMES_H
|
||||
#endif
|
||||
|
||||
#if (SIZEOF_PTRDIFF_T <= 0)
|
||||
# undef /**/ SIZEOF_PTRDIFF_T
|
||||
#endif
|
||||
|
||||
#if (SIZEOF_SIZE_T <= 0)
|
||||
# undef /**/ SIZEOF_SIZE_T
|
||||
#endif
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
/*
|
||||
vi:ts=4
|
||||
*/
|
||||
+14
-11
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@
|
||||
#undef USE_CONSOLE
|
||||
#undef USE_ANSI
|
||||
#undef USE_SCREEN
|
||||
#undef USE_SCREEN_VCSA
|
||||
#undef USE_SCREEN_CURSES
|
||||
#undef USE_SCREEN_VCSA
|
||||
#undef USE_SCREEN_WIN32
|
||||
#undef USE_FRAMES
|
||||
|
||||
#if defined(WITH_GUI) && !defined(NO_CONSOLE)
|
||||
@@ -57,10 +58,12 @@
|
||||
|
||||
#if 1 && defined(__DJGPP__)
|
||||
# define USE_SCREEN
|
||||
#endif
|
||||
|
||||
#if 1 && defined(__MFX_WIN32)
|
||||
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_WIN32
|
||||
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_WIN32
|
||||
#endif
|
||||
|
||||
|
||||
@@ -120,10 +123,10 @@ console_t;
|
||||
|
||||
|
||||
#if defined(__GNUC__)
|
||||
void con_fprintf(FILE *f, const char *format, ...)
|
||||
__attribute__((format(printf,2,3)));
|
||||
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
|
||||
__attribute__((__format__(printf,2,3)));
|
||||
#else
|
||||
void con_fprintf(FILE *f, const char *format, ...);
|
||||
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+59
-14
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,14 +21,55 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
long Throwable::counter = 0;
|
||||
|
||||
Throwable::Throwable(const char *m, int e, bool w) NOTHROW
|
||||
: super(), msg(NULL), err(e), is_warning(w)
|
||||
{
|
||||
if (m)
|
||||
msg = strdup(m);
|
||||
#if 0
|
||||
fprintf(stderr, "construct exception: %s %ld\n", msg, counter);
|
||||
counter++;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Throwable::Throwable(const Throwable &other) NOTHROW
|
||||
: super(other), msg(NULL), err(other.err), is_warning(other.is_warning)
|
||||
{
|
||||
if (other.msg)
|
||||
msg = strdup(other.msg);
|
||||
#if 0
|
||||
fprintf(stderr, "copy exception: %s %ld\n", msg, counter);
|
||||
counter++;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Throwable::~Throwable() NOTHROW
|
||||
{
|
||||
#if 0
|
||||
counter--;
|
||||
fprintf(stderr, "destruct exception: %s %ld\n", msg, counter);
|
||||
#endif
|
||||
if (msg)
|
||||
free(msg);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compression
|
||||
**************************************************************************/
|
||||
@@ -133,20 +174,24 @@ void throwEOFException(const char *msg, int e)
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
const char *prettyName(const char *n)
|
||||
const char *prettyName(const char *n) NOTHROW
|
||||
{
|
||||
while (*n >= '0' && *n <= '9') // gcc / egcs
|
||||
n++;
|
||||
if (strncmp(n, "class ", 6) == 0) // Visual C++
|
||||
n += 6;
|
||||
if (n == NULL)
|
||||
return "(null)";
|
||||
while (*n)
|
||||
{
|
||||
if (*n >= '0' && *n <= '9') // Linux ABI
|
||||
n++;
|
||||
else if (*n == ' ')
|
||||
n++;
|
||||
else if (strncmp(n, "class ", 6) == 0) // Visual C++
|
||||
n += 6;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
const char *prettyName(const type_info &ti)
|
||||
{
|
||||
return prettyName(ti.name());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
|
||||
+46
-40
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -31,32 +31,38 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
const char *prettyName(const char *n);
|
||||
const char *prettyName(const type_info &ti);
|
||||
const char *prettyName(const char *n) NOTHROW;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// exceptions
|
||||
**************************************************************************/
|
||||
|
||||
class Throwable : public exception
|
||||
class Throwable : public std::exception
|
||||
{
|
||||
typedef std::exception super;
|
||||
protected:
|
||||
Throwable(const char *m = 0, int e = 0, bool w = false)
|
||||
: msg(m), err(e), is_warning(w) { }
|
||||
Throwable(const char *m = 0, int e = 0, bool w = false) NOTHROW;
|
||||
public:
|
||||
virtual ~Throwable() { }
|
||||
const char *getMsg() const { return msg; }
|
||||
int getErrno() const { return err; }
|
||||
bool isWarning() const { return is_warning; }
|
||||
Throwable(const Throwable &) NOTHROW;
|
||||
virtual ~Throwable() NOTHROW;
|
||||
const char *getMsg() const NOTHROW { return msg; }
|
||||
int getErrno() const NOTHROW { return err; }
|
||||
bool isWarning() const NOTHROW { return is_warning; }
|
||||
private:
|
||||
//Throwable(const Throwable &);
|
||||
private:
|
||||
// void * operator new(size_t); // ...
|
||||
const char *msg;
|
||||
char *msg;
|
||||
int err;
|
||||
protected:
|
||||
bool is_warning; // can be set by subclasses
|
||||
|
||||
private:
|
||||
// disable assignment
|
||||
Throwable& operator= (const Throwable &);
|
||||
// disable dynamic allocation
|
||||
DISABLE_NEW_DELETE
|
||||
|
||||
private:
|
||||
static long counter; // for debugging
|
||||
};
|
||||
|
||||
|
||||
@@ -65,7 +71,7 @@ class Exception : public Throwable
|
||||
{
|
||||
typedef Throwable super;
|
||||
public:
|
||||
Exception(const char *m = 0, int e = 0, bool w = false) : super(m,e,w) { }
|
||||
Exception(const char *m = 0, int e = 0, bool w = false) NOTHROW : super(m,e,w) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -74,7 +80,7 @@ class Error : public Throwable
|
||||
{
|
||||
typedef Throwable super;
|
||||
public:
|
||||
Error(const char *m = 0, int e = 0) : super(m,e) { }
|
||||
Error(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -86,7 +92,7 @@ class OutOfMemoryException : public Exception
|
||||
{
|
||||
typedef Exception super;
|
||||
public:
|
||||
OutOfMemoryException(const char *m = 0, int e = 0) : super(m,e) { }
|
||||
OutOfMemoryException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -94,7 +100,7 @@ class IOException : public Exception
|
||||
{
|
||||
typedef Exception super;
|
||||
public:
|
||||
IOException(const char *m = 0, int e = 0) : super(m,e) { }
|
||||
IOException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -102,7 +108,7 @@ class EOFException : public IOException
|
||||
{
|
||||
typedef IOException super;
|
||||
public:
|
||||
EOFException(const char *m = 0, int e = 0) : super(m,e) { }
|
||||
EOFException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -110,7 +116,7 @@ class FileNotFoundException : public IOException
|
||||
{
|
||||
typedef IOException super;
|
||||
public:
|
||||
FileNotFoundException(const char *m = 0, int e = 0) : super(m,e) { }
|
||||
FileNotFoundException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -118,7 +124,7 @@ class FileAlreadyExistsException : public IOException
|
||||
{
|
||||
typedef IOException super;
|
||||
public:
|
||||
FileAlreadyExistsException(const char *m = 0, int e = 0) : super(m,e) { }
|
||||
FileAlreadyExistsException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -130,35 +136,35 @@ class OverlayException : public Exception
|
||||
{
|
||||
typedef Exception super;
|
||||
public:
|
||||
OverlayException(const char *m = 0, bool w = false) : super(m,0,w) { }
|
||||
OverlayException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
|
||||
};
|
||||
|
||||
class CantPackException : public Exception
|
||||
{
|
||||
typedef Exception super;
|
||||
public:
|
||||
CantPackException(const char *m = 0, bool w = false) : super(m,0,w) { }
|
||||
CantPackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
|
||||
};
|
||||
|
||||
class UnknownExecutableFormatException : public CantPackException
|
||||
{
|
||||
typedef CantPackException super;
|
||||
public:
|
||||
UnknownExecutableFormatException(const char *m = 0, bool w = false) : super(m,w) { }
|
||||
UnknownExecutableFormatException(const char *m = 0, bool w = false) NOTHROW : super(m,w) { }
|
||||
};
|
||||
|
||||
class AlreadyPackedException : public CantPackException
|
||||
{
|
||||
typedef CantPackException super;
|
||||
public:
|
||||
AlreadyPackedException(const char *m = 0) : super(m) { is_warning = true; }
|
||||
AlreadyPackedException(const char *m = 0) NOTHROW : super(m) { is_warning = true; }
|
||||
};
|
||||
|
||||
class NotCompressibleException : public CantPackException
|
||||
{
|
||||
typedef CantPackException super;
|
||||
public:
|
||||
NotCompressibleException(const char *m = 0) : super(m) { }
|
||||
NotCompressibleException(const char *m = 0) NOTHROW : super(m) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -166,14 +172,14 @@ class CantUnpackException : public Exception
|
||||
{
|
||||
typedef Exception super;
|
||||
public:
|
||||
CantUnpackException(const char *m = 0, bool w = false) : super(m,0,w) { }
|
||||
CantUnpackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
|
||||
};
|
||||
|
||||
class NotPackedException : public CantUnpackException
|
||||
{
|
||||
typedef CantUnpackException super;
|
||||
public:
|
||||
NotPackedException(const char *m = 0) : super(m,true) { }
|
||||
NotPackedException(const char *m = 0) NOTHROW : super(m,true) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -185,7 +191,7 @@ class InternalError : public Error
|
||||
{
|
||||
typedef Error super;
|
||||
public:
|
||||
InternalError(const char *m = 0) : super(m,0) { }
|
||||
InternalError(const char *m = 0) NOTHROW : super(m,0) { }
|
||||
};
|
||||
|
||||
|
||||
@@ -196,25 +202,25 @@ public:
|
||||
#undef NORET
|
||||
#if 0 && defined(__GNUC__)
|
||||
// (noreturn) is probably not the correct semantics for throwing exceptions
|
||||
#define NORET __attribute__((noreturn))
|
||||
#define NORET __attribute__((__noreturn__))
|
||||
#else
|
||||
#define NORET
|
||||
#endif
|
||||
|
||||
void throwCantPack(const char *msg) NORET;
|
||||
void throwUnknownExecutableFormat(const char *msg = 0, bool warn = false) NORET;
|
||||
void throwNotCompressible(const char *msg = 0) NORET;
|
||||
void throwAlreadyPacked(const char *msg = 0) NORET;
|
||||
void throwAlreadyPackedByUPX(const char *msg = 0) NORET;
|
||||
void throwUnknownExecutableFormat(const char *msg = NULL, bool warn = false) NORET;
|
||||
void throwNotCompressible(const char *msg = NULL) NORET;
|
||||
void throwAlreadyPacked(const char *msg = NULL) NORET;
|
||||
void throwAlreadyPackedByUPX(const char *msg = NULL) NORET;
|
||||
void throwCantUnpack(const char *msg) NORET;
|
||||
void throwNotPacked(const char *msg = 0) NORET;
|
||||
void throwNotPacked(const char *msg = NULL) NORET;
|
||||
void throwFilterException() NORET;
|
||||
void throwBadLoader() NORET;
|
||||
void throwChecksumError() NORET;
|
||||
void throwCompressedDataViolation() NORET;
|
||||
void throwInternalError(const char *msg) NORET;
|
||||
void throwIOException(const char *msg = 0, int e = 0) NORET;
|
||||
void throwEOFException(const char *msg = 0, int e = 0) NORET;
|
||||
void throwIOException(const char *msg = NULL, int e = 0) NORET;
|
||||
void throwEOFException(const char *msg = NULL, int e = 0) NORET;
|
||||
|
||||
#undef NORET
|
||||
|
||||
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
/* fctl_ml.ch -- filter CTO implementation
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// these are not implemented here
|
||||
**************************************************************************/
|
||||
|
||||
// filter: e8, e9, e8e9
|
||||
#define f_cto32_e8 NULL
|
||||
#define f_cto32_e9 NULL
|
||||
#define f_cto32_e8e9 NULL
|
||||
|
||||
// unfilter: e8, e9, e8e9
|
||||
#define u_cto32_e8 NULL
|
||||
#define u_cto32_e9 NULL
|
||||
#define u_cto32_e8e9 NULL
|
||||
|
||||
// scan: e8, e9, e8e9
|
||||
#define s_cto32_e8 NULL
|
||||
#define s_cto32_e9 NULL
|
||||
#define s_cto32_e8e9 NULL
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap be->le
|
||||
#define f_cto32_e8_bswap_be NULL
|
||||
#define f_cto32_e9_bswap_be NULL
|
||||
#define f_cto32_e8e9_bswap_be NULL
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap be->le
|
||||
#define u_cto32_e8_bswap_be NULL
|
||||
#define u_cto32_e9_bswap_be NULL
|
||||
#define u_cto32_e8e9_bswap_be NULL
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap be->le
|
||||
#define s_cto32_e8_bswap_be NULL
|
||||
#define s_cto32_e9_bswap_be NULL
|
||||
#define s_cto32_e8e9_bswap_be NULL
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#define COND(b,x) (b[x] == 0xe8)
|
||||
#define F f_cto32_e8_bswap_le
|
||||
#define U u_cto32_e8_bswap_le
|
||||
#include "fcto_ml2.ch"
|
||||
#undef U
|
||||
#undef F
|
||||
#define F s_cto32_e8_bswap_le
|
||||
#include "fcto_ml2.ch"
|
||||
#undef F
|
||||
#undef COND
|
||||
|
||||
#define COND(b,x) (b[x] == 0xe9)
|
||||
#define F f_cto32_e9_bswap_le
|
||||
#define U u_cto32_e9_bswap_le
|
||||
#include "fcto_ml2.ch"
|
||||
#undef U
|
||||
#undef F
|
||||
#define F s_cto32_e9_bswap_le
|
||||
#include "fcto_ml2.ch"
|
||||
#undef F
|
||||
#undef COND
|
||||
|
||||
#define COND(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||
#define F f_cto32_e8e9_bswap_le
|
||||
#define U u_cto32_e8e9_bswap_le
|
||||
#include "fcto_ml2.ch"
|
||||
#undef U
|
||||
#undef F
|
||||
#define F s_cto32_e8e9_bswap_le
|
||||
#include "fcto_ml2.ch"
|
||||
#undef F
|
||||
#undef COND
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#define COND(b,x,lastcall) (b[x] == 0xe8 || b[x] == 0xe9 \
|
||||
|| (lastcall!=(x) && 0xf==b[(x)-1] \
|
||||
&& 0x80<=b[x] && b[x]<=0x8f) )
|
||||
#define F f_ctjo32_e8e9_bswap_le
|
||||
#define U u_ctjo32_e8e9_bswap_le
|
||||
#include "fcto_ml3.ch"
|
||||
#undef U
|
||||
#undef F
|
||||
#define F s_ctjo32_e8e9_bswap_le
|
||||
#include "fcto_ml3.ch"
|
||||
#undef F
|
||||
#undef COND
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+103
-94
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,13 +21,14 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "file.h"
|
||||
#include "mem.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -45,7 +46,7 @@ void File::chmod(const char *name, int mode)
|
||||
|
||||
void File::rename(const char *old_, const char *new_)
|
||||
{
|
||||
#if 1 && defined(__DJGPP__)
|
||||
#if defined(__DJGPP__)
|
||||
if (::_rename(old_,new_) != 0)
|
||||
#else
|
||||
if (::rename(old_,new_) != 0)
|
||||
@@ -85,6 +86,25 @@ FileBase::~FileBase()
|
||||
}
|
||||
|
||||
|
||||
void FileBase::sopen()
|
||||
{
|
||||
if (_shflags < 0)
|
||||
_fd = ::open(_name, _flags, _mode);
|
||||
else
|
||||
{
|
||||
#if defined(__DJGPP__)
|
||||
_fd = ::open(_name,_flags | _shflags, _mode);
|
||||
#elif defined(__MINT__)
|
||||
_fd = ::open(_name,_flags | (_shflags & O_SHMODE), _mode);
|
||||
#elif defined(SH_DENYRW)
|
||||
_fd = ::sopen(_name, _flags, _shflags, _mode);
|
||||
#else
|
||||
assert(0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FileBase::close()
|
||||
{
|
||||
bool ok = true;
|
||||
@@ -108,35 +128,19 @@ void FileBase::closex()
|
||||
|
||||
int FileBase::read(void *buf, int len)
|
||||
{
|
||||
int l;
|
||||
if (!isOpen() || len < 0)
|
||||
throwIOException("bad read");
|
||||
if (len == 0)
|
||||
return 0;
|
||||
for (;;)
|
||||
{
|
||||
#if 1 && defined(__DJGPP__)
|
||||
l = ::_read(_fd,buf,len);
|
||||
#else
|
||||
l = ::read(_fd,buf,len);
|
||||
#endif
|
||||
if (l < 0)
|
||||
{
|
||||
#if defined(EINTR)
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
#endif
|
||||
throwIOException("read error",errno);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return l;
|
||||
errno = 0;
|
||||
long l = acc_safe_hread(_fd, buf, len);
|
||||
if (errno)
|
||||
throwIOException("read error",errno);
|
||||
return (int) l;
|
||||
}
|
||||
|
||||
|
||||
int FileBase::readx(void *buf, int len)
|
||||
{
|
||||
int l = this->read(buf,len);
|
||||
int l = this->read(buf, len);
|
||||
if (l != len)
|
||||
throwEOFException();
|
||||
return l;
|
||||
@@ -145,43 +149,33 @@ int FileBase::readx(void *buf, int len)
|
||||
|
||||
void FileBase::write(const void *buf, int len)
|
||||
{
|
||||
int l;
|
||||
if (!isOpen() || len < 0)
|
||||
throwIOException("bad write");
|
||||
if (len == 0)
|
||||
return;
|
||||
for (;;)
|
||||
{
|
||||
#if 1 && defined(__DJGPP__)
|
||||
l = ::_write(_fd,buf,len);
|
||||
#else
|
||||
l = ::write(_fd,buf,len);
|
||||
#endif
|
||||
#if defined(EINTR)
|
||||
if (l < 0 && errno == EINTR)
|
||||
continue;
|
||||
#endif
|
||||
if (l != len)
|
||||
throwIOException("write error",errno);
|
||||
break;
|
||||
}
|
||||
errno = 0;
|
||||
long l = acc_safe_hwrite(_fd, buf, len);
|
||||
if (l != len)
|
||||
throwIOException("write error",errno);
|
||||
}
|
||||
|
||||
|
||||
void FileBase::seek(off_t off, int whence)
|
||||
{
|
||||
if (!isOpen())
|
||||
throwIOException("bad seek");
|
||||
throwIOException("bad seek 1");
|
||||
if (whence == SEEK_SET && off < 0)
|
||||
throwIOException("bad seek 2");
|
||||
if (whence == SEEK_END && off > 0)
|
||||
throwIOException("bad seek 3");
|
||||
if (::lseek(_fd,off,whence) < 0)
|
||||
throwIOException("seek error",errno);
|
||||
}
|
||||
|
||||
|
||||
off_t FileBase::tell()
|
||||
off_t FileBase::tell() const
|
||||
{
|
||||
if (!isOpen())
|
||||
throwIOException("bad tell");
|
||||
off_t l = ::lseek(_fd,0,SEEK_CUR);
|
||||
off_t l = ::lseek(_fd, 0, SEEK_CUR);
|
||||
if (l < 0)
|
||||
throwIOException("tell error",errno);
|
||||
return l;
|
||||
@@ -209,37 +203,53 @@ void InputFile::sopen(const char *name, int flags, int shflags)
|
||||
_flags = flags;
|
||||
_shflags = shflags;
|
||||
_mode = 0;
|
||||
if (shflags < 0)
|
||||
_fd = ::open(_name,_flags);
|
||||
else
|
||||
#if defined(__DJGPP__)
|
||||
_fd = ::open(_name,_flags | _shflags);
|
||||
#elif defined(SH_DENYRW)
|
||||
_fd = ::sopen(_name,_flags,_shflags);
|
||||
#else
|
||||
assert(0);
|
||||
#endif
|
||||
FileBase::sopen();
|
||||
if (!isOpen())
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
throw FileNotFoundException(_name,errno);
|
||||
throw FileNotFoundException(_name, errno);
|
||||
else if (errno == EEXIST)
|
||||
throw FileAlreadyExistsException(_name,errno);
|
||||
throw FileAlreadyExistsException(_name, errno);
|
||||
else
|
||||
throwIOException(_name,errno);
|
||||
throwIOException(_name, errno);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int InputFile::read(void *buf, int len)
|
||||
{
|
||||
return super::read(buf,len);
|
||||
return super::read(buf, len);
|
||||
}
|
||||
|
||||
|
||||
int InputFile::readx(void *buf, int len)
|
||||
{
|
||||
return super::readx(buf,len);
|
||||
return super::readx(buf, len);
|
||||
}
|
||||
|
||||
|
||||
int InputFile::read(MemBuffer *buf, int len)
|
||||
{
|
||||
buf->checkState();
|
||||
assert((unsigned)len <= buf->getSize());
|
||||
return read(buf->getVoidPtr(), len);
|
||||
}
|
||||
|
||||
int InputFile::readx(MemBuffer *buf, int len)
|
||||
{
|
||||
buf->checkState();
|
||||
assert((unsigned)len <= buf->getSize());
|
||||
return read(buf->getVoidPtr(), len);
|
||||
}
|
||||
|
||||
|
||||
int InputFile::read(MemBuffer &buf, int len)
|
||||
{
|
||||
return read(&buf, len);
|
||||
}
|
||||
|
||||
int InputFile::readx(MemBuffer &buf, int len)
|
||||
{
|
||||
return readx(&buf, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +259,7 @@ void InputFile::seek(off_t off, int whence)
|
||||
}
|
||||
|
||||
|
||||
off_t InputFile::tell()
|
||||
off_t InputFile::tell() const
|
||||
{
|
||||
return super::tell();
|
||||
}
|
||||
@@ -277,16 +287,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
|
||||
_flags = flags;
|
||||
_shflags = shflags;
|
||||
_mode = mode;
|
||||
if (shflags < 0)
|
||||
_fd = ::open(_name,_flags,_mode);
|
||||
else
|
||||
#if defined(__DJGPP__)
|
||||
_fd = ::open(_name,_flags | _shflags, _mode);
|
||||
#elif defined(SH_DENYRW)
|
||||
_fd = ::sopen(_name,_flags,_shflags,_mode);
|
||||
#else
|
||||
assert(0);
|
||||
#endif
|
||||
FileBase::sopen();
|
||||
if (!isOpen())
|
||||
{
|
||||
#if 0
|
||||
@@ -306,45 +307,48 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
|
||||
bool OutputFile::openStdout(int flags, bool force)
|
||||
{
|
||||
close();
|
||||
if (!force)
|
||||
{
|
||||
if (!isafile(STDOUT_FILENO))
|
||||
return false;
|
||||
}
|
||||
_fd = STDOUT_FILENO;
|
||||
int fd = STDOUT_FILENO;
|
||||
if (!force && acc_isatty(fd))
|
||||
return false;
|
||||
_name = "<stdout>";
|
||||
_flags = flags;
|
||||
_shflags = -1;
|
||||
_mode = 0;
|
||||
if (flags != 0)
|
||||
{
|
||||
assert(flags == O_BINARY);
|
||||
#if defined(HAVE_SETMODE) && defined(USE_SETMODE)
|
||||
if (setmode(_fd, O_BINARY) == -1)
|
||||
throwIOException(_name,errno);
|
||||
#if defined(__DJGPP__)
|
||||
__djgpp_set_ctrl_c(1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
if (flags && acc_set_binmode(fd, 1) == -1)
|
||||
throwIOException(_name, errno);
|
||||
_fd = fd;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void OutputFile::write(const void *buf, int len)
|
||||
{
|
||||
super::write(buf,len);
|
||||
super::write(buf, len);
|
||||
bytes_written += len;
|
||||
}
|
||||
|
||||
|
||||
void OutputFile::write(const MemBuffer *buf, int len)
|
||||
{
|
||||
buf->checkState();
|
||||
assert((unsigned)len <= buf->getSize());
|
||||
write(buf->getVoidPtr(), len);
|
||||
}
|
||||
|
||||
|
||||
void OutputFile::write(const MemBuffer &buf, int len)
|
||||
{
|
||||
write(&buf, len);
|
||||
}
|
||||
|
||||
|
||||
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
||||
{
|
||||
if (flags < 0)
|
||||
flags = O_CREAT | O_BINARY | O_TRUNC;
|
||||
flags |= O_WRONLY;
|
||||
OutputFile f;
|
||||
f.open(name, flags, 0666);
|
||||
f.open(name, flags, 0600);
|
||||
f.write(buf, len);
|
||||
f.closex();
|
||||
}
|
||||
@@ -354,6 +358,8 @@ void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
MemoryOutputFile::MemoryOutputFile() :
|
||||
b(NULL), b_size(0), b_pos(0), bytes_written(0)
|
||||
{
|
||||
@@ -374,6 +380,9 @@ void MemoryOutputFile::write(const void *buf, int len)
|
||||
}
|
||||
|
||||
|
||||
#endif /* if 0 */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+26
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,14 +21,16 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_FILE_H
|
||||
#define __UPX_FILE_H
|
||||
|
||||
class MemBuffer;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
@@ -36,6 +38,9 @@
|
||||
|
||||
class File
|
||||
{
|
||||
protected:
|
||||
File() { }
|
||||
virtual ~File() { }
|
||||
public:
|
||||
static void chmod(const char *name, int mode);
|
||||
static void rename(const char *old_, const char *new_);
|
||||
@@ -56,11 +61,12 @@ public:
|
||||
const char *getName() const { return _name; }
|
||||
|
||||
protected:
|
||||
void sopen();
|
||||
virtual int read(void *buf, int len);
|
||||
virtual int readx(void *buf, int len);
|
||||
virtual void write(const void *buf, int len);
|
||||
virtual void seek(off_t off, int whence);
|
||||
virtual off_t tell();
|
||||
virtual off_t tell() const;
|
||||
|
||||
int _fd;
|
||||
int _flags;
|
||||
@@ -89,11 +95,15 @@ public:
|
||||
sopen(name, flags, -1);
|
||||
}
|
||||
|
||||
virtual int read(void * buf, int len);
|
||||
virtual int readx(void * buf, int len);
|
||||
virtual int read(void *buf, int len);
|
||||
virtual int readx(void *buf, int len);
|
||||
virtual int read(MemBuffer *buf, int len);
|
||||
virtual int readx(MemBuffer *buf, int len);
|
||||
virtual int read(MemBuffer &buf, int len);
|
||||
virtual int readx(MemBuffer &buf, int len);
|
||||
|
||||
virtual void seek(off_t off, int whence);
|
||||
virtual off_t tell();
|
||||
virtual off_t tell() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -116,19 +126,25 @@ public:
|
||||
virtual bool openStdout(int flags=0, bool force=false);
|
||||
|
||||
virtual void write(const void *buf, int len);
|
||||
virtual void write(const MemBuffer *buf, int len);
|
||||
virtual void write(const MemBuffer &buf, int len);
|
||||
|
||||
off_t getBytesWritten() const { return bytes_written; }
|
||||
|
||||
#if (UPX_VERSION_HEX >= 0x019000)
|
||||
// FIXME - these won't work when using the `--stdout' option
|
||||
virtual void seek(off_t off, int whence)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
super::seek(off,whence);
|
||||
}
|
||||
virtual void rewrite(const void *buf, int len)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
write(buf, len);
|
||||
bytes_written -= len; // restore
|
||||
}
|
||||
#endif
|
||||
|
||||
// util
|
||||
static void dump(const char *name, const void *buf, int len, int flags=-1);
|
||||
@@ -142,6 +158,7 @@ protected:
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if 0 /* NOT USED */
|
||||
class MemoryOutputFile : public FileBase
|
||||
{
|
||||
typedef FileBase super;
|
||||
@@ -164,6 +181,7 @@ protected:
|
||||
unsigned b_pos;
|
||||
off_t bytes_written;
|
||||
};
|
||||
#endif /* if 0 */
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
+26
-22
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,13 +21,14 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "filter.h"
|
||||
#include "file.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -40,7 +41,7 @@ void initFilter(Filter *f, upx_byte *buf, unsigned buf_len)
|
||||
f->buf = buf;
|
||||
f->buf_len = buf_len;
|
||||
// clear output parameters
|
||||
f->calls = f->wrongcalls = f->noncalls = f->lastcall = 0;
|
||||
f->calls = f->wrongcalls = f->noncalls = f->firstcall = f->lastcall = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +79,13 @@ const FilterImp::FilterEntry *FilterImp::getFilter(int id)
|
||||
}
|
||||
|
||||
|
||||
bool Filter::isValidFilter(int filter_id)
|
||||
{
|
||||
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(filter_id);
|
||||
return fe != NULL;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// high level API
|
||||
**************************************************************************/
|
||||
@@ -88,10 +96,10 @@ void Filter::init(int id_, unsigned addvalue_)
|
||||
initFilter(this, NULL, 0);
|
||||
// clear input parameters
|
||||
this->addvalue = addvalue_;
|
||||
this->forced_cto = -1;
|
||||
this->preferred_ctos = NULL;
|
||||
// clear input/output parameters
|
||||
this->cto = 0;
|
||||
this->n_mru = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,13 +120,12 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
|
||||
throwInternalError("filter-2");
|
||||
|
||||
// save checksum
|
||||
this->adler = 0;
|
||||
if (clevel != 1)
|
||||
{
|
||||
this->adler = upx_adler32(0,NULL,0);
|
||||
this->adler = upx_adler32(this->adler, this->buf, this->buf_len);
|
||||
}
|
||||
this->adler = upx_adler32(this->buf, this->buf_len);
|
||||
|
||||
//printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
||||
//OutputFile::dump("filter.dat", buf, buf_len);
|
||||
int r = (*fe->do_filter)(this);
|
||||
//printf("filter: %02x %d\n", fe->id, r);
|
||||
if (r > 0)
|
||||
@@ -129,7 +136,7 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
|
||||
}
|
||||
|
||||
|
||||
bool Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
|
||||
void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
|
||||
{
|
||||
initFilter(this, buf_, buf_len_);
|
||||
|
||||
@@ -137,11 +144,11 @@ bool Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
|
||||
if (fe == NULL)
|
||||
throwInternalError("unfilter-1");
|
||||
if (fe->id == 0)
|
||||
return true;
|
||||
return;
|
||||
if (buf_len < fe->min_buf_len)
|
||||
return false;
|
||||
return;
|
||||
if (fe->max_buf_len && buf_len > fe->max_buf_len)
|
||||
return false;
|
||||
return;
|
||||
if (!fe->do_unfilter)
|
||||
throwInternalError("unfilter-2");
|
||||
|
||||
@@ -150,20 +157,18 @@ bool Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
|
||||
//printf("unfilter: %02x %d\n", fe->id, r);
|
||||
if (r != 0)
|
||||
throwInternalError("unfilter-3");
|
||||
//OutputFile::dump("unfilter.dat", buf, buf_len);
|
||||
|
||||
// verify checksum
|
||||
if (verify_checksum && clevel != 1)
|
||||
{
|
||||
unsigned a = upx_adler32(0,NULL,0);
|
||||
if (this->adler != upx_adler32(a, this->buf, this->buf_len))
|
||||
if (this->adler != upx_adler32(this->buf, this->buf_len))
|
||||
throwInternalError("unfilter-4");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Filter::verifyUnfilter()
|
||||
void Filter::verifyUnfilter()
|
||||
{
|
||||
// Note:
|
||||
// This verify is just because of complete paranoia that there
|
||||
@@ -175,9 +180,8 @@ bool Filter::verifyUnfilter()
|
||||
// Packer::verifyOverlappingDecompression()
|
||||
|
||||
//printf("verifyUnfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
||||
if (clevel == 1)
|
||||
return true;
|
||||
return unfilter(this->buf, this->buf_len, true);
|
||||
if (clevel != 1)
|
||||
unfilter(this->buf, this->buf_len, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+11
-9
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ class FilterImp;
|
||||
// call throwFilterException() - this will cause the compression
|
||||
// to fail.
|
||||
//
|
||||
// The return value of unfilters can/should be ignored. They throw
|
||||
// exceptions in case of errors.
|
||||
// Unfilters throw exceptions in case of errors.
|
||||
//
|
||||
// The main idea behind filters is to convert relative jumps and calls
|
||||
// to absolute addresses so that the buffer compresses better.
|
||||
@@ -58,10 +57,12 @@ public:
|
||||
void init(int id=0, unsigned addvalue=0);
|
||||
|
||||
bool filter(upx_byte *buf, unsigned buf_len);
|
||||
bool unfilter(upx_byte *buf, unsigned buf_len, bool verify_checksum=false);
|
||||
bool verifyUnfilter();
|
||||
void unfilter(upx_byte *buf, unsigned buf_len, bool verify_checksum=false);
|
||||
void verifyUnfilter();
|
||||
bool scan(const upx_byte *buf, unsigned buf_len);
|
||||
|
||||
static bool isValidFilter(int filter_id);
|
||||
|
||||
public:
|
||||
// Will be set by each call to filter()/unfilter().
|
||||
// Read-only afterwards.
|
||||
@@ -74,7 +75,6 @@ public:
|
||||
|
||||
// Input parameters used by various filters.
|
||||
unsigned addvalue;
|
||||
int forced_cto;
|
||||
const int *preferred_ctos;
|
||||
|
||||
// Input/output parameters used by various filters
|
||||
@@ -84,7 +84,9 @@ public:
|
||||
unsigned calls;
|
||||
unsigned noncalls;
|
||||
unsigned wrongcalls;
|
||||
unsigned firstcall;
|
||||
unsigned lastcall;
|
||||
unsigned n_mru; // ctojr only
|
||||
|
||||
// Read only.
|
||||
int id;
|
||||
|
||||
+390
@@ -0,0 +1,390 @@
|
||||
/* ct.h -- calltrick filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 16-bit calltrick ("naive")
|
||||
**************************************************************************/
|
||||
|
||||
#define CT16(f, cond, addvalue, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 3; \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b) + (addvalue)); \
|
||||
f->calls++; \
|
||||
b += 2 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 2; \
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9
|
||||
static int f_ct16_e8(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e8e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9
|
||||
static int u_ct16_e8(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e8e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9
|
||||
static int s_ct16_e8(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e8e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap le->be
|
||||
static int f_ct16_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int f_ct16_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int f_ct16_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap le->be
|
||||
static int u_ct16_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap le->be
|
||||
static int s_ct16_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap be->le
|
||||
static int f_ct16_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap be->le
|
||||
static int u_ct16_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int u_ct16_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int u_ct16_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap be->le
|
||||
static int s_ct16_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef CT16
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 32-bit calltrick ("naive")
|
||||
**************************************************************************/
|
||||
|
||||
#define CT32(f, cond, addvalue, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 5; \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b) + (addvalue)); \
|
||||
f->calls++; \
|
||||
b += 4 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 4; \
|
||||
return 0;
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9
|
||||
static int f_ct32_e8(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e8e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9
|
||||
static int u_ct32_e8(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e8e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9
|
||||
static int s_ct32_e8(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e8e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap le->be
|
||||
static int f_ct32_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int f_ct32_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int f_ct32_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap le->be
|
||||
static int u_ct32_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap le->be
|
||||
static int s_ct32_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap be->le
|
||||
static int f_ct32_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap be->le
|
||||
static int u_ct32_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int u_ct32_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int u_ct32_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap be->le
|
||||
static int s_ct32_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef CT32
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* fctl_ml2.ch -- filter CTO implementation
|
||||
/* cto.h -- calltrick filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,14 +21,14 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
// filter / scan
|
||||
**************************************************************************/
|
||||
|
||||
static int F(Filter *f)
|
||||
@@ -44,64 +44,27 @@ static int F(Filter *f)
|
||||
const unsigned size = f->buf_len;
|
||||
|
||||
unsigned ic, jc, kc;
|
||||
unsigned cto;
|
||||
unsigned char cto8;
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
if (f->forced_cto >= 0 && f->forced_cto <= 255)
|
||||
cto8 = (unsigned char) f->forced_cto;
|
||||
else
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
|
||||
#if 1
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
#else
|
||||
{
|
||||
int i = size - 6;
|
||||
do {
|
||||
if (COND(b,i) && get_le32(b+i+1)+i+1 >= size)
|
||||
buf[b[i+1]] |= 1;
|
||||
} while (--i >= 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
ic = 256;
|
||||
if (f->preferred_ctos)
|
||||
{
|
||||
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
|
||||
{
|
||||
if (buf[*pc & 255] == 0)
|
||||
{
|
||||
ic = *pc & 255;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// just a test to see if certain ctos would improve compression
|
||||
if (ic >= 256)
|
||||
for (ic = 0; ic < 256; ic += 16)
|
||||
if (buf[ic] == 0)
|
||||
break;
|
||||
#endif
|
||||
if (ic >= 256)
|
||||
for (ic = 0; ic < 256; ic++)
|
||||
if (buf[ic] == 0)
|
||||
break;
|
||||
if (ic >= 256)
|
||||
//throwCantPack("call trick problem");
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
cto8 = (unsigned char) ic;
|
||||
}
|
||||
cto = (unsigned)cto8 << 24;
|
||||
const unsigned char cto8 = f->cto;
|
||||
#ifdef U
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
#endif
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
{
|
||||
@@ -145,7 +108,6 @@ static int F(Filter *f)
|
||||
}
|
||||
}
|
||||
|
||||
f->cto = cto8;
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
@@ -157,13 +119,17 @@ static int F(Filter *f)
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// unfilter
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef U
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size5 = f->buf_len - 5;
|
||||
const unsigned addvalue = f->addvalue;
|
||||
const unsigned cto = f->cto << 24;
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
|
||||
unsigned ic, jc;
|
||||
|
||||
@@ -186,7 +152,11 @@ static int U(Filter *f)
|
||||
#endif
|
||||
|
||||
|
||||
#undef F
|
||||
#undef U
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* fctl_ml3.ch -- filter CTO implementation
|
||||
/* ctoj.h -- filter CTO implementation
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
Copyright (C) 2000 John F. Reiser
|
||||
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
|
||||
@@ -22,14 +22,17 @@
|
||||
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@jk.uni-linz.ac.at 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>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
// filter / scan
|
||||
**************************************************************************/
|
||||
|
||||
static int F(Filter *f)
|
||||
@@ -45,64 +48,27 @@ static int F(Filter *f)
|
||||
const unsigned size = f->buf_len;
|
||||
|
||||
unsigned ic, jc, kc;
|
||||
unsigned cto;
|
||||
unsigned char cto8;
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
if (f->forced_cto >= 0 && f->forced_cto <= 255)
|
||||
cto8 = (unsigned char) f->forced_cto;
|
||||
else
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
|
||||
#if 1
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
#else
|
||||
{
|
||||
int i = size - 6;
|
||||
do {
|
||||
if (COND(b,i,lastcall) && get_le32(b+i+1)+i+1 >= size)
|
||||
buf[b[i+1]] |= 1;
|
||||
} while (--i >= 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
ic = 256;
|
||||
if (f->preferred_ctos)
|
||||
{
|
||||
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
|
||||
{
|
||||
if (buf[*pc & 255] == 0)
|
||||
{
|
||||
ic = *pc & 255;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// just a test to see if certain ctos would improve compression
|
||||
if (ic >= 256)
|
||||
for (ic = 0; ic < 256; ic += 16)
|
||||
if (buf[ic] == 0)
|
||||
break;
|
||||
#endif
|
||||
if (ic >= 256)
|
||||
for (ic = 0; ic < 256; ic++)
|
||||
if (buf[ic] == 0)
|
||||
break;
|
||||
if (ic >= 256)
|
||||
//throwCantPack("call trick problem");
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
cto8 = (unsigned char) ic;
|
||||
}
|
||||
cto = (unsigned)cto8 << 24;
|
||||
const unsigned char cto8 = f->cto;
|
||||
#ifdef U
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
#endif
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
{
|
||||
@@ -146,7 +112,6 @@ static int F(Filter *f)
|
||||
}
|
||||
}
|
||||
|
||||
f->cto = cto8;
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
@@ -158,15 +123,18 @@ static int F(Filter *f)
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// unfilter
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef U
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size5 = f->buf_len - 5;
|
||||
const unsigned addvalue = f->addvalue;
|
||||
const unsigned cto = f->cto << 24;
|
||||
unsigned lastcall = 0;
|
||||
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
// unsigned lastcall = 0; // lastcall is not used in COND macro
|
||||
unsigned ic, jc;
|
||||
|
||||
for (ic = 0; ic < size5; ic++)
|
||||
@@ -178,7 +146,7 @@ static int U(Filter *f)
|
||||
set_le32(b+ic+1,jc-ic-1-addvalue-cto);
|
||||
f->calls++;
|
||||
ic += 4;
|
||||
f->lastcall = lastcall = ic+1;
|
||||
f->lastcall = ic+1;
|
||||
}
|
||||
else
|
||||
f->noncalls++;
|
||||
@@ -188,7 +156,11 @@ static int U(Filter *f)
|
||||
#endif
|
||||
|
||||
|
||||
#undef F
|
||||
#undef U
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
/* ctojr.h -- filter CTO implementation; renumber destinations MRU
|
||||
|
||||
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>
|
||||
*/
|
||||
|
||||
|
||||
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1300))
|
||||
# pragma warning(disable: 4702) // W4: unreachable code
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// filter / scan
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef U //{
|
||||
#define NOFILT 0 // no filter
|
||||
#define FNOMRU 1 // filter, but not using mru
|
||||
#define MRUFLT 2 // mru filter
|
||||
|
||||
static unsigned
|
||||
f80_call(Filter const *f)
|
||||
{
|
||||
return (1+ (0x0f & f->id)) % 3;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
f80_jmp1(Filter const *f)
|
||||
{
|
||||
return ((1+ (0x0f & f->id)) / 3) % 3;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
f80_jcc2(Filter const *f)
|
||||
{
|
||||
return f80_jmp1(f);
|
||||
}
|
||||
|
||||
static int const N_MRU = 32; // does not have to be a power of 2
|
||||
|
||||
// Adaptively remember recent destinations.
|
||||
static void
|
||||
update_mru(
|
||||
unsigned const jc, // destination address
|
||||
int const kh, // mru[kh] is slot where found
|
||||
unsigned mru[N_MRU], // circular buffer of most recent destinations
|
||||
int &hand, // mru[hand] is most recent destination
|
||||
int &tail // mru[tail] is beyond oldest destination ("cold cache" startup)
|
||||
)
|
||||
{
|
||||
if (0 > --hand) {
|
||||
hand = N_MRU -1;
|
||||
}
|
||||
unsigned const t = mru[hand]; // entry which will be overwritten by jc
|
||||
if (0!=t) { // have seen at least N_MRU destinations
|
||||
mru[kh] = t;
|
||||
}
|
||||
else { // "cold cache": keep active region contiguous
|
||||
if (0 > --tail) {
|
||||
tail = N_MRU -1;
|
||||
}
|
||||
unsigned const t2 = mru[tail];
|
||||
mru[tail] = 0;
|
||||
mru[kh] = t2;
|
||||
}
|
||||
mru[hand] = jc;
|
||||
}
|
||||
#endif //}
|
||||
|
||||
|
||||
static int F(Filter *f)
|
||||
{
|
||||
#ifdef U
|
||||
// filter
|
||||
upx_byte *const b = f->buf;
|
||||
#else
|
||||
// scan
|
||||
const upx_byte *b = f->buf;
|
||||
#endif
|
||||
const unsigned size = f->buf_len;
|
||||
|
||||
unsigned ic, jc, kc;
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
unsigned wtally[3]; memset(wtally, 0, sizeof(wtally));
|
||||
|
||||
#ifdef U //{
|
||||
unsigned const f_call = f80_call(f);
|
||||
unsigned const f_jmp1 = f80_jmp1(f);
|
||||
unsigned const f_jcc2 = f80_jcc2(f);
|
||||
|
||||
int hand = 0, tail = 0;
|
||||
unsigned mru[N_MRU];
|
||||
memset(&mru[0], 0, sizeof(mru));
|
||||
assert(N_MRU<=256);
|
||||
f->n_mru = (MRUFLT==f_call || MRUFLT==f_jmp1 || MRUFLT==f_jcc2) ?
|
||||
N_MRU : 0;
|
||||
#endif //}
|
||||
|
||||
// FIXME: We must fit into 8MB because we steal one bit.
|
||||
// find a 16MB large empty address space
|
||||
{
|
||||
int which;
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (CONDF(which,b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
UNUSED(which);
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
}
|
||||
const unsigned char cto8 = f->cto;
|
||||
#ifdef U
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
#endif
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
{
|
||||
int which;
|
||||
int f_on = 0;
|
||||
if (!CONDF(which,b,ic,lastcall))
|
||||
continue;
|
||||
++wtally[which];
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
#ifdef U
|
||||
if (2==which && NOFILT!=f_jcc2) { // 6-byte Jcc <disp32>
|
||||
// Prefix 0x0f is constant, but opcode condition 0x80..0x8f
|
||||
// varies. Because we store the destination (or its mru index)
|
||||
// in be32 big endian format, the low-addressed bytes
|
||||
// will tend to be constant. Swap prefix and opcode
|
||||
// so that constants are together for better compression.
|
||||
unsigned char const t =
|
||||
b[ic-1];
|
||||
b[ic-1] = b[ic];
|
||||
b[ic] = t;
|
||||
}
|
||||
// FIXME [?]: Extend to 8 bytes if "ADD ESP, byte 4*n" follows CALL.
|
||||
// This will require two related cto's (consecutive, or otherwise).
|
||||
if ((0==which && MRUFLT==f_call)
|
||||
|| (1==which && MRUFLT==f_jmp1)
|
||||
|| (2==which && MRUFLT==f_jcc2) ) {
|
||||
f_on = 1;
|
||||
// Recode the destination: narrower mru indices
|
||||
// should compress better than wider addresses.
|
||||
// (But not when offset of match is unlimited?)
|
||||
int k;
|
||||
for (k = 0; k < N_MRU; ++k) {
|
||||
int kh = hand + k;
|
||||
if (N_MRU <= kh) {
|
||||
kh -= N_MRU;
|
||||
}
|
||||
if (mru[kh] == jc) { // destination was seen recently
|
||||
set_be32(b+ic+1,((k<<1)|0)+cto);
|
||||
update_mru(jc, kh, mru, hand, tail);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (k == N_MRU) { // loop failed; jc is not in mru[]
|
||||
set_be32(b+ic+1,((jc<<1)|1)+cto);
|
||||
// Adaptively remember recent destinations.
|
||||
if (0 > --hand) {
|
||||
hand = N_MRU -1;
|
||||
}
|
||||
mru[hand] = jc;
|
||||
}
|
||||
} else
|
||||
if ((0==which && NOFILT!=f_call)
|
||||
|| (1==which && NOFILT!=f_jmp1)
|
||||
|| (2==which && NOFILT!=f_jcc2) ) {
|
||||
f_on = 1;
|
||||
set_be32(b+ic+1, jc+cto);
|
||||
}
|
||||
#endif
|
||||
if (f_on) {
|
||||
if (ic - lastnoncall < 5)
|
||||
{
|
||||
// check the last 4 bytes before this call
|
||||
for (kc = 4; kc; kc--)
|
||||
if (CONDF(which,b,ic-kc,lastcall) && b[ic-kc+1] == cto8)
|
||||
break;
|
||||
if (kc)
|
||||
{
|
||||
#ifdef U
|
||||
// restore original
|
||||
if (2==which) {
|
||||
// Unswap prefix and opcode for 6-byte Jcc <disp32>
|
||||
unsigned char const t =
|
||||
b[ic-1];
|
||||
b[ic-1] = b[ic];
|
||||
b[ic] = t;
|
||||
}
|
||||
set_le32(b+ic+1,jc-ic-1);
|
||||
#endif
|
||||
if (b[ic+1] == cto8)
|
||||
return 1; // fail - buffer not restored
|
||||
lastnoncall = ic;
|
||||
noncalls2++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
calls++;
|
||||
ic += 4;
|
||||
lastcall = ic+1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(b[ic+1] != cto8); // this should not happen
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
}
|
||||
}
|
||||
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
/*#ifdef TESTING*/
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",
|
||||
calls,noncalls,noncalls2,size,cto8);
|
||||
printf("CALL/JMP/JCC %d %d %d\n",wtally[0],wtally[1],wtally[2]);
|
||||
/*#endif*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// unfilter
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef U
|
||||
static int U(Filter *f)
|
||||
{
|
||||
unsigned ic, jc;
|
||||
|
||||
upx_byte *const b = f->buf;
|
||||
const unsigned size5 = f->buf_len - 5;
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
unsigned lastcall = 0;
|
||||
int hand = 0, tail = 0;
|
||||
unsigned const f_call = f80_call(f);
|
||||
unsigned const f_jmp1 = f80_jmp1(f);
|
||||
unsigned const f_jcc2 = f80_jcc2(f);
|
||||
|
||||
unsigned mru[N_MRU];
|
||||
memset(&mru[0], 0, sizeof(mru));
|
||||
|
||||
for (ic = 0; ic < size5; ic++) {
|
||||
int which;
|
||||
if (CONDU(which,b,ic,lastcall))
|
||||
{
|
||||
unsigned f_on = 0;
|
||||
jc = get_be32(b+ic+1) - cto;
|
||||
if (b[ic+1] == f->cto)
|
||||
{
|
||||
if ((0==which && MRUFLT==f_call)
|
||||
|| (1==which && MRUFLT==f_jmp1)
|
||||
|| (2==which && MRUFLT==f_jcc2) ) {
|
||||
f_on = 1;
|
||||
if (1&jc) { // 1st time at this destination
|
||||
jc >>= 1;
|
||||
if (0 > --hand) {
|
||||
hand = N_MRU -1;
|
||||
}
|
||||
mru[hand] = jc;
|
||||
}
|
||||
else { // not 1st time at this destination
|
||||
jc >>= 1;
|
||||
int kh = jc + hand;
|
||||
if (N_MRU <= kh) {
|
||||
kh -= N_MRU;
|
||||
}
|
||||
jc = mru[kh];
|
||||
update_mru(jc, kh, mru, hand, tail);
|
||||
}
|
||||
set_le32(b+ic+1,jc-ic-1);
|
||||
} else
|
||||
if ((0==which && NOFILT!=f_call)
|
||||
|| (1==which && NOFILT!=f_jmp1)
|
||||
|| (2==which && NOFILT!=f_jcc2) ) {
|
||||
f_on = 1;
|
||||
set_le32(b+ic+1,jc-ic-1);
|
||||
}
|
||||
if (2==which && NOFILT!=f_jcc2) {
|
||||
// Unswap prefix and opcode for 6-byte Jcc <disp32>
|
||||
unsigned char const t =
|
||||
b[ic-1];
|
||||
b[ic-1] = b[ic];
|
||||
b[ic] = t;
|
||||
}
|
||||
|
||||
if (f_on) {
|
||||
f->calls++;
|
||||
ic += 4;
|
||||
f->lastcall = lastcall = ic+1;
|
||||
}
|
||||
}
|
||||
else
|
||||
f->noncalls++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#undef F
|
||||
#undef U
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/* ctok.h -- filter CTO implementation
|
||||
|
||||
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>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// filter / scan
|
||||
**************************************************************************/
|
||||
|
||||
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 = f->buf_len;
|
||||
unsigned const id = f->id;
|
||||
|
||||
unsigned ic, jc, kc;
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic,lastcall,id) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
}
|
||||
const unsigned char cto8 = f->cto;
|
||||
#ifdef U
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
#endif
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
{
|
||||
if (!COND(b,ic,lastcall,id))
|
||||
continue;
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
#ifdef U
|
||||
set_be32(b+ic+1,jc+addvalue+cto);
|
||||
#endif
|
||||
if (ic - lastnoncall < 5)
|
||||
{
|
||||
// check the last 4 bytes before this call
|
||||
for (kc = 4; kc; kc--)
|
||||
if (COND(b,ic-kc,lastcall,id) && b[ic-kc+1] == cto8)
|
||||
break;
|
||||
if (kc)
|
||||
{
|
||||
#ifdef U
|
||||
// restore original
|
||||
set_le32(b+ic+1,jc-ic-1);
|
||||
#endif
|
||||
if (b[ic+1] == cto8)
|
||||
return 1; // fail - buffer not restored
|
||||
lastnoncall = ic;
|
||||
noncalls2++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
calls++;
|
||||
ic += 4;
|
||||
lastcall = ic+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(b[ic+1] != cto8); // this should not happen
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
}
|
||||
}
|
||||
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#ifdef TESTING
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// unfilter
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef U
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size5 = f->buf_len - 5;
|
||||
const unsigned addvalue = f->addvalue;
|
||||
const unsigned cto = (unsigned)f->cto << 24;
|
||||
unsigned const id = f->id;
|
||||
unsigned lastcall = 0;
|
||||
|
||||
unsigned ic, jc;
|
||||
|
||||
for (ic = 0; ic < size5; ic++)
|
||||
if (COND(b,ic,lastcall,id))
|
||||
{
|
||||
jc = get_be32(b+ic+1);
|
||||
if (b[ic+1] == f->cto)
|
||||
{
|
||||
set_le32(b+ic+1,jc-ic-1-addvalue-cto);
|
||||
f->calls++;
|
||||
ic += 4;
|
||||
f->lastcall = lastcall = ic+1;
|
||||
}
|
||||
else
|
||||
f->noncalls++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#undef F
|
||||
#undef U
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
/* ctsw.h -- call-/swaptrick filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 16-bit call-/swaptrick ("naive")
|
||||
**************************************************************************/
|
||||
|
||||
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 3; \
|
||||
do { \
|
||||
if (cond1) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b) + (addvalue)); \
|
||||
f->calls++; \
|
||||
b += 2 - 1; \
|
||||
} \
|
||||
else if (cond2) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b)); \
|
||||
f->calls++; \
|
||||
b += 2 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 2; \
|
||||
return 0;
|
||||
|
||||
|
||||
// filter
|
||||
static int f_ctsw16_e8_e9(Filter *f)
|
||||
{
|
||||
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int f_ctsw16_e9_e8(Filter *f)
|
||||
{
|
||||
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter
|
||||
static int u_ctsw16_e8_e9(Filter *f)
|
||||
{
|
||||
CTSW16(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ctsw16_e9_e8(Filter *f)
|
||||
{
|
||||
CTSW16(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// scan
|
||||
static int s_ctsw16_e8_e9(Filter *f)
|
||||
{
|
||||
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ctsw16_e9_e8(Filter *f)
|
||||
{
|
||||
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef CTSW16
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 32-bit call-/swaptrick ("naive")
|
||||
**************************************************************************/
|
||||
|
||||
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 5; \
|
||||
do { \
|
||||
if (cond1) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b) + (addvalue)); \
|
||||
f->calls++; \
|
||||
b += 4 - 1; \
|
||||
} \
|
||||
else if (cond2) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b)); \
|
||||
f->calls++; \
|
||||
b += 4 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 4; \
|
||||
return 0;
|
||||
|
||||
|
||||
// filter
|
||||
static int f_ctsw32_e8_e9(Filter *f)
|
||||
{
|
||||
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int f_ctsw32_e9_e8(Filter *f)
|
||||
{
|
||||
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter
|
||||
static int u_ctsw32_e8_e9(Filter *f)
|
||||
{
|
||||
CTSW32(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ctsw32_e9_e8(Filter *f)
|
||||
{
|
||||
CTSW32(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// scan
|
||||
static int s_ctsw32_e8_e9(Filter *f)
|
||||
{
|
||||
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ctsw32_e9_e8(Filter *f)
|
||||
{
|
||||
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef CTSW32
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/* getcto.h -- calltrick util
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
static int getcto(Filter *f, const unsigned char *buf, const int n=256)
|
||||
{
|
||||
int ic = n;
|
||||
|
||||
if (f->preferred_ctos)
|
||||
{
|
||||
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
|
||||
{
|
||||
if (*pc < n && buf[*pc] == 0)
|
||||
{
|
||||
ic = *pc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// just a test to see if certain ctos would improve compression
|
||||
if (ic >= n)
|
||||
for (ic = 0; ic < n; ic += 16)
|
||||
if (buf[ic] == 0)
|
||||
break;
|
||||
#endif
|
||||
if (ic >= n)
|
||||
for (ic = 0; ic < n; ic++)
|
||||
if (buf[ic] == 0)
|
||||
break;
|
||||
|
||||
if (ic >= n)
|
||||
//throwCantPack("call trick problem");
|
||||
return -1;
|
||||
|
||||
f->cto = (unsigned char) ic;
|
||||
return ic;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/* sub.hh -- simple delta filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#define SUB(f, N, T, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
unsigned l = f->buf_len / sizeof(T); \
|
||||
int i; \
|
||||
T d[N]; \
|
||||
\
|
||||
i = N - 1; do d[i] = 0; while (--i >= 0); \
|
||||
\
|
||||
i = N - 1; \
|
||||
do { \
|
||||
T delta = (T) (get(b) - d[i]); \
|
||||
set(b, delta); \
|
||||
d[i] = (T) (d[i] + delta); \
|
||||
b += sizeof(T); \
|
||||
if (--i < 0) \
|
||||
i = N - 1; \
|
||||
} while (--l > 0); \
|
||||
f->calls = (f->buf_len / sizeof(T)) - N; \
|
||||
assert((int)f->calls > 0); \
|
||||
return 0;
|
||||
|
||||
|
||||
#define ADD(f, N, T, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
unsigned l = f->buf_len / sizeof(T); \
|
||||
int i; \
|
||||
T d[N]; \
|
||||
\
|
||||
i = N - 1; do d[i] = 0; while (--i >= 0); \
|
||||
\
|
||||
i = N - 1; \
|
||||
do { \
|
||||
d[i] = (T) (d[i] + get(b)); \
|
||||
set(b, d[i]); \
|
||||
b += sizeof(T); \
|
||||
if (--i < 0) \
|
||||
i = N - 1; \
|
||||
} while (--l > 0); \
|
||||
f->calls = (f->buf_len / sizeof(T)) - N; \
|
||||
assert((int)f->calls > 0); \
|
||||
return 0;
|
||||
|
||||
|
||||
#define SCAN(f, N, T, get, set) \
|
||||
f->calls = (f->buf_len / sizeof(T)) - N; \
|
||||
assert((int)f->calls > 0); \
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/* sub16.h -- simple delta filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#include "sub.hh"
|
||||
|
||||
#define SUB16(f, N) SUB(f, N, unsigned short, get_le16, set_le16)
|
||||
#define ADD16(f, N) ADD(f, N, unsigned short, get_le16, set_le16)
|
||||
#define SCAN16(f, N) SCAN(f, N, unsigned short, get_le16, set_le16)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
// filter
|
||||
static int f_sub16_1(Filter *f)
|
||||
{
|
||||
SUB16(f, 1)
|
||||
}
|
||||
|
||||
static int f_sub16_2(Filter *f)
|
||||
{
|
||||
SUB16(f, 2)
|
||||
}
|
||||
|
||||
static int f_sub16_3(Filter *f)
|
||||
{
|
||||
SUB16(f, 3)
|
||||
}
|
||||
|
||||
static int f_sub16_4(Filter *f)
|
||||
{
|
||||
SUB16(f, 4)
|
||||
}
|
||||
|
||||
|
||||
// unfilter
|
||||
static int u_sub16_1(Filter *f)
|
||||
{
|
||||
ADD16(f, 1)
|
||||
}
|
||||
|
||||
static int u_sub16_2(Filter *f)
|
||||
{
|
||||
ADD16(f, 2)
|
||||
}
|
||||
|
||||
static int u_sub16_3(Filter *f)
|
||||
{
|
||||
ADD16(f, 3)
|
||||
}
|
||||
|
||||
static int u_sub16_4(Filter *f)
|
||||
{
|
||||
ADD16(f, 4)
|
||||
}
|
||||
|
||||
|
||||
// scan
|
||||
static int s_sub16_1(Filter *f)
|
||||
{
|
||||
SCAN16(f, 1)
|
||||
}
|
||||
|
||||
static int s_sub16_2(Filter *f)
|
||||
{
|
||||
SCAN16(f, 2)
|
||||
}
|
||||
|
||||
static int s_sub16_3(Filter *f)
|
||||
{
|
||||
SCAN16(f, 3)
|
||||
}
|
||||
|
||||
static int s_sub16_4(Filter *f)
|
||||
{
|
||||
SCAN16(f, 4)
|
||||
}
|
||||
|
||||
|
||||
#undef SUB
|
||||
#undef ADD
|
||||
#undef SCAN
|
||||
#undef SUB16
|
||||
#undef ADD16
|
||||
#undef SCAN16
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/* sub32.h -- simple delta filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#include "sub.hh"
|
||||
|
||||
#define SUB32(f, N) SUB(f, N, unsigned int, get_le32, set_le32)
|
||||
#define ADD32(f, N) ADD(f, N, unsigned int, get_le32, set_le32)
|
||||
#define SCAN32(f, N) SCAN(f, N, unsigned int, get_le32, set_le32)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
// filter
|
||||
static int f_sub32_1(Filter *f)
|
||||
{
|
||||
SUB32(f, 1)
|
||||
}
|
||||
|
||||
static int f_sub32_2(Filter *f)
|
||||
{
|
||||
SUB32(f, 2)
|
||||
}
|
||||
|
||||
static int f_sub32_3(Filter *f)
|
||||
{
|
||||
SUB32(f, 3)
|
||||
}
|
||||
|
||||
static int f_sub32_4(Filter *f)
|
||||
{
|
||||
SUB32(f, 4)
|
||||
}
|
||||
|
||||
|
||||
// unfilter
|
||||
static int u_sub32_1(Filter *f)
|
||||
{
|
||||
ADD32(f, 1)
|
||||
}
|
||||
|
||||
static int u_sub32_2(Filter *f)
|
||||
{
|
||||
ADD32(f, 2)
|
||||
}
|
||||
|
||||
static int u_sub32_3(Filter *f)
|
||||
{
|
||||
ADD32(f, 3)
|
||||
}
|
||||
|
||||
static int u_sub32_4(Filter *f)
|
||||
{
|
||||
ADD32(f, 4)
|
||||
}
|
||||
|
||||
|
||||
// scan
|
||||
static int s_sub32_1(Filter *f)
|
||||
{
|
||||
SCAN32(f, 1)
|
||||
}
|
||||
|
||||
static int s_sub32_2(Filter *f)
|
||||
{
|
||||
SCAN32(f, 2)
|
||||
}
|
||||
|
||||
static int s_sub32_3(Filter *f)
|
||||
{
|
||||
SCAN32(f, 3)
|
||||
}
|
||||
|
||||
static int s_sub32_4(Filter *f)
|
||||
{
|
||||
SCAN32(f, 4)
|
||||
}
|
||||
|
||||
|
||||
#undef SUB
|
||||
#undef ADD
|
||||
#undef SCAN
|
||||
#undef SUB32
|
||||
#undef ADD32
|
||||
#undef SCAN32
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/* sub8.h -- simple delta filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#include "sub.hh"
|
||||
|
||||
#define SUB8(f, N) SUB(f, N, unsigned char, get_8, set_8)
|
||||
#define ADD8(f, N) ADD(f, N, unsigned char, get_8, set_8)
|
||||
#define SCAN8(f, N) SCAN(f, N, unsigned char, get_8, set_8)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
// filter
|
||||
static int f_sub8_1(Filter *f)
|
||||
{
|
||||
SUB8(f, 1)
|
||||
}
|
||||
|
||||
static int f_sub8_2(Filter *f)
|
||||
{
|
||||
SUB8(f, 2)
|
||||
}
|
||||
|
||||
static int f_sub8_3(Filter *f)
|
||||
{
|
||||
SUB8(f, 3)
|
||||
}
|
||||
|
||||
static int f_sub8_4(Filter *f)
|
||||
{
|
||||
SUB8(f, 4)
|
||||
}
|
||||
|
||||
|
||||
// unfilter
|
||||
static int u_sub8_1(Filter *f)
|
||||
{
|
||||
ADD8(f, 1)
|
||||
}
|
||||
|
||||
static int u_sub8_2(Filter *f)
|
||||
{
|
||||
ADD8(f, 2)
|
||||
}
|
||||
|
||||
static int u_sub8_3(Filter *f)
|
||||
{
|
||||
ADD8(f, 3)
|
||||
}
|
||||
|
||||
static int u_sub8_4(Filter *f)
|
||||
{
|
||||
ADD8(f, 4)
|
||||
}
|
||||
|
||||
|
||||
// scan
|
||||
static int s_sub8_1(Filter *f)
|
||||
{
|
||||
SCAN8(f, 1)
|
||||
}
|
||||
|
||||
static int s_sub8_2(Filter *f)
|
||||
{
|
||||
SCAN8(f, 2)
|
||||
}
|
||||
|
||||
static int s_sub8_3(Filter *f)
|
||||
{
|
||||
SCAN8(f, 3)
|
||||
}
|
||||
|
||||
static int s_sub8_4(Filter *f)
|
||||
{
|
||||
SCAN8(f, 4)
|
||||
}
|
||||
|
||||
|
||||
#undef SUB
|
||||
#undef ADD
|
||||
#undef SCAN
|
||||
#undef SUB8
|
||||
#undef ADD8
|
||||
#undef SCAN8
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
/* sw.h -- swaptrick filter
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 16-bit swaptrick ("naive")
|
||||
**************************************************************************/
|
||||
|
||||
#define SW16(f, cond, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 3; \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b)); \
|
||||
f->calls++; \
|
||||
b += 2 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 2; \
|
||||
return 0;
|
||||
|
||||
|
||||
// filter
|
||||
static int f_sw16_e8(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe8), get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int f_sw16_e9(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe9), get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int f_sw16_e8e9(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe8 || *b == 0xe9), get_le16, set_be16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter
|
||||
static int u_sw16_e8(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe8), get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int u_sw16_e9(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe9), get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int u_sw16_e8e9(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe8 || *b == 0xe9), get_be16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// scan
|
||||
static int s_sw16_e8(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe8), get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_sw16_e9(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe9), get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_sw16_e8e9(Filter *f)
|
||||
{
|
||||
SW16(f, (*b == 0xe8 || *b == 0xe9), get_le16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef SW16
|
||||
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 32-bit swaptrick ("naive")
|
||||
**************************************************************************/
|
||||
|
||||
#define SW32(f, cond, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 5; \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b)); \
|
||||
f->calls++; \
|
||||
b += 4 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 4; \
|
||||
return 0;
|
||||
|
||||
|
||||
// filter
|
||||
static int f_sw32_e8(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe8), get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int f_sw32_e9(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe9), get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int f_sw32_e8e9(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe8 || *b == 0xe9), get_le32, set_be32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter
|
||||
static int u_sw32_e8(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe8), get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int u_sw32_e9(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe9), get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int u_sw32_e8e9(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe8 || *b == 0xe9), get_be32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// scan
|
||||
static int s_sw32_e8(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe8), get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_sw32_e9(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe9), get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_sw32_e8e9(Filter *f)
|
||||
{
|
||||
SW32(f, (*b == 0xe8 || *b == 0xe9), get_le32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef SW32
|
||||
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
+156
-367
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
@@ -31,375 +31,118 @@
|
||||
|
||||
|
||||
#define set_dummy(p, v) ((void)0)
|
||||
#define get_8(p) (*(p))
|
||||
#define set_8(p, v) (*(p) = (v))
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 16-bit calltrick ("naive")
|
||||
// util
|
||||
**************************************************************************/
|
||||
|
||||
#define CT16(f, cond, addvalue, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 3; \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b) + (addvalue)); \
|
||||
f->calls++; \
|
||||
b += 2 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 2; \
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9
|
||||
static int f_ct16_e8(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e8e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9
|
||||
static int u_ct16_e8(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e8e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9
|
||||
static int s_ct16_e8(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e8e9(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap le->be
|
||||
static int f_ct16_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int f_ct16_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int f_ct16_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap le->be
|
||||
static int u_ct16_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int u_ct16_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap le->be
|
||||
static int s_ct16_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap be->le
|
||||
static int f_ct16_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
static int f_ct16_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap be->le
|
||||
static int u_ct16_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int u_ct16_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
static int u_ct16_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap be->le
|
||||
static int s_ct16_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct16_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef CT16
|
||||
#include "filter/getcto.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 32-bit calltrick ("naive")
|
||||
// simple filters: calltrick / swaptrick / delta / ...
|
||||
**************************************************************************/
|
||||
|
||||
#define CT32(f, cond, addvalue, get, set) \
|
||||
upx_byte *b = f->buf; \
|
||||
upx_byte *b_end = b + f->buf_len - 5; \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
b += 1; \
|
||||
unsigned a = (unsigned) (b - f->buf); \
|
||||
f->lastcall = a; \
|
||||
set(b, get(b) + (addvalue)); \
|
||||
f->calls++; \
|
||||
b += 4 - 1; \
|
||||
} \
|
||||
} while (++b < b_end); \
|
||||
if (f->lastcall) f->lastcall += 4; \
|
||||
return 0;
|
||||
#include "filter/ct.h"
|
||||
#include "filter/sw.h"
|
||||
#include "filter/ctsw.h"
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9
|
||||
static int f_ct32_e8(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e8e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9
|
||||
static int u_ct32_e8(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e8e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9
|
||||
static int s_ct32_e8(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e8e9(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap le->be
|
||||
static int f_ct32_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int f_ct32_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int f_ct32_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap le->be
|
||||
static int u_ct32_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int u_ct32_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap le->be
|
||||
static int s_ct32_e8_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e8e9_bswap_le(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
// filter: e8, e9, e8e9 with bswap be->le
|
||||
static int f_ct32_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
static int f_ct32_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
||||
}
|
||||
|
||||
|
||||
// unfilter: e8, e9, e8e9 with bswap be->le
|
||||
static int u_ct32_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int u_ct32_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
static int u_ct32_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
||||
}
|
||||
|
||||
|
||||
// scan: e8, e9, e8e9 with bswap be->le
|
||||
static int s_ct32_e8_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
static int s_ct32_e8e9_bswap_be(Filter *f)
|
||||
{
|
||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||
}
|
||||
|
||||
|
||||
#undef CT32
|
||||
|
||||
#undef set_dummy
|
||||
#include "filter/sub8.h"
|
||||
#include "filter/sub16.h"
|
||||
#include "filter/sub32.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 32-bit calltrick with cto ("clever")
|
||||
//
|
||||
// This version is more sophisticated because it only
|
||||
// tries to change actual calls and/or jumps.
|
||||
// cto calltrick
|
||||
**************************************************************************/
|
||||
|
||||
#include "fcto_ml.ch"
|
||||
#define COND(b,x) (b[x] == 0xe8)
|
||||
#define F f_cto32_e8_bswap_le
|
||||
#define U u_cto32_e8_bswap_le
|
||||
#include "filter/cto.h"
|
||||
#define F s_cto32_e8_bswap_le
|
||||
#include "filter/cto.h"
|
||||
#undef COND
|
||||
|
||||
#define COND(b,x) (b[x] == 0xe9)
|
||||
#define F f_cto32_e9_bswap_le
|
||||
#define U u_cto32_e9_bswap_le
|
||||
#include "filter/cto.h"
|
||||
#define F s_cto32_e9_bswap_le
|
||||
#include "filter/cto.h"
|
||||
#undef COND
|
||||
|
||||
#define COND(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||
#define F f_cto32_e8e9_bswap_le
|
||||
#define U u_cto32_e8e9_bswap_le
|
||||
#include "filter/cto.h"
|
||||
#define F s_cto32_e8e9_bswap_le
|
||||
#include "filter/cto.h"
|
||||
#undef COND
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// cto calltrick with jmp
|
||||
**************************************************************************/
|
||||
|
||||
#define COND(b,x,lastcall) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||
#define F f_ctoj32_e8e9_bswap_le
|
||||
#define U u_ctoj32_e8e9_bswap_le
|
||||
#include "filter/ctoj.h"
|
||||
#define F s_ctoj32_e8e9_bswap_le
|
||||
#include "filter/ctoj.h"
|
||||
#undef COND
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// cto calltrick with jmp, optional jcc
|
||||
**************************************************************************/
|
||||
|
||||
#define COND1(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||
#define COND2(b,x,lc) (lc!=(x) && 0xf==b[(x)-1] && 0x80<=b[x] && b[x]<=0x8f)
|
||||
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
|
||||
#define F f_ctok32_e8e9_bswap_le
|
||||
#define U u_ctok32_e8e9_bswap_le
|
||||
#include "filter/ctok.h"
|
||||
#define F s_ctok32_e8e9_bswap_le
|
||||
#include "filter/ctok.h"
|
||||
#undef COND
|
||||
#undef COND2
|
||||
#undef COND1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// cto calltrick with jmp and jcc and relative renumbering
|
||||
**************************************************************************/
|
||||
|
||||
#define COND_CALL(which,b,x) ((which = 0), b[x] == 0xe8)
|
||||
#define COND_JMP( which,b,x) ((which = 1), b[x] == 0xe9)
|
||||
#define COND_JCC( which,b,lastcall,x,y,z) ((which = 2), \
|
||||
(lastcall!=(x) && 0xf==b[y] && 0x80<=b[z] && b[z]<=0x8f))
|
||||
#define COND1(which,b,x) (COND_CALL(which,b,x) || COND_JMP(which,b,x))
|
||||
#define COND2(which,b,lastcall,x,y,z) COND_JCC(which,b,lastcall,x,y,z)
|
||||
|
||||
#define CONDF(which,b,x,lastcall) \
|
||||
(COND1(which,b,x) || COND2(which,b,lastcall,x,(x)-1, x ))
|
||||
#define CONDU(which,b,x,lastcall) \
|
||||
(COND1(which,b,x) || COND2(which,b,lastcall,x, x ,(x)-1))
|
||||
|
||||
#define F f_ctojr32_e8e9_bswap_le
|
||||
#define U u_ctojr32_e8e9_bswap_le
|
||||
#include "filter/ctojr.h"
|
||||
#define F s_ctojr32_e8e9_bswap_le
|
||||
#include "filter/ctojr.h"
|
||||
|
||||
#undef CONDU
|
||||
#undef CONDF
|
||||
#undef COND2
|
||||
#undef COND1
|
||||
#undef COND_JCC
|
||||
#undef COND_JMP
|
||||
#undef COND_CALL
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -409,8 +152,9 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
|
||||
const FilterImp::FilterEntry FilterImp::filters[] = {
|
||||
// no filter
|
||||
{ 0x00, 0, 0, NULL, NULL, NULL },
|
||||
|
||||
// 16-bit calltrick
|
||||
{ 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8,},
|
||||
{ 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8 },
|
||||
{ 0x02, 4, 0, f_ct16_e9, u_ct16_e9, s_ct16_e9 },
|
||||
{ 0x03, 4, 0, f_ct16_e8e9, u_ct16_e8e9, s_ct16_e8e9 },
|
||||
{ 0x04, 4, 0, f_ct16_e8_bswap_le, u_ct16_e8_bswap_le, s_ct16_e8_bswap_le },
|
||||
@@ -419,6 +163,16 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
||||
{ 0x07, 4, 0, f_ct16_e8_bswap_be, u_ct16_e8_bswap_be, s_ct16_e8_bswap_be },
|
||||
{ 0x08, 4, 0, f_ct16_e9_bswap_be, u_ct16_e9_bswap_be, s_ct16_e9_bswap_be },
|
||||
{ 0x09, 4, 0, f_ct16_e8e9_bswap_be, u_ct16_e8e9_bswap_be, s_ct16_e8e9_bswap_be },
|
||||
|
||||
// 16-bit swaptrick
|
||||
{ 0x0a, 4, 0, f_sw16_e8, u_sw16_e8, s_sw16_e8 },
|
||||
{ 0x0b, 4, 0, f_sw16_e9, u_sw16_e9, s_sw16_e9 },
|
||||
{ 0x0c, 4, 0, f_sw16_e8e9, u_sw16_e8e9, s_sw16_e8e9 },
|
||||
|
||||
// 16-bit call-/swaptrick
|
||||
{ 0x0d, 4, 0, f_ctsw16_e8_e9, u_ctsw16_e8_e9, s_ctsw16_e8_e9 },
|
||||
{ 0x0e, 4, 0, f_ctsw16_e9_e8, u_ctsw16_e9_e8, s_ctsw16_e9_e8 },
|
||||
|
||||
// 32-bit calltrick
|
||||
{ 0x11, 6, 0, f_ct32_e8, u_ct32_e8, s_ct32_e8 },
|
||||
{ 0x12, 6, 0, f_ct32_e9, u_ct32_e9, s_ct32_e9 },
|
||||
@@ -429,21 +183,56 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
||||
{ 0x17, 6, 0, f_ct32_e8_bswap_be, u_ct32_e8_bswap_be, s_ct32_e8_bswap_be },
|
||||
{ 0x18, 6, 0, f_ct32_e9_bswap_be, u_ct32_e9_bswap_be, s_ct32_e9_bswap_be },
|
||||
{ 0x19, 6, 0, f_ct32_e8e9_bswap_be, u_ct32_e8e9_bswap_be, s_ct32_e8e9_bswap_be },
|
||||
|
||||
// 32-bit swaptrick
|
||||
{ 0x1a, 6, 0, f_sw32_e8, u_sw32_e8, s_sw32_e8 },
|
||||
{ 0x1b, 6, 0, f_sw32_e9, u_sw32_e9, s_sw32_e9 },
|
||||
{ 0x1c, 6, 0, f_sw32_e8e9, u_sw32_e8e9, s_sw32_e8e9 },
|
||||
|
||||
// 32-bit call-/swaptrick
|
||||
{ 0x1d, 6, 0, f_ctsw32_e8_e9, u_ctsw32_e8_e9, s_ctsw32_e8_e9 },
|
||||
{ 0x1e, 6, 0, f_ctsw32_e9_e8, u_ctsw32_e9_e8, s_ctsw32_e9_e8 },
|
||||
|
||||
// 32-bit cto calltrick
|
||||
{ 0x21, 6, 0x00ffffff, f_cto32_e8, u_cto32_e8, s_cto32_e8 },
|
||||
{ 0x22, 6, 0x00ffffff, f_cto32_e9, u_cto32_e9, s_cto32_e9 },
|
||||
{ 0x23, 6, 0x00ffffff, f_cto32_e8e9, u_cto32_e8e9, s_cto32_e8e9 },
|
||||
{ 0x24, 6, 0x00ffffff, f_cto32_e8_bswap_le, u_cto32_e8_bswap_le, s_cto32_e8_bswap_le },
|
||||
{ 0x25, 6, 0x00ffffff, f_cto32_e9_bswap_le, u_cto32_e9_bswap_le, s_cto32_e9_bswap_le },
|
||||
{ 0x26, 6, 0x00ffffff, f_cto32_e8e9_bswap_le, u_cto32_e8e9_bswap_le, s_cto32_e8e9_bswap_le },
|
||||
{ 0x27, 6, 0x00ffffff, f_cto32_e8_bswap_be, u_cto32_e8_bswap_be, s_cto32_e8_bswap_be },
|
||||
{ 0x28, 6, 0x00ffffff, f_cto32_e9_bswap_be, u_cto32_e9_bswap_be, s_cto32_e9_bswap_be },
|
||||
{ 0x29, 6, 0x00ffffff, f_cto32_e8e9_bswap_be, u_cto32_e8e9_bswap_be, s_cto32_e8e9_bswap_be },
|
||||
// 32-bit cto calltrick + jmp
|
||||
{ 0x36, 6, 0x00ffffff, f_ctjo32_e8e9_bswap_le, u_ctjo32_e8e9_bswap_le, s_ctjo32_e8e9_bswap_le },
|
||||
|
||||
// 32-bit cto calltrick with jmp
|
||||
{ 0x36, 6, 0x00ffffff, f_ctoj32_e8e9_bswap_le, u_ctoj32_e8e9_bswap_le, s_ctoj32_e8e9_bswap_le },
|
||||
|
||||
// 32-bit calltrick with jmp, optional jcc; runtime can unfilter more than one block
|
||||
{ 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 },
|
||||
|
||||
// 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 },
|
||||
{ 0x82, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
{ 0x83, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
{ 0x84, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
{ 0x85, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
{ 0x86, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
{ 0x87, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||
|
||||
// simple delta filter
|
||||
{ 0x90, 2, 0, f_sub8_1, u_sub8_1, s_sub8_1 },
|
||||
{ 0x91, 3, 0, f_sub8_2, u_sub8_2, s_sub8_2 },
|
||||
{ 0x92, 4, 0, f_sub8_3, u_sub8_3, s_sub8_3 },
|
||||
{ 0x93, 5, 0, f_sub8_4, u_sub8_4, s_sub8_4 },
|
||||
|
||||
{ 0xa0,99, 0, f_sub16_1, u_sub16_1, s_sub16_1 },
|
||||
{ 0xa1,99, 0, f_sub16_2, u_sub16_2, s_sub16_2 },
|
||||
{ 0xa2,99, 0, f_sub16_3, u_sub16_3, s_sub16_3 },
|
||||
{ 0xa3,99, 0, f_sub16_4, u_sub16_4, s_sub16_4 },
|
||||
|
||||
{ 0xb0,99, 0, f_sub32_1, u_sub32_1, s_sub32_1 },
|
||||
{ 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 },
|
||||
};
|
||||
|
||||
const int FilterImp::n_filters = HIGH(filters);
|
||||
const int FilterImp::n_filters = TABLESIZE(filters);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+119
-49
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -44,13 +44,26 @@ void show_head(void)
|
||||
return;
|
||||
head_done = 1;
|
||||
|
||||
#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\n"
|
||||
"UPX v%-12sMarkus F.X.J. Oberhumer & Laszlo Molnar%21s\n\n",
|
||||
UPX_VERSION_STRING, UPX_VERSION_DATE);
|
||||
" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004\n"
|
||||
"UPX %-12s Markus F.X.J. Oberhumer & Laszlo Molnar %20s\n\n",
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||
V("d"),
|
||||
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
V("w"),
|
||||
#elif 0 && defined(__linux__)
|
||||
V("l"),
|
||||
#else
|
||||
UPX_VERSION_STRING,
|
||||
#endif
|
||||
UPX_VERSION_DATE);
|
||||
fg = con_fg(f,fg);
|
||||
#undef V
|
||||
|
||||
UNUSED(fg);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +75,7 @@ void show_usage(void)
|
||||
{
|
||||
FILE *f = con_term;
|
||||
|
||||
con_fprintf(f,"Usage: %s [-123456788dlthVL] [-qvfk] [-o file] %sfile..\n", progname,
|
||||
con_fprintf(f,"Usage: %s [-123456789dlthVL] [-qvfk] [-o file] %sfile..\n", progname,
|
||||
#if defined(__DJGPP__) || defined(__EMX__)
|
||||
"[@]");
|
||||
#else
|
||||
@@ -92,7 +105,7 @@ void show_help(int x)
|
||||
" -d decompress -l list compressed file\n"
|
||||
" -t test compressed file -V display version number\n"
|
||||
" -h give %s help -L display software license\n%s",
|
||||
x == 0 ? "" : " --best compress best (can be very slow for big files)\n",
|
||||
x == 0 ? "" : " --best compress best (can be slow for big files)\n",
|
||||
x == 0 ? "more" : "this", x == 0 ? "" : "\n");
|
||||
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
@@ -101,7 +114,6 @@ void show_help(int x)
|
||||
|
||||
con_fprintf(f,
|
||||
" -q be quiet -v be verbose\n"
|
||||
//" -oFILE write output to `FILE' -c write output to stdout\n"
|
||||
" -oFILE write output to `FILE'\n"
|
||||
//" -f force overwrite of output files and compression of suspicious files\n"
|
||||
" -f force compression of suspicious files\n"
|
||||
@@ -128,20 +140,30 @@ void show_help(int x)
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --overlay=copy copy any extra data attached to the file [default]\n"
|
||||
" --overlay=strip strip any extra data attached to the file [dangerous]\n"
|
||||
" --overlay=strip strip any extra data attached to the file [DANGEROUS]\n"
|
||||
" --overlay=skip don't compress a file with an overlay\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for atari/tos:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for djgpp2/coff:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --coff produce COFF output [default: EXE]\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for dos/com:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --8086 make compressed com work on any 8086\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for dos/exe:\n");
|
||||
@@ -149,12 +171,47 @@ void show_help(int x)
|
||||
con_fprintf(f,
|
||||
" --8086 make compressed exe work on any 8086\n"
|
||||
" --no-reloc put no relocations in to the exe header\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for dos/sys:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --8086 make compressed sys work on any 8086\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
#if 0
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for linux/386\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --script use /usr/local/lib/upx/upx[bd] as decompressor\n"
|
||||
" --script=/path/upxX use path/upxX as decompressor\n"
|
||||
"\n");
|
||||
#endif
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for ps1/exe:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --8-bit uses 8 bit size compression [default: 32 bit]\n"
|
||||
" --console-run enables client/host transfer compatibility\n"
|
||||
" --no-align don't align to 2048 bytes [enables: --console-run]\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for tmt/adam:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for vmlinuz/386\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for watcom/le:\n");
|
||||
@@ -172,39 +229,43 @@ void show_help(int x)
|
||||
" --compress-icons=1 compress all but the first icon\n"
|
||||
" --compress-icons=2 compress all but the first icon directory [default]\n"
|
||||
" --compress-resources=0 do not compress any resources at all\n"
|
||||
" --strip-loadconf=0 do not strip SEH load config [default]\n"
|
||||
" --strip-loadconf=1 strip SEH load config [DANGEROUS]\n"
|
||||
" --strip-relocs=0 do not strip relocations\n"
|
||||
" --strip-relocs=1 strip relocations [default]\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
#if 0
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for linux/386\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --script use /usr/local/lib/upx/upx[bd] as decompressor\n"
|
||||
" --script=/path/upxX use path/upxX as decompressor\n"
|
||||
"\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
con_fprintf(f,
|
||||
" file.. executables to (de)compress\n"
|
||||
"\n"
|
||||
"This version supports:\n "
|
||||
"atari/tos, "
|
||||
"bvmlinuz/386, "
|
||||
"djgpp2/coff, "
|
||||
"dos/com, "
|
||||
"dos/exe, "
|
||||
"dos/sys,\n "
|
||||
"linux/386, "
|
||||
"linux/elf386, "
|
||||
"linux/sh386, "
|
||||
"rtm32/pe, "
|
||||
"tmt/adam, "
|
||||
"vmlinuz/386,\n "
|
||||
"watcom/le, "
|
||||
"win32/pe"
|
||||
"\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.tsx.org\n"
|
||||
"file.. executables to (de)compress\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"This version supports:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f," "
|
||||
" atari/tos,"
|
||||
" bvmlinuz/386,"
|
||||
" djgpp2/coff,"
|
||||
" dos/com,"
|
||||
" dos/exe,"
|
||||
" dos/sys,"
|
||||
"\n "
|
||||
//" elks/8086,"
|
||||
" linux/386,"
|
||||
" linux/elf386,"
|
||||
" linux/sh386,"
|
||||
" ps1/exe,"
|
||||
" rtm32/pe,"
|
||||
" tmt/adam,"
|
||||
"\n "
|
||||
" 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"
|
||||
"");
|
||||
|
||||
@@ -221,6 +282,8 @@ void show_help(int x)
|
||||
"\n");
|
||||
fg = con_fg(f,fg);
|
||||
#endif
|
||||
|
||||
UNUSED(fg);
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +297,7 @@ void show_license(void)
|
||||
|
||||
show_head();
|
||||
|
||||
con_fprintf(f,
|
||||
con_fprintf(f,
|
||||
" This program may be used freely, and you are welcome to\n"
|
||||
" redistribute it under certain conditions.\n"
|
||||
"\n"
|
||||
@@ -249,17 +312,19 @@ con_fprintf(f,
|
||||
"\n"
|
||||
);
|
||||
int fg = con_fg(f,FG_CYAN);
|
||||
con_fprintf(f,
|
||||
" http://upx.tsx.org\n"
|
||||
" http://wildsau.idv.uni-linz.ac.at/mfx/upx.html\n"
|
||||
con_fprintf(f,
|
||||
" http://upx.sourceforge.net\n"
|
||||
" http://www.oberhumer.com/opensource/upx/\n"
|
||||
);
|
||||
(void)con_fg(f,FG_ORANGE);
|
||||
con_fprintf(f,
|
||||
con_fprintf(f,
|
||||
"\n"
|
||||
" Markus F.X.J. Oberhumer Laszlo Molnar\n"
|
||||
" markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu\n"
|
||||
" Markus F.X.J. Oberhumer Laszlo Molnar\n"
|
||||
" <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>\n"
|
||||
);
|
||||
fg = con_fg(f,fg);
|
||||
|
||||
UNUSED(fg);
|
||||
}
|
||||
|
||||
|
||||
@@ -272,16 +337,21 @@ void show_version(int x)
|
||||
FILE *f = stdout;
|
||||
UNUSED(x);
|
||||
|
||||
fprintf(f,"upx %s\n",UPX_VERSION_STRING);
|
||||
#if (0 && ACC_CC_GNUC)
|
||||
fprintf(f,"upx %s (gcc 0x%06lx)\n", UPX_VERSION_STRING, ACC_CC_GNUC);
|
||||
#else
|
||||
fprintf(f,"upx %s\n", UPX_VERSION_STRING);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
fprintf(f,"NRV data compression library %s\n", nrv_version_string());
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
|
||||
#endif
|
||||
fprintf(f,"Copyright (C) 1996,1997,1998,1999,2000 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f,"Copyright (C) 1996,1997,1998,1999,2000 Laszlo Molnar\n");
|
||||
fprintf(f,"Copyright (C) 2000 John F. Reiser\n");
|
||||
fprintf(f,"Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f,"Copyright (C) 1996-2004 Laszlo Molnar\n");
|
||||
fprintf(f,"Copyright (C) 2000-2004 John F. Reiser\n");
|
||||
fprintf(f,"Copyright (C) 2002-2004 Jens Medoch\n");
|
||||
fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
|
||||
}
|
||||
|
||||
|
||||
+29
-12
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -32,8 +32,13 @@
|
||||
#include "lefile.h"
|
||||
|
||||
|
||||
LeFile::LeFile(InputFile *f) : fif(f)
|
||||
LeFile::LeFile(InputFile *f) :
|
||||
fif(f), fof(NULL),
|
||||
le_offset(0), exe_offset(0)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(le_header_t) == 196);
|
||||
COMPILE_TIME_ASSERT(sizeof(le_object_table_entry_t) == 24);
|
||||
COMPILE_TIME_ASSERT(sizeof(le_pagemap_entry_t) == 4);
|
||||
memset(&ih,0,sizeof ih);
|
||||
memset(&oh,0,sizeof oh);
|
||||
iobject_table = oobject_table = NULL;
|
||||
@@ -43,7 +48,6 @@ LeFile::LeFile(InputFile *f) : fif(f)
|
||||
ifixups = ofixups = NULL;
|
||||
inonres_names = ononres_names = NULL;
|
||||
ientries = oentries = NULL;
|
||||
le_offset = exe_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +172,18 @@ void LeFile::writeFixups()
|
||||
}
|
||||
|
||||
|
||||
unsigned LeFile::getImageSize() const
|
||||
{
|
||||
unsigned n = 0;
|
||||
if (ih.memory_pages > 0)
|
||||
{
|
||||
n = (ih.memory_pages - 1) * ih.memory_page_size;
|
||||
n += ih.bytes_on_last_page;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
void LeFile::readImage()
|
||||
{
|
||||
soimage = pages*mps;
|
||||
@@ -295,7 +311,8 @@ void LeFile::writeFile(OutputFile *f, bool le)
|
||||
|
||||
void LeFile::countFixups(unsigned *counts) const
|
||||
{
|
||||
memset(counts,0,sizeof(unsigned)*(objects+2));
|
||||
const unsigned o = objects;
|
||||
memset(counts,0,sizeof(unsigned)*(o+2));
|
||||
// counts[0..objects-1] - # of 32-bit offset relocations in for that objects
|
||||
// counts[objects] - # of selector fixups
|
||||
// counts[objects+1] - # of self-relative fixups
|
||||
@@ -311,7 +328,7 @@ void LeFile::countFixups(unsigned *counts) const
|
||||
switch (*fix)
|
||||
{
|
||||
case 2: // selector fixup
|
||||
counts[objects] += 9;
|
||||
counts[o] += 9;
|
||||
fix += 5;
|
||||
break;
|
||||
case 0x12: // alias selector
|
||||
@@ -320,7 +337,7 @@ void LeFile::countFixups(unsigned *counts) const
|
||||
fix += (fix[1] & 0x10) ? 9 : 7;
|
||||
break;
|
||||
case 6: // 16:32 pointer
|
||||
counts[objects] += 9;
|
||||
counts[o] += 9;
|
||||
case 7: // 32-bit offset
|
||||
counts[fix[4]-1] += 4;
|
||||
fix += (fix[1] & 0x10) ? 9 : 7;
|
||||
@@ -332,15 +349,15 @@ void LeFile::countFixups(unsigned *counts) const
|
||||
fix += ll*2;
|
||||
break;
|
||||
case 8: // 32-bit self relative fixup
|
||||
counts[objects+1] += 4;
|
||||
counts[o+1] += 4;
|
||||
fix += (fix[1] & 0x10) ? 9 : 7;
|
||||
break;
|
||||
default:
|
||||
throwCantPack("unsupported fixup record");
|
||||
}
|
||||
}
|
||||
counts[objects]++; // extra space for 'ret'
|
||||
counts[objects+1] += 4; // extra space for 0xFFFFFFFF
|
||||
counts[o]++; // extra space for 'ret'
|
||||
counts[o+1] += 4; // extra space for 0xFFFFFFFF
|
||||
}
|
||||
|
||||
|
||||
|
||||
+17
-13
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -117,7 +117,8 @@ protected:
|
||||
LE16 device_id;
|
||||
LE16 ddk_version;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct le_object_table_entry_t
|
||||
{
|
||||
@@ -127,15 +128,17 @@ protected:
|
||||
LE32 pagemap_index;
|
||||
LE32 npages;
|
||||
LE32 reserved;
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct le_pagemap_entry_t
|
||||
{
|
||||
upx_byte h;
|
||||
upx_byte m;
|
||||
upx_byte l;
|
||||
upx_byte type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
|
||||
};
|
||||
unsigned char h;
|
||||
unsigned char m;
|
||||
unsigned char l;
|
||||
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
virtual void readObjectTable();
|
||||
virtual void writeObjectTable();
|
||||
@@ -178,6 +181,7 @@ protected:
|
||||
//virtual void decodeImage(){encodeImage();}
|
||||
|
||||
void countFixups(unsigned *) const;
|
||||
unsigned getImageSize() const;
|
||||
|
||||
InputFile *fif;
|
||||
OutputFile *fof;
|
||||
@@ -215,8 +219,8 @@ protected:
|
||||
|
||||
private:
|
||||
// disable copy and assignment
|
||||
LeFile(LeFile const &); // {}
|
||||
LeFile& operator= (LeFile const &); // { return *this; }
|
||||
LeFile(const LeFile &); // {}
|
||||
LeFile& operator= (const LeFile &); // { return *this; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
+34
-23
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ struct Linker::jump
|
||||
int toffs;
|
||||
};
|
||||
|
||||
|
||||
Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
{
|
||||
iloader = new char[(ilen = plen) + 4096];
|
||||
@@ -54,32 +53,34 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
|
||||
oloader = new char[plen];
|
||||
olen = 0;
|
||||
align_hack = 0;
|
||||
align_offset = 0;
|
||||
info = pinfo;
|
||||
njumps = nsections = frozen = 0;
|
||||
jumps = new jump[200];
|
||||
sections = new section[200];
|
||||
#define NSECTIONS 350
|
||||
sections = new section[NSECTIONS];
|
||||
|
||||
char *p = iloader + info;
|
||||
while (get_le32(p) != (unsigned)(-1))
|
||||
while (get32(p) != (unsigned)(-1))
|
||||
{
|
||||
if (get_le32(p))
|
||||
if (get32(p))
|
||||
{
|
||||
memcpy(sections[nsections].name,p,8);
|
||||
sections[nsections].istart = get_le32(p+8);
|
||||
sections[nsections].istart = get32(p+8);
|
||||
sections[nsections++].ostart = -1;
|
||||
p += 12;
|
||||
assert(nsections < 200);
|
||||
assert(nsections < NSECTIONS);
|
||||
}
|
||||
else
|
||||
{
|
||||
int l;
|
||||
for (l = get_le32(p+4) - 1; iloader[l] == 0; l--)
|
||||
for (l = get32(p+4) - 1; iloader[l] == 0; l--)
|
||||
;
|
||||
|
||||
jumps[njumps].pos = l+1;
|
||||
jumps[njumps].len = get_le32(p+4)-jumps[njumps].pos;
|
||||
jumps[njumps].len = get32(p+4)-jumps[njumps].pos;
|
||||
memcpy(jumps[njumps].tsect,p+8,8);
|
||||
jumps[njumps++].toffs = get_le32(p+16);
|
||||
jumps[njumps++].toffs = get32(p+16);
|
||||
p += 20;
|
||||
assert(njumps < 200);
|
||||
}
|
||||
@@ -101,7 +102,17 @@ Linker::~Linker()
|
||||
}
|
||||
|
||||
|
||||
void Linker::addSection(const char *sect)
|
||||
void Linker::setLoaderAlignOffset(int offset)
|
||||
{
|
||||
align_offset = offset;
|
||||
}
|
||||
|
||||
static int hex(char c)
|
||||
{
|
||||
return (c & 0xf) + (c > '9' ? 9 : 0);
|
||||
}
|
||||
|
||||
int Linker::addSection(const char *sect)
|
||||
{
|
||||
int ic;
|
||||
while (*sect)
|
||||
@@ -109,14 +120,13 @@ void Linker::addSection(const char *sect)
|
||||
if (*sect == '+') // alignment
|
||||
{
|
||||
if (sect[1] == '0')
|
||||
align_hack = olen;
|
||||
align_hack = olen + align_offset;
|
||||
else
|
||||
{
|
||||
ic = (sect[1] & 0xf) + (sect[1] > '9' ? 9 : 0);
|
||||
ic = (ic + (sect[2] & 0xf) + (sect[2] > '9' ? 9 : 0)
|
||||
- (olen - align_hack) % ic) % ic;
|
||||
memset(oloader+olen,sect[3] == 'C' ? 0x90 : 0,ic);
|
||||
olen += ic;
|
||||
unsigned j = hex(sect[1]);
|
||||
j = (hex(sect[2]) - ((olen + align_offset) - align_hack) ) % j;
|
||||
memset(oloader+olen, (sect[3] == 'C' ? 0x90 : 0), j);
|
||||
olen += j;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -129,11 +139,12 @@ void Linker::addSection(const char *sect)
|
||||
olen += sections[ic].len;
|
||||
break;
|
||||
}
|
||||
//printf("%8.8s",section);
|
||||
//printf("%8.8s",sect);
|
||||
assert(ic!=nsections);
|
||||
}
|
||||
sect += 8;
|
||||
}
|
||||
return olen;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +155,7 @@ void Linker::addSection(const char *sname, const void *sdata, unsigned len)
|
||||
sections[nsections].istart = ilen;
|
||||
sections[nsections].len = len;
|
||||
sections[nsections++].ostart = olen;
|
||||
assert(nsections < 200);
|
||||
assert(nsections < NSECTIONS);
|
||||
memcpy(iloader+ilen,sdata,len);
|
||||
ilen += len;
|
||||
}
|
||||
@@ -177,7 +188,7 @@ const char *Linker::getLoader(int *llen)
|
||||
if (jumps[ic].len == 1)
|
||||
assert(-128 <= offs && offs <= 127);
|
||||
|
||||
set_le32(&offs,offs);
|
||||
set32(&offs,offs);
|
||||
memcpy(oloader+sections[jc].ostart+jumps[ic].pos-sections[jc].istart,&offs,jumps[ic].len);
|
||||
}
|
||||
frozen=1;
|
||||
|
||||
+34
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
@@ -34,11 +34,18 @@ class Linker
|
||||
{
|
||||
public:
|
||||
Linker(const void *pdata, int plen, int pinfo);
|
||||
~Linker();
|
||||
void addSection(const char *sect);
|
||||
virtual ~Linker();
|
||||
int addSection(const char *sect);
|
||||
void addSection(const char *sname, const void *sdata, unsigned len);
|
||||
const char *getLoader(int *llen);
|
||||
int getSection(const char *name, int *slen) const;
|
||||
int getLoaderSize() const { return olen; }
|
||||
void setLoaderAlignOffset(int phase);
|
||||
|
||||
protected:
|
||||
// little endian
|
||||
virtual unsigned get32(const void *b) const { return get_le32(b); }
|
||||
virtual void set32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
|
||||
private:
|
||||
struct section;
|
||||
@@ -53,14 +60,33 @@ private:
|
||||
int nsections;
|
||||
int frozen;
|
||||
int align_hack;
|
||||
int align_offset;
|
||||
|
||||
private:
|
||||
// disable copy and assignment
|
||||
Linker(Linker const &); // {}
|
||||
Linker& operator= (Linker const &); // { return *this; }
|
||||
Linker(const Linker &); // {}
|
||||
Linker& operator= (const Linker &); // { return *this; }
|
||||
};
|
||||
|
||||
|
||||
class BeLinker : public Linker
|
||||
{
|
||||
typedef Linker super;
|
||||
public:
|
||||
BeLinker(const void *pdata, int plen, int pinfo) :
|
||||
super(pdata, plen, pinfo) { }
|
||||
|
||||
protected:
|
||||
// big endian
|
||||
virtual unsigned get32(const void *b) const { return get_be32(b); }
|
||||
virtual void set32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
|
||||
private:
|
||||
// disable copy and assignment
|
||||
BeLinker(const BeLinker &); // {}
|
||||
BeLinker& operator= (const BeLinker &); // { return *this; }
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
+244
-148
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,14 +21,21 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "mygetopt.h"
|
||||
#include "file.h"
|
||||
#include "packer.h"
|
||||
|
||||
|
||||
#if 1 && defined(__DJGPP__)
|
||||
#include <crt0.h>
|
||||
int _crt0_startup_flags = _CRT0_FLAG_UNIX_SBRK;
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -43,24 +50,29 @@ void init_options(struct options_t *o)
|
||||
o->cmd = CMD_NONE;
|
||||
o->method = -1;
|
||||
o->level = -1;
|
||||
o->mem_level = -1;
|
||||
o->filter = -1;
|
||||
|
||||
o->backup = -1;
|
||||
o->overlay = -1;
|
||||
|
||||
o->console = CON_FILE;
|
||||
#if defined(__MFX_DOS) || defined(__MFX_WIN)
|
||||
#if defined(__DJGPP__)
|
||||
o->console = CON_INIT;
|
||||
#elif defined(USE_SCREEN_WIN32)
|
||||
o->console = CON_INIT;
|
||||
#elif 1 && defined(__linux__)
|
||||
o->console = CON_INIT;
|
||||
#endif
|
||||
o->verbose = 2;
|
||||
|
||||
o->w32pe.compress_exports = 1;
|
||||
o->w32pe.compress_icons = 2;
|
||||
o->w32pe.compress_resources = true;
|
||||
o->w32pe.strip_relocs = -1;
|
||||
o->win32_pe.compress_exports = 1;
|
||||
o->win32_pe.compress_icons = 2;
|
||||
o->win32_pe.compress_resources = -1;
|
||||
for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++)
|
||||
o->win32_pe.compress_rt[i] = -1;
|
||||
o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
|
||||
o->win32_pe.strip_loadconf = -1;
|
||||
o->win32_pe.strip_relocs = -1;
|
||||
}
|
||||
|
||||
static struct options_t global_options;
|
||||
@@ -83,7 +95,7 @@ static int exit_code = EXIT_OK;
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(__GNUC__)
|
||||
static void do_exit(void) __attribute__((noreturn));
|
||||
static void do_exit(void) __attribute__((__noreturn__));
|
||||
#endif
|
||||
static void do_exit(void)
|
||||
{
|
||||
@@ -174,6 +186,14 @@ static void e_optarg(const char *n)
|
||||
}
|
||||
|
||||
|
||||
static void e_optval(const char *n)
|
||||
{
|
||||
fflush(con_term);
|
||||
fprintf(stderr,"%s: invalid value for option `%s'\n", argv0, n);
|
||||
e_exit(EXIT_USAGE);
|
||||
}
|
||||
|
||||
|
||||
#if defined(OPTIONS_VAR)
|
||||
void e_envopt(const char *n)
|
||||
{
|
||||
@@ -189,7 +209,7 @@ void e_envopt(const char *n)
|
||||
#endif /* defined(OPTIONS_VAR) */
|
||||
|
||||
|
||||
RETSIGTYPE SIGTYPEENTRY e_sighandler(int signum)
|
||||
void __acc_cdecl_sighandler e_sighandler(int signum)
|
||||
{
|
||||
UNUSED(signum);
|
||||
e_exit(EXIT_FATAL);
|
||||
@@ -228,6 +248,11 @@ void check_options(int i, int argc)
|
||||
opt->backup = 1;
|
||||
|
||||
check_not_both(opt->to_stdout, opt->output_name != NULL, "--stdout", "-o");
|
||||
if (opt->to_stdout && opt->cmd == CMD_COMPRESS)
|
||||
{
|
||||
fprintf(stderr,"%s: cannot use `--stdout' when compressing\n", argv0);
|
||||
e_usage();
|
||||
}
|
||||
if (opt->to_stdout || opt->output_name)
|
||||
{
|
||||
if (i + 1 != argc)
|
||||
@@ -256,7 +281,7 @@ static void set_term(FILE *f)
|
||||
if (f)
|
||||
con_term = f;
|
||||
else
|
||||
con_term = isafile(STDIN_FILENO) ? stderr : stdout;
|
||||
con_term = acc_isatty(STDIN_FILENO) ? stderr : stdout;
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +295,12 @@ static void set_cmd(int cmd)
|
||||
static bool set_method(int m, int l)
|
||||
{
|
||||
if (m > 0)
|
||||
{
|
||||
if (!Packer::isValidCompressionMethod(m))
|
||||
return false;
|
||||
opt->method = m;
|
||||
opt->all_methods = false;
|
||||
}
|
||||
if (l > 0)
|
||||
opt->level = l;
|
||||
set_cmd(CMD_COMPRESS);
|
||||
@@ -292,7 +322,7 @@ static void set_output_name(const char *n, bool allow_m)
|
||||
fprintf(stderr,"%s: missing output name\n",argv0);
|
||||
e_usage();
|
||||
}
|
||||
if (strlen(n) >= PATH_MAX - 4)
|
||||
if (strlen(n) >= ACC_FN_PATH_MAX - 4)
|
||||
{
|
||||
fprintf(stderr,"%s: output name too long\n",argv0);
|
||||
e_usage();
|
||||
@@ -315,12 +345,12 @@ static void set_script_name(const char *n, bool allow_m)
|
||||
fprintf(stderr,"%s: missing script name\n",argv0);
|
||||
e_usage();
|
||||
}
|
||||
if (strlen(n) >= opt->unix.SCRIPT_MAX - 3)
|
||||
if (strlen(n) >= (size_t)opt->o_unix.SCRIPT_MAX - 3)
|
||||
{
|
||||
fprintf(stderr,"%s: script name too long\n",argv0);
|
||||
e_usage();
|
||||
}
|
||||
opt->unix.script_name = n;
|
||||
opt->o_unix.script_name = n;
|
||||
done_script_name++;
|
||||
}
|
||||
|
||||
@@ -374,7 +404,7 @@ char* prepare_shortopts(char *buf, const char *n,
|
||||
|
||||
|
||||
template <class T>
|
||||
int getoptvar(T *var, T minval, T maxval)
|
||||
int getoptvar(T *var, const T minval, const T maxval)
|
||||
{
|
||||
const char *p = mfx_optarg;
|
||||
char *endptr;
|
||||
@@ -403,10 +433,13 @@ static int do_option(int optc, const char *arg)
|
||||
|
||||
switch (optc)
|
||||
{
|
||||
#if 0
|
||||
// FIXME: to_stdout doesn't work because of console code mess
|
||||
//case 'c':
|
||||
case 517:
|
||||
opt->to_stdout = true;
|
||||
break;
|
||||
#endif
|
||||
case 'd':
|
||||
set_cmd(CMD_DECOMPRESS);
|
||||
break;
|
||||
@@ -416,7 +449,7 @@ static int do_option(int optc, const char *arg)
|
||||
case 'f':
|
||||
opt->force++;
|
||||
break;
|
||||
case 901:
|
||||
case 902:
|
||||
set_cmd(CMD_FILEINFO);
|
||||
break;
|
||||
case 'h':
|
||||
@@ -425,9 +458,11 @@ static int do_option(int optc, const char *arg)
|
||||
set_cmd(CMD_HELP);
|
||||
break;
|
||||
case 'h'+256:
|
||||
#if 0
|
||||
/* according to GNU standards */
|
||||
set_term(stdout);
|
||||
opt->console = CON_FILE;
|
||||
#endif
|
||||
show_help(1);
|
||||
e_exit(EXIT_OK);
|
||||
break;
|
||||
@@ -472,6 +507,10 @@ static int do_option(int optc, const char *arg)
|
||||
if (!set_method(M_NRV2D_LE32, -1))
|
||||
e_method(M_NRV2D_LE32, opt->level);
|
||||
break;
|
||||
case 705:
|
||||
if (!set_method(M_NRV2E_LE32, -1))
|
||||
e_method(M_NRV2E_LE32, opt->level);
|
||||
break;
|
||||
|
||||
// compression level
|
||||
case '1':
|
||||
@@ -486,16 +525,19 @@ static int do_option(int optc, const char *arg)
|
||||
if (!set_method(-1, optc - '0'))
|
||||
e_method(opt->method, optc);
|
||||
break;
|
||||
case 900:
|
||||
|
||||
case 901: // --brute
|
||||
opt->all_methods = true;
|
||||
opt->method = -1;
|
||||
opt->all_filters = true;
|
||||
opt->filter = -1;
|
||||
opt->crp.m_size = 999999;
|
||||
/* fallthrough */
|
||||
case 900: // --best
|
||||
if (!set_method(-1, 10))
|
||||
e_method(opt->method, 10);
|
||||
break;
|
||||
|
||||
// compression memory level
|
||||
case 902:
|
||||
getoptvar(&opt->mem_level, 1, 9);
|
||||
break;
|
||||
|
||||
// misc
|
||||
case 512:
|
||||
opt->console = CON_FILE;
|
||||
@@ -513,17 +555,27 @@ static int do_option(int optc, const char *arg)
|
||||
opt->no_env = true;
|
||||
break;
|
||||
// compression settings
|
||||
case 525:
|
||||
opt->small = 1;
|
||||
case 520: // --small
|
||||
if (opt->small < 0)
|
||||
opt->small = 0;
|
||||
opt->small++;
|
||||
break;
|
||||
case 526:
|
||||
case 521: // --filter=
|
||||
getoptvar(&opt->filter, 0, 255);
|
||||
opt->all_filters = false;
|
||||
break;
|
||||
case 527:
|
||||
case 522: // --no-filter
|
||||
opt->filter = 0;
|
||||
opt->all_filters = false;
|
||||
break;
|
||||
case 523: // --all-filters
|
||||
opt->all_filters = true;
|
||||
opt->filter = -1;
|
||||
break;
|
||||
case 524: // --all-methods
|
||||
opt->all_methods = true;
|
||||
opt->method = -1;
|
||||
break;
|
||||
// compression parms
|
||||
case 531:
|
||||
getoptvar(&opt->crp.c_flags, 0, 3);
|
||||
@@ -544,7 +596,8 @@ static int do_option(int optc, const char *arg)
|
||||
getoptvar(&opt->crp.max_match, 16u, ~0u);
|
||||
break;
|
||||
case 537:
|
||||
getoptvar(&opt->crp.m_size, 1024u, 512*1024u);
|
||||
if (getoptvar(&opt->crp.m_size, 10000u, 999999u) != 0)
|
||||
e_optval("--crp-ms=");
|
||||
break;
|
||||
// backup
|
||||
case 'k':
|
||||
@@ -596,50 +649,72 @@ static int do_option(int optc, const char *arg)
|
||||
break;
|
||||
//
|
||||
case 600:
|
||||
opt->dos.force_stub = true;
|
||||
opt->dos_exe.force_stub = true;
|
||||
break;
|
||||
case 601:
|
||||
opt->dos.no_reloc = true;
|
||||
opt->dos_exe.no_reloc = true;
|
||||
break;
|
||||
case 610:
|
||||
opt->djgpp2.coff = true;
|
||||
opt->djgpp2_coff.coff = true;
|
||||
break;
|
||||
case 620:
|
||||
opt->wcle.le = true;
|
||||
opt->watcom_le.le = true;
|
||||
break;
|
||||
case 630:
|
||||
opt->w32pe.compress_exports = 1;
|
||||
getoptvar(&opt->w32pe.compress_exports, 0, 1);
|
||||
//printf("compress_exports: %d\n", opt->w32pe.compress_exports);
|
||||
opt->win32_pe.compress_exports = 1;
|
||||
getoptvar(&opt->win32_pe.compress_exports, 0, 1);
|
||||
//printf("compress_exports: %d\n", opt->win32_pe.compress_exports);
|
||||
break;
|
||||
case 631:
|
||||
opt->w32pe.compress_icons = 1;
|
||||
getoptvar(&opt->w32pe.compress_icons, 0, 2);
|
||||
//printf("compress_icons: %d\n", opt->w32pe.compress_icons);
|
||||
opt->win32_pe.compress_icons = 1;
|
||||
getoptvar(&opt->win32_pe.compress_icons, 0, 2);
|
||||
//printf("compress_icons: %d\n", opt->win32_pe.compress_icons);
|
||||
break;
|
||||
case 632:
|
||||
opt->w32pe.compress_resources = true;
|
||||
opt->win32_pe.compress_resources = true;
|
||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||
opt->w32pe.compress_resources = false;
|
||||
//printf("compress_resources: %d\n", opt->w32pe.compress_resources);
|
||||
opt->win32_pe.compress_resources = false;
|
||||
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
|
||||
break;
|
||||
case 633:
|
||||
opt->w32pe.strip_relocs = 1;
|
||||
opt->win32_pe.strip_loadconf = 1;
|
||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||
opt->w32pe.strip_relocs = 0;
|
||||
//printf("strip_relocs: %d\n", opt->w32pe.strip_relocs);
|
||||
opt->win32_pe.strip_loadconf = 0;
|
||||
//printf("strip_loadconf: %d\n", opt->win32_pe.strip_loadconf);
|
||||
break;
|
||||
case 634:
|
||||
opt->win32_pe.strip_relocs = 1;
|
||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||
opt->win32_pe.strip_relocs = 0;
|
||||
//printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
|
||||
break;
|
||||
case 650:
|
||||
opt->tos.split_segments = true;
|
||||
opt->atari_tos.split_segments = true;
|
||||
break;
|
||||
case 660:
|
||||
getoptvar(&opt->unix.blocksize, 8192u, ~0u);
|
||||
getoptvar(&opt->o_unix.blocksize, 8192u, ~0u);
|
||||
break;
|
||||
case 661:
|
||||
opt->unix.script_name = "/usr/local/lib/upx/upxX";
|
||||
opt->o_unix.force_execve = true;
|
||||
break;
|
||||
case 662:
|
||||
opt->o_unix.script_name = "/usr/local/lib/upx/upxX";
|
||||
if (mfx_optarg && mfx_optarg[0])
|
||||
set_script_name(mfx_optarg,1);
|
||||
break;
|
||||
case 663:
|
||||
opt->o_unix.ptinterp = true;
|
||||
break;
|
||||
case 670:
|
||||
opt->ps1_exe.console_run = true;
|
||||
break;
|
||||
case 671:
|
||||
opt->ps1_exe.no_align = true;
|
||||
opt->ps1_exe.console_run = true;
|
||||
break;
|
||||
case 672:
|
||||
opt->ps1_exe.do_8bit = true;
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
return -1;
|
||||
@@ -661,10 +736,12 @@ static int get_options(int argc, char **argv)
|
||||
static const struct mfx_option longopts[] =
|
||||
{
|
||||
// commands
|
||||
{"best", 0, 0, 900}, // compress best
|
||||
{"best", 0x10, 0, 900}, // compress best
|
||||
{"brute", 0x10, 0, 901}, // compress best, brute force
|
||||
{"decompress", 0, 0, 'd'}, // decompress
|
||||
{"fast", 0, 0, '1'}, // compress faster
|
||||
{"fileinfo", 0x10, 0, 901}, // display info about file
|
||||
{"fast", 0x10, 0, '1'}, // compress faster
|
||||
{"fileinfo", 0x10, 0, 902}, // display info about file
|
||||
{"file-info", 0x10, 0, 902}, // display info about file
|
||||
{"help", 0, 0, 'h'+256}, // give help
|
||||
{"license", 0, 0, 'L'}, // display software license
|
||||
{"list", 0, 0, 'l'}, // list compressed exe
|
||||
@@ -682,8 +759,11 @@ static const struct mfx_option longopts[] =
|
||||
{"output", 0x21, 0, 'o'},
|
||||
{"quiet", 0, 0, 'q'}, // quiet mode
|
||||
{"silent", 0, 0, 'q'}, // quiet mode
|
||||
#if 0
|
||||
// FIXME: to_stdout doesn't work because of console code mess
|
||||
{"stdout", 0x10, 0, 517}, // write output on standard output
|
||||
{"to-stdout", 0x10, 0, 517}, // write output on standard output
|
||||
#endif
|
||||
{"verbose", 0, 0, 'v'}, // verbose mode
|
||||
|
||||
// backup options
|
||||
@@ -710,17 +790,15 @@ static const struct mfx_option longopts[] =
|
||||
{"color", 0, 0, 514},
|
||||
|
||||
// compression method
|
||||
{"2b", 0x10, 0, 702}, // --2b
|
||||
{"n2b", 0x10, 0, 702}, // --n2b
|
||||
{"nrv2b", 0x10, 0, 702}, // --nrv2b
|
||||
{"2d", 0x10, 0, 704}, // --2d
|
||||
{"n2d", 0x10, 0, 704}, // --n2d
|
||||
{"nrv2d", 0x10, 0, 704}, // --nrv2d
|
||||
{"nrv2e", 0x10, 0, 705}, // --nrv2e
|
||||
// compression settings
|
||||
{"all-filters", 0x10, 0, 527},
|
||||
{"filter", 0x31, 0, 526}, // --filter=
|
||||
{"mem", 0x31, 0, 902}, // --mem=
|
||||
{"small", 0x10, 0, 525},
|
||||
{"all-filters", 0x10, 0, 523},
|
||||
{"all-methods", 0x10, 0, 524},
|
||||
{"filter", 0x31, 0, 521}, // --filter=
|
||||
{"no-filter", 0x10, 0, 522},
|
||||
{"small", 0x10, 0, 520},
|
||||
// compression runtime parameters
|
||||
{"crp-cf", 0x31, 0, 531},
|
||||
{"crp-sl", 0x31, 0, 532},
|
||||
@@ -741,18 +819,25 @@ static const struct mfx_option longopts[] =
|
||||
// dos/sys
|
||||
// unix
|
||||
{"blocksize", 0x31, 0, 660}, // --blocksize=
|
||||
{"force-execve", 0x10, 0, 661}, // force linux/386 execve format
|
||||
#if 0
|
||||
{"script", 0x31, 0, 661}, // --script=
|
||||
{"script", 0x31, 0, 662}, // --script=
|
||||
#endif
|
||||
{"ptinterp", 0, 0, 663}, // 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-relocs", 2, 0, 633},
|
||||
{"strip-loadconf", 0x12, 0, 633},
|
||||
{"strip-relocs", 0x12, 0, 634},
|
||||
// ps1/exe
|
||||
{"console-run", 0x10, 0, 670},
|
||||
{"no-align", 0x10, 0, 671},
|
||||
{"8-bit", 0x10, 0, 672},
|
||||
|
||||
{ 0, 0, 0, 0 }
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int optc, longind;
|
||||
@@ -780,8 +865,9 @@ static void get_envoptions(int argc, char **argv)
|
||||
static const struct mfx_option longopts[] =
|
||||
{
|
||||
// commands
|
||||
{"best", 0, 0, 900}, // compress best
|
||||
{"fast", 0, 0, '1'}, // compress faster
|
||||
{"best", 0x10, 0, 900}, // compress best
|
||||
{"brute", 0x10, 0, 901}, // compress best, brute force
|
||||
{"fast", 0x10, 0, '1'}, // compress faster
|
||||
|
||||
// options
|
||||
{"info", 0, 0, 'i'}, // info mode
|
||||
@@ -813,13 +899,23 @@ static const struct mfx_option longopts[] =
|
||||
{"mono", 0, 0, 513},
|
||||
{"color", 0, 0, 514},
|
||||
|
||||
// compression runtime parameters
|
||||
{"crp-cf", 0x31, 0, 531},
|
||||
{"crp-sl", 0x31, 0, 532},
|
||||
{"crp-hl", 0x31, 0, 533},
|
||||
{"crp-pl", 0x31, 0, 534},
|
||||
{"crp-mo", 0x31, 0, 535},
|
||||
{"crp-mm", 0x31, 0, 536},
|
||||
{"crp-ms", 0x31, 0, 537},
|
||||
|
||||
// win32/pe
|
||||
{"compress-exports", 2, 0, 630},
|
||||
{"compress-icons", 2, 0, 631},
|
||||
{"compress-resources", 2, 0, 632},
|
||||
{"strip-relocs", 2, 0, 633},
|
||||
{"strip-loadconf", 0x12, 0, 633},
|
||||
{"strip-relocs", 0x12, 0, 634},
|
||||
|
||||
{ 0, 0, 0, 0 }
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
char *env, *p;
|
||||
@@ -907,14 +1003,22 @@ static const struct mfx_option longopts[] =
|
||||
static void first_options(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int n = argc;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
if (strcmp(argv[i],"--") == 0)
|
||||
{
|
||||
n = i;
|
||||
break;
|
||||
}
|
||||
if (strcmp(argv[i],"--version") == 0)
|
||||
do_option('V'+256, argv[i]);
|
||||
for (i = 1; i < argc; i++)
|
||||
}
|
||||
for (i = 1; i < n; i++)
|
||||
if (strcmp(argv[i],"--help") == 0)
|
||||
do_option('h'+256, argv[i]);
|
||||
for (i = 1; i < argc; i++)
|
||||
for (i = 1; i < n; i++)
|
||||
if (strcmp(argv[i],"--no-env") == 0)
|
||||
do_option(519, argv[i]);
|
||||
}
|
||||
@@ -926,57 +1030,54 @@ static void first_options(int argc, char **argv)
|
||||
|
||||
void upx_sanity_check(void)
|
||||
{
|
||||
assert(sizeof(char) == 1);
|
||||
assert(sizeof(short) == 2);
|
||||
assert(sizeof(int) == 4);
|
||||
assert(sizeof(long) >= 4);
|
||||
assert(sizeof(void *) >= 4);
|
||||
assert(sizeof(long) >= sizeof(void *));
|
||||
assert(((size_t) -1) > 0);
|
||||
assert(((ptrdiff_t) -1) < 0);
|
||||
assert(((off_t) -1) < 0);
|
||||
#include "acc/acc_chk.ch"
|
||||
|
||||
assert(sizeof(BE16) == 2);
|
||||
assert(sizeof(BE32) == 4);
|
||||
assert(sizeof(LE16) == 2);
|
||||
assert(sizeof(LE32) == 4);
|
||||
COMPILE_TIME_ASSERT(sizeof(char) == 1)
|
||||
COMPILE_TIME_ASSERT(sizeof(short) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(int) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(long) >= 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(void *) >= 4)
|
||||
|
||||
struct align_assertion_1a_t
|
||||
{
|
||||
struct foo_t {
|
||||
char c1;
|
||||
LE16 v[4];
|
||||
} d[3];
|
||||
};
|
||||
struct align_assertion_1b_t
|
||||
{
|
||||
struct foo_t {
|
||||
char c1;
|
||||
char v[4*2];
|
||||
} d[3];
|
||||
};
|
||||
struct align_assertion_2a_t
|
||||
{
|
||||
struct foo_t {
|
||||
char c1;
|
||||
LE32 v[4];
|
||||
} d[3];
|
||||
};
|
||||
struct align_assertion_2b_t
|
||||
{
|
||||
struct foo_t {
|
||||
char c1;
|
||||
char v[4*4];
|
||||
} d[3];
|
||||
};
|
||||
//printf("%d\n", (int) sizeof(align_assertion_1a_t));
|
||||
//printf("%d\n", (int) sizeof(align_assertion_1b_t));
|
||||
//printf("%d\n", (int) sizeof(align_assertion_2a_t));
|
||||
//printf("%d\n", (int) sizeof(align_assertion_2b_t));
|
||||
assert(sizeof(align_assertion_1a_t) == sizeof(align_assertion_1b_t));
|
||||
assert(sizeof(align_assertion_2a_t) == sizeof(align_assertion_2b_t));
|
||||
assert(sizeof(align_assertion_1a_t) == 3*9);
|
||||
assert(sizeof(align_assertion_2a_t) == 3*17);
|
||||
COMPILE_TIME_ASSERT(sizeof(off_t) >= sizeof(long))
|
||||
COMPILE_TIME_ASSERT(((off_t) -1) < 0)
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
|
||||
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE32, 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);
|
||||
|
||||
#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);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -986,40 +1087,42 @@ void upx_sanity_check(void)
|
||||
|
||||
#if !defined(WITH_GUI)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int __acc_cdecl_main main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
static char default_argv0[] = "upx";
|
||||
int cmdline_cmd = CMD_NONE;
|
||||
// int cmdline_cmd = CMD_NONE;
|
||||
|
||||
#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);
|
||||
|
||||
upx_sanity_check();
|
||||
init_options(opt);
|
||||
|
||||
#if defined(WITH_MSS)
|
||||
MSS_DISABLE_LOG_OUTPUT;
|
||||
#endif
|
||||
|
||||
#if defined(__EMX__)
|
||||
_response(&argc,&argv);
|
||||
_wildcard(&argc,&argv);
|
||||
#endif
|
||||
|
||||
if (!argv[0] || !argv[0][0])
|
||||
argv[0] = default_argv0;
|
||||
argv0 = argv[0];
|
||||
#if defined(DOSISH)
|
||||
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
{
|
||||
char *prog = fn_basename(argv0);
|
||||
char *p;
|
||||
bool allupper = 1;
|
||||
bool allupper = true;
|
||||
for (p = prog; *p; p++)
|
||||
if (islower((unsigned char)*p))
|
||||
allupper = 0;
|
||||
allupper = false;
|
||||
if (allupper)
|
||||
fn_strlwr(prog);
|
||||
if (strlen(prog) > 4)
|
||||
if (p - prog > 4)
|
||||
{
|
||||
p = prog + strlen(prog) - 4;
|
||||
p -= 4;
|
||||
if (fn_strcmp(p, ".exe") == 0 || fn_strcmp(p, ".ttp") == 0)
|
||||
*p = 0;
|
||||
}
|
||||
@@ -1028,6 +1131,8 @@ int main(int argc, char *argv[])
|
||||
#else
|
||||
progname = fn_basename(argv0);
|
||||
#endif
|
||||
while (progname[0] == '.' && progname[1] == '/' && progname[2])
|
||||
progname += 2;
|
||||
|
||||
set_term(stderr);
|
||||
|
||||
@@ -1043,7 +1148,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
if (nrv_init() != NRV_E_OK)
|
||||
if (nrv_init() != NRV_E_OK || NRV_VERSION != nrv_version())
|
||||
{
|
||||
show_head();
|
||||
fprintf(stderr,"nrv_init() failed - check your NRV installation !\n");
|
||||
@@ -1066,8 +1171,8 @@ int main(int argc, char *argv[])
|
||||
i = get_options(argc,argv);
|
||||
assert(i <= argc);
|
||||
|
||||
set_term(0);
|
||||
cmdline_cmd = opt->cmd;
|
||||
set_term(NULL);
|
||||
// cmdline_cmd = opt->cmd;
|
||||
switch (opt->cmd)
|
||||
{
|
||||
case CMD_NONE:
|
||||
@@ -1106,7 +1211,6 @@ int main(int argc, char *argv[])
|
||||
// invalidate compression options
|
||||
opt->method = 0;
|
||||
opt->level = 0;
|
||||
opt->mem_level = 0;
|
||||
memset(&opt->crp, 0xff, sizeof(opt->crp));
|
||||
}
|
||||
|
||||
@@ -1128,27 +1232,19 @@ int main(int argc, char *argv[])
|
||||
set_term(stdout);
|
||||
do_files(i,argc,argv);
|
||||
|
||||
#if 1 && (UPX_VERSION < 0x012000)
|
||||
#if 0 && (UPX_VERSION_HEX < 0x020000)
|
||||
{
|
||||
FILE *f = stdout;
|
||||
int fg = con_fg(f,FG_RED);
|
||||
con_fprintf(f,"\nWARNING: this is an unstable beta version - use for testing only! Really.\n");
|
||||
fg = con_fg(f,fg);
|
||||
}
|
||||
#endif
|
||||
#if 1 && !defined(WITH_NRV)
|
||||
{
|
||||
FILE *f = stdout;
|
||||
int fg = con_fg(f,FG_GREEN);
|
||||
con_fprintf(f,"\nINFO: this version does not use the NRV library - compression ratio is worse\n");
|
||||
fg = con_fg(f,fg);
|
||||
UNUSED(fg);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 && defined(__GLIBC__)
|
||||
//malloc_stats();
|
||||
#endif
|
||||
do_exit();
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
|
||||
+146
-64
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -34,84 +34,166 @@
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
MemBuffer::MemBuffer(unsigned size) :
|
||||
ptr(NULL), alloc_ptr(NULL), alloc_size(0)
|
||||
static int use_mcheck = -1;
|
||||
|
||||
static int mcheck_init()
|
||||
{
|
||||
if (size > 0)
|
||||
alloc(size, 0);
|
||||
if (use_mcheck < 0)
|
||||
{
|
||||
use_mcheck = 1;
|
||||
#if defined(WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
|
||||
if (RUNNING_ON_VALGRIND)
|
||||
{
|
||||
//fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n");
|
||||
use_mcheck = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return use_mcheck;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
MemBuffer::MemBuffer() :
|
||||
b(NULL), b_size(0)
|
||||
{
|
||||
}
|
||||
|
||||
MemBuffer::MemBuffer(unsigned size) :
|
||||
b(NULL), b_size(0)
|
||||
{
|
||||
alloc(size);
|
||||
}
|
||||
|
||||
|
||||
MemBuffer::~MemBuffer()
|
||||
{
|
||||
this->free();
|
||||
this->dealloc();
|
||||
}
|
||||
|
||||
|
||||
void MemBuffer::free()
|
||||
void MemBuffer::dealloc()
|
||||
{
|
||||
if (alloc_ptr)
|
||||
::free(alloc_ptr);
|
||||
alloc_ptr = ptr = NULL;
|
||||
alloc_size = 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned MemBuffer::getSize() const
|
||||
{
|
||||
if (!alloc_ptr)
|
||||
return 0;
|
||||
unsigned size = alloc_size - (ptr - alloc_ptr);
|
||||
assert((int)size > 0);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
void MemBuffer::alloc(unsigned size, unsigned base_offset)
|
||||
{
|
||||
#if 0
|
||||
this->free();
|
||||
#else
|
||||
// don't automaticlly free a used buffer
|
||||
#endif
|
||||
assert(alloc_ptr == NULL);
|
||||
assert((int)size > 0);
|
||||
size = base_offset + size;
|
||||
alloc_ptr = (unsigned char *) malloc(size);
|
||||
if (!alloc_ptr)
|
||||
if (b)
|
||||
{
|
||||
throwCantPack("out of memory");
|
||||
//exit(1);
|
||||
checkState();
|
||||
if (use_mcheck)
|
||||
{
|
||||
// remove magic constants
|
||||
set_be32(b - 8, 0);
|
||||
set_be32(b - 4, 0);
|
||||
set_be32(b + b_size, 0);
|
||||
set_be32(b + b_size + 4, 0);
|
||||
//
|
||||
::free(b - 8);
|
||||
}
|
||||
else
|
||||
::free(b);
|
||||
b = NULL;
|
||||
b_size = 0;
|
||||
}
|
||||
alloc_size = size;
|
||||
ptr = alloc_ptr + base_offset;
|
||||
else
|
||||
assert(b_size == 0);
|
||||
}
|
||||
|
||||
|
||||
void MemBuffer::allocForCompression(unsigned uncompressed_size, unsigned extra)
|
||||
{
|
||||
assert((int)uncompressed_size > 0);
|
||||
assert((int)extra >= 0);
|
||||
unsigned size = uncompressed_size + uncompressed_size/8 + 256 + extra;
|
||||
alloc(size);
|
||||
}
|
||||
|
||||
|
||||
void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra)
|
||||
{
|
||||
assert((int)uncompressed_size > 0);
|
||||
assert((int)extra >= 0);
|
||||
unsigned size = uncompressed_size + extra;
|
||||
// size += 512; // 512 safety bytes
|
||||
// INFO: 3 bytes are the allowed overrun for the i386 asm_fast decompressors
|
||||
#if (ACC_ARCH_IA32)
|
||||
size += 3;
|
||||
#endif
|
||||
alloc(size);
|
||||
}
|
||||
|
||||
|
||||
void MemBuffer::fill(unsigned off, unsigned len, int value)
|
||||
{
|
||||
checkState();
|
||||
assert((int)off >= 0);
|
||||
assert((int)len >= 0);
|
||||
assert(off <= b_size);
|
||||
assert(len <= b_size);
|
||||
assert(off + len <= b_size);
|
||||
if (len > 0)
|
||||
memset(b + off, value, len);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#define PTR(p) ((unsigned) ((acc_uintptr_t)(p) & 0xffffffff))
|
||||
#define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb)
|
||||
#define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001)
|
||||
|
||||
unsigned MemBuffer::global_alloc_counter = 0;
|
||||
|
||||
|
||||
void MemBuffer::checkState() const
|
||||
{
|
||||
if (!b)
|
||||
throwInternalError("block not allocated");
|
||||
if (use_mcheck)
|
||||
{
|
||||
if (get_be32(b - 4) != MAGIC1(b))
|
||||
throwInternalError("memory clobbered before allocated block 1");
|
||||
if (get_be32(b - 8) != b_size)
|
||||
throwInternalError("memory clobbered before allocated block 2");
|
||||
if (get_be32(b + b_size) != MAGIC2(b))
|
||||
throwInternalError("memory clobbered past end of allocated block");
|
||||
}
|
||||
assert((int)b_size > 0);
|
||||
}
|
||||
|
||||
|
||||
void MemBuffer::alloc(unsigned size)
|
||||
{
|
||||
alloc(size, 0);
|
||||
}
|
||||
if (use_mcheck < 0)
|
||||
mcheck_init();
|
||||
|
||||
|
||||
void MemBuffer::allocForCompression(unsigned uncompressed_size)
|
||||
{
|
||||
// Idea:
|
||||
// We allocate the buffer at an offset of 4096 so
|
||||
// that we could do an in-place decompression for
|
||||
// verifying our overlap_overhead at the end
|
||||
// of packing.
|
||||
// NOTE: we don't automatically free a used buffer
|
||||
assert(b == NULL);
|
||||
assert(b_size == 0);
|
||||
//
|
||||
// See Packer::verifyOverlappingDecompression().
|
||||
|
||||
alloc(uncompressed_size + uncompressed_size/8 + 256, MAX_OVERLAP_OVERHEAD);
|
||||
}
|
||||
|
||||
|
||||
void MemBuffer::allocForUncompression(unsigned uncompressed_size)
|
||||
{
|
||||
//alloc(uncompressed_size + 3 + 512, 0); // 512 safety bytes
|
||||
alloc(uncompressed_size + 3, 0); // 3 bytes for asm_fast decompresion
|
||||
assert((int)size > 0);
|
||||
unsigned total = use_mcheck ? size + 16 : size;
|
||||
assert((int)total > 0);
|
||||
unsigned char *p = (unsigned char *) malloc(total);
|
||||
if (!p)
|
||||
{
|
||||
//throw bad_alloc();
|
||||
throw OutOfMemoryException("out of memory");
|
||||
//exit(1);
|
||||
}
|
||||
b_size = size;
|
||||
if (use_mcheck)
|
||||
{
|
||||
b = p + 8;
|
||||
// store magic constants to detect buffer overruns
|
||||
set_be32(b - 8, b_size);
|
||||
set_be32(b - 4, MAGIC1(b));
|
||||
set_be32(b + b_size, MAGIC2(b));
|
||||
set_be32(b + b_size + 4, global_alloc_counter++);
|
||||
}
|
||||
else
|
||||
b = p ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -37,43 +37,43 @@
|
||||
class MemBuffer
|
||||
{
|
||||
public:
|
||||
MemBuffer(unsigned size=0);
|
||||
MemBuffer();
|
||||
MemBuffer(unsigned size);
|
||||
~MemBuffer();
|
||||
|
||||
void alloc(unsigned size);
|
||||
void allocForCompression(unsigned uncompressed_size);
|
||||
void allocForUncompression(unsigned uncompressed_size);
|
||||
void allocForCompression(unsigned uncompressed_size, unsigned extra=0);
|
||||
void allocForUncompression(unsigned uncompressed_size, unsigned extra=0);
|
||||
|
||||
void free();
|
||||
void dealloc();
|
||||
|
||||
const unsigned char *getBuf() const { return ptr; }
|
||||
unsigned getSize() const ;
|
||||
void checkState() const;
|
||||
|
||||
operator unsigned char * () { return ptr; }
|
||||
//operator const unsigned char * () const { return ptr; }
|
||||
unsigned getSize() const { return b_size; }
|
||||
|
||||
enum { MAX_OVERLAP_OVERHEAD = 4096 };
|
||||
operator unsigned char * () { return b; }
|
||||
//operator const unsigned char * () const { return b; }
|
||||
void *getVoidPtr() { return (void *) b; }
|
||||
const void *getVoidPtr() const { return (const void *) b; }
|
||||
|
||||
void fill(unsigned off, unsigned len, int value);
|
||||
void clear(unsigned off, unsigned len) { fill(off, len, 0); }
|
||||
void clear() { fill(0, b_size, 0); }
|
||||
|
||||
private:
|
||||
void alloc(unsigned size, unsigned base_offset);
|
||||
unsigned char *b;
|
||||
unsigned b_size;
|
||||
|
||||
unsigned char *ptr;
|
||||
unsigned char *alloc_ptr;
|
||||
unsigned alloc_size;
|
||||
static unsigned global_alloc_counter;
|
||||
|
||||
private:
|
||||
// disable copy and assignment
|
||||
MemBuffer(MemBuffer const &); // {}
|
||||
MemBuffer& operator= (MemBuffer const &); // { return *this; }
|
||||
MemBuffer(const MemBuffer &); // {}
|
||||
MemBuffer& operator= (const MemBuffer &); // { return *this; }
|
||||
|
||||
// disable dynamic allocation
|
||||
static void *operator new (size_t); // {}
|
||||
static void *operator new[] (size_t); // {}
|
||||
//static void operator delete (void *) {}
|
||||
//static void operator delete[] (void *) {}
|
||||
DISABLE_NEW_DELETE
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
|
||||
+28
-17
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@ static void pr_print(bool c, const char *msg)
|
||||
|
||||
static void pr_error(const char *iname, const char *msg, bool is_warning)
|
||||
{
|
||||
set_ec(EXIT_ERROR);
|
||||
fflush(stdout); fflush(stderr);
|
||||
char buf[1024];
|
||||
buf[0] = 0;
|
||||
@@ -89,7 +88,7 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
|
||||
// This hack is needed, otherwise error messages may get lost
|
||||
// when the cursor is not yet at the bottom of the screen.
|
||||
// At least I can use some colors then...
|
||||
bool c = isatty(STDERR_FILENO) ? 1 : 0;
|
||||
bool c = acc_isatty(STDERR_FILENO) ? 1 : 0;
|
||||
|
||||
int fg = con_fg(stderr,FG_BRTRED);
|
||||
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"%s: ", progname);
|
||||
@@ -104,23 +103,35 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
|
||||
fg = con_fg(stderr,fg);
|
||||
|
||||
UNUSED(is_warning);
|
||||
UNUSED(fg);
|
||||
}
|
||||
|
||||
|
||||
void printErr(const char *iname, const Throwable *e)
|
||||
{
|
||||
char buf[1024];
|
||||
size_t l;
|
||||
|
||||
upx_snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e)));
|
||||
if (e->getMsg())
|
||||
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),": %s", e->getMsg());
|
||||
if (e->getErrno())
|
||||
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),": %s", strerror(e->getErrno()));
|
||||
upx_snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e).name()));
|
||||
l = strlen(buf);
|
||||
if (l < sizeof(buf) && e->getMsg())
|
||||
upx_snprintf(buf+l, sizeof(buf)-l, ": %s", e->getMsg());
|
||||
l = strlen(buf);
|
||||
if (l < sizeof(buf) && e->getErrno()) {
|
||||
upx_snprintf(buf+l, sizeof(buf)-l, ": %s", strerror(e->getErrno()));
|
||||
#if 1
|
||||
// some compilers (e.g. Borland C++) put a trailing '\n'
|
||||
// into strerror() result
|
||||
l = strlen(buf);
|
||||
while (l-- > 0 && (buf[l] == '\n' || buf[l] == ' '))
|
||||
buf[l] = 0;
|
||||
#endif
|
||||
}
|
||||
pr_error(iname,buf,e->isWarning());
|
||||
}
|
||||
|
||||
|
||||
void printErr(const char *iname, const char *format, ...)
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[1024];
|
||||
@@ -133,7 +144,7 @@ void printErr(const char *iname, const char *format, ...)
|
||||
}
|
||||
|
||||
|
||||
void printWarn(const char *iname, const char *format, ...)
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[1024];
|
||||
@@ -146,7 +157,7 @@ void printWarn(const char *iname, const char *format, ...)
|
||||
}
|
||||
|
||||
|
||||
void printUnhandledException(const char *iname, const exception *e)
|
||||
void printUnhandledException(const char *iname, const std::exception *e)
|
||||
{
|
||||
if (e)
|
||||
printErr(iname,"unhandled exception: %s\n", prettyName(e->what()));
|
||||
@@ -190,7 +201,7 @@ void infoHeader()
|
||||
info_header = 0;
|
||||
}
|
||||
|
||||
void infoHeader(const char *format, ...)
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||
{
|
||||
if (opt->info_mode <= 0)
|
||||
return;
|
||||
@@ -204,7 +215,7 @@ void infoHeader(const char *format, ...)
|
||||
}
|
||||
|
||||
|
||||
void info(const char *format, ...)
|
||||
void __acc_cdecl_va info(const char *format, ...)
|
||||
{
|
||||
if (opt->info_mode <= 0)
|
||||
return;
|
||||
@@ -219,7 +230,7 @@ void info(const char *format, ...)
|
||||
}
|
||||
|
||||
|
||||
void infoWarning(const char *format, ...)
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||
{
|
||||
if (opt->info_mode <= 0)
|
||||
{
|
||||
|
||||
+40
-30
@@ -21,11 +21,22 @@
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
|
||||
#include "tailor.h"
|
||||
|
||||
#undef PROGNAME
|
||||
#if 0
|
||||
#ifndef EOF
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#define PROGNAME(x) (x)
|
||||
#else
|
||||
#include "conf.h"
|
||||
static const char *my_progname(const char *argv0)
|
||||
{
|
||||
return progname ? progname : argv0;
|
||||
}
|
||||
#define PROGNAME(x) my_progname(x)
|
||||
#endif
|
||||
|
||||
|
||||
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
|
||||
@@ -54,8 +65,6 @@
|
||||
#define optind mfx_optind
|
||||
#define opterr mfx_opterr
|
||||
#define optopt mfx_optopt
|
||||
#define my_index strchr
|
||||
#define my_strlen strlen
|
||||
#undef BAD_OPTION
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
@@ -167,7 +176,7 @@ static int last_nonopt;
|
||||
|
||||
static void exchange (char **argv)
|
||||
{
|
||||
char *temp, **first, **last;
|
||||
char *temp; char **first, **last;
|
||||
|
||||
/* Reverse all the elements [first_nonopt, optind) */
|
||||
first = &argv[first_nonopt];
|
||||
@@ -382,15 +391,10 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
int indfound = 0;
|
||||
int needexact = 0;
|
||||
|
||||
#if defined(DOSISH)
|
||||
/* allow `--option#value' because you cannout assign a '='
|
||||
to an environment variable under DOS command.com */
|
||||
while (*s && *s != '=' && * s != '#')
|
||||
s++;
|
||||
#else
|
||||
while (*s && *s != '=')
|
||||
s++;
|
||||
#endif
|
||||
|
||||
/* Test all options for either exact match or abbreviated matches. */
|
||||
for (p = longopts, option_index = 0; p->name;
|
||||
@@ -399,7 +403,7 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
{
|
||||
if (p->has_arg & 0x10)
|
||||
needexact = 1;
|
||||
if ((unsigned) (s - nextchar) == my_strlen (p->name))
|
||||
if ((unsigned) (s - nextchar) == strlen (p->name))
|
||||
{
|
||||
/* Exact match found. */
|
||||
pfound = p;
|
||||
@@ -423,8 +427,8 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: unrecognized option `%s'\n",
|
||||
argv[0], argv[optind]);
|
||||
nextchar += my_strlen (nextchar);
|
||||
PROGNAME(argv[0]), argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
@@ -432,8 +436,8 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: option `%s' is ambiguous\n",
|
||||
argv[0], argv[optind]);
|
||||
nextchar += my_strlen (nextchar);
|
||||
PROGNAME(argv[0]), argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
@@ -459,14 +463,14 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
/* --option */
|
||||
fprintf (stderr,
|
||||
"%s: option `--%s' doesn't allow an argument\n",
|
||||
argv[0], pfound->name);
|
||||
PROGNAME(argv[0]), pfound->name);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr,
|
||||
"%s: option `%c%s' doesn't allow an argument\n",
|
||||
argv[0], argv[optind - 1][0], pfound->name);
|
||||
PROGNAME(argv[0]), argv[optind - 1][0], pfound->name);
|
||||
}
|
||||
nextchar += my_strlen (nextchar);
|
||||
nextchar += strlen (nextchar);
|
||||
return BAD_OPTION;
|
||||
}
|
||||
}
|
||||
@@ -482,13 +486,13 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: option `--%s%s' requires an argument\n",
|
||||
argv[0], pfound->name,
|
||||
PROGNAME(argv[0]), pfound->name,
|
||||
(pfound->has_arg & 0x20) ? "=" : "");
|
||||
nextchar += my_strlen (nextchar);
|
||||
nextchar += strlen (nextchar);
|
||||
return optstring[0] == ':' ? ':' : BAD_OPTION;
|
||||
}
|
||||
}
|
||||
nextchar += my_strlen (nextchar);
|
||||
nextchar += strlen (nextchar);
|
||||
if (longind != NULL)
|
||||
*longind = option_index;
|
||||
if (pfound->flag)
|
||||
@@ -506,31 +510,31 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
#ifdef GETOPT_COMPAT
|
||||
|| argv[optind][0] == '+'
|
||||
#endif /* GETOPT_COMPAT */
|
||||
|| my_index (optstring, *nextchar) == NULL)
|
||||
|| strchr (optstring, *nextchar) == NULL)
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
if (argv[optind][1] == '-')
|
||||
/* --option */
|
||||
fprintf (stderr, "%s: unrecognized option `--%s'\n",
|
||||
argv[0], nextchar);
|
||||
PROGNAME(argv[0]), nextchar);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
|
||||
argv[0], argv[optind][0], nextchar);
|
||||
PROGNAME(argv[0]), argv[optind][0], nextchar);
|
||||
}
|
||||
nextchar = empty_string;
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
ambig = ambig;
|
||||
(void) &ambig; /* UNUSED */
|
||||
}
|
||||
|
||||
/* Look at and handle the next option-character. */
|
||||
|
||||
{
|
||||
char c = *nextchar++;
|
||||
const char *temp = my_index (optstring, c);
|
||||
const char *temp = strchr (optstring, c);
|
||||
|
||||
/* Increment `optind' when we start to process its last character. */
|
||||
if (*nextchar == '\0')
|
||||
@@ -543,12 +547,12 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
#if 0
|
||||
if (c < 040 || c >= 0177)
|
||||
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
|
||||
argv[0], c);
|
||||
PROGNAME(argv[0]), c);
|
||||
else
|
||||
fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
|
||||
fprintf (stderr, "%s: unrecognized option `-%c'\n", PROGNAME(argv[0]), c);
|
||||
#else
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
|
||||
fprintf (stderr, "%s: illegal option -- %c\n", PROGNAME(argv[0]), c);
|
||||
#endif
|
||||
}
|
||||
optopt = c;
|
||||
@@ -584,11 +588,11 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
{
|
||||
#if 0
|
||||
fprintf (stderr, "%s: option `-%c' requires an argument\n",
|
||||
argv[0], c);
|
||||
PROGNAME(argv[0]), c);
|
||||
#else
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr, "%s: option requires an argument -- %c\n",
|
||||
argv[0], c);
|
||||
PROGNAME(argv[0]), c);
|
||||
#endif
|
||||
}
|
||||
optopt = c;
|
||||
@@ -694,3 +698,9 @@ main (argc, argv)
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@
|
||||
#define __MFX_GETOPT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
/* extern "C" { */
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
@@ -96,7 +96,7 @@ int mfx_getopt_long(int argc, char **argv, const char *shortopts,
|
||||
const struct mfx_option *longopts, int *longind);
|
||||
|
||||
#ifdef __cplusplus
|
||||
//}
|
||||
/* } */
|
||||
#endif
|
||||
|
||||
#endif /* _GETOPT_H */
|
||||
#endif /* __MFX_GETOPT_H */
|
||||
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
/* options.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2004 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_OPTIONS_H
|
||||
#define __UPX_OPTIONS_H
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// globals
|
||||
**************************************************************************/
|
||||
|
||||
// options - command
|
||||
enum {
|
||||
CMD_NONE,
|
||||
CMD_COMPRESS, CMD_DECOMPRESS, CMD_TEST, CMD_LIST, CMD_FILEINFO,
|
||||
CMD_HELP, CMD_LICENSE, CMD_VERSION
|
||||
};
|
||||
|
||||
|
||||
struct options_t {
|
||||
int cmd;
|
||||
|
||||
// compression options
|
||||
int method;
|
||||
int level; // compression level 1..10
|
||||
int filter; // preferred filter from Packer::getFilters()
|
||||
bool all_methods; // try all available compression methods ?
|
||||
bool all_filters; // try all available filters ?
|
||||
|
||||
// other options
|
||||
int backup;
|
||||
int console;
|
||||
int debug;
|
||||
int force;
|
||||
int info_mode;
|
||||
bool ignorewarn;
|
||||
bool no_env;
|
||||
bool no_progress;
|
||||
const char *output_name;
|
||||
int small;
|
||||
int verbose;
|
||||
bool to_stdout;
|
||||
|
||||
// overlay handling
|
||||
enum {
|
||||
SKIP_OVERLAY = 0,
|
||||
COPY_OVERLAY = 1,
|
||||
STRIP_OVERLAY = 2
|
||||
};
|
||||
int overlay;
|
||||
|
||||
// compression runtime parameters - see struct ucl_compress_config_t
|
||||
struct {
|
||||
upx_uint max_offset;
|
||||
upx_uint max_match;
|
||||
int s_level;
|
||||
int h_level;
|
||||
int p_level;
|
||||
int c_flags;
|
||||
upx_uint m_size;
|
||||
} crp;
|
||||
|
||||
// CPU
|
||||
enum {
|
||||
CPU_DEFAULT = 0,
|
||||
CPU_8086 = 1,
|
||||
CPU_286 = 2,
|
||||
CPU_386 = 3,
|
||||
CPU_486 = 4,
|
||||
CPU_586 = 5,
|
||||
CPU_686 = 6
|
||||
};
|
||||
int cpu;
|
||||
|
||||
// options for various executable formats
|
||||
struct {
|
||||
bool split_segments;
|
||||
} atari_tos;
|
||||
struct {
|
||||
bool coff;
|
||||
} djgpp2_coff;
|
||||
struct {
|
||||
bool force_stub;
|
||||
bool no_reloc;
|
||||
} dos_exe;
|
||||
struct {
|
||||
bool console_run;
|
||||
bool no_align;
|
||||
bool do_8bit;
|
||||
} ps1_exe;
|
||||
struct {
|
||||
unsigned blocksize;
|
||||
bool force_execve; // force the linux/386 execve format
|
||||
bool ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
} o_unix;
|
||||
struct {
|
||||
bool le;
|
||||
} watcom_le;
|
||||
struct {
|
||||
int compress_exports;
|
||||
int compress_icons;
|
||||
int compress_resources;
|
||||
signed char compress_rt[25]; // 25 == RT_LAST
|
||||
int strip_loadconf;
|
||||
int strip_relocs;
|
||||
} win32_pe;
|
||||
};
|
||||
|
||||
extern struct options_t * volatile opt;
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+41
-45
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
static const
|
||||
#include "stub/l_com.h"
|
||||
|
||||
#define STACKSIZE 0x60
|
||||
|
||||
//#define TESTING
|
||||
|
||||
|
||||
@@ -44,22 +42,27 @@ static const
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int PackCom::getCompressionMethod() const
|
||||
const int *PackCom::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
if (M_IS_NRV2B(opt->method))
|
||||
return M_NRV2B_LE16;
|
||||
static const int m_nrv2b[] = { M_NRV2B_LE16, -1 };
|
||||
if (M_IS_NRV2B(method))
|
||||
return m_nrv2b;
|
||||
#if 0
|
||||
// NOT IMPLEMENTED
|
||||
if (M_IS_NRV2D(opt->method))
|
||||
return M_NRV2D_LE16;
|
||||
static const int m_nrv2d[] = { M_NRV2D_LE16, -1 };
|
||||
if (M_IS_NRV2D(method))
|
||||
return m_nrv2d;
|
||||
#endif
|
||||
return M_NRV2B_LE16;
|
||||
UNUSED(level);
|
||||
return m_nrv2b;
|
||||
}
|
||||
|
||||
|
||||
const int *PackCom::getFilters() const
|
||||
{
|
||||
static const int filters[] = { 0x06, 0x03, 0x04, 0x01, 0x05, 0x02, -1 };
|
||||
static const int filters[] = {
|
||||
0x06, 0x03, 0x04, 0x01, 0x05, 0x02,
|
||||
-1 };
|
||||
return filters;
|
||||
}
|
||||
|
||||
@@ -72,14 +75,13 @@ bool PackCom::canPack()
|
||||
{
|
||||
unsigned char buf[128];
|
||||
|
||||
fi->readx(buf,128);
|
||||
fi->readx(buf, sizeof(buf));
|
||||
if (memcmp(buf,"MZ",2) == 0 || memcmp(buf,"ZM",2) == 0 // .exe
|
||||
|| memcmp (buf,"\xff\xff\xff\xff",4) == 0) // .sys
|
||||
return false;
|
||||
if (!fn_has_ext(fi->getName(),"com"))
|
||||
return false;
|
||||
if (find_le32(buf,128,UPX_MAGIC_LE32) >= 0)
|
||||
throwAlreadyPacked();
|
||||
checkAlreadyPacked(buf, sizeof(buf));
|
||||
if (file_size < 1024)
|
||||
throwCantPack("file is too small");
|
||||
if (file_size > 0xFF00)
|
||||
@@ -94,7 +96,7 @@ bool PackCom::canPack()
|
||||
|
||||
void PackCom::patchLoader(OutputFile *fo,
|
||||
upx_byte *loader, int lsize,
|
||||
unsigned calls, unsigned overlapoh)
|
||||
unsigned calls)
|
||||
{
|
||||
const int filter_id = ph.filter;
|
||||
const int e_len = getLoaderSectionStart("COMCUTPO");
|
||||
@@ -102,9 +104,12 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
assert(e_len > 0 && e_len < 256);
|
||||
assert(d_len > 0 && d_len < 256);
|
||||
|
||||
const unsigned upper_end = ph.u_len + overlapoh + d_len + 0x100;
|
||||
if (upper_end + STACKSIZE > 0xfffe)
|
||||
throwNotCompressible();
|
||||
const unsigned upper_end = ph.u_len + ph.overlap_overhead + d_len + 0x100;
|
||||
unsigned stacksize = 0x60;
|
||||
if (upper_end + stacksize > 0xfffe)
|
||||
stacksize = 0x56;
|
||||
if (upper_end + stacksize > 0xfffe)
|
||||
throwCantPack("file is too big for dos/com");
|
||||
|
||||
if (filter_id)
|
||||
{
|
||||
@@ -116,11 +121,11 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
|
||||
// NOTE: Depends on: decompr_start == cutpoint+1 !!!
|
||||
patch_le16(loader,e_len,"JM",upper_end - 0xff - d_len - getLoaderSection("UPX1HEAD"));
|
||||
loader[getLoaderSection("COMSUBSI") - 1] = (upx_byte) -e_len;
|
||||
loader[getLoaderSectionStart("COMSUBSI") - 1] = (upx_byte) -e_len;
|
||||
patch_le16(loader,e_len,"DI",upper_end);
|
||||
patch_le16(loader,e_len,"SI",ph.c_len + lsize + 0x100);
|
||||
patch_le16(loader,e_len,"CX",ph.c_len + lsize);
|
||||
patch_le16(loader,e_len,"SP",upper_end + STACKSIZE);
|
||||
patch_le16(loader,e_len,"SP",upper_end + stacksize);
|
||||
|
||||
// write loader + compressed file
|
||||
fo->write(loader,e_len); // entry
|
||||
@@ -136,19 +141,23 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
|
||||
int PackCom::buildLoader(const Filter *ft)
|
||||
{
|
||||
const int filter_id = ft->id;
|
||||
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
|
||||
addLoader("COMMAIN1""COMSUBSI",
|
||||
filter_id ? "COMCALLT" : "",
|
||||
ph.first_offset_found == 1 ? "COMSBBBP" : "",
|
||||
"COMPSHDI",
|
||||
ft->id ? "COMCALLT" : "",
|
||||
"COMMAIN2""UPX1HEAD""COMCUTPO""NRV2B160",
|
||||
filter_id ? "NRVDDONE" : "NRVDRETU",
|
||||
ft->id ? "NRVDDONE" : "NRVDRETU",
|
||||
"NRVDECO1",
|
||||
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
|
||||
"NRVDECO2""NRV2B169",
|
||||
NULL
|
||||
);
|
||||
if (filter_id)
|
||||
addFilter16(filter_id);
|
||||
if (ft->id)
|
||||
{
|
||||
assert(ft->calls > 0);
|
||||
addFilter16(ft->id);
|
||||
}
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -192,35 +201,22 @@ void PackCom::pack(OutputFile *fo)
|
||||
|
||||
// prepare packheader
|
||||
ph.u_len = file_size;
|
||||
ph.filter = 0;
|
||||
// prepare filter
|
||||
Filter ft(opt->level);
|
||||
Filter ft(ph.level);
|
||||
ft.addvalue = getCallTrickOffset();
|
||||
// prepare other settings
|
||||
// compress
|
||||
const unsigned overlap_range = ph.u_len < 0xFE00 - ft.addvalue ? 32 : 0;
|
||||
unsigned overlapoh;
|
||||
|
||||
int strategy = -1; // try the first working filter
|
||||
if (opt->filter >= 0 && isValidFilter(opt->filter))
|
||||
// try opt->filter or 0 if that fails
|
||||
strategy = -2;
|
||||
else if (opt->all_filters || opt->level > 9)
|
||||
// choose best from all available filters
|
||||
strategy = 0;
|
||||
else if (opt->level == 9)
|
||||
// choose best from the first 4 filters
|
||||
strategy = 4;
|
||||
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
|
||||
compressWithFilters(&ft, overlap_range);
|
||||
|
||||
const int lsize = getLoaderSize();
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader,getLoader(),lsize);
|
||||
|
||||
const unsigned calls = ft.id % 3 ? ft.lastcall - 2 * ft.calls : ft.calls;
|
||||
patchLoader(fo, loader, lsize, calls, overlapoh);
|
||||
patchLoader(fo, loader, lsize, calls);
|
||||
|
||||
// verify
|
||||
verifyOverlappingDecompression(&obuf, overlapoh);
|
||||
verifyOverlappingDecompression();
|
||||
|
||||
// finally check the compression ratio
|
||||
if (!checkFinalCompressionRatio(fo))
|
||||
|
||||
+8
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,8 +21,8 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ class PackCom : public Packer
|
||||
typedef Packer super;
|
||||
public:
|
||||
PackCom(InputFile *f) : super(f) { }
|
||||
virtual int getVersion() const { return 11; }
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_DOS_COM; }
|
||||
virtual const char *getName() const { return "dos/com"; }
|
||||
virtual int getCompressionMethod() const;
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
@@ -52,11 +52,11 @@ public:
|
||||
virtual int canUnpack();
|
||||
|
||||
protected:
|
||||
virtual const unsigned getCallTrickOffset() const { return 0x100; }
|
||||
virtual unsigned getCallTrickOffset() const { return 0x100; }
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned, unsigned);
|
||||
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
|
||||
virtual void addFilter16(int filter_id);
|
||||
};
|
||||
|
||||
|
||||
+152
-137
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
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
|
||||
@@ -21,21 +21,21 @@
|
||||
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "file.h"
|
||||
#include "filter.h"
|
||||
#include "packer.h"
|
||||
#include "p_djgpp2.h"
|
||||
|
||||
static const
|
||||
#include "stub/stubify.h"
|
||||
|
||||
static const
|
||||
#include "stub/l_djgpp2.h"
|
||||
static const
|
||||
#include "stub/stubify.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -45,32 +45,47 @@ static const
|
||||
PackDjgpp2::PackDjgpp2(InputFile *f) :
|
||||
super(f), coff_offset(0)
|
||||
{
|
||||
assert(sizeof(coff_hdr) == 0xa8);
|
||||
assert(sizeof(stubify_stub) == 2048);
|
||||
COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40);
|
||||
COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8);
|
||||
COMPILE_TIME_ASSERT(sizeof(stubify_stub) == 2048);
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(external_scnhdr_t, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(coff_header_t, char)
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_ADLER32 == 0xbf689ba8);
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_CRC32 == 0x2ae982b2);
|
||||
//printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub)));
|
||||
assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
|
||||
}
|
||||
|
||||
|
||||
int PackDjgpp2::getCompressionMethod() const
|
||||
const int *PackDjgpp2::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
if (M_IS_NRV2B(opt->method))
|
||||
return M_NRV2B_LE32;
|
||||
if (M_IS_NRV2D(opt->method))
|
||||
return M_NRV2D_LE32;
|
||||
return opt->level > 1 && file_size >= 512*1024 ? M_NRV2D_LE32 : M_NRV2B_LE32;
|
||||
return Packer::getDefaultCompressionMethods_le32(method, level);
|
||||
}
|
||||
|
||||
|
||||
const int *PackDjgpp2::getFilters() const
|
||||
{
|
||||
static const int filters[] = { 0x26, 0x24, 0x11, 0x14, 0x13, 0x16,
|
||||
0x25, 0x15, 0x12, -1 };
|
||||
static const int filters[] = {
|
||||
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
||||
-1 };
|
||||
return filters;
|
||||
}
|
||||
|
||||
|
||||
unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf,
|
||||
unsigned range,
|
||||
unsigned upper_limit) const
|
||||
{
|
||||
unsigned o = super::findOverlapOverhead(buf, range, upper_limit);
|
||||
o = (o + 0x3ff) &~ 0x1ff;
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
addLoader("IDENTSTR""DJ2MAIN1",
|
||||
ft->id ? "DJCALLT1" : "",
|
||||
"DJ2MAIN2",
|
||||
@@ -81,10 +96,10 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
if (ft->id)
|
||||
{
|
||||
assert(ft->calls > 0);
|
||||
addLoader("DJCALLT2",NULL);
|
||||
addLoader("DJCALLT2", NULL);
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("DJRETURN+40DXXXXUPX1HEAD",NULL);
|
||||
addLoader("DJRETURN+40DXXXXUPX1HEAD", NULL);
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
@@ -95,18 +110,18 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
|
||||
void PackDjgpp2::handleStub(OutputFile *fo)
|
||||
{
|
||||
if (fo && !opt->djgpp2.coff)
|
||||
if (fo && !opt->djgpp2_coff.coff)
|
||||
{
|
||||
if (coff_offset > 0)
|
||||
{
|
||||
// copy stub from exe
|
||||
Packer::handleStub(fi,fo,coff_offset);
|
||||
Packer::handleStub(fi, fo, coff_offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
// "stubify" stub
|
||||
info("Adding stub: %ld bytes", (long)sizeof(stubify_stub));
|
||||
fo->write(stubify_stub,sizeof(stubify_stub));
|
||||
fo->write(stubify_stub, sizeof(stubify_stub));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,16 +133,16 @@ static bool is_dlm(InputFile *fi, long coff_offset)
|
||||
long off;
|
||||
|
||||
try {
|
||||
fi->seek(coff_offset,SEEK_SET);
|
||||
fi->readx(buf,4);
|
||||
fi->seek(coff_offset, SEEK_SET);
|
||||
fi->readx(buf, 4);
|
||||
off = get_le32(buf);
|
||||
if (off < 0 || off > coff_offset + 4)
|
||||
return false;
|
||||
fi->seek(off,SEEK_SET);
|
||||
fi->readx(buf,4);
|
||||
if (memcmp(buf,"DLMF",4) == 0)
|
||||
fi->seek(off, SEEK_SET);
|
||||
fi->readx(buf, 4);
|
||||
if (memcmp(buf, "DLMF", 4) == 0)
|
||||
return true;
|
||||
} catch (IOException&) {
|
||||
} catch (const IOException&) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -136,65 +151,67 @@ static bool is_dlm(InputFile *fi, long coff_offset)
|
||||
static void handle_allegropak(InputFile *fi, OutputFile *fo)
|
||||
{
|
||||
unsigned char buf[0x4000];
|
||||
unsigned pfsize=0, ic;
|
||||
int pfsize = 0;
|
||||
|
||||
try {
|
||||
fi->seek(-8,SEEK_END);
|
||||
fi->readx(buf,8);
|
||||
if (memcmp(buf,"slh+",4) != 0)
|
||||
fi->seek(-8, SEEK_END);
|
||||
fi->readx(buf, 8);
|
||||
if (memcmp(buf, "slh+", 4) != 0)
|
||||
return;
|
||||
pfsize = get_be32(buf+4);
|
||||
fi->seek(-(off_t)pfsize,SEEK_END);
|
||||
} catch (IOException&) {
|
||||
pfsize = get_be32_signed(buf+4);
|
||||
if (pfsize <= 8 || pfsize >= fi->st.st_size)
|
||||
return;
|
||||
fi->seek(-pfsize, SEEK_END);
|
||||
} catch (const IOException&) {
|
||||
return;
|
||||
}
|
||||
while (pfsize)
|
||||
while (pfsize > 0)
|
||||
{
|
||||
ic = pfsize < sizeof(buf) ? pfsize : sizeof(buf);
|
||||
fi->readx(buf,ic);
|
||||
fo->write(buf,ic);
|
||||
pfsize -= ic;
|
||||
const int len = UPX_MIN(pfsize, (int)sizeof(buf));
|
||||
fi->readx(buf, len);
|
||||
fo->write(buf, len);
|
||||
pfsize -= len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool PackDjgpp2::readFileHeader()
|
||||
int PackDjgpp2::readFileHeader()
|
||||
{
|
||||
unsigned char hdr[0x1c];
|
||||
unsigned char magic[8];
|
||||
|
||||
fi->seek(0,SEEK_SET);
|
||||
fi->readx(hdr,sizeof(hdr));
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(hdr, sizeof(hdr));
|
||||
if (get_le16(hdr) == 0x5a4d) // MZ exe signature, stubbed?
|
||||
{
|
||||
coff_offset = 512 * get_le16(hdr+4);
|
||||
if (get_le16(hdr+2) != 0)
|
||||
coff_offset += get_le16(hdr+2) - 512;
|
||||
fi->seek(512,SEEK_SET);
|
||||
fi->readx(magic,8);
|
||||
if (memcmp("go32stub",magic,8) != 0)
|
||||
return false; // not V2 image
|
||||
fi->seek(coff_offset,SEEK_SET);
|
||||
if (fi->read(&coff_hdr,sizeof(coff_hdr)) != sizeof(coff_hdr))
|
||||
fi->seek(512, SEEK_SET);
|
||||
fi->readx(magic, 8);
|
||||
if (memcmp("go32stub", magic, 8) != 0)
|
||||
return 0; // not V2 image
|
||||
fi->seek(coff_offset, SEEK_SET);
|
||||
if (fi->read(&coff_hdr, sizeof(coff_hdr)) != sizeof(coff_hdr))
|
||||
throwCantPack("skipping djgpp symlink");
|
||||
}
|
||||
else
|
||||
{
|
||||
fi->seek(coff_offset,SEEK_SET);
|
||||
fi->readx(&coff_hdr,0xa8);
|
||||
fi->seek(coff_offset, SEEK_SET);
|
||||
fi->readx(&coff_hdr, 0xa8);
|
||||
}
|
||||
if (coff_hdr.f_magic != 0x014c) // I386MAGIC
|
||||
return false;
|
||||
return 0;
|
||||
if ((coff_hdr.f_flags & 2) == 0) // F_EXEC - COFF executable
|
||||
return false;
|
||||
return 0;
|
||||
if (coff_hdr.a_magic != 0413) // ZMAGIC - demand load format
|
||||
return false;
|
||||
return 0;
|
||||
// FIXME: check for Linux etc.
|
||||
|
||||
text = coff_hdr.sh;
|
||||
data = text + 1;
|
||||
bss = data + 1;
|
||||
return true;
|
||||
return UPX_F_DJGPP2_COFF;
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +221,7 @@ void PackDjgpp2::stripDebug()
|
||||
coff_hdr.f_symptr = 0;
|
||||
coff_hdr.f_nsyms = 0;
|
||||
coff_hdr.f_flags = 0x10f; // 0x100: "32 bit machine: LSB first"
|
||||
memset(text->misc,0,12);
|
||||
memset(text->misc, 0, 12);
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +233,7 @@ bool PackDjgpp2::canPack()
|
||||
{
|
||||
if (!readFileHeader())
|
||||
return false;
|
||||
if (is_dlm(fi,coff_offset))
|
||||
if (is_dlm(fi, coff_offset))
|
||||
throwCantPack("can't handle DLM");
|
||||
|
||||
if (opt->force == 0)
|
||||
@@ -253,102 +270,73 @@ void PackDjgpp2::pack(OutputFile *fo)
|
||||
// read file
|
||||
const unsigned size = text->size + data->size;
|
||||
const unsigned tpos = text->scnptr;
|
||||
const unsigned usize = size + (tpos & 0x1ff);
|
||||
const unsigned hdrsize = 20 + 28 + (40 * coff_hdr.f_nscns);
|
||||
const unsigned hdrsize = 20 + 28 + sizeof(external_scnhdr_t) * coff_hdr.f_nscns;
|
||||
const unsigned usize = size + hdrsize;
|
||||
if (hdrsize < sizeof(coff_hdr) || hdrsize > tpos)
|
||||
throwCantPack("coff header error");
|
||||
|
||||
ibuf.alloc(usize);
|
||||
obuf.allocForCompression(usize);
|
||||
|
||||
fi->seek(coff_offset,SEEK_SET);
|
||||
fi->readx(ibuf,hdrsize); // orig. coff header
|
||||
memset(ibuf + hdrsize, 0, tpos - hdrsize);
|
||||
fi->seek(coff_offset+tpos,SEEK_SET);
|
||||
fi->readx(ibuf + (tpos & 0x1ff),size);
|
||||
|
||||
#if 0
|
||||
// filter
|
||||
Filter ft(opt->level);
|
||||
tryFilters(&ft, ibuf, usize - data->size, text->vaddr & ~0x1ff);
|
||||
|
||||
// compress
|
||||
ph.filter = ft.id;
|
||||
ph.filter_cto = ft.cto;
|
||||
ph.u_len = usize;
|
||||
if (!compress(ibuf,obuf))
|
||||
throwNotCompressible();
|
||||
|
||||
unsigned overlapoh = findOverlapOverhead(obuf,ibuf,512);
|
||||
overlapoh = (overlapoh + 0x3ff) & ~0x1ff;
|
||||
|
||||
// verify filter
|
||||
ft.verifyUnfilter();
|
||||
#else
|
||||
// new version using compressWithFilters()
|
||||
fi->seek(coff_offset, SEEK_SET);
|
||||
fi->readx(ibuf, hdrsize); // orig. coff header
|
||||
fi->seek(coff_offset + tpos, SEEK_SET);
|
||||
fi->readx(ibuf + hdrsize, size);
|
||||
|
||||
// prepare packheader
|
||||
ph.u_len = usize;
|
||||
ph.filter = 0;
|
||||
// prepare filter
|
||||
Filter ft(opt->level);
|
||||
Filter ft(ph.level);
|
||||
ft.buf_len = usize - data->size;
|
||||
ft.addvalue = text->vaddr & ~0x1ff;
|
||||
// prepare other settings
|
||||
const unsigned overlap_range = 512;
|
||||
unsigned overlapoh;
|
||||
|
||||
int strategy = -1; // try the first working filter
|
||||
if (opt->filter >= 0 && isValidFilter(opt->filter))
|
||||
// try opt->filter or 0 if that fails
|
||||
strategy = -2;
|
||||
else if (opt->all_filters)
|
||||
// choose best from all available filters
|
||||
strategy = 0;
|
||||
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
|
||||
overlapoh = (overlapoh + 0x3ff) & ~0x1ff;
|
||||
#endif
|
||||
ft.addvalue = text->vaddr - hdrsize;
|
||||
// compress
|
||||
compressWithFilters(&ft, 512);
|
||||
|
||||
// patch coff header #2
|
||||
const unsigned lsize = getLoaderSize();
|
||||
text->size = lsize; // new size of .text
|
||||
data->size = ph.c_len; // new size of .data
|
||||
|
||||
if (bss->size < overlapoh) // give it a .bss
|
||||
bss->size = overlapoh;
|
||||
if (bss->size < ph.overlap_overhead) // give it a .bss
|
||||
bss->size = ph.overlap_overhead;
|
||||
|
||||
text->scnptr = sizeof(coff_hdr);
|
||||
data->scnptr = text->scnptr + text->size;
|
||||
data->vaddr = bss->vaddr + ((data->scnptr + data->size) & 0x1ff) - data->size + overlapoh - 0x200;
|
||||
data->vaddr = bss->vaddr + ((data->scnptr + data->size) & 0x1ff) - data->size + ph.overlap_overhead - 0x200;
|
||||
coff_hdr.f_nscns = 3;
|
||||
|
||||
// prepare loader
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader,getLoader(),lsize);
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
|
||||
// patch loader
|
||||
patchPackHeader(loader,lsize);
|
||||
patch_le32(loader,lsize,"ENTR",coff_hdr.a_entry);
|
||||
patchPackHeader(loader, lsize);
|
||||
patch_le32(loader, lsize, "ENTR", coff_hdr.a_entry);
|
||||
patchFilter32(loader, lsize, &ft);
|
||||
patch_le32(loader,lsize,"BSSL",overlapoh/4);
|
||||
patch_le32(loader, lsize, "BSSL", ph.overlap_overhead / 4);
|
||||
assert(bss->vaddr == ((size + 0x1ff) &~ 0x1ff) + (text->vaddr &~ 0x1ff));
|
||||
patch_le32(loader,lsize,"OUTP",text->vaddr &~ 0x1ff);
|
||||
patch_le32(loader,lsize,"INPP",data->vaddr);
|
||||
patch_le32(loader, lsize, "OUTP", text->vaddr - hdrsize);
|
||||
patch_le32(loader, lsize, "INPP", data->vaddr);
|
||||
|
||||
// we should not overwrite our decompressor during unpacking
|
||||
// the original coff header (which is put just before the
|
||||
// beginning of the original .text section)
|
||||
assert(text->vaddr > hdrsize + lsize + sizeof(coff_hdr));
|
||||
|
||||
// patch coff header #3
|
||||
text->vaddr = sizeof(coff_hdr);
|
||||
coff_hdr.a_entry = sizeof(coff_hdr) + getLoaderSection("DJ2MAIN1");
|
||||
bss->vaddr += overlapoh;
|
||||
bss->size -= overlapoh;
|
||||
bss->vaddr += ph.overlap_overhead;
|
||||
bss->size -= ph.overlap_overhead;
|
||||
|
||||
// because of a feature (bug?) in stub.asm we need some padding
|
||||
memcpy(obuf+data->size,"UPX",3);
|
||||
data->size = ALIGN_UP(data->size,4);
|
||||
memcpy(obuf+data->size, "UPX", 3);
|
||||
data->size = ALIGN_UP(data->size, 4);
|
||||
|
||||
// write coff header, loader and compressed file
|
||||
fo->write(&coff_hdr,sizeof(coff_hdr));
|
||||
fo->write(loader,lsize);
|
||||
fo->write(obuf,data->size);
|
||||
fo->write(&coff_hdr, sizeof(coff_hdr));
|
||||
fo->write(loader, lsize);
|
||||
fo->write(obuf, data->size);
|
||||
#if 0
|
||||
printf("%-13s: coff hdr : %8ld bytes\n", getName(), (long) sizeof(coff_hdr));
|
||||
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
|
||||
@@ -356,11 +344,11 @@ void PackDjgpp2::pack(OutputFile *fo)
|
||||
#endif
|
||||
|
||||
// verify
|
||||
verifyOverlappingDecompression(&obuf, overlapoh);
|
||||
verifyOverlappingDecompression();
|
||||
|
||||
// handle overlay
|
||||
// FIXME: only Allegro pakfiles are supported
|
||||
handle_allegropak(fi,fo);
|
||||
handle_allegropak(fi, fo);
|
||||
|
||||
// finally check the compression ratio
|
||||
if (!checkFinalCompressionRatio(fo))
|
||||
@@ -376,7 +364,7 @@ int PackDjgpp2::canUnpack()
|
||||
{
|
||||
if (!readFileHeader())
|
||||
return false;
|
||||
if (is_dlm(fi,coff_offset))
|
||||
if (is_dlm(fi, coff_offset))
|
||||
throwCantUnpack("can't handle DLM");
|
||||
fi->seek(coff_offset, SEEK_SET);
|
||||
return readPackHeader(1024) ? 1 : -1;
|
||||
@@ -394,19 +382,30 @@ void PackDjgpp2::unpack(OutputFile *fo)
|
||||
ibuf.alloc(ph.c_len);
|
||||
obuf.allocForUncompression(ph.u_len);
|
||||
|
||||
fi->seek(coff_offset + ph.buf_offset + ph.getPackHeaderSize(),SEEK_SET);
|
||||
fi->readx(ibuf,ph.c_len);
|
||||
fi->seek(coff_offset + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
|
||||
fi->readx(ibuf, ph.c_len);
|
||||
|
||||
// decompress
|
||||
decompress(ibuf,obuf);
|
||||
decompress(ibuf, obuf);
|
||||
|
||||
coff_header_t *chdr = (coff_header_t*) obuf.getVoidPtr();
|
||||
text = chdr->sh;
|
||||
data = text + 1;
|
||||
|
||||
const unsigned hdrsize = 20 + 28
|
||||
+ sizeof(external_scnhdr_t) * chdr->f_nscns;
|
||||
|
||||
unsigned addvalue;
|
||||
if (ph.version >= 14)
|
||||
addvalue = text->vaddr - hdrsize;
|
||||
else
|
||||
addvalue = text->vaddr &~ 0x1ff; // for old versions
|
||||
|
||||
// unfilter
|
||||
if (ph.filter)
|
||||
{
|
||||
memcpy(&coff_hdr,obuf,sizeof(coff_hdr));
|
||||
|
||||
Filter ft(ph.level);
|
||||
ft.init(ph.filter, text->vaddr &~ 0x1ff);
|
||||
ft.init(ph.filter, addvalue);
|
||||
ft.cto = (unsigned char) ph.filter_cto;
|
||||
if (ph.version < 11)
|
||||
{
|
||||
@@ -417,18 +416,34 @@ void PackDjgpp2::unpack(OutputFile *fo)
|
||||
ft.unfilter(obuf, ph.u_len - data->size);
|
||||
}
|
||||
|
||||
// fixup for the aligning bug in strip 2.8+
|
||||
text = ((coff_header_t*) (unsigned char *) obuf)->sh;
|
||||
data = text + 1;
|
||||
text->scnptr &= 0x1ff;
|
||||
data->scnptr = text->scnptr + text->size;
|
||||
|
||||
// write decompressed file
|
||||
if (fo)
|
||||
if (ph.version < 14)
|
||||
{
|
||||
fo->write(obuf,ph.u_len);
|
||||
handle_allegropak(fi,fo);
|
||||
// fixup for the aligning bug in strip 2.8+
|
||||
text->scnptr &= 0x1ff;
|
||||
data->scnptr = text->scnptr + text->size;
|
||||
// write decompressed file
|
||||
if (fo)
|
||||
fo->write(obuf, ph.u_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
// write the header
|
||||
// some padding might be required between the end
|
||||
// of the header and the start of the .text section
|
||||
|
||||
const unsigned padding = text->scnptr - hdrsize;
|
||||
ibuf.clear(0, padding);
|
||||
|
||||
if (fo)
|
||||
{
|
||||
fo->write(obuf, hdrsize);
|
||||
fo->write(ibuf, padding);
|
||||
fo->write(obuf + hdrsize, ph.u_len - hdrsize);
|
||||
}
|
||||
}
|
||||
|
||||
if (fo)
|
||||
handle_allegropak(fi, fo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user