Commit Graph

3533 Commits

Author SHA1 Message Date
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