Compare commits
460 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 099c3d829e | |||
| a1a6d02b6f | |||
| f2ad7fb9c4 | |||
| 1bcf709fcf | |||
| 47fc230893 | |||
| be05d85570 | |||
| f598fa13a9 | |||
| 568859d16f | |||
| b5ed0a637b | |||
| 17eff0aed4 | |||
| 0a3f048eed | |||
| 3cde897557 | |||
| 0500e7d016 | |||
| 778663ae69 | |||
| 636cefb9f3 | |||
| 1236776aa2 | |||
| 51a6a5cca5 | |||
| 3326c86e91 | |||
| b0dbc3fe39 | |||
| decc1efb74 | |||
| 2cf1c32d18 | |||
| fc6e3840b7 | |||
| 5e85c1a11b | |||
| 468bfce599 | |||
| 1e6e4043ed | |||
| 67564513d2 | |||
| ed2633bf95 | |||
| 3e70021406 | |||
| bf8dd31914 | |||
| d4e94f5086 | |||
| ae77fd60bb | |||
| e79c790264 | |||
| 46029bb8a0 | |||
| f74c225338 | |||
| c479fe32b3 | |||
| dc23ee0ad2 | |||
| a5c32db01b | |||
| d7142312c9 | |||
| 283ab0e7ea | |||
| b6dd61cea8 | |||
| 11970d276d | |||
| d618716ec1 | |||
| 4f0f977f04 | |||
| 2c4b1d8a8c | |||
| b2810c6deb | |||
| ceb2b56b71 | |||
| d14fa5f8a4 | |||
| 79263a52ac | |||
| ecb3f83e83 | |||
| f6aedb35ce | |||
| 3b7d25ac49 | |||
| e964d4acf3 | |||
| e306085b81 | |||
| b094ad4f2b | |||
| 19c6b969ab | |||
| acfda848cd | |||
| 52400e2561 | |||
| f62576a2be | |||
| 19bf9f59e9 | |||
| fadf7cfc7b | |||
| ec0c9399fa | |||
| 37b923245d | |||
| 38a676f6f7 | |||
| cd1df6f6b1 | |||
| 4a24fe8c53 | |||
| 6dac3dd248 | |||
| 37d393cbc8 | |||
| 27f155374a | |||
| 8102137ad7 | |||
| 9c46f4653f | |||
| 29b4752d0e | |||
| 2724039c09 | |||
| 6ae4e88475 | |||
| facabd68d7 | |||
| 18f043015e | |||
| ab259a1af9 | |||
| 1dd96a7628 | |||
| 1ee7ecb1f0 | |||
| 67548a4d9a | |||
| 9fbe95ad48 | |||
| 91c15b2475 | |||
| c9550b48d8 | |||
| a1d090a6fd | |||
| 4870765e1b | |||
| d8be2ed276 | |||
| 2b371e99bd | |||
| 005e39871b | |||
| 96dd9eeb44 | |||
| 65b06f6046 | |||
| 0515be4334 | |||
| e32de83758 | |||
| e767461f65 | |||
| 632c7c4826 | |||
| 7f9d381c7b | |||
| 4d5d6661d5 | |||
| b0b87eda02 | |||
| f63a673a8b | |||
| 290dd0c5d2 | |||
| 194bf2b852 | |||
| d6d5e7ae3d | |||
| 39a6cc4b5f | |||
| a24de15060 | |||
| eb021accd1 | |||
| 98a77dde00 | |||
| 854988bc5f | |||
| bfeed2ab9a | |||
| d11fc71e79 | |||
| f1703fa322 | |||
| 06675acc67 | |||
| 57ad6bc37d | |||
| 0192b0b7e4 | |||
| 3b098b845a | |||
| ac398f1ffe | |||
| 92dfb9c83c | |||
| 38d6cb090c | |||
| e93172bd33 | |||
| 30fcca4b64 | |||
| 4f6320d3aa | |||
| 62dbf8485f | |||
| 9331ed39d4 | |||
| 35dd9cfd22 | |||
| 0ac6c36af2 | |||
| 3c4b959f78 | |||
| a00687b092 | |||
| bb6b087862 | |||
| bfb438dc89 | |||
| cd3f69c290 | |||
| d54315392e | |||
| cfa8107ab9 | |||
| f4e5b29708 | |||
| d65fea1147 | |||
| 25a3c109c1 | |||
| b526eed346 | |||
| 59c6a71b72 | |||
| c7a2a0faa1 | |||
| bfb5ea50a9 | |||
| 149d84edca | |||
| 7636abc158 | |||
| 6eace187e7 | |||
| dd1838a7eb | |||
| dd928cf956 | |||
| 38be230467 | |||
| 1f747a28a9 | |||
| 1a7732b285 | |||
| f8ea416a4d | |||
| b9bf81d548 | |||
| 8975e2a6b5 | |||
| 394cd77bec | |||
| a9ac4b5e23 | |||
| 10e759f1f1 | |||
| 777d4f5279 | |||
| c65c882ecc | |||
| a66ee9fafd | |||
| 757401dd0c | |||
| 11e3770864 | |||
| fbb317e9c8 | |||
| 9d7698a359 | |||
| 44fd11f4dd | |||
| 8779113131 | |||
| 26cfd0a616 | |||
| 75e153dd99 | |||
| fa364d6ea3 | |||
| 13e5c13695 | |||
| 43b3b54197 | |||
| 3a16d4a12e | |||
| 50fc9235de | |||
| 70287d3c49 | |||
| 41e9f7985f | |||
| c3327977da | |||
| 905bfacf44 | |||
| 053e95033f | |||
| 5a1203be0d | |||
| 745fef7425 | |||
| c9d625a237 | |||
| 334731f56b | |||
| d5e7672a45 | |||
| e702aa0252 | |||
| 2684e815e0 | |||
| efbc93229a | |||
| 05539ad5b6 | |||
| 670aae2e11 | |||
| e6ff68dc2c | |||
| 641b116f04 | |||
| f81f7194ed | |||
| 161d20e614 | |||
| fc4dcd46db | |||
| 891dc87064 | |||
| b866631448 | |||
| 672d69c68a | |||
| 507c31ec14 | |||
| 65cc40bdda | |||
| 067895fa5f | |||
| 3f7f26c74b | |||
| 9a6b5940cf | |||
| 828f4a63bf | |||
| 707fb55625 | |||
| 8d41ae09c8 | |||
| 7ec0faca1e | |||
| 300fa29446 | |||
| 6981f7b3ae | |||
| 682a1e97e4 | |||
| 1d71dd3851 | |||
| 5edfda46e5 | |||
| d7754a97c7 | |||
| c79aa6ad8a | |||
| 525e091472 | |||
| 16f6de677d | |||
| 12c36bab6c | |||
| c429859cbf | |||
| dc76b2af97 | |||
| b75e7687f4 | |||
| ece5af2895 | |||
| 1aaa33552e | |||
| f622871eb0 | |||
| 060b01260d | |||
| 871f8a4793 | |||
| c54e03d0f2 | |||
| aaf3f75990 | |||
| 512a26cee4 | |||
| b4a793ed26 | |||
| 5d2c74008e | |||
| 7fafc68940 | |||
| d1af2af499 | |||
| a5206eb696 | |||
| 1ff0d137ab | |||
| 07aa65b55e | |||
| 0fadddec65 | |||
| 1bebe53cef | |||
| 43019c744c | |||
| c585774162 | |||
| 75e87a58da | |||
| 19e84fea62 | |||
| db39f9c4dc | |||
| dae45ae0d4 | |||
| efeffc6e01 | |||
| ebf0f2f68a | |||
| 09bd1d8c40 | |||
| 40653e40a4 | |||
| b3e4efbabe | |||
| 279101d464 | |||
| f571feee72 | |||
| 900afd1c8c | |||
| 08a72d5251 | |||
| 736a6cd955 | |||
| 75ce5e5df3 | |||
| eaf2143162 | |||
| f0bdb8dea1 | |||
| 60093cfff6 | |||
| 56bb7b53cb | |||
| 0cffeca102 | |||
| 937d4462ca | |||
| db5a39572c | |||
| ecc9c67e1f | |||
| 0901ce1b68 | |||
| be6e77379a | |||
| 726f5de778 | |||
| 98b835e0a7 | |||
| 04ffb641a6 | |||
| 1b7233b673 | |||
| eaa0f33473 | |||
| c03b382d61 | |||
| e633694255 | |||
| 278b25bad2 | |||
| f89f0838dc | |||
| b1729e3bcf | |||
| d1ab85a1a6 | |||
| 7f5b64c91a | |||
| 78b68283c4 | |||
| 9e3b1c9f8a | |||
| 5dc54c7adc | |||
| 320e5b850f | |||
| d8395d8c42 | |||
| a20c5a1e7f | |||
| 3bdfcaa541 | |||
| 7b2faf2016 | |||
| 42902dabac | |||
| 14521eb6dd | |||
| b9533f409c | |||
| 4df68aafd2 | |||
| c72ceaa979 | |||
| 8ac79ca0ad | |||
| e0bfaf1028 | |||
| b361b91ec7 | |||
| b5d1eba4c1 | |||
| ba447344d6 | |||
| 7b68aa7bdc | |||
| 5d15e57294 | |||
| 0bf8ff151e | |||
| 06fae05910 | |||
| f68ac8155b | |||
| 15484aa296 | |||
| 5b113a5041 | |||
| 1320e3efdb | |||
| d32f447bda | |||
| b74c4e4ac1 | |||
| 35333403ef | |||
| a627648249 | |||
| 127fd095e7 | |||
| f8934c09ff | |||
| 7a09c88e30 | |||
| 17526d1132 | |||
| ff7939c1c0 | |||
| 96c196b1be | |||
| adb0ca8250 | |||
| fa56a1d9cd | |||
| 3d691645a4 | |||
| e1edc5f50a | |||
| 4a8efd2e2f | |||
| 8d364c82e2 | |||
| c5059231dc | |||
| f584c91386 | |||
| b8d9c2b755 | |||
| 163377d1a0 | |||
| 8944e90175 | |||
| 33cdcb0e82 | |||
| ec870a5aeb | |||
| 0653bb5a72 | |||
| 43b6ff29e3 | |||
| a444a8a704 | |||
| 3fa18c1799 | |||
| 19147963b9 | |||
| 5056215a1f | |||
| 340b7614e2 | |||
| 8a1bd67a20 | |||
| a094df7b55 | |||
| cc893dfc11 | |||
| 8ef17da082 | |||
| 7993e619cd | |||
| 1ab8d5fb3f | |||
| 213ac3ac73 | |||
| 0a8876443a | |||
| f37a3bb9bb | |||
| 2632342f44 | |||
| 8efcf6f099 | |||
| 58343fc78d | |||
| 6c41a4c9c8 | |||
| 334be287fc | |||
| aa050e0001 | |||
| cc994326a0 | |||
| 58de07629e | |||
| 9f830e0c41 | |||
| c52d302f07 | |||
| 44049ecf30 | |||
| e1b5904196 | |||
| 88e692791a | |||
| f00667ad7d | |||
| 696d0eec64 | |||
| 513b00a30e | |||
| 0cb0dbf6d8 | |||
| 9f00515da4 | |||
| 72f31787f6 | |||
| cd686cb1d9 | |||
| d9657e9831 | |||
| 72f3e9b25a | |||
| 811b15a5b3 | |||
| ab00825f37 | |||
| e86d9179aa | |||
| 26d8e9c4c5 | |||
| 5f3ebc8a7f | |||
| 425b1b44bc | |||
| 39442e6282 | |||
| 99575e1010 | |||
| 64aa7540e2 | |||
| 3ff5dbd179 | |||
| e25d04fb12 | |||
| dd1d5a92d2 | |||
| c6e0aad40b | |||
| 99b795ceaa | |||
| 33dc60df26 | |||
| 619aeb54ff | |||
| 77ba43328b | |||
| 01a30752c7 | |||
| e56b748435 | |||
| bb4cbdff44 | |||
| 0b47e474a7 | |||
| 8e85680eb4 | |||
| fefce0d5c4 | |||
| 0ac3cb2329 | |||
| 708ab1dcd7 | |||
| 9b87ddb621 | |||
| 5dc4eb4b03 | |||
| a203c72281 | |||
| 6cf85cee6e | |||
| 1eb6a40fdd | |||
| 1bed77e4d3 | |||
| f2a68023fa | |||
| 8ccffc40e3 | |||
| dd8c1d0441 | |||
| f9f28ff176 | |||
| 3649041195 | |||
| c23c7a9379 | |||
| 9934e33b99 | |||
| 9e75fdda66 | |||
| d873a26f41 | |||
| 91aa5b55ab | |||
| 3f460a76ce | |||
| 7256ea3b32 | |||
| 4cdf77e16f | |||
| d89813e911 | |||
| 7c57b10cae | |||
| 8d1a98e03b | |||
| 65a2da4b40 | |||
| 02f6786b2a | |||
| 9da4f7a6dc | |||
| 510505a85c | |||
| 741cb3a136 | |||
| 9f5d67e27c | |||
| 93c6496ba8 | |||
| 779b648c5f | |||
| 9d5e06232d | |||
| b221c44466 | |||
| 665296f7cf | |||
| 39778d5f47 | |||
| 0af9bbb623 | |||
| fdec47a83d | |||
| 7ff913bbd2 | |||
| 94775bef9f | |||
| 3cf102334f | |||
| 627e733a30 | |||
| d31b80da5b | |||
| eb231b65f3 | |||
| 59e3b1f98d | |||
| 8b174bb272 | |||
| 4199a44bef | |||
| 777392c0fe | |||
| ede1fec5e7 | |||
| 16de3e78a5 | |||
| d7508d8c09 | |||
| 2a136c1c1d | |||
| 2578102be9 | |||
| dadee7acfb | |||
| 28f0bb4e11 | |||
| 824c8a8efb | |||
| 37f27a1262 | |||
| 2b8a7a492a | |||
| db56bbb11b | |||
| 82d26f04a4 | |||
| 5045f7eb42 | |||
| 82a6ccac4d | |||
| 2d74298001 | |||
| ce21254ed2 | |||
| 874250fe49 | |||
| c8a3acbba8 | |||
| 81e11987a2 | |||
| 668cefec2f | |||
| 212bc04257 | |||
| db401fd05e | |||
| bebe72481c | |||
| 2b9e83256d | |||
| 5763518cce | |||
| 3e4c5bab72 | |||
| bce109ab54 | |||
| 69ca635c4c | |||
| e0bf460993 | |||
| 29762a8a96 | |||
| c7ef08dc2d | |||
| 50a6698715 | |||
| 7dd2cdea1e | |||
| af87f7f2bf | |||
| 295889023f |
+13
-18
@@ -1,28 +1,23 @@
|
|||||||
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
|
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
|
||||||
#
|
#
|
||||||
# for clang-format-10.0.1 from https://github.com/upx/upx-stubtools/releases
|
# for clang-format-15.0.6 from https://github.com/upx/upx-stubtools/releases
|
||||||
---
|
---
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
AccessModifierOffset: -4
|
|
||||||
#AlignConsecutiveAssignments: true
|
|
||||||
AlwaysBreakTemplateDeclarations: true
|
|
||||||
ColumnLimit: 100
|
ColumnLimit: 100
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignConsecutiveMacros: AcrossComments
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
AttributeMacros:
|
||||||
|
- DELETED_FUNCTION
|
||||||
|
- XSPAN_DELETED_FUNCTION
|
||||||
|
- may_throw
|
||||||
|
EmptyLineBeforeAccessModifier: Leave
|
||||||
SortIncludes: false
|
SortIncludes: false
|
||||||
SpaceAfterCStyleCast: true
|
SpaceAfterCStyleCast: true
|
||||||
Standard: Cpp03
|
Standard: Cpp03
|
||||||
StatementMacros: [
|
StatementMacros:
|
||||||
ACCCHK_ASSERT,
|
- CLANG_FORMAT_DUMMY_STATEMENT
|
||||||
ACCCHK_ASSERT_IS_SIGNED_T,
|
|
||||||
ACCCHK_ASSERT_IS_UNSIGNED_T,
|
|
||||||
ACCCHK_ASSERT_SIGN_T,
|
|
||||||
ACC_COMPILE_TIME_ASSERT,
|
|
||||||
ACC_COMPILE_TIME_ASSERT_HEADER,
|
|
||||||
ACC_CXX_DISABLE_NEW_DELETE,
|
|
||||||
ACC_CXX_TRIGGER_FUNCTION,
|
|
||||||
ACC_CXX_TRIGGER_FUNCTION_IMPL,
|
|
||||||
CLANG_FORMAT_DUMMY_STATEMENT,
|
|
||||||
COMPILE_TIME_ASSERT,
|
|
||||||
COMPILE_TIME_ASSERT_ALIGNED1,
|
|
||||||
]
|
|
||||||
...
|
...
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
||||||
|
---
|
||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
-bugprone-assignment-in-if-condition,
|
||||||
|
-bugprone-branch-clone,
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-empty-catch,
|
||||||
|
-bugprone-implicit-widening-of-multiplication-result,
|
||||||
|
-bugprone-macro-parentheses,
|
||||||
|
-bugprone-narrowing-conversions,
|
||||||
|
-bugprone-reserved-identifier,
|
||||||
|
-bugprone-sizeof-expression,
|
||||||
|
-bugprone-suspicious-include,
|
||||||
|
-bugprone-suspicious-memory-comparison,
|
||||||
|
-bugprone-suspicious-string-compare,
|
||||||
|
-bugprone-switch-missing-default-case,
|
||||||
|
clang-analyzer-*,
|
||||||
|
-clang-analyzer-optin.performance.Padding,
|
||||||
|
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
|
||||||
|
-clang-analyzer-security.insecureAPI.strcpy,
|
||||||
|
clang-diagnostics-*',
|
||||||
|
performance-*,
|
||||||
|
-performance-avoid-endl,
|
||||||
|
-performance-unnecessary-value-param,
|
||||||
|
FormatStyle: file
|
||||||
|
HeaderFilterRegex: '.*'
|
||||||
|
InheritParentConfig: false
|
||||||
|
...
|
||||||
+28
-7
@@ -1,10 +1,31 @@
|
|||||||
# make GitHub language detection more accurate, see https://github.com/github/linguist
|
# see https://github.com/github-linguist/linguist
|
||||||
|
#
|
||||||
|
# HINT: check settings with
|
||||||
|
# git ls-files | git check-attr --stdin --all
|
||||||
|
|
||||||
src/*.h linguist-language=C++
|
#
|
||||||
src/*/*.h linguist-language=C++
|
# tell diff tools that these files are generated automatically
|
||||||
|
#
|
||||||
|
|
||||||
src/stub/**/*.ash linguist-language=Assembly
|
/doc/upx.1 linguist-generated
|
||||||
src/stub/**/*.asm linguist-language=Assembly
|
/doc/upx-doc.* linguist-generated
|
||||||
src/stub/**/*.S linguist-language=Assembly
|
|
||||||
|
|
||||||
src/stub/tmp/** linguist-vendored
|
/src/stub/*.h linguist-generated
|
||||||
|
/src/stub/src/arch/**/lzma_d_c[fns].S linguist-generated
|
||||||
|
/src/stub/tmp/** linguist-generated
|
||||||
|
|
||||||
|
/misc/podman/*/packages*.txt linguist-generated
|
||||||
|
/misc/testsuite/*expected_sha256sums* linguist-generated
|
||||||
|
|
||||||
|
#
|
||||||
|
# make GitHub language detection more accurate
|
||||||
|
#
|
||||||
|
|
||||||
|
/src/*.h linguist-language=C++
|
||||||
|
/src/*/*.h linguist-language=C++
|
||||||
|
|
||||||
|
/src/stub/**/*.ash linguist-language=Assembly
|
||||||
|
/src/stub/**/*.asm linguist-language=Assembly
|
||||||
|
/src/stub/**/*.S linguist-language=Assembly
|
||||||
|
|
||||||
|
/src/stub/tmp/** linguist-vendored
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
* @markus-oberhumer @jreiser
|
||||||
|
|
||||||
|
/src/p_lx_* @jreiser
|
||||||
|
/src/p_mach* @jreiser
|
||||||
|
/src/p_unix* @jreiser
|
||||||
|
/src/p_vmlin* @jreiser
|
||||||
|
|
||||||
|
/src/stub/src/*bsd.* @jreiser
|
||||||
|
/src/stub/src/*darwin.* @jreiser
|
||||||
|
/src/stub/src/*linux.* @jreiser
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
version: 2
|
|
||||||
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: 'github-actions'
|
|
||||||
directory: '/'
|
|
||||||
schedule:
|
|
||||||
# Check for updates to GitHub Actions every weekday
|
|
||||||
interval: 'daily'
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
## vim:set ts=4 sw=4 et:
|
|
||||||
set -e; set -o pipefail
|
|
||||||
|
|
||||||
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
|
||||||
|
|
||||||
# ...lots of outdated/unneeded stuff from the old Travis/Circle/AppVeyor CI days...
|
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == osx ]]; then
|
|
||||||
argv0=$0; argv0abs=$(greadlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
|
|
||||||
else
|
|
||||||
argv0=$0; argv0abs=$(readlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
|
|
||||||
fi
|
|
||||||
source "$argv0dir/travis_init.sh" || exit 1
|
|
||||||
|
|
||||||
# create dirs
|
|
||||||
cd / || exit 1
|
|
||||||
mkbuilddirs $upx_BUILDDIR $ucl_BUILDDIR $upx_testsuite_BUILDDIR $zlib_BUILDDIR
|
|
||||||
cd / && cd "$upx_SRCDIR" || exit 1
|
|
||||||
|
|
||||||
echo
|
|
||||||
print_settings
|
|
||||||
echo
|
|
||||||
echo "$CC --version"; $CC --version
|
|
||||||
echo "$CXX --version"; $CXX --version
|
|
||||||
echo
|
|
||||||
|
|
||||||
# check whitespace
|
|
||||||
if [[ $TRAVIS_OS_NAME == linux ]]; then
|
|
||||||
cd / && cd $upx_SRCDIR || exit 1
|
|
||||||
echo "Checking source code for whitespace violations..."
|
|
||||||
bash ./misc/scripts/check_whitespace.sh || exit 1
|
|
||||||
echo " Passed."
|
|
||||||
fi # linux
|
|
||||||
|
|
||||||
set -x
|
|
||||||
|
|
||||||
#
|
|
||||||
# rebuild UPX stubs (needs upx-stubtools)
|
|
||||||
#
|
|
||||||
|
|
||||||
if [[ $BM_X =~ (^|\+)rebuild-stubs($|\+) ]]; then
|
|
||||||
if [[ -f "$HOME/local/bin/bin-upx/upx-stubtools-check-version" ]]; then
|
|
||||||
bin_upx=$(readlink -en -- "$HOME/local/bin/bin-upx")
|
|
||||||
elif [[ -f "$HOME/.local/bin/bin-upx/upx-stubtools-check-version" ]]; then
|
|
||||||
bin_upx=$(readlink -en -- "$HOME/.local/bin/bin-upx")
|
|
||||||
else
|
|
||||||
bin_upx=$(readlink -en -- "$upx_SRCDIR/../deps/bin-upx-20210104")
|
|
||||||
fi
|
|
||||||
cd / && cd "$upx_SRCDIR" || exit 1
|
|
||||||
extra_subdirs=()
|
|
||||||
extra_subdirs+=( src/stub/src/arch/amd64 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/arm/v4a )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/arm/v4t )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/arm64/v8 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/i386 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/m68k/m68000 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/m68k/m68020 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/mips/r3000 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/powerpc/32 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/powerpc/64 )
|
|
||||||
extra_subdirs+=( src/stub/src/arch/powerpc/64le )
|
|
||||||
make -C src/stub maintainer-clean
|
|
||||||
for d in ${extra_subdirs[@]}; do
|
|
||||||
make -C $d -f Makefile.extra maintainer-clean
|
|
||||||
git status $d || true
|
|
||||||
done
|
|
||||||
git status src/stub/src || true
|
|
||||||
git status || true
|
|
||||||
failed=0
|
|
||||||
for d in ${extra_subdirs[@]}; do
|
|
||||||
PATH="$bin_upx:$PATH" make -C $d -f Makefile.extra || failed=1
|
|
||||||
done
|
|
||||||
PATH="$bin_upx:$PATH" make -C src/stub all || failed=1
|
|
||||||
if [[ $failed != 0 ]]; then
|
|
||||||
echo "UPX-ERROR: FATAL: rebuild-stubs failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if ! git diff --quiet; then
|
|
||||||
git status || true
|
|
||||||
git diff || true
|
|
||||||
echo "UPX-ERROR: FATAL: rebuild-stubs git status mismatch. See log file."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
git status
|
|
||||||
if [[ $BM_X == rebuild-stubs ]]; then
|
|
||||||
echo "X=rebuild-stubs done. Exiting."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
unset bin_upx extra_subdirs d failed
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 1
|
|
||||||
@@ -1,273 +0,0 @@
|
|||||||
## vim:set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
|
||||||
|
|
||||||
# ...lots of outdated/unneeded stuff from the old Travis/Circle/AppVeyor CI days...
|
|
||||||
|
|
||||||
#set -x # debug
|
|
||||||
umask 022
|
|
||||||
export GIT_PAGER=
|
|
||||||
|
|
||||||
# rename short variables to more readable Build-Matrix BM_ names
|
|
||||||
# C is COMPILER
|
|
||||||
# B is BUILD_OPTIONS
|
|
||||||
# T is TESTSUITE_OPTIONS
|
|
||||||
# X is EXTRA_OPTIONS
|
|
||||||
BM_CROSS=$CROSS; BM_C=$C; BM_B=$B; BM_T=$T; BM_X=$X
|
|
||||||
unset CROSS C B T X
|
|
||||||
[[ -z $BM_C ]] && BM_C=gcc
|
|
||||||
[[ -z $BM_B ]] && BM_B=release
|
|
||||||
|
|
||||||
# just in case, unset variable for passing extra UPX options
|
|
||||||
export UPX=
|
|
||||||
# un-export some vars
|
|
||||||
declare +x UPX_AUTOMATIC_BUILDS_SSL_KEY UPX_AUTOMATIC_BUILDS_SSL_IV
|
|
||||||
|
|
||||||
# compatibility wrappers
|
|
||||||
if [[ $TRAVIS_OS_NAME == osx ]]; then
|
|
||||||
# use GNU coreutils ("brew install coreutils")
|
|
||||||
chmod() {
|
|
||||||
gchmod "$@"
|
|
||||||
}
|
|
||||||
date() {
|
|
||||||
gdate "$@"
|
|
||||||
}
|
|
||||||
readlink() {
|
|
||||||
greadlink "$@"
|
|
||||||
}
|
|
||||||
sha256sum() {
|
|
||||||
gsha256sum "$@"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
if [[ -n $APPVEYOR_JOB_ID ]]; then
|
|
||||||
openssl() {
|
|
||||||
/usr/bin/openssl "$@"
|
|
||||||
}
|
|
||||||
sort() {
|
|
||||||
/usr/bin/sort "$@"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# set CC and CXX from BM_C and BM_CROSS
|
|
||||||
if [[ -z $CC_OVERRIDE ]]; then
|
|
||||||
CC=false CXX=false SCAN_BUILD=false
|
|
||||||
AR=ar SIZE=size
|
|
||||||
if [[ -n $APPVEYOR_JOB_ID ]]; then
|
|
||||||
BUILD_LOCAL_UCL=1
|
|
||||||
BUILD_LOCAL_ZLIB=1
|
|
||||||
if [[ $BM_C =~ (^|\-)(clang|gcc)($|\-) ]]; then
|
|
||||||
export upx_EXTRA_LDFLAGS="-static-libgcc -static-libstdc++"
|
|
||||||
fi
|
|
||||||
upx_exeext=.exe
|
|
||||||
# dir c:\cygwin
|
|
||||||
case $BM_C in
|
|
||||||
gcc-m32 | gcc-4.9-m32)
|
|
||||||
x=i686-w64-mingw32; AR="$x-ar"; CC="$x-gcc -m32"; CXX="$x-g++ -m32" ;;
|
|
||||||
gcc-m64 | gcc-4.9-m64)
|
|
||||||
x=x86_64-w64-mingw32; AR="$x-ar"; CC="$x-gcc -m64"; CXX="$x-g++ -m64" ;;
|
|
||||||
msvc | msvc-*)
|
|
||||||
AR="link -lib"; CC="cl"; CXX="cl" ;; # standard system compiler
|
|
||||||
esac
|
|
||||||
fi # APPVEYOR_JOB_ID
|
|
||||||
if [[ -n $BM_CROSS ]]; then
|
|
||||||
BUILD_LOCAL_UCL=1
|
|
||||||
BUILD_LOCAL_ZLIB=1
|
|
||||||
if [[ $BM_C =~ (^|\-)(clang|gcc)($|\-) ]]; then
|
|
||||||
export upx_EXTRA_LDFLAGS="-static-libgcc -static-libstdc++"
|
|
||||||
fi
|
|
||||||
cat /etc/os-release || true
|
|
||||||
if grep -E -q '^PRETTY_NAME="?Ubuntu .*12\.04' /etc/os-release; then
|
|
||||||
case $BM_CROSS-$BM_C in
|
|
||||||
arm-linux-gnueabi-gcc | arm-linux-gnueabi-gcc-4.6)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-arm -L /usr/arm-linux-gnueabi"
|
|
||||||
x=arm-linux-gnueabi; AR="$x-ar"; CC="$x-gcc"; CXX="$x-g++" ;;
|
|
||||||
arm-linux-gnueabihf-gcc | arm-linux-gnueabihf-gcc-4.6)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-arm -L /usr/arm-linux-gnueabihf"
|
|
||||||
x=arm-linux-gnueabihf; AR="$x-ar"; CC="$x-gcc"; CXX="$x-g++" ;;
|
|
||||||
i[36]86-w64-mingw32-gcc | i[36]86-w64-mingw32-gcc-4.6)
|
|
||||||
upx_exeext=.exe
|
|
||||||
[[ -z $upx_wine ]] && upx_wine="wine"
|
|
||||||
x=i686-w64-mingw32; AR="$x-ar"; CC="$x-gcc -m32"; CXX="$x-g++ -m32" ;;
|
|
||||||
x86_64-w64-mingw32-gcc | x86_64-w64-mingw32-gcc-4.6)
|
|
||||||
upx_exeext=.exe
|
|
||||||
[[ -z $upx_wine ]] && upx_wine="wine"
|
|
||||||
x=x86_64-w64-mingw32; AR="$x-ar"; CC="$x-gcc -m64"; CXX="$x-g++ -m64" ;;
|
|
||||||
esac
|
|
||||||
elif grep -E -q '^PRETTY_NAME="?Ubuntu 16\.04' /etc/os-release; then
|
|
||||||
case $BM_CROSS-$BM_C in
|
|
||||||
aarch64-linux-gnu-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-aarch64 -L /usr/aarch64-linux-gnu"
|
|
||||||
x=aarch64-linux-gnu; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
arm-linux-gnueabi-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-arm -L /usr/arm-linux-gnueabi"
|
|
||||||
x=arm-linux-gnueabi; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
arm-linux-gnueabihf-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-arm -L /usr/arm-linux-gnueabihf"
|
|
||||||
x=arm-linux-gnueabihf; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
i[36]86-w64-mingw32-gcc-5)
|
|
||||||
upx_exeext=.exe
|
|
||||||
[[ -z $upx_wine ]] && upx_wine="wine"
|
|
||||||
x=i686-w64-mingw32; AR="$x-ar"; CC="$x-gcc -m32"; CXX="$x-g++ -m32" ;;
|
|
||||||
mips-linux-gnu-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-mips -L /usr/mips-linux-gnu"
|
|
||||||
x=mips-linux-gnu; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
mipsel-linux-gnu-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-mipsel -L /usr/mipsel-linux-gnu"
|
|
||||||
x=mipsel-linux-gnu; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
powerpc-linux-gnu-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-ppc -L /usr/powerpc-linux-gnu"
|
|
||||||
x=powerpc-linux-gnu; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
powerpc64-linux-gnu-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-ppc64 -L /usr/powerpc64-linux-gnu"
|
|
||||||
x=powerpc64-linux-gnu; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
powerpc64le-linux-gnu-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-ppc64le -L /usr/powerpc64le-linux-gnu"
|
|
||||||
x=powerpc64le-linux-gnu; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
s390x-linux-gnu-gcc-5)
|
|
||||||
[[ -z $upx_qemu ]] && upx_qemu="qemu-s390x -L /usr/s390x-linux-gnu"
|
|
||||||
x=s390x-linux-gnu; AR="$x-ar"; CC="$x-gcc-5"; CXX="$x-g++-5" ;;
|
|
||||||
x86_64-w64-mingw32-gcc-5)
|
|
||||||
upx_exeext=.exe
|
|
||||||
[[ -z $upx_wine ]] && upx_wine="wine"
|
|
||||||
x=x86_64-w64-mingw32; AR="$x-ar"; CC="$x-gcc -m64"; CXX="$x-g++ -m64" ;;
|
|
||||||
esac
|
|
||||||
elif grep -E -q '^PRETTY_NAME="?Ubuntu 20\.04' /etc/os-release; then
|
|
||||||
case $BM_CROSS-$BM_C in
|
|
||||||
x86_64-w64-mingw32-gcc-9)
|
|
||||||
export upx_EXTRA_CPPFLAGS="-D__USE_MINGW_ANSI_STDIO=1"
|
|
||||||
export upx_EXTRA_LDFLAGS="-static"
|
|
||||||
upx_exeext=.exe
|
|
||||||
[[ -z $upx_wine ]] && upx_wine="wine64"
|
|
||||||
x=x86_64-w64-mingw32; AR="$x-ar"; CC="$x-gcc -m64"; CXX="$x-g++ -m64" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
fi # BM_CROSS
|
|
||||||
if [[ $CC == "false" ]]; then # generic
|
|
||||||
if [[ -z $BM_CROSS ]]; then
|
|
||||||
if [[ $TRAVIS_OS_NAME == osx ]]; then
|
|
||||||
case $BM_C in
|
|
||||||
clang | clang-m?? | clang-[6789][0-9][0-9]-m?? | clang-1[0-1][0-9][0-9]-m??)
|
|
||||||
CC="clang"; CXX="clang++" ;; # standard system compiler
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
case $BM_C in
|
|
||||||
clang | clang-m?? | clang-3.4-m??)
|
|
||||||
CC="clang"; CXX="clang++" ;; # standard system compiler
|
|
||||||
clang-[3456].[0-9]-m??)
|
|
||||||
v=${BM_C:6:3}; CC="clang-$v"; CXX="clang++-$v"; SCAN_BUILD="scan-build-$v" ;;
|
|
||||||
clang-[789]-m??)
|
|
||||||
v=${BM_C:6:1}; CC="clang-$v"; CXX="clang++-$v"; SCAN_BUILD="scan-build-$v" ;;
|
|
||||||
clang-1[0-9]-m??)
|
|
||||||
v=${BM_C:6:2}; CC="clang-$v"; CXX="clang++-$v"; SCAN_BUILD="scan-build-$v" ;;
|
|
||||||
gcc | gcc-m?? | gcc-mx32)
|
|
||||||
CC="gcc"; CXX="g++" ;; # standard system compiler
|
|
||||||
gcc-[34].[0-9]-m?? | gcc-[34].[0-9]-mx32)
|
|
||||||
v=${BM_C:4:3}; CC="gcc-$v"; CXX="g++-$v" ;;
|
|
||||||
gcc-[56789]-m?? | gcc-[56789]-mx32)
|
|
||||||
v=${BM_C:4:1}; CC="gcc-$v"; CXX="g++-$v" ;;
|
|
||||||
gcc-1[0-9]-m?? | gcc-1[0-9]-mx32)
|
|
||||||
v=${BM_C:4:2}; CC="gcc-$v"; CXX="g++-$v" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi # generic
|
|
||||||
case $BM_C in
|
|
||||||
clang*-m32) CC="$CC -m32"; CXX="$CXX -m32" ;;
|
|
||||||
clang*-m64) CC="$CC -m64"; CXX="$CXX -m64" ;;
|
|
||||||
gcc*-m32) CC="$CC -m32"; CXX="$CXX -m32" ;;
|
|
||||||
gcc*-m64) CC="$CC -m64"; CXX="$CXX -m64" ;;
|
|
||||||
gcc*-mx32) CC="$CC -mx32"; CXX="$CXX -mx32"; BUILD_LOCAL_UCL=1; BUILD_LOCAL_ZLIB=1 ;;
|
|
||||||
esac
|
|
||||||
if [[ $BM_C =~ (^|\-)(clang|gcc)($|\-) ]]; then
|
|
||||||
CC="$CC -std=gnu89"
|
|
||||||
fi
|
|
||||||
unset v x
|
|
||||||
export AR CC CXX
|
|
||||||
fi # CC_OVERRIDE
|
|
||||||
|
|
||||||
# source dirs
|
|
||||||
[[ -z $upx_SRCDIR ]] && upx_SRCDIR=$(readlink -mn -- $argv0dir/..)
|
|
||||||
[[ -z $ucl_SRCDIR ]] && ucl_SRCDIR=$(readlink -mn -- $upx_SRCDIR/../deps/ucl-1.03)
|
|
||||||
[[ -z $upx_testsuite_SRCDIR ]] && upx_testsuite_SRCDIR=$(readlink -mn -- $upx_SRCDIR/../deps/upx-testsuite)
|
|
||||||
[[ -z $zlib_SRCDIR ]] && zlib_SRCDIR=$(readlink -mn -- $upx_SRCDIR/../deps/zlib-1.2.11)
|
|
||||||
|
|
||||||
# build dirs
|
|
||||||
mkbuilddirs() {
|
|
||||||
local d
|
|
||||||
for d in "$@"; do
|
|
||||||
mkdir -p -v "$d" || exit 1
|
|
||||||
[[ -f "$d/.mfxnobackup" ]] || touch "$d/.mfxnobackup"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
# search for an existing $toptop_builddir
|
|
||||||
if [[ -z $toptop_builddir ]]; then
|
|
||||||
for d in . ..; do
|
|
||||||
for subdir in "local" appveyor circle github gitlab travis .; do
|
|
||||||
dd=$d/build/$subdir
|
|
||||||
if [[ -d $dd ]]; then
|
|
||||||
toptop_builddir=$(readlink -en -- "$dd")
|
|
||||||
break 2
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
unset d subdir dd
|
|
||||||
fi
|
|
||||||
[[ -z $toptop_builddir ]] && toptop_builddir=$(readlink -mn -- ./build)
|
|
||||||
[[ -z $toptop_bdir ]] && toptop_bdir=$(readlink -mn -- "$toptop_builddir/${BM_CROSS:+$BM_CROSS-}$BM_C/$BM_B")
|
|
||||||
[[ -z $upx_BUILDDIR ]] && upx_BUILDDIR=$(readlink -mn -- "$toptop_bdir/upx")
|
|
||||||
[[ -z $ucl_BUILDDIR ]] && ucl_BUILDDIR=$(readlink -mn -- "$toptop_bdir/ucl-1.03")
|
|
||||||
[[ -z $upx_testsuite_BUILDDIR ]] && upx_testsuite_BUILDDIR=$(readlink -mn -- "$toptop_bdir/upx-testsuite")
|
|
||||||
[[ -z $zlib_BUILDDIR ]] && zlib_BUILDDIR=$(readlink -mn -- "$toptop_bdir/zlib-1.2.11")
|
|
||||||
[[ -z $lcov_OUTPUTDIR ]] && lcov_OUTPUTDIR=$(readlink -mn -- "$toptop_bdir/.lcov-results")
|
|
||||||
unset toptop_builddir toptop_bdir
|
|
||||||
|
|
||||||
# ensure absolute directories
|
|
||||||
make_absolute() {
|
|
||||||
local d
|
|
||||||
while [[ $# -gt 0 ]]; do
|
|
||||||
if [[ -n ${!1} ]]; then
|
|
||||||
d=$(readlink -mn -- "${!1}")
|
|
||||||
eval $1="$d"
|
|
||||||
fi
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
}
|
|
||||||
for var_prefix in ucl upx upx_testsuite zlib; do
|
|
||||||
for var_suffix in _BUILDDIR _SRCDIR; do
|
|
||||||
make_absolute ${var_prefix}${var_suffix}
|
|
||||||
done
|
|
||||||
done
|
|
||||||
make_absolute lcov_OUTPUTDIR
|
|
||||||
unset var_prefix var_suffix
|
|
||||||
|
|
||||||
print_header() {
|
|
||||||
local x="==========="; x="$x$x$x$x$x$x$x"
|
|
||||||
echo -e "\n${x}\n${1}\n${x}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_settings() {
|
|
||||||
local v var_prefix var_suffix
|
|
||||||
# Build Matrix
|
|
||||||
for v in TRAVIS_OS_NAME BM_CROSS BM_C BM_B BM_T; do
|
|
||||||
[[ -n ${!v} ]] && echo "${v}='${!v}'"
|
|
||||||
done
|
|
||||||
# BM_C related
|
|
||||||
for v in AR CC CXX CPPFLAGS CFLAGS CXXFLAGS LDFLAGS LIBS SCAN_BUILD; do
|
|
||||||
[[ -n ${!v} ]] && echo "${v}='${!v}'"
|
|
||||||
v=EXTRA_${v}
|
|
||||||
[[ -n ${!v} ]] && echo "${v}='${!v}'"
|
|
||||||
done
|
|
||||||
# directories and other info
|
|
||||||
for v in TRAVIS_XCODE_SDK UPX_UCLDIR lcov_OUTPUTDIR; do
|
|
||||||
[[ -n ${!v} ]] && echo "${v}='${!v}'"
|
|
||||||
done
|
|
||||||
for var_prefix in ucl upx upx_testsuite zlib; do
|
|
||||||
for var_suffix in _BUILDDIR _SRCDIR; do
|
|
||||||
v=${var_prefix}${var_suffix}
|
|
||||||
[[ -n ${!v} ]] && echo "${v}='${!v}'"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
##env | LC_ALL=C sort
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
########## begin .sha256sums.recreate
|
|
||||||
expected_sha256sums__t010_decompressed="\
|
|
||||||
24158f78c34c4ef94bb7773a6dda7231d289be76c2f5f60e8b9ddb3f800c100e *amd64-linux.elf/upx-3.91
|
|
||||||
24808d572483f4cd713d66894b3da406755038737007a78b076528e6407e3132 *amd64-linux.elf/upx-3.95
|
|
||||||
d88eaad0528bcecec9f51cbe015a117c8cf350a3f6d8308f2b0517d4fd19d189 *amd64-win64.pe/upx-3.95.exe
|
|
||||||
f7279729eb975e4238f8b8ee56fefa41ccbeb35ef0ffe4c34f8047baab78fff5 *arm-linux.elf/upx-3.95
|
|
||||||
e09df2a69f88c692138447f274ba7f99cdd11f8696c71ac8d3761606c95ab5c5 *arm-wince.pe/upx-3.91.exe
|
|
||||||
ce81113f8a4ff1cd806811cb80ab8bea5c9c6fbced47451c7f07e50700f9817b *arm64-linux.elf/upx-3.95
|
|
||||||
b1c1c38d50007616aaf8e942839648c80a6111023e0b411e5fa7a06c543aeb4a *armeb-linux.elf/upx-3.91
|
|
||||||
84b90eb0d617571fe4885639925b35ca6a61060cb2616bb5bf729b4d701653e4 *armeb-linux.elf/upx-3.95
|
|
||||||
bcac77a287289301a45fde9a75e4e6c9ad7f8d57856bae6eafaae12ae4445a34 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
7d331e508449497f64cd47abdd3f00f70307f508ad3fd692d333feb97beccead *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
730a513b72a094697f827e4ac1a4f8ef58a614fc7a7ad448fa58d60cd89af7ed *i386-linux.elf/upx-3.91
|
|
||||||
a1f3e5ffa7b2cfebe1e475ac1f4c7683b1b8b4e292aa0d04386cc0314dd162c9 *i386-linux.elf/upx-3.95
|
|
||||||
e90fb09a808334c2674996760d42c82f8352e3f671f6b66c11481e772785c4d2 *i386-win32.pe/upx-3.91.exe
|
|
||||||
07bd50c1d80f6ff651228e6fc0ba3a583a472915772244f232696b34156a9d27 *i386-win32.pe/upx-3.95.exe
|
|
||||||
8e5333ea040f5594d3e67d5b09e005d52b3a52ef55099a7c11d7e39ead38e66d *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
8902f38ec3d95d8e077e3ab5fdbb5bad408859913a35deb87041f4f053cd6605 *mips-linux.elf/upx-3.95
|
|
||||||
c3f44b4d00a87384c03a6f9e7aec809c1addfe3e271244d38a474f296603088c *mipsel-linux.elf/upx-3.91
|
|
||||||
dd1496bc4e9c32a5d5dd47e3eaabf7b134ca001d48807eebfd3d5e28c8a2ab58 *mipsel-linux.elf/upx-3.95
|
|
||||||
b8c35fa2956da17ca505956e9f5017bb5f3a746322647e24ccb8ff28059cafa4 *powerpc-linux.elf/upx-3.91
|
|
||||||
2bc00a51daa0bada19a8fa1bd2c227a8596844fa1b0aa3611087f195072700e2 *powerpc-linux.elf/upx-3.95
|
|
||||||
a0950546dc17fca9437219431d8ddb0249ce5b08e899e0c799a87ac982adee70 *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t020_canonicalized="\
|
|
||||||
24158f78c34c4ef94bb7773a6dda7231d289be76c2f5f60e8b9ddb3f800c100e *amd64-linux.elf/upx-3.91
|
|
||||||
24808d572483f4cd713d66894b3da406755038737007a78b076528e6407e3132 *amd64-linux.elf/upx-3.95
|
|
||||||
d88eaad0528bcecec9f51cbe015a117c8cf350a3f6d8308f2b0517d4fd19d189 *amd64-win64.pe/upx-3.95.exe
|
|
||||||
f7279729eb975e4238f8b8ee56fefa41ccbeb35ef0ffe4c34f8047baab78fff5 *arm-linux.elf/upx-3.95
|
|
||||||
e09df2a69f88c692138447f274ba7f99cdd11f8696c71ac8d3761606c95ab5c5 *arm-wince.pe/upx-3.91.exe
|
|
||||||
ce81113f8a4ff1cd806811cb80ab8bea5c9c6fbced47451c7f07e50700f9817b *arm64-linux.elf/upx-3.95
|
|
||||||
b1c1c38d50007616aaf8e942839648c80a6111023e0b411e5fa7a06c543aeb4a *armeb-linux.elf/upx-3.91
|
|
||||||
84b90eb0d617571fe4885639925b35ca6a61060cb2616bb5bf729b4d701653e4 *armeb-linux.elf/upx-3.95
|
|
||||||
bcac77a287289301a45fde9a75e4e6c9ad7f8d57856bae6eafaae12ae4445a34 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
7d331e508449497f64cd47abdd3f00f70307f508ad3fd692d333feb97beccead *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
730a513b72a094697f827e4ac1a4f8ef58a614fc7a7ad448fa58d60cd89af7ed *i386-linux.elf/upx-3.91
|
|
||||||
a1f3e5ffa7b2cfebe1e475ac1f4c7683b1b8b4e292aa0d04386cc0314dd162c9 *i386-linux.elf/upx-3.95
|
|
||||||
e90fb09a808334c2674996760d42c82f8352e3f671f6b66c11481e772785c4d2 *i386-win32.pe/upx-3.91.exe
|
|
||||||
07bd50c1d80f6ff651228e6fc0ba3a583a472915772244f232696b34156a9d27 *i386-win32.pe/upx-3.95.exe
|
|
||||||
8e5333ea040f5594d3e67d5b09e005d52b3a52ef55099a7c11d7e39ead38e66d *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
8902f38ec3d95d8e077e3ab5fdbb5bad408859913a35deb87041f4f053cd6605 *mips-linux.elf/upx-3.95
|
|
||||||
c3f44b4d00a87384c03a6f9e7aec809c1addfe3e271244d38a474f296603088c *mipsel-linux.elf/upx-3.91
|
|
||||||
dd1496bc4e9c32a5d5dd47e3eaabf7b134ca001d48807eebfd3d5e28c8a2ab58 *mipsel-linux.elf/upx-3.95
|
|
||||||
b8c35fa2956da17ca505956e9f5017bb5f3a746322647e24ccb8ff28059cafa4 *powerpc-linux.elf/upx-3.91
|
|
||||||
2bc00a51daa0bada19a8fa1bd2c227a8596844fa1b0aa3611087f195072700e2 *powerpc-linux.elf/upx-3.95
|
|
||||||
a0950546dc17fca9437219431d8ddb0249ce5b08e899e0c799a87ac982adee70 *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t110_compress_ucl_nrv2b_3_no_filter="\
|
|
||||||
d8e9cb72d6d63b64b68c44a380b0f700a2c2a127bb128cf16bf003e5fe7b112f *amd64-linux.elf/upx-3.91
|
|
||||||
71c2a5e4b1fd131c7d94c646394228e577e33a90620e6f04ed8ce71bf9419dd6 *amd64-linux.elf/upx-3.95
|
|
||||||
7ef188bb0071bf5ad92edc0ff2cca7798ab2f084bad5d244162bafdd4dd99a03 *amd64-win64.pe/upx-3.95.exe
|
|
||||||
cb458bf41edcac0b50648c15ac538048fd9e57da03c3588f0fa3e524d7e9b856 *arm-linux.elf/upx-3.95
|
|
||||||
5d86c92a039dbe374ff69d1ee160eee849ed7a43aabe21a427482d4f050b98be *arm-wince.pe/upx-3.91.exe
|
|
||||||
9436568081d9bb519cf0c7ad1f9497026e2e74fd29009d4829a05a742c649142 *arm64-linux.elf/upx-3.95
|
|
||||||
e68f0929566ff9a8c978c9203c07bde9bc9ecc57fb3b3664f7ce4cd84ca82d26 *armeb-linux.elf/upx-3.91
|
|
||||||
8fe7b9bcf5db78b3f5585555526ee9aa640e40e97052226431c2f4e2dcd8d26a *armeb-linux.elf/upx-3.95
|
|
||||||
899a2af496235848b333d49645c9b08638170fc05899b55673900e5962d70a2a *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
41048de2b63e0703a78c222efeca6b99225fad8e0c8758775f5fb6e63edde3e9 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
4e7bb9e52a5f8085e9882eff1007b7f401a7fbdfc82e5342ef604e4feb4ccf15 *i386-linux.elf/upx-3.91
|
|
||||||
72fba7c493de49b2ee152629e9083b83d6e732c99eefc7d59641d091c64f171e *i386-linux.elf/upx-3.95
|
|
||||||
38fbad083a8eaa4ed7cb379f21a5277a703baaa77d4e6d9e145d2bb4838513b5 *i386-win32.pe/upx-3.91.exe
|
|
||||||
a27abdb7d9888b7d1e79aa90cdb6a1500e0a3abdc64ee9fbe7db7ce4423ffc79 *i386-win32.pe/upx-3.95.exe
|
|
||||||
a8e11176946ec68f4c2e40e0a585eb70f589560117bef2a98315c454b2fe1f13 *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
a80d40f6ae66effe0ce9dfcbcc306e59c61118a3653eba304b6120c3cb4bd951 *mips-linux.elf/upx-3.95
|
|
||||||
8aab2896c689c9b9eae5d205e8dbf3e9896989f212181f666dece91e893314e9 *mipsel-linux.elf/upx-3.91
|
|
||||||
00dbb8a83349fff83374b5a716ae953943b003991e1808e5d773f3e2aa3176bb *mipsel-linux.elf/upx-3.95
|
|
||||||
174a1e090a254cefff98bc23235a3feea9e23c3be0a4c007c44c89a999e62567 *powerpc-linux.elf/upx-3.91
|
|
||||||
f133e103c0d02927311593f6f25ea0c4803fe648919e154a5b2a527964b6a9fb *powerpc-linux.elf/upx-3.95
|
|
||||||
996c63e6717ced59c7dfd4573482ef54d2715dc04bc106e6a86e0317443cb960 *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t120_compress_ucl_nrv2d_3_no_filter="\
|
|
||||||
e5fce664c1ed5e4d5ced5186c5b88be8ef14b378b911e2e70bc8e7a331f8e3ff *amd64-linux.elf/upx-3.91
|
|
||||||
86437aa77c0c1c5f55ef8d15ae2ba69d9d48034330faccc025f03a2a7d54ef12 *amd64-linux.elf/upx-3.95
|
|
||||||
761629a404ac155b3f856ff6bedf66266e1c75dcf389b56aee7692f420872653 *amd64-win64.pe/upx-3.95.exe
|
|
||||||
7dc22a271fd568f2ec7db5360ae08d2ed0dc6ceb14901bf8d3a49f6a239506be *arm-linux.elf/upx-3.95
|
|
||||||
58259c38274532baf60932569a4006ceb762a381ac3b257e9af648af24422660 *arm-wince.pe/upx-3.91.exe
|
|
||||||
f626c4131c1b70a880e6431c41842093dad4a2fff921304727306e699c6e6ceb *arm64-linux.elf/upx-3.95
|
|
||||||
6f870fe4f7a92cd244bc0b209082264ffdf68d023dc1d697f5111ce5f4a168ca *armeb-linux.elf/upx-3.91
|
|
||||||
ed554bbf0d531740a2cb408a5408b7fb67fef32173531bae21b15829e4465b92 *armeb-linux.elf/upx-3.95
|
|
||||||
6e5b040dd59e0bf3491da6947fd3c576fd1b090b1fa7f278b147dd33b0a561a4 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
f27ef0ce4ca0c7557dfd4c0c3a7e5443523f82dd9f4d354fb80ad0e001ede485 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
8e6d5979658e8a00b567ddd214abd5565fc4c356b3e84941038c16aff9b3fb23 *i386-linux.elf/upx-3.91
|
|
||||||
7d7cc62ec7f8e71e526687cde53d5b49e5f688787c3aef533a8aa9f302e51bea *i386-linux.elf/upx-3.95
|
|
||||||
f81ed2a88589df18a735bebc1b42d638d3eb0bebbaea70758c762348103adde1 *i386-win32.pe/upx-3.91.exe
|
|
||||||
d5533151370ea42679c94036b8d61239f90fd930fca5d3cedbbca9c959756294 *i386-win32.pe/upx-3.95.exe
|
|
||||||
5361b1f369a4b42f9063f448bdcda31f97bd610c659d2fe3c89d3e479a84cbc9 *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
ac4233c2d342375bd2fb5cf871cfd47b58863fbcac7693937e1d15d23f09f96e *mips-linux.elf/upx-3.95
|
|
||||||
9bcae27b631736ff226d45fc143c61c55b1bbb127b77b9612ad2d123dc96d45d *mipsel-linux.elf/upx-3.91
|
|
||||||
bf735a042c3406897f1cba6a62f8f7ea631bd15f15f21a56165decfe39323c52 *mipsel-linux.elf/upx-3.95
|
|
||||||
215c0694962ab6f4ead91448722a6ddce8471abce0742e148a6626cdbdf904fa *powerpc-linux.elf/upx-3.91
|
|
||||||
82857404a03d2a21c4bff152c8da78ae3cdcdb71ad0c847256c370ce510a4f1b *powerpc-linux.elf/upx-3.95
|
|
||||||
ee860ecf8fafb5ca6a7f9c6baf316dba1c3b55553aa02f4dc254d54b32e0a61a *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t130_compress_ucl_nrv2e_3_no_filter="\
|
|
||||||
d43e28f8724cdb76deaca6581b698bd77c06a94ea37c8cf730eb38f82ce62cce *amd64-linux.elf/upx-3.91
|
|
||||||
05c7ced28df8fa967385aa85adb479a9d9928112cb28884e8382421ee7aed062 *amd64-linux.elf/upx-3.95
|
|
||||||
405399cb91cde3dfeed89bfe14ff65301fcb9a6925ffb55bdac8c60e164fec9f *amd64-win64.pe/upx-3.95.exe
|
|
||||||
48a0983b24a0dc0e29df24ee30470ce228f4c978a3e965e27a6b12d8977807bd *arm-linux.elf/upx-3.95
|
|
||||||
9b460ce1edeb2557661526bdd0d195f5d4c7c5f261c2886fe47691ce5b2d20c5 *arm-wince.pe/upx-3.91.exe
|
|
||||||
391afe58edcbbedadde8c9ec4cd693c4c169bd6f6fefa9f63c41f4d7529246c9 *arm64-linux.elf/upx-3.95
|
|
||||||
05943cb6189f8230a6a6cc8ffb9ae9b6f3ecb1ef222181522833dc8373c77211 *armeb-linux.elf/upx-3.91
|
|
||||||
0f1cdc18d24c03d3e56256721ba9fdddf7809eeaeefacf4f677120903c9544e4 *armeb-linux.elf/upx-3.95
|
|
||||||
ee2918a9bf26aebcb5547684f2d4f9c24ac516597c208a478e5bc3f36b59291e *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
f24770536216fa29a7d3624f6e676a54244be0a7ab1213d29d21a146639a1b83 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
2ea7702d4398d03ea46502f5179b2eaa209926ad0d105e81663b3c87c2e7acb7 *i386-linux.elf/upx-3.91
|
|
||||||
74df9d74515b51839272c5c84572880d58ea85a16cbed5549b2af182149dad24 *i386-linux.elf/upx-3.95
|
|
||||||
11401986fe43ee57cb0170099d3a6228238e2eff8244ad81cc647420314c98ee *i386-win32.pe/upx-3.91.exe
|
|
||||||
3ee3b313f0cf6c891c5895343ff304aa34e3017aac45022f7bbd0cfd7d80dc25 *i386-win32.pe/upx-3.95.exe
|
|
||||||
e9659acb2dc14f60e8f3d71b6024ec9c768ee11233ec9dad5e1bd252cd259381 *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
0796aa39c6a069f5c940ee07442c22d864fdca7f6fe083d51debabab077c413f *mips-linux.elf/upx-3.95
|
|
||||||
98d370c61692de7249aa51f3befc3ebefa705f172a1ebf0dd092ea07b9776158 *mipsel-linux.elf/upx-3.91
|
|
||||||
7bb3afac05c13ef34721facf4c81621791a45a40cceab2cc1bb7306a747c5df5 *mipsel-linux.elf/upx-3.95
|
|
||||||
eb292cd7c95fcd597431a8e6c9f13f0b64bbda3423611a43ceeca418a3979554 *powerpc-linux.elf/upx-3.91
|
|
||||||
6a45c2734fc2aa82a0e2b9331c545e1bb04d02797c59ab00a8250d052603b8a2 *powerpc-linux.elf/upx-3.95
|
|
||||||
9c6dc09daf5901983625e8f9f2f45f66a10fcf9841ae3e9788bb3ae075db5307 *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t140_compress_lzma_2_no_filter="\
|
|
||||||
8f08ea0a86c3f49c7b2a90aca17b5739a91e39ef6542365e7395d1325fdcfc2b *amd64-linux.elf/upx-3.91
|
|
||||||
9f7c9d0432baaf21977ca4bd827f7cdf7c39296f77e122689cc57945856e7b39 *amd64-linux.elf/upx-3.95
|
|
||||||
86e277047c1b8c1884bf5ceb4f628410b011fae761e8cf7031f0b8b3058adac6 *amd64-win64.pe/upx-3.95.exe
|
|
||||||
80a8f4d0df27d32d8f20bfd838f6c876026f84d6c54bb5c1a920340031eb22e8 *arm-linux.elf/upx-3.95
|
|
||||||
c059993735be23726fd74a5d0c5165f4c6581cc90513b2a6f82cb0f8d113ca6a *arm-wince.pe/upx-3.91.exe
|
|
||||||
3b8298af00f656d071187fc219bbb9a131a412f7489dc7a164fa7c6a78c96c85 *arm64-linux.elf/upx-3.95
|
|
||||||
83d0c4dc17bbb9391d904c85c6382fee5b8f76baf664f14c8f7c3c0b31bc8079 *armeb-linux.elf/upx-3.91
|
|
||||||
f939c8365f00d486573f9b969d42d1b43e49fc8c5f59b3a72eb229482de3938e *armeb-linux.elf/upx-3.95
|
|
||||||
467cead4f4418d1a581ac61cac5526afdbb6ebe8887749c3b8b25a45bb686e22 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
c35eb28139afcea4b03e7fabf993e9927486b53e0ca20d78e61a274358934ad3 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
6898de07c4d250dfdd9be431a59562e87f49e2c69112d034352d1ec62c6e99dd *i386-linux.elf/upx-3.91
|
|
||||||
400f08c53c7b3d81e99c85f9aa86443616d884a366627f61dce3f1d0c46c67ba *i386-linux.elf/upx-3.95
|
|
||||||
2530b702024091f71405e5a8b4b0ebc235a8e12bcb66867590d1a6741c905b9d *i386-win32.pe/upx-3.91.exe
|
|
||||||
2a854af2416d459b7bdf8345cae374800cf471d9e945a170fa38046221e7b462 *i386-win32.pe/upx-3.95.exe
|
|
||||||
74ac6483e4a98a4173330ad43203f04354af0bc1ce046e6c94e5759d68ce992f *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
118fd0c794402cf96c4c97533c2a3292afdc87632bac6a25978f0baae248e375 *mips-linux.elf/upx-3.95
|
|
||||||
4b26db733fab84d8032dd4c6cc345f3da50ac3fe581706b1676ebe19d099c693 *mipsel-linux.elf/upx-3.91
|
|
||||||
a016e09a4aa299dd176a6e5eccde98db8781c509e7605504c316a77bf55fe1a1 *mipsel-linux.elf/upx-3.95
|
|
||||||
db75012b5177ef021fb9365c3828aba39ea7feff0783e737a4625c0066de8ef1 *powerpc-linux.elf/upx-3.91
|
|
||||||
168931dfcecc39019fa86eb2e27dfc2e8239160c3b826b76fd53f39f13f986da *powerpc-linux.elf/upx-3.95
|
|
||||||
e58fb39928d60ec18add81e3dcc62b5a82cfa8c9c19f89ade0a7388ac88342f5 *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t150_compress_ucl_2_all_filters="\
|
|
||||||
c329512f59d065b20698c49ff7d710c7bb0cf099b8a4b8fe5ecd1121a12eb175 *amd64-linux.elf/upx-3.91
|
|
||||||
8cf09664da89c51453e23c4ac76e8d619814dbd576580f408ebf95078dc67474 *amd64-linux.elf/upx-3.95
|
|
||||||
8af657df3b6a0f7d586f38960a592827921a914f923db4ab87fbb93094f1096d *amd64-win64.pe/upx-3.95.exe
|
|
||||||
055f5fd681f872e2e308a59402196bb3f33fdb0ef34ddee4031f7d676e6ac364 *arm-linux.elf/upx-3.95
|
|
||||||
eae07f1e169d0b89ec80fac5f61ce41af9c697d48ddb45495806f9e3103dd0ac *arm-wince.pe/upx-3.91.exe
|
|
||||||
b1bfa0d71d8dfd3edd772d1d92f76695155ba9cbcdc572c68efa8cd6e500b0b6 *arm64-linux.elf/upx-3.95
|
|
||||||
12af497fbc9d06199fa623744a31778ee78fe142e5958162f0e683809ca58435 *armeb-linux.elf/upx-3.91
|
|
||||||
b497a7fb0b12fb75a4444f0c137e174fe059b973f5f2425b1eedb04855dfb130 *armeb-linux.elf/upx-3.95
|
|
||||||
1c7d4abe5aa21da343399e2cff642f04bf0904bbac2df97d5e10b2e9087806fd *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
70ae2c3a58b22dbf1aefb145705c00855be241e6b2cc45fe18cd90bf93fa3802 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
f332cba5e96fa04377a127c2c7f45822ccf1f12dd990fca5bf73499902082c3b *i386-linux.elf/upx-3.91
|
|
||||||
15f1238bd48835d850c4eb9bb51515738d69237b6c81bd7148aefb0a0e4556e6 *i386-linux.elf/upx-3.95
|
|
||||||
1c00860e202116b199fa76b4b508f27d7ec28510d8287557d04688c93be4e624 *i386-win32.pe/upx-3.91.exe
|
|
||||||
12e1ac68a55bae0c2f82149b133e21224e37168e9915ef97bd40d38455723a53 *i386-win32.pe/upx-3.95.exe
|
|
||||||
ae43a71d76b0bc2f1af2e9b5ec90d6cc0337dbd603d124dfac8c68893bd8fb5f *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
e0c0dd0e41b3d0f059d373bbc81c35fdb843657d496614fd090aa2d89ed5da27 *mips-linux.elf/upx-3.95
|
|
||||||
558780a870830f5fbb14f5cd00db576fa37c8fcd72f7f22491ca2279aaf85757 *mipsel-linux.elf/upx-3.91
|
|
||||||
7d85974f25e3daa3f21c11496683bee6c22d1c6086f29ed5b410637cb9c66f2e *mipsel-linux.elf/upx-3.95
|
|
||||||
cb3c36ee3ade39e4cb1c2d5bb20548f1f4560bf1853c315b5c2b3fca533c75ec *powerpc-linux.elf/upx-3.91
|
|
||||||
faaf09644ef9eb51a5f48a34971bb6ab363cb85fb79fdba8ad9eb1aecd7d5a7e *powerpc-linux.elf/upx-3.95
|
|
||||||
c714496c2027d81cd16431cc27dc105761aae98d71099cecae84bd1d269e9dba *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t160_compress_all_methods_1_no_filter="\
|
|
||||||
08a685a5869892597aa82264e8796a6d0e663f61426b683cfb47a51c5f4e1f37 *amd64-linux.elf/upx-3.91
|
|
||||||
ea0ef4eed5ecfa14f5e713bae4a7559adcd8dc5bf26a6bc035d771063cf325eb *amd64-linux.elf/upx-3.95
|
|
||||||
d5cbc1908d75808afffaa503584588aa33ef3ce36692273c0d7ae628fe649fc6 *amd64-win64.pe/upx-3.95.exe
|
|
||||||
a90a668fb46aa1ae1ebe875383930f016ea3ca9985f8a6d0d09bcef179cee7ab *arm-linux.elf/upx-3.95
|
|
||||||
ad3d1c557d82f8d4d54a462b5e720705b51df064141b0fd3f81d54de685f51d6 *arm-wince.pe/upx-3.91.exe
|
|
||||||
1b2f673515ca9b67c7af0a9381d4e2b7f23b709e97ae969cf1dedcfda8b254ef *arm64-linux.elf/upx-3.95
|
|
||||||
ef2ce0aace6ea8c6994232c93b73d2b0fda6ccc2b108bfca6a0f4d4dbacc36d0 *armeb-linux.elf/upx-3.91
|
|
||||||
2bfdc5e22932b32d405611d51940d7a79b851e3776b8cdb05db5112a195cc624 *armeb-linux.elf/upx-3.95
|
|
||||||
a9b09a6118386855e0b326e337f72c8dd369b3cadfb4e1d35a08c197a71ec0f6 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
4cedba26f462707805fef1810d720e09b25040f97344444d93c0af36923e8089 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
7fdf110134d120d6cec0aea13c1a7b861770cecb4f516cd1ab595a4d3d26936f *i386-linux.elf/upx-3.91
|
|
||||||
deb15af9198da2d8e2d95b5f5e64bd8639cb97d4cfe2484eabdcd6385288b964 *i386-linux.elf/upx-3.95
|
|
||||||
40fcff57d7859f37d349b907a4564bf3e9ba7223cc163e770f8353a8bfa51c73 *i386-win32.pe/upx-3.91.exe
|
|
||||||
fae3dc1dc8eac23f6e610a1e01c20d4779026511a091672f7c150c402ae1c552 *i386-win32.pe/upx-3.95.exe
|
|
||||||
f9663e80b6d0f69cc916ae137f6df9cd8c10bfff9c1562959efd32e91b02e1a8 *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
50b71e6090c7964bb704849584c7c75d8ee5aaa5bfab26482d3879bc01d17841 *mips-linux.elf/upx-3.95
|
|
||||||
cb7d16ae50a2eb464c1f864f1b9052cc66f52545b82d636e48b2105e797e31f7 *mipsel-linux.elf/upx-3.91
|
|
||||||
a1052f7425c434ce0f92dbb292d6511c8af1698a2e88352f7a463711ef8115c6 *mipsel-linux.elf/upx-3.95
|
|
||||||
5fcc6323a8cd37d83e9a9136d7d2511a3e5c59216ceab50d4f386a2ae1a6c842 *powerpc-linux.elf/upx-3.91
|
|
||||||
a905cb39a96982ab08e2663be690cd400bd54646b50ee50790de51b322d09830 *powerpc-linux.elf/upx-3.95
|
|
||||||
071b42a5ae7bf3d25f01e436473433470b97311ac2aff834884a0d3d240d0291 *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
expected_sha256sums__t170_compress_all_methods_no_lzma_5_no_filter="\
|
|
||||||
c5ed17847125467790aa635c926075768925ab88c3a6baa57b3bf2877c6b9001 *amd64-linux.elf/upx-3.91
|
|
||||||
a17594fae504de512492ef822675cf6faac74e48c7803ac119626148ea9adb89 *amd64-linux.elf/upx-3.95
|
|
||||||
1ea4c9aedd3591f62cd6902986c1df39d3ef7fc624abc78bde61300e87627d20 *amd64-win64.pe/upx-3.95.exe
|
|
||||||
319e96fc0a6dbaa3aa7214100176957d4d0e84b7d0ee849a1f60c34ba5a22947 *arm-linux.elf/upx-3.95
|
|
||||||
a3f2144754b44700b4aacb39ab5f5b818fda7caa0a934090eeacee7dafb6ba7b *arm-wince.pe/upx-3.91.exe
|
|
||||||
5cb0a03d3305ddd5bc77990538b49ce3f14dcd03ad76d272d45005aa86dd5f7d *arm64-linux.elf/upx-3.95
|
|
||||||
f5061f76060445a72edb898e9919400e81423bde6dad566a5bb5bdf1407ef6dc *armeb-linux.elf/upx-3.91
|
|
||||||
337e4776b2f1afec7eb6d54c34d68f166af63ce5b4e2fb7ac48eeb5b83582c28 *armeb-linux.elf/upx-3.95
|
|
||||||
46223cc5aea67b275cc5621eec79f97d4f543edecfdac37a0f2407583f881fc9 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
|
||||||
228c9007c5395fc9eef93a23d781e7daab01efa1ee86a4d4f6a46b9b7f7aeb8b *i386-dos32.djgpp2.coff/upx-3.95.exe
|
|
||||||
089693d8059d8580ea3bf326d038ffb51f258721833ad96c05f20c321ab8df13 *i386-linux.elf/upx-3.91
|
|
||||||
d4995b5b5c46eef7f8f1673c629f427d19b5dbda495c2b3f157acf4046b72123 *i386-linux.elf/upx-3.95
|
|
||||||
dd70e8fde421a35692f26147c3eba392f57adb332d0e5025fa0039a2673c10cb *i386-win32.pe/upx-3.91.exe
|
|
||||||
3fa365f39199afc7a259ba8ad8ae50cd026ef3f0a37d3fd570d42cba8bc5e0e7 *i386-win32.pe/upx-3.95.exe
|
|
||||||
1b2f9a97731805dafef6961656bd29d7e983320a5626fe88ba987bf267bef32a *m68k-atari.tos/upx-3.91.ttp
|
|
||||||
21febba6606d89c4a0f72a7f07f55d90268da48b97c65d23647c021c2e26b7c4 *mips-linux.elf/upx-3.95
|
|
||||||
7a0892428e07493578d59f16adc0e6f5959f3d5a437e818375ff9fbf8ba42d2f *mipsel-linux.elf/upx-3.91
|
|
||||||
ecf7d97388e48f2ad27a06ab8f4027e165e5a34f577f7b4fec3928a946557d60 *mipsel-linux.elf/upx-3.95
|
|
||||||
171393e34d004f04040067080b4b48d08030708bd30bcea593f554ed13b4ddb8 *powerpc-linux.elf/upx-3.91
|
|
||||||
0b97ff1ed48d19e64120cd4fac5f4e76da6ea6f3ec1fda5cada11aa2142d045a *powerpc-linux.elf/upx-3.95
|
|
||||||
0c825675a076c7b9f73ae0292527e3d569b5c0b33298b9f48b7bdd3084115c69 *powerpc64le-linux.elf/upx-3.95
|
|
||||||
"
|
|
||||||
########## end .sha256sums.recreate
|
|
||||||
@@ -1,287 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
## vim:set ts=4 sw=4 et:
|
|
||||||
set -e; set -o pipefail
|
|
||||||
|
|
||||||
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
|
||||||
|
|
||||||
#
|
|
||||||
# very first version of the upx-testsuite
|
|
||||||
#
|
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == osx ]]; then
|
|
||||||
argv0=$0; argv0abs=$(greadlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
|
|
||||||
else
|
|
||||||
argv0=$0; argv0abs=$(readlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
|
|
||||||
fi
|
|
||||||
source "$argv0dir/travis_init.sh" || exit 1
|
|
||||||
|
|
||||||
if [[ $BM_T =~ (^|\+)SKIP($|\+) ]]; then
|
|
||||||
echo "UPX testsuite SKIPPED."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
if [[ $BM_X == rebuild-stubs ]]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# convenience
|
|
||||||
[[ -f $upx_exe ]] && upx_exe=$(readlink -en -- "$upx_exe")
|
|
||||||
|
|
||||||
# create dirs
|
|
||||||
cd / || exit 1
|
|
||||||
if [[ ! -d "$upx_testsuite_SRCDIR/files/packed" ]]; then
|
|
||||||
echo 'invalid or missing $upx_testsuite_SRCDIR:'
|
|
||||||
echo ' please git clone https://github.com/upx/upx-testsuite'
|
|
||||||
echo ' and set (export) the envvar upx_testsuite_SRCDIR to the local file path'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
mkbuilddirs "$upx_testsuite_BUILDDIR"
|
|
||||||
cd / && cd "$upx_testsuite_BUILDDIR" || exit 1
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // support functions
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
testsuite_header() {
|
|
||||||
print_header "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
testsuite_split_f() {
|
|
||||||
fd=$(dirname "$1")
|
|
||||||
fb=$(basename "$1")
|
|
||||||
fsubdir=$(basename "$fd")
|
|
||||||
# sanity checks
|
|
||||||
if [[ ! -f $1 || -z $fsubdir || -z $fb ]]; then
|
|
||||||
fd= fb= fsubdir=
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
testsuite_check_sha() {
|
|
||||||
(cd "$1" && sha256sum -b */* | LC_ALL=C sort -k2) > $1/.sha256sums.current
|
|
||||||
echo
|
|
||||||
cat $1/.sha256sums.current
|
|
||||||
if ! cmp -s $1/.sha256sums.expected $1/.sha256sums.current; then
|
|
||||||
echo "UPX-ERROR: $1 FAILED: checksum mismatch"
|
|
||||||
diff -u $1/.sha256sums.expected $1/.sha256sums.current || true
|
|
||||||
exit_code=99
|
|
||||||
let num_errors+=1 || true
|
|
||||||
all_errors="${all_errors} $1"
|
|
||||||
#exit 99
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
testsuite_check_sha_decompressed() {
|
|
||||||
(cd "$1" && sha256sum -b */* | LC_ALL=C sort -k2) > $1/.sha256sums.current
|
|
||||||
if ! cmp -s $1/.sha256sums.expected $1/.sha256sums.current; then
|
|
||||||
cat $1/.sha256sums.current
|
|
||||||
echo "UPX-ERROR: FATAL: $1 FAILED: decompressed checksum mismatch"
|
|
||||||
diff -u $1/.sha256sums.expected $1/.sha256sums.current || true
|
|
||||||
exit 98
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
testsuite_use_canonicalized=1
|
|
||||||
testsuite_run_compress() {
|
|
||||||
testsuite_header $testdir
|
|
||||||
local files f
|
|
||||||
if [[ $testsuite_use_canonicalized == 1 ]]; then
|
|
||||||
files=t020_canonicalized/*/*
|
|
||||||
else
|
|
||||||
files=t010_decompressed/*/*
|
|
||||||
fi
|
|
||||||
for f in $files; do
|
|
||||||
testsuite_split_f $f
|
|
||||||
[[ -z $fb ]] && continue
|
|
||||||
echo "# $f"
|
|
||||||
mkdir -p $testdir/$fsubdir $testdir/.decompressed/$fsubdir
|
|
||||||
$upx_run -qq --prefer-ucl "$@" $f -o $testdir/$fsubdir/$fb
|
|
||||||
$upx_run -qq -d $testdir/$fsubdir/$fb -o $testdir/.decompressed/$fsubdir/$fb
|
|
||||||
done
|
|
||||||
testsuite_check_sha $testdir
|
|
||||||
$upx_run -qq -l $testdir/*/*
|
|
||||||
$upx_run -qq --file-info $testdir/*/*
|
|
||||||
$upx_run -q -t $testdir/*/*
|
|
||||||
if [[ $testsuite_use_canonicalized == 1 ]]; then
|
|
||||||
# check that after decompression the file matches the canonicalized version
|
|
||||||
cp t020_canonicalized/.sha256sums.expected $testdir/.decompressed/
|
|
||||||
testsuite_check_sha_decompressed $testdir/.decompressed
|
|
||||||
rm -rf "./$testdir/.decompressed"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // expected checksums
|
|
||||||
# //
|
|
||||||
# // To ease maintenance of this script in case of updates this section
|
|
||||||
# // can be automatically re-created from the current checksums -
|
|
||||||
# // see call of function recreate_expected_sha256sums below.
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
recreate_expected_sha256sums() {
|
|
||||||
local o=$1
|
|
||||||
local files f d
|
|
||||||
echo "########## begin .sha256sums.recreate" > "$o"
|
|
||||||
files=*/.sha256sums.current
|
|
||||||
for f in $files; do
|
|
||||||
d=$(dirname "$f")
|
|
||||||
echo "expected_sha256sums__${d}="'"\' >> "$o"
|
|
||||||
cat "$f" >> "$o"
|
|
||||||
echo '"' >> "$o"
|
|
||||||
done
|
|
||||||
echo "########## end .sha256sums.recreate" >> "$o"
|
|
||||||
}
|
|
||||||
|
|
||||||
source "$argv0dir/travis_testsuite_1-expected_sha256sums.sh" || exit 1
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // init
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
#set -x # debug
|
|
||||||
exit_code=0
|
|
||||||
num_errors=0
|
|
||||||
all_errors=
|
|
||||||
|
|
||||||
if [[ $BM_T =~ (^|\+)ALLOW_FAIL($|\+) ]]; then
|
|
||||||
echo "ALLOW_FAIL"
|
|
||||||
set +e
|
|
||||||
fi
|
|
||||||
|
|
||||||
[[ -z $upx_exe && -f $upx_BUILDDIR/upx.out ]] && upx_exe=$upx_BUILDDIR/upx.out
|
|
||||||
[[ -z $upx_exe && -f $upx_BUILDDIR/upx.exe ]] && upx_exe=$upx_BUILDDIR/upx.exe
|
|
||||||
if [[ -z $upx_exe ]]; then exit 1; fi
|
|
||||||
upx_run=$upx_exe
|
|
||||||
if [[ $BM_T =~ (^|\+)qemu($|\+) && -n $upx_qemu ]]; then
|
|
||||||
upx_run="$upx_qemu $upx_qemu_flags -- $upx_exe"
|
|
||||||
fi
|
|
||||||
if [[ $BM_T =~ (^|\+)wine($|\+) && -n $upx_wine ]]; then
|
|
||||||
upx_run="$upx_wine $upx_wine_flags $upx_exe"
|
|
||||||
fi
|
|
||||||
if [[ $BM_T =~ (^|\+)valgrind($|\+) ]]; then
|
|
||||||
if [[ -z $upx_valgrind ]]; then
|
|
||||||
upx_valgrind="valgrind"
|
|
||||||
fi
|
|
||||||
if [[ -z $upx_valgrind_flags ]]; then
|
|
||||||
#upx_valgrind_flags="--leak-check=full --show-reachable=yes"
|
|
||||||
#upx_valgrind_flags="-q --leak-check=no --error-exitcode=1"
|
|
||||||
upx_valgrind_flags="--leak-check=no --error-exitcode=1"
|
|
||||||
fi
|
|
||||||
upx_run="$upx_valgrind $upx_valgrind_flags $upx_exe"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $BM_B =~ (^|\+)coverage($|\+) ]]; then
|
|
||||||
(cd / && cd "$upx_BUILDDIR" && lcov -d . --zerocounters)
|
|
||||||
fi
|
|
||||||
|
|
||||||
export UPX="--prefer-ucl --no-color --no-progress"
|
|
||||||
export UPX_DEBUG_DISABLE_GITREV_WARNING=1
|
|
||||||
export UPX_DEBUG_DOCTEST_VERBOSE=0
|
|
||||||
|
|
||||||
# let's go
|
|
||||||
if ! $upx_run --version-short; then echo "UPX-ERROR: FATAL: upx --version-short FAILED"; exit 1; fi
|
|
||||||
if ! $upx_run -L >/dev/null 2>&1; then echo "UPX-ERROR: FATAL: upx -L FAILED"; exit 1; fi
|
|
||||||
if ! $upx_run --help >/dev/null; then echo "UPX-ERROR: FATAL: upx --help FAILED"; exit 1; fi
|
|
||||||
rm -rf ./testsuite_1
|
|
||||||
mkbuilddirs testsuite_1
|
|
||||||
cd testsuite_1 || exit 1
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // decompression tests
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
testdir=t010_decompressed
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
|
|
||||||
testsuite_header $testdir
|
|
||||||
for f in $upx_testsuite_SRCDIR/files/packed/*/upx-3.9[15]*; do
|
|
||||||
testsuite_split_f $f
|
|
||||||
[[ -z $fb ]] && continue
|
|
||||||
echo "# $f"
|
|
||||||
mkdir -p $testdir/$fsubdir
|
|
||||||
$upx_run -qq -d $f -o $testdir/$fsubdir/$fb
|
|
||||||
done
|
|
||||||
testsuite_check_sha $testdir
|
|
||||||
|
|
||||||
# run one pack+unpack step to canonicalize the files
|
|
||||||
testdir=t020_canonicalized
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
|
|
||||||
testsuite_header $testdir
|
|
||||||
for f in t010_decompressed/*/*; do
|
|
||||||
testsuite_split_f $f
|
|
||||||
[[ -z $fb ]] && continue
|
|
||||||
echo "# $f"
|
|
||||||
mkdir -p $testdir/$fsubdir/.packed
|
|
||||||
$upx_run -qq --prefer-ucl -1 $f -o $testdir/$fsubdir/.packed/$fb
|
|
||||||
$upx_run -qq -d $testdir/$fsubdir/.packed/$fb -o $testdir/$fsubdir/$fb
|
|
||||||
done
|
|
||||||
testsuite_check_sha $testdir
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // compression tests
|
|
||||||
# // info: we use fast compression levels because we want to
|
|
||||||
# // test UPX and not the compression libraries
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
testdir=t110_compress_ucl_nrv2b_3_no_filter
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
time testsuite_run_compress --nrv2b -3 --no-filter
|
|
||||||
|
|
||||||
testdir=t120_compress_ucl_nrv2d_3_no_filter
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
time testsuite_run_compress --nrv2d -3 --no-filter
|
|
||||||
|
|
||||||
testdir=t130_compress_ucl_nrv2e_3_no_filter
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
time testsuite_run_compress --nrv2e -3 --no-filter
|
|
||||||
|
|
||||||
testdir=t140_compress_lzma_2_no_filter
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
time testsuite_run_compress --lzma -2 --no-filter
|
|
||||||
|
|
||||||
testdir=t150_compress_ucl_2_all_filters
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
time testsuite_run_compress -2 --all-filters
|
|
||||||
|
|
||||||
testdir=t160_compress_all_methods_1_no_filter
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
time testsuite_run_compress --all-methods -1 --no-filter
|
|
||||||
|
|
||||||
testdir=t170_compress_all_methods_no_lzma_5_no_filter
|
|
||||||
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
|
||||||
time testsuite_run_compress --all-methods --no-lzma -5 --no-filter
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# // summary
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
# recreate checksums from current version for an easy update in case of changes
|
|
||||||
recreate_expected_sha256sums .sha256sums.recreate
|
|
||||||
|
|
||||||
testsuite_header "UPX testsuite summary"
|
|
||||||
if ! $upx_run --version-short; then
|
|
||||||
echo "UPX-ERROR: upx --version-short FAILED"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
echo "upx_exe='$upx_exe'"
|
|
||||||
if [[ $upx_run != "$upx_exe" ]]; then
|
|
||||||
echo "upx_run='$upx_run'"
|
|
||||||
fi
|
|
||||||
if [[ -f $upx_exe ]]; then
|
|
||||||
ls -l "$upx_exe"
|
|
||||||
file "$upx_exe" || true
|
|
||||||
fi
|
|
||||||
echo "upx_testsuite_SRCDIR='$upx_testsuite_SRCDIR'"
|
|
||||||
echo "upx_testsuite_BUILDDIR='$upx_testsuite_BUILDDIR'"
|
|
||||||
echo ".sha256sums.{expected,current}:"
|
|
||||||
cat */.sha256sums.expected | LC_ALL=C sort | wc
|
|
||||||
cat */.sha256sums.current | LC_ALL=C sort | wc
|
|
||||||
echo
|
|
||||||
if [[ $exit_code == 0 ]]; then
|
|
||||||
echo "UPX testsuite passed. All done."
|
|
||||||
else
|
|
||||||
echo "UPX-ERROR: UPX testsuite FAILED:${all_errors}"
|
|
||||||
echo "UPX-ERROR: UPX testsuite FAILED with $num_errors error(s). See log file."
|
|
||||||
fi
|
|
||||||
exit $exit_code
|
|
||||||
+371
-115
@@ -1,4 +1,3 @@
|
|||||||
# Support for GitHub Actions -- https://github.com/features/actions
|
|
||||||
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
|
||||||
# note: GitHub Actions runner images are frequently updated, and
|
# note: GitHub Actions runner images are frequently updated, and
|
||||||
@@ -7,17 +6,17 @@
|
|||||||
|
|
||||||
name: 'CI'
|
name: 'CI'
|
||||||
|
|
||||||
on:
|
on: [push, workflow_dispatch]
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- '*'
|
|
||||||
- '!appveyor*'
|
|
||||||
- '!gitlab*'
|
|
||||||
- '!travis*'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
CMAKE_REQUIRED_QUIET: 'OFF'
|
||||||
|
CMAKE_VERBOSE_MAKEFILE: 'ON'
|
||||||
|
CTEST_OUTPUT_ON_FAILURE: 'ON'
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
UPX_CMAKE_BUILD_FLAGS: --verbose
|
UPX_CMAKE_BUILD_FLAGS: --verbose
|
||||||
|
UPX_CMAKE_CONFIG_FLAGS: -Wdev --warn-uninitialized
|
||||||
|
# 2023-11-08
|
||||||
|
ZIG_DIST_VERSION: 0.12.0-dev.1502+b3462b7ce
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
job-rebuild-and-verify-stubs:
|
job-rebuild-and-verify-stubs:
|
||||||
@@ -27,30 +26,41 @@ jobs:
|
|||||||
- name: 'Install extra packages'
|
- name: 'Install extra packages'
|
||||||
run: |
|
run: |
|
||||||
uname -a; pwd; id; umask
|
uname -a; pwd; id; umask
|
||||||
cd ..; mkdir -p deps; cd deps; mkdir packages
|
mkdir ../deps; cd ../deps; mkdir packages
|
||||||
# for ubuntu-22.04: install python2
|
if ! test -e /usr/bin/python2; then
|
||||||
##export DEBIAN_FRONTEND=noninteractive
|
####sudo apt-get update && sudo apt-get install -y --no-install-recommends python2-minimal
|
||||||
##sudo apt-get install -y --no-install-recommends python2-minimal
|
# install python2-minimal packages from Debian-11
|
||||||
# manually install compat libs from Ubuntu 16.04
|
wget -q 'https://ftp.debian.org/debian/pool/main/p/python2.7/libpython2.7-minimal_2.7.18-8+deb11u1_amd64.deb'
|
||||||
wget -q 'http://mirror.enzu.com/ubuntu/pool/main/g/gmp/libgmp10_6.1.0+dfsg-2_amd64.deb'
|
wget -q 'https://ftp.debian.org/debian/pool/main/p/python2.7/python2.7-minimal_2.7.18-8+deb11u1_amd64.deb'
|
||||||
wget -q 'http://mirror.enzu.com/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.4-1_amd64.deb'
|
sudo dpkg -i ./*python2*.deb && rm ./*python2*.deb && sudo ldconfig
|
||||||
for f in *.deb; do dpkg -x $f ./packages; done
|
sudo ln -s -v python2.7 /usr/bin/python2
|
||||||
|
fi
|
||||||
|
# manually unpack and install compat libs from Ubuntu-16.04
|
||||||
|
wget -q 'https://archive.kernel.org/ubuntu-archive/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.6-1_amd64.deb'
|
||||||
|
for f in ./*.deb; do dpkg -x $f ./packages; done
|
||||||
sudo mv -v -n ./packages/usr/lib/x86_64-linux-gnu/lib* /usr/lib/x86_64-linux-gnu/
|
sudo mv -v -n ./packages/usr/lib/x86_64-linux-gnu/lib* /usr/lib/x86_64-linux-gnu/
|
||||||
|
rm -rf ./*.deb ./packages
|
||||||
sudo ldconfig
|
sudo ldconfig
|
||||||
wget -q -O - https://github.com/upx/upx-stubtools/releases/download/v20210104/bin-upx-20210104.tar.xz | tar -xJ
|
# install upx-stubtools
|
||||||
|
wget -q -O - https://github.com/upx/upx-stubtools/releases/download/v20221212/bin-upx-20221212.tar.xz | tar -xJ
|
||||||
- name: 'Check out code'
|
- name: 'Check out code'
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with: { submodules: true }
|
with: { submodules: true }
|
||||||
- name: 'Rebuild and verify stubs'
|
- name: 'Rebuild and verify stubs'
|
||||||
run: |
|
run: |
|
||||||
env C=gcc X=rebuild-stubs TRAVIS_OS_NAME=linux bash ./.github/travis_build.sh
|
export PATH="$(readlink -en ../deps/bin-upx-20221212):$PATH"
|
||||||
|
make -C src/stub maintainer-clean extra-clean
|
||||||
|
git status || true
|
||||||
|
make -C src/stub extra-all all
|
||||||
|
if ! git diff --quiet; then git diff; exit 1; fi
|
||||||
- name: 'Check source code formatting'
|
- name: 'Check source code formatting'
|
||||||
run: |
|
run: |
|
||||||
bash ./misc/scripts/check_whitespace_git.sh
|
bash ./misc/scripts/check_whitespace_git.sh
|
||||||
env UPX_CLANG_FORMAT="$PWD/../deps/bin-upx-20210104/clang-format-10.0.1" make -C src clang-format
|
UPX_CLANG_FORMAT="$PWD/../deps/bin-upx-20221212/clang-format-15.0.6" make -C src clang-format
|
||||||
if ! git diff --quiet; then git diff; exit 1; fi
|
if ! git diff --quiet; then git diff; exit 1; fi
|
||||||
|
|
||||||
job-linux-cmake:
|
job-linux-cmake: # uses cmake + make
|
||||||
|
if: true
|
||||||
needs: [ job-rebuild-and-verify-stubs ]
|
needs: [ job-rebuild-and-verify-stubs ]
|
||||||
name: ${{ format('{0} cmake', matrix.os) }}
|
name: ${{ format('{0} cmake', matrix.os) }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -58,41 +68,95 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- { os: ubuntu-20.04 }
|
- { os: ubuntu-22.04, use_m32: true }
|
||||||
- { os: ubuntu-22.04 }
|
- { os: ubuntu-20.04, use_m32: true } # use_m32 also works here, but save some CI time
|
||||||
|
env:
|
||||||
|
UPX_CONFIG_EXPECT_THREADS: 'ON'
|
||||||
steps:
|
steps:
|
||||||
|
- name: 'Install extra 32-bit and Windows packages'
|
||||||
|
if: ${{ matrix.use_m32 }}
|
||||||
|
run: |
|
||||||
|
sudo dpkg --add-architecture i386
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y g++-multilib g++-mingw-w64-i686 g++-mingw-w64-x86-64
|
||||||
|
# make sure that we use posix-threads (pthread/winpthreads) and NOT win32-threads
|
||||||
|
for f in i686-w64-mingw32-g++ i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc; do
|
||||||
|
if test -f /usr/bin/$f-posix; then sudo update-alternatives --set $f /usr/bin/$f-posix; fi
|
||||||
|
done
|
||||||
- name: 'Check out code'
|
- name: 'Check out code'
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with: { submodules: true }
|
with: { submodules: true }
|
||||||
- name: 'Build cmake debug-gcc'
|
- name: 'Check out test suite'
|
||||||
run: 'make build/debug-gcc'
|
run: 'git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite'
|
||||||
- name: 'Build cmake release-gcc'
|
- name: 'Build cmake extra/gcc/debug'
|
||||||
run: 'make build/release-gcc'
|
run: 'make build/extra/gcc/debug'
|
||||||
- name: 'Build cmake debug-clang'
|
- name: 'Build cmake extra/gcc/release'
|
||||||
run: 'make build/debug-clang'
|
run: 'make build/extra/gcc/release'
|
||||||
- name: 'Build cmake release-clang'
|
- name: 'Build cmake extra/clang/debug'
|
||||||
run: 'make build/release-clang'
|
run: 'make build/extra/clang/debug'
|
||||||
|
- name: 'Build cmake extra/clang/release'
|
||||||
|
run: 'make build/extra/clang/release'
|
||||||
|
- name: 'Build cmake extra/gcc-m32/debug'
|
||||||
|
if: ${{ matrix.use_m32 }}
|
||||||
|
run: 'make build/extra/gcc-m32/debug'
|
||||||
|
- name: 'Build cmake extra/gcc-m32/release'
|
||||||
|
if: ${{ matrix.use_m32 && (success() || failure()) }} # run this step even if the previous step failed
|
||||||
|
run: 'make build/extra/gcc-m32/release'
|
||||||
|
- name: 'Build cmake extra/cross-windows-mingw32/release'
|
||||||
|
if: ${{ matrix.use_m32 && (success() || failure()) }} # run this step even if the previous step failed
|
||||||
|
run: 'make build/extra/cross-windows-mingw32/release'
|
||||||
|
- name: 'Build cmake extra/cross-windows-mingw64/release'
|
||||||
|
if: ${{ matrix.use_m32 && (success() || failure()) }} # run this step even if the previous step failed
|
||||||
|
run: 'make build/extra/cross-windows-mingw64/release'
|
||||||
- name: 'Make artifact'
|
- name: 'Make artifact'
|
||||||
run: |
|
run: |
|
||||||
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
|
N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}" | sed 's/[^0-9a-zA-Z_.-]/-/g')
|
||||||
mkdir -p "tmp/artifact/$N"
|
mkdir -p "tmp/artifact/$N"
|
||||||
(cd build && cp -ai --parents */upx "../tmp/artifact/$N")
|
(cd build && shopt -s nullglob && cp -ai --parents */upx{,.exe} */*/*/upx{,.exe} "../tmp/artifact/$N")
|
||||||
(cd tmp/artifact && tar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N")
|
(cd tmp/artifact && tar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N")
|
||||||
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
||||||
echo "artifact_name=$N" >> $GITHUB_ENV
|
echo "artifact_name=$N" >> $GITHUB_ENV
|
||||||
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.artifact_name }}
|
name: ${{ env.artifact_name }}
|
||||||
path: tmp/artifact
|
path: tmp/artifact
|
||||||
- name: 'Run basic tests'
|
- name: 'Run install tests'
|
||||||
run: |
|
run: |
|
||||||
make -C build/debug-gcc test
|
(cd build/extra/gcc/release && DESTDIR=$PWD/Install-with-cmake cmake --install .)
|
||||||
make -C build/release-gcc test
|
(cd build/extra/gcc/release && DESTDIR=$PWD/Install-with-make make install)
|
||||||
make -C build/debug-clang test
|
- name: 'Run ctest tests'
|
||||||
make -C build/release-clang test
|
run: |
|
||||||
|
make -C build/extra/gcc/debug test
|
||||||
|
make -C build/extra/gcc/release test
|
||||||
|
make -C build/extra/clang/debug test
|
||||||
|
make -C build/extra/clang/release test
|
||||||
|
- name: 'Run ctest tests 32-bit'
|
||||||
|
if: ${{ matrix.use_m32 }}
|
||||||
|
run: |
|
||||||
|
make -C build/extra/gcc-m32/debug test
|
||||||
|
make -C build/extra/gcc-m32/release test
|
||||||
|
- name: 'Mimic ctest tests'
|
||||||
|
run: |
|
||||||
|
env -C build/extra/gcc/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
env -C build/extra/clang/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
env -C build/extra/clang/release bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
- name: 'Mimic ctest tests 32-bit'
|
||||||
|
if: ${{ matrix.use_m32 }}
|
||||||
|
run: |
|
||||||
|
env -C build/extra/gcc-m32/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
env -C build/extra/gcc-m32/release bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
- name: 'Run file system test suite'
|
||||||
|
run: |
|
||||||
|
env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/test_symlinks.sh
|
||||||
|
- name: 'Run test suite build/extra/gcc/release'
|
||||||
|
run: |
|
||||||
|
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
|
||||||
|
env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
||||||
|
|
||||||
job-macos-cmake:
|
job-macos-cmake: # uses cmake + make
|
||||||
|
if: true
|
||||||
needs: [ job-rebuild-and-verify-stubs ]
|
needs: [ job-rebuild-and-verify-stubs ]
|
||||||
name: ${{ format('{0} cmake', matrix.os) }}
|
name: ${{ format('{0} cmake', matrix.os) }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -100,65 +164,113 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- { os: macos-11, gcc: gcc-10, gxx: 'g++-10' }
|
# NOTE: macos does not have "env -C"; only with brew coreutils
|
||||||
# { os: macos-12, gcc: gcc-11, gxx: 'g++-11' } # disable gcc - XCode 14.0 ld bug
|
# NOTE: macos-11 does not have "readlink -f"; only on macos >= 12 or with brew coreutils
|
||||||
- { os: macos-12 }
|
- { os: macos-11, gcc: gcc-10, gxx: 'g++-10', testsuite: true }
|
||||||
|
- { os: macos-12, gcc: gcc-11, gxx: 'g++-11', testsuite: true }
|
||||||
|
- { os: macos-13, gcc: gcc-12, gxx: 'g++-12', testsuite: true }
|
||||||
|
env:
|
||||||
|
UPX_CONFIG_EXPECT_THREADS: 'ON'
|
||||||
steps:
|
steps:
|
||||||
|
- name: 'Install brew packages'
|
||||||
|
if: ${{ matrix.testsuite }}
|
||||||
|
run: |
|
||||||
|
# testsuite needs working "readlink -en" and "sha256sum -b"
|
||||||
|
if ! test -e /usr/local/opt/coreutils/libexec/gnubin/readlink; then
|
||||||
|
echo "===== brew leaves:"; brew leaves; echo "===== brew list:"; brew list --versions
|
||||||
|
# only run "brew update" if needed
|
||||||
|
if ! brew install coreutils; then brew update && brew install coreutils; fi
|
||||||
|
fi
|
||||||
- name: 'Check out code'
|
- name: 'Check out code'
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with: { submodules: true }
|
with: { submodules: true }
|
||||||
- name: 'Build cmake debug-gcc'
|
- name: 'Check out test suite'
|
||||||
|
if: ${{ matrix.testsuite }}
|
||||||
|
run: 'git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite'
|
||||||
|
- name: 'Build cmake extra/clang/debug'
|
||||||
|
run: 'make build/extra/clang/debug'
|
||||||
|
- name: 'Build cmake extra/clang/release'
|
||||||
|
run: 'make build/extra/clang/release'
|
||||||
|
- name: 'Build cmake extra/gcc/debug'
|
||||||
if: ${{ matrix.gcc != '' }}
|
if: ${{ matrix.gcc != '' }}
|
||||||
run: 'make build/debug-gcc CC=${{ matrix.gcc }} CXX=${{ matrix.gxx }}'
|
run: 'make build/extra/gcc/debug CC="${{ matrix.gcc }} -static-libgcc" CXX="${{ matrix.gxx }} -static-libgcc -static-libstdc++"'
|
||||||
- name: 'Build cmake release-gcc'
|
- name: 'Build cmake extra/gcc/release'
|
||||||
if: ${{ matrix.gcc != '' }}
|
if: ${{ matrix.gcc != '' }}
|
||||||
run: 'make build/release-gcc CC=${{ matrix.gcc }} CXX=${{ matrix.gxx }}'
|
run: 'make build/extra/gcc/release CC="${{ matrix.gcc }} -static-libgcc" CXX="${{ matrix.gxx }} -static-libgcc -static-libstdc++"'
|
||||||
- name: 'Build cmake debug-clang'
|
- name: 'Build cmake xtarget/cross-darwin-arm64/debug'
|
||||||
run: 'make build/debug-clang'
|
run: |
|
||||||
- name: 'Build cmake release-clang'
|
CC="clang -target arm64-apple-darwin" CXX="clang++ -target arm64-apple-darwin" \
|
||||||
run: 'make build/release-clang'
|
make UPX_XTARGET=cross-darwin-arm64 xtarget/debug
|
||||||
|
- name: 'Build cmake xtarget/cross-darwin-arm64/release'
|
||||||
|
run: |
|
||||||
|
CC="clang -target arm64-apple-darwin" CXX="clang++ -target arm64-apple-darwin" \
|
||||||
|
make UPX_XTARGET=cross-darwin-arm64 xtarget/release
|
||||||
- name: 'Make artifact'
|
- name: 'Make artifact'
|
||||||
run: |
|
run: |
|
||||||
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
|
N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}" | sed 's/[^0-9a-zA-Z_.-]/-/g')
|
||||||
mkdir -p "tmp/artifact/$N"
|
mkdir -p "tmp/artifact/$N"
|
||||||
(cd build && rsync -R -a */upx "../tmp/artifact/$N/")
|
(cd build && rsync -R -a */*/*/upx "../tmp/artifact/$N/")
|
||||||
(cd tmp/artifact && gtar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N")
|
(cd tmp/artifact && gtar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N")
|
||||||
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
||||||
echo "artifact_name=$N" >> $GITHUB_ENV
|
echo "artifact_name=$N" >> $GITHUB_ENV
|
||||||
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.artifact_name }}
|
name: ${{ env.artifact_name }}
|
||||||
path: tmp/artifact
|
path: tmp/artifact
|
||||||
- name: 'Run basic tests'
|
- name: 'Run install tests'
|
||||||
run: |
|
run: |
|
||||||
make -C build/debug-clang test
|
(cd build/extra/clang/release && DESTDIR=$PWD/Install-with-cmake cmake --install .)
|
||||||
make -C build/release-clang test
|
(cd build/extra/clang/release && DESTDIR=$PWD/Install-with-make make install)
|
||||||
|
- name: 'Run ctest tests'
|
||||||
|
if: ${{ !contains(matrix.os, 'macos-13') }} # FIXME: UPX on macos-13 is broken => disable self-test for now
|
||||||
|
run: |
|
||||||
|
make -C build/extra/clang/debug test
|
||||||
|
#make -C build/extra/clang/release test
|
||||||
|
for f in ./build/extra/*/*/upx; do echo "===== $f"; $f --sysinfo -v; done
|
||||||
|
- name: 'Mimic ctest tests'
|
||||||
|
if: ${{ !contains(matrix.os, 'macos-13') }} # FIXME: UPX on macos-13 is broken => disable self-test for now
|
||||||
|
run: |
|
||||||
|
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
|
||||||
|
env -C build/extra/clang/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
#env -C build/extra/clang/release bash "$PWD"/misc/testsuite/mimic_ctest.sh
|
||||||
|
- name: 'Run file system test suite'
|
||||||
|
if: ${{ matrix.testsuite }} # for coreutils readlink
|
||||||
|
run: |
|
||||||
|
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
|
||||||
|
env -C build/extra/clang/release bash "$PWD"/misc/testsuite/test_symlinks.sh
|
||||||
|
- name: 'Run test suite build/extra/clang/release'
|
||||||
|
if: ${{ matrix.testsuite }}
|
||||||
|
run: |
|
||||||
|
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
|
||||||
|
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
|
||||||
|
env -C build/extra/clang/release bash "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
||||||
|
|
||||||
job-windows-cmake:
|
job-windows-cmake: # uses cmake + msbuild
|
||||||
|
if: true
|
||||||
needs: [ job-rebuild-and-verify-stubs ]
|
needs: [ job-rebuild-and-verify-stubs ]
|
||||||
name: ${{ format('{0} cmake', matrix.os) }}
|
name: ${{ format('{0} cmake', matrix.name) }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
# windows-2019 used to work but got broken with the 20220821.1
|
- { name: windows-2019-amd64, os: windows-2019, vsversion: 2019, arch: amd64 }
|
||||||
# runner-image update; disable for now
|
- { name: windows-2022-amd64, os: windows-2022, vsversion: 2022, arch: amd64 }
|
||||||
# see https://github.com/actions/runner-images.git
|
env:
|
||||||
####- { os: windows-2019 }
|
UPX_CONFIG_EXPECT_THREADS: 'ON'
|
||||||
- { os: windows-2022 }
|
|
||||||
steps:
|
steps:
|
||||||
|
- run: git config --global core.autocrlf false
|
||||||
- name: 'Check out code'
|
- name: 'Check out code'
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with: { submodules: true }
|
with: { submodules: true }
|
||||||
- name: 'Inspect runner-image settings'
|
- name: 'Check out test suite'
|
||||||
# see https://github.com/actions/runner-images.git
|
run: 'git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite'
|
||||||
if: ${{ false }}
|
- name: 'Set up Developer Command Prompt'
|
||||||
run: |
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
Get-Command bash; Get-Command cmake; Get-Command make
|
with:
|
||||||
bash --version; cmake --version; make --version
|
vsversion: ${{ matrix.vsversion }}
|
||||||
Get-Command cl -ErrorAction SilentlyContinue
|
arch: ${{ matrix.arch }}
|
||||||
- name: 'Build cmake debug'
|
- name: 'Build cmake debug'
|
||||||
run: 'make build/debug'
|
run: 'make build/debug'
|
||||||
- name: 'Build cmake release'
|
- name: 'Build cmake release'
|
||||||
@@ -166,106 +278,250 @@ jobs:
|
|||||||
- name: 'Make artifact'
|
- name: 'Make artifact'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
|
N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}" | sed 's/[^0-9a-zA-Z_.-]/-/g')
|
||||||
mkdir -p "tmp/artifact/$N"
|
mkdir -p "tmp/artifact/$N"
|
||||||
(cd build && cp -ai --parents */*/upx.exe "../tmp/artifact/$N")
|
(cd build && cp -ai --parents */*/upx.exe "../tmp/artifact/$N")
|
||||||
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
||||||
echo "artifact_name=$N" >> $GITHUB_ENV
|
echo "artifact_name=$N" >> $GITHUB_ENV
|
||||||
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.artifact_name }}
|
name: ${{ env.artifact_name }}
|
||||||
path: tmp/artifact
|
path: tmp/artifact
|
||||||
- name: 'Run basic tests'
|
- name: 'Run ctest tests'
|
||||||
|
if: ${{ matrix.arch != 'amd64_arm64' }}
|
||||||
run: |
|
run: |
|
||||||
cmake --build build/debug --config Debug --target RUN_TESTS
|
ctest --test-dir build/debug -C Debug
|
||||||
cmake --build build/release --config Release --target RUN_TESTS
|
ctest --test-dir build/release -C Release
|
||||||
|
- name: 'Run test suite build/release'
|
||||||
|
if: ${{ matrix.arch != 'amd64_arm64' }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
|
||||||
|
env -C build/release/Release bash "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
||||||
|
|
||||||
job-windows-toolchains:
|
job-windows-toolchains: # build "by hand" using cmd.exe
|
||||||
|
if: github.repository_owner == 'upx'
|
||||||
needs: [ job-rebuild-and-verify-stubs ]
|
needs: [ job-rebuild-and-verify-stubs ]
|
||||||
name: ${{ matrix.name }}
|
name: ${{ format('windows {0}', matrix.name) }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
env:
|
env:
|
||||||
C: ${{ matrix.C }}
|
C: ${{ matrix.name }}
|
||||||
B: release
|
B: release
|
||||||
H: 'd:\a\upx'
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- { name: amd64-win64-msvc-14.2, os: windows-2019, C: msvc-14.2-x64, A: x64 }
|
- { name: amd64-win64-vs2019, os: windows-2019, vsversion: 2019, arch: amd64 }
|
||||||
- { name: amd64-win64-msvc-14.3, os: windows-2022, C: msvc-14.3-x64, A: x64 }
|
- { name: amd64-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64 }
|
||||||
- { name: i386-win32-msvc-14.2, os: windows-2019, C: msvc-14.2-x86, A: x86 }
|
- { name: arm64-win64-vs2019, os: windows-2019, vsversion: 2019, arch: amd64_arm64 }
|
||||||
- { name: i386-win32-msvc-14.3, os: windows-2022, C: msvc-14.3-x86, A: x86 }
|
- { name: arm64-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_arm64 }
|
||||||
|
- { name: arm64ec-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_arm64, cl_machine_flags: -arm64EC, link_machine_flags: '/machine:arm64ec' }
|
||||||
|
# { name: arm64x-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_arm64, cl_machine_flags: -arm64EC, link_machine_flags: '/machine:arm64x' }
|
||||||
|
- { name: i386-win32-vs2019, os: windows-2019, vsversion: 2019, arch: amd64_x86 }
|
||||||
|
- { name: i386-win32-vs2022, os: windows-2022, vsversion: 2022, arch: amd64_x86 }
|
||||||
steps:
|
steps:
|
||||||
|
- run: git config --global core.autocrlf false
|
||||||
- name: 'Check out code'
|
- name: 'Check out code'
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with: { submodules: true }
|
with: { submodules: true }
|
||||||
- name: 'Prepare sources'
|
- name: 'Prepare sources and Check out test suite'
|
||||||
shell: cmd
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
where bash & where cat & where chmod & where cmp & where cp & where curl & where date & where file & where git & where gzip & where mkdir & where mv & where openssl & where readlink & where rm & where rmdir & where sed & where sha256sum & where sort & where ssh & where ssh-add & where ssh-agent & where ssh-keyscan & where tar & where touch
|
git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite
|
||||||
git config --global core.autocrlf input
|
mkdir -p -v build/$C/$B/{bzip2,ucl,upx,zlib,zstd}
|
||||||
git --version & bash --version
|
repository_name="${GITHUB_REPOSITORY##*/}" # basename
|
||||||
cd %H%
|
echo "H=d:\\a\\$repository_name\\$repository_name" >> $GITHUB_ENV
|
||||||
md build build\%C% deps
|
|
||||||
cd deps
|
|
||||||
git clone --depth=1 https://github.com/upx/upx-testsuite
|
|
||||||
- name: 'Set up Developer Command Prompt'
|
- name: 'Set up Developer Command Prompt'
|
||||||
uses: ilammy/msvc-dev-cmd@v1
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
with:
|
with:
|
||||||
arch: ${{ matrix.A }}
|
vsversion: ${{ matrix.vsversion }}
|
||||||
- name: 'Build'
|
arch: ${{ matrix.arch }}
|
||||||
|
- name: 'Build by hand'
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: |
|
run: |
|
||||||
@REM setup directories following the VPATH build in travis_build.sh
|
@REM ===== set vars =====
|
||||||
where cl & where link
|
where cl & where link
|
||||||
|
set RUN_CL=cl ${{ matrix.cl_machine_flags }} -MT
|
||||||
|
set RUN_LIB=link -lib ${{ matrix.link_machine_flags }}
|
||||||
|
@rem UPX only uses the very basic Windows API
|
||||||
|
set DEFS=-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0400
|
||||||
set BDIR=%H%\build\%C%\%B%
|
set BDIR=%H%\build\%C%\%B%
|
||||||
md %BDIR% %BDIR%\ucl %BDIR%\upx %BDIR%\upx-testsuite %BDIR%\zlib
|
|
||||||
set DEFS=-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS
|
|
||||||
git rev-parse --short=12 HEAD > %BDIR%\upx\.GITREV.txt
|
git rev-parse --short=12 HEAD > %BDIR%\upx\.GITREV.txt
|
||||||
|
@REM ===== build bzip2 =====
|
||||||
|
cd %BDIR%\bzip2
|
||||||
|
@rem %RUN_CL% -J -O2 -W4 -wd4127 -wd4244 -wd4267 -WX %DEFS% -DBZ_NO_STDIO -c %H%\vendor\bzip2\*.c
|
||||||
|
@rem %RUN_LIB% -out:bzip2.lib *.obj
|
||||||
@REM ===== build UCL =====
|
@REM ===== build UCL =====
|
||||||
cd %BDIR%\ucl
|
cd %BDIR%\ucl
|
||||||
set s=%H%\upx\vendor\ucl
|
set s=%H%\vendor\ucl
|
||||||
cl -MT -J -O2 -W4 %DEFS% -I%s%\include -I%s% -c %s%\src\*.c
|
%RUN_CL% -J -O2 -W4 -WX %DEFS% -I%s%\include -I%s% -c %s%\src\*.c
|
||||||
link -lib -out:ucl.lib *.obj
|
%RUN_LIB% -out:ucl.lib *.obj
|
||||||
@REM ===== build zlib =====
|
@REM ===== build zlib =====
|
||||||
cd %BDIR%\zlib
|
cd %BDIR%\zlib
|
||||||
cl -MT -J -O2 -W3 %DEFS% -c %H%\upx\vendor\zlib\*.c
|
%RUN_CL% -J -O2 -W3 -WX %DEFS% -DHAVE_VSNPRINTF -c %H%\vendor\zlib\*.c
|
||||||
link -lib -out:zlib.lib *.obj
|
%RUN_LIB% -out:zlib.lib *.obj
|
||||||
|
@REM ===== build zstd =====
|
||||||
|
cd %BDIR%\zstd
|
||||||
|
set s=%H%\vendor\zstd\lib
|
||||||
|
@rem %RUN_CL% -J -O2 -W4 -WX %DEFS% -DDYNAMIC_BMI2=0 -DZSTD_DISABLE_ASM -c %s%\common\*.c %s%\compress\*.c %s%\decompress\*.c
|
||||||
|
@rem %RUN_LIB% -out:zstd.lib *.obj
|
||||||
@REM ===== build UPX =====
|
@REM ===== build UPX =====
|
||||||
cd %BDIR%\upx
|
cd %BDIR%\upx
|
||||||
set s=%H%\upx\src
|
set s=%H%\src
|
||||||
cat .GITREV.txt
|
cat .GITREV.txt
|
||||||
set /p GITREV=<.GITREV.txt
|
set /p GITREV=<.GITREV.txt
|
||||||
cl -MT -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -I%H%\upx\vendor -Feupx.exe %s%\*.cpp %s%\util\*.cpp %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj
|
set UPX_DEFS=-DUPX_CONFIG_DISABLE_WSTRICT=0 -DUPX_CONFIG_DISABLE_WERROR=0 -DWITH_THREADS=0 -DWITH_BZIP2=0 -DWITH_ZSTD=0
|
||||||
|
set UPX_LIBS=%BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib
|
||||||
|
@rem set UPX_LIBS=%BDIR%\bzip2\bzip2.lib %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib %BDIR%\zstd\zstd.lib
|
||||||
|
set sources=%s%\*.cpp %s%\check\*.cpp %s%\compress\*.cpp %s%\console\*.cpp %s%\filter\*.cpp %s%\util\*.cpp
|
||||||
|
%RUN_CL% -J -O2 -W4 -WX -std:c++17 -Zc:__cplusplus -EHsc -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% %UPX_DEFS% -I%H%\vendor -Feupx.exe %sources% %UPX_LIBS% /link ${{ matrix.link_machine_flags }} setargv.obj
|
||||||
- name: 'Make artifact'
|
- name: 'Make artifact'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.name }}
|
N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-windows-${{ matrix.name }}" | sed 's/[^0-9a-zA-Z_.-]/-/g')
|
||||||
mkdir -p "tmp/artifact/$N/$B"
|
mkdir -p "tmp/artifact/$N/$B"
|
||||||
cp -ai ../build/$C/$B/upx/upx*.exe "tmp/artifact/$N/$B"
|
cp -ai build/$C/$B/upx/upx*.exe "tmp/artifact/$N/$B"
|
||||||
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
||||||
echo "artifact_name=$N" >> $GITHUB_ENV
|
echo "artifact_name=$N" >> $GITHUB_ENV
|
||||||
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.artifact_name }}
|
name: ${{ env.artifact_name }}
|
||||||
path: tmp/artifact
|
path: tmp/artifact
|
||||||
- name: 'Run basic tests'
|
- name: 'Run basic tests'
|
||||||
|
if: ${{ matrix.arch != 'amd64_arm64' }}
|
||||||
run: |
|
run: |
|
||||||
$ErrorActionPreference = 'stop'
|
$ErrorActionPreference = 'stop'
|
||||||
$ErrorView = 'NormalView'
|
$ErrorView = 'NormalView'
|
||||||
cd $Env:H\build\$Env:C\$Env:B\upx
|
cd $Env:H\build\$Env:C\$Env:B\upx
|
||||||
$Env:UPX = "--no-color --no-progress"
|
$Env:UPX = "--no-color --no-progress"
|
||||||
.\upx.exe --version
|
.\upx.exe --version
|
||||||
|
.\upx.exe --sysinfo -v
|
||||||
.\upx.exe upx.exe -o upx_packed.exe
|
.\upx.exe upx.exe -o upx_packed.exe
|
||||||
dir *.exe
|
dir *.exe
|
||||||
.\upx.exe -l upx_packed.exe
|
.\upx.exe -l upx_packed.exe
|
||||||
.\upx.exe -t upx_packed.exe
|
.\upx.exe -t upx_packed.exe
|
||||||
.\upx_packed.exe --version
|
.\upx_packed.exe --version
|
||||||
- name: 'Run test suite'
|
- name: 'Run test suite'
|
||||||
|
if: ${{ matrix.arch != 'amd64_arm64' }}
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
bash ./.github/travis_testsuite_1.sh
|
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
|
||||||
|
env -C build/$C/$B/upx upx_exe=./upx.exe bash "$PWD"/misc/testsuite/upx_testsuite_1.sh
|
||||||
|
|
||||||
# vim:set ts=2 sw=2 et:
|
job-linux-zigcc: # uses cmake + make
|
||||||
|
if: github.repository_owner == 'upx'
|
||||||
|
needs: [ job-rebuild-and-verify-stubs ]
|
||||||
|
name: ${{ format('zigcc {0} {1}', matrix.zig_target, matrix.zig_pic) }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: 'alpine:3.19' # older versions such as alpine:3.12 also work; no-container also works
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
# only build a few targets => more targets are tested in the Weekly CI
|
||||||
|
- { zig_target: aarch64-linux-musl }
|
||||||
|
# { zig_target: aarch64-linux-musl, zig_pic: -fPIE }
|
||||||
|
# { zig_target: aarch64-macos-none }
|
||||||
|
- { zig_target: aarch64-macos.11.0-none }
|
||||||
|
# { zig_target: aarch64-macos.12.0-none }
|
||||||
|
# { zig_target: aarch64-macos.13.0-none }
|
||||||
|
- { zig_target: aarch64-windows-gnu }
|
||||||
|
- { zig_target: arm-linux-musleabihf }
|
||||||
|
# { zig_target: arm-linux-musleabihf, zig_pic: -fPIE }
|
||||||
|
- { zig_target: i386-linux-musl }
|
||||||
|
# { zig_target: i386-linux-musl, zig_pic: -fPIE }
|
||||||
|
- { zig_target: i386-windows-gnu }
|
||||||
|
# { zig_target: mips-linux-musl }
|
||||||
|
# { zig_target: mipsel-linux-musl }
|
||||||
|
# { zig_target: powerpc-linux-musl }
|
||||||
|
# { zig_target: powerpc64-linux-musl }
|
||||||
|
# { zig_target: powerpc64le-linux-musl }
|
||||||
|
- { zig_target: x86_64-linux-musl }
|
||||||
|
# { zig_target: x86_64-linux-musl, zig_pic: -fPIE }
|
||||||
|
# { zig_target: x86_64-macos-none }
|
||||||
|
- { zig_target: x86_64-macos.11.0-none }
|
||||||
|
# { zig_target: x86_64-macos.12.0-none }
|
||||||
|
# { zig_target: x86_64-macos.13.0-none }
|
||||||
|
- { zig_target: x86_64-windows-gnu }
|
||||||
|
env:
|
||||||
|
UPX_CONFIG_EXPECT_THREADS: 'ON'
|
||||||
|
# for zig-cc wrapper scripts (see below):
|
||||||
|
ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING
|
||||||
|
ZIG_FLAGS: ${{ matrix.zig_flags }}
|
||||||
|
ZIG_PIC: ${{ matrix.zig_pic }}
|
||||||
|
ZIG_TARGET: ${{ matrix.zig_target }}
|
||||||
|
steps:
|
||||||
|
- name: 'Install Alpine Linux container packages'
|
||||||
|
if: ${{ job.container }}
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
apk update && apk upgrade && apk add bash cmake file git make tar xz
|
||||||
|
# set PATH like in Ubuntu
|
||||||
|
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
|
||||||
|
# this seems to be needed when running in a container (beause of UID mismatch??)
|
||||||
|
git config --global --add safe.directory '*'
|
||||||
|
- name: 'Check out code'
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with: { submodules: true }
|
||||||
|
- name: ${{ format('Install Zig {0}', env.ZIG_DIST_VERSION) }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# GitHub Actions magic: set "UPX_GITREV_SHORT" environment value for use in steps below
|
||||||
|
rev=$(git rev-parse --short=7 HEAD)
|
||||||
|
echo "UPX_GITREV_SHORT=$rev" >> $GITHUB_ENV
|
||||||
|
# update ZIG_TARGET (i386 => x86)
|
||||||
|
ZIG_TARGET=${ZIG_TARGET/i386-/x86-}
|
||||||
|
echo "ZIG_TARGET=$ZIG_TARGET" >> $GITHUB_ENV
|
||||||
|
# install zig; note that ~/.local/bin is included in the default $PATH on Ubuntu
|
||||||
|
mkdir -p -v ~/.local/bin
|
||||||
|
cd ~/.local/bin
|
||||||
|
ZIG_DIST_NAME=zig-linux-x86_64-${ZIG_DIST_VERSION}
|
||||||
|
wget -q https://ziglang.org/builds/${ZIG_DIST_NAME}.tar.xz
|
||||||
|
ls -l ${ZIG_DIST_NAME}.tar.xz
|
||||||
|
tar -xoJf ${ZIG_DIST_NAME}.tar.xz
|
||||||
|
rm ${ZIG_DIST_NAME}.tar.xz
|
||||||
|
ln -s -v ${ZIG_DIST_NAME}/zig zig
|
||||||
|
#echo "PATH=$PATH" && which zig
|
||||||
|
echo -n 'zig version: '; zig version
|
||||||
|
# create wrapper scripts (needed for CMake)
|
||||||
|
echo -e '#!/bin/sh\nexec zig ar "$@"' > zig-ar
|
||||||
|
echo -e '#!/bin/sh\nexec zig cc -target $ZIG_TARGET $ZIG_PIC $ZIG_FLAGS $ZIG_CPPFLAGS $ZIG_CFLAGS "$@"' > zig-cc
|
||||||
|
echo -e '#!/bin/sh\nexec zig c++ -target $ZIG_TARGET $ZIG_PIC $ZIG_FLAGS $ZIG_CPPFLAGS $ZIG_CXXFLAGS "$@"' > zig-cxx
|
||||||
|
echo -e '#!/bin/sh\nexec zig ranlib "$@"' > zig-ranlib
|
||||||
|
chmod +x zig-ar zig-cc zig-cxx zig-ranlib
|
||||||
|
ls -la; head zig-ar zig-cc zig-cxx zig-ranlib
|
||||||
|
- name: ${{ format('Build Release with zig-cc -target {0} {1}', env.ZIG_TARGET, env.ZIG_PIC) }}
|
||||||
|
run: |
|
||||||
|
mkdir -p build/zig/${ZIG_TARGET}${ZIG_PIC}/release
|
||||||
|
cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release
|
||||||
|
cmake ../../../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_AR=$HOME/.local/bin/zig-ar -DCMAKE_C_COMPILER=zig-cc -DCMAKE_CXX_COMPILER=zig-cxx -DCMAKE_RANLIB=$HOME/.local/bin/zig-ranlib $EXTRA_CMAKE_CONFIG_FLAGS_RELEASE
|
||||||
|
cmake --build . --config Release --parallel --verbose
|
||||||
|
file ./upx*
|
||||||
|
- name: ${{ format('Build Debug with zig-cc -target {0} {1}', env.ZIG_TARGET, env.ZIG_PIC) }}
|
||||||
|
run: |
|
||||||
|
mkdir -p build/zig/${ZIG_TARGET}${ZIG_PIC}/debug
|
||||||
|
cd build/zig/${ZIG_TARGET}${ZIG_PIC}/debug
|
||||||
|
cmake ../../../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_AR=$HOME/.local/bin/zig-ar -DCMAKE_C_COMPILER=zig-cc -DCMAKE_CXX_COMPILER=zig-cxx -DCMAKE_RANLIB=$HOME/.local/bin/zig-ranlib $EXTRA_CMAKE_CONFIG_FLAGS_DEBUG
|
||||||
|
cmake --build . --config Debug --parallel --verbose
|
||||||
|
file ./upx*
|
||||||
|
- name: ${{ format('Make artifact from upx-{0}-{1}', github.ref_name, env.UPX_GITREV_SHORT) }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-zigcc-${{ matrix.zig_target }}${ZIG_PIC}" | sed 's/[^0-9a-zA-Z_.-]/-/g')
|
||||||
|
mkdir -p "tmp/artifact/$N"
|
||||||
|
(cd build && shopt -s nullglob && cp -ai --parents */upx{,.exe} */*/*/upx{,.exe} "../tmp/artifact/$N")
|
||||||
|
(cd tmp/artifact && tar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N")
|
||||||
|
# GitHub Actions magic: set "artifact_name" environment value for use in next step
|
||||||
|
echo "artifact_name=$N" >> $GITHUB_ENV
|
||||||
|
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.artifact_name }}
|
||||||
|
path: tmp/artifact
|
||||||
|
- name: 'Run install tests'
|
||||||
|
if: ${{ contains(matrix.zig_target, '-linux') }}
|
||||||
|
run: |
|
||||||
|
(cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release && DESTDIR=$PWD/Install-with-cmake cmake --install .)
|
||||||
|
(cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release && DESTDIR=$PWD/Install-with-make make install)
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
# see https://docs.github.com/en/actions/managing-issues-and-pull-requests/closing-inactive-issues
|
|
||||||
# see https://github.com/actions/stale
|
|
||||||
|
|
||||||
# Automatically closing issues is far from perfect, but then we only have
|
|
||||||
# limited resources and this approach favors issues that people
|
|
||||||
# actually care about.
|
|
||||||
#
|
|
||||||
# also see:
|
|
||||||
# "Should I Stale or Should I Close? An Analysis of a Bot that Closes
|
|
||||||
# Abandoned Issues and Pull Request".
|
|
||||||
# https://igorwiese.com/images/papers/Paper_BotSE_19.pdf
|
|
||||||
|
|
||||||
name: 'Close inactive issues'
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: "30 6 * * 4"
|
|
||||||
workflow_dispatch:
|
|
||||||
jobs:
|
|
||||||
close-issues:
|
|
||||||
name: 'Close inactive issues'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
issues: write
|
|
||||||
pull-requests: write
|
|
||||||
steps:
|
|
||||||
- uses: actions/stale@v6
|
|
||||||
with:
|
|
||||||
# operations-per-run: 300
|
|
||||||
days-before-stale: 60
|
|
||||||
days-before-close: 30
|
|
||||||
stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Please remove the stale label or add a comment or this issue will be closed in 30 days.'
|
|
||||||
stale-pr-message: 'This PR is stale because it has been open 60 days with no activity. Please remove the stale label or add a comment or this PR will be closed in 30 days.'
|
|
||||||
close-issue-message: 'This issue was closed because it has been stalled for 30 days with no activity. Please feel free to reopen.'
|
|
||||||
close-pr-message: 'This PR was closed because it has been stalled for 30 days with no activity. Please feel free to reopen.'
|
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
name: "CodeQL"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "devel", "devel4", "devel5", "master" ]
|
|
||||||
pull_request:
|
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
branches: [ "devel", "devel4", "devel5" ]
|
|
||||||
schedule:
|
|
||||||
- cron: '20 1 * * 3'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
analyze:
|
|
||||||
name: Analyze
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
language: [ 'cpp' ]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with: { submodules: true }
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v2
|
|
||||||
with:
|
|
||||||
languages: ${{ matrix.language }}
|
|
||||||
- name: Autobuild
|
|
||||||
uses: github/codeql-action/autobuild@v2
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v2
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
name: 'Close pull requests'
|
|
||||||
on:
|
|
||||||
#pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
jobs:
|
|
||||||
close-pull-requests:
|
|
||||||
name: 'Close pull requests'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
pull-requests: write
|
|
||||||
steps:
|
|
||||||
- name: 'Close pull requests'
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
gh pr list --repo='${{ github.repository }}' --state=open --json=number | jq '.[].number' | xargs -r -n1 -- gh pr close --repo='${{ github.repository }}'
|
|
||||||
+15
-10
@@ -1,49 +1,54 @@
|
|||||||
/.hg*
|
/.hg*
|
||||||
/.vscode*
|
/.vscode*
|
||||||
/Makevars.global*
|
/Makevars.global*
|
||||||
|
/Testing*
|
||||||
/build*
|
/build*
|
||||||
/maint*
|
/maint*
|
||||||
/vendor*
|
/vendor*
|
||||||
|
|
||||||
.depend
|
GNUmakefile*
|
||||||
GNUmakefile
|
MMakefile*
|
||||||
MMakefile
|
|
||||||
Makevars.local*
|
Makevars.local*
|
||||||
tmp-testsuite*
|
compile_flags*.txt
|
||||||
|
Tmp*
|
||||||
|
tmp*
|
||||||
|
|
||||||
*.a
|
*.a
|
||||||
|
*.bz2
|
||||||
*.d
|
*.d
|
||||||
*.dll
|
*.dll
|
||||||
|
*.dylib
|
||||||
*.exe
|
*.exe
|
||||||
|
*.gz
|
||||||
*.lib
|
*.lib
|
||||||
*.map
|
*.map
|
||||||
*.o
|
*.o
|
||||||
*.obj
|
*.obj
|
||||||
*.out
|
*.out
|
||||||
|
*.patch
|
||||||
*.py[cdo]
|
*.py[cdo]
|
||||||
|
*.rar
|
||||||
*.so
|
*.so
|
||||||
*.swp
|
*.swp
|
||||||
|
*.tmp
|
||||||
*.ttp
|
*.ttp
|
||||||
|
*.xz
|
||||||
|
*.zip
|
||||||
|
*.zst
|
||||||
|
|
||||||
doc/*.man
|
doc/*.man
|
||||||
doc/*.ps
|
doc/*.ps
|
||||||
doc/*.tex
|
doc/*.tex
|
||||||
|
|
||||||
src/stub/**/.*-stamp
|
src/stub/**/.*-stamp
|
||||||
src/stub/**/MMakefile
|
|
||||||
src/stub/tmp*/*.bin
|
src/stub/tmp*/*.bin
|
||||||
src/stub/tmp*/*.bin.bindump
|
src/stub/tmp*/*.bin.bindump
|
||||||
src/stub/tmp*/*.bin.disasm
|
src/stub/tmp*/*.bin.disasm
|
||||||
src/stub/tmp*/*.d
|
|
||||||
src/stub/tmp*/*.o
|
|
||||||
src/stub/tmp*/*.o.disasm
|
src/stub/tmp*/*.o.disasm
|
||||||
src/stub/tmp*/mips.r3000-*.[is]
|
src/stub/tmp*/mips.r3000-*.[is]
|
||||||
src/stub/tmp*/mipsel.r3000-*.[is]
|
src/stub/tmp*/mipsel.r3000-*.[is]
|
||||||
src/stub/src/**/tmp*/*
|
src/stub/src/**/tmp*/*
|
||||||
|
|
||||||
src/stub/tools/armpe/armpe_tester.exe
|
|
||||||
src/stub/tools/armpe/armpe_tester.out
|
|
||||||
|
|
||||||
src/stub/tools/sstrip/amd64-linux-sstrip
|
src/stub/tools/sstrip/amd64-linux-sstrip
|
||||||
src/stub/tools/sstrip/i386-linux-sstrip
|
src/stub/tools/sstrip/i386-linux-sstrip
|
||||||
src/stub/tools/sstrip/sstrip
|
src/stub/tools/sstrip/sstrip
|
||||||
|
|||||||
@@ -13,6 +13,11 @@
|
|||||||
url = https://github.com/upx/upx-vendor-ucl.git
|
url = https://github.com/upx/upx-vendor-ucl.git
|
||||||
branch = upx-vendor
|
branch = upx-vendor
|
||||||
shallow = true
|
shallow = true
|
||||||
|
[submodule "vendor/valgrind"]
|
||||||
|
path = vendor/valgrind
|
||||||
|
url = https://github.com/upx/upx-vendor-valgrind.git
|
||||||
|
branch = upx-vendor
|
||||||
|
shallow = true
|
||||||
[submodule "vendor/zlib"]
|
[submodule "vendor/zlib"]
|
||||||
path = vendor/zlib
|
path = vendor/zlib
|
||||||
url = https://github.com/upx/upx-vendor-zlib.git
|
url = https://github.com/upx/upx-vendor-zlib.git
|
||||||
|
|||||||
+409
-119
@@ -1,34 +1,102 @@
|
|||||||
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
#
|
||||||
|
# UPX "CMake" build file; see https://cmake.org/
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
#
|
||||||
|
|
||||||
# config options
|
# Build requirements:
|
||||||
option(UPX_CONFIG_DISABLE_GITREV "Do not compile with default Git version info.")
|
# A C++ compiler that fully implements C++17: clang-5, gcc-8 or msvc-2019-16.11
|
||||||
option(UPX_CONFIG_DISABLE_SANITIZE "Do not compile with default sanitize options.")
|
# (older or other compilers may work but are unsupported, use at your own risk)
|
||||||
option(UPX_CONFIG_DISABLE_WERROR "Do not compile with default -Werror option.")
|
|
||||||
|
# Sections of this CMakeLists.txt:
|
||||||
|
# - options
|
||||||
|
# - init
|
||||||
|
# - common compilation flags
|
||||||
|
# - targets
|
||||||
|
# - target compilation flags
|
||||||
|
# - test
|
||||||
|
# - install
|
||||||
|
# - print summary
|
||||||
|
|
||||||
|
# CMake version check; using a somewhat current CMake version is highly recommended
|
||||||
|
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/.upx_cmake_config_done.txt")
|
||||||
|
if(DEFINED UPX_CONFIG_CMAKE_MINIMUM_REQUIRED_VERSION)
|
||||||
|
cmake_minimum_required(VERSION "${UPX_CONFIG_CMAKE_MINIMUM_REQUIRED_VERSION}" FATAL_ERROR)
|
||||||
|
else()
|
||||||
|
cmake_minimum_required(VERSION "3.8" FATAL_ERROR) # CMake >= 3.8 is needed for CXX_STANDARD 17
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# support functions
|
||||||
|
include("${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/functions.cmake")
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# options
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
upx_cmake_include_hook(1_options)
|
||||||
|
|
||||||
|
# compilation config options
|
||||||
|
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git" OR NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/use_strict_defaults.cmake")
|
||||||
|
# permissive config defaults when building from source code tarball
|
||||||
|
option(UPX_CONFIG_DISABLE_GITREV "Do not compile with default Git version info." ON)
|
||||||
|
option(UPX_CONFIG_DISABLE_SANITIZE "Do not compile with default sanitize options." ON)
|
||||||
|
option(UPX_CONFIG_DISABLE_WSTRICT "Do not compile with strict compiler warnings." ON)
|
||||||
|
option(UPX_CONFIG_DISABLE_WERROR "Do not compile with default -Werror option." ON)
|
||||||
|
else()
|
||||||
|
# strict config defaults for Git developer builds
|
||||||
|
message(STATUS "===== UPX info: strict config defaults enabled")
|
||||||
|
option(UPX_CONFIG_DISABLE_GITREV "Do not compile with default Git version info." OFF)
|
||||||
|
option(UPX_CONFIG_DISABLE_SANITIZE "Do not compile with default sanitize options." OFF)
|
||||||
|
option(UPX_CONFIG_DISABLE_WSTRICT "Do not compile with strict compiler warnings." OFF)
|
||||||
|
option(UPX_CONFIG_DISABLE_WERROR "Do not compile with default -Werror option." OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# test config options (see below)
|
||||||
|
# IMPORTANT NOTE: self-pack test can only work if the host executable format is supported by UPX!
|
||||||
|
option(UPX_CONFIG_DISABLE_SELF_PACK_TEST "Do not test packing UPX with itself" OFF)
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# init
|
# init
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
# Disallow in-source builds. Note that you will still have to manually
|
set(UPX_VERSION_STRING "4.3.0")
|
||||||
|
|
||||||
|
upx_cmake_include_hook(2_init)
|
||||||
|
|
||||||
|
# Disallow in-source build. Note that you will still have to manually
|
||||||
# clean up a few files if you accidentally try an in-source build.
|
# clean up a few files if you accidentally try an in-source build.
|
||||||
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
|
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
|
upx_disallow_in_source_build()
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
if(",${CMAKE_SOURCE_DIR}," STREQUAL ",${CMAKE_BINARY_DIR},")
|
|
||||||
message(FATAL_ERROR "ERROR: In-source builds are not allowed, please use an extra build dir.")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# determine git revision
|
# global settings
|
||||||
|
if(${CMAKE_VERSION} VERSION_GREATER "3.14.99" AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
|
||||||
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
|
||||||
|
cmake_policy(SET CMP0091 NEW)
|
||||||
|
endif()
|
||||||
|
# global CMake settings that default to ON
|
||||||
|
upx_cache_bool_vars(ON
|
||||||
|
CMAKE_C_STANDARD_REQUIRED CMAKE_CXX_STANDARD_REQUIRED
|
||||||
|
CMAKE_EXPORT_COMPILE_COMMANDS CMAKE_REQUIRED_QUIET
|
||||||
|
)
|
||||||
|
# internal UPX settings that default to OFF
|
||||||
|
upx_cache_bool_vars(OFF
|
||||||
|
UPX_CONFIG_CMAKE_DISABLE_TEST UPX_CONFIG_CMAKE_DISABLE_INSTALL
|
||||||
|
UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK
|
||||||
|
UPX_CONFIG_DISABLE_C_STANDARD UPX_CONFIG_DISABLE_CXX_STANDARD
|
||||||
|
UPX_CONFIG_EXPECT_THREADS UPX_CONFIG_REQUIRE_THREADS
|
||||||
|
)
|
||||||
|
|
||||||
|
# determine Git revision
|
||||||
set(GITREV_SHORT "")
|
set(GITREV_SHORT "")
|
||||||
set(GITREV_PLUS "")
|
set(GITREV_PLUS "")
|
||||||
|
set(GIT_DESCRIBE "")
|
||||||
|
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git" AND NOT UPX_CONFIG_DISABLE_GITREV)
|
||||||
find_package(Git)
|
find_package(Git)
|
||||||
if(GIT_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV)
|
if(Git_FOUND)
|
||||||
execute_process(
|
execute_process(
|
||||||
RESULT_VARIABLE result
|
|
||||||
COMMAND "${GIT_EXECUTABLE}" rev-parse --short=12 HEAD
|
COMMAND "${GIT_EXECUTABLE}" rev-parse --short=12 HEAD
|
||||||
ERROR_QUIET
|
RESULT_VARIABLE result ERROR_QUIET
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_VARIABLE GITREV_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
OUTPUT_VARIABLE GITREV_SHORT
|
|
||||||
)
|
)
|
||||||
string(LENGTH "${GITREV_SHORT}" l)
|
string(LENGTH "${GITREV_SHORT}" l)
|
||||||
if(${result} EQUAL 0 AND ${l} EQUAL 12)
|
if(${result} EQUAL 0 AND ${l} EQUAL 12)
|
||||||
@@ -39,196 +107,418 @@ if(GIT_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV)
|
|||||||
else()
|
else()
|
||||||
set(GITREV_SHORT "")
|
set(GITREV_SHORT "")
|
||||||
endif()
|
endif()
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GIT_EXECUTABLE}" describe --match "v*.*.*" --tags --dirty
|
||||||
|
RESULT_VARIABLE result ERROR_QUIET
|
||||||
|
OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
if(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g(.+)$")
|
||||||
|
set(GIT_DESCRIBE "${CMAKE_MATCH_1}-devel.${CMAKE_MATCH_2}+git-${CMAKE_MATCH_3}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git") # extra check
|
|
||||||
set(GITREV_SHORT "")
|
|
||||||
endif()
|
endif()
|
||||||
if(GITREV_SHORT)
|
if(GITREV_SHORT)
|
||||||
message(STATUS "UPX_VERSION_GITREV = \"${GITREV_SHORT}${GITREV_PLUS}\"")
|
message(STATUS "UPX_VERSION_GITREV = \"${GITREV_SHORT}${GITREV_PLUS}\"")
|
||||||
|
if(GIT_DESCRIBE)
|
||||||
|
message(STATUS "UPX_VERSION_GIT_DESCRIBE = \"${GIT_DESCRIBE}\"")
|
||||||
|
endif()
|
||||||
|
elseif(UPX_CONFIG_DISABLE_GITREV)
|
||||||
|
message(STATUS "UPX_VERSION_GITREV: disabled")
|
||||||
else()
|
else()
|
||||||
message(STATUS "UPX_VERSION_GITREV: not set")
|
message(STATUS "UPX_VERSION_GITREV: not set")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(upx VERSION 4.0.0 LANGUAGES C CXX)
|
# CMake init
|
||||||
|
upx_default_build_type(Release)
|
||||||
|
project(upx VERSION "${UPX_VERSION_STRING}" LANGUAGES C CXX)
|
||||||
|
upx_apply_build_type()
|
||||||
|
|
||||||
# set default build type to "Release"
|
# set MSVC_FRONTEND and MINGW
|
||||||
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
if(NOT DEFINED MSVC_FRONTEND AND (MSVC OR CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC"))
|
||||||
if(is_multi_config)
|
set(MSVC_FRONTEND 1)
|
||||||
set(c "${CMAKE_CONFIGURATION_TYPES}")
|
|
||||||
list(INSERT c 0 "Release")
|
|
||||||
list(INSERT c 1 "Debug")
|
|
||||||
if (CMAKE_BUILD_TYPE)
|
|
||||||
list(INSERT c 0 "${CMAKE_BUILD_TYPE}")
|
|
||||||
endif()
|
endif()
|
||||||
list(REMOVE_DUPLICATES c)
|
if(NOT DEFINED MINGW AND CMAKE_C_PLATFORM_ID MATCHES "^MinGW")
|
||||||
set(CMAKE_CONFIGURATION_TYPES "${c}" CACHE STRING "List of supported configuration types." FORCE)
|
set(MINGW 1)
|
||||||
elseif(NOT CMAKE_BUILD_TYPE)
|
|
||||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# targets and compilation flags
|
# common compilation flags
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
file(GLOB ucl_SOURCES "vendor/ucl/src/*.c")
|
include(CheckCCompilerFlag)
|
||||||
list(SORT ucl_SOURCES)
|
include(CheckFunctionExists)
|
||||||
add_library(upx_vendor_ucl STATIC ${ucl_SOURCES})
|
include(CheckIncludeFile)
|
||||||
set_property(TARGET upx_vendor_ucl PROPERTY C_STANDARD 11)
|
include(CheckStructHasMember)
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
|
||||||
file(GLOB zlib_SOURCES "vendor/zlib/*.c")
|
upx_cmake_include_hook(3_common_compilation_flags)
|
||||||
list(SORT zlib_SOURCES)
|
|
||||||
add_library(upx_vendor_zlib STATIC ${zlib_SOURCES})
|
|
||||||
set_property(TARGET upx_vendor_zlib PROPERTY C_STANDARD 11)
|
|
||||||
|
|
||||||
file(GLOB upx_SOURCES "src/*.cpp" "src/util/*.cpp")
|
if(NOT DEFINED HAVE_UNISTD_H)
|
||||||
list(SORT upx_SOURCES)
|
check_include_file("unistd.h" HAVE_UNISTD_H)
|
||||||
add_executable(upx ${upx_SOURCES})
|
endif()
|
||||||
set_property(TARGET upx PROPERTY CXX_STANDARD 14)
|
if(NOT DEFINED HAVE_UTIMENSAT)
|
||||||
target_link_libraries(upx upx_vendor_ucl upx_vendor_zlib)
|
# proper checking for utimensat() is somewhat messy
|
||||||
|
check_function_exists(utimensat HAVE_UTIMENSAT_FUNCTION__)
|
||||||
|
if(HAVE_UTIMENSAT_FUNCTION__)
|
||||||
|
check_symbol_exists(utimensat "sys/types.h;fcntl.h;sys/stat.h" HAVE_UTIMENSAT_SYMBOL__)
|
||||||
|
if(HAVE_UTIMENSAT_SYMBOL__)
|
||||||
|
CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtim.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) # POSIX.1-2008
|
||||||
|
if(NOT HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
||||||
|
CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtimespec.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) # macOS
|
||||||
|
endif()
|
||||||
|
if(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC OR HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
|
||||||
|
set(HAVE_UTIMENSAT 1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(UPX_CONFIG_DISABLE_WSTRICT)
|
||||||
|
# enable all basic warnings
|
||||||
|
set(warn_Wall -Wall)
|
||||||
|
set(warn_WN -W3)
|
||||||
|
else()
|
||||||
|
# enable all basic warnings, and enable lots of strict warnings
|
||||||
|
set(warn_Wall -Wall -Wextra -Wcast-align -Wcast-qual -Wmissing-declarations -Wpointer-arith -Wshadow -Wvla -Wwrite-strings)
|
||||||
|
set(warn_WN -W4)
|
||||||
|
endif()
|
||||||
if(UPX_CONFIG_DISABLE_WERROR)
|
if(UPX_CONFIG_DISABLE_WERROR)
|
||||||
|
# warnings are just warnings
|
||||||
set(warn_Werror "")
|
set(warn_Werror "")
|
||||||
set(warn_WX "")
|
set(warn_WX "")
|
||||||
else()
|
else()
|
||||||
|
# warnings are fatal errors; annoy developers to keep the source code warning-free
|
||||||
set(warn_Werror -Werror)
|
set(warn_Werror -Werror)
|
||||||
set(warn_WX -WX)
|
set(warn_WX -WX)
|
||||||
endif()
|
endif()
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
# disable warning C5105 which may get triggered by some older versions of <windows.h>
|
||||||
|
set(warn_WX -wd5105 ${warn_WX})
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT CMAKE_C_COMPILER_ID MATCHES "^MSVC")
|
||||||
# use -O2 instead of -O3 to reduce code size
|
# use -O2 instead of -O3 to reduce code size
|
||||||
string(REGEX REPLACE "(^| )-O3( |$$)" "\\1-O2\\2" a "${CMAKE_C_FLAGS_RELEASE}")
|
string(REGEX REPLACE "(^| )-O3( |$$)" "\\1-O2\\2" a "${CMAKE_C_FLAGS_RELEASE}")
|
||||||
string(REGEX REPLACE "(^| )-O3( |$$)" "\\1-O2\\2" b "${CMAKE_CXX_FLAGS_RELEASE}")
|
string(REGEX REPLACE "(^| )-O3( |$$)" "\\1-O2\\2" b "${CMAKE_CXX_FLAGS_RELEASE}")
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${a}" CACHE STRING "Flags used by the C compiler during RELEASE builds." FORCE)
|
set(CMAKE_C_FLAGS_RELEASE "${a}" CACHE STRING "Flags used by the C compiler during RELEASE builds." FORCE)
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${b}" CACHE STRING "Flags used by the CXX compiler during RELEASE builds." FORCE)
|
set(CMAKE_CXX_FLAGS_RELEASE "${b}" CACHE STRING "Flags used by the CXX compiler during RELEASE builds." FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
if(MSVC_FRONTEND OR WIN32 OR MINGW OR CYGWIN)
|
||||||
if(MSVC)
|
|
||||||
# disable silly warnings about using "deprecated" POSIX functions like fopen()
|
# disable silly warnings about using "deprecated" POSIX functions like fopen()
|
||||||
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
|
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
|
||||||
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
|
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
|
||||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
else()
|
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||||
|
add_definitions(-D__USE_MINGW_ANSI_STDIO)
|
||||||
|
endif()
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
# use -funsigned-char; set __cplusplus according to selected C++ standard
|
||||||
|
add_definitions(-J -Zc:__cplusplus)
|
||||||
|
if(CMAKE_C_COMPILER_ID MATCHES "^MSVC")
|
||||||
|
upx_add_definitions(-Zc:preprocessor) # use new preprocessor
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(NOT CMAKE_C_COMPILER_ID MATCHES "^MSVC")
|
||||||
# protect against security threats caused by misguided compiler "optimizations"
|
# protect against security threats caused by misguided compiler "optimizations"
|
||||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
upx_add_definitions(-fno-delete-null-pointer-checks -fno-lifetime-dse)
|
||||||
add_definitions(-fno-delete-null-pointer-checks)
|
upx_add_definitions(-fno-strict-aliasing -fno-strict-overflow -funsigned-char)
|
||||||
endif()
|
|
||||||
add_definitions(-fno-strict-aliasing -fno-strict-overflow -funsigned-char)
|
|
||||||
# disable overambitious auto-vectorization until this actually gains something
|
# disable overambitious auto-vectorization until this actually gains something
|
||||||
add_definitions(-fno-tree-vectorize)
|
upx_add_definitions(-fno-tree-vectorize)
|
||||||
|
# disable annoying clang warnings which get added by the macOS Xcode cmake generator
|
||||||
|
if(CMAKE_GENERATOR MATCHES "Xcode")
|
||||||
|
upx_add_definitions(-Wno-shorten-64-to-32)
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# examine MinGW/Cygwin compiler configuration
|
||||||
|
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
|
upx_print_mingw_symbols()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# targets
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# internal settings; these may change in a future versions
|
||||||
|
set(UPX_CONFIG_DISABLE_THREADS ON) # multithreading is currently not used; maybe in UPX version 5
|
||||||
|
set(UPX_CONFIG_DISABLE_BZIP2 ON) # bzip2 is currently not used; we might need it to decompress linux kernels
|
||||||
|
set(UPX_CONFIG_DISABLE_ZSTD ON) # zstd is currently not used; maybe in UPX version 5
|
||||||
|
|
||||||
|
upx_cmake_include_hook(4_targets)
|
||||||
|
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_THREADS)
|
||||||
|
find_package(Threads)
|
||||||
|
endif()
|
||||||
|
# make sure that threads are indeed fully supported in C++
|
||||||
|
if(Threads_FOUND)
|
||||||
|
foreach(f std_lock_guard.cpp)
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE")
|
||||||
|
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/try_compile/${f}"
|
||||||
|
OUTPUT_VARIABLE output)
|
||||||
|
if(NOT result)
|
||||||
|
# failed; under MinGW be sure to use the posix-threads and NOT the win32-threads version
|
||||||
|
#message(STATUS "Threads FAILED: ${output}") # debug output from try_compile
|
||||||
|
set(Threads_FOUND OFF)
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
||||||
|
upx_add_glob_files(bzip2_SOURCES "vendor/bzip2/*.c")
|
||||||
|
add_library(upx_vendor_bzip2 STATIC ${bzip2_SOURCES})
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
||||||
|
set_property(TARGET upx_vendor_bzip2 PROPERTY C_STANDARD 11)
|
||||||
|
endif()
|
||||||
|
endif() # UPX_CONFIG_DISABLE_BZIP2
|
||||||
|
|
||||||
|
upx_add_glob_files(ucl_SOURCES "vendor/ucl/src/*.c")
|
||||||
|
add_library(upx_vendor_ucl STATIC ${ucl_SOURCES})
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
||||||
|
set_property(TARGET upx_vendor_ucl PROPERTY C_STANDARD 11)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
upx_add_glob_files(zlib_SOURCES "vendor/zlib/*.c")
|
||||||
|
add_library(upx_vendor_zlib STATIC ${zlib_SOURCES})
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
||||||
|
set_property(TARGET upx_vendor_zlib PROPERTY C_STANDARD 11)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
||||||
|
upx_add_glob_files(zstd_SOURCES "vendor/zstd/lib/*/*.c")
|
||||||
|
add_library(upx_vendor_zstd STATIC ${zstd_SOURCES})
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
||||||
|
set_property(TARGET upx_vendor_zstd PROPERTY C_STANDARD 11)
|
||||||
|
endif()
|
||||||
|
endif() # UPX_CONFIG_DISABLE_ZSTD
|
||||||
|
|
||||||
|
upx_add_glob_files(upx_SOURCES "src/*.cpp" "src/[cfu]*/*.cpp")
|
||||||
|
add_executable(upx ${upx_SOURCES})
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_CXX_STANDARD)
|
||||||
|
set_property(TARGET upx PROPERTY CXX_STANDARD 17)
|
||||||
|
endif()
|
||||||
|
target_link_libraries(upx upx_vendor_ucl upx_vendor_zlib)
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
||||||
|
target_link_libraries(upx upx_vendor_bzip2)
|
||||||
|
endif()
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
||||||
|
target_link_libraries(upx upx_vendor_zstd)
|
||||||
|
endif()
|
||||||
|
if(Threads_FOUND)
|
||||||
|
target_link_libraries(upx Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# target compilation flags
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
upx_cmake_include_hook(5_target_compilation_flags)
|
||||||
|
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
||||||
|
set(t upx_vendor_bzip2)
|
||||||
|
upx_compile_target_debug_with_O2(${t})
|
||||||
|
upx_sanitize_target(${t})
|
||||||
|
target_compile_definitions(${t} PRIVATE BZ_NO_STDIO=1)
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
target_compile_options(${t} PRIVATE ${warn_WN} -wd4127 -wd4244 -wd4267 ${warn_WX})
|
||||||
|
else()
|
||||||
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
||||||
|
endif()
|
||||||
|
endif() # UPX_CONFIG_DISABLE_BZIP2
|
||||||
|
|
||||||
set(t upx_vendor_ucl)
|
set(t upx_vendor_ucl)
|
||||||
target_include_directories(${t} PRIVATE vendor/ucl/include vendor/ucl)
|
target_include_directories(${t} PRIVATE vendor/ucl/include vendor/ucl)
|
||||||
if(MSVC)
|
upx_compile_target_debug_with_O2(${t})
|
||||||
target_compile_options(${t} PRIVATE -J -W4 ${warn_WX})
|
upx_sanitize_target(${t})
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
target_compile_options(${t} PRIVATE ${warn_WN} ${warn_WX})
|
||||||
else()
|
else()
|
||||||
target_compile_options(${t} PRIVATE -Wall -Wextra -Wvla ${warn_Werror})
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(t upx_vendor_zlib)
|
set(t upx_vendor_zlib)
|
||||||
if(MSVC)
|
upx_compile_target_debug_with_O2(${t})
|
||||||
target_compile_options(${t} PRIVATE -DHAVE_STDARG_H -DHAVE_VSNPRINTF -J -W3 ${warn_WX})
|
upx_sanitize_target(${t})
|
||||||
else()
|
target_compile_definitions(${t} PRIVATE HAVE_VSNPRINTF=1)
|
||||||
target_compile_options(${t} PRIVATE -DHAVE_STDARG_H -DHAVE_UNISTD_H -DHAVE_VSNPRINTF)
|
if(HAVE_UNISTD_H)
|
||||||
# clang-15: -Wno-strict-prototypes is needed to silence the new -Wdeprecated-non-prototype warning
|
target_compile_definitions(${t} PRIVATE HAVE_UNISTD_H=1)
|
||||||
target_compile_options(${t} PRIVATE -Wall -Wextra -Wvla -Wno-strict-prototypes ${warn_Werror})
|
|
||||||
endif()
|
endif()
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
target_compile_options(${t} PRIVATE -W3 ${warn_WX})
|
||||||
|
else()
|
||||||
|
##target_compile_options(${t} PRIVATE -Wall ${warn_Werror})
|
||||||
|
target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-cast-align -Wno-cast-qual ${warn_Werror})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
||||||
|
set(t upx_vendor_zstd)
|
||||||
|
upx_compile_target_debug_with_O2(${t})
|
||||||
|
upx_sanitize_target(${t})
|
||||||
|
target_compile_definitions(${t} PRIVATE DYNAMIC_BMI2=0 ZSTD_DISABLE_ASM=1)
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
target_compile_options(${t} PRIVATE ${warn_WN} ${warn_WX})
|
||||||
|
else()
|
||||||
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
||||||
|
endif()
|
||||||
|
endif() # UPX_CONFIG_DISABLE_ZSTD
|
||||||
|
|
||||||
set(t upx)
|
set(t upx)
|
||||||
target_include_directories(${t} PRIVATE vendor)
|
target_include_directories(${t} PRIVATE vendor)
|
||||||
target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
|
target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
|
||||||
if(GITREV_SHORT)
|
if(GITREV_SHORT)
|
||||||
target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}")
|
target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}")
|
||||||
|
if(GIT_DESCRIBE)
|
||||||
|
target_compile_definitions(${t} PRIVATE UPX_VERSION_GIT_DESCRIBE="${GIT_DESCRIBE}")
|
||||||
endif()
|
endif()
|
||||||
if(NOT UPX_CONFIG_DISABLE_SANITIZE AND NOT MSVC)
|
|
||||||
# default sanitizer for Debug builds
|
|
||||||
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-fsanitize=undefined -fsanitize-undefined-trap-on-error -fstack-protector-all>)
|
|
||||||
# default sanitizer for Release builds
|
|
||||||
target_compile_options(${t} PRIVATE $<$<CONFIG:Release>:-fstack-protector>)
|
|
||||||
endif()
|
endif()
|
||||||
if(MSVC)
|
if(Threads_FOUND)
|
||||||
target_compile_options(${t} PRIVATE -EHsc -J -W4 ${warn_WX})
|
target_compile_definitions(${t} PRIVATE WITH_THREADS=1)
|
||||||
|
endif()
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_WSTRICT)
|
||||||
|
target_compile_definitions(${t} PRIVATE UPX_CONFIG_DISABLE_WSTRICT=0)
|
||||||
|
endif()
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_WERROR)
|
||||||
|
target_compile_definitions(${t} PRIVATE UPX_CONFIG_DISABLE_WERROR=0)
|
||||||
|
endif()
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
||||||
|
target_compile_definitions(${t} PRIVATE WITH_BZIP2=1)
|
||||||
|
endif()
|
||||||
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
||||||
|
target_compile_definitions(${t} PRIVATE WITH_ZSTD=1)
|
||||||
|
endif()
|
||||||
|
if(HAVE_UTIMENSAT)
|
||||||
|
target_compile_definitions(${t} PRIVATE USE_UTIMENSAT=1)
|
||||||
|
if(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
|
||||||
|
target_compile_definitions(${t} PRIVATE HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC=1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
# improve speed of the Debug versions
|
||||||
|
upx_compile_source_debug_with_O2(src/compress/compress_lzma.cpp)
|
||||||
|
upx_compile_source_debug_with_O2(src/filter/filter_impl.cpp)
|
||||||
|
#upx_compile_target_debug_with_O2(${t})
|
||||||
|
upx_sanitize_target(${t})
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
target_compile_options(${t} PRIVATE -EHsc ${warn_WN} ${warn_WX})
|
||||||
else()
|
else()
|
||||||
target_compile_options(${t} PRIVATE
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
||||||
-Wall -Wextra -Wcast-align -Wcast-qual -Wmissing-declarations -Wpointer-arith
|
|
||||||
-Wshadow -Wvla -Wwrite-strings ${warn_Werror}
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# "make test"
|
# test
|
||||||
|
# ctest
|
||||||
|
# make test
|
||||||
|
# ninja test
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
if(NOT CMAKE_CROSSCOMPILING)
|
upx_cmake_include_hook(6_test)
|
||||||
|
|
||||||
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_TEST)
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
set(exe ${CMAKE_EXECUTABLE_SUFFIX})
|
if(NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
|
||||||
set(upx_self_exe "$<TARGET_FILE:upx>")
|
|
||||||
add_test(NAME upx-test-cleanup COMMAND rm -f ./upx.packed${exe} ./upx.unpacked${exe})
|
|
||||||
add_test(NAME upx-version COMMAND upx --version)
|
add_test(NAME upx-version COMMAND upx --version)
|
||||||
add_test(NAME upx-help COMMAND upx --help)
|
add_test(NAME upx-help COMMAND upx --help)
|
||||||
add_test(NAME upx-self-pack COMMAND upx -3 ${upx_self_exe} -o upx.packed${exe})
|
add_test(NAME upx-sysinfo COMMAND upx --sysinfo -v)
|
||||||
add_test(NAME upx-list COMMAND upx -l upx.packed${exe})
|
if(NOT UPX_CONFIG_DISABLE_SELF_PACK_TEST)
|
||||||
add_test(NAME upx-fileinfo COMMAND upx --fileinfo upx.packed${exe})
|
# IMPORTANT NOTE: these tests can only work if the host executable format is supported by UPX!
|
||||||
add_test(NAME upx-test COMMAND upx -t upx.packed${exe})
|
set(emu "")
|
||||||
add_test(NAME upx-unpack COMMAND upx -d upx.packed${exe} -o upx.unpacked${exe})
|
if(DEFINED CMAKE_CROSSCOMPILING_EMULATOR)
|
||||||
add_test(NAME upx-run-unpacked COMMAND ./upx.unpacked${exe} --version)
|
set(emu "${CMAKE_CROSSCOMPILING_EMULATOR}")
|
||||||
add_test(NAME upx-run-packed COMMAND ./upx.packed${exe} --version)
|
endif()
|
||||||
|
set(exe "${CMAKE_EXECUTABLE_SUFFIX}")
|
||||||
|
set(upx_self_exe "$<TARGET_FILE:upx>")
|
||||||
|
set(fo "--force-overwrite")
|
||||||
|
upx_add_serial_test(upx-self-pack upx -3 "${upx_self_exe}" ${fo} -o upx-packed${exe})
|
||||||
|
upx_add_serial_test(upx-self-pack-n2b upx -3 --nrv2b "${upx_self_exe}" ${fo} -o upx-packed-n2b${exe})
|
||||||
|
upx_add_serial_test(upx-self-pack-n2d upx -3 --nrv2d "${upx_self_exe}" ${fo} -o upx-packed-n2d${exe})
|
||||||
|
upx_add_serial_test(upx-self-pack-n2e upx -3 --nrv2e "${upx_self_exe}" ${fo} -o upx-packed-n2e${exe})
|
||||||
|
upx_add_serial_test(upx-self-pack-lzma upx -1 --lzma "${upx_self_exe}" ${fo} -o upx-packed-lzma${exe})
|
||||||
|
upx_add_serial_test(upx-list upx -l upx-packed${exe} upx-packed-n2b${exe} upx-packed-n2d${exe} upx-packed-n2e${exe} upx-packed-lzma${exe})
|
||||||
|
upx_add_serial_test(upx-fileinfo upx --fileinfo upx-packed${exe} upx-packed-n2b${exe} upx-packed-n2d${exe} upx-packed-n2e${exe} upx-packed-lzma${exe})
|
||||||
|
upx_add_serial_test(upx-test upx -t upx-packed${exe} upx-packed-n2b${exe} upx-packed-n2d${exe} upx-packed-n2e${exe} upx-packed-lzma${exe})
|
||||||
|
upx_add_serial_test(upx-unpack upx -d upx-packed${exe} ${fo} -o upx-unpacked${exe})
|
||||||
|
upx_add_serial_test(upx-run-unpacked ${emu} ./upx-unpacked${exe} --version-short)
|
||||||
|
upx_add_serial_test(upx-run-packed ${emu} ./upx-packed${exe} --version-short)
|
||||||
|
endif() # UPX_CONFIG_DISABLE_SELF_PACK_TEST
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# TODO: could add some more explicit test programs; but then, the integrated
|
endif() # UPX_CONFIG_CMAKE_DISABLE_TEST
|
||||||
# "doctest" is quite convenient and already covers a number of basic
|
|
||||||
# checks - and more complex cases better should be handled by an
|
|
||||||
# external test suite.
|
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# "make install"
|
# install
|
||||||
|
# cmake --install .
|
||||||
|
# make install
|
||||||
|
# ninja install
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
|
upx_cmake_include_hook(7_install)
|
||||||
|
|
||||||
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_INSTALL)
|
||||||
|
|
||||||
# installation prefix and directories
|
# installation prefix and directories
|
||||||
if(NOT CMAKE_INSTALL_PREFIX)
|
if(NOT CMAKE_INSTALL_PREFIX)
|
||||||
message(FATAL_ERROR "ERROR: CMAKE_INSTALL_PREFIX is not defined.")
|
#message(FATAL_ERROR "ERROR: CMAKE_INSTALL_PREFIX is not defined")
|
||||||
|
message(WARNING "WARNING: CMAKE_INSTALL_PREFIX is not defined")
|
||||||
endif()
|
endif()
|
||||||
|
if(CMAKE_INSTALL_PREFIX)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
endif()
|
||||||
if(DEFINED CMAKE_INSTALL_FULL_BINDIR)
|
# install files
|
||||||
|
if(CMAKE_INSTALL_PREFIX AND DEFINED CMAKE_INSTALL_FULL_BINDIR)
|
||||||
install(TARGETS upx DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
|
install(TARGETS upx DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
|
||||||
install(FILES
|
install(FILES
|
||||||
COPYING LICENSE NEWS README doc/upx-doc.html doc/upx-doc.txt
|
COPYING LICENSE NEWS README doc/THANKS.txt doc/upx-doc.html doc/upx-doc.txt
|
||||||
DESTINATION "${CMAKE_INSTALL_FULL_DOCDIR}"
|
DESTINATION "${CMAKE_INSTALL_FULL_DOCDIR}"
|
||||||
)
|
)
|
||||||
install(FILES doc/upx.1 DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man1")
|
install(FILES doc/upx.1 DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man1")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
endif() # UPX_CONFIG_CMAKE_DISABLE_INSTALL
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# finally print some info about the build configuration
|
# summary
|
||||||
|
# print some info about the build configuration
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/maint/src/CMakeLists.extra.txt")
|
upx_cmake_include_hook(8_summary)
|
||||||
include("${CMAKE_CURRENT_SOURCE_DIR}/maint/src/CMakeLists.extra.txt")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
function(print_var v)
|
upx_print_var(CMAKE_VERSION UPX_CONFIG_CMAKE_MINIMUM_REQUIRED_VERSION CMAKE_GENERATOR)
|
||||||
if(${v})
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO)
|
||||||
message(STATUS "${v} = ${${v}}")
|
upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION)
|
||||||
|
upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR)
|
||||||
|
upx_print_var(CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_C_COMPILER_ARCHITECTURE_ID CMAKE_C_PLATFORM_ID CMAKE_C_COMPILER_ABI)
|
||||||
|
upx_print_var(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_CXX_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_ARCHITECTURE_ID CMAKE_CXX_PLATFORM_ID CMAKE_CXX_COMPILER_ABI)
|
||||||
|
upx_print_var(CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_POSITION_INDEPENDENT_CODE CMAKE_TRY_COMPILE_CONFIGURATION)
|
||||||
|
upx_print_var(CYGWIN GNUC MINGW MSVC MSVC_FRONTEND MSVC_IDE WIN32 WIN64)
|
||||||
|
endif() # UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO
|
||||||
|
upx_print_var(CMAKE_INSTALL_PREFIX CMAKE_CONFIGURATION_TYPES CMAKE_BUILD_TYPE)
|
||||||
|
if(Threads_FOUND)
|
||||||
|
message(STATUS "WITH_THREADS = 1")
|
||||||
|
elseif(UPX_CONFIG_REQUIRE_THREADS)
|
||||||
|
message(FATAL_ERROR "ERROR: WITH_THREADS required")
|
||||||
|
elseif(UPX_CONFIG_EXPECT_THREADS AND NOT UPX_CONFIG_DISABLE_THREADS)
|
||||||
|
message(FATAL_ERROR "ERROR: WITH_THREADS expected")
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|None|Release)$")
|
||||||
print_var(CMAKE_BUILD_TYPE)
|
|
||||||
print_var(CMAKE_CONFIGURATION_TYPES)
|
|
||||||
print_var(CMAKE_INSTALL_PREFIX)
|
|
||||||
print_var(CMAKE_CROSSCOMPILING)
|
|
||||||
print_var(CMAKE_C_COMPILER_ID)
|
|
||||||
print_var(CMAKE_C_COMPILER_VERSION)
|
|
||||||
print_var(CMAKE_C_COMPILER_ARCHITECTURE_ID)
|
|
||||||
print_var(CMAKE_C_PLATFORM_ID)
|
|
||||||
print_var(CMAKE_C_COMPILER_ABI)
|
|
||||||
print_var(CMAKE_CXX_COMPILER_ID)
|
|
||||||
print_var(CMAKE_CXX_COMPILER_VERSION)
|
|
||||||
print_var(CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
|
|
||||||
print_var(CMAKE_CXX_PLATFORM_ID)
|
|
||||||
print_var(CMAKE_CXX_COMPILER_ABI)
|
|
||||||
if (CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$")
|
|
||||||
message(WARNING "WARNING: unsupported CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}; please use \"Debug\" or \"Release\"")
|
message(WARNING "WARNING: unsupported CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}; please use \"Debug\" or \"Release\"")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# extra sanity checks to detect incompatible C vs CXX settings
|
||||||
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK)
|
||||||
|
if(NOT ",${CMAKE_C_PLATFORM_ID}," STREQUAL ",${CMAKE_CXX_PLATFORM_ID},")
|
||||||
|
message(FATAL_ERROR "ERROR: CMAKE_C_PLATFORM_ID CMAKE_CXX_PLATFORM_ID mismatch")
|
||||||
|
endif()
|
||||||
|
if(NOT ",${CMAKE_C_COMPILER_ABI}," STREQUAL ",${CMAKE_CXX_COMPILER_ABI},")
|
||||||
|
message(FATAL_ERROR "ERROR: CMAKE_C_COMPILER_ABI CMAKE_CXX_COMPILER_ABI mismatch")
|
||||||
|
endif()
|
||||||
|
if(NOT ",${CMAKE_C_COMPILER_FRONTEND_VARIANT}," STREQUAL ",${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},")
|
||||||
|
message(FATAL_ERROR "ERROR: CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_FRONTEND_VARIANT mismatch")
|
||||||
|
endif()
|
||||||
|
endif() # UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK
|
||||||
|
|
||||||
|
upx_cmake_include_hook(9_finish)
|
||||||
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/.upx_cmake_config_done.txt" "")
|
||||||
|
|
||||||
# vim:set ft=cmake ts=4 sw=4 tw=0 et:
|
# vim:set ft=cmake ts=4 sw=4 tw=0 et:
|
||||||
|
|||||||
@@ -1,42 +1,36 @@
|
|||||||
#
|
#
|
||||||
# UPX top-level Makefile - needs GNU make and CMake >= 3.13
|
# UPX top-level Makefile - needs GNU make and CMake >= 3.13
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
#
|
#
|
||||||
|
|
||||||
# NOTE: if you only have CMake 3.10 then you can invoke cmake manually like this:
|
# INFO: this Makefile is just a convenience wrapper for calling CMake
|
||||||
|
|
||||||
|
# HINT: if you only have an older CMake 3.x then you can invoke cmake manually like this:
|
||||||
# mkdir -p build/release
|
# mkdir -p build/release
|
||||||
# cd build/release
|
# cd build/release
|
||||||
# cmake ../..
|
# cmake ../.. # run config
|
||||||
# cmake --build .
|
# make -j # and run build
|
||||||
|
|
||||||
CMAKE = cmake
|
CMAKE = cmake
|
||||||
UPX_CMAKE_BUILD_FLAGS += --parallel
|
UPX_CMAKE_BUILD_FLAGS += --parallel
|
||||||
ifneq ($(VERBOSE),)
|
ifneq ($(VERBOSE),)
|
||||||
UPX_CMAKE_BUILD_FLAGS += --verbose
|
#UPX_CMAKE_BUILD_FLAGS += --verbose # requires CMake >= 3.14
|
||||||
endif
|
UPX_CMAKE_CONFIG_FLAGS += -DCMAKE_VERBOSE_MAKEFILE=ON
|
||||||
|
|
||||||
# check git submodules
|
|
||||||
ifeq ($(wildcard ./vendor/doctest/doctest/.),)
|
|
||||||
$(error ERROR: missing git submodule; run 'git submodule update --init')
|
|
||||||
endif
|
|
||||||
ifeq ($(wildcard ./vendor/lzma-sdk/C/.),)
|
|
||||||
$(error ERROR: missing git submodule; run 'git submodule update --init')
|
|
||||||
endif
|
|
||||||
ifeq ($(wildcard ./vendor/ucl/include/.),)
|
|
||||||
$(error ERROR: missing git submodule; run 'git submodule update --init')
|
|
||||||
endif
|
|
||||||
ifeq ($(wildcard ./vendor/zlib/crc32.c),)
|
|
||||||
$(error ERROR: missing git submodule; run 'git submodule update --init')
|
|
||||||
endif
|
endif
|
||||||
|
# enable this if you prefer Ninja for the actual builds:
|
||||||
|
#UPX_CMAKE_CONFIG_FLAGS += -G Ninja
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# default
|
# default
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
|
|
||||||
__check_cache = $(if $(wildcard $1/CMakeCache.txt),@true,)
|
.DEFAULT_GOAL = build/release
|
||||||
run_config = $(call __check_cache,$1) $(CMAKE) -S . -B $1 $(UPX_CMAKE_CONFIG_FLAGS) -DCMAKE_BUILD_TYPE=$2
|
|
||||||
run_build = $(CMAKE) --build $1 $(UPX_CMAKE_BUILD_FLAGS) --config $2
|
|
||||||
|
|
||||||
default: build/release
|
run_cmake_config = $(CMAKE) -S . -B $1 $(UPX_CMAKE_CONFIG_FLAGS) -DCMAKE_BUILD_TYPE=$2
|
||||||
|
run_cmake_build = $(CMAKE) --build $1 $(UPX_CMAKE_BUILD_FLAGS) --config $2
|
||||||
|
# avoid re-running run_cmake_config if .upx_cmake_config_done.txt already exists
|
||||||
|
run_config = $(if $(wildcard $1/CMakeFiles/.upx_cmake_config_done.txt),,$(call run_cmake_config,$1,$2))
|
||||||
|
run_build = $(call run_cmake_build,$1,$2)
|
||||||
|
|
||||||
build/debug: PHONY
|
build/debug: PHONY
|
||||||
$(call run_config,$@,Debug)
|
$(call run_config,$@,Debug)
|
||||||
@@ -46,40 +40,35 @@ build/release: PHONY
|
|||||||
$(call run_config,$@,Release)
|
$(call run_config,$@,Release)
|
||||||
$(call run_build,$@,Release)
|
$(call run_build,$@,Release)
|
||||||
|
|
||||||
#***********************************************************************
|
.NOTPARALLEL: # because the actual builds use "cmake --parallel"
|
||||||
# some pre-defined build configurations
|
.PHONY: PHONY
|
||||||
#***********************************************************************
|
.SECONDEXPANSION:
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
# force building with gcc/g++
|
# shortcuts (all => debug + release)
|
||||||
build/%-gcc: export CC=gcc
|
debug: build/debug
|
||||||
build/%-gcc: export CXX=g++
|
release: build/release
|
||||||
build/debug-gcc: PHONY
|
all build/all: build/debug build/release
|
||||||
$(call run_config,$@,Debug)
|
build/%/all: $$(dir $$@)debug $$(dir $$@)release ;
|
||||||
$(call run_build,$@,Debug)
|
|
||||||
build/release-gcc: PHONY
|
|
||||||
$(call run_config,$@,Release)
|
|
||||||
$(call run_build,$@,Release)
|
|
||||||
|
|
||||||
# force building with clang/clang++
|
#
|
||||||
build/%-clang: export CC=clang
|
# END of Makefile
|
||||||
build/%-clang: export CXX=clang++
|
#
|
||||||
build/debug-clang: PHONY
|
|
||||||
$(call run_config,$@,Debug)
|
|
||||||
$(call run_build,$@,Debug)
|
|
||||||
build/release-clang: PHONY
|
|
||||||
$(call run_config,$@,Release)
|
|
||||||
$(call run_build,$@,Release)
|
|
||||||
|
|
||||||
# cross compiler: Windows mingw-w64
|
# extra pre-defined build configurations and some utility; optional
|
||||||
build/%-cross-mingw64: export CC=x86_64-w64-mingw32-gcc
|
ifneq ($(MAKEFILE_LIST),)
|
||||||
build/%-cross-mingw64: export CXX=x86_64-w64-mingw32-g++
|
include $(dir $(lastword $(MAKEFILE_LIST)))/misc/make/Makefile-extra.mk
|
||||||
# disable sanitize to avoid link errors on GitHub CI
|
else
|
||||||
build/%-cross-mingw64: UPX_CMAKE_CONFIG_FLAGS += -DUPX_CONFIG_DISABLE_SANITIZE=1
|
include ./misc/make/Makefile-extra.mk
|
||||||
build/debug-cross-mingw64: PHONY
|
endif
|
||||||
$(call run_config,$@,Debug)
|
|
||||||
$(call run_build,$@,Debug)
|
|
||||||
build/release-cross-mingw64: PHONY
|
|
||||||
$(call run_config,$@,Release)
|
|
||||||
$(call run_build,$@,Release)
|
|
||||||
|
|
||||||
.PHONY: default PHONY
|
# developer convenience
|
||||||
|
CTEST = ctest
|
||||||
|
test:: $(.DEFAULT_GOAL) PHONY
|
||||||
|
cd $(.DEFAULT_GOAL) && $(CTEST)
|
||||||
|
ifneq ($(wildcard /usr/bin/env),) # need Unix utils like bash, perl, sed, xargs, etc.
|
||||||
|
ifneq ($(wildcard ./misc/scripts/.),)
|
||||||
|
check-whitespace clang-format run-testsuite run-testsuite-debug run-testsuite-release: src/Makefile PHONY
|
||||||
|
$(MAKE) -C src $@
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|||||||
@@ -2,15 +2,44 @@
|
|||||||
User visible changes for UPX
|
User visible changes for UPX
|
||||||
==================================================================
|
==================================================================
|
||||||
|
|
||||||
Changes in 3.99 (27 Oct 2022):
|
Changes in 4.2.2 (03 Jan 2024):
|
||||||
* NOTE: this is a pre-release with known regressions for some ELF formats;
|
* bug fixes - see https://github.com/upx/upx/milestone/15
|
||||||
please help testing and reporting bugs, and see our GitHub Actions CI
|
|
||||||
page for up-to-date pre-built binaries ("Artifacts")
|
Changes in 4.2.1 (01 Nov 2023):
|
||||||
https://github.com/upx/upx/actions/workflows/ci.yml
|
* linux: /proc/self/exe now is optional
|
||||||
|
* windows: use SetFileTime to preserve sub-second file timestamps
|
||||||
|
* official Windows builds: revert activeCodePage change introduced in 4.2.0
|
||||||
|
* bug fixes - see https://github.com/upx/upx/milestone/14
|
||||||
|
|
||||||
|
Changes in 4.2.0 (26 Oct 2023):
|
||||||
|
* win32/pe and win64/pe: stricter relocation checks; please report regressions
|
||||||
|
* unix: use utimensat to preserve sub-second file timestamps
|
||||||
|
* new option '--link' to preserve hard-links (Unix only; use with care)
|
||||||
|
* add support for NO_COLOR env var; see https://no-color.org/
|
||||||
|
* disable macOS support until we fix compatibility with macOS 13+
|
||||||
|
* official Windows builds: set activeCodePage to UTF-8
|
||||||
|
* bug fixes - see https://github.com/upx/upx/milestone/13
|
||||||
|
|
||||||
|
Changes in 4.1.0 (08 Aug 2023):
|
||||||
|
* ELF: handle shared libraries with more than 2 PT_LOAD segments
|
||||||
|
* bug fixes - see https://github.com/upx/upx/milestone/11
|
||||||
|
|
||||||
|
Changes in 4.0.2 (30 Jan 2023):
|
||||||
|
* bug fixes - see https://github.com/upx/upx/milestone/9
|
||||||
|
|
||||||
|
Changes in 4.0.1 (16 Nov 2022):
|
||||||
|
* bug fixes - see https://github.com/upx/upx/milestone/8
|
||||||
|
|
||||||
|
Changes in 4.0.0 (28 Oct 2022):
|
||||||
|
* Switch to semantic versioning
|
||||||
* SECURITY NOTES: emphasize the security context in the docs
|
* SECURITY NOTES: emphasize the security context in the docs
|
||||||
* Support easy building from source code with CMake
|
* Support easy building from source code with CMake
|
||||||
|
* Support easy rebuilding the stubs from source with Podman/Docker
|
||||||
|
* Add integrated doctest C++ testing framework
|
||||||
* Add support for EFI files (PE x86; Kornel Pal)
|
* Add support for EFI files (PE x86; Kornel Pal)
|
||||||
|
* win32/pe and win64/pe: set correct SizeOfHeaders in the PE header
|
||||||
* bug fixes - see https://github.com/upx/upx/milestone/6
|
* bug fixes - see https://github.com/upx/upx/milestone/6
|
||||||
|
* bug fixes - see https://github.com/upx/upx/milestone/7
|
||||||
|
|
||||||
Changes in 3.96 (23 Jan 2020):
|
Changes in 3.96 (23 Jan 2020):
|
||||||
* bug fixes - see https://github.com/upx/upx/milestone/5
|
* bug fixes - see https://github.com/upx/upx/milestone/5
|
||||||
@@ -68,7 +97,7 @@ Changes in 3.08 (12 Dec 2011):
|
|||||||
* Compress shared library on ELF i386 only [ld.so threatens even this case].
|
* Compress shared library on ELF i386 only [ld.so threatens even this case].
|
||||||
* Attempt to support ELF on QNX 6.3.0 for armel (experimental).
|
* Attempt to support ELF on QNX 6.3.0 for armel (experimental).
|
||||||
* Better diagnostic when ELF -fPIC is needed.
|
* Better diagnostic when ELF -fPIC is needed.
|
||||||
* PT_NOTE improvements for *BSD.
|
* PT_NOTE improvements for BSD.
|
||||||
* Preserve more ELF .e_flags on ARM.
|
* Preserve more ELF .e_flags on ARM.
|
||||||
* Minor code improvements for ELF stubs.
|
* Minor code improvements for ELF stubs.
|
||||||
* Defend against another flavor of corrupt PE header.
|
* Defend against another flavor of corrupt PE header.
|
||||||
@@ -142,7 +171,7 @@ Changes in 2.92 beta (23 Jan 2007):
|
|||||||
|
|
||||||
Changes in 2.91 beta (29 Nov 2006):
|
Changes in 2.91 beta (29 Nov 2006):
|
||||||
* assorted bug fixes
|
* assorted bug fixes
|
||||||
* arm/pe: fix "missing" icon & version info resource problem for wince 5
|
* wince/arm: fix "missing" icon & version info resource problem for WinCE 5
|
||||||
* win32/pe & arm/pe: added option --compress-icons=3 to compress all icons
|
* win32/pe & arm/pe: added option --compress-icons=3 to compress all icons
|
||||||
|
|
||||||
Changes in 2.90 beta (08 Oct 2006):
|
Changes in 2.90 beta (08 Oct 2006):
|
||||||
@@ -196,7 +225,7 @@ Changes in 1.95 beta (09 Apr 2006):
|
|||||||
* win32/pe: really worked around R6002 runtime errors
|
* win32/pe: really worked around R6002 runtime errors
|
||||||
|
|
||||||
Changes in 1.94 beta (11 Mar 2006):
|
Changes in 1.94 beta (11 Mar 2006):
|
||||||
* new format: added support for arm/pe (ARM executables running on WinCE)
|
* new format: added support for wince/arm (ARM executables running on WinCE)
|
||||||
* new format: added support for linux elf/amd64
|
* new format: added support for linux elf/amd64
|
||||||
* new format: added support for linux elf/ppc32
|
* new format: added support for linux elf/ppc32
|
||||||
* new format: added support for mach/ppc32 (Apple Mac OS X)
|
* new format: added support for mach/ppc32 (Apple Mac OS X)
|
||||||
@@ -248,7 +277,7 @@ Changes in 1.11 beta (20 Dec 2000):
|
|||||||
==================================================================
|
==================================================================
|
||||||
|
|
||||||
Changes in 1.25 (29 Jun 2004)
|
Changes in 1.25 (29 Jun 2004)
|
||||||
* INFO: http://upx.sourceforge.net is the permanent UPX home page
|
* INFO: http://upx.sourceforge.net is the new UPX home page
|
||||||
* watcom/le: don't crash on files without relocations
|
* watcom/le: don't crash on files without relocations
|
||||||
* win32/pe: stricter checks of some PE values
|
* win32/pe: stricter checks of some PE values
|
||||||
* source code: much improved portability using ACC, the
|
* source code: much improved portability using ACC, the
|
||||||
@@ -364,6 +393,8 @@ Changes in 0.99 (25 Feb 2000)
|
|||||||
* dos/com and dos/sys: fixed a bad decompressor problem
|
* dos/com and dos/sys: fixed a bad decompressor problem
|
||||||
* linux/386: the counter for the progress indicator was off by one
|
* linux/386: the counter for the progress indicator was off by one
|
||||||
|
|
||||||
|
==================================================================
|
||||||
|
|
||||||
Changes in 0.94 (06 Dec 1999)
|
Changes in 0.94 (06 Dec 1999)
|
||||||
* win32/pe: the stub now calls ExitProcess in case of import errors
|
* win32/pe: the stub now calls ExitProcess in case of import errors
|
||||||
* under DOS and Windows, the environment variable UPX now accepts
|
* under DOS and Windows, the environment variable UPX now accepts
|
||||||
@@ -511,12 +542,12 @@ Changes in 0.40 (05 Oct 1998)
|
|||||||
* fixed a small but fatal bug in dos/sys introduced in 0.30
|
* fixed a small but fatal bug in dos/sys introduced in 0.30
|
||||||
* fixed a rare bug in dos/exe
|
* fixed a rare bug in dos/exe
|
||||||
* worked around a bug in djgpp's strip 2.8
|
* worked around a bug in djgpp's strip 2.8
|
||||||
* djgpp/coff: Allegro packfile support should work now
|
* djgpp2/coff: Allegro packfile support should work now
|
||||||
* added dos/exeh compression method (works on 386+)
|
* added dos/exeh compression method (works on 386+)
|
||||||
|
|
||||||
Changes in 0.30 (27 Jul 1998)
|
Changes in 0.30 (27 Jul 1998)
|
||||||
* fixed a serious bug in the 32-bit compressors - please don't use
|
* fixed a serious bug in the 32-bit compressors - please don't use
|
||||||
djgpp/coff and watcom/le compressed files from previous versions,
|
djgpp2/coff and watcom/le compressed files from previous versions,
|
||||||
some of them are possibly damaged !
|
some of them are possibly damaged !
|
||||||
* the 16-bit uncompressors are a little bit shorter & faster
|
* the 16-bit uncompressors are a little bit shorter & faster
|
||||||
* fixed progress indicator for VESA and SVGA text modes
|
* fixed progress indicator for VESA and SVGA text modes
|
||||||
@@ -527,6 +558,5 @@ Changes in 0.20 (05 Jul 1998)
|
|||||||
|
|
||||||
Changes in 0.05 (26 May 1998)
|
Changes in 0.05 (26 May 1998)
|
||||||
* first public beta release
|
* first public beta release
|
||||||
|
* based on experience gained from our previous packers DJP (djgpp2/coff, 1996),
|
||||||
|
lzop (1996) and mfxpak (atari/tos, 1990)
|
||||||
# vim:set syntax=off tw=0 ts=4 sw=4 et: -*- coding: utf-8 -*-
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||||
https://upx.github.io
|
https://upx.github.io
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ and run exactly as before, with no runtime or memory penalty for most
|
|||||||
of the supported formats.
|
of the supported formats.
|
||||||
|
|
||||||
UPX supports a number of different executable formats, including
|
UPX supports a number of different executable formats, including
|
||||||
Windows programs and DLLs, macOS apps and Linux executables.
|
Windows programs and DLLs, and Linux executables.
|
||||||
|
|
||||||
UPX is free software distributed under the term of the GNU General
|
UPX is free software distributed under the term of the GNU General
|
||||||
Public License. Full source code is available.
|
Public License. Full source code is available.
|
||||||
@@ -68,9 +68,11 @@ NEWS and BUGS also contain various tidbits of information.
|
|||||||
THE FUTURE
|
THE FUTURE
|
||||||
==========
|
==========
|
||||||
|
|
||||||
- Stay up-to-date with ongoing OS and executable format changes.
|
- Stay up-to-date with ongoing OS and executable format changes
|
||||||
|
|
||||||
- RISC-V 64 for Linux.
|
- RISC-V 64 for Linux
|
||||||
|
|
||||||
|
- ARM64 for Windows (help wanted)
|
||||||
|
|
||||||
- We will *NOT* add any sort of protection and/or encryption.
|
- We will *NOT* add any sort of protection and/or encryption.
|
||||||
This only gives people a false feeling of security because
|
This only gives people a false feeling of security because
|
||||||
@@ -83,24 +85,20 @@ THE FUTURE
|
|||||||
COPYRIGHT
|
COPYRIGHT
|
||||||
=========
|
=========
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
Copyright (C) 2000-2022 John F. Reiser
|
Copyright (C) 2000-2024 John F. Reiser
|
||||||
|
|
||||||
This program may be used freely, and you are welcome to
|
UPX is distributed with full source code under the terms of the
|
||||||
redistribute it under certain conditions.
|
GNU General Public License v2+; either under the pure GPLv2+ (see
|
||||||
|
the file COPYING), or (at your option) under the GPLv+2 with special
|
||||||
|
exceptions and restrictions granting the free usage for all binaries
|
||||||
|
including commercial programs (see the file LICENSE).
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
UPX is distributed with full source code under the terms of the
|
|
||||||
GNU General Public License v2+;
|
|
||||||
either under the pure GPLv2+ (see the file COPYING),
|
|
||||||
or (at your option) under the GPLv+2 with special exceptions and
|
|
||||||
restrictions granting the free usage for commercial
|
|
||||||
programs (see the file LICENSE).
|
|
||||||
|
|
||||||
You should have received a copy of the UPX License Agreements along
|
You should have received a copy of the UPX License Agreements along
|
||||||
with this program; see the files COPYING and LICENSE. If not,
|
with this program; see the files COPYING and LICENSE. If not,
|
||||||
visit the UPX home page.
|
visit the UPX home page.
|
||||||
|
|||||||
+37
-2
@@ -44,7 +44,8 @@ Short overview
|
|||||||
Tools needed to build/modify the UPX sources
|
Tools needed to build/modify the UPX sources
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
- A C++ compiler that supports C++ 14: clang, gcc or msvc
|
- A C++ compiler that fully implements C++17: clang-5, gcc-8 or msvc-2019-16.11
|
||||||
|
(older or other compilers may work but are unsupported, use at your own risk)
|
||||||
|
|
||||||
- GNU make
|
- GNU make
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ To compile the packer sources
|
|||||||
If you want to modify the stub sources you'll also need
|
If you want to modify the stub sources you'll also need
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
|
|
||||||
- Podman/Docker: see misc/rebuild-stubs-with-podman - this
|
- Podman/Docker: see misc/podman/rebuild-stubs - this
|
||||||
is the preferred way of rebuilding the stubs
|
is the preferred way of rebuilding the stubs
|
||||||
|
|
||||||
- otherwise you will need:
|
- otherwise you will need:
|
||||||
@@ -70,6 +71,40 @@ If you want to modify the stub sources you'll also need
|
|||||||
https://github.com/upx/upx-stubtools/releases
|
https://github.com/upx/upx-stubtools/releases
|
||||||
|
|
||||||
|
|
||||||
|
Developer quick start
|
||||||
|
---------------------
|
||||||
|
1) $ mkdir my-upx; cd my-upx # new directory for safety and convenience
|
||||||
|
2) $ git clone https://github.com/upx/upx.git
|
||||||
|
3) $ git clone https://github.com/upx/upx-testsuite.git
|
||||||
|
4) # Optional for re-building stubs:
|
||||||
|
4a) $ pushd upx/src/stub # my-upx/upx/src/stub
|
||||||
|
4b) $ wget https://github.com/upx/upx-stubtools/releases/download/v20221212/bin-upx-20221212.tar.xz
|
||||||
|
# Extract to $HOME/bin/bin-upx or $HOME/local/bin/bin-upx.
|
||||||
|
# See directions in: https://github.com/upx/upx-stubtools
|
||||||
|
4c) $ make clean; make # verify that you can re-build stubs
|
||||||
|
4d) $ popd # my-upx
|
||||||
|
5) $ cd upx # my-upx/upx
|
||||||
|
6) $ git submodule update --init # compression algorithms, etc.
|
||||||
|
# DO NOT TOUCH vendor/...
|
||||||
|
# After a git merge/pull/etc, then use "git status"
|
||||||
|
# to check whether the vendor directory is clean;
|
||||||
|
# if not, then update via "git submodule update".
|
||||||
|
# If stuck, then reset via "rm -rf vendor; git submodule update --init".
|
||||||
|
7) $ mkdir -p build/debug build/release
|
||||||
|
8) $ pushd build/debug # my-upx/upx/build/debug
|
||||||
|
9) $ cmake ../.. # configure cmake
|
||||||
|
10) $ cmake --build . --verbose # optional "--verbose"
|
||||||
|
# This relies on stub/*.h, which YOU must re-build if necessary.
|
||||||
|
# When in doubt, then use "cd src/stub; make clean; make".
|
||||||
|
11) $ popd # my-upx/upx
|
||||||
|
12) $ cd src # my-upx/upx/src
|
||||||
|
12a) On MacOS: install homebrew (https:://brew.sh), then "brew install coreutils"
|
||||||
|
and put <some_prefix>/opt/coreutils/libexec/gnubin into PATH so that
|
||||||
|
"readlink -en" and "sha256sum -b" work.
|
||||||
|
13) $ make run-testsuite 2>&1 | tee testsuite.log
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Misc. notes
|
Misc. notes
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
-Ivendor
|
|
||||||
-fno-strict-aliasing
|
|
||||||
-fno-strict-overflow
|
|
||||||
-funsigned-char
|
|
||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||||
https://upx.github.io
|
https://upx.github.io
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-35
@@ -1,21 +1,9 @@
|
|||||||
#
|
#
|
||||||
# UPX doc Makefile - needs GNU make
|
# UPX doc Makefile - needs GNU make, sed, pod2html, pod2man and pod2text
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
#
|
#
|
||||||
|
|
||||||
MAKEFLAGS += -rR
|
BUILT_SOURCES = upx.1 upx-doc.html upx-doc.txt
|
||||||
.SUFFIXES:
|
|
||||||
SHELL = /bin/sh
|
|
||||||
|
|
||||||
# internal make variables
|
|
||||||
comma := ,
|
|
||||||
empty :=
|
|
||||||
space := $(empty) $(empty)
|
|
||||||
tab := $(empty) $(empty)
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
|
||||||
# //
|
|
||||||
# ************************************************************************/
|
|
||||||
|
|
||||||
top_srcdir ?= ..
|
top_srcdir ?= ..
|
||||||
|
|
||||||
@@ -23,27 +11,32 @@ PACKAGE = upx
|
|||||||
VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||||
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||||
|
|
||||||
|
# internal make variables
|
||||||
|
comma := ,
|
||||||
|
empty :=
|
||||||
|
space := $(empty) $(empty)
|
||||||
|
tab := $(empty) $(empty)
|
||||||
|
|
||||||
RTRIM := sed -e 's/[ $(tab)]*$$//'
|
RTRIM := sed -e 's/[ $(tab)]*$$//'
|
||||||
DETAB2 := sed -e 's/$(tab)/ /g'
|
DETAB2 := sed -e 's/$(tab)/ /g'
|
||||||
|
|
||||||
BUILT_SOURCES = upx.1 upx-doc.html upx-doc.txt
|
#***********************************************************************
|
||||||
|
# targets
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
.DEFAULT_GOAL = all
|
||||||
|
.PHONY: PHONY
|
||||||
|
.SECONDEXPANSION:
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
###
|
all: $(BUILT_SOURCES) PHONY
|
||||||
### targets
|
|
||||||
###
|
|
||||||
|
|
||||||
all: $(BUILT_SOURCES)
|
mostlyclean clean distclean maintainer-clean: PHONY
|
||||||
|
rm -f $(BUILT_SOURCES) ./pod2htm*
|
||||||
|
|
||||||
mostlyclean clean distclean maintainer-clean:
|
#***********************************************************************
|
||||||
rm -f $(BUILT_SOURCES) pod2htm*
|
# rules
|
||||||
|
#***********************************************************************
|
||||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
### rules
|
|
||||||
###
|
|
||||||
|
|
||||||
.SUFFIXES: .1 .html .man .pod .ps .tex .txt
|
.SUFFIXES: .1 .html .man .pod .ps .tex .txt
|
||||||
|
|
||||||
@@ -53,7 +46,7 @@ mostlyclean clean distclean maintainer-clean:
|
|||||||
|
|
||||||
%-doc.html : %.pod
|
%-doc.html : %.pod
|
||||||
pod2html --noindex $< | $(RTRIM) | $(DETAB2) > $@
|
pod2html --noindex $< | $(RTRIM) | $(DETAB2) > $@
|
||||||
@rm -f pod2htm*
|
@rm -f ./pod2htm*
|
||||||
test -s $@
|
test -s $@
|
||||||
|
|
||||||
%.man : %.1
|
%.man : %.1
|
||||||
@@ -72,11 +65,9 @@ mostlyclean clean distclean maintainer-clean:
|
|||||||
pod2text < $< | $(RTRIM) > $@
|
pod2text < $< | $(RTRIM) > $@
|
||||||
test -s $@
|
test -s $@
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
###
|
# dependencies
|
||||||
### dependencies
|
#***********************************************************************
|
||||||
###
|
|
||||||
|
|
||||||
$(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
|
$(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
|
||||||
.DELETE_ON_ERROR: $(BUILT_SOURCES)
|
.DELETE_ON_ERROR: $(BUILT_SOURCES)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||||
https://upx.github.io
|
https://upx.github.io
|
||||||
|
|
||||||
|
|
||||||
@@ -41,12 +41,14 @@ Joergen Ibsen <jibz@hotmail.com> and d'b
|
|||||||
for the relocation & address optimization ideas
|
for the relocation & address optimization ideas
|
||||||
John S. Fine <johnfine@erols.com>
|
John S. Fine <johnfine@erols.com>
|
||||||
for the new version of the dos/exe decompressor
|
for the new version of the dos/exe decompressor
|
||||||
|
Kornel Pal
|
||||||
|
for the EFI support
|
||||||
Lukundoo <Lukundoo@softhome.net>
|
Lukundoo <Lukundoo@softhome.net>
|
||||||
for beta testing
|
for beta testing
|
||||||
Michael Devore
|
Michael Devore
|
||||||
for initial dos/exe device driver support
|
for initial dos/exe device driver support
|
||||||
Oleg V. Volkov <rover@lglobus.ru>
|
Oleg V. Volkov <rover@lglobus.ru>
|
||||||
for various FreeBSD specific informations
|
for various FreeBSD specific information
|
||||||
The Owl & G-RoM
|
The Owl & G-RoM
|
||||||
for the --compress-icons fix
|
for the --compress-icons fix
|
||||||
Ralph Roth <RalphRoth@gmx.net>
|
Ralph Roth <RalphRoth@gmx.net>
|
||||||
@@ -55,6 +57,6 @@ Salvador Eduardo Tropea
|
|||||||
for beta testing
|
for beta testing
|
||||||
Stefan Widmann
|
Stefan Widmann
|
||||||
for the win32/pe TLS callback support
|
for the win32/pe TLS callback support
|
||||||
The WINE project (http://www.winehq.com/)
|
The WINE project (https://www.winehq.com/)
|
||||||
for lots of useful information found in their PE loader sources
|
for lots of useful information found in their PE loader sources
|
||||||
Natascha
|
Natascha
|
||||||
+46
-44
@@ -1,5 +1,5 @@
|
|||||||
Decompressing ELF Directly to Memory on Linux/x86
|
Decompressing ELF Directly to Memory on Linux/x86
|
||||||
Copyright (C) 2000-2022 John F. Reiser jreiser@BitWagon.com
|
Copyright (C) 2000-2024 John F. Reiser jreiser@BitWagon.com
|
||||||
|
|
||||||
References:
|
References:
|
||||||
<elf.h> definitions for the ELF file format
|
<elf.h> definitions for the ELF file format
|
||||||
@@ -15,7 +15,7 @@ the value that is manipulated by system call 45 (__NR_brk in
|
|||||||
there will be no execve() except for the execve() of the decompressor
|
there will be no execve() except for the execve() of the decompressor
|
||||||
program itself. So, the decompressor program (which contains the
|
program itself. So, the decompressor program (which contains the
|
||||||
compressed version of the original executable) must have the same
|
compressed version of the original executable) must have the same
|
||||||
brk() as the original executable. So, the second PT_LOAD
|
brk() as the original executable. So, the first PT_LOAD
|
||||||
ELF "segment" of the compressed program is used only to set the brk(0).
|
ELF "segment" of the compressed program is used only to set the brk(0).
|
||||||
See src/p_lx_elf.cpp, function PackLinuxElf32::generateElfHdr.
|
See src/p_lx_elf.cpp, function PackLinuxElf32::generateElfHdr.
|
||||||
All of the decompressor's code, and all of the compressed image
|
All of the decompressor's code, and all of the compressed image
|
||||||
@@ -25,35 +25,27 @@ decompressor program.
|
|||||||
The decompressor program stub is just under 2K bytes when linked.
|
The decompressor program stub is just under 2K bytes when linked.
|
||||||
After linking, the decompressor code is converted to an initialized
|
After linking, the decompressor code is converted to an initialized
|
||||||
array, and #included into the compilation of the compressor;
|
array, and #included into the compilation of the compressor;
|
||||||
see src/stub/l_le_n2b.h. To make self-contained compressed
|
see stub/i386-linux.elf-entry.h. To make self-contained compressed
|
||||||
executables even smaller, the compressor also compresses all but the
|
executables even smaller, the compressor also compresses all but the
|
||||||
startup and decompression subroutine of the decompressor itself,
|
startup and decompression subroutine of the decompressor itself,
|
||||||
saving a few hundred bytes. The startup code first decompresses the
|
saving a few hundred bytes. The startup code first decompresses the
|
||||||
rest of the decompressor, then jumps to it. A nonstandard linker
|
rest of the decompressor, then jumps to it. A nonstandard linker
|
||||||
script src/stub/l_lx_elf86.lds places both the .text and .data
|
script src/stub/src/i386-linux.elf-entry.lds arranges the SECTIONS
|
||||||
of the decompressor into the same PT_LOAD at 0x00401000. The
|
so that PackLinuxElf32x86::buildLoader() and buildLinuxLoader()
|
||||||
compressor includes the compressed bytes of the original executable
|
generate the desired stub code, which goes into PT_LOAD[1].
|
||||||
at the end of this first PT_LOAD.
|
|
||||||
|
|
||||||
At runtime, the decompressed stub lives at 0x00400000. In order for the
|
At runtime, the decompressed stub lives close beyond the brk().
|
||||||
decompressed stub to work properly at an address that is different
|
In order for the decompressed stub to work properly at an address
|
||||||
from its link-time address, the compiled code must contain no absolute
|
that is different from its link-time address, the compiled code must
|
||||||
addresses. So, the data items in l_lx_elf.c must be only parameters
|
contain no absolute addresses. So, the data items in stub code
|
||||||
and automatic (on-stack) local variables; no global data, no static data,
|
must be only parameters and automatic (on-stack) local variables;
|
||||||
and no string constants. Use "size l_le_n2b.o l_6e_n2b.o" to check
|
no global data, no static data, and no string constants. Also,
|
||||||
that both data and bss have length zero. Also, the '&' operator
|
the '&' operator may not be used to take the address of a function.
|
||||||
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 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
|
Decompression of the executable begins by decompressing the Elf32_Ehdr
|
||||||
and Elf32_Phdr, and then uses the Ehdr and Phdrs to control decompression
|
and Elf32_Phdr, and then uses those Ehdr and Phdrs to control decompression
|
||||||
of the PT_LOAD segments.
|
of the PT_LOAD segments. Subroutine do_xmap() of src/stub/src/
|
||||||
Subroutine do_xmap() of src/stub/l_lx_elf.c performs the
|
i386-linux.elf-main.c performs the
|
||||||
"virtual execve()" using the compressed data as source, and stores
|
"virtual execve()" using the compressed data as source, and stores
|
||||||
the decompressed bytes directly into the appropriate virtual addresses.
|
the decompressed bytes directly into the appropriate virtual addresses.
|
||||||
|
|
||||||
@@ -74,22 +66,17 @@ expanding $ORIGIN in -rpath, or for application code that relies on
|
|||||||
--unmap-all-pages to achieve that effect at run time. Upx-3.04
|
--unmap-all-pages to achieve that effect at run time. Upx-3.04
|
||||||
and previous versions did this by default with no option. However,
|
and previous versions did this by default with no option. However,
|
||||||
too much other software erroneously assumes that /proc/self/exe
|
too much other software erroneously assumes that /proc/self/exe
|
||||||
always exists.
|
always exists. upx-4.3.0 made /proc/self/exe optional so that
|
||||||
|
chroot() and related environments can work.
|
||||||
|
For Elf formats, UPX adds an environment variable named " " [three
|
||||||
|
spaces] which saves the results of readlink("/proc/self/exe",,)
|
||||||
|
If /proc/self/exe is ENOENT, then the variable has the same value
|
||||||
|
as its name "/proc/self/exe".
|
||||||
|
|
||||||
On arm*-linux-elf there is no good address at which to retain one
|
All of the above documentation refers to ET_EXEC main programs,
|
||||||
page of the compressed executable. Pages below the usual .p_vaddr
|
which always use the same virtual addresses. An ET_DYN executable
|
||||||
0x8000 (32KiB) are rejected by the kernel. Using a page above the
|
(main program or shared library) follows much the same scheme,
|
||||||
original uncompressed brk(0) would require placing the entire initial
|
re-using the address space that the kernel chose originally.
|
||||||
compressed program above uncompressed brk(0), which would significantly
|
|
||||||
increase the running brk(0); but too many programs break if brk(0)
|
|
||||||
moves. Thus on arm*-linux-elf the compressed executable begins
|
|
||||||
with 0x8000==.p_vaddr, all pages mapped by execve() that are also
|
|
||||||
occupied by decompressed bytes are removed before overwriting, and
|
|
||||||
/proc/self/exe becomes a "(deleted)" symlink. It might be possible
|
|
||||||
to preserve /proc/self/exe if the original uncompressed executable
|
|
||||||
were created with 0x9000==.p_vaddr (one page higher than the usual
|
|
||||||
0x8000) so that the compressed page mapped at 0x8000 would linger.
|
|
||||||
[This has not been tested.]
|
|
||||||
|
|
||||||
Linux stores the pathname argument that was specified to execve()
|
Linux stores the pathname argument that was specified to execve()
|
||||||
immediately after the '\0' which terminates the character string of the
|
immediately after the '\0' which terminates the character string of the
|
||||||
@@ -99,9 +86,24 @@ 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 pathname is not "bound" to the file as strongly as /proc/self/exe
|
||||||
(the file may be changed without affecting the pathname), but the
|
(the file may be changed without affecting the pathname), but the
|
||||||
pathname does provide some information. The pathname may be relative
|
pathname does provide some information. The pathname may be relative
|
||||||
to the working directory, so look before any chdir().
|
to the working directory, so look before performing any chdir().
|
||||||
|
|
||||||
The Elf formats for Linux add an environment variable named " " [three
|
On any page, then SELinux in strictest enforcing mode prohibits
|
||||||
spaces] which saves the results of readlink("/proc/self/exe",,) before
|
simultaneous PROT_EXEC and PROT_WRITE, and also prohibits adding
|
||||||
the runtime stub unmaps all its pages. As of 2006-10-03 this works
|
PROT_EXEC if the kernel VMA struct (Virtual Memory Area struct)
|
||||||
for linux/elf386 and linux/ElfAMD.
|
that manages that page ever has had PROT_WRITE. This implies that
|
||||||
|
the only way to get PROT_EXEC is to map the page directly from a file.
|
||||||
|
Therefore, in late 2023 the various decompression stubs are being
|
||||||
|
rewritten to "bounce" the decompressed data through pages in a
|
||||||
|
memory-resident file created by the memfd_create() system call,
|
||||||
|
and subsequently mapped PROT_EXEC. Actual copying of the pages
|
||||||
|
can be avoided by careful sequence mmap() modes, but the overhead
|
||||||
|
of an additional system call is required.
|
||||||
|
|
||||||
|
The not-as-strict "targeted enforcing" mode of
|
||||||
|
SELinux seems not to demand this extra work, except for executables
|
||||||
|
that run with elevated privileges, such as various system daemons.
|
||||||
|
So "ordinary" user-mode apps can run in current "targeted enforcing"
|
||||||
|
mode. But because the actual runtime mode of SELinux is unknown
|
||||||
|
at compression time, then the memfd_create method should be used
|
||||||
|
all the time.
|
||||||
|
|||||||
Generated
+7
-9
@@ -22,7 +22,7 @@
|
|||||||
<h1 id="ABSTRACT">ABSTRACT</h1>
|
<h1 id="ABSTRACT">ABSTRACT</h1>
|
||||||
|
|
||||||
<pre><code> The Ultimate Packer for eXecutables
|
<pre><code> The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||||
https://upx.github.io</code></pre>
|
https://upx.github.io</code></pre>
|
||||||
|
|
||||||
<p><b>UPX</b> is a portable, extendable, high-performance executable packer for several different executable formats. It achieves an excellent compression ratio and offers <i>*very*</i> fast decompression. Your executables suffer no memory overhead or other drawbacks for most of the formats supported, because of in-place decompression.</p>
|
<p><b>UPX</b> is a portable, extendable, high-performance executable packer for several different executable formats. It achieves an excellent compression ratio and offers <i>*very*</i> fast decompression. Your executables suffer no memory overhead or other drawbacks for most of the formats supported, because of in-place decompression.</p>
|
||||||
@@ -160,7 +160,7 @@ Copyright (c) 1996-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
|||||||
|
|
||||||
<p>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).</p>
|
<p>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).</p>
|
||||||
|
|
||||||
<p><b>UPX</b> handles overlays like many other executable packers do: it simply copies the overlay after the compressed image. This works with some files, but doesn't work with others, depending on how an application actually accesses this overlayed data.</p>
|
<p><b>UPX</b> handles overlays like many other executable packers do: it simply copies the overlay after the compressed image. This works with some files, but doesn't work with others, depending on how an application actually accesses this overlaid data.</p>
|
||||||
|
|
||||||
<pre><code>--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
<pre><code>--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
||||||
|
|
||||||
@@ -785,20 +785,18 @@ Jens Medoch <jssg@users.sourceforge.net></code></pre>
|
|||||||
|
|
||||||
<h1 id="COPYRIGHT">COPYRIGHT</h1>
|
<h1 id="COPYRIGHT">COPYRIGHT</h1>
|
||||||
|
|
||||||
<p>Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer</p>
|
<p>Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer</p>
|
||||||
|
|
||||||
<p>Copyright (C) 1996-2022 Laszlo Molnar</p>
|
<p>Copyright (C) 1996-2024 Laszlo Molnar</p>
|
||||||
|
|
||||||
<p>Copyright (C) 2000-2022 John F. Reiser</p>
|
<p>Copyright (C) 2000-2024 John F. Reiser</p>
|
||||||
|
|
||||||
<p>Copyright (C) 2002-2022 Jens Medoch</p>
|
<p>Copyright (C) 2002-2024 Jens Medoch</p>
|
||||||
|
|
||||||
<p>This program may be used freely, and you are welcome to redistribute it under certain conditions.</p>
|
<p><b>UPX</b> is distributed with full source code under the terms of the GNU General Public License v2+; either under the pure GPLv2+ (see the file COPYING), or (at your option) under the GPLv+2 with special exceptions and restrictions granting the free usage for all binaries including commercial programs (see the file LICENSE).</p>
|
||||||
|
|
||||||
<p>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.</p>
|
<p>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.</p>
|
||||||
|
|
||||||
<p><b>UPX</b> is distributed with full source code under the terms of the GNU General Public License v2+; either under the pure GPLv2+ (see the file COPYING), or (at your option) under the GPLv+2 with special exceptions and restrictions granting the free usage for commercial programs (see the file LICENSE).</p>
|
|
||||||
|
|
||||||
<p>You should have received a copy of the UPX License Agreements along with this program; see the files COPYING and LICENSE. If not, visit the UPX home page.</p>
|
<p>You should have received a copy of the UPX License Agreements along with this program; see the files COPYING and LICENSE. If not, visit the UPX home page.</p>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Generated
+11
-14
@@ -6,7 +6,7 @@ SYNOPSIS
|
|||||||
|
|
||||||
ABSTRACT
|
ABSTRACT
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||||
https://upx.github.io
|
https://upx.github.io
|
||||||
|
|
||||||
UPX is a portable, extendable, high-performance executable packer for
|
UPX is a portable, extendable, high-performance executable packer for
|
||||||
@@ -153,7 +153,7 @@ OVERLAY HANDLING OPTIONS
|
|||||||
UPX handles overlays like many other executable packers do: it simply
|
UPX handles overlays like many other executable packers do: it simply
|
||||||
copies the overlay after the compressed image. This works with some
|
copies the overlay after the compressed image. This works with some
|
||||||
files, but doesn't work with others, depending on how an application
|
files, but doesn't work with others, depending on how an application
|
||||||
actually accesses this overlayed data.
|
actually accesses this overlaid data.
|
||||||
|
|
||||||
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
||||||
|
|
||||||
@@ -818,27 +818,24 @@ AUTHORS
|
|||||||
Jens Medoch <jssg@users.sourceforge.net>
|
Jens Medoch <jssg@users.sourceforge.net>
|
||||||
|
|
||||||
COPYRIGHT
|
COPYRIGHT
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
|
|
||||||
Copyright (C) 2000-2022 John F. Reiser
|
Copyright (C) 2000-2024 John F. Reiser
|
||||||
|
|
||||||
Copyright (C) 2002-2022 Jens Medoch
|
Copyright (C) 2002-2024 Jens Medoch
|
||||||
|
|
||||||
This program may be used freely, and you are welcome to redistribute it
|
UPX is distributed with full source code under the terms of the GNU
|
||||||
under certain conditions.
|
General Public License v2+; either under the pure GPLv2+ (see the file
|
||||||
|
COPYING), or (at your option) under the GPLv+2 with special exceptions
|
||||||
|
and restrictions granting the free usage for all binaries including
|
||||||
|
commercial programs (see the file LICENSE).
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but
|
This program is distributed in the hope that it will be useful, but
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
UPX is distributed with full source code under the terms of the GNU
|
|
||||||
General Public License v2+; either under the pure GPLv2+ (see the file
|
|
||||||
COPYING), or (at your option) under the GPLv+2 with special exceptions
|
|
||||||
and restrictions granting the free usage for commercial programs (see
|
|
||||||
the file LICENSE).
|
|
||||||
|
|
||||||
You should have received a copy of the UPX License Agreements along with
|
You should have received a copy of the UPX License Agreements along with
|
||||||
this program; see the files COPYING and LICENSE. If not, visit the UPX
|
this program; see the files COPYING and LICENSE. If not, visit the UPX
|
||||||
home page.
|
home page.
|
||||||
|
|||||||
@@ -133,7 +133,7 @@
|
|||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "UPX 1"
|
.IX Title "UPX 1"
|
||||||
.TH UPX 1 "2022-10-27" "upx 3.99" " "
|
.TH UPX 1 "2024-01-03" "upx 4.2.2" " "
|
||||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
.\" way too many mistakes in technical documents.
|
.\" way too many mistakes in technical documents.
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
@@ -147,7 +147,7 @@ upx \- compress or expand executable files
|
|||||||
.IX Header "ABSTRACT"
|
.IX Header "ABSTRACT"
|
||||||
.Vb 3
|
.Vb 3
|
||||||
\& The Ultimate Packer for eXecutables
|
\& The Ultimate Packer for eXecutables
|
||||||
\& Copyright (c) 1996\-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
\& Copyright (c) 1996\-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||||
\& https://upx.github.io
|
\& https://upx.github.io
|
||||||
.Ve
|
.Ve
|
||||||
.PP
|
.PP
|
||||||
@@ -296,7 +296,7 @@ it would be better to use resource sections).
|
|||||||
\&\fB\s-1UPX\s0\fR handles overlays like many other executable packers do: it simply
|
\&\fB\s-1UPX\s0\fR handles overlays like many other executable packers do: it simply
|
||||||
copies the overlay after the compressed image. This works with some
|
copies the overlay after the compressed image. This works with some
|
||||||
files, but doesn't work with others, depending on how an application
|
files, but doesn't work with others, depending on how an application
|
||||||
actually accesses this overlayed data.
|
actually accesses this overlaid data.
|
||||||
.PP
|
.PP
|
||||||
.Vb 1
|
.Vb 1
|
||||||
\& \-\-overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
\& \-\-overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
||||||
@@ -1019,28 +1019,24 @@ Please report all bugs immediately to the authors.
|
|||||||
.Ve
|
.Ve
|
||||||
.SH "COPYRIGHT"
|
.SH "COPYRIGHT"
|
||||||
.IX Header "COPYRIGHT"
|
.IX Header "COPYRIGHT"
|
||||||
Copyright (C) 1996\-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996\-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
.PP
|
.PP
|
||||||
Copyright (C) 1996\-2022 Laszlo Molnar
|
Copyright (C) 1996\-2024 Laszlo Molnar
|
||||||
.PP
|
.PP
|
||||||
Copyright (C) 2000\-2022 John F. Reiser
|
Copyright (C) 2000\-2024 John F. Reiser
|
||||||
.PP
|
.PP
|
||||||
Copyright (C) 2002\-2022 Jens Medoch
|
Copyright (C) 2002\-2024 Jens Medoch
|
||||||
.PP
|
.PP
|
||||||
This program may be used freely, and you are welcome to
|
\&\fB\s-1UPX\s0\fR is distributed with full source code under the terms of the
|
||||||
redistribute it under certain conditions.
|
\&\s-1GNU\s0 General Public License v2+; either under the pure GPLv2+ (see
|
||||||
|
the file \s-1COPYING\s0), or (at your option) under the GPLv+2 with special
|
||||||
|
exceptions and restrictions granting the free usage for all binaries
|
||||||
|
including commercial programs (see the file \s-1LICENSE\s0).
|
||||||
.PP
|
.PP
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of
|
but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of
|
||||||
\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0
|
\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0
|
||||||
.PP
|
.PP
|
||||||
\&\fB\s-1UPX\s0\fR is distributed with full source code under the terms of the
|
|
||||||
\&\s-1GNU\s0 General Public License v2+;
|
|
||||||
either under the pure GPLv2+ (see the file \s-1COPYING\s0),
|
|
||||||
or (at your option) under the GPLv+2 with special exceptions and
|
|
||||||
restrictions granting the free usage for commercial
|
|
||||||
programs (see the file \s-1LICENSE\s0).
|
|
||||||
.PP
|
|
||||||
You should have received a copy of the \s-1UPX\s0 License Agreements along
|
You should have received a copy of the \s-1UPX\s0 License Agreements along
|
||||||
with this program; see the files \s-1COPYING\s0 and \s-1LICENSE.\s0 If not,
|
with this program; see the files \s-1COPYING\s0 and \s-1LICENSE.\s0 If not,
|
||||||
visit the \s-1UPX\s0 home page.
|
visit the \s-1UPX\s0 home page.
|
||||||
|
|||||||
+11
-15
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
|||||||
=head1 ABSTRACT
|
=head1 ABSTRACT
|
||||||
|
|
||||||
The Ultimate Packer for eXecutables
|
The Ultimate Packer for eXecutables
|
||||||
Copyright (c) 1996-2022 Markus Oberhumer, Laszlo Molnar & John Reiser
|
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||||
https://upx.github.io
|
https://upx.github.io
|
||||||
|
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ it would be better to use resource sections).
|
|||||||
B<UPX> handles overlays like many other executable packers do: it simply
|
B<UPX> handles overlays like many other executable packers do: it simply
|
||||||
copies the overlay after the compressed image. This works with some
|
copies the overlay after the compressed image. This works with some
|
||||||
files, but doesn't work with others, depending on how an application
|
files, but doesn't work with others, depending on how an application
|
||||||
actually accesses this overlayed data.
|
actually accesses this overlaid data.
|
||||||
|
|
||||||
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
|
||||||
|
|
||||||
@@ -932,28 +932,24 @@ Please report all bugs immediately to the authors.
|
|||||||
|
|
||||||
=head1 COPYRIGHT
|
=head1 COPYRIGHT
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
|
|
||||||
Copyright (C) 2000-2022 John F. Reiser
|
Copyright (C) 2000-2024 John F. Reiser
|
||||||
|
|
||||||
Copyright (C) 2002-2022 Jens Medoch
|
Copyright (C) 2002-2024 Jens Medoch
|
||||||
|
|
||||||
This program may be used freely, and you are welcome to
|
B<UPX> is distributed with full source code under the terms of the
|
||||||
redistribute it under certain conditions.
|
GNU General Public License v2+; either under the pure GPLv2+ (see
|
||||||
|
the file COPYING), or (at your option) under the GPLv+2 with special
|
||||||
|
exceptions and restrictions granting the free usage for all binaries
|
||||||
|
including commercial programs (see the file LICENSE).
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
B<UPX> is distributed with full source code under the terms of the
|
|
||||||
GNU General Public License v2+;
|
|
||||||
either under the pure GPLv2+ (see the file COPYING),
|
|
||||||
or (at your option) under the GPLv+2 with special exceptions and
|
|
||||||
restrictions granting the free usage for commercial
|
|
||||||
programs (see the file LICENSE).
|
|
||||||
|
|
||||||
You should have received a copy of the UPX License Agreements along
|
You should have received a copy of the UPX License Agreements along
|
||||||
with this program; see the files COPYING and LICENSE. If not,
|
with this program; see the files COPYING and LICENSE. If not,
|
||||||
visit the UPX home page.
|
visit the UPX home page.
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
||||||
|
---
|
||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
-bugprone-branch-clone,
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-implicit-widening-of-multiplication-result,
|
||||||
|
-bugprone-macro-parentheses,
|
||||||
|
-bugprone-narrowing-conversions,
|
||||||
|
-bugprone-reserved-identifier,
|
||||||
|
-bugprone-switch-missing-default-case,
|
||||||
|
clang-analyzer-*,
|
||||||
|
-clang-analyzer-core.UndefinedBinaryOperatorResult,
|
||||||
|
-clang-analyzer-core.uninitialized.Assign,
|
||||||
|
-clang-analyzer-security.insecureAPI.strcpy,
|
||||||
|
clang-diagnostics-*',
|
||||||
|
performance-*,
|
||||||
|
FormatStyle: file
|
||||||
|
HeaderFilterRegex: '.*'
|
||||||
|
InheritParentConfig: false
|
||||||
|
...
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
||||||
|
---
|
||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
-bugprone-assignment-in-if-condition,
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-implicit-widening-of-multiplication-result,
|
||||||
|
-bugprone-macro-parentheses,
|
||||||
|
-bugprone-reserved-identifier,
|
||||||
|
-bugprone-sizeof-expression,
|
||||||
|
-bugprone-suspicious-include,
|
||||||
|
clang-analyzer-*,
|
||||||
|
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
|
||||||
|
clang-diagnostics-*',
|
||||||
|
performance-*,
|
||||||
|
FormatStyle: file
|
||||||
|
HeaderFilterRegex: '.*'
|
||||||
|
InheritParentConfig: false
|
||||||
|
...
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
||||||
|
---
|
||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
-bugprone-assignment-in-if-condition,
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-implicit-widening-of-multiplication-result,
|
||||||
|
-bugprone-macro-parentheses,
|
||||||
|
-bugprone-narrowing-conversions,
|
||||||
|
-bugprone-reserved-identifier,
|
||||||
|
-bugprone-switch-missing-default-case,
|
||||||
|
clang-analyzer-*,
|
||||||
|
-clang-analyzer-optin.performance.Padding,
|
||||||
|
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
|
||||||
|
clang-diagnostics-*',
|
||||||
|
performance-*,
|
||||||
|
FormatStyle: file
|
||||||
|
HeaderFilterRegex: '.*'
|
||||||
|
InheritParentConfig: false
|
||||||
|
...
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/
|
||||||
|
---
|
||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
-bugprone-assignment-in-if-condition,
|
||||||
|
-bugprone-branch-clone,
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-implicit-widening-of-multiplication-result,
|
||||||
|
-bugprone-macro-parentheses,
|
||||||
|
-bugprone-misplaced-widening-cast,
|
||||||
|
-bugprone-narrowing-conversions,
|
||||||
|
-bugprone-reserved-identifier,
|
||||||
|
-bugprone-switch-missing-default-case,
|
||||||
|
clang-analyzer-*,
|
||||||
|
-clang-analyzer-core.UndefinedBinaryOperatorResult,
|
||||||
|
-clang-analyzer-deadcode.DeadStores,
|
||||||
|
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
|
||||||
|
clang-diagnostics-*',
|
||||||
|
performance-*,
|
||||||
|
-performance-no-int-to-ptr,
|
||||||
|
FormatStyle: file
|
||||||
|
HeaderFilterRegex: '.*'
|
||||||
|
InheritParentConfig: false
|
||||||
|
...
|
||||||
Executable
+549
@@ -0,0 +1,549 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# ===- run-clang-tidy.py - Parallel clang-tidy runner --------*- python -*--===#
|
||||||
|
#
|
||||||
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
# See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
#
|
||||||
|
# ===-----------------------------------------------------------------------===#
|
||||||
|
# FIXME: Integrate with clang-tidy-diff.py
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Parallel clang-tidy runner
|
||||||
|
==========================
|
||||||
|
|
||||||
|
Runs clang-tidy over all files in a compilation database. Requires clang-tidy
|
||||||
|
and clang-apply-replacements in $PATH.
|
||||||
|
|
||||||
|
Example invocations.
|
||||||
|
- Run clang-tidy on all files in the current working directory with a default
|
||||||
|
set of checks and show warnings in the cpp files and all project headers.
|
||||||
|
run-clang-tidy.py $PWD
|
||||||
|
|
||||||
|
- Fix all header guards.
|
||||||
|
run-clang-tidy.py -fix -checks=-*,llvm-header-guard
|
||||||
|
|
||||||
|
- Fix all header guards included from clang-tidy and header guards
|
||||||
|
for clang-tidy headers.
|
||||||
|
run-clang-tidy.py -fix -checks=-*,llvm-header-guard extra/clang-tidy \
|
||||||
|
-header-filter=extra/clang-tidy
|
||||||
|
|
||||||
|
Compilation database setup:
|
||||||
|
http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import glob
|
||||||
|
import json
|
||||||
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
import queue
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import threading
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
try:
|
||||||
|
import yaml
|
||||||
|
except ImportError:
|
||||||
|
yaml = None
|
||||||
|
|
||||||
|
|
||||||
|
def strtobool(val):
|
||||||
|
"""Convert a string representation of truth to a bool following LLVM's CLI argument parsing."""
|
||||||
|
|
||||||
|
val = val.lower()
|
||||||
|
if val in ["", "true", "1"]:
|
||||||
|
return True
|
||||||
|
elif val in ["false", "0"]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Return ArgumentTypeError so that argparse does not substitute its own error message
|
||||||
|
raise argparse.ArgumentTypeError(
|
||||||
|
"'{}' is invalid value for boolean argument! Try 0 or 1.".format(val)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def find_compilation_database(path):
|
||||||
|
"""Adjusts the directory until a compilation database is found."""
|
||||||
|
result = os.path.realpath("./")
|
||||||
|
while not os.path.isfile(os.path.join(result, path)):
|
||||||
|
parent = os.path.dirname(result)
|
||||||
|
if result == parent:
|
||||||
|
print("Error: could not find compilation database.")
|
||||||
|
sys.exit(1)
|
||||||
|
result = parent
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def make_absolute(f, directory):
|
||||||
|
if os.path.isabs(f):
|
||||||
|
return f
|
||||||
|
return os.path.normpath(os.path.join(directory, f))
|
||||||
|
|
||||||
|
|
||||||
|
def get_tidy_invocation(
|
||||||
|
f,
|
||||||
|
clang_tidy_binary,
|
||||||
|
checks,
|
||||||
|
tmpdir,
|
||||||
|
build_path,
|
||||||
|
header_filter,
|
||||||
|
allow_enabling_alpha_checkers,
|
||||||
|
extra_arg,
|
||||||
|
extra_arg_before,
|
||||||
|
quiet,
|
||||||
|
config_file_path,
|
||||||
|
config,
|
||||||
|
line_filter,
|
||||||
|
use_color,
|
||||||
|
plugins,
|
||||||
|
warnings_as_errors,
|
||||||
|
):
|
||||||
|
"""Gets a command line for clang-tidy."""
|
||||||
|
start = [clang_tidy_binary]
|
||||||
|
if allow_enabling_alpha_checkers:
|
||||||
|
start.append("-allow-enabling-analyzer-alpha-checkers")
|
||||||
|
if header_filter is not None:
|
||||||
|
start.append("-header-filter=" + header_filter)
|
||||||
|
if line_filter is not None:
|
||||||
|
start.append("-line-filter=" + line_filter)
|
||||||
|
if use_color is not None:
|
||||||
|
if use_color:
|
||||||
|
start.append("--use-color")
|
||||||
|
else:
|
||||||
|
start.append("--use-color=false")
|
||||||
|
if checks:
|
||||||
|
start.append("-checks=" + checks)
|
||||||
|
if tmpdir is not None:
|
||||||
|
start.append("-export-fixes")
|
||||||
|
# Get a temporary file. We immediately close the handle so clang-tidy can
|
||||||
|
# overwrite it.
|
||||||
|
(handle, name) = tempfile.mkstemp(suffix=".yaml", dir=tmpdir)
|
||||||
|
os.close(handle)
|
||||||
|
start.append(name)
|
||||||
|
for arg in extra_arg:
|
||||||
|
start.append("-extra-arg=%s" % arg)
|
||||||
|
for arg in extra_arg_before:
|
||||||
|
start.append("-extra-arg-before=%s" % arg)
|
||||||
|
start.append("-p=" + build_path)
|
||||||
|
if quiet:
|
||||||
|
start.append("-quiet")
|
||||||
|
if config_file_path:
|
||||||
|
start.append("--config-file=" + config_file_path)
|
||||||
|
elif config:
|
||||||
|
start.append("-config=" + config)
|
||||||
|
for plugin in plugins:
|
||||||
|
start.append("-load=" + plugin)
|
||||||
|
if warnings_as_errors:
|
||||||
|
start.append("--warnings-as-errors=" + warnings_as_errors)
|
||||||
|
start.append(f)
|
||||||
|
return start
|
||||||
|
|
||||||
|
|
||||||
|
def merge_replacement_files(tmpdir, mergefile):
|
||||||
|
"""Merge all replacement files in a directory into a single file"""
|
||||||
|
# The fixes suggested by clang-tidy >= 4.0.0 are given under
|
||||||
|
# the top level key 'Diagnostics' in the output yaml files
|
||||||
|
mergekey = "Diagnostics"
|
||||||
|
merged = []
|
||||||
|
for replacefile in glob.iglob(os.path.join(tmpdir, "*.yaml")):
|
||||||
|
content = yaml.safe_load(open(replacefile, "r"))
|
||||||
|
if not content:
|
||||||
|
continue # Skip empty files.
|
||||||
|
merged.extend(content.get(mergekey, []))
|
||||||
|
|
||||||
|
if merged:
|
||||||
|
# MainSourceFile: The key is required by the definition inside
|
||||||
|
# include/clang/Tooling/ReplacementsYaml.h, but the value
|
||||||
|
# is actually never used inside clang-apply-replacements,
|
||||||
|
# so we set it to '' here.
|
||||||
|
output = {"MainSourceFile": "", mergekey: merged}
|
||||||
|
with open(mergefile, "w") as out:
|
||||||
|
yaml.safe_dump(output, out)
|
||||||
|
else:
|
||||||
|
# Empty the file:
|
||||||
|
open(mergefile, "w").close()
|
||||||
|
|
||||||
|
|
||||||
|
def find_binary(arg, name, build_path):
|
||||||
|
"""Get the path for a binary or exit"""
|
||||||
|
if arg:
|
||||||
|
if shutil.which(arg):
|
||||||
|
return arg
|
||||||
|
else:
|
||||||
|
raise SystemExit(
|
||||||
|
"error: passed binary '{}' was not found or is not executable".format(
|
||||||
|
arg
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
built_path = os.path.join(build_path, "bin", name)
|
||||||
|
binary = shutil.which(name) or shutil.which(built_path)
|
||||||
|
if binary:
|
||||||
|
return binary
|
||||||
|
else:
|
||||||
|
raise SystemExit(
|
||||||
|
"error: failed to find {} in $PATH or at {}".format(name, built_path)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_fixes(args, clang_apply_replacements_binary, tmpdir):
|
||||||
|
"""Calls clang-apply-fixes on a given directory."""
|
||||||
|
invocation = [clang_apply_replacements_binary]
|
||||||
|
invocation.append("-ignore-insert-conflict")
|
||||||
|
if args.format:
|
||||||
|
invocation.append("-format")
|
||||||
|
if args.style:
|
||||||
|
invocation.append("-style=" + args.style)
|
||||||
|
invocation.append(tmpdir)
|
||||||
|
subprocess.call(invocation)
|
||||||
|
|
||||||
|
|
||||||
|
def run_tidy(args, clang_tidy_binary, tmpdir, build_path, queue, lock, failed_files):
|
||||||
|
"""Takes filenames out of queue and runs clang-tidy on them."""
|
||||||
|
while True:
|
||||||
|
name = queue.get()
|
||||||
|
invocation = get_tidy_invocation(
|
||||||
|
name,
|
||||||
|
clang_tidy_binary,
|
||||||
|
args.checks,
|
||||||
|
tmpdir,
|
||||||
|
build_path,
|
||||||
|
args.header_filter,
|
||||||
|
args.allow_enabling_alpha_checkers,
|
||||||
|
args.extra_arg,
|
||||||
|
args.extra_arg_before,
|
||||||
|
args.quiet,
|
||||||
|
args.config_file,
|
||||||
|
args.config,
|
||||||
|
args.line_filter,
|
||||||
|
args.use_color,
|
||||||
|
args.plugins,
|
||||||
|
args.warnings_as_errors,
|
||||||
|
)
|
||||||
|
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||||
|
)
|
||||||
|
output, err = proc.communicate()
|
||||||
|
if proc.returncode != 0:
|
||||||
|
if proc.returncode < 0:
|
||||||
|
msg = "%s: terminated by signal %d\n" % (name, -proc.returncode)
|
||||||
|
err += msg.encode("utf-8")
|
||||||
|
failed_files.append(name)
|
||||||
|
with lock:
|
||||||
|
sys.stdout.write(" ".join(invocation) + "\n" + output.decode("utf-8"))
|
||||||
|
if len(err) > 0:
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stderr.write(err.decode("utf-8"))
|
||||||
|
queue.task_done()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Runs clang-tidy over all files "
|
||||||
|
"in a compilation database. Requires "
|
||||||
|
"clang-tidy and clang-apply-replacements in "
|
||||||
|
"$PATH or in your build directory."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-allow-enabling-alpha-checkers",
|
||||||
|
action="store_true",
|
||||||
|
help="allow alpha checkers from clang-analyzer.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-clang-tidy-binary", metavar="PATH", help="path to clang-tidy binary"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-clang-apply-replacements-binary",
|
||||||
|
metavar="PATH",
|
||||||
|
help="path to clang-apply-replacements binary",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-checks",
|
||||||
|
default=None,
|
||||||
|
help="checks filter, when not specified, use clang-tidy default",
|
||||||
|
)
|
||||||
|
config_group = parser.add_mutually_exclusive_group()
|
||||||
|
config_group.add_argument(
|
||||||
|
"-config",
|
||||||
|
default=None,
|
||||||
|
help="Specifies a configuration in YAML/JSON format: "
|
||||||
|
" -config=\"{Checks: '*', "
|
||||||
|
' CheckOptions: {x: y}}" '
|
||||||
|
"When the value is empty, clang-tidy will "
|
||||||
|
"attempt to find a file named .clang-tidy for "
|
||||||
|
"each source file in its parent directories.",
|
||||||
|
)
|
||||||
|
config_group.add_argument(
|
||||||
|
"-config-file",
|
||||||
|
default=None,
|
||||||
|
help="Specify the path of .clang-tidy or custom config "
|
||||||
|
"file: e.g. -config-file=/some/path/myTidyConfigFile. "
|
||||||
|
"This option internally works exactly the same way as "
|
||||||
|
"-config option after reading specified config file. "
|
||||||
|
"Use either -config-file or -config, not both.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-header-filter",
|
||||||
|
default=None,
|
||||||
|
help="regular expression matching the names of the "
|
||||||
|
"headers to output diagnostics from. Diagnostics from "
|
||||||
|
"the main file of each translation unit are always "
|
||||||
|
"displayed.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-line-filter",
|
||||||
|
default=None,
|
||||||
|
help="List of files with line ranges to filter the warnings.",
|
||||||
|
)
|
||||||
|
if yaml:
|
||||||
|
parser.add_argument(
|
||||||
|
"-export-fixes",
|
||||||
|
metavar="file_or_directory",
|
||||||
|
dest="export_fixes",
|
||||||
|
help="A directory or a yaml file to store suggested fixes in, "
|
||||||
|
"which can be applied with clang-apply-replacements. If the "
|
||||||
|
"parameter is a directory, the fixes of each compilation unit are "
|
||||||
|
"stored in individual yaml files in the directory.",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
parser.add_argument(
|
||||||
|
"-export-fixes",
|
||||||
|
metavar="directory",
|
||||||
|
dest="export_fixes",
|
||||||
|
help="A directory to store suggested fixes in, which can be applied "
|
||||||
|
"with clang-apply-replacements. The fixes of each compilation unit are "
|
||||||
|
"stored in individual yaml files in the directory.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-j",
|
||||||
|
type=int,
|
||||||
|
default=0,
|
||||||
|
help="number of tidy instances to be run in parallel.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"files", nargs="*", default=[".*"], help="files to be processed (regex on path)"
|
||||||
|
)
|
||||||
|
parser.add_argument("-fix", action="store_true", help="apply fix-its")
|
||||||
|
parser.add_argument(
|
||||||
|
"-format", action="store_true", help="Reformat code after applying fixes"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-style",
|
||||||
|
default="file",
|
||||||
|
help="The style of reformat code after applying fixes",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-use-color",
|
||||||
|
type=strtobool,
|
||||||
|
nargs="?",
|
||||||
|
const=True,
|
||||||
|
help="Use colors in diagnostics, overriding clang-tidy's"
|
||||||
|
" default behavior. This option overrides the 'UseColor"
|
||||||
|
"' option in .clang-tidy file, if any.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-p", dest="build_path", help="Path used to read a compile command database."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-extra-arg",
|
||||||
|
dest="extra_arg",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Additional argument to append to the compiler command line.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-extra-arg-before",
|
||||||
|
dest="extra_arg_before",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Additional argument to prepend to the compiler command line.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-quiet", action="store_true", help="Run clang-tidy in quiet mode"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-load",
|
||||||
|
dest="plugins",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Load the specified plugin in clang-tidy.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-warnings-as-errors",
|
||||||
|
default=None,
|
||||||
|
help="Upgrades warnings to errors. Same format as '-checks'",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
db_path = "compile_commands.json"
|
||||||
|
|
||||||
|
if args.build_path is not None:
|
||||||
|
build_path = args.build_path
|
||||||
|
else:
|
||||||
|
# Find our database
|
||||||
|
build_path = find_compilation_database(db_path)
|
||||||
|
|
||||||
|
clang_tidy_binary = find_binary(args.clang_tidy_binary, "clang-tidy", build_path)
|
||||||
|
|
||||||
|
if args.fix:
|
||||||
|
clang_apply_replacements_binary = find_binary(
|
||||||
|
args.clang_apply_replacements_binary, "clang-apply-replacements", build_path
|
||||||
|
)
|
||||||
|
|
||||||
|
combine_fixes = False
|
||||||
|
export_fixes_dir = None
|
||||||
|
delete_fixes_dir = False
|
||||||
|
if args.export_fixes is not None:
|
||||||
|
# if a directory is given, create it if it does not exist
|
||||||
|
if args.export_fixes.endswith(os.path.sep) and not os.path.isdir(
|
||||||
|
args.export_fixes
|
||||||
|
):
|
||||||
|
os.makedirs(args.export_fixes)
|
||||||
|
|
||||||
|
if not os.path.isdir(args.export_fixes):
|
||||||
|
if not yaml:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Cannot combine fixes in one yaml file. Either install PyYAML or specify an output directory."
|
||||||
|
)
|
||||||
|
|
||||||
|
combine_fixes = True
|
||||||
|
|
||||||
|
if os.path.isdir(args.export_fixes):
|
||||||
|
export_fixes_dir = args.export_fixes
|
||||||
|
|
||||||
|
if export_fixes_dir is None and (args.fix or combine_fixes):
|
||||||
|
export_fixes_dir = tempfile.mkdtemp()
|
||||||
|
delete_fixes_dir = True
|
||||||
|
|
||||||
|
# Load the database and extract all files.
|
||||||
|
database = json.load(open(os.path.join(build_path, db_path)))
|
||||||
|
files = set(
|
||||||
|
[make_absolute(entry["file"], entry["directory"]) for entry in database]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Build up a big regexy filter from all command line arguments.
|
||||||
|
file_name_re = re.compile("|".join(args.files))
|
||||||
|
|
||||||
|
# filter files with mo.group(0), and sort files
|
||||||
|
matched_files = []
|
||||||
|
for name in files:
|
||||||
|
mo = file_name_re.search(name)
|
||||||
|
if mo and mo.group(0):
|
||||||
|
matched_files.append(name)
|
||||||
|
files = sorted(matched_files)
|
||||||
|
if not files:
|
||||||
|
if delete_fixes_dir:
|
||||||
|
shutil.rmtree(export_fixes_dir)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
try:
|
||||||
|
invocation = get_tidy_invocation(
|
||||||
|
"",
|
||||||
|
clang_tidy_binary,
|
||||||
|
args.checks,
|
||||||
|
None,
|
||||||
|
build_path,
|
||||||
|
args.header_filter,
|
||||||
|
args.allow_enabling_alpha_checkers,
|
||||||
|
args.extra_arg,
|
||||||
|
args.extra_arg_before,
|
||||||
|
args.quiet,
|
||||||
|
args.config_file,
|
||||||
|
args.config,
|
||||||
|
args.line_filter,
|
||||||
|
args.use_color,
|
||||||
|
args.plugins,
|
||||||
|
args.warnings_as_errors,
|
||||||
|
)
|
||||||
|
invocation.append("-list-checks")
|
||||||
|
invocation.append("-")
|
||||||
|
if args.quiet:
|
||||||
|
# Even with -quiet we still want to check if we can call clang-tidy.
|
||||||
|
with open(os.devnull, "w") as dev_null:
|
||||||
|
subprocess.check_call(invocation, stdout=dev_null)
|
||||||
|
else:
|
||||||
|
subprocess.check_call(invocation)
|
||||||
|
except:
|
||||||
|
print("Unable to run clang-tidy.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
max_task = args.j
|
||||||
|
if max_task == 0:
|
||||||
|
max_task = multiprocessing.cpu_count()
|
||||||
|
|
||||||
|
return_code = 0
|
||||||
|
try:
|
||||||
|
# Spin up a bunch of tidy-launching threads.
|
||||||
|
task_queue = queue.Queue(max_task)
|
||||||
|
# List of files with a non-zero return code.
|
||||||
|
failed_files = []
|
||||||
|
lock = threading.Lock()
|
||||||
|
for _ in range(max_task):
|
||||||
|
t = threading.Thread(
|
||||||
|
target=run_tidy,
|
||||||
|
args=(
|
||||||
|
args,
|
||||||
|
clang_tidy_binary,
|
||||||
|
export_fixes_dir,
|
||||||
|
build_path,
|
||||||
|
task_queue,
|
||||||
|
lock,
|
||||||
|
failed_files,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
# Fill the queue with files.
|
||||||
|
for name in files:
|
||||||
|
if file_name_re.search(name):
|
||||||
|
task_queue.put(name)
|
||||||
|
|
||||||
|
# Wait for all threads to be done.
|
||||||
|
task_queue.join()
|
||||||
|
if len(failed_files):
|
||||||
|
return_code = 1
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
# This is a sad hack. Unfortunately subprocess goes
|
||||||
|
# bonkers with ctrl-c and we start forking merrily.
|
||||||
|
print("\nCtrl-C detected, goodbye.")
|
||||||
|
if delete_fixes_dir:
|
||||||
|
shutil.rmtree(export_fixes_dir)
|
||||||
|
os.kill(0, 9)
|
||||||
|
|
||||||
|
if combine_fixes:
|
||||||
|
print("Writing fixes to " + args.export_fixes + " ...")
|
||||||
|
try:
|
||||||
|
merge_replacement_files(export_fixes_dir, args.export_fixes)
|
||||||
|
except:
|
||||||
|
print("Error exporting fixes.\n", file=sys.stderr)
|
||||||
|
traceback.print_exc()
|
||||||
|
return_code = 1
|
||||||
|
|
||||||
|
if args.fix:
|
||||||
|
print("Applying fixes ...")
|
||||||
|
try:
|
||||||
|
apply_fixes(args, clang_apply_replacements_binary, export_fixes_dir)
|
||||||
|
except:
|
||||||
|
print("Error applying fixes.\n", file=sys.stderr)
|
||||||
|
traceback.print_exc()
|
||||||
|
return_code = 1
|
||||||
|
|
||||||
|
if delete_fixes_dir:
|
||||||
|
shutil.rmtree(export_fixes_dir)
|
||||||
|
sys.exit(return_code)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
#
|
||||||
|
# UPX "CMake" build file; see https://cmake.org/
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
#
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# macros
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# support config hooks; developer convenience
|
||||||
|
macro(upx_cmake_include_hook section)
|
||||||
|
include("${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/hooks/CMakeLists.${section}.txt" OPTIONAL)
|
||||||
|
include("${CMAKE_CURRENT_SOURCE_DIR}/maint/make/CMakeLists.${section}.txt" OPTIONAL)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Disallow in-source build. Note that you will still have to manually
|
||||||
|
# clean up a few files if you accidentally try an in-source build.
|
||||||
|
macro(upx_disallow_in_source_build)
|
||||||
|
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
|
||||||
|
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
|
||||||
|
if(",${CMAKE_CURRENT_SOURCE_DIR}," STREQUAL ",${CMAKE_CURRENT_BINARY_DIR},")
|
||||||
|
# try to clean up (does not work)
|
||||||
|
#file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/CMakeCache.txt")
|
||||||
|
#file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/cmake.check_cache")
|
||||||
|
message(FATAL_ERROR "ERROR: In-source builds are not allowed, please use an extra build dir.")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# set the default build type; must be called before project() cmake init
|
||||||
|
macro(upx_default_build_type type)
|
||||||
|
set(upx_global_default_build_type "${type}")
|
||||||
|
get_property(upx_global_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||||
|
if(NOT upx_global_is_multi_config AND NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE "${upx_global_default_build_type}" CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# set the default multi-config build type; must be called after project() cmake init
|
||||||
|
macro(upx_apply_build_type)
|
||||||
|
if(upx_global_is_multi_config)
|
||||||
|
set(c "${CMAKE_CONFIGURATION_TYPES}")
|
||||||
|
list(INSERT c 0 "${upx_global_default_build_type}")
|
||||||
|
if(CMAKE_BUILD_TYPE)
|
||||||
|
list(INSERT c 0 "${CMAKE_BUILD_TYPE}")
|
||||||
|
endif()
|
||||||
|
list(REMOVE_DUPLICATES c)
|
||||||
|
set(CMAKE_CONFIGURATION_TYPES "${c}" CACHE STRING "List of supported configuration types." FORCE)
|
||||||
|
endif()
|
||||||
|
# now also set the build type for use in try_compile()
|
||||||
|
if(NOT CMAKE_TRY_COMPILE_CONFIGURATION)
|
||||||
|
if(CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_TRY_COMPILE_CONFIGURATION "${CMAKE_BUILD_TYPE}")
|
||||||
|
else()
|
||||||
|
set(CMAKE_TRY_COMPILE_CONFIGURATION "${upx_global_default_build_type}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# util
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
function(upx_print_var) # ARGV
|
||||||
|
foreach(var_name ${ARGV})
|
||||||
|
if(DEFINED ${var_name})
|
||||||
|
if(NOT ",${${var_name}}," STREQUAL ",,")
|
||||||
|
if(${var_name})
|
||||||
|
message(STATUS "${var_name} = ${${var_name}}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(upx_print_have_symbol) # ARGV; needs include(CheckSymbolExists)
|
||||||
|
foreach(symbol ${ARGV})
|
||||||
|
set(cache_var_name "HAVE_symbol_${symbol}")
|
||||||
|
check_symbol_exists(${symbol} "limits.h;stddef.h;stdint.h" ${cache_var_name})
|
||||||
|
if(${cache_var_name})
|
||||||
|
message(STATUS "HAVE ${symbol}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# examine MinGW/Cygwin compiler configuration
|
||||||
|
function(upx_print_mingw_symbols)
|
||||||
|
if(WIN32 OR MINGW OR CYGWIN)
|
||||||
|
if(CMAKE_C_COMPILER_ID MATCHES "(Clang|GNU)")
|
||||||
|
# runtime library: msvcrt vs ucrt vs cygwin
|
||||||
|
upx_print_have_symbol(__CRTDLL__ __CYGWIN__ __CYGWIN32__ __CYGWIN64__ __MINGW32__ __MINGW64__ __MINGW64_VERSION_MAJOR __MSVCRT__ _UCRT _WIN32 _WIN64)
|
||||||
|
# exception handing: SJLJ (setjmp/longjmp) vs DWARF vs SEH
|
||||||
|
upx_print_have_symbol(__GCC_HAVE_DWARF2_CFI_ASM __SEH__ __USING_SJLJ_EXCEPTIONS__)
|
||||||
|
# threads: win32 vs posix/pthread/winpthreads vs mcfgthread
|
||||||
|
upx_print_have_symbol(_REENTRANT __USING_MCFGTHREAD__)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# add wildcard expansions to a variable
|
||||||
|
function(upx_add_glob_files) # ARGV
|
||||||
|
set(var_name ${ARGV0})
|
||||||
|
list(REMOVE_AT ARGV 0)
|
||||||
|
file(GLOB files ${ARGV})
|
||||||
|
set(result "")
|
||||||
|
if(DEFINED ${var_name})
|
||||||
|
set(result "${${var_name}}")
|
||||||
|
endif()
|
||||||
|
list(APPEND result "${files}")
|
||||||
|
list(SORT result)
|
||||||
|
list(REMOVE_DUPLICATES result)
|
||||||
|
##message(STATUS "upx_add_glob_files: ${var_name} = ${result}")
|
||||||
|
set(${var_name} "${result}" PARENT_SCOPE) # return value
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# useful for CI jobs: allow settings via environment and cache result
|
||||||
|
function(upx_cache_bool_vars) # ARGV
|
||||||
|
set(default_value "${ARGV0}")
|
||||||
|
list(REMOVE_AT ARGV 0)
|
||||||
|
foreach(var_name ${ARGV})
|
||||||
|
set(value ${default_value})
|
||||||
|
if(DEFINED UPX_CACHE_VALUE_${var_name}) # check cache
|
||||||
|
set(value "${UPX_CACHE_VALUE_${var_name}}")
|
||||||
|
elseif(DEFINED ${var_name}) # defined via "cmake -DXXX=YYY"
|
||||||
|
set(value "${${var_name}}")
|
||||||
|
elseif(DEFINED ENV{${var_name}})
|
||||||
|
if("$ENV{${var_name}}" MATCHES "^(0|1|OFF|ON|FALSE|TRUE)$") # check environment
|
||||||
|
set(value "$ENV{${var_name}}")
|
||||||
|
set(UPX_CACHE_ORIGIN_FROM_ENV_${var_name} TRUE CACHE INTERNAL "" FORCE) # for info below
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
# convert to bool
|
||||||
|
if(value)
|
||||||
|
set(value ON)
|
||||||
|
else()
|
||||||
|
set(value OFF)
|
||||||
|
endif()
|
||||||
|
# store result
|
||||||
|
if(UPX_CACHE_ORIGIN_FROM_ENV_${var_name})
|
||||||
|
message(STATUS "setting from environment: ${var_name} = ${value}")
|
||||||
|
endif()
|
||||||
|
set(${var_name} "${value}" PARENT_SCOPE) # store result
|
||||||
|
set(UPX_CACHE_VALUE_${var_name} "${value}" CACHE INTERNAL "" FORCE) # and store in cache
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# compilation flags
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
function(upx_internal_add_definitions_with_prefix) # ARGV; needs include(CheckCCompilerFlag)
|
||||||
|
set(flag_prefix "${ARGV0}")
|
||||||
|
if(flag_prefix MATCHES "^empty$") # need "empty" to work around bug in old CMake versions
|
||||||
|
set(flag_prefix "")
|
||||||
|
endif()
|
||||||
|
list(REMOVE_AT ARGV 0)
|
||||||
|
set(failed "")
|
||||||
|
foreach(f ${ARGV})
|
||||||
|
set(flag "${flag_prefix}${f}")
|
||||||
|
string(REGEX REPLACE "[^0-9a-zA-Z_]" "_" cache_var_name "HAVE_CFLAG_${flag}")
|
||||||
|
check_c_compiler_flag("${flag}" ${cache_var_name})
|
||||||
|
if(${cache_var_name})
|
||||||
|
#message(STATUS "add_definitions: ${flag}")
|
||||||
|
add_definitions("${flag}")
|
||||||
|
else()
|
||||||
|
list(APPEND failed "${f}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
set(failed_flags "${failed}" PARENT_SCOPE) # return value
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(upx_add_definitions) # ARGV; needs include(CheckCCompilerFlag)
|
||||||
|
set(failed_flags "")
|
||||||
|
if(MSVC_FRONTEND AND CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
|
# for clang-cl try "-clang:" flag prefix first
|
||||||
|
upx_internal_add_definitions_with_prefix("-clang:" ${ARGV})
|
||||||
|
upx_internal_add_definitions_with_prefix("empty" ${failed_flags})
|
||||||
|
else()
|
||||||
|
upx_internal_add_definitions_with_prefix("empty" ${ARGV})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# compile a target with -O2 optimization even in Debug build
|
||||||
|
function(upx_compile_target_debug_with_O2) # ARGV
|
||||||
|
foreach(t ${ARGV})
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
# MSVC uses some Debug compilation options like -RTC1 that are incompatible with -O2
|
||||||
|
else()
|
||||||
|
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-O2>)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# compile a source file with -O2 optimization even in Debug build; messy because of CMake limitations
|
||||||
|
function(upx_compile_source_debug_with_O2) # ARGV
|
||||||
|
set(flags "$<$<CONFIG:Debug>:-O2>")
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.8")
|
||||||
|
# 3.8: The COMPILE_FLAGS source file property learned to support generator expressions
|
||||||
|
if(upx_global_is_multi_config OR NOT CMAKE_BUILD_TYPE MATCHES "^Debug$")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(flags "-O2")
|
||||||
|
endif()
|
||||||
|
if(CMAKE_GENERATOR MATCHES "Xcode") # multi-config
|
||||||
|
# NOTE: Xcode does not support per-config per-source COMPILE_FLAGS (as of CMake 3.27.7)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
foreach(source ${ARGV})
|
||||||
|
if(MSVC_FRONTEND)
|
||||||
|
# MSVC uses some Debug compilation options like -RTC1 that are incompatible with -O2
|
||||||
|
else()
|
||||||
|
get_source_file_property(prop "${source}" COMPILE_FLAGS)
|
||||||
|
if(prop MATCHES "^(NOTFOUND)?$")
|
||||||
|
set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}")
|
||||||
|
else()
|
||||||
|
set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${prop} ${flags}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# sanitize a target: this needs proper support from your compiler AND toolchain
|
||||||
|
function(upx_sanitize_target) # ARGV
|
||||||
|
foreach(t ${ARGV})
|
||||||
|
if(UPX_CONFIG_DISABLE_SANITIZE)
|
||||||
|
# no-op
|
||||||
|
elseif(MSVC_FRONTEND)
|
||||||
|
# MSVC uses -GS (similar to -fstack-protector) by default
|
||||||
|
elseif(MINGW OR CYGWIN)
|
||||||
|
# avoid link errors with current MinGW-w64 versions
|
||||||
|
# see https://www.mingw-w64.org/contribute/#sanitizers-asan-tsan-usan
|
||||||
|
elseif(CMAKE_C_COMPILER_ID MATCHES "^GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "8.0")
|
||||||
|
# unsupported compiler; unreliable/broken sanitize implementation
|
||||||
|
else()
|
||||||
|
# default sanitizer for Debug builds
|
||||||
|
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-fsanitize=undefined -fsanitize-undefined-trap-on-error -fstack-protector-all>)
|
||||||
|
# default sanitizer for Release builds
|
||||||
|
target_compile_options(${t} PRIVATE $<$<CONFIG:MinSizeRel>:-fstack-protector>)
|
||||||
|
target_compile_options(${t} PRIVATE $<$<CONFIG:Release>:-fstack-protector>)
|
||||||
|
target_compile_options(${t} PRIVATE $<$<CONFIG:RelWithDebInfo>:-fstack-protector>)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# test
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
function(upx_add_serial_test) # ARGV
|
||||||
|
set(name "${ARGV0}")
|
||||||
|
list(REMOVE_AT ARGV 0)
|
||||||
|
add_test(NAME "${name}" COMMAND ${ARGV})
|
||||||
|
set_tests_properties("${name}" PROPERTIES RUN_SERIAL TRUE) # run these tests sequentially
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# vim:set ft=cmake ts=4 sw=4 tw=0 et:
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
static std::mutex lock_mutex;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::lock_guard<std::mutex> lock(lock_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,286 @@
|
|||||||
|
#
|
||||||
|
# UPX top-level Makefile - needs GNU make and CMake >= 3.13
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
#
|
||||||
|
|
||||||
|
ifeq ($(UPX_MAKEFILE_EXTRA_MK_INCLUDED),)
|
||||||
|
override UPX_MAKEFILE_EXTRA_MK_INCLUDED := 1
|
||||||
|
|
||||||
|
override check_defined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),$(error ERROR: variable '$1' is not defined),))
|
||||||
|
override check_undefined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),,$(error ERROR: variable '$1' is already defined)))
|
||||||
|
$(call check_defined,run_config run_build)
|
||||||
|
$(call check_undefined,run_config_and_build)
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# extra builds: some pre-defined build configurations
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
define run_config_and_build
|
||||||
|
$(call run_config,$1,$2)
|
||||||
|
$(call run_build,$1,$2)
|
||||||
|
endef
|
||||||
|
|
||||||
|
# force building with clang/clang++
|
||||||
|
build/extra/clang/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang/%: export CC = clang
|
||||||
|
build/extra/clang/%: export CXX = clang++
|
||||||
|
|
||||||
|
# force building with clang/clang++ -m32
|
||||||
|
build/extra/clang-m32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang-m32/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang-m32/%: export CC = clang -m32
|
||||||
|
build/extra/clang-m32/%: export CXX = clang++ -m32
|
||||||
|
|
||||||
|
# force building with clang/clang++ -mx32
|
||||||
|
build/extra/clang-mx32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang-mx32/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang-mx32/%: export CC = clang -mx32
|
||||||
|
build/extra/clang-mx32/%: export CXX = clang++ -mx32
|
||||||
|
|
||||||
|
# force building with clang/clang++ -m64
|
||||||
|
build/extra/clang-m64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang-m64/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang-m64/%: export CC = clang -m64
|
||||||
|
build/extra/clang-m64/%: export CXX = clang++ -m64
|
||||||
|
|
||||||
|
# force building with clang/clang++ -static
|
||||||
|
build/extra/clang-static/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang-static/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang-static/%: export CC = clang -static
|
||||||
|
build/extra/clang-static/%: export CXX = clang++ -static
|
||||||
|
|
||||||
|
# force building with clang/clang++ -static -flto
|
||||||
|
build/extra/clang-static-lto/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang-static-lto/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang-static-lto/%: export CC = clang -static -flto
|
||||||
|
build/extra/clang-static-lto/%: export CXX = clang++ -static -flto
|
||||||
|
|
||||||
|
# force building with clang/clang++ C17/C++20
|
||||||
|
build/extra/clang-std-cxx20/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang-std-cxx20/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang-std-cxx20/%: export CC = clang -std=gnu17
|
||||||
|
build/extra/clang-std-cxx20/%: export CXX = clang++ -std=gnu++20
|
||||||
|
build/extra/clang-std-cxx20/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||||
|
build/extra/clang-std-cxx20/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||||
|
|
||||||
|
# force building with clang/clang++ C23/C++23
|
||||||
|
build/extra/clang-std-cxx23/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/clang-std-cxx23/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/clang-std-cxx23/%: export CC = clang -std=gnu2x
|
||||||
|
build/extra/clang-std-cxx23/%: export CXX = clang++ -std=gnu++2b
|
||||||
|
build/extra/clang-std-cxx23/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||||
|
build/extra/clang-std-cxx23/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||||
|
|
||||||
|
# force building with gcc/g++
|
||||||
|
build/extra/gcc/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc/%: export CC = gcc
|
||||||
|
build/extra/gcc/%: export CXX = g++
|
||||||
|
|
||||||
|
# force building with gcc/g++ -m32
|
||||||
|
build/extra/gcc-m32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc-m32/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc-m32/%: export CC = gcc -m32
|
||||||
|
build/extra/gcc-m32/%: export CXX = g++ -m32
|
||||||
|
|
||||||
|
# force building with gcc/g++ -mx32
|
||||||
|
build/extra/gcc-mx32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc-mx32/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc-mx32/%: export CC = gcc -mx32
|
||||||
|
build/extra/gcc-mx32/%: export CXX = g++ -mx32
|
||||||
|
|
||||||
|
# force building with gcc/g++ -m64
|
||||||
|
build/extra/gcc-m64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc-m64/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc-m64/%: export CC = gcc -m64
|
||||||
|
build/extra/gcc-m64/%: export CXX = g++ -m64
|
||||||
|
|
||||||
|
# force building with gcc/g++ -static
|
||||||
|
build/extra/gcc-static/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc-static/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc-static/%: export CC = gcc -static
|
||||||
|
build/extra/gcc-static/%: export CXX = g++ -static
|
||||||
|
|
||||||
|
# force building with gcc/g++ -static -flto
|
||||||
|
build/extra/gcc-static-lto/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc-static-lto/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc-static-lto/%: export CC = gcc -static -flto
|
||||||
|
build/extra/gcc-static-lto/%: export CXX = g++ -static -flto
|
||||||
|
|
||||||
|
# force building with gcc/g++ C17/C++20
|
||||||
|
build/extra/gcc-std-cxx20/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc-std-cxx20/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc-std-cxx20/%: export CC = gcc -std=gnu17
|
||||||
|
build/extra/gcc-std-cxx20/%: export CXX = g++ -std=gnu++20
|
||||||
|
build/extra/gcc-std-cxx20/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||||
|
build/extra/gcc-std-cxx20/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||||
|
|
||||||
|
# force building with gcc/g++ C23/C++23
|
||||||
|
build/extra/gcc-std-cxx23/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/gcc-std-cxx23/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/gcc-std-cxx23/%: export CC = gcc -std=gnu2x
|
||||||
|
build/extra/gcc-std-cxx23/%: export CXX = g++ -std=gnu++2b
|
||||||
|
build/extra/gcc-std-cxx23/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||||
|
build/extra/gcc-std-cxx23/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||||
|
|
||||||
|
# cross compiler: Linux glibc aarch64-linux-gnu (arm64)
|
||||||
|
build/extra/cross-linux-gnu-aarch64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/cross-linux-gnu-aarch64/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/cross-linux-gnu-aarch64/%: export CC = aarch64-linux-gnu-gcc
|
||||||
|
build/extra/cross-linux-gnu-aarch64/%: export CXX = aarch64-linux-gnu-g++
|
||||||
|
build/extra/cross-linux-gnu-aarch64/%: CMAKE_SYSTEM_NAME ?= Linux
|
||||||
|
build/extra/cross-linux-gnu-aarch64/%: CMAKE_CROSSCOMPILING_EMULATOR ?= qemu-aarch64
|
||||||
|
|
||||||
|
# cross compiler: Linux glibc arm-linux-gnueabihf
|
||||||
|
build/extra/cross-linux-gnu-arm-eabihf/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/cross-linux-gnu-arm-eabihf/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/cross-linux-gnu-arm-eabihf/%: export CC = arm-linux-gnueabihf-gcc
|
||||||
|
build/extra/cross-linux-gnu-arm-eabihf/%: export CXX = arm-linux-gnueabihf-g++ -Wno-psabi
|
||||||
|
build/extra/cross-linux-gnu-arm-eabihf/%: CMAKE_SYSTEM_NAME ?= Linux
|
||||||
|
build/extra/cross-linux-gnu-arm-eabihf/%: CMAKE_CROSSCOMPILING_EMULATOR ?= qemu-arm
|
||||||
|
|
||||||
|
# cross compiler: Windows x86 win32 MinGW (i386)
|
||||||
|
build/extra/cross-windows-mingw32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/cross-windows-mingw32/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/cross-windows-mingw32/%: export CC = i686-w64-mingw32-gcc -static -D_WIN32_WINNT=0x0400
|
||||||
|
build/extra/cross-windows-mingw32/%: export CXX = i686-w64-mingw32-g++ -static -D_WIN32_WINNT=0x0400
|
||||||
|
build/extra/cross-windows-mingw32/%: CMAKE_SYSTEM_NAME ?= Windows
|
||||||
|
build/extra/cross-windows-mingw32/%: CMAKE_CROSSCOMPILING_EMULATOR ?= wine
|
||||||
|
|
||||||
|
# cross compiler: Windows x64 win64 MinGW (amd64)
|
||||||
|
build/extra/cross-windows-mingw64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/cross-windows-mingw64/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/cross-windows-mingw64/%: export CC = x86_64-w64-mingw32-gcc -static -D_WIN32_WINNT=0x0400
|
||||||
|
build/extra/cross-windows-mingw64/%: export CXX = x86_64-w64-mingw32-g++ -static -D_WIN32_WINNT=0x0400
|
||||||
|
build/extra/cross-windows-mingw64/%: CMAKE_SYSTEM_NAME ?= Windows
|
||||||
|
build/extra/cross-windows-mingw64/%: CMAKE_CROSSCOMPILING_EMULATOR ?= wine64
|
||||||
|
|
||||||
|
# cross compiler: macOS arm64 (aarch64)
|
||||||
|
build/extra/cross-darwin-arm64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/cross-darwin-arm64/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/cross-darwin-arm64/%: export CC = clang -target arm64-apple-darwin
|
||||||
|
build/extra/cross-darwin-arm64/%: export CXX = clang++ -target arm64-apple-darwin
|
||||||
|
build/extra/cross-darwin-arm64/%: CMAKE_SYSTEM_NAME ?= Darwin
|
||||||
|
|
||||||
|
# cross compiler: macOS x86_64 (amd64)
|
||||||
|
build/extra/cross-darwin-x86_64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/extra/cross-darwin-x86_64/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/extra/cross-darwin-x86_64/%: export CC = clang -target x86_64-apple-darwin
|
||||||
|
build/extra/cross-darwin-x86_64/%: export CXX = clang++ -target x86_64-apple-darwin
|
||||||
|
build/extra/cross-darwin-x86_64/%: CMAKE_SYSTEM_NAME ?= Darwin
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# C/C++ static analyzers
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# force building with clang Static Analyzer (scan-build)
|
||||||
|
SCAN_BUILD = scan-build
|
||||||
|
build/analyze/clang-analyzer/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/analyze/clang-analyzer/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/analyze/clang-analyzer/%: override CMAKE := $(SCAN_BUILD) $(CMAKE)
|
||||||
|
build/analyze/clang-analyzer/%: export CCC_CC ?= clang
|
||||||
|
build/analyze/clang-analyzer/%: export CCC_CXX ?= clang++
|
||||||
|
|
||||||
|
# run clang-tidy: uses file compile_commands.json from an existing clang build
|
||||||
|
# does not create any actual files, so purely PHONY
|
||||||
|
RUN_CLANG_TIDY = time python3 ./misc/analyze/clang-tidy/run-clang-tidy.py -p $<
|
||||||
|
RUN_CLANG_TIDY_WERROR = $(RUN_CLANG_TIDY) '-warnings-as-errors=*'
|
||||||
|
build/analyze/clang-tidy-upx/debug build/analyze/clang-tidy-upx/release: build/extra/clang/$$(notdir $$@) PHONY
|
||||||
|
$(RUN_CLANG_TIDY_WERROR) -config-file ./.clang-tidy '/src/.*\.cpp'
|
||||||
|
build/analyze/clang-tidy-bzip2/debug build/analyze/clang-tidy-bzip2/release: build/extra/clang/$$(notdir $$@) PHONY
|
||||||
|
$(RUN_CLANG_TIDY) -config-file ./misc/analyze/clang-tidy/clang-tidy-bzip2.yml /vendor/bzip2/
|
||||||
|
build/analyze/clang-tidy-ucl/debug build/analyze/clang-tidy-ucl/release: build/extra/clang/$$(notdir $$@) PHONY
|
||||||
|
$(RUN_CLANG_TIDY_WERROR) -config-file ./misc/analyze/clang-tidy/clang-tidy-ucl.yml /vendor/ucl/
|
||||||
|
build/analyze/clang-tidy-zlib/debug build/analyze/clang-tidy-zlib/release: build/extra/clang/$$(notdir $$@) PHONY
|
||||||
|
$(RUN_CLANG_TIDY_WERROR) -config-file ./misc/analyze/clang-tidy/clang-tidy-zlib.yml /vendor/zlib/
|
||||||
|
build/analyze/clang-tidy-zstd/debug build/analyze/clang-tidy-zstd/release: build/extra/clang/$$(notdir $$@) PHONY
|
||||||
|
$(RUN_CLANG_TIDY) -config-file ./misc/analyze/clang-tidy/clang-tidy-zstd.yml /vendor/zstd/
|
||||||
|
build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-upx/$$(notdir $$@)
|
||||||
|
build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-bzip2/$$(notdir $$@)
|
||||||
|
build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-ucl/$$(notdir $$@)
|
||||||
|
build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-zlib/$$(notdir $$@)
|
||||||
|
build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-zstd/$$(notdir $$@)
|
||||||
|
|
||||||
|
# OLD names [deprecated]
|
||||||
|
build/extra/scan-build/debug: build/analyze/clang-analyzer/debug
|
||||||
|
build/extra/scan-build/release: build/analyze/clang-analyzer/release
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# advanced: generic eXtra target
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# usage:
|
||||||
|
# make UPX_XTARGET=my-target CC="my-cc -flags" CXX="my-cxx -flags"
|
||||||
|
# make UPX_XTARGET=my-target CC="my-cc -flags" CXX="my-cxx -flags" xtarget/debug
|
||||||
|
|
||||||
|
ifneq ($(UPX_XTARGET),)
|
||||||
|
ifneq ($(CC),)
|
||||||
|
ifneq ($(CXX),)
|
||||||
|
|
||||||
|
UPX_XTARGET := $(UPX_XTARGET)
|
||||||
|
build/xtarget/$(UPX_XTARGET)/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||||
|
build/xtarget/$(UPX_XTARGET)/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||||
|
build/xtarget/$(UPX_XTARGET)/%: export CC := $(CC)
|
||||||
|
build/xtarget/$(UPX_XTARGET)/%: export CXX := $(CXX)
|
||||||
|
# shortcuts
|
||||||
|
xtarget/all: xtarget/debug xtarget/release
|
||||||
|
xtarget/debug: build/xtarget/$(UPX_XTARGET)/debug
|
||||||
|
xtarget/release: build/xtarget/$(UPX_XTARGET)/release
|
||||||
|
# set new default
|
||||||
|
.DEFAULT_GOAL = build/xtarget/$(UPX_XTARGET)/release
|
||||||
|
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# assemble cmake config flags; useful for CI jobs
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
ifneq ($(origin UPX_CMAKE_CONFIG_FLAGS),command line) # needed to work around a GNU make bug
|
||||||
|
|
||||||
|
# info: by default CMake only honors the CC and CXX environment variables; make
|
||||||
|
# it easy to set other variables like CMAKE_AR or CMAKE_RANLIB
|
||||||
|
__add_cmake_config = $(and $($1),-D$1="$($1)")
|
||||||
|
# pass common CMake settings from environment/make to cmake
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_VERBOSE_MAKEFILE)
|
||||||
|
# pass common CMake toolchain settings from environment/make to cmake
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_ADDR2LINE)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_AR)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_DLLTOOL)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_LINKER)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_NM)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_OBJCOPY)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_OBJDUMP)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_RANLIB)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_READELF)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_STRIP)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_TAPI)
|
||||||
|
# pass common CMake LTO toolchain settings from environment/make to cmake (for use with "-flto")
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_C_COMPILER_AR)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_C_COMPILER_RANLIB)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_CXX_COMPILER_AR)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_CXX_COMPILER_RANLIB)
|
||||||
|
# pass common CMake cross compilation settings from environment/make to cmake
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_SYSTEM_NAME)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_CROSSCOMPILING_EMULATOR)
|
||||||
|
# pass UPX config options from environment/make to cmake; see CMakeLists.txt
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_GITREV)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_SANITIZE)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_WSTRICT)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_WERROR)
|
||||||
|
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_SELF_PACK_TEST)
|
||||||
|
|
||||||
|
endif # bug work-around
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# check git submodules
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
SUBMODULES = doctest lzma-sdk ucl valgrind zlib
|
||||||
|
|
||||||
|
$(foreach 1,$(SUBMODULES),$(if $(wildcard vendor/$1/[CL]*),,\
|
||||||
|
$(error ERROR: missing git submodule '$1'; run 'git submodule update --init')))
|
||||||
|
|
||||||
|
endif # UPX_MAKEFILE_EXTRA_MK_INCLUDED
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
||||||
|
|
||||||
|
# create the image from Dockerfile
|
||||||
|
# using a rootless Podman container
|
||||||
|
|
||||||
|
# NOTE: this image is based on rebuild-stubs/upx-stubtools-20221212-v7,
|
||||||
|
# so you have to create that image first
|
||||||
|
# WARNING: we install many packages, so the resulting image needs A LOT of disk space!
|
||||||
|
image=upx-cross-compile-ubuntu2204-20230721-v3
|
||||||
|
[[ $1 == --print-image ]] && echo "$image" && exit 0
|
||||||
|
|
||||||
|
podman build -t "$image" -f "$argv0dir/Dockerfile" "$argv0dir"
|
||||||
|
|
||||||
|
podman image list "$image"
|
||||||
|
echo
|
||||||
|
podman image tree "$image"
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
||||||
|
|
||||||
|
# list all system packages that are installed in the image
|
||||||
|
# using a rootless Podman container
|
||||||
|
|
||||||
|
image="$("$argv0dir/10-create-image.sh" --print-image)"
|
||||||
|
|
||||||
|
podman image list "$image"
|
||||||
|
echo
|
||||||
|
podman image tree "$image"
|
||||||
|
|
||||||
|
echo 'Packages:'
|
||||||
|
flags=( --read-only --rm --pull=never )
|
||||||
|
flags+=( --cap-drop=all ) # drop all capabilities
|
||||||
|
flags+=( --network=none ) # no network needed
|
||||||
|
podman run "${flags[@]}" "$image" bash -c $'dpkg -l | sed \'s/ *$//\' | LC_ALL=C sort'
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo 'Packages sorted by Installed-Size:'
|
||||||
|
podman run "${flags[@]}" "$image" bash -c $'awk \'
|
||||||
|
BEGIN {
|
||||||
|
arch = "UNKNOWN"; size = 0; package = "UNKNOWN";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if ($1 == "Architecture:") arch = $2;
|
||||||
|
if ($1 == "Installed-Size:") size = $2;
|
||||||
|
if ($1 == "Package:") package = $2;
|
||||||
|
if ($1 == "") {
|
||||||
|
printf("%9d %-40s %s\\n", size, package, arch);
|
||||||
|
count += 1; total += size;
|
||||||
|
arch = "UNKNOWN"; size = 0; package = "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
printf("%9d ===== TOTAL (%d packages)\\n", total, count);
|
||||||
|
}
|
||||||
|
\' /var/lib/dpkg/status | LC_ALL=C sort -rn'
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
||||||
|
|
||||||
|
# run an interactive shell in the image
|
||||||
|
# using a rootless Podman container
|
||||||
|
|
||||||
|
image="$("$argv0dir/10-create-image.sh" --print-image)"
|
||||||
|
|
||||||
|
flags=( --read-only --rm --pull=never )
|
||||||
|
flags+=( --cap-drop=all ) # drop all capabilities
|
||||||
|
flags+=( --network=none ) # no network needed
|
||||||
|
flags+=( -ti -e TERM="$TERM" ) # allocate an interactive pseudo-tty and pass $TERM
|
||||||
|
if [[ 1 == 1 ]]; then
|
||||||
|
# run as user upx 2000:2000
|
||||||
|
flags+=( --user 2000 )
|
||||||
|
# map container users 0..999 to subuid-users 1..1000, and map container user 2000 to current host user
|
||||||
|
flags+=( --uidmap=0:1:1000 --uidmap=2000:0:1 )
|
||||||
|
# map container groups 0..999 to subgid-groups 1..1000, and map container group 2000 to current host group
|
||||||
|
flags+=( --gidmap=0:1:1000 --gidmap=2000:0:1 )
|
||||||
|
# NOTE: we mount the upx top-level directory read-write under /home/upx/src/upx
|
||||||
|
# INFO: SELinux users *may* have to add ":z" to the volume mount flags; check the docs!
|
||||||
|
flags+=( -v "${argv0dir}/../../..:/home/upx/src/upx" )
|
||||||
|
flags+=( -w /home/upx/src/upx ) # set working directory
|
||||||
|
flags+=( --tmpfs /home/upx/.cache:rw,exec ) # mount a writeable tmpfs
|
||||||
|
flags+=( --tmpfs /home/upx/.local:rw,exec ) # mount a writeable tmpfs
|
||||||
|
else
|
||||||
|
# run as user root 0:0
|
||||||
|
# ONLY FOR DEBUGGING THE IMAGE
|
||||||
|
# map container user/group 0 to current host user/group
|
||||||
|
flags+=( --user 0 )
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
podman run "${flags[@]}" "$image" bash -l
|
||||||
|
else
|
||||||
|
podman run "${flags[@]}" "$image" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# now we can cross-compile UPX for Windows:
|
||||||
|
# cd /home/upx/src/upx
|
||||||
|
# rm -rf ./build/extra/cross-windows-mingw64/release
|
||||||
|
# make build/extra/cross-windows-mingw64/release
|
||||||
|
|
||||||
|
# and we can run the clang Static Analyzer (scan-build)
|
||||||
|
# cd /home/upx/src/upx
|
||||||
|
# rm -rf ./build/extra/scan-build/release
|
||||||
|
# make build/extra/scan-build/release
|
||||||
|
|
||||||
|
# and lots of other cross-compilers are installed; see "ls /usr/bin/*g++*"
|
||||||
|
|
||||||
|
# and finally see
|
||||||
|
# ./misc/podman/cross-compile-upx-ubuntu/build-all-inside-container.sh
|
||||||
|
# after running that script we can do cool things like:
|
||||||
|
# cd /home/upx/src/upx/build/cross-compile-upx-ubuntu2204/alpha-linux-gnu/debug
|
||||||
|
# qemu-alpha -L /usr/alpha-linux-gnu ./upx --version
|
||||||
|
# cd /home/upx/src/upx/build/cross-compile-upx-ubuntu2204/hppa-linux-gnu/debug
|
||||||
|
# qemu-hppa -L /usr/hppa-linux-gnu ./upx --version
|
||||||
|
# (similar for many other architectures/builds)
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# NOTE: this image is based on rebuild-stubs/upx-stubtools-20221212-v7,
|
||||||
|
# so you have to create that image first
|
||||||
|
# WARNING: we install many packages, so the resulting image needs A LOT of disk space!
|
||||||
|
FROM localhost/upx-stubtools-20221212-v7
|
||||||
|
ENV UPX_CONTAINER_IMAGE_NAME=upx-cross-compile-ubuntu2204-20230721-v3
|
||||||
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
USER root
|
||||||
|
|
||||||
|
# Ubuntu 22.04
|
||||||
|
RUN apt-get update && apt-get upgrade -y \
|
||||||
|
&& apt-get install -y \
|
||||||
|
# Linux glibc cross compilers
|
||||||
|
g++-aarch64-linux-gnu \
|
||||||
|
g++-alpha-linux-gnu \
|
||||||
|
g++-arm-linux-gnueabi \
|
||||||
|
g++-arm-linux-gnueabihf \
|
||||||
|
g++-hppa-linux-gnu \
|
||||||
|
g++-i686-linux-gnu \
|
||||||
|
g++-m68k-linux-gnu \
|
||||||
|
g++-mips-linux-gnu \
|
||||||
|
g++-mipsel-linux-gnu \
|
||||||
|
g++-mips64-linux-gnuabi64 \
|
||||||
|
g++-mips64el-linux-gnuabi64 \
|
||||||
|
g++-powerpc-linux-gnu \
|
||||||
|
g++-powerpc64-linux-gnu \
|
||||||
|
g++-powerpc64le-linux-gnu \
|
||||||
|
g++-riscv64-linux-gnu \
|
||||||
|
g++-s390x-linux-gnu \
|
||||||
|
g++-sh4-linux-gnu \
|
||||||
|
g++-sparc64-linux-gnu \
|
||||||
|
# Linux glibc cross compilers - ILP32 on 64-bit CPUs
|
||||||
|
g++-x86-64-linux-gnux32 \
|
||||||
|
# Windows cross compilers
|
||||||
|
g++-mingw-w64-i686 \
|
||||||
|
g++-mingw-w64-x86-64 \
|
||||||
|
# make sure that we use posix-threads (pthread/winpthreads) and NOT win32-threads
|
||||||
|
&& for f in i686-w64-mingw32-g++ i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc; do update-alternatives --set $f /usr/bin/$f-posix; done \
|
||||||
|
&& true
|
||||||
|
RUN apt-get install -y \
|
||||||
|
# clang-14 and tools
|
||||||
|
clang-14 clang-format-14 clang-tidy-14 clang-tools-14 lldb-14 llvm-14 \
|
||||||
|
# QEMU and Wine
|
||||||
|
qemu-system qemu-user wine wine32:i386 wine64 \
|
||||||
|
# misc
|
||||||
|
gdb lsb-release valgrind \
|
||||||
|
&& true
|
||||||
|
RUN cd /usr/bin \
|
||||||
|
# create unversioned clang symlinks in /usr/local/bin
|
||||||
|
&& for f in clang*-14 llvm-*-14 scan-*-14; do ln -s -v ../../bin/$f /usr/local/bin/${f%-14}; done \
|
||||||
|
&& ln -s -v ../../bin/obj2yaml-14 /usr/local/bin/llvm-obj2yaml \
|
||||||
|
&& ln -s -v ../../bin/yaml2obj-14 /usr/local/bin/llvm-yaml2obj \
|
||||||
|
&& true
|
||||||
|
|
||||||
|
# switch back to default user upx:upx 2000:2000
|
||||||
|
USER upx
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
||||||
|
|
||||||
|
# build UPX for 21 targets; must be run inside the container!
|
||||||
|
# using a rootless Podman container
|
||||||
|
|
||||||
|
# simple sanity check that we are indeed running inside the container
|
||||||
|
if [[ $UPX_CONTAINER_IMAGE_NAME != upx-cross-compile-* ]]; then
|
||||||
|
echo "$argv0: NOTE: please run this script *inside* the container"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# go to upx top-level directory
|
||||||
|
cd "$argv0dir/../../.." || exit 1
|
||||||
|
pwd
|
||||||
|
test -f doc/upx.pod || exit 1 # sanity check
|
||||||
|
test -f src/version.h || exit 1 # sanity check
|
||||||
|
|
||||||
|
function run_config_and_build {
|
||||||
|
# requires: AR CC CXX RANLIB
|
||||||
|
local toolchain=$1
|
||||||
|
local cmake_config_flags build_type bdir
|
||||||
|
# cmake flags
|
||||||
|
cmake_config_flags=
|
||||||
|
case $toolchain in
|
||||||
|
# these old architectures do not support sanitize
|
||||||
|
alpha-linux-gnu) cmake_config_flags=-DUPX_CONFIG_DISABLE_SANITIZE=ON ;;
|
||||||
|
hppa-linux-gnu) cmake_config_flags=-DUPX_CONFIG_DISABLE_SANITIZE=ON ;;
|
||||||
|
# avoid sanitize link errors with current MinGW-w64 versions; link libstdc++ statically
|
||||||
|
i686-w64-mingw32)
|
||||||
|
cmake_config_flags=-DUPX_CONFIG_DISABLE_SANITIZE=ON
|
||||||
|
CC="$CC -static"; CXX="$CXX -static" ;;
|
||||||
|
x86_64-w64-mingw32)
|
||||||
|
cmake_config_flags=-DUPX_CONFIG_DISABLE_SANITIZE=ON
|
||||||
|
CC="$CC -static"; CXX="$CXX -static" ;;
|
||||||
|
# avoid warnings about arm libstdc++ ABI change in gcc-7
|
||||||
|
arm-linux-*) CXX="$CXX -Wno-psabi" ;;
|
||||||
|
esac
|
||||||
|
if [[ 1 == 1 ]]; then
|
||||||
|
# prefer building with Ninja (ninja-build)
|
||||||
|
cmake_config_flags="$cmake_config_flags -G Ninja -DUPX_CONFIG_CMAKE_DISABLE_INSTALL=ON"
|
||||||
|
fi
|
||||||
|
# for all build types
|
||||||
|
for build_type in Debug Release; do
|
||||||
|
bdir="build/cross-compile-upx-ubuntu2204/$toolchain/${build_type,,}"
|
||||||
|
mkdir -p "$bdir"
|
||||||
|
# run_config
|
||||||
|
if [[ ! -f $bdir/CMakeCache.txt ]]; then
|
||||||
|
export CMAKE_REQUIRED_QUIET=OFF
|
||||||
|
cmake -S . -B "$bdir" -DCMAKE_BUILD_TYPE=$build_type -DCMAKE_AR="$AR" -DCMAKE_RANLIB="$RANLIB" $cmake_config_flags
|
||||||
|
fi
|
||||||
|
# run_build
|
||||||
|
cmake --build "$bdir" --config $build_type --parallel
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# see Dockerfile for packages
|
||||||
|
for package in \
|
||||||
|
g++-aarch64-linux-gnu \
|
||||||
|
g++-alpha-linux-gnu \
|
||||||
|
g++-arm-linux-gnueabi \
|
||||||
|
g++-arm-linux-gnueabihf \
|
||||||
|
g++-hppa-linux-gnu \
|
||||||
|
g++-i686-linux-gnu \
|
||||||
|
g++-m68k-linux-gnu \
|
||||||
|
g++-mips-linux-gnu \
|
||||||
|
g++-mipsel-linux-gnu \
|
||||||
|
g++-mips64-linux-gnuabi64 \
|
||||||
|
g++-mips64el-linux-gnuabi64 \
|
||||||
|
g++-powerpc-linux-gnu \
|
||||||
|
g++-powerpc64-linux-gnu \
|
||||||
|
g++-powerpc64le-linux-gnu \
|
||||||
|
g++-riscv64-linux-gnu \
|
||||||
|
g++-s390x-linux-gnu \
|
||||||
|
g++-sh4-linux-gnu \
|
||||||
|
g++-sparc64-linux-gnu \
|
||||||
|
g++-x86-64-linux-gnux32 \
|
||||||
|
g++-mingw-w64-i686 \
|
||||||
|
g++-mingw-w64-x86-64
|
||||||
|
do
|
||||||
|
# setup toolchain and environment variables
|
||||||
|
toolchain=$package
|
||||||
|
toolchain=${toolchain/-x86-64/-x86_64}
|
||||||
|
toolchain=${toolchain/g++-/}
|
||||||
|
case $toolchain in
|
||||||
|
mingw-w64-i686) toolchain=i686-w64-mingw32 ;;
|
||||||
|
mingw-w64-x86_64) toolchain=x86_64-w64-mingw32 ;;
|
||||||
|
esac
|
||||||
|
echo "========== $toolchain"
|
||||||
|
export AR=/usr/bin/${toolchain}-ar
|
||||||
|
export CC=/usr/bin/${toolchain}-gcc
|
||||||
|
export CXX=/usr/bin/${toolchain}-g++
|
||||||
|
export RANLIB=/usr/bin/${toolchain}-ranlib
|
||||||
|
ls -l "$AR" "$CC" "$CXX" "$RANLIB"
|
||||||
|
run_config_and_build $toolchain
|
||||||
|
unset AR CC CXX RANLIB
|
||||||
|
done
|
||||||
+2459
File diff suppressed because it is too large
Load Diff
+3
-1
@@ -6,9 +6,11 @@ argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
|||||||
# create the image from Dockerfile
|
# create the image from Dockerfile
|
||||||
# using a rootless Podman container
|
# using a rootless Podman container
|
||||||
|
|
||||||
image=upx-stubtools-20210104-v5
|
image=upx-stubtools-20221212-v7
|
||||||
|
[[ $1 == --print-image ]] && echo "$image" && exit 0
|
||||||
|
|
||||||
podman build -t "$image" -f "$argv0dir/Dockerfile" "$argv0dir"
|
podman build -t "$image" -f "$argv0dir/Dockerfile" "$argv0dir"
|
||||||
|
|
||||||
podman image list "$image"
|
podman image list "$image"
|
||||||
|
echo
|
||||||
podman image tree "$image"
|
podman image tree "$image"
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
||||||
|
|
||||||
|
# list all system packages that are installed in the image
|
||||||
|
# using a rootless Podman container
|
||||||
|
|
||||||
|
image="$("$argv0dir/10-create-image.sh" --print-image)"
|
||||||
|
|
||||||
|
podman image list "$image"
|
||||||
|
echo
|
||||||
|
podman image tree "$image"
|
||||||
|
|
||||||
|
echo 'Packages:'
|
||||||
|
flags=( --read-only --rm --pull=never )
|
||||||
|
flags+=( --cap-drop=all ) # drop all capabilities
|
||||||
|
flags+=( --network=none ) # no network needed
|
||||||
|
podman run "${flags[@]}" "$image" bash -c $'dpkg -l | sed \'s/ *$//\' | LC_ALL=C sort'
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo 'Packages sorted by Installed-Size:'
|
||||||
|
podman run "${flags[@]}" "$image" bash -c $'awk \'
|
||||||
|
BEGIN {
|
||||||
|
arch = "UNKNOWN"; size = 0; package = "UNKNOWN";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if ($1 == "Architecture:") arch = $2;
|
||||||
|
if ($1 == "Installed-Size:") size = $2;
|
||||||
|
if ($1 == "Package:") package = $2;
|
||||||
|
if ($1 == "") {
|
||||||
|
printf("%9d %-40s %s\\n", size, package, arch);
|
||||||
|
count += 1; total += size;
|
||||||
|
arch = "UNKNOWN"; size = 0; package = "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
printf("%9d ===== TOTAL (%d packages)\\n", total, count);
|
||||||
|
}
|
||||||
|
\' /var/lib/dpkg/status | LC_ALL=C sort -rn'
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
||||||
|
|
||||||
|
# run an interactive shell in the image
|
||||||
|
# using a rootless Podman container
|
||||||
|
|
||||||
|
image="$("$argv0dir/10-create-image.sh" --print-image)"
|
||||||
|
|
||||||
|
flags=( --read-only --rm --pull=never )
|
||||||
|
flags+=( --cap-drop=all ) # drop all capabilities
|
||||||
|
flags+=( --network=none ) # no network needed
|
||||||
|
flags+=( -ti -e TERM="$TERM" ) # allocate an interactive pseudo-tty and pass $TERM
|
||||||
|
if [[ 1 == 1 ]]; then
|
||||||
|
# run as user upx 2000:2000
|
||||||
|
flags+=( --user 2000 )
|
||||||
|
# map container users 0..999 to subuid-users 1..1000, and map container user 2000 to current host user
|
||||||
|
flags+=( --uidmap=0:1:1000 --uidmap=2000:0:1 )
|
||||||
|
# map container groups 0..999 to subgid-groups 1..1000, and map container group 2000 to current host group
|
||||||
|
flags+=( --gidmap=0:1:1000 --gidmap=2000:0:1 )
|
||||||
|
# NOTE: we mount the upx top-level directory read-write under /home/upx/src/upx
|
||||||
|
# INFO: SELinux users *may* have to add ":z" to the volume mount flags; check the docs!
|
||||||
|
flags+=( -v "${argv0dir}/../../..:/home/upx/src/upx" )
|
||||||
|
flags+=( -w /home/upx/src/upx ) # set working directory
|
||||||
|
flags+=( --tmpfs /home/upx/.cache:rw,exec ) # mount a writeable tmpfs
|
||||||
|
flags+=( --tmpfs /home/upx/.local:rw,exec ) # mount a writeable tmpfs
|
||||||
|
else
|
||||||
|
# run as user root 0:0
|
||||||
|
# ONLY FOR DEBUGGING THE IMAGE
|
||||||
|
# map container user/group 0 to current host user/group
|
||||||
|
flags+=( --user 0 )
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
podman run "${flags[@]}" "$image" bash -l
|
||||||
|
else
|
||||||
|
podman run "${flags[@]}" "$image" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# now we can rebuild the UPX stubs:
|
||||||
|
# cd /home/upx/src/upx/src/stub
|
||||||
|
# # make sure that git is clean:
|
||||||
|
# git status .
|
||||||
|
# # remove stub files and make sure that they got deleted:
|
||||||
|
# make maintainer-clean extra-clean
|
||||||
|
# git status .
|
||||||
|
# # rebuild
|
||||||
|
# make extra-all all
|
||||||
|
# # make sure that the stub files did rebuild correctly:
|
||||||
|
# git status .
|
||||||
|
# git diff .
|
||||||
|
|
||||||
|
# we can also build UPX in the container:
|
||||||
|
# cd /home/upx/src/upx
|
||||||
|
# rm -rf ./build/extra/gcc/release
|
||||||
|
# make build/extra/gcc/release
|
||||||
|
# # run tests
|
||||||
|
# ./build/extra/gcc/release/upx --version
|
||||||
|
# make -C build/extra/gcc/release test
|
||||||
|
|
||||||
|
# and we can also build UPX with -m32:
|
||||||
|
# cd /home/upx/src/upx
|
||||||
|
# rm -rf ./build/extra/gcc-m32/release
|
||||||
|
# make build/extra/gcc-m32/release
|
||||||
|
# # run tests
|
||||||
|
# ./build/extra/gcc-m32/release/upx --version
|
||||||
|
# make -C build/extra/gcc-m32/release test
|
||||||
|
|
||||||
|
# and we can also build UPX with -mx32: (NOTE: needs CONFIG_X86_X32_ABI on host kernel!)
|
||||||
|
# cd /home/upx/src/upx
|
||||||
|
# rm -rf ./build/extra/gcc-mx32/release
|
||||||
|
# make build/extra/gcc-mx32/release
|
||||||
|
# # run tests (needs CONFIG_X86_X32_ABI on host kernel)
|
||||||
|
# ./build/extra/gcc-mx32/release/upx --version
|
||||||
|
# make -C build/extra/gcc-mx32/release test
|
||||||
|
|
||||||
|
# and we can also rebuild the UPX docs the container:
|
||||||
|
# cd /home/upx/src/upx/doc
|
||||||
|
# make clean all
|
||||||
|
# git status .
|
||||||
|
# git diff .
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
FROM docker.io/library/ubuntu:22.04
|
||||||
|
ENV UPX_CONTAINER_IMAGE_NAME=upx-stubtools-20221212-v6
|
||||||
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
ENV LANG=C.UTF-8
|
||||||
|
|
||||||
|
# install system packages
|
||||||
|
RUN dpkg --add-architecture i386 \
|
||||||
|
&& apt-get update && apt-get upgrade -y \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
aria2 bash bash-completion ca-certificates dash git less libmpc3 libncurses5 \
|
||||||
|
make ncurses-term perl-base python2-minimal time wget xz-utils \
|
||||||
|
libc6:i386 zlib1g:i386 \
|
||||||
|
# the following packages are not required for rebuilding the stubs, but
|
||||||
|
# they do make the image *much* more convenient and also allow building
|
||||||
|
# the full UPX binary inside the container via CMake:
|
||||||
|
7zip bfs busybox bzip2 cabextract ccache chrpath cmake cpio curl elfutils fd-find file fzf \
|
||||||
|
g++ gawk gdb gojq ht htop hyperfine jq libzstd-dev lsb-release lz4 lzip lzop \
|
||||||
|
mksh moreutils ninja-build p7zip parallel patch patchelf patchutils pax-utils paxctl \
|
||||||
|
python3 python3-pyasn1 python3-pycryptodome python3-zstd \
|
||||||
|
re2c ripgrep rsync screen universal-ctags unzip vim yash zip zlib1g-dev zsh zstd \
|
||||||
|
# extra packages for compiling with "gcc -m32" and and "gcc -mx32":
|
||||||
|
g++-multilib gcc-multilib \
|
||||||
|
&& true
|
||||||
|
|
||||||
|
# manually unpack and install compat libs from Ubuntu-16.04; REQUIRED
|
||||||
|
RUN cd /root \
|
||||||
|
&& aria2c --checksum=sha-256=de22baf3dd851a10e16fbf66a243e70149ca46e06b2939fdc79429196cefc090 \
|
||||||
|
'https://archive.kernel.org/ubuntu-archive/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.6-1_amd64.deb' \
|
||||||
|
&& mkdir packages \
|
||||||
|
&& for f in ./*.deb; do dpkg -x $f ./packages; done \
|
||||||
|
&& mv -v -n ./packages/usr/lib/x86_64-linux-gnu/lib* /usr/lib/x86_64-linux-gnu/ \
|
||||||
|
&& rm -rf ./*.deb ./packages \
|
||||||
|
&& ldconfig \
|
||||||
|
&& true
|
||||||
|
|
||||||
|
# install upx-stubtools into /usr/local/bin/bin-upx-20221212; REQUIRED
|
||||||
|
RUN cd /root \
|
||||||
|
&& aria2c --checksum=sha-256=509e06639118a79d8e79489a400e134c6d3ca36bad2c6ec29648d7c1e5b81afa \
|
||||||
|
'https://github.com/upx/upx-stubtools/releases/download/v20221212/bin-upx-20221212.tar.xz' \
|
||||||
|
&& cd /usr/local/bin \
|
||||||
|
&& tar -xoaf /root/bin-upx-20221212.tar.xz \
|
||||||
|
&& rm /root/bin-upx-20221212.tar.xz \
|
||||||
|
&& true
|
||||||
|
|
||||||
|
# install official UPX release binaries into /usr/local/bin; not required but convenient for testing
|
||||||
|
RUN cd /root \
|
||||||
|
&& wget -q https://github.com/upx/upx/releases/download/v3.91/upx-3.91-amd64_linux.tar.bz2 \
|
||||||
|
&& xzlist="3.92 3.93 3.94 3.95 3.96 4.0.0 4.0.1 4.0.2 4.1.0 4.2.0 4.2.1" \
|
||||||
|
&& for v in $xzlist; do wget -q https://github.com/upx/upx/releases/download/v${v}/upx-${v}-amd64_linux.tar.xz; done \
|
||||||
|
&& for f in ./upx-*.tar.*; do tar -xoaf $f; done \
|
||||||
|
&& for v in 3.91 $xzlist; do d=upx-${v}-amd64_linux; ./$d/upx -qq -d $d/upx -o /usr/local/bin/upx-${v}; done \
|
||||||
|
&& rm -r ./upx-*.tar.* ./upx-*linux \
|
||||||
|
&& true
|
||||||
|
|
||||||
|
# create default user upx:upx 2000:2000
|
||||||
|
RUN useradd upx -U --uid 2000 --shell /bin/bash -m \
|
||||||
|
&& cd /home/upx && chmod 00700 . \
|
||||||
|
# prepare ~/.cache and ~/.local for possible tmpfs mounts
|
||||||
|
&& mkdir -p .cache/tmp .local/bin src/upx \
|
||||||
|
&& for d in ccache fontconfig go-build mesa_shader_cache tmp wine zig; do mkdir -p .cache/$d; done \
|
||||||
|
&& for d in bin include lib share state; do mkdir -p .local/$d; done \
|
||||||
|
&& ln -s .cache/wine .wine && ln -s .cache/tmp tmp \
|
||||||
|
&& ln -s /usr/local/bin/bin-upx-20221212 .local/bin/bin-upx \
|
||||||
|
&& chown -R upx:upx . \
|
||||||
|
&& true
|
||||||
|
USER upx
|
||||||
Generated
+659
@@ -0,0 +1,659 @@
|
|||||||
|
Packages:
|
||||||
|
+++-===========================-=======================================-============-================================================================================
|
||||||
|
Desired=Unknown/Install/Remove/Purge/Hold
|
||||||
|
ii 7zip 21.07+dfsg-4 amd64 7-Zip file archiver with a high compression ratio
|
||||||
|
ii adduser 3.118ubuntu5 all add and remove users and groups
|
||||||
|
ii apt 2.4.11 amd64 commandline package manager
|
||||||
|
ii aria2 1.36.0-1 amd64 High speed download utility
|
||||||
|
ii base-files 12ubuntu4.4 amd64 Debian base system miscellaneous files
|
||||||
|
ii base-passwd 3.5.52build1 amd64 Debian base system master password and group files
|
||||||
|
ii bash 5.1-6ubuntu1 amd64 GNU Bourne Again SHell
|
||||||
|
ii bash-completion 1:2.11-5ubuntu1 all programmable completion for the bash shell
|
||||||
|
ii bfs 2.3.1-1 amd64 Breadth-first version of find(1)
|
||||||
|
ii binutils 2.38-4ubuntu2.4 amd64 GNU assembler, linker and binary utilities
|
||||||
|
ii binutils-common:amd64 2.38-4ubuntu2.4 amd64 Common files for the GNU assembler, linker and binary utilities
|
||||||
|
ii binutils-x86-64-linux-gnu 2.38-4ubuntu2.4 amd64 GNU binary utilities, for x86-64-linux-gnu target
|
||||||
|
ii bsdutils 1:2.37.2-4ubuntu3 amd64 basic utilities from 4.4BSD-Lite
|
||||||
|
ii busybox 1:1.30.1-7ubuntu3 amd64 Tiny utilities for small and embedded systems
|
||||||
|
ii bzip2 1.0.8-5build1 amd64 high-quality block-sorting file compressor - utilities
|
||||||
|
ii ca-certificates 20230311ubuntu0.22.04.1 all Common CA certificates
|
||||||
|
ii cabextract 1.9-3 amd64 Microsoft Cabinet file unpacker
|
||||||
|
ii ccache 4.5.1-1 amd64 Compiler cache for fast recompilation of C/C++ code
|
||||||
|
ii chrpath 0.16-2 amd64 Tool to edit the rpath in ELF binaries
|
||||||
|
ii cmake 3.22.1-1ubuntu1.22.04.1 amd64 cross-platform, open-source make system
|
||||||
|
ii cmake-data 3.22.1-1ubuntu1.22.04.1 all CMake data files (modules, templates and documentation)
|
||||||
|
ii coreutils 8.32-4.1ubuntu1 amd64 GNU core utilities
|
||||||
|
ii cpio 2.13+dfsg-7 amd64 GNU cpio -- a program to manage archives of files
|
||||||
|
ii cpp 4:11.2.0-1ubuntu1 amd64 GNU C preprocessor (cpp)
|
||||||
|
ii cpp-11 11.4.0-1ubuntu1~22.04 amd64 GNU C preprocessor
|
||||||
|
ii curl 7.81.0-1ubuntu1.15 amd64 command line tool for transferring data with URL syntax
|
||||||
|
ii dash 0.5.11+git20210903+057cd650a4ed-3build1 amd64 POSIX-compliant shell
|
||||||
|
ii debconf 1.5.79ubuntu1 all Debian configuration management system
|
||||||
|
ii debianutils 5.5-1ubuntu2 amd64 Miscellaneous utilities specific to Debian
|
||||||
|
ii dh-elpa-helper 2.0.9ubuntu1 all helper package for emacs lisp extensions
|
||||||
|
ii diffutils 1:3.8-0ubuntu2 amd64 File comparison utilities
|
||||||
|
ii distro-info-data 0.52ubuntu0.6 all information about the distributions' releases (data files)
|
||||||
|
ii dpkg 1.21.1ubuntu2.2 amd64 Debian package management system
|
||||||
|
ii e2fsprogs 1.46.5-2ubuntu1.1 amd64 ext2/ext3/ext4 file system utilities
|
||||||
|
ii elfutils 0.186-1build1 amd64 collection of utilities to handle ELF objects
|
||||||
|
ii emacsen-common 3.0.4 all Common facilities for all emacsen
|
||||||
|
ii fd-find 8.3.1-1ubuntu0.1 amd64 Simple, fast and user-friendly alternative to find
|
||||||
|
ii file 1:5.41-3ubuntu0.1 amd64 Recognize the type of data in a file using "magic" numbers
|
||||||
|
ii findutils 4.8.0-1ubuntu3 amd64 utilities for finding files--find, xargs
|
||||||
|
ii fzf 0.29.0-1 amd64 general-purpose command-line fuzzy finder
|
||||||
|
ii g++ 4:11.2.0-1ubuntu1 amd64 GNU C++ compiler
|
||||||
|
ii g++-11 11.4.0-1ubuntu1~22.04 amd64 GNU C++ compiler
|
||||||
|
ii g++-11-multilib 11.4.0-1ubuntu1~22.04 amd64 GNU C++ compiler (multilib support)
|
||||||
|
ii g++-multilib 4:11.2.0-1ubuntu1 amd64 GNU C++ compiler (multilib files)
|
||||||
|
ii gawk 1:5.1.0-1ubuntu0.1 amd64 GNU awk, a pattern scanning and processing language
|
||||||
|
ii gcc 4:11.2.0-1ubuntu1 amd64 GNU C compiler
|
||||||
|
ii gcc-11 11.4.0-1ubuntu1~22.04 amd64 GNU C compiler
|
||||||
|
ii gcc-11-base:amd64 11.4.0-1ubuntu1~22.04 amd64 GCC, the GNU Compiler Collection (base package)
|
||||||
|
ii gcc-11-multilib 11.4.0-1ubuntu1~22.04 amd64 GNU C compiler (multilib support)
|
||||||
|
ii gcc-12-base:amd64 12.3.0-1ubuntu1~22.04 amd64 GCC, the GNU Compiler Collection (base package)
|
||||||
|
ii gcc-12-base:i386 12.3.0-1ubuntu1~22.04 i386 GCC, the GNU Compiler Collection (base package)
|
||||||
|
ii gcc-multilib 4:11.2.0-1ubuntu1 amd64 GNU C compiler (multilib files)
|
||||||
|
ii gdb 12.1-0ubuntu1~22.04 amd64 GNU Debugger
|
||||||
|
ii git 1:2.34.1-1ubuntu1.10 amd64 fast, scalable, distributed revision control system
|
||||||
|
ii git-man 1:2.34.1-1ubuntu1.10 all fast, scalable, distributed revision control system (manual pages)
|
||||||
|
ii gojq 0.12.6-1 amd64 pure Go implementation of jq (program)
|
||||||
|
ii gpgv 2.2.27-3ubuntu2.1 amd64 GNU privacy guard - signature verification tool
|
||||||
|
ii grep 3.7-1build1 amd64 GNU grep, egrep and fgrep
|
||||||
|
ii gzip 1.10-4ubuntu4.1 amd64 GNU compression utilities
|
||||||
|
ii hostname 3.23ubuntu2 amd64 utility to set/show the host name or domain name
|
||||||
|
ii ht 2.1.0+repack1-5 amd64 Viewer/editor/analyser (mostly) for executables
|
||||||
|
ii htop 3.0.5-7build2 amd64 interactive processes viewer
|
||||||
|
ii hyperfine 1.12.0-3ubuntu0.1 amd64 Command-line benchmarking tool
|
||||||
|
ii init-system-helpers 1.62 all helper tools for all init systems
|
||||||
|
ii jq 1.6-2.1ubuntu3 amd64 lightweight and flexible command-line JSON processor
|
||||||
|
ii less 590-1ubuntu0.22.04.1 amd64 pager program similar to more
|
||||||
|
ii lib32asan6 11.4.0-1ubuntu1~22.04 amd64 AddressSanitizer -- a fast memory error detector (32bit)
|
||||||
|
ii lib32atomic1 12.3.0-1ubuntu1~22.04 amd64 support library providing __atomic built-in functions (32bit)
|
||||||
|
ii lib32gcc-11-dev 11.4.0-1ubuntu1~22.04 amd64 GCC support library (32 bit development files)
|
||||||
|
ii lib32gcc-s1 12.3.0-1ubuntu1~22.04 amd64 GCC support library (32 bit Version)
|
||||||
|
ii lib32gomp1 12.3.0-1ubuntu1~22.04 amd64 GCC OpenMP (GOMP) support library (32bit)
|
||||||
|
ii lib32itm1 12.3.0-1ubuntu1~22.04 amd64 GNU Transactional Memory Library (32bit)
|
||||||
|
ii lib32quadmath0 12.3.0-1ubuntu1~22.04 amd64 GCC Quad-Precision Math Library (32bit)
|
||||||
|
ii lib32stdc++-11-dev 11.4.0-1ubuntu1~22.04 amd64 GNU Standard C++ Library v3 (development files)
|
||||||
|
ii lib32stdc++6 12.3.0-1ubuntu1~22.04 amd64 GNU Standard C++ Library v3 (32 bit Version)
|
||||||
|
ii lib32ubsan1 12.3.0-1ubuntu1~22.04 amd64 UBSan -- undefined behaviour sanitizer (32bit)
|
||||||
|
ii libacl1:amd64 2.3.1-1 amd64 access control list - shared library
|
||||||
|
ii libapt-pkg6.0:amd64 2.4.11 amd64 package management runtime library
|
||||||
|
ii libarchive13:amd64 3.6.0-1ubuntu1 amd64 Multi-format archive and compression library (shared library)
|
||||||
|
ii libaria2-0:amd64 1.36.0-1 amd64 C++ library interface to aria2
|
||||||
|
ii libasan6:amd64 11.4.0-1ubuntu1~22.04 amd64 AddressSanitizer -- a fast memory error detector
|
||||||
|
ii libasm1:amd64 0.186-1build1 amd64 library with a programmable assembler interface
|
||||||
|
ii libatomic1:amd64 12.3.0-1ubuntu1~22.04 amd64 support library providing __atomic built-in functions
|
||||||
|
ii libattr1:amd64 1:2.5.1-1build1 amd64 extended attribute handling - shared library
|
||||||
|
ii libaudit-common 1:3.0.7-1build1 all Dynamic library for security auditing - common files
|
||||||
|
ii libaudit1:amd64 1:3.0.7-1build1 amd64 Dynamic library for security auditing
|
||||||
|
ii libbabeltrace1:amd64 1.5.8-2build1 amd64 Babeltrace conversion libraries
|
||||||
|
ii libbinutils:amd64 2.38-4ubuntu2.4 amd64 GNU binary utilities (private shared library)
|
||||||
|
ii libblkid1:amd64 2.37.2-4ubuntu3 amd64 block device ID library
|
||||||
|
ii libboost-regex1.74.0:amd64 1.74.0-14ubuntu3 amd64 regular expression library for C++
|
||||||
|
ii libbrotli1:amd64 1.0.9-2build6 amd64 library implementing brotli encoder and decoder (shared libraries)
|
||||||
|
ii libbsd0:amd64 0.11.5-1 amd64 utility functions from BSD systems - shared library
|
||||||
|
ii libbz2-1.0:amd64 1.0.8-5build1 amd64 high-quality block-sorting file compressor library - runtime
|
||||||
|
ii libc-ares2:amd64 1.18.1-1ubuntu0.22.04.2 amd64 asynchronous name resolver
|
||||||
|
ii libc-bin 2.35-0ubuntu3.5 amd64 GNU C Library: Binaries
|
||||||
|
ii libc-dev-bin 2.35-0ubuntu3.5 amd64 GNU C Library: Development binaries
|
||||||
|
ii libc6-dev-i386 2.35-0ubuntu3.5 amd64 GNU C Library: 32-bit development libraries for AMD64
|
||||||
|
ii libc6-dev-x32 2.35-0ubuntu3.5 amd64 GNU C Library: X32 ABI Development Libraries for AMD64
|
||||||
|
ii libc6-dev:amd64 2.35-0ubuntu3.5 amd64 GNU C Library: Development Libraries and Header Files
|
||||||
|
ii libc6-i386 2.35-0ubuntu3.5 amd64 GNU C Library: 32-bit shared libraries for AMD64
|
||||||
|
ii libc6-x32 2.35-0ubuntu3.5 amd64 GNU C Library: X32 ABI Shared libraries for AMD64
|
||||||
|
ii libc6:amd64 2.35-0ubuntu3.5 amd64 GNU C Library: Shared libraries
|
||||||
|
ii libc6:i386 2.35-0ubuntu3.5 i386 GNU C Library: Shared libraries
|
||||||
|
ii libcap-ng0:amd64 0.7.9-2.2build3 amd64 An alternate POSIX capabilities library
|
||||||
|
ii libcap2:amd64 1:2.44-1ubuntu0.22.04.1 amd64 POSIX 1003.1e capabilities (library)
|
||||||
|
ii libcc1-0:amd64 12.3.0-1ubuntu1~22.04 amd64 GCC cc1 plugin for GDB
|
||||||
|
ii libcom-err2:amd64 1.46.5-2ubuntu1.1 amd64 common error description library
|
||||||
|
ii libcrypt-dev:amd64 1:4.4.27-1 amd64 libcrypt development files
|
||||||
|
ii libcrypt1:amd64 1:4.4.27-1 amd64 libcrypt shared library
|
||||||
|
ii libcrypt1:i386 1:4.4.27-1 i386 libcrypt shared library
|
||||||
|
ii libctf-nobfd0:amd64 2.38-4ubuntu2.4 amd64 Compact C Type Format library (runtime, no BFD dependency)
|
||||||
|
ii libctf0:amd64 2.38-4ubuntu2.4 amd64 Compact C Type Format library (runtime, BFD dependency)
|
||||||
|
ii libcurl3-gnutls:amd64 7.81.0-1ubuntu1.15 amd64 easy-to-use client-side URL transfer library (GnuTLS flavour)
|
||||||
|
ii libcurl4:amd64 7.81.0-1ubuntu1.15 amd64 easy-to-use client-side URL transfer library (OpenSSL flavour)
|
||||||
|
ii libdb5.3:amd64 5.3.28+dfsg1-0.8ubuntu3 amd64 Berkeley v5.3 Database Libraries [runtime]
|
||||||
|
ii libdebconfclient0:amd64 0.261ubuntu1 amd64 Debian Configuration Management System (C-implementation library)
|
||||||
|
ii libdebuginfod-common 0.186-1build1 all configuration to enable the Debian debug info server
|
||||||
|
ii libdebuginfod1:amd64 0.186-1build1 amd64 library to interact with debuginfod (development files)
|
||||||
|
ii libdw1:amd64 0.186-1build1 amd64 library that provides access to the DWARF debug information
|
||||||
|
ii libelf1:amd64 0.186-1build1 amd64 library to read and write ELF files
|
||||||
|
ii liberror-perl 0.17029-1 all Perl module for error/exception handling in an OO-ish way
|
||||||
|
ii libexpat1:amd64 2.4.7-1ubuntu0.2 amd64 XML parsing C library - runtime library
|
||||||
|
ii libext2fs2:amd64 1.46.5-2ubuntu1.1 amd64 ext2/ext3/ext4 file system libraries
|
||||||
|
ii libffi8:amd64 3.4.2-4 amd64 Foreign Function Interface library runtime
|
||||||
|
ii libgcc-11-dev:amd64 11.4.0-1ubuntu1~22.04 amd64 GCC support library (development files)
|
||||||
|
ii libgcc-s1:amd64 12.3.0-1ubuntu1~22.04 amd64 GCC support library
|
||||||
|
ii libgcc-s1:i386 12.3.0-1ubuntu1~22.04 i386 GCC support library
|
||||||
|
ii libgcrypt20:amd64 1.9.4-3ubuntu3 amd64 LGPL Crypto library - runtime library
|
||||||
|
ii libgdbm-compat4:amd64 1.23-1 amd64 GNU dbm database routines (legacy support runtime version)
|
||||||
|
ii libgdbm6:amd64 1.23-1 amd64 GNU dbm database routines (runtime version)
|
||||||
|
ii libglib2.0-0:amd64 2.72.4-0ubuntu2.2 amd64 GLib library of C routines
|
||||||
|
ii libgmp10:amd64 2:6.2.1+dfsg-3ubuntu1 amd64 Multiprecision arithmetic library
|
||||||
|
ii libgnutls30:amd64 3.7.3-4ubuntu1.3 amd64 GNU TLS library - main runtime library
|
||||||
|
ii libgomp1:amd64 12.3.0-1ubuntu1~22.04 amd64 GCC OpenMP (GOMP) support library
|
||||||
|
ii libgpg-error0:amd64 1.43-3 amd64 GnuPG development runtime library
|
||||||
|
ii libgpm2:amd64 1.20.7-10build1 amd64 General Purpose Mouse - shared library
|
||||||
|
ii libgssapi-krb5-2:amd64 1.19.2-2ubuntu0.3 amd64 MIT Kerberos runtime libraries - krb5 GSS-API Mechanism
|
||||||
|
ii libhiredis0.14:amd64 0.14.1-2 amd64 minimalistic C client library for Redis
|
||||||
|
ii libhogweed6:amd64 3.7.3-1build2 amd64 low level cryptographic library (public-key cryptos)
|
||||||
|
ii libicu70:amd64 70.1-2 amd64 International Components for Unicode
|
||||||
|
ii libidn2-0:amd64 2.3.2-2build1 amd64 Internationalized domain names (IDNA2008/TR46) library
|
||||||
|
ii libio-pty-perl 1:1.15-2build2 amd64 Perl module for pseudo tty IO
|
||||||
|
ii libipc-run-perl 20200505.0-1 all Perl module for running processes
|
||||||
|
ii libipt2 2.0.5-1 amd64 Intel Processor Trace Decoder Library
|
||||||
|
ii libisl23:amd64 0.24-2build1 amd64 manipulating sets and relations of integer points bounded by linear constraints
|
||||||
|
ii libitm1:amd64 12.3.0-1ubuntu1~22.04 amd64 GNU Transactional Memory Library
|
||||||
|
ii libjansson4:amd64 2.13.1-1.1build3 amd64 C library for encoding, decoding and manipulating JSON data
|
||||||
|
ii libjq1:amd64 1.6-2.1ubuntu3 amd64 lightweight and flexible command-line JSON processor - shared library
|
||||||
|
ii libjsoncpp25:amd64 1.9.5-3 amd64 library for reading and writing JSON for C++
|
||||||
|
ii libk5crypto3:amd64 1.19.2-2ubuntu0.3 amd64 MIT Kerberos runtime libraries - Crypto Library
|
||||||
|
ii libkeyutils1:amd64 1.6.1-2ubuntu3 amd64 Linux Key Management Utilities (library)
|
||||||
|
ii libkrb5-3:amd64 1.19.2-2ubuntu0.3 amd64 MIT Kerberos runtime libraries
|
||||||
|
ii libkrb5support0:amd64 1.19.2-2ubuntu0.3 amd64 MIT Kerberos runtime libraries - Support library
|
||||||
|
ii libldap-2.5-0:amd64 2.5.16+dfsg-0ubuntu0.22.04.1 amd64 OpenLDAP libraries
|
||||||
|
ii liblsan0:amd64 12.3.0-1ubuntu1~22.04 amd64 LeakSanitizer -- a memory leak detector (runtime)
|
||||||
|
ii liblz4-1:amd64 1.9.3-2build2 amd64 Fast LZ compression algorithm library - runtime
|
||||||
|
ii liblzma5:amd64 5.2.5-2ubuntu1 amd64 XZ-format compression library
|
||||||
|
ii liblzo2-2:amd64 2.10-2build3 amd64 data compression library
|
||||||
|
ii libmagic-mgc 1:5.41-3ubuntu0.1 amd64 File type determination library using "magic" numbers (compiled magic file)
|
||||||
|
ii libmagic1:amd64 1:5.41-3ubuntu0.1 amd64 Recognize the type of data in a file using "magic" numbers - library
|
||||||
|
ii libmd0:amd64 1.0.4-1build1 amd64 message digest functions from BSD systems - shared library
|
||||||
|
ii libmount1:amd64 2.37.2-4ubuntu3 amd64 device mounting library
|
||||||
|
ii libmpc3:amd64 1.2.1-2build1 amd64 multiple precision complex floating-point library
|
||||||
|
ii libmpdec3:amd64 2.5.1-2build2 amd64 library for decimal floating point arithmetic (runtime library)
|
||||||
|
ii libmpfr6:amd64 4.1.0-3build3 amd64 multiple precision floating-point computation
|
||||||
|
ii libmspack0:amd64 0.10.1-2build2 amd64 library for Microsoft compression formats (shared library)
|
||||||
|
ii libncurses5:amd64 6.3-2ubuntu0.1 amd64 shared libraries for terminal handling (legacy version)
|
||||||
|
ii libncurses6:amd64 6.3-2ubuntu0.1 amd64 shared libraries for terminal handling
|
||||||
|
ii libncursesw6:amd64 6.3-2ubuntu0.1 amd64 shared libraries for terminal handling (wide character support)
|
||||||
|
ii libnettle8:amd64 3.7.3-1build2 amd64 low level cryptographic library (symmetric and one-way cryptos)
|
||||||
|
ii libnghttp2-14:amd64 1.43.0-1ubuntu0.1 amd64 library implementing HTTP/2 protocol (shared library)
|
||||||
|
ii libnl-3-200:amd64 3.5.0-0.1 amd64 library for dealing with netlink sockets
|
||||||
|
ii libnl-genl-3-200:amd64 3.5.0-0.1 amd64 library for dealing with netlink sockets - generic netlink
|
||||||
|
ii libnsl-dev:amd64 1.3.0-2build2 amd64 libnsl development files
|
||||||
|
ii libnsl2:amd64 1.3.0-2build2 amd64 Public client interface for NIS(YP) and NIS+
|
||||||
|
ii libonig5:amd64 6.9.7.1-2build1 amd64 regular expressions library
|
||||||
|
ii libp11-kit0:amd64 0.24.0-6build1 amd64 library for loading and coordinating access to PKCS#11 modules - runtime
|
||||||
|
ii libpam-modules-bin 1.4.0-11ubuntu2.3 amd64 Pluggable Authentication Modules for PAM - helper binaries
|
||||||
|
ii libpam-modules:amd64 1.4.0-11ubuntu2.3 amd64 Pluggable Authentication Modules for PAM
|
||||||
|
ii libpam-runtime 1.4.0-11ubuntu2.3 all Runtime support for the PAM library
|
||||||
|
ii libpam0g:amd64 1.4.0-11ubuntu2.3 amd64 Pluggable Authentication Modules library
|
||||||
|
ii libpcre2-8-0:amd64 10.39-3ubuntu0.1 amd64 New Perl Compatible Regular Expression Library- 8 bit runtime files
|
||||||
|
ii libpcre3:amd64 2:8.39-13ubuntu0.22.04.1 amd64 Old Perl 5 Compatible Regular Expression Library - runtime files
|
||||||
|
ii libperl5.34:amd64 5.34.0-3ubuntu1.3 amd64 shared Perl library
|
||||||
|
ii libpopt0:amd64 1.18-3build1 amd64 lib for parsing cmdline parameters
|
||||||
|
ii libprocps8:amd64 2:3.3.17-6ubuntu2.1 amd64 library for accessing process information from /proc
|
||||||
|
ii libpsl5:amd64 0.21.0-1.2build2 amd64 Library for Public Suffix List (shared libraries)
|
||||||
|
ii libpython2.7-minimal:amd64 2.7.18-13ubuntu1.1 amd64 Minimal subset of the Python language (version 2.7)
|
||||||
|
ii libpython3-stdlib:amd64 3.10.6-1~22.04 amd64 interactive high-level object-oriented language (default python3 version)
|
||||||
|
ii libpython3.10-minimal:amd64 3.10.12-1~22.04.3 amd64 Minimal subset of the Python language (version 3.10)
|
||||||
|
ii libpython3.10-stdlib:amd64 3.10.12-1~22.04.3 amd64 Interactive high-level object-oriented language (standard library, version 3.10)
|
||||||
|
ii libpython3.10:amd64 3.10.12-1~22.04.3 amd64 Shared Python runtime library (version 3.10)
|
||||||
|
ii libquadmath0:amd64 12.3.0-1ubuntu1~22.04 amd64 GCC Quad-Precision Math Library
|
||||||
|
ii libreadline8:amd64 8.1.2-1 amd64 GNU readline and history libraries, run-time libraries
|
||||||
|
ii librhash0:amd64 1.4.2-1ubuntu1 amd64 shared library for hash functions computing
|
||||||
|
ii librtmp1:amd64 2.4+20151223.gitfa8646d.1-2build4 amd64 toolkit for RTMP streams (shared library)
|
||||||
|
ii libsasl2-2:amd64 2.1.27+dfsg2-3ubuntu1.2 amd64 Cyrus SASL - authentication abstraction library
|
||||||
|
ii libsasl2-modules-db:amd64 2.1.27+dfsg2-3ubuntu1.2 amd64 Cyrus SASL - pluggable authentication modules (DB)
|
||||||
|
ii libseccomp2:amd64 2.5.3-2ubuntu2 amd64 high level interface to Linux seccomp filter
|
||||||
|
ii libselinux1:amd64 3.3-1build2 amd64 SELinux runtime shared libraries
|
||||||
|
ii libsemanage-common 3.3-1build2 all Common files for SELinux policy management libraries
|
||||||
|
ii libsemanage2:amd64 3.3-1build2 amd64 SELinux policy management library
|
||||||
|
ii libsensors-config 1:3.6.0-7ubuntu1 all lm-sensors configuration files
|
||||||
|
ii libsensors5:amd64 1:3.6.0-7ubuntu1 amd64 library to read temperature/voltage/fan sensors
|
||||||
|
ii libsepol2:amd64 3.3-1build1 amd64 SELinux library for manipulating binary security policies
|
||||||
|
ii libsigsegv2:amd64 2.13-1ubuntu3 amd64 Library for handling page faults in a portable way
|
||||||
|
ii libsmartcols1:amd64 2.37.2-4ubuntu3 amd64 smart column output alignment library
|
||||||
|
ii libsodium23:amd64 1.0.18-1build2 amd64 Network communication, cryptography and signaturing library
|
||||||
|
ii libsource-highlight-common 3.1.9-4.1build2 all architecture-independent files for source highlighting library
|
||||||
|
ii libsource-highlight4v5 3.1.9-4.1build2 amd64 source highlighting library
|
||||||
|
ii libsqlite3-0:amd64 3.37.2-2ubuntu0.1 amd64 SQLite 3 shared library
|
||||||
|
ii libss2:amd64 1.46.5-2ubuntu1.1 amd64 command-line interface parsing library
|
||||||
|
ii libssh-4:amd64 0.9.6-2ubuntu0.22.04.2 amd64 tiny C SSH library (OpenSSL flavor)
|
||||||
|
ii libssh2-1:amd64 1.10.0-3 amd64 SSH2 client-side library
|
||||||
|
ii libssl3:amd64 3.0.2-0ubuntu1.12 amd64 Secure Sockets Layer toolkit - shared libraries
|
||||||
|
ii libstdc++-11-dev:amd64 11.4.0-1ubuntu1~22.04 amd64 GNU Standard C++ Library v3 (development files)
|
||||||
|
ii libstdc++6:amd64 12.3.0-1ubuntu1~22.04 amd64 GNU Standard C++ Library v3
|
||||||
|
ii libsystemd0:amd64 249.11-0ubuntu3.11 amd64 systemd utility library
|
||||||
|
ii libtasn1-6:amd64 4.18.0-4build1 amd64 Manage ASN.1 structures (runtime)
|
||||||
|
ii libtime-duration-perl 1.21-1 all module for rounded or exact English expression of durations
|
||||||
|
ii libtimedate-perl 2.3300-2 all collection of modules to manipulate date/time information
|
||||||
|
ii libtinfo5:amd64 6.3-2ubuntu0.1 amd64 shared low-level terminfo library (legacy version)
|
||||||
|
ii libtinfo6:amd64 6.3-2ubuntu0.1 amd64 shared low-level terminfo library for terminal handling
|
||||||
|
ii libtirpc-common 1.3.2-2ubuntu0.1 all transport-independent RPC library - common files
|
||||||
|
ii libtirpc-dev:amd64 1.3.2-2ubuntu0.1 amd64 transport-independent RPC library - development files
|
||||||
|
ii libtirpc3:amd64 1.3.2-2ubuntu0.1 amd64 transport-independent RPC library
|
||||||
|
ii libtsan0:amd64 11.4.0-1ubuntu1~22.04 amd64 ThreadSanitizer -- a Valgrind-based detector of data races (runtime)
|
||||||
|
ii libubsan1:amd64 12.3.0-1ubuntu1~22.04 amd64 UBSan -- undefined behaviour sanitizer (runtime)
|
||||||
|
ii libudev1:amd64 249.11-0ubuntu3.11 amd64 libudev shared library
|
||||||
|
ii libunistring2:amd64 1.0-1 amd64 Unicode string library for C
|
||||||
|
ii libutempter0:amd64 1.2.1-2build2 amd64 privileged helper for utmp/wtmp updates (runtime)
|
||||||
|
ii libuuid1:amd64 2.37.2-4ubuntu3 amd64 Universally Unique ID library
|
||||||
|
ii libuv1:amd64 1.43.0-1 amd64 asynchronous event notification library - runtime library
|
||||||
|
ii libx11-6:amd64 2:1.7.5-1ubuntu0.3 amd64 X11 client-side library
|
||||||
|
ii libx11-data 2:1.7.5-1ubuntu0.3 all X11 client-side library
|
||||||
|
ii libx32asan6 11.4.0-1ubuntu1~22.04 amd64 AddressSanitizer -- a fast memory error detector (x32)
|
||||||
|
ii libx32atomic1 12.3.0-1ubuntu1~22.04 amd64 support library providing __atomic built-in functions (x32)
|
||||||
|
ii libx32gcc-11-dev 11.4.0-1ubuntu1~22.04 amd64 GCC support library (x32 development files)
|
||||||
|
ii libx32gcc-s1 12.3.0-1ubuntu1~22.04 amd64 GCC support library (x32)
|
||||||
|
ii libx32gomp1 12.3.0-1ubuntu1~22.04 amd64 GCC OpenMP (GOMP) support library (x32)
|
||||||
|
ii libx32itm1 12.3.0-1ubuntu1~22.04 amd64 GNU Transactional Memory Library (x32)
|
||||||
|
ii libx32quadmath0 12.3.0-1ubuntu1~22.04 amd64 GCC Quad-Precision Math Library (x32)
|
||||||
|
ii libx32stdc++-11-dev 11.4.0-1ubuntu1~22.04 amd64 GNU Standard C++ Library v3 (development files)
|
||||||
|
ii libx32stdc++6 12.3.0-1ubuntu1~22.04 amd64 GNU Standard C++ Library v3 (x32)
|
||||||
|
ii libx32ubsan1 12.3.0-1ubuntu1~22.04 amd64 UBSan -- undefined behaviour sanitizer (x32)
|
||||||
|
ii libxau6:amd64 1:1.0.9-1build5 amd64 X11 authorisation library
|
||||||
|
ii libxcb1:amd64 1.14-3ubuntu3 amd64 X C Binding
|
||||||
|
ii libxdmcp6:amd64 1:1.1.3-0ubuntu5 amd64 X11 Display Manager Control Protocol library
|
||||||
|
ii libxml2:amd64 2.9.13+dfsg-1ubuntu0.3 amd64 GNOME XML library
|
||||||
|
ii libxxhash0:amd64 0.8.1-1 amd64 shared library for xxhash
|
||||||
|
ii libyaml-0-2:amd64 0.2.2-1build2 amd64 Fast YAML 1.1 parser and emitter library
|
||||||
|
ii libzstd-dev:amd64 1.4.8+dfsg-3build1 amd64 fast lossless compression algorithm -- development files
|
||||||
|
ii libzstd1:amd64 1.4.8+dfsg-3build1 amd64 fast lossless compression algorithm
|
||||||
|
ii linux-libc-dev:amd64 5.15.0-91.101 amd64 Linux Kernel Headers for development
|
||||||
|
ii login 1:4.8.1-2ubuntu2.1 amd64 system login tools
|
||||||
|
ii logsave 1.46.5-2ubuntu1.1 amd64 save the output of a command in a log file
|
||||||
|
ii lsb-base 11.1.0ubuntu4 all Linux Standard Base init script functionality
|
||||||
|
ii lsb-release 11.1.0ubuntu4 all Linux Standard Base version reporting utility
|
||||||
|
ii lz4 1.9.3-2build2 amd64 Fast LZ compression algorithm library - tool
|
||||||
|
ii lzip 1.23-1 amd64 lossless data compressor based on the LZMA algorithm
|
||||||
|
ii lzop 1.04-2build2 amd64 fast compression program
|
||||||
|
ii make 4.3-4.1build1 amd64 utility for directing compilation
|
||||||
|
ii mawk 1.3.4.20200120-3 amd64 Pattern scanning and text processing language
|
||||||
|
ii media-types 7.0.0 all List of standard media types and their usual file extension
|
||||||
|
ii mksh 59c-16 amd64 MirBSD Korn Shell
|
||||||
|
ii moreutils 0.66-1 amd64 additional Unix utilities
|
||||||
|
ii mount 2.37.2-4ubuntu3 amd64 tools for mounting and manipulating filesystems
|
||||||
|
ii ncurses-base 6.3-2ubuntu0.1 all basic terminal type definitions
|
||||||
|
ii ncurses-bin 6.3-2ubuntu0.1 amd64 terminal-related programs and man pages
|
||||||
|
ii ncurses-term 6.3-2ubuntu0.1 all additional terminal type definitions
|
||||||
|
ii ninja-build 1.10.1-1 amd64 small build system closest in spirit to Make
|
||||||
|
ii openssl 3.0.2-0ubuntu1.12 amd64 Secure Sockets Layer toolkit - cryptographic utility
|
||||||
|
ii p7zip 16.02+dfsg-8 amd64 7zr file archiver with high compression ratio
|
||||||
|
ii parallel 20210822+ds-2 all build and execute command lines from standard input in parallel
|
||||||
|
ii passwd 1:4.8.1-2ubuntu2.1 amd64 change and administer password and group data
|
||||||
|
ii patch 2.7.6-7build2 amd64 Apply a diff file to an original
|
||||||
|
ii patchelf 0.14.3-1 amd64 modify properties of ELF executables
|
||||||
|
ii patchutils 0.4.2-1build2 amd64 Utilities to work with patches
|
||||||
|
ii pax-utils 1.2.9-1 amd64 Security-focused ELF files checking tool
|
||||||
|
ii paxctl 0.9-1build1 amd64 new PaX control program for using the PT_PAX_FLAGS marking
|
||||||
|
ii perl 5.34.0-3ubuntu1.3 amd64 Larry Wall's Practical Extraction and Report Language
|
||||||
|
ii perl-base 5.34.0-3ubuntu1.3 amd64 minimal Perl system
|
||||||
|
ii perl-modules-5.34 5.34.0-3ubuntu1.3 all Core Perl modules
|
||||||
|
ii procps 2:3.3.17-6ubuntu2.1 amd64 /proc file system utilities
|
||||||
|
ii python2-minimal 2.7.18-3 amd64 minimal subset of the Python2 language
|
||||||
|
ii python2.7-minimal 2.7.18-13ubuntu1.1 amd64 Minimal subset of the Python language (version 2.7)
|
||||||
|
ii python3 3.10.6-1~22.04 amd64 interactive high-level object-oriented language (default python3 version)
|
||||||
|
ii python3-minimal 3.10.6-1~22.04 amd64 minimal subset of the Python language (default python3 version)
|
||||||
|
ii python3-pyasn1 0.4.8-1 all ASN.1 library for Python (Python 3 module)
|
||||||
|
ii python3-pycryptodome 3.11.0+dfsg1-3build1 amd64 cryptographic Python library (Python 3)
|
||||||
|
ii python3-zstd 1.5.0.2-1build1 amd64 python bindings to Yann Collet ZSTD compression library
|
||||||
|
ii python3.10 3.10.12-1~22.04.3 amd64 Interactive high-level object-oriented language (version 3.10)
|
||||||
|
ii python3.10-minimal 3.10.12-1~22.04.3 amd64 Minimal subset of the Python language (version 3.10)
|
||||||
|
ii re2c 3.0-1 amd64 lexer generator for C, C++, Go and Rust
|
||||||
|
ii readline-common 8.1.2-1 all GNU readline and history libraries, common files
|
||||||
|
ii ripgrep 13.0.0-2ubuntu0.1 amd64 Recursively searches directories for a regex pattern
|
||||||
|
ii rpcsvc-proto 1.4.2-0ubuntu6 amd64 RPC protocol compiler and definitions
|
||||||
|
ii rsync 3.2.7-0ubuntu0.22.04.2 amd64 fast, versatile, remote (and local) file-copying tool
|
||||||
|
ii screen 4.9.0-1 amd64 terminal multiplexer with VT100/ANSI terminal emulation
|
||||||
|
ii sed 4.8-1ubuntu2 amd64 GNU stream editor for filtering/transforming text
|
||||||
|
ii sensible-utils 0.0.17 all Utilities for sensible alternative selection
|
||||||
|
ii sysstat 12.5.2-2ubuntu0.2 amd64 system performance tools for Linux
|
||||||
|
ii sysvinit-utils 3.01-1ubuntu1 amd64 System-V-like utilities
|
||||||
|
ii tar 1.34+dfsg-1ubuntu0.1.22.04.2 amd64 GNU version of the tar archiving utility
|
||||||
|
ii time 1.9-0.1build2 amd64 GNU time program for measuring CPU resource usage
|
||||||
|
ii ubuntu-keyring 2021.03.26 all GnuPG keys of the Ubuntu archive
|
||||||
|
ii ucf 3.0043 all Update Configuration File(s): preserve user changes to config files
|
||||||
|
ii universal-ctags 5.9.20210829.0-1 amd64 build tag file indexes of source code definitions
|
||||||
|
ii unzip 6.0-26ubuntu3.1 amd64 De-archiver for .zip files
|
||||||
|
ii usrmerge 25ubuntu2 all Convert the system to the merged /usr directories scheme
|
||||||
|
ii util-linux 2.37.2-4ubuntu3 amd64 miscellaneous system utilities
|
||||||
|
ii vim 2:8.2.3995-1ubuntu2.15 amd64 Vi IMproved - enhanced vi editor
|
||||||
|
ii vim-common 2:8.2.3995-1ubuntu2.15 all Vi IMproved - Common files
|
||||||
|
ii vim-runtime 2:8.2.3995-1ubuntu2.15 all Vi IMproved - Runtime files
|
||||||
|
ii wget 1.21.2-2ubuntu1 amd64 retrieves files from the web
|
||||||
|
ii xxd 2:8.2.3995-1ubuntu2.15 amd64 tool to make (or reverse) a hex dump
|
||||||
|
ii xz-utils 5.2.5-2ubuntu1 amd64 XZ-format compression utilities
|
||||||
|
ii yash 2.51-1 amd64 yet another shell
|
||||||
|
ii zip 3.0-12build2 amd64 Archiver for .zip files
|
||||||
|
ii zlib1g-dev:amd64 1:1.2.11.dfsg-2ubuntu9.2 amd64 compression library - development
|
||||||
|
ii zlib1g:amd64 1:1.2.11.dfsg-2ubuntu9.2 amd64 compression library - runtime
|
||||||
|
ii zlib1g:i386 1:1.2.11.dfsg-2ubuntu9.2 i386 compression library - runtime
|
||||||
|
ii zsh 5.8.1-1 amd64 shell with lots of features
|
||||||
|
ii zsh-common 5.8.1-1 all architecture independent files for Zsh
|
||||||
|
ii zstd 1.4.8+dfsg-3build1 amd64 fast lossless compression algorithm -- CLI tool
|
||||||
|
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|
||||||
|
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
|
||||||
|
||/ Name Version Architecture Description
|
||||||
|
|
||||||
|
Packages sorted by Installed-Size:
|
||||||
|
754338 ===== TOTAL (325 packages)
|
||||||
|
52747 gcc-11 amd64
|
||||||
|
34444 libicu70 amd64
|
||||||
|
32783 vim-runtime all
|
||||||
|
28891 g++-11 amd64
|
||||||
|
28445 libperl5.34 amd64
|
||||||
|
26284 cpp-11 amd64
|
||||||
|
20742 cmake amd64
|
||||||
|
18759 libstdc++-11-dev amd64
|
||||||
|
18468 git amd64
|
||||||
|
17671 perl-modules-5.34 all
|
||||||
|
15293 zsh-common all
|
||||||
|
13895 libgcc-11-dev amd64
|
||||||
|
13593 libc6 amd64
|
||||||
|
13037 libc6-dev amd64
|
||||||
|
12562 libc6-x32 amd64
|
||||||
|
12480 libc6 i386
|
||||||
|
12201 libc6-i386 amd64
|
||||||
|
11311 gdb amd64
|
||||||
|
10877 lib32stdc++-11-dev amd64
|
||||||
|
10439 binutils-x86-64-linux-gnu amd64
|
||||||
|
10390 libx32stdc++-11-dev amd64
|
||||||
|
9866 cmake-data all
|
||||||
|
8249 libc6-dev-x32 amd64
|
||||||
|
8119 libpython3.10-stdlib amd64
|
||||||
|
7948 lib32gcc-11-dev amd64
|
||||||
|
7734 perl-base amd64
|
||||||
|
7518 libasan6 amd64
|
||||||
|
7262 libc6-dev-i386 amd64
|
||||||
|
7255 libtsan0 amd64
|
||||||
|
7128 libmagic-mgc amd64
|
||||||
|
7112 coreutils amd64
|
||||||
|
6988 libx32gcc-11-dev amd64
|
||||||
|
6810 linux-libc-dev amd64
|
||||||
|
6733 dpkg amd64
|
||||||
|
6667 lib32asan6 amd64
|
||||||
|
6570 libx32asan6 amd64
|
||||||
|
5898 python3.10-minimal amd64
|
||||||
|
5828 libssl3 amd64
|
||||||
|
5768 libpython3.10 amd64
|
||||||
|
5106 libpython3.10-minimal amd64
|
||||||
|
4249 ncurses-term all
|
||||||
|
4147 ripgrep amd64
|
||||||
|
4141 apt amd64
|
||||||
|
4082 libglib2.0-0 amd64
|
||||||
|
3931 vim amd64
|
||||||
|
3643 python2.7-minimal amd64
|
||||||
|
3542 python3-pycryptodome amd64
|
||||||
|
3506 re2c amd64
|
||||||
|
3487 gojq amd64
|
||||||
|
3405 libmpfr6 amd64
|
||||||
|
3399 util-linux amd64
|
||||||
|
3347 libaria2-0 amd64
|
||||||
|
3198 libapt-pkg6.0 amd64
|
||||||
|
3013 libboost-regex1.74.0 amd64
|
||||||
|
2961 liblsan0 amd64
|
||||||
|
2943 parallel all
|
||||||
|
2801 elfutils amd64
|
||||||
|
2784 libpython2.7-minimal amd64
|
||||||
|
2776 libbinutils amd64
|
||||||
|
2755 libstdc++6 amd64
|
||||||
|
2676 libubsan1 amd64
|
||||||
|
2662 lib32stdc++6 amd64
|
||||||
|
2538 libc-bin amd64
|
||||||
|
2518 libx32ubsan1 amd64
|
||||||
|
2510 fd-find amd64
|
||||||
|
2499 lib32ubsan1 amd64
|
||||||
|
2468 zsh amd64
|
||||||
|
2450 libx32stdc++6 amd64
|
||||||
|
2428 fzf amd64
|
||||||
|
2396 7zip amd64
|
||||||
|
2325 passwd amd64
|
||||||
|
2284 libgnutls30 amd64
|
||||||
|
2191 ht amd64
|
||||||
|
2159 libisl23 amd64
|
||||||
|
2097 libxml2 amd64
|
||||||
|
2053 openssl amd64
|
||||||
|
2009 universal-ctags amd64
|
||||||
|
1958 git-man all
|
||||||
|
1864 bash amd64
|
||||||
|
1854 aria2 amd64
|
||||||
|
1750 libdb5.3 amd64
|
||||||
|
1746 libunistring2 amd64
|
||||||
|
1680 gawk amd64
|
||||||
|
1655 zstd amd64
|
||||||
|
1602 libsqlite3-0 amd64
|
||||||
|
1516 e2fsprogs amd64
|
||||||
|
1508 mksh amd64
|
||||||
|
1472 sysstat amd64
|
||||||
|
1464 bash-completion all
|
||||||
|
1445 hyperfine amd64
|
||||||
|
1430 libx11-data all
|
||||||
|
1429 yash amd64
|
||||||
|
1388 procps amd64
|
||||||
|
1387 libx11-6 amd64
|
||||||
|
1354 libgcrypt20 amd64
|
||||||
|
1343 ccache amd64
|
||||||
|
1328 libzstd-dev amd64
|
||||||
|
1292 libp11-kit0 amd64
|
||||||
|
1138 libpam-modules amd64
|
||||||
|
1052 libkrb5-3 amd64
|
||||||
|
1005 screen amd64
|
||||||
|
995 libsystemd0 amd64
|
||||||
|
990 p7zip amd64
|
||||||
|
984 wget amd64
|
||||||
|
960 tar amd64
|
||||||
|
888 login amd64
|
||||||
|
876 libarchive13 amd64
|
||||||
|
846 libzstd1 amd64
|
||||||
|
794 rsync amd64
|
||||||
|
791 busybox amd64
|
||||||
|
787 libcurl4 amd64
|
||||||
|
784 libbrotli1 amd64
|
||||||
|
771 libcurl3-gnutls amd64
|
||||||
|
743 python3-zstd amd64
|
||||||
|
735 libsepol2 amd64
|
||||||
|
729 libdw1 amd64
|
||||||
|
720 libtirpc-dev amd64
|
||||||
|
717 perl amd64
|
||||||
|
686 lib32quadmath0 amd64
|
||||||
|
683 libpcre3 amd64
|
||||||
|
646 ncurses-bin amd64
|
||||||
|
633 python3.10 amd64
|
||||||
|
621 libpcre2-8-0 amd64
|
||||||
|
620 findutils amd64
|
||||||
|
615 libonig5 amd64
|
||||||
|
610 libsource-highlight4v5 amd64
|
||||||
|
608 adduser all
|
||||||
|
592 zlib1g-dev amd64
|
||||||
|
574 libext2fs2 amd64
|
||||||
|
565 libldap-2.5-0 amd64
|
||||||
|
558 libtinfo6 amd64
|
||||||
|
544 libtinfo5 amd64
|
||||||
|
544 libgmp10 amd64
|
||||||
|
531 zip amd64
|
||||||
|
512 debconf all
|
||||||
|
504 binutils-common amd64
|
||||||
|
502 libbabeltrace1 amd64
|
||||||
|
496 grep amd64
|
||||||
|
486 libssh-4 amd64
|
||||||
|
461 libreadline8 amd64
|
||||||
|
455 libgssapi-krb5-2 amd64
|
||||||
|
443 curl amd64
|
||||||
|
433 libexpat1 amd64
|
||||||
|
424 diffutils amd64
|
||||||
|
422 libncursesw6 amd64
|
||||||
|
416 make amd64
|
||||||
|
402 libsodium23 amd64
|
||||||
|
394 base-files amd64
|
||||||
|
393 ncurses-base all
|
||||||
|
390 python3-pyasn1 all
|
||||||
|
390 ca-certificates all
|
||||||
|
389 mount amd64
|
||||||
|
382 vim-common all
|
||||||
|
382 libmount1 amd64
|
||||||
|
376 unzip amd64
|
||||||
|
372 xz-utils amd64
|
||||||
|
368 libssh2-1 amd64
|
||||||
|
356 libnettle8 amd64
|
||||||
|
350 ninja-build amd64
|
||||||
|
347 libudev1 amd64
|
||||||
|
347 libnsl-dev amd64
|
||||||
|
347 libjq1 amd64
|
||||||
|
336 libhogweed6 amd64
|
||||||
|
334 lib32gomp1 amd64
|
||||||
|
334 htop amd64
|
||||||
|
334 bsdutils amd64
|
||||||
|
329 libncurses6 amd64
|
||||||
|
328 sed amd64
|
||||||
|
324 gpgv amd64
|
||||||
|
324 cpio amd64
|
||||||
|
323 libblkid1 amd64
|
||||||
|
321 less amd64
|
||||||
|
320 libgomp1 amd64
|
||||||
|
320 libcrypt-dev amd64
|
||||||
|
318 libncurses5 amd64
|
||||||
|
313 libctf-nobfd0 amd64
|
||||||
|
312 libpam-runtime all
|
||||||
|
307 libsource-highlight-common all
|
||||||
|
306 libx32gomp1 amd64
|
||||||
|
300 libsemanage2 amd64
|
||||||
|
299 libc-dev-bin amd64
|
||||||
|
296 libquadmath0 amd64
|
||||||
|
295 libx32quadmath0 amd64
|
||||||
|
292 libk5crypto3 amd64
|
||||||
|
290 pax-utils amd64
|
||||||
|
290 liblzma5 amd64
|
||||||
|
280 xxd amd64
|
||||||
|
273 gcc-11-base amd64
|
||||||
|
272 gcc-12-base i386
|
||||||
|
272 gcc-12-base amd64
|
||||||
|
252 libuv1 amd64
|
||||||
|
252 libipc-run-perl all
|
||||||
|
252 libcrypt1 i386
|
||||||
|
250 libmpdec3 amd64
|
||||||
|
248 libpam-modules-bin amd64
|
||||||
|
245 rpcsvc-proto amd64
|
||||||
|
243 debianutils amd64
|
||||||
|
243 base-passwd amd64
|
||||||
|
240 moreutils amd64
|
||||||
|
240 gzip amd64
|
||||||
|
239 libctf0 amd64
|
||||||
|
235 libpam0g amd64
|
||||||
|
235 libjsoncpp25 amd64
|
||||||
|
232 ucf all
|
||||||
|
230 lz4 amd64
|
||||||
|
229 patch amd64
|
||||||
|
229 mawk amd64
|
||||||
|
229 libmagic1 amd64
|
||||||
|
225 libcrypt1 amd64
|
||||||
|
221 bfs amd64
|
||||||
|
220 libidn2-0 amd64
|
||||||
|
219 patchutils amd64
|
||||||
|
219 libtirpc3 amd64
|
||||||
|
219 librhash0 amd64
|
||||||
|
214 dash amd64
|
||||||
|
209 libsmartcols1 amd64
|
||||||
|
207 libselinux1 amd64
|
||||||
|
206 libxcb1 amd64
|
||||||
|
203 libnghttp2-14 amd64
|
||||||
|
200 usrmerge all
|
||||||
|
192 libelf1 amd64
|
||||||
|
189 libgpg-error0 amd64
|
||||||
|
182 patchelf amd64
|
||||||
|
180 libnl-3-200 amd64
|
||||||
|
171 zlib1g i386
|
||||||
|
170 libsasl2-2 amd64
|
||||||
|
167 libgcc-s1 i386
|
||||||
|
164 zlib1g amd64
|
||||||
|
164 libkrb5support0 amd64
|
||||||
|
163 lib32gcc-s1 amd64
|
||||||
|
161 lzip amd64
|
||||||
|
159 lzop amd64
|
||||||
|
159 liblzo2-2 amd64
|
||||||
|
156 libaudit1 amd64
|
||||||
|
145 libseccomp2 amd64
|
||||||
|
145 liblz4-1 amd64
|
||||||
|
144 libyaml-0-2 amd64
|
||||||
|
144 libcc1-0 amd64
|
||||||
|
141 librtmp1 amd64
|
||||||
|
140 libgcc-s1 amd64
|
||||||
|
136 libbsd0 amd64
|
||||||
|
135 libx32gcc-s1 amd64
|
||||||
|
134 libuuid1 amd64
|
||||||
|
133 libtasn1-6 amd64
|
||||||
|
133 init-system-helpers all
|
||||||
|
132 libipt2 amd64
|
||||||
|
131 libprocps8 amd64
|
||||||
|
126 time amd64
|
||||||
|
125 libmpc3 amd64
|
||||||
|
123 libtimedate-perl all
|
||||||
|
123 libnsl2 amd64
|
||||||
|
122 python3-minimal amd64
|
||||||
|
120 libpopt0 amd64
|
||||||
|
115 libitm1 amd64
|
||||||
|
114 bzip2 amd64
|
||||||
|
113 libss2 amd64
|
||||||
|
113 lib32itm1 amd64
|
||||||
|
113 binutils amd64
|
||||||
|
112 libc-ares2 amd64
|
||||||
|
110 libio-pty-perl amd64
|
||||||
|
105 python2-minimal amd64
|
||||||
|
105 libx32itm1 amd64
|
||||||
|
101 libcom-err2 amd64
|
||||||
|
100 libgdbm6 amd64
|
||||||
|
100 libbz2-1.0 amd64
|
||||||
|
100 jq amd64
|
||||||
|
97 media-types all
|
||||||
|
97 logsave amd64
|
||||||
|
97 libxxhash0 amd64
|
||||||
|
96 libsensors5 amd64
|
||||||
|
96 libmspack0 amd64
|
||||||
|
95 libpsl5 amd64
|
||||||
|
93 libsasl2-modules-db amd64
|
||||||
|
92 libhiredis0.14 amd64
|
||||||
|
91 libjansson4 amd64
|
||||||
|
90 python3 amd64
|
||||||
|
84 file amd64
|
||||||
|
83 sysvinit-utils amd64
|
||||||
|
82 cabextract amd64
|
||||||
|
80 readline-common all
|
||||||
|
79 libdebconfclient0 amd64
|
||||||
|
74 libasm1 amd64
|
||||||
|
71 libmd0 amd64
|
||||||
|
71 liberror-perl all
|
||||||
|
69 libffi8 amd64
|
||||||
|
67 libacl1 amd64
|
||||||
|
67 cpp amd64
|
||||||
|
66 lsb-release all
|
||||||
|
65 libgpm2 amd64
|
||||||
|
65 libdebuginfod1 amd64
|
||||||
|
65 libcap2 amd64
|
||||||
|
62 emacsen-common all
|
||||||
|
61 libnl-genl-3-200 amd64
|
||||||
|
59 sensible-utils all
|
||||||
|
58 lsb-base all
|
||||||
|
57 libattr1 amd64
|
||||||
|
51 libutempter0 amd64
|
||||||
|
51 hostname amd64
|
||||||
|
50 gcc amd64
|
||||||
|
49 libsigsegv2 amd64
|
||||||
|
47 libkeyutils1 amd64
|
||||||
|
45 libgdbm-compat4 amd64
|
||||||
|
45 libcap-ng0 amd64
|
||||||
|
45 libatomic1 amd64
|
||||||
|
43 libxdmcp6 amd64
|
||||||
|
43 libx32atomic1 amd64
|
||||||
|
42 libsensors-config all
|
||||||
|
41 ubuntu-keyring all
|
||||||
|
41 libdebuginfod-common all
|
||||||
|
39 libpython3-stdlib amd64
|
||||||
|
39 lib32atomic1 amd64
|
||||||
|
37 libsemanage-common all
|
||||||
|
37 chrpath amd64
|
||||||
|
35 libxau6 amd64
|
||||||
|
35 libtime-duration-perl all
|
||||||
|
32 libtirpc-common all
|
||||||
|
30 paxctl amd64
|
||||||
|
27 dh-elpa-helper all
|
||||||
|
23 libaudit-common all
|
||||||
|
20 distro-info-data all
|
||||||
|
16 g++ amd64
|
||||||
|
8 gcc-multilib amd64
|
||||||
|
6 gcc-11-multilib amd64
|
||||||
|
6 g++-multilib amd64
|
||||||
|
6 g++-11-multilib amd64
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#! /usr/bin/env bash
|
|
||||||
## vim:set ts=4 sw=4 et:
|
|
||||||
set -e; set -o pipefail
|
|
||||||
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
|
|
||||||
|
|
||||||
# run an interactive shell in the image
|
|
||||||
# using a rootless Podman container
|
|
||||||
|
|
||||||
image=upx-stubtools-20210104-v5
|
|
||||||
|
|
||||||
flags=( -ti --read-only --rm )
|
|
||||||
flags+=( --cap-drop=all ) # drop all capabilities
|
|
||||||
flags+=( --network=none ) # no network needed
|
|
||||||
flags+=( -e TERM="$TERM" ) # pass $TERM
|
|
||||||
if [[ 1 == 1 ]]; then
|
|
||||||
# run as user upx 2000:2000
|
|
||||||
flags+=( --user 2000 )
|
|
||||||
# map container user 0 to subuid-user 1, and map container user 2000 to current host user
|
|
||||||
flags+=( --uidmap=0:1:1 --uidmap=2000:0:1 )
|
|
||||||
# map container group 0 to subgid-group 1, and map container group 2000 to current host group
|
|
||||||
flags+=( --gidmap=0:1:1 --gidmap=2000:0:1 )
|
|
||||||
# NOTE: we mount the upx top-level directory read-write under /home/upx/src/upx
|
|
||||||
# INFO: SELinux users *may* have to add ":z" to the volume mount flags; check the docs!
|
|
||||||
flags+=( -v "${argv0dir}/../..:/home/upx/src/upx" )
|
|
||||||
flags+=( -w /home/upx/src/upx ) # working directory
|
|
||||||
else
|
|
||||||
# run as user root 0:0
|
|
||||||
# ONLY FOR DEBUGGING THE IMAGE
|
|
||||||
# map container user/group 0 to current host user/group
|
|
||||||
flags+=( --user 0 )
|
|
||||||
fi
|
|
||||||
|
|
||||||
podman run "${flags[@]}" "$image" bash -l
|
|
||||||
|
|
||||||
# now we can rebuild the UPX stubs:
|
|
||||||
# cd /home/upx/src/upx/src/stub
|
|
||||||
# # make sure that git is clean:
|
|
||||||
# git status .
|
|
||||||
# # remove stub files and make sure that they got deleted:
|
|
||||||
# make maintainer-clean
|
|
||||||
# git status .
|
|
||||||
# # rebuild
|
|
||||||
# make all
|
|
||||||
# # make sure that the stub files did rebuild correctly:
|
|
||||||
# git status .
|
|
||||||
# git diff .
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
FROM docker.io/library/ubuntu:22.04
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
|
||||||
ENV LANG=C.UTF-8
|
|
||||||
|
|
||||||
# install system packages
|
|
||||||
RUN dpkg --add-architecture i386 \
|
|
||||||
&& apt-get update && apt-get upgrade -y \
|
|
||||||
&& apt-get install -y --no-install-recommends \
|
|
||||||
aria2 ca-certificates git less libmpc3 libncurses5 make \
|
|
||||||
ncurses-term perl-base python2-minimal wget xz-utils \
|
|
||||||
libc6:i386 zlib1g:i386 \
|
|
||||||
# the following packages are not required for rebuilding the stubs,
|
|
||||||
# but they do make the image more convenient and also allow building
|
|
||||||
# the full UPX binary inside the container via CMake:
|
|
||||||
bzip2 cmake elfutils file g++ libzstd-dev lzop ninja-build patch \
|
|
||||||
patchelf pax-utils rsync unzip vim zip zlib1g-dev zsh zstd \
|
|
||||||
&& true
|
|
||||||
|
|
||||||
# manually install compat libs from Ubuntu 16.04
|
|
||||||
RUN cd /root \
|
|
||||||
&& aria2c --checksum=sha-256=2605f43f8047fc972855bb909f1dd7af761bbfd35ae559ad689b0d55a4236d69 \
|
|
||||||
'http://mirror.enzu.com/ubuntu/pool/main/g/gmp/libgmp10_6.1.0+dfsg-2_amd64.deb' \
|
|
||||||
&& aria2c --checksum=sha-256=3973a97387bbe0e8a775995c22861d8478edee2a594e8117970f635de25b2c8a \
|
|
||||||
'http://mirror.enzu.com/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.4-1_amd64.deb' \
|
|
||||||
&& mkdir packages \
|
|
||||||
&& for f in ./*.deb; do dpkg -x $f ./packages; done \
|
|
||||||
&& mv -v -n ./packages/usr/lib/x86_64-linux-gnu/lib* /usr/lib/x86_64-linux-gnu/ \
|
|
||||||
&& rm -rf ./*.deb ./packages \
|
|
||||||
&& ldconfig \
|
|
||||||
&& true
|
|
||||||
|
|
||||||
# install upx-stubtools into /usr/local/bin/bin-upx-20210104
|
|
||||||
RUN cd /root \
|
|
||||||
&& aria2c --checksum=sha-256=abcd8337cc656fe68d7bbb2ffe0f1e5ddce618688aa0e18c1ebcc40072843884 \
|
|
||||||
'https://github.com/upx/upx-stubtools/releases/download/v20210104/bin-upx-20210104.tar.xz' \
|
|
||||||
&& cd /usr/local/bin \
|
|
||||||
&& tar -xoaf /root/bin-upx-20210104.tar.xz \
|
|
||||||
&& rm /root/bin-upx-20210104.tar.xz \
|
|
||||||
&& true
|
|
||||||
|
|
||||||
# install previous UPX versions into /usr/local/bin
|
|
||||||
RUN cd /root \
|
|
||||||
&& wget -q https://github.com/upx/upx/releases/download/v3.91/upx-3.91-amd64_linux.tar.bz2 \
|
|
||||||
&& wget -q https://github.com/upx/upx/releases/download/v3.92/upx-3.92-amd64_linux.tar.xz \
|
|
||||||
&& wget -q https://github.com/upx/upx/releases/download/v3.93/upx-3.93-amd64_linux.tar.xz \
|
|
||||||
&& wget -q https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz \
|
|
||||||
&& wget -q https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz \
|
|
||||||
&& wget -q https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz \
|
|
||||||
&& for f in ./upx-*.tar.*; do tar -xoaf $f; done \
|
|
||||||
&& rm ./upx-*.tar.* \
|
|
||||||
&& d=upx-3.91-amd64_linux; ./$d/upx -d $d/upx -o /usr/local/bin/upx-3.91 \
|
|
||||||
&& d=upx-3.92-amd64_linux; ./$d/upx -d $d/upx -o /usr/local/bin/upx-3.92 \
|
|
||||||
&& d=upx-3.93-amd64_linux; ./$d/upx -d $d/upx -o /usr/local/bin/upx-3.93 \
|
|
||||||
&& d=upx-3.94-amd64_linux; ./$d/upx -d $d/upx -o /usr/local/bin/upx-3.94 \
|
|
||||||
&& d=upx-3.95-amd64_linux; ./$d/upx -d $d/upx -o /usr/local/bin/upx-3.95 \
|
|
||||||
&& d=upx-3.96-amd64_linux; ./$d/upx -d $d/upx -o /usr/local/bin/upx-3.96 \
|
|
||||||
&& rm -rf ./upx-*linux \
|
|
||||||
&& true
|
|
||||||
|
|
||||||
# create default user upx 2000:2000
|
|
||||||
RUN useradd upx -U --uid 2000 --shell /bin/bash -m \
|
|
||||||
&& mkdir -p /home/upx/.local/bin /home/upx/src/upx \
|
|
||||||
&& ln -s /usr/local/bin/bin-upx-20210104 /home/upx/.local/bin/bin-upx \
|
|
||||||
&& chown -R upx:upx /home/upx \
|
|
||||||
&& true
|
|
||||||
USER upx
|
|
||||||
Executable
+149
@@ -0,0 +1,149 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e
|
||||||
|
|
||||||
|
#
|
||||||
|
# build UPX "by hand", using a POSIX-compliant shell and
|
||||||
|
# a minimal number of compilation flags
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
#
|
||||||
|
|
||||||
|
# uses optional environment variables: AR, CC, CXX, OPTIMIZE, VERBOSE
|
||||||
|
# and optional settings for top_srcdir, obj_suffix and XXX_extra_flags
|
||||||
|
|
||||||
|
# shell init
|
||||||
|
### set -x # enable logging
|
||||||
|
DUALCASE=1; export DUALCASE # for MKS sh
|
||||||
|
test -n "${ZSH_VERSION+set}" && emulate sh # for zsh
|
||||||
|
my_argv0="$0"
|
||||||
|
|
||||||
|
# toolchain settings and compilation flags
|
||||||
|
AR="${AR:-ar}"
|
||||||
|
CC="${CC:-cc}"
|
||||||
|
CXX="${CXX:-c++ -std=gnu++17}"
|
||||||
|
# HINT: use "export AR=false" if "$AR rcs" does not work on your system; see below
|
||||||
|
if test "x$AR" = "x0" || test "x$AR" = "xfalse" || test "x$AR" = "x/bin/false"; then
|
||||||
|
AR="" # do not use $AR
|
||||||
|
fi
|
||||||
|
if test -z "${mandatory_flags+set}"; then
|
||||||
|
# protect against security threats caused by misguided compiler "optimizations"
|
||||||
|
mandatory_flags="-fno-strict-aliasing -fno-strict-overflow -funsigned-char"
|
||||||
|
fi
|
||||||
|
if test -z "${sensible_flags+set}"; then
|
||||||
|
# not mandatory but good practice when using <windows.h>:
|
||||||
|
sensible_flags="-DWIN32_LEAN_AND_MEAN"
|
||||||
|
if test "x$OPTIMIZE" != "x" && test "x$OPTIMIZE" != "x0"; then
|
||||||
|
# not mandatory and not minimal, but usually a good idea:
|
||||||
|
sensible_flags="-Wall -O2 $sensible_flags"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
CC="$CC $sensible_flags $mandatory_flags"
|
||||||
|
CXX="$CXX $sensible_flags $mandatory_flags"
|
||||||
|
|
||||||
|
# go to upx top-level directory
|
||||||
|
# HINT: set "top_srcdir" manually if your system does not have "readlink -f"
|
||||||
|
if test "x$top_srcdir" = "x"; then
|
||||||
|
my_argv0abs="$(readlink -fn "$my_argv0")"
|
||||||
|
test "x$my_argv0abs" = "x" && exit 1
|
||||||
|
my_argv0dir="$(dirname "$my_argv0abs")"
|
||||||
|
test "x$my_argv0dir" = "x" && exit 1
|
||||||
|
cd "$my_argv0dir/../.." || exit 1
|
||||||
|
else
|
||||||
|
cd "$top_srcdir" || exit 1
|
||||||
|
fi
|
||||||
|
top_srcdir="$(pwd)" # absolute
|
||||||
|
rel_top_srcdir=. # relative top_srcdir
|
||||||
|
echo "# current directory: '$(pwd)'"
|
||||||
|
test -f doc/upx.pod || exit 1 # sanity check
|
||||||
|
test -f src/version.h || exit 1 # sanity check
|
||||||
|
rm -rf ./build/by-hand # WARNING: existing build-directory gets deleted!
|
||||||
|
|
||||||
|
# helper function
|
||||||
|
run() {
|
||||||
|
if test 0 = 1; then
|
||||||
|
# DEBUG dry-run: print command, but don't actually run unless $1 is "+"
|
||||||
|
if test "x$1" = "x+"; then
|
||||||
|
shift; echo "$@"; "$@"; return
|
||||||
|
fi
|
||||||
|
shift; echo "$@"; return
|
||||||
|
fi
|
||||||
|
# print short info and run command
|
||||||
|
test "x$1" != "x" && test "x$1" != "x+" && echo "$1"
|
||||||
|
shift
|
||||||
|
if test "x$VERBOSE" != "x" && test "x$VERBOSE" != "x0"; then
|
||||||
|
# print full command
|
||||||
|
echo " $@"
|
||||||
|
fi
|
||||||
|
"$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# helper function
|
||||||
|
check_submodule() {
|
||||||
|
#local ff # "local" seems unsupported by some versions of ksh
|
||||||
|
for ff in COPYING LICENSE LICENSE.txt; do
|
||||||
|
if test -f "$rel_top_srcdir/vendor/$1/$ff"; then
|
||||||
|
# create and enter build directory; updates global $rel_top_srcdir
|
||||||
|
run "+" cd "$rel_top_srcdir" || exit 1
|
||||||
|
rel_top_srcdir=.
|
||||||
|
echo "#===== build $1 ====="
|
||||||
|
run "+" mkdir "build/by-hand/$1"
|
||||||
|
run "+" cd "build/by-hand/$1" || exit 1
|
||||||
|
rel_top_srcdir=../../..
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# build
|
||||||
|
upx_submodule_defs=
|
||||||
|
run "+" mkdir -p "build/by-hand"
|
||||||
|
if check_submodule bzip2; then
|
||||||
|
upx_submodule_defs="$upx_submodule_defs -DWITH_BZIP2"
|
||||||
|
test -z "${bzip2_extra_flags+set}" && bzip2_extra_flags="-DBZ_NO_STDIO"
|
||||||
|
for f in "$rel_top_srcdir"/vendor/bzip2/*.c; do
|
||||||
|
run "CC $f" $CC $bzip2_extra_flags -c "$f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if check_submodule ucl; then
|
||||||
|
#upx_submodule_defs="$upx_submodule_defs -DWITH_UCL"
|
||||||
|
test -z "${ucl_extra_flags+set}" && ucl_extra_flags=
|
||||||
|
for f in "$rel_top_srcdir"/vendor/ucl/src/*.c; do
|
||||||
|
run "CC $f" $CC -I"$rel_top_srcdir"/vendor/ucl/include -I"$rel_top_srcdir"/vendor/ucl $ucl_extra_flags -c "$f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if check_submodule zlib; then
|
||||||
|
#upx_submodule_defs="$upx_submodule_defs -DWITH_ZLIB"
|
||||||
|
test -z "${zlib_extra_flags+set}" && zlib_extra_flags="-DHAVE_UNISTD_H -DHAVE_VSNPRINTF"
|
||||||
|
for f in "$rel_top_srcdir"/vendor/zlib/*.c; do
|
||||||
|
run "CC $f" $CC $zlib_extra_flags -c "$f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if check_submodule zstd; then
|
||||||
|
upx_submodule_defs="$upx_submodule_defs -DWITH_ZSTD"
|
||||||
|
test -z "${zstd_extra_flags+set}" && zstd_extra_flags="-DDYNAMIC_BMI2=0 -DZSTD_DISABLE_ASM"
|
||||||
|
for f in "$rel_top_srcdir"/vendor/zstd/lib/*/*.c; do
|
||||||
|
run "CC $f" $CC $zstd_extra_flags -c "$f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
run "+" cd "$rel_top_srcdir" || exit 1
|
||||||
|
rel_top_srcdir=.
|
||||||
|
echo "#===== build UPX ====="
|
||||||
|
run "+" cd "build/by-hand" || exit 1
|
||||||
|
rel_top_srcdir=../..
|
||||||
|
for f in "$rel_top_srcdir"/src/*.cpp "$rel_top_srcdir"/src/*/*.cpp; do
|
||||||
|
run "CXX $f" $CXX -I"$rel_top_srcdir"/vendor $upx_submodule_defs -c "$f"
|
||||||
|
done
|
||||||
|
# echo "#===== link UPX ====="
|
||||||
|
test "x$obj_suffix" = "x" && obj_suffix=.o
|
||||||
|
if test "x$AR" = "x"; then
|
||||||
|
# link without using $AR
|
||||||
|
run "CXX upx" $CXX -o upx *${obj_suffix} */*${obj_suffix}
|
||||||
|
else
|
||||||
|
run "AR libupx" $AR rcs ${AR_LIBFILE:-libupx_submodules.a} */*${obj_suffix}
|
||||||
|
run "CXX upx" $CXX -o upx *${obj_suffix} -L. -lupx_submodules
|
||||||
|
fi
|
||||||
|
echo "# current directory: '$(pwd)'"
|
||||||
|
ls -l upx*
|
||||||
|
|
||||||
|
echo "# All done."
|
||||||
@@ -32,6 +32,7 @@ LC_ALL=C sort -z | xargs -0r perl -n -e '
|
|||||||
}
|
}
|
||||||
if (m,\t,) {
|
if (m,\t,) {
|
||||||
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
|
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
|
||||||
|
elsif ($ARGV =~ m,\.mk$,) { }
|
||||||
elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { }
|
elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { }
|
||||||
elsif ($ARGV =~ m,/src/stub/src/arch/.*/lzma\w+\.S$,) { }
|
elsif ($ARGV =~ m,/src/stub/src/arch/.*/lzma\w+\.S$,) { }
|
||||||
else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); }
|
else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); }
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ git ls-files --full-name -z | perl -0 -n -e '
|
|||||||
}
|
}
|
||||||
if (m,\t,) {
|
if (m,\t,) {
|
||||||
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
|
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
|
||||||
|
elsif ($ARGV =~ m,\.mk$,) { }
|
||||||
elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { }
|
elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { }
|
||||||
elsif ($ARGV =~ m,/src/stub/src/arch/.*/lzma\w+\.S$,) { }
|
elsif ($ARGV =~ m,/src/stub/src/arch/.*/lzma\w+\.S$,) { }
|
||||||
else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); }
|
else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); }
|
||||||
|
|||||||
@@ -3,23 +3,24 @@
|
|||||||
set -e; set -o pipefail
|
set -e; set -o pipefail
|
||||||
|
|
||||||
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
|
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
|
||||||
|
#
|
||||||
# NOTE: we are using clang-format-10.0.1 from upx-stubtools
|
# NOTE: we are using clang-format-15.0.6 from upx-stubtools
|
||||||
# see https://github.com/upx/upx-stubtools/releases
|
# see https://github.com/upx/upx-stubtools/releases
|
||||||
|
#
|
||||||
# NOTE: we use .clang-format config from upx.git/.clang-format
|
# NOTE: we use .clang-format config from upx.git/.clang-format
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
|
||||||
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
||||||
UPX_CLANG_FORMAT="$HOME/local/bin/bin-upx/clang-format-10.0.1"
|
UPX_CLANG_FORMAT="$HOME/local/bin/bin-upx/clang-format-15.0.6"
|
||||||
fi
|
fi
|
||||||
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
||||||
UPX_CLANG_FORMAT="$HOME/.local/bin/bin-upx/clang-format-10.0.1"
|
UPX_CLANG_FORMAT="$HOME/.local/bin/bin-upx/clang-format-15.0.6"
|
||||||
fi
|
fi
|
||||||
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
||||||
UPX_CLANG_FORMAT="$HOME/bin/bin-upx/clang-format-10.0.1"
|
UPX_CLANG_FORMAT="$HOME/bin/bin-upx/clang-format-15.0.6"
|
||||||
fi
|
fi
|
||||||
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
|
||||||
echo "ERROR: $0: cannot find clang-format-10.0.1"
|
echo "ERROR: $0: cannot find clang-format-15.0.6"
|
||||||
echo "ERROR: $0: please visit https://github.com/upx/upx-stubtools"
|
echo "ERROR: $0: please visit https://github.com/upx/upx-stubtools"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -29,4 +30,4 @@ ulimit -v 1048576 || true
|
|||||||
|
|
||||||
#echo $UPX_CLANG_FORMAT
|
#echo $UPX_CLANG_FORMAT
|
||||||
exec "$UPX_CLANG_FORMAT" -style=file "$@"
|
exec "$UPX_CLANG_FORMAT" -style=file "$@"
|
||||||
exit 1
|
exit 99
|
||||||
Executable
+75
@@ -0,0 +1,75 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs=$(readlink -fn "$argv0"); argv0dir=$(dirname "$argv0abs")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
#
|
||||||
|
# mimic running "ctest", i.e. the "test" section of CMakeLists.txt; does not redirect stdout
|
||||||
|
#
|
||||||
|
# requires:
|
||||||
|
# $upx_exe (required, but with convenience fallback "./upx")
|
||||||
|
# optional settings:
|
||||||
|
# $upx_exe_runner (e.g. "qemu-x86_64 -cpu Nehalem" or "valgrind")
|
||||||
|
#
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# init & checks
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# upx_exe
|
||||||
|
[[ -z $upx_exe && -f ./upx && -x ./upx ]] && upx_exe=./upx # convenience fallback
|
||||||
|
if [[ -z $upx_exe ]]; then echo "UPX-ERROR: please set \$upx_exe"; exit 1; fi
|
||||||
|
if [[ ! -f $upx_exe ]]; then echo "UPX-ERROR: file '$upx_exe' does not exist"; exit 1; fi
|
||||||
|
upx_exe=$(readlink -fn "$upx_exe") # make absolute
|
||||||
|
[[ -f $upx_exe ]] || exit 1
|
||||||
|
upx_run=()
|
||||||
|
if [[ -n $upx_exe_runner ]]; then
|
||||||
|
# usage examples:
|
||||||
|
# export upx_exe_runner="qemu-x86_64 -cpu Nehalem"
|
||||||
|
# export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet"
|
||||||
|
# export upx_exe_runner="wine"
|
||||||
|
IFS=' ' read -r -a upx_run <<< "$upx_exe_runner" # split at spaces into array
|
||||||
|
elif [[ -n $CMAKE_CROSSCOMPILING_EMULATOR ]]; then
|
||||||
|
IFS=';' read -r -a upx_run <<< "$CMAKE_CROSSCOMPILING_EMULATOR" # split at semicolons into array
|
||||||
|
fi
|
||||||
|
upx_runner=( "${upx_run[@]}" )
|
||||||
|
upx_run+=( "$upx_exe" )
|
||||||
|
echo "upx_run='${upx_run[*]}'"
|
||||||
|
|
||||||
|
# upx_run sanity check
|
||||||
|
if ! "${upx_run[@]}" --version-short >/dev/null; then echo "UPX-ERROR: FATAL: upx --version-short FAILED"; exit 1; fi
|
||||||
|
if ! "${upx_run[@]}" -L >/dev/null 2>&1; then echo "UPX-ERROR: FATAL: upx -L FAILED"; exit 1; fi
|
||||||
|
if ! "${upx_run[@]}" --help >/dev/null; then echo "UPX-ERROR: FATAL: upx --help FAILED"; exit 1; fi
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# see CMakeLists.txt
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
export UPX="--no-color --no-progress"
|
||||||
|
|
||||||
|
"${upx_run[@]}" --version
|
||||||
|
"${upx_run[@]}" --help
|
||||||
|
"${upx_run[@]}" --sysinfo -v
|
||||||
|
|
||||||
|
exe=".out"
|
||||||
|
upx_self_exe=$upx_exe
|
||||||
|
fo="--force-overwrite"
|
||||||
|
|
||||||
|
"${upx_run[@]}" -3 "${upx_self_exe}" ${fo} -o upx-packed${exe}
|
||||||
|
"${upx_run[@]}" -3 --nrv2b "${upx_self_exe}" ${fo} -o upx-packed-n2b${exe}
|
||||||
|
"${upx_run[@]}" -3 --nrv2d "${upx_self_exe}" ${fo} -o upx-packed-n2d${exe}
|
||||||
|
"${upx_run[@]}" -3 --nrv2e "${upx_self_exe}" ${fo} -o upx-packed-n2e${exe}
|
||||||
|
"${upx_run[@]}" -1 --lzma "${upx_self_exe}" ${fo} -o upx-packed-lzma${exe}
|
||||||
|
|
||||||
|
"${upx_run[@]}" -l upx-packed${exe} upx-packed-n2b${exe} upx-packed-n2d${exe} upx-packed-n2e${exe} upx-packed-lzma${exe}
|
||||||
|
"${upx_run[@]}" --fileinfo upx-packed${exe} upx-packed-n2b${exe} upx-packed-n2d${exe} upx-packed-n2e${exe} upx-packed-lzma${exe}
|
||||||
|
"${upx_run[@]}" -t upx-packed${exe} upx-packed-n2b${exe} upx-packed-n2d${exe} upx-packed-n2e${exe} upx-packed-lzma${exe}
|
||||||
|
"${upx_run[@]}" -d upx-packed${exe} ${fo} -o upx-unpacked${exe}
|
||||||
|
|
||||||
|
set -x
|
||||||
|
"${upx_runner[@]}" ./upx-unpacked${exe} --version-short
|
||||||
|
"${upx_runner[@]}" ./upx-packed${exe} --version-short
|
||||||
|
|
||||||
|
echo "All done."
|
||||||
Executable
+400
@@ -0,0 +1,400 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs=$(readlink -fn "$argv0"); argv0dir=$(dirname "$argv0abs")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
#
|
||||||
|
# test file system behaviour with symlinks; requires:
|
||||||
|
# $upx_exe (required, but with convenience fallback "./upx")
|
||||||
|
# optional settings:
|
||||||
|
# $upx_exe_runner (e.g. "qemu-x86_64 -cpu Nehalem" or "valgrind")
|
||||||
|
#
|
||||||
|
|
||||||
|
# IMPORTANT NOTE: do NOT run as user root!!
|
||||||
|
# IMPORTANT NOTE: this script only works on Unix!!
|
||||||
|
umask 0022
|
||||||
|
|
||||||
|
# disable on macOS for now, see https://github.com/upx/upx/issues/612
|
||||||
|
if [[ "$(uname)" == Darwin ]]; then
|
||||||
|
echo "$0: SKIPPED"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
id || true
|
||||||
|
echo "PWD='$PWD'"
|
||||||
|
if [[ $UID == 0 || $EUID == 0 ]]; then
|
||||||
|
echo "ERROR: do not run as root: UID=$UID EUID=$EUID"
|
||||||
|
exit 91
|
||||||
|
fi
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# init & checks
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# upx_exe
|
||||||
|
[[ -z $upx_exe && -f ./upx && -x ./upx ]] && upx_exe=./upx # convenience fallback
|
||||||
|
if [[ -z $upx_exe ]]; then echo "UPX-ERROR: please set \$upx_exe"; exit 1; fi
|
||||||
|
if [[ ! -f $upx_exe ]]; then echo "UPX-ERROR: file '$upx_exe' does not exist"; exit 1; fi
|
||||||
|
upx_exe=$(readlink -fn "$upx_exe") # make absolute
|
||||||
|
[[ -f $upx_exe ]] || exit 1
|
||||||
|
upx_run=()
|
||||||
|
if [[ -n $upx_exe_runner ]]; then
|
||||||
|
# usage examples:
|
||||||
|
# export upx_exe_runner="qemu-x86_64 -cpu Nehalem"
|
||||||
|
# export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet"
|
||||||
|
# export upx_exe_runner="wine"
|
||||||
|
IFS=' ' read -r -a upx_run <<< "$upx_exe_runner" # split at spaces into array
|
||||||
|
elif [[ -n $CMAKE_CROSSCOMPILING_EMULATOR ]]; then
|
||||||
|
IFS=';' read -r -a upx_run <<< "$CMAKE_CROSSCOMPILING_EMULATOR" # split at semicolons into array
|
||||||
|
fi
|
||||||
|
upx_run+=( "$upx_exe" )
|
||||||
|
echo "upx_run='${upx_run[*]}'"
|
||||||
|
|
||||||
|
# upx_run sanity check
|
||||||
|
if ! "${upx_run[@]}" --version-short >/dev/null; then echo "UPX-ERROR: FATAL: upx --version-short FAILED"; exit 1; fi
|
||||||
|
if ! "${upx_run[@]}" -L >/dev/null 2>&1; then echo "UPX-ERROR: FATAL: upx -L FAILED"; exit 1; fi
|
||||||
|
if ! "${upx_run[@]}" --help >/dev/null; then echo "UPX-ERROR: FATAL: upx --help FAILED"; exit 1; fi
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# util
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
exit_code=0
|
||||||
|
num_errors=0
|
||||||
|
all_errors=
|
||||||
|
|
||||||
|
failed() {
|
||||||
|
####exit $1
|
||||||
|
# log error and keep going
|
||||||
|
exit_code=1
|
||||||
|
local a="$(basename "$(dirname "$PWD")")"
|
||||||
|
local b="$(basename "$PWD")"
|
||||||
|
let num_errors+=1 || true
|
||||||
|
all_errors="${all_errors} $a/$b/$1"
|
||||||
|
echo " FAILED $b/$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_file() {
|
||||||
|
local f
|
||||||
|
for f in "$@"; do
|
||||||
|
[[ ! -L "$f" && -f "$f" ]] && continue
|
||||||
|
echo "failed '$f': not a regular file"
|
||||||
|
failed 21
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_symlink_to_file() {
|
||||||
|
local f
|
||||||
|
for f in "$@"; do
|
||||||
|
[[ -L "$f" && -f "$f" ]] && continue
|
||||||
|
echo "failed '$f': not a symlink to file"
|
||||||
|
failed 22
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_symlink_to_dir() {
|
||||||
|
local f
|
||||||
|
for f in "$@"; do
|
||||||
|
[[ -L "$f" && -d "$f" ]] && continue
|
||||||
|
echo "failed '$f': not a symlink to dir"
|
||||||
|
failed 23
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_symlink_dangling() {
|
||||||
|
local f
|
||||||
|
for f in "$@"; do
|
||||||
|
[[ -L "$f" && ! -e "$f" ]] && continue
|
||||||
|
echo "failed '$f': not a dangling symlink"
|
||||||
|
failed 24
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
copy_directory() {
|
||||||
|
if command -v rsync >/dev/null; then
|
||||||
|
rsync -aH "$1/" "$2"
|
||||||
|
else
|
||||||
|
cp -ai "$1" "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
create_files() {
|
||||||
|
# clean
|
||||||
|
local d
|
||||||
|
for d in z_dir_1 z_dir_2 z_dir_3 z_dir_4; do
|
||||||
|
if [[ -d $d ]]; then
|
||||||
|
chmod -R +rwx "./$d"
|
||||||
|
rm -rf "./$d"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
mkdir z_dir_1
|
||||||
|
cd z_dir_1
|
||||||
|
: > z_file
|
||||||
|
ln -s z_file z_symlink_file
|
||||||
|
: > z_file_link_1
|
||||||
|
ln z_file_link_1 z_file_link_2
|
||||||
|
ln -s z_file_link_1 z_symlink_file_link
|
||||||
|
mkdir z_dir
|
||||||
|
ln -s z_dir z_symlink_dir
|
||||||
|
ln -s z_file_missing z_symlink_dangling
|
||||||
|
assert_file z_file*
|
||||||
|
assert_symlink_to_file z_symlink_file
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# write-protect z_dir_2/z_file*
|
||||||
|
copy_directory z_dir_1 z_dir_2
|
||||||
|
chmod a-w z_dir_2/z_file*
|
||||||
|
|
||||||
|
# write-protect z_dir_3 itself
|
||||||
|
copy_directory z_dir_1 z_dir_3
|
||||||
|
chmod a-w z_dir_3
|
||||||
|
|
||||||
|
# write-protect everything in z_dir_4
|
||||||
|
copy_directory z_dir_1 z_dir_4
|
||||||
|
chmod -R a-w z_dir_4
|
||||||
|
}
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
#
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
#set -x # debug
|
||||||
|
|
||||||
|
export UPX="--prefer-ucl --no-color --no-progress"
|
||||||
|
export UPX_DEBUG_DISABLE_GITREV_WARNING=1
|
||||||
|
export UPX_DEBUG_DOCTEST_VERBOSE=0
|
||||||
|
export NO_COLOR=1
|
||||||
|
|
||||||
|
testsuite_header() {
|
||||||
|
local x='==========='; x="$x$x$x$x$x$x$x"
|
||||||
|
echo -e "\n${x}\n${1}\n${x}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
enter_dir() {
|
||||||
|
cd "$1" || exit 1
|
||||||
|
echo "===== $(basename "$PWD")"
|
||||||
|
}
|
||||||
|
leave_dir() {
|
||||||
|
echo "===== $(basename "$PWD") files"
|
||||||
|
ls -lA
|
||||||
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
|
# create a tmpdir in current directory
|
||||||
|
tmpdir="$(mktemp -d tmp-upx-test-XXXXXX)"
|
||||||
|
cd "./$tmpdir" || exit 1
|
||||||
|
|
||||||
|
if [[ -f /bin/ls ]]; then
|
||||||
|
test_file="$(readlink -fn /bin/ls)"
|
||||||
|
else
|
||||||
|
test_file="$(readlink -fn /usr/bin/env)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
testsuite_header "default"
|
||||||
|
flags="-qq -1 --no-filter"
|
||||||
|
mkdir default
|
||||||
|
cd default
|
||||||
|
create_files
|
||||||
|
enter_dir z_dir_1
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new || failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file && failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 && failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file && failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link && failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_2
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new || failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file && failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 && failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file && failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link && failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_3
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new && failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file && failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 && failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file && failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link && failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_4
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new && failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file && failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 && failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file && failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link && failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
testsuite_header "force-overwrite"
|
||||||
|
flags="-qq -1 --no-filter --force-overwrite"
|
||||||
|
mkdir force-overwrite
|
||||||
|
cd force-overwrite
|
||||||
|
create_files
|
||||||
|
enter_dir z_dir_1
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new || failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file || failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 || failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir || failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling || failed 18
|
||||||
|
assert_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_file z_symlink_dir
|
||||||
|
assert_file z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_2
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new || failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file || failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 || failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir || failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling || failed 18
|
||||||
|
assert_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_file z_symlink_dir
|
||||||
|
assert_file z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_3
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new && failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file || failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 || failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_4
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new && failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file || failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 || failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
if [[ 1 == 1 ]]; then
|
||||||
|
testsuite_header "link"
|
||||||
|
flags="-qq -1 --no-filter --link"
|
||||||
|
mkdir link
|
||||||
|
cd link
|
||||||
|
create_files
|
||||||
|
enter_dir z_dir_1
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new || failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file || failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 || failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir || failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling || failed 18
|
||||||
|
assert_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_file z_symlink_dir
|
||||||
|
assert_file z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_2
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new || failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file && failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 && failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir || failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling || failed 18
|
||||||
|
assert_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_file z_symlink_dir
|
||||||
|
assert_file z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_3
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new && failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file || failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 || failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
enter_dir z_dir_4
|
||||||
|
"${upx_run[@]}" $flags z_symlink_file && failed 10
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_new && failed 11
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_dir && failed 12
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file && failed 13
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_file_link_1 && failed 14
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file || failed 15
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_file_link || failed 16
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dir && failed 17
|
||||||
|
"${upx_run[@]}" $flags "$test_file" -o z_symlink_dangling && failed 18
|
||||||
|
assert_symlink_to_file z_symlink_file z_symlink_file_link
|
||||||
|
assert_symlink_to_dir z_symlink_dir
|
||||||
|
assert_symlink_dangling z_symlink_dangling
|
||||||
|
leave_dir
|
||||||
|
cd ..
|
||||||
|
fi
|
||||||
|
|
||||||
|
# clean up
|
||||||
|
cd ..
|
||||||
|
chmod -R +rwx "./$tmpdir"
|
||||||
|
rm -rf "./$tmpdir"
|
||||||
|
|
||||||
|
if [[ $exit_code == 0 ]]; then
|
||||||
|
echo "UPX testsuite passed. All done."
|
||||||
|
else
|
||||||
|
echo "UPX-ERROR: UPX testsuite FAILED:${all_errors}"
|
||||||
|
echo "UPX-ERROR: UPX testsuite FAILED with $num_errors error(s). See log file."
|
||||||
|
fi
|
||||||
|
exit $exit_code
|
||||||
+209
@@ -0,0 +1,209 @@
|
|||||||
|
########## begin .sha256sums.recreate
|
||||||
|
expected_sha256sums__t010_decompressed="\
|
||||||
|
24158f78c34c4ef94bb7773a6dda7231d289be76c2f5f60e8b9ddb3f800c100e *amd64-linux.elf/upx-3.91
|
||||||
|
24808d572483f4cd713d66894b3da406755038737007a78b076528e6407e3132 *amd64-linux.elf/upx-3.95
|
||||||
|
d88eaad0528bcecec9f51cbe015a117c8cf350a3f6d8308f2b0517d4fd19d189 *amd64-win64.pe/upx-3.95.exe
|
||||||
|
f7279729eb975e4238f8b8ee56fefa41ccbeb35ef0ffe4c34f8047baab78fff5 *arm-linux.elf/upx-3.95
|
||||||
|
e09df2a69f88c692138447f274ba7f99cdd11f8696c71ac8d3761606c95ab5c5 *arm-wince.pe/upx-3.91.exe
|
||||||
|
ce81113f8a4ff1cd806811cb80ab8bea5c9c6fbced47451c7f07e50700f9817b *arm64-linux.elf/upx-3.95
|
||||||
|
b1c1c38d50007616aaf8e942839648c80a6111023e0b411e5fa7a06c543aeb4a *armeb-linux.elf/upx-3.91
|
||||||
|
84b90eb0d617571fe4885639925b35ca6a61060cb2616bb5bf729b4d701653e4 *armeb-linux.elf/upx-3.95
|
||||||
|
bcac77a287289301a45fde9a75e4e6c9ad7f8d57856bae6eafaae12ae4445a34 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
7d331e508449497f64cd47abdd3f00f70307f508ad3fd692d333feb97beccead *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
730a513b72a094697f827e4ac1a4f8ef58a614fc7a7ad448fa58d60cd89af7ed *i386-linux.elf/upx-3.91
|
||||||
|
a1f3e5ffa7b2cfebe1e475ac1f4c7683b1b8b4e292aa0d04386cc0314dd162c9 *i386-linux.elf/upx-3.95
|
||||||
|
e90fb09a808334c2674996760d42c82f8352e3f671f6b66c11481e772785c4d2 *i386-win32.pe/upx-3.91.exe
|
||||||
|
07bd50c1d80f6ff651228e6fc0ba3a583a472915772244f232696b34156a9d27 *i386-win32.pe/upx-3.95.exe
|
||||||
|
8e5333ea040f5594d3e67d5b09e005d52b3a52ef55099a7c11d7e39ead38e66d *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
8902f38ec3d95d8e077e3ab5fdbb5bad408859913a35deb87041f4f053cd6605 *mips-linux.elf/upx-3.95
|
||||||
|
c3f44b4d00a87384c03a6f9e7aec809c1addfe3e271244d38a474f296603088c *mipsel-linux.elf/upx-3.91
|
||||||
|
dd1496bc4e9c32a5d5dd47e3eaabf7b134ca001d48807eebfd3d5e28c8a2ab58 *mipsel-linux.elf/upx-3.95
|
||||||
|
b8c35fa2956da17ca505956e9f5017bb5f3a746322647e24ccb8ff28059cafa4 *powerpc-linux.elf/upx-3.91
|
||||||
|
2bc00a51daa0bada19a8fa1bd2c227a8596844fa1b0aa3611087f195072700e2 *powerpc-linux.elf/upx-3.95
|
||||||
|
a0950546dc17fca9437219431d8ddb0249ce5b08e899e0c799a87ac982adee70 *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t020_canonicalized="\
|
||||||
|
24158f78c34c4ef94bb7773a6dda7231d289be76c2f5f60e8b9ddb3f800c100e *amd64-linux.elf/upx-3.91
|
||||||
|
24808d572483f4cd713d66894b3da406755038737007a78b076528e6407e3132 *amd64-linux.elf/upx-3.95
|
||||||
|
d88eaad0528bcecec9f51cbe015a117c8cf350a3f6d8308f2b0517d4fd19d189 *amd64-win64.pe/upx-3.95.exe
|
||||||
|
f7279729eb975e4238f8b8ee56fefa41ccbeb35ef0ffe4c34f8047baab78fff5 *arm-linux.elf/upx-3.95
|
||||||
|
e09df2a69f88c692138447f274ba7f99cdd11f8696c71ac8d3761606c95ab5c5 *arm-wince.pe/upx-3.91.exe
|
||||||
|
ce81113f8a4ff1cd806811cb80ab8bea5c9c6fbced47451c7f07e50700f9817b *arm64-linux.elf/upx-3.95
|
||||||
|
b1c1c38d50007616aaf8e942839648c80a6111023e0b411e5fa7a06c543aeb4a *armeb-linux.elf/upx-3.91
|
||||||
|
84b90eb0d617571fe4885639925b35ca6a61060cb2616bb5bf729b4d701653e4 *armeb-linux.elf/upx-3.95
|
||||||
|
bcac77a287289301a45fde9a75e4e6c9ad7f8d57856bae6eafaae12ae4445a34 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
7d331e508449497f64cd47abdd3f00f70307f508ad3fd692d333feb97beccead *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
730a513b72a094697f827e4ac1a4f8ef58a614fc7a7ad448fa58d60cd89af7ed *i386-linux.elf/upx-3.91
|
||||||
|
a1f3e5ffa7b2cfebe1e475ac1f4c7683b1b8b4e292aa0d04386cc0314dd162c9 *i386-linux.elf/upx-3.95
|
||||||
|
e90fb09a808334c2674996760d42c82f8352e3f671f6b66c11481e772785c4d2 *i386-win32.pe/upx-3.91.exe
|
||||||
|
07bd50c1d80f6ff651228e6fc0ba3a583a472915772244f232696b34156a9d27 *i386-win32.pe/upx-3.95.exe
|
||||||
|
8e5333ea040f5594d3e67d5b09e005d52b3a52ef55099a7c11d7e39ead38e66d *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
8902f38ec3d95d8e077e3ab5fdbb5bad408859913a35deb87041f4f053cd6605 *mips-linux.elf/upx-3.95
|
||||||
|
c3f44b4d00a87384c03a6f9e7aec809c1addfe3e271244d38a474f296603088c *mipsel-linux.elf/upx-3.91
|
||||||
|
dd1496bc4e9c32a5d5dd47e3eaabf7b134ca001d48807eebfd3d5e28c8a2ab58 *mipsel-linux.elf/upx-3.95
|
||||||
|
b8c35fa2956da17ca505956e9f5017bb5f3a746322647e24ccb8ff28059cafa4 *powerpc-linux.elf/upx-3.91
|
||||||
|
2bc00a51daa0bada19a8fa1bd2c227a8596844fa1b0aa3611087f195072700e2 *powerpc-linux.elf/upx-3.95
|
||||||
|
a0950546dc17fca9437219431d8ddb0249ce5b08e899e0c799a87ac982adee70 *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t110_compress_ucl_nrv2b_3_no_filter="\
|
||||||
|
d11ff80ef4e663679699d92bfd5d9ed8421dc2def0a91b104697cdb2ef0a1ffe *amd64-linux.elf/upx-3.91
|
||||||
|
14d9ecc398a3b1863b19371387cadc434b8bb9a7da9225c58d3df2ab624cbf9e *amd64-linux.elf/upx-3.95
|
||||||
|
3c161ae654b290be806a38be271a4e9498404e038d5ef163543b072077b29859 *amd64-win64.pe/upx-3.95.exe
|
||||||
|
dc1927ca0317cdefe2c07b0a76f0c2d45cf02079ee163c1ced26688277a22be3 *arm-linux.elf/upx-3.95
|
||||||
|
c5a65ebda6db5f619afad9a0c0e9ece6cb025c5fdfdec57affa26120255b5e73 *arm-wince.pe/upx-3.91.exe
|
||||||
|
4a76cf662f29ef93cb674d9dd8ec144e2388d3b05d33abd89cb0416f760330c5 *arm64-linux.elf/upx-3.95
|
||||||
|
bfca960388f228846091c7124d49e9bb1504c7696ee0b359278009fa17dfa9a7 *armeb-linux.elf/upx-3.91
|
||||||
|
35b09fdbd0f9977172ebaff8231d8e00f68a8475dcba2f75b6d05c36a39f4bb4 *armeb-linux.elf/upx-3.95
|
||||||
|
5434fa28036a14abf19e4c24fe1f8bdc4cff132ed9080cb34ef1dd3c596ebce8 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
a194bd54d3058fd97871b96a14ede16b337241e912cd51456d2a8e5b3dfa6a39 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
a57e4e0d72e8e5ace0e045192150c4b4e9889c0ac7630c885f8cecab8280ecda *i386-linux.elf/upx-3.91
|
||||||
|
b150460b6061cfca7ec76e868626bb33a92e2558fe1f1fc8baab8c528cd1dde4 *i386-linux.elf/upx-3.95
|
||||||
|
c9a92aa8099262b5174b50f37c4f2995ceff79a8c9ba4c755a4fd1dc98bb0f23 *i386-win32.pe/upx-3.91.exe
|
||||||
|
4f15940af27173ee18aa4fdf96b79ed4c5b563141b7362b398424366e3f51dca *i386-win32.pe/upx-3.95.exe
|
||||||
|
81539760603ca5abbc5f6f0e9f0df922129fad624643d6cfc10d820205519650 *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
648378e19d72bc85950e6244d837475e21008dbf470a4cb3484fda10677b8afd *mips-linux.elf/upx-3.95
|
||||||
|
3eb9a06b68617499a0c7994b6b300e4fbe9ca3cf0c3601948ab129d9e181b345 *mipsel-linux.elf/upx-3.91
|
||||||
|
5a188e4aa04e98def8294e21a587a5e958fdd745cafa52fe584976c8b62a96e9 *mipsel-linux.elf/upx-3.95
|
||||||
|
557a255deb0250ea1d0db01b07b40603817b97b9e645328bc01aaf1c51742cae *powerpc-linux.elf/upx-3.91
|
||||||
|
0751e651da9809deea7926c4125527677d7034fbbbb4d5ae10dd692c37a47074 *powerpc-linux.elf/upx-3.95
|
||||||
|
08a46dffd447f0b1f723613bfb31d14154c1a31cc3e7982263ec4b242724410c *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t120_compress_ucl_nrv2d_3_no_filter="\
|
||||||
|
c7b05335f178c5c550e3d1d0d90fb6d921a4c0c66c16e215114483ade78d9b5f *amd64-linux.elf/upx-3.91
|
||||||
|
9cedd104b3bdd11c6933ecb21e0c47bda7362909905e7e63e950984825650950 *amd64-linux.elf/upx-3.95
|
||||||
|
d96be2f6f5fb0088736ff7a83a8854844ae41d61aff7862e91f09222755a56b0 *amd64-win64.pe/upx-3.95.exe
|
||||||
|
cf7c02b78bb85e9426b01aaf31a99c65944822d65eaac461de1b3db0c718625d *arm-linux.elf/upx-3.95
|
||||||
|
c05c9d17f6d74f760d0c9cdbf7c8d0f29b9059ec0048a160579d9d40ee6dde46 *arm-wince.pe/upx-3.91.exe
|
||||||
|
91c4f7d3485e53a5b9cfadc2dda610ad5507c02b2d75f70d9628e336eaf154c8 *arm64-linux.elf/upx-3.95
|
||||||
|
e4b2f54fcacc320e4a7e45b49a499b58ebf8c4ad35232e4982144c817dee19a5 *armeb-linux.elf/upx-3.91
|
||||||
|
2a0b9e1cf234ed0746b74f8e63e15bd52f74082705ee74647899da238c7cebb3 *armeb-linux.elf/upx-3.95
|
||||||
|
0d16d4489ba249636541134471ac6dca6c78874c9201dc12a7825747cd095767 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
49671cdfa344b6d259ba339e764f0a196b190eb7a3979771b83704d26766ed63 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
f9bde637fa12497a02d38e52fd7acba5b7220eaa3888434fc18dcbf224c14af9 *i386-linux.elf/upx-3.91
|
||||||
|
11ef9a08ea0aba3ed8d2043be6b2297e0b41f10fc5d73f9b9299fea00eb36426 *i386-linux.elf/upx-3.95
|
||||||
|
48984390e36e8b6dd133a372570d215a49e1bf2b5d8304ba060e1088149eb603 *i386-win32.pe/upx-3.91.exe
|
||||||
|
0f9d2325e0d8930b72629c37dbb333a3ac1e3d0be0f00245a376fceb287dfff6 *i386-win32.pe/upx-3.95.exe
|
||||||
|
e87f9d09fdd313c3cf552030e9596dea67cdd6178bdf6cefb0b33f1fc893339f *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
d31a35f3fae92984df28dd26c90a525038be74a54714948b96914af885902fdb *mips-linux.elf/upx-3.95
|
||||||
|
26de609a6eda26fcf93273d6a95abfe211b7080abdbbdc6fd4f793ea59bb8aa6 *mipsel-linux.elf/upx-3.91
|
||||||
|
0bd931fa89c1cc5b6f0c2425f0d564808caf5223e3214fd718b6a6df2c42ca2b *mipsel-linux.elf/upx-3.95
|
||||||
|
98dc5a8995b36bca8873a41414245db7a608d644b7a75d43bdecf9d6c8660817 *powerpc-linux.elf/upx-3.91
|
||||||
|
42d0fce35d881b90986b6de32b6dd231c310023c1e3a33f16affe5b36503b663 *powerpc-linux.elf/upx-3.95
|
||||||
|
e5db79bd3323df67afc53eed8621cae8de8c57522230cb18463d0a38ef8e0e2b *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t130_compress_ucl_nrv2e_3_no_filter="\
|
||||||
|
bb7df16340f56a859b10b5c591e69435b72443c4b9387b4c0afc4f3362217c5c *amd64-linux.elf/upx-3.91
|
||||||
|
bf45e190f7dfce9eec13163ccc7da85c51420736b15ef679290af7f4662e5850 *amd64-linux.elf/upx-3.95
|
||||||
|
cedb3c199f6b37c2993c2f6beaff327bebfcef0d1dd904b655f79c7261e374f6 *amd64-win64.pe/upx-3.95.exe
|
||||||
|
6887322866a5b77058c1b7ecc229fb43c80ea4d88e965dd34ad8a562604f5f4c *arm-linux.elf/upx-3.95
|
||||||
|
8b12ec425233a4f2e00769f2106a804d64100ac3d32f38db2383a0f51ab0c8fb *arm-wince.pe/upx-3.91.exe
|
||||||
|
13410a318f80b193f75b26388c45f603e62ab7e30392b248f89409f73f59dcc3 *arm64-linux.elf/upx-3.95
|
||||||
|
bf60d3e917be3abe66f15d8e61c93e2451f241e5b7e55de8c68d0a5eea4ab474 *armeb-linux.elf/upx-3.91
|
||||||
|
8b0ae4260e24398e479a6e220625f50158ab3142c565cc4929350a298437e6a8 *armeb-linux.elf/upx-3.95
|
||||||
|
8b5739273e1565e031c4335ceb76e5efc00830074093f092ab3ac2942b1f756e *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
27875bd06a68b56d4ecf4b1aac7cd088f6fd3c358970b0c0fe881026b83a4603 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
018137b520e22511d67d6768ec57a9bc053bc7927a87fd51d60521042d2a26f2 *i386-linux.elf/upx-3.91
|
||||||
|
b9f6b51798e239c881174a9a93391ea27020fb6632f9cbf6040d2c7c43798f74 *i386-linux.elf/upx-3.95
|
||||||
|
38229e4a2d830568ed2b25f3d23cb20b7b78e912227da45fe1bae57e131470df *i386-win32.pe/upx-3.91.exe
|
||||||
|
f55a0c8f3197977bfe9bca325fb86e1a3f5effe82f4efaa062554b8dc7093e10 *i386-win32.pe/upx-3.95.exe
|
||||||
|
e08fb4722915ea11259084c1483e2f40f0a047be600e7a9f2607c44582849ef0 *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
e452be5c3f9310879626387cbe60a7bd4465f0efc9b31e711733b964ab9286b8 *mips-linux.elf/upx-3.95
|
||||||
|
bca2e642253157d4e004a53cb393cecf34df82f2072bedf4c46bf32f1302da74 *mipsel-linux.elf/upx-3.91
|
||||||
|
849469774baf909c7470f5306f75e91fbed4664475d4f7d60910ce07101a0ce8 *mipsel-linux.elf/upx-3.95
|
||||||
|
59a21be192ac75bdf5ed882a53c3e2560380dd46c1af36d256c6329bbed7c2b7 *powerpc-linux.elf/upx-3.91
|
||||||
|
fa8f8f063ae7eedb936d0774485451b785387b435b9bcbe2fc0c9fbe7ed4eced *powerpc-linux.elf/upx-3.95
|
||||||
|
64ade3a0badb4357bf7714e5192be73ef03678260ac31ac729fc68d639495c56 *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t140_compress_lzma_2_no_filter="\
|
||||||
|
ba01763526328e15b34441891b4bfbfded4488cfc0221bd923fc33c17cd94f26 *amd64-linux.elf/upx-3.91
|
||||||
|
401dba7e1d660d732006a7b3b39d0b8806ac90530090141c583ad7037482b637 *amd64-linux.elf/upx-3.95
|
||||||
|
0afff19522cd3480f13170f6f56ad1df918ff6427fdd1f76e0014adbc492112c *amd64-win64.pe/upx-3.95.exe
|
||||||
|
a7d7457b0dc5105297f070db66bac8e581c3901efa5b4c89c991cc652edd1c58 *arm-linux.elf/upx-3.95
|
||||||
|
a2178a2be4b595adb32e11c0dcdcf6af701a3f1fc41cc4019dee00a96c997860 *arm-wince.pe/upx-3.91.exe
|
||||||
|
2e45b63d7a9897c8316436cd73ea30c788b9cc873374f572ab4119ccd4585f62 *arm64-linux.elf/upx-3.95
|
||||||
|
c77b62df69a4e0e712e7ceab519bb5e8760b6dde3b609be5422258fe8c5464a3 *armeb-linux.elf/upx-3.91
|
||||||
|
abe0d09a0e3aa9b483ba652face53718480c3a928d0cb0be183e41eb2c64f1aa *armeb-linux.elf/upx-3.95
|
||||||
|
46c1aceafa1e3a2fcf224bf6e50d1dfac2dc1519671387cb066e3454b3207635 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
170c70a9fb257ca845bbbef5f8da0062b4197a8b3f5cf9a29f472751ab38879a *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
3a5d6531b1f1ce021282592dd645fe66affd86b36ccb72c3a4f43976fb150606 *i386-linux.elf/upx-3.91
|
||||||
|
c073fe95891b83015e7d778a44562d057d5b3bc787e37f794f0e2b9867d83d76 *i386-linux.elf/upx-3.95
|
||||||
|
3e1fcbdb6267e99c50c20c3d0e6ca7795b3c35282bd127e3f09c13ae4a9ef6d0 *i386-win32.pe/upx-3.91.exe
|
||||||
|
7618f249a922b7e504a389eb1c5c640b3bc5678ca1b4575900a778453c2666fc *i386-win32.pe/upx-3.95.exe
|
||||||
|
b1a481020f6afc2601dac02bba1582f47719c964fbb3e63090cd2ae19caf2c28 *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
64574681a2cbef2e5ecd4c290e8c4ed482a1a34438e3b7151eda097c593195df *mips-linux.elf/upx-3.95
|
||||||
|
0a9f789949135858acebd4da834a2d904bbc722adc599d59ae41382475988d6a *mipsel-linux.elf/upx-3.91
|
||||||
|
69faa554496af25239a5fea6f7941c0424d8f40d8078a7e40012ba284bf7b678 *mipsel-linux.elf/upx-3.95
|
||||||
|
224cc6a5336f768457c92a317a4f7e47188779ff459b821f49d2ef2188b5674b *powerpc-linux.elf/upx-3.91
|
||||||
|
8da438605f0be0e9a00c4f169d66b4639468f8e3922ed63320f33b91d0a6b099 *powerpc-linux.elf/upx-3.95
|
||||||
|
efa063be5c8a488b16f0d03598b96e144a0c0d317c462a58a3e32585b68403a7 *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t150_compress_ucl_2_all_filters="\
|
||||||
|
19d81859acc5322e7610e44aee84eed65974650d7a7afb5fb9731d11dad70144 *amd64-linux.elf/upx-3.91
|
||||||
|
9663a26ee5367181ad8d8cc0d8df0573d4cfcff0aa5c8f014e56963b80007146 *amd64-linux.elf/upx-3.95
|
||||||
|
1e2dd8689c3e7d4bd484eb53490ab0a9764c1ba4022145e309873537d63765f5 *amd64-win64.pe/upx-3.95.exe
|
||||||
|
4bf9b45b89d5668e41caf176f34b32336cbd4f858b71ed03385f69b722192796 *arm-linux.elf/upx-3.95
|
||||||
|
b94e8887f7901239b1fb4aa926c96d4dd5d935a653e619c3ab4c4124dad7380c *arm-wince.pe/upx-3.91.exe
|
||||||
|
6138f52201f283e64816f77380da10dc422d1689031fb6c72054647e48f55188 *arm64-linux.elf/upx-3.95
|
||||||
|
72c31db3472141f44f6034c9eaec3352c4f4391560a3d81fc63cb2fe45778d32 *armeb-linux.elf/upx-3.91
|
||||||
|
8cfb3a15c6d795e0be95c92791081573d5987633b52c51e044ab3baa7436c8d5 *armeb-linux.elf/upx-3.95
|
||||||
|
ef96852c3865b3e6682e345954568acdf7ef2e3f59f3aaec5477142097b029b7 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
c2c11ca8450b0cf61eb2e4d5ee54692ca0f308be4b61c544e03bfc108a79cb0d *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
a595b6d76204351340a2f6eff0cfb7b3f64c40866fc11e6bb7ff9d534f097bee *i386-linux.elf/upx-3.91
|
||||||
|
8b1929b7753b56274c136648359a01a862ae994f291b2f511fdb1d2268bccbbc *i386-linux.elf/upx-3.95
|
||||||
|
10f32132ca0a218c069185834ace32447d4cf33c4ab7766141c4c08d967606a1 *i386-win32.pe/upx-3.91.exe
|
||||||
|
c1146e9c9b1c4e755822fbd5486c53e905b9d16028b97c55d0430bbcec467793 *i386-win32.pe/upx-3.95.exe
|
||||||
|
e217c1613fe848e6126f6a05b32aceaeda777e4d4a3755405118e3586b1bd93d *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
e2ef44ac8519d9aadf99469c8c387503d8737827f840ef5e5b5695529d4de8f6 *mips-linux.elf/upx-3.95
|
||||||
|
23ebde2dc0d11ab32c056683edca55b8ece7f429cea28520653ed367f16a8b26 *mipsel-linux.elf/upx-3.91
|
||||||
|
354c349f1504b3403ca922fb275f25835a173268a58a2ca5b17b0632220bb6c8 *mipsel-linux.elf/upx-3.95
|
||||||
|
6f3197a3e460b23dde39522a12d734d3dddb1515645931e4fad622d8ffbe37b8 *powerpc-linux.elf/upx-3.91
|
||||||
|
66bc0f51d3a2905cdf39d599ec609565fbee3afc962cdb74caa431b71a0f5ee6 *powerpc-linux.elf/upx-3.95
|
||||||
|
f47a2f1d67f37af7087c94fc7a3fd3cd81ec3ed8149df79774250a4ace793768 *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t160_compress_all_methods_1_no_filter="\
|
||||||
|
a4e92543a5cf5e692823d0bc2a75a995570358ba899e273d67c1df0709d5f41d *amd64-linux.elf/upx-3.91
|
||||||
|
77e7f8b07304c8acbf55a4755854c51f5d1582558f15ec74585fc471379c81f3 *amd64-linux.elf/upx-3.95
|
||||||
|
c8c19d2e24cd9c5b416888cff1828ef7a5b09236b0c423adbc3d2215977d4756 *amd64-win64.pe/upx-3.95.exe
|
||||||
|
0aa2cd95ed88fd3e220d14e429068269556ad7dc22ef740d07faf5288fc10189 *arm-linux.elf/upx-3.95
|
||||||
|
876f3e8c159f744db0ec8bc9d9afe51be7dac4c18da744c82550d9cc8abfae64 *arm-wince.pe/upx-3.91.exe
|
||||||
|
0853acc0af2991a5c87d54215cabc46db588d2626b468559b052418fa90b40f9 *arm64-linux.elf/upx-3.95
|
||||||
|
af0cef4cd954d3eed8218c92434ab351c4d071293223361b12f10381117798c8 *armeb-linux.elf/upx-3.91
|
||||||
|
6fb686656901a4db12cdf6ffd050be225d74e1123aecea3e45d7604f0eb1104d *armeb-linux.elf/upx-3.95
|
||||||
|
f2e94193758f32cab6b11e7d72d6c35339170e7db7f2fffb828e528a2a8a9611 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
4ff2bbd08158a94f2d3e7aff2b681b9314704aa9724319c4ea3f2ad554b97edc *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
49e38b822d774cfe637a61a36d18ce0d6b402a80cfbfe2ca16f2d63d0ea05cdf *i386-linux.elf/upx-3.91
|
||||||
|
2ffc13b1515ad20846cca5b2d1c7d5ae0d2b3410fe14ea97fbeb9da46332b7c9 *i386-linux.elf/upx-3.95
|
||||||
|
76b29c91e9429d4587192584ee8b15a2fc40f00ae6a3c83c220c245a780e31a2 *i386-win32.pe/upx-3.91.exe
|
||||||
|
5c5b5148f679341301776689d41205d746ea96c530721a64edf8c10e8876ae35 *i386-win32.pe/upx-3.95.exe
|
||||||
|
cacdad81fb8a39c08f656f07a370c2c21e0c2aa7b3a81bcac22bb114078c478a *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
d9cbddf0e48f870dca28ccb394f2077d49fb7da3c7244a4c132627bc7b2c1a89 *mips-linux.elf/upx-3.95
|
||||||
|
27fad7afdbf8fdce8b9729ed9bac4e2a1fe501ebd9dda00630c7717c504eccbb *mipsel-linux.elf/upx-3.91
|
||||||
|
b11fa6e0a609bbf3222f342951cbb77b214602168bd37ddadae23afa479c2ade *mipsel-linux.elf/upx-3.95
|
||||||
|
b7e4c9b02c30dc7436ef6cc133342b93c75ba71779b564e21dc2cb88749bc113 *powerpc-linux.elf/upx-3.91
|
||||||
|
920090c1e5147f10e1be0de3ea99a8a3140a6271c260cb90eeff6549e2855828 *powerpc-linux.elf/upx-3.95
|
||||||
|
29c6854869fd0a4e95cb3d434f8b93e7728c126ce2a8f9d7163506f1271b2af0 *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
expected_sha256sums__t170_compress_all_methods_no_lzma_5_no_filter="\
|
||||||
|
f11151a8eea22872544062dcab0190e26d63073c0e0b9e1356f31a336e7a56e4 *amd64-linux.elf/upx-3.91
|
||||||
|
047ad308483a6f2789de768f8de86a35b9a9c92d9ec4d04efeae55c7ea5c643c *amd64-linux.elf/upx-3.95
|
||||||
|
bd559454e3c5ad2e4afd145c2e366aed0e6bb6e8e059e7bd0bc72962cfd1f2ad *amd64-win64.pe/upx-3.95.exe
|
||||||
|
e1966d2e2056dc0af5bd18b880039cca83c70b5c370f3869e013384bdf8c853a *arm-linux.elf/upx-3.95
|
||||||
|
ef0a4b9341aacd4b9962f9e77c019c5e641616f4f5d713af93263cbf67e32a0f *arm-wince.pe/upx-3.91.exe
|
||||||
|
45700ca243888ec22cf84018d7b4ec47f2ee6e36edfc4a16056ea81e99eee9d0 *arm64-linux.elf/upx-3.95
|
||||||
|
fd5697370dca17662f271530af4a164790c63b164cc3160d7d8be317e624af8d *armeb-linux.elf/upx-3.91
|
||||||
|
c09ecb409692d91fc4710896f6fe934066d4bdff778c675c99e27b5c624d1d63 *armeb-linux.elf/upx-3.95
|
||||||
|
4766485709641cbbe06b09e64d0c77b66afa45eadf3ee11c0e92e5a0a97e5bc1 *i386-dos32.djgpp2.coff/upx-3.91.exe
|
||||||
|
f4de30c9fb6b695264db098790d189b01f1df950c75e34f8f445d8fa49b69755 *i386-dos32.djgpp2.coff/upx-3.95.exe
|
||||||
|
a25c10adb376e932191aeb2e11d1020e71b56a9c82ea0d7f8af71b4e05cffbf1 *i386-linux.elf/upx-3.91
|
||||||
|
4dca2d0bdc78d5d8fc582f6638c4595ee45c03ee2523e1da0cd914576ba7a5dd *i386-linux.elf/upx-3.95
|
||||||
|
f4500b64adb382552152c737880a3cd55c172d023437c996ccae5b07414dcb0e *i386-win32.pe/upx-3.91.exe
|
||||||
|
8922ab742e9641ca533af2693c85fd5121bbac677b12a2c67a33a49b6e4eb939 *i386-win32.pe/upx-3.95.exe
|
||||||
|
f95d3a1811be7665fc6cb9479eeb4e94b64d4b1f16187b06fa6c9f0c54782564 *m68k-atari.tos/upx-3.91.ttp
|
||||||
|
e637eb6b7c4c9c06488e79c26f8910cc8c40196a962339c849457e6b6a59b964 *mips-linux.elf/upx-3.95
|
||||||
|
8c1c4fe3430f1524e70c68f2c10ab67f356c94ea79cf7726a24931d29388458c *mipsel-linux.elf/upx-3.91
|
||||||
|
572283b261f90bd2b13f5a65c94f065f7a7e40ed32c2d048f314ec8a9656e365 *mipsel-linux.elf/upx-3.95
|
||||||
|
0a7c32c5b3cda6e7c90e21227f1b5af14d169d56d074644c431dbf367b308cdb *powerpc-linux.elf/upx-3.91
|
||||||
|
fe6e2d1c1b8e9119713863997f52735a4814d35c3bfba0a6ef1cd9e218510383 *powerpc-linux.elf/upx-3.95
|
||||||
|
cbeb988b78e3edd3f0d9526998b700c0b1c3c4bb29ef9e2591c4083a40126c50 *powerpc64le-linux.elf/upx-3.95
|
||||||
|
"
|
||||||
|
########## end .sha256sums.recreate
|
||||||
Executable
+335
@@ -0,0 +1,335 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
## vim:set ts=4 sw=4 et:
|
||||||
|
set -e; set -o pipefail
|
||||||
|
argv0=$0; argv0abs=$(readlink -fn "$argv0"); argv0dir=$(dirname "$argv0abs")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
|
#
|
||||||
|
# very first version of the upx-testsuite; requires:
|
||||||
|
# $upx_exe (required, but with convenience fallback "./upx")
|
||||||
|
# $upx_testsuite_SRCDIR (required, but with convenience fallback)
|
||||||
|
# $upx_testsuite_BUILDDIR (optional)
|
||||||
|
#
|
||||||
|
# optional settings:
|
||||||
|
# $upx_exe_runner (e.g. "qemu-x86_64 -cpu Nehalem" or "valgrind")
|
||||||
|
# $UPX_TESTSUITE_VERBOSE
|
||||||
|
# $UPX_TESTSUITE_LEVEL
|
||||||
|
#
|
||||||
|
# see https://github.com/upx/upx-testsuite.git
|
||||||
|
#
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# init & checks
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# upx_exe
|
||||||
|
[[ -z $upx_exe && -f ./upx && -x ./upx ]] && upx_exe=./upx # convenience fallback
|
||||||
|
if [[ -z $upx_exe ]]; then echo "UPX-ERROR: please set \$upx_exe"; exit 1; fi
|
||||||
|
if [[ ! -f $upx_exe ]]; then echo "UPX-ERROR: file '$upx_exe' does not exist"; exit 1; fi
|
||||||
|
upx_exe=$(readlink -fn "$upx_exe") # make absolute
|
||||||
|
[[ -f $upx_exe ]] || exit 1
|
||||||
|
upx_run=()
|
||||||
|
if [[ -n $upx_exe_runner ]]; then
|
||||||
|
# usage examples:
|
||||||
|
# export upx_exe_runner="qemu-x86_64 -cpu Nehalem"
|
||||||
|
# export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet"
|
||||||
|
# export upx_exe_runner="wine"
|
||||||
|
IFS=' ' read -r -a upx_run <<< "$upx_exe_runner" # split at spaces into array
|
||||||
|
elif [[ -n $CMAKE_CROSSCOMPILING_EMULATOR ]]; then
|
||||||
|
IFS=';' read -r -a upx_run <<< "$CMAKE_CROSSCOMPILING_EMULATOR" # split at semicolons into array
|
||||||
|
fi
|
||||||
|
upx_run+=( "$upx_exe" )
|
||||||
|
echo "upx_run='${upx_run[*]}'"
|
||||||
|
|
||||||
|
# upx_run sanity check, part1
|
||||||
|
if ! "${upx_run[@]}" --version-short >/dev/null; then echo "UPX-ERROR: FATAL: upx --version-short FAILED"; exit 1; fi
|
||||||
|
if ! "${upx_run[@]}" -L >/dev/null 2>&1; then echo "UPX-ERROR: FATAL: upx -L FAILED"; exit 1; fi
|
||||||
|
if ! "${upx_run[@]}" --help >/dev/null; then echo "UPX-ERROR: FATAL: upx --help FAILED"; exit 1; fi
|
||||||
|
|
||||||
|
# upx_testsuite_SRCDIR
|
||||||
|
if [[ -z $upx_testsuite_SRCDIR ]]; then
|
||||||
|
# convenience fallback: search standard locations below upx top-level directory
|
||||||
|
if [[ -d "$argv0dir/../../../upx--upx-testsuite.git/files/packed" ]]; then
|
||||||
|
upx_testsuite_SRCDIR="$argv0dir/../../../upx--upx-testsuite.git"
|
||||||
|
elif [[ -d "$argv0dir/../../../upx-testsuite.git/files/packed" ]]; then
|
||||||
|
upx_testsuite_SRCDIR="$argv0dir/../../../upx-testsuite.git"
|
||||||
|
elif [[ -d "$argv0dir/../../../upx-testsuite/files/packed" ]]; then
|
||||||
|
upx_testsuite_SRCDIR="$argv0dir/../../../upx-testsuite"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ ! -d "$upx_testsuite_SRCDIR/files/packed" ]]; then
|
||||||
|
echo "invalid or missing \$upx_testsuite_SRCDIR:"
|
||||||
|
echo " please git clone https://github.com/upx/upx-testsuite.git"
|
||||||
|
echo " and set (export) the envvar upx_testsuite_SRCDIR to the local file path"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
upx_testsuite_SRCDIR=$(readlink -fn "$upx_testsuite_SRCDIR") # make absolute
|
||||||
|
[[ -d $upx_testsuite_SRCDIR ]] || exit 1
|
||||||
|
|
||||||
|
# upx_testsuite_BUILDDIR
|
||||||
|
if [[ -z $upx_testsuite_BUILDDIR ]]; then
|
||||||
|
upx_testsuite_BUILDDIR="./tmp-upx-testsuite"
|
||||||
|
fi
|
||||||
|
mkdir -p "$upx_testsuite_BUILDDIR" || exit 1
|
||||||
|
upx_testsuite_BUILDDIR=$(readlink -fn "$upx_testsuite_BUILDDIR") # make absolute
|
||||||
|
[[ -d $upx_testsuite_BUILDDIR ]] || exit 1
|
||||||
|
|
||||||
|
cd / && cd "$upx_testsuite_BUILDDIR" || exit 1
|
||||||
|
: > ./.mfxnobackup
|
||||||
|
|
||||||
|
# upx_run sanity check, part2
|
||||||
|
if ! "${upx_run[@]}" --version-short >/dev/null; then
|
||||||
|
echo "UPX-ERROR: FATAL: upx --version-short FAILED"
|
||||||
|
echo "please make sure that \$upx_exe contains ABSOLUTE file paths and can be run from any directory"
|
||||||
|
echo "INFO: upx_run='${upx_run[*]}'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! "${upx_run[@]}" -L >/dev/null 2>&1; then echo "UPX-ERROR: FATAL: upx -L FAILED"; exit 1; fi
|
||||||
|
if ! "${upx_run[@]}" --help >/dev/null; then echo "UPX-ERROR: FATAL: upx --help FAILED"; exit 1; fi
|
||||||
|
|
||||||
|
case $UPX_TESTSUITE_LEVEL in
|
||||||
|
[0-8]) ;;
|
||||||
|
*) UPX_TESTSUITE_LEVEL=999 ;;
|
||||||
|
esac
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL == 0 ]]; then
|
||||||
|
echo "UPX testsuite SKIPPED."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# setup
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
#set -x # debug
|
||||||
|
exit_code=0
|
||||||
|
num_errors=0
|
||||||
|
all_errors=
|
||||||
|
|
||||||
|
export UPX="--prefer-ucl --no-color --no-progress"
|
||||||
|
export UPX_DEBUG_DISABLE_GITREV_WARNING=1
|
||||||
|
export UPX_DEBUG_DOCTEST_VERBOSE=0
|
||||||
|
|
||||||
|
rm -rf ./testsuite_1
|
||||||
|
mkdir testsuite_1 || exit 1
|
||||||
|
cd testsuite_1 || exit 1
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# support functions
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
run_upx() {
|
||||||
|
local ec=0
|
||||||
|
if [[ $UPX_TESTSUITE_VERBOSE == 1 ]]; then
|
||||||
|
echo "LOG: '${upx_run[*]}' $*"
|
||||||
|
fi
|
||||||
|
"${upx_run[@]}" "$@" || ec=$?
|
||||||
|
if [[ $ec != 0 ]]; then
|
||||||
|
echo "FATAL: '${upx_run[*]}' $*"
|
||||||
|
echo " (exit code was $ec)"
|
||||||
|
exit 42
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
testsuite_header() {
|
||||||
|
local x='==========='; x="$x$x$x$x$x$x$x"
|
||||||
|
echo -e "\n${x}\n${1}\n${x}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
testsuite_split_f() {
|
||||||
|
fd=$(dirname "$1")
|
||||||
|
fb=$(basename "$1")
|
||||||
|
fsubdir=$(basename "$fd")
|
||||||
|
# sanity checks
|
||||||
|
if [[ ! -f $1 || -z $fsubdir || -z $fb ]]; then
|
||||||
|
fd=''; fb=''; fsubdir=''
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
testsuite_check_sha() {
|
||||||
|
(cd "$1" && sha256sum -b [0-9a-zA-Z]*/* | LC_ALL=C sort -k2) > $1/.sha256sums.current
|
||||||
|
echo
|
||||||
|
cat $1/.sha256sums.current
|
||||||
|
if ! cmp -s $1/.sha256sums.expected $1/.sha256sums.current; then
|
||||||
|
echo "UPX-ERROR: $1 FAILED: checksum mismatch"
|
||||||
|
diff -u $1/.sha256sums.expected $1/.sha256sums.current || true
|
||||||
|
exit_code=99
|
||||||
|
let num_errors+=1 || true
|
||||||
|
all_errors="${all_errors} $1"
|
||||||
|
#exit 99
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
testsuite_check_sha_decompressed() {
|
||||||
|
(cd "$1" && sha256sum -b [0-9a-zA-Z]*/* | LC_ALL=C sort -k2) > $1/.sha256sums.current
|
||||||
|
if ! cmp -s $1/.sha256sums.expected $1/.sha256sums.current; then
|
||||||
|
cat $1/.sha256sums.current
|
||||||
|
echo "UPX-ERROR: FATAL: $1 FAILED: decompressed checksum mismatch"
|
||||||
|
diff -u $1/.sha256sums.expected $1/.sha256sums.current || true
|
||||||
|
exit 98
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
testsuite_use_canonicalized=1
|
||||||
|
testsuite_run_compress() {
|
||||||
|
testsuite_header $testdir
|
||||||
|
local files f
|
||||||
|
if [[ $testsuite_use_canonicalized == 1 ]]; then
|
||||||
|
files='t020_canonicalized/*/*'
|
||||||
|
else
|
||||||
|
files='t010_decompressed/*/*'
|
||||||
|
fi
|
||||||
|
for f in $files; do
|
||||||
|
testsuite_split_f "$f"
|
||||||
|
[[ -z $fb ]] && continue
|
||||||
|
echo "# $f"
|
||||||
|
mkdir -p "$testdir/$fsubdir" "$testdir/.decompressed/$fsubdir"
|
||||||
|
run_upx -qq --prefer-ucl "$@" "$f" -o "$testdir/$fsubdir/$fb"
|
||||||
|
run_upx -qq -d "$testdir/$fsubdir/$fb" -o "$testdir/.decompressed/$fsubdir/$fb"
|
||||||
|
done
|
||||||
|
testsuite_check_sha $testdir
|
||||||
|
run_upx -qq -l "$testdir"/*/*
|
||||||
|
run_upx -qq --file-info "$testdir"/*/*
|
||||||
|
run_upx -q -t "$testdir"/*/*
|
||||||
|
if [[ $testsuite_use_canonicalized == 1 ]]; then
|
||||||
|
# check that after decompression the file matches the canonicalized version
|
||||||
|
cp t020_canonicalized/.sha256sums.expected $testdir/.decompressed/
|
||||||
|
testsuite_check_sha_decompressed $testdir/.decompressed
|
||||||
|
rm -rf "./$testdir/.decompressed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# expected checksums
|
||||||
|
#
|
||||||
|
# To ease maintenance of this script in case of updates this section
|
||||||
|
# can be automatically re-created from the current checksums -
|
||||||
|
# see call of function recreate_expected_sha256sums below.
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
recreate_expected_sha256sums() {
|
||||||
|
local o="$1"
|
||||||
|
local files f d
|
||||||
|
echo "########## begin .sha256sums.recreate" > "$o"
|
||||||
|
files='*/.sha256sums.current'
|
||||||
|
for f in $files; do
|
||||||
|
d=$(dirname "$f")
|
||||||
|
echo "expected_sha256sums__${d}="'"\' >> "$o"
|
||||||
|
cat "$f" >> "$o"
|
||||||
|
echo '"' >> "$o"
|
||||||
|
done
|
||||||
|
echo "########## end .sha256sums.recreate" >> "$o"
|
||||||
|
}
|
||||||
|
|
||||||
|
source "$argv0dir/upx_testsuite_1-expected_sha256sums.sh" || exit 1
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# decompression tests
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
testdir=t010_decompressed
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
|
||||||
|
testsuite_header $testdir
|
||||||
|
for f in "$upx_testsuite_SRCDIR"/files/packed/*/upx-3.9[15]*; do
|
||||||
|
testsuite_split_f "$f"
|
||||||
|
[[ -z $fb ]] && continue
|
||||||
|
echo "# $f"
|
||||||
|
mkdir -p "$testdir/$fsubdir"
|
||||||
|
run_upx -qq -d "$f" -o "$testdir/$fsubdir/$fb"
|
||||||
|
done
|
||||||
|
testsuite_check_sha $testdir
|
||||||
|
|
||||||
|
# run one pack+unpack step to canonicalize the files
|
||||||
|
testdir=t020_canonicalized
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
|
||||||
|
testsuite_header $testdir
|
||||||
|
for f in t010_decompressed/*/*; do
|
||||||
|
testsuite_split_f "$f"
|
||||||
|
[[ -z $fb ]] && continue
|
||||||
|
echo "# $f"
|
||||||
|
mkdir -p "$testdir/$fsubdir/.packed"
|
||||||
|
run_upx -qq --prefer-ucl -1 "$f" -o "$testdir/$fsubdir/.packed/$fb"
|
||||||
|
run_upx -qq -d "$testdir/$fsubdir/.packed/$fb" -o "$testdir/$fsubdir/$fb"
|
||||||
|
done
|
||||||
|
testsuite_check_sha $testdir
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# compression tests
|
||||||
|
# info: we use fast compression levels because we want to
|
||||||
|
# test UPX and not the compression libraries
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL -ge 2 ]]; then
|
||||||
|
testdir=t110_compress_ucl_nrv2b_3_no_filter
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
time testsuite_run_compress --nrv2b -3 --no-filter
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL -ge 3 ]]; then
|
||||||
|
testdir=t120_compress_ucl_nrv2d_3_no_filter
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
time testsuite_run_compress --nrv2d -3 --no-filter
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL -ge 4 ]]; then
|
||||||
|
testdir=t130_compress_ucl_nrv2e_3_no_filter
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
time testsuite_run_compress --nrv2e -3 --no-filter
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL -ge 5 ]]; then
|
||||||
|
testdir=t140_compress_lzma_2_no_filter
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
time testsuite_run_compress --lzma -2 --no-filter
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL -ge 6 ]]; then
|
||||||
|
testdir=t150_compress_ucl_2_all_filters
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
time testsuite_run_compress -2 --all-filters
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL -ge 7 ]]; then
|
||||||
|
testdir=t160_compress_all_methods_1_no_filter
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
time testsuite_run_compress --all-methods -1 --no-filter
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $UPX_TESTSUITE_LEVEL -ge 8 ]]; then
|
||||||
|
testdir=t170_compress_all_methods_no_lzma_5_no_filter
|
||||||
|
mkdir $testdir; v=expected_sha256sums__$testdir; echo -n "${!v}" >$testdir/.sha256sums.expected
|
||||||
|
time testsuite_run_compress --all-methods --no-lzma -5 --no-filter
|
||||||
|
fi
|
||||||
|
|
||||||
|
#***********************************************************************
|
||||||
|
# summary
|
||||||
|
#***********************************************************************
|
||||||
|
|
||||||
|
# recreate checksums from current version for an easy update in case of changes
|
||||||
|
recreate_expected_sha256sums .sha256sums.recreate
|
||||||
|
|
||||||
|
testsuite_header "UPX testsuite summary: level $UPX_TESTSUITE_LEVEL"
|
||||||
|
run_upx --version-short
|
||||||
|
echo
|
||||||
|
echo "upx_exe='$upx_exe'"
|
||||||
|
ls -l "$upx_exe"
|
||||||
|
if command -v file >/dev/null; then
|
||||||
|
file "$upx_exe" || true
|
||||||
|
fi
|
||||||
|
echo "upx_run='${upx_run[*]}'"
|
||||||
|
echo "upx_testsuite_SRCDIR='$upx_testsuite_SRCDIR'"
|
||||||
|
echo "upx_testsuite_BUILDDIR='$upx_testsuite_BUILDDIR'"
|
||||||
|
echo ".sha256sums.{expected,current} counts:"
|
||||||
|
cat ./*/.sha256sums.expected | LC_ALL=C sort | wc
|
||||||
|
cat ./*/.sha256sums.current | LC_ALL=C sort | wc
|
||||||
|
echo
|
||||||
|
if [[ $exit_code == 0 ]]; then
|
||||||
|
echo "UPX testsuite passed. All done."
|
||||||
|
else
|
||||||
|
echo "UPX-ERROR: UPX testsuite FAILED:${all_errors}"
|
||||||
|
echo "UPX-ERROR: UPX testsuite FAILED with $num_errors error(s). See log file."
|
||||||
|
fi
|
||||||
|
exit $exit_code
|
||||||
+64
-56
@@ -1,17 +1,13 @@
|
|||||||
#
|
#
|
||||||
# UPX Makefile - needs GNU make
|
# UPX src Makefile - needs GNU make and CMake >= 3.13
|
||||||
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||||
#
|
#
|
||||||
|
|
||||||
# IMPORTANT NOTE: this Makefile is deprecated - please
|
# NOTE: this Makefile is deprecated - please directly use
|
||||||
# directly use the CMake build instead!
|
# the top-level CMake build instead.
|
||||||
|
|
||||||
MAKEFLAGS += -r
|
|
||||||
.SUFFIXES:
|
|
||||||
export SHELL = /bin/sh
|
|
||||||
|
|
||||||
ifndef srcdir
|
ifndef srcdir
|
||||||
srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
|
srcdir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
|
||||||
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,' || echo 'ERROR')
|
|
||||||
endif
|
endif
|
||||||
ifndef top_srcdir
|
ifndef top_srcdir
|
||||||
top_srcdir := $(srcdir)/..
|
top_srcdir := $(srcdir)/..
|
||||||
@@ -21,25 +17,37 @@ endif
|
|||||||
# redirect to top-level CMake build
|
# redirect to top-level CMake build
|
||||||
#
|
#
|
||||||
|
|
||||||
default: debug
|
# NOTE that top-level Makefile .DEFAULT_GOAL is build/release
|
||||||
all: debug release
|
.DEFAULT_GOAL = build/all
|
||||||
debug: $(top_srcdir)/build/debug/upx
|
|
||||||
release: $(top_srcdir)/build/release/upx
|
|
||||||
|
|
||||||
$(top_srcdir)/build/debug/upx:
|
build/debug: $(top_srcdir)/build/debug
|
||||||
$(MAKE) -C $(top_srcdir) build/debug
|
build/release: $(top_srcdir)/build/release
|
||||||
$(top_srcdir)/build/release/upx:
|
|
||||||
$(MAKE) -C $(top_srcdir) build/release
|
|
||||||
|
|
||||||
.PHONY: default all debug release
|
.NOTPARALLEL: # because the actual builds use "cmake --parallel"
|
||||||
.PHONY: $(top_srcdir)/build/debug/upx
|
.PHONY: PHONY
|
||||||
.PHONY: $(top_srcdir)/build/release/upx
|
.SECONDEXPANSION:
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
|
# shortcuts (all => debug + release)
|
||||||
|
debug: build/debug
|
||||||
|
release: build/release
|
||||||
|
all build/all: build/debug build/release
|
||||||
|
|
||||||
|
# actual rules - redirect to top-level
|
||||||
|
$(top_srcdir)/build/debug: PHONY; $(MAKE) -C $(top_srcdir) build/debug
|
||||||
|
$(top_srcdir)/build/release: PHONY; $(MAKE) -C $(top_srcdir) build/release
|
||||||
|
|
||||||
|
# convenience
|
||||||
|
CTEST = ctest
|
||||||
|
test:: $(top_srcdir)/build/debug PHONY; cd $< && $(CTEST)
|
||||||
|
test:: $(top_srcdir)/build/release PHONY; cd $< && $(CTEST)
|
||||||
|
|
||||||
#
|
#
|
||||||
# "make run-testsuite"
|
# "make run-testsuite"
|
||||||
|
# git clone https://github.com/upx/upx-testsuite.git
|
||||||
#
|
#
|
||||||
|
|
||||||
# search for the UPX testsuite -- git clone https://github.com/upx/upx-testsuite.git
|
# search for the UPX testsuite
|
||||||
# you also can override upx_testsuite_SRCDIR
|
# you also can override upx_testsuite_SRCDIR
|
||||||
ifndef upx_testsuite_SRCDIR
|
ifndef upx_testsuite_SRCDIR
|
||||||
# search standard locations below $(top_srcdir)
|
# search standard locations below $(top_srcdir)
|
||||||
@@ -53,51 +61,51 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# run the UPX testsuite
|
# run the UPX testsuite
|
||||||
# The expected (old) checksums are in $(top_srcdir)/.github/travis_testsuite_1-expected_sha256sums.sh
|
# The expected (old) checksums are in $(top_srcdir)/misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
|
||||||
# The actual (new) checksums are in tmp-testsuite/testsuite_1/.sha256sums.recreate
|
# The actual (new) checksums are in ./tmp-upx-testsuite-*/testsuite_1/.sha256sums.recreate
|
||||||
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
|
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
|
||||||
ifneq ($(wildcard $(top_srcdir)/.github/travis_testsuite_1.sh),)
|
ifneq ($(wildcard $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh),)
|
||||||
run-testsuite: export upx_exe := $(top_srcdir)/build/release/upx
|
run-testsuite: run-testsuite-release
|
||||||
run-testsuite: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
|
run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
|
||||||
run-testsuite: export upx_testsuite_BUILDDIR := ./tmp-testsuite
|
run-testsuite-debug: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite-debug
|
||||||
run-testsuite: $(top_srcdir)/build/release/upx
|
run-testsuite-debug: export upx_exe := $(top_srcdir)/build/debug/upx
|
||||||
time -p bash $(top_srcdir)/.github/travis_testsuite_1.sh
|
run-testsuite-debug: $(top_srcdir)/build/debug PHONY
|
||||||
.PHONY: run-testsuite
|
time -p bash $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh
|
||||||
|
run-testsuite-release: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite-release
|
||||||
|
run-testsuite-release: export upx_exe := $(top_srcdir)/build/release/upx
|
||||||
|
run-testsuite-release: $(top_srcdir)/build/release PHONY
|
||||||
|
time -p bash $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# "make check-whitespace"
|
||||||
|
#
|
||||||
|
|
||||||
|
ifneq ($(wildcard /usr/bin/env),) # need Unix utils like bash, perl, sed, xargs, etc.
|
||||||
|
CHECK_WHITESPACE = bash $(top_srcdir)/misc/scripts/check_whitespace.sh $(top_srcdir)
|
||||||
|
ifneq ($(wildcard $(top_srcdir)/.git/.),)
|
||||||
|
CHECK_WHITESPACE = bash $(top_srcdir)/misc/scripts/check_whitespace_git.sh $(top_srcdir)
|
||||||
|
endif
|
||||||
|
check-whitespace: PHONY; $(CHECK_WHITESPACE)
|
||||||
|
endif
|
||||||
|
|
||||||
#
|
#
|
||||||
# "make clang-format"
|
# "make clang-format"
|
||||||
#
|
#
|
||||||
|
|
||||||
# automatically format some C++ source code files
|
# automatically format some C++ source code files
|
||||||
ifeq ($(shell uname),Linux)
|
ifeq ($(shell uname),Linux)
|
||||||
CLANG_FORMAT_FILES += bele.h bele_policy.h
|
# Markus loves clang-format, but John hates it; find a compromise
|
||||||
CLANG_FORMAT_FILES += except.cpp except.h
|
CLANG_FORMAT_EXCLUDE_FILES += miniacc.h stub/%.h
|
||||||
CLANG_FORMAT_FILES += file.cpp file.h
|
CLANG_FORMAT_EXCLUDE_FILES += p_lx_% p_mach% p_unix% p_vmlin%
|
||||||
CLANG_FORMAT_FILES += linker.cpp linker.h packhead.cpp packmast.cpp packmast.h
|
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*))
|
||||||
CLANG_FORMAT_FILES += main.cpp options.cpp options.h packer.cpp packer.h
|
CLANG_FORMAT_FILES += $(sort $(wildcard stub/tools/*/*.[ch]*))
|
||||||
CLANG_FORMAT_FILES += p_tos.cpp p_tos.h
|
CLANG_FORMAT_FILES += $(sort $(wildcard ../misc/cmake/try_compile/*.[ch]*))
|
||||||
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
|
CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))
|
||||||
CLANG_FORMAT_FILES += ui.cpp ui.h work.cpp
|
clang-format: $(CLANG_FORMAT_FILES) PHONY
|
||||||
CLANG_FORMAT_FILES += $(wildcard util/[a-ln-z]*.[ch]* util/mem*.[ch]*)
|
@echo "running upx-clang-format"
|
||||||
clang-format:
|
@$(top_srcdir)/misc/scripts/upx-clang-format.sh -i $(CLANG_FORMAT_FILES)
|
||||||
$(top_srcdir)/misc/scripts/upx-clang-format -i $(addprefix $(top_srcdir)/src/,$(sort $(CLANG_FORMAT_FILES)))
|
|
||||||
.PHONY: clang-format
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#
|
|
||||||
# "make check-whitespace"
|
|
||||||
#
|
|
||||||
|
|
||||||
CHECK_WHITESPACE =
|
|
||||||
ifeq ($(shell uname),Linux)
|
|
||||||
CHECK_WHITESPACE = $(top_srcdir)/misc/scripts/check_whitespace.sh $(top_srcdir)
|
|
||||||
ifneq ($(wildcard $(top_srcdir)/.git/.),)
|
|
||||||
CHECK_WHITESPACE = $(top_srcdir)/misc/scripts/check_whitespace_git.sh $(top_srcdir)
|
|
||||||
endif
|
|
||||||
check-whitespace : ; $(CHECK_WHITESPACE)
|
|
||||||
endif
|
|
||||||
.PHONY: check-whitespace
|
|
||||||
|
|
||||||
# vim:set ts=8 sw=8 noet:
|
# vim:set ts=8 sw=8 noet:
|
||||||
|
|||||||
+337
-190
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -26,47 +26,119 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef UPX_BELE_H__
|
|
||||||
#define UPX_BELE_H__ 1
|
|
||||||
|
|
||||||
// BE - Big Endian
|
// BE - Big Endian
|
||||||
// LE - Little Endian
|
// LE - Little Endian
|
||||||
// NE - Native Endianness (aka host endianness)
|
// NE - Native Endianness (aka Host Endianness aka CPU Endianness)
|
||||||
// TE - Target Endianness (not used here, see various packers)
|
// TE - Target Endianness (not used here, see various packers)
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// some platforms may provide their own system bswapXX() functions, so rename to avoid conflicts
|
||||||
|
#undef bswap16
|
||||||
|
#undef bswap32
|
||||||
|
#undef bswap64
|
||||||
|
#define bswap16 upx_bswap16
|
||||||
|
#define bswap32 upx_bswap32
|
||||||
|
#define bswap64 upx_bswap64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// XE - eXtended Endian compatibility
|
||||||
|
// try to detect XX16 vs XX32 vs XX64 size mismatches
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if 0 // permissive version using "void *"
|
||||||
|
|
||||||
|
#define REQUIRE_XE16 /*empty*/
|
||||||
|
#define REQUIRE_XE24 /*empty*/
|
||||||
|
#define REQUIRE_XE32 /*empty*/
|
||||||
|
#define REQUIRE_XE64 /*empty*/
|
||||||
|
typedef void XE16;
|
||||||
|
typedef void XE24;
|
||||||
|
typedef void XE32;
|
||||||
|
typedef void XE64;
|
||||||
|
|
||||||
|
#else // permissive version
|
||||||
|
|
||||||
|
// forward declarations
|
||||||
|
struct BE16;
|
||||||
|
struct BE32;
|
||||||
|
struct BE64;
|
||||||
|
struct LE16;
|
||||||
|
struct LE32;
|
||||||
|
struct LE64;
|
||||||
|
|
||||||
|
// Note:
|
||||||
|
// void is explicitly allowed (but there is no automatic pointer conversion because of template!)
|
||||||
|
// char is explicitly allowed
|
||||||
|
// byte is explicitly allowed
|
||||||
|
template <class T>
|
||||||
|
static inline constexpr bool is_xe16_type =
|
||||||
|
upx::is_same_any_v<T, void, char, byte, upx_int16_t, upx_uint16_t, BE16, LE16>;
|
||||||
|
template <class T>
|
||||||
|
static inline constexpr bool is_xe24_type = upx::is_same_any_v<T, void, char, byte>;
|
||||||
|
template <class T>
|
||||||
|
static inline constexpr bool is_xe32_type =
|
||||||
|
upx::is_same_any_v<T, void, char, byte, upx_int32_t, upx_uint32_t, BE32, LE32>;
|
||||||
|
template <class T>
|
||||||
|
static inline constexpr bool is_xe64_type =
|
||||||
|
upx::is_same_any_v<T, void, char, byte, upx_int64_t, upx_uint64_t, BE64, LE64>;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
using enable_if_xe16 = std::enable_if_t<is_xe16_type<T>, T>;
|
||||||
|
template <class T>
|
||||||
|
using enable_if_xe24 = std::enable_if_t<is_xe24_type<T>, T>;
|
||||||
|
template <class T>
|
||||||
|
using enable_if_xe32 = std::enable_if_t<is_xe32_type<T>, T>;
|
||||||
|
template <class T>
|
||||||
|
using enable_if_xe64 = std::enable_if_t<is_xe64_type<T>, T>;
|
||||||
|
|
||||||
|
#define REQUIRE_XE16 template <class XE16, class = enable_if_xe16<XE16> >
|
||||||
|
#define REQUIRE_XE24 template <class XE24, class = enable_if_xe24<XE24> >
|
||||||
|
#define REQUIRE_XE32 template <class XE32, class = enable_if_xe32<XE32> >
|
||||||
|
#define REQUIRE_XE64 template <class XE64, class = enable_if_xe64<XE64> >
|
||||||
|
|
||||||
|
#endif // permissive version
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// core - NE
|
// core - NE
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
__acc_static_forceinline unsigned get_ne16(const void *p) {
|
REQUIRE_XE16
|
||||||
|
static forceinline unsigned get_ne16(const XE16 *p) noexcept {
|
||||||
upx_uint16_t v = 0;
|
upx_uint16_t v = 0;
|
||||||
upx_memcpy_inline(&v, p, sizeof(v));
|
upx_memcpy_inline(&v, p, sizeof(v));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline unsigned get_ne32(const void *p) {
|
REQUIRE_XE32
|
||||||
|
static forceinline unsigned get_ne32(const XE32 *p) noexcept {
|
||||||
upx_uint32_t v = 0;
|
upx_uint32_t v = 0;
|
||||||
upx_memcpy_inline(&v, p, sizeof(v));
|
upx_memcpy_inline(&v, p, sizeof(v));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline upx_uint64_t get_ne64(const void *p) {
|
REQUIRE_XE64
|
||||||
|
static forceinline upx_uint64_t get_ne64(const XE64 *p) noexcept {
|
||||||
upx_uint64_t v = 0;
|
upx_uint64_t v = 0;
|
||||||
upx_memcpy_inline(&v, p, sizeof(v));
|
upx_memcpy_inline(&v, p, sizeof(v));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline void set_ne16(void *p, unsigned vv) {
|
REQUIRE_XE16
|
||||||
|
static forceinline void set_ne16(XE16 *p, unsigned vv) noexcept {
|
||||||
upx_uint16_t v = (upx_uint16_t) (vv & 0xffff);
|
upx_uint16_t v = (upx_uint16_t) (vv & 0xffff);
|
||||||
upx_memcpy_inline(p, &v, sizeof(v));
|
upx_memcpy_inline(p, &v, sizeof(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline void set_ne32(void *p, unsigned vv) {
|
REQUIRE_XE32
|
||||||
|
static forceinline void set_ne32(XE32 *p, unsigned vv) noexcept {
|
||||||
upx_uint32_t v = vv;
|
upx_uint32_t v = vv;
|
||||||
upx_memcpy_inline(p, &v, sizeof(v));
|
upx_memcpy_inline(p, &v, sizeof(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline void set_ne64(void *p, upx_uint64_t vv) {
|
REQUIRE_XE64
|
||||||
|
static forceinline void set_ne64(XE64 *p, upx_uint64_t vv) noexcept {
|
||||||
upx_uint64_t v = vv;
|
upx_uint64_t v = vv;
|
||||||
upx_memcpy_inline(p, &v, sizeof(v));
|
upx_memcpy_inline(p, &v, sizeof(v));
|
||||||
}
|
}
|
||||||
@@ -79,36 +151,42 @@ __acc_static_forceinline void set_ne64(void *p, upx_uint64_t vv) {
|
|||||||
|
|
||||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4)
|
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4)
|
||||||
|
|
||||||
__acc_static_forceinline unsigned bswap16(unsigned v) {
|
// unfortunately *not* constexpr with current MSVC
|
||||||
|
static forceinline unsigned bswap16(unsigned v) noexcept {
|
||||||
return (unsigned) _byteswap_ulong(v << 16);
|
return (unsigned) _byteswap_ulong(v << 16);
|
||||||
}
|
}
|
||||||
__acc_static_forceinline unsigned bswap32(unsigned v) { return (unsigned) _byteswap_ulong(v); }
|
static forceinline unsigned bswap32(unsigned v) noexcept { return (unsigned) _byteswap_ulong(v); }
|
||||||
__acc_static_forceinline upx_uint64_t bswap64(upx_uint64_t v) { return _byteswap_uint64(v); }
|
static forceinline upx_uint64_t bswap64(upx_uint64_t v) noexcept { return _byteswap_uint64(v); }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
__acc_static_forceinline constexpr unsigned bswap16(unsigned v) {
|
static forceinline constexpr unsigned bswap16(unsigned v) noexcept {
|
||||||
|
#if defined(__riscv) && __riscv_xlen == 64
|
||||||
|
return (unsigned) __builtin_bswap64((upx_uint64_t) v << 48);
|
||||||
|
#else
|
||||||
// return __builtin_bswap16((upx_uint16_t) (v & 0xffff));
|
// return __builtin_bswap16((upx_uint16_t) (v & 0xffff));
|
||||||
// return (unsigned) __builtin_bswap64((upx_uint64_t) v << 48);
|
|
||||||
return __builtin_bswap32(v << 16);
|
return __builtin_bswap32(v << 16);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
__acc_static_forceinline constexpr unsigned bswap32(unsigned v) {
|
static forceinline constexpr unsigned bswap32(unsigned v) noexcept {
|
||||||
// return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
|
#if defined(__riscv) && __riscv_xlen == 64
|
||||||
|
return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
|
||||||
|
#else
|
||||||
return __builtin_bswap32(v);
|
return __builtin_bswap32(v);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
__acc_static_forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v) {
|
static forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v) noexcept {
|
||||||
return __builtin_bswap64(v);
|
return __builtin_bswap64(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__acc_static_forceinline constexpr unsigned no_bswap16(unsigned v) {
|
static forceinline constexpr unsigned no_bswap16(unsigned v) noexcept {
|
||||||
return v & 0xffff; // needed so that this is equivalent to bswap16() above
|
// mask is needed so that for all v: bswap16(bswap16(v)) == no_bswap16(v)
|
||||||
|
return v & 0xffff;
|
||||||
}
|
}
|
||||||
|
static forceinline constexpr unsigned no_bswap32(unsigned v) noexcept { return v; }
|
||||||
__acc_static_forceinline constexpr unsigned no_bswap32(unsigned v) { return v; }
|
static forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) noexcept { return v; }
|
||||||
|
|
||||||
__acc_static_forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) { return v; }
|
|
||||||
|
|
||||||
#if (ACC_ABI_BIG_ENDIAN)
|
#if (ACC_ABI_BIG_ENDIAN)
|
||||||
#define ne16_to_be16(v) no_bswap16(v)
|
#define ne16_to_be16(v) no_bswap16(v)
|
||||||
@@ -130,111 +208,144 @@ __acc_static_forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) { ret
|
|||||||
// get/set 16/32/64
|
// get/set 16/32/64
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
inline unsigned get_be16(const void *p) { return ne16_to_be16(get_ne16(p)); }
|
REQUIRE_XE16
|
||||||
inline unsigned get_be32(const void *p) { return ne32_to_be32(get_ne32(p)); }
|
inline unsigned get_be16(const XE16 *p) noexcept { return ne16_to_be16(get_ne16(p)); }
|
||||||
inline upx_uint64_t get_be64(const void *p) { return ne64_to_be64(get_ne64(p)); }
|
REQUIRE_XE32
|
||||||
inline unsigned get_le16(const void *p) { return ne16_to_le16(get_ne16(p)); }
|
inline unsigned get_be32(const XE32 *p) noexcept { return ne32_to_be32(get_ne32(p)); }
|
||||||
inline unsigned get_le32(const void *p) { return ne32_to_le32(get_ne32(p)); }
|
REQUIRE_XE64
|
||||||
inline upx_uint64_t get_le64(const void *p) { return ne64_to_le64(get_ne64(p)); }
|
inline upx_uint64_t get_be64(const XE64 *p) noexcept { return ne64_to_be64(get_ne64(p)); }
|
||||||
inline void set_be16(void *p, unsigned v) { set_ne16(p, ne16_to_be16(v)); }
|
REQUIRE_XE16
|
||||||
inline void set_be32(void *p, unsigned v) { set_ne32(p, ne32_to_be32(v)); }
|
inline unsigned get_le16(const XE16 *p) noexcept { return ne16_to_le16(get_ne16(p)); }
|
||||||
inline void set_be64(void *p, upx_uint64_t v) { set_ne64(p, ne64_to_be64(v)); }
|
REQUIRE_XE32
|
||||||
inline void set_le16(void *p, unsigned v) { set_ne16(p, ne16_to_le16(v)); }
|
inline unsigned get_le32(const XE32 *p) noexcept { return ne32_to_le32(get_ne32(p)); }
|
||||||
inline void set_le32(void *p, unsigned v) { set_ne32(p, ne32_to_le32(v)); }
|
REQUIRE_XE64
|
||||||
inline void set_le64(void *p, upx_uint64_t v) { set_ne64(p, ne64_to_le64(v)); }
|
inline upx_uint64_t get_le64(const XE64 *p) noexcept { return ne64_to_le64(get_ne64(p)); }
|
||||||
|
|
||||||
|
REQUIRE_XE16
|
||||||
|
inline void set_be16(XE16 *p, unsigned v) noexcept { set_ne16(p, ne16_to_be16(v)); }
|
||||||
|
REQUIRE_XE32
|
||||||
|
inline void set_be32(XE32 *p, unsigned v) noexcept { set_ne32(p, ne32_to_be32(v)); }
|
||||||
|
REQUIRE_XE64
|
||||||
|
inline void set_be64(XE64 *p, upx_uint64_t v) noexcept { set_ne64(p, ne64_to_be64(v)); }
|
||||||
|
REQUIRE_XE16
|
||||||
|
inline void set_le16(XE16 *p, unsigned v) noexcept { set_ne16(p, ne16_to_le16(v)); }
|
||||||
|
REQUIRE_XE32
|
||||||
|
inline void set_le32(XE32 *p, unsigned v) noexcept { set_ne32(p, ne32_to_le32(v)); }
|
||||||
|
REQUIRE_XE64
|
||||||
|
inline void set_le64(XE64 *p, upx_uint64_t v) noexcept { set_ne64(p, ne64_to_le64(v)); }
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// get/set 24/26
|
// get/set 24/26
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
inline unsigned get_be24(const void *p) {
|
REQUIRE_XE24
|
||||||
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
|
inline unsigned get_be24(const XE24 *p) noexcept {
|
||||||
|
const byte *b = ACC_CCAST(const byte *, p);
|
||||||
return (b[0] << 16) | (b[1] << 8) | (b[2] << 0);
|
return (b[0] << 16) | (b[1] << 8) | (b[2] << 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned get_le24(const void *p) {
|
REQUIRE_XE24
|
||||||
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
|
inline unsigned get_le24(const XE24 *p) noexcept {
|
||||||
|
const byte *b = ACC_CCAST(const byte *, p);
|
||||||
return (b[0] << 0) | (b[1] << 8) | (b[2] << 16);
|
return (b[0] << 0) | (b[1] << 8) | (b[2] << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void set_be24(void *p, unsigned v) {
|
REQUIRE_XE24
|
||||||
unsigned char *b = ACC_PCAST(unsigned char *, p);
|
inline void set_be24(XE24 *p, unsigned v) noexcept {
|
||||||
b[0] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
|
byte *b = ACC_PCAST(byte *, p);
|
||||||
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
b[0] = ACC_ICONV(byte, (v >> 16) & 0xff);
|
||||||
b[2] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
|
b[1] = ACC_ICONV(byte, (v >> 8) & 0xff);
|
||||||
|
b[2] = ACC_ICONV(byte, (v >> 0) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void set_le24(void *p, unsigned v) {
|
REQUIRE_XE24
|
||||||
unsigned char *b = ACC_PCAST(unsigned char *, p);
|
inline void set_le24(XE24 *p, unsigned v) noexcept {
|
||||||
b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
|
byte *b = ACC_PCAST(byte *, p);
|
||||||
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
b[0] = ACC_ICONV(byte, (v >> 0) & 0xff);
|
||||||
b[2] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
|
b[1] = ACC_ICONV(byte, (v >> 8) & 0xff);
|
||||||
|
b[2] = ACC_ICONV(byte, (v >> 16) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned get_le26(const void *p) { return get_le32(p) & 0x03ffffff; }
|
inline unsigned get_le26(const void *p) noexcept { return get_le32(p) & 0x03ffffff; }
|
||||||
|
inline unsigned get_le19_5(const void *p) noexcept { return (get_le32(p) >> 5) & 0x0007ffff; }
|
||||||
|
inline unsigned get_le14_5(const void *p) noexcept { return (get_le32(p) >> 5) & 0x00003fff; }
|
||||||
|
|
||||||
inline void set_le26(void *p, unsigned v) {
|
inline void set_le26(void *p, unsigned v) noexcept {
|
||||||
// preserve the top 6 bits
|
// preserve the top 6 bits
|
||||||
// set_le32(p, (get_le32(p) & 0xfc000000) | (v & 0x03ffffff));
|
// set_le32(p, (get_le32(p) & 0xfc000000) | (v & 0x03ffffff));
|
||||||
// optimized version, saving a runtime bswap32
|
// optimized version, saving a runtime bswap32
|
||||||
set_ne32(p, (get_ne32(p) & ne32_to_le32(0xfc000000)) |
|
set_ne32(p, (get_ne32(p) & ne32_to_le32(0xfc000000)) |
|
||||||
(ne32_to_le32(v) & ne32_to_le32(0x03ffffff)));
|
(ne32_to_le32(v) & ne32_to_le32(0x03ffffff)));
|
||||||
}
|
}
|
||||||
|
inline void set_le19_5(void *p, unsigned v) noexcept {
|
||||||
|
set_le32(p, (get_le32(p) & 0xff00001f) | ((v & 0x0007ffff) << 5));
|
||||||
|
}
|
||||||
|
inline void set_le14_5(void *p, unsigned v) noexcept {
|
||||||
|
set_le32(p, (get_le32(p) & 0xfff8001f) | ((v & 0x00003fff) << 5));
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// get signed values
|
// get signed values
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
__acc_static_forceinline int sign_extend(unsigned v, unsigned bits) {
|
static forceinline constexpr int sign_extend(unsigned v, unsigned bits) noexcept {
|
||||||
const unsigned sign_bit = 1u << (bits - 1);
|
const unsigned sign_bit = 1u << (bits - 1);
|
||||||
v &= sign_bit | (sign_bit - 1);
|
v &= sign_bit | (sign_bit - 1);
|
||||||
v |= 0 - (v & sign_bit);
|
v |= 0u - (v & sign_bit);
|
||||||
return ACC_ICAST(int, v);
|
return ACC_ICAST(int, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits) {
|
static forceinline constexpr upx_int64_t sign_extend(upx_uint64_t v, unsigned bits) noexcept {
|
||||||
const upx_uint64_t sign_bit = 1ull << (bits - 1);
|
const upx_uint64_t sign_bit = 1ull << (bits - 1);
|
||||||
v &= sign_bit | (sign_bit - 1);
|
v &= sign_bit | (sign_bit - 1);
|
||||||
v |= 0 - (v & sign_bit);
|
v |= 0ull - (v & sign_bit);
|
||||||
return ACC_ICAST(upx_int64_t, v);
|
return ACC_ICAST(upx_int64_t, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int get_be16_signed(const void *p) {
|
REQUIRE_XE16
|
||||||
|
inline int get_be16_signed(const XE16 *p) noexcept {
|
||||||
unsigned v = get_be16(p);
|
unsigned v = get_be16(p);
|
||||||
return sign_extend(v, 16);
|
return sign_extend(v, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int get_be24_signed(const void *p) {
|
REQUIRE_XE24
|
||||||
|
inline int get_be24_signed(const XE24 *p) noexcept {
|
||||||
unsigned v = get_be24(p);
|
unsigned v = get_be24(p);
|
||||||
return sign_extend(v, 24);
|
return sign_extend(v, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int get_be32_signed(const void *p) {
|
REQUIRE_XE32
|
||||||
|
inline int get_be32_signed(const XE32 *p) noexcept {
|
||||||
unsigned v = get_be32(p);
|
unsigned v = get_be32(p);
|
||||||
return sign_extend(v, 32);
|
return sign_extend(v, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline upx_int64_t get_be64_signed(const void *p) {
|
REQUIRE_XE64
|
||||||
|
inline upx_int64_t get_be64_signed(const XE64 *p) noexcept {
|
||||||
upx_uint64_t v = get_be64(p);
|
upx_uint64_t v = get_be64(p);
|
||||||
return sign_extend(v, 64);
|
return sign_extend(v, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int get_le16_signed(const void *p) {
|
REQUIRE_XE16
|
||||||
|
inline int get_le16_signed(const XE16 *p) noexcept {
|
||||||
unsigned v = get_le16(p);
|
unsigned v = get_le16(p);
|
||||||
return sign_extend(v, 16);
|
return sign_extend(v, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int get_le24_signed(const void *p) {
|
REQUIRE_XE24
|
||||||
|
inline int get_le24_signed(const XE24 *p) noexcept {
|
||||||
unsigned v = get_le24(p);
|
unsigned v = get_le24(p);
|
||||||
return sign_extend(v, 24);
|
return sign_extend(v, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int get_le32_signed(const void *p) {
|
REQUIRE_XE32
|
||||||
|
inline int get_le32_signed(const XE32 *p) noexcept {
|
||||||
unsigned v = get_le32(p);
|
unsigned v = get_le32(p);
|
||||||
return sign_extend(v, 32);
|
return sign_extend(v, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline upx_int64_t get_le64_signed(const void *p) {
|
REQUIRE_XE64
|
||||||
|
inline upx_int64_t get_le64_signed(const XE64 *p) noexcept {
|
||||||
upx_uint64_t v = get_le64(p);
|
upx_uint64_t v = get_le64(p);
|
||||||
return sign_extend(v, 64);
|
return sign_extend(v, 64);
|
||||||
}
|
}
|
||||||
@@ -250,362 +361,358 @@ inline upx_int64_t get_le64_signed(const void *p) {
|
|||||||
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
|
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
struct alignas(1) BE16 {
|
struct alignas(1) BE16 final {
|
||||||
unsigned char d[2];
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
|
byte d[2];
|
||||||
|
|
||||||
BE16 &operator=(unsigned v) {
|
forceinline operator unsigned() const noexcept { return get_be16(d); }
|
||||||
|
|
||||||
|
forceinline BE16 &operator=(unsigned v) noexcept {
|
||||||
set_be16(d, v);
|
set_be16(d, v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator+=(unsigned v) {
|
BE16 &operator+=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) + v);
|
set_be16(d, get_be16(d) + v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator-=(unsigned v) {
|
BE16 &operator-=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) - v);
|
set_be16(d, get_be16(d) - v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator*=(unsigned v) {
|
BE16 &operator*=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) * v);
|
set_be16(d, get_be16(d) * v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator/=(unsigned v) {
|
BE16 &operator/=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) / v);
|
set_be16(d, get_be16(d) / v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator&=(unsigned v) {
|
BE16 &operator&=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) & v);
|
set_be16(d, get_be16(d) & v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator|=(unsigned v) {
|
BE16 &operator|=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) | v);
|
set_be16(d, get_be16(d) | v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator^=(unsigned v) {
|
BE16 &operator^=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) ^ v);
|
set_be16(d, get_be16(d) ^ v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator<<=(unsigned v) {
|
BE16 &operator<<=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) << v);
|
set_be16(d, get_be16(d) << v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE16 &operator>>=(unsigned v) {
|
BE16 &operator>>=(unsigned v) noexcept {
|
||||||
set_be16(d, get_be16(d) >> v);
|
set_be16(d, get_be16(d) >> v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator unsigned() const { return get_be16(d); }
|
bool operator==(const BE16 &x) const noexcept { return memcmp(d, x.d, sizeof(d)) == 0; }
|
||||||
|
bool operator<(const BE16 &x) const noexcept { return unsigned(*this) < unsigned(x); }
|
||||||
bool operator<(const BE16 &v) const { return unsigned(*this) < unsigned(v); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) BE32 {
|
struct alignas(1) BE32 final {
|
||||||
unsigned char d[4];
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
|
byte d[4];
|
||||||
|
|
||||||
BE32 &operator=(unsigned v) {
|
forceinline operator unsigned() const noexcept { return get_be32(d); }
|
||||||
|
|
||||||
|
forceinline BE32 &operator=(unsigned v) noexcept {
|
||||||
set_be32(d, v);
|
set_be32(d, v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator+=(unsigned v) {
|
BE32 &operator+=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) + v);
|
set_be32(d, get_be32(d) + v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator-=(unsigned v) {
|
BE32 &operator-=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) - v);
|
set_be32(d, get_be32(d) - v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator*=(unsigned v) {
|
BE32 &operator*=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) * v);
|
set_be32(d, get_be32(d) * v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator/=(unsigned v) {
|
BE32 &operator/=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) / v);
|
set_be32(d, get_be32(d) / v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator&=(unsigned v) {
|
BE32 &operator&=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) & v);
|
set_be32(d, get_be32(d) & v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator|=(unsigned v) {
|
BE32 &operator|=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) | v);
|
set_be32(d, get_be32(d) | v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator^=(unsigned v) {
|
BE32 &operator^=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) ^ v);
|
set_be32(d, get_be32(d) ^ v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator<<=(unsigned v) {
|
BE32 &operator<<=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) << v);
|
set_be32(d, get_be32(d) << v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE32 &operator>>=(unsigned v) {
|
BE32 &operator>>=(unsigned v) noexcept {
|
||||||
set_be32(d, get_be32(d) >> v);
|
set_be32(d, get_be32(d) >> v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator unsigned() const { return get_be32(d); }
|
bool operator==(const BE32 &x) const noexcept { return memcmp(d, x.d, sizeof(d)) == 0; }
|
||||||
|
bool operator<(const BE32 &x) const noexcept { return unsigned(*this) < unsigned(x); }
|
||||||
bool operator<(const BE32 &v) const { return unsigned(*this) < unsigned(v); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) BE64 {
|
struct alignas(1) BE64 final {
|
||||||
unsigned char d[8];
|
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
|
||||||
|
byte d[8];
|
||||||
|
|
||||||
BE64 &operator=(upx_uint64_t v) {
|
forceinline operator upx_uint64_t() const noexcept { return get_be64(d); }
|
||||||
|
|
||||||
|
forceinline BE64 &operator=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, v);
|
set_be64(d, v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator+=(upx_uint64_t v) {
|
BE64 &operator+=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, get_be64(d) + v);
|
set_be64(d, get_be64(d) + v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator-=(upx_uint64_t v) {
|
BE64 &operator-=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, get_be64(d) - v);
|
set_be64(d, get_be64(d) - v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator*=(upx_uint64_t v) {
|
BE64 &operator*=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, get_be64(d) * v);
|
set_be64(d, get_be64(d) * v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator/=(upx_uint64_t v) {
|
BE64 &operator/=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, get_be64(d) / v);
|
set_be64(d, get_be64(d) / v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator&=(upx_uint64_t v) {
|
BE64 &operator&=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, get_be64(d) & v);
|
set_be64(d, get_be64(d) & v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator|=(upx_uint64_t v) {
|
BE64 &operator|=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, get_be64(d) | v);
|
set_be64(d, get_be64(d) | v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator^=(upx_uint64_t v) {
|
BE64 &operator^=(upx_uint64_t v) noexcept {
|
||||||
set_be64(d, get_be64(d) ^ v);
|
set_be64(d, get_be64(d) ^ v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator<<=(unsigned v) {
|
BE64 &operator<<=(unsigned v) noexcept {
|
||||||
set_be64(d, get_be64(d) << v);
|
set_be64(d, get_be64(d) << v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
BE64 &operator>>=(unsigned v) {
|
BE64 &operator>>=(unsigned v) noexcept {
|
||||||
set_be64(d, get_be64(d) >> v);
|
set_be64(d, get_be64(d) >> v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator upx_uint64_t() const { return get_be64(d); }
|
bool operator==(const BE64 &x) const noexcept { return memcmp(d, x.d, sizeof(d)) == 0; }
|
||||||
|
bool operator<(const BE64 &x) const noexcept { return upx_uint64_t(*this) < upx_uint64_t(x); }
|
||||||
bool operator<(const BE64 &v) const { return upx_uint64_t(*this) < upx_uint64_t(v); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) LE16 {
|
struct alignas(1) LE16 final {
|
||||||
unsigned char d[2];
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
|
byte d[2];
|
||||||
|
|
||||||
LE16 &operator=(unsigned v) {
|
forceinline operator unsigned() const noexcept { return get_le16(d); }
|
||||||
|
|
||||||
|
forceinline LE16 &operator=(unsigned v) noexcept {
|
||||||
set_le16(d, v);
|
set_le16(d, v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator+=(unsigned v) {
|
LE16 &operator+=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) + v);
|
set_le16(d, get_le16(d) + v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator-=(unsigned v) {
|
LE16 &operator-=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) - v);
|
set_le16(d, get_le16(d) - v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator*=(unsigned v) {
|
LE16 &operator*=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) * v);
|
set_le16(d, get_le16(d) * v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator/=(unsigned v) {
|
LE16 &operator/=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) / v);
|
set_le16(d, get_le16(d) / v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator&=(unsigned v) {
|
LE16 &operator&=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) & v);
|
set_le16(d, get_le16(d) & v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator|=(unsigned v) {
|
LE16 &operator|=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) | v);
|
set_le16(d, get_le16(d) | v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator^=(unsigned v) {
|
LE16 &operator^=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) ^ v);
|
set_le16(d, get_le16(d) ^ v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator<<=(unsigned v) {
|
LE16 &operator<<=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) << v);
|
set_le16(d, get_le16(d) << v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE16 &operator>>=(unsigned v) {
|
LE16 &operator>>=(unsigned v) noexcept {
|
||||||
set_le16(d, get_le16(d) >> v);
|
set_le16(d, get_le16(d) >> v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator unsigned() const { return get_le16(d); }
|
bool operator==(const LE16 &x) const noexcept { return memcmp(d, x.d, sizeof(d)) == 0; }
|
||||||
|
bool operator<(const LE16 &x) const noexcept { return unsigned(*this) < unsigned(x); }
|
||||||
bool operator<(const LE16 &v) const { return unsigned(*this) < unsigned(v); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) LE32 {
|
struct alignas(1) LE32 final {
|
||||||
unsigned char d[4];
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
|
byte d[4];
|
||||||
|
|
||||||
LE32 &operator=(unsigned v) {
|
forceinline operator unsigned() const noexcept { return get_le32(d); }
|
||||||
|
|
||||||
|
forceinline LE32 &operator=(unsigned v) noexcept {
|
||||||
set_le32(d, v);
|
set_le32(d, v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator+=(unsigned v) {
|
LE32 &operator+=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) + v);
|
set_le32(d, get_le32(d) + v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator-=(unsigned v) {
|
LE32 &operator-=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) - v);
|
set_le32(d, get_le32(d) - v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator*=(unsigned v) {
|
LE32 &operator*=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) * v);
|
set_le32(d, get_le32(d) * v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator/=(unsigned v) {
|
LE32 &operator/=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) / v);
|
set_le32(d, get_le32(d) / v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator&=(unsigned v) {
|
LE32 &operator&=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) & v);
|
set_le32(d, get_le32(d) & v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator|=(unsigned v) {
|
LE32 &operator|=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) | v);
|
set_le32(d, get_le32(d) | v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator^=(unsigned v) {
|
LE32 &operator^=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) ^ v);
|
set_le32(d, get_le32(d) ^ v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator<<=(unsigned v) {
|
LE32 &operator<<=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) << v);
|
set_le32(d, get_le32(d) << v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE32 &operator>>=(unsigned v) {
|
LE32 &operator>>=(unsigned v) noexcept {
|
||||||
set_le32(d, get_le32(d) >> v);
|
set_le32(d, get_le32(d) >> v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator unsigned() const { return get_le32(d); }
|
bool operator==(const LE32 &x) const noexcept { return memcmp(d, x.d, sizeof(d)) == 0; }
|
||||||
|
bool operator<(const LE32 &x) const noexcept { return unsigned(*this) < unsigned(x); }
|
||||||
bool operator<(const LE32 &v) const { return unsigned(*this) < unsigned(v); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) LE64 {
|
struct alignas(1) LE64 final {
|
||||||
unsigned char d[8];
|
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
|
||||||
|
byte d[8];
|
||||||
|
|
||||||
LE64 &operator=(upx_uint64_t v) {
|
forceinline operator upx_uint64_t() const noexcept { return get_le64(d); }
|
||||||
|
|
||||||
|
forceinline LE64 &operator=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, v);
|
set_le64(d, v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator+=(upx_uint64_t v) {
|
LE64 &operator+=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, get_le64(d) + v);
|
set_le64(d, get_le64(d) + v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator-=(upx_uint64_t v) {
|
LE64 &operator-=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, get_le64(d) - v);
|
set_le64(d, get_le64(d) - v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator*=(upx_uint64_t v) {
|
LE64 &operator*=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, get_le64(d) * v);
|
set_le64(d, get_le64(d) * v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator/=(upx_uint64_t v) {
|
LE64 &operator/=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, get_le64(d) / v);
|
set_le64(d, get_le64(d) / v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator&=(upx_uint64_t v) {
|
LE64 &operator&=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, get_le64(d) & v);
|
set_le64(d, get_le64(d) & v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator|=(upx_uint64_t v) {
|
LE64 &operator|=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, get_le64(d) | v);
|
set_le64(d, get_le64(d) | v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator^=(upx_uint64_t v) {
|
LE64 &operator^=(upx_uint64_t v) noexcept {
|
||||||
set_le64(d, get_le64(d) ^ v);
|
set_le64(d, get_le64(d) ^ v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator<<=(unsigned v) {
|
LE64 &operator<<=(unsigned v) noexcept {
|
||||||
set_le64(d, get_le64(d) << v);
|
set_le64(d, get_le64(d) << v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
LE64 &operator>>=(unsigned v) {
|
LE64 &operator>>=(unsigned v) noexcept {
|
||||||
set_le64(d, get_le64(d) >> v);
|
set_le64(d, get_le64(d) >> v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator upx_uint64_t() const { return get_le64(d); }
|
bool operator==(const LE64 &x) const noexcept { return memcmp(d, x.d, sizeof(d)) == 0; }
|
||||||
|
bool operator<(const LE64 &x) const noexcept { return upx_uint64_t(*this) < upx_uint64_t(x); }
|
||||||
bool operator<(const LE64 &v) const { return upx_uint64_t(*this) < upx_uint64_t(v); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// native types
|
|
||||||
#if (ACC_ABI_BIG_ENDIAN)
|
|
||||||
typedef BE16 NE16;
|
|
||||||
typedef BE32 NE32;
|
|
||||||
typedef BE64 NE64;
|
|
||||||
#else
|
|
||||||
typedef LE16 NE16;
|
|
||||||
typedef LE32 NE32;
|
|
||||||
typedef LE64 NE64;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// global operators (pointer addition/subtraction)
|
// global operators (pointer addition/subtraction)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T *operator+(T *ptr, const BE16 &v) {
|
inline T *operator+(T *ptr, const BE16 &v) noexcept {
|
||||||
return ptr + unsigned(v);
|
return ptr + unsigned(v);
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T *operator-(T *ptr, const BE16 &v) {
|
inline T *operator-(T *ptr, const BE16 &v) noexcept {
|
||||||
return ptr - unsigned(v);
|
return ptr - unsigned(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T *operator+(T *ptr, const BE32 &v) {
|
inline T *operator+(T *ptr, const BE32 &v) noexcept {
|
||||||
return ptr + unsigned(v);
|
return ptr + unsigned(v);
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T *operator-(T *ptr, const BE32 &v) {
|
inline T *operator-(T *ptr, const BE32 &v) noexcept {
|
||||||
return ptr - unsigned(v);
|
return ptr - unsigned(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are not implemented on purpose and will cause link-time errors
|
|
||||||
template <class T>
|
template <class T>
|
||||||
T *operator+(T *ptr, const BE64 &v);
|
inline T *operator+(T *ptr, const LE16 &v) noexcept {
|
||||||
template <class T>
|
|
||||||
T *operator-(T *ptr, const BE64 &v);
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline T *operator+(T *ptr, const LE16 &v) {
|
|
||||||
return ptr + unsigned(v);
|
return ptr + unsigned(v);
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T *operator-(T *ptr, const LE16 &v) {
|
inline T *operator-(T *ptr, const LE16 &v) noexcept {
|
||||||
return ptr - unsigned(v);
|
return ptr - unsigned(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T *operator+(T *ptr, const LE32 &v) {
|
inline T *operator+(T *ptr, const LE32 &v) noexcept {
|
||||||
return ptr + unsigned(v);
|
return ptr + unsigned(v);
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T *operator-(T *ptr, const LE32 &v) {
|
inline T *operator-(T *ptr, const LE32 &v) noexcept {
|
||||||
return ptr - unsigned(v);
|
return ptr - unsigned(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are not implemented on purpose and will cause link-time errors
|
// these are not implemented on purpose and will cause errors
|
||||||
template <class T>
|
template <class T>
|
||||||
T *operator+(T *ptr, const LE64 &v);
|
T *operator+(T *ptr, const BE64 &v) noexcept DELETED_FUNCTION;
|
||||||
template <class T>
|
template <class T>
|
||||||
T *operator-(T *ptr, const LE64 &v);
|
T *operator-(T *ptr, const BE64 &v) noexcept DELETED_FUNCTION;
|
||||||
|
template <class T>
|
||||||
|
T *operator+(T *ptr, const LE64 &v) noexcept DELETED_FUNCTION;
|
||||||
|
template <class T>
|
||||||
|
T *operator-(T *ptr, const LE64 &v) noexcept DELETED_FUNCTION;
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// global overloads
|
// global overloads
|
||||||
@@ -621,6 +728,7 @@ inline unsigned ALIGN_DOWN(const LE32 &a, unsigned b) { return ALIGN_DOWN(unsign
|
|||||||
inline unsigned ALIGN_UP(unsigned a, const LE32 &b) { return ALIGN_UP(a, unsigned(b)); }
|
inline unsigned ALIGN_UP(unsigned a, const LE32 &b) { return ALIGN_UP(a, unsigned(b)); }
|
||||||
inline unsigned ALIGN_UP(const LE32 &a, unsigned b) { return ALIGN_UP(unsigned(a), b); }
|
inline unsigned ALIGN_UP(const LE32 &a, unsigned b) { return ALIGN_UP(unsigned(a), b); }
|
||||||
|
|
||||||
|
// TODO: introduce upx::umax() and upx::umin()
|
||||||
inline unsigned UPX_MAX(unsigned a, const BE16 &b) { return UPX_MAX(a, unsigned(b)); }
|
inline unsigned UPX_MAX(unsigned a, const BE16 &b) { return UPX_MAX(a, unsigned(b)); }
|
||||||
inline unsigned UPX_MAX(const BE16 &a, unsigned b) { return UPX_MAX(unsigned(a), b); }
|
inline unsigned UPX_MAX(const BE16 &a, unsigned b) { return UPX_MAX(unsigned(a), b); }
|
||||||
inline unsigned UPX_MIN(unsigned a, const BE16 &b) { return UPX_MIN(a, unsigned(b)); }
|
inline unsigned UPX_MIN(unsigned a, const BE16 &b) { return UPX_MIN(a, unsigned(b)); }
|
||||||
@@ -645,6 +753,47 @@ inline unsigned UPX_MIN(const LE32 &a, unsigned b) { return UPX_MIN(unsigned(a),
|
|||||||
// misc support
|
// misc support
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// <type_traits> upx_is_integral; see conf.h
|
||||||
|
#define TT_UPX_IS_INTEGRAL(T) \
|
||||||
|
template <> \
|
||||||
|
struct upx_is_integral<T> : public std::true_type {}; \
|
||||||
|
template <> \
|
||||||
|
struct upx_is_integral<const T> : public std::true_type {}; \
|
||||||
|
template <> \
|
||||||
|
struct upx_is_integral<volatile T> : public std::true_type {}; \
|
||||||
|
template <> \
|
||||||
|
struct upx_is_integral<const volatile T> : public std::true_type {}
|
||||||
|
TT_UPX_IS_INTEGRAL(BE16);
|
||||||
|
TT_UPX_IS_INTEGRAL(BE32);
|
||||||
|
TT_UPX_IS_INTEGRAL(BE64);
|
||||||
|
TT_UPX_IS_INTEGRAL(LE16);
|
||||||
|
TT_UPX_IS_INTEGRAL(LE32);
|
||||||
|
TT_UPX_IS_INTEGRAL(LE64);
|
||||||
|
#undef TT_UPX_IS_INTEGRAL
|
||||||
|
|
||||||
|
// native types
|
||||||
|
#if (ACC_ABI_BIG_ENDIAN)
|
||||||
|
typedef BE16 NE16;
|
||||||
|
typedef BE32 NE32;
|
||||||
|
typedef BE64 NE64;
|
||||||
|
#define ne16_compare be16_compare
|
||||||
|
#define ne32_compare be32_compare
|
||||||
|
#define ne64_compare be64_compare
|
||||||
|
#define ne16_compare_signed be16_compare_signed
|
||||||
|
#define ne32_compare_signed be32_compare_signed
|
||||||
|
#define ne64_compare_signed be64_compare_signed
|
||||||
|
#else
|
||||||
|
typedef LE16 NE16;
|
||||||
|
typedef LE32 NE32;
|
||||||
|
typedef LE64 NE64;
|
||||||
|
#define ne16_compare le16_compare
|
||||||
|
#define ne32_compare le32_compare
|
||||||
|
#define ne64_compare le64_compare
|
||||||
|
#define ne16_compare_signed le16_compare_signed
|
||||||
|
#define ne32_compare_signed le32_compare_signed
|
||||||
|
#define ne64_compare_signed le64_compare_signed
|
||||||
|
#endif
|
||||||
|
|
||||||
// for use with qsort()
|
// for use with qsort()
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int __acc_cdecl_qsort be16_compare(const void *, const void *);
|
int __acc_cdecl_qsort be16_compare(const void *, const void *);
|
||||||
@@ -701,14 +850,12 @@ namespace N_BELE_RTP {
|
|||||||
|
|
||||||
// util
|
// util
|
||||||
namespace N_BELE_CTP {
|
namespace N_BELE_CTP {
|
||||||
inline const N_BELE_RTP::AbstractPolicy *getRTP(const BEPolicy * /*dummy*/) {
|
inline const N_BELE_RTP::AbstractPolicy *getRTP(const BEPolicy * /*dummy*/) noexcept {
|
||||||
return &N_BELE_RTP::be_policy;
|
return &N_BELE_RTP::be_policy;
|
||||||
}
|
}
|
||||||
inline const N_BELE_RTP::AbstractPolicy *getRTP(const LEPolicy * /*dummy*/) {
|
inline const N_BELE_RTP::AbstractPolicy *getRTP(const LEPolicy * /*dummy*/) noexcept {
|
||||||
return &N_BELE_RTP::le_policy;
|
return &N_BELE_RTP::le_policy;
|
||||||
}
|
}
|
||||||
} // namespace N_BELE_CTP
|
} // namespace N_BELE_CTP
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+22
-46
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,9 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef UPX_BELE_H__
|
// this is an internal include file private to bele.h
|
||||||
#error "this is an internal include file"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
@@ -37,20 +35,20 @@
|
|||||||
// CTP - Compile-Time Polymorphism (templates)
|
// CTP - Compile-Time Polymorphism (templates)
|
||||||
#define V static inline
|
#define V static inline
|
||||||
#define S static int __acc_cdecl_qsort
|
#define S static int __acc_cdecl_qsort
|
||||||
#define C /*empty*/
|
#define C noexcept
|
||||||
#elif defined(BELE_RTP)
|
#elif defined(BELE_RTP)
|
||||||
// RTP - Run-Time Polymorphism (virtual functions)
|
// RTP - Run-Time Polymorphism (virtual functions)
|
||||||
#define V virtual
|
#define V virtual
|
||||||
#define S virtual int
|
#define S virtual int
|
||||||
#define C const
|
#define C const noexcept
|
||||||
#else
|
#else
|
||||||
#error
|
#error
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BELE_RTP)
|
#if defined(BELE_RTP)
|
||||||
struct AbstractPolicy {
|
struct AbstractPolicy {
|
||||||
inline AbstractPolicy() {}
|
explicit inline AbstractPolicy() noexcept {}
|
||||||
virtual inline ~AbstractPolicy() {}
|
virtual inline ~AbstractPolicy() noexcept {}
|
||||||
V bool isBE() C = 0;
|
V bool isBE() C = 0;
|
||||||
V bool isLE() C = 0;
|
V bool isLE() C = 0;
|
||||||
|
|
||||||
@@ -80,18 +78,16 @@ struct AbstractPolicy {
|
|||||||
S u64_compare_signed(const void *a, const void *b) C = 0;
|
S u64_compare_signed(const void *a, const void *b) C = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disable copy, assignment and move assignment
|
// disable copy and move
|
||||||
AbstractPolicy(const AbstractPolicy &) = delete;
|
UPX_CXX_DISABLE_COPY_MOVE(AbstractPolicy)
|
||||||
AbstractPolicy &operator=(const AbstractPolicy &) = delete;
|
|
||||||
AbstractPolicy &operator=(AbstractPolicy &&) = delete;
|
|
||||||
// disable dynamic allocation
|
// disable dynamic allocation
|
||||||
ACC_CXX_DISABLE_NEW_DELETE
|
UPX_CXX_DISABLE_NEW_DELETE(AbstractPolicy)
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BELE_RTP)
|
#if defined(BELE_RTP)
|
||||||
#undef C
|
#undef C
|
||||||
#define C const override
|
#define C const noexcept override
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct BEPolicy
|
struct BEPolicy
|
||||||
@@ -99,7 +95,7 @@ struct BEPolicy
|
|||||||
final : public AbstractPolicy
|
final : public AbstractPolicy
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
inline BEPolicy() {}
|
explicit inline BEPolicy() noexcept {}
|
||||||
#if defined(BELE_CTP)
|
#if defined(BELE_CTP)
|
||||||
typedef N_BELE_RTP::BEPolicy RTP_Policy;
|
typedef N_BELE_RTP::BEPolicy RTP_Policy;
|
||||||
#elif defined(BELE_RTP)
|
#elif defined(BELE_RTP)
|
||||||
@@ -147,12 +143,10 @@ struct BEPolicy
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disable copy, assignment and move assignment
|
// disable copy and move
|
||||||
BEPolicy(const BEPolicy &) = delete;
|
UPX_CXX_DISABLE_COPY_MOVE(BEPolicy)
|
||||||
BEPolicy &operator=(const BEPolicy &) = delete;
|
|
||||||
BEPolicy &operator=(BEPolicy &&) = delete;
|
|
||||||
// disable dynamic allocation
|
// disable dynamic allocation
|
||||||
ACC_CXX_DISABLE_NEW_DELETE
|
UPX_CXX_DISABLE_NEW_DELETE(BEPolicy)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LEPolicy
|
struct LEPolicy
|
||||||
@@ -160,7 +154,7 @@ struct LEPolicy
|
|||||||
final : public AbstractPolicy
|
final : public AbstractPolicy
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
inline LEPolicy() {}
|
explicit inline LEPolicy() noexcept {}
|
||||||
#if defined(BELE_CTP)
|
#if defined(BELE_CTP)
|
||||||
typedef N_BELE_RTP::LEPolicy RTP_Policy;
|
typedef N_BELE_RTP::LEPolicy RTP_Policy;
|
||||||
#elif defined(BELE_RTP)
|
#elif defined(BELE_RTP)
|
||||||
@@ -208,41 +202,23 @@ struct LEPolicy
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disable copy, assignment and move assignment
|
// disable copy and move
|
||||||
LEPolicy(const LEPolicy &) = delete;
|
UPX_CXX_DISABLE_COPY_MOVE(LEPolicy)
|
||||||
LEPolicy &operator=(const LEPolicy &) = delete;
|
|
||||||
LEPolicy &operator=(LEPolicy &&) = delete;
|
|
||||||
// disable dynamic allocation
|
// disable dynamic allocation
|
||||||
ACC_CXX_DISABLE_NEW_DELETE
|
UPX_CXX_DISABLE_NEW_DELETE(LEPolicy)
|
||||||
};
|
};
|
||||||
|
|
||||||
// native policy (aka host policy)
|
// Native Endianness policy (aka host policy)
|
||||||
#if (ACC_ABI_BIG_ENDIAN)
|
#if (ACC_ABI_BIG_ENDIAN)
|
||||||
|
typedef BEPolicy NEPolicy;
|
||||||
typedef BEPolicy HostPolicy;
|
typedef BEPolicy HostPolicy;
|
||||||
#elif (ACC_ABI_LITTLE_ENDIAN)
|
#elif (ACC_ABI_LITTLE_ENDIAN)
|
||||||
|
typedef LEPolicy NEPolicy;
|
||||||
typedef LEPolicy HostPolicy;
|
typedef LEPolicy HostPolicy;
|
||||||
#else
|
#else
|
||||||
#error "ACC_ABI_ENDIAN"
|
#error "ACC_ABI_ENDIAN"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 /* UNUSED */
|
|
||||||
struct HostAlignedPolicy {
|
|
||||||
#if defined(BELE_CTP)
|
|
||||||
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef upx_uint16_t U16;
|
|
||||||
typedef upx_uint32_t U32;
|
|
||||||
typedef upx_uint64_t U64;
|
|
||||||
|
|
||||||
static void compileTimeAssertions() {
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef V
|
#undef V
|
||||||
#undef S
|
#undef S
|
||||||
#undef C
|
#undef C
|
||||||
|
|||||||
@@ -0,0 +1,685 @@
|
|||||||
|
/* dt_check.cpp -- doctest check
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// upx_doctest_check()
|
||||||
|
//
|
||||||
|
// honors environment variables:
|
||||||
|
// UPX_DEBUG_DOCTEST_DISABLE
|
||||||
|
// UPX_DEBUG_DOCTEST_VERBOSE
|
||||||
|
//
|
||||||
|
// HINT: set "UPX_DEBUG_DOCTEST_DISABLE=1" for improved debugging experience
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_doctest_check(int argc, char **argv) {
|
||||||
|
#if defined(DOCTEST_CONFIG_DISABLE)
|
||||||
|
UNUSED(argc);
|
||||||
|
UNUSED(argv);
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
const char *e = getenv("UPX_DEBUG_DOCTEST_DISABLE");
|
||||||
|
if (!e)
|
||||||
|
e = getenv("UPX_DEBUG_DISABLE_DOCTEST"); // allow alternate spelling
|
||||||
|
if (e && e[0] && strcmp(e, "0") != 0)
|
||||||
|
return 0;
|
||||||
|
bool minimal = true; // don't show summary
|
||||||
|
bool duration = false; // don't show timings
|
||||||
|
bool success = false; // don't show all succeeding tests
|
||||||
|
#if DEBUG
|
||||||
|
// default for debug builds: do show the [doctest] summary
|
||||||
|
minimal = false;
|
||||||
|
#endif
|
||||||
|
e = getenv("UPX_DEBUG_DOCTEST_VERBOSE");
|
||||||
|
if (e && e[0]) {
|
||||||
|
if (strcmp(e, "0") == 0) {
|
||||||
|
minimal = true;
|
||||||
|
} else if (strcmp(e, "1") == 0) {
|
||||||
|
minimal = false;
|
||||||
|
} else if (strcmp(e, "2") == 0) {
|
||||||
|
minimal = false;
|
||||||
|
duration = true;
|
||||||
|
} else if (strcmp(e, "3") == 0) {
|
||||||
|
minimal = false;
|
||||||
|
duration = true;
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
doctest::Context context;
|
||||||
|
if (minimal)
|
||||||
|
context.setOption("dt-minimal", true);
|
||||||
|
if (duration)
|
||||||
|
context.setOption("dt-duration", true);
|
||||||
|
if (success)
|
||||||
|
context.setOption("dt-success", true);
|
||||||
|
// this requires that main_get_options() understands "--dt-XXX" options
|
||||||
|
if (argc > 0 && argv != nullptr)
|
||||||
|
context.applyCommandLine(argc, argv);
|
||||||
|
int r = context.run();
|
||||||
|
if (r != 0)
|
||||||
|
return 1;
|
||||||
|
if (context.shouldExit())
|
||||||
|
return 2;
|
||||||
|
return 0;
|
||||||
|
#endif // DOCTEST_CONFIG_DISABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
int upx_doctest_check() { return upx_doctest_check(0, nullptr); }
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// compile-time checks
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
// need extra parenthesis because the C preprocessor does not understand C++ templates
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<short, upx_int16_t>::value))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<unsigned short, upx_uint16_t>::value))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<int, upx_int32_t>::value))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<unsigned, upx_uint32_t>::value))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<long long, upx_int64_t>::value))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<unsigned long long, upx_uint64_t>::value))
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(no_bswap16(0x04030201) == 0x0201)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(no_bswap32(0x04030201) == 0x04030201)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(no_bswap64(0x0807060504030201ull) == 0x0807060504030201ull)
|
||||||
|
#if !(ACC_CC_MSC) // unfortunately *not* constexpr with current MSVC
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(bswap16(0x04030201) == 0x0102)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(bswap32(0x04030201) == 0x01020304)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(bswap64(0x0807060504030201ull) == 0x0102030405060708ull)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(bswap16(bswap16(0xf4f3f2f1)) == no_bswap16(0xf4f3f2f1))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(bswap32(bswap32(0xf4f3f2f1)) == no_bswap32(0xf4f3f2f1))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(bswap64(bswap64(0xf8f7f6f5f4f3f2f1ull)) ==
|
||||||
|
no_bswap64(0xf8f7f6f5f4f3f2f1ull))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 0, 8) == 0)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 1, 8) == 1)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 127, 8) == 127)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 128, 8) == -128)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u - 1, 8) == -1)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 256, 8) == 0)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 257, 8) == 1)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 383, 8) == 127)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 384, 8) == -128)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0u + 511, 8) == -1)
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_BIT == 8)
|
||||||
|
#if 0 // does not work with MSVC
|
||||||
|
#if '\0' - 1 < 0
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 127)
|
||||||
|
#else
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255)
|
||||||
|
#endif
|
||||||
|
#if L'\0' - 1 < 0
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((wchar_t) -1 < 0)
|
||||||
|
#else
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((wchar_t) -1 > 0)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// upx_compiler_sanity_check()
|
||||||
|
// assert a sane architecture and compiler
|
||||||
|
// (modern compilers will optimize away most of this code)
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct CheckIntegral {
|
||||||
|
struct TestT {
|
||||||
|
T a;
|
||||||
|
T x[2];
|
||||||
|
};
|
||||||
|
template <class U>
|
||||||
|
struct TestU {
|
||||||
|
U a = {};
|
||||||
|
const U b = {};
|
||||||
|
static constexpr U c = {};
|
||||||
|
U x[2] = {};
|
||||||
|
const U y[2] = {};
|
||||||
|
static constexpr U z[2] = {};
|
||||||
|
};
|
||||||
|
template <class U>
|
||||||
|
static void checkU(void) noexcept {
|
||||||
|
{
|
||||||
|
U a = {};
|
||||||
|
const U b = {};
|
||||||
|
constexpr U c = {};
|
||||||
|
U x[2] = {};
|
||||||
|
const U y[2] = {};
|
||||||
|
constexpr U z[2] = {};
|
||||||
|
assert_noexcept(a == 0);
|
||||||
|
assert_noexcept(b == 0);
|
||||||
|
assert_noexcept(c == 0);
|
||||||
|
assert_noexcept(x[0] == 0 && x[1] == 0);
|
||||||
|
assert_noexcept(y[0] == 0 && y[1] == 0);
|
||||||
|
assert_noexcept(z[0] == 0 && z[1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
TestU<U> t;
|
||||||
|
assert_noexcept(t.a == 0);
|
||||||
|
assert_noexcept(t.b == 0);
|
||||||
|
assert_noexcept(t.c == 0);
|
||||||
|
assert_noexcept(t.x[0] == 0 && t.x[1] == 0);
|
||||||
|
assert_noexcept(t.y[0] == 0 && t.y[1] == 0);
|
||||||
|
assert_noexcept(t.z[0] == 0 && t.z[1] == 0);
|
||||||
|
}
|
||||||
|
#if __cplusplus <= 201703L
|
||||||
|
COMPILE_TIME_ASSERT(std::is_pod<U>::value) // std::is_pod is deprecated in C++20
|
||||||
|
#endif
|
||||||
|
COMPILE_TIME_ASSERT(std::is_standard_layout<U>::value)
|
||||||
|
COMPILE_TIME_ASSERT(std::is_trivial<U>::value)
|
||||||
|
// more checks, these are probably implied by std::is_trivial
|
||||||
|
COMPILE_TIME_ASSERT(std::is_nothrow_default_constructible<U>::value)
|
||||||
|
COMPILE_TIME_ASSERT(std::is_nothrow_destructible<U>::value)
|
||||||
|
COMPILE_TIME_ASSERT(std::is_trivially_copyable<U>::value)
|
||||||
|
COMPILE_TIME_ASSERT(std::is_trivially_default_constructible<U>::value)
|
||||||
|
// UPX extras
|
||||||
|
COMPILE_TIME_ASSERT(upx_is_integral<U>::value)
|
||||||
|
COMPILE_TIME_ASSERT(upx_is_integral_v<U>)
|
||||||
|
}
|
||||||
|
static void check(void) noexcept {
|
||||||
|
{
|
||||||
|
TestT t = {};
|
||||||
|
assert_noexcept(t.a == 0);
|
||||||
|
assert_noexcept(t.x[0] == 0 && t.x[1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const TestT t = {};
|
||||||
|
assert_noexcept(t.a == 0);
|
||||||
|
assert_noexcept(t.x[0] == 0 && t.x[1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
constexpr TestT t = {};
|
||||||
|
assert_noexcept(t.a == 0);
|
||||||
|
assert_noexcept(t.x[0] == 0 && t.x[1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
TestT t;
|
||||||
|
mem_clear(&t);
|
||||||
|
assert_noexcept(t.a == 0);
|
||||||
|
assert_noexcept(t.x[0] == 0 && t.x[1] == 0);
|
||||||
|
}
|
||||||
|
checkU<T>();
|
||||||
|
checkU<typename std::add_const<T>::type>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <class T>
|
||||||
|
struct CheckAlignment {
|
||||||
|
static void check(void) noexcept {
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(T)
|
||||||
|
struct alignas(1) Test1 {
|
||||||
|
char a;
|
||||||
|
T b;
|
||||||
|
};
|
||||||
|
struct alignas(1) Test2 {
|
||||||
|
char a;
|
||||||
|
T b[3];
|
||||||
|
};
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(Test1)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(Test2)
|
||||||
|
Test1 t1[7];
|
||||||
|
Test2 t2[7];
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(Test1) == 1 + sizeof(T))
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(t1) == 7 + 7 * sizeof(T))
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(Test2) == 1 + 3 * sizeof(T))
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21 * sizeof(T))
|
||||||
|
UNUSED(t1);
|
||||||
|
UNUSED(t2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <class T>
|
||||||
|
struct TestBELE {
|
||||||
|
static noinline bool test(void) noexcept {
|
||||||
|
CheckIntegral<T>::check();
|
||||||
|
CheckAlignment<T>::check();
|
||||||
|
// arithmetic checks
|
||||||
|
T allbits = {};
|
||||||
|
assert_noexcept(allbits == 0);
|
||||||
|
allbits += 1;
|
||||||
|
allbits -= 2;
|
||||||
|
T v1;
|
||||||
|
v1 = 1;
|
||||||
|
v1 *= 4;
|
||||||
|
v1 /= 2;
|
||||||
|
v1 -= 1;
|
||||||
|
T v2;
|
||||||
|
v2 = 1;
|
||||||
|
assert_noexcept((v1 == v2));
|
||||||
|
assert_noexcept(!(v1 != v2));
|
||||||
|
assert_noexcept((v1 <= v2));
|
||||||
|
assert_noexcept((v1 >= v2));
|
||||||
|
assert_noexcept(!(v1 < v2));
|
||||||
|
assert_noexcept(!(v1 > v2));
|
||||||
|
v2 ^= allbits;
|
||||||
|
assert_noexcept(!(v1 == v2));
|
||||||
|
assert_noexcept((v1 != v2));
|
||||||
|
assert_noexcept((v1 <= v2));
|
||||||
|
assert_noexcept(!(v1 >= v2));
|
||||||
|
assert_noexcept((v1 < v2));
|
||||||
|
assert_noexcept(!(v1 > v2));
|
||||||
|
v2 += 2;
|
||||||
|
assert_noexcept(v1 == 1);
|
||||||
|
assert_noexcept(v2 == 0);
|
||||||
|
v1 <<= 1;
|
||||||
|
v1 |= v2;
|
||||||
|
v1 >>= 1;
|
||||||
|
v2 &= v1;
|
||||||
|
v2 /= v1;
|
||||||
|
v2 *= v1;
|
||||||
|
v1 += v2;
|
||||||
|
v1 -= v2;
|
||||||
|
assert_noexcept(v1 == 1);
|
||||||
|
assert_noexcept(v2 == 0);
|
||||||
|
if ((v1 ^ v2) != 1)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class A, class B>
|
||||||
|
struct TestNoAliasingStruct {
|
||||||
|
static noinline bool test(A *a, B *b) noexcept {
|
||||||
|
*a = 0;
|
||||||
|
*b = 0;
|
||||||
|
*b -= 3;
|
||||||
|
return *a != 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <class A, class B>
|
||||||
|
static forceinline bool testNoAliasing(A *a, B *b) noexcept {
|
||||||
|
return TestNoAliasingStruct<A, B>::test(a, b);
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
struct TestIntegerWrap {
|
||||||
|
static inline bool inc_gt(const T x) noexcept { return x + 1 > x; }
|
||||||
|
static inline bool dec_lt(const T x) noexcept { return x - 1 < x; }
|
||||||
|
static inline bool neg_eq(const T x) noexcept { return T(0) - x == x; }
|
||||||
|
};
|
||||||
|
|
||||||
|
static noinline void throwSomeValue(int x) may_throw {
|
||||||
|
if (x < 0)
|
||||||
|
throw int(x);
|
||||||
|
else
|
||||||
|
throw size_t(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static noinline void check_basic_cxx_exception_handling(void (*func)(int)) noexcept {
|
||||||
|
bool cxx_exception_handling_works = false;
|
||||||
|
try {
|
||||||
|
func(42);
|
||||||
|
} catch (const size_t &e) {
|
||||||
|
if (e == 42)
|
||||||
|
cxx_exception_handling_works = true;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
assert_noexcept(cxx_exception_handling_works);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#define ACC_WANT_ACC_CHK_CH 1
|
||||||
|
#undef ACCCHK_ASSERT
|
||||||
|
#include "../miniacc.h"
|
||||||
|
|
||||||
|
void upx_compiler_sanity_check(void) noexcept {
|
||||||
|
const char *e = getenv("UPX_DEBUG_DOCTEST_DISABLE");
|
||||||
|
if (!e)
|
||||||
|
e = getenv("UPX_DEBUG_DISABLE_DOCTEST"); // allow alternate spelling
|
||||||
|
if (e && e[0] && strcmp(e, "0") != 0) {
|
||||||
|
// If UPX_DEBUG_DOCTEST_DISABLE is set then we don't want to throw any
|
||||||
|
// exceptions in order to improve debugging experience.
|
||||||
|
} else {
|
||||||
|
// check working C++ exception handling to catch toolchain/qemu/wine/etc problems
|
||||||
|
check_basic_cxx_exception_handling(throwSomeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ACC_WANT_ACC_CHK_CH 1
|
||||||
|
#undef ACCCHK_ASSERT
|
||||||
|
#define ACCCHK_ASSERT(expr) ACC_COMPILE_TIME_ASSERT(expr)
|
||||||
|
#include "../miniacc.h"
|
||||||
|
#undef ACCCHK_ASSERT
|
||||||
|
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(char) == 1)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(short) == 2)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(int) == 4)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(long) >= 4)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(void *) >= 4)
|
||||||
|
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(BE64) == 8)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(LE64) == 8)
|
||||||
|
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(BE16)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(BE32)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(BE64)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(LE16)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(LE32)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(LE64)
|
||||||
|
|
||||||
|
CheckIntegral<char>::check();
|
||||||
|
CheckIntegral<signed char>::check();
|
||||||
|
CheckIntegral<unsigned char>::check();
|
||||||
|
CheckIntegral<short>::check();
|
||||||
|
CheckIntegral<int>::check();
|
||||||
|
CheckIntegral<long>::check();
|
||||||
|
CheckIntegral<long long>::check();
|
||||||
|
CheckIntegral<ptrdiff_t>::check();
|
||||||
|
CheckIntegral<size_t>::check();
|
||||||
|
CheckIntegral<upx_off_t>::check();
|
||||||
|
CheckIntegral<upx_uintptr_t>::check();
|
||||||
|
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(upx_charptr_unit_type) == 1)
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(upx_charptr_unit_type)
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(*((charptr) nullptr)) == 1)
|
||||||
|
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
|
||||||
|
assert_noexcept(strlen(UPX_VERSION_STRING4) == 4);
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_YEAR) == 4 + 1)
|
||||||
|
assert_noexcept(strlen(UPX_VERSION_YEAR) == 4);
|
||||||
|
assert_noexcept(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0);
|
||||||
|
assert_noexcept(
|
||||||
|
memcmp(&UPX_VERSION_DATE[sizeof(UPX_VERSION_DATE) - 1 - 4], UPX_VERSION_YEAR, 4) == 0);
|
||||||
|
if (gitrev[0]) {
|
||||||
|
size_t revlen = strlen(gitrev);
|
||||||
|
if (strncmp(gitrev, "ERROR", 5) == 0) {
|
||||||
|
assert_noexcept(revlen == 5 || revlen == 6);
|
||||||
|
} else {
|
||||||
|
assert_noexcept(revlen == 12 || revlen == 13);
|
||||||
|
}
|
||||||
|
if (revlen == 6 || revlen == 13) {
|
||||||
|
assert_noexcept(gitrev[revlen - 1] == '+');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_noexcept(UPX_RSIZE_MAX_MEM == 805306368);
|
||||||
|
|
||||||
|
#if DEBUG || 1
|
||||||
|
assert_noexcept(TestBELE<LE16>::test());
|
||||||
|
assert_noexcept(TestBELE<LE32>::test());
|
||||||
|
assert_noexcept(TestBELE<LE64>::test());
|
||||||
|
assert_noexcept(TestBELE<BE16>::test());
|
||||||
|
assert_noexcept(TestBELE<BE32>::test());
|
||||||
|
assert_noexcept(TestBELE<BE64>::test());
|
||||||
|
{
|
||||||
|
alignas(16) static const byte dd[32] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0,
|
||||||
|
0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 0, 0, 0, 0, 0};
|
||||||
|
const byte *d;
|
||||||
|
const N_BELE_RTP::AbstractPolicy *bele;
|
||||||
|
d = dd + 7;
|
||||||
|
assert_noexcept(upx_adler32(d, 4) == 0x09f003f7);
|
||||||
|
assert_noexcept(upx_adler32(d, 4, 0) == 0x09ec03f6);
|
||||||
|
assert_noexcept(upx_adler32(d, 4, 1) == 0x09f003f7);
|
||||||
|
bele = &N_BELE_RTP::be_policy;
|
||||||
|
assert_noexcept(get_be16(d) == 0xfffe);
|
||||||
|
assert_noexcept(bele->get16(d) == 0xfffe);
|
||||||
|
assert_noexcept(get_be16_signed(d) == -2);
|
||||||
|
assert_noexcept(get_be24(d) == 0xfffefd);
|
||||||
|
assert_noexcept(bele->get24(d) == 0xfffefd);
|
||||||
|
assert_noexcept(get_be24_signed(d) == -259);
|
||||||
|
assert_noexcept(get_be32(d) == 0xfffefdfc);
|
||||||
|
assert_noexcept(bele->get32(d) == 0xfffefdfc);
|
||||||
|
assert_noexcept(get_be32_signed(d) == -66052);
|
||||||
|
bele = &N_BELE_RTP::le_policy;
|
||||||
|
assert_noexcept(get_le16(d) == 0xfeff);
|
||||||
|
assert_noexcept(bele->get16(d) == 0xfeff);
|
||||||
|
assert_noexcept(get_le16_signed(d) == -257);
|
||||||
|
assert_noexcept(get_le24(d) == 0xfdfeff);
|
||||||
|
assert_noexcept(bele->get24(d) == 0xfdfeff);
|
||||||
|
assert_noexcept(get_le24_signed(d) == -131329);
|
||||||
|
assert_noexcept(get_le32(d) == 0xfcfdfeff);
|
||||||
|
assert_noexcept(bele->get32(d) == 0xfcfdfeff);
|
||||||
|
assert_noexcept(get_le32_signed(d) == -50462977);
|
||||||
|
assert_noexcept(get_le64_signed(d) == -506097522914230529LL);
|
||||||
|
assert_noexcept(find_be16(d, 2, 0xfffe) == 0);
|
||||||
|
assert_noexcept(find_le16(d, 2, 0xfeff) == 0);
|
||||||
|
assert_noexcept(find_be32(d, 4, 0xfffefdfc) == 0);
|
||||||
|
assert_noexcept(find_le32(d, 4, 0xfcfdfeff) == 0);
|
||||||
|
d += 12;
|
||||||
|
assert_noexcept(get_be16_signed(d) == 32638);
|
||||||
|
assert_noexcept(get_be24_signed(d) == 8355453);
|
||||||
|
assert_noexcept(get_be32_signed(d) == 2138996092);
|
||||||
|
assert_noexcept(get_be64_signed(d) == 9186918263483431288LL);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
unsigned dd;
|
||||||
|
void *const d = ⅆ
|
||||||
|
dd = ne32_to_le32(0xf7f6f5f4);
|
||||||
|
assert_noexcept(get_le26(d) == 0x03f6f5f4);
|
||||||
|
set_le26(d, 0);
|
||||||
|
assert_noexcept(get_le26(d) == 0);
|
||||||
|
assert_noexcept(dd == ne32_to_le32(0xf4000000));
|
||||||
|
set_le26(d, 0xff020304);
|
||||||
|
assert_noexcept(get_le26(d) == 0x03020304);
|
||||||
|
assert_noexcept(dd == ne32_to_le32(0xf7020304));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
upx_uint16_t a = 0;
|
||||||
|
upx_uint32_t b = 0;
|
||||||
|
upx_uint64_t c = 0;
|
||||||
|
set_ne16(&a, 0x04030201); // ignore upper bits
|
||||||
|
set_ne32(&b, 0x04030201);
|
||||||
|
set_ne64(&c, 0x0807060504030201ull);
|
||||||
|
assert_noexcept(a == 0x0201);
|
||||||
|
assert_noexcept(b == 0x04030201);
|
||||||
|
assert_noexcept(c == 0x0807060504030201ull);
|
||||||
|
assert_noexcept(get_ne16(&a) == 0x0201);
|
||||||
|
assert_noexcept(get_ne32(&b) == 0x04030201);
|
||||||
|
assert_noexcept(get_ne64(&c) == 0x0807060504030201ull);
|
||||||
|
}
|
||||||
|
#endif // DEBUG
|
||||||
|
union {
|
||||||
|
short v_short;
|
||||||
|
int v_int;
|
||||||
|
long v_long;
|
||||||
|
long long v_llong;
|
||||||
|
BE16 b16;
|
||||||
|
BE32 b32;
|
||||||
|
BE64 b64;
|
||||||
|
LE16 l16;
|
||||||
|
LE32 l32;
|
||||||
|
LE64 l64;
|
||||||
|
} u;
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_short, &u.b32));
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_short, &u.l32));
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_int, &u.b64));
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_int, &u.l64));
|
||||||
|
// check working -fno-strict-aliasing
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_short, &u.v_int));
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_int, &u.v_long));
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_int, &u.v_llong));
|
||||||
|
assert_noexcept(testNoAliasing(&u.v_long, &u.v_llong));
|
||||||
|
|
||||||
|
assert_noexcept(TestIntegerWrap<unsigned>::inc_gt(0));
|
||||||
|
assert_noexcept(!TestIntegerWrap<unsigned>::inc_gt(UINT_MAX));
|
||||||
|
assert_noexcept(TestIntegerWrap<unsigned>::dec_lt(1));
|
||||||
|
assert_noexcept(!TestIntegerWrap<unsigned>::dec_lt(0));
|
||||||
|
assert_noexcept(TestIntegerWrap<unsigned>::neg_eq(0));
|
||||||
|
assert_noexcept(!TestIntegerWrap<unsigned>::neg_eq(1));
|
||||||
|
assert_noexcept(!TestIntegerWrap<unsigned>::neg_eq(UINT_MAX));
|
||||||
|
// check working -fno-strict-overflow
|
||||||
|
assert_noexcept(TestIntegerWrap<int>::inc_gt(0));
|
||||||
|
assert_noexcept(!TestIntegerWrap<int>::inc_gt(INT_MAX));
|
||||||
|
assert_noexcept(TestIntegerWrap<int>::dec_lt(0));
|
||||||
|
assert_noexcept(!TestIntegerWrap<int>::dec_lt(INT_MIN));
|
||||||
|
assert_noexcept(TestIntegerWrap<int>::neg_eq(0));
|
||||||
|
assert_noexcept(!TestIntegerWrap<int>::neg_eq(1));
|
||||||
|
assert_noexcept(!TestIntegerWrap<int>::neg_eq(INT_MAX));
|
||||||
|
assert_noexcept(TestIntegerWrap<int>::neg_eq(INT_MIN)); // special case
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// some doctest test cases
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("assert_noexcept") {
|
||||||
|
// just to make sure that our own assert() macros don't generate any warnings
|
||||||
|
byte dummy = 0;
|
||||||
|
byte *ptr1 = &dummy;
|
||||||
|
const byte *const ptr2 = &dummy;
|
||||||
|
void *ptr3 = nullptr;
|
||||||
|
assert(true);
|
||||||
|
assert(1);
|
||||||
|
assert(ptr1);
|
||||||
|
assert(ptr2);
|
||||||
|
assert(!ptr3);
|
||||||
|
assert_noexcept(true);
|
||||||
|
assert_noexcept(1);
|
||||||
|
assert_noexcept(ptr1);
|
||||||
|
assert_noexcept(ptr2);
|
||||||
|
assert_noexcept(!ptr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("acc_vget") {
|
||||||
|
CHECK_EQ(acc_vget_int(0, 0), 0);
|
||||||
|
CHECK_EQ(acc_vget_long(1, -1), 1);
|
||||||
|
CHECK_EQ(acc_vget_acc_int64l_t(2, 1), 2);
|
||||||
|
CHECK_EQ(acc_vget_acc_hvoid_p(nullptr, 0), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("ptr_invalidate_and_poison") {
|
||||||
|
int *ip = nullptr;
|
||||||
|
ptr_invalidate_and_poison(ip);
|
||||||
|
assert(ip != nullptr);
|
||||||
|
(void) ip;
|
||||||
|
double *dp;
|
||||||
|
ptr_invalidate_and_poison(dp);
|
||||||
|
assert(dp != nullptr);
|
||||||
|
(void) dp;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("working -fno-strict-aliasing") {
|
||||||
|
bool ok;
|
||||||
|
long v = 0;
|
||||||
|
short *ps = ACC_STATIC_CAST(short *, acc_vget_acc_hvoid_p(&v, 0));
|
||||||
|
int *pi = ACC_STATIC_CAST(int *, acc_vget_acc_hvoid_p(&v, 0));
|
||||||
|
long *pl = ACC_STATIC_CAST(long *, acc_vget_acc_hvoid_p(&v, 0));
|
||||||
|
*ps = 0;
|
||||||
|
*pl = -1;
|
||||||
|
ok = *ps == -1;
|
||||||
|
CHECK(ok);
|
||||||
|
*pi = 0;
|
||||||
|
*pl = -1;
|
||||||
|
ok = *pi == -1;
|
||||||
|
CHECK(ok);
|
||||||
|
*pl = 0;
|
||||||
|
*ps = -1;
|
||||||
|
ok = *pl != 0;
|
||||||
|
CHECK(ok);
|
||||||
|
*pl = 0;
|
||||||
|
*pi = -1;
|
||||||
|
ok = *pl != 0;
|
||||||
|
CHECK(ok);
|
||||||
|
UNUSED(ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("working -fno-strict-overflow") {
|
||||||
|
CHECK_EQ(acc_vget_int(INT_MAX, 0) + 1, INT_MIN);
|
||||||
|
CHECK_EQ(acc_vget_int(INT_MIN, 0) - 1, INT_MAX);
|
||||||
|
CHECK_EQ(acc_vget_long(LONG_MAX, 0) + 1, LONG_MIN);
|
||||||
|
CHECK_EQ(acc_vget_long(LONG_MIN, 0) - 1, LONG_MAX);
|
||||||
|
bool ok;
|
||||||
|
int i;
|
||||||
|
i = INT_MAX;
|
||||||
|
i += 1;
|
||||||
|
ok = i == INT_MIN;
|
||||||
|
CHECK(ok);
|
||||||
|
i = INT_MIN;
|
||||||
|
i -= 1;
|
||||||
|
ok = i == INT_MAX;
|
||||||
|
CHECK(ok);
|
||||||
|
UNUSED(ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("libc snprintf") {
|
||||||
|
// runtime check that Windows/MinGW <stdio.h> works as expected
|
||||||
|
char buf[64];
|
||||||
|
long long ll = acc_vget_int(-1, 0);
|
||||||
|
unsigned long long llu = (unsigned long long) ll;
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%ld.%lld.%u.%lu.%llu", -3, -2L, ll, 3U, 2LU, llu);
|
||||||
|
CHECK_EQ(strcmp(buf, "-3.-2.-1.3.2.18446744073709551615"), 0);
|
||||||
|
intmax_t im = ll;
|
||||||
|
uintmax_t um = llu;
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%jd", -4, 0, 0, 0, 0, 0, 0, 0, 4, im);
|
||||||
|
CHECK_EQ(strcmp(buf, "-4.0.0.0.0.0.0.0.4.-1"), 0);
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%ju", -5, 0, 0, 0, 0, 0, 0, 0, 5, um);
|
||||||
|
CHECK_EQ(strcmp(buf, "-5.0.0.0.0.0.0.0.5.18446744073709551615"), 0);
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%jx", -6, 0, 0, 0, 0, 0, 0, 0, 6, um);
|
||||||
|
CHECK_EQ(strcmp(buf, "-6.0.0.0.0.0.0.0.6.ffffffffffffffff"), 0);
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%#jx", -7, 0, 0, 0, 0, 0, 0, 0, 7, um);
|
||||||
|
CHECK_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
TEST_CASE("libc qsort") {
|
||||||
|
// runtime check that libc qsort() never compares identical objects
|
||||||
|
// UPDATE: while only poor implementations of qsort() would actually do
|
||||||
|
// this, it is probably allowed by the standard; so skip this test case
|
||||||
|
struct Elem {
|
||||||
|
upx_uint16_t id;
|
||||||
|
upx_uint16_t value;
|
||||||
|
static int __acc_cdecl_qsort compare(const void *aa, const void *bb) noexcept {
|
||||||
|
const Elem *a = (const Elem *) aa;
|
||||||
|
const Elem *b = (const Elem *) bb;
|
||||||
|
assert_noexcept(a->id != b->id); // check not IDENTICAL
|
||||||
|
return a->value < b->value ? -1 : (a->value == b->value ? 0 : 1);
|
||||||
|
}
|
||||||
|
static bool check_sort(upx_sort_func_t sort, Elem *e, size_t n) {
|
||||||
|
upx_uint32_t x = 5381 + n + ((upx_uintptr_t) e & 0xff);
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
e[i].id = (upx_uint16_t) i;
|
||||||
|
x = x * 33 + 1 + (i & 255);
|
||||||
|
e[i].value = (upx_uint16_t) x;
|
||||||
|
}
|
||||||
|
sort(e, n, sizeof(Elem), Elem::compare);
|
||||||
|
for (size_t i = 1; i < n; i++)
|
||||||
|
if very_unlikely (e[i - 1].value > e[i].value)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
constexpr size_t N = 4096;
|
||||||
|
Elem e[N];
|
||||||
|
for (size_t n = 0; n <= N; n = 2 * n + 1) {
|
||||||
|
// CHECK(Elem::check_sort(qsort, e, n)); // libc qsort()
|
||||||
|
CHECK(Elem::check_sort(upx_gnomesort, e, n));
|
||||||
|
CHECK(Elem::check_sort(upx_shellsort_memswap, e, n));
|
||||||
|
CHECK(Elem::check_sort(upx_shellsort_memcpy, e, n));
|
||||||
|
#if UPX_CONFIG_USE_STABLE_SORT
|
||||||
|
upx_sort_func_t wrap_stable_sort = [](void *aa, size_t nn, size_t, upx_compare_func_t cc) {
|
||||||
|
upx_std_stable_sort<sizeof(Elem)>(aa, nn, cc);
|
||||||
|
};
|
||||||
|
CHECK(Elem::check_sort(wrap_stable_sort, e, n));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -0,0 +1,410 @@
|
|||||||
|
/* dt_cxxlib.cpp -- doctest check
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
// lots of tests (and probably quite a number of redundant tests)
|
||||||
|
// modern compilers will optimize away much of this code
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// compile-time checks
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
// need extra parenthesis because the C preprocessor does not understand C++ templates
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((upx::is_same_all_v<int>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((upx::is_same_all_v<int, int>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((upx::is_same_all_v<int, int, int>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((!upx::is_same_all_v<int, char>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((!upx::is_same_all_v<int, char, int>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((!upx::is_same_all_v<int, int, char>) )
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((!upx::is_same_any_v<int>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((upx::is_same_any_v<int, int>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((upx::is_same_any_v<int, char, int>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((upx::is_same_any_v<int, int, char>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((!upx::is_same_any_v<int, char>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((!upx::is_same_any_v<int, char, char>) )
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER((!upx::is_same_any_v<int, char, long>) )
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(int) == sizeof(int))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof('a') == sizeof(char))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof("") == 1)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof("a") == 2)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof("ab") == 3)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(L'a') == sizeof(wchar_t))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(L"") == 1 * sizeof(wchar_t))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(L"a") == 2 * sizeof(wchar_t))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(L"ab") == 3 * sizeof(wchar_t))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(0) == sizeof(int))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(0L) == sizeof(long))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(0LL) == sizeof(long long))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(nullptr) == sizeof(void *))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(sizeof(0)) == sizeof(size_t))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(usizeof(0)) == sizeof(unsigned))
|
||||||
|
#if 0
|
||||||
|
// works, but may trigger clang/gcc warnings "-Wunused-value"
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof((1LL, 1)) == sizeof(int))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(usizeof((1, 1LL)) == sizeof(long long))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace compile_time = upx::compile_time;
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("") == 0)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("a") == 1)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("ab") == 2)
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("abc") == 3)
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_eq("", ""))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_eq("a", ""))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_eq("", "a"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_eq("abc", "abc"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_eq("ab", "abc"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_eq("abc", "ab"))
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_lt("", ""))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_lt("a", ""))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_lt("", "a"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_lt("abc", "abc"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_lt("ab", "abc"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_lt("abc", "ab"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_lt("abc", "aba"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_lt("abc", "abz"))
|
||||||
|
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_ne("abc", "abz"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_gt("abc", "abz"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_ge("abc", "abz"))
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_le("abc", "abz"))
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// UPX_CXX_DISABLE_xxx
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <class TA, class TB, int TC = 0>
|
||||||
|
struct MyType1 {
|
||||||
|
MyType1() noexcept {}
|
||||||
|
UPX_CXX_DISABLE_ADDRESS(MyType1)
|
||||||
|
UPX_CXX_DISABLE_COPY_MOVE(MyType1)
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE_NO_VIRTUAL(MyType1)
|
||||||
|
};
|
||||||
|
template <class TA, class TB, int TC = 0>
|
||||||
|
struct MyType2 {
|
||||||
|
MyType2() noexcept {}
|
||||||
|
UPX_CXX_DISABLE_COPY_MOVE(MyType2)
|
||||||
|
typedef MyType2<TA, TB, TC> Self;
|
||||||
|
UPX_CXX_DISABLE_ADDRESS(Self)
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE_NO_VIRTUAL(Self)
|
||||||
|
};
|
||||||
|
template <class TA, class TB, int TC = 0>
|
||||||
|
struct MyVType1 {
|
||||||
|
MyVType1() noexcept {}
|
||||||
|
virtual ~MyVType1() noexcept {}
|
||||||
|
UPX_CXX_DISABLE_ADDRESS(MyVType1)
|
||||||
|
UPX_CXX_DISABLE_COPY_MOVE(MyVType1)
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE(MyVType1)
|
||||||
|
};
|
||||||
|
template <class TA, class TB, int TC = 0>
|
||||||
|
struct MyVType2 {
|
||||||
|
MyVType2() noexcept {}
|
||||||
|
virtual ~MyVType2() noexcept {}
|
||||||
|
UPX_CXX_DISABLE_COPY_MOVE(MyVType2)
|
||||||
|
typedef MyVType2<TA, TB, TC> Self;
|
||||||
|
UPX_CXX_DISABLE_ADDRESS(Self)
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE(Self)
|
||||||
|
};
|
||||||
|
TEST_CASE("upx_cxx_disable") {
|
||||||
|
MyType1<char, int, 1> dummy1;
|
||||||
|
MyType2<char, int, 2> dummy2;
|
||||||
|
MyVType1<char, int, 1> vdummy1;
|
||||||
|
MyVType2<char, int, 2> vdummy2;
|
||||||
|
(void) dummy1;
|
||||||
|
(void) dummy2;
|
||||||
|
(void) vdummy1;
|
||||||
|
(void) vdummy2;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace test_disable_new_delete {
|
||||||
|
|
||||||
|
struct A1 {
|
||||||
|
int a;
|
||||||
|
};
|
||||||
|
struct A2 {
|
||||||
|
int a;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE_NO_VIRTUAL(A2)
|
||||||
|
};
|
||||||
|
struct B1_A1 : public A1 {
|
||||||
|
int b;
|
||||||
|
};
|
||||||
|
struct B1_A2 : public A2 {
|
||||||
|
int b;
|
||||||
|
};
|
||||||
|
struct B2_A1 : public A1 {
|
||||||
|
int b;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE_NO_VIRTUAL(B2_A1)
|
||||||
|
};
|
||||||
|
struct B2_A2 : public A2 {
|
||||||
|
int b;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE_NO_VIRTUAL(B2_A2)
|
||||||
|
};
|
||||||
|
|
||||||
|
struct X1 {
|
||||||
|
virtual ~X1() noexcept {}
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
struct X2 {
|
||||||
|
virtual ~X2() noexcept {}
|
||||||
|
int x;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE(X2)
|
||||||
|
};
|
||||||
|
struct Y1_X1 : public X1 {
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
struct Y1_X2 : public X2 {
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
struct Y2_X1 : public X1 {
|
||||||
|
int y;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE(Y2_X1)
|
||||||
|
};
|
||||||
|
struct Y2_X2 : public X2 {
|
||||||
|
int y;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE(Y2_X2)
|
||||||
|
};
|
||||||
|
struct Z1_X1 : public X1 {
|
||||||
|
virtual ~Z1_X1() noexcept {}
|
||||||
|
int z;
|
||||||
|
};
|
||||||
|
struct Z1_X2 : public X2 {
|
||||||
|
virtual ~Z1_X2() noexcept {}
|
||||||
|
int z;
|
||||||
|
};
|
||||||
|
struct Z2_X1 : public X1 {
|
||||||
|
virtual ~Z2_X1() noexcept {}
|
||||||
|
int z;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE(Z2_X1)
|
||||||
|
};
|
||||||
|
struct Z2_X2 : public X2 {
|
||||||
|
virtual ~Z2_X2() noexcept {}
|
||||||
|
int z;
|
||||||
|
UPX_CXX_DISABLE_NEW_DELETE(Z2_X2)
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test_disable_new_delete
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// util
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("ptr_static_cast") {
|
||||||
|
// check that we don't trigger any -Wcast-align warnings
|
||||||
|
using upx::ptr_static_cast;
|
||||||
|
void *vp = nullptr;
|
||||||
|
byte *bp = nullptr;
|
||||||
|
int *ip = nullptr;
|
||||||
|
double *dp = nullptr;
|
||||||
|
|
||||||
|
assert((vp == ptr_static_cast<void *>(vp)));
|
||||||
|
assert((vp == ptr_static_cast<void *>(bp)));
|
||||||
|
assert((vp == ptr_static_cast<void *>(ip)));
|
||||||
|
assert((vp == ptr_static_cast<void *>(dp)));
|
||||||
|
|
||||||
|
assert((bp == ptr_static_cast<byte *>(vp)));
|
||||||
|
assert((bp == ptr_static_cast<byte *>(bp)));
|
||||||
|
assert((bp == ptr_static_cast<byte *>(ip)));
|
||||||
|
assert((bp == ptr_static_cast<byte *>(dp)));
|
||||||
|
|
||||||
|
assert((ip == ptr_static_cast<int *>(vp)));
|
||||||
|
assert((ip == ptr_static_cast<int *>(bp)));
|
||||||
|
assert((ip == ptr_static_cast<int *>(ip)));
|
||||||
|
assert((ip == ptr_static_cast<int *>(dp)));
|
||||||
|
|
||||||
|
assert((dp == ptr_static_cast<double *>(vp)));
|
||||||
|
assert((dp == ptr_static_cast<double *>(bp)));
|
||||||
|
assert((dp == ptr_static_cast<double *>(ip)));
|
||||||
|
assert((dp == ptr_static_cast<double *>(dp)));
|
||||||
|
|
||||||
|
const byte *bc = nullptr;
|
||||||
|
const int *ic = nullptr;
|
||||||
|
assert((bc == ptr_static_cast<byte *>(bp)));
|
||||||
|
assert((bc == ptr_static_cast<const byte *>(bc)));
|
||||||
|
assert((bc == ptr_static_cast<byte *>(ip)));
|
||||||
|
assert((bc == ptr_static_cast<const byte *>(ic)));
|
||||||
|
assert((ic == ptr_static_cast<int *>(bp)));
|
||||||
|
assert((ic == ptr_static_cast<const int *>(bc)));
|
||||||
|
assert((ic == ptr_static_cast<int *>(ip)));
|
||||||
|
assert((ic == ptr_static_cast<const int *>(ic)));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("noncopyable") {
|
||||||
|
struct Test : private upx::noncopyable {
|
||||||
|
int v = 1;
|
||||||
|
};
|
||||||
|
Test t = {};
|
||||||
|
CHECK(t.v == 1);
|
||||||
|
#if (ACC_CC_MSC) // MSVC thinks that Test is not std::is_trivially_copyable; true or compiler bug?
|
||||||
|
// @COMPILER_BUG @MSVC_BUG
|
||||||
|
t.v = 0;
|
||||||
|
#else
|
||||||
|
mem_clear(&t);
|
||||||
|
#endif
|
||||||
|
CHECK(t.v == 0);
|
||||||
|
constexpr Test x = {};
|
||||||
|
static_assert(x.v == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// TriBool checks
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <class T>
|
||||||
|
struct TestTriBool {
|
||||||
|
static void test(bool expect_true) {
|
||||||
|
static_assert(std::is_class<T>::value);
|
||||||
|
static_assert(std::is_nothrow_default_constructible<T>::value);
|
||||||
|
static_assert(std::is_nothrow_destructible<T>::value);
|
||||||
|
static_assert(std::is_standard_layout<T>::value);
|
||||||
|
static_assert(std::is_trivially_copyable<T>::value);
|
||||||
|
static_assert(sizeof(typename T::value_type) == sizeof(typename T::underlying_type));
|
||||||
|
static_assert(alignof(typename T::value_type) == alignof(typename T::underlying_type));
|
||||||
|
#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)
|
||||||
|
// broken compiler or broken ABI
|
||||||
|
#else
|
||||||
|
static_assert(sizeof(T) == sizeof(typename T::underlying_type));
|
||||||
|
static_assert(alignof(T) == alignof(typename T::underlying_type));
|
||||||
|
#endif
|
||||||
|
static_assert(!bool(T(false)));
|
||||||
|
static_assert(bool(T(true)));
|
||||||
|
static_assert(bool(T(T::Third)) == T::is_third_true);
|
||||||
|
static_assert(T(false) == T::False);
|
||||||
|
static_assert(T(true) == T::True);
|
||||||
|
static_assert(T(T::False) == T::False);
|
||||||
|
static_assert(T(T::True) == T::True);
|
||||||
|
static_assert(T(T::Third) == T::Third);
|
||||||
|
static_assert(T(T::Third) == T(9));
|
||||||
|
static_assert(T(8) == T(9));
|
||||||
|
static_assert(!(T(0) == T(9)));
|
||||||
|
static_assert(!(T(1) == T(9)));
|
||||||
|
static_assert(T(T::Third) == 9);
|
||||||
|
static_assert(T(8) == 9);
|
||||||
|
static_assert(!(T(0) == 9));
|
||||||
|
static_assert(!(T(1) == 9));
|
||||||
|
constexpr T array[] = {false, true, T::Third};
|
||||||
|
static_assert(array[0].isStrictFalse());
|
||||||
|
static_assert(array[1].isStrictTrue());
|
||||||
|
static_assert(array[2].isThird());
|
||||||
|
static_assert(sizeof(array) == 3 * sizeof(T));
|
||||||
|
T a;
|
||||||
|
assert(a.getValue() == T::False);
|
||||||
|
assert(!a);
|
||||||
|
assert(!bool(a));
|
||||||
|
assert((!a ? true : false));
|
||||||
|
assert(a.isStrictFalse());
|
||||||
|
assert(!a.isStrictTrue());
|
||||||
|
assert(a.isStrictBool());
|
||||||
|
assert(!a.isThird());
|
||||||
|
a = false;
|
||||||
|
assert(a.getValue() == T::False);
|
||||||
|
assert(!a);
|
||||||
|
assert(!bool(a));
|
||||||
|
assert((!a ? true : false));
|
||||||
|
assert(a.isStrictFalse());
|
||||||
|
assert(!a.isStrictTrue());
|
||||||
|
assert(a.isStrictBool());
|
||||||
|
assert(!a.isThird());
|
||||||
|
a = true;
|
||||||
|
assert(a.getValue() == T::True);
|
||||||
|
assert(a);
|
||||||
|
assert(bool(a));
|
||||||
|
assert((a ? true : false));
|
||||||
|
assert(!a.isStrictFalse());
|
||||||
|
assert(a.isStrictTrue());
|
||||||
|
assert(a.isStrictBool());
|
||||||
|
assert(!a.isThird());
|
||||||
|
a = T::Third;
|
||||||
|
assert(a.getValue() == T::Third);
|
||||||
|
assert(T::is_third_true == expect_true);
|
||||||
|
if (expect_true) {
|
||||||
|
assert(a);
|
||||||
|
assert(bool(a));
|
||||||
|
assert((a ? true : false));
|
||||||
|
} else {
|
||||||
|
assert(!a);
|
||||||
|
assert(!bool(a));
|
||||||
|
assert((!a ? true : false));
|
||||||
|
}
|
||||||
|
assert(!a.isStrictFalse());
|
||||||
|
assert(!a.isStrictTrue());
|
||||||
|
assert(!a.isStrictBool());
|
||||||
|
assert(a.isThird());
|
||||||
|
a = 99;
|
||||||
|
assert(a.getValue() == T::Third);
|
||||||
|
if (expect_true) {
|
||||||
|
assert(a);
|
||||||
|
assert(bool(a));
|
||||||
|
assert((a ? true : false));
|
||||||
|
} else {
|
||||||
|
assert(!a);
|
||||||
|
assert(!bool(a));
|
||||||
|
assert((!a ? true : false));
|
||||||
|
}
|
||||||
|
assert(!a.isStrictFalse());
|
||||||
|
assert(!a.isStrictTrue());
|
||||||
|
assert(!a.isStrictBool());
|
||||||
|
assert(a.isThird());
|
||||||
|
mem_clear(&a);
|
||||||
|
assert(a.isStrictFalse());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST_CASE("TriBool") {
|
||||||
|
using upx::TriBool, upx::tribool;
|
||||||
|
static_assert(!tribool(false));
|
||||||
|
static_assert(tribool(true));
|
||||||
|
static_assert(!tribool(tribool::Third));
|
||||||
|
TestTriBool<tribool>::test(false);
|
||||||
|
#if DEBUG || 1
|
||||||
|
TestTriBool<TriBool<upx_int8_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_uint8_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_int16_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_uint16_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_int32_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_uint32_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_int64_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_uint64_t> >::test(false);
|
||||||
|
TestTriBool<TriBool<upx_int8_t, true> >::test(true);
|
||||||
|
TestTriBool<TriBool<upx_uint8_t, true> >::test(true);
|
||||||
|
TestTriBool<TriBool<upx_int16_t, true> >::test(true);
|
||||||
|
TestTriBool<TriBool<upx_uint16_t, true> >::test(true);
|
||||||
|
TestTriBool<TriBool<upx_int32_t, true> >::test(true);
|
||||||
|
TestTriBool<TriBool<upx_uint32_t, true> >::test(true);
|
||||||
|
TestTriBool<TriBool<upx_int64_t, true> >::test(true);
|
||||||
|
TestTriBool<TriBool<upx_uint64_t, true> >::test(true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -21,8 +20,8 @@
|
|||||||
If not, write to the Free Software Foundation, Inc.,
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
Markus F.X.J. Oberhumer
|
||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -30,15 +29,33 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define DOCTEST_CONFIG_IMPLEMENT
|
#define DOCTEST_CONFIG_IMPLEMENT
|
||||||
#if !defined(UPX_DOCTEST_CONFIG_MULTITHREADING)
|
|
||||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
|
||||||
#endif
|
|
||||||
#if defined(__MSDOS__) && defined(__DJGPP__)
|
|
||||||
#define DOCTEST_CONFIG_NO_POSIX_SIGNALS
|
|
||||||
#endif
|
|
||||||
#define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
|
#define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
|
||||||
|
|
||||||
#if !defined(DOCTEST_CONFIG_DISABLE)
|
#if !defined(DOCTEST_CONFIG_DISABLE)
|
||||||
#include <doctest/doctest/parts/doctest.cpp>
|
|
||||||
|
#if defined(__i386__) && defined(__MSDOS__) && defined(__DJGPP__) && defined(__GNUC__)
|
||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_NO_POSIX_SIGNALS
|
||||||
|
#elif defined(__m68k__) && defined(__atarist__) && defined(__GNUC__)
|
||||||
|
#define DOCTEST_CONFIG_COLORS_NONE
|
||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_NO_POSIX_SIGNALS
|
||||||
|
#pragma GCC diagnostic ignored "-Wshadow"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(UPX_DOCTEST_CONFIG_MULTITHREADING) && !(WITH_THREADS)
|
||||||
|
#ifndef DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__clang__) && defined(__FAST_MATH__) && defined(__INTEL_LLVM_COMPILER)
|
||||||
|
// warning: comparison with NaN always evaluates to false in fast floating point modes
|
||||||
|
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <doctest/doctest/parts/doctest.cpp>
|
||||||
|
|
||||||
|
#endif // DOCTEST_CONFIG_DISABLE
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -0,0 +1,978 @@
|
|||||||
|
/* xspan -- a minimally invasive checked memory smart pointer
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
// lots of tests (and probably quite a number of redundant tests)
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// raw_bytes
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("raw_bytes ptr") {
|
||||||
|
upx_uint16_t *ptr = nullptr;
|
||||||
|
CHECK_NOTHROW(raw_bytes(ptr, 0));
|
||||||
|
CHECK_THROWS(raw_bytes(ptr, 1));
|
||||||
|
CHECK_THROWS(raw_index_bytes(ptr, 0, 0));
|
||||||
|
CHECK_THROWS(raw_index_bytes(ptr, 1, 0));
|
||||||
|
CHECK_THROWS(raw_index_bytes(ptr, 0, 1));
|
||||||
|
upx_uint16_t buf[4];
|
||||||
|
ptr = buf;
|
||||||
|
CHECK(ptr_udiff_bytes(raw_index_bytes(ptr, 1, 1), ptr) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(raw_index_bytes(ptr, 4, 0), ptr) == 8u);
|
||||||
|
UNUSED(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("raw_bytes bounded array") {
|
||||||
|
upx_uint16_t buf[4];
|
||||||
|
CHECK_NOTHROW(raw_bytes(buf, 8));
|
||||||
|
CHECK_THROWS(raw_bytes(buf, 9));
|
||||||
|
CHECK_NOTHROW(raw_index_bytes(buf, 4, 0));
|
||||||
|
CHECK_THROWS(raw_index_bytes(buf, 4, 1));
|
||||||
|
CHECK_NOTHROW(raw_index_bytes(buf, 3, 2));
|
||||||
|
CHECK_THROWS(raw_index_bytes(buf, 3, 3));
|
||||||
|
CHECK(ptr_udiff_bytes(raw_index_bytes(buf, 1, 1), buf) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(raw_index_bytes(buf, 4, 0), buf) == 8u);
|
||||||
|
UNUSED(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// basic xspan
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("basic xspan usage") {
|
||||||
|
alignas(4) char buf[4] = {0, 1, 2, 3};
|
||||||
|
|
||||||
|
SUBCASE("XSPAN_x") {
|
||||||
|
XSPAN_0(char) a0 = nullptr;
|
||||||
|
|
||||||
|
XSPAN_0(char) b0 = buf;
|
||||||
|
XSPAN_P(char) bp = buf;
|
||||||
|
|
||||||
|
XSPAN_0(char) c0 = XSPAN_0_MAKE(char, buf);
|
||||||
|
XSPAN_P(char) cp = XSPAN_P_MAKE(char, buf);
|
||||||
|
XSPAN_S(char) cs = XSPAN_S_MAKE(char, buf, sizeof(buf));
|
||||||
|
|
||||||
|
XSPAN_0(const char) const x0 = XSPAN_0_MAKE(const char, buf);
|
||||||
|
XSPAN_P(const char) const xp = XSPAN_P_MAKE(const char, buf);
|
||||||
|
XSPAN_S(const char) const xs = XSPAN_S_MAKE(const char, buf, sizeof(buf));
|
||||||
|
XSPAN_P(const char) const yp = xs;
|
||||||
|
XSPAN_0(const char) const z0p = yp;
|
||||||
|
XSPAN_0(const char) const z0s = xs;
|
||||||
|
|
||||||
|
CHECK((a0 == nullptr));
|
||||||
|
CHECK(c0 == b0);
|
||||||
|
CHECK(cp == bp);
|
||||||
|
CHECK(cs == bp);
|
||||||
|
CHECK(x0 == z0p);
|
||||||
|
CHECK(xp == z0s);
|
||||||
|
|
||||||
|
CHECK_NOTHROW(raw_bytes(a0, 0));
|
||||||
|
CHECK_THROWS(raw_bytes(a0, 1));
|
||||||
|
CHECK_THROWS(raw_index_bytes(a0, 0, 0));
|
||||||
|
|
||||||
|
CHECK(raw_bytes(b0, 0) == buf);
|
||||||
|
CHECK(raw_bytes(bp, 0) == buf);
|
||||||
|
// info: these will fail if we ever add an overload for bounded-arrays
|
||||||
|
#if WITH_XSPAN >= 2
|
||||||
|
CHECK(b0.raw_size_in_bytes() == 0u);
|
||||||
|
CHECK(bp.raw_size_in_bytes() == 0u);
|
||||||
|
#endif
|
||||||
|
CHECK(raw_bytes(b0, 999999) == buf);
|
||||||
|
CHECK(raw_bytes(bp, 999999) == buf);
|
||||||
|
|
||||||
|
CHECK(raw_bytes(c0, 4) == buf);
|
||||||
|
CHECK(raw_index_bytes(c0, 1, 3) == buf + 1);
|
||||||
|
CHECK(raw_bytes(cp, 4) == buf);
|
||||||
|
CHECK(raw_index_bytes(cp, 1, 3) == buf + 1);
|
||||||
|
CHECK(raw_bytes(cs, 4) == buf);
|
||||||
|
CHECK(raw_index_bytes(cs, 1, 3) == buf + 1);
|
||||||
|
#if WITH_XSPAN >= 2
|
||||||
|
CHECK_THROWS(raw_bytes(cs, 5));
|
||||||
|
CHECK_THROWS(raw_index_bytes(cs, 1, 4));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
XSPAN_0(upx_uint16_t) c0_2 = XSPAN_TYPE_CAST(upx_uint16_t, c0 + 2);
|
||||||
|
XSPAN_P(upx_uint16_t) cp_2 = XSPAN_TYPE_CAST(upx_uint16_t, cp + 2);
|
||||||
|
XSPAN_S(upx_uint16_t) cs_2 = XSPAN_TYPE_CAST(upx_uint16_t, cs + 2);
|
||||||
|
CHECK(ptr_udiff_bytes(c0_2, c0) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cp_2, c0) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cs_2, c0) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(c0_2, cp) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cp_2, cp) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cs_2, cp) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(c0_2, cs) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cp_2, cs) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cs_2, cs) == 2u);
|
||||||
|
XSPAN_0(upx_uint16_t) c0_2b = XSPAN_TYPE_CAST(upx_uint16_t, c0) + 1;
|
||||||
|
XSPAN_P(upx_uint16_t) cp_2b = XSPAN_TYPE_CAST(upx_uint16_t, cp) + 1;
|
||||||
|
XSPAN_S(upx_uint16_t) cs_2b = XSPAN_TYPE_CAST(upx_uint16_t, cs) + 1;
|
||||||
|
CHECK(c0_2 == c0_2b);
|
||||||
|
CHECK(cp_2 == cp_2b);
|
||||||
|
CHECK(cs_2 == cs_2b);
|
||||||
|
|
||||||
|
CHECK(sizeof(*c0) == 1u);
|
||||||
|
CHECK(sizeof(*c0_2) == 2u);
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("XSPAN_x_VAR") {
|
||||||
|
XSPAN_0_VAR(char, b0, buf);
|
||||||
|
XSPAN_P_VAR(char, bp, buf);
|
||||||
|
|
||||||
|
XSPAN_0_VAR(char, c0, buf, sizeof(buf));
|
||||||
|
XSPAN_P_VAR(char, cp, buf, sizeof(buf));
|
||||||
|
XSPAN_S_VAR(char, cs, buf, sizeof(buf));
|
||||||
|
|
||||||
|
XSPAN_0_VAR(char, d0, buf + 1, sizeof(buf), buf);
|
||||||
|
XSPAN_P_VAR(char, dp, buf + 1, sizeof(buf), buf);
|
||||||
|
XSPAN_S_VAR(char, ds, buf + 1, sizeof(buf), buf);
|
||||||
|
|
||||||
|
XSPAN_0_VAR(const char, const x0, buf, sizeof(buf));
|
||||||
|
XSPAN_P_VAR(const char, const xp, buf, sizeof(buf));
|
||||||
|
XSPAN_S_VAR(const char, const xs, buf, sizeof(buf));
|
||||||
|
XSPAN_P_VAR(const char, const yp, xs);
|
||||||
|
XSPAN_0_VAR(const char, const z0p, yp);
|
||||||
|
XSPAN_0_VAR(const char, const z0s, xs);
|
||||||
|
|
||||||
|
CHECK(c0 == b0);
|
||||||
|
CHECK(cp == bp);
|
||||||
|
CHECK(cs == bp);
|
||||||
|
CHECK(d0 == dp);
|
||||||
|
CHECK(d0 == ds);
|
||||||
|
CHECK(x0 == z0p);
|
||||||
|
CHECK(xp == z0s);
|
||||||
|
|
||||||
|
#if WITH_XSPAN >= 1 || __cplusplus >= 201103L
|
||||||
|
XSPAN_0_VAR(char, a0, nullptr);
|
||||||
|
CHECK((a0 == nullptr));
|
||||||
|
CHECK_NOTHROW(raw_bytes(a0, 0));
|
||||||
|
CHECK_THROWS(raw_bytes(a0, 1));
|
||||||
|
CHECK_THROWS(raw_index_bytes(a0, 0, 0));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CHECK(raw_bytes(b0, 0) == buf);
|
||||||
|
CHECK(raw_bytes(bp, 0) == buf);
|
||||||
|
// info: these will fail if we ever add an overload for bounded-arrays
|
||||||
|
#if WITH_XSPAN >= 2
|
||||||
|
CHECK(b0.raw_size_in_bytes() == 0u);
|
||||||
|
CHECK(bp.raw_size_in_bytes() == 0u);
|
||||||
|
#endif
|
||||||
|
CHECK(raw_bytes(b0, 999999) == buf);
|
||||||
|
CHECK(raw_bytes(bp, 999999) == buf);
|
||||||
|
|
||||||
|
CHECK(raw_bytes(c0, 4) == buf);
|
||||||
|
CHECK(raw_index_bytes(c0, 1, 3) == buf + 1);
|
||||||
|
CHECK(raw_bytes(cp, 4) == buf);
|
||||||
|
CHECK(raw_index_bytes(cp, 1, 3) == buf + 1);
|
||||||
|
CHECK(raw_bytes(cs, 4) == buf);
|
||||||
|
CHECK(raw_index_bytes(cs, 1, 3) == buf + 1);
|
||||||
|
#if WITH_XSPAN >= 2
|
||||||
|
CHECK_THROWS(raw_bytes(cs, 5));
|
||||||
|
CHECK_THROWS(raw_index_bytes(cs, 1, 4));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
XSPAN_0_VAR(upx_uint16_t, c0_2, XSPAN_TYPE_CAST(upx_uint16_t, c0 + 2));
|
||||||
|
XSPAN_P_VAR(upx_uint16_t, cp_2, XSPAN_TYPE_CAST(upx_uint16_t, cp + 2));
|
||||||
|
XSPAN_S_VAR(upx_uint16_t, cs_2, XSPAN_TYPE_CAST(upx_uint16_t, cs + 2));
|
||||||
|
CHECK(ptr_udiff_bytes(c0_2, c0) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cp_2, c0) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cs_2, c0) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(c0_2, cp) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cp_2, cp) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cs_2, cp) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(c0_2, cs) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cp_2, cs) == 2u);
|
||||||
|
CHECK(ptr_udiff_bytes(cs_2, cs) == 2u);
|
||||||
|
XSPAN_0_VAR(upx_uint16_t, c0_2b, XSPAN_TYPE_CAST(upx_uint16_t, c0) + 1);
|
||||||
|
XSPAN_P_VAR(upx_uint16_t, cp_2b, XSPAN_TYPE_CAST(upx_uint16_t, cp) + 1);
|
||||||
|
XSPAN_S_VAR(upx_uint16_t, cs_2b, XSPAN_TYPE_CAST(upx_uint16_t, cs) + 1);
|
||||||
|
CHECK(c0_2 == c0_2b);
|
||||||
|
CHECK(cp_2 == cp_2b);
|
||||||
|
CHECK(cs_2 == cs_2b);
|
||||||
|
|
||||||
|
CHECK(sizeof(*c0) == 1u);
|
||||||
|
CHECK(sizeof(*c0_2) == 2u);
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("xspan in class") {
|
||||||
|
struct MyType {
|
||||||
|
XSPAN_0(char) s0;
|
||||||
|
XSPAN_P(char) sp;
|
||||||
|
XSPAN_S(char) ss;
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
XSPAN_0(char) x0 = nullptr;
|
||||||
|
#endif
|
||||||
|
#if WITH_XSPAN >= 2
|
||||||
|
// much nicer syntax when using fully checked xspan:
|
||||||
|
MyType(char *b, size_t n, bool) : s0(b, n), sp(b, n), ss(b, n) {}
|
||||||
|
#endif
|
||||||
|
MyType(char *b, size_t n)
|
||||||
|
: s0(XSPAN_0_MAKE(char, b, n)), sp(XSPAN_P_MAKE(char, b, n)),
|
||||||
|
ss(XSPAN_S_MAKE(char, b, n)) {
|
||||||
|
UNUSED(n);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
MyType x(buf, sizeof(buf));
|
||||||
|
MyType y = MyType(buf, sizeof(buf));
|
||||||
|
CHECK(x.s0 == y.sp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if (WITH_XSPAN >= 2) && DEBUG
|
||||||
|
|
||||||
|
TEST_CASE("PtrOrSpanOrNull") {
|
||||||
|
char real_buf[2 + 6 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 124, 125};
|
||||||
|
char *base_buf = real_buf + 2;
|
||||||
|
char *const my_null = nullptr;
|
||||||
|
typedef PtrOrSpanOrNull<char> Span0;
|
||||||
|
|
||||||
|
// basic nullptr
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = my_null);
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 4, base_buf).assign(my_null));
|
||||||
|
// basic range checking
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 4, base_buf));
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 0, base_buf));
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 0, base_buf) - 0);
|
||||||
|
CHECK_THROWS(Span0(base_buf, 0, base_buf) + 1);
|
||||||
|
CHECK_THROWS(Span0(base_buf, 0, base_buf) - 1);
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) + 4);
|
||||||
|
CHECK_THROWS(Span0(base_buf, 4, base_buf) + 5);
|
||||||
|
CHECK_THROWS(Span0(base_buf - 1, 4, base_buf));
|
||||||
|
CHECK_THROWS(Span0(base_buf + 1, 0, base_buf));
|
||||||
|
// basic same base
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 3, base_buf));
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 1, base_buf));
|
||||||
|
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 5, base_buf));
|
||||||
|
CHECK_THROWS(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 3, base_buf + 1));
|
||||||
|
|
||||||
|
Span0 a1(nullptr);
|
||||||
|
assert(a1 == nullptr);
|
||||||
|
assert(a1.raw_ptr() == nullptr);
|
||||||
|
assert(a1.raw_base() == nullptr);
|
||||||
|
assert(a1.raw_size_in_bytes() == 0u);
|
||||||
|
CHECK_THROWS(*a1);
|
||||||
|
CHECK_THROWS(a1[0]);
|
||||||
|
|
||||||
|
Span0 a2 = nullptr;
|
||||||
|
assert(a2 == nullptr);
|
||||||
|
assert(a2.raw_ptr() == nullptr);
|
||||||
|
assert(a2.raw_base() == nullptr);
|
||||||
|
assert(a2.raw_size_in_bytes() == 0u);
|
||||||
|
CHECK_THROWS(*a2);
|
||||||
|
CHECK_THROWS(a2[0]);
|
||||||
|
|
||||||
|
Span0 base0(nullptr, 4, base_buf);
|
||||||
|
assert(base0.raw_ptr() == nullptr);
|
||||||
|
assert(base0.raw_base() == base_buf);
|
||||||
|
assert(base0.raw_size_in_bytes() == 4u);
|
||||||
|
CHECK_THROWS(*base0); // nullptr
|
||||||
|
CHECK_THROWS(base0[0]); // nullptr
|
||||||
|
CHECK_THROWS(base0 + 1); // nullptr
|
||||||
|
|
||||||
|
Span0 base4(base_buf, 4);
|
||||||
|
assert(base4.raw_ptr() == base_buf);
|
||||||
|
assert(base4.raw_base() == base_buf);
|
||||||
|
assert(base4.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
a1 = base_buf;
|
||||||
|
a1 = base0;
|
||||||
|
assert(a1 == nullptr);
|
||||||
|
assert(a1.raw_ptr() == nullptr);
|
||||||
|
assert(a1.raw_base() == base_buf);
|
||||||
|
assert(a1.raw_size_in_bytes() == 4u);
|
||||||
|
a1 = base4;
|
||||||
|
assert(a1 == base_buf);
|
||||||
|
assert(a1.raw_ptr() == base_buf);
|
||||||
|
assert(a1.raw_base() == base_buf);
|
||||||
|
assert(a1.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
a1 = base_buf;
|
||||||
|
assert(a1 != nullptr);
|
||||||
|
a1 = base_buf + 1;
|
||||||
|
CHECK(*a1++ == 1);
|
||||||
|
CHECK(*++a1 == 3);
|
||||||
|
CHECK(*a1 == 3);
|
||||||
|
a1 = base_buf + 4; // at the end of buffer
|
||||||
|
CHECK_THROWS(*a1);
|
||||||
|
CHECK_THROWS(a1 = base_buf + 5); // range error
|
||||||
|
assert(a1 == base_buf + 4);
|
||||||
|
CHECK(a1[-4] == 0);
|
||||||
|
CHECK_THROWS(a1[-5]); // range error
|
||||||
|
a1 = base_buf;
|
||||||
|
CHECK(*a1 == 0);
|
||||||
|
|
||||||
|
Span0 new_base4(base_buf + 2, 4);
|
||||||
|
CHECK_THROWS(a1 = new_base4); // not same base
|
||||||
|
a2 = new_base4;
|
||||||
|
CHECK_THROWS(a2 = base4); // not same base
|
||||||
|
|
||||||
|
Span0 s0_no_base(nullptr);
|
||||||
|
Span0 s0_with_base(nullptr, 4, base_buf);
|
||||||
|
s0_no_base = nullptr;
|
||||||
|
s0_with_base = nullptr;
|
||||||
|
s0_with_base = s0_no_base;
|
||||||
|
assert(s0_no_base.raw_base() == nullptr);
|
||||||
|
assert(s0_with_base.raw_base() == base_buf);
|
||||||
|
s0_no_base = s0_with_base;
|
||||||
|
assert(s0_no_base.raw_base() == base_buf);
|
||||||
|
assert(s0_no_base.raw_ptr() == nullptr);
|
||||||
|
assert(s0_with_base.raw_ptr() == nullptr);
|
||||||
|
s0_no_base = my_null;
|
||||||
|
s0_with_base = my_null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("PtrOrSpan") {
|
||||||
|
char real_buf[2 + 6 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 124, 125};
|
||||||
|
char *base_buf = real_buf + 2;
|
||||||
|
char *const my_null = nullptr;
|
||||||
|
typedef PtrOrSpan<char> SpanP;
|
||||||
|
|
||||||
|
// basic nullptr
|
||||||
|
CHECK_THROWS(SpanP(base_buf, 4, base_buf) = my_null);
|
||||||
|
CHECK_THROWS(SpanP(base_buf, 4, base_buf).assign(my_null));
|
||||||
|
// basic range checking
|
||||||
|
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanP(base_buf, 0, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanP(base_buf, 0, base_buf) - 0);
|
||||||
|
CHECK_THROWS(SpanP(base_buf, 0, base_buf) + 1);
|
||||||
|
CHECK_THROWS(SpanP(base_buf, 0, base_buf) - 1);
|
||||||
|
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) + 4);
|
||||||
|
CHECK_THROWS(SpanP(base_buf, 4, base_buf) + 5);
|
||||||
|
CHECK_THROWS(SpanP(base_buf - 1, 4, base_buf));
|
||||||
|
CHECK_THROWS(SpanP(base_buf + 1, 0, base_buf));
|
||||||
|
// basic same base
|
||||||
|
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 3, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 1, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 5, base_buf));
|
||||||
|
CHECK_THROWS(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 3, base_buf + 1));
|
||||||
|
|
||||||
|
SpanP x1(base_buf, 0);
|
||||||
|
assert(x1 != nullptr);
|
||||||
|
assert(x1.raw_ptr() == base_buf);
|
||||||
|
assert(x1.raw_base() == base_buf);
|
||||||
|
assert(x1.raw_size_in_bytes() == 0u);
|
||||||
|
CHECK_THROWS(*x1);
|
||||||
|
CHECK_THROWS(x1[0]);
|
||||||
|
|
||||||
|
SpanP a2 = base_buf;
|
||||||
|
assert(a2 != nullptr);
|
||||||
|
assert(a2.raw_ptr() == base_buf);
|
||||||
|
assert(a2.raw_base() == nullptr);
|
||||||
|
assert(a2.raw_size_in_bytes() == 0u);
|
||||||
|
CHECK(*a2 == 0);
|
||||||
|
CHECK(a2[1] == 1);
|
||||||
|
|
||||||
|
SpanP base0(base_buf, 4, base_buf);
|
||||||
|
assert(base0.raw_ptr() == base_buf);
|
||||||
|
assert(base0.raw_base() == base_buf);
|
||||||
|
assert(base0.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
SpanP base4(base_buf, 4);
|
||||||
|
assert(base4.raw_ptr() == base_buf);
|
||||||
|
assert(base4.raw_base() == base_buf);
|
||||||
|
assert(base4.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
SpanP a1(base_buf, 4);
|
||||||
|
a1 = base_buf;
|
||||||
|
a1 = base0;
|
||||||
|
assert(a1 == base0);
|
||||||
|
assert(a1 != nullptr);
|
||||||
|
assert(a1.raw_ptr() == base0.raw_ptr());
|
||||||
|
assert(a1.raw_base() == base_buf);
|
||||||
|
assert(a1.raw_size_in_bytes() == 4u);
|
||||||
|
a1 = base4;
|
||||||
|
assert(a1 == base_buf);
|
||||||
|
assert(a1.raw_ptr() == base_buf);
|
||||||
|
assert(a1.raw_base() == base_buf);
|
||||||
|
assert(a1.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
a1 = base_buf;
|
||||||
|
a1 = base_buf + 1;
|
||||||
|
CHECK(*a1++ == 1);
|
||||||
|
CHECK(*++a1 == 3);
|
||||||
|
CHECK(*a1 == 3);
|
||||||
|
a1 = base_buf + 4; // at the end of buffer
|
||||||
|
CHECK_THROWS(*a1);
|
||||||
|
CHECK_THROWS(a1 = base_buf + 5); // range error
|
||||||
|
assert(a1 == base_buf + 4);
|
||||||
|
CHECK(a1[-4] == 0);
|
||||||
|
CHECK_THROWS(a1[-5]); // range error
|
||||||
|
a1 = base_buf;
|
||||||
|
CHECK(*a1 == 0);
|
||||||
|
|
||||||
|
SpanP new_base4(base_buf + 2, 4);
|
||||||
|
CHECK_THROWS(a1 = new_base4); // not same base
|
||||||
|
a2 = new_base4;
|
||||||
|
CHECK_THROWS(a2 = base4); // not same base
|
||||||
|
|
||||||
|
SpanP sp_no_base(base_buf);
|
||||||
|
SpanP sp_with_base(base_buf, 4, base_buf);
|
||||||
|
assert(sp_no_base.raw_base() == nullptr);
|
||||||
|
assert(sp_with_base.raw_base() == base_buf);
|
||||||
|
CHECK_THROWS(sp_no_base = my_null); // nullptr assignment
|
||||||
|
CHECK_THROWS(sp_with_base = my_null); // nullptr assignment
|
||||||
|
#if XSPAN_CONFIG_ENABLE_SPAN_CONVERSION
|
||||||
|
typedef PtrOrSpanOrNull<char> Span0;
|
||||||
|
Span0 s0_no_base(nullptr);
|
||||||
|
Span0 s0_with_base(nullptr, 4, base_buf);
|
||||||
|
CHECK_THROWS(sp_no_base = s0_no_base); // nullptr assignment
|
||||||
|
CHECK_THROWS(sp_no_base = s0_with_base); // nullptr assignment
|
||||||
|
CHECK_THROWS(sp_with_base = s0_no_base); // nullptr assignment
|
||||||
|
CHECK_THROWS(sp_with_base = s0_with_base); // nullptr assignment
|
||||||
|
#endif
|
||||||
|
UNUSED(my_null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("Span") {
|
||||||
|
char real_buf[2 + 6 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 124, 125};
|
||||||
|
char *base_buf = real_buf + 2;
|
||||||
|
char *const my_null = nullptr;
|
||||||
|
typedef Span<char> SpanS;
|
||||||
|
|
||||||
|
// basic nullptr
|
||||||
|
CHECK_THROWS(SpanS(base_buf, 4, base_buf) = my_null);
|
||||||
|
CHECK_THROWS(SpanS(base_buf, 4, base_buf).assign(my_null));
|
||||||
|
// basic range checking
|
||||||
|
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanS(base_buf, 0, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanS(base_buf, 0, base_buf) - 0);
|
||||||
|
CHECK_THROWS(SpanS(base_buf, 0, base_buf) + 1);
|
||||||
|
CHECK_THROWS(SpanS(base_buf, 0, base_buf) - 1);
|
||||||
|
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) + 4);
|
||||||
|
CHECK_THROWS(SpanS(base_buf, 4, base_buf) + 5);
|
||||||
|
CHECK_THROWS(SpanS(base_buf - 1, 4, base_buf));
|
||||||
|
CHECK_THROWS(SpanS(base_buf + 1, 0, base_buf));
|
||||||
|
// basic same base
|
||||||
|
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 3, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 1, base_buf));
|
||||||
|
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 5, base_buf));
|
||||||
|
CHECK_THROWS(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 3, base_buf + 1));
|
||||||
|
|
||||||
|
SpanS x1(base_buf, 0);
|
||||||
|
assert(x1 != nullptr);
|
||||||
|
assert(x1.raw_ptr() == base_buf);
|
||||||
|
assert(x1.raw_base() == base_buf);
|
||||||
|
assert(x1.raw_size_in_bytes() == 0u);
|
||||||
|
CHECK_THROWS(*x1);
|
||||||
|
CHECK_THROWS(x1[0]);
|
||||||
|
|
||||||
|
SpanS a2(base_buf, 4);
|
||||||
|
assert(a2 != nullptr);
|
||||||
|
assert(a2.raw_ptr() == base_buf);
|
||||||
|
assert(a2.raw_base() == base_buf);
|
||||||
|
assert(a2.raw_size_in_bytes() == 4u);
|
||||||
|
CHECK(*a2 == 0);
|
||||||
|
CHECK(a2[1] == 1);
|
||||||
|
|
||||||
|
SpanS base0(base_buf, 4, base_buf);
|
||||||
|
assert(base0.raw_ptr() == base_buf);
|
||||||
|
assert(base0.raw_base() == base_buf);
|
||||||
|
assert(base0.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
SpanS base4(base_buf, 4);
|
||||||
|
assert(base4.raw_ptr() == base_buf);
|
||||||
|
assert(base4.raw_base() == base_buf);
|
||||||
|
assert(base4.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
SpanS a1(base_buf, 4);
|
||||||
|
a1 = base_buf;
|
||||||
|
a1 = base0;
|
||||||
|
assert(a1 == base0);
|
||||||
|
assert(a1 != nullptr);
|
||||||
|
assert(a1.raw_ptr() == base0.raw_ptr());
|
||||||
|
assert(a1.raw_base() == base_buf);
|
||||||
|
assert(a1.raw_size_in_bytes() == 4u);
|
||||||
|
a1 = base4;
|
||||||
|
assert(a1 == base_buf);
|
||||||
|
assert(a1.raw_ptr() == base_buf);
|
||||||
|
assert(a1.raw_base() == base_buf);
|
||||||
|
assert(a1.raw_size_in_bytes() == 4u);
|
||||||
|
|
||||||
|
a1 = base_buf;
|
||||||
|
a1 = base_buf + 1;
|
||||||
|
CHECK(*a1++ == 1);
|
||||||
|
CHECK(*++a1 == 3);
|
||||||
|
CHECK(*a1 == 3);
|
||||||
|
a1 = base_buf + 4; // at the end of buffer
|
||||||
|
CHECK_THROWS(*a1);
|
||||||
|
CHECK_THROWS(a1 = base_buf + 5); // range error
|
||||||
|
assert(a1 == base_buf + 4);
|
||||||
|
CHECK(a1[-4] == 0);
|
||||||
|
CHECK_THROWS(a1[-5]); // range error
|
||||||
|
a1 = base_buf;
|
||||||
|
CHECK(*a1 == 0);
|
||||||
|
|
||||||
|
SpanS new_base4(base_buf + 2, 4);
|
||||||
|
CHECK_THROWS(a1 = new_base4); // not same base
|
||||||
|
CHECK_THROWS(a2 = new_base4); // not same base
|
||||||
|
|
||||||
|
SpanS ss_with_base(base_buf, 4, base_buf);
|
||||||
|
assert(ss_with_base.raw_base() == base_buf);
|
||||||
|
CHECK_THROWS(ss_with_base = my_null); // nullptr assignment
|
||||||
|
#if XSPAN_CONFIG_ENABLE_SPAN_CONVERSION
|
||||||
|
{
|
||||||
|
typedef PtrOrSpanOrNull<char> Span0;
|
||||||
|
// v0 nullptr, b0 base, b1 base + 1
|
||||||
|
const Span0 v0_v0(nullptr);
|
||||||
|
const Span0 v0_b0(nullptr, 4, base_buf);
|
||||||
|
const Span0 v0_b1(nullptr, 3, base_buf + 1);
|
||||||
|
const Span0 b0_v0(base_buf);
|
||||||
|
const Span0 b0_b0(base_buf, 4, base_buf);
|
||||||
|
CHECK_THROWS(XSPAN_0_MAKE(char, base_buf, 3, base_buf + 1)); // b0_b1
|
||||||
|
const Span0 b1_v0(base_buf + 1);
|
||||||
|
const Span0 b1_b0(base_buf + 1, 4, base_buf);
|
||||||
|
const Span0 b1_b1(base_buf + 1, 3, base_buf + 1);
|
||||||
|
CHECK_THROWS(ss_with_base = v0_v0); // nullptr assignment
|
||||||
|
CHECK_THROWS(ss_with_base = v0_b0); // nullptr assignment
|
||||||
|
CHECK_THROWS(ss_with_base = v0_b1); // nullptr assignment
|
||||||
|
CHECK_NOTHROW(ss_with_base = b0_v0);
|
||||||
|
CHECK_NOTHROW(ss_with_base = b0_b0);
|
||||||
|
CHECK_NOTHROW(ss_with_base = b1_v0);
|
||||||
|
CHECK_NOTHROW(ss_with_base = b1_b0);
|
||||||
|
CHECK_THROWS(ss_with_base = b1_b1); // different base
|
||||||
|
CHECK_THROWS(XSPAN_S_MAKE(char, v0_v0));
|
||||||
|
CHECK_THROWS(XSPAN_S_MAKE(char, v0_b0));
|
||||||
|
CHECK_THROWS(XSPAN_S_MAKE(char, v0_b1));
|
||||||
|
CHECK_THROWS(XSPAN_S_MAKE(char, b0_v0));
|
||||||
|
CHECK_NOTHROW(XSPAN_S_MAKE(char, b0_b0));
|
||||||
|
CHECK_THROWS(XSPAN_S_MAKE(char, b1_v0));
|
||||||
|
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b0));
|
||||||
|
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b1));
|
||||||
|
//
|
||||||
|
CHECK((XSPAN_S_MAKE(char, b0_b0).raw_base() == base_buf));
|
||||||
|
CHECK((XSPAN_S_MAKE(char, b1_b0).raw_base() == base_buf));
|
||||||
|
CHECK((XSPAN_S_MAKE(char, b1_b1).raw_base() == base_buf + 1));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef PtrOrSpan<char> SpanP;
|
||||||
|
// v0 nullptr, b0 base, b1 base + 1
|
||||||
|
const SpanP b0_v0(base_buf);
|
||||||
|
const SpanP b0_b0(base_buf, 4, base_buf);
|
||||||
|
CHECK_THROWS(XSPAN_P_MAKE(char, base_buf, 3, base_buf + 1)); // b0_b1
|
||||||
|
const SpanP b1_v0(base_buf + 1);
|
||||||
|
const SpanP b1_b0(base_buf + 1, 4, base_buf);
|
||||||
|
const SpanP b1_b1(base_buf + 1, 3, base_buf + 1);
|
||||||
|
CHECK_NOTHROW(ss_with_base = b0_v0);
|
||||||
|
CHECK_NOTHROW(ss_with_base = b0_b0);
|
||||||
|
CHECK_NOTHROW(ss_with_base = b1_v0);
|
||||||
|
CHECK_NOTHROW(ss_with_base = b1_b0);
|
||||||
|
CHECK_THROWS(ss_with_base = b1_b1); // different base
|
||||||
|
CHECK_THROWS(XSPAN_S_MAKE(char, b0_v0));
|
||||||
|
CHECK_NOTHROW(XSPAN_S_MAKE(char, b0_b0));
|
||||||
|
CHECK_THROWS(XSPAN_S_MAKE(char, b1_v0));
|
||||||
|
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b0));
|
||||||
|
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b1));
|
||||||
|
//
|
||||||
|
CHECK((XSPAN_S_MAKE(char, b0_b0).raw_base() == base_buf));
|
||||||
|
CHECK((XSPAN_S_MAKE(char, b1_b0).raw_base() == base_buf));
|
||||||
|
CHECK((XSPAN_S_MAKE(char, b1_b1).raw_base() == base_buf + 1));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
UNUSED(my_null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("Span void ptr") {
|
||||||
|
static char a[4] = {0, 1, 2, 3};
|
||||||
|
XSPAN_0(void) a0(a, 4);
|
||||||
|
XSPAN_P(void) ap(a, 4);
|
||||||
|
XSPAN_S(void) as(a, 4);
|
||||||
|
XSPAN_0(const void) c0(a, 4);
|
||||||
|
XSPAN_P(const void) cp(a, 4);
|
||||||
|
XSPAN_S(const void) cs(a, 4);
|
||||||
|
static const char b[4] = {0, 1, 2, 3};
|
||||||
|
XSPAN_0(const void) b0(b, 4);
|
||||||
|
XSPAN_P(const void) bp(b, 4);
|
||||||
|
XSPAN_S(const void) bs(b, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Span deref/array/arrow") {
|
||||||
|
static char real_a[2 + 4 + 2] = {126, 127, 0, 1, 2, 3, 124, 125};
|
||||||
|
static char *a = real_a + 2;
|
||||||
|
XSPAN_0(char) a0(a, 4);
|
||||||
|
XSPAN_P(char) ap(a, 4);
|
||||||
|
XSPAN_S(char) as(a, 4);
|
||||||
|
CHECK_THROWS(a0[4]);
|
||||||
|
CHECK_THROWS(a0[-1]);
|
||||||
|
CHECK_THROWS(a0[-2]);
|
||||||
|
a0 += 2;
|
||||||
|
CHECK(*a0 == 2);
|
||||||
|
CHECK(a0[-1] == 1);
|
||||||
|
CHECK(a0[0] == 2);
|
||||||
|
CHECK(a0[1] == 3);
|
||||||
|
ap += 2;
|
||||||
|
CHECK(*ap == 2);
|
||||||
|
CHECK(ap[-1] == 1);
|
||||||
|
CHECK(ap[0] == 2);
|
||||||
|
CHECK(ap[1] == 3);
|
||||||
|
as += 2;
|
||||||
|
CHECK(*as == 2);
|
||||||
|
CHECK(as[-1] == 1);
|
||||||
|
CHECK(as[0] == 2);
|
||||||
|
CHECK(as[1] == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Span subspan") {
|
||||||
|
static char buf[4] = {0, 1, 2, 3};
|
||||||
|
XSPAN_S(char) as(buf, 4);
|
||||||
|
CHECK(as.subspan(1, 1)[0] == 1);
|
||||||
|
CHECK((as + 1).subspan(1, 1)[0] == 2);
|
||||||
|
CHECK((as + 2).subspan(0, -2)[0] == 0);
|
||||||
|
CHECK_THROWS(as.subspan(1, 0)[0]);
|
||||||
|
CHECK_THROWS(as.subspan(1, 1)[-1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Span constness") {
|
||||||
|
static char buf[4] = {0, 1, 2, 3};
|
||||||
|
|
||||||
|
// NOLINTBEGIN(performance-unnecessary-copy-initialization)
|
||||||
|
|
||||||
|
XSPAN_0(char) b0(buf, 4);
|
||||||
|
XSPAN_P(char) bp(buf, 4);
|
||||||
|
XSPAN_S(char) bs(buf, 4);
|
||||||
|
|
||||||
|
XSPAN_0(char) s0(b0);
|
||||||
|
XSPAN_P(char) sp(bp);
|
||||||
|
XSPAN_S(char) ss(bs);
|
||||||
|
|
||||||
|
XSPAN_0(const char) b0c(buf, 4);
|
||||||
|
XSPAN_P(const char) bpc(buf, 4);
|
||||||
|
XSPAN_S(const char) bsc(buf, 4);
|
||||||
|
|
||||||
|
XSPAN_0(const char) s0c(b0c);
|
||||||
|
XSPAN_P(const char) spc(bpc);
|
||||||
|
XSPAN_S(const char) ssc(bsc);
|
||||||
|
|
||||||
|
XSPAN_0(const char) x0c(b0);
|
||||||
|
XSPAN_P(const char) xpc(bp);
|
||||||
|
XSPAN_S(const char) xsc(bs);
|
||||||
|
|
||||||
|
// NOLINTEND(performance-unnecessary-copy-initialization)
|
||||||
|
|
||||||
|
CHECK(ptr_diff_bytes(b0, buf) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(bp, buf) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(bs, buf) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(s0, buf) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(sp, buf) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(bs, buf) == 0);
|
||||||
|
//
|
||||||
|
CHECK(ptr_diff_bytes(s0, bp) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(s0, sp) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(s0, ss) == 0);
|
||||||
|
//
|
||||||
|
CHECK(ptr_diff_bytes(s0c, b0c) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(spc, bpc) == 0);
|
||||||
|
CHECK(ptr_diff_bytes(ssc, bsc) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if !defined(DOCTEST_CONFIG_DISABLE)
|
||||||
|
namespace {
|
||||||
|
int my_memcmp_v1(XSPAN_P(const void) a, XSPAN_0(const void) b, size_t n) {
|
||||||
|
if (b == nullptr)
|
||||||
|
return -2;
|
||||||
|
XSPAN_0(const void) x(a);
|
||||||
|
return memcmp(x, b, n);
|
||||||
|
}
|
||||||
|
int my_memcmp_v2(XSPAN_P(const char) a, XSPAN_0(const char) b, size_t n) {
|
||||||
|
if (a == b)
|
||||||
|
return 0;
|
||||||
|
if (b == nullptr)
|
||||||
|
return -2;
|
||||||
|
a += 1;
|
||||||
|
b -= 1;
|
||||||
|
XSPAN_0(const char) x(a);
|
||||||
|
XSPAN_0(const char) y = b;
|
||||||
|
return memcmp(x, y, n);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TEST_CASE("PtrOrSpan") {
|
||||||
|
static const char buf[4] = {0, 1, 2, 3};
|
||||||
|
CHECK(my_memcmp_v1(buf, nullptr, 4) == -2);
|
||||||
|
CHECK(my_memcmp_v2(buf + 4, buf + 4, 999) == 0);
|
||||||
|
CHECK(my_memcmp_v2(buf, buf + 2, 3) == 0);
|
||||||
|
UNUSED(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("PtrOrSpan char") {
|
||||||
|
char real_buf[2 + 8 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 6, 7, 124, 125};
|
||||||
|
char *buf = real_buf + 2;
|
||||||
|
XSPAN_P(char) a(buf, XSpanSizeInBytes(8));
|
||||||
|
XSPAN_P(char) b = a.subspan(0, 7);
|
||||||
|
XSPAN_P(char) c = (b + 1).subspan(0, 6);
|
||||||
|
a += 1;
|
||||||
|
CHECK(*a == 1);
|
||||||
|
*a++ += 1;
|
||||||
|
*b++ = 1;
|
||||||
|
CHECK(a == buf + 2);
|
||||||
|
CHECK(b == buf + 1);
|
||||||
|
CHECK(c == buf + 1);
|
||||||
|
CHECK(*b == 2);
|
||||||
|
CHECK(*c == 2);
|
||||||
|
CHECK(a.raw_size_in_bytes() == 8u);
|
||||||
|
CHECK(b.raw_size_in_bytes() == 7u);
|
||||||
|
CHECK(c.raw_size_in_bytes() == 6u);
|
||||||
|
CHECK(a.raw_base() == buf);
|
||||||
|
CHECK(b.raw_base() == buf);
|
||||||
|
CHECK(c.raw_base() == buf + 1);
|
||||||
|
#ifdef UPX_VERSION_HEX
|
||||||
|
CHECK(get_le32(a) != 0);
|
||||||
|
#endif
|
||||||
|
++c;
|
||||||
|
c++;
|
||||||
|
#ifdef UPX_VERSION_HEX
|
||||||
|
CHECK(get_le32(c) != 0);
|
||||||
|
#endif
|
||||||
|
++c;
|
||||||
|
#ifdef UPX_VERSION_HEX
|
||||||
|
CHECK_THROWS(get_le32(c));
|
||||||
|
#endif
|
||||||
|
++b;
|
||||||
|
b++;
|
||||||
|
b += 4;
|
||||||
|
CHECK(b.raw_ptr() == buf + 7);
|
||||||
|
CHECK_THROWS(*b);
|
||||||
|
CHECK(a.raw_size_in_bytes() == 8u);
|
||||||
|
a = b;
|
||||||
|
CHECK(a.raw_size_in_bytes() == 8u);
|
||||||
|
CHECK(a.raw_ptr() == buf + 7);
|
||||||
|
a++;
|
||||||
|
CHECK_THROWS(*a);
|
||||||
|
CHECK_THROWS(raw_bytes(a, 1));
|
||||||
|
a = b;
|
||||||
|
CHECK_THROWS(a = c);
|
||||||
|
*a = 0;
|
||||||
|
a = buf;
|
||||||
|
#ifdef UPX_VERSION_HEX
|
||||||
|
CHECK(upx_safe_strlen(a) == 7u);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("PtrOrSpan int") {
|
||||||
|
int buf[8] = {0, 11, 22, 33, 44, 55, 66, 77};
|
||||||
|
XSPAN_P(const int) a(buf, XSpanCount(8));
|
||||||
|
CHECK(a.raw_size_in_bytes() == 8 * sizeof(int));
|
||||||
|
XSPAN_P(const int) b = a.subspan(0, 7);
|
||||||
|
CHECK(b.raw_size_in_bytes() == 7 * sizeof(int));
|
||||||
|
XSPAN_P(const int) c = (b + 1).subspan(0, 6);
|
||||||
|
CHECK(c.raw_size_in_bytes() == 6 * sizeof(int));
|
||||||
|
a += 1;
|
||||||
|
CHECK(a == buf + 1);
|
||||||
|
CHECK(*a == 11);
|
||||||
|
CHECK(*a++ == 11);
|
||||||
|
CHECK(a == buf + 2);
|
||||||
|
CHECK(*a == 22);
|
||||||
|
CHECK(*++a == 33);
|
||||||
|
CHECK(a == buf + 3);
|
||||||
|
CHECK(*a == 33);
|
||||||
|
CHECK(*--a == 22);
|
||||||
|
CHECK(a == buf + 2);
|
||||||
|
CHECK(*a == 22);
|
||||||
|
CHECK(*a-- == 22);
|
||||||
|
CHECK(a == buf + 1);
|
||||||
|
CHECK(*a == 11);
|
||||||
|
CHECK(*b == 0);
|
||||||
|
CHECK(*c == 11);
|
||||||
|
a -= 1;
|
||||||
|
a += 7;
|
||||||
|
#ifdef UPX_VERSION_HEX
|
||||||
|
CHECK(get_le32(a) == ne32_to_le32(77));
|
||||||
|
#endif
|
||||||
|
a++;
|
||||||
|
#ifdef UPX_VERSION_HEX
|
||||||
|
CHECK_THROWS(get_le32(a));
|
||||||
|
#endif
|
||||||
|
CHECK_THROWS(raw_bytes(a, 1));
|
||||||
|
CHECK_THROWS(a++);
|
||||||
|
CHECK_THROWS(++a);
|
||||||
|
CHECK_THROWS(a += 1);
|
||||||
|
CHECK(a == buf + 8);
|
||||||
|
a = buf;
|
||||||
|
CHECK_THROWS(a--);
|
||||||
|
CHECK_THROWS(--a);
|
||||||
|
CHECK_THROWS(a -= 1);
|
||||||
|
CHECK_THROWS(a += 9);
|
||||||
|
CHECK(a == buf);
|
||||||
|
a += 8;
|
||||||
|
CHECK(a == buf + 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// codegen
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <class T>
|
||||||
|
static noinline int foo(T p) {
|
||||||
|
unsigned r = 0;
|
||||||
|
r += *p++;
|
||||||
|
r += *++p;
|
||||||
|
p += 3;
|
||||||
|
r += *p;
|
||||||
|
r += *--p;
|
||||||
|
r += *p--;
|
||||||
|
r += *p;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
XSPAN_0(T)
|
||||||
|
make_span_0(T *ptr, size_t count) {
|
||||||
|
return PtrOrSpanOrNull<T>(ptr, count);
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
XSPAN_P(T)
|
||||||
|
make_span_p(T *ptr, size_t count) {
|
||||||
|
return PtrOrSpan<T>(ptr, count);
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
XSPAN_S(T)
|
||||||
|
make_span_s(T *ptr, size_t count) {
|
||||||
|
return Span<T>(ptr, count);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST_CASE("Span codegen") {
|
||||||
|
upx_uint8_t buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||||
|
CHECK(foo(buf) == 0 + 2 + 5 + 4 + 4 + 3);
|
||||||
|
CHECK(foo(make_span_0(buf, 8)) == 0 + 2 + 5 + 4 + 4 + 3);
|
||||||
|
CHECK(foo(make_span_p(buf, 8)) == 0 + 2 + 5 + 4 + 4 + 3);
|
||||||
|
CHECK(foo(make_span_s(buf, 8)) == 0 + 2 + 5 + 4 + 4 + 3);
|
||||||
|
CHECK(foo(XSPAN_0_MAKE(upx_uint8_t, buf, 8)) == 0 + 2 + 5 + 4 + 4 + 3);
|
||||||
|
CHECK(foo(XSPAN_P_MAKE(upx_uint8_t, buf, 8)) == 0 + 2 + 5 + 4 + 4 + 3);
|
||||||
|
CHECK(foo(XSPAN_S_MAKE(upx_uint8_t, buf, 8)) == 0 + 2 + 5 + 4 + 4 + 3);
|
||||||
|
UNUSED(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WITH_XSPAN >= 2
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// misc
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <class T>
|
||||||
|
struct PointerTraits {
|
||||||
|
typedef typename std::add_lvalue_reference<T>::type reference;
|
||||||
|
typedef
|
||||||
|
typename std::add_lvalue_reference<typename std::add_const<T>::type>::type const_reference;
|
||||||
|
typedef typename std::add_pointer<T>::type pointer;
|
||||||
|
typedef typename std::add_pointer<typename std::add_const<T>::type>::type const_pointer;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
|
||||||
|
TEST_CASE("decltype integral constants") {
|
||||||
|
static_assert((std::is_same<decltype(0), int>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(0u), unsigned>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(0l), long>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(0ul), unsigned long>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(0ll), long long>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(0ull), unsigned long long>::value), "");
|
||||||
|
static_assert((std::is_same<decltype((char) 0), char>::value), "");
|
||||||
|
static_assert((std::is_same<decltype((short) 0), short>::value), "");
|
||||||
|
static_assert((std::is_same<decltype((long) 0), long>::value), "");
|
||||||
|
static_assert((std::is_same<decltype((long long) 0), long long>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(char(0)), char>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(short(0)), short>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(long(0)), long>::value), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("decltype pointer") {
|
||||||
|
int dummy = 0;
|
||||||
|
int *p = &dummy;
|
||||||
|
const int *c = &dummy;
|
||||||
|
static_assert((std::is_same<decltype(p - p), std::ptrdiff_t>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c - c), std::ptrdiff_t>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(p - c), std::ptrdiff_t>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c - p), std::ptrdiff_t>::value), "");
|
||||||
|
typedef PointerTraits<int> TInt;
|
||||||
|
typedef PointerTraits<const int> TConstInt;
|
||||||
|
static_assert((std::is_same<int *, TInt::pointer>::value), "");
|
||||||
|
static_assert((std::is_same<const int *, TInt::const_pointer>::value), "");
|
||||||
|
static_assert((std::is_same<const int *, TConstInt::pointer>::value), "");
|
||||||
|
static_assert((std::is_same<const int *, TConstInt::const_pointer>::value), "");
|
||||||
|
//
|
||||||
|
static_assert((std::is_same<decltype(p), TInt::pointer>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c), TInt::const_pointer>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c), TConstInt::pointer>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(p + 1), TInt::pointer>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c + 1), TInt::const_pointer>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c + 1), TConstInt::pointer>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c + 1), TConstInt::const_pointer>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c + 1), const int *>::value), "");
|
||||||
|
// dereference
|
||||||
|
static_assert((std::is_same<decltype(*p), TInt::reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*c), TInt::const_reference>::value), "");
|
||||||
|
#if 0
|
||||||
|
// this works, but avoid clang warnings:
|
||||||
|
// "Expression with side effects has no effect in an unevaluated context"
|
||||||
|
static_assert((std::is_same<decltype(*p++), TInt::reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*++p), TInt::reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*c++), TInt::const_reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*c++), TConstInt::reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*c++), TConstInt::const_reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*++c), TInt::const_reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*++c), TConstInt::reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(*++c), TConstInt::const_reference>::value), "");
|
||||||
|
#endif
|
||||||
|
// array access
|
||||||
|
static_assert((std::is_same<decltype(p[0]), TInt::reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c[0]), TInt::const_reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c[0]), TConstInt::reference>::value), "");
|
||||||
|
static_assert((std::is_same<decltype(c[0]), TConstInt::const_reference>::value), "");
|
||||||
|
UNUSED(p);
|
||||||
|
UNUSED(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __cplusplus >= 201103L
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -21,22 +20,19 @@
|
|||||||
If not, write to the Free Software Foundation, Inc.,
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
Markus F.X.J. Oberhumer
|
||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
#include "conf.h"
|
|
||||||
#include "compress.h"
|
#include "compress.h"
|
||||||
#include "util/membuffer.h"
|
#include "../util/membuffer.h"
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
|
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler) {
|
||||||
{
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return adler;
|
return adler;
|
||||||
assert(buf != nullptr);
|
assert(buf != nullptr);
|
||||||
@@ -47,8 +43,7 @@ unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0 // UNUSED
|
||||||
#if 0 /* UNUSED */
|
|
||||||
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
|
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
|
||||||
{
|
{
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
@@ -60,24 +55,20 @@ unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
|
|||||||
return upx_zlib_crc32(buf, len, crc);
|
return upx_zlib_crc32(buf, len, crc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* UNUSED */
|
#endif // UNUSED
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_compress( const upx_bytep src, unsigned src_len,
|
int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
upx_bytep dst, unsigned* dst_len,
|
upx_callback_t *cb, int method, int level, const upx_compress_config_t *cconf,
|
||||||
upx_callback_p cb,
|
upx_compress_result_t *cresult) {
|
||||||
int method, int level,
|
|
||||||
const upx_compress_config_t *cconf,
|
|
||||||
upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
int r = UPX_E_ERROR;
|
int r = UPX_E_ERROR;
|
||||||
upx_compress_result_t cresult_buffer;
|
upx_compress_result_t cresult_buffer;
|
||||||
|
|
||||||
assert(method > 0); assert(level > 0);
|
assert(method > 0);
|
||||||
|
assert(level > 0);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
// set available bytes in dst
|
// set available bytes in dst
|
||||||
@@ -87,68 +78,76 @@ int upx_compress( const upx_bytep src, unsigned src_len,
|
|||||||
// force users to provide *dst_len
|
// force users to provide *dst_len
|
||||||
assert(*dst_len != 0);
|
assert(*dst_len != 0);
|
||||||
#endif
|
#endif
|
||||||
// for UPX, we always require a reasonably sized outbut buffer
|
// for UPX, we always require a reasonably sized output buffer
|
||||||
assert(*dst_len >= MemBuffer::getSizeForCompression(src_len));
|
assert(*dst_len >= MemBuffer::getSizeForCompression(src_len));
|
||||||
|
|
||||||
if (!cresult)
|
if (!cresult)
|
||||||
cresult = &cresult_buffer;
|
cresult = &cresult_buffer;
|
||||||
memset(cresult, 0, sizeof(*cresult));
|
cresult->reset();
|
||||||
#if 1
|
#if 1
|
||||||
// debug
|
// debugging aid
|
||||||
cresult->method = method;
|
cresult->debug.method = method;
|
||||||
cresult->level = level;
|
cresult->debug.level = level;
|
||||||
cresult->u_len = src_len;
|
cresult->debug.u_len = src_len;
|
||||||
cresult->c_len = 0;
|
cresult->debug.c_len = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if __acc_cte(0) {
|
const unsigned orig_dst_len = *dst_len;
|
||||||
|
if (__acc_cte(false)) {
|
||||||
}
|
}
|
||||||
|
#if (WITH_BZIP2)
|
||||||
|
else if (M_IS_BZIP2(method))
|
||||||
|
r = upx_bzip2_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
|
||||||
|
#endif
|
||||||
#if (WITH_LZMA)
|
#if (WITH_LZMA)
|
||||||
else if (M_IS_LZMA(method))
|
else if (M_IS_LZMA(method))
|
||||||
r = upx_lzma_compress(src, src_len, dst, dst_len,
|
r = upx_lzma_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
|
||||||
cb, method, level, cconf, cresult);
|
|
||||||
#endif
|
#endif
|
||||||
#if (WITH_NRV)
|
#if (WITH_NRV)
|
||||||
else if ((M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) && !opt->prefer_ucl)
|
else if ((M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) && !opt->prefer_ucl)
|
||||||
r = upx_nrv_compress(src, src_len, dst, dst_len,
|
r = upx_nrv_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
|
||||||
cb, method, level, cconf, cresult);
|
|
||||||
#endif
|
#endif
|
||||||
#if (WITH_UCL)
|
#if (WITH_UCL)
|
||||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||||
r = upx_ucl_compress(src, src_len, dst, dst_len,
|
r = upx_ucl_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
|
||||||
cb, method, level, cconf, cresult);
|
#endif
|
||||||
|
#if (WITH_ZSTD)
|
||||||
|
else if (M_IS_ZSTD(method))
|
||||||
|
r = upx_zstd_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
throwInternalError("unknown compression method");
|
throwInternalError("unknown compression method %d", method);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
// debug
|
// debugging aid
|
||||||
cresult->c_len = *dst_len;
|
cresult->debug.c_len = *dst_len;
|
||||||
#endif
|
#endif
|
||||||
|
assert_noexcept(*dst_len <= orig_dst_len);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_decompress(const upx_bytep src, unsigned src_len,
|
int upx_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
upx_bytep dst, unsigned* dst_len,
|
int method, const upx_compress_result_t *cresult) {
|
||||||
int method,
|
|
||||||
const upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
int r = UPX_E_ERROR;
|
int r = UPX_E_ERROR;
|
||||||
|
|
||||||
assert(*dst_len > 0);
|
assert(*dst_len > 0);
|
||||||
assert(src_len < *dst_len); // must be compressed
|
assert(src_len < *dst_len); // must be compressed
|
||||||
|
|
||||||
if (cresult && cresult->method == 0)
|
if (cresult && cresult->debug.method == 0)
|
||||||
cresult = nullptr;
|
cresult = nullptr;
|
||||||
|
|
||||||
if __acc_cte(0) {
|
const unsigned orig_dst_len = *dst_len;
|
||||||
|
if (__acc_cte(false)) {
|
||||||
}
|
}
|
||||||
|
#if (WITH_BZIP2)
|
||||||
|
else if (M_IS_BZIP2(method))
|
||||||
|
r = upx_bzip2_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||||
|
#endif
|
||||||
#if (WITH_LZMA)
|
#if (WITH_LZMA)
|
||||||
else if (M_IS_LZMA(method))
|
else if (M_IS_LZMA(method))
|
||||||
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
|
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||||
@@ -164,29 +163,28 @@ int upx_decompress(const upx_bytep src, unsigned src_len,
|
|||||||
#if (WITH_ZLIB)
|
#if (WITH_ZLIB)
|
||||||
else if (M_IS_DEFLATE(method))
|
else if (M_IS_DEFLATE(method))
|
||||||
r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult);
|
r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||||
|
#endif
|
||||||
|
#if (WITH_ZSTD)
|
||||||
|
else if (M_IS_ZSTD(method))
|
||||||
|
r = upx_zstd_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
throwInternalError("unknown decompression method");
|
throwInternalError("unknown compression method %d", method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_noexcept(*dst_len <= orig_dst_len);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_test_overlap( const upx_bytep buf,
|
int upx_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off, unsigned src_len,
|
||||||
const upx_bytep tbuf,
|
unsigned *dst_len, int method, const upx_compress_result_t *cresult) {
|
||||||
unsigned src_off, unsigned src_len,
|
|
||||||
unsigned* dst_len,
|
|
||||||
int method,
|
|
||||||
const upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
int r = UPX_E_ERROR;
|
int r = UPX_E_ERROR;
|
||||||
|
|
||||||
if (cresult && cresult->method == 0)
|
if (cresult && cresult->debug.method == 0)
|
||||||
cresult = nullptr;
|
cresult = nullptr;
|
||||||
|
|
||||||
assert(*dst_len > 0);
|
assert(*dst_len > 0);
|
||||||
@@ -194,8 +192,13 @@ int upx_test_overlap( const upx_bytep buf,
|
|||||||
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
||||||
assert((int) overlap_overhead > 0);
|
assert((int) overlap_overhead > 0);
|
||||||
|
|
||||||
if __acc_cte(0) {
|
const unsigned orig_dst_len = *dst_len;
|
||||||
|
if (__acc_cte(false)) {
|
||||||
}
|
}
|
||||||
|
#if (WITH_BZIP2)
|
||||||
|
else if (M_IS_BZIP2(method))
|
||||||
|
r = upx_bzip2_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||||
|
#endif
|
||||||
#if (WITH_LZMA)
|
#if (WITH_LZMA)
|
||||||
else if (M_IS_LZMA(method))
|
else if (M_IS_LZMA(method))
|
||||||
r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||||
@@ -207,11 +210,16 @@ int upx_test_overlap( const upx_bytep buf,
|
|||||||
#if (WITH_UCL)
|
#if (WITH_UCL)
|
||||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||||
r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||||
|
#endif
|
||||||
|
#if (WITH_ZSTD)
|
||||||
|
else if (M_IS_ZSTD(method))
|
||||||
|
r = upx_zstd_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
throwInternalError("unknown decompression method");
|
throwInternalError("unknown compression method %d", method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_noexcept(*dst_len <= orig_dst_len);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -21,25 +20,45 @@
|
|||||||
If not, write to the Free Software Foundation, Inc.,
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
Markus F.X.J. Oberhumer
|
||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#ifndef __UPX_COMPRESS_H
|
// clang-format off
|
||||||
#define __UPX_COMPRESS_H 1
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if (WITH_BZIP2)
|
||||||
|
int upx_bzip2_init(void);
|
||||||
|
const char *upx_bzip2_version_string(void);
|
||||||
|
int upx_bzip2_compress ( const upx_bytep src, unsigned src_len,
|
||||||
|
upx_bytep dst, unsigned *dst_len,
|
||||||
|
upx_callback_t *cb,
|
||||||
|
int method, int level,
|
||||||
|
const upx_compress_config_t *cconf,
|
||||||
|
upx_compress_result_t *cresult );
|
||||||
|
int upx_bzip2_decompress ( const upx_bytep src, unsigned src_len,
|
||||||
|
upx_bytep dst, unsigned *dst_len,
|
||||||
|
int method,
|
||||||
|
const upx_compress_result_t *cresult );
|
||||||
|
int upx_bzip2_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 (WITH_LZMA)
|
#if (WITH_LZMA)
|
||||||
int upx_lzma_init(void);
|
int upx_lzma_init(void);
|
||||||
const char *upx_lzma_version_string(void);
|
const char *upx_lzma_version_string(void);
|
||||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||||
upx_bytep dst, unsigned *dst_len,
|
upx_bytep dst, unsigned *dst_len,
|
||||||
upx_callback_p cb,
|
upx_callback_t *cb,
|
||||||
int method, int level,
|
int method, int level,
|
||||||
const upx_compress_config_t *cconf,
|
const upx_compress_config_t *cconf,
|
||||||
upx_compress_result_t *cresult );
|
upx_compress_result_t *cresult );
|
||||||
@@ -55,13 +74,12 @@ int upx_lzma_test_overlap ( const upx_bytep buf,
|
|||||||
const upx_compress_result_t *cresult );
|
const upx_compress_result_t *cresult );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if (WITH_NRV)
|
#if (WITH_NRV)
|
||||||
int upx_nrv_init(void);
|
int upx_nrv_init(void);
|
||||||
const char *upx_nrv_version_string(void);
|
const char *upx_nrv_version_string(void);
|
||||||
int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
|
int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
|
||||||
upx_bytep dst, unsigned *dst_len,
|
upx_bytep dst, unsigned *dst_len,
|
||||||
upx_callback_p cb,
|
upx_callback_t *cb,
|
||||||
int method, int level,
|
int method, int level,
|
||||||
const upx_compress_config_t *cconf,
|
const upx_compress_config_t *cconf,
|
||||||
upx_compress_result_t *cresult );
|
upx_compress_result_t *cresult );
|
||||||
@@ -77,13 +95,12 @@ int upx_nrv_test_overlap ( const upx_bytep buf,
|
|||||||
const upx_compress_result_t *cresult );
|
const upx_compress_result_t *cresult );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if (WITH_UCL)
|
#if (WITH_UCL)
|
||||||
int upx_ucl_init(void);
|
int upx_ucl_init(void);
|
||||||
const char *upx_ucl_version_string(void);
|
const char *upx_ucl_version_string(void);
|
||||||
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||||
upx_bytep dst, unsigned *dst_len,
|
upx_bytep dst, unsigned *dst_len,
|
||||||
upx_callback_p cb,
|
upx_callback_t *cb,
|
||||||
int method, int level,
|
int method, int level,
|
||||||
const upx_compress_config_t *cconf,
|
const upx_compress_config_t *cconf,
|
||||||
upx_compress_result_t *cresult );
|
upx_compress_result_t *cresult );
|
||||||
@@ -101,13 +118,12 @@ unsigned upx_ucl_adler32(const void *buf, unsigned len, unsigned adler);
|
|||||||
unsigned upx_ucl_crc32 (const void *buf, unsigned len, unsigned crc);
|
unsigned upx_ucl_crc32 (const void *buf, unsigned len, unsigned crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if (WITH_ZLIB)
|
#if (WITH_ZLIB)
|
||||||
int upx_zlib_init(void);
|
int upx_zlib_init(void);
|
||||||
const char *upx_zlib_version_string(void);
|
const char *upx_zlib_version_string(void);
|
||||||
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
|
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
|
||||||
upx_bytep dst, unsigned *dst_len,
|
upx_bytep dst, unsigned *dst_len,
|
||||||
upx_callback_p cb,
|
upx_callback_t *cb,
|
||||||
int method, int level,
|
int method, int level,
|
||||||
const upx_compress_config_t *cconf,
|
const upx_compress_config_t *cconf,
|
||||||
upx_compress_result_t *cresult );
|
upx_compress_result_t *cresult );
|
||||||
@@ -125,7 +141,25 @@ unsigned upx_zlib_adler32(const void *buf, unsigned len, unsigned adler);
|
|||||||
unsigned upx_zlib_crc32 (const void *buf, unsigned len, unsigned crc);
|
unsigned upx_zlib_crc32 (const void *buf, unsigned len, unsigned crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (WITH_ZSTD)
|
||||||
#endif /* already included */
|
int upx_zstd_init(void);
|
||||||
|
const char *upx_zstd_version_string(void);
|
||||||
|
int upx_zstd_compress ( const upx_bytep src, unsigned src_len,
|
||||||
|
upx_bytep dst, unsigned *dst_len,
|
||||||
|
upx_callback_t *cb,
|
||||||
|
int method, int level,
|
||||||
|
const upx_compress_config_t *cconf,
|
||||||
|
upx_compress_result_t *cresult );
|
||||||
|
int upx_zstd_decompress ( const upx_bytep src, unsigned src_len,
|
||||||
|
upx_bytep dst, unsigned *dst_len,
|
||||||
|
int method,
|
||||||
|
const upx_compress_result_t *cresult );
|
||||||
|
int upx_zstd_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
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -0,0 +1,208 @@
|
|||||||
|
/* compress_bzip2.cpp --
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
|
|
||||||
|
void bzip2_compress_config_t::reset() noexcept { mem_clear(this); }
|
||||||
|
|
||||||
|
#if WITH_BZIP2
|
||||||
|
#include "compress.h"
|
||||||
|
#include "../util/membuffer.h"
|
||||||
|
#include <bzip2/bzlib.h>
|
||||||
|
|
||||||
|
#if defined(BZ_NO_STDIO) || 1
|
||||||
|
// we need to supply bz_internal_error() when building with BZ_NO_STDIO
|
||||||
|
extern "C" {
|
||||||
|
extern void bz_internal_error(int);
|
||||||
|
void bz_internal_error(int errcode) { throwInternalError("bz_internal_error %d", errcode); }
|
||||||
|
}
|
||||||
|
#endif // BZ_NO_STDIO
|
||||||
|
|
||||||
|
static int convert_errno_from_bzip2(int r) {
|
||||||
|
switch (r) {
|
||||||
|
case BZ_OK:
|
||||||
|
return UPX_E_OK;
|
||||||
|
case BZ_MEM_ERROR:
|
||||||
|
return UPX_E_OUT_OF_MEMORY;
|
||||||
|
// TODO later: convert to UPX_E_INPUT_OVERRUN, UPX_E_OUTPUT_OVERRUN
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_bzip2_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
|
upx_callback_t *cb_parm, int method, int level,
|
||||||
|
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
|
||||||
|
assert(method == M_BZIP2);
|
||||||
|
assert(level > 0);
|
||||||
|
assert(cresult != nullptr);
|
||||||
|
UNUSED(cb_parm);
|
||||||
|
int r = UPX_E_ERROR;
|
||||||
|
const bzip2_compress_config_t *const lcconf = cconf_parm ? &cconf_parm->conf_bzip2 : nullptr;
|
||||||
|
bzip2_compress_result_t *const res = &cresult->result_bzip2;
|
||||||
|
res->reset();
|
||||||
|
|
||||||
|
int blockSize100k = (src_len + 100000 - 1) / 100000;
|
||||||
|
if (blockSize100k < 1)
|
||||||
|
blockSize100k = 1;
|
||||||
|
if (blockSize100k > 9)
|
||||||
|
blockSize100k = 9;
|
||||||
|
// idea for later: could enhance lcconf to allow setting blockSize100k
|
||||||
|
UNUSED(lcconf);
|
||||||
|
if (level <= 3 && blockSize100k > level)
|
||||||
|
blockSize100k = level;
|
||||||
|
|
||||||
|
char *dest = (char *) dst;
|
||||||
|
char *source = (char *) const_cast<byte *>(src);
|
||||||
|
r = BZ2_bzBuffToBuffCompress(dest, dst_len, source, src_len, blockSize100k, 0, 0);
|
||||||
|
return convert_errno_from_bzip2(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_bzip2_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
|
int method, const upx_compress_result_t *cresult) {
|
||||||
|
assert(method == M_BZIP2);
|
||||||
|
UNUSED(method);
|
||||||
|
UNUSED(cresult);
|
||||||
|
char *dest = (char *) dst;
|
||||||
|
char *source = (char *) const_cast<byte *>(src);
|
||||||
|
int small = 0;
|
||||||
|
int r = BZ2_bzBuffToBuffDecompress(dest, dst_len, source, src_len, small, 0);
|
||||||
|
return convert_errno_from_bzip2(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// test_overlap - see <ucl/ucl.h> for semantics
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_bzip2_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_BZIP2);
|
||||||
|
|
||||||
|
MemBuffer b(src_off + src_len);
|
||||||
|
memcpy(b + src_off, buf + src_off, src_len);
|
||||||
|
unsigned saved_dst_len = *dst_len;
|
||||||
|
int r = upx_bzip2_decompress(raw_index_bytes(b, src_off, src_len), src_len,
|
||||||
|
raw_bytes(b, *dst_len), 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, so we use an extra memcmp().
|
||||||
|
if (tbuf != nullptr && memcmp(tbuf, b, *dst_len) != 0)
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
return UPX_E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// misc
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_bzip2_init(void) { return 0; }
|
||||||
|
|
||||||
|
const char *upx_bzip2_version_string(void) { return BZ2_bzlibVersion(); }
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// doctest checks
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if DEBUG && !defined(DOCTEST_CONFIG_DISABLE) && 1
|
||||||
|
|
||||||
|
static bool check_bzip2(const int method, const int level, const unsigned expected_c_len) {
|
||||||
|
const unsigned u_len = 16384;
|
||||||
|
const unsigned c_extra = 4096;
|
||||||
|
MemBuffer u_buf, c_buf, d_buf;
|
||||||
|
unsigned c_len, d_len;
|
||||||
|
upx_compress_result_t cresult;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
u_buf.alloc(u_len);
|
||||||
|
memset(u_buf, 0, u_len);
|
||||||
|
c_buf.allocForCompression(u_len, c_extra);
|
||||||
|
d_buf.allocForDecompression(u_len);
|
||||||
|
|
||||||
|
c_len = c_buf.getSize() - c_extra;
|
||||||
|
r = upx_bzip2_compress(raw_bytes(u_buf, u_len), u_len, raw_index_bytes(c_buf, c_extra, c_len),
|
||||||
|
&c_len, nullptr, method, level, NULL_cconf, &cresult);
|
||||||
|
if (r != 0 || c_len != expected_c_len)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
d_len = d_buf.getSize();
|
||||||
|
r = upx_bzip2_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
|
&d_len, method, nullptr);
|
||||||
|
if (r != 0 || d_len != u_len || memcmp(u_buf, d_buf, u_len) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
d_len = u_len - 1;
|
||||||
|
r = upx_bzip2_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
|
&d_len, method, nullptr);
|
||||||
|
if (r == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
|
||||||
|
// unsigned x_len = d_len;
|
||||||
|
// r = upx_bzip2_test_overlap(c_buf, u_buf, c_extra, c_len, &x_len, method, nullptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("compress_bzip2") { CHECK(check_bzip2(M_BZIP2, 9, 46)); }
|
||||||
|
|
||||||
|
#endif // DEBUG
|
||||||
|
|
||||||
|
TEST_CASE("upx_bzip2_decompress") {
|
||||||
|
#if 0 // TODO later, see above
|
||||||
|
const byte *c_data;
|
||||||
|
byte d_buf[32];
|
||||||
|
unsigned d_len;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
c_data = (const byte *) "\x28\xb5\x2f\xfd\x20\x20\x3d\x00\x00\x08\xff\x01\x00\x34\x4e\x08";
|
||||||
|
d_len = 32;
|
||||||
|
r = upx_bzip2_decompress(c_data, 16, d_buf, &d_len, M_BZIP2, nullptr);
|
||||||
|
CHECK((r == 0 && d_len == 32));
|
||||||
|
r = upx_bzip2_decompress(c_data, 15, d_buf, &d_len, M_BZIP2, nullptr);
|
||||||
|
CHECK(r == UPX_E_INPUT_OVERRUN);
|
||||||
|
d_len = 31;
|
||||||
|
r = upx_bzip2_decompress(c_data, 16, d_buf, &d_len, M_BZIP2, nullptr);
|
||||||
|
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||||
|
UNUSED(r);
|
||||||
|
#endif // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WITH_BZIP2
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -21,14 +20,13 @@
|
|||||||
If not, write to the Free Software Foundation, Inc.,
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
Markus F.X.J. Oberhumer
|
||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
#include "conf.h"
|
|
||||||
#include "compress.h"
|
#include "compress.h"
|
||||||
#include "util/membuffer.h"
|
#include "../util/membuffer.h"
|
||||||
|
|
||||||
#if (ACC_CC_CLANG)
|
#if (ACC_CC_CLANG)
|
||||||
#pragma clang diagnostic ignored "-Wshadow"
|
#pragma clang diagnostic ignored "-Wshadow"
|
||||||
@@ -42,13 +40,8 @@
|
|||||||
#if (ACC_CC_MSC && (_MSC_VER < 1900))
|
#if (ACC_CC_MSC && (_MSC_VER < 1900))
|
||||||
#pragma warning(disable : 4127) // warning C4127: conditional expression is constant
|
#pragma warning(disable : 4127) // warning C4127: conditional expression is constant
|
||||||
#endif
|
#endif
|
||||||
#if (ACC_CC_INTELC_GNUC)
|
|
||||||
# pragma warning(error: 424) // #424: extra ";" ignored
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
void lzma_compress_config_t::reset() noexcept {
|
||||||
void lzma_compress_config_t::reset()
|
|
||||||
{
|
|
||||||
pos_bits.reset();
|
pos_bits.reset();
|
||||||
lit_pos_bits.reset();
|
lit_pos_bits.reset();
|
||||||
lit_context_bits.reset();
|
lit_context_bits.reset();
|
||||||
@@ -60,7 +53,6 @@ void lzma_compress_config_t::reset()
|
|||||||
max_num_probs = 0;
|
max_num_probs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// INFO: the LZMA SDK is covered by a permissive license which allows
|
// INFO: the LZMA SDK is covered by a permissive license which allows
|
||||||
// using unmodified LZMA source code in UPX and the UPX stubs.
|
// using unmodified LZMA source code in UPX and the UPX stubs.
|
||||||
// See SPECIAL EXCEPTION below.
|
// See SPECIAL EXCEPTION below.
|
||||||
@@ -97,21 +89,18 @@ void lzma_compress_config_t::reset()
|
|||||||
// SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
|
// SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
|
||||||
// while you keep LZMA SDK code unmodified.
|
// while you keep LZMA SDK code unmodified.
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// compress defaults
|
// compress defaults
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int prepare(lzma_compress_result_t *res,
|
static bool prepare_result(lzma_compress_result_t *res, unsigned src_len, int method, int level,
|
||||||
unsigned src_len, int method, int level,
|
const lzma_compress_config_t *lcconf) {
|
||||||
const lzma_compress_config_t *lcconf)
|
|
||||||
{
|
|
||||||
// setup defaults
|
// setup defaults
|
||||||
res->pos_bits = 2; // 0 .. 4
|
res->pos_bits = 2; // 0 .. 4
|
||||||
res->lit_pos_bits = 0; // 0 .. 4
|
res->lit_pos_bits = 0; // 0 .. 4
|
||||||
res->lit_context_bits = 3; // 0 .. 8
|
res->lit_context_bits = 3; // 0 .. 8
|
||||||
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
|
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
|
||||||
res->fast_mode = 2;
|
res->fast_mode = 2; // 0 .. 2
|
||||||
res->num_fast_bytes = 64; // 5 .. 273
|
res->num_fast_bytes = 64; // 5 .. 273
|
||||||
res->match_finder_cycles = 0;
|
res->match_finder_cycles = 0;
|
||||||
// UPX overrides
|
// UPX overrides
|
||||||
@@ -127,7 +116,7 @@ static int prepare(lzma_compress_result_t *res,
|
|||||||
res->lit_context_bits = (method >> 8) & 15;
|
res->lit_context_bits = (method >> 8) & 15;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
// DEBUG - set sizes so that we use a maximum amount of stack.
|
||||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||||
// need about 6 MiB of stack during runtime decompression.
|
// need about 6 MiB of stack during runtime decompression.
|
||||||
res->lit_pos_bits = 4;
|
res->lit_pos_bits = 4;
|
||||||
@@ -135,8 +124,7 @@ static int prepare(lzma_compress_result_t *res,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: tune these settings according to level
|
// TODO: tune these settings according to level
|
||||||
switch (level)
|
switch (level) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
res->dict_size = 256 * 1024;
|
res->dict_size = 256 * 1024;
|
||||||
res->fast_mode = 0;
|
res->fast_mode = 0;
|
||||||
@@ -169,8 +157,7 @@ static int prepare(lzma_compress_result_t *res,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cconf overrides
|
// cconf overrides
|
||||||
if (lcconf)
|
if (lcconf) {
|
||||||
{
|
|
||||||
oassign(res->pos_bits, lcconf->pos_bits);
|
oassign(res->pos_bits, lcconf->pos_bits);
|
||||||
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
|
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
|
||||||
oassign(res->lit_context_bits, lcconf->lit_context_bits);
|
oassign(res->lit_context_bits, lcconf->lit_context_bits);
|
||||||
@@ -183,21 +170,16 @@ static int prepare(lzma_compress_result_t *res,
|
|||||||
res->dict_size = src_len;
|
res->dict_size = src_len;
|
||||||
|
|
||||||
// limit num_probs
|
// limit num_probs
|
||||||
if (lcconf && lcconf->max_num_probs)
|
if (lcconf && lcconf->max_num_probs) {
|
||||||
{
|
for (;;) {
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
unsigned n = 1846 + (768u << (res->lit_context_bits + res->lit_pos_bits));
|
unsigned n = 1846 + (768u << (res->lit_context_bits + res->lit_pos_bits));
|
||||||
if (n <= lcconf->max_num_probs)
|
if (n <= lcconf->max_num_probs)
|
||||||
break;
|
break;
|
||||||
if (res->lit_pos_bits > res->lit_context_bits)
|
if (res->lit_pos_bits > res->lit_context_bits) {
|
||||||
{
|
|
||||||
if (res->lit_pos_bits == 0)
|
if (res->lit_pos_bits == 0)
|
||||||
goto error;
|
goto error;
|
||||||
res->lit_pos_bits -= 1;
|
res->lit_pos_bits -= 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (res->lit_context_bits == 0)
|
if (res->lit_context_bits == 0)
|
||||||
goto error;
|
goto error;
|
||||||
res->lit_context_bits -= 1;
|
res->lit_context_bits -= 1;
|
||||||
@@ -212,95 +194,115 @@ static int prepare(lzma_compress_result_t *res,
|
|||||||
lzma_compress_config_t::num_fast_bytes_t::assertValue(res->num_fast_bytes);
|
lzma_compress_config_t::num_fast_bytes_t::assertValue(res->num_fast_bytes);
|
||||||
|
|
||||||
res->num_probs = 1846 + (768u << (res->lit_context_bits + res->lit_pos_bits));
|
res->num_probs = 1846 + (768u << (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);
|
NO_printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits,
|
||||||
return 0;
|
res->lit_context_bits, res->dict_size, res->num_probs);
|
||||||
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// compress - cruft because of pseudo-COM layer
|
// compress - cruft because of pseudo-COM layer
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// ensure proper nullptr usage
|
||||||
|
// TODO later: examine why we need this in the first place
|
||||||
|
#undef NULL
|
||||||
|
// NOLINTBEGIN(clang-analyzer-optin.cplusplus.*)
|
||||||
|
#define NULL nullptr
|
||||||
|
// NOLINTEND(clang-analyzer-optin.cplusplus.*)
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#undef __null
|
||||||
|
#define __null nullptr
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef MSDOS
|
#undef MSDOS
|
||||||
#undef OS2
|
#undef OS2
|
||||||
#undef _WIN32
|
#undef _WIN32
|
||||||
#undef _WIN32_WCE
|
#undef _WIN32_WCE
|
||||||
#undef COMPRESS_MF_MT
|
#undef COMPRESS_MF_MT
|
||||||
#undef _NO_EXCEPTIONS
|
#undef _NO_EXCEPTIONS
|
||||||
#undef NULL
|
|
||||||
#define NULL nullptr
|
|
||||||
#include <lzma-sdk/C/Common/MyInitGuid.h>
|
#include <lzma-sdk/C/Common/MyInitGuid.h>
|
||||||
// #include <lzma-sdk/C/7zip/Compress/LZMA/LZMADecoder.h>
|
// #include <lzma-sdk/C/7zip/Compress/LZMA/LZMADecoder.h>
|
||||||
#include <lzma-sdk/C/7zip/Compress/LZMA/LZMAEncoder.h>
|
#include <lzma-sdk/C/7zip/Compress/LZMA/LZMAEncoder.h>
|
||||||
|
|
||||||
namespace MyLzma {
|
namespace MyLzma {
|
||||||
|
|
||||||
struct InStream: public ISequentialInStream, public CMyUnknownImp
|
struct InStream final : public ISequentialInStream, public CMyUnknownImp {
|
||||||
{
|
|
||||||
virtual ~InStream() {}
|
virtual ~InStream() {}
|
||||||
MY_UNKNOWN_IMP
|
MY_UNKNOWN_IMP
|
||||||
const Byte *b_buf; size_t b_size; size_t b_pos;
|
const Byte *b_buf = nullptr;
|
||||||
|
size_t b_size;
|
||||||
|
size_t b_pos;
|
||||||
void Init(const Byte *data, size_t size) {
|
void Init(const Byte *data, size_t size) {
|
||||||
b_buf = data; b_size = size; b_pos = 0;
|
b_buf = data;
|
||||||
|
b_size = size;
|
||||||
|
b_pos = 0;
|
||||||
}
|
}
|
||||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) override;
|
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize) {
|
||||||
{
|
|
||||||
size_t remain = b_size - b_pos;
|
size_t remain = b_size - b_pos;
|
||||||
if (size > remain) size = (UInt32) remain;
|
if (size > remain)
|
||||||
|
size = (UInt32) remain;
|
||||||
memmove(data, b_buf + b_pos, size);
|
memmove(data, b_buf + b_pos, size);
|
||||||
b_pos += size;
|
b_pos += size;
|
||||||
if (processedSize != nullptr) *processedSize = size;
|
if (processedSize != nullptr)
|
||||||
|
*processedSize = size;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OutStream : public ISequentialOutStream, public CMyUnknownImp
|
struct OutStream final : public ISequentialOutStream, public CMyUnknownImp {
|
||||||
{
|
|
||||||
virtual ~OutStream() {}
|
virtual ~OutStream() {}
|
||||||
MY_UNKNOWN_IMP
|
MY_UNKNOWN_IMP
|
||||||
Byte *b_buf; size_t b_size; size_t b_pos; bool overflow;
|
Byte *b_buf = nullptr;
|
||||||
|
size_t b_size;
|
||||||
|
size_t b_pos;
|
||||||
|
bool overflow;
|
||||||
void Init(Byte *data, size_t size) {
|
void Init(Byte *data, size_t size) {
|
||||||
b_buf = data; b_size = size; b_pos = 0; overflow = false;
|
b_buf = data;
|
||||||
|
b_size = size;
|
||||||
|
b_pos = 0;
|
||||||
|
overflow = false;
|
||||||
}
|
}
|
||||||
HRESULT WriteByte(Byte c) {
|
HRESULT WriteByte(Byte c) {
|
||||||
if (b_pos >= b_size) { overflow = true; return E_FAIL; }
|
if (b_pos >= b_size) {
|
||||||
|
overflow = true;
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
b_buf[b_pos++] = c;
|
b_buf[b_pos++] = c;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) override;
|
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) {
|
||||||
{
|
|
||||||
size_t remain = b_size - b_pos;
|
size_t remain = b_size - b_pos;
|
||||||
if (size > remain) size = (UInt32) remain, overflow = true;
|
if (size > remain)
|
||||||
|
size = (UInt32) remain, overflow = true;
|
||||||
memmove(b_buf + b_pos, data, size);
|
memmove(b_buf + b_pos, data, size);
|
||||||
b_pos += size;
|
b_pos += size;
|
||||||
if (processedSize != nullptr) *processedSize = size;
|
if (processedSize != nullptr)
|
||||||
|
*processedSize = size;
|
||||||
return overflow ? E_FAIL : S_OK;
|
return overflow ? E_FAIL : S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
|
struct ProgressInfo final : public ICompressProgressInfo, public CMyUnknownImp {
|
||||||
{
|
|
||||||
virtual ~ProgressInfo() {}
|
virtual ~ProgressInfo() {}
|
||||||
MY_UNKNOWN_IMP
|
MY_UNKNOWN_IMP
|
||||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) override;
|
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) override;
|
||||||
upx_callback_p cb;
|
upx_callback_t *cb = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
|
STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) {
|
||||||
{
|
|
||||||
if (cb && cb->nprogress)
|
if (cb && cb->nprogress)
|
||||||
cb->nprogress(cb, (unsigned) *inSize, (unsigned) *outSize);
|
cb->nprogress(cb, (unsigned) *inSize, (unsigned) *outSize);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace MyLzma
|
||||||
|
|
||||||
#include <lzma-sdk/C/Common/Alloc.cpp>
|
#include <lzma-sdk/C/Common/Alloc.cpp>
|
||||||
#include <lzma-sdk/C/Common/CRC.cpp>
|
#include <lzma-sdk/C/Common/CRC.cpp>
|
||||||
@@ -314,29 +316,28 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
|
|||||||
#include <lzma-sdk/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp>
|
#include <lzma-sdk/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp>
|
||||||
#undef RC_NORMALIZE
|
#undef RC_NORMALIZE
|
||||||
|
|
||||||
|
int upx_lzma_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
upx_callback_t *cb, int method, int level,
|
||||||
upx_bytep dst, unsigned* dst_len,
|
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
|
||||||
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(M_IS_LZMA(method));
|
||||||
assert(level > 0); assert(cresult != nullptr);
|
assert(level > 0);
|
||||||
|
assert(cresult != nullptr);
|
||||||
|
|
||||||
int r = UPX_E_ERROR;
|
int r = UPX_E_ERROR;
|
||||||
HRESULT rh;
|
HRESULT rh;
|
||||||
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : nullptr;
|
const lzma_compress_config_t *const lcconf = cconf_parm ? &cconf_parm->conf_lzma : nullptr;
|
||||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
lzma_compress_result_t *const res = &cresult->result_lzma;
|
||||||
|
res->reset();
|
||||||
|
|
||||||
MyLzma::InStream is; is.AddRef();
|
MyLzma::InStream is;
|
||||||
MyLzma::OutStream os; os.AddRef();
|
is.AddRef();
|
||||||
is.Init(src, src_len);
|
is.Init(src, src_len);
|
||||||
|
MyLzma::OutStream os;
|
||||||
|
os.AddRef();
|
||||||
os.Init(dst, *dst_len);
|
os.Init(dst, *dst_len);
|
||||||
|
MyLzma::ProgressInfo progress;
|
||||||
MyLzma::ProgressInfo progress; progress.AddRef();
|
progress.AddRef();
|
||||||
progress.cb = cb;
|
progress.cb = cb; // progress.Init()
|
||||||
|
|
||||||
NCompress::NLZMA::CEncoder enc;
|
NCompress::NLZMA::CEncoder enc;
|
||||||
const PROPID propIDs[8] = {
|
const PROPID propIDs[8] = {
|
||||||
@@ -351,13 +352,10 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
};
|
};
|
||||||
PROPVARIANT pr[8];
|
PROPVARIANT pr[8];
|
||||||
const unsigned nprops = 8;
|
const unsigned nprops = 8;
|
||||||
static const wchar_t matchfinder[] = L"BT4";
|
if (!prepare_result(res, src_len, method, level, lcconf))
|
||||||
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
|
|
||||||
pr[7].vt = VT_BSTR; pr[7].bstrVal = ACC_PCAST(BSTR, ACC_UNCONST_CAST(wchar_t *, matchfinder));
|
|
||||||
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;
|
|
||||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
|
||||||
|
pr[7].vt = VT_BSTR;
|
||||||
pr[0].uintVal = res->pos_bits;
|
pr[0].uintVal = res->pos_bits;
|
||||||
pr[1].uintVal = res->lit_pos_bits;
|
pr[1].uintVal = res->lit_pos_bits;
|
||||||
pr[2].uintVal = res->lit_context_bits;
|
pr[2].uintVal = res->lit_context_bits;
|
||||||
@@ -365,11 +363,14 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
pr[4].uintVal = res->fast_mode;
|
pr[4].uintVal = res->fast_mode;
|
||||||
pr[5].uintVal = res->num_fast_bytes;
|
pr[5].uintVal = res->num_fast_bytes;
|
||||||
pr[6].uintVal = res->match_finder_cycles;
|
pr[6].uintVal = res->match_finder_cycles;
|
||||||
|
static const wchar_t matchfinder[] = L"BT4";
|
||||||
|
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
|
||||||
|
pr[7].bstrVal = ACC_PCAST(BSTR, ACC_UNCONST_CAST(wchar_t *, matchfinder));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
|
if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
// encode properties in LZMA-style (5 bytes)
|
||||||
if (enc.WriteCoderProperties(&os) != S_OK)
|
if (enc.WriteCoderProperties(&os) != S_OK)
|
||||||
goto error;
|
goto error;
|
||||||
if (os.overflow) {
|
if (os.overflow) {
|
||||||
@@ -378,12 +379,15 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
assert(os.b_pos == 5);
|
assert(os.b_pos == 5);
|
||||||
|
|
||||||
|
// reset and encode properties in UPX-style (2 bytes)
|
||||||
os.b_pos = 0;
|
os.b_pos = 0;
|
||||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
// UPX extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||||
unsigned t = res->lit_context_bits + res->lit_pos_bits;
|
unsigned t = res->lit_context_bits + res->lit_pos_bits;
|
||||||
os.WriteByte(Byte((t << 3) | res->pos_bits));
|
os.WriteByte(Byte((t << 3) | res->pos_bits));
|
||||||
os.WriteByte(Byte((res->lit_pos_bits << 4) | (res->lit_context_bits)));
|
os.WriteByte(Byte((res->lit_pos_bits << 4) | res->lit_context_bits));
|
||||||
|
|
||||||
|
// compress
|
||||||
rh = enc.Code(&is, &os, nullptr, nullptr, &progress);
|
rh = enc.Code(&is, &os, nullptr, nullptr, &progress);
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@@ -394,26 +398,24 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
assert(os.b_pos <= *dst_len);
|
assert(os.b_pos <= *dst_len);
|
||||||
if (rh == E_OUTOFMEMORY)
|
if (rh == E_OUTOFMEMORY)
|
||||||
r = UPX_E_OUT_OF_MEMORY;
|
r = UPX_E_OUT_OF_MEMORY;
|
||||||
else if (os.overflow)
|
else if (os.overflow) {
|
||||||
{
|
|
||||||
assert(os.b_pos == *dst_len);
|
assert(os.b_pos == *dst_len);
|
||||||
// r = UPX_E_OUTPUT_OVERRUN;
|
// r = UPX_E_OUTPUT_OVERRUN;
|
||||||
r = UPX_E_NOT_COMPRESSIBLE;
|
r = UPX_E_NOT_COMPRESSIBLE;
|
||||||
}
|
} else if (rh == S_OK) {
|
||||||
else if (rh == S_OK)
|
|
||||||
{
|
|
||||||
assert(is.b_pos == src_len);
|
assert(is.b_pos == src_len);
|
||||||
r = UPX_E_OK;
|
r = UPX_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
*dst_len = (unsigned) 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);
|
NO_printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits,
|
||||||
//printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
|
res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len,
|
||||||
|
*dst_len);
|
||||||
|
NO_printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// decompress
|
// decompress
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -425,60 +427,67 @@ error:
|
|||||||
#include <lzma-sdk/C/7zip/Compress/LZMA_C/LzmaDecode.h>
|
#include <lzma-sdk/C/7zip/Compress/LZMA_C/LzmaDecode.h>
|
||||||
#include <lzma-sdk/C/7zip/Compress/LZMA_C/LzmaDecode.c>
|
#include <lzma-sdk/C/7zip/Compress/LZMA_C/LzmaDecode.c>
|
||||||
|
|
||||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
int upx_lzma_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
upx_bytep dst, unsigned* dst_len,
|
int method, const upx_compress_result_t *cresult) {
|
||||||
int method,
|
|
||||||
const upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
assert(M_IS_LZMA(method));
|
assert(M_IS_LZMA(method));
|
||||||
// see res->num_probs above
|
// see res->num_probs above
|
||||||
COMPILE_TIME_ASSERT(sizeof(CProb) == 2)
|
COMPILE_TIME_ASSERT(sizeof(CProb) == 2)
|
||||||
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
|
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
|
||||||
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
|
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
|
||||||
|
|
||||||
CLzmaDecoderState s; memset(&s, 0, sizeof(s));
|
CLzmaDecoderState s;
|
||||||
|
mem_clear(&s);
|
||||||
SizeT src_out = 0, dst_out = 0;
|
SizeT src_out = 0, dst_out = 0;
|
||||||
int r = UPX_E_ERROR;
|
int r = UPX_E_ERROR;
|
||||||
int rh;
|
int rh;
|
||||||
|
|
||||||
if (src_len < 3)
|
// decode UPX-style properties (2 bytes)
|
||||||
|
if (src_len < 3) {
|
||||||
|
r = UPX_E_INPUT_OVERRUN;
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
s.Properties.pb = src[0] & 7;
|
s.Properties.pb = src[0] & 7;
|
||||||
s.Properties.lp = (src[1] >> 4);
|
s.Properties.lp = (src[1] >> 4);
|
||||||
s.Properties.lc = src[1] & 15;
|
s.Properties.lc = src[1] & 15;
|
||||||
if (s.Properties.pb >= 5) goto error;
|
if (s.Properties.pb >= 5)
|
||||||
if (s.Properties.lp >= 5) goto error;
|
goto error;
|
||||||
if (s.Properties.lc >= 9) goto error;
|
if (s.Properties.lp >= 5)
|
||||||
// extra
|
goto error;
|
||||||
if ((src[0] >> 3) != s.Properties.lc + s.Properties.lp) goto error;
|
if (s.Properties.lc >= 9)
|
||||||
src += 2; src_len -= 2;
|
goto error;
|
||||||
|
// UPX extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||||
|
if ((src[0] >> 3) != s.Properties.lc + s.Properties.lp)
|
||||||
|
goto error;
|
||||||
|
src += 2;
|
||||||
|
src_len -= 2;
|
||||||
|
|
||||||
if (cresult)
|
if (cresult) {
|
||||||
{
|
assert(cresult->debug.method == method);
|
||||||
assert(cresult->method == method);
|
|
||||||
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
|
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_pos_bits == (unsigned) s.Properties.lp);
|
||||||
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
||||||
assert(cresult->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
|
assert(cresult->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
|
||||||
const lzma_compress_result_t *res = &cresult->result_lzma;
|
const lzma_compress_result_t *res = &cresult->result_lzma;
|
||||||
|
NO_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);
|
||||||
UNUSED(res);
|
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);
|
|
||||||
}
|
}
|
||||||
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
|
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
|
||||||
if (!s.Probs)
|
if (!s.Probs) {
|
||||||
{
|
|
||||||
r = UPX_E_OUT_OF_MEMORY;
|
r = UPX_E_OUT_OF_MEMORY;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
rh = LzmaDecode(&s, src, src_len, &src_out, dst, *dst_len, &dst_out);
|
rh = LzmaDecode(&s, src, src_len, &src_out, dst, *dst_len, &dst_out);
|
||||||
assert(src_out <= src_len);
|
assert(src_out <= src_len);
|
||||||
assert(dst_out <= *dst_len);
|
assert(dst_out <= *dst_len);
|
||||||
if (rh == 0)
|
if (rh == 0) {
|
||||||
{
|
|
||||||
r = UPX_E_OK;
|
r = UPX_E_OK;
|
||||||
if (src_out != src_len)
|
if (src_out != src_len)
|
||||||
r = UPX_E_INPUT_NOT_CONSUMED;
|
r = UPX_E_INPUT_NOT_CONSUMED;
|
||||||
}
|
} else if (rh == LZMA_RESULT_INPUT_OVERRUN)
|
||||||
|
r = UPX_E_INPUT_OVERRUN;
|
||||||
|
else if (rh == LZMA_RESULT_OUTPUT_OVERRUN)
|
||||||
|
r = UPX_E_OUTPUT_OVERRUN;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
*dst_len = dst_out;
|
*dst_len = dst_out;
|
||||||
@@ -486,24 +495,20 @@ error:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// test_overlap - see <ucl/ucl.h> for semantics
|
// test_overlap - see <ucl/ucl.h> for semantics
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_lzma_test_overlap ( const upx_bytep buf,
|
int upx_lzma_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off,
|
||||||
const upx_bytep tbuf,
|
unsigned src_len, unsigned *dst_len, int method,
|
||||||
unsigned src_off, unsigned src_len,
|
const upx_compress_result_t *cresult) {
|
||||||
unsigned* dst_len,
|
|
||||||
int method,
|
|
||||||
const upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
assert(M_IS_LZMA(method));
|
assert(M_IS_LZMA(method));
|
||||||
|
|
||||||
MemBuffer b(src_off + src_len);
|
MemBuffer b(src_off + src_len);
|
||||||
memcpy(b + src_off, buf + src_off, src_len);
|
memcpy(b + src_off, buf + src_off, src_len);
|
||||||
unsigned saved_dst_len = *dst_len;
|
unsigned saved_dst_len = *dst_len;
|
||||||
int r = upx_lzma_decompress(b + src_off, src_len, b, dst_len, method, cresult);
|
int r = upx_lzma_decompress(raw_index_bytes(b, src_off, src_len), src_len,
|
||||||
|
raw_bytes(b, *dst_len), dst_len, method, cresult);
|
||||||
if (r != UPX_E_OK)
|
if (r != UPX_E_OK)
|
||||||
return r;
|
return r;
|
||||||
if (*dst_len != saved_dst_len)
|
if (*dst_len != saved_dst_len)
|
||||||
@@ -516,25 +521,34 @@ int upx_lzma_test_overlap ( const upx_bytep buf,
|
|||||||
return UPX_E_OK;
|
return UPX_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// misc
|
// misc
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_lzma_init(void)
|
int upx_lzma_init(void) { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *upx_lzma_version_string(void)
|
const char *upx_lzma_version_string(void) { return "4.43"; }
|
||||||
{
|
|
||||||
#if (WITH_LZMA == 0x443)
|
|
||||||
return "4.43";
|
|
||||||
#else
|
|
||||||
# error "unknown WITH_LZMA version"
|
|
||||||
return nullptr;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// doctest checks
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("upx_lzma_decompress") {
|
||||||
|
const byte *c_data;
|
||||||
|
byte d_buf[16];
|
||||||
|
unsigned d_len;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
c_data = (const byte *) "\x1a\x03\x00\x7f\xed\x3c\x00\x00\x00";
|
||||||
|
d_len = 16;
|
||||||
|
r = upx_lzma_decompress(c_data, 9, d_buf, &d_len, M_LZMA, nullptr);
|
||||||
|
CHECK((r == 0 && d_len == 16));
|
||||||
|
r = upx_lzma_decompress(c_data, 8, d_buf, &d_len, M_LZMA, nullptr);
|
||||||
|
CHECK(r == UPX_E_INPUT_OVERRUN);
|
||||||
|
d_len = 15;
|
||||||
|
r = upx_lzma_decompress(c_data, 9, d_buf, &d_len, M_LZMA, nullptr);
|
||||||
|
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||||
|
UNUSED(r);
|
||||||
|
}
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -0,0 +1,369 @@
|
|||||||
|
/* compress_ucl.cpp --
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
|
#include "compress.h"
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
static int convert_errno_from_ucl(int r) {
|
||||||
|
switch (r) {
|
||||||
|
case UCL_E_OK:
|
||||||
|
return UPX_E_OK;
|
||||||
|
case UCL_E_ERROR:
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
case UCL_E_OUT_OF_MEMORY:
|
||||||
|
return UPX_E_OUT_OF_MEMORY;
|
||||||
|
case UCL_E_NOT_COMPRESSIBLE:
|
||||||
|
return UPX_E_NOT_COMPRESSIBLE;
|
||||||
|
case UCL_E_INPUT_OVERRUN:
|
||||||
|
return UPX_E_INPUT_OVERRUN;
|
||||||
|
case UCL_E_OUTPUT_OVERRUN:
|
||||||
|
return UPX_E_OUTPUT_OVERRUN;
|
||||||
|
case UCL_E_LOOKBEHIND_OVERRUN:
|
||||||
|
return UPX_E_LOOKBEHIND_OVERRUN;
|
||||||
|
case UCL_E_EOF_NOT_FOUND:
|
||||||
|
return UPX_E_EOF_NOT_FOUND;
|
||||||
|
case UCL_E_INPUT_NOT_CONSUMED:
|
||||||
|
return UPX_E_INPUT_NOT_CONSUMED;
|
||||||
|
case UCL_E_INVALID_ARGUMENT:
|
||||||
|
return UPX_E_INVALID_ARGUMENT;
|
||||||
|
// UCL extra:
|
||||||
|
case UCL_E_OVERLAP_OVERRUN:
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
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_t *cb = (upx_callback_t *) user;
|
||||||
|
if (cb && cb->nprogress)
|
||||||
|
cb->nprogress(cb, a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_ucl_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
|
upx_callback_t *cb_parm, int method, int level,
|
||||||
|
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
|
||||||
|
int r;
|
||||||
|
assert(level > 0);
|
||||||
|
assert(cresult != nullptr);
|
||||||
|
|
||||||
|
COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))
|
||||||
|
|
||||||
|
ucl_progress_callback_t cb;
|
||||||
|
cb.callback = nullptr;
|
||||||
|
cb.user = nullptr;
|
||||||
|
if (cb_parm && cb_parm->nprogress) {
|
||||||
|
cb.callback = wrap_nprogress_ucl;
|
||||||
|
cb.user = cb_parm;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
ucl_uint *const res = cresult->result_ucl.result;
|
||||||
|
// assume no info available - fill in worst case results
|
||||||
|
// res[0] = 1; // min_offset_found - NOT USED
|
||||||
|
res[1] = src_len - 1; // max_offset_found
|
||||||
|
// res[2] = 2; // min_match_found - NOT USED
|
||||||
|
res[3] = src_len - 1; // max_match_found
|
||||||
|
// res[4] = 1; // min_run_found - NOT USED
|
||||||
|
res[5] = src_len; // max_run_found
|
||||||
|
res[6] = 1; // first_offset_found
|
||||||
|
// res[7] = 999999; // same_match_offsets_found - NOT USED
|
||||||
|
|
||||||
|
// prepare bit-buffer settings
|
||||||
|
cconf.bb_endian = 0;
|
||||||
|
cconf.bb_size = 0;
|
||||||
|
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16) {
|
||||||
|
static const upx_uint8_t sizes[3] = {32, 8, 16};
|
||||||
|
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
||||||
|
} else {
|
||||||
|
throwInternalError("unknown compression method");
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// optimize compression params
|
||||||
|
if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
|
||||||
|
cconf.max_offset = 8 * 1024 - 1;
|
||||||
|
else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
|
||||||
|
cconf.max_offset = 32 * 1024 - 1;
|
||||||
|
|
||||||
|
if M_IS_NRV2B (method)
|
||||||
|
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len, &cb, level, &cconf, res);
|
||||||
|
else if M_IS_NRV2D (method)
|
||||||
|
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len, &cb, level, &cconf, res);
|
||||||
|
else if M_IS_NRV2E (method)
|
||||||
|
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len, &cb, level, &cconf, res);
|
||||||
|
else {
|
||||||
|
throwInternalError("unknown compression method");
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure first_offset_found is set
|
||||||
|
if (res[6] == 0)
|
||||||
|
res[6] = 1;
|
||||||
|
|
||||||
|
return convert_errno_from_ucl(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
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 r;
|
||||||
|
|
||||||
|
switch (method) {
|
||||||
|
case M_NRV2B_8:
|
||||||
|
r = ucl_nrv2b_decompress_safe_8(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2B_LE16:
|
||||||
|
r = ucl_nrv2b_decompress_safe_le16(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2B_LE32:
|
||||||
|
r = ucl_nrv2b_decompress_safe_le32(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2D_8:
|
||||||
|
r = ucl_nrv2d_decompress_safe_8(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2D_LE16:
|
||||||
|
r = ucl_nrv2d_decompress_safe_le16(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2D_LE32:
|
||||||
|
r = ucl_nrv2d_decompress_safe_le32(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2E_8:
|
||||||
|
r = ucl_nrv2e_decompress_safe_8(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2E_LE16:
|
||||||
|
r = ucl_nrv2e_decompress_safe_le16(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2E_LE32:
|
||||||
|
r = ucl_nrv2e_decompress_safe_le32(src, src_len, dst, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throwInternalError("unknown decompression method");
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
UNUSED(cresult);
|
||||||
|
return convert_errno_from_ucl(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
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) {
|
||||||
|
case M_NRV2B_8:
|
||||||
|
r = ucl_nrv2b_test_overlap_8(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2B_LE16:
|
||||||
|
r = ucl_nrv2b_test_overlap_le16(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2B_LE32:
|
||||||
|
r = ucl_nrv2b_test_overlap_le32(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2D_8:
|
||||||
|
r = ucl_nrv2d_test_overlap_8(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2D_LE16:
|
||||||
|
r = ucl_nrv2d_test_overlap_le16(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2D_LE32:
|
||||||
|
r = ucl_nrv2d_test_overlap_le32(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2E_8:
|
||||||
|
r = ucl_nrv2e_test_overlap_8(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2E_LE16:
|
||||||
|
r = ucl_nrv2e_test_overlap_le16(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
case M_NRV2E_LE32:
|
||||||
|
r = ucl_nrv2e_test_overlap_le32(buf, src_off, src_len, dst_len, nullptr);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throwInternalError("unknown decompression method");
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
UNUSED(cresult);
|
||||||
|
return convert_errno_from_ucl(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// misc
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static ucl_voidp __UCL_CDECL my_malloc(ucl_uint n) { return upx_calloc(n, 1); }
|
||||||
|
static void __UCL_CDECL my_free(ucl_voidp p) { free(p); }
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
|
int upx_ucl_init(void) {
|
||||||
|
if (ucl_init() != UCL_E_OK)
|
||||||
|
return -1;
|
||||||
|
if (UCL_VERSION != ucl_version() || strcmp(UCL_VERSION_STRING, ucl_version_string()) != 0)
|
||||||
|
return -2;
|
||||||
|
ucl_set_malloc_hooks(my_malloc, my_free);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *upx_ucl_version_string(void) { return ucl_version_string(); }
|
||||||
|
|
||||||
|
unsigned upx_ucl_adler32(const void *buf, unsigned len, unsigned adler) {
|
||||||
|
return ucl_adler32(adler, (const ucl_bytep) buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0 // UNUSED
|
||||||
|
unsigned upx_ucl_crc32(const void *buf, unsigned len, unsigned crc) {
|
||||||
|
return ucl_crc32(crc, (const ucl_bytep) buf, len);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// doctest checks
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if DEBUG && !defined(DOCTEST_CONFIG_DISABLE) && 1
|
||||||
|
|
||||||
|
#include "../util/membuffer.h"
|
||||||
|
|
||||||
|
static bool check_ucl(const int method, const unsigned expected_c_len) {
|
||||||
|
const unsigned u_len = 16384;
|
||||||
|
const unsigned c_extra = 4096;
|
||||||
|
MemBuffer u_buf, c_buf, d_buf;
|
||||||
|
unsigned c_len, d_len;
|
||||||
|
upx_compress_result_t cresult;
|
||||||
|
int r;
|
||||||
|
const int level = 3; // don't waste time
|
||||||
|
|
||||||
|
u_buf.alloc(u_len);
|
||||||
|
memset(u_buf, 0, u_len);
|
||||||
|
c_buf.allocForCompression(u_len, c_extra);
|
||||||
|
d_buf.allocForDecompression(u_len);
|
||||||
|
|
||||||
|
c_len = c_buf.getSize() - c_extra;
|
||||||
|
r = upx_ucl_compress(raw_bytes(u_buf, u_len), u_len, raw_index_bytes(c_buf, c_extra, c_len),
|
||||||
|
&c_len, nullptr, method, level, NULL_cconf, &cresult);
|
||||||
|
if (r != 0 || c_len != expected_c_len)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
d_len = d_buf.getSize();
|
||||||
|
r = upx_ucl_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
|
&d_len, method, nullptr);
|
||||||
|
if (r != 0 || d_len != u_len || memcmp(u_buf, d_buf, u_len) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
d_len = u_len - 1;
|
||||||
|
r = upx_ucl_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
|
&d_len, method, nullptr);
|
||||||
|
if (r == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
|
||||||
|
// unsigned x_len = d_len;
|
||||||
|
// r = upx_ucl_test_overlap(c_buf, u_buf, c_extra, c_len, &x_len, method, nullptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("compress_ucl") {
|
||||||
|
CHECK(check_ucl(M_NRV2B_8, 34));
|
||||||
|
CHECK(check_ucl(M_NRV2B_LE16, 34));
|
||||||
|
CHECK(check_ucl(M_NRV2B_LE32, 34));
|
||||||
|
CHECK(check_ucl(M_NRV2D_8, 32));
|
||||||
|
CHECK(check_ucl(M_NRV2D_LE16, 32));
|
||||||
|
CHECK(check_ucl(M_NRV2D_LE32, 34));
|
||||||
|
CHECK(check_ucl(M_NRV2E_8, 32));
|
||||||
|
CHECK(check_ucl(M_NRV2E_LE16, 32));
|
||||||
|
CHECK(check_ucl(M_NRV2E_LE32, 34));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DEBUG
|
||||||
|
|
||||||
|
TEST_CASE("upx_ucl_decompress") {
|
||||||
|
const byte *c_data;
|
||||||
|
byte d_buf[16];
|
||||||
|
unsigned d_len;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
c_data = (const byte *) "\x92\xff\x10\x00\x00\x00\x00\x00\x48\xff";
|
||||||
|
d_len = 16;
|
||||||
|
r = upx_ucl_decompress(c_data, 10, d_buf, &d_len, M_NRV2B_8, nullptr);
|
||||||
|
CHECK((r == 0 && d_len == 16));
|
||||||
|
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2B_8, nullptr);
|
||||||
|
CHECK(r == UPX_E_INPUT_OVERRUN);
|
||||||
|
d_len = 15;
|
||||||
|
r = upx_ucl_decompress(c_data, 10, d_buf, &d_len, M_NRV2B_8, nullptr);
|
||||||
|
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||||
|
|
||||||
|
c_data = (const byte *) "\x92\xff\x10\x92\x49\x24\x92\xa0\xff";
|
||||||
|
d_len = 16;
|
||||||
|
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2D_8, nullptr);
|
||||||
|
CHECK((r == 0 && d_len == 16));
|
||||||
|
r = upx_ucl_decompress(c_data, 8, d_buf, &d_len, M_NRV2D_8, nullptr);
|
||||||
|
CHECK(r == UPX_E_INPUT_OVERRUN);
|
||||||
|
d_len = 15;
|
||||||
|
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2D_8, nullptr);
|
||||||
|
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||||
|
|
||||||
|
c_data = (const byte *) "\x90\xff\xb0\x92\x49\x24\x92\xa0\xff";
|
||||||
|
d_len = 16;
|
||||||
|
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2E_8, nullptr);
|
||||||
|
CHECK((r == 0 && d_len == 16));
|
||||||
|
r = upx_ucl_decompress(c_data, 8, d_buf, &d_len, M_NRV2E_8, nullptr);
|
||||||
|
CHECK(r == UPX_E_INPUT_OVERRUN);
|
||||||
|
d_len = 15;
|
||||||
|
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2E_8, nullptr);
|
||||||
|
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||||
|
UNUSED(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -21,58 +20,72 @@
|
|||||||
If not, write to the Free Software Foundation, Inc.,
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
Markus F.X.J. Oberhumer
|
||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
#include "conf.h"
|
|
||||||
#include "compress.h"
|
#include "compress.h"
|
||||||
#include "util/membuffer.h"
|
#include "../util/membuffer.h"
|
||||||
|
// NOLINTBEGIN(clang-analyzer-optin.performance.Padding)
|
||||||
|
#define ZLIB_CONST 1
|
||||||
#include <zlib/zlib.h>
|
#include <zlib/zlib.h>
|
||||||
#include <zlib/deflate.h>
|
#include <zlib/deflate.h>
|
||||||
|
// NOLINTEND(clang-analyzer-optin.performance.Padding)
|
||||||
|
|
||||||
|
void zlib_compress_config_t::reset() noexcept {
|
||||||
void zlib_compress_config_t::reset()
|
mem_clear(this);
|
||||||
{
|
|
||||||
mem_clear(this, sizeof(*this));
|
|
||||||
|
|
||||||
mem_level.reset();
|
mem_level.reset();
|
||||||
window_bits.reset();
|
window_bits.reset();
|
||||||
strategy.reset();
|
strategy.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int convert_errno_from_zlib(int zr) {
|
||||||
static int convert_errno_from_zlib(int zr)
|
switch (zr) {
|
||||||
{
|
case Z_OK:
|
||||||
switch (zr)
|
return UPX_E_OK;
|
||||||
{
|
// positive values
|
||||||
case Z_OK: return UPX_E_OK;
|
case Z_STREAM_END:
|
||||||
case Z_DATA_ERROR: return UPX_E_ERROR;
|
return UPX_E_ERROR;
|
||||||
case Z_NEED_DICT: return UPX_E_ERROR;
|
case Z_NEED_DICT:
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
// negative values
|
||||||
|
case Z_ERRNO:
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
case Z_STREAM_ERROR:
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
case Z_DATA_ERROR:
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
case Z_MEM_ERROR:
|
||||||
|
return UPX_E_OUT_OF_MEMORY;
|
||||||
|
case Z_BUF_ERROR:
|
||||||
|
return UPX_E_OUTPUT_OVERRUN;
|
||||||
|
case Z_VERSION_ERROR:
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
case -7: // UPX extra
|
||||||
|
return UPX_E_INPUT_OVERRUN;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return UPX_E_ERROR;
|
return UPX_E_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
|
int upx_zlib_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
upx_bytep dst, unsigned* dst_len,
|
upx_callback_t *cb_parm, int method, int level,
|
||||||
upx_callback_p cb_parm,
|
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
|
||||||
int method, int level,
|
|
||||||
const upx_compress_config_t *cconf_parm,
|
|
||||||
upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
assert(method == M_DEFLATE);
|
assert(method == M_DEFLATE);
|
||||||
assert(level > 0); assert(cresult != nullptr);
|
assert(level > 0);
|
||||||
|
assert(cresult != nullptr);
|
||||||
UNUSED(cb_parm);
|
UNUSED(cb_parm);
|
||||||
int r = UPX_E_ERROR;
|
int r = UPX_E_ERROR;
|
||||||
int zr;
|
int zr;
|
||||||
const zlib_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_zlib : nullptr;
|
const zlib_compress_config_t *const lcconf = cconf_parm ? &cconf_parm->conf_zlib : nullptr;
|
||||||
zlib_compress_result_t *res = &cresult->result_zlib;
|
zlib_compress_result_t *const res = &cresult->result_zlib;
|
||||||
|
res->reset();
|
||||||
|
|
||||||
if (level == 10)
|
if (level == 10)
|
||||||
level = 9;
|
level = 9;
|
||||||
@@ -81,26 +94,22 @@ int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
zlib_compress_config_t::window_bits_t window_bits;
|
zlib_compress_config_t::window_bits_t window_bits;
|
||||||
zlib_compress_config_t::strategy_t strategy;
|
zlib_compress_config_t::strategy_t strategy;
|
||||||
// cconf overrides
|
// cconf overrides
|
||||||
if (lcconf)
|
if (lcconf) {
|
||||||
{
|
|
||||||
oassign(mem_level, lcconf->mem_level);
|
oassign(mem_level, lcconf->mem_level);
|
||||||
oassign(window_bits, lcconf->window_bits);
|
oassign(window_bits, lcconf->window_bits);
|
||||||
oassign(strategy, lcconf->strategy);
|
oassign(strategy, lcconf->strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
res->dummy = 0;
|
|
||||||
|
|
||||||
z_stream s;
|
z_stream s;
|
||||||
s.zalloc = (alloc_func) nullptr;
|
s.zalloc = (alloc_func) nullptr;
|
||||||
s.zfree = (free_func) nullptr;
|
s.zfree = (free_func) nullptr;
|
||||||
s.next_in = ACC_UNCONST_CAST(upx_bytep, src);
|
s.next_in = src;
|
||||||
s.avail_in = src_len;
|
s.avail_in = src_len;
|
||||||
s.next_out = dst;
|
s.next_out = dst;
|
||||||
s.avail_out = *dst_len;
|
s.avail_out = *dst_len;
|
||||||
s.total_in = s.total_out = 0;
|
s.total_in = s.total_out = 0;
|
||||||
|
|
||||||
zr = (int)deflateInit2(&s, level, Z_DEFLATED, 0 - (int)window_bits,
|
zr = (int) deflateInit2(&s, level, Z_DEFLATED, 0 - (int) window_bits, mem_level, strategy);
|
||||||
mem_level, strategy);
|
|
||||||
if (zr != Z_OK)
|
if (zr != Z_OK)
|
||||||
goto error;
|
goto error;
|
||||||
assert(s.state->level == level);
|
assert(s.state->level == level);
|
||||||
@@ -118,8 +127,7 @@ error:
|
|||||||
if (r == UPX_E_OK)
|
if (r == UPX_E_OK)
|
||||||
r = UPX_E_ERROR;
|
r = UPX_E_ERROR;
|
||||||
done:
|
done:
|
||||||
if (r == UPX_E_OK)
|
if (r == UPX_E_OK) {
|
||||||
{
|
|
||||||
if (s.avail_in != 0 || s.total_in != src_len)
|
if (s.avail_in != 0 || s.total_in != src_len)
|
||||||
r = UPX_E_ERROR;
|
r = UPX_E_ERROR;
|
||||||
}
|
}
|
||||||
@@ -129,16 +137,12 @@ done:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
|
int upx_zlib_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
upx_bytep dst, unsigned* dst_len,
|
int method, const upx_compress_result_t *cresult) {
|
||||||
int method,
|
|
||||||
const upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
assert(method == M_DEFLATE);
|
assert(method == M_DEFLATE);
|
||||||
UNUSED(method);
|
UNUSED(method);
|
||||||
UNUSED(cresult);
|
UNUSED(cresult);
|
||||||
@@ -148,7 +152,7 @@ int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
|
|||||||
z_stream s;
|
z_stream s;
|
||||||
s.zalloc = (alloc_func) nullptr;
|
s.zalloc = (alloc_func) nullptr;
|
||||||
s.zfree = (free_func) nullptr;
|
s.zfree = (free_func) nullptr;
|
||||||
s.next_in = ACC_UNCONST_CAST(upx_bytep, src);
|
s.next_in = src;
|
||||||
s.avail_in = src_len;
|
s.avail_in = src_len;
|
||||||
s.next_out = dst;
|
s.next_out = dst;
|
||||||
s.avail_out = *dst_len;
|
s.avail_out = *dst_len;
|
||||||
@@ -158,8 +162,11 @@ int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
|
|||||||
if (zr != Z_OK)
|
if (zr != Z_OK)
|
||||||
goto error;
|
goto error;
|
||||||
zr = inflate(&s, Z_FINISH);
|
zr = inflate(&s, Z_FINISH);
|
||||||
if (zr != Z_STREAM_END)
|
if (zr != Z_STREAM_END) {
|
||||||
|
if (zr == Z_BUF_ERROR && s.avail_in == 0)
|
||||||
|
zr = -7; // UPX extra
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
zr = inflateEnd(&s);
|
zr = inflateEnd(&s);
|
||||||
if (zr != Z_OK)
|
if (zr != Z_OK)
|
||||||
goto error;
|
goto error;
|
||||||
@@ -171,8 +178,7 @@ error:
|
|||||||
if (r == UPX_E_OK)
|
if (r == UPX_E_OK)
|
||||||
r = UPX_E_ERROR;
|
r = UPX_E_ERROR;
|
||||||
done:
|
done:
|
||||||
if (r == UPX_E_OK)
|
if (r == UPX_E_OK) {
|
||||||
{
|
|
||||||
if (s.avail_in != 0 || s.total_in != src_len)
|
if (s.avail_in != 0 || s.total_in != src_len)
|
||||||
r = UPX_E_INPUT_NOT_CONSUMED;
|
r = UPX_E_INPUT_NOT_CONSUMED;
|
||||||
}
|
}
|
||||||
@@ -182,24 +188,20 @@ done:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// test_overlap - see <ucl/ucl.h> for semantics
|
// test_overlap - see <ucl/ucl.h> for semantics
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_zlib_test_overlap ( const upx_bytep buf,
|
int upx_zlib_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off,
|
||||||
const upx_bytep tbuf,
|
unsigned src_len, unsigned *dst_len, int method,
|
||||||
unsigned src_off, unsigned src_len,
|
const upx_compress_result_t *cresult) {
|
||||||
unsigned* dst_len,
|
|
||||||
int method,
|
|
||||||
const upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
assert(method == M_DEFLATE);
|
assert(method == M_DEFLATE);
|
||||||
|
|
||||||
MemBuffer b(src_off + src_len);
|
MemBuffer b(src_off + src_len);
|
||||||
memcpy(b + src_off, buf + src_off, src_len);
|
memcpy(b + src_off, buf + src_off, src_len);
|
||||||
unsigned saved_dst_len = *dst_len;
|
unsigned saved_dst_len = *dst_len;
|
||||||
int r = upx_zlib_decompress(b + src_off, src_len, b, dst_len, method, cresult);
|
int r = upx_zlib_decompress(raw_index_bytes(b, src_off, src_len), src_len,
|
||||||
|
raw_bytes(b, *dst_len), dst_len, method, cresult);
|
||||||
if (r != UPX_E_OK)
|
if (r != UPX_E_OK)
|
||||||
return r;
|
return r;
|
||||||
if (*dst_len != saved_dst_len)
|
if (*dst_len != saved_dst_len)
|
||||||
@@ -212,44 +214,35 @@ int upx_zlib_test_overlap ( const upx_bytep buf,
|
|||||||
return UPX_E_OK;
|
return UPX_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// misc
|
// misc
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int upx_zlib_init(void)
|
int upx_zlib_init(void) {
|
||||||
{
|
|
||||||
if (strcmp(ZLIB_VERSION, zlibVersion()) != 0)
|
if (strcmp(ZLIB_VERSION, zlibVersion()) != 0)
|
||||||
return -2;
|
return -2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *upx_zlib_version_string(void)
|
const char *upx_zlib_version_string(void) { return zlibVersion(); }
|
||||||
{
|
|
||||||
return zlibVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0 /* UNUSED */
|
#if 0 // UNUSED
|
||||||
unsigned upx_zlib_adler32(const void *buf, unsigned len, unsigned adler)
|
unsigned upx_zlib_adler32(const void *buf, unsigned len, unsigned adler) {
|
||||||
{
|
|
||||||
return adler32(adler, (const Bytef *) buf, len);
|
return adler32(adler, (const Bytef *) buf, len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 /* UNUSED */
|
#if 0 // UNUSED
|
||||||
unsigned upx_zlib_crc32(const void *buf, unsigned len, unsigned crc)
|
unsigned upx_zlib_crc32(const void *buf, unsigned len, unsigned crc) {
|
||||||
{
|
|
||||||
return crc32(crc, (const Bytef *) buf, len);
|
return crc32(crc, (const Bytef *) buf, len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// Debug checks
|
// doctest checks
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if DEBUG && 1
|
#if DEBUG && !defined(DOCTEST_CONFIG_DISABLE) && 1
|
||||||
|
|
||||||
#include "util/membuffer.h"
|
|
||||||
|
|
||||||
static bool check_zlib(const int method, const int level, const unsigned expected_c_len) {
|
static bool check_zlib(const int method, const int level, const unsigned expected_c_len) {
|
||||||
const unsigned u_len = 16384;
|
const unsigned u_len = 16384;
|
||||||
@@ -262,16 +255,25 @@ static bool check_zlib(const int method, const int level, const unsigned expecte
|
|||||||
u_buf.alloc(u_len);
|
u_buf.alloc(u_len);
|
||||||
memset(u_buf, 0, u_len);
|
memset(u_buf, 0, u_len);
|
||||||
c_buf.allocForCompression(u_len, c_extra);
|
c_buf.allocForCompression(u_len, c_extra);
|
||||||
d_buf.allocForUncompression(u_len);
|
d_buf.allocForDecompression(u_len);
|
||||||
|
|
||||||
c_len = c_buf.getSize() - c_extra;
|
c_len = c_buf.getSize() - c_extra;
|
||||||
r = upx_zlib_compress(u_buf, u_len, c_buf + c_extra, &c_len, nullptr, method, level, NULL_cconf, &cresult);
|
r = upx_zlib_compress(raw_bytes(u_buf, u_len), u_len, raw_index_bytes(c_buf, c_extra, c_len),
|
||||||
if (r != 0 || c_len != expected_c_len) return false;
|
&c_len, nullptr, method, level, NULL_cconf, &cresult);
|
||||||
|
if (r != 0 || c_len != expected_c_len)
|
||||||
|
return false;
|
||||||
|
|
||||||
d_len = d_buf.getSize();
|
d_len = d_buf.getSize();
|
||||||
r = upx_zlib_decompress(c_buf + c_extra, c_len, d_buf, &d_len, method, nullptr);
|
r = upx_zlib_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
if (r != 0 || d_len != u_len) return false;
|
&d_len, method, nullptr);
|
||||||
if (memcmp(u_buf, d_buf, u_len) != 0) return false;
|
if (r != 0 || d_len != u_len || memcmp(u_buf, d_buf, u_len) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
d_len = u_len - 1;
|
||||||
|
r = upx_zlib_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
|
&d_len, method, nullptr);
|
||||||
|
if (r == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
|
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
|
||||||
// unsigned x_len = d_len;
|
// unsigned x_len = d_len;
|
||||||
@@ -287,5 +289,22 @@ TEST_CASE("compress_zlib") {
|
|||||||
|
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
|
TEST_CASE("upx_zlib_decompress") {
|
||||||
|
const byte *c_data;
|
||||||
|
byte d_buf[16];
|
||||||
|
unsigned d_len;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
c_data = (const byte *) "\xfb\xff\x1f\x15\x00\x00";
|
||||||
|
d_len = 16;
|
||||||
|
r = upx_zlib_decompress(c_data, 6, d_buf, &d_len, M_DEFLATE, nullptr);
|
||||||
|
CHECK((r == 0 && d_len == 16));
|
||||||
|
r = upx_zlib_decompress(c_data, 5, d_buf, &d_len, M_DEFLATE, nullptr);
|
||||||
|
CHECK(r == UPX_E_INPUT_OVERRUN);
|
||||||
|
d_len = 15;
|
||||||
|
r = upx_zlib_decompress(c_data, 6, d_buf, &d_len, M_DEFLATE, nullptr);
|
||||||
|
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||||
|
UNUSED(r);
|
||||||
|
}
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
/* compress_zstd.cpp --
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
|
|
||||||
|
void zstd_compress_config_t::reset() noexcept { mem_clear(this); }
|
||||||
|
|
||||||
|
#if WITH_ZSTD
|
||||||
|
#include "compress.h"
|
||||||
|
#include "../util/membuffer.h"
|
||||||
|
#include <zstd/lib/zstd.h>
|
||||||
|
#include <zstd/lib/zstd_errors.h>
|
||||||
|
#include <zstd/lib/compress/hist.h>
|
||||||
|
|
||||||
|
static int convert_errno_from_zstd(size_t zr) {
|
||||||
|
const ZSTD_ErrorCode ze = ZSTD_getErrorCode(zr);
|
||||||
|
switch (ze) {
|
||||||
|
case ZSTD_error_memory_allocation:
|
||||||
|
return UPX_E_OUT_OF_MEMORY;
|
||||||
|
case ZSTD_error_srcSize_wrong:
|
||||||
|
return UPX_E_INPUT_OVERRUN;
|
||||||
|
case ZSTD_error_dstSize_tooSmall:
|
||||||
|
return UPX_E_OUTPUT_OVERRUN;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// TODO later: use advanced compression API for compression finetuning
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_zstd_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
|
upx_callback_t *cb_parm, int method, int level,
|
||||||
|
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
|
||||||
|
assert(method == M_ZSTD);
|
||||||
|
assert(level > 0);
|
||||||
|
assert(cresult != nullptr);
|
||||||
|
UNUSED(cb_parm);
|
||||||
|
int r = UPX_E_ERROR;
|
||||||
|
size_t zr;
|
||||||
|
const zstd_compress_config_t *const lcconf = cconf_parm ? &cconf_parm->conf_zstd : nullptr;
|
||||||
|
zstd_compress_result_t *const res = &cresult->result_zstd;
|
||||||
|
res->reset();
|
||||||
|
|
||||||
|
// TODO later: map level 1..10 to zstd-level 1..22
|
||||||
|
if (level == 10)
|
||||||
|
level = 22;
|
||||||
|
|
||||||
|
// cconf overrides
|
||||||
|
if (lcconf) {
|
||||||
|
UNUSED(lcconf);
|
||||||
|
}
|
||||||
|
|
||||||
|
zr = ZSTD_compress(dst, *dst_len, src, src_len, level);
|
||||||
|
if (ZSTD_isError(zr)) {
|
||||||
|
*dst_len = 0; // TODO ???
|
||||||
|
r = convert_errno_from_zstd(zr);
|
||||||
|
assert(r != UPX_E_OK);
|
||||||
|
} else {
|
||||||
|
assert(zr <= *dst_len);
|
||||||
|
*dst_len = (unsigned) zr;
|
||||||
|
r = UPX_E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_zstd_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
|
||||||
|
int method, const upx_compress_result_t *cresult) {
|
||||||
|
assert(method == M_ZSTD);
|
||||||
|
UNUSED(method);
|
||||||
|
UNUSED(cresult);
|
||||||
|
int r = UPX_E_ERROR;
|
||||||
|
size_t zr;
|
||||||
|
|
||||||
|
zr = ZSTD_decompress(dst, *dst_len, src, src_len);
|
||||||
|
if (ZSTD_isError(zr)) {
|
||||||
|
*dst_len = 0; // TODO ???
|
||||||
|
r = convert_errno_from_zstd(zr);
|
||||||
|
assert(r != UPX_E_OK);
|
||||||
|
} else {
|
||||||
|
assert(zr <= *dst_len);
|
||||||
|
*dst_len = (unsigned) zr;
|
||||||
|
r = UPX_E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// test_overlap - see <ucl/ucl.h> for semantics
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_zstd_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_ZSTD);
|
||||||
|
|
||||||
|
MemBuffer b(src_off + src_len);
|
||||||
|
memcpy(b + src_off, buf + src_off, src_len);
|
||||||
|
unsigned saved_dst_len = *dst_len;
|
||||||
|
int r = upx_zstd_decompress(raw_index_bytes(b, src_off, src_len), src_len,
|
||||||
|
raw_bytes(b, *dst_len), 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, so we use an extra memcmp().
|
||||||
|
if (tbuf != nullptr && memcmp(tbuf, b, *dst_len) != 0)
|
||||||
|
return UPX_E_ERROR;
|
||||||
|
return UPX_E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// misc
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int upx_zstd_init(void) {
|
||||||
|
if (strcmp(ZSTD_VERSION_STRING, ZSTD_versionString()) != 0)
|
||||||
|
return -2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *upx_zstd_version_string(void) { return ZSTD_VERSION_STRING; }
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// doctest checks
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if DEBUG && !defined(DOCTEST_CONFIG_DISABLE) && 1
|
||||||
|
|
||||||
|
static bool check_zstd(const int method, const int level, const unsigned expected_c_len) {
|
||||||
|
const unsigned u_len = 16384;
|
||||||
|
const unsigned c_extra = 4096;
|
||||||
|
MemBuffer u_buf, c_buf, d_buf;
|
||||||
|
unsigned c_len, d_len;
|
||||||
|
upx_compress_result_t cresult;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
u_buf.alloc(u_len);
|
||||||
|
memset(u_buf, 0, u_len);
|
||||||
|
c_buf.allocForCompression(u_len, c_extra);
|
||||||
|
d_buf.allocForDecompression(u_len);
|
||||||
|
|
||||||
|
c_len = c_buf.getSize() - c_extra;
|
||||||
|
r = upx_zstd_compress(raw_bytes(u_buf, u_len), u_len, raw_index_bytes(c_buf, c_extra, c_len),
|
||||||
|
&c_len, nullptr, method, level, NULL_cconf, &cresult);
|
||||||
|
if (r != 0 || c_len != expected_c_len)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
d_len = d_buf.getSize();
|
||||||
|
r = upx_zstd_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
|
&d_len, method, nullptr);
|
||||||
|
if (r != 0 || d_len != u_len || memcmp(u_buf, d_buf, u_len) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
d_len = u_len - 1;
|
||||||
|
r = upx_zstd_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
|
||||||
|
&d_len, method, nullptr);
|
||||||
|
if (r == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
|
||||||
|
// unsigned x_len = d_len;
|
||||||
|
// r = upx_zstd_test_overlap(c_buf, u_buf, c_extra, c_len, &x_len, method, nullptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("compress_zstd") {
|
||||||
|
CHECK(check_zstd(M_ZSTD, 1, 19));
|
||||||
|
CHECK(check_zstd(M_ZSTD, 3, 19));
|
||||||
|
CHECK(check_zstd(M_ZSTD, 5, 19));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DEBUG
|
||||||
|
|
||||||
|
TEST_CASE("upx_zstd_decompress") {
|
||||||
|
const byte *c_data;
|
||||||
|
byte d_buf[32];
|
||||||
|
unsigned d_len;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
c_data = (const byte *) "\x28\xb5\x2f\xfd\x20\x20\x3d\x00\x00\x08\xff\x01\x00\x34\x4e\x08";
|
||||||
|
d_len = 32;
|
||||||
|
r = upx_zstd_decompress(c_data, 16, d_buf, &d_len, M_ZSTD, nullptr);
|
||||||
|
CHECK((r == 0 && d_len == 32));
|
||||||
|
r = upx_zstd_decompress(c_data, 15, d_buf, &d_len, M_ZSTD, nullptr);
|
||||||
|
CHECK(r == UPX_E_INPUT_OVERRUN);
|
||||||
|
d_len = 31;
|
||||||
|
r = upx_zstd_decompress(c_data, 16, d_buf, &d_len, M_ZSTD, nullptr);
|
||||||
|
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||||
|
UNUSED(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WITH_ZSTD
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
@@ -1,340 +0,0 @@
|
|||||||
/* compress_ucl.cpp --
|
|
||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
|
||||||
All Rights Reserved.
|
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
|
||||||
and/or modify them under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; see the file COPYING.
|
|
||||||
If not, write to the Free Software Foundation, Inc.,
|
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
|
|
||||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
|
||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "conf.h"
|
|
||||||
#include "compress.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
//
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static int convert_errno_from_ucl(int r)
|
|
||||||
{
|
|
||||||
switch (r)
|
|
||||||
{
|
|
||||||
case UCL_E_OK: return UPX_E_OK;
|
|
||||||
case UCL_E_ERROR: return UPX_E_ERROR;
|
|
||||||
case UCL_E_OUT_OF_MEMORY: return UPX_E_OUT_OF_MEMORY;
|
|
||||||
case UCL_E_NOT_COMPRESSIBLE: return UPX_E_NOT_COMPRESSIBLE;
|
|
||||||
case UCL_E_INPUT_OVERRUN: return UPX_E_INPUT_OVERRUN;
|
|
||||||
case UCL_E_OUTPUT_OVERRUN: return UPX_E_OUTPUT_OVERRUN;
|
|
||||||
case UCL_E_LOOKBEHIND_OVERRUN: return UPX_E_LOOKBEHIND_OVERRUN;
|
|
||||||
case UCL_E_EOF_NOT_FOUND: return UPX_E_EOF_NOT_FOUND;
|
|
||||||
case UCL_E_INPUT_NOT_CONSUMED: return UPX_E_INPUT_NOT_CONSUMED;
|
|
||||||
// case UCL_E_NOT_YET_IMPLEMENTED: return UPX_E_NOT_YET_IMPLEMENTED;
|
|
||||||
case UCL_E_INVALID_ARGUMENT: return UPX_E_INVALID_ARGUMENT;
|
|
||||||
// UCL extra:
|
|
||||||
case UCL_E_OVERLAP_OVERRUN: return UPX_E_ERROR;
|
|
||||||
}
|
|
||||||
return UPX_E_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
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;
|
|
||||||
if (cb && cb->nprogress)
|
|
||||||
cb->nprogress(cb, a, b);
|
|
||||||
}}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
//
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
|
||||||
upx_bytep dst, unsigned* dst_len,
|
|
||||||
upx_callback_p cb_parm,
|
|
||||||
int method, int level,
|
|
||||||
const upx_compress_config_t *cconf_parm,
|
|
||||||
upx_compress_result_t *cresult )
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
assert(level > 0); assert(cresult != nullptr);
|
|
||||||
|
|
||||||
COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))
|
|
||||||
|
|
||||||
ucl_progress_callback_t cb;
|
|
||||||
cb.callback = nullptr;
|
|
||||||
cb.user = nullptr;
|
|
||||||
if (cb_parm && cb_parm->nprogress) {
|
|
||||||
cb.callback = wrap_nprogress_ucl;
|
|
||||||
cb.user = cb_parm;
|
|
||||||
}
|
|
||||||
|
|
||||||
ucl_compress_config_t cconf; cconf.reset();
|
|
||||||
if (cconf_parm)
|
|
||||||
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
|
|
||||||
//res[0] = 1; // min_offset_found - NOT USED
|
|
||||||
res[1] = src_len - 1; // max_offset_found
|
|
||||||
//res[2] = 2; // min_match_found - NOT USED
|
|
||||||
res[3] = src_len - 1; // max_match_found
|
|
||||||
//res[4] = 1; // min_run_found - NOT USED
|
|
||||||
res[5] = src_len; // max_run_found
|
|
||||||
res[6] = 1; // first_offset_found
|
|
||||||
//res[7] = 999999; // same_match_offsets_found - NOT USED
|
|
||||||
|
|
||||||
// prepare bit-buffer settings
|
|
||||||
cconf.bb_endian = 0;
|
|
||||||
cconf.bb_size = 0;
|
|
||||||
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16)
|
|
||||||
{
|
|
||||||
static const unsigned char sizes[3] = {32, 8, 16};
|
|
||||||
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throwInternalError("unknown compression method");
|
|
||||||
return UPX_E_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// optimize compression parms
|
|
||||||
if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
|
|
||||||
cconf.max_offset = 8*1024-1;
|
|
||||||
else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
|
|
||||||
cconf.max_offset = 32*1024-1;
|
|
||||||
|
|
||||||
if M_IS_NRV2B(method)
|
|
||||||
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
|
|
||||||
&cb, level, &cconf, res);
|
|
||||||
else if M_IS_NRV2D(method)
|
|
||||||
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
|
|
||||||
&cb, level, &cconf, res);
|
|
||||||
else if M_IS_NRV2E(method)
|
|
||||||
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
|
|
||||||
&cb, level, &cconf, res);
|
|
||||||
else {
|
|
||||||
throwInternalError("unknown compression method");
|
|
||||||
return UPX_E_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure first_offset_found is set
|
|
||||||
if (res[6] == 0)
|
|
||||||
res[6] = 1;
|
|
||||||
|
|
||||||
return convert_errno_from_ucl(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
//
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
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 r;
|
|
||||||
|
|
||||||
switch (method)
|
|
||||||
{
|
|
||||||
case M_NRV2B_8:
|
|
||||||
r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2B_LE16:
|
|
||||||
r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2B_LE32:
|
|
||||||
r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2D_8:
|
|
||||||
r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2D_LE16:
|
|
||||||
r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2D_LE32:
|
|
||||||
r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2E_8:
|
|
||||||
r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2E_LE16:
|
|
||||||
r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2E_LE32:
|
|
||||||
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throwInternalError("unknown decompression method");
|
|
||||||
return UPX_E_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
UNUSED(cresult);
|
|
||||||
return convert_errno_from_ucl(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
//
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
case M_NRV2B_8:
|
|
||||||
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2B_LE16:
|
|
||||||
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2B_LE32:
|
|
||||||
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2D_8:
|
|
||||||
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2D_LE16:
|
|
||||||
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2D_LE32:
|
|
||||||
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2E_8:
|
|
||||||
r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2E_LE16:
|
|
||||||
r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
case M_NRV2E_LE32:
|
|
||||||
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,nullptr);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throwInternalError("unknown decompression method");
|
|
||||||
return UPX_E_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
UNUSED(cresult);
|
|
||||||
return convert_errno_from_ucl(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
// misc
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
static ucl_voidp __UCL_CDECL my_malloc(ucl_uint n) { return calloc(1, n); }
|
|
||||||
static void __UCL_CDECL my_free(ucl_voidp p) { free(p); }
|
|
||||||
}
|
|
||||||
|
|
||||||
int upx_ucl_init(void)
|
|
||||||
{
|
|
||||||
if (ucl_init() != UCL_E_OK)
|
|
||||||
return -1;
|
|
||||||
if (UCL_VERSION != ucl_version() || strcmp(UCL_VERSION_STRING, ucl_version_string()) != 0)
|
|
||||||
return -2;
|
|
||||||
ucl_set_malloc_hooks(my_malloc, my_free);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *upx_ucl_version_string(void)
|
|
||||||
{
|
|
||||||
return ucl_version_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned upx_ucl_adler32(const void *buf, unsigned len, unsigned adler)
|
|
||||||
{
|
|
||||||
return ucl_adler32(adler, (const ucl_bytep) buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0 /* UNUSED */
|
|
||||||
unsigned upx_ucl_crc32(const void *buf, unsigned len, unsigned crc)
|
|
||||||
{
|
|
||||||
return ucl_crc32(crc, (const ucl_bytep) buf, len);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
// Debug checks
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#if DEBUG && 1
|
|
||||||
|
|
||||||
#include "util/membuffer.h"
|
|
||||||
|
|
||||||
static bool check_ucl(const int method, const unsigned expected_c_len) {
|
|
||||||
const unsigned u_len = 16384;
|
|
||||||
const unsigned c_extra = 4096;
|
|
||||||
MemBuffer u_buf, c_buf, d_buf;
|
|
||||||
unsigned c_len, d_len;
|
|
||||||
upx_compress_result_t cresult;
|
|
||||||
int r;
|
|
||||||
const int level = 3; // don't waste time
|
|
||||||
|
|
||||||
u_buf.alloc(u_len);
|
|
||||||
memset(u_buf, 0, u_len);
|
|
||||||
c_buf.allocForCompression(u_len, c_extra);
|
|
||||||
d_buf.allocForUncompression(u_len);
|
|
||||||
|
|
||||||
c_len = c_buf.getSize() - c_extra;
|
|
||||||
r = upx_ucl_compress(u_buf, u_len, c_buf + c_extra, &c_len, nullptr, method, level, NULL_cconf, &cresult);
|
|
||||||
if (r != 0 || c_len != expected_c_len) return false;
|
|
||||||
|
|
||||||
d_len = d_buf.getSize();
|
|
||||||
r = upx_ucl_decompress(c_buf + c_extra, c_len, d_buf, &d_len, method, nullptr);
|
|
||||||
if (r != 0 || d_len != u_len) return false;
|
|
||||||
if (memcmp(u_buf, d_buf, u_len) != 0) return false;
|
|
||||||
|
|
||||||
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
|
|
||||||
//unsigned x_len = d_len;
|
|
||||||
//r = upx_ucl_test_overlap(c_buf, u_buf, c_extra, c_len, &x_len, method, nullptr);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("compress_ucl") {
|
|
||||||
CHECK(check_ucl(M_NRV2B_8, 34));
|
|
||||||
CHECK(check_ucl(M_NRV2B_LE16, 34));
|
|
||||||
CHECK(check_ucl(M_NRV2B_LE32, 34));
|
|
||||||
CHECK(check_ucl(M_NRV2D_8, 32));
|
|
||||||
CHECK(check_ucl(M_NRV2D_LE16, 32));
|
|
||||||
CHECK(check_ucl(M_NRV2D_LE32, 34));
|
|
||||||
CHECK(check_ucl(M_NRV2E_8, 32));
|
|
||||||
CHECK(check_ucl(M_NRV2E_LE16, 32));
|
|
||||||
CHECK(check_ucl(M_NRV2E_LE32, 34));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // DEBUG
|
|
||||||
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
|
||||||
+395
-373
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
#if (USE_CONSOLE)
|
#if (USE_CONSOLE)
|
||||||
|
|
||||||
@@ -34,58 +33,41 @@
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int init(FILE *f, int o, int now)
|
static int init(FILE *f, int o, int now) {
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
UNUSED(o);
|
UNUSED(o);
|
||||||
UNUSED(now);
|
UNUSED(now);
|
||||||
return CON_FILE;
|
return CON_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int set_fg(FILE *f, int fg) {
|
||||||
static int set_fg(FILE *f, int fg)
|
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
UNUSED(fg);
|
UNUSED(fg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print0(FILE *f, const char *s) {
|
||||||
static void print0(FILE *f, const char *s)
|
|
||||||
{
|
|
||||||
#if 1
|
#if 1
|
||||||
fputs(s, f);
|
fputs(s, f);
|
||||||
#else
|
#else
|
||||||
/* filter out all ANSI sequences */
|
/* filter out all ANSI sequences */
|
||||||
int c;
|
int c;
|
||||||
while ((c = *s++) != 0)
|
while ((c = *s++) != 0) {
|
||||||
{
|
if (c == '\033' && *s == ']') {
|
||||||
if (c == '\033' && *s == ']')
|
|
||||||
{
|
|
||||||
while (*s && *s != 'm')
|
while (*s && *s != 'm')
|
||||||
s++;
|
s++;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fputc(c, f);
|
fputc(c, f);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool intro(FILE *f) {
|
||||||
static bool intro(FILE *f)
|
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console_t console_file = {init, set_fg, print0, intro};
|
||||||
console_t console_file =
|
|
||||||
{
|
|
||||||
init,
|
|
||||||
set_fg,
|
|
||||||
print0,
|
|
||||||
intro
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* USE_CONSOLE */
|
#endif /* USE_CONSOLE */
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
FILE *con_term = nullptr;
|
FILE *con_term = nullptr;
|
||||||
|
|
||||||
@@ -41,9 +40,7 @@ console_t * con = &console_init;
|
|||||||
|
|
||||||
int con_mode = CON_INIT;
|
int con_mode = CON_INIT;
|
||||||
|
|
||||||
|
static void try_init(console_t *c, FILE *f) {
|
||||||
static void try_init(console_t *c, FILE *f)
|
|
||||||
{
|
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
assert(c);
|
assert(c);
|
||||||
@@ -56,8 +53,7 @@ static void try_init(console_t *c, FILE *f)
|
|||||||
if (k != opt->console)
|
if (k != opt->console)
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
if (k > con_mode)
|
if (k > con_mode) {
|
||||||
{
|
|
||||||
con_mode = k;
|
con_mode = k;
|
||||||
con = c;
|
con = c;
|
||||||
con->init = nullptr;
|
con->init = nullptr;
|
||||||
@@ -70,9 +66,7 @@ static void try_init(console_t *c, FILE *f)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_init(FILE *f) {
|
||||||
static int do_init(FILE *f)
|
|
||||||
{
|
|
||||||
assert(con_mode == CON_INIT);
|
assert(con_mode == CON_INIT);
|
||||||
|
|
||||||
try_init(&console_none, f);
|
try_init(&console_none, f);
|
||||||
@@ -98,13 +92,11 @@ static int do_init(FILE *f)
|
|||||||
return con_mode;
|
return con_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int init(FILE *f, int o, int now)
|
static int init(FILE *f, int o, int now) {
|
||||||
{
|
|
||||||
if (con != me)
|
if (con != me)
|
||||||
return con_mode;
|
return con_mode;
|
||||||
assert(o == -1);
|
assert(o == -1);
|
||||||
@@ -114,36 +106,23 @@ static int init(FILE *f, int o, int now)
|
|||||||
return do_init(f);
|
return do_init(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int set_fg(FILE *f, int fg) {
|
||||||
static int set_fg(FILE *f, int fg)
|
|
||||||
{
|
|
||||||
if (con == me)
|
if (con == me)
|
||||||
init(f, -1, -1);
|
init(f, -1, -1);
|
||||||
assert(con != me);
|
assert(con != me);
|
||||||
return con->set_fg(f, fg);
|
return con->set_fg(f, fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool intro(FILE *f) {
|
||||||
static bool intro(FILE *f)
|
|
||||||
{
|
|
||||||
if (con == me)
|
if (con == me)
|
||||||
init(f, -1, -1);
|
init(f, -1, -1);
|
||||||
assert(con != me);
|
assert(con != me);
|
||||||
return con->intro(f);
|
return con->intro(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console_t console_init = {init, set_fg, nullptr, intro};
|
||||||
|
|
||||||
console_t console_init =
|
void con_fprintf(FILE *f, const char *format, ...) {
|
||||||
{
|
|
||||||
init,
|
|
||||||
set_fg,
|
|
||||||
nullptr,
|
|
||||||
intro
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void con_fprintf(FILE *f, const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[80 * 25];
|
char buf[80 * 25];
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
#if (USE_CONSOLE)
|
#if (USE_CONSOLE)
|
||||||
|
|
||||||
@@ -34,44 +33,30 @@
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int init(FILE *f, int o, int now)
|
static int init(FILE *f, int o, int now) {
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
UNUSED(o);
|
UNUSED(o);
|
||||||
UNUSED(now);
|
UNUSED(now);
|
||||||
return CON_NONE;
|
return CON_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int set_fg(FILE *f, int fg) {
|
||||||
static int set_fg(FILE *f, int fg)
|
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
UNUSED(fg);
|
UNUSED(fg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print0(FILE *f, const char *s) {
|
||||||
static void print0(FILE *f, const char *s)
|
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
UNUSED(s);
|
UNUSED(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool intro(FILE *f) {
|
||||||
static bool intro(FILE *f)
|
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console_t console_none = {init, set_fg, print0, intro};
|
||||||
console_t console_none =
|
|
||||||
{
|
|
||||||
init,
|
|
||||||
set_fg,
|
|
||||||
print0,
|
|
||||||
intro
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* USE_CONSOLE */
|
#endif /* USE_CONSOLE */
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
#if (USE_SCREEN)
|
#if (USE_SCREEN)
|
||||||
|
|
||||||
@@ -35,13 +34,11 @@
|
|||||||
#define mask_fg 0x0f
|
#define mask_fg 0x0f
|
||||||
#define mask_bg 0xf0
|
#define mask_bg 0xf0
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int do_init(screen_t *s, int fd)
|
static int do_init(screen_t *s, int fd) {
|
||||||
{
|
|
||||||
int fg, bg;
|
int fg, bg;
|
||||||
|
|
||||||
if (s->init(s, fd) != 0)
|
if (s->init(s, fd) != 0)
|
||||||
@@ -59,8 +56,7 @@ static int do_init(screen_t *s, int fd)
|
|||||||
if (fg == (bg >> 4))
|
if (fg == (bg >> 4))
|
||||||
return -1;
|
return -1;
|
||||||
if (bg != BG_BLACK)
|
if (bg != BG_BLACK)
|
||||||
if (!s->isMono(s))
|
if (!s->isMono(s)) {
|
||||||
{
|
|
||||||
/* return 0; */ /* we could emulate ANSI mono */
|
/* return 0; */ /* we could emulate ANSI mono */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -68,30 +64,24 @@ static int do_init(screen_t *s, int fd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static screen_t *do_construct(screen_t *s, int fd) {
|
||||||
static screen_t *do_construct(screen_t *s, int fd)
|
|
||||||
{
|
|
||||||
if (!s)
|
if (!s)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (do_init(s,fd) != 0)
|
if (do_init(s, fd) != 0) {
|
||||||
{
|
|
||||||
s->destroy(s);
|
s->destroy(s);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static screen_t *screen = nullptr;
|
static screen_t *screen = nullptr;
|
||||||
|
|
||||||
static void __acc_cdecl_atexit do_destroy(void)
|
static void __acc_cdecl_atexit do_destroy(void) {
|
||||||
{
|
if (screen) {
|
||||||
if (screen)
|
|
||||||
{
|
|
||||||
if (screen->atExit)
|
if (screen->atExit)
|
||||||
screen->atExit();
|
screen->atExit();
|
||||||
screen->destroy(screen);
|
screen->destroy(screen);
|
||||||
@@ -99,16 +89,13 @@ static void __acc_cdecl_atexit do_destroy(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int mode = -1;
|
static int mode = -1;
|
||||||
static int init_fg = -1;
|
static int init_fg = -1;
|
||||||
static int init_bg = -1;
|
static int init_bg = -1;
|
||||||
static int cur_fg = -1;
|
static int cur_fg = -1;
|
||||||
static int cur_bg = -1;
|
static int cur_bg = -1;
|
||||||
|
|
||||||
|
static int init(FILE *f, int o, int now) {
|
||||||
static int init(FILE *f, int o, int now)
|
|
||||||
{
|
|
||||||
int fd = fileno(f);
|
int fd = fileno(f);
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@@ -155,17 +142,14 @@ static int init(FILE *f, int o, int now)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int set_fg(FILE *f, int fg) {
|
||||||
static int set_fg(FILE *f, int fg)
|
|
||||||
{
|
|
||||||
const int last_fg = cur_fg;
|
const int last_fg = cur_fg;
|
||||||
int f1 = fg & mask_fg;
|
int f1 = fg & mask_fg;
|
||||||
int f2 = init_fg & mask_fg;
|
int f2 = init_fg & mask_fg;
|
||||||
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
cur_fg = fg;
|
cur_fg = fg;
|
||||||
if (screen->isMono(screen))
|
if (screen->isMono(screen)) {
|
||||||
{
|
|
||||||
const int b = (init_bg & mask_bg) >> 4;
|
const int b = (init_bg & mask_bg) >> 4;
|
||||||
if (fg == -1) /* restore startup fg */
|
if (fg == -1) /* restore startup fg */
|
||||||
f1 = f2;
|
f1 = f2;
|
||||||
@@ -175,9 +159,7 @@ static int set_fg(FILE *f, int fg)
|
|||||||
f1 = (f2 == 0) ? 15 : 0;
|
f1 = (f2 == 0) ? 15 : 0;
|
||||||
else
|
else
|
||||||
f1 = (f2 == 0) ? 8 : 0;
|
f1 = (f2 == 0) ? 8 : 0;
|
||||||
}
|
} else if (con_mode == CON_ANSI_MONO && f1 != f2) {
|
||||||
else if (con_mode == CON_ANSI_MONO && f1 != f2)
|
|
||||||
{
|
|
||||||
f1 = f2 ^ 0x08;
|
f1 = f2 ^ 0x08;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,9 +167,7 @@ static int set_fg(FILE *f, int fg)
|
|||||||
return last_fg;
|
return last_fg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print0(FILE *f, const char *ss) {
|
||||||
static void print0(FILE *f, const char *ss)
|
|
||||||
{
|
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
int old_cx = 0, old_cy = 0;
|
int old_cx = 0, old_cy = 0;
|
||||||
const int sx = screen->getCols(screen);
|
const int sx = screen->getCols(screen);
|
||||||
@@ -200,54 +180,44 @@ static void print0(FILE *f, const char *ss)
|
|||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
|
|
||||||
screen->getCursor(screen, &old_cx, &old_cy);
|
screen->getCursor(screen, &old_cx, &old_cy);
|
||||||
cx = old_cx; cy = old_cy;
|
cx = old_cx;
|
||||||
|
cy = old_cy;
|
||||||
|
|
||||||
for (pass = 0; pass < 2; pass++)
|
for (pass = 0; pass < 2; pass++) {
|
||||||
{
|
|
||||||
const char *s = ss;
|
const char *s = ss;
|
||||||
// char buffer for pass 2
|
// char buffer for pass 2
|
||||||
char p[256 + 1];
|
char p[256 + 1];
|
||||||
int pi = 0, px = 0, py = 0;
|
int pi = 0, px = 0, py = 0;
|
||||||
|
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// walk over whitespace
|
// walk over whitespace
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
if (*s == '\n') {
|
||||||
if (*s == '\n')
|
|
||||||
{
|
|
||||||
cx = 0;
|
cx = 0;
|
||||||
cy++;
|
cy++;
|
||||||
}
|
} else if (*s == '\r') {
|
||||||
else if (*s == '\r')
|
|
||||||
{
|
|
||||||
cx = 0;
|
cx = 0;
|
||||||
if (pass > 0 && cy < sy)
|
if (pass > 0 && cy < sy)
|
||||||
screen->clearLine(screen, cy);
|
screen->clearLine(screen, cy);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
// adjust cursor
|
// adjust cursor
|
||||||
if (cx >= sx)
|
if (cx >= sx) {
|
||||||
{
|
|
||||||
cx = 0;
|
cx = 0;
|
||||||
cy++;
|
cy++;
|
||||||
}
|
}
|
||||||
if (pass > 0)
|
if (pass > 0) {
|
||||||
{
|
|
||||||
// check if we should print something
|
// check if we should print something
|
||||||
if (pi > 0 && (*s == 0 || py != cy))
|
if (pi > 0 && (*s == 0 || py != cy)) {
|
||||||
{
|
|
||||||
p[pi] = 0;
|
p[pi] = 0;
|
||||||
screen->putString(screen, p, px, py);
|
screen->putString(screen, p, px, py);
|
||||||
pi = 0;
|
pi = 0;
|
||||||
}
|
}
|
||||||
// check if we should scroll even more (this can happen
|
// check if we should scroll even more (this can happen
|
||||||
// if the string is longer than sy lines)
|
// if the string is longer than sy lines)
|
||||||
if (cy >= sy)
|
if (cy >= sy) {
|
||||||
{
|
|
||||||
int scroll_y = cy - sy + 1;
|
int scroll_y = cy - sy + 1;
|
||||||
screen->scrollUp(screen, scroll_y);
|
screen->scrollUp(screen, scroll_y);
|
||||||
cy -= scroll_y;
|
cy -= scroll_y;
|
||||||
@@ -258,11 +228,9 @@ static void print0(FILE *f, const char *ss)
|
|||||||
// done ?
|
// done ?
|
||||||
if (*s == 0)
|
if (*s == 0)
|
||||||
break;
|
break;
|
||||||
if (pass > 0)
|
if (pass > 0) {
|
||||||
{
|
|
||||||
// store current char
|
// store current char
|
||||||
if (pi == 0)
|
if (pi == 0) {
|
||||||
{
|
|
||||||
px = cx;
|
px = cx;
|
||||||
py = cy;
|
py = cy;
|
||||||
}
|
}
|
||||||
@@ -273,18 +241,15 @@ static void print0(FILE *f, const char *ss)
|
|||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass == 0)
|
if (pass == 0) {
|
||||||
{
|
|
||||||
// end of pass 1 - scroll up, restore cursor
|
// end of pass 1 - scroll up, restore cursor
|
||||||
if (cy >= sy)
|
if (cy >= sy) {
|
||||||
{
|
|
||||||
int scroll_y = cy - sy + 1;
|
int scroll_y = cy - sy + 1;
|
||||||
screen->scrollUp(screen, scroll_y);
|
screen->scrollUp(screen, scroll_y);
|
||||||
cy = old_cy - scroll_y;
|
cy = old_cy - scroll_y;
|
||||||
if (cy < 0)
|
if (cy < 0)
|
||||||
cy = 0;
|
cy = 0;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
cy = old_cy;
|
cy = old_cy;
|
||||||
cx = old_cx;
|
cx = old_cx;
|
||||||
}
|
}
|
||||||
@@ -294,9 +259,7 @@ static void print0(FILE *f, const char *ss)
|
|||||||
screen->refresh(screen);
|
screen->refresh(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool intro(FILE *f) {
|
||||||
static bool intro(FILE *f)
|
|
||||||
{
|
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
#if (USE_FRAMES)
|
#if (USE_FRAMES)
|
||||||
if (screen->intro)
|
if (screen->intro)
|
||||||
@@ -305,15 +268,7 @@ static bool intro(FILE *f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console_t console_screen = {init, set_fg, print0, intro};
|
||||||
console_t console_screen =
|
|
||||||
{
|
|
||||||
init,
|
|
||||||
set_fg,
|
|
||||||
print0,
|
|
||||||
intro
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* USE_SCREEN */
|
#endif /* USE_SCREEN */
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
@@ -64,9 +64,10 @@
|
|||||||
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
|
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
|
||||||
#define USE_SCREEN 1
|
#define USE_SCREEN 1
|
||||||
#define USE_SCREEN_WIN32 1
|
#define USE_SCREEN_WIN32 1
|
||||||
|
#elif 1 && (ACC_ARCH_M68K && ACC_OS_TOS)
|
||||||
|
#define NO_CONSOLE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if 0 || (NO_ANSI)
|
#if 0 || (NO_ANSI)
|
||||||
#undef USE_ANSI
|
#undef USE_ANSI
|
||||||
#endif
|
#endif
|
||||||
@@ -80,7 +81,6 @@
|
|||||||
#undef USE_FRAMES
|
#undef USE_FRAMES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if 0 || (USE_ANSI) || (USE_SCREEN)
|
#if 0 || (USE_ANSI) || (USE_SCREEN)
|
||||||
#define USE_CONSOLE 1
|
#define USE_CONSOLE 1
|
||||||
#endif
|
#endif
|
||||||
@@ -94,37 +94,23 @@
|
|||||||
#undef USE_FRAMES
|
#undef USE_FRAMES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
enum {
|
enum { CON_INIT, CON_NONE, CON_FILE, CON_ANSI_MONO, CON_ANSI_COLOR, CON_SCREEN, CON_UNUSED };
|
||||||
CON_INIT,
|
|
||||||
CON_NONE,
|
|
||||||
CON_FILE,
|
|
||||||
CON_ANSI_MONO,
|
|
||||||
CON_ANSI_COLOR,
|
|
||||||
CON_SCREEN,
|
|
||||||
CON_UNUSED
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#if (USE_CONSOLE)
|
#if (USE_CONSOLE)
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
int (*init)(FILE *f, int, int);
|
int (*init)(FILE *f, int, int);
|
||||||
int (*set_fg)(FILE *f, int fg);
|
int (*set_fg)(FILE *f, int fg);
|
||||||
void (*print0)(FILE *f, const char *s);
|
void (*print0)(FILE *f, const char *s);
|
||||||
bool (*intro)(FILE *f);
|
bool (*intro)(FILE *f);
|
||||||
}
|
} console_t;
|
||||||
console_t;
|
|
||||||
|
|
||||||
|
|
||||||
void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3);
|
void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3);
|
||||||
|
|
||||||
|
|
||||||
#define FG_BLACK 0x00
|
#define FG_BLACK 0x00
|
||||||
#define FG_BLUE 0x01
|
#define FG_BLUE 0x01
|
||||||
#define FG_GREEN 0x02
|
#define FG_GREEN 0x02
|
||||||
@@ -153,7 +139,6 @@ void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3);
|
|||||||
|
|
||||||
#endif /* USE_CONSOLE */
|
#endif /* USE_CONSOLE */
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -172,7 +157,6 @@ extern console_t console_ansi_mono;
|
|||||||
extern console_t console_ansi_color;
|
extern console_t console_ansi_color;
|
||||||
extern console_t console_screen;
|
extern console_t console_screen;
|
||||||
|
|
||||||
|
|
||||||
#define con_fg(f, x) con->set_fg(f, x)
|
#define con_fg(f, x) con->set_fg(f, x)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "conf.h"
|
#include "../conf.h"
|
||||||
|
|
||||||
#if (USE_SCREEN) && (ACC_OS_DOS32) && defined(__DJGPP__)
|
#if (USE_SCREEN) && (ACC_OS_DOS32) && defined(__DJGPP__)
|
||||||
#if (ACC_CC_GNUC >= 0x040300ul)
|
#if (ACC_CC_GNUC >= 0x040300ul)
|
||||||
@@ -81,7 +81,9 @@ struct screen_data_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* atExit information */
|
/* atExit information */
|
||||||
static struct { int cursor_shape; } ae = {-1};
|
static struct {
|
||||||
|
int cursor_shape;
|
||||||
|
} ae = {-1};
|
||||||
|
|
||||||
#if USE_SCROLLBACK
|
#if USE_SCROLLBACK
|
||||||
static __inline__ void sb_add(screen_t *this, int *val, int inc) {
|
static __inline__ void sb_add(screen_t *this, int *val, int inc) {
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "conf.h"
|
#include "../conf.h"
|
||||||
|
|
||||||
#if (USE_SCREEN)
|
#if (USE_SCREEN)
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "conf.h"
|
#include "../conf.h"
|
||||||
|
|
||||||
#if (USE_SCREEN) && (USE_SCREEN_VCSA)
|
#if (USE_SCREEN) && (USE_SCREEN_VCSA)
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,10 +25,19 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "conf.h"
|
#include "../conf.h"
|
||||||
|
|
||||||
#if (USE_SCREEN_WIN32)
|
#if (USE_SCREEN_WIN32)
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// direct screen access
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#include "../util/windows_lean.h"
|
||||||
|
#if (HAVE_CONIO_H)
|
||||||
|
#include <conio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
#define this self
|
#define this self
|
||||||
@@ -36,24 +45,6 @@
|
|||||||
#define mask_fg 0x0f
|
#define mask_fg 0x0f
|
||||||
#define mask_bg 0xf0
|
#define mask_bg 0xf0
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
// direct screen access
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200))
|
|
||||||
/* avoid -W4 warnings in <conio.h> */
|
|
||||||
#pragma warning(disable : 4032)
|
|
||||||
/* avoid -W4 warnings in <windows.h> */
|
|
||||||
#pragma warning(disable : 4201 4214 4514)
|
|
||||||
#endif
|
|
||||||
#if defined(__RSXNT__)
|
|
||||||
#define timeval win32_timeval /* struct timeval already in <sys/time.h> */
|
|
||||||
#endif
|
|
||||||
#include <windows.h>
|
|
||||||
#if (HAVE_CONIO_H)
|
|
||||||
#include <conio.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct screen_data_t {
|
struct screen_data_t {
|
||||||
HANDLE hi;
|
HANDLE hi;
|
||||||
HANDLE ho;
|
HANDLE ho;
|
||||||
@@ -266,6 +257,22 @@ static int init(screen_t *this, int fd) {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// check if we are running under Wine
|
||||||
|
// (this rather direct Win32 screen driver maps poorly to Unix terminals)
|
||||||
|
// ntdll.dll wine_get_version() was added in wine-0.9.59 (Apr 2008)
|
||||||
|
HMODULE ntdll = GetModuleHandleA("ntdll.dll");
|
||||||
|
if (ntdll != nullptr) {
|
||||||
|
typedef const char *(CDECL * wine_get_version_func_t)(void);
|
||||||
|
wine_get_version_func_t wine_get_version;
|
||||||
|
wine_get_version =
|
||||||
|
(wine_get_version_func_t) (void *) GetProcAddress(ntdll, "wine_get_version");
|
||||||
|
if (wine_get_version != nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
this->data->cursor_x = csbi->dwCursorPosition.X;
|
this->data->cursor_x = csbi->dwCursorPosition.X;
|
||||||
this->data->cursor_y = csbi->dwCursorPosition.Y;
|
this->data->cursor_y = csbi->dwCursorPosition.Y;
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,8 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __UPX_SCREEN_H
|
#pragma once
|
||||||
#define __UPX_SCREEN_H 1
|
|
||||||
|
|
||||||
#if (USE_SCREEN)
|
#if (USE_SCREEN)
|
||||||
|
|
||||||
@@ -99,6 +98,4 @@ void screen_show_frames(screen_t *);
|
|||||||
|
|
||||||
#endif /* USE_SCREEN */
|
#endif /* USE_SCREEN */
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
+62
-12
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
unsigned long Throwable::counter = 0;
|
/*static*/ upx_std_atomic(size_t) Throwable::debug_counter;
|
||||||
|
|
||||||
Throwable::Throwable(const char *m, int e, bool w) noexcept : super(),
|
Throwable::Throwable(const char *m, int e, bool w) noexcept : super(),
|
||||||
msg(nullptr),
|
msg(nullptr),
|
||||||
@@ -40,8 +40,8 @@ Throwable::Throwable(const char *m, int e, bool w) noexcept : super(),
|
|||||||
if (m)
|
if (m)
|
||||||
msg = strdup(m);
|
msg = strdup(m);
|
||||||
#if 0
|
#if 0
|
||||||
fprintf(stderr, "construct exception: %s %lu\n", msg, counter);
|
fprintf(stderr, "construct exception: %s %zu\n", msg, debug_counter);
|
||||||
counter++;
|
debug_counter += 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,15 +52,15 @@ Throwable::Throwable(const Throwable &other) noexcept : super(other),
|
|||||||
if (other.msg)
|
if (other.msg)
|
||||||
msg = strdup(other.msg);
|
msg = strdup(other.msg);
|
||||||
#if 0
|
#if 0
|
||||||
fprintf(stderr, "copy exception: %s %lu\n", msg, counter);
|
fprintf(stderr, "copy exception: %s %zu\n", msg, debug_counter);
|
||||||
counter++;
|
debug_counter += 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Throwable::~Throwable() noexcept {
|
Throwable::~Throwable() noexcept {
|
||||||
#if 0
|
#if 0
|
||||||
counter--;
|
debug_counter -= 1;
|
||||||
fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
|
fprintf(stderr, "destruct exception: %s %zu\n", msg, debug_counter);
|
||||||
#endif
|
#endif
|
||||||
if (msg)
|
if (msg)
|
||||||
free(msg);
|
free(msg);
|
||||||
@@ -72,7 +72,9 @@ Throwable::~Throwable() noexcept {
|
|||||||
|
|
||||||
void throwCantPack(const char *msg) {
|
void throwCantPack(const char *msg) {
|
||||||
// UGLY, but makes things easier
|
// UGLY, but makes things easier
|
||||||
if (opt->cmd == CMD_COMPRESS)
|
if (opt->cmd == CMD_NONE)
|
||||||
|
throw CantPackException(msg);
|
||||||
|
else if (opt->cmd == CMD_COMPRESS)
|
||||||
throw CantPackException(msg);
|
throw CantPackException(msg);
|
||||||
else if (opt->cmd == CMD_FILEINFO)
|
else if (opt->cmd == CMD_FILEINFO)
|
||||||
throw CantPackException(msg);
|
throw CantPackException(msg);
|
||||||
@@ -140,9 +142,57 @@ void throwEOFException(const char *msg, int e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
// varargs overloads
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void throwCantPack(const char *format, ...) {
|
||||||
|
char msg[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
(void) upx_safe_vsnprintf_noexcept(msg, sizeof(msg), format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
throwCantPack(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void throwCantUnpack(const char *format, ...) {
|
||||||
|
char msg[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
(void) upx_safe_vsnprintf_noexcept(msg, sizeof(msg), format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
throwCantUnpack(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void throwInternalError(const char *format, ...) {
|
||||||
|
char msg[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
(void) upx_safe_vsnprintf_noexcept(msg, sizeof(msg), format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
throwCantUnpack(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// util
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
void assertFailed(const char *expr, const char *file, int line, const char *func) noexcept {
|
||||||
|
fflush(stdout);
|
||||||
|
fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void throwAssertFailed(const char *expr, const char *file, int line, const char *func) {
|
||||||
|
if (opt->debug.debug_level >= 1) {
|
||||||
|
throwCantPack("corrupted file; details: %s (%s: %s: %d)", expr, file, func, line);
|
||||||
|
} else {
|
||||||
|
throwCantPack("corrupted file; try '--debug' for more details");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char *prettyName(const char *n) noexcept {
|
const char *prettyName(const char *n) noexcept {
|
||||||
if (n == nullptr)
|
if (n == nullptr)
|
||||||
return "(null)";
|
return "(null)";
|
||||||
@@ -151,7 +201,7 @@ const char *prettyName(const char *n) noexcept {
|
|||||||
n++;
|
n++;
|
||||||
else if (*n == ' ')
|
else if (*n == ' ')
|
||||||
n++;
|
n++;
|
||||||
else if (strncmp(n, "class ", 6) == 0) // Visual C++
|
else if (strncmp(n, "class ", 6) == 0) // Visual C++ (msvc)
|
||||||
n += 6;
|
n += 6;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|||||||
+58
-61
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -26,13 +26,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef UPX_EXCEPT_H__
|
|
||||||
#define UPX_EXCEPT_H__ 1
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
|
|
||||||
const char *prettyName(const char *n) noexcept;
|
const char *prettyName(const char *n) noexcept;
|
||||||
|
|
||||||
|
noinline void assertFailed(const char *expr, const char *file, int line, const char *func) noexcept;
|
||||||
|
noinline void throwAssertFailed(const char *expr, const char *file, int line, const char *func);
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// exceptions
|
// exceptions
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -44,7 +43,7 @@ protected:
|
|||||||
Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
|
Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Throwable(const Throwable &) noexcept;
|
Throwable(const Throwable &) noexcept; // copy constructor
|
||||||
virtual ~Throwable() noexcept;
|
virtual ~Throwable() noexcept;
|
||||||
const char *getMsg() const noexcept { return msg; }
|
const char *getMsg() const noexcept { return msg; }
|
||||||
int getErrno() const noexcept { return err; }
|
int getErrno() const noexcept { return err; }
|
||||||
@@ -53,24 +52,26 @@ public:
|
|||||||
private:
|
private:
|
||||||
char *msg = nullptr;
|
char *msg = nullptr;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool is_warning = false; // can be set by subclasses
|
bool is_warning = false; // can be set by subclasses
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disable assignment
|
// disable copy assignment and move
|
||||||
Throwable &operator=(const Throwable &) = delete;
|
Throwable &operator=(const Throwable &) noexcept DELETED_FUNCTION; // copy assignment
|
||||||
|
UPX_CXX_DISABLE_MOVE(Throwable)
|
||||||
// disable dynamic allocation => force throwing by value
|
// disable dynamic allocation => force throwing by value
|
||||||
ACC_CXX_DISABLE_NEW_DELETE
|
UPX_CXX_DISABLE_NEW_DELETE(Throwable)
|
||||||
|
// disable taking the address => force passing by reference
|
||||||
|
// [I'm not too sure about this design decision, but we can always allow it if needed]
|
||||||
|
UPX_CXX_DISABLE_ADDRESS(Throwable)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static unsigned long counter; // for debugging
|
static upx_std_atomic(size_t) debug_counter; // for debugging
|
||||||
};
|
};
|
||||||
|
|
||||||
// Exceptions can/should be caught
|
// Exceptions can/should be caught
|
||||||
class Exception : public Throwable {
|
class Exception : public Throwable {
|
||||||
typedef Throwable super;
|
typedef Throwable super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Exception(const char *m = nullptr, int e = 0, bool w = false) noexcept : super(m, e, w) {}
|
Exception(const char *m = nullptr, int e = 0, bool w = false) noexcept : super(m, e, w) {}
|
||||||
};
|
};
|
||||||
@@ -78,7 +79,6 @@ public:
|
|||||||
// Errors should not be caught (or re-thrown)
|
// Errors should not be caught (or re-thrown)
|
||||||
class Error : public Throwable {
|
class Error : public Throwable {
|
||||||
typedef Throwable super;
|
typedef Throwable super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Error(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
Error(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
||||||
};
|
};
|
||||||
@@ -87,37 +87,32 @@ public:
|
|||||||
// system exception
|
// system exception
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class OutOfMemoryException : public Exception {
|
class OutOfMemoryException final : public Exception {
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OutOfMemoryException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
OutOfMemoryException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class IOException : public Exception {
|
class IOException /*not_final*/ : public Exception {
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IOException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
IOException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class EOFException : public IOException {
|
class EOFException final : public IOException {
|
||||||
typedef IOException super;
|
typedef IOException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EOFException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
EOFException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileNotFoundException : public IOException {
|
class FileNotFoundException final : public IOException {
|
||||||
typedef IOException super;
|
typedef IOException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileNotFoundException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
FileNotFoundException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileAlreadyExistsException : public IOException {
|
class FileAlreadyExistsException final : public IOException {
|
||||||
typedef IOException super;
|
typedef IOException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileAlreadyExistsException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
FileAlreadyExistsException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
|
||||||
};
|
};
|
||||||
@@ -126,52 +121,45 @@ public:
|
|||||||
// application exceptions
|
// application exceptions
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class OverlayException : public Exception {
|
class OverlayException final : public Exception {
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OverlayException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
|
OverlayException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CantPackException : public Exception {
|
class CantPackException /*not_final*/ : public Exception {
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CantPackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
|
CantPackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class UnknownExecutableFormatException : public CantPackException {
|
class UnknownExecutableFormatException : public CantPackException {
|
||||||
typedef CantPackException super;
|
typedef CantPackException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnknownExecutableFormatException(const char *m = nullptr, bool w = false) noexcept
|
UnknownExecutableFormatException(const char *m = nullptr, bool w = false) noexcept
|
||||||
: super(m, w) {}
|
: super(m, w) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class AlreadyPackedException : public CantPackException {
|
class AlreadyPackedException final : public CantPackException {
|
||||||
typedef CantPackException super;
|
typedef CantPackException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
|
AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotCompressibleException : public CantPackException {
|
class NotCompressibleException final : public CantPackException {
|
||||||
typedef CantPackException super;
|
typedef CantPackException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NotCompressibleException(const char *m = nullptr) noexcept : super(m) {}
|
NotCompressibleException(const char *m = nullptr) noexcept : super(m) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CantUnpackException : public Exception {
|
class CantUnpackException /*not_final*/ : public Exception {
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CantUnpackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
|
CantUnpackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotPackedException : public CantUnpackException {
|
class NotPackedException final : public CantUnpackException {
|
||||||
typedef CantUnpackException super;
|
typedef CantUnpackException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NotPackedException(const char *m = nullptr) noexcept : super(m, true) {}
|
NotPackedException(const char *m = nullptr) noexcept : super(m, true) {}
|
||||||
};
|
};
|
||||||
@@ -180,9 +168,8 @@ public:
|
|||||||
// errors
|
// errors
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class InternalError : public Error {
|
class InternalError final : public Error {
|
||||||
typedef Error super;
|
typedef Error super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InternalError(const char *m = nullptr) noexcept : super(m, 0) {}
|
InternalError(const char *m = nullptr) noexcept : super(m, 0) {}
|
||||||
};
|
};
|
||||||
@@ -193,32 +180,42 @@ public:
|
|||||||
|
|
||||||
#undef NORET
|
#undef NORET
|
||||||
#if 1 && defined(__GNUC__)
|
#if 1 && defined(__GNUC__)
|
||||||
#define NORET __acc_noinline __attribute__((__noreturn__))
|
#define NORET noinline __attribute__((__noreturn__))
|
||||||
#else
|
#else
|
||||||
#define NORET __acc_noinline
|
#define NORET noinline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NORET void throwCantPack(const char *msg);
|
NORET void throwCantPack(const char *msg) may_throw;
|
||||||
NORET void throwCantPackExact();
|
NORET void throwCantPackExact() may_throw;
|
||||||
NORET void throwUnknownExecutableFormat(const char *msg = nullptr, bool warn = false);
|
NORET void throwUnknownExecutableFormat(const char *msg = nullptr, bool warn = false) may_throw;
|
||||||
NORET void throwNotCompressible(const char *msg = nullptr);
|
NORET void throwNotCompressible(const char *msg = nullptr) may_throw;
|
||||||
NORET void throwAlreadyPacked(const char *msg = nullptr);
|
NORET void throwAlreadyPacked(const char *msg = nullptr) may_throw;
|
||||||
NORET void throwAlreadyPackedByUPX(const char *msg = nullptr);
|
NORET void throwAlreadyPackedByUPX(const char *msg = nullptr) may_throw;
|
||||||
NORET void throwCantUnpack(const char *msg);
|
NORET void throwCantUnpack(const char *msg) may_throw;
|
||||||
NORET void throwNotPacked(const char *msg = nullptr);
|
NORET void throwNotPacked(const char *msg = nullptr) may_throw;
|
||||||
NORET void throwFilterException();
|
NORET void throwFilterException() may_throw;
|
||||||
NORET void throwBadLoader();
|
NORET void throwBadLoader() may_throw;
|
||||||
NORET void throwChecksumError();
|
NORET void throwChecksumError() may_throw;
|
||||||
NORET void throwCompressedDataViolation();
|
NORET void throwCompressedDataViolation() may_throw;
|
||||||
NORET void throwInternalError(const char *msg);
|
NORET void throwInternalError(const char *msg) may_throw;
|
||||||
NORET void throwOutOfMemoryException(const char *msg = nullptr);
|
NORET void throwOutOfMemoryException(const char *msg = nullptr) may_throw;
|
||||||
NORET void throwIOException(const char *msg = nullptr, int e = 0);
|
NORET void throwIOException(const char *msg = nullptr, int e = 0) may_throw;
|
||||||
NORET void throwEOFException(const char *msg = nullptr, int e = 0);
|
NORET void throwEOFException(const char *msg = nullptr, int e = 0) may_throw;
|
||||||
|
|
||||||
|
// some C++ template wizardry is needed to overload throwCantPack() for varargs
|
||||||
|
template <class T>
|
||||||
|
void throwCantPack(const T *, ...) DELETED_FUNCTION;
|
||||||
|
template <>
|
||||||
|
NORET void throwCantPack(const char *format, ...) may_throw attribute_format(1, 2);
|
||||||
|
template <class T>
|
||||||
|
void throwCantUnpack(const T *, ...) DELETED_FUNCTION;
|
||||||
|
template <>
|
||||||
|
NORET void throwCantUnpack(const char *format, ...) may_throw attribute_format(1, 2);
|
||||||
|
template <class T>
|
||||||
|
void throwInternalError(const T *, ...) DELETED_FUNCTION;
|
||||||
|
template <>
|
||||||
|
NORET void throwInternalError(const char *format, ...) may_throw attribute_format(1, 2);
|
||||||
|
|
||||||
#undef NORET
|
#undef NORET
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+82
-51
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -29,11 +29,12 @@
|
|||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// static functions
|
// static file-related util functions; will throw on error
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void FileBase::chmod(const char *name, int mode) {
|
/*static*/ void FileBase::chmod(const char *name, int mode) {
|
||||||
#if (HAVE_CHMOD)
|
assert(name != nullptr && name[0] != 0);
|
||||||
|
#if HAVE_CHMOD
|
||||||
if (::chmod(name, mode) != 0)
|
if (::chmod(name, mode) != 0)
|
||||||
throwIOException(name, errno);
|
throwIOException(name, errno);
|
||||||
#else
|
#else
|
||||||
@@ -42,7 +43,7 @@ void FileBase::chmod(const char *name, int mode) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBase::rename(const char *old_, const char *new_) {
|
/*static*/ void FileBase::rename(const char *old_, const char *new_) {
|
||||||
#if (ACC_OS_DOS32) && defined(__DJGPP__)
|
#if (ACC_OS_DOS32) && defined(__DJGPP__)
|
||||||
if (::_rename(old_, new_) != 0)
|
if (::_rename(old_, new_) != 0)
|
||||||
#else
|
#else
|
||||||
@@ -51,29 +52,34 @@ void FileBase::rename(const char *old_, const char *new_) {
|
|||||||
throwIOException("rename error", errno);
|
throwIOException("rename error", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBase::unlink(const char *name) {
|
/*static*/ bool FileBase::unlink_noexcept(const char *name) noexcept {
|
||||||
if (::unlink(name) != 0)
|
assert_noexcept(name != nullptr && name[0] != 0);
|
||||||
|
bool success = ::unlink(name) == 0;
|
||||||
|
#if HAVE_CHMOD
|
||||||
|
if (!success)
|
||||||
|
success = (::chmod(name, 0666) == 0 && ::unlink(name) == 0);
|
||||||
|
#endif
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*static*/ void FileBase::unlink(const char *name) {
|
||||||
|
if (!unlink_noexcept(name))
|
||||||
throwIOException(name, errno);
|
throwIOException(name, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
// FileBase
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
FileBase::FileBase()
|
FileBase::~FileBase() may_throw {
|
||||||
: _fd(-1), _flags(0), _shflags(0), _mode(0), _name(nullptr), _offset(0), _length(0) {
|
|
||||||
memset(&st, 0, sizeof(st));
|
|
||||||
}
|
|
||||||
|
|
||||||
FileBase::~FileBase() {
|
|
||||||
#if 0 && defined(__GNUC__) // debug
|
#if 0 && defined(__GNUC__) // debug
|
||||||
if (isOpen())
|
if (isOpen())
|
||||||
fprintf(stderr, "%s: %s\n", _name, __PRETTY_FUNCTION__);
|
fprintf(stderr, "%s: %s\n", _name, __PRETTY_FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
|
if (std::uncaught_exceptions() == 0)
|
||||||
// FIXME: we should use close() during exception unwinding but
|
closex(); // may_throw
|
||||||
// closex() otherwise
|
else
|
||||||
closex();
|
close_noexcept(); // currently in exception unwinding, use noexcept variant
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileBase::do_sopen() {
|
bool FileBase::do_sopen() {
|
||||||
@@ -98,7 +104,7 @@ bool FileBase::do_sopen() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileBase::close() {
|
bool FileBase::close_noexcept() noexcept {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO)
|
if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO)
|
||||||
if (::close(_fd) == -1)
|
if (::close(_fd) == -1)
|
||||||
@@ -112,11 +118,12 @@ bool FileBase::close() {
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBase::closex() {
|
void FileBase::closex() may_throw {
|
||||||
if (!close())
|
if (!close_noexcept())
|
||||||
throwIOException("close failed", errno);
|
throwIOException("close failed", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return value of ::seek is the resulting file offset (same as ::tell())
|
||||||
upx_off_t FileBase::seek(upx_off_t off, int whence) {
|
upx_off_t FileBase::seek(upx_off_t off, int whence) {
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
throwIOException("bad seek 1");
|
throwIOException("bad seek 1");
|
||||||
@@ -125,16 +132,18 @@ upx_off_t FileBase::seek(upx_off_t off, int whence) {
|
|||||||
if (off < 0)
|
if (off < 0)
|
||||||
throwIOException("bad seek 2");
|
throwIOException("bad seek 2");
|
||||||
off += _offset;
|
off += _offset;
|
||||||
}
|
} else if (whence == SEEK_END) {
|
||||||
if (whence == SEEK_END) {
|
|
||||||
if (off > 0)
|
if (off > 0)
|
||||||
throwIOException("bad seek 3");
|
throwIOException("bad seek 3");
|
||||||
off += _offset + _length;
|
off += _offset + _length;
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
}
|
} else if (whence == SEEK_CUR) {
|
||||||
if (::lseek(_fd, off, whence) < 0)
|
} else
|
||||||
|
throwInternalError("bad seek: whence");
|
||||||
|
upx_off_t l = ::lseek(_fd, off, whence);
|
||||||
|
if (l < 0)
|
||||||
throwIOException("seek error", errno);
|
throwIOException("seek error", errno);
|
||||||
return off - _offset;
|
return l - _offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
upx_off_t FileBase::tell() const {
|
upx_off_t FileBase::tell() const {
|
||||||
@@ -154,13 +163,11 @@ void FileBase::set_extent(upx_off_t offset, upx_off_t length) {
|
|||||||
upx_off_t FileBase::st_size() const { return _length; }
|
upx_off_t FileBase::st_size() const { return _length; }
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
// InputFile
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
InputFile::InputFile() {}
|
|
||||||
|
|
||||||
void InputFile::sopen(const char *name, int flags, int shflags) {
|
void InputFile::sopen(const char *name, int flags, int shflags) {
|
||||||
close();
|
closex();
|
||||||
_name = name;
|
_name = name;
|
||||||
_flags = flags;
|
_flags = flags;
|
||||||
_shflags = shflags;
|
_shflags = shflags;
|
||||||
@@ -178,10 +185,10 @@ void InputFile::sopen(const char *name, int flags, int shflags) {
|
|||||||
_length_orig = _length;
|
_length_orig = _length;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InputFile::read(SPAN_P(void) buf, int len) {
|
int InputFile::read(SPAN_P(void) buf, upx_int64_t blen) {
|
||||||
if (!isOpen() || len < 0)
|
if (!isOpen() || blen < 0)
|
||||||
throwIOException("bad read");
|
throwIOException("bad read");
|
||||||
mem_size_assert(1, len); // sanity check
|
int len = (int) mem_size(1, blen); // sanity check
|
||||||
errno = 0;
|
errno = 0;
|
||||||
long l = acc_safe_hread(_fd, raw_bytes(buf, len), len);
|
long l = acc_safe_hread(_fd, raw_bytes(buf, len), len);
|
||||||
if (errno)
|
if (errno)
|
||||||
@@ -189,9 +196,9 @@ int InputFile::read(SPAN_P(void) buf, int len) {
|
|||||||
return (int) l;
|
return (int) l;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InputFile::readx(SPAN_P(void) buf, int len) {
|
int InputFile::readx(SPAN_P(void) buf, upx_int64_t blen) {
|
||||||
int l = this->read(buf, len);
|
int l = this->read(buf, blen);
|
||||||
if (l != len)
|
if (l != blen)
|
||||||
throwEOFException();
|
throwEOFException();
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@@ -206,13 +213,11 @@ upx_off_t InputFile::seek(upx_off_t off, int whence) {
|
|||||||
upx_off_t InputFile::st_size_orig() const { return _length_orig; }
|
upx_off_t InputFile::st_size_orig() const { return _length_orig; }
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
// OutputFile
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
OutputFile::OutputFile() : bytes_written(0) {}
|
|
||||||
|
|
||||||
void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
|
void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
|
||||||
close();
|
closex();
|
||||||
_name = name;
|
_name = name;
|
||||||
_flags = flags;
|
_flags = flags;
|
||||||
_shflags = shflags;
|
_shflags = shflags;
|
||||||
@@ -234,7 +239,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OutputFile::openStdout(int flags, bool force) {
|
bool OutputFile::openStdout(int flags, bool force) {
|
||||||
close();
|
closex();
|
||||||
int fd = STDOUT_FILENO;
|
int fd = STDOUT_FILENO;
|
||||||
if (!force && acc_isatty(fd))
|
if (!force && acc_isatty(fd))
|
||||||
return false;
|
return false;
|
||||||
@@ -250,22 +255,33 @@ bool OutputFile::openStdout(int flags, bool force) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputFile::write(SPAN_0(const void) buf, int len) {
|
void OutputFile::write(SPAN_0(const void) buf, upx_int64_t blen) {
|
||||||
if (!isOpen() || len < 0)
|
if (!isOpen() || blen < 0)
|
||||||
throwIOException("bad write");
|
throwIOException("bad write");
|
||||||
// allow nullptr if len == 0
|
// allow nullptr if blen == 0
|
||||||
if (len == 0)
|
if (blen == 0)
|
||||||
return;
|
return;
|
||||||
mem_size_assert(1, len); // sanity check
|
int len = (int) mem_size(1, blen); // sanity check
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#if 0
|
#if WITH_XSPAN >= 2
|
||||||
fprintf(stderr, "write %p %zd (%p) %d\n", buf.raw_ptr(), buf.raw_size_in_bytes(),
|
NO_fprintf(stderr, "write %p %zd (%p) %d\n", buf.raw_ptr(), buf.raw_size_in_bytes(),
|
||||||
buf.raw_base(), len);
|
buf.raw_base(), len);
|
||||||
#endif
|
#endif
|
||||||
long l = acc_safe_hwrite(_fd, raw_bytes(buf, len), len);
|
long l = acc_safe_hwrite(_fd, raw_bytes(buf, len), len);
|
||||||
if (l != len)
|
if (l != len)
|
||||||
throwIOException("write error", errno);
|
throwIOException("write error", errno);
|
||||||
bytes_written += len;
|
bytes_written += len;
|
||||||
|
#if TESTING && 0
|
||||||
|
static upx_std_atomic(bool) dumping;
|
||||||
|
if (!dumping) {
|
||||||
|
dumping = true;
|
||||||
|
char fn[64];
|
||||||
|
static int part = 0;
|
||||||
|
snprintf(fn, sizeof(fn), "upx-dump-%04d.data", part++);
|
||||||
|
OutputFile::dump(fn, buf, len);
|
||||||
|
dumping = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
upx_off_t OutputFile::st_size() const {
|
upx_off_t OutputFile::st_size() const {
|
||||||
@@ -316,7 +332,7 @@ upx_off_t OutputFile::seek(upx_off_t off, int whence) {
|
|||||||
void OutputFile::set_extent(upx_off_t offset, upx_off_t length) {
|
void OutputFile::set_extent(upx_off_t offset, upx_off_t length) {
|
||||||
super::set_extent(offset, length);
|
super::set_extent(offset, length);
|
||||||
bytes_written = 0;
|
bytes_written = 0;
|
||||||
if (0 == offset && (upx_off_t) ~0u == length) {
|
if (0 == offset && 0xffffffffLL == length) { // TODO: check all callers of this method
|
||||||
if (::fstat(_fd, &st) != 0)
|
if (::fstat(_fd, &st) != 0)
|
||||||
throwIOException(_name, errno);
|
throwIOException(_name, errno);
|
||||||
_length = st.st_size - offset;
|
_length = st.st_size - offset;
|
||||||
@@ -333,7 +349,7 @@ upx_off_t OutputFile::unset_extent() {
|
|||||||
return _length;
|
return _length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputFile::dump(const char *name, SPAN_P(const void) buf, int len, int flags) {
|
/*static*/ void OutputFile::dump(const char *name, SPAN_P(const void) buf, int len, int flags) {
|
||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
flags = O_CREAT | O_TRUNC;
|
flags = O_CREAT | O_TRUNC;
|
||||||
flags |= O_WRONLY | O_BINARY;
|
flags |= O_WRONLY | O_BINARY;
|
||||||
@@ -343,4 +359,19 @@ void OutputFile::dump(const char *name, SPAN_P(const void) buf, int len, int fla
|
|||||||
f.closex();
|
f.closex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
TEST_CASE("file") {
|
||||||
|
InputFile fi;
|
||||||
|
CHECK(!fi.isOpen());
|
||||||
|
CHECK(fi.getFd() == -1);
|
||||||
|
CHECK(fi.st_size() == 0);
|
||||||
|
OutputFile fo;
|
||||||
|
CHECK(!fo.isOpen());
|
||||||
|
CHECK(fo.getFd() == -1);
|
||||||
|
CHECK(fo.getBytesWritten() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+21
-26
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -26,8 +26,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef UPX_FILE_H__
|
|
||||||
#define UPX_FILE_H__ 1
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
@@ -35,15 +33,15 @@
|
|||||||
|
|
||||||
class FileBase {
|
class FileBase {
|
||||||
protected:
|
protected:
|
||||||
FileBase();
|
explicit FileBase() noexcept = default;
|
||||||
virtual ~FileBase();
|
virtual ~FileBase() may_throw;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool close();
|
bool close_noexcept() noexcept;
|
||||||
void closex();
|
void closex() may_throw;
|
||||||
bool isOpen() const { return _fd >= 0; }
|
bool isOpen() const noexcept { return _fd >= 0; }
|
||||||
int getFd() const { return _fd; }
|
int getFd() const noexcept { return _fd; }
|
||||||
const char *getName() const { return _name; }
|
const char *getName() const noexcept { return _name; }
|
||||||
|
|
||||||
virtual upx_off_t seek(upx_off_t off, int whence);
|
virtual upx_off_t seek(upx_off_t off, int whence);
|
||||||
upx_off_t tell() const;
|
upx_off_t tell() const;
|
||||||
@@ -51,10 +49,11 @@ public:
|
|||||||
virtual void set_extent(upx_off_t offset, upx_off_t length);
|
virtual void set_extent(upx_off_t offset, upx_off_t length);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// static file-related util functions
|
// static file-related util functions; will throw on error
|
||||||
static void chmod(const char *name, int mode);
|
static void chmod(const char *name, int mode) may_throw;
|
||||||
static void rename(const char *old_, const char *new_);
|
static void rename(const char *old_, const char *new_) may_throw;
|
||||||
static void unlink(const char *name);
|
static void unlink(const char *name) may_throw;
|
||||||
|
static bool unlink_noexcept(const char *name) noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool do_sopen();
|
bool do_sopen();
|
||||||
@@ -78,14 +77,13 @@ class InputFile final : public FileBase {
|
|||||||
typedef FileBase super;
|
typedef FileBase super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InputFile();
|
explicit InputFile() noexcept = default;
|
||||||
virtual ~InputFile() {}
|
|
||||||
|
|
||||||
void sopen(const char *name, int flags, int shflags);
|
void sopen(const char *name, int flags, int shflags);
|
||||||
void open(const char *name, int flags) { sopen(name, flags, -1); }
|
void open(const char *name, int flags) { sopen(name, flags, -1); }
|
||||||
|
|
||||||
int read(SPAN_P(void) buf, int len);
|
int read(SPAN_P(void) buf, upx_int64_t blen);
|
||||||
int readx(SPAN_P(void) buf, int len);
|
int readx(SPAN_P(void) buf, upx_int64_t blen);
|
||||||
|
|
||||||
virtual upx_off_t seek(upx_off_t off, int whence) override;
|
virtual upx_off_t seek(upx_off_t off, int whence) override;
|
||||||
upx_off_t st_size_orig() const;
|
upx_off_t st_size_orig() const;
|
||||||
@@ -102,15 +100,14 @@ class OutputFile final : public FileBase {
|
|||||||
typedef FileBase super;
|
typedef FileBase super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OutputFile();
|
explicit OutputFile() noexcept = default;
|
||||||
virtual ~OutputFile() {}
|
|
||||||
|
|
||||||
void sopen(const char *name, int flags, int shflags, int mode);
|
void sopen(const char *name, int flags, int shflags, int mode);
|
||||||
void open(const char *name, int flags, int mode) { sopen(name, flags, -1, mode); }
|
void open(const char *name, int flags, int mode) { sopen(name, flags, -1, mode); }
|
||||||
bool openStdout(int flags = 0, bool force = false);
|
bool openStdout(int flags = 0, bool force = false);
|
||||||
|
|
||||||
// info: allow nullptr if len == 0
|
// info: allow nullptr if blen == 0
|
||||||
void write(SPAN_0(const void) buf, int len);
|
void write(SPAN_0(const void) buf, upx_int64_t blen);
|
||||||
|
|
||||||
virtual upx_off_t seek(upx_off_t off, int whence) override;
|
virtual upx_off_t seek(upx_off_t off, int whence) override;
|
||||||
virtual upx_off_t st_size() const override; // { return _length; }
|
virtual upx_off_t st_size() const override; // { return _length; }
|
||||||
@@ -119,7 +116,7 @@ public:
|
|||||||
|
|
||||||
upx_off_t getBytesWritten() const { return bytes_written; }
|
upx_off_t getBytesWritten() const { return bytes_written; }
|
||||||
|
|
||||||
// FIXME - these won't work when using the '--stdout' option
|
// FIXME - this won't work when using the '--stdout' option
|
||||||
void rewrite(SPAN_P(const void) buf, int len);
|
void rewrite(SPAN_P(const void) buf, int len);
|
||||||
|
|
||||||
// util
|
// util
|
||||||
@@ -129,6 +126,4 @@ protected:
|
|||||||
upx_off_t bytes_written = 0;
|
upx_off_t bytes_written = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+40
-58
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,68 +25,56 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static //inline
|
static void initFilter(Filter *f, byte *buf, unsigned buf_len) noexcept {
|
||||||
void initFilter(Filter *f, upx_byte *buf, unsigned buf_len)
|
|
||||||
{
|
|
||||||
f->buf = buf;
|
f->buf = buf;
|
||||||
f->buf_len = buf_len;
|
f->buf_len = buf_len;
|
||||||
// clear output parameters
|
// clear output parameters
|
||||||
f->calls = f->wrongcalls = f->noncalls = f->firstcall = f->lastcall = 0;
|
f->calls = f->wrongcalls = f->noncalls = f->firstcall = f->lastcall = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// get a FilterEntry
|
// get a FilterEntry
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
const FilterImp::FilterEntry *FilterImp::getFilter(int id)
|
/*static*/ const FilterImpl::FilterEntry *FilterImpl::getFilter(int id) {
|
||||||
{
|
static upx_uint8_t filter_map[256];
|
||||||
static bool done = false;
|
static upx_std_once_flag init_done;
|
||||||
static unsigned char filter_map[256];
|
|
||||||
|
|
||||||
if (!done)
|
upx_std_call_once(init_done, []() noexcept {
|
||||||
{
|
// init the filter_map[] (using a lambda function)
|
||||||
// init the filter_map[]
|
assert_noexcept(n_filters <= 254); // as 0xff means "empty slot"
|
||||||
assert(n_filters <= 254); // as 0xff means "empty slot"
|
|
||||||
memset(filter_map, 0xff, sizeof(filter_map));
|
memset(filter_map, 0xff, sizeof(filter_map));
|
||||||
for (int i = 0; i < n_filters; i++)
|
for (int i = 0; i < n_filters; i++) {
|
||||||
{
|
|
||||||
int filter_id = filters[i].id;
|
int filter_id = filters[i].id;
|
||||||
assert(filter_id >= 0 && filter_id <= 255);
|
assert_noexcept(filter_id >= 0 && filter_id <= 255);
|
||||||
assert(filter_map[filter_id] == 0xff);
|
assert_noexcept(filter_map[filter_id] == 0xff);
|
||||||
filter_map[filter_id] = (unsigned char) i;
|
filter_map[filter_id] = (upx_uint8_t) i;
|
||||||
}
|
|
||||||
done = true;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (id < 0 || id > 255)
|
if (id < 0 || id > 255)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
unsigned index = filter_map[id];
|
unsigned index = filter_map[id];
|
||||||
if (index == 0xff) // empty slot
|
if (index == 0xff) // empty slot
|
||||||
return nullptr;
|
return nullptr;
|
||||||
assert(filters[index].id == id);
|
assert_noexcept(filters[index].id == id);
|
||||||
return &filters[index];
|
return &filters[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/ bool Filter::isValidFilter(int filter_id) {
|
||||||
bool Filter::isValidFilter(int filter_id)
|
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(filter_id);
|
||||||
{
|
|
||||||
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(filter_id);
|
|
||||||
return fe != nullptr;
|
return fe != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
|
/*static*/ bool Filter::isValidFilter(int filter_id, const int *allowed_filters) {
|
||||||
{
|
|
||||||
if (!isValidFilter(filter_id))
|
if (!isValidFilter(filter_id))
|
||||||
return false;
|
return false;
|
||||||
if (filter_id == 0)
|
if (filter_id == 0)
|
||||||
@@ -99,13 +87,13 @@ bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// high level API
|
// high level API
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void Filter::init(int id_, unsigned addvalue_)
|
Filter::Filter(int level) noexcept : clevel(level) { init(); }
|
||||||
{
|
|
||||||
|
void Filter::init(int id_, unsigned addvalue_) noexcept {
|
||||||
this->id = id_;
|
this->id = id_;
|
||||||
initFilter(this, nullptr, 0);
|
initFilter(this, nullptr, 0);
|
||||||
// clear input parameters
|
// clear input parameters
|
||||||
@@ -116,12 +104,11 @@ void Filter::init(int id_, unsigned addvalue_)
|
|||||||
this->n_mru = 0;
|
this->n_mru = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Filter::filter(SPAN_0(byte) xbuf, unsigned buf_len_) {
|
||||||
bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
|
byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
||||||
{
|
|
||||||
initFilter(this, buf_, buf_len_);
|
initFilter(this, buf_, buf_len_);
|
||||||
|
|
||||||
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id);
|
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
||||||
if (fe == nullptr)
|
if (fe == nullptr)
|
||||||
throwInternalError("filter-1");
|
throwInternalError("filter-1");
|
||||||
if (fe->id == 0)
|
if (fe->id == 0)
|
||||||
@@ -138,10 +125,10 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
|
|||||||
if (clevel != 1)
|
if (clevel != 1)
|
||||||
this->adler = upx_adler32(this->buf, this->buf_len);
|
this->adler = upx_adler32(this->buf, this->buf_len);
|
||||||
|
|
||||||
//printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
NO_printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
||||||
// OutputFile::dump("filter.dat", buf, buf_len);
|
// OutputFile::dump("filter.dat", buf, buf_len);
|
||||||
int r = (*fe->do_filter)(this);
|
int r = (*fe->do_filter)(this);
|
||||||
//printf("filter: %02x %d\n", fe->id, r);
|
NO_printf("filter: %02x %d\n", fe->id, r);
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
throwFilterException();
|
throwFilterException();
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
@@ -149,12 +136,11 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Filter::unfilter(SPAN_0(byte) xbuf, unsigned buf_len_, bool verify_checksum) {
|
||||||
void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
|
byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
||||||
{
|
|
||||||
initFilter(this, buf_, buf_len_);
|
initFilter(this, buf_, buf_len_);
|
||||||
|
|
||||||
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id);
|
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
||||||
if (fe == nullptr)
|
if (fe == nullptr)
|
||||||
throwInternalError("unfilter-1");
|
throwInternalError("unfilter-1");
|
||||||
if (fe->id == 0)
|
if (fe->id == 0)
|
||||||
@@ -166,24 +152,21 @@ void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
|
|||||||
if (!fe->do_unfilter)
|
if (!fe->do_unfilter)
|
||||||
throwInternalError("unfilter-2");
|
throwInternalError("unfilter-2");
|
||||||
|
|
||||||
//printf("unfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
NO_printf("unfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
||||||
int r = (*fe->do_unfilter)(this);
|
int r = (*fe->do_unfilter)(this);
|
||||||
//printf("unfilter: %02x %d\n", fe->id, r);
|
NO_printf("unfilter: %02x %d\n", fe->id, r);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
throwInternalError("unfilter-3");
|
throwInternalError("unfilter-3");
|
||||||
// OutputFile::dump("unfilter.dat", buf, buf_len);
|
// OutputFile::dump("unfilter.dat", buf, buf_len);
|
||||||
|
|
||||||
// verify checksum
|
// verify checksum
|
||||||
if (verify_checksum && clevel != 1)
|
if (verify_checksum && clevel != 1) {
|
||||||
{
|
|
||||||
if (this->adler != upx_adler32(this->buf, this->buf_len))
|
if (this->adler != upx_adler32(this->buf, this->buf_len))
|
||||||
throwInternalError("unfilter-4");
|
throwInternalError("unfilter-4");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Filter::verifyUnfilter() {
|
||||||
void Filter::verifyUnfilter()
|
|
||||||
{
|
|
||||||
// Note:
|
// Note:
|
||||||
// This verify is just because of complete paranoia that there
|
// This verify is just because of complete paranoia that there
|
||||||
// could be a hidden bug in the filter implementation, and
|
// could be a hidden bug in the filter implementation, and
|
||||||
@@ -193,20 +176,19 @@ void Filter::verifyUnfilter()
|
|||||||
// See also:
|
// See also:
|
||||||
// Packer::verifyOverlappingDecompression()
|
// Packer::verifyOverlappingDecompression()
|
||||||
|
|
||||||
//printf("verifyUnfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
NO_printf("verifyUnfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
||||||
if (clevel != 1)
|
if (clevel != 1)
|
||||||
unfilter(this->buf, this->buf_len, true);
|
unfilter(this->buf, this->buf_len, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Filter::scan(SPAN_0(const byte) xbuf, unsigned buf_len_) {
|
||||||
bool Filter::scan(const upx_byte *buf_, unsigned buf_len_)
|
const byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
||||||
{
|
|
||||||
// Note: must use const_cast here. This is fine as the scan
|
// Note: must use const_cast here. This is fine as the scan
|
||||||
// implementations (fe->do_scan) actually don't change the buffer.
|
// implementations (fe->do_scan) actually don't change the buffer.
|
||||||
upx_byte *b = const_cast<upx_byte *>(buf_);
|
byte *const b = const_cast<byte *>(buf_);
|
||||||
initFilter(this, b, buf_len_);
|
initFilter(this, b, buf_len_);
|
||||||
|
|
||||||
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id);
|
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
||||||
if (fe == nullptr)
|
if (fe == nullptr)
|
||||||
throwInternalError("scan-1");
|
throwInternalError("scan-1");
|
||||||
if (fe->id == 0)
|
if (fe->id == 0)
|
||||||
@@ -218,9 +200,9 @@ bool Filter::scan(const upx_byte *buf_, unsigned buf_len_)
|
|||||||
if (!fe->do_scan)
|
if (!fe->do_scan)
|
||||||
throwInternalError("scan-2");
|
throwInternalError("scan-2");
|
||||||
|
|
||||||
//printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
NO_printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
|
||||||
int r = (*fe->do_scan)(this);
|
int r = (*fe->do_scan)(this);
|
||||||
//printf("filter: %02x %d\n", fe->id, r);
|
NO_printf("filter: %02x %d\n", fe->id, r);
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
throwFilterException();
|
throwFilterException();
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
|
|||||||
+15
-26
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,13 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
#ifndef __UPX_FILTER_H
|
|
||||||
#define __UPX_FILTER_H 1
|
|
||||||
|
|
||||||
class Filter;
|
|
||||||
class FilterImp;
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// A filter is a reversible operation that modifies a given
|
// A filter is a reversible operation that modifies a given
|
||||||
@@ -50,16 +44,15 @@ class FilterImp;
|
|||||||
// to absolute addresses so that the buffer compresses better.
|
// to absolute addresses so that the buffer compresses better.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class Filter
|
class Filter final {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Filter(int level) { clevel = level; init(); }
|
explicit Filter(int level) noexcept;
|
||||||
void init(int id=0, unsigned addvalue=0);
|
void init(int id = 0, unsigned addvalue = 0) noexcept;
|
||||||
|
|
||||||
bool filter(upx_byte *buf, unsigned buf_len);
|
bool filter(SPAN_0(byte) buf, unsigned buf_len);
|
||||||
void unfilter(upx_byte *buf, unsigned buf_len, bool verify_checksum=false);
|
void unfilter(SPAN_0(byte) buf, unsigned buf_len, bool verify_checksum = false);
|
||||||
void verifyUnfilter();
|
void verifyUnfilter();
|
||||||
bool scan(const upx_byte *buf, unsigned buf_len);
|
bool scan(SPAN_0(const byte) buf, unsigned buf_len);
|
||||||
|
|
||||||
static bool isValidFilter(int filter_id);
|
static bool isValidFilter(int filter_id);
|
||||||
static bool isValidFilter(int filter_id, const int *allowed_filters);
|
static bool isValidFilter(int filter_id, const int *allowed_filters);
|
||||||
@@ -67,7 +60,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
// Will be set by each call to filter()/unfilter().
|
// Will be set by each call to filter()/unfilter().
|
||||||
// Read-only afterwards.
|
// Read-only afterwards.
|
||||||
upx_byte *buf = nullptr;
|
byte *buf = nullptr;
|
||||||
unsigned buf_len = 0;
|
unsigned buf_len = 0;
|
||||||
|
|
||||||
// Checksum of the buffer before applying the filter
|
// Checksum of the buffer before applying the filter
|
||||||
@@ -79,7 +72,7 @@ public:
|
|||||||
const int *preferred_ctos = nullptr;
|
const int *preferred_ctos = nullptr;
|
||||||
|
|
||||||
// Input/output parameters used by various filters
|
// Input/output parameters used by various filters
|
||||||
unsigned char cto; // call trick offset
|
byte cto; // call trick offset
|
||||||
|
|
||||||
// Output used by various filters. Read only.
|
// Output used by various filters. Read only.
|
||||||
unsigned calls;
|
unsigned calls;
|
||||||
@@ -96,7 +89,6 @@ private:
|
|||||||
int clevel; // compression level
|
int clevel; // compression level
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// We don't want a full OO interface here because of
|
// We don't want a full OO interface here because of
|
||||||
// certain implementation speed reasons.
|
// certain implementation speed reasons.
|
||||||
@@ -104,13 +96,13 @@ private:
|
|||||||
// This class is private to Filter - don't look.
|
// This class is private to Filter - don't look.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class FilterImp
|
class FilterImpl final {
|
||||||
{
|
|
||||||
friend class Filter;
|
friend class Filter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct FilterEntry
|
explicit FilterImpl() noexcept DELETED_FUNCTION;
|
||||||
{
|
|
||||||
|
struct FilterEntry {
|
||||||
int id; // 0 .. 255
|
int id; // 0 .. 255
|
||||||
unsigned min_buf_len;
|
unsigned min_buf_len;
|
||||||
unsigned max_buf_len;
|
unsigned max_buf_len;
|
||||||
@@ -128,7 +120,4 @@ private:
|
|||||||
static const int n_filters; // number of filters[]
|
static const int n_filters; // number of filters[]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+134
-203
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,18 +25,15 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// 16-bit calltrick ("naive")
|
// 16-bit calltrick ("naive")
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CT16(f, cond, addvalue, get, set) \
|
#define CT16(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 3; \
|
byte *b_end = b + f->buf_len - 3; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) { \
|
||||||
{ \
|
|
||||||
b += 1; \
|
b += 1; \
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
@@ -45,177 +42,126 @@
|
|||||||
b += 2 - 1; \
|
b += 2 - 1; \
|
||||||
} \
|
} \
|
||||||
} while (++b < b_end); \
|
} while (++b < b_end); \
|
||||||
if (f->lastcall) f->lastcall += 2; \
|
if (f->lastcall) \
|
||||||
|
f->lastcall += 2; \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// filter: e8, e9, e8e9
|
// filter: e8, e9, e8e9
|
||||||
static int f_ct16_e8(Filter *f)
|
static int f_ct16_e8(Filter *f) { CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16) }
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int f_ct16_e9(Filter *f)
|
static int f_ct16_e9(Filter *f) { CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_le16) }
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_le16)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int f_ct16_e8e9(Filter *f)
|
static int f_ct16_e8e9(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_le16)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter: e8, e9, e8e9
|
// unfilter: e8, e9, e8e9
|
||||||
static int u_ct16_e8(Filter *f)
|
static int u_ct16_e8(Filter *f) { CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16) }
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int u_ct16_e9(Filter *f)
|
static int u_ct16_e9(Filter *f) { CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16) }
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int u_ct16_e8e9(Filter *f)
|
static int u_ct16_e8e9(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan: e8, e9, e8e9
|
// scan: e8, e9, e8e9
|
||||||
static int s_ct16_e8(Filter *f)
|
static int s_ct16_e8(Filter *f) { CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy) }
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int s_ct16_e9(Filter *f)
|
static int s_ct16_e9(Filter *f) { CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy) }
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int s_ct16_e8e9(Filter *f)
|
static int s_ct16_e8e9(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// filter: e8, e9, e8e9 with bswap le->be
|
// filter: e8, e9, e8e9 with bswap le->be
|
||||||
static int f_ct16_e8_bswap_le(Filter *f)
|
static int f_ct16_e8_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
|
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct16_e9_bswap_le(Filter *f)
|
static int f_ct16_e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct16_e8e9_bswap_le(Filter *f)
|
static int f_ct16_e8e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter: e8, e9, e8e9 with bswap le->be
|
// unfilter: e8, e9, e8e9 with bswap le->be
|
||||||
static int u_ct16_e8_bswap_le(Filter *f)
|
static int u_ct16_e8_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
|
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct16_e9_bswap_le(Filter *f)
|
static int u_ct16_e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct16_e8e9_bswap_le(Filter *f)
|
static int u_ct16_e8e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan: e8, e9, e8e9 with bswap le->be
|
// scan: e8, e9, e8e9 with bswap le->be
|
||||||
static int s_ct16_e8_bswap_le(Filter *f)
|
static int s_ct16_e8_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_dummy)
|
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct16_e9_bswap_le(Filter *f)
|
static int s_ct16_e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct16_e8e9_bswap_le(Filter *f)
|
static int s_ct16_e8e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// filter: e8, e9, e8e9 with bswap be->le
|
// filter: e8, e9, e8e9 with bswap be->le
|
||||||
static int f_ct16_e8_bswap_be(Filter *f)
|
static int f_ct16_e8_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_le16)
|
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct16_e9_bswap_be(Filter *f)
|
static int f_ct16_e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct16_e8e9_bswap_be(Filter *f)
|
static int f_ct16_e8e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter: e8, e9, e8e9 with bswap be->le
|
// unfilter: e8, e9, e8e9 with bswap be->le
|
||||||
static int u_ct16_e8_bswap_be(Filter *f)
|
static int u_ct16_e8_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_be16)
|
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct16_e9_bswap_be(Filter *f)
|
static int u_ct16_e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct16_e8e9_bswap_be(Filter *f)
|
static int u_ct16_e8e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan: e8, e9, e8e9 with bswap be->le
|
// scan: e8, e9, e8e9 with bswap be->le
|
||||||
static int s_ct16_e8_bswap_be(Filter *f)
|
static int s_ct16_e8_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct16_e9_bswap_be(Filter *f)
|
static int s_ct16_e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct16_e8e9_bswap_be(Filter *f)
|
static int s_ct16_e8e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#undef CT16
|
#undef CT16
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// 32-bit calltrick ("naive")
|
// 32-bit calltrick ("naive")
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CT32(f, cond, addvalue, get, set) \
|
#define CT32(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 5; \
|
byte *b_end = b + f->buf_len - 5; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) { \
|
||||||
{ \
|
|
||||||
b += 1; \
|
b += 1; \
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
@@ -224,163 +170,115 @@ static int s_ct16_e8e9_bswap_be(Filter *f)
|
|||||||
b += 4 - 1; \
|
b += 4 - 1; \
|
||||||
} \
|
} \
|
||||||
} while (++b < b_end); \
|
} while (++b < b_end); \
|
||||||
if (f->lastcall) f->lastcall += 4; \
|
if (f->lastcall) \
|
||||||
|
f->lastcall += 4; \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
// filter: e8, e9, e8e9
|
// filter: e8, e9, e8e9
|
||||||
static int f_ct32_e8(Filter *f)
|
static int f_ct32_e8(Filter *f) { CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32) }
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int f_ct32_e9(Filter *f)
|
static int f_ct32_e9(Filter *f) { CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_le32) }
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_le32)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int f_ct32_e8e9(Filter *f)
|
static int f_ct32_e8e9(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_le32)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter: e8, e9, e8e9
|
// unfilter: e8, e9, e8e9
|
||||||
static int u_ct32_e8(Filter *f)
|
static int u_ct32_e8(Filter *f) { CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32) }
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int u_ct32_e9(Filter *f)
|
static int u_ct32_e9(Filter *f) { CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32) }
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int u_ct32_e8e9(Filter *f)
|
static int u_ct32_e8e9(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan: e8, e9, e8e9
|
// scan: e8, e9, e8e9
|
||||||
static int s_ct32_e8(Filter *f)
|
static int s_ct32_e8(Filter *f) { CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy) }
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int s_ct32_e9(Filter *f)
|
static int s_ct32_e9(Filter *f) { CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy) }
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
|
||||||
}
|
|
||||||
|
|
||||||
static int s_ct32_e8e9(Filter *f)
|
static int s_ct32_e8e9(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// filter: e8, e9, e8e9 with bswap le->be
|
// filter: e8, e9, e8e9 with bswap le->be
|
||||||
static int f_ct32_e8_bswap_le(Filter *f)
|
static int f_ct32_e8_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
|
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct32_e9_bswap_le(Filter *f)
|
static int f_ct32_e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct32_e8e9_bswap_le(Filter *f)
|
static int f_ct32_e8e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter: e8, e9, e8e9 with bswap le->be
|
// unfilter: e8, e9, e8e9 with bswap le->be
|
||||||
static int u_ct32_e8_bswap_le(Filter *f)
|
static int u_ct32_e8_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
|
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct32_e9_bswap_le(Filter *f)
|
static int u_ct32_e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct32_e8e9_bswap_le(Filter *f)
|
static int u_ct32_e8e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan: e8, e9, e8e9 with bswap le->be
|
// scan: e8, e9, e8e9 with bswap le->be
|
||||||
static int s_ct32_e8_bswap_le(Filter *f)
|
static int s_ct32_e8_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_dummy)
|
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct32_e9_bswap_le(Filter *f)
|
static int s_ct32_e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct32_e8e9_bswap_le(Filter *f)
|
static int s_ct32_e8e9_bswap_le(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// filter: e8, e9, e8e9 with bswap be->le
|
// filter: e8, e9, e8e9 with bswap be->le
|
||||||
static int f_ct32_e8_bswap_be(Filter *f)
|
static int f_ct32_e8_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_le32)
|
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct32_e9_bswap_be(Filter *f)
|
static int f_ct32_e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ct32_e8e9_bswap_be(Filter *f)
|
static int f_ct32_e8e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter: e8, e9, e8e9 with bswap be->le
|
// unfilter: e8, e9, e8e9 with bswap be->le
|
||||||
static int u_ct32_e8_bswap_be(Filter *f)
|
static int u_ct32_e8_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_be32)
|
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct32_e9_bswap_be(Filter *f)
|
static int u_ct32_e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct32_e8e9_bswap_be(Filter *f)
|
static int u_ct32_e8e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan: e8, e9, e8e9 with bswap be->le
|
// scan: e8, e9, e8e9 with bswap be->le
|
||||||
static int s_ct32_e8_bswap_be(Filter *f)
|
static int s_ct32_e8_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct32_e9_bswap_be(Filter *f)
|
static int s_ct32_e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct32_e8e9_bswap_be(Filter *f)
|
static int s_ct32_e8e9_bswap_be(Filter *f) {
|
||||||
{
|
|
||||||
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#undef CT32
|
#undef CT32
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -388,11 +286,10 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CT24ARM_LE(f, cond, addvalue, get, set) \
|
#define CT24ARM_LE(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 4; \
|
byte *b_end = b + f->buf_len - 4; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) { \
|
||||||
{ \
|
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
set(b, get(b) + (addvalue)); \
|
set(b, get(b) + (addvalue)); \
|
||||||
@@ -400,35 +297,31 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
|
|||||||
} \
|
} \
|
||||||
b += 4; \
|
b += 4; \
|
||||||
} while (b < b_end); \
|
} while (b < b_end); \
|
||||||
if (f->lastcall) f->lastcall += 4; \
|
if (f->lastcall) \
|
||||||
|
f->lastcall += 4; \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
#define ARMCT_COND_le (((b[3] & 0x0f) == 0x0b))
|
#define ARMCT_COND_le (((b[3] & 0x0f) == 0x0b))
|
||||||
|
|
||||||
static int f_ct24arm_le(Filter *f)
|
static int f_ct24arm_le(Filter *f) {
|
||||||
{
|
|
||||||
CT24ARM_LE(f, ARMCT_COND_le, a / 4 + f->addvalue, get_le24, set_le24)
|
CT24ARM_LE(f, ARMCT_COND_le, a / 4 + f->addvalue, get_le24, set_le24)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct24arm_le(Filter *f)
|
static int u_ct24arm_le(Filter *f) {
|
||||||
{
|
|
||||||
CT24ARM_LE(f, ARMCT_COND_le, 0 - a / 4 - f->addvalue, get_le24, set_le24)
|
CT24ARM_LE(f, ARMCT_COND_le, 0 - a / 4 - f->addvalue, get_le24, set_le24)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct24arm_le(Filter *f)
|
static int s_ct24arm_le(Filter *f) {
|
||||||
{
|
|
||||||
CT24ARM_LE(f, ARMCT_COND_le, a + f->addvalue, get_le24, set_dummy)
|
CT24ARM_LE(f, ARMCT_COND_le, a + f->addvalue, get_le24, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef CT24ARM_LE
|
#undef CT24ARM_LE
|
||||||
|
|
||||||
#define CT24ARM_BE(f, cond, addvalue, get, set) \
|
#define CT24ARM_BE(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 4; \
|
byte *b_end = b + f->buf_len - 4; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) { \
|
||||||
{ \
|
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
set(1 + b, get(1 + b) + (addvalue)); \
|
set(1 + b, get(1 + b) + (addvalue)); \
|
||||||
@@ -436,23 +329,21 @@ static int s_ct24arm_le(Filter *f)
|
|||||||
} \
|
} \
|
||||||
b += 4; \
|
b += 4; \
|
||||||
} while (b < b_end); \
|
} while (b < b_end); \
|
||||||
if (f->lastcall) f->lastcall += 4; \
|
if (f->lastcall) \
|
||||||
|
f->lastcall += 4; \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#define ARMCT_COND_be (((b[0] & 0x0f) == 0x0b))
|
#define ARMCT_COND_be (((b[0] & 0x0f) == 0x0b))
|
||||||
|
|
||||||
static int f_ct24arm_be(Filter *f)
|
static int f_ct24arm_be(Filter *f) {
|
||||||
{
|
|
||||||
CT24ARM_BE(f, ARMCT_COND_be, a / 4 + f->addvalue, get_be24, set_be24)
|
CT24ARM_BE(f, ARMCT_COND_be, a / 4 + f->addvalue, get_be24, set_be24)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct24arm_be(Filter *f)
|
static int u_ct24arm_be(Filter *f) {
|
||||||
{
|
|
||||||
CT24ARM_BE(f, ARMCT_COND_be, 0 - a / 4 - f->addvalue, get_be24, set_be24)
|
CT24ARM_BE(f, ARMCT_COND_be, 0 - a / 4 - f->addvalue, get_be24, set_be24)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct24arm_be(Filter *f)
|
static int s_ct24arm_be(Filter *f) {
|
||||||
{
|
|
||||||
CT24ARM_BE(f, ARMCT_COND_be, a + f->addvalue, get_be24, set_dummy)
|
CT24ARM_BE(f, ARMCT_COND_be, a + f->addvalue, get_be24, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,12 +354,12 @@ static int s_ct24arm_be(Filter *f)
|
|||||||
// 26-bit ARM calltrick ("naive")
|
// 26-bit ARM calltrick ("naive")
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
#if 1 //{ old reliable
|
||||||
#define CT26ARM_LE(f, cond, addvalue, get, set) \
|
#define CT26ARM_LE(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 4; \
|
byte *b_end = b + f->buf_len - 4; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) { \
|
||||||
{ \
|
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
set(b, get(b) + (addvalue)); \
|
set(b, get(b) + (addvalue)); \
|
||||||
@@ -476,27 +367,67 @@ static int s_ct24arm_be(Filter *f)
|
|||||||
} \
|
} \
|
||||||
b += 4; \
|
b += 4; \
|
||||||
} while (b < b_end); \
|
} while (b < b_end); \
|
||||||
if (f->lastcall) f->lastcall += 4; \
|
if (f->lastcall) \
|
||||||
|
f->lastcall += 4; \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
#define ARMCT_COND (((b[3] & 0x7C) == 0x14))
|
#define ARMCT_COND (((b[3] & 0x7C) == 0x14))
|
||||||
|
|
||||||
static int f_ct26arm_le(Filter *f)
|
static int f_ct26arm_le(Filter *f) {
|
||||||
{
|
|
||||||
CT26ARM_LE(f, ARMCT_COND, a / 4 + f->addvalue, get_le26, set_le26)
|
CT26ARM_LE(f, ARMCT_COND, a / 4 + f->addvalue, get_le26, set_le26)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ct26arm_le(Filter *f)
|
static int u_ct26arm_le(Filter *f) {
|
||||||
{
|
|
||||||
CT26ARM_LE(f, ARMCT_COND, 0 - a / 4 - f->addvalue, get_le26, set_le26)
|
CT26ARM_LE(f, ARMCT_COND, 0 - a / 4 - f->addvalue, get_le26, set_le26)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ct26arm_le(Filter *f)
|
static int s_ct26arm_le(Filter *f) {
|
||||||
{
|
|
||||||
CT26ARM_LE(f, ARMCT_COND, a + f->addvalue, get_le26, set_dummy)
|
CT26ARM_LE(f, ARMCT_COND, a + f->addvalue, get_le26, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else //}{ new enhanced but DIFFERENT; need new filter type!
|
||||||
|
|
||||||
|
static int CTarm64(Filter *f, int dir) // dir: 1, 0, -1
|
||||||
|
{
|
||||||
|
upx_byte *b = f->buf; // will be incremented
|
||||||
|
upx_byte *const b_end = b + f->buf_len - 4;
|
||||||
|
do {
|
||||||
|
unsigned const a = b - f->buf;
|
||||||
|
int const d = dir * (f->addvalue + (a >> 2));
|
||||||
|
unsigned const v = get_le32(f->buf); // the 32-bit instruction
|
||||||
|
if (0x05 == (0x1f & (v >> 26))) { // b, bl
|
||||||
|
f->lastcall = a;
|
||||||
|
if (dir)
|
||||||
|
set_le26(b, v + d);
|
||||||
|
f->calls++;
|
||||||
|
} else if ((0x54 == (v >> 24)) // b.cond
|
||||||
|
|| (0x1a == ((v >> 25) & 0x3f)) // cb{z,nz}
|
||||||
|
) {
|
||||||
|
f->lastcall = a;
|
||||||
|
if (dir)
|
||||||
|
set_le19_5(b, (v >> 5) + d);
|
||||||
|
f->calls++;
|
||||||
|
} else if (0x1b == ((v >> 25) & 0x3f)) { // tb{z,nz}
|
||||||
|
f->lastcall = a;
|
||||||
|
if (dir)
|
||||||
|
set_le14_5(b, (v >> 5) + d);
|
||||||
|
f->calls++;
|
||||||
|
}
|
||||||
|
b += 4;
|
||||||
|
} while (b < b_end);
|
||||||
|
if (f->lastcall)
|
||||||
|
f->lastcall += 4;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int f_CTarm64_le(Filter *f) { return CTarm64(f, 1); }
|
||||||
|
|
||||||
|
static int u_CTarm64_le(Filter *f) { return CTarm64(f, -1); }
|
||||||
|
|
||||||
|
static int s_CTarm64_le(Filter *f) { return CTarm64(f, 0); }
|
||||||
|
|
||||||
|
#endif //}
|
||||||
|
|
||||||
#undef CT26ARM_LE
|
#undef CT26ARM_LE
|
||||||
#undef ARMCT_COND
|
#undef ARMCT_COND
|
||||||
|
|
||||||
|
|||||||
+18
-36
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,20 +25,17 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// filter / scan
|
// filter / scan
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int F(Filter *f)
|
static int F(Filter *f) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
@@ -57,17 +54,14 @@ static int F(Filter *f)
|
|||||||
// So, a call to a destination that is outside the buffer
|
// So, a call to a destination that is outside the buffer
|
||||||
// must not conflict with the mark.
|
// must not conflict with the mark.
|
||||||
// Note that unsigned comparison checks both edges of buffer.
|
// Note that unsigned comparison checks both edges of buffer.
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++) {
|
||||||
{
|
|
||||||
if (!COND(b, ic))
|
if (!COND(b, ic))
|
||||||
continue;
|
continue;
|
||||||
jc = get_le32(b + ic + 1) + ic + 1;
|
jc = get_le32(b + ic + 1) + ic + 1;
|
||||||
if (jc < size)
|
if (jc < size) {
|
||||||
{
|
|
||||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
buf[b[ic + 1]] |= 1;
|
buf[b[ic + 1]] |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,26 +73,22 @@ static int F(Filter *f)
|
|||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++) {
|
||||||
{
|
|
||||||
if (!COND(b, ic))
|
if (!COND(b, ic))
|
||||||
continue;
|
continue;
|
||||||
jc = get_le32(b + ic + 1) + ic + 1;
|
jc = get_le32(b + ic + 1) + ic + 1;
|
||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size) {
|
||||||
{
|
|
||||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b + ic + 1, jc + addvalue + cto);
|
set_be32(b + ic + 1, jc + addvalue + cto);
|
||||||
#endif
|
#endif
|
||||||
if (ic - lastnoncall < 5)
|
if (ic - lastnoncall < 5) {
|
||||||
{
|
|
||||||
// check the last 4 bytes before this call
|
// check the last 4 bytes before this call
|
||||||
for (kc = 4; kc; kc--)
|
for (kc = 4; kc; kc--)
|
||||||
if (COND(b, ic - kc) && b[ic - kc + 1] == cto8)
|
if (COND(b, ic - kc) && b[ic - kc + 1] == cto8)
|
||||||
break;
|
break;
|
||||||
if (kc)
|
if (kc) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// restore original
|
// restore original
|
||||||
set_le32(b + ic + 1, jc - ic - 1);
|
set_le32(b + ic + 1, jc - ic - 1);
|
||||||
@@ -113,9 +103,7 @@ static int F(Filter *f)
|
|||||||
calls++;
|
calls++;
|
||||||
ic += 4;
|
ic += 4;
|
||||||
lastcall = ic + 1;
|
lastcall = ic + 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(b[ic + 1] != cto8); // this should not happen
|
assert(b[ic + 1] != cto8); // this should not happen
|
||||||
lastnoncall = ic;
|
lastnoncall = ic;
|
||||||
noncalls++;
|
noncalls++;
|
||||||
@@ -133,15 +121,13 @@ static int F(Filter *f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// unfilter
|
// unfilter
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f) {
|
||||||
{
|
byte *b = f->buf;
|
||||||
upx_byte *b = f->buf;
|
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
@@ -149,24 +135,20 @@ static int U(Filter *f)
|
|||||||
unsigned ic, jc;
|
unsigned ic, jc;
|
||||||
|
|
||||||
for (ic = 0; ic < size5; ic++)
|
for (ic = 0; ic < size5; ic++)
|
||||||
if (COND(b,ic))
|
if (COND(b, ic)) {
|
||||||
{
|
|
||||||
jc = get_be32(b + ic + 1);
|
jc = get_be32(b + ic + 1);
|
||||||
if (b[ic+1] == f->cto)
|
if (b[ic + 1] == f->cto) {
|
||||||
{
|
|
||||||
set_le32(b + ic + 1, jc - ic - 1 - addvalue - cto);
|
set_le32(b + ic + 1, jc - ic - 1 - addvalue - cto);
|
||||||
f->calls++;
|
f->calls++;
|
||||||
ic += 4;
|
ic += 4;
|
||||||
f->lastcall = ic + 1;
|
f->lastcall = ic + 1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
f->noncalls++;
|
f->noncalls++;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
#undef U
|
#undef U
|
||||||
|
|
||||||
|
|||||||
+19
-37
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
Copyright (C) 2000-2022 John F. Reiser
|
Copyright (C) 2000-2024 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -29,20 +29,17 @@
|
|||||||
<jreiser@users.sourceforge.net>
|
<jreiser@users.sourceforge.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// filter / scan
|
// filter / scan
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int F(Filter *f)
|
static int F(Filter *f) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
@@ -56,17 +53,14 @@ static int F(Filter *f)
|
|||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
memset(buf, 0, 256);
|
memset(buf, 0, 256);
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++) {
|
||||||
{
|
|
||||||
if (!COND(b, ic, lastcall))
|
if (!COND(b, ic, lastcall))
|
||||||
continue;
|
continue;
|
||||||
jc = get_le32(b + ic + 1) + ic + 1;
|
jc = get_le32(b + ic + 1) + ic + 1;
|
||||||
if (jc < size)
|
if (jc < size) {
|
||||||
{
|
|
||||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
buf[b[ic + 1]] |= 1;
|
buf[b[ic + 1]] |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,26 +72,22 @@ static int F(Filter *f)
|
|||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++) {
|
||||||
{
|
|
||||||
if (!COND(b, ic, lastcall))
|
if (!COND(b, ic, lastcall))
|
||||||
continue;
|
continue;
|
||||||
jc = get_le32(b + ic + 1) + ic + 1;
|
jc = get_le32(b + ic + 1) + ic + 1;
|
||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size) {
|
||||||
{
|
|
||||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b + ic + 1, jc + addvalue + cto);
|
set_be32(b + ic + 1, jc + addvalue + cto);
|
||||||
#endif
|
#endif
|
||||||
if (ic - lastnoncall < 5)
|
if (ic - lastnoncall < 5) {
|
||||||
{
|
|
||||||
// check the last 4 bytes before this call
|
// check the last 4 bytes before this call
|
||||||
for (kc = 4; kc; kc--)
|
for (kc = 4; kc; kc--)
|
||||||
if (COND(b, ic - kc, lastcall) && b[ic - kc + 1] == cto8)
|
if (COND(b, ic - kc, lastcall) && b[ic - kc + 1] == cto8)
|
||||||
break;
|
break;
|
||||||
if (kc)
|
if (kc) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// restore original
|
// restore original
|
||||||
set_le32(b + ic + 1, jc - ic - 1);
|
set_le32(b + ic + 1, jc - ic - 1);
|
||||||
@@ -112,9 +102,7 @@ static int F(Filter *f)
|
|||||||
calls++;
|
calls++;
|
||||||
ic += 4;
|
ic += 4;
|
||||||
lastcall = ic + 1;
|
lastcall = ic + 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(b[ic + 1] != cto8); // this should not happen
|
assert(b[ic + 1] != cto8); // this should not happen
|
||||||
lastnoncall = ic;
|
lastnoncall = ic;
|
||||||
noncalls++;
|
noncalls++;
|
||||||
@@ -132,15 +120,13 @@ static int F(Filter *f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// unfilter
|
// unfilter
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f) {
|
||||||
{
|
byte *b = f->buf;
|
||||||
upx_byte *b = f->buf;
|
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
@@ -148,24 +134,20 @@ static int U(Filter *f)
|
|||||||
unsigned ic, jc;
|
unsigned ic, jc;
|
||||||
|
|
||||||
for (ic = 0; ic < size5; ic++)
|
for (ic = 0; ic < size5; ic++)
|
||||||
if (COND(b,ic,lastcall))
|
if (COND(b, ic, lastcall)) {
|
||||||
{
|
|
||||||
jc = get_be32(b + ic + 1);
|
jc = get_be32(b + ic + 1);
|
||||||
if (b[ic+1] == f->cto)
|
if (b[ic + 1] == f->cto) {
|
||||||
{
|
|
||||||
set_le32(b + ic + 1, jc - ic - 1 - addvalue - cto);
|
set_le32(b + ic + 1, jc - ic - 1 - addvalue - cto);
|
||||||
f->calls++;
|
f->calls++;
|
||||||
ic += 4;
|
ic += 4;
|
||||||
f->lastcall = ic + 1;
|
f->lastcall = ic + 1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
f->noncalls++;
|
f->noncalls++;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
#undef U
|
#undef U
|
||||||
|
|
||||||
|
|||||||
+47
-89
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
Copyright (C) 2000-2022 John F. Reiser
|
Copyright (C) 2000-2024 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -29,12 +29,10 @@
|
|||||||
<jreiser@users.sourceforge.net>
|
<jreiser@users.sourceforge.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1300))
|
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1300))
|
||||||
#pragma warning(disable : 4702) // W4: unreachable code
|
#pragma warning(disable : 4702) // W4: unreachable code
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// filter / scan
|
// filter / scan
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -44,48 +42,32 @@
|
|||||||
#define FNOMRU 1 // filter, but not using mru
|
#define FNOMRU 1 // filter, but not using mru
|
||||||
#define MRUFLT 2 // mru filter
|
#define MRUFLT 2 // mru filter
|
||||||
|
|
||||||
static unsigned
|
static unsigned f80_call(Filter const *f) { return (1 + (0x0f & f->id)) % 3; }
|
||||||
f80_call(Filter const *f)
|
|
||||||
{
|
|
||||||
return (1+ (0x0f & f->id)) % 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned
|
static unsigned f80_jmp1(Filter const *f) { return ((1 + (0x0f & f->id)) / 3) % 3; }
|
||||||
f80_jmp1(Filter const *f)
|
|
||||||
{
|
|
||||||
return ((1+ (0x0f & f->id)) / 3) % 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned
|
static unsigned f80_jcc2(Filter const *f) { return f80_jmp1(f); }
|
||||||
f80_jcc2(Filter const *f)
|
|
||||||
{
|
|
||||||
return f80_jmp1(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define N_MRU 32 // does not have to be a power of 2
|
#define N_MRU 32 // does not have to be a power of 2
|
||||||
|
|
||||||
// Adaptively remember recent destinations.
|
// Adaptively remember recent destinations.
|
||||||
static void
|
static void update_mru(const unsigned jc, // destination address
|
||||||
update_mru(
|
const int kh, // mru[kh] is slot where found
|
||||||
unsigned const jc, // destination address
|
|
||||||
int const kh, // mru[kh] is slot where found
|
|
||||||
unsigned mru[N_MRU], // circular buffer of most recent destinations
|
unsigned mru[N_MRU], // circular buffer of most recent destinations
|
||||||
int &hand, // mru[hand] is most recent destination
|
int &hand, // mru[hand] is most recent destination
|
||||||
int &tail // mru[tail] is beyond oldest destination ("cold cache" startup)
|
int &tail // mru[tail] is beyond oldest destination ("cold cache" startup)
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
if (0 > --hand) {
|
if (0 > --hand) {
|
||||||
hand = N_MRU - 1;
|
hand = N_MRU - 1;
|
||||||
}
|
}
|
||||||
unsigned const t = mru[hand]; // entry which will be overwritten by jc
|
const unsigned t = mru[hand]; // entry which will be overwritten by jc
|
||||||
if (0 != t) { // have seen at least N_MRU destinations
|
if (0 != t) { // have seen at least N_MRU destinations
|
||||||
mru[kh] = t;
|
mru[kh] = t;
|
||||||
}
|
} else { // "cold cache": keep active region contiguous
|
||||||
else { // "cold cache": keep active region contiguous
|
|
||||||
if (0 > --tail) {
|
if (0 > --tail) {
|
||||||
tail = N_MRU - 1;
|
tail = N_MRU - 1;
|
||||||
}
|
}
|
||||||
unsigned const t2 = mru[tail];
|
const unsigned t2 = mru[tail];
|
||||||
mru[tail] = 0;
|
mru[tail] = 0;
|
||||||
mru[kh] = t2;
|
mru[kh] = t2;
|
||||||
}
|
}
|
||||||
@@ -93,34 +75,32 @@ update_mru(
|
|||||||
}
|
}
|
||||||
#endif //}
|
#endif //}
|
||||||
|
|
||||||
|
static int F(Filter *f) {
|
||||||
static int F(Filter *f)
|
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *const b = f->buf;
|
byte *const b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
|
|
||||||
unsigned ic, jc, kc;
|
unsigned ic, jc, kc;
|
||||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||||
unsigned lastnoncall = size, lastcall = 0;
|
unsigned lastnoncall = size, lastcall = 0;
|
||||||
unsigned wtally[3]; memset(wtally, 0, sizeof(wtally));
|
unsigned wtally[3];
|
||||||
|
memset(wtally, 0, sizeof(wtally));
|
||||||
|
|
||||||
#ifdef U //{
|
#ifdef U //{
|
||||||
unsigned const f_call = f80_call(f);
|
const unsigned f_call = f80_call(f);
|
||||||
unsigned const f_jmp1 = f80_jmp1(f);
|
const unsigned f_jmp1 = f80_jmp1(f);
|
||||||
unsigned const f_jcc2 = f80_jcc2(f);
|
const unsigned f_jcc2 = f80_jcc2(f);
|
||||||
|
|
||||||
int hand = 0, tail = 0;
|
int hand = 0, tail = 0;
|
||||||
unsigned mru[N_MRU];
|
unsigned mru[N_MRU];
|
||||||
memset(&mru[0], 0, sizeof(mru));
|
memset(&mru[0], 0, sizeof(mru));
|
||||||
assert(N_MRU <= 256);
|
assert(N_MRU <= 256);
|
||||||
f->n_mru = (MRUFLT==f_call || MRUFLT==f_jmp1 || MRUFLT==f_jcc2) ?
|
f->n_mru = (MRUFLT == f_call || MRUFLT == f_jmp1 || MRUFLT == f_jcc2) ? N_MRU : 0;
|
||||||
N_MRU : 0;
|
|
||||||
#endif //}
|
#endif //}
|
||||||
|
|
||||||
// FIXME: We must fit into 8 MiB because we steal one bit.
|
// FIXME: We must fit into 8 MiB because we steal one bit.
|
||||||
@@ -131,8 +111,7 @@ static int F(Filter *f)
|
|||||||
memset(buf, 0, 256);
|
memset(buf, 0, 256);
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++)
|
||||||
if (CONDF(which,b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
|
if (CONDF(which, b, ic, lastcall) && get_le32(b + ic + 1) + ic + 1 >= size) {
|
||||||
{
|
|
||||||
buf[b[ic + 1]] |= 1;
|
buf[b[ic + 1]] |= 1;
|
||||||
}
|
}
|
||||||
UNUSED(which);
|
UNUSED(which);
|
||||||
@@ -145,8 +124,7 @@ static int F(Filter *f)
|
|||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++) {
|
||||||
{
|
|
||||||
int which;
|
int which;
|
||||||
int f_on = 0;
|
int f_on = 0;
|
||||||
if (!CONDF(which, b, ic, lastcall))
|
if (!CONDF(which, b, ic, lastcall))
|
||||||
@@ -154,8 +132,7 @@ static int F(Filter *f)
|
|||||||
++wtally[which];
|
++wtally[which];
|
||||||
jc = get_le32(b + ic + 1) + ic + 1;
|
jc = get_le32(b + ic + 1) + ic + 1;
|
||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
if (2 == which && NOFILT != f_jcc2) { // 6-byte Jcc <disp32>
|
if (2 == which && NOFILT != f_jcc2) { // 6-byte Jcc <disp32>
|
||||||
// Prefix 0x0f is constant, but opcode condition 0x80..0x8f
|
// Prefix 0x0f is constant, but opcode condition 0x80..0x8f
|
||||||
@@ -163,16 +140,14 @@ static int F(Filter *f)
|
|||||||
// in be32 big endian format, the low-addressed bytes
|
// in be32 big endian format, the low-addressed bytes
|
||||||
// will tend to be constant. Swap prefix and opcode
|
// will tend to be constant. Swap prefix and opcode
|
||||||
// so that constants are together for better compression.
|
// so that constants are together for better compression.
|
||||||
unsigned char const t =
|
unsigned char const t = b[ic - 1];
|
||||||
b[ic-1];
|
|
||||||
b[ic - 1] = b[ic];
|
b[ic - 1] = b[ic];
|
||||||
b[ic] = t;
|
b[ic] = t;
|
||||||
}
|
}
|
||||||
// FIXME [?]: Extend to 8 bytes if "ADD ESP, byte 4*n" follows CALL.
|
// FIXME [?]: Extend to 8 bytes if "ADD ESP, byte 4*n" follows CALL.
|
||||||
// This will require two related cto's (consecutive, or otherwise).
|
// This will require two related cto's (consecutive, or otherwise).
|
||||||
if ((0==which && MRUFLT==f_call)
|
if ((0 == which && MRUFLT == f_call) || (1 == which && MRUFLT == f_jmp1) ||
|
||||||
|| (1==which && MRUFLT==f_jmp1)
|
(2 == which && MRUFLT == f_jcc2)) {
|
||||||
|| (2==which && MRUFLT==f_jcc2) ) {
|
|
||||||
f_on = 1;
|
f_on = 1;
|
||||||
// Recode the destination: narrower mru indices
|
// Recode the destination: narrower mru indices
|
||||||
// should compress better than wider addresses.
|
// should compress better than wider addresses.
|
||||||
@@ -197,29 +172,24 @@ static int F(Filter *f)
|
|||||||
}
|
}
|
||||||
mru[hand] = jc;
|
mru[hand] = jc;
|
||||||
}
|
}
|
||||||
} else
|
} else if ((0 == which && NOFILT != f_call) || (1 == which && NOFILT != f_jmp1) ||
|
||||||
if ((0==which && NOFILT!=f_call)
|
(2 == which && NOFILT != f_jcc2)) {
|
||||||
|| (1==which && NOFILT!=f_jmp1)
|
|
||||||
|| (2==which && NOFILT!=f_jcc2) ) {
|
|
||||||
f_on = 1;
|
f_on = 1;
|
||||||
set_be32(b + ic + 1, jc + cto);
|
set_be32(b + ic + 1, jc + cto);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (f_on) {
|
if (f_on) {
|
||||||
if (ic - lastnoncall < 5)
|
if (ic - lastnoncall < 5) {
|
||||||
{
|
|
||||||
// check the last 4 bytes before this call
|
// check the last 4 bytes before this call
|
||||||
for (kc = 4; kc; kc--)
|
for (kc = 4; kc; kc--)
|
||||||
if (CONDF(which, b, ic - kc, lastcall) && b[ic - kc + 1] == cto8)
|
if (CONDF(which, b, ic - kc, lastcall) && b[ic - kc + 1] == cto8)
|
||||||
break;
|
break;
|
||||||
if (kc)
|
if (kc) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// restore original
|
// restore original
|
||||||
if (2 == which) {
|
if (2 == which) {
|
||||||
// Unswap prefix and opcode for 6-byte Jcc <disp32>
|
// Unswap prefix and opcode for 6-byte Jcc <disp32>
|
||||||
unsigned char const t =
|
unsigned char const t = b[ic - 1];
|
||||||
b[ic-1];
|
|
||||||
b[ic - 1] = b[ic];
|
b[ic - 1] = b[ic];
|
||||||
b[ic] = t;
|
b[ic] = t;
|
||||||
}
|
}
|
||||||
@@ -236,9 +206,7 @@ static int F(Filter *f)
|
|||||||
ic += 4;
|
ic += 4;
|
||||||
lastcall = ic + 1;
|
lastcall = ic + 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(b[ic + 1] != cto8); // this should not happen
|
assert(b[ic + 1] != cto8); // this should not happen
|
||||||
lastnoncall = ic;
|
lastnoncall = ic;
|
||||||
noncalls++;
|
noncalls++;
|
||||||
@@ -258,39 +226,34 @@ static int F(Filter *f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// unfilter
|
// unfilter
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f) {
|
||||||
{
|
|
||||||
unsigned ic, jc;
|
unsigned ic, jc;
|
||||||
|
|
||||||
upx_byte *const b = f->buf;
|
byte *const b = f->buf;
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
unsigned lastcall = 0;
|
unsigned lastcall = 0;
|
||||||
int hand = 0, tail = 0;
|
int hand = 0, tail = 0;
|
||||||
unsigned const f_call = f80_call(f);
|
const unsigned f_call = f80_call(f);
|
||||||
unsigned const f_jmp1 = f80_jmp1(f);
|
const unsigned f_jmp1 = f80_jmp1(f);
|
||||||
unsigned const f_jcc2 = f80_jcc2(f);
|
const unsigned f_jcc2 = f80_jcc2(f);
|
||||||
|
|
||||||
unsigned mru[N_MRU];
|
unsigned mru[N_MRU];
|
||||||
memset(&mru[0], 0, sizeof(mru));
|
memset(&mru[0], 0, sizeof(mru));
|
||||||
|
|
||||||
for (ic = 0; ic < size5; ic++) {
|
for (ic = 0; ic < size5; ic++) {
|
||||||
int which;
|
int which;
|
||||||
if (CONDU(which,b,ic,lastcall))
|
if (CONDU(which, b, ic, lastcall)) {
|
||||||
{
|
|
||||||
unsigned f_on = 0;
|
unsigned f_on = 0;
|
||||||
jc = get_be32(b + ic + 1) - cto;
|
jc = get_be32(b + ic + 1) - cto;
|
||||||
if (b[ic+1] == f->cto)
|
if (b[ic + 1] == f->cto) {
|
||||||
{
|
if ((0 == which && MRUFLT == f_call) || (1 == which && MRUFLT == f_jmp1) ||
|
||||||
if ((0==which && MRUFLT==f_call)
|
(2 == which && MRUFLT == f_jcc2)) {
|
||||||
|| (1==which && MRUFLT==f_jmp1)
|
|
||||||
|| (2==which && MRUFLT==f_jcc2) ) {
|
|
||||||
f_on = 1;
|
f_on = 1;
|
||||||
if (1 & jc) { // 1st time at this destination
|
if (1 & jc) { // 1st time at this destination
|
||||||
jc >>= 1;
|
jc >>= 1;
|
||||||
@@ -298,8 +261,7 @@ static int U(Filter *f)
|
|||||||
hand = N_MRU - 1;
|
hand = N_MRU - 1;
|
||||||
}
|
}
|
||||||
mru[hand] = jc;
|
mru[hand] = jc;
|
||||||
}
|
} else { // not 1st time at this destination
|
||||||
else { // not 1st time at this destination
|
|
||||||
jc >>= 1;
|
jc >>= 1;
|
||||||
if (N_MRU <= jc) {
|
if (N_MRU <= jc) {
|
||||||
throwCompressedDataViolation();
|
throwCompressedDataViolation();
|
||||||
@@ -312,17 +274,14 @@ static int U(Filter *f)
|
|||||||
update_mru(jc, kh, mru, hand, tail);
|
update_mru(jc, kh, mru, hand, tail);
|
||||||
}
|
}
|
||||||
set_le32(b + ic + 1, jc - ic - 1);
|
set_le32(b + ic + 1, jc - ic - 1);
|
||||||
} else
|
} else if ((0 == which && NOFILT != f_call) || (1 == which && NOFILT != f_jmp1) ||
|
||||||
if ((0==which && NOFILT!=f_call)
|
(2 == which && NOFILT != f_jcc2)) {
|
||||||
|| (1==which && NOFILT!=f_jmp1)
|
|
||||||
|| (2==which && NOFILT!=f_jcc2) ) {
|
|
||||||
f_on = 1;
|
f_on = 1;
|
||||||
set_le32(b + ic + 1, jc - ic - 1);
|
set_le32(b + ic + 1, jc - ic - 1);
|
||||||
}
|
}
|
||||||
if (2 == which && NOFILT != f_jcc2) {
|
if (2 == which && NOFILT != f_jcc2) {
|
||||||
// Unswap prefix and opcode for 6-byte Jcc <disp32>
|
// Unswap prefix and opcode for 6-byte Jcc <disp32>
|
||||||
unsigned char const t =
|
unsigned char const t = b[ic - 1];
|
||||||
b[ic-1];
|
|
||||||
b[ic - 1] = b[ic];
|
b[ic - 1] = b[ic];
|
||||||
b[ic] = t;
|
b[ic] = t;
|
||||||
}
|
}
|
||||||
@@ -332,8 +291,7 @@ static int U(Filter *f)
|
|||||||
ic += 4;
|
ic += 4;
|
||||||
f->lastcall = lastcall = ic + 1;
|
f->lastcall = lastcall = ic + 1;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
f->noncalls++;
|
f->noncalls++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-39
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
Copyright (C) 2000-2022 John F. Reiser
|
Copyright (C) 2000-2024 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -29,24 +29,21 @@
|
|||||||
<jreiser@users.sourceforge.net>
|
<jreiser@users.sourceforge.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// filter / scan
|
// filter / scan
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int F(Filter *f)
|
static int F(Filter *f) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
unsigned const id = f->id;
|
const unsigned id = f->id;
|
||||||
|
|
||||||
unsigned ic, jc, kc;
|
unsigned ic, jc, kc;
|
||||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||||
@@ -57,17 +54,14 @@ static int F(Filter *f)
|
|||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
memset(buf, 0, 256);
|
memset(buf, 0, 256);
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++) {
|
||||||
{
|
|
||||||
if (!COND(b, ic, lastcall, id))
|
if (!COND(b, ic, lastcall, id))
|
||||||
continue;
|
continue;
|
||||||
jc = get_le32(b + ic + 1) + ic + 1;
|
jc = get_le32(b + ic + 1) + ic + 1;
|
||||||
if (jc < size)
|
if (jc < size) {
|
||||||
{
|
|
||||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
buf[b[ic + 1]] |= 1;
|
buf[b[ic + 1]] |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,26 +73,22 @@ static int F(Filter *f)
|
|||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
for (ic = 0; ic < size - 5; ic++) {
|
||||||
{
|
|
||||||
if (!COND(b, ic, lastcall, id))
|
if (!COND(b, ic, lastcall, id))
|
||||||
continue;
|
continue;
|
||||||
jc = get_le32(b + ic + 1) + ic + 1;
|
jc = get_le32(b + ic + 1) + ic + 1;
|
||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size) {
|
||||||
{
|
|
||||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b + ic + 1, jc + addvalue + cto);
|
set_be32(b + ic + 1, jc + addvalue + cto);
|
||||||
#endif
|
#endif
|
||||||
if (ic - lastnoncall < 5)
|
if (ic - lastnoncall < 5) {
|
||||||
{
|
|
||||||
// check the last 4 bytes before this call
|
// check the last 4 bytes before this call
|
||||||
for (kc = 4; kc; kc--)
|
for (kc = 4; kc; kc--)
|
||||||
if (COND(b, ic - kc, lastcall, id) && b[ic - kc + 1] == cto8)
|
if (COND(b, ic - kc, lastcall, id) && b[ic - kc + 1] == cto8)
|
||||||
break;
|
break;
|
||||||
if (kc)
|
if (kc) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// restore original
|
// restore original
|
||||||
set_le32(b + ic + 1, jc - ic - 1);
|
set_le32(b + ic + 1, jc - ic - 1);
|
||||||
@@ -113,9 +103,7 @@ static int F(Filter *f)
|
|||||||
calls++;
|
calls++;
|
||||||
ic += 4;
|
ic += 4;
|
||||||
lastcall = ic + 1;
|
lastcall = ic + 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(b[ic + 1] != cto8); // this should not happen
|
assert(b[ic + 1] != cto8); // this should not happen
|
||||||
lastnoncall = ic;
|
lastnoncall = ic;
|
||||||
noncalls++;
|
noncalls++;
|
||||||
@@ -133,42 +121,36 @@ static int F(Filter *f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// unfilter
|
// unfilter
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f) {
|
||||||
{
|
byte *b = f->buf;
|
||||||
upx_byte *b = f->buf;
|
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned cto = (unsigned) f->cto << 24;
|
const unsigned cto = (unsigned) f->cto << 24;
|
||||||
unsigned const id = f->id;
|
const unsigned id = f->id;
|
||||||
unsigned lastcall = 0;
|
unsigned lastcall = 0;
|
||||||
|
|
||||||
unsigned ic, jc;
|
unsigned ic, jc;
|
||||||
|
|
||||||
for (ic = 0; ic < size5; ic++)
|
for (ic = 0; ic < size5; ic++)
|
||||||
if (COND(b,ic,lastcall,id))
|
if (COND(b, ic, lastcall, id)) {
|
||||||
{
|
|
||||||
jc = get_be32(b + ic + 1);
|
jc = get_be32(b + ic + 1);
|
||||||
if (b[ic+1] == f->cto)
|
if (b[ic + 1] == f->cto) {
|
||||||
{
|
|
||||||
set_le32(b + ic + 1, jc - ic - 1 - addvalue - cto);
|
set_le32(b + ic + 1, jc - ic - 1 - addvalue - cto);
|
||||||
f->calls++;
|
f->calls++;
|
||||||
ic += 4;
|
ic += 4;
|
||||||
f->lastcall = lastcall = ic + 1;
|
f->lastcall = lastcall = ic + 1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
f->noncalls++;
|
f->noncalls++;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
#undef U
|
#undef U
|
||||||
|
|
||||||
|
|||||||
+26
-53
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,27 +25,22 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// 16-bit call-/swaptrick ("naive")
|
// 16-bit call-/swaptrick ("naive")
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
|
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 3; \
|
byte *b_end = b + f->buf_len - 3; \
|
||||||
do { \
|
do { \
|
||||||
if (cond1) \
|
if (cond1) { \
|
||||||
{ \
|
|
||||||
b += 1; \
|
b += 1; \
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
set(b, get(b) + (addvalue)); \
|
set(b, get(b) + (addvalue)); \
|
||||||
f->calls++; \
|
f->calls++; \
|
||||||
b += 2 - 1; \
|
b += 2 - 1; \
|
||||||
} \
|
} else if (cond2) { \
|
||||||
else if (cond2) \
|
|
||||||
{ \
|
|
||||||
b += 1; \
|
b += 1; \
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
@@ -54,68 +49,55 @@
|
|||||||
b += 2 - 1; \
|
b += 2 - 1; \
|
||||||
} \
|
} \
|
||||||
} while (++b < b_end); \
|
} while (++b < b_end); \
|
||||||
if (f->lastcall) f->lastcall += 2; \
|
if (f->lastcall) \
|
||||||
|
f->lastcall += 2; \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
// filter
|
// filter
|
||||||
static int f_ctsw16_e8_e9(Filter *f)
|
static int f_ctsw16_e8_e9(Filter *f) {
|
||||||
{
|
|
||||||
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ctsw16_e9_e8(Filter *f)
|
static int f_ctsw16_e9_e8(Filter *f) {
|
||||||
{
|
|
||||||
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
|
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter
|
// unfilter
|
||||||
static int u_ctsw16_e8_e9(Filter *f)
|
static int u_ctsw16_e8_e9(Filter *f) {
|
||||||
{
|
|
||||||
CTSW16(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
CTSW16(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ctsw16_e9_e8(Filter *f)
|
static int u_ctsw16_e9_e8(Filter *f) {
|
||||||
{
|
|
||||||
CTSW16(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
|
CTSW16(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan
|
// scan
|
||||||
static int s_ctsw16_e8_e9(Filter *f)
|
static int s_ctsw16_e8_e9(Filter *f) {
|
||||||
{
|
|
||||||
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ctsw16_e9_e8(Filter *f)
|
static int s_ctsw16_e9_e8(Filter *f) {
|
||||||
{
|
|
||||||
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#undef CTSW16
|
#undef CTSW16
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// 32-bit call-/swaptrick ("naive")
|
// 32-bit call-/swaptrick ("naive")
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
|
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 5; \
|
byte *b_end = b + f->buf_len - 5; \
|
||||||
do { \
|
do { \
|
||||||
if (cond1) \
|
if (cond1) { \
|
||||||
{ \
|
|
||||||
b += 1; \
|
b += 1; \
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
set(b, get(b) + (addvalue)); \
|
set(b, get(b) + (addvalue)); \
|
||||||
f->calls++; \
|
f->calls++; \
|
||||||
b += 4 - 1; \
|
b += 4 - 1; \
|
||||||
} \
|
} else if (cond2) { \
|
||||||
else if (cond2) \
|
|
||||||
{ \
|
|
||||||
b += 1; \
|
b += 1; \
|
||||||
unsigned a = (unsigned) (b - f->buf); \
|
unsigned a = (unsigned) (b - f->buf); \
|
||||||
f->lastcall = a; \
|
f->lastcall = a; \
|
||||||
@@ -124,46 +106,37 @@ static int s_ctsw16_e9_e8(Filter *f)
|
|||||||
b += 4 - 1; \
|
b += 4 - 1; \
|
||||||
} \
|
} \
|
||||||
} while (++b < b_end); \
|
} while (++b < b_end); \
|
||||||
if (f->lastcall) f->lastcall += 4; \
|
if (f->lastcall) \
|
||||||
|
f->lastcall += 4; \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
// filter
|
// filter
|
||||||
static int f_ctsw32_e8_e9(Filter *f)
|
static int f_ctsw32_e8_e9(Filter *f) {
|
||||||
{
|
|
||||||
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f_ctsw32_e9_e8(Filter *f)
|
static int f_ctsw32_e9_e8(Filter *f) {
|
||||||
{
|
|
||||||
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
|
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unfilter
|
// unfilter
|
||||||
static int u_ctsw32_e8_e9(Filter *f)
|
static int u_ctsw32_e8_e9(Filter *f) {
|
||||||
{
|
|
||||||
CTSW32(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
CTSW32(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u_ctsw32_e9_e8(Filter *f)
|
static int u_ctsw32_e9_e8(Filter *f) {
|
||||||
{
|
|
||||||
CTSW32(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
|
CTSW32(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan
|
// scan
|
||||||
static int s_ctsw32_e8_e9(Filter *f)
|
static int s_ctsw32_e8_e9(Filter *f) {
|
||||||
{
|
|
||||||
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_ctsw32_e9_e8(Filter *f)
|
static int s_ctsw32_e9_e8(Filter *f) {
|
||||||
{
|
|
||||||
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#undef CTSW32
|
#undef CTSW32
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/* filteri.cpp -- filter implementation (low-level)
|
/* filter_impl.cpp -- filter implementation (low-level)
|
||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,41 +25,32 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../conf.h"
|
||||||
|
#include "../filter.h"
|
||||||
|
|
||||||
#include "conf.h"
|
static unsigned umin(const unsigned a, const unsigned b) { return (a <= b) ? a : b; }
|
||||||
#include "filter.h"
|
|
||||||
|
|
||||||
static unsigned
|
|
||||||
umin(unsigned const a, unsigned const b)
|
|
||||||
{
|
|
||||||
return (a<=b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define set_dummy(p, v) ((void) 0)
|
#define set_dummy(p, v) ((void) 0)
|
||||||
#define get_8(p) (*(p))
|
#define get_8(p) (*(p))
|
||||||
#define set_8(p, v) (*(p) = (v))
|
#define set_8(p, v) (*(p) = (v))
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "filter/getcto.h"
|
#include "getcto.h"
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// simple filters: calltrick / swaptrick / delta / ...
|
// simple filters: calltrick / swaptrick / delta / ...
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "filter/ct.h"
|
#include "ct.h"
|
||||||
#include "filter/sw.h"
|
#include "sw.h"
|
||||||
#include "filter/ctsw.h"
|
#include "ctsw.h"
|
||||||
|
|
||||||
#include "filter/sub8.h"
|
|
||||||
#include "filter/sub16.h"
|
|
||||||
#include "filter/sub32.h"
|
|
||||||
|
|
||||||
|
#include "sub8.h"
|
||||||
|
#include "sub16.h"
|
||||||
|
#include "sub32.h"
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// cto calltrick
|
// cto calltrick
|
||||||
@@ -68,28 +59,27 @@ umin(unsigned const a, unsigned const b)
|
|||||||
#define COND(b, x) (b[x] == 0xe8)
|
#define COND(b, x) (b[x] == 0xe8)
|
||||||
#define F f_cto32_e8_bswap_le
|
#define F f_cto32_e8_bswap_le
|
||||||
#define U u_cto32_e8_bswap_le
|
#define U u_cto32_e8_bswap_le
|
||||||
#include "filter/cto.h"
|
#include "cto.h"
|
||||||
#define F s_cto32_e8_bswap_le
|
#define F s_cto32_e8_bswap_le
|
||||||
#include "filter/cto.h"
|
#include "cto.h"
|
||||||
#undef COND
|
#undef COND
|
||||||
|
|
||||||
#define COND(b, x) (b[x] == 0xe9)
|
#define COND(b, x) (b[x] == 0xe9)
|
||||||
#define F f_cto32_e9_bswap_le
|
#define F f_cto32_e9_bswap_le
|
||||||
#define U u_cto32_e9_bswap_le
|
#define U u_cto32_e9_bswap_le
|
||||||
#include "filter/cto.h"
|
#include "cto.h"
|
||||||
#define F s_cto32_e9_bswap_le
|
#define F s_cto32_e9_bswap_le
|
||||||
#include "filter/cto.h"
|
#include "cto.h"
|
||||||
#undef COND
|
#undef COND
|
||||||
|
|
||||||
#define COND(b, x) (b[x] == 0xe8 || b[x] == 0xe9)
|
#define COND(b, x) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||||
#define F f_cto32_e8e9_bswap_le
|
#define F f_cto32_e8e9_bswap_le
|
||||||
#define U u_cto32_e8e9_bswap_le
|
#define U u_cto32_e8e9_bswap_le
|
||||||
#include "filter/cto.h"
|
#include "cto.h"
|
||||||
#define F s_cto32_e8e9_bswap_le
|
#define F s_cto32_e8e9_bswap_le
|
||||||
#include "filter/cto.h"
|
#include "cto.h"
|
||||||
#undef COND
|
#undef COND
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// cto calltrick with jmp
|
// cto calltrick with jmp
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -97,12 +87,11 @@ umin(unsigned const a, unsigned const b)
|
|||||||
#define COND(b, x, lastcall) (b[x] == 0xe8 || b[x] == 0xe9)
|
#define COND(b, x, lastcall) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||||
#define F f_ctoj32_e8e9_bswap_le
|
#define F f_ctoj32_e8e9_bswap_le
|
||||||
#define U u_ctoj32_e8e9_bswap_le
|
#define U u_ctoj32_e8e9_bswap_le
|
||||||
#include "filter/ctoj.h"
|
#include "ctoj.h"
|
||||||
#define F s_ctoj32_e8e9_bswap_le
|
#define F s_ctoj32_e8e9_bswap_le
|
||||||
#include "filter/ctoj.h"
|
#include "ctoj.h"
|
||||||
#undef COND
|
#undef COND
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// cto calltrick with jmp, optional jcc
|
// cto calltrick with jmp, optional jcc
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -112,35 +101,32 @@ umin(unsigned const a, unsigned const b)
|
|||||||
#define COND(b, x, lc, id) (COND1(b, x) || ((9 <= (0xf & (id))) && COND2(b, x, lc)))
|
#define COND(b, x, lc, id) (COND1(b, x) || ((9 <= (0xf & (id))) && COND2(b, x, lc)))
|
||||||
#define F f_ctok32_e8e9_bswap_le
|
#define F f_ctok32_e8e9_bswap_le
|
||||||
#define U u_ctok32_e8e9_bswap_le
|
#define U u_ctok32_e8e9_bswap_le
|
||||||
#include "filter/ctok.h"
|
#include "ctok.h"
|
||||||
#define F s_ctok32_e8e9_bswap_le
|
#define F s_ctok32_e8e9_bswap_le
|
||||||
#include "filter/ctok.h"
|
#include "ctok.h"
|
||||||
#undef COND
|
#undef COND
|
||||||
#undef COND2
|
#undef COND2
|
||||||
#undef COND1
|
#undef COND1
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// cto calltrick with jmp and jcc and relative renumbering
|
// cto calltrick with jmp and jcc and relative renumbering
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define COND_CALL(which, b, x) ((which = 0), b[x] == 0xe8)
|
#define COND_CALL(which, b, x) ((which = 0), b[x] == 0xe8)
|
||||||
#define COND_JMP(which, b, x) ((which = 1), b[x] == 0xe9)
|
#define COND_JMP(which, b, x) ((which = 1), b[x] == 0xe9)
|
||||||
#define COND_JCC( which,b,lastcall,x,y,z) ((which = 2), \
|
#define COND_JCC(which, b, lastcall, x, y, z) \
|
||||||
(lastcall!=(x) && 0xf==b[y] && 0x80<=b[z] && b[z]<=0x8f))
|
((which = 2), (lastcall != (x) && 0xf == b[y] && 0x80 <= b[z] && b[z] <= 0x8f))
|
||||||
#define COND1(which, b, x) (COND_CALL(which, b, x) || COND_JMP(which, b, x))
|
#define COND1(which, b, x) (COND_CALL(which, b, x) || COND_JMP(which, b, x))
|
||||||
#define COND2(which, b, lastcall, x, y, z) COND_JCC(which, b, lastcall, x, y, z)
|
#define COND2(which, b, lastcall, x, y, z) COND_JCC(which, b, lastcall, x, y, z)
|
||||||
|
|
||||||
#define CONDF(which,b,x,lastcall) \
|
#define CONDF(which, b, x, lastcall) (COND1(which, b, x) || COND2(which, b, lastcall, x, (x) -1, x))
|
||||||
(COND1(which,b,x) || COND2(which,b,lastcall,x,(x)-1, x ))
|
#define CONDU(which, b, x, lastcall) (COND1(which, b, x) || COND2(which, b, lastcall, x, x, (x) -1))
|
||||||
#define CONDU(which,b,x,lastcall) \
|
|
||||||
(COND1(which,b,x) || COND2(which,b,lastcall,x, x ,(x)-1))
|
|
||||||
|
|
||||||
#define F f_ctojr32_e8e9_bswap_le
|
#define F f_ctojr32_e8e9_bswap_le
|
||||||
#define U u_ctojr32_e8e9_bswap_le
|
#define U u_ctojr32_e8e9_bswap_le
|
||||||
#include "filter/ctojr.h"
|
#include "ctojr.h"
|
||||||
#define F s_ctojr32_e8e9_bswap_le
|
#define F s_ctojr32_e8e9_bswap_le
|
||||||
#include "filter/ctojr.h"
|
#include "ctojr.h"
|
||||||
|
|
||||||
#undef CONDU
|
#undef CONDU
|
||||||
#undef CONDF
|
#undef CONDF
|
||||||
@@ -150,7 +136,6 @@ umin(unsigned const a, unsigned const b)
|
|||||||
#undef COND_JMP
|
#undef COND_JMP
|
||||||
#undef COND_CALL
|
#undef COND_CALL
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// PowerPC branch [incl. call] trick
|
// PowerPC branch [incl. call] trick
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -158,17 +143,17 @@ umin(unsigned const a, unsigned const b)
|
|||||||
#define COND(b, x) (18 == (get_be32(b + x) >> 26))
|
#define COND(b, x) (18 == (get_be32(b + x) >> 26))
|
||||||
#define F f_ppcbxx
|
#define F f_ppcbxx
|
||||||
#define U u_ppcbxx
|
#define U u_ppcbxx
|
||||||
#include "filter/ppcbxx.h"
|
#include "ppcbxx.h"
|
||||||
#define F s_ppcbxx
|
#define F s_ppcbxx
|
||||||
#include "filter/ppcbxx.h"
|
#include "ppcbxx.h"
|
||||||
#undef COND
|
#undef COND
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// database for use in class Filter
|
// database for use in class Filter
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
const FilterImp::FilterEntry FilterImp::filters[] = {
|
// clang-format off
|
||||||
|
/*static*/ const FilterImpl::FilterEntry FilterImpl::filters[] = {
|
||||||
// no filter
|
// no filter
|
||||||
{ 0x00, 0, 0, nullptr, nullptr, nullptr },
|
{ 0x00, 0, 0, nullptr, nullptr, nullptr },
|
||||||
|
|
||||||
@@ -228,8 +213,13 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
|||||||
{ 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le },
|
{ 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le },
|
||||||
{ 0x51, 8, 0x01ffffff, f_ct24arm_be, u_ct24arm_be, s_ct24arm_be },
|
{ 0x51, 8, 0x01ffffff, f_ct24arm_be, u_ct24arm_be, s_ct24arm_be },
|
||||||
|
|
||||||
|
#if 1 //{ old reliable
|
||||||
// 26-bit calltrick for arm64
|
// 26-bit calltrick for arm64
|
||||||
{ 0x52, 8, 0x03ffffff, f_ct26arm_le, u_ct26arm_le, s_ct26arm_le },
|
{ 0x52, 8, 0x03ffffff, f_ct26arm_le, u_ct26arm_le, s_ct26arm_le },
|
||||||
|
#else //}{ new enhanced, but needs new filter id
|
||||||
|
// 26-bit calltrick for arm64; also 19-bit and 14-bit
|
||||||
|
{ 0x52, 8, 0x03ffffff, f_CTarm64_le, u_CTarm64_le, s_CTarm64_le },
|
||||||
|
#endif //}
|
||||||
|
|
||||||
// 32-bit cto calltrick with jmp and jcc(swap 0x0f/0x8Y) and relative renumbering
|
// 32-bit cto calltrick with jmp and jcc(swap 0x0f/0x8Y) and relative renumbering
|
||||||
{ 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
{ 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
|
||||||
@@ -260,7 +250,8 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
|
|||||||
// PowerPC branch+call trick
|
// PowerPC branch+call trick
|
||||||
{ 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx },
|
{ 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx },
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
const int FilterImp::n_filters = TABLESIZE(filters);
|
/*static*/ const int FilterImpl::n_filters = TABLESIZE(filters);
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
+7
-13
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,22 +25,16 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int getcto(Filter *f, const unsigned char *buf, const int n=256)
|
static int getcto(Filter *f, const byte *buf, const int n = 256) {
|
||||||
{
|
|
||||||
int ic = n;
|
int ic = n;
|
||||||
|
|
||||||
if (f->preferred_ctos)
|
if (f->preferred_ctos) {
|
||||||
{
|
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++) {
|
||||||
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
|
if (*pc < n && buf[*pc] == 0) {
|
||||||
{
|
|
||||||
if (*pc < n && buf[*pc] == 0)
|
|
||||||
{
|
|
||||||
ic = *pc;
|
ic = *pc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -63,7 +57,7 @@ static int getcto(Filter *f, const unsigned char *buf, const int n=256)
|
|||||||
// throwCantPack("call trick problem");
|
// throwCantPack("call trick problem");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
f->cto = (unsigned char) ic;
|
f->cto = (byte) ic;
|
||||||
return ic;
|
return ic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-22
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
Copyright (C) 2004-2022 John F. Reiser
|
Copyright (C) 2004-2024 John F. Reiser
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -29,23 +29,20 @@
|
|||||||
<jreiser@users.sourceforge.net>
|
<jreiser@users.sourceforge.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// filter / scan
|
// filter / scan
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define W_CTO 4 /* width of cto; must match stub/ppc_bxx.S */
|
#define W_CTO 4 /* width of cto; must match stub/ppc_bxx.S */
|
||||||
|
|
||||||
static int F(Filter *f)
|
static int F(Filter *f) {
|
||||||
{
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned size = umin(f->buf_len, 0u - (~0u << (32 - (6 + W_CTO))));
|
const unsigned size = umin(f->buf_len, 0u - (~0u << (32 - (6 + W_CTO))));
|
||||||
const unsigned size4 = size - 4;
|
const unsigned size4 = size - 4;
|
||||||
@@ -63,7 +60,8 @@ static int F(Filter *f)
|
|||||||
memset(buf, 0, WW);
|
memset(buf, 0, WW);
|
||||||
memset(buf + WW, 1, 256 - WW);
|
memset(buf + WW, 1, 256 - WW);
|
||||||
|
|
||||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
for (ic = 0; ic <= size4; ic += 4)
|
||||||
|
if (COND(b, ic)) {
|
||||||
unsigned const off = (int) (get_be32(b + ic) << 6) >> 6;
|
unsigned const off = (int) (get_be32(b + ic) << 6) >> 6;
|
||||||
if (size <= (off & (~0u << 2)) + ic) {
|
if (size <= (off & (~0u << 2)) + ic) {
|
||||||
buf[(~(~0u << W_CTO)) & (off >> (26 - W_CTO))] |= 1;
|
buf[(~(~0u << W_CTO)) & (off >> (26 - W_CTO))] |= 1;
|
||||||
@@ -84,7 +82,8 @@ static int F(Filter *f)
|
|||||||
const unsigned cto = (unsigned) f->cto << (24 + 2 - W_CTO);
|
const unsigned cto = (unsigned) f->cto << (24 + 2 - W_CTO);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
for (ic = 0; ic <= size4; ic += 4)
|
||||||
|
if (COND(b, ic)) {
|
||||||
unsigned const word = get_be32(b + ic);
|
unsigned const word = get_be32(b + ic);
|
||||||
unsigned const off = (int) (word << 6) >> 6;
|
unsigned const off = (int) (word << 6) >> 6;
|
||||||
unsigned const jc = (off & (~0u << 2)) + ic;
|
unsigned const jc = (off & (~0u << 2)) + ic;
|
||||||
@@ -95,10 +94,10 @@ static int F(Filter *f)
|
|||||||
#endif
|
#endif
|
||||||
calls++;
|
calls++;
|
||||||
lastcall = ic;
|
lastcall = ic;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
#if (W_CTO != 0)
|
#if (W_CTO != 0)
|
||||||
assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != (unsigned) cto8); // this should not happen
|
assert((~(~0u << W_CTO) & (word >> (24 + 2 - W_CTO))) !=
|
||||||
|
(unsigned) cto8); // this should not happen
|
||||||
#endif
|
#endif
|
||||||
lastnoncall = ic;
|
lastnoncall = ic;
|
||||||
noncalls++;
|
noncalls++;
|
||||||
@@ -117,29 +116,27 @@ static int F(Filter *f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// unfilter
|
// unfilter
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f) {
|
||||||
{
|
byte *b = f->buf;
|
||||||
upx_byte *b = f->buf;
|
|
||||||
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u << (32 - (6 + W_CTO))));
|
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u << (32 - (6 + W_CTO))));
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
|
|
||||||
unsigned ic;
|
unsigned ic;
|
||||||
|
|
||||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
for (ic = 0; ic <= size4; ic += 4)
|
||||||
|
if (COND(b, ic)) {
|
||||||
unsigned const word = get_be32(b + ic);
|
unsigned const word = get_be32(b + ic);
|
||||||
if ((~(~0u << W_CTO) & (word >> (24 + 2 - W_CTO))) == (unsigned) f->cto) {
|
if ((~(~0u << W_CTO) & (word >> (24 + 2 - W_CTO))) == (unsigned) f->cto) {
|
||||||
unsigned const jc = word & (~(~0u << (26 - W_CTO)) & (~0u << 2));
|
unsigned const jc = word & (~(~0u << (26 - W_CTO)) & (~0u << 2));
|
||||||
set_be32(b + ic, (0xfc000003 & word) | (0x03fffffc & (jc - ic - addvalue)));
|
set_be32(b + ic, (0xfc000003 & word) | (0x03fffffc & (jc - ic - addvalue)));
|
||||||
f->calls++;
|
f->calls++;
|
||||||
f->lastcall = ic;
|
f->lastcall = ic;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
f->noncalls++;
|
f->noncalls++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,7 +144,6 @@ static int U(Filter *f)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#undef F
|
#undef F
|
||||||
#undef U
|
#undef U
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
This file is part of the UPX executable compressor.
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
Copyright (C) 1996-2022 Markus Franz Xaver Johannes Oberhumer
|
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
|
||||||
Copyright (C) 1996-2022 Laszlo Molnar
|
Copyright (C) 1996-2024 Laszlo Molnar
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
UPX and the UCL library are free software; you can redistribute them
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
@@ -25,19 +25,20 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define SUB(f, N, T, get, set) \
|
#define SUB(f, N, T, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
unsigned l = f->buf_len / sizeof(T); \
|
unsigned l = f->buf_len / sizeof(T); \
|
||||||
int i; \
|
int i; \
|
||||||
T d[N]; \
|
T d[N]; \
|
||||||
\
|
\
|
||||||
i = N - 1; do d[i] = 0; while (--i >= 0); \
|
i = N - 1; \
|
||||||
|
do \
|
||||||
|
d[i] = 0; \
|
||||||
|
while (--i >= 0); \
|
||||||
\
|
\
|
||||||
i = N - 1; \
|
i = N - 1; \
|
||||||
do { \
|
do { \
|
||||||
@@ -52,14 +53,16 @@
|
|||||||
assert((int) f->calls > 0); \
|
assert((int) f->calls > 0); \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
#define ADD(f, N, T, get, set) \
|
#define ADD(f, N, T, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
unsigned l = f->buf_len / sizeof(T); \
|
unsigned l = f->buf_len / sizeof(T); \
|
||||||
int i; \
|
int i; \
|
||||||
T d[N]; \
|
T d[N]; \
|
||||||
\
|
\
|
||||||
i = N - 1; do d[i] = 0; while (--i >= 0); \
|
i = N - 1; \
|
||||||
|
do \
|
||||||
|
d[i] = 0; \
|
||||||
|
while (--i >= 0); \
|
||||||
\
|
\
|
||||||
i = N - 1; \
|
i = N - 1; \
|
||||||
do { \
|
do { \
|
||||||
@@ -73,7 +76,6 @@
|
|||||||
assert((int) f->calls > 0); \
|
assert((int) f->calls > 0); \
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
#define SCAN(f, N, T, get, set) \
|
#define SCAN(f, N, T, get, set) \
|
||||||
f->calls = (f->buf_len / sizeof(T)) - N; \
|
f->calls = (f->buf_len / sizeof(T)) - N; \
|
||||||
assert((int) f->calls > 0); \
|
assert((int) f->calls > 0); \
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user