Compare commits

...

374 Commits

Author SHA1 Message Date
Markus F.X.J. Oberhumer 5bef968068 all: prepare for release 2024-03-27 13:57:30 +01:00
Markus F.X.J. Oberhumer 543cfe0a73 submodules: update for new versions 2024-03-26 15:46:48 +01:00
Markus F.X.J. Oberhumer 3ba91b8072 cmake update 2024-03-26 15:38:20 +01:00
Markus F.X.J. Oberhumer a27a9e6000 all: and yet more cleanups; NFCI 2024-03-25 11:07:40 +01:00
Markus F.X.J. Oberhumer 7e839e6962 all: more cleanups; NFCI 2024-03-23 20:18:28 +01:00
Markus F.X.J. Oberhumer 809a1b3dae submodules: update for new versions 2024-03-22 01:40:51 +01:00
Markus F.X.J. Oberhumer 9b80628f84 src/pefile.cpp: support relocs of large files
Use 5-byte entries instead of 4-byte entries to fully preserve "pos".

And add some symbolic constants.

Partially based on a patch by John.
2024-03-22 00:46:17 +01:00
Markus F.X.J. Oberhumer a21a006fe9 all: yet more minor cleanups 2024-03-19 16:03:37 +01:00
Markus F.X.J. Oberhumer 54d16a458a CI updates; cleanups 2024-03-16 17:46:40 +01:00
Markus F.X.J. Oberhumer cfc5f42ef2 testsuite: update checksums caused by version change 2024-03-12 18:16:52 +01:00
Markus F.X.J. Oberhumer e3d24238e4 all: update version 2024-03-12 18:12:43 +01:00
Markus F.X.J. Oberhumer 56e7b36959 src: new ACC version 2024-03-12 18:11:46 +01:00
Markus F.X.J. Oberhumer f29791470f all: yet more cleanups 2024-03-10 16:23:06 +01:00
Markus F.X.J. Oberhumer 52d9b53b74 all: minor cleanups 2024-03-08 11:52:44 +01:00
Markus F.X.J. Oberhumer 839a78f2e0 Better fix for previous commit to avoid out-of-bounds pointer. 2024-02-27 11:20:29 +01:00
John Reiser 680ce0a7af find_dt_ndx defends against overrun
https://github.com/upx/upx/issues/790
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66344&q=label%3AProj-upx
	modified:   p_lx_elf.cpp
2024-02-26 14:32:02 -08:00
Markus F.X.J. Oberhumer 06b0de9c77 CI: work-around zig cc mips bad codegen for hard-float 2024-02-17 16:34:11 +01:00
Markus F.X.J. Oberhumer 76b0b7b1ae all: clang-format 2024-02-14 21:29:51 +01:00
John Reiser fabda4df3a R_PPC64_REL24 is reallly "PC-rel. 26 bit, word aligned:
Just like R_PPC_REL24
	modified:   linker.cpp
2024-02-14 11:43:20 -08:00
Markus F.X.J. Oberhumer fdcdaf596a all: pacify clang-tidy, CI and cmake updates 2024-02-14 15:14:47 +01:00
Markus F.X.J. Oberhumer be44cefbe7 CI updates 2024-02-13 18:29:07 +01:00
Markus F.X.J. Oberhumer c1050e624b submodules: update for new versions 2024-02-13 16:49:08 +01:00
Markus F.X.J. Oberhumer ae6d3b9bff all: more assorted cleanups 2024-02-09 14:48:47 +01:00
John Reiser 25aa0e2e46 un_asl_dynsym() should skip when !dynstr
https://github.com/upx/upx/issues/785
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66302
	modified:   p_lx_elf.cpp
2024-02-08 19:32:03 -08:00
Markus F.X.J. Oberhumer 8f7578eef1 CI: enable valgrind 2024-02-04 13:54:37 +01:00
Markus F.X.J. Oberhumer 29ce4807fb all: minor updates 2024-02-04 13:37:00 +01:00
John Reiser 41f6945be1 Fix auxv_up() to avoid SIGSEGV under valgrind
https://github.com/upx/upx/issues/784
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-main.c
	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
           plus all generated stub/*-linux.elf-fold.{h,map}
2024-02-03 13:58:53 -08:00
Markus F.X.J. Oberhumer 718ec468ff all: more assorted cleanups; NFCI 2024-02-02 10:17:16 +01:00
John Reiser d429801498 Avoid &file_image[file_size] because some Standards object
modified:   p_lx_elf.cpp
2024-02-01 11:41:04 -08:00
Markus F.X.J. Oberhumer 024091e6b5 src: fix previous bounds checking commit 2024-01-31 20:52:19 +01:00
Markus F.X.J. Oberhumer d849e9de98 src: add some bounds checking to MemBufferBase 2024-01-31 16:48:55 +01:00
John Reiser c0e40da2ab more checking of Mach_header when unpacking for MachOS
https://github.com/upx/upx/issues/783
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65532
	modified:   p_mach.cpp
2024-01-27 14:16:53 -08:00
John Reiser dff3766501 Detect too-large bit-shift in elf_lookup of DT_GNUHASH
https://github.com/upx/upx/issues/782
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65776
	modified:   p_lx_elf.cpp
2024-01-27 13:38:25 -08:00
John Reiser 2767ec54e1 more checking of PackUnix::p_info at unpack
https://github.com/upx/upx/issues/781
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65864
	modified:   p_unix.cpp
2024-01-27 13:06:59 -08:00
John Reiser ac72c02793 check nbucket earlier in DT_HASH on ELF
https://github.com/upx/upx/issues/780
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66079
	modified:   p_lx_elf.cpp
2024-01-27 11:42:25 -08:00
John Reiser 69c51eee4d better checking of DT_STRSZ for ELF
https://github.com/upx/upx/issues/779
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66064
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2024-01-27 11:11:07 -08:00
John Reiser ff5a4eeb96 ELF versus --brute: addStubEntrySections() needs ph_forced_method()
https://github.com/upx/upx/issues/770
	modified:   p_lx_elf.cpp
2024-01-25 17:17:32 -08:00
John Reiser b48f870701 Detect circular DT_HASH and DT_GNUHASH lookup
https://github.com/upx/upx/issues/775
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65811&q=label%3AProj-upx
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65840&q=label%3AProj-upx
2024-01-25 15:05:53 -08:00
John Reiser 10807ebdc2 Unpack 8-byte b_info only if (ph.version <= 11): 2001 or earlier
*x86 only: .e_entry too low
https://github.com/upx/upx/issues/774
	modified:   p_lx_elf.cpp
2024-01-25 09:06:46 -08:00
Markus F.X.J. Oberhumer 5d649f83ec all: assorted cleanups 2024-01-24 20:53:14 +01:00
Markus F.X.J. Oberhumer 65b25adceb submodules: update for new versions 2024-01-24 20:49:33 +01:00
John Reiser d615985b8a elf_find_table_size() did not check for empty table
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65765&q=label%3AProj-upx
https://github.com/upx/upx/issues/771
	modified:   p_lx_elf.cpp
2024-01-18 19:11:12 -08:00
Markus F.X.J. Oberhumer b019440980 testsuite: update checksums caused by version year bump 2024-01-13 20:08:08 +01:00
John Reiser 38ed4b2017 arm32, arm64 ABI for -static must preserve register 0
Also arm32 forgot to unmap the expanded de-compressor via the escape hatch.

https://github.com/upx/upx/issues/758
https://github.com/upx/upx/issues/768
	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/amd64-linux.elf-main.c
          plus associated *.h *.map *.dump
2024-01-12 15:39:18 -08:00
John Reiser 2ad0d51226 PeFile::rebuildImports(): Allow strlen() up to the very end of a logical block
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65650
https://github.com/upx/upx/issues/769
	modified:   pefile.cpp
2024-01-11 09:57:57 -08:00
John Reiser e4a611bcae PeFile ::readPeHeader should check ih.subsystem.
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65526
https://github.com/upx/upx/issues/767
	modified:   pefile.cpp
2024-01-10 16:28:17 -08:00
John Reiser f3728d99b9 Check ph.method in PackMachBase::unpack
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65553
https://github.com/upx/upx/issues/766
	modified:   p_mach.cpp
2024-01-10 16:04:08 -08:00
John Reiser b87f60a917 Check Mach_fat_arch.align
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65558
https://github.com/upx/upx/issues/765
	modified:   p_mach.cpp
2024-01-10 15:31:37 -08:00
John Reiser 28f26da6ab Need more care in PackMachBase::canUnpack()
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65532
https://github.com/upx/upx/issues/764
	modified:   p_mach.cpp
2024-01-10 15:14:54 -08:00
John Reiser d3e780d617 Unpacking ELF requires e_phnum at least 2
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65535
https://github.com/upx/upx/issues/763
	modified:   p_lx_elf.cpp
2024-01-10 14:07:58 -08:00
John Reiser d549c2b5c9 More care when recovering from slid b_info
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65531
https://github.com/upx/upx/issues/762
	modified:   p_lx_elf.cpp
2024-01-10 13:38:18 -08:00
John Reiser f310ce376e Beware fuzzer setting compressed size too small
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65519
https://github.com/upx/upx/issues/761
	modified:   p_unix.cpp
2024-01-10 11:20:47 -08:00
John Reiser 553fc9b1fb invert_pt_dynamic: Compilers differ, unsigned vs. signed
modified:   p_lx_elf.cpp
2024-01-10 10:33:33 -08:00
John Reiser 6dde9f7dc0 find_overlay_offset() did not check carefully enough
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65518
https://github.com/upx/upx/issues/760
	modified:   p_unix.cpp
2024-01-10 10:05:28 -08:00
John Reiser 3dca1175e5 invert_pt_dynamic() needs better checking for malformed input
https://github.com/upx/upx/issues/759
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65510
	modified:   p_lx_elf.cpp
2024-01-10 09:41:12 -08:00
John Reiser 09c5e38322 arm64-linux.elf ABI owns x0 at execve()?
https://github.com/upx/upx/issues/758
	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/tmp/arm64-linux.elf-fold.map
2024-01-09 12:17:01 -08:00
John Reiser fe6f1f0bb6 arm64-linux.elf-fold.S typo (eyesight)
https://github.com/upx/upx/issues/743
	modified:   misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
	modified:   src/stub/arm64-linux.elf-fold.h
	modified:   src/stub/src/arm64-linux.elf-fold.S
2024-01-09 10:01:07 -08:00
Markus F.X.J. Oberhumer 250c656b9e testsuite: update checksums caused by version bump 2024-01-04 03:18:19 +01:00
Markus F.X.J. Oberhumer 9a0b5b65b8 all: remove unused scripts 2024-01-04 03:09:48 +01:00
Markus F.X.J. Oberhumer 57b2fb4c62 all: post-release version bump 2024-01-04 02:52:22 +01:00
Markus F.X.J. Oberhumer 099c3d829e all: prepare for release. 2024-01-03 18:43:18 +01:00
Markus F.X.J. Oberhumer a1a6d02b6f all: tired of CI updates 2024-01-03 18:01:56 +01:00
Markus F.X.J. Oberhumer f2ad7fb9c4 testsuite: update checksums caused by version bump 2024-01-03 18:00:07 +01:00
Markus F.X.J. Oberhumer 1bcf709fcf all: bump version date 2024-01-03 17:54:43 +01:00
Markus F.X.J. Oberhumer 47fc230893 all: welcome 2024 2024-01-03 17:47:25 +01:00
Markus F.X.J. Oberhumer be05d85570 submodules: update for new versions 2024-01-03 17:44:57 +01:00
Markus F.X.J. Oberhumer f598fa13a9 clang-format 2024-01-03 17:36:43 +01:00
Markus F.X.J. Oberhumer 568859d16f CI updates 2024-01-03 17:31:16 +01:00
Markus F.X.J. Oberhumer b5ed0a637b CI updates 2023-12-29 10:02:46 +01:00
Markus F.X.J. Oberhumer 17eff0aed4 CI updates 2023-12-29 05:45:00 +01:00
Markus F.X.J. Oberhumer 0a3f048eed CI updates 2023-12-29 05:14:03 +01:00
Markus F.X.J. Oberhumer 3cde897557 Improve testsuite. 2023-12-28 21:44:53 +01:00
Markus F.X.J. Oberhumer 0500e7d016 CI updates; cxxlib.h cleanups 2023-12-28 04:42:41 +01:00
Markus F.X.J. Oberhumer 778663ae69 CI updates 2023-12-21 23:01:52 +01:00
Markus F.X.J. Oberhumer 636cefb9f3 cmake update 2023-12-20 18:49:34 +01:00
Markus F.X.J. Oberhumer 1236776aa2 cmake update 2023-12-20 12:16:25 +01:00
Markus F.X.J. Oberhumer 51a6a5cca5 src: rename ptr_reinterpret_cast to ptr_static_cast; misc cleanups 2023-12-20 11:44:01 +01:00
Markus F.X.J. Oberhumer 3326c86e91 cmake update 2023-12-19 16:11:23 +01:00
Markus F.X.J. Oberhumer b0dbc3fe39 submodules: update for new versions 2023-12-19 16:10:32 +01:00
Markus F.X.J. Oberhumer decc1efb74 CI updates 2023-12-17 07:35:39 +01:00
Markus F.X.J. Oberhumer 2cf1c32d18 CI updates 2023-12-13 18:52:55 +01:00
Markus F.X.J. Oberhumer fc6e3840b7 CI updates 2023-12-09 08:52:25 +01:00
Markus F.X.J. Oberhumer 5e85c1a11b submodules: update for new versions 2023-12-09 08:34:48 +01:00
Markus F.X.J. Oberhumer 468bfce599 submodules: update for new versions 2023-12-02 01:52:32 +01:00
Markus F.X.J. Oberhumer 1e6e4043ed CI updates and minor cleanups. 2023-12-02 01:48:26 +01:00
John Reiser 67564513d2 Update because of age and evolution.
modified:   elf-to-mem.txt
2023-11-30 11:10:24 -08:00
John Reiser ed2633bf95 Honor .p_align <= 64K; else assume 4K is also available
https://github.com/upx/upx/issues/737
	modified:   p_lx_elf.cpp
2023-11-26 11:46:12 -08:00
Markus F.X.J. Oberhumer 3e70021406 all: more minor cleanups 2023-11-26 18:30:47 +01:00
Markus F.X.J. Oberhumer bf8dd31914 all: minor cleanups 2023-11-21 20:29:54 +01:00
John Reiser d4e94f5086 Fix varying page size on arm64
https://github.com/upx/upx/issues/734
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
          ... plus associated stub/*.h etc
2023-11-17 15:10:31 -08:00
John Reiser ae77fd60bb initial headway is limited by both file_size and mhcmdi.sizeofcmds
https://github.com/upx/upx/issues/732
	modified:   p_mach.cpp
2023-11-17 07:28:21 -08:00
Markus F.X.J. Oberhumer e79c790264 CI updates 2023-11-17 11:50:52 +01:00
Markus F.X.J. Oberhumer 46029bb8a0 CI updates 2023-11-15 13:06:29 +01:00
Markus F.X.J. Oberhumer f74c225338 CI updates 2023-11-14 19:15:34 +01:00
Markus F.X.J. Oberhumer c479fe32b3 cmake update 2023-11-13 11:29:17 +01:00
Markus F.X.J. Oberhumer dc23ee0ad2 submodules: update for new versions 2023-11-08 11:48:39 +01:00
Markus F.X.J. Oberhumer a5c32db01b CI updates 2023-11-08 11:25:23 +01:00
Markus F.X.J. Oberhumer d7142312c9 CI updates 2023-11-08 10:08:19 +01:00
Markus F.X.J. Oberhumer 283ab0e7ea CI updates and assorted cleanups 2023-11-06 19:29:40 +01:00
Markus F.X.J. Oberhumer b6dd61cea8 CI updates 2023-11-05 09:03:38 +01:00
Markus F.X.J. Oberhumer 11970d276d CI updates 2023-11-04 06:30:07 +01:00
Markus F.X.J. Oberhumer d618716ec1 Minify .clang-format
Remove all settings that currently do not have any effect.
2023-11-03 17:56:12 +01:00
Markus F.X.J. Oberhumer 4f0f977f04 CI updates and cleanups 2023-11-03 17:52:46 +01:00
Markus F.X.J. Oberhumer 2c4b1d8a8c submodules: update for new versions 2023-11-03 16:46:57 +01:00
Markus F.X.J. Oberhumer b2810c6deb testsuite: update checksums caused by version bump 2023-11-01 15:12:39 +01:00
Markus F.X.J. Oberhumer ceb2b56b71 all: post-release version bump 2023-11-01 15:07:18 +01:00
Markus F.X.J. Oberhumer d14fa5f8a4 all: prepare for release 2023-11-01 12:00:03 +01:00
Markus F.X.J. Oberhumer 79263a52ac submodules: update for new versions 2023-11-01 11:40:28 +01:00
Markus F.X.J. Oberhumer ecb3f83e83 CI updates 2023-11-01 11:28:35 +01:00
Markus F.X.J. Oberhumer f6aedb35ce CI updates 2023-11-01 10:06:27 +01:00
Markus F.X.J. Oberhumer 3b7d25ac49 CI updates 2023-11-01 08:48:27 +01:00
Markus F.X.J. Oberhumer e964d4acf3 src/util: change TriBool logic to use a bool template parameter 2023-10-31 12:24:44 +01:00
Markus F.X.J. Oberhumer e306085b81 CI updates 2023-10-31 11:49:18 +01:00
Markus F.X.J. Oberhumer b094ad4f2b CI updates 2023-10-31 10:34:55 +01:00
Markus F.X.J. Oberhumer 19c6b969ab src/options: fix bad TriBool ThirdValue for pefile compress_resources 2023-10-30 21:36:36 +01:00
Markus F.X.J. Oberhumer acfda848cd src/check: add some more tribool checks 2023-10-30 20:29:05 +01:00
John Reiser 52400e2561 /proc/self/exe now is optional
... for the benefit of 'unshare', 'chroot', etc.
If not present, then upx run-time stub unmaps all pages of original main program.
https://github.com/upx/upx/issues/721

	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh

           ... plus all associaed *.h, *.map, *.dump in stub/
2023-10-30 08:23:52 -07:00
Markus F.X.J. Oberhumer f62576a2be CI updates and minor cleanups 2023-10-30 14:15:35 +01:00
Markus F.X.J. Oberhumer 19bf9f59e9 src: clang-format stub/tools/armpe/armpe_tester.c 2023-10-30 13:07:20 +01:00
Markus F.X.J. Oberhumer fadf7cfc7b src: work on packed_struct cleanup 2023-10-30 12:55:07 +01:00
Markus F.X.J. Oberhumer ec0c9399fa src: clang-format conf.h 2023-10-30 12:30:58 +01:00
Markus F.X.J. Oberhumer 37b923245d all: various cleanups 2023-10-30 12:17:51 +01:00
Markus F.X.J. Oberhumer 38a676f6f7 src: introduce upx::ptr_reinterpret_cast 2023-10-29 16:52:24 +01:00
Markus F.X.J. Oberhumer cd1df6f6b1 all: update version 2023-10-29 15:37:13 +01:00
Markus F.X.J. Oberhumer 4a24fe8c53 CI updates and cleanups 2023-10-29 15:12:33 +01:00
Markus F.X.J. Oberhumer 6dac3dd248 CI updates 2023-10-27 09:24:06 +02:00
Markus F.X.J. Oberhumer 37d393cbc8 src: prefer using SetFileTime() on Windows 2023-10-27 06:58:14 +02:00
Markus F.X.J. Oberhumer 27f155374a testsuite: update checksums caused by version bump 2023-10-26 12:28:52 +02:00
Markus F.X.J. Oberhumer 8102137ad7 all: post-release version bump 2023-10-26 12:25:13 +02:00
Markus F.X.J. Oberhumer 9c46f4653f all: prepare for release 2023-10-26 11:09:48 +02:00
Markus F.X.J. Oberhumer 29b4752d0e src: add some noexcept 2023-10-26 00:28:36 +02:00
Markus F.X.J. Oberhumer 2724039c09 submodules: update for new versions 2023-10-26 00:23:57 +02:00
Markus F.X.J. Oberhumer 6ae4e88475 cmake: fix Xcode generator build 2023-10-25 06:47:09 +02:00
Markus F.X.J. Oberhumer facabd68d7 all: more minor cleanups 2023-10-24 23:56:55 +02:00
Markus F.X.J. Oberhumer 18f043015e all: minor cleanups 2023-10-24 22:54:54 +02:00
Markus F.X.J. Oberhumer ab259a1af9 src/pefile: try to clean up reloc handling 2023-10-24 11:47:23 +02:00
Markus F.X.J. Oberhumer 1dd96a7628 src/pefile: stricter reloc checks; cleanups 2023-10-23 14:26:37 +02:00
Markus F.X.J. Oberhumer 1ee7ecb1f0 all: prefer using utimensat() 2023-10-22 13:29:26 +02:00
Markus F.X.J. Oberhumer 67548a4d9a src: minor cleanups 2023-10-22 00:45:06 +02:00
Markus F.X.J. Oberhumer 9fbe95ad48 all: cleanups 2023-10-21 11:22:18 +02:00
dependabot[bot] 91c15b2475 build(deps): bump crate-ci/typos from 1.16.19 to 1.16.20
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.16.19 to 1.16.20.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/35a8bc67870d6c0b7407683319ae175577e24261...c004e98018d8621614d1ca516eed8ca2d04b365a)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-18 16:00:48 +00:00
Markus F.X.J. Oberhumer c9550b48d8 all: disable packing macOS binaries for now 2023-10-18 07:04:00 +02:00
Markus F.X.J. Oberhumer a1d090a6fd src/stub: add a "clang-format off" directive 2023-10-15 10:55:15 +02:00
Markus F.X.J. Oberhumer 4870765e1b all: disable packing macOS binaries for now 2023-10-15 10:15:46 +02:00
Markus F.X.J. Oberhumer d8be2ed276 src/pefile.cpp: cleanup reloc handling and add more checks 2023-10-14 19:24:44 +02:00
Markus F.X.J. Oberhumer 2b371e99bd src/util: minor xspan enhancements 2023-10-14 05:58:47 +02:00
Markus F.X.J. Oberhumer 005e39871b CI updates 2023-10-13 00:49:01 +02:00
Markus F.X.J. Oberhumer 96dd9eeb44 CI updates 2023-10-13 00:01:00 +02:00
John Reiser 65b06f6046 More LZMA inSize (srclen) defense
https://github.com/upx/upx/issues/717

	modified:   stub/src/amd64-darwin.dylib-entry.S  fixed
	modified:   stub/src/amd64-darwin.macho-entry.S  fixed
	modified:   stub/src/amd64-linux.elf-so_entry.S  comment-only
	modified:   stub/src/i386-linux.elf-so_entry.S  comment-only

	modified:   stub/amd64-darwin.dylib-entry.h
	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/amd64-linux.elf-so_entry.h
	modified:   stub/tmp/amd64-darwin.dylib-entry.bin.dump
	modified:   stub/tmp/amd64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/amd64-linux.elf-so_entry.bin.dump

Find+fix steps that were performed:
1. Find all 'add' instructions that compute "eof".
NRV run-time decompressors ignore srclen, so 'add' can be ignored for them.

$ cd upx-devel4/src/stub
$ grep -sr 'add.*eof' src  |  grep -v 'nrv2._d.*.S'  |  sort
src/amd64-darwin.dylib-entry.S:        addq src,lsrc; push lsrc  // &input_eof
src/amd64-darwin.macho-entry.S:        addq src,lsrc; push lsrc  // &input_eof
src/amd64-linux.elf-entry.S:        addq src,lsrc; push lsrc  // &input_eof
src/amd64-linux.elf-so_entry.S:        addq src,lsrc; push lsrc  // MATCH_05  &input_eof
src/amd64-linux.elf-so_main.c:            void *mfd_addr = Pmap(0, sizeof(code), PROT_READ|PROT_EXEC, MAP_PRIVATE, mfd, 0);
src/amd64-linux.shlib-init.S:        addq src,lsrc; push lsrc  // &input_eof
src/arch/amd64/lzma_d.S://      addq src,lsrc; push lsrc  // &input_eof
src/i386-expand.S:    add src,%ecx; push %ecx  // MATCH_52  eof_src
src/i386-linux.elf-so_entry.S:        add src,lsrc; push lsrc  // MATCH_05  &input_eof

2.  Case-by-case inspection

src/amd64-darwin.dylib-entry.S:        addq src,lsrc; push lsrc  // &input_eof
    restoring 'subq' is added in this commit

src/amd64-darwin.macho-entry.S:        addq src,lsrc; push lsrc  // &input_eof
    restoring 'subq' is added in this commit

src/amd64-linux.elf-entry.S:        addq src,lsrc; push lsrc  // &input_eof
    a restoring 'subq' is already next

src/amd64-linux.elf-so_entry.S:        addq src,lsrc; push lsrc  // MATCH_05  &input_eof
    lsrc is dead for inlined nrv2b

src/amd64-linux.elf-so_main.c:            void *mfd_addr = Pmap(0, sizeof(code), PROT_READ|PROT_EXEC, MAP_PRIVATE, mfd, 0);
    .c code

src/amd64-linux.shlib-init.S:        addq src,lsrc; push lsrc  // &input_eof
    restoring 'subq' is already next

src/arch/amd64/lzma_d.S://      addq src,lsrc; push lsrc  // &input_eof
    comment that explains preceding actions in ELFMAINX; a restoring 'subq' is already next

src/i386-expand.S:    add src,%ecx; push %ecx  // MATCH_52  eof_src
    %ecx is dead

src/i386-linux.elf-so_entry.S:        add src,lsrc; push lsrc  // MATCH_05  &input_eof
    lsrc is dead for inlined nrv2b
2023-10-12 10:41:13 -07:00
John Reiser 0515be4334 LZMA on AMD64 had bug in calling sequence, leading to random exit(127)
LzmaDecode randomly decided that the input had ended in the middle,
because of error in interface between ELFMAINX and the decoder.

Thanks to Kevin Gosse!
https://github.com/upx/upx/pull/716
https://github.com/MichalStrehovsky/PublishAotCompressed/issues/11
2023-10-06 14:14:32 -07:00
Markus F.X.J. Oberhumer e32de83758 CI updates 2023-10-05 12:23:17 +02:00
Markus F.X.J. Oberhumer e767461f65 src: more clang-format 2023-10-05 11:53:02 +02:00
Markus F.X.J. Oberhumer 632c7c4826 all: assorted cleanups; introduce undocumented '--sysinfo' option 2023-10-05 03:51:27 +02:00
Markus F.X.J. Oberhumer 7f9d381c7b CI updates 2023-09-30 10:46:39 +02:00
Markus F.X.J. Oberhumer 4d5d6661d5 submodules: update for new versions 2023-09-30 09:44:58 +02:00
John Reiser b0b87eda02 check-whitespace
modified:   stub/src/upxfd_android.c
2023-09-28 12:49:14 -07:00
John Reiser f63a673a8b Prepare to emulate memfd_create() on 32-bit Android (ARM and i386)
modified:   stub/src/include/linux.h
	new file:   stub/src/upxfd_android.c
	new file:   stub/src/upxfd_create.c
2023-09-28 12:44:49 -07:00
John Reiser 290dd0c5d2 Git straggler
modified:   src/stub/tmp/i386-linux.elf-entry.bin.dump
2023-09-28 12:09:32 -07:00
John Reiser 194bf2b852 Common prototypes for mmap and ftruncate
modified:   src/stub/src/include/linux.h
	modified:   src/stub/src/amd64-linux.elf-so_main.c
	modified:   src/stub/src/i386-linux.elf-so_main.c
	modified:   src/stub/src/i386-linux.elf.execve-main.c
	modified:   src/stub/src/i386-linux.elf.interp-main.c
	modified:   src/stub/src/i386-linux.elf.shell-main.c
2023-09-28 12:07:04 -07:00
John Reiser d6d5e7ae3d For Android emulator: align i386 LEXEC020 binfo
modified:   src/stub/src/i386-linux.elf-entry.S
	modified:   src/p_lx_elf.cpp

	modified:   src/stub/i386-linux.elf-entry.h
	modified:   misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
2023-09-28 12:02:28 -07:00
Markus F.X.J. Oberhumer 39a6cc4b5f src: improve memory sanitizer handling 2023-09-26 15:15:55 +02:00
Markus F.X.J. Oberhumer a24de15060 submodules: update for new versions 2023-09-26 15:15:55 +02:00
Markus F.X.J. Oberhumer eb021accd1 CI updates 2023-09-25 13:47:43 +02:00
Markus F.X.J. Oberhumer 98a77dde00 CI updates 2023-09-22 17:33:22 +02:00
John Reiser 854988bc5f Detect AlreadyPacked even when trailing PackHeader has been lopped.
This is heuristic, but strong.
https://github.com/upx/upx/issues/712
	modified:   p_lx_elf.cpp
	modified:   p_unix.h
2023-09-21 14:12:18 -07:00
John Reiser bfeed2ab9a MAP_PRIVATE to capture memfd pages before closing the fd
https://github.com/upx/upx/issues/710

	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c

	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/i386-linux.elf-so_fold.h
2023-09-20 13:12:04 -07:00
Markus F.X.J. Oberhumer d11fc71e79 CI updates 2023-09-20 11:24:55 +02:00
Markus F.X.J. Oberhumer f1703fa322 CI updates 2023-09-19 11:47:15 +02:00
Markus F.X.J. Oberhumer 06675acc67 all: cosmetic cleanups 2023-09-18 15:19:37 +02:00
Markus F.X.J. Oberhumer 57ad6bc37d CI updates 2023-09-11 06:52:57 +02:00
dependabot[bot] 0192b0b7e4 build(deps): bump actions/checkout from 3 to 4 (#707)
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 18:54:02 +02:00
Markus F.X.J. Oberhumer 3b098b845a CI updates 2023-09-06 12:48:30 +02:00
Markus F.X.J. Oberhumer ac398f1ffe CI updates 2023-09-06 01:48:20 +02:00
Markus F.X.J. Oberhumer 92dfb9c83c testsuite: add file system test suite test_symlinks.sh 2023-09-06 00:09:44 +02:00
Markus F.X.J. Oberhumer 38d6cb090c src/packer.cpp: fix bug in constructor introduced during cleanup
Introduced in 10e759f1f1
2023-09-05 21:09:17 +02:00
Markus F.X.J. Oberhumer e93172bd33 src/work.cpp: clean up get_open_flags() 2023-09-05 06:09:13 +02:00
Markus F.X.J. Oberhumer 30fcca4b64 src: optimize preserve_link: only if the file has actual link-count >= 2 2023-09-05 05:50:47 +02:00
Markus F.X.J. Oberhumer 4f6320d3aa src: add new option --link to preserve hard links; use with care 2023-09-04 22:34:21 +02:00
Markus F.X.J. Oberhumer 62dbf8485f src: sort cleanups 2023-09-04 07:28:48 +02:00
John Reiser 9331ed39d4 32-bit Android lacks memfd_create, and has varying __NR_ftruncate
https://github.com/upx/upx/issues/700
	modified:   stub/src/i386-linux.elf-so_main.c
	modified:   stub/src/arm.v4a-linux.elf-so_entry.S
	modified:   stub/src/arm.v4a-linux.elf-so_fold.S

	modified:   stub/arm.v4a-linux.elf-so_entry.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_entry.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
2023-09-02 15:31:32 -07:00
Markus F.X.J. Oberhumer 35dd9cfd22 src: retract libc qsort() requirements 2023-09-02 16:15:57 +02:00
Markus F.X.J. Oberhumer 0ac6c36af2 src: add a check for libc qsort(); cleanups 2023-09-01 11:59:29 +02:00
Markus F.X.J. Oberhumer 3c4b959f78 all: update clang-format settings 2023-09-01 11:29:51 +02:00
Markus F.X.J. Oberhumer a00687b092 src/p_mach.cpp: make sort order deterministic 2023-09-01 11:11:00 +02:00
Markus F.X.J. Oberhumer bb6b087862 src: implement upx_shellsort() 2023-09-01 10:49:47 +02:00
John Reiser bfb438dc89 Sync stubs
modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/i386-linux.elf-so_fold.h
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-08-31 13:34:49 -07:00
John Reiser cd3f69c290 Explicit write() can subsume ftruncate()
modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c
2023-08-31 13:25:53 -07:00
Markus F.X.J. Oberhumer d54315392e src: add support for NO_COLOR environment variable 2023-08-31 12:31:31 +02:00
Markus F.X.J. Oberhumer cfa8107ab9 src: make sort order deterministic, next try
We cannot compare pointers as they may point to qsort-local objects.
And we must make sure that cmp(a,b) always agrees with cmp(b,a).
2023-08-30 16:41:59 +02:00
Markus F.X.J. Oberhumer f4e5b29708 src: make sort order deterministic 2023-08-28 02:08:34 +02:00
Markus F.X.J. Oberhumer d65fea1147 src/bele.h: try to detect possible size-mismatches 2023-08-28 00:23:53 +02:00
Markus F.X.J. Oberhumer 25a3c109c1 CI updates 2023-08-27 13:30:51 +02:00
John Reiser b526eed346 Detect "no Shdrs" earlier when already packed
https://github.com/upx/upx/issues/699
	modified:   p_lx_elf.cpp
2023-08-23 19:52:35 +02:00
John Reiser 59c6a71b72 More use of ph_forced_method()
modified:   p_lx_elf.cpp
2023-08-23 19:52:35 +02:00
John Reiser c7a2a0faa1 Document path to mach-o/loader.h on Apple CommandLineTools
modified:   p_mach_enum.h
2023-08-23 19:52:35 +02:00
John Reiser bfb5ea50a9 Temporary
modified:   p_lx_elf.cpp
2023-08-23 19:52:35 +02:00
John Reiser 149d84edca --brute versus forced_method(ph.method)
https://github.com/upx/upx/issues/694  (partial)
	modified:   p_lx_elf.cpp
2023-08-23 19:52:35 +02:00
Markus F.X.J. Oberhumer 7636abc158 CI updates 2023-08-22 11:12:48 +02:00
Markus F.X.J. Oberhumer 6eace187e7 src: add a famous quote 2023-08-22 00:37:45 +02:00
Markus F.X.J. Oberhumer dd1838a7eb src: minor cleanups 2023-08-21 22:41:42 +02:00
Markus F.X.J. Oberhumer dd928cf956 src: update MemBuffer::getSizeForCompression() 2023-08-21 22:32:28 +02:00
Markus F.X.J. Oberhumer 38be230467 submodules: update for new versions 2023-08-21 22:28:25 +02:00
Markus F.X.J. Oberhumer 1f747a28a9 all: spell check 2023-08-17 12:55:38 +02:00
Markus F.X.J. Oberhumer 1a7732b285 CI update: add ASAN/MSAN/valgrind checks 2023-08-17 12:07:19 +02:00
Markus F.X.J. Oberhumer f8ea416a4d src/pefile.cpp: fix a pedantic ASAN error 2023-08-17 00:08:03 +02:00
Markus F.X.J. Oberhumer b9bf81d548 src/p_lx_elf.cpp: init o_binfo to avoid crash with MSAN build
This should be double-checked by @jreiser
2023-08-16 22:23:28 +02:00
Markus F.X.J. Oberhumer 8975e2a6b5 src: create util/cxxlib.h 2023-08-16 10:05:59 +02:00
Markus F.X.J. Oberhumer 394cd77bec all: cleanups 2023-08-16 01:06:52 +02:00
Markus F.X.J. Oberhumer a9ac4b5e23 src: introduce type tribool 2023-08-15 14:44:50 +02:00
Markus F.X.J. Oberhumer 10e759f1f1 src: minor cleanups 2023-08-11 13:32:53 +02:00
Markus F.X.J. Oberhumer 777d4f5279 src: refactoring: create packhead.h and move some methods 2023-08-11 03:57:20 +02:00
Markus F.X.J. Oberhumer c65c882ecc src: class Packer decomposition, introduce PackerBase 2023-08-10 20:40:27 +02:00
Markus F.X.J. Oberhumer a66ee9fafd CI update 2023-08-09 21:08:04 +02:00
Markus F.X.J. Oberhumer 757401dd0c CI and spell checks 2023-08-09 13:08:38 +02:00
Markus F.X.J. Oberhumer 11e3770864 CI updates 2023-08-08 15:57:45 +02:00
Markus F.X.J. Oberhumer fbb317e9c8 submodules: update for new versions 2023-08-08 12:54:11 +02:00
Markus F.X.J. Oberhumer 9d7698a359 testsuite: update checksums caused by version bump 2023-08-08 12:46:17 +02:00
Markus F.X.J. Oberhumer 44fd11f4dd all: post-release version bump 2023-08-08 12:43:47 +02:00
Markus F.X.J. Oberhumer 8779113131 all: prepare for release 2023-08-08 10:38:12 +02:00
Markus F.X.J. Oberhumer 26cfd0a616 all: minor cleanups 2023-08-08 10:34:12 +02:00
John Reiser 75e153dd99 More care in ::forward_Shdrs() and ::pack4()
Also, de-compressing arm64 shlib restores .init_array[0],
although supposedly *_RELATIVE relocation should overwrite.

https://github.com/upx/upx/issues/693
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2023-08-04 11:52:58 -07:00
Markus F.X.J. Oberhumer fa364d6ea3 all: final cleanups in preparation for release 2023-08-03 14:20:35 +02:00
Markus F.X.J. Oberhumer 13e5c13695 Fix functional change in commit 905bfacf44 2023-08-02 17:45:17 +02:00
John Reiser 43b3b54197 spell check typos
modified:   p_lx_exc.cpp
	modified:   p_mach.cpp
	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c
	modified:   stub/src/arch/mips/r3000/bits.ash
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm.v4a-linux.shlib-init.S
	modified:   stub/src/arm64-linux.shlib-init.S
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/mipsel.r3000-linux.elf-entry.S
2023-07-31 09:05:32 -07:00
John Reiser 3a16d4a12e Spell check; No-Functional-Change
modified:   p_lx_elf.cpp
2023-07-31 06:06:31 -07:00
Markus F.X.J. Oberhumer 50fc9235de misc: update podman test-qemu 2023-08-01 07:24:10 +02:00
Markus F.X.J. Oberhumer 70287d3c49 clang-tidy 2023-07-31 14:49:48 +02:00
John Reiser 41e9f7985f forward_Shdrs: elfout for main, lowmem for shlib
Especially Android.
https://github.com/upx/upx/issues/680
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2023-07-29 13:43:33 -07:00
John Reiser c3327977da Pwrite:
modified:   stub/src/amd64-linux.elf-so_fold.S

	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-07-29 13:42:20 -07:00
John Reiser 905bfacf44 Pacify clang-tidy 2023-07-26 17:21:39 -07:00
Markus F.X.J. Oberhumer 053e95033f all: improve C++ static analyzers 2023-07-26 22:28:47 +02:00
Markus F.X.J. Oberhumer 5a1203be0d submodules: update for new versions 2023-07-26 18:13:25 +02:00
John Reiser 745fef7425 fpad4, fpad8, and _Shdr hacking should guard against (!fo)
Also pacify some clang scan-build complaints.
	modified:   p_lx_elf.cpp
2023-07-26 07:27:12 -07:00
John Reiser c9d625a237 Use 'elfout' for changing ElfXX_Ehdr
https://github.com/upx/upx/issues/688
	modified:   p_lx_elf.cpp
2023-07-26 07:15:22 +02:00
John Reiser 334731f56b Sync stubs for powerpc64le-linux.elf/upx-3.95
How did this mismatch happen?
	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
	modified:   stub/arm64-linux.elf-so_entry.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
2023-07-26 07:15:22 +02:00
John Reiser d5e7672a45 De-activate "bkpt" at entry
modified:   arm64-linux.elf-so_entry.S
2023-07-26 07:15:22 +02:00
Markus F.X.J. Oberhumer e702aa0252 Review 2023-07-26 07:15:22 +02:00
John Reiser 2684e815e0 Fix use of memfd_create for shlib stubs, espcially Android
Also relocation of init_array[0] for Elf32 shlib.
        https://github.com/upx/upx/issues/220
        https://github.com/upx/upx/issues/609
        https://github.com/upx/upx/issues/680

	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c
	modified:   p_lx_elf.cpp

	modified:   stub/src/arm.v4a-linux.elf-so_fold.S
	modified:   stub/src/arm64-linux.elf-so_entry.S
	modified:   stub/src/arm64-linux.elf-so_fold.S
	modified:   stub/src/i386-linux.elf-so_fold.S

	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_entry.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/i386-linux.elf-so_fold.h
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-07-26 07:15:22 +02:00
John Reiser efbc93229a Un-debug amd64-linux.elf-so_main.c
modified:   stub/src/amd64-linux.elf-so_main.c

	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-07-26 07:15:22 +02:00
John Reiser 05539ad5b6 Fix stubs for shlib with only 2 PT_LOAD 2023-07-26 07:15:22 +02:00
John Reiser 670aae2e11 Check /proc/self/auxv exists
modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c

	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-07-26 07:15:22 +02:00
John Reiser e6ff68dc2c Turn on DEBUG for 64-bit shlib
modified:   src/stub/src/amd64-linux.elf-so_main.c

	modified:   src/stub/amd64-linux.elf-so_fold.h
	modified:   src/stub/arm64-linux.elf-so_fold.h
	modified:   src/stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-07-26 07:15:22 +02:00
Markus F.X.J. Oberhumer 641b116f04 Update .gitattributes. 2023-07-25 12:18:33 +02:00
Markus F.X.J. Oberhumer f81f7194ed submodules: update for new versions 2023-07-25 12:05:14 +02:00
Markus F.X.J. Oberhumer 161d20e614 CI: update 2023-07-24 14:47:32 +02:00
Markus F.X.J. Oberhumer fc4dcd46db CI and build updates 2023-07-22 16:12:13 +02:00
Markus F.X.J. Oberhumer 891dc87064 misc: upx_testsuite; move podman directories into subdirectory 2023-07-22 00:19:11 +02:00
Markus F.X.J. Oberhumer b866631448 misc: improve upx_testsuite; cmake update 2023-07-19 20:12:20 +02:00
John Reiser 672d69c68a Fix unpacking of upx-3.94-armeb_linux/upx
Getting past the code of the stub must deal with variances
between released versions.
	modified:   p_lx_elf.cpp
2023-07-18 16:56:39 -07:00
Markus F.X.J. Oberhumer 507c31ec14 CI and cmake updates 2023-07-18 07:21:51 +02:00
John Reiser 65cc40bdda Align escape hatch in powerpc64 main program
modified:   stub/src/amd64-linux.elf-main.c
	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh

	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/tmp/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2023-07-17 15:58:01 -07:00
John Reiser 067895fa5f Fix brk+munmap in folded stubs for main programs
qemu emulating a compressed ET_EXEC revealed an access to ElfXX_Phdr
on the discarded side of brk() during cleanup. qemu was more aggressive
than the Linux kernel implementation of brk().
        https://github.com/upx/upx/issues/683

	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/include/linux.h

	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh

	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S

	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/armeb.v4a-linux.elf-fold.h
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/mips.r3000-linux.elf-fold.h
	modified:   stub/mipsel.r3000-linux.elf-fold.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h

	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   stub/tmp/arm.v4a-linux.elf-fold.map
	modified:   stub/tmp/arm.v5a-linux.elf-fold.map
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/armeb.v4a-linux.elf-fold.map
	modified:   stub/tmp/i386-linux.elf-fold.map
	modified:   stub/tmp/mips.r3000-linux.elf-fold.map
	modified:   stub/tmp/mipsel.r3000-linux.elf-fold.map
	modified:   stub/tmp/powerpc-linux.elf-fold.map
	modified:   stub/tmp/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2023-07-17 07:21:56 +02:00
Markus F.X.J. Oberhumer 3f7f26c74b CI: update 2023-07-16 21:28:26 +02:00
Markus F.X.J. Oberhumer 9a6b5940cf CI: update 2023-07-16 15:14:19 +02:00
Markus F.X.J. Oberhumer 828f4a63bf src: add some "explicit"; cleanups 2023-07-16 07:37:31 +02:00
John Reiser 707fb55625 A fuzzer attacked i386-dos32.watcom.le 2023-07-06 20:25:14 -07:00
Markus F.X.J. Oberhumer 8d41ae09c8 all: misc updates 2023-07-12 18:59:08 +02:00
Markus F.X.J. Oberhumer 7ec0faca1e all: misc and noexcept updates 2023-07-09 17:36:24 +02:00
Markus F.X.J. Oberhumer 300fa29446 CI: update 2023-07-08 21:28:29 +02:00
Markus F.X.J. Oberhumer 6981f7b3ae misc: add misc/test-qemu-with-podman 2023-07-08 18:14:41 +02:00
Markus F.X.J. Oberhumer 682a1e97e4 src: add assert_noexcept() 2023-07-08 12:06:27 +02:00
Markus F.X.J. Oberhumer 1d71dd3851 all: clang-tidy updates 2023-07-08 10:51:02 +02:00
Markus F.X.J. Oberhumer 5edfda46e5 all: clang-tidy updates 2023-07-08 09:59:41 +02:00
Markus F.X.J. Oberhumer d7754a97c7 all: add support for clang-tidy 2023-07-07 23:13:08 +02:00
Markus F.X.J. Oberhumer c79aa6ad8a all: cosmetic updates 2023-07-06 18:03:37 +02:00
Markus F.X.J. Oberhumer 525e091472 src/console: disable win32 screen driver when running under Wine 2023-07-06 10:09:38 +02:00
Markus F.X.J. Oberhumer 16f6de677d misc: podman updates 2023-07-06 10:09:38 +02:00
John Reiser 12c36bab6c Linux EINVAL for zero-length mmap: mmap(, 0, ,,,)
https://github.com/upx/upx/issues/681
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-main.c

	modified:   stub/src/i386-bsd.elf-main.c
	modified:   stub/src/i386-openbsd.elf-main.c

	modified:   ../misc/testsuite/upx_testsuite_1-expected_sha256sums.sh

	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/i386-bsd.elf-fold.h
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/i386-netbsd.elf-fold.h
	modified:   stub/i386-openbsd.elf-fold.h
	modified:   stub/mips.r3000-linux.elf-fold.h
	modified:   stub/mipsel.r3000-linux.elf-fold.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/i386-bsd.elf-fold.map
	modified:   stub/tmp/i386-linux.elf-fold.map
	modified:   stub/tmp/i386-netbsd.elf-fold.map
	modified:   stub/tmp/i386-openbsd.elf-fold.map
	modified:   stub/tmp/mips.r3000-linux.elf-fold.map
	modified:   stub/tmp/mipsel.r3000-linux.elf-fold.map
	modified:   stub/tmp/powerpc-linux.elf-fold.map
	modified:   stub/tmp/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2023-07-06 10:09:07 +02:00
John Reiser c429859cbf Placate Android dlopen() some more.
https://github.com/upx/upx/issues/680
	modified:   p_lx_elf.cpp
2023-07-06 10:08:41 +02:00
John Reiser dc76b2af97 info(Android_penalty)
modified:   p_lx_elf.cpp
2023-06-26 09:09:47 -07:00
Markus F.X.J. Oberhumer b75e7687f4 all: CI and misc updates 2023-06-30 01:20:48 +02:00
Markus F.X.J. Oberhumer ece5af2895 CI: make sure that directories which contain whitespace do work 2023-06-28 18:18:36 +02:00
Markus F.X.J. Oberhumer 1aaa33552e all: move testsuite to misc/testsuite; CI updates 2023-06-27 14:27:19 +02:00
Markus F.X.J. Oberhumer f622871eb0 src: fix building under freebsd; updates 2023-06-27 12:59:24 +02:00
Markus F.X.J. Oberhumer 060b01260d CI: yet more updates 2023-06-25 19:40:09 +02:00
Markus F.X.J. Oberhumer 871f8a4793 src: new ACC version 2023-06-25 14:30:00 +02:00
Markus F.X.J. Oberhumer c54e03d0f2 CI: ongoing cleanups 2023-06-25 03:27:51 +02:00
Markus F.X.J. Oberhumer aaf3f75990 CI and cmake updates 2023-06-25 01:55:06 +02:00
Markus F.X.J. Oberhumer 512a26cee4 CI: update 2023-06-24 10:16:43 +02:00
John Reiser b4a793ed26 Make ::forward_Shdrs more friendly to Android dlopen()
https://github.com/upx/upx/issues/220
https://github.com/upx/upx/issues/609
2023-06-22 10:16:25 -07:00
Markus F.X.J. Oberhumer 5d2c74008e all: cmake and noexcept updates 2023-06-23 14:13:08 +02:00
Markus F.X.J. Oberhumer 7fafc68940 CI: update 2023-06-19 14:28:12 +02:00
Markus F.X.J. Oberhumer d1af2af499 all: yet more misc updates 2023-06-15 19:42:54 +02:00
Markus F.X.J. Oberhumer a5206eb696 CI: cleanups 2023-06-14 07:40:14 +02:00
Markus F.X.J. Oberhumer 1ff0d137ab all: misc updates 2023-06-13 16:42:14 +02:00
John Reiser 07aa65b55e Sync stubs
Dependency processing does not propagate this one:
src/stub/src/arm.v5a-darwin.macho-main.c:
   #include "amd64-darwin.macho-main.c"
	modified:   arm.v5a-darwin.macho-fold.h
	modified:   tmp/arm.v5a-darwin.macho-fold.map
2023-06-13 16:29:13 +02:00
John Reiser 0fadddec65 Force 'bkpt' on arm.v5a and below
fixup  https://github.com/upx/upx/issues/612
	modified:   stub/src/amd64-darwin.macho-main.c
2023-06-13 16:29:13 +02:00
John Reiser 1bebe53cef Allow more bytes for Mach_headers in /usr/lib/dyld on MacOS 13
Fixes initial complaint (HelloUPX4) in https://github.com/upx/upx/issues/612
	modified:   stub/amd64-darwin.macho-fold.h
	modified:   stub/arm64-darwin.macho-fold.h
	modified:   stub/src/amd64-darwin.macho-fold.S
	modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/tmp/amd64-darwin.macho-fold.map
	modified:   stub/tmp/arm64-darwin.macho-fold.map
2023-06-13 16:29:13 +02:00
John Reiser 43019c744c Document requirement for 'homebrew' when developing on MacOS
... else testsuite fails for "readlink -en" and 'sha256sum'
https://github.com/upx/upx/issues/676
	modified:   README.SRC
2023-06-13 16:29:13 +02:00
Markus F.X.J. Oberhumer c585774162 CI: disable self-test on macos-13 2023-06-10 11:02:19 +02:00
Markus F.X.J. Oberhumer 75e87a58da src: rework mem_clear() 2023-06-09 18:20:06 +02:00
Markus F.X.J. Oberhumer 19e84fea62 all: yet more minor updates 2023-06-09 14:12:05 +02:00
Markus F.X.J. Oberhumer db39f9c4dc all: CI and misc updates 2023-06-06 23:16:28 +02:00
Markus F.X.J. Oberhumer dae45ae0d4 all: bump version; cleanups 2023-05-28 14:06:11 +02:00
Markus F.X.J. Oberhumer efeffc6e01 submodules: update for new versions 2023-05-28 13:58:27 +02:00
Markus F.X.J. Oberhumer ebf0f2f68a all: more minor cleanups 2023-05-27 22:58:07 +02:00
Markus F.X.J. Oberhumer 09bd1d8c40 all: misc updates 2023-05-19 13:21:26 +02:00
Markus F.X.J. Oberhumer 40653e40a4 all: minor cleanups 2023-05-14 09:36:10 +02:00
Markus F.X.J. Oberhumer b3e4efbabe all: misc updates 2023-05-13 16:28:44 +02:00
John Reiser 279101d464 Fix checksum of non-compressible extents
https://github.com/upx/upx/issues/673
	modified:   src/p_unix.cpp
2023-05-13 16:28:22 +02:00
Markus F.X.J. Oberhumer f571feee72 CI: use gcc -static for macos builds 2023-05-10 20:42:26 +02:00
Markus F.X.J. Oberhumer 900afd1c8c all: minor updates 2023-05-10 20:20:39 +02:00
Markus F.X.J. Oberhumer 08a72d5251 Fix whitespace. 2023-05-10 20:19:22 +02:00
John Reiser 736a6cd955 Catch amd64 ET_EXEC with .e_entry < 0x400000
https://github.com/upx/upx/issues/673
	modified:   p_lx_elf.cpp
2023-05-10 20:17:22 +02:00
John Reiser 75ce5e5df3 Fix SIGSEGV due to name confusion in ::forward_Shdrs
https://github.com/upx/upx/issues/671
	modified:   p_lx_elf.cpp
2023-05-10 20:17:22 +02:00
Markus F.X.J. Oberhumer eaf2143162 CI: add macos-13 2023-05-03 10:06:22 +02:00
Markus F.X.J. Oberhumer f0bdb8dea1 submodules: update for new versions 2023-05-03 09:49:20 +02:00
John Reiser 60093cfff6 Merge branch 'devel4' of https://github.com/upx/upx into devel4 2023-04-30 15:19:44 -07:00
John Reiser 56bb7b53cb Synch *.h stub headers and testcase checksums
Shared libraries for amd64, i386, arm64, and arm should be
compatible with SELinux: no complaints of execmod or execmem.

https://github.com/upx/upx/issues/609
https://github.com/upx/upx/issues/220
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
	modified:   stub/amd64-linux.elf-so_entry.h
	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-so_entry.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-entry.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-so_entry.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_entry.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/i386-linux.elf-so_entry.h
	modified:   stub/i386-linux.elf-so_fold.h
	modified:   stub/tmp/amd64-linux.elf-so_entry.bin.dump
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
	modified:   stub/tmp/arm.v5a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v5a-linux.elf-fold.map
2023-04-30 15:12:29 -07:00
John Reiser 0cffeca102 arm32 shlib works with SELinux
modified:   stub/src/arch/arm/v4a/macros.S
	modified:   stub/src/arm.v4a-linux.elf-so_entry.S
	modified:   stub/src/arm.v4a-linux.elf-so_fold.S
	modified:   stub/src/arm64-linux.elf-so_entry.S
	modified:   stub/src/i386-linux.elf-so_main.c
2023-04-28 13:52:26 -07:00
John Reiser 937d4462ca SELinux for i386 shlib stub
modified:   stub/src/i386-linux.elf-so_entry.S
	modified:   stub/src/i386-linux.elf-so_fold.S
	modified:   stub/src/i386-linux.elf-so_main.c
	modified:   stub/src/include/linux.h
2023-04-27 18:49:35 -07:00
John Reiser db5a39572c Change stub for arm64 shlib to work with SELinux
modified:   stub/src/arm64-linux.elf-so_entry.S
	modified:   stub/src/arm64-linux.elf-so_fold.S
2023-04-27 10:44:13 -07:00
John Reiser ecc9c67e1f Check return value from syscalls; leave debugging hint if error
modified:   stub/src/amd64-linux.elf-so_entry.S
2023-04-27 10:42:56 -07:00
John Reiser 0901ce1b68 amd64-linux.elf shlib now fully-SELinux compliant
modified:   stub/src/amd64-linux.elf-so_entry.S
	modified:   stub/src/amd64-linux.elf-so_fold.S
2023-04-26 13:06:48 -07:00
John Reiser be6e77379a SELinux forces memfd_create for .so on amd64, arm64
More coming for .so: so_entry.S, powerpc64, 32-bit
	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/arm64-linux.elf-so_entry.S
	modified:   stub/src/arm64-linux.elf-so_fold.S
2023-04-26 08:30:55 -07:00
Markus F.X.J. Oberhumer 726f5de778 src: minor cleanups 2023-04-26 08:13:32 +02:00
John Reiser 98b835e0a7 WIP: SELinux is expensive: +2KB in stub
Needs make_hatch()
	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/amd64-linux.elf-so_fold.S

	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/src/arm.v4a-linux.elf-so_fold.S
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-04-24 19:40:57 -07:00
John Reiser 04ffb641a6 Compilers generate junk .sh_info
modified:   p_lx_elf.cpp
2023-04-24 19:37:25 -07:00
John Reiser 1b7233b673 whitespace
modified:   stub/src/amd64-expand.S
2023-04-24 19:35:52 -07:00
John Reiser eaa0f33473 Fix call to unfilter from amd64-expand
modified:   stub/src/amd64-expand.S

	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-04-21 08:57:10 -07:00
Markus F.X.J. Oberhumer c03b382d61 src: some more "noexcept" 2023-04-20 20:58:19 +02:00
Markus F.X.J. Oberhumer e633694255 cmake: use MSVC_FRONTEND 2023-04-20 20:10:12 +02:00
Markus F.X.J. Oberhumer 278b25bad2 cmake: check CMAKE_C_COMPILER_FRONTEND_VARIANT 2023-04-20 14:54:14 +02:00
Markus F.X.J. Oberhumer f89f0838dc src: change UPX_CONFIG logic to permissive defaults 2023-04-20 14:13:36 +02:00
Markus F.X.J. Oberhumer b1729e3bcf src: cleanup MAX_ELF_HDR 2023-04-19 23:23:46 +02:00
Markus F.X.J. Oberhumer d1ab85a1a6 src: cleanup linker.h 2023-04-19 23:19:45 +02:00
John Reiser 7f5b64c91a Merge branch 'devel4' of https://github.com/upx/upx into devel4 2023-04-19 14:00:43 -07:00
John Reiser 78b68283c4 Fix .e_entry for PowerPC64
https://github.com/upx/upx/issues/668
	modified:   p_lx_elf.cpp
2023-04-19 13:58:52 -07:00
Markus F.X.J. Oberhumer 9e3b1c9f8a src: enable TE checks in packer.h; add some "noexcept" 2023-04-18 17:56:28 +02:00
Markus F.X.J. Oberhumer 5dc54c7adc Merge branch 'devel' into devel4 2023-04-18 17:15:57 +02:00
Markus F.X.J. Oberhumer 320e5b850f all: yet more cleanups
Changes include:
  - use standard names for PE constants
  - add some more "noexcept"
  - improve upx_is_integral type-trait
  - introduce is_same_all and is_same_any type-traits
  - prepare TE-size checks in packer.h
  - CI updates
2023-04-18 17:02:13 +02:00
John Reiser d8395d8c42 Fix usage of _te32/_te64/_te16 for Elf classes
How did it ever work?  UPX_RSIZE_MAX_MEM of 768MiB, Elf32_Off of only
32-bits, and preponderance of little-endian and small positive integers
hides many mis-uses of _te64/_te32.
ELF does not help: e_phnum, e_shnum, Elf32_Section, Elf64_Section are all
16-bit, but sh_info and sh_link are 32-bit.
Templatizing p_elf.h (following the example of p_mach.h) failed
because of complexity.  (Plus too many special cases of ELF where 32-bit
and 64-bit are not parallel.)
	modified:   p_lx_elf.cpp
	modified:   p_lx_sh.cpp
	modified:   p_mach.cpp
2023-04-17 13:19:06 -07:00
John Reiser a20c5a1e7f Align 64-bit forward_Shdr
//github.com/upx/upx/issues/220
	modified:   p_lx_elf.cpp
2023-04-12 14:54:49 -07:00
John Reiser 3bdfcaa541 Try to placate Android crapware, which cannot deal with null strings
From https://github.com/upx/upx/issues/220 :

Phone:
04-10 16:07:52.862 E/AndroidRuntime( 5178): java.lang.UnsatisfiedLinkError: dlopen failed: \
"/data/app/~~Nwb-iR6LHpHyrT37xe8HNg==/com.android.support-y0YbcwLn1b4sBRD09JGVAw==/lib/arm64/libMyLibName.so" \
has unsupported e_shentsize: 0x0 (expected 0x40)

Emulator:
04-10 09:57:38.746 E/AndroidRuntime( 6403): java.lang.UnsatisfiedLinkError: dlopen failed: \
"/data/app/~~sBBMDvh36TxwO4muxOJ3Bg==/com.android.support-8Lc6r2dLzTIW7SEHXLI0XQ==/lib/arm64/libMyLibName.so" \
has no section headers

	modified:   p_lx_elf.cpp
2023-04-11 13:41:54 -07:00
John Reiser 7b2faf2016 Elf64_Rela for shlib DT_INIT_ARRAY
Also allow PT_PHDR in shlibs.
Also page align lo end of mmap, like mprotect.
        https://github.com/upx/upx/issues/664
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c

	modified:   stub/src/amd64-linux.elf-so_fold.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm.v4a-linux.elf-so_fold.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-so_fold.S
	modified:   stub/src/i386-linux.elf-so_fold.S

	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/armeb.v4a-linux.elf-fold.h
	modified:   stub/i386-linux.elf-so_fold.h

	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
	modified:   stub/tmp/arm.v4a-linux.elf-fold.map
	modified:   stub/tmp/arm.v5a-linux.elf-fold.map
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/armeb.v4a-linux.elf-fold.map

	modified:   stub/src/arch/mips/r3000/macros.ash
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
2023-04-11 11:00:48 -07:00
John Reiser 42902dabac 64-bit shlib with DT_INIT_ARRAY but no DT_INIT
https://github.com/upx/upx/issues/664
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2023-04-10 18:01:39 -07:00
John Reiser 14521eb6dd Allow pre-linking when compressing shared libraries
Such as Wine kernel32.dll etc.
https://github.com/upx/upx/issues/660
	modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/i386-linux.elf-so_fold.h
	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-04-03 13:18:21 -07:00
John Reiser b9533f409c Sync testsuite checksums
modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
2023-03-29 16:11:08 -07:00
John Reiser 4df68aafd2 Pprotect: mprotect but enlarge the interval to start on page boundary
https://github.com/upx/upx/issues/609
	modified:   src/stub/src/amd64-linux.elf-fold.S
	modified:   src/stub/src/amd64-linux.elf-main.c
	modified:   src/stub/src/amd64-linux.elf-so_fold.S
	modified:   src/stub/src/amd64-linux.elf-so_main.c
	modified:   src/stub/src/arm.v4a-linux.elf-fold.S
	modified:   src/stub/src/arm.v4a-linux.elf-so_fold.S
	modified:   src/stub/src/arm64-linux.elf-fold.S
	modified:   src/stub/src/arm64-linux.elf-so_fold.S
	modified:   src/stub/src/i386-linux.elf-fold.S
	modified:   src/stub/src/i386-linux.elf-main.c
	modified:   src/stub/src/i386-linux.elf-so_fold.S
	modified:   src/stub/src/i386-linux.elf-so_main.c
	modified:   src/stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   src/stub/src/powerpc-linux.elf-fold.S
	modified:   src/stub/src/powerpc64le-linux.elf-fold.S

	modified:   src/stub/amd64-linux.elf-fold.h
	modified:   src/stub/amd64-linux.elf-so_fold.h
	modified:   src/stub/arm.v4a-linux.elf-fold.h
	modified:   src/stub/arm.v4a-linux.elf-so_fold.h
	modified:   src/stub/arm.v5a-linux.elf-fold.h
	modified:   src/stub/arm.v5a-linux.elf-so_fold.h
	modified:   src/stub/arm64-linux.elf-fold.h
	modified:   src/stub/arm64-linux.elf-so_fold.h
	modified:   src/stub/armeb.v4a-linux.elf-fold.h
	modified:   src/stub/i386-linux.elf-fold.h
	modified:   src/stub/i386-linux.elf-so_fold.h
	modified:   src/stub/mips.r3000-linux.elf-fold.h
	modified:   src/stub/mipsel.r3000-linux.elf-fold.h
	modified:   src/stub/powerpc-linux.elf-fold.h
	modified:   src/stub/powerpc64-linux.elf-fold.h
	modified:   src/stub/powerpc64le-linux.elf-fold.h

	modified:   src/stub/tmp/amd64-linux.elf-fold.map
	modified:   src/stub/tmp/amd64-linux.elf-so_fold.bin.dump
	modified:   src/stub/tmp/arm.v4a-linux.elf-fold.map
	modified:   src/stub/tmp/arm.v5a-linux.elf-fold.map
	modified:   src/stub/tmp/arm64-linux.elf-fold.map
	modified:   src/stub/tmp/armeb.v4a-linux.elf-fold.map
	modified:   src/stub/tmp/i386-linux.elf-fold.map
	modified:   src/stub/tmp/mips.r3000-linux.elf-fold.map
	modified:   src/stub/tmp/mipsel.r3000-linux.elf-fold.map
	modified:   src/stub/tmp/powerpc-linux.elf-fold.map
	modified:   src/stub/tmp/powerpc64-linux.elf-fold.map
	modified:   src/stub/tmp/powerpc64le-linux.elf-fold.map
2023-03-29 15:46:58 -07:00
John Reiser c72ceaa979 MSVC
modified:   p_lx_elf.cpp
2023-03-26 11:29:19 -07:00
John Reiser 8ac79ca0ad whitespce
modified:   p_lx_elf.cpp
2023-03-26 11:16:36 -07:00
John Reiser e0bfaf1028 Merge branch 'devel4' of https://github.com/upx/upx into devel4 2023-03-26 11:06:22 -07:00
John Reiser b361b91ec7 Try to appease Android runtime loader; _Shdr vs _Phdr offsets
JNI FalalError called: Unable to load library:
    [dlopen failed: "/lib/arm/libunity.so"
    .dynamic section has invalid offset: 0x6d3e58,
    expected to match PT_DYNAMIC offset: 0x441e58]
https://github.com/upx/upx/issues/609
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2023-03-26 10:53:30 -07:00
John Reiser b5d1eba4c1 mprotect() requires page-aligned address
modified:   stub/amd64-linux.elf-so_fold.h
	modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/arm64-linux.elf-so_fold.h
	modified:   stub/i386-linux.elf-so_fold.h
	modified:   stub/src/amd64-linux.elf-so_fold.S
	modified:   stub/src/arm.v4a-linux.elf-so_entry.S
	modified:   stub/src/arm.v4a-linux.elf-so_fold.S
	modified:   stub/src/arm64-linux.elf-so_fold.S
	modified:   stub/src/i386-linux.elf-so_fold.S
	modified:   stub/tmp/amd64-linux.elf-so_fold.bin.dump
2023-03-26 07:26:53 -07:00
John Reiser ba447344d6 New strategy for de-compression stub for shared libraries
modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf-so_main.c
2023-03-26 07:25:32 -07:00
John Reiser 7b68aa7bdc Fix de-comression of shared libraries
modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2023-03-26 07:23:08 -07:00
John Reiser 5d15e57294 De-compression for 32-bit shared libraries on i686, ARM
https://github.com/upx/upx/issues/609
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2023-03-23 16:29:25 -07:00
John Reiser 0bf8ff151e Un-debug stubs for 32-bit shared libraries
modified:   stub/arm.v4a-linux.elf-so_fold.h
	modified:   stub/arm.v5a-linux.elf-so_fold.h
	modified:   stub/i386-linux.elf-so_fold.h
	modified:   stub/src/arm.v4a-linux.elf-so_entry.S
2023-03-23 16:27:44 -07:00
John Reiser 06fae05910 32-bit ARM Android shlib: DT_INIT_ARRAY without DT_INIT
De-compressor needs to catch up.
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   stub/src/i386-linux.elf-so_main.c
2023-03-22 10:44:17 -07:00
Markus F.X.J. Oberhumer f68ac8155b Merge branch 'devel' into devel4 2023-03-18 21:52:17 +01:00
Markus F.X.J. Oberhumer 15484aa296 all: more cleanups
Changes include:
  - extract headers.h from conf.h
  - use "byte" in some more places
  - unify "const" coding style
  - pefile.cpp: make sort order deterministic
  - simplify some other pefile.cpp code
  - CI updates
2023-03-18 21:27:34 +01:00
John Reiser 5b113a5041 Merge branch 'devel4' of https://github.com/upx/upx into devel4 2023-03-16 08:51:29 -07:00
John Reiser 1320e3efdb PackLinuxElf32::canPackOSABI() isolates canPack() from OSABI weirdness
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2023-03-16 08:30:06 -07:00
Markus F.X.J. Oberhumer d32f447bda Merge branch 'devel' into devel4 2023-03-15 22:34:05 +01:00
John Reiser b74c4e4ac1 Picky, picky static analyzer
https://github.com/upx/upx/actions/runs/4422867763/jobs/7755057541
	modified:   p_lx_elf.cpp
2023-03-15 09:05:02 -07:00
John Reiser 35333403ef Zero ElfXX_Ehdr.e_sh* info when removing ElfXX_Shdr
The aim is less confusion by static linkers: the _Shdr are gone!
https://github.com/upx/upx/issues/659
	modified:   p_lx_elf.cpp
2023-03-15 08:44:59 -07:00
Markus F.X.J. Oberhumer a627648249 all: assorted cleanups and updates
Changes include:
  - add a bunch of "noexcept", mostly to operators and forceinline
  - use "uchar"
  - use "charptr"
  - rename options_t to Options
  - add ptr_check_no_overlap()
  - rewrite p_exe.cpp, NFCI
  - clang-format help.cpp
  - spelling fixes
2023-03-15 00:19:55 +01:00
Markus F.X.J. Oberhumer 127fd095e7 CI: add spell-check.yml 2023-03-11 03:11:19 +01:00
John Reiser f8934c09ff F*ck MSVC
warning C4245: 'return': conversion from 'int' to 'unsigned int', signed/unsigned mismatch
    return ~0;  // in function declared as returning 'unsigned'.  The bits are the same!
	modified:   p_lx_elf.cpp
2023-03-09 12:00:56 -08:00
John Reiser 7a09c88e30 CI convention sucks
renamed:    MAX_ELF_HDR.cpp -> MAX_ELF_HDR.h
	modified:   p_lx_elf.cpp
2023-03-09 11:44:22 -08:00
John Reiser 17526d1132 Make it easier to change MAX_ELF_HDR consistently
https://github.com/upx/upx/issues/655

	new file:   MAX_ELF_HDR.cpp
	new file:   stub/src/MAX_ELF_HDR.S
	new file:   stub/src/MAX_ELF_HDR.c

	modified:   p_lx_elf.cpp
	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm.v4a-linux.elf-so_fold.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-so_fold.S
	modified:   stub/src/i386-bsd.elf-fold.S
	modified:   stub/src/i386-bsd.elf-main.c
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-so_main.c
	modified:   stub/src/i386-linux.elf.interp-fold.S
	modified:   stub/src/i386-linux.elf.interp-main.c
	modified:   stub/src/i386-linux.elf.shell-fold.S
	modified:   stub/src/i386-linux.elf.shell-main.c
	modified:   stub/src/i386-openbsd.elf-fold.S
	modified:   stub/src/i386-openbsd.elf-main.c
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
2023-03-09 10:06:13 -08:00
John Reiser ff7939c1c0 invert_pt_dynamic, sort_DTxx_offsets, elf_find_table_size
https://github.com/upx/upx/issues/655
        modified:   p_lx_elf.cpp
        modified:   p_lx_elf.h
2023-03-09 09:24:35 -08:00
John Reiser 96c196b1be Final ph.u_len and ph.c_len reflect multiple compressed extents
https://github.com/upx/upx/issues/655
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
	modified:   p_lx_elf.cpp
2023-03-09 09:06:06 -08:00
John Reiser adb0ca8250 Many changes for ELF shared libraries on Linux and Android
Handling more than 2 PT_LOAD (and thus more than 1 executable PT_LOAD)
required extensive changes.  But the bonus is the infrastructure
to support a different (de-)compression algorithm for each PT_LOAD.

https://github.com/upx/upx/issues/341   i386 .so decompression
https://github.com/upx/upx/issues/609   armv7 .so on Android
https://github.com/upx/upx/issues/625   amd64 .so execution
https://github.com/upx/upx/issues/654   armv7 .exe
Not yet: .so on MIPS, PowerPC, PowerPC64
2023-03-04 17:37:25 -08:00
Markus F.X.J. Oberhumer fa56a1d9cd submodules: update for new versions 2023-02-24 10:59:32 +01:00
Markus F.X.J. Oberhumer 3d691645a4 src: pefile: add checkMachine() 2023-02-21 20:33:40 +01:00
Markus F.X.J. Oberhumer e1edc5f50a src: use 'byte' instead of 'upx_byte'; NFCI 2023-02-21 19:27:23 +01:00
Markus F.X.J. Oberhumer 4a8efd2e2f src: rework optimizeReloc handling; cleanups 2023-02-21 15:19:24 +01:00
Markus F.X.J. Oberhumer 8d364c82e2 CI: add build for windows arm64ec 2023-02-12 19:27:56 +01:00
Markus F.X.J. Oberhumer c5059231dc all: rename win32/arm back to wince/arm 2023-02-12 18:58:11 +01:00
Markus F.X.J. Oberhumer f584c91386 all: canonicalize win32 and win64 file names 2023-02-10 09:49:29 +01:00
Markus F.X.J. Oberhumer b8d9c2b755 all: assorted updates and cleanups 2023-02-05 17:20:32 +01:00
Markus F.X.J. Oberhumer 163377d1a0 testsuite: update checksums caused by version bump 2023-01-30 13:44:18 +01:00
Markus F.X.J. Oberhumer 8944e90175 all: post-release version bump 2023-01-30 13:39:49 +01:00
570 changed files with 44682 additions and 25864 deletions
+10 -27
View File
@@ -1,44 +1,27 @@
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
#
# vim:set ft=yaml ts=2 sw=2 et:
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
# for clang-format-15.0.6 from https://github.com/upx/upx-stubtools/releases
#
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
---
BasedOnStyle: LLVM
ColumnLimit: 100
IndentWidth: 4
---
# settings for C and C++
Language: Cpp
AccessModifierOffset: -4
AlignConsecutiveMacros: AcrossComments
AlwaysBreakTemplateDeclarations: true
AttributeMacros:
- __acc_cdecl
- __acc_cdecl_atexit
- __acc_cdecl_qsort
- __acc_cdecl_sighandler
- __acc_forceinline
- __acc_noinline
- __acc_static_noinline
- __acc_static_forceinline
- forceinline
- noinline
- DELETED_FUNCTION
- XSPAN_DELETED_FUNCTION
- may_throw
EmptyLineBeforeAccessModifier: Leave
# IndentPPDirectives: AfterHash # TODO later
SortIncludes: false
SpaceAfterCStyleCast: true
Standard: Cpp03
StatementMacros:
- ACCCHK_ASSERT
- ACCCHK_ASSERT_IS_SIGNED_T
- ACCCHK_ASSERT_IS_UNSIGNED_T
- ACCCHK_ASSERT_SIGN_T
- ACC_BLOCK_BEGIN
- 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
WhitespaceSensitiveMacros:
- ACC_PP_MACRO_EXPAND
- ACC_PP_STRINGIZE
...
+32
View File
@@ -0,0 +1,32 @@
# vim:set ft=yaml ts=2 sw=2 et:
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
# for clang-tidy 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
...
+43
View File
@@ -0,0 +1,43 @@
# vim:set ft=yaml ts=2 sw=2 et:
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
# for clangd from https://clangd.llvm.org/
---
# treat *.h files as C++ source code
If:
PathMatch: src/.*\.h
PathExclude: vendor/.*
CompileFlags:
Add:
- -xc++
---
# C++ flags
If:
PathMatch: [ src/.*\.h, src/.*\.cpp ]
PathExclude: vendor/.*
CompileFlags:
Add:
- -std=gnu++17
# -std=gnu++20 # requires clang >= 10.0
---
# common flags for all C/C++ files
If:
PathMatch: [ src/.*\.h, src/.*\.c, src/.*\.cpp ]
PathExclude: vendor/.*
CompileFlags:
Add:
# see https://github.com/clangd/clangd/issues/1038 : Support deterministic relative include path
- -Ivendor
- -I../vendor
- -I../../vendor
- -DDEBUG
- -fno-strict-aliasing
- -fno-strict-overflow
- -funsigned-char
Diagnostics:
Includes:
# IgnoreHeader: A list of regexes. Include Cleaner will not produce diagnostics
# for headers whose path is a suffix match for any of these.
IgnoreHeader:
- src/.*\.h
UnusedIncludes: None
...
+3 -2
View File
@@ -1,3 +1,4 @@
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
# see https://editorconfig.org/
root = true
@@ -14,8 +15,8 @@ trim_trailing_whitespace = true
indent_size = 8
indent_style = tab
[*.S]
[{*.asm,*.S}]
indent_size = 8
[*.yml]
[{*.yaml,*.yml}]
indent_size = 2
+29 -7
View File
@@ -1,10 +1,32 @@
# make GitHub language detection more accurate, see https://github.com/github/linguist
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
# 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
src/stub/**/*.asm linguist-language=Assembly
src/stub/**/*.S linguist-language=Assembly
/doc/upx.1 linguist-generated
/doc/upx-doc.* linguist-generated
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
+10
View File
@@ -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
-8
View File
@@ -1,8 +0,0 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
# Check for updates to GitHub Actions every weekday
interval: 'daily'
@@ -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="\
693102863358cc906bce946afec10dd0e15d0effc6ceb462d9beaaba25967304 *amd64-linux.elf/upx-3.91
4aa9e1868d7797b50768cf1ae0ab0e93cc2eff81f3abaf36f2fdb5faf673f7b7 *amd64-linux.elf/upx-3.95
996dc60b7b6aa8c4c55b4fbec9b1ad3e2f82f9986fd1cdcd2cb41ab01877d5a9 *amd64-win64.pe/upx-3.95.exe
bb6cd600a28de3abc86c618125d72231d3d4b40de0260d2da7393970859723dd *arm-linux.elf/upx-3.95
bc945bc3f64a318a00ecbfde2e4a4bac2d298f753e5a8dbdc6a972bcabfce6eb *arm-wince.pe/upx-3.91.exe
19bdd27706f3476dfd46e5cdde782908af5bf9d068bf337ad8a26024d51ede8f *arm64-linux.elf/upx-3.95
3b6e5e9eeb660859e35d9d3e005fb51a8163bfe548d8be6525660a30d1ea5c37 *armeb-linux.elf/upx-3.91
2f2d916ee977e06b07429e563aeab0d052b7ba359dd61a7d767e2a7ef7fa049d *armeb-linux.elf/upx-3.95
1e8cded938d4ee16bcc66fb5462650733a8862a1c9fab264a77a22e7958b36a7 *i386-dos32.djgpp2.coff/upx-3.91.exe
6f439d62cdb735570c6c5e941924b6d2819024cad6c3453db020edc1e9e0d66b *i386-dos32.djgpp2.coff/upx-3.95.exe
f6a8a76b9af29272722be6785242a9822ce6b2ca3483cd953c2c34e4d85e1cf4 *i386-linux.elf/upx-3.91
7eead732dddffdb1db5e5002babe112f8589eeb8251cb23e0b6f29dacfad3817 *i386-linux.elf/upx-3.95
2c41d77ae9ac810cde23a222046d05b57a272c90aa75b127e0697a586be1ce1f *i386-win32.pe/upx-3.91.exe
0218c00a3686363148a2bbe7d89634d54a2d7840beeab7f5fef2f269e56d517e *i386-win32.pe/upx-3.95.exe
44034fc9a3609538d8edfbe3996aa3946b1745e537d1ea2ca14181c177b98034 *m68k-atari.tos/upx-3.91.ttp
55c6151325fdf1638584f0fa5ee228547445e239bb0c8f4c6f31c30945e114b1 *mips-linux.elf/upx-3.95
b6905f55277b3abc8ad10eb1ca95135ce9f2a5d87c992f7de78ca8e69d8e819e *mipsel-linux.elf/upx-3.91
3a5eb4b01cb334e4a30a0ebb1c7d9f85f2035e6e5989acc296beb3ff34c98152 *mipsel-linux.elf/upx-3.95
df4157e8e613f62fb26b1965b1c22dc44bf18f4aec4611283afadb9889d267d4 *powerpc-linux.elf/upx-3.91
054a126aa7e17c6c5b8a00f608c4bf98f252ec4ab9ca2c03aebf9c92e30bda4f *powerpc-linux.elf/upx-3.95
4667d37cb2474a30b184cd4d7ca8ba071650c396ebe9f1f9a39172c924676090 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t120_compress_ucl_nrv2d_3_no_filter="\
f3cfc0be5885525965fbd3e56f5a4083a727414978bb4c018b4b0355c5b06921 *amd64-linux.elf/upx-3.91
06f933cf1c5e42f2f00ffb6a5312fa687846b6a566d372459208f8cad34e34bb *amd64-linux.elf/upx-3.95
db33236e886947a74c766e632ded0249166e2e5f74a3d03cda37cc07901cd1b1 *amd64-win64.pe/upx-3.95.exe
3564858c026c2b0637e3c8e41a972fabc609ccc69c7ddd0ae457dd4ba7a62008 *arm-linux.elf/upx-3.95
dceda960aa7b15b13a06bf88d1512d52e7e460d85a81207b6b5407bdbb51ffe8 *arm-wince.pe/upx-3.91.exe
52b93b549591081ef72d19fe09d4588d7f2bc736f2ad50a32be03fb7fcd70e95 *arm64-linux.elf/upx-3.95
1877be1f5f5333f1ee7c77bfb020f35f5c125e7f6b661a92a6918b468c02484f *armeb-linux.elf/upx-3.91
a4d1f01a3dc748e92dd33e1377885ef2955c2c35fd379474c6622ce67267fac2 *armeb-linux.elf/upx-3.95
d5d3cf6ecf1a89f5871bcfef9c59794f249b9f7ca12afdf15b79d343a18ddefc *i386-dos32.djgpp2.coff/upx-3.91.exe
eca16dec497e1a9f334fd4d806f035cafcd3438749d25b494e95f4935760ae4f *i386-dos32.djgpp2.coff/upx-3.95.exe
1ab8d00e13d149f6e74187eadaacd1d8cfa4777ce7489cef88fba4cbde9bcdee *i386-linux.elf/upx-3.91
dd3169256039f7df2db15a86114818b275c03bd96c3ee828d724131b98fcc6f2 *i386-linux.elf/upx-3.95
17a97d24ebbdaa3bd8f7ec9633e38bca1754c8af2d79250aaa5472499a98e0ec *i386-win32.pe/upx-3.91.exe
1bb873ed8a8cbb11238f98c3f616ec6a34f4765a6021e10d9686158f382458f0 *i386-win32.pe/upx-3.95.exe
13b0b57643342d0e08fe084cbf799f518b3d44ac9f39edda7db3e6b6c36386cc *m68k-atari.tos/upx-3.91.ttp
91145a85e926495a536661d4e842a7b5b259707ef6accf5f08d13adcec173f13 *mips-linux.elf/upx-3.95
8090533000872748b70c761d5581d78fde421d66884ab238527ca41d1446c2ae *mipsel-linux.elf/upx-3.91
f82e7b166647f157c981af92eaeec63bf080609591a5d13f76f84cd49c8e7495 *mipsel-linux.elf/upx-3.95
ae312cc5d34fd889ed9582a928ab03c589c0caddb111aceade7e072f928c6361 *powerpc-linux.elf/upx-3.91
fd28cb894be895afb8aec675739b276810e7a35c5212016c3f7acde853d8c763 *powerpc-linux.elf/upx-3.95
e299bb500c34d2f90b2b35a7186a0b24fb5ac80e56d4a2d80f9c8bd32cf2be62 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t130_compress_ucl_nrv2e_3_no_filter="\
eea59d6755beed52bff26941d31362f28097d029d4f61a2f9065dcc63cd628fb *amd64-linux.elf/upx-3.91
b89f4ca39165071a7a5eb107ed9b7c6c77b7c7ad90acdb2b073314571aacc23a *amd64-linux.elf/upx-3.95
6af6bc4f2d4bdb1e7694f44ce695c54d181011b734f159018d5e2c515d14a47c *amd64-win64.pe/upx-3.95.exe
9ae22ad9af331ec8c08ab22b0a8e0e0ff849512a6d11257c55fe7c423c0b7937 *arm-linux.elf/upx-3.95
8605ddb612a1a3e096e272cb876e7777585804fa000f338f2164437a6da3de9a *arm-wince.pe/upx-3.91.exe
2ab36b41db84e6e3002420ec397d79abed451869a7a8b703ab3b81f79c487753 *arm64-linux.elf/upx-3.95
38879c80525760492a95de9bfcbce49997c5bff30bb43a6bb173b1978d21f248 *armeb-linux.elf/upx-3.91
72e3bf259bf1304235a7ebe600f5b37be21297b8552f2fbdf47e28e3aa19e807 *armeb-linux.elf/upx-3.95
3af56cb84be62f4078ae39be3370ef68061b094c62b3cbcd5d38e99e0e91df7f *i386-dos32.djgpp2.coff/upx-3.91.exe
224b882b4dcebc1112ced3df1b468ea8dc58083dac4893fa0061dc50ce6abf7c *i386-dos32.djgpp2.coff/upx-3.95.exe
59e3a1d456036bed175056978d12484a64405f356b1a1fa480866e7e31c9543b *i386-linux.elf/upx-3.91
9662deb5f74b23c5b63d09457442895091f4b6cfd619f7bd6ffc27ec75f08682 *i386-linux.elf/upx-3.95
3c585a745cd105073bb7324f2183731be84cfc4669f2bab1ef20c9bff909d2fc *i386-win32.pe/upx-3.91.exe
fc796dad77cb6cb99bcb5700c3ff0a7b185c1fe8b129a293dd0e45d0903b13e6 *i386-win32.pe/upx-3.95.exe
da41cb691775b8b0ef969954ea272262ed77e83b57257b2ba0ba19427a2ab991 *m68k-atari.tos/upx-3.91.ttp
ea6ff916a226e39a5e67b2118fc3ceb0dbc69d8d473051a5df19af14e03ae25e *mips-linux.elf/upx-3.95
0cbc8eaecb2aa7dcc2e9d7b11ba0c0e26193f1328a35107cf1069a8c5f9e63be *mipsel-linux.elf/upx-3.91
7b112c59fccf3e5f3d4ec253fdb25761e47705a1c5d3a0103249b1747bbbe7d9 *mipsel-linux.elf/upx-3.95
de8354fbeaf0623f3d08c3945dcdb5a8f0c078fe3e8082a13767979e841e6677 *powerpc-linux.elf/upx-3.91
403c26bc1dda0cbf23032bc5ec5ac42ed8537a640a077c4332446227c8a3eb7b *powerpc-linux.elf/upx-3.95
093a7fdbb555c8aea8728b4d6240ed3b723ee9007c5f6ea40a8daf2d1eb63f54 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t140_compress_lzma_2_no_filter="\
6dd472386ff2a9683d75fe4cc8d0d40be223681f4d7305a51a7aacf25501e60f *amd64-linux.elf/upx-3.91
4bbb96b109ae2b8b43b957bc66c3cdc2cfcf3a692377153ef912d09a495c876c *amd64-linux.elf/upx-3.95
510fc860ac393abcfdbb547e999c12a6c6e928ead026607a6879fa7ca1e2d568 *amd64-win64.pe/upx-3.95.exe
a54c0e5b61257154c56f076460f64efbb4216c913c846073d0a695ac3c0ddffd *arm-linux.elf/upx-3.95
9182294f2e31db89b138294cbbc6f6d03ea39a00565adf0e052ed3d21491e1b5 *arm-wince.pe/upx-3.91.exe
fde8face710b6a479a96d7d2d40a29ac8894d5483403e33acbf4a5d6f9cdb29d *arm64-linux.elf/upx-3.95
0a92af3f6034487034ea062bc44c93bba74219fa5fdcbb34d1643a95f7daa9ed *armeb-linux.elf/upx-3.91
2c11ec89ad145e9f82c3cbbd63ed1e1eca2b0d3c3081fce3e0500ed33c05a623 *armeb-linux.elf/upx-3.95
13cbcb06079492a21b7440b981250f84ff2be48a69daa168d95cee798f8fbf77 *i386-dos32.djgpp2.coff/upx-3.91.exe
adfdcd033340a7b14945c9a60da036e25d44c8b1ee0811ac0a4ef1cbca423cc5 *i386-dos32.djgpp2.coff/upx-3.95.exe
e5fff5b965da26349311c0513d09086600c3b466f1d53e42d6e35d6b4656168e *i386-linux.elf/upx-3.91
cf8df3858bbb1c92a06e57ce1b971e11bbf280954f2fc1dc7e5b5a4641d72819 *i386-linux.elf/upx-3.95
ddc4952ef008b7f31e69bf53310d6f03b36a959ebb1cd3c3985d560efcbd4296 *i386-win32.pe/upx-3.91.exe
99b0b637b562798a440ba605d44e34cf7d4ff995b04dc2e54ebee288ed5180b4 *i386-win32.pe/upx-3.95.exe
89a5de403a012256afefff0f88e1cff4696dee611946e326ad15416dbdba7d13 *m68k-atari.tos/upx-3.91.ttp
eac695bc19163050c5bee9271393156a195bfef9c3c76f5aaf3aaef00f5602eb *mips-linux.elf/upx-3.95
b1331b88421cdf8ef73f8ef1a2c86045fc56a495c08d06d83018c88f5f3934de *mipsel-linux.elf/upx-3.91
9644118e26647d489e811ebe3bfd320e2976dbe26621e994fe979b0f9d175818 *mipsel-linux.elf/upx-3.95
64a4a31815e4bf43e2ea866faa494c69a4209ed53055f16562d0d2d6ba7fd927 *powerpc-linux.elf/upx-3.91
dec559bf9cbd4d1745e8f3bf2cedf016a72f443d037f75eab0d2baab191f0ae1 *powerpc-linux.elf/upx-3.95
f10b8afa319b1056a82f24dd52d13003c5cf005fc3cc3481dad1e58ef33e973f *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t150_compress_ucl_2_all_filters="\
2e89a5b8192957b066d5a5ee39e47663518f49c1e7811f6806e21d938201d5b6 *amd64-linux.elf/upx-3.91
d1cfdda4b93d697211c052f3d85cd745e533261f05cc06c2869a8561c07b4f57 *amd64-linux.elf/upx-3.95
c7381363e31af6789111f58ca590b0d751956c322684efa1914f1d918ecc23ce *amd64-win64.pe/upx-3.95.exe
4dc8ba75edd4b1c3d890c9deeb033d9abf08fb65054eddb4f34138d34503c21d *arm-linux.elf/upx-3.95
36f744d6dca6ecb8c60ee456859ac6a1ac241d12ababa20a5e2d0d79551d53aa *arm-wince.pe/upx-3.91.exe
72d3de2abdc3985c790d833a9535054683e2b3feaa6b96778e55ea8f448846a3 *arm64-linux.elf/upx-3.95
233d4f130995bb7155064ce6f651b9f6ac61268c8698ccc90a8ea3b2e297cb39 *armeb-linux.elf/upx-3.91
a107428a7675181974a8efc359d39da74510098d8307347865f7bcdd707e28ad *armeb-linux.elf/upx-3.95
bd57c1e3844310c2a864384f2b83a5781933a5beb05a5eb748a6094e37621166 *i386-dos32.djgpp2.coff/upx-3.91.exe
1a13debece417ada4e18d5ec02efa7ef1c354ddfa4674b5717e0aa6bc90c16e3 *i386-dos32.djgpp2.coff/upx-3.95.exe
f7b56af17d3d8402310387d1e82f90fa670dfa058feb3fe413ac81c01a1efbb1 *i386-linux.elf/upx-3.91
fe9162fbfe8f4eb1c9f286df68107c08f25592d2edaaf5707540c81f709e29ac *i386-linux.elf/upx-3.95
aaa267d824bd0520c016edcc1a6642d4898030760879e1da883b8211cf071350 *i386-win32.pe/upx-3.91.exe
d178699c0ed805829e457987ea5da21f4e37cf1eb74529235d9b1275bf3122f6 *i386-win32.pe/upx-3.95.exe
8376ba3954c4fd9cd5e5e8e38923759db005a4048c3d86dc76476e9f3d92a07d *m68k-atari.tos/upx-3.91.ttp
65a0227127b7952a42216c79a8431d1bbe7f04c9efdc81f72095d095a969cb80 *mips-linux.elf/upx-3.95
c2bd45b55980bfbc5e568a640643772e3e82bc02cd2c7559cb1c57fc0809d01e *mipsel-linux.elf/upx-3.91
74e25daba42baeaaffadab00bacca56b1de5f151a00160592077288a678f41f2 *mipsel-linux.elf/upx-3.95
904310944bec344897fc6b7a61dfe8ee639d136c555a950c736059cbc6cac8be *powerpc-linux.elf/upx-3.91
5304a95cdcdbdcb76cfac2b93e254f601fb73f68be0a44ed282096aec8d55ae8 *powerpc-linux.elf/upx-3.95
7ebd0be91bc9f60e22304103b3543b16a0fd128aa22f11474e31aecc97703e43 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t160_compress_all_methods_1_no_filter="\
4d8069614af5721c7878daf10ee1d30a6bffc5446532963e2ff0e6cb6f1feecd *amd64-linux.elf/upx-3.91
f1971902f7d8f840fdc70ad9edbf5587db556ba046947f5ee7b4130e9ba7de5a *amd64-linux.elf/upx-3.95
0198a6cfd468f7ec7cd32294333400a4c97bf1cac32602594681db8f08c87700 *amd64-win64.pe/upx-3.95.exe
d46340dcd209cce0f1d65d6a50754ea3246cdbba730199765b2c2ac40957bd55 *arm-linux.elf/upx-3.95
aa03361a7dae633d5b6c8b4164726c99bfc28fcf4f1ac8ebea6fc44e90c03244 *arm-wince.pe/upx-3.91.exe
aa0a3dda3e2f073eb36d6614c02f4af79590876a23437623ea6c231be8e070fa *arm64-linux.elf/upx-3.95
578547a4d527655c7fd661148dfcf0f7dc9585dfb08063c13b116364a881bf15 *armeb-linux.elf/upx-3.91
0034809b31b0105631b0e4c0a4378cfd26a80dfca2016228e8084f410025f091 *armeb-linux.elf/upx-3.95
55b9b578a97a7b8637a9041a222269f2563a4e1f75c329c533f83432c8f9652c *i386-dos32.djgpp2.coff/upx-3.91.exe
98a9f601d095f910c68bbf35ff50f19e3e851ef5dae78fc0e9ef4462dd8a314d *i386-dos32.djgpp2.coff/upx-3.95.exe
45f714365212b31419986016b5b730ca77523036469e28242543bfde4dc44678 *i386-linux.elf/upx-3.91
e45f6ae7ad7b9e719e5080bfbd04e7c961242473bb8f1574cb625bc8a1abd201 *i386-linux.elf/upx-3.95
0b5d940059fc6f2a3d5664eadd0781399210c306be99411beeb8f6f02ea85762 *i386-win32.pe/upx-3.91.exe
0f5b50dfe0db34ae07f113871a39c64624f964ed16dc8d49922e6a891c17a3bd *i386-win32.pe/upx-3.95.exe
56fd999694feb66cdc2272daf86bb91b3c66b857867f3e0c071f3e70624760f4 *m68k-atari.tos/upx-3.91.ttp
2d8d2e02bedad8ba1e7d69a89888b173b9be48ee154e2461c205ba4eae6ececa *mips-linux.elf/upx-3.95
c478c21ecabe91910cf861ebc6b6d38deeb31545e5ae44eaf826dafb477bbfba *mipsel-linux.elf/upx-3.91
4d66e1b32ca6b1d399616de5643ee5d1c54a7bf1eca761055570450f56efe4f9 *mipsel-linux.elf/upx-3.95
72c85b48afb30cc191483af41f797a397225cfaaa44e2eaf7a9d59d9033335e1 *powerpc-linux.elf/upx-3.91
c0ed0c72fd6a6e0bfb4444b8c358018246f80cbc732388a22bd2492fd9fdc59c *powerpc-linux.elf/upx-3.95
070f4c2ca60717abedda0ab4030d546cca8a75b9872038a414e2946b8d8f93e7 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t170_compress_all_methods_no_lzma_5_no_filter="\
223bcdc5f11daa4d0258090e967d4e0b5986d764d6b21fcfadba7212676396f2 *amd64-linux.elf/upx-3.91
a3e5f1a20bd9db4ae920c5c7e7f1707a63fa3f557f9db50b5e1004b706e3a52c *amd64-linux.elf/upx-3.95
355011427a4d433ccef5060e4cbebc59b0ecc38a430566cdb684330388ea0812 *amd64-win64.pe/upx-3.95.exe
1e0a8363b539953181dc95283a1e3100bacce961f49e875c8f430b18d0e6672d *arm-linux.elf/upx-3.95
e281362e2172468d20ea2c7171c847f47e01a63d912cafacf977236655708521 *arm-wince.pe/upx-3.91.exe
7f3497c67e816b3f2af6642f09ba809166f8a0a65f52936cfb2e3d9756d7bd44 *arm64-linux.elf/upx-3.95
7d9d52959a64c5dd19ea343c8c2bdd4d70fd0644d13c62924760407515fd74ba *armeb-linux.elf/upx-3.91
e05ad251ec24e2f788de71c4c8cf7c8880a8eb7d8a516ca8d6ab94c715c2f77d *armeb-linux.elf/upx-3.95
00a030d8967c5145b955eba17d84edd44b21c93b570f80a44e894a10a3ebf99f *i386-dos32.djgpp2.coff/upx-3.91.exe
b4b0e3c774dbf3940af777d28e1ba7c62bfedaa710e3376e81259218779eae56 *i386-dos32.djgpp2.coff/upx-3.95.exe
f903265140b193e672c4dd2bc28e68b9f822d73517f0b339fc715ad781a49fab *i386-linux.elf/upx-3.91
6253062e41c4619bb3aeb807665a2925b1f01095d000c614c443b81d44112a1d *i386-linux.elf/upx-3.95
7664ed4ce00b962a21ca5654993c4c4cb2ec1afcf9dc921cd90862f8412572cc *i386-win32.pe/upx-3.91.exe
6ef354d0b2dffc71c32fc33f3f89b0b8ae7035e43e8a684a12d6ce2c53caf706 *i386-win32.pe/upx-3.95.exe
5890050fe690bb93bf70693f1bef0e6ea708029836c7d8aa57de02b6aefe4239 *m68k-atari.tos/upx-3.91.ttp
2bce2082ae39dedcc21a1a6c83e954073b368e9172ee0c7f2a3f13b3447a7898 *mips-linux.elf/upx-3.95
d5b88d291a8a2141d9d9f07a6a21e11522e510c6520ba0c36ebf94d089962607 *mipsel-linux.elf/upx-3.91
ff42d564999e02346c86d4156266f423edd55b3887aadf76d81a8c355e3b175d *mipsel-linux.elf/upx-3.95
f33205ad8252524d8c48d18cdb03bba507e29c9cc931f94327a5a46480f70843 *powerpc-linux.elf/upx-3.91
011683a891e30ea346efe9ba5c1488fb50f143e4090bd2be07537c696d6167db *powerpc-linux.elf/upx-3.95
9d919460b0ceec4b880cdf14850fea8096d6796c2457467b3cc9b2ce954cc6de *powerpc64le-linux.elf/upx-3.95
"
########## end .sha256sums.recreate
-290
View File
@@ -1,290 +0,0 @@
#! /bin/bash
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
argv0=$0; argv0abs=$(readlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
# very first version of the upx-testsuite; requires:
# $upx_exe
# $upx_testsuite_SRCDIR
# $upx_testsuite_BUILDDIR (optional)
# $BM_T (optional)
# convenience
[[ -z $upx_testsuite_BUILDDIR ]] && upx_testsuite_BUILDDIR=./tmp-upx-testsuite
[[ -f $upx_exe ]] && upx_exe=$(readlink -en -- "$upx_exe")
# make dirs absolute
upx_testsuite_SRCDIR=$(readlink -en -- "$upx_testsuite_SRCDIR")
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
mkdir -p "$upx_testsuite_BUILDDIR"
upx_testsuite_BUILDDIR=$(readlink -en -- "$upx_testsuite_BUILDDIR")
cd / && cd "$upx_testsuite_BUILDDIR" || exit 1
# /***********************************************************************
# // support functions
# ************************************************************************/
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 */* | 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
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
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
mkdir 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
# ************************************************************************/
case $UPX_TESTSUITE_FAST in
[0-7]) ;;
*) UPX_TESTSUITE_FAST=999 ;;
esac
if [[ $UPX_TESTSUITE_FAST -ge 1 ]]; 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_FAST -ge 2 ]]; 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_FAST -ge 3 ]]; 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_FAST -ge 4 ]]; 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_FAST -ge 5 ]]; 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_FAST -ge 6 ]]; 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_FAST -ge 7 ]]; 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"
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
+292 -136
View File
@@ -1,4 +1,4 @@
# Support for GitHub Actions -- https://github.com/features/actions
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
# note: GitHub Actions runner images are frequently updated, and
# unfortunately this sometimes breaks builds in mysterious ways...
@@ -9,8 +9,15 @@ name: 'CI'
on: [push, workflow_dispatch]
env:
CMAKE_REQUIRED_QUIET: 'OFF'
CMAKE_VERBOSE_MAKEFILE: 'ON'
CTEST_OUTPUT_ON_FAILURE: 'ON'
DEBIAN_FRONTEND: noninteractive
UPX_CMAKE_BUILD_FLAGS: --verbose
UPX_CMAKE_CONFIG_FLAGS: -Wdev --warn-uninitialized
UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO: 1
# 2024-03-23
ZIG_DIST_VERSION: 0.12.0-dev.3429+13a9d94a8
jobs:
job-rebuild-and-verify-stubs:
@@ -21,17 +28,24 @@ jobs:
run: |
uname -a; pwd; id; umask
mkdir ../deps; cd ../deps; mkdir packages
# for ubuntu-22.04: install python2-minimal
##sudo apt-get update && sudo apt-get install -y --no-install-recommends python2-minimal
# manually install compat libs from Ubuntu 16.04
wget -q 'http://archive.kernel.org/ubuntu-archive/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.6-1_amd64.deb'
if ! test -e /usr/bin/python2; then
####sudo apt-get update && sudo apt-get install -y --no-install-recommends python2-minimal
# install python2-minimal packages from Debian-11
wget -q 'https://ftp.debian.org/debian/pool/main/p/python2.7/libpython2.7-minimal_2.7.18-8+deb11u1_amd64.deb'
wget -q 'https://ftp.debian.org/debian/pool/main/p/python2.7/python2.7-minimal_2.7.18-8+deb11u1_amd64.deb'
sudo dpkg -i ./*python2*.deb && rm ./*python2*.deb && sudo ldconfig
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/
rm -rf ./*.deb ./packages
sudo ldconfig
# 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'
uses: actions/checkout@v3
uses: actions/checkout@v4
with: { submodules: true }
- name: 'Rebuild and verify stubs'
run: |
@@ -40,22 +54,25 @@ jobs:
git status || true
make -C src/stub extra-all all
if ! git diff --quiet; then git diff; exit 1; fi
- run: bash ./misc/scripts/check_whitespace_git.sh
- name: 'Check source code formatting'
run: |
bash ./misc/scripts/check_whitespace_git.sh
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
job-linux-cmake:
job-linux-cmake: # uses cmake + make
if: true
needs: [ job-rebuild-and-verify-stubs ]
name: ${{ format('{0} cmake', matrix.os) }}
name: ${{ format('{0}', matrix.os) }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-22.04, use_m32: true }
- { os: ubuntu-20.04, use_m32: false }
- { os: ubuntu-20.04, use_m32: true } # use_m32 also works here, but save some CI time
env:
UPX_CONFIG_EXPECT_THREADS: 'ON'
steps:
- name: 'Install extra 32-bit and Windows packages'
if: ${{ matrix.use_m32 }}
@@ -63,253 +80,352 @@ jobs:
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
sudo apt-get install libc6-dbg:i386 valgrind
- name: 'Check out code'
uses: actions/checkout@v3
uses: actions/checkout@v4
with: { submodules: true }
- name: 'Check out test suite'
run: 'git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite'
- name: 'Build cmake extra/gcc/debug'
- name: 'Build extra/gcc/debug'
run: 'make build/extra/gcc/debug'
- name: 'Build cmake extra/gcc/release'
- name: 'Build extra/gcc/release'
run: 'make build/extra/gcc/release'
- name: 'Build cmake extra/clang/debug'
- name: 'Build extra/clang/debug'
run: 'make build/extra/clang/debug'
- name: 'Build cmake extra/clang/release'
- name: 'Build extra/clang/release'
run: 'make build/extra/clang/release'
- name: 'Build cmake extra/gcc-m32/debug'
- name: 'Build 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 }}
- name: 'Build 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 }}
- name: 'Build 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 }}
- name: 'Build 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'
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"
(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@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
- name: 'Run basic tests'
- name: 'Run install tests'
run: |
(cd build/extra/gcc/release && DESTDIR="$PWD/Install with cmake" cmake --install .)
(cd build/extra/gcc/release && DESTDIR="$PWD/Install with make" make install)
- name: 'Run ctest tests'
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 basic tests 32-bit'
- 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: 'Mimic ctest tests with Valgrind'
run: |
if command -v valgrind >/dev/null; then
export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all"
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
# clang/debug does not work before valgrind-3.20, see https://bugs.kde.org/show_bug.cgi?id=452758
##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
fi
- name: 'Mimic ctest tests 32-bit with Valgrind'
if: ${{ matrix.use_m32 }}
run: |
if command -v valgrind >/dev/null; then
export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all"
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
fi
- name: 'Run file system test suite'
run: |
env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/test_symlinks.sh
- name: 'Run file system test suite with Valgrind'
run: |
if command -v valgrind >/dev/null; then
export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all"
env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/test_symlinks.sh
fi
- name: 'Run test suite build/extra/gcc/release'
run: |
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
testsuite_1=$(readlink -en ./.github/travis_testsuite_1.sh)
env -C build/extra/gcc/release upx_exe=./upx bash "$testsuite_1"
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 ]
name: ${{ format('{0} cmake', matrix.os) }}
name: ${{ format('{0} {1}', matrix.os, matrix.xcode_version) }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# NOTE: macos does not have "env -C"; only with brew coreutils
# NOTE: macos-11 does not have "readlink -f"; only on macos >= 12 or with brew coreutils
- { 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, xcode_version: 14.3.1 }
- { os: macos-13, testsuite: true } # use default Xcode-15
# { os: macos-14, gcc: gcc-13, gxx: 'g++-13', testsuite: true } # gcc-13: INTERNAL ERROR in ld64
# { os: macos-14, gcc: gcc-13, gxx: 'g++-13', testsuite: true, xcode_version: 14.3.1 } # gcc-13: MISSING HEADER FILES
- { os: macos-14, gcc: gcc-12, gxx: 'g++-12', testsuite: true } # => use gcc-12 for now
env:
UPX_CONFIG_EXPECT_THREADS: 'ON'
steps:
- uses: maxim-lobanov/setup-xcode@v1
if: matrix.xcode_version # NOTE: gcc-12 on macos-13 does not work with Xcode-15
with:
xcode-version: ${{ matrix.xcode_version }}
- name: 'Install brew packages'
if: ${{ matrix.testsuite }}
run: |
brew update
brew install coreutils
test -z "$HOMEBREW_PREFIX" && HOMEBREW_PREFIX="$(brew --prefix)"
echo "HOMEBREW_PREFIX=$HOMEBREW_PREFIX" >> $GITHUB_ENV
# testsuite needs working "readlink -en" and "sha256sum -b"
if ! test -e "$HOMEBREW_PREFIX/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
case "${{ matrix.os }}" in
macos-11 | macos-12) echo "UPX_DEBUG_FORCE_PACK_MACOS=1" >> $GITHUB_ENV ;;
# FIXME: UPX on macos-13+ is broken => disable self-test for now
macos-13 | macos-14) echo "UPX_CONFIG_DISABLE_SELF_PACK_TEST=ON" >> $GITHUB_ENV ;;
esac
- name: 'Check out code'
uses: actions/checkout@v3
uses: actions/checkout@v4
with: { submodules: true }
- 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'
- name: 'Build extra/clang/debug'
run: 'make build/extra/clang/debug'
- name: 'Build cmake extra/clang/release'
- name: 'Build extra/clang/release'
run: 'make build/extra/clang/release'
- name: 'Build cmake extra/gcc/debug'
- name: 'Build extra/gcc/debug'
if: ${{ matrix.gcc != '' }}
run: 'make build/extra/gcc/debug CC=${{ matrix.gcc }} CXX=${{ matrix.gxx }}'
- name: 'Build cmake extra/gcc/release'
run: 'make build/extra/gcc/debug CC="${{ matrix.gcc }} -static-libgcc" CXX="${{ matrix.gxx }} -static-libgcc -static-libstdc++"'
- name: 'Build extra/gcc/release'
if: ${{ matrix.gcc != '' }}
run: 'make build/extra/gcc/release CC=${{ matrix.gcc }} CXX=${{ matrix.gxx }}'
- name: 'Build cmake xtarget/cross-darwin-arm64/debug'
run: 'make build/extra/gcc/release CC="${{ matrix.gcc }} -static-libgcc" CXX="${{ matrix.gxx }} -static-libgcc -static-libstdc++"'
- name: 'Build xtarget/cross-darwin-arm64/debug'
run: |
CC="clang -target arm64-apple-darwin" CXX="clang++ -target arm64-apple-darwin" \
make UPX_XTARGET=cross-darwin-arm64 xtarget/debug
- name: 'Build cmake xtarget/cross-darwin-arm64/release'
make UPX_XTARGET=xtarget/cross-darwin-arm64 xtarget/debug \
CC="clang -target arm64-apple-darwin" CXX="clang++ -target arm64-apple-darwin"
- name: 'Build 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
make UPX_XTARGET=xtarget/cross-darwin-arm64 xtarget/release \
CC="clang -target arm64-apple-darwin" CXX="clang++ -target arm64-apple-darwin"
- name: 'Make artifact'
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
X="${{ matrix.xcode_version }}"; test -n "$X" && X="-xcode-$X"
N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}$X" | sed 's/[^0-9a-zA-Z_.-]/-/g')
mkdir -p "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")
# 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@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
- name: 'Run basic tests'
- name: 'Run install tests'
run: |
(cd build/extra/clang/release && DESTDIR="$PWD/Install with cmake" cmake --install .)
(cd build/extra/clang/release && DESTDIR="$PWD/Install with make" make install)
- name: 'Run ctest tests'
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'
run: |
export PATH="$HOMEBREW_PREFIX/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="$HOMEBREW_PREFIX/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 PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
testsuite_1=$(readlink -en ./.github/travis_testsuite_1.sh)
env -C build/extra/clang/release upx_exe=./upx bash "$testsuite_1"
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 ]
name: ${{ format('{0} cmake', matrix.os) }}
name: ${{ format('{0}', matrix.name) }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# windows-2019 used to work but got broken with the 20220821.1 runner-image
# update; we cannot download that image for inspection, and debugging the
# remote image is painful, so disable for now
# see https://github.com/actions/runner-images.git
####- { os: windows-2019 }
- { os: windows-2022 }
- { name: windows-2019-amd64, os: windows-2019, vsversion: 2019, arch: amd64 }
- { name: windows-2022-amd64, os: windows-2022, vsversion: 2022, arch: amd64 }
env:
UPX_CONFIG_EXPECT_THREADS: 'ON'
steps:
- run: git config --global core.autocrlf false
- name: 'Check out code'
uses: actions/checkout@v3
uses: actions/checkout@v4
with: { submodules: true }
- name: 'Check out test suite'
run: 'git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite'
- name: 'Inspect runner-image settings'
# debug remote image; also see https://github.com/actions/runner-images.git
if: ${{ false }}
run: |
Get-Command bash; Get-Command cmake; Get-Command make
bash --version; cmake --version; make --version
Get-Command cl -ErrorAction SilentlyContinue
- name: 'Build cmake debug'
- name: 'Set up Developer Command Prompt'
uses: ilammy/msvc-dev-cmd@v1
with:
vsversion: ${{ matrix.vsversion }}
arch: ${{ matrix.arch }}
- name: 'Build debug'
run: 'make build/debug'
- name: 'Build cmake release'
- name: 'Build release'
run: 'make build/release'
- name: 'Make artifact'
shell: bash
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"
(cd build && cp -ai --parents */*/upx.exe "../tmp/artifact/$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@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
- name: 'Run basic tests'
- name: 'Run ctest tests'
if: ${{ matrix.arch != 'amd64_arm64' }}
run: |
cmake --build build/debug --config Debug --target RUN_TESTS
cmake --build build/release --config Release --target RUN_TESTS
ctest --test-dir build/debug -C Debug
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)"
testsuite_1=$(readlink -en ./.github/travis_testsuite_1.sh)
env -C build/release/Release upx_exe=./upx bash "$testsuite_1"
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 ]
name: ${{ format('windows {0}', matrix.name) }}
runs-on: ${{ matrix.os }}
env:
C: ${{ matrix.C }}
C: ${{ matrix.name }}
B: release
H: 'd:\a\upx\upx'
strategy:
fail-fast: false
matrix:
include:
- { name: amd64-win64-vs2019, os: windows-2019, C: msvc-14.2-x64, arch: amd64 }
- { name: amd64-win64-vs2022, os: windows-2022, C: msvc-14.3-x64, arch: amd64 }
- { name: arm64-win64-vs2019, os: windows-2019, C: msvc-14.2-x64, arch: amd64_arm64 }
- { name: arm64-win64-vs2022, os: windows-2022, C: msvc-14.3-x64, arch: amd64_arm64 }
- { name: i386-win32-vs2019, os: windows-2019, C: msvc-14.2-x86, arch: amd64_x86 }
- { name: i386-win32-vs2022, os: windows-2022, C: msvc-14.3-x86, arch: amd64_x86 }
- { name: amd64-win64-vs2019, os: windows-2019, vsversion: 2019, arch: amd64 }
- { name: amd64-win64-vs2022, os: windows-2022, vsversion: 2022, arch: amd64 }
- { name: arm64-win64-vs2019, os: windows-2019, vsversion: 2019, arch: amd64_arm64 }
- { 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:
- run: git config --global core.autocrlf false
- name: 'Check out code'
uses: actions/checkout@v3
uses: actions/checkout@v4
with: { submodules: true }
- name: 'Prepare sources and Check out test suite'
shell: bash
run: |
git config --global core.autocrlf input
git --version && bash --version
git clone --depth=1 https://github.com/upx/upx-testsuite ../deps/upx-testsuite
mkdir -p -v build/$C/$B/{ucl,upx,zlib,zstd}
mkdir -p -v build/$C/$B/{bzip2,ucl,upx,zlib,zstd}
repository_name="${GITHUB_REPOSITORY##*/}" # basename
echo "H=d:\\a\\$repository_name\\$repository_name" >> $GITHUB_ENV
- name: 'Set up Developer Command Prompt'
uses: ilammy/msvc-dev-cmd@v1
with:
vsversion: ${{ matrix.vsversion }}
arch: ${{ matrix.arch }}
- name: 'Build'
- name: 'Build by hand'
shell: cmd
run: |
@REM setup directories
@REM ===== set vars =====
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=0x0501
set BDIR=%H%\build\%C%\%B%
set DEFS=-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS
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 =====
cd %BDIR%\ucl
set s=%H%\vendor\ucl
cl -MT -J -O2 -W4 -WX %DEFS% -I%s%\include -I%s% -c %s%\src\*.c
link -lib -out:ucl.lib *.obj
%RUN_CL% -J -O2 -W4 -WX %DEFS% -I%s%\include -I%s% -c %s%\src\*.c
%RUN_LIB% -out:ucl.lib *.obj
@REM ===== build zlib =====
cd %BDIR%\zlib
cl -MT -J -O2 -W3 -WX %DEFS% -c %H%\vendor\zlib\*.c
link -lib -out:zlib.lib *.obj
%RUN_CL% -J -O2 -W3 -WX %DEFS% -DHAVE_VSNPRINTF -c %H%\vendor\zlib\*.c
%RUN_LIB% -out:zlib.lib *.obj
@REM ===== build zstd =====
@rem cd %BDIR%\zstd
@rem set s=%H%\vendor\zstd\lib
@rem cl -MT -J -O2 -W4 -WX -DDYNAMIC_BMI2=0 -DZSTD_DISABLE_ASM %DEFS% -c %s%\common\*.c %s%\compress\*.c %s%\decompress\*.c
@rem link -lib -out:zstd.lib *.obj
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 =====
cd %BDIR%\upx
set s=%H%\src
cat .GITREV.txt
set /p GITREV=<.GITREV.txt
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
cl -MT -std:c++17 -Zc:__cplusplus -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" -DWITH_ZSTD=0 %DEFS% -I%H%\vendor -I%H%\vendor\boost-pfr\include -Feupx.exe %sources% %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj
%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'
shell: bash
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-windows-${{ 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"
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
echo "artifact_name=$N" >> $GITHUB_ENV
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
@@ -321,6 +437,7 @@ jobs:
cd $Env:H\build\$Env:C\$Env:B\upx
$Env:UPX = "--no-color --no-progress"
.\upx.exe --version
.\upx.exe --sysinfo -v
.\upx.exe upx.exe -o upx_packed.exe
dir *.exe
.\upx.exe -l upx_packed.exe
@@ -331,35 +448,48 @@ jobs:
shell: bash
run: |
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
testsuite_1=$(readlink -en ./.github/travis_testsuite_1.sh)
env -C build/$C/$B/upx upx_exe=./upx.exe bash "$testsuite_1"
env -C build/$C/$B/upx upx_exe=./upx.exe bash "$PWD"/misc/testsuite/upx_testsuite_1.sh
job-linux-zigcc:
if: ${{ true }}
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.17 # older versions such as alpine:3.12 also work; no-container also works
container: 'alpine:3.19'
strategy:
fail-fast: false
matrix:
include:
- { zig_target: aarch64-linux-musl }
- { zig_target: aarch64-macos.11-none }
- { zig_target: aarch64-macos.12-none }
- { zig_target: aarch64-macos.13-none }
# only build a few targets => more targets are tested in the Weekly CI
- { zig_target: aarch64-linux-musl, qemu: qemu-aarch64 }
# { zig_target: aarch64-linux-musl, qemu: qemu-aarch64, 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: i386-linux-musl }
- { zig_target: arm-linux-musleabihf, qemu: qemu-arm }
# { zig_target: arm-linux-musleabihf, qemu: qemu-arm, zig_pic: -fPIE }
- { zig_target: i386-linux-musl, qemu: qemu-i386 -cpu Conroe }
# { zig_target: i386-linux-musl, qemu: qemu-i386 -cpu Conroe, zig_pic: -fPIE }
- { zig_target: i386-windows-gnu }
- { zig_target: x86_64-linux-musl }
- { zig_target: x86_64-linux-musl, zig_pic: -fPIE }
- { zig_target: x86_64-macos.11-none }
- { zig_target: x86_64-macos.12-none }
- { zig_target: x86_64-macos.13-none }
# mips and mipsel: bad hard-float code generation(??); or QEMU bug; or UPX bug; see https://github.com/upx/upx/issues/788
- { zig_target: mips-linux-musl, zig_flags: -msoft-float, qemu: qemu-mips }
- { zig_target: mipsel-linux-musl, zig_flags: -msoft-float, qemu: qemu-mipsel }
- { zig_target: powerpc-linux-musl, qemu: qemu-ppc }
- { zig_target: powerpc64-linux-musl, qemu: qemu-ppc64 }
- { zig_target: powerpc64le-linux-musl, qemu: qemu-ppc64le }
- { zig_target: x86_64-linux-musl, qemu: qemu-x86_64 }
# { zig_target: x86_64-linux-musl, qemu: qemu-x86_64, 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:
# 2023-01-30
ZIG_DIST_VERSION: 0.11.0-dev.1491+2b27bc2c6
##UPX_CONFIG_EXPECT_THREADS: 'ON'
# zig is currently missing winpthreads; see https://github.com/ziglang/zig/issues/10989
UPX_CONFIG_EXPECT_THREADS: ${{ contains(matrix.zig_target, '-windows-') && 'OFF' || 'ON' }}
# for zig-cc wrapper scripts (see below):
ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING
ZIG_FLAGS: ${{ matrix.zig_flags }}
@@ -376,7 +506,7 @@ jobs:
# 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@v3
uses: actions/checkout@v4
with: { submodules: true }
- name: ${{ format('Install Zig {0}', env.ZIG_DIST_VERSION) }}
shell: bash
@@ -391,7 +521,7 @@ jobs:
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
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
@@ -407,31 +537,57 @@ jobs:
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*
make UPX_XTARGET=zig/${ZIG_TARGET}${ZIG_PIC} xtarget/release \
CC="zig-cc" CXX="zig-cxx" CMAKE_AR="$HOME/.local/bin/zig-ar" CMAKE_RANLIB="$HOME/.local/bin/zig-ranlib"
file build/zig/${ZIG_TARGET}${ZIG_PIC}/release/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*
make UPX_XTARGET=zig/${ZIG_TARGET}${ZIG_PIC} xtarget/debug \
CC="zig-cc" CXX="zig-cxx" CMAKE_AR="$HOME/.local/bin/zig-ar" CMAKE_RANLIB="$HOME/.local/bin/zig-ranlib"
file build/zig/${ZIG_TARGET}${ZIG_PIC}/debug/upx*
- name: ${{ format('Make artifact from upx-{0}-{1}', github.ref_name, env.UPX_GITREV_SHORT) }}
shell: bash
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-zigcc-${{ matrix.zig_target }}${ZIG_PIC}
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@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
# vim:set ts=2 sw=2 et:
- 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)
- name: 'Run ctest tests'
if: ${{ matrix.zig_target == 'i386-linux-musl' || matrix.zig_target == 'x86_64-linux-musl' }}
run: |
make -C build/zig/${ZIG_TARGET}${ZIG_PIC}/debug test
make -C build/zig/${ZIG_TARGET}${ZIG_PIC}/release test
- name: 'Mimic ctest tests'
if: ${{ matrix.zig_target == 'i386-linux-musl' || matrix.zig_target == 'x86_64-linux-musl' }}
run: |
apk add coreutils
env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh
env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/release bash "$PWD"/misc/testsuite/mimic_ctest.sh
- name: ${{ format('Mimic ctest tests with QEMU {0}', matrix.qemu) }}
if: ${{ matrix.qemu }}
run: |
qemu="${{ matrix.qemu }}"
apk add coreutils "${qemu%% *}"
export upx_exe_runner="$qemu"
env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh
env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/release bash "$PWD"/misc/testsuite/mimic_ctest.sh
- name: 'Mimic ctest tests with Valgrind'
if: ${{ matrix.zig_target == 'x86_64-linux-musl' }}
run: |
apk add coreutils valgrind
export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all"
upx_exe_runner="$upx_exe_runner --suppressions=$PWD/misc/valgrind/musl.supp"
env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh
env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/release bash "$PWD"/misc/testsuite/mimic_ctest.sh
-37
View File
@@ -1,37 +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: 'GitHub - 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@v7
with:
operations-per-run: 300
exempt-all-milestones: true
exempt-issue-labels: 'blocker,enhancement,regression'
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 }}
-38
View File
@@ -1,38 +0,0 @@
name: 'Static Analyzer - 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
-29
View File
@@ -1,29 +0,0 @@
# minimal GitHub CI building UPX with clang and gcc in an Alpine Linux container
name: 'CI - Minimal CI with Alpine Linux'
on: { workflow_dispatch: }
jobs:
job-alpine-cmake:
strategy: {matrix: {container: ['alpine:3.12','alpine:3.17','alpine:edge']}}
name: ${{ format('container {0}', matrix.container) }}
runs-on: ubuntu-latest
container: ${{ matrix.container }}
steps:
- name: ${{ format('Install packages {0}', matrix.container) }}
run: 'apk update && apk upgrade && apk add bash clang cmake g++ git make'
- name: ${{ format('Check out code upx-{0}', github.ref_name) }}
run: |
git clone --branch "$GITHUB_REF_NAME" --depth 1 https://github.com/upx/upx
git -C upx submodule update --init
echo "artifact_name=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-minimal-ci-${{ matrix.container }}" | sed 's/[:,; ]/-/g' >> $GITHUB_ENV
- { name: 'Build clang', run: 'make -C upx UPX_XTARGET=clang-static CC="clang -static" CXX="clang++ -static"' }
- { name: 'Build gcc', run: 'make -C upx UPX_XTARGET=gcc-static CC="gcc -static" CXX="g++ -static"' }
- { name: 'Strip release binaries', run: 'strip -p --strip-unneeded upx/build/*/*/release/upx' }
- name: ${{ format('Upload artifact {0}', env.artifact_name) }}
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}
path: 'upx*/build/*/*/*/upx'
- { name: 'Run basic tests clang', run: 'make -C upx/build/xtarget/clang-static/release test' }
- { name: 'Run basic tests gcc', run: 'make -C upx/build/xtarget/gcc-static/release test' }
-16
View File
@@ -1,16 +0,0 @@
name: 'GitHub - 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 }}'
-22
View File
@@ -1,22 +0,0 @@
name: 'Static Analyzer - scan-build'
on:
schedule:
- cron: '40 1 * * 3'
workflow_dispatch:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
container: 'alpine:edge'
steps:
- name: 'Install packages'
run: 'apk update && apk upgrade && apk add bash clang clang-analyzer cmake g++ git make'
- name: 'Check out code'
uses: actions/checkout@v3
with: { submodules: true }
- name: 'Perform scan-build Analysis Debug'
run: 'make build/extra/scan-build/debug'
- name: 'Perform scan-build Analysis Release'
run: 'make build/extra/scan-build/release'
+17 -4
View File
@@ -1,28 +1,41 @@
/.hg*
/.vscode*
/Makevars.global*
/Makevars[.-]global*
/Testing*
/build*
/maint*
/vendor*
GNUmakefile
MMakefile
Makevars.local*
GNUmakefile*
MMakefile*
Makevars[.-]local*
compile_flags*.txt
Tmp*
tmp*
*.a
*.bz2
*.d
*.diff
*.dll
*.dylib
*.exe
*.gz
*.lib
*.map
*.o
*.obj
*.out
*.patch
*.py[cdo]
*.rar
*.so
*.swp
*.tmp
*.ttp
*.xz
*.zip
*.zst
doc/*.man
doc/*.ps
+351 -166
View File
@@ -1,46 +1,99 @@
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
#
# UPX "CMake" build file; see https://cmake.org/
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
#
# Build requirements:
# 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)
# 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")
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 devel builds
# 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)
# NOTE: self-pack test can only work if the host executable format is supported by UPX!
# 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
#***********************************************************************
# Disallow in-source builds. Note that you will still have to manually
# clean up a few files if you accidentally try an in-source build.
if(NOT MSVC_IDE)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
if(",${CMAKE_CURRENT_SOURCE_DIR}," STREQUAL ",${CMAKE_CURRENT_BINARY_DIR},")
message(FATAL_ERROR "ERROR: In-source builds are not allowed, please use an extra build dir.")
endif()
endif()
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(UPX_VERSION_STRING "4.2.3") # this should match src/version.h
# determine git revision
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.
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
upx_disallow_in_source_build()
endif()
# 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
)
upx_print_env_var(CC CXX)
# determine Git revision
set(GITREV_SHORT "")
set(GITREV_PLUS "")
set(GIT_DESCRIBE "")
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git" AND NOT UPX_CONFIG_DISABLE_GITREV)
find_package(Git)
if(Git_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV)
if(Git_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --short=12 HEAD
RESULT_VARIABLE result ERROR_QUIET
@@ -64,8 +117,6 @@ if(Git_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV)
set(GIT_DESCRIBE "${CMAKE_MATCH_1}-devel.${CMAKE_MATCH_2}+git-${CMAKE_MATCH_3}")
endif()
endif()
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git") # extra check
set(GITREV_SHORT "")
endif()
if(GITREV_SHORT)
message(STATUS "UPX_VERSION_GITREV = \"${GITREV_SHORT}${GITREV_PLUS}\"")
@@ -79,152 +130,252 @@ else()
endif()
# CMake init
project(upx VERSION 4.0.2 LANGUAGES C CXX)
upx_set_default_build_type(Release) # default is CMAKE_BUILD_TYPE=Release
project(upx VERSION "${UPX_VERSION_STRING}" LANGUAGES C CXX)
upx_apply_build_type()
# set default build type to "Release"
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
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}")
# set MSVC_FRONTEND and MINGW
if(NOT DEFINED MSVC_FRONTEND AND (MSVC OR CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC"))
set(MSVC_FRONTEND 1)
endif()
list(REMOVE_DUPLICATES c)
set(CMAKE_CONFIGURATION_TYPES "${c}" CACHE STRING "List of supported configuration types." FORCE)
elseif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
if(NOT DEFINED MINGW AND CMAKE_C_PLATFORM_ID MATCHES "^MinGW")
set(MINGW 1)
endif()
#***********************************************************************
# targets and compilation flags
# common compilation flags
#***********************************************************************
#find_package(Threads) # multithreading is currently not used; maybe in UPX version 5
set(UPX_CONFIG_DISABLE_ZSTD ON) # zstd is currently not used; maybe in UPX version 5
include(CheckCCompilerFlag)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckStructHasMember)
include(CheckSymbolExists)
file(GLOB ucl_SOURCES "vendor/ucl/src/*.c")
list(SORT ucl_SOURCES)
add_library(upx_vendor_ucl STATIC ${ucl_SOURCES})
set_property(TARGET upx_vendor_ucl PROPERTY C_STANDARD 11)
upx_cmake_include_hook(3_common_compilation_flags)
file(GLOB zlib_SOURCES "vendor/zlib/*.c")
list(SORT zlib_SOURCES)
add_library(upx_vendor_zlib STATIC ${zlib_SOURCES})
set_property(TARGET upx_vendor_zlib PROPERTY C_STANDARD 11)
if(NOT UPX_CONFIG_DISABLE_ZSTD)
file(GLOB zstd_SOURCES "vendor/zstd/lib/*/*.c")
list(SORT zstd_SOURCES)
add_library(upx_vendor_zstd STATIC ${zstd_SOURCES})
set_property(TARGET upx_vendor_zstd PROPERTY C_STANDARD 11)
if(NOT DEFINED HAVE_UNISTD_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
endif()
if(NOT DEFINED HAVE_UTIMENSAT)
# 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()
file(GLOB upx_SOURCES "src/*.cpp" "src/[cfu]*/*.cpp")
list(SORT upx_SOURCES)
add_executable(upx ${upx_SOURCES})
set_property(TARGET upx PROPERTY CXX_STANDARD 17)
target_link_libraries(upx upx_vendor_ucl upx_vendor_zlib)
if(NOT MSVC)
# rather strict default compilation warnings
set(warn_strict
-Wall -Wextra -Wcast-align -Wcast-qual -Wmissing-declarations
-Wpointer-arith -Wshadow -Wvla -Wwrite-strings
)
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)
# warnings are just warnings
set(warn_Werror "")
set(warn_WX "")
else()
# warnings are fatal errors; annoy developers to keep the source code warning-free
set(warn_Werror -Werror)
set(warn_WX -WX)
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
string(REGEX REPLACE "(^| )-O3( |$$)" "\\1-O2\\2" a "${CMAKE_C_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_CXX_FLAGS_RELEASE "${b}" CACHE STRING "Flags used by the CXX compiler during RELEASE builds." FORCE)
endif()
if(MSVC)
if(MSVC_FRONTEND OR WIN32 OR MINGW OR CYGWIN)
# disable silly warnings about using "deprecated" POSIX functions like fopen()
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# set __cplusplus according to selected C++ standard; use new preprocessor
add_definitions(-Zc:__cplusplus -Zc:preprocessor)
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"
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_definitions(-fno-delete-null-pointer-checks -fno-lifetime-dse)
endif()
add_definitions(-fno-strict-aliasing -fno-strict-overflow -funsigned-char)
upx_add_definitions(-fno-delete-null-pointer-checks -fno-lifetime-dse)
upx_add_definitions(-fno-strict-aliasing -fno-strict-overflow -funsigned-char)
# 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()
# compile a target with -O2 in Debug build
function(upx_compile_target_debug_with_O2 t)
if(MSVC)
# msvc uses some Debug compile options like -RTC1 that are incompatible with -O2
else()
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-O2>)
# examine MinGW/Cygwin compiler configuration
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
upx_print_mingw_symbols()
endif()
endfunction()
function(upx_sanitize_target t)
if(NOT UPX_CONFIG_DISABLE_SANITIZE AND NOT MSVC)
if(CMAKE_C_PLATFORM_ID MATCHES "^MinGW" OR MINGW OR CYGWIN)
# avoid link errors with current MinGW-w64 versions
# see https://www.mingw-w64.org/contribute/#sanitizers-asan-tsan-usan
#***********************************************************************
# 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")
if(NOT UPX_CONFIG_DISABLE_CXX_STANDARD)
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/try_compile/${f}"
OUTPUT_VARIABLE output CXX_STANDARD 17)
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:Release>:-fstack-protector>)
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/try_compile/${f}"
OUTPUT_VARIABLE output)
endif()
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()
endfunction()
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()
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2)
endif() # UPX_CONFIG_DISABLE_BZIP2
set(t upx_vendor_ucl)
target_include_directories(${t} PRIVATE vendor/ucl/include vendor/ucl)
upx_compile_target_debug_with_O2(${t})
upx_sanitize_target(${t})
if(MSVC)
target_compile_options(${t} PRIVATE -J -W4 ${warn_WX})
if(MSVC_FRONTEND)
target_compile_options(${t} PRIVATE ${warn_WN} ${warn_WX})
else()
target_compile_options(${t} PRIVATE ${warn_strict} ${warn_Werror})
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
endif()
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL)
set(t upx_vendor_zlib)
upx_compile_target_debug_with_O2(${t})
upx_sanitize_target(${t})
if(MSVC)
target_compile_options(${t} PRIVATE -DHAVE_STDARG_H -DHAVE_VSNPRINTF -J -W3 ${warn_WX})
else()
target_compile_options(${t} PRIVATE -DHAVE_STDARG_H -DHAVE_UNISTD_H -DHAVE_VSNPRINTF)
# clang-15: -Wno-strict-prototypes is needed to silence the new -Wdeprecated-non-prototype warning
target_compile_options(${t} PRIVATE -Wall -Wextra -Wvla -Wno-strict-prototypes ${warn_Werror})
target_compile_definitions(${t} PRIVATE HAVE_VSNPRINTF=1)
if(HAVE_UNISTD_H)
target_compile_definitions(${t} PRIVATE HAVE_UNISTD_H=1)
endif()
if(MSVC_FRONTEND)
target_compile_options(${t} PRIVATE -W3 ${warn_WX})
else()
target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-cast-align -Wno-cast-qual ${warn_Werror})
endif()
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZLIB)
if(NOT UPX_CONFIG_DISABLE_ZSTD)
set(t upx_vendor_zstd)
upx_compile_target_debug_with_O2(${t})
upx_sanitize_target(${t})
target_compile_options(${t} PRIVATE -DDYNAMIC_BMI2=0 -DZSTD_DISABLE_ASM)
if(MSVC)
target_compile_options(${t} PRIVATE -J -W4 ${warn_WX})
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_strict} ${warn_Werror})
endif()
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
endif()
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZSTD)
endif() # UPX_CONFIG_DISABLE_ZSTD
set(t upx)
target_include_directories(${t} PRIVATE vendor vendor/boost-pfr/include)
target_include_directories(${t} PRIVATE vendor)
target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
if(GITREV_SHORT)
target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}")
@@ -232,77 +383,104 @@ if(GITREV_SHORT)
target_compile_definitions(${t} PRIVATE UPX_VERSION_GIT_DESCRIBE="${GIT_DESCRIBE}")
endif()
endif()
#upx_compile_target_debug_with_O2(${t})
upx_sanitize_target(${t})
if(MSVC)
target_compile_options(${t} PRIVATE -EHsc -J -W4 ${warn_WX})
else()
target_compile_options(${t} PRIVATE ${warn_strict} ${warn_Werror})
if(Threads_FOUND)
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)
target_link_libraries(upx upx_vendor_zstd)
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()
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
endif()
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UPX)
#***********************************************************************
# "ctest"
# "make test"
# "ninja test"
# test
# ctest
# make test
# ninja test
#***********************************************************************
upx_cmake_include_hook(6_test)
if(NOT UPX_CONFIG_CMAKE_DISABLE_TEST)
include(CTest)
if(NOT CMAKE_CROSSCOMPILING)
if(NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
add_test(NAME upx-version COMMAND upx --version)
add_test(NAME upx-help COMMAND upx --help)
add_test(NAME upx-sysinfo COMMAND upx --sysinfo -v)
if(NOT UPX_CONFIG_DISABLE_SELF_PACK_TEST)
# IMPORTANT NOTE: these tests can only work if the host executable format is supported by UPX!
set(emu "")
if(DEFINED CMAKE_CROSSCOMPILING_EMULATOR)
set(emu "${CMAKE_CROSSCOMPILING_EMULATOR}")
endif()
if(NOT CMAKE_CROSSCOMPILING AND NOT UPX_CONFIG_DISABLE_SELF_PACK_TEST)
# NOTE: these tests can only work if the host executable format is supported by UPX!
function(upx_add_test)
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()
set(exe ${CMAKE_EXECUTABLE_SUFFIX})
set(exe "${CMAKE_EXECUTABLE_SUFFIX}")
set(upx_self_exe "$<TARGET_FILE:upx>")
set(fo "--force-overwrite")
upx_add_test(upx-self-pack upx -3 ${upx_self_exe} ${fo} -o upx-packed${exe})
upx_add_test(upx-self-pack-n2b upx -3 --nrv2b ${upx_self_exe} ${fo} -o upx-packed-n2b${exe})
upx_add_test(upx-self-pack-n2d upx -3 --nrv2d ${upx_self_exe} ${fo} -o upx-packed-n2d${exe})
upx_add_test(upx-self-pack-n2e upx -3 --nrv2e ${upx_self_exe} ${fo} -o upx-packed-n2e${exe})
upx_add_test(upx-self-pack-lzma upx -3 --lzma ${upx_self_exe} ${fo} -o upx-packed-lzma${exe})
upx_add_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_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_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_test(upx-unpack upx -d upx-packed${exe} ${fo} -o upx-unpacked${exe})
upx_add_test(upx-run-unpacked ./upx-unpacked${exe} --version-short)
upx_add_test(upx-run-packed ./upx-packed${exe} --version-short)
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() # UPX_CONFIG_CMAKE_DISABLE_TEST
#***********************************************************************
# "cmake --install ."
# "make install"
# "ninja 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
if(NOT CMAKE_INSTALL_PREFIX)
#message(FATAL_ERROR "ERROR: CMAKE_INSTALL_PREFIX is not defined.")
message(WARNING "WARNING: 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()
if(CMAKE_INSTALL_PREFIX)
include(GNUInstallDirs)
endif()
# install files
if(CMAKE_INSTALL_PREFIX AND DEFINED CMAKE_INSTALL_FULL_BINDIR)
install(TARGETS upx DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
install(FILES
COPYING LICENSE NEWS README THANKS 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}"
)
install(FILES doc/upx.1 DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man1")
@@ -311,39 +489,46 @@ 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/make/CMakeLists.maint.txt")
include("${CMAKE_CURRENT_SOURCE_DIR}/maint/make/CMakeLists.maint.txt")
endif()
upx_cmake_include_hook(8_summary)
function(print_var)
foreach(v ${ARGV})
if(${v})
message(STATUS "${v} = ${${v}}")
endif()
endforeach()
endfunction()
upx_print_var(CMAKE_VERSION UPX_CONFIG_CMAKE_MINIMUM_REQUIRED_VERSION CMAKE_GENERATOR)
if(NOT UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO)
print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION)
print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_CROSSCOMPILING)
print_var(CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION CMAKE_C_COMPILER_ARCHITECTURE_ID CMAKE_C_PLATFORM_ID CMAKE_C_COMPILER_ABI)
print_var(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_CXX_COMPILER_ARCHITECTURE_ID CMAKE_CXX_PLATFORM_ID CMAKE_CXX_COMPILER_ABI)
if(NOT ",${CMAKE_BINARY_DIR}," STREQUAL ",${CMAKE_CURRENT_BINARY_DIR}," OR NOT ",${CMAKE_SOURCE_DIR}," STREQUAL ",${CMAKE_CURRENT_SOURCE_DIR},")
upx_print_var(CMAKE_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_CURRENT_SOURCE_DIR)
endif()
upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_APPLE_SILICON_PROCESSOR)
upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_SYSTEM_PROCESSOR CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR)
upx_print_var(CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
upx_print_var(CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_AR CMAKE_RANLIB)
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(APPLE CYGWIN GNUC MINGW MSVC MSVC_FRONTEND MSVC_IDE UNIX WIN32 WIN64)
endif() # UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO
print_var(CMAKE_INSTALL_PREFIX CMAKE_CONFIGURATION_TYPES CMAKE_BUILD_TYPE)
if (CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$")
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()
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|None|Release)$")
message(WARNING "WARNING: unsupported CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}; please use \"Debug\" or \"Release\"")
endif()
if(NOT UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK)
# extra sanity checks to detect incompatible C vs CXX settings
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 UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK)
upx_platform_check_mismatch(CMAKE_C_PLATFORM_ID CMAKE_CXX_PLATFORM_ID)
upx_platform_check_mismatch(CMAKE_C_COMPILER_ABI CMAKE_CXX_COMPILER_ABI)
upx_platform_check_mismatch(CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
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:
+33 -147
View File
@@ -1,19 +1,21 @@
#
# UPX top-level Makefile - needs GNU make and CMake >= 3.13
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
#
# INFO: this Makefile is just a convenience wrapper for calling CMake
# NOTE: if you only have an older CMake 3.x then you can invoke cmake manually like this:
# HINT: if you only have an older CMake 3.x then you can invoke cmake manually like this:
# mkdir -p build/release
# cd build/release
# cmake ../..
# make -j (or use "cmake --build . --parallel")
# cmake ../.. # run config
# make -j # and run build
CMAKE = cmake
UPX_CMAKE_BUILD_FLAGS += --parallel
ifneq ($(VERBOSE),)
UPX_CMAKE_BUILD_FLAGS += --verbose
#UPX_CMAKE_BUILD_FLAGS += --verbose # requires CMake >= 3.14
UPX_CMAKE_CONFIG_FLAGS += -DCMAKE_VERBOSE_MAKEFILE=ON
endif
# enable this if you prefer Ninja for the actual builds:
#UPX_CMAKE_CONFIG_FLAGS += -G Ninja
@@ -22,14 +24,14 @@ endif
# default
#***********************************************************************
.DEFAULT_GOAL = 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 CMakeCache.txt already exists
run_config = $(if $(wildcard $1/CMakeCache.txt),,$(call run_cmake_config,$1,$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)
.DEFAULT_GOAL = build/release
build/debug: PHONY
$(call run_config,$@,Debug)
$(call run_build,$@,Debug)
@@ -38,149 +40,33 @@ build/release: PHONY
$(call run_config,$@,Release)
$(call run_build,$@,Release)
# shortcuts
all: build/debug build/release
debug: build/debug
release: build/release
.PHONY: PHONY
.NOTPARALLEL: # because the actual builds use "cmake --parallel"
.PHONY: PHONY
.SECONDEXPANSION:
.SUFFIXES:
# END of Makefile; extra stuff follows
# shortcuts (all => debug + release)
debug: build/debug PHONY
release: build/release PHONY
all build/all: build/debug build/release PHONY
build/%/all: $$(dir $$@)debug $$(dir $$@)release PHONY ;
#***********************************************************************
# extra builds: some pre-defined build configurations
#***********************************************************************
#
# END of Makefile
#
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 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 clang Static Analyzer (scan-build)
build/extra/scan-build/debug: PHONY; $(call run_config_and_build,$@,Debug)
build/extra/scan-build/release: PHONY; $(call run_config_and_build,$@,Release)
build/extra/scan-build/%: CMAKE := scan-build $(CMAKE)
build/extra/scan-build/%: export CCC_CC ?= clang
build/extra/scan-build/%: export CCC_CXX ?= clang++
# cross compiler: Linux glibc aarch64-linux-gnu
build/extra/cross-linux-aarch64/debug: PHONY; $(call run_config_and_build,$@,Debug)
build/extra/cross-linux-aarch64/release: PHONY; $(call run_config_and_build,$@,Release)
build/extra/cross-linux-aarch64/%: export CC = aarch64-linux-gnu-gcc
build/extra/cross-linux-aarch64/%: export CXX = aarch64-linux-gnu-g++
# cross compiler: Linux glibc arm-linux-gnueabihf
build/extra/cross-linux-arm/debug: PHONY; $(call run_config_and_build,$@,Debug)
build/extra/cross-linux-arm/release: PHONY; $(call run_config_and_build,$@,Release)
build/extra/cross-linux-arm/%: export CC = arm-linux-gnueabihf-gcc
build/extra/cross-linux-arm/%: export CXX = arm-linux-gnueabihf-g++ -Wno-psabi
# cross compiler: Windows x86 win32 MinGW
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
build/extra/cross-windows-mingw32/%: export CXX = i686-w64-mingw32-g++
# cross compiler: Windows x64 win64 MinGW
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
build/extra/cross-windows-mingw64/%: export CXX = x86_64-w64-mingw32-g++
# cross compiler: macOS arm64
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
# cross compiler: macOS x86_64
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
#***********************************************************************
# 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
build/xtarget/$(UPX_XTARGET)/%: export CXX
# shortcuts
xtarget/debug: build/xtarget/$(UPX_XTARGET)/debug
xtarget/release: build/xtarget/$(UPX_XTARGET)/release
# set new default
.DEFAULT_GOAL = xtarget/release
endif
endif
# extra pre-defined build configurations and some utility; optional
ifneq ($(MAKEFILE_LIST),)
include $(dir $(lastword $(MAKEFILE_LIST)))/misc/make/Makefile-extra.mk
else
include ./misc/make/Makefile-extra.mk
endif
#***********************************************************************
# check git submodules
#***********************************************************************
SUBMODULES = doctest lzma-sdk ucl valgrind zlib
dummy := $(foreach m,$(SUBMODULES),$(if $(wildcard vendor/$m/[CL]*),$m,\
$(error ERROR: missing git submodule $m; run 'git submodule update --init')))
# developer convenience
test:: build/all+test PHONY
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
+33 -9
View File
@@ -2,6 +2,31 @@
User visible changes for UPX
==================================================================
Changes in 4.2.3 (27 Mar 2024):
* bug fixes - see https://github.com/upx/upx/milestone/16
Changes in 4.2.2 (03 Jan 2024):
* bug fixes - see https://github.com/upx/upx/milestone/15
Changes in 4.2.1 (01 Nov 2023):
* 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
@@ -75,7 +100,7 @@ Changes in 3.08 (12 Dec 2011):
* 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).
* Better diagnostic when ELF -fPIC is needed.
* PT_NOTE improvements for *BSD.
* PT_NOTE improvements for BSD.
* Preserve more ELF .e_flags on ARM.
* Minor code improvements for ELF stubs.
* Defend against another flavor of corrupt PE header.
@@ -149,7 +174,7 @@ Changes in 2.92 beta (23 Jan 2007):
Changes in 2.91 beta (29 Nov 2006):
* 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
Changes in 2.90 beta (08 Oct 2006):
@@ -203,7 +228,7 @@ Changes in 1.95 beta (09 Apr 2006):
* win32/pe: really worked around R6002 runtime errors
Changes in 1.94 beta (11 Mar 2006):
* new format: added support for arm/pe (ARM executables running on WinCE)
* new format: added support for wince/arm (ARM executables running on WinCE)
* new format: added support for linux elf/amd64
* new format: added support for linux elf/ppc32
* new format: added support for mach/ppc32 (Apple Mac OS X)
@@ -255,7 +280,7 @@ Changes in 1.11 beta (20 Dec 2000):
==================================================================
Changes in 1.25 (29 Jun 2004)
* INFO: http://upx.sourceforge.net is the permanent UPX home page
* INFO: http://upx.sourceforge.net is the new UPX home page
* watcom/le: don't crash on files without relocations
* win32/pe: stricter checks of some PE values
* source code: much improved portability using ACC, the
@@ -520,12 +545,12 @@ Changes in 0.40 (05 Oct 1998)
* fixed a small but fatal bug in dos/sys introduced in 0.30
* fixed a rare bug in dos/exe
* worked around a bug in djgpp's strip 2.8
* djgpp/coff: Allegro packfile support should work now
* djgpp2/coff: Allegro packfile support should work now
* added dos/exeh compression method (works on 386+)
Changes in 0.30 (27 Jul 1998)
* 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 !
* the 16-bit uncompressors are a little bit shorter & faster
* fixed progress indicator for VESA and SVGA text modes
@@ -536,6 +561,5 @@ Changes in 0.20 (05 Jul 1998)
Changes in 0.05 (26 May 1998)
* first public beta release
# vim:set syntax=off tw=0 ts=4 sw=4 et: -*- coding: utf-8 -*-
* based on experience gained from our previous packers DJP (djgpp2/coff, 1996),
lzop (1996) and mfxpak (atari/tos, 1990)
+5 -5
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
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.
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
Public License. Full source code is available.
@@ -85,9 +85,9 @@ THE FUTURE
COPYRIGHT
=========
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2023 John F. Reiser
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
Copyright (C) 2000-2024 John F. Reiser
UPX is distributed with full source code under the terms of the
GNU General Public License v2+; either under the pure GPLv2+ (see
+36 -2
View File
@@ -44,7 +44,7 @@ Short overview
Tools needed to build/modify the UPX sources
--------------------------------------------
- A C++ compiler that supports C++ 17: clang-5, gcc-8 or msvc-2019 16.11
- 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
@@ -61,7 +61,7 @@ To compile the packer sources
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
- otherwise you will need:
@@ -71,6 +71,40 @@ If you want to modify the stub sources you'll also need
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
-----------
-5
View File
@@ -1,5 +0,0 @@
-std=gnu++17
-Ivendor
-fno-strict-aliasing
-fno-strict-overflow
-funsigned-char
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
https://upx.github.io
+5 -3
View File
@@ -1,5 +1,6 @@
#
# UPX doc Makefile - needs GNU make, pod2html, pod2man and pod2text
# UPX doc Makefile - needs GNU make, sed, pod2html, pod2man and pod2text
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
#
BUILT_SOURCES = upx.1 upx-doc.html upx-doc.txt
@@ -24,6 +25,9 @@ DETAB2 := sed -e 's/$(tab)/ /g'
#***********************************************************************
.DEFAULT_GOAL = all
.PHONY: PHONY
.SECONDEXPANSION:
.SUFFIXES:
all: $(BUILT_SOURCES) PHONY
@@ -34,7 +38,6 @@ mostlyclean clean distclean maintainer-clean: PHONY
# rules
#***********************************************************************
.SUFFIXES:
.SUFFIXES: .1 .html .man .pod .ps .tex .txt
%.1 : %.pod
@@ -68,4 +71,3 @@ mostlyclean clean distclean maintainer-clean: PHONY
$(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
.DELETE_ON_ERROR: $(BUILT_SOURCES)
.PHONY: PHONY
+4 -2
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
https://upx.github.io
@@ -41,12 +41,14 @@ Joergen Ibsen <jibz@hotmail.com> and d'b
for the relocation & address optimization ideas
John S. Fine <johnfine@erols.com>
for the new version of the dos/exe decompressor
Kornel Pal
for the EFI support
Lukundoo <Lukundoo@softhome.net>
for beta testing
Michael Devore
for initial dos/exe device driver support
Oleg V. Volkov <rover@lglobus.ru>
for various FreeBSD specific informations
for various FreeBSD specific information
The Owl & G-RoM
for the --compress-icons fix
Ralph Roth <RalphRoth@gmx.net>
+46 -44
View File
@@ -1,5 +1,5 @@
Decompressing ELF Directly to Memory on Linux/x86
Copyright (C) 2000-2023 John F. Reiser jreiser@BitWagon.com
Copyright (C) 2000-2024 John F. Reiser jreiser@BitWagon.com
References:
<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
program itself. So, the decompressor program (which contains the
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).
See src/p_lx_elf.cpp, function PackLinuxElf32::generateElfHdr.
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.
After linking, the decompressor code is converted to an initialized
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
startup and decompression subroutine of the decompressor itself,
saving a few hundred bytes. The startup code first decompresses the
rest of the decompressor, then jumps to it. A nonstandard linker
script src/stub/l_lx_elf86.lds places both the .text and .data
of the decompressor into the same PT_LOAD at 0x00401000. The
compressor includes the compressed bytes of the original executable
at the end of this first PT_LOAD.
script src/stub/src/i386-linux.elf-entry.lds arranges the SECTIONS
so that PackLinuxElf32x86::buildLoader() and buildLinuxLoader()
generate the desired stub code, which goes into PT_LOAD[1].
At runtime, the decompressed stub lives at 0x00400000. In order for the
decompressed stub to work properly at an address that is different
from its link-time address, the compiled code must contain no absolute
addresses. So, the data items in l_lx_elf.c must be only parameters
and automatic (on-stack) local variables; no global data, no static data,
and no string constants. Use "size l_le_n2b.o l_6e_n2b.o" to check
that both data and bss have length zero. Also, the '&' operator
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.
At runtime, the decompressed stub lives close beyond the brk().
In order for the decompressed stub to work properly at an address
that is different from its link-time address, the compiled code must
contain no absolute addresses. So, the data items in stub code
must be only parameters and automatic (on-stack) local variables;
no global data, no static data, and no string constants. Also,
the '&' operator may not be used to take the address of a function.
Decompression of the executable begins by decompressing the Elf32_Ehdr
and Elf32_Phdr, and then uses the Ehdr and Phdrs to control decompression
of the PT_LOAD segments.
Subroutine do_xmap() of src/stub/l_lx_elf.c performs the
and Elf32_Phdr, and then uses those Ehdr and Phdrs to control decompression
of the PT_LOAD segments. Subroutine do_xmap() of src/stub/src/
i386-linux.elf-main.c performs the
"virtual execve()" using the compressed data as source, and stores
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
and previous versions did this by default with no option. However,
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
page of the compressed executable. Pages below the usual .p_vaddr
0x8000 (32KiB) are rejected by the kernel. Using a page above the
original uncompressed brk(0) would require placing the entire initial
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.]
All of the above documentation refers to ET_EXEC main programs,
which always use the same virtual addresses. An ET_DYN executable
(main program or shared library) follows much the same scheme,
re-using the address space that the kernel chose originally.
Linux stores the pathname argument that was specified to execve()
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 file may be changed without affecting the pathname), but the
pathname does provide some information. The pathname may be relative
to the working directory, so look before any chdir().
to the working directory, so look before performing any chdir().
The Elf formats for Linux add an environment variable named " " [three
spaces] which saves the results of readlink("/proc/self/exe",,) before
the runtime stub unmaps all its pages. As of 2006-10-03 this works
for linux/elf386 and linux/ElfAMD.
On any page, then SELinux in strictest enforcing mode prohibits
simultaneous PROT_EXEC and PROT_WRITE, and also prohibits adding
PROT_EXEC if the kernel VMA struct (Virtual Memory Area struct)
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.
+6 -6
View File
@@ -22,7 +22,7 @@
<h1 id="ABSTRACT">ABSTRACT</h1>
<pre><code> The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar &amp; John Reiser
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar &amp; John Reiser
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>
@@ -160,7 +160,7 @@ Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar &amp; John Reiser
<p>Info: An &quot;overlay&quot; 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&#39;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&#39;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]
@@ -785,13 +785,13 @@ Jens Medoch &lt;jssg@users.sourceforge.net&gt;</code></pre>
<h1 id="COPYRIGHT">COPYRIGHT</h1>
<p>Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer</p>
<p>Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer</p>
<p>Copyright (C) 1996-2023 Laszlo Molnar</p>
<p>Copyright (C) 1996-2024 Laszlo Molnar</p>
<p>Copyright (C) 2000-2023 John F. Reiser</p>
<p>Copyright (C) 2000-2024 John F. Reiser</p>
<p>Copyright (C) 2002-2023 Jens Medoch</p>
<p>Copyright (C) 2002-2024 Jens Medoch</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>
+6 -6
View File
@@ -6,7 +6,7 @@ SYNOPSIS
ABSTRACT
The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
https://upx.github.io
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
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.
actually accesses this overlaid data.
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
@@ -818,13 +818,13 @@ AUTHORS
Jens Medoch <jssg@users.sourceforge.net>
COPYRIGHT
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Laszlo Molnar
Copyright (C) 2000-2023 John F. Reiser
Copyright (C) 2000-2024 John F. Reiser
Copyright (C) 2002-2023 Jens Medoch
Copyright (C) 2002-2024 Jens Medoch
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
Generated
+7 -7
View File
@@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "UPX 1"
.TH UPX 1 "2023-01-30" "upx 4.0.2" " "
.TH UPX 1 "2024-03-27" "upx 4.2.3" " "
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -147,7 +147,7 @@ upx \- compress or expand executable files
.IX Header "ABSTRACT"
.Vb 3
\& The Ultimate Packer for eXecutables
\& Copyright (c) 1996\-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
\& Copyright (c) 1996\-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
\& https://upx.github.io
.Ve
.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
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.
actually accesses this overlaid data.
.PP
.Vb 1
\& \-\-overlay=copy Copy any extra data attached to the file. [DEFAULT]
@@ -1019,13 +1019,13 @@ Please report all bugs immediately to the authors.
.Ve
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (C) 1996\-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996\-2024 Markus Franz Xaver Johannes Oberhumer
.PP
Copyright (C) 1996\-2023 Laszlo Molnar
Copyright (C) 1996\-2024 Laszlo Molnar
.PP
Copyright (C) 2000\-2023 John F. Reiser
Copyright (C) 2000\-2024 John F. Reiser
.PP
Copyright (C) 2002\-2023 Jens Medoch
Copyright (C) 2002\-2024 Jens Medoch
.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
+6 -6
View File
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
=head1 ABSTRACT
The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
Copyright (c) 1996-2024 Markus Oberhumer, Laszlo Molnar & John Reiser
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
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.
actually accesses this overlaid data.
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
@@ -932,13 +932,13 @@ Please report all bugs immediately to the authors.
=head1 COPYRIGHT
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Laszlo Molnar
Copyright (C) 2000-2023 John F. Reiser
Copyright (C) 2000-2024 John F. Reiser
Copyright (C) 2002-2023 Jens Medoch
Copyright (C) 2002-2024 Jens Medoch
B<UPX> is distributed with full source code under the terms of the
GNU General Public License v2+; either under the pure GPLv2+ (see
@@ -0,0 +1,22 @@
# for clang-tidy 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 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 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 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
...
+549
View File
@@ -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()
+316
View File
@@ -0,0 +1,316 @@
#
# 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_set_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_env_var) # ARGV
foreach(var_name ${ARGV})
if(DEFINED ENV{${var_name}})
if(NOT ",$ENV{${var_name}}," STREQUAL ",,")
message(STATUS "ENV{${var_name}} = $ENV{${var_name}}")
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__ __MSVCRT_VERSION__ _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()
# remove wildcard expansions from a variable
function(upx_remove_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}}")
foreach(file ${files})
list(REMOVE_ITEM result "${file}")
endforeach()
list(SORT result)
list(REMOVE_DUPLICATES result)
endif()
#message(STATUS "upx_remove_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}}) # check environment
if("$ENV{${var_name}}" MATCHES "^(0|1|OFF|ON|FALSE|TRUE)$")
set(value "$ENV{${var_name}}")
set(UPX_CACHE_ORIGIN_FROM_ENV_${var_name} TRUE CACHE INTERNAL "" FORCE) # for status message 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()
function(upx_platform_check_mismatch var_name_1 var_name_2)
if(DEFINED ${var_name_1} OR DEFINED ${var_name_2})
if(NOT ",${${var_name_1}}," STREQUAL ",${${var_name_2}},")
if(UPX_CONFIG_DISABLE_WERROR)
message(WARNING "WARNING: '${var_name_1}' '${var_name_2}' mismatch")
else()
message(FATAL_ERROR "FATAL ERROR: '${var_name_1}' '${var_name_2}' mismatch")
endif()
endif()
endif()
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()
# useful for CI jobs: allow target extra compile options
function(upx_add_target_extra_compile_options) # ARGV
set(t "${ARGV0}")
list(REMOVE_AT ARGV 0)
foreach(var_name ${ARGV})
if(NOT DEFINED ${var_name})
elseif(",${${var_name}}," STREQUAL ",,")
else()
set(flags "${${var_name}}")
if(NOT flags MATCHES ";") # NOTE: split into list from string only if not already a list
if(${CMAKE_VERSION} VERSION_GREATER "3.8.99")
separate_arguments(flags NATIVE_COMMAND "${flags}")
else()
separate_arguments(flags)
endif()
endif()
target_compile_options(${t} PRIVATE "${flags}")
endif()
endforeach()
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; note that this may require special run-time support libs from your 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:
+10
View File
@@ -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;
}
@@ -1,17 +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")"
# create the image from Dockerfile
# using a rootless Podman container
# NOTE: this image is based on rebuild-stubs-with-podman/upx-stubtools-20221212-v4,
# 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-20230115-v2
podman build -t "$image" -f "$argv0dir/Dockerfile" "$argv0dir"
podman image list "$image"
podman image tree "$image"
@@ -1,53 +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-cross-compile-20230115-v2
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 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
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 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/cross-compile-upx-with-podman/build-all-inside-container.sh
# after running that script we can do cool things like:
# cd /home/upx/src/upx/build/cross-compile-upx-with-podman/alpha-linux-gnu/debug
# qemu-alpha -L /usr/alpha-linux-gnu upx --version
# cd /home/upx/src/upx/build/cross-compile-upx-with-podman/hppa-linux-gnu/debug
# qemu-hppa -L /usr/hppa-linux-gnu upx --version
# (similar for many other architectures/builds)
@@ -1,54 +0,0 @@
# NOTE: this image is based on rebuild-stubs-with-podman/upx-stubtools-20221212-v4,
# 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-v4
ENV UPX_CONTAINER_IMAGE_NAME=upx-cross-compile-20230115-v2
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 \
&& 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 \
# 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 2000:2000
USER upx
@@ -1,93 +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")"
# 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
[[ -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 link errors with current MinGW-w64 versions
i686-w64-mingw32) cmake_config_flags=-DUPX_CONFIG_DISABLE_SANITIZE=ON ;;
x86_64-w64-mingw32) cmake_config_flags=-DUPX_CONFIG_DISABLE_SANITIZE=ON ;;
# 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-with-podman/$toolchain/${build_type,,}
mkdir -p $bdir
# run_config
if [[ ! -f $bdir/CMakeCache.txt ]]; then
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
+333
View File
@@ -0,0 +1,333 @@
#
# 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)
#***********************************************************************
# build and test
#***********************************************************************
CTEST = ctest
build/debug+test: $$(dir $$@)debug PHONY; cd "$(dir $@)debug" && $(CTEST)
build/%/debug+test: $$(dir $$@)debug PHONY; cd "$(dir $@)debug" && $(CTEST)
build/release+test: $$(dir $$@)release PHONY; cd "$(dir $@)release" && $(CTEST)
build/%/release+test: $$(dir $$@)release PHONY; cd "$(dir $@)release" && $(CTEST)
build/%/all+test: $$(dir $$@)debug+test $$(dir $$@)release+test PHONY ;
# shortcuts
debug+test: build/debug+test PHONY
release+test: build/release+test PHONY
all+test build/all+test: build/debug+test build/release+test PHONY
#***********************************************************************
# 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-pie
build/extra/clang-static-pie/debug: PHONY; $(call run_config_and_build,$@,Debug)
build/extra/clang-static-pie/release: PHONY; $(call run_config_and_build,$@,Release)
build/extra/clang-static-pie/%: export CC = clang -static-pie -fPIE -Wno-unused-command-line-argument
build/extra/clang-static-pie/%: export CXX = clang++ -static-pie -fPIE -Wno-unused-command-line-argument
# 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-pie
build/extra/gcc-static-pie/debug: PHONY; $(call run_config_and_build,$@,Debug)
build/extra/gcc-static-pie/release: PHONY; $(call run_config_and_build,$@,Release)
build/extra/gcc-static-pie/%: export CC = gcc -static-pie -fPIE
build/extra/gcc-static-pie/%: export CXX = g++ -static-pie -fPIE
# 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=0x0501
build/extra/cross-windows-mingw32/%: export CXX = i686-w64-mingw32-g++ -static -D_WIN32_WINNT=0x0501
build/extra/cross-windows-mingw32/%: CMAKE_SYSTEM_NAME ?= Windows
build/extra/cross-windows-mingw32/%: CMAKE_SYSTEM_PROCESSOR ?= X86
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=0x0501
build/extra/cross-windows-mingw64/%: export CXX = x86_64-w64-mingw32-g++ -static -D_WIN32_WINNT=0x0501
build/extra/cross-windows-mingw64/%: CMAKE_SYSTEM_NAME ?= Windows
build/extra/cross-windows-mingw64/%: CMAKE_SYSTEM_PROCESSOR ?= AMD64
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
build/extra/cross-darwin-arm64/%: CMAKE_SYSTEM_PROCESSOR ?= arm64
# 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
build/extra/cross-darwin-x86_64/%: CMAKE_SYSTEM_PROCESSOR ?= x86_64
#***********************************************************************
# 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/$(UPX_XTARGET)/debug: PHONY; $(call run_config_and_build,$@,Debug)
build/$(UPX_XTARGET)/release: PHONY; $(call run_config_and_build,$@,Release)
build/$(UPX_XTARGET)/%: export CC := $(CC)
build/$(UPX_XTARGET)/%: export CXX := $(CXX)
# shortcuts
xtarget/all: xtarget/debug xtarget/release PHONY
xtarget/debug: build/$(UPX_XTARGET)/debug PHONY
xtarget/release: build/$(UPX_XTARGET)/release PHONY
xtarget/all+test: xtarget/debug+test xtarget/release+test PHONY
xtarget/debug+test: build/$(UPX_XTARGET)/debug+test PHONY
xtarget/release+test: build/$(UPX_XTARGET)/release+test PHONY
# set new default
.DEFAULT_GOAL := build/$(UPX_XTARGET)/release
endif
endif
endif
#***********************************************************************
# assemble cmake config flags; useful for CI jobs
#
# 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
#***********************************************************************
ifneq ($(origin UPX_CMAKE_CONFIG_FLAGS),command line) # GNU make bug work-around
# GNU make bug, see https://savannah.gnu.org/bugs/index.php?64822
# and commit https://git.savannah.gnu.org/cgit/make.git/commit/?id=07187db947ba25e6c59b55f10660a04f8e9c5229
$(call check_undefined,__add_cmake_config)
__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_SYSTEM_PROCESSOR)
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)
# pass UPX extra compile options from environment/make to cmake; see CMakeLists.txt
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2)
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL)
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UPX)
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZLIB)
build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZSTD)
endif # GNU make 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
@@ -6,9 +6,11 @@ argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
# create the image from Dockerfile
# using a rootless Podman container
image=upx-stubtools-20221212-v4
image=upx-stubtools-20221212-v7
[[ $1 == --print-image ]] && echo "$image" && exit 0
podman build -t "$image" -f "$argv0dir/Dockerfile" "$argv0dir"
podman image list "$image"
echo
podman image tree "$image"
+40
View File
@@ -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'
@@ -6,12 +6,12 @@ argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
# run an interactive shell in the image
# using a rootless Podman container
image=upx-stubtools-20221212-v4
image="$("$argv0dir/10-create-image.sh" --print-image)"
flags=( -ti --read-only --rm )
flags=( --read-only --rm --pull=never )
flags+=( --cap-drop=all ) # drop all capabilities
flags+=( --network=none ) # no network needed
flags+=( -e TERM="$TERM" ) # pass $TERM
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 )
@@ -21,8 +21,10 @@ if [[ 1 == 1 ]]; then
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+=( -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
@@ -30,7 +32,11 @@ else
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
+66
View File
@@ -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 "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 4.2.2" \
&& 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
+659
View File
@@ -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.6 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.6 amd64 GNU assembler, linker and binary utilities
ii binutils-common:amd64 2.38-4ubuntu2.6 amd64 Common files for the GNU assembler, linker and binary utilities
ii binutils-x86-64-linux-gnu 2.38-4ubuntu2.6 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.2 amd64 cross-platform, open-source make system
ii cmake-data 3.22.1-1ubuntu1.22.04.2 all CMake data files (modules, templates and documentation)
ii coreutils 8.32-4.1ubuntu1.1 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.3 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.2 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.6 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.3 amd64 asynchronous name resolver
ii libc-bin 2.35-0ubuntu3.6 amd64 GNU C Library: Binaries
ii libc-dev-bin 2.35-0ubuntu3.6 amd64 GNU C Library: Development binaries
ii libc6-dev-i386 2.35-0ubuntu3.6 amd64 GNU C Library: 32-bit development libraries for AMD64
ii libc6-dev-x32 2.35-0ubuntu3.6 amd64 GNU C Library: X32 ABI Development Libraries for AMD64
ii libc6-dev:amd64 2.35-0ubuntu3.6 amd64 GNU C Library: Development Libraries and Header Files
ii libc6-i386 2.35-0ubuntu3.6 amd64 GNU C Library: 32-bit shared libraries for AMD64
ii libc6-x32 2.35-0ubuntu3.6 amd64 GNU C Library: X32 ABI Shared libraries for AMD64
ii libc6:amd64 2.35-0ubuntu3.6 amd64 GNU C Library: Shared libraries
ii libc6:i386 2.35-0ubuntu3.6 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.6 amd64 Compact C Type Format library (runtime, no BFD dependency)
ii libctf0:amd64 2.38-4ubuntu2.6 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.3 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.4 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.17+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.4 amd64 Pluggable Authentication Modules for PAM - helper binaries
ii libpam-modules:amd64 1.4.0-11ubuntu2.4 amd64 Pluggable Authentication Modules for PAM
ii libpam-runtime 1.4.0-11ubuntu2.4 all Runtime support for the PAM library
ii libpam0g:amd64 1.4.0-11ubuntu2.4 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.2 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.3 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.3 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.15 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.12 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.12 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-1ubuntu0.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.4 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-100.110 amd64 Linux Kernel Headers for development
ii login 1:4.8.1-2ubuntu2.2 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.15 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.2 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.2 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-3ubuntu0.1 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.2 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:
754392 ===== 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
13597 libc6 amd64
13038 libc6-dev amd64
12562 libc6-x32 amd64
12480 libc6 i386
12201 libc6-i386 amd64
11311 gdb amd64
10877 lib32stdc++-11-dev amd64
10431 binutils-x86-64-linux-gnu amd64
10390 libx32stdc++-11-dev amd64
9866 cmake-data all
8250 libc6-dev-x32 amd64
8119 libpython3.10-stdlib amd64
7948 lib32gcc-11-dev amd64
7734 perl-base amd64
7518 libasan6 amd64
7263 libc6-dev-i386 amd64
7255 libtsan0 amd64
7128 libmagic-mgc amd64
7104 coreutils amd64
6988 libx32gcc-11-dev amd64
6858 linux-libc-dev amd64
6733 dpkg amd64
6667 lib32asan6 amd64
6570 libx32asan6 amd64
5898 python3.10-minimal amd64
5833 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
3639 python2.7-minimal amd64
3552 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
996 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
377 unzip amd64
372 xz-utils amd64
368 libssh2-1 amd64
356 libnettle8 amd64
350 ninja-build amd64
348 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
253 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
-58
View File
@@ -1,58 +0,0 @@
FROM docker.io/library/ubuntu:22.04
ENV UPX_CONTAINER_IMAGE_NAME=upx-stubtools-20221212-v4
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 much more convenient and also allow building
# the full UPX binary inside the container via CMake:
7zip bfs bzip2 cmake curl elfutils fd-find file fzf g++ gdb gojq htop hyperfine \
jq libzstd-dev lsb-release lzip lzop ninja-build p7zip patch patchelf pax-utils \
ripgrep rsync screen universal-ctags unzip vim zip zlib1g-dev zsh zstd \
# extra packages for compiling with "gcc -m32" and and "gcc -mx32":
gcc-multilib g++-multilib \
&& true
# manually install compat libs from Ubuntu 16.04; REQUIRED
RUN cd /root \
&& aria2c --checksum=sha-256=de22baf3dd851a10e16fbf66a243e70149ca46e06b2939fdc79429196cefc090 \
'http://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 \
&& for v in 3.92 3.93 3.94 3.95 3.96 4.0.0 4.0.1 4.0.2; 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 3.92 3.93 3.94 3.95 3.96 4.0.0 4.0.1 4.0.2; 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 2000:2000
RUN useradd upx -U --uid 2000 --shell /bin/bash -m \
&& mkdir -p /home/upx/.cache/zig /home/upx/.local/bin /home/upx/src/upx \
&& ln -s /usr/local/bin/bin-upx-20221212 /home/upx/.local/bin/bin-upx \
&& chown -R upx:upx /home/upx \
&& true
USER upx
+1
View File
@@ -32,6 +32,7 @@ LC_ALL=C sort -z | xargs -0r perl -n -e '
}
if (m,\t,) {
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
elsif ($ARGV =~ m,\.mk$,) { }
elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { }
elsif ($ARGV =~ m,/src/stub/src/arch/.*/lzma\w+\.S$,) { }
else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); }
+1
View File
@@ -26,6 +26,7 @@ git ls-files --full-name -z | perl -0 -n -e '
}
if (m,\t,) {
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
elsif ($ARGV =~ m,\.mk$,) { }
elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { }
elsif ($ARGV =~ m,/src/stub/src/arch/.*/lzma\w+\.S$,) { }
else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); }
+41
View File
@@ -0,0 +1,41 @@
#! /usr/bin/env bash
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
# assemble cmake config flags; useful for CI jobs
# also see misc/make/Makefile-extra.mk
cmake_config_flags=()
__add_cmake_config() {
[[ -z "${!1}" ]] || cmake_config_flags+=( -D$1="${!1}" )
}
# pass common CMake settings from environment to cmake
for v in CMAKE_VERBOSE_MAKEFILE; do
__add_cmake_config $v
done
# pass common CMake toolchain settings from environment to cmake
for v in CMAKE_ADDR2LINE CMAKE_AR CMAKE_DLLTOOL CMAKE_LINKER CMAKE_NM CMAKE_OBJCOPY CMAKE_OBJDUMP CMAKE_RANLIB CMAKE_READELF CMAKE_STRIP CMAKE_TAPI; do
__add_cmake_config $v
done
# pass common CMake LTO toolchain settings from environment to cmake (for use with "-flto")
for v in CMAKE_C_COMPILER_AR CMAKE_C_COMPILER_RANLIB CMAKE_CXX_COMPILER_AR CMAKE_CXX_COMPILER_RANLIB; do
__add_cmake_config $v
done
# pass common CMake cross compilation settings from environment to cmake
for v in CMAKE_SYSTEM_NAME CMAKE_SYSTEM_PROCESSOR CMAKE_CROSSCOMPILING_EMULATOR; do
__add_cmake_config $v
done
# pass UPX config options from environment to cmake; see CMakeLists.txt
for v in UPX_CONFIG_DISABLE_GITREV UPX_CONFIG_DISABLE_SANITIZE UPX_CONFIG_DISABLE_WSTRICT UPX_CONFIG_DISABLE_WERROR UPX_CONFIG_DISABLE_SELF_PACK_TEST; do
__add_cmake_config $v
done
# pass UPX extra compile options from environment to cmake; see CMakeLists.txt
for v in UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2 UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UPX UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZLIB UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZSTD; do
__add_cmake_config $v
done
exec "${CMAKE:-cmake}" $UPX_CMAKE_CONFIG_FLAGS "${cmake_config_flags[@]}" "$@"
exit 99
@@ -2,11 +2,13 @@
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
#
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
#
# NOTE: we are using clang-format-15.0.6 from upx-stubtools
# see https://github.com/upx/upx-stubtools/releases
#
# NOTE: we use .clang-format config from upx.git/.clang-format
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
@@ -29,4 +31,4 @@ ulimit -v 1048576 || true
#echo $UPX_CLANG_FORMAT
exec "$UPX_CLANG_FORMAT" -style=file "$@"
exit 1
exit 99
+80
View File
@@ -0,0 +1,80 @@
#! /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
case "$UPX_CONFIG_DISABLE_SELF_PACK_TEST" in
"" | "0" | "FALSE" | "OFF") ;;
*) echo "Self-pack test disabled. All done."; exit 0 ;;
esac
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."
+401
View File
@@ -0,0 +1,401 @@
#! /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
case "$UPX_DEBUG_FORCE_PACK_MACOS" in
"" | "0") echo "$0: SKIPPED"; exit 0 ;;
esac
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
View File
@@ -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="\
afd8b4ec4379b013887e2dbb9cb07ed8e19942c6c5b72bd42fa20d2d43e35d52 *amd64-linux.elf/upx-3.91
320f5819d96f575ea4abad04c5a1bac53274a5d4704ff530ee778acfa261376c *amd64-linux.elf/upx-3.95
a8804bce00be8e2f9d3874c8fc884e69c19efc2f0fd07272e7d0749efd36f381 *amd64-win64.pe/upx-3.95.exe
80ff4e72220302cdccbdce753981d9a36596941ffcd9231317c5cb53f988ac72 *arm-linux.elf/upx-3.95
4e3db49fb086c4293b8a5809c166546d3a33f731b6ef5565cc0566d491f91cf2 *arm-wince.pe/upx-3.91.exe
71a27b41a763fab594ed953f3bf543489554b509bce488e7c5533e312c953e30 *arm64-linux.elf/upx-3.95
8a84b2161d83358c824de200ed480e9cb9cb7557138d710808ec44a19165c898 *armeb-linux.elf/upx-3.91
09b92d07b30b16321301aa2faf46576da2587c1334e7a842742fed36aadef5fa *armeb-linux.elf/upx-3.95
a418a4df498f55e86a7f2788c6e0fe0324d60a9032d4841569c7e4e2694410df *i386-dos32.djgpp2.coff/upx-3.91.exe
0aecdd97242054dcd390317e97a539a2e35f53a28a71d0148b703141d21345b0 *i386-dos32.djgpp2.coff/upx-3.95.exe
09a748c65d2a26975a5c829dd3d9f36e96607b1d9728d64068731815d8b82c36 *i386-linux.elf/upx-3.91
5189d860ddc1edc7e9b524aa09bd9677548d83efb788627cdbac27941f509262 *i386-linux.elf/upx-3.95
0b51fd861dd2b574bfed6ab3998b01333ae173fd76b7fd0d30187e75b09ab316 *i386-win32.pe/upx-3.91.exe
05568f9b47da0c8949080f66437f7a8d08c3c11f3ee5fb9e5d20a1324f2ab829 *i386-win32.pe/upx-3.95.exe
f6fb2f10a4f2b2d327c9868bb06241c3143771b0371ca564b8dfaeb180026298 *m68k-atari.tos/upx-3.91.ttp
196fb37ba72d7b0e081386a8110cf193678934ae1a0f16cd9d071b18c034a3f2 *mips-linux.elf/upx-3.95
e528a2c33b2ab882c6e18fab4662d612ffc71c0261c367fa9c0282b23ad53b3c *mipsel-linux.elf/upx-3.91
4b44c1b60f8eea0f40bcd2cdbc1e7217afee6d1cb054856e2791339aa7c31a78 *mipsel-linux.elf/upx-3.95
ae73bba4db8413a7a287b2a61dc9829ee3a66f9d93940ad7f08aa93b09770f4f *powerpc-linux.elf/upx-3.91
c7a8bba27dbd09c8f73ae2cd11d893187b15b298dd7d857cbd2c676670ff0a80 *powerpc-linux.elf/upx-3.95
6075bc28ac64f865d0e93cb16629c02331fb4abbea8da931288a60a6350cf635 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t120_compress_ucl_nrv2d_3_no_filter="\
f23ea1c7cea84e5edf136b2b3a0a8740e9d6bf3552ef1f460aa4508c2f27df6d *amd64-linux.elf/upx-3.91
e725f00542f605851cfe03aee2042fbccf04e0a01bbf5a4aaecd04ad59c80077 *amd64-linux.elf/upx-3.95
57af8f45cef9e5c9f63387a15b8cf1b96426ab8dc73c303bd4caaa95b093bf92 *amd64-win64.pe/upx-3.95.exe
a01ad023431e05287be77f160ea1a491489416e34de0d5ce194665e99f12e483 *arm-linux.elf/upx-3.95
a711a73bfd20ccc012507c3f07ed98ee025f55e441156efb5fdbaa1815640c63 *arm-wince.pe/upx-3.91.exe
4a341330a44845a10521d5acaa91eda3b7602367b1c77f6a5cf0731b528e478f *arm64-linux.elf/upx-3.95
d4a8653134f16f91b8fcdb0ed0d71ae3a31199af2ec42bf5dbe97e3344eceb74 *armeb-linux.elf/upx-3.91
a7da82c93f93a842a2876a54bba85cbb380eb7c79fc123ff30f31d99be3eca5c *armeb-linux.elf/upx-3.95
f1caf28b7500b14ca1405b31b8e18a226bf682c619982ea2712b5631cc61d0d8 *i386-dos32.djgpp2.coff/upx-3.91.exe
2c5ab68a6a23d460fab8def92a4cd32a54f084811584c1472c07dbe9429a503a *i386-dos32.djgpp2.coff/upx-3.95.exe
8f227074f8bc7682fd8e71bf96c60cb42fba7d3038acb8e500c6b075df50b732 *i386-linux.elf/upx-3.91
3df0f160a7d58a1f1368450c9db2d6911818e00b11ab819edbc56afeb84e3fb8 *i386-linux.elf/upx-3.95
31aaff6332ea65bb4c386de0bb75553cae77becd9a587dcbb51e38719c8a3b7a *i386-win32.pe/upx-3.91.exe
221a2c5c07d6c0a0127b3ce27d924fc36ee4b5af52fc4f47bc172e60ef0b244a *i386-win32.pe/upx-3.95.exe
9b280a1d2b82185339a4aea0c9338d9ae6c34d1a68da84a4a173d9010d092feb *m68k-atari.tos/upx-3.91.ttp
410335b935535fab6852d4b9677a24d016a9fb47d1b71d5a7967e99d1300ac15 *mips-linux.elf/upx-3.95
52746060c4c7971a4e786ba618896eebe9592f1b443c0d217d4e2cdb8b34fa8d *mipsel-linux.elf/upx-3.91
7367c89786c15b2d8305f41980b84addfddff69f2dae0f0572a88ffee6abe884 *mipsel-linux.elf/upx-3.95
4504c03dcc84be9f5ffc2279c4638c47a435a70c4748f1e25a738af33dc20720 *powerpc-linux.elf/upx-3.91
ef410a9cbd01c7c046f888417cb451aad8ebe4288aeb98319f689a030517d181 *powerpc-linux.elf/upx-3.95
da073cf9edf9d6efd0495d3f09101972541cdccd9df3c5a07df97e47ce1f77c3 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t130_compress_ucl_nrv2e_3_no_filter="\
1777841250f6b34fe7b75e2931b5154918abea5e7c47047f523ab15ed59e0658 *amd64-linux.elf/upx-3.91
9fefd378d92d1e370c450dd8d3f826248594ca7234aa6fccc83d20aa37694cdd *amd64-linux.elf/upx-3.95
b5a9eee9a774712899148a339cb8326e51a120355cb0dbb5a59f07ef4a149562 *amd64-win64.pe/upx-3.95.exe
e56b71096f08c30448f560ccd60e5bffcb1f14d5b84948005d9d707600e50311 *arm-linux.elf/upx-3.95
9e1c47059e892f73a4fa118a6b435d455613e4ff4b4ab3fb432dd45adcc06809 *arm-wince.pe/upx-3.91.exe
615437bd5f987fae39502999fc1fd6a8857cdbffa4001cba1b485a8ddd0dbd14 *arm64-linux.elf/upx-3.95
37dec03e64c74da1e194fb129231c5e87fb3398f4a4f1d269de9bc2487068a6a *armeb-linux.elf/upx-3.91
e45e09fca25c28cbd458c636ac1d060bc08bab37a6571880b6f32a6e26ecaff8 *armeb-linux.elf/upx-3.95
b941187968c86db8a01f106098996f2c0cd227da66003856c19e8b24438f446a *i386-dos32.djgpp2.coff/upx-3.91.exe
8194a6a0de66019d8aa7f49504ec7303f155a2dbcf29489300428fb1bb5d1b4a *i386-dos32.djgpp2.coff/upx-3.95.exe
4380ef64efadd605bc0908ac2d56ee7597e665850d2291f40f5acd978f4ecbf8 *i386-linux.elf/upx-3.91
f9bacd9bf3a1f84455f0c647f615827606fba5608996cbae65c07a06b7b9ef42 *i386-linux.elf/upx-3.95
71b7880ee783da6182fa1dcc5cc8662eb15b82c2e96ea827f2dca3c83d4040c2 *i386-win32.pe/upx-3.91.exe
629624e02dfa11c295e22989a09d5938c415ab2d32b7b4fdb009d3cc50c63933 *i386-win32.pe/upx-3.95.exe
5215eb51b80d7d0f428da49c3249eb2b5e937f8b3487f2e59eb31e7f1b9155ee *m68k-atari.tos/upx-3.91.ttp
e393bb54cb21d93d1b4ade1048204e4a9ed1bb0ca0517e54f42fddf8dc09a89d *mips-linux.elf/upx-3.95
7fd4a440ffa128a455b6e4a7864f75953a16fb593b5dc1b890c1ed111e80b021 *mipsel-linux.elf/upx-3.91
24357e6c79022919f181286d6ae5a8316078f30c01bbbb83169cd2794c7204ec *mipsel-linux.elf/upx-3.95
e37070c89617e9d155507662ee98d9f97a7c506317fdbe22797769a5738e75c5 *powerpc-linux.elf/upx-3.91
e2af43ea9cdc9f2e75de4c9a03ace0fabac9dcbfb54ea1b57031f2c860318663 *powerpc-linux.elf/upx-3.95
d7cf1e60f962094ce5b28e3e920ed4ba0b8b84daee896043f915ab036ed774c7 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t140_compress_lzma_2_no_filter="\
0744ab571ee5d8ca76d0be11d474611771e417a99598b051f1d8a3a791a91533 *amd64-linux.elf/upx-3.91
90660071ddb63165bf77f9175d3f9862d8626c085d932af2c2d66459a73cf409 *amd64-linux.elf/upx-3.95
9781094badb6013e8fd29caad2d7f369e79f60d5a5f66b547c2260e98b1c7d92 *amd64-win64.pe/upx-3.95.exe
9224db1973129ab654bfa9154689e2f1e99c7e5118dad9f143fa7b3e49abcb82 *arm-linux.elf/upx-3.95
961d61207958be48cccb37e5c0a111d85ff3e5d8fb6d5e0ca92e8681320a6f4b *arm-wince.pe/upx-3.91.exe
f044f8755d43dfd753327b6a5d1e69c8b73095fc12b3208be720ca2286a258c0 *arm64-linux.elf/upx-3.95
85e460829c5bc3bad8a7a7c82b2dfcd64594980b443972de1e52d15f644225cb *armeb-linux.elf/upx-3.91
4829edc4b97d2011e789272a4b8ad254d7df573a476bae5a71832e9aecbf0e7b *armeb-linux.elf/upx-3.95
902a9f177818e680042911e77d17de3f4bd3846fac210581ccaa7643dd1426f2 *i386-dos32.djgpp2.coff/upx-3.91.exe
665d3c278bb9a8e0cb28cffdf6a17c3c920052a2bf7d05b74413186b043ede28 *i386-dos32.djgpp2.coff/upx-3.95.exe
5ffc9d683e2e2050a7f4d6e03332de3754bb48efaf800e3dcd96678fcff6d15a *i386-linux.elf/upx-3.91
fbc487cf2343a2b277e5a1d469ea34b6b70ce609b2966ce6a372e004ae70a125 *i386-linux.elf/upx-3.95
9c35de99b53620cb09617061e7d01c31ff7a60f4bda7c4560b294ef18300c7f6 *i386-win32.pe/upx-3.91.exe
9430239c9d12e7d796fe2fa2de10bef21985841a0adf2357a4ca6b08cf08f989 *i386-win32.pe/upx-3.95.exe
e3d224960f13424eb4083a547eefd907e3384cfd2ebe6e8d6a8bd56181f5339b *m68k-atari.tos/upx-3.91.ttp
fa9c411562d1d580944274e744d5d63c2268b334ef754fef89a666938c8601ee *mips-linux.elf/upx-3.95
dd71cec3b4c14c462f58f26077193c8ec2a302aa37b4ae59a6c92ce2d493cccc *mipsel-linux.elf/upx-3.91
29c04c30ee8b3c2b4353d92b3e9ad5327af3d9f4439f2a93a08801bb456b7a2a *mipsel-linux.elf/upx-3.95
2c109762689cf8691dcc6ad952f27863dd0fc79bfa74883702dc3a4601784aa5 *powerpc-linux.elf/upx-3.91
2ad4441667860519efbd0cd60744ceadcce73e3019acd80e593917ce76b3cbf1 *powerpc-linux.elf/upx-3.95
970fe74533bd7b7c3bd7ddb300f982cde77227f2b1a69155a8dfb30366574d76 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t150_compress_ucl_2_all_filters="\
62e5a3fe8a9e2f7934194904ebfebd445e194b17fe3171c07d22017b3aa09419 *amd64-linux.elf/upx-3.91
351c778baa6826faf9661c7c5b8e8c0dd49a8aa5899f0107b2f5f7a4e3a69f3e *amd64-linux.elf/upx-3.95
3b943c943fe91b948e159c5687db6ff1b22acae0552d1cbf50a181750873f8d4 *amd64-win64.pe/upx-3.95.exe
cda2ba38e20f75623cea46cd75f604cd5466edd63cb9eafca64ea0fe765c69eb *arm-linux.elf/upx-3.95
dea0d13ec7b3f1208988d25c30e3bcd60bc013186a88cc82c998e86f320cad99 *arm-wince.pe/upx-3.91.exe
b748ca51f52811112aeea21aba9d0e59b67512d98b1e01f71c22bf4fe755304d *arm64-linux.elf/upx-3.95
57686ad3f48c7d950f866f534232693ecc3489f322bb8f1eaf78fbcbbc3bba4d *armeb-linux.elf/upx-3.91
c50c2f015491e40a8b687ae91827cf502e46e47dff21382b19c8e626388e5fe3 *armeb-linux.elf/upx-3.95
d597d829ef4beca9759c51b135f3cfd1e17c17c1d7cda04e9cb453e76742c9dc *i386-dos32.djgpp2.coff/upx-3.91.exe
ac0cc4beea08af6a39ec037d0b2a4e77d0951776e0f9ac945e8b0033b227cc30 *i386-dos32.djgpp2.coff/upx-3.95.exe
9204e3fabb4cca148a0d545f9ae3d7facd199edc570d4ce9b9794c4c7d8f46e3 *i386-linux.elf/upx-3.91
7953f12209c9838707898a73a79962764c01d7106c9c743e7437d996042811b5 *i386-linux.elf/upx-3.95
2e6dbebbae2997ae689c616221f7eecf72117d148783025363b99580df79fdad *i386-win32.pe/upx-3.91.exe
8d549e43950072ce5d271ecad25331e29a9886c4f034f150260af20f8a57feb9 *i386-win32.pe/upx-3.95.exe
d4eabc9adebd7edd40483f34ceb4081157c7542cdcea0f6b4b4dec640084fc6f *m68k-atari.tos/upx-3.91.ttp
d03d5702382fd391c61736a3dda350737590c05de07837aa3ac0eb23ff9e6d7a *mips-linux.elf/upx-3.95
431e8d80da56f51339a914c5bc4cf00242a7a8afbc4a77837888c42fb4888c3b *mipsel-linux.elf/upx-3.91
8a9722f82e89c2d83437503765b9e0798854b960839d3fa57e6ccd2f581ed352 *mipsel-linux.elf/upx-3.95
2bcf9a0b0245e807a4728f84ca134ab30371a91a2d247ed63ea80fbf4f6a44be *powerpc-linux.elf/upx-3.91
37b3f5e0a7973ca5143dea5fc7d116d759f662780ee0b809357554b21fd4bbb0 *powerpc-linux.elf/upx-3.95
04c9a8dfb2bc25327894045cc5b5f8325fb7fe90d77473ad08c5491c58b28988 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t160_compress_all_methods_1_no_filter="\
0c2dedc98ac535a39c4166db713ed6feb02680869d23cc734c40e4d4ee36c6b4 *amd64-linux.elf/upx-3.91
dc87386b6afd2a36ab6ca67139399f9de6b3d29edb1741b523236e596c625043 *amd64-linux.elf/upx-3.95
b75527ed6cfd8fa9b48a68e021545833790bc2817c2155cc5eeb97cb9d43cd5c *amd64-win64.pe/upx-3.95.exe
56416fe7d9100ebb3dddee598ce0844d1abfc6f006178b5fa05fc6d1d15e9a8c *arm-linux.elf/upx-3.95
3ea0a4cafa457a1bf86ddf659a57c5737c4fa79b4a0d161df1c55c7ff0fa5ad5 *arm-wince.pe/upx-3.91.exe
0fe74c52794dc63e8e92590413eea6aceb73a9cb9f34bed3eae9a8fc34aa5ef2 *arm64-linux.elf/upx-3.95
5eb71685d564fdc4e99d939e5b2d58d8a8341288bcde5eac06f465c68a61a40a *armeb-linux.elf/upx-3.91
08516cb6655f58965c4dea7c9227aac78e3bcffd8113062dd72118e074b3380e *armeb-linux.elf/upx-3.95
2a98332d1e82db93f7025dcf792d0e8924caf38fa9b4c22963841ab5e86d22ce *i386-dos32.djgpp2.coff/upx-3.91.exe
6939a695082de59e8993886c8213aaff1ca2ed1d7687404dd242796e27275a42 *i386-dos32.djgpp2.coff/upx-3.95.exe
0a866faf423e2c134f26ec705916b7ded0cdcb4c11fcb4e3b1ff75291d0b9d71 *i386-linux.elf/upx-3.91
523d569a0682728fa84312db03930d290b7f6ef71eb2222fd81ebeb4bcc16ffa *i386-linux.elf/upx-3.95
e1f8df77bb4591b1a68f7c110ed36ad778fef240ed52f9d3e511318a2d091e66 *i386-win32.pe/upx-3.91.exe
265f4c7045bae686897dd9981575a5ebeb99ab28233d66e9a8164789359f00d8 *i386-win32.pe/upx-3.95.exe
55732af6251cc6aa7bbb9c52415424a8cc4074288004a6064d9311a2ee01fddb *m68k-atari.tos/upx-3.91.ttp
138f3f2798f0cac9235011f14910ef6b079b908746d570a2ec631bb62d0f5917 *mips-linux.elf/upx-3.95
4f740937696b2d86a4bd89ec61d52338db4c739c71a8dde5cc6ff67f675304c6 *mipsel-linux.elf/upx-3.91
18b3320462c479420723407cc3aea2b07911a4c725b0c334e1d9585a51c86bf0 *mipsel-linux.elf/upx-3.95
c8f8974ebc401286910894d6751b0a13cd908d09b51e186e49e0c309ace3d282 *powerpc-linux.elf/upx-3.91
ad08eb6c4339cd8ec63c12dd8551ef10851dcce66be27d0f9fbb251003ef0f4b *powerpc-linux.elf/upx-3.95
fb0fa7d60c542653e7d3448f2aa69e7c2ed5aaebf3845d5aa5f10c5bff2ee279 *powerpc64le-linux.elf/upx-3.95
"
expected_sha256sums__t170_compress_all_methods_no_lzma_5_no_filter="\
3a5098207aa95f40fd8a62a6a79f416837f69bf0a1ac729264fbee72d1fae0f6 *amd64-linux.elf/upx-3.91
4748b6f0bb08e1417dc62cff1c049eb2ee993717be4f9f5359fc7454e736def2 *amd64-linux.elf/upx-3.95
9fc18a2ec177ff3b48b5d299828e3275be1585db6c205ec5652e3d13f4d91eda *amd64-win64.pe/upx-3.95.exe
d90b9a2f71107025885e289633ef9e7942f494a7f8aa0e0597e79664b09ad034 *arm-linux.elf/upx-3.95
f03a3f07787765e499ad5a60f7c576598f433ba9a1f4d7158b0923f510929142 *arm-wince.pe/upx-3.91.exe
d01b573be7bb79257c3e0637f38a7fe8940e9302c7391fbc4a75664219a5522c *arm64-linux.elf/upx-3.95
085600cfffbe1d9e0c1bc25a3e48bbf3130b023b49ccbca001db27b4881e6246 *armeb-linux.elf/upx-3.91
a7923c6b78b9d3d58ee4f1bc42861476a57bb9935af47d2a15e048efb642f5d4 *armeb-linux.elf/upx-3.95
0970d5a8ee6c819e11b2bd889c7ee908403af2adf3542f7670ed92eb51090485 *i386-dos32.djgpp2.coff/upx-3.91.exe
e2d6b3c8de85bdc7b0262f64c1a16c9d41695a92e6f374cc9f12e87ca78fd956 *i386-dos32.djgpp2.coff/upx-3.95.exe
9e28e20b115e4a671b3f4006934b94fd59fcd48dc36311a479dda6bc1ccebe07 *i386-linux.elf/upx-3.91
910401db763c9a0bcb8e4d1b9cf1ee476c034b94b54a9350bcd303a5487085ef *i386-linux.elf/upx-3.95
0a413298c461facb93048106cfd261d72192443e6d2d313f2b48dbdf6537b22a *i386-win32.pe/upx-3.91.exe
684a0e0309d062e3fb7a1fabbdb7b2be45d3bde6a9a030f8a45fcc369a066efa *i386-win32.pe/upx-3.95.exe
3ea4fe59d58b92fe0b0e41662c15c40130d72ed30425871d572a8c06c3c27bbf *m68k-atari.tos/upx-3.91.ttp
e098036f912764f9dcef7377d17fe15b4f21439303306f9c84838d35fe655530 *mips-linux.elf/upx-3.95
df4106be954d5233644a3d761a9f899132f052741d16e1d793ae481aafd51caa *mipsel-linux.elf/upx-3.91
4c87f94f926aedbe17bf2d7ef72873506bbae75b8abf51a6775eb4b2e0ac0d96 *mipsel-linux.elf/upx-3.95
4c6b2ca8ed7bbe6b9705f02a26781e6d93ab2a1011c119283130a738df5e47eb *powerpc-linux.elf/upx-3.91
ccecc0acef4c430a8871704f93280a17bff518267499f05ba89a5290ba654a89 *powerpc-linux.elf/upx-3.95
86123a78b0ff91321acbc837874034c099443f77ff62848e338bb61c0888e1c6 *powerpc64le-linux.elf/upx-3.95
"
########## end .sha256sums.recreate
+335
View File
@@ -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
+41
View File
@@ -0,0 +1,41 @@
#
# valgrind suppressions for musl libc
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
#
# musl malloc
{
musl-malloc-enframe
Memcheck:Cond
fun:enframe
}
# these are only needed for older musl versions
{
musl-malloc-mal0_clear
Memcheck:Cond
fun:mal0_clear
fun:calloc
}
{
musl-string-memchr
Memcheck:Cond
fun:memchr
}
{
musl-string-stpcpy
Memcheck:Cond
fun:stpcpy
}
{
musl-string-strchrnul
Memcheck:Cond
fun:strchrnul
}
{
musl-string-strlen
Memcheck:Cond
fun:strlen
}
+69 -64
View File
@@ -1,49 +1,48 @@
#
# 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
# directly use the CMake build instead!
MAKEFLAGS += -r
.SUFFIXES:
export SHELL = /bin/sh
# NOTE: this Makefile is deprecated - please directly use
# the top-level CMake build instead.
ifndef srcdir
srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,' || echo 'ERROR')
srcdir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
endif
ifndef top_srcdir
top_srcdir := $(srcdir)/..
endif
#
#***********************************************************************
# redirect to top-level CMake build
#
#***********************************************************************
.DEFAULT_GOAL = build/debug
build/debug: $(top_srcdir)/build/debug/upx
build/release: $(top_srcdir)/build/release/upx
# shortcuts
all: build/debug build/release
debug: build/debug
release: build/release
$(top_srcdir)/build/debug/upx: PHONY
$(MAKE) -C $(top_srcdir) build/debug
$(top_srcdir)/build/release/upx: PHONY
$(MAKE) -C $(top_srcdir) build/release
# NOTE that the top-level Makefile .DEFAULT_GOAL is build/release
.DEFAULT_GOAL = build/all
.NOTPARALLEL: # because the actual builds use "cmake --parallel"
.PHONY: PHONY
.NOTPARALLEL:
.SECONDEXPANSION:
.SUFFIXES:
#
# "make run-testsuite"
#
build/debug build/release build/all: PHONY; $(MAKE) -C $(top_srcdir) $@
build/debug+test build/release+test build/all+test: PHONY; $(MAKE) -C $(top_srcdir) $@
# shortcuts
debug release all: PHONY; $(MAKE) -C $(top_srcdir) $@
debug+test release+test all+test: PHONY; $(MAKE) -C $(top_srcdir) $@
# search for the UPX testsuite -- git clone https://github.com/upx/upx-testsuite.git
# you also can override upx_testsuite_SRCDIR
test:: build/all+test PHONY
# OLD target names [deprecated]
$(top_srcdir)/build/debug: build/debug PHONY
$(top_srcdir)/build/release: build/release PHONY
#***********************************************************************
# make run-testsuite
# git clone https://github.com/upx/upx-testsuite.git
#***********************************************************************
# search for the UPX testsuite; you can override by setting "upx_testsuite_SRCDIR"
ifndef upx_testsuite_SRCDIR
# search standard locations below $(top_srcdir)
ifneq ($(wildcard $(top_srcdir)/../upx--upx-testsuite.git/files/packed/.),)
@@ -56,51 +55,57 @@ endif
endif
# run the UPX testsuite
# The expected (old) checksums are in $(top_srcdir)/.github/travis_testsuite_1-expected_sha256sums.sh
# The actual (new) checksums are in ./tmp-testsuite/testsuite_1/.sha256sums.recreate
# The expected (old) checksums are in $(top_srcdir)/misc/testsuite/upx_testsuite_1-expected_sha256sums.sh
# The actual (new) checksums are in ./tmp-upx-testsuite-*/testsuite_1/.sha256sums.recreate
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
ifneq ($(wildcard $(top_srcdir)/.github/travis_testsuite_1.sh),)
run-testsuite: run-testsuite-release
ifneq ($(wildcard $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh),)
run-testsuite: run-testsuite-release PHONY
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-debug: export upx_exe := $(top_srcdir)/build/debug/upx
run-testsuite-debug: PHONY $(top_srcdir)/build/debug/upx
time -p bash $(top_srcdir)/.github/travis_testsuite_1.sh
run-testsuite-debug: build/debug PHONY
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: PHONY $(top_srcdir)/build/release/upx
time -p bash $(top_srcdir)/.github/travis_testsuite_1.sh
run-testsuite-release: build/release PHONY
time -p bash $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh
endif
endif
#
# "make clang-format"
#
#***********************************************************************
# make check-whitespace
#***********************************************************************
# automatically format some C++ source code files
ifeq ($(shell uname),Linux)
# Markus loves clang-format, but John hates it; find a compromise
CLANG_FORMAT_EXCLUDE_FILES += conf.h miniacc.h version.h help.cpp
CLANG_FORMAT_EXCLUDE_FILES += p_elf.h p_elf_enum.h p_lx_% p_mach% p_unix% p_vmli%
CLANG_FORMAT_EXCLUDE_FILES += packer_c.cpp packer_f.cpp
CLANG_FORMAT_EXCLUDE_FILES += compress/compress.h filter/filter_impl.cpp
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* [cu]*/*.[ch]*))
CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))
clang-format: PHONY $(CLANG_FORMAT_FILES)
@echo "running upx-clang-format"
@$(top_srcdir)/misc/scripts/upx-clang-format -i $(CLANG_FORMAT_FILES)
endif
ifneq ($(wildcard /usr/bin/env),) # need Unix utils like bash, perl, sed, xargs, etc.
#
# "make check-whitespace"
#
CHECK_WHITESPACE =
ifeq ($(shell uname),Linux)
CHECK_WHITESPACE = $(top_srcdir)/misc/scripts/check_whitespace.sh $(top_srcdir)
CHECK_WHITESPACE = bash $(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)
CHECK_WHITESPACE = bash $(top_srcdir)/misc/scripts/check_whitespace_git.sh $(top_srcdir)
endif
check-whitespace: PHONY; $(CHECK_WHITESPACE)
endif
endif # /usr/bin/env
#***********************************************************************
# make clang-format
#***********************************************************************
# automatically format some C++ source code files
ifneq ($(wildcard /usr/bin/env),)
ifeq ($(shell uname),Linux)
# Markus loves clang-format, but John hates it; find a compromise
CLANG_FORMAT_EXCLUDE_FILES += stub/%.h util/miniacc.h
CLANG_FORMAT_EXCLUDE_FILES += p_lx_% p_mach% p_unix% p_vmlin%
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*))
CLANG_FORMAT_FILES += $(sort $(wildcard stub/tools/*/*.[ch]*))
CLANG_FORMAT_FILES += $(sort $(wildcard ../misc/cmake/try_compile/*.[ch]*))
CLANG_FORMAT_FILES := $(sort $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES)))
clang-format: $(CLANG_FORMAT_FILES) PHONY
@echo "running upx-clang-format"
@bash $(top_srcdir)/misc/scripts/upx-clang-format.sh -i $(CLANG_FORMAT_FILES)
endif # Linux
endif # /usr/bin/env
# vim:set ts=8 sw=8 noet:
+369 -189
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -26,47 +26,120 @@
*/
#pragma once
#ifndef UPX_BELE_H__
#define UPX_BELE_H__ 1
// BE - Big 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)
#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 !(DEBUG)
// 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>
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>
inline constexpr bool is_xe24_type = upx::is_same_any_v<T, void, char, byte>;
template <class T>
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>
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
**************************************************************************/
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_memcpy_inline(&v, p, sizeof(v));
return v;
}
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_memcpy_inline(&v, p, sizeof(v));
return v;
}
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_memcpy_inline(&v, p, sizeof(v));
return v;
}
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_memcpy_inline(p, &v, sizeof(v));
}
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_memcpy_inline(p, &v, sizeof(v));
}
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_memcpy_inline(p, &v, sizeof(v));
}
@@ -79,31 +152,46 @@ static forceinline void set_ne64(void *p, upx_uint64_t vv) {
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4)
// unfortunately *not* constexpr with MSVC
static forceinline unsigned bswap16(unsigned v) { return (unsigned) _byteswap_ulong(v << 16); }
static forceinline unsigned bswap32(unsigned v) { return (unsigned) _byteswap_ulong(v); }
static forceinline upx_uint64_t bswap64(upx_uint64_t v) { return _byteswap_uint64(v); }
// unfortunately *not* constexpr with current MSVC
static forceinline /*constexpr*/ unsigned bswap16(unsigned v) noexcept {
return (unsigned) _byteswap_ulong(v << 16);
}
static forceinline /*constexpr*/ unsigned bswap32(unsigned v) noexcept {
return (unsigned) _byteswap_ulong(v);
}
static forceinline /*constexpr*/ upx_uint64_t bswap64(upx_uint64_t v) noexcept {
return _byteswap_uint64(v);
}
#else
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 (unsigned) __builtin_bswap64((upx_uint64_t) v << 48);
return __builtin_bswap32(v << 16);
#endif
}
static forceinline constexpr unsigned bswap32(unsigned v) {
// return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
static forceinline constexpr unsigned bswap32(unsigned v) noexcept {
#if defined(__riscv) && __riscv_xlen == 64
return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
#else
return __builtin_bswap32(v);
#endif
}
static forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v) noexcept {
return __builtin_bswap64(v);
}
static forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v) { return __builtin_bswap64(v); }
#endif
static forceinline constexpr unsigned no_bswap16(unsigned v) {
return v & 0xffff; // needed so that this is equivalent to bswap16() above
static forceinline constexpr unsigned no_bswap16(unsigned v) noexcept {
// 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) { return v; }
static forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) { return v; }
static forceinline constexpr unsigned no_bswap32(unsigned v) noexcept { return v; }
static forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) noexcept { return v; }
#if (ACC_ABI_BIG_ENDIAN)
#define ne16_to_be16(v) no_bswap16(v)
@@ -125,114 +213,154 @@ static forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) { return v;
// get/set 16/32/64
**************************************************************************/
inline unsigned get_be16(const void *p) { return ne16_to_be16(get_ne16(p)); }
inline unsigned get_be32(const void *p) { return ne32_to_be32(get_ne32(p)); }
inline upx_uint64_t get_be64(const void *p) { return ne64_to_be64(get_ne64(p)); }
inline unsigned get_le16(const void *p) { return ne16_to_le16(get_ne16(p)); }
inline unsigned get_le32(const void *p) { return ne32_to_le32(get_ne32(p)); }
inline upx_uint64_t get_le64(const void *p) { return ne64_to_le64(get_ne64(p)); }
inline void set_be16(void *p, unsigned v) { set_ne16(p, ne16_to_be16(v)); }
inline void set_be32(void *p, unsigned v) { set_ne32(p, ne32_to_be32(v)); }
inline void set_be64(void *p, upx_uint64_t v) { set_ne64(p, ne64_to_be64(v)); }
inline void set_le16(void *p, unsigned v) { set_ne16(p, ne16_to_le16(v)); }
inline void set_le32(void *p, unsigned v) { set_ne32(p, ne32_to_le32(v)); }
inline void set_le64(void *p, upx_uint64_t v) { set_ne64(p, ne64_to_le64(v)); }
REQUIRE_XE16
inline unsigned get_be16(const XE16 *p) noexcept { return ne16_to_be16(get_ne16(p)); }
REQUIRE_XE32
inline unsigned get_be32(const XE32 *p) noexcept { return ne32_to_be32(get_ne32(p)); }
REQUIRE_XE64
inline upx_uint64_t get_be64(const XE64 *p) noexcept { return ne64_to_be64(get_ne64(p)); }
REQUIRE_XE16
inline unsigned get_le16(const XE16 *p) noexcept { return ne16_to_le16(get_ne16(p)); }
REQUIRE_XE32
inline unsigned get_le32(const XE32 *p) noexcept { return ne32_to_le32(get_ne32(p)); }
REQUIRE_XE64
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
**************************************************************************/
inline unsigned get_be24(const void *p) {
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
REQUIRE_XE24
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);
}
inline unsigned get_le24(const void *p) {
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
REQUIRE_XE24
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);
}
inline void set_be24(void *p, unsigned v) {
unsigned char *b = ACC_PCAST(unsigned char *, p);
b[0] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
b[2] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
REQUIRE_XE24
inline void set_be24(XE24 *p, unsigned v) noexcept {
byte *b = ACC_PCAST(byte *, p);
b[0] = ACC_ICONV(byte, (v >> 16) & 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) {
unsigned char *b = ACC_PCAST(unsigned char *, p);
b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
b[2] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
REQUIRE_XE24
inline void set_le24(XE24 *p, unsigned v) noexcept {
byte *b = ACC_PCAST(byte *, p);
b[0] = ACC_ICONV(byte, (v >> 0) & 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; }
REQUIRE_XE32
inline unsigned get_le26(const XE32 *p) noexcept { return get_le32(p) & 0x03ffffff; }
REQUIRE_XE32
inline unsigned get_le19_5(const XE32 *p) noexcept { return (get_le32(p) >> 5) & 0x0007ffff; }
REQUIRE_XE32
inline unsigned get_le14_5(const XE32 *p) noexcept { return (get_le32(p) >> 5) & 0x00003fff; }
inline void set_le26(void *p, unsigned v) {
REQUIRE_XE32
inline void set_le26(XE32 *p, unsigned v) noexcept {
// preserve the top 6 bits
#if 0
set_le32(p, (get_le32(p) & 0xfc000000) | (v & 0x03ffffff));
#else
// set_le32(p, (get_le32(p) & 0xfc000000) | (v & 0x03ffffff));
// optimized version, saving a runtime bswap32
set_ne32(p, (get_ne32(p) & ne32_to_le32(0xfc000000)) |
(ne32_to_le32(v) & ne32_to_le32(0x03ffffff)));
#endif
}
REQUIRE_XE32
inline void set_le19_5(XE32 *p, unsigned v) noexcept {
set_le32(p, (get_le32(p) & 0xff00001f) | ((v & 0x0007ffff) << 5));
}
REQUIRE_XE32
inline void set_le14_5(XE32 *p, unsigned v) noexcept {
set_le32(p, (get_le32(p) & 0xfff8001f) | ((v & 0x00003fff) << 5));
}
/*************************************************************************
// get signed values
**************************************************************************/
static forceinline int sign_extend(unsigned v, unsigned bits) {
static forceinline constexpr int sign_extend(unsigned v, unsigned bits) noexcept {
#if (ACC_ARCH_M68K) // no barrel shifter
const unsigned sign_bit = 1u << (bits - 1);
v &= sign_bit | (sign_bit - 1);
v |= 0 - (v & sign_bit);
return ACC_ICAST(int, v);
return ACC_ICAST(int, (v & (sign_bit - 1)) - (v & sign_bit));
#else
return ACC_ICAST(int, v << (32 - bits)) >> (32 - bits);
#endif
}
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 {
#if (ACC_ARCH_M68K) // no barrel shifter
const upx_uint64_t sign_bit = 1ull << (bits - 1);
v &= sign_bit | (sign_bit - 1);
v |= 0 - (v & sign_bit);
return ACC_ICAST(upx_int64_t, v);
return ACC_ICAST(upx_int64_t, (v & (sign_bit - 1)) - (v & sign_bit));
#else
return ACC_ICAST(upx_int64_t, v << (64 - bits)) >> (64 - bits);
#endif
}
inline int get_be16_signed(const void *p) {
REQUIRE_XE16
inline int get_be16_signed(const XE16 *p) noexcept {
unsigned v = get_be16(p);
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);
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);
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);
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);
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);
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);
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);
return sign_extend(v, 64);
}
@@ -248,368 +376,380 @@ inline upx_int64_t get_le64_signed(const void *p) {
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
**************************************************************************/
struct alignas(1) BE16 {
struct alignas(1) BE16 final {
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
unsigned char d[2];
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);
return *this;
}
BE16 &operator+=(unsigned v) {
BE16 &operator+=(unsigned v) noexcept {
set_be16(d, get_be16(d) + v);
return *this;
}
BE16 &operator-=(unsigned v) {
BE16 &operator-=(unsigned v) noexcept {
set_be16(d, get_be16(d) - v);
return *this;
}
BE16 &operator*=(unsigned v) {
BE16 &operator*=(unsigned v) noexcept {
set_be16(d, get_be16(d) * v);
return *this;
}
BE16 &operator/=(unsigned v) {
BE16 &operator/=(unsigned v) noexcept {
set_be16(d, get_be16(d) / v);
return *this;
}
BE16 &operator&=(unsigned v) {
BE16 &operator&=(unsigned v) noexcept {
set_be16(d, get_be16(d) & v);
return *this;
}
BE16 &operator|=(unsigned v) {
BE16 &operator|=(unsigned v) noexcept {
set_be16(d, get_be16(d) | v);
return *this;
}
BE16 &operator^=(unsigned v) {
BE16 &operator^=(unsigned v) noexcept {
set_be16(d, get_be16(d) ^ v);
return *this;
}
BE16 &operator<<=(unsigned v) {
BE16 &operator<<=(unsigned v) noexcept {
set_be16(d, get_be16(d) << v);
return *this;
}
BE16 &operator>>=(unsigned v) {
BE16 &operator>>=(unsigned v) noexcept {
set_be16(d, get_be16(d) >> v);
return *this;
}
operator unsigned() const { return get_be16(d); }
bool operator<(const BE16 &v) const { return unsigned(*this) < unsigned(v); }
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); }
};
struct alignas(1) BE32 {
struct alignas(1) BE32 final {
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
unsigned char d[4];
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);
return *this;
}
BE32 &operator+=(unsigned v) {
BE32 &operator+=(unsigned v) noexcept {
set_be32(d, get_be32(d) + v);
return *this;
}
BE32 &operator-=(unsigned v) {
BE32 &operator-=(unsigned v) noexcept {
set_be32(d, get_be32(d) - v);
return *this;
}
BE32 &operator*=(unsigned v) {
BE32 &operator*=(unsigned v) noexcept {
set_be32(d, get_be32(d) * v);
return *this;
}
BE32 &operator/=(unsigned v) {
BE32 &operator/=(unsigned v) noexcept {
set_be32(d, get_be32(d) / v);
return *this;
}
BE32 &operator&=(unsigned v) {
BE32 &operator&=(unsigned v) noexcept {
set_be32(d, get_be32(d) & v);
return *this;
}
BE32 &operator|=(unsigned v) {
BE32 &operator|=(unsigned v) noexcept {
set_be32(d, get_be32(d) | v);
return *this;
}
BE32 &operator^=(unsigned v) {
BE32 &operator^=(unsigned v) noexcept {
set_be32(d, get_be32(d) ^ v);
return *this;
}
BE32 &operator<<=(unsigned v) {
BE32 &operator<<=(unsigned v) noexcept {
set_be32(d, get_be32(d) << v);
return *this;
}
BE32 &operator>>=(unsigned v) {
BE32 &operator>>=(unsigned v) noexcept {
set_be32(d, get_be32(d) >> v);
return *this;
}
operator unsigned() const { return get_be32(d); }
bool operator<(const BE32 &v) const { return unsigned(*this) < unsigned(v); }
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); }
};
struct alignas(1) BE64 {
struct alignas(1) BE64 final {
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
unsigned char d[8];
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);
return *this;
}
BE64 &operator+=(upx_uint64_t v) {
BE64 &operator+=(upx_uint64_t v) noexcept {
set_be64(d, get_be64(d) + v);
return *this;
}
BE64 &operator-=(upx_uint64_t v) {
BE64 &operator-=(upx_uint64_t v) noexcept {
set_be64(d, get_be64(d) - v);
return *this;
}
BE64 &operator*=(upx_uint64_t v) {
BE64 &operator*=(upx_uint64_t v) noexcept {
set_be64(d, get_be64(d) * v);
return *this;
}
BE64 &operator/=(upx_uint64_t v) {
BE64 &operator/=(upx_uint64_t v) noexcept {
set_be64(d, get_be64(d) / v);
return *this;
}
BE64 &operator&=(upx_uint64_t v) {
BE64 &operator&=(upx_uint64_t v) noexcept {
set_be64(d, get_be64(d) & v);
return *this;
}
BE64 &operator|=(upx_uint64_t v) {
BE64 &operator|=(upx_uint64_t v) noexcept {
set_be64(d, get_be64(d) | v);
return *this;
}
BE64 &operator^=(upx_uint64_t v) {
BE64 &operator^=(upx_uint64_t v) noexcept {
set_be64(d, get_be64(d) ^ v);
return *this;
}
BE64 &operator<<=(unsigned v) {
BE64 &operator<<=(unsigned v) noexcept {
set_be64(d, get_be64(d) << v);
return *this;
}
BE64 &operator>>=(unsigned v) {
BE64 &operator>>=(unsigned v) noexcept {
set_be64(d, get_be64(d) >> v);
return *this;
}
operator upx_uint64_t() const { return get_be64(d); }
bool operator<(const BE64 &v) const { return upx_uint64_t(*this) < upx_uint64_t(v); }
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); }
};
struct alignas(1) LE16 {
struct alignas(1) LE16 final {
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
unsigned char d[2];
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);
return *this;
}
LE16 &operator+=(unsigned v) {
LE16 &operator+=(unsigned v) noexcept {
set_le16(d, get_le16(d) + v);
return *this;
}
LE16 &operator-=(unsigned v) {
LE16 &operator-=(unsigned v) noexcept {
set_le16(d, get_le16(d) - v);
return *this;
}
LE16 &operator*=(unsigned v) {
LE16 &operator*=(unsigned v) noexcept {
set_le16(d, get_le16(d) * v);
return *this;
}
LE16 &operator/=(unsigned v) {
LE16 &operator/=(unsigned v) noexcept {
set_le16(d, get_le16(d) / v);
return *this;
}
LE16 &operator&=(unsigned v) {
LE16 &operator&=(unsigned v) noexcept {
set_le16(d, get_le16(d) & v);
return *this;
}
LE16 &operator|=(unsigned v) {
LE16 &operator|=(unsigned v) noexcept {
set_le16(d, get_le16(d) | v);
return *this;
}
LE16 &operator^=(unsigned v) {
LE16 &operator^=(unsigned v) noexcept {
set_le16(d, get_le16(d) ^ v);
return *this;
}
LE16 &operator<<=(unsigned v) {
LE16 &operator<<=(unsigned v) noexcept {
set_le16(d, get_le16(d) << v);
return *this;
}
LE16 &operator>>=(unsigned v) {
LE16 &operator>>=(unsigned v) noexcept {
set_le16(d, get_le16(d) >> v);
return *this;
}
operator unsigned() const { return get_le16(d); }
bool operator<(const LE16 &v) const { return unsigned(*this) < unsigned(v); }
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); }
};
struct alignas(1) LE32 {
struct alignas(1) LE32 final {
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
unsigned char d[4];
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);
return *this;
}
LE32 &operator+=(unsigned v) {
LE32 &operator+=(unsigned v) noexcept {
set_le32(d, get_le32(d) + v);
return *this;
}
LE32 &operator-=(unsigned v) {
LE32 &operator-=(unsigned v) noexcept {
set_le32(d, get_le32(d) - v);
return *this;
}
LE32 &operator*=(unsigned v) {
LE32 &operator*=(unsigned v) noexcept {
set_le32(d, get_le32(d) * v);
return *this;
}
LE32 &operator/=(unsigned v) {
LE32 &operator/=(unsigned v) noexcept {
set_le32(d, get_le32(d) / v);
return *this;
}
LE32 &operator&=(unsigned v) {
LE32 &operator&=(unsigned v) noexcept {
set_le32(d, get_le32(d) & v);
return *this;
}
LE32 &operator|=(unsigned v) {
LE32 &operator|=(unsigned v) noexcept {
set_le32(d, get_le32(d) | v);
return *this;
}
LE32 &operator^=(unsigned v) {
LE32 &operator^=(unsigned v) noexcept {
set_le32(d, get_le32(d) ^ v);
return *this;
}
LE32 &operator<<=(unsigned v) {
LE32 &operator<<=(unsigned v) noexcept {
set_le32(d, get_le32(d) << v);
return *this;
}
LE32 &operator>>=(unsigned v) {
LE32 &operator>>=(unsigned v) noexcept {
set_le32(d, get_le32(d) >> v);
return *this;
}
operator unsigned() const { return get_le32(d); }
bool operator<(const LE32 &v) const { return unsigned(*this) < unsigned(v); }
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); }
};
struct alignas(1) LE64 {
struct alignas(1) LE64 final {
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
unsigned char d[8];
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);
return *this;
}
LE64 &operator+=(upx_uint64_t v) {
LE64 &operator+=(upx_uint64_t v) noexcept {
set_le64(d, get_le64(d) + v);
return *this;
}
LE64 &operator-=(upx_uint64_t v) {
LE64 &operator-=(upx_uint64_t v) noexcept {
set_le64(d, get_le64(d) - v);
return *this;
}
LE64 &operator*=(upx_uint64_t v) {
LE64 &operator*=(upx_uint64_t v) noexcept {
set_le64(d, get_le64(d) * v);
return *this;
}
LE64 &operator/=(upx_uint64_t v) {
LE64 &operator/=(upx_uint64_t v) noexcept {
set_le64(d, get_le64(d) / v);
return *this;
}
LE64 &operator&=(upx_uint64_t v) {
LE64 &operator&=(upx_uint64_t v) noexcept {
set_le64(d, get_le64(d) & v);
return *this;
}
LE64 &operator|=(upx_uint64_t v) {
LE64 &operator|=(upx_uint64_t v) noexcept {
set_le64(d, get_le64(d) | v);
return *this;
}
LE64 &operator^=(upx_uint64_t v) {
LE64 &operator^=(upx_uint64_t v) noexcept {
set_le64(d, get_le64(d) ^ v);
return *this;
}
LE64 &operator<<=(unsigned v) {
LE64 &operator<<=(unsigned v) noexcept {
set_le64(d, get_le64(d) << v);
return *this;
}
LE64 &operator>>=(unsigned v) {
LE64 &operator>>=(unsigned v) noexcept {
set_le64(d, get_le64(d) >> v);
return *this;
}
operator upx_uint64_t() const { return get_le64(d); }
bool operator<(const LE64 &v) const { return upx_uint64_t(*this) < upx_uint64_t(v); }
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); }
};
// 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)
**************************************************************************/
template <class T>
inline T *operator+(T *ptr, const BE16 &v) {
inline T *operator+(T *ptr, const BE16 &v) noexcept {
return ptr + unsigned(v);
}
template <class T>
inline T *operator-(T *ptr, const BE16 &v) {
inline T *operator-(T *ptr, const BE16 &v) noexcept {
return ptr - unsigned(v);
}
template <class T>
inline T *operator+(T *ptr, const BE32 &v) {
inline T *operator+(T *ptr, const BE32 &v) noexcept {
return ptr + unsigned(v);
}
template <class T>
inline T *operator-(T *ptr, const BE32 &v) {
inline T *operator-(T *ptr, const BE32 &v) noexcept {
return ptr - unsigned(v);
}
template <class T>
inline T *operator+(T *ptr, const LE16 &v) {
inline T *operator+(T *ptr, const LE16 &v) noexcept {
return ptr + unsigned(v);
}
template <class T>
inline T *operator-(T *ptr, const LE16 &v) {
inline T *operator-(T *ptr, const LE16 &v) noexcept {
return ptr - unsigned(v);
}
template <class T>
inline T *operator+(T *ptr, const LE32 &v) {
inline T *operator+(T *ptr, const LE32 &v) noexcept {
return ptr + unsigned(v);
}
template <class T>
inline T *operator-(T *ptr, const LE32 &v) {
inline T *operator-(T *ptr, const LE32 &v) noexcept {
return ptr - unsigned(v);
}
// these are not implemented on purpose and will cause errors
template <class T>
T *operator+(T *ptr, const BE64 &v) DELETED_FUNCTION;
T *operator+(T *ptr, const BE64 &v) noexcept DELETED_FUNCTION;
template <class T>
T *operator-(T *ptr, const BE64 &v) DELETED_FUNCTION;
T *operator-(T *ptr, const BE64 &v) noexcept DELETED_FUNCTION;
template <class T>
T *operator+(T *ptr, const LE64 &v) DELETED_FUNCTION;
T *operator+(T *ptr, const LE64 &v) noexcept DELETED_FUNCTION;
template <class T>
T *operator-(T *ptr, const LE64 &v) DELETED_FUNCTION;
T *operator-(T *ptr, const LE64 &v) noexcept DELETED_FUNCTION;
#if !ALLOW_INT_PLUS_MEMBUFFER
template <class T>
T *operator+(const BE16 &v, T *ptr) noexcept DELETED_FUNCTION;
template <class T>
T *operator+(const BE32 &v, T *ptr) noexcept DELETED_FUNCTION;
template <class T>
T *operator+(const LE16 &v, T *ptr) noexcept DELETED_FUNCTION;
template <class T>
T *operator+(const LE32 &v, T *ptr) noexcept DELETED_FUNCTION;
#endif // ALLOW_INT_PLUS_MEMBUFFER
template <class T>
T *operator+(const BE64 &v, T *ptr) noexcept DELETED_FUNCTION;
template <class T>
T *operator+(const LE64 &v, T *ptr) noexcept DELETED_FUNCTION;
/*************************************************************************
// global overloads
**************************************************************************/
// TODO later: move these to upx namespace in util/cxxlib.h; see conf.h
inline unsigned ALIGN_DOWN(unsigned a, const BE32 &b) { return ALIGN_DOWN(a, unsigned(b)); }
inline unsigned ALIGN_DOWN(const BE32 &a, unsigned b) { return ALIGN_DOWN(unsigned(a), b); }
inline unsigned ALIGN_UP(unsigned a, const BE32 &b) { return ALIGN_UP(a, unsigned(b)); }
@@ -620,6 +760,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(const LE32 &a, unsigned b) { return ALIGN_UP(unsigned(a), b); }
// TODO later: 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(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)); }
@@ -644,6 +785,47 @@ inline unsigned UPX_MIN(const LE32 &a, unsigned b) { return UPX_MIN(unsigned(a),
// 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()
extern "C" {
int __acc_cdecl_qsort be16_compare(const void *, const void *);
@@ -700,14 +882,12 @@ namespace N_BELE_RTP {
// util
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;
}
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;
}
} // namespace N_BELE_CTP
#endif /* already included */
/* vim:set ts=4 sw=4 et: */
+29 -50
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,9 +25,7 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef UPX_BELE_H__
#error "this is an internal include file"
#endif
// this is an internal include file private to bele.h
/*************************************************************************
//
@@ -36,21 +34,23 @@
#if defined(BELE_CTP)
// CTP - Compile-Time Polymorphism (templates)
#define V static inline
#define VV static forceinline_constexpr
#define S static int __acc_cdecl_qsort
#define C /*empty*/
#define C noexcept
#elif defined(BELE_RTP)
// RTP - Run-Time Polymorphism (virtual functions)
#define V virtual
#define VV virtual
#define S virtual int
#define C const
#define C const noexcept
#else
#error
#endif
#if defined(BELE_RTP)
struct AbstractPolicy {
inline AbstractPolicy() {}
virtual inline ~AbstractPolicy() {}
explicit inline AbstractPolicy() noexcept {}
virtual inline ~AbstractPolicy() noexcept {}
V bool isBE() C = 0;
V bool isLE() C = 0;
@@ -80,18 +80,16 @@ struct AbstractPolicy {
S u64_compare_signed(const void *a, const void *b) C = 0;
private:
// disable copy, assignment and move assignment
AbstractPolicy(const AbstractPolicy &) = delete;
AbstractPolicy &operator=(const AbstractPolicy &) = delete;
AbstractPolicy &operator=(AbstractPolicy &&) = delete;
// disable copy and move
UPX_CXX_DISABLE_COPY_MOVE(AbstractPolicy)
// disable dynamic allocation
ACC_CXX_DISABLE_NEW_DELETE
UPX_CXX_DISABLE_NEW_DELETE(AbstractPolicy)
};
#endif
#if defined(BELE_RTP)
#undef C
#define C const override
#define C const noexcept override
#endif
struct BEPolicy
@@ -99,14 +97,14 @@ struct BEPolicy
final : public AbstractPolicy
#endif
{
inline BEPolicy() {}
explicit inline BEPolicy() noexcept {}
#if defined(BELE_CTP)
typedef N_BELE_RTP::BEPolicy RTP_Policy;
#elif defined(BELE_RTP)
typedef N_BELE_CTP::BEPolicy CTP_Policy;
#endif
V bool isBE() C { return true; }
V bool isLE() C { return false; }
VV bool isBE() C { return true; }
VV bool isLE() C { return false; }
typedef BE16 U16;
typedef BE32 U32;
@@ -147,12 +145,10 @@ struct BEPolicy
}
private:
// disable copy, assignment and move assignment
BEPolicy(const BEPolicy &) = delete;
BEPolicy &operator=(const BEPolicy &) = delete;
BEPolicy &operator=(BEPolicy &&) = delete;
// disable copy and move
UPX_CXX_DISABLE_COPY_MOVE(BEPolicy)
// disable dynamic allocation
ACC_CXX_DISABLE_NEW_DELETE
UPX_CXX_DISABLE_NEW_DELETE(BEPolicy)
};
struct LEPolicy
@@ -160,14 +156,14 @@ struct LEPolicy
final : public AbstractPolicy
#endif
{
inline LEPolicy() {}
explicit inline LEPolicy() noexcept {}
#if defined(BELE_CTP)
typedef N_BELE_RTP::LEPolicy RTP_Policy;
#elif defined(BELE_RTP)
typedef N_BELE_CTP::LEPolicy CTP_Policy;
#endif
V bool isBE() C { return false; }
V bool isLE() C { return true; }
VV bool isBE() C { return false; }
VV bool isLE() C { return true; }
typedef LE16 U16;
typedef LE32 U32;
@@ -208,42 +204,25 @@ struct LEPolicy
}
private:
// disable copy, assignment and move assignment
LEPolicy(const LEPolicy &) = delete;
LEPolicy &operator=(const LEPolicy &) = delete;
LEPolicy &operator=(LEPolicy &&) = delete;
// disable copy and move
UPX_CXX_DISABLE_COPY_MOVE(LEPolicy)
// 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)
typedef BEPolicy NEPolicy;
typedef BEPolicy HostPolicy;
#elif (ACC_ABI_LITTLE_ENDIAN)
typedef LEPolicy NEPolicy;
typedef LEPolicy HostPolicy;
#else
#error "ACC_ABI_ENDIAN"
#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 VV
#undef S
#undef C
+483 -159
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -24,10 +24,18 @@
<markus@oberhumer.com>
*/
#include "../util/system_headers.h"
#include <cmath> // std::isinf std::isnan
#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) {
@@ -36,23 +44,26 @@ int upx_doctest_check(int argc, char **argv) {
UNUSED(argv);
return 0;
#else
const char *e = getenv("UPX_DEBUG_DOCTEST_DISABLE");
if (e && e[0] && strcmp(e, "0") != 0)
if (is_envvar_true("UPX_DEBUG_DOCTEST_DISABLE", "UPX_DEBUG_DISABLE_DOCTEST"))
return 0;
bool minimal = true; // only show failing tests
bool duration = false; // show timings
bool success = false; // show all tests
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");
const char *e = getenv("UPX_DEBUG_DOCTEST_VERBOSE");
if (e && e[0]) {
minimal = false;
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;
}
@@ -82,6 +93,7 @@ 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))
@@ -92,35 +104,28 @@ ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<unsigned long long, upx_uint64_t>::
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)
#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(compile_time::string_len("") == 0)
ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("a") == 1)
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"))
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(sign_extend(0ull + 0, 1) == 0)
ACC_COMPILE_TIME_ASSERT_HEADER(sign_extend(0ull + 1, 1) == -1)
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_BIT == 8)
#if 0 // does not work with MSVC
@@ -139,92 +144,167 @@ ACC_COMPILE_TIME_ASSERT_HEADER((wchar_t) -1 > 0)
/*************************************************************************
// upx_compiler_sanity_check()
// assert a sane architecture and compiler
// (modern compilers will optimize away most of this code)
**************************************************************************/
namespace {
template <class T>
struct TestBELE {
__acc_static_noinline bool test(void) {
// POD checks
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 {
{
COMPILE_TIME_ASSERT(std::is_standard_layout<T>::value)
COMPILE_TIME_ASSERT(std::is_trivial<T>::value)
// extra checks, these are probably implied by std::is_trivial:
COMPILE_TIME_ASSERT(std::is_nothrow_default_constructible<T>::value)
COMPILE_TIME_ASSERT(std::is_trivially_copyable<T>::value)
COMPILE_TIME_ASSERT(std::is_trivially_default_constructible<T>::value)
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);
}
// alignment checks
{
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_t {
struct alignas(1) Test1 {
char a;
T b;
};
struct alignas(1) test2_t {
struct alignas(1) Test2 {
char a;
T b[3];
};
COMPILE_TIME_ASSERT_ALIGNED1(test1_t)
COMPILE_TIME_ASSERT_ALIGNED1(test2_t)
test1_t t1[7];
test2_t t2[7];
COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T))
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_t) == 1 + 3 * sizeof(T))
COMPILE_TIME_ASSERT(sizeof(Test2) == 1 + 3 * sizeof(T))
COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21 * sizeof(T))
UNUSED(t1);
UNUSED(t2);
}
#if 1
};
template <class T>
struct TestBELE {
static noinline bool test(void) noexcept {
CheckIntegral<T>::check();
CheckAlignment<T>::check();
// arithmetic checks
{
T allbits;
allbits = 0;
T allbits = {};
assert_noexcept(allbits == 0);
allbits += 1;
allbits -= 2;
T v1;
v1 = 1;
v1 *= 2;
v1 *= 4;
v1 /= 2;
v1 -= 1;
T v2;
v2 = 1;
assert((v1 == v2));
assert(!(v1 != v2));
assert((v1 <= v2));
assert((v1 >= v2));
assert(!(v1 < v2));
assert(!(v1 > v2));
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(!(v1 == v2));
assert((v1 != v2));
assert((v1 <= v2));
assert(!(v1 >= v2));
assert((v1 < v2));
assert(!(v1 > v2));
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(v1 == 1);
assert(v2 == 0);
assert_noexcept(v1 == 1);
assert_noexcept(v2 == 0);
v1 <<= 1;
v1 |= v2;
v1 >>= 1;
v2 &= v1;
v2 /= v1;
v2 *= v1;
assert(v1 == 1);
assert(v2 == 0);
v1 += v2;
v1 -= v2;
assert_noexcept(v1 == 1);
assert_noexcept(v2 == 0);
if ((v1 ^ v2) != 1)
return false;
}
#endif
return true;
}
};
template <class A, class B>
struct TestNoAliasingStruct {
__acc_static_noinline bool test(A *a, B *b) {
static noinline bool test(A *a, B *b) noexcept {
*a = 0;
*b = 0;
*b -= 3;
@@ -232,26 +312,130 @@ struct TestNoAliasingStruct {
}
};
template <class A, class B>
__acc_static_forceinline bool testNoAliasing(A *a, B *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(T x) { return x + 1 > x; }
static inline bool dec(T x) { return x - 1 < x; }
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; }
};
//
// basic exception handling checks to early catch toolchain/qemu/wine/etc problems
//
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);
}
//
// basic floating point checks to early catch toolchain/qemu/wine/etc problems
//
static noinline float i64_f32_add_div(upx_int64_t a, upx_int64_t b) { return (a + b) / 1000000.0f; }
static noinline float u64_f32_add_div(upx_uint64_t a, upx_uint64_t b) {
return (a + b) / 1000000.0f;
}
static noinline float i64_f32_sub_div(upx_int64_t a, upx_int64_t b) { return (a - b) / 1000000.0f; }
static noinline float u64_f32_sub_div(upx_uint64_t a, upx_uint64_t b) {
return (a - b) / 1000000.0f;
}
static noinline double i64_f64_add_div(upx_int64_t a, upx_int64_t b) { return (a + b) / 1000000.0; }
static noinline double u64_f64_add_div(upx_uint64_t a, upx_uint64_t b) {
return (a + b) / 1000000.0;
}
static noinline double i64_f64_sub_div(upx_int64_t a, upx_int64_t b) { return (a - b) / 1000000.0; }
static noinline double u64_f64_sub_div(upx_uint64_t a, upx_uint64_t b) {
return (a - b) / 1000000.0;
}
template <class Int, class Float>
struct TestFloat {
static constexpr Int X = 1000000;
static noinline Float div(Int a, Float f) { return a / f; }
static noinline Float add_div(Int a, Int b, Float f) { return Float(a + b) / f; }
static noinline Float sub_div(Int a, Int b, Float f) { return Float(a - b) / f; }
static noinline Float add_div_x(Int a, Int b) { return Float(a + b) / Float(X); }
static noinline Float sub_div_x(Int a, Int b) { return Float(a - b) / Float(X); }
static noinline void check() noexcept {
assert_noexcept(add_div(X, X, Float(X)) == Float(2));
assert_noexcept(add_div_x(X, X) == Float(2));
assert_noexcept(sub_div(3 * X, X, Float(X)) == Float(2));
assert_noexcept(sub_div_x(3 * X, X) == Float(2));
// extra debugging; floating point edge cases cause portability problems in practice
if (is_envvar_true("UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO")) {
#if defined(__clang__) && defined(__FAST_MATH__) && defined(__INTEL_LLVM_COMPILER)
// warning: comparison with NaN always evaluates to false in fast floating point modes
fprintf(stderr, "upx: WARNING: ignoring UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO\n");
#elif defined(__clang__) && (__clang_major__ < 9) && defined(__SANITIZE_UNDEFINED_BEHAVIOR__)
// @COMPILER_BUG @CLANG_BUG
fprintf(stderr, "upx: WARNING: ignoring UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO\n");
#else
assert_noexcept(std::isnan(div(0, Float(0))));
assert_noexcept(std::isinf(div(1, Float(0))));
#endif
}
}
};
static noinline void check_basic_floating_point(void) noexcept {
assert_noexcept(i64_f32_add_div(1000000, 1000000) == 2.0f);
assert_noexcept(u64_f32_add_div(1000000, 1000000) == 2.0f);
assert_noexcept(i64_f32_sub_div(3000000, 1000000) == 2.0f);
assert_noexcept(u64_f32_sub_div(3000000, 1000000) == 2.0f);
assert_noexcept(i64_f64_add_div(1000000, 1000000) == 2.0);
assert_noexcept(u64_f64_add_div(1000000, 1000000) == 2.0);
assert_noexcept(i64_f64_sub_div(3000000, 1000000) == 2.0);
assert_noexcept(u64_f64_sub_div(3000000, 1000000) == 2.0);
TestFloat<upx_int32_t, float>::check();
TestFloat<upx_uint32_t, float>::check();
TestFloat<upx_int64_t, float>::check();
TestFloat<upx_uint64_t, float>::check();
TestFloat<upx_int32_t, double>::check();
TestFloat<upx_uint32_t, double>::check();
TestFloat<upx_int64_t, double>::check();
TestFloat<upx_uint64_t, double>::check();
}
} // namespace
#define ACC_WANT_ACC_CHK_CH 1
#undef ACCCHK_ASSERT
#include "../miniacc.h"
#include "../util/miniacc.h"
void upx_compiler_sanity_check(void) noexcept {
if (is_envvar_true("UPX_DEBUG_DOCTEST_DISABLE", "UPX_DEBUG_DISABLE_DOCTEST")) {
// 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 early catch toolchain/qemu/wine/etc problems
check_basic_cxx_exception_handling(throwSomeValue);
}
check_basic_floating_point();
void upx_compiler_sanity_check(void) {
#define ACC_WANT_ACC_CHK_CH 1
#undef ACCCHK_ASSERT
#define ACCCHK_ASSERT(expr) ACC_COMPILE_TIME_ASSERT(expr)
#include "../miniacc.h"
#include "../util/miniacc.h"
#undef ACCCHK_ASSERT
COMPILE_TIME_ASSERT(sizeof(char) == 1)
@@ -274,100 +458,149 @@ void upx_compiler_sanity_check(void) {
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(strlen(UPX_VERSION_STRING4) == 4);
assert_noexcept(strlen(UPX_VERSION_STRING4) == 4);
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_YEAR) == 4 + 1)
assert(strlen(UPX_VERSION_YEAR) == 4);
assert(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0);
assert(memcmp(&UPX_VERSION_DATE[sizeof(UPX_VERSION_DATE) - 1 - 4], UPX_VERSION_YEAR, 4) == 0);
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(revlen == 5 || revlen == 6);
assert_noexcept(revlen == 5 || revlen == 6);
} else {
assert(revlen == 12 || revlen == 13);
assert_noexcept(revlen == 12 || revlen == 13);
}
if (revlen == 6 || revlen == 13) {
assert(gitrev[revlen - 1] == '+');
assert_noexcept(gitrev[revlen - 1] == '+');
}
}
assert(UPX_RSIZE_MAX_MEM == 805306368);
assert_noexcept(UPX_RSIZE_MAX_MEM == 805306368);
#if 1
assert(TestBELE<LE16>::test());
assert(TestBELE<LE32>::test());
assert(TestBELE<LE64>::test());
assert(TestBELE<BE16>::test());
assert(TestBELE<BE32>::test());
assert(TestBELE<BE64>::test());
#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 unsigned char dd[32] = {
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 unsigned char *d;
const byte *d;
const N_BELE_RTP::AbstractPolicy *bele;
d = dd + 7;
assert(upx_adler32(d, 4) == 0x09f003f7);
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
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(get_be16(d) == 0xfffe);
assert(bele->get16(d) == 0xfffe);
assert(get_be16_signed(d) == -2);
assert(get_be24(d) == 0xfffefd);
assert(bele->get24(d) == 0xfffefd);
assert(get_be24_signed(d) == -259);
assert(get_be32(d) == 0xfffefdfc);
assert(bele->get32(d) == 0xfffefdfc);
assert(get_be32_signed(d) == -66052);
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(get_le16(d) == 0xfeff);
assert(bele->get16(d) == 0xfeff);
assert(get_le16_signed(d) == -257);
assert(get_le24(d) == 0xfdfeff);
assert(bele->get24(d) == 0xfdfeff);
assert(get_le24_signed(d) == -131329);
assert(get_le32(d) == 0xfcfdfeff);
assert(bele->get32(d) == 0xfcfdfeff);
assert(get_le32_signed(d) == -50462977);
assert(get_le64_signed(d) == -506097522914230529LL);
assert(find_be16(d, 2, 0xfffe) == 0);
assert(find_le16(d, 2, 0xfeff) == 0);
assert(find_be32(d, 4, 0xfffefdfc) == 0);
assert(find_le32(d, 4, 0xfcfdfeff) == 0);
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(get_be16_signed(d) == 32638);
assert(get_be24_signed(d) == 8355453);
assert(get_be32_signed(d) == 2138996092);
assert(get_be64_signed(d) == 9186918263483431288LL);
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);
}
#if DEBUG >= 1
{
for (int i = 0; i < 256; i++) {
{
const unsigned u = i;
assert_noexcept(sign_extend(u, 1) == ((i & 1) ? -1 : 0));
assert_noexcept(sign_extend(u, 2) == ((i & 2) ? -2 + (i & 1) : (i & 1)));
assert_noexcept(sign_extend(u, 3) == ((i & 4) ? -4 + (i & 3) : (i & 3)));
assert_noexcept(sign_extend(u, 4) == ((i & 8) ? -8 + (i & 7) : (i & 7)));
assert_noexcept(sign_extend(u, 5) == ((i & 16) ? -16 + (i & 15) : (i & 15)));
assert_noexcept(sign_extend(u, 6) == ((i & 32) ? -32 + (i & 31) : (i & 31)));
assert_noexcept(sign_extend(u, 7) == ((i & 64) ? -64 + (i & 63) : (i & 63)));
assert_noexcept(sign_extend(u, 8) == ((i & 128) ? -128 + (i & 127) : (i & 127)));
assert_noexcept(sign_extend(u, 32) == i);
assert_noexcept(sign_extend(0u - u, 32) == -i);
}
{
const upx_uint64_t u = i;
assert_noexcept(sign_extend(u, 1) == ((i & 1) ? -1 : 0));
assert_noexcept(sign_extend(u, 2) == ((i & 2) ? -2 + (i & 1) : (i & 1)));
assert_noexcept(sign_extend(u, 3) == ((i & 4) ? -4 + (i & 3) : (i & 3)));
assert_noexcept(sign_extend(u, 4) == ((i & 8) ? -8 + (i & 7) : (i & 7)));
assert_noexcept(sign_extend(u, 5) == ((i & 16) ? -16 + (i & 15) : (i & 15)));
assert_noexcept(sign_extend(u, 6) == ((i & 32) ? -32 + (i & 31) : (i & 31)));
assert_noexcept(sign_extend(u, 7) == ((i & 64) ? -64 + (i & 63) : (i & 63)));
assert_noexcept(sign_extend(u, 8) == ((i & 128) ? -128 + (i & 127) : (i & 127)));
assert_noexcept(sign_extend(u, 64) == i);
assert_noexcept(sign_extend(0ull - u, 64) == -i);
}
}
}
#endif
{
unsigned dd;
void *const d = &dd;
dd = ne32_to_le32(0xf7f6f5f4);
assert(get_le26(d) == 0x03f6f5f4);
assert_noexcept(get_le26(d) == 0x03f6f5f4);
set_le26(d, 0);
assert(get_le26(d) == 0);
assert(dd == ne32_to_le32(0xf4000000));
assert_noexcept(get_le26(d) == 0);
assert_noexcept(dd == ne32_to_le32(0xf4000000));
set_le26(d, 0xff020304);
assert(get_le26(d) == 0x03020304);
assert(dd == ne32_to_le32(0xf7020304));
assert_noexcept(get_le26(d) == 0x03020304);
assert_noexcept(dd == ne32_to_le32(0xf7020304));
}
{
upx_uint16_t a;
upx_uint32_t b;
upx_uint64_t c;
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(a == 0x0201);
assert(b == 0x04030201);
assert(c == 0x0807060504030201ull);
assert(get_ne16(&a) == 0x0201);
assert(get_ne32(&b) == 0x04030201);
assert(get_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
#endif // DEBUG
union {
short v_short;
int v_int;
@@ -380,31 +613,56 @@ void upx_compiler_sanity_check(void) {
LE32 l32;
LE64 l64;
} u;
assert(testNoAliasing(&u.v_short, &u.b32));
assert(testNoAliasing(&u.v_short, &u.l32));
assert(testNoAliasing(&u.v_int, &u.b64));
assert(testNoAliasing(&u.v_int, &u.l64));
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(testNoAliasing(&u.v_short, &u.v_int));
assert(testNoAliasing(&u.v_int, &u.v_long));
assert(testNoAliasing(&u.v_int, &u.v_llong));
assert(testNoAliasing(&u.v_long, &u.v_llong));
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(TestIntegerWrap<unsigned>::inc(0));
assert(!TestIntegerWrap<unsigned>::inc(UINT_MAX));
assert(TestIntegerWrap<unsigned>::dec(1));
assert(!TestIntegerWrap<unsigned>::dec(0));
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(TestIntegerWrap<int>::inc(0));
assert(!TestIntegerWrap<int>::inc(INT_MAX));
assert(TestIntegerWrap<int>::dec(0));
assert(!TestIntegerWrap<int>::dec(INT_MIN));
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);
@@ -412,6 +670,17 @@ TEST_CASE("acc_vget") {
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; // not initialized
ptr_invalidate_and_poison(dp);
assert(dp != nullptr);
(void) dp;
}
TEST_CASE("working -fno-strict-aliasing") {
bool ok;
long v = 0;
@@ -434,6 +703,7 @@ TEST_CASE("working -fno-strict-aliasing") {
*pi = -1;
ok = *pl != 0;
CHECK(ok);
UNUSED(ok);
}
TEST_CASE("working -fno-strict-overflow") {
@@ -451,10 +721,11 @@ TEST_CASE("working -fno-strict-overflow") {
i -= 1;
ok = i == INT_MAX;
CHECK(ok);
UNUSED(ok);
}
TEST_CASE("libc snprintf") {
// runtime check that Win32/MinGW <stdio.h> works as expected
// 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;
@@ -470,6 +741,59 @@ TEST_CASE("libc snprintf") {
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);
snprintf(buf, sizeof(buf), "%#X %#lx %#llx", 26u, 27ul, 28ull);
CHECK_EQ(strcmp(buf, "0X1A 0x1b 0x1c"), 0);
snprintf(buf, sizeof(buf), "%#06x %#06lX %#06llx", 26u, 27ul, 28ull);
CHECK_EQ(strcmp(buf, "0x001a 0X001B 0x001c"), 0);
snprintf(buf, sizeof(buf), "%#6x %#6lx %#6llX", 26u, 27ul, 28ull);
CHECK_EQ(strcmp(buf, " 0x1a 0x1b 0X1C"), 0);
snprintf(buf, sizeof(buf), "%#-6X %#-6lx %#-6llx", 26u, 27ul, 28ull);
CHECK_EQ(strcmp(buf, "0X1A 0x1b 0x1c "), 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: */
+489
View File
@@ -0,0 +1,489 @@
/* 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
#if 0 // TODO later
// libc++ hardenining
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18)
#if DEBUG
#define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEBUG
#else
#define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
#endif
#endif
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 < 18)
#if DEBUG
#define _LIBCPP_ENABLE_ASSERTIONS 1
#endif
#endif
#endif // TODO later
#include "../util/system_headers.h"
#include <vector>
#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((upx::is_same_any_v<ptrdiff_t, int, long, long long>) )
ACC_COMPILE_TIME_ASSERT_HEADER(
(upx::is_same_any_v<size_t, unsigned, unsigned long, unsigned long long>) )
ACC_COMPILE_TIME_ASSERT_HEADER(
(upx::is_same_any_v<upx_uintptr_t, unsigned, unsigned long, unsigned long 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"))
/*************************************************************************
//
**************************************************************************/
TEST_CASE("libc++") {
constexpr size_t N = 16;
std::vector<int> v(N);
CHECK(v.end() - v.begin() == N);
CHECK(&v[0] == &(*(v.begin())));
// CHECK(&v[0] + N == &(*(v.end()))); // TODO later: is this legal??
// TODO later: make sure that this throws
#if defined(_LIBCPP_HARDENING_MODE_DEBUG) && \
(_LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG)
CHECK_THROWS((void) &v[N]);
#endif
UNUSED(v);
}
/*************************************************************************
// 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_xxx") {
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("upx::ObjectDeleter 1") {
LE16 *o = nullptr; // object
LE32 *a = nullptr; // array
{
const upx::ObjectDeleter<LE16 **> o_deleter{&o, 1};
o = new LE16;
assert(o != nullptr);
const upx::ArrayDeleter<LE32 **> a_deleter{&a, 1};
a = New(LE32, 1);
assert(a != nullptr);
}
assert(o == nullptr);
assert(a == nullptr);
}
TEST_CASE("upx::ObjectDeleter 2") {
constexpr size_t N = 2;
BE16 *o[N]; // multiple objects
BE32 *a[N]; // multiple arrays
{
upx::ObjectDeleter<BE16 **> o_deleter{o, 0};
upx::ArrayDeleter<BE32 **> a_deleter{a, 0};
for (size_t i = 0; i < N; i++) {
o[i] = new BE16;
assert(o[i] != nullptr);
o_deleter.count += 1;
a[i] = New(BE32, 1 + i);
assert(a[i] != nullptr);
a_deleter.count += 1;
}
}
for (size_t i = 0; i < N; i++) {
assert(o[i] == nullptr);
assert(a[i] == nullptr);
}
}
TEST_CASE("upx::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("upx::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("upx::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: */
+23 -7
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -24,28 +24,44 @@
<markus@oberhumer.com>
*/
#include "../util/system_defs.h"
#include "../util/system_features.h"
/*************************************************************************
// doctest support code implementation
**************************************************************************/
#define DOCTEST_CONFIG_IMPLEMENT
#if !defined(UPX_DOCTEST_CONFIG_MULTITHREADING)
#define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
#if !defined(DOCTEST_CONFIG_DISABLE)
#if defined(__wasi__)
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_NO_POSIX_SIGNALS
#elif defined(__i386__) && defined(__MSDOS__) && defined(__DJGPP__) && defined(__GNUC__)
#define DOCTEST_CONFIG_NO_MULTITHREADING
#endif
#if defined(__i386__) && defined(__MSDOS__) && defined(__DJGPP__) && defined(__GNUC__)
#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
#define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
#if !defined(DOCTEST_CONFIG_DISABLE)
#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
#endif // DOCTEST_CONFIG_DISABLE
/* vim:set ts=4 sw=4 et: */
+242 -23
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -43,6 +43,7 @@ TEST_CASE("raw_bytes ptr") {
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") {
@@ -55,6 +56,7 @@ TEST_CASE("raw_bytes bounded array") {
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);
}
/*************************************************************************
@@ -62,7 +64,7 @@ TEST_CASE("raw_bytes bounded array") {
**************************************************************************/
TEST_CASE("basic xspan usage") {
char buf[4] = {0, 1, 2, 3};
alignas(4) char buf[4] = {0, 1, 2, 3};
SUBCASE("XSPAN_x") {
XSPAN_0(char) a0 = nullptr;
@@ -91,6 +93,17 @@ TEST_CASE("basic xspan usage") {
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);
@@ -101,11 +114,31 @@ TEST_CASE("basic xspan usage") {
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, a0, nullptr);
XSPAN_0_VAR(char, b0, buf);
XSPAN_P_VAR(char, bp, buf);
@@ -124,7 +157,6 @@ TEST_CASE("basic xspan usage") {
XSPAN_0_VAR(const char, const z0p, yp);
XSPAN_0_VAR(const char, const z0s, xs);
CHECK((a0 == nullptr));
CHECK(c0 == b0);
CHECK(cp == bp);
CHECK(cs == bp);
@@ -133,9 +165,24 @@ TEST_CASE("basic xspan usage") {
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);
@@ -146,6 +193,28 @@ TEST_CASE("basic xspan usage") {
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") {
@@ -172,6 +241,35 @@ TEST_CASE("basic xspan usage") {
}
}
TEST_CASE("xspan array access") {
const size_t N = 16;
char buf[N];
memset(buf, 0, sizeof(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));
for (size_t i = 0; i != N; ++i)
c0[i] += 1;
for (size_t i = 0; i != N; ++i)
cp[i] += 1;
for (size_t i = 0; i != N; ++i)
cs[i] += 1;
#if __cplusplus >= 201103L
for (auto ptr = c0; ptr != c0 + N; ++ptr)
*ptr += 1;
for (auto ptr = c0 + 0; ptr < c0 + N; ++ptr)
*ptr += 1;
for (auto ptr = cp; ptr != cp + N; ++ptr)
*ptr += 1;
for (auto ptr = cp + 0; ptr < cp + N; ++ptr)
*ptr += 1;
for (auto ptr = cs; ptr != cs + N; ++ptr)
*ptr += 1;
for (auto ptr = cs + 0; ptr < cs + N; ++ptr)
*ptr += 1;
#endif
}
/*************************************************************************
//
**************************************************************************/
@@ -382,6 +480,7 @@ TEST_CASE("PtrOrSpan") {
CHECK_THROWS(sp_with_base = s0_no_base); // nullptr assignment
CHECK_THROWS(sp_with_base = s0_with_base); // nullptr assignment
#endif
UNUSED(my_null);
}
/*************************************************************************
@@ -533,6 +632,7 @@ TEST_CASE("Span") {
CHECK((XSPAN_S_MAKE(char, b1_b1).raw_base() == base_buf + 1));
}
#endif
UNUSED(my_null);
}
/*************************************************************************
@@ -587,11 +687,16 @@ TEST_CASE("Span subspan") {
CHECK((as + 2).subspan(0, -2)[0] == 0);
CHECK_THROWS(as.subspan(1, 0)[0]);
CHECK_THROWS(as.subspan(1, 1)[-1]);
CHECK(as.subspan(1)[0] == 1);
CHECK(as.subspan(2)[0] == 2);
CHECK(as.subspan(3)[0] == 3);
}
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);
@@ -612,6 +717,8 @@ TEST_CASE("Span constness") {
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);
@@ -659,6 +766,7 @@ TEST_CASE("PtrOrSpan") {
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);
}
/*************************************************************************
@@ -720,30 +828,52 @@ TEST_CASE("PtrOrSpan char") {
}
TEST_CASE("PtrOrSpan int") {
int buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};
XSPAN_P(int) a(buf, XSpanCount(8));
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(int) b = a.subspan(0, 7);
XSPAN_P(const int) b = a.subspan(0, 7);
CHECK(b.raw_size_in_bytes() == 7 * sizeof(int));
XSPAN_P(int) c = (b + 1).subspan(0, 6);
XSPAN_P(const int) c = (b + 1).subspan(0, 6);
CHECK(c.raw_size_in_bytes() == 6 * sizeof(int));
a += 1;
CHECK(*a == 1);
CHECK(*a++ == 1);
CHECK(*++a == 3);
CHECK(--*a == 2);
CHECK(*a-- == 2);
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 == 1);
a = buf + 7;
CHECK(*c == 11);
a -= 1;
a += 7;
#ifdef UPX_VERSION_HEX
CHECK(get_le32(a) == ne32_to_le32(7));
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);
}
/*************************************************************************
@@ -752,12 +882,15 @@ TEST_CASE("PtrOrSpan int") {
namespace {
template <class T>
__acc_static_noinline int foo(T p) {
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;
}
@@ -779,13 +912,99 @@ make_span_s(T *ptr, size_t count) {
} // namespace
TEST_CASE("Span codegen") {
char buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};
CHECK(foo(buf) == 0 + 2 + 5);
CHECK(foo(make_span_0(buf, 8)) == 0 + 2 + 5);
CHECK(foo(make_span_p(buf, 8)) == 0 + 2 + 5);
CHECK(foo(make_span_s(buf, 8)) == 0 + 2 + 5);
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: */
+25 -7
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -62,7 +62,7 @@ unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
**************************************************************************/
int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_callback_p cb, int method, int level, const upx_compress_config_t *cconf,
upx_callback_t *cb, int method, int level, const upx_compress_config_t *cconf,
upx_compress_result_t *cresult) {
int r = UPX_E_ERROR;
upx_compress_result_t cresult_buffer;
@@ -78,12 +78,12 @@ int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned
// force users to provide *dst_len
assert(*dst_len != 0);
#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));
if (!cresult)
cresult = &cresult_buffer;
memset(cresult, 0, sizeof(*cresult));
cresult->reset();
#if 1
// debugging aid
cresult->debug.method = method;
@@ -92,8 +92,13 @@ int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned
cresult->debug.c_len = 0;
#endif
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)
else if (M_IS_LZMA(method))
r = upx_lzma_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
@@ -111,13 +116,14 @@ int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned
r = upx_zstd_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
#endif
else {
throwInternalError("unknown compression method");
throwInternalError("unknown compression method %d", method);
}
#if 1
// debugging aid
cresult->debug.c_len = *dst_len;
#endif
assert_noexcept(*dst_len <= orig_dst_len);
return r;
}
@@ -135,8 +141,13 @@ int upx_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigne
if (cresult && cresult->debug.method == 0)
cresult = nullptr;
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)
else if (M_IS_LZMA(method))
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
@@ -158,9 +169,10 @@ int upx_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigne
r = upx_zstd_decompress(src, src_len, dst, dst_len, method, cresult);
#endif
else {
throwInternalError("unknown decompression method");
throwInternalError("unknown compression method %d", method);
}
assert_noexcept(*dst_len <= orig_dst_len);
return r;
}
@@ -180,8 +192,13 @@ int upx_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off
unsigned overlap_overhead = src_off + src_len - *dst_len;
assert((int) overlap_overhead > 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)
else if (M_IS_LZMA(method))
r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
@@ -199,9 +216,10 @@ int upx_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off
r = upx_zstd_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif
else {
throwInternalError("unknown decompression method");
throwInternalError("unknown compression method %d", method);
}
assert_noexcept(*dst_len <= orig_dst_len);
return r;
}
+9 -17
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,8 +25,8 @@
*/
#pragma once
#ifndef UPX_COMPRESS_H__
#define UPX_COMPRESS_H__ 1
// clang-format off
/*************************************************************************
//
@@ -37,7 +37,7 @@ 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_p cb,
upx_callback_t *cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
@@ -53,13 +53,12 @@ int upx_bzip2_test_overlap ( const upx_bytep buf,
const upx_compress_result_t *cresult );
#endif
#if (WITH_LZMA)
int upx_lzma_init(void);
const char *upx_lzma_version_string(void);
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned *dst_len,
upx_callback_p cb,
upx_callback_t *cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
@@ -75,13 +74,12 @@ int upx_lzma_test_overlap ( const upx_bytep buf,
const upx_compress_result_t *cresult );
#endif
#if (WITH_NRV)
int upx_nrv_init(void);
const char *upx_nrv_version_string(void);
int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned *dst_len,
upx_callback_p cb,
upx_callback_t *cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
@@ -97,13 +95,12 @@ int upx_nrv_test_overlap ( const upx_bytep buf,
const upx_compress_result_t *cresult );
#endif
#if (WITH_UCL)
int upx_ucl_init(void);
const char *upx_ucl_version_string(void);
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned *dst_len,
upx_callback_p cb,
upx_callback_t *cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
@@ -121,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);
#endif
#if (WITH_ZLIB)
int upx_zlib_init(void);
const char *upx_zlib_version_string(void);
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned *dst_len,
upx_callback_p cb,
upx_callback_t *cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
@@ -145,13 +141,12 @@ unsigned upx_zlib_adler32(const void *buf, unsigned len, unsigned adler);
unsigned upx_zlib_crc32 (const void *buf, unsigned len, unsigned crc);
#endif
#if (WITH_ZSTD)
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_p cb,
upx_callback_t *cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
@@ -167,7 +162,4 @@ int upx_zstd_test_overlap ( const upx_bytep buf,
const upx_compress_result_t *cresult );
#endif
#endif /* already included */
/* vim:set ts=4 sw=4 et: */
+211
View File
@@ -0,0 +1,211 @@
/* 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 "../util/system_headers.h"
#if WITH_BZIP2
#include <bzip2/bzlib.h>
#endif
#include "../conf.h"
void bzip2_compress_config_t::reset() noexcept { mem_clear(this); }
#if WITH_BZIP2
#include "compress.h"
#include "../util/membuffer.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: */
+31 -21
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -41,7 +41,7 @@
#pragma warning(disable : 4127) // warning C4127: conditional expression is constant
#endif
void lzma_compress_config_t::reset() {
void lzma_compress_config_t::reset() noexcept {
pos_bits.reset();
lit_pos_bits.reset();
lit_context_bits.reset();
@@ -116,7 +116,7 @@ static bool prepare_result(lzma_compress_result_t *res, unsigned src_len, int me
res->lit_context_bits = (method >> 8) & 15;
}
#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
// need about 6 MiB of stack during runtime decompression.
res->lit_pos_bits = 4;
@@ -194,8 +194,8 @@ static bool prepare_result(lzma_compress_result_t *res, unsigned src_len, int me
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));
// 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,
res->lit_context_bits, res->dict_size, res->num_probs);
return true;
error:
@@ -206,14 +206,23 @@ error:
// 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 OS2
#undef _WIN32
#undef _WIN32_WCE
#undef COMPRESS_MF_MT
#undef _NO_EXCEPTIONS
#undef NULL
#define NULL nullptr
#include <lzma-sdk/C/Common/MyInitGuid.h>
// #include <lzma-sdk/C/7zip/Compress/LZMA/LZMADecoder.h>
#include <lzma-sdk/C/7zip/Compress/LZMA/LZMAEncoder.h>
@@ -284,7 +293,7 @@ struct ProgressInfo final : public ICompressProgressInfo, public CMyUnknownImp {
virtual ~ProgressInfo() {}
MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) override;
upx_callback_p cb = nullptr;
upx_callback_t *cb = nullptr;
};
STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) {
@@ -308,7 +317,7 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
#undef RC_NORMALIZE
int upx_lzma_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_callback_p cb, int method, int level,
upx_callback_t *cb, int method, int level,
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
assert(M_IS_LZMA(method));
assert(level > 0);
@@ -318,6 +327,7 @@ int upx_lzma_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi
HRESULT rh;
const lzma_compress_config_t *const lcconf = cconf_parm ? &cconf_parm->conf_lzma : nullptr;
lzma_compress_result_t *const res = &cresult->result_lzma;
res->reset();
MyLzma::InStream is;
is.AddRef();
@@ -375,7 +385,7 @@ int upx_lzma_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi
// UPX extra stuff in first byte: 5 high bits convenience for stub decompressor
unsigned t = res->lit_context_bits + res->lit_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);
@@ -399,10 +409,10 @@ int upx_lzma_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi
error:
*dst_len = (unsigned) os.b_pos;
// printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits,
// res->lit_pos_bits,
// res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
// printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
NO_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("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
return r;
}
@@ -426,7 +436,7 @@ int upx_lzma_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, un
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
CLzmaDecoderState s;
memset(&s, 0, sizeof(s));
mem_clear(&s);
SizeT src_out = 0, dst_out = 0;
int r = UPX_E_ERROR;
int rh;
@@ -458,8 +468,8 @@ int upx_lzma_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, un
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
assert(cresult->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
const lzma_compress_result_t *res = &cresult->result_lzma;
// 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);
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);
}
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
@@ -524,13 +534,12 @@ const char *upx_lzma_version_string(void) { return "4.43"; }
**************************************************************************/
TEST_CASE("upx_lzma_decompress") {
typedef const upx_byte C;
C *c_data;
upx_byte d_buf[16];
const byte *c_data;
byte d_buf[16];
unsigned d_len;
int r;
c_data = (C *) "\x1a\x03\x00\x7f\xed\x3c\x00\x00\x00";
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));
@@ -539,6 +548,7 @@ TEST_CASE("upx_lzma_decompress") {
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: */
+15 -13
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -56,6 +56,8 @@ static int convert_errno_from_ucl(int r) {
// UCL extra:
case UCL_E_OVERLAP_OVERRUN:
return UPX_E_ERROR;
default:
break;
}
return UPX_E_ERROR;
}
@@ -64,7 +66,7 @@ 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;
upx_callback_t *cb = (upx_callback_t *) user;
if (cb && cb->nprogress)
cb->nprogress(cb, a, b);
}
@@ -75,7 +77,7 @@ static void __UCL_CDECL wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, uc
**************************************************************************/
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,
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);
@@ -113,14 +115,14 @@ int upx_ucl_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsig
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};
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 parms
// 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)
@@ -241,9 +243,9 @@ int upx_ucl_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src
**************************************************************************/
extern "C" {
static ucl_voidp __UCL_CDECL my_malloc(ucl_uint n) { return calloc(1, n); }
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)
@@ -327,13 +329,12 @@ TEST_CASE("compress_ucl") {
#endif // DEBUG
TEST_CASE("upx_ucl_decompress") {
typedef const upx_byte C;
C *c_data;
upx_byte d_buf[16];
const byte *c_data;
byte d_buf[16];
unsigned d_len;
int r;
c_data = (C *) "\x92\xff\x10\x00\x00\x00\x00\x00\x48\xff";
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));
@@ -343,7 +344,7 @@ TEST_CASE("upx_ucl_decompress") {
r = upx_ucl_decompress(c_data, 10, d_buf, &d_len, M_NRV2B_8, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
c_data = (C *) "\x92\xff\x10\x92\x49\x24\x92\xa0\xff";
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));
@@ -353,7 +354,7 @@ TEST_CASE("upx_ucl_decompress") {
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2D_8, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
c_data = (C *) "\x90\xff\xb0\x92\x49\x24\x92\xa0\xff";
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));
@@ -362,6 +363,7 @@ TEST_CASE("upx_ucl_decompress") {
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: */
+16 -13
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -27,12 +27,14 @@
#include "../conf.h"
#include "compress.h"
#include "../util/membuffer.h"
// NOLINTBEGIN(clang-analyzer-optin.performance.Padding)
#define ZLIB_CONST 1
#include <zlib/zlib.h>
#include <zlib/deflate.h>
// NOLINTEND(clang-analyzer-optin.performance.Padding)
void zlib_compress_config_t::reset() {
mem_clear(this, sizeof(*this));
void zlib_compress_config_t::reset() noexcept {
mem_clear(this);
mem_level.reset();
window_bits.reset();
strategy.reset();
@@ -62,6 +64,8 @@ static int convert_errno_from_zlib(int zr) {
return UPX_E_ERROR;
case -7: // UPX extra
return UPX_E_INPUT_OVERRUN;
default:
break;
}
return UPX_E_ERROR;
}
@@ -71,7 +75,7 @@ static int convert_errno_from_zlib(int zr) {
**************************************************************************/
int upx_zlib_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_callback_p cb_parm, int method, int level,
upx_callback_t *cb_parm, int method, int level,
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
assert(method == M_DEFLATE);
assert(level > 0);
@@ -81,6 +85,7 @@ int upx_zlib_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi
int zr;
const zlib_compress_config_t *const lcconf = cconf_parm ? &cconf_parm->conf_zlib : nullptr;
zlib_compress_result_t *const res = &cresult->result_zlib;
res->reset();
if (level == 10)
level = 9;
@@ -95,12 +100,10 @@ int upx_zlib_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi
oassign(strategy, lcconf->strategy);
}
res->dummy = 0;
z_stream s;
s.zalloc = (alloc_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.next_out = dst;
s.avail_out = *dst_len;
@@ -149,7 +152,7 @@ int upx_zlib_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, un
z_stream s;
s.zalloc = (alloc_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.next_out = dst;
s.avail_out = *dst_len;
@@ -287,13 +290,12 @@ TEST_CASE("compress_zlib") {
#endif // DEBUG
TEST_CASE("upx_zlib_decompress") {
typedef const upx_byte C;
C *c_data;
upx_byte d_buf[16];
const byte *c_data;
byte d_buf[16];
unsigned d_len;
int r;
c_data = (C *) "\xfb\xff\x1f\x15\x00\x00";
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));
@@ -302,6 +304,7 @@ TEST_CASE("upx_zlib_decompress") {
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: */
+14 -12
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -24,16 +24,19 @@
<markus@oberhumer.com>
*/
#include "../util/system_headers.h"
#if WITH_ZSTD
#include <zstd/lib/zstd.h>
#include <zstd/lib/zstd_errors.h>
#include <zstd/lib/compress/hist.h>
#endif
#include "../conf.h"
void zstd_compress_config_t::reset() { mem_clear(this, sizeof(*this)); }
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);
@@ -55,7 +58,7 @@ static int convert_errno_from_zstd(size_t zr) {
**************************************************************************/
int upx_zstd_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_callback_p cb_parm, int method, int level,
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);
@@ -65,6 +68,7 @@ int upx_zstd_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi
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)
@@ -75,8 +79,6 @@ int upx_zstd_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsi
UNUSED(lcconf);
}
res->dummy = 0;
zr = ZSTD_compress(dst, *dst_len, src, src_len, level);
if (ZSTD_isError(zr)) {
*dst_len = 0; // TODO ???
@@ -207,13 +209,12 @@ TEST_CASE("compress_zstd") {
#endif // DEBUG
TEST_CASE("upx_zstd_decompress") {
typedef const upx_byte C;
C *c_data;
upx_byte d_buf[32];
const byte *c_data;
byte d_buf[32];
unsigned d_len;
int r;
c_data = (C *) "\x28\xb5\x2f\xfd\x20\x20\x3d\x00\x00\x08\xff\x01\x00\x34\x4e\x08";
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));
@@ -222,6 +223,7 @@ TEST_CASE("upx_zstd_decompress") {
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
+325 -356
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+27 -20
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,10 +25,19 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#define WANT_WINDOWS_LEAN_H 1
#include "../util/system_headers.h"
#if (HAVE_CONIO_H)
#include <conio.h>
#endif
#include "../conf.h"
#if (USE_SCREEN_WIN32)
/*************************************************************************
// direct screen access
**************************************************************************/
#include "screen.h"
#define this self
@@ -36,24 +45,6 @@
#define mask_fg 0x0f
#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 {
HANDLE hi;
HANDLE ho;
@@ -266,6 +257,22 @@ static int init(screen_t *this, int fd) {
#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_y = csbi->dwCursorPosition.Y;
+2 -6
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -26,8 +26,6 @@
*/
#pragma once
#ifndef UPX_SCREEN_H__
#define UPX_SCREEN_H__ 1
#if (USE_SCREEN)
@@ -100,6 +98,4 @@ void screen_show_frames(screen_t *);
#endif /* USE_SCREEN */
#endif /* already included */
/* vim:set ts=4 sw=4 et: */
+74 -22
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -31,39 +31,41 @@
//
**************************************************************************/
unsigned long Throwable::counter = 0;
/*static*/ Throwable::Stats Throwable::stats;
Throwable::Throwable(const char *m, int e, bool w) noexcept : super(),
msg(nullptr),
err(e),
is_warning(w) {
if (m)
if (m != nullptr) {
msg = strdup(m);
#if 0
fprintf(stderr, "construct exception: %s %lu\n", msg, counter);
counter++;
#endif
assert_noexcept(msg != nullptr);
}
NO_fprintf(stderr, "construct exception: %zu %zu %s\n", size_t(stats.counter_current),
size_t(stats.counter_total), (const char *) msg);
stats.counter_current += 1;
stats.counter_total += 1;
}
Throwable::Throwable(const Throwable &other) noexcept : super(other),
msg(nullptr),
err(other.err),
is_warning(other.is_warning) {
if (other.msg)
if (other.msg != nullptr) {
msg = strdup(other.msg);
#if 0
fprintf(stderr, "copy exception: %s %lu\n", msg, counter);
counter++;
#endif
assert_noexcept(msg != nullptr);
}
NO_fprintf(stderr, "copy construct exception: %zu %zu %s\n", size_t(stats.counter_current),
size_t(stats.counter_total), (const char *) msg);
stats.counter_current += 1;
stats.counter_total += 1;
}
Throwable::~Throwable() noexcept {
#if 0
counter--;
fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
#endif
if (msg)
free(msg);
stats.counter_current -= 1;
NO_fprintf(stderr, "destruct exception: %zu %zu %s\n", size_t(stats.counter_current),
size_t(stats.counter_total), (const char *) msg);
upx::owner_free(msg);
}
/*************************************************************************
@@ -72,7 +74,9 @@ Throwable::~Throwable() noexcept {
void throwCantPack(const char *msg) {
// 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);
else if (opt->cmd == CMD_FILEINFO)
throw CantPackException(msg);
@@ -140,9 +144,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 {
if (n == nullptr)
return "(null)";
@@ -151,7 +203,7 @@ const char *prettyName(const char *n) noexcept {
n++;
else if (*n == ' ')
n++;
else if (strncmp(n, "class ", 6) == 0) // Visual C++
else if (strncmp(n, "class ", 6) == 0) // Visual C++ (msvc)
n += 6;
else
break;
+60 -70
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -26,12 +26,6 @@
*/
#pragma once
#ifndef UPX_EXCEPT_H__
#define UPX_EXCEPT_H__ 1
#ifdef __cplusplus
const char *prettyName(const char *n) noexcept;
/*************************************************************************
// exceptions
@@ -44,33 +38,40 @@ protected:
Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
public:
Throwable(const Throwable &) noexcept;
Throwable(const Throwable &) noexcept; // copy constructor
virtual ~Throwable() noexcept;
const char *getMsg() const noexcept { return msg; }
int getErrno() const noexcept { return err; }
bool isWarning() const noexcept { return is_warning; }
private:
char *msg = nullptr;
OwningPointer(char) msg = nullptr;
int err = 0;
protected:
bool is_warning = false; // can be set by subclasses
private:
// disable assignment
Throwable &operator=(const Throwable &) = delete;
// disable copy assignment and move
Throwable &operator=(const Throwable &) noexcept DELETED_FUNCTION; // copy assignment
UPX_CXX_DISABLE_MOVE(Throwable)
// 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:
static unsigned long counter; // for debugging
// static debug stats
struct Stats {
upx_std_atomic(size_t) counter_total;
upx_std_atomic(size_t) counter_current;
};
static Stats stats;
};
// Exceptions can/should be caught
class Exception : public Throwable {
typedef Throwable super;
public:
Exception(const char *m = nullptr, int e = 0, bool w = false) noexcept : super(m, e, w) {}
};
@@ -78,46 +79,40 @@ public:
// Errors should not be caught (or re-thrown)
class Error : public Throwable {
typedef Throwable super;
public:
Error(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
/*************************************************************************
// system exception
// system exceptions
**************************************************************************/
class OutOfMemoryException : public Exception {
class OutOfMemoryException final : public Exception {
typedef Exception super;
public:
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;
public:
IOException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
class EOFException : public IOException {
class EOFException final : public IOException {
typedef IOException super;
public:
EOFException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
class FileNotFoundException : public IOException {
class FileNotFoundException final : public IOException {
typedef IOException super;
public:
FileNotFoundException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
class FileAlreadyExistsException : public IOException {
class FileAlreadyExistsException final : public IOException {
typedef IOException super;
public:
FileAlreadyExistsException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
@@ -126,52 +121,45 @@ public:
// application exceptions
**************************************************************************/
class OverlayException : public Exception {
class OverlayException final : public Exception {
typedef Exception super;
public:
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;
public:
CantPackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
};
class UnknownExecutableFormatException : public CantPackException {
typedef CantPackException super;
public:
UnknownExecutableFormatException(const char *m = nullptr, bool w = false) noexcept
: super(m, w) {}
};
class AlreadyPackedException : public CantPackException {
class AlreadyPackedException final : public CantPackException {
typedef CantPackException super;
public:
AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
};
class NotCompressibleException : public CantPackException {
class NotCompressibleException final : public CantPackException {
typedef CantPackException super;
public:
NotCompressibleException(const char *m = nullptr) noexcept : super(m) {}
};
class CantUnpackException : public Exception {
class CantUnpackException /*not_final*/ : public Exception {
typedef Exception super;
public:
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;
public:
NotPackedException(const char *m = nullptr) noexcept : super(m, true) {}
};
@@ -180,9 +168,8 @@ public:
// errors
**************************************************************************/
class InternalError : public Error {
class InternalError final : public Error {
typedef Error super;
public:
InternalError(const char *m = nullptr) noexcept : super(m, 0) {}
};
@@ -191,34 +178,37 @@ public:
// util
**************************************************************************/
#undef NORET
#if 1 && defined(__GNUC__)
#define NORET __acc_noinline __attribute__((__noreturn__))
#else
#define NORET __acc_noinline
#endif
const char *prettyName(const char *n) noexcept;
NORET void throwCantPack(const char *msg);
NORET void throwCantPackExact();
NORET void throwUnknownExecutableFormat(const char *msg = nullptr, bool warn = false);
NORET void throwNotCompressible(const char *msg = nullptr);
NORET void throwAlreadyPacked(const char *msg = nullptr);
NORET void throwAlreadyPackedByUPX(const char *msg = nullptr);
NORET void throwCantUnpack(const char *msg);
NORET void throwNotPacked(const char *msg = nullptr);
NORET void throwFilterException();
NORET void throwBadLoader();
NORET void throwChecksumError();
NORET void throwCompressedDataViolation();
NORET void throwInternalError(const char *msg);
NORET void throwOutOfMemoryException(const char *msg = nullptr);
NORET void throwIOException(const char *msg = nullptr, int e = 0);
NORET void throwEOFException(const char *msg = nullptr, int e = 0);
noreturn void throwCantPack(const char *msg) may_throw;
noreturn void throwCantPackExact() may_throw;
noreturn void throwUnknownExecutableFormat(const char *msg = nullptr, bool warn = false) may_throw;
noreturn void throwNotCompressible(const char *msg = nullptr) may_throw;
noreturn void throwAlreadyPacked(const char *msg = nullptr) may_throw;
noreturn void throwAlreadyPackedByUPX(const char *msg = nullptr) may_throw;
noreturn void throwCantUnpack(const char *msg) may_throw;
noreturn void throwNotPacked(const char *msg = nullptr) may_throw;
noreturn void throwFilterException() may_throw;
noreturn void throwBadLoader() may_throw;
noreturn void throwChecksumError() may_throw;
noreturn void throwCompressedDataViolation() may_throw;
noreturn void throwInternalError(const char *msg) may_throw;
noreturn void throwOutOfMemoryException(const char *msg = nullptr) may_throw;
noreturn void throwIOException(const char *msg = nullptr, int e = 0) may_throw;
noreturn void throwEOFException(const char *msg = nullptr, int e = 0) may_throw;
#undef NORET
#endif /* __cplusplus */
#endif /* already included */
// some C++ template wizardry is needed to overload throwCantPack() for varargs
template <class T>
void throwCantPack(const T *, ...) DELETED_FUNCTION;
template <>
noreturn void throwCantPack(const char *format, ...) may_throw attribute_format(1, 2);
template <class T>
void throwCantUnpack(const T *, ...) DELETED_FUNCTION;
template <>
noreturn void throwCantUnpack(const char *format, ...) may_throw attribute_format(1, 2);
template <class T>
void throwInternalError(const T *, ...) DELETED_FUNCTION;
template <>
noreturn void throwInternalError(const char *format, ...) may_throw attribute_format(1, 2);
/* vim:set ts=4 sw=4 et: */
+81 -53
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -29,11 +29,12 @@
#include "file.h"
/*************************************************************************
// static functions
// static file-related util functions; will throw on error
**************************************************************************/
void FileBase::chmod(const char *name, int mode) {
#if (HAVE_CHMOD)
/*static*/ void FileBase::chmod(const char *name, int mode) {
assert(name != nullptr && name[0] != 0);
#if HAVE_CHMOD
if (::chmod(name, mode) != 0)
throwIOException(name, errno);
#else
@@ -42,7 +43,7 @@ void FileBase::chmod(const char *name, int mode) {
#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 (::_rename(old_, new_) != 0)
#else
@@ -51,29 +52,34 @@ void FileBase::rename(const char *old_, const char *new_) {
throwIOException("rename error", errno);
}
void FileBase::unlink(const char *name) {
if (::unlink(name) != 0)
/*static*/ bool FileBase::unlink_noexcept(const char *name) noexcept {
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);
}
/*************************************************************************
//
// FileBase
**************************************************************************/
FileBase::FileBase()
: _fd(-1), _flags(0), _shflags(0), _mode(0), _name(nullptr), _offset(0), _length(0) {
memset(&st, 0, sizeof(st));
}
FileBase::~FileBase() {
FileBase::~FileBase() may_throw {
#if 0 && defined(__GNUC__) // debug
if (isOpen())
fprintf(stderr, "%s: %s\n", _name, __PRETTY_FUNCTION__);
#endif
// FIXME: we should use close() during exception unwinding but
// closex() otherwise
closex();
if (std::uncaught_exceptions() == 0)
closex(); // may_throw
else
close_noexcept(); // currently in exception unwinding, use noexcept variant
}
bool FileBase::do_sopen() {
@@ -98,7 +104,7 @@ bool FileBase::do_sopen() {
return true;
}
bool FileBase::close() {
bool FileBase::close_noexcept() noexcept {
bool ok = true;
if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO)
if (::close(_fd) == -1)
@@ -112,8 +118,8 @@ bool FileBase::close() {
return ok;
}
void FileBase::closex() {
if (!close())
void FileBase::closex() may_throw {
if (!close_noexcept())
throwIOException("close failed", errno);
}
@@ -126,18 +132,18 @@ upx_off_t FileBase::seek(upx_off_t off, int whence) {
if (off < 0)
throwIOException("bad seek 2");
off += _offset;
}
if (whence == SEEK_END) {
} else if (whence == SEEK_END) {
if (off > 0)
throwIOException("bad seek 3");
off += _offset + _length;
whence = SEEK_SET;
}
// SEEK_CUR falls through to here
upx_off_t rv = ::lseek(_fd, off, whence);
if (rv < 0)
} else if (whence == SEEK_CUR) {
} else
throwInternalError("bad seek: whence");
upx_off_t l = ::lseek(_fd, off, whence);
if (l < 0)
throwIOException("seek error", errno);
return rv - _offset;
return l - _offset;
}
upx_off_t FileBase::tell() const {
@@ -157,13 +163,11 @@ void FileBase::set_extent(upx_off_t offset, upx_off_t length) {
upx_off_t FileBase::st_size() const { return _length; }
/*************************************************************************
//
// InputFile
**************************************************************************/
InputFile::InputFile() {}
void InputFile::sopen(const char *name, int flags, int shflags) {
close();
closex();
_name = name;
_flags = flags;
_shflags = shflags;
@@ -181,10 +185,10 @@ void InputFile::sopen(const char *name, int flags, int shflags) {
_length_orig = _length;
}
int InputFile::read(SPAN_P(void) buf, int len) {
if (!isOpen() || len < 0)
int InputFile::read(SPAN_P(void) buf, upx_int64_t blen) {
if (!isOpen() || blen < 0)
throwIOException("bad read");
mem_size_assert(1, len); // sanity check
int len = (int) mem_size(1, blen); // sanity check
errno = 0;
long l = acc_safe_hread(_fd, raw_bytes(buf, len), len);
if (errno)
@@ -192,9 +196,9 @@ int InputFile::read(SPAN_P(void) buf, int len) {
return (int) l;
}
int InputFile::readx(SPAN_P(void) buf, int len) {
int l = this->read(buf, len);
if (l != len)
int InputFile::readx(SPAN_P(void) buf, upx_int64_t blen) {
int l = this->read(buf, blen);
if (l != blen)
throwEOFException();
return l;
}
@@ -209,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; }
/*************************************************************************
//
// OutputFile
**************************************************************************/
OutputFile::OutputFile() : bytes_written(0) {}
void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
close();
closex();
_name = name;
_flags = flags;
_shflags = shflags;
@@ -237,7 +239,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
}
bool OutputFile::openStdout(int flags, bool force) {
close();
closex();
int fd = STDOUT_FILENO;
if (!force && acc_isatty(fd))
return false;
@@ -253,22 +255,33 @@ bool OutputFile::openStdout(int flags, bool force) {
return true;
}
void OutputFile::write(SPAN_0(const void) buf, int len) {
if (!isOpen() || len < 0)
void OutputFile::write(SPAN_0(const void) buf, upx_int64_t blen) {
if (!isOpen() || blen < 0)
throwIOException("bad write");
// allow nullptr if len == 0
if (len == 0)
// allow nullptr if blen == 0
if (blen == 0)
return;
mem_size_assert(1, len); // sanity check
int len = (int) mem_size(1, blen); // sanity check
errno = 0;
#if 0
fprintf(stderr, "write %p %zd (%p) %d\n", buf.raw_ptr(), buf.raw_size_in_bytes(),
#if WITH_XSPAN >= 2
NO_fprintf(stderr, "write %p %zd (%p) %d\n", buf.raw_ptr(), buf.raw_size_in_bytes(),
buf.raw_base(), len);
#endif
long l = acc_safe_hwrite(_fd, raw_bytes(buf, len), len);
if (l != len)
throwIOException("write error", errno);
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 {
@@ -319,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) {
super::set_extent(offset, length);
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)
throwIOException(_name, errno);
_length = st.st_size - offset;
@@ -336,7 +349,7 @@ upx_off_t OutputFile::unset_extent() {
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)
flags = O_CREAT | O_TRUNC;
flags |= O_WRONLY | O_BINARY;
@@ -346,4 +359,19 @@ void OutputFile::dump(const char *name, SPAN_P(const void) buf, int len, int fla
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: */
+21 -26
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -26,8 +26,6 @@
*/
#pragma once
#ifndef UPX_FILE_H__
#define UPX_FILE_H__ 1
/*************************************************************************
//
@@ -35,15 +33,15 @@
class FileBase {
protected:
FileBase();
virtual ~FileBase();
explicit FileBase() noexcept = default;
virtual ~FileBase() may_throw;
public:
bool close();
void closex();
bool isOpen() const { return _fd >= 0; }
int getFd() const { return _fd; }
const char *getName() const { return _name; }
bool close_noexcept() noexcept;
void closex() may_throw;
bool isOpen() const noexcept { return _fd >= 0; }
int getFd() const noexcept { return _fd; }
const char *getName() const noexcept { return _name; }
virtual upx_off_t seek(upx_off_t off, int whence);
upx_off_t tell() const;
@@ -51,10 +49,11 @@ public:
virtual void set_extent(upx_off_t offset, upx_off_t length);
public:
// static file-related util functions
static void chmod(const char *name, int mode);
static void rename(const char *old_, const char *new_);
static void unlink(const char *name);
// static file-related util functions; will throw on error
static void chmod(const char *name, int mode) may_throw;
static void rename(const char *old_, const char *new_) may_throw;
static void unlink(const char *name) may_throw;
static bool unlink_noexcept(const char *name) noexcept;
protected:
bool do_sopen();
@@ -78,14 +77,13 @@ class InputFile final : public FileBase {
typedef FileBase super;
public:
InputFile();
virtual ~InputFile() {}
explicit InputFile() noexcept = default;
void sopen(const char *name, int flags, int shflags);
void open(const char *name, int flags) { sopen(name, flags, -1); }
int read(SPAN_P(void) buf, int len);
int readx(SPAN_P(void) buf, int len);
int read(SPAN_P(void) buf, upx_int64_t blen);
int readx(SPAN_P(void) buf, upx_int64_t blen);
virtual upx_off_t seek(upx_off_t off, int whence) override;
upx_off_t st_size_orig() const;
@@ -102,15 +100,14 @@ class OutputFile final : public FileBase {
typedef FileBase super;
public:
OutputFile();
virtual ~OutputFile() {}
explicit OutputFile() noexcept = default;
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); }
bool openStdout(int flags = 0, bool force = false);
// info: allow nullptr if len == 0
void write(SPAN_0(const void) buf, int len);
// info: allow nullptr if blen == 0
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 st_size() const override; // { return _length; }
@@ -119,7 +116,7 @@ public:
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);
// util
@@ -129,6 +126,4 @@ protected:
upx_off_t bytes_written = 0;
};
#endif
/* vim:set ts=4 sw=4 et: */
+26 -22
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -33,7 +33,7 @@
// util
**************************************************************************/
static void initFilter(Filter *f, upx_byte *buf, unsigned buf_len) {
static void initFilter(Filter *f, byte *buf, unsigned buf_len) noexcept {
f->buf = buf;
f->buf_len = buf_len;
// clear output parameters
@@ -44,38 +44,37 @@ static void initFilter(Filter *f, upx_byte *buf, unsigned buf_len) {
// get a FilterEntry
**************************************************************************/
const FilterImpl::FilterEntry *FilterImpl::getFilter(int id) {
static bool done = false;
static unsigned char filter_map[256];
/*static*/ const FilterImpl::FilterEntry *FilterImpl::getFilter(int id) {
static upx_uint8_t filter_map[256];
static upx_std_once_flag init_done;
if (!done) {
// init the filter_map[]
assert(n_filters <= 254); // as 0xff means "empty slot"
upx_std_call_once(init_done, []() noexcept {
// init the filter_map[] (using a lambda function)
assert_noexcept(n_filters <= 254); // as 0xff means "empty slot"
memset(filter_map, 0xff, sizeof(filter_map));
for (int i = 0; i < n_filters; i++) {
int filter_id = filters[i].id;
assert(filter_id >= 0 && filter_id <= 255);
assert(filter_map[filter_id] == 0xff);
filter_map[filter_id] = (unsigned char) i;
}
done = true;
assert_noexcept(filter_id >= 0 && filter_id <= 255);
assert_noexcept(filter_map[filter_id] == 0xff);
filter_map[filter_id] = (upx_uint8_t) i;
}
});
if (id < 0 || id > 255)
return nullptr;
unsigned index = filter_map[id];
if (index == 0xff) // empty slot
return nullptr;
assert(filters[index].id == id);
assert_noexcept(filters[index].id == id);
return &filters[index];
}
bool Filter::isValidFilter(int filter_id) {
/*static*/ bool Filter::isValidFilter(int filter_id) {
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(filter_id);
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))
return false;
if (filter_id == 0)
@@ -92,7 +91,9 @@ bool Filter::isValidFilter(int filter_id, const int *allowed_filters) {
// 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_;
initFilter(this, nullptr, 0);
// clear input parameters
@@ -103,7 +104,8 @@ void Filter::init(int id_, unsigned addvalue_) {
this->n_mru = 0;
}
bool Filter::filter(upx_byte *buf_, unsigned buf_len_) {
bool Filter::filter(SPAN_0(byte) xbuf, unsigned buf_len_) {
byte *const buf_ = raw_bytes(xbuf, buf_len_);
initFilter(this, buf_, buf_len_);
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
@@ -134,7 +136,8 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_) {
return false;
}
void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum) {
void Filter::unfilter(SPAN_0(byte) xbuf, unsigned buf_len_, bool verify_checksum) {
byte *const buf_ = raw_bytes(xbuf, buf_len_);
initFilter(this, buf_, buf_len_);
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
@@ -178,10 +181,11 @@ void Filter::verifyUnfilter() {
unfilter(this->buf, this->buf_len, true);
}
bool Filter::scan(const upx_byte *buf_, unsigned buf_len_) {
bool Filter::scan(SPAN_0(const byte) xbuf, unsigned buf_len_) {
const byte *const buf_ = raw_bytes(xbuf, buf_len_);
// Note: must use const_cast here. This is fine as the scan
// 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_);
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
+13 -18
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -26,8 +26,6 @@
*/
#pragma once
#ifndef UPX_FILTER_H__
#define UPX_FILTER_H__ 1
/*************************************************************************
// A filter is a reversible operation that modifies a given
@@ -46,18 +44,15 @@
// to absolute addresses so that the buffer compresses better.
**************************************************************************/
class Filter {
class Filter final {
public:
Filter(int level) {
clevel = level;
init();
}
void init(int id = 0, unsigned addvalue = 0);
explicit Filter(int level) noexcept;
void init(int id = 0, unsigned addvalue = 0) noexcept;
bool filter(upx_byte *buf, unsigned buf_len);
void unfilter(upx_byte *buf, unsigned buf_len, bool verify_checksum = false);
bool filter(SPAN_0(byte) buf, unsigned buf_len);
void unfilter(SPAN_0(byte) buf, unsigned buf_len, bool verify_checksum = false);
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, const int *allowed_filters);
@@ -65,7 +60,7 @@ public:
public:
// Will be set by each call to filter()/unfilter().
// Read-only afterwards.
upx_byte *buf = nullptr;
byte *buf = nullptr;
unsigned buf_len = 0;
// Checksum of the buffer before applying the filter
@@ -77,7 +72,7 @@ public:
const int *preferred_ctos = nullptr;
// 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.
unsigned calls;
@@ -101,10 +96,12 @@ private:
// This class is private to Filter - don't look.
**************************************************************************/
class FilterImpl {
class FilterImpl final {
friend class Filter;
private:
explicit FilterImpl() noexcept DELETED_FUNCTION;
struct FilterEntry {
int id; // 0 .. 255
unsigned min_buf_len;
@@ -123,6 +120,4 @@ private:
static const int n_filters; // number of filters[]
};
#endif /* already included */
/* vim:set ts=4 sw=4 et: */
+134 -203
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,18 +25,15 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
/*************************************************************************
// 16-bit calltrick ("naive")
**************************************************************************/
#define CT16(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 3; \
byte *b = f->buf; \
byte *b_end = b + f->buf_len - 3; \
do { \
if (cond) \
{ \
if (cond) { \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
@@ -45,177 +42,126 @@
b += 2 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 2; \
if (f->lastcall) \
f->lastcall += 2; \
return 0;
// filter: e8, e9, e8e9
static int f_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16)
}
static int f_ct16_e8(Filter *f) { CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16) }
static int f_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_le16)
}
static int f_ct16_e9(Filter *f) { 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)
}
// unfilter: e8, e9, e8e9
static int u_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16)
}
static int u_ct16_e8(Filter *f) { CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16) }
static int u_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
}
static int u_ct16_e9(Filter *f) { 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)
}
// scan: e8, e9, e8e9
static int s_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e8(Filter *f) { CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy) }
static int s_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e9(Filter *f) { 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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
#undef CT16
/*************************************************************************
// 32-bit calltrick ("naive")
**************************************************************************/
#define CT32(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 5; \
byte *b = f->buf; \
byte *b_end = b + f->buf_len - 5; \
do { \
if (cond) \
{ \
if (cond) { \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
@@ -224,163 +170,115 @@ static int s_ct16_e8e9_bswap_be(Filter *f)
b += 4 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 4; \
if (f->lastcall) \
f->lastcall += 4; \
return 0;
// filter: e8, e9, e8e9
static int f_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32)
}
static int f_ct32_e8(Filter *f) { CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32) }
static int f_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_le32)
}
static int f_ct32_e9(Filter *f) { 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)
}
// unfilter: e8, e9, e8e9
static int u_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32)
}
static int u_ct32_e8(Filter *f) { CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32) }
static int u_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
}
static int u_ct32_e9(Filter *f) { 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)
}
// scan: e8, e9, e8e9
static int s_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e8(Filter *f) { CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy) }
static int s_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e9(Filter *f) { 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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
// 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)
}
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)
}
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)
}
#undef CT32
/*************************************************************************
@@ -388,11 +286,10 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
**************************************************************************/
#define CT24ARM_LE(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 4; \
byte *b = f->buf; \
byte *b_end = b + f->buf_len - 4; \
do { \
if (cond) \
{ \
if (cond) { \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
@@ -400,35 +297,31 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
} \
b += 4; \
} while (b < b_end); \
if (f->lastcall) f->lastcall += 4; \
if (f->lastcall) \
f->lastcall += 4; \
return 0;
#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)
}
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)
}
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)
}
#undef CT24ARM_LE
#define CT24ARM_BE(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 4; \
byte *b = f->buf; \
byte *b_end = b + f->buf_len - 4; \
do { \
if (cond) \
{ \
if (cond) { \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(1 + b, get(1 + b) + (addvalue)); \
@@ -436,23 +329,21 @@ static int s_ct24arm_le(Filter *f)
} \
b += 4; \
} while (b < b_end); \
if (f->lastcall) f->lastcall += 4; \
if (f->lastcall) \
f->lastcall += 4; \
return 0;
#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)
}
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)
}
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)
}
@@ -463,12 +354,12 @@ static int s_ct24arm_be(Filter *f)
// 26-bit ARM calltrick ("naive")
**************************************************************************/
#if 1 //{ old reliable
#define CT26ARM_LE(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 4; \
byte *b = f->buf; \
byte *b_end = b + f->buf_len - 4; \
do { \
if (cond) \
{ \
if (cond) { \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
@@ -476,27 +367,67 @@ static int s_ct24arm_be(Filter *f)
} \
b += 4; \
} while (b < b_end); \
if (f->lastcall) f->lastcall += 4; \
if (f->lastcall) \
f->lastcall += 4; \
return 0;
#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)
}
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)
}
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)
}
#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 ARMCT_COND
+18 -36
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,20 +25,17 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
/*************************************************************************
// filter / scan
**************************************************************************/
static int F(Filter *f)
{
static int F(Filter *f) {
#ifdef U
// filter
upx_byte *b = f->buf;
byte *b = f->buf;
#else
// scan
const upx_byte *b = f->buf;
const byte *b = f->buf;
#endif
const unsigned addvalue = f->addvalue;
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
// must not conflict with the mark.
// Note that unsigned comparison checks both edges of buffer.
for (ic = 0; ic < size - 5; ic++)
{
for (ic = 0; ic < size - 5; ic++) {
if (!COND(b, ic))
continue;
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
return -1;
}
else
} else
buf[b[ic + 1]] |= 1;
}
@@ -79,26 +73,22 @@ static int F(Filter *f)
const unsigned cto = (unsigned) f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
for (ic = 0; ic < size - 5; ic++) {
if (!COND(b, ic))
continue;
jc = get_le32(b + ic + 1) + ic + 1;
// try to detect 'real' calls only
if (jc < size)
{
if (jc < size) {
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
#ifdef U
set_be32(b + ic + 1, jc + addvalue + cto);
#endif
if (ic - lastnoncall < 5)
{
if (ic - lastnoncall < 5) {
// check the last 4 bytes before this call
for (kc = 4; kc; kc--)
if (COND(b, ic - kc) && b[ic - kc + 1] == cto8)
break;
if (kc)
{
if (kc) {
#ifdef U
// restore original
set_le32(b + ic + 1, jc - ic - 1);
@@ -113,9 +103,7 @@ static int F(Filter *f)
calls++;
ic += 4;
lastcall = ic + 1;
}
else
{
} else {
assert(b[ic + 1] != cto8); // this should not happen
lastnoncall = ic;
noncalls++;
@@ -133,15 +121,13 @@ static int F(Filter *f)
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
static int U(Filter *f) {
byte *b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned addvalue = f->addvalue;
const unsigned cto = (unsigned) f->cto << 24;
@@ -149,24 +135,20 @@ static int U(Filter *f)
unsigned ic, jc;
for (ic = 0; ic < size5; ic++)
if (COND(b,ic))
{
if (COND(b, ic)) {
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);
f->calls++;
ic += 4;
f->lastcall = ic + 1;
}
else
} else
f->noncalls++;
}
return 0;
}
#endif
#undef F
#undef U
+19 -37
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2023 John F. Reiser
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
Copyright (C) 2000-2024 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -29,20 +29,17 @@
<jreiser@users.sourceforge.net>
*/
/*************************************************************************
// filter / scan
**************************************************************************/
static int F(Filter *f)
{
static int F(Filter *f) {
#ifdef U
// filter
upx_byte *b = f->buf;
byte *b = f->buf;
#else
// scan
const upx_byte *b = f->buf;
const byte *b = f->buf;
#endif
const unsigned addvalue = f->addvalue;
const unsigned size = f->buf_len;
@@ -56,17 +53,14 @@ static int F(Filter *f)
unsigned char buf[256];
memset(buf, 0, 256);
for (ic = 0; ic < size - 5; ic++)
{
for (ic = 0; ic < size - 5; ic++) {
if (!COND(b, ic, lastcall))
continue;
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
return -1;
}
else
} else
buf[b[ic + 1]] |= 1;
}
@@ -78,26 +72,22 @@ static int F(Filter *f)
const unsigned cto = (unsigned) f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
for (ic = 0; ic < size - 5; ic++) {
if (!COND(b, ic, lastcall))
continue;
jc = get_le32(b + ic + 1) + ic + 1;
// try to detect 'real' calls only
if (jc < size)
{
if (jc < size) {
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
#ifdef U
set_be32(b + ic + 1, jc + addvalue + cto);
#endif
if (ic - lastnoncall < 5)
{
if (ic - lastnoncall < 5) {
// check the last 4 bytes before this call
for (kc = 4; kc; kc--)
if (COND(b, ic - kc, lastcall) && b[ic - kc + 1] == cto8)
break;
if (kc)
{
if (kc) {
#ifdef U
// restore original
set_le32(b + ic + 1, jc - ic - 1);
@@ -112,9 +102,7 @@ static int F(Filter *f)
calls++;
ic += 4;
lastcall = ic + 1;
}
else
{
} else {
assert(b[ic + 1] != cto8); // this should not happen
lastnoncall = ic;
noncalls++;
@@ -132,15 +120,13 @@ static int F(Filter *f)
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
static int U(Filter *f) {
byte *b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned addvalue = f->addvalue;
const unsigned cto = (unsigned) f->cto << 24;
@@ -148,24 +134,20 @@ static int U(Filter *f)
unsigned ic, jc;
for (ic = 0; ic < size5; ic++)
if (COND(b,ic,lastcall))
{
if (COND(b, ic, lastcall)) {
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);
f->calls++;
ic += 4;
f->lastcall = ic + 1;
}
else
} else
f->noncalls++;
}
return 0;
}
#endif
#undef F
#undef U
+47 -89
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2023 John F. Reiser
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
Copyright (C) 2000-2024 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -29,12 +29,10 @@
<jreiser@users.sourceforge.net>
*/
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1300))
#pragma warning(disable : 4702) // W4: unreachable code
#endif
/*************************************************************************
// filter / scan
**************************************************************************/
@@ -44,48 +42,32 @@
#define FNOMRU 1 // filter, but not using mru
#define MRUFLT 2 // mru filter
static unsigned
f80_call(Filter const *f)
{
return (1+ (0x0f & f->id)) % 3;
}
static unsigned f80_call(Filter const *f) { return (1 + (0x0f & f->id)) % 3; }
static unsigned
f80_jmp1(Filter const *f)
{
return ((1+ (0x0f & f->id)) / 3) % 3;
}
static unsigned f80_jmp1(Filter const *f) { return ((1 + (0x0f & f->id)) / 3) % 3; }
static unsigned
f80_jcc2(Filter const *f)
{
return f80_jmp1(f);
}
static unsigned f80_jcc2(Filter const *f) { return f80_jmp1(f); }
#define N_MRU 32 // does not have to be a power of 2
// Adaptively remember recent destinations.
static void
update_mru(
unsigned const jc, // destination address
int const kh, // mru[kh] is slot where found
static void update_mru(const unsigned jc, // destination address
const int kh, // mru[kh] is slot where found
unsigned mru[N_MRU], // circular buffer of most recent destinations
int &hand, // mru[hand] is most recent destination
int &tail // mru[tail] is beyond oldest destination ("cold cache" startup)
)
{
) {
if (0 > --hand) {
hand = N_MRU - 1;
}
unsigned const t = mru[hand]; // entry which will be overwritten by jc
const unsigned t = mru[hand]; // entry which will be overwritten by jc
if (0 != t) { // have seen at least N_MRU destinations
mru[kh] = t;
}
else { // "cold cache": keep active region contiguous
} else { // "cold cache": keep active region contiguous
if (0 > --tail) {
tail = N_MRU - 1;
}
unsigned const t2 = mru[tail];
const unsigned t2 = mru[tail];
mru[tail] = 0;
mru[kh] = t2;
}
@@ -93,34 +75,32 @@ update_mru(
}
#endif //}
static int F(Filter *f)
{
static int F(Filter *f) {
#ifdef U
// filter
upx_byte *const b = f->buf;
byte *const b = f->buf;
#else
// scan
const upx_byte *b = f->buf;
const byte *b = f->buf;
#endif
const unsigned size = f->buf_len;
unsigned ic, jc, kc;
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0;
unsigned wtally[3]; memset(wtally, 0, sizeof(wtally));
unsigned wtally[3];
memset(wtally, 0, sizeof(wtally));
#ifdef U //{
unsigned const f_call = f80_call(f);
unsigned const f_jmp1 = f80_jmp1(f);
unsigned const f_jcc2 = f80_jcc2(f);
const unsigned f_call = f80_call(f);
const unsigned f_jmp1 = f80_jmp1(f);
const unsigned f_jcc2 = f80_jcc2(f);
int hand = 0, tail = 0;
unsigned mru[N_MRU];
memset(&mru[0], 0, sizeof(mru));
assert(N_MRU <= 256);
f->n_mru = (MRUFLT==f_call || MRUFLT==f_jmp1 || MRUFLT==f_jcc2) ?
N_MRU : 0;
f->n_mru = (MRUFLT == f_call || MRUFLT == f_jmp1 || MRUFLT == f_jcc2) ? N_MRU : 0;
#endif //}
// 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);
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;
}
UNUSED(which);
@@ -145,8 +124,7 @@ static int F(Filter *f)
const unsigned cto = (unsigned) f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
for (ic = 0; ic < size - 5; ic++) {
int which;
int f_on = 0;
if (!CONDF(which, b, ic, lastcall))
@@ -154,8 +132,7 @@ static int F(Filter *f)
++wtally[which];
jc = get_le32(b + ic + 1) + ic + 1;
// try to detect 'real' calls only
if (jc < size)
{
if (jc < size) {
#ifdef U
if (2 == which && NOFILT != f_jcc2) { // 6-byte Jcc <disp32>
// 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
// will tend to be constant. Swap prefix and opcode
// so that constants are together for better compression.
unsigned char const t =
b[ic-1];
unsigned char const t = b[ic - 1];
b[ic - 1] = b[ic];
b[ic] = t;
}
// FIXME [?]: Extend to 8 bytes if "ADD ESP, byte 4*n" follows CALL.
// This will require two related cto's (consecutive, or otherwise).
if ((0==which && MRUFLT==f_call)
|| (1==which && MRUFLT==f_jmp1)
|| (2==which && MRUFLT==f_jcc2) ) {
if ((0 == which && MRUFLT == f_call) || (1 == which && MRUFLT == f_jmp1) ||
(2 == which && MRUFLT == f_jcc2)) {
f_on = 1;
// Recode the destination: narrower mru indices
// should compress better than wider addresses.
@@ -197,29 +172,24 @@ static int F(Filter *f)
}
mru[hand] = jc;
}
} else
if ((0==which && NOFILT!=f_call)
|| (1==which && NOFILT!=f_jmp1)
|| (2==which && NOFILT!=f_jcc2) ) {
} else if ((0 == which && NOFILT != f_call) || (1 == which && NOFILT != f_jmp1) ||
(2 == which && NOFILT != f_jcc2)) {
f_on = 1;
set_be32(b + ic + 1, jc + cto);
}
#endif
if (f_on) {
if (ic - lastnoncall < 5)
{
if (ic - lastnoncall < 5) {
// check the last 4 bytes before this call
for (kc = 4; kc; kc--)
if (CONDF(which, b, ic - kc, lastcall) && b[ic - kc + 1] == cto8)
break;
if (kc)
{
if (kc) {
#ifdef U
// restore original
if (2 == which) {
// Unswap prefix and opcode for 6-byte Jcc <disp32>
unsigned char const t =
b[ic-1];
unsigned char const t = b[ic - 1];
b[ic - 1] = b[ic];
b[ic] = t;
}
@@ -236,9 +206,7 @@ static int F(Filter *f)
ic += 4;
lastcall = ic + 1;
}
}
else
{
} else {
assert(b[ic + 1] != cto8); // this should not happen
lastnoncall = ic;
noncalls++;
@@ -258,39 +226,34 @@ static int F(Filter *f)
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
static int U(Filter *f) {
unsigned ic, jc;
upx_byte *const b = f->buf;
byte *const b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned cto = (unsigned) f->cto << 24;
unsigned lastcall = 0;
int hand = 0, tail = 0;
unsigned const f_call = f80_call(f);
unsigned const f_jmp1 = f80_jmp1(f);
unsigned const f_jcc2 = f80_jcc2(f);
const unsigned f_call = f80_call(f);
const unsigned f_jmp1 = f80_jmp1(f);
const unsigned f_jcc2 = f80_jcc2(f);
unsigned mru[N_MRU];
memset(&mru[0], 0, sizeof(mru));
for (ic = 0; ic < size5; ic++) {
int which;
if (CONDU(which,b,ic,lastcall))
{
if (CONDU(which, b, ic, lastcall)) {
unsigned f_on = 0;
jc = get_be32(b + ic + 1) - cto;
if (b[ic+1] == f->cto)
{
if ((0==which && MRUFLT==f_call)
|| (1==which && MRUFLT==f_jmp1)
|| (2==which && MRUFLT==f_jcc2) ) {
if (b[ic + 1] == f->cto) {
if ((0 == which && MRUFLT == f_call) || (1 == which && MRUFLT == f_jmp1) ||
(2 == which && MRUFLT == f_jcc2)) {
f_on = 1;
if (1 & jc) { // 1st time at this destination
jc >>= 1;
@@ -298,8 +261,7 @@ static int U(Filter *f)
hand = N_MRU - 1;
}
mru[hand] = jc;
}
else { // not 1st time at this destination
} else { // not 1st time at this destination
jc >>= 1;
if (N_MRU <= jc) {
throwCompressedDataViolation();
@@ -312,17 +274,14 @@ static int U(Filter *f)
update_mru(jc, kh, mru, hand, tail);
}
set_le32(b + ic + 1, jc - ic - 1);
} else
if ((0==which && NOFILT!=f_call)
|| (1==which && NOFILT!=f_jmp1)
|| (2==which && NOFILT!=f_jcc2) ) {
} else if ((0 == which && NOFILT != f_call) || (1 == which && NOFILT != f_jmp1) ||
(2 == which && NOFILT != f_jcc2)) {
f_on = 1;
set_le32(b + ic + 1, jc - ic - 1);
}
if (2 == which && NOFILT != f_jcc2) {
// Unswap prefix and opcode for 6-byte Jcc <disp32>
unsigned char const t =
b[ic-1];
unsigned char const t = b[ic - 1];
b[ic - 1] = b[ic];
b[ic] = t;
}
@@ -332,8 +291,7 @@ static int U(Filter *f)
ic += 4;
f->lastcall = lastcall = ic + 1;
}
}
else
} else
f->noncalls++;
}
}
+21 -39
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2023 John F. Reiser
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
Copyright (C) 2000-2024 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -29,24 +29,21 @@
<jreiser@users.sourceforge.net>
*/
/*************************************************************************
// filter / scan
**************************************************************************/
static int F(Filter *f)
{
static int F(Filter *f) {
#ifdef U
// filter
upx_byte *b = f->buf;
byte *b = f->buf;
#else
// scan
const upx_byte *b = f->buf;
const byte *b = f->buf;
#endif
const unsigned addvalue = f->addvalue;
const unsigned size = f->buf_len;
unsigned const id = f->id;
const unsigned id = f->id;
unsigned ic, jc, kc;
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
@@ -57,17 +54,14 @@ static int F(Filter *f)
unsigned char buf[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))
continue;
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
return -1;
}
else
} else
buf[b[ic + 1]] |= 1;
}
@@ -79,26 +73,22 @@ static int F(Filter *f)
const unsigned cto = (unsigned) f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
for (ic = 0; ic < size - 5; ic++) {
if (!COND(b, ic, lastcall, id))
continue;
jc = get_le32(b + ic + 1) + ic + 1;
// try to detect 'real' calls only
if (jc < size)
{
if (jc < size) {
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
#ifdef U
set_be32(b + ic + 1, jc + addvalue + cto);
#endif
if (ic - lastnoncall < 5)
{
if (ic - lastnoncall < 5) {
// check the last 4 bytes before this call
for (kc = 4; kc; kc--)
if (COND(b, ic - kc, lastcall, id) && b[ic - kc + 1] == cto8)
break;
if (kc)
{
if (kc) {
#ifdef U
// restore original
set_le32(b + ic + 1, jc - ic - 1);
@@ -113,9 +103,7 @@ static int F(Filter *f)
calls++;
ic += 4;
lastcall = ic + 1;
}
else
{
} else {
assert(b[ic + 1] != cto8); // this should not happen
lastnoncall = ic;
noncalls++;
@@ -133,42 +121,36 @@ static int F(Filter *f)
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
static int U(Filter *f) {
byte *b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned addvalue = f->addvalue;
const unsigned cto = (unsigned) f->cto << 24;
unsigned const id = f->id;
const unsigned id = f->id;
unsigned lastcall = 0;
unsigned ic, jc;
for (ic = 0; ic < size5; ic++)
if (COND(b,ic,lastcall,id))
{
if (COND(b, ic, lastcall, id)) {
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);
f->calls++;
ic += 4;
f->lastcall = lastcall = ic + 1;
}
else
} else
f->noncalls++;
}
return 0;
}
#endif
#undef F
#undef U
+26 -53
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,27 +25,22 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
/*************************************************************************
// 16-bit call-/swaptrick ("naive")
**************************************************************************/
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 3; \
byte *b = f->buf; \
byte *b_end = b + f->buf_len - 3; \
do { \
if (cond1) \
{ \
if (cond1) { \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 2 - 1; \
} \
else if (cond2) \
{ \
} else if (cond2) { \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
@@ -54,68 +49,55 @@
b += 2 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 2; \
if (f->lastcall) \
f->lastcall += 2; \
return 0;
// 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)
}
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)
}
// 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)
}
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)
}
// 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)
}
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)
}
#undef CTSW16
/*************************************************************************
// 32-bit call-/swaptrick ("naive")
**************************************************************************/
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 5; \
byte *b = f->buf; \
byte *b_end = b + f->buf_len - 5; \
do { \
if (cond1) \
{ \
if (cond1) { \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 4 - 1; \
} \
else if (cond2) \
{ \
} else if (cond2) { \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
@@ -124,46 +106,37 @@ static int s_ctsw16_e9_e8(Filter *f)
b += 4 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 4; \
if (f->lastcall) \
f->lastcall += 4; \
return 0;
// 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)
}
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)
}
// 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)
}
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)
}
// 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)
}
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)
}
#undef CTSW32
/* vim:set ts=4 sw=4 et: */
+16 -25
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,29 +25,21 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#include "../conf.h"
#include "../filter.h"
static unsigned
umin(unsigned const a, unsigned const b)
{
return (a<=b) ? a : b;
}
static unsigned umin(const unsigned a, const unsigned b) { return (a <= b) ? a : b; }
#define set_dummy(p, v) ((void) 0)
#define get_8(p) (*(p))
#define set_8(p, v) (*(p) = (v))
/*************************************************************************
// util
**************************************************************************/
#include "getcto.h"
/*************************************************************************
// simple filters: calltrick / swaptrick / delta / ...
**************************************************************************/
@@ -60,7 +52,6 @@ umin(unsigned const a, unsigned const b)
#include "sub16.h"
#include "sub32.h"
/*************************************************************************
// cto calltrick
**************************************************************************/
@@ -89,7 +80,6 @@ umin(unsigned const a, unsigned const b)
#include "cto.h"
#undef COND
/*************************************************************************
// cto calltrick with jmp
**************************************************************************/
@@ -102,7 +92,6 @@ umin(unsigned const a, unsigned const b)
#include "ctoj.h"
#undef COND
/*************************************************************************
// cto calltrick with jmp, optional jcc
**************************************************************************/
@@ -119,22 +108,19 @@ umin(unsigned const a, unsigned const b)
#undef COND2
#undef COND1
/*************************************************************************
// cto calltrick with jmp and jcc and relative renumbering
**************************************************************************/
#define COND_CALL(which, b, x) ((which = 0), b[x] == 0xe8)
#define COND_JMP(which, b, x) ((which = 1), b[x] == 0xe9)
#define COND_JCC( which,b,lastcall,x,y,z) ((which = 2), \
(lastcall!=(x) && 0xf==b[y] && 0x80<=b[z] && b[z]<=0x8f))
#define COND_JCC(which, b, lastcall, x, y, z) \
((which = 2), (lastcall != (x) && 0xf == b[y] && 0x80 <= b[z] && b[z] <= 0x8f))
#define COND1(which, b, x) (COND_CALL(which, b, x) || COND_JMP(which, b, x))
#define COND2(which, b, lastcall, x, y, z) COND_JCC(which, b, lastcall, x, y, z)
#define CONDF(which,b,x,lastcall) \
(COND1(which,b,x) || COND2(which,b,lastcall,x,(x)-1, x ))
#define CONDU(which,b,x,lastcall) \
(COND1(which,b,x) || COND2(which,b,lastcall,x, x ,(x)-1))
#define CONDF(which, b, x, lastcall) (COND1(which, b, x) || COND2(which, b, lastcall, x, (x) -1, x))
#define CONDU(which, b, x, lastcall) (COND1(which, b, x) || COND2(which, b, lastcall, x, x, (x) -1))
#define F f_ctojr32_e8e9_bswap_le
#define U u_ctojr32_e8e9_bswap_le
@@ -150,7 +136,6 @@ umin(unsigned const a, unsigned const b)
#undef COND_JMP
#undef COND_CALL
/*************************************************************************
// PowerPC branch [incl. call] trick
**************************************************************************/
@@ -163,12 +148,12 @@ umin(unsigned const a, unsigned const b)
#include "ppcbxx.h"
#undef COND
/*************************************************************************
// database for use in class Filter
**************************************************************************/
const FilterImpl::FilterEntry FilterImpl::filters[] = {
// clang-format off
/*static*/ const FilterImpl::FilterEntry FilterImpl::filters[] = {
// no filter
{ 0x00, 0, 0, nullptr, nullptr, nullptr },
@@ -228,8 +213,13 @@ const FilterImpl::FilterEntry FilterImpl::filters[] = {
{ 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le },
{ 0x51, 8, 0x01ffffff, f_ct24arm_be, u_ct24arm_be, s_ct24arm_be },
#if 1 //{ old reliable
// 26-bit calltrick for arm64
{ 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
{ 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
@@ -260,7 +250,8 @@ const FilterImpl::FilterEntry FilterImpl::filters[] = {
// PowerPC branch+call trick
{ 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx },
};
// clang-format on
const int FilterImpl::n_filters = TABLESIZE(filters);
/*static*/ const int FilterImpl::n_filters = TABLESIZE(filters);
/* vim:set ts=4 sw=4 et: */
+7 -13
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,22 +25,16 @@
<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;
if (f->preferred_ctos)
{
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
{
if (*pc < n && buf[*pc] == 0)
{
if (f->preferred_ctos) {
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++) {
if (*pc < n && buf[*pc] == 0) {
ic = *pc;
break;
}
@@ -63,7 +57,7 @@ static int getcto(Filter *f, const unsigned char *buf, const int n=256)
// throwCantPack("call trick problem");
return -1;
f->cto = (unsigned char) ic;
f->cto = (byte) ic;
return ic;
}
+18 -22
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2004-2023 John F. Reiser
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
Copyright (C) 2004-2024 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -29,23 +29,20 @@
<jreiser@users.sourceforge.net>
*/
/*************************************************************************
// filter / scan
**************************************************************************/
#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
// filter
upx_byte *b = f->buf;
byte *b = f->buf;
const unsigned addvalue = f->addvalue;
#else
// scan
const upx_byte *b = f->buf;
const byte *b = f->buf;
#endif
const unsigned size = umin(f->buf_len, 0u - (~0u << (32 - (6 + W_CTO))));
const unsigned size4 = size - 4;
@@ -63,7 +60,8 @@ static int F(Filter *f)
memset(buf, 0, 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;
if (size <= (off & (~0u << 2)) + ic) {
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);
#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 off = (int) (word << 6) >> 6;
unsigned const jc = (off & (~0u << 2)) + ic;
@@ -95,10 +94,10 @@ static int F(Filter *f)
#endif
calls++;
lastcall = ic;
}
else {
} else {
#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
lastnoncall = ic;
noncalls++;
@@ -117,29 +116,27 @@ static int F(Filter *f)
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
static int U(Filter *f) {
byte *b = f->buf;
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u << (32 - (6 + W_CTO))));
const unsigned addvalue = f->addvalue;
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);
if ((~(~0u << W_CTO) & (word >> (24 + 2 - W_CTO))) == (unsigned) f->cto) {
unsigned const jc = word & (~(~0u << (26 - W_CTO)) & (~0u << 2));
set_be32(b + ic, (0xfc000003 & word) | (0x03fffffc & (jc - ic - addvalue)));
f->calls++;
f->lastcall = ic;
}
else {
} else {
f->noncalls++;
}
}
@@ -147,7 +144,6 @@ static int U(Filter *f)
}
#endif
#undef F
#undef U
+12 -10
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,19 +25,20 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
/*************************************************************************
//
**************************************************************************/
#define SUB(f, N, T, get, set) \
upx_byte *b = f->buf; \
byte *b = f->buf; \
unsigned l = f->buf_len / sizeof(T); \
int i; \
T d[N]; \
\
i = N - 1; do d[i] = 0; while (--i >= 0); \
i = N - 1; \
do \
d[i] = 0; \
while (--i >= 0); \
\
i = N - 1; \
do { \
@@ -52,14 +53,16 @@
assert((int) f->calls > 0); \
return 0;
#define ADD(f, N, T, get, set) \
upx_byte *b = f->buf; \
byte *b = f->buf; \
unsigned l = f->buf_len / sizeof(T); \
int i; \
T d[N]; \
\
i = N - 1; do d[i] = 0; while (--i >= 0); \
i = N - 1; \
do \
d[i] = 0; \
while (--i >= 0); \
\
i = N - 1; \
do { \
@@ -73,7 +76,6 @@
assert((int) f->calls > 0); \
return 0;
#define SCAN(f, N, T, get, set) \
f->calls = (f->buf_len / sizeof(T)) - N; \
assert((int) f->calls > 0); \
+14 -56
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,8 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
/*************************************************************************
//
**************************************************************************/
@@ -37,76 +35,36 @@
#define ADD16(f, N) ADD(f, N, unsigned short, get_le16, set_le16)
#define SCAN16(f, N) SCAN(f, N, unsigned short, get_le16, set_le16)
/*************************************************************************
//
**************************************************************************/
// filter
static int f_sub16_1(Filter *f)
{
SUB16(f, 1)
}
static int f_sub16_1(Filter *f) { SUB16(f, 1) }
static int f_sub16_2(Filter *f)
{
SUB16(f, 2)
}
static int f_sub16_2(Filter *f) { SUB16(f, 2) }
static int f_sub16_3(Filter *f)
{
SUB16(f, 3)
}
static int f_sub16_4(Filter *f)
{
SUB16(f, 4)
}
static int f_sub16_3(Filter *f) { SUB16(f, 3) }
static int f_sub16_4(Filter *f) { SUB16(f, 4) }
// unfilter
static int u_sub16_1(Filter *f)
{
ADD16(f, 1)
}
static int u_sub16_1(Filter *f) { ADD16(f, 1) }
static int u_sub16_2(Filter *f)
{
ADD16(f, 2)
}
static int u_sub16_2(Filter *f) { ADD16(f, 2) }
static int u_sub16_3(Filter *f)
{
ADD16(f, 3)
}
static int u_sub16_4(Filter *f)
{
ADD16(f, 4)
}
static int u_sub16_3(Filter *f) { ADD16(f, 3) }
static int u_sub16_4(Filter *f) { ADD16(f, 4) }
// scan
static int s_sub16_1(Filter *f)
{
SCAN16(f, 1)
}
static int s_sub16_1(Filter *f) { SCAN16(f, 1) }
static int s_sub16_2(Filter *f)
{
SCAN16(f, 2)
}
static int s_sub16_2(Filter *f) { SCAN16(f, 2) }
static int s_sub16_3(Filter *f)
{
SCAN16(f, 3)
}
static int s_sub16_4(Filter *f)
{
SCAN16(f, 4)
}
static int s_sub16_3(Filter *f) { SCAN16(f, 3) }
static int s_sub16_4(Filter *f) { SCAN16(f, 4) }
#undef SUB
#undef ADD
+14 -56
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2024 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -25,8 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
/*************************************************************************
//
**************************************************************************/
@@ -37,76 +35,36 @@
#define ADD32(f, N) ADD(f, N, unsigned int, get_le32, set_le32)
#define SCAN32(f, N) SCAN(f, N, unsigned int, get_le32, set_le32)
/*************************************************************************
//
**************************************************************************/
// filter
static int f_sub32_1(Filter *f)
{
SUB32(f, 1)
}
static int f_sub32_1(Filter *f) { SUB32(f, 1) }
static int f_sub32_2(Filter *f)
{
SUB32(f, 2)
}
static int f_sub32_2(Filter *f) { SUB32(f, 2) }
static int f_sub32_3(Filter *f)
{
SUB32(f, 3)
}
static int f_sub32_4(Filter *f)
{
SUB32(f, 4)
}
static int f_sub32_3(Filter *f) { SUB32(f, 3) }
static int f_sub32_4(Filter *f) { SUB32(f, 4) }
// unfilter
static int u_sub32_1(Filter *f)
{
ADD32(f, 1)
}
static int u_sub32_1(Filter *f) { ADD32(f, 1) }
static int u_sub32_2(Filter *f)
{
ADD32(f, 2)
}
static int u_sub32_2(Filter *f) { ADD32(f, 2) }
static int u_sub32_3(Filter *f)
{
ADD32(f, 3)
}
static int u_sub32_4(Filter *f)
{
ADD32(f, 4)
}
static int u_sub32_3(Filter *f) { ADD32(f, 3) }
static int u_sub32_4(Filter *f) { ADD32(f, 4) }
// scan
static int s_sub32_1(Filter *f)
{
SCAN32(f, 1)
}
static int s_sub32_1(Filter *f) { SCAN32(f, 1) }
static int s_sub32_2(Filter *f)
{
SCAN32(f, 2)
}
static int s_sub32_2(Filter *f) { SCAN32(f, 2) }
static int s_sub32_3(Filter *f)
{
SCAN32(f, 3)
}
static int s_sub32_4(Filter *f)
{
SCAN32(f, 4)
}
static int s_sub32_3(Filter *f) { SCAN32(f, 3) }
static int s_sub32_4(Filter *f) { SCAN32(f, 4) }
#undef SUB
#undef ADD

Some files were not shown because too many files have changed in this diff Show More