Compare commits
498 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b4c11954d | |||
| a1b724f30a | |||
| 7c3b2fb9cc | |||
| acef68d67e | |||
| 7e393d5f1e | |||
| 955c31b165 | |||
| e307cd48ad | |||
| 25f8b9e451 | |||
| e8ba14a2c1 | |||
| 9670d3341c | |||
| cec9778fd5 | |||
| 7451db4a68 | |||
| e31777ec53 | |||
| 7aa0b3dc7a | |||
| e7b2d5dc01 | |||
| 47d728667d | |||
| e1f8989d54 | |||
| 1d8cb47830 | |||
| faaa7c37a9 | |||
| 0aff9d8df4 | |||
| 30c3f8c1ac | |||
| bcd2469e01 | |||
| 983c6ae73d | |||
| 6d8e1fe776 | |||
| 99b4921309 | |||
| 3c231c3c9e | |||
| 175c0a6236 | |||
| 0031ceb06c | |||
| e3cc5a63df | |||
| 3cb61402c2 | |||
| 5336c51199 | |||
| 52aa658aaa | |||
| d08a51d7e4 | |||
| d97a557ac3 | |||
| 8a68d9cded | |||
| b031f7e902 | |||
| 963ffecb96 | |||
| 8f8aaca818 | |||
| 801f92b7e7 | |||
| 44db45700e | |||
| 25902005f6 | |||
| ffec71e0d8 | |||
| 99a208110b | |||
| e56799c993 | |||
| 957eb300f8 | |||
| 626025d539 | |||
| 9e8a0a020f | |||
| 40f592eade | |||
| 5e899f0be4 | |||
| f2748284b1 | |||
| a15ce00934 | |||
| 9e3e80261b | |||
| c72c685434 | |||
| 0177a8d277 | |||
| b6a9b0a4c9 | |||
| f4f8bd8d42 | |||
| 6e4aeffc0c | |||
| dba256d384 | |||
| 910008e9e7 | |||
| 8cb9545c41 | |||
| 59c16da6fb | |||
| 630df5bbd2 | |||
| f550111400 | |||
| 77377195aa | |||
| 7e2e72bd40 | |||
| aa7a13bd02 | |||
| 5895058a17 | |||
| ffb60d5149 | |||
| 1e2cb279b0 | |||
| e7f766f5ba | |||
| 8de5aa9409 | |||
| bf28a4df49 | |||
| fe1a0ab371 | |||
| 01daccfaf7 | |||
| 94e861e298 | |||
| d36af2ed5c | |||
| 7104b33214 | |||
| 32998e5377 | |||
| af0c9ef092 | |||
| 3bc3b3d10e | |||
| f03f42ca4d | |||
| 79783abeb1 | |||
| 895b0bd602 | |||
| 2ee5ee92f8 | |||
| 3e619423b1 | |||
| b524e18bdf | |||
| 6aa4579db8 | |||
| 17fb86c0f1 | |||
| 62ecfe4873 | |||
| 04e55e6b9a | |||
| f432aa1090 | |||
| 7add104313 | |||
| 36de249066 | |||
| b7a54dcffd | |||
| 6bb28deab2 | |||
| 7f88d15c86 | |||
| 94c5014e23 | |||
| c5a8256500 | |||
| 5f39884bf7 | |||
| d96825a242 | |||
| 443a938091 | |||
| 6bc3197721 | |||
| 269cc91fd5 | |||
| c1ddea479d | |||
| 5f3a95962c | |||
| ee1a8e6a32 | |||
| eeae73296e | |||
| 4ca8357af4 | |||
| 8a5b8c87fb | |||
| 6ab04d7bbc | |||
| a5a1380636 | |||
| eeab1aef64 | |||
| 4e1c342e55 | |||
| d8ed259bce | |||
| 9f6cb5de4c | |||
| ba634118d7 | |||
| 63da091d36 | |||
| ad0dc88a33 | |||
| 147acf4b57 | |||
| 5085f3a15e | |||
| 22a95ad8ea | |||
| df4bd6a60c | |||
| 813e7b05e4 | |||
| ab8b486b4a | |||
| 590f666ec9 | |||
| 9adaee915b | |||
| bce0f06fe9 | |||
| 856ecb84a0 | |||
| 90ddc06c98 | |||
| 405abc4e95 | |||
| 549c59ecf5 | |||
| 0a485eafcb | |||
| e0c11956a6 | |||
| da6a9bf3eb | |||
| dacd11e1cc | |||
| fc854b4c77 | |||
| 4dcc1f0374 | |||
| fc57390242 | |||
| bd15ef0a0c | |||
| 967ecafc33 | |||
| 29576da985 | |||
| 200a2556ef | |||
| ae0ab5025e | |||
| aa74276b25 | |||
| b03112a5dd | |||
| a3f49df62d | |||
| aa2af3f6dd | |||
| 20dcbc593c | |||
| 472ba8c1fd | |||
| d8345a44a4 | |||
| a187cb6c9c | |||
| b89c0b35d1 | |||
| 7ffcc0a5e7 | |||
| bde43fbdfb | |||
| 3728b2208f | |||
| dc52a756ee | |||
| 98dc886841 | |||
| d0cf104e43 | |||
| d7ed2412f6 | |||
| 7d38f0e234 | |||
| 3e8d072d24 | |||
| 84ac771893 | |||
| 3a9e0b5be6 | |||
| 9694ff433f | |||
| 2e82e78b98 | |||
| aaef4bee27 | |||
| 4ca8569488 | |||
| 8377ada3e0 | |||
| 8a034d59ed | |||
| 8e492d8798 | |||
| 7974ef80d7 | |||
| 3664d86430 | |||
| 9adef80d6b | |||
| be57adaee7 | |||
| d117e442a4 | |||
| 8820bc0796 | |||
| 57a64de023 | |||
| 5ed689ceb0 | |||
| 25f1765f36 | |||
| 063bd58802 | |||
| 901c6b34fa | |||
| 5b2d6488a2 | |||
| f6f35415d1 | |||
| 6c6069e963 | |||
| 6219d82560 | |||
| 1dcd7a16ab | |||
| b60caeb9dd | |||
| 4c4768aaf3 | |||
| 2f4ac0a663 | |||
| 23a446f852 | |||
| ec48334a1a | |||
| f4c061d412 | |||
| 31a076d7b3 | |||
| 6bd43d986c | |||
| dd32a2f15a | |||
| c88c20820f | |||
| 86de510731 | |||
| 0b31fbf827 | |||
| 34ad1450eb | |||
| e6ba71390d | |||
| f0c8dbe0ec | |||
| bf046a8ccb | |||
| b05ba7683e | |||
| aedf8dad15 | |||
| 74ebb7c722 | |||
| 1307f66494 | |||
| 448a24cb36 | |||
| 7266f23450 | |||
| c0ad31acfc | |||
| 25d3a0de27 | |||
| 1e38bbfbc1 | |||
| 1c62e95812 | |||
| d453cc27a3 | |||
| 2c3e841d8a | |||
| 50668c462f | |||
| 8d1192e832 | |||
| 4a8e2e9ed4 | |||
| 12fc45220a | |||
| 6bce68fbe7 | |||
| d54f947c98 | |||
| 6c8bb3a22e | |||
| ed29ce5183 | |||
| a51d269b7c | |||
| 8283e4e6d6 | |||
| 23ce91eb55 | |||
| 545ac7fcfa | |||
| 3926ccccad | |||
| f431307ef2 | |||
| ca368e0f9b | |||
| 8afeb56c11 | |||
| 2a6f90c5f3 | |||
| 271031128e | |||
| b991f954d0 | |||
| f12bb3f80d | |||
| 6dc978e8d8 | |||
| 9f05a873bc | |||
| 703d498772 | |||
| ed3b9543bb | |||
| fc7efba7d8 | |||
| b3178fe8f4 | |||
| e36798a993 | |||
| a143605465 | |||
| d3ad35b21e | |||
| 68134941bf | |||
| 54d0fef559 | |||
| 7f9c47176a | |||
| 9060ac7897 | |||
| d9073e4a17 | |||
| de1c1d7cc2 | |||
| 6ff1bd5917 | |||
| a6b04f426e | |||
| fa49dbe2cb | |||
| 682eb04a52 | |||
| 77064fb09e | |||
| be8d93563a | |||
| d4a6a5216d | |||
| 1cb1427050 | |||
| e4f4eace1c | |||
| 30a98b7e8c | |||
| d36c8d95ad | |||
| 506bd0abcf | |||
| 8dd810c41d | |||
| d9d0dc5201 | |||
| 72880d9e03 | |||
| 6c7ec6eb1b | |||
| 705fc5d116 | |||
| d20b575b9b | |||
| c949beab9c | |||
| 3fb857c435 | |||
| 0a4f999ade | |||
| f0b7147881 | |||
| b36a42cd0a | |||
| 000309b47f | |||
| 5cb12988f0 | |||
| 50c4b749ec | |||
| 5db2734e6f | |||
| e9e5507483 | |||
| d63dc7adfb | |||
| 27db44a8db | |||
| 1a035e2866 | |||
| 887aa20116 | |||
| 5e03d86695 | |||
| 95075aa28e | |||
| 0260f0790a | |||
| 34d65ba292 | |||
| 27a77a15ed | |||
| 76025bfae1 | |||
| 4957faf482 | |||
| 0d8e16d5c8 | |||
| 07baed1581 | |||
| eab5da075a | |||
| 0d1bbb19ce | |||
| 58d6cbc6ac | |||
| 4d3b627839 | |||
| 49455c99ad | |||
| 31bb6bedbd | |||
| 8d54678ea1 | |||
| 590767c299 | |||
| ec1bd342b8 | |||
| b031c9e7f6 | |||
| ea0dfe83b7 | |||
| bdd90f2c57 | |||
| 288dac5d70 | |||
| 9d22e1c35e | |||
| ace2359e7b | |||
| 617e6510a5 | |||
| 26024770b8 | |||
| d556f58e34 | |||
| b6f302dfc0 | |||
| 8e9b5f14af | |||
| 3635c00143 | |||
| abc71baaa6 | |||
| 959aaebede | |||
| d17f8c5049 | |||
| 42a7201a70 | |||
| 1f1744a49a | |||
| fd7dbe5bd9 | |||
| 984549400d | |||
| cf0c49277e | |||
| 16c3f9fa9c | |||
| 2f2539cf34 | |||
| e66823d017 | |||
| 881c32a3df | |||
| ea0a361c35 | |||
| dc60f8bb7b | |||
| 9e92c9ea12 | |||
| a503a54240 | |||
| 265957712a | |||
| c26962bb71 | |||
| a428eddf93 | |||
| dc4f7eb2f9 | |||
| d54ac1ba91 | |||
| a3d46b18ac | |||
| e81dd05666 | |||
| 29394935e3 | |||
| df8acc4ed7 | |||
| 81928d4ab1 | |||
| 3ebf93e03d | |||
| 59e4032f1f | |||
| 8f15777427 | |||
| 748c4bf780 | |||
| befcf6d2b3 | |||
| 48236ecd3c | |||
| f340f84de7 | |||
| 40e19293f9 | |||
| f252f824a4 | |||
| 1d7e5a8130 | |||
| cb2ff92c2f | |||
| ef373ab54f | |||
| 9141a78c29 | |||
| 10a6370738 | |||
| 573009eeb6 | |||
| c3363712d9 | |||
| faa33d89a2 | |||
| f347458c53 | |||
| 530e6d9196 | |||
| b398e18e12 | |||
| 747e8370e0 | |||
| 2c67875781 | |||
| c96e8a8c19 | |||
| 5f203fc082 | |||
| b943c9b471 | |||
| 1a90a1daa8 | |||
| 72dfc743fd | |||
| 465307655b | |||
| 6ce71e6694 | |||
| 7f01b3b92a | |||
| 76950d56b9 | |||
| c11e0d02b3 | |||
| 4c798c1718 | |||
| 450d7e9ad4 | |||
| b8ab79c83e | |||
| 6934bdd533 | |||
| 84dedb73a5 | |||
| 8964aa5221 | |||
| 3481ae236c | |||
| 46adc5f8a4 | |||
| 5296df5899 | |||
| 13dad4be16 | |||
| b5d0c343b4 | |||
| b00b945264 | |||
| 3bda09e105 | |||
| 32d32c4e4a | |||
| 497441b54e | |||
| 9c564fd4c7 | |||
| 0c2263d0e9 | |||
| 3d4d30766d | |||
| 99d84d44fc | |||
| 41ba7077ad | |||
| 8a929a91c3 | |||
| 0604f06841 | |||
| 229924adf9 | |||
| df988b7c69 | |||
| e8106e2e34 | |||
| c21d3e24f8 | |||
| 2d87aa0753 | |||
| b2ad4dc9a0 | |||
| 370f2ea98f | |||
| a05ca565ff | |||
| 52255637f2 | |||
| 0fcaa3a2f5 | |||
| 0e2fa6eb9d | |||
| 1aac462c83 | |||
| 2a0edfd8f7 | |||
| 1f59a9f846 | |||
| 80c20a90ea | |||
| 56a35649fe | |||
| f07cea0b79 | |||
| 4c1b08a281 | |||
| 117f9eddcd | |||
| 7bbbfce482 | |||
| f37a7811f9 | |||
| 9173c10239 | |||
| 318b31550d | |||
| c18ebc63a6 | |||
| d704694272 | |||
| 1cfec3bdf7 | |||
| fe6ea6bc10 | |||
| d29c8df45e | |||
| 71f996af95 | |||
| d9722ad6b3 | |||
| 398fd8028c | |||
| 1345a3cfd3 | |||
| 7eb0b195b8 | |||
| 009caee82d | |||
| 3bdc805a22 | |||
| ac457792b4 | |||
| 1377b54b9e | |||
| 66418ffc8c | |||
| b4c4b1fb70 | |||
| ffe4a4b047 | |||
| 753ce45310 | |||
| fece0d73e7 | |||
| edce076e68 | |||
| 675d0a009a | |||
| 5d41b5a4db | |||
| fe53b135eb | |||
| 5b1c154ee2 | |||
| 816d882611 | |||
| 12bcb09051 | |||
| c59c69a85f | |||
| bdd0daaf6f | |||
| cfad7c8356 | |||
| b2b8a128d0 | |||
| 1cfad80ca2 | |||
| a5a80e41b8 | |||
| 152f8e92bf | |||
| 0323560b49 | |||
| d3bc84a2f7 | |||
| 8a82c259bd | |||
| 46009c7658 | |||
| 6f760308bd | |||
| c346f8f17d | |||
| af1d059fff | |||
| 5562b21a20 | |||
| 8f68f31877 | |||
| ce7e94030c | |||
| ccf5a1b972 | |||
| 0d5ae77efc | |||
| 1695096d18 | |||
| 6db0b7cf18 | |||
| 575b43b0d4 | |||
| 7b39b05894 | |||
| 8bea9e0a5e | |||
| 2255b32e45 | |||
| b62573ae8f | |||
| 44ed84f5cf | |||
| d008c834be | |||
| 2d3a914aee | |||
| 7324f4c3d1 | |||
| 50c8860a50 | |||
| 6456de7188 | |||
| 23c629f2aa | |||
| 2bf154f74f | |||
| b598ad1bc0 | |||
| ace24ad68e | |||
| 750c1a0f27 | |||
| 52d89bd66b | |||
| 8cfb9d35e9 | |||
| 2f529158a0 | |||
| 6e68ab6d9e | |||
| 7a3c55af35 | |||
| fb39d6304a | |||
| 4cb57d9059 | |||
| 42d69bd0e5 | |||
| f27b399f81 | |||
| a545a3938f | |||
| d1e352c9ee | |||
| 99be1e798b | |||
| 2132a28a17 | |||
| 8b1cc28783 | |||
| 78364ac830 | |||
| 6e5f5732b5 | |||
| 87844254d1 | |||
| 08ef9f69fb | |||
| 5fbd1b78e7 | |||
| 39f5eb753f | |||
| f4cbe3f300 |
@@ -2,11 +2,15 @@ syntax: regexp
|
||||
|
||||
^\.bzr
|
||||
^ChangeLog
|
||||
^Makevars.global
|
||||
^build
|
||||
^maint
|
||||
|
||||
syntax: glob
|
||||
|
||||
.depend
|
||||
Makevars.local
|
||||
|
||||
*.a
|
||||
*.dll
|
||||
*.lib
|
||||
@@ -41,7 +45,7 @@ stub/**.*-stamp
|
||||
stub/tmp*/*
|
||||
stub/**/tmp*/*
|
||||
|
||||
stub/tools/armpe/armpe_tester
|
||||
stub/tools/armpe/armpe_tester{,.exe,.out}
|
||||
|
||||
stub/tools/sstrip/amd64-linux-sstrip
|
||||
stub/tools/sstrip/i386-linux-sstrip
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
|
||||
155618b5b7930f97bd84b82befa7a4fd6672efb3 RELEASE_304
|
||||
1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301
|
||||
223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190
|
||||
2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194
|
||||
2ee65b77f9117651e2e5517b2edede23698d73ca RELEASE_196
|
||||
396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291
|
||||
46f3a6cca02603000fadc16637b02e30caddd909 RELEASE_302
|
||||
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
|
||||
7c6747c82b167368344a238b1a3a87c2a4fa6a18 RELEASE_306
|
||||
95c558f81a0b8d5bb2bede4c8208bb84ae7d1e58 RELEASE_303
|
||||
a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292
|
||||
a916a2fe22de45167d25abcb40008315f415221c RELEASE_201
|
||||
a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
|
||||
b0353253b0b3d062eb5adb50d4b665a96620da45 RELEASE_195
|
||||
b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg
|
||||
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
|
||||
c9a983b7da9d4a2311f74366478348412cac2986 RELEASE_305
|
||||
d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290
|
||||
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
|
||||
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
|
||||
ef9c7f2c9658d73a9b5ab2ed291483d2bbcd8bc7 RELEASE_300
|
||||
efa52753e366300c0e0ebe20631adcb24ed3c15b RELEASE_293
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ dos/exe
|
||||
watcom/le
|
||||
---------
|
||||
* 16-bit selector alias fixups
|
||||
* 16-bit offset relocation for objects larger than 4 kB
|
||||
* 16-bit offset relocation for objects larger than 4 KiB
|
||||
* 16:16 fixups
|
||||
|
||||
If you need any of the above (they're very rare), send us an URL of a
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
#
|
||||
# UPX toplevel Makefile - needs GNU make 3.80 or better
|
||||
# UPX toplevel Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
export SHELL = /bin/sh
|
||||
|
||||
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),)
|
||||
$(error GNU make 3.81 or better is required)
|
||||
endif
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = .
|
||||
include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local)
|
||||
|
||||
|
||||
# info: src/stub needs GNU make 3.81 and special build tools
|
||||
# info: src/stub needs special build tools
|
||||
BUILD_STUB = 0
|
||||
ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
|
||||
BUILD_STUB = 1
|
||||
@@ -18,9 +25,6 @@ endif
|
||||
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
|
||||
BUILD_STUB = 1
|
||||
endif
|
||||
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.79 3.79.1 3.80),)
|
||||
BUILD_STUB = 0
|
||||
endif
|
||||
|
||||
|
||||
default:
|
||||
@@ -33,15 +37,6 @@ endif
|
||||
$(MAKE) -C src $@
|
||||
$(MAKE) -C doc $@
|
||||
|
||||
# automatically generate ChangeLog from Mercurial repo
|
||||
ChangeLog:
|
||||
ifneq ($(wildcard .hg/data/.),)
|
||||
hg log --style=changelog > $@
|
||||
else
|
||||
@echo "UPX info: no hg repo found"
|
||||
endif
|
||||
|
||||
|
||||
.PHONY: default all mostlyclean clean distclean maintainer-clean
|
||||
.PHONY: ChangeLog
|
||||
|
||||
|
||||
@@ -2,6 +2,66 @@
|
||||
User visible changes for UPX
|
||||
==================================================================
|
||||
|
||||
Changes in 3.07 (08 Sep 2010):
|
||||
* win32/pe: fixed relocation handling for files with *no* TLS callbacks
|
||||
[severe bug introduced in 3.06]
|
||||
|
||||
Changes in 3.06 (04 Sep 2010):
|
||||
* win32/pe: TLS callback support contributed by Stefan Widmann. Thanks!
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.05 (27 Apr 2010):
|
||||
* i386-linux and amd64-linux support shared libraries (DT_INIT must
|
||||
exist, all info needed by runtime loader must be first in .text, etc.)
|
||||
* Linux /proc/self/exe now is preserved by default, by leaving behind
|
||||
one page. New compress-time option --unmap-all-pages is available.
|
||||
* Withdraw support for shared libraries on Darwin (Apple Mac OS X)
|
||||
because upx does not understand enough about .dylib.
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.04 (27 Sep 2009):
|
||||
* new format Mach/AMD64 supports 64-bit programs on Apple Macintosh.
|
||||
* new formats Dylib/i386 and Dylib/ppc32 support shared libraries
|
||||
[such as browser plugins] on Darwin (Apple Macintosh). An existing
|
||||
-init function (LC_ROUTINES command) is required.
|
||||
* new format vmlinuz/armel for Debian NSLU2 (etc.) linux kernel
|
||||
* bvmlinuz boot protocol 2.08 for 386 Linux kernel
|
||||
* Extended ABI version 4 for armel-eabi ARM Linux ELF
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.03 (27 Apr 2008):
|
||||
* implement cache flushing for PowerPC (esp. model 440)
|
||||
* fix cache flushing on MIPS (>3 MiB compressed, or with holes)
|
||||
* fix MIPS big-endian
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.02 (16 Dec 2007):
|
||||
* fix unmapping on arm-linux.elf
|
||||
* fix error checking in mmap for i386-linux.elf [triggered by -fPIE]
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.01 (31 Jul 2007):
|
||||
* new options --no-mode, --no-owner and --no-time to disable preservation
|
||||
of mode (file permissions), file ownership and timestamps.
|
||||
* dos/exe: fixed an incorrect error message caused by a bug in
|
||||
relocation handling
|
||||
* new format linux/mipsel supports ELF on [32-bit] R3000
|
||||
* fix argv[0] on PowerPC with --lzma
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.00 (27 Apr 2007):
|
||||
* watcom/le & tmt/adam: fixed a problem when using certain filters
|
||||
|
||||
Changes in 2.93 beta (08 Mar 2007):
|
||||
* new formats Mach/i386 and Mach/fat support Mac OS X i686 and
|
||||
Universal binaries [i686 and PowerPC only]
|
||||
* dos/exe: LZMA is now also supported for 16-bit dos/exe. Please note that
|
||||
you have to explicitly use '--lzma' even for '--ultra-brute' here
|
||||
because runtime decompression is about 30 times slower than NRV -
|
||||
which is really noticeable on old machines.
|
||||
* dos/exe: fixed a rarely occuring bug in relocation handling
|
||||
* win32/pe & arm/pe: better icon compression handling
|
||||
|
||||
Changes in 2.92 beta (23 Jan 2007):
|
||||
* new option '--ultra-brute' which tries even more variants
|
||||
* slightly improved compression ratio for some files when
|
||||
@@ -302,8 +362,8 @@ Changes in 0.80 (03 Aug 1999)
|
||||
* win32/pe: even better TLS support
|
||||
* win32/pe: versioninfo works on NT
|
||||
* win32/pe: import by ordinal from kernel32.dll works
|
||||
* win32/pe: other import improvements: importing a nonexistant DLL
|
||||
results in a usual Windows message, importing a nonexistant function
|
||||
* win32/pe: other import improvements: importing a nonexistent DLL
|
||||
results in a usual Windows message, importing a nonexistent function
|
||||
results in program exit (instead of crash ;-)
|
||||
* win32/pe: new option: '--compress-resources=0'
|
||||
* win32/pe: reduced memory requirement during uncompression, some
|
||||
@@ -355,7 +415,7 @@ Changes in 0.60 (06 Mar 1999)
|
||||
* win32/pe: fixed file corruption when the size of the export data is invalid
|
||||
* win32/pe: fixed a problem with empty resource data
|
||||
* win32/pe: compressed file alignment set to minimum value
|
||||
* win32/pe: made all compressed sections writeable
|
||||
* win32/pe: made all compressed sections writable
|
||||
* fixed some other win32/pe bugs
|
||||
* fixed an address optimization problem for some not Watcom LE files
|
||||
* fixed a bug which could make UPX hang when an exe header contained
|
||||
@@ -396,3 +456,5 @@ Changes in 0.20 (05 Jul 1998)
|
||||
Changes in 0.05 (26 May 1998)
|
||||
* first public beta release
|
||||
|
||||
|
||||
# vim:set syntax=off tw=0 ts=4 sw=4 et: -*- coding: utf-8 -*-
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ THE FUTURE
|
||||
- We will *NOT* add any sort of protection and/or encryption.
|
||||
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
|
||||
And don't trust any advertisement of authors of other executable
|
||||
compressors about this topic - just do a websearch on "unpackers"...
|
||||
|
||||
- Fix all remaining bugs - keep your reports coming ;-)
|
||||
@@ -108,9 +108,9 @@ THE FUTURE
|
||||
COPYRIGHT
|
||||
=========
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
@@ -128,8 +128,8 @@ Share and enjoy,
|
||||
Markus & Laszlo
|
||||
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-9
@@ -8,18 +8,10 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
WARNING - UNSTABLE BETA VERSION
|
||||
===============================
|
||||
|
||||
The current stable release is 2.02, and the next stable release
|
||||
will be called version 3.00.
|
||||
|
||||
|
||||
MAJOR NEWS IN UPX 3
|
||||
===================
|
||||
|
||||
|
||||
+2
-5
@@ -69,7 +69,7 @@ Tools needed to build/modify the UPX sources
|
||||
- A C++ compiler supporting inner classes, templates, exceptions
|
||||
and RTTI.
|
||||
|
||||
- GNU make 3.80 or better (GNU make 3.81 recommened).
|
||||
- GNU make 3.81 or better
|
||||
|
||||
|
||||
To compile the packer sources
|
||||
@@ -94,14 +94,11 @@ To compile the packer sources
|
||||
If you want to modify the stub sources you'll also need
|
||||
-------------------------------------------------------
|
||||
|
||||
- GNU make 3.81 or better
|
||||
http://savannah.gnu.org/projects/make/
|
||||
|
||||
- Perl & Python
|
||||
|
||||
- A number of cross-assemblers and cross-compilers - precompiled
|
||||
binaries for i386-linux hosts are available from
|
||||
http://sourceforge.net/project/showfiles.php?group_id=2331
|
||||
http://sourceforge.net/projects/upx/files/upx-tools/20060823/
|
||||
|
||||
|
||||
Misc. notes
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ Ralph Roth <RalphRoth@gmx.net>
|
||||
for reporting several bugs
|
||||
Salvador Eduardo Tropea
|
||||
for beta testing
|
||||
Stefan Widmann
|
||||
for the win32/pe TLS callback support
|
||||
The WINE project (http://www.winehq.com/)
|
||||
for lots of useful information found in their PE loader sources
|
||||
Natascha
|
||||
|
||||
+25
-14
@@ -1,5 +1,5 @@
|
||||
Decompressing ELF Directly to Memory on Linux/x86
|
||||
Copyright (C) 2000-2007 John F. Reiser jreiser@BitWagon.com
|
||||
Copyright (C) 2000-2010 John F. Reiser jreiser@BitWagon.com
|
||||
|
||||
References:
|
||||
<elf.h> definitions for the ELF file format
|
||||
@@ -46,8 +46,8 @@ may not be used to take the address of a function.
|
||||
|
||||
The address 0x00400000 was chosen to be out of the way of the usual
|
||||
load address 0x08048000, and to minimize fragmentation in kernel
|
||||
page tables; one page of page tables covers 4MB. The address
|
||||
0x00401000 was chosen as 1 page up from a 64KB boundary, to
|
||||
page tables; one page of page tables covers 4 MiB. The address
|
||||
0x00401000 was chosen as 1 page up from a 64 KiB boundary, to
|
||||
make the startup code and its constants smaller.
|
||||
|
||||
Decompression of the executable begins by decompressing the Elf32_Ehdr
|
||||
@@ -57,23 +57,34 @@ Subroutine do_xmap() of src/stub/l_lx_elf.c performs the
|
||||
"virtual execve()" using the compressed data as source, and stores
|
||||
the decompressed bytes directly into the appropriate virtual addresses.
|
||||
|
||||
Before transfering control to the PT_INTERP "program interpreter",
|
||||
Before transferring control to the PT_INTERP "program interpreter",
|
||||
minor tricks are required to setup the Elf32_auxv_t entries,
|
||||
clear the free portion of the stack (to compensate for ld-linux.so.2
|
||||
assuming that its automatic stack variables are initialized to zero),
|
||||
and remove (all but 4 bytes of) the decompression program (and
|
||||
compressed executable) from the address space.
|
||||
|
||||
Because the UPX runtime stub removes all traces of the compressed file
|
||||
from the address space, then the Linux kernel erases the symlink
|
||||
/proc/self/exe. Linux stores the pathname argument that was specified
|
||||
to execve() immediately after the '\0' which terminates the character
|
||||
string of the last environment variable [as of execve()]. This is true
|
||||
for at least all Linux 2.6, 2.4, and 2.2 kernels. The pathname is not
|
||||
"bound" to the file as strongly as /proc/self/exe (the file may be changed
|
||||
without affecting the pathname), but the pathname does provide some
|
||||
information. The pathname may be relative to the working directory,
|
||||
so look before any chdir().
|
||||
As of upx-3.05, by default on Linux, upon decompression then one page
|
||||
of the compressed executable remains mapped into the address space
|
||||
of the process. If all of the pages of the compressed executable are
|
||||
unmapped, then the Linux kernel erases the symlink /proc/self/exe,
|
||||
and this can cause trouble for the runtime shared library loader
|
||||
expanding $ORIGIN in -rpath, or for application code that relies on
|
||||
/proc/self/exe. Use the compress-time command-line option
|
||||
--unmap-all-pages to achieve that effect at run time. Upx-3.04
|
||||
and previous versions did this by default with no option. However,
|
||||
too much other software erroneously assumes that /proc/self/exe
|
||||
always exists.
|
||||
|
||||
Linux stores the pathname argument that was specified to execve()
|
||||
immediately after the '\0' which terminates the character string of the
|
||||
last environment variable [as of execve()]. This is true for at least
|
||||
all Linux 2.6, 2.4, and 2.2 kernels. Linux kernel 2.6.29 and later
|
||||
records a pointer to that character string in Elf32_auxv[AT_EXECFN].
|
||||
The pathname is not "bound" to the file as strongly as /proc/self/exe
|
||||
(the file may be changed without affecting the pathname), but the
|
||||
pathname does provide some information. The pathname may be relative
|
||||
to the working directory, so look before any chdir().
|
||||
|
||||
The Elf formats for Linux add an environment variable named " " [three
|
||||
spaces] which saves the results of readlink("/proc/self/exe",,) before
|
||||
|
||||
+2
-2
@@ -108,14 +108,14 @@ then skip another one - the unfiltering process needs some information
|
||||
to be able to reverse the filtering.
|
||||
|
||||
UPX uses the following idea, which works nicely. First we assume that
|
||||
the size of the area that should be filtered is less than 16MB. Then
|
||||
the size of the area that should be filtered is less than 16 MiB. Then
|
||||
UPX scans over this area and keeps a record of the bytes that are
|
||||
following the 0xE8 bytes. If we are lucky, there will be bytes that
|
||||
were not found following 0xE8. These bytes are our candidates to be
|
||||
used as markers.
|
||||
|
||||
Do you still remember that we assumed that the size of scanned area is
|
||||
less than 16MB? Well, this means that when we process a real call, the
|
||||
less than 16 MiB? Well, this means that when we process a real call, the
|
||||
resulting offset will be less than 0x00FFFFFF too. So the MSB is always
|
||||
0x00. Which is a nice place to store our marker. Of course we should
|
||||
reverse the byte order in the resulting offset - so this marker will
|
||||
|
||||
+1
-1
@@ -45,6 +45,6 @@ These symbols can be defined later in C++ using
|
||||
|
||||
linker->defineSymbol("xx", yy)
|
||||
|
||||
This functionality (we could say it's a simple linker) is achived by
|
||||
This functionality (we could say it's a simple linker) is achieved by
|
||||
compiling the assembly into an ELF object file which a little C++
|
||||
module (src/linker.cpp) can interpret and work with.
|
||||
|
||||
+39
-32
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
||||
=head1 ABSTRACT
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -51,8 +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 on an ancient Pentium 133,
|
||||
about 200 MB/sec on an Athlon XP 2000+.
|
||||
- very fast decompression: about 10 MiB/sec on an ancient Pentium 133,
|
||||
about 200 MiB/sec on an Athlon XP 2000+.
|
||||
|
||||
- no memory overhead for your compressed executables for most of the
|
||||
supported formats
|
||||
@@ -139,7 +139,11 @@ B<--help>: prints the help
|
||||
B<--version>: print the version of B<UPX>
|
||||
|
||||
B<--exact>: when compressing, require to be able to get a byte-identical file
|
||||
after decompression with option B<-d>
|
||||
after decompression with option B<-d>. [NOTE: this is work in progress and is
|
||||
not supported for all formats yet. If you do care, as a workaround you can
|
||||
compress and then decompress your program a first time - any further
|
||||
compress-decompress steps should then yield byte-identical results
|
||||
as compared to the first decompressed version.]
|
||||
|
||||
[ ...to be written... - type `B<upx --help>' for now ]
|
||||
|
||||
@@ -149,7 +153,7 @@ after decompression with option B<-d>
|
||||
|
||||
B<UPX> offers ten different compression levels from B<-1> to B<-9>,
|
||||
and B<--best>. The default compression level is B<-8> for files
|
||||
smaller than 512 kB, and B<-7> otherwise.
|
||||
smaller than 512 KiB, and B<-7> otherwise.
|
||||
|
||||
=over 4
|
||||
|
||||
@@ -197,7 +201,7 @@ 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
|
||||
Info: An "overlay" means auxiliary data attached 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).
|
||||
@@ -345,7 +349,7 @@ Extra options available for this executable format:
|
||||
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 B<UPX> corrects a bug/feature in strip v2.8.x: it
|
||||
will fix the 4 KByte aligment of the stub.
|
||||
will fix the 4 KiB alignment of the stub.
|
||||
|
||||
B<UPX> includes the full functionality of stubify. This means it will
|
||||
automatically stubify your COFF files. Use the option B<--coff> to
|
||||
@@ -380,7 +384,7 @@ Extra options available for this executable format:
|
||||
Introduction
|
||||
|
||||
Linux/386 support in UPX consists of 3 different executable formats,
|
||||
one optimized for ELF excutables ("linux/elf386"), one optimized
|
||||
one optimized for ELF executables ("linux/elf386"), one optimized
|
||||
for shell scripts ("linux/sh386"), and one generic format
|
||||
("linux/386").
|
||||
|
||||
@@ -408,14 +412,14 @@ General user's overview
|
||||
or network I/O.
|
||||
|
||||
Depending on the statistics of usage and access, and the relative
|
||||
speeds of CPU, RAM, swap space, /tmp, and filesystem storage, then
|
||||
speeds of CPU, RAM, swap space, /tmp, and file system storage, then
|
||||
invoking and running a compressed executable can be faster than
|
||||
directly running the corresponding uncompressed program.
|
||||
The operating system might perfrom fewer expensive I/O operations
|
||||
The operating system might perform fewer expensive I/O operations
|
||||
to invoke the compressed program. Paging to or from swap space
|
||||
or /tmp might be faster than paging from the general filesystem.
|
||||
or /tmp might be faster than paging from the general file system.
|
||||
``Medium-sized'' programs which access about 1/3 to 1/2 of their
|
||||
stored program bytes can do particulary well with compression.
|
||||
stored program bytes can do particularly well with compression.
|
||||
Small programs tend not to benefit as much because the absolute
|
||||
savings is less. Big programs tend not to benefit proportionally
|
||||
because each invocation may use only a small fraction of the program,
|
||||
@@ -424,7 +428,7 @@ General user's overview
|
||||
then compression may win anyway.
|
||||
|
||||
Currently, executables compressed by UPX do not share RAM at runtime
|
||||
in the way that executables mapped from a filesystem do. As a
|
||||
in the way that executables mapped from a file system do. As a
|
||||
result, if the same program is run simultaneously by more than one
|
||||
process, then using the compressed version will require more RAM and/or
|
||||
swap space. So, shell programs (bash, csh, etc.) and ``make''
|
||||
@@ -513,7 +517,7 @@ The linux/elf386 format decompresses directly into RAM,
|
||||
uses only one exec, does not use space in /tmp,
|
||||
and does not use /proc.
|
||||
|
||||
Linux/elf386 is automatically selected for Linux ELF exectuables.
|
||||
Linux/elf386 is automatically selected for Linux ELF executables.
|
||||
|
||||
Packed programs will be byte-identical to the original after uncompression.
|
||||
|
||||
@@ -602,7 +606,7 @@ Extra options available for this executable format:
|
||||
Please read the general Linux description first.
|
||||
|
||||
The generic linux/386 format decompresses to /tmp and needs
|
||||
/proc filesystem support. It starts the decompressed program
|
||||
/proc file system support. It starts the decompressed program
|
||||
via the execve() syscall.
|
||||
|
||||
Linux/386 is only selected if the specialized linux/elf386
|
||||
@@ -614,11 +618,11 @@ How it works:
|
||||
|
||||
For files which are not ELF and not a script for a known "-c" shell,
|
||||
UPX uses kernel execve(), which first requires decompressing to a
|
||||
temporary file in the filesystem. Interestingly -
|
||||
temporary file in the file system. Interestingly -
|
||||
because of the good memory management of the Linux kernel - this
|
||||
often does not introduce a noticable delay, and in fact there
|
||||
often does not introduce a noticeable delay, and in fact there
|
||||
will be no disk access at all if you have enough free memory as
|
||||
the entire process takes places within the filesystem buffers.
|
||||
the entire process takes places within the file system buffers.
|
||||
|
||||
A compressed executable consists of the UPX stub and an overlay
|
||||
which contains the original program in a compressed form.
|
||||
@@ -644,7 +648,7 @@ Specific drawbacks:
|
||||
decompression, but you still need it for the full execution time
|
||||
of the program.
|
||||
|
||||
- You must have /proc filesystem support as the stub wants to open
|
||||
- You must have /proc file system support as the stub wants to open
|
||||
/proc/<pid>/exe and needs /proc/<pid>/fd/X. This also means that you
|
||||
cannot compress programs that are used during the boot sequence
|
||||
before /proc is mounted.
|
||||
@@ -656,8 +660,8 @@ Specific drawbacks:
|
||||
|
||||
- Because of temporary decompression to disk the decompression speed
|
||||
is not as fast as with the other executable formats. Still, I can see
|
||||
no noticable delay when starting programs like my ~3 MB emacs (which
|
||||
is less than 1 MB when compressed :-).
|
||||
no noticeable delay when starting programs like my ~3 MiB emacs (which
|
||||
is less than 1 MiB when compressed :-).
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
@@ -677,13 +681,16 @@ nostalgic feelings of one of the authors.
|
||||
Packed programs will be byte-identical to the original after uncompression,
|
||||
until further notice.
|
||||
|
||||
Maximum uncompressed size: ~1.89 / ~7.60 Mbytes.
|
||||
Maximum uncompressed size: ~1.89 / ~7.60 MiB.
|
||||
|
||||
Notes:
|
||||
|
||||
- UPX creates as default a suitable executable for CD-Mastering
|
||||
and console transfer. For a CD-Master main executable you could also try
|
||||
the special option "--boot-only" as descriped below.
|
||||
the special option "--boot-only" as described below.
|
||||
It has been reported that upx packed executables are fully compatible with
|
||||
the Sony PlayStation 2 (PS2, PStwo) and Sony PlayStation Portable (PSP) in
|
||||
Sony PlayStation (PSone) emulation mode.
|
||||
|
||||
- Normally the packed files use the same memory areas like the uncompressed
|
||||
versions, so they will not override other memory areas while unpacking.
|
||||
@@ -701,7 +708,7 @@ Extra options available for this executable format:
|
||||
|
||||
--8-bit Uses 8 bit size compression [default: 32 bit]
|
||||
|
||||
--8mb-ram PSone has 8 MB ram available [default: 2 MB]
|
||||
--8mib-ram PSone has 8 MiB ram available [default: 2 MiB]
|
||||
|
||||
--boot-only This format is for main exes and CD-Mastering only !
|
||||
It may slightly improve the compression ratio,
|
||||
@@ -759,7 +766,7 @@ Benefits:
|
||||
- Better compression (but note that the kernel was already compressed,
|
||||
so the improvement is not as large as with other formats).
|
||||
Still, the bytes saved may be essential for special needs like
|
||||
bootdisks.
|
||||
boot disks.
|
||||
|
||||
For example, this is what I get for my 2.2.16 kernel:
|
||||
1589708 vmlinux
|
||||
@@ -806,13 +813,13 @@ Extra options available for this executable format:
|
||||
=head2 NOTES FOR WIN32/PE
|
||||
|
||||
The PE support in B<UPX> is quite stable now, but probably there are
|
||||
still some incompabilities with some files.
|
||||
still some incompatibilities with some files.
|
||||
|
||||
Because of the way B<UPX> (and other packers for this format) works, you
|
||||
can see increased memory usage of your compressed files because the whole
|
||||
program is loaded into memory at startup.
|
||||
If you start several instances of huge compressed programs you're
|
||||
wasting memory because the common segements of the program won't
|
||||
wasting memory because the common segments of the program won't
|
||||
get shared across the instances.
|
||||
On the other hand if you're compressing only smaller programs, or
|
||||
running only one instance of larger programs, then this penalty is
|
||||
@@ -831,7 +838,7 @@ must end with ".scr" (as screensavers are handled slightly different
|
||||
than normal exe files).
|
||||
|
||||
UPX compressed PE files have some minor memory overhead (usually in the
|
||||
10 - 30 kbytes range) which can be seen by specifying the "-i" command
|
||||
10 - 30 KiB range) which can be seen by specifying the "-i" command
|
||||
line switch during compression.
|
||||
|
||||
Extra options available for this executable format:
|
||||
@@ -926,13 +933,13 @@ Please report all bugs immediately to the authors.
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
|
||||
Copyright (C) 2002-2007 Jens Medoch
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
|
||||
+50
-18
@@ -1,5 +1,7 @@
|
||||
#
|
||||
# UPX Makefile - needs GNU make 3.80 or better
|
||||
# UPX Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
@@ -7,9 +9,19 @@ MAKEFLAGS += -rR
|
||||
export SHELL = /bin/sh
|
||||
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
|
||||
|
||||
srcdir ?= $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
||||
ifneq ($(srcdir),./)
|
||||
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),)
|
||||
$(error GNU make 3.81 or better is required)
|
||||
endif
|
||||
|
||||
ifndef srcdir
|
||||
srcdir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
||||
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,')
|
||||
endif
|
||||
ifndef top_srcdir
|
||||
top_srcdir := $(srcdir)/..
|
||||
endif
|
||||
include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local)
|
||||
ifneq ($(srcdir),.)
|
||||
##$(info Info: using VPATH . $(srcdir))
|
||||
VPATH := . $(srcdir)
|
||||
endif
|
||||
@@ -17,18 +29,18 @@ endif
|
||||
ifeq ($(CXX),)
|
||||
CXX = g++
|
||||
endif
|
||||
ifeq ($(firstword $(CXX)),g++)
|
||||
ifneq ($(findstring $(firstword $(CXX)),g++),)
|
||||
USE_GNUC ?= 1
|
||||
endif
|
||||
ifeq ($(USE_GNUC),1)
|
||||
CXXFLAGS += -MMD
|
||||
ifeq ($(DEBUG),1)
|
||||
CXXFLAGS += -O0 -g
|
||||
else
|
||||
CXXFLAGS += -O2
|
||||
endif
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
|
||||
##CXXFLAGS += -Wshadow
|
||||
CXXFLAGS_WERROR = -Werror
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wshadow -Wwrite-strings
|
||||
CXXFLAGS += $(CXXFLAGS_WERROR)
|
||||
endif
|
||||
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
|
||||
CXXLD ?= $(CXX)
|
||||
@@ -37,7 +49,7 @@ exeext ?= .out
|
||||
libext ?= .a
|
||||
objext ?= .o
|
||||
|
||||
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
|
||||
upx_SOURCES := $(sort $(wildcard $(srcdir)/*.cpp))
|
||||
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
|
||||
|
||||
# we need UCL and zlib - you can set envvar UPX_UCLDIR
|
||||
@@ -46,37 +58,57 @@ INCLUDES += -I$(UPX_UCLDIR)/include
|
||||
LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext))))
|
||||
endif
|
||||
LIBS += -lucl -lz
|
||||
# you should set envvar UPX_LZMADIR to point to your unpacked lzma443.tar.bz2
|
||||
ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),)
|
||||
DEFS += -DWITH_LZMA
|
||||
# you should set envvar UPX_LZMADIR to point to your unpacked LZMA SDK
|
||||
include $(top_srcdir)/src/stub/src/c/Makevars.lzma
|
||||
ifneq ($(UPX_LZMA_VERSION),)
|
||||
DEFS += -DWITH_LZMA=$(UPX_LZMA_VERSION)
|
||||
INCLUDES += -I$(UPX_LZMADIR)
|
||||
endif
|
||||
|
||||
|
||||
all: upx$(exeext)
|
||||
.DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS)
|
||||
all: upx$(exeext) | .depend
|
||||
.DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS) .depend
|
||||
|
||||
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
|
||||
$($(notdir $@).PRE_LINK_STEP)
|
||||
$(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS))
|
||||
$($(notdir $@).POST_LINK_STEP)
|
||||
|
||||
%.o : %.cpp
|
||||
%.o : %.cpp | .depend
|
||||
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
|
||||
|
||||
.depend: $(sort $(wildcard $(srcdir)/*.cpp $(srcdir)/*.h)) $(MAKEFILE_LIST)
|
||||
@rm -f $@
|
||||
ifeq ($(USE_GNUC),1)
|
||||
@echo "Updating $@"
|
||||
@$(strip $(CXX) $(call e,CPPFLAGS) -MM) $(filter %.cpp,$^) > $@
|
||||
else
|
||||
touch $@
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(USE_GNUC),1)
|
||||
##compress_lzma$(objext) : CXXFLAGS += -O3 -fomit-frame-pointer
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-cast-qual
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-non-virtual-dtor
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-shadow
|
||||
ifeq ($(UPX_LZMA_VERSION),0x443)
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-non-virtual-dtor
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-unused
|
||||
##compress_lzma$(objext) : CXXFLAGS += -Wno-error
|
||||
endif
|
||||
# needed for gcc-4.3:
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-error
|
||||
endif
|
||||
|
||||
|
||||
mostlyclean clean distclean maintainer-clean:
|
||||
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)
|
||||
rm -f *.d *.map *.o *.obj *.res .depend upx.exe upx.out upx.ttp upx$(exeext)
|
||||
|
||||
-include *.d
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
|
||||
ifeq ($(MAKECMDGOALS),mostlyclean)
|
||||
else ifeq ($(MAKECMDGOALS),clean)
|
||||
else ifeq ($(MAKECMDGOALS),distclean)
|
||||
else ifeq ($(MAKECMDGOALS),maintainer-clean)
|
||||
else
|
||||
-include .depend
|
||||
endif
|
||||
|
||||
+27
-45
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_BELE_H
|
||||
#define __UPX_BELE_H
|
||||
#define __UPX_BELE_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -282,12 +282,12 @@ inline unsigned acc_swap32p(const acc_uint32e_t *p)
|
||||
|
||||
inline void acc_swab16s(acc_uint16e_t *p)
|
||||
{
|
||||
*p = acc_swab16(*p);
|
||||
*p = (acc_uint16e_t) acc_swab16(*p);
|
||||
}
|
||||
|
||||
inline void acc_swab32s(acc_uint32e_t *p)
|
||||
{
|
||||
*p = acc_swab32(*p);
|
||||
*p = (acc_uint32e_t) acc_swab32(*p);
|
||||
}
|
||||
|
||||
|
||||
@@ -313,8 +313,7 @@ inline void acc_ua_swab32s(void *p)
|
||||
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
|
||||
**************************************************************************/
|
||||
|
||||
struct BE16
|
||||
{
|
||||
__packed_struct(BE16)
|
||||
unsigned char d[2];
|
||||
|
||||
//inline BE16() { }
|
||||
@@ -332,12 +331,10 @@ struct BE16
|
||||
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct BE32
|
||||
{
|
||||
__packed_struct(BE32)
|
||||
unsigned char d[4];
|
||||
|
||||
//inline BE32() { }
|
||||
@@ -355,12 +352,10 @@ struct BE32
|
||||
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct BE64
|
||||
{
|
||||
__packed_struct(BE64)
|
||||
unsigned char d[8];
|
||||
|
||||
//inline BE64() { }
|
||||
@@ -378,12 +373,10 @@ struct BE64
|
||||
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_be64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE16
|
||||
{
|
||||
__packed_struct(LE16)
|
||||
unsigned char d[2];
|
||||
|
||||
//inline LE16() { }
|
||||
@@ -401,12 +394,10 @@ struct LE16
|
||||
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE32
|
||||
{
|
||||
__packed_struct(LE32)
|
||||
unsigned char d[4];
|
||||
|
||||
//inline LE32() { }
|
||||
@@ -424,12 +415,10 @@ struct LE32
|
||||
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE64
|
||||
{
|
||||
__packed_struct(LE64)
|
||||
unsigned char d[8];
|
||||
|
||||
//inline LE64() { }
|
||||
@@ -447,8 +436,7 @@ struct LE64
|
||||
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_le64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -555,7 +543,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
|
||||
// just for testing...
|
||||
#if !defined(ACC_CFG_NO_UNALIGNED)
|
||||
#if !(ACC_CFG_NO_UNALIGNED)
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200)
|
||||
typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
@@ -591,7 +579,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Provide namespaces and classes to abtract endianness policies.
|
||||
// Provide namespaces and classes to abstract endianness policies.
|
||||
//
|
||||
// CTP - Compile-Time Polymorphism (templates)
|
||||
// RTP - Run-Time Polymorphism (virtual functions)
|
||||
@@ -599,13 +587,13 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
// forward declarations
|
||||
namespace N_BELE_CTP {
|
||||
class BEPolicy; class LEPolicy;
|
||||
struct BEPolicy; struct LEPolicy;
|
||||
extern const BEPolicy be_policy;
|
||||
extern const LEPolicy le_policy;
|
||||
}
|
||||
namespace N_BELE_RTP {
|
||||
class AbstractPolicy;
|
||||
class BEPolicy; class LEPolicy;
|
||||
struct AbstractPolicy;
|
||||
struct BEPolicy; struct LEPolicy;
|
||||
extern const BEPolicy be_policy;
|
||||
extern const LEPolicy le_policy;
|
||||
}
|
||||
@@ -623,16 +611,10 @@ namespace N_BELE_RTP {
|
||||
}
|
||||
|
||||
namespace N_BELE_CTP {
|
||||
|
||||
template <class T>
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP();
|
||||
template <>
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP<BEPolicy>()
|
||||
{ return &N_BELE_RTP::be_policy; }
|
||||
template <>
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP<LEPolicy>()
|
||||
{ return &N_BELE_RTP::le_policy; }
|
||||
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP(const BEPolicy*)
|
||||
{ return &N_BELE_RTP::be_policy; }
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP(const LEPolicy*)
|
||||
{ return &N_BELE_RTP::le_policy; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
// CTP - Compile-Time Polymorphism (templates)
|
||||
# define V static inline
|
||||
# define S static int __acc_cdecl_qsort
|
||||
# define C
|
||||
# define C /*empty*/
|
||||
#elif defined(BELE_RTP)
|
||||
// RTP - Run-Time Polymorphism (virtual functions)
|
||||
# define V virtual
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_BPTR_H
|
||||
#define __UPX_BPTR_H
|
||||
#define __UPX_BPTR_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,13 +22,13 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
|
||||
+7
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
FILE *con_term = NULL;
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
@@ -84,14 +84,14 @@ static int do_init(FILE *f)
|
||||
if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO))
|
||||
return con_mode;
|
||||
|
||||
#if defined(USE_ANSI)
|
||||
#if (USE_ANSI)
|
||||
try_init(&console_ansi_mono,f);
|
||||
try_init(&console_ansi_color,f);
|
||||
#endif
|
||||
#if defined(USE_SCREEN)
|
||||
#if (USE_SCREEN)
|
||||
try_init(&console_screen,f);
|
||||
#endif
|
||||
#if defined(USE_AALIB)
|
||||
#if (USE_AALIB)
|
||||
try_init(&console_aalib,f);
|
||||
#endif
|
||||
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,13 +22,13 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
|
||||
+8
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,13 +22,13 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#if defined(USE_SCREEN)
|
||||
#if (USE_SCREEN)
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
@@ -130,15 +130,15 @@ static int init(FILE *f, int o, int now)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_djgpp2_construct(),fd);
|
||||
#endif
|
||||
#if defined(USE_SCREEN_WIN32)
|
||||
#if (USE_SCREEN_WIN32)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_win32_construct(),fd);
|
||||
#endif
|
||||
#if defined(USE_SCREEN_VCSA)
|
||||
#if (USE_SCREEN_VCSA)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_vcsa_construct(),fd);
|
||||
#endif
|
||||
#if defined(USE_SCREEN_CURSES)
|
||||
#if (USE_SCREEN_CURSES)
|
||||
if (!screen && o == CON_SCREEN)
|
||||
screen = do_construct(screen_curses_construct(),fd);
|
||||
#endif
|
||||
@@ -298,7 +298,7 @@ static void print0(FILE *f, const char *ss)
|
||||
static bool intro(FILE *f)
|
||||
{
|
||||
UNUSED(f);
|
||||
#if defined(USE_FRAMES)
|
||||
#if (USE_FRAMES)
|
||||
if (screen->intro)
|
||||
return screen->intro(screen,screen_show_frames);
|
||||
#endif
|
||||
|
||||
+22
-20
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
|
||||
assert(buf != NULL);
|
||||
#if 0
|
||||
return adler32(adler, (const Bytef *) buf, len); // zlib
|
||||
#elif defined(WITH_UCL)
|
||||
#elif (WITH_UCL)
|
||||
return ucl_adler32(adler, (const ucl_bytep) buf, len);
|
||||
#else
|
||||
# error
|
||||
@@ -59,7 +59,7 @@ unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
|
||||
assert(buf != NULL);
|
||||
#if 0
|
||||
return crc32(crc, (const Bytef *) buf, len); // zlib
|
||||
#elif defined(WITH_UCL)
|
||||
#elif (WITH_UCL)
|
||||
return ucl_crc32(crc, (const ucl_bytep) buf, len);
|
||||
#else
|
||||
# error
|
||||
@@ -108,17 +108,17 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
||||
|
||||
if (0) {
|
||||
}
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, cconf, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, cconf, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, cconf, cresult);
|
||||
@@ -154,19 +154,19 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
|
||||
if (0) {
|
||||
}
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_ZLIB)
|
||||
#if (WITH_ZLIB)
|
||||
else if (M_IS_DEFLATE(method))
|
||||
r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
@@ -182,8 +182,10 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
@@ -199,17 +201,17 @@ int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
|
||||
if (0) {
|
||||
}
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
r = upx_nrv_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
else {
|
||||
throwInternalError("unknown decompression method");
|
||||
|
||||
+25
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,19 +22,19 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_COMPRESS_H
|
||||
#define __UPX_COMPRESS_H
|
||||
#define __UPX_COMPRESS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
const char *upx_lzma_version_string(void);
|
||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
@@ -46,14 +46,16 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
const char *upx_nrv_version_string(void);
|
||||
int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
@@ -65,14 +67,16 @@ int upx_nrv_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_nrv_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_nrv_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
const char *upx_ucl_version_string(void);
|
||||
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
@@ -84,13 +88,16 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
#if defined(WITH_ZLIB)
|
||||
|
||||
#if (WITH_ZLIB)
|
||||
const char *upx_zlib_version_string(void);
|
||||
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
@@ -102,8 +109,10 @@ int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_zlib_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_zlib_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
+433
-161
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,13 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "compress.h"
|
||||
#include "mem.h"
|
||||
|
||||
|
||||
void lzma_compress_config_t::reset()
|
||||
@@ -46,10 +47,13 @@ void lzma_compress_config_t::reset()
|
||||
}
|
||||
|
||||
|
||||
#if !defined(WITH_LZMA)
|
||||
#if !(WITH_LZMA)
|
||||
extern int compress_lzma_dummy;
|
||||
int compress_lzma_dummy = 0;
|
||||
#else
|
||||
#define opt compress_lzma_opt
|
||||
|
||||
#undef USE_LZMA_PROPERTIES
|
||||
|
||||
|
||||
// INFO: the LZMA SDK is covered by a permissive license which allows
|
||||
@@ -89,11 +93,244 @@ int compress_lzma_dummy = 0;
|
||||
// while you keep LZMA SDK code unmodified.
|
||||
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#include "C/7zVersion.h"
|
||||
#if (WITH_LZMA != (0x100 * MY_VER_MAJOR) + (0x10 * (MY_VER_MINOR / 10)) + (MY_VER_MINOR % 10))
|
||||
# error "WITH_LZMA version mismatch"
|
||||
#endif
|
||||
#include "C/Types.h"
|
||||
static void *cb_alloc(void *, size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
static void cb_free(void *, void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// cruft because of pseudo-COM layer
|
||||
// compress defaults
|
||||
**************************************************************************/
|
||||
|
||||
#undef USE_LZMA_PROPERTIES
|
||||
static int prepare(lzma_compress_result_t *res,
|
||||
unsigned src_len, int method, int level,
|
||||
const lzma_compress_config_t *lcconf)
|
||||
{
|
||||
// setup defaults
|
||||
res->pos_bits = 2; // 0 .. 4
|
||||
res->lit_pos_bits = 0; // 0 .. 4
|
||||
res->lit_context_bits = 3; // 0 .. 8
|
||||
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
|
||||
res->fast_mode = 2;
|
||||
res->num_fast_bytes = 64; // 5 .. 273
|
||||
res->match_finder_cycles = 0;
|
||||
#if 1
|
||||
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value_c;
|
||||
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
|
||||
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value_c;
|
||||
res->dict_size = lzma_compress_config_t::dict_size_t::default_value_c;
|
||||
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
|
||||
#endif
|
||||
// method overrides
|
||||
if (method >= 0x100) {
|
||||
res->pos_bits = (method >> 16) & 15;
|
||||
res->lit_pos_bits = (method >> 12) & 15;
|
||||
res->lit_context_bits = (method >> 8) & 15;
|
||||
}
|
||||
#if 0
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MiB of stack during runtime decompression.
|
||||
res->lit_pos_bits = 4;
|
||||
res->lit_context_bits = 8;
|
||||
#endif
|
||||
|
||||
// FIXME: tune these settings according to level
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
res->dict_size = 256 * 1024;
|
||||
res->fast_mode = 0;
|
||||
res->num_fast_bytes = 8;
|
||||
break;
|
||||
case 2:
|
||||
res->dict_size = 256 * 1024;
|
||||
res->fast_mode = 0;
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
case 8:
|
||||
break;
|
||||
case 9:
|
||||
res->dict_size = 8 * 1024 * 1024;
|
||||
break;
|
||||
case 10:
|
||||
res->dict_size = src_len;
|
||||
break;
|
||||
default:
|
||||
goto error;
|
||||
}
|
||||
|
||||
// cconf overrides
|
||||
if (lcconf)
|
||||
{
|
||||
oassign(res->pos_bits, lcconf->pos_bits);
|
||||
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
|
||||
oassign(res->lit_context_bits, lcconf->lit_context_bits);
|
||||
oassign(res->dict_size, lcconf->dict_size);
|
||||
oassign(res->num_fast_bytes, lcconf->num_fast_bytes);
|
||||
}
|
||||
|
||||
// limit dictionary size
|
||||
if (res->dict_size > src_len)
|
||||
res->dict_size = src_len;
|
||||
|
||||
// limit num_probs
|
||||
if (lcconf && lcconf->max_num_probs)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned n = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
if (n <= lcconf->max_num_probs)
|
||||
break;
|
||||
if (res->lit_pos_bits > res->lit_context_bits)
|
||||
{
|
||||
if (res->lit_pos_bits == 0)
|
||||
goto error;
|
||||
res->lit_pos_bits -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (res->lit_context_bits == 0)
|
||||
goto error;
|
||||
res->lit_context_bits -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#define kLiteralNextStates kLiteralNextStates_enc
|
||||
#include "C/LzmaEnc.h"
|
||||
#include "C/LzmaEnc.c"
|
||||
#include "C/LzFind.c"
|
||||
#undef kLiteralNextStates
|
||||
#undef kNumFullDistances
|
||||
|
||||
|
||||
struct upx_ICompressProgress {
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
upx_callback_p cb;
|
||||
};
|
||||
|
||||
static SRes cb_progress(void *p, UInt64 inSize, UInt64 outSize) {
|
||||
upx_callback_p cb = ((upx_ICompressProgress *) p)->cb;
|
||||
if (cb && cb->nprogress)
|
||||
cb->nprogress(cb, (unsigned) inSize, (unsigned) outSize);
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(M_IS_LZMA(method));
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
|
||||
int r = UPX_E_ERROR;
|
||||
int rh;
|
||||
|
||||
unsigned dst_avail = *dst_len;
|
||||
*dst_len = 0;
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
upx_ICompressProgress progress;
|
||||
progress.Progress = cb_progress; progress.cb = cb;
|
||||
|
||||
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
|
||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
goto error;
|
||||
|
||||
CLzmaEncProps props; memset(&props, 0, sizeof(props));
|
||||
props.level = level;
|
||||
LzmaEncProps_Init(&props);
|
||||
props.pb = res->pos_bits;
|
||||
props.lp = res->lit_pos_bits;
|
||||
props.lc = res->lit_context_bits;
|
||||
props.dictSize = res->dict_size;
|
||||
props.algo = res->fast_mode ? 1 : 0;
|
||||
props.fb = res->num_fast_bytes;
|
||||
props.mc = res->match_finder_cycles;
|
||||
|
||||
unsigned char props_buf[LZMA_PROPS_SIZE];
|
||||
SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE;
|
||||
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
if (dst_avail < 1)
|
||||
goto error;
|
||||
dst[0] = 0; // filled below
|
||||
dst += 1; *dst_len += 1; dst_avail -= 1;
|
||||
#else
|
||||
if (dst_avail < 2)
|
||||
goto error;
|
||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||
unsigned tt; tt = res->lit_context_bits + res->lit_pos_bits;
|
||||
dst[0] = ((tt << 3) | res->pos_bits);
|
||||
dst[1] = ((res->lit_pos_bits << 4) | (res->lit_context_bits));
|
||||
dst += 2; *dst_len += 2; dst_avail -= 2;
|
||||
#endif
|
||||
SizeT x_len; x_len = dst_avail;
|
||||
rh = LzmaEncode(dst, &x_len, src, src_len,
|
||||
&props, props_buf, &props_buf_size, 0,
|
||||
(ICompressProgress *) (void *) &progress, &cba, &cba);
|
||||
assert(x_len <= dst_avail);
|
||||
*dst_len += x_len;
|
||||
if (rh == SZ_OK) {
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
dst[-1] = props_buf[0];
|
||||
#endif
|
||||
r = UPX_E_OK;
|
||||
}
|
||||
|
||||
error:
|
||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress - cruft because of pseudo-COM layer
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef MSDOS
|
||||
#undef OS2
|
||||
@@ -101,9 +338,15 @@ int compress_lzma_dummy = 0;
|
||||
#undef _WIN32_WCE
|
||||
#undef COMPRESS_MF_MT
|
||||
#undef _NO_EXCEPTIONS
|
||||
#include "C/Common/MyInitGuid.h"
|
||||
//#include "C/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
#include "C/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# define INITGUID 1
|
||||
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#else
|
||||
# include "C/Common/MyInitGuid.h"
|
||||
//# include "C/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
# include "C/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#endif
|
||||
|
||||
namespace MyLzma {
|
||||
|
||||
@@ -173,16 +416,29 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
|
||||
# pragma warning(disable: 424) // #424: extra ";" ignored
|
||||
#endif
|
||||
|
||||
#include "C/Common/Alloc.cpp"
|
||||
#include "C/Common/CRC.cpp"
|
||||
//#include "C/7zip/Common/InBuffer.cpp"
|
||||
#include "C/7zip/Common/OutBuffer.cpp"
|
||||
#include "C/7zip/Common/StreamUtils.cpp"
|
||||
#include "C/7zip/Compress/LZ/LZInWindow.cpp"
|
||||
//#include "C/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//#include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
#include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
#include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# include "C/Alloc.c"
|
||||
# include "C/7zCrc.c"
|
||||
# include "C/Compress/Lz/MatchFinder.c"
|
||||
//# include "CPP/7zip/Common/InBuffer.cpp"
|
||||
# include "CPP/7zip/Common/OutBuffer.cpp"
|
||||
# include "CPP/7zip/Common/StreamUtils.cpp"
|
||||
//# include "CPP/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
# include "CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#else
|
||||
# include "C/Common/Alloc.cpp"
|
||||
# include "C/Common/CRC.cpp"
|
||||
//# include "C/7zip/Common/InBuffer.cpp"
|
||||
# include "C/7zip/Common/OutBuffer.cpp"
|
||||
# include "C/7zip/Common/StreamUtils.cpp"
|
||||
# include "C/7zip/Compress/LZ/LZInWindow.cpp"
|
||||
//# include "C/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//# include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
# include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
# include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#endif
|
||||
#undef RC_NORMALIZE
|
||||
|
||||
|
||||
@@ -221,126 +477,25 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
NCoderPropID::kMatchFinder // 7 mf
|
||||
};
|
||||
PROPVARIANT pr[8];
|
||||
#ifdef COMPRESS_MF_BT4
|
||||
const unsigned nprops = 8;
|
||||
static wchar_t matchfinder[] = L"BT4";
|
||||
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
|
||||
pr[7].vt = VT_BSTR; pr[7].bstrVal = matchfinder;
|
||||
#else
|
||||
const unsigned nprops = 7;
|
||||
#endif
|
||||
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4;
|
||||
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
|
||||
pr[7].vt = VT_BSTR;
|
||||
|
||||
// setup defaults
|
||||
pr[0].uintVal = 2; // 0 .. 4
|
||||
pr[1].uintVal = 0; // 0 .. 4
|
||||
pr[2].uintVal = 3; // 0 .. 8
|
||||
pr[3].uintVal = 4 * 1024 * 1024; // 1 .. 2**30
|
||||
pr[4].uintVal = 2;
|
||||
pr[5].uintVal = 64; // 5 .. 273
|
||||
pr[6].uintVal = 0;
|
||||
#ifdef COMPRESS_MF_BT4
|
||||
static wchar_t matchfinder[] = L"BT4";
|
||||
#endif
|
||||
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
|
||||
pr[7].bstrVal = matchfinder;
|
||||
#if 1
|
||||
pr[0].uintVal = lzma_compress_config_t::pos_bits_t::default_value_c;
|
||||
pr[1].uintVal = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
|
||||
pr[2].uintVal = lzma_compress_config_t::lit_context_bits_t::default_value_c;
|
||||
pr[3].uintVal = lzma_compress_config_t::dict_size_t::default_value_c;
|
||||
pr[5].uintVal = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
|
||||
#endif
|
||||
// method overrides
|
||||
if (method >= 0x100) {
|
||||
pr[0].uintVal = (method >> 16) & 15;
|
||||
pr[1].uintVal = (method >> 12) & 15;
|
||||
pr[2].uintVal = (method >> 8) & 15;
|
||||
}
|
||||
#if 0
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MB of stack during runtime decompression.
|
||||
pr[1].uintVal = 4;
|
||||
pr[2].uintVal = 8;
|
||||
#endif
|
||||
|
||||
// FIXME: tune these settings according to level
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
pr[3].uintVal = 256 * 1024;
|
||||
pr[4].uintVal = 0;
|
||||
pr[5].uintVal = 8;
|
||||
break;
|
||||
case 2:
|
||||
pr[3].uintVal = 256 * 1024;
|
||||
pr[4].uintVal = 0;
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
case 8:
|
||||
break;
|
||||
case 9:
|
||||
pr[3].uintVal = 8 * 1024 * 1024;
|
||||
break;
|
||||
case 10:
|
||||
pr[3].uintVal = src_len;
|
||||
break;
|
||||
default:
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
// cconf overrides
|
||||
if (lcconf)
|
||||
{
|
||||
oassign(pr[0].uintVal, lcconf->pos_bits);
|
||||
oassign(pr[1].uintVal, lcconf->lit_pos_bits);
|
||||
oassign(pr[2].uintVal, lcconf->lit_context_bits);
|
||||
oassign(pr[3].uintVal, lcconf->dict_size);
|
||||
oassign(pr[5].uintVal, lcconf->num_fast_bytes);
|
||||
}
|
||||
|
||||
// limit dictionary size
|
||||
if (pr[3].uintVal > src_len)
|
||||
pr[3].uintVal = src_len;
|
||||
|
||||
// limit num_probs
|
||||
if (lcconf && lcconf->max_num_probs)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned n = 1846 + (768 << (pr[2].uintVal + pr[1].uintVal));
|
||||
if (n <= lcconf->max_num_probs)
|
||||
break;
|
||||
if (pr[1].uintVal > pr[2].uintVal)
|
||||
{
|
||||
if (pr[1].uintVal == 0)
|
||||
goto error;
|
||||
pr[1].uintVal -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pr[2].uintVal == 0)
|
||||
goto error;
|
||||
pr[2].uintVal -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res->pos_bits = pr[0].uintVal;
|
||||
res->lit_pos_bits = pr[1].uintVal;
|
||||
res->lit_context_bits = pr[2].uintVal;
|
||||
res->dict_size = pr[3].uintVal;
|
||||
res->fast_mode = pr[4].uintVal;
|
||||
res->num_fast_bytes = pr[5].uintVal;
|
||||
res->match_finder_cycles = pr[6].uintVal;
|
||||
//res->num_probs = LzmaGetNumProbs(&s.Properties));
|
||||
//res->num_probs = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
|
||||
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
pr[0].uintVal = res->pos_bits;
|
||||
pr[1].uintVal = res->lit_pos_bits;
|
||||
pr[2].uintVal = res->lit_context_bits;
|
||||
pr[3].uintVal = res->dict_size;
|
||||
pr[4].uintVal = res->fast_mode;
|
||||
pr[5].uintVal = res->num_fast_bytes;
|
||||
pr[6].uintVal = res->match_finder_cycles;
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
try {
|
||||
@@ -348,7 +503,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
# error
|
||||
#endif
|
||||
|
||||
if (enc.SetCoderProperties(propIDs, pr, 8) != S_OK)
|
||||
if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
|
||||
goto error;
|
||||
if (enc.WriteCoderProperties(&os) != S_OK)
|
||||
goto error;
|
||||
@@ -358,7 +513,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
goto error;
|
||||
}
|
||||
assert(os.b_pos == 5);
|
||||
#if defined(USE_LZMA_PROPERTIES)
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
os.b_pos = 1;
|
||||
#else
|
||||
os.b_pos = 0;
|
||||
@@ -391,23 +546,127 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
}
|
||||
|
||||
error:
|
||||
*dst_len = os.b_pos;
|
||||
*dst_len = (unsigned) os.b_pos;
|
||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||
//printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
|
||||
#undef _LZMA_PROB32
|
||||
#include "C/LzmaDec.h"
|
||||
#include "C/LzmaDec.c"
|
||||
|
||||
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
#define Properties prop
|
||||
assert(M_IS_LZMA(method));
|
||||
// see res->num_probs above
|
||||
COMPILE_TIME_ASSERT(sizeof(CLzmaProb) == 2)
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
|
||||
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
CLzmaDec s; memset(&s, 0, sizeof(s));
|
||||
SizeT srcLen = 0;
|
||||
int r = UPX_E_ERROR;
|
||||
SRes rh;
|
||||
ELzmaStatus status;
|
||||
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
rh = LzmaProps_Decode(&s.Properties, src, src_len);
|
||||
if (rh != 0)
|
||||
goto error;
|
||||
src += 1; src_len -= 1;
|
||||
#else
|
||||
if (src_len < 3)
|
||||
goto error;
|
||||
s.Properties.pb = src[0] & 7;
|
||||
s.Properties.lp = (src[1] >> 4);
|
||||
s.Properties.lc = src[1] & 15;
|
||||
if (s.Properties.pb >= 5) goto error;
|
||||
if (s.Properties.lp >= 5) goto error;
|
||||
if (s.Properties.lc >= 9) goto error;
|
||||
// extra
|
||||
if ((src[0] >> 3) != (int)(s.Properties.lc + s.Properties.lp)) goto error;
|
||||
src += 2; src_len -= 2;
|
||||
#endif
|
||||
s.Properties.dicSize = 0;
|
||||
|
||||
if (cresult)
|
||||
{
|
||||
assert(cresult->method == method);
|
||||
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
|
||||
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
|
||||
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
||||
assert(cresult->result_lzma.num_probs == (unsigned) LzmaProps_GetNumProbs(&s.Properties));
|
||||
const lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
UNUSED(res);
|
||||
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
}
|
||||
|
||||
rh = LzmaDec_AllocateProbs2(&s, &s.Properties, &cba);
|
||||
if (rh != SZ_OK)
|
||||
{
|
||||
r = UPX_E_OUT_OF_MEMORY;
|
||||
goto error;
|
||||
}
|
||||
|
||||
s.dic = dst; s.dicPos = 0; s.dicBufSize = *dst_len;
|
||||
LzmaDec_Init(&s);
|
||||
srcLen = src_len;
|
||||
rh = LzmaDec_DecodeToDic(&s, *dst_len, src, &srcLen, LZMA_FINISH_ANY, &status);
|
||||
assert(srcLen <= src_len);
|
||||
assert(s.dicPos <= *dst_len);
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
rh = SZ_ERROR_INPUT_EOF;
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
|
||||
{
|
||||
r = UPX_E_OK;
|
||||
if (srcLen != src_len)
|
||||
r = UPX_E_INPUT_NOT_CONSUMED;
|
||||
}
|
||||
error:
|
||||
*dst_len = s.dicPos;
|
||||
LzmaDec_FreeProbs(&s, &cba);
|
||||
return r;
|
||||
#undef Properties
|
||||
}
|
||||
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef _LZMA_IN_CB
|
||||
#undef _LZMA_OUT_READ
|
||||
#undef _LZMA_PROB32
|
||||
#undef _LZMA_LOC_OPT
|
||||
#include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
|
||||
#include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# include "C/Compress/Lzma/LzmaDecode.h"
|
||||
# include "C/Compress/Lzma/LzmaDecode.c"
|
||||
#else
|
||||
# include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
|
||||
# include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
|
||||
#endif
|
||||
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
@@ -425,7 +684,7 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
int r = UPX_E_ERROR;
|
||||
int rh;
|
||||
|
||||
#if defined(USE_LZMA_PROPERTIES)
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
if (src_len < 2)
|
||||
goto error;
|
||||
rh = LzmaDecodeProperties(&s.Properties, src, src_len);
|
||||
@@ -476,35 +735,39 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
error:
|
||||
*dst_len = dst_out;
|
||||
free(s.Probs);
|
||||
|
||||
UNUSED(cresult);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// test_overlap
|
||||
// test_overlap - see <ucl/ucl.h> for semantics
|
||||
**************************************************************************/
|
||||
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(M_IS_LZMA(method));
|
||||
|
||||
// FIXME - implement this
|
||||
// Note that Packer::verifyOverlappingDecompression() will
|
||||
// verify the final result in any case.
|
||||
UNUSED(buf);
|
||||
|
||||
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
||||
//printf("upx_lzma_test_overlap: %d\n", overlap_overhead);
|
||||
if ((int)overlap_overhead >= 256)
|
||||
return UPX_E_OK;
|
||||
|
||||
UNUSED(cresult);
|
||||
return UPX_E_ERROR;
|
||||
MemBuffer b(src_off + src_len);
|
||||
memcpy(b + src_off, buf + src_off, src_len);
|
||||
unsigned saved_dst_len = *dst_len;
|
||||
int r = upx_lzma_decompress(b + src_off, src_len, b, dst_len, method, cresult);
|
||||
if (r != UPX_E_OK)
|
||||
return r;
|
||||
if (*dst_len != saved_dst_len)
|
||||
return UPX_E_ERROR;
|
||||
// NOTE: there is a very tiny possibility that decompression has
|
||||
// succeeded but the data is not restored correctly because of
|
||||
// in-place buffer overlapping.
|
||||
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
|
||||
return UPX_E_ERROR;
|
||||
return UPX_E_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -514,9 +777,18 @@ int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
|
||||
const char *upx_lzma_version_string(void)
|
||||
{
|
||||
// FIXME
|
||||
// return NULL;
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
return MY_VERSION;
|
||||
#elif (WITH_LZMA + 0 == 0x457)
|
||||
return "4.57";
|
||||
#elif (WITH_LZMA + 0 == 0x449)
|
||||
return "4.49";
|
||||
#elif (WITH_LZMA + 0 == 0x443)
|
||||
return "4.43";
|
||||
#else
|
||||
# error "unknown WITH_LZMA version"
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
+16
-13
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,29 +22,29 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "compress.h"
|
||||
#if !defined(WITH_UCL)
|
||||
#if !(WITH_UCL)
|
||||
extern int compress_ucl_dummy;
|
||||
int compress_ucl_dummy = 0;
|
||||
#else
|
||||
|
||||
#if 1 && !defined(UCL_USE_ASM) && (ACC_ARCH_I386)
|
||||
#if 1 && !(UCL_USE_ASM) && (ACC_ARCH_I386)
|
||||
# if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
|
||||
# define UCL_USE_ASM
|
||||
# define UCL_USE_ASM 1
|
||||
# endif
|
||||
#endif
|
||||
#if defined(UCL_NO_ASM)
|
||||
#if (UCL_NO_ASM)
|
||||
# undef UCL_USE_ASM
|
||||
#endif
|
||||
#if defined(ACC_CFG_NO_UNALIGNED)
|
||||
#if (ACC_CFG_NO_UNALIGNED)
|
||||
# undef UCL_USE_ASM
|
||||
#endif
|
||||
#if 1 && defined(UCL_USE_ASM)
|
||||
#if 1 && (UCL_USE_ASM)
|
||||
# include <ucl/ucl_asm.h>
|
||||
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
|
||||
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
|
||||
@@ -85,7 +85,7 @@ static int convert_errno_from_ucl(int r)
|
||||
|
||||
|
||||
extern "C" {
|
||||
static void wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
|
||||
static void __UCL_CDECL wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
|
||||
{
|
||||
if (state != -1 && state != 3) return;
|
||||
upx_callback_p cb = (upx_callback_p) user;
|
||||
@@ -120,7 +120,7 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
|
||||
ucl_compress_config_t cconf; cconf.reset();
|
||||
if (cconf_parm)
|
||||
cconf = cconf_parm->conf_ucl; // struct copy
|
||||
memcpy(&cconf, &cconf_parm->conf_ucl, sizeof(cconf)); // cconf = cconf_parm->conf_ucl; // struct copy
|
||||
|
||||
ucl_uint *res = cresult->result_ucl.result;
|
||||
// assume no info available - fill in worst case results
|
||||
@@ -228,12 +228,15 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
int r;
|
||||
UNUSED(tbuf); // not needed for UCL
|
||||
|
||||
switch (method)
|
||||
{
|
||||
|
||||
+24
-19
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,13 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "compress.h"
|
||||
#include "mem.h"
|
||||
|
||||
|
||||
void zlib_compress_config_t::reset()
|
||||
@@ -40,7 +41,7 @@ void zlib_compress_config_t::reset()
|
||||
}
|
||||
|
||||
|
||||
#if !defined(WITH_ZLIB)
|
||||
#if !(WITH_ZLIB)
|
||||
extern int compress_zlib_dummy;
|
||||
int compress_zlib_dummy = 0;
|
||||
#else
|
||||
@@ -188,28 +189,32 @@ done:
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// test_overlap
|
||||
// test_overlap - see <ucl/ucl.h> for semantics
|
||||
**************************************************************************/
|
||||
|
||||
int upx_zlib_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_zlib_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_DEFLATE);
|
||||
|
||||
// FIXME - implement this
|
||||
// Note that Packer::verifyOverlappingDecompression() will
|
||||
// verify the final result in any case.
|
||||
UNUSED(buf);
|
||||
|
||||
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
||||
//printf("upx_zlib_test_overlap: %d\n", overlap_overhead);
|
||||
if ((int)overlap_overhead >= 256)
|
||||
return UPX_E_OK;
|
||||
|
||||
UNUSED(cresult);
|
||||
return UPX_E_ERROR;
|
||||
MemBuffer b(src_off + src_len);
|
||||
memcpy(b + src_off, buf + src_off, src_len);
|
||||
unsigned saved_dst_len = *dst_len;
|
||||
int r = upx_zlib_decompress(b + src_off, src_len, b, dst_len, method, cresult);
|
||||
if (r != UPX_E_OK)
|
||||
return r;
|
||||
if (*dst_len != saved_dst_len)
|
||||
return UPX_E_ERROR;
|
||||
// NOTE: there is a very tiny possibility that decompression has
|
||||
// succeeded but the data is not restored correctly because of
|
||||
// in-place buffer overlapping.
|
||||
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
|
||||
return UPX_E_ERROR;
|
||||
return UPX_E_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+84
-41
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_CONF_H
|
||||
#define __UPX_CONF_H
|
||||
#define __UPX_CONF_H 1
|
||||
|
||||
#include "version.h"
|
||||
|
||||
@@ -36,6 +36,21 @@
|
||||
// ACC
|
||||
**************************************************************************/
|
||||
|
||||
#if (defined(_WIN32) || defined(_WIN64)) && defined(_MSC_VER)
|
||||
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE 1
|
||||
#endif
|
||||
#ifndef _CRT_NONSTDC_NO_WARNINGS
|
||||
#define _CRT_NONSTDC_NO_WARNINGS 1
|
||||
#endif
|
||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "miniacc.h"
|
||||
#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
# undef HAVE_UTIME_H /* this pulls in <windows.h> */
|
||||
@@ -78,10 +93,13 @@
|
||||
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# elif defined(__linux__)
|
||||
# pragma warning(error: 424) // #424: extra ";" ignored
|
||||
//# pragma warning(disable: 128) // #128: loop is not reachable from preceding code
|
||||
//# pragma warning(disable: 181) // #181: argument is incompatible with corresponding format string conversion
|
||||
# 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
|
||||
# pragma warning(disable: 1418) // #1418: external function definition with no prior declaration
|
||||
//# pragma warning(disable: 1419) // #1419: external declaration in primary source file
|
||||
# else
|
||||
# error "untested platform"
|
||||
# endif
|
||||
@@ -90,6 +108,7 @@
|
||||
# error "need Visual C++ 5.0 or newer"
|
||||
# endif
|
||||
# pragma warning(error: 4096) // W2: '__cdecl' must be used with '...'
|
||||
# pragma warning(error: 4138) // Wx: '*/' found outside of comment
|
||||
# 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
|
||||
@@ -107,10 +126,13 @@
|
||||
#elif (ACC_CC_SUNPROC)
|
||||
//# pragma error_messages(off,"badargtype2w") // FIXME
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# if (__WATCOMC__ < 1100)
|
||||
# error "need Watcom C++ 11.0c or newer"
|
||||
# if (__WATCOMC__ < 1280)
|
||||
# error "need Open Watcom C++ 1.8 or newer" // because earlier versions do not support nested classes
|
||||
# endif
|
||||
# if defined(__cplusplus)
|
||||
# pragma warning 367 9 // w3: conditional expression in if statement is always true
|
||||
# pragma warning 368 9 // w3: conditional expression in if statement is always false
|
||||
# pragma warning 389 9 // w3: integral value may be truncated
|
||||
# pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality)
|
||||
# endif
|
||||
#endif
|
||||
@@ -137,15 +159,18 @@
|
||||
#endif
|
||||
|
||||
// just in case
|
||||
#undef _
|
||||
#undef __
|
||||
#undef ___
|
||||
#undef NDEBUG
|
||||
#undef dos
|
||||
#undef linux
|
||||
#undef small
|
||||
#undef tos
|
||||
#if defined(ACC_CC_DMC)
|
||||
#if (ACC_CC_DMC)
|
||||
# undef tell
|
||||
#endif
|
||||
#if !defined(ACC_CC_PGI)
|
||||
#if !(ACC_CC_PGI)
|
||||
# undef unix
|
||||
#endif
|
||||
#if defined(__DJGPP__)
|
||||
@@ -160,15 +185,18 @@
|
||||
#if 0 && !defined(WITH_LZMA)
|
||||
# define WITH_LZMA 1
|
||||
#endif
|
||||
#if 1 && (ACC_CC_WATCOMC)
|
||||
# undef WITH_LZMA
|
||||
#endif
|
||||
#if defined(UPX_OFFICIAL_BUILD)
|
||||
# if !defined(WITH_LZMA) || !defined(WITH_NRV) || !defined(WITH_UCL)
|
||||
# if !(WITH_LZMA) || !(WITH_NRV) || !(WITH_UCL)
|
||||
# error
|
||||
# endif
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
# include <nrv/nrvconf.h>
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
# define ucl_compress_config_t REAL_ucl_compress_config_t
|
||||
# include <ucl/uclconf.h>
|
||||
# include <ucl/ucl.h>
|
||||
@@ -178,11 +206,6 @@
|
||||
# undef ucl_compress_config_t
|
||||
# undef ucl_compress_config_p
|
||||
#endif
|
||||
#if !defined(__UPX_CHECKER)
|
||||
# if defined(__UCL_CHECKER) || defined(__NRV_CHECKER)
|
||||
# define __UPX_CHECKER
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
|
||||
# error "UINT_MAX"
|
||||
#endif
|
||||
@@ -196,7 +219,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
// malloc debuggers
|
||||
#if defined(WITH_VALGRIND)
|
||||
#if (WITH_VALGRIND)
|
||||
# include <valgrind/memcheck.h>
|
||||
#endif
|
||||
|
||||
@@ -235,11 +258,11 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(HAVE_STRCASECMP) && defined(HAVE_STRICMP)
|
||||
# define strcasecmp stricmp
|
||||
#if !(HAVE_STRCASECMP) && (HAVE_STRICMP)
|
||||
# define strcasecmp stricmp
|
||||
#endif
|
||||
#if !defined(HAVE_STRNCASECMP) && defined(HAVE_STRNICMP)
|
||||
# define strncasecmp strnicmp
|
||||
#if !(HAVE_STRNCASECMP) && (HAVE_STRNICMP)
|
||||
# define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
|
||||
@@ -301,16 +324,18 @@
|
||||
#endif
|
||||
|
||||
|
||||
#undef __attribute_packed
|
||||
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||
# if (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
|
||||
# define __attribute_packed
|
||||
# else
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# endif
|
||||
#if (ACC_CC_INTELC && (__INTEL_COMPILER < 800))
|
||||
#elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
|
||||
#elif (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||
# define __packed_struct(s) struct s {
|
||||
# define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# define __packed_struct(s) _Packed struct s {
|
||||
# define __packed_struct_end() };
|
||||
#endif
|
||||
#if !defined(__attribute_packed)
|
||||
# define __attribute_packed
|
||||
#if !defined(__packed_struct)
|
||||
# define __packed_struct(s) struct s {
|
||||
# define __packed_struct_end() };
|
||||
#endif
|
||||
|
||||
|
||||
@@ -323,8 +348,9 @@
|
||||
|
||||
#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; } __attribute_packed; \
|
||||
__packed_struct(acc_tmp_t) acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; __packed_struct_end() \
|
||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2*sizeof(b)+sizeof(a)) \
|
||||
COMPILE_TIME_ASSERT(sizeof(((acc_tmp_t*)0)->x)+sizeof(((acc_tmp_t*)0)->y)+sizeof(((acc_tmp_t*)0)->z) == 2*sizeof(b)+sizeof(a)) \
|
||||
}
|
||||
#if defined(__acc_alignof)
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
@@ -379,12 +405,14 @@ inline unsigned UPX_MIN(unsigned a, unsigned b) { return a < b ? a : b; }
|
||||
|
||||
#define ByteArray(var, size) Array(unsigned char, var, size)
|
||||
|
||||
struct nocopy
|
||||
struct noncopyable
|
||||
{
|
||||
inline nocopy() {}
|
||||
protected:
|
||||
inline noncopyable() {}
|
||||
inline ~noncopyable() {}
|
||||
private:
|
||||
nocopy(const nocopy &); // undefined
|
||||
nocopy& operator=(const nocopy &); // undefined
|
||||
noncopyable(const noncopyable &); // undefined
|
||||
const noncopyable& operator=(const noncopyable &); // undefined
|
||||
};
|
||||
|
||||
|
||||
@@ -448,13 +476,21 @@ private:
|
||||
#define UPX_F_LINUX_ELFI_i386 20
|
||||
#define UPX_F_WINCE_ARM_PE 21
|
||||
#define UPX_F_LINUX_ELF64_AMD 22
|
||||
#define UPX_F_LINUX_ELF32_ARMLE 23
|
||||
#define UPX_F_LINUX_ELF32_ARMEL 23
|
||||
#define UPX_F_BSD_i386 24
|
||||
#define UPX_F_BSD_ELF_i386 25
|
||||
#define UPX_F_BSD_SH_i386 26
|
||||
|
||||
#define UPX_F_VMLINUX_AMD64 27
|
||||
#define UPX_F_VMLINUX_ARM 28
|
||||
#define UPX_F_VMLINUX_ARMEL 28
|
||||
#define UPX_F_MACH_i386 29
|
||||
#define UPX_F_LINUX_ELF32_MIPSEL 30
|
||||
#define UPX_F_VMLINUZ_ARMEL 31
|
||||
#define UPX_F_MACH_ARMEL 32
|
||||
|
||||
#define UPX_F_DYLIB_i386 33
|
||||
#define UPX_F_MACH_AMD64 34
|
||||
#define UPX_F_DYLIB_AMD64 35
|
||||
|
||||
#define UPX_F_PLAIN_TEXT 127
|
||||
|
||||
@@ -462,7 +498,12 @@ private:
|
||||
#define UPX_F_SOLARIS_SPARC 130
|
||||
#define UPX_F_MACH_PPC32 131
|
||||
#define UPX_F_LINUX_ELFPPC32 132
|
||||
#define UPX_F_LINUX_ELF32_ARMBE 133
|
||||
#define UPX_F_LINUX_ELF32_ARMEB 133
|
||||
#define UPX_F_MACH_FAT 134
|
||||
#define UPX_F_VMLINUX_ARMEB 135
|
||||
#define UPX_F_VMLINUX_PPC32 136
|
||||
#define UPX_F_LINUX_ELF32_MIPSEB 137
|
||||
#define UPX_F_DYLIB_PPC32 138
|
||||
|
||||
|
||||
// compression methods
|
||||
@@ -776,8 +817,10 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
|
||||
|
||||
+22
-22
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -39,41 +39,41 @@
|
||||
#undef USE_SCREEN_WIN32
|
||||
#undef USE_FRAMES
|
||||
|
||||
#if defined(WITH_GUI) && !defined(NO_CONSOLE)
|
||||
# define NO_CONSOLE
|
||||
#if 1 && (WITH_GUI) && !defined(NO_CONSOLE)
|
||||
# define NO_CONSOLE 1
|
||||
#endif
|
||||
|
||||
#if 1 && defined(__linux__)
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_VCSA
|
||||
# if !defined(HAVE_LINUX_KD_H)
|
||||
# define USE_SCREEN 1
|
||||
# define USE_SCREEN_VCSA 1
|
||||
# if !(HAVE_LINUX_KD_H)
|
||||
# undef USE_SCREEN
|
||||
# undef USE_SCREEN_VCSA
|
||||
# endif
|
||||
# if !defined(HAVE_LINUX_KDEV_T_H) || !defined(HAVE_LINUX_MAJOR_H)
|
||||
# if !(HAVE_LINUX_KDEV_T_H) || !(HAVE_LINUX_MAJOR_H)
|
||||
# undef USE_SCREEN
|
||||
# undef USE_SCREEN_VCSA
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 1 && defined(__DJGPP__)
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN 1
|
||||
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_WIN32
|
||||
# define USE_SCREEN 1
|
||||
# define USE_SCREEN_WIN32 1
|
||||
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_WIN32
|
||||
# define USE_SCREEN 1
|
||||
# define USE_SCREEN_WIN32 1
|
||||
#endif
|
||||
|
||||
|
||||
#if 0 || defined(NO_ANSI)
|
||||
#if 0 || (NO_ANSI)
|
||||
# undef USE_ANSI
|
||||
#endif
|
||||
#if 0 || defined(NO_SCREEN)
|
||||
#if 0 || (NO_SCREEN)
|
||||
# undef USE_SCREEN
|
||||
#endif
|
||||
#if 0 || defined(NO_FRAMES) || !defined(USE_SCREEN)
|
||||
#if 0 || (NO_FRAMES) || !(USE_SCREEN)
|
||||
# undef USE_FRAMES
|
||||
#endif
|
||||
#if 1
|
||||
@@ -81,11 +81,11 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if 0 || defined(USE_ANSI) || defined(USE_SCREEN)
|
||||
# define USE_CONSOLE
|
||||
#if 0 || (USE_ANSI) || (USE_SCREEN)
|
||||
# define USE_CONSOLE 1
|
||||
#endif
|
||||
|
||||
#if 0 || defined(NO_CONSOLE) || !defined(USE_CONSOLE)
|
||||
#if 0 || (NO_CONSOLE) || !(USE_CONSOLE)
|
||||
# undef USE_CONSOLE
|
||||
# undef USE_ANSI
|
||||
# undef USE_SCREEN
|
||||
@@ -110,7 +110,7 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -165,7 +165,7 @@ void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
|
||||
|
||||
extern FILE *con_term;
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
extern int con_mode;
|
||||
extern console_t *con;
|
||||
|
||||
+11
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -161,6 +161,14 @@ void throwBadLoader()
|
||||
}
|
||||
|
||||
|
||||
void throwOutOfMemoryException(const char *msg)
|
||||
{
|
||||
if (msg == NULL)
|
||||
msg = "out of memory";
|
||||
throw OutOfMemoryException(msg);
|
||||
}
|
||||
|
||||
|
||||
void throwIOException(const char *msg, int e)
|
||||
{
|
||||
throw IOException(msg, e);
|
||||
|
||||
+6
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_EXCEPT_H
|
||||
#define __UPX_EXCEPT_H
|
||||
#define __UPX_EXCEPT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -204,7 +204,7 @@ public:
|
||||
// (noreturn) is probably not the correct semantics for throwing exceptions
|
||||
#define NORET __attribute__((__noreturn__))
|
||||
#else
|
||||
#define NORET
|
||||
#define NORET /*empty*/
|
||||
#endif
|
||||
|
||||
void throwCantPack(const char *msg) NORET;
|
||||
@@ -220,6 +220,7 @@ void throwBadLoader() NORET;
|
||||
void throwChecksumError() NORET;
|
||||
void throwCompressedDataViolation() NORET;
|
||||
void throwInternalError(const char *msg) NORET;
|
||||
void throwOutOfMemoryException(const char *msg = NULL) NORET;
|
||||
void throwIOException(const char *msg = NULL, int e = 0) NORET;
|
||||
void throwEOFException(const char *msg = NULL, int e = 0) NORET;
|
||||
|
||||
|
||||
+104
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
void File::chmod(const char *name, int mode)
|
||||
{
|
||||
#if defined(HAVE_CHMOD)
|
||||
#if (HAVE_CHMOD)
|
||||
if (::chmod(name,mode) != 0)
|
||||
throwIOException(name,errno);
|
||||
#else
|
||||
@@ -69,7 +69,7 @@ void File::unlink(const char *name)
|
||||
**************************************************************************/
|
||||
|
||||
FileBase::FileBase() :
|
||||
_fd(-1), _flags(0), _shflags(0), _mode(0), _name(NULL)
|
||||
_fd(-1), _flags(0), _shflags(0), _mode(0), _name(NULL), _offset(0), _length(0)
|
||||
{
|
||||
memset(&st,0,sizeof(st));
|
||||
}
|
||||
@@ -88,7 +88,7 @@ FileBase::~FileBase()
|
||||
}
|
||||
|
||||
|
||||
void FileBase::sopen()
|
||||
bool FileBase::do_sopen()
|
||||
{
|
||||
if (_shflags < 0)
|
||||
_fd = ::open(_name, _flags, _mode);
|
||||
@@ -101,9 +101,15 @@ void FileBase::sopen()
|
||||
#elif defined(SH_DENYRW)
|
||||
_fd = ::sopen(_name, _flags, _shflags, _mode);
|
||||
#else
|
||||
assert(0);
|
||||
throwInternalError("bad usage of do_sopen()");
|
||||
#endif
|
||||
}
|
||||
if (_fd < 0)
|
||||
return false;
|
||||
if (::fstat(_fd, &st) != 0)
|
||||
throwIOException(_name, errno);
|
||||
_length = st.st_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +123,8 @@ bool FileBase::close()
|
||||
_flags = 0;
|
||||
_mode = 0;
|
||||
_name = NULL;
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -164,10 +172,17 @@ void FileBase::seek(off_t off, int whence)
|
||||
{
|
||||
if (!isOpen())
|
||||
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 (whence == SEEK_SET) {
|
||||
if (off < 0)
|
||||
throwIOException("bad seek 2");
|
||||
off += _offset;
|
||||
}
|
||||
if (whence == SEEK_END) {
|
||||
if (off > 0)
|
||||
throwIOException("bad seek 3");
|
||||
off += _offset + _length;
|
||||
whence = SEEK_SET;
|
||||
}
|
||||
if (::lseek(_fd,off,whence) < 0)
|
||||
throwIOException("seek error",errno);
|
||||
}
|
||||
@@ -180,7 +195,19 @@ off_t FileBase::tell() const
|
||||
off_t l = ::lseek(_fd, 0, SEEK_CUR);
|
||||
if (l < 0)
|
||||
throwIOException("tell error",errno);
|
||||
return l;
|
||||
return l - _offset;
|
||||
}
|
||||
|
||||
|
||||
void FileBase::set_extent(off_t offset, off_t length)
|
||||
{
|
||||
_offset = offset;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
off_t FileBase::st_size() const
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,8 +232,9 @@ void InputFile::sopen(const char *name, int flags, int shflags)
|
||||
_flags = flags;
|
||||
_shflags = shflags;
|
||||
_mode = 0;
|
||||
FileBase::sopen();
|
||||
if (!isOpen())
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
if (!FileBase::do_sopen())
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
throw FileNotFoundException(_name, errno);
|
||||
@@ -289,8 +317,9 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
|
||||
_flags = flags;
|
||||
_shflags = shflags;
|
||||
_mode = mode;
|
||||
FileBase::sopen();
|
||||
if (!isOpen())
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
if (!FileBase::do_sopen())
|
||||
{
|
||||
#if 0
|
||||
// don't throw FileNotFound here -- this is confusing
|
||||
@@ -316,6 +345,8 @@ bool OutputFile::openStdout(int flags, bool force)
|
||||
_flags = flags;
|
||||
_shflags = -1;
|
||||
_mode = 0;
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
if (flags && acc_set_binmode(fd, 1) == -1)
|
||||
throwIOException(_name, errno);
|
||||
_fd = fd;
|
||||
@@ -329,6 +360,18 @@ void OutputFile::write(const void *buf, int len)
|
||||
bytes_written += len;
|
||||
}
|
||||
|
||||
off_t OutputFile::st_size() const
|
||||
{
|
||||
if (opt->to_stdout) { // might be a pipe ==> .st_size is invalid
|
||||
return bytes_written; // too big if seek()+write() instead of rewrite()
|
||||
}
|
||||
struct stat my_st;
|
||||
my_st.st_size = 0;
|
||||
if (::fstat(_fd, &my_st) != 0)
|
||||
throwIOException(_name, errno);
|
||||
return my_st.st_size;
|
||||
}
|
||||
|
||||
|
||||
void OutputFile::write(const MemBuffer *buf, int len)
|
||||
{
|
||||
@@ -343,6 +386,51 @@ void OutputFile::write(const MemBuffer &buf, int len)
|
||||
write(&buf, len);
|
||||
}
|
||||
|
||||
void OutputFile::rewrite(const void *buf, int len)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
write(buf, len);
|
||||
bytes_written -= len; // restore
|
||||
}
|
||||
|
||||
void OutputFile::seek(off_t off, int whence)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
switch (whence) {
|
||||
case SEEK_SET: {
|
||||
if (bytes_written < off) {
|
||||
bytes_written = off;
|
||||
}
|
||||
_length = bytes_written; // cheap, lazy update; needed?
|
||||
} break;
|
||||
case SEEK_END: {
|
||||
_length = bytes_written; // necessary
|
||||
} break;
|
||||
}
|
||||
super::seek(off,whence);
|
||||
}
|
||||
|
||||
void OutputFile::set_extent(off_t offset, off_t length)
|
||||
{
|
||||
super::set_extent(offset, length);
|
||||
bytes_written = 0;
|
||||
if (0==offset && (off_t)~0u==length) {
|
||||
if (::fstat(_fd, &st) != 0)
|
||||
throwIOException(_name, errno);
|
||||
_length = st.st_size - offset;
|
||||
}
|
||||
}
|
||||
|
||||
off_t OutputFile::unset_extent()
|
||||
{
|
||||
off_t l = ::lseek(_fd, 0, SEEK_END);
|
||||
if (l < 0)
|
||||
throwIOException("lseek error", errno);
|
||||
_offset = 0;
|
||||
_length = l;
|
||||
bytes_written = _length;
|
||||
return _length;
|
||||
}
|
||||
|
||||
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
||||
{
|
||||
|
||||
+14
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_FILE_H
|
||||
#define __UPX_FILE_H
|
||||
#define __UPX_FILE_H 1
|
||||
|
||||
class MemBuffer;
|
||||
|
||||
@@ -59,9 +59,11 @@ public:
|
||||
virtual bool isOpen() const { return _fd >= 0; }
|
||||
int getFd() const { return _fd; }
|
||||
const char *getName() const { return _name; }
|
||||
virtual off_t st_size() const; // { return _length; }
|
||||
virtual void set_extent(off_t offset, off_t length);
|
||||
|
||||
protected:
|
||||
void sopen();
|
||||
bool do_sopen();
|
||||
virtual int read(void *buf, int len);
|
||||
virtual int readx(void *buf, int len);
|
||||
virtual void write(const void *buf, int len);
|
||||
@@ -73,6 +75,8 @@ protected:
|
||||
int _shflags;
|
||||
int _mode;
|
||||
const char *_name;
|
||||
off_t _offset;
|
||||
off_t _length;
|
||||
public:
|
||||
struct stat st;
|
||||
};
|
||||
@@ -128,21 +132,15 @@ public:
|
||||
virtual void write(const void *buf, int len);
|
||||
virtual void write(const MemBuffer *buf, int len);
|
||||
virtual void write(const MemBuffer &buf, int len);
|
||||
virtual void set_extent(off_t offset, off_t length);
|
||||
virtual off_t unset_extent(); // returns actual length
|
||||
|
||||
off_t getBytesWritten() const { return bytes_written; }
|
||||
virtual off_t st_size() const; // { return _length; }
|
||||
|
||||
// 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
|
||||
}
|
||||
virtual void seek(off_t off, int whence);
|
||||
virtual void rewrite(const void *buf, int len);
|
||||
|
||||
// util
|
||||
static void dump(const char *name, const void *buf, int len, int flags=-1);
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_FILTER_H
|
||||
#define __UPX_FILTER_H
|
||||
#define __UPX_FILTER_H 1
|
||||
|
||||
class Filter;
|
||||
class FilterImp;
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ static int F(Filter *f)
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
@@ -126,7 +126,7 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#ifdef TESTING
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
+6
-6
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -51,7 +51,7 @@ static int F(Filter *f)
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
@@ -125,7 +125,7 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#ifdef TESTING
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
+8
-8
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -123,8 +123,8 @@ static int F(Filter *f)
|
||||
N_MRU : 0;
|
||||
#endif //}
|
||||
|
||||
// FIXME: We must fit into 8MB because we steal one bit.
|
||||
// find a 16MB large empty address space
|
||||
// FIXME: We must fit into 8 MiB because we steal one bit.
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
int which;
|
||||
unsigned char buf[256];
|
||||
@@ -249,11 +249,11 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
/*#ifdef TESTING*/
|
||||
#if 0 || defined(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*/
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -52,7 +52,7 @@ static int F(Filter *f)
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
@@ -126,7 +126,7 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#ifdef TESTING
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+15
-11
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2004-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2004-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -47,7 +47,7 @@ static int F(Filter *f)
|
||||
// scan
|
||||
const upx_byte *b = f->buf;
|
||||
#endif
|
||||
const unsigned size = umin(f->buf_len, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size = umin(f->buf_len, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = size -4;
|
||||
|
||||
unsigned ic;
|
||||
@@ -72,9 +72,11 @@ static int F(Filter *f)
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0) {
|
||||
if (0!=W_CTO) // FIXME: what is this ???
|
||||
return -1;
|
||||
#if (W_CTO != 0)
|
||||
return -1;
|
||||
#else
|
||||
f->cto = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
const unsigned char cto8 = f->cto;
|
||||
@@ -95,8 +97,9 @@ static int F(Filter *f)
|
||||
lastcall = ic;
|
||||
}
|
||||
else {
|
||||
assert(0==W_CTO // FIXME: what is this ???
|
||||
|| (~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
#if (W_CTO != 0)
|
||||
assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
#endif
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
}
|
||||
@@ -105,8 +108,9 @@ static int F(Filter *f)
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
ACC_UNUSED(lastnoncall);
|
||||
|
||||
#if 0
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d text_size=%x calltrickoffset=%x\n",
|
||||
calls,noncalls,size,cto8);
|
||||
#endif
|
||||
@@ -122,7 +126,7 @@ static int F(Filter *f)
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size4 = umin(f->buf_len - 4, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned addvalue = f->addvalue;
|
||||
|
||||
unsigned ic;
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+30
-57
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -51,8 +51,9 @@ void show_head(void)
|
||||
fg = con_fg(f,FG_GREEN);
|
||||
con_fprintf(f,
|
||||
" Ultimate Packer for eXecutables\n"
|
||||
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007\n"
|
||||
" Copyright (C) 1996 - %s\n"
|
||||
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
|
||||
UPX_VERSION_YEAR,
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||
V("d"),
|
||||
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
@@ -97,14 +98,14 @@ struct PackerNames
|
||||
const char* fname;
|
||||
const char* sname;
|
||||
};
|
||||
Entry names[32];
|
||||
Entry names[64];
|
||||
size_t names_count;
|
||||
const options_t *o;
|
||||
PackerNames() : names_count(0), o(NULL) { }
|
||||
void add(const Packer *p)
|
||||
{
|
||||
p->assertPacker();
|
||||
assert(names_count < 32);
|
||||
assert(names_count < 64);
|
||||
names[names_count].fname = p->getFullName(o);
|
||||
names[names_count].sname = p->getName();
|
||||
names_count++;
|
||||
@@ -113,6 +114,7 @@ struct PackerNames
|
||||
{
|
||||
PackerNames *self = (PackerNames *) user;
|
||||
self->add(p);
|
||||
delete p; p = NULL;
|
||||
return NULL;
|
||||
}
|
||||
static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) {
|
||||
@@ -140,15 +142,16 @@ static void show_all_packers(FILE *f, int verbose)
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t fl = strlen(fn);
|
||||
if (pos == 0) {
|
||||
con_fprintf(f, " %s", fn);
|
||||
pos = 2 + strlen(fn);
|
||||
} else if (pos + 1 + strlen(fn) > 80) {
|
||||
pos = 2 + fl;
|
||||
} else if (pos + 1 + fl > 80) {
|
||||
con_fprintf(f, "\n %s", fn);
|
||||
pos = 2 + strlen(fn);
|
||||
pos = 2 + fl;
|
||||
} else {
|
||||
con_fprintf(f, " %s", fn);
|
||||
pos += 1 + strlen(fn);
|
||||
pos += 1 + fl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,8 +208,8 @@ void show_help(int verbose)
|
||||
con_fprintf(f,"\nCompression tuning options:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --brute try all available compression methods & filters\n"
|
||||
" --ultra-brute try even more compression variants\n"
|
||||
" --brute try all available compression methods & filters [slow]\n"
|
||||
" --ultra-brute try even more compression variants [very slow]\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Backup options:\n");
|
||||
@@ -224,26 +227,16 @@ void show_help(int verbose)
|
||||
" --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");
|
||||
@@ -251,15 +244,12 @@ void show_help(int verbose)
|
||||
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);
|
||||
@@ -274,27 +264,12 @@ void show_help(int verbose)
|
||||
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"
|
||||
" --8mb-ram 8 megabyte memory limit [default: 2 mb]\n"
|
||||
" --8mib-ram 8 megabyte memory limit [default: 2 MiB]\n"
|
||||
" --boot-only disables 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");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
@@ -314,8 +289,6 @@ void show_help(int verbose)
|
||||
" --keep-resource=list do not compress resources specified by list\n"
|
||||
" --strip-relocs=0 do not strip relocations\n"
|
||||
" --strip-relocs=1 strip relocations [default]\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
@@ -337,13 +310,13 @@ void show_help(int verbose)
|
||||
// "\nUPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.\n"
|
||||
"");
|
||||
|
||||
#if defined(DEBUG) || defined(TESTING)
|
||||
#if (DEBUG) || (TESTING)
|
||||
fg = con_fg(f,FG_RED);
|
||||
con_fprintf(f,"\nWARNING: this version is compiled with"
|
||||
#if defined(DEBUG)
|
||||
#if (DEBUG)
|
||||
" -DDEBUG"
|
||||
#endif
|
||||
#if defined(TESTING)
|
||||
#if (TESTING)
|
||||
" -DTESTING"
|
||||
#endif
|
||||
"\n");
|
||||
@@ -387,7 +360,7 @@ void show_license(void)
|
||||
con_fprintf(f,
|
||||
"\n"
|
||||
" Markus F.X.J. Oberhumer Laszlo Molnar\n"
|
||||
" <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>\n"
|
||||
" <markus@oberhumer.com> <ml1050@users.sourceforge.net>\n"
|
||||
);
|
||||
fg = con_fg(f,fg);
|
||||
|
||||
@@ -407,34 +380,34 @@ void show_version(int x)
|
||||
UNUSED(v);
|
||||
|
||||
fprintf(fp, "upx %s\n", UPX_VERSION_STRING);
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
v = upx_nrv_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "NRV data compression library %s\n", v);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
v = upx_ucl_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "UCL data compression library %s\n", v);
|
||||
#endif
|
||||
#if defined(WITH_ZLIB)
|
||||
#if (WITH_ZLIB)
|
||||
v = upx_zlib_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "zlib data compression library %s\n", v);
|
||||
#endif
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
v = upx_lzma_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "LZMA SDK version %s\n", v);
|
||||
#endif
|
||||
fprintf(fp, "Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(fp, "Copyright (C) 1996-2007 Laszlo Molnar\n");
|
||||
fprintf(fp, "Copyright (C) 2000-2007 John F. Reiser\n");
|
||||
fprintf(fp, "Copyright (C) 2002-2007 Jens Medoch\n");
|
||||
#if defined(WITH_ZLIB)
|
||||
fprintf(fp, "Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(fp, "Copyright (C) 1996-2010 Laszlo Molnar\n");
|
||||
fprintf(fp, "Copyright (C) 2000-2010 John F. Reiser\n");
|
||||
fprintf(fp, "Copyright (C) 2002-2010 Jens Medoch\n");
|
||||
#if (WITH_ZLIB)
|
||||
fprintf(fp, "Copyright (C) 1995" "-2005 Jean-loup Gailly and Mark Adler\n");
|
||||
#endif
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
fprintf(fp, "Copyright (C) 1999" "-2006 Igor Pavlov\n");
|
||||
#endif
|
||||
fprintf(fp, "UPX comes with ABSOLUTELY NO WARRANTY; for details type '%s -L'.\n", progname);
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+11
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_LEFILE_H
|
||||
#define __UPX_LEFILE_H
|
||||
#define __UPX_LEFILE_H 1
|
||||
|
||||
class InputFile;
|
||||
class OutputFile;
|
||||
@@ -49,8 +49,8 @@ public:
|
||||
protected:
|
||||
enum { FIXUP_EXTRA = 3 };
|
||||
|
||||
struct le_header_t
|
||||
{ // 0x00
|
||||
__packed_struct(le_header_t)
|
||||
// 0x00
|
||||
char _[2]; // signature: 'LE' || 'LX'
|
||||
char byte_order; // 0 little endian
|
||||
char word_order; // 0 little endian
|
||||
@@ -117,28 +117,23 @@ protected:
|
||||
LE16 device_id;
|
||||
LE16 ddk_version;
|
||||
#endif
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct le_object_table_entry_t
|
||||
{
|
||||
__packed_struct(le_object_table_entry_t)
|
||||
LE32 virtual_size;
|
||||
LE32 base_address;
|
||||
LE32 flags;
|
||||
LE32 pagemap_index;
|
||||
LE32 npages;
|
||||
LE32 reserved;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct le_pagemap_entry_t
|
||||
{
|
||||
__packed_struct(le_pagemap_entry_t)
|
||||
unsigned char h;
|
||||
unsigned char m;
|
||||
unsigned char l;
|
||||
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
virtual void readObjectTable();
|
||||
virtual void writeObjectTable();
|
||||
|
||||
+79
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -159,7 +159,9 @@ void ElfLinker::init(const void *pdata_v, int plen)
|
||||
input = new upx_byte[inputlen + 1];
|
||||
unsigned new_len = u_len;
|
||||
int r = upx_decompress(pdata, c_len, input, &new_len, method, NULL);
|
||||
if (r != 0 || new_len != u_len)
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK || new_len != u_len)
|
||||
throwBadLoader();
|
||||
}
|
||||
else
|
||||
@@ -228,15 +230,21 @@ void ElfLinker::preprocessSymbols(char *start, char *end)
|
||||
assert(nextl != NULL);
|
||||
|
||||
if (sscanf(start, "%x g *ABS* %x %1023s",
|
||||
&value, &offset, symbol) == 3)
|
||||
&value, &offset, symbol) == 3)
|
||||
{
|
||||
char *s = strstr(start, symbol);
|
||||
s[strlen(symbol)] = 0;
|
||||
addSymbol(s, "*ABS*", value);
|
||||
assert(offset == 0);
|
||||
}
|
||||
#if 0
|
||||
else if (sscanf(start, "%x%*8c %1023s %*x %1023s",
|
||||
&offset, section, symbol) == 3)
|
||||
#else
|
||||
// work around broken scanf() implementations
|
||||
// http://bugs.winehq.org/show_bug.cgi?id=10401 (fixed in Wine 0.9.58)
|
||||
else if (sscanf(start, "%x%*c%*c%*c%*c%*c%*c%*c%*c %1023s %*x %1023s",
|
||||
#endif
|
||||
&offset, section, symbol) == 3)
|
||||
{
|
||||
char *s = strstr(start, symbol);
|
||||
s[strlen(symbol)] = 0;
|
||||
@@ -439,12 +447,29 @@ int ElfLinker::addLoader(const char *sname)
|
||||
return outputlen;
|
||||
}
|
||||
|
||||
void ElfLinker::addLoader(const char *s, va_list ap)
|
||||
{
|
||||
while (s != NULL)
|
||||
{
|
||||
addLoader(s);
|
||||
s = va_arg(ap, const char *);
|
||||
}
|
||||
}
|
||||
|
||||
void __acc_cdecl_va ElfLinker::addLoaderVA(const char *s, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
addLoader(s, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
int ElfLinker::getSection(const char *sname, int *slen) const
|
||||
{
|
||||
const Section *section = findSection(sname);
|
||||
if (slen)
|
||||
*slen = section->size;
|
||||
return section->output - output;
|
||||
return (int) (section->output - output);
|
||||
}
|
||||
|
||||
int ElfLinker::getSectionSize(const char *sname) const
|
||||
@@ -585,6 +610,7 @@ void ElfLinker::relocate1(const Relocation *rel, upx_byte *,
|
||||
/*************************************************************************
|
||||
// ElfLinker arch subclasses
|
||||
// FIXME: add more displacment overflow checks
|
||||
// FIXME: add support for our special "ignore_reloc_overflow" section
|
||||
**************************************************************************/
|
||||
|
||||
#if 0 // FIXME
|
||||
@@ -653,7 +679,10 @@ void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
{
|
||||
set_be32(location, get_be32(location) + value);
|
||||
}
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0
|
||||
|| strcmp(type, "R_ARM_THM_XPC22") == 0
|
||||
|| strcmp(type, "R_ARM_THM_PC22") == 0
|
||||
)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
value += ((get_be16(location) & 0x7ff) << 12);
|
||||
@@ -685,7 +714,10 @@ void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
{
|
||||
set_le32(location, get_le32(location) + value);
|
||||
}
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0
|
||||
|| strcmp(type, "R_ARM_THM_XPC22") == 0
|
||||
|| strcmp(type, "R_ARM_THM_PC22") == 0
|
||||
)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
value += ((get_le16(location) & 0x7ff) << 12);
|
||||
@@ -740,6 +772,37 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
{
|
||||
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
|
||||
#define MIPS_LO(a) ((a) & 0xffff)
|
||||
#define MIPS_PC16(a) ((a) >> 2)
|
||||
#define MIPS_PC26(a) (((a) & 0x0fffffff) >> 2)
|
||||
|
||||
if (strcmp(type, "R_MIPS_HI16") == 0)
|
||||
set_be16(2+location, get_be16(2+location) + MIPS_HI(value));
|
||||
else if (strcmp(type, "R_MIPS_LO16") == 0)
|
||||
set_be16(2+location, get_be16(2+location) + MIPS_LO(value));
|
||||
else if (strcmp(type, "R_MIPS_PC16") == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
set_be16(2+location, get_be16(2+location) + MIPS_PC16(value));
|
||||
}
|
||||
else if (strcmp(type, "R_MIPS_26") == 0)
|
||||
set_be32(location, get_be32(location) + MIPS_PC26(value));
|
||||
else if (strcmp(type, "R_MIPS_32") == 0)
|
||||
set_be32(location, get_be32(location) + value);
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
|
||||
#undef MIPS_HI
|
||||
#undef MIPS_LO
|
||||
#undef MIPS_PC16
|
||||
#undef MIPS_PC26
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
{
|
||||
@@ -778,6 +841,12 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
|
||||
return super::relocate1(rel, location, value, type);
|
||||
type += 6;
|
||||
|
||||
if (strcmp(type, "ADDR32") == 0)
|
||||
{
|
||||
set_be32(location, get_be32(location) + value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(type, "REL", 3) == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
|
||||
+35
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,24 +21,24 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_LINKER_H
|
||||
#define __UPX_LINKER_H
|
||||
#define __UPX_LINKER_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// ElfLinker
|
||||
**************************************************************************/
|
||||
|
||||
class ElfLinker : private nocopy
|
||||
class ElfLinker : private noncopyable
|
||||
{
|
||||
friend class Packer;
|
||||
public:
|
||||
const N_BELE_RTP::AbstractPolicy *bele;
|
||||
const N_BELE_RTP::AbstractPolicy *bele; // target endianness
|
||||
protected:
|
||||
struct Section;
|
||||
struct Symbol;
|
||||
@@ -83,6 +83,12 @@ public:
|
||||
virtual void init(const void *pdata, int plen);
|
||||
//virtual void setLoaderAlignOffset(int phase);
|
||||
virtual int addLoader(const char *sname);
|
||||
void addLoader(const char *s, va_list ap);
|
||||
#if 1 && (ACC_CC_GNUC >= 0x040100)
|
||||
void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__));
|
||||
#else
|
||||
void __acc_cdecl_va addLoaderVA(const char *s, ...);
|
||||
#endif
|
||||
virtual Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align);
|
||||
virtual int getSection(const char *sname, int *slen=NULL) const;
|
||||
virtual int getSectionSize(const char *sname) const;
|
||||
@@ -101,10 +107,18 @@ protected:
|
||||
virtual void relocate();
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
|
||||
// target endianness abstraction
|
||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||
unsigned get_te32(const void *p) const { return bele->get32(p); }
|
||||
acc_uint64l_t get_te64(const void *p) const { return bele->get64(p); }
|
||||
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
||||
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
|
||||
void set_te64(void *p, acc_uint64l_t v) const { bele->set64(p, v); }
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Section : private nocopy
|
||||
struct ElfLinker::Section : private noncopyable
|
||||
{
|
||||
char *name;
|
||||
void *input;
|
||||
@@ -119,7 +133,7 @@ struct ElfLinker::Section : private nocopy
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Symbol : private nocopy
|
||||
struct ElfLinker::Symbol : private noncopyable
|
||||
{
|
||||
char *name;
|
||||
Section *section;
|
||||
@@ -130,7 +144,7 @@ struct ElfLinker::Symbol : private nocopy
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Relocation : private nocopy
|
||||
struct ElfLinker::Relocation : private noncopyable
|
||||
{
|
||||
const Section *section;
|
||||
unsigned offset;
|
||||
@@ -189,6 +203,17 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerMipsBE : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
public:
|
||||
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerMipsLE : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
|
||||
+106
-27
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,11 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "mygetopt.h"
|
||||
#include "file.h"
|
||||
#include "packer.h"
|
||||
#include "p_elf.h"
|
||||
@@ -56,11 +55,14 @@ void options_t::reset()
|
||||
|
||||
o->backup = -1;
|
||||
o->overlay = -1;
|
||||
o->preserve_mode = true;
|
||||
o->preserve_ownership = true;
|
||||
o->preserve_timestamp = true;
|
||||
|
||||
o->console = CON_FILE;
|
||||
#if defined(__DJGPP__)
|
||||
o->console = CON_INIT;
|
||||
#elif defined(USE_SCREEN_WIN32)
|
||||
#elif (USE_SCREEN_WIN32)
|
||||
o->console = CON_INIT;
|
||||
#elif 1 && defined(__linux__)
|
||||
o->console = CON_INIT;
|
||||
@@ -87,6 +89,19 @@ static int done_script_name = 0;
|
||||
const char *argv0 = "";
|
||||
const char *progname = "";
|
||||
|
||||
static acc_getopt_t mfx_getopt;
|
||||
#define mfx_optarg mfx_getopt.optarg
|
||||
#define mfx_optind mfx_getopt.optind
|
||||
#define mfx_option acc_getopt_longopt_t
|
||||
static void handle_opterr(acc_getopt_p g, const char *f, void *v)
|
||||
{
|
||||
struct A { va_list ap; };
|
||||
struct A *a = (struct A *) v;
|
||||
fprintf( stderr, "%s: ", g->progname);
|
||||
vfprintf(stderr, f, a->ap);
|
||||
fprintf( stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
static int num_files = -1;
|
||||
static int exit_code = EXIT_OK;
|
||||
@@ -553,23 +568,28 @@ static int do_option(int optc, const char *arg)
|
||||
|
||||
// method
|
||||
case 702:
|
||||
opt->method_nrv2b_seen = true;
|
||||
if (!set_method(M_NRV2B_LE32, -1))
|
||||
e_method(M_NRV2B_LE32, opt->level);
|
||||
break;
|
||||
case 704:
|
||||
opt->method_nrv2d_seen = true;
|
||||
if (!set_method(M_NRV2D_LE32, -1))
|
||||
e_method(M_NRV2D_LE32, opt->level);
|
||||
break;
|
||||
case 705:
|
||||
opt->method_nrv2e_seen = true;
|
||||
if (!set_method(M_NRV2E_LE32, -1))
|
||||
e_method(M_NRV2E_LE32, opt->level);
|
||||
break;
|
||||
case 721:
|
||||
opt->method_lzma_seen = true;
|
||||
opt->all_methods_use_lzma = true;
|
||||
if (!set_method(M_LZMA, -1))
|
||||
e_method(M_LZMA, opt->level);
|
||||
break;
|
||||
case 722:
|
||||
opt->method_lzma_seen = false;
|
||||
opt->all_methods_use_lzma = false;
|
||||
if (M_IS_LZMA(opt->method))
|
||||
opt->method = -1;
|
||||
@@ -625,6 +645,17 @@ static int do_option(int optc, const char *arg)
|
||||
opt->debug.disable_random_id = true;
|
||||
break;
|
||||
|
||||
// mp (meta)
|
||||
case 501:
|
||||
getoptvar(&opt->mp_compress_task, 1, 999999, arg);
|
||||
break;
|
||||
case 502:
|
||||
opt->mp_query_format = true;
|
||||
break;
|
||||
case 503:
|
||||
opt->mp_query_num_tasks = true;
|
||||
break;
|
||||
|
||||
// misc
|
||||
case 512:
|
||||
opt->console = CON_FILE;
|
||||
@@ -641,6 +672,15 @@ static int do_option(int optc, const char *arg)
|
||||
case 519:
|
||||
opt->no_env = true;
|
||||
break;
|
||||
case 526:
|
||||
opt->preserve_mode = false;
|
||||
break;
|
||||
case 527:
|
||||
opt->preserve_ownership = false;
|
||||
break;
|
||||
case 528:
|
||||
opt->preserve_timestamp = false;
|
||||
break;
|
||||
// compression settings
|
||||
case 520: // --small
|
||||
if (opt->small < 0)
|
||||
@@ -853,7 +893,10 @@ static int do_option(int optc, const char *arg)
|
||||
opt->ps1_exe.do_8bit = true;
|
||||
break;
|
||||
case 673:
|
||||
opt->ps1_exe.do_8mb = false;
|
||||
opt->ps1_exe.do_8mib = false;
|
||||
break;
|
||||
case 674:
|
||||
opt->o_unix.unmap_all_pages = true; // val ?
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
@@ -895,7 +938,10 @@ static const struct mfx_option longopts[] =
|
||||
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files
|
||||
{"info", 0, 0, 'i'}, // info mode
|
||||
{"no-env", 0x10, 0, 519}, // no environment var
|
||||
{"no-mode", 0x10, 0, 526}, // do not preserve mode (permissions)
|
||||
{"no-owner", 0x10, 0, 527}, // do not preserve ownership
|
||||
{"no-progress", 0, 0, 516}, // no progress bar
|
||||
{"no-time", 0x10, 0, 528}, // do not preserve timestamp
|
||||
{"output", 0x21, 0, 'o'},
|
||||
{"quiet", 0, 0, 'q'}, // quiet mode
|
||||
{"silent", 0, 0, 'q'}, // quiet mode
|
||||
@@ -1001,6 +1047,7 @@ static const struct mfx_option longopts[] =
|
||||
{"netbsd", 0x10, 0, 668},
|
||||
{"OpenBSD", 0x10, 0, 669},
|
||||
{"openbsd", 0x10, 0, 669},
|
||||
{"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes
|
||||
// watcom/le
|
||||
{"le", 0x10, 0, 620}, // produce LE output
|
||||
// win32/pe
|
||||
@@ -1014,19 +1061,26 @@ static const struct mfx_option longopts[] =
|
||||
{"boot-only", 0x10, 0, 670},
|
||||
{"no-align", 0x10, 0, 671},
|
||||
{"8-bit", 0x10, 0, 672},
|
||||
{"8mib-ram", 0x10, 0, 673},
|
||||
{"8mb-ram", 0x10, 0, 673},
|
||||
|
||||
// mp (meta) options
|
||||
{"mp-compress-task", 0x31, 0, 501},
|
||||
{"mp-query-format", 0x10, 0, 502},
|
||||
{"mp-query-num-tasks", 0x10, 0, 503},
|
||||
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int optc, longind;
|
||||
char buf[256];
|
||||
char shortopts[256];
|
||||
|
||||
prepare_shortopts(buf,"123456789hH?V",longopts),
|
||||
mfx_optind = 0;
|
||||
mfx_opterr = 1;
|
||||
prepare_shortopts(shortopts, "123456789hH?V", longopts),
|
||||
acc_getopt_init(&mfx_getopt, 1, argc, argv);
|
||||
mfx_getopt.progname = progname;
|
||||
mfx_getopt.opterr = handle_opterr;
|
||||
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;
|
||||
while ((optc = mfx_getopt_long(argc, argv, buf, longopts, &longind)) >= 0)
|
||||
while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0)
|
||||
{
|
||||
if (do_option(optc, argv[mfx_optind-1]) != 0)
|
||||
e_usage();
|
||||
@@ -1086,6 +1140,13 @@ static const struct mfx_option longopts[] =
|
||||
// compression settings
|
||||
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression
|
||||
|
||||
// compression method
|
||||
{"nrv2b", 0x10, 0, 702}, // --nrv2b
|
||||
{"nrv2d", 0x10, 0, 704}, // --nrv2d
|
||||
{"nrv2e", 0x10, 0, 705}, // --nrv2e
|
||||
{"lzma", 0x10, 0, 721}, // --lzma
|
||||
{"no-lzma", 0x10, 0, 722}, // (disable all_methods_use_lzma)
|
||||
// compression settings
|
||||
// compression runtime parameters
|
||||
|
||||
// win32/pe
|
||||
@@ -1105,7 +1166,7 @@ static const struct mfx_option longopts[] =
|
||||
int targc;
|
||||
char **targv = NULL;
|
||||
static const char sep[] = " \t";
|
||||
char buf[256];
|
||||
char shortopts[256];
|
||||
|
||||
var = getenv(OPTIONS_VAR);
|
||||
if (var == NULL || !var[0])
|
||||
@@ -1161,10 +1222,11 @@ static const struct mfx_option longopts[] =
|
||||
e_envopt(targv[i]);
|
||||
|
||||
/* handle options */
|
||||
prepare_shortopts(buf,"123456789",longopts);
|
||||
mfx_optind = 0;
|
||||
mfx_opterr = 1;
|
||||
while ((optc = mfx_getopt_long(targc, targv, buf, longopts, &longind)) >= 0)
|
||||
prepare_shortopts(shortopts, "123456789", longopts);
|
||||
acc_getopt_init(&mfx_getopt, 1, targc, targv);
|
||||
mfx_getopt.progname = progname;
|
||||
mfx_getopt.opterr = handle_opterr;
|
||||
while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0)
|
||||
{
|
||||
if (do_option(optc, targv[mfx_optind-1]) != 0)
|
||||
e_envopt(NULL);
|
||||
@@ -1213,8 +1275,8 @@ template <class T> struct TestBELE {
|
||||
static bool test(void)
|
||||
{
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(T)
|
||||
struct test1_t { char a; T b; } __attribute_packed;
|
||||
struct test2_t { char a; T b[3]; } __attribute_packed;
|
||||
__packed_struct(test1_t) char a; T b; __packed_struct_end()
|
||||
__packed_struct(test2_t) char a; T b[3]; __packed_struct_end()
|
||||
test1_t t1[7]; UNUSED(t1); test2_t t2[7]; UNUSED(t2);
|
||||
COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T))
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(test1_t)
|
||||
@@ -1226,7 +1288,11 @@ static bool test(void)
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1)
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1)
|
||||
#endif
|
||||
#if 1 && !defined(xUPX_OFFICIAL_BUILD)
|
||||
#if 1 && (ACC_CC_WATCOMC)
|
||||
test1_t t11; COMPILE_TIME_ASSERT(sizeof(t11.a) <= sizeof(t11.b))
|
||||
test2_t t22; COMPILE_TIME_ASSERT(sizeof(t22.a) <= sizeof(t22.b))
|
||||
#endif
|
||||
#if 1 && !defined(UPX_OFFICIAL_BUILD)
|
||||
T allbits; allbits = 0; allbits -= 1;
|
||||
//++allbits; allbits++; --allbits; allbits--;
|
||||
T v1; v1 = 1; v1 *= 2; v1 -= 1;
|
||||
@@ -1299,27 +1365,40 @@ void upx_sanity_check(void)
|
||||
assert(TestBELE<BE32>::test());
|
||||
assert(TestBELE<BE64>::test());
|
||||
{
|
||||
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
static const unsigned char dd[32]
|
||||
#if 1 && (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__)
|
||||
__attribute__((__aligned__(16)))
|
||||
#endif
|
||||
= { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
0, 0, 0, 0, 0 };
|
||||
const unsigned char *d;
|
||||
const N_BELE_RTP::AbstractPolicy *bele;
|
||||
d = dd + 7;
|
||||
assert(upx_adler32(d, 4) == 0x09f003f7);
|
||||
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
|
||||
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
|
||||
bele = &N_BELE_RTP::be_policy;
|
||||
assert(get_be16(d) == 0xfffe);
|
||||
assert(bele->get16(d) == 0xfffe);
|
||||
assert(get_be16_signed(d) == -2);
|
||||
assert(get_be24(d) == 0xfffefd);
|
||||
assert(bele->get24(d) == 0xfffefd);
|
||||
assert(get_be24_signed(d) == -259);
|
||||
assert(get_be32(d) == 0xfffefdfc);
|
||||
assert(bele->get32(d) == 0xfffefdfc);
|
||||
assert(get_be32_signed(d) == -66052);
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
assert(get_le16(d) == 0xfeff);
|
||||
assert(bele->get16(d) == 0xfeff);
|
||||
assert(get_le16_signed(d) == -257);
|
||||
assert(get_le24(d) == 0xfdfeff);
|
||||
assert(bele->get24(d) == 0xfdfeff);
|
||||
assert(get_le24_signed(d) == -131329);
|
||||
assert(get_le32(d) == 0xfcfdfeff);
|
||||
assert(bele->get32(d) == 0xfcfdfeff);
|
||||
assert(get_le32_signed(d) == -50462977);
|
||||
assert(get_le64_signed(d) == ACC_INT64_C(-506097522914230529));
|
||||
assert(find_be16(d, 2, 0xfffe) == 0);
|
||||
@@ -1340,7 +1419,7 @@ void upx_sanity_check(void)
|
||||
// main entry point
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(WITH_GUI)
|
||||
#if !(WITH_GUI)
|
||||
|
||||
#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)
|
||||
extern "C" { extern long _stksize; long _stksize = 256 * 1024L; }
|
||||
@@ -1390,7 +1469,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
|
||||
set_term(stderr);
|
||||
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
if (ucl_init() != UCL_E_OK)
|
||||
{
|
||||
show_head();
|
||||
@@ -1401,7 +1480,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
e_exit(EXIT_INIT);
|
||||
}
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
if (nrv_init() != NRV_E_OK || NRV_VERSION != nrv_version())
|
||||
{
|
||||
show_head();
|
||||
@@ -1494,7 +1573,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
#endif /* !defined(WITH_GUI) */
|
||||
#endif /* !(WITH_GUI) */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+5
-9
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ static int mcheck_init()
|
||||
if (use_mcheck < 0)
|
||||
{
|
||||
use_mcheck = 1;
|
||||
#if defined(WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
|
||||
#if (WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
|
||||
if (RUNNING_ON_VALGRIND)
|
||||
{
|
||||
//fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n");
|
||||
@@ -192,11 +192,7 @@ void MemBuffer::alloc(unsigned size)
|
||||
assert((int)total > 0);
|
||||
unsigned char *p = (unsigned char *) malloc(total);
|
||||
if (!p)
|
||||
{
|
||||
//throw bad_alloc();
|
||||
throw OutOfMemoryException("out of memory");
|
||||
//exit(1);
|
||||
}
|
||||
throwOutOfMemoryException();
|
||||
b_size = size;
|
||||
if (use_mcheck)
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_MEM_H
|
||||
#define __UPX_MEM_H
|
||||
#define __UPX_MEM_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+548
-353
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ void printClearLine(FILE *f)
|
||||
fflush(stdout); fflush(stderr);
|
||||
if (f == NULL)
|
||||
f = stdout;
|
||||
con_fprintf(f,clear_line_msg);
|
||||
con_fprintf(f, "%s", clear_line_msg);
|
||||
fflush(f);
|
||||
printSetNl(0);
|
||||
}
|
||||
|
||||
@@ -1,706 +0,0 @@
|
||||
/* Getopt for GNU.
|
||||
NOTE: getopt is now part of the C library, so if you don't know what
|
||||
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
|
||||
before changing it!
|
||||
|
||||
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
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, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
|
||||
|
||||
#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
|
||||
long-named option. Because this is not POSIX.2 compliant, it is
|
||||
being phased out. */
|
||||
/* #define GETOPT_COMPAT */
|
||||
#undef GETOPT_COMPAT
|
||||
|
||||
/* This version of `getopt' appears to the caller like standard Unix `getopt'
|
||||
but it behaves differently for the user, since it allows the user
|
||||
to intersperse the options with the other arguments.
|
||||
|
||||
As `getopt' works, it permutes the elements of ARGV so that,
|
||||
when it is done, all the options precede everything else. Thus
|
||||
all application programs are extended to handle flexible argument order.
|
||||
|
||||
Setting the environment variable POSIXLY_CORRECT disables permutation.
|
||||
Then the behavior is completely standard.
|
||||
|
||||
GNU application programs can use a third alternative mode in which
|
||||
they can distinguish the relative order of options and other arguments. */
|
||||
|
||||
#include "mygetopt.h"
|
||||
#define option mfx_option
|
||||
#define optarg mfx_optarg
|
||||
#define optind mfx_optind
|
||||
#define opterr mfx_opterr
|
||||
#define optopt mfx_optopt
|
||||
#undef BAD_OPTION
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
char *optarg = NULL;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
/* XXX 1003.2 says this must be 1 before any call. */
|
||||
int optind = 0;
|
||||
|
||||
/* The next char to be scanned in the option-element
|
||||
in which the last option character we returned was found.
|
||||
This allows us to pick up the scan where we left off.
|
||||
|
||||
If this is zero, or a null string, it means resume the scan
|
||||
by advancing to the next ARGV-element. */
|
||||
|
||||
static char *nextchar;
|
||||
|
||||
/* Callers store zero here to inhibit the error message
|
||||
for unrecognized options. */
|
||||
|
||||
int opterr = 1;
|
||||
|
||||
/* Set to an option character which was unrecognized.
|
||||
This must be initialized on some systems to avoid linking in the
|
||||
system's own getopt implementation. */
|
||||
|
||||
#define BAD_OPTION '\0'
|
||||
int optopt = BAD_OPTION;
|
||||
|
||||
/* Describe how to deal with options that follow non-option ARGV-elements.
|
||||
|
||||
If the caller did not specify anything,
|
||||
the default is REQUIRE_ORDER if the environment variable
|
||||
POSIXLY_CORRECT is defined, PERMUTE otherwise.
|
||||
|
||||
REQUIRE_ORDER means don't recognize them as options;
|
||||
stop option processing when the first non-option is seen.
|
||||
This is what Unix does.
|
||||
This mode of operation is selected by either setting the environment
|
||||
variable POSIXLY_CORRECT, or using `+' as the first character
|
||||
of the list of option characters.
|
||||
|
||||
PERMUTE is the default. We permute the contents of ARGV as we scan,
|
||||
so that eventually all the non-options are at the end. This allows options
|
||||
to be given in any order, even with programs that were not written to
|
||||
expect this.
|
||||
|
||||
RETURN_IN_ORDER is an option available to programs that were written
|
||||
to expect options and other ARGV-elements in any order and that care about
|
||||
the ordering of the two. We describe each non-option ARGV-element
|
||||
as if it were the argument of an option with character code 1.
|
||||
Using `-' as the first character of the list of option characters
|
||||
selects this mode of operation.
|
||||
|
||||
The special argument `--' forces an end of option-scanning regardless
|
||||
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
|
||||
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
|
||||
|
||||
static enum
|
||||
{
|
||||
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
|
||||
} ordering;
|
||||
|
||||
/* Handle permutation of arguments. */
|
||||
|
||||
/* Describe the part of ARGV that contains non-options that have
|
||||
been skipped. `first_nonopt' is the index in ARGV of the first of them;
|
||||
`last_nonopt' is the index after the last of them. */
|
||||
|
||||
static int first_nonopt;
|
||||
static int last_nonopt;
|
||||
|
||||
/* Exchange two adjacent subsequences of ARGV.
|
||||
One subsequence is elements [first_nonopt,last_nonopt)
|
||||
which contains all the non-options that have been skipped so far.
|
||||
The other is elements [last_nonopt,optind), which contains all
|
||||
the options processed since those non-options were skipped.
|
||||
|
||||
`first_nonopt' and `last_nonopt' are relocated so that they describe
|
||||
the new indices of the non-options in ARGV after they are moved.
|
||||
|
||||
To perform the swap, we first reverse the order of all elements. So
|
||||
all options now come before all non options, but they are in the
|
||||
wrong order. So we put back the options and non options in original
|
||||
order by reversing them again. For example:
|
||||
original input: a b c -x -y
|
||||
reverse all: -y -x c b a
|
||||
reverse options: -x -y c b a
|
||||
reverse non options: -x -y a b c
|
||||
*/
|
||||
|
||||
|
||||
static void exchange (char **argv)
|
||||
{
|
||||
char *temp; char **first, **last;
|
||||
|
||||
/* Reverse all the elements [first_nonopt, optind) */
|
||||
first = &argv[first_nonopt];
|
||||
last = &argv[optind-1];
|
||||
while (first < last) {
|
||||
temp = *first; *first = *last; *last = temp; first++; last--;
|
||||
}
|
||||
/* Put back the options in order */
|
||||
first = &argv[first_nonopt];
|
||||
first_nonopt += (optind - last_nonopt);
|
||||
last = &argv[first_nonopt - 1];
|
||||
while (first < last) {
|
||||
temp = *first; *first = *last; *last = temp; first++; last--;
|
||||
}
|
||||
|
||||
/* Put back the non options in order */
|
||||
first = &argv[first_nonopt];
|
||||
last_nonopt = optind;
|
||||
last = &argv[last_nonopt-1];
|
||||
while (first < last) {
|
||||
temp = *first; *first = *last; *last = temp; first++; last--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan elements of ARGV (whose length is ARGC) for option characters
|
||||
given in OPTSTRING.
|
||||
|
||||
If an element of ARGV starts with '-', and is not exactly "-" or "--",
|
||||
then it is an option element. The characters of this element
|
||||
(aside from the initial '-') are option characters. If `getopt'
|
||||
is called repeatedly, it returns successively each of the option characters
|
||||
from each of the option elements.
|
||||
|
||||
If `getopt' finds another option character, it returns that character,
|
||||
updating `optind' and `nextchar' so that the next call to `getopt' can
|
||||
resume the scan with the following option character or ARGV-element.
|
||||
|
||||
If there are no more option characters, `getopt' returns `EOF'.
|
||||
Then `optind' is the index in ARGV of the first ARGV-element
|
||||
that is not an option. (The ARGV-elements have been permuted
|
||||
so that those that are not options now come last.)
|
||||
|
||||
OPTSTRING is a string containing the legitimate option characters.
|
||||
If an option character is seen that is not listed in OPTSTRING,
|
||||
return BAD_OPTION after printing an error message. If you set `opterr' to
|
||||
zero, the error message is suppressed but we still return BAD_OPTION.
|
||||
|
||||
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
|
||||
so the following text in the same ARGV-element, or the text of the following
|
||||
ARGV-element, is returned in `optarg'. Two colons mean an option that
|
||||
wants an optional arg; if there is text in the current ARGV-element,
|
||||
it is returned in `optarg', otherwise `optarg' is set to zero.
|
||||
|
||||
If OPTSTRING starts with `-' or `+', it requests different methods of
|
||||
handling the non-option ARGV-elements.
|
||||
See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
|
||||
|
||||
Long-named options begin with `--' instead of `-'.
|
||||
Their names may be abbreviated as long as the abbreviation is unique
|
||||
or is an exact match for some defined option. If they have an
|
||||
argument, it follows the option name in the same ARGV-element, separated
|
||||
from the option name by a `=', or else the in next ARGV-element.
|
||||
When `getopt' finds a long-named option, it returns 0 if that option's
|
||||
`flag' field is nonzero, the value of the option's `val' field
|
||||
if the `flag' field is zero.
|
||||
|
||||
LONGOPTS is a vector of `struct option' terminated by an
|
||||
element containing a name which is zero.
|
||||
|
||||
LONGIND returns the index in LONGOPT of the long-named option found.
|
||||
It is only valid when a long-named option has been found by the most
|
||||
recent call.
|
||||
|
||||
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
|
||||
long-named options. */
|
||||
|
||||
static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
const struct option *longopts, int *longind,
|
||||
int long_only)
|
||||
{
|
||||
static char empty_string[1];
|
||||
int option_index;
|
||||
|
||||
if (longind != NULL)
|
||||
*longind = -1;
|
||||
|
||||
optarg = 0;
|
||||
|
||||
/* Initialize the internal data when the first call is made.
|
||||
Start processing options with ARGV-element 1 (since ARGV-element 0
|
||||
is the program name); the sequence of previously skipped
|
||||
non-option ARGV-elements is empty. */
|
||||
|
||||
if (optind == 0)
|
||||
{
|
||||
first_nonopt = last_nonopt = optind = 1;
|
||||
|
||||
nextchar = NULL;
|
||||
|
||||
/* Determine how to handle the ordering of options and nonoptions. */
|
||||
|
||||
if (optstring[0] == '-')
|
||||
{
|
||||
ordering = RETURN_IN_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
else if (optstring[0] == '+')
|
||||
{
|
||||
ordering = REQUIRE_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
#if 0
|
||||
else if (getenv ("POSIXLY_CORRECT") != NULL)
|
||||
ordering = REQUIRE_ORDER;
|
||||
#endif
|
||||
else
|
||||
ordering = PERMUTE;
|
||||
}
|
||||
|
||||
if (nextchar == NULL || *nextchar == '\0')
|
||||
{
|
||||
if (ordering == PERMUTE)
|
||||
{
|
||||
/* If we have just processed some options following some non-options,
|
||||
exchange them so that the options come first. */
|
||||
|
||||
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||
exchange (argv);
|
||||
else if (last_nonopt != optind)
|
||||
first_nonopt = optind;
|
||||
|
||||
/* Now skip any additional non-options
|
||||
and extend the range of non-options previously skipped. */
|
||||
|
||||
while (optind < argc
|
||||
&& (argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||
#ifdef GETOPT_COMPAT
|
||||
&& (longopts == NULL
|
||||
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
|
||||
#endif /* GETOPT_COMPAT */
|
||||
)
|
||||
optind++;
|
||||
last_nonopt = optind;
|
||||
}
|
||||
|
||||
/* Special ARGV-element `--' means premature end of options.
|
||||
Skip it like a null option,
|
||||
then exchange with previous non-options as if it were an option,
|
||||
then skip everything else like a non-option. */
|
||||
|
||||
if (optind != argc && !strcmp (argv[optind], "--"))
|
||||
{
|
||||
optind++;
|
||||
|
||||
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||
exchange (argv);
|
||||
else if (first_nonopt == last_nonopt)
|
||||
first_nonopt = optind;
|
||||
last_nonopt = argc;
|
||||
|
||||
optind = argc;
|
||||
}
|
||||
|
||||
/* If we have done all the ARGV-elements, stop the scan
|
||||
and back over any non-options that we skipped and permuted. */
|
||||
|
||||
if (optind == argc)
|
||||
{
|
||||
/* Set the next-arg-index to point at the non-options
|
||||
that we previously skipped, so the caller will digest them. */
|
||||
if (first_nonopt != last_nonopt)
|
||||
optind = first_nonopt;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* If we have come to a non-option and did not permute it,
|
||||
either stop the scan or describe it to the caller and pass it by. */
|
||||
|
||||
if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||
#ifdef GETOPT_COMPAT
|
||||
&& (longopts == NULL
|
||||
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
|
||||
#endif /* GETOPT_COMPAT */
|
||||
)
|
||||
{
|
||||
if (ordering == REQUIRE_ORDER)
|
||||
return EOF;
|
||||
optarg = argv[optind++];
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* We have found another option-ARGV-element.
|
||||
Start decoding its characters. */
|
||||
|
||||
nextchar = (argv[optind] + 1
|
||||
+ (longopts != NULL && argv[optind][1] == '-'));
|
||||
}
|
||||
|
||||
if (longopts != NULL
|
||||
&& ((argv[optind][0] == '-'
|
||||
&& (argv[optind][1] == '-' || long_only))
|
||||
#ifdef GETOPT_COMPAT
|
||||
|| argv[optind][0] == '+'
|
||||
#endif /* GETOPT_COMPAT */
|
||||
))
|
||||
{
|
||||
const struct option *p;
|
||||
char *s = nextchar;
|
||||
int exact = 0;
|
||||
int ambig = 0;
|
||||
const struct option *pfound = NULL;
|
||||
int indfound = 0;
|
||||
int needexact = 0;
|
||||
|
||||
/* allow `--option#value' because you cannout assign a '='
|
||||
to an environment variable under DOS command.com */
|
||||
while (*s && *s != '=' && * s != '#')
|
||||
s++;
|
||||
|
||||
/* Test all options for either exact match or abbreviated matches. */
|
||||
for (p = longopts, option_index = 0; p->name;
|
||||
p++, option_index++)
|
||||
if (!strncmp (p->name, nextchar, (unsigned) (s - nextchar)))
|
||||
{
|
||||
if (p->has_arg & 0x10)
|
||||
needexact = 1;
|
||||
if ((unsigned) (s - nextchar) == strlen (p->name))
|
||||
{
|
||||
/* Exact match found. */
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
exact = 1;
|
||||
break;
|
||||
}
|
||||
else if (pfound == NULL)
|
||||
{
|
||||
/* First nonexact match found. */
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
}
|
||||
else
|
||||
/* Second nonexact match found. */
|
||||
ambig = 1;
|
||||
}
|
||||
|
||||
/* don't allow nonexact longoptions */
|
||||
if (needexact && !exact)
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: unrecognized option `%s'\n",
|
||||
PROGNAME(argv[0]), argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
if (ambig && !exact)
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: option `%s' is ambiguous\n",
|
||||
PROGNAME(argv[0]), argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
|
||||
if (pfound != NULL)
|
||||
{
|
||||
int have_arg = (s[0] != '\0');
|
||||
if (have_arg && (pfound->has_arg & 0xf))
|
||||
have_arg = (s[1] != '\0');
|
||||
option_index = indfound;
|
||||
optind++;
|
||||
if (have_arg)
|
||||
{
|
||||
/* Don't test has_arg with >, because some C compilers don't
|
||||
allow it to be used on enums. */
|
||||
if (pfound->has_arg & 0xf)
|
||||
optarg = s + 1;
|
||||
else
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
if (argv[optind - 1][1] == '-')
|
||||
/* --option */
|
||||
fprintf (stderr,
|
||||
"%s: option `--%s' doesn't allow an argument\n",
|
||||
PROGNAME(argv[0]), pfound->name);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr,
|
||||
"%s: option `%c%s' doesn't allow an argument\n",
|
||||
PROGNAME(argv[0]), argv[optind - 1][0], pfound->name);
|
||||
}
|
||||
nextchar += strlen (nextchar);
|
||||
return BAD_OPTION;
|
||||
}
|
||||
}
|
||||
else if ((pfound->has_arg & 0xf) == 1)
|
||||
{
|
||||
#if 0
|
||||
if (optind < argc)
|
||||
#else
|
||||
if (optind < argc && (pfound->has_arg & 0x20) == 0)
|
||||
#endif
|
||||
optarg = argv[optind++];
|
||||
else
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: option `--%s%s' requires an argument\n",
|
||||
PROGNAME(argv[0]), pfound->name,
|
||||
(pfound->has_arg & 0x20) ? "=" : "");
|
||||
nextchar += strlen (nextchar);
|
||||
return optstring[0] == ':' ? ':' : BAD_OPTION;
|
||||
}
|
||||
}
|
||||
nextchar += strlen (nextchar);
|
||||
if (longind != NULL)
|
||||
*longind = option_index;
|
||||
if (pfound->flag)
|
||||
{
|
||||
*(pfound->flag) = pfound->val;
|
||||
return 0;
|
||||
}
|
||||
return pfound->val;
|
||||
}
|
||||
/* Can't find it as a long option. If this is not getopt_long_only,
|
||||
or the option starts with '--' or is not a valid short
|
||||
option, then it's an error.
|
||||
Otherwise interpret it as a short option. */
|
||||
if (!long_only || argv[optind][1] == '-'
|
||||
#ifdef GETOPT_COMPAT
|
||||
|| argv[optind][0] == '+'
|
||||
#endif /* GETOPT_COMPAT */
|
||||
|| strchr (optstring, *nextchar) == NULL)
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
if (argv[optind][1] == '-')
|
||||
/* --option */
|
||||
fprintf (stderr, "%s: unrecognized option `--%s'\n",
|
||||
PROGNAME(argv[0]), nextchar);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
|
||||
PROGNAME(argv[0]), argv[optind][0], nextchar);
|
||||
}
|
||||
nextchar = empty_string;
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
(void) &ambig; /* UNUSED */
|
||||
}
|
||||
|
||||
/* Look at and handle the next option-character. */
|
||||
|
||||
{
|
||||
char c = *nextchar++;
|
||||
const char *temp = strchr (optstring, c);
|
||||
|
||||
/* Increment `optind' when we start to process its last character. */
|
||||
if (*nextchar == '\0')
|
||||
++optind;
|
||||
|
||||
if (temp == NULL || c == ':')
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
#if 0
|
||||
if (c < 040 || c >= 0177)
|
||||
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
|
||||
PROGNAME(argv[0]), c);
|
||||
else
|
||||
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", PROGNAME(argv[0]), c);
|
||||
#endif
|
||||
}
|
||||
optopt = c;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
if (temp[1] == ':')
|
||||
{
|
||||
if (temp[2] == ':')
|
||||
{
|
||||
/* This is an option that accepts an argument optionally. */
|
||||
if (*nextchar != '\0')
|
||||
{
|
||||
optarg = nextchar;
|
||||
optind++;
|
||||
}
|
||||
else
|
||||
optarg = 0;
|
||||
nextchar = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is an option that requires an argument. */
|
||||
if (*nextchar != '\0')
|
||||
{
|
||||
optarg = nextchar;
|
||||
/* If we end this ARGV-element by taking the rest as an arg,
|
||||
we must advance to the next element now. */
|
||||
optind++;
|
||||
}
|
||||
else if (optind == argc)
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
#if 0
|
||||
fprintf (stderr, "%s: option `-%c' requires an argument\n",
|
||||
PROGNAME(argv[0]), c);
|
||||
#else
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr, "%s: option requires an argument -- %c\n",
|
||||
PROGNAME(argv[0]), c);
|
||||
#endif
|
||||
}
|
||||
optopt = c;
|
||||
if (optstring[0] == ':')
|
||||
c = ':';
|
||||
else
|
||||
c = BAD_OPTION;
|
||||
}
|
||||
else
|
||||
/* We already incremented `optind' once;
|
||||
increment it again when taking next ARGV-elt as argument. */
|
||||
optarg = argv[optind++];
|
||||
nextchar = NULL;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
int mfx_getopt(int argc, char **argv, const char *optstring)
|
||||
{
|
||||
return _getopt_internal (argc, argv, optstring,
|
||||
(const struct option *) 0,
|
||||
(int *) 0,
|
||||
0);
|
||||
}
|
||||
|
||||
int mfx_getopt_long(int argc, char **argv, const char *options,
|
||||
const struct option *long_options, int *opt_index)
|
||||
{
|
||||
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
/* Compile with -DTEST to make an executable for use in testing
|
||||
the above definition of `getopt'. */
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
|
||||
c = getopt (argc, argv, "abc:d:0123456789");
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case BAD_OPTION:
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
|
||||
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, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#ifndef __MFX_GETOPT_H
|
||||
#define __MFX_GETOPT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* extern "C" { */
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *mfx_optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int mfx_optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int mfx_opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int mfx_optopt;
|
||||
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct mfx_option
|
||||
{
|
||||
const char *name;
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
#define mfx_no_argument 0
|
||||
#define mfx_required_argument 1
|
||||
#define mfx_optional_argument 2
|
||||
#define mfx_exact_argument 0x10 /* no abbrev. */
|
||||
|
||||
int mfx_getopt(int argc, char **argv, const char *shortopts);
|
||||
int mfx_getopt_long(int argc, char **argv, const char *shortopts,
|
||||
const struct mfx_option *longopts, int *longind);
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* } */
|
||||
#endif
|
||||
|
||||
#endif /* __MFX_GETOPT_H */
|
||||
+18
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_OPTIONS_H
|
||||
#define __UPX_OPTIONS_H
|
||||
#define __UPX_OPTIONS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -45,8 +45,17 @@ enum {
|
||||
struct options_t {
|
||||
int cmd;
|
||||
|
||||
// mp (meta) options
|
||||
int mp_compress_task;
|
||||
bool mp_query_format;
|
||||
bool mp_query_num_tasks;
|
||||
|
||||
// compression options
|
||||
int method;
|
||||
bool method_lzma_seen;
|
||||
bool method_nrv2b_seen;
|
||||
bool method_nrv2d_seen;
|
||||
bool method_nrv2e_seen;
|
||||
int level; // compression level 1..10
|
||||
int filter; // preferred filter from Packer::getFilters()
|
||||
bool ultra_brute;
|
||||
@@ -65,6 +74,9 @@ struct options_t {
|
||||
bool no_env;
|
||||
bool no_progress;
|
||||
const char *output_name;
|
||||
bool preserve_mode;
|
||||
bool preserve_ownership;
|
||||
bool preserve_timestamp;
|
||||
int small;
|
||||
int verbose;
|
||||
bool to_stdout;
|
||||
@@ -122,7 +134,7 @@ struct options_t {
|
||||
bool boot_only;
|
||||
bool no_align;
|
||||
bool do_8bit;
|
||||
bool do_8mb;
|
||||
bool do_8mib;
|
||||
} ps1_exe;
|
||||
struct {
|
||||
unsigned blocksize;
|
||||
@@ -130,6 +142,7 @@ struct options_t {
|
||||
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
bool use_ptinterp; // use PT_INTERP /opt/upx/run
|
||||
bool make_ptinterp; // make PT_INTERP [ignore current file!]
|
||||
bool unmap_all_pages; // thus /proc/self/exe vanishes
|
||||
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
|
||||
+16
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -148,14 +148,12 @@ Linker* PackArmPe::newLinker() const
|
||||
// import handling
|
||||
**************************************************************************/
|
||||
|
||||
struct import_desc
|
||||
{
|
||||
__packed_struct(import_desc)
|
||||
LE32 oft; // orig first thunk
|
||||
char _[8];
|
||||
LE32 dllname;
|
||||
LE32 iat; // import address table
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
void PackArmPe::processImports(unsigned myimport, unsigned iat_off) // pass 2
|
||||
{
|
||||
@@ -507,6 +505,10 @@ void PackArmPe::buildLoader(const Filter *ft)
|
||||
|
||||
void PackArmPe::pack(OutputFile *fo)
|
||||
{
|
||||
// FIXME: we need to think about better support for --exact
|
||||
if (opt->exact)
|
||||
throwCantPackExact();
|
||||
|
||||
const unsigned objs = ih.objects;
|
||||
isection = new pe_section_t[objs];
|
||||
fi->seek(pe_offset+sizeof(ih),SEEK_SET);
|
||||
@@ -542,10 +544,12 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
else if (opt->win32_pe.strip_relocs < 0)
|
||||
opt->win32_pe.strip_relocs = (ih.imagebase >= 0x10000);
|
||||
if (opt->win32_pe.strip_relocs)
|
||||
{
|
||||
if (ih.imagebase < 0x10000)
|
||||
throwCantPack("--strip-relocs is not allowed when imagebase < 0x10000");
|
||||
else
|
||||
ih.flags |= RELOCS_STRIPPED;
|
||||
}
|
||||
|
||||
if (memcmp(isection[0].name,"UPX",3) == 0)
|
||||
throwAlreadyPackedByUPX();
|
||||
@@ -632,7 +636,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
|
||||
//OutputFile::dump("x1", ibuf, usize);
|
||||
|
||||
// some checks for broken linkers - disable filter if neccessary
|
||||
// some checks for broken linkers - disable filter if necessary
|
||||
bool allow_filter = true;
|
||||
if (ih.codebase == ih.database
|
||||
|| ih.codebase + ih.codesize > ih.imagesize
|
||||
@@ -708,7 +712,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
|
||||
// limit stack size needed for runtime decompression
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 2048, &cconf, filter_strategy,
|
||||
ih.codebase, rvamin, 0, NULL, 0);
|
||||
// info: see buildLoader()
|
||||
@@ -882,6 +886,8 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
oh.codesize = osection[1].vsize;
|
||||
oh.codebase = osection[1].vaddr;
|
||||
oh.headersize = osection[1].rawdataptr;
|
||||
if (rvamin < osection[0].rawdataptr)
|
||||
throwCantPack("object alignment too small");
|
||||
|
||||
if (opt->win32_pe.strip_relocs && !isdll)
|
||||
oh.flags |= RELOCS_STRIPPED;
|
||||
@@ -890,7 +896,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
// set_le32(ibuf + ic,get_le32("UPX "));
|
||||
ibuf.clear(0, oh.filealign);
|
||||
|
||||
info("Image size change: %u -> %u kBytes",
|
||||
info("Image size change: %u -> %u KiB",
|
||||
ih.imagesize / 1024, oh.imagesize / 1024);
|
||||
|
||||
infoHeader("[Writing compressed file]");
|
||||
|
||||
+6
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_ARMPE_H
|
||||
#define __UPX_P_ARMPE_H
|
||||
#define __UPX_P_ARMPE_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// arm/pe
|
||||
|
||||
+5
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
static const
|
||||
#include "stub/i086-dos16.com.h"
|
||||
|
||||
//#define TESTING
|
||||
//#define TESTING 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+7
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_COM_H
|
||||
#define __UPX_P_COM_H
|
||||
#define __UPX_P_COM_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,7 +42,8 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_DOS_COM; }
|
||||
virtual const char *getName() const { return "dos/com"; }
|
||||
virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.com" : "i286-dos16.com"; }
|
||||
//virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.com" : "i286-dos16.com"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i086-dos16.com"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
|
||||
+7
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -76,10 +76,11 @@ const int *PackDjgpp2::getFilters() const
|
||||
|
||||
|
||||
unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range,
|
||||
unsigned upper_limit) const
|
||||
{
|
||||
unsigned o = super::findOverlapOverhead(buf, range, upper_limit);
|
||||
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
||||
o = (o + 0x3ff) &~ 0x1ff;
|
||||
return o;
|
||||
}
|
||||
@@ -302,7 +303,7 @@ void PackDjgpp2::pack(OutputFile *fo)
|
||||
// compress
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
|
||||
// patch coff header #2
|
||||
|
||||
+11
-14
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_DJGPP2_H
|
||||
#define __UPX_P_DJGPP2_H
|
||||
#define __UPX_P_DJGPP2_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
virtual int getVersion() const { return 14; }
|
||||
virtual int getFormat() const { return UPX_F_DJGPP2_COFF; }
|
||||
virtual const char *getName() const { return "djgpp2/coff"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-dos32.djgpp2"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-dos32.djgpp2.coff"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -58,6 +58,7 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
|
||||
virtual unsigned findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range = 0,
|
||||
unsigned upper_limit = ~0u) const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
@@ -65,19 +66,16 @@ protected:
|
||||
|
||||
long coff_offset;
|
||||
|
||||
struct external_scnhdr_t
|
||||
{
|
||||
__packed_struct(external_scnhdr_t)
|
||||
char _[12]; // name, paddr
|
||||
LE32 vaddr;
|
||||
LE32 size;
|
||||
LE32 scnptr;
|
||||
char misc[12]; // relptr, lnnoptr, nreloc, nlnno
|
||||
char __[4]; // flags
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct coff_header_t
|
||||
{
|
||||
__packed_struct(coff_header_t)
|
||||
// ext_file_hdr
|
||||
LE16 f_magic;
|
||||
LE16 f_nscns;
|
||||
@@ -98,8 +96,7 @@ protected:
|
||||
|
||||
// section headers
|
||||
external_scnhdr_t sh[3];
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
coff_header_t coff_hdr;
|
||||
external_scnhdr_t *text,*data,*bss;
|
||||
|
||||
+82
-53
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_ELF_H
|
||||
#define __UPX_P_ELF_H
|
||||
#define __UPX_P_ELF_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -52,8 +52,7 @@ struct ElfITypes
|
||||
|
||||
// The ELF file header. This appears at the start of every ELF file.
|
||||
template <class TElfITypes>
|
||||
struct Ehdr
|
||||
{
|
||||
__packed_struct(Ehdr)
|
||||
typedef typename TElfITypes::Half Half;
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -76,13 +75,11 @@ struct Ehdr
|
||||
|
||||
# define WANT_EHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Dyn
|
||||
{
|
||||
__packed_struct(Dyn)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
@@ -91,13 +88,32 @@ struct Dyn
|
||||
|
||||
# define WANT_DYN_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct External_Note
|
||||
{
|
||||
__packed_struct(Rel)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
Addr r_offset;
|
||||
Xword r_info;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Rela)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
Addr r_offset;
|
||||
Xword r_info;
|
||||
Xword r_addend;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(External_Note)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
|
||||
Word xn_namesz; // includes terminating '\0'
|
||||
@@ -105,8 +121,7 @@ struct External_Note
|
||||
Word xn_type;
|
||||
//char xn_name[N]; // terminate with '\0'
|
||||
//char xn_data[M]; // aligned to 0 mod 4
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf
|
||||
@@ -119,8 +134,7 @@ __attribute_packed;
|
||||
namespace N_Elf32 {
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Phdr
|
||||
{
|
||||
__packed_struct(Phdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
@@ -136,13 +150,11 @@ struct Phdr
|
||||
|
||||
# define WANT_PHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Shdr
|
||||
{
|
||||
__packed_struct(Shdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
@@ -160,13 +172,11 @@ struct Shdr
|
||||
|
||||
# define WANT_SHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Sym
|
||||
{
|
||||
__packed_struct(Sym)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Section Section;
|
||||
@@ -183,9 +193,9 @@ struct Sym
|
||||
|
||||
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
|
||||
static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
|
||||
}
|
||||
__attribute_packed;
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type)
|
||||
{ return (unsigned char) (((bind<<4) + (0xf & type)) & 0xff); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf32
|
||||
@@ -198,8 +208,7 @@ __attribute_packed;
|
||||
namespace N_Elf64 {
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Phdr
|
||||
{
|
||||
__packed_struct(Phdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -216,13 +225,11 @@ struct Phdr
|
||||
|
||||
# define WANT_PHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Shdr
|
||||
{
|
||||
__packed_struct(Shdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -241,13 +248,11 @@ struct Shdr
|
||||
|
||||
# define WANT_SHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Sym
|
||||
{
|
||||
__packed_struct(Sym)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -265,9 +270,9 @@ struct Sym
|
||||
|
||||
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
|
||||
static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
|
||||
}
|
||||
__attribute_packed;
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type)
|
||||
{ return (unsigned char) (((bind<<4) + (0xf & type)) & 0xff); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf64
|
||||
@@ -284,17 +289,19 @@ struct ElfClass_32
|
||||
{
|
||||
typedef TP BeLePolicy;
|
||||
|
||||
// integral types
|
||||
typedef typename TP::U16 U16;
|
||||
typedef typename TP::U32 U32;
|
||||
typedef typename TP::U64 U64;
|
||||
typedef N_Elf::ElfITypes<U16, U32, U32, U32, U32> ElfITypes;
|
||||
// integral types (target endianness)
|
||||
typedef typename TP::U16 TE16;
|
||||
typedef typename TP::U32 TE32;
|
||||
typedef typename TP::U64 TE64;
|
||||
typedef N_Elf::ElfITypes<TE16, TE32, TE32, TE32, TE32> ElfITypes;
|
||||
|
||||
// ELF types
|
||||
typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
|
||||
typedef N_Elf32::Phdr<ElfITypes> Phdr;
|
||||
typedef N_Elf32::Shdr<ElfITypes> Shdr;
|
||||
typedef N_Elf ::Dyn <ElfITypes> Dyn;
|
||||
typedef N_Elf ::Rel <ElfITypes> Rel;
|
||||
typedef N_Elf ::Rela<ElfITypes> Rela;
|
||||
typedef N_Elf32::Sym <ElfITypes> Sym;
|
||||
typedef N_Elf ::External_Note<ElfITypes> External_Note;
|
||||
|
||||
@@ -304,11 +311,15 @@ struct ElfClass_32
|
||||
COMPILE_TIME_ASSERT(sizeof(Phdr) == 32)
|
||||
COMPILE_TIME_ASSERT(sizeof(Shdr) == 40)
|
||||
COMPILE_TIME_ASSERT(sizeof(Dyn) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rel) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rela) == 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(Sym) == 16)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rel)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rela)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
|
||||
}
|
||||
};
|
||||
@@ -319,17 +330,19 @@ struct ElfClass_64
|
||||
{
|
||||
typedef TP BeLePolicy;
|
||||
|
||||
// integral types
|
||||
typedef typename TP::U16 U16;
|
||||
typedef typename TP::U32 U32;
|
||||
typedef typename TP::U64 U64;
|
||||
typedef N_Elf::ElfITypes<U16, U32, U64, U64, U64> ElfITypes;
|
||||
// integral types (target endianness)
|
||||
typedef typename TP::U16 TE16;
|
||||
typedef typename TP::U32 TE32;
|
||||
typedef typename TP::U64 TE64;
|
||||
typedef N_Elf::ElfITypes<TE16, TE32, TE64, TE64, TE64> ElfITypes;
|
||||
|
||||
// ELF types
|
||||
typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
|
||||
typedef N_Elf64::Phdr<ElfITypes> Phdr;
|
||||
typedef N_Elf64::Shdr<ElfITypes> Shdr;
|
||||
typedef N_Elf ::Dyn <ElfITypes> Dyn;
|
||||
typedef N_Elf ::Rel <ElfITypes> Rel;
|
||||
typedef N_Elf ::Rela<ElfITypes> Rela;
|
||||
typedef N_Elf64::Sym <ElfITypes> Sym;
|
||||
typedef N_Elf ::External_Note<ElfITypes> External_Note;
|
||||
|
||||
@@ -339,11 +352,15 @@ struct ElfClass_64
|
||||
COMPILE_TIME_ASSERT(sizeof(Phdr) == 56)
|
||||
COMPILE_TIME_ASSERT(sizeof(Shdr) == 64)
|
||||
COMPILE_TIME_ASSERT(sizeof(Dyn) == 16)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rel) == 16)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rela) == 24)
|
||||
COMPILE_TIME_ASSERT(sizeof(Sym) == 24)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rel)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rela)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
|
||||
}
|
||||
};
|
||||
@@ -368,6 +385,8 @@ typedef ElfClass_Host32::Ehdr Elf32_Ehdr;
|
||||
typedef ElfClass_Host32::Phdr Elf32_Phdr;
|
||||
typedef ElfClass_Host32::Shdr Elf32_Shdr;
|
||||
typedef ElfClass_Host32::Dyn Elf32_Dyn;
|
||||
typedef ElfClass_Host32::Rel Elf32_Rel;
|
||||
typedef ElfClass_Host32::Rela Elf32_Rela;
|
||||
typedef ElfClass_Host32::Sym Elf32_Sym;
|
||||
typedef ElfClass_Host32::External_Note Elf32_External_Note;
|
||||
|
||||
@@ -375,6 +394,8 @@ typedef ElfClass_Host64::Ehdr Elf64_Ehdr;
|
||||
typedef ElfClass_Host64::Phdr Elf64_Phdr;
|
||||
typedef ElfClass_Host64::Shdr Elf64_Shdr;
|
||||
typedef ElfClass_Host64::Dyn Elf64_Dyn;
|
||||
typedef ElfClass_Host64::Rel Elf64_Rel;
|
||||
typedef ElfClass_Host64::Rela Elf64_Rela;
|
||||
typedef ElfClass_Host64::Sym Elf64_Sym;
|
||||
typedef ElfClass_Host64::External_Note Elf64_External_Note;
|
||||
|
||||
@@ -382,6 +403,8 @@ typedef ElfClass_BE32::Ehdr Elf_BE32_Ehdr;
|
||||
typedef ElfClass_BE32::Phdr Elf_BE32_Phdr;
|
||||
typedef ElfClass_BE32::Shdr Elf_BE32_Shdr;
|
||||
typedef ElfClass_BE32::Dyn Elf_BE32_Dyn;
|
||||
typedef ElfClass_BE32::Rel Elf_BE32_Rel;
|
||||
typedef ElfClass_BE32::Rela Elf_BE32_Rela;
|
||||
typedef ElfClass_BE32::Sym Elf_BE32_Sym;
|
||||
typedef ElfClass_BE32::External_Note Elf_BE32_External_Note;
|
||||
|
||||
@@ -389,6 +412,8 @@ typedef ElfClass_BE64::Ehdr Elf_BE64_Ehdr;
|
||||
typedef ElfClass_BE64::Phdr Elf_BE64_Phdr;
|
||||
typedef ElfClass_BE64::Shdr Elf_BE64_Shdr;
|
||||
typedef ElfClass_BE64::Dyn Elf_BE64_Dyn;
|
||||
typedef ElfClass_BE64::Rel Elf_BE64_Rel;
|
||||
typedef ElfClass_BE64::Rela Elf_BE64_Rela;
|
||||
typedef ElfClass_BE64::Sym Elf_BE64_Sym;
|
||||
typedef ElfClass_BE64::External_Note Elf_BE64_External_Note;
|
||||
|
||||
@@ -396,6 +421,8 @@ typedef ElfClass_LE32::Ehdr Elf_LE32_Ehdr;
|
||||
typedef ElfClass_LE32::Phdr Elf_LE32_Phdr;
|
||||
typedef ElfClass_LE32::Shdr Elf_LE32_Shdr;
|
||||
typedef ElfClass_LE32::Dyn Elf_LE32_Dyn;
|
||||
typedef ElfClass_LE32::Rel Elf_LE32_Rel;
|
||||
typedef ElfClass_LE32::Rela Elf_LE32_Rela;
|
||||
typedef ElfClass_LE32::Sym Elf_LE32_Sym;
|
||||
typedef ElfClass_LE32::External_Note Elf_LE32_External_Note;
|
||||
|
||||
@@ -403,6 +430,8 @@ typedef ElfClass_LE64::Ehdr Elf_LE64_Ehdr;
|
||||
typedef ElfClass_LE64::Phdr Elf_LE64_Phdr;
|
||||
typedef ElfClass_LE64::Shdr Elf_LE64_Shdr;
|
||||
typedef ElfClass_LE64::Dyn Elf_LE64_Dyn;
|
||||
typedef ElfClass_LE64::Rel Elf_LE64_Rel;
|
||||
typedef ElfClass_LE64::Rela Elf_LE64_Rela;
|
||||
typedef ElfClass_LE64::Sym Elf_LE64_Sym;
|
||||
typedef ElfClass_LE64::External_Note Elf_LE64_External_Note;
|
||||
|
||||
|
||||
+22
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,15 +21,15 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Use the preprocessor to work around
|
||||
// - that the types embedding these enums have to be PODs, and
|
||||
// deriving from an empty base class (which is the ususal C++ way
|
||||
// deriving from an empty base class (which is the usual C++ way
|
||||
// of "importing" enums) does not yield a POD any more
|
||||
// - that older compilers do not correctly perform EBCO
|
||||
**************************************************************************/
|
||||
@@ -68,10 +68,13 @@
|
||||
};
|
||||
enum { // e_machine
|
||||
EM_386 = 3,
|
||||
EM_MIPS = 8,
|
||||
EM_MIPS_RS3_LE = 10, /* MIPS R3000 little-endian */
|
||||
EM_PPC = 20,
|
||||
EM_PPC64 = 21,
|
||||
EM_ARM = 40,
|
||||
EM_X86_64 = 62
|
||||
|
||||
};
|
||||
enum { // e_version
|
||||
EV_CURRENT = 1
|
||||
@@ -138,10 +141,23 @@
|
||||
enum { // d_tag
|
||||
DT_NULL = 0, /* End flag */
|
||||
DT_NEEDED = 1, /* Name of needed library */
|
||||
DT_PLTRELSZ = 2, /* Size in bytes of PLT relocs */
|
||||
DT_HASH = 4, /* Hash table of symbol names */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_SYMTAB = 6, /* Symbol table */
|
||||
DT_STRSZ = 10 /* Sizeof string table */
|
||||
DT_RELA = 7, /* Relocations which do contain an addend */
|
||||
DT_RELAENT = 9, /* Size of one RELA relocation */
|
||||
DT_INIT = 12, /* Address of init function */
|
||||
DT_REL = 17, /* Relocations which contain no addend */
|
||||
DT_RELENT = 19, /* Size of one Rel relocation */
|
||||
DT_STRSZ = 10, /* Sizeof string table */
|
||||
DT_PLTREL = 20, /* Type of reloc in PLT */
|
||||
DT_JMPREL = 23, /* Address of PLT relocs */
|
||||
DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */
|
||||
DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */
|
||||
DT_VERSYM = 0x6ffffff0, /* version[] for each symbol */
|
||||
DT_VERDEF = 0x6ffffffc, /* version definitions[] */
|
||||
DT_VERNEEDED= 0x6ffffffe /* version[] needed */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+210
-66
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -51,26 +51,22 @@ PackExe::PackExe(InputFile *f) :
|
||||
super(f)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32);
|
||||
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(exe_header_t)
|
||||
ih_exesize = ih_imagesize = ih_overlay = 0;
|
||||
stack_for_lzma = 0;
|
||||
use_clear_dirty_stack = false;
|
||||
}
|
||||
|
||||
|
||||
const int *PackExe::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
static const int m_all[] = { M_NRV2B_8, M_NRV2D_8, M_NRV2E_8, M_END };
|
||||
static const int m_nrv2b[] = { M_NRV2B_8, M_END };
|
||||
static const int m_nrv2d[] = { M_NRV2D_8, M_END };
|
||||
static const int m_nrv2e[] = { M_NRV2E_8, M_END };
|
||||
|
||||
if (method == M_ALL) return m_all;
|
||||
if (M_IS_NRV2B(method)) return m_nrv2b;
|
||||
if (M_IS_NRV2D(method)) return m_nrv2d;
|
||||
if (M_IS_NRV2E(method)) return m_nrv2e;
|
||||
bool small = ih_imagesize <= 256*1024;
|
||||
if (level == 1 || small)
|
||||
return m_nrv2b;
|
||||
return m_nrv2e;
|
||||
// disable lzma for "--brute" unless explicitly given "--lzma"
|
||||
// WARNING: this side effect persists for later files!
|
||||
if (opt->all_methods_use_lzma && !opt->method_lzma_seen)
|
||||
opt->all_methods_use_lzma = false;
|
||||
return Packer::getDefaultCompressionMethods_8(method, level, small);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +81,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
||||
#define oh (*eh)
|
||||
// fill new exe header
|
||||
int flag = 0;
|
||||
if (!opt->dos_exe.no_reloc)
|
||||
if (!opt->dos_exe.no_reloc && !M_IS_LZMA(ph.method))
|
||||
flag |= USEJUMP;
|
||||
if (ih.relocs == 0)
|
||||
flag |= NORELOC;
|
||||
@@ -94,7 +90,16 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
||||
oh.ident = 'M' + 'Z' * 256;
|
||||
oh.headsize16 = 2;
|
||||
|
||||
oh.sp = ih.sp > 0x200 ? (unsigned) ih.sp : 0x200;
|
||||
unsigned minsp = 0x200;
|
||||
if (M_IS_LZMA(ph.method))
|
||||
minsp = stack_for_lzma;
|
||||
minsp = ALIGN_UP(minsp, 16u);
|
||||
assert(minsp < 0xff00);
|
||||
if (oh.sp > minsp)
|
||||
minsp = oh.sp;
|
||||
if (minsp < 0xff00 - 2)
|
||||
minsp = ALIGN_UP(minsp, 2u);
|
||||
oh.sp = minsp;
|
||||
|
||||
unsigned destpara = (ph.u_len + ph.overlap_overhead - ph.c_len + 31) / 16;
|
||||
oh.ss = ph.c_len/16 + destpara;
|
||||
@@ -106,27 +111,118 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
||||
|
||||
if (oh.ss != ih.ss)
|
||||
flag |= SS;
|
||||
if (oh.sp != ih.sp)
|
||||
if (oh.sp != ih.sp || M_IS_LZMA(ph.method))
|
||||
flag |= SP;
|
||||
return flag;
|
||||
#undef oh
|
||||
}
|
||||
|
||||
void PackExe::addLoaderEpilogue(int flag)
|
||||
{
|
||||
addLoader("EXEMAIN5", NULL);
|
||||
if (relocsize)
|
||||
addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS",
|
||||
"EXERELO1",
|
||||
has_9a ? "EXEREL9A" : "",
|
||||
"EXERELO2",
|
||||
ih_exesize > 0xFE00 ? "EXEREBIG" : "",
|
||||
"EXERELO3",
|
||||
NULL
|
||||
);
|
||||
addLoader("EXEMAIN8",
|
||||
device_driver ? "DEVICEEND" : "",
|
||||
(flag & SS) ? "EXESTACK" : "",
|
||||
(flag & SP) ? "EXESTASP" : "",
|
||||
(flag & USEJUMP) ? "EXEJUMPF" : "",
|
||||
NULL
|
||||
);
|
||||
if (!(flag & USEJUMP))
|
||||
addLoader(ih.cs ? "EXERCSPO" : "",
|
||||
"EXERETIP",
|
||||
NULL
|
||||
);
|
||||
|
||||
linker->defineSymbol("original_cs", ih.cs);
|
||||
linker->defineSymbol("original_ip", ih.ip);
|
||||
linker->defineSymbol("original_sp", ih.sp);
|
||||
linker->defineSymbol("original_ss", ih.ss);
|
||||
linker->defineSymbol("reloc_size",
|
||||
(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff)
|
||||
>= relocsize ? 0 : MAXRELOCS) - relocsize);
|
||||
}
|
||||
|
||||
void PackExe::buildLoader(const Filter *)
|
||||
{
|
||||
struct exe_header_t tmp_oh;
|
||||
int flag = fillExeHeader(&tmp_oh);
|
||||
// get flag
|
||||
exe_header_t dummy_oh;
|
||||
int flag = fillExeHeader(&dummy_oh);
|
||||
|
||||
// prepare loader
|
||||
initLoader(stub_i086_dos16_exe, sizeof(stub_i086_dos16_exe));
|
||||
if (device_driver)
|
||||
addLoader("DEVICEENTRY", NULL);
|
||||
|
||||
if (M_IS_LZMA(ph.method))
|
||||
{
|
||||
addLoader("LZMA_DEC00",
|
||||
opt->small ? "LZMA_DEC10" : "LZMA_DEC20",
|
||||
"LZMA_DEC30",
|
||||
use_clear_dirty_stack ? "LZMA_DEC31" : "",
|
||||
"LZMA_DEC32",
|
||||
ph.u_len > 0xffff ? "LZMA_DEC33" : "",
|
||||
NULL
|
||||
);
|
||||
|
||||
addLoaderEpilogue(flag);
|
||||
defineDecompressorSymbols();
|
||||
const unsigned lsize0 = getLoaderSize();
|
||||
|
||||
// Lzma decompression code starts at ss:0x10, and its size is
|
||||
// lsize bytes. It also needs getDecompressorWrkmemSize() bytes
|
||||
// during uncompression. It also uses some stack, so 0x100
|
||||
// more bytes are allocated
|
||||
stack_for_lzma = 0x10 + lsize0 + getDecompressorWrkmemSize() + 0x100;
|
||||
stack_for_lzma = ALIGN_UP(stack_for_lzma, 16u);
|
||||
|
||||
unsigned clear_dirty_stack_low = 0x10 + lsize0;
|
||||
clear_dirty_stack_low = ALIGN_UP(clear_dirty_stack_low, 2u);
|
||||
if (use_clear_dirty_stack)
|
||||
linker->defineSymbol("clear_dirty_stack_low", clear_dirty_stack_low);
|
||||
|
||||
relocateLoader();
|
||||
const unsigned lsize = getLoaderSize();
|
||||
assert(lsize0 == lsize);
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
|
||||
MemBuffer compressed_lzma;
|
||||
compressed_lzma.allocForCompression(lsize);
|
||||
unsigned c_len_lzma = MemBuffer::getSizeForCompression(lsize);
|
||||
int r = upx_compress(loader, lsize, compressed_lzma, &c_len_lzma,
|
||||
NULL, M_NRV2B_LE16, 9, NULL, NULL);
|
||||
assert(r == UPX_E_OK); assert(c_len_lzma < lsize);
|
||||
|
||||
info("lzma+relocator code compressed: %u -> %u", lsize, c_len_lzma);
|
||||
// reinit the loader
|
||||
initLoader(stub_i086_dos16_exe, sizeof(stub_i086_dos16_exe));
|
||||
// prepare loader
|
||||
if (device_driver)
|
||||
addLoader("DEVICEENTRY,LZMADEVICE,DEVICEENTRY2", NULL);
|
||||
|
||||
linker->addSection("COMPRESSED_LZMA", compressed_lzma, c_len_lzma, 0);
|
||||
addLoader("LZMAENTRY,NRV2B160,NRVDDONE,NRVDECO1,NRVGTD00,NRVDECO2",
|
||||
NULL);
|
||||
|
||||
}
|
||||
else if (device_driver)
|
||||
addLoader("DEVICEENTRY,DEVICEENTRY2", NULL);
|
||||
|
||||
addLoader("EXEENTRY",
|
||||
device_driver ? "DEVICESUB" : "EXESUB",
|
||||
M_IS_LZMA(ph.method) && device_driver ? "LONGSUB" : "SHORTSUB",
|
||||
"JNCDOCOPY",
|
||||
relocsize ? "EXERELPU" : "",
|
||||
"EXEMAIN4,+G5DXXXX,UPX1HEAD,EXECUTPO",
|
||||
"EXEMAIN4",
|
||||
M_IS_LZMA(ph.method) ? "" : "EXEMAIN4B",
|
||||
"EXEMAIN4C",
|
||||
M_IS_LZMA(ph.method) ? "COMPRESSED_LZMA_START,COMPRESSED_LZMA" : "",
|
||||
"+G5DXXXX,UPX1HEAD,EXECUTPO",
|
||||
NULL
|
||||
);
|
||||
if (ph.method == M_NRV2B_8)
|
||||
@@ -165,30 +261,12 @@ void PackExe::buildLoader(const Filter *)
|
||||
"NRV2EEX9",
|
||||
NULL
|
||||
);
|
||||
else if M_IS_LZMA(ph.method)
|
||||
return;
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
addLoader("EXEMAIN5", NULL);
|
||||
if (relocsize)
|
||||
addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS",
|
||||
"EXERELO1",
|
||||
has_9a ? "EXEREL9A" : "",
|
||||
"EXERELO2",
|
||||
ih_exesize > 0xFE00 ? "EXEREBIG" : "",
|
||||
"EXERELO3",
|
||||
NULL
|
||||
);
|
||||
addLoader("EXEMAIN8",
|
||||
device_driver ? "DEVICEEND" : "",
|
||||
(flag & SS) ? "EXESTACK" : "",
|
||||
(flag & SP) ? "EXESTASP" : "",
|
||||
(flag & USEJUMP) ? "EXEJUMPF" : "",
|
||||
NULL
|
||||
);
|
||||
if (!(flag & USEJUMP))
|
||||
addLoader(ih.cs ? "EXERCSPO" : "",
|
||||
"EXERETIP",
|
||||
NULL
|
||||
);
|
||||
|
||||
addLoaderEpilogue(flag);
|
||||
}
|
||||
|
||||
|
||||
@@ -324,7 +402,7 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
|
||||
break;
|
||||
}
|
||||
unsigned offs = addr - es*16;
|
||||
if (offs >= 3 && b[es*16 + offs-3] == 0x9a)
|
||||
if (offs >= 3 && b[es*16 + offs-3] == 0x9a && offs > di + 3)
|
||||
{
|
||||
for (t = di; t < offs-3; t++)
|
||||
if (b[es*16+t] == 0x9a && get_le16(b+es*16+t+3) <= seg_high)
|
||||
@@ -401,7 +479,7 @@ void PackExe::pack(OutputFile *fo)
|
||||
for (ic = 0; ic < ih.relocs; ic++)
|
||||
{
|
||||
unsigned jc = get_le32(wr+4*ic);
|
||||
set_le32(wr+4*ic, (jc>>16)*16+(jc&0xffff));
|
||||
set_le32(wr+4*ic, ((jc>>16)*16+(jc&0xffff)) & 0xfffff);
|
||||
}
|
||||
qsort(wr,ih.relocs,4,le32_compare);
|
||||
relocsize = optimize_relocs(ibuf, ih_imagesize, wr, ih.relocs, w, &has_9a);
|
||||
@@ -429,11 +507,14 @@ void PackExe::pack(OutputFile *fo)
|
||||
// compress (max_match = 8192)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = MAXMATCH;
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 32, &cconf);
|
||||
if (ph.max_run_found + ph.max_match_found > 0x8000)
|
||||
throwCantPack("decompressor limit exceeded, send a bugreport");
|
||||
|
||||
#ifdef TESTING
|
||||
if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
|
||||
if (ph.max_run_found + ph.max_match_found > 0x8000)
|
||||
throwCantPack("decompressor limit exceeded, send a bugreport");
|
||||
|
||||
#if TESTING
|
||||
if (opt->debug.debug_level)
|
||||
{
|
||||
printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len);
|
||||
@@ -497,15 +578,13 @@ void PackExe::pack(OutputFile *fo)
|
||||
}
|
||||
extra_info[eisize++] = (unsigned char) flag;
|
||||
|
||||
linker->defineSymbol("original_cs", ih.cs);
|
||||
linker->defineSymbol("original_ip", ih.ip);
|
||||
linker->defineSymbol("original_sp", ih.sp);
|
||||
linker->defineSymbol("original_ss", ih.ss);
|
||||
linker->defineSymbol("reloc_size",
|
||||
(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff)
|
||||
>= relocsize ? 0 : MAXRELOCS) - relocsize);
|
||||
linker->defineSymbol("bx_magic", 0x7FFF + 0x10 * ((packedsize & 15) + 1));
|
||||
linker->defineSymbol("decompressor_entry", (packedsize & 15) + 1);
|
||||
if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
|
||||
linker->defineSymbol("bx_magic", 0x7FFF + 0x10 * ((packedsize & 15) + 1));
|
||||
|
||||
unsigned decompressor_entry = 1 + (packedsize & 15);
|
||||
if (M_IS_LZMA(ph.method))
|
||||
decompressor_entry = 0x10;
|
||||
linker->defineSymbol("decompressor_entry", decompressor_entry);
|
||||
|
||||
// patch loader
|
||||
if (flag & USEJUMP)
|
||||
@@ -541,8 +620,10 @@ void PackExe::pack(OutputFile *fo)
|
||||
oh.m512 = outputlen & 511;
|
||||
oh.p512 = (outputlen + 511) >> 9;
|
||||
|
||||
oh.ip = device_driver ? getLoaderSection("EXEENTRY") - 2 : 0;
|
||||
const char *exeentry = M_IS_LZMA(ph.method) ? "LZMAENTRY" : "EXEENTRY";
|
||||
oh.ip = device_driver ? getLoaderSection(exeentry) - 2 : 0;
|
||||
|
||||
defineDecompressorSymbols();
|
||||
relocateLoader();
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
patchPackHeader(loader,e_len);
|
||||
@@ -550,7 +631,7 @@ void PackExe::pack(OutputFile *fo)
|
||||
//fprintf(stderr,"\ne_len=%x d_len=%x c_len=%x oo=%x ulen=%x destp=%x copys=%x images=%x",e_len,d_len,packedsize,ph.overlap_overhead,ph.u_len,destpara,copysize,ih_imagesize);
|
||||
|
||||
// write header + write loader + compressed file
|
||||
#ifdef TESTING
|
||||
#if TESTING
|
||||
if (opt->debug.debug_level)
|
||||
printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len);
|
||||
#endif
|
||||
@@ -591,7 +672,7 @@ int PackExe::canUnpack()
|
||||
return false;
|
||||
const off_t off = ih.headsize16 * 16;
|
||||
fi->seek(off, SEEK_SET);
|
||||
bool b = readPackHeader(256);
|
||||
bool b = readPackHeader(4096);
|
||||
return b && (off + (off_t) ph.c_len <= file_size);
|
||||
}
|
||||
|
||||
@@ -726,6 +807,69 @@ Linker* PackExe::newLinker() const
|
||||
return new ElfLinkerX86();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
memory layout at decompression time
|
||||
===================================
|
||||
|
||||
normal exe
|
||||
----------
|
||||
|
||||
a, at load time
|
||||
|
||||
(e - copying code, C - compressed data, d - decompressor+relocator,
|
||||
x - not specified, U - uncompressed code+data, R uncompressed relocation)
|
||||
|
||||
eeCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCdddd
|
||||
^ CS:0 ^ SS:0
|
||||
|
||||
b, after copying
|
||||
|
||||
xxxxxxxxxxxxxxxCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCdddd
|
||||
^ES:DI=0 ^ DS:SI=0 ^ CS=SS, IP in range 0..0xf
|
||||
|
||||
c, after uncompression
|
||||
|
||||
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURRdddd
|
||||
^ ES:DI
|
||||
|
||||
device driver
|
||||
-------------
|
||||
|
||||
the file has 2 entry points, CS:0 in device driver mode, and
|
||||
CS:exe_as_device_entry in normal mode. the code in section DEVICEENTRY
|
||||
sets up the same environment for section EXEENTRY, as it would see in normal
|
||||
execution mode.
|
||||
|
||||
lzma uncompression for normal exes
|
||||
----------------------------------
|
||||
|
||||
(n - nrv2b uncompressor, l - nrv2b compressed lzma + relocator code)
|
||||
|
||||
a, at load time
|
||||
|
||||
nneelllCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
|
||||
^ CS:0 ^ SS:0
|
||||
|
||||
b, after nrv2b
|
||||
|
||||
nneelllCCCCCCCCCCCCCCCCCCCCCCCCC dddd
|
||||
^ CS:0 ^ SS:0x10
|
||||
|
||||
after this, normal ee code runs
|
||||
|
||||
lzma + device driver
|
||||
--------------------
|
||||
|
||||
(D - device driver adapter)
|
||||
|
||||
a, at load time
|
||||
|
||||
DDnneelllCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
|
||||
+13
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_EXE_H
|
||||
#define __UPX_P_EXE_H
|
||||
#define __UPX_P_EXE_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,7 +42,8 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_DOS_EXE; }
|
||||
virtual const char *getName() const { return "dos/exe"; }
|
||||
virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.exe" : "i286-dos16.exe"; }
|
||||
//virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.exe" : "i286-dos16.exe"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i086-dos16.exe"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -71,9 +72,9 @@ protected:
|
||||
virtual int fillExeHeader(struct exe_header_t *) const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
void addLoaderEpilogue(int flag);
|
||||
|
||||
struct exe_header_t
|
||||
{
|
||||
__packed_struct(exe_header_t)
|
||||
LE16 ident;
|
||||
LE16 m512;
|
||||
LE16 p512;
|
||||
@@ -89,8 +90,7 @@ protected:
|
||||
LE16 relocoffs;
|
||||
char __[2]; // overlnum
|
||||
LE32 firstreloc;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
exe_header_t ih, oh;
|
||||
|
||||
@@ -110,6 +110,9 @@ protected:
|
||||
MINMEM = 16,
|
||||
MAXMEM = 32
|
||||
};
|
||||
|
||||
unsigned stack_for_lzma; // stack size required for lzma
|
||||
bool use_clear_dirty_stack;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+1462
-507
File diff suppressed because it is too large
Load Diff
+122
-56
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_ELF_H //{
|
||||
#define __UPX_P_LX_ELF_H
|
||||
#define __UPX_P_LX_ELF_H 1
|
||||
|
||||
|
||||
class PackLinuxElf : public PackUnix
|
||||
@@ -61,15 +61,26 @@ protected:
|
||||
) = 0;
|
||||
virtual void defineSymbols(Filter const *);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
virtual void unpack(OutputFile *fo) = 0;
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const = 0;
|
||||
virtual void const *elf_find_dynamic(unsigned) const = 0;
|
||||
virtual acc_uint64l_t elf_unsigned_dynamic(unsigned) const = 0;
|
||||
|
||||
protected:
|
||||
unsigned e_phnum; /* Program header table entry count */
|
||||
char *file_image; // if ET_DYN investigation
|
||||
char const *dynstr; // from DT_STRTAB
|
||||
|
||||
unsigned sz_phdrs; // sizeof Phdr[]
|
||||
unsigned sz_elf_hdrs; // all Elf headers
|
||||
unsigned sz_pack2; // after pack2(), before loader
|
||||
unsigned lg2_page; // log2(PAGE_SIZE)
|
||||
unsigned page_size; // 1u<<lg2_page
|
||||
unsigned xct_off; // shared library: file offset of SHT_EXECINSTR
|
||||
unsigned hatch_off; // file offset of escape hatch
|
||||
acc_uint64l_t load_va; // PT_LOAD[0].p_vaddr
|
||||
acc_uint64l_t xct_va; // minimum SHT_EXECINSTR virtual address
|
||||
|
||||
unsigned short e_machine;
|
||||
unsigned char ei_class;
|
||||
@@ -119,38 +130,48 @@ protected:
|
||||
virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const;
|
||||
|
||||
static unsigned elf_hash(char const *) /*const*/;
|
||||
virtual void const *elf_find_dynamic(unsigned) const;
|
||||
static unsigned gnu_hash(char const *) /*const*/;
|
||||
virtual Elf32_Sym const *elf_lookup(char const *) const;
|
||||
virtual unsigned elf_get_offset_from_address(unsigned) const;
|
||||
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const;
|
||||
Elf32_Shdr const *elf_find_section_name(char const *) const;
|
||||
Elf32_Shdr const *elf_find_section_type(unsigned) const;
|
||||
void const *elf_find_dynamic(unsigned) const;
|
||||
acc_uint64l_t elf_unsigned_dynamic(unsigned) const;
|
||||
|
||||
protected:
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // for input file
|
||||
Elf32_Shdr const *shdri; // from input file
|
||||
unsigned page_mask; // AND clears the offset-within-page
|
||||
|
||||
Elf32_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
unsigned int const *gashtab; // from DT_GNU_HASH
|
||||
Elf32_Sym const *dynsym; // from DT_SYMTAB
|
||||
char const *shstrtab; // via Elf32_Shdr
|
||||
int n_elf_shnum; // via e_shnum
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf32_Shdr const *sec_strndx;
|
||||
Elf32_Shdr const *sec_dynsym;
|
||||
Elf32_Shdr const *sec_dynstr;
|
||||
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
@@ -208,30 +229,46 @@ protected:
|
||||
virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
|
||||
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const;
|
||||
Elf64_Shdr const *elf_find_section_name(char const *) const;
|
||||
Elf64_Shdr const *elf_find_section_type(unsigned) const;
|
||||
void const *elf_find_dynamic(unsigned) const;
|
||||
acc_uint64l_t elf_unsigned_dynamic(unsigned) const;
|
||||
|
||||
protected:
|
||||
Elf64_Ehdr ehdri; // from input file
|
||||
Elf64_Phdr *phdri; // for input file
|
||||
Elf64_Shdr const *shdri; // from input file
|
||||
acc_uint64l_t page_mask; // AND clears the offset-within-page
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf64_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
unsigned int const *gashtab; // from DT_GNU_HASH
|
||||
Elf64_Sym const *dynsym; // from DT_SYMTAB
|
||||
char const *shstrtab; // via Elf64_Shdr
|
||||
int n_elf_shnum; // via e_shnum
|
||||
|
||||
Elf64_Shdr const *sec_strndx;
|
||||
Elf64_Shdr const *sec_dynsym;
|
||||
Elf64_Shdr const *sec_dynstr;
|
||||
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
@@ -249,44 +286,33 @@ class PackLinuxElf32Be : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::be_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
class PackLinuxElf32Le : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
PackLinuxElf32Le(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
class PackLinuxElf64Le : public PackLinuxElf64
|
||||
{
|
||||
typedef PackLinuxElf64 super;
|
||||
protected:
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf64amd
|
||||
**************************************************************************/
|
||||
@@ -310,6 +336,7 @@ protected:
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf32ppc
|
||||
**************************************************************************/
|
||||
@@ -330,6 +357,7 @@ protected:
|
||||
virtual Linker* newLinker() const;
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf386
|
||||
**************************************************************************/
|
||||
@@ -345,8 +373,6 @@ public:
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
|
||||
@@ -406,6 +432,7 @@ protected:
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elfarm
|
||||
**************************************************************************/
|
||||
@@ -416,8 +443,8 @@ class PackLinuxElf32armLe : public PackLinuxElf32Le
|
||||
public:
|
||||
PackLinuxElf32armLe(InputFile *f);
|
||||
virtual ~PackLinuxElf32armLe();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMLE; }
|
||||
virtual const char *getName() const { return "linux/armLE"; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMEL; }
|
||||
virtual const char *getName() const { return "linux/armel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "arm-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -436,8 +463,8 @@ class PackLinuxElf32armBe : public PackLinuxElf32Be
|
||||
public:
|
||||
PackLinuxElf32armBe(InputFile *f);
|
||||
virtual ~PackLinuxElf32armBe();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMBE; }
|
||||
virtual const char *getName() const { return "linux/armBE"; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMEB; }
|
||||
virtual const char *getName() const { return "linux/armeb"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "armeb-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -450,6 +477,45 @@ protected:
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
class PackLinuxElf32mipseb : public PackLinuxElf32Be
|
||||
{
|
||||
typedef PackLinuxElf32Be super;
|
||||
public:
|
||||
PackLinuxElf32mipseb(InputFile *f);
|
||||
virtual ~PackLinuxElf32mipseb();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_MIPSEB; }
|
||||
virtual const char *getName() const { return "linux/mipseb"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "mips-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
class PackLinuxElf32mipsel : public PackLinuxElf32Le
|
||||
{
|
||||
typedef PackLinuxElf32Le super;
|
||||
public:
|
||||
PackLinuxElf32mipsel(InputFile *f);
|
||||
virtual ~PackLinuxElf32mipsel();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_MIPSEL; }
|
||||
virtual const char *getName() const { return "linux/mipsel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "mipsel-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
|
||||
#endif /*} already included */
|
||||
|
||||
|
||||
|
||||
+20
-17
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2001-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2001-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -132,8 +132,8 @@ PackLinuxI386::generateElfHdr(
|
||||
unsigned const brka
|
||||
)
|
||||
{
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout;
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout;
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)(void *)&elfout;
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)(void *)&elfout;
|
||||
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
|
||||
|
||||
assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
|
||||
@@ -526,28 +526,31 @@ bool PackLinuxI386::canPack()
|
||||
ei_osabi = osabi0; // Proudly declares its osabi in Ehdr.
|
||||
break;
|
||||
default:
|
||||
unsigned const e_phnum = get_native16(&ehdr.e_phnum);
|
||||
unsigned const e_phnum = get_te16(&ehdr.e_phnum);
|
||||
if (e_phnum<=(512/sizeof(Elf32_Phdr))) {
|
||||
char buf2[512];
|
||||
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(buf2, sizeof(buf2));
|
||||
union {
|
||||
unsigned char buf2[512];
|
||||
//Elf32_Phdr phdr;
|
||||
} u;
|
||||
fi->seek(get_te32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(u.buf2, sizeof(u.buf2));
|
||||
fi->seek(0, SEEK_SET);
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr const *)buf2;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *) u.buf2;
|
||||
for (unsigned j=0; j < e_phnum; ++phdr, ++j) {
|
||||
if (phdr->PT_NOTE == get_native32(&phdr->p_type)) {
|
||||
unsigned const offset = get_native32(&phdr->p_offset);
|
||||
if (phdr->PT_NOTE == get_te32(&phdr->p_type)) {
|
||||
unsigned const offset = get_te32(&phdr->p_offset);
|
||||
struct Elf32_Note note; memset(¬e, 0, sizeof(note));
|
||||
fi->seek(offset, SEEK_SET);
|
||||
fi->readx(¬e, sizeof(note));
|
||||
fi->seek(0, SEEK_SET);
|
||||
if (4==get_native32(¬e.descsz)
|
||||
&& 1==get_native32(¬e.type)
|
||||
if (4==get_te32(¬e.descsz)
|
||||
&& 1==get_te32(¬e.type)
|
||||
&& 0==note.end ) {
|
||||
if (0==strcmp("NetBSD", (char const *)¬e.text)) {
|
||||
if (0==strcmp("NetBSD", (char const *)note.text)) {
|
||||
ei_osabi = Elf32_Ehdr::ELFOSABI_NETBSD;
|
||||
break;
|
||||
}
|
||||
if (0==strcmp("OpenBSD", (char const *)¬e.text)) {
|
||||
if (0==strcmp("OpenBSD", (char const *)note.text)) {
|
||||
ei_osabi = Elf32_Ehdr::ELFOSABI_OPENBSD;
|
||||
break;
|
||||
}
|
||||
|
||||
+11
-14
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_EXC_H
|
||||
#define __UPX_P_LX_EXC_H
|
||||
#define __UPX_P_LX_EXC_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -87,26 +87,23 @@ protected:
|
||||
|
||||
unsigned n_mru;
|
||||
|
||||
struct cprElfHdr1 {
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
@@ -138,7 +135,7 @@ class PackBSDI386 : public PackLinuxI386
|
||||
public:
|
||||
PackBSDI386(InputFile *f);
|
||||
virtual int getFormat() const { return UPX_F_BSD_i386; }
|
||||
virtual const char *getName() const { return "*BSD/386"; }
|
||||
virtual const char *getName() const { return "BSD/386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-bsd.elf.execve"; }
|
||||
|
||||
protected:
|
||||
|
||||
+17
-14
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -197,15 +197,18 @@ void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
{
|
||||
#define MAX_INTERP_HDR 512
|
||||
char bufehdr[MAX_INTERP_HDR];
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)bufehdr;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *)(1+ehdr);
|
||||
union {
|
||||
unsigned char buf[MAX_INTERP_HDR];
|
||||
//struct { Elf32_Ehdr ehdr; Elf32_Phdr phdr; } e;
|
||||
} u;
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *) u.buf;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *) (u.buf + sizeof(*ehdr));
|
||||
|
||||
unsigned szb_info = sizeof(b_info);
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(bufehdr, MAX_INTERP_HDR);
|
||||
unsigned const e_entry = get_native32(&ehdr->e_entry);
|
||||
fi->readx(u.buf, MAX_INTERP_HDR);
|
||||
unsigned const e_entry = get_te32(&ehdr->e_entry);
|
||||
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
@@ -214,16 +217,16 @@ void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
fi->seek(overlay_offset, SEEK_SET);
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
unsigned orig_file_size = get_te32(&hbuf.p_filesize);
|
||||
blocksize = get_te32(&hbuf.p_blocksize);
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
|
||||
ibuf.alloc(blocksize + OVERHEAD);
|
||||
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
|
||||
fi->readx(&bhdr, szb_info);
|
||||
ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = get_native32(&bhdr.sz_cpr);
|
||||
ph.u_len = get_te32(&bhdr.sz_unc);
|
||||
ph.c_len = get_te32(&bhdr.sz_cpr);
|
||||
ph.filter_cto = bhdr.b_cto8;
|
||||
|
||||
// Uncompress Ehdr and Phdrs.
|
||||
@@ -277,7 +280,7 @@ void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
|
||||
// check for end-of-file
|
||||
fi->readx(&bhdr, szb_info);
|
||||
unsigned const sz_unc = ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
unsigned const sz_unc = ph.u_len = get_te32(&bhdr.sz_unc);
|
||||
|
||||
if (sz_unc == 0) { // uncompressed size 0 -> EOF
|
||||
// note: magic is always stored le32
|
||||
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_INTERP_H //{
|
||||
#define __UPX_P_LX_INTERP_H
|
||||
#define __UPX_P_LX_INTERP_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -91,7 +91,7 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
|
||||
// filter
|
||||
optimizeFilter(&fold_ft, buf, sz_fold);
|
||||
unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) +
|
||||
sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
|
||||
sizeof(Elf32_Phdr) * get_te32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
|
||||
if (0 == get_le32(fold_hdrlen + buf)) {
|
||||
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
|
||||
fold_hdrlen = umax(0x80, fold_hdrlen);
|
||||
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2000-2007 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_SH_H //{
|
||||
#define __UPX_P_LX_SH_H
|
||||
#define __UPX_P_LX_SH_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+1186
-98
File diff suppressed because it is too large
Load Diff
+763
-128
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,169 +21,530 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_MACHO_H
|
||||
#define __UPX_P_MACHO_H
|
||||
#define __UPX_P_MACHO_H 1
|
||||
|
||||
|
||||
__packed_struct(Mach_fat_header)
|
||||
BE32 magic;
|
||||
enum { // note conflict with java bytecode PackLinuxI386
|
||||
FAT_MAGIC = 0xcafebabe,
|
||||
FAT_MAGIC_SWAB = 0xbebafeca
|
||||
};
|
||||
BE32 nfat_arch; // Number of Mach_fat_arch which follow.
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(Mach_fat_arch)
|
||||
BE32 cputype;
|
||||
BE32 cpusubtype;
|
||||
BE32 offset;
|
||||
BE32 size;
|
||||
BE32 align; /* shift count; log base 2 */
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Mach Mach Object executable
|
||||
// Mach Mach Object executable; all structures are target-endian
|
||||
// 'otool' is the Mach analog of 'readelf' (convert executable file to ASCII).
|
||||
**************************************************************************/
|
||||
|
||||
struct Mach_header {
|
||||
BE32 magic;
|
||||
enum {
|
||||
MH_MAGIC = 0xfeedface
|
||||
};
|
||||
BE32 cputype;
|
||||
enum {
|
||||
CPU_TYPE_POWERPC = 18
|
||||
};
|
||||
BE32 cpysubtype;
|
||||
BE32 filetype;
|
||||
enum {
|
||||
MH_EXECUTE = 2
|
||||
};
|
||||
BE32 ncmds;
|
||||
BE32 sizeofcmds;
|
||||
BE32 flags;
|
||||
enum {
|
||||
MH_NOUNDEFS = 1
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
namespace N_Mach {
|
||||
|
||||
struct Mach_segment_command {
|
||||
BE32 cmd;
|
||||
enum {
|
||||
LC_SEGMENT = 0x1,
|
||||
LC_THREAD = 0x4,
|
||||
LC_UNIXTHREAD = 0x5,
|
||||
LC_LOAD_DYLINKER = 0xe
|
||||
};
|
||||
BE32 cmdsize;
|
||||
// integral types
|
||||
template <class TWord, class TXword, class TAddr, class TOff>
|
||||
struct MachITypes
|
||||
{
|
||||
typedef TWord Word;
|
||||
typedef TXword Xword;
|
||||
typedef TAddr Addr;
|
||||
typedef TOff Off;
|
||||
};
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_header)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word magic;
|
||||
Word cputype;
|
||||
Word cpysubtype;
|
||||
Word filetype;
|
||||
Word ncmds;
|
||||
Word sizeofcmds;
|
||||
Word flags;
|
||||
#define WANT_MACH_HEADER_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_header64)
|
||||
// only difference is padding to 0 mod 8
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word magic;
|
||||
Word cputype;
|
||||
Word cpysubtype;
|
||||
Word filetype;
|
||||
Word ncmds;
|
||||
Word sizeofcmds;
|
||||
Word flags;
|
||||
Word reserved; // pad to 0 mod 8
|
||||
#define WANT_MACH_HEADER_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_segment_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
char segname[16];
|
||||
BE32 vmaddr;
|
||||
BE32 vmsize;
|
||||
BE32 fileoff;
|
||||
BE32 filesize;
|
||||
BE32 maxprot;
|
||||
enum {
|
||||
VM_PROT_READ = 1,
|
||||
VM_PROT_WRITE = 2,
|
||||
VM_PROT_EXECUTE = 4
|
||||
};
|
||||
BE32 initprot;
|
||||
BE32 nsects;
|
||||
BE32 flags;
|
||||
}
|
||||
__attribute_packed;
|
||||
Addr vmaddr;
|
||||
Addr vmsize;
|
||||
Off fileoff;
|
||||
Off filesize;
|
||||
Word maxprot;
|
||||
Word initprot;
|
||||
Word nsects;
|
||||
Word flags;
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_section_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
|
||||
struct Mach_section {
|
||||
char sectname[16];
|
||||
char segname[16];
|
||||
BE32 addr; /* memory address */
|
||||
BE32 size; /* size in bytes */
|
||||
BE32 offset; /* file offset */
|
||||
BE32 align; /* power of 2 */
|
||||
BE32 reloff; /* file offset of relocation entries */
|
||||
BE32 nreloc; /* number of relocation entries */
|
||||
BE32 flags; /* section type and attributes */
|
||||
enum {
|
||||
S_REGULAR = 0,
|
||||
S_ZEROFILL,
|
||||
S_CSTRING_LITERALS,
|
||||
S_4BYTE_LITERALS,
|
||||
S_8BYTE_LITERALS,
|
||||
S_LITERAL_POINTERS,
|
||||
S_NON_LAZY_SYMBOL_POINTERS,
|
||||
S_LAZY_SYMBOL_POINTERS,
|
||||
S_SYMBOL_STUBS,
|
||||
S_MOD_INIT_FUNC_POINTERS,
|
||||
S_MOD_TERM_FNC_POINTERS,
|
||||
S_COALESCED
|
||||
};
|
||||
enum {
|
||||
S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
|
||||
S_ATTR_NO_TOC = 0x40000000,
|
||||
S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
|
||||
S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
|
||||
S_ATTR_EXT_RELOC = 0x00000200,
|
||||
S_ATTR_LOC_RELOC = 0x00000100
|
||||
};
|
||||
BE32 reserved1;
|
||||
BE32 reserved2;
|
||||
Addr addr; /* memory address */
|
||||
Addr size; /* size in bytes */
|
||||
Word offset; /* file offset */
|
||||
Word align; /* power of 2 */
|
||||
Word reloff; /* file offset of relocation entries */
|
||||
Word nreloc; /* number of relocation entries */
|
||||
Word flags; /* section type and attributes */
|
||||
Word reserved1; /* for offset or index */
|
||||
Word reserved2; /* for count or sizeof */
|
||||
#define WANT_MACH_SECTION_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
}
|
||||
__attribute_packed;
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_section_command_64)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
typedef typename TMachITypes::Word Off32;
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
struct Mach_ppc_thread_state {
|
||||
BE32 srr0; /* Instruction address register (PC; entry addr) */
|
||||
BE32 srr1; /* Machine state register (supervisor) */
|
||||
BE32 r0, r1, r2, r3, r4, r5, r6, r7;
|
||||
BE32 r8, r9,r10,r11,r12,r13,r14,r15;
|
||||
BE32 r16,r17,r18,r19,r20,r21,r22,r23;
|
||||
BE32 r24,r25,r26,r27,r28,r29,r30,r31;
|
||||
char sectname[16];
|
||||
char segname[16];
|
||||
Addr addr; /* memory address */
|
||||
Addr size; /* size in bytes */
|
||||
Off32 offset; /* file offset */
|
||||
Word align; /* power of 2 */
|
||||
Word reloff; /* file offset of relocation entries */
|
||||
Word nreloc; /* number of relocation entries */
|
||||
Word flags; /* section type and attributes */
|
||||
Word reserved1; /* for offset or index */
|
||||
Word reserved2; /* for count or sizeof */
|
||||
Word reserved3; /* NOT IN 32-bit VERSION!! */
|
||||
#define WANT_MACH_SECTION_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
BE32 cr; /* Condition register */
|
||||
BE32 xer; /* User's integer exception register */
|
||||
BE32 lr; /* Link register */
|
||||
BE32 ctr; /* Count register */
|
||||
BE32 mq; /* MQ register (601 only) */
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_symtab_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
typedef typename TMachITypes::Word Off32;
|
||||
|
||||
BE32 vrsave; /* Vector Save Register */
|
||||
}
|
||||
__attribute_packed;
|
||||
Word cmd; /* LC_SYMTAB */
|
||||
Word cmdsize; /* sizeof(struct Mach_symtab_command) */
|
||||
Off32 symoff; /* symbol table offset */
|
||||
Word nsyms; /* number of symbol table entries */
|
||||
Off32 stroff; /* string table offset */
|
||||
Word strsize; /* string table size in bytes */
|
||||
__packed_struct_end()
|
||||
|
||||
struct Mach_thread_command {
|
||||
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
BE32 cmdsize; /* total size of this command */
|
||||
BE32 flavor;
|
||||
enum {
|
||||
PPC_THREAD_STATE = 1
|
||||
};
|
||||
BE32 count; /* sizeof(following_thread_state)/4 */
|
||||
enum {
|
||||
PPC_THREAD_STATE_COUNT = sizeof(struct Mach_ppc_thread_state)/4
|
||||
};
|
||||
struct Mach_ppc_thread_state state;
|
||||
}
|
||||
__attribute_packed;
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_dysymtab_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
typedef typename TMachITypes::Word Off32;
|
||||
|
||||
Word cmd; /* LC_DYSYMTAB */
|
||||
Word cmdsize; /* sizeof(struct Mach_dysymtab_command) */
|
||||
Word ilocalsym; /* index to local symbols */
|
||||
Word nlocalsym; /* number of local symbols */
|
||||
Word iextdefsym; /* index to externally defined symbols */
|
||||
Word nextdefsym; /* number of externally defined symbols */
|
||||
Word iundefsym; /* index to undefined symbols */
|
||||
Word nundefsym; /* number of undefined symbols */
|
||||
Off32 tocoff; /* file offset to table of contents */
|
||||
Word ntoc; /* number of entries in table of contents */
|
||||
Off32 modtaboff; /* file offset to module table */
|
||||
Word nmodtab; /* number of module table entries */
|
||||
Off32 extrefsymoff; /* offset to referenced symbol table */
|
||||
Word nextrefsymoff; /* number of referenced symbol table entries */
|
||||
Off32 indirectsymoff; /* file offset to the indirect symbol table */
|
||||
Word nindirectsyms; /* number of indirect symbol table entries */
|
||||
Off32 extreloff; /* offset to external relocation entries */
|
||||
Word nextrel; /* number of external relocation entries */
|
||||
Off32 locreloff; /* offset to local relocation entries */
|
||||
Word nlocrel; /* number of local relocation entries */
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_segsplit_info_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
|
||||
Word cmd; /* LC_SEGMENT_SPLIT_INFO */
|
||||
Word cmdsize; /* sizeof(struct Mach_segsplit_info_command) */
|
||||
Off dataoff;
|
||||
Word datasize;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_routines_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
Addr init_address;
|
||||
Word init_module;
|
||||
Word reserved1;
|
||||
Word reserved2;
|
||||
Word reserved3;
|
||||
Word reserved4;
|
||||
Word reserved5;
|
||||
Word reserved6;
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_routines_command_64)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
Addr init_address;
|
||||
Xword init_module;
|
||||
Xword reserved1;
|
||||
Xword reserved2;
|
||||
Xword reserved3;
|
||||
Xword reserved4;
|
||||
Xword reserved5;
|
||||
Xword reserved6;
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_twolevel_hints_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
Off offset; /* offset to the hint table */
|
||||
Word nhints; /* number of hints */
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_ppc_thread_state)
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
|
||||
Addr srr0; /* Instruction address register (PC; entry addr) */
|
||||
Addr srr1; /* Machine state register (supervisor) */
|
||||
Addr r0, r1, r2, r3, r4, r5, r6, r7;
|
||||
Addr r8, r9,r10,r11,r12,r13,r14,r15;
|
||||
Addr r16,r17,r18,r19,r20,r21,r22,r23;
|
||||
Addr r24,r25,r26,r27,r28,r29,r30,r31;
|
||||
|
||||
Addr cr; /* Condition register */ // FIXME: Word?
|
||||
Addr xer; /* User's integer exception register */
|
||||
Addr lr; /* Link register */
|
||||
Addr ctr; /* Count register */
|
||||
Addr mq; /* MQ register (601 only) */
|
||||
|
||||
Addr vrsave; /* Vector Save Register */
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_i386_thread_state)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word eax, ebx, ecx, edx;
|
||||
Word edi, esi, ebp;
|
||||
Word esp, ss;
|
||||
Word eflags;
|
||||
Word eip, cs;
|
||||
Word ds, es, fs, gs;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_AMD64_thread_state)
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
Xword rax, rbx, rcx, rdx;
|
||||
Xword rdi, rsi, rbp, rsp;
|
||||
Xword r8, r9, r10, r11;
|
||||
Xword r12, r13, r14, r15;
|
||||
Xword rip, rflags;
|
||||
Xword cs, fs, gs;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_i386_new_thread_state)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word gs, fs, es, ds;
|
||||
Word edi, esi, ebp, esp;
|
||||
Word ebx, edx, ecx, eax;
|
||||
Word eip, cs, efl;
|
||||
Word uesp, ss;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_ARM_thread_state)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word r[13]; // r0-r12
|
||||
Word sp; // r13
|
||||
Word lr; // r14
|
||||
Word pc; // r15
|
||||
Word cpsr;
|
||||
__packed_struct_end()
|
||||
|
||||
} // namespace N_Mach
|
||||
|
||||
namespace N_Mach32 {
|
||||
|
||||
} // namespace N_Mach32
|
||||
|
||||
namespace N_Mach64 {
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_ppc_thread_state64)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
Xword srr0; /* Instruction address register (PC; entry addr) */
|
||||
Xword srr1; /* Machine state register (supervisor) */
|
||||
Xword r0, r1, r2, r3, r4, r5, r6, r7;
|
||||
Xword r8, r9,r10,r11,r12,r13,r14,r15;
|
||||
Xword r16,r17,r18,r19,r20,r21,r22,r23;
|
||||
Xword r24,r25,r26,r27,r28,r29,r30,r31;
|
||||
|
||||
Word cr; /* Condition register */ // FIXME: Xword?
|
||||
Xword xer; /* User's integer exception register */
|
||||
Xword lr; /* Link register */
|
||||
Xword ctr; /* Count register */
|
||||
|
||||
Word vrsave; /* Vector Save Register */
|
||||
__packed_struct_end()
|
||||
|
||||
} // namespace N_Mach64
|
||||
|
||||
namespace N_Mach {
|
||||
|
||||
template <class TP>
|
||||
struct MachClass_32
|
||||
{
|
||||
typedef TP BeLePolicy;
|
||||
|
||||
// integral types (target endianness)
|
||||
typedef typename TP::U16 TE16;
|
||||
typedef typename TP::U32 TE32;
|
||||
typedef typename TP::U64 TE64;
|
||||
typedef N_Mach::MachITypes<TE32, TE64, TE32, TE32> MachITypes;
|
||||
#if (ACC_CC_BORLANDC)
|
||||
typedef TE32 Addr;
|
||||
#else
|
||||
typedef typename MachITypes::Addr Addr;
|
||||
#endif
|
||||
|
||||
// Mach types
|
||||
typedef N_Mach::Mach_header<MachITypes> Mach_header;
|
||||
typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
|
||||
typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command;
|
||||
typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
|
||||
typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_command;
|
||||
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
|
||||
typedef N_Mach::Mach_routines_command<MachITypes> Mach_routines_command;
|
||||
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
|
||||
typedef N_Mach::Mach_ppc_thread_state<MachITypes> Mach_ppc_thread_state;
|
||||
typedef N_Mach::Mach_i386_thread_state<MachITypes> Mach_i386_thread_state;
|
||||
typedef N_Mach::Mach_AMD64_thread_state<MachITypes> Mach_AMD64_thread_state;
|
||||
typedef N_Mach::Mach_ARM_thread_state<MachITypes> Mach_ARM_thread_state;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
BeLePolicy::compileTimeAssertions();
|
||||
COMPILE_TIME_ASSERT(sizeof(Addr) == 4)
|
||||
}
|
||||
};
|
||||
|
||||
template <class TP>
|
||||
struct MachClass_64
|
||||
{
|
||||
typedef TP BeLePolicy;
|
||||
|
||||
// integral types (target endianness)
|
||||
typedef typename TP::U16 TE16;
|
||||
typedef typename TP::U32 TE32;
|
||||
typedef typename TP::U64 TE64;
|
||||
typedef N_Mach::MachITypes<TE32, TE64, TE64, TE64> MachITypes;
|
||||
#if (ACC_CC_BORLANDC)
|
||||
typedef TE64 Addr;
|
||||
#else
|
||||
typedef typename MachITypes::Addr Addr;
|
||||
#endif
|
||||
|
||||
// Mach types
|
||||
typedef N_Mach::Mach_header64<MachITypes> Mach_header;
|
||||
typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
|
||||
typedef N_Mach::Mach_section_command_64<MachITypes> Mach_section_command;
|
||||
typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
|
||||
typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_command;
|
||||
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
|
||||
typedef N_Mach::Mach_routines_command_64<MachITypes> Mach_routines_command;
|
||||
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
BeLePolicy::compileTimeAssertions();
|
||||
COMPILE_TIME_ASSERT(sizeof(Addr) == 8)
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace N_Mach
|
||||
|
||||
typedef N_Mach::MachClass_32<N_BELE_CTP::HostPolicy> MachClass_Host32;
|
||||
typedef N_Mach::MachClass_64<N_BELE_CTP::HostPolicy> MachClass_Host64;
|
||||
typedef N_Mach::MachClass_32<N_BELE_CTP::BEPolicy> MachClass_BE32;
|
||||
typedef N_Mach::MachClass_64<N_BELE_CTP::BEPolicy> MachClass_BE64;
|
||||
typedef N_Mach::MachClass_32<N_BELE_CTP::LEPolicy> MachClass_LE32;
|
||||
typedef N_Mach::MachClass_64<N_BELE_CTP::LEPolicy> MachClass_LE64;
|
||||
|
||||
// shortcuts
|
||||
typedef MachClass_Host32::Mach_segment_command Mach32_segment_command;
|
||||
typedef MachClass_Host32::Mach_section_command Mach32_section_command;
|
||||
typedef MachClass_Host32::Mach_symtab_command Mach32_symtab_command;
|
||||
typedef MachClass_Host32::Mach_dysymtab_command Mach32_dysymtab_command;
|
||||
typedef MachClass_Host32::Mach_segsplit_info_command Mach32_segsplit_info_command;
|
||||
typedef MachClass_Host32::Mach_routines_command Mach32_routines_command;
|
||||
typedef MachClass_Host32::Mach_twolevel_hints_command Mach32_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_Host64::Mach_segment_command Mach64_segment_command;
|
||||
typedef MachClass_Host64::Mach_section_command Mach64_section_command;
|
||||
typedef MachClass_Host64::Mach_symtab_command Mach64_symtab_command;
|
||||
typedef MachClass_Host64::Mach_dysymtab_command Mach64_dysymtab_command;
|
||||
typedef MachClass_Host64::Mach_segsplit_info_command Mach64_segsplit_info_command;
|
||||
typedef MachClass_Host64::Mach_routines_command Mach64_routines_command;
|
||||
typedef MachClass_Host64::Mach_twolevel_hints_command Mach64_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_BE32::Mach_segment_command MachBE32_segment_command;
|
||||
typedef MachClass_BE32::Mach_section_command MachBE32_section_command;
|
||||
typedef MachClass_BE32::Mach_symtab_command MachBE32_symtab_command;
|
||||
typedef MachClass_BE32::Mach_dysymtab_command MachBE32_dysymtab_command;
|
||||
typedef MachClass_BE32::Mach_segsplit_info_command MachBE32_segsplit_info_command;
|
||||
typedef MachClass_BE32::Mach_routines_command MachBE32_routines_command;
|
||||
typedef MachClass_BE32::Mach_twolevel_hints_command MachBE32_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_BE64::Mach_segment_command MachBE64_segment_command;
|
||||
typedef MachClass_BE64::Mach_section_command MachBE64_section_command;
|
||||
typedef MachClass_BE64::Mach_symtab_command MachBE64_symtab_command;
|
||||
typedef MachClass_BE64::Mach_dysymtab_command MachBE64_dysymtab_command;
|
||||
typedef MachClass_BE64::Mach_segsplit_info_command MachBE64_segsplit_info_command;
|
||||
typedef MachClass_BE64::Mach_routines_command MachBE64_routines_command;
|
||||
typedef MachClass_BE64::Mach_twolevel_hints_command MachBE64_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_LE32::Mach_segment_command MachLE32_segment_command;
|
||||
typedef MachClass_LE32::Mach_section_command MachLE32_section_command;
|
||||
typedef MachClass_LE32::Mach_symtab_command MachLE32_symtab_command;
|
||||
typedef MachClass_LE32::Mach_dysymtab_command MachLE32_dysymtab_command;
|
||||
typedef MachClass_LE32::Mach_segsplit_info_command MachLE32_segsplit_info_command;
|
||||
typedef MachClass_LE32::Mach_routines_command MachLE32_routines_command;
|
||||
typedef MachClass_LE32::Mach_twolevel_hints_command MachLE32_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command;
|
||||
typedef MachClass_LE64::Mach_section_command MachLE64_section_command;
|
||||
typedef MachClass_LE64::Mach_symtab_command MachLE64_symtab_command;
|
||||
typedef MachClass_LE64::Mach_dysymtab_command MachLE64_dysymtab_command;
|
||||
typedef MachClass_LE64::Mach_segsplit_info_command MachLE64_segsplit_info_command;
|
||||
typedef MachClass_LE64::Mach_routines_command MachLE64_routines_command;
|
||||
typedef MachClass_LE64::Mach_twolevel_hints_command MachLE64_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state;
|
||||
typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state;
|
||||
typedef MachClass_LE32::Mach_AMD64_thread_state Mach_AMD64_thread_state; // FIXME LE32 vs AMD64
|
||||
typedef MachClass_LE32::Mach_ARM_thread_state Mach_ARM_thread_state;
|
||||
#include "p_unix.h"
|
||||
|
||||
|
||||
class PackMachPPC32 : public PackUnixBe32
|
||||
template <class TMachClass>
|
||||
class PackMachBase : public PackUnix
|
||||
{
|
||||
typedef PackUnixBe32 super;
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
typedef TMachClass MachClass;
|
||||
typedef typename MachClass::BeLePolicy BeLePolicy;
|
||||
typedef typename MachClass::MachITypes MachITypes;
|
||||
// integral types (target endianness)
|
||||
typedef typename MachClass::TE16 TE16;
|
||||
typedef typename MachClass::TE32 TE32;
|
||||
typedef typename MachClass::TE64 TE64;
|
||||
typedef typename MachClass::Addr Addr;
|
||||
// Mach types
|
||||
typedef typename MachClass::Mach_header Mach_header;
|
||||
typedef typename MachClass::Mach_segment_command Mach_segment_command;
|
||||
typedef typename MachClass::Mach_section_command Mach_section_command;
|
||||
typedef typename MachClass::Mach_symtab_command Mach_symtab_command;
|
||||
typedef typename MachClass::Mach_dysymtab_command Mach_dysymtab_command;
|
||||
typedef typename MachClass::Mach_segsplit_info_command Mach_segsplit_info_command;
|
||||
typedef typename MachClass::Mach_routines_command Mach_routines_command;
|
||||
typedef typename MachClass::Mach_twolevel_hints_command Mach_twolevel_hints_command;
|
||||
|
||||
public:
|
||||
PackMachPPC32(InputFile *f);
|
||||
virtual ~PackMachPPC32();
|
||||
PackMachBase(InputFile *, unsigned cpuid, unsigned filetype,
|
||||
unsigned t_flavor, unsigned ts_word_cnt, unsigned tc_size);
|
||||
virtual ~PackMachBase();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_MACH_PPC32; }
|
||||
virtual const char *getName() const { return "Mach/ppc32"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.macho"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
// called by the generic pack()
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual void pack3(OutputFile *, Filter &) = 0; // append loader
|
||||
virtual void pack4(OutputFile *, Filter &) = 0; // append PackHeader
|
||||
|
||||
virtual void pack4dylib(OutputFile *, Filter &, Addr init_address);
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo) = 0;
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
virtual unsigned find_SEGMENT_gap(unsigned const k);
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void patchLoader();
|
||||
virtual void patchLoaderChecksum();
|
||||
virtual void updateLoader(OutputFile *);
|
||||
@@ -196,20 +557,294 @@ protected:
|
||||
virtual void defineSymbols(Filter const *);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
|
||||
static int __acc_cdecl_qsort compare_segment_command(void const *aa, void const *bb);
|
||||
|
||||
unsigned my_cputype;
|
||||
unsigned my_filetype;
|
||||
unsigned my_thread_flavor;
|
||||
unsigned my_thread_state_word_count;
|
||||
unsigned my_thread_command_size;
|
||||
|
||||
unsigned n_segment;
|
||||
unsigned sz_segment;
|
||||
unsigned sz_mach_headers;
|
||||
Mach_segment_command *rawmseg; // as input, with sections
|
||||
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
|
||||
unsigned o_routines_cmd; // file offset to LC_ROUINTES
|
||||
acc_uint64l_t prev_init_address;
|
||||
Mach_header mhdri;
|
||||
|
||||
Mach_header mhdro;
|
||||
Mach_segment_command segcmdo;
|
||||
Mach_thread_command threado;
|
||||
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
TE32 sz_unc; // uncompressed_size
|
||||
TE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
TE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
TE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
TE32 p_progid;
|
||||
TE32 p_filesize;
|
||||
TE32 p_blocksize;
|
||||
__packed_struct_end()
|
||||
|
||||
struct l_info linfo;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
MachClass::compileTimeAssertions();
|
||||
COMPILE_TIME_ASSERT(sizeof(b_info) == 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(l_info) == 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(p_info) == 12)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(b_info)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(l_info)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(p_info)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class PackMachPPC32 : public PackMachBase<MachClass_BE32>
|
||||
{
|
||||
typedef PackMachBase<MachClass_BE32> super;
|
||||
|
||||
public:
|
||||
PackMachPPC32(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_PPC32; }
|
||||
virtual const char *getName() const { return "Mach/ppc32"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.macho"; }
|
||||
|
||||
protected:
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo);
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
|
||||
__packed_struct(Mach_thread_command)
|
||||
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
BE32 cmdsize; /* total size of this command */
|
||||
BE32 flavor;
|
||||
BE32 count; /* sizeof(following_thread_state)/4 */
|
||||
Mach_ppc_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
class PackDylibPPC32 : public PackMachPPC32
|
||||
{
|
||||
typedef PackMachPPC32 super;
|
||||
|
||||
public:
|
||||
PackDylibPPC32(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_DYLIB_PPC32; }
|
||||
virtual const char *getName() const { return "Dylib/ppc32"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.dylib"; }
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
};
|
||||
|
||||
class PackMachI386 : public PackMachBase<MachClass_LE32>
|
||||
{
|
||||
typedef PackMachBase<MachClass_LE32> super;
|
||||
|
||||
public:
|
||||
PackMachI386(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_i386; }
|
||||
virtual const char *getName() const { return "Mach/i386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-darwin.macho"; }
|
||||
protected:
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo);
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
|
||||
__packed_struct(Mach_thread_command)
|
||||
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
LE32 cmdsize; /* total size of this command */
|
||||
LE32 flavor;
|
||||
LE32 count; /* sizeof(following_thread_state)/4 */
|
||||
Mach_i386_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
class PackDylibI386 : public PackMachI386
|
||||
{
|
||||
typedef PackMachI386 super;
|
||||
|
||||
public:
|
||||
PackDylibI386(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_DYLIB_i386; }
|
||||
virtual const char *getName() const { return "Dylib/i386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-darwin.dylib"; }
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
};
|
||||
|
||||
class PackMachAMD64 : public PackMachBase<MachClass_LE64>
|
||||
{
|
||||
typedef PackMachBase<MachClass_LE64> super;
|
||||
|
||||
public:
|
||||
PackMachAMD64(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_AMD64; }
|
||||
virtual const char *getName() const { return "Mach/AMD64"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "AMD64-darwin.macho"; }
|
||||
protected:
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo);
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
|
||||
__packed_struct(Mach_thread_command)
|
||||
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
LE32 cmdsize; /* total size of this command */
|
||||
LE32 flavor;
|
||||
LE32 count; /* sizeof(following_thread_state)/4 */
|
||||
Mach_AMD64_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
class PackDylibAMD64 : public PackMachAMD64
|
||||
{
|
||||
typedef PackMachAMD64 super;
|
||||
|
||||
public:
|
||||
PackDylibAMD64(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_DYLIB_AMD64; }
|
||||
virtual const char *getName() const { return "Dylib/AMD64"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "AMD64-darwin.dylib"; }
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
};
|
||||
|
||||
class PackMachARMEL : public PackMachBase<MachClass_LE32>
|
||||
{
|
||||
typedef PackMachBase<MachClass_LE32> super;
|
||||
|
||||
public:
|
||||
PackMachARMEL(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_ARMEL; }
|
||||
virtual const char *getName() const { return "Mach/ARMEL"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "ARMEL-darwin.macho"; }
|
||||
protected:
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo);
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
|
||||
__packed_struct(Mach_thread_command)
|
||||
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
LE32 cmdsize; /* total size of this command */
|
||||
LE32 flavor;
|
||||
LE32 count; /* sizeof(following_thread_state)/4 */
|
||||
Mach_ARM_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
class PackMachFat : public Packer
|
||||
{
|
||||
typedef Packer super;
|
||||
public:
|
||||
PackMachFat(InputFile *f);
|
||||
virtual ~PackMachFat();
|
||||
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_MACH_FAT; }
|
||||
virtual const char *getName() const { return "Mach/fat"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "fat-darwin.macho"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
// implementation
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
virtual void list();
|
||||
|
||||
public:
|
||||
virtual bool canPack();
|
||||
virtual int canUnpack();
|
||||
|
||||
protected:
|
||||
// loader core
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
#if (ACC_CC_BORLANDC)
|
||||
public:
|
||||
#endif
|
||||
enum { N_FAT_ARCH = 5 };
|
||||
protected:
|
||||
__packed_struct(Fat_head)
|
||||
struct Mach_fat_header fat;
|
||||
struct Mach_fat_arch arch[N_FAT_ARCH];
|
||||
__packed_struct_end()
|
||||
|
||||
Fat_head fat_head;
|
||||
|
||||
// UI handler
|
||||
UiPacker *uip;
|
||||
|
||||
// linker
|
||||
Linker *linker;
|
||||
#define WANT_MACH_HEADER_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
};
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/* p_mach_enum.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2007-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Use the preprocessor to work around
|
||||
// - that the types embedding these enums have to be PODs, and
|
||||
// deriving from an empty base class (which is the usual C++ way
|
||||
// of "importing" enums) does not yield a POD any more
|
||||
// - that older compilers do not correctly perform EBCO
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef WANT_MACH_HEADER_ENUM /*{*/
|
||||
#undef WANT_MACH_HEADER_ENUM
|
||||
enum { // magic
|
||||
MH_MAGIC = 0xfeedface
|
||||
};
|
||||
enum { // cputype
|
||||
CPU_TYPE_I386 = 7,
|
||||
CPU_TYPE_X86_64 = 0x01000007,
|
||||
CPU_TYPE_ARM = 12,
|
||||
CPU_TYPE_POWERPC = 0x00000012,
|
||||
CPU_TYPE_POWERPC64 = 0x01000012
|
||||
};
|
||||
enum { // cpusubtype
|
||||
CPU_SUBTYPE_ARM_ALL = 0,
|
||||
CPU_SUBTYPE_ARM_V4T = 5,
|
||||
CPU_SUBTYPE_ARM_V6 = 6
|
||||
};
|
||||
enum { // filetype
|
||||
MH_EXECUTE = 2,
|
||||
MH_DYLIB = 6
|
||||
};
|
||||
enum { // flags
|
||||
MH_NOUNDEFS = 1
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
#ifdef WANT_MACH_SEGMENT_ENUM /*{*/
|
||||
#undef WANT_MACH_SEGMENT_ENUM
|
||||
enum { // cmd
|
||||
LC_SEGMENT = 0x1,
|
||||
LC_SYMTAB = 0x2,
|
||||
LC_THREAD = 0x4,
|
||||
LC_UNIXTHREAD = 0x5,
|
||||
LC_DYSYMTAB = 0xb,
|
||||
LC_LOAD_DYLIB = 0xc,
|
||||
LC_ID_DYLIB = 0xd,
|
||||
LC_LOAD_DYLINKER = 0xe,
|
||||
LC_ROUTINES = 0x11,
|
||||
LC_TWOLEVEL_HINTS= 0x16,
|
||||
LC_SEGMENT_64 = 0x19,
|
||||
LC_ROUTINES_64 = 0x1a,
|
||||
LC_UUID = 0x1b,
|
||||
LC_RPATH = 0x1c,
|
||||
LC_CODE_SIGNATURE = 0x1d,
|
||||
LC_SEGMENT_SPLIT_INFO = 0x1e,
|
||||
LC_REEXPORT_DYLIB = 0x1f,
|
||||
LC_LAZY_LOAD_DYLIB= 0X20,
|
||||
LC_ENCRYPTION_INFO= 0X21,
|
||||
LC_DYLD_INFO = 0X22, // compressed dyld information (10.6.x)
|
||||
LC_REQ_DYLD = 0x80000000 // OR'ed ==> must not ignore
|
||||
};
|
||||
enum { // maxprot
|
||||
VM_PROT_READ = 1,
|
||||
VM_PROT_WRITE = 2,
|
||||
VM_PROT_EXECUTE = 4
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
#ifdef WANT_MACH_SECTION_ENUM /*{*/
|
||||
#undef WANT_MACH_SECTION_ENUM
|
||||
enum { // section type (low byte only)
|
||||
S_REGULAR = 0,
|
||||
S_ZEROFILL,
|
||||
S_CSTRING_LITERALS,
|
||||
S_4BYTE_LITERALS,
|
||||
S_8BYTE_LITERALS,
|
||||
S_LITERAL_POINTERS,
|
||||
S_NON_LAZY_SYMBOL_POINTERS, // sectname __nl_symbol_ptr
|
||||
S_LAZY_SYMBOL_POINTERS, // sectname __la_symbol_ptr
|
||||
S_SYMBOL_STUBS,
|
||||
S_MOD_INIT_FUNC_POINTERS, // sectname __mod_init_func
|
||||
S_MOD_TERM_FUNC_POINTERS,
|
||||
S_COALESCED,
|
||||
S_GB_ZEROFILL,
|
||||
S_INTERPOSING,
|
||||
S_16BYTE_LITERALS,
|
||||
S_DTRACE_DOF
|
||||
};
|
||||
enum { // section flags (high 24 bits)
|
||||
S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
|
||||
S_ATTR_NO_TOC = 0x40000000,
|
||||
S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
|
||||
S_ATTR_NO_DEAD_STRIP = 0x10000000,
|
||||
S_ATTR_LIVE_SUPPORT = 0x08000000,
|
||||
S_ATTR_SELF_MODIFYING_CODE = 0x04000000,
|
||||
S_ATTR_DEBUG = 0x02000000,
|
||||
S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
|
||||
S_ATTR_EXT_RELOC = 0x00000200,
|
||||
S_ATTR_LOC_RELOC = 0x00000100
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
#ifdef WANT_MACH_THREAD_ENUM /*{*/
|
||||
#undef WANT_MACH_THREAD_ENUM
|
||||
enum { // thread flavor
|
||||
PPC_THREAD_STATE = 1,
|
||||
PPC_THREAD_STATE64 = 5,
|
||||
x86_THREAD_STATE32 = 1,
|
||||
x86_THREAD_STATE64 = 4,
|
||||
i386_OLD_THREAD_STATE = -1,
|
||||
ARM_THREAD_STATE = 1
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+35
-18
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2002-2007 Jens Medoch
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
Jens Medoch
|
||||
<jssg@users.sourceforge.net>
|
||||
@@ -95,7 +95,7 @@ PackPs1::PackPs1(InputFile *f) :
|
||||
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40)
|
||||
|
||||
fdata_size = file_size - PS_HDR_SIZE;
|
||||
ram_size = !opt->ps1_exe.do_8mb ? 0x200000 : 0x800000;
|
||||
ram_size = !opt->ps1_exe.do_8mib ? 0x200000 : 0x800000;
|
||||
}
|
||||
|
||||
const int *PackPs1::getCompressionMethods(int method, int level) const
|
||||
@@ -127,8 +127,8 @@ int PackPs1::readFileHeader()
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ih, sizeof(ih));
|
||||
if (memcmp(&ih.id, "PS-X EXE", 8) != 0 &&
|
||||
memcmp(&ih.id, "EXE X-SP", 8) != 0)
|
||||
if (memcmp(&ih.id[0], "PS-X EXE", 8) != 0 &&
|
||||
memcmp(&ih.id[0], "EXE X-SP", 8) != 0)
|
||||
return 0;
|
||||
if (ih.text != 0 || ih.data != 0)
|
||||
return 0;
|
||||
@@ -194,6 +194,8 @@ bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst)
|
||||
unsigned sz_bh = SZ_IH_BKUP;
|
||||
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
|
||||
unc_bh, &sz_bh, M_NRV2E_8, NULL );
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP)
|
||||
throwInternalError("header decompression failed");
|
||||
unsigned ad = upx_adler32(unc_bh, SZ_IH_BKUP);
|
||||
@@ -254,8 +256,9 @@ bool PackPs1::canPack()
|
||||
fi->readx(buf, sizeof(buf));
|
||||
checkAlreadyPacked(buf, sizeof(buf));
|
||||
|
||||
for (unsigned i = 0; i < sizeof(buf); i++)
|
||||
for (size_t i = 0; i < sizeof(buf); i++)
|
||||
if (buf[i] != 0)
|
||||
{
|
||||
if (!opt->force)
|
||||
throwCantPack("unknown data in header (try --force)");
|
||||
else
|
||||
@@ -265,6 +268,7 @@ bool PackPs1::canPack()
|
||||
opt->backup = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!checkFileHeader())
|
||||
throwCantPack("unsupported header flags (try --force)");
|
||||
if (!opt->force && file_size < PS_MIN_SIZE)
|
||||
@@ -318,7 +322,8 @@ void PackPs1::buildLoader(const Filter *)
|
||||
sa_tmp += overlap = ALIGN_UP((ph.overlap_overhead - sa_tmp), 4u);
|
||||
}
|
||||
|
||||
foundBss = findBssSection();
|
||||
if (isCon || M_IS_LZMA(ph.method))
|
||||
foundBss = findBssSection();
|
||||
|
||||
if (M_IS_LZMA(ph.method) && !buildPart2)
|
||||
{
|
||||
@@ -370,16 +375,20 @@ void PackPs1::buildLoader(const Filter *)
|
||||
else
|
||||
{
|
||||
if (M_IS_LZMA(ph.method))
|
||||
addLoader("cdb.start.lzma", "pad.code", "cdb.entry.lzma", method, "cdb.lzma.cpr",
|
||||
addLoader(!foundBss ? "cdb.start.lzma" : "bss.cdb.start.lzma", "pad.code",
|
||||
!foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma",
|
||||
method, "cdb.lzma.cpr",
|
||||
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
|
||||
"lzma.exec", NULL);
|
||||
else
|
||||
{
|
||||
assert(foundBss != true);
|
||||
addLoader("cdb.start", "pad.code", "cdb.entry",
|
||||
ih.tx_ptr & 0xffff ? "cdb.dec.ptr" : "cdb.dec.ptr.hi",
|
||||
method,
|
||||
sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "",
|
||||
!foundBss ? "cdb.exit" : "bss.exit",
|
||||
"pad.code", NULL);
|
||||
"cdb.exit", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("UPX1HEAD", "IDENTSTR", NULL);
|
||||
}
|
||||
@@ -424,7 +433,7 @@ bool PackPs1::findBssSection()
|
||||
reg = REG1(op);
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
bss_nfo *p = (bss_nfo *)&p1[i];
|
||||
bss_nfo *p = (bss_nfo *)(void *)&p1[i];
|
||||
unsigned short op1 = p->op1, op2 = p->op2;
|
||||
|
||||
// check for la (x),bss_start
|
||||
@@ -491,7 +500,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
// compress (max_match = 65535)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = 65535;
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, sa_cnt, &cconf);
|
||||
|
||||
if (overlap)
|
||||
@@ -554,7 +563,9 @@ void PackPs1::pack(OutputFile *fo)
|
||||
}
|
||||
else
|
||||
{
|
||||
d_len = (lsize - h_len) - getLoaderSectionStart(M_IS_LZMA(ph.method) ? "cdb.entry.lzma" : "cdb.entry");
|
||||
const char* entry_lzma = !foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma";
|
||||
|
||||
d_len = (lsize - h_len) - getLoaderSectionStart(M_IS_LZMA(ph.method) ? entry_lzma : "cdb.entry");
|
||||
e_len = (lsize - d_len) - h_len;
|
||||
}
|
||||
|
||||
@@ -565,11 +576,13 @@ void PackPs1::pack(OutputFile *fo)
|
||||
linker->defineSymbol("ldr_sz", M_IS_LZMA(ph.method) ? sz_lunc + 16 : (d_len-pad_code));
|
||||
|
||||
if (foundBss)
|
||||
{
|
||||
if (M_IS_LZMA(ph.method))
|
||||
linker->defineSymbol("wrkmem", bss_end - 160 - getDecompressorWrkmemSize()
|
||||
- (sz_lunc + 16));
|
||||
else
|
||||
linker->defineSymbol("wrkmem", bss_end - 16 - (d_len - pad_code));
|
||||
}
|
||||
|
||||
|
||||
const unsigned entry = comp_data_start - e_len;
|
||||
@@ -578,7 +591,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
|
||||
unsigned pad = 0;
|
||||
|
||||
if (!opt->ps1_exe.no_align)
|
||||
if (!opt->ps1_exe.no_align || !isCon)
|
||||
{
|
||||
pad = oh.tx_len;
|
||||
oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC);
|
||||
@@ -611,8 +624,12 @@ void PackPs1::pack(OutputFile *fo)
|
||||
linker->defineSymbol("PSVR", FIX_PSVR);
|
||||
linker->defineSymbol("CPDO", comp_data_start);
|
||||
if (M_IS_LZMA(ph.method))
|
||||
linker->defineSymbol("lzma_cpr", getLoaderSectionStart("lzma.exec")
|
||||
- getLoaderSectionStart("cdb.entry.lzma"));
|
||||
{
|
||||
unsigned entry_lzma = getLoaderSectionStart( !foundBss ? "cdb.entry.lzma" :
|
||||
"bss.cdb.entry.lzma");
|
||||
|
||||
linker->defineSymbol("lzma_cpr", getLoaderSectionStart("lzma.exec") - entry_lzma);
|
||||
}
|
||||
}
|
||||
|
||||
relocateLoader();
|
||||
|
||||
+13
-21
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2002-2007 Jens Medoch
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
Jens Medoch
|
||||
<jssg@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_PS1_H
|
||||
#define __UPX_P_PS1_H
|
||||
#define __UPX_P_PS1_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -67,8 +67,7 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
virtual bool checkFileHeader();
|
||||
|
||||
struct ps1_exe_t
|
||||
{
|
||||
__packed_struct(ps1_exe_t)
|
||||
// ident string
|
||||
char id[8];
|
||||
// is NULL
|
||||
@@ -91,33 +90,26 @@ protected:
|
||||
char origin[60];
|
||||
// backup of the original header (epc - is_len)
|
||||
// id & the upx header ...
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
// for unpack
|
||||
struct ps1_exe_hb_t
|
||||
{
|
||||
__packed_struct(ps1_exe_hb_t)
|
||||
LE32 ih_bkup[10];
|
||||
// plus checksum for the backup
|
||||
LE32 ih_csum;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct ps1_exe_chb_t
|
||||
{
|
||||
__packed_struct(ps1_exe_chb_t)
|
||||
unsigned char id;
|
||||
unsigned char len;
|
||||
LE16 ih_csum;
|
||||
unsigned char ih_bkup;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct bss_nfo
|
||||
{
|
||||
__packed_struct(bss_nfo)
|
||||
LE16 hi1, op1, lo1, op2;
|
||||
LE16 hi2, op3, lo2, op4;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
ps1_exe_t ih, oh;
|
||||
ps1_exe_hb_t bh;
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+7
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_SYS_H
|
||||
#define __UPX_P_SYS_H
|
||||
#define __UPX_P_SYS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,7 +42,8 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_DOS_SYS; }
|
||||
virtual const char *getName() const { return "dos/sys"; }
|
||||
virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.sys" : "i286-dos16.sys"; }
|
||||
//virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.sys" : "i286-dos16.sys"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i086-dos16.sys"; }
|
||||
|
||||
virtual bool canPack();
|
||||
|
||||
|
||||
+7
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -67,11 +67,12 @@ const int *PackTmt::getFilters() const
|
||||
|
||||
|
||||
unsigned PackTmt::findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range,
|
||||
unsigned upper_limit) const
|
||||
{
|
||||
// make sure the decompressor will be paragraph aligned
|
||||
unsigned o = super::findOverlapOverhead(buf, range, upper_limit);
|
||||
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
||||
o = ((o + 0x20) &~ 0xf) - (ph.u_len & 0xf);
|
||||
return o;
|
||||
}
|
||||
@@ -241,7 +242,7 @@ void PackTmt::pack(OutputFile *fo)
|
||||
// compress
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
|
||||
+7
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_TMT_H
|
||||
#define __UPX_P_TMT_H
|
||||
#define __UPX_P_TMT_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_TMT_ADAM; }
|
||||
virtual const char *getName() const { return "tmt/adam"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-dos32.tmt"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-dos32.tmt.adam"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -56,6 +56,7 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
|
||||
virtual unsigned findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range = 0,
|
||||
unsigned upper_limit = ~0u) const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
|
||||
+8
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -446,7 +446,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
overlay = file_size - (FH_SIZE + i_text + i_data + i_sym);
|
||||
fi->readx(ibuf+t,overlay);
|
||||
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
|
||||
i_text, i_data, i_sym, i_bss, (int)ih.fh_flag);
|
||||
printf("xx1 reloc: %d, overlay: %d, fixup: %d\n", relocsize, overlay, overlay >= 4 ? (int)get_be32(ibuf+t) : -1);
|
||||
@@ -476,7 +476,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
symbols.need_reloc = true;
|
||||
}
|
||||
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("xx2: %d relocs: %d, overlay: %d, t: %d\n", nrelocs, relocsize, overlay, t);
|
||||
#endif
|
||||
|
||||
@@ -487,7 +487,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
ih.fh_sym = 0; // we stripped all symbols
|
||||
memcpy(ibuf+t, &ih, FH_SIZE);
|
||||
t += FH_SIZE;
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("xx3 reloc: %d, overlay: %d, t: %d\n", relocsize, overlay, t);
|
||||
#endif
|
||||
assert(t <= isize);
|
||||
@@ -507,7 +507,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
// compress (max_match = 65535)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = 65535;
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
|
||||
//
|
||||
@@ -686,7 +686,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
// add an empty relocation fixup to workaround a bug in some TOS versions
|
||||
oh.fh_reloc = 0;
|
||||
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("old text: %6d, data: %6d, bss: %6d, reloc: %d, overlay: %d\n",
|
||||
i_text, i_data, i_bss, relocsize, overlay);
|
||||
printf("new text: %6d, data: %6d, bss: %6d, flag=0x%x\n",
|
||||
|
||||
+6
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_TOS_H
|
||||
#define __UPX_P_TOS_H
|
||||
#define __UPX_P_TOS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -62,8 +62,7 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
virtual bool checkFileHeader();
|
||||
|
||||
struct tos_header_t
|
||||
{
|
||||
__packed_struct(tos_header_t)
|
||||
BE16 fh_magic;
|
||||
BE32 fh_text;
|
||||
BE32 fh_data;
|
||||
@@ -72,8 +71,7 @@ protected:
|
||||
BE32 fh_reserved;
|
||||
BE32 fh_flag;
|
||||
BE16 fh_reloc;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
tos_header_t ih, oh;
|
||||
|
||||
|
||||
+34
-30
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -173,8 +173,10 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy);
|
||||
|
||||
if (ph.c_len < ph.u_len) {
|
||||
const upx_bytep tbuf = NULL;
|
||||
if (ft.id == 0) tbuf = ibuf;
|
||||
ph.overlap_overhead = OVERHEAD;
|
||||
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
|
||||
if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
|
||||
// not in-place compressible
|
||||
ph.c_len = ph.u_len;
|
||||
}
|
||||
@@ -189,8 +191,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
// write block header
|
||||
b_info blk_info;
|
||||
memset(&blk_info, 0, sizeof(blk_info));
|
||||
set_native32(&blk_info.sz_unc, ph.u_len);
|
||||
set_native32(&blk_info.sz_cpr, ph.c_len);
|
||||
set_te32(&blk_info.sz_unc, ph.u_len);
|
||||
set_te32(&blk_info.sz_cpr, ph.c_len);
|
||||
if (ph.c_len < ph.u_len) {
|
||||
blk_info.b_method = (unsigned char) ph.method;
|
||||
blk_info.b_ftid = (unsigned char) ph.filter;
|
||||
@@ -250,7 +252,7 @@ void PackUnix::pack4(OutputFile *fo, Filter &)
|
||||
writePackHeader(fo);
|
||||
|
||||
unsigned tmp;
|
||||
set_native32(&tmp, overlay_offset);
|
||||
set_te32(&tmp, overlay_offset);
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
@@ -276,9 +278,9 @@ void PackUnix::pack(OutputFile *fo)
|
||||
pack1(fo, ft); // generate Elf header, etc.
|
||||
|
||||
p_info hbuf;
|
||||
set_native32(&hbuf.p_progid, progid);
|
||||
set_native32(&hbuf.p_filesize, file_size);
|
||||
set_native32(&hbuf.p_blocksize, blocksize);
|
||||
set_te32(&hbuf.p_progid, progid);
|
||||
set_te32(&hbuf.p_filesize, file_size);
|
||||
set_te32(&hbuf.p_blocksize, blocksize);
|
||||
fo->write(&hbuf, sizeof(hbuf));
|
||||
|
||||
pack2(fo, ft); // append the compressed body
|
||||
@@ -353,8 +355,10 @@ void PackUnix::packExtent(
|
||||
}
|
||||
|
||||
if (ph.c_len < ph.u_len) {
|
||||
const upx_bytep tbuf = NULL;
|
||||
if (ft == NULL || ft->id == 0) tbuf = ibuf;
|
||||
ph.overlap_overhead = OVERHEAD;
|
||||
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
|
||||
if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
|
||||
// not in-place compressible
|
||||
ph.c_len = ph.u_len;
|
||||
}
|
||||
@@ -385,8 +389,8 @@ void PackUnix::packExtent(
|
||||
ph.c_adler = upx_adler32(obuf, ph.c_len, ph.saved_c_adler);
|
||||
end_u_adler = ph.u_adler;
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, hdr_u_len);
|
||||
set_native32(&tmp.sz_cpr, hdr_c_len);
|
||||
set_te32(&tmp.sz_unc, hdr_u_len);
|
||||
set_te32(&tmp.sz_cpr, hdr_c_len);
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
@@ -396,8 +400,8 @@ void PackUnix::packExtent(
|
||||
hdr_u_len = 0; // compress hdr one time only
|
||||
}
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, ph.u_len);
|
||||
set_native32(&tmp.sz_cpr, ph.c_len);
|
||||
set_te32(&tmp.sz_unc, ph.u_len);
|
||||
set_te32(&tmp.sz_cpr, ph.c_len);
|
||||
if (ph.c_len < ph.u_len) {
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
if (ft) {
|
||||
@@ -408,6 +412,9 @@ void PackUnix::packExtent(
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
// write compressed data
|
||||
if (ph.c_len < ph.u_len) {
|
||||
fo->write(obuf, ph.c_len);
|
||||
@@ -418,9 +425,6 @@ void PackUnix::packExtent(
|
||||
fo->write(ibuf, ph.u_len);
|
||||
}
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
total_in += ph.u_len;
|
||||
total_out += ph.c_len;
|
||||
}
|
||||
@@ -435,8 +439,8 @@ void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
while (wanted) {
|
||||
fi->readx(&hdr, szb_info);
|
||||
int const sz_unc = ph.u_len = get_native32(&hdr.sz_unc);
|
||||
int const sz_cpr = ph.c_len = get_native32(&hdr.sz_cpr);
|
||||
int const sz_unc = ph.u_len = get_te32(&hdr.sz_unc);
|
||||
int const sz_cpr = ph.c_len = get_te32(&hdr.sz_cpr);
|
||||
ph.filter_cto = hdr.b_cto8;
|
||||
|
||||
if (sz_unc == 0) { // must never happen while 0!=wanted
|
||||
@@ -499,13 +503,13 @@ int PackUnix::canUnpack()
|
||||
|
||||
fi->seek(-bufsize, SEEK_END);
|
||||
fi->readx(buf, bufsize);
|
||||
if (!getPackHeader(buf, bufsize))
|
||||
if (!getPackHeader(buf, bufsize, true)) // allow incompressible extents
|
||||
return false;
|
||||
|
||||
int l = ph.buf_offset + ph.getPackHeaderSize();
|
||||
if (l < 0 || l + 4 > bufsize)
|
||||
throwCantUnpack("file corrupted");
|
||||
overlay_offset = get_native32(buf+l);
|
||||
overlay_offset = get_te32(buf+l);
|
||||
if ((off_t)overlay_offset >= file_size)
|
||||
throwCantUnpack("file corrupted");
|
||||
|
||||
@@ -527,15 +531,15 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
Elf32_Ehdr ehdr;
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ehdr, sizeof(ehdr));
|
||||
unsigned const e_entry = get_native32(&ehdr.e_entry);
|
||||
unsigned const e_entry = get_te32(&ehdr.e_entry);
|
||||
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
else {
|
||||
Elf32_Phdr phdr;
|
||||
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->seek(get_te32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(&phdr, sizeof(phdr));
|
||||
unsigned const p_vaddr = get_native32(&phdr.p_vaddr);
|
||||
unsigned const p_vaddr = get_te32(&phdr.p_vaddr);
|
||||
if (0x80==(e_entry - p_vaddr)) { /* 1.22 old style */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
@@ -554,8 +558,8 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
{
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
orig_file_size = get_te32(&hbuf.p_filesize);
|
||||
blocksize = get_te32(&hbuf.p_blocksize);
|
||||
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
@@ -579,8 +583,8 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
unsigned sz_unc, sz_cpr;
|
||||
|
||||
fi->readx(&bhdr, szb_info);
|
||||
ph.u_len = sz_unc = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = sz_cpr = get_native32(&bhdr.sz_cpr);
|
||||
ph.u_len = sz_unc = get_te32(&bhdr.sz_unc);
|
||||
ph.c_len = sz_cpr = get_te32(&bhdr.sz_cpr);
|
||||
|
||||
if (sz_unc == 0) // uncompressed size 0 -> EOF
|
||||
{
|
||||
|
||||
+26
-55
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
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>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_UNIX_H
|
||||
#define __UPX_P_UNIX_H
|
||||
#define __UPX_P_UNIX_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -64,15 +64,6 @@ protected:
|
||||
|
||||
virtual void writePackHeader(OutputFile *fo);
|
||||
|
||||
// in order too share as much code as possible we introduce
|
||||
// an endian abstraction here
|
||||
virtual acc_uint64l_t get_native64(const void *) const = 0;
|
||||
virtual unsigned get_native32(const void *) const = 0;
|
||||
virtual unsigned get_native16(const void *) const = 0;
|
||||
virtual void set_native64(void *, acc_uint64l_t) const = 0;
|
||||
virtual void set_native32(void *, unsigned) const = 0;
|
||||
virtual void set_native16(void *, unsigned) const = 0;
|
||||
|
||||
virtual bool checkCompressionRatio(unsigned, unsigned) const;
|
||||
|
||||
protected:
|
||||
@@ -101,30 +92,28 @@ protected:
|
||||
unsigned b_len; // total length of b_info blocks
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
unsigned sz_unc; // uncompressed_size
|
||||
unsigned sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
unsigned p_progid;
|
||||
unsigned p_filesize;
|
||||
unsigned p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct l_info linfo;
|
||||
|
||||
@@ -142,39 +131,30 @@ class PackUnixBe32 : public PackUnix
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixBe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; }
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
BE32 sz_unc; // uncompressed_size
|
||||
BE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
BE32 l_checksum;
|
||||
BE32 l_magic;
|
||||
BE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
BE32 p_progid;
|
||||
BE32 p_filesize;
|
||||
BE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
__packed_struct_end()
|
||||
};
|
||||
|
||||
|
||||
@@ -183,39 +163,30 @@ class PackUnixLe32 : public PackUnix
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixLe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
LE32 sz_unc; // uncompressed_size
|
||||
LE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
LE32 p_progid;
|
||||
LE32 p_filesize;
|
||||
LE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
__packed_struct_end()
|
||||
};
|
||||
|
||||
|
||||
@@ -235,7 +206,7 @@ public:
|
||||
virtual bool canPack();
|
||||
|
||||
protected:
|
||||
virtual const upx_byte *getLoader() const;
|
||||
virtual upx_byte *getLoader() const;
|
||||
virtual int getLoaderSize() const;
|
||||
|
||||
virtual void patchLoader();
|
||||
|
||||
+434
-36
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2004-2007 John Reiser
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 2004-2010 John Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,11 +22,11 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John Reiser
|
||||
jreiser@users.sourceforge.net
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ static const
|
||||
#include "stub/amd64-linux.kernel.vmlinux.h"
|
||||
static const
|
||||
#include "stub/arm-linux.kernel.vmlinux.h"
|
||||
static const
|
||||
#include "stub/armeb-linux.kernel.vmlinux.h"
|
||||
static const
|
||||
#include "stub/powerpc-linux.kernel.vmlinux.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -60,15 +64,15 @@ PackVmlinuxBase<T>::PackVmlinuxBase(InputFile *f,
|
||||
n_ptload(0), phdri(NULL), shdri(NULL), shstrtab(NULL)
|
||||
{
|
||||
ElfClass::compileTimeAssertions();
|
||||
bele = N_BELE_CTP::getRTP<BeLePolicy>();
|
||||
bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PackVmlinuxBase<T>::~PackVmlinuxBase()
|
||||
{
|
||||
delete [] shstrtab;
|
||||
delete [] phdri;
|
||||
delete [] shdri;
|
||||
delete [] shstrtab;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -201,13 +205,14 @@ bool PackVmlinuxBase<T>::canPack()
|
||||
return 0 < n_ptload;
|
||||
}
|
||||
|
||||
#include "p_elf.h"
|
||||
|
||||
template <class T>
|
||||
void PackVmlinuxBase<T>::pack(OutputFile *fo)
|
||||
{
|
||||
unsigned fo_off = 0;
|
||||
Ehdr ehdro;
|
||||
U32 tmp_u32;
|
||||
TE32 tmp_u32;
|
||||
|
||||
// NULL
|
||||
// .text(PT_LOADs) .note(1st page) .note(rest)
|
||||
@@ -264,8 +269,217 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
|
||||
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
|
||||
unsigned ppc32_extra = 0;
|
||||
if (Ehdr::EM_PPC==my_e_machine) {
|
||||
// output layout:
|
||||
// .long UPX_MAGIC_LE32
|
||||
// .long L20 - L10
|
||||
// L10:
|
||||
// b_info for Ehdr; compressed Ehdr; .balign 4 // one block only
|
||||
// b_info for LOAD; compressed LOAD; .balign 4 // possibly many blocks
|
||||
// // This allows per-block filters!
|
||||
// L20:
|
||||
// b f_decompress
|
||||
// +4: f_unfilter(char *buf, unsigned len, unsigned cto8, unsigned ftid)
|
||||
// // Code for multiple filters can "daisy chain" on ftid.
|
||||
// f_decompress(char const *src, unsigned src_len,
|
||||
// char *dst, unsigned *dst_len, int method)
|
||||
unsigned tmp;
|
||||
tmp = UPX_MAGIC_LE32; fo->write(&tmp, sizeof(tmp)); fo_off += sizeof(tmp);
|
||||
tmp = 0; fo->write(&tmp, sizeof(tmp)); fo_off += sizeof(tmp);
|
||||
ppc32_extra += 2*sizeof(tmp);
|
||||
unsigned const len_unc = sizeof(ehdri) + sizeof(Phdr) * ehdri.e_phnum;
|
||||
MemBuffer unc_hdr(len_unc);
|
||||
MemBuffer cpr_hdr; cpr_hdr.allocForCompression(len_unc);
|
||||
memcpy(&unc_hdr[0], &ehdri, sizeof(ehdri));
|
||||
memcpy(&unc_hdr[sizeof(ehdri)], phdri, sizeof(Phdr) * ehdri.e_phnum);
|
||||
unsigned len_cpr = 0;
|
||||
int const r = upx_compress(unc_hdr, len_unc, cpr_hdr, &len_cpr,
|
||||
NULL, ph.method, 10, NULL, NULL );
|
||||
if (UPX_E_OK!=r || len_unc<=len_cpr) // FIXME: allow no compression
|
||||
throwInternalError("Ehdr compression failed");
|
||||
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
unsigned sz_unc; // uncompressed_size
|
||||
unsigned sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused; // FIXME: !=0 for partial-block unfilter
|
||||
// unsigned f_offset, f_len; // only if partial-block unfilter
|
||||
__packed_struct_end()
|
||||
|
||||
struct b_info hdr_info;
|
||||
set_be32(&hdr_info.sz_unc, len_unc);
|
||||
set_be32(&hdr_info.sz_cpr, len_cpr);
|
||||
hdr_info.b_method = ph.method;
|
||||
hdr_info.b_ftid = 0;
|
||||
hdr_info.b_cto8 = 0;
|
||||
hdr_info.b_unused = 0;
|
||||
fo->write(&hdr_info, sizeof(hdr_info)); fo_off += sizeof(hdr_info);
|
||||
unsigned const frag = (3& (0u-len_cpr));
|
||||
ppc32_extra += sizeof(hdr_info) + len_cpr + frag;
|
||||
fo_off += len_cpr + frag;
|
||||
memset(&cpr_hdr[len_cpr], 0, frag); // valgrind only
|
||||
fo->write(cpr_hdr, len_cpr + frag);
|
||||
|
||||
// Partial filter: .text and following contiguous SHF_EXECINSTR
|
||||
upx_bytep f_ptr = ibuf;
|
||||
unsigned f_len = 0;
|
||||
Shdr const *shdr = 1+ shdri; // skip empty shdr[0]
|
||||
if (ft.buf_len==0 // not specified yet FIXME: was set near construction
|
||||
&& (Shdr::SHF_ALLOC & shdr->sh_flags)
|
||||
&& (Shdr::SHF_EXECINSTR & shdr->sh_flags)) {
|
||||
// shdr[1] is instructions (probably .text)
|
||||
f_ptr = ibuf + (unsigned) (shdr->sh_offset - phdri[0].p_offset);
|
||||
f_len = shdr->sh_size;
|
||||
++shdr;
|
||||
for (int j= ehdri.e_shnum - 2; --j>=0; ++shdr) {
|
||||
unsigned prev_end = shdr[-1].sh_size + shdr[-1].sh_offset;
|
||||
prev_end += ~(0u-shdr[0].sh_addralign) & (0u-prev_end); // align_up
|
||||
if ((Shdr::SHF_ALLOC & shdr->sh_flags)
|
||||
&& (Shdr::SHF_EXECINSTR & shdr->sh_flags)
|
||||
&& shdr[0].sh_offset==prev_end) {
|
||||
f_len += shdr->sh_size;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // ft.buf_len already specified, or Shdr[1] not instructions
|
||||
f_ptr = ibuf;
|
||||
f_len = ph.u_len;
|
||||
}
|
||||
compressWithFilters(ibuf, ph.u_len, obuf,
|
||||
f_ptr, f_len, // filter range
|
||||
NULL, 0, // hdr_ptr, hdr_len
|
||||
&ft, 512, &cconf, getStrategy(ft));
|
||||
|
||||
set_be32(&hdr_info.sz_unc, ph.u_len);
|
||||
set_be32(&hdr_info.sz_cpr, ph.c_len);
|
||||
hdr_info.b_ftid = ft.id;
|
||||
hdr_info.b_cto8 = ft.cto;
|
||||
if (ph.u_len!=f_len) {
|
||||
hdr_info.b_unused = 1; // flag for partial filter
|
||||
}
|
||||
fo->write(&hdr_info, sizeof(hdr_info)); fo_off += sizeof(hdr_info);
|
||||
ppc32_extra += sizeof(hdr_info);
|
||||
if (ph.u_len!=f_len) {
|
||||
set_be32(&hdr_info.sz_unc, f_ptr - (upx_bytep) ibuf);
|
||||
set_be32(&hdr_info.sz_cpr, f_len);
|
||||
fo->write(&hdr_info, 2*sizeof(unsigned)); fo_off += 2*sizeof(unsigned);
|
||||
ppc32_extra += 2*sizeof(unsigned);
|
||||
}
|
||||
|
||||
#if 0 /*{ Documentation: changes to arch/powerpc/boot/main.c */
|
||||
struct b_info {
|
||||
unsigned sz_unc;
|
||||
unsigned sz_cpr;
|
||||
unsigned char b_method;
|
||||
unsigned char b_ftid;
|
||||
unsigned char b_cto8;
|
||||
unsigned char b_unused;
|
||||
};
|
||||
typedef int (*upx_f_unc)( /* uncompress */
|
||||
unsigned char const *src, unsigned src_len,
|
||||
unsigned char *dst, unsigned *dst_len,
|
||||
int method
|
||||
);
|
||||
typedef int (*upx_f_unf)( /* unfilter */
|
||||
unsigned char *buf,
|
||||
unsigned len,
|
||||
unsigned cto8,
|
||||
unsigned ftid
|
||||
);
|
||||
|
||||
unsigned char const *upx_expand( // return updated src [aligned, too]
|
||||
unsigned char const *src,
|
||||
unsigned char *dst,
|
||||
unsigned *const dst_len,
|
||||
upx_f_unc const f_unc
|
||||
)
|
||||
{
|
||||
if (0==*dst_len) {
|
||||
*dst_len = ((struct b_info const *)src)->sz_unc;
|
||||
}
|
||||
upx_f_unf const f_unf = (upx_f_unf)(sizeof(int) + (char *)f_unc);
|
||||
unsigned total_len = 0;
|
||||
unsigned need = *dst_len;
|
||||
while (0 < need) {
|
||||
struct b_info const *const b_hdr = (struct b_info const *)src;
|
||||
src = (unsigned char const *)(1+ b_hdr);
|
||||
unsigned blk_len = b_hdr->sz_unc;
|
||||
int const rv = (*f_unc)(src, b_hdr->sz_cpr, dst, &blk_len, b_hdr->b_method);
|
||||
if (0!=rv) {
|
||||
printf("decompress error %d\n\r", rv);
|
||||
exit();
|
||||
}
|
||||
if (b_hdr->b_ftid) {
|
||||
(*f_unf)(dst, b_hdr->sz_unc, b_hdr->b_cto8, b_hdr->b_ftid);
|
||||
}
|
||||
src += b_hdr->sz_cpr;
|
||||
src += (3& -(int)src); // 4-byte align
|
||||
dst += b_hdr->sz_unc;
|
||||
total_len += b_hdr->sz_unc;
|
||||
need -= b_hdr->sz_unc;
|
||||
}
|
||||
*dst_len = total_len;
|
||||
return src;
|
||||
}
|
||||
|
||||
void prep_kernel(unsigned long a1, unsigned long a2)
|
||||
{
|
||||
upx_f_unc f_unc = (upx_f_unc)0;
|
||||
|
||||
vmlinuz.addr = (unsigned long)_vmlinux_start;
|
||||
vmlinuz.size = (unsigned long)(_vmlinux_end - _vmlinux_start);
|
||||
|
||||
if (0x55505821 == *(unsigned *)vmlinuz.addr) {
|
||||
/* was compressed by upx */
|
||||
/* Uncompress elfheader */
|
||||
unsigned const *const fwa = (unsigned *)vmlinuz.addr;
|
||||
f_unc = (upx_f_unc)((char *)&fwa[2] + fwa[1]);
|
||||
unsigned dst_len = 0;
|
||||
unsigned char const *src = (unsigned char const *)&fwa[2];
|
||||
src = upx_expand(src, (unsigned char *)elfheader, &dst_len, f_unc);
|
||||
unsigned const src_len = src - (unsigned char const *)&fwa[0];
|
||||
vmlinuz.addr += src_len;
|
||||
vmlinuz.size -= src_len;
|
||||
} else {
|
||||
memcpy(elfheader, (const void *)vmlinuz.addr,
|
||||
sizeof(elfheader));
|
||||
}
|
||||
=====
|
||||
/* Eventually gunzip the kernel */
|
||||
if (f_unc) {
|
||||
/* was compressed by upx */
|
||||
printf("upx_expand (0x%lx <- 0x%lx:0x%0lx)...",
|
||||
vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size);
|
||||
unsigned dst_len = vmlinux.size - elfoffset;
|
||||
upx_expand((unsigned char const *)vmlinuz.addr,
|
||||
(unsigned char *)vmlinux.addr, &dst_len, f_unc);
|
||||
printf("done 0x%lx bytes\n\r", len);
|
||||
} else {
|
||||
memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,
|
||||
vmlinuz.size);
|
||||
/* Skip over the ELF header */
|
||||
#ifdef DEBUG
|
||||
printf("... skipping 0x%lx bytes of ELF header\n\r",
|
||||
elfoffset);
|
||||
#endif
|
||||
vmlinux.addr += elfoffset;
|
||||
}
|
||||
=====
|
||||
}
|
||||
#endif /*}*/
|
||||
|
||||
}
|
||||
else {
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
}
|
||||
unsigned const txt_c_len = ph.c_len;
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
@@ -285,13 +499,13 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
|
||||
shdro[1].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[1].sh_type = Shdr::SHT_PROGBITS;
|
||||
shdro[1].sh_flags = Shdr::SHF_ALLOC | Shdr::SHF_EXECINSTR;
|
||||
shdro[1].sh_offset = fo_off;
|
||||
shdro[1].sh_size = txt_c_len + lsize; // plus more ...
|
||||
shdro[1].sh_offset = fo_off - ppc32_extra;
|
||||
shdro[1].sh_size = ppc32_extra + txt_c_len + lsize; // plus more ...
|
||||
shdro[1].sh_addralign = 1; // default
|
||||
|
||||
fo_off += write_vmlinux_head(fo, &shdro[1]);
|
||||
fo->write(obuf, txt_c_len); fo_off += txt_c_len;
|
||||
unsigned const a = (shdro[1].sh_addralign -1) & (0u-txt_c_len);
|
||||
unsigned const a = (shdro[1].sh_addralign -1) & (0u-(ppc32_extra + txt_c_len));
|
||||
if (0!=a) { // align
|
||||
fo_off += a;
|
||||
shdro[1].sh_size += a;
|
||||
@@ -359,7 +573,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
|
||||
shdro[5].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[5].sh_type = Shdr::SHT_SYMTAB;
|
||||
shdro[5].sh_offset = fo_off;
|
||||
shdro[5].sh_size = 5*sizeof(Sym);
|
||||
shdro[5].sh_size = ((Ehdr::EM_PPC==my_e_machine) + 5)*sizeof(Sym);
|
||||
//shdro[5].sh_flags = Shdr::SHF_INFO_LINK;
|
||||
shdro[5].sh_link = 6; // to .strtab for symbols
|
||||
shdro[5].sh_info = 1+3; // number of non-global symbols [binutils/bfd/elf.c]
|
||||
@@ -386,26 +600,40 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
|
||||
Sym unc_ker;
|
||||
unc_ker.st_name = 1; // 1 byte into strtab
|
||||
unc_ker.st_value = 0;
|
||||
unc_ker.st_size = txt_c_len;
|
||||
unc_ker.st_size = ppc32_extra + txt_c_len;
|
||||
unc_ker.st_info = unc_ker.make_st_info(Sym::STB_GLOBAL, Sym::STT_FUNC);
|
||||
unc_ker.st_other = Sym::STV_DEFAULT;
|
||||
unc_ker.st_shndx = 1; // .text
|
||||
fo->write(&unc_ker, sizeof(unc_ker)); fo_off += sizeof(unc_ker);
|
||||
|
||||
unsigned const lablen = strlen(my_boot_label);
|
||||
if (Ehdr::EM_PPC==my_e_machine) {
|
||||
unc_ker.st_name += 1+ lablen;
|
||||
unc_ker.st_value = unc_ker.st_size;
|
||||
unc_ker.st_size = 0;
|
||||
fo->write(&unc_ker, sizeof(unc_ker)); fo_off += sizeof(unc_ker);
|
||||
}
|
||||
while (0!=*p++) ;
|
||||
shdro[6].sh_name = ptr_diff(p, shstrtab);
|
||||
shdro[6].sh_type = Shdr::SHT_STRTAB;
|
||||
shdro[6].sh_offset = fo_off;
|
||||
shdro[6].sh_size = 2+ lablen; // '\0' before and after
|
||||
shdro[6].sh_size = 2+ lablen + (Ehdr::EM_PPC==my_e_machine)*(1+ 12); // '\0' before and after
|
||||
shdro[6].sh_addralign = 1;
|
||||
fo->seek(1, SEEK_CUR); // the '\0' before
|
||||
fo->write(my_boot_label, 1+ lablen); // include the '\0' terminator
|
||||
if (Ehdr::EM_PPC==my_e_machine) {
|
||||
fo->write("_vmlinux_end", 1+ 12); fo_off += 1+ 12;
|
||||
}
|
||||
fo_off += 2+ lablen;
|
||||
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->write(&ehdro, sizeof(ehdro));
|
||||
fo->write(&shdro, sizeof(shdro));
|
||||
fo->write(&shdro[0], sizeof(shdro));
|
||||
if (Ehdr::EM_PPC==my_e_machine) {
|
||||
fo->seek(sizeof(unsigned), SEEK_CUR);
|
||||
set_be32(&ppc32_extra, ppc32_extra - 2*sizeof(unsigned) + txt_c_len);
|
||||
fo->write(&ppc32_extra, sizeof(ppc32_extra));
|
||||
}
|
||||
|
||||
if (!checkFinalCompressionRatio(fo))
|
||||
throwNotCompressible();
|
||||
@@ -481,7 +709,7 @@ int PackVmlinuxBase<T>::canUnpack()
|
||||
template <class T>
|
||||
void PackVmlinuxBase<T>::unpack(OutputFile *fo)
|
||||
{
|
||||
U32 word;
|
||||
TE32 word;
|
||||
PackHeader const ph_tmp(ph);
|
||||
|
||||
fi->seek(p_note0->sh_offset, SEEK_SET);
|
||||
@@ -547,18 +775,41 @@ const int *PackVmlinuxI386::getFilters() const
|
||||
return filters;
|
||||
}
|
||||
|
||||
const int *PackVmlinuxARM::getCompressionMethods(int method, int level) const
|
||||
const int *PackVmlinuxARMEL::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
return Packer::getDefaultCompressionMethods_8(method, level);
|
||||
}
|
||||
|
||||
const int *PackVmlinuxARMEB::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
return Packer::getDefaultCompressionMethods_8(method, level);
|
||||
}
|
||||
|
||||
const int *PackVmlinuxARM::getFilters() const
|
||||
const int *PackVmlinuxPPC32::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
// No real dependency on LE32.
|
||||
return Packer::getDefaultCompressionMethods_le32(method, level);
|
||||
}
|
||||
|
||||
|
||||
const int *PackVmlinuxARMEL::getFilters() const
|
||||
{
|
||||
static const int f50[] = { 0x50, FT_END };
|
||||
return f50;
|
||||
}
|
||||
|
||||
const int *PackVmlinuxARMEB::getFilters() const
|
||||
{
|
||||
static const int f51[] = { 0x51, FT_END };
|
||||
return f51;
|
||||
}
|
||||
|
||||
const int *PackVmlinuxPPC32::getFilters() const
|
||||
{
|
||||
static const int fd0[] = { 0xd0, FT_END };
|
||||
return fd0;
|
||||
}
|
||||
|
||||
//
|
||||
// Examples as of 2004-07-16 [readelf --segments vmlinux # before fiddling]:
|
||||
//
|
||||
@@ -586,7 +837,7 @@ const int *PackVmlinuxARM::getFilters() const
|
||||
|
||||
bool PackVmlinuxI386::is_valid_e_entry(Addr e_entry)
|
||||
{
|
||||
return 0==(0x000fffff & e_entry); // entry on whole 1MB
|
||||
return 0==(0x000fffff & e_entry); // entry on whole 1 MiB
|
||||
}
|
||||
|
||||
|
||||
@@ -646,18 +897,39 @@ void PackVmlinuxAMD64::buildLoader(const Filter *ft)
|
||||
"LINUX992,IDENTSTR,UPX1HEAD", NULL);
|
||||
}
|
||||
|
||||
bool PackVmlinuxARM::is_valid_e_entry(Addr e_entry)
|
||||
bool PackVmlinuxARMEL::is_valid_e_entry(Addr e_entry)
|
||||
{
|
||||
return 0xc0008000==e_entry;
|
||||
}
|
||||
|
||||
Linker* PackVmlinuxARM::newLinker() const
|
||||
bool PackVmlinuxARMEB::is_valid_e_entry(Addr e_entry)
|
||||
{
|
||||
return 0xc0008000==e_entry;
|
||||
}
|
||||
|
||||
bool PackVmlinuxPPC32::is_valid_e_entry(Addr e_entry)
|
||||
{
|
||||
return 0xc0000000==e_entry;
|
||||
}
|
||||
|
||||
Linker* PackVmlinuxARMEL::newLinker() const
|
||||
{
|
||||
return new ElfLinkerArmLE;
|
||||
}
|
||||
|
||||
Linker* PackVmlinuxARMEB::newLinker() const
|
||||
{
|
||||
return new ElfLinkerArmBE;
|
||||
}
|
||||
|
||||
void PackVmlinuxARM::buildLoader(const Filter *ft)
|
||||
Linker* PackVmlinuxPPC32::newLinker() const
|
||||
{
|
||||
return new ElfLinkerPpc32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PackVmlinuxARMEL::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(stub_arm_linux_kernel_vmlinux, sizeof(stub_arm_linux_kernel_vmlinux));
|
||||
@@ -679,6 +951,53 @@ void PackVmlinuxARM::buildLoader(const Filter *ft)
|
||||
addLoader("IDENTSTR,UPX1HEAD", NULL);
|
||||
}
|
||||
|
||||
void PackVmlinuxARMEB::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(stub_armeb_linux_kernel_vmlinux, sizeof(stub_armeb_linux_kernel_vmlinux));
|
||||
addLoader("LINUX000", NULL);
|
||||
if (ft->id) {
|
||||
assert(ft->calls > 0);
|
||||
addLoader("LINUX010", NULL);
|
||||
}
|
||||
addLoader("LINUX020", NULL);
|
||||
if (ft->id) {
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUX030", NULL);
|
||||
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL);
|
||||
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL);
|
||||
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL);
|
||||
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL);
|
||||
else throwBadLoader();
|
||||
addLoader("IDENTSTR,UPX1HEAD", NULL);
|
||||
}
|
||||
|
||||
void PackVmlinuxPPC32::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(stub_powerpc_linux_kernel_vmlinux, sizeof(stub_powerpc_linux_kernel_vmlinux));
|
||||
addLoader("LINUX000", NULL);
|
||||
if (ft->id) {
|
||||
assert(ft->calls > 0);
|
||||
addLoader("LINUX010", NULL);
|
||||
}
|
||||
addLoader("LINUX020", NULL);
|
||||
if (ft->id) {
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUX030", NULL);
|
||||
if (ph.method == M_NRV2E_LE32) addLoader("NRV2E,NRV_TAIL", NULL);
|
||||
else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B,NRV_TAIL", NULL);
|
||||
else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D,NRV_TAIL", NULL);
|
||||
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL);
|
||||
else throwBadLoader();
|
||||
if (hasLoaderSection("CFLUSH"))
|
||||
addLoader("CFLUSH");
|
||||
|
||||
addLoader("IDENTSTR,UPX1HEAD", NULL);
|
||||
}
|
||||
|
||||
|
||||
static const
|
||||
#include "stub/i386-linux.kernel.vmlinux-head.h"
|
||||
@@ -686,6 +1005,10 @@ static const
|
||||
#include "stub/amd64-linux.kernel.vmlinux-head.h"
|
||||
static const
|
||||
#include "stub/arm-linux.kernel.vmlinux-head.h"
|
||||
static const
|
||||
#include "stub/armeb-linux.kernel.vmlinux-head.h"
|
||||
static const
|
||||
#include "stub/powerpc-linux.kernel.vmlinux-head.h"
|
||||
|
||||
unsigned PackVmlinuxI386::write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
@@ -695,7 +1018,7 @@ unsigned PackVmlinuxI386::write_vmlinux_head(
|
||||
// COMPRESSED_LENGTH
|
||||
fo->write(&stub_i386_linux_kernel_vmlinux_head[0],
|
||||
sizeof(stub_i386_linux_kernel_vmlinux_head)-(1+ 4) +1);
|
||||
U32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4);
|
||||
TE32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4);
|
||||
|
||||
stxt->sh_size += sizeof(stub_i386_linux_kernel_vmlinux_head);
|
||||
|
||||
@@ -710,7 +1033,7 @@ unsigned PackVmlinuxAMD64::write_vmlinux_head(
|
||||
// COMPRESSED_LENGTH
|
||||
fo->write(&stub_amd64_linux_kernel_vmlinux_head[0],
|
||||
sizeof(stub_amd64_linux_kernel_vmlinux_head)-(1+ 4) +1);
|
||||
U32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4);
|
||||
TE32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4);
|
||||
printf(" Compressed length=0x%x\n", ph.c_len);
|
||||
printf("UnCompressed length=0x%x\n", ph.u_len);
|
||||
|
||||
@@ -719,7 +1042,7 @@ printf("UnCompressed length=0x%x\n", ph.u_len);
|
||||
return sizeof(stub_amd64_linux_kernel_vmlinux_head);
|
||||
}
|
||||
|
||||
void PackVmlinuxARM::defineDecompressorSymbols()
|
||||
void PackVmlinuxARMEL::defineDecompressorSymbols()
|
||||
{
|
||||
super::defineDecompressorSymbols();
|
||||
linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
|
||||
@@ -727,6 +1050,22 @@ void PackVmlinuxARM::defineDecompressorSymbols()
|
||||
linker->defineSymbol("METHOD", ph.method);
|
||||
}
|
||||
|
||||
void PackVmlinuxARMEB::defineDecompressorSymbols()
|
||||
{
|
||||
super::defineDecompressorSymbols();
|
||||
linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
|
||||
linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len);
|
||||
linker->defineSymbol("METHOD", ph.method);
|
||||
}
|
||||
|
||||
void PackVmlinuxPPC32::defineDecompressorSymbols()
|
||||
{
|
||||
super::defineDecompressorSymbols();
|
||||
// linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
|
||||
// linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len);
|
||||
// linker->defineSymbol("METHOD", ph.method);
|
||||
}
|
||||
|
||||
void PackVmlinuxI386::defineDecompressorSymbols()
|
||||
{
|
||||
super::defineDecompressorSymbols();
|
||||
@@ -744,7 +1083,7 @@ void PackVmlinuxAMD64::defineDecompressorSymbols()
|
||||
linker->defineSymbol("PHYSICAL_START", phdri[0].p_paddr);
|
||||
}
|
||||
|
||||
unsigned PackVmlinuxARM::write_vmlinux_head(
|
||||
unsigned PackVmlinuxARMEL::write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
)
|
||||
@@ -753,7 +1092,7 @@ unsigned PackVmlinuxARM::write_vmlinux_head(
|
||||
fo->write(&stub_arm_linux_kernel_vmlinux_head[0], 4);
|
||||
|
||||
// Second word
|
||||
U32 tmp_u32;
|
||||
TE32 tmp_u32;
|
||||
unsigned const t = (0xff000000 &
|
||||
BeLePolicy::get32(&stub_arm_linux_kernel_vmlinux_head[4]))
|
||||
| (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
|
||||
@@ -766,10 +1105,40 @@ unsigned PackVmlinuxARM::write_vmlinux_head(
|
||||
return sizeof(stub_arm_linux_kernel_vmlinux_head);
|
||||
}
|
||||
|
||||
|
||||
bool PackVmlinuxARM::has_valid_vmlinux_head()
|
||||
unsigned PackVmlinuxARMEB::write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
)
|
||||
{
|
||||
U32 buf[2];
|
||||
// First word from vmlinux-head.S
|
||||
fo->write(&stub_armeb_linux_kernel_vmlinux_head[0], 4);
|
||||
|
||||
// Second word
|
||||
TE32 tmp_u32;
|
||||
unsigned const t = (0xff000000 &
|
||||
BeLePolicy::get32(&stub_armeb_linux_kernel_vmlinux_head[4]))
|
||||
| (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
|
||||
tmp_u32 = t;
|
||||
fo->write(&tmp_u32, 4);
|
||||
|
||||
stxt->sh_addralign = 4;
|
||||
stxt->sh_size += sizeof(stub_armeb_linux_kernel_vmlinux_head);
|
||||
|
||||
return sizeof(stub_armeb_linux_kernel_vmlinux_head);
|
||||
}
|
||||
|
||||
unsigned PackVmlinuxPPC32::write_vmlinux_head(
|
||||
OutputFile * /*const fo*/,
|
||||
Shdr * /*const stxt*/
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool PackVmlinuxARMEL::has_valid_vmlinux_head()
|
||||
{
|
||||
TE32 buf[2];
|
||||
fi->seek(p_text->sh_offset + sizeof(stub_arm_linux_kernel_vmlinux_head) -8, SEEK_SET);
|
||||
fi->readx(buf, sizeof(buf));
|
||||
//unsigned const word0 = buf[0];
|
||||
@@ -781,6 +1150,34 @@ bool PackVmlinuxARM::has_valid_vmlinux_head()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PackVmlinuxARMEB::has_valid_vmlinux_head()
|
||||
{
|
||||
TE32 buf[2];
|
||||
fi->seek(p_text->sh_offset + sizeof(stub_armeb_linux_kernel_vmlinux_head) -8, SEEK_SET);
|
||||
fi->readx(buf, sizeof(buf));
|
||||
//unsigned const word0 = buf[0];
|
||||
unsigned const word1 = buf[1];
|
||||
if (0xeb==(word1>>24)
|
||||
&& (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PackVmlinuxPPC32::has_valid_vmlinux_head()
|
||||
{
|
||||
TE32 buf[2];
|
||||
fi->seek(p_text->sh_offset + sizeof(stub_powerpc_linux_kernel_vmlinux_head) -8, SEEK_SET);
|
||||
fi->readx(buf, sizeof(buf));
|
||||
//unsigned const word0 = buf[0];
|
||||
unsigned const word1 = buf[1];
|
||||
if (0xeb==(word1>>24)
|
||||
&& (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PackVmlinuxI386::has_valid_vmlinux_head()
|
||||
{
|
||||
unsigned char buf[5];
|
||||
@@ -996,8 +1393,8 @@ bool PackVmlinuxAMD64::has_valid_vmlinux_head()
|
||||
// pushl $0
|
||||
// pushl $ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED
|
||||
// pushl $ PROT_EXEC | PROT_WRITE | PROT_READ
|
||||
// pushl $0x600000 # 6MB length
|
||||
// pushl $0x100000 # 1MB address
|
||||
// pushl $0x600000 # 6 MiB length
|
||||
// pushl $0x100000 # 1 MiB address
|
||||
// call mmap
|
||||
// leal -0x9000(%esp),%esi # expect "lea 0x9000(%esi),%esp" later
|
||||
///* Fall into .text of upx-compressed vmlinux. */
|
||||
@@ -1046,7 +1443,7 @@ const int *PackVmlinuxAMD64::getFilters() const
|
||||
|
||||
bool PackVmlinuxAMD64::is_valid_e_entry(Addr e_entry)
|
||||
{
|
||||
return 0x200000<=e_entry; // 2MB
|
||||
return 0x200000<=e_entry; // 2 MiB
|
||||
}
|
||||
|
||||
Linker* PackVmlinuxAMD64::newLinker() const
|
||||
@@ -1058,6 +1455,7 @@ Linker* PackVmlinuxAMD64::newLinker() const
|
||||
|
||||
// instantiate instances
|
||||
template class PackVmlinuxBase<ElfClass_LE32>;
|
||||
template class PackVmlinuxBase<ElfClass_BE32>;
|
||||
template class PackVmlinuxBase<ElfClass_LE64>;
|
||||
|
||||
|
||||
|
||||
+60
-12
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_VMLINX_H
|
||||
#define __UPX_P_VMLINX_H
|
||||
#define __UPX_P_VMLINX_H 1
|
||||
|
||||
#include "p_elf.h"
|
||||
|
||||
@@ -45,9 +45,9 @@ protected:
|
||||
typedef typename ElfClass::BeLePolicy BeLePolicy;
|
||||
typedef typename ElfClass::ElfITypes ElfITypes;
|
||||
// integral types
|
||||
typedef typename ElfClass::U16 U16;
|
||||
typedef typename ElfClass::U32 U32;
|
||||
typedef typename ElfClass::U64 U64;
|
||||
typedef typename ElfClass::TE16 TE16;
|
||||
typedef typename ElfClass::TE32 TE32;
|
||||
typedef typename ElfClass::TE64 TE64;
|
||||
typedef typename ElfITypes::Addr Addr;
|
||||
// ELF types
|
||||
typedef typename ElfClass::Ehdr Ehdr;
|
||||
@@ -119,14 +119,14 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PackVmlinuxARM : public PackVmlinuxBase<ElfClass_LE32>
|
||||
class PackVmlinuxARMEL : public PackVmlinuxBase<ElfClass_LE32>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_LE32> super;
|
||||
public:
|
||||
PackVmlinuxARM(InputFile *f) : super(f, Ehdr::EM_ARM,
|
||||
PackVmlinuxARMEL(InputFile *f) : super(f, Ehdr::EM_ARM,
|
||||
Ehdr::ELFCLASS32, Ehdr::ELFDATA2LSB, "decompress_kernel") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_ARM; }
|
||||
virtual const char *getName() const { return "vmlinux/ARM"; }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_ARMEL; }
|
||||
virtual const char *getName() const { return "vmlinux/armel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "arm-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
@@ -143,6 +143,54 @@ protected:
|
||||
);
|
||||
};
|
||||
|
||||
class PackVmlinuxARMEB : public PackVmlinuxBase<ElfClass_BE32>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_BE32> super;
|
||||
public:
|
||||
PackVmlinuxARMEB(InputFile *f) : super(f, Ehdr::EM_ARM,
|
||||
Ehdr::ELFCLASS32, Ehdr::ELFDATA2MSB, "decompress_kernel") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_ARMEB; }
|
||||
virtual const char *getName() const { return "vmlinux/armeb"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "armeb-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
virtual bool is_valid_e_entry(Addr);
|
||||
virtual bool has_valid_vmlinux_head();
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
);
|
||||
};
|
||||
|
||||
class PackVmlinuxPPC32 : public PackVmlinuxBase<ElfClass_BE32>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_BE32> super;
|
||||
public:
|
||||
PackVmlinuxPPC32(InputFile *f) : super(f, Ehdr::EM_PPC,
|
||||
Ehdr::ELFCLASS32, Ehdr::ELFDATA2MSB, "_vmlinux_start") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_PPC32; }
|
||||
virtual const char *getName() const { return "vmlinux/ppc32"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "powerpc-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
virtual bool is_valid_e_entry(Addr);
|
||||
virtual bool has_valid_vmlinux_head();
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
class PackVmlinuxAMD64 : public PackVmlinuxBase<ElfClass_LE64>
|
||||
{
|
||||
|
||||
+618
-57
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#include "p_elf.h"
|
||||
#include "file.h"
|
||||
#include "filter.h"
|
||||
#include "packer.h"
|
||||
@@ -51,10 +52,11 @@ static const unsigned bzimage_offset = 0x100000;
|
||||
**************************************************************************/
|
||||
|
||||
PackVmlinuzI386::PackVmlinuzI386(InputFile *f) :
|
||||
super(f), physical_start(0x100000)
|
||||
super(f), physical_start(0x100000), page_offset(0), config_physical_align(0)
|
||||
, filter_len(0)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x218);
|
||||
COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x250);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +75,22 @@ const int *PackVmlinuzI386::getFilters() const
|
||||
return filters;
|
||||
}
|
||||
|
||||
const int *PackBvmlinuzI386::getFilters() const
|
||||
{
|
||||
// The destination buffer might be relocated at runtime.
|
||||
static const int filters[] = {
|
||||
0x49, 0x46,
|
||||
FT_END };
|
||||
return filters;
|
||||
}
|
||||
|
||||
int PackVmlinuzI386::getStrategy(Filter &/*ft*/)
|
||||
{
|
||||
// If user specified the filter, then use it (-2==filter_strategy).
|
||||
// Else try the first two filters, and pick the better (2==filter_strategy).
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
|
||||
bool PackVmlinuzI386::canPack()
|
||||
{
|
||||
@@ -86,8 +104,6 @@ bool PackVmlinuzI386::canPack()
|
||||
|
||||
int PackVmlinuzI386::readFileHeader()
|
||||
{
|
||||
boot_sect_t h;
|
||||
|
||||
setup_size = 0;
|
||||
|
||||
fi->readx(&h, sizeof(h));
|
||||
@@ -111,12 +127,16 @@ int PackVmlinuzI386::readFileHeader()
|
||||
else if (hdrs && (h.load_flags & 1) != 0)
|
||||
{
|
||||
format = UPX_F_BVMLINUZ_i386;
|
||||
// account for 16-bit h.sys_size, wrap around at 20 bits
|
||||
sys_size &= (1 << 20) - 1;
|
||||
}
|
||||
|
||||
if (16u * h.sys_size != sys_size)
|
||||
return 0;
|
||||
if (0x204<=h.version) {
|
||||
if ((16u * h.sys_size) != sys_size)
|
||||
return 0;
|
||||
}
|
||||
else { // h.sys_size is only 2 bytes
|
||||
if ((16u * (0xffff & h.sys_size)) != (~(~0u<<20) & sys_size))
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FIXME: add more checks for a valid kernel
|
||||
|
||||
@@ -124,6 +144,11 @@ int PackVmlinuzI386::readFileHeader()
|
||||
}
|
||||
|
||||
|
||||
static int is_pow2(unsigned const x)
|
||||
{
|
||||
return !(x & (x - 1));
|
||||
}
|
||||
|
||||
// read full kernel into obuf[], gzip-decompress into ibuf[],
|
||||
// return decompressed size
|
||||
int PackVmlinuzI386::decompressKernel()
|
||||
@@ -133,26 +158,96 @@ int PackVmlinuzI386::decompressKernel()
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(obuf, file_size);
|
||||
|
||||
// Find "ljmp $__BOOT_CS,$__PHYSICAL_START" if any.
|
||||
{
|
||||
const upx_byte *base = NULL;
|
||||
unsigned relocated = 0;
|
||||
|
||||
// See startup_32: in linux/arch/i386/boot/compressed/head.S
|
||||
char const *p = (char const *)&obuf[setup_size];
|
||||
for (int j= 0; j < 0x200; ++j, ++p)
|
||||
if (0==memcmp("\xEA\x00\x00", p, 3) && 0==(0xf & p[3]) && 0==p[4]) {
|
||||
/* whole megabyte < 16MB */
|
||||
physical_start = get_le32(1+ p);
|
||||
break;
|
||||
const upx_byte *p = &obuf[setup_size];
|
||||
unsigned cpa_0 = 0;
|
||||
unsigned cpa_1 = 0;
|
||||
int j;
|
||||
if (0x205<=h.version) {
|
||||
cpa_0 = h.kernel_alignment;
|
||||
cpa_1 = 0u - cpa_0;
|
||||
} else
|
||||
for ((p = &obuf[setup_size]), (j= 0); j < 0x200; ++j, ++p) {
|
||||
if (0==memcmp("\x89\xeb\x81\xc3", p, 4)
|
||||
&& 0==memcmp("\x81\xe3", 8+ p, 2)) {
|
||||
// movl %ebp,%ebx
|
||||
// addl $imm.w,%ebx
|
||||
// andl $imm.w,%ebx
|
||||
cpa_0 = 1+ get_te32( 4+ p);
|
||||
cpa_1 = get_te32(10+ p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for ((p = &obuf[setup_size]), (j= 0); j < 0x200; ++j, ++p) {
|
||||
if (0==memcmp("\x8d\x83", p, 2) // leal d32(%ebx),%eax
|
||||
&& 0==memcmp("\xff\xe0", 6+ p, 2) // jmp *%eax
|
||||
) {
|
||||
relocated = get_te32(2+ p);
|
||||
}
|
||||
if (0==memcmp("\xE8\x00\x00\x00\x00\x5D", p, 6)) {
|
||||
// "call 1f; 1f: pop %ebp" determines actual execution address.
|
||||
// linux-2.6.21 (spring 2007) and later; upx stub needs work
|
||||
// unless LOAD_PHYSICAL_ADDR is known.
|
||||
// Allowed code is: linux-2.6.23/arch/x86/head_32.S 2008-01-01
|
||||
// call 1f
|
||||
// 1: popl %ebp
|
||||
// subl $1b, %ebp # 32-bit immediate
|
||||
// movl $LOAD_PHYSICAL_ADDR, %ebx
|
||||
//
|
||||
if (0==memcmp("\x81\xed", 6+ p, 2) // subl $imm.w,%ebp
|
||||
&& 0==memcmp("\xbb", 12+ p, 1) ) { // movl $imm.w,%ebx
|
||||
physical_start = get_te32(13+ p);
|
||||
} else
|
||||
if (0==memcmp("\x81\xed", 6+ p, 2) // subl $imm.w,%ebp
|
||||
&& is_pow2(cpa_0) && (0u-cpa_0)==cpa_1) {
|
||||
base = (5+ p) - get_te32(8+ p);
|
||||
config_physical_align = cpa_0;
|
||||
}
|
||||
else {
|
||||
throwCantPack("Unrecognized relocatable kernel");
|
||||
}
|
||||
}
|
||||
// Find "ljmp $__BOOT_CS,$__PHYSICAL_START" if any.
|
||||
if (0==memcmp("\xEA\x00\x00", p, 3) && 0==(0xf & p[3]) && 0==p[4]) {
|
||||
/* whole megabyte < 16 MiB */
|
||||
physical_start = get_te32(1+ p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (base && relocated) {
|
||||
p = base + relocated;
|
||||
for (j = 0; j < 0x200; ++j, ++p) {
|
||||
if (0==memcmp("\x01\x9c\x0b", p, 3) // addl %ebx,d32(%ebx,%ecx)
|
||||
) {
|
||||
page_offset = 0u - get_te32(3+ p);
|
||||
}
|
||||
if (0==memcmp("\x89\xeb", p, 2) // movl %ebp,%ebx
|
||||
&& 0==memcmp("\x81\xeb", 2+ p, 2) // subl $imm32,%ebx
|
||||
) {
|
||||
physical_start = get_te32(4+ p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, (off_t)1024));
|
||||
|
||||
for (int gzoff = setup_size; gzoff < file_size; gzoff++)
|
||||
int gzoff = setup_size;
|
||||
if (0x208<=h.version) {
|
||||
gzoff += h.payload_offset;
|
||||
}
|
||||
for (; gzoff < file_size; gzoff++)
|
||||
{
|
||||
// find gzip header (2 bytes magic + 1 byte method "deflated")
|
||||
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3);
|
||||
if (off < 0)
|
||||
break;
|
||||
gzoff += off;
|
||||
const int gzlen = file_size - gzoff;
|
||||
const int gzlen = (h.version < 0x208) ? (file_size - gzoff) : h.payload_length;
|
||||
if (gzlen < 256)
|
||||
break;
|
||||
// check gzip flag byte
|
||||
@@ -201,6 +296,49 @@ int PackVmlinuzI386::decompressKernel()
|
||||
if (klen <= gzlen)
|
||||
continue;
|
||||
|
||||
if (0x208<=h.version && 0==memcmp("\177ELF", ibuf, 4)) {
|
||||
// Full ELF in theory; for now, try to handle as .bin at physical_start.
|
||||
// Check for PT_LOAD.p_paddr being ascending and adjacent.
|
||||
Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)(void const *)ibuf;
|
||||
Elf_LE32_Phdr const *phdr = (Elf_LE32_Phdr const *)(ehdr->e_phoff + (char const *)ehdr);
|
||||
Elf_LE32_Shdr const *shdr = (Elf_LE32_Shdr const *)(ehdr->e_shoff + (char const *)ehdr);
|
||||
unsigned hi_paddr = 0, lo_paddr = 0;
|
||||
unsigned delta_off = 0;
|
||||
for (unsigned j=0; j < ehdr->e_phnum; ++j, ++phdr) {
|
||||
if (phdr->PT_LOAD==phdr->p_type) {
|
||||
unsigned step = (hi_paddr + phdr->p_align - 1) & ~(phdr->p_align - 1);
|
||||
if (0==hi_paddr) { // first PT_LOAD
|
||||
if (physical_start!=phdr->p_paddr) {
|
||||
return 0;
|
||||
}
|
||||
delta_off = phdr->p_paddr - phdr->p_offset;
|
||||
lo_paddr = phdr->p_paddr;
|
||||
hi_paddr = phdr->p_filesz + phdr->p_paddr;
|
||||
}
|
||||
else if (step==phdr->p_paddr
|
||||
&& delta_off==(phdr->p_paddr - phdr->p_offset)) {
|
||||
hi_paddr = phdr->p_filesz + phdr->p_paddr;
|
||||
}
|
||||
else {
|
||||
return 0; // Not equivalent to a .bin. Too complex for now.
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME: ascending order is only a convention; might need sorting.
|
||||
for (unsigned j=1; j < ehdr->e_shnum; ++j) {
|
||||
if (shdr->SHT_PROGBITS==shdr->sh_type) { // SHT_REL might be intermixed
|
||||
if (shdr->SHF_EXECINSTR & shdr[j].sh_flags) {
|
||||
filter_len += shdr[j].sh_size; // FIXME: include sh_addralign
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
memmove(ibuf, (lo_paddr - delta_off) + ibuf, hi_paddr - lo_paddr); // FIXME: set_size
|
||||
// FIXME: .bss ? Apparently handled by head.S
|
||||
}
|
||||
|
||||
if (opt->force > 0)
|
||||
return klen;
|
||||
|
||||
@@ -208,15 +346,24 @@ int PackVmlinuzI386::decompressKernel()
|
||||
if (fd_pos != file_size)
|
||||
{
|
||||
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
|
||||
throwCantPack("trailing bytes after kernel image; use option '-f' to force packing");
|
||||
|
||||
// linux-2.6.21.5/arch/i386/boot/compressed/vmlinux.lds
|
||||
// puts .data.compressed ahead of .text, .rodata, etc;
|
||||
// so piggy.o need not be last in bzImage. Alas.
|
||||
//throwCantPack("trailing bytes after kernel image; use option '-f' to force packing");
|
||||
}
|
||||
|
||||
|
||||
// see /usr/src/linux/arch/i386/kernel/head.S
|
||||
// 2.4.x: cld; mov $...,%eax
|
||||
if (memcmp(ibuf, "\xFC\xB8", 2) == 0) goto head_ok;
|
||||
// 2.6.x: cld; lgdt ...
|
||||
if (memcmp(ibuf, "\xFC\x0F\x01", 3) == 0) goto head_ok;
|
||||
// 2.4.x: [cli;] cld; mov $...,%eax
|
||||
if (memcmp(ibuf, "\xFC\xB8", 2) == 0) goto head_ok;
|
||||
if (memcmp(ibuf, "\xFA\xFC\xB8", 3) == 0) goto head_ok;
|
||||
// 2.6.21.5 CONFIG_PARAVIRT mov %cs,%eax; test $3,%eax; jne ...;
|
||||
if (memcmp(ibuf, "\x8c\xc8\xa9\x03\x00\x00\x00\x0f\x85", 9) == 0) goto head_ok;
|
||||
if (memcmp(ibuf, "\x8c\xc8\xa8\x03\x0f\x85", 6) == 0) goto head_ok;
|
||||
// 2.6.x: [cli;] cld; lgdt ...
|
||||
if (memcmp(ibuf, "\xFC\x0F\x01", 3) == 0) goto head_ok;
|
||||
if (memcmp(ibuf, "\xFA\xFC\x0F\x01", 4) == 0) goto head_ok;
|
||||
// 2.6.x+grsecurity+strongswan+openwall+trustix: ljmp $0x10,...
|
||||
if (ibuf[0] == 0xEA && memcmp(ibuf+5, "\x10\x00", 2) == 0) goto head_ok;
|
||||
// x86_64 2.6.x
|
||||
@@ -227,6 +374,15 @@ int PackVmlinuzI386::decompressKernel()
|
||||
&& 0x0F==ibuf[19] && 0xA2==ibuf[20] // cpuid
|
||||
) goto head_ok;
|
||||
|
||||
// cmpw $0x207,0x206(%esi) Debian vmlinuz-2.6.24-12-generic
|
||||
if (0==memcmp("\x66\x81\xbe\x06\x02\x00\x00\x07\x02", ibuf, 9)) goto head_ok;
|
||||
|
||||
// testb $0x40,0x211(%esi) Fedora vmlinuz-2.6.25-0.218.rc8.git7.fc9.i686
|
||||
if (0==memcmp("\xf6\x86\x11\x02\x00\x00\x40", ibuf, 7)) goto head_ok;
|
||||
|
||||
// rex.W prefix for x86_64
|
||||
if (0x48==ibuf[0]) throwCantPack("x86_64 bzImage is not yet supported");
|
||||
|
||||
throwCantPack("unrecognized kernel architecture; use option '-f' to force packing");
|
||||
head_ok:
|
||||
|
||||
@@ -275,7 +431,7 @@ void PackVmlinuzI386::buildLoader(const Filter *ft)
|
||||
// prepare loader
|
||||
initLoader(stub_i386_linux_kernel_vmlinuz, sizeof(stub_i386_linux_kernel_vmlinuz));
|
||||
addLoader("LINUZ000",
|
||||
ph.first_offset_found == 1 ? "LINUZ001" : "",
|
||||
ph.first_offset_found == 1 ? "LINUZ010" : "",
|
||||
ft->id ? "LZCALLT1" : "",
|
||||
"LZIMAGE0",
|
||||
getDecompressorSections(),
|
||||
@@ -303,8 +459,8 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
||||
// compress
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
|
||||
@@ -321,6 +477,7 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
||||
|
||||
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16u) / 16;
|
||||
bs->payload_length = ph.c_len;
|
||||
|
||||
fo->write(setup_buf, setup_buf.getSize());
|
||||
fo->write(loader, lsize);
|
||||
@@ -348,24 +505,33 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(stub_i386_linux_kernel_vmlinuz, sizeof(stub_i386_linux_kernel_vmlinuz));
|
||||
addLoader("LINUZ000",
|
||||
ph.first_offset_found == 1 ? "LINUZ001" : "",
|
||||
if (0!=page_offset) { // relocatable kernel
|
||||
assert(0==ft->id || 0x40==(0xf0 & ft->id)); // others assume fixed buffer address
|
||||
addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ101,LINUZ110",
|
||||
((0!=config_physical_align) ? "LINUZ120" : "LINUZ130"),
|
||||
"LINUZ140,LZCUTPOI,LINUZ141",
|
||||
(ft->id ? "LINUZ145" : ""),
|
||||
(ph.first_offset_found == 1 ? "LINUZ010" : ""),
|
||||
NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ005",
|
||||
ph.first_offset_found == 1 ? "LINUZ010" : "",
|
||||
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
|
||||
"LBZIMAGE,IDENTSTR",
|
||||
"+40", // align the stuff to 4 byte boundary
|
||||
"UPX1HEAD", // 32 byte
|
||||
"LZCUTPOI",
|
||||
NULL);
|
||||
// fake alignment for the start of the decompressor
|
||||
//linker->defineSymbol("LZCUTPOI", 0x1000);
|
||||
}
|
||||
|
||||
// fake alignment for the start of the decompressor
|
||||
linker->defineSymbol("LZCUTPOI", 0x1000);
|
||||
addLoader(getDecompressorSections(), NULL);
|
||||
|
||||
addLoader(getDecompressorSections(),
|
||||
NULL
|
||||
);
|
||||
if (ft->id)
|
||||
{
|
||||
assert(ft->calls > 0);
|
||||
assert(ft->calls > 0);
|
||||
if (0x40==(0xf0 & ft->id)) {
|
||||
addLoader("LZCKLLT9", NULL);
|
||||
}
|
||||
@@ -374,7 +540,27 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
|
||||
}
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUZ990", NULL);
|
||||
if (0!=page_offset) {
|
||||
addLoader("LINUZ150,IDENTSTR,+40,UPX1HEAD", NULL);
|
||||
unsigned const l_len = getLoaderSize();
|
||||
unsigned const c_len = ALIGN_UP(ph.c_len, 4u);
|
||||
unsigned const e_len = getLoaderSectionStart("LINUZ141") -
|
||||
getLoaderSectionStart("LINUZ110");
|
||||
linker->defineSymbol("compressed_length", c_len);
|
||||
linker->defineSymbol("load_physical_address", physical_start); // FIXME
|
||||
if (0!=config_physical_align) {
|
||||
linker->defineSymbol("neg_config_physical_align", 0u - config_physical_align);
|
||||
}
|
||||
linker->defineSymbol("neg_length_mov", 0u - ALIGN_UP(c_len + l_len, 4u));
|
||||
linker->defineSymbol("neg_page_offset", 0u - page_offset);
|
||||
//linker->defineSymbol("physical_start", physical_start);
|
||||
linker->defineSymbol("unc_length", ph.u_len);
|
||||
linker->defineSymbol("dec_offset", ph.overlap_overhead + e_len);
|
||||
linker->defineSymbol("unc_offset", ph.overlap_overhead + ph.u_len - c_len);
|
||||
}
|
||||
else {
|
||||
addLoader("LINUZ990", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -384,13 +570,17 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
||||
|
||||
// prepare filter
|
||||
Filter ft(ph.level);
|
||||
ft.buf_len = ph.u_len;
|
||||
ft.addvalue = physical_start; // saves 4 bytes in unfilter code
|
||||
ft.buf_len = (filter_len ? filter_len : (ph.u_len * 3)/5);
|
||||
// May 2008: 3/5 is heuristic to cover most .text but avoid non-instructions.
|
||||
// Otherwise "call trick" filter cannot find a free marker byte,
|
||||
// especially when it searches over tables of data.
|
||||
ft.addvalue = 0; // The destination buffer might be relocated at runtime.
|
||||
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
// LINUZ001 allows most of low memory as stack for Bvmlinuz
|
||||
cconf.conf_lzma.max_num_probs = (0x90000 - 0x10000)>>1; // ushort: 512 KiB stack
|
||||
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
|
||||
// align everything to dword boundary - it is easier to handle
|
||||
unsigned c_len = ph.c_len;
|
||||
@@ -418,21 +608,25 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
||||
const int e_len = getLoaderSectionStart("LZCUTPOI");
|
||||
assert(e_len > 0);
|
||||
|
||||
const unsigned d_len4 = ALIGN_UP(lsize - e_len, 4u);
|
||||
const unsigned decompr_pos = ALIGN_UP(ph.u_len + ph.overlap_overhead, 16u);
|
||||
const unsigned copy_size = c_len + d_len4;
|
||||
const unsigned edi = decompr_pos + d_len4 - 4; // copy to
|
||||
const unsigned esi = ALIGN_UP(c_len + lsize, 4u) - 4; // copy from
|
||||
if (0==page_offset) { // not relocatable kernel
|
||||
const unsigned d_len4 = ALIGN_UP(lsize - e_len, 4u);
|
||||
const unsigned decompr_pos = ALIGN_UP(ph.u_len + ph.overlap_overhead, 16u);
|
||||
const unsigned copy_size = c_len + d_len4;
|
||||
const unsigned edi = decompr_pos + d_len4 - 4; // copy to
|
||||
const unsigned esi = ALIGN_UP(c_len + lsize, 4u) - 4; // copy from
|
||||
|
||||
linker->defineSymbol("decompressor", decompr_pos - bzimage_offset + physical_start);
|
||||
linker->defineSymbol("src_for_decompressor", physical_start + decompr_pos - c_len);
|
||||
linker->defineSymbol("words_to_copy", copy_size / 4);
|
||||
linker->defineSymbol("copy_dest", physical_start + edi);
|
||||
linker->defineSymbol("copy_source", bzimage_offset + esi);
|
||||
linker->defineSymbol("decompressor", decompr_pos - bzimage_offset + physical_start);
|
||||
linker->defineSymbol("src_for_decompressor", physical_start + decompr_pos - c_len);
|
||||
linker->defineSymbol("words_to_copy", copy_size / 4);
|
||||
linker->defineSymbol("copy_dest", physical_start + edi);
|
||||
linker->defineSymbol("copy_source", bzimage_offset + esi);
|
||||
}
|
||||
|
||||
defineFilterSymbols(&ft);
|
||||
defineDecompressorSymbols();
|
||||
linker->defineSymbol("original_entry", physical_start);
|
||||
if (0==page_offset) {
|
||||
linker->defineSymbol("original_entry", physical_start);
|
||||
}
|
||||
linker->defineSymbol("stack_offset", stack_offset_during_uncompression);
|
||||
relocateLoader();
|
||||
|
||||
@@ -441,11 +635,21 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
||||
patchPackHeader(loader, lsize);
|
||||
|
||||
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||
bs->sys_size = (ALIGN_UP(lsize + c_len, 16u) / 16) & 0xffff;
|
||||
bs->sys_size = (ALIGN_UP(lsize + c_len, 16u) / 16);
|
||||
|
||||
fo->write(setup_buf, setup_buf.getSize());
|
||||
fo->write(loader, e_len);
|
||||
|
||||
unsigned const e_pfx = (0==page_offset) ? 0 : getLoaderSectionStart("LINUZ110");
|
||||
if (0!=page_offset) {
|
||||
fo->write(loader, e_pfx);
|
||||
}
|
||||
else {
|
||||
fo->write(loader, e_len);
|
||||
}
|
||||
fo->write(obuf, c_len);
|
||||
if (0!=page_offset) {
|
||||
fo->write(loader + e_pfx, e_len - e_pfx);
|
||||
}
|
||||
fo->write(loader + e_len, lsize - e_len);
|
||||
#if 0
|
||||
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
|
||||
@@ -479,7 +683,7 @@ int PackVmlinuzI386::canUnpack()
|
||||
void PackVmlinuzI386::unpack(OutputFile *fo)
|
||||
{
|
||||
// no uncompression support for this format, so that
|
||||
// it is possible to remove the original deflate code (>10KB)
|
||||
// it is possible to remove the original deflate code (>10 KiB)
|
||||
|
||||
// FIXME: but we could write the uncompressed "vmlinux" image
|
||||
|
||||
@@ -507,6 +711,363 @@ void PackVmlinuzI386::unpack(OutputFile *fo)
|
||||
}
|
||||
|
||||
|
||||
PackVmlinuzARMEL::PackVmlinuzARMEL(InputFile *f) :
|
||||
super(f), setup_size(0), filter_len(0)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
}
|
||||
|
||||
const int *PackVmlinuzARMEL::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
return Packer::getDefaultCompressionMethods_8(method, level);
|
||||
}
|
||||
|
||||
const int *PackVmlinuzARMEL::getFilters() const
|
||||
{
|
||||
static const int f50[] = { 0x50, FT_END };
|
||||
return f50;
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::getStrategy(Filter &/*ft*/)
|
||||
{
|
||||
// If user specified the filter, then use it (-2==filter_strategy).
|
||||
// Else try the first two filters, and pick the better (2==filter_strategy).
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
bool PackVmlinuzARMEL::canPack()
|
||||
{
|
||||
return readFileHeader() == getFormat();
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::readFileHeader()
|
||||
{
|
||||
unsigned int hdr[8];
|
||||
|
||||
fi->readx(hdr, sizeof(hdr));
|
||||
for (int j=0; j < 8; ++j) {
|
||||
if (0xe1a00000!=get_te32(&hdr[j])) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return UPX_F_VMLINUZ_ARMEL;
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::decompressKernel()
|
||||
{
|
||||
// read whole kernel image
|
||||
obuf.alloc(file_size);
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(obuf, file_size);
|
||||
|
||||
//checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, (off_t)1024));
|
||||
|
||||
// Find head.S:
|
||||
// bl decompress_kernel # 0xeb......
|
||||
// b call_kernel # 0xea......
|
||||
//LC0: .word LC0 # self!
|
||||
unsigned decompress_kernel = 0;
|
||||
unsigned caller1 = 0;
|
||||
unsigned caller2 = 0;
|
||||
unsigned got_start = 0;
|
||||
unsigned got_end = 0;
|
||||
for (unsigned j = 0; j < 0x400; j+=4) {
|
||||
unsigned w;
|
||||
if (j!=get_te32(j + obuf)) {
|
||||
continue;
|
||||
}
|
||||
if (0xea000000!=(0xff000000& get_te32(j - 4 + obuf))
|
||||
|| 0xeb000000!=(0xff000000&(w= get_te32(j - 8 + obuf))) ) {
|
||||
continue;
|
||||
}
|
||||
caller1 = j - 8;
|
||||
decompress_kernel = ((0x00ffffff & w)<<2) + 8+ caller1;
|
||||
for (unsigned k = 12; k<=128; k+=4) {
|
||||
w = get_te32(j - k + obuf);
|
||||
if (0xeb000000==(0xff000000 & w)
|
||||
&& decompress_kernel==(((0x00ffffff & w)<<2) + 8+ j - k) ) {
|
||||
caller2 = j - k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
got_start = get_te32(5*4 + j + obuf);
|
||||
got_end = get_te32(6*4 + j + obuf);
|
||||
#if 0 /*{*/
|
||||
printf("decompress_kernel=0x%x got_start=0x%x got_end=0x%x\n",
|
||||
decompress_kernel, got_start, got_end);
|
||||
#endif /*}*/
|
||||
break;
|
||||
}
|
||||
if (0==decompress_kernel) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Find first subroutine that is called by decompress_kernel,
|
||||
// which we will consider to be the start of the gunzip module
|
||||
// and the end of the non-gunzip modules.
|
||||
for (unsigned j = decompress_kernel; j < (unsigned)file_size; j+=4) {
|
||||
unsigned w = get_te32(j + obuf);
|
||||
if (0xeb800000==(0xff800000 & w)) {
|
||||
setup_size = 8+ ((0xff000000 | w)<<2) + j;
|
||||
// Move the GlobalOffsetTable.
|
||||
for (unsigned k = got_start; k < got_end; k+=4) {
|
||||
w = get_te32(k + obuf);
|
||||
// FIXME: must relocate w
|
||||
set_te32(k - got_start + setup_size + obuf, w);
|
||||
}
|
||||
setup_size += got_end - got_start;
|
||||
set_te32(&obuf[caller1], 0xeb000000 |
|
||||
(0x00ffffff & ((setup_size - (8+ caller1))>>2)) );
|
||||
set_te32(&obuf[caller2], 0xeb000000 |
|
||||
(0x00ffffff & ((setup_size - (8+ caller2))>>2)) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int gzoff = 0; gzoff < 0x4000; gzoff+=4) {
|
||||
// find gzip header (2 bytes magic + 1 byte method "deflated")
|
||||
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3);
|
||||
if (off < 0 || 0!=(3u & off))
|
||||
break; // not found, or not word-aligned
|
||||
gzoff += off;
|
||||
const int gzlen = file_size - gzoff;
|
||||
if (gzlen < 256)
|
||||
break;
|
||||
// check gzip flag byte
|
||||
unsigned char flags = obuf[gzoff + 3];
|
||||
if ((flags & 0xe0) != 0) // reserved bits set
|
||||
continue;
|
||||
//printf("found gzip header at offset %d\n", gzoff);
|
||||
|
||||
// try to decompress
|
||||
int klen;
|
||||
int fd;
|
||||
off_t fd_pos;
|
||||
for (;;)
|
||||
{
|
||||
klen = -1;
|
||||
fd = -1;
|
||||
fd_pos = -1;
|
||||
// open
|
||||
fi->seek(gzoff, SEEK_SET);
|
||||
fd = dup(fi->getFd());
|
||||
if (fd < 0)
|
||||
break;
|
||||
gzFile zf = gzdopen(fd, "rb");
|
||||
if (zf == NULL)
|
||||
break;
|
||||
// estimate gzip-decompressed kernel size & alloc buffer
|
||||
if (ibuf.getSize() == 0)
|
||||
ibuf.alloc(gzlen * 3);
|
||||
// decompress
|
||||
klen = gzread(zf, ibuf, ibuf.getSize());
|
||||
fd_pos = lseek(fd, 0, SEEK_CUR);
|
||||
gzclose(zf);
|
||||
fd = -1;
|
||||
if (klen != (int)ibuf.getSize())
|
||||
break;
|
||||
// realloc and try again
|
||||
unsigned const s = ibuf.getSize();
|
||||
ibuf.dealloc();
|
||||
ibuf.alloc(3 * s / 2);
|
||||
}
|
||||
if (fd >= 0)
|
||||
(void) close(fd);
|
||||
if (klen <= 0)
|
||||
continue;
|
||||
|
||||
if (klen <= gzlen)
|
||||
continue;
|
||||
|
||||
if (opt->force > 0)
|
||||
return klen;
|
||||
|
||||
// some checks
|
||||
if (fd_pos != file_size) {
|
||||
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
|
||||
}
|
||||
|
||||
//head_ok:
|
||||
|
||||
// FIXME: more checks for special magic bytes in ibuf ???
|
||||
// FIXME: more checks for kernel architecture ???
|
||||
|
||||
return klen;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::readKernel()
|
||||
{
|
||||
int klen = decompressKernel();
|
||||
if (klen <= 0)
|
||||
throwCantPack("kernel decompression failed");
|
||||
//OutputFile::dump("kernel.img", ibuf, klen);
|
||||
|
||||
// copy the setup boot code
|
||||
setup_buf.alloc(setup_size);
|
||||
memcpy(setup_buf, obuf, setup_size);
|
||||
//OutputFile::dump("setup.img", setup_buf, setup_size);
|
||||
|
||||
obuf.dealloc();
|
||||
obuf.allocForCompression(klen);
|
||||
|
||||
ph.u_len = klen;
|
||||
ph.filter = 0;
|
||||
}
|
||||
|
||||
Linker* PackVmlinuzARMEL::newLinker() const
|
||||
{
|
||||
return new ElfLinkerArmLE;
|
||||
}
|
||||
|
||||
static const
|
||||
#include "stub/arm-linux.kernel.vmlinux.h"
|
||||
static const
|
||||
#include "stub/armel-linux.kernel.vmlinuz-head.h"
|
||||
|
||||
void PackVmlinuzARMEL::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader; same as vmlinux (with 'x')
|
||||
initLoader(stub_arm_linux_kernel_vmlinux, sizeof(stub_arm_linux_kernel_vmlinux));
|
||||
addLoader("LINUX000", NULL);
|
||||
if (ft->id) {
|
||||
assert(ft->calls > 0);
|
||||
addLoader("LINUX010", NULL);
|
||||
}
|
||||
addLoader("LINUX020", NULL);
|
||||
if (ft->id) {
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUX030", NULL);
|
||||
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL);
|
||||
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL);
|
||||
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL);
|
||||
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00",
|
||||
(opt->small ? "LZMA_DEC10" : "LZMA_DEC20"), "LZMA_DEC30", NULL);
|
||||
else throwBadLoader();
|
||||
addLoader("IDENTSTR,UPX1HEAD", NULL);
|
||||
|
||||
// To debug (2008-09-14):
|
||||
// Build gdb-6.8-21.fc9.src.rpm; ./configure --target=arm-none-elf; make
|
||||
// Contains the fix for http://bugzilla.redhat.com/show_bug.cgi?id=436037
|
||||
// Install qemu-0.9.1-6.fc9.i386.rpm
|
||||
// qemu-system-arm -s -S -kernel <file> -nographic
|
||||
// (gdb) target remote localhost:1234
|
||||
// A very small boot loader runs at pc=0x0; the kernel is at 0x10000 (64KiB).
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::defineDecompressorSymbols()
|
||||
{
|
||||
super::defineDecompressorSymbols();
|
||||
linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
|
||||
linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len);
|
||||
linker->defineSymbol("METHOD", ph.method);
|
||||
}
|
||||
|
||||
unsigned PackVmlinuzARMEL::write_vmlinuz_head(OutputFile *const fo)
|
||||
{ // First word from vmlinuz-head.S
|
||||
fo->write(&stub_armel_linux_kernel_vmlinuz_head[0], 4);
|
||||
|
||||
// Second word
|
||||
LE32 tmp_u32;
|
||||
unsigned const t = (0xff000000 &
|
||||
get_te32(&stub_armel_linux_kernel_vmlinuz_head[4]))
|
||||
| (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
|
||||
tmp_u32 = t;
|
||||
fo->write((void const *)&tmp_u32, 4);
|
||||
|
||||
return sizeof(stub_armel_linux_kernel_vmlinuz_head);
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::pack(OutputFile *fo)
|
||||
{
|
||||
readKernel();
|
||||
|
||||
// prepare filter
|
||||
Filter ft(ph.level);
|
||||
ft.buf_len = ph.u_len;
|
||||
ft.addvalue = 0;
|
||||
|
||||
// compress
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 5); // ushort: 52,844 byte stack
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
|
||||
defineDecompressorSymbols();
|
||||
defineFilterSymbols(&ft);
|
||||
relocateLoader();
|
||||
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
patchPackHeader(loader, lsize);
|
||||
|
||||
// boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||
// bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16u) / 16;
|
||||
// bs->payload_length = ph.c_len;
|
||||
|
||||
fo->write(setup_buf, setup_buf.getSize());
|
||||
write_vmlinuz_head(fo);
|
||||
fo->write(obuf, ph.c_len);
|
||||
unsigned const zero = 0;
|
||||
fo->write((void const *)&zero, 3u & (0u - ph.c_len));
|
||||
fo->write(loader, lsize);
|
||||
#if 0
|
||||
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
|
||||
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
|
||||
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
|
||||
#endif
|
||||
|
||||
// verify
|
||||
verifyOverlappingDecompression();
|
||||
|
||||
// finally check the compression ratio
|
||||
if (!checkFinalCompressionRatio(fo))
|
||||
throwNotCompressible();
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::canUnpack()
|
||||
{
|
||||
if (readFileHeader() != getFormat())
|
||||
return false;
|
||||
fi->seek(setup_size, SEEK_SET);
|
||||
return readPackHeader(1024) ? 1 : -1;
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::unpack(OutputFile *fo)
|
||||
{
|
||||
// no uncompression support for this format, so that
|
||||
// it is possible to remove the original deflate code (>10 KiB)
|
||||
|
||||
// FIXME: but we could write the uncompressed "vmlinux" image
|
||||
|
||||
ibuf.alloc(ph.c_len);
|
||||
obuf.allocForUncompression(ph.u_len);
|
||||
|
||||
fi->seek(setup_size + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
|
||||
fi->readx(ibuf, ph.c_len);
|
||||
|
||||
// decompress
|
||||
decompress(ibuf, obuf);
|
||||
|
||||
// unfilter
|
||||
Filter ft(ph.level);
|
||||
ft.init(ph.filter, 0);
|
||||
ft.cto = (unsigned char) ph.filter_cto;
|
||||
ft.unfilter(obuf, ph.u_len);
|
||||
|
||||
// write decompressed file
|
||||
if (fo)
|
||||
{
|
||||
throwCantUnpack("build a new kernel instead :-)");
|
||||
//fo->write(obuf, ph.u_len);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+70
-14
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_VMLINZ_H
|
||||
#define __UPX_P_VMLINZ_H
|
||||
#define __UPX_P_VMLINZ_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.vmlinuz"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
virtual int getStrategy(Filter &);
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
@@ -60,16 +61,15 @@ protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
// virtual const upx_byte *getLoader() const;
|
||||
// virtual upx_byte *getLoader() const;
|
||||
// virtual int getLoaderSize() const;
|
||||
|
||||
struct boot_sect_t
|
||||
{
|
||||
__packed_struct(boot_sect_t)
|
||||
char _[0x1f1];
|
||||
unsigned char setup_sects;
|
||||
char __[2];
|
||||
LE16 sys_size;
|
||||
char ___[8];
|
||||
LE32 sys_size;
|
||||
char ___[6];
|
||||
LE16 boot_flag; // 0xAA55
|
||||
// 0x200
|
||||
char ____[2];
|
||||
@@ -79,15 +79,24 @@ protected:
|
||||
unsigned char load_flags;
|
||||
char ______[2];
|
||||
LE32 code32_start;
|
||||
|
||||
char _7[0x230 - (0x214 + 4)];
|
||||
LE32 kernel_alignment;
|
||||
char relocatable_kernel;
|
||||
char _8[0x248 - (0x234 + 1)];
|
||||
LE32 payload_offset;
|
||||
LE32 payload_length;
|
||||
// some more uninteresting fields here ...
|
||||
// see /usr/src/linux/Documentation/i386/zero-page.txt
|
||||
}
|
||||
__attribute_packed;
|
||||
// see /usr/src/linux/Documentation/i386/boot.txt
|
||||
__packed_struct_end()
|
||||
|
||||
boot_sect_t h;
|
||||
|
||||
MemBuffer setup_buf;
|
||||
int setup_size;
|
||||
unsigned physical_start;
|
||||
unsigned page_offset;
|
||||
unsigned config_physical_align;
|
||||
unsigned filter_len;
|
||||
};
|
||||
|
||||
|
||||
@@ -103,6 +112,7 @@ public:
|
||||
virtual int getFormat() const { return UPX_F_BVMLINUZ_i386; }
|
||||
virtual const char *getName() const { return "bvmlinuz/386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.bvmlinuz"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
|
||||
@@ -139,6 +149,52 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// vmlinuz/armel (gzip compressed Linux kernel image)
|
||||
**************************************************************************/
|
||||
|
||||
class PackVmlinuzARMEL : public Packer
|
||||
{
|
||||
typedef Packer super;
|
||||
public:
|
||||
PackVmlinuzARMEL(InputFile *f);
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUZ_ARMEL; }
|
||||
virtual const char *getName() const { return "vmlinuz/armel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "armel-linux.kernel.vmlinuz"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
virtual int getStrategy(Filter &);
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
virtual int canUnpack();
|
||||
|
||||
protected:
|
||||
virtual int readFileHeader();
|
||||
virtual int decompressKernel();
|
||||
virtual void readKernel();
|
||||
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual unsigned write_vmlinuz_head(OutputFile *const fo);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
// virtual upx_byte *getLoader() const;
|
||||
// virtual int getLoaderSize() const;
|
||||
|
||||
|
||||
MemBuffer setup_buf;
|
||||
int setup_size;
|
||||
// unsigned physical_start;
|
||||
// unsigned page_offset;
|
||||
// unsigned config_physical_align;
|
||||
unsigned filter_len;
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_VXD_H
|
||||
#define __UPX_P_VXD_H
|
||||
#define __UPX_P_VXD_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2007 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user