Compare commits

..

1469 Commits

Author SHA1 Message Date
Markus F.X.J. Oberhumer 33cdcb0e82 all: prepare for release 2023-01-30 11:18:06 +01:00
Markus F.X.J. Oberhumer ec870a5aeb submodules: update for new versions 2023-01-30 11:10:36 +01:00
Markus F.X.J. Oberhumer 0653bb5a72 src: some xspan cleanups 2023-01-30 11:03:11 +01:00
Markus F.X.J. Oberhumer 43b6ff29e3 all: bump tentative release date 2023-01-29 15:39:35 +01:00
Markus F.X.J. Oberhumer a444a8a704 src: pefile: fix overly tricky canUnpack0 logic 2023-01-29 12:40:00 +01:00
Markus F.X.J. Oberhumer 3fa18c1799 src: clang-format pefile 2023-01-29 12:34:05 +01:00
Markus F.X.J. Oberhumer 19147963b9 src: pefile: try to work-around a scan-build warning 2023-01-29 12:21:15 +01:00
Markus F.X.J. Oberhumer 5056215a1f all: more assorted cleanups 2023-01-29 11:39:57 +01:00
Markus F.X.J. Oberhumer 340b7614e2 submodules: update for new versions 2023-01-26 18:49:14 +01:00
Markus F.X.J. Oberhumer 8a1bd67a20 src: more valgrind integration 2023-01-26 08:50:30 +01:00
Markus F.X.J. Oberhumer a094df7b55 all: more cleanups; NFCI 2023-01-24 21:52:10 +01:00
Markus F.X.J. Oberhumer cc893dfc11 CI: add zigcc and scan-build 2023-01-22 22:07:35 +01:00
Markus F.X.J. Oberhumer 8ef17da082 all: cleanups 2023-01-22 18:44:31 +01:00
Markus F.X.J. Oberhumer 7993e619cd src: even more outstanding util/xspan renaming; NFC 2023-01-21 19:15:38 +01:00
Markus F.X.J. Oberhumer 1ab8d5fb3f src: remove currently unused submodules 2023-01-21 18:57:23 +01:00
Markus F.X.J. Oberhumer 213ac3ac73 all: better support for clang Static Analyzer (scan-build) 2023-01-19 19:17:26 +01:00
Markus F.X.J. Oberhumer 0a8876443a submodules: update for new versions 2023-01-19 19:16:11 +01:00
Markus F.X.J. Oberhumer f37a3bb9bb src: new ACC version 2023-01-19 06:26:06 +01:00
Markus F.X.J. Oberhumer 2632342f44 all: remove currently unused submodules 2023-01-19 03:32:49 +01:00
Markus F.X.J. Oberhumer 8efcf6f099 src: move console files into a subdir; NFC 2023-01-18 14:19:15 +01:00
Markus F.X.J. Oberhumer 58343fc78d src: more outstanding util/xspan renaming; NFC 2023-01-18 10:11:29 +01:00
Markus F.X.J. Oberhumer 6c41a4c9c8 src: move compress files into a subdir; clang-format some more files; NFC 2023-01-18 09:28:12 +01:00
Markus F.X.J. Oberhumer 334be287fc CI: add minimal-ci 2023-01-17 23:43:24 +01:00
Markus F.X.J. Oberhumer aa050e0001 cmake: compile compression libs with -O2 even in Debug mode 2023-01-16 09:47:39 +01:00
Markus F.X.J. Oberhumer cc994326a0 all: cleanups 2023-01-15 13:49:27 +01:00
Markus F.X.J. Oberhumer 58de07629e submodules: add vendor/rangeless 2023-01-15 03:23:22 +01:00
Markus F.X.J. Oberhumer 9f830e0c41 all: add zstd compression library 2023-01-13 22:25:15 +01:00
Markus F.X.J. Oberhumer c52d302f07 submodules: add vendor/zstd 2023-01-13 22:25:15 +01:00
Markus F.X.J. Oberhumer 44049ecf30 all: enable WITH_VALGRIND by default 2023-01-13 22:25:15 +01:00
Markus F.X.J. Oberhumer e1b5904196 submodules: add vendor/valgrind 2023-01-13 22:25:15 +01:00
Markus F.X.J. Oberhumer 88e692791a submodules: update for new version 2023-01-13 13:02:38 +01:00
Markus F.X.J. Oberhumer f00667ad7d all: minor cleanups, update some comments 2023-01-13 05:37:28 +01:00
Markus F.X.J. Oberhumer 696d0eec64 misc: update podman images 2023-01-06 01:48:32 +01:00
Markus F.X.J. Oberhumer 513b00a30e cmake: update for MSVC_IDE 2023-01-05 14:26:17 +01:00
Markus F.X.J. Oberhumer 0cb0dbf6d8 src: cleanup conf.h 2023-01-05 14:26:12 +01:00
Markus F.X.J. Oberhumer 9f00515da4 CI: fix windows build 2023-01-05 02:29:12 +01:00
Markus F.X.J. Oberhumer 72f31787f6 submodules: update for new versions 2023-01-05 02:02:31 +01:00
Markus F.X.J. Oberhumer cd686cb1d9 src: add boost-pfr 2023-01-05 00:57:05 +01:00
Markus F.X.J. Oberhumer d9657e9831 cmake and make: minor updates 2023-01-05 00:57:01 +01:00
Markus F.X.J. Oberhumer 72f3e9b25a all: require C++17 2023-01-03 15:11:11 +01:00
John Reiser 811b15a5b3 Fix crash with TLS init in i386 dll
https://github.com/upx/upx/issues/643
	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
	modified:   src/stub/i386-win32.pe.h
	modified:   src/stub/src/i386-win32.pe.S
	modified:   src/stub/tmp/i386-win32.pe.bin.dump
2023-01-12 18:35:04 -08:00
John Reiser ab00825f37 i386 shared library TLS init
https://github.com/upx/upx/issues/643
	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
	modified:   src/p_w32pe.cpp
	modified:   src/stub/i386-win32.pe.h
	modified:   src/stub/src/i386-win32.pe.S
	modified:   src/stub/tmp/i386-win32.pe.bin.dump
2023-01-12 14:34:06 -08:00
John Reiser e86d9179aa Sync testsuite
modified:   .github/travis_testsuite_1-expected_sha256sums.sh
	modified:   src/p_lx_elf.cpp
2023-01-09 10:51:47 -08:00
John Reiser 26d8e9c4c5 amd64-linux revamp for compressing shared libraries
Major changes: p_lx_elf.cpp and stub/src/amd64-linux.elf-so*.
(Includes run-time infrastructure for multiple de-compressors.)
	modified:   linker.cpp
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_unix.cpp
	modified:   p_unix.h
	modified:   stub/Makefile
	modified:   stub/src/amd64-darwin.dylib-entry.S
	modified:   stub/src/amd64-darwin.macho-entry.S
	new file:   stub/src/amd64-expand.S
	modified:   stub/src/amd64-linux.elf-entry.S
	new file:   stub/src/amd64-linux.elf-so_entry.S
	new file:   stub/src/amd64-linux.elf-so_fold.S
	new file:   stub/src/amd64-linux.elf-so_fold.lds
	new file:   stub/src/amd64-linux.elf-so_main.c
	modified:   stub/src/amd64-linux.shlib-init.S
	modified:   stub/src/amd64-win64.pep.S
	modified:   stub/src/arch/amd64/nrv2b_d.S
	modified:   stub/src/arch/amd64/nrv2d_d.S
	modified:   stub/src/arch/amd64/nrv2e_d.S
           plus many generated stub/*.h and stub/tmp/*.bin.dump
2023-01-09 09:39:25 -08:00
John Reiser 5f3ebc8a7f clang-format
modified:   linker.cpp
2023-01-09 09:33:34 -08:00
John Reiser 425b1b44bc Initialize output_capacity for loader
modified:   pefile.cpp
2023-01-09 09:20:43 -08:00
John Reiser 39442e6282 initLoader() 4th parameter allows larger output size
modified:   packer.cpp
	modified:   packer.h
2023-01-05 15:28:12 -08:00
John Reiser 99575e1010 ElfLinker::output_capacity
modified:   linker.cpp
	modified:   linker.h
2023-01-05 15:25:34 -08:00
John Reiser 64aa7540e2 Sync copyright year 2023
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_unix.cpp
	modified:   p_unix.h
2023-01-02 08:28:41 -08:00
Markus F.X.J. Oberhumer 3ff5dbd179 testsuite: update testsuite caused by version year change 2023-01-01 19:56:14 +01:00
Markus F.X.J. Oberhumer e25d04fb12 all: bump version date 2023-01-01 19:53:28 +01:00
Markus F.X.J. Oberhumer dd1d5a92d2 all: welcome 2023 2023-01-01 19:49:30 +01:00
Markus F.X.J. Oberhumer c6e0aad40b make: move extra builds to "build/extra/" subdirectories 2023-01-01 19:43:57 +01:00
Markus F.X.J. Oberhumer 99b795ceaa cmake: update for MinGW 2023-01-01 13:54:39 +01:00
Markus F.X.J. Oberhumer 33dc60df26 all: minor cleanups 2022-12-31 21:08:58 +01:00
John Reiser 619aeb54ff Pesky "upx -t" mode
https://github.com/upx/upx/issues/599
	modified:   p_lx_elf.cpp
2022-12-30 10:29:25 -08:00
John Reiser 77ba43328b Use my_page_size, which is 0x4000 (16KiB) on arm64
https://github.com/upx/upx/issues/628
	modified:   p_mach.cpp
2022-12-31 20:55:34 +01:00
John Reiser 01a30752c7 Mach-O: allow 256 ncmds and 32768 sizeofcmds
https://github.com/upx/upx/issues/642
	modified:   p_mach.cpp
	modified:   stub/src/i386-darwin.macho-upxmain.c
	modified:   stub/src/powerpc-darwin.macho-upxmain.c
2022-12-29 14:02:42 -08:00
John Reiser e56b748435 WIP fixing "upx -t" of shared library
modified:   p_lx_elf.cpp
2022-12-23 11:23:41 -08:00
Markus F.X.J. Oberhumer bb4cbdff44 src: fix m68k-atari build, prepare for std::atomic, port John's MemBuffer debug 2022-12-22 16:06:25 +01:00
Markus F.X.J. Oberhumer 0b47e474a7 make: update src/Makefile 2022-12-22 15:52:50 +01:00
Markus F.X.J. Oberhumer 8e85680eb4 all: minor updates 2022-12-21 22:09:05 +01:00
John Reiser fefce0d5c4 Cleanup "PT_LOAD gap recovery" during upx -d
https://github.com/upx/upx/issues/635
	modified:   p_lx_elf.cpp
2022-12-21 06:53:37 -08:00
Markus F.X.J. Oberhumer 0ac3cb2329 CI: update CI 2022-12-21 10:08:21 +01:00
Markus F.X.J. Oberhumer 708ab1dcd7 src: p_xxx_enum.h: trailing commas in enums are allowed since C++11 2022-12-20 23:34:36 +01:00
Markus F.X.J. Oberhumer 9b87ddb621 CI: run test-suite; remove obsolete scripts 2022-12-20 23:33:58 +01:00
Markus F.X.J. Oberhumer 5dc4eb4b03 CI: also test linux gcc-m32 builds 2022-12-20 12:10:39 +01:00
Markus F.X.J. Oberhumer a203c72281 make: update Makefile 2022-12-20 11:40:48 +01:00
Markus F.X.J. Oberhumer 6cf85cee6e src: minor compatibility fix 2022-12-20 11:40:22 +01:00
Markus F.X.J. Oberhumer 1eb6a40fdd src: restore lseek() error check in file.cpp 2022-12-20 11:51:31 +01:00
John Reiser 1bed77e4d3 'sizeof' returns size_t, which on i386 is not as wide as off_t
https://github.com/upx/upx/issues/629
https://github.com/upx/upx/issues/635
	modified:   p_lx_elf.cpp
2022-12-20 07:21:02 -08:00
John Reiser f2a68023fa MSVC error C4146: unary minus operator applied to unsigned type, result still unsigned
modified:   p_lx_elf.cpp
2022-12-19 16:14:48 -08:00
John Reiser 8ccffc40e3 A real typo that caused an error in "upx -d" de-compressing
modified:   p_lx_elf.cpp
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
2022-12-19 15:45:27 -08:00
John Reiser dd8c1d0441 clang alignment
modified:   p_lx_elf.cpp
2022-12-19 14:31:26 -08:00
John Reiser f9f28ff176 More work on "upx -d" de-compression
https://github.com/upx/upx/issues/629
https://github.com/upx/upx/issues/635
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_unix.cpp
2022-12-19 13:49:43 -08:00
John Reiser 3649041195 Return value of FileBase::seek(, SEEK_CUR) was not FileBase::tell()
modified:   file.cpp
2022-12-19 13:37:24 -08:00
Markus F.X.J. Oberhumer c23c7a9379 all: minor updates 2022-12-15 16:20:22 +01:00
Markus F.X.J. Oberhumer 9934e33b99 src: pacify a clang scan-build warning in p_mach.cpp 2022-12-12 21:27:34 +01:00
Markus F.X.J. Oberhumer 9e75fdda66 src: pacify a -Wcast-align warning 2022-12-12 20:07:27 +01:00
Markus F.X.J. Oberhumer d873a26f41 all: clang-format-15.0.6 2022-12-12 19:25:31 +01:00
Markus F.X.J. Oberhumer 91aa5b55ab all: upgrade to upx-stubtools v20221212 2022-12-12 19:25:28 +01:00
Markus F.X.J. Oberhumer 3f460a76ce src: fix typo in options.cpp 2022-12-12 05:38:51 +01:00
Markus F.X.J. Oberhumer 7256ea3b32 make: update Makefile 2022-12-12 05:32:04 +01:00
John Reiser 4cdf77e16f Stupid MSVC 14.2, 14.3; obtuse clang 14.0.5 (and MemBuffer vs alignment)
MSVC: cannot say "if (0)" to get "check symtax+semantics, but do not emit code"
clang+MemBuffer: must fight too much to get pointer to wider-than-char
	modified:   src/p_lx_elf.cpp
2022-12-11 14:41:38 -08:00
John Reiser d89813e911 Implement de-compress of --android-shlib
64-bit (arm64, aarch64) only for now.  NYI: 32-bit (armv7).
(Also: implied catch-up with all changes by Markus in the meantime.)
https://github.com/upx/upx/issues/599

	modified:   src/p_lx_elf.cpp
	modified:   src/p_lx_elf.h
2022-12-11 13:46:44 -08:00
Markus F.X.J. Oberhumer 7c57b10cae all: minor cleanups 2022-12-02 16:46:16 +01:00
Markus F.X.J. Oberhumer 8d1a98e03b misc: update podman images, add build-all script 2022-11-27 23:50:22 +01:00
Markus F.X.J. Oberhumer 65a2da4b40 src: more clang-format 2022-11-27 22:03:20 +01:00
Markus F.X.J. Oberhumer 02f6786b2a src: new ACC version 2022-11-27 21:56:30 +01:00
Markus F.X.J. Oberhumer 9da4f7a6dc src: clang-format more files; cleanups; NFCI 2022-11-27 12:34:15 +01:00
John Reiser 510505a85c p_tmt: more sanity of input, cleanup MemBuffer usage
https://github.com/upx/upx/issues/632
	modified:   src/p_tmt.cpp
2022-11-24 10:28:03 -08:00
Markus F.X.J. Oberhumer 741cb3a136 misc: update podman images 2022-11-26 19:12:26 +01:00
Markus F.X.J. Oberhumer 9f5d67e27c src: clang-format various packers 2022-11-26 17:45:25 +01:00
Markus F.X.J. Oberhumer 93c6496ba8 src: add a xspan check to p_tmt.cpp and clang-format 2022-11-24 09:11:25 +01:00
John Reiser 779b648c5f invert_pt_dynamic: fix thinko; PackLinuxElf64help1 insist on ELF
https://github.com/upx/upx/issues/631
	modified:   src/p_lx_elf.cpp
2022-11-23 19:49:28 -08:00
Markus F.X.J. Oberhumer 9d5e06232d testsuite: update checksums caused by version bump 2022-11-22 21:36:32 +01:00
Markus F.X.J. Oberhumer b221c44466 src: re-add non-working PackMachPPC32 to PackMaster 2022-11-22 21:24:33 +01:00
Markus F.X.J. Oberhumer 665296f7cf src/util: minor xspan improvements 2022-11-22 21:21:26 +01:00
Markus F.X.J. Oberhumer 39778d5f47 cmake: default to relaxed options when building from source tarball 2022-11-22 20:54:12 +01:00
Markus F.X.J. Oberhumer 0af9bbb623 all: post-release version bump 2022-11-22 20:51:56 +01:00
Markus F.X.J. Oberhumer fdec47a83d all: prepare for release 2022-11-16 23:15:38 +01:00
Markus F.X.J. Oberhumer 7ff913bbd2 src: remove non-working PackMachPPC32 from PackMaster 2022-11-16 22:24:39 +01:00
Markus F.X.J. Oberhumer 94775bef9f src: remove non-working PackMachPPC64 from PackMaster; see issue #626 2022-11-16 20:41:31 +01:00
Markus F.X.J. Oberhumer 3cf102334f src: add option '--force-overwrite' 2022-11-16 12:52:53 +01:00
Markus F.X.J. Oberhumer 627e733a30 src: minor compress_lzma.cpp cleanups 2022-11-15 11:59:22 +01:00
Markus F.X.J. Oberhumer d31b80da5b cmake: improve tests 2022-11-14 13:21:07 +01:00
Markus F.X.J. Oberhumer eb231b65f3 src: clang-format compress_*.cpp; minor cleanup 2022-11-14 11:35:13 +01:00
Markus F.X.J. Oberhumer 59e3b1f98d all: cosmetic cleanups in NEWS and doc/Makefile 2022-11-11 05:32:59 +01:00
Markus F.X.J. Oberhumer 8b174bb272 submodules: update for new version 2022-11-10 17:34:02 +01:00
John Reiser 4199a44bef armeb stub: b_method as arg5 is 32-bit unsigned
https://github.com/upx/upx/issues/618
	modified:   src/stub/src/arch/arm/v4a/lzma_d.S

	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
        also src/stub/arm*-linux*.h, src/stub/tmp/*.bin.dump
2022-11-10 08:04:35 -08:00
Markus F.X.J. Oberhumer 777392c0fe src: add some compress doctest checks 2022-11-10 16:26:36 +01:00
Markus F.X.J. Oberhumer ede1fec5e7 submodules: update for new version 2022-11-10 16:25:33 +01:00
Markus F.X.J. Oberhumer 16de3e78a5 src: try to fix canUnpack() confusion - see packer.h 2022-11-10 06:00:53 +01:00
Markus F.X.J. Oberhumer d7508d8c09 src: pefile.cpp: replace "membuffer + x - y" with "membuffer + (x - y)"
This is needed because "membuffer + x" is now bounds-checked, and
the temporary addition would trigger an exception.
2022-11-10 00:40:41 +01:00
John Reiser 2a136c1c1d End users wish to avoid "double packing".
https://github.com/upx/upx/issues/622
	modified:   src/p_lx_elf.cpp
2022-11-09 15:39:16 -08:00
Markus F.X.J. Oberhumer 2578102be9 src: misc cleanups 2022-11-09 22:15:11 +01:00
Markus F.X.J. Oberhumer dadee7acfb doc: update NEWS to mention a user visible change 2022-11-09 21:47:28 +01:00
Markus F.X.J. Oberhumer 28f0bb4e11 src: fix pefile.cpp otls allocation not accounting for alignment. Closes #621. 2022-11-09 19:29:16 +01:00
Markus F.X.J. Oberhumer 824c8a8efb src: introduce raw_index_bytes() 2022-11-08 23:05:34 +01:00
John Reiser 37f27a1262 "gcc -Werror=format-security" is small-minded
... and does not perform constant propagation
	modified:   src/p_vmlinx.cpp
2022-11-08 13:36:28 -08:00
Markus F.X.J. Oberhumer 2b8a7a492a src/util: fix compilation when not using xspan 2022-11-08 20:38:52 +01:00
Markus F.X.J. Oberhumer db56bbb11b src/util: forward memset() in xspan_fwd.h 2022-11-08 20:34:44 +01:00
John Reiser 82d26f04a4 p_vmlinx was too eager
https://github.com/upx/upx/issues/622
	modified:   src/p_vmlinx.cpp
2022-11-08 10:30:48 -08:00
Markus F.X.J. Oberhumer 5045f7eb42 submodules: update for new versions 2022-11-08 17:33:56 +01:00
Markus F.X.J. Oberhumer 82a6ccac4d misc: add misc/cross-compile-upx-with-podman 2022-11-08 03:54:30 +01:00
Markus F.X.J. Oberhumer 2d74298001 make: update Makefiles 2022-11-08 03:52:43 +01:00
Markus F.X.J. Oberhumer ce21254ed2 all: misc cleanups 2022-11-06 08:35:00 +01:00
Markus F.X.J. Oberhumer 874250fe49 submodules: update for new versions 2022-11-06 08:34:06 +01:00
John Reiser c8a3acbba8 Static executable with 4 PT_LOAD has only ELF headers in first PT_LOAD
https://github.com/upx/upx/issues/615
2022-11-02 10:03:25 -07:00
Markus F.X.J. Oberhumer 81e11987a2 all: add UPX_VERSION_GIT_DESCRIBE 2022-11-02 10:35:40 +01:00
Markus F.X.J. Oberhumer 668cefec2f src: mention UPX_CONFIG_DISABLE_GITREV build config 2022-11-02 02:52:20 +01:00
Markus F.X.J. Oberhumer 212bc04257 cmake: run tests sequentially 2022-11-02 02:50:02 +01:00
Markus F.X.J. Oberhumer db401fd05e cmake: improve "make test" 2022-10-31 18:53:38 +01:00
Markus F.X.J. Oberhumer bebe72481c testsuite: update checksums 2022-10-29 19:16:57 +02:00
John Reiser 2b9e83256d SELinux execmod requires no PROT_EXEC when PROT_WRITE
modified:   src/stub/src/amd64-linux.elf-main.c

	modified:   src/stub/amd64-linux.elf-fold.h
	modified:   src/stub/arm64-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/arm64-linux.elf-fold.map
	modified:   src/stub/tmp/powerpc64-linux.elf-fold.map
	modified:   src/stub/tmp/powerpc64le-linux.elf-fold.map
2022-10-28 13:04:17 -07:00
Markus F.X.J. Oberhumer 5763518cce misc: add misc/rebuild-stubs-with-podman to add upx-4.0.0 2022-10-28 20:03:30 +02:00
Markus F.X.J. Oberhumer 3e4c5bab72 testsuite: update checksums caused by version bump 2022-10-28 17:30:56 +02:00
Markus F.X.J. Oberhumer bce109ab54 all: post-release version bump 2022-10-28 17:10:52 +02:00
Markus F.X.J. Oberhumer 69ca635c4c all: prepare for 4.0.0 release 2022-10-28 10:38:03 +02:00
Markus F.X.J. Oberhumer e0bf460993 src: rename membuffer "Uncompression" to "Decompression" 2022-10-28 10:34:31 +02:00
Markus F.X.J. Oberhumer 29762a8a96 CI: small update 2022-10-28 07:51:00 +02:00
Markus F.X.J. Oberhumer c7ef08dc2d testsuite: update 2022-10-27 22:35:45 +02:00
John Reiser 50a6698715 Each PROT_WRITE segment has implicit .bss on end of last page (64-bit only for now);
Also  workaround kernel bug invoking the escape hatch on arm64 (aarch64).
https://github.com/upx/upx/issues/611
2022-10-27 11:01:37 -07:00
Markus F.X.J. Oberhumer 7dd2cdea1e src: deprecate util/bptr.h 2022-10-27 17:52:15 +02:00
Markus F.X.J. Oberhumer af87f7f2bf doc: add missing NEWS entries 2022-10-27 18:10:29 +02:00
Markus F.X.J. Oberhumer 295889023f all: set next version back to 4.0.0, bump tentative release date, update
docs
2022-10-27 17:36:02 +02:00
Markus F.X.J. Oberhumer feef2e38cf all: final tweaks for release 2022-10-27 16:53:16 +02:00
Markus F.X.J. Oberhumer 80d30aab32 testsuite: update checksums caused by version change 2022-10-27 16:03:08 +02:00
Markus F.X.J. Oberhumer e910a9dc3e all: change version back to 3.99; docs: warn about know regressions and
clarify GPLv2+ COPYING
2022-10-27 16:00:25 +02:00
Markus F.X.J. Oberhumer 504224696c misc: update misc/rebuild-stubs-with-podman to install previous UPX versions 2022-10-27 15:35:59 +02:00
Markus F.X.J. Oberhumer e2acd666df CI: remove some obsolete stuff 2022-10-25 02:53:49 +02:00
Markus F.X.J. Oberhumer e5c0d998b7 src: fully deprecate src/Makefile; minor doc and CI cleanups 2022-10-25 01:48:45 +02:00
Markus F.X.J. Oberhumer 63f6fef964 all: don't use egrep or fgrep 2022-10-25 01:47:42 +02:00
Markus F.X.J. Oberhumer 983eb6d676 src: improve error message when using doctest options like '--dt-help'; add
doctest info to help.cpp
2022-10-25 01:47:38 +02:00
Markus F.X.J. Oberhumer 98fedef1a1 testsuite: update checksums 2022-10-24 12:56:49 +02:00
Markus F.X.J. Oberhumer 75a769759d src/stub: sync stubs 2022-10-24 12:56:49 +02:00
John Reiser 2354b01bad Adapt to libbfd: "no Shdrs" requires 0==.e_shentsize and 0==.e_shnum
modified:   p_lx_elf.cpp
2022-10-24 12:56:49 +02:00
John Reiser c331b9f1e2 Zero the tail of last RW page, even when variable page size
https://github.com/upx/upx/issues/611
	modified:   stub/src/amd64-linux.elf-main.c
2022-10-24 12:56:49 +02:00
John Reiser afeaeeddec munmap(, Phdr[C_TEXT=1].p_memsz); // not .p_vaddr
modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
2022-10-24 12:56:49 +02:00
John Reiser ab7ef9f511 Document the value of "brk #0" instruction
modified:   stub/src/arm64-linux.elf-entry.S
2022-10-24 12:56:49 +02:00
John Reiser d3ad6d25d8 PackLinuxElf64::asl_pack2_Shdrs() for better fit in logical flow
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2022-10-24 12:56:49 +02:00
John Reiser 2e29f9fa5f pack2() fixes for --android-shlib
WIP for https://github.com/upx/upx/issues/599
	modified:   p_lx_elf.cpp
2022-10-24 12:56:49 +02:00
John Reiser 5d9f71bb13 asl_pack1_Shdrs()
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2022-10-24 12:56:49 +02:00
John Reiser 82ed25bb44 Major fix 64-bit un_shlib_1() and unpack(), but not --android-shlib
Also canUnpack() is really a 'bool' which sets overlay_offset
when 'true'; confusing!
        https://github.com/upx/upx/issues/599 (partial)
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_unix.h
2022-10-24 12:56:49 +02:00
Markus F.X.J. Oberhumer f57393c0e8 all: simplify include path handling; update src/Makefile 2022-10-24 12:56:35 +02:00
Markus F.X.J. Oberhumer b54cced19c src: add some tests for compress_zlib 2022-10-24 12:18:25 +02:00
Markus F.X.J. Oberhumer 60a0544314 all: bump tentative release date 2022-10-23 23:15:00 +02:00
Markus F.X.J. Oberhumer 283c1cf931 src: add --version-short option; support doctest --dt-XXX options; cleanups 2022-10-23 23:09:13 +02:00
Markus F.X.J. Oberhumer fff53efc05 src: add some more xspan tests 2022-10-20 14:06:20 +02:00
Markus F.X.J. Oberhumer 07d368adca all: misc cleanups 2022-10-20 02:09:05 +02:00
Markus F.X.J. Oberhumer 13276d93fa all: bump tentative release date 2022-10-18 21:07:48 +02:00
Markus F.X.J. Oberhumer 79b1b1a586 submodules: update for new version 2022-10-18 20:32:03 +02:00
Markus F.X.J. Oberhumer 2f083f3e56 submodules: update for new version 2022-10-14 11:21:19 +02:00
Markus F.X.J. Oberhumer 73b0b4db9d submodules: update for new version 2022-10-12 17:26:11 +02:00
Markus F.X.J. Oberhumer ca0e614b56 CI: update for new GitHub Actions deprecated set-output commands 2022-10-12 16:29:20 +02:00
John Reiser 72613d06a5 Look for PackHeader in the right place.
https://github.com/upx/upx/issues/606
	modified:   p_mach.cpp
2022-10-11 08:08:55 -07:00
John Reiser 48ad5513ff un_shlib_1() allows test mode ("-t") which has (nullptr == fo)
modified:   p_lx_elf.cpp
2022-10-07 12:52:21 -07:00
John Reiser 201d9f1346 Fix length when stub unmaps compressed input for main program
https://github.com/upx/upx/issues/606
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/tmp/amd64-linux.elf-fold.map
2022-10-07 09:53:29 +02:00
John Reiser 1e8f1f49d0 is_bad_linker_command() ignores LC_REQ_DYLD
https://github.com/upx/upx/issues/606
	modified:   p_mach.cpp
2022-10-06 10:15:10 -07:00
Markus F.X.J. Oberhumer 65707900bc src: remove more traces of fictional powerpc64le-darwin 2022-10-06 15:53:50 +02:00
Markus F.X.J. Oberhumer 39c5be43aa CI: add Visual Studio 2022 builds; updates 2022-10-06 15:35:51 +02:00
Markus F.X.J. Oberhumer c4437cb293 all: add support for a basic "make test" 2022-10-06 14:10:35 +02:00
Markus F.X.J. Oberhumer e2b86a49db src: fix recently introduced bug in unoptimzeReloc 2022-10-06 14:09:45 +02:00
Markus F.X.J. Oberhumer 8fe83be87f misc: update misc/rebuild-stubs-with-podman so that we can build
the full upx program in a container
2022-10-05 16:07:12 +02:00
Markus F.X.J. Oberhumer 17167d4905 CI: update macos-12 build 2022-10-05 02:05:20 +02:00
John Reiser 05ff7e35a1 Warn for big shell scripts, and send them to --force-execve.
Also propagte error code when execve() fails for compressed shell,
to avoid confusion of `hlt` ==> SIGSEGV.
https://github.com/upx/upx/issues/604
2022-10-05 01:30:32 +02:00
Markus F.X.J. Oberhumer f67cec4752 submodules: update for new version 2022-10-04 15:33:27 +02:00
Markus F.X.J. Oberhumer fd4882abcf CI: run close-stale-issues.yml once per week 2022-10-04 13:28:51 +02:00
Markus F.X.J. Oberhumer 0f42579e68 src: fix djgpp and musl builds 2022-10-02 20:00:30 +02:00
Markus F.X.J. Oberhumer 7398d8f68f src: enable -Wsuggest-override in src/conf.h 2022-09-27 18:17:28 +02:00
John Reiser ec33109b22 clang-10 requires the use of 'override'
Discovered during gitlab auto-build for https://github.com/upx/upx/issues/595
	modified:   Makefile
	modified:   p_armpe.h
	modified:   p_djgpp2.h
	modified:   p_lx_elf.h
	modified:   p_lx_exc.h
	modified:   p_lx_interp.h
	modified:   p_lx_sh.h
	modified:   p_mach.h
	modified:   p_ps1.h
	modified:   p_tmt.h
	modified:   p_unix.h
	modified:   p_vmlinx.h
	modified:   p_vmlinz.h
	modified:   p_w32pe.h
	modified:   p_w64pep.h
	modified:   pefile.h
2022-09-27 18:15:48 +02:00
Markus F.X.J. Oberhumer 2cfa4c1eb7 CI: update testsuite checksums caused by getVersion() bump 2022-09-27 18:15:48 +02:00
John Reiser a13b4d10d9 After upx-3.96, the de-compressing stub for ELF moved
... so unpack() of newly-compressed ELF by upx-3.96 now says
"CantUnpackException: need a newer version of UPX"
        https://github.com/upx/upx/issues/595
	modified:   p_lx_elf.h
	modified:   packer.h
2022-09-27 18:09:20 +02:00
Markus F.X.J. Oberhumer 36e94e58d0 stub: add mising powerpc64-darwin tmp dump files 2022-09-27 18:09:20 +02:00
John Reiser d0a52bd483 More cleanup of stubs for powerpc64le-darwin* which does not exist.
Only powerpc64-darwin (BigEndian, no suffix) exists.
https://github.com/upx/upx/issues/596
2022-09-27 15:58:35 +02:00
dependabot[bot] 38a1d3179b build(deps): bump actions/stale from 5 to 6
Bumps [actions/stale](https://github.com/actions/stale) from 5 to 6.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/v5...v6)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-22 17:07:26 +00:00
Markus F.X.J. Oberhumer 0d639d6386 CI: add macos job 2022-09-21 21:55:07 +02:00
Markus F.X.J. Oberhumer 4256057c27 src: add a mem_size() call hinted by GitHub CodeQL 2022-09-21 19:28:46 +02:00
Markus F.X.J. Oberhumer b720b47c12 CI: update testsuite caused by previous commit 2022-09-21 19:22:39 +02:00
John Reiser 55e4a4f086 Assembler local symbol ("1:") clobbered by code in .macro
https://github.com/upx/upx/issues/534
	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/src/arch/arm64/v8/lzma_d.S
	modified:   stub/src/arch/arm64/v8/macros.S
2022-09-20 13:08:14 -07:00
Markus F.X.J. Oberhumer b4cb9f8b2f src: silence some bogus GitHub CodeQL warnings; add MemBuffer "+" overload 2022-09-17 07:53:14 +02:00
Markus F.X.J. Oberhumer 63298ebd6d src: silence clang-15 compiler warnings 2022-09-16 16:31:34 +02:00
Markus F.X.J. Oberhumer 73c816e468 doc: work on improving docs; add generated files to Git repo 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 0492e650ef submodules: update for new versions 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer b8b94ee89e src: more cleanups; NFCI 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 81176716d5 src: linker: fix a minor printf format issue detected by codeql 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 26e7ae00e9 CI: create codeql-analysis.yml 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer c75d7a685d src: major cleanups, introduce new eXtended Span class
- initial minimally invasive eXtended Span implementation
- rename ptr_diff to ptr_diff_bytes
- move some files to util subdir
- lots of cleanups
- start using the new checked pointers - this needs some real-world testing
2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 4318cc22ee src: cleanup option handling, add testcases; fixes #587 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 575cb720c6 doc: work on README 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 5db34fbf92 src: new ACC version 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 7cfef2f6bf CI: update testsuite checksums caused by version date bump 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 4603f1df4b src: bump tentative release date 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer c69fcfff9d src: doctest: start work on using doctest 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 70f14101ed doc: update README.SRC, mention misc/rebuild-stubs-with-podman 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer a9803459ed doc: move BUGS into doc subdirectory 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 43034e8e92 doc: remove outdated README.1ST 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer ef547034f6 misc: add misc/rebuild-stubs-with-podman files 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer e87fc60391 misc: update clang-format files 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 45e6e73d85 misc: move some scripts from src/stub/scripts to misc/scripts 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer be30c26dbb make: update src/Makefile 2022-09-16 13:26:13 +02:00
Markus F.X.J. Oberhumer 79e9b0762c CI: work on new cmake-based CI; updates 2022-09-16 13:26:10 +02:00
Markus F.X.J. Oberhumer a9a806c418 CI: remove obsolete travis_deploy.sh - superseded by GitHub Actions 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer c7d8b6fed1 make: add new top-level Makefile, now using CMake 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer a723efd225 make: remove top-level Makefile 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer cf429dfce4 cmake: add CMakeLists.txt for building with CMake 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer 3fcd64a0c0 misc: update files 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer 83cb38022b misc: add compile_flags.txt to support editors using clangd LSP 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer 93c04d1f66 misc: add .gitattributes for GitHub linguist 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer 3c47898cf4 make: adjust for new vendor/lzma-sdk location 2022-09-11 13:26:32 +02:00
Markus F.X.J. Oberhumer 61e1366122 submodules: add new upx-vendor submodules in directory "vendor" 2022-09-11 13:26:29 +02:00
Markus F.X.J. Oberhumer a20636fd63 submodules: remove submodule src/lzma-sdk 2022-09-04 04:24:39 +02:00
Markus F.X.J. Oberhumer aa8cdca0a9 src: consistently use TESTING for internal development tests 2022-09-04 04:24:39 +02:00
Markus F.X.J. Oberhumer 6931a3aa70 src: enable -Wzero-as-null-pointer-constant when using clang 2022-09-04 04:24:39 +02:00
Markus F.X.J. Oberhumer d001a63bce Welcome 2022. 2022-09-04 04:24:39 +02:00
Markus F.X.J. Oberhumer 0d3377f48b src: p_mach.cpp: disable -Wcast-align warning 2022-08-17 19:54:44 +02:00
John Reiser aeb04d97c8 powerpc64-darwin.macho (not powerpc64le-darwin.macho)
All Apple PowerPC are BigEndian only.
        https://github.com/upx/upx/issues/596
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   packmast.cpp
2022-09-03 12:39:50 -07:00
John Reiser eb68ab91cd PackDjgpp2::canPack() allows "loose" (non-contiguous) text,data,bss
Hack: grow text to eliminate gap; don't complain unless bss overlaps data
https://github.com/upx/upx/issues/45
	modified:   p_djgpp2.cpp
2022-08-29 11:37:46 +02:00
Markus F.X.J. Oberhumer ee242ba987 CI: improve workflows/close-stale-issues.yml 2022-08-27 21:04:56 +02:00
cui fliter 44a53736ff fix some typos
Signed-off-by: cui fliter <imcusg@gmail.com>
2022-08-23 19:20:21 +02:00
Markus F.X.J. Oberhumer 1b21fef081 CI: improve workflows/close-stale-issues.yml 2022-08-12 17:59:32 +02:00
Markus F.X.J. Oberhumer 5f9c50cd3e clang-format 2022-08-10 23:29:43 +02:00
Markus F.X.J. Oberhumer 793d8c1d2e Fix compilation with C++20. 2022-07-17 21:16:11 +02:00
Markus F.X.J. Oberhumer 81f868a0c6 Add .github/workflows/close-stale-issues.yml 2022-08-10 23:12:09 +02:00
John Reiser dadbbbdc64 Avoid trouble: disallow empty name of export directory
https://github.com/upx/upx/issues/425
	modified:   pefile.cpp
2022-08-13 12:25:30 -07:00
John Reiser bfd2153f2b Delete trailing space characters
https://github.com/upx/upx/pull/589
	modified:   pefile.cpp
2022-07-26 20:09:16 -07:00
S01den 077793fa5e Update pefile.cpp
I found a bug by participating to the Binary Golf Grand Prix 3 (https://tmpout.sh/bggp/3/) : upx text.exe segfaults when NumberOfSections in the IMAGE_FILE_HEADER is NULL, so 
if (memcmp(isection[0].name,"UPX",3) == 0) triggers a NULL pointer dereference causing a crash.
To fix it, just have to check if isection is NULL (which means NumberOfSections = 0) or not.
2022-07-27 01:54:01 +02:00
John Reiser acad3c3000 DT_INIT_ARRAY noes not pertain to DT_* for symbol table info
https://github.com/upx/upx/issues/586
	modified:   p_lx_elf.cpp
2022-07-02 20:52:18 -07:00
John Reiser 3b4627e17e Add filename to infoWarning("file coruupted")
modified:   p_mach.cpp
2022-06-01 08:34:23 -07:00
John Reiser 05976ee1a7 Try harder to de-compress corrupted Mach-o file.
https://github.com/upx/upx/issues/579
	modified:   p_mach.cpp
2022-05-31 11:52:10 -07:00
John Reiser c1311c78a3 Extra space to force "git commit" to force rebuild for tagging Issue
https://github.com/upx/upx/issues/577
	modified:   p_lx_elf.cpp
2022-05-30 15:19:18 -07:00
John Reiser 717150b7f3 Stupid MSVC: bad C4706: assignment within conditional expression
-    for (unsigned j=0; (k = dt_names[j]); ++j) {
+    for (unsigned j=0; ((k = dt_names[j]), k); ++j) {

The complaint was:
    p_lx_elf.cpp(5710) : warning C4706: assignment within conditional expression
which is INCORRECT, as shown in the change which is 100% equivalent.
The assignment occurs BEFORE the conditional expression.
	modified:   p_lx_elf.cpp
2022-05-30 15:09:34 -07:00
John Reiser a68c62d938 More placate compilers
https://github.com/upx/upx/issues/577
	modified:   p_lx_elf.cpp
2022-05-30 15:02:53 -07:00
John Reiser c11f8a569a Placate 'clang' -Wcast-align
https://github.com/upx/upx/issues/577
	modified:   p_lx_elf.cpp
2022-05-30 14:55:39 -07:00
John Reiser 03436d2415 Bug in handling DT_GNU_HASH table.
Fix includes a more-general and stronger heuristic to find the end of
GNU_HASH table when there is no ElfXX_Shdr for it.  64-bit only for now.
(This is needed to help prevent SIGSEGV when processing tampered .exe.)

https://github.com/upx/upx/issues/577
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2022-05-30 14:24:21 -07:00
John Reiser 4ae75375e0 LC_BUILD_VERSION etc for XCode 13+
https://github.com/upx/upx/issues/578
	modified:   p_mach.cpp
	modified:   p_mach_enum.h
2022-05-30 01:05:09 -07:00
John Reiser 2721ef0636 ElfLinker::init() allows symbols and relocations (but not Sections) to be empty
modified:   linker.cpp
	modified:   linker.h
2022-05-04 13:29:36 -07:00
John Reiser 7a232cb330 Allow qemu on host with smaller PAGE_SIZE. Sync stubs.
https://github.com/upx/upx/issues/571
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2022-03-25 09:13:10 -07:00
John Reiser 52f19ae330 Cleanup powerpc64le-linux.elf-*.S (forgotten when powerpc-linux.elf*.S)
https://github.com/upx/upx/issues/571
	modified:   stub/powerpc64-linux.elf-entry.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/tmp/powerpc64-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2022-03-24 19:14:56 -07:00
John Reiser 275477f914 ElfLinker::addSection omits "ABS*" and "UND*" sections
modified:   linker.cpp
2022-03-24 19:09:09 -07:00
John Reiser 2ed6755d5d Sync stubs
https://github.com/upx/upx/issues/570
	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
2022-03-22 19:27:27 -07:00
John Reiser 78c555b4a6 Handle old-style compressed main programs when de-compressing
modified:   p_lx_elf.cpp
2022-03-22 19:20:09 -07:00
John Reiser a127125707 Comment the breakpoint instructions for faster analysis by 'grep'
modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm.v5a-darwin.macho-fold.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/mipsel.r3000-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
2022-03-22 19:18:19 -07:00
John Reiser f853f91c5b Placate clang re: missing 'override'
modified:   file.h
2022-03-22 19:16:15 -07:00
John Reiser e7ca5c54ff Fix --brute for p_lx_elf.cpp, which compresses multiple pieces
Force all pieces to use the same de-compressor.
(Future: allow each PT_LOAD to choose its own.)
Has minor wobbles due to page alignment, and size of de-compressor.
64-bit only for now.
https://github.com/upx/upx/issues/570
https://github.com/upx/upx/issues/297
	modified:   p_lx_elf.cpp
	modified:   p_unix.cpp
	modified:   packer.cpp
	modified:   packer.h
2022-03-22 11:46:25 -07:00
John Reiser 663d6b466b WIP: clarify compressWithFilters; reduce size of obuf for PackLinuxElf64
modified:   p_lx_elf.cpp
	modified:   packer.cpp
	modified:   packer.h
2022-03-21 13:49:46 -07:00
John Reiser 0e2a9de2b2 Empty commit to force re-build Action
https://github.com/upx/upx/issues/568
2022-03-14 15:51:09 -07:00
John Reiser 34df0d6ef1 More empty HASH and/or GNU_HASH when Rust-musl
https://github.com/upx/upx/issues/568
	modified:   p_lx_elf.cpp
2022-03-12 14:21:51 -08:00
John Reiser 540164849b whitespace
https://github.com/upx/upx/issues/446
	modified:   macho-snip.c
2022-03-01 16:05:37 -08:00
John Reiser 252143d0bb WIP: smallest executable on Apple M1 (aarch64 or arm64)
Requirements for success after snipping a loader_command:
    "codesign -s - my_app" must succeed.
    "lldb my_app; process launch -s; continue" must succeed.

Optional loader_commands (macho-snip can remove these successfully):
    LC_UUID, LC_BUILD_VERSION, LC_SOURCE_VERISON,
    LC_DATA_IN_CODE (when 0==datasize)

Apple "strip -N" clears out LC_SYMTAB and LC_DYSYMTAB, but leaves
LC_DYLD_INFO_ONLY.export_size.  Perhaps this could be zero if
constructed that way; snipping seems tedious because codesign
requires that __LINKEDIT must have no gaps.

LC_FUNCTION_STARTS seems to be required by codesign.
codesign wants offsets that point into __LINKEDIT to be in order:
    LC_DYLD_INFO_ONLY, LC_FUNCTION_STARTS, LC_DATA_IN_CODE, LC_SYMTAB

MacOS seesm to require LC_LOAD_DYLINKER (else "zsh: Kiled"),
which seems to require LD_LOAD_DYLIB (else SIGABRT).

https://github.com/upx/upx/issues/446
----
        modified:   macho-snip.c
	modified:   udf.s
2022-03-01 15:06:58 -08:00
John Reiser 480ab51650 Evade poratbility constraints of UPX build system
when building a tool to investigate "minimal" Mach-O executable
on Apple MacOS Big Sur using Apple M1 hardware (aarch64).
https://github.com/upx/upx/issues/567
	modified:   stub/tools/macho-snip/Makefile
	modified:   stub/tools/macho-snip/macho-snip.c
	modified:   stub/tools/macho-snip/udf.s
2022-03-01 11:12:19 -08:00
John Reiser 972c76eb42 Tool for snipping loader_commands in Mach-O on Apple M1 (aarch64) on BigSur.
experimental!
https://github.com/upx/upx/issues/424
	new file:   macho-snip/Makefile
	new file:   macho-snip/macho-snip.c
	new file:   macho-snip/udf.s
2022-02-28 19:53:25 -08:00
John Reiser e5aeea9ed2 Check more carefully in invert_pt_dynamic()
https://github.com/upx/upx/issues/566
	modified:   p_lx_elf.cpp
2022-02-28 07:55:49 -08:00
John Reiser f204670008 Mach unpack checks for bad load_command in compressed input
https://github.com/upx/upx/issues/564
	modified:   p_mach.cpp
2022-02-25 10:17:04 -08:00
John Reiser 651155c64d Check Mach_header.ncmds at unpack
https://github.com/upx/upx/issues/563
	modified:   p_mach.cpp
2022-02-25 09:32:29 -08:00
John Reiser 660aee6d22 More checking for unpack of tampered Elf_Phdr
https://github.com/upx/upx/issues/562
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2022-02-25 09:23:55 -08:00
John Reiser a646231630 aligned_sotls, per Laszlo
https://github.com/upx/upx/issues/556
	modified:   pefile.cpp
2022-02-07 08:39:13 -08:00
John Reiser 1050de5171 Native alignment for the "load config" table
https://github.com/upx/upx/issues/556
	modified:   pefile.cpp
2022-01-15 06:45:47 -08:00
John Reiser b7a5b9437a Fix checking of sh_name versus shstrsec->sh_size
https://github.com/upx/upx/issues/509
	modified:   p_vmlinx.cpp
2022-01-01 14:20:18 -08:00
Kornel Pal 620955a724 PE: Fix has_oxrelocs (TLS always has oxrelocs) 2021-12-31 20:45:28 +01:00
John Reiser 2e64a277f8 Fix headway during optimizeReloc()
Later: "Assertion `(soxrelocs == 0) == !has_oxrelocs' failed."
https://github.com/upx/upx/issues/552
	modified:   packer.cpp
	modified:   packer.h
	modified:   pefile.cpp
2021-12-31 10:27:58 -08:00
John Reiser ea567a8b14 Check when optimizeRelocs()
https://github.com/upx/upx/issues/513
	modified:   packer.h
	modified:   packer.cpp
	modified:   pefile.cpp
	modified:   p_wcle.cpp
	modified:   p_tmt.cpp
2021-12-29 16:57:52 -08:00
John Reiser be23f93ee6 upx_uint8_t
https://github.com/upx/upx/issues/545
	modified:   p_mach.h
2021-12-27 08:49:05 -08:00
John Reiser fcdf0e92c1 Use upx_uint32_t, upx_uint64_t
Avoid complaints from x86_64-w64-mingw32-gcc (GCC) 9.3-win32 20200320
https://github.com/upx/upx/issues/545
	modified:   p_mach.h
2021-12-27 08:33:54 -08:00
John Reiser 2d6987252e is_bad_linker_command()
https://github.com/upx/upx/issues/545
	modified:   p_mach.cpp
2021-12-27 08:14:19 -08:00
John Reiser 4a9c46253e Validate input LC_ commands in order to defend against fuzzers
TODO: validate in ::unpack(), too
https://github.com/upx/upx/issues/545
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   p_mach_enum.h
2021-12-26 19:40:34 -08:00
John Reiser 5bcf9dd8af Do not complain for minimal DT_GNU_HASH as by Rust.
Also: .p_type is 32 bits only!

https://github.com/upx/upx/issues/525
	modified:   p_lx_elf.cpp
2021-12-25 12:39:31 -08:00
John Reiser 284adb203f Better checking of DT_HASH.nbuckets
https://github.com/upx/upx/issues/507
	modified:   p_lx_elf.cpp
2021-12-24 15:52:16 -08:00
John Reiser adafa841f7 Some PT_LOAD must have (p_flags & PF_X)
https://github.com/upx/upx/issues/511
	modified:   p_lx_elf.cpp
2021-12-24 15:32:19 -08:00
John Reiser fdc5d25d03 Require DT_STRSZ
https://github.com/upx/upx/issues/512
	modified:   p_lx_elf.cpp
2021-12-24 15:08:22 -08:00
John Reiser 294a7077de Announce support for EFI files (PE x86)
modified:   NEWS
2021-12-24 15:05:53 -08:00
Kornel Pal 990d0ec543 PE: Remove duplicate oxrelocs write 2021-12-22 05:07:54 +01:00
John Reiser bb90c4dff4 Sync PE stubs
modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
2021-12-24 07:34:06 -08:00
Kornel Pal 00e3d992e8 Sync stubs 2021-12-22 03:05:53 +01:00
Kornel Pal 937bfa4e49 PE: Add support for EFI images 2021-12-22 03:05:24 +01:00
Kornel Pal 1d9c211eed PE: Make imports in decompressor stub optional 2021-12-22 03:00:17 +01:00
Kornel Pal 76ddf6b8da PE: Add position independent decompressor stub for i386 2021-12-22 02:58:09 +01:00
Kornel Pal 7f1f29b0d8 PE: Remove empty non-compressed section 2021-12-22 02:57:10 +01:00
Kornel Pal 222471744f PE: Remove file alignment restriction 2021-12-22 02:56:09 +01:00
Kornel Pal cc100be26e PE: Fix stripped relocation handling 2021-12-22 02:55:33 +01:00
Kornel Pal 966b571b7c PE: Use no red zone on AMD64 2021-12-16 06:59:26 +01:00
Kornel Pal f3e710394a PE: Set header size on 64-bit too 2021-12-16 06:57:39 +01:00
Kornel Pal bfd1f1fbfa PE: Fix relocation parsing and validation 2021-12-16 06:56:01 +01:00
Efreak a09146b5e0 unreferenced variable breaks build 2021-12-02 14:00:40 -08:00
John Reiser bbf2b08f48 Update testsuite with new signatures for i386-linux.elf
https://github.com/upx/upx/issues/540
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
2021-12-03 08:53:08 -08:00
John Reiser e2dbc661f1 Sync stub
modified:   stub/i386-linux.elf-entry.h
2021-12-03 08:38:26 -08:00
John Reiser 7626e09f66 Fix jl ==> jb (unsigned compare)
modified:   stub/src/i386-linux.elf-entry.S
2021-12-03 08:27:23 -08:00
Kirill A. Korinsky 248a6980cf Revert -std=c++14
This commit reverts 648fa30f22 which was removed by d60c46371d which is fixed https://github.com/upx/upx/issues/440
2021-11-27 13:22:54 +01:00
John Reiser f956bfc797 Allow slack for non-GLIBC tool chains versus -Wzero-as-null-pointer-constant
https://github.com/upx/upx/pull/531
	modified:   conf.h
2021-11-27 06:58:38 -08:00
bitraid 6da79783ea PE: Handle empty imports 2021-05-15 21:41:31 +03:00
a1346054 22329e0ab2 trim excess whitespace 2021-08-22 11:23:41 +00:00
a1346054 a94b0329c9 update codestyle in travis scripts to conform to guidelines
* adds and fixes indentation in a few places
* removes redundant quotes
* adds quotes around some arguments to silence shellcheck warnings
* fixes spelling
2021-08-22 11:21:28 +00:00
a1346054 be8601f8cc use grep -E instead of egrep
egrep will go away at some point, and grep -E is standardized
2021-08-22 11:19:38 +00:00
John Reiser bd441e83ae WIP: de-compression of old-style shlib
modified:   p_lx_elf.cpp
2021-09-06 08:43:20 -07:00
John Reiser 02bd9cc403 IMAGE_SUBSYSTEM_EFI_APPLICATION
Beginning of support for compressing EFI files; lacks run-time decompressor.
https://github.com/upx/upx/issues/518
	modified:   p_armpe.cpp
	modified:   p_w32pe.cpp
	modified:   p_w64pep.cpp
	modified:   pefile.cpp
	modified:   pefile.h
2021-09-06 08:38:51 -07:00
John Reiser c9f6a3583c WIP 64-bit shlib
modified:   p_lx_elf.cpp
2021-08-07 06:45:01 -07:00
John Reiser 076aaf829a WIP: Elf64 shlib compress+decompress seems to work
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_unix.cpp
2021-07-05 13:47:19 -07:00
John Reiser 85f0c5a445 WIP: Elf64 shlib cleanup
modified:   file.cpp
	modified:   file.h
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2021-07-02 18:33:38 -07:00
John Reiser d5263a56ce WIP: handling shared library
modified:   p_lx_elf.cpp
	modified:   p_unix.cpp
	modified:   p_unix.h
2021-05-22 16:03:53 -07:00
John Reiser ef5b55b4d1 sync stubs
https://github.com/upx/upx/issues/441
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
2021-05-16 10:14:03 -07:00
Markus F.X.J. Oberhumer d65e65b2b1 Update CI. 2021-05-15 07:24:16 +02:00
Markus F.X.J. Oberhumer 6aa641e5aa Update submodules. 2021-05-15 06:03:48 +02:00
John Reiser 504839951a arm64 clear_cache at end of de-compress
https://github.com/upx/upx/issues/441
	modified:   stub/src/arch/arm64/v8/macros.S

	modified:   stub/src/arch/arm64/v8/lzma_d.S
	modified:   stub/src/arch/arm64/v8/nrv2b_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2d_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2e_d32.S

	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2021-05-16 09:53:03 -07:00
bitraid d55746f62d PE: disable CFG and compress with --force 2021-05-01 18:05:27 +03:00
bitraid 144010295e Improve --strip-relocs
- Remove .reloc section
- Enable for 64-bit images
- Abort if explicitly set on unsupported image
- Use with --force to remove ASLR / apply when imagebase < default
2021-04-25 20:15:07 +03:00
John Reiser 181c752488 WIP: un_shlib_1
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2021-05-08 11:14:31 -07:00
John Reiser bd4aca5c12 generated stub files
https://github.com/upx/upx/issues/473
	modified:   stub/mips.r3000-linux.shlib-init.h
	modified:   stub/mipsel.r3000-linux.shlib-init.h
	modified:   stub/tmp/mips.r3000-linux.shlib-init.bin.dump
	modified:   stub/tmp/mipsel.r3000-linux.shlib-init.bin.dump
2021-05-07 11:15:41 -07:00
John Reiser ad6d73c875 /proc/self/auxv for AT_PAGESZ because musl calls _init with no args
https://github.com/upx/upx/issues/473
	modified:   mipsel.r3000-linux.shlib-init.S
2021-05-07 09:36:07 -07:00
bitraid c5cc83d424 Fix unoptimizeReloc() to process all relocs 2021-04-21 23:06:55 +03:00
bitraid fe949bdf67 Build: Enable wildcard argument expansion for msvc 2021-04-12 11:20:13 +03:00
John Reiser 766fe466d6 PAGE_SIZE varies: Apple M1 uses 16K
modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   p_mach_enum.h
2021-04-11 15:19:24 -07:00
John Reiser 333a288248 shlib: Don't compress below xct_off (except Elf headers)
modified:   p_lx_elf.cpp
2021-04-11 15:16:34 -07:00
John Reiser 613df414ed Fix off-by-1 in invert_pt_dynamic; SHT_NOBITS occupies no space
modified:   p_lx_elf.cpp
2021-04-11 15:09:55 -07:00
John Reiser be050693f2 PackLinuxElf::canUnpack must checkEhdr() for ELF input
https://github.com/upx/upx/issues/485
	modified:   p_lx_elf.cpp
2021-04-10 10:11:48 -07:00
goushibee bf957f435e fix issue 486 2021-04-07 15:40:13 +08:00
John Reiser 3a6f688265 Sync testsuite checksums for PE: fix SizeOfHeaders
https://github.com/upx/upx/pull/483
	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
2021-04-10 08:51:27 -07:00
Sebastien Rosset (serosset) 1084a7896c Add default goal 2021-04-03 13:08:01 -07:00
bitraid 9ea2b31541 PE: fix SectionHeadersSize of SizeOfHeaders value 2021-04-06 22:49:31 +03:00
Sebastien Rosset (serosset) 09da986742 build instructions 2021-04-03 11:57:05 -07:00
John Reiser cb70a5fef5 Enable usual grep for function definition
Developer convenience: no space between function name and left paren
	modified:   compress.cpp
2021-04-03 12:46:20 -07:00
John Reiser 4fa6a6aeef Sync testsuite checksums for PE: fix SizeOfHeaders
https://github.com/upx/upx/pull/477
	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
2021-04-02 19:37:29 -07:00
Markus F.X.J. Oberhumer ab31e8dde9 testsuite: change exit code to 98 for FATAL decompression checksum mismatchs. 2021-03-28 22:06:42 +02:00
Markus F.X.J. Oberhumer 53d7b5449f testsuite: change exit code to 99 for checksum mismatchs. 2021-03-28 21:49:32 +02:00
Markus F.X.J. Oberhumer d33a34f016 Revert some changes from previous commit to pacify clang
-Winconsistent-missing-override warnings.
2021-03-28 21:40:13 +02:00
Markus F.X.J. Oberhumer f6ff5a2805 Cleanups: start working on -Wsuggest-override, add some "final". NFCI. 2021-03-28 21:19:29 +02:00
bitraid 1518e5bc98 PE: fix SizeOfHeaders value of Optional Header field 2021-03-25 21:41:49 +02:00
John Reiser 78f48d65d5 Allow 0==nbucket for DT_HASH, DT_GNU_HASH
static linked 'Rust' program with no symbols
https://github.com/upx/upx/issues/476
2021-03-25 07:22:01 -07:00
John Reiser b81ec224b7 Fix headway argument to invert_pt_dynamic()
https://github.com/upx/upx/issues/473
	modified:   p_lx_elf.cpp
2021-03-25 07:10:40 -07:00
John Reiser 4be6cfebcd get_te32() when checking DT_GNU_HASH chains (MIPS .so)
https://github.com/upx/upx/issues/473
        modified:   p_lx_elf.cpp
2021-03-23 18:21:45 -07:00
John Reiser 98973dd8b9 get_te32() when checking DT_HASH chains (MIPS .so)
https://github.com/upx/upx/issues/473
	modified:   p_lx_elf.cpp
2021-03-23 06:45:01 -07:00
John Reiser 1218b6ff2a Check more in invert_pt_dynamic
https://github.com/upx/upx/issues/471
	modified:   p_lx_elf.cpp
2021-03-16 18:46:11 -07:00
John Reiser ba5c77c9e5 Reject if MZ and PE headers overlap
Overlap ('leanify', etc.) causes headaches.
https://github.com/upx/upx/issues/231
	modified:   p_w32pe.cpp
	modified:   p_w64pep.cpp
	modified:   pefile.cpp
2021-03-14 15:20:15 -07:00
jsm174 cbaedffce2 ci: make artifacts for all builds 2021-03-09 09:36:08 -05:00
John Reiser cb60603950 Turn off BUILD_TYPE_DEBUG to enable CI build amd64-win64-gcc-9 to pass.
modified:   Makefile
2021-03-07 09:33:16 -08:00
John Reiser 0a69e7803b Fix errors detected by "make run-testsuite".
total_out does not matter when option -t writes no output file.
Subtle error in generateElfHdr() [noted by address sanitizer].
New member function is_LOAD32() to avoid confusion with (1+ LO_PROC).
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2021-03-06 15:31:56 -08:00
John Reiser baa9090198 Change back to lzma-sdk d5bed9963d051c9e5690b12199eab6884a592c43
modified:   lzma-sdk
2021-03-06 12:05:23 -08:00
John Reiser e78a08b8fc change lzma-sdk to latest commit 44db23cc6d6b607986dace07b17fece1af925558 on its master 2021-03-06 10:46:40 -08:00
John Reiser 7e5e6012df PackMachFat::canPack handles case PackMachFat::CPU_TYPE_ARM64
modified:   p_mach.cpp
2021-03-06 09:59:51 -08:00
John Reiser 0a1d24d1d9 Remove nit from PackLinuxElf64::generateElfHdr [address sanitizer]
modified:   p_lx_elf.cpp
2021-03-05 16:33:25 -08:00
John Reiser 35555bfb8a WIP: PackLinuxElf64::unpack working for shared libraries (non-Android)
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_unix.cpp
2021-03-05 16:20:36 -08:00
John Reiser c9cb42df40 WIP: hacking un_shlib_1
modified:   p_lx_elf.cpp
2021-02-28 17:12:20 -08:00
John Reiser 2be03028f4 WIP: un_shlib_1
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2021-02-27 19:27:12 -08:00
John Reiser 214dd0a522 4 fewer bytes of code?
modified:   arm64-linux.elf-fold.h
	modified:   tmp/arm64-linux.elf-fold.map
2021-02-23 02:24:24 -08:00
John Reiser 182e0796df Split PackLinuxElf64::unpack for main program vs shared library
modified:   p_lx_elf.cpp
2021-02-22 16:15:03 -08:00
John Reiser fb844a8ed1 total_in, total_out move to PackUnix
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_lx_interp.cpp
	modified:   p_mach.cpp
	modified:   p_unix.cpp
	modified:   p_unix.h
2021-02-22 16:13:40 -08:00
John Reiser 6be3e747ca Remove unrelated debugging
modified:   stub/src/arm64-linux.elf-fold.S
2021-02-15 11:40:04 -08:00
John Reiser 23f63e4196 WIP unpacking ELF shared library
modified:   Makefile
	modified:   lzma-sdk
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_mach.cpp
	modified:   p_unix.cpp
	modified:   p_unix.h
	modified:   packer.cpp
	modified:   packer.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/tmp/arm64-linux.elf-fold.map
2021-01-15 14:11:09 -08:00
John Reiser fd6837b267 Another checkAlreadyPacked()
https://github.com/upx/upx/issues/463
	modified:   Makefile
	modified:   p_mach.cpp
2021-02-26 15:15:28 -08:00
John Reiser 1c29f921e0 getSizeForCompression worst cases
https://github.com/upx/upx/issues/463
	modified:   Makefile
	modified:   mem.cpp
2021-02-25 20:04:16 -08:00
John Reiser 1ab6e01de2 MacOS BigSur wants no MH_DYLDLINK for our MH_EXECUTE
https://github.com/upx/upx/issues/434
	modified:   p_mach.cpp
2021-02-14 13:23:19 -08:00
Markus F.X.J. Oberhumer 801618740c CI: fix current Ubuntu problem. 2021-02-01 13:06:49 +01:00
John Reiser 2469563b26 Mach_ARM64_thread_state padded to (0 mod 8)
https://github.com/upx/upx/issues/446  (partial)
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   p_mach_enum.h
2021-01-30 16:11:32 -08:00
John Reiser 00139caf43 More robust PackWcle::decodeFixups()
https://github.com/upx/upx/issues/455
	modified:   p_wcle.cpp
2021-01-23 15:37:52 -08:00
John Reiser 21d102c84f Better checking of Mach_header.ncmds, .sizeofcmds
Improves earlier fix.
https://github.com/upx/upx/issues/447
	modified:   p_mach.cpp
2021-01-23 13:52:54 -08:00
John Reiser f17d9967c2 Clarify comment in previous commit
modified:   main.cpp
2021-01-20 05:54:53 -08:00
Liam Murphy 0569ef37ba add comment explaining code as per PR review 2021-01-20 02:29:08 +00:00
Liam Murphy 984334c9a1 reset done_output_name counter upx_main() 2021-01-18 00:16:49 +00:00
John Reiser 34a25e61c7 "%zx" for ptrdiff_t in hex printf
modified:   p_wcle.cpp
2021-01-17 19:36:36 -08:00
John Reiser ed3f45953e Try not to run off the end of selfrel_fixups.
https://github.com/upx/upx/issues/455
	modified:   p_wcle.cpp
	modified:   packer.cpp
2021-01-17 19:21:32 -08:00
John Reiser 80de11bc5b Detect Mach_header.sizeofcmds==0
https://github.com/upx/upx/issues/448
	modified:   p_mach.cpp
2021-01-17 17:09:35 -08:00
Darío Hereñú c9fe84c9aa Typo fixed (line 61) 2021-01-09 14:04:47 -03:00
John Reiser 5f98bb0ab0 De-compress allows old-style LC_UNIXTHREAD with one LC_SEGMENT
https://github.com/upx/upx/issues/447
	modified:   p_mach.cpp
2021-01-15 15:03:26 -08:00
Markus F.X.J. Oberhumer d86d5314ba Modernize libc usage: more cleanups. 2021-01-05 22:03:29 +01:00
Markus F.X.J. Oberhumer 700c8730cf Modernize libc usage: stop using off_t, use modern printf.
C++ 14 is here, and old versions of MSVC and MSVCRT have
haunted us long enough.
2021-01-05 18:52:05 +01:00
Markus F.X.J. Oberhumer b4429e1a42 CI: add sanitizer builds. 2021-01-04 22:03:23 +01:00
Markus F.X.J. Oberhumer a8fa3ca5cf Use correct native types with "alignas(1)". 2021-01-04 21:13:49 +01:00
Markus F.X.J. Oberhumer 9aef7b0d6f Use C++ 14 alignas(), init some struct fields just because of good practice. 2021-01-04 21:02:07 +01:00
Markus F.X.J. Oberhumer 2575eef3c0 clang-format more files.
"Gofmt's style is nobody's favourite, but gofmt is everybody's favourite."
    - Rob Pike
2021-01-04 20:26:31 +01:00
Markus F.X.J. Oberhumer 8236276a90 Add and use .clang-format file. 2021-01-04 19:07:17 +01:00
Markus F.X.J. Oberhumer fdc68812c5 clang-format-10.0.1 files. 2021-01-04 17:27:48 +01:00
Markus F.X.J. Oberhumer 9db6d18d11 Now using upx-stubtools 20210104 with new clang-format-10.0.1. 2021-01-04 17:23:57 +01:00
Markus F.X.J. Oberhumer f962afe146 Various cosmetic updates and refactors. NFCI. 2021-01-04 17:20:57 +01:00
Markus F.X.J. Oberhumer adcd569852 Makefile: update default sanitizer flags. 2021-01-04 17:20:06 +01:00
Markus F.X.J. Oberhumer d045b7f223 Update bele.h to better work with modern compilers. 2021-01-02 16:45:58 +01:00
Markus F.X.J. Oberhumer 57cb6a7530 CI: add mingw64 build. 2021-01-02 01:03:24 +01:00
Markus F.X.J. Oberhumer baa1ed9be3 Update CI to use lastest zlib. Update Makefile. 2021-01-01 23:24:31 +01:00
Markus F.X.J. Oberhumer 16af6e1a29 Update testsuite checksums caused by version bump. 2021-01-01 20:52:07 +01:00
Markus F.X.J. Oberhumer 0af8998be6 Bump version date. 2021-01-01 20:45:11 +01:00
Markus F.X.J. Oberhumer c32f517fa5 Remove obsolete PROJECTS file. 2021-01-01 20:43:34 +01:00
Markus F.X.J. Oberhumer 9131d5216f Welcome 2021. 2021-01-01 20:39:22 +01:00
Markus F.X.J. Oberhumer fb14a7991d Fix Makefile breakage in previous commit. 2020-12-15 02:15:34 +01:00
Markus F.X.J. Oberhumer ff53862dab Extract upx_main() for compilation with -DWITH_GUI. 2020-12-14 22:10:07 +01:00
Markus F.X.J. Oberhumer 49245a20c5 Update Makefile and compiler checks so that users don't inadvertently
change mandatory compiler flags.
2020-12-14 20:53:54 +01:00
John Reiser 13bc031163 Check DT_REL/DT_RELA, DT_RELSZ/DT_RELASZ
https://github.com/upx/upx/issues/421
	modified:   p_lx_elf.cpp
2020-12-11 13:38:18 -08:00
John Reiser 0c18c1c35c Include --lzma as a compression tuning option in --help.
modified:   help.cpp
2020-12-11 12:34:38 -08:00
John Reiser 63dc19ce25 -std=c++14
modified:   Makefile
2020-12-11 11:38:38 -08:00
John Reiser 6871c2fc0a Tweak unoptimizeReloc again
modified:   packer.cpp
2020-12-10 19:56:02 -08:00
Markus F.X.J. Oberhumer 4ae3a8b2b0 Revert useless "fast exit" check from b2c00aa637. 2020-12-08 07:13:11 +01:00
Markus F.X.J. Oberhumer f2e562b5de Update CI. 2020-12-08 06:22:10 +01:00
Markus F.X.J. Oberhumer f7e2266c3f Start using some C++ 14 features. 2020-12-08 05:40:17 +01:00
Markus F.X.J. Oberhumer 361a3056cb Update submodules. 2020-12-08 05:40:07 +01:00
Markus F.X.J. Oberhumer ca0437556d Start using "noexcept". 2020-12-08 00:45:41 +01:00
Markus F.X.J. Oberhumer 51899957a9 Require C++ 14. Finally!
This is the default for gcc >= 6, clang >= 6 and MSVC >= 2019.
2020-12-07 23:05:13 +01:00
Markus F.X.J. Oberhumer 7b0b760d78 src/Makefile: add -Wsign-compare to warning flags to better match MSVC. 2020-12-07 23:04:37 +01:00
Markus F.X.J. Oberhumer 4f5866b5a7 Remove AppVeyor CI. 2020-12-07 23:04:01 +01:00
John Reiser a6b5033cf1 Fix overlap detection for PE unoptimizeReloc()
https://github.com/upx/upx/issues/438
	modified:   packer.cpp
2020-12-10 19:31:56 -08:00
John Reiser a6296ecd67 Avoid complaint from "gcc -Wsign-conversion"
modified:   compress_lzma.cpp
	modified:   compress_zlib.cpp
2020-12-06 15:22:58 -08:00
John Reiser bb1df15958 Use 'mb_' prefix on instances of MemBuffer
modified:   pefile.cpp
	modified:   pefile.h
2020-12-05 13:53:14 -08:00
Liam Murphy 249431f45f tweak formatting to reduce diff 2020-11-26 03:00:21 +00:00
Liam Murphy cbe129795e migrate to MemBuffer class from New() to remove leak 2020-11-26 00:14:00 +00:00
John Reiser 2a135e245b Prefer MemBuffer instead of New()+delete
https://github.com/upx/upx/issues/428
	modified:   pefile.cpp
	modified:   pefile.h
2020-12-05 13:44:19 -08:00
Markus F.X.J. Oberhumer 05a0b3557a Update CI. 2020-12-05 14:04:46 +01:00
Markus F.X.J. Oberhumer c7cfe8b608 Remove Travis CI. 2020-12-05 06:29:57 +01:00
Markus F.X.J. Oberhumer 8d3e1d28a7 Update GitHub CI. 2020-12-05 04:37:30 +01:00
John Reiser 7841e15583 Prefer MemBuffer instead of New()+delete
https://github.com/upx/upx/issues/428
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2020-12-05 10:31:55 -08:00
Markus F.X.J. Oberhumer dd164fbc86 Undo Makefile change in 9b0f523d00. 2020-12-03 18:16:11 +01:00
Markus F.X.J. Oberhumer 23fe02e84a Add GitHub Actions CI. 2020-12-03 13:58:38 +01:00
Markus F.X.J. Oberhumer 94e72238f2 Fix some warnings. 2020-12-03 03:10:12 +01:00
Markus F.X.J. Oberhumer 8f7ac520eb Run clang-format. 2020-12-03 02:15:14 +01:00
Markus F.X.J. Oberhumer bd193201b2 Avoid a clang-11 warning. 2020-12-03 02:14:47 +01:00
Markus F.X.J. Oberhumer 8ced672d24 docs: add a note about security considerations. 2020-12-03 02:10:05 +01:00
Markus F.X.J. Oberhumer f218812858 Fix spelling of some constants. 2020-12-03 01:46:30 +01:00
Markus F.X.J. Oberhumer 8a7b980fc0 Avoid a MSVC warning. 2020-12-03 01:44:09 +01:00
Markus F.X.J. Oberhumer 385c9877f8 Update submodules. 2020-12-03 01:27:05 +01:00
John Reiser 10df93536e Yet another attempt to suppress MSVC C4245
https://github.com/upx/upx/issues/435
	modified:   pefile.cpp
2020-11-29 00:01:22 -08:00
John Reiser 6cad27896f Another attempt to suppress MSVC C4245
https://github.com/upx/upx/issues/435
	modified:   pefile.cpp
2020-11-28 23:53:49 -08:00
John Reiser 052392d97b Attempt workaround for MSVC C4245 signed/unsigned mismatch in template 'argument'
https://github.com/upx/upx/issues/435
	modified:   pefile.cpp
2020-11-28 20:23:01 -08:00
John Reiser ce6b5a0688 Fix MSVC warning C4245: signed/unsigned mismatch in prototype matching
The type of the return value must match exactly the function prototype.
MSVC warning C4245: 'argument': conversion from 'int' to 'unsigned int', signed/unsigned mismatch
https://github.com/upx/upx/issues/435
	modified:   bele_policy.h
2020-11-28 19:45:54 -08:00
John Reiser 1879185e42 Check Mach_command.cmdsize
https://github.com/upx/upx/issues/426
Also use MemBuffer to avoid leaks that result from throw()
	modified:   p_mach.cpp
	modified:   p_mach.h
2020-11-28 10:56:28 -08:00
John Reiser a928a08f9d ptrTEXT in PackMachBase<T>::canUnpack()
https://github.com/upx/upx/issues/417
	modified:   p_mach.cpp
2020-11-06 19:14:18 -08:00
John Reiser 1805cb6857 headway vs size
https://github.com/upx/upx/issues/414
	modified:   packhead.cpp
2020-11-06 14:25:36 -08:00
Liam Murphy 6ce625b535 fix build 2020-11-05 22:21:19 +00:00
Liam Murphy 4702f12818 tweaks: some extra checks on lengths 2020-11-05 04:43:40 +00:00
Matthijs Lavrijsen 4f3054f07d PE: only add a TLS relocation if tls_handler_offset_reloc != 0 2020-09-08 11:44:56 +02:00
bitraid 0d7bd52e21 Only pack w/ -f PE files that force integrity check 2020-10-31 19:53:33 +02:00
John Reiser c3466f579c fillPackHeader: revise and add yet more checks
https://github.com/upx/upx/issues/414
https://github.com/upx/upx/pull/415  revised
	modified:   packhead.cpp
2020-11-06 13:53:29 -08:00
John Reiser 7c105d7af5 omemmove exactly as much
Fix 14992260c60b8d6677a677a9cdfae98b11353df7; revealed by testsuite
	modified:   pefile.cpp
2020-11-05 15:05:52 -08:00
John Reiser 924b229afb fillPackHeader more checks
https://github.com/upx/upx/issues/414
	modified:   packhead.cpp
2020-11-03 01:58:39 -08:00
John Reiser 890d66ecf0 Avoid overlap when rebuild relocs.
Based on a hint from a little bird.
	modified:   packer.cpp
2020-09-20 15:08:39 -07:00
John Reiser 143049922b Beware overlap when rebuildImports
Based on a hint from a little bird.
	modified:   pefile.cpp
2020-09-20 14:10:24 -07:00
John Reiser e6ccef2cf1 MSVC strikes again
modified:   p_lx_elf.cpp
2020-09-05 19:19:11 -07:00
John Reiser be61e9f584 Fix 64-bit ET_EXEC
https://github.com/upx/upx/issues/405
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-main.c

	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/arm64-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/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2020-09-04 10:21:14 -07:00
Mattiwatti 89d0fda9fa Make PE load config directory address dword aligned 2020-01-21 16:03:40 +01:00
bitraid 6a85bab5da Don't pack Cotrol Flow Guard PE files 2020-07-28 17:36:13 +03:00
John Reiser c1a55b063e 0==e_shnum obviates testing of e_shoff
modified:   p_lx_elf.cpp
2020-07-26 20:00:05 -07:00
John Reiser 77c914bce5 Check de-compressed SHT_SYMTAB
https://github.com/upx/upx/issues/396
	modified:   p_lx_elf.cpp
2020-07-25 09:28:02 -07:00
John Reiser cc60f03b2e Check Shdr more
https://github.com/upx/upx/issues/395
	modified:   p_lx_elf.cpp
2020-07-25 08:19:45 -07:00
John Reiser cc9ccdbbd1 Check .sh_offset and .sh_size in SHT_DYNAMIC and SHT_STRNDX
https://github.com/upx/upx/issues/394
	modified:   p_lx_elf.cpp
2020-07-25 07:41:43 -07:00
John Reiser 9dfc8f573c Avoid 0==nbucket
https://github.com/upx/upx/issues/393
	modified:   p_lx_elf.cpp
2020-07-23 05:44:18 -07:00
John Reiser 4e2fdb464a Defend against bad PT_DYNAMIC
https://github.com/upx/upx/issues/391
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2020-07-23 05:09:52 -07:00
John Reiser 73b854874e Defend against junk PT_DYNAMIC
https://github.com/upx/upx/issues/390
	modified:   p_lx_elf.cpp
2020-07-23 04:14:34 -07:00
John Reiser 0016512df1 Unpack: Phdrs must be within expansion of first compressed block
https://github.com/upx/upx/issues/388
	modified:   p_lx_elf.cpp
2020-07-22 19:34:27 -07:00
John Reiser 527139978a DT_HASH chains might be trimmed (64-bit, too)
https://github.com/upx/upx/issues/383
	modified:   p_lx_elf.cpp
2020-06-08 12:37:53 -07:00
John Reiser 47bc68fa6b DT_HASH chains might be trimmed
https://github.com/upx/upx/issues/383
	modified:   p_lx_elf.cpp
2020-06-07 19:35:49 -07:00
John Reiser 972b670a64 Set .b_extra for hdr, especially for Mach-o for 'go'.
https://github.com/upx/upx/issues/222
	modified:   p_unix.cpp
2020-06-06 17:11:32 -07:00
John Reiser d7c416f243 More DPRINTF debugging
modified:   stub/src/amd64-darwin.macho-main.c
2020-06-06 17:10:53 -07:00
John Reiser 3ace7a0468 Documentation only
modified:   stub/src/amd64-darwin.macho-main.c
2020-06-06 15:32:45 -07:00
John Reiser d305023f5e Sync testsuite checksums for "ELF pageholes" feature
modified:   .github/travis_testsuite_1-expected_sha256sums.sh
2020-05-30 13:56:12 -07:00
John Reiser 963392a5ae De-compress (upx -d) for ELF pageholes
modified:   p_lx_elf.cpp
2020-05-30 13:54:11 -07:00
John Reiser 2f453acf5d use UPX_RSIZE_MAX_MEM
modified:   p_mach.cpp
2020-05-28 15:45:07 -07:00
John Reiser 4ae1576726 Mach-o LC_SEGMENTs not monotonic in file (__DWARF for 'go')
https://github.com/upx/upx/issues/222  go-1.14 (but not go-1.14.3 ?)
	modified:   ../p_mach.cpp
	modified:   ../p_mach.h
	modified:   ../p_unix.cpp
	modified:   ../p_unix.h
	modified:   ../stub/src/amd64-darwin.macho-main.c

	modified:   ../stub/amd64-darwin.macho-fold.h
	modified:   ../stub/arm.v5a-darwin.macho-fold.h
	modified:   ../stub/arm64-darwin.macho-fold.h
	modified:   ../stub/tmp/amd64-darwin.macho-fold.map
	modified:   ../stub/tmp/arm.v5a-darwin.macho-fold.map
	modified:   ../stub/tmp/arm64-darwin.macho-fold.map
2020-05-30 02:54:09 -07:00
bitraid 17bd0b3248 Don't use --strip-reloc with -d
Always restore the relocation section of Portable Executables on
unpacking, if it exists in the compressed image.
2020-04-13 21:38:22 +03:00
Markus F.X.J. Oberhumer a1ad1aee99 Use "python2" instead of "python". 2020-05-23 20:07:23 +02:00
John Reiser a817ed0692 uintptr_t for MSVC
modified:   p_lx_elf.cpp
2020-05-23 11:02:46 -07:00
John Reiser 828a6cf07b invert_pt_dynamic() more checking
https://github.com/upx/upx/issues/378
https://github.com/upx/upx/issues/379
	modified:   p_lx_elf.cpp
2020-05-23 10:51:03 -07:00
John Reiser 962c35aa08 More checking of DT_GNU_HASH and DT_HASH tables
https://github.com/upx/upx/issues/381
	modified:   p_lx_elf.cpp
2020-05-23 10:04:38 -07:00
John Reiser b327645e64 More checking of DT_GNU_HASH and DT_HASH tables
https://github.com/upx/upx/issues/380
	modified:   p_lx_elf.cpp
2020-05-23 09:41:41 -07:00
John Reiser e1b42616a2 workaround: MIPS.r3000 early uClibc forgot memset(,0,) of local array
ldso/ldso/ldso.c: _dl_get_ready_to_run()
    _dl_memset(app_tpnt, 0, sizeof(*app_tpnt));
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S

	modified:   stub/mips.r3000-linux.elf-fold.h
	modified:   stub/mipsel.r3000-linux.elf-fold.h
2020-05-26 14:49:25 -07:00
John Reiser f96638c42a MIPS32 works: ELF layout for page holes
modified:   stub/src/include/linux.h
	modified:   stub/src/mipsel.r3000-linux.elf-entry.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S

	modified:   stub/mips.r3000-linux.elf-entry.h
	modified:   stub/mips.r3000-linux.elf-fold.h
	modified:   stub/mipsel.r3000-linux.elf-entry.h
	modified:   stub/mipsel.r3000-linux.elf-fold.h
	modified:   stub/tmp/mips.r3000-linux.elf-entry.bin.dump
	modified:   stub/tmp/mips.r3000-linux.elf-fold.map
	modified:   stub/tmp/mipsel.r3000-linux.elf-entry.bin.dump
	modified:   stub/tmp/mipsel.r3000-linux.elf-fold.map
2020-05-25 14:13:01 -07:00
John Reiser 6272152dfe phdr[C_BASE].p_memsz for ET_EXEC
modified:   p_lx_elf.cpp
2020-05-25 14:11:46 -07:00
John Reiser 030a200c08 clarity; no functional change
modified:   stub/src/powerpc-linux.elf-entry.S
2020-05-25 14:07:58 -07:00
John Reiser 994da63b4d DPRINTF the munmap
modified:   stub/src/i386-linux.elf-main.c
2020-05-25 14:05:58 -07:00
John Reiser 2315bff280 powerpc64 works: ELF layout for page holes
modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S

	modified:   stub/powerpc64-linux.elf-entry.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/tmp/powerpc64-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2020-05-23 11:18:32 -07:00
John Reiser 98dddf93d8 powerpc32 works: ELF layout for page holes
modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S

	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-fold.map
2020-05-23 08:00:35 -07:00
John Reiser fd2939e18d i386 works: ELF layout for page holes
modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-main.c

	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/armeb.v4a-linux.elf-fold.h
	modified:   stub/i386-linux.elf-entry.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/src/include/linux.h
	modified:   stub/tmp/arm.v4a-linux.elf-fold.map
	modified:   stub/tmp/arm.v5a-linux.elf-fold.map
	modified:   stub/tmp/armeb.v4a-linux.elf-fold.map
	modified:   stub/tmp/i386-linux.elf-entry.bin.dump
	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
2020-05-15 16:05:26 -07:00
John Reiser 80c27e0822 arm.v4a works: ELF layout for page holes
modified:   p_lx_elf.cpp
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S

	modified:   stub/arm.v4a-linux.elf-entry.h
	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-entry.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/armeb.v4a-linux.elf-entry.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/tmp/arm.v4a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v4a-linux.elf-fold.map
	modified:   stub/tmp/arm.v5a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v5a-linux.elf-fold.map
	modified:   stub/tmp/armeb.v4a-linux.elf-entry.bin.dump
	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
2020-05-14 15:10:40 -07:00
John Reiser b463f24eda arm64 works: ELF layout for page holes
modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S

	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-fold.map
2020-05-10 09:18:06 -07:00
John Reiser 2a849444db un-debug
modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
2020-05-09 09:46:51 -07:00
John Reiser 69e106c0c5 unmap C_TEXT
modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
2020-05-09 09:45:02 -07:00
John Reiser 926481dace ELF layout for page holes when runtime PAGE_SIZE < .p_align
amd64 works
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   Makefile
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/amd64-linux.shlib-init.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/src/amd64-linux.shlib-init.S
	modified:   stub/tmp/amd64-linux.elf-entry.bin.dump
	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   stub/tmp/amd64-linux.shlib-init.bin.dump
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2020-05-09 08:05:05 -07:00
John Reiser a3b2cde58d max_bucket versus symbias
modified:   p_lx_elf.cpp
2020-04-17 17:09:47 -07:00
John Reiser 30f37d2cc6 DT_GNU_HASH check the buckets
https://github.com/upx/upx/issues/365
	modified:   p_lx_elf.cpp
2020-04-17 16:49:54 -07:00
John Reiser c4d61dd9fe --preserve-build-id for ET_EXEC
https://github.com/upx/upx/issues/371
	modified:   p_lx_elf.cpp
2020-04-17 16:17:29 -07:00
John Reiser 210870f840 invert_pt_dynamic() DT_GNU_HASH trims hash array for Rust and Android
https://github.com/upx/upx/issues/369
	modified:   p_lx_elf.cpp
2020-04-15 17:29:03 -07:00
John Reiser 4cb4bd38eb check_pt_dynamic() checks PT_DYNAMIC.p_memsz
https://github.com/upx/upx/issues/368
	modified:   p_lx_elf.cpp
2020-04-15 14:24:05 -07:00
John Reiser 58c6d19f7c unpack() checks PT_DYNAMIC.p_filesz
https://github.com/upx/upx/issues/367
	modified:   p_lx_elf.cpp
2020-04-15 14:12:06 -07:00
John Reiser f99ae94747 More checking .e_shstrndx
https://github.com/upx/upx/issues/366
	modified:   p_vmlinx.cpp
2020-04-15 13:44:35 -07:00
John Reiser 6868ca7953 getElfSections concentrates on _Shdr[.e_shstrndx]
https://github.com/upx/upx/issues/363
	modified:   p_vmlinx.cpp
2020-04-15 13:29:01 -07:00
John Reiser 87a5a4ef32 WIP but should concentrate on section .e_shstrndx instead.
modified:   p_vmlinx.cpp
2020-04-15 13:13:45 -07:00
John Reiser c67a5d677c More bounds checking for DT_INIT (etc.) in shlib
https://github.com/upx/upx/issues/364
	modified:   p_lx_elf.cpp
2020-04-13 17:08:49 -07:00
bitraid 1ce6f0e6f4 Fix unpacking of ASLR enabled PE files 2020-04-12 03:19:57 +03:00
John Reiser 740b4ff865 ELF shared lib: PT_DYNAMIC might be below xct_off, such as MIPS
https://github.com/upx/upx/issues/298
	modified:   p_lx_elf.cpp
2020-02-15 15:04:44 -08:00
John Reiser 1059f62566 MIPS stub mprotect() suffered from [non-]inlining.
https://github.com/upx/upx/issues/342
https://github.com/upx/upx/issues/339
	modified:   src/stub/src/include/linux.h
   consequences:
	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
	modified:   src/stub/mips.r3000-linux.elf-fold.h
	modified:   src/stub/mipsel.r3000-linux.elf-fold.h
	modified:   src/stub/tmp/mips.r3000-linux.elf-fold.map
	modified:   src/stub/tmp/mipsel.r3000-linux.elf-fold.map
2020-02-08 19:55:08 -08:00
Markus F.X.J. Oberhumer df3193c1ee Use new ASCII art logo. 2020-01-23 00:21:44 +01:00
Jonas Zeitler 67860e3704 fix kerning on ascii art logo 2019-01-11 17:22:56 +01:00
Markus F.X.J. Oberhumer 35fbb1ecb6 Update testsuite checksums caused by version bump. 2020-01-22 23:26:41 +01:00
Markus F.X.J. Oberhumer c63a71ad42 Prepare for switch to semantic versioning. 2020-01-22 23:24:00 +01:00
Markus F.X.J. Oberhumer f33645f739 Post-release version bump. 2020-01-22 23:11:13 +01:00
Markus F.X.J. Oberhumer d7ba31cab8 Bump release date. 2020-01-22 22:29:58 +01:00
John Reiser 342b1b7d6c EM_PPC64 forgot get_te16(&...) for ehdri.e_machine
So compression on big-endian host was not correct.
https://github.com/upx/upx/issues/334
	modified:   p_lx_elf.cpp
2020-01-19 18:48:50 -08:00
John Reiser 936013f60c Decompression escape hatch for ELF can require a new page.
If not enough room on last page of .text, and ElfXX_Ehdr not PF_X,
then the escape hatch must use a new page.
https://github.com/upx/upx/issues/308
	modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-main.c
    Plus stub/*-linux.elf-fold.h and stub/tmp/*-linux.elf-fold.map
2020-01-19 13:25:55 -08:00
Markus F.X.J. Oberhumer fdf2eddc73 Update Travis. 2020-01-16 13:38:30 +01:00
Markus F.X.J. Oberhumer 4409753014 Update Travis. 2020-01-16 01:54:41 +01:00
Markus F.X.J. Oberhumer 9172ae3d19 New ACC version. 2020-01-16 01:53:55 +01:00
John Reiser e2f60adc95 Detect 0==DT_SYMTAB in invert_pt_dynamic()
https://github.com/upx/upx/issues/333
	modified:   p_lx_elf.cpp
2020-01-14 18:45:52 -08:00
John Reiser 1bb93d4fce Detect bad e_shstrtab better.
https://github.com/upx/upx/issues/332
	modified:   p_lx_elf.cpp
2020-01-13 17:26:31 -08:00
John Reiser eb90eab632 Detect bogus DT_SYMENT.
https://github.com/upx/upx/issues/331
	modified:   p_lx_elf.cpp
2020-01-13 17:10:02 -08:00
Markus F.X.J. Oberhumer 0f4975fd7f Update Travis. 2020-01-08 17:30:03 +01:00
Markus F.X.J. Oberhumer b5b1f06a11 Avoid some compilation warnings. 2020-01-08 06:04:21 +01:00
Markus F.X.J. Oberhumer 86f8eb0930 Fix shadowing global symbols. 2020-01-08 05:44:06 +01:00
Markus F.X.J. Oberhumer 91ad0e7572 Revert "Cleanup legacy symbols: basename, index"
This reverts commit 47ddace96a.
2020-01-08 05:41:56 +01:00
Markus F.X.J. Oberhumer b034ee98fe Revert "Mention --assume-execute-permission"
This reverts commit 29fa358077.
2020-01-08 05:40:40 +01:00
Markus F.X.J. Oberhumer ded07f8781 Revert "MSVC lacks S_IXUSR"
This reverts commit 62a07df45e.
2020-01-08 05:38:44 +01:00
Markus F.X.J. Oberhumer 849bdd87e1 Revert "Option --assume-execute-permission"
This reverts commit 4484acf9d6.
2020-01-08 05:38:19 +01:00
Markus F.X.J. Oberhumer 643e48efd7 Update Travis. 2020-01-08 05:18:43 +01:00
Markus F.X.J. Oberhumer 92f072cf70 Silence some compiler warnings. 2020-01-08 04:49:27 +01:00
Markus F.X.J. Oberhumer 95bf2e2e41 Update testsuite checksums caused by version date bump. 2020-01-08 04:37:59 +01:00
Markus F.X.J. Oberhumer 6a6c6d84eb Rebuild stubs. 2020-01-08 04:30:08 +01:00
Markus F.X.J. Oberhumer 08a689c81e Bump tentative release date. 2020-01-08 04:21:30 +01:00
Markus F.X.J. Oberhumer d1174385ef Welcome 2020. 2020-01-08 04:13:28 +01:00
John Reiser cb5f590e10 More hacking Android shlib.
https://github.com/upx/upx/issues/318
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2019-12-12 20:23:33 -08:00
John Reiser 5ed9c66ed9 Hack Android shared libraries on arm64.
https://github.com/upx/upx/issues/318
	modified:   p_lx_elf.cpp
2019-12-12 17:05:50 -08:00
John Reiser b8f52d14f4 user_init_va on AARCH64
https://github.com/upx/upx/issues/318  (work-in-progress)
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2019-12-04 14:26:46 -08:00
John Reiser 5d295c24f0 DT_NEEDED can be duplicated
modified:   p_lx_elf.cpp
2019-11-26 19:33:27 -08:00
John Reiser 8be9da8280 Avoid bogus values in PT_DYNAMIC segment.
Detect duplicate DT_*.
Detect out-of-bounds hashtab and gashtab.
Detect missing DT_REL, DT_RELA.
Detect out-of-bounds d_val.
https://github.com/upx/upx/issues/317
	modified:   p_lx_elf.cpp
2019-11-23 20:06:14 -08:00
John Reiser 819c33fee2 Detect malformed Mach-o file in ::canUnpack()
https://github.com/upx/upx/issues/314
https://github.com/upx/upx/issues/315
	modified:   p_mach.cpp
2019-11-15 21:32:06 -08:00
John Reiser 75a2cc4ecb Sync testsuite (amd64, 32-bit ARM, 64-bit ARM)
modified:   ../.github/travis_testsuite_1-expected_sha256sums.sh
	modified:   Makefile
2019-10-27 21:56:30 -07:00
John Reiser e2833cf303 Message when /proc/self/exe lacks Read permission
Done: amd64, 32-bit ARM, 64-bit ARM.  TODO: mips, PowerpC
https://github.com/upx/upx/issues/302
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/arm.v4a-linux.elf-entry.h
	modified:   stub/arm.v5a-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/armeb.v4a-linux.elf-entry.h
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/tmp/amd64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v4a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v5a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/armeb.v4a-linux.elf-entry.bin.dump
2019-10-27 21:30:41 -07:00
John Reiser 801de73dbe random assembler?
modified:   ../stub/arm64-linux.elf-entry.h
2019-10-27 21:15:15 -07:00
John Reiser 6a53c0b3d4 [Append to previous commit message.]
https://github.com/upx/upx/issues/286
	modified:   p_vmlinx.cpp
2019-07-21 10:51:59 -07:00
John Reiser 58b122d97d Better checking for malformed input
https://github.com/upx/upx/issues
	modified:   p_vmlinx.cpp
2019-07-21 10:48:50 -07:00
John Reiser 276b748aa6 Ignore malformed ElfXX_Shdr in search for .text or .note
https://github.com/upx/upx/issues/287
	modified:   p_vmlinx.cpp
2019-07-21 07:40:21 -07:00
John Reiser 23570097cf MSVC barfs on {unsigned == long int) [because sizeof() is the same!]
https://github.com/upx/upx/issues/283
	modified:   p_lx_elf.cpp
2019-07-14 13:39:09 -07:00
John Reiser 62a07df45e MSVC lacks S_IXUSR
modified:   p_unix.cpp
2019-07-14 13:38:51 -07:00
John Reiser 593a69ce25 PT_LOAD[0] with ElfXX.Ehdr only
https://github.com/upx/upx/issues/283
	modified:   p_lx_elf.cpp
2019-07-14 13:08:56 -07:00
John Reiser c33603e324 'bound' register was clobbered
modified:   stub/src/arch/arm64/v8/lzma_d-arm.S
2019-07-14 13:05:52 -07:00
John Reiser 29fa358077 Mention --assume-execute-permission
for MSYS2 and other permission-poor OS.
	modified:   NEWS
2019-05-10 07:03:51 -07:00
John Reiser 49766388bc Fix compression and de-compression of Android shared libraries
Handle relocation (and DT_INIT_ARRAY[0]==NULL) when !DT_INIT.
Warn about missing --android-shlib if (ET_DYN && !DF_1_PIE && Arm*).
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
https://github.com/upx/upx/issues/265
https://github.com/upx/upx/issues/262
https://github.com/upx/upx/issues/259
https://github.com/upx/upx/issues/243
https://github.com/upx/upx/issues/229
https://github.com/upx/upx/issues/220
2019-04-14 19:59:08 -07:00
John Reiser f23267bddd Fix rotate+lop of PT_INTERP in shared library
Found while working on https://github.com/upx/upx/issues/262
but probably does not help that bug.
	modified:   p_lx_elf.cpp
2019-04-01 21:35:53 -07:00
John Reiser 4484acf9d6 Option --assume-execute-permission
modified:   main.cpp
	modified:   options.h
	modified:   p_unix.cpp
https://github.com/upx/upx/issues/256
2019-03-31 10:25:06 -07:00
John Reiser 47ddace96a Cleanup legacy symbols: basename, index
modified:   conf.h
https://github.com/upx/upx/issues/257
2019-03-31 10:12:41 -07:00
John Reiser 8aadbcd786 Enable standalone compiling, to investigate size of compiled code
modified:   stub/src/arch/arm64/v8/lzma_d-arm.S
	modified:   stub/src/arch/arm64/v8/lzma_d.S
	modified:   stub/src/arch/arm64/v8/nrv2b_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2d_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2e_d32.S
2019-03-03 14:27:33 -08:00
John Reiser 517bc9db0b PR_SET_MM (previous commit had typo) is from 7 years ago: 2012
modified:   stub/src/include/linux.h
2019-03-03 14:26:20 -08:00
John Reiser 16bfa7b846 PT_SET_MM since 2012
modified:   stub/src/include/linux.h
2019-03-02 16:12:14 -08:00
John Reiser 570b2d0e88 arm64-linux.elf changed when PT_LOAD[1] no longer forces 4KB alignment
modified:   travis_testsuite_1-expected_sha256sums.sh
2019-03-02 16:10:37 -08:00
John Reiser 2653a0749a de-tabify
modified:   stub/src/arch/i386/bxx.S
2019-03-02 15:48:44 -08:00
John Reiser 3de0008543 i386-darwin.macho re-implementation, especially for MacOS <= 10.8.x (Mountain Lion)
[i386 will not be supported by new MacOS beginning fall 2019.]
https://github.com/upx/upx/issues/246
	modified:   p_mach.cpp
	modified:   stub/i386-darwin.macho-entry.h
	modified:   stub/i386-darwin.macho-fold.h
	modified:   stub/i386-darwin.macho-upxmain.exe
	modified:   stub/i386-darwin.macho-upxmain.h
	new file:   stub/src/arch/i386/bxx.S
	new file:   stub/src/arch/i386/nrv2b_d32-easy.S
	new file:   stub/src/arch/i386/nrv2d_d32-easy.S
	new file:   stub/src/arch/i386/nrv2e_d32-easy.S
	modified:   stub/src/i386-darwin.macho-entry.S
	modified:   stub/src/i386-darwin.macho-fold.S
	modified:   stub/src/i386-darwin.macho-main.c
	modified:   stub/src/i386-darwin.macho-upxmain.c
	modified:   stub/tmp/i386-darwin.macho-entry.bin.dump
	modified:   stub/tmp/i386-darwin.macho-fold.map
2019-03-02 15:39:30 -08:00
John Reiser d4e2d7e8a8 arm64 (aarch64) and PAGE_SIZE > 4KiB
Future: use prctl(PR_SET_MM, PR_SET_MM_START_BRK, addr)
https://github.com/upx/upx/issues/254
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-main.c
2019-03-01 20:31:41 -08:00
John Reiser a9c08c6f52 __MSYS2__ acts like UNIX but cannot handle --x permission
https://github.com/upx/upx/issues/256
	modified:   p_unix.cpp
2019-03-01 16:46:49 -08:00
Markus F.X.J. Oberhumer c2aa5c35f7 Silence a gcc-4.6 compiler warning. 2019-02-25 13:41:54 +01:00
John Reiser 423f1a8758 pack4() "__TEXT".nsects can differ from prototype to actual
modified:   p_mach.cpp
2019-02-18 14:41:43 -08:00
Markus F.X.J. Oberhumer cc5f684e33 Update testsuite checksums caused by version date bump. 2019-02-15 11:14:18 +01:00
Markus F.X.J. Oberhumer b6646d319a Bump tentative release date. 2019-02-15 11:12:07 +01:00
Markus F.X.J. Oberhumer 3667fa4e44 Welcome 2019. 2019-02-15 11:04:09 +01:00
John Reiser d1c80154f6 SHT_NOTE with ~SHF_ALLOC; as for 'gold' linker version
https://github.com/upx/upx/issues/243
	modified:   p_lx_elf.cpp
2019-02-12 21:13:24 -08:00
John Reiser 3c2bfc742e g++ -Wsign-compare is not as picky as MSVC warning C4018: '<': signed/unsigned mismatch
https://github.com/upx/upx/issues/247
	modified:   p_lx_elf.cpp
2019-02-09 08:04:58 -08:00
John Reiser d60fef753f check_pt_load(); u32_t, u64_t; (off_t) is not unsigned!
https://github.com/upx/upx/issues/247
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2019-02-01 19:31:57 -08:00
John Reiser 70ed2d0d03 Allow Load Configuration directory > 256, with info().
https://github.com/upx/upx/issues/245
	modified:   pefile.cpp
2019-01-26 07:51:16 -08:00
John Reiser 716d203a78 Testsuite checksums
amd64-linux.elf
commit 6b500bc83b
Date:   Wed Aug 22 14:39:14 2018 -0700

arm-linux.elf, armeb-linux.elf:
commit 75c31dff1d
Date:   Thu Dec 13 20:10:57 2018 -0800

	modified:   .github/travis_testsuite_1-expected_sha256sums.sh
2018-12-31 11:08:53 -08:00
John Reiser 9719a7dd56 MSVC pettiness
https://github.com/upx/upx/issues/238
	modified:   p_lx_elf.cpp
2018-12-26 18:38:30 -08:00
John Reiser c097233bf3 Stronger checks for DT_HASH, DT_GNU_HASH
https://github.com/upx/upx/issues/238
	modified:   p_lx_elf.cpp
2018-12-26 13:00:20 -08:00
John Reiser 69a583281f MemBuffer::subref() for 64-bit offsets; better diagnosis for bad .e_shoff
https://github.com/upx/upx/issues/235 (POC14)
	modified:   mem.cpp
	modified:   mem.h
	modified:   p_lx_elf.cpp
2018-12-16 16:00:15 -08:00
John Reiser 8e90c9af2b Corner cases for e_shnum vs e_shstrndx
modified:   p_lx_elf.cpp
2018-12-16 15:36:51 -08:00
John Reiser a784284b7f Check user_init_off. Also remove '\n' from error messages.
https://github.com/upx/upx/issues/235  POC11
	modified:   p_lx_elf.cpp
2018-12-16 12:14:22 -08:00
John Reiser 0509edf08d ElfXX_Sym.st_name is always 32 bits
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-12-16 11:32:58 -08:00
John Reiser 7ca20f424f Typos
modified:   p_lx_elf.cpp
2018-12-15 21:17:26 -08:00
John Reiser b74d51c2a8 More checking of e_shstrndx
https://github.com/upx/upx/issues/235  POC6
	modified:   p_lx_elf.cpp
2018-12-15 21:12:15 -08:00
John Reiser 58061cd121 Check .p_offset
https://github.com/upx/upx/issues/235  POC13
	modified:   p_lx_elf.cpp
2018-12-15 20:59:45 -08:00
John Reiser b8f6be5389 More checking of DT_HASH and DT_GNU_HASH
https://github.com/upx/upx/issues/235  POC12
	modified:   p_lx_elf.cpp
2018-12-15 20:43:33 -08:00
John Reiser 7c766b3313 Check e_shstrndx and Shdr.st_name
https://github.com/upx/upx/issues/235  POC10
	modified:   p_lx_elf.cpp
2018-12-15 20:27:20 -08:00
John Reiser 91b81b587b Abandon when outrageous Elf64_Dyn.d_tag
https://github.com/upx/upx/issues/235  POC8
	modified:   p_lx_elf.cpp
2018-12-15 19:35:13 -08:00
John Reiser 780a4347b8 Check DT_HASH and DT_GNU_HASH.
https://github.com/upx/upx/issues/235  POC2,POC4
Also cleanup checking of symbol number and .st_name
in POC1,POC3,POC5,POC7,POC9,POC11
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-12-15 19:16:14 -08:00
John Reiser 606ad08dd1 Check symbol number and .st_name
https://github.com/upx/upx/issues/235  POC1,POC3,POC7,POC9
	modified:   p_elf_enum.h
	modified:   p_lx_elf.h
	modified:   p_lx_elf.cpp
2018-12-14 21:32:49 -08:00
John Reiser 75c31dff1d Use THUMB 'ret' when in THUMB mode.
https://github.com/upx/upx/issues/236
https://github.com/upx/upx/issues/229
	modified:   src/arm.v4t-linux.shlib-init.S

	modified:   arm.v5t-linux.shlib-init.h
	modified:   tmp/arm.v5t-linux.shlib-init.bin.dump
2018-12-13 20:14:14 -08:00
John Reiser 473b90419f Mach-o for 'rust' has intermixed LC_SEGMENT64 "__DWARF" with 0==.vmsize
https://github.com/upx/upx/issues/222
	modified:   p_mach.cpp
	modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/amd64-darwin.macho-upxmain.c
	also *-darwin.macho-fold.{h,map}
2018-10-13 21:06:37 -07:00
John Reiser f88b85e126 MSVC error C4146: unary minus operator applied to unsigned type, result still unsigned
modified:   p_lx_elf.cpp
2018-10-09 20:27:19 -07:00
John Reiser b122f8e9d0 Optimize /proc/self/exe. Sync stubs.
See also commit 78b1da5c00 earlier today
for https://github.com/upx/upx/issues/225 .
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	also *.h, *.map, *.bin.dump
2018-10-09 20:11:34 -07:00
John Reiser cb8b1595a1 Pay more attention to 0==.e_shnum
modified:   p_lx_elf.cpp
2018-10-09 19:38:43 -07:00
John Reiser 1bee919276 cosmetic: developer quality-of-life
modified:   packer.cpp
2018-10-09 19:35:03 -07:00
John Reiser 78b1da5c00 Avoid dcache==>icache trouble with mflg_data; heuristic cache_flush for 32-bit ARM
modified:   arm.v4a-linux.elf-entry.S
	modified:   arm.v4a-linux.elf-fold.S
2018-10-09 19:24:50 -07:00
John Reiser bb8239ccda more DPRINTF
modified:   amd64-linux.elf-main.c
2018-10-09 19:23:06 -07:00
John Reiser 2a594ad0a7 Better return value when de-compression method mismatches.
modified:   arch/amd64/lzma_d.S
	modified:   arch/amd64/nrv2b_d.S
	modified:   arch/amd64/nrv2d_d.S
	modified:   arch/amd64/nrv2e_d.S
2018-10-07 10:15:48 -07:00
John Reiser b05073550c "pop %rcx", not %ecx
modified:   amd64-darwin.macho-entry.S
	modified:   amd64-linux.elf-entry.S
2018-10-07 10:11:45 -07:00
John Reiser 37d6a34e58 MSVC is a nimrod. (All verions 10.0 through 14.1)
"(4074): error C4146: unary minus operator applied to unsigned type, result still unsigned"
So what?  Many programmers are much better than the typical Microsoft coder.
The C standard GUARANTEES that unsigned arithmetic uses two's complement,
ignores overflow, and the result is what the hardware adder produces.
	modified:   p_lx_elf.cpp
2018-09-23 20:45:07 -07:00
John Reiser 4f0cba9bb6 /proc/self/exe mapping had wrong offset in stub for 32-bit ARM
https://github.com/upx/upx/issues/221
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	also arm*.*-linux.elf-*.{h,map}
2018-09-23 20:32:37 -07:00
John Reiser 4d1c754af9 Preserve Mach_segment_header.flags; fix non-PIE main programs on MacOS.
https://github.com/upx/upx/issues/222
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   stub/src/amd64-darwin.macho-entry.S
	also *.macho-*.h, *.macho-fold.map, amd64-darwin.macho-entry.bin.dump
2018-09-22 18:50:37 -07:00
John Reiser c1cfde21d7 Map when .vmsize (not .filesize). More debugging DPRINTF;
modified:   stub/src/amd64-darwin.macho-main.c
	also *.macho-fold.h, *.macho-fold.map
2018-09-22 13:06:45 -07:00
John Reiser bb1f9cdecd Propagate pagezero_vmsize; fix overlay_offset.
modified:   p_mach.cpp
2018-09-22 12:11:51 -07:00
John Reiser b259b0ca28 Print failed syscalls to stderr
modified:   stub/src/amd64-darwin.macho-fold.S
2018-09-22 12:09:22 -07:00
John Reiser 0051dfc84f --android-shlib: Relocate ABS _edata etc.
https://github.com/upx/upx/issues/220
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-09-16 15:10:40 -07:00
John Reiser 9f294e6ce5 Fix "upx -d" de-compression when input is compressed Android shlib.
https://github.com/upx/upx/issues/220
	modified:   p_lx_elf.cpp
2018-09-16 13:09:43 -07:00
John Reiser 153ea8be03 MSVC signed/unsigned
modified:   p_mach.cpp
2018-09-11 21:13:27 -07:00
John Reiser f3f7f97f8d MSVC signed/unsigned
modified:   p_mach.cpp
2018-09-09 15:58:24 -07:00
John Reiser 9bb6854e64 Fix stub for MacOS El Capitan, which has "pre-linked" /usr/bin/dyld
https://github.com/upx/upx/issues/218
https://github.com/Homebrew/homebrew-core/pull/31846
	modified:   src/amd64-darwin.macho-main.c
	    also *-darwin.mach-fold.{h,map}
2018-09-09 15:37:54 -07:00
John Reiser 4bba1e6cb7 Merge branch 'devel' of https://github.com/upx/upx into devel 2018-09-08 11:43:41 -07:00
John Reiser 597e8fe407 Fix de-compression for Mach-O files (MacOS)
https://github.com/upx/upx/issues/219
	modified:   p_mach.cpp
	modified:   p_mach.h
2018-09-08 11:41:38 -07:00
Markus F.X.J. Oberhumer 556c541ffb Sync with latest upx-testsuite changes. 2018-09-06 13:57:15 +02:00
John Reiser 5963f18f7c Merge branch 'devel' of https://github.com/upx/upx into devel 2018-09-04 20:54:21 -07:00
John Reiser 0dac6b7be3 MacOS de-compression (upx -d)
https://github.com/upx/upx/issues/218
	modified:   p_mach.cpp
2018-09-04 20:52:17 -07:00
Markus F.X.J. Oberhumer 296ede780b Update Travis. 2018-08-29 15:13:46 +02:00
Markus F.X.J. Oberhumer faaa19331a Update Travis. 2018-08-27 16:43:21 +02:00
Markus F.X.J. Oberhumer 88cb5886f3 Update Travis. 2018-08-26 06:42:46 +02:00
Markus F.X.J. Oberhumer 2fcc3f86c0 Introduce environment variable UPX_DISABLE_GITREV_WARNING. 2018-08-26 06:29:58 +02:00
Markus F.X.J. Oberhumer 9362fde9eb Update testsuite checksums caused by version bump. 2018-08-26 06:15:54 +02:00
Markus F.X.J. Oberhumer 56f4d781c1 Post-release version bump. 2018-08-26 06:08:40 +02:00
Markus F.X.J. Oberhumer 7a3637ff5a Update NEWS. 2018-08-26 04:58:09 +02:00
John Reiser 2923c0968e Merge branch 'devel' of https://github.com/upx/upx into devel
Fix Conflicts:
	.github/travis_testsuite_1.sh
2018-08-22 14:58:36 -07:00
John Reiser 98cfe99d65 sync testsuite
modified:   .github/travis_testsuite_1.sh
2018-08-22 14:52:00 -07:00
John Reiser bdd97fe0b2 build stubs
modified:   amd64-linux.elf-fold.h
	modified:   arm64-linux.elf-fold.h
	modified:   i386-bsd.elf-fold.h
	modified:   i386-linux.elf.interp-fold.h
	modified:   i386-netbsd.elf-fold.h
	modified:   i386-openbsd.elf-fold.h
	modified:   powerpc64-linux.elf-fold.h
	modified:   powerpc64le-linux.elf-fold.h
	modified:   tmp/amd64-linux.elf-fold.map
	modified:   tmp/arm64-linux.elf-fold.map
	modified:   tmp/i386-bsd.elf-fold.map
	modified:   tmp/i386-linux.elf.interp-fold.map
	modified:   tmp/i386-netbsd.elf-fold.map
	modified:   tmp/i386-openbsd.elf-fold.map
	modified:   tmp/powerpc64-linux.elf-fold.map
	modified:   tmp/powerpc64le-linux.elf-fold.map
2018-08-22 14:48:15 -07:00
John Reiser 6b500bc83b auxv_up() quit at AT_NULL, especially when AT_BASE has been omitted.
Based on contribution from Brian Geffon 'bgaff'
https://github.com/upx/upx/pull/215 ; bgaff
	modified:   amd64-linux.elf-main.c
	modified:   i386-bsd.elf-main.c
	modified:   i386-linux.elf.interp-main.c
	modified:   i386-openbsd.elf-main.c
2018-08-22 14:39:14 -07:00
Markus F.X.J. Oberhumer 92a12a2ec1 Update testsuite checksums caused by version date bump. 2018-08-22 13:16:39 +02:00
Markus F.X.J. Oberhumer 04d79040f9 Bump tentative release date. 2018-08-22 13:15:50 +02:00
Markus F.X.J. Oberhumer 3201ddc680 Update .editorconfig. 2018-08-22 13:06:39 +02:00
Markus F.X.J. Oberhumer 2f06de54c5 Cosmetic update. 2018-08-22 12:43:23 +02:00
John Reiser 6489ec9bba Fix PT_LOAD for ELF shared library.
modified:   p_lx_elf.cpp
2018-08-20 19:36:27 -07:00
John Reiser 1a5ba22fe7 Highlight changes for upx-3.95.
modified:   NEWS
2018-08-20 17:10:00 -07:00
John Reiser 8f9713ed53 Appease MSVC warning C4018: s/igned/unsigned mismatch
modified:   p_lx_elf.cpp
2018-08-13 18:47:42 -07:00
John Reiser 90eb68b3b9 Adapt to 4 PT_LOAD in binutils-2.31 and gcc-8.2.1 (Fedora 29)
0:        PF_R: .gnu.hash .dynsym .dynstr
1: PF_X | PF_R: .plt .plt.sec .text
2:        PF_R: .rodata .hash
3: PF_W | PF_R: .data.rel.ro .dynamic .got .got.plt .data .bss
	modified:   p_lx_elf.cpp

https://github.com/upx/upx/issues/212 (partial, Fedora 29)
2018-08-13 17:36:56 -07:00
John Reiser 95fcbcb4f2 ::PackLinuxElf64amd() sets lg2_page back to 12.
https://github.com/upx/upx/issues/212 (partial, Fedora 29)
	modified:   p_lx_elf.cpp
2018-08-10 20:28:40 -07:00
John Reiser b97688d119 Stub updates AT_PHDR for 32-bit libmusl, particularly -fPIE
https://github.com/upx/upx/issues/200
	modified:   stub/src/i386-linux.elf-main.c
	  also *.elf-fold.h, *.elf-fold.map for arm, armeb, i386, mips, mipsel, powerpc
	modified:   ../.github/travis_testsuite_1.sh
2018-08-04 18:26:02 -07:00
John Reiser 5ea3627cab --android-shlib, --force-pie
modified:   NEWS
2018-05-19 06:30:23 -07:00
John Reiser d9288213ec More checking of PT_DYNAMIC and its contents.
https://github.com/upx/upx/issues/206
	modified:   p_lx_elf.cpp
2018-05-17 21:48:26 -07:00
John Reiser 614c86fb7d --force-pie inhibits treating as shared library (for 'rust', etc.)
https://github.com/upx/upx/issues/200
	modified:   main.cpp
	modified:   options.h
	modified:   p_lx_elf.cpp
2018-04-26 13:44:17 -07:00
John Reiser 9f651ee40f Ignore ElfXX_Shdr if not CMD_COMPRESS; beware unpack when PT_DYNAMIC in other PT_LOAD
https://github.com/upx/upx/issues/200
	modified:   p_lx_elf.cpp
2018-04-26 08:34:58 -07:00
John Reiser 774c8c3fd4 Fix forgotten get_teXX() in canPack() and invert_pt_dynamic()
https://github.com/upx/upx/issues/200
	modified:   p_lx_elf.cpp
2018-04-25 23:05:17 -07:00
John Reiser b711d2f750 TLS callbacks: one entry only
https://github.com/upx/upx/issues/186  [partial, incomplete]
(Laszlo hints there is more, but meanwhile this does fix some.)
	modified:   pefile.cpp
2018-04-06 13:44:24 -07:00
John Reiser 8a793d5942 ELF shlib when no DT_INIT (especially --android-shlib)
https://github.com/upx/upx/issues/191
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-04-04 09:15:18 -07:00
John Reiser 99f52c60ed Merge branch 'Mattiwatti-offset-to-rva-fix' into devel
https://github.com/upx/upx/pull/193
2018-04-02 09:08:57 -07:00
Mattiwatti 2c2e108301 PE: fix comparison against a constant value
... due to size always being assigned to right before this comparison,
and instead check against the RVA and size of the export directory
from the header. (note: this is still stricter than the Windows loader
which ignores all of these except the directory RVA, but if the name RVA
is invalid the PE was probably tampered with).
Change 'offset' to 'RVA' in exception message; this field is always an RVA

  Author:    Mattiwatti <mattiwatti@gmail.com>
	modified:   pefile.cpp
2018-04-02 09:07:29 -07:00
John Reiser 563165e6ae Defensive patches from hints by Sean Williams <rootkit@google.com>
modified:   pefile.cpp
2018-03-29 16:55:21 -07:00
John Reiser f1a31b4793 ELf32::unpack; Elf64 parity with Elf32 for shlib with no DT_INIT
https://github.com/upx/upx/issues/191  [partial, not finished]
	modified:   p_lx_elf.cpp
2018-03-27 19:15:47 -07:00
John Reiser 5e9b6bd69d more ELF shlib when no DT_INIT (especially Android): hook DT_INIT_ARRAY[0]
https://github.com/upx/upx/issues/191  [partial, not finished]
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   stub/src/arm.v4a-linux.shlib-init.S
	modified:   stub/src/arm.v4t-linux.shlib-init.S
2018-03-26 16:30:52 -07:00
John Reiser 9b990c4eae clarity
modified:   p_lx_elf.cpp
2018-03-24 13:52:29 -07:00
John Reiser 7a625a449a ELF shlib without DT_INIT: steal a DT_NULL from PT_DYNAMIC
https://github.com/upx/upx/issues/191  [partial, not finished]
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-03-24 09:41:58 -07:00
John Reiser c2b62359d5 arm32 stubs on linux: allow 0==user_DT_INIT as nop; somewhat expensive
modified:   stub/arm.v5a-linux.shlib-init.h
	modified:   stub/arm.v5t-linux.shlib-init.h
	modified:   stub/src/arm.v4a-linux.shlib-init.S
	modified:   stub/src/arm.v4t-linux.shlib-init.S
	modified:   stub/tmp/arm.v5a-linux.shlib-init.bin.dump
	modified:   stub/tmp/arm.v5t-linux.shlib-init.bin.dump
2018-03-24 08:55:04 -07:00
John Reiser 6722e8972e cleanup dead variables: is_big, all_pages
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-03-23 08:06:31 -07:00
John Reiser fefe7a3452 Fix segTEXT.vmsize and data for entry to shlib.
https://github.com/upx/upx/issues/57
	modified:   p_mach.cpp
2018-03-19 14:59:20 -07:00
John Reiser 90a1322929 Also check for wrap-around when checking oversize involving e_shoff and e_shnum.
raised by https://github.com/upx/upx/pull/190
	modified:   p_lx_elf.cpp
2018-03-15 21:25:20 -07:00
John Reiser d698eb69e2 Fix decompression stub for arm64 --lzma
https://github.com/upx/upx/issues/181
	modified:   stub/src/arch/arm64/v8/lzma_d.S
2018-02-24 13:04:15 -08:00
John Reiser 0ef00e9b82 Fix --lzma (and so --ultra-brute) for 32-bit ARM
https://github.com/upx/upx/issues/167  (comment #14)
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   ../.github/travis_testsuite_1.sh
2018-02-03 15:44:00 -08:00
John Reiser 95cedb6640 upgrade ::unpack for --android-shlib
modified:   p_elf_enum.h
    	modified:   p_lx_elf.cpp
    	modified:   p_lx_elf.h
    	modified:   stub/src/arm64-linux.shlib-init.S
    	modified:   stub/src/arm.v4t-linux.shlib-init.S
2018-02-02 14:50:56 -08:00
John Reiser d736da4208 Elf32, not shared lib: leave alone the hole between .text and .data
In theory Linux might put pages there (and that would be a problem),
but postpone closing the gap until more experience.
	modified:   p_lx_elf.cpp
2018-01-28 13:30:10 -08:00
John Reiser be83788666 --android-shlib for 32-bit ARM
Includes better handling of asl_delta in execution stub.

    	modified:   p_lx_elf.cpp
    	modified:   p_lx_elf.h
    	modified:   stub/src/arm.v4t-linux.shlib-init.S
    	modified:   stub/src/arm64-linux.shlib-init.S
2018-01-27 22:00:16 -08:00
John Reiser 5a28a51abc android shlib: better handling of asl_delta in execution stub
modified:   p_lx_elf.cpp
    	modified:   stub/src/arm64-linux.shlib-init.S
2018-01-26 12:35:06 -08:00
John Reiser 8a84df752c Compiler nit: ptr->ENUM is not always considered a constant
modified:   p_lx_elf.cpp
2018-01-26 11:54:33 -08:00
John Reiser 85f53b210d de-compression of arm64 --android-shlib
modified:   src/p_lx_elf.cpp
	modified:   src/p_lx_elf.h
	modified:   src/stub/src/arm64-linux.shlib-init.S
2018-01-24 15:39:46 -08:00
John Reiser 5d13c6cd01 elfout is unset for shlib in PackLinuxElf64::updateLoader
modified:   p_lx_elf.cpp
2018-01-22 16:15:53 -08:00
John Reiser 98a0d381e9 Merge branch 'devel' into jreiser-android
modified:   p_lx_elf.cpp
2018-01-22 13:55:45 -08:00
John Reiser e1d20fd0b5 Fix wobble in PackLinuxElf64::pack2
modified:   p_lx_elf.cpp
2018-01-22 13:48:26 -08:00
John Reiser d1035ecd8f Fix PLT for --android-shlib
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-01-22 13:05:18 -08:00
John Reiser 0e651facdd Fix PLT for --android-shlib
NYI: unpack of PLT, DT_INIT etc.  Also e_entry.
	modified:   p_lx_elf.cpp
2018-01-22 13:01:20 -08:00
John Reiser 9fdddfc332 work in progress: de-compression of --android-shlib
OK except for asl_delta not removed from DT_INIT, DT_INIT_ARRAY,
DT_FINI_ARRAY, DT_PREINIT_ARRAY
	modified:   ../p_lx_elf.cpp
2018-01-21 18:59:21 -08:00
John Reiser 7d2913709c MemBuffer lowmem; for shlib, especially android
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-01-21 14:03:52 -08:00
John Reiser 3623199e8d Merge branch 'devel' into jreiser-android 2018-01-21 10:55:56 -08:00
John Reiser e4b23f7a47 Merge branch 'devel' of https://github.com/upx/upx into devel 2018-01-21 10:30:42 -08:00
John Reiser f056ecdcd5 pefile: Allow overlap of MZ header and PE header (h.nexepos==0x10)
https://github.com/upx/upx/issues/169
This means .codebase is aliased to .nexepos, with both equal to 0x10.
	modified:   pefile.cpp
2018-01-21 10:29:17 -08:00
John Reiser 857a03a074 fix sh_offset for new Shdr[e_shstrndx]
modified:   p_lx_elf.cpp
2018-01-20 16:41:32 -08:00
John Reiser a34deee4f5 work in progress for --android-shlib
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-01-20 16:34:52 -08:00
John Reiser fc9c8ae482 fix updating of DT_INIT
modified:   p_lx_elf.cpp
2018-01-20 09:48:28 -08:00
John Reiser 08c63f06eb p_lx_elf.h: phdro for --android-shlib
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-01-19 22:01:56 -08:00
John Reiser bbff510ef1 Merge branch 'devel' into jreiser-android
Conflicts:
	src/p_lx_elf.cpp
	src/p_lx_elf.h

	modified:   ../.github/travis_testsuite_1.sh
	modified:   p_exe.cpp
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   pefile.cpp
2018-01-19 21:51:49 -08:00
Markus F.X.J. Oberhumer f747435952 For consistency, add missing "virtual". 2018-01-19 20:21:18 +01:00
Markus F.X.J. Oberhumer e6edad8f46 Clean up OptVar handling. 2018-01-19 19:50:28 +01:00
Markus F.X.J. Oberhumer 05e44b9644 Fix powerpc64 cross build. 2018-01-19 15:05:43 +01:00
Markus F.X.J. Oberhumer 16bb7ab841 clang-format files. 2018-01-19 14:18:47 +01:00
Markus F.X.J. Oberhumer 9248f02557 Silence some gcc-8-snapshot compiler warnings. 2018-01-19 14:13:58 +01:00
Markus F.X.J. Oberhumer 9485a56af1 Update Travis. 2018-01-19 11:30:34 +01:00
Markus F.X.J. Oberhumer 021c8db58a Welcome 2018. 2018-01-19 10:55:32 +01:00
John Reiser 8ab180edf8 MS-DOS .exe (not PE): default to file_size when ih.m512 and ih.p512 are zero
https://github.com/upx/upx/issues/169
	modified:   p_exe.cpp
2018-01-18 12:00:38 -08:00
John Reiser ab35b685d4 Fix pefile.cpp bad range checking for reloc type 3 and 10
modified:   pefile.cpp
2018-01-18 11:11:19 -08:00
John Reiser 86745721ee MSVC strikes again
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-01-15 16:27:00 -08:00
John Reiser c34fe09a79 Revamp --android-shlib
Android "Oreo" wants to deal with ElfXX_Shdr[].  So splice 4KiB into PT_LOAD[0]
with an "extra" copy of them.  This requires careful relocation processing.
It also costs a page at run time, and an average of a page in the file
(depending on fragmentation at the boundary between r-x and rw- .)

https://github.com/upx/upx/issues/124
https://github.com/upx/upx/issues/139
https://github.com/upx/upx/issues/142

	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   stub/src/arm.v4a-linux.shlib-init.S
	modified:   stub/src/arm.v4t-linux.shlib-init.S
	modified:   stub/src/arm64-linux.shlib-init.S

	modified:   stub/arm.v5a-linux.shlib-init.h
	modified:   stub/arm.v5t-linux.shlib-init.h
	modified:   stub/arm64-linux.shlib-init.h

	modified:   ../.github/travis_testsuite_1.sh
2018-01-15 16:08:34 -08:00
John Reiser 1fa9ff2c05 --android-shlib handles implicit relocation in PLT
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2018-01-15 15:45:37 -08:00
John Reiser e8ef0cf63f Merge branch 'devel' into jreiser-android 2018-01-13 09:25:55 -08:00
John Reiser 8c84efb8fb --android-shlib for Android "Oreo"
Android "Oreo" wants to deal with ElfXX_Shdr[].  So splice 4KiB into PT_LOAD[0]
with an "extra" copy of them.  This requires careful relocation processing.
It also costs a page at run time.
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   stub/src/arm.v4a-linux.shlib-init.S
	modified:   stub/src/arm.v4t-linux.shlib-init.S
	modified:   stub/src/arm64-linux.shlib-init.S
2018-01-13 09:20:04 -08:00
John Reiser f3a7620ae8 ARM: recognize R_ARM_CALL and R_ARM_JUMP24 as equivalent to R_ARM_PC24
modified:   linker.cpp
2018-01-12 08:42:34 -08:00
John Reiser c7969ed5a5 work in progress for --android-shlib
modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   stub/src/arm.v4a-linux.shlib-init.S
	modified:   stub/src/arm.v4t-linux.shlib-init.S
2018-01-12 08:32:24 -08:00
Markus F.X.J. Oberhumer 900926c0ed Avoid a MSVC warning. 2018-01-12 10:19:14 +01:00
John Reiser df94f4288a picky, picky
modified:   p_lx_elf.cpp
2018-01-11 12:09:43 -08:00
John Reiser 969efe687d MSVC pecadillos
modified:   p_lx_elf.cpp
	modified:   pefile.cpp
2018-01-11 12:01:00 -08:00
John Reiser ee3f1292d0 fix editing rot for mach-o .dylib
https://github.com/upx/upx/issues/57
	modified:   p_mach.cpp
2018-01-11 11:33:15 -08:00
John Reiser cacb239040 work in progress for --android-shlib
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   stub/src/arm64-linux.shlib-init.S
2018-01-11 09:39:26 -08:00
John Reiser 28d1789783 work in progress for --android-shlib
modified:   p_lx_elf.cpp
2018-01-08 14:04:38 -08:00
John Reiser 633eb98e34 Merge branch 'devel' into jreiser-android 2018-01-06 09:53:43 -08:00
John Reiser 4854c03096 uint64_t ==> upx_uint64_t
MSVC error C2065: 'uint64_t' : undeclared identifier
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_mach.cpp
2018-01-06 09:33:04 -08:00
John Reiser e853119c77 canonicalize bool in OR
MSVC error C4805: '|' : unsafe mix of type 'bool' and type 'unsigned int' in operation
	modified:   p_lx_elf.cpp
2018-01-06 09:20:46 -08:00
John Reiser 161a58bafb work in progress for --android-shlib
modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2018-01-06 09:18:17 -08:00
John Reiser f5fd94e815 Android shlib: work in progress
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-12-31 22:40:57 -08:00
John Reiser edde6210f1 amd64 linux stack align
forgotten as part of 4a35bf32ea
	modified:   stub/src/amd64-linux.elf-fold.S

	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   ../.github/travis_testsuite_1.sh
2017-12-31 10:36:14 -08:00
John Reiser 507e19945e more checking of PT_DYNAMIC
https://github.com/upx/upx/issues/166
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-12-30 22:31:50 -08:00
John Reiser 4a35bf32ea static uClibc on amd64 passes entry.%rdx to 'atexit'
https://github.com/upx/upx/issues/166
	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/amd64-linux.elf-main.c
2017-12-30 17:20:01 -08:00
John Reiser e04bf9e4bc more checking of PT_DYNAMIC
https://github.com/upx/upx/issues/164
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-12-28 17:40:04 -08:00
John Reiser c384d224c0 Mach-o stubs turn off DEBUG
Branch jreiser-macho has DEBUG 1
	modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm.v5a-darwin.macho-fold.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
2017-12-27 10:23:19 -08:00
John Reiser 35427f998e Mach-o stubs turn off SIMULATE_ON_LINUX_EABI4
modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm.v5a-darwin.macho-fold.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
2017-12-27 09:12:38 -08:00
John Reiser 1174da2bc3 arm64 stubs use NBPW in TRACE etc
modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.shlib-init.S
2017-12-26 16:39:51 -08:00
John Reiser 11e8a47030 DEBUG and TRACE for arm*-darwin.macho-* stubs
modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm.v5a-darwin.macho-fold.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
2017-12-26 15:44:54 -08:00
John Reiser 8c4e9bcf0d typo
modified:   stub/src/arm.v4a-linux.elf-entry.S
2017-12-26 15:43:58 -08:00
John Reiser 9dfd624901 fix TRACE macro
modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
2017-12-26 15:43:01 -08:00
John Reiser 79e65503a9 Merge branch 'devel' into jreiser-macho 2017-12-26 10:41:26 -08:00
John Reiser 59f18b9d9f stash work-in-progress
modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm.v5a-darwin.macho-fold.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
2017-12-22 23:07:03 -08:00
John Reiser fb3699fb89 stash work-in-progress
modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/amd64-darwin.macho-upxmain.c
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm.v5a-darwin.macho-fold.S
	modified:   stub/src/arm.v5a-darwin.macho-main.c
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
	modified:   stub/src/i386-darwin.macho-upxmain.c
2017-12-22 10:20:32 -08:00
John Reiser 9d2d59b5d2 stash work-in-progress
modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm64-darwin.macho-fold.S
2017-12-19 21:19:53 -08:00
John Reiser aefb2fa3c3 bad logic for throwCantUnpack("cmdsize") [simple]
https://github.com/upx/upx/issues/161
	modified:   p_mach.cpp
2017-12-19 17:36:22 -08:00
John Reiser e8aa80f904 stash work-in-progress
modified:   linker.cpp
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   packmast.cpp
	modified:   stub/Makefile
	modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
	modified:   stub/src/arm64-darwin.macho-main.c
2017-12-19 17:32:15 -08:00
John Reiser 990988f920 More checking of input Phdr and Shdr
https://github.com/upx/upx/issues/157
	modified:   p_lx_elf.cpp
2017-12-18 10:36:43 -08:00
John Reiser 576d9a4e7e stash work-in-progress
modified:   stub/src/amd64-darwin.macho-entry.S
	modified:   stub/src/arm.v5a-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-entry.S
2017-12-17 15:02:57 -08:00
John Reiser 1d462ee424 MIPS shlib --lzma stub coding error: wrong register
https://github.com/upx/upx/issues/139 (part2)
	modified:   stub/src/mipsel.r3000-linux.shlib-init.S
2017-12-14 11:17:01 -08:00
John Reiser c9b09555c4 MH_PIE ASLR (Address-Space Layout Randomization)
modified:   stub/src/amd64-darwin.macho-main.c
2017-12-13 11:15:10 -08:00
John Reiser 860b5bf967 MH_EXECUTE diagnose syscall failure
modified:   stub/src/amd64-darwin.macho-fold.S
2017-12-13 10:53:22 -08:00
John Reiser 5063480a38 MH_EXECUTE runs under lldb, fails under shell
mmap  addr=0x100000000  len=0x3003  prot=0x3  flags=0x1012  fd=-1  off=0x0  reloc=0x0
maddr=0xffffffffffffffff  addr=0x100000000
	modified:   p_mach.cpp
	modified:   p_mach_enum.h
	modified:   stub/src/amd64-darwin.macho-entry.S
	modified:   stub/src/amd64-darwin.macho-fold.S
	modified:   stub/src/amd64-darwin.macho-main.c
2017-12-13 09:54:44 -08:00
John Reiser 3400ae9dbe MH_EXECUTE leave space for thread state command
modified:   p_mach.cpp
2017-12-12 10:53:19 -08:00
John Reiser 3385264eb2 new DPRINTF
modified:   stub/src/amd64-darwin.macho-main.c
2017-12-12 10:52:47 -08:00
John Reiser 34646f1c6a fix braces in comment after #elif
modified:   stub/src/amd64-linux.elf-main.c
2017-12-12 10:51:38 -08:00
John Reiser 50aa63a5a0 declare write()
modified:   stub/src/include/darwin.h
2017-12-12 10:50:50 -08:00
John Reiser 64557bee43 Mach-o MH_EXECUTE rewrite; work-in-progress
The stub for amd64 gets to upx_main()
	modified:   stub/src/amd64-darwin.macho-entry.S
	modified:   stub/src/amd64-darwin.macho-fold.S
	plus .h .bin.dump .map
2017-12-09 20:18:39 -08:00
John Reiser 7c21c4513e Android 64-bit ARM shared library stub: use 4Ki page size until more is known
https://github.com/upx/upx/issues/124
	modified:   p_lx_elf.cpp
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/src/arm64-linux.shlib-init.S
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-12-08 20:05:21 -08:00
John Reiser c6d6378005 Mach-o MH_EXECUTE rewrite; work-in-progress
The stub for amd64 gets into the de-compressed folded code.
	modified:   p_mach.cpp
	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/src/amd64-darwin.macho-entry.S
	modified:   stub/src/amd64-darwin.macho-upxmain.c
	modified:   stub/tmp/amd64-darwin.macho-entry.bin.dump
2017-12-06 17:04:47 -08:00
John Reiser 4f6979967d Mach-o MH_EXECUTE rewrite; work-in-progress
On amd64, otool and lldb accept the results.
The entry point points to the unfilter and uncompress routines.
Somehow _start has been lost.

	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   p_mach_enum.h
	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/src/amd64-darwin.macho-entry.S
	modified:   stub/src/amd64-darwin.macho-upxmain.c
	modified:   stub/src/i386-darwin.macho-upxmain.c
	modified:   stub/src/powerpc-darwin.macho-upxmain.c
	modified:   stub/tmp/amd64-darwin.macho-entry.bin.dump
2017-12-03 23:17:55 -08:00
John Reiser e633c51b50 off_t_upx_stub typedef enables easier use of native #include
... but requires  #define __WORDSIZE
	modified:   p_mach.h
	modified:   stub/amd64-darwin.macho-fold.h
	modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm.v5a-darwin.macho-main.c
	modified:   stub/src/arm64-darwin.macho-main.c
	modified:   stub/src/i386-darwin.macho-main.c
	modified:   stub/src/include/darwin.h
	modified:   stub/src/powerpc-darwin.macho-main.c
	modified:   stub/src/powerpc64le-darwin.macho-main.c
	modified:   stub/tmp/amd64-darwin.macho-fold.map
2017-11-28 14:49:46 -08:00
John Reiser 143f0accef PeFile check MZ offset to PE header
modified:   pefile.cpp
2017-11-21 13:07:42 -08:00
John Reiser b413f3da26 ELF shared library: PT_NOTE can prevent packing
Android build environment post-processing is adding a PT_NOTE
("Android", 21, "r16-beta1") at the high end of PT_LOAD[0],
above the stub; the runtime linker looks there before de-compression.
https://github.com/upx/upx/issues/124
	modified:   p_lx_elf.cpp
2017-11-20 10:08:24 -08:00
John Reiser 6eafa552bb Mach-o defend against bad crafted input
https://github.com/upx/upx/issues/146
	modified:   p_mach.cpp
2017-11-15 13:38:54 -08:00
John Reiser 7a0514d9b4 PeFile more checks for Section table
modified:   pefile.cpp
2017-11-12 21:47:47 -08:00
John Reiser 7e7565299e PeFile check Section table
https://github.com/upx/upx/issues/132
	modified:   pefile.cpp
2017-11-12 21:02:52 -08:00
László Molnár ed34a089c6 minor update for a memory derefencing check 2017-11-12 16:19:40 +01:00
John Reiser d14a2c5282 PeFile fix the recently-added interval checking.
https://github.com/upx/upx/issues/143
	modified:   pefile.cpp
2017-11-09 21:58:25 -08:00
John Reiser f014406b65 MemBuffer.subref(errfmt, skip, take) checks that a subinterval is inside
modified:   mem.cpp
	modified:   mem.h
2017-11-09 21:55:41 -08:00
John Reiser 58771ecca6 PeFile: better checking for import descriptors
modified:   pefile.cpp
2017-11-08 12:38:54 -08:00
John Reiser 5d9dcb634b PeFile: Defend against bad crafted import descriptors
https://github.com/upx/upx/issues/143
	modified:   pefile.cpp
	modified:   pefile.h
2017-11-08 11:07:46 -08:00
John Reiser 19c2c1edcf Android 8.0 (Oreo) wants 0!=.e_shstrndx in a shared library
https://github.com/upx/upx/issues/142
It should not matter what the .sh_name is; only the .sh_type matters.
	modified:   p_lx_elf.cpp
2017-11-07 11:12:23 -08:00
John Reiser 0430e7931e PowerPC64 stub: on syscall, real Linux trashes r13 and below
(except r1, r2, and input args!) So, r12 .e_entry for musl
must copy from a saved register.  [qemu-ppc64 doesn't trash registers!]
	modified:   ../.github/travis_testsuite_1.sh
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	also .h  .fold.map
2017-10-27 20:07:32 -07:00
John Reiser bb8e607442 PowerPC64 musl 1.1.16 wants r12= .e_entry
modified:   stub/src/powerpc64le-linux.elf-fold.S
	also .h  .fold.map
2017-10-27 13:19:03 -07:00
John Reiser e61ada944d debug info for shared library on stderr under "-D"
modified:   p_lx_elf.cpp
2017-10-25 21:32:17 -07:00
John Reiser 46730315e3 stub arm64-linux.shlib-init.S saves 1 instr and checks for assembly errors
modified:   arm64-linux.shlib-init.S
	also .h .bin.dump
2017-10-24 12:50:29 -07:00
John Reiser 4869142034 arm64 stub for shared library uses AT_PAGESZ
modified:   stub/src/arm64-linux.shlib-init.S
	also .h .bin.dump
2017-10-23 18:55:28 -07:00
John Reiser 8e42e17bbf typo
modified:   stub/src/amd64-linux.elf-entry.S
2017-10-23 18:53:42 -07:00
John Reiser 38c8b84a26 Align hatch_off.
modified:   p_lx_elf.cpp
2017-10-20 17:23:55 -07:00
John Reiser c652626a37 32-bit shared libs reduce Phdr[1].p_align to 4096, like 64-bit.
This saves space when PAGE_SIZE is larger than 4096: MIPS, etc.
	modified:   p_lx_elf.cpp
2017-10-20 16:35:27 -07:00
John Reiser 06f6e47ebf Fix stub for MIPS shared libraries
https://github.com/upx/upx/issues/135
	modified:   p_lx_elf.cpp
	modified:   stub/src/mipsel.r3000-linux.shlib-init.S
	also .h .bin.dump
2017-10-20 16:16:35 -07:00
John Reiser 403b180b1d Compress shared libraries for mips and mipsel in ELF on Linux
modified:   p_lx_elf.cpp
	modified:   stub/Makefile
	new file:   stub/mips.r3000-linux.shlib-init.h
	new file:   stub/mipsel.r3000-linux.shlib-init.h
	new file:   stub/src/mips.r3000-linux.shlib-init.S
	new file:   stub/src/mipsel.r3000-linux.shlib-init.S
	new file:   stub/tmp/mips.r3000-linux.shlib-init.bin.dump
	new file:   stub/tmp/mipsel.r3000-linux.shlib-init.bin.dump
2017-10-19 13:47:36 -07:00
John Reiser ee008acfbd amd64 implements --is_ptinterp
https://github.com/upx/upx/issues/121
	modified:   ../.github/travis_testsuite_1.sh
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/amd64-linux.elf-main.c
	also .h, .map, .bin.dump
2017-10-18 13:10:49 -07:00
John Reiser d149092ac0 Reference to external documentation only.
modified:   stub/src/arch/mips/r3000/macros.ash
2017-10-17 14:11:06 -07:00
John Reiser eafa136c69 Appease error C4146 unary minus operator applied to unsigned type, result still unsigned
Microsoft Optimizing Compiler 16.00.40219.01, 19.00.24215.1, 19.11.25507.1; others
	modified:   p_lx_elf.cpp
2017-10-17 08:44:08 -07:00
John Reiser 402c885987 Merge branch 'jreiser-elfstub' into devel
New stub strategy on Linux:  Linux adds too many other segments
to the address space: [vdso], [sigpage], ...; and qemu might
arrange them differently.  Thus the only reliable mappings
are the PT_LOAD of the compressed file itself; all other
address space is unknown!  First, the compressed file uses
.bss to occupy all unused pages up to the original brk(0).
Then at run time, the stub gets another mapping of /proc/self/exe,
and uncompresses the user program on top of the original pages.
[*BSD unchanged for now?]

	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   stub/src/mipsel.r3000-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-main.c
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   p_unix.cpp
	modified:   p_mach.cpp
	modified:   p_lx_sh.cpp
	modified:   p_lx_interp.cpp
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_lx_interp.h
	modified:   p_lx_sh.h
	modified:   p_mach.h
	modified:   p_unix.h
	modified:   stub/src/arch/mips/r3000/macros.ash
	modified:   stub/src/arch/powerpc/32/ppc_regs.h
	modified:   stub/src/arch/powerpc/64le/ppc_regs.h
	modified:   stub/src/include/linux.h
	modified:   stub/Makefile
	modified:   ../.github/travis_testsuite_1.sh
	also .h .map .bin.dump
2017-10-14 14:26:11 -07:00
John Reiser 5e7e0508b9 sync stubs for "make run-testsuite"
modified:   ../.github/travis_testsuite_1.sh
2017-10-14 14:19:24 -07:00
John Reiser ff1d5fb794 stub for 64-bit little-endian PowerPC also uses TOC
modified:   stub/src/arch/powerpc/64le/ppc_regs.h
	modified:   stub/src/powerpc64le-linux.elf-fold.S
2017-10-14 13:54:43 -07:00
John Reiser ad3f63b5c4 stubs *.elf-main.c: tighten input to first decompress of ELF headers
modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-main.c
	also .h, .map
2017-10-14 06:21:44 -07:00
John Reiser a3e51e6dee stub for PowerPC 64-bit big endian: accommodate musl bare .func as .e_entry
modified:   stub/src/powerpc64le-linux.elf-fold.S
2017-10-14 06:18:00 -07:00
John Reiser c1b9c79f54 arm,armeb stubs need endian-neutral code to set mflg_subr
modified:   stub/src/arm.v4a-linux.elf-entry.S
	also .h, .bin.dump
2017-10-13 12:27:07 -07:00
John Reiser e0bc040b0a mips stub uses new strategy
modified:   p_lx_elf.cpp
	modified:   stub/src/arch/mips/r3000/macros.ash
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/mipsel.r3000-linux.elf-entry.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	also .h, .bin.dump, .map
2017-10-12 21:04:10 -07:00
John Reiser 85eb4c7537 powerpc stub: used wrong register
modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/arch/powerpc/32/ppc_regs.h
2017-10-11 17:17:45 -07:00
John Reiser 1f929d47d0 x86_64 stub also needs make_hatch()
https://github.com/upx/upx/issues/133
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   ../.github/travis_testsuite_1.sh
	also .h and .map
2017-10-11 09:06:50 -07:00
John Reiser 608662d73b x86_64 stub also needs make_hatch()
https://github.com/upx/upx/issues/133
	modified:   stub/src/amd64-linux.elf-main.c
2017-10-11 08:45:21 -07:00
John Reiser 7841d23e77 arm64: folded stub uses 64-bit TRACEing under DEBUG
modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
2017-10-10 21:39:50 -07:00
John Reiser b72dda4ada arm64 spills a few registers because syscall can trash x18
modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
2017-10-10 20:31:11 -07:00
John Reiser c59c8a1ea2 readability; no functional change
modified:   stub/src/powerpc64le-linux.elf-entry.S
2017-10-10 20:30:41 -07:00
John Reiser 1522293be0 arm64: stub uses new strategy
modified:   p_lx_elf.cpp
	modified:   stub/src/powerpc64le-linux.elf-entry.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:   stub/src/arm64-linux.elf-main.c
	also .h, .map, .bin.dump
2017-10-10 14:51:03 -07:00
John Reiser b37bc99330 PowerPC64: stub uses new strategy
Needed: expert on TOC for big-endian.  glibc, musl, gcc disagree
on layout (is the .func first?) and usage for .e_entry.
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/arch/powerpc/64le/ppc_regs.h
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/Makefile
	also .h, .bin.dump, .map
2017-10-07 13:43:12 -07:00
John Reiser 7f905724b1 amd64: stub uses new strategy
modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   p_lx_elf.cpp
	also .h, .bin.dump, .map
2017-10-06 11:15:34 -07:00
John Reiser 2bf5bb1625 arm: stub uses new strategy
modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   p_lx_elf.cpp
	plus .h, .bin.dump, .map
2017-10-05 17:07:30 -07:00
John Reiser 08d3376740 Elf i386 stub: get enough space when unfolded code requires another page
modified:   src/i386-linux.elf-entry.S
2017-10-03 11:48:27 -07:00
John Reiser 7bace76176 Protect against bad crafted input.
https://github.com/upx/upx/issues/129
	modified:   p_lx_elf.cpp
2017-10-03 09:55:34 -07:00
John Reiser ef336dbcc6 Protect against bad crafted input.
https://github.com/upx/upx/issues/128
	modified:   p_lx_elf.cpp
2017-10-02 21:47:40 -07:00
John Reiser ca7217e717 powerpc: stub uses new strategy
First mmap must reserve enough space to decompress folded stub.
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	also .h, .map, .dump
2017-10-02 20:03:47 -07:00
John Reiser 3931cb7871 off_t is signed and long; keep the long when discarding the signed.
https://github.com/upx/upx/issues/127
	modified:   p_vmlinx.cpp
2017-10-01 16:14:09 -07:00
John Reiser 9e8de4abe5 i386: new stub strategy to avoid problems with early mmap layout
The stub occupies the same region that execve() would create
for the original progam.  The stub copies everything to a new area,
erases the original region, replaces it with the de-compressed
program, and erases the copy of itself via the escape hatch.
The copy is inexpensive via mmap() of /proc/self/exe.

	modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-main.c

	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_lx_interp.cpp
	modified:   p_lx_interp.h
	modified:   p_lx_sh.cpp
	modified:   p_lx_sh.h
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   p_unix.cpp
	modified:   p_unix.h
	modified:   p_vmlinx.cpp

	plus .h, .map, .dump
2017-10-01 15:56:34 -07:00
John Reiser 26be845563 mips stubs: implement ET_DYN (-pie).
modified:   stub/src/mipsel.r3000-linux.elf-entry.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	plus associated *.h, *.bin.dump, and ../.github/travis_testsuite_1.sh
2017-09-26 10:05:22 -07:00
John Reiser 2f11a629fa Fix flub: "git --amend" after "git push" is not a good idea.
https://github.com/upx/upx/issues/126# Please enter the commit message for your changes. Lines starting
	modified:   arm64-linux.shlib-init.S
2017-09-25 11:43:38 -07:00
John Reiser a295437e11 Merge branch 'devel' of https://github.com/upx/upx into devel 2017-09-25 11:39:13 -07:00
John Reiser 04597fb804 Fix bug in unfilter for shlib on arm64.
https://github.com/upx/upx/issues/126
	modified:   stub/src/arm64-linux.shlib-init.S
	and associated *.h, *.bin.dump
2017-09-25 11:38:33 -07:00
John Reiser f2f002409b Fix bug in unfilter for shlib on arm64.
https://github.com/upx/upx/issues/126
	modified:   stub/src/arm64-linux.shlib-init.S
	and associated *.h, *.bin.dump
2017-09-25 11:31:44 -07:00
John Reiser 509de877ca Cleanup powerpc64 aux stub files.
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
2017-09-24 20:30:07 -07:00
John Reiser 63aea4a7dc 64-bit Power PC linux uses 64KiB page size, but qemu-ppc64{,le} uses 4KiB.
modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/include/linux.h
	modified:   stub/src/powerpc64le-linux.elf-fold.S
2017-09-24 20:24:46 -07:00
John Reiser 6470c748db Flush ACC_UNUSED(adrc); and its predecessors from stub for MIPS.
modified:   p_lx_elf.cpp
2017-09-24 20:07:31 -07:00
John Reiser 25a6429e6a Merge branch 'devel' of https://github.com/upx/upx into devel 2017-09-23 10:43:14 -07:00
John Reiser 4fa1c2a97e Avoid the stack in stub for PowerPC, especially under qemu-ppc.
modified:   stub/src/powerpc-linux.elf-entry.S

	also travis_testsuite_1.sh, -entry.h, -entry.bin.dump
2017-09-23 10:41:40 -07:00
Markus F.X.J. Oberhumer 9ad39d77cc Update Travis. 2017-09-21 10:15:01 +02:00
John Reiser 92527126a8 Adapt around qemu-arm placement of ET_DYN and stack.
modified:   stub/src/arm.v4a-linux.elf-entry.S

	modified:   ../.github/travis_testsuite_1.sh
	plus arm*.elf-entry.h, arm*.elf-entry.bin.dump
2017-09-20 15:23:12 -07:00
John Reiser 02b4a4c974 Sync testsuite checksums.
modified:   ../.github/travis_testsuite_1.sh
2017-09-20 13:37:38 -07:00
John Reiser ede570be21 Spend 8 instructions to avoid modifying [0xf7000000, +) under qemu-arm.
modified:   src/arm.v4a-linux.elf-entry.S
	modified:   src/arm.v4a-linux.elf-fold.S

	plus arm*.h and tmp/arm*.{dump,map}
2017-09-20 13:31:38 -07:00
John Reiser 08627e9df5 Fix some AT_PHDR problems, at least on x86*.
modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-main.c

	modified:   ../.github/travis_testsuite_1.sh
	plus many *.elf-fold.h and *.elf-fold.map
2017-09-18 19:54:27 -07:00
John Reiser 6d9f3adc86 Escape hatch for Thumb-mode shared library must reside at even address.
https://github.com/upx/upx/issues/122
	modified:   stub/src/arm.v4t-linux.shlib-init.S

	modified:   stub/arm.v5t-linux.shlib-init.h
	modified:   stub/tmp/arm.v5t-linux.shlib-init.bin.dump
2017-09-13 22:38:24 -07:00
John Reiser 96433b4e39 FILTER_ID was wrong for arm64-linux.shlib and arm64-darwin.macho.
https://github.com/upx/upx/issues/100  (partial)
	modified:   stub/src/arm64-darwin.macho-fold.S
	modified:   stub/src/arm64-linux.shlib-init.S
	modified:   p_mach.cpp

	modified:   stub/arm64-darwin.macho-fold.h
	modified:   stub/arm64-linux.shlib-init.h
2017-08-25 12:51:33 -07:00
John Reiser f4947cc2ae Work-around Ubuntu runtime bug loading shlib on ARM.
Use --android-shlib to activate the work-around.
https://bugs.launchpad.net/bugs/1712938
https://github.com/upx/upx/issues/116
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2017-08-24 19:52:30 -07:00
John Reiser 7b554d4f72 ucl-1.03 needs help for recent gcc and for native on aarch64.
modified:   README.SRC
2017-08-23 05:47:16 -07:00
John Reiser 5b54544438 Fix powerpc64 (BIG_ENDIAN and comments)
modified:   stub/src/arch/powerpc/64/lzma_d.S
	modified:   stub/src/arch/powerpc/64le/lzma_d-common.S
	modified:   stub/src/powerpc64-linux.elf-main.c
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-main.c
	modified:   stub/src/powerpc64le-linux.kernel.vmlinux.S

	plus stub/powerpc64*entry.h and .dump
2017-07-26 11:16:02 -07:00
Markus F.X.J. Oberhumer ef78d23494 Update Travis and check_whitespace.sh. 2017-07-23 02:59:51 +02:00
Markus F.X.J. Oberhumer ef8a7f330d Silence some compiler warnings. 2017-07-23 02:59:51 +02:00
Markus F.X.J. Oberhumer b72e0f3060 Disable debugging section. 2017-07-23 02:59:51 +02:00
Markus F.X.J. Oberhumer 2a0bab938b Rebuild stubs. 2017-07-23 02:20:05 +02:00
Markus F.X.J. Oberhumer cd637629c4 Update stub/src/arch/powerpc Makefiles. 2017-07-23 02:18:39 +02:00
John Reiser b9adfd801d Compile powerpc64 using powerpc64-linux-gcc-4.9.2 from stubtools
modified:   src/arch/powerpc/64/Makefile.extra
2017-07-22 16:14:12 -07:00
Markus F.X.J. Oberhumer 69355514c9 Fix some misspellings. 2017-07-22 12:54:37 +02:00
Markus F.X.J. Oberhumer 33dc947c21 clang-format files. 2017-07-22 12:47:45 +02:00
John Reiser 6de021d8d8 Fix MIPS, at least ET_EXEC.
ET_DYN not tested.  Also /proc/self/exe is not proected [use getenv("   ")]
	modified:   p_lx_elf.cpp
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   ../.github/travis_testsuite_1.sh

	also .h .dump .map for mips
2017-06-27 20:53:44 -07:00
John Reiser 9be86621bf PowerPC64 unifies into amd64-linux.elf-main.c
Also reconcile ppc32 and ppc64, especially *.S
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-main.c
	modified:   ../.github/travis_testsuite_1.sh

	also corresponding *.h *.map *.dump
2017-06-27 14:58:13 -07:00
John Reiser a7a0876298 /proc/self/exe in powerpc64*.S stub; unify with powerpc*.S.
modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   .github/travis_testsuite_1.sh

	also corresponding *.h *.dump *.map files
2017-06-26 21:40:12 -07:00
John Reiser 31b42345c3 Fix nesting brace in comment on #endif.
modified:   i386-linux.elf-main.c
2017-06-26 21:31:36 -07:00
John Reiser 1b172e729e Fix stub for powerpc64, powerpc64le
modified:   src/powerpc64le-linux.elf-fold.S
2017-06-25 16:03:43 -07:00
John Reiser 3bf387a2d4 PowerPC stub unified with i386; including escape hatch [munmap all extras]
modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-main.c
	modified:   ../.github/travis_testsuite_1.sh

	{arm.*,i386,mips*.r3000,powerpc}-linux.elf-fold.{h,map}
	powerpc-*-entry.*
2017-06-24 18:37:16 -07:00
John Reiser 9f20bbb046 Fix merge 2017-06-19 16:01:35 -07:00
John Reiser 82af555974 Merge branch 'i386-VDSO' into devel 2017-06-19 15:58:22 -07:00
John Reiser 50638b5213 i386 VDSO may conflict on low side of -pie ET_DYN
https://github.com/upx/upx/issues/105
	modified:   stub/src/i386-linux.elf-entry.S

	modified:   stub/i386-linux.elf-entry.h
	modified:   stub/tmp/i386-linux.elf-entry.bin.dump
2017-06-19 15:49:28 -07:00
John Reiser 650df95b72 Fix thinko in PackMachBase<T>::canUnpack(). Also detect more bad input values.
https://github.com/upx/upx/issues/109
	modified:   p_mach.cpp
2017-06-18 14:24:44 -07:00
John Reiser b2115a4162 i386: clear the stack when leaving (for buggy programs); align esp to 0 mod 8
modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S

	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/i386-linux.elf-entry.h
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/tmp/i386-linux.elf-entry.bin.dump
	modified:   stub/tmp/i386-linux.elf-fold.map
2017-06-16 21:36:21 -07:00
John Reiser d67bf16a08 i386: Separate PROT_EXEC and PROT_WRITE
Also affects some arm and mips (via sharing i386-linux.elf-main.c)
	modified:   i386-linux.elf-entry.S
	modified:   i386-linux.elf-main.c

	also .h, .map, .dump
2017-06-16 08:17:44 -07:00
John Reiser a4c9b64224 PowerPC: fix ET_EXEC [merge problems?] Next: -pie
modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-main.c

	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-fold.map
2017-06-14 20:00:30 -07:00
John Reiser 8f572e5fe6 Rewrite stubs for 32-bit arm and i386 for -pie (Position-Independent Executable)
Coming next: MIPS and PowerPC.
	modified:   p_lx_elf.cpp
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   ../.github/travis_testsuite_1.sh

	also associated *.h *.map *.dump files
2017-06-14 09:57:19 -07:00
John Reiser e58873044b Remove unused and obsolete macros do_dcache_flush and do_icache_invalidate
modified:   stub/src/arch/arm64/v8/macros.S
2017-06-14 09:35:05 -07:00
John Reiser 8ada92a69f "Drive-by" typo fix
modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/arm64-darwin.macho-entry.h
2017-06-14 09:33:41 -07:00
John Reiser 3c8ed5c000 Fix typo under "#if 0"
modified:   packer.cpp
2017-06-10 22:11:04 -07:00
John Reiser c127d5b64a o_binfo got in the way
modified:   stub/src/i386-linux.elf-entry.S
2017-06-10 14:03:05 -07:00
John Reiser 2d3bd0809a i386-linux.elf-fold.S avoids mmap() into stack
modified:   stub/src/i386-linux.elf-fold.S
	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/tmp/i386-linux.elf-fold.map
2017-06-09 14:38:08 -07:00
John Reiser eef955a9dd Fix arm.v4a-linux.elf-entry.S
modified:   stub/src/arm.v4a-linux.elf-entry.S

	modified:   stub/arm.v4a-linux.elf-entry.h
	modified:   stub/arm.v5a-linux.elf-entry.h
	modified:   stub/armeb.v4a-linux.elf-entry.h
	modified:   stub/tmp/arm.v4a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v5a-linux.elf-entry.bin.dump
	modified:   stub/tmp/armeb.v4a-linux.elf-entry.bin.dump
	modified:   ../.github/travis_testsuite_1.sh
2017-06-08 20:50:57 -07:00
John Reiser e59ce39dc6 Fix arm64-linux.elf-*
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:   stub/src/arm64-linux.elf-main.c

	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-fold.map
2017-06-08 17:23:19 -07:00
John Reiser 62815f5c3c Fix AT_PHDR and AT_ENTRY for amd64-linux.elf (-pie, libmusl)
modified:   stub/src/amd64-linux.elf-main.c

	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
2017-06-07 09:04:02 -07:00
John Reiser f496010273 Fix reloc of stub for amd64-linux.elf
modified:   stub/src/arm64-linux.elf-main.c

	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/tmp/arm64-linux.elf-fold.map
2017-06-07 09:01:37 -07:00
John Reiser 143c4e3322 Fix MH_EXECUTE for amd64-darwin.macho
modified:   p_mach.cpp
	modified:   stub/src/amd64-darwin.macho-entry.S

	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/tmp/amd64-darwin.macho-entry.bin.dump
2017-06-07 08:58:20 -07:00
John Reiser e7f1e99a5e Merge branch 'jreiser' into devel
O_BINFO simplifies stubs on linux Elf;
PowerPC64 (big endian: Apple Macintosh G5) and PowerPC* cleanup;
-fpie simplification; shlib for arm64, amd64.

A big merge due to suspending activity on 'devel' branch
during stabilization for release of UPX-3.94.
There were intermediate merges with private branch 'jreiser',
and attempted rebase onto 'devel' did not go well.
Verfication of cases ({ET_EXEC, -fpie, shlib} x {$ARCH}) is in progress.

	modified:   ../.github/travis_testsuite_1.sh
	modified:   conf.h
	modified:   linker.cpp
	modified:   linker.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   p_mach_enum.h
	modified:   packmast.cpp
	modified:   stub/Makefile
	modified:   stub/scripts/xstrip.py

	modified:   stub/src/amd64-darwin.dylib-entry.S
	modified:   stub/src/amd64-darwin.macho-entry.S
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/arch/powerpc/32/bxx.S
	modified:   stub/src/arch/powerpc/32/lzma_d.S
	modified:   stub/src/arch/powerpc/32/nrv2b_d.S
	modified:   stub/src/arch/powerpc/32/nrv2d_d.S
	modified:   stub/src/arch/powerpc/32/nrv2e_d.S
	modified:   stub/src/arch/powerpc/32/ppc_regs.h
	new file:   stub/src/arch/powerpc/64/Makefile
	new file:   stub/src/arch/powerpc/64/Makefile.extra
	new file:   stub/src/arch/powerpc/64/bxx.S
	new file:   stub/src/arch/powerpc/64/lzma_d.S
	new file:   stub/src/arch/powerpc/64/lzma_d_cf.S
	new file:   stub/src/arch/powerpc/64/lzma_d_cs.S
	new file:   stub/src/arch/powerpc/64/macros.S
	new file:   stub/src/arch/powerpc/64/nrv2b_d.S
	new file:   stub/src/arch/powerpc/64/nrv2d_d.S
	new file:   stub/src/arch/powerpc/64/nrv2e_d.S
	new file:   stub/src/arch/powerpc/64/ppc_regs.h
	modified:   stub/src/arch/powerpc/64le/bxx.S
	copied:     stub/src/arch/powerpc/64le/lzma_d.S -> stub/src/arch/powerpc/64le/lzma_d-common.S
	modified:   stub/src/arch/powerpc/64le/lzma_d.S
	modified:   stub/src/arch/powerpc/64le/lzma_d_cs.S
	modified:   stub/src/arch/powerpc/64le/nrv2b_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2d_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2e_d.S
	modified:   stub/src/arch/powerpc/64le/ppc_regs.h
	modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.shlib-init.S
	modified:   stub/src/i386-bsd.elf-entry.S
	modified:   stub/src/i386-darwin.macho-entry.S
	modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/mipsel.r3000-linux.elf-entry.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   stub/src/powerpc-darwin.dylib-entry.S
	modified:   stub/src/powerpc-darwin.macho-entry.S
	modified:   stub/src/powerpc-darwin.macho-fold.S
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-main.c
	new file:   stub/src/powerpc64-darwin.dylib-entry.S
	new file:   stub/src/powerpc64-darwin.macho-entry.S
	new file:   stub/src/powerpc64-darwin.macho-fold.S
	new file:   stub/src/powerpc64-darwin.macho-main.c
	new file:   stub/src/powerpc64-linux.elf-entry.S
	new file:   stub/src/powerpc64-linux.elf-fold.S
	new file:   stub/src/powerpc64-linux.elf-fold.lds
	new file:   stub/src/powerpc64-linux.elf-main.c
	modified:   stub/src/powerpc64-savegpr0.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-main.c

	and most stub/*.h and stub/tmp/*.dump
2017-06-05 11:32:25 -07:00
John Reiser 140a031515 arm64-linux.shlib-init
modified:   p_lx_elf.cpp
	modified:   stub/src/arm64-linux.shlib-init.S

	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-06-04 16:52:43 -07:00
John Reiser b7c91941b8 --android-shlib fix Elf64_Shdr.sh_offset
https://github.com/upx/upx/issues/100
	modified:   ../p_lx_elf.cpp
	modified:   ../p_lx_elf.h
2017-05-31 11:04:56 -07:00
John Reiser 33f0b6da67 Merge branch 'devel' of https://github.com/upx/upx into devel 2017-05-31 10:57:19 -07:00
John Reiser ee18fe9bba DF_1_PIE and calls_crt1() to handle part of -pie,-fPIE
https://github.com/upx/upx/issues/106  [partial]
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-05-31 10:53:55 -07:00
John Reiser a51330cf07 DF_1_PIE and calls_crt1() to handle part of -pie,-fPIE
https://github.com/upx/upx/issues/106  [partial]
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-05-30 13:43:06 -07:00
John Reiser a67aed2744 Merge branch 'devel' of https://github.com/upx/upx into devel 2017-05-30 11:33:39 -07:00
John Reiser d979e19315 fpad8() for --android-shlib in PackLinuxElf64::pack4()
https://github.com/upx/upx/issues/100
	modified:   p_lx_elf.cpp
2017-05-30 11:32:05 -07:00
Markus F.X.J. Oberhumer 4c74d16795 Avoid a compilation warning. clang-format files. 2017-05-28 11:32:12 +02:00
John Reiser 6e541a432f amd64-linux: DF_1_PIE marks a main program; stub juggles AT_PHDR for same
https://github.com/upx/upx/issues/105
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-main.c

	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
2017-05-27 19:54:12 -07:00
John Reiser d8f47e248a Handle old style 8-byte headers for version <= 11
https://github.com/upx/upx/issues/102
	modified:   p_unix.cpp
2017-05-26 13:05:12 -07:00
John Reiser d1a869496b More visibility for PackHeader when debug(-D)
modified:   packhead.cpp
	modified:   packmast.cpp
	modified:   pefile.h
2017-05-26 13:02:32 -07:00
John Reiser f42a37555d Merge branch 'devel' of https://github.com/upx/upx into devel 2017-05-21 20:48:05 -07:00
John Reiser d9e019bd87 amd64-darwin.dylib hacking
modified:   stub/src/amd64-darwin.dylib-entry.S

	modified:   stub/amd64-darwin.dylib-entry.h
	modified:   stub/tmp/amd64-darwin.dylib-entry.bin.dump
2017-05-17 21:36:40 -07:00
John Reiser ce194fa5d8 amd64-darwin.dylib hacking
modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   p_mach_enum.h
	modified:   stub/src/amd64-darwin.dylib-entry.S

	modified:   stub/amd64-darwin.dylib-entry.h
	modified:   stub/tmp/amd64-darwin.dylib-entry.bin.dump
2017-05-17 15:50:34 -07:00
Markus F.X.J. Oberhumer b5bdf57636 Minor cleanups. 2017-05-14 19:21:04 +02:00
Markus F.X.J. Oberhumer a3a81ce7c6 Update NEWS. 2017-05-13 20:44:02 +02:00
Markus F.X.J. Oberhumer 61f347401c Update testsuite checksums caused by version bump. 2017-05-12 15:35:24 +02:00
Markus F.X.J. Oberhumer d985a4c250 Post-release version bump. 2017-05-12 15:28:47 +02:00
Markus F.X.J. Oberhumer d31947e1f0 Update NEWS. 2017-05-12 13:01:20 +02:00
Markus F.X.J. Oberhumer e4659b7d7c Bump release date. 2017-05-12 12:47:14 +02:00
Markus F.X.J. Oberhumer 8827a534db Update Travis. 2017-05-12 12:45:43 +02:00
Markus F.X.J. Oberhumer ddf48b45a5 Update Travis. 2017-05-09 22:50:18 +02:00
John Reiser 8eabb9b02f i386 recover from merge
modified:   p_lx_elf.cpp
2017-05-08 18:54:41 -07:00
John Reiser 8a195a0b35 amd64 recover from merge
modified:   stub/src/amd64-linux.elf-fold.S

	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
2017-05-08 16:06:02 -07:00
John Reiser 955206aaf0 Merge branch 'devel' into jreiser
Conflicts:
	src/p_lx_elf.cpp
	src/stub/src/amd64-linux.elf-entry.S
	src/stub/src/amd64-linux.elf-main.c
	src/stub/src/arm.v4a-linux.elf-entry.S
	src/stub/src/arm.v4a-linux.elf-fold.S
	src/stub/src/arm64-linux.elf-entry.S
	src/stub/src/arm64-linux.elf-fold.S
	src/stub/src/i386-linux.elf-fold.S
	src/stub/src/powerpc-darwin.macho-entry.S
	src/stub/src/powerpc-linux.elf-fold.S
	src/stub/src/powerpc64le-darwin.macho-entry.S
	src/stub/src/powerpc64le-linux.elf-entry.S
	src/stub/src/powerpc64le-linux.elf-fold.S
	src/stub/src/powerpc64le-linux.elf-main.c

 Changes to be committed:
	modified:   ../.github/ISSUE_TEMPLATE.md
	modified:   ../.github/travis_build.sh
	modified:   ../.github/travis_deploy.sh
	modified:   ../.github/travis_init.sh
	modified:   ../.github/travis_testsuite_1.sh
	modified:   ../.gitignore
	modified:   ../.travis.yml
	modified:   ../NEWS
	modified:   c_screen.cpp
	modified:   file.cpp
	modified:   help.cpp
	modified:   linker.cpp
	modified:   main.cpp
	modified:   p_lx_elf.cpp
	modified:   packer.cpp
	modified:   s_djgpp2.cpp
	modified:   stub/src/amd64-linux.elf-main.c
	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/powerpc-darwin.dylib-entry.S
	modified:   stub/src/powerpc-darwin.macho-entry.S
	modified:   stub/src/powerpc-darwin.macho-fold.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-main.c
	modified:   ui.cpp
	modified:   util.cpp
	modified:   work.cpp
	[plus *.h, *.dump, *.map]
2017-05-08 14:21:31 -07:00
John Reiser 082dd7d5ee arm64 TRACE improvement
modified:   stub/src/arm64-linux.elf-entry.S

	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
2017-05-07 12:07:51 -07:00
John Reiser 90714cf624 arm64 tracing in stub
modified:   ../../linker.cpp
	modified:   ../../p_lx_elf.cpp
	modified:   arm64-linux.elf-entry.S
2017-05-06 19:37:37 -07:00
John Reiser 61798d33f0 Revamp stub on arm, arm64; mmap into stack defeats auto-expansion [kernel bug?]
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:   ../.github/travis_testsuite_1.sh
	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/armeb.v4a-linux.elf-fold.h
	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
2017-05-05 18:36:44 -07:00
John Reiser 6e2a41cb26 DPRINTF for amd64
modified:   Makefile
	modified:   src/amd64-linux.elf-fold.S
	modified:   src/amd64-linux.elf-main.c

	modified:   amd64-linux.elf-fold.h
	modified:   tmp/amd64-linux.elf-fold.map
2017-05-05 13:32:42 -07:00
John Reiser 515897e180 Allow Elf64_Ehdr::ELFOSABI_NONE on Linux; cater to EM_PPC64.e_flags quirk
modified:   p_lx_elf.cpp
2017-05-04 08:28:03 -07:00
John Reiser fe4a8f33b1 Start on darwin.macho-dylib
modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   packmast.cpp
2017-05-03 08:30:21 -07:00
Markus F.X.J. Oberhumer 304d848f53 Bump version date. 2017-05-03 13:49:22 +02:00
Markus F.X.J. Oberhumer b5f738abf3 Move xxx_le26 from miniacc.h to bele.h. 2017-05-03 13:25:10 +02:00
Markus F.X.J. Oberhumer 7ebed06393 Fix building with recent djgpp2 gcc-6 version. 2017-05-03 13:21:08 +02:00
Markus F.X.J. Oberhumer 2e56fe82bb Update Travis. 2017-05-01 10:37:07 +02:00
John Reiser 32019c61aa dynamic e_phnum for arm
modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S

	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/arm.v4a-linux.elf-entry.h
	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-entry.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/armeb.v4a-linux.elf-entry.h
	modified:   stub/armeb.v4a-linux.elf-fold.h
	modified:   stub/tmp/arm.v4a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v4a-linux.elf-fold.map
	modified:   stub/tmp/arm.v5a-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm.v5a-linux.elf-fold.map
	modified:   stub/tmp/armeb.v4a-linux.elf-entry.bin.dump
	modified:   stub/tmp/armeb.v4a-linux.elf-fold.map
2017-04-30 19:15:17 -07:00
John Reiser f7ffae565c dynamic e_phnum for arm64
modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S

	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
2017-04-30 13:13:53 -07:00
John Reiser cd11bb1606 Update AT_BASE for musl-libc
https://github.com/upx/upx/issues/93
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/i386-linux.elf-main.c
	modified:   stub/src/powerpc64le-linux.elf-main.c

	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
	modified:   ../.github/travis_testsuite_1.sh
2017-04-27 20:55:02 -07:00
John Reiser 24c924d668 Fix size of 'imul'
modified:   src/stub/src/i386-linux.elf-fold.S
	modified:   src/p_lx_elf.cpp

	modified:   .github/travis_testsuite_1.sh
	modified:   src/stub/i386-linux.elf-fold.h
	modified:   src/stub/tmp/i386-linux.elf-fold.map
2017-04-26 15:24:19 -07:00
John Reiser 9be94e4b58 Fix size of 'imul'
modified:   stub/src/amd64-linux.elf-entry.S

	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/tmp/amd64-linux.elf-entry.bin.dump
2017-04-24 17:12:55 -07:00
John Reiser 15e9d8c99d Recognize __libc_init for Android -pie (PositionIndependentExecutable)
based on https://github.com/upx/upx/pull/92/commits/d34887ef60304cb28990c4b99c17b1f91acbbef1
	modified:   p_lx_elf.cpp
2017-04-24 11:04:48 -07:00
John Reiser 391f511094 powerpc-linux.elf-fold.S and -main.c handle /proc/self/exe
modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-main.c

	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-fold.map
2017-04-22 20:18:00 -07:00
John Reiser 5b53c11a6b Sync powerpc-linux.elf testsuite
modified:   travis_testsuite_1.sh
2017-04-21 11:30:12 -07:00
John Reiser 9df4b6ea24 Sync SZ_FRAME with devel branch
modified:   src/arch/powerpc/32/ppc_regs.h
	modified:   src/arch/powerpc/64le/ppc_regs.h
	modified:   src/powerpc64le-linux.elf-entry.S
	modified:   src/powerpc64le-linux.elf-fold.S
2017-04-21 10:54:04 -07:00
John Reiser a440564ba4 Fix powerpc64le ABI stack frame omitting spill area for a0-a7
Also use new symbol SZ_FRAME in */ppc_regs.h
	modified:   stub/src/arch/powerpc/32/ppc_regs.h
	modified:   stub/src/arch/powerpc/64le/ppc_regs.h
	modified:   stub/src/powerpc-darwin.dylib-entry.S
	modified:   stub/src/powerpc-darwin.macho-entry.S
	modified:   stub/src/powerpc-darwin.macho-fold.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S

	modified:   stub/powerpc-darwin.dylib-entry.h
	modified:   stub/powerpc-darwin.macho-entry.h
	modified:   stub/powerpc-darwin.macho-fold.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-darwin.macho-fold.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/tmp/powerpc64le-darwin.macho-fold.map
2017-04-21 08:58:13 -07:00
John Reiser 9583cfcc93 Update NEWS 2017-04-19 19:55:39 -07:00
John Reiser c4a921283a Revamp powerpc{,64le,64}.
Fix 64-bit stack frame (8*8 bytes for spilling a0-a7).  Avoid using r2 (t0).
Prepare for -pie executables.  Prepare for unified strategy in stubs.

	modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-main.c
	modified:   stub/src/arch/powerpc/32/bxx.S
	modified:   stub/src/arch/powerpc/32/lzma_d.S
	modified:   stub/src/arch/powerpc/32/nrv2b_d.S
	modified:   stub/src/arch/powerpc/32/nrv2d_d.S
	modified:   stub/src/arch/powerpc/32/nrv2e_d.S
	modified:   stub/src/arch/powerpc/32/ppc_regs.h
	new file:   stub/src/arch/powerpc/64/Makefile
	new file:   stub/src/arch/powerpc/64/Makefile.extra
	new file:   stub/src/arch/powerpc/64/lzma_d.S
	new file:   stub/src/arch/powerpc/64/lzma_d_cf.S
	new file:   stub/src/arch/powerpc/64/lzma_d_cs.S
	modified:   stub/src/arch/powerpc/64le/bxx.S
	copied:     stub/src/arch/powerpc/64le/lzma_d.S -> stub/src/arch/powerpc/64le/lzma_d-common.S
	modified:   stub/src/arch/powerpc/64le/lzma_d.S
	modified:   stub/src/arch/powerpc/64le/lzma_d_cs.S
	modified:   stub/src/arch/powerpc/64le/nrv2b_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2d_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2e_d.S
	modified:   stub/src/arch/powerpc/64le/ppc_regs.h
	modified:   stub/src/i386-darwin.macho-entry.S
	modified:   stub/src/powerpc-darwin.dylib-entry.S
	modified:   stub/src/powerpc-darwin.macho-entry.S
	modified:   stub/src/powerpc-darwin.macho-fold.S
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-main.c
	modified:   stub/src/powerpc64-darwin.dylib-entry.S
	modified:   stub/src/powerpc64-darwin.macho-entry.S
	modified:   stub/src/powerpc64-darwin.macho-fold.S
	modified:   stub/src/powerpc64-darwin.macho-main.c
	modified:   stub/src/powerpc64-linux.elf-main.c
	modified:   stub/src/powerpc64-savegpr0.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S

	modified:   stub/i386-darwin.macho-entry.h
	modified:   stub/powerpc-darwin.dylib-entry.h
	modified:   stub/powerpc-darwin.macho-entry.h
	modified:   stub/powerpc-darwin.macho-fold.h
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc-linux.kernel.vmlinux.h
	modified:   stub/powerpc64-linux.elf-entry.h
	modified:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-darwin.macho-fold.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.kernel.vmlinux.h
	modified:   stub/tmp/i386-darwin.macho-entry.bin.dump
	modified:   stub/tmp/powerpc-darwin.dylib-entry.bin.dump
	modified:   stub/tmp/powerpc-darwin.macho-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-darwin.dylib-entry.bin.dump
	modified:   stub/tmp/powerpc64le-darwin.macho-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.kernel.vmlinux.bin.dump
2017-04-19 19:25:05 -07:00
John Reiser 4e05f087f9 PowerPC 64-bit big-endian
modified:   conf.h
	modified:   linker.cpp
	modified:   linker.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   packmast.cpp
	modified:   stub/Makefile
	modified:   stub/powerpc-linux.elf-entry.h
	new file:   stub/powerpc64-linux.elf-entry.h
	new file:   stub/powerpc64-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/scripts/xstrip.py
	modified:   stub/src/arch/powerpc/64le/nrv2b_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2d_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2e_d.S
	new file:   stub/src/powerpc64-darwin.dylib-entry.S
	new file:   stub/src/powerpc64-darwin.macho-entry.S
	new file:   stub/src/powerpc64-darwin.macho-fold.S
	new file:   stub/src/powerpc64-darwin.macho-main.c
	new file:   stub/src/powerpc64-linux.elf-entry.S
	new file:   stub/src/powerpc64-linux.elf-fold.S
	new file:   stub/src/powerpc64-linux.elf-fold.lds
	new file:   stub/src/powerpc64-linux.elf-main.c
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-main.c
	modified:   stub/tmp/powerpc64le-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2017-04-11 19:15:43 -07:00
John Reiser 40b506d2e0 Sync arm* stubs
modified:   ../arm.v4a-linux.elf-entry.h
	modified:   ../arm.v4a-linux.elf-fold.h
	modified:   ../arm.v5a-linux.elf-entry.h
	modified:   ../arm.v5a-linux.elf-fold.h
	modified:   ../arm64-darwin.macho-entry.h
	modified:   ../arm64-linux.elf-entry.h
	modified:   ../arm64-linux.elf-fold.h
	modified:   ../armeb.v4a-linux.elf-entry.h
	modified:   ../armeb.v4a-linux.elf-fold.h
	modified:   ../tmp/arm.v4a-linux.elf-entry.bin.dump
	modified:   ../tmp/arm.v4a-linux.elf-fold.map
	modified:   ../tmp/arm.v5a-linux.elf-entry.bin.dump
	modified:   ../tmp/arm.v5a-linux.elf-fold.map
	modified:   ../tmp/arm64-darwin.macho-entry.bin.dump
	modified:   ../tmp/arm64-linux.elf-entry.bin.dump
	modified:   ../tmp/armeb.v4a-linux.elf-entry.bin.dump
	modified:   ../tmp/armeb.v4a-linux.elf-fold.map
2017-04-11 19:13:11 -07:00
John Reiser 263f384810 o_binfo
modified:   arm64-darwin.macho-entry.S
2017-04-11 19:07:38 -07:00
John Reiser d80c145a18 PROT_EXEC for decompressed 'fold'
modified:   powerpc-linux.elf-entry.S
2017-04-10 15:36:43 -07:00
Markus F.X.J. Oberhumer 8848fe35f6 Update Travis. 2017-04-10 16:15:03 +02:00
John Reiser 7a681bd20d Use saved registers for parameters to 'fold'; lzma can clobber others
modified:   arm64-linux.elf-entry.S
	modified:   arm64-linux.elf-fold.S
2017-04-09 21:33:29 -07:00
John Reiser ed31fb184b Replace crumb with b_info
modified:   stub/src/arm.v4a-linux.elf-entry.S
	modified:   stub/src/arm.v4a-linux.elf-fold.S
2017-04-09 18:06:16 -07:00
John Reiser 360b94dd6c i386-linux ET_EXEC working
modified:   stub/src/i386-linux.elf-fold.S

	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/tmp/i386-linux.elf-fold.map
2017-04-07 16:08:13 -07:00
John Reiser 8524e73f59 Always a 1-page crumb for i386
modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S

	modified:   stub/i386-linux.elf-entry.h
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/tmp/i386-linux.elf-entry.bin.dump
2017-04-07 11:17:01 -07:00
John Reiser 940514e5ca Sync stubs
modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-04-07 10:09:01 -07:00
John Reiser a4e47625ac Sync stubs
modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-04-07 08:23:30 -07:00
John Reiser 7c16872a6e Merge branch 'devel' into jreiser 2017-04-07 08:22:08 -07:00
John Reiser 994c3c3552 Use arm64-linux-objdump-2.25 and arm64-linux-objcopy-2.25
modified:   Makefile.extra

	modified:   lzma_d_cf.S
	modified:   lzma_d_cs.S
2017-04-07 07:20:47 -07:00
John Reiser c34f496600 Avoid incorrect C4319 by Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64
modified:   p_lx_elf.cpp
2017-04-07 05:36:40 -07:00
John Reiser 8bca8629be Preserve symlink /proc/self/exe by mapping one page into the stack.
modified:   stub/src/amd64-linux.elf-fold.S

	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-fold.map
2017-04-06 23:08:35 -07:00
John Reiser 85fdd579d6 Cleanup PackLinuxElf64amd::defineSymbols(): use is_pie; reduce symbols
modified:   p_lx_elf.cpp
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S

	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/tmp/amd64-linux.elf-entry.bin.dump
	modified:   stub/tmp/amd64-linux.elf-fold.map
2017-04-06 17:22:30 -07:00
John Reiser e88d2ff88c Merge branch 'devel' into jreiser
modified:   ../.appveyor.yml
	modified:   ../.github/travis_build.sh
	modified:   Makefile
	modified:   linker.cpp
	modified:   p_lx_elf.cpp
	modified:   packmast.cpp
2017-04-06 14:25:14 -07:00
John Reiser bdf08baebd O_BINFO
modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/i386-bsd.elf-entry.h
	modified:   stub/i386-darwin.macho-entry.h
	modified:   stub/i386-linux.elf-entry.h
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/i386-netbsd.elf-entry.h
	modified:   stub/mips.r3000-linux.elf-fold.h
	modified:   stub/mipsel.r3000-linux.elf-fold.h
	modified:   stub/powerpc-darwin.macho-entry.h
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/src/amd64-darwin.macho-entry.S
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/amd64-linux.elf-fold.S
	modified:   stub/src/arch/powerpc/32/ppc_regs.h
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/i386-bsd.elf-entry.S
	modified:   stub/src/i386-darwin.macho-entry.S
	modified:   stub/src/i386-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/mipsel.r3000-linux.elf-fold.S
	modified:   stub/src/powerpc-darwin.macho-entry.S
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-main.c
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-main.c
	modified:   stub/tmp/amd64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/amd64-linux.elf-entry.bin.dump
	modified:   stub/tmp/amd64-linux.elf-fold.map
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/i386-bsd.elf-entry.bin.dump
	modified:   stub/tmp/i386-darwin.macho-entry.bin.dump
	modified:   stub/tmp/i386-linux.elf-entry.bin.dump
	modified:   stub/tmp/i386-linux.elf-fold.map
	modified:   stub/tmp/i386-netbsd.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-darwin.macho-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-darwin.macho-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2017-04-06 14:22:47 -07:00
John Reiser 3dcdd25177 re-work -fpie for amd64
modified:   stub/src/amd64-linux.elf-main.c
2017-04-06 14:22:05 -07:00
John Reiser 491e8640b2 is_pie; O_BINFO; remove LUNMP000, LUNMP001
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-04-06 14:15:07 -07:00
John Reiser b23b7ef85e DT_FLAGS_1, DF_1_PIE
modified:   p_elf_enum.h
2017-04-06 14:13:02 -07:00
John Reiser b167374f13 R_PPC64_ADDR32
modified:   linker.cpp
2017-04-06 14:12:29 -07:00
John Reiser cd1f6e733f Merge branch 'devel' of https://github.com/upx/upx into devel 2017-04-06 09:05:46 -07:00
John Reiser d3fc7687b8 Fix valgrind error
https://travis-ci.org/upx/upx/jobs/218929378
	modified:   p_lx_elf.cpp
2017-04-06 09:04:13 -07:00
Markus F.X.J. Oberhumer 17a83d58da clang-format files. 2017-04-05 17:15:29 +02:00
Markus F.X.J. Oberhumer 18a8e1b6d6 Update Travis. 2017-04-05 17:02:46 +02:00
Markus F.X.J. Oberhumer 2c23cbb359 Silence some compiler warnings. 2017-04-05 17:02:42 +02:00
Markus F.X.J. Oberhumer cdd58cf757 Use proper UPX types. 2017-04-05 16:31:36 +02:00
John Reiser a0df325659 Merge branch 'devel' of https://github.com/upx/upx into devel 2017-04-03 20:26:23 -07:00
John Reiser a59005e836 Elf propagates NX via PT_GNU_STACK (except MIPS stub is too difficult for now)
https://github.com/upx/upx/issues/81
	modified:   ../.github/travis_testsuite_1.sh
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/tmp/amd64-linux.elf-entry.bin.dump
	modified:   stub/tmp/i386-linux.elf-fold.map
	modified:   stub/tmp/powerpc-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2017-04-03 20:25:57 -07:00
John Reiser 5da6a27e6b Elf propates NX via PT_GNU_STACK (except MIPS stub is too difficult for now)
https://github.com/upx/upx/issues/81
	modified:   ../.github/travis_testsuite_1.sh
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/i386-linux.elf-fold.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/src/amd64-linux.elf-entry.S
	modified:   stub/src/i386-linux.elf-fold.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/tmp/amd64-linux.elf-entry.bin.dump
	modified:   stub/tmp/i386-linux.elf-fold.map
	modified:   stub/tmp/powerpc-linux.elf-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2017-04-03 20:11:08 -07:00
John Reiser ef97af71e3 Merge branch 'jreiser' into devel 2017-04-03 12:57:57 -07:00
John Reiser 6ed67f4532 Unpack prefix with appended data; give message, keep backup
https://github.com/upx/upx/issues/4
	modified:   p_mach.cpp
2017-04-03 12:53:27 -07:00
John Reiser 1278d663b4 Merge branch 'jreiser' into devel 2017-04-02 14:56:26 -07:00
John Reiser 0395c7b407 Use stubtools for arm64.
modified:   stub/Makefile
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-04-02 14:55:39 -07:00
John Reiser df3d15ffb3 Enable stub for arm64 shlib. Stub is broken, but at least it packs.
modified:   p_lx_elf.cpp
2017-03-31 20:01:14 -07:00
John Reiser 6f673310d2 powerpc64le: lzma compression support
https://github.com/upx/upx/pull/79

Integration based on:
commit c4bde4369f
Author: Thierry Fauck <tfauck@free.fr>
Date:   Fri Mar 24 17:39:30 2017 +0100

    powerpc64le: lzma compression support

    Signed-off-by: Thierry Fauck <tfauck@free.fr>

    	modified:   powerpc64le-darwin.dylib-entry.h
    	modified:   powerpc64le-darwin.macho-entry.h
    	modified:   powerpc64le-linux.elf-entry.h
    	modified:   powerpc64le-linux.kernel.vmlinux.h
    	modified:   src/arch/powerpc/64le/lzma_d.S
    	modified:   tmp/powerpc64le-darwin.dylib-entry.bin.dump
    	modified:   tmp/powerpc64le-darwin.macho-entry.bin.dump
    	modified:   tmp/powerpc64le-linux.elf-entry.bin.dump
    	modified:   tmp/powerpc64le-linux.kernel.vmlinux.bin.dump
2017-03-31 13:42:43 -07:00
John Reiser 978c3eca23 --android-shlib preserves selected Elf64_Shdr
https://github.com/upx/upx/issues/65
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-03-31 13:26:27 -07:00
John Reiser 20bc848bd6 --android-shlib preserves selected Elf64_Shdr
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-03-31 13:24:36 -07:00
John Reiser ce7f1292dc Merge branch 'devel' into jreiser 2017-03-31 13:10:08 -07:00
John Reiser d97ff8bb40 More cleanup
modified:   p_lx_elf.cpp
2017-03-31 12:57:11 -07:00
John Reiser 8a9b46d82f Cleanup minor bug in unpack ET_EXE
modified:   p_lx_elf.cpp
2017-03-31 12:42:14 -07:00
John Reiser 12e5703541 Stronger test and better message for PT_LOAD[0].p_offset != 0
https://github.com/upx/upx/issues/80
	modified:   p_lx_elf.cpp
2017-03-31 12:20:02 -07:00
John Reiser 1b87fc2ee6 DT_INIT restored for -d on --android-shlib
modified:   p_lx_elf.cpp
2017-03-30 15:55:35 -07:00
John Reiser ebd0c780a1 Unpacking --android-shlib works except for restoring DT_INIT
modified:   p_lx_elf.cpp
2017-03-30 11:05:49 -07:00
John Reiser bd976cd562 Merge branch 'devel' into jreiser
modified:   packmast.cpp
2017-03-30 10:27:54 -07:00
John Reiser 0e511c3e07 visitAllPackers() lists class names when -D
modified:   packmast.cpp
2017-03-30 10:23:27 -07:00
John Reiser 300d489408 --android-shlib preserves selected Elf32_Shdr
32-bit only for now; also in wrong place for unpacking (-d)
	modified:   main.cpp
	modified:   options.h
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-03-29 18:31:39 -07:00
John Reiser 024d081167 Fix unpack of ET_DYN
https://github.com/upx/upx/issues/73

	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-03-27 16:49:46 -07:00
John Reiser 348173d3f1 Fix editing glitch
modified:   p_lx_elf.cpp
2017-03-27 16:42:26 -07:00
John Reiser 23e3814f8a Fix unpacking of ET_DYN
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2017-03-27 16:10:12 -07:00
John Reiser b818e2c4b8 arm64 (aarch64)
Tested and working: nrv2b and nrv2e for ET_EXE on linux.
NOT TESTED: lzma, ET_DYN on linux; any Mach-O

	modified:   bele.h
	modified:   conf.h
	modified:   filter/ct.h
	modified:   filteri.cpp
	modified:   linker.cpp
	modified:   linker.h
	modified:   miniacc.h
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   packmast.cpp
	modified:   stub/Makefile
	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-darwin.macho-fold.h
	new file:   stub/arm64-linux.elf-entry.h
	new file:   stub/arm64-linux.elf-fold.h
	new file:   stub/arm64-linux.shlib-init.h
	new file:   stub/src/arch/arm64/v8/Makefile.extra
	modified:   stub/src/arch/arm64/v8/lzma_d-arm.S
	modified:   stub/src/arch/arm64/v8/lzma_d.S
	modified:   stub/src/arch/arm64/v8/lzma_d_cf.S
	new file:   stub/src/arch/arm64/v8/lzma_d_cs.S
	modified:   stub/src/arch/arm64/v8/macros.S
	renamed:    stub/src/arch/arm64/v8/nrv2b_d8.S -> stub/src/arch/arm64/v8/nrv2b_d32.S
	renamed:    stub/src/arch/arm64/v8/nrv2d_d8.S -> stub/src/arch/arm64/v8/nrv2d_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2e_d32.S
	deleted:    stub/src/arch/arm64/v8/nrv2e_d8.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-darwin.macho-fold.S
	new file:   stub/src/arm64-linux.elf-entry.S
	new file:   stub/src/arm64-linux.elf-fold.S
	new file:   stub/src/arm64-linux.elf-fold.lds
	new file:   stub/src/arm64-linux.elf-main.c
	new file:   stub/src/arm64-linux.shlib-init.S
	modified:   stub/src/include/linux.h
	modified:   stub/tmp/arm64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/arm64-darwin.macho-fold.map
	new file:   stub/tmp/arm64-linux.elf-entry.bin.dump
	new file:   stub/tmp/arm64-linux.elf-fold.map
	new file:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-03-26 13:10:26 -07:00
John Reiser 6adb3dc142 BUILD_TYPE_DEBUG ?= 0 2017-03-26 13:03:49 -07:00
John Reiser 0e154cc759 Hint when need DT_INIT for shared library
https://github.com/upx/upx/issues/74
	modified:   p_lx_elf.cpp
2017-03-25 20:22:04 -07:00
John Reiser 9dce8d9bce Separate from amd64/bxx.S
modified:   stub/src/arch/amd64/bxx.S
2017-03-25 20:14:48 -07:00
John Reiser 0aa3b9c487 Revise comment
modified:   stub/src/arch/amd64/bxx.S
2017-03-25 20:10:50 -07:00
John Reiser dc7ab3ed30 sync git branch
modified:   stub/amd64-win64.pep.h
	modified:   stub/tmp/amd64-win64.pep.bin.dump
2017-03-25 20:08:29 -07:00
John Reiser 254259b354 Fix comment
modified:   stub/src/arch/amd64/bxx.S
2017-03-25 20:05:32 -07:00
John Reiser 9651c70efd Revert powerpc-linux.elf-fold.S
modified:   stub/src/powerpc-linux.elf-fold.S
2017-03-25 17:51:32 -07:00
John Reiser 5840190ed5 Revert xstrip.py
modified:   stub/scripts/xstrip.py
2017-03-25 17:50:06 -07:00
John Reiser a807b88694 BUILD_TYPE_DEBUG ?= 1
modified:   Makefile
2017-03-25 17:40:24 -07:00
John Reiser 0db82e09e9 Suggest fix for missing DT_INIT in shared library.
modified:   p_lx_elf.cpp
2017-03-25 17:39:47 -07:00
John Reiser e5865f171a xstrip.py: *.bindump was unused; clear e_shnum, e_shstrndx
Also allow other compilers for powerpc64le and arm64: loosen checking.
	modified:   stub/Makefile
	modified:   stub/scripts/xstrip.py

	modified:   stub/amd64-darwin.dylib-entry.h
	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/amd64-linux.kernel.vmlinux.h
	modified:   stub/amd64-linux.shlib-init.h
	modified:   stub/amd64-win64.pep.h
	modified:   stub/arm.v4a-linux.elf-entry.h
	modified:   stub/arm.v4a-wince.pe.h
	modified:   stub/arm.v4t-wince.pe.h
	modified:   stub/arm.v5a-darwin.macho-entry.h
	modified:   stub/arm.v5a-linux.elf-entry.h
	modified:   stub/arm.v5a-linux.kernel.vmlinux.h
	modified:   stub/arm.v5a-linux.kernel.vmlinuz.h
	modified:   stub/arm.v5a-linux.shlib-init.h
	modified:   stub/arm.v5t-linux.shlib-init.h
	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/armeb.v4a-linux.elf-entry.h
	modified:   stub/armeb.v5a-linux.kernel.vmlinux.h
	modified:   stub/i086-dos16.com.h
	modified:   stub/i086-dos16.exe.h
	modified:   stub/i086-dos16.sys.h
	modified:   stub/i386-bsd.elf-entry.h
	modified:   stub/i386-bsd.elf.execve-entry.h
	modified:   stub/i386-darwin.dylib-entry.h
	modified:   stub/i386-darwin.macho-entry.h
	modified:   stub/i386-dos32.djgpp2.h
	modified:   stub/i386-dos32.tmt.h
	modified:   stub/i386-dos32.watcom.le.h
	modified:   stub/i386-linux.elf-entry.h
	modified:   stub/i386-linux.elf.execve-entry.h
	modified:   stub/i386-linux.elf.interp-entry.h
	modified:   stub/i386-linux.elf.shell-entry.h
	modified:   stub/i386-linux.kernel.vmlinux.h
	modified:   stub/i386-linux.kernel.vmlinuz.h
	modified:   stub/i386-linux.shlib-init.h
	modified:   stub/i386-netbsd.elf-entry.h
	modified:   stub/i386-win32.pe.h
	modified:   stub/m68k-atari.tos.h
	modified:   stub/mips.r3000-linux.elf-entry.h
	modified:   stub/mipsel.r3000-linux.elf-entry.h
	modified:   stub/mipsel.r3000-ps1.h
	modified:   stub/powerpc-darwin.dylib-entry.h
	modified:   stub/powerpc-darwin.macho-entry.h
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.kernel.vmlinux.h
	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.kernel.vmlinux.h
2017-03-25 17:09:16 -07:00
John Reiser 166d198dcb Default BUILD_TYPE_DEBUG
modified:   Makefile
2017-03-25 16:54:26 -07:00
John Reiser 445795f2ec Sync testsuite for 32-bit powerpc lzma
modified:   ../.github/travis_testsuite_1.sh
2017-03-25 16:50:38 -07:00
John Reiser 6be4a87dac Revert "testsuite "set -x""
This reverts commit fbe4d287c7.

	modified:   .github/travis_testsuite_1.sh
2017-03-25 16:38:30 -07:00
John Reiser 17c47053d6 Revert amd64/bxx.S to reduce churn of testsuite
modified:   stub/src/arch/amd64/bxx.S

	modified:   stub/amd64-darwin.dylib-entry.h
	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/amd64-darwin.macho-fold.h
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/amd64-linux.shlib-init.h
	modified:   stub/amd64-win64.pep.h
2017-03-25 16:34:01 -07:00
John Reiser b4e18f7521 Remove debugging straggler.
modified:   src/powerpc-linux.elf-fold.S

	modified:   powerpc-linux.elf-fold.h
	modified:   tmp/powerpc-linux.elf-fold.map
2017-03-25 15:48:18 -07:00
John Reiser fbe4d287c7 testsuite "set -x"
modified:   ../.github/travis_testsuite_1.sh
2017-03-25 14:52:08 -07:00
John Reiser 543fa3ae79 Revert PackLinuxElf32::unpack() for decompression of armeb-linux.elf/upx-3.91
Conflicting with https://github.com/upx/upx/issues/73
	modified:   p_lx_elf.cpp
2017-03-25 12:52:20 -07:00
John Reiser 7cf855413c Sync testuite checksums (powerpc)
modified:   ../.github/travis_testsuite_1.sh
2017-03-25 09:12:56 -07:00
John Reiser f5d65dc0bc arm64 unfilter
modified:   stub/src/arm64-linux.elf-fold.S

	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/tmp/arm64-linux.elf-fold.map
2017-03-24 13:55:54 -07:00
John Reiser 2f6211a1d9 xstrip.py slight improvement for powerpc64le and arm64
modified:   stub/scripts/xstrip.py
2017-03-24 10:54:56 -07:00
John Reiser 513a57330a xstrip.py: *.bindump was unused; clear e_shnum, e_shstrndx
modified:   stub/scripts/xstrip.py
	modified:   stub/Makefile

	modified:   stub/amd64-darwin.dylib-entry.h
	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/amd64-linux.elf-entry.h
	modified:   stub/amd64-linux.kernel.vmlinux.h
	modified:   stub/amd64-linux.shlib-init.h
	modified:   stub/amd64-win64.pep.h
	modified:   stub/arm.v4a-linux.elf-entry.h
	modified:   stub/arm.v4a-wince.pe.h
	modified:   stub/arm.v4t-wince.pe.h
	modified:   stub/arm.v5a-darwin.macho-entry.h
	modified:   stub/arm.v5a-linux.elf-entry.h
	modified:   stub/arm.v5a-linux.kernel.vmlinux.h
	modified:   stub/arm.v5a-linux.kernel.vmlinuz.h
	modified:   stub/arm.v5a-linux.shlib-init.h
	modified:   stub/arm.v5t-linux.shlib-init.h
	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/armeb.v4a-linux.elf-entry.h
	modified:   stub/armeb.v5a-linux.kernel.vmlinux.h
	modified:   stub/i086-dos16.com.h
	modified:   stub/i086-dos16.exe.h
	modified:   stub/i086-dos16.sys.h
	modified:   stub/i386-bsd.elf-entry.h
	modified:   stub/i386-bsd.elf.execve-entry.h
	modified:   stub/i386-darwin.dylib-entry.h
	modified:   stub/i386-darwin.macho-entry.h
	modified:   stub/i386-dos32.djgpp2.h
	modified:   stub/i386-dos32.tmt.h
	modified:   stub/i386-dos32.watcom.le.h
	modified:   stub/i386-linux.elf-entry.h
	modified:   stub/i386-linux.elf.execve-entry.h
	modified:   stub/i386-linux.elf.interp-entry.h
	modified:   stub/i386-linux.elf.shell-entry.h
	modified:   stub/i386-linux.kernel.vmlinux.h
	modified:   stub/i386-linux.kernel.vmlinuz.h
	modified:   stub/i386-linux.shlib-init.h
	modified:   stub/i386-netbsd.elf-entry.h
	modified:   stub/i386-win32.pe.h
	modified:   stub/m68k-atari.tos.h
	modified:   stub/mips.r3000-linux.elf-entry.h
	modified:   stub/mipsel.r3000-linux.elf-entry.h
	modified:   stub/mipsel.r3000-ps1.h
	modified:   stub/powerpc-darwin.dylib-entry.h
	modified:   stub/powerpc-darwin.macho-entry.h
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.kernel.vmlinux.h
	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.kernel.vmlinux.h
2017-03-24 09:26:40 -07:00
John Reiser 715ddf0620 arm64 hacking
modified:   stub/src/arch/arm64/v8/macros.S
	new file:   stub/src/arch/arm64/v8/Makefile.extra
	modified:   stub/src/arch/arm64/v8/lzma_d-arm.S
	modified:   stub/src/arch/arm64/v8/lzma_d.S
	modified:   stub/src/arch/arm64/v8/lzma_d_cf.S
	new file:   stub/src/arch/arm64/v8/lzma_d_cs.S
	modified:   stub/src/arm64-darwin.macho-entry.S

	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-03-23 20:32:41 -07:00
John Reiser 6bb31e276e Merge branch 'devel' into jreiser 2017-03-23 13:27:09 -07:00
John Reiser b10f1df49f Merge branch 'devel' of https://github.com/upx/upx into devel 2017-03-23 13:09:59 -07:00
John Reiser f999519b13 Sync stubs for 32-bit powerpc
modified:   stub/src/arch/powerpc/32/Makefile.extra
	modified:   stub/src/arch/powerpc/32/lzma_d_cf.S
	modified:   stub/src/arch/powerpc/32/lzma_d_cs.S

	modified:   stub/powerpc-darwin.dylib-entry.h
	modified:   stub/powerpc-darwin.macho-entry.h
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.kernel.vmlinux.h
2017-03-23 13:08:36 -07:00
Markus F.X.J. Oberhumer aedbf02830 p_lx_elf.cpp: silence a clang-4.0 compilation warning. 2017-03-23 17:43:23 +01:00
John Reiser bd5479b250 arm64 omit "dc zva," while valgrind complains
modified:   src/arm64-linux.elf-entry.S
	modified:   src/arm64-linux.elf-fold.S

	modified:   arm64-linux.elf-entry.h
	modified:   arm64-linux.elf-fold.h
	modified:   tmp/arm64-linux.elf-entry.bin.dump
	modified:   tmp/arm64-linux.elf-fold.map
2017-03-23 09:12:35 -07:00
Markus F.X.J. Oberhumer 9d14715652 Update Travis. 2017-03-23 13:00:42 +01:00
Thierry Fauck 72156fcf1b powerpc64le: support for -fpie compiled binaries
Signed-off-by: Thierry Fauck <tfauck@free.fr>

	modified:   powerpc64le-linux.elf-fold.h
	modified:   src/powerpc64le-linux.elf-fold.S
	modified:   src/powerpc64le-linux.elf-main.c
	modified:   tmp/powerpc64le-linux.elf-fold.map
2017-03-23 11:21:50 +01:00
Markus F.X.J. Oberhumer 1c6eab00d1 Update Travis. 2017-03-23 04:20:29 +01:00
Markus F.X.J. Oberhumer f9738c5b55 New ACC version. 2017-03-23 01:17:33 +01:00
John Reiser 3b63083619 Cleanup powerpc64 stubs
modified:   stub/src/powerpc64le-darwin.macho-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S

	modified:   stub/powerpc64le-darwin.macho-fold.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/tmp/powerpc64le-darwin.macho-fold.map
	modified:   stub/tmp/powerpc64le-linux.elf-entry.bin.dump
2017-03-22 16:50:52 -07:00
John Reiser d5d7d8bc84 arm64 hacking
modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-main.c

	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/tmp/arm64-linux.elf-fold.map
2017-03-22 16:45:09 -07:00
John Reiser f26118cf5a lzma for powerpc64le: -Os needs _restgpr0_*
modified:   stub/src/arch/powerpc/64le/Makefile.extra
	modified:   stub/src/arch/powerpc/64le/ppc_regs.h
	modified:   stub/src/powerpc64-savegpr0.S

	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.kernel.vmlinux.h
	modified:   stub/src/arch/powerpc/64le/lzma_d_cf.S
	modified:   stub/src/arch/powerpc/64le/lzma_d_cs.S
	modified:   stub/tmp/powerpc64le-darwin.dylib-entry.bin.dump
	modified:   stub/tmp/powerpc64le-darwin.macho-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc64le-linux.kernel.vmlinux.bin.dump
2017-03-22 14:17:40 -07:00
John Reiser 5d6c4b475c preloc
modified:   stub/src/arm64-linux.elf-main.c
2017-03-22 09:03:13 -07:00
John Reiser 2c4ef392f6 arm64-linux hacking; returns from upx_main(), only launch remains!
modified:   stub/src/arch/arm64/v8/lzma_d.S
	modified:   stub/src/arch/arm64/v8/nrv2b_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2d_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2e_d32.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.elf-main.c

	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-03-21 21:54:49 -07:00
John Reiser 2a128fe772 Work on arm64 decompression
renamed:    stub/src/arch/arm64/v8/nrv2b_d8.S -> stub/src/arch/arm64/v8/nrv2b_d32.S
	renamed:    stub/src/arch/arm64/v8/nrv2d_d8.S -> stub/src/arch/arm64/v8/nrv2d_d32.S
	modified:   stub/src/arch/arm64/v8/nrv2e_d32.S
	deleted:    stub/src/arch/arm64/v8/nrv2e_d8.S
	modified:   stub/src/arm64-darwin.macho-entry.S
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/src/arm64-linux.elf-fold.S
	modified:   stub/src/arm64-linux.shlib-init.S

	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/arm64-linux.shlib-init.h
	modified:   stub/tmp/arm64-darwin.macho-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-fold.map
	modified:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-03-20 21:23:15 -07:00
John Reiser bb7d3ca3a1 Fix PackLinuxElf32::unpack() for shared library?
modified:   p_lx_elf.cpp
2017-03-20 21:21:46 -07:00
John Reiser a2bdba7eda arm64 cache flogging at initial move
modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/src/arm64-linux.elf-entry.S
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
2017-03-14 21:36:18 -07:00
John Reiser e8aabc9980 R_AARCH64_CONDBR19
modified:   linker.cpp
2017-03-14 21:35:01 -07:00
John Reiser 9f554a14fd ARM64 hacking
modified:   p_lx_elf.cpp
	modified:   stub/src/arch/arm64/v8/macros.S
	modified:   stub/src/arm64-darwin.macho-fold.S
	modified:   stub/src/arm64-linux.elf-entry.S

	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-darwin.macho-fold.h
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/arm64-linux.elf-fold.h
	modified:   stub/tmp/arm64-darwin.macho-fold.map
	modified:   stub/tmp/arm64-linux.elf-entry.bin.dump
	modified:   stub/tmp/arm64-linux.elf-fold.map
2017-03-14 20:08:28 -07:00
John Reiser 68a2b91ccb arm64 filter, relocation, defineSymbols
modified:   Makefile
	modified:   bele.h
	modified:   filter/ct.h
	modified:   filteri.cpp
	modified:   linker.cpp
	modified:   miniacc.h
	modified:   p_lx_elf.cpp
	modified:   stub/arm64-linux.elf-entry.h
	modified:   stub/src/arm64-linux.elf-entry.S
2017-03-05 21:05:13 -08:00
John Reiser 4089cc6e6f arm64-linux compiles
modified:   conf.h
	modified:   linker.cpp
	modified:   linker.h
	modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
	modified:   packmast.cpp
	modified:   stub/Makefile
	new file:   stub/arm64-linux.shlib-init.h
	new file:   stub/src/arm64-linux.shlib-init.S
	new file:   stub/tmp/arm64-linux.elf-entry.bin.dump
	new file:   stub/tmp/arm64-linux.elf-fold.map
	new file:   stub/tmp/arm64-linux.shlib-init.bin.dump
2017-03-05 18:07:29 -08:00
John Reiser 4e8848eeca Merge branch 'devel' into jreiser
Conflicts:
	src/stub/amd64-win64.pep.h
	src/stub/powerpc-linux.elf-entry.h
	src/stub/powerpc-linux.elf-fold.h
	src/stub/src/amd64-win64.pep.S
	src/stub/src/arch/powerpc/32/ppc_regs.h
	src/stub/src/arch/powerpc/64le/lzma_d.S
	src/stub/src/powerpc-linux.elf-entry.S
	src/stub/src/powerpc64le-darwin.dylib-entry.S
	src/stub/src/powerpc64le-darwin.macho-entry.S
	src/stub/src/powerpc64le-linux.elf-entry.S
	src/stub/src/powerpc64le-linux.kernel.vmlinux.S
	src/stub/tmp/amd64-win64.pep.bin.dump
	src/stub/tmp/powerpc-linux.elf-entry.bin.dump
	src/stub/tmp/powerpc-linux.elf-fold.map

	modified:   ../../.github/travis_testsuite_1.sh
	modified:   ../p_lx_elf.cpp
	modified:   ../p_unix.cpp
	modified:   ../p_unix.h
	modified:   amd64-win64.pep.h
	modified:   arm.v4a-linux.elf-fold.h
	modified:   arm.v5a-linux.elf-fold.h
	modified:   armeb.v4a-linux.elf-fold.h
	modified:   powerpc-darwin.dylib-entry.h
	modified:   powerpc-darwin.macho-entry.h
	copied:     powerpc-darwin.dylib-entry.h -> powerpc-linux.elf-entry.h
	modified:   powerpc-linux.elf-fold.h
	modified:   powerpc-linux.kernel.vmlinux.h
	modified:   powerpc64le-linux.elf-fold.h
	modified:   src/amd64-win64.pep.S
	modified:   src/arch/powerpc/32/bxx.S
	modified:   src/arch/powerpc/32/lzma_d.S
	modified:   src/arch/powerpc/32/nrv2d_d.S
	modified:   src/arch/powerpc/32/nrv2e_d.S
	modified:   src/arch/powerpc/32/ppc_regs.h
	modified:   src/arch/powerpc/64le/bxx.S
	modified:   src/arch/powerpc/64le/lzma_d.S
	modified:   src/arch/powerpc/64le/nrv2b_d.S
	modified:   src/arch/powerpc/64le/nrv2d_d.S
	modified:   src/arch/powerpc/64le/nrv2e_d.S
	modified:   src/arm.v4a-linux.elf-fold.S
	modified:   src/powerpc-darwin.macho-fold.S
	modified:   src/powerpc-linux.elf-entry.S
	modified:   src/powerpc-linux.elf-fold.S
	modified:   src/powerpc64le-darwin.dylib-entry.S
	modified:   src/powerpc64le-darwin.macho-entry.S
	modified:   src/powerpc64le-darwin.macho-fold.S
	modified:   src/powerpc64le-linux.elf-entry.S
	modified:   src/powerpc64le-linux.elf-fold.S
	modified:   src/powerpc64le-linux.kernel.vmlinux.S
	modified:   tmp/amd64-win64.pep.bin.dump
	modified:   tmp/arm.v4a-linux.elf-fold.map
	modified:   tmp/arm.v5a-linux.elf-fold.map
	modified:   tmp/armeb.v4a-linux.elf-fold.map
	modified:   tmp/powerpc-darwin.dylib-entry.bin.dump
	modified:   tmp/powerpc-darwin.macho-entry.bin.dump
	modified:   tmp/powerpc-linux.elf-entry.bin.dump
	modified:   tmp/powerpc-linux.elf-fold.map
	modified:   tmp/powerpc-linux.kernel.vmlinux.bin.dump
2017-03-01 08:14:13 -08:00
John Reiser 8c6133c115 Decompression stubs for arm64-linux (aarch)
modified:   stub/Makefile
	modified:   stub/arm64-darwin.macho-entry.h
	modified:   stub/arm64-darwin.macho-fold.h
	new file:   stub/arm64-linux.elf-entry.h
	new file:   stub/arm64-linux.elf-fold.h
	modified:   stub/scripts/xstrip.py
	modified:   stub/src/arch/arm64/v8/macros.S
	modified:   stub/src/arch/arm64/v8/nrv2b_d8.S
	modified:   stub/src/arch/arm64/v8/nrv2d_d8.S
	modified:   stub/src/arch/arm64/v8/nrv2e_d8.S
	new file:   stub/src/arm64-linux.elf-entry.S
	new file:   stub/src/arm64-linux.elf-fold.S
	new file:   stub/src/arm64-linux.elf-fold.lds
	new file:   stub/src/arm64-linux.elf-main.c
	modified:   stub/src/include/linux.h
2017-03-01 05:47:03 -08:00
John Reiser 483db31acd arm: Preserve 8-byte alignment of stack pointer
https://github.com/upx/upx/issues/60  (partial)
	modified:   stub/src/arm.v4a-linux.elf-fold.S

	modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/arm.v4a-linux.elf-fold.h
	modified:   stub/arm.v5a-linux.elf-fold.h
	modified:   stub/armeb.v4a-linux.elf-fold.h
	modified:   stub/tmp/arm.v4a-linux.elf-fold.map
	modified:   stub/tmp/arm.v5a-linux.elf-fold.map
	modified:   stub/tmp/armeb.v4a-linux.elf-fold.map
2017-02-14 20:36:45 -08:00
John Reiser 35dae3dab7 PowerPC 32-bit lzma stub defends against omitted linkage area.
https://github.com/upx/upx/issues/60
	modified:   stub/src/arch/powerpc/32/lzma_d.S
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S

	modified:   stub/powerpc-darwin.dylib-entry.h
	modified:   stub/powerpc-darwin.macho-entry.h
 [WTF?]	copied:     stub/powerpc-darwin.dylib-entry.h -> stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc-linux.kernel.vmlinux.h

	modified:   stub/tmp/powerpc-linux.elf-fold.map
	modified:   stub/tmp/powerpc-darwin.dylib-entry.bin.dump
	modified:   stub/tmp/powerpc-darwin.macho-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.kernel.vmlinux.bin.dump

	modified:   ../.github/travis_testsuite_1.sh
2017-02-12 16:23:57 -08:00
John Reiser 8232aedf78 unpackExtent() segregates rewrite() from write()
Fix the reported output file size when un-compressing.
Part of https://github.com/upx/upx/issues/60
	modified:   p_lx_elf.cpp
	modified:   p_unix.cpp
	modified:   p_unix.h
2017-02-11 15:26:27 -08:00
László Molnár d30a0a2e67 updated filter invocation in win64/pe 2017-02-06 14:31:16 +01:00
John Reiser d913fe508f Remove debugging jig
modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/tmp/powerpc-linux.elf-fold.map
2017-02-05 15:41:52 -08:00
John Reiser 4029903301 Sync testsuite
modified:   ../.github/travis_testsuite_1.sh
2017-02-05 15:14:11 -08:00
John Reiser 5db7e826d3 Find and use AT_PAGESZ; forward from -entry to -fold.
Cleanup the runtime choice of PAGE_SIZE 4K or 64K
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/src/arch/powerpc/32/ppc_regs.h
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-fold.map
2017-02-05 15:02:31 -08:00
John Reiser 7f3e7da7c7 Stubs LZMA_DEC00 and LZMA_ELF00 fall through; no "+80C" alignment.
https://github.com/upx/upx/issues/60  (partial)
addStubEntrySections() and getDecompressorSections()
	modified:   p_lx_elf.cpp
	modified:   p_mach.cpp
	modified:   packer_c.cpp
2017-02-05 14:52:09 -08:00
John Reiser 93cefde8fc Allow __PAGEZERO.vmsize to be 0x1000 on x86_64, as for "go"-language.
https://github.com/upx/upx/issues/59
	modified:   p_mach.cpp
	modified:   p_mach.h
2017-02-05 14:50:08 -08:00
John Reiser 02e7981e10 Merge and fix conflics
Conflicts:
	src/stub/src/arch/powerpc/64le/lzma_d.S
	src/stub/src/powerpc64le-darwin.dylib-entry.S
	src/stub/src/powerpc64le-darwin.macho-entry.S
	src/stub/src/powerpc64le-linux.elf-entry.S
	src/stub/src/powerpc64le-linux.kernel.vmlinux.S

	modified:   stub/src/arch/powerpc/32/lzma_d.S
2017-02-05 14:41:15 -08:00
John Reiser 0ecec10af0 Sync stubs and testsuite.
modified:   ../.github/travis_testsuite_1.sh
	modified:   stub/powerpc-linux.elf-entry.h
2017-02-05 14:26:18 -08:00
John Reiser 00b8cba987 typos
modified:   stub/src/powerpc-linux.elf-entry.S
2017-02-05 14:18:05 -08:00
John Reiser 8486bff918 PowerPC compare instructions: make cr0 explicit, put width ('w' or 'd') into mnemonic.
Easier to understand, caught a couple bugs in width.
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.kernel.vmlinux.h
	modified:   stub/src/arch/powerpc/32/bxx.S
	modified:   stub/src/arch/powerpc/32/nrv2d_d.S
	modified:   stub/src/arch/powerpc/32/nrv2e_d.S
	modified:   stub/src/arch/powerpc/64le/bxx.S
	modified:   stub/src/arch/powerpc/64le/lzma_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2b_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2d_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2e_d.S
	modified:   stub/src/powerpc-darwin.macho-fold.S
	modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.kernel.vmlinux.S
2017-02-05 14:00:19 -08:00
John Reiser 5305eb5b8a Sync stubs
modified:   stub/amd64-darwin.dylib-entry.h
	modified:   stub/amd64-darwin.macho-entry.h
	modified:   stub/amd64-darwin.macho-fold.h
	modified:   stub/amd64-linux.elf-fold.h
	modified:   stub/amd64-linux.shlib-init.h
	modified:   stub/amd64-win64.pep.h
	modified:   stub/powerpc-linux.elf-entry.h
	modified:   stub/powerpc-linux.elf-fold.h
	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.kernel.vmlinux.h
	modified:   stub/src/arch/powerpc/64le/lzma_d.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.kernel.vmlinux.S
	modified:   stub/tmp/amd64-win64.pep.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-entry.bin.dump
	modified:   stub/tmp/powerpc-linux.elf-fold.map
2017-02-05 13:37:01 -08:00
John Reiser 377a3bb7de More register definitions
modified:   stub/src/arch/powerpc/32/ppc_regs.h
2017-02-05 13:32:54 -08:00
John Reiser 5a47e8d2c6 Find and use AT_PAGESZ
modified:   stub/src/powerpc-linux.elf-entry.S
	modified:   stub/src/powerpc-linux.elf-fold.S
2017-02-05 13:31:17 -08:00
John Reiser 71f4cd7c85 Fix register usage conventions for amd64 unfilter
modified:   stub/src/amd64-win64.pep.S
	modified:   stub/src/arch/amd64/bxx.S
2017-02-05 13:29:59 -08:00
John Reiser f7751684af Stubs LZMA_DEC00 and LZMA_ELF00 fall through; no "+80C" alignment.
addStubEntrySections() and getDecompressorSections()
	modified:   p_lx_elf.cpp
	modified:   p_mach.cpp
	modified:   packer_c.cpp
2017-02-05 13:26:02 -08:00
John Reiser 59df1d39b2 Merge pull request #61 from tfauck/devel-thf
Following #51 pull with rerequested changes
2017-02-04 09:10:24 -08:00
John Reiser 7e5933e6a0 Merge branch 'devel' into devel-thf 2017-02-04 08:42:10 -08:00
John Reiser 2cefd34bb7 Allow __PAGEZERO.vmsize to be 0x1000 on x86_64, as for "go"-language.
https://github.com/upx/upx/issues/59
	modified:   p_mach.cpp
	modified:   p_mach.h
2017-02-03 15:12:40 -08:00
Thierry Fauck eac891dc3a Typo in .bss bzeroing
Rebuild of powerpc64le stubs

Signed-off-by: Thierry Fauck <tfauck@free.fr>

	modified:   stub/powerpc64le-darwin.dylib-entry.h
	modified:   stub/powerpc64le-darwin.macho-entry.h
	modified:   stub/powerpc64le-linux.elf-entry.h
	modified:   stub/powerpc64le-linux.elf-fold.h
	modified:   stub/powerpc64le-linux.kernel.vmlinux.h
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.elf-main.c
	modified:   stub/tmp/powerpc64le-linux.elf-fold.map
2017-02-03 10:57:05 +01:00
Thierry Fauck abd3599408 Explicitely specify cmp instructions to be 32 bits or 64bits on powerpc
(Thanks to John Reiser).

Signed-off-by: Thierry Fauck <tfauck@free.fr>

	modified:   src/arch/powerpc/32/bxx.S
	modified:   src/arch/powerpc/32/lzma_d.S
	modified:   src/arch/powerpc/64le/bxx.S
	modified:   src/arch/powerpc/64le/lzma_d.S
	modified:   src/arch/powerpc/64le/nrv2b_d.S
	modified:   src/arch/powerpc/64le/nrv2d_d.S
	modified:   src/arch/powerpc/64le/nrv2e_d.S
	modified:   src/powerpc64le-darwin.dylib-entry.S
	modified:   src/powerpc64le-darwin.macho-entry.S
	modified:   src/powerpc64le-darwin.macho-fold.S
	modified:   src/powerpc64le-linux.elf-entry.S
	modified:   src/powerpc64le-linux.elf-fold.S
	modified:   src/powerpc64le-linux.kernel.vmlinux.S
2017-02-03 10:55:14 +01:00
John Reiser 1bcd259c00 Merge branch 'devel' of https://github.com/upx/upx into devel 2017-02-01 17:17:31 -08:00
Thierry Fauck c4e835266c Typo in .bss bzeroing
Signed-off-by: Thierry Fauck <tfauck@free.fr>

	modified:   src/stub/powerpc64le-linux.elf-fold.h
	modified:   src/stub/src/powerpc64le-linux.elf-fold.S
	modified:   src/stub/src/powerpc64le-linux.elf-main.c
	modified:   src/stub/tmp/powerpc64le-linux.elf-fold.map
2017-01-30 18:53:34 +01:00
Thierry Fauck 685953f6a5 Explicitely specify cmp instructions to be 32 bits or 64bits on powerpc
Signed-off-by: Thierry Fauck <tfauck@free.fr>

	modified:   stub/src/arch/powerpc/32/bxx.S
	modified:   stub/src/arch/powerpc/64le/bxx.S
	modified:   stub/src/arch/powerpc/64le/lzma_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2b_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2d_d.S
	modified:   stub/src/arch/powerpc/64le/nrv2e_d.S
	modified:   stub/src/powerpc64le-darwin.dylib-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-entry.S
	modified:   stub/src/powerpc64le-darwin.macho-fold.S
	modified:   stub/src/powerpc64le-linux.elf-entry.S
	modified:   stub/src/powerpc64le-linux.elf-fold.S
	modified:   stub/src/powerpc64le-linux.kernel.vmlinux.S
2017-01-30 00:34:45 +01:00
John Reiser 03fffbc724 Re-base to upx-3.93
modified:   src/stub/src/arch/amd64/bxx.S
2017-01-29 06:58:03 -08:00
Markus F.X.J. Oberhumer e1a8c932ee Cleanup snprintf.cpp. 2017-01-29 14:11:46 +01:00
Markus F.X.J. Oberhumer 1aa2a6b054 Add missing src/stub/tmp/*.map files to repo. 2017-01-29 14:10:12 +01:00
Markus F.X.J. Oberhumer 1ad96c9c81 Update testsuite checksums caused by version bump. 2017-01-29 14:08:02 +01:00
Markus F.X.J. Oberhumer f69199909f Post-release version bump. 2017-01-29 14:05:00 +01:00
John Reiser d063e77040 Update checksums for testsuite.
modified:   .github/travis_testsuite_1.sh
2017-01-29 14:01:57 +01:00
John Reiser bf3ddeb1eb Rebuild stubs.
modified:   amd64-darwin.dylib-entry.h
	modified:   amd64-darwin.macho-entry.h
	modified:   amd64-darwin.macho-fold.h
	modified:   amd64-linux.elf-fold.h
	modified:   amd64-linux.kernel.vmlinux.h
	modified:   amd64-linux.shlib-init.h
	modified:   amd64-win64.pep.h
	modified:   i386-bsd.elf-entry.h
	modified:   i386-bsd.elf.execve-entry.h
	modified:   i386-darwin.dylib-entry.h
	modified:   i386-darwin.macho-entry.h
	modified:   i386-dos32.djgpp2.h
	modified:   i386-dos32.tmt.h
	modified:   i386-dos32.watcom.le.h
	modified:   i386-linux.elf-entry.h
	modified:   i386-linux.elf.execve-entry.h
	modified:   i386-linux.elf.interp-entry.h
	modified:   i386-linux.kernel.vmlinux.h
	modified:   i386-linux.kernel.vmlinuz.h
	modified:   i386-linux.shlib-init.h
	modified:   i386-netbsd.elf-entry.h
	modified:   i386-win32.pe.h
	modified:   tmp/amd64-darwin.dylib-entry.bin.dump
	modified:   tmp/amd64-darwin.macho-entry.bin.dump
	modified:   tmp/amd64-linux.shlib-init.bin.dump
	modified:   tmp/amd64-win64.pep.bin.dump
2017-01-29 14:01:57 +01:00
John Reiser fc261ad8cd Smaller by 7 bytes; also slower.
https://github.com/upx/upx/issues/43
	modified:   bxx.S
2017-01-29 14:01:56 +01:00
John Reiser 90fc018295 Avoid sigsegv after "patchelf --set-rpath"
https://github.com/upx/upx/issues/47
Enhancement not yet implemented: non-adjacent ElfXX_Ehdr and ElfXX_Phdr.
	modified:   p_unix.cpp
2017-01-29 14:01:56 +01:00
John Reiser cdc01d9a69 linux.sh/i386 interpreter.e_machine must be EM_386; else execve()
https://github.com/upx/upx/issues/53
	modified:   stub/i386-linux.elf.shell-fold.h
	modified:   stub/src/i386-linux.elf.shell-fold.S
	modified:   stub/src/i386-linux.elf.shell-main.c
2017-01-29 14:01:56 +01:00
John Reiser da7e76c07d Document location of checksums for testsuite.
modified:   Makefile
2017-01-29 14:01:56 +01:00
John Reiser ba9118aa58 Bug in unfilter on x86* when region ends in 32-bit displacement.
https://github.com/upx/upx/issues/43
	modified:   stub/src/arch/amd64/bxx.S
	modified:   stub/src/arch/i386/macros.S
	plus all the stubs that use them
2017-01-29 14:01:56 +01:00
Markus F.X.J. Oberhumer fdce705e55 Bump release date. 2017-01-29 12:07:00 +01:00
Markus F.X.J. Oberhumer 81268e7064 Update Travis. 2017-01-28 23:29:12 +01:00
Markus F.X.J. Oberhumer f502f41359 Update conf.h. 2017-01-28 22:39:42 +01:00
Markus F.X.J. Oberhumer 34c9cfb6b0 Don't use "long". 2017-01-28 22:39:42 +01:00
Markus F.X.J. Oberhumer 6da1790c46 New ACC version. 2017-01-28 22:39:42 +01:00
Markus F.X.J. Oberhumer d333c940da Update Travis. 2017-01-17 01:59:13 +01:00
Markus F.X.J. Oberhumer c940d2906f Mention win64/pe in help usage text. 2017-01-17 01:56:58 +01:00
Markus F.X.J. Oberhumer ac4b51ba85 Update Travis. 2017-01-15 23:25:39 +01:00
Markus F.X.J. Oberhumer ea7a1ad2c7 Bump version date. 2017-01-15 15:51:33 +01:00
Markus F.X.J. Oberhumer 45ddd6a68d Enable wildcard expansion on newer mingw versions. 2017-01-15 15:47:53 +01:00
Markus F.X.J. Oberhumer acd99364e0 Update Travis. 2017-01-15 11:10:59 +01:00
Markus F.X.J. Oberhumer 14710dea55 Replace some negative enum constants with "static const unsigned" vars. 2017-01-03 12:57:10 +01:00
Markus F.X.J. Oberhumer 5d3be8da1d Silence a MSVC warning. 2017-01-03 12:37:35 +01:00
Markus F.X.J. Oberhumer 3026821f9f Update testsuite checksums caused by version bump. 2017-01-03 12:16:51 +01:00
Markus F.X.J. Oberhumer fba51dabd0 Bump UPX_VERSION_DATE. 2017-01-03 12:06:17 +01:00
Markus F.X.J. Oberhumer c4da5e81fa Welcome 2017. 2017-01-03 12:02:07 +01:00
Markus F.X.J. Oberhumer bc80d81432 Silence a bogus scan-build warning. 2016-12-30 23:59:31 +01:00
László Molnár 67797efead fixed relocation handling regression in win32/pe (issue #38) 2016-12-30 23:18:32 +01:00
László Molnár c7cb036536 fixed data corruption in import handling (issue #32,#34) 2016-12-30 21:31:50 +01:00
Markus F.X.J. Oberhumer 0ccbc5f139 Silence some bogus coverity warnings. 2016-12-21 19:03:01 +01:00
Markus F.X.J. Oberhumer 2a6bbcaf8f Fix a p_w64pep.cpp issue detected by coverity. 2016-12-21 19:01:55 +01:00
Markus F.X.J. Oberhumer d46a8438ba Remove unused option "--script=". 2016-12-19 23:44:10 +01:00
Markus F.X.J. Oberhumer cc9d19da19 Remove unused PackLinuxI386sep. 2016-12-19 23:29:42 +01:00
Markus F.X.J. Oberhumer 6e6aa6fd6d Update doc/Makefile. 2016-12-19 23:23:59 +01:00
Markus F.X.J. Oberhumer 61652a2989 Remove unused PackSolarisSparc. 2016-12-19 23:23:25 +01:00
Markus F.X.J. Oberhumer edd7503607 Update executable format constants. 2016-12-19 23:18:38 +01:00
Markus F.X.J. Oberhumer c9d6dab401 Remove unused p_elks.cpp. 2016-12-19 23:14:08 +01:00
Markus F.X.J. Oberhumer d303038bcb Remove unused p_vxd.h. 2016-12-19 23:12:05 +01:00
Markus F.X.J. Oberhumer 0a0e7c3b7c Remove unused p_w16ne.cpp. 2016-12-19 23:11:00 +01:00
Markus F.X.J. Oberhumer 0b4ac35bc9 Tune some MSVC warnings. 2016-12-19 22:57:43 +01:00
László Molnár c51864ca39 fixed TLS callback handling for PE64 2016-12-18 23:34:27 +01:00
John Reiser a1cabd5a68 Avoid warning C4805: '|': unsafe mix of type 'bool' and type 'unsigned int' in operation
modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2016-12-18 11:32:47 -08:00
John Reiser 9c1bc99d7a Avoid warning C4146: unary minus operator applied to unsigned type, result still unsigned
modified:   p_mach.cpp
2016-12-16 10:59:51 -08:00
Markus F.X.J. Oberhumer c05fedcb76 Update Travis. 2016-12-14 16:27:51 +01:00
Markus F.X.J. Oberhumer e11beeae4b Update testsuite checksums caused by version bump. 2016-12-11 18:31:01 +01:00
Markus F.X.J. Oberhumer 4749e0d71e Post-release version bump. 2016-12-11 17:50:03 +01:00
Markus F.X.J. Oberhumer 1c01b77a71 Bump release date. 2016-12-11 16:12:06 +01:00
Markus F.X.J. Oberhumer 1dd8ad3685 Remove outdated TODO file. 2016-12-11 15:58:43 +01:00
John Reiser d6f6350b54 Remove comment about PalmPilot; add MacOS; add future AArch64; add John
modified:   README
	modified:   README.1ST
2016-12-01 21:51:04 -08:00
Markus F.X.J. Oberhumer 4f3b85e604 Update NEWS. 2016-12-01 00:45:25 +01:00
Markus F.X.J. Oberhumer efd5bc24b0 Bump tentative release date. 2016-12-01 00:40:54 +01:00
Markus F.X.J. Oberhumer a1d5dfa1ac Update Travis. 2016-12-01 00:36:49 +01:00
Markus F.X.J. Oberhumer 597c2ba180 Add .github/ISSUE_TEMPLATE.md. 2016-12-01 00:34:28 +01:00
Markus F.X.J. Oberhumer 2c2fb1b70b Update Travis. 2016-11-24 14:27:49 +01:00
John Reiser fc1287659a de-tab (comments, too?)
modified:   stub/src/powerpc-darwin.macho-upxmain.c
2016-11-21 14:02:57 -08:00
John Reiser 1a76630594 Mention support for MacOS "Sierra"
modified:   NEWS
2016-11-21 08:30:34 -08:00
John Reiser 322f682d32 re-generate stub
modified:   powerpc-darwin.macho-upxmain.h
2016-11-21 08:26:08 -08:00
John Reiser 0e329336fc Merge branch 'devel' of https://github.com/upx/upx into devel 2016-11-21 08:23:05 -08:00
John Reiser b33bdabbb6 powerpc Mach-o cleanup
modified:   stub/powerpc-darwin.macho-upxmain.exe
	new file:   stub/src/powerpc-darwin.macho-upxmain.c
2016-11-21 08:22:09 -08:00
Markus F.X.J. Oberhumer 27d30121ab Bump tentative release date. 2016-11-20 15:07:46 +01:00
Markus F.X.J. Oberhumer 345278f309 Re-enable assertion in xstrip.py. 2016-11-20 15:07:46 +01:00
Markus F.X.J. Oberhumer 4953e77161 upx-clang-format -i linker.cpp linker.h 2016-11-20 14:20:36 +01:00
Markus F.X.J. Oberhumer 8d61e037f9 Cleanups. 2016-11-20 14:17:21 +01:00
Markus F.X.J. Oberhumer 33a51e69bf Update submodules. 2016-11-20 13:56:42 +01:00
Markus F.X.J. Oberhumer d5dd9bbf24 Update Travis. 2016-11-20 13:51:53 +01:00
Markus F.X.J. Oberhumer 8772e52513 Remove old cruft. 2016-11-20 13:51:53 +01:00
John Reiser 9e1631ad4f avoid null section name and zero alignment; enforce record === line
modified:   linker.cpp
	modified:   linker.h
2016-11-19 17:38:23 -08:00
John Reiser 134b829d59 prevent warning C4319: '~': zero extending 'const unsigned int' to 'upx_uint64_t' of greater size
modified:   linker.cpp
	modified:   p_lx_elf.cpp
	modified:   pefile.cpp
2016-11-19 16:46:01 -08:00
John Reiser 3df7d26101 propagate cpusubtype
modified:   p_mach.cpp
	modified:   p_mach.h
2016-11-14 05:06:29 -08:00
John Reiser cf56086f06 powerpc-darwin.macho-: remove debugging 'trap' :-)
modified:   stub/powerpc-darwin.macho-upxmain.exe
	modified:   stub/powerpc-darwin.macho-upxmain.h
	modified:   stub/src/powerpc-darwin.macho-upxsubr.S
2016-11-12 20:13:12 -08:00
John Reiser a72aca4379 powerpc (32-bit) works on MacOS using Sierra-compatible strategy.
modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   stub/powerpc-darwin.macho-entry.h
	modified:   stub/powerpc-darwin.macho-upxmain.exe
	modified:   stub/powerpc-darwin.macho-upxmain.h
	modified:   stub/src/powerpc-darwin.macho-entry.S
	modified:   stub/src/powerpc-darwin.macho-upxsubr.S
	modified:   stub/tmp/powerpc-darwin.macho-entry.bin.dump
2016-11-12 19:48:19 -08:00
John Reiser edb0b7519a Merge branch 'devel' of https://github.com/upx/upx into devel 2016-11-09 06:08:44 -08:00
Markus F.X.J. Oberhumer 3a3248c88c Merge pull request #24 from tfauck/devel
powerpc64le -fpic dynamically linked binary support
2016-11-09 10:57:33 +01:00
John Reiser 3f14b9dab7 LC_UNIXTHREAD in ::pass4
modified:   p_mach.cpp
2016-11-08 17:53:02 -08:00
Thierry Fauck b1c07c22ce powerpc64le -fpic dynamically linked binary support
Update stub for -fpic support
 Handle 64K page in p_lx_elf.cpp

Signed-off-by: Thierry Fauck <tfauck@free.fr>
2016-11-08 18:29:10 +01:00
John Reiser 3b2c411274 Work on 32-bit PowerPC
modified:   p_mach.cpp
	modified:   p_mach.h
2016-11-06 20:39:01 -08:00
John Reiser e418af1ccd Try to fix 32-bit PowerPC.
modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   stub/Makefile
	new file:   stub/powerpc-darwin.macho-upxmain.exe
	new file:   stub/powerpc-darwin.macho-upxmain.h
	new file:   stub/src/powerpc-darwin.macho-upxsubr.S
2016-11-06 17:59:16 -08:00
John Reiser 7dc004acb3 bug in other-endian ::canPack and ::canUnpack
modified:   p_mach.cpp
2016-11-05 14:02:51 -07:00
John Reiser 2635472896 more unpacking for Mach-o (pre-3.91 ?)
modified:   p_mach.cpp
	modified:   p_mach.h
2016-11-05 13:16:16 -07:00
John Reiser 5c0340f9ae Merge branch 'devel' of https://github.com/upx/upx into devel 2016-10-19 15:20:04 -07:00
John Reiser c2c970ee33 pacify c++-analyzer
modified:   p_lx_elf.cpp
2016-10-19 15:19:33 -07:00
Markus F.X.J. Oberhumer b52dabe091 Update Travis. 2016-10-19 15:21:40 +02:00
Markus F.X.J. Oberhumer 3fa2db8d6f Update testsuite checksum to match current version. UNTESTED. 2016-10-19 15:03:25 +02:00
Markus F.X.J. Oberhumer 1e7950f671 Rebuild src/stubs from current sources. UNTESTED. 2016-10-19 14:59:33 +02:00
Thierry Fauck 8fde05191a powerpc: Omit -Os flag to avoid use of savegrp*
Signed-off-by: Thierry Fauck <tfauck@free.fr>

	modified:   stub/Makefile
2016-10-19 14:41:18 +02:00
John Reiser 2557de6c4e amd64 changes for brk() fix. powerpc changes UNKNOWN!
Also, filename of expected checksums begins with dot.
	modified:   .github/travis_testsuite_1.sh
2016-10-16 07:31:26 -07:00
John Reiser 44328aee76 fix brk() problem when is_big: stub must munmap all_pages
https://github.com/upx/upx/issues/5
	modified:   p_lx_elf.cpp
	modified:   p_lx_elf.h
2016-10-15 14:06:56 -07:00
Markus F.X.J. Oberhumer f606b5879b Update Travis. 2016-10-11 22:33:45 +02:00
Markus F.X.J. Oberhumer 83607119df Merge pull request #14 from tfauck/powerpc-fixes
POWERPC: Allocate 4K / 64K pages depending on processor type.
2016-10-11 16:11:40 +02:00
Thierry Fauck 9b86e68268 POWERPC: Allocate 4K / 64K pages depending on processor type.
Powerpc: ppc64le processor - Fix nrv2x-d.S compression routines
xstrip - disallow assert at line 178

Signed-off-by: Thierry Fauck <tfauck@free.fr>

	modified:   powerpc-darwin.dylib-entry.h
	modified:   powerpc-darwin.macho-entry.h
	modified:   powerpc-darwin.macho-fold.h
	modified:   powerpc-linux.elf-entry.h
	modified:   powerpc-linux.elf-fold.h
	modified:   powerpc-linux.kernel.vmlinux.h
	modified:   powerpc64le-darwin.dylib-entry.h
	modified:   powerpc64le-darwin.macho-entry.h
	modified:   powerpc64le-darwin.macho-fold.h
	modified:   powerpc64le-linux.elf-entry.h
	modified:   powerpc64le-linux.elf-fold.h
	modified:   powerpc64le-linux.kernel.vmlinux.h
	modified:   scripts/xstrip.py
	modified:   src/arch/powerpc/64le/nrv2b_d.S
	modified:   src/arch/powerpc/64le/nrv2d_d.S
	modified:   src/arch/powerpc/64le/nrv2e_d.S
	modified:   src/powerpc-linux.elf-entry.S
	modified:   src/powerpc-linux.elf-fold.S
	modified:   src/powerpc-linux.elf-main.c
	modified:   tmp/powerpc-linux.elf-entry.bin.dump
	modified:   tmp/powerpc64le-darwin.dylib-entry.bin.dump
	modified:   tmp/powerpc64le-darwin.macho-entry.bin.dump
	modified:   tmp/powerpc64le-linux.elf-entry.bin.dump
	modified:   tmp/powerpc64le-linux.kernel.vmlinux.bin.dump
2016-10-11 09:52:40 -04:00
John Reiser d688a05ac7 DT_JMPREL vanished (binutils-2.26.1); check all DT_RELA.
modified:   p_elf_enum.h
	modified:   p_lx_elf.cpp
2016-10-09 21:50:45 -07:00
Markus F.X.J. Oberhumer 97e975b4f6 Update Travis so that is works with bash 3 again. 2016-10-09 19:53:04 +02:00
John Reiser 9dd0e3ce4f c++-analyzer finds the speck but misses the log.
modified:   p_mach.cpp
2016-10-09 09:34:33 -07:00
John Reiser ca2293f6d3 c++-analyzer needs improved range tracking.
modified:   p_lx_elf.cpp
2016-10-09 09:33:35 -07:00
Markus F.X.J. Oberhumer 0cd1ef0c7a Update Travis for OSX. 2016-10-09 13:56:45 +02:00
Markus F.X.J. Oberhumer b0207ce524 Some refactoring. NFC. 2016-10-09 13:23:19 +02:00
Markus F.X.J. Oberhumer fab0c3b09d testsuite: rename tests. 2016-10-09 13:00:43 +02:00
Markus F.X.J. Oberhumer 8b35dd3358 testsuite: allow easy updating of the checksums by writing .sha256sums.recreate. 2016-10-09 12:36:22 +02:00
László Molnár cadcbb27eb travis checksums updated 2016-10-09 12:13:22 +02:00
László Molnár 297d44c614 PE: fixed file data alignment problem 2016-10-09 11:29:29 +02:00
Markus F.X.J. Oberhumer 22178f2224 Minor cleanups. 2016-10-09 03:12:19 +02:00
Markus F.X.J. Oberhumer 554f8a376c Update testsuite for previous commit. 2016-10-09 03:00:49 +02:00
Markus F.X.J. Oberhumer 4157affbd7 pefile: make kernelDLL() return the same strings as in UPX 3.91. 2016-10-09 02:53:20 +02:00
Markus F.X.J. Oberhumer 4b991203df pefile.cpp: make import sorting independent from qsort() internals. 2016-10-09 00:48:40 +02:00
Markus F.X.J. Oberhumer 38a265741c Ongoing cleanups. 2016-10-08 18:49:14 +02:00
Markus F.X.J. Oberhumer 56eb02280f Update Travis. 2016-10-07 23:07:25 +02:00
Markus F.X.J. Oberhumer ed900b0476 More thorough use of O_BINARY. 2016-10-07 15:04:12 +02:00
John Reiser 42206364e5 Reduce Mach-o headers
modified:   p_mach.cpp
2016-10-06 16:06:24 -07:00
John Reiser 82d9bb8f51 Fix namespace typedefs for Mach-o structs [upx_uint32_t ==> Word]
modified:   p_mach.cpp
	modified:   p_mach.h
2016-10-06 14:00:05 -07:00
John Reiser 923a9d3f9b Template PackMackBase<T>::pack3. Use more templates for ::pack4.
modified:   p_mach.cpp
	modified:   p_mach.h
2016-10-06 08:55:09 -07:00
John Reiser ae7660068b Merge branch 'devel' of https://github.com/upx/upx into devel 2016-10-06 07:49:52 -07:00
John Reiser f466c1d764 Cosmetic
modified:   p_mach.cpp
2016-10-06 07:49:37 -07:00
Markus F.X.J. Oberhumer 6e76f8ef3a Don't use variable length arrays (VLA). 2016-10-06 13:04:46 +02:00
Markus F.X.J. Oberhumer b3a8d02caf Cosmetic cleanups. 2016-10-06 12:31:03 +02:00
Markus F.X.J. Oberhumer 022ba32c1a Improve robustness of seek() by adding some sanity checks. 2016-10-06 12:11:32 +02:00
Markus F.X.J. Oberhumer 8f5e89c900 Update testsuite. 2016-10-06 11:19:31 +02:00
Markus F.X.J. Oberhumer d335d7bafd p_mach.h: fix C++ syntax. 2016-10-06 09:51:58 +02:00
John Reiser 1f51ef7df6 Merge branch 'devel' of https://github.com/upx/upx into devel 2016-10-05 17:16:53 -07:00
Markus F.X.J. Oberhumer ec082ee023 Cosmetic cleanup. 2016-10-06 00:45:42 +02:00
Markus F.X.J. Oberhumer a6bc271e0d Update testsuite. 2016-10-06 00:43:54 +02:00
John Reiser 791fd9199e Preserve alignment in .text
modified:   p_mach.cpp
2016-10-05 12:52:52 -07:00
John Reiser 9e8baf1914 i386 for MacOS 10.12 "Sierra"
modified:   p_mach.cpp
	modified:   stub/i386-darwin.macho-entry.h
	modified:   stub/src/i386-darwin.macho-entry.S
	modified:   stub/tmp/i386-darwin.macho-entry.bin.dump
2016-10-05 11:25:16 -07:00
John Reiser 64b7080532 Merge branch 'devel' of https://github.com/upx/upx into devel 2016-10-04 21:05:44 -07:00
John Reiser 8fd5479f32 Templates for ::pack4; i386 now packs, needs work before running.
modified:   p_mach.cpp
	modified:   p_mach.h
	new file:   stub/i386-darwin.macho-upxmain.exe
	new file:   stub/i386-darwin.macho-upxmain.h
	new file:   stub/src/i386-darwin.macho-upxmain.c
2016-10-04 19:58:04 -07:00
Markus F.X.J. Oberhumer 04eb9c02c3 Update testsuite checksums to match recent changes. Sigh. 2016-10-05 01:35:45 +02:00
John Reiser 07b41b9bc3 i386-darwin.macho-upxmain.h
modified:   Makefile
2016-10-04 10:48:44 -07:00
John Reiser 8ebadfafe9 Standalone bswap, bzero, syscalls for i386-darwin.macho
new file:   i386-darwin.macho-upxsubr.S
2016-10-04 10:46:59 -07:00
John Reiser 3283896e4b Templatize ::buildLoader
modified:   p_mach.cpp
	modified:   p_mach.h
2016-10-04 08:54:55 -07:00
John Reiser b444bcf418 On the way to templates and mach-o/i386.
modified:   p_mach.cpp
	modified:   p_mach.h
2016-10-03 22:00:26 -07:00
Markus F.X.J. Oberhumer 13034577fc Fix previous commit. 2016-10-04 00:56:01 +02:00
Markus F.X.J. Oberhumer 9feefc2e7f Makefile: added run-testsuite target. 2016-10-04 00:42:24 +02:00
John Reiser a5393e985d Merge branch 'devel' of https://github.com/upx/upx into devel 2016-10-03 09:42:48 -07:00
John Reiser e3fe0dc89b Avoid bug in ld-linux to set brk(0) when .p_align is large.
modified:   p_lx_elf.cpp
2016-10-03 09:41:05 -07:00
Markus F.X.J. Oberhumer 42d49e9d50 Update Makefile and check_whitespace.sh. 2016-10-03 13:13:13 +02:00
Markus F.X.J. Oberhumer 06eb244800 Add check_whitespace_git.sh. Minor cleanups. 2016-10-03 04:47:02 +02:00
John Reiser 870cdfa51f Merge branch 'devel' of https://github.com/upx/upx into devel 2016-10-02 10:47:59 -07:00
John Reiser 93787c74ee Rewrite linfo in output file.
modified:   p_mach.cpp
2016-10-02 10:47:37 -07:00
Markus F.X.J. Oberhumer 945323fe15 Fix a compilation warning. 2016-10-02 15:54:14 +02:00
Markus F.X.J. Oberhumer 5e41e69b27 Remove trailing whitespace from p_mach.cpp. 2016-10-02 15:48:56 +02:00
Markus F.X.J. Oberhumer 9d14185f7d Add check_whitespace.sh and call it from Makefile. Update Travis. 2016-10-02 15:46:57 +02:00
John Reiser 0f74162551 Decompression works after codesign. (Still more is possible.)
modified:   p_mach.cpp
2016-10-01 20:38:25 -07:00
John Reiser 00b1ff1ff6 Apple codesign now works.
modified:   p_mach.cpp
2016-10-01 17:40:32 -07:00
John Reiser 977024ea94 Fix clang scan-build errors.
modified:   p_lx_elf.cpp
2016-10-01 17:38:16 -07:00
Markus F.X.J. Oberhumer 3534ed21d7 Update Travis and AppVeyor. 2016-10-01 20:00:48 +02:00
Markus F.X.J. Oberhumer ee093e5232 Minor cleanups. 2016-10-01 19:59:10 +02:00
Markus F.X.J. Oberhumer 807ab8d19f Update Travis and AppVeyor. 2016-09-29 09:54:07 +02:00
Markus F.X.J. Oberhumer 81f3ff098f Update download links to point to github. 2016-09-29 00:37:11 +02:00
Markus F.X.J. Oberhumer 85a5759afb Update AppVeyor to also run the testsuite. 2016-09-29 00:18:22 +02:00
Markus F.X.J. Oberhumer 490e7a56a5 Remove travis_testsuite_2.sh. 2016-09-28 23:02:06 +02:00
Markus F.X.J. Oberhumer e41c475671 Use calloc instead of malloc to pacify valgrind. 2016-09-28 21:30:38 +02:00
Markus F.X.J. Oberhumer b0841268bd Update Travis testsuite. 2016-09-28 20:18:05 +02:00
Markus F.X.J. Oberhumer b9b3b67b95 Silence some pedantic compilation warnings about unused results. 2016-09-28 13:50:50 +02:00
Markus F.X.J. Oberhumer 0d57d2cfe3 Remove old cruft. 2016-09-28 13:39:49 +02:00
Markus F.X.J. Oberhumer 32de5d0d7f Fix msvc build. 2016-09-28 13:34:39 +02:00
Markus F.X.J. Oberhumer 51eab2a4b7 Update Makefile configuration variables. 2016-09-28 13:07:39 +02:00
Markus F.X.J. Oberhumer 93cf170253 Update NEWS. 2016-09-28 12:31:44 +02:00
Markus F.X.J. Oberhumer f7554374ab Update email address. 2016-09-28 12:25:01 +02:00
Markus F.X.J. Oberhumer b4870f62c9 Add option --prefer-ucl. 2016-09-28 11:57:15 +02:00
Markus F.X.J. Oberhumer f1d713ebf6 Silence some pedantic warnings. 2016-09-28 11:29:20 +02:00
Markus F.X.J. Oberhumer 4134a512b9 Update Travis. 2016-09-28 11:13:46 +02:00
Markus F.X.J. Oberhumer cf998f945c Add support for AppVeyor CI. 2016-09-27 20:30:54 +02:00
Markus F.X.J. Oberhumer a7386238dd Update Travis. 2016-09-27 20:29:04 +02:00
Markus F.X.J. Oberhumer 6b39d122a6 Support MSVC. 2016-09-27 20:23:23 +02:00
Markus F.X.J. Oberhumer a0582c5380 pefile.cpp: don't use VLA. 2016-09-27 20:19:43 +02:00
Markus F.X.J. Oberhumer 1f37112969 Moving to github. 2016-09-27 08:41:11 +02:00
Markus F.X.J. Oberhumer 361958db76 Check endian in assertPacker(). 2016-09-26 15:38:04 +02:00
Markus F.X.J. Oberhumer 8bc7880b19 Improve gitrev handling. 2016-09-26 15:32:01 +02:00
Markus F.X.J. Oberhumer ceddf29586 Update Travis. 2016-09-26 15:32:01 +02:00
Markus F.X.J. Oberhumer 3fc78e21bc Stop using Circle CI. 2016-09-26 15:31:49 +02:00
John Reiser 48e00b371c Move UPX_F_MACH_PPC64LE and friends to 38 et seq, the little-endian side.
modified:   conf.h
2016-09-26 05:53:11 -07:00
Markus F.X.J. Oberhumer aee52d3880 Improve gitrev handling. 2016-09-26 10:35:29 +02:00
Markus F.X.J. Oberhumer bd54499537 Update Travis. 2016-09-26 10:07:48 +02:00
Markus F.X.J. Oberhumer e6da9e8d1a Small snprintf.cpp update. 2016-09-26 09:12:53 +02:00
Markus F.X.J. Oberhumer 156ca03b67 Silence some pedantic compiler warnings. 2016-09-26 09:12:53 +02:00
Markus F.X.J. Oberhumer 3f4419b177 Update stub/src for recent changes. 2016-09-26 09:12:53 +02:00
Markus F.X.J. Oberhumer 676f860d7d Normalize whitespace. 2016-09-26 09:12:53 +02:00
Markus F.X.J. Oberhumer 5ce93ae0c7 Update submodules. 2016-09-26 09:12:53 +02:00
László Molnár 43231826b9 fixed address sanitizer problem (untested) 2016-09-26 08:56:23 +02:00
Markus F.X.J. Oberhumer 899b393fcc Add support for Circle CI. 2016-09-25 17:18:29 +02:00
Markus F.X.J. Oberhumer 5c3e02d2f0 Update Travis CI. 2016-09-25 17:17:14 +02:00
Markus F.X.J. Oberhumer a29064107e Bump version date. 2016-09-25 14:01:40 +02:00
Markus F.X.J. Oberhumer 4cdc969801 Update Travis. 2016-09-25 14:00:49 +02:00
Markus F.X.J. Oberhumer 68159d457e Update Travis. 2016-09-25 09:43:30 +02:00
Markus F.X.J. Oberhumer daafc29d2b Add support for UPX_VERSION_GITREV. Some cleanups. 2016-09-25 09:41:26 +02:00
John Reiser 3c786acf2b Fix bug in Mach-O stub.
modified:   amd64-darwin.macho-upxmain.exe
	modified:   amd64-darwin.macho-upxmain.h
	modified:   src/amd64-darwin.macho-upxmain.c
2016-09-24 19:44:00 -07:00
John Reiser 53c3817d4d Allow longer Mach-O headers.
modified:   amd64-darwin.macho-upxmain.exe
2016-09-24 17:26:00 -07:00
John Reiser 9109254488 Allow longer Mach-O headers.
modified:   src/amd64-darwin.macho-upxmain.c
2016-09-24 17:21:07 -07:00
John Reiser df19f0d5ec Try harder to decompress Mach-O I386, too.
modified:   p_mach.cpp
	modified:   p_mach.h
2016-09-24 09:15:10 -07:00
John Reiser 093362e479 Merge branch 'devel' of https://github.com/upx/upx into devel 2016-09-24 06:44:19 -07:00
John Reiser 7826a3652b Try harder to decompress Mach-O, because pirates.
modified:   p_mach.cpp
	modified:   p_mach.h
2016-09-24 06:43:16 -07:00
Markus F.X.J. Oberhumer c27b7e52e1 Small Makefile update. 2016-09-24 13:49:07 +02:00
Markus F.X.J. Oberhumer 6f79cbb2a6 Update Travis. 2016-09-24 12:53:01 +02:00
Markus F.X.J. Oberhumer 6f33929f91 Cleanups. 2016-09-24 12:10:46 +02:00
Markus F.X.J. Oberhumer 2e8b649195 Update Travis. 2016-09-24 11:19:12 +02:00
Markus F.X.J. Oberhumer 3841be7e20 Remove *.bin files. 2016-09-24 11:18:18 +02:00
John Reiser 2c28521283 NetBSDElf32x86 should not impersonate [i386-linux.elf, linux/i386] 2016-09-23 19:31:26 -07:00
László Molnár 1c735cc204 fixed too strict checks in resource handling 2016-09-22 22:17:08 +02:00
Markus F.X.J. Oberhumer f0b13ae8e4 Add .editorconfig. 2016-09-22 18:29:02 +02:00
Markus F.X.J. Oberhumer b1a2f8fec0 Update vim modelines. 2016-09-22 18:17:37 +02:00
Markus F.X.J. Oberhumer 83828aa8a3 Update vim modelines. 2016-09-22 17:29:43 +02:00
Markus F.X.J. Oberhumer 4eb81b4d66 Update stub/scripts. 2016-09-22 14:27:57 +02:00
Markus F.X.J. Oberhumer 96d9968db5 Welcome 2016. 2016-09-22 14:07:14 +02:00
Markus F.X.J. Oberhumer 2781e37ec0 Mark version as "BETA". 2016-09-22 14:05:08 +02:00
Markus F.X.J. Oberhumer 6d61e773b5 Bump version year. 2016-09-22 14:02:44 +02:00
Markus F.X.J. Oberhumer c5171114d1 Clean up stub/Makefile. NFC. 2016-09-22 13:11:14 +02:00
Markus F.X.J. Oberhumer 0ca0a832de stub: arm renaming. 2016-09-22 12:36:00 +02:00
Markus F.X.J. Oberhumer aef54a4bfd Update source for previous rename. 2016-09-22 12:12:43 +02:00
Markus F.X.J. Oberhumer 4c473acfec stub: arm renaming. 2016-09-22 12:05:53 +02:00
Markus F.X.J. Oberhumer 0de41e97ac Update source for previous rename. 2016-09-22 11:54:44 +02:00
Markus F.X.J. Oberhumer 0e52ab3f90 stub: arm renaming. 2016-09-22 11:52:50 +02:00
Markus F.X.J. Oberhumer 797679b42c stub: arm renaming. 2016-09-22 11:43:23 +02:00
Markus F.X.J. Oberhumer 1bc8b6f46e Update source for previous rename. 2016-09-22 11:29:12 +02:00
Markus F.X.J. Oberhumer f322b580ff stub: arm renaming. 2016-09-22 11:28:00 +02:00
Markus F.X.J. Oberhumer 2b2f33e3f5 Update source for previous rename. 2016-09-22 11:22:18 +02:00
Markus F.X.J. Oberhumer ce29cd2fad stub: arm renaming. 2016-09-22 11:20:53 +02:00
Markus F.X.J. Oberhumer 0d5843f44e Update source for previous rename. 2016-09-22 11:17:53 +02:00
Markus F.X.J. Oberhumer e36e8e3b33 stub: arm renaming. 2016-09-22 11:15:49 +02:00
Markus F.X.J. Oberhumer e251a1ca19 Update source for previous rename. 2016-09-22 11:11:03 +02:00
Markus F.X.J. Oberhumer 4aedb00e43 stub: arm renaming. 2016-09-22 11:06:53 +02:00
Markus F.X.J. Oberhumer 10a0469221 Update source for previous rename. 2016-09-22 10:56:33 +02:00
Markus F.X.J. Oberhumer d3419acada stub: start arm renaming. 2016-09-22 10:52:26 +02:00
Markus F.X.J. Oberhumer 65ea4117ca Add some comments to stub/Makefile in prepartion of renames. 2016-09-22 10:44:40 +02:00
Markus F.X.J. Oberhumer 8b0101dcab Update source for previous rename. 2016-09-22 10:25:45 +02:00
Markus F.X.J. Oberhumer 188f67cfca stub: rename ppc64le to powerpc64le. 2016-09-22 10:20:54 +02:00
Markus F.X.J. Oberhumer a89f4bd4b8 Update .gitignore. 2016-09-22 09:56:30 +02:00
Markus F.X.J. Oberhumer 053c9dc0e1 stub: arm64: rename some files, remove unused files. 2016-09-22 09:55:13 +02:00
Markus F.X.J. Oberhumer 493d9f1b9d Ongoing cleanups. 2016-09-22 03:23:55 +02:00
Markus F.X.J. Oberhumer e28793f128 upx-clang-format -i packhead.cpp 2016-09-22 00:59:48 +02:00
Markus F.X.J. Oberhumer ea2bddf245 Fix one more file_image usage. 2016-09-22 00:58:43 +02:00
Markus F.X.J. Oberhumer 763b3c05af Don't use "long". Cleanups. 2016-09-22 00:47:35 +02:00
Markus F.X.J. Oberhumer 473cfb54be Normalize whitespace. 2016-09-22 00:02:58 +02:00
Markus F.X.J. Oberhumer a7fd742c17 Canonicalize the names of our executable formats. 2016-09-21 23:58:08 +02:00
Markus F.X.J. Oberhumer b66ba140cb More cleanups. 2016-09-21 23:18:19 +02:00
Markus F.X.J. Oberhumer 242f606a29 p_lx_elf.h: turn file_image into a MemBuffer. 2016-09-21 22:22:41 +02:00
Markus F.X.J. Oberhumer 60a1214d7e upx-clang-format -i ui.cpp 2016-09-21 21:38:56 +02:00
Markus F.X.J. Oberhumer 189ab8c8e8 upx-clang-format -i ui.h 2016-09-21 21:35:13 +02:00
Markus F.X.J. Oberhumer 3765ca4e92 Cleanups and cruft removal. 2016-09-21 21:33:53 +02:00
Markus F.X.J. Oberhumer df87d76070 p_mach.cpp: use proper types for variable "zero". 2016-09-21 20:39:00 +02:00
Markus F.X.J. Oberhumer 8fbf0b406b p_vmlinx.cpp: remove unused code fragment. 2016-09-21 17:56:43 +02:00
Markus F.X.J. Oberhumer 633073803f upx-clang-format -i s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h 2016-09-21 17:46:42 +02:00
Markus F.X.J. Oberhumer 104da198d3 Minor screen cleanup. 2016-09-21 17:43:32 +02:00
Markus F.X.J. Oberhumer b3121e4534 Use upx_uint16_t instead of unsigned short. 2016-09-21 17:40:11 +02:00
Markus F.X.J. Oberhumer 3bb654cc85 Ongoing cleanups and cruft removal. 2016-09-21 16:42:25 +02:00
John Reiser d2830db94d Fix memory leak
modified:   p_lx_elf.cpp
2016-09-20 20:43:48 -07:00
John Reiser ad6914b938 PackMachBase<T>::canUnpack() finds overlay_offset for decompression
modified:   p_mach.cpp
	modified:   p_mach.h
2016-09-20 20:07:42 -07:00
Markus F.X.J. Oberhumer 57ba965b93 Add support for Travis CI. 2016-09-21 03:54:49 +02:00
Markus F.X.J. Oberhumer 544ec21fc2 Fix building with clang. 2016-09-21 01:09:07 +02:00
Markus F.X.J. Oberhumer 1bb0fa1809 Fix a few things spotted by the gcc-6 sanitizer. Needs review. 2016-09-21 00:35:51 +02:00
Markus F.X.J. Oberhumer ffa0efc898 Makefile: add support for USE_SANITIZE. 2016-09-21 00:34:52 +02:00
Markus F.X.J. Oberhumer af6b4b8c27 Fix previous commit. 2016-09-21 00:34:20 +02:00
Markus F.X.J. Oberhumer 3f7c1f966b Minor cleanups. 2016-09-20 22:14:25 +02:00
Markus F.X.J. Oberhumer 535515f296 Update submodules. 2016-09-20 22:13:07 +02:00
Markus F.X.J. Oberhumer 7af6c4b10e Use new style casts. Cleanups. 2016-09-20 20:59:34 +02:00
Markus F.X.J. Oberhumer 2076bef95b upx-clang-format -i stdcxx.cpp stdcxx.h ; remove old cruft. 2016-09-20 20:40:08 +02:00
John Reiser 48ce1f1814 Merge branch 'master' of https://github.com/upx/upx 2016-09-20 10:56:00 -07:00
John Reiser 5151c8a505 Indentation error detected by g++-6
modified:   p_lx_elf.cpp
2016-09-20 10:55:14 -07:00
Markus F.X.J. Oberhumer 44248f19b5 Introduce mem_size() and New() and start using it. 2016-09-20 15:24:07 +02:00
Markus F.X.J. Oberhumer 8d433f2580 Update submodules. 2016-09-20 15:09:50 +02:00
Markus F.X.J. Oberhumer 272fe5488c Remove Makefile fragment from p_vmlinx.cpp. 2016-09-20 13:06:24 +02:00
Markus F.X.J. Oberhumer c97765de14 upx-clang-format -i snprintf.cpp 2016-09-20 13:03:48 +02:00
Markus F.X.J. Oberhumer 7acf150ac5 Update README.SRC. 2016-09-20 12:51:06 +02:00
Markus F.X.J. Oberhumer 077bbdfc78 conf.h: check for proper WITH_LZMA. 2016-09-20 12:45:28 +02:00
Markus F.X.J. Oberhumer 2fb38ce13a Update Makefile for upx-lzma-sdk. 2016-09-20 12:37:00 +02:00
Markus F.X.J. Oberhumer 22dc183f25 Add upx-lzma-sdk submodule. 2016-09-20 12:35:15 +02:00
Markus F.X.J. Oberhumer 3c492c3fc7 Update Makefile so that my build scripts work again. 2016-09-20 11:29:28 +02:00
Markus F.X.J. Oberhumer d71db2978e Remove some old cruft. 2016-09-20 11:24:18 +02:00
Markus F.X.J. Oberhumer e4723e0bad Avoid some compiler warnings. 2016-09-20 10:54:27 +02:00
Markus F.X.J. Oberhumer dc56c4e530 bptr.h: size optimizations. 2016-09-20 10:30:09 +02:00
Markus F.X.J. Oberhumer 9579a51a8b pefile.cpp: always use BoundedPtr. 2016-09-20 10:20:42 +02:00
Markus F.X.J. Oberhumer 71f897ebf5 Avoid a -Wsign-compare warning. 2016-09-20 10:08:32 +02:00
Markus F.X.J. Oberhumer 09d9f71ae9 p_mach.h: use proper upx types. 2016-09-20 10:05:08 +02:00
John Reiser c678ccdfb1 stub/ppc64le-darwin.macho-fold.h is flapping (works one time, not the next.) 2016-09-19 21:25:30 -07:00
John Reiser bbbebe343b Try to recover powerpc64le. Still not successful [TOC space?]
modified:   Makefile
	new file:   ppc64-savegpr0.S
	modified:   ppc64le-darwin.macho-fold.h
2016-09-19 20:05:52 -07:00
John Reiser 033cb4f0c2 Fix merge
modified:   p_mach.cpp
2016-09-19 18:49:40 -07:00
John Reiser d750034b79 amd64-darwin.macho-upxmain.exe and .h 2016-09-19 18:32:26 -07:00
Markus F.X.J. Oberhumer a2063f0628 Normalize whitespace. 2016-09-20 02:06:58 +02:00
Markus F.X.J. Oberhumer acf2f2ffc4 Merge branch 'sierra' 2016-09-20 01:54:33 +02:00
Markus F.X.J. Oberhumer d14f484c4b Moving to github. 2016-09-19 22:41:32 +02:00
Markus F.X.J. Oberhumer 695e515a65 stub: update powerpc64le settings. 2016-09-19 22:22:21 +02:00
upstream 61089feee7 New ACC version. 2016-09-19 12:44:29 +00:00
Markus F.X.J. Oberhumer ddc9b10cd3 Add scripts/upx-clang-format. 2016-09-19 11:04:25 +02:00
Markus F.X.J. Oberhumer f95c92b431 Create a dummy stub/ppc64le-darwin.macho-fold.h so that upx builds again. 2016-09-19 10:54:23 +02:00
Markus F.X.J. Oberhumer eba65a94e6 Add missing *.dump files to repo. 2016-09-19 10:44:22 +02:00
John Reiser c28a0c6bb8 Synchronize stubs
modified:   src/stub/arm64-darwin.macho-entry.h
	modified:   src/stub/arm64-darwin.macho-fold.h
	modified:   src/stub/ppc64le-linux.elf-fold.h
	modified:   src/stub/tmp/arm64-darwin.macho-entry.bin.dump
2016-09-18 12:45:11 -07:00
Markus F.X.J. Oberhumer d6bacd9b47 Remove src/stub/scripts/UNUSED. 2016-09-18 16:07:47 +02:00
Markus F.X.J. Oberhumer 70b1657323 Update for upx-stubtools v20160918. 2016-09-18 16:00:29 +02:00
Markus F.X.J. Oberhumer 1ef08bd169 Add .gitignore. 2016-09-18 15:29:03 +02:00
Markus F.X.J. Oberhumer da68cc6a78 Remove .hgignore and .hgtags. 2016-09-18 15:00:53 +02:00
John Reiser 45c75d42ad Catch up to upxtools 20160902; add dangling arm/v8a/lzma_d.S 2016-09-17 19:51:32 -07:00
jreiser@BitWagon.com d4e55af2c2 Propagate LC_VERSION_MIN_MACOSX and LC_SOURCE_VERSION
changed src/p_mach.cpp
2016-09-17 16:40:07 -07:00
jreiser@BitWagon.com 48791a329d overlay_offset for decompress
changed src/p_mach.cpp
2016-09-17 16:16:41 -07:00
jreiser@BitWagon.com 9b26ebed75 LINKEDIT has unfilter and decompressor
changed src/p_mach.cpp
 changed src/stub/amd64-darwin.macho-upxmain.h
 changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-17 15:24:23 -07:00
jreiser@BitWagon.com e2160fb6c9 segLINK.initprot |= VM_PROT_EXECUTE
changed src/p_mach.cpp
2016-09-17 10:41:38 -07:00
jreiser@BitWagon.com 345a1c64f9 Omit Mach_command from stub where allowed.
changed src/p_mach.cpp
2016-09-17 09:36:58 -07:00
jreiser@BitWagon.com 7ad1e7756b Cleanup for checkin
changed src/p_mach.cpp
2016-09-17 06:49:41 -07:00
jreiser@BitWagon.com 90caf19e9e Cleanup amd64-darwin.macho-upxmain.c
changed src/stub/amd64-darwin.macho-upxmain.h
 changed src/stub/src/amd64-darwin.macho-upxmain.c
 changed src/stub/src/amd64-darwin.macho-upxsubr.S
2016-09-16 21:29:37 -07:00
jreiser@BitWagon.com 8d0b3b7d44 Fix segXHDR, but assume no __DATA in stub for now.
changed src/p_mach.cpp
2016-09-15 21:44:17 -07:00
jreiser@BitWagon.com 4c253d68d4 new start address 0xfe000000
changed src/stub/amd64-darwin.macho-upxmain.h
2016-09-15 21:38:39 -07:00
jreiser@BitWagon.com 73d1b331f1 trim Mach_command from stub. [Dirty, needs cleanup!]
changed src/p_mach.cpp
2016-09-13 20:20:41 -07:00
jreiser@BitWagon.com af2fddfd6d rebuild stub
changed src/stub/amd64-darwin.macho-upxmain.h
2016-09-13 20:18:54 -07:00
jreiser@BitWagon.com 3e065ead65 fix .bss in floating dyld
changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-13 20:17:51 -07:00
jreiser@BitWagon.com 3774704326 forgotten file; 3 FIXME !
added src/stub/src/arch/arm/v8a/lzma_d-arm.S
2016-09-13 20:14:44 -07:00
jreiser@BitWagon.com 4a1100b6a4 Unexport all symbols in compressed output.
added src/stub/src/amd64-darwin.macho-upxhide.txt
 changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-11 15:28:42 -07:00
jreiser@BitWagon.com 63dec77ed6 Try auto-relocate for /usr/lib/dyld
changed src/stub/amd64-darwin.macho-upxmain.h
 changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-11 15:08:56 -07:00
jreiser@BitWagon.com 1d3a66f890 bswap(), bzero(), fat_find(), assembly-language system calls
added src/stub/src/amd64-darwin.macho-upxsubr.S
 changed src/stub/amd64-darwin.macho-upxmain.h
 changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-11 14:22:19 -07:00
jreiser@BitWagon.com c1da92ca22 reduce asm()
changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-11 06:03:06 -07:00
jreiser@BitWagon.com 13475002d7 segXHDR reserves address space; actual launch!
changed src/p_mach.cpp
 changed src/stub/amd64-darwin.macho-upxmain.h
 changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-10 20:13:44 -07:00
jreiser@BitWagon.com 5bb6f246ed Mach-O dyld: __LINKEDIT must have highest .vmaddr and .fileoff 2016-09-10 15:46:36 -07:00
jreiser@BitWagon.com 89df7451ef Rebuild stubs
changed src/stub/amd64-darwin.macho-entry.h
 changed src/stub/amd64-darwin.macho-upxmain.h
 changed src/stub/tmp/amd64-darwin.macho-entry.bin.dump
2016-09-10 15:03:55 -07:00
jreiser@BitWagon.com 1334d544f7 stubtools 20160902 2016-09-10 15:03:04 -07:00
jreiser@BitWagon.com 3fefaa7362 revamp MH_EXECUTE: try to meet expectations of MacOSX 10.12 Sierra
changed src/p_mach.cpp
 changed src/stub/src/amd64-darwin.macho-upxmain.c
2016-09-10 15:02:13 -07:00
jreiser@BitWagon.com 15d62f7b96 Mach_main_command LC_MAIN 2016-09-10 15:00:28 -07:00
jreiser@BitWagon.com 83e0aaa511 sections AMD64BXX, MACH_UNC for MacOSX 10.12 2016-09-10 14:59:23 -07:00
jreiser@BitWagon.com ee06ce1148 generic Mach_command 2016-09-10 14:57:27 -07:00
jreiser@BitWagon.com 16d6124bb4 amd64-darwin.macho-upxmain for stub on Mac OS X 10.12 "Sierra" 2016-09-05 20:37:23 -07:00
jreiser@BitWagon.com 1197beaa13 ElfLinker::init() zero length implies 0x4000 blank bytes 2016-09-05 20:36:07 -07:00
jreiser@BitWagon.com 98b428a8be Fix compiler warning 2016-09-05 20:32:52 -07:00
jreiser@BitWagon.com 17f47d3c0a p_mach*: Try for MacOSX 10.12 "Sierra" with UUID, XHDR. 2016-09-04 19:05:31 -07:00
John Reiser a9cc3b2a89 Use gcc-ppc64-linux-gnu-5.3.1-2.fc22.x86_64
But bin-upx-20130920/multiarch-ld-2.17 gets SIGSEGV for fold.h

  src/stub/Makefile
  src/stub/ppc64le-darwin.dylib-entry.h
  src/stub/ppc64le-darwin.macho-entry.h
  src/stub/ppc64le-linux.elf-entry.h
  src/stub/ppc64le-linux.kernel.vmlinux.h
2016-07-27 08:57:54 -07:00
John Reiser 199102c106 stub/src/arch/arm/v8a/lzma_d_cf.S and follow-ons
src/stub/arm64-darwin.macho-entry.h
  src/stub/src/arch/arm/v8a/lzma_d_cf.S
  src/stub/tmp/arm64-darwin.macho-entry.bin.dump
2016-07-27 08:27:06 -07:00
John Reiser c7d76fb7ab Change copyright year 2013 ==> 2016 in ppc64le files.
src/stub/ppc64le-darwin.macho-fold.h
  src/stub/src/arch/ppc64le/64/bxx.S
  src/stub/src/arch/ppc64le/64/lzma_d.S
  src/stub/src/arch/ppc64le/64/macros.S
  src/stub/src/arch/ppc64le/64/nrv2b_d.S
  src/stub/src/arch/ppc64le/64/nrv2d_d.S
  src/stub/src/arch/ppc64le/64/nrv2e_d.S
  src/stub/src/ppc64le-darwin.dylib-entry.S
  src/stub/src/ppc64le-darwin.macho-entry.S
  src/stub/src/ppc64le-darwin.macho-fold.S
  src/stub/src/ppc64le-darwin.macho-main.c
  src/stub/src/ppc64le-linux.elf-entry.S
  src/stub/src/ppc64le-linux.elf-fold.S
  src/stub/src/ppc64le-linux.elf-fold.lds
  src/stub/src/ppc64le-linux.elf-main.c
  src/stub/src/ppc64le-linux.kernel.vmlinux-head.S
  src/stub/src/ppc64le-linux.kernel.vmlinux.S
2016-07-26 21:42:07 -07:00
John Reiser ba9b86c0dc added src/stub/src/arch/arm/v8a/lzma_d_cf.S 2016-07-26 21:32:43 -07:00
John Reiser 5de83a606e Cleanup after Thierry Fauck changes for ppc64le.
We need a "UPX standard" compiler in order to re-compile the stubs for ppc64le;
meanwhile use Thierry's "pre-compiled" stubs.
Revert powerpc stubs to those produced by UPX standard powerpc.405-linux-gcc-3.4.5.
Cleanup the workarounds that Thierry used because he lacked upx-stubtools 20130920.
ARMv8 (64-bit) compiles but is incomplete and does not run yet.

 changed src/Makefile
 changed src/linker.cpp
 changed src/stub/Makefile
 changed src/stub/amd64-linux.elf-entry.h
 changed src/stub/arm64-darwin.macho-entry.h
 changed src/stub/arm64-darwin.macho-fold.h
 changed src/stub/powerpc-darwin.dylib-entry.h
 changed src/stub/powerpc-darwin.macho-entry.h
 changed src/stub/powerpc-darwin.macho-fold.h
 changed src/stub/powerpc-linux.elf-entry.h
 changed src/stub/powerpc-linux.elf-fold.h
 changed src/stub/powerpc-linux.kernel.vmlinux.h
 changed src/stub/scripts/xstrip.py
 changed src/stub/src/arch/arm/v8a/lzma_d.S
 changed src/stub/src/arch/arm/v8a/macros.S
 changed src/stub/src/arm64-darwin.macho-entry.S
 changed src/stub/tmp/arm64-darwin.macho-entry.bin.dump
2016-07-26 21:29:29 -07:00
John Reiser 01a0c8672d changeset: 2451:4e2a6c33d5fb
tag: ppc64le
user: Thierry Fauck <tfauck@free.fr>
date: Wed Jun 22 08:25:13 2016 -0400
summary: Add support for ppc64le statically linked binaries
2016-07-26 17:00:25 -07:00
John Reiser fa522c0ffc Hacking convert v4a/lzma_d-arm.S from 32-bit to 64-bit 2016-02-14 21:26:37 -08:00
John Reiser 16241d010f PUSH+POP now in macros.S 2016-02-14 21:25:28 -08:00
John Reiser 9cb8fbf178 branch merge
branch 'default'
   changed src/pefile.cpp
   changed src/pefile.h
2016-01-31 20:11:42 -08:00
John Reiser bd7ef27628 ARM64LE begins implementation
added src/stub/arm64-darwin.macho-entry.h
   added src/stub/arm64-darwin.macho-fold.h
   added src/stub/src/arch/arm/v8a/lzma_d.S
   added src/stub/src/arch/arm/v8a/macros.S
   added src/stub/src/arch/arm/v8a/nrv2b_d8.S
   added src/stub/src/arch/arm/v8a/nrv2d_d8.S
   added src/stub/src/arch/arm/v8a/nrv2e_d32.S
   added src/stub/src/arch/arm/v8a/nrv2e_d8.S
   added src/stub/src/arm64-darwin.macho-entry.S
   added src/stub/src/arm64-darwin.macho-fold.S
   added src/stub/src/arm64-darwin.macho-main.c
   added src/stub/src/arm64-linux.elf-entry.S
   added src/stub/src/arm64-linux.elf-fold.S
   added src/stub/tmp/arm64-darwin.macho-entry.bin.dump
   changed src/p_mach.cpp
   changed src/p_mach.h
   changed src/stub/Makefile
2016-01-31 20:09:38 -08:00
John Reiser 42e520e841 ElfLinkerArm64LE 2016-01-31 19:59:00 -08:00
John Reiser d8f9cd237f UPX_F_MACH_ARM64EL 2016-01-31 19:58:17 -08:00
László Molnár 33065ecf04 fixed resource bounds checking when compressing; let --force override throwing an exception 2015-08-11 13:05:10 +02:00
John Reiser 718a1da262 Bounds check shstrtab in PackVmlinuxBase<T>::canPack() 2015-08-10 05:45:52 -07:00
John Reiser b89c3ebb42 LZMA version 15.05 2015-08-03 22:36:16 -07:00
John Reiser 9d7e44feff GNU Make 4.0 does not assign to MAKEFLAGS sequentially 2015-08-03 22:35:00 -07:00
John Reiser e48a60a4f0 Add link to goupx for Go-language workaround and UI. 2015-07-28 13:40:44 -07:00
John Reiser 163e1907a4 0==.vmsize in Go-language LC_SEGMENT_64; also g++ 5.1.1 nit 2015-07-25 12:54:25 -07:00
John Reiser ac1ccaa246 Go-language PT_LOAD 2015-07-25 07:21:28 -07:00
John Reiser 53b45279ad Better diagnosis of Go-language PT_LOAD; https://sourceforge.net/p/upx/bugs/195/ 2015-07-25 07:11:57 -07:00
John Reiser f80daf5de1 CERT-FI Case 829767 UPX command line tools segfaults
The vulnerabilities were discovered by Joonas Kuorilehto and Antti Häyrynen from Codenomicon.
2015-05-16 15:33:31 -07:00
John Reiser 298ea1f0d3 ::unpack(): another check on b_info; uncompressed ElfXX_Ehdr must match input 2015-05-16 15:23:01 -07:00
John Reiser 1d13d8c4a0 PackMachBase::unpack() process lc_seg in same order as ::pack() 2015-05-16 15:20:03 -07:00
John Reiser 2238c99b61 another check on b_info in ::unpackExtent() 2015-05-16 15:18:28 -07:00
John Reiser 7d4dfbef2b cleanup IPTR_I_D 2015-05-15 20:56:34 -07:00
John Reiser 759827b404 EI_OSABI for EM_ARM is a real mess 2015-05-15 20:47:35 -07:00
John Reiser fca627d1b0 ::seek() returns resulting off_t; InputFile::seek() restricts to actual _length 2015-05-15 20:44:09 -07:00
John Reiser 404da18aed IPTR_I_D: 'import' buffer is a subset of ibuf 2015-05-15 20:42:18 -07:00
John Reiser 330fca722a too large: blocksize > 1024*1024*1024 [corrupted] 2015-05-15 05:36:21 -07:00
John Reiser 8939cd120b too small: (st.st_size < 512) 2015-05-15 05:32:52 -07:00
László Molnár 63afeb7373 added a check for corrupted packheader 2015-05-14 21:48:16 +02:00
László Molnár 6ba68a6455 PE related fixes for CERT-FI 829767 2015-05-14 21:46:52 +02:00
John Reiser 1579c74302 canPack() requires 0 < nfat 2015-05-10 14:01:48 -07:00
John Reiser 373ca15c71 size < 1024 is too short 2015-05-10 14:01:08 -07:00
John Reiser a8a3caed1c Check blocksize 2015-05-09 20:29:56 -07:00
John Reiser cb35ba4543 At ::unpack much of decompressed Mach_header must match outer Mach_header 2015-05-09 20:14:32 -07:00
John Reiser cdd152d015 Detect (int)blocksize < 0 2015-05-09 20:13:30 -07:00
John Reiser 83ce7dc62f Must not compare orig_file_size with fi->st_size() during ::unpack 2015-05-09 17:47:17 -07:00
John Reiser b182b50f24 Distinguish corruption of p_info, b_info 2015-05-09 10:13:13 -07:00
John Reiser 71a9941b84 Check getImageSize(). CERT-FI 829767
id:000058,sig:06,src:000001,op:havoc,rep:64
2015-05-09 07:29:26 -07:00
John Reiser c777da263e Check blocksize. CERT-FI 829767
id:000053,sig:06,src:000000,op:arith8,pos:10440,val:+20
2015-05-09 07:25:25 -07:00
John Reiser 2cb7b56a41 Check ph.c_len; CERT-FI 829767
id:000023,sig:06,src:000000,op:flip2,pos:10440
2015-05-09 07:18:54 -07:00
John Reiser 52f9ef14b9 Check ph.c_len; CERT-FI 829767
id:000010,sig:06,src:000000,op:flip1,pos:11584
2015-05-09 07:13:47 -07:00
John Reiser 8d6c594240 Check ph.c_len; CERT-FI 829767
id:000008,sig:06,src:000000,op:flip1,pos:205
2015-05-09 07:05:17 -07:00
John Reiser 7ad77ff540 Check blocksize. CERT-FI 829767
id:000005,sig:06,src:000000,op:havoc,rep:16
2015-05-09 06:56:32 -07:00
John Reiser acede72e9b Check ph.c_len. CERT-FI 829767
id:000002,sig:06,src:000000,op:havoc,rep:1
2015-05-09 06:49:45 -07:00
John Reiser 771fd732d1 Check e_phentsize; CERT-FI 829767
id:000064,sig:06,sync:upx-macho-crash-2,src:000096
2015-05-09 05:31:36 -07:00
John Reiser 2a79a69f59 PackUnix::unpack() is non-Elf. CERT-FI 829767
id:000057,sig:11,sync:upx-macho-crash-2,src:000108
id:000058,sig:11,sync:upx-macho-crash-2,src:000107
id:000059,sig:06,sync:upx-macho-crash-2,src:000106
id:000060,sig:06,sync:upx-macho-crash-2,src:000103
2015-05-09 05:14:12 -07:00
John Reiser 8c0321697f Check PackHeader before decompress; CERT-FI id:000002,sig:06,src:000000,op:flip1,pos:4629 2015-05-08 20:13:44 -07:00
John Reiser 0151b3f9b3 Validate Mach_segment_command.cmdsize; CERT-FI id:000000,sig:11,src:000000,op:havoc,rep:2 2015-05-08 19:45:05 -07:00
John Reiser 82a51f35ea Validate header CERT_FI id:000000,sig:11,src:000000,op:flip1,pos:1 2015-05-08 19:22:24 -07:00
John Reiser 35944cbfc1 Validate fat_head; CERT-FI id:000000,sig:06,src:000000,op:flip1,pos:7 2015-05-08 18:32:42 -07:00
John Reiser f0aef9b28b Check input data; CERT-FI upx-crashes-elf id:000000,sig:11,src:000000,op:flip1,pos:0 2015-05-08 17:04:16 -07:00
John Reiser ae37c3902c Apple codesign requires a different secTEXT.size 2015-03-27 20:41:00 -07:00
John Reiser d612585582 C/7zTypes.h #if (WITH_LZMA >= 0x938) 2015-03-15 10:30:55 -07:00
John Reiser 7ca14d209c Use upx_uint64_t instead of "unsigned long". 2015-01-10 12:26:35 -08:00
Markus F.X.J. Oberhumer c37f582c10 Merge. 2015-01-04 11:11:05 +01:00
John Reiser 6272fb3822 ARM --lzma && is_big: stub mmap must allow for cpr0.sz_unc [How did this ever work before?] 2015-01-02 17:36:26 -08:00
Markus F.X.J. Oberhumer 2582fbac59 Update src/Makefile to use more conservative gcc optimization settings. 2015-01-03 01:55:51 +01:00
Markus F.X.J. Oberhumer 5abb578e47 p_djgpp2.{cpp,h}: remove usage of "long". 2015-01-03 01:12:46 +01:00
Markus F.X.J. Oberhumer 015ebf89a5 lefile.h: remove usage of "long". 2015-01-03 01:04:41 +01:00
Markus F.X.J. Oberhumer c6724968f1 pefile.cpp: work around a gcc-3.4 limitation. 2015-01-03 00:40:28 +01:00
Markus F.X.J. Oberhumer 9fa1772ae4 Merge. 2015-01-03 00:34:42 +01:00
Markus F.X.J. Oberhumer 4551937812 Bump version year. 2015-01-03 00:26:48 +01:00
John Reiser 51ee664cae PackLinuxElf32help1 refuses if e_ident[EI_DATA] mismatches bele policy 2015-01-02 15:25:29 -08:00
Markus F.X.J. Oberhumer fb611a98f9 Welcome 2015. 2015-01-03 00:24:07 +01:00
Markus F.X.J. Oberhumer a3d5face38 Fix a comment. 2015-01-03 00:21:51 +01:00
László Molnár 424cd497d3 pe64: saved a few bytes in the nrv decompressors 2014-03-18 23:35:30 +01:00
László Molnár d46eeffaaf NEWS updated 2014-03-10 21:53:46 +01:00
László Molnár 6520f2061e arm/pe: thumb mode stub hopefully fixed 2014-03-10 21:44:23 +01:00
László Molnár 5d93f86b4b armpe_tester: better import handling 2014-03-10 21:42:11 +01:00
László Molnár b3f63ce7ae pe: fix a bug in pack0() for arm 2014-03-09 23:55:28 +01:00
László Molnár 56de770682 armpe_tester now works on android 2014-03-09 23:42:41 +01:00
László Molnár 940341bc9d arm/pe: import handling updates (untested) 2014-03-08 18:59:26 +01:00
László Molnár 804a0ce601 merge 2014-03-06 22:38:15 +01:00
László Molnár 41054a4c56 handle duplicates in ImportLinker 2014-03-06 22:26:41 +01:00
László Molnár 7b8e5d4180 pe: remove some dead code 2014-03-05 23:59:53 +01:00
László Molnár ca2369f1c1 pe: win32/win64 pack/unpack seems to work again 2014-03-05 23:40:24 +01:00
László Molnár 129cb0b3cd pe: packing of pe64 starts to work again 2014-03-04 23:51:59 +01:00
László Molnár 632b2ae1ba pe: pack() logic moved to PeFile 2014-03-02 22:34:52 +01:00
László Molnár 18e55061e1 pepfile.* disabled; PeFile64 class introduced 2014-02-20 00:10:18 +01:00
László Molnár e49b65723f pe: canUnpack moved to PeFile 2014-02-19 23:27:41 +01:00
László Molnár 8e52894763 pe: loadconf handling moved to PeFile 2014-02-19 21:45:24 +01:00
László Molnár 07cba6c774 pe32: tls refactoring 2014-02-18 00:23:42 +01:00
László Molnár 9cb639b505 pe32: refactoring of import handling and unpacking continues 2014-02-16 23:04:39 +01:00
Markus F.X.J. Oberhumer 4cf6eeeee2 README.SRC: update an URL. 2014-01-27 20:59:47 +01:00
John Reiser c0f692792f 2014 2014-01-10 19:23:41 -08:00
John Reiser bd77e0945b more LC_* constants 2014-01-10 19:22:30 -08:00
Markus F.X.J. Oberhumer f0eb171b2a Strip trailing whitespace. 2014-01-07 23:09:11 +01:00
Markus F.X.J. Oberhumer fb93662b5c Bump version for next release. 2014-01-07 23:08:00 +01:00
Markus F.X.J. Oberhumer a26c982e93 Welcome 2014. 2014-01-07 23:05:10 +01:00
Markus F.X.J. Oberhumer 7db3e98944 Small cleanups. 2014-01-07 23:03:16 +01:00
Markus F.X.J. Oberhumer 4a87834e04 New ACC version. 2014-01-07 19:15:57 +00:00
Markus F.X.J. Oberhumer bf6ecaeeb9 stub: minor cosmetic cleanups. 2013-12-02 19:37:28 +01:00
Markus F.X.J. Oberhumer f70ef86dfa help.cpp: add a missing con_fg() call. 2013-12-02 19:23:06 +01:00
John Reiser cd3132667a ARM shlib escape hatch moves to just beyond .text.
https://sourceforge.net/p/upx/bugs/223/
2013-11-22 19:26:19 -08:00
John Reiser 1c459a7bea Sync stubs. 2013-11-16 14:29:52 -08:00
John Reiser 4f0bfeab4c Round down unfilter length to a multiple of 4.
https://sourceforge.net/p/upx/bugs/223
2013-11-16 14:28:59 -08:00
John Reiser c5c9921b59 Unpack detects is_shlib more robustly. Dispute .e_shoff. 2013-11-16 14:25:53 -08:00
John Reiser 6b63aba1fc Disable jni_onload_* 2013-11-09 16:06:41 -08:00
John Reiser 382331fb11 e_phoff and e_shoff are 32/64 specific 2013-10-28 07:11:40 -07:00
John Reiser caf9af7ae4 JNI_OnLoad is a pre-DT_INIT in a shared library. 2013-10-26 09:51:25 -07:00
John Reiser 45d2adeb9c Android < 4.1 (kernel < 3.0.31) often has PT_INTERP of /system/bin/linker
with bad PT_LOAD[0].  https://sourceforge.net/p/upx/bugs/221
2013-10-21 07:27:53 -07:00
László Molnár 96708d7592 ImportLinker copied into PeFile 2013-10-12 16:48:56 +02:00
John Reiser 13090d1219 ARM close /proc/self/exe after mmap 2013-10-06 19:56:14 -07:00
László Molnár 8ab229cca9 pe: refactoring started 2013-10-06 22:57:20 +02:00
John Reiser 583cd078dc ARM elf-fold: preserve /proc/self/exe by mmap of one page into stack 2013-10-06 13:22:05 -07:00
László Molnár aa2ac1bbb8 pe: ImportLinker introduced 2013-10-04 22:48:21 +02:00
Markus F.X.J. Oberhumer 928b426672 Add tag for RELEASE_391. 2013-09-30 15:51:00 +00:00
Markus F.X.J. Oberhumer 6766b14415 Prepare release. 2013-09-30 14:21:37 +02:00
John Reiser 9d0f9e967f Avoid stmdb with write-back register in stored list,
even when stored value is don't care.
2013-09-21 09:52:21 -07:00
John Reiser d7609088e5 Silence "warning: cannot find entry symbol _start" 2013-09-21 08:39:15 -07:00
Markus F.X.J. Oberhumer b2643b6926 Start using the new intergral type names. 2013-09-20 08:19:18 +02:00
Markus F.X.J. Oberhumer 07b65ca069 Introduce integral type names using <stdint.h> terminology like "upx_uint64_t". 2013-09-20 08:16:37 +02:00
Markus F.X.J. Oberhumer 25727f7f99 Minor portability fixes. 2013-09-20 07:48:29 +02:00
Markus F.X.J. Oberhumer 880ae89307 Bump version and tentative release date. 2013-09-20 07:19:06 +02:00
Markus F.X.J. Oberhumer 1496df1989 New ACC version. 2013-09-20 07:09:35 +02:00
Markus F.X.J. Oberhumer 7d8ae6b4b1 Make amd64-win64.pep.S compile with current upx stubtools. 2013-09-20 07:08:09 +02:00
Markus F.X.J. Oberhumer 312d4cccaf stub: start using stubtools bin-upx-20130920. 2013-09-20 06:59:27 +02:00
Markus F.X.J. Oberhumer ce5f9f95ea stub: fix i386 syntax for current gas versions, and add some explicit
alignments at the end of the file so that we do not depend on gas defaults.
2013-09-20 06:15:46 +02:00
Markus F.X.J. Oberhumer d9bf8a76d9 Protect against changes from future gas versions in amd64-linux.elf-entry.S. 2013-09-20 05:22:05 +02:00
Markus F.X.J. Oberhumer f7a35fb9fe stub: save 1 byte in amd64-darwin.{dylib,macho}-entry.S. 2013-09-20 04:20:23 +02:00
Markus F.X.J. Oberhumer 3ba691ded5 Remove trailing whitespace. 2013-09-20 03:25:59 +02:00
Markus F.X.J. Oberhumer 7a7277d56f Use correct "movzwl" opcode in src/stub/src/arch/i386/macros.S. 2013-09-20 03:18:19 +02:00
László Molnár 76be5dd1d3 linker: Section::offset should be u64 2013-09-01 21:38:44 +02:00
László Molnár 53dc63f3bc linker: a small 64-bit relocation support related fix 2013-09-01 11:15:30 +02:00
László Molnár 80da0bc9d5 pepfile: infoWarning about unsupported relocation types fixed 2013-08-28 22:33:39 +02:00
László Molnár bce7af4e11 fixed 8 bit range checking in ElfLinkerAMD64::relocate1 2013-08-28 22:31:40 +02:00
László Molnár 9da09b51ed win64/pe: tls callback assembly improvements + misc cleanups 2013-08-28 21:53:23 +02:00
László Molnár 86392f197f win64/pe: lzma support added 2013-08-28 00:24:54 +02:00
László Molnár 1c13046297 win64/pe: added nrv2b and nrv2d support 2013-08-27 22:06:52 +02:00
László Molnár fbc756b531 win64/pe: filter support added 2013-08-27 21:22:21 +02:00
László Molnár 6c64b06453 win64/pe: uncompression seems to work; tls handling improvement 2013-08-26 22:07:55 +02:00
László Molnár 241834029a 64 relocation handling added; basic DLL support works 2013-08-25 23:54:13 +02:00
László Molnár 5b8a9c0b47 basic win64 PE support added 2013-08-22 22:01:09 +02:00
László Molnár 037c29d24a added full support for 64-bit relocations 2013-08-22 21:43:11 +02:00
László Molnár 893f26ac9a fix wcle fixup unpacking segfault (sf.net bug 220) 2013-08-19 13:39:44 +02:00
John Reiser d43f8e3100 Alignment bug in test or decompress of shared library;
sourceforge.net/p/upx/bugs/218/
2013-07-06 13:50:15 -07:00
John Reiser 2b42acf7b8 ARM heuristic dcache flush by sweeping 1/2 MB 2013-06-10 14:20:59 -07:00
John Reiser f65b80ed42 ARM remember readlink("/proc/self/exe",) as environment variable " =" (3 spaces) 2013-06-09 20:33:59 -07:00
John Reiser e84abbdc82 ARM __clear_cache() has bugs
Linux hostname 3.0.8-482645-user #1 SMP PREEMPT Mon Apr 30 19:43:45 KST 2012 armv7l GNU/Linux
  Processor	: ARMv7 Processor rev 3 (v7l)

  processor	: 0
  BogoMIPS	: 597.12

  processor	: 1
  BogoMIPS	: 597.12

  CPU implementer	: 0x41
  CPU architecture: 7
  CPU variant	: 0x1
  CPU part	: 0xc09
  CPU revision	: 3

  Hardware	: Espresso10
  Revision	: 000a
2013-06-09 13:03:06 -07:00
John Reiser 66269eabe9 ARM Try a hole so that kernel does not extend brk(0) 2013-06-08 08:39:08 -07:00
John Reiser 36c0928483 ARM __clear_cache() on escape hatch; http://sourceforge.net/p/upx/bugs/214/ 2013-06-07 07:08:03 -07:00
John Reiser 9237e15adc Fix ARM compress shared library. 2013-05-10 16:20:52 -07:00
Markus F.X.J. Oberhumer 0d3a2072b2 Add some more sanity checks in pefile.cpp. 2013-04-04 14:30:52 +02:00
Markus F.X.J. Oberhumer aa2ee5dfc2 New ACC version. 2013-03-20 16:48:27 +00:00
John Reiser b515fa39ec Apple codesign follies: need more flags 2013-03-07 19:47:44 -08:00
Markus F.X.J. Oberhumer 76e3f4eb92 Post-release version bump. 2013-02-20 13:50:12 +01:00
Markus F.X.J. Oberhumer 4959e5c6c2 Add tag for RELEASE_309. 2013-02-18 16:09:00 +00:00
652 changed files with 114486 additions and 86412 deletions
+44
View File
@@ -0,0 +1,44 @@
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." --Rob Pike
#
# for clang-format-15.0.6 from https://github.com/upx/upx-stubtools/releases
---
BasedOnStyle: LLVM
ColumnLimit: 100
IndentWidth: 4
---
Language: Cpp
AccessModifierOffset: -4
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
EmptyLineBeforeAccessModifier: Leave
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
...
+21
View File
@@ -0,0 +1,21 @@
# see https://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[{GNUmakefile*,MMakefile*,Makefile*,Makevars*,*.mk}]
indent_size = 8
indent_style = tab
[*.S]
indent_size = 8
[*.yml]
indent_size = 2
+10
View File
@@ -0,0 +1,10 @@
# make GitHub language detection more accurate, see https://github.com/github/linguist
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
+45
View File
@@ -0,0 +1,45 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
This issue tracker is **ONLY** used for reporting bugs.
Please use [stackoverflow](https://stackoverflow.com) for supporting issues.
<!---
IF YOU REMOVE THIS TEMPLATE WE WILL CLOSE YOUR ISSUE WITHOUT RESPONSE.
Just read it and fill in the details we're asking, it saves so much of our time. Thanks!
-->
## What's the problem (or question)?
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
## What should have happened?
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->
## Do you have an idea for a solution?
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change -->
## How can we reproduce the issue?
<!--- Provide unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant -->
1.
2.
3.
4.
## Please tell us details about your environment.
<!--- Include as many relevant details about the environment you experienced the bug in -->
* UPX version used (`upx --version`):
* Host Operating System and version:
* Host CPU architecture:
* Target Operating System and version:
* Target CPU architecture:
+1
View File
@@ -0,0 +1 @@
blank_issues_enabled: false
+45
View File
@@ -0,0 +1,45 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
This issue tracker is **ONLY** used for requesting sensible features.
Please use [stackoverflow](https://stackoverflow.com) for supporting issues.
<!---
IF YOU REMOVE THIS TEMPLATE WE WILL CLOSE YOUR ISSUE WITHOUT RESPONSE.
Just read it and fill in the details we're asking, it saves so much of our time. Thanks!
-->
## What's the problem (or question)?
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
## What should have happened?
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->
## Do you have an idea for a solution?
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change -->
## How can we reproduce the issue?
<!--- Provide unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant -->
1.
2.
3.
4.
## Please tell us details about your environment.
<!--- Include as many relevant details about the environment you experienced the bug in -->
* UPX version used (`upx --version`):
* Host Operating System and version:
* Host CPU architecture:
* Target Operating System and version:
* Target CPU architecture:
+8
View File
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
# Check for updates to GitHub Actions every weekday
interval: 'daily'
+14
View File
@@ -0,0 +1,14 @@
UPX PULL REQUEST NOTES
======================
Handling pull requests is actually quite time consuming, so please
- if you want to contribute **a real C++ code bug-fix** then open an issue
on the main UPX issue tracker first
- if you want to contribute **a new feature** then by all means open an issue
on the main UPX issue tracker first before starting any coding!
- please refuse the temptation to "improve" the docs, scripts, CI, makefiles,
cmake build system, spelling errors, etc - we will NOT merge this; only open
an issue if you're sure there is a **real bug**
+15
View File
@@ -0,0 +1,15 @@
# Security Context
IMPORTANT NOTE: UPX inherits the security context of any files it handles.
This means that packing, unpacking, or even testing or listing a file requires
the same security considerations as actually executing the file.
Use UPX on trusted files only!
## Supported Versions
| Version | Supported |
| --------- | ------------------ |
| git HEAD | :white_check_mark: |
| any other | :x: |
@@ -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="\
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
@@ -0,0 +1,290 @@
#! /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
+437
View File
@@ -0,0 +1,437 @@
# Support for GitHub Actions -- https://github.com/features/actions
# note: GitHub Actions runner images are frequently updated, and
# unfortunately this sometimes breaks builds in mysterious ways...
# see https://github.com/actions/runner-images.git
name: 'CI'
on: [push, workflow_dispatch]
env:
DEBIAN_FRONTEND: noninteractive
UPX_CMAKE_BUILD_FLAGS: --verbose
jobs:
job-rebuild-and-verify-stubs:
name: 'Rebuild stubs'
runs-on: ubuntu-20.04
steps:
- name: 'Install extra packages'
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'
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
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
with: { submodules: true }
- name: 'Rebuild and verify stubs'
run: |
export PATH="$(readlink -en ../deps/bin-upx-20221212):$PATH"
make -C src/stub maintainer-clean extra-clean
git status || true
make -C src/stub extra-all all
if ! git diff --quiet; then git diff; exit 1; fi
- name: 'Check source code formatting'
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:
needs: [ job-rebuild-and-verify-stubs ]
name: ${{ format('{0} cmake', 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 }
steps:
- name: 'Install extra 32-bit and Windows packages'
if: ${{ matrix.use_m32 }}
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y g++-multilib g++-mingw-w64-i686 g++-mingw-w64-x86-64
- name: 'Check out code'
uses: actions/checkout@v3
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'
run: 'make build/extra/gcc/debug'
- name: 'Build cmake extra/gcc/release'
run: 'make build/extra/gcc/release'
- name: 'Build cmake extra/clang/debug'
run: 'make build/extra/clang/debug'
- name: 'Build cmake extra/clang/release'
run: 'make build/extra/clang/release'
- name: 'Build cmake extra/gcc-m32/debug'
if: ${{ matrix.use_m32 }}
run: 'make build/extra/gcc-m32/debug'
- name: 'Build cmake extra/gcc-m32/release'
if: ${{ matrix.use_m32 }}
run: 'make build/extra/gcc-m32/release'
- name: 'Build cmake extra/cross-windows-mingw32/release'
if: ${{ matrix.use_m32 }}
run: 'make build/extra/cross-windows-mingw32/release'
- name: 'Build cmake extra/cross-windows-mingw64/release'
if: ${{ matrix.use_m32 }}
run: 'make build/extra/cross-windows-mingw64/release'
- name: 'Make artifact'
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
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
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
- name: 'Run basic 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'
if: ${{ matrix.use_m32 }}
run: |
make -C build/extra/gcc-m32/debug test
make -C build/extra/gcc-m32/release test
- 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"
job-macos-cmake:
needs: [ job-rebuild-and-verify-stubs ]
name: ${{ format('{0} cmake', matrix.os) }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { os: macos-11, gcc: gcc-10, gxx: 'g++-10', testsuite: true }
- { os: macos-12, gcc: gcc-11, gxx: 'g++-11', testsuite: true }
steps:
- name: 'Install brew packages'
if: ${{ matrix.testsuite }}
run: |
brew update
brew install coreutils
- name: 'Check out code'
uses: actions/checkout@v3
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'
run: 'make build/extra/clang/debug'
- name: 'Build cmake extra/clang/release'
run: 'make build/extra/clang/release'
- name: 'Build cmake extra/gcc/debug'
if: ${{ matrix.gcc != '' }}
run: 'make build/extra/gcc/debug CC=${{ matrix.gcc }} CXX=${{ matrix.gxx }}'
- name: 'Build cmake 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: |
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'
run: |
CC="clang -target arm64-apple-darwin" CXX="clang++ -target arm64-apple-darwin" \
make UPX_XTARGET=cross-darwin-arm64 xtarget/release
- name: 'Make artifact'
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
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
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
- name: 'Run basic tests'
run: |
make -C build/extra/clang/debug test
make -C build/extra/clang/release test
- name: 'Run test suite build/extra/clang/release'
if: ${{ matrix.testsuite }}
run: |
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
export upx_testsuite_SRCDIR="$(readlink -en ../deps/upx-testsuite)"
testsuite_1=$(readlink -en ./.github/travis_testsuite_1.sh)
env -C build/extra/clang/release upx_exe=./upx bash "$testsuite_1"
job-windows-cmake:
needs: [ job-rebuild-and-verify-stubs ]
name: ${{ format('{0} cmake', matrix.os) }}
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 }
steps:
- name: 'Check out code'
uses: actions/checkout@v3
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'
run: 'make build/debug'
- name: 'Build cmake release'
run: 'make build/release'
- name: 'Make artifact'
shell: bash
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
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
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
- name: 'Run basic tests'
run: |
cmake --build build/debug --config Debug --target RUN_TESTS
cmake --build build/release --config Release --target RUN_TESTS
- name: 'Run test suite build/release'
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"
job-windows-toolchains:
needs: [ job-rebuild-and-verify-stubs ]
name: ${{ format('windows {0}', matrix.name) }}
runs-on: ${{ matrix.os }}
env:
C: ${{ matrix.C }}
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 }
steps:
- name: 'Check out code'
uses: actions/checkout@v3
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}
- name: 'Set up Developer Command Prompt'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
- name: 'Build'
shell: cmd
run: |
@REM setup directories
where cl & where link
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 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
@REM ===== build zlib =====
cd %BDIR%\zlib
cl -MT -J -O2 -W3 -WX %DEFS% -c %H%\vendor\zlib\*.c
link -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
@REM ===== build UPX =====
cd %BDIR%\upx
set s=%H%\src
cat .GITREV.txt
set /p GITREV=<.GITREV.txt
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
- name: 'Make artifact'
shell: bash
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-windows-${{ matrix.name }}
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
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
- name: 'Run basic tests'
if: ${{ matrix.arch != 'amd64_arm64' }}
run: |
$ErrorActionPreference = 'stop'
$ErrorView = 'NormalView'
cd $Env:H\build\$Env:C\$Env:B\upx
$Env:UPX = "--no-color --no-progress"
.\upx.exe --version
.\upx.exe upx.exe -o upx_packed.exe
dir *.exe
.\upx.exe -l upx_packed.exe
.\upx.exe -t upx_packed.exe
.\upx_packed.exe --version
- name: 'Run test suite'
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/$C/$B/upx upx_exe=./upx.exe bash "$testsuite_1"
job-linux-zigcc:
if: ${{ true }}
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
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 }
- { zig_target: aarch64-windows-gnu }
- { zig_target: i386-linux-musl }
- { 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 }
- { zig_target: x86_64-windows-gnu }
env:
# 2023-01-30
ZIG_DIST_VERSION: 0.11.0-dev.1491+2b27bc2c6
# for zig-cc wrapper scripts (see below):
ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING
ZIG_FLAGS: ${{ matrix.zig_flags }}
ZIG_PIC: ${{ matrix.zig_pic }}
ZIG_TARGET: ${{ matrix.zig_target }}
steps:
- name: 'Install Alpine Linux container packages'
if: ${{ job.container }}
shell: sh
run: |
apk update && apk upgrade && apk add bash cmake file git make tar xz
# set PATH like in Ubuntu
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
# this seems to be needed when running in a container (beause of UID mismatch??)
git config --global --add safe.directory '*'
- name: 'Check out code'
uses: actions/checkout@v3
with: { submodules: true }
- name: ${{ format('Install Zig {0}', env.ZIG_DIST_VERSION) }}
shell: bash
run: |
# GitHub Actions magic: set "UPX_GITREV_SHORT" environment value for use in steps below
rev=$(git rev-parse --short=7 HEAD)
echo "UPX_GITREV_SHORT=$rev" >> $GITHUB_ENV
# update ZIG_TARGET (i386 => x86)
ZIG_TARGET=${ZIG_TARGET/i386-/x86-}
echo "ZIG_TARGET=$ZIG_TARGET" >> $GITHUB_ENV
# install zig; note that ~/.local/bin is included in the default $PATH on Ubuntu
mkdir -p -v ~/.local/bin
cd ~/.local/bin
ZIG_DIST_NAME=zig-linux-x86_64-${ZIG_DIST_VERSION}
wget -q 'https://ziglang.org/builds/'${ZIG_DIST_NAME}.tar.xz
ls -l ${ZIG_DIST_NAME}.tar.xz
tar -xoJf ${ZIG_DIST_NAME}.tar.xz
rm ${ZIG_DIST_NAME}.tar.xz
ln -s -v ${ZIG_DIST_NAME}/zig zig
#echo "PATH=$PATH" && which zig
echo -n 'zig version: '; zig version
# create wrapper scripts (needed for CMake)
echo -e '#!/bin/sh\nexec zig ar "$@"' > zig-ar
echo -e '#!/bin/sh\nexec zig cc -target $ZIG_TARGET $ZIG_PIC $ZIG_FLAGS $ZIG_CPPFLAGS $ZIG_CFLAGS "$@"' > zig-cc
echo -e '#!/bin/sh\nexec zig c++ -target $ZIG_TARGET $ZIG_PIC $ZIG_FLAGS $ZIG_CPPFLAGS $ZIG_CXXFLAGS "$@"' > zig-cxx
echo -e '#!/bin/sh\nexec zig ranlib "$@"' > zig-ranlib
chmod +x zig-ar zig-cc zig-cxx zig-ranlib
ls -la; head zig-ar zig-cc zig-cxx zig-ranlib
- name: ${{ format('Build Release with zig-cc -target {0} {1}', env.ZIG_TARGET, env.ZIG_PIC) }}
run: |
mkdir -p build/zig/${ZIG_TARGET}${ZIG_PIC}/release
cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release
cmake ../../../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_AR=$HOME/.local/bin/zig-ar -DCMAKE_C_COMPILER=zig-cc -DCMAKE_CXX_COMPILER=zig-cxx -DCMAKE_RANLIB=$HOME/.local/bin/zig-ranlib $EXTRA_CMAKE_CONFIG_FLAGS_RELEASE
cmake --build . --config Release --parallel --verbose
file ./upx*
- name: ${{ format('Build Debug with zig-cc -target {0} {1}', env.ZIG_TARGET, env.ZIG_PIC) }}
run: |
mkdir -p build/zig/${ZIG_TARGET}${ZIG_PIC}/debug
cd build/zig/${ZIG_TARGET}${ZIG_PIC}/debug
cmake ../../../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_AR=$HOME/.local/bin/zig-ar -DCMAKE_C_COMPILER=zig-cc -DCMAKE_CXX_COMPILER=zig-cxx -DCMAKE_RANLIB=$HOME/.local/bin/zig-ranlib $EXTRA_CMAKE_CONFIG_FLAGS_DEBUG
cmake --build . --config Debug --parallel --verbose
file ./upx*
- name: ${{ format('Make artifact from upx-{0}-{1}', github.ref_name, env.UPX_GITREV_SHORT) }}
shell: bash
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-zigcc-${{ matrix.zig_target }}${ZIG_PIC}
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
with:
name: ${{ env.artifact_name }}
path: tmp/artifact
# vim:set ts=2 sw=2 et:
+37
View File
@@ -0,0 +1,37 @@
# 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
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,29 @@
# 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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,22 @@
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'
+42
View File
@@ -0,0 +1,42 @@
/.hg*
/.vscode*
/Makevars.global*
/build*
/maint*
/vendor*
GNUmakefile
MMakefile
Makevars.local*
tmp*
*.a
*.d
*.dll
*.exe
*.lib
*.map
*.o
*.obj
*.out
*.py[cdo]
*.so
*.swp
*.ttp
doc/*.man
doc/*.ps
doc/*.tex
src/stub/**/.*-stamp
src/stub/tmp*/*.bin
src/stub/tmp*/*.bin.bindump
src/stub/tmp*/*.bin.disasm
src/stub/tmp*/*.o.disasm
src/stub/tmp*/mips.r3000-*.[is]
src/stub/tmp*/mipsel.r3000-*.[is]
src/stub/src/**/tmp*/*
src/stub/tools/sstrip/amd64-linux-sstrip
src/stub/tools/sstrip/i386-linux-sstrip
src/stub/tools/sstrip/sstrip
+25
View File
@@ -0,0 +1,25 @@
[submodule "vendor/doctest"]
path = vendor/doctest
url = https://github.com/upx/upx-vendor-doctest.git
branch = upx-vendor
shallow = true
[submodule "vendor/lzma-sdk"]
path = vendor/lzma-sdk
url = https://github.com/upx/upx-vendor-lzma-sdk.git
branch = upx-vendor
shallow = true
[submodule "vendor/ucl"]
path = vendor/ucl
url = https://github.com/upx/upx-vendor-ucl.git
branch = upx-vendor
shallow = true
[submodule "vendor/valgrind"]
path = vendor/valgrind
url = https://github.com/upx/upx-vendor-valgrind.git
branch = upx-vendor
shallow = true
[submodule "vendor/zlib"]
path = vendor/zlib
url = https://github.com/upx/upx-vendor-zlib.git
branch = upx-vendor
shallow = true
-55
View File
@@ -1,55 +0,0 @@
syntax: regexp
^\.bzr
^ChangeLog
^Makevars.global
^build
^maint
syntax: glob
.depend
*.qtcreator.{config,creator,creator.user,files,includes}
Makevars.local
*.a
*.dll
*.lib
*.py[cdo]
*.so
*.swp
doc/*.1
doc/*.doc
doc/*.html
doc/*.man
doc/*.ps
doc/*.tex
src/GNUmakefile
src/MMakefile
src/compress_nrv*
src/*.mft
src/*.rc
src/*.d
src/*.exe
src/*.map
src/*.o
src/*.obj
src/*.out
src/*.res
src/*.ttp
stub/**MMakefile
stub/**.*-stamp
##stub/tmp*/*
stub/tmp*/*.{bin,bin.bindump,bin.disasm,d,map,o,o.disasm}
stub/tmp*/mips{,el}.r3000-*.{i,s}
stub/**/tmp*/*
stub/tools/armpe/armpe_tester{,.exe,.out}
stub/tools/sstrip/amd64-linux-sstrip
stub/tools/sstrip/i386-linux-sstrip
stub/tools/sstrip/sstrip
-25
View File
@@ -1,25 +0,0 @@
087cafe682c014863b4aa8a6ea21431251a6ad3c RELEASE_308
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
155618b5b7930f97bd84b82befa7a4fd6672efb3 RELEASE_304
1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301
223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190
2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194
2ee65b77f9117651e2e5517b2edede23698d73ca RELEASE_196
396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291
46f3a6cca02603000fadc16637b02e30caddd909 RELEASE_302
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
7c6747c82b167368344a238b1a3a87c2a4fa6a18 RELEASE_306
95c558f81a0b8d5bb2bede4c8208bb84ae7d1e58 RELEASE_303
a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292
a916a2fe22de45167d25abcb40008315f415221c RELEASE_201
a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
b0353253b0b3d062eb5adb50d4b665a96620da45 RELEASE_195
b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
c9a983b7da9d4a2311f74366478348412cac2986 RELEASE_305
d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
ef9c7f2c9658d73a9b5ab2ed291483d2bbcd8bc7 RELEASE_300
efa52753e366300c0e0ebe20631adcb24ed3c15b RELEASE_293
fe7acf61147e7031fcc304aae47ca2352056815d RELEASE_307
+349
View File
@@ -0,0 +1,349 @@
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
# compilation config options
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
# 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_WERROR "Do not compile with default -Werror option." ON)
else()
# strict config defaults for devel 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_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!
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)
# determine git revision
set(GITREV_SHORT "")
set(GITREV_PLUS "")
set(GIT_DESCRIBE "")
find_package(Git)
if(Git_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV)
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --short=12 HEAD
RESULT_VARIABLE result ERROR_QUIET
OUTPUT_VARIABLE GITREV_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(LENGTH "${GITREV_SHORT}" l)
if(${result} EQUAL 0 AND ${l} EQUAL 12)
execute_process(RESULT_VARIABLE result COMMAND "${GIT_EXECUTABLE}" diff --quiet)
if(NOT ${result} EQUAL 0)
set(GITREV_PLUS "+")
endif()
else()
set(GITREV_SHORT "")
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --match "v*.*.*" --tags --dirty
RESULT_VARIABLE result ERROR_QUIET
OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g(.+)$")
set(GIT_DESCRIBE "${CMAKE_MATCH_1}-devel.${CMAKE_MATCH_2}+git-${CMAKE_MATCH_3}")
endif()
endif()
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}\"")
if(GIT_DESCRIBE)
message(STATUS "UPX_VERSION_GIT_DESCRIBE = \"${GIT_DESCRIBE}\"")
endif()
elseif(UPX_CONFIG_DISABLE_GITREV)
message(STATUS "UPX_VERSION_GITREV: disabled")
else()
message(STATUS "UPX_VERSION_GITREV: not set")
endif()
# CMake init
project(upx VERSION 4.0.2 LANGUAGES C CXX)
# 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}")
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)
endif()
#***********************************************************************
# targets and 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
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)
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)
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
)
endif()
if(UPX_CONFIG_DISABLE_WERROR)
set(warn_Werror "")
set(warn_WX "")
else()
set(warn_Werror -Werror)
set(warn_WX -WX)
endif()
if(NOT 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)
# 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()
# 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)
# disable overambitious auto-vectorization until this actually gains something
add_definitions(-fno-tree-vectorize)
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>)
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
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>)
endif()
endif()
endfunction()
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})
else()
target_compile_options(${t} PRIVATE ${warn_strict} ${warn_Werror})
endif()
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})
endif()
if(NOT UPX_CONFIG_DISABLE_ZSTD)
set(t upx_vendor_zstd)
upx_compile_target_debug_with_O2(${t})
upx_sanitize_target(${t})
target_compile_options(${t} PRIVATE -DDYNAMIC_BMI2=0 -DZSTD_DISABLE_ASM)
if(MSVC)
target_compile_options(${t} PRIVATE -J -W4 ${warn_WX})
else()
target_compile_options(${t} PRIVATE ${warn_strict} ${warn_Werror})
endif()
endif()
set(t upx)
target_include_directories(${t} PRIVATE vendor vendor/boost-pfr/include)
target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
if(GITREV_SHORT)
target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}")
if(GIT_DESCRIBE)
target_compile_definitions(${t} PRIVATE UPX_VERSION_GIT_DESCRIBE="${GIT_DESCRIBE}")
endif()
endif()
#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})
endif()
if(NOT UPX_CONFIG_DISABLE_ZSTD)
target_compile_definitions(${t} PRIVATE WITH_ZSTD=1)
target_link_libraries(upx upx_vendor_zstd)
endif()
#***********************************************************************
# "ctest"
# "make test"
# "ninja test"
#***********************************************************************
if(NOT UPX_CONFIG_CMAKE_DISABLE_TEST)
include(CTest)
if(NOT CMAKE_CROSSCOMPILING)
add_test(NAME upx-version COMMAND upx --version)
add_test(NAME upx-help COMMAND upx --help)
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(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)
endif()
endif() # UPX_CONFIG_CMAKE_DISABLE_TEST
#***********************************************************************
# "cmake --install ."
# "make install"
# "ninja 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.")
endif()
if(CMAKE_INSTALL_PREFIX)
include(GNUInstallDirs)
endif()
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
DESTINATION "${CMAKE_INSTALL_FULL_DOCDIR}"
)
install(FILES doc/upx.1 DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man1")
endif()
endif() # UPX_CONFIG_CMAKE_DISABLE_INSTALL
#***********************************************************************
# finally 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()
function(print_var)
foreach(v ${ARGV})
if(${v})
message(STATUS "${v} = ${${v}}")
endif()
endforeach()
endfunction()
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)
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)$")
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()
endif() # UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK
# vim:set ft=cmake ts=4 sw=4 tw=0 et:
+177 -33
View File
@@ -1,42 +1,186 @@
# #
# UPX toplevel Makefile - needs GNU make 3.81 or better # UPX top-level Makefile - needs GNU make and CMake >= 3.13
#
# Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR # 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:
# mkdir -p build/release
# cd build/release
# cmake ../..
# make -j (or use "cmake --build . --parallel")
CMAKE = cmake
UPX_CMAKE_BUILD_FLAGS += --parallel
ifneq ($(VERBOSE),)
UPX_CMAKE_BUILD_FLAGS += --verbose
endif
# enable this if you prefer Ninja for the actual builds:
#UPX_CMAKE_CONFIG_FLAGS += -G Ninja
#***********************************************************************
# default
#***********************************************************************
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))
run_build = $(call run_cmake_build,$1,$2)
.DEFAULT_GOAL = build/release
build/debug: PHONY
$(call run_config,$@,Debug)
$(call run_build,$@,Debug)
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"
.SUFFIXES: .SUFFIXES:
export SHELL = /bin/sh
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),) # END of Makefile; extra stuff follows
$(error GNU make 3.81 or better is required)
#***********************************************************************
# 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 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
endif endif
srcdir = . #***********************************************************************
top_srcdir = . # check git submodules
include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local) #***********************************************************************
SUBMODULES = doctest lzma-sdk ucl valgrind zlib
# info: src/stub needs special build tools dummy := $(foreach m,$(SUBMODULES),$(if $(wildcard vendor/$m/[CL]*),$m,\
BUILD_STUB = 0 $(error ERROR: missing git submodule $m; run 'git submodule update --init')))
ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
BUILD_STUB = 1
endif
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
BUILD_STUB = 1
endif
default:
@echo "UPX info: please choose a target for 'make'"
all mostlyclean clean distclean maintainer-clean:
ifeq ($(BUILD_STUB),1)
$(MAKE) -C src/stub $@
endif
$(MAKE) -C src $@
$(MAKE) -C doc $@
.PHONY: default all mostlyclean clean distclean maintainer-clean
+64 -1
View File
@@ -2,6 +2,67 @@
User visible changes for UPX User visible changes for UPX
================================================================== ==================================================================
Changes in 4.0.2 (30 Jan 2023):
* bug fixes - see https://github.com/upx/upx/milestone/9
Changes in 4.0.1 (16 Nov 2022):
* bug fixes - see https://github.com/upx/upx/milestone/8
Changes in 4.0.0 (28 Oct 2022):
* Switch to semantic versioning
* SECURITY NOTES: emphasize the security context in the docs
* Support easy building from source code with CMake
* Support easy rebuilding the stubs from source with Podman/Docker
* Add integrated doctest C++ testing framework
* Add support for EFI files (PE x86; Kornel Pal)
* win32/pe and win64/pe: set correct SizeOfHeaders in the PE header
* bug fixes - see https://github.com/upx/upx/milestone/6
* bug fixes - see https://github.com/upx/upx/milestone/7
Changes in 3.96 (23 Jan 2020):
* bug fixes - see https://github.com/upx/upx/milestone/5
Changes in 3.95 (26 Aug 2018):
* Flag --android-shlib to work around bad design in Android
* Flag --force-pie when ET_DYN main program is not marked as DF_1_PIE
* Better compatibility with varying layout of address space on Linux
* Support for 4 PT_LOAD layout in ELF generated by binutils-2.31
* bug fixes, particularly better diagnosis of malformed input
* bug fixes - see https://github.com/upx/upx/milestone/4
Changes in 3.94 (12 May 2017):
* Add support for arm64-linux (aka "aarch64").
* Add support for --lzma compression on 64-bit PowerPC (Thierry Fauck).
* For Mach, "upx -d" will unpack a prefix of the file (and warn).
* Various improvements to the ELF formats.
* bug fixes - see https://github.com/upx/upx/milestone/3
Changes in 3.93 (29 Jan 2017):
* Fixed some win32/pe and win64/pe regressions introduced in 3.92
* bug fixes - see https://github.com/upx/upx/milestone/2
Changes in 3.92 (11 Dec 2016):
* INFO: UPX has moved to GitHub - the new home page is https://upx.github.io
* IMPORTANT: all PE formats: internal changes: reunited the diverged source
files - please report all regressions into the bug tracker and try UPX 3.91
in case of problems.
* Support Apple MacOS 10.12 "Sierra", including more-robust de-compression.
* Explicitly diagnose Go-language bad PT_LOAD; recommend hemfix.c.
https://sourceforge.net/p/upx/bugs/195/ https://github.com/pwaller/goupx
* Fix CERT-FI Case 829767 UPX command line tools segfaults.
Received by UPX Team on 2015-May-08; originally reported
by Codenomicon to NCSC-FI on 2015-01-08.
The vulnerabilities were discovered by Joonas Kuorilehto and
Antti Häyrynen from Codenomicon.
* bug fixes - see https://github.com/upx/upx/milestone/1
Changes in 3.91 (30 Sep 2013):
* Added experimental support for Windows 64-bit PE files, based on
work by Stefan Widmann. Please use for testing only!
* bug fixes
==================================================================
Changes in 3.09 (18 Feb 2013): Changes in 3.09 (18 Feb 2013):
* New option --preserve-build-id for GNU ELF. * New option --preserve-build-id for GNU ELF.
* Allow for code signing and LC_UUID on Mac OS X executables. * Allow for code signing and LC_UUID on Mac OS X executables.
@@ -77,7 +138,7 @@ Changes in 2.93 beta (08 Mar 2007):
you have to explicitly use '--lzma' even for '--ultra-brute' here you have to explicitly use '--lzma' even for '--ultra-brute' here
because runtime decompression is about 30 times slower than NRV - because runtime decompression is about 30 times slower than NRV -
which is really noticeable on old machines. which is really noticeable on old machines.
* dos/exe: fixed a rarely occuring bug in relocation handling * dos/exe: fixed a rarely occurring bug in relocation handling
* win32/pe & arm/pe: better icon compression handling * win32/pe & arm/pe: better icon compression handling
Changes in 2.92 beta (23 Jan 2007): Changes in 2.92 beta (23 Jan 2007):
@@ -310,6 +371,8 @@ Changes in 0.99 (25 Feb 2000)
* dos/com and dos/sys: fixed a bad decompressor problem * dos/com and dos/sys: fixed a bad decompressor problem
* linux/386: the counter for the progress indicator was off by one * linux/386: the counter for the progress indicator was off by one
==================================================================
Changes in 0.94 (06 Dec 1999) Changes in 0.94 (06 Dec 1999)
* win32/pe: the stub now calls ExitProcess in case of import errors * win32/pe: the stub now calls ExitProcess in case of import errors
* under DOS and Windows, the environment variable UPX now accepts * under DOS and Windows, the environment variable UPX now accepts
-88
View File
@@ -1,88 +0,0 @@
ooooo ooo ooooooooo. ooooooo ooooo
`888' `8' `888 `Y88. `8888 d8'
888 8 888 .d88' Y888..8P
888 8 888ooo88P' `8888'
888 8 888 .8PY888.
`88. .8' 888 d8' `888b
`YbodP' o888o o888o o88888o
The Ultimate Packer for eXecutables
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
Here are some possible projects from which you can choose if you'd like to
contribute to UPX. Be sure to get in touch with us first to avoid
duplicate efforts.
User interface:
---------------
- Write a nifty Win32 GUI (in C++), but try to keep the size of the
final executable small. Compression should be in a separate
thread that calls do_one_file() [see src/work.cpp].
- Draw a nice UPX icon.
More formats:
-------------
- Amiga
- BeOS
- C64
- elks/8086 (this is a 16-bit linux-8086 kernel)
See http://www.elks.ecs.soton.ac.uk/
- freebsd/386 (generic), freebsd/elf386 (specialized).
Probably could share most of the linux code.
- add support for self-extracting HTML pages using a Javascript stub
(like the AlgART HTML Packer "AHP")
Existing formats:
-----------------
- djgpp2/coff: add support for DLX dynamic loading
(see SEAL http://www.home.sk/public/seal/ )
- dos/com: add support for very long files - convert to exe if necessary
- dos/exe: implement filter support
- linux/i386:
- use the new assembly preprocessor stuff (ie. process the file
headers internally)
- UPX uncompressor daemon
- rewrite the stub in assembly (not sure if this is a good idea...)
- watcom/le: add support for per section compression, LX support, VXD
- win32/pe: display a nice dialog box in the stub in case
of problems (like importing a DLL or function fails)
- win32/pe: per section compression
Compression ratio:
------------------
- invent more effective filters
- I (Markus) will continue to work on better compression algorithms,
so be sure to do better than me if you plan working on this ;-)
Other:
------
- anything else you think that could improve UPX...
Thanks for your contribution.
+39 -61
View File
@@ -8,8 +8,8 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net https://upx.github.io
@@ -18,10 +18,8 @@ WELCOME
Welcome to UPX ! Welcome to UPX !
Please don't forget to read the file LICENSE - UPX is distributed UPX is a free, secure, portable, extendable, high-performance
under the GNU General Public License (GPL) with special exceptions executable packer for several executable formats.
allowing the distribution of all compressed executables, including
commercial programs.
INTRODUCTION INTRODUCTION
@@ -37,106 +35,86 @@ and run exactly as before, with no runtime or memory penalty for most
of the supported formats. of the supported formats.
UPX supports a number of different executable formats, including UPX supports a number of different executable formats, including
Windows 95/98/ME/NT/2000/XP/CE programs and DLLs, DOS programs, Windows programs and DLLs, macOS apps and Linux executables.
and Linux executables and kernels.
UPX is free software distributed under the term of the GNU General UPX is free software distributed under the term of the GNU General
Public License. Full source code is available. Public License. Full source code is available.
UPX may be distributed and used freely, even with commercial applications. UPX may be distributed and used freely, even with commercial applications.
See the UPX License Agreement for details. See the UPX License Agreements for details.
UPX is rated number one in the well known Archive Comparison Test. Visit
http://compression.ca/ .
UPX aims to be Commercial Quality Freeware. SECURITY CONTEXT
================
IMPORTANT NOTE: UPX inherits the security context of any files it handles.
This means that packing, unpacking, or even testing or listing a file requires
the same security considerations as actually executing the file.
Use UPX on trusted files only!
SHORT DOCUMENTATION SHORT DOCUMENTATION
=================== ===================
'upx program.exe' will compress a program or DLL. For best compression 'upx program.exe' will compress a program or DLL. For best compression
results try 'upx --brute program.exe'. results try 'upx --best program.exe' or 'upx --brute program.exe'.
Please see the file UPX.DOC for the full documentation. The files Please see the file UPX.DOC for the full documentation. The files
NEWS and BUGS also contain various tidbits of information. NEWS and BUGS also contain various tidbits of information.
DISCLAIMER
==========
UPX comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
Having said that, we think that UPX is quite stable now. Indeed we
have compressed lots of files without any problems. Also, the
current version has undergone several months of beta testing -
actually it's almost 8 years since our first public beta.
This is the first production quality release, and we plan that future
releases will be backward compatible with this version.
Please report all problems or suggestions to the authors. Thanks.
THE FUTURE THE FUTURE
========== ==========
- We'd really love to support handheld systems like the PalmPilot because - Stay up-to-date with ongoing OS and executable format changes
compression makes a lot of sense here. And - because of the atari/tos
format - we already have a working decompressor in 68000 assembly.
Unfortunately we know next to nothing about the operating system
architecture of such handhelds, so we need some information from
an expert. Please contact us if you think you can help.
- The Linux approach could probably get ported to a lot of other Unix - RISC-V 64 for Linux
variants, at least for other i386 architectures it shouldn't be too
much work. If someone sends me a fresh hard disk and an official - ARM64 for Windows (help wanted)
FreeBSD/OpenBSD/NetBSD/Solaris/BeOS... CD I might take a look at it ;-)
- We will *NOT* add any sort of protection and/or encryption. - We will *NOT* add any sort of protection and/or encryption.
This only gives people a false feeling of security because This only gives people a false feeling of security because
by definition all protectors/compressors can be broken. all "protectors" can be broken by definition.
And don't trust any advertisement of authors of other executable
compressors about this topic - just do a websearch on "unpackers"...
- Fix all remaining bugs - keep your reports coming ;-) - Fix all remaining bugs - please report any issues
https://github.com/upx/upx/issues
- See the file PROJECTS in the source code distribution if you want
to contribute.
COPYRIGHT COPYRIGHT
========= =========
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2013 John F. Reiser Copyright (C) 2000-2023 John F. Reiser
This program may be used freely, and you are welcome to UPX is distributed with full source code under the terms of the
redistribute it under certain conditions. GNU General Public License v2+; either under the pure GPLv2+ (see
the file COPYING), or (at your option) under the GPLv+2 with special
exceptions and restrictions granting the free usage for all binaries
including commercial programs (see the file LICENSE).
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
UPX License Agreement for more details.
You should have received a copy of the UPX License Agreement along You should have received a copy of the UPX License Agreements along
with this program; see the file LICENSE. If not, visit the UPX home page. with this program; see the files COPYING and LICENSE. If not,
visit the UPX home page.
Share and enjoy, Share and enjoy,
Markus & Laszlo Markus & Laszlo & John
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
John F. Reiser
<jreiser@BitWagon.com>
[ The term UPX is a shorthand for the Ultimate Packer for eXecutables [ The term UPX is a shorthand for the Ultimate Packer for eXecutables
and holds no connection with potential owners of registered trademarks and holds no connection with potential owners of registered trademarks
or other rights. ] or other rights. ]
[ Feel free to contact us if you have commercial compression requirements
or interesting job offers. ]
-23
View File
@@ -1,23 +0,0 @@
ooooo ooo ooooooooo. ooooooo ooooo
`888' `8' `888 `Y88. `8888 d8'
888 8 888 .d88' Y888..8P
888 8 888ooo88P' `8888'
888 8 888 .8PY888.
`88. .8' 888 d8' `888b
`YbodP' o888o o888o o88888o
The Ultimate Packer for eXecutables
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
MAJOR NEWS IN UPX 3
===================
The main news since UPX 2 are:
* new format: added support for linux elf/arm
* better compression using the LZMA algorithm (option '--lzma')
+14 -64
View File
@@ -27,21 +27,6 @@ Foreword
Markus & Laszlo Markus & Laszlo
Introduction
------------
Welcome to the UPX source code release!
UPX is not a toy for kids. Apart from basic knowledge about executables
and data compression you will need to be firm in C++, assembler,
Perl and Makefiles. Probably some other things as well.
If you can't manage to compile it then the sources are
probably not for you. Don't email us for help.
The authors use Linux for development. You might want to as well.
Short overview Short overview
-------------- --------------
@@ -56,56 +41,34 @@ Short overview
are #included by the individual executable format handlers. are #included by the individual executable format handlers.
Prerequisites
-------------
- first of all you need to build the UCL compression library
http://www.oberhumer.com/opensource/ucl/
Tools needed to build/modify the UPX sources Tools needed to build/modify the UPX sources
-------------------------------------------- --------------------------------------------
- A C++ compiler supporting inner classes, templates, exceptions - A C++ compiler that supports C++ 17: clang-5, gcc-8 or msvc-2019 16.11
and RTTI. (older or other compilers may work but are unsupported, use at your own risk)
- GNU make 3.81 or better - GNU make
- zlib and zlib-devel [or zlib-dev] software packages for your - CMake 3.13 or better; see https://cmake.org/
host environment, or via http://www.cygwin.org/setup.exe
- lzma SDK, such as from https://sourceforge.net/projects/sevenzip/
files/LZMA%20SDK/4.43/
To compile the packer sources To compile the packer sources
----------------------------- -----------------------------
Set the environment variable UPX_UCLDIR to point to your - just run "make" in the top-level source directory
UCL build directory, e.g.
set UPX_UCLDIR=c:\src\ucl-1.03 (DOS / Windows)
export UPX_UCLDIR=$HOME/local/src/ucl-1.03 (Unix)
Set the environment variable UPX_LZMADIR to point to your
to your unpacked lzma443.tar.bz2 source directory, e.g.
export UPX_LZMADIR=$HOME/local/src/lzma-4.43 (Unix)
export UPX_LZMA_VERSION=0x443 # perhaps 0x459,0x458,0x457,0x449,0x442
Finally type
make
If you want to modify the stub sources you'll also need If you want to modify the stub sources you'll also need
------------------------------------------------------- -------------------------------------------------------
- Perl & Python - Podman/Docker: see misc/rebuild-stubs-with-podman - this
is the preferred way of rebuilding the stubs
- A number of cross-assemblers and cross-compilers - precompiled - otherwise you will need:
binaries for i386-linux hosts are available from - a Linux host system with Perl, Python2 and some older compat-libs
http://sourceforge.net/projects/upx/files/upx-tools/20060823/ - upx-stubtools - a number of cross-assemblers and cross-compilers.
Precompiled binaries for amd64-linux hosts are available from
https://github.com/upx/upx-stubtools/releases
Misc. notes Misc. notes
@@ -121,9 +84,9 @@ Misc. notes
- Use gcc extensions and other compiler specific stuff only through - Use gcc extensions and other compiler specific stuff only through
macros. macros.
***
Some conventions: Some conventions:
-----------------
- follow our coding style - follow our coding style
- indent level = 4 - indent level = 4
@@ -132,17 +95,4 @@ Some conventions:
- Use throwSomeException() functions instead of throw SomeException(): - Use throwSomeException() functions instead of throw SomeException():
this makes the code shorter if used often. this makes the code shorter if used often.
*** # vim:set ts=4 sw=4 et:
Patches/Contributions
- Please send us bug fixes/contributions only using
diff -u oldfile newfile
or
diff -uNr olddirectory newdirectory
# vi:ts=4:et
+3 -4
View File
@@ -8,8 +8,8 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net https://upx.github.io
.___.. . .___.. .
@@ -55,7 +55,6 @@ Salvador Eduardo Tropea
for beta testing for beta testing
Stefan Widmann Stefan Widmann
for the win32/pe TLS callback support for the win32/pe TLS callback support
The WINE project (http://www.winehq.com/) The WINE project (https://www.winehq.com/)
for lots of useful information found in their PE loader sources for lots of useful information found in their PE loader sources
Natascha Natascha
-114
View File
@@ -1,114 +0,0 @@
UPX TODO list. Last updated 2006-12-08.
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
- [None]
OTHER:
- docs: convert docs from upx.pod to use AsciiDoc
- check all <const_cast> to make sure they are not invalid
- throwNotCompressible() is not a real error, so make the output nicer
(info: bla bla). Also ui.cpp (total_*).
-----------------------------------------------------------------------
IMPROVED COMPRESSION RATIO
==========================
- experiment with new filters
- implement filters for dos/exe
- filters: could we exploit a f->firstcall info field ?
- for small programs (e.g. < 64k), try an additional algorithm
to see if it gives better compression
ALL FORMATS
===========
- more thoroughly test the exe-header in canPack()
and throw exceptions when encountering bad values.
- implement `--cpu=486' option to use bswap on the 32-bit formats
(if cpu >= 486)
FORMAT DJGPP2/COFF
==================
- handle overlays
- fix default file extension handling when the --coff option is set
FORMAT DOS/EXE
==============
- implement filters
- add a check so that we don't pack djgpp1 binaries
FORMAT LINUX/386
================
- don't mmap() the temporary output file - this seems to improve
file io speed
FORMAT TMT/ADAM
===============
- the decompressors are already aligned, no need for an
extra alignment
FORMAT WATCOM/LE
================
- handle files without relocations
- the decompressors are already aligned, no need for an
extra alignment
- fix default file extension handling when the --le option is set
- handle holes in the file
FORMAT WIN16/NE
===============
- implement readFileHeader() to correctly identify a win16/ne
executable, so that the call for contribution will get thrown
FORMAT WIN32/PE
===============
- fix the section alignment with the Intel compiler
- decrease runtime memory overhead
3 - difficult) don't compress the BSS section and other holes.
4 - medium - ml) fix when objectalign < 0x1000
4 - easy - ml) put the original offset of moved resources somewhere into
the res.dir. (if it's safe to do)
4 - ??? - ml) fix FIXMEs
5 - medium - ml) try to put the preprocessed imports & relocs back to their
original section if possible. this could save some virtual memory
address space.
+5
View File
@@ -0,0 +1,5 @@
-std=gnu++17
-Ivendor
-fno-strict-aliasing
-fno-strict-overflow
-funsigned-char
+2 -3
View File
@@ -8,8 +8,8 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net https://upx.github.io
Limitations and other things which are not (yet) supported: Limitations and other things which are not (yet) supported:
@@ -48,4 +48,3 @@ win32/pe
* certificates in the image * certificates in the image
* compressing files which contain a big BSS requires lots of memory * compressing files which contain a big BSS requires lots of memory
during compression during compression
+34 -48
View File
@@ -1,29 +1,8 @@
# #
# UPX doc Makefile - needs GNU make 3.80 or better # UPX doc Makefile - needs GNU make, pod2html, pod2man and pod2text
# #
MAKEFLAGS += -rR BUILT_SOURCES = upx.1 upx-doc.html upx-doc.txt
.SUFFIXES:
SHELL = /bin/sh
# internal make variables
comma := ,
empty :=
space := $(empty) $(empty)
tab := $(empty) $(empty)
# update $PATH for our special stub build tools
ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
export PATH := $(HOME)/local/bin/bin-upx:$(PATH)
endif
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
export PATH := $(HOME)/bin/bin-upx:$(PATH)
endif
# /***********************************************************************
# //
# ************************************************************************/
top_srcdir ?= .. top_srcdir ?= ..
@@ -31,55 +10,62 @@ PACKAGE = upx
VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h) VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h) VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
# internal make variables
comma := ,
empty :=
space := $(empty) $(empty)
tab := $(empty) $(empty)
RTRIM := sed -e 's/[ $(tab)]*$$//' RTRIM := sed -e 's/[ $(tab)]*$$//'
DETAB2 := sed -e 's/$(tab)/ /g' DETAB2 := sed -e 's/$(tab)/ /g'
BUILT_SOURCES = upx.1 upx.doc upx.html upx.man upx.ps upx.tex #***********************************************************************
BUILT_SOURCES = upx.1 upx.doc upx.html # targets
#***********************************************************************
.DEFAULT_GOAL = all
### all: $(BUILT_SOURCES) PHONY
### targets
###
all: $(BUILT_SOURCES) mostlyclean clean distclean maintainer-clean: PHONY
rm -f $(BUILT_SOURCES) ./pod2htm*
mostlyclean clean distclean maintainer-clean: #***********************************************************************
rm -f $(BUILT_SOURCES) pod2htm* # rules
#***********************************************************************
.PHONY: all mostlyclean clean distclean maintainer-clean .SUFFIXES:
.SUFFIXES: .1 .html .man .pod .ps .tex .txt
###
### rules
###
.SUFFIXES: .1 .doc .html .man .pod .ps .tex
%.1 : %.pod %.1 : %.pod
pod2man --center=" " --release="$(PACKAGE) $(VERSION)" --date="$(VERSION_DATE)" $< | $(RTRIM) > $@ pod2man --center=" " --release="$(PACKAGE) $(VERSION)" --date="$(VERSION_DATE)" $< | $(RTRIM) > $@
test -s $@
%.doc : %.pod %-doc.html : %.pod
pod2text < $< | $(RTRIM) > $@
%.html : %.pod
pod2html --noindex $< | $(RTRIM) | $(DETAB2) > $@ pod2html --noindex $< | $(RTRIM) | $(DETAB2) > $@
@rm -f pod2htm* @rm -f ./pod2htm*
test -s $@
%.man : %.1 %.man : %.1
nroff -man $< | $(RTRIM) > $@ nroff -man $< | $(RTRIM) > $@
test -s $@
%.ps : %.1 %.ps : %.1
groff -man $< | $(RTRIM) > $@ groff -man $< | $(RTRIM) > $@
test -s $@
%.tex : %.pod %.tex : %.pod
pod2latex $< pod2latex $<
test -s $@
%-doc.txt : %.pod
pod2text < $< | $(RTRIM) > $@
test -s $@
### #***********************************************************************
### dependencies # dependencies
### #***********************************************************************
$(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST) $(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
.DELETE_ON_ERROR: $(BUILT_SOURCES) .DELETE_ON_ERROR: $(BUILT_SOURCES)
.PHONY: PHONY
+1 -1
View File
@@ -1,5 +1,5 @@
Decompressing ELF Directly to Memory on Linux/x86 Decompressing ELF Directly to Memory on Linux/x86
Copyright (C) 2000-2013 John F. Reiser jreiser@BitWagon.com Copyright (C) 2000-2023 John F. Reiser jreiser@BitWagon.com
References: References:
<elf.h> definitions for the ELF file format <elf.h> definitions for the ELF file format
View File
+807
View File
@@ -0,0 +1,807 @@
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>upx - compress or expand executable files</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body>
<h1 id="NAME">NAME</h1>
<p>upx - compress or expand executable files</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<p><b>upx</b> <span style="white-space: nowrap;">[ <i>command</i> ]</span> <span style="white-space: nowrap;">[ <i>options</i> ]</span> <i>filename</i>...</p>
<h1 id="ABSTRACT">ABSTRACT</h1>
<pre><code> The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 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>
<h1 id="DISCLAIMER">DISCLAIMER</h1>
<p><b>UPX</b> comes with ABSOLUTELY NO WARRANTY; for details see the file COPYING.</p>
<p>Please report all problems or suggestions to the authors. Thanks.</p>
<h1 id="SECURITY-CONTEXT">SECURITY CONTEXT</h1>
<p>IMPORTANT NOTE: <b>UPX</b> inherits the security context of any files it handles.</p>
<p>This means that packing, unpacking, or even testing or listing a file requires the same security considerations as actually executing the file.</p>
<p>Use <b>UPX</b> on trusted files only!</p>
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p><b>UPX</b> is a versatile executable packer with the following features:</p>
<pre><code>- secure: as UPX is documented Open Source since many years any relevant
Security/Antivirus software is able to peek inside UPX compressed
apps to verify them
- excellent compression ratio: typically compresses better than Zip,
use UPX to decrease the size of your distribution !
- very fast decompression: more than 500 MB/sec on any reasonably modern
machine
- no memory overhead for your compressed executables for most of the
supported formats because of in-place decompression
- safe: you can list, test and unpack your executables.
Also, a checksum of both the compressed and uncompressed file is
maintained internally.
- universal: UPX can pack a number of executable formats, including
Windows programs and DLLs, macOS apps and Linux executables
- portable: UPX is written in portable endian-neutral C++
- extendable: because of the class layout it&#39;s very easy to support
new executable formats or add new compression algorithms
- free: UPX is distributed with full source code under the GNU General
Public License v2+, with special exceptions granting the free usage
for commercial programs</code></pre>
<p>You probably understand now why we call <b>UPX</b> the &quot;<i>ultimate</i>&quot; executable packer.</p>
<h1 id="COMMANDS">COMMANDS</h1>
<h2 id="Compress">Compress</h2>
<p>This is the default operation, eg. <b>upx yourfile.exe</b> will compress the file specified on the command line.</p>
<h2 id="Decompress">Decompress</h2>
<p>All <b>UPX</b> supported file formats can be unpacked using the <b>-d</b> switch, eg. <b>upx -d yourfile.exe</b> will uncompress the file you&#39;ve just compressed.</p>
<h2 id="Test">Test</h2>
<p>The <b>-t</b> command tests the integrity of the compressed and uncompressed data, eg. <b>upx -t yourfile.exe</b> check whether your file can be safely decompressed. Note, that this command doesn&#39;t check the whole file, only the part that will be uncompressed during program execution. This means that you should not use this command instead of a virus checker.</p>
<h2 id="List">List</h2>
<p>The <b>-l</b> command prints out some information about the compressed files specified on the command line as parameters, eg <b>upx -l yourfile.exe</b> shows the compressed / uncompressed size and the compression ratio of <i>yourfile.exe</i>.</p>
<h1 id="OPTIONS">OPTIONS</h1>
<p><b>-q</b>: be quiet, suppress warnings</p>
<p><b>-q -q</b> (or <b>-qq</b>): be very quiet, suppress errors</p>
<p><b>-q -q -q</b> (or <b>-qqq</b>): produce no output at all</p>
<p><b>--help</b>: prints the help</p>
<p><b>--version</b>: print the version of <b>UPX</b></p>
<p><b>--exact</b>: when compressing, require to be able to get a byte-identical file after decompression with option <b>-d</b>. [NOTE: this is work in progress and is not supported for all formats yet. If you do care, as a workaround you can compress and then decompress your program a first time - any further compress-decompress steps should then yield byte-identical results as compared to the first decompressed version.]</p>
<p><b>-k</b>: keep backup files</p>
<p><b>-o file</b>: write output to file</p>
<p>[ ...more docs need to be written... - type `<b>upx --help</b>&#39; for now ]</p>
<h1 id="COMPRESSION-LEVELS-TUNING">COMPRESSION LEVELS &amp; TUNING</h1>
<p><b>UPX</b> offers ten different compression levels from <b>-1</b> to <b>-9</b>, and <b>--best</b>. The default compression level is <b>-8</b> for files smaller than 512 KiB, and <b>-7</b> otherwise.</p>
<ul>
<li><p>Compression levels 1, 2 and 3 are pretty fast.</p>
</li>
<li><p>Compression levels 4, 5 and 6 achieve a good time/ratio performance.</p>
</li>
<li><p>Compression levels 7, 8 and 9 favor compression ratio over speed.</p>
</li>
<li><p>Compression level <b>--best</b> may take a long time.</p>
</li>
</ul>
<p>Note that compression level <b>--best</b> can be somewhat slow for large files, but you definitely should use it when releasing a final version of your program.</p>
<p>Quick info for achieving the best compression ratio:</p>
<ul>
<li><p>Try <b>upx --brute --no-lzma myfile.exe</b> or even <b>upx --ultra-brute --no-lzma myfile.exe</b>.</p>
</li>
<li><p>The option <b>--lzma</b> enables LZMA compression, which compresses better but is *significantly slower* at decompression. You probably do not want to use it for large files.</p>
<p>(Note that <b>--lzma</b> is automatically enabled by <b>--all-methods</b> and <b>--brute</b>, use <b>--no-lzma</b> to override.)</p>
</li>
<li><p>Try if <b>--overlay=strip</b> works.</p>
</li>
<li><p>For win32/pe programs there&#39;s <b>--strip-relocs=0</b>. See notes below.</p>
</li>
</ul>
<h1 id="OVERLAY-HANDLING-OPTIONS">OVERLAY HANDLING OPTIONS</h1>
<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>
<pre><code>--overlay=copy Copy any extra data attached to the file. [DEFAULT]
--overlay=strip Strip any overlay from the program instead of
copying it. Be warned, this may make the compressed
program crash or otherwise unusable.
--overlay=skip Refuse to compress any program which has an overlay.</code></pre>
<h1 id="ENVIRONMENT-VARIABLE">ENVIRONMENT VARIABLE</h1>
<p>The environment variable <b>UPX</b> can hold a set of default options for <b>UPX</b>. These options are interpreted first and can be overwritten by explicit command line parameters. For example:</p>
<pre><code>for DOS/Windows: set UPX=-9 --compress-icons#0
for sh/ksh/zsh: UPX=&quot;-9 --compress-icons=0&quot;; export UPX
for csh/tcsh: setenv UPX &quot;-9 --compress-icons=0&quot;</code></pre>
<p>Under DOS/Windows you must use &#39;#&#39; instead of &#39;=&#39; when setting the environment variable because of a COMMAND.COM limitation.</p>
<p>Not all of the options are valid in the environment variable - <b>UPX</b> will tell you.</p>
<p>You can explicitly use the <b>--no-env</b> option to ignore the environment variable.</p>
<h1 id="NOTES-FOR-THE-SUPPORTED-EXECUTABLE-FORMATS">NOTES FOR THE SUPPORTED EXECUTABLE FORMATS</h1>
<h2 id="NOTES-FOR-ATARI-TOS">NOTES FOR ATARI/TOS</h2>
<p>This is the executable format used by the Atari ST/TT, a Motorola 68000 based personal computer which was popular in the late &#39;80s. Support of this format is only because of nostalgic feelings of one of the authors and serves no practical purpose :-). See https://freemint.github.io for more info.</p>
<p>Packed programs will be byte-identical to the original after uncompression. All debug information will be stripped, though.</p>
<p>Extra options available for this executable format:</p>
<pre><code>--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.</code></pre>
<h2 id="NOTES-FOR-BVMLINUZ-I386">NOTES FOR BVMLINUZ/I386</h2>
<p>Same as vmlinuz/i386.</p>
<h2 id="NOTES-FOR-DOS-COM">NOTES FOR DOS/COM</h2>
<p>Obviously <b>UPX</b> won&#39;t work with executables that want to read data from themselves (like some commandline utilities that ship with Win95/98/ME).</p>
<p>Compressed programs only work on a 286+.</p>
<p>Packed programs will be byte-identical to the original after uncompression.</p>
<p>Maximum uncompressed size: ~65100 bytes.</p>
<p>Extra options available for this executable format:</p>
<pre><code>--8086 Create an executable that works on any 8086 CPU.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.</code></pre>
<h2 id="NOTES-FOR-DOS-EXE">NOTES FOR DOS/EXE</h2>
<p>dos/exe stands for all &quot;normal&quot; 16-bit DOS executables.</p>
<p>Obviously <b>UPX</b> won&#39;t work with executables that want to read data from themselves (like some command line utilities that ship with Win95/98/ME).</p>
<p>Compressed programs only work on a 286+.</p>
<p>Extra options available for this executable format:</p>
<pre><code>--8086 Create an executable that works on any 8086 CPU.
--no-reloc Use no relocation records in the exe header.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.</code></pre>
<h2 id="NOTES-FOR-DOS-SYS">NOTES FOR DOS/SYS</h2>
<p>Compressed programs only work on a 286+.</p>
<p>Packed programs will be byte-identical to the original after uncompression.</p>
<p>Maximum uncompressed size: ~65350 bytes.</p>
<p>Extra options available for this executable format:</p>
<pre><code>--8086 Create an executable that works on any 8086 CPU.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.</code></pre>
<h2 id="NOTES-FOR-DJGPP2-COFF">NOTES FOR DJGPP2/COFF</h2>
<p>First of all, it is recommended to use <b>UPX</b> *instead* of <b>strip</b>. strip has the very bad habit of replacing your stub with its own (outdated) version. Additionally <b>UPX</b> corrects a bug/feature in strip v2.8.x: it will fix the 4 KiB alignment of the stub.</p>
<p><b>UPX</b> includes the full functionality of stubify. This means it will automatically stubify your COFF files. Use the option <b>--coff</b> to disable this functionality (see below).</p>
<p><b>UPX</b> automatically handles Allegro packfiles.</p>
<p>The DLM format (a rather exotic shared library extension) is not supported.</p>
<p>Packed programs will be byte-identical to the original after uncompression. All debug information and trailing garbage will be stripped, though.</p>
<p>Extra options available for this executable format:</p>
<pre><code>--coff Produce COFF output instead of EXE. By default
UPX keeps your current stub.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.</code></pre>
<h2 id="NOTES-FOR-LINUX-general">NOTES FOR LINUX [general]</h2>
<p>Introduction</p>
<pre><code>Linux/386 support in UPX consists of 3 different executable formats,
one optimized for ELF executables (&quot;linux/elf386&quot;), one optimized
for shell scripts (&quot;linux/sh386&quot;), and one generic format
(&quot;linux/386&quot;).
We will start with a general discussion first, but please
also read the relevant docs for each of the individual formats.
Also, there is special support for bootable kernels - see the
description of the vmlinuz/386 format.</code></pre>
<p>General user&#39;s overview</p>
<pre><code>Running a compressed executable program trades less space on a
``permanent&#39;&#39; storage medium (such as a hard disk, floppy disk,
CD-ROM, flash memory, EPROM, etc.) for more space in one or more
``temporary&#39;&#39; storage media (such as RAM, swap space, /tmp, etc.).
Running a compressed executable also requires some additional CPU
cycles to generate the compressed executable in the first place,
and to decompress it at each invocation.
How much space is traded? It depends on the executable, but many
programs save 30% to 50% of permanent disk space. How much CPU
overhead is there? Again, it depends on the executable, but
decompression speed generally is at least many megabytes per second,
and frequently is limited by the speed of the underlying disk
or network I/O.
Depending on the statistics of usage and access, and the relative
speeds of CPU, RAM, swap space, /tmp, and file system storage, then
invoking and running a compressed executable can be faster than
directly running the corresponding uncompressed program.
The operating system might perform fewer expensive I/O operations
to invoke the compressed program. Paging to or from swap space
or /tmp might be faster than paging from the general file system.
``Medium-sized&#39;&#39; programs which access about 1/3 to 1/2 of their
stored program bytes can do particularly well with compression.
Small programs tend not to benefit as much because the absolute
savings is less. Big programs tend not to benefit proportionally
because each invocation may use only a small fraction of the program,
yet UPX decompresses the entire program before invoking it.
But in environments where disk or flash memory storage is limited,
then compression may win anyway.
Currently, executables compressed by UPX do not share RAM at runtime
in the way that executables mapped from a file system do. As a
result, if the same program is run simultaneously by more than one
process, then using the compressed version will require more RAM and/or
swap space. So, shell programs (bash, csh, etc.) and ``make&#39;&#39;
might not be good candidates for compression.
UPX recognizes three executable formats for Linux: Linux/elf386,
Linux/sh386, and Linux/386. Linux/386 is the most generic format;
it accommodates any file that can be executed. At runtime, the UPX
decompression stub re-creates in /tmp a copy of the original file,
and then the copy is (re-)executed with the same arguments.
ELF binary executables prefer the Linux/elf386 format by default,
because UPX decompresses them directly into RAM, uses only one
exec, does not use space in /tmp, and does not use /proc.
Shell scripts where the underlying shell accepts a ``-c&#39;&#39; argument
can use the Linux/sh386 format. UPX decompresses the shell script
into low memory, then maps the shell and passes the entire text of the
script as an argument with a leading ``-c&#39;&#39;.</code></pre>
<p>General benefits:</p>
<pre><code>- UPX can compress all executables, be it AOUT, ELF, libc4, libc5,
libc6, Shell/Perl/Python/... scripts, standalone Java .class
binaries, or whatever...
All scripts and programs will work just as before.
- Compressed programs are completely self-contained. No need for
any external program.
- UPX keeps your original program untouched. This means that
after decompression you will have a byte-identical version,
and you can use UPX as a file compressor just like gzip.
[ Note that UPX maintains a checksum of the file internally,
so it is indeed a reliable alternative. ]
- As the stub only uses syscalls and isn&#39;t linked against libc it
should run under any Linux configuration that can run ELF
binaries.
- For the same reason compressed executables should run under
FreeBSD and other systems which can run Linux binaries.
[ Please send feedback on this topic ]</code></pre>
<p>General drawbacks:</p>
<pre><code>- It is not advisable to compress programs which usually have many
instances running (like `sh&#39; or `make&#39;) because the common segments of
compressed programs won&#39;t be shared any longer between different
processes.
- `ldd&#39; and `size&#39; won&#39;t show anything useful because all they
see is the statically linked stub. Since version 0.82 the section
headers are stripped from the UPX stub and `size&#39; doesn&#39;t even
recognize the file format. The file patches/patch-elfcode.h has a
patch to fix this bug in `size&#39; and other programs which use GNU BFD.</code></pre>
<p>General notes:</p>
<pre><code>- As UPX leaves your original program untouched it is advantageous
to strip it before compression.
- If you compress a script you will lose platform independence -
this could be a problem if you are using NFS mounted disks.
- Compression of suid, guid and sticky-bit programs is rejected
because of possible security implications.
- For the same reason there is no sense in making any compressed
program suid.
- Obviously UPX won&#39;t work with executables that want to read data
from themselves. E.g., this might be a problem for Perl scripts
which access their __DATA__ lines.
- In case of internal errors the stub will abort with exitcode 127.
Typical reasons for this to happen are that the program has somehow
been modified after compression.
Running `strace -o strace.log compressed_file&#39; will tell you more.</code></pre>
<h2 id="NOTES-FOR-LINUX-ELF386">NOTES FOR LINUX/ELF386</h2>
<p>Please read the general Linux description first.</p>
<p>The linux/elf386 format decompresses directly into RAM, uses only one exec, does not use space in /tmp, and does not use /proc.</p>
<p>Linux/elf386 is automatically selected for Linux ELF executables.</p>
<p>Packed programs will be byte-identical to the original after uncompression.</p>
<p>How it works:</p>
<pre><code>For ELF executables, UPX decompresses directly to memory, simulating
the mapping that the operating system kernel uses during exec(),
including the PT_INTERP program interpreter (if any).
The brk() is set by a special PT_LOAD segment in the compressed
executable itself. UPX then wipes the stack clean except for
arguments, environment variables, and Elf_auxv entries (this is
required by bugs in the startup code of /lib/ld-linux.so as of
May 2000), and transfers control to the program interpreter or
the e_entry address of the original executable.
The UPX stub is about 1700 bytes long, partly written in assembler
and only uses kernel syscalls. It is not linked against any libc.</code></pre>
<p>Specific drawbacks:</p>
<pre><code>- For linux/elf386 and linux/sh386 formats, you will be relying on
RAM and swap space to hold all of the decompressed program during
the lifetime of the process. If you already use most of your swap
space, then you may run out. A system that is &quot;out of memory&quot;
can become fragile. Many programs do not react gracefully when
malloc() returns 0. With newer Linux kernels, the kernel
may decide to kill some processes to regain memory, and you
may not like the kernel&#39;s choice of which to kill. Running
/usr/bin/top is one way to check on the usage of swap space.</code></pre>
<p>Extra options available for this executable format:</p>
<pre><code>(none)</code></pre>
<h2 id="NOTES-FOR-LINUX-SH386">NOTES FOR LINUX/SH386</h2>
<p>Please read the general Linux description first.</p>
<p>Shell scripts where the underling shell accepts a ``-c&#39;&#39; argument can use the Linux/sh386 format. <b>UPX</b> decompresses the shell script into low memory, then maps the shell and passes the entire text of the script as an argument with a leading ``-c&#39;&#39;. It does not use space in /tmp, and does not use /proc.</p>
<p>Linux/sh386 is automatically selected for shell scripts that use a known shell.</p>
<p>Packed programs will be byte-identical to the original after uncompression.</p>
<p>How it works:</p>
<pre><code>For shell script executables (files beginning with &quot;#!/&quot; or &quot;#! /&quot;)
where the shell is known to accept &quot;-c &lt;command&gt;&quot;, UPX decompresses
the file into low memory, then maps the shell (and its PT_INTERP),
and passes control to the shell with the entire decompressed file
as the argument after &quot;-c&quot;. Known shells are sh, ash, bash, bsh, csh,
ksh, tcsh, pdksh. Restriction: UPX cannot use this method
for shell scripts which use the one optional string argument after
the shell name in the script (example: &quot;#! /bin/sh option3\n&quot;.)
The UPX stub is about 1700 bytes long, partly written in assembler
and only uses kernel syscalls. It is not linked against any libc.</code></pre>
<p>Specific drawbacks:</p>
<pre><code>- For linux/elf386 and linux/sh386 formats, you will be relying on
RAM and swap space to hold all of the decompressed program during
the lifetime of the process. If you already use most of your swap
space, then you may run out. A system that is &quot;out of memory&quot;
can become fragile. Many programs do not react gracefully when
malloc() returns 0. With newer Linux kernels, the kernel
may decide to kill some processes to regain memory, and you
may not like the kernel&#39;s choice of which to kill. Running
/usr/bin/top is one way to check on the usage of swap space.</code></pre>
<p>Extra options available for this executable format:</p>
<pre><code>(none)</code></pre>
<h2 id="NOTES-FOR-LINUX-386">NOTES FOR LINUX/386</h2>
<p>Please read the general Linux description first.</p>
<p>The generic linux/386 format decompresses to /tmp and needs /proc file system support. It starts the decompressed program via the execve() syscall.</p>
<p>Linux/386 is only selected if the specialized linux/elf386 and linux/sh386 won&#39;t recognize a file.</p>
<p>Packed programs will be byte-identical to the original after uncompression.</p>
<p>How it works:</p>
<pre><code>For files which are not ELF and not a script for a known &quot;-c&quot; shell,
UPX uses kernel execve(), which first requires decompressing to a
temporary file in the file system. Interestingly -
because of the good memory management of the Linux kernel - this
often does not introduce a noticeable delay, and in fact there
will be no disk access at all if you have enough free memory as
the entire process takes places within the file system buffers.
A compressed executable consists of the UPX stub and an overlay
which contains the original program in a compressed form.
The UPX stub is a statically linked ELF executable and does
the following at program startup:
1) decompress the overlay to a temporary location in /tmp
2) open the temporary file for reading
3) try to delete the temporary file and start (execve)
the uncompressed program in /tmp using /proc/&lt;pid&gt;/fd/X as
attained by step 2)
4) if that fails, fork off a subprocess to clean up and
start the program in /tmp in the meantime
The UPX stub is about 1700 bytes long, partly written in assembler
and only uses kernel syscalls. It is not linked against any libc.</code></pre>
<p>Specific drawbacks:</p>
<pre><code>- You need additional free disk space for the uncompressed program
in your /tmp directory. This program is deleted immediately after
decompression, but you still need it for the full execution time
of the program.
- You must have /proc file system support as the stub wants to open
/proc/&lt;pid&gt;/exe and needs /proc/&lt;pid&gt;/fd/X. This also means that you
cannot compress programs that are used during the boot sequence
before /proc is mounted.
- Utilities like `top&#39; will display numerical values in the process
name field. This is because Linux computes the process name from
the first argument of the last execve syscall (which is typically
something like /proc/&lt;pid&gt;/fd/3).
- Because of temporary decompression to disk the decompression speed
is not as fast as with the other executable formats. Still, I can see
no noticeable delay when starting programs like my ~3 MiB emacs (which
is less than 1 MiB when compressed :-).</code></pre>
<p>Extra options available for this executable format:</p>
<pre><code>--force-execve Force the use of the generic linux/386 &quot;execve&quot;
format, i.e. do not try the linux/elf386 and
linux/sh386 formats.</code></pre>
<h2 id="NOTES-FOR-PS1-EXE">NOTES FOR PS1/EXE</h2>
<p>This is the executable format used by the Sony PlayStation (PSone), a MIPS R3000 based gaming console which is popular since the late &#39;90s. Support of this format is very similar to the Atari one, because of nostalgic feelings of one of the authors.</p>
<p>Packed programs will be byte-identical to the original after uncompression, until further notice.</p>
<p>Maximum uncompressed size: ~1.89 / ~7.60 MiB.</p>
<p>Notes:</p>
<pre><code>- UPX creates as default a suitable executable for CD-Mastering
and console transfer. For a CD-Master main executable you could also try
the special option &quot;--boot-only&quot; as described below.
It has been reported that upx packed executables are fully compatible with
the Sony PlayStation 2 (PS2, PStwo) and Sony PlayStation Portable (PSP) in
Sony PlayStation (PSone) emulation mode.
- Normally the packed files use the same memory areas like the uncompressed
versions, so they will not override other memory areas while unpacking.
If this isn&#39;t possible UPX will abort showing a &#39;packed data overlap&#39;
error. With the &quot;--force&quot; option UPX will relocate the loading address
for the packed file, but this isn&#39;t a real problem if it is a single or
the main executable.</code></pre>
<p>Extra options available for this executable format:</p>
<pre><code>--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--8-bit Uses 8 bit size compression [default: 32 bit]
--8mib-ram PSone has 8 MiB ram available [default: 2 MiB]
--boot-only This format is for main exes and CD-Mastering only !
It may slightly improve the compression ratio,
decompression routines are faster than default ones.
But it cannot be used for console transfer !
--no-align This option disables CD mode 2 data sector format
alignment. May slightly improves the compression ratio,
but the compressed executable will not boot from a CD.
Use it for console transfer only !</code></pre>
<h2 id="NOTES-FOR-RTM32-PE-and-ARM-PE">NOTES FOR RTM32/PE and ARM/PE</h2>
<p>Same as win32/pe.</p>
<h2 id="NOTES-FOR-TMT-ADAM">NOTES FOR TMT/ADAM</h2>
<p>This format is used by the TMT Pascal compiler - see http://www.tmt.com/ .</p>
<p>Extra options available for this executable format:</p>
<pre><code>--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.</code></pre>
<h2 id="NOTES-FOR-VMLINUZ-386">NOTES FOR VMLINUZ/386</h2>
<p>The vmlinuz/386 and bvmlinuz/386 formats take a gzip-compressed bootable Linux kernel image (&quot;vmlinuz&quot;, &quot;zImage&quot;, &quot;bzImage&quot;), gzip-decompress it and re-compress it with the <b>UPX</b> compression method.</p>
<p>vmlinuz/386 is completely unrelated to the other Linux executable formats, and it does not share any of their drawbacks.</p>
<p>Notes:</p>
<pre><code>- Be sure that &quot;vmlinuz/386&quot; or &quot;bvmlinuz/386&quot; is displayed
during compression - otherwise a wrong executable format
may have been used, and the kernel won&#39;t boot.</code></pre>
<p>Benefits:</p>
<pre><code>- Better compression (but note that the kernel was already compressed,
so the improvement is not as large as with other formats).
Still, the bytes saved may be essential for special needs like
boot disks.
For example, this is what I get for my 2.2.16 kernel:
1589708 vmlinux
641073 bzImage [original]
560755 bzImage.upx [compressed by &quot;upx -9&quot;]
- Much faster decompression at kernel boot time (but kernel
decompression speed is not really an issue these days).</code></pre>
<p>Drawbacks:</p>
<pre><code>(none)</code></pre>
<p>Extra options available for this executable format:</p>
<pre><code>--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.</code></pre>
<h2 id="NOTES-FOR-WATCOM-LE">NOTES FOR WATCOM/LE</h2>
<p><b>UPX</b> has been successfully tested with the following extenders: DOS4G, DOS4GW, PMODE/W, DOS32a, CauseWay. The WDOS/X extender is partly supported (for details see the file bugs BUGS).</p>
<p>DLLs and the LX format are not supported.</p>
<p>Extra options available for this executable format:</p>
<pre><code>--le Produce an unbound LE output instead of
keeping the current stub.</code></pre>
<h2 id="NOTES-FOR-WIN32-PE">NOTES FOR WIN32/PE</h2>
<p>The PE support in <b>UPX</b> is quite stable now, but probably there are still some incompatibilities with some files.</p>
<p>Because of the way <b>UPX</b> (and other packers for this format) works, you can see increased memory usage of your compressed files because the whole program is loaded into memory at startup. If you start several instances of huge compressed programs you&#39;re wasting memory because the common segments of the program won&#39;t get shared across the instances. On the other hand if you&#39;re compressing only smaller programs, or running only one instance of larger programs, then this penalty is smaller, but it&#39;s still there.</p>
<p>If you&#39;re running executables from network, then compressed programs will load faster, and require less bandwidth during execution.</p>
<p>DLLs are supported. But UPX compressed DLLs can not share common data and code when they got used by multiple applications. So compressing msvcrt.dll is a waste of memory, but compressing the dll plugins of a particular application may be a better idea.</p>
<p>Screensavers are supported, with the restriction that the filename must end with &quot;.scr&quot; (as screensavers are handled slightly different than normal exe files).</p>
<p>UPX compressed PE files have some minor memory overhead (usually in the 10 - 30 KiB range) which can be seen by specifying the &quot;-i&quot; command line switch during compression.</p>
<p>Extra options available for this executable format:</p>
<pre><code>--compress-exports=0 Don&#39;t compress the export section.
Use this if you plan to run the compressed
program under Wine.
--compress-exports=1 Compress the export section. [DEFAULT]
Compression of the export section can improve the
compression ratio quite a bit but may not work
with all programs (like winword.exe).
UPX never compresses the export section of a DLL
regardless of this option.
--compress-icons=0 Don&#39;t compress any icons.
--compress-icons=1 Compress all but the first icon.
--compress-icons=2 Compress all icons which are not in the
first icon directory. [DEFAULT]
--compress-icons=3 Compress all icons.
--compress-resources=0 Don&#39;t compress any resources at all.
--keep-resource=list Don&#39;t compress resources specified by the list.
The members of the list are separated by commas.
A list member has the following format: I&lt;type[/name]&gt;.
I&lt;Type&gt; is the type of the resource. Standard types
must be specified as decimal numbers, user types can be
specified by decimal IDs or strings. I&lt;Name&gt; is the
identifier of the resource. It can be a decimal number
or a string. For example:
--keep-resource=2/MYBITMAP,5,6/12345
UPX won&#39;t compress the named bitmap resource &quot;MYBITMAP&quot;,
it leaves every dialog (5) resource uncompressed, and
it won&#39;t touch the string table resource with identifier
12345.
--force Force compression even when there is an
unexpected value in a header field.
Use with care.
--strip-relocs=0 Don&#39;t strip relocation records.
--strip-relocs=1 Strip relocation records. [DEFAULT]
This option only works on executables with base
address greater or equal to 0x400000. Usually the
compressed files becomes smaller, but some files
may become larger. Note that the resulting file will
not work under Windows 3.x (Win32s).
UPX never strips relocations from a DLL
regardless of this option.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.</code></pre>
<h1 id="DIAGNOSTICS">DIAGNOSTICS</h1>
<p>Exit status is normally 0; if an error occurs, exit status is 1. If a warning occurs, exit status is 2.</p>
<p><b>UPX</b>&#39;s diagnostics are intended to be self-explanatory.</p>
<h1 id="BUGS">BUGS</h1>
<p>Please report all bugs immediately to the authors.</p>
<h1 id="AUTHORS">AUTHORS</h1>
<pre><code>Markus F.X.J. Oberhumer &lt;markus@oberhumer.com&gt;
http://www.oberhumer.com
Laszlo Molnar &lt;ezerotven+github@gmail.com&gt;
John F. Reiser &lt;jreiser@BitWagon.com&gt;
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-2023 Laszlo Molnar</p>
<p>Copyright (C) 2000-2023 John F. Reiser</p>
<p>Copyright (C) 2002-2023 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>
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>
<p>You should have received a copy of the UPX License Agreements along with this program; see the files COPYING and LICENSE. If not, visit the UPX home page.</p>
</body>
</html>
+842
View File
@@ -0,0 +1,842 @@
NAME
upx - compress or expand executable files
SYNOPSIS
upx [ *command* ] [ *options* ] *filename*...
ABSTRACT
The Ultimate Packer for eXecutables
Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
https://upx.github.io
UPX is a portable, extendable, high-performance executable packer for
several different executable formats. It achieves an excellent
compression ratio and offers **very** fast decompression. Your
executables suffer no memory overhead or other drawbacks for most of the
formats supported, because of in-place decompression.
DISCLAIMER
UPX comes with ABSOLUTELY NO WARRANTY; for details see the file COPYING.
Please report all problems or suggestions to the authors. Thanks.
SECURITY CONTEXT
IMPORTANT NOTE: UPX inherits the security context of any files it
handles.
This means that packing, unpacking, or even testing or listing a file
requires the same security considerations as actually executing the
file.
Use UPX on trusted files only!
DESCRIPTION
UPX is a versatile executable packer with the following features:
- secure: as UPX is documented Open Source since many years any relevant
Security/Antivirus software is able to peek inside UPX compressed
apps to verify them
- excellent compression ratio: typically compresses better than Zip,
use UPX to decrease the size of your distribution !
- very fast decompression: more than 500 MB/sec on any reasonably modern
machine
- no memory overhead for your compressed executables for most of the
supported formats because of in-place decompression
- safe: you can list, test and unpack your executables.
Also, a checksum of both the compressed and uncompressed file is
maintained internally.
- universal: UPX can pack a number of executable formats, including
Windows programs and DLLs, macOS apps and Linux executables
- portable: UPX is written in portable endian-neutral C++
- extendable: because of the class layout it's very easy to support
new executable formats or add new compression algorithms
- free: UPX is distributed with full source code under the GNU General
Public License v2+, with special exceptions granting the free usage
for commercial programs
You probably understand now why we call UPX the "*ultimate*" executable
packer.
COMMANDS
Compress
This is the default operation, eg. upx yourfile.exe will compress the
file specified on the command line.
Decompress
All UPX supported file formats can be unpacked using the -d switch, eg.
upx -d yourfile.exe will uncompress the file you've just compressed.
Test
The -t command tests the integrity of the compressed and uncompressed
data, eg. upx -t yourfile.exe check whether your file can be safely
decompressed. Note, that this command doesn't check the whole file, only
the part that will be uncompressed during program execution. This means
that you should not use this command instead of a virus checker.
List
The -l command prints out some information about the compressed files
specified on the command line as parameters, eg upx -l yourfile.exe
shows the compressed / uncompressed size and the compression ratio of
*yourfile.exe*.
OPTIONS
-q: be quiet, suppress warnings
-q -q (or -qq): be very quiet, suppress errors
-q -q -q (or -qqq): produce no output at all
--help: prints the help
--version: print the version of UPX
--exact: when compressing, require to be able to get a byte-identical
file after decompression with option -d. [NOTE: this is work in progress
and is not supported for all formats yet. If you do care, as a
workaround you can compress and then decompress your program a first
time - any further compress-decompress steps should then yield
byte-identical results as compared to the first decompressed version.]
-k: keep backup files
-o file: write output to file
[ ...more docs need to be written... - type `upx --help' for now ]
COMPRESSION LEVELS & TUNING
UPX offers ten different compression levels from -1 to -9, and --best.
The default compression level is -8 for files smaller than 512 KiB, and
-7 otherwise.
* Compression levels 1, 2 and 3 are pretty fast.
* Compression levels 4, 5 and 6 achieve a good time/ratio performance.
* Compression levels 7, 8 and 9 favor compression ratio over speed.
* Compression level --best may take a long time.
Note that compression level --best can be somewhat slow for large files,
but you definitely should use it when releasing a final version of your
program.
Quick info for achieving the best compression ratio:
* Try upx --brute --no-lzma myfile.exe or even upx --ultra-brute
--no-lzma myfile.exe.
* The option --lzma enables LZMA compression, which compresses better
but is *significantly slower* at decompression. You probably do not
want to use it for large files.
(Note that --lzma is automatically enabled by --all-methods and
--brute, use --no-lzma to override.)
* Try if --overlay=strip works.
* For win32/pe programs there's --strip-relocs=0. See notes below.
OVERLAY HANDLING OPTIONS
Info: An "overlay" means auxiliary data attached after the logical end
of an executable, and it often contains application specific data (this
is a common practice to avoid an extra data file, though it would be
better to use resource sections).
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.
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
--overlay=strip Strip any overlay from the program instead of
copying it. Be warned, this may make the compressed
program crash or otherwise unusable.
--overlay=skip Refuse to compress any program which has an overlay.
ENVIRONMENT VARIABLE
The environment variable UPX can hold a set of default options for UPX.
These options are interpreted first and can be overwritten by explicit
command line parameters. For example:
for DOS/Windows: set UPX=-9 --compress-icons#0
for sh/ksh/zsh: UPX="-9 --compress-icons=0"; export UPX
for csh/tcsh: setenv UPX "-9 --compress-icons=0"
Under DOS/Windows you must use '#' instead of '=' when setting the
environment variable because of a COMMAND.COM limitation.
Not all of the options are valid in the environment variable - UPX will
tell you.
You can explicitly use the --no-env option to ignore the environment
variable.
NOTES FOR THE SUPPORTED EXECUTABLE FORMATS
NOTES FOR ATARI/TOS
This is the executable format used by the Atari ST/TT, a Motorola 68000
based personal computer which was popular in the late '80s. Support of
this format is only because of nostalgic feelings of one of the authors
and serves no practical purpose :-). See https://freemint.github.io for
more info.
Packed programs will be byte-identical to the original after
uncompression. All debug information will be stripped, though.
Extra options available for this executable format:
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
NOTES FOR BVMLINUZ/I386
Same as vmlinuz/i386.
NOTES FOR DOS/COM
Obviously UPX won't work with executables that want to read data from
themselves (like some commandline utilities that ship with Win95/98/ME).
Compressed programs only work on a 286+.
Packed programs will be byte-identical to the original after
uncompression.
Maximum uncompressed size: ~65100 bytes.
Extra options available for this executable format:
--8086 Create an executable that works on any 8086 CPU.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
NOTES FOR DOS/EXE
dos/exe stands for all "normal" 16-bit DOS executables.
Obviously UPX won't work with executables that want to read data from
themselves (like some command line utilities that ship with
Win95/98/ME).
Compressed programs only work on a 286+.
Extra options available for this executable format:
--8086 Create an executable that works on any 8086 CPU.
--no-reloc Use no relocation records in the exe header.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
NOTES FOR DOS/SYS
Compressed programs only work on a 286+.
Packed programs will be byte-identical to the original after
uncompression.
Maximum uncompressed size: ~65350 bytes.
Extra options available for this executable format:
--8086 Create an executable that works on any 8086 CPU.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
NOTES FOR DJGPP2/COFF
First of all, it is recommended to use UPX *instead* of strip. strip has
the very bad habit of replacing your stub with its own (outdated)
version. Additionally UPX corrects a bug/feature in strip v2.8.x: it
will fix the 4 KiB alignment of the stub.
UPX includes the full functionality of stubify. This means it will
automatically stubify your COFF files. Use the option --coff to disable
this functionality (see below).
UPX automatically handles Allegro packfiles.
The DLM format (a rather exotic shared library extension) is not
supported.
Packed programs will be byte-identical to the original after
uncompression. All debug information and trailing garbage will be
stripped, though.
Extra options available for this executable format:
--coff Produce COFF output instead of EXE. By default
UPX keeps your current stub.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
NOTES FOR LINUX [general]
Introduction
Linux/386 support in UPX consists of 3 different executable formats,
one optimized for ELF executables ("linux/elf386"), one optimized
for shell scripts ("linux/sh386"), and one generic format
("linux/386").
We will start with a general discussion first, but please
also read the relevant docs for each of the individual formats.
Also, there is special support for bootable kernels - see the
description of the vmlinuz/386 format.
General user's overview
Running a compressed executable program trades less space on a
``permanent'' storage medium (such as a hard disk, floppy disk,
CD-ROM, flash memory, EPROM, etc.) for more space in one or more
``temporary'' storage media (such as RAM, swap space, /tmp, etc.).
Running a compressed executable also requires some additional CPU
cycles to generate the compressed executable in the first place,
and to decompress it at each invocation.
How much space is traded? It depends on the executable, but many
programs save 30% to 50% of permanent disk space. How much CPU
overhead is there? Again, it depends on the executable, but
decompression speed generally is at least many megabytes per second,
and frequently is limited by the speed of the underlying disk
or network I/O.
Depending on the statistics of usage and access, and the relative
speeds of CPU, RAM, swap space, /tmp, and file system storage, then
invoking and running a compressed executable can be faster than
directly running the corresponding uncompressed program.
The operating system might perform fewer expensive I/O operations
to invoke the compressed program. Paging to or from swap space
or /tmp might be faster than paging from the general file system.
``Medium-sized'' programs which access about 1/3 to 1/2 of their
stored program bytes can do particularly well with compression.
Small programs tend not to benefit as much because the absolute
savings is less. Big programs tend not to benefit proportionally
because each invocation may use only a small fraction of the program,
yet UPX decompresses the entire program before invoking it.
But in environments where disk or flash memory storage is limited,
then compression may win anyway.
Currently, executables compressed by UPX do not share RAM at runtime
in the way that executables mapped from a file system do. As a
result, if the same program is run simultaneously by more than one
process, then using the compressed version will require more RAM and/or
swap space. So, shell programs (bash, csh, etc.) and ``make''
might not be good candidates for compression.
UPX recognizes three executable formats for Linux: Linux/elf386,
Linux/sh386, and Linux/386. Linux/386 is the most generic format;
it accommodates any file that can be executed. At runtime, the UPX
decompression stub re-creates in /tmp a copy of the original file,
and then the copy is (re-)executed with the same arguments.
ELF binary executables prefer the Linux/elf386 format by default,
because UPX decompresses them directly into RAM, uses only one
exec, does not use space in /tmp, and does not use /proc.
Shell scripts where the underlying shell accepts a ``-c'' argument
can use the Linux/sh386 format. UPX decompresses the shell script
into low memory, then maps the shell and passes the entire text of the
script as an argument with a leading ``-c''.
General benefits:
- UPX can compress all executables, be it AOUT, ELF, libc4, libc5,
libc6, Shell/Perl/Python/... scripts, standalone Java .class
binaries, or whatever...
All scripts and programs will work just as before.
- Compressed programs are completely self-contained. No need for
any external program.
- UPX keeps your original program untouched. This means that
after decompression you will have a byte-identical version,
and you can use UPX as a file compressor just like gzip.
[ Note that UPX maintains a checksum of the file internally,
so it is indeed a reliable alternative. ]
- As the stub only uses syscalls and isn't linked against libc it
should run under any Linux configuration that can run ELF
binaries.
- For the same reason compressed executables should run under
FreeBSD and other systems which can run Linux binaries.
[ Please send feedback on this topic ]
General drawbacks:
- It is not advisable to compress programs which usually have many
instances running (like `sh' or `make') because the common segments of
compressed programs won't be shared any longer between different
processes.
- `ldd' and `size' won't show anything useful because all they
see is the statically linked stub. Since version 0.82 the section
headers are stripped from the UPX stub and `size' doesn't even
recognize the file format. The file patches/patch-elfcode.h has a
patch to fix this bug in `size' and other programs which use GNU BFD.
General notes:
- As UPX leaves your original program untouched it is advantageous
to strip it before compression.
- If you compress a script you will lose platform independence -
this could be a problem if you are using NFS mounted disks.
- Compression of suid, guid and sticky-bit programs is rejected
because of possible security implications.
- For the same reason there is no sense in making any compressed
program suid.
- Obviously UPX won't work with executables that want to read data
from themselves. E.g., this might be a problem for Perl scripts
which access their __DATA__ lines.
- In case of internal errors the stub will abort with exitcode 127.
Typical reasons for this to happen are that the program has somehow
been modified after compression.
Running `strace -o strace.log compressed_file' will tell you more.
NOTES FOR LINUX/ELF386
Please read the general Linux description first.
The linux/elf386 format decompresses directly into RAM, uses only one
exec, does not use space in /tmp, and does not use /proc.
Linux/elf386 is automatically selected for Linux ELF executables.
Packed programs will be byte-identical to the original after
uncompression.
How it works:
For ELF executables, UPX decompresses directly to memory, simulating
the mapping that the operating system kernel uses during exec(),
including the PT_INTERP program interpreter (if any).
The brk() is set by a special PT_LOAD segment in the compressed
executable itself. UPX then wipes the stack clean except for
arguments, environment variables, and Elf_auxv entries (this is
required by bugs in the startup code of /lib/ld-linux.so as of
May 2000), and transfers control to the program interpreter or
the e_entry address of the original executable.
The UPX stub is about 1700 bytes long, partly written in assembler
and only uses kernel syscalls. It is not linked against any libc.
Specific drawbacks:
- For linux/elf386 and linux/sh386 formats, you will be relying on
RAM and swap space to hold all of the decompressed program during
the lifetime of the process. If you already use most of your swap
space, then you may run out. A system that is "out of memory"
can become fragile. Many programs do not react gracefully when
malloc() returns 0. With newer Linux kernels, the kernel
may decide to kill some processes to regain memory, and you
may not like the kernel's choice of which to kill. Running
/usr/bin/top is one way to check on the usage of swap space.
Extra options available for this executable format:
(none)
NOTES FOR LINUX/SH386
Please read the general Linux description first.
Shell scripts where the underling shell accepts a ``-c'' argument can
use the Linux/sh386 format. UPX decompresses the shell script into low
memory, then maps the shell and passes the entire text of the script as
an argument with a leading ``-c''. It does not use space in /tmp, and
does not use /proc.
Linux/sh386 is automatically selected for shell scripts that use a known
shell.
Packed programs will be byte-identical to the original after
uncompression.
How it works:
For shell script executables (files beginning with "#!/" or "#! /")
where the shell is known to accept "-c <command>", UPX decompresses
the file into low memory, then maps the shell (and its PT_INTERP),
and passes control to the shell with the entire decompressed file
as the argument after "-c". Known shells are sh, ash, bash, bsh, csh,
ksh, tcsh, pdksh. Restriction: UPX cannot use this method
for shell scripts which use the one optional string argument after
the shell name in the script (example: "#! /bin/sh option3\n".)
The UPX stub is about 1700 bytes long, partly written in assembler
and only uses kernel syscalls. It is not linked against any libc.
Specific drawbacks:
- For linux/elf386 and linux/sh386 formats, you will be relying on
RAM and swap space to hold all of the decompressed program during
the lifetime of the process. If you already use most of your swap
space, then you may run out. A system that is "out of memory"
can become fragile. Many programs do not react gracefully when
malloc() returns 0. With newer Linux kernels, the kernel
may decide to kill some processes to regain memory, and you
may not like the kernel's choice of which to kill. Running
/usr/bin/top is one way to check on the usage of swap space.
Extra options available for this executable format:
(none)
NOTES FOR LINUX/386
Please read the general Linux description first.
The generic linux/386 format decompresses to /tmp and needs /proc file
system support. It starts the decompressed program via the execve()
syscall.
Linux/386 is only selected if the specialized linux/elf386 and
linux/sh386 won't recognize a file.
Packed programs will be byte-identical to the original after
uncompression.
How it works:
For files which are not ELF and not a script for a known "-c" shell,
UPX uses kernel execve(), which first requires decompressing to a
temporary file in the file system. Interestingly -
because of the good memory management of the Linux kernel - this
often does not introduce a noticeable delay, and in fact there
will be no disk access at all if you have enough free memory as
the entire process takes places within the file system buffers.
A compressed executable consists of the UPX stub and an overlay
which contains the original program in a compressed form.
The UPX stub is a statically linked ELF executable and does
the following at program startup:
1) decompress the overlay to a temporary location in /tmp
2) open the temporary file for reading
3) try to delete the temporary file and start (execve)
the uncompressed program in /tmp using /proc/<pid>/fd/X as
attained by step 2)
4) if that fails, fork off a subprocess to clean up and
start the program in /tmp in the meantime
The UPX stub is about 1700 bytes long, partly written in assembler
and only uses kernel syscalls. It is not linked against any libc.
Specific drawbacks:
- You need additional free disk space for the uncompressed program
in your /tmp directory. This program is deleted immediately after
decompression, but you still need it for the full execution time
of the program.
- You must have /proc file system support as the stub wants to open
/proc/<pid>/exe and needs /proc/<pid>/fd/X. This also means that you
cannot compress programs that are used during the boot sequence
before /proc is mounted.
- Utilities like `top' will display numerical values in the process
name field. This is because Linux computes the process name from
the first argument of the last execve syscall (which is typically
something like /proc/<pid>/fd/3).
- Because of temporary decompression to disk the decompression speed
is not as fast as with the other executable formats. Still, I can see
no noticeable delay when starting programs like my ~3 MiB emacs (which
is less than 1 MiB when compressed :-).
Extra options available for this executable format:
--force-execve Force the use of the generic linux/386 "execve"
format, i.e. do not try the linux/elf386 and
linux/sh386 formats.
NOTES FOR PS1/EXE
This is the executable format used by the Sony PlayStation (PSone), a
MIPS R3000 based gaming console which is popular since the late '90s.
Support of this format is very similar to the Atari one, because of
nostalgic feelings of one of the authors.
Packed programs will be byte-identical to the original after
uncompression, until further notice.
Maximum uncompressed size: ~1.89 / ~7.60 MiB.
Notes:
- UPX creates as default a suitable executable for CD-Mastering
and console transfer. For a CD-Master main executable you could also try
the special option "--boot-only" as described below.
It has been reported that upx packed executables are fully compatible with
the Sony PlayStation 2 (PS2, PStwo) and Sony PlayStation Portable (PSP) in
Sony PlayStation (PSone) emulation mode.
- Normally the packed files use the same memory areas like the uncompressed
versions, so they will not override other memory areas while unpacking.
If this isn't possible UPX will abort showing a 'packed data overlap'
error. With the "--force" option UPX will relocate the loading address
for the packed file, but this isn't a real problem if it is a single or
the main executable.
Extra options available for this executable format:
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--8-bit Uses 8 bit size compression [default: 32 bit]
--8mib-ram PSone has 8 MiB ram available [default: 2 MiB]
--boot-only This format is for main exes and CD-Mastering only !
It may slightly improve the compression ratio,
decompression routines are faster than default ones.
But it cannot be used for console transfer !
--no-align This option disables CD mode 2 data sector format
alignment. May slightly improves the compression ratio,
but the compressed executable will not boot from a CD.
Use it for console transfer only !
NOTES FOR RTM32/PE and ARM/PE
Same as win32/pe.
NOTES FOR TMT/ADAM
This format is used by the TMT Pascal compiler - see http://www.tmt.com/
.
Extra options available for this executable format:
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
NOTES FOR VMLINUZ/386
The vmlinuz/386 and bvmlinuz/386 formats take a gzip-compressed bootable
Linux kernel image ("vmlinuz", "zImage", "bzImage"), gzip-decompress it
and re-compress it with the UPX compression method.
vmlinuz/386 is completely unrelated to the other Linux executable
formats, and it does not share any of their drawbacks.
Notes:
- Be sure that "vmlinuz/386" or "bvmlinuz/386" is displayed
during compression - otherwise a wrong executable format
may have been used, and the kernel won't boot.
Benefits:
- Better compression (but note that the kernel was already compressed,
so the improvement is not as large as with other formats).
Still, the bytes saved may be essential for special needs like
boot disks.
For example, this is what I get for my 2.2.16 kernel:
1589708 vmlinux
641073 bzImage [original]
560755 bzImage.upx [compressed by "upx -9"]
- Much faster decompression at kernel boot time (but kernel
decompression speed is not really an issue these days).
Drawbacks:
(none)
Extra options available for this executable format:
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
NOTES FOR WATCOM/LE
UPX has been successfully tested with the following extenders: DOS4G,
DOS4GW, PMODE/W, DOS32a, CauseWay. The WDOS/X extender is partly
supported (for details see the file bugs BUGS).
DLLs and the LX format are not supported.
Extra options available for this executable format:
--le Produce an unbound LE output instead of
keeping the current stub.
NOTES FOR WIN32/PE
The PE support in UPX is quite stable now, but probably there are still
some incompatibilities with some files.
Because of the way UPX (and other packers for this format) works, you
can see increased memory usage of your compressed files because the
whole program is loaded into memory at startup. If you start several
instances of huge compressed programs you're wasting memory because the
common segments of the program won't get shared across the instances. On
the other hand if you're compressing only smaller programs, or running
only one instance of larger programs, then this penalty is smaller, but
it's still there.
If you're running executables from network, then compressed programs
will load faster, and require less bandwidth during execution.
DLLs are supported. But UPX compressed DLLs can not share common data
and code when they got used by multiple applications. So compressing
msvcrt.dll is a waste of memory, but compressing the dll plugins of a
particular application may be a better idea.
Screensavers are supported, with the restriction that the filename must
end with ".scr" (as screensavers are handled slightly different than
normal exe files).
UPX compressed PE files have some minor memory overhead (usually in the
10 - 30 KiB range) which can be seen by specifying the "-i" command line
switch during compression.
Extra options available for this executable format:
--compress-exports=0 Don't compress the export section.
Use this if you plan to run the compressed
program under Wine.
--compress-exports=1 Compress the export section. [DEFAULT]
Compression of the export section can improve the
compression ratio quite a bit but may not work
with all programs (like winword.exe).
UPX never compresses the export section of a DLL
regardless of this option.
--compress-icons=0 Don't compress any icons.
--compress-icons=1 Compress all but the first icon.
--compress-icons=2 Compress all icons which are not in the
first icon directory. [DEFAULT]
--compress-icons=3 Compress all icons.
--compress-resources=0 Don't compress any resources at all.
--keep-resource=list Don't compress resources specified by the list.
The members of the list are separated by commas.
A list member has the following format: I<type[/name]>.
I<Type> is the type of the resource. Standard types
must be specified as decimal numbers, user types can be
specified by decimal IDs or strings. I<Name> is the
identifier of the resource. It can be a decimal number
or a string. For example:
--keep-resource=2/MYBITMAP,5,6/12345
UPX won't compress the named bitmap resource "MYBITMAP",
it leaves every dialog (5) resource uncompressed, and
it won't touch the string table resource with identifier
12345.
--force Force compression even when there is an
unexpected value in a header field.
Use with care.
--strip-relocs=0 Don't strip relocation records.
--strip-relocs=1 Strip relocation records. [DEFAULT]
This option only works on executables with base
address greater or equal to 0x400000. Usually the
compressed files becomes smaller, but some files
may become larger. Note that the resulting file will
not work under Windows 3.x (Win32s).
UPX never strips relocations from a DLL
regardless of this option.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
DIAGNOSTICS
Exit status is normally 0; if an error occurs, exit status is 1. If a
warning occurs, exit status is 2.
UPX's diagnostics are intended to be self-explanatory.
BUGS
Please report all bugs immediately to the authors.
AUTHORS
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com
Laszlo Molnar <ezerotven+github@gmail.com>
John F. Reiser <jreiser@BitWagon.com>
Jens Medoch <jssg@users.sourceforge.net>
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) 2002-2023 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
COPYING), or (at your option) under the GPLv+2 with special exceptions
and restrictions granting the free usage for all binaries including
commercial programs (see the file LICENSE).
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the UPX License Agreements along with
this program; see the files COPYING and LICENSE. If not, visit the UPX
home page.
+1042
View File
File diff suppressed because it is too large Load Diff
+61 -60
View File
@@ -13,8 +13,8 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
=head1 ABSTRACT =head1 ABSTRACT
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2023 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net https://upx.github.io
B<UPX> is a portable, extendable, high-performance executable packer for B<UPX> is a portable, extendable, high-performance executable packer for
@@ -23,74 +23,59 @@ ratio and offers I<*very*> fast decompression. Your executables suffer
no memory overhead or other drawbacks for most of the formats supported, no memory overhead or other drawbacks for most of the formats supported,
because of in-place decompression. because of in-place decompression.
While you may use B<UPX> freely for both non-commercial and commercial
executables (for details see the file LICENSE), we would highly
appreciate if you credit B<UPX> and ourselves in the documentation,
possibly including a reference to the B<UPX> home page. Thanks.
[ Using B<UPX> in non-OpenSource applications without proper credits
is considered not politically correct ;-) ]
=head1 DISCLAIMER =head1 DISCLAIMER
B<UPX> comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE. B<UPX> comes with ABSOLUTELY NO WARRANTY; for details see the file COPYING.
This is the first production quality release, and we plan that future 1.xx
releases will be backward compatible with this version.
Please report all problems or suggestions to the authors. Thanks. Please report all problems or suggestions to the authors. Thanks.
=head1 SECURITY CONTEXT
IMPORTANT NOTE: B<UPX> inherits the security context of any files it handles.
This means that packing, unpacking, or even testing or listing a file requires
the same security considerations as actually executing the file.
Use B<UPX> on trusted files only!
=head1 DESCRIPTION =head1 DESCRIPTION
B<UPX> is a versatile executable packer with the following features: B<UPX> is a versatile executable packer with the following features:
- excellent compression ratio: compresses better than zip/gzip, - secure: as UPX is documented Open Source since many years any relevant
Security/Antivirus software is able to peek inside UPX compressed
apps to verify them
- excellent compression ratio: typically compresses better than Zip,
use UPX to decrease the size of your distribution ! use UPX to decrease the size of your distribution !
- very fast decompression: about 10 MiB/sec on an ancient Pentium 133, - very fast decompression: more than 500 MB/sec on any reasonably modern
about 200 MiB/sec on an Athlon XP 2000+. machine
- no memory overhead for your compressed executables for most of the - no memory overhead for your compressed executables for most of the
supported formats supported formats because of in-place decompression
- safe: you can list, test and unpack your executables - safe: you can list, test and unpack your executables.
Also, a checksum of both the compressed and uncompressed file is Also, a checksum of both the compressed and uncompressed file is
maintained internally. maintained internally.
- universal: UPX can pack a number of executable formats: - universal: UPX can pack a number of executable formats, including
* atari/tos Windows programs and DLLs, macOS apps and Linux executables
* bvmlinuz/386 [bootable Linux kernel]
* djgpp2/coff
* dos/com
* dos/exe
* dos/sys
* linux/386
* linux/elf386
* linux/sh386
* ps1/exe
* rtm32/pe
* tmt/adam
* vmlinuz/386 [bootable Linux kernel]
* vmlinux/386
* watcom/le (supporting DOS4G, PMODE/W, DOS32a and CauseWay)
* win32/pe (exe and dll)
* arm/pe (exe and dll)
* linux/elfamd64
* linux/elfppc32
* mach/elfppc32
- portable: UPX is written in portable endian-neutral C++ - portable: UPX is written in portable endian-neutral C++
- extendable: because of the class layout it's very easy to support - extendable: because of the class layout it's very easy to support
new executable formats or add new compression algorithms new executable formats or add new compression algorithms
- free: UPX can be distributed and used freely. And from version 0.99 - free: UPX is distributed with full source code under the GNU General
the full source code of UPX is released under the GNU General Public Public License v2+, with special exceptions granting the free usage
License (GPL) ! for commercial programs
You probably understand now why we call B<UPX> the "I<ultimate>" You probably understand now why we call B<UPX> the "I<ultimate>"
executable packer. executable packer.
@@ -145,7 +130,11 @@ compress and then decompress your program a first time - any further
compress-decompress steps should then yield byte-identical results compress-decompress steps should then yield byte-identical results
as compared to the first decompressed version.] as compared to the first decompressed version.]
[ ...to be written... - type `B<upx --help>' for now ] B<-k>: keep backup files
B<-o file>: write output to file
[ ...more docs need to be written... - type `B<upx --help>' for now ]
@@ -185,7 +174,17 @@ Quick info for achieving the best compression ratio:
=item * =item *
Try B<upx --brute myfile.exe> or even B<upx --ultra-brute myfile.exe>. Try B<upx --brute --no-lzma myfile.exe> or even
B<upx --ultra-brute --no-lzma myfile.exe>.
=item *
The option B<--lzma> enables LZMA compression, which compresses better but
is *significantly slower* at decompression. You probably do not want
to use it for large files.
(Note that B<--lzma> is automatically enabled by B<--all-methods> and
B<--brute>, use B<--no-lzma> to override.)
=item * =item *
@@ -221,7 +220,7 @@ actually accesses this overlayed data.
=head1 ENVIRONMENT =head1 ENVIRONMENT VARIABLE
The environment variable B<UPX> can hold a set of default The environment variable B<UPX> can hold a set of default
options for B<UPX>. These options are interpreted first and options for B<UPX>. These options are interpreted first and
@@ -251,7 +250,7 @@ This is the executable format used by the Atari ST/TT, a Motorola 68000
based personal computer which was popular in the late '80s. Support based personal computer which was popular in the late '80s. Support
of this format is only because of nostalgic feelings of one of of this format is only because of nostalgic feelings of one of
the authors and serves no practical purpose :-). the authors and serves no practical purpose :-).
See http://www.freemint.de for more info. See https://freemint.github.io for more info.
Packed programs will be byte-identical to the original after uncompression. Packed programs will be byte-identical to the original after uncompression.
All debug information will be stripped, though. All debug information will be stripped, though.
@@ -674,7 +673,7 @@ Extra options available for this executable format:
=head2 NOTES FOR PS1/EXE =head2 NOTES FOR PS1/EXE
This is the executable format used by the Sony PlayStation (PSone), This is the executable format used by the Sony PlayStation (PSone),
a Mips R3000 based gaming console which is popular since the late '90s. a MIPS R3000 based gaming console which is popular since the late '90s.
Support of this format is very similar to the Atari one, because of Support of this format is very similar to the Atari one, because of
nostalgic feelings of one of the authors. nostalgic feelings of one of the authors.
@@ -923,7 +922,7 @@ Please report all bugs immediately to the authors.
Markus F.X.J. Oberhumer <markus@oberhumer.com> Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com http://www.oberhumer.com
Laszlo Molnar <ml1050@users.sourceforge.net> Laszlo Molnar <ezerotven+github@gmail.com>
John F. Reiser <jreiser@BitWagon.com> John F. Reiser <jreiser@BitWagon.com>
@@ -933,22 +932,24 @@ Please report all bugs immediately to the authors.
=head1 COPYRIGHT =head1 COPYRIGHT
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2013 John F. Reiser Copyright (C) 2000-2023 John F. Reiser
Copyright (C) 2002-2013 Jens Medoch Copyright (C) 2002-2023 Jens Medoch
This program may be used freely, and you are welcome to B<UPX> is distributed with full source code under the terms of the
redistribute it under certain conditions. GNU General Public License v2+; either under the pure GPLv2+ (see
the file COPYING), or (at your option) under the GPLv+2 with special
exceptions and restrictions granting the free usage for all binaries
including commercial programs (see the file LICENSE).
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
B<UPX License Agreement> for more details.
You should have received a copy of the UPX License Agreement along
with this program; see the file LICENSE. If not, visit the UPX home page.
You should have received a copy of the UPX License Agreements along
with this program; see the files COPYING and LICENSE. If not,
visit the UPX home page.
+17
View File
@@ -0,0 +1,17 @@
#! /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"
+53
View File
@@ -0,0 +1,53 @@
#! /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)
@@ -0,0 +1,54 @@
# 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
@@ -0,0 +1,93 @@
#! /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
+14
View File
@@ -0,0 +1,14 @@
#! /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
image=upx-stubtools-20221212-v4
podman build -t "$image" -f "$argv0dir/Dockerfile" "$argv0dir"
podman image list "$image"
podman image tree "$image"
+76
View File
@@ -0,0 +1,76 @@
#! /usr/bin/env bash
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
argv0=$0; argv0abs="$(readlink -fn "$argv0")"; argv0dir="$(dirname "$argv0abs")"
# run an interactive shell in the image
# using a rootless Podman container
image=upx-stubtools-20221212-v4
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 rebuild the UPX stubs:
# cd /home/upx/src/upx/src/stub
# # make sure that git is clean:
# git status .
# # remove stub files and make sure that they got deleted:
# make maintainer-clean extra-clean
# git status .
# # rebuild
# make extra-all all
# # make sure that the stub files did rebuild correctly:
# git status .
# git diff .
# we can also build UPX in the container:
# cd /home/upx/src/upx
# rm -rf ./build/extra/gcc/release
# make build/extra/gcc/release
# # run tests
# ./build/extra/gcc/release/upx --version
# make -C build/extra/gcc/release test
# and we can also build UPX with -m32:
# cd /home/upx/src/upx
# rm -rf ./build/extra/gcc-m32/release
# make build/extra/gcc-m32/release
# # run tests
# ./build/extra/gcc-m32/release/upx --version
# make -C build/extra/gcc-m32/release test
# and we can also build UPX with -mx32: (NOTE: needs CONFIG_X86_X32_ABI on host kernel!)
# cd /home/upx/src/upx
# rm -rf ./build/extra/gcc-mx32/release
# make build/extra/gcc-mx32/release
# # run tests (needs CONFIG_X86_X32_ABI on host kernel)
# ./build/extra/gcc-mx32/release/upx --version
# make -C build/extra/gcc-mx32/release test
# and we can also rebuild the UPX docs the container:
# cd /home/upx/src/upx/doc
# make clean all
# git status .
# git diff .
+58
View File
@@ -0,0 +1,58 @@
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
+39
View File
@@ -0,0 +1,39 @@
#! /usr/bin/env bash
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
[[ -z $1 ]] || cd "$1" || exit 1
find . \
-type d -name '.git' -prune -o \
-type d -name '.hg' -prune -o \
-type d -name 'build*' -prune -o \
-type d -name 'tmp*' -prune -o \
-type d -name 'vendor' -prune -o \
-type f -iname '*.bat' -prune -o \
-type f -iname '*.exe' -prune -o \
-type f -iname '*.o' -prune -o \
-type f -iname '*.obj' -prune -o \
-type f -iname '*.out' -prune -o \
-type f -iname '*.pdf' -prune -o \
-type f -iname '*.swp' -prune -o \
-type f -print0 | \
LC_ALL=C sort -z | xargs -0r perl -n -e '
#print("$ARGV\n");
if (m,[\x00\x01\x02\x7f\xfe\xff],) { print "ERROR: binary file detected $ARGV: $_"; exit(1); }
if (m,[\r\x1a],) { print "ERROR: DOS EOL detected $ARGV: $_"; exit(1); }
if (m,([ \t]+)$,) {
# allow exactly two trailing spaces for GitHub flavoured Markdown in .md files
if ($1 ne " " || $ARGV !~ m,\.md$,) {
print "ERROR: trailing whitespace detected $ARGV: $_"; exit(1);
}
}
if (m,\t,) {
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
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); }
}
' || exit 1
+33
View File
@@ -0,0 +1,33 @@
#! /usr/bin/env bash
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
[[ -z $1 ]] || cd "$1" || exit 1
[[ -d .git ]] || exit 1
git ls-files --full-name -z | perl -0 -n -e '
s,^,./,;
if (m,^\./src/lzma-sdk(\0|$),) { }
elsif (m,^\./vendor/,) { }
elsif (m,\.bat(\0|$),) { }
elsif (m,\.exe(\0|$),) { }
else { print; }
' | LC_ALL=C sort -z | xargs -0r perl -n -e '
#print("$ARGV\n");
if (m,[\x00\x01\x02\x7f\xfe\xff],) { print "ERROR: binary file detected $ARGV: $_"; exit(1); }
if (m,[\r\x1a],) { print "ERROR: DOS EOL detected $ARGV: $_"; exit(1); }
if (m,([ \t]+)$,) {
# allow exactly two trailing spaces for GitHub flavoured Markdown in .md files
if ($1 ne " " || $ARGV !~ m,\.md$,) {
print "ERROR: trailing whitespace detected $ARGV: $_"; exit(1);
}
}
if (m,\t,) {
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
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); }
}
' || exit 1
+32
View File
@@ -0,0 +1,32 @@
#! /usr/bin/env bash
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
# "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
UPX_CLANG_FORMAT="$HOME/local/bin/bin-upx/clang-format-15.0.6"
fi
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
UPX_CLANG_FORMAT="$HOME/.local/bin/bin-upx/clang-format-15.0.6"
fi
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
UPX_CLANG_FORMAT="$HOME/bin/bin-upx/clang-format-15.0.6"
fi
if [[ ! -f $UPX_CLANG_FORMAT ]]; then
echo "ERROR: $0: cannot find clang-format-15.0.6"
echo "ERROR: $0: please visit https://github.com/upx/upx-stubtools"
exit 1
fi
# limit memory usage to 1 GiB (in case of clang-format problems with invalid files)
ulimit -v 1048576 || true
#echo $UPX_CLANG_FORMAT
exec "$UPX_CLANG_FORMAT" -style=file "$@"
exit 1
+83 -91
View File
@@ -1,114 +1,106 @@
# #
# UPX Makefile - needs GNU make 3.81 or better # UPX Makefile - needs GNU make
#
# Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR # IMPORTANT NOTE: this Makefile is deprecated - please
# directly use the CMake build instead!
MAKEFLAGS += -r
.SUFFIXES: .SUFFIXES:
export SHELL = /bin/sh export SHELL = /bin/sh
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),)
$(error GNU make 3.81 or better is required)
endif
ifndef srcdir ifndef srcdir
srcdir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,') srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,' || echo 'ERROR')
endif endif
ifndef top_srcdir ifndef top_srcdir
top_srcdir := $(srcdir)/.. top_srcdir := $(srcdir)/..
endif endif
include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local)
ifneq ($(srcdir),.) #
##$(info Info: using VPATH . $(srcdir)) # redirect to top-level CMake build
VPATH := . $(srcdir) #
.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
.PHONY: PHONY
.NOTPARALLEL:
#
# "make run-testsuite"
#
# search for the UPX testsuite -- git clone https://github.com/upx/upx-testsuite.git
# you also can override upx_testsuite_SRCDIR
ifndef upx_testsuite_SRCDIR
# search standard locations below $(top_srcdir)
ifneq ($(wildcard $(top_srcdir)/../upx--upx-testsuite.git/files/packed/.),)
upx_testsuite_SRCDIR := $(top_srcdir)/../upx--upx-testsuite.git
else ifneq ($(wildcard $(top_srcdir)/../upx-testsuite.git/files/packed/.),)
upx_testsuite_SRCDIR := $(top_srcdir)/../upx-testsuite.git
else ifneq ($(wildcard $(top_srcdir)/../upx-testsuite/files/packed/.),)
upx_testsuite_SRCDIR := $(top_srcdir)/../upx-testsuite
endif
endif endif
ifeq ($(CXX),) # run the UPX testsuite
CXX = g++ # 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
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
ifneq ($(wildcard $(top_srcdir)/.github/travis_testsuite_1.sh),)
run-testsuite: run-testsuite-release
run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
run-testsuite-%: export upx_testsuite_BUILDDIR := ./tmp-testsuite
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-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
endif endif
ifneq ($(findstring $(firstword $(CXX)),g++),)
USE_GNUC ?= 1
endif
ifeq ($(USE_GNUC),1)
ifeq ($(DEBUG),1)
CXXFLAGS += -O0 -g
else
CXXFLAGS += -O2
endif
CXXFLAGS_WERROR = -Werror
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wshadow -Wwrite-strings
CXXFLAGS += $(CXXFLAGS_WERROR)
endif
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
CXXLD ?= $(CXX)
exeext ?= .out
libext ?= .a
objext ?= .o
upx_SOURCES := $(sort $(wildcard $(srcdir)/*.cpp))
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
# we need UCL and zlib - you can set envvar UPX_UCLDIR
ifneq ($(wildcard $(UPX_UCLDIR)/include/ucl/ucl.h),)
INCLUDES += -I$(UPX_UCLDIR)/include
LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext))))
endif
LIBS += -lucl -lz
# you should set envvar UPX_LZMADIR to point to your unpacked LZMA SDK
include $(top_srcdir)/src/stub/src/c/Makevars.lzma
ifneq ($(UPX_LZMA_VERSION),)
DEFS += -DWITH_LZMA=$(UPX_LZMA_VERSION)
INCLUDES += -I$(UPX_LZMADIR)
endif endif
#
# "make clang-format"
#
all: upx$(exeext) | .depend # automatically format some C++ source code files
.DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS) .depend ifeq ($(shell uname),Linux)
# Markus loves clang-format, but John hates it; find a compromise
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES) CLANG_FORMAT_EXCLUDE_FILES += conf.h miniacc.h version.h help.cpp
$($(notdir $@).PRE_LINK_STEP) CLANG_FORMAT_EXCLUDE_FILES += p_elf.h p_elf_enum.h p_lx_% p_mach% p_unix% p_vmli%
$(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS)) CLANG_FORMAT_EXCLUDE_FILES += packer_c.cpp packer_f.cpp
$($(notdir $@).POST_LINK_STEP) CLANG_FORMAT_EXCLUDE_FILES += compress/compress.h filter/filter_impl.cpp
CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* [cu]*/*.[ch]*))
%.o : %.cpp | .depend CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<) clang-format: PHONY $(CLANG_FORMAT_FILES)
@echo "running upx-clang-format"
.depend: $(sort $(wildcard $(srcdir)/*.cpp $(srcdir)/*.h)) $(MAKEFILE_LIST) @$(top_srcdir)/misc/scripts/upx-clang-format -i $(CLANG_FORMAT_FILES)
@rm -f $@
ifeq ($(USE_GNUC),1)
@echo "Updating $@"
@$(strip $(CXX) $(call e,CPPFLAGS) -MM) $(filter %.cpp,$^) > $@
else
touch $@
endif endif
#
# "make check-whitespace"
#
ifeq ($(USE_GNUC),1) CHECK_WHITESPACE =
##compress_lzma$(objext) : CXXFLAGS += -O3 -fomit-frame-pointer ifeq ($(shell uname),Linux)
compress_lzma$(objext) : CXXFLAGS += -Wno-cast-qual CHECK_WHITESPACE = $(top_srcdir)/misc/scripts/check_whitespace.sh $(top_srcdir)
compress_lzma$(objext) : CXXFLAGS += -Wno-shadow ifneq ($(wildcard $(top_srcdir)/.git/.),)
ifeq ($(UPX_LZMA_VERSION),0x443) CHECK_WHITESPACE = $(top_srcdir)/misc/scripts/check_whitespace_git.sh $(top_srcdir)
compress_lzma$(objext) : CXXFLAGS += -Wno-non-virtual-dtor
compress_lzma$(objext) : CXXFLAGS += -Wno-unused
endif endif
# needed for gcc-4.3: check-whitespace : PHONY ; $(CHECK_WHITESPACE)
compress_lzma$(objext) : CXXFLAGS += -Wno-error
endif endif
# vim:set ts=8 sw=8 noet:
mostlyclean clean distclean maintainer-clean:
rm -f *.d *.map *.o *.obj *.res .depend upx.exe upx.out upx.ttp upx$(exeext)
.PHONY: all mostlyclean clean distclean maintainer-clean
ifeq ($(MAKECMDGOALS),mostlyclean)
else ifeq ($(MAKECMDGOALS),clean)
else ifeq ($(MAKECMDGOALS),distclean)
else ifeq ($(MAKECMDGOALS),maintainer-clean)
else
-include .depend
endif
+509 -423
View File
File diff suppressed because it is too large Load Diff
+81 -114
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,15 +22,13 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#ifndef UPX_BELE_H__
#ifndef __UPX_BELE_H
#error "this is an internal include file" #error "this is an internal include file"
#endif #endif
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -49,10 +47,8 @@
#error #error
#endif #endif
#if defined(BELE_RTP) #if defined(BELE_RTP)
struct AbstractPolicy struct AbstractPolicy {
{
inline AbstractPolicy() {} inline AbstractPolicy() {}
virtual inline ~AbstractPolicy() {} virtual inline ~AbstractPolicy() {}
V bool isBE() C = 0; V bool isBE() C = 0;
@@ -61,17 +57,17 @@ struct AbstractPolicy
V unsigned get16(const void *p) C = 0; V unsigned get16(const void *p) C = 0;
V unsigned get24(const void *p) C = 0; V unsigned get24(const void *p) C = 0;
V unsigned get32(const void *p) C = 0; V unsigned get32(const void *p) C = 0;
V acc_uint64l_t get64(const void *p) C = 0; V upx_uint64_t get64(const void *p) C = 0;
V void set16(void *p, unsigned v) C = 0; V void set16(void *p, unsigned v) C = 0;
V void set24(void *p, unsigned v) C = 0; V void set24(void *p, unsigned v) C = 0;
V void set32(void *p, unsigned v) C = 0; V void set32(void *p, unsigned v) C = 0;
V void set64(void *p, acc_uint64l_t v) C = 0; V void set64(void *p, upx_uint64_t v) C = 0;
V unsigned get16_signed(const void *p) C = 0; V int get16_signed(const void *p) C = 0;
V unsigned get24_signed(const void *p) C = 0; V int get24_signed(const void *p) C = 0;
V unsigned get32_signed(const void *p) C = 0; V int get32_signed(const void *p) C = 0;
V acc_uint64l_t get64_signed(const void *p) C = 0; V upx_int64_t get64_signed(const void *p) C = 0;
S u16_compare(const void *a, const void *b) C = 0; S u16_compare(const void *a, const void *b) C = 0;
S u24_compare(const void *a, const void *b) C = 0; S u24_compare(const void *a, const void *b) C = 0;
@@ -83,15 +79,24 @@ struct AbstractPolicy
S u32_compare_signed(const void *a, const void *b) C = 0; S u32_compare_signed(const void *a, const void *b) C = 0;
S u64_compare_signed(const void *a, const void *b) C = 0; S u64_compare_signed(const void *a, const void *b) C = 0;
private:
// disable copy, assignment and move assignment
AbstractPolicy(const AbstractPolicy &) = delete;
AbstractPolicy &operator=(const AbstractPolicy &) = delete;
AbstractPolicy &operator=(AbstractPolicy &&) = delete;
// disable dynamic allocation // disable dynamic allocation
DISABLE_NEW_DELETE ACC_CXX_DISABLE_NEW_DELETE
}; };
#endif #endif
#if defined(BELE_RTP)
#undef C
#define C const override
#endif
struct BEPolicy struct BEPolicy
#if defined(BELE_RTP) #if defined(BELE_RTP)
: public AbstractPolicy final : public AbstractPolicy
#endif #endif
{ {
inline BEPolicy() {} inline BEPolicy() {}
@@ -107,50 +112,30 @@ struct BEPolicy
typedef BE32 U32; typedef BE32 U32;
typedef BE64 U64; typedef BE64 U64;
V unsigned get16(const void *p) C V unsigned get16(const void *p) C { return get_be16(p); }
{ return get_be16(p); } V unsigned get24(const void *p) C { return get_be24(p); }
V unsigned get24(const void *p) C V unsigned get32(const void *p) C { return get_be32(p); }
{ return get_be24(p); } V upx_uint64_t get64(const void *p) C { return get_be64(p); }
V unsigned get32(const void *p) C
{ return get_be32(p); }
V acc_uint64l_t get64(const void *p) C
{ return get_be64(p); }
V void set16(void *p, unsigned v) C V void set16(void *p, unsigned v) C { set_be16(p, v); }
{ set_be16(p, v); } V void set24(void *p, unsigned v) C { set_be24(p, v); }
V void set24(void *p, unsigned v) C V void set32(void *p, unsigned v) C { set_be32(p, v); }
{ set_be24(p, v); } V void set64(void *p, upx_uint64_t v) C { set_be64(p, v); }
V void set32(void *p, unsigned v) C
{ set_be32(p, v); }
V void set64(void *p, acc_uint64l_t v) C
{ set_be64(p, v); }
V unsigned get16_signed(const void *p) C V int get16_signed(const void *p) C { return get_be16_signed(p); }
{ return get_be16_signed(p); } V int get24_signed(const void *p) C { return get_be24_signed(p); }
V unsigned get24_signed(const void *p) C V int get32_signed(const void *p) C { return get_be32_signed(p); }
{ return get_be24_signed(p); } V upx_int64_t get64_signed(const void *p) C { return get_be64_signed(p); }
V unsigned get32_signed(const void *p) C
{ return get_be32_signed(p); }
V acc_uint64l_t get64_signed(const void *p) C
{ return get_be64_signed(p); }
S u16_compare(const void *a, const void *b) C S u16_compare(const void *a, const void *b) C { return be16_compare(a, b); }
{ return be16_compare(a, b); } S u24_compare(const void *a, const void *b) C { return be24_compare(a, b); }
S u24_compare(const void *a, const void *b) C S u32_compare(const void *a, const void *b) C { return be32_compare(a, b); }
{ return be24_compare(a, b); } S u64_compare(const void *a, const void *b) C { return be64_compare(a, b); }
S u32_compare(const void *a, const void *b) C
{ return be32_compare(a, b); }
S u64_compare(const void *a, const void *b) C
{ return be64_compare(a, b); }
S u16_compare_signed(const void *a, const void *b) C S u16_compare_signed(const void *a, const void *b) C { return be16_compare_signed(a, b); }
{ return be16_compare_signed(a, b); } S u24_compare_signed(const void *a, const void *b) C { return be24_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C S u32_compare_signed(const void *a, const void *b) C { return be32_compare_signed(a, b); }
{ return be24_compare_signed(a, b); } S u64_compare_signed(const void *a, const void *b) C { return be64_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C
{ return be32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C
{ return be64_compare_signed(a, b); }
static void compileTimeAssertions() { static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2) COMPILE_TIME_ASSERT(sizeof(U16) == 2)
@@ -161,14 +146,18 @@ struct BEPolicy
COMPILE_TIME_ASSERT_ALIGNED1(U64) COMPILE_TIME_ASSERT_ALIGNED1(U64)
} }
private:
// disable copy, assignment and move assignment
BEPolicy(const BEPolicy &) = delete;
BEPolicy &operator=(const BEPolicy &) = delete;
BEPolicy &operator=(BEPolicy &&) = delete;
// disable dynamic allocation // disable dynamic allocation
DISABLE_NEW_DELETE ACC_CXX_DISABLE_NEW_DELETE
}; };
struct LEPolicy struct LEPolicy
#if defined(BELE_RTP) #if defined(BELE_RTP)
: public AbstractPolicy final : public AbstractPolicy
#endif #endif
{ {
inline LEPolicy() {} inline LEPolicy() {}
@@ -184,50 +173,30 @@ struct LEPolicy
typedef LE32 U32; typedef LE32 U32;
typedef LE64 U64; typedef LE64 U64;
V unsigned get16(const void *p) C V unsigned get16(const void *p) C { return get_le16(p); }
{ return get_le16(p); } V unsigned get24(const void *p) C { return get_le24(p); }
V unsigned get24(const void *p) C V unsigned get32(const void *p) C { return get_le32(p); }
{ return get_le24(p); } V upx_uint64_t get64(const void *p) C { return get_le64(p); }
V unsigned get32(const void *p) C
{ return get_le32(p); }
V acc_uint64l_t get64(const void *p) C
{ return get_le64(p); }
V void set16(void *p, unsigned v) C V void set16(void *p, unsigned v) C { set_le16(p, v); }
{ set_le16(p, v); } V void set24(void *p, unsigned v) C { set_le24(p, v); }
V void set24(void *p, unsigned v) C V void set32(void *p, unsigned v) C { set_le32(p, v); }
{ set_le24(p, v); } V void set64(void *p, upx_uint64_t v) C { set_le64(p, v); }
V void set32(void *p, unsigned v) C
{ set_le32(p, v); }
V void set64(void *p, acc_uint64l_t v) C
{ set_le64(p, v); }
V unsigned get16_signed(const void *p) C V int get16_signed(const void *p) C { return get_le16_signed(p); }
{ return get_le16_signed(p); } V int get24_signed(const void *p) C { return get_le24_signed(p); }
V unsigned get24_signed(const void *p) C V int get32_signed(const void *p) C { return get_le32_signed(p); }
{ return get_le24_signed(p); } V upx_int64_t get64_signed(const void *p) C { return get_le64_signed(p); }
V unsigned get32_signed(const void *p) C
{ return get_le32_signed(p); }
V acc_uint64l_t get64_signed(const void *p) C
{ return get_le64_signed(p); }
S u16_compare(const void *a, const void *b) C S u16_compare(const void *a, const void *b) C { return le16_compare(a, b); }
{ return le16_compare(a, b); } S u24_compare(const void *a, const void *b) C { return le24_compare(a, b); }
S u24_compare(const void *a, const void *b) C S u32_compare(const void *a, const void *b) C { return le32_compare(a, b); }
{ return le24_compare(a, b); } S u64_compare(const void *a, const void *b) C { return le64_compare(a, b); }
S u32_compare(const void *a, const void *b) C
{ return le32_compare(a, b); }
S u64_compare(const void *a, const void *b) C
{ return le64_compare(a, b); }
S u16_compare_signed(const void *a, const void *b) C S u16_compare_signed(const void *a, const void *b) C { return le16_compare_signed(a, b); }
{ return le16_compare_signed(a, b); } S u24_compare_signed(const void *a, const void *b) C { return le24_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C S u32_compare_signed(const void *a, const void *b) C { return le32_compare_signed(a, b); }
{ return le24_compare_signed(a, b); } S u64_compare_signed(const void *a, const void *b) C { return le64_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C
{ return le32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C
{ return le64_compare_signed(a, b); }
static void compileTimeAssertions() { static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2) COMPILE_TIME_ASSERT(sizeof(U16) == 2)
@@ -238,11 +207,16 @@ struct LEPolicy
COMPILE_TIME_ASSERT_ALIGNED1(U64) COMPILE_TIME_ASSERT_ALIGNED1(U64)
} }
private:
// disable copy, assignment and move assignment
LEPolicy(const LEPolicy &) = delete;
LEPolicy &operator=(const LEPolicy &) = delete;
LEPolicy &operator=(LEPolicy &&) = delete;
// disable dynamic allocation // disable dynamic allocation
DISABLE_NEW_DELETE ACC_CXX_DISABLE_NEW_DELETE
}; };
// native policy (aka host policy)
#if (ACC_ABI_BIG_ENDIAN) #if (ACC_ABI_BIG_ENDIAN)
typedef BEPolicy HostPolicy; typedef BEPolicy HostPolicy;
#elif (ACC_ABI_LITTLE_ENDIAN) #elif (ACC_ABI_LITTLE_ENDIAN)
@@ -251,17 +225,15 @@ typedef LEPolicy HostPolicy;
#error "ACC_ABI_ENDIAN" #error "ACC_ABI_ENDIAN"
#endif #endif
#if 0 /* UNUSED */ #if 0 /* UNUSED */
struct HostAlignedPolicy struct HostAlignedPolicy {
{
#if defined(BELE_CTP) #if defined(BELE_CTP)
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE }; enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
#endif #endif
typedef acc_uint16e_t U16; typedef upx_uint16_t U16;
typedef acc_uint32e_t U32; typedef upx_uint32_t U32;
typedef acc_uint64l_t U64; typedef upx_uint64_t U64;
static void compileTimeAssertions() { static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2) COMPILE_TIME_ASSERT(sizeof(U16) == 2)
@@ -271,13 +243,8 @@ struct HostAlignedPolicy
}; };
#endif #endif
#undef V #undef V
#undef S #undef S
#undef C #undef C
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
-115
View File
@@ -1,115 +0,0 @@
/* bptr.h --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/
#ifndef __UPX_BPTR_H
#define __UPX_BPTR_H 1
/*************************************************************************
// BoundedPtr
**************************************************************************/
template <class T>
class BoundedPtr
{
// typedef BoundedPtr<T> Self;
public:
typedef T* StoredType;
typedef T* PointerType;
typedef T& ReferenceType;
~BoundedPtr() { }
explicit BoundedPtr(void* base, unsigned size, T* ptr=0)
: ptr_(ptr), base_(base), size_(size) { check(); }
BoundedPtr& operator= (const BoundedPtr& other) {
assert(base_ == other.base_); assert(size_ == other.size_);
ptr_ = other.ptr_; check(); return *this;
}
BoundedPtr& operator= (T* other) {
ptr_ = other; check(); return *this;
}
operator T* () { check(); return ptr_; }
operator const T* () const { check(); return ptr_; }
BoundedPtr& operator += (size_t n) {
checkStrict(); ptr_ += n; checkStrict(); return *this;
}
BoundedPtr& operator -= (size_t n) {
checkStrict(); ptr_ -= n; checkStrict(); return *this;
}
BoundedPtr& operator ++ (void) {
checkStrict(); ptr_ += 1; checkStrict(); return *this;
}
// T* operator ++ (int) {
// T* p = ptr_; checkStrict(); ptr_ += 1; checkStrict(); return p;
// }
// BoundedPtr& operator -- (void) {
// checkStrict(); ptr_ -= 1; checkStrict(); return *this;
// }
private:
void checkNULL() const {
if (!ptr_)
throwCantUnpack("unexpected NULL pointer; take care!");
}
void checkRange(size_t extra=0) const {
size_t off = (const char *) ptr_ - (const char *) base_;
if (off > size_ || off + extra > size_)
throwCantUnpack("pointer out of range; take care!");
}
void checkStrict(size_t extra=0) const {
checkNULL();
checkRange(extra);
}
void check(size_t extra=0) const {
if (ptr_) checkRange(extra);
}
T* ptr_;
void* base_;
size_t size_;
// disable copy
BoundedPtr(const BoundedPtr&); // {}
// BoundedPtr& operator= (const BoundedPtr&); // { return *this; }
// disable dynamic allocation
DISABLE_NEW_DELETE
};
#endif /* already included */
/*
vi:ts=4:et
*/
+475
View File
@@ -0,0 +1,475 @@
/* dt_check.cpp -- doctest check
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
*/
#include "../conf.h"
/*************************************************************************
// upx_doctest_check()
**************************************************************************/
int upx_doctest_check(int argc, char **argv) {
#if defined(DOCTEST_CONFIG_DISABLE)
UNUSED(argc);
UNUSED(argv);
return 0;
#else
const char *e = getenv("UPX_DEBUG_DOCTEST_DISABLE");
if (e && e[0] && strcmp(e, "0") != 0)
return 0;
bool minimal = true; // only show failing tests
bool duration = false; // show timings
bool success = false; // show all tests
#if DEBUG
minimal = false;
#endif
e = getenv("UPX_DEBUG_DOCTEST_VERBOSE");
if (e && e[0]) {
minimal = false;
if (strcmp(e, "0") == 0) {
minimal = true;
} else if (strcmp(e, "2") == 0) {
duration = true;
} else if (strcmp(e, "3") == 0) {
duration = true;
success = true;
}
}
doctest::Context context;
if (minimal)
context.setOption("dt-minimal", true);
if (duration)
context.setOption("dt-duration", true);
if (success)
context.setOption("dt-success", true);
// this requires that main_get_options() understands "--dt-XXX" options
if (argc > 0 && argv != nullptr)
context.applyCommandLine(argc, argv);
int r = context.run();
if (r != 0)
return 1;
if (context.shouldExit())
return 2;
return 0;
#endif // DOCTEST_CONFIG_DISABLE
}
int upx_doctest_check() { return upx_doctest_check(0, nullptr); }
/*************************************************************************
// compile-time checks
**************************************************************************/
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<short, upx_int16_t>::value))
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<unsigned short, upx_uint16_t>::value))
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<int, upx_int32_t>::value))
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<unsigned, upx_uint32_t>::value))
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<long long, upx_int64_t>::value))
ACC_COMPILE_TIME_ASSERT_HEADER((std::is_same<unsigned long long, upx_uint64_t>::value))
ACC_COMPILE_TIME_ASSERT_HEADER(no_bswap16(0x04030201) == 0x0201)
ACC_COMPILE_TIME_ASSERT_HEADER(no_bswap32(0x04030201) == 0x04030201)
ACC_COMPILE_TIME_ASSERT_HEADER(no_bswap64(0x0807060504030201ull) == 0x0807060504030201ull)
#if !(ACC_CC_MSC)
ACC_COMPILE_TIME_ASSERT_HEADER(bswap16(0x04030201) == 0x0102)
ACC_COMPILE_TIME_ASSERT_HEADER(bswap32(0x04030201) == 0x01020304)
ACC_COMPILE_TIME_ASSERT_HEADER(bswap64(0x0807060504030201ull) == 0x0102030405060708ull)
#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(CHAR_BIT == 8)
#if 0 // does not work with MSVC
#if '\0' - 1 < 0
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 127)
#else
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255)
#endif
#if L'\0' - 1 < 0
ACC_COMPILE_TIME_ASSERT_HEADER((wchar_t) -1 < 0)
#else
ACC_COMPILE_TIME_ASSERT_HEADER((wchar_t) -1 > 0)
#endif
#endif
/*************************************************************************
// upx_compiler_sanity_check()
// assert a sane architecture and compiler
**************************************************************************/
namespace {
template <class T>
struct TestBELE {
__acc_static_noinline bool test(void) {
// POD checks
{
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)
}
// alignment checks
{
COMPILE_TIME_ASSERT_ALIGNED1(T)
struct alignas(1) test1_t {
char a;
T b;
};
struct alignas(1) test2_t {
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(sizeof(t1) == 7 + 7 * sizeof(T))
COMPILE_TIME_ASSERT(sizeof(test2_t) == 1 + 3 * sizeof(T))
COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21 * sizeof(T))
UNUSED(t1);
UNUSED(t2);
}
#if 1
// arithmetic checks
{
T allbits;
allbits = 0;
allbits += 1;
allbits -= 2;
T v1;
v1 = 1;
v1 *= 2;
v1 -= 1;
T v2;
v2 = 1;
assert((v1 == v2));
assert(!(v1 != v2));
assert((v1 <= v2));
assert((v1 >= v2));
assert(!(v1 < v2));
assert(!(v1 > v2));
v2 ^= allbits;
assert(!(v1 == v2));
assert((v1 != v2));
assert((v1 <= v2));
assert(!(v1 >= v2));
assert((v1 < v2));
assert(!(v1 > v2));
v2 += 2;
assert(v1 == 1);
assert(v2 == 0);
v1 <<= 1;
v1 |= v2;
v1 >>= 1;
v2 &= v1;
v2 /= v1;
v2 *= v1;
assert(v1 == 1);
assert(v2 == 0);
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) {
*a = 0;
*b = 0;
*b -= 3;
return *a != 0;
}
};
template <class A, class B>
__acc_static_forceinline bool testNoAliasing(A *a, B *b) {
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; }
};
} // namespace
#define ACC_WANT_ACC_CHK_CH 1
#undef ACCCHK_ASSERT
#include "../miniacc.h"
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"
#undef ACCCHK_ASSERT
COMPILE_TIME_ASSERT(sizeof(char) == 1)
COMPILE_TIME_ASSERT(sizeof(short) == 2)
COMPILE_TIME_ASSERT(sizeof(int) == 4)
COMPILE_TIME_ASSERT(sizeof(long) >= 4)
COMPILE_TIME_ASSERT(sizeof(void *) >= 4)
COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
COMPILE_TIME_ASSERT(sizeof(BE64) == 8)
COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
COMPILE_TIME_ASSERT(sizeof(LE64) == 8)
COMPILE_TIME_ASSERT_ALIGNED1(BE16)
COMPILE_TIME_ASSERT_ALIGNED1(BE32)
COMPILE_TIME_ASSERT_ALIGNED1(BE64)
COMPILE_TIME_ASSERT_ALIGNED1(LE16)
COMPILE_TIME_ASSERT_ALIGNED1(LE32)
COMPILE_TIME_ASSERT_ALIGNED1(LE64)
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
assert(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);
if (gitrev[0]) {
size_t revlen = strlen(gitrev);
if (strncmp(gitrev, "ERROR", 5) == 0) {
assert(revlen == 5 || revlen == 6);
} else {
assert(revlen == 12 || revlen == 13);
}
if (revlen == 6 || revlen == 13) {
assert(gitrev[revlen - 1] == '+');
}
}
assert(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());
{
alignas(16) static const unsigned char dd[32] = {
0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0,
0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 0, 0, 0, 0, 0};
const unsigned char *d;
const N_BELE_RTP::AbstractPolicy *bele;
d = dd + 7;
assert(upx_adler32(d, 4) == 0x09f003f7);
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
bele = &N_BELE_RTP::be_policy;
assert(get_be16(d) == 0xfffe);
assert(bele->get16(d) == 0xfffe);
assert(get_be16_signed(d) == -2);
assert(get_be24(d) == 0xfffefd);
assert(bele->get24(d) == 0xfffefd);
assert(get_be24_signed(d) == -259);
assert(get_be32(d) == 0xfffefdfc);
assert(bele->get32(d) == 0xfffefdfc);
assert(get_be32_signed(d) == -66052);
bele = &N_BELE_RTP::le_policy;
assert(get_le16(d) == 0xfeff);
assert(bele->get16(d) == 0xfeff);
assert(get_le16_signed(d) == -257);
assert(get_le24(d) == 0xfdfeff);
assert(bele->get24(d) == 0xfdfeff);
assert(get_le24_signed(d) == -131329);
assert(get_le32(d) == 0xfcfdfeff);
assert(bele->get32(d) == 0xfcfdfeff);
assert(get_le32_signed(d) == -50462977);
assert(get_le64_signed(d) == -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);
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);
}
{
unsigned dd;
void *const d = &dd;
dd = ne32_to_le32(0xf7f6f5f4);
assert(get_le26(d) == 0x03f6f5f4);
set_le26(d, 0);
assert(get_le26(d) == 0);
assert(dd == ne32_to_le32(0xf4000000));
set_le26(d, 0xff020304);
assert(get_le26(d) == 0x03020304);
assert(dd == ne32_to_le32(0xf7020304));
}
{
upx_uint16_t a;
upx_uint32_t b;
upx_uint64_t c;
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);
}
#endif
union {
short v_short;
int v_int;
long v_long;
long long v_llong;
BE16 b16;
BE32 b32;
BE64 b64;
LE16 l16;
LE32 l32;
LE64 l64;
} u;
assert(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));
// 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(TestIntegerWrap<unsigned>::inc(0));
assert(!TestIntegerWrap<unsigned>::inc(UINT_MAX));
assert(TestIntegerWrap<unsigned>::dec(1));
assert(!TestIntegerWrap<unsigned>::dec(0));
// 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));
}
/*************************************************************************
// some doctest test cases
**************************************************************************/
TEST_CASE("acc_vget") {
CHECK_EQ(acc_vget_int(0, 0), 0);
CHECK_EQ(acc_vget_long(1, -1), 1);
CHECK_EQ(acc_vget_acc_int64l_t(2, 1), 2);
CHECK_EQ(acc_vget_acc_hvoid_p(nullptr, 0), nullptr);
}
TEST_CASE("working -fno-strict-aliasing") {
bool ok;
long v = 0;
short *ps = ACC_STATIC_CAST(short *, acc_vget_acc_hvoid_p(&v, 0));
int *pi = ACC_STATIC_CAST(int *, acc_vget_acc_hvoid_p(&v, 0));
long *pl = ACC_STATIC_CAST(long *, acc_vget_acc_hvoid_p(&v, 0));
*ps = 0;
*pl = -1;
ok = *ps == -1;
CHECK(ok);
*pi = 0;
*pl = -1;
ok = *pi == -1;
CHECK(ok);
*pl = 0;
*ps = -1;
ok = *pl != 0;
CHECK(ok);
*pl = 0;
*pi = -1;
ok = *pl != 0;
CHECK(ok);
}
TEST_CASE("working -fno-strict-overflow") {
CHECK_EQ(acc_vget_int(INT_MAX, 0) + 1, INT_MIN);
CHECK_EQ(acc_vget_int(INT_MIN, 0) - 1, INT_MAX);
CHECK_EQ(acc_vget_long(LONG_MAX, 0) + 1, LONG_MIN);
CHECK_EQ(acc_vget_long(LONG_MIN, 0) - 1, LONG_MAX);
bool ok;
int i;
i = INT_MAX;
i += 1;
ok = i == INT_MIN;
CHECK(ok);
i = INT_MIN;
i -= 1;
ok = i == INT_MAX;
CHECK(ok);
}
TEST_CASE("libc snprintf") {
// runtime check that Win32/MinGW <stdio.h> works as expected
char buf[64];
long long ll = acc_vget_int(-1, 0);
unsigned long long llu = (unsigned long long) ll;
snprintf(buf, sizeof(buf), "%d.%ld.%lld.%u.%lu.%llu", -3, -2L, ll, 3U, 2LU, llu);
CHECK_EQ(strcmp(buf, "-3.-2.-1.3.2.18446744073709551615"), 0);
intmax_t im = ll;
uintmax_t um = llu;
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%jd", -4, 0, 0, 0, 0, 0, 0, 0, 4, im);
CHECK_EQ(strcmp(buf, "-4.0.0.0.0.0.0.0.4.-1"), 0);
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%ju", -5, 0, 0, 0, 0, 0, 0, 0, 5, um);
CHECK_EQ(strcmp(buf, "-5.0.0.0.0.0.0.0.5.18446744073709551615"), 0);
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%jx", -6, 0, 0, 0, 0, 0, 0, 0, 6, um);
CHECK_EQ(strcmp(buf, "-6.0.0.0.0.0.0.0.6.ffffffffffffffff"), 0);
snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%#jx", -7, 0, 0, 0, 0, 0, 0, 0, 7, um);
CHECK_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0);
}
/* vim:set ts=4 sw=4 et: */
+51
View File
@@ -0,0 +1,51 @@
/* dt_impl.cpp -- doctest support code implementation
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 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>
*/
/*************************************************************************
// doctest support code implementation
**************************************************************************/
#define DOCTEST_CONFIG_IMPLEMENT
#if !defined(UPX_DOCTEST_CONFIG_MULTITHREADING)
#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_POSIX_SIGNALS
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
#if !defined(DOCTEST_CONFIG_DISABLE)
#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
/* vim:set ts=4 sw=4 et: */
+791
View File
@@ -0,0 +1,791 @@
/* xspan -- a minimally invasive checked memory smart pointer
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
*/
// lots of tests (and probably quite a number of redundant tests)
#include "../conf.h"
/*************************************************************************
// raw_bytes
**************************************************************************/
TEST_CASE("raw_bytes ptr") {
upx_uint16_t *ptr = nullptr;
CHECK_NOTHROW(raw_bytes(ptr, 0));
CHECK_THROWS(raw_bytes(ptr, 1));
CHECK_THROWS(raw_index_bytes(ptr, 0, 0));
CHECK_THROWS(raw_index_bytes(ptr, 1, 0));
CHECK_THROWS(raw_index_bytes(ptr, 0, 1));
upx_uint16_t buf[4];
ptr = buf;
CHECK(ptr_udiff_bytes(raw_index_bytes(ptr, 1, 1), ptr) == 2u);
CHECK(ptr_udiff_bytes(raw_index_bytes(ptr, 4, 0), ptr) == 8u);
}
TEST_CASE("raw_bytes bounded array") {
upx_uint16_t buf[4];
CHECK_NOTHROW(raw_bytes(buf, 8));
CHECK_THROWS(raw_bytes(buf, 9));
CHECK_NOTHROW(raw_index_bytes(buf, 4, 0));
CHECK_THROWS(raw_index_bytes(buf, 4, 1));
CHECK_NOTHROW(raw_index_bytes(buf, 3, 2));
CHECK_THROWS(raw_index_bytes(buf, 3, 3));
CHECK(ptr_udiff_bytes(raw_index_bytes(buf, 1, 1), buf) == 2u);
CHECK(ptr_udiff_bytes(raw_index_bytes(buf, 4, 0), buf) == 8u);
}
/*************************************************************************
// basic xspan
**************************************************************************/
TEST_CASE("basic xspan usage") {
char buf[4] = {0, 1, 2, 3};
SUBCASE("XSPAN_x") {
XSPAN_0(char) a0 = nullptr;
XSPAN_0(char) b0 = buf;
XSPAN_P(char) bp = buf;
XSPAN_0(char) c0 = XSPAN_0_MAKE(char, buf);
XSPAN_P(char) cp = XSPAN_P_MAKE(char, buf);
XSPAN_S(char) cs = XSPAN_S_MAKE(char, buf, sizeof(buf));
XSPAN_0(const char) const x0 = XSPAN_0_MAKE(const char, buf);
XSPAN_P(const char) const xp = XSPAN_P_MAKE(const char, buf);
XSPAN_S(const char) const xs = XSPAN_S_MAKE(const char, buf, sizeof(buf));
XSPAN_P(const char) const yp = xs;
XSPAN_0(const char) const z0p = yp;
XSPAN_0(const char) const z0s = xs;
CHECK((a0 == nullptr));
CHECK(c0 == b0);
CHECK(cp == bp);
CHECK(cs == bp);
CHECK(x0 == z0p);
CHECK(xp == z0s);
CHECK_NOTHROW(raw_bytes(a0, 0));
CHECK_THROWS(raw_bytes(a0, 1));
CHECK_THROWS(raw_index_bytes(a0, 0, 0));
CHECK(raw_bytes(c0, 4) == buf);
CHECK(raw_index_bytes(c0, 1, 3) == buf + 1);
CHECK(raw_bytes(cp, 4) == buf);
CHECK(raw_index_bytes(cp, 1, 3) == buf + 1);
CHECK(raw_bytes(cs, 4) == buf);
CHECK(raw_index_bytes(cs, 1, 3) == buf + 1);
#if WITH_XSPAN >= 2
CHECK_THROWS(raw_bytes(cs, 5));
CHECK_THROWS(raw_index_bytes(cs, 1, 4));
#endif
}
SUBCASE("XSPAN_x_VAR") {
XSPAN_0_VAR(char, a0, nullptr);
XSPAN_0_VAR(char, b0, buf);
XSPAN_P_VAR(char, bp, buf);
XSPAN_0_VAR(char, c0, buf, sizeof(buf));
XSPAN_P_VAR(char, cp, buf, sizeof(buf));
XSPAN_S_VAR(char, cs, buf, sizeof(buf));
XSPAN_0_VAR(char, d0, buf + 1, sizeof(buf), buf);
XSPAN_P_VAR(char, dp, buf + 1, sizeof(buf), buf);
XSPAN_S_VAR(char, ds, buf + 1, sizeof(buf), buf);
XSPAN_0_VAR(const char, const x0, buf, sizeof(buf));
XSPAN_P_VAR(const char, const xp, buf, sizeof(buf));
XSPAN_S_VAR(const char, const xs, buf, sizeof(buf));
XSPAN_P_VAR(const char, const yp, xs);
XSPAN_0_VAR(const char, const z0p, yp);
XSPAN_0_VAR(const char, const z0s, xs);
CHECK((a0 == nullptr));
CHECK(c0 == b0);
CHECK(cp == bp);
CHECK(cs == bp);
CHECK(d0 == dp);
CHECK(d0 == ds);
CHECK(x0 == z0p);
CHECK(xp == z0s);
CHECK_NOTHROW(raw_bytes(a0, 0));
CHECK_THROWS(raw_bytes(a0, 1));
CHECK_THROWS(raw_index_bytes(a0, 0, 0));
CHECK(raw_bytes(c0, 4) == buf);
CHECK(raw_index_bytes(c0, 1, 3) == buf + 1);
CHECK(raw_bytes(cp, 4) == buf);
CHECK(raw_index_bytes(cp, 1, 3) == buf + 1);
CHECK(raw_bytes(cs, 4) == buf);
CHECK(raw_index_bytes(cs, 1, 3) == buf + 1);
#if WITH_XSPAN >= 2
CHECK_THROWS(raw_bytes(cs, 5));
CHECK_THROWS(raw_index_bytes(cs, 1, 4));
#endif
}
SUBCASE("xspan in class") {
struct MyType {
XSPAN_0(char) s0;
XSPAN_P(char) sp;
XSPAN_S(char) ss;
#if __cplusplus >= 201103L
XSPAN_0(char) x0 = nullptr;
#endif
#if WITH_XSPAN >= 2
// much nicer syntax when using fully checked xspan:
MyType(char *b, size_t n, bool) : s0(b, n), sp(b, n), ss(b, n) {}
#endif
MyType(char *b, size_t n)
: s0(XSPAN_0_MAKE(char, b, n)), sp(XSPAN_P_MAKE(char, b, n)),
ss(XSPAN_S_MAKE(char, b, n)) {
UNUSED(n);
}
};
MyType x(buf, sizeof(buf));
MyType y = MyType(buf, sizeof(buf));
CHECK(x.s0 == y.sp);
}
}
/*************************************************************************
//
**************************************************************************/
#if (WITH_XSPAN >= 2) && DEBUG
TEST_CASE("PtrOrSpanOrNull") {
char real_buf[2 + 6 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 124, 125};
char *base_buf = real_buf + 2;
char *const my_null = nullptr;
typedef PtrOrSpanOrNull<char> Span0;
// basic nullptr
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = my_null);
CHECK_NOTHROW(Span0(base_buf, 4, base_buf).assign(my_null));
// basic range checking
CHECK_NOTHROW(Span0(base_buf, 4, base_buf));
CHECK_NOTHROW(Span0(base_buf, 0, base_buf));
CHECK_NOTHROW(Span0(base_buf, 0, base_buf) - 0);
CHECK_THROWS(Span0(base_buf, 0, base_buf) + 1);
CHECK_THROWS(Span0(base_buf, 0, base_buf) - 1);
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) + 4);
CHECK_THROWS(Span0(base_buf, 4, base_buf) + 5);
CHECK_THROWS(Span0(base_buf - 1, 4, base_buf));
CHECK_THROWS(Span0(base_buf + 1, 0, base_buf));
// basic same base
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 3, base_buf));
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 1, base_buf));
CHECK_NOTHROW(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 5, base_buf));
CHECK_THROWS(Span0(base_buf, 4, base_buf) = Span0(base_buf + 1, 3, base_buf + 1));
Span0 a1(nullptr);
assert(a1 == nullptr);
assert(a1.raw_ptr() == nullptr);
assert(a1.raw_base() == nullptr);
assert(a1.raw_size_in_bytes() == 0u);
CHECK_THROWS(*a1);
CHECK_THROWS(a1[0]);
Span0 a2 = nullptr;
assert(a2 == nullptr);
assert(a2.raw_ptr() == nullptr);
assert(a2.raw_base() == nullptr);
assert(a2.raw_size_in_bytes() == 0u);
CHECK_THROWS(*a2);
CHECK_THROWS(a2[0]);
Span0 base0(nullptr, 4, base_buf);
assert(base0.raw_ptr() == nullptr);
assert(base0.raw_base() == base_buf);
assert(base0.raw_size_in_bytes() == 4u);
CHECK_THROWS(*base0); // nullptr
CHECK_THROWS(base0[0]); // nullptr
CHECK_THROWS(base0 + 1); // nullptr
Span0 base4(base_buf, 4);
assert(base4.raw_ptr() == base_buf);
assert(base4.raw_base() == base_buf);
assert(base4.raw_size_in_bytes() == 4u);
a1 = base_buf;
a1 = base0;
assert(a1 == nullptr);
assert(a1.raw_ptr() == nullptr);
assert(a1.raw_base() == base_buf);
assert(a1.raw_size_in_bytes() == 4u);
a1 = base4;
assert(a1 == base_buf);
assert(a1.raw_ptr() == base_buf);
assert(a1.raw_base() == base_buf);
assert(a1.raw_size_in_bytes() == 4u);
a1 = base_buf;
assert(a1 != nullptr);
a1 = base_buf + 1;
CHECK(*a1++ == 1);
CHECK(*++a1 == 3);
CHECK(*a1 == 3);
a1 = base_buf + 4; // at the end of buffer
CHECK_THROWS(*a1);
CHECK_THROWS(a1 = base_buf + 5); // range error
assert(a1 == base_buf + 4);
CHECK(a1[-4] == 0);
CHECK_THROWS(a1[-5]); // range error
a1 = base_buf;
CHECK(*a1 == 0);
Span0 new_base4(base_buf + 2, 4);
CHECK_THROWS(a1 = new_base4); // not same base
a2 = new_base4;
CHECK_THROWS(a2 = base4); // not same base
Span0 s0_no_base(nullptr);
Span0 s0_with_base(nullptr, 4, base_buf);
s0_no_base = nullptr;
s0_with_base = nullptr;
s0_with_base = s0_no_base;
assert(s0_no_base.raw_base() == nullptr);
assert(s0_with_base.raw_base() == base_buf);
s0_no_base = s0_with_base;
assert(s0_no_base.raw_base() == base_buf);
assert(s0_no_base.raw_ptr() == nullptr);
assert(s0_with_base.raw_ptr() == nullptr);
s0_no_base = my_null;
s0_with_base = my_null;
}
/*************************************************************************
//
**************************************************************************/
TEST_CASE("PtrOrSpan") {
char real_buf[2 + 6 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 124, 125};
char *base_buf = real_buf + 2;
char *const my_null = nullptr;
typedef PtrOrSpan<char> SpanP;
// basic nullptr
CHECK_THROWS(SpanP(base_buf, 4, base_buf) = my_null);
CHECK_THROWS(SpanP(base_buf, 4, base_buf).assign(my_null));
// basic range checking
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf));
CHECK_NOTHROW(SpanP(base_buf, 0, base_buf));
CHECK_NOTHROW(SpanP(base_buf, 0, base_buf) - 0);
CHECK_THROWS(SpanP(base_buf, 0, base_buf) + 1);
CHECK_THROWS(SpanP(base_buf, 0, base_buf) - 1);
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) + 4);
CHECK_THROWS(SpanP(base_buf, 4, base_buf) + 5);
CHECK_THROWS(SpanP(base_buf - 1, 4, base_buf));
CHECK_THROWS(SpanP(base_buf + 1, 0, base_buf));
// basic same base
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 3, base_buf));
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 1, base_buf));
CHECK_NOTHROW(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 5, base_buf));
CHECK_THROWS(SpanP(base_buf, 4, base_buf) = SpanP(base_buf + 1, 3, base_buf + 1));
SpanP x1(base_buf, 0);
assert(x1 != nullptr);
assert(x1.raw_ptr() == base_buf);
assert(x1.raw_base() == base_buf);
assert(x1.raw_size_in_bytes() == 0u);
CHECK_THROWS(*x1);
CHECK_THROWS(x1[0]);
SpanP a2 = base_buf;
assert(a2 != nullptr);
assert(a2.raw_ptr() == base_buf);
assert(a2.raw_base() == nullptr);
assert(a2.raw_size_in_bytes() == 0u);
CHECK(*a2 == 0);
CHECK(a2[1] == 1);
SpanP base0(base_buf, 4, base_buf);
assert(base0.raw_ptr() == base_buf);
assert(base0.raw_base() == base_buf);
assert(base0.raw_size_in_bytes() == 4u);
SpanP base4(base_buf, 4);
assert(base4.raw_ptr() == base_buf);
assert(base4.raw_base() == base_buf);
assert(base4.raw_size_in_bytes() == 4u);
SpanP a1(base_buf, 4);
a1 = base_buf;
a1 = base0;
assert(a1 == base0);
assert(a1 != nullptr);
assert(a1.raw_ptr() == base0.raw_ptr());
assert(a1.raw_base() == base_buf);
assert(a1.raw_size_in_bytes() == 4u);
a1 = base4;
assert(a1 == base_buf);
assert(a1.raw_ptr() == base_buf);
assert(a1.raw_base() == base_buf);
assert(a1.raw_size_in_bytes() == 4u);
a1 = base_buf;
a1 = base_buf + 1;
CHECK(*a1++ == 1);
CHECK(*++a1 == 3);
CHECK(*a1 == 3);
a1 = base_buf + 4; // at the end of buffer
CHECK_THROWS(*a1);
CHECK_THROWS(a1 = base_buf + 5); // range error
assert(a1 == base_buf + 4);
CHECK(a1[-4] == 0);
CHECK_THROWS(a1[-5]); // range error
a1 = base_buf;
CHECK(*a1 == 0);
SpanP new_base4(base_buf + 2, 4);
CHECK_THROWS(a1 = new_base4); // not same base
a2 = new_base4;
CHECK_THROWS(a2 = base4); // not same base
SpanP sp_no_base(base_buf);
SpanP sp_with_base(base_buf, 4, base_buf);
assert(sp_no_base.raw_base() == nullptr);
assert(sp_with_base.raw_base() == base_buf);
CHECK_THROWS(sp_no_base = my_null); // nullptr assignment
CHECK_THROWS(sp_with_base = my_null); // nullptr assignment
#if XSPAN_CONFIG_ENABLE_SPAN_CONVERSION
typedef PtrOrSpanOrNull<char> Span0;
Span0 s0_no_base(nullptr);
Span0 s0_with_base(nullptr, 4, base_buf);
CHECK_THROWS(sp_no_base = s0_no_base); // nullptr assignment
CHECK_THROWS(sp_no_base = s0_with_base); // nullptr assignment
CHECK_THROWS(sp_with_base = s0_no_base); // nullptr assignment
CHECK_THROWS(sp_with_base = s0_with_base); // nullptr assignment
#endif
}
/*************************************************************************
//
**************************************************************************/
TEST_CASE("Span") {
char real_buf[2 + 6 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 124, 125};
char *base_buf = real_buf + 2;
char *const my_null = nullptr;
typedef Span<char> SpanS;
// basic nullptr
CHECK_THROWS(SpanS(base_buf, 4, base_buf) = my_null);
CHECK_THROWS(SpanS(base_buf, 4, base_buf).assign(my_null));
// basic range checking
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf));
CHECK_NOTHROW(SpanS(base_buf, 0, base_buf));
CHECK_NOTHROW(SpanS(base_buf, 0, base_buf) - 0);
CHECK_THROWS(SpanS(base_buf, 0, base_buf) + 1);
CHECK_THROWS(SpanS(base_buf, 0, base_buf) - 1);
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) + 4);
CHECK_THROWS(SpanS(base_buf, 4, base_buf) + 5);
CHECK_THROWS(SpanS(base_buf - 1, 4, base_buf));
CHECK_THROWS(SpanS(base_buf + 1, 0, base_buf));
// basic same base
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 3, base_buf));
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 1, base_buf));
CHECK_NOTHROW(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 5, base_buf));
CHECK_THROWS(SpanS(base_buf, 4, base_buf) = SpanS(base_buf + 1, 3, base_buf + 1));
SpanS x1(base_buf, 0);
assert(x1 != nullptr);
assert(x1.raw_ptr() == base_buf);
assert(x1.raw_base() == base_buf);
assert(x1.raw_size_in_bytes() == 0u);
CHECK_THROWS(*x1);
CHECK_THROWS(x1[0]);
SpanS a2(base_buf, 4);
assert(a2 != nullptr);
assert(a2.raw_ptr() == base_buf);
assert(a2.raw_base() == base_buf);
assert(a2.raw_size_in_bytes() == 4u);
CHECK(*a2 == 0);
CHECK(a2[1] == 1);
SpanS base0(base_buf, 4, base_buf);
assert(base0.raw_ptr() == base_buf);
assert(base0.raw_base() == base_buf);
assert(base0.raw_size_in_bytes() == 4u);
SpanS base4(base_buf, 4);
assert(base4.raw_ptr() == base_buf);
assert(base4.raw_base() == base_buf);
assert(base4.raw_size_in_bytes() == 4u);
SpanS a1(base_buf, 4);
a1 = base_buf;
a1 = base0;
assert(a1 == base0);
assert(a1 != nullptr);
assert(a1.raw_ptr() == base0.raw_ptr());
assert(a1.raw_base() == base_buf);
assert(a1.raw_size_in_bytes() == 4u);
a1 = base4;
assert(a1 == base_buf);
assert(a1.raw_ptr() == base_buf);
assert(a1.raw_base() == base_buf);
assert(a1.raw_size_in_bytes() == 4u);
a1 = base_buf;
a1 = base_buf + 1;
CHECK(*a1++ == 1);
CHECK(*++a1 == 3);
CHECK(*a1 == 3);
a1 = base_buf + 4; // at the end of buffer
CHECK_THROWS(*a1);
CHECK_THROWS(a1 = base_buf + 5); // range error
assert(a1 == base_buf + 4);
CHECK(a1[-4] == 0);
CHECK_THROWS(a1[-5]); // range error
a1 = base_buf;
CHECK(*a1 == 0);
SpanS new_base4(base_buf + 2, 4);
CHECK_THROWS(a1 = new_base4); // not same base
CHECK_THROWS(a2 = new_base4); // not same base
SpanS ss_with_base(base_buf, 4, base_buf);
assert(ss_with_base.raw_base() == base_buf);
CHECK_THROWS(ss_with_base = my_null); // nullptr assignment
#if XSPAN_CONFIG_ENABLE_SPAN_CONVERSION
{
typedef PtrOrSpanOrNull<char> Span0;
// v0 nullptr, b0 base, b1 base + 1
const Span0 v0_v0(nullptr);
const Span0 v0_b0(nullptr, 4, base_buf);
const Span0 v0_b1(nullptr, 3, base_buf + 1);
const Span0 b0_v0(base_buf);
const Span0 b0_b0(base_buf, 4, base_buf);
CHECK_THROWS(XSPAN_0_MAKE(char, base_buf, 3, base_buf + 1)); // b0_b1
const Span0 b1_v0(base_buf + 1);
const Span0 b1_b0(base_buf + 1, 4, base_buf);
const Span0 b1_b1(base_buf + 1, 3, base_buf + 1);
CHECK_THROWS(ss_with_base = v0_v0); // nullptr assignment
CHECK_THROWS(ss_with_base = v0_b0); // nullptr assignment
CHECK_THROWS(ss_with_base = v0_b1); // nullptr assignment
CHECK_NOTHROW(ss_with_base = b0_v0);
CHECK_NOTHROW(ss_with_base = b0_b0);
CHECK_NOTHROW(ss_with_base = b1_v0);
CHECK_NOTHROW(ss_with_base = b1_b0);
CHECK_THROWS(ss_with_base = b1_b1); // different base
CHECK_THROWS(XSPAN_S_MAKE(char, v0_v0));
CHECK_THROWS(XSPAN_S_MAKE(char, v0_b0));
CHECK_THROWS(XSPAN_S_MAKE(char, v0_b1));
CHECK_THROWS(XSPAN_S_MAKE(char, b0_v0));
CHECK_NOTHROW(XSPAN_S_MAKE(char, b0_b0));
CHECK_THROWS(XSPAN_S_MAKE(char, b1_v0));
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b0));
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b1));
//
CHECK((XSPAN_S_MAKE(char, b0_b0).raw_base() == base_buf));
CHECK((XSPAN_S_MAKE(char, b1_b0).raw_base() == base_buf));
CHECK((XSPAN_S_MAKE(char, b1_b1).raw_base() == base_buf + 1));
}
{
typedef PtrOrSpan<char> SpanP;
// v0 nullptr, b0 base, b1 base + 1
const SpanP b0_v0(base_buf);
const SpanP b0_b0(base_buf, 4, base_buf);
CHECK_THROWS(XSPAN_P_MAKE(char, base_buf, 3, base_buf + 1)); // b0_b1
const SpanP b1_v0(base_buf + 1);
const SpanP b1_b0(base_buf + 1, 4, base_buf);
const SpanP b1_b1(base_buf + 1, 3, base_buf + 1);
CHECK_NOTHROW(ss_with_base = b0_v0);
CHECK_NOTHROW(ss_with_base = b0_b0);
CHECK_NOTHROW(ss_with_base = b1_v0);
CHECK_NOTHROW(ss_with_base = b1_b0);
CHECK_THROWS(ss_with_base = b1_b1); // different base
CHECK_THROWS(XSPAN_S_MAKE(char, b0_v0));
CHECK_NOTHROW(XSPAN_S_MAKE(char, b0_b0));
CHECK_THROWS(XSPAN_S_MAKE(char, b1_v0));
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b0));
CHECK_NOTHROW(XSPAN_S_MAKE(char, b1_b1));
//
CHECK((XSPAN_S_MAKE(char, b0_b0).raw_base() == base_buf));
CHECK((XSPAN_S_MAKE(char, b1_b0).raw_base() == base_buf));
CHECK((XSPAN_S_MAKE(char, b1_b1).raw_base() == base_buf + 1));
}
#endif
}
/*************************************************************************
//
**************************************************************************/
TEST_CASE("Span void ptr") {
static char a[4] = {0, 1, 2, 3};
XSPAN_0(void) a0(a, 4);
XSPAN_P(void) ap(a, 4);
XSPAN_S(void) as(a, 4);
XSPAN_0(const void) c0(a, 4);
XSPAN_P(const void) cp(a, 4);
XSPAN_S(const void) cs(a, 4);
static const char b[4] = {0, 1, 2, 3};
XSPAN_0(const void) b0(b, 4);
XSPAN_P(const void) bp(b, 4);
XSPAN_S(const void) bs(b, 4);
}
TEST_CASE("Span deref/array/arrow") {
static char real_a[2 + 4 + 2] = {126, 127, 0, 1, 2, 3, 124, 125};
static char *a = real_a + 2;
XSPAN_0(char) a0(a, 4);
XSPAN_P(char) ap(a, 4);
XSPAN_S(char) as(a, 4);
CHECK_THROWS(a0[4]);
CHECK_THROWS(a0[-1]);
CHECK_THROWS(a0[-2]);
a0 += 2;
CHECK(*a0 == 2);
CHECK(a0[-1] == 1);
CHECK(a0[0] == 2);
CHECK(a0[1] == 3);
ap += 2;
CHECK(*ap == 2);
CHECK(ap[-1] == 1);
CHECK(ap[0] == 2);
CHECK(ap[1] == 3);
as += 2;
CHECK(*as == 2);
CHECK(as[-1] == 1);
CHECK(as[0] == 2);
CHECK(as[1] == 3);
}
TEST_CASE("Span subspan") {
static char buf[4] = {0, 1, 2, 3};
XSPAN_S(char) as(buf, 4);
CHECK(as.subspan(1, 1)[0] == 1);
CHECK((as + 1).subspan(1, 1)[0] == 2);
CHECK((as + 2).subspan(0, -2)[0] == 0);
CHECK_THROWS(as.subspan(1, 0)[0]);
CHECK_THROWS(as.subspan(1, 1)[-1]);
}
TEST_CASE("Span constness") {
static char buf[4] = {0, 1, 2, 3};
XSPAN_0(char) b0(buf, 4);
XSPAN_P(char) bp(buf, 4);
XSPAN_S(char) bs(buf, 4);
XSPAN_0(char) s0(b0);
XSPAN_P(char) sp(bp);
XSPAN_S(char) ss(bs);
XSPAN_0(const char) b0c(buf, 4);
XSPAN_P(const char) bpc(buf, 4);
XSPAN_S(const char) bsc(buf, 4);
XSPAN_0(const char) s0c(b0c);
XSPAN_P(const char) spc(bpc);
XSPAN_S(const char) ssc(bsc);
XSPAN_0(const char) x0c(b0);
XSPAN_P(const char) xpc(bp);
XSPAN_S(const char) xsc(bs);
CHECK(ptr_diff_bytes(b0, buf) == 0);
CHECK(ptr_diff_bytes(bp, buf) == 0);
CHECK(ptr_diff_bytes(bs, buf) == 0);
CHECK(ptr_diff_bytes(s0, buf) == 0);
CHECK(ptr_diff_bytes(sp, buf) == 0);
CHECK(ptr_diff_bytes(bs, buf) == 0);
//
CHECK(ptr_diff_bytes(s0, bp) == 0);
CHECK(ptr_diff_bytes(s0, sp) == 0);
CHECK(ptr_diff_bytes(s0, ss) == 0);
//
CHECK(ptr_diff_bytes(s0c, b0c) == 0);
CHECK(ptr_diff_bytes(spc, bpc) == 0);
CHECK(ptr_diff_bytes(ssc, bsc) == 0);
}
/*************************************************************************
//
**************************************************************************/
#if !defined(DOCTEST_CONFIG_DISABLE)
namespace {
int my_memcmp_v1(XSPAN_P(const void) a, XSPAN_0(const void) b, size_t n) {
if (b == nullptr)
return -2;
XSPAN_0(const void) x(a);
return memcmp(x, b, n);
}
int my_memcmp_v2(XSPAN_P(const char) a, XSPAN_0(const char) b, size_t n) {
if (a == b)
return 0;
if (b == nullptr)
return -2;
a += 1;
b -= 1;
XSPAN_0(const char) x(a);
XSPAN_0(const char) y = b;
return memcmp(x, y, n);
}
} // namespace
#endif
TEST_CASE("PtrOrSpan") {
static const char buf[4] = {0, 1, 2, 3};
CHECK(my_memcmp_v1(buf, nullptr, 4) == -2);
CHECK(my_memcmp_v2(buf + 4, buf + 4, 999) == 0);
CHECK(my_memcmp_v2(buf, buf + 2, 3) == 0);
}
/*************************************************************************
//
**************************************************************************/
TEST_CASE("PtrOrSpan char") {
char real_buf[2 + 8 + 2] = {126, 127, 0, 1, 2, 3, 4, 5, 6, 7, 124, 125};
char *buf = real_buf + 2;
XSPAN_P(char) a(buf, XSpanSizeInBytes(8));
XSPAN_P(char) b = a.subspan(0, 7);
XSPAN_P(char) c = (b + 1).subspan(0, 6);
a += 1;
CHECK(*a == 1);
*a++ += 1;
*b++ = 1;
CHECK(a == buf + 2);
CHECK(b == buf + 1);
CHECK(c == buf + 1);
CHECK(*b == 2);
CHECK(*c == 2);
CHECK(a.raw_size_in_bytes() == 8u);
CHECK(b.raw_size_in_bytes() == 7u);
CHECK(c.raw_size_in_bytes() == 6u);
CHECK(a.raw_base() == buf);
CHECK(b.raw_base() == buf);
CHECK(c.raw_base() == buf + 1);
#ifdef UPX_VERSION_HEX
CHECK(get_le32(a) != 0);
#endif
++c;
c++;
#ifdef UPX_VERSION_HEX
CHECK(get_le32(c) != 0);
#endif
++c;
#ifdef UPX_VERSION_HEX
CHECK_THROWS(get_le32(c));
#endif
++b;
b++;
b += 4;
CHECK(b.raw_ptr() == buf + 7);
CHECK_THROWS(*b);
CHECK(a.raw_size_in_bytes() == 8u);
a = b;
CHECK(a.raw_size_in_bytes() == 8u);
CHECK(a.raw_ptr() == buf + 7);
a++;
CHECK_THROWS(*a);
CHECK_THROWS(raw_bytes(a, 1));
a = b;
CHECK_THROWS(a = c);
*a = 0;
a = buf;
#ifdef UPX_VERSION_HEX
CHECK(upx_safe_strlen(a) == 7u);
#endif
}
TEST_CASE("PtrOrSpan int") {
int buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};
XSPAN_P(int) a(buf, XSpanCount(8));
CHECK(a.raw_size_in_bytes() == 8 * sizeof(int));
XSPAN_P(int) b = a.subspan(0, 7);
CHECK(b.raw_size_in_bytes() == 7 * sizeof(int));
XSPAN_P(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(*b == 0);
CHECK(*c == 1);
a = buf + 7;
#ifdef UPX_VERSION_HEX
CHECK(get_le32(a) == ne32_to_le32(7));
#endif
a++;
#ifdef UPX_VERSION_HEX
CHECK_THROWS(get_le32(a));
#endif
CHECK_THROWS(raw_bytes(a, 1));
}
/*************************************************************************
// codegen
**************************************************************************/
namespace {
template <class T>
__acc_static_noinline int foo(T p) {
unsigned r = 0;
r += *p++;
r += *++p;
p += 3;
r += *p;
return r;
}
template <class T>
XSPAN_0(T)
make_span_0(T *ptr, size_t count) {
return PtrOrSpanOrNull<T>(ptr, count);
}
template <class T>
XSPAN_P(T)
make_span_p(T *ptr, size_t count) {
return PtrOrSpan<T>(ptr, count);
}
template <class T>
XSPAN_S(T)
make_span_s(T *ptr, size_t count) {
return Span<T>(ptr, count);
}
} // namespace
TEST_CASE("Span codegen") {
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);
}
#endif // WITH_XSPAN >= 2
/* vim:set ts=4 sw=4 et: */
+58 -77
View File
@@ -2,8 +2,7 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -21,68 +20,55 @@
If not, write to the Free Software Foundation, Inc., If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com>
*/ */
#include "../conf.h"
#include "conf.h"
#include "compress.h" #include "compress.h"
#include "mem.h" #include "../util/membuffer.h"
#include <zlib.h>
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler) unsigned upx_adler32(const void *buf, unsigned len, unsigned adler) {
{
if (len == 0) if (len == 0)
return adler; return adler;
assert(buf != NULL); assert(buf != nullptr);
#if 0 #if 1
return adler32(adler, (const Bytef *) buf, len); // zlib return upx_ucl_adler32(buf, len, adler);
#elif (WITH_UCL)
return ucl_adler32(adler, (const ucl_bytep) buf, len);
#else #else
# error return upx_zlib_adler32(buf, len, adler);
#endif #endif
} }
#if 0 // UNUSED
#if 0 /* UNUSED */
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc) unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
{ {
if (len == 0) if (len == 0)
return crc; return crc;
assert(buf != NULL); assert(buf != nullptr);
#if 0 #if 1
return crc32(crc, (const Bytef *) buf, len); // zlib return upx_ucl_crc32(buf, len, crc);
#elif (WITH_UCL)
return ucl_crc32(crc, (const ucl_bytep) buf, len);
#else #else
# error return upx_zlib_crc32(buf, len, crc);
#endif #endif
} }
#endif /* UNUSED */ #endif // UNUSED
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
int upx_compress ( const upx_bytep src, unsigned src_len, int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_bytep dst, unsigned* dst_len, upx_callback_p cb, int method, int level, const upx_compress_config_t *cconf,
upx_callback_p cb, upx_compress_result_t *cresult) {
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR; int r = UPX_E_ERROR;
upx_compress_result_t cresult_buffer; upx_compress_result_t cresult_buffer;
assert(method > 0); assert(level > 0); assert(method > 0);
assert(level > 0);
#if 1 #if 1
// set available bytes in dst // set available bytes in dst
@@ -99,67 +85,64 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
cresult = &cresult_buffer; cresult = &cresult_buffer;
memset(cresult, 0, sizeof(*cresult)); memset(cresult, 0, sizeof(*cresult));
#if 1 #if 1
// debug // debugging aid
cresult->method = method; cresult->debug.method = method;
cresult->level = level; cresult->debug.level = level;
cresult->u_len = src_len; cresult->debug.u_len = src_len;
cresult->c_len = 0; cresult->debug.c_len = 0;
#endif #endif
if (0) { if (__acc_cte(false)) {
} }
#if (WITH_LZMA) #if (WITH_LZMA)
else if (M_IS_LZMA(method)) else if (M_IS_LZMA(method))
r = upx_lzma_compress(src, src_len, dst, dst_len, r = upx_lzma_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
cb, method, level, cconf, cresult);
#endif #endif
#if (WITH_NRV) #if (WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if ((M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) && !opt->prefer_ucl)
r = upx_nrv_compress(src, src_len, dst, dst_len, r = upx_nrv_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
cb, method, level, cconf, cresult);
#endif #endif
#if (WITH_UCL) #if (WITH_UCL)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_ucl_compress(src, src_len, dst, dst_len, r = upx_ucl_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
cb, method, level, cconf, cresult); #endif
#if (WITH_ZSTD)
else if (M_IS_ZSTD(method))
r = upx_zstd_compress(src, src_len, dst, dst_len, cb, method, level, cconf, cresult);
#endif #endif
else { else {
throwInternalError("unknown compression method"); throwInternalError("unknown compression method");
} }
#if 1 #if 1
// debug // debugging aid
cresult->c_len = *dst_len; cresult->debug.c_len = *dst_len;
#endif #endif
return r; return r;
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
int upx_decompress ( const upx_bytep src, unsigned src_len, int upx_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_bytep dst, unsigned* dst_len, int method, const upx_compress_result_t *cresult) {
int method,
const upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR; int r = UPX_E_ERROR;
assert(*dst_len > 0); assert(*dst_len > 0);
assert(src_len < *dst_len); // must be compressed assert(src_len < *dst_len); // must be compressed
if (cresult && cresult->method == 0) if (cresult && cresult->debug.method == 0)
cresult = NULL; cresult = nullptr;
if (0) { if (__acc_cte(false)) {
} }
#if (WITH_LZMA) #if (WITH_LZMA)
else if (M_IS_LZMA(method)) else if (M_IS_LZMA(method))
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult); r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
#endif #endif
#if (WITH_NRV) #if (WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if ((M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) && !opt->prefer_ucl)
r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult); r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult);
#endif #endif
#if (WITH_UCL) #if (WITH_UCL)
@@ -169,6 +152,10 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
#if (WITH_ZLIB) #if (WITH_ZLIB)
else if (M_IS_DEFLATE(method)) else if (M_IS_DEFLATE(method))
r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult); r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult);
#endif
#if (WITH_ZSTD)
else if (M_IS_ZSTD(method))
r = upx_zstd_decompress(src, src_len, dst, dst_len, method, cresult);
#endif #endif
else { else {
throwInternalError("unknown decompression method"); throwInternalError("unknown decompression method");
@@ -177,41 +164,39 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
return r; return r;
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
int upx_test_overlap ( const upx_bytep buf, int upx_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off, unsigned src_len,
const upx_bytep tbuf, unsigned *dst_len, int method, const upx_compress_result_t *cresult) {
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR; int r = UPX_E_ERROR;
if (cresult && cresult->method == 0) if (cresult && cresult->debug.method == 0)
cresult = NULL; cresult = nullptr;
assert(*dst_len > 0); assert(*dst_len > 0);
assert(src_len < *dst_len); // must be compressed assert(src_len < *dst_len); // must be compressed
unsigned overlap_overhead = src_off + src_len - *dst_len; unsigned overlap_overhead = src_off + src_len - *dst_len;
assert((int) overlap_overhead > 0); assert((int) overlap_overhead > 0);
if (0) { if (__acc_cte(false)) {
} }
#if (WITH_LZMA) #if (WITH_LZMA)
else if (M_IS_LZMA(method)) else if (M_IS_LZMA(method))
r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult); r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif #endif
#if (WITH_NRV) #if (WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if ((M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) && !opt->prefer_ucl)
r = upx_nrv_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult); r = upx_nrv_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif #endif
#if (WITH_UCL) #if (WITH_UCL)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult); r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif
#if (WITH_ZSTD)
else if (M_IS_ZSTD(method))
r = upx_zstd_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif #endif
else { else {
throwInternalError("unknown decompression method"); throwInternalError("unknown decompression method");
@@ -220,8 +205,4 @@ int upx_test_overlap ( const upx_bytep buf,
return r; return r;
} }
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+59 -13
View File
@@ -2,8 +2,7 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -21,20 +20,42 @@
If not, write to the Free Software Foundation, Inc., If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com>
*/ */
#pragma once
#ifndef __UPX_COMPRESS_H #ifndef UPX_COMPRESS_H__
#define __UPX_COMPRESS_H 1 #define UPX_COMPRESS_H__ 1
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
#if (WITH_BZIP2)
int upx_bzip2_init(void);
const char *upx_bzip2_version_string(void);
int upx_bzip2_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
int upx_bzip2_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
int upx_bzip2_test_overlap ( const upx_bytep buf,
const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
#endif
#if (WITH_LZMA) #if (WITH_LZMA)
int upx_lzma_init(void);
const char *upx_lzma_version_string(void); const char *upx_lzma_version_string(void);
int upx_lzma_compress ( const upx_bytep src, unsigned src_len, int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -56,6 +77,7 @@ int upx_lzma_test_overlap ( const upx_bytep buf,
#if (WITH_NRV) #if (WITH_NRV)
int upx_nrv_init(void);
const char *upx_nrv_version_string(void); const char *upx_nrv_version_string(void);
int upx_nrv_compress ( const upx_bytep src, unsigned src_len, int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -77,6 +99,7 @@ int upx_nrv_test_overlap ( const upx_bytep buf,
#if (WITH_UCL) #if (WITH_UCL)
int upx_ucl_init(void);
const char *upx_ucl_version_string(void); const char *upx_ucl_version_string(void);
int upx_ucl_compress ( const upx_bytep src, unsigned src_len, int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -94,10 +117,13 @@ int upx_ucl_test_overlap ( const upx_bytep buf,
unsigned* dst_len, unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
unsigned upx_ucl_adler32(const void *buf, unsigned len, unsigned adler);
unsigned upx_ucl_crc32 (const void *buf, unsigned len, unsigned crc);
#endif #endif
#if (WITH_ZLIB) #if (WITH_ZLIB)
int upx_zlib_init(void);
const char *upx_zlib_version_string(void); const char *upx_zlib_version_string(void);
int upx_zlib_compress ( const upx_bytep src, unsigned src_len, int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -115,13 +141,33 @@ int upx_zlib_test_overlap ( const upx_bytep buf,
unsigned* dst_len, unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
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,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
int upx_zstd_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
int upx_zstd_test_overlap ( const upx_bytep buf,
const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
#endif #endif
#endif /* already included */ #endif /* already included */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+544
View File
@@ -0,0 +1,544 @@
/* compress_lzma.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
*/
#include "../conf.h"
#include "compress.h"
#include "../util/membuffer.h"
#if (ACC_CC_CLANG)
#pragma clang diagnostic ignored "-Wshadow"
#endif
#if (ACC_CC_GNUC >= 0x040200)
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#if (ACC_CC_MSC)
#pragma warning(disable : 4456) // -Wno-shadow
#endif
#if (ACC_CC_MSC && (_MSC_VER < 1900))
#pragma warning(disable : 4127) // warning C4127: conditional expression is constant
#endif
void lzma_compress_config_t::reset() {
pos_bits.reset();
lit_pos_bits.reset();
lit_context_bits.reset();
dict_size.reset();
fast_mode = 2;
num_fast_bytes.reset();
match_finder_cycles = 0;
max_num_probs = 0;
}
// INFO: the LZMA SDK is covered by a permissive license which allows
// using unmodified LZMA source code in UPX and the UPX stubs.
// See SPECIAL EXCEPTION below.
//
// Quoting from lzma-4.43/lzma.txt:
//
// LICENSE
// -------
//
// LZMA SDK is available under any of the following licenses:
//
// 1) GNU Lesser General Public License (GNU LGPL)
// 2) Common Public License (CPL)
// 3) Simplified license for unmodified code (read SPECIAL EXCEPTION)
// 4) Proprietary license
//
// It means that you can select one of these four options and follow rules
// of that license.
//
// 1,2) GNU LGPL and CPL licenses are pretty similar and both these
// licenses are classified as
// - "Free software licenses" at http://www.gnu.org/
// - "OSI-approved" at http://www.opensource.org/
//
// 3) SPECIAL EXCEPTION
//
// Igor Pavlov, as the author of this code, expressly permits you
// to statically or dynamically link your code (or bind by name)
// to the files from LZMA SDK without subjecting your linked
// code to the terms of the CPL or GNU LGPL.
// Any modifications or additions to files from LZMA SDK, however,
// are subject to the GNU LGPL or CPL terms.
//
// SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
// while you keep LZMA SDK code unmodified.
/*************************************************************************
// compress defaults
**************************************************************************/
static bool prepare_result(lzma_compress_result_t *res, unsigned src_len, int method, int level,
const lzma_compress_config_t *lcconf) {
// setup defaults
res->pos_bits = 2; // 0 .. 4
res->lit_pos_bits = 0; // 0 .. 4
res->lit_context_bits = 3; // 0 .. 8
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
res->fast_mode = 2; // 0 .. 2
res->num_fast_bytes = 64; // 5 .. 273
res->match_finder_cycles = 0;
// UPX overrides
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value;
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value;
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value;
res->dict_size = lzma_compress_config_t::dict_size_t::default_value;
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value;
// method overrides
if (method >= 0x100) {
res->pos_bits = (method >> 16) & 15;
res->lit_pos_bits = (method >> 12) & 15;
res->lit_context_bits = (method >> 8) & 15;
}
#if 0
// DEBUG - set sizes so that we use a maxmimum amount of stack.
// These settings cause res->num_probs == 3147574, i.e. we will
// need about 6 MiB of stack during runtime decompression.
res->lit_pos_bits = 4;
res->lit_context_bits = 8;
#endif
// TODO: tune these settings according to level
switch (level) {
case 1:
res->dict_size = 256 * 1024;
res->fast_mode = 0;
res->num_fast_bytes = 8;
break;
case 2:
res->dict_size = 256 * 1024;
res->fast_mode = 0;
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
res->dict_size = 8 * 1024 * 1024;
break;
case 10:
res->dict_size = src_len;
break;
default:
goto error;
}
// cconf overrides
if (lcconf) {
oassign(res->pos_bits, lcconf->pos_bits);
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
oassign(res->lit_context_bits, lcconf->lit_context_bits);
oassign(res->dict_size, lcconf->dict_size);
oassign(res->num_fast_bytes, lcconf->num_fast_bytes);
}
// limit dictionary size
if (res->dict_size > src_len)
res->dict_size = src_len;
// limit num_probs
if (lcconf && lcconf->max_num_probs) {
for (;;) {
unsigned n = 1846 + (768u << (res->lit_context_bits + res->lit_pos_bits));
if (n <= lcconf->max_num_probs)
break;
if (res->lit_pos_bits > res->lit_context_bits) {
if (res->lit_pos_bits == 0)
goto error;
res->lit_pos_bits -= 1;
} else {
if (res->lit_context_bits == 0)
goto error;
res->lit_context_bits -= 1;
}
}
}
lzma_compress_config_t::pos_bits_t::assertValue(res->pos_bits);
lzma_compress_config_t::lit_pos_bits_t::assertValue(res->lit_pos_bits);
lzma_compress_config_t::lit_context_bits_t::assertValue(res->lit_context_bits);
lzma_compress_config_t::dict_size_t::assertValue(res->dict_size);
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);
return true;
error:
return false;
}
/*************************************************************************
// compress - cruft because of pseudo-COM layer
**************************************************************************/
#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>
namespace MyLzma {
struct InStream final : public ISequentialInStream, public CMyUnknownImp {
virtual ~InStream() {}
MY_UNKNOWN_IMP
const Byte *b_buf = nullptr;
size_t b_size;
size_t b_pos;
void Init(const Byte *data, size_t size) {
b_buf = data;
b_size = size;
b_pos = 0;
}
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) override;
};
STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize) {
size_t remain = b_size - b_pos;
if (size > remain)
size = (UInt32) remain;
memmove(data, b_buf + b_pos, size);
b_pos += size;
if (processedSize != nullptr)
*processedSize = size;
return S_OK;
}
struct OutStream final : public ISequentialOutStream, public CMyUnknownImp {
virtual ~OutStream() {}
MY_UNKNOWN_IMP
Byte *b_buf = nullptr;
size_t b_size;
size_t b_pos;
bool overflow;
void Init(Byte *data, size_t size) {
b_buf = data;
b_size = size;
b_pos = 0;
overflow = false;
}
HRESULT WriteByte(Byte c) {
if (b_pos >= b_size) {
overflow = true;
return E_FAIL;
}
b_buf[b_pos++] = c;
return S_OK;
}
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) override;
};
STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) {
size_t remain = b_size - b_pos;
if (size > remain)
size = (UInt32) remain, overflow = true;
memmove(b_buf + b_pos, data, size);
b_pos += size;
if (processedSize != nullptr)
*processedSize = size;
return overflow ? E_FAIL : S_OK;
}
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;
};
STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) {
if (cb && cb->nprogress)
cb->nprogress(cb, (unsigned) *inSize, (unsigned) *outSize);
return S_OK;
}
} // namespace MyLzma
#include <lzma-sdk/C/Common/Alloc.cpp>
#include <lzma-sdk/C/Common/CRC.cpp>
// #include <lzma-sdk/C/7zip/Common/InBuffer.cpp>
#include <lzma-sdk/C/7zip/Common/OutBuffer.cpp>
#include <lzma-sdk/C/7zip/Common/StreamUtils.cpp>
#include <lzma-sdk/C/7zip/Compress/LZ/LZInWindow.cpp>
// #include <lzma-sdk/C/7zip/Compress/LZ/LZOutWindow.cpp>
// #include <lzma-sdk/C/7zip/Compress/LZMA/LZMADecoder.cpp>
#include <lzma-sdk/C/7zip/Compress/LZMA/LZMAEncoder.cpp>
#include <lzma-sdk/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp>
#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,
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
assert(M_IS_LZMA(method));
assert(level > 0);
assert(cresult != nullptr);
int r = UPX_E_ERROR;
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;
MyLzma::InStream is;
is.AddRef();
is.Init(src, src_len);
MyLzma::OutStream os;
os.AddRef();
os.Init(dst, *dst_len);
MyLzma::ProgressInfo progress;
progress.AddRef();
progress.cb = cb; // progress.Init()
NCompress::NLZMA::CEncoder enc;
const PROPID propIDs[8] = {
NCoderPropID::kPosStateBits, // 0 pb _posStateBits(2)
NCoderPropID::kLitPosBits, // 1 lp _numLiteralPosStateBits(0)
NCoderPropID::kLitContextBits, // 2 lc _numLiteralContextBits(3)
NCoderPropID::kDictionarySize, // 3 ds
NCoderPropID::kAlgorithm, // 4 fm _fastmode
NCoderPropID::kNumFastBytes, // 5 fb
NCoderPropID::kMatchFinderCycles, // 6 mfc _matchFinderCycles, _cutValue
NCoderPropID::kMatchFinder // 7 mf
};
PROPVARIANT pr[8];
const unsigned nprops = 8;
if (!prepare_result(res, src_len, method, level, lcconf))
goto error;
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
pr[7].vt = VT_BSTR;
pr[0].uintVal = res->pos_bits;
pr[1].uintVal = res->lit_pos_bits;
pr[2].uintVal = res->lit_context_bits;
pr[3].uintVal = res->dict_size;
pr[4].uintVal = res->fast_mode;
pr[5].uintVal = res->num_fast_bytes;
pr[6].uintVal = res->match_finder_cycles;
static const wchar_t matchfinder[] = L"BT4";
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
pr[7].bstrVal = ACC_PCAST(BSTR, ACC_UNCONST_CAST(wchar_t *, matchfinder));
try {
if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
goto error;
// encode properties in LZMA-style (5 bytes)
if (enc.WriteCoderProperties(&os) != S_OK)
goto error;
if (os.overflow) {
// r = UPX_E_OUTPUT_OVERRUN;
r = UPX_E_NOT_COMPRESSIBLE;
goto error;
}
assert(os.b_pos == 5);
// reset and encode properties in UPX-style (2 bytes)
os.b_pos = 0;
// 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)));
// compress
rh = enc.Code(&is, &os, nullptr, nullptr, &progress);
} catch (...) {
rh = E_OUTOFMEMORY;
}
assert(is.b_pos <= src_len);
assert(os.b_pos <= *dst_len);
if (rh == E_OUTOFMEMORY)
r = UPX_E_OUT_OF_MEMORY;
else if (os.overflow) {
assert(os.b_pos == *dst_len);
// r = UPX_E_OUTPUT_OVERRUN;
r = UPX_E_NOT_COMPRESSIBLE;
} else if (rh == S_OK) {
assert(is.b_pos == src_len);
r = UPX_E_OK;
}
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);
return r;
}
/*************************************************************************
// decompress
**************************************************************************/
#undef _LZMA_IN_CB
#undef _LZMA_OUT_READ
#undef _LZMA_PROB32
#undef _LZMA_LOC_OPT
#include <lzma-sdk/C/7zip/Compress/LZMA_C/LzmaDecode.h>
#include <lzma-sdk/C/7zip/Compress/LZMA_C/LzmaDecode.c>
int upx_lzma_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
int method, const upx_compress_result_t *cresult) {
assert(M_IS_LZMA(method));
// see res->num_probs above
COMPILE_TIME_ASSERT(sizeof(CProb) == 2)
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
CLzmaDecoderState s;
memset(&s, 0, sizeof(s));
SizeT src_out = 0, dst_out = 0;
int r = UPX_E_ERROR;
int rh;
// decode UPX-style properties (2 bytes)
if (src_len < 3) {
r = UPX_E_INPUT_OVERRUN;
goto error;
}
s.Properties.pb = src[0] & 7;
s.Properties.lp = (src[1] >> 4);
s.Properties.lc = src[1] & 15;
if (s.Properties.pb >= 5)
goto error;
if (s.Properties.lp >= 5)
goto error;
if (s.Properties.lc >= 9)
goto error;
// UPX extra stuff in first byte: 5 high bits convenience for stub decompressor
if ((src[0] >> 3) != s.Properties.lc + s.Properties.lp)
goto error;
src += 2;
src_len -= 2;
if (cresult) {
assert(cresult->debug.method == method);
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
assert(cresult->result_lzma.num_probs == (unsigned) 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);
UNUSED(res);
}
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
if (!s.Probs) {
r = UPX_E_OUT_OF_MEMORY;
goto error;
}
rh = LzmaDecode(&s, src, src_len, &src_out, dst, *dst_len, &dst_out);
assert(src_out <= src_len);
assert(dst_out <= *dst_len);
if (rh == 0) {
r = UPX_E_OK;
if (src_out != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
} else if (rh == LZMA_RESULT_INPUT_OVERRUN)
r = UPX_E_INPUT_OVERRUN;
else if (rh == LZMA_RESULT_OUTPUT_OVERRUN)
r = UPX_E_OUTPUT_OVERRUN;
error:
*dst_len = dst_out;
free(s.Probs);
return r;
}
/*************************************************************************
// test_overlap - see <ucl/ucl.h> for semantics
**************************************************************************/
int upx_lzma_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off,
unsigned src_len, unsigned *dst_len, int method,
const upx_compress_result_t *cresult) {
assert(M_IS_LZMA(method));
MemBuffer b(src_off + src_len);
memcpy(b + src_off, buf + src_off, src_len);
unsigned saved_dst_len = *dst_len;
int r = upx_lzma_decompress(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_lzma_init(void) { return 0; }
const char *upx_lzma_version_string(void) { return "4.43"; }
/*************************************************************************
// doctest checks
**************************************************************************/
TEST_CASE("upx_lzma_decompress") {
typedef const upx_byte C;
C *c_data;
upx_byte d_buf[16];
unsigned d_len;
int r;
c_data = (C *) "\x1a\x03\x00\x7f\xed\x3c\x00\x00\x00";
d_len = 16;
r = upx_lzma_decompress(c_data, 9, d_buf, &d_len, M_LZMA, nullptr);
CHECK((r == 0 && d_len == 16));
r = upx_lzma_decompress(c_data, 8, d_buf, &d_len, M_LZMA, nullptr);
CHECK(r == UPX_E_INPUT_OVERRUN);
d_len = 15;
r = upx_lzma_decompress(c_data, 9, d_buf, &d_len, M_LZMA, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
}
/* vim:set ts=4 sw=4 et: */
+367
View File
@@ -0,0 +1,367 @@
/* compress_ucl.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
*/
#include "../conf.h"
#include "compress.h"
/*************************************************************************
//
**************************************************************************/
static int convert_errno_from_ucl(int r) {
switch (r) {
case UCL_E_OK:
return UPX_E_OK;
case UCL_E_ERROR:
return UPX_E_ERROR;
case UCL_E_OUT_OF_MEMORY:
return UPX_E_OUT_OF_MEMORY;
case UCL_E_NOT_COMPRESSIBLE:
return UPX_E_NOT_COMPRESSIBLE;
case UCL_E_INPUT_OVERRUN:
return UPX_E_INPUT_OVERRUN;
case UCL_E_OUTPUT_OVERRUN:
return UPX_E_OUTPUT_OVERRUN;
case UCL_E_LOOKBEHIND_OVERRUN:
return UPX_E_LOOKBEHIND_OVERRUN;
case UCL_E_EOF_NOT_FOUND:
return UPX_E_EOF_NOT_FOUND;
case UCL_E_INPUT_NOT_CONSUMED:
return UPX_E_INPUT_NOT_CONSUMED;
case UCL_E_INVALID_ARGUMENT:
return UPX_E_INVALID_ARGUMENT;
// UCL extra:
case UCL_E_OVERLAP_OVERRUN:
return UPX_E_ERROR;
}
return UPX_E_ERROR;
}
extern "C" {
static void __UCL_CDECL wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user) {
if (state != -1 && state != 3)
return;
upx_callback_p cb = (upx_callback_p) user;
if (cb && cb->nprogress)
cb->nprogress(cb, a, b);
}
}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_callback_p cb_parm, int method, int level,
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
int r;
assert(level > 0);
assert(cresult != nullptr);
COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))
ucl_progress_callback_t cb;
cb.callback = nullptr;
cb.user = nullptr;
if (cb_parm && cb_parm->nprogress) {
cb.callback = wrap_nprogress_ucl;
cb.user = cb_parm;
}
ucl_compress_config_t cconf;
cconf.reset();
if (cconf_parm) {
// cconf = cconf_parm->conf_ucl; // struct copy
memcpy(&cconf, &cconf_parm->conf_ucl, sizeof(cconf));
}
ucl_uint *const res = cresult->result_ucl.result;
// assume no info available - fill in worst case results
// res[0] = 1; // min_offset_found - NOT USED
res[1] = src_len - 1; // max_offset_found
// res[2] = 2; // min_match_found - NOT USED
res[3] = src_len - 1; // max_match_found
// res[4] = 1; // min_run_found - NOT USED
res[5] = src_len; // max_run_found
res[6] = 1; // first_offset_found
// res[7] = 999999; // same_match_offsets_found - NOT USED
// prepare bit-buffer settings
cconf.bb_endian = 0;
cconf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16) {
static const unsigned char sizes[3] = {32, 8, 16};
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
} else {
throwInternalError("unknown compression method");
return UPX_E_ERROR;
}
// optimize compression parms
if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
cconf.max_offset = 8 * 1024 - 1;
else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
cconf.max_offset = 32 * 1024 - 1;
if M_IS_NRV2B (method)
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len, &cb, level, &cconf, res);
else if M_IS_NRV2D (method)
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len, &cb, level, &cconf, res);
else if M_IS_NRV2E (method)
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len, &cb, level, &cconf, res);
else {
throwInternalError("unknown compression method");
return UPX_E_ERROR;
}
// make sure first_offset_found is set
if (res[6] == 0)
res[6] = 1;
return convert_errno_from_ucl(r);
}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
int method, const upx_compress_result_t *cresult) {
int r;
switch (method) {
case M_NRV2B_8:
r = ucl_nrv2b_decompress_safe_8(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_decompress_safe_le16(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_decompress_safe_le32(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2D_8:
r = ucl_nrv2d_decompress_safe_8(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_decompress_safe_le16(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_decompress_safe_le32(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2E_8:
r = ucl_nrv2e_decompress_safe_8(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_decompress_safe_le16(src, src_len, dst, dst_len, nullptr);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_decompress_safe_le32(src, src_len, dst, dst_len, nullptr);
break;
default:
throwInternalError("unknown decompression method");
return UPX_E_ERROR;
}
UNUSED(cresult);
return convert_errno_from_ucl(r);
}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off,
unsigned src_len, unsigned *dst_len, int method,
const upx_compress_result_t *cresult) {
int r;
UNUSED(tbuf); // not needed for UCL
switch (method) {
case M_NRV2B_8:
r = ucl_nrv2b_test_overlap_8(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_test_overlap_le16(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_test_overlap_le32(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2D_8:
r = ucl_nrv2d_test_overlap_8(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_test_overlap_le16(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_test_overlap_le32(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2E_8:
r = ucl_nrv2e_test_overlap_8(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_test_overlap_le16(buf, src_off, src_len, dst_len, nullptr);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_test_overlap_le32(buf, src_off, src_len, dst_len, nullptr);
break;
default:
throwInternalError("unknown decompression method");
return UPX_E_ERROR;
}
UNUSED(cresult);
return convert_errno_from_ucl(r);
}
/*************************************************************************
// misc
**************************************************************************/
extern "C" {
static ucl_voidp __UCL_CDECL my_malloc(ucl_uint n) { return calloc(1, n); }
static void __UCL_CDECL my_free(ucl_voidp p) { free(p); }
}
int upx_ucl_init(void) {
if (ucl_init() != UCL_E_OK)
return -1;
if (UCL_VERSION != ucl_version() || strcmp(UCL_VERSION_STRING, ucl_version_string()) != 0)
return -2;
ucl_set_malloc_hooks(my_malloc, my_free);
return 0;
}
const char *upx_ucl_version_string(void) { return ucl_version_string(); }
unsigned upx_ucl_adler32(const void *buf, unsigned len, unsigned adler) {
return ucl_adler32(adler, (const ucl_bytep) buf, len);
}
#if 0 // UNUSED
unsigned upx_ucl_crc32(const void *buf, unsigned len, unsigned crc) {
return ucl_crc32(crc, (const ucl_bytep) buf, len);
}
#endif
/*************************************************************************
// doctest checks
**************************************************************************/
#if DEBUG && !defined(DOCTEST_CONFIG_DISABLE) && 1
#include "../util/membuffer.h"
static bool check_ucl(const int method, const unsigned expected_c_len) {
const unsigned u_len = 16384;
const unsigned c_extra = 4096;
MemBuffer u_buf, c_buf, d_buf;
unsigned c_len, d_len;
upx_compress_result_t cresult;
int r;
const int level = 3; // don't waste time
u_buf.alloc(u_len);
memset(u_buf, 0, u_len);
c_buf.allocForCompression(u_len, c_extra);
d_buf.allocForDecompression(u_len);
c_len = c_buf.getSize() - c_extra;
r = upx_ucl_compress(raw_bytes(u_buf, u_len), u_len, raw_index_bytes(c_buf, c_extra, c_len),
&c_len, nullptr, method, level, NULL_cconf, &cresult);
if (r != 0 || c_len != expected_c_len)
return false;
d_len = d_buf.getSize();
r = upx_ucl_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
&d_len, method, nullptr);
if (r != 0 || d_len != u_len || memcmp(u_buf, d_buf, u_len) != 0)
return false;
d_len = u_len - 1;
r = upx_ucl_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
&d_len, method, nullptr);
if (r == 0)
return false;
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
// unsigned x_len = d_len;
// r = upx_ucl_test_overlap(c_buf, u_buf, c_extra, c_len, &x_len, method, nullptr);
return true;
}
TEST_CASE("compress_ucl") {
CHECK(check_ucl(M_NRV2B_8, 34));
CHECK(check_ucl(M_NRV2B_LE16, 34));
CHECK(check_ucl(M_NRV2B_LE32, 34));
CHECK(check_ucl(M_NRV2D_8, 32));
CHECK(check_ucl(M_NRV2D_LE16, 32));
CHECK(check_ucl(M_NRV2D_LE32, 34));
CHECK(check_ucl(M_NRV2E_8, 32));
CHECK(check_ucl(M_NRV2E_LE16, 32));
CHECK(check_ucl(M_NRV2E_LE32, 34));
}
#endif // DEBUG
TEST_CASE("upx_ucl_decompress") {
typedef const upx_byte C;
C *c_data;
upx_byte d_buf[16];
unsigned d_len;
int r;
c_data = (C *) "\x92\xff\x10\x00\x00\x00\x00\x00\x48\xff";
d_len = 16;
r = upx_ucl_decompress(c_data, 10, d_buf, &d_len, M_NRV2B_8, nullptr);
CHECK((r == 0 && d_len == 16));
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2B_8, nullptr);
CHECK(r == UPX_E_INPUT_OVERRUN);
d_len = 15;
r = upx_ucl_decompress(c_data, 10, d_buf, &d_len, M_NRV2B_8, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
c_data = (C *) "\x92\xff\x10\x92\x49\x24\x92\xa0\xff";
d_len = 16;
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2D_8, nullptr);
CHECK((r == 0 && d_len == 16));
r = upx_ucl_decompress(c_data, 8, d_buf, &d_len, M_NRV2D_8, nullptr);
CHECK(r == UPX_E_INPUT_OVERRUN);
d_len = 15;
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2D_8, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
c_data = (C *) "\x90\xff\xb0\x92\x49\x24\x92\xa0\xff";
d_len = 16;
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2E_8, nullptr);
CHECK((r == 0 && d_len == 16));
r = upx_ucl_decompress(c_data, 8, d_buf, &d_len, M_NRV2E_8, nullptr);
CHECK(r == UPX_E_INPUT_OVERRUN);
d_len = 15;
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2E_8, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
}
/* vim:set ts=4 sw=4 et: */
+307
View File
@@ -0,0 +1,307 @@
/* compress_zlib.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
*/
#include "../conf.h"
#include "compress.h"
#include "../util/membuffer.h"
#include <zlib/zlib.h>
#include <zlib/deflate.h>
void zlib_compress_config_t::reset() {
mem_clear(this, sizeof(*this));
mem_level.reset();
window_bits.reset();
strategy.reset();
}
static int convert_errno_from_zlib(int zr) {
switch (zr) {
case Z_OK:
return UPX_E_OK;
// positive values
case Z_STREAM_END:
return UPX_E_ERROR;
case Z_NEED_DICT:
return UPX_E_ERROR;
// negative values
case Z_ERRNO:
return UPX_E_ERROR;
case Z_STREAM_ERROR:
return UPX_E_ERROR;
case Z_DATA_ERROR:
return UPX_E_ERROR;
case Z_MEM_ERROR:
return UPX_E_OUT_OF_MEMORY;
case Z_BUF_ERROR:
return UPX_E_OUTPUT_OVERRUN;
case Z_VERSION_ERROR:
return UPX_E_ERROR;
case -7: // UPX extra
return UPX_E_INPUT_OVERRUN;
}
return UPX_E_ERROR;
}
/*************************************************************************
//
**************************************************************************/
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,
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
assert(method == M_DEFLATE);
assert(level > 0);
assert(cresult != nullptr);
UNUSED(cb_parm);
int r = UPX_E_ERROR;
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;
if (level == 10)
level = 9;
zlib_compress_config_t::mem_level_t mem_level;
zlib_compress_config_t::window_bits_t window_bits;
zlib_compress_config_t::strategy_t strategy;
// cconf overrides
if (lcconf) {
oassign(mem_level, lcconf->mem_level);
oassign(window_bits, lcconf->window_bits);
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.avail_in = src_len;
s.next_out = dst;
s.avail_out = *dst_len;
s.total_in = s.total_out = 0;
zr = (int) deflateInit2(&s, level, Z_DEFLATED, 0 - (int) window_bits, mem_level, strategy);
if (zr != Z_OK)
goto error;
assert(s.state->level == level);
zr = deflate(&s, Z_FINISH);
if (zr != Z_STREAM_END)
goto error;
zr = deflateEnd(&s);
if (zr != Z_OK)
goto error;
r = UPX_E_OK;
goto done;
error:
(void) deflateEnd(&s);
r = convert_errno_from_zlib(zr);
if (r == UPX_E_OK)
r = UPX_E_ERROR;
done:
if (r == UPX_E_OK) {
if (s.avail_in != 0 || s.total_in != src_len)
r = UPX_E_ERROR;
}
assert(s.total_in <= src_len);
assert(s.total_out <= *dst_len);
*dst_len = s.total_out;
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_zlib_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
int method, const upx_compress_result_t *cresult) {
assert(method == M_DEFLATE);
UNUSED(method);
UNUSED(cresult);
int r = UPX_E_ERROR;
int zr;
z_stream s;
s.zalloc = (alloc_func) nullptr;
s.zfree = (free_func) nullptr;
s.next_in = ACC_UNCONST_CAST(upx_bytep, src);
s.avail_in = src_len;
s.next_out = dst;
s.avail_out = *dst_len;
s.total_in = s.total_out = 0;
zr = inflateInit2(&s, -15);
if (zr != Z_OK)
goto error;
zr = inflate(&s, Z_FINISH);
if (zr != Z_STREAM_END) {
if (zr == Z_BUF_ERROR && s.avail_in == 0)
zr = -7; // UPX extra
goto error;
}
zr = inflateEnd(&s);
if (zr != Z_OK)
goto error;
r = UPX_E_OK;
goto done;
error:
(void) inflateEnd(&s);
r = convert_errno_from_zlib(zr);
if (r == UPX_E_OK)
r = UPX_E_ERROR;
done:
if (r == UPX_E_OK) {
if (s.avail_in != 0 || s.total_in != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
}
assert(s.total_in <= src_len);
assert(s.total_out <= *dst_len);
*dst_len = s.total_out;
return r;
}
/*************************************************************************
// test_overlap - see <ucl/ucl.h> for semantics
**************************************************************************/
int upx_zlib_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off,
unsigned src_len, unsigned *dst_len, int method,
const upx_compress_result_t *cresult) {
assert(method == M_DEFLATE);
MemBuffer b(src_off + src_len);
memcpy(b + src_off, buf + src_off, src_len);
unsigned saved_dst_len = *dst_len;
int r = upx_zlib_decompress(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_zlib_init(void) {
if (strcmp(ZLIB_VERSION, zlibVersion()) != 0)
return -2;
return 0;
}
const char *upx_zlib_version_string(void) { return zlibVersion(); }
#if 0 // UNUSED
unsigned upx_zlib_adler32(const void *buf, unsigned len, unsigned adler) {
return adler32(adler, (const Bytef *) buf, len);
}
#endif
#if 0 // UNUSED
unsigned upx_zlib_crc32(const void *buf, unsigned len, unsigned crc) {
return crc32(crc, (const Bytef *) buf, len);
}
#endif
/*************************************************************************
// doctest checks
**************************************************************************/
#if DEBUG && !defined(DOCTEST_CONFIG_DISABLE) && 1
static bool check_zlib(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_zlib_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_zlib_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
&d_len, method, nullptr);
if (r != 0 || d_len != u_len || memcmp(u_buf, d_buf, u_len) != 0)
return false;
d_len = u_len - 1;
r = upx_zlib_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
&d_len, method, nullptr);
if (r == 0)
return false;
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
// unsigned x_len = d_len;
// r = upx_zlib_test_overlap(c_buf, u_buf, c_extra, c_len, &x_len, method, nullptr);
return true;
}
TEST_CASE("compress_zlib") {
CHECK(check_zlib(M_DEFLATE, 1, 89));
CHECK(check_zlib(M_DEFLATE, 3, 89));
CHECK(check_zlib(M_DEFLATE, 5, 33));
}
#endif // DEBUG
TEST_CASE("upx_zlib_decompress") {
typedef const upx_byte C;
C *c_data;
upx_byte d_buf[16];
unsigned d_len;
int r;
c_data = (C *) "\xfb\xff\x1f\x15\x00\x00";
d_len = 16;
r = upx_zlib_decompress(c_data, 6, d_buf, &d_len, M_DEFLATE, nullptr);
CHECK((r == 0 && d_len == 16));
r = upx_zlib_decompress(c_data, 5, d_buf, &d_len, M_DEFLATE, nullptr);
CHECK(r == UPX_E_INPUT_OVERRUN);
d_len = 15;
r = upx_zlib_decompress(c_data, 6, d_buf, &d_len, M_DEFLATE, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
}
/* vim:set ts=4 sw=4 et: */
+229
View File
@@ -0,0 +1,229 @@
/* compress_zstd.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
*/
#include "../conf.h"
void zstd_compress_config_t::reset() { mem_clear(this, sizeof(*this)); }
#if WITH_ZSTD
#include "compress.h"
#include "../util/membuffer.h"
#include <zstd/lib/zstd.h>
#include <zstd/lib/zstd_errors.h>
#include <zstd/lib/compress/hist.h>
static int convert_errno_from_zstd(size_t zr) {
const ZSTD_ErrorCode ze = ZSTD_getErrorCode(zr);
switch (ze) {
case ZSTD_error_memory_allocation:
return UPX_E_OUT_OF_MEMORY;
case ZSTD_error_srcSize_wrong:
return UPX_E_INPUT_OVERRUN;
case ZSTD_error_dstSize_tooSmall:
return UPX_E_OUTPUT_OVERRUN;
default:
break;
}
return UPX_E_ERROR;
}
/*************************************************************************
// TODO later: use advanced compression API for compression finetuning
**************************************************************************/
int upx_zstd_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
upx_callback_p cb_parm, int method, int level,
const upx_compress_config_t *cconf_parm, upx_compress_result_t *cresult) {
assert(method == M_ZSTD);
assert(level > 0);
assert(cresult != nullptr);
UNUSED(cb_parm);
int r = UPX_E_ERROR;
size_t zr;
const zstd_compress_config_t *const lcconf = cconf_parm ? &cconf_parm->conf_zstd : nullptr;
zstd_compress_result_t *const res = &cresult->result_zstd;
// TODO later: map level 1..10 to zstd-level 1..22
if (level == 10)
level = 22;
// cconf overrides
if (lcconf) {
UNUSED(lcconf);
}
res->dummy = 0;
zr = ZSTD_compress(dst, *dst_len, src, src_len, level);
if (ZSTD_isError(zr)) {
*dst_len = 0; // TODO ???
r = convert_errno_from_zstd(zr);
assert(r != UPX_E_OK);
} else {
assert(zr <= *dst_len);
*dst_len = (unsigned) zr;
r = UPX_E_OK;
}
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_zstd_decompress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned *dst_len,
int method, const upx_compress_result_t *cresult) {
assert(method == M_ZSTD);
UNUSED(method);
UNUSED(cresult);
int r = UPX_E_ERROR;
size_t zr;
zr = ZSTD_decompress(dst, *dst_len, src, src_len);
if (ZSTD_isError(zr)) {
*dst_len = 0; // TODO ???
r = convert_errno_from_zstd(zr);
assert(r != UPX_E_OK);
} else {
assert(zr <= *dst_len);
*dst_len = (unsigned) zr;
r = UPX_E_OK;
}
return r;
}
/*************************************************************************
// test_overlap - see <ucl/ucl.h> for semantics
**************************************************************************/
int upx_zstd_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src_off,
unsigned src_len, unsigned *dst_len, int method,
const upx_compress_result_t *cresult) {
assert(method == M_ZSTD);
MemBuffer b(src_off + src_len);
memcpy(b + src_off, buf + src_off, src_len);
unsigned saved_dst_len = *dst_len;
int r = upx_zstd_decompress(raw_index_bytes(b, src_off, src_len), src_len,
raw_bytes(b, *dst_len), dst_len, method, cresult);
if (r != UPX_E_OK)
return r;
if (*dst_len != saved_dst_len)
return UPX_E_ERROR;
// NOTE: there is a very tiny possibility that decompression has
// succeeded but the data is not restored correctly because of
// in-place buffer overlapping, so we use an extra memcmp().
if (tbuf != nullptr && memcmp(tbuf, b, *dst_len) != 0)
return UPX_E_ERROR;
return UPX_E_OK;
}
/*************************************************************************
// misc
**************************************************************************/
int upx_zstd_init(void) {
if (strcmp(ZSTD_VERSION_STRING, ZSTD_versionString()) != 0)
return -2;
return 0;
}
const char *upx_zstd_version_string(void) { return ZSTD_VERSION_STRING; }
/*************************************************************************
// doctest checks
**************************************************************************/
#if DEBUG && !defined(DOCTEST_CONFIG_DISABLE) && 1
static bool check_zstd(const int method, const int level, const unsigned expected_c_len) {
const unsigned u_len = 16384;
const unsigned c_extra = 4096;
MemBuffer u_buf, c_buf, d_buf;
unsigned c_len, d_len;
upx_compress_result_t cresult;
int r;
u_buf.alloc(u_len);
memset(u_buf, 0, u_len);
c_buf.allocForCompression(u_len, c_extra);
d_buf.allocForDecompression(u_len);
c_len = c_buf.getSize() - c_extra;
r = upx_zstd_compress(raw_bytes(u_buf, u_len), u_len, raw_index_bytes(c_buf, c_extra, c_len),
&c_len, nullptr, method, level, NULL_cconf, &cresult);
if (r != 0 || c_len != expected_c_len)
return false;
d_len = d_buf.getSize();
r = upx_zstd_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
&d_len, method, nullptr);
if (r != 0 || d_len != u_len || memcmp(u_buf, d_buf, u_len) != 0)
return false;
d_len = u_len - 1;
r = upx_zstd_decompress(raw_index_bytes(c_buf, c_extra, c_len), c_len, raw_bytes(d_buf, d_len),
&d_len, method, nullptr);
if (r == 0)
return false;
// TODO: rewrite Packer::findOverlapOverhead() so that we can test it here
// unsigned x_len = d_len;
// r = upx_zstd_test_overlap(c_buf, u_buf, c_extra, c_len, &x_len, method, nullptr);
return true;
}
TEST_CASE("compress_zstd") {
CHECK(check_zstd(M_ZSTD, 1, 19));
CHECK(check_zstd(M_ZSTD, 3, 19));
CHECK(check_zstd(M_ZSTD, 5, 19));
}
#endif // DEBUG
TEST_CASE("upx_zstd_decompress") {
typedef const upx_byte C;
C *c_data;
upx_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";
d_len = 32;
r = upx_zstd_decompress(c_data, 16, d_buf, &d_len, M_ZSTD, nullptr);
CHECK((r == 0 && d_len == 32));
r = upx_zstd_decompress(c_data, 15, d_buf, &d_len, M_ZSTD, nullptr);
CHECK(r == UPX_E_INPUT_OVERRUN);
d_len = 31;
r = upx_zstd_decompress(c_data, 16, d_buf, &d_len, M_ZSTD, nullptr);
CHECK(r == UPX_E_OUTPUT_OVERRUN);
}
#endif // WITH_ZSTD
/* vim:set ts=4 sw=4 et: */
-802
View File
@@ -1,802 +0,0 @@
/* compress_lzma.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "compress.h"
#include "mem.h"
void lzma_compress_config_t::reset()
{
memset(this, 0, sizeof(*this));
pos_bits.reset();
lit_pos_bits.reset();
lit_context_bits.reset();
dict_size.reset();
fast_mode = 2;
num_fast_bytes.reset();
match_finder_cycles = 0;
max_num_probs = 0;
}
#if !(WITH_LZMA)
extern int compress_lzma_dummy;
int compress_lzma_dummy = 0;
#else
#define opt compress_lzma_opt
#undef USE_LZMA_PROPERTIES
// INFO: the LZMA SDK is covered by a permissive license which allows
// using unmodified LZMA source code in UPX and the UPX stubs.
// See SPECIAL EXCEPTION below.
//
// Quoting from lzma-4.43/lzma.txt:
//
// LICENSE
// -------
//
// LZMA SDK is available under any of the following licenses:
//
// 1) GNU Lesser General Public License (GNU LGPL)
// 2) Common Public License (CPL)
// 3) Simplified license for unmodified code (read SPECIAL EXCEPTION)
// 4) Proprietary license
//
// It means that you can select one of these four options and follow rules
// of that license.
//
// 1,2) GNU LGPL and CPL licenses are pretty similar and both these
// licenses are classified as
// - "Free software licenses" at http://www.gnu.org/
// - "OSI-approved" at http://www.opensource.org/
//
// 3) SPECIAL EXCEPTION
//
// Igor Pavlov, as the author of this code, expressly permits you
// to statically or dynamically link your code (or bind by name)
// to the files from LZMA SDK without subjecting your linked
// code to the terms of the CPL or GNU LGPL.
// Any modifications or additions to files from LZMA SDK, however,
// are subject to the GNU LGPL or CPL terms.
//
// SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
// while you keep LZMA SDK code unmodified.
#if (WITH_LZMA >= 0x461)
#include "C/7zVersion.h"
#if (WITH_LZMA != (0x100 * MY_VER_MAJOR) + (0x10 * (MY_VER_MINOR / 10)) + (MY_VER_MINOR % 10))
# error "WITH_LZMA version mismatch"
#endif
#include "C/Types.h"
static void *cb_alloc(void *, size_t size) {
return malloc(size);
}
static void cb_free(void *, void *ptr) {
free(ptr);
}
#endif
/*************************************************************************
// compress defaults
**************************************************************************/
static int prepare(lzma_compress_result_t *res,
unsigned src_len, int method, int level,
const lzma_compress_config_t *lcconf)
{
// setup defaults
res->pos_bits = 2; // 0 .. 4
res->lit_pos_bits = 0; // 0 .. 4
res->lit_context_bits = 3; // 0 .. 8
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
res->fast_mode = 2;
res->num_fast_bytes = 64; // 5 .. 273
res->match_finder_cycles = 0;
#if 1
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value_c;
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value_c;
res->dict_size = lzma_compress_config_t::dict_size_t::default_value_c;
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
#endif
// method overrides
if (method >= 0x100) {
res->pos_bits = (method >> 16) & 15;
res->lit_pos_bits = (method >> 12) & 15;
res->lit_context_bits = (method >> 8) & 15;
}
#if 0
// DEBUG - set sizes so that we use a maxmimum amount of stack.
// These settings cause res->num_probs == 3147574, i.e. we will
// need about 6 MiB of stack during runtime decompression.
res->lit_pos_bits = 4;
res->lit_context_bits = 8;
#endif
// FIXME: tune these settings according to level
switch (level)
{
case 1:
res->dict_size = 256 * 1024;
res->fast_mode = 0;
res->num_fast_bytes = 8;
break;
case 2:
res->dict_size = 256 * 1024;
res->fast_mode = 0;
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
res->dict_size = 8 * 1024 * 1024;
break;
case 10:
res->dict_size = src_len;
break;
default:
goto error;
}
// cconf overrides
if (lcconf)
{
oassign(res->pos_bits, lcconf->pos_bits);
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
oassign(res->lit_context_bits, lcconf->lit_context_bits);
oassign(res->dict_size, lcconf->dict_size);
oassign(res->num_fast_bytes, lcconf->num_fast_bytes);
}
// limit dictionary size
if (res->dict_size > src_len)
res->dict_size = src_len;
// limit num_probs
if (lcconf && lcconf->max_num_probs)
{
for (;;)
{
unsigned n = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
if (n <= lcconf->max_num_probs)
break;
if (res->lit_pos_bits > res->lit_context_bits)
{
if (res->lit_pos_bits == 0)
goto error;
res->lit_pos_bits -= 1;
}
else
{
if (res->lit_context_bits == 0)
goto error;
res->lit_context_bits -= 1;
}
}
}
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
return 0;
error:
return -1;
}
/*************************************************************************
// compress
**************************************************************************/
#if (WITH_LZMA >= 0x461)
#define kLiteralNextStates kLiteralNextStates_enc
#include "C/LzmaEnc.h"
#include "C/LzmaEnc.c"
#include "C/LzFind.c"
#undef kLiteralNextStates
#undef kNumFullDistances
struct upx_ICompressProgress {
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
upx_callback_p cb;
};
static SRes cb_progress(void *p, UInt64 inSize, UInt64 outSize) {
upx_callback_p cb = ((upx_ICompressProgress *) p)->cb;
if (cb && cb->nprogress)
cb->nprogress(cb, (unsigned) inSize, (unsigned) outSize);
return SZ_OK;
}
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
assert(level > 0); assert(cresult != NULL);
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
int r = UPX_E_ERROR;
int rh;
unsigned dst_avail = *dst_len;
*dst_len = 0;
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
upx_ICompressProgress progress;
progress.Progress = cb_progress; progress.cb = cb;
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
lzma_compress_result_t *res = &cresult->result_lzma;
if (prepare(res, src_len, method, level, lcconf) != 0)
goto error;
CLzmaEncProps props; memset(&props, 0, sizeof(props));
props.level = level;
LzmaEncProps_Init(&props);
props.pb = res->pos_bits;
props.lp = res->lit_pos_bits;
props.lc = res->lit_context_bits;
props.dictSize = res->dict_size;
props.algo = res->fast_mode ? 1 : 0;
props.fb = res->num_fast_bytes;
props.mc = res->match_finder_cycles;
unsigned char props_buf[LZMA_PROPS_SIZE];
SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE;
#if (USE_LZMA_PROPERTIES)
if (dst_avail < 1)
goto error;
dst[0] = 0; // filled below
dst += 1; *dst_len += 1; dst_avail -= 1;
#else
if (dst_avail < 2)
goto error;
// extra stuff in first byte: 5 high bits convenience for stub decompressor
unsigned tt; tt = res->lit_context_bits + res->lit_pos_bits;
dst[0] = ((tt << 3) | res->pos_bits);
dst[1] = ((res->lit_pos_bits << 4) | (res->lit_context_bits));
dst += 2; *dst_len += 2; dst_avail -= 2;
#endif
SizeT x_len; x_len = dst_avail;
rh = LzmaEncode(dst, &x_len, src, src_len,
&props, props_buf, &props_buf_size, 0,
(ICompressProgress *) (void *) &progress, &cba, &cba);
assert(x_len <= dst_avail);
*dst_len += x_len;
if (rh == SZ_OK) {
#if (USE_LZMA_PROPERTIES)
dst[-1] = props_buf[0];
#endif
r = UPX_E_OK;
}
error:
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
return r;
}
#endif /* (WITH_LZMA >= 0x461) */
/*************************************************************************
// compress - cruft because of pseudo-COM layer
**************************************************************************/
#if (WITH_LZMA < 0x461)
#undef MSDOS
#undef OS2
#undef _WIN32
#undef _WIN32_WCE
#undef COMPRESS_MF_MT
#undef _NO_EXCEPTIONS
#if (WITH_LZMA >= 0x449)
# define INITGUID 1
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.h"
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.h"
#else
# include "C/Common/MyInitGuid.h"
//# include "C/7zip/Compress/LZMA/LZMADecoder.h"
# include "C/7zip/Compress/LZMA/LZMAEncoder.h"
#endif
namespace MyLzma {
struct InStream: public ISequentialInStream, public CMyUnknownImp
{
virtual ~InStream() { }
MY_UNKNOWN_IMP
const Byte *b_buf; size_t b_size; size_t b_pos;
void Init(const Byte *data, size_t size) {
b_buf = data; b_size = size; b_pos = 0;
}
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
size_t remain = b_size - b_pos;
if (size > remain) size = (UInt32) remain;
memcpy(data, b_buf + b_pos, size);
b_pos += size;
if (processedSize != NULL) *processedSize = size;
return S_OK;
}
struct OutStream : public ISequentialOutStream, public CMyUnknownImp
{
virtual ~OutStream() { }
MY_UNKNOWN_IMP
Byte *b_buf; size_t b_size; size_t b_pos; bool overflow;
void Init(Byte *data, size_t size) {
b_buf = data; b_size = size; b_pos = 0; overflow = false;
}
HRESULT WriteByte(Byte c) {
if (b_pos >= b_size) { overflow = true; return E_FAIL; }
b_buf[b_pos++] = c;
return S_OK;
}
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
size_t remain = b_size - b_pos;
if (size > remain) size = (UInt32) remain, overflow = true;
memcpy(b_buf + b_pos, data, size);
b_pos += size;
if (processedSize != NULL) *processedSize = size;
return overflow ? E_FAIL : S_OK;
}
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
{
virtual ~ProgressInfo() { }
MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
upx_callback_p cb;
};
STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
{
if (cb && cb->nprogress)
cb->nprogress(cb, (unsigned) *inSize, (unsigned) *outSize);
return S_OK;
}
} // namespace
#if (ACC_CC_INTELC) && defined(__linux__)
# pragma warning(disable: 424) // #424: extra ";" ignored
#endif
#if (WITH_LZMA >= 0x449)
# include "C/Alloc.c"
# include "C/7zCrc.c"
# include "C/Compress/Lz/MatchFinder.c"
//# include "CPP/7zip/Common/InBuffer.cpp"
# include "CPP/7zip/Common/OutBuffer.cpp"
# include "CPP/7zip/Common/StreamUtils.cpp"
//# include "CPP/7zip/Compress/LZ/LZOutWindow.cpp"
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.cpp"
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.cpp"
# include "CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
#else
# include "C/Common/Alloc.cpp"
# include "C/Common/CRC.cpp"
//# include "C/7zip/Common/InBuffer.cpp"
# include "C/7zip/Common/OutBuffer.cpp"
# include "C/7zip/Common/StreamUtils.cpp"
# include "C/7zip/Compress/LZ/LZInWindow.cpp"
//# include "C/7zip/Compress/LZ/LZOutWindow.cpp"
//# include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
# include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
# include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
#endif
#undef RC_NORMALIZE
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
assert(level > 0); assert(cresult != NULL);
int r = UPX_E_ERROR;
HRESULT rh;
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
lzma_compress_result_t *res = &cresult->result_lzma;
MyLzma::InStream is; is.AddRef();
MyLzma::OutStream os; os.AddRef();
is.Init(src, src_len);
os.Init(dst, *dst_len);
MyLzma::ProgressInfo progress; progress.AddRef();
progress.cb = cb;
NCompress::NLZMA::CEncoder enc;
const PROPID propIDs[8] = {
NCoderPropID::kPosStateBits, // 0 pb _posStateBits(2)
NCoderPropID::kLitPosBits, // 1 lp _numLiteralPosStateBits(0)
NCoderPropID::kLitContextBits, // 2 lc _numLiteralContextBits(3)
NCoderPropID::kDictionarySize, // 3 ds
NCoderPropID::kAlgorithm, // 4 fm _fastmode
NCoderPropID::kNumFastBytes, // 5 fb
NCoderPropID::kMatchFinderCycles, // 6 mfc _matchFinderCycles, _cutValue
NCoderPropID::kMatchFinder // 7 mf
};
PROPVARIANT pr[8];
#ifdef COMPRESS_MF_BT4
const unsigned nprops = 8;
static wchar_t matchfinder[] = L"BT4";
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
pr[7].vt = VT_BSTR; pr[7].bstrVal = matchfinder;
#else
const unsigned nprops = 7;
#endif
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4;
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
if (prepare(res, src_len, method, level, lcconf) != 0)
goto error;
pr[0].uintVal = res->pos_bits;
pr[1].uintVal = res->lit_pos_bits;
pr[2].uintVal = res->lit_context_bits;
pr[3].uintVal = res->dict_size;
pr[4].uintVal = res->fast_mode;
pr[5].uintVal = res->num_fast_bytes;
pr[6].uintVal = res->match_finder_cycles;
#ifndef _NO_EXCEPTIONS
try {
#else
# error
#endif
if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
goto error;
if (enc.WriteCoderProperties(&os) != S_OK)
goto error;
if (os.overflow) {
//r = UPX_E_OUTPUT_OVERRUN;
r = UPX_E_NOT_COMPRESSIBLE;
goto error;
}
assert(os.b_pos == 5);
#if (USE_LZMA_PROPERTIES)
os.b_pos = 1;
#else
os.b_pos = 0;
// extra stuff in first byte: 5 high bits convenience for stub decompressor
unsigned t = res->lit_context_bits + res->lit_pos_bits;
os.WriteByte((t << 3) | res->pos_bits);
os.WriteByte((res->lit_pos_bits << 4) | (res->lit_context_bits));
#endif
rh = enc.Code(&is, &os, NULL, NULL, &progress);
#ifndef _NO_EXCEPTIONS
} catch (...) { rh = E_OUTOFMEMORY; }
#endif
assert(is.b_pos <= src_len);
assert(os.b_pos <= *dst_len);
if (rh == E_OUTOFMEMORY)
r = UPX_E_OUT_OF_MEMORY;
else if (os.overflow)
{
assert(os.b_pos == *dst_len);
//r = UPX_E_OUTPUT_OVERRUN;
r = UPX_E_NOT_COMPRESSIBLE;
}
else if (rh == S_OK)
{
assert(is.b_pos == src_len);
r = UPX_E_OK;
}
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);
return r;
}
#endif /* (WITH_LZMA < 0x461) */
/*************************************************************************
// decompress
**************************************************************************/
#if (WITH_LZMA >= 0x461)
#undef _LZMA_PROB32
#include "C/LzmaDec.h"
#include "C/LzmaDec.c"
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
#define Properties prop
assert(M_IS_LZMA(method));
// see res->num_probs above
COMPILE_TIME_ASSERT(sizeof(CLzmaProb) == 2)
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
CLzmaDec s; memset(&s, 0, sizeof(s));
SizeT srcLen = 0;
int r = UPX_E_ERROR;
SRes rh;
ELzmaStatus status;
#if (USE_LZMA_PROPERTIES)
rh = LzmaProps_Decode(&s.Properties, src, src_len);
if (rh != 0)
goto error;
src += 1; src_len -= 1;
#else
if (src_len < 3)
goto error;
s.Properties.pb = src[0] & 7;
s.Properties.lp = (src[1] >> 4);
s.Properties.lc = src[1] & 15;
if (s.Properties.pb >= 5) goto error;
if (s.Properties.lp >= 5) goto error;
if (s.Properties.lc >= 9) goto error;
// extra
if ((src[0] >> 3) != (int)(s.Properties.lc + s.Properties.lp)) goto error;
src += 2; src_len -= 2;
#endif
s.Properties.dicSize = 0;
if (cresult)
{
assert(cresult->method == method);
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
assert(cresult->result_lzma.num_probs == (unsigned) LzmaProps_GetNumProbs(&s.Properties));
const lzma_compress_result_t *res = &cresult->result_lzma;
UNUSED(res);
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
}
rh = LzmaDec_AllocateProbs2(&s, &s.Properties, &cba);
if (rh != SZ_OK)
{
r = UPX_E_OUT_OF_MEMORY;
goto error;
}
s.dic = dst; s.dicPos = 0; s.dicBufSize = *dst_len;
LzmaDec_Init(&s);
srcLen = src_len;
rh = LzmaDec_DecodeToDic(&s, *dst_len, src, &srcLen, LZMA_FINISH_ANY, &status);
assert(srcLen <= src_len);
assert(s.dicPos <= *dst_len);
if (rh == SZ_OK && status == LZMA_STATUS_NEEDS_MORE_INPUT)
rh = SZ_ERROR_INPUT_EOF;
if (rh == SZ_OK && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
{
r = UPX_E_OK;
if (srcLen != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
}
error:
*dst_len = s.dicPos;
LzmaDec_FreeProbs(&s, &cba);
return r;
#undef Properties
}
#endif /* (WITH_LZMA >= 0x461) */
/*************************************************************************
// decompress
**************************************************************************/
#if (WITH_LZMA < 0x461)
#undef _LZMA_IN_CB
#undef _LZMA_OUT_READ
#undef _LZMA_PROB32
#undef _LZMA_LOC_OPT
#if (WITH_LZMA >= 0x449)
# include "C/Compress/Lzma/LzmaDecode.h"
# include "C/Compress/Lzma/LzmaDecode.c"
#else
# include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
# include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
#endif
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
// see res->num_probs above
COMPILE_TIME_ASSERT(sizeof(CProb) == 2)
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
CLzmaDecoderState s; memset(&s, 0, sizeof(s));
SizeT src_out = 0, dst_out = 0;
int r = UPX_E_ERROR;
int rh;
#if (USE_LZMA_PROPERTIES)
if (src_len < 2)
goto error;
rh = LzmaDecodeProperties(&s.Properties, src, src_len);
if (rh != 0)
goto error;
src += 1; src_len -= 1;
#else
if (src_len < 3)
goto error;
s.Properties.pb = src[0] & 7;
s.Properties.lp = (src[1] >> 4);
s.Properties.lc = src[1] & 15;
if (s.Properties.pb >= 5) goto error;
if (s.Properties.lp >= 5) goto error;
if (s.Properties.lc >= 9) goto error;
// extra
if ((src[0] >> 3) != s.Properties.lc + s.Properties.lp) goto error;
src += 2; src_len -= 2;
#endif
if (cresult)
{
assert(cresult->method == method);
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
assert(cresult->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
const lzma_compress_result_t *res = &cresult->result_lzma;
UNUSED(res);
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
}
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
if (!s.Probs)
{
r = UPX_E_OUT_OF_MEMORY;
goto error;
}
rh = LzmaDecode(&s, src, src_len, &src_out, dst, *dst_len, &dst_out);
assert(src_out <= src_len);
assert(dst_out <= *dst_len);
if (rh == 0)
{
r = UPX_E_OK;
if (src_out != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
}
error:
*dst_len = dst_out;
free(s.Probs);
return r;
}
#endif /* (WITH_LZMA < 0x461) */
/*************************************************************************
// test_overlap - see <ucl/ucl.h> for semantics
**************************************************************************/
int upx_lzma_test_overlap ( const upx_bytep buf,
const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
MemBuffer b(src_off + src_len);
memcpy(b + src_off, buf + src_off, src_len);
unsigned saved_dst_len = *dst_len;
int r = upx_lzma_decompress(b + src_off, src_len, b, dst_len, method, cresult);
if (r != UPX_E_OK)
return r;
if (*dst_len != saved_dst_len)
return UPX_E_ERROR;
// NOTE: there is a very tiny possibility that decompression has
// succeeded but the data is not restored correctly because of
// in-place buffer overlapping.
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
return UPX_E_ERROR;
return UPX_E_OK;
}
/*************************************************************************
// misc
**************************************************************************/
const char *upx_lzma_version_string(void)
{
#if (WITH_LZMA >= 0x461)
return MY_VERSION;
#elif (WITH_LZMA + 0 == 0x457)
return "4.57";
#elif (WITH_LZMA + 0 == 0x449)
return "4.49";
#elif (WITH_LZMA + 0 == 0x443)
return "4.43";
#else
# error "unknown WITH_LZMA version"
return NULL;
#endif
}
#endif /* WITH_LZMA */
/*
vi:ts=4:et:nowrap
*/
-294
View File
@@ -1,294 +0,0 @@
/* compress_ucl.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "compress.h"
#if !(WITH_UCL)
extern int compress_ucl_dummy;
int compress_ucl_dummy = 0;
#else
#if 1 && !(UCL_USE_ASM) && (ACC_ARCH_I386)
# if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
# define UCL_USE_ASM 1
# endif
#endif
#if (UCL_NO_ASM)
# undef UCL_USE_ASM
#endif
#if (ACC_CFG_NO_UNALIGNED)
# undef UCL_USE_ASM
#endif
#if 1 && (UCL_USE_ASM)
# include <ucl/ucl_asm.h>
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
# define ucl_nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
# define ucl_nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
# define ucl_nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
# define ucl_nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
# define ucl_nrv2e_decompress_safe_8 ucl_nrv2e_decompress_asm_safe_8
# define ucl_nrv2e_decompress_safe_le16 ucl_nrv2e_decompress_asm_safe_le16
# define ucl_nrv2e_decompress_safe_le32 ucl_nrv2e_decompress_asm_safe_le32
#endif
/*************************************************************************
//
**************************************************************************/
static int convert_errno_from_ucl(int r)
{
switch (r)
{
case UCL_E_OK: return UPX_E_OK;
case UCL_E_ERROR: return UPX_E_ERROR;
case UCL_E_OUT_OF_MEMORY: return UPX_E_OUT_OF_MEMORY;
case UCL_E_NOT_COMPRESSIBLE: return UPX_E_NOT_COMPRESSIBLE;
case UCL_E_INPUT_OVERRUN: return UPX_E_INPUT_OVERRUN;
case UCL_E_OUTPUT_OVERRUN: return UPX_E_OUTPUT_OVERRUN;
case UCL_E_LOOKBEHIND_OVERRUN: return UPX_E_LOOKBEHIND_OVERRUN;
case UCL_E_EOF_NOT_FOUND: return UPX_E_EOF_NOT_FOUND;
case UCL_E_INPUT_NOT_CONSUMED: return UPX_E_INPUT_NOT_CONSUMED;
// case UCL_E_NOT_YET_IMPLEMENTED: return UPX_E_NOT_YET_IMPLEMENTED;
case UCL_E_INVALID_ARGUMENT: return UPX_E_INVALID_ARGUMENT;
// UCL extra:
case UCL_E_OVERLAP_OVERRUN: return UPX_E_ERROR;
}
return UPX_E_ERROR;
}
extern "C" {
static void __UCL_CDECL wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
{
if (state != -1 && state != 3) return;
upx_callback_p cb = (upx_callback_p) user;
if (cb && cb->nprogress)
cb->nprogress(cb, a, b);
}}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb_parm,
int method, int level,
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
int r;
assert(level > 0); assert(cresult != NULL);
COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))
ucl_progress_callback_t cb;
cb.callback = 0;
cb.user = NULL;
if (cb_parm && cb_parm->nprogress) {
cb.callback = wrap_nprogress_ucl;
cb.user = cb_parm;
}
ucl_compress_config_t cconf; cconf.reset();
if (cconf_parm)
memcpy(&cconf, &cconf_parm->conf_ucl, sizeof(cconf)); // cconf = cconf_parm->conf_ucl; // struct copy
ucl_uint *res = cresult->result_ucl.result;
// assume no info available - fill in worst case results
//res[0] = 1; // min_offset_found - NOT USED
res[1] = src_len - 1; // max_offset_found
//res[2] = 2; // min_match_found - NOT USED
res[3] = src_len - 1; // max_match_found
//res[4] = 1; // min_run_found - NOT USED
res[5] = src_len; // max_run_found
res[6] = 1; // first_offset_found
//res[7] = 999999; // same_match_offsets_found - NOT USED
// prepare bit-buffer settings
cconf.bb_endian = 0;
cconf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16)
{
static const unsigned char sizes[3] = {32, 8, 16};
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
}
else {
throwInternalError("unknown compression method");
return UPX_E_ERROR;
}
// optimize compression parms
if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
cconf.max_offset = 8*1024-1;
else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
cconf.max_offset = 32*1024-1;
if M_IS_NRV2B(method)
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
&cb, level, &cconf, res);
else if M_IS_NRV2D(method)
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
&cb, level, &cconf, res);
else if M_IS_NRV2E(method)
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
&cb, level, &cconf, res);
else {
throwInternalError("unknown compression method");
return UPX_E_ERROR;
}
// make sure first_offset_found is set
if (res[6] == 0)
res[6] = 1;
return convert_errno_from_ucl(r);
}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
int r;
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_8:
r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
default:
throwInternalError("unknown decompression method");
return UPX_E_ERROR;
}
UNUSED(cresult);
return convert_errno_from_ucl(r);
}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_test_overlap ( const upx_bytep buf,
const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
int r;
UNUSED(tbuf); // not needed for UCL
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_8:
r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
default:
throwInternalError("unknown decompression method");
return UPX_E_ERROR;
}
UNUSED(cresult);
return convert_errno_from_ucl(r);
}
/*************************************************************************
// misc
**************************************************************************/
const char *upx_ucl_version_string(void)
{
return ucl_version_string();
}
#endif /* WITH_UCL */
/*
vi:ts=4:et:nowrap
*/
-235
View File
@@ -1,235 +0,0 @@
/* compress_zlib.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "compress.h"
#include "mem.h"
void zlib_compress_config_t::reset()
{
memset(this, 0, sizeof(*this));
mem_level.reset();
window_bits.reset();
strategy.reset();
}
#if !(WITH_ZLIB)
extern int compress_zlib_dummy;
int compress_zlib_dummy = 0;
#else
#include <zlib.h>
static int convert_errno_from_zlib(int zr)
{
switch (zr)
{
case Z_OK: return UPX_E_OK;
case Z_DATA_ERROR: return UPX_E_ERROR;
case Z_NEED_DICT: return UPX_E_ERROR;
}
return UPX_E_ERROR;
}
/*************************************************************************
//
**************************************************************************/
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,
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
assert(method == M_DEFLATE);
assert(level > 0); assert(cresult != NULL);
UNUSED(cb_parm);
int r = UPX_E_ERROR;
int zr;
const zlib_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_zlib : NULL;
zlib_compress_result_t *res = &cresult->result_zlib;
if (level == 10)
level = 9;
zlib_compress_config_t::mem_level_t mem_level;
zlib_compress_config_t::window_bits_t window_bits;
zlib_compress_config_t::strategy_t strategy;
// cconf overrides
if (lcconf)
{
oassign(mem_level, lcconf->mem_level);
oassign(window_bits, lcconf->window_bits);
oassign(strategy, lcconf->strategy);
}
res->dummy = 0;
z_stream s;
s.zalloc = (alloc_func) 0;
s.zfree = (free_func) 0;
s.next_in = const_cast<upx_bytep>(src); // UNCONST
s.avail_in = src_len;
s.next_out = dst;
s.avail_out = *dst_len;
s.total_in = s.total_out = 0;
zr = deflateInit2(&s, level, Z_DEFLATED, 0 - (int)window_bits,
mem_level, strategy);
if (zr != Z_OK)
goto error;
zr = deflate(&s, Z_FINISH);
if (zr != Z_STREAM_END)
goto error;
zr = deflateEnd(&s);
if (zr != Z_OK)
goto error;
r = UPX_E_OK;
goto done;
error:
(void) deflateEnd(&s);
r = convert_errno_from_zlib(zr);
if (r == UPX_E_OK)
r = UPX_E_ERROR;
done:
if (r == UPX_E_OK)
{
if (s.avail_in != 0 || s.total_in != src_len)
r = UPX_E_ERROR;
}
assert(s.total_in <= src_len);
assert(s.total_out <= *dst_len);
*dst_len = s.total_out;
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(method == M_DEFLATE);
UNUSED(method);
UNUSED(cresult);
int r = UPX_E_ERROR;
int zr;
z_stream s;
s.zalloc = (alloc_func) 0;
s.zfree = (free_func) 0;
s.next_in = const_cast<upx_bytep>(src); // UNCONST
s.avail_in = src_len;
s.next_out = dst;
s.avail_out = *dst_len;
s.total_in = s.total_out = 0;
zr = inflateInit2(&s, -15);
if (zr != Z_OK)
goto error;
zr = inflate(&s, Z_FINISH);
if (zr != Z_STREAM_END)
goto error;
zr = inflateEnd(&s);
if (zr != Z_OK)
goto error;
r = UPX_E_OK;
goto done;
error:
(void) inflateEnd(&s);
r = convert_errno_from_zlib(zr);
if (r == UPX_E_OK)
r = UPX_E_ERROR;
done:
if (r == UPX_E_OK)
{
if (s.avail_in != 0 || s.total_in != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
}
assert(s.total_in <= src_len);
assert(s.total_out <= *dst_len);
*dst_len = s.total_out;
return r;
}
/*************************************************************************
// test_overlap - see <ucl/ucl.h> for semantics
**************************************************************************/
int upx_zlib_test_overlap ( const upx_bytep buf,
const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(method == M_DEFLATE);
MemBuffer b(src_off + src_len);
memcpy(b + src_off, buf + src_off, src_len);
unsigned saved_dst_len = *dst_len;
int r = upx_zlib_decompress(b + src_off, src_len, b, dst_len, method, cresult);
if (r != UPX_E_OK)
return r;
if (*dst_len != saved_dst_len)
return UPX_E_ERROR;
// NOTE: there is a very tiny possibility that decompression has
// succeeded but the data is not restored correctly because of
// in-place buffer overlapping.
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
return UPX_E_ERROR;
return UPX_E_OK;
}
/*************************************************************************
// misc
**************************************************************************/
const char *upx_zlib_version_string(void)
{
return zlibVersion();
}
#endif /* WITH_ZLIB */
/*
vi:ts=4:et:nowrap
*/
+430 -369
View File
File diff suppressed because it is too large Load Diff
+13 -35
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,11 +22,10 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h"
#if (USE_CONSOLE) #if (USE_CONSOLE)
@@ -34,63 +33,42 @@
// //
**************************************************************************/ **************************************************************************/
static int init(FILE *f, int o, int now) static int init(FILE *f, int o, int now) {
{
UNUSED(f); UNUSED(f);
UNUSED(o); UNUSED(o);
UNUSED(now); UNUSED(now);
return CON_FILE; return CON_FILE;
} }
static int set_fg(FILE *f, int fg) {
static int set_fg(FILE *f, int fg)
{
UNUSED(f); UNUSED(f);
UNUSED(fg); UNUSED(fg);
return -1; return -1;
} }
static void print0(FILE *f, const char *s) {
static void print0(FILE *f, const char *s)
{
#if 1 #if 1
fputs(s, f); fputs(s, f);
#else #else
/* filter out all ANSI sequences */ /* filter out all ANSI sequences */
int c; int c;
while ((c = *s++) != 0) while ((c = *s++) != 0) {
{ if (c == '\033' && *s == ']') {
if (c == '\033' && *s == ']')
{
while (*s && *s != 'm') while (*s && *s != 'm')
s++; s++;
} } else
else
fputc(c, f); fputc(c, f);
} }
#endif #endif
} }
static bool intro(FILE *f) {
static bool intro(FILE *f)
{
UNUSED(f); UNUSED(f);
return 0; return 0;
} }
console_t console_file = {init, set_fg, print0, intro};
console_t console_file =
{
init,
set_fg,
print0,
intro
};
#endif /* USE_CONSOLE */ #endif /* USE_CONSOLE */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+16 -41
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,13 +22,12 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h" FILE *con_term = nullptr;
FILE *con_term = NULL;
#if (USE_CONSOLE) #if (USE_CONSOLE)
@@ -41,9 +40,7 @@ console_t * con = &console_init;
int con_mode = CON_INIT; int con_mode = CON_INIT;
static void try_init(console_t *c, FILE *f) {
static void try_init(console_t *c, FILE *f)
{
int k; int k;
assert(c); assert(c);
@@ -56,11 +53,10 @@ static void try_init(console_t *c, FILE *f)
if (k != opt->console) if (k != opt->console)
return; return;
#endif #endif
if (k > con_mode) if (k > con_mode) {
{
con_mode = k; con_mode = k;
con = c; con = c;
con->init = 0; con->init = nullptr;
if (!con->set_fg) if (!con->set_fg)
con->set_fg = console_none.set_fg; con->set_fg = console_none.set_fg;
if (!con->print0) if (!con->print0)
@@ -70,9 +66,7 @@ static void try_init(console_t *c, FILE *f)
} }
} }
static int do_init(FILE *f) {
static int do_init(FILE *f)
{
assert(con_mode == CON_INIT); assert(con_mode == CON_INIT);
try_init(&console_none, f); try_init(&console_none, f);
@@ -98,13 +92,11 @@ static int do_init(FILE *f)
return con_mode; return con_mode;
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
static int init(FILE *f, int o, int now) static int init(FILE *f, int o, int now) {
{
if (con != me) if (con != me)
return con_mode; return con_mode;
assert(o == -1); assert(o == -1);
@@ -114,41 +106,28 @@ static int init(FILE *f, int o, int now)
return do_init(f); return do_init(f);
} }
static int set_fg(FILE *f, int fg) {
static int set_fg(FILE *f, int fg)
{
if (con == me) if (con == me)
init(f, -1, -1); init(f, -1, -1);
assert(con != me); assert(con != me);
return con->set_fg(f, fg); return con->set_fg(f, fg);
} }
static bool intro(FILE *f) {
static bool intro(FILE *f)
{
if (con == me) if (con == me)
init(f, -1, -1); init(f, -1, -1);
assert(con != me); assert(con != me);
return con->intro(f); return con->intro(f);
} }
console_t console_init = {init, set_fg, nullptr, intro};
console_t console_init = void con_fprintf(FILE *f, const char *format, ...) {
{
init,
set_fg,
0,
intro
};
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
{
va_list args; va_list args;
char buf[80 * 25]; char buf[80 * 25];
va_start(args, format); va_start(args, format);
upx_vsnprintf(buf, sizeof(buf), format,args); upx_safe_vsnprintf(buf, sizeof(buf), format, args);
va_end(args); va_end(args);
if (con == me) if (con == me)
@@ -159,8 +138,4 @@ void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
#endif /* USE_CONSOLE */ #endif /* USE_CONSOLE */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+10 -29
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,11 +22,10 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h"
#if (USE_CONSOLE) #if (USE_CONSOLE)
@@ -34,49 +33,31 @@
// //
**************************************************************************/ **************************************************************************/
static int init(FILE *f, int o, int now) static int init(FILE *f, int o, int now) {
{
UNUSED(f); UNUSED(f);
UNUSED(o); UNUSED(o);
UNUSED(now); UNUSED(now);
return CON_NONE; return CON_NONE;
} }
static int set_fg(FILE *f, int fg) {
static int set_fg(FILE *f, int fg)
{
UNUSED(f); UNUSED(f);
UNUSED(fg); UNUSED(fg);
return -1; return -1;
} }
static void print0(FILE *f, const char *s) {
static void print0(FILE *f, const char *s)
{
UNUSED(f); UNUSED(f);
UNUSED(s); UNUSED(s);
} }
static bool intro(FILE *f) {
static bool intro(FILE *f)
{
UNUSED(f); UNUSED(f);
return 0; return 0;
} }
console_t console_none = {init, set_fg, print0, intro};
console_t console_none =
{
init,
set_fg,
print0,
intro
};
#endif /* USE_CONSOLE */ #endif /* USE_CONSOLE */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+41 -90
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,11 +22,10 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h"
#if (USE_SCREEN) #if (USE_SCREEN)
@@ -35,13 +34,11 @@
#define mask_fg 0x0f #define mask_fg 0x0f
#define mask_bg 0xf0 #define mask_bg 0xf0
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
static int do_init(screen_t *s, int fd) static int do_init(screen_t *s, int fd) {
{
int fg, bg; int fg, bg;
if (s->init(s, fd) != 0) if (s->init(s, fd) != 0)
@@ -59,8 +56,7 @@ static int do_init(screen_t *s, int fd)
if (fg == (bg >> 4)) if (fg == (bg >> 4))
return -1; return -1;
if (bg != BG_BLACK) if (bg != BG_BLACK)
if (!s->isMono(s)) if (!s->isMono(s)) {
{
/* return 0; */ /* we could emulate ANSI mono */ /* return 0; */ /* we could emulate ANSI mono */
return -1; return -1;
} }
@@ -68,52 +64,43 @@ static int do_init(screen_t *s, int fd)
return 0; return 0;
} }
static screen_t *do_construct(screen_t *s, int fd) {
static screen_t *do_construct(screen_t *s, int fd)
{
if (!s) if (!s)
return NULL; return nullptr;
if (do_init(s,fd) != 0) if (do_init(s, fd) != 0) {
{
s->destroy(s); s->destroy(s);
return NULL; return nullptr;
} }
return s; return s;
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
static screen_t *screen = NULL; static screen_t *screen = nullptr;
static void __acc_cdecl_atexit do_destroy(void) static void __acc_cdecl_atexit do_destroy(void) {
{ if (screen) {
if (screen)
{
if (screen->atExit) if (screen->atExit)
screen->atExit(); screen->atExit();
screen->destroy(screen); screen->destroy(screen);
screen = NULL; screen = nullptr;
} }
} }
static int mode = -1; static int mode = -1;
static int init_fg = -1; static int init_fg = -1;
static int init_bg = -1; static int init_bg = -1;
static int cur_fg = -1; static int cur_fg = -1;
static int cur_bg = -1; static int cur_bg = -1;
static int init(FILE *f, int o, int now) {
static int init(FILE *f, int o, int now)
{
int fd = fileno(f); int fd = fileno(f);
int n; int n;
UNUSED(now); UNUSED(now);
assert(screen == NULL); assert(screen == nullptr);
if (o == CON_SCREEN) if (o == CON_SCREEN)
n = CON_SCREEN; n = CON_SCREEN;
@@ -126,7 +113,7 @@ static int init(FILE *f, int o, int now)
else else
return CON_INIT; return CON_INIT;
#if defined(__DJGPP__) #if (ACC_OS_DOS32) && defined(__DJGPP__)
if (!screen) if (!screen)
screen = do_construct(screen_djgpp2_construct(), fd); screen = do_construct(screen_djgpp2_construct(), fd);
#endif #endif
@@ -155,17 +142,14 @@ static int init(FILE *f, int o, int now)
return n; return n;
} }
static int set_fg(FILE *f, int fg) {
static int set_fg(FILE *f, int fg)
{
const int last_fg = cur_fg; const int last_fg = cur_fg;
int f1 = fg & mask_fg; int f1 = fg & mask_fg;
int f2 = init_fg & mask_fg; int f2 = init_fg & mask_fg;
UNUSED(f); UNUSED(f);
cur_fg = fg; cur_fg = fg;
if (screen->isMono(screen)) if (screen->isMono(screen)) {
{
const int b = (init_bg & mask_bg) >> 4; const int b = (init_bg & mask_bg) >> 4;
if (fg == -1) /* restore startup fg */ if (fg == -1) /* restore startup fg */
f1 = f2; f1 = f2;
@@ -175,9 +159,7 @@ static int set_fg(FILE *f, int fg)
f1 = (f2 == 0) ? 15 : 0; f1 = (f2 == 0) ? 15 : 0;
else else
f1 = (f2 == 0) ? 8 : 0; f1 = (f2 == 0) ? 8 : 0;
} } else if (con_mode == CON_ANSI_MONO && f1 != f2) {
else if (con_mode == CON_ANSI_MONO && f1 != f2)
{
f1 = f2 ^ 0x08; f1 = f2 ^ 0x08;
} }
@@ -185,9 +167,7 @@ static int set_fg(FILE *f, int fg)
return last_fg; return last_fg;
} }
static void print0(FILE *f, const char *ss) {
static void print0(FILE *f, const char *ss)
{
int cx, cy; int cx, cy;
int old_cx = 0, old_cy = 0; int old_cx = 0, old_cy = 0;
const int sx = screen->getCols(screen); const int sx = screen->getCols(screen);
@@ -200,54 +180,44 @@ static void print0(FILE *f, const char *ss)
UNUSED(f); UNUSED(f);
screen->getCursor(screen, &old_cx, &old_cy); screen->getCursor(screen, &old_cx, &old_cy);
cx = old_cx; cy = old_cy; cx = old_cx;
cy = old_cy;
for (pass = 0; pass < 2; pass++) for (pass = 0; pass < 2; pass++) {
{
const char *s = ss; const char *s = ss;
// char buffer for pass 2 // char buffer for pass 2
char p[256 + 1]; char p[256 + 1];
int pi = 0, px = 0, py = 0; int pi = 0, px = 0, py = 0;
for (;;) for (;;) {
{
// walk over whitespace // walk over whitespace
for (;;) for (;;) {
{ if (*s == '\n') {
if (*s == '\n')
{
cx = 0; cx = 0;
cy++; cy++;
} } else if (*s == '\r') {
else if (*s == '\r')
{
cx = 0; cx = 0;
if (pass > 0 && cy < sy) if (pass > 0 && cy < sy)
screen->clearLine(screen, cy); screen->clearLine(screen, cy);
} } else
else
break; break;
s++; s++;
} }
// adjust cursor // adjust cursor
if (cx >= sx) if (cx >= sx) {
{
cx = 0; cx = 0;
cy++; cy++;
} }
if (pass > 0) if (pass > 0) {
{
// check if we should print something // check if we should print something
if (pi > 0 && (*s == 0 || py != cy)) if (pi > 0 && (*s == 0 || py != cy)) {
{
p[pi] = 0; p[pi] = 0;
screen->putString(screen, p, px, py); screen->putString(screen, p, px, py);
pi = 0; pi = 0;
} }
// check if we should scroll even more (this can happen // check if we should scroll even more (this can happen
// if the string is longer than sy lines) // if the string is longer than sy lines)
if (cy >= sy) if (cy >= sy) {
{
int scroll_y = cy - sy + 1; int scroll_y = cy - sy + 1;
screen->scrollUp(screen, scroll_y); screen->scrollUp(screen, scroll_y);
cy -= scroll_y; cy -= scroll_y;
@@ -258,11 +228,9 @@ static void print0(FILE *f, const char *ss)
// done ? // done ?
if (*s == 0) if (*s == 0)
break; break;
if (pass > 0) if (pass > 0) {
{
// store current char // store current char
if (pi == 0) if (pi == 0) {
{
px = cx; px = cx;
py = cy; py = cy;
} }
@@ -273,18 +241,15 @@ static void print0(FILE *f, const char *ss)
s++; s++;
} }
if (pass == 0) if (pass == 0) {
{
// end of pass 1 - scroll up, restore cursor // end of pass 1 - scroll up, restore cursor
if (cy >= sy) if (cy >= sy) {
{
int scroll_y = cy - sy + 1; int scroll_y = cy - sy + 1;
screen->scrollUp(screen, scroll_y); screen->scrollUp(screen, scroll_y);
cy = old_cy - scroll_y; cy = old_cy - scroll_y;
if (cy < 0) if (cy < 0)
cy = 0; cy = 0;
} } else
else
cy = old_cy; cy = old_cy;
cx = old_cx; cx = old_cx;
} }
@@ -294,9 +259,7 @@ static void print0(FILE *f, const char *ss)
screen->refresh(screen); screen->refresh(screen);
} }
static bool intro(FILE *f) {
static bool intro(FILE *f)
{
UNUSED(f); UNUSED(f);
#if (USE_FRAMES) #if (USE_FRAMES)
if (screen->intro) if (screen->intro)
@@ -305,20 +268,8 @@ static bool intro(FILE *f)
return 0; return 0;
} }
console_t console_screen = {init, set_fg, print0, intro};
console_t console_screen =
{
init,
set_fg,
print0,
intro
};
#endif /* USE_SCREEN */ #endif /* USE_SCREEN */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+12 -37
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,10 +22,10 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#pragma once
/************************************************************************* /*************************************************************************
// //
@@ -56,7 +56,7 @@
#endif #endif
#endif #endif
#if 1 && defined(__DJGPP__) #if 1 && (ACC_OS_DOS32) && defined(__DJGPP__)
#define USE_SCREEN 1 #define USE_SCREEN 1
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) #elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
#define USE_SCREEN 1 #define USE_SCREEN 1
@@ -64,9 +64,10 @@
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__)) #elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
#define USE_SCREEN 1 #define USE_SCREEN 1
#define USE_SCREEN_WIN32 1 #define USE_SCREEN_WIN32 1
#elif 1 && (ACC_ARCH_M68K && ACC_OS_TOS)
#define NO_CONSOLE 1
#endif #endif
#if 0 || (NO_ANSI) #if 0 || (NO_ANSI)
#undef USE_ANSI #undef USE_ANSI
#endif #endif
@@ -80,7 +81,6 @@
#undef USE_FRAMES #undef USE_FRAMES
#endif #endif
#if 0 || (USE_ANSI) || (USE_SCREEN) #if 0 || (USE_ANSI) || (USE_SCREEN)
#define USE_CONSOLE 1 #define USE_CONSOLE 1
#endif #endif
@@ -94,41 +94,22 @@
#undef USE_FRAMES #undef USE_FRAMES
#endif #endif
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
enum { enum { CON_INIT, CON_NONE, CON_FILE, CON_ANSI_MONO, CON_ANSI_COLOR, CON_SCREEN, CON_UNUSED };
CON_INIT,
CON_NONE,
CON_FILE,
CON_ANSI_MONO,
CON_ANSI_COLOR,
CON_SCREEN,
CON_UNUSED
};
#if (USE_CONSOLE) #if (USE_CONSOLE)
typedef struct typedef struct {
{
int (*init)(FILE *f, int, int); int (*init)(FILE *f, int, int);
int (*set_fg)(FILE *f, int fg); int (*set_fg)(FILE *f, int fg);
void (*print0)(FILE *f, const char *s); void (*print0)(FILE *f, const char *s);
bool (*intro)(FILE *f); bool (*intro)(FILE *f);
} } console_t;
console_t;
#if defined(__GNUC__)
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
__attribute__((__format__(printf,2,3)));
#else
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
#endif
void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3);
#define FG_BLACK 0x00 #define FG_BLACK 0x00
#define FG_BLUE 0x01 #define FG_BLUE 0x01
@@ -158,7 +139,6 @@ void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
#endif /* USE_CONSOLE */ #endif /* USE_CONSOLE */
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -177,7 +157,6 @@ extern console_t console_ansi_mono;
extern console_t console_ansi_color; extern console_t console_ansi_color;
extern console_t console_screen; extern console_t console_screen;
#define con_fg(f, x) con->set_fg(f, x) #define con_fg(f, x) con->set_fg(f, x)
#else #else
@@ -187,8 +166,4 @@ extern console_t console_screen;
#endif /* USE_CONSOLE */ #endif /* USE_CONSOLE */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+88 -211
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,24 +22,25 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h" #if (USE_SCREEN) && (ACC_OS_DOS32) && defined(__DJGPP__)
#if (ACC_CC_GNUC >= 0x040300ul)
#if (USE_SCREEN) && defined(__DJGPP__) #pragma GCC diagnostic ignored "-Wvla"
#endif
#include "screen.h" #include "screen.h"
#define this local_this #define this self
#define mask_fg 0x0f #define mask_fg 0x0f
#define mask_bg 0xf0 #define mask_bg 0xf0
/* #define USE_SCROLLBACK 1 */ /* #define USE_SCROLLBACK 1 */
/************************************************************************* /*************************************************************************
// direct screen access // direct screen access
**************************************************************************/ **************************************************************************/
@@ -57,9 +58,9 @@
#define co80 _go32_info_block.linear_address_of_primary_screen #define co80 _go32_info_block.linear_address_of_primary_screen
#undef kbhit #undef kbhit
#define Cell upx_uint16_t
struct screen_data_t struct screen_data_t {
{
int mode; int mode;
int cols; int cols;
int rows; int rows;
@@ -69,92 +70,63 @@ struct screen_data_t
unsigned char attr; unsigned char attr;
unsigned char init_attr; unsigned char init_attr;
unsigned char empty_attr; unsigned char empty_attr;
unsigned short empty_cell; Cell empty_cell;
#if USE_SCROLLBACK #if USE_SCROLLBACK
/* scrollback buffer */ /* scrollback buffer */
unsigned short sb_buf[32][256]; Cell sb_buf[32][256];
int sb_size; int sb_size;
int sb_base; int sb_base;
int sb_sp; int sb_sp;
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
}; };
/* atExit information */ /* atExit information */
static struct static struct {
{
int cursor_shape; int cursor_shape;
} ae = { } ae = {-1};
-1
};
#if USE_SCROLLBACK #if USE_SCROLLBACK
static __inline__ void sb_add(screen_t *this, int *val, int inc) static __inline__ void sb_add(screen_t *this, int *val, int inc) {
{
*val = (*val + inc) & (this->data->sb_size - 1); *val = (*val + inc) & (this->data->sb_size - 1);
} }
static void sb_push(screen_t *this, const unsigned short *line, int len) static void sb_push(screen_t *this, const Cell *line, int len) {
{
memcpy(this->data->sb_buf[this->data->sb_sp], line, len); memcpy(this->data->sb_buf[this->data->sb_sp], line, len);
sb_add(this, &this->data->sb_sp, 1); sb_add(this, &this->data->sb_sp, 1);
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
sb_add(this, &this->data->sb_base, 1); sb_add(this, &this->data->sb_base, 1);
} }
static const unsigned short *sb_pop(screen_t *this) static const Cell *sb_pop(screen_t *this) {
{
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
return NULL; return nullptr;
sb_add(this, &this->data->sb_sp, -1); sb_add(this, &this->data->sb_sp, -1);
return this->data->sb_buf[this->data->sb_sp]; return this->data->sb_buf[this->data->sb_sp];
} }
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
static void refresh(screen_t *this) { UNUSED(this); }
static void refresh(screen_t *this) static __inline__ Cell make_cell(screen_t *this, int ch, int attr) {
{
UNUSED(this); UNUSED(this);
return (Cell) (((attr & 0xff) << 8) | (ch & 0xff));
} }
static int getMode(const screen_t *this) {
static __inline__
unsigned short make_cell(screen_t *this, int ch, int attr)
{
UNUSED(this);
return (unsigned short) (((attr & 0xff) << 8) | (ch & 0xff));
}
static int getMode(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return ScreenMode(); return ScreenMode();
} }
static int getPage(const screen_t *this) {
static int getPage(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return _farpeekb(dossel, 0x462); return _farpeekb(dossel, 0x462);
} }
static int getRows(const screen_t *this) { return this->data->rows; }
static int getRows(const screen_t *this) static int getCols(const screen_t *this) { return this->data->cols; }
{
return this->data->rows;
}
static int isMono(const screen_t *this) {
static int getCols(const screen_t *this)
{
return this->data->cols;
}
static int isMono(const screen_t *this)
{
if (this->data->mode == 7) if (this->data->mode == 7)
return 1; return 1;
if ((_farpeekb(dossel, 0x465) & (4 | 16)) != 0) if ((_farpeekb(dossel, 0x465) & (4 | 16)) != 0)
@@ -162,42 +134,26 @@ static int isMono(const screen_t *this)
return 0; return 0;
} }
static int getFg(const screen_t *this) { return this->data->attr & mask_fg; }
static int getFg(const screen_t *this) static int getBg(const screen_t *this) { return this->data->attr & mask_bg; }
{
return this->data->attr & mask_fg;
}
static void setFg(screen_t *this, int fg) {
static int getBg(const screen_t *this)
{
return this->data->attr & mask_bg;
}
static void setFg(screen_t *this, int fg)
{
this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg); this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg);
} }
static void setBg(screen_t *this, int bg) {
static void setBg(screen_t *this, int bg)
{
this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg); this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg);
} }
static void setCursor(screen_t *this, int x, int y) {
static void setCursor(screen_t *this, int x, int y) if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) {
{
if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows)
{
ScreenSetCursor(y, x); ScreenSetCursor(y, x);
this->data->cursor_x = x; this->data->cursor_x = x;
this->data->cursor_y = y; this->data->cursor_y = y;
} }
} }
/* /*
// I added ScreenGetCursor, because when upx prints something longer than // I added ScreenGetCursor, because when upx prints something longer than
// 1 line (an error message for example), the this->data->cursor_y can // 1 line (an error message for example), the this->data->cursor_y can
@@ -209,65 +165,52 @@ static void setCursor(screen_t *this, int x, int y)
// the 2 passes implementation. // the 2 passes implementation.
*/ */
static void getCursor(const screen_t *this, int *x, int *y) static void getCursor(const screen_t *this, int *x, int *y) {
{
int cx = this->data->cursor_x; int cx = this->data->cursor_x;
int cy = this->data->cursor_y; int cy = this->data->cursor_y;
#if 1 #if 1
ScreenGetCursor(&cy, &cx); ScreenGetCursor(&cy, &cx);
#endif #endif
if (x) *x = cx; if (x)
if (y) *y = cy; *x = cx;
if (y)
*y = cy;
} }
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) {
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y)
{
UNUSED(this); UNUSED(this);
ScreenPutChar(ch, attr, x, y); ScreenPutChar(ch, attr, x, y);
} }
static void putChar(screen_t *this, int ch, int x, int y) {
static void putChar(screen_t *this, int ch, int x, int y)
{
ScreenPutChar(ch, this->data->attr, x, y); ScreenPutChar(ch, this->data->attr, x, y);
} }
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y) {
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
{
UNUSED(this); UNUSED(this);
assert((int) strlen(s) <= 256); assert((int) strlen(s) <= 256);
assert(x + (int) strlen(s) <= this->data->cols); assert(x + (int) strlen(s) <= this->data->cols);
ScreenPutString(s, attr, x, y); ScreenPutString(s, attr, x, y);
} }
static void putString(screen_t *this, const char *s, int x, int y) {
static void putString(screen_t *this, const char *s, int x, int y)
{
assert((int) strlen(s) <= 256); assert((int) strlen(s) <= 256);
assert(x + (int) strlen(s) <= this->data->cols); assert(x + (int) strlen(s) <= this->data->cols);
ScreenPutString(s, this->data->attr, x, y); ScreenPutString(s, this->data->attr, x, y);
} }
/* private */ /* private */
static void getChar(screen_t *this, int *ch, int *attr, int x, int y) static void getChar(screen_t *this, int *ch, int *attr, int x, int y) {
{
UNUSED(this); UNUSED(this);
ScreenGetChar(ch, attr, x, y); ScreenGetChar(ch, attr, x, y);
} }
static int getCursorShape(const screen_t *this) {
static int getCursorShape(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return _farpeekw(dossel, 0x460); return _farpeekw(dossel, 0x460);
} }
static void setCursorShape(screen_t *this, int shape) {
static void setCursorShape(screen_t *this, int shape)
{
__dpmi_regs r; __dpmi_regs r;
memset(&r, 0, sizeof(r)); /* just in case... */ memset(&r, 0, sizeof(r)); /* just in case... */
@@ -280,17 +223,13 @@ static void setCursorShape(screen_t *this, int shape)
__dpmi_int(0x10, &r); __dpmi_int(0x10, &r);
} }
static int hideCursor(screen_t *this) {
static int hideCursor(screen_t *this)
{
int shape = getCursorShape(this); int shape = getCursorShape(this);
setCursorShape(this, 0x2000); setCursorShape(this, 0x2000);
return shape; return shape;
} }
static int init(screen_t *this, int fd) {
static int init(screen_t *this, int fd)
{
int mode; int mode;
int cols, rows; int cols, rows;
int attr; int attr;
@@ -314,7 +253,7 @@ static int init(screen_t *this, int fd)
if (getPage(this) != 0) if (getPage(this) != 0)
return -1; return -1;
#if 1 && defined(__DJGPP__) #if 1 && (ACC_OS_DOS32) && defined(__DJGPP__)
/* check for Windows NT/2000/XP */ /* check for Windows NT/2000/XP */
if (_get_dos_version(1) == 0x0532) if (_get_dos_version(1) == 0x0532)
return -1; return -1;
@@ -323,8 +262,7 @@ static int init(screen_t *this, int fd)
cols = ScreenCols(); cols = ScreenCols();
rows = ScreenRows(); rows = ScreenRows();
mode = getMode(this); mode = getMode(this);
if (mode > 0x13) if (mode > 0x13) {
{
/* assume this is some SVGA/VESA text mode */ /* assume this is some SVGA/VESA text mode */
__dpmi_regs r; __dpmi_regs r;
@@ -333,17 +271,14 @@ static int init(screen_t *this, int fd)
__dpmi_int(0x10, &r); __dpmi_int(0x10, &r);
if (r.h.ah == 0) if (r.h.ah == 0)
mode = r.x.bx; mode = r.x.bx;
} } else {
else
{
if (mode != 2 && mode != 3 && mode != 7) if (mode != 2 && mode != 3 && mode != 7)
return -1; return -1;
} }
ScreenGetCursor(&this->data->cursor_y, &this->data->cursor_x); ScreenGetCursor(&this->data->cursor_y, &this->data->cursor_x);
getChar(this,NULL,&attr,this->data->cursor_x,this->data->cursor_y); getChar(this, nullptr, &attr, this->data->cursor_x, this->data->cursor_y);
this->data->init_attr = attr; this->data->init_attr = attr;
if (mode != 7) if (mode != 7) {
{
/* Does it normally blink when bg has its 3rd bit set? */ /* Does it normally blink when bg has its 3rd bit set? */
int b_mask = (_farpeekb(dossel, 0x465) & 0x20) ? 0x70 : 0xf0; int b_mask = (_farpeekb(dossel, 0x465) & 0x20) ? 0x70 : 0xf0;
attr = attr & (mask_fg | b_mask); attr = attr & (mask_fg | b_mask);
@@ -360,20 +295,15 @@ static int init(screen_t *this, int fd)
return 0; return 0;
} }
static void updateLineN(screen_t *this, const void *line, int y, int len) {
static void updateLineN(screen_t *this, const void *line, int y, int len)
{
if (y >= 0 && y < this->data->rows && len > 0 && len <= 2 * this->data->cols) if (y >= 0 && y < this->data->rows && len > 0 && len <= 2 * this->data->cols)
movedata(_my_ds(), (unsigned) line, dossel, co80 + y * this->data->cols * 2, len); movedata(_my_ds(), (unsigned) line, dossel, co80 + y * this->data->cols * 2, len);
} }
static void clearLine(screen_t *this, int y) {
static void clearLine(screen_t *this, int y) if (y >= 0 && y < this->data->rows) {
{
if (y >= 0 && y < this->data->rows)
{
unsigned sp = co80 + y * this->data->cols * 2; unsigned sp = co80 + y * this->data->cols * 2;
unsigned short a = this->data->empty_cell; Cell a = this->data->empty_cell;
int i = this->data->cols; int i = this->data->cols;
_farsetsel(dossel); _farsetsel(dossel);
@@ -384,31 +314,25 @@ static void clearLine(screen_t *this, int y)
} }
} }
static void clear(screen_t *this) {
static void clear(screen_t *this)
{
unsigned char attr = ScreenAttrib; unsigned char attr = ScreenAttrib;
ScreenAttrib = this->data->empty_attr; ScreenAttrib = this->data->empty_attr;
ScreenClear(); ScreenClear();
ScreenAttrib = attr; ScreenAttrib = attr;
} }
static int scrollUp(screen_t *this, int lines) {
static int scrollUp(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
if (lines <= 0 || lines > sr) if (lines <= 0 || lines > sr)
return 0; return 0;
#if USE_SCROLLBACK #if USE_SCROLLBACK
/* copy to scrollback buffer */ /* copy to scrollback buffer */
for (y = 0; y < lines; y++) for (y = 0; y < lines; y++) {
{ Cell buf[sc];
unsigned short buf[ sc ];
movedata(dossel, co80 + y * this->data->cols * 2, _my_ds(), (unsigned) buf, sizeof(buf)); movedata(dossel, co80 + y * this->data->cols * 2, _my_ds(), (unsigned) buf, sizeof(buf));
sb_push(this, buf, sizeof(buf)); sb_push(this, buf, sizeof(buf));
} }
@@ -426,9 +350,7 @@ static int scrollUp(screen_t *this, int lines)
return lines; return lines;
} }
static int scrollDown(screen_t *this, int lines) {
static int scrollDown(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
@@ -437,21 +359,19 @@ static int scrollDown(screen_t *this, int lines)
return 0; return 0;
/* move screen down */ /* move screen down */
if (lines < sr) if (lines < sr) {
{
/* !@#% movedata can't handle overlapping regions... */ /* !@#% movedata can't handle overlapping regions... */
/* movedata(dossel,co80,dossel,co80+lines*sc*2,(sr-lines)*sc*2); */ /* movedata(dossel,co80,dossel,co80+lines*sc*2,(sr-lines)*sc*2); */
unsigned short buf[ (sr-lines)*sc ]; Cell buf[(sr - lines) * sc];
movedata(dossel, co80, _my_ds(), (unsigned) buf, sizeof(buf)); movedata(dossel, co80, _my_ds(), (unsigned) buf, sizeof(buf));
movedata(_my_ds(), (unsigned) buf, dossel, co80 + lines * sc * 2, sizeof(buf)); movedata(_my_ds(), (unsigned) buf, dossel, co80 + lines * sc * 2, sizeof(buf));
} }
/* copy top lines from scrollback buffer */ /* copy top lines from scrollback buffer */
for (y = lines; --y >= 0; ) for (y = lines; --y >= 0;) {
{
#if USE_SCROLLBACK #if USE_SCROLLBACK
const unsigned short *buf = sb_pop(this); const Cell *buf = sb_pop(this);
if (buf == NULL) if (buf == nullptr)
clearLine(this, y); clearLine(this, y);
else else
updateLineN(this, buf, y, sc * 2); updateLineN(this, buf, y, sc * 2);
@@ -464,24 +384,16 @@ static int scrollDown(screen_t *this, int lines)
return lines; return lines;
} }
static int getScrollCounter(const screen_t *this) { return this->data->scroll_counter; }
static int getScrollCounter(const screen_t *this) static int s_kbhit(screen_t *this) {
{
return this->data->scroll_counter;
}
static int s_kbhit(screen_t *this)
{
UNUSED(this); UNUSED(this);
return kbhit(); return kbhit();
} }
static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
static int intro(screen_t *this, void (*show_frames)(screen_t *) )
{
int shape; int shape;
unsigned short old_flags = __djgpp_hwint_flags; upx_uint16_t old_flags = __djgpp_hwint_flags;
if ((this->data->init_attr & mask_bg) != BG_BLACK) if ((this->data->init_attr & mask_bg) != BG_BLACK)
return 0; return 0;
@@ -501,65 +413,30 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *) )
return 1; return 1;
} }
static void atExit(void) {
static void atExit(void)
{
static int done = 0; static int done = 0;
if (done) return; if (done)
return;
done = 1; done = 1;
if (ae.cursor_shape >= 0) if (ae.cursor_shape >= 0)
setCursorShape(NULL,ae.cursor_shape); setCursorShape(nullptr, ae.cursor_shape);
} }
static const screen_t driver = {sobject_destroy, nullptr, /* finalize */
static const screen_t driver = atExit, init, refresh,
{ getMode, getPage, getRows,
sobject_destroy, getCols, isMono, getFg,
0, /* finalize, */ getBg, getCursor, getCursorShape,
atExit, setFg, setBg, setCursor,
init, setCursorShape, hideCursor, putChar,
refresh, putCharAttr, putString, putStringAttr,
getMode, clear, clearLine, updateLineN,
getPage, scrollUp, scrollDown, getScrollCounter,
getRows, s_kbhit, intro, (struct screen_data_t *) nullptr};
getCols,
isMono,
getFg,
getBg,
getCursor,
getCursorShape,
setFg,
setBg,
setCursor,
setCursorShape,
hideCursor,
putChar,
putCharAttr,
putString,
putStringAttr,
clear,
clearLine,
updateLineN,
scrollUp,
scrollDown,
getScrollCounter,
s_kbhit,
intro,
(struct screen_data_t *) 0
};
/* public constructor */ /* public constructor */
screen_t *screen_djgpp2_construct(void) screen_t *screen_djgpp2_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
{
return sobject_construct(&driver,sizeof(*driver.data));
}
#endif /* (USE_SCREEN) && (ACC_OS_DOS32) && defined(__DJGPP__) */
#endif /* (USE_SCREEN) && defined(__DJGPP__) */ /* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+17 -33
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,68 +22,57 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h"
#if (USE_SCREEN) #if (USE_SCREEN)
#define this local_this #define this self
#include "screen.h" #include "screen.h"
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
// ugly hacks // ugly hacks
static screen_t *last_screen = NULL; static screen_t *last_screen = nullptr;
screen_t *sobject_get_screen(void) screen_t *sobject_get_screen(void) { return last_screen; }
{
return last_screen;
}
void sobject_destroy(screen_t *this) {
void sobject_destroy(screen_t *this) last_screen = nullptr;
{
last_screen = NULL;
if (!this) if (!this)
return; return;
if (this->data) if (this->data) {
{
if (this->finalize) if (this->finalize)
this->finalize(this); this->finalize(this);
free(this->data); free(this->data);
this->data = NULL; this->data = nullptr;
} }
free(this); free(this);
} }
screen_t *sobject_construct(const screen_t *c, size_t data_size) {
screen_t *sobject_construct(const screen_t *c, size_t data_size)
{
screen_t *this; screen_t *this;
last_screen = NULL; last_screen = nullptr;
/* allocate object */ /* allocate object */
this = (screen_t *) malloc(sizeof(*this)); this = (screen_t *) malloc(sizeof(*this));
if (!this) if (!this)
return NULL; return nullptr;
/* copy function table */ /* copy function table */
*this = *c; *this = *c;
/* initialize instance variables */ /* initialize instance variables */
this->data = (struct screen_data_t *) malloc(data_size); this->data = (struct screen_data_t *) malloc(data_size);
if (!this->data) if (!this->data) {
{
free(this); free(this);
return NULL; return nullptr;
} }
memset(this->data, 0, data_size); memset(this->data, 0, data_size);
@@ -91,11 +80,6 @@ screen_t *sobject_construct(const screen_t *c, size_t data_size)
return this; return this;
} }
#endif /* (USE_SCREEN) */ #endif /* (USE_SCREEN) */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+93 -216
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,24 +22,22 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h"
#if (USE_SCREEN) && (USE_SCREEN_VCSA) #if (USE_SCREEN) && (USE_SCREEN_VCSA)
#include "screen.h" #include "screen.h"
#define this local_this #define this self
#define mask_fg 0x0f #define mask_fg 0x0f
#define mask_bg 0xf0 #define mask_bg 0xf0
/* #define USE_SCROLLBACK 1 */ /* #define USE_SCROLLBACK 1 */
/************************************************************************* /*************************************************************************
// direct screen access ( /dev/vcsaNN ) // direct screen access ( /dev/vcsaNN )
**************************************************************************/ **************************************************************************/
@@ -53,9 +51,9 @@
#include <linux/major.h> #include <linux/major.h>
#endif #endif
#define Cell upx_uint16_t
struct screen_data_t struct screen_data_t {
{
int fd; int fd;
int mode; int mode;
int page; int page;
@@ -67,128 +65,80 @@ struct screen_data_t
unsigned char attr; unsigned char attr;
unsigned char init_attr; unsigned char init_attr;
unsigned char map[256]; unsigned char map[256];
unsigned short empty_line[256]; Cell empty_line[256];
#if USE_SCROLLBACK #if USE_SCROLLBACK
/* scrollback buffer */ /* scrollback buffer */
unsigned short sb_buf[32][256]; Cell sb_buf[32][256];
int sb_size; int sb_size;
int sb_base; int sb_base;
int sb_sp; int sb_sp;
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
}; };
#if USE_SCROLLBACK #if USE_SCROLLBACK
static __inline__ void sb_add(screen_t *this, int *val, int inc) static __inline__ void sb_add(screen_t *this, int *val, int inc) {
{
*val = (*val + inc) & (this->data->sb_size - 1); *val = (*val + inc) & (this->data->sb_size - 1);
} }
static void sb_push(screen_t *this, const unsigned short *line, int len) static void sb_push(screen_t *this, const Cell *line, int len) {
{
memcpy(this->data->sb_buf[this->data->sb_sp], line, len); memcpy(this->data->sb_buf[this->data->sb_sp], line, len);
sb_add(this, &this->data->sb_sp, 1); sb_add(this, &this->data->sb_sp, 1);
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
sb_add(this, &this->data->sb_base, 1); sb_add(this, &this->data->sb_base, 1);
} }
static const unsigned short *sb_pop(screen_t *this) static const Cell *sb_pop(screen_t *this) {
{
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
return NULL; return nullptr;
sb_add(this, &this->data->sb_sp, -1); sb_add(this, &this->data->sb_sp, -1);
return this->data->sb_buf[this->data->sb_sp]; return this->data->sb_buf[this->data->sb_sp];
} }
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
static void refresh(screen_t *this) { UNUSED(this); }
static void refresh(screen_t *this) static __inline__ Cell make_cell(screen_t *this, int ch, int attr) {
{
UNUSED(this);
}
static __inline__
unsigned short make_cell(screen_t *this, int ch, int attr)
{
return ((attr & 0xff) << 8) | (this->data->map[ch & 0xff] & 0xff); return ((attr & 0xff) << 8) | (this->data->map[ch & 0xff] & 0xff);
} }
static int getMode(const screen_t *this) { return this->data->mode; }
static int getMode(const screen_t *this) static int getPage(const screen_t *this) { return this->data->page; }
{
return this->data->mode;
}
static int getRows(const screen_t *this) { return this->data->rows; }
static int getPage(const screen_t *this) static int getCols(const screen_t *this) { return this->data->cols; }
{
return this->data->page;
}
static int isMono(const screen_t *this) {
static int getRows(const screen_t *this)
{
return this->data->rows;
}
static int getCols(const screen_t *this)
{
return this->data->cols;
}
static int isMono(const screen_t *this)
{
/* FIXME */ /* FIXME */
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static int getFg(const screen_t *this) { return this->data->attr & mask_fg; }
static int getFg(const screen_t *this) static int getBg(const screen_t *this) { return this->data->attr & mask_bg; }
{
return this->data->attr & mask_fg;
}
static void setFg(screen_t *this, int fg) {
static int getBg(const screen_t *this)
{
return this->data->attr & mask_bg;
}
static void setFg(screen_t *this, int fg)
{
this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg); this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg);
} }
static void setBg(screen_t *this, int bg) {
static void setBg(screen_t *this, int bg)
{
this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg); this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg);
} }
/* private */ /* private */
static int gotoxy(screen_t *this, int x, int y) static int gotoxy(screen_t *this, int x, int y) {
{ if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) {
if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) if (lseek(this->data->fd, 4 + (x + y * this->data->cols) * 2, SEEK_SET) != -1) {
{
if (lseek(this->data->fd, 4 + (x + y * this->data->cols) * 2, SEEK_SET) != -1)
{
return 0; return 0;
} }
} }
return -1; return -1;
} }
static void setCursor(screen_t *this, int x, int y) {
static void setCursor(screen_t *this, int x, int y) if (gotoxy(this, x, y) == 0) {
{
if (gotoxy(this,x,y) == 0)
{
unsigned char b[2] = {x, y}; unsigned char b[2] = {x, y};
if (lseek(this->data->fd, 2, SEEK_SET) != -1) if (lseek(this->data->fd, 2, SEEK_SET) != -1)
write(this->data->fd, b, 2); write(this->data->fd, b, 2);
@@ -197,67 +147,53 @@ static void setCursor(screen_t *this, int x, int y)
} }
} }
static void getCursor(const screen_t *this, int *x, int *y) {
static void getCursor(const screen_t *this, int *x, int *y)
{
int cx = this->data->cursor_x; int cx = this->data->cursor_x;
int cy = this->data->cursor_y; int cy = this->data->cursor_y;
#if 1 #if 1
if (lseek(this->data->fd, 2, SEEK_SET) != -1) if (lseek(this->data->fd, 2, SEEK_SET) != -1) {
{
unsigned char b[2]; unsigned char b[2];
if (read(this->data->fd, b, 2) == 2) if (read(this->data->fd, b, 2) == 2) {
{ if (b[0] < this->data->cols && b[1] < this->data->rows) {
if (b[0] < this->data->cols && b[1] < this->data->rows)
{
cx = b[0]; cx = b[0];
cy = b[1]; cy = b[1];
} }
} }
} }
#endif #endif
if (x) *x = cx; if (x)
if (y) *y = cy; *x = cx;
if (y)
*y = cy;
} }
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) {
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) Cell a = make_cell(this, ch, attr);
{
unsigned short a = make_cell(this,ch,attr);
if (gotoxy(this, x, y) == 0) if (gotoxy(this, x, y) == 0)
write(this->data->fd, &a, 2); write(this->data->fd, &a, 2);
} }
static void putChar(screen_t *this, int ch, int x, int y) {
static void putChar(screen_t *this, int ch, int x, int y)
{
putCharAttr(this, ch, this->data->attr, x, y); putCharAttr(this, ch, this->data->attr, x, y);
} }
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y) {
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
{
assert((int) strlen(s) <= 256); assert((int) strlen(s) <= 256);
assert(x + (int) strlen(s) <= this->data->cols); assert(x + (int) strlen(s) <= this->data->cols);
while (*s) while (*s)
putCharAttr(this, *s++, attr, x++, y); putCharAttr(this, *s++, attr, x++, y);
} }
static void putString(screen_t *this, const char *s, int x, int y) {
static void putString(screen_t *this, const char *s, int x, int y)
{
putStringAttr(this, s, this->data->attr, x, y); putStringAttr(this, s, this->data->attr, x, y);
} }
/* private */ /* private */
static void getChar(screen_t *this, int *ch, int *attr, int x, int y) static void getChar(screen_t *this, int *ch, int *attr, int x, int y) {
{ upx_uint16_t a;
unsigned short a;
if (gotoxy(this,x,y) == 0 && read(this->data->fd, &a, 2) == 2) if (gotoxy(this, x, y) == 0 && read(this->data->fd, &a, 2) == 2) {
{
if (ch) if (ch)
*ch = a & 0xff; *ch = a & 0xff;
if (attr) if (attr)
@@ -265,19 +201,15 @@ static void getChar(screen_t *this, int *ch, int *attr, int x, int y)
} }
} }
/* private */ /* private */
static int init_scrnmap(screen_t *this, int fd) static int init_scrnmap(screen_t *this, int fd) {
{
int scrnmap_done = 0; int scrnmap_done = 0;
int i; int i;
#if 1 && defined(GIO_UNISCRNMAP) && defined(E_TABSZ) #if 1 && defined(GIO_UNISCRNMAP) && defined(E_TABSZ)
if (!scrnmap_done) if (!scrnmap_done) {
{ upx_uint16_t scrnmap[E_TABSZ];
unsigned short scrnmap[E_TABSZ]; if (ioctl(fd, GIO_UNISCRNMAP, scrnmap) == 0) {
if (ioctl(fd, GIO_UNISCRNMAP, scrnmap) == 0)
{
for (i = 0; i < E_TABSZ; i++) for (i = 0; i < E_TABSZ; i++)
this->data->map[scrnmap[i] & 0xff] = i; this->data->map[scrnmap[i] & 0xff] = i;
scrnmap_done = 1; scrnmap_done = 1;
@@ -285,11 +217,9 @@ static int init_scrnmap(screen_t *this, int fd)
} }
#endif #endif
#if 1 && defined(GIO_SCRNMAP) && defined(E_TABSZ) #if 1 && defined(GIO_SCRNMAP) && defined(E_TABSZ)
if (!scrnmap_done) if (!scrnmap_done) {
{
unsigned char scrnmap[E_TABSZ]; unsigned char scrnmap[E_TABSZ];
if (ioctl(fd, GIO_SCRNMAP, scrnmap) == 0) if (ioctl(fd, GIO_SCRNMAP, scrnmap) == 0) {
{
for (i = 0; i < E_TABSZ; i++) for (i = 0; i < E_TABSZ; i++)
this->data->map[scrnmap[i] & 0xff] = i; this->data->map[scrnmap[i] & 0xff] = i;
scrnmap_done = 1; scrnmap_done = 1;
@@ -300,9 +230,7 @@ static int init_scrnmap(screen_t *this, int fd)
return scrnmap_done; return scrnmap_done;
} }
static int init(screen_t *this, int fd) {
static int init(screen_t *this, int fd)
{
struct stat st; struct stat st;
if (!this || !this->data) if (!this || !this->data)
@@ -323,25 +251,21 @@ static int init(screen_t *this, int fd)
/* check if we are running in a virtual console */ /* check if we are running in a virtual console */
#if defined(MINOR) && defined(MAJOR) && defined(TTY_MAJOR) #if defined(MINOR) && defined(MAJOR) && defined(TTY_MAJOR)
if (MAJOR(st.st_rdev) == TTY_MAJOR) if (MAJOR(st.st_rdev) == TTY_MAJOR) {
{
char vc_name[64]; char vc_name[64];
unsigned char vc_data[4]; unsigned char vc_data[4];
int i; int i;
int attr; int attr;
unsigned short a; Cell a;
upx_snprintf(vc_name, sizeof(vc_name), "/dev/vcsa%d", (int) MINOR(st.st_rdev)); upx_safe_snprintf(vc_name, sizeof(vc_name), "/dev/vcsa%d", (int) MINOR(st.st_rdev));
this->data->fd = open(vc_name, O_RDWR); this->data->fd = open(vc_name, O_RDWR);
if (this->data->fd == -1) if (this->data->fd == -1) {
{ upx_safe_snprintf(vc_name, sizeof(vc_name), "/dev/vcc/a%d", (int) MINOR(st.st_rdev));
upx_snprintf(vc_name, sizeof(vc_name), "/dev/vcc/a%d", (int) MINOR(st.st_rdev));
this->data->fd = open(vc_name, O_RDWR); this->data->fd = open(vc_name, O_RDWR);
} }
if (this->data->fd != -1) if (this->data->fd != -1) {
{ if (read(this->data->fd, vc_data, 4) == 4) {
if (read(this->data->fd, vc_data, 4) == 4)
{
this->data->mode = 3; this->data->mode = 3;
this->data->rows = vc_data[0]; this->data->rows = vc_data[0];
this->data->cols = vc_data[1]; this->data->cols = vc_data[1];
@@ -350,18 +274,15 @@ static int init(screen_t *this, int fd)
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
this->data->map[i] = i; this->data->map[i] = i;
i = init_scrnmap(this,this->data->fd) || i = init_scrnmap(this, this->data->fd) || init_scrnmap(this, STDIN_FILENO);
init_scrnmap(this,STDIN_FILENO);
getChar(this,NULL,&attr,this->data->cursor_x,this->data->cursor_y); getChar(this, nullptr, &attr, this->data->cursor_x, this->data->cursor_y);
this->data->init_attr = attr; this->data->init_attr = attr;
this->data->attr = attr; this->data->attr = attr;
a = make_cell(this, ' ', attr); a = make_cell(this, ' ', attr);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
this->data->empty_line[i] = a; this->data->empty_line[i] = a;
} } else {
else
{
close(this->data->fd); close(this->data->fd);
this->data->fd = -1; this->data->fd = -1;
} }
@@ -375,25 +296,19 @@ static int init(screen_t *this, int fd)
return 0; return 0;
} }
static void finalize(screen_t *this) {
static void finalize(screen_t *this)
{
if (this->data->fd != -1) if (this->data->fd != -1)
(void) close(this->data->fd); (void) close(this->data->fd);
} }
static void updateLineN(screen_t *this, const void *line, int y, int len) {
static void updateLineN(screen_t *this, const void *line, int y, int len) if (len > 0 && len <= 2 * this->data->cols && gotoxy(this, 0, y) == 0) {
{
if (len > 0 && len <= 2*this->data->cols && gotoxy(this,0,y) == 0)
{
int i; int i;
unsigned char new_line[len]; unsigned char new_line[len];
unsigned char *l1 = new_line; unsigned char *l1 = new_line;
const unsigned char *l2 = (const unsigned char *) line; const unsigned char *l2 = (const unsigned char *) line;
for (i = 0; i < len; i += 2) for (i = 0; i < len; i += 2) {
{
*l1++ = *l2++; *l1++ = *l2++;
*l1++ = this->data->map[*l2++]; *l1++ = this->data->map[*l2++];
} }
@@ -401,25 +316,19 @@ static void updateLineN(screen_t *this, const void *line, int y, int len)
} }
} }
static void clearLine(screen_t *this, int y) {
static void clearLine(screen_t *this, int y)
{
if (gotoxy(this, 0, y) == 0) if (gotoxy(this, 0, y) == 0)
write(this->data->fd, this->data->empty_line, 2 * this->data->cols); write(this->data->fd, this->data->empty_line, 2 * this->data->cols);
} }
static void clear(screen_t *this) {
static void clear(screen_t *this)
{
int y; int y;
for (y = 0; y < this->data->rows; y++) for (y = 0; y < this->data->rows; y++)
clearLine(this, y); clearLine(this, y);
} }
static int scrollUp(screen_t *this, int lines) {
static int scrollUp(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
@@ -429,9 +338,8 @@ static int scrollUp(screen_t *this, int lines)
#if USE_SCROLLBACK #if USE_SCROLLBACK
/* copy to scrollback buffer */ /* copy to scrollback buffer */
for (y = 0; y < lines; y++) for (y = 0; y < lines; y++) {
{ Cell buf[sc];
unsigned short buf[ sc ];
gotoxy(this, 0, y); gotoxy(this, 0, y);
read(this->data->fd, buf, sizeof(buf)); read(this->data->fd, buf, sizeof(buf));
sb_push(this, buf, sizeof(buf)); sb_push(this, buf, sizeof(buf));
@@ -439,9 +347,8 @@ static int scrollUp(screen_t *this, int lines)
#endif #endif
/* move screen up */ /* move screen up */
if (lines < sr) if (lines < sr) {
{ Cell buf[(sr - lines) * sc];
unsigned short buf[ (sr-lines)*sc ];
gotoxy(this, 0, lines); gotoxy(this, 0, lines);
read(this->data->fd, buf, sizeof(buf)); read(this->data->fd, buf, sizeof(buf));
gotoxy(this, 0, 0); gotoxy(this, 0, 0);
@@ -456,9 +363,7 @@ static int scrollUp(screen_t *this, int lines)
return lines; return lines;
} }
static int scrollDown(screen_t *this, int lines) {
static int scrollDown(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
@@ -467,9 +372,8 @@ static int scrollDown(screen_t *this, int lines)
return 0; return 0;
/* move screen down */ /* move screen down */
if (lines < sr) if (lines < sr) {
{ Cell buf[(sr - lines) * sc];
unsigned short buf[ (sr-lines)*sc ];
gotoxy(this, 0, 0); gotoxy(this, 0, 0);
read(this->data->fd, buf, sizeof(buf)); read(this->data->fd, buf, sizeof(buf));
gotoxy(this, 0, lines); gotoxy(this, 0, lines);
@@ -477,11 +381,10 @@ static int scrollDown(screen_t *this, int lines)
} }
/* copy top lines from scrollback buffer */ /* copy top lines from scrollback buffer */
for (y = lines; --y >= 0; ) for (y = lines; --y >= 0;) {
{
#if USE_SCROLLBACK #if USE_SCROLLBACK
const unsigned short *buf = sb_pop(this); const Cell *buf = sb_pop(this);
if (buf == NULL) if (buf == nullptr)
clearLine(this, y); clearLine(this, y);
else else
updateLineN(this, buf, y, sc * 2); updateLineN(this, buf, y, sc * 2);
@@ -494,31 +397,21 @@ static int scrollDown(screen_t *this, int lines)
return lines; return lines;
} }
static int getScrollCounter(const screen_t *this) { return this->data->scroll_counter; }
static int getScrollCounter(const screen_t *this) static int getCursorShape(const screen_t *this) {
{
return this->data->scroll_counter;
}
static int getCursorShape(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static void setCursorShape(screen_t *this, int shape) {
static void setCursorShape(screen_t *this, int shape)
{
UNUSED(this); UNUSED(this);
UNUSED(shape); UNUSED(shape);
} }
static int kbhit(screen_t *this) {
static int kbhit(screen_t *this)
{
const int fd = STDIN_FILENO; const int fd = STDIN_FILENO;
const unsigned long usec = 0; const unsigned usec = 0;
struct timeval tv; struct timeval tv;
fd_set fds; fd_set fds;
@@ -527,12 +420,10 @@ static int kbhit(screen_t *this)
FD_SET(fd, &fds); FD_SET(fd, &fds);
tv.tv_sec = usec / 1000000; tv.tv_sec = usec / 1000000;
tv.tv_usec = usec % 1000000; tv.tv_usec = usec % 1000000;
return (select(fd + 1, &fds, NULL, NULL, &tv) > 0); return (select(fd + 1, &fds, nullptr, nullptr, &tv) > 0);
} }
static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
static int intro(screen_t *this, void (*show_frames)(screen_t *) )
{
int shape; int shape;
struct termios term_old, term_new; struct termios term_old, term_new;
int term_r; int term_r;
@@ -541,8 +432,7 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *) )
return 0; return 0;
term_r = tcgetattr(STDIN_FILENO, &term_old); term_r = tcgetattr(STDIN_FILENO, &term_old);
if (term_r == 0) if (term_r == 0) {
{
term_new = term_old; term_new = term_old;
term_new.c_lflag &= ~(ISIG | ICANON | ECHO); term_new.c_lflag &= ~(ISIG | ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &term_new); tcsetattr(STDIN_FILENO, TCSANOW, &term_new);
@@ -563,12 +453,9 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *) )
return 1; return 1;
} }
static const screen_t driver = {sobject_destroy,
static const screen_t driver =
{
sobject_destroy,
finalize, finalize,
0, /* atExit */ nullptr, /* atExit */
init, init,
refresh, refresh,
getMode, getMode,
@@ -584,7 +471,7 @@ static const screen_t driver =
setBg, setBg,
setCursor, setCursor,
setCursorShape, setCursorShape,
0, /* hideCursor */ nullptr, /* hideCursor */
putChar, putChar,
putCharAttr, putCharAttr,
putString, putString,
@@ -597,21 +484,11 @@ static const screen_t driver =
getScrollCounter, getScrollCounter,
kbhit, kbhit,
intro, intro,
(struct screen_data_t *) 0 (struct screen_data_t *) nullptr};
};
/* public constructor */ /* public constructor */
screen_t *screen_vcsa_construct(void) screen_t *screen_vcsa_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
{
return sobject_construct(&driver,sizeof(*driver.data));
}
#endif /* (USE_SCREEN) && (USE_SCREEN_VCSA) */ #endif /* (USE_SCREEN) && (USE_SCREEN_VCSA) */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+67 -187
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,22 +22,20 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "../conf.h"
#include "conf.h"
#if (USE_SCREEN_WIN32) #if (USE_SCREEN_WIN32)
#include "screen.h" #include "screen.h"
#define this local_this #define this self
#define mask_fg 0x0f #define mask_fg 0x0f
#define mask_bg 0xf0 #define mask_bg 0xf0
/************************************************************************* /*************************************************************************
// direct screen access // direct screen access
**************************************************************************/ **************************************************************************/
@@ -56,9 +54,7 @@
#include <conio.h> #include <conio.h>
#endif #endif
struct screen_data_t {
struct screen_data_t
{
HANDLE hi; HANDLE hi;
HANDLE ho; HANDLE ho;
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
@@ -80,90 +76,52 @@ struct screen_data_t
CHAR_INFO empty_line[256]; CHAR_INFO empty_line[256];
}; };
#define P(x) ((SHORT) (x)) #define P(x) ((SHORT) (x))
static const COORD pos00 = {0, 0}; static const COORD pos00 = {0, 0};
static const COORD size11 = {1, 1}; static const COORD size11 = {1, 1};
/* atExit information */ /* atExit information */
static struct static struct {
{
int is_valid; int is_valid;
HANDLE ho; HANDLE ho;
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
} ae; } ae;
static void refresh(screen_t *this) { UNUSED(this); }
static void refresh(screen_t *this) static int getMode(const screen_t *this) { return this->data->mode; }
{
UNUSED(this);
}
static int getPage(const screen_t *this) {
static int getMode(const screen_t *this)
{
return this->data->mode;
}
static int getPage(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static int getRows(const screen_t *this) { return this->data->rows; }
static int getRows(const screen_t *this) static int getCols(const screen_t *this) { return this->data->cols; }
{
return this->data->rows;
}
static int isMono(const screen_t *this) {
static int getCols(const screen_t *this)
{
return this->data->cols;
}
static int isMono(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static int getFg(const screen_t *this) { return this->data->attr & mask_fg; }
static int getFg(const screen_t *this) static int getBg(const screen_t *this) { return this->data->attr & mask_bg; }
{
return this->data->attr & mask_fg;
}
static void setFg(screen_t *this, int fg) {
static int getBg(const screen_t *this)
{
return this->data->attr & mask_bg;
}
static void setFg(screen_t *this, int fg)
{
this->data->attr = (WORD) ((this->data->attr & mask_bg) | (fg & mask_fg)); this->data->attr = (WORD) ((this->data->attr & mask_bg) | (fg & mask_fg));
SetConsoleTextAttribute(this->data->ho, this->data->attr); SetConsoleTextAttribute(this->data->ho, this->data->attr);
} }
static void setBg(screen_t *this, int bg) {
static void setBg(screen_t *this, int bg)
{
this->data->attr = (WORD) ((this->data->attr & mask_fg) | (bg & mask_bg)); this->data->attr = (WORD) ((this->data->attr & mask_fg) | (bg & mask_bg));
SetConsoleTextAttribute(this->data->ho, this->data->attr); SetConsoleTextAttribute(this->data->ho, this->data->attr);
} }
static void setCursor(screen_t *this, int x, int y) {
static void setCursor(screen_t *this, int x, int y) if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) {
{
if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows)
{
COORD coord = {P(x), P(y)}; COORD coord = {P(x), P(y)};
SetConsoleCursorPosition(this->data->ho, coord); SetConsoleCursorPosition(this->data->ho, coord);
this->data->cursor_x = x; this->data->cursor_x = x;
@@ -171,15 +129,12 @@ static void setCursor(screen_t *this, int x, int y)
} }
} }
static void getCursor(const screen_t *this, int *x, int *y) {
static void getCursor(const screen_t *this, int *x, int *y)
{
int cx = this->data->cursor_x; int cx = this->data->cursor_x;
int cy = this->data->cursor_y; int cy = this->data->cursor_y;
#if 1 #if 1
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(this->data->ho, &csbi)) if (GetConsoleScreenBufferInfo(this->data->ho, &csbi)) {
{
cx = csbi.dwCursorPosition.X; cx = csbi.dwCursorPosition.X;
cy = csbi.dwCursorPosition.Y; cy = csbi.dwCursorPosition.Y;
#if 0 #if 0
@@ -188,13 +143,13 @@ static void getCursor(const screen_t *this, int *x, int *y)
#endif #endif
} }
#endif #endif
if (x) *x = cx; if (x)
if (y) *y = cy; *x = cx;
if (y)
*y = cy;
} }
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) {
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y)
{
CHAR_INFO ci; CHAR_INFO ci;
SMALL_RECT region = {P(x), P(y), P(x), P(y)}; SMALL_RECT region = {P(x), P(y), P(x), P(y)};
ci.Char.UnicodeChar = 0; ci.Char.UnicodeChar = 0;
@@ -203,15 +158,11 @@ static void putCharAttr(screen_t *this, int ch, int attr, int x, int y)
WriteConsoleOutputA(this->data->ho, &ci, size11, pos00, &region); WriteConsoleOutputA(this->data->ho, &ci, size11, pos00, &region);
} }
static void putChar(screen_t *this, int ch, int x, int y) {
static void putChar(screen_t *this, int ch, int x, int y)
{
this->putCharAttr(this, ch, this->data->attr, x, y); this->putCharAttr(this, ch, this->data->attr, x, y);
} }
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y) {
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
{
int i; int i;
int l = (int) strlen(s); int l = (int) strlen(s);
if (l <= 0) if (l <= 0)
@@ -221,8 +172,7 @@ static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
CHAR_INFO ci[256]; CHAR_INFO ci[256];
COORD size = {P(l), 1}; COORD size = {P(l), 1};
SMALL_RECT region = {P(x), P(y), P(x + l - 1), P(y)}; SMALL_RECT region = {P(x), P(y), P(x + l - 1), P(y)};
for (i = 0; i < l; i++) for (i = 0; i < l; i++) {
{
ci[i].Char.UnicodeChar = 0; ci[i].Char.UnicodeChar = 0;
ci[i].Char.AsciiChar = *s++; ci[i].Char.AsciiChar = *s++;
ci[i].Attributes = (WORD) attr; ci[i].Attributes = (WORD) attr;
@@ -230,58 +180,45 @@ static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
WriteConsoleOutputA(this->data->ho, &ci[0], size, pos00, &region); WriteConsoleOutputA(this->data->ho, &ci[0], size, pos00, &region);
} }
static void putString(screen_t *this, const char *s, int x, int y) {
static void putString(screen_t *this, const char *s, int x, int y)
{
this->putStringAttr(this, s, this->data->attr, x, y); this->putStringAttr(this, s, this->data->attr, x, y);
} }
/* private */ /* private */
static int cci2shape(const CONSOLE_CURSOR_INFO *cci) static int cci2shape(const CONSOLE_CURSOR_INFO *cci) {
{
int shape = cci->dwSize & 255; int shape = cci->dwSize & 255;
if (!cci->bVisible) if (!cci->bVisible)
shape |= 0x2000; shape |= 0x2000;
return shape; return shape;
} }
static int getCursorShape(const screen_t *this) {
static int getCursorShape(const screen_t *this)
{
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(this->data->ho, &cci); GetConsoleCursorInfo(this->data->ho, &cci);
return cci2shape(&cci); return cci2shape(&cci);
} }
static void setCursorShape(screen_t *this, int shape) {
static void setCursorShape(screen_t *this, int shape)
{
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
cci.dwSize = shape & 255; cci.dwSize = shape & 255;
cci.bVisible = (shape & 0x2000) ? 0 : 1; cci.bVisible = (shape & 0x2000) ? 0 : 1;
SetConsoleCursorInfo(this->data->ho, &cci); SetConsoleCursorInfo(this->data->ho, &cci);
} }
static int hideCursor(screen_t *this) {
static int hideCursor(screen_t *this)
{
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
int shape; int shape;
GetConsoleCursorInfo(this->data->ho, &cci); GetConsoleCursorInfo(this->data->ho, &cci);
shape = cci2shape(&cci); shape = cci2shape(&cci);
if (cci.bVisible) if (cci.bVisible) {
{
cci.bVisible = 0; cci.bVisible = 0;
SetConsoleCursorInfo(this->data->ho, &cci); SetConsoleCursorInfo(this->data->ho, &cci);
} }
return shape; return shape;
} }
static int init(screen_t *this, int fd) {
static int init(screen_t *this, int fd)
{
HANDLE hi, ho; HANDLE hi, ho;
CONSOLE_SCREEN_BUFFER_INFO *csbi; CONSOLE_SCREEN_BUFFER_INFO *csbi;
DWORD mode; DWORD mode;
@@ -350,11 +287,8 @@ static int init(screen_t *this, int fd)
return 0; return 0;
} }
static void updateLineN(screen_t *this, const void *line, int y, int len) {
static void updateLineN(screen_t *this, const void *line, int y, int len) if (y >= 0 && y < this->data->rows && len > 0 && len <= 2 * this->data->cols) {
{
if (y >= 0 && y < this->data->rows && len > 0 && len <= 2*this->data->cols)
{
#if 0 #if 0
const char *s = (const char *) line; const char *s = (const char *) line;
int l = len / 2; int l = len / 2;
@@ -376,33 +310,25 @@ static void updateLineN(screen_t *this, const void *line, int y, int len)
} }
} }
static void clearLine(screen_t *this, int y) {
static void clearLine(screen_t *this, int y) if (y >= 0 && y < this->data->rows) {
{
if (y >= 0 && y < this->data->rows)
{
COORD size = {P(this->data->cols), 1}; COORD size = {P(this->data->cols), 1};
SMALL_RECT region = {0, P(y), P(this->data->cols - 1), P(y)}; SMALL_RECT region = {0, P(y), P(this->data->cols - 1), P(y)};
WriteConsoleOutputA(this->data->ho, this->data->empty_line, size, pos00, &region); WriteConsoleOutputA(this->data->ho, this->data->empty_line, size, pos00, &region);
} }
} }
static void clear(screen_t *this) {
static void clear(screen_t *this)
{
int y; int y;
for (y = 0; y < this->data->rows; y++) for (y = 0; y < this->data->rows; y++)
this->clearLine(this, y); this->clearLine(this, y);
} }
/* private */ /* private */
static int do_scroll(screen_t *this, int lines, int way) static int do_scroll(screen_t *this, int lines, int way) {
{
if (lines <= 0 || lines > this->data->rows) if (lines <= 0 || lines > this->data->rows)
return 0; return 0;
if (lines == this->data->rows) if (lines == this->data->rows) {
{
this->clear(this); this->clear(this);
return lines; return lines;
} }
@@ -410,8 +336,7 @@ static int do_scroll(screen_t *this, int lines, int way)
SMALL_RECT rect = {0, 0, P(this->data->cols - 1), P(this->data->rows - 1)}; SMALL_RECT rect = {0, 0, P(this->data->cols - 1), P(this->data->rows - 1)};
// SMALL_RECT clip = rect; // SMALL_RECT clip = rect;
COORD dest = {0, 0}; COORD dest = {0, 0};
switch (way) switch (way) {
{
case 0: case 0:
rect.Top = P(rect.Top + lines); rect.Top = P(rect.Top + lines);
break; break;
@@ -421,33 +346,26 @@ static int do_scroll(screen_t *this, int lines, int way)
break; break;
} }
// ScrollConsoleScreenBuffer(this->data->ho, &rect, &clip, dest, &this->data->empty_cell); // ScrollConsoleScreenBuffer(this->data->ho, &rect, &clip, dest, &this->data->empty_cell);
ScrollConsoleScreenBuffer(this->data->ho, &rect, NULL, dest, &this->data->empty_cell); ScrollConsoleScreenBuffer(this->data->ho, &rect, nullptr, dest, &this->data->empty_cell);
return lines; return lines;
} }
static int scrollUp(screen_t *this, int lines) static int scrollUp(screen_t *this, int lines) {
{
lines = do_scroll(this, lines, 0); lines = do_scroll(this, lines, 0);
this->data->scroll_counter += lines; this->data->scroll_counter += lines;
return lines; return lines;
} }
static int scrollDown(screen_t *this, int lines) static int scrollDown(screen_t *this, int lines) {
{
lines = do_scroll(this, lines, 1); lines = do_scroll(this, lines, 1);
this->data->scroll_counter -= lines; this->data->scroll_counter -= lines;
return lines; return lines;
} }
static int getScrollCounter(const screen_t *this) static int getScrollCounter(const screen_t *this) { return this->data->scroll_counter; }
{
return this->data->scroll_counter;
}
static int s_kbhit(screen_t *this) {
static int s_kbhit(screen_t *this)
{
UNUSED(this); UNUSED(this);
#if (HAVE_CONIO_H) #if (HAVE_CONIO_H)
#if defined(__RSXNT__) #if defined(__RSXNT__)
@@ -462,74 +380,36 @@ static int s_kbhit(screen_t *this)
#endif #endif
} }
static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
static int intro(screen_t *this, void (*show_frames)(screen_t *) )
{
UNUSED(this); UNUSED(this);
UNUSED(show_frames); UNUSED(show_frames);
return 0; return 0;
} }
static void atExit(void) {
static void atExit(void)
{
static int done = 0; static int done = 0;
if (done) return; if (done)
return;
done = 1; done = 1;
if (ae.is_valid) if (ae.is_valid) {
{
} }
} }
static const screen_t driver = {sobject_destroy, nullptr, /* finalize */
static const screen_t driver = atExit, init, refresh,
{ getMode, getPage, getRows,
sobject_destroy, getCols, isMono, getFg,
0, /* finalize, */ getBg, getCursor, getCursorShape,
atExit, setFg, setBg, setCursor,
init, setCursorShape, hideCursor, putChar,
refresh, putCharAttr, putString, putStringAttr,
getMode, clear, clearLine, updateLineN,
getPage, scrollUp, scrollDown, getScrollCounter,
getRows, s_kbhit, intro, (struct screen_data_t *) nullptr};
getCols,
isMono,
getFg,
getBg,
getCursor,
getCursorShape,
setFg,
setBg,
setCursor,
setCursorShape,
hideCursor,
putChar,
putCharAttr,
putString,
putStringAttr,
clear,
clearLine,
updateLineN,
scrollUp,
scrollDown,
getScrollCounter,
s_kbhit,
intro,
(struct screen_data_t *) 0
};
/* public constructor */ /* public constructor */
screen_t *screen_win32_construct(void) screen_t *screen_win32_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
{
return sobject_construct(&driver,sizeof(*driver.data));
}
#endif /* (USE_SCREEN_WIN32) */ #endif /* (USE_SCREEN_WIN32) */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+8 -55
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,16 +22,15 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#pragma once
#ifndef __UPX_SCREEN_H #ifndef UPX_SCREEN_H__
#define __UPX_SCREEN_H 1 #define UPX_SCREEN_H__ 1
#if (USE_SCREEN) #if (USE_SCREEN)
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -40,8 +39,7 @@ struct screen_data_t;
struct screen_t; struct screen_t;
typedef struct screen_t screen_t; typedef struct screen_t screen_t;
struct screen_t struct screen_t {
{
/* public: */ /* public: */
void (*destroy)(screen_t *s); void (*destroy)(screen_t *s);
void (*finalize)(screen_t *s); void (*finalize)(screen_t *s);
@@ -89,7 +87,6 @@ struct screen_t
struct screen_data_t *data; struct screen_data_t *data;
}; };
screen_t *sobject_construct(const screen_t *c, size_t data_size); screen_t *sobject_construct(const screen_t *c, size_t data_size);
void sobject_destroy(screen_t *); void sobject_destroy(screen_t *);
screen_t *sobject_get_screen(void); screen_t *sobject_get_screen(void);
@@ -101,52 +98,8 @@ screen_t *screen_win32_construct(void);
void screen_show_frames(screen_t *); void screen_show_frames(screen_t *);
/*************************************************************************
// debugging support
**************************************************************************/
#if 0
#undef LOG
#undef LOGI
#undef LOGU
#undef LOGS
#if (SCREEN_DEBUG)
static void LOG(const char *format, ...)
{
static FILE *logfile = NULL;
va_list args;
if (!logfile)
logfile = fopen("screen.log", "wt");
if (!logfile)
return;
va_start(args,format);
vfprintf(logfile,format,args);
fflush(logfile);
va_end(args);
}
# define LOGI(x) LOG(#x " %ld\n", (long)(x))
# define LOGU(x) LOG(#x " %lu\n", (long)(x))
# define LOGS(x) LOG(#x " %s\n", x)
#else
# define LOGI(x) /*empty*/
# define LOGU(x) /*empty*/
# define LOGS(x) /*empty*/
#endif
#endif /* if #0 */
#endif /* USE_SCREEN */ #endif /* USE_SCREEN */
#endif /* already included */ #endif /* already included */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+40 -90
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,60 +22,55 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "conf.h"
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
long Throwable::counter = 0; unsigned long Throwable::counter = 0;
Throwable::Throwable(const char *m, int e, bool w) NOTHROW Throwable::Throwable(const char *m, int e, bool w) noexcept : super(),
: super(), msg(NULL), err(e), is_warning(w) msg(nullptr),
{ err(e),
is_warning(w) {
if (m) if (m)
msg = strdup(m); msg = strdup(m);
#if 0 #if 0
fprintf(stderr, "construct exception: %s %ld\n", msg, counter); fprintf(stderr, "construct exception: %s %lu\n", msg, counter);
counter++; counter++;
#endif #endif
} }
Throwable::Throwable(const Throwable &other) noexcept : super(other),
Throwable::Throwable(const Throwable &other) NOTHROW msg(nullptr),
: super(other), msg(NULL), err(other.err), is_warning(other.is_warning) err(other.err),
{ is_warning(other.is_warning) {
if (other.msg) if (other.msg)
msg = strdup(other.msg); msg = strdup(other.msg);
#if 0 #if 0
fprintf(stderr, "copy exception: %s %ld\n", msg, counter); fprintf(stderr, "copy exception: %s %lu\n", msg, counter);
counter++; counter++;
#endif #endif
} }
Throwable::~Throwable() noexcept {
Throwable::~Throwable() NOTHROW
{
#if 0 #if 0
counter--; counter--;
fprintf(stderr, "destruct exception: %s %ld\n", msg, counter); fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
#endif #endif
if (msg) if (msg)
free(msg); free(msg);
} }
/************************************************************************* /*************************************************************************
// compression // compression
**************************************************************************/ **************************************************************************/
void throwCantPack(const char *msg) void throwCantPack(const char *msg) {
{
// UGLY, but makes things easier // UGLY, but makes things easier
if (opt->cmd == CMD_COMPRESS) if (opt->cmd == CMD_COMPRESS)
throw CantPackException(msg); throw CantPackException(msg);
@@ -85,114 +80,73 @@ void throwCantPack(const char *msg)
throw CantUnpackException(msg); throw CantUnpackException(msg);
} }
void throwCantPackExact() void throwCantPackExact() { throwCantPack("option '--exact' does not work with this file"); }
{
throwCantPack("option '--exact' does not work with this file");
}
void throwFilterException() void throwFilterException() { throwCantPack("filter problem"); }
{
throwCantPack("filter problem");
}
void throwUnknownExecutableFormat(const char *msg, bool warn) void throwUnknownExecutableFormat(const char *msg, bool warn) {
{
throw UnknownExecutableFormatException(msg, warn); throw UnknownExecutableFormatException(msg, warn);
} }
void throwNotCompressible(const char *msg) void throwNotCompressible(const char *msg) { throw NotCompressibleException(msg); }
{
throw NotCompressibleException(msg);
}
void throwAlreadyPacked(const char *msg) void throwAlreadyPacked(const char *msg) { throw AlreadyPackedException(msg); }
{
throw AlreadyPackedException(msg);
}
void throwAlreadyPackedByUPX(const char *msg) void throwAlreadyPackedByUPX(const char *msg) {
{ if (msg == nullptr)
if (msg == NULL)
msg = "already packed by UPX"; msg = "already packed by UPX";
throwAlreadyPacked(msg); throwAlreadyPacked(msg);
} }
/************************************************************************* /*************************************************************************
// decompression // decompression
**************************************************************************/ **************************************************************************/
void throwCantUnpack(const char *msg) void throwCantUnpack(const char *msg) {
{
// UGLY, but makes things easier // UGLY, but makes things easier
throwCantPack(msg); throwCantPack(msg);
} }
void throwNotPacked(const char *msg) void throwNotPacked(const char *msg) {
{ if (msg == nullptr)
if (msg == NULL)
msg = "not packed by UPX"; msg = "not packed by UPX";
throw NotPackedException(msg); throw NotPackedException(msg);
} }
void throwChecksumError() void throwChecksumError() { throw Exception("checksum error"); }
{
throw Exception("checksum error");
}
void throwCompressedDataViolation()
{
throw Exception("compressed data violation");
}
void throwCompressedDataViolation() { throw Exception("compressed data violation"); }
/************************************************************************* /*************************************************************************
// other // other
**************************************************************************/ **************************************************************************/
void throwInternalError(const char *msg) void throwInternalError(const char *msg) { throw InternalError(msg); }
{
throw InternalError(msg);
}
void throwBadLoader() void throwBadLoader() { throwInternalError("bad loader"); }
{
throwInternalError("bad loader");
}
void throwOutOfMemoryException(const char *msg) {
void throwOutOfMemoryException(const char *msg) if (msg == nullptr)
{
if (msg == NULL)
msg = "out of memory"; msg = "out of memory";
throw OutOfMemoryException(msg); throw OutOfMemoryException(msg);
} }
void throwIOException(const char *msg, int e) { throw IOException(msg, e); }
void throwIOException(const char *msg, int e) void throwEOFException(const char *msg, int e) {
{ if (msg == nullptr && e == 0)
throw IOException(msg, e);
}
void throwEOFException(const char *msg, int e)
{
if (msg == NULL && e == 0)
msg = "premature end of file"; msg = "premature end of file";
throw EOFException(msg, e); throw EOFException(msg, e);
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
const char *prettyName(const char *n) NOTHROW const char *prettyName(const char *n) noexcept {
{ if (n == nullptr)
if (n == NULL)
return "(null)"; return "(null)";
while (*n) while (*n) {
{
if (*n >= '0' && *n <= '9') // Linux ABI if (*n >= '0' && *n <= '9') // Linux ABI
n++; n++;
else if (*n == ' ') else if (*n == ' ')
@@ -205,8 +159,4 @@ const char *prettyName(const char *n) NOTHROW
return n; return n;
} }
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+97 -111
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,217 +22,203 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#pragma once
#ifndef __UPX_EXCEPT_H #ifndef UPX_EXCEPT_H__
#define __UPX_EXCEPT_H 1 #define UPX_EXCEPT_H__ 1
#ifdef __cplusplus #ifdef __cplusplus
const char *prettyName(const char *n) NOTHROW; const char *prettyName(const char *n) noexcept;
/************************************************************************* /*************************************************************************
// exceptions // exceptions
**************************************************************************/ **************************************************************************/
class Throwable : public std::exception class Throwable : public std::exception {
{
typedef std::exception super; typedef std::exception super;
protected: protected:
Throwable(const char *m = 0, int e = 0, bool w = false) NOTHROW; Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
public: public:
Throwable(const Throwable &) NOTHROW; Throwable(const Throwable &) noexcept;
virtual ~Throwable() NOTHROW; virtual ~Throwable() noexcept;
const char *getMsg() const NOTHROW { return msg; } const char *getMsg() const noexcept { return msg; }
int getErrno() const NOTHROW { return err; } int getErrno() const noexcept { return err; }
bool isWarning() const NOTHROW { return is_warning; } bool isWarning() const noexcept { return is_warning; }
private: private:
char *msg; char *msg = nullptr;
int err; int err = 0;
protected: protected:
bool is_warning; // can be set by subclasses bool is_warning = false; // can be set by subclasses
private: private:
// disable assignment // disable assignment
Throwable& operator= (const Throwable &); Throwable &operator=(const Throwable &) = delete;
// disable dynamic allocation // disable dynamic allocation => force throwing by value
DISABLE_NEW_DELETE ACC_CXX_DISABLE_NEW_DELETE
private: private:
static long counter; // for debugging static unsigned long counter; // for debugging
}; };
// Exceptions can/should be caught // Exceptions can/should be caught
class Exception : public Throwable class Exception : public Throwable {
{
typedef Throwable super; typedef Throwable super;
public:
Exception(const char *m = 0, int e = 0, bool w = false) NOTHROW : super(m,e,w) { }
};
public:
Exception(const char *m = nullptr, int e = 0, bool w = false) noexcept : super(m, e, w) {}
};
// Errors should not be caught (or re-thrown) // Errors should not be caught (or re-thrown)
class Error : public Throwable class Error : public Throwable {
{
typedef Throwable super; typedef Throwable super;
public:
Error(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
public:
Error(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
/************************************************************************* /*************************************************************************
// system exception // system exception
**************************************************************************/ **************************************************************************/
class OutOfMemoryException : public Exception class OutOfMemoryException : public Exception {
{
typedef Exception super; typedef Exception super;
public: public:
OutOfMemoryException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { } OutOfMemoryException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
}; };
class IOException : public Exception {
class IOException : public Exception
{
typedef Exception super; typedef Exception super;
public: public:
IOException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { } IOException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
}; };
class EOFException : public IOException {
class EOFException : public IOException
{
typedef IOException super; typedef IOException super;
public: public:
EOFException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { } EOFException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
}; };
class FileNotFoundException : public IOException {
class FileNotFoundException : public IOException
{
typedef IOException super; typedef IOException super;
public: public:
FileNotFoundException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { } FileNotFoundException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
}; };
class FileAlreadyExistsException : public IOException {
class FileAlreadyExistsException : public IOException
{
typedef IOException super; typedef IOException super;
public:
FileAlreadyExistsException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
public:
FileAlreadyExistsException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
/************************************************************************* /*************************************************************************
// application execptions // application exceptions
**************************************************************************/ **************************************************************************/
class OverlayException : public Exception class OverlayException : public Exception {
{
typedef Exception super; typedef Exception super;
public: public:
OverlayException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { } OverlayException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
}; };
class CantPackException : public Exception class CantPackException : public Exception {
{
typedef Exception super; typedef Exception super;
public: public:
CantPackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { } CantPackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
}; };
class UnknownExecutableFormatException : public CantPackException class UnknownExecutableFormatException : public CantPackException {
{
typedef CantPackException super; typedef CantPackException super;
public: public:
UnknownExecutableFormatException(const char *m = 0, bool w = false) NOTHROW : super(m,w) { } UnknownExecutableFormatException(const char *m = nullptr, bool w = false) noexcept
: super(m, w) {}
}; };
class AlreadyPackedException : public CantPackException class AlreadyPackedException : public CantPackException {
{
typedef CantPackException super; typedef CantPackException super;
public: public:
AlreadyPackedException(const char *m = 0) NOTHROW : super(m) { is_warning = true; } AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
}; };
class NotCompressibleException : public CantPackException class NotCompressibleException : public CantPackException {
{
typedef CantPackException super; typedef CantPackException super;
public: public:
NotCompressibleException(const char *m = 0) NOTHROW : super(m) { } NotCompressibleException(const char *m = nullptr) noexcept : super(m) {}
}; };
class CantUnpackException : public Exception {
class CantUnpackException : public Exception
{
typedef Exception super; typedef Exception super;
public: public:
CantUnpackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { } CantUnpackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
}; };
class NotPackedException : public CantUnpackException class NotPackedException : public CantUnpackException {
{
typedef CantUnpackException super; typedef CantUnpackException super;
public:
NotPackedException(const char *m = 0) NOTHROW : super(m,true) { }
};
public:
NotPackedException(const char *m = nullptr) noexcept : super(m, true) {}
};
/************************************************************************* /*************************************************************************
// errors // errors
**************************************************************************/ **************************************************************************/
class InternalError : public Error class InternalError : public Error {
{
typedef Error super; typedef Error super;
public:
InternalError(const char *m = 0) NOTHROW : super(m,0) { }
};
public:
InternalError(const char *m = nullptr) noexcept : super(m, 0) {}
};
/************************************************************************* /*************************************************************************
// util // util
**************************************************************************/ **************************************************************************/
#undef NORET #undef NORET
#if 0 && defined(__GNUC__) #if 1 && defined(__GNUC__)
// (noreturn) is probably not the correct semantics for throwing exceptions #define NORET __acc_noinline __attribute__((__noreturn__))
#define NORET __attribute__((__noreturn__))
#else #else
#define NORET /*empty*/ #define NORET __acc_noinline
#endif #endif
void throwCantPack(const char *msg) NORET; NORET void throwCantPack(const char *msg);
void throwCantPackExact() NORET; NORET void throwCantPackExact();
void throwUnknownExecutableFormat(const char *msg = NULL, bool warn = false) NORET; NORET void throwUnknownExecutableFormat(const char *msg = nullptr, bool warn = false);
void throwNotCompressible(const char *msg = NULL) NORET; NORET void throwNotCompressible(const char *msg = nullptr);
void throwAlreadyPacked(const char *msg = NULL) NORET; NORET void throwAlreadyPacked(const char *msg = nullptr);
void throwAlreadyPackedByUPX(const char *msg = NULL) NORET; NORET void throwAlreadyPackedByUPX(const char *msg = nullptr);
void throwCantUnpack(const char *msg) NORET; NORET void throwCantUnpack(const char *msg);
void throwNotPacked(const char *msg = NULL) NORET; NORET void throwNotPacked(const char *msg = nullptr);
void throwFilterException() NORET; NORET void throwFilterException();
void throwBadLoader() NORET; NORET void throwBadLoader();
void throwChecksumError() NORET; NORET void throwChecksumError();
void throwCompressedDataViolation() NORET; NORET void throwCompressedDataViolation();
void throwInternalError(const char *msg) NORET; NORET void throwInternalError(const char *msg);
void throwOutOfMemoryException(const char *msg = NULL) NORET; NORET void throwOutOfMemoryException(const char *msg = nullptr);
void throwIOException(const char *msg = NULL, int e = 0) NORET; NORET void throwIOException(const char *msg = nullptr, int e = 0);
void throwEOFException(const char *msg = NULL, int e = 0) NORET; NORET void throwEOFException(const char *msg = nullptr, int e = 0);
#undef NORET #undef NORET
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* already included */ #endif /* already included */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+88 -229
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,33 +22,28 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "conf.h"
#include "file.h" #include "file.h"
#include "mem.h"
/************************************************************************* /*************************************************************************
// // static functions
**************************************************************************/ **************************************************************************/
void File::chmod(const char *name, int mode) void FileBase::chmod(const char *name, int mode) {
{
#if (HAVE_CHMOD) #if (HAVE_CHMOD)
if (::chmod(name, mode) != 0) if (::chmod(name, mode) != 0)
throwIOException(name, errno); throwIOException(name, errno);
#else #else
UNUSED(name); UNUSED(mode); UNUSED(name);
UNUSED(mode);
#endif #endif
} }
void FileBase::rename(const char *old_, const char *new_) {
void File::rename(const char *old_, const char *new_) #if (ACC_OS_DOS32) && defined(__DJGPP__)
{
#if defined(__DJGPP__)
if (::_rename(old_, new_) != 0) if (::_rename(old_, new_) != 0)
#else #else
if (::rename(old_, new_) != 0) if (::rename(old_, new_) != 0)
@@ -56,27 +51,21 @@ void File::rename(const char *old_, const char *new_)
throwIOException("rename error", errno); throwIOException("rename error", errno);
} }
void FileBase::unlink(const char *name) {
void File::unlink(const char *name)
{
if (::unlink(name) != 0) if (::unlink(name) != 0)
throwIOException(name, errno); throwIOException(name, errno);
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
FileBase::FileBase() : FileBase::FileBase()
_fd(-1), _flags(0), _shflags(0), _mode(0), _name(NULL), _offset(0), _length(0) : _fd(-1), _flags(0), _shflags(0), _mode(0), _name(nullptr), _offset(0), _length(0) {
{
memset(&st, 0, sizeof(st)); memset(&st, 0, sizeof(st));
} }
FileBase::~FileBase() {
FileBase::~FileBase()
{
#if 0 && defined(__GNUC__) // debug #if 0 && defined(__GNUC__) // debug
if (isOpen()) if (isOpen())
fprintf(stderr,"%s: %s\n", _name, __PRETTY_FUNCTION__); fprintf(stderr,"%s: %s\n", _name, __PRETTY_FUNCTION__);
@@ -87,14 +76,11 @@ FileBase::~FileBase()
closex(); closex();
} }
bool FileBase::do_sopen() {
bool FileBase::do_sopen()
{
if (_shflags < 0) if (_shflags < 0)
_fd = ::open(_name, _flags, _mode); _fd = ::open(_name, _flags, _mode);
else else {
{ #if (ACC_OS_DOS32) && defined(__DJGPP__)
#if defined(__DJGPP__)
_fd = ::open(_name, _flags | _shflags, _mode); _fd = ::open(_name, _flags | _shflags, _mode);
#elif defined(__MINT__) #elif defined(__MINT__)
_fd = ::open(_name, _flags | (_shflags & O_SHMODE), _mode); _fd = ::open(_name, _flags | (_shflags & O_SHMODE), _mode);
@@ -112,9 +98,7 @@ bool FileBase::do_sopen()
return true; return true;
} }
bool FileBase::close() {
bool FileBase::close()
{
bool ok = true; bool ok = true;
if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO) if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO)
if (::close(_fd) == -1) if (::close(_fd) == -1)
@@ -122,56 +106,22 @@ bool FileBase::close()
_fd = -1; _fd = -1;
_flags = 0; _flags = 0;
_mode = 0; _mode = 0;
_name = NULL; _name = nullptr;
_offset = 0; _offset = 0;
_length = 0; _length = 0;
return ok; return ok;
} }
void FileBase::closex() {
void FileBase::closex()
{
if (!close()) if (!close())
throwIOException("close failed", errno); throwIOException("close failed", errno);
} }
// Return value of ::seek is the resulting file offset (same as ::tell())
int FileBase::read(void *buf, int len) upx_off_t FileBase::seek(upx_off_t off, int whence) {
{
if (!isOpen() || len < 0)
throwIOException("bad read");
errno = 0;
long l = acc_safe_hread(_fd, buf, len);
if (errno)
throwIOException("read error",errno);
return (int) l;
}
int FileBase::readx(void *buf, int len)
{
int l = this->read(buf, len);
if (l != len)
throwEOFException();
return l;
}
void FileBase::write(const void *buf, int len)
{
if (!isOpen() || len < 0)
throwIOException("bad write");
errno = 0;
long l = acc_safe_hwrite(_fd, buf, len);
if (l != len)
throwIOException("write error",errno);
}
void FileBase::seek(off_t off, int whence)
{
if (!isOpen()) if (!isOpen())
throwIOException("bad seek 1"); throwIOException("bad seek 1");
mem_size_assert(1, off >= 0 ? off : -off); // sanity check
if (whence == SEEK_SET) { if (whence == SEEK_SET) {
if (off < 0) if (off < 0)
throwIOException("bad seek 2"); throwIOException("bad seek 2");
@@ -183,50 +133,36 @@ void FileBase::seek(off_t off, int whence)
off += _offset + _length; off += _offset + _length;
whence = SEEK_SET; whence = SEEK_SET;
} }
if (::lseek(_fd,off,whence) < 0) // SEEK_CUR falls through to here
upx_off_t rv = ::lseek(_fd, off, whence);
if (rv < 0)
throwIOException("seek error", errno); throwIOException("seek error", errno);
return rv - _offset;
} }
upx_off_t FileBase::tell() const {
off_t FileBase::tell() const
{
if (!isOpen()) if (!isOpen())
throwIOException("bad tell"); throwIOException("bad tell");
off_t l = ::lseek(_fd, 0, SEEK_CUR); upx_off_t l = ::lseek(_fd, 0, SEEK_CUR);
if (l < 0) if (l < 0)
throwIOException("tell error", errno); throwIOException("tell error", errno);
return l - _offset; return l - _offset;
} }
void FileBase::set_extent(upx_off_t offset, upx_off_t length) {
void FileBase::set_extent(off_t offset, off_t length)
{
_offset = offset; _offset = offset;
_length = length; _length = length;
} }
off_t FileBase::st_size() const upx_off_t FileBase::st_size() const { return _length; }
{
return _length;
}
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
InputFile::InputFile() InputFile::InputFile() {}
{
}
void InputFile::sopen(const char *name, int flags, int shflags) {
InputFile::~InputFile()
{
}
void InputFile::sopen(const char *name, int flags, int shflags)
{
close(); close();
_name = name; _name = name;
_flags = flags; _flags = flags;
@@ -234,8 +170,7 @@ void InputFile::sopen(const char *name, int flags, int shflags)
_mode = 0; _mode = 0;
_offset = 0; _offset = 0;
_length = 0; _length = 0;
if (!FileBase::do_sopen()) if (!super::do_sopen()) {
{
if (errno == ENOENT) if (errno == ENOENT)
throw FileNotFoundException(_name, errno); throw FileNotFoundException(_name, errno);
else if (errno == EEXIST) else if (errno == EEXIST)
@@ -243,75 +178,43 @@ void InputFile::sopen(const char *name, int flags, int shflags)
else else
throwIOException(_name, errno); throwIOException(_name, errno);
} }
_length_orig = _length;
} }
int InputFile::read(SPAN_P(void) buf, int len) {
int InputFile::read(void *buf, int len) if (!isOpen() || len < 0)
{ throwIOException("bad read");
return super::read(buf, len); mem_size_assert(1, len); // sanity check
errno = 0;
long l = acc_safe_hread(_fd, raw_bytes(buf, len), len);
if (errno)
throwIOException("read error", errno);
return (int) l;
} }
int InputFile::readx(void *buf, int len) int InputFile::readx(SPAN_P(void) buf, int len) {
{ int l = this->read(buf, len);
return super::readx(buf, len); if (l != len)
throwEOFException();
return l;
} }
upx_off_t InputFile::seek(upx_off_t off, int whence) {
int InputFile::read(MemBuffer *buf, int len) upx_off_t pos = super::seek(off, whence);
{ if (_length < pos)
buf->checkState(); throwIOException("bad seek 4");
assert((unsigned)len <= buf->getSize()); return pos;
return read(buf->getVoidPtr(), len);
}
int InputFile::readx(MemBuffer *buf, int len)
{
buf->checkState();
assert((unsigned)len <= buf->getSize());
return read(buf->getVoidPtr(), len);
}
int InputFile::read(MemBuffer &buf, int len)
{
return read(&buf, len);
}
int InputFile::readx(MemBuffer &buf, int len)
{
return readx(&buf, len);
}
void InputFile::seek(off_t off, int whence)
{
super::seek(off,whence);
}
off_t InputFile::tell() const
{
return super::tell();
} }
upx_off_t InputFile::st_size_orig() const { return _length_orig; }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
OutputFile::OutputFile() : OutputFile::OutputFile() : bytes_written(0) {}
bytes_written(0)
{
}
void OutputFile::sopen(const char *name, int flags, int shflags, int mode) {
OutputFile::~OutputFile()
{
}
void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
{
close(); close();
_name = name; _name = name;
_flags = flags; _flags = flags;
@@ -319,8 +222,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
_mode = mode; _mode = mode;
_offset = 0; _offset = 0;
_length = 0; _length = 0;
if (!FileBase::do_sopen()) if (!super::do_sopen()) {
{
#if 0 #if 0
// don't throw FileNotFound here -- this is confusing // don't throw FileNotFound here -- this is confusing
if (errno == ENOENT) if (errno == ENOENT)
@@ -334,9 +236,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
} }
} }
bool OutputFile::openStdout(int flags, bool force) {
bool OutputFile::openStdout(int flags, bool force)
{
close(); close();
int fd = STDOUT_FILENO; int fd = STDOUT_FILENO;
if (!force && acc_isatty(fd)) if (!force && acc_isatty(fd))
@@ -353,15 +253,25 @@ bool OutputFile::openStdout(int flags, bool force)
return true; return true;
} }
void OutputFile::write(SPAN_0(const void) buf, int len) {
void OutputFile::write(const void *buf, int len) if (!isOpen() || len < 0)
{ throwIOException("bad write");
super::write(buf, len); // allow nullptr if len == 0
if (len == 0)
return;
mem_size_assert(1, len); // sanity check
errno = 0;
#if 0
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; bytes_written += len;
} }
off_t OutputFile::st_size() const upx_off_t OutputFile::st_size() const {
{
if (opt->to_stdout) { // might be a pipe ==> .st_size is invalid if (opt->to_stdout) { // might be a pipe ==> .st_size is invalid
return bytes_written; // too big if seek()+write() instead of rewrite() return bytes_written; // too big if seek()+write() instead of rewrite()
} }
@@ -372,29 +282,14 @@ off_t OutputFile::st_size() const
return my_st.st_size; return my_st.st_size;
} }
void OutputFile::rewrite(SPAN_P(const void) buf, int len) {
void OutputFile::write(const MemBuffer *buf, int len)
{
buf->checkState();
assert((unsigned)len <= buf->getSize());
write(buf->getVoidPtr(), len);
}
void OutputFile::write(const MemBuffer &buf, int len)
{
write(&buf, len);
}
void OutputFile::rewrite(const void *buf, int len)
{
assert(!opt->to_stdout); assert(!opt->to_stdout);
write(buf, len); write(buf, len);
bytes_written -= len; // restore bytes_written -= len; // restore
} }
void OutputFile::seek(off_t off, int whence) upx_off_t OutputFile::seek(upx_off_t off, int whence) {
{ mem_size_assert(1, off >= 0 ? off : -off); // sanity check
assert(!opt->to_stdout); assert(!opt->to_stdout);
switch (whence) { switch (whence) {
case SEEK_SET: { case SEEK_SET: {
@@ -407,7 +302,7 @@ void OutputFile::seek(off_t off, int whence)
_length = bytes_written; // necessary _length = bytes_written; // necessary
} break; } break;
} }
super::seek(off,whence); return super::seek(off, whence);
} }
// WARNING: fsync() does not exist in some Windows environments. // WARNING: fsync() does not exist in some Windows environments.
@@ -416,25 +311,23 @@ void OutputFile::seek(off_t off, int whence)
//{ //{
// fsync(_fd); // fsync(_fd);
// InputFile infile; // InputFile infile;
// infile.open(this->getName(), O_RDONLY); // infile.open(this->getName(), O_RDONLY | O_BINARY);
// infile.seek(this->tell(), SEEK_SET); // infile.seek(this->tell(), SEEK_SET);
// return infile.read(buf, len); // return infile.read(buf, len);
//} //}
void OutputFile::set_extent(off_t offset, off_t length) void OutputFile::set_extent(upx_off_t offset, upx_off_t length) {
{
super::set_extent(offset, length); super::set_extent(offset, length);
bytes_written = 0; bytes_written = 0;
if (0==offset && (off_t)~0u==length) { if (0 == offset && (upx_off_t) ~0u == length) {
if (::fstat(_fd, &st) != 0) if (::fstat(_fd, &st) != 0)
throwIOException(_name, errno); throwIOException(_name, errno);
_length = st.st_size - offset; _length = st.st_size - offset;
} }
} }
off_t OutputFile::unset_extent() upx_off_t OutputFile::unset_extent() {
{ upx_off_t l = ::lseek(_fd, 0, SEEK_END);
off_t l = ::lseek(_fd, 0, SEEK_END);
if (l < 0) if (l < 0)
throwIOException("lseek error", errno); throwIOException("lseek error", errno);
_offset = 0; _offset = 0;
@@ -443,48 +336,14 @@ off_t OutputFile::unset_extent()
return _length; return _length;
} }
void OutputFile::dump(const char *name, const void *buf, int len, int flags) void OutputFile::dump(const char *name, SPAN_P(const void) buf, int len, int flags) {
{
if (flags < 0) if (flags < 0)
flags = O_CREAT | O_BINARY | O_TRUNC; flags = O_CREAT | O_TRUNC;
flags |= O_WRONLY; flags |= O_WRONLY | O_BINARY;
OutputFile f; OutputFile f;
f.open(name, flags, 0600); f.open(name, flags, 0600);
f.write(buf, len); f.write(raw_bytes(buf, len), len);
f.closex(); f.closex();
} }
/* vim:set ts=4 sw=4 et: */
/*************************************************************************
//
**************************************************************************/
#if 0
MemoryOutputFile::MemoryOutputFile() :
b(NULL), b_size(0), b_pos(0), bytes_written(0)
{
}
void MemoryOutputFile::write(const void *buf, int len)
{
if (!isOpen() || len < 0)
throwIOException("bad write");
if (len == 0)
return;
if (b_pos + len > b_size)
throwIOException("write error",ENOSPC);
memcpy(b + b_pos, buf, len);
b_pos += len;
bytes_written += len;
}
#endif /* if 0 */
/*
vi:ts=4:et
*/
+61 -116
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,168 +22,113 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#pragma once
#ifndef __UPX_FILE_H #ifndef UPX_FILE_H__
#define __UPX_FILE_H 1 #define UPX_FILE_H__ 1
class MemBuffer;
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
class File class FileBase {
{
protected:
File() { }
virtual ~File() { }
public:
static void chmod(const char *name, int mode);
static void rename(const char *old_, const char *new_);
static void unlink(const char *name);
};
class FileBase : public File
{
protected: protected:
FileBase(); FileBase();
virtual ~FileBase(); virtual ~FileBase();
public: public:
virtual bool close(); bool close();
virtual void closex(); void closex();
virtual bool isOpen() const { return _fd >= 0; } bool isOpen() const { return _fd >= 0; }
int getFd() const { return _fd; } int getFd() const { return _fd; }
const char *getName() const { return _name; } const char *getName() const { return _name; }
virtual off_t st_size() const; // { return _length; }
virtual void set_extent(off_t offset, off_t length); virtual upx_off_t seek(upx_off_t off, int whence);
upx_off_t tell() const;
virtual upx_off_t st_size() const; // { return _length; }
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);
protected: protected:
bool do_sopen(); bool do_sopen();
virtual int read(void *buf, int len); int _fd = -1;
virtual int readx(void *buf, int len); int _flags = 0;
virtual void write(const void *buf, int len); int _shflags = 0;
virtual void seek(off_t off, int whence); int _mode = 0;
virtual off_t tell() const; const char *_name = nullptr;
upx_off_t _offset = 0;
upx_off_t _length = 0;
int _fd;
int _flags;
int _shflags;
int _mode;
const char *_name;
off_t _offset;
off_t _length;
public: public:
struct stat st; struct stat st = {};
}; };
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
class InputFile : public FileBase class InputFile final : public FileBase {
{
typedef FileBase super; typedef FileBase super;
public: public:
InputFile(); InputFile();
virtual ~InputFile(); virtual ~InputFile() {}
virtual void sopen(const char *name, int flags, int shflags); void sopen(const char *name, int flags, int shflags);
virtual void open(const char *name, int flags) void open(const char *name, int flags) { sopen(name, flags, -1); }
{
sopen(name, flags, -1);
}
virtual int read(void *buf, int len); int read(SPAN_P(void) buf, int len);
virtual int readx(void *buf, int len); int readx(SPAN_P(void) buf, int len);
virtual int read(MemBuffer *buf, int len);
virtual int readx(MemBuffer *buf, int len);
virtual int read(MemBuffer &buf, int len);
virtual int readx(MemBuffer &buf, int len);
virtual void seek(off_t off, int whence); virtual upx_off_t seek(upx_off_t off, int whence) override;
virtual off_t tell() const; upx_off_t st_size_orig() const;
protected:
upx_off_t _length_orig = 0;
}; };
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
class OutputFile : public FileBase class OutputFile final : public FileBase {
{
typedef FileBase super; typedef FileBase super;
public: public:
OutputFile(); OutputFile();
virtual ~OutputFile(); virtual ~OutputFile() {}
virtual void sopen(const char *name, int flags, int shflags, int mode); void sopen(const char *name, int flags, int shflags, int mode);
virtual void open(const char *name, int flags, int mode) void open(const char *name, int flags, int mode) { sopen(name, flags, -1, mode); }
{ bool openStdout(int flags = 0, bool force = false);
sopen(name, flags, -1, mode);
}
virtual bool openStdout(int flags=0, bool force=false);
virtual void write(const void *buf, int len); // info: allow nullptr if len == 0
virtual void write(const MemBuffer *buf, int len); void write(SPAN_0(const void) buf, int len);
virtual void write(const MemBuffer &buf, int len);
virtual void set_extent(off_t offset, off_t length);
virtual off_t unset_extent(); // returns actual length
off_t getBytesWritten() const { return bytes_written; } virtual upx_off_t seek(upx_off_t off, int whence) override;
virtual off_t st_size() const; // { return _length; } virtual upx_off_t st_size() const override; // { return _length; }
virtual void set_extent(upx_off_t offset, upx_off_t length) override;
upx_off_t unset_extent(); // returns actual length
upx_off_t getBytesWritten() const { return bytes_written; }
// FIXME - these won't work when using the '--stdout' option // FIXME - these won't work when using the '--stdout' option
virtual void seek(off_t off, int whence); void rewrite(SPAN_P(const void) buf, int len);
virtual void rewrite(const void *buf, int len);
// util // util
static void dump(const char *name, const void *buf, int len, int flags=-1); static void dump(const char *name, SPAN_P(const void) buf, int len, int flags = -1);
protected: protected:
off_t bytes_written; upx_off_t bytes_written = 0;
}; };
#endif
/************************************************************************* /* vim:set ts=4 sw=4 et: */
//
**************************************************************************/
#if 0 /* NOT USED */
class MemoryOutputFile : public FileBase
{
typedef FileBase super;
public:
MemoryOutputFile();
virtual ~MemoryOutputFile() { b = NULL; }
virtual bool close() { b = NULL; return true; }
virtual bool isOpen() const { return b != NULL; }
virtual void open(void *buf, unsigned size)
{ b = (upx_bytep) buf; b_size = size; }
virtual void write(const void *buf, int len);
off_t getBytesWritten() const { return bytes_written; }
protected:
upx_bytep b;
unsigned b_size;
unsigned b_pos;
off_t bytes_written;
};
#endif /* if 0 */
#endif /* already included */
/*
vi:ts=4:et
*/
+36 -62
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,45 +22,37 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "conf.h"
#include "filter.h" #include "filter.h"
#include "file.h" #include "file.h"
/************************************************************************* /*************************************************************************
// util // util
**************************************************************************/ **************************************************************************/
static //inline static void initFilter(Filter *f, upx_byte *buf, unsigned buf_len) {
void initFilter(Filter *f, upx_byte *buf, unsigned buf_len)
{
f->buf = buf; f->buf = buf;
f->buf_len = buf_len; f->buf_len = buf_len;
// clear output parameters // clear output parameters
f->calls = f->wrongcalls = f->noncalls = f->firstcall = f->lastcall = 0; f->calls = f->wrongcalls = f->noncalls = f->firstcall = f->lastcall = 0;
} }
/************************************************************************* /*************************************************************************
// get a FilterEntry // get a FilterEntry
**************************************************************************/ **************************************************************************/
const FilterImp::FilterEntry *FilterImp::getFilter(int id) const FilterImpl::FilterEntry *FilterImpl::getFilter(int id) {
{
static bool done = false; static bool done = false;
static unsigned char filter_map[256]; static unsigned char filter_map[256];
if (!done) if (!done) {
{
// init the filter_map[] // init the filter_map[]
assert(n_filters <= 254); // as 0xff means "empty slot" assert(n_filters <= 254); // as 0xff means "empty slot"
memset(filter_map, 0xff, sizeof(filter_map)); memset(filter_map, 0xff, sizeof(filter_map));
for (int i = 0; i < n_filters; i++) for (int i = 0; i < n_filters; i++) {
{
int filter_id = filters[i].id; int filter_id = filters[i].id;
assert(filter_id >= 0 && filter_id <= 255); assert(filter_id >= 0 && filter_id <= 255);
assert(filter_map[filter_id] == 0xff); assert(filter_map[filter_id] == 0xff);
@@ -70,28 +62,25 @@ const FilterImp::FilterEntry *FilterImp::getFilter(int id)
} }
if (id < 0 || id > 255) if (id < 0 || id > 255)
return NULL; return nullptr;
unsigned index = filter_map[id]; unsigned index = filter_map[id];
if (index == 0xff) // empty slot if (index == 0xff) // empty slot
return NULL; return nullptr;
assert(filters[index].id == id); assert(filters[index].id == id);
return &filters[index]; return &filters[index];
} }
bool Filter::isValidFilter(int filter_id) {
bool Filter::isValidFilter(int filter_id) const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(filter_id);
{ return fe != nullptr;
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(filter_id);
return fe != NULL;
} }
bool Filter::isValidFilter(int filter_id, const int *allowed_filters) bool Filter::isValidFilter(int filter_id, const int *allowed_filters) {
{
if (!isValidFilter(filter_id)) if (!isValidFilter(filter_id))
return false; return false;
if (filter_id == 0) if (filter_id == 0)
return true; return true;
if (allowed_filters == NULL) if (allowed_filters == nullptr)
return false; return false;
while (*allowed_filters != FT_END) while (*allowed_filters != FT_END)
if (*allowed_filters++ == filter_id) if (*allowed_filters++ == filter_id)
@@ -99,30 +88,26 @@ bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
return false; return false;
} }
/************************************************************************* /*************************************************************************
// high level API // high level API
**************************************************************************/ **************************************************************************/
void Filter::init(int id_, unsigned addvalue_) void Filter::init(int id_, unsigned addvalue_) {
{
this->id = id_; this->id = id_;
initFilter(this, NULL, 0); initFilter(this, nullptr, 0);
// clear input parameters // clear input parameters
this->addvalue = addvalue_; this->addvalue = addvalue_;
this->preferred_ctos = NULL; this->preferred_ctos = nullptr;
// clear input/output parameters // clear input/output parameters
this->cto = 0; this->cto = 0;
this->n_mru = 0; this->n_mru = 0;
} }
bool Filter::filter(upx_byte *buf_, unsigned buf_len_) {
bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
{
initFilter(this, buf_, buf_len_); initFilter(this, buf_, buf_len_);
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id); const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
if (fe == NULL) if (fe == nullptr)
throwInternalError("filter-1"); throwInternalError("filter-1");
if (fe->id == 0) if (fe->id == 0)
return true; return true;
@@ -138,10 +123,10 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
if (clevel != 1) if (clevel != 1)
this->adler = upx_adler32(this->buf, this->buf_len); this->adler = upx_adler32(this->buf, this->buf_len);
//printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len); NO_printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
// OutputFile::dump("filter.dat", buf, buf_len); // OutputFile::dump("filter.dat", buf, buf_len);
int r = (*fe->do_filter)(this); int r = (*fe->do_filter)(this);
//printf("filter: %02x %d\n", fe->id, r); NO_printf("filter: %02x %d\n", fe->id, r);
if (r > 0) if (r > 0)
throwFilterException(); throwFilterException();
if (r == 0) if (r == 0)
@@ -149,13 +134,11 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
return false; return false;
} }
void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum) {
void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
{
initFilter(this, buf_, buf_len_); initFilter(this, buf_, buf_len_);
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id); const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
if (fe == NULL) if (fe == nullptr)
throwInternalError("unfilter-1"); throwInternalError("unfilter-1");
if (fe->id == 0) if (fe->id == 0)
return; return;
@@ -166,24 +149,21 @@ void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
if (!fe->do_unfilter) if (!fe->do_unfilter)
throwInternalError("unfilter-2"); throwInternalError("unfilter-2");
//printf("unfilter: %02x %p %d\n", this->id, this->buf, this->buf_len); NO_printf("unfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
int r = (*fe->do_unfilter)(this); int r = (*fe->do_unfilter)(this);
//printf("unfilter: %02x %d\n", fe->id, r); NO_printf("unfilter: %02x %d\n", fe->id, r);
if (r != 0) if (r != 0)
throwInternalError("unfilter-3"); throwInternalError("unfilter-3");
// OutputFile::dump("unfilter.dat", buf, buf_len); // OutputFile::dump("unfilter.dat", buf, buf_len);
// verify checksum // verify checksum
if (verify_checksum && clevel != 1) if (verify_checksum && clevel != 1) {
{
if (this->adler != upx_adler32(this->buf, this->buf_len)) if (this->adler != upx_adler32(this->buf, this->buf_len))
throwInternalError("unfilter-4"); throwInternalError("unfilter-4");
} }
} }
void Filter::verifyUnfilter() {
void Filter::verifyUnfilter()
{
// Note: // Note:
// This verify is just because of complete paranoia that there // This verify is just because of complete paranoia that there
// could be a hidden bug in the filter implementation, and // could be a hidden bug in the filter implementation, and
@@ -193,21 +173,19 @@ void Filter::verifyUnfilter()
// See also: // See also:
// Packer::verifyOverlappingDecompression() // Packer::verifyOverlappingDecompression()
//printf("verifyUnfilter: %02x %p %d\n", this->id, this->buf, this->buf_len); NO_printf("verifyUnfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
if (clevel != 1) if (clevel != 1)
unfilter(this->buf, this->buf_len, true); unfilter(this->buf, this->buf_len, true);
} }
bool Filter::scan(const upx_byte *buf_, unsigned buf_len_) {
bool Filter::scan(const upx_byte *buf_, unsigned buf_len_)
{
// Note: must use const_cast here. This is fine as the scan // Note: must use const_cast here. This is fine as the scan
// implementations (fe->do_scan) actually don't change the buffer. // implementations (fe->do_scan) actually don't change the buffer.
upx_byte *b = const_cast<upx_byte *>(buf_); upx_byte *b = const_cast<upx_byte *>(buf_);
initFilter(this, b, buf_len_); initFilter(this, b, buf_len_);
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id); const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
if (fe == NULL) if (fe == nullptr)
throwInternalError("scan-1"); throwInternalError("scan-1");
if (fe->id == 0) if (fe->id == 0)
return true; return true;
@@ -218,9 +196,9 @@ bool Filter::scan(const upx_byte *buf_, unsigned buf_len_)
if (!fe->do_scan) if (!fe->do_scan)
throwInternalError("scan-2"); throwInternalError("scan-2");
//printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len); NO_printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
int r = (*fe->do_scan)(this); int r = (*fe->do_scan)(this);
//printf("filter: %02x %d\n", fe->id, r); NO_printf("filter: %02x %d\n", fe->id, r);
if (r > 0) if (r > 0)
throwFilterException(); throwFilterException();
if (r == 0) if (r == 0)
@@ -228,8 +206,4 @@ bool Filter::scan(const upx_byte *buf_, unsigned buf_len_)
return false; return false;
} }
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+17 -27
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,16 +22,12 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#pragma once
#ifndef __UPX_FILTER_H #ifndef UPX_FILTER_H__
#define __UPX_FILTER_H 1 #define UPX_FILTER_H__ 1
class Filter;
class FilterImp;
/************************************************************************* /*************************************************************************
// A filter is a reversible operation that modifies a given // A filter is a reversible operation that modifies a given
@@ -50,10 +46,12 @@ class FilterImp;
// to absolute addresses so that the buffer compresses better. // to absolute addresses so that the buffer compresses better.
**************************************************************************/ **************************************************************************/
class Filter class Filter {
{
public: public:
Filter(int level) { clevel = level; init(); } Filter(int level) {
clevel = level;
init();
}
void init(int id = 0, unsigned addvalue = 0); void init(int id = 0, unsigned addvalue = 0);
bool filter(upx_byte *buf, unsigned buf_len); bool filter(upx_byte *buf, unsigned buf_len);
@@ -67,8 +65,8 @@ public:
public: public:
// Will be set by each call to filter()/unfilter(). // Will be set by each call to filter()/unfilter().
// Read-only afterwards. // Read-only afterwards.
upx_byte *buf; upx_byte *buf = nullptr;
unsigned buf_len; unsigned buf_len = 0;
// Checksum of the buffer before applying the filter // Checksum of the buffer before applying the filter
// or after un-applying the filter. // or after un-applying the filter.
@@ -76,7 +74,7 @@ public:
// Input parameters used by various filters. // Input parameters used by various filters.
unsigned addvalue; unsigned addvalue;
const int *preferred_ctos; const int *preferred_ctos = nullptr;
// Input/output parameters used by various filters // Input/output parameters used by various filters
unsigned char cto; // call trick offset unsigned char cto; // call trick offset
@@ -96,7 +94,6 @@ private:
int clevel; // compression level int clevel; // compression level
}; };
/************************************************************************* /*************************************************************************
// We don't want a full OO interface here because of // We don't want a full OO interface here because of
// certain implementation speed reasons. // certain implementation speed reasons.
@@ -104,13 +101,11 @@ private:
// This class is private to Filter - don't look. // This class is private to Filter - don't look.
**************************************************************************/ **************************************************************************/
class FilterImp class FilterImpl {
{
friend class Filter; friend class Filter;
private: private:
struct FilterEntry struct FilterEntry {
{
int id; // 0 .. 255 int id; // 0 .. 255
unsigned min_buf_len; unsigned min_buf_len;
unsigned max_buf_len; unsigned max_buf_len;
@@ -128,11 +123,6 @@ private:
static const int n_filters; // number of filters[] static const int n_filters; // number of filters[]
}; };
#endif /* already included */ #endif /* already included */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+44 -6
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -459,7 +459,45 @@ static int s_ct24arm_be(Filter *f)
#undef CT24ARM_BE #undef CT24ARM_BE
#undef ARMCT_COND #undef ARMCT_COND
/* /*************************************************************************
vi:ts=4:et:nowrap // 26-bit ARM calltrick ("naive")
*/ **************************************************************************/
#define CT26ARM_LE(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 4; \
do { \
if (cond) \
{ \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
} \
b += 4; \
} while (b < b_end); \
if (f->lastcall) f->lastcall += 4; \
return 0;
#define ARMCT_COND (((b[3] & 0x7C) == 0x14))
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)
{
CT26ARM_LE(f, ARMCT_COND, 0 - a / 4 - f->addvalue, get_le26, set_le26)
}
static int s_ct26arm_le(Filter *f)
{
CT26ARM_LE(f, ARMCT_COND, a + f->addvalue, get_le26, set_dummy)
}
#undef CT26ARM_LE
#undef ARMCT_COND
/* vim:set ts=4 sw=4 et: */
+5 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -129,6 +129,7 @@ static int F(Filter *f)
#if 0 || defined(TESTING) #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto); printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
#endif #endif
UNUSED(noncalls2);
return 0; return 0;
} }
@@ -169,8 +170,4 @@ static int U(Filter *f)
#undef F #undef F
#undef U #undef U
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+6 -9
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2013 John F. Reiser Copyright (C) 2000-2023 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -128,6 +128,7 @@ static int F(Filter *f)
#if 0 || defined(TESTING) #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto); printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
#endif #endif
UNUSED(noncalls2);
return 0; return 0;
} }
@@ -168,8 +169,4 @@ static int U(Filter *f)
#undef F #undef F
#undef U #undef U
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+11 -11
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2013 John F. Reiser Copyright (C) 2000-2023 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -62,7 +62,7 @@ f80_jcc2(Filter const *f)
return f80_jmp1(f); return f80_jmp1(f);
} }
static int const N_MRU = 32; // does not have to be a power of 2 #define N_MRU 32 // does not have to be a power of 2
// Adaptively remember recent destinations. // Adaptively remember recent destinations.
static void static void
@@ -254,6 +254,7 @@ static int F(Filter *f)
calls,noncalls,noncalls2,size,cto8); calls,noncalls,noncalls2,size,cto8);
printf("CALL/JMP/JCC %d %d %d\n",wtally[0],wtally[1],wtally[2]); printf("CALL/JMP/JCC %d %d %d\n",wtally[0],wtally[1],wtally[2]);
#endif #endif
UNUSED(noncalls2);
return 0; return 0;
} }
@@ -300,6 +301,9 @@ static int U(Filter *f)
} }
else { // not 1st time at this destination else { // not 1st time at this destination
jc >>= 1; jc >>= 1;
if (N_MRU <= jc) {
throwCompressedDataViolation();
}
int kh = jc + hand; int kh = jc + hand;
if (N_MRU <= kh) { if (N_MRU <= kh) {
kh -= N_MRU; kh -= N_MRU;
@@ -337,12 +341,8 @@ static int U(Filter *f)
} }
#endif #endif
#undef N_MRU
#undef F #undef F
#undef U #undef U
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+6 -9
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2000-2013 John F. Reiser Copyright (C) 2000-2023 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -129,6 +129,7 @@ static int F(Filter *f)
#if 0 || defined(TESTING) #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto); printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
#endif #endif
UNUSED(noncalls2);
return 0; return 0;
} }
@@ -171,8 +172,4 @@ static int U(Filter *f)
#undef F #undef F
#undef U #undef U
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+4 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -166,8 +166,4 @@ static int s_ctsw32_e9_e8(Filter *f)
#undef CTSW32 #undef CTSW32
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+34 -35
View File
@@ -1,9 +1,9 @@
/* filteri.cpp -- filter implementation (low-level) /* filter_impl.cpp -- filter implementation (low-level)
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,12 +22,12 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "../conf.h"
#include "filter.h" #include "../filter.h"
static unsigned static unsigned
umin(unsigned const a, unsigned const b) umin(unsigned const a, unsigned const b)
@@ -45,20 +45,20 @@ umin(unsigned const a, unsigned const b)
// util // util
**************************************************************************/ **************************************************************************/
#include "filter/getcto.h" #include "getcto.h"
/************************************************************************* /*************************************************************************
// simple filters: calltrick / swaptrick / delta / ... // simple filters: calltrick / swaptrick / delta / ...
**************************************************************************/ **************************************************************************/
#include "filter/ct.h" #include "ct.h"
#include "filter/sw.h" #include "sw.h"
#include "filter/ctsw.h" #include "ctsw.h"
#include "filter/sub8.h" #include "sub8.h"
#include "filter/sub16.h" #include "sub16.h"
#include "filter/sub32.h" #include "sub32.h"
/************************************************************************* /*************************************************************************
@@ -68,25 +68,25 @@ umin(unsigned const a, unsigned const b)
#define COND(b,x) (b[x] == 0xe8) #define COND(b,x) (b[x] == 0xe8)
#define F f_cto32_e8_bswap_le #define F f_cto32_e8_bswap_le
#define U u_cto32_e8_bswap_le #define U u_cto32_e8_bswap_le
#include "filter/cto.h" #include "cto.h"
#define F s_cto32_e8_bswap_le #define F s_cto32_e8_bswap_le
#include "filter/cto.h" #include "cto.h"
#undef COND #undef COND
#define COND(b,x) (b[x] == 0xe9) #define COND(b,x) (b[x] == 0xe9)
#define F f_cto32_e9_bswap_le #define F f_cto32_e9_bswap_le
#define U u_cto32_e9_bswap_le #define U u_cto32_e9_bswap_le
#include "filter/cto.h" #include "cto.h"
#define F s_cto32_e9_bswap_le #define F s_cto32_e9_bswap_le
#include "filter/cto.h" #include "cto.h"
#undef COND #undef COND
#define COND(b,x) (b[x] == 0xe8 || b[x] == 0xe9) #define COND(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
#define F f_cto32_e8e9_bswap_le #define F f_cto32_e8e9_bswap_le
#define U u_cto32_e8e9_bswap_le #define U u_cto32_e8e9_bswap_le
#include "filter/cto.h" #include "cto.h"
#define F s_cto32_e8e9_bswap_le #define F s_cto32_e8e9_bswap_le
#include "filter/cto.h" #include "cto.h"
#undef COND #undef COND
@@ -97,9 +97,9 @@ umin(unsigned const a, unsigned const b)
#define COND(b,x,lastcall) (b[x] == 0xe8 || b[x] == 0xe9) #define COND(b,x,lastcall) (b[x] == 0xe8 || b[x] == 0xe9)
#define F f_ctoj32_e8e9_bswap_le #define F f_ctoj32_e8e9_bswap_le
#define U u_ctoj32_e8e9_bswap_le #define U u_ctoj32_e8e9_bswap_le
#include "filter/ctoj.h" #include "ctoj.h"
#define F s_ctoj32_e8e9_bswap_le #define F s_ctoj32_e8e9_bswap_le
#include "filter/ctoj.h" #include "ctoj.h"
#undef COND #undef COND
@@ -112,9 +112,9 @@ umin(unsigned const a, unsigned const b)
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc))) #define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
#define F f_ctok32_e8e9_bswap_le #define F f_ctok32_e8e9_bswap_le
#define U u_ctok32_e8e9_bswap_le #define U u_ctok32_e8e9_bswap_le
#include "filter/ctok.h" #include "ctok.h"
#define F s_ctok32_e8e9_bswap_le #define F s_ctok32_e8e9_bswap_le
#include "filter/ctok.h" #include "ctok.h"
#undef COND #undef COND
#undef COND2 #undef COND2
#undef COND1 #undef COND1
@@ -138,9 +138,9 @@ umin(unsigned const a, unsigned const b)
#define F f_ctojr32_e8e9_bswap_le #define F f_ctojr32_e8e9_bswap_le
#define U u_ctojr32_e8e9_bswap_le #define U u_ctojr32_e8e9_bswap_le
#include "filter/ctojr.h" #include "ctojr.h"
#define F s_ctojr32_e8e9_bswap_le #define F s_ctojr32_e8e9_bswap_le
#include "filter/ctojr.h" #include "ctojr.h"
#undef CONDU #undef CONDU
#undef CONDF #undef CONDF
@@ -158,9 +158,9 @@ umin(unsigned const a, unsigned const b)
#define COND(b,x) (18==(get_be32(b+x)>>26)) #define COND(b,x) (18==(get_be32(b+x)>>26))
#define F f_ppcbxx #define F f_ppcbxx
#define U u_ppcbxx #define U u_ppcbxx
#include "filter/ppcbxx.h" #include "ppcbxx.h"
#define F s_ppcbxx #define F s_ppcbxx
#include "filter/ppcbxx.h" #include "ppcbxx.h"
#undef COND #undef COND
@@ -168,9 +168,9 @@ umin(unsigned const a, unsigned const b)
// database for use in class Filter // database for use in class Filter
**************************************************************************/ **************************************************************************/
const FilterImp::FilterEntry FilterImp::filters[] = { const FilterImpl::FilterEntry FilterImpl::filters[] = {
// no filter // no filter
{ 0x00, 0, 0, NULL, NULL, NULL }, { 0x00, 0, 0, nullptr, nullptr, nullptr },
// 16-bit calltrick // 16-bit calltrick
{ 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8 }, { 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8 },
@@ -228,6 +228,9 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
{ 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le }, { 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le },
{ 0x51, 8, 0x01ffffff, f_ct24arm_be, u_ct24arm_be, s_ct24arm_be }, { 0x51, 8, 0x01ffffff, f_ct24arm_be, u_ct24arm_be, s_ct24arm_be },
// 26-bit calltrick for arm64
{ 0x52, 8, 0x03ffffff, f_ct26arm_le, u_ct26arm_le, s_ct26arm_le },
// 32-bit cto calltrick with jmp and jcc(swap 0x0f/0x8Y) and relative renumbering // 32-bit cto calltrick with jmp and jcc(swap 0x0f/0x8Y) and relative renumbering
{ 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le }, { 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
{ 0x81, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le }, { 0x81, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
@@ -258,10 +261,6 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
{ 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx }, { 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx },
}; };
const int FilterImp::n_filters = TABLESIZE(filters); const int FilterImpl::n_filters = TABLESIZE(filters);
/*
vi:ts=4:et:nowrap
*/
/* vim:set ts=4 sw=4 et: */
+4 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -67,9 +67,4 @@ static int getcto(Filter *f, const unsigned char *buf, const int n=256)
return ic; return ic;
} }
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+5 -8
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
Copyright (C) 2004-2013 John F. Reiser Copyright (C) 2004-2023 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -153,7 +153,4 @@ static int U(Filter *f)
#undef W_CTO #undef W_CTO
/* /* vim:set ts=4 sw=4 et: */
vi:ts=4:et:nowrap
*/
+4 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -79,9 +79,4 @@
assert((int)f->calls > 0); \ assert((int)f->calls > 0); \
return 0; return 0;
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+4 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -115,8 +115,4 @@ static int s_sub16_4(Filter *f)
#undef ADD16 #undef ADD16
#undef SCAN16 #undef SCAN16
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+4 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -115,8 +115,4 @@ static int s_sub32_4(Filter *f)
#undef ADD32 #undef ADD32
#undef SCAN32 #undef SCAN32
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+4 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -115,8 +115,4 @@ static int s_sub8_4(Filter *f)
#undef ADD8 #undef ADD8
#undef SCAN8 #undef SCAN8
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+4 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
@@ -180,9 +180,4 @@ static int s_sw32_e8e9(Filter *f)
#undef SW32 #undef SW32
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+77 -60
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,14 +22,14 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "conf.h"
#include "compress.h"
#include "packmast.h" #include "packmast.h"
#include "packer.h" #include "packer.h"
#include "compress/compress.h" // upx_ucl_version_string()
/************************************************************************* /*************************************************************************
@@ -38,6 +38,13 @@
static bool head_done = 0; static bool head_done = 0;
// also see UPX_CONFIG_DISABLE_GITREV in CMakeLists.txt
#if defined(UPX_VERSION_GITREV)
const char gitrev[] = UPX_VERSION_GITREV;
#else
const char gitrev[1] = { 0 };
#endif
void show_head(void) void show_head(void)
{ {
FILE *f = con_term; FILE *f = con_term;
@@ -47,19 +54,19 @@ void show_head(void)
return; return;
head_done = 1; head_done = 1;
#define V(x) (strcmp(UPX_VERSION_STRING, UPX_VERSION_STRING4) ? UPX_VERSION_STRING : UPX_VERSION_STRING x)
fg = con_fg(f,FG_GREEN); fg = con_fg(f,FG_GREEN);
con_fprintf(f, con_fprintf(f,
" Ultimate Packer for eXecutables\n" " Ultimate Packer for eXecutables\n"
" Copyright (C) 1996 - %s\n" " Copyright (C) 1996 - " UPX_VERSION_YEAR "\n"
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n", #if defined(UPX_VERSION_GITREV)
UPX_VERSION_YEAR, "UPX git-%6.6s%c"
#if (ACC_OS_DOS16 || ACC_OS_DOS32) #else
V("d"), "UPX %-11s"
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64) #endif
V("w"), " Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
#elif 0 && defined(__linux__) #if defined(UPX_VERSION_GITREV)
V("l"), gitrev,
(sizeof(gitrev)-1 > 6 && gitrev[sizeof(gitrev)-2] == '+') ? '+' : ' ',
#else #else
UPX_VERSION_STRING, UPX_VERSION_STRING,
#endif #endif
@@ -80,7 +87,7 @@ void show_usage(void)
FILE *f = con_term; FILE *f = con_term;
con_fprintf(f,"Usage: %s [-123456789dlthVL] [-qvfk] [-o file] %sfile..\n", progname, con_fprintf(f,"Usage: %s [-123456789dlthVL] [-qvfk] [-o file] %sfile..\n", progname,
#if defined(__DJGPP__) || defined(__EMX__) #if (ACC_OS_DOS32) && defined(__DJGPP__)
"[@]"); "[@]");
#else #else
""); "");
@@ -101,7 +108,7 @@ struct PackerNames
Entry names[64]; Entry names[64];
size_t names_count; size_t names_count;
const options_t *o; const options_t *o;
PackerNames() : names_count(0), o(NULL) { } PackerNames() : names_count(0), o(nullptr) { }
void add(const Packer *p) void add(const Packer *p)
{ {
p->assertPacker(); p->assertPacker();
@@ -114,8 +121,8 @@ struct PackerNames
{ {
PackerNames *self = (PackerNames *) user; PackerNames *self = (PackerNames *) user;
self->add(p); self->add(p);
delete p; p = NULL; delete p; p = nullptr;
return NULL; return nullptr;
} }
static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) { static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) {
return strcmp(((const Entry *) a)->fname, ((const Entry *) b)->fname); return strcmp(((const Entry *) a)->fname, ((const Entry *) b)->fname);
@@ -129,16 +136,16 @@ static void show_all_packers(FILE *f, int verbose)
{ {
options_t o; o.reset(); options_t o; o.reset();
PackerNames pn; pn.o = &o; PackerNames pn; pn.o = &o;
PackMaster::visitAllPackers(pn.visit, NULL, &o, &pn); PackMaster::visitAllPackers(PackerNames::visit, nullptr, &o, &pn);
qsort(pn.names, pn.names_count, sizeof(PackerNames::Entry), pn.cmp_fname); qsort(pn.names, pn.names_count, sizeof(PackerNames::Entry), PackerNames::cmp_fname);
size_t pos = 0; size_t pos = 0;
for (size_t i = 0; i < pn.names_count; ++i) for (size_t i = 0; i < pn.names_count; ++i)
{ {
const char *fn = pn.names[i].fname; const char *fn = pn.names[i].fname;
const char *sn = pn.names[i].sname; const char *sn = pn.names[i].sname;
if (verbose) if (verbose > 0)
{ {
con_fprintf(f, " %-32s %s\n", fn, sn); con_fprintf(f, " %-36s %s\n", fn, sn);
} }
else else
{ {
@@ -155,7 +162,7 @@ static void show_all_packers(FILE *f, int verbose)
} }
} }
} }
if (!verbose && pn.names_count) if (verbose <= 0 && pn.names_count)
con_fprintf(f, "\n"); con_fprintf(f, "\n");
} }
@@ -208,6 +215,7 @@ void show_help(int verbose)
con_fprintf(f,"\nCompression tuning options:\n"); con_fprintf(f,"\nCompression tuning options:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
" --lzma try LZMA [slower but tighter than NRV]\n"
" --brute try all available compression methods & filters [slow]\n" " --brute try all available compression methods & filters [slow]\n"
" --ultra-brute try even more compression variants [very slow]\n" " --ultra-brute try even more compression variants [very slow]\n"
"\n"); "\n");
@@ -251,15 +259,6 @@ void show_help(int verbose)
con_fprintf(f, con_fprintf(f,
" --8086 make compressed sys work on any 8086\n" " --8086 make compressed sys work on any 8086\n"
"\n"); "\n");
#if 0
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for linux/386\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --script use /usr/local/lib/upx/upx[bd] as decompressor\n"
" --script=/path/upxX use path/upxX as decompressor\n"
"\n");
#endif
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for ps1/exe:\n"); con_fprintf(f,"Options for ps1/exe:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
@@ -276,7 +275,7 @@ void show_help(int verbose)
" --le produce LE output [default: EXE]\n" " --le produce LE output [default: EXE]\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for win32/pe, rtm32/pe & arm/pe:\n"); con_fprintf(f,"Options for win32/pe, win64/pe, rtm32/pe & arm/pe:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
" --compress-exports=0 do not compress the export section\n" " --compress-exports=0 do not compress the export section\n"
@@ -290,6 +289,7 @@ void show_help(int verbose)
" --strip-relocs=0 do not strip relocations\n" " --strip-relocs=0 do not strip relocations\n"
" --strip-relocs=1 strip relocations [default]\n" " --strip-relocs=1 strip relocations [default]\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for linux/elf:\n"); con_fprintf(f,"Options for linux/elf:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
@@ -311,17 +311,17 @@ void show_help(int verbose)
con_fprintf(f,"\nType '%s --help' for more detailed help.\n", progname); con_fprintf(f,"\nType '%s --help' for more detailed help.\n", progname);
} }
con_fprintf(f,"\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net\n" con_fprintf(f,"\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit https://upx.github.io\n"
// "\nUPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.\n" // "\nUPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.\n"
""); "");
#if (DEBUG) || (TESTING) #if DEBUG || TESTING
fg = con_fg(f,FG_RED); fg = con_fg(f,FG_RED);
con_fprintf(f,"\nWARNING: this version is compiled with" con_fprintf(f,"\nWARNING: this version is compiled with"
#if (DEBUG) #if DEBUG
" -DDEBUG" " -DDEBUG"
#endif #endif
#if (TESTING) #if TESTING
" -DTESTING" " -DTESTING"
#endif #endif
"\n"); "\n");
@@ -349,23 +349,23 @@ void show_license(void)
" This program is distributed in the hope that it will be useful,\n" " This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" UPX License Agreement for more details.\n" " UPX License Agreements for more details.\n"
"\n" "\n"
" You should have received a copy of the UPX License Agreement\n" " You should have received a copy of the UPX License Agreements\n"
" along with this program; see the file LICENSE.\n" " along with this program; see the files COPYING and LICENSE.\n"
" If not, visit one of the following pages:\n" " If not, visit one of the following pages:\n"
"\n" "\n"
); );
int fg = con_fg(f,FG_CYAN); int fg = con_fg(f,FG_CYAN);
con_fprintf(f, con_fprintf(f,
" http://upx.sourceforge.net\n" " https://upx.github.io\n"
" http://www.oberhumer.com/opensource/upx/\n" " https://www.oberhumer.com/opensource/upx/\n"
); );
(void)con_fg(f,FG_ORANGE); (void)con_fg(f,FG_ORANGE);
con_fprintf(f, con_fprintf(f,
"\n" "\n"
" Markus F.X.J. Oberhumer Laszlo Molnar\n" " Markus F.X.J. Oberhumer Laszlo Molnar\n"
" <markus@oberhumer.com> <ml1050@users.sourceforge.net>\n" " <markus@oberhumer.com> <ezerotven+github@gmail.com>\n"
); );
fg = con_fg(f,fg); fg = con_fg(f,fg);
@@ -377,49 +377,66 @@ void show_license(void)
// //
**************************************************************************/ **************************************************************************/
void show_version(int x) void show_version(bool one_line)
{ {
FILE *fp = stdout; FILE *fp = stdout;
const char *v; const char *v;
UNUSED(x);
UNUSED(v);
#if defined(UPX_VERSION_GIT_DESCRIBE)
fprintf(fp, "upx %s\n", UPX_VERSION_GIT_DESCRIBE);
#elif defined(UPX_VERSION_GITREV)
fprintf(fp, "upx %s\n", UPX_VERSION_STRING "-git-" UPX_VERSION_GITREV);
#else
fprintf(fp, "upx %s\n", UPX_VERSION_STRING); fprintf(fp, "upx %s\n", UPX_VERSION_STRING);
#endif
if (one_line)
return;
#if (WITH_NRV) #if (WITH_NRV)
v = upx_nrv_version_string(); v = upx_nrv_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "NRV data compression library %s\n", v); fprintf(fp, "NRV data compression library %s\n", v);
#endif #endif
#if (WITH_UCL) #if (WITH_UCL)
v = upx_ucl_version_string(); v = upx_ucl_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "UCL data compression library %s\n", v); fprintf(fp, "UCL data compression library %s\n", v);
#endif #endif
#if (WITH_ZLIB) #if (WITH_ZLIB)
v = upx_zlib_version_string(); v = upx_zlib_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "zlib data compression library %s\n", v); fprintf(fp, "zlib data compression library %s\n", v);
#endif #endif
#if (WITH_LZMA) #if (WITH_LZMA)
v = upx_lzma_version_string(); v = upx_lzma_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "LZMA SDK version %s\n", v); fprintf(fp, "LZMA SDK version %s\n", v);
#endif #endif
fprintf(fp, "Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer\n"); #if (WITH_ZSTD)
fprintf(fp, "Copyright (C) 1996-2013 Laszlo Molnar\n"); v = upx_zstd_version_string();
fprintf(fp, "Copyright (C) 2000-2013 John F. Reiser\n"); if (v != nullptr && v[0])
fprintf(fp, "Copyright (C) 2002-2013 Jens Medoch\n"); fprintf(fp, "zstd data compression library %s\n", v);
#endif
#if !defined(DOCTEST_CONFIG_DISABLE)
fprintf(fp, "doctest C++ testing framework version %s\n", DOCTEST_VERSION_STR);
#endif
fprintf(fp, "Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(fp, "Copyright (C) 1996-2023 Laszlo Molnar\n");
fprintf(fp, "Copyright (C) 2000-2023 John F. Reiser\n");
fprintf(fp, "Copyright (C) 2002-2023 Jens Medoch\n");
#if (WITH_ZLIB) #if (WITH_ZLIB)
fprintf(fp, "Copyright (C) 1995" "-2005 Jean-loup Gailly and Mark Adler\n"); fprintf(fp, "Copyright (C) 1995" "-2022 Jean-loup Gailly and Mark Adler\n");
#endif #endif
#if (WITH_LZMA) #if (WITH_LZMA)
fprintf(fp, "Copyright (C) 1999" "-2006 Igor Pavlov\n"); fprintf(fp, "Copyright (C) 1999" "-2006 Igor Pavlov\n");
#endif
#if (WITH_ZSTD)
// see vendor/zstd/LICENSE; main author is Yann Collet
fprintf(fp, "Copyright (C) 2015" "-2023 Meta Platforms, Inc. and affiliates\n");
#endif
#if !defined(DOCTEST_CONFIG_DISABLE)
fprintf(fp, "Copyright (C) 2016" "-2021 Viktor Kirilov\n");
#endif #endif
fprintf(fp, "UPX comes with ABSOLUTELY NO WARRANTY; for details type '%s -L'.\n", progname); fprintf(fp, "UPX comes with ABSOLUTELY NO WARRANTY; for details type '%s -L'.\n", progname);
} }
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et:nowrap
*/
+66 -126
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,37 +22,23 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "conf.h"
#include "file.h" #include "file.h"
#include "mem.h" #include "util/membuffer.h"
#include "lefile.h" #include "lefile.h"
LeFile::LeFile(InputFile *f) : fif(f), fof(nullptr), le_offset(0), exe_offset(0) {
LeFile::LeFile(InputFile *f) : COMPILE_TIME_ASSERT(sizeof(le_header_t) == 196)
fif(f), fof(NULL), COMPILE_TIME_ASSERT(sizeof(le_object_table_entry_t) == 24)
le_offset(0), exe_offset(0) COMPILE_TIME_ASSERT(sizeof(le_pagemap_entry_t) == 4)
{
COMPILE_TIME_ASSERT(sizeof(le_header_t) == 196);
COMPILE_TIME_ASSERT(sizeof(le_object_table_entry_t) == 24);
COMPILE_TIME_ASSERT(sizeof(le_pagemap_entry_t) == 4);
memset(&ih, 0, sizeof ih); memset(&ih, 0, sizeof ih);
memset(&oh, 0, sizeof oh); memset(&oh, 0, sizeof oh);
iobject_table = oobject_table = NULL;
ifpage_table = ofpage_table = NULL;
ipm_entries = opm_entries = NULL;
ires_names = ores_names = NULL;
ifixups = ofixups = NULL;
inonres_names = ononres_names = NULL;
ientries = oentries = NULL;
} }
LeFile::~LeFile() {
LeFile::~LeFile()
{
delete[] iobject_table; delete[] iobject_table;
delete[] oobject_table; delete[] oobject_table;
delete[] ifpage_table; delete[] ifpage_table;
@@ -69,30 +55,25 @@ LeFile::~LeFile()
delete[] oentries; delete[] oentries;
} }
#define objects ih.object_table_entries #define objects ih.object_table_entries
#define pages ih.memory_pages #define pages ih.memory_pages
#define mps ih.memory_page_size #define mps ih.memory_page_size
void LeFile::readObjectTable() {
void LeFile::readObjectTable() soobject_table = objects;
{ iobject_table = New(le_object_table_entry_t, soobject_table);
iobject_table = new le_object_table_entry_t[soobject_table = objects];
fif->seek(le_offset + ih.object_table_offset, SEEK_SET); fif->seek(le_offset + ih.object_table_offset, SEEK_SET);
fif->readx(iobject_table, sizeof(*iobject_table) * objects); fif->readx(iobject_table, sizeof(*iobject_table) * objects);
} }
void LeFile::writeObjectTable() {
void LeFile::writeObjectTable()
{
if (fof && oobject_table) if (fof && oobject_table)
fof->write(oobject_table, sizeof(*iobject_table) * soobject_table); fof->write(oobject_table, sizeof(*iobject_table) * soobject_table);
} }
void LeFile::readPageMap() {
void LeFile::readPageMap() sopm_entries = pages;
{ ipm_entries = New(le_pagemap_entry_t, sopm_entries);
ipm_entries = new le_pagemap_entry_t[sopm_entries = pages];
fif->seek(le_offset + ih.object_pagemap_offset, SEEK_SET); fif->seek(le_offset + ih.object_pagemap_offset, SEEK_SET);
fif->readx(ipm_entries, sizeof(*ipm_entries) * pages); fif->readx(ipm_entries, sizeof(*ipm_entries) * pages);
@@ -101,162 +82,129 @@ void LeFile::readPageMap()
throwCantPack("unexpected value in page map table"); throwCantPack("unexpected value in page map table");
} }
void LeFile::writePageMap() {
void LeFile::writePageMap()
{
if (fof && opm_entries) if (fof && opm_entries)
fof->write(opm_entries, sizeof(*ipm_entries) * sopm_entries); fof->write(opm_entries, sizeof(*ipm_entries) * sopm_entries);
} }
void LeFile::readResidentNames() {
void LeFile::readResidentNames()
{
sores_names = ih.entry_table_offset - ih.resident_names_offset; sores_names = ih.entry_table_offset - ih.resident_names_offset;
ires_names = new upx_byte[sores_names]; ires_names = New(upx_byte, sores_names);
fif->seek(le_offset + ih.resident_names_offset, SEEK_SET); fif->seek(le_offset + ih.resident_names_offset, SEEK_SET);
fif->readx(ires_names, sores_names); fif->readx(ires_names, sores_names);
} }
void LeFile::writeResidentNames() {
void LeFile::writeResidentNames()
{
if (fof && ores_names) if (fof && ores_names)
fof->write(ores_names, sores_names); fof->write(ores_names, sores_names);
} }
void LeFile::readEntryTable() {
void LeFile::readEntryTable()
{
soentries = ih.fixup_page_table_offset - ih.entry_table_offset; soentries = ih.fixup_page_table_offset - ih.entry_table_offset;
fif->seek(le_offset + ih.entry_table_offset, SEEK_SET); fif->seek(le_offset + ih.entry_table_offset, SEEK_SET);
ientries = new upx_byte[soentries]; ientries = New(upx_byte, soentries);
fif->readx(ientries, soentries); fif->readx(ientries, soentries);
} }
void LeFile::writeEntryTable() {
void LeFile::writeEntryTable()
{
if (fof && oentries) if (fof && oentries)
fof->write(oentries, soentries); fof->write(oentries, soentries);
} }
void LeFile::readFixupPageTable() {
void LeFile::readFixupPageTable() sofpage_table = 1 + pages;
{ ifpage_table = New(unsigned, sofpage_table);
ifpage_table = new unsigned[sofpage_table = 1+pages];
fif->seek(le_offset + ih.fixup_page_table_offset, SEEK_SET); fif->seek(le_offset + ih.fixup_page_table_offset, SEEK_SET);
fif->readx(ifpage_table, 4 * sofpage_table); fif->readx(ifpage_table, 4 * sofpage_table);
} }
void LeFile::writeFixupPageTable() {
void LeFile::writeFixupPageTable()
{
if (fof && ofpage_table) if (fof && ofpage_table)
fof->write(ofpage_table, 4 * sofpage_table); fof->write(ofpage_table, 4 * sofpage_table);
} }
void LeFile::readFixups() {
void LeFile::readFixups()
{
sofixups = get_le32(ifpage_table + pages) - get_le32(ifpage_table); sofixups = get_le32(ifpage_table + pages) - get_le32(ifpage_table);
ifixups = new upx_byte[sofixups]; ifixups = New(upx_byte, sofixups);
fif->seek(le_offset + ih.fixup_record_table_offset, SEEK_SET); fif->seek(le_offset + ih.fixup_record_table_offset, SEEK_SET);
fif->readx(ifixups, sofixups); fif->readx(ifixups, sofixups);
} }
void LeFile::writeFixups() {
void LeFile::writeFixups()
{
if (fof && ofixups) if (fof && ofixups)
fof->write(ofixups, sofixups); fof->write(ofixups, sofixups);
} }
unsigned LeFile::getImageSize() const {
unsigned LeFile::getImageSize() const
{
unsigned n = 0; unsigned n = 0;
if (ih.memory_pages > 0) if (ih.memory_pages > 0) {
{
n = (ih.memory_pages - 1) * ih.memory_page_size; n = (ih.memory_pages - 1) * ih.memory_page_size;
n += ih.bytes_on_last_page; n += ih.bytes_on_last_page;
} }
return n; return n;
} }
void LeFile::readImage() {
void LeFile::readImage()
{
soimage = pages * mps; soimage = pages * mps;
iimage.alloc(soimage); mb_iimage.alloc(soimage);
memset(iimage,0,soimage); mb_iimage.clear();
iimage = mb_iimage;
unsigned ic, jc; unsigned ic, jc;
for (ic = jc = 0; ic < pages; ic++) for (ic = jc = 0; ic < pages; ic++) {
{ if ((ipm_entries[ic].type & 0xC0) == 0) {
if ((ipm_entries[ic].type & 0xC0) == 0)
{
fif->seek(ih.data_pages_offset + exe_offset + fif->seek(ih.data_pages_offset + exe_offset +
(ipm_entries[ic].m*0x100 + ipm_entries[ic].l-1) * mps,SEEK_SET); (ipm_entries[ic].m * 0x100 + ipm_entries[ic].l - 1) * mps,
fif->readx(iimage+jc,ic != pages-1 ? mps : ih.bytes_on_last_page); SEEK_SET);
auto bytes = ic != pages - 1 ? mps : ih.bytes_on_last_page;
fif->readx(raw_bytes(iimage + jc, bytes), bytes);
} }
jc += mps; jc += mps;
} }
} }
void LeFile::writeImage() {
void LeFile::writeImage() if (fof && oimage != nullptr)
{ fof->write(raw_bytes(oimage, soimage), soimage);
if (fof && oimage != NULL)
fof->write(oimage, soimage);
} }
void LeFile::readNonResidentNames() {
void LeFile::readNonResidentNames() if (ih.non_resident_name_table_length) {
{ sononres_names = ih.non_resident_name_table_length;
if (ih.non_resident_name_table_length) inonres_names = New(upx_byte, sononres_names);
{
inonres_names = new upx_byte[sononres_names = ih.non_resident_name_table_length];
fif->seek(exe_offset + ih.non_resident_name_table_offset, SEEK_SET); fif->seek(exe_offset + ih.non_resident_name_table_offset, SEEK_SET);
fif->readx(inonres_names, sononres_names); fif->readx(inonres_names, sononres_names);
} }
} }
void LeFile::writeNonResidentNames() {
void LeFile::writeNonResidentNames()
{
if (fof && ononres_names) if (fof && ononres_names)
fof->write(ononres_names, sononres_names); fof->write(ononres_names, sononres_names);
} }
bool LeFile::readFileHeader() {
bool LeFile::readFileHeader()
{
#define H(x) get_le16(header + 2 * (x)) #define H(x) get_le16(header + 2 * (x))
upx_byte header[0x40]; upx_byte header[0x40];
le_offset = exe_offset = 0; le_offset = exe_offset = 0;
int ic; int ic;
for (ic = 0; ic < 20; ic++) for (ic = 0; ic < 20; ic++) {
{
fif->seek(le_offset, SEEK_SET); fif->seek(le_offset, SEEK_SET);
fif->readx(header, sizeof(header)); fif->readx(header, sizeof(header));
if (memcmp(header, "MZ", 2) == 0) // normal dos exe if (memcmp(header, "MZ", 2) == 0) // normal dos exe
{ {
exe_offset = le_offset; exe_offset = le_offset;
if (H(0x18/2) >= 0x40 if (H(0x18 / 2) >= 0x40 && memcmp(header + 0x19, "TIPPACH", 7)) // new format exe
&& memcmp(header+0x19,"TIPPACH",7)) // new format exe
le_offset += H(0x3c / 2) + H(0x3e / 2) * 65536; le_offset += H(0x3c / 2) + H(0x3e / 2) * 65536;
else else {
{
le_offset += H(2) * 512 + H(1); le_offset += H(2) * 512 + H(1);
if (H(1)) if (H(1))
le_offset -= 512; le_offset -= 512;
else if (H(2) == 0) else if (H(2) == 0)
return false; return false;
} }
} } else if (memcmp(header, "BW", 2) == 0) // used in dos4gw.exe
else if (memcmp(header,"BW",2) == 0) // used in dos4gw.exe
le_offset += H(2) * 512 + H(1); le_offset += H(2) * 512 + H(1);
else if (memcmp(header, "LE", 2) == 0) else if (memcmp(header, "LE", 2) == 0)
break; break;
@@ -273,11 +221,10 @@ bool LeFile::readFileHeader()
#undef H #undef H
} }
void LeFile::writeFile(OutputFile *f, bool le) {
void LeFile::writeFile(OutputFile *f, bool le)
{
fof = f; fof = f;
memcpy (&oh,&ih,(char*)&oh.memory_pages-(char*)&oh); // copy some members of the orig. header memcpy(&oh, &ih,
(char *) &oh.memory_pages - (char *) &oh); // copy some members of the orig. header
oh.memory_page_size = mps; oh.memory_page_size = mps;
oh.object_table_offset = sizeof(oh); oh.object_table_offset = sizeof(oh);
oh.object_table_entries = soobject_table; oh.object_table_entries = soobject_table;
@@ -288,9 +235,9 @@ void LeFile::writeFile(OutputFile *f, bool le)
oh.fixup_record_table_offset = oh.fixup_page_table_offset + sofpage_table * 4; oh.fixup_record_table_offset = oh.fixup_page_table_offset + sofpage_table * 4;
oh.imported_modules_name_table_offset = oh.fixup_record_table_offset + sofixups - FIXUP_EXTRA; oh.imported_modules_name_table_offset = oh.fixup_record_table_offset + sofixups - FIXUP_EXTRA;
oh.imported_procedures_name_table_offset = oh.imported_modules_name_table_offset; oh.imported_procedures_name_table_offset = oh.imported_modules_name_table_offset;
oh.data_pages_offset = oh.fixup_record_table_offset + sofixups + (le ? 0 : le_offset-exe_offset); oh.data_pages_offset =
if (ih.non_resident_name_table_length) oh.fixup_record_table_offset + sofixups + (le ? 0 : le_offset - exe_offset);
{ if (ih.non_resident_name_table_length) {
oh.non_resident_name_table_offset = oh.data_pages_offset + soimage; oh.non_resident_name_table_offset = oh.data_pages_offset + soimage;
oh.non_resident_name_table_length = sononres_names; oh.non_resident_name_table_length = sononres_names;
} }
@@ -308,9 +255,7 @@ void LeFile::writeFile(OutputFile *f, bool le)
writeNonResidentNames(); writeNonResidentNames();
} }
void LeFile::countFixups(unsigned *counts) const {
void LeFile::countFixups(unsigned *counts) const
{
const unsigned o = objects; const unsigned o = objects;
memset(counts, 0, sizeof(unsigned) * (o + 2)); memset(counts, 0, sizeof(unsigned) * (o + 2));
// counts[0..objects-1] - # of 32-bit offset relocations in for that objects // counts[0..objects-1] - # of 32-bit offset relocations in for that objects
@@ -321,12 +266,10 @@ void LeFile::countFixups(unsigned *counts) const
const unsigned sfixups = get_le32(ifpage_table + pages); const unsigned sfixups = get_le32(ifpage_table + pages);
unsigned ll; unsigned ll;
while ((unsigned)(fix - ifixups) < sfixups) while (ptr_udiff_bytes(fix, ifixups) < sfixups) {
{
if ((fix[1] & ~0x10) != 0) if ((fix[1] & ~0x10) != 0)
throwCantPack("unsupported fixup record"); throwCantPack("unsupported fixup record");
switch (*fix) switch (*fix) {
{
case 2: // selector fixup case 2: // selector fixup
counts[o] += 9; counts[o] += 9;
fix += 5; fix += 5;
@@ -338,6 +281,7 @@ void LeFile::countFixups(unsigned *counts) const
break; break;
case 6: // 16:32 pointer case 6: // 16:32 pointer
counts[o] += 9; counts[o] += 9;
// fall through
case 7: // 32-bit offset case 7: // 32-bit offset
counts[fix[4] - 1] += 4; counts[fix[4] - 1] += 4;
fix += (fix[1] & 0x10) ? 9 : 7; fix += (fix[1] & 0x10) ? 9 : 7;
@@ -360,8 +304,4 @@ void LeFile::countFixups(unsigned *counts) const
counts[o + 1] += 4; // extra space for 0xFFFFFFFF counts[o + 1] += 4; // extra space for 0xFFFFFFFF
} }
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+57 -53
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar Copyright (C) 1996-2023 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,24 +22,22 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#pragma once
#ifndef __UPX_LEFILE_H #ifndef UPX_LEFILE_H__
#define __UPX_LEFILE_H 1 #define UPX_LEFILE_H__ 1
class InputFile; class InputFile;
class OutputFile; class OutputFile;
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
class LeFile class LeFile {
{ protected:
public:
LeFile(InputFile *); LeFile(InputFile *);
virtual ~LeFile(); virtual ~LeFile();
@@ -49,7 +47,7 @@ public:
protected: protected:
enum { FIXUP_EXTRA = 3 }; enum { FIXUP_EXTRA = 3 };
__packed_struct(le_header_t) struct alignas(1) le_header_t {
// 0x00 // 0x00
char _[2]; // signature: 'LE' || 'LX' char _[2]; // signature: 'LE' || 'LX'
char byte_order; // 0 little endian char byte_order; // 0 little endian
@@ -112,96 +110,107 @@ protected:
LE32 extra_heap_alloc; LE32 extra_heap_alloc;
char reserved[12]; char reserved[12];
LE32 versioninfo; LE32 versioninfo;
LE32 unkown; LE32 unknown;
// 0xC0 // 0xC0
LE16 device_id; LE16 device_id;
LE16 ddk_version; LE16 ddk_version;
#endif #endif
__packed_struct_end() };
__packed_struct(le_object_table_entry_t) struct alignas(1) le_object_table_entry_t {
LE32 virtual_size; LE32 virtual_size;
LE32 base_address; LE32 base_address;
LE32 flags; LE32 flags;
LE32 pagemap_index; LE32 pagemap_index;
LE32 npages; LE32 npages;
LE32 reserved; LE32 reserved;
__packed_struct_end() };
__packed_struct(le_pagemap_entry_t) struct alignas(1) le_pagemap_entry_t {
unsigned char h; unsigned char h;
unsigned char m; unsigned char m;
unsigned char l; unsigned char l;
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
__packed_struct_end() };
virtual void readObjectTable(); virtual void readObjectTable();
virtual void writeObjectTable(); virtual void writeObjectTable();
//virtual void encodeObjectTable(){oobject_table = iobject_table; iobject_table = NULL;} // virtual void encodeObjectTable(){oobject_table = iobject_table; iobject_table = nullptr;}
// virtual void decodeObjectTable(){encodeObjectTable();} // virtual void decodeObjectTable(){encodeObjectTable();}
virtual void readFixupPageTable(); virtual void readFixupPageTable();
virtual void writeFixupPageTable(); virtual void writeFixupPageTable();
//virtual void encodeFixupPageTable(){ofpage_table = ifpage_table; ifpage_table = NULL;} // virtual void encodeFixupPageTable(){ofpage_table = ifpage_table; ifpage_table = nullptr;}
// virtual void decodeFixupPageTable(){encodeFixupPageTable();} // virtual void decodeFixupPageTable(){encodeFixupPageTable();}
virtual void readPageMap(); virtual void readPageMap();
virtual void writePageMap(); virtual void writePageMap();
virtual void encodePageMap(){opm_entries = ipm_entries; ipm_entries = NULL;} virtual void encodePageMap() {
opm_entries = ipm_entries;
ipm_entries = nullptr;
}
virtual void decodePageMap() { encodePageMap(); } virtual void decodePageMap() { encodePageMap(); }
virtual void readResidentNames(); virtual void readResidentNames();
virtual void writeResidentNames(); virtual void writeResidentNames();
virtual void encodeResidentNames(){ores_names = ires_names; ires_names = NULL;} virtual void encodeResidentNames() {
ores_names = ires_names;
ires_names = nullptr;
}
virtual void decodeResidentNames() { encodeResidentNames(); } virtual void decodeResidentNames() { encodeResidentNames(); }
virtual void readNonResidentNames(); virtual void readNonResidentNames();
virtual void writeNonResidentNames(); virtual void writeNonResidentNames();
virtual void encodeNonResidentNames(){ononres_names = inonres_names; inonres_names = NULL;} virtual void encodeNonResidentNames() {
ononres_names = inonres_names;
inonres_names = nullptr;
}
virtual void decodeNonResidentNames() { encodeNonResidentNames(); } virtual void decodeNonResidentNames() { encodeNonResidentNames(); }
virtual void readEntryTable(); virtual void readEntryTable();
virtual void writeEntryTable(); virtual void writeEntryTable();
//virtual void encodeEntryTable(){oentries = ientries; ientries = NULL;} // virtual void encodeEntryTable(){oentries = ientries; ientries = nullptr;}
// virtual void decodeEntryTable(){encodeEntryTable();} // virtual void decodeEntryTable(){encodeEntryTable();}
virtual void readFixups(); virtual void readFixups();
virtual void writeFixups(); virtual void writeFixups();
//virtual void encodeFixups(){ofixups = ifixups; ifixups = NULL;} // virtual void encodeFixups(){ofixups = ifixups; ifixups = nullptr;}
// virtual void decodeFixups(){encodeFixups();} // virtual void decodeFixups(){encodeFixups();}
virtual void readImage(); virtual void readImage();
virtual void writeImage(); virtual void writeImage();
//virtual void encodeImage(){oimage = iimage; iimage = NULL;} // virtual void encodeImage(){oimage = iimage; iimage = nullptr;}
// virtual void decodeImage(){encodeImage();} // virtual void decodeImage(){encodeImage();}
void countFixups(unsigned *) const; void countFixups(unsigned *) const;
unsigned getImageSize() const; unsigned getImageSize() const;
InputFile *fif; InputFile *fif = nullptr;
OutputFile *fof; OutputFile *fof = nullptr;
long le_offset; unsigned le_offset;
long exe_offset; unsigned exe_offset;
le_header_t ih; le_header_t ih;
le_header_t oh; le_header_t oh;
le_object_table_entry_t *iobject_table; le_object_table_entry_t *iobject_table = nullptr;
le_object_table_entry_t *oobject_table; le_object_table_entry_t *oobject_table = nullptr;
unsigned *ifpage_table; unsigned *ifpage_table = nullptr;
unsigned *ofpage_table; unsigned *ofpage_table = nullptr;
le_pagemap_entry_t *ipm_entries; le_pagemap_entry_t *ipm_entries = nullptr;
le_pagemap_entry_t *opm_entries; le_pagemap_entry_t *opm_entries = nullptr;
upx_byte *ires_names; upx_byte *ires_names = nullptr;
upx_byte *ores_names; upx_byte *ores_names = nullptr;
upx_byte *ifixups; upx_byte *ifixups = nullptr;
upx_byte *ofixups; upx_byte *ofixups = nullptr;
upx_byte *inonres_names; upx_byte *inonres_names = nullptr;
upx_byte *ononres_names; upx_byte *ononres_names = nullptr;
MemBuffer iimage; MemBuffer mb_iimage;
MemBuffer oimage; SPAN_0(upx_byte) iimage = nullptr;
upx_byte *ientries; MemBuffer mb_oimage;
upx_byte *oentries; SPAN_0(upx_byte) oimage = nullptr;
upx_byte *ientries = nullptr;
upx_byte *oentries = nullptr;
unsigned soobject_table; unsigned soobject_table;
unsigned sofpage_table; unsigned sofpage_table;
@@ -214,15 +223,10 @@ protected:
private: private:
// disable copy and assignment // disable copy and assignment
LeFile(const LeFile &); // {} LeFile(const LeFile &) = delete;
LeFile& operator= (const LeFile &); // { return *this; } LeFile &operator=(const LeFile &) = delete;
}; };
#endif /* already included */ #endif /* already included */
/* vim:set ts=4 sw=4 et: */
/*
vi:ts=4:et
*/
+384 -371
View File
File diff suppressed because it is too large Load Diff

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