Compare commits

...

94 Commits

Author SHA1 Message Date
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
Markus F.X.J. Oberhumer 7082594bbc Prepare release. 2013-02-18 11:03:33 +01:00
Markus F.X.J. Oberhumer 36dd35f238 Silence some compilation warnings. 2013-02-18 11:01:30 +01:00
John Reiser 9c9fb6a485 DEBUG-only bug in decimal() 2013-02-15 16:35:45 -08:00
John Reiser 5438a4837b more AT_PHDR trouble 2013-02-15 16:32:51 -08:00
Markus F.X.J. Oberhumer 84996e8cb6 Bump tentative release date. 2013-02-12 10:32:11 +01:00
Markus F.X.J. Oberhumer 87a368a857 Welcome 2013. 2013-02-12 10:14:03 +01:00
Markus F.X.J. Oberhumer 21412d93dd New ACC version. 2013-02-12 08:16:44 +00:00
John Reiser 0b11ff22b4 internal documentation: pointer to source for Apple codesign 2013-02-03 11:27:02 -08:00
John Reiser 8fafa78796 sync stubs 2013-01-31 12:33:16 -08:00
John Reiser c43158f8a2 find PT_LOAD in case ARM PT_EXIDX is first 2013-01-31 12:21:51 -08:00
John Reiser 92ad524947 clear registers at user entry (paranoia) 2013-01-31 12:20:42 -08:00
John Reiser b362a61863 fix for user brk() on ARM with static linking 2013-01-31 12:19:35 -08:00
John Reiser 468fec38d7 Fix .e_ident[EI_OSABI] for Debian armhf. 2013-01-30 13:31:35 -08:00
John Reiser 89830a5ae0 Mac OS X codesign disallows overhang of vmsize. 2013-01-25 15:58:25 -08:00
John Reiser 5977c296bd Fix codesign for Mac OS X. 2013-01-24 15:28:21 -08:00
John Reiser 47d5792d97 Updates to prepare for next release. 2012-11-14 09:07:10 -08:00
Markus F.X.J. Oberhumer 25d706a913 Whitespace cleanup. 2012-10-31 15:50:52 +01:00
John Reiser 048236aaaa Isolate change to p_mach.cpp of previous revision
(p_lx_elf.cpp and p_lx_elf.h were included by mistake.)
2012-10-10 08:58:15 -07:00
John Reiser d442c58fd1 MachO no longer needs contiguous LC_SEGMENT (SourceForge bug 3308161) 2012-10-10 08:51:52 -07:00
John Reiser f890f6bb09 ignore another .vmsize==0; fix unfold which needs another page 2012-08-23 14:26:42 -07:00
John Reiser 036d466790 allow 3-byte decompressor overrun; fix DEBUG decimal(); unify with i386 2012-08-23 14:25:32 -07:00
John Reiser dee47ba2d8 implement DEBUG 2012-08-23 14:22:55 -07:00
John Reiser be96c28b77 fix DEBUG decimal() of negative number 2012-08-23 12:37:44 -07:00
John Reiser ad1c0f578e fix DEBUG decimal() of negative number 2012-08-23 07:31:30 -07:00
John Reiser c8f7b1b72c MacOSX launcher gets SIGBUS when it cannot find mapped Mach_header.
Add segZERO, segMHDR, secMHDR.
2012-08-22 20:46:35 -07:00
John Reiser c89702ae84 skip 0==.vmsize; also DEBUG, DPRINTF 2012-08-22 20:43:00 -07:00
John Reiser 2d29a82250 PackMachBase<T>::pack1() segTEXT.vmaddr must ignore zero-length segments 2012-08-20 20:02:26 -07:00
John Reiser b36c65e654 fix Mac OS X code signing; also leave room for LC_UUID 2012-08-04 16:44:21 -07:00
John Reiser 09b072b908 Leave space for code signing on Mac OS X. 2012-08-03 13:28:33 -07:00
John Reiser 0ae9fee350 Mach_linkedit_data_command 2012-08-03 13:20:00 -07:00
John Reiser 1579182ed9 PackUnix::canUnpack() allows zero-filled last page 2012-08-03 13:19:28 -07:00
John Reiser 074671aa71 ::unpack "if (fo)"; also "delete []" (SourceForge bug 3545609) 2012-07-19 20:11:44 -07:00
John Reiser 36b7c47247 __DWARF LC_SEGMENT_64 with .vmsize==0 (SourceForge bug 3308161) 2012-07-18 15:37:41 -07:00
John Reiser 424d5b3025 UPX_LZMA_VERSION, zlib, zlib-devel, URL for lzma SDK 2012-07-16 15:22:22 -07:00
John Reiser 8a5d352733 Portability: fix "EOFException: premature end of file" doing ELF on Windows.
OutputFile::read() was bad news; fsync() should work, but was missing.
2012-07-12 14:25:28 -07:00
John Reiser f383629282 compressWithFilters(..., inhibit_compression_check=0) // SourceForge bug 3541020
Not good to check compression ratio on every block when blocksize < file_size,
as when --force_execve of Elf > 0x80000 bytes.
2012-07-12 07:04:56 -07:00
John Reiser a6d717cb04 big endian, too: ARM Linux EABI version 4 and 5 is a mess 2012-07-07 07:45:51 -07:00
Markus F.X.J. Oberhumer 84a5753301 New ACC version. 2012-05-31 16:08:14 +00:00
Markus F.X.J. Oberhumer 5d2d9c7e81 Update .hgignore. Update valgrind macros. 2012-04-26 09:05:35 +02:00
Markus F.X.J. Oberhumer 82801d1411 Fix some typos in documentation and comments. 2012-03-27 02:14:03 +02:00
John Reiser 340c3963d8 MIPS mmap_privanon in .S in case gcc learns how to 'bal'. 2012-03-14 08:24:04 -07:00
John Reiser ef15cf9847 merge 2012-03-13 19:56:30 -07:00
John Reiser 4d613ccfa7 MIPS mmap_privanon() forgot to set syscall number; also gcc __asm__() problems.
[Sourceforge upx-Bugs-3503753]
2012-03-13 19:54:47 -07:00
Markus F.X.J. Oberhumer 43ce34d547 Welcome 2012. 2012-01-01 22:35:11 +01:00
Markus F.X.J. Oberhumer eda074cd80 New ACC version. 2012-01-01 21:18:43 +00:00
Markus F.X.J. Oberhumer a2396d82f6 NEWS: spelling fixes. 2011-12-14 18:06:39 +01:00
Markus F.X.J. Oberhumer a38721db93 Remove meaningless "const" from casts. 2011-12-14 06:05:41 +01:00
Markus F.X.J. Oberhumer a06e811717 Remove extra semicolons. 2011-12-14 06:05:08 +01:00
Markus F.X.J. Oberhumer 86e534ff75 Remove trailing whitespace. Remove hard tabs. 2011-12-14 06:03:08 +01:00
John Reiser 640d5b2dec Option --preserve-build-id for Gnu ELF; contributed by Nicholas Twerdochlib
(SourceForge [ upx-Patches-3413335 ])
2011-12-13 17:26:03 -08:00
John Reiser 57e9b27085 merge 2011-12-13 10:54:55 -08:00
John Reiser c56eefc739 Document /proc/self/exe problems on arm*-linux-elf. 2011-12-13 10:53:26 -08:00
Markus F.X.J. Oberhumer cf28306997 Post-release version bump. 2011-12-13 01:30:00 +01:00
Markus F.X.J. Oberhumer 10acf3ddd1 Add tag for RELEASE_308. 2011-12-12 16:08:00 +00:00
365 changed files with 12629 additions and 5260 deletions
+2
View File
@@ -9,6 +9,8 @@ syntax: regexp
syntax: glob syntax: glob
.depend .depend
*.qtcreator.{config,creator,creator.user,files,includes}
*.sublime-{project,workspace}
Makevars.local Makevars.local
*.a *.a
+2
View File
@@ -1,3 +1,4 @@
087cafe682c014863b4aa8a6ea21431251a6ad3c RELEASE_308
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111 140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
155618b5b7930f97bd84b82befa7a4fd6672efb3 RELEASE_304 155618b5b7930f97bd84b82befa7a4fd6672efb3 RELEASE_304
1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301 1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301
@@ -17,6 +18,7 @@ b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192 c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
c9a983b7da9d4a2311f74366478348412cac2986 RELEASE_305 c9a983b7da9d4a2311f74366478348412cac2986 RELEASE_305
d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290 d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290
d3989a12c70b0921ff0f7e5e485b398eb12a73b3 RELEASE_309
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110 eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191 ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
ef9c7f2c9658d73a9b5ab2ed291483d2bbcd8bc7 RELEASE_300 ef9c7f2c9658d73a9b5ab2ed291483d2bbcd8bc7 RELEASE_300
+2 -2
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2011 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -44,7 +44,7 @@ test file.
win32/pe win32/pe
-------- --------
* writeable shared sections (`--force' *may* work) * writable shared sections (`--force' *may* work)
* 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
+1 -1
View File
@@ -1,7 +1,7 @@
# #
# UPX toplevel Makefile - needs GNU make 3.81 or better # UPX toplevel Makefile - needs GNU make 3.81 or better
# #
# Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer # Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR MAKEFLAGS += -rR
+17 -3
View File
@@ -2,14 +2,28 @@
User visible changes for UPX User visible changes for UPX
================================================================== ==================================================================
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):
* New option --preserve-build-id for GNU ELF.
* Allow for code signing and LC_UUID on Mac OS X executables.
* Allow non-contiguous LC_SEGMENTs and 0==.vmsize for Mach-O.
* Allow zero-filled final page in PackUnix::canUnpack().
* bug fixes
Changes in 3.08 (12 Dec 2011): Changes in 3.08 (12 Dec 2011):
* Fix allocation in runtime stub for darwin.macho-entry (i386 and amd64). * Fix allocation in runtime stub for darwin.macho-entry (i386 and amd64).
* Compress shared library on ELF i386 only [ld.so threatens even this case]. * Compress shared library on ELF i386 only [ld.so threatens even this case].
* Attempt to suport ELF on QNX 6.3.0 for armel (experimental). * Attempt to support ELF on QNX 6.3.0 for armel (experimental).
* Better diangostic when ELF -fPIC is needed. * Better diagnostic when ELF -fPIC is needed.
* PT_NOTE improvements for *BSD. * PT_NOTE improvements for *BSD.
* Preserve more ELF .e_flags on ARM. * Preserve more ELF .e_flags on ARM.
* Minor code improvements for ELF stubs * Minor code improvements for ELF stubs.
* Defend against another flavor of corrupt PE header. * Defend against another flavor of corrupt PE header.
* bug fixes * bug fixes
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2011 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
+4 -4
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2011 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -108,9 +108,9 @@ THE FUTURE
COPYRIGHT COPYRIGHT
========= =========
Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 John F. Reiser
This program may be used freely, and you are welcome to This program may be used freely, and you are welcome to
redistribute it under certain conditions. redistribute it under certain conditions.
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2011 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
+7
View File
@@ -71,6 +71,12 @@ Tools needed to build/modify the UPX sources
- GNU make 3.81 or better - GNU make 3.81 or better
- zlib and zlib-devel [or zlib-dev] software packages for your
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
----------------------------- -----------------------------
@@ -85,6 +91,7 @@ To compile the packer sources
to your unpacked lzma443.tar.bz2 source directory, e.g. to your unpacked lzma443.tar.bz2 source directory, e.g.
export UPX_LZMADIR=$HOME/local/src/lzma-4.43 (Unix) export UPX_LZMADIR=$HOME/local/src/lzma-4.43 (Unix)
export UPX_LZMA_VERSION=0x443 # perhaps 0x459,0x458,0x457,0x449,0x442
Finally type Finally type
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2011 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
+16 -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-2011 John F. Reiser jreiser@BitWagon.com Copyright (C) 2000-2013 John F. Reiser jreiser@BitWagon.com
References: References:
<elf.h> definitions for the ELF file format <elf.h> definitions for the ELF file format
@@ -76,6 +76,21 @@ and previous versions did this by default with no option. However,
too much other software erroneously assumes that /proc/self/exe too much other software erroneously assumes that /proc/self/exe
always exists. always exists.
On arm*-linux-elf there is no good address at which to retain one
page of the compressed executable. Pages below the usual .p_vaddr
0x8000 (32KiB) are rejected by the kernel. Using a page above the
original uncompressed brk(0) would require placing the entire initial
compressed program above uncompressed brk(0), which would significantly
increase the running brk(0); but too many programs break if brk(0)
moves. Thus on arm*-linux-elf the compressed executable begins
with 0x8000==.p_vaddr, all pages mapped by execve() that are also
occupied by decompressed bytes are removed before overwriting, and
/proc/self/exe becomes a "(deleted)" symlink. It might be possible
to preserve /proc/self/exe if the original uncompressed executable
were created with 0x9000==.p_vaddr (one page higher than the usual
0x8000) so that the compressed page mapped at 0x8000 would linger.
[This has not been tested.]
Linux stores the pathname argument that was specified to execve() Linux stores the pathname argument that was specified to execve()
immediately after the '\0' which terminates the character string of the immediately after the '\0' which terminates the character string of the
last environment variable [as of execve()]. This is true for at least last environment variable [as of execve()]. This is true for at least
+1 -1
View File
@@ -20,7 +20,7 @@ code 127, and a record will be added to the history file
In "targeted enforcing" mode, SELinux pays close attention mostly to In "targeted enforcing" mode, SELinux pays close attention mostly to
designated processes that run with elevated privileges: web server, designated processes that run with elevated privileges: web server,
print server, login server, etc. Ordinary user excutables receive print server, login server, etc. Ordinary user executables receive
much less scrutiny. However, one of the eventual goals of SELinux is to much less scrutiny. However, one of the eventual goals of SELinux is to
eradicate runtime generation of instructions because of the possibility eradicate runtime generation of instructions because of the possibility
for exploitation by malware (virus, trojan, key logger, privilege for exploitation by malware (virus, trojan, key logger, privilege
+5 -5
View File
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
=head1 ABSTRACT =head1 ABSTRACT
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2011 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -933,13 +933,13 @@ Please report all bugs immediately to the authors.
=head1 COPYRIGHT =head1 COPYRIGHT
Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 John F. Reiser
Copyright (C) 2002-2011 Jens Medoch Copyright (C) 2002-2013 Jens Medoch
This program may be used freely, and you are welcome to This program may be used freely, and you are welcome to
redistribute it under certain conditions. redistribute it under certain conditions.
+1 -1
View File
@@ -1,7 +1,7 @@
# #
# UPX Makefile - needs GNU make 3.81 or better # UPX Makefile - needs GNU make 3.81 or better
# #
# Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer # Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR MAKEFLAGS += -rR
+45 -45
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -88,7 +88,7 @@ inline void set_be32(void *p, unsigned v)
#endif #endif
} }
inline acc_uint64l_t get_be64(const void *p) inline upx_uint64_t get_be64(const void *p)
{ {
#if defined(ACC_UA_GET_BE64) #if defined(ACC_UA_GET_BE64)
return ACC_UA_GET_BE64(p); return ACC_UA_GET_BE64(p);
@@ -97,7 +97,7 @@ inline acc_uint64l_t get_be64(const void *p)
#endif #endif
} }
inline void set_be64(void *p, acc_uint64l_t v) inline void set_be64(void *p, upx_uint64_t v)
{ {
#if defined(ACC_UA_SET_BE64) #if defined(ACC_UA_SET_BE64)
ACC_UA_SET_BE64(p, v); ACC_UA_SET_BE64(p, v);
@@ -160,7 +160,7 @@ inline void set_le32(void *p, unsigned v)
#endif #endif
} }
inline acc_uint64l_t get_le64(const void *p) inline upx_uint64_t get_le64(const void *p)
{ {
#if defined(ACC_UA_GET_LE64) #if defined(ACC_UA_GET_LE64)
return ACC_UA_GET_LE64(p); return ACC_UA_GET_LE64(p);
@@ -169,7 +169,7 @@ inline acc_uint64l_t get_le64(const void *p)
#endif #endif
} }
inline void set_le64(void *p, acc_uint64l_t v) inline void set_le64(void *p, upx_uint64_t v)
{ {
#if defined(ACC_UA_SET_LE64) #if defined(ACC_UA_SET_LE64)
ACC_UA_SET_LE64(p, v); ACC_UA_SET_LE64(p, v);
@@ -192,13 +192,13 @@ inline int sign_extend(unsigned v, unsigned bits)
return (int) v; return (int) v;
} }
inline acc_int64l_t sign_extend(acc_uint64l_t v, unsigned bits) inline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits)
{ {
const acc_uint64l_t sign_bit = ACC_UINT64_C(1) << (bits - 1); const upx_uint64_t sign_bit = UPX_UINT64_C(1) << (bits - 1);
v &= sign_bit | (sign_bit - 1); v &= sign_bit | (sign_bit - 1);
//v = (v ^ sign_bit) - sign_bit; //v = (v ^ sign_bit) - sign_bit;
v |= 0 - (v & sign_bit); v |= 0 - (v & sign_bit);
return (acc_int64l_t) v; return (upx_int64_t) v;
} }
inline int get_be16_signed(const void *p) inline int get_be16_signed(const void *p)
@@ -219,9 +219,9 @@ inline int get_be32_signed(const void *p)
return sign_extend(v, 32); return sign_extend(v, 32);
} }
inline acc_int64l_t get_be64_signed(const void *p) inline upx_int64_t get_be64_signed(const void *p)
{ {
acc_uint64l_t v = get_be64(p); upx_uint64_t v = get_be64(p);
return sign_extend(v, 64); return sign_extend(v, 64);
} }
@@ -243,9 +243,9 @@ inline int get_le32_signed(const void *p)
return sign_extend(v, 32); return sign_extend(v, 32);
} }
inline acc_int64l_t get_le64_signed(const void *p) inline upx_int64_t get_le64_signed(const void *p)
{ {
acc_uint64l_t v = get_le64(p); upx_uint64_t v = get_le64(p);
return sign_extend(v, 64); return sign_extend(v, 64);
} }
@@ -269,25 +269,25 @@ inline unsigned acc_swab32(unsigned v)
} }
inline unsigned acc_swab16p(const acc_uint16e_t *p) inline unsigned acc_swab16p(const upx_uint16_t *p)
{ {
return acc_swab16(*p); return acc_swab16(*p);
} }
inline unsigned acc_swap32p(const acc_uint32e_t *p) inline unsigned acc_swap32p(const upx_uint32_t *p)
{ {
return acc_swab32(*p); return acc_swab32(*p);
} }
inline void acc_swab16s(acc_uint16e_t *p) inline void acc_swab16s(upx_uint16_t *p)
{ {
*p = (acc_uint16e_t) acc_swab16(*p); *p = (upx_uint16_t) acc_swab16(*p);
} }
inline void acc_swab32s(acc_uint32e_t *p) inline void acc_swab32s(upx_uint32_t *p)
{ {
*p = (acc_uint32e_t) acc_swab32(*p); *p = (upx_uint32_t) acc_swab32(*p);
} }
@@ -359,20 +359,20 @@ __packed_struct(BE64)
unsigned char d[8]; unsigned char d[8];
//inline BE64() { } //inline BE64() { }
//BE64(acc_uint64l_t v) { set_be64(d, v); } //BE64(upx_uint64_t v) { set_be64(d, v); }
BE64& operator = (acc_uint64l_t v) { set_be64(d, v); return *this; } BE64& operator = (upx_uint64_t v) { set_be64(d, v); return *this; }
BE64& operator += (acc_uint64l_t v) { set_be64(d, get_be64(d) + v); return *this; } BE64& operator += (upx_uint64_t v) { set_be64(d, get_be64(d) + v); return *this; }
BE64& operator -= (acc_uint64l_t v) { set_be64(d, get_be64(d) - v); return *this; } BE64& operator -= (upx_uint64_t v) { set_be64(d, get_be64(d) - v); return *this; }
BE64& operator *= (acc_uint64l_t v) { set_be64(d, get_be64(d) * v); return *this; } BE64& operator *= (upx_uint64_t v) { set_be64(d, get_be64(d) * v); return *this; }
BE64& operator /= (acc_uint64l_t v) { set_be64(d, get_be64(d) / v); return *this; } BE64& operator /= (upx_uint64_t v) { set_be64(d, get_be64(d) / v); return *this; }
BE64& operator &= (acc_uint64l_t v) { set_be64(d, get_be64(d) & v); return *this; } BE64& operator &= (upx_uint64_t v) { set_be64(d, get_be64(d) & v); return *this; }
BE64& operator |= (acc_uint64l_t v) { set_be64(d, get_be64(d) | v); return *this; } BE64& operator |= (upx_uint64_t v) { set_be64(d, get_be64(d) | v); return *this; }
BE64& operator ^= (acc_uint64l_t v) { set_be64(d, get_be64(d) ^ v); return *this; } BE64& operator ^= (upx_uint64_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; } BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; }
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; } BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
operator acc_uint64l_t () const { return get_be64(d); } operator upx_uint64_t () const { return get_be64(d); }
__packed_struct_end() __packed_struct_end()
@@ -422,20 +422,20 @@ __packed_struct(LE64)
unsigned char d[8]; unsigned char d[8];
//inline LE64() { } //inline LE64() { }
//LE64(acc_uint64l_t v) { set_le64(d, v); } //LE64(upx_uint64_t v) { set_le64(d, v); }
LE64& operator = (acc_uint64l_t v) { set_le64(d, v); return *this; } LE64& operator = (upx_uint64_t v) { set_le64(d, v); return *this; }
LE64& operator += (acc_uint64l_t v) { set_le64(d, get_le64(d) + v); return *this; } LE64& operator += (upx_uint64_t v) { set_le64(d, get_le64(d) + v); return *this; }
LE64& operator -= (acc_uint64l_t v) { set_le64(d, get_le64(d) - v); return *this; } LE64& operator -= (upx_uint64_t v) { set_le64(d, get_le64(d) - v); return *this; }
LE64& operator *= (acc_uint64l_t v) { set_le64(d, get_le64(d) * v); return *this; } LE64& operator *= (upx_uint64_t v) { set_le64(d, get_le64(d) * v); return *this; }
LE64& operator /= (acc_uint64l_t v) { set_le64(d, get_le64(d) / v); return *this; } LE64& operator /= (upx_uint64_t v) { set_le64(d, get_le64(d) / v); return *this; }
LE64& operator &= (acc_uint64l_t v) { set_le64(d, get_le64(d) & v); return *this; } LE64& operator &= (upx_uint64_t v) { set_le64(d, get_le64(d) & v); return *this; }
LE64& operator |= (acc_uint64l_t v) { set_le64(d, get_le64(d) | v); return *this; } LE64& operator |= (upx_uint64_t v) { set_le64(d, get_le64(d) | v); return *this; }
LE64& operator ^= (acc_uint64l_t v) { set_le64(d, get_le64(d) ^ v); return *this; } LE64& operator ^= (upx_uint64_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; } LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; }
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; } LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
operator acc_uint64l_t () const { return get_le64(d); } operator upx_uint64_t () const { return get_le64(d); }
__packed_struct_end() __packed_struct_end()
@@ -545,8 +545,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
// just for testing... // just for testing...
#if !(ACC_CFG_NO_UNALIGNED) #if !(ACC_CFG_NO_UNALIGNED)
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200) #if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200)
typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1))); typedef upx_uint16_t LE16_unaligned __attribute__((__aligned__(1)));
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1))); typedef upx_uint32_t LE32_unaligned __attribute__((__aligned__(1)));
# ifndef LE16 # ifndef LE16
# define LE16 LE16_unaligned # define LE16 LE16_unaligned
# endif # endif
@@ -555,8 +555,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
# endif # endif
#endif #endif
#if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC) #if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC)
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned; typedef __declspec(align(1)) upx_uint16_t LE16_unaligned;
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned; typedef __declspec(align(1)) upx_uint32_t LE32_unaligned;
# ifndef LE16 # ifndef LE16
# define LE16 LE16_unaligned # define LE16 LE16_unaligned
# endif # endif
@@ -565,8 +565,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
# endif # endif
#endif #endif
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200) #if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned; typedef __declspec(align(1)) upx_uint16_t LE16_unaligned;
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned; typedef __declspec(align(1)) upx_uint32_t LE32_unaligned;
# ifndef LE16 # ifndef LE16
# define LE16 LE16_unaligned # define LE16 LE16_unaligned
# endif # endif
+14 -14
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -61,17 +61,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 unsigned get16_signed(const void *p) C = 0;
V unsigned get24_signed(const void *p) C = 0; V unsigned get24_signed(const void *p) C = 0;
V unsigned get32_signed(const void *p) C = 0; V unsigned get32_signed(const void *p) C = 0;
V acc_uint64l_t get64_signed(const void *p) C = 0; V upx_uint64_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;
@@ -113,7 +113,7 @@ struct BEPolicy
{ return get_be24(p); } { return get_be24(p); }
V unsigned get32(const void *p) C V unsigned get32(const void *p) C
{ return get_be32(p); } { return get_be32(p); }
V acc_uint64l_t get64(const void *p) C V upx_uint64_t get64(const void *p) C
{ return get_be64(p); } { return get_be64(p); }
V void set16(void *p, unsigned v) C V void set16(void *p, unsigned v) C
@@ -122,7 +122,7 @@ struct BEPolicy
{ set_be24(p, v); } { set_be24(p, v); }
V void set32(void *p, unsigned v) C V void set32(void *p, unsigned v) C
{ set_be32(p, v); } { set_be32(p, v); }
V void set64(void *p, acc_uint64l_t v) C V void set64(void *p, upx_uint64_t v) C
{ set_be64(p, v); } { set_be64(p, v); }
V unsigned get16_signed(const void *p) C V unsigned get16_signed(const void *p) C
@@ -131,7 +131,7 @@ struct BEPolicy
{ return get_be24_signed(p); } { return get_be24_signed(p); }
V unsigned get32_signed(const void *p) C V unsigned get32_signed(const void *p) C
{ return get_be32_signed(p); } { return get_be32_signed(p); }
V acc_uint64l_t get64_signed(const void *p) C V upx_uint64_t get64_signed(const void *p) C
{ return get_be64_signed(p); } { 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
@@ -190,7 +190,7 @@ struct LEPolicy
{ return get_le24(p); } { return get_le24(p); }
V unsigned get32(const void *p) C V unsigned get32(const void *p) C
{ return get_le32(p); } { return get_le32(p); }
V acc_uint64l_t get64(const void *p) C V upx_uint64_t get64(const void *p) C
{ return get_le64(p); } { return get_le64(p); }
V void set16(void *p, unsigned v) C V void set16(void *p, unsigned v) C
@@ -199,7 +199,7 @@ struct LEPolicy
{ set_le24(p, v); } { set_le24(p, v); }
V void set32(void *p, unsigned v) C V void set32(void *p, unsigned v) C
{ set_le32(p, v); } { set_le32(p, v); }
V void set64(void *p, acc_uint64l_t v) C V void set64(void *p, upx_uint64_t v) C
{ set_le64(p, v); } { set_le64(p, v); }
V unsigned get16_signed(const void *p) C V unsigned get16_signed(const void *p) C
@@ -208,7 +208,7 @@ struct LEPolicy
{ return get_le24_signed(p); } { return get_le24_signed(p); }
V unsigned get32_signed(const void *p) C V unsigned get32_signed(const void *p) C
{ return get_le32_signed(p); } { return get_le32_signed(p); }
V acc_uint64l_t get64_signed(const void *p) C V upx_uint64_t get64_signed(const void *p) C
{ return get_le64_signed(p); } { 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
@@ -259,9 +259,9 @@ struct HostAlignedPolicy
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)
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+7 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -230,6 +230,7 @@ error:
**************************************************************************/ **************************************************************************/
#if (WITH_LZMA >= 0x461) #if (WITH_LZMA >= 0x461)
#define _7ZIP_ST 1
#define kLiteralNextStates kLiteralNextStates_enc #define kLiteralNextStates kLiteralNextStates_enc
#include "C/LzmaEnc.h" #include "C/LzmaEnc.h"
#include "C/LzmaEnc.c" #include "C/LzmaEnc.c"
@@ -352,6 +353,7 @@ namespace MyLzma {
struct InStream: public ISequentialInStream, public CMyUnknownImp struct InStream: public ISequentialInStream, public CMyUnknownImp
{ {
virtual ~InStream() { }
MY_UNKNOWN_IMP MY_UNKNOWN_IMP
const Byte *b_buf; size_t b_size; size_t b_pos; const Byte *b_buf; size_t b_size; size_t b_pos;
void Init(const Byte *data, size_t size) { void Init(const Byte *data, size_t size) {
@@ -372,6 +374,7 @@ STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
struct OutStream : public ISequentialOutStream, public CMyUnknownImp struct OutStream : public ISequentialOutStream, public CMyUnknownImp
{ {
virtual ~OutStream() { }
MY_UNKNOWN_IMP MY_UNKNOWN_IMP
Byte *b_buf; size_t b_size; size_t b_pos; bool overflow; Byte *b_buf; size_t b_size; size_t b_pos; bool overflow;
void Init(Byte *data, size_t size) { void Init(Byte *data, size_t size) {
@@ -397,6 +400,7 @@ STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSi
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
{ {
virtual ~ProgressInfo() { }
MY_UNKNOWN_IMP MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
upx_callback_p cb; upx_callback_p cb;
@@ -412,7 +416,7 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
} // namespace } // namespace
#if (ACC_CC_INTELC) && defined(__linux__) #if (ACC_CC_INTELC_GNUC)
# pragma warning(disable: 424) // #424: extra ";" ignored # pragma warning(disable: 424) // #424: extra ";" ignored
#endif #endif
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+28 -14
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -149,6 +149,23 @@
# endif # endif
#endif #endif
/* intergral types */
typedef acc_int8_t upx_int8_t;
typedef acc_uint8_t upx_uint8_t;
typedef acc_int16_t upx_int16_t;
typedef acc_uint16_t upx_uint16_t;
typedef acc_int32_t upx_int32_t;
typedef acc_uint32_t upx_uint32_t;
typedef acc_int64_t upx_int64_t;
typedef acc_uint64_t upx_uint64_t;
typedef acc_uintptr_t upx_uintptr_t;
#define UPX_INT16_C ACC_INT16_C
#define UPX_UINT16_C ACC_UINT16_C
#define UPX_INT32_C ACC_INT32_C
#define UPX_UINT32_C ACC_UINT32_C
#define UPX_INT64_C ACC_INT64_C
#define UPX_UINT64_C ACC_UINT64_C
/************************************************************************* /*************************************************************************
// //
@@ -222,19 +239,14 @@
#if (WITH_VALGRIND) #if (WITH_VALGRIND)
# include <valgrind/memcheck.h> # include <valgrind/memcheck.h>
#endif #endif
#if !defined(VALGRIND_MAKE_MEM_DEFINED)
#if !defined(VALGRIND_MAKE_WRITABLE) # define VALGRIND_MAKE_MEM_DEFINED(addr,len) 0
# define VALGRIND_MAKE_WRITABLE(addr,len) 0
#endif #endif
#if !defined(VALGRIND_MAKE_READABLE) #if !defined(VALGRIND_MAKE_MEM_NOACCESS)
# if 0 # define VALGRIND_MAKE_MEM_NOACCESS(addr,len) 0
# define VALGRIND_MAKE_READABLE(addr,len) (memset(addr,0,len), 0)
# else
# define VALGRIND_MAKE_READABLE(addr,len) 0
# endif
#endif #endif
#if !defined(VALGRIND_DISCARD) #if !defined(VALGRIND_MAKE_MEM_UNDEFINED)
# define VALGRIND_DISCARD(handle) ((void)(&handle)) # define VALGRIND_MAKE_MEM_UNDEFINED(addr,len) 0
#endif #endif
@@ -326,7 +338,7 @@
#if (ACC_CC_INTELC && (__INTEL_COMPILER < 800)) #if (ACC_CC_INTELC && (__INTEL_COMPILER < 800))
#elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386)) #elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
#elif (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) #elif (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC_GNUC || ACC_CC_PATHSCALE)
# define __packed_struct(s) struct s { # define __packed_struct(s) struct s {
# define __packed_struct_end() } __attribute__((__packed__,__aligned__(1))); # define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
#elif (ACC_CC_WATCOMC) #elif (ACC_CC_WATCOMC)
@@ -492,6 +504,8 @@ private:
#define UPX_F_MACH_AMD64 34 #define UPX_F_MACH_AMD64 34
#define UPX_F_DYLIB_AMD64 35 #define UPX_F_DYLIB_AMD64 35
#define UPX_F_WIN64_PEP 36
#define UPX_F_PLAIN_TEXT 127 #define UPX_F_PLAIN_TEXT 127
#define UPX_F_ATARI_TOS 129 #define UPX_F_ATARI_TOS 129
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+6 -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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -33,7 +33,7 @@
// //
**************************************************************************/ **************************************************************************/
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) NOTHROW
: super(), msg(NULL), err(e), is_warning(w) : super(), msg(NULL), err(e), is_warning(w)
@@ -41,7 +41,7 @@ Throwable::Throwable(const char *m, int e, bool w) NOTHROW
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
} }
@@ -53,7 +53,7 @@ Throwable::Throwable(const Throwable &other) NOTHROW
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
} }
@@ -63,7 +63,7 @@ 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);
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -62,7 +62,7 @@ private:
DISABLE_NEW_DELETE DISABLE_NEW_DELETE
private: private:
static long counter; // for debugging static unsigned long counter; // for debugging
}; };
+12 -17
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -410,21 +410,16 @@ void OutputFile::seek(off_t off, int whence)
super::seek(off,whence); super::seek(off,whence);
} }
int OutputFile::read(void *buf, int len) // WARNING: fsync() does not exist in some Windows environments.
{ // This trick works only on UNIX-like systems.
InputFile infile; //int OutputFile::read(void *buf, int len)
infile.open(this->getName(), O_RDONLY); //{
infile.seek(this->tell(), SEEK_SET); // fsync(_fd);
return infile.read(buf, len); // InputFile infile;
} // infile.open(this->getName(), O_RDONLY);
// infile.seek(this->tell(), SEEK_SET);
int OutputFile::readx(void *buf, int len) // return infile.read(buf, len);
{ //}
InputFile infile;
infile.open(this->getName(), O_RDONLY);
infile.seek(this->tell(), SEEK_SET);
return infile.readx(buf, len);
}
void OutputFile::set_extent(off_t offset, off_t length) void OutputFile::set_extent(off_t offset, off_t length)
{ {
+2 -4
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -141,8 +141,6 @@ public:
// 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); virtual void seek(off_t off, int whence);
virtual void rewrite(const void *buf, int len); virtual void rewrite(const void *buf, int len);
virtual int read(void *buf, int len);
virtual int readx(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, const void *buf, int len, int flags=-1);
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+5 -5
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2004-2011 John F. Reiser Copyright (C) 2004-2013 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
@@ -98,7 +98,7 @@ static int F(Filter *f)
} }
else { else {
#if (W_CTO != 0) #if (W_CTO != 0)
assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != (unsigned) cto8); // this should not happen
#endif #endif
lastnoncall = ic; lastnoncall = ic;
noncalls++; noncalls++;
@@ -133,7 +133,7 @@ static int U(Filter *f)
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) { for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
unsigned const word = get_be32(b+ic); unsigned const word = get_be32(b+ic);
if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == f->cto) { if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == (unsigned) f->cto) {
unsigned const jc = word & (~(~0u<<(26 - W_CTO)) & (~0u<<2)); unsigned const jc = word & (~(~0u<<(26 - W_CTO)) & (~0u<<2));
set_be32(b+ic, (0xfc000003&word)|(0x03fffffc&(jc-ic-addvalue))); set_be32(b+ic, (0xfc000003&word)|(0x03fffffc&(jc-ic-addvalue)));
f->calls++; f->calls++;
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+11 -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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -290,6 +290,11 @@ 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");
con_fprintf(f,"Options for linux/elf:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --preserve-build-id copy .gnu.note.build-id to compressed output\n"
"\n");
} }
con_fprintf(f, "file.. executables to (de)compress\n"); con_fprintf(f, "file.. executables to (de)compress\n");
@@ -400,10 +405,10 @@ void show_version(int x)
if (v != NULL && v[0]) if (v != NULL && 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-2011 Markus Franz Xaver Johannes Oberhumer\n"); fprintf(fp, "Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(fp, "Copyright (C) 1996-2011 Laszlo Molnar\n"); fprintf(fp, "Copyright (C) 1996-2013 Laszlo Molnar\n");
fprintf(fp, "Copyright (C) 2000-2011 John F. Reiser\n"); fprintf(fp, "Copyright (C) 2000-2013 John F. Reiser\n");
fprintf(fp, "Copyright (C) 2002-2011 Jens Medoch\n"); fprintf(fp, "Copyright (C) 2002-2013 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" "-2005 Jean-loup Gailly and Mark Adler\n");
#endif #endif
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+47 -39
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -84,7 +84,7 @@ ElfLinker::Section::~Section()
// Symbol // Symbol
**************************************************************************/ **************************************************************************/
ElfLinker::Symbol::Symbol(const char *n, Section *s, unsigned o) : ElfLinker::Symbol::Symbol(const char *n, Section *s, upx_uint64_t o) :
name(NULL), section(s), offset(o) name(NULL), section(s), offset(o)
{ {
name = strdup(n); name = strdup(n);
@@ -103,7 +103,7 @@ ElfLinker::Symbol::~Symbol()
**************************************************************************/ **************************************************************************/
ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t, ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t,
const Symbol *v, unsigned a) : const Symbol *v, upx_uint64_t a) :
section(s), offset(o), type(t), value(v), add(a) section(s), offset(o), type(t), value(v), add(a)
{ {
assert(section != NULL); assert(section != NULL);
@@ -294,29 +294,28 @@ void ElfLinker::preprocessRelocations(char *start, char *end)
char *t = strstr(start, type); char *t = strstr(start, type);
t[strlen(type)] = 0; t[strlen(type)] = 0;
unsigned add = 0; upx_uint64_t add = 0;
if (char *p = strstr(symbol, "+0x")) char *p = strstr(symbol, "+0x");
if (p == NULL)
p = strstr(symbol, "-0x");
if (p)
{ {
char sign = *p;
*p = 0; // terminate the symbol name *p = 0; // terminate the symbol name
p += 3; p += 3;
if (strlen(p) == 16) { assert(strlen(p) == 8 || strlen(p) == 16);
// skip 8 leading chars if sign of char 9 matches
if (memcmp(p, "000000000", 9))
p += 8;
else if (memcmp(p, "fffffffff", 9))
p += 8;
}
assert(strlen(p) == 8);
char *endptr = NULL; char *endptr = NULL;
unsigned long ul = strtoul(p, &endptr, 16); upx_uint64_t ull = strtoull(p, &endptr, 16);
add = (unsigned) ul; add = (upx_uint64_t) ull;
assert(add == ul); assert(add == ull);
assert(endptr && *endptr == '\0'); assert(endptr && *endptr == '\0');
if (sign == '-')
add = -add;
} }
addRelocation(section->name, offset, t, symbol, add); addRelocation(section->name, offset, t, symbol, add);
//printf("relocation %s %s %x %d preprocessed\n", section->name, symbol, offset, add); //printf("relocation %s %s %x %llu preprocessed\n", section->name, symbol, offset, (unsigned long long) add);
} }
start = nextl + 1; start = nextl + 1;
@@ -357,7 +356,7 @@ ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata,
} }
ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section, ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
unsigned offset) upx_uint64_t offset)
{ {
//printf("addSymbol: %s %s 0x%x\n", name, section, offset); //printf("addSymbol: %s %s 0x%x\n", name, section, offset);
if (update_capacity(nsymbols, &nsymbols_capacity)) if (update_capacity(nsymbols, &nsymbols_capacity))
@@ -372,7 +371,7 @@ ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned off, ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned off,
const char *type, const char *symbol, const char *type, const char *symbol,
unsigned add) upx_uint64_t add)
{ {
if (update_capacity(nrelocations, &nrelocations_capacity)) if (update_capacity(nrelocations, &nrelocations_capacity))
relocations = static_cast<Relocation **>(realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *))); relocations = static_cast<Relocation **>(realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *)));
@@ -498,7 +497,7 @@ void ElfLinker::relocate()
for (unsigned ic = 0; ic < nrelocations; ic++) for (unsigned ic = 0; ic < nrelocations; ic++)
{ {
const Relocation *rel = relocations[ic]; const Relocation *rel = relocations[ic];
unsigned value = 0; upx_uint64_t value = 0;
if (rel->section->output == NULL) if (rel->section->output == NULL)
continue; continue;
@@ -519,13 +518,13 @@ void ElfLinker::relocate()
rel->value->offset + rel->add; rel->value->offset + rel->add;
} }
upx_byte *location = rel->section->output + rel->offset; upx_byte *location = rel->section->output + rel->offset;
//printf("%-28s %-28s %-10s 0x%08x 0x%08x\n", rel->section->name, rel->value->name, rel->type, value, value - rel->section->offset - rel->offset); //printf("%-28s %-28s %-10s 0x%16llx 0x%16llx\n", rel->section->name, rel->value->name, rel->type, (long long) value, (long long) value - rel->section->offset - rel->offset);
//printf(" %d %d %d %d %d : %d\n", value, rel->value->section->offset, rel->value->offset, rel->offset, rel->add, *location); //printf(" %llx %d %llx %d %llx : %d\n", (long long) value, rel->value->section->offset, rel->value->offset, rel->offset, (long long) rel->add, *location);
relocate1(rel, location, value, rel->type); relocate1(rel, location, value, rel->type);
} }
} }
void ElfLinker::defineSymbol(const char *name, unsigned value) void ElfLinker::defineSymbol(const char *name, upx_uint64_t value)
{ {
Symbol *symbol = findSymbol(name); Symbol *symbol = findSymbol(name);
if (strcmp(symbol->section->name, "*ABS*") == 0) if (strcmp(symbol->section->name, "*ABS*") == 0)
@@ -550,8 +549,11 @@ void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const
{ {
if ((flags & 1) && symbol->section->output == NULL) if ((flags & 1) && symbol->section->output == NULL)
return; return;
fprintf(fp, "%-28s 0x%08x | %-28s 0x%08x\n", char d0[16+1], d1[16+1];
symbol->name, symbol->offset, symbol->section->name, symbol->section->offset); upx_snprintf(d0, sizeof(d0), "%016llx", (upx_uint64_t) symbol->offset);
upx_snprintf(d1, sizeof(d1), "%016llx", (upx_uint64_t) symbol->section->offset);
fprintf(fp, "%-28s 0x%-16s | %-28s 0x%-16s\n",
symbol->name, d0, symbol->section->name, d1);
} }
void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
{ {
@@ -562,7 +564,9 @@ void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
// default: dump symbols in used section order // default: dump symbols in used section order
for (const Section *section = head; section; section = section->next) for (const Section *section = head; section; section = section->next)
{ {
fprintf(fp, "%-42s%-28s 0x%08x\n", "", section->name, section->offset); char d1[16+1];
upx_snprintf(d1, sizeof(d1), "%016llx", (upx_uint64_t) section->offset);
fprintf(fp, "%-42s%-28s 0x%-16s\n", "", section->name, d1);
for (unsigned ic = 0; ic < nsymbols; ic++) for (unsigned ic = 0; ic < nsymbols; ic++)
{ {
const Symbol *symbol = symbols[ic]; const Symbol *symbol = symbols[ic];
@@ -579,7 +583,7 @@ void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
} }
} }
unsigned ElfLinker::getSymbolOffset(const char *name) const upx_uint64_t ElfLinker::getSymbolOffset(const char *name) const
{ {
const Symbol *symbol = findSymbol(name); const Symbol *symbol = findSymbol(name);
if (symbol->section->output == NULL) if (symbol->section->output == NULL)
@@ -594,7 +598,7 @@ void ElfLinker::alignWithByte(unsigned len, unsigned char b)
} }
void ElfLinker::relocate1(const Relocation *rel, upx_byte *, void ElfLinker::relocate1(const Relocation *rel, upx_byte *,
unsigned, const char *) upx_uint64_t, const char *)
{ {
internal_error("unknown relocation type '%s\n", rel->type); internal_error("unknown relocation type '%s\n", rel->type);
} }
@@ -620,16 +624,18 @@ static void check8(const Relocation *rel, const upx_byte *location, int v, int d
void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
if (strncmp(type, "R_X86_64_", 9)) if (strncmp(type, "R_X86_64_", 9))
return super::relocate1(rel, location, value, type); return super::relocate1(rel, location, value, type);
type += 9; type += 9;
bool range_check = false;
if (strncmp(type, "PC", 2) == 0) if (strncmp(type, "PC", 2) == 0)
{ {
value -= rel->section->offset + rel->offset; value -= rel->section->offset + rel->offset;
type += 2; type += 2;
range_check = true;
} }
if (strcmp(type, "8") == 0) if (strcmp(type, "8") == 0)
@@ -639,22 +645,24 @@ void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location,
#else #else
int displ = (signed char) *location + (int) value; int displ = (signed char) *location + (int) value;
#endif #endif
if (displ < -128 || displ > 127) if (range_check && (displ < -128 || displ > 127))
internal_error("target out of range (%d) in reloc %s:%x\n", internal_error("target out of range (%d) in reloc %s:%x\n",
displ, rel->section->name, rel->offset); displ, rel->section->name, rel->offset);
*location += value; *location += value;
} }
else if (strcmp(type, "16") == 0) else if (strcmp(type, "16") == 0)
set_le16(location, get_le16(location) + value); set_le16(location, get_le16(location) + value);
else if (strcmp(type, "32") == 0) else if (strncmp(type, "32", 2) == 0) // for "32" and "32S"
set_le32(location, get_le32(location) + value); set_le32(location, get_le32(location) + value);
else if (strcmp(type, "64") == 0)
set_le64(location, get_le64(location) + value);
else else
super::relocate1(rel, location, value, type); super::relocate1(rel, location, value, type);
} }
void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
if (strcmp(type, "R_ARM_PC24") == 0) if (strcmp(type, "R_ARM_PC24") == 0)
{ {
@@ -689,7 +697,7 @@ void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
if (strcmp(type, "R_ARM_PC24") == 0) if (strcmp(type, "R_ARM_PC24") == 0)
{ {
@@ -733,7 +741,7 @@ void ElfLinkerM68k::alignCode(unsigned len)
} }
void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
if (strncmp(type, "R_68K_", 6)) if (strncmp(type, "R_68K_", 6))
return super::relocate1(rel, location, value, type); return super::relocate1(rel, location, value, type);
@@ -759,7 +767,7 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15)) #define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
#define MIPS_LO(a) ((a) & 0xffff) #define MIPS_LO(a) ((a) & 0xffff)
@@ -790,7 +798,7 @@ void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location,
void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15)) #define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
#define MIPS_LO(a) ((a) & 0xffff) #define MIPS_LO(a) ((a) & 0xffff)
@@ -821,7 +829,7 @@ void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location,
void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
if (strncmp(type, "R_PPC_", 6)) if (strncmp(type, "R_PPC_", 6))
return super::relocate1(rel, location, value, type); return super::relocate1(rel, location, value, type);
@@ -862,7 +870,7 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) upx_uint64_t value, const char *type)
{ {
if (strncmp(type, "R_386_", 6)) if (strncmp(type, "R_386_", 6))
return super::relocate1(rel, location, value, type); return super::relocate1(rel, location, value, type);
+26 -26
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -72,9 +72,9 @@ protected:
Section *findSection(const char *name, bool fatal=true) const; Section *findSection(const char *name, bool fatal=true) const;
Symbol *findSymbol(const char *name, bool fatal=true) const; Symbol *findSymbol(const char *name, bool fatal=true) const;
Symbol *addSymbol(const char *name, const char *section, unsigned offset); Symbol *addSymbol(const char *name, const char *section, upx_uint64_t offset);
Relocation *addRelocation(const char *section, unsigned off, const char *type, Relocation *addRelocation(const char *section, unsigned off, const char *type,
const char *symbol, unsigned add); const char *symbol, upx_uint64_t add);
public: public:
ElfLinker(); ElfLinker();
@@ -93,8 +93,8 @@ public:
virtual int getSection(const char *sname, int *slen=NULL) const; virtual int getSection(const char *sname, int *slen=NULL) const;
virtual int getSectionSize(const char *sname) const; virtual int getSectionSize(const char *sname) const;
virtual upx_byte *getLoader(int *llen=NULL) const; virtual upx_byte *getLoader(int *llen=NULL) const;
virtual void defineSymbol(const char *name, unsigned value); virtual void defineSymbol(const char *name, upx_uint64_t value);
virtual unsigned getSymbolOffset(const char *) const; virtual upx_uint64_t getSymbolOffset(const char *) const;
virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const; virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const;
virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const; virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const;
@@ -106,15 +106,15 @@ public:
protected: protected:
virtual void relocate(); virtual void relocate();
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
// target endianness abstraction // target endianness abstraction
unsigned get_te16(const void *p) const { return bele->get16(p); } unsigned get_te16(const void *p) const { return bele->get16(p); }
unsigned get_te32(const void *p) const { return bele->get32(p); } unsigned get_te32(const void *p) const { return bele->get32(p); }
acc_uint64l_t get_te64(const void *p) const { return bele->get64(p); } upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
void set_te16(void *p, unsigned v) const { bele->set16(p, v); } void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
void set_te32(void *p, unsigned v) const { bele->set32(p, v); } void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
void set_te64(void *p, acc_uint64l_t v) const { bele->set64(p, v); } void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
}; };
@@ -124,7 +124,7 @@ struct ElfLinker::Section : private noncopyable
void *input; void *input;
upx_byte *output; upx_byte *output;
unsigned size; unsigned size;
unsigned offset; upx_uint64_t offset;
unsigned p2align; // log2 unsigned p2align; // log2
Section *next; Section *next;
@@ -137,9 +137,9 @@ struct ElfLinker::Symbol : private noncopyable
{ {
char *name; char *name;
Section *section; Section *section;
unsigned offset; upx_uint64_t offset;
Symbol(const char *n, Section *s, unsigned o); Symbol(const char *n, Section *s, upx_uint64_t o);
~Symbol(); ~Symbol();
}; };
@@ -150,10 +150,10 @@ struct ElfLinker::Relocation : private noncopyable
unsigned offset; unsigned offset;
const char *type; const char *type;
const Symbol *value; const Symbol *value;
unsigned add; // used in .rela relocations upx_uint64_t add; // used in .rela relocations
Relocation(const Section *s, unsigned o, const char *t, Relocation(const Section *s, unsigned o, const char *t,
const Symbol *v, unsigned a); const Symbol *v, upx_uint64_t a);
}; };
@@ -167,7 +167,7 @@ class ElfLinkerAMD64 : public ElfLinker
protected: protected:
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); } virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
@@ -178,7 +178,7 @@ public:
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; } ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
protected: protected:
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
@@ -187,7 +187,7 @@ class ElfLinkerArmLE : public ElfLinker
typedef ElfLinker super; typedef ElfLinker super;
protected: protected:
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
@@ -199,7 +199,7 @@ public:
protected: protected:
virtual void alignCode(unsigned len); virtual void alignCode(unsigned len);
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
@@ -210,7 +210,7 @@ public:
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; } ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
protected: protected:
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
@@ -219,7 +219,7 @@ class ElfLinkerMipsLE : public ElfLinker
typedef ElfLinker super; typedef ElfLinker super;
protected: protected:
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
@@ -230,7 +230,7 @@ public:
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; } ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
protected: protected:
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
@@ -240,7 +240,7 @@ class ElfLinkerX86 : public ElfLinker
protected: protected:
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); } virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
virtual void relocate1(const Relocation *, upx_byte *location, virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type); upx_uint64_t value, const char *type);
}; };
+8 -4
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -898,6 +898,9 @@ static int do_option(int optc, const char *arg)
case 674: case 674:
opt->o_unix.unmap_all_pages = true; // val ? opt->o_unix.unmap_all_pages = true; // val ?
break; break;
case 675:
opt->o_unix.preserve_build_id = true;
break;
case '\0': case '\0':
return -1; return -1;
@@ -1048,6 +1051,7 @@ static const struct mfx_option longopts[] =
{"OpenBSD", 0x10, 0, 669}, {"OpenBSD", 0x10, 0, 669},
{"openbsd", 0x10, 0, 669}, {"openbsd", 0x10, 0, 669},
{"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes {"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes
{"preserve-build-id", 0, 0, 675},
// watcom/le // watcom/le
{"le", 0x10, 0, 620}, // produce LE output {"le", 0x10, 0, 620}, // produce LE output
// win32/pe // win32/pe
@@ -1404,7 +1408,7 @@ void upx_sanity_check(void)
assert(get_le32(d) == 0xfcfdfeff); assert(get_le32(d) == 0xfcfdfeff);
assert(bele->get32(d) == 0xfcfdfeff); assert(bele->get32(d) == 0xfcfdfeff);
assert(get_le32_signed(d) == -50462977); assert(get_le32_signed(d) == -50462977);
assert(get_le64_signed(d) == ACC_INT64_C(-506097522914230529)); assert(get_le64_signed(d) == UPX_INT64_C(-506097522914230529));
assert(find_be16(d, 2, 0xfffe) == 0); assert(find_be16(d, 2, 0xfffe) == 0);
assert(find_le16(d, 2, 0xfeff) == 0); assert(find_le16(d, 2, 0xfeff) == 0);
assert(find_be32(d, 4, 0xfffefdfc) == 0); assert(find_be32(d, 4, 0xfffefdfc) == 0);
@@ -1413,7 +1417,7 @@ void upx_sanity_check(void)
assert(get_be16_signed(d) == 32638); assert(get_be16_signed(d) == 32638);
assert(get_be24_signed(d) == 8355453); assert(get_be24_signed(d) == 8355453);
assert(get_be32_signed(d) == 2138996092); assert(get_be32_signed(d) == 2138996092);
assert(get_be64_signed(d) == ACC_INT64_C(9186918263483431288)); assert(get_be64_signed(d) == UPX_INT64_C(9186918263483431288));
} }
#endif #endif
} }
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -154,7 +154,7 @@ void MemBuffer::fill(unsigned off, unsigned len, int value)
// //
**************************************************************************/ **************************************************************************/
#define PTR(p) ((unsigned) ((acc_uintptr_t)(p) & 0xffffffff)) #define PTR(p) ((unsigned) ((upx_uintptr_t)(p) & 0xffffffff))
#define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb) #define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb)
#define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001) #define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001)
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+1663 -1478
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+3 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -146,6 +146,7 @@ struct options_t {
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI] unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
enum { SCRIPT_MAX = 32 }; enum { SCRIPT_MAX = 32 };
const char *script_name; const char *script_name;
bool preserve_build_id; // copy the build-id to the compressed binary
} o_unix; } o_unix;
struct { struct {
bool le; bool le;
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -599,7 +599,7 @@ void PackArmPe::pack(OutputFile *fo)
if (((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED)) if (((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED))
== (PEFL_WRITE|PEFL_SHARED))) == (PEFL_WRITE|PEFL_SHARED)))
if (!opt->force) if (!opt->force)
throwCantPack("writeable shared sections not supported (try --force)"); throwCantPack("writable shared sections not supported (try --force)");
if (jc && isection[ic].rawdataptr - jc > ih.filealign) if (jc && isection[ic].rawdataptr - jc > ih.filealign)
throwCantPack("superfluous data between sections"); throwCantPack("superfluous data between sections");
fi->seek(isection[ic].rawdataptr,SEEK_SET); fi->seek(isection[ic].rawdataptr,SEEK_SET);
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+322 -105
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
@@ -51,14 +51,20 @@
static unsigned const EF_ARM_EABI_VER4 = 0x04000000; static unsigned const EF_ARM_EABI_VER4 = 0x04000000;
static unsigned const EF_ARM_EABI_VER5 = 0x05000000; static unsigned const EF_ARM_EABI_VER5 = 0x05000000;
unsigned char PackLinuxElf::o_shstrtab[] = { \
/*start*/ '\0',
/*offset 1*/ '.','n','o','t','e','.','g','n','u','.','b','u','i','l','d','-','i','d','\0',
/*offset 20*/ '.','s','h','s','t','r','t','a','b','\0'
};
static unsigned static unsigned
umin(unsigned a, unsigned b) umin(unsigned a, unsigned b)
{ {
return (a < b) ? a : b; return (a < b) ? a : b;
} }
static acc_uint64l_t static upx_uint64_t
umin64(acc_uint64l_t a, acc_uint64l_t b) umin64(upx_uint64_t a, upx_uint64_t b)
{ {
return (a < b) ? a : b; return (a < b) ? a : b;
} }
@@ -79,6 +85,15 @@ fpad4(OutputFile *fo)
return d + len; return d + len;
} }
static unsigned
funpad4(InputFile *fi)
{
unsigned d = 3u & (0 - fi->tell());
if (d)
fi->seek(d, SEEK_CUR);
return d;
}
int int
PackLinuxElf32::checkEhdr(Elf32_Ehdr const *ehdr) const PackLinuxElf32::checkEhdr(Elf32_Ehdr const *ehdr) const
{ {
@@ -96,7 +111,7 @@ PackLinuxElf32::checkEhdr(Elf32_Ehdr const *ehdr) const
int const type = get_te16(&ehdr->e_type); int const type = get_te16(&ehdr->e_type);
if (type != Elf32_Ehdr::ET_EXEC && type != Elf32_Ehdr::ET_DYN) if (type != Elf32_Ehdr::ET_EXEC && type != Elf32_Ehdr::ET_DYN)
return 2; return 2;
if (get_te16(&ehdr->e_machine) != e_machine) if (get_te16(&ehdr->e_machine) != (unsigned) e_machine)
return 3; return 3;
if (get_te32(&ehdr->e_version) != Elf32_Ehdr::EV_CURRENT) if (get_te32(&ehdr->e_version) != Elf32_Ehdr::EV_CURRENT)
return 4; return 4;
@@ -129,7 +144,7 @@ int
PackLinuxElf64::checkEhdr(Elf64_Ehdr const *ehdr) const PackLinuxElf64::checkEhdr(Elf64_Ehdr const *ehdr) const
{ {
const unsigned char * const buf = ehdr->e_ident; const unsigned char * const buf = ehdr->e_ident;
unsigned osabi0 = buf[Elf32_Ehdr::EI_OSABI]; unsigned char osabi0 = buf[Elf32_Ehdr::EI_OSABI];
if (0==osabi0) { if (0==osabi0) {
osabi0 = opt->o_unix.osabi0; osabi0 = opt->o_unix.osabi0;
} }
@@ -147,7 +162,7 @@ PackLinuxElf64::checkEhdr(Elf64_Ehdr const *ehdr) const
int const type = get_te16(&ehdr->e_type); int const type = get_te16(&ehdr->e_type);
if (type != Elf64_Ehdr::ET_EXEC && type != Elf64_Ehdr::ET_DYN) if (type != Elf64_Ehdr::ET_EXEC && type != Elf64_Ehdr::ET_DYN)
return 2; return 2;
if (get_te16(&ehdr->e_machine) != e_machine) if (get_te16(&ehdr->e_machine) != (unsigned) e_machine)
return 3; return 3;
if (get_te32(&ehdr->e_version) != Elf64_Ehdr::EV_CURRENT) if (get_te32(&ehdr->e_version) != Elf64_Ehdr::EV_CURRENT)
return 4; return 4;
@@ -158,7 +173,7 @@ PackLinuxElf64::checkEhdr(Elf64_Ehdr const *ehdr) const
if (type == Elf64_Ehdr::ET_EXEC) { if (type == Elf64_Ehdr::ET_EXEC) {
// check for Linux kernels // check for Linux kernels
acc_uint64l_t const entry = get_te64(&ehdr->e_entry); upx_uint64_t const entry = get_te64(&ehdr->e_entry);
if (entry == 0xC0100000) // uncompressed vmlinux if (entry == 0xC0100000) // uncompressed vmlinux
return 1000; return 1000;
if (entry == 0x00001000) // compressed vmlinux if (entry == 0x00001000) // compressed vmlinux
@@ -178,9 +193,10 @@ PackLinuxElf64::checkEhdr(Elf64_Ehdr const *ehdr) const
PackLinuxElf::PackLinuxElf(InputFile *f) PackLinuxElf::PackLinuxElf(InputFile *f)
: super(f), e_phnum(0), file_image(NULL), dynstr(NULL), : super(f), e_phnum(0), file_image(NULL), dynstr(NULL),
sz_phdrs(0), sz_elf_hdrs(0), sz_pack2(0), sz_pack2a(0), sz_pack2b(0), sz_phdrs(0), sz_elf_hdrs(0), sz_pack2(0), sz_pack2a(0),
lg2_page(12), page_size(1u<<lg2_page), xct_off(0), xct_va(0), lg2_page(12), page_size(1u<<lg2_page), xct_off(0), xct_va(0),
e_machine(0), ei_class(0), ei_data(0), ei_osabi(0), osabi_note(NULL) e_machine(0), ei_class(0), ei_data(0), ei_osabi(0), osabi_note(NULL),
o_elf_shnum(0)
{ {
} }
@@ -189,20 +205,8 @@ PackLinuxElf::~PackLinuxElf()
delete[] file_image; file_image = NULL; delete[] file_image; file_image = NULL;
} }
// Swap the byte ranges fo[a to b] and fo[b to c].
static void swap_byte_ranges(OutputFile *fo, unsigned a, unsigned b, unsigned c)
{
MemBuffer buf(c - a);
fo->seek(a, SEEK_SET);
fo->readx(buf, c - a);
fo->seek(a, SEEK_SET);
fo->rewrite(&buf[b - a], c - b);
fo->rewrite(&buf[0], b - a);
}
void PackLinuxElf::pack3(OutputFile *fo, Filter &ft) void PackLinuxElf::pack3(OutputFile *fo, Filter &ft)
{ {
sz_pack2b = fpad4(fo); // after headers, all PT_LOAD, gaps
unsigned disp; unsigned disp;
unsigned const zero = 0; unsigned const zero = 0;
unsigned len = sz_pack2a; // after headers and all PT_LOAD unsigned len = sz_pack2a; // after headers and all PT_LOAD
@@ -234,20 +238,32 @@ void PackLinuxElf::pack3(OutputFile *fo, Filter &ft)
sz_pack2 = len; // 0 mod 8 sz_pack2 = len; // 0 mod 8
super::pack3(fo, ft); // append the decompressor super::pack3(fo, ft); // append the decompressor
set_te16(&linfo.l_lsize, up4( set_te16(&linfo.l_lsize, up4( // MATCH03: up4
get_te16(&linfo.l_lsize) + len - sz_pack2a)); get_te16(&linfo.l_lsize) + len - sz_pack2a));
len = fpad4(fo); len = fpad4(fo); // MATCH03
// Put the loader in the middle, after the compressed PT_LOADs
// and before the compressed gaps (and debuginfo!)
// As first written, loader is fo[sz_pack2b to len],
// and gaps and debuginfo are fo[sz_pack2a to sz_pack2b].
swap_byte_ranges(fo, sz_pack2a, sz_pack2b, len);
} }
void PackLinuxElf32::pack3(OutputFile *fo, Filter &ft) void PackLinuxElf32::pack3(OutputFile *fo, Filter &ft)
{ {
super::pack3(fo, ft); super::pack3(fo, ft); // loader follows compressed PT_LOADs
// Then compressed gaps (including debuginfo.)
unsigned total_in = 0, total_out = 0;
for (unsigned k = 0; k < e_phnum; ++k) {
Extent x;
x.size = find_LOAD_gap(phdri, k, e_phnum);
if (x.size) {
x.offset = get_te32(&phdri[k].p_offset) +
get_te32(&phdri[k].p_filesz);
packExtent(x, total_in, total_out, 0, fo);
}
}
// write block end marker (uncompressed size 0)
b_info hdr; memset(&hdr, 0, sizeof(hdr));
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
fo->write(&hdr, sizeof(hdr));
fpad4(fo);
set_te32(&elfout.phdr[0].p_filesz, sz_pack2 + lsize); set_te32(&elfout.phdr[0].p_filesz, sz_pack2 + lsize);
set_te32(&elfout.phdr[0].p_memsz, sz_pack2 + lsize); set_te32(&elfout.phdr[0].p_memsz, sz_pack2 + lsize);
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
@@ -324,20 +340,37 @@ void PackLinuxElf32::pack3(OutputFile *fo, Filter &ft)
void PackLinuxElf64::pack3(OutputFile *fo, Filter &ft) void PackLinuxElf64::pack3(OutputFile *fo, Filter &ft)
{ {
super::pack3(fo, ft); super::pack3(fo, ft); // loader follows compressed PT_LOADs
// Then compressed gaps (including debuginfo.)
unsigned total_in = 0, total_out = 0;
for (unsigned k = 0; k < e_phnum; ++k) {
Extent x;
x.size = find_LOAD_gap(phdri, k, e_phnum);
if (x.size) {
x.offset = get_te64(&phdri[k].p_offset) +
get_te64(&phdri[k].p_filesz);
packExtent(x, total_in, total_out, 0, fo);
}
}
// write block end marker (uncompressed size 0)
b_info hdr; memset(&hdr, 0, sizeof(hdr));
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
fo->write(&hdr, sizeof(hdr));
fpad4(fo);
set_te64(&elfout.phdr[0].p_filesz, sz_pack2 + lsize); set_te64(&elfout.phdr[0].p_filesz, sz_pack2 + lsize);
set_te64(&elfout.phdr[0].p_memsz, sz_pack2 + lsize); set_te64(&elfout.phdr[0].p_memsz, sz_pack2 + lsize);
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
Elf64_Phdr *phdr = phdri; Elf64_Phdr *phdr = phdri;
unsigned off = fo->st_size(); unsigned off = fo->st_size();
unsigned off_init = 0; // where in file unsigned off_init = 0; // where in file
acc_uint64l_t va_init = sz_pack2; // virtual address upx_uint64_t va_init = sz_pack2; // virtual address
acc_uint64l_t rel = 0; upx_uint64_t rel = 0;
acc_uint64l_t old_dtinit = 0; upx_uint64_t old_dtinit = 0;
for (int j = e_phnum; --j>=0; ++phdr) { for (int j = e_phnum; --j>=0; ++phdr) {
acc_uint64l_t const len = get_te64(&phdr->p_filesz); upx_uint64_t const len = get_te64(&phdr->p_filesz);
acc_uint64l_t const ioff = get_te64(&phdr->p_offset); upx_uint64_t const ioff = get_te64(&phdr->p_offset);
acc_uint64l_t align= get_te64(&phdr->p_align); upx_uint64_t align= get_te64(&phdr->p_align);
unsigned const type = get_te32(&phdr->p_type); unsigned const type = get_te32(&phdr->p_type);
if (phdr->PT_INTERP==type) { if (phdr->PT_INTERP==type) {
// Rotate to highest position, so it can be lopped // Rotate to highest position, so it can be lopped
@@ -395,7 +428,7 @@ void PackLinuxElf64::pack3(OutputFile *fo, Filter &ft)
} }
if (off_init) { // change DT_INIT.d_val if (off_init) { // change DT_INIT.d_val
fo->seek(off_init, SEEK_SET); fo->seek(off_init, SEEK_SET);
acc_uint64l_t word; set_te64(&word, va_init); upx_uint64_t word; set_te64(&word, va_init);
fo->rewrite(&word, sizeof(word)); fo->rewrite(&word, sizeof(word));
fo->seek(0, SEEK_END); fo->seek(0, SEEK_END);
} }
@@ -411,7 +444,10 @@ PackLinuxElf::addStubEntrySections(Filter const *)
{ {
addLoader("ELFMAINX", NULL); addLoader("ELFMAINX", NULL);
if (hasLoaderSection("ELFMAINXu")) { if (hasLoaderSection("ELFMAINXu")) {
addLoader((opt->o_unix.unmap_all_pages ? "LUNMP000" : "LUNMP001"), "ELFMAINXu", NULL); int const all_pages = opt->o_unix.unmap_all_pages ||
// brk() trouble if static
(Elf32_Ehdr::EM_ARM==e_machine && 0x8000==load_va);
addLoader((all_pages ? "LUNMP000" : "LUNMP001"), "ELFMAINXu", NULL);
} }
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), NULL);
addLoader( addLoader(
@@ -824,22 +860,22 @@ PackLinuxElf64amd::defineSymbols(Filter const *)
// know the final total compressed size yet, so use the uncompressed // know the final total compressed size yet, so use the uncompressed
// size (total over all PT_LOAD64) as an upper bound. // size (total over all PT_LOAD64) as an upper bound.
unsigned len = 0; unsigned len = 0;
acc_uint64l_t lo_va_user = ~0ull; // infinity upx_uint64_t lo_va_user = ~0ull; // infinity
for (int j= e_phnum; --j>=0; ) { for (int j= e_phnum; --j>=0; ) {
if (PT_LOAD64 == get_te32(&phdri[j].p_type)) { if (PT_LOAD64 == get_te32(&phdri[j].p_type)) {
len += (unsigned)get_te64(&phdri[j].p_filesz); len += (unsigned)get_te64(&phdri[j].p_filesz);
acc_uint64l_t const va = get_te64(&phdri[j].p_vaddr); upx_uint64_t const va = get_te64(&phdri[j].p_vaddr);
if (va < lo_va_user) { if (va < lo_va_user) {
lo_va_user = va; lo_va_user = va;
} }
} }
} }
lsize = /*getLoaderSize()*/ 64 * 1024; // XXX: upper bound; avoid circularity lsize = /*getLoaderSize()*/ 64 * 1024; // XXX: upper bound; avoid circularity
acc_uint64l_t lo_va_stub = get_te64(&elfout.phdr[0].p_vaddr); upx_uint64_t lo_va_stub = get_te64(&elfout.phdr[0].p_vaddr);
acc_uint64l_t adrc; upx_uint64_t adrc;
acc_uint64l_t adrm; upx_uint64_t adrm;
acc_uint64l_t adru; upx_uint64_t adru;
acc_uint64l_t adrx; upx_uint64_t adrx;
unsigned cntc; unsigned cntc;
unsigned lenm; unsigned lenm;
unsigned lenu; unsigned lenu;
@@ -1141,6 +1177,21 @@ Elf32_Shdr const *PackLinuxElf32::elf_find_section_name(
return 0; return 0;
} }
Elf64_Shdr const *PackLinuxElf64::elf_find_section_name(
char const *const name
) const
{
Elf64_Shdr const *shdr = shdri;
int j = n_elf_shnum;
for (; 0 <=--j; ++shdr) {
unsigned ndx = get_te64(&shdr->sh_name);
if (0==strcmp(name, &shstrtab[ndx])) {
return shdr;
}
}
return 0;
}
Elf32_Shdr const *PackLinuxElf32::elf_find_section_type( Elf32_Shdr const *PackLinuxElf32::elf_find_section_type(
unsigned const type unsigned const type
) const ) const
@@ -1198,7 +1249,7 @@ bool PackLinuxElf32::canPack()
return false; return false;
} }
unsigned osabi0 = u.buf[Elf32_Ehdr::EI_OSABI]; unsigned char osabi0 = u.buf[Elf32_Ehdr::EI_OSABI];
// The first PT_LOAD32 must cover the beginning of the file (0==p_offset). // The first PT_LOAD32 must cover the beginning of the file (0==p_offset).
Elf32_Phdr const *phdr = (Elf32_Phdr const *)(u.buf + e_phoff); Elf32_Phdr const *phdr = (Elf32_Phdr const *)(u.buf + e_phoff);
note_size = 0; note_size = 0;
@@ -1249,10 +1300,9 @@ bool PackLinuxElf32::canPack()
if (Elf32_Ehdr::ELFOSABI_NONE==osabi0) { // No EI_OSBAI, no PT_NOTE. if (Elf32_Ehdr::ELFOSABI_NONE==osabi0) { // No EI_OSBAI, no PT_NOTE.
unsigned const arm_eabi = 0xff000000u & get_te32(&ehdr->e_flags); unsigned const arm_eabi = 0xff000000u & get_te32(&ehdr->e_flags);
if (Elf32_Ehdr::EM_ARM==e_machine if (Elf32_Ehdr::EM_ARM==e_machine
&& Elf32_Ehdr::ELFDATA2LSB==ei_data
&& (EF_ARM_EABI_VER5==arm_eabi && (EF_ARM_EABI_VER5==arm_eabi
|| EF_ARM_EABI_VER4==arm_eabi ) ) { || EF_ARM_EABI_VER4==arm_eabi ) ) {
// armel-eabi ARM little-endian Linux EABI version 4 is a mess. // armel-eabi armeb-eabi ARM Linux EABI version 4 is a mess.
ei_osabi = osabi0 = Elf32_Ehdr::ELFOSABI_LINUX; ei_osabi = osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;
} }
else { else {
@@ -1429,8 +1479,8 @@ PackLinuxElf64amd::canPack()
throwCantPack("invalid Ehdr e_ehsize; try '--force-execve'"); throwCantPack("invalid Ehdr e_ehsize; try '--force-execve'");
return false; return false;
} }
acc_uint64l_t const e_shoff = get_te64(&ehdr->e_shoff); upx_uint64_t const e_shoff = get_te64(&ehdr->e_shoff);
acc_uint64l_t const e_phoff = get_te64(&ehdr->e_phoff); upx_uint64_t const e_phoff = get_te64(&ehdr->e_phoff);
if (e_phoff != sizeof(*ehdr)) {// Phdrs not contiguous with Ehdr if (e_phoff != sizeof(*ehdr)) {// Phdrs not contiguous with Ehdr
throwCantPack("non-contiguous Ehdr/Phdr; try '--force-execve'"); throwCantPack("non-contiguous Ehdr/Phdr; try '--force-execve'");
return false; return false;
@@ -1538,8 +1588,8 @@ PackLinuxElf64amd::canPack()
} }
} }
// Rely on 0==elf_unsigned_dynamic(tag) if no such tag. // Rely on 0==elf_unsigned_dynamic(tag) if no such tag.
acc_uint64l_t const va_gash = elf_unsigned_dynamic(Elf64_Dyn::DT_GNU_HASH); upx_uint64_t const va_gash = elf_unsigned_dynamic(Elf64_Dyn::DT_GNU_HASH);
acc_uint64l_t const va_hash = elf_unsigned_dynamic(Elf64_Dyn::DT_HASH); upx_uint64_t const va_hash = elf_unsigned_dynamic(Elf64_Dyn::DT_HASH);
if (xct_va < va_gash || (0==va_gash && xct_va < va_hash) if (xct_va < va_gash || (0==va_gash && xct_va < va_hash)
|| xct_va < elf_unsigned_dynamic(Elf64_Dyn::DT_STRTAB) || xct_va < elf_unsigned_dynamic(Elf64_Dyn::DT_STRTAB)
|| xct_va < elf_unsigned_dynamic(Elf64_Dyn::DT_SYMTAB) || xct_va < elf_unsigned_dynamic(Elf64_Dyn::DT_SYMTAB)
@@ -1555,7 +1605,7 @@ PackLinuxElf64amd::canPack()
goto abandon; goto abandon;
} }
for ((shdr= shdri), (j= n_elf_shnum); --j>=0; ++shdr) { for ((shdr= shdri), (j= n_elf_shnum); --j>=0; ++shdr) {
acc_uint64l_t const sh_addr = get_te64(&shdr->sh_addr); upx_uint64_t const sh_addr = get_te64(&shdr->sh_addr);
if ( sh_addr==va_gash if ( sh_addr==va_gash
|| (sh_addr==va_hash && 0==va_gash) ) { || (sh_addr==va_hash && 0==va_gash) ) {
shdr= &shdri[get_te32(&shdr->sh_link)]; // the associated SHT_SYMTAB shdr= &shdri[get_te32(&shdr->sh_link)]; // the associated SHT_SYMTAB
@@ -1652,8 +1702,14 @@ PackLinuxElf32::generateElfHdr(
assert(get_te16(&h2->ehdr.e_ehsize) == sizeof(Elf32_Ehdr)); assert(get_te16(&h2->ehdr.e_ehsize) == sizeof(Elf32_Ehdr));
assert(get_te16(&h2->ehdr.e_phentsize) == sizeof(Elf32_Phdr)); assert(get_te16(&h2->ehdr.e_phentsize) == sizeof(Elf32_Phdr));
set_te16(&h2->ehdr.e_shentsize, sizeof(Elf32_Shdr)); set_te16(&h2->ehdr.e_shentsize, sizeof(Elf32_Shdr));
h2->ehdr.e_shnum = 0; if (o_elf_shnum) {
h2->ehdr.e_shstrndx = 0; h2->ehdr.e_shnum = o_elf_shnum;
h2->ehdr.e_shstrndx = o_elf_shnum - 1;
}
else {
h2->ehdr.e_shnum = 0;
h2->ehdr.e_shstrndx = 0;
}
sz_elf_hdrs = sizeof(*h2) - sizeof(linfo); // default sz_elf_hdrs = sizeof(*h2) - sizeof(linfo); // default
set_te32(&h2->phdr[0].p_filesz, sizeof(*h2)); // + identsize; set_te32(&h2->phdr[0].p_filesz, sizeof(*h2)); // + identsize;
@@ -1878,8 +1934,14 @@ PackLinuxElf64::generateElfHdr(
assert(get_te16(&h2->ehdr.e_ehsize) == sizeof(Elf64_Ehdr)); assert(get_te16(&h2->ehdr.e_ehsize) == sizeof(Elf64_Ehdr));
assert(get_te16(&h2->ehdr.e_phentsize) == sizeof(Elf64_Phdr)); assert(get_te16(&h2->ehdr.e_phentsize) == sizeof(Elf64_Phdr));
set_te16(&h2->ehdr.e_shentsize, sizeof(Elf64_Shdr)); set_te16(&h2->ehdr.e_shentsize, sizeof(Elf64_Shdr));
h2->ehdr.e_shnum = 0; if (o_elf_shnum) {
h2->ehdr.e_shstrndx = 0; h2->ehdr.e_shnum = o_elf_shnum;
h2->ehdr.e_shstrndx = o_elf_shnum - 1;
}
else {
h2->ehdr.e_shnum = 0;
h2->ehdr.e_shstrndx = 0;
}
sz_elf_hdrs = sizeof(*h2) - sizeof(linfo); // default sz_elf_hdrs = sizeof(*h2) - sizeof(linfo); // default
set_te64(&h2->phdr[0].p_filesz, sizeof(*h2)); // + identsize; set_te64(&h2->phdr[0].p_filesz, sizeof(*h2)); // + identsize;
@@ -1965,6 +2027,65 @@ void PackLinuxElf32::pack1(OutputFile *fo, Filter & /*ft*/)
memset(&linfo, 0, sizeof(linfo)); memset(&linfo, 0, sizeof(linfo));
fo->write(&linfo, sizeof(linfo)); fo->write(&linfo, sizeof(linfo));
} }
// if the preserve build-id option was specified
if (opt->o_unix.preserve_build_id) {
n_elf_shnum = ehdri.e_shnum;
Elf32_Shdr *shdr = NULL;
Elf32_Shdr const *tmp = shdri;
if (! shdri) {
shdr = new Elf32_Shdr[n_elf_shnum];
fi->seek(0,SEEK_SET);
fi->seek(ehdri.e_shoff,SEEK_SET);
fi->readx((void*)shdr,ehdri.e_shentsize*ehdri.e_shnum);
// set this so we can use elf_find_section_name
shdri = (Elf32_Shdr *)shdr;
}
//set the shstrtab
sec_strndx = &shdr[ehdri.e_shstrndx];
char *strtab = new char[(unsigned) sec_strndx->sh_size];
fi->seek(0,SEEK_SET);
fi->seek(sec_strndx->sh_offset,SEEK_SET);
fi->readx(strtab,sec_strndx->sh_size);
shstrtab = (const char*)strtab;
Elf32_Shdr const *buildid = elf_find_section_name(".note.gnu.build-id");
if (buildid) {
unsigned char *data = new unsigned char[(unsigned) buildid->sh_size];
memset(data,0,buildid->sh_size);
fi->seek(0,SEEK_SET);
fi->seek(buildid->sh_offset,SEEK_SET);
fi->readx(data,buildid->sh_size);
buildid_data = data;
o_elf_shnum = 3;
memset(&shdrout,0,sizeof(shdrout));
//setup the build-id
memcpy(&shdrout.shdr[1],buildid, sizeof(shdrout.shdr[1]));
shdrout.shdr[1].sh_name = 1;
//setup the shstrtab
memcpy(&shdrout.shdr[2],sec_strndx, sizeof(shdrout.shdr[2]));
shdrout.shdr[2].sh_name = 20;
shdrout.shdr[2].sh_size = 29; //size of our static shstrtab
}
// repoint shdr in case it is used by code some where else
if (shdr) {
shdri = tmp;
delete [] shdr;
shdr = NULL;
}
}
} }
void PackLinuxElf32x86::pack1(OutputFile *fo, Filter &ft) void PackLinuxElf32x86::pack1(OutputFile *fo, Filter &ft)
@@ -1998,6 +2119,9 @@ void PackLinuxElf32armLe::pack1(OutputFile *fo, Filter &ft)
else { else {
memcpy(&h3, stub_arm_linux_elf_fold, sizeof(Elf32_Ehdr) + 2*sizeof(Elf32_Phdr)); memcpy(&h3, stub_arm_linux_elf_fold, sizeof(Elf32_Ehdr) + 2*sizeof(Elf32_Phdr));
} }
// Fighting over .e_ident[EI_ABIVERSION]: Debian armhf is latest culprit.
// So copy from input to output; but see PackLinuxElf32::generateElfHdr
memcpy(&h3.ehdr.e_ident[0], &ehdri.e_ident[0], sizeof(ehdri.e_ident));
set_te32(&h3.ehdr.e_flags, e_flags); set_te32(&h3.ehdr.e_flags, e_flags);
generateElfHdr(fo, &h3, getbrk(phdri, e_phnum) ); generateElfHdr(fo, &h3, getbrk(phdri, e_phnum) );
} }
@@ -2094,6 +2218,68 @@ void PackLinuxElf64::pack1(OutputFile *fo, Filter & /*ft*/)
memset(&linfo, 0, sizeof(linfo)); memset(&linfo, 0, sizeof(linfo));
fo->write(&linfo, sizeof(linfo)); fo->write(&linfo, sizeof(linfo));
} }
// only execute if option present
if (opt->o_unix.preserve_build_id) {
// set this so we can use elf_find_section_name
n_elf_shnum = ehdri.e_shnum;
// there is a class member similar to this, but I did not
// want to assume it would be available
Elf64_Shdr const *tmp = shdri;
Elf64_Shdr *shdr = NULL;
if (! shdri) {
shdr = new Elf64_Shdr[n_elf_shnum];
fi->seek(0,SEEK_SET);
fi->seek(ehdri.e_shoff,SEEK_SET);
fi->readx((void*)shdr,ehdri.e_shentsize*ehdri.e_shnum);
// set this so we can use elf_find_section_name
shdri = (Elf64_Shdr *)shdr;
}
//set the shstrtab
sec_strndx = &shdri[ehdri.e_shstrndx];
char *strtab = new char[(unsigned) sec_strndx->sh_size];
fi->seek(0,SEEK_SET);
fi->seek(sec_strndx->sh_offset,SEEK_SET);
fi->readx(strtab,sec_strndx->sh_size);
shstrtab = (const char*)strtab;
Elf64_Shdr const *buildid = elf_find_section_name(".note.gnu.build-id");
if (buildid) {
unsigned char *data = new unsigned char[(unsigned) buildid->sh_size];
memset(data,0,buildid->sh_size);
fi->seek(0,SEEK_SET);
fi->seek(buildid->sh_offset,SEEK_SET);
fi->readx(data,buildid->sh_size);
buildid_data = data;
o_elf_shnum = 3;
memset(&shdrout,0,sizeof(shdrout));
//setup the build-id
memcpy(&shdrout.shdr[1],buildid, sizeof(shdrout.shdr[1]));
shdrout.shdr[1].sh_name = 1;
//setup the shstrtab
memcpy(&shdrout.shdr[2],sec_strndx, sizeof(shdrout.shdr[2]));
shdrout.shdr[2].sh_name = 20;
shdrout.shdr[2].sh_size = 29; //size of our static shstrtab
}
if (shdr) {
shdri = tmp;
delete [] shdr;
shdr = NULL;
}
}
} }
void PackLinuxElf64amd::pack1(OutputFile *fo, Filter &ft) void PackLinuxElf64amd::pack1(OutputFile *fo, Filter &ft)
@@ -2144,7 +2330,7 @@ unsigned PackLinuxElf32::find_LOAD_gap(
return lo - hi; return lo - hi;
} }
void PackLinuxElf32::pack2(OutputFile *fo, Filter &ft) int PackLinuxElf32::pack2(OutputFile *fo, Filter &ft)
{ {
Extent x; Extent x;
unsigned k; unsigned k;
@@ -2200,19 +2386,17 @@ void PackLinuxElf32::pack2(OutputFile *fo, Filter &ft)
hdr_u_len = 0; hdr_u_len = 0;
++nx; ++nx;
} }
sz_pack2a = fpad4(fo); sz_pack2a = fpad4(fo); // MATCH01
// Accounting only; ::pack3 will do the compression and output
for (k = 0; k < e_phnum; ++k) { for (k = 0; k < e_phnum; ++k) {
x.size = find_LOAD_gap(phdri, k, e_phnum); total_in += find_LOAD_gap(phdri, k, e_phnum);
if (x.size) {
x.offset = get_te32(&phdri[k].p_offset) +
get_te32(&phdri[k].p_filesz);
packExtent(x, total_in, total_out, 0, fo);
}
} }
if ((off_t)total_in != file_size) if ((off_t)total_in != file_size)
throwEOFException(); throwEOFException();
return 0; // omit end-of-compression bhdr for now
} }
// Determine length of gap between PT_LOAD phdr[k] and closest PT_LOAD // Determine length of gap between PT_LOAD phdr[k] and closest PT_LOAD
@@ -2255,7 +2439,7 @@ unsigned PackLinuxElf64::find_LOAD_gap(
return lo - hi; return lo - hi;
} }
void PackLinuxElf64::pack2(OutputFile *fo, Filter &ft) int PackLinuxElf64::pack2(OutputFile *fo, Filter &ft)
{ {
Extent x; Extent x;
unsigned k; unsigned k;
@@ -2311,19 +2495,17 @@ void PackLinuxElf64::pack2(OutputFile *fo, Filter &ft)
hdr_u_len = 0; hdr_u_len = 0;
++nx; ++nx;
} }
sz_pack2a = fpad4(fo); sz_pack2a = fpad4(fo); // MATCH01
for (k = 0; k < e_phnum; ++k) { // Accounting only; ::pack3 will do the compression and output
x.size = find_LOAD_gap(phdri, k, e_phnum); for (k = 0; k < e_phnum; ++k) { //
if (x.size) { total_in += find_LOAD_gap(phdri, k, e_phnum);
x.offset = get_te64(&phdri[k].p_offset) +
get_te64(&phdri[k].p_filesz);
packExtent(x, total_in, total_out, 0, fo);
}
} }
if ((off_t)total_in != file_size) if ((off_t)total_in != file_size)
throwEOFException(); throwEOFException();
return 0; // omit end-of-compression bhdr for now
} }
// Filter 0x50, 0x51 assume HostPolicy::isLE // Filter 0x50, 0x51 assume HostPolicy::isLE
@@ -2393,8 +2575,6 @@ int PackLinuxElf32::ARM_is_QNX(void)
void PackLinuxElf32::ARM_defineSymbols(Filter const * /*ft*/) void PackLinuxElf32::ARM_defineSymbols(Filter const * /*ft*/)
{ {
unsigned const hlen = sz_elf_hdrs + sizeof(l_info) + sizeof(p_info);
lsize = /*getLoaderSize()*/ 4 * 1024; // upper bound; avoid circularity lsize = /*getLoaderSize()*/ 4 * 1024; // upper bound; avoid circularity
unsigned lo_va_user = ~0u; // infinity unsigned lo_va_user = ~0u; // infinity
for (int j= e_phnum; --j>=0; ) { for (int j= e_phnum; --j>=0; ) {
@@ -2408,9 +2588,8 @@ void PackLinuxElf32::ARM_defineSymbols(Filter const * /*ft*/)
unsigned lo_va_stub = get_te32(&elfout.phdr[0].p_vaddr); unsigned lo_va_stub = get_te32(&elfout.phdr[0].p_vaddr);
unsigned adrc; unsigned adrc;
unsigned adrm; unsigned adrm;
unsigned adrx;
bool const is_big = true; bool const is_big = true; // kernel disallows mapping below 0x8000.
if (is_big) { if (is_big) {
set_te32( &elfout.ehdr.e_entry, linker->getSymbolOffset("_start") + set_te32( &elfout.ehdr.e_entry, linker->getSymbolOffset("_start") +
get_te32(&elfout.ehdr.e_entry) + lo_va_user - lo_va_stub); get_te32(&elfout.ehdr.e_entry) + lo_va_user - lo_va_stub);
@@ -2419,16 +2598,15 @@ void PackLinuxElf32::ARM_defineSymbols(Filter const * /*ft*/)
lo_va_stub = lo_va_user; lo_va_stub = lo_va_user;
adrc = lo_va_stub; adrc = lo_va_stub;
adrm = getbrk(phdri, e_phnum); adrm = getbrk(phdri, e_phnum);
adrx = hlen + (page_mask & (~page_mask + adrm)); // round up to page boundary
} }
adrm = page_mask & (~page_mask + adrm); // round up to page boundary
adrc = page_mask & (~page_mask + adrc); // round up to page boundary adrc = page_mask & (~page_mask + adrc); // round up to page boundary
adrm = page_mask & (~page_mask + adrm); // round up to page boundary
adrm += page_size; // Try: hole so that kernel does not extend the brk(0)
linker->defineSymbol("ADRM", adrm); // addr for map
linker->defineSymbol("CPR0", 4+ linker->getSymbolOffset("cpr0")); linker->defineSymbol("CPR0", 4+ linker->getSymbolOffset("cpr0"));
linker->defineSymbol("LENF", 4+ linker->getSymbolOffset("end_decompress")); linker->defineSymbol("LENF", 4+ linker->getSymbolOffset("end_decompress"));
linker->defineSymbol("ADRM", adrm); // addr for map
#define MAP_PRIVATE 2 /* UNIX standard */ #define MAP_PRIVATE 2 /* UNIX standard */
#define MAP_FIXED 0x10 /* UNIX standard */ #define MAP_FIXED 0x10 /* UNIX standard */
#define MAP_ANONYMOUS 0x20 /* UNIX standard */ #define MAP_ANONYMOUS 0x20 /* UNIX standard */
@@ -2437,8 +2615,6 @@ void PackLinuxElf32::ARM_defineSymbols(Filter const * /*ft*/)
if (ARM_is_QNX()) if (ARM_is_QNX())
mflg = MAP_PRIVANON; mflg = MAP_PRIVANON;
linker->defineSymbol("MFLG", mflg); linker->defineSymbol("MFLG", mflg);
ACC_UNUSED(adrx);
} }
void PackLinuxElf32armLe::defineSymbols(Filter const *ft) void PackLinuxElf32armLe::defineSymbols(Filter const *ft)
@@ -2601,6 +2777,24 @@ void PackLinuxElf32::pack4(OutputFile *fo, Filter &ft)
{ {
overlay_offset = sz_elf_hdrs + sizeof(linfo); overlay_offset = sz_elf_hdrs + sizeof(linfo);
if (opt->o_unix.preserve_build_id) {
// calc e_shoff here and write shdrout, then o_shstrtab
//NOTE: these are pushed last to ensure nothing is stepped on
//for the UPX structure.
unsigned const len = fpad4(fo);
set_te32(&elfout.ehdr.e_shoff,len);
int const ssize = sizeof(shdrout);
shdrout.shdr[2].sh_offset = len+ssize;
shdrout.shdr[1].sh_offset = shdrout.shdr[2].sh_offset+shdrout.shdr[2].sh_size;
fo->write(&shdrout, ssize);
fo->write(o_shstrtab,shdrout.shdr[2].sh_size);
fo->write(buildid_data,shdrout.shdr[1].sh_size);
}
// Cannot pre-round .p_memsz. If .p_filesz < .p_memsz, then kernel // Cannot pre-round .p_memsz. If .p_filesz < .p_memsz, then kernel
// tries to make .bss, which requires PF_W. // tries to make .bss, which requires PF_W.
// But strict SELinux (or PaX, grSecurity) disallows PF_W with PF_X. // But strict SELinux (or PaX, grSecurity) disallows PF_W with PF_X.
@@ -2650,6 +2844,24 @@ void PackLinuxElf64::pack4(OutputFile *fo, Filter &ft)
{ {
overlay_offset = sz_elf_hdrs + sizeof(linfo); overlay_offset = sz_elf_hdrs + sizeof(linfo);
if (opt->o_unix.preserve_build_id) {
// calc e_shoff here and write shdrout, then o_shstrtab
//NOTE: these are pushed last to ensure nothing is stepped on
//for the UPX structure.
unsigned const len = fpad4(fo);
set_te64(&elfout.ehdr.e_shoff,len);
int const ssize = sizeof(shdrout);
shdrout.shdr[2].sh_offset = len+ssize;
shdrout.shdr[1].sh_offset = shdrout.shdr[2].sh_offset+shdrout.shdr[2].sh_size;
fo->write(&shdrout, ssize);
fo->write(o_shstrtab,shdrout.shdr[2].sh_size);
fo->write(buildid_data,shdrout.shdr[1].sh_size);
}
// Cannot pre-round .p_memsz. If .p_filesz < .p_memsz, then kernel // Cannot pre-round .p_memsz. If .p_filesz < .p_memsz, then kernel
// tries to make .bss, which requires PF_W. // tries to make .bss, which requires PF_W.
// But strict SELinux (or PaX, grSecurity) disallows PF_W with PF_X. // But strict SELinux (or PaX, grSecurity) disallows PF_W with PF_X.
@@ -2659,7 +2871,7 @@ void PackLinuxElf64::pack4(OutputFile *fo, Filter &ft)
// rewrite Elf header // rewrite Elf header
if (Elf64_Ehdr::ET_DYN==get_te16(&ehdri.e_type)) { if (Elf64_Ehdr::ET_DYN==get_te16(&ehdri.e_type)) {
acc_uint64l_t const base= get_te64(&elfout.phdr[0].p_vaddr); upx_uint64_t const base= get_te64(&elfout.phdr[0].p_vaddr);
set_te16(&elfout.ehdr.e_type, Elf64_Ehdr::ET_DYN); set_te16(&elfout.ehdr.e_type, Elf64_Ehdr::ET_DYN);
set_te16(&elfout.ehdr.e_phnum, 1); set_te16(&elfout.ehdr.e_phnum, 1);
set_te64( &elfout.ehdr.e_entry, set_te64( &elfout.ehdr.e_entry,
@@ -2677,7 +2889,7 @@ void PackLinuxElf64::pack4(OutputFile *fo, Filter &ft)
} }
else { else {
if (Elf64_Phdr::PT_NOTE==get_te64(&elfout.phdr[2].p_type)) { if (Elf64_Phdr::PT_NOTE==get_te64(&elfout.phdr[2].p_type)) {
acc_uint64l_t const reloc = get_te64(&elfout.phdr[0].p_vaddr); upx_uint64_t const reloc = get_te64(&elfout.phdr[0].p_vaddr);
set_te64( &elfout.phdr[2].p_vaddr, set_te64( &elfout.phdr[2].p_vaddr,
reloc + get_te64(&elfout.phdr[2].p_vaddr)); reloc + get_te64(&elfout.phdr[2].p_vaddr));
set_te64( &elfout.phdr[2].p_paddr, set_te64( &elfout.phdr[2].p_paddr,
@@ -2706,7 +2918,7 @@ void PackLinuxElf64::unpack(OutputFile *fo)
{ {
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
fi->readx(u.buf, MAX_ELF_HDR); fi->readx(u.buf, MAX_ELF_HDR);
acc_uint64l_t const e_entry = get_te64(&ehdr->e_entry); upx_uint64_t const e_entry = get_te64(&ehdr->e_entry);
if (e_entry < 0x401180 if (e_entry < 0x401180
&& ehdr->e_machine==Elf64_Ehdr::EM_386) { /* old style, 8-byte b_info */ && ehdr->e_machine==Elf64_Ehdr::EM_386) { /* old style, 8-byte b_info */
szb_info = 2*sizeof(unsigned); szb_info = 2*sizeof(unsigned);
@@ -2749,8 +2961,8 @@ void PackLinuxElf64::unpack(OutputFile *fo)
fi->seek(- (off_t) (szb_info + ph.c_len), SEEK_CUR); fi->seek(- (off_t) (szb_info + ph.c_len), SEEK_CUR);
for (unsigned j=0; j < u_phnum; ++phdr, ++j) { for (unsigned j=0; j < u_phnum; ++phdr, ++j) {
if (PT_LOAD64==get_te32(&phdr->p_type)) { if (PT_LOAD64==get_te32(&phdr->p_type)) {
acc_uint64l_t const filesz = get_te64(&phdr->p_filesz); upx_uint64_t const filesz = get_te64(&phdr->p_filesz);
acc_uint64l_t const offset = get_te64(&phdr->p_offset); upx_uint64_t const offset = get_te64(&phdr->p_offset);
if (fo) if (fo)
fo->seek(offset, SEEK_SET); fo->seek(offset, SEEK_SET);
if (Elf64_Phdr::PF_X & get_te32(&phdr->p_flags)) { if (Elf64_Phdr::PF_X & get_te32(&phdr->p_flags)) {
@@ -2764,11 +2976,14 @@ void PackLinuxElf64::unpack(OutputFile *fo)
} }
} }
} }
if (( (unsigned)(get_te64(&ehdri.e_entry) - load_va) + up4(lsize) + bool const is_shlib = 0; // XXX ??
ph.getPackHeaderSize() + sizeof(overlay_offset)) < up4(fi->st_size())) { if (is_shlib
|| ((unsigned)(get_te64(&ehdri.e_entry) - load_va) + up4(lsize) +
ph.getPackHeaderSize() + sizeof(overlay_offset))
< up4(fi->st_size())) {
// Loader is not at end; skip past it. // Loader is not at end; skip past it.
// total_in does not include n*szb_info, so we use SEEK_CUR. funpad4(fi); // MATCH01
fi->seek(up4(total_in) - total_in + lsize, SEEK_CUR); fi->seek(lsize, SEEK_CUR);
} }
// The gaps between PT_LOAD and after last PT_LOAD // The gaps between PT_LOAD and after last PT_LOAD
@@ -3006,7 +3221,7 @@ PackLinuxElf32::elf_find_dynamic(unsigned int const key) const
return 0; return 0;
} }
acc_uint64l_t upx_uint64_t
PackLinuxElf32::elf_unsigned_dynamic(unsigned int const key) const PackLinuxElf32::elf_unsigned_dynamic(unsigned int const key) const
{ {
Elf32_Dyn const *dynp= dynseg; Elf32_Dyn const *dynp= dynseg;
@@ -3017,13 +3232,13 @@ PackLinuxElf32::elf_unsigned_dynamic(unsigned int const key) const
return 0; return 0;
} }
acc_uint64l_t upx_uint64_t
PackLinuxElf64::elf_get_offset_from_address(acc_uint64l_t const addr) const PackLinuxElf64::elf_get_offset_from_address(upx_uint64_t const addr) const
{ {
Elf64_Phdr const *phdr = phdri; Elf64_Phdr const *phdr = phdri;
int j = e_phnum; int j = e_phnum;
for (; --j>=0; ++phdr) if (PT_LOAD64 == get_te32(&phdr->p_type)) { for (; --j>=0; ++phdr) if (PT_LOAD64 == get_te32(&phdr->p_type)) {
acc_uint64l_t const t = addr - get_te64(&phdr->p_vaddr); upx_uint64_t const t = addr - get_te64(&phdr->p_vaddr);
if (t < get_te64(&phdr->p_filesz)) { if (t < get_te64(&phdr->p_filesz)) {
return t + get_te64(&phdr->p_offset); return t + get_te64(&phdr->p_offset);
} }
@@ -3048,7 +3263,7 @@ PackLinuxElf64::elf_find_dynamic(unsigned int const key) const
Elf64_Dyn const *dynp= dynseg; Elf64_Dyn const *dynp= dynseg;
if (dynp) if (dynp)
for (; Elf64_Dyn::DT_NULL!=dynp->d_tag; ++dynp) if (get_te64(&dynp->d_tag)==key) { for (; Elf64_Dyn::DT_NULL!=dynp->d_tag; ++dynp) if (get_te64(&dynp->d_tag)==key) {
acc_uint64l_t const t= elf_get_offset_from_address(get_te64(&dynp->d_val)); upx_uint64_t const t= elf_get_offset_from_address(get_te64(&dynp->d_val));
if (t) { if (t) {
return (size_t)t + file_image; return (size_t)t + file_image;
} }
@@ -3057,7 +3272,7 @@ PackLinuxElf64::elf_find_dynamic(unsigned int const key) const
return 0; return 0;
} }
acc_uint64l_t upx_uint64_t
PackLinuxElf64::elf_unsigned_dynamic(unsigned int const key) const PackLinuxElf64::elf_unsigned_dynamic(unsigned int const key) const
{ {
Elf64_Dyn const *dynp= dynseg; Elf64_Dyn const *dynp= dynseg;
@@ -3270,11 +3485,13 @@ void PackLinuxElf32::unpack(OutputFile *fo)
} }
} }
} }
if (( (unsigned)(get_te32(&ehdri.e_entry) - load_va) + up4(lsize) + if (is_shlib
ph.getPackHeaderSize() + sizeof(overlay_offset)) < up4(fi->st_size())) { || ((unsigned)(get_te32(&ehdri.e_entry) - load_va) + up4(lsize) +
ph.getPackHeaderSize() + sizeof(overlay_offset))
< up4(fi->st_size())) {
// Loader is not at end; skip past it. // Loader is not at end; skip past it.
// total_in does not include n*szb_info, so we use SEEK_CUR. funpad4(fi); // MATCH01
fi->seek(up4(total_in) - total_in + lsize, SEEK_CUR); fi->seek(lsize, SEEK_CUR);
} }
// The gaps between PT_LOAD and after last PT_LOAD // The gaps between PT_LOAD and after last PT_LOAD
+29 -14
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
@@ -50,7 +50,7 @@ protected:
// because they depend on Elf32 or Elf64 data structures, which differ. // because they depend on Elf32 or Elf64 data structures, which differ.
virtual void pack1(OutputFile *, Filter &) = 0; // generate executable header virtual void pack1(OutputFile *, Filter &) = 0; // generate executable header
virtual void pack2(OutputFile *, Filter &) = 0; // append compressed data virtual int pack2(OutputFile *, Filter &) = 0; // append compressed data
virtual void pack3(OutputFile *, Filter &) = 0; // append loader virtual void pack3(OutputFile *, Filter &) = 0; // append loader
//virtual void pack4(OutputFile *, Filter &) = 0; // append pack header //virtual void pack4(OutputFile *, Filter &) = 0; // append pack header
@@ -64,7 +64,7 @@ protected:
virtual void unpack(OutputFile *fo); virtual void unpack(OutputFile *fo);
//virtual void const *elf_find_dynamic(unsigned) const = 0; //virtual void const *elf_find_dynamic(unsigned) const = 0;
virtual acc_uint64l_t elf_unsigned_dynamic(unsigned) const = 0; virtual upx_uint64_t elf_unsigned_dynamic(unsigned) const = 0;
protected: protected:
unsigned e_phnum; /* Program header table entry count */ unsigned e_phnum; /* Program header table entry count */
@@ -75,19 +75,22 @@ protected:
unsigned sz_elf_hdrs; // all Elf headers unsigned sz_elf_hdrs; // all Elf headers
unsigned sz_pack2; // after pack2(), before loader unsigned sz_pack2; // after pack2(), before loader
unsigned sz_pack2a; // after pack2() of all PT_LOAD unsigned sz_pack2a; // after pack2() of all PT_LOAD
unsigned sz_pack2b; // after pack2() of all PT_LOAD and gaps
unsigned lg2_page; // log2(PAGE_SIZE) unsigned lg2_page; // log2(PAGE_SIZE)
unsigned page_size; // 1u<<lg2_page unsigned page_size; // 1u<<lg2_page
unsigned xct_off; // shared library: file offset of SHT_EXECINSTR unsigned xct_off; // shared library: file offset of SHT_EXECINSTR
unsigned hatch_off; // file offset of escape hatch unsigned hatch_off; // file offset of escape hatch
acc_uint64l_t load_va; // PT_LOAD[0].p_vaddr upx_uint64_t load_va; // PT_LOAD[0].p_vaddr
acc_uint64l_t xct_va; // minimum SHT_EXECINSTR virtual address upx_uint64_t xct_va; // minimum SHT_EXECINSTR virtual address
unsigned short e_machine; unsigned short e_machine;
unsigned char ei_class; unsigned char ei_class;
unsigned char ei_data; unsigned char ei_data;
unsigned char ei_osabi; unsigned char ei_osabi;
char const *osabi_note; char const *osabi_note;
unsigned char const *buildid_data;
int o_elf_shnum; // num output Shdrs
static unsigned char o_shstrtab[];
}; };
class PackLinuxElf32 : public PackLinuxElf class PackLinuxElf32 : public PackLinuxElf
@@ -107,7 +110,7 @@ protected:
virtual int ARM_is_QNX(void); virtual int ARM_is_QNX(void);
virtual void pack1(OutputFile *, Filter &); // generate executable header virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data virtual int pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &); // append loader virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append pack header virtual void pack4(OutputFile *, Filter &); // append pack header
virtual void unpack(OutputFile *fo); virtual void unpack(OutputFile *fo);
@@ -139,7 +142,7 @@ protected:
Elf32_Shdr const *elf_find_section_type(unsigned) const; Elf32_Shdr const *elf_find_section_type(unsigned) const;
void const *elf_find_dynamic(unsigned) const; void const *elf_find_dynamic(unsigned) const;
Elf32_Dyn const *elf_has_dynamic(unsigned) const; Elf32_Dyn const *elf_has_dynamic(unsigned) const;
acc_uint64l_t elf_unsigned_dynamic(unsigned) const; upx_uint64_t elf_unsigned_dynamic(unsigned) const;
protected: protected:
Elf32_Ehdr ehdri; // from input file Elf32_Ehdr ehdri; // from input file
@@ -186,6 +189,12 @@ protected:
cprElfHdrNetBSD elfout; cprElfHdrNetBSD elfout;
__packed_struct(cprElfShdr3)
Elf32_Shdr shdr[3];
__packed_struct_end()
cprElfShdr3 shdrout;
struct Elf32_Nhdr { struct Elf32_Nhdr {
unsigned namesz; unsigned namesz;
unsigned descsz; unsigned descsz;
@@ -218,7 +227,7 @@ protected:
virtual int checkEhdr(Elf64_Ehdr const *ehdr) const; virtual int checkEhdr(Elf64_Ehdr const *ehdr) const;
virtual void pack1(OutputFile *, Filter &); // generate executable header virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data virtual int pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &); // append loader virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append pack header virtual void pack4(OutputFile *, Filter &); // append pack header
virtual void unpack(OutputFile *fo); virtual void unpack(OutputFile *fo);
@@ -241,12 +250,12 @@ protected:
virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k, virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k,
unsigned const e_phnum); unsigned const e_phnum);
virtual acc_uint64l_t elf_get_offset_from_address(acc_uint64l_t) const; virtual upx_uint64_t elf_get_offset_from_address(upx_uint64_t) const;
Elf64_Shdr const *elf_find_section_name(char const *) const; Elf64_Shdr const *elf_find_section_name(char const *) const;
Elf64_Shdr const *elf_find_section_type(unsigned) const; Elf64_Shdr const *elf_find_section_type(unsigned) const;
void const *elf_find_dynamic(unsigned) const; void const *elf_find_dynamic(unsigned) const;
Elf64_Dyn const *elf_has_dynamic(unsigned) const; Elf64_Dyn const *elf_has_dynamic(unsigned) const;
acc_uint64l_t elf_unsigned_dynamic(unsigned) const; upx_uint64_t elf_unsigned_dynamic(unsigned) const;
protected: protected:
Elf64_Ehdr ehdri; // from input file Elf64_Ehdr ehdri; // from input file
@@ -254,7 +263,7 @@ protected:
unsigned char *note_body; // concatenated contents of PT_NOTEs, if any unsigned char *note_body; // concatenated contents of PT_NOTEs, if any
unsigned note_size; // total size of PT_NOTEs unsigned note_size; // total size of PT_NOTEs
Elf64_Shdr const *shdri; // from input file Elf64_Shdr const *shdri; // from input file
acc_uint64l_t page_mask; // AND clears the offset-within-page upx_uint64_t page_mask; // AND clears the offset-within-page
Elf64_Dyn const *dynseg; // from PT_DYNAMIC Elf64_Dyn const *dynseg; // from PT_DYNAMIC
unsigned int const *hashtab; // from DT_HASH unsigned int const *hashtab; // from DT_HASH
@@ -293,6 +302,12 @@ protected:
cprElfHdr4 elfout; cprElfHdr4 elfout;
__packed_struct(cprElfShdr3)
Elf64_Shdr shdr[3];
__packed_struct_end()
cprElfShdr3 shdrout;
static void compileTimeAssertions() { static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 64 + 1*56 + 12) COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 64 + 1*56 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 64 + 2*56 + 12) COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 64 + 2*56 + 12)
+5 -5
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2001-2011 John F. Reiser Copyright (C) 2001-2013 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
@@ -375,7 +375,7 @@ PackLinuxI386::buildLinuxLoader(
addLoader("FOLDEXEC", NULL); addLoader("FOLDEXEC", NULL);
if (M_IS_LZMA(ph.method)) { if (M_IS_LZMA(ph.method)) {
const lzma_compress_result_t *res = &ph.compress_result.result_lzma; const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
acc_uint32e_t properties = // lc, lp, pb, dummy upx_uint32_t properties = // lc, lp, pb, dummy
(res->lit_context_bits << 0) | (res->lit_context_bits << 0) |
(res->lit_pos_bits << 8) | (res->lit_pos_bits << 8) |
(res->pos_bits << 16); (res->pos_bits << 16);
@@ -449,7 +449,7 @@ int PackLinuxI386::getLoaderPrefixSize() const
// some ELF utitlity functions // some ELF utitlity functions
**************************************************************************/ **************************************************************************/
// basic check of an Linux ELF Ehdr // basic check of a Linux ELF Ehdr
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
{ {
const unsigned char * const buf = ehdr->e_ident; const unsigned char * const buf = ehdr->e_ident;
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+6 -6
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
@@ -124,12 +124,12 @@ void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
#undef E #undef E
} }
void PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft) int PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft)
{ {
if (opt->o_unix.make_ptinterp) { if (opt->o_unix.make_ptinterp) {
return; // ignore current input file! return 1; // ignore current input file!
} }
super::pack2(fo, ft); return super::pack2(fo, ft);
} }
#undef PAGE_MASK #undef PAGE_MASK
+4 -4
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
@@ -54,7 +54,7 @@ public:
protected: protected:
virtual void pack1(OutputFile *, Filter &); // generate executable header virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data virtual int pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &); // build loader virtual void pack3(OutputFile *, Filter &); // build loader
}; };
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2011 John F. Reiser Copyright (C) 2000-2013 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
+258 -65
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 2004-2011 John Reiser Copyright (C) 2004-2013 John 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
@@ -351,7 +351,7 @@ PackMachBase<T>::buildMachLoader(
int const GAP = 128; // must match stub/l_mac_ppc.S int const GAP = 128; // must match stub/l_mac_ppc.S
int const NO_LAP = 64; // must match stub/src/*darwin*.S int const NO_LAP = 64; // must match stub/src/*darwin*.S
segcmdo.vmsize += h.sz_unc - h.sz_cpr + GAP + NO_LAP; segTEXT.vmsize = h.sz_unc - h.sz_cpr + GAP + NO_LAP;
addStubEntrySections(ft); addStubEntrySections(ft);
@@ -447,77 +447,211 @@ PackMachBase<T>::compare_segment_command(void const *const aa, void const *const
unsigned const xb = b->cmd - lc_seg; unsigned const xb = b->cmd - lc_seg;
if (xa < xb) return -1; // LC_SEGMENT first if (xa < xb) return -1; // LC_SEGMENT first
if (xa > xb) return 1; if (xa > xb) return 1;
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr // Beware 0==.vmsize (some MacOSX __DWARF debug info: a "comment")
if (a->vmaddr > b->vmaddr) return 1; if (a->vmsize!=0 && b->vmsize!=0) {
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr
if (a->vmaddr > b->vmaddr) return 1;
}
else { // 0==.vmsize goes last, except ordered by fileoff
if (a->vmsize) return -1; // 'a' is first
if (b->vmsize) return 1; // 'a' is last
if (a->fileoff < b->fileoff)
return -1;
if (a->fileoff > b->fileoff)
return 1;
}
return 0; return 0;
} }
#undef PAGE_MASK
#undef PAGE_SIZE
#define PAGE_MASK (~0u<<12)
#define PAGE_SIZE (0u-PAGE_MASK)
#undef PAGE_MASK64
#undef PAGE_SIZE64
#define PAGE_MASK64 (~(upx_uint64_t)0<<12)
#define PAGE_SIZE64 ((upx_uint64_t)0-PAGE_MASK64)
// At 2013-02-03 part of the source for codesign was
// http://opensource.apple.com/source/cctools/cctools-836/libstuff/ofile.c
void PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader void PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{ {
// offset of p_info in compressed file // offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo); overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
}
super::pack4(fo, ft); super::pack4(fo, ft);
segcmdo.filesize = fo->getBytesWritten(); unsigned const t = fo->getBytesWritten();
segcmdo.vmsize += segcmdo.filesize; segTEXT.filesize = t;
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
secTEXT.offset = overlay_offset - sizeof(linfo);
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
if (foff1 < segTEXT.vmsize)
foff1 += PAGE_SIZE; // codesign disallows overhang
segLINK.fileoff = foff1;
segLINK.vmaddr = segTEXT.vmaddr + foff1;
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
fo->seek(sizeof(mhdro), SEEK_SET); fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segcmdo, sizeof(segcmdo)); fo->rewrite(&segZERO, sizeof(segZERO));
fo->rewrite(&segXHDR, sizeof(segXHDR));
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado)); fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo)); fo->rewrite(&linfo, sizeof(linfo));
} }
void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{ {
// offset of p_info in compressed file // offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo); overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
}
super::pack4(fo, ft); super::pack4(fo, ft);
segcmdo.filesize = fo->getBytesWritten(); unsigned const t = fo->getBytesWritten();
segcmdo.vmsize += segcmdo.filesize; segTEXT.filesize = t;
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
secTEXT.offset = overlay_offset - sizeof(linfo);
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
if (foff1 < segTEXT.vmsize)
foff1 += PAGE_SIZE; // codesign disallows overhang
segLINK.fileoff = foff1;
segLINK.vmaddr = segTEXT.vmaddr + foff1;
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
fo->seek(sizeof(mhdro), SEEK_SET); fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segcmdo, sizeof(segcmdo)); fo->rewrite(&segZERO, sizeof(segZERO));
fo->rewrite(&segXHDR, sizeof(segXHDR));
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado)); fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo)); fo->rewrite(&linfo, sizeof(linfo));
} }
void PackMachAMD64::pack4(OutputFile *fo, Filter &ft) // append PackHeader void PackMachAMD64::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{ {
// offset of p_info in compressed file // offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo); overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
}
super::pack4(fo, ft); super::pack4(fo, ft);
segcmdo.filesize = fo->getBytesWritten(); unsigned const t = fo->getBytesWritten();
segcmdo.vmsize += segcmdo.filesize; segTEXT.filesize = t;
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
secTEXT.offset = overlay_offset - sizeof(linfo);
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
if (foff1 < segTEXT.vmsize)
foff1 += PAGE_SIZE; // codesign disallows overhang
segLINK.fileoff = foff1;
segLINK.vmaddr = segTEXT.vmaddr + foff1;
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
fo->seek(sizeof(mhdro), SEEK_SET); fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segcmdo, sizeof(segcmdo)); fo->rewrite(&segZERO, sizeof(segZERO));
fo->rewrite(&segXHDR, sizeof(segXHDR));
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado)); fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo)); fo->rewrite(&linfo, sizeof(linfo));
} }
void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{ {
// offset of p_info in compressed file // offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo); overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
}
super::pack4(fo, ft); super::pack4(fo, ft);
segcmdo.filesize = fo->getBytesWritten(); unsigned const t = fo->getBytesWritten();
segcmdo.vmsize += segcmdo.filesize; segTEXT.filesize = t;
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
secTEXT.offset = overlay_offset - sizeof(linfo);
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
if (foff1 < segTEXT.vmsize)
foff1 += PAGE_SIZE; // codesign disallows overhang
segLINK.fileoff = foff1;
segLINK.vmaddr = segTEXT.vmaddr + foff1;
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
fo->seek(sizeof(mhdro), SEEK_SET); fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segcmdo, sizeof(segcmdo)); fo->rewrite(&segZERO, sizeof(segZERO));
fo->rewrite(&segXHDR, sizeof(segXHDR));
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado)); fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo)); fo->rewrite(&linfo, sizeof(linfo));
} }
#undef PAGE_MASK
#undef PAGE_SIZE
#define PAGE_MASK (~0u<<12)
#define PAGE_SIZE -PAGE_MASK
#undef PAGE_MASK64
#undef PAGE_SIZE64
#define PAGE_MASK64 (~(acc_uint64l_t)0<<12)
#define PAGE_SIZE64 -PAGE_MASK64
template <class T> template <class T>
void PackMachBase<T>::pack4dylib( // append PackHeader void PackMachBase<T>::pack4dylib( // append PackHeader
OutputFile *const fo, OutputFile *const fo,
@@ -726,7 +860,7 @@ void PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
disp = 4+ len - sz_mach_headers; // 4: sizeof(instruction) disp = 4+ len - sz_mach_headers; // 4: sizeof(instruction)
fo->write(&disp, sizeof(disp)); fo->write(&disp, sizeof(disp));
threado.state.srr0 = len + segcmdo.vmaddr; /* entry address */ threado.state.srr0 = len + segTEXT.vmaddr; /* entry address */
super::pack3(fo, ft); super::pack3(fo, ft);
} }
@@ -740,7 +874,7 @@ void PackMachI386::pack3(OutputFile *fo, Filter &ft) // append loader
disp = len - sz_mach_headers; disp = len - sz_mach_headers;
fo->write(&disp, sizeof(disp)); fo->write(&disp, sizeof(disp));
threado.state.eip = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */ threado.state.eip = len + sizeof(disp) + segTEXT.vmaddr; /* entry address */
super::pack3(fo, ft); super::pack3(fo, ft);
} }
@@ -754,7 +888,7 @@ void PackMachAMD64::pack3(OutputFile *fo, Filter &ft) // append loader
disp = len - sz_mach_headers; disp = len - sz_mach_headers;
fo->write(&disp, sizeof(disp)); fo->write(&disp, sizeof(disp));
threado.state.rip = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */ threado.state.rip = len + sizeof(disp) + segTEXT.vmaddr; /* entry address */
super::pack3(fo, ft); super::pack3(fo, ft);
} }
@@ -768,7 +902,7 @@ void PackMachARMEL::pack3(OutputFile *fo, Filter &ft) // append loader
disp = len - sz_mach_headers; disp = len - sz_mach_headers;
fo->write(&disp, sizeof(disp)); fo->write(&disp, sizeof(disp));
threado.state.pc = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */ threado.state.pc = len + sizeof(disp) + segTEXT.vmaddr; /* entry address */
super::pack3(fo, ft); super::pack3(fo, ft);
} }
@@ -899,7 +1033,7 @@ void PackMachBase<T>::pack3(OutputFile *fo, Filter &ft)
} }
template <class T> template <class T>
void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed body int PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed body
{ {
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3]; unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
Extent x; Extent x;
@@ -976,7 +1110,10 @@ void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
if (my_filetype!=Mach_header::MH_DYLIB) if (my_filetype!=Mach_header::MH_DYLIB)
if ((off_t)total_in != file_size) if ((off_t)total_in != file_size)
throwEOFException(); throwEOFException();
segcmdo.filesize = fo->getBytesWritten(); segTEXT.filesize = fo->getBytesWritten();
secTEXT.size = segTEXT.filesize - overlay_offset + sizeof(linfo);
return 1;
} }
void PackMachPPC32::pack1_setup_threado(OutputFile *const fo) void PackMachPPC32::pack1_setup_threado(OutputFile *const fo)
@@ -1025,34 +1162,82 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3]; unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
mhdro = mhdri; mhdro = mhdri;
if (my_filetype==Mach_header::MH_EXECUTE) { if (my_filetype==Mach_header::MH_EXECUTE) {
mhdro.ncmds = 2; mhdro.ncmds = 5; // __ZERO, __XHDR, __TEXT, __LINKEDIT, THREAD_STATE
mhdro.sizeofcmds = sizeof(segcmdo) + my_thread_command_size; mhdro.sizeofcmds = sizeof(segZERO)
mhdro.flags = Mach_header::MH_NOUNDEFS; + sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT) + sizeof(segLINK) +
my_thread_command_size /* + sizeof(uuid_cmd) + sizeof(linkitem) */ ;
mhdro.flags = Mach_header::MH_NOUNDEFS | Mach_header::MH_DYLDLINK;
} }
fo->write(&mhdro, sizeof(mhdro)); fo->write(&mhdro, sizeof(mhdro));
segcmdo.cmd = lc_seg; memset(&segZERO, 0, sizeof(segZERO));
segcmdo.cmdsize = sizeof(segcmdo); segZERO.cmd = lc_seg;
strncpy((char *)segcmdo.segname, "__TEXT", sizeof(segcmdo.segname)); segZERO.cmdsize = sizeof(segZERO);
strncpy((char *)segZERO.segname, "__PAGEZERO", sizeof(segZERO.segname));
segZERO.vmsize = PAGE_SIZE;
segTEXT.cmd = lc_seg;
segTEXT.cmdsize = sizeof(segTEXT) + sizeof(secTEXT);
strncpy((char *)segTEXT.segname, "__TEXT", sizeof(segTEXT.segname));
if (my_filetype==Mach_header::MH_EXECUTE) { if (my_filetype==Mach_header::MH_EXECUTE) {
segcmdo.vmaddr = PAGE_MASK64 & (~PAGE_MASK64 + int k; // must ignore zero-length segments, which sort last
msegcmd[n_segment -1].vmsize + msegcmd[n_segment -1].vmaddr ); for (k=n_segment; --k>=0; )
if (msegcmd[k].vmsize!=0)
break;
segTEXT.vmaddr = PAGE_MASK64 & (~PAGE_MASK64 +
msegcmd[k].vmsize + msegcmd[k].vmaddr );
} }
if (my_filetype==Mach_header::MH_DYLIB) { if (my_filetype==Mach_header::MH_DYLIB) {
segcmdo.vmaddr = 0; segTEXT.vmaddr = 0;
} }
segcmdo.vmsize = 0; // adjust later segTEXT.vmsize = 0; // adjust later
segcmdo.fileoff = 0; segTEXT.fileoff = 0;
segcmdo.filesize = 0; // adjust later segTEXT.filesize = 0; // adjust later
segcmdo.initprot = segcmdo.maxprot = segTEXT.initprot = segTEXT.maxprot =
Mach_segment_command::VM_PROT_READ | Mach_segment_command::VM_PROT_READ |
Mach_segment_command::VM_PROT_WRITE | Mach_segment_command::VM_PROT_WRITE |
Mach_segment_command::VM_PROT_EXECUTE; Mach_segment_command::VM_PROT_EXECUTE;
segcmdo.nsects = 0; segTEXT.nsects = 1; // secTEXT
segcmdo.flags = 0; segTEXT.flags = 0;
memset(&secTEXT, 0, sizeof(secTEXT));
strncpy((char *)secTEXT.sectname, "__text", sizeof(secTEXT.sectname));
memcpy(secTEXT.segname, segTEXT.segname, sizeof(secTEXT.segname));
secTEXT.align = 2; // (1<<2) ==> 4
segXHDR = segTEXT;
segXHDR.vmaddr = PAGE_SIZE;
segXHDR.vmsize = PAGE_SIZE;
segXHDR.filesize = PAGE_SIZE;
strncpy((char *)segXHDR.segname, "__XHDR", sizeof(segXHDR.segname));
memset(&secXHDR, 0, sizeof(secXHDR));
strncpy((char *)secXHDR.sectname, "__xhdr", sizeof(secXHDR.sectname));
memcpy(secXHDR.segname, segXHDR.segname, sizeof(secXHDR.segname));
secXHDR.addr = PAGE_SIZE;
secXHDR.size = 0; // empty so far
secXHDR.align = 2; // (1<<2) ==> 4
segLINK = segTEXT;
segLINK.cmdsize = sizeof(segLINK);
strncpy((char *)segLINK.segname, "__LINKEDIT", sizeof(segLINK.segname));
segLINK.nsects = 0;
segLINK.initprot = Mach_segment_command::VM_PROT_READ;
// Adjust later: .vmaddr .vmsize .fileoff .filesize
if (my_filetype==Mach_header::MH_EXECUTE) { if (my_filetype==Mach_header::MH_EXECUTE) {
fo->write(&segcmdo, sizeof(segcmdo)); fo->write(&segZERO, sizeof(segZERO));
fo->write(&segXHDR, sizeof(segXHDR));
fo->write(&secXHDR, sizeof(secXHDR));
fo->write(&segTEXT, sizeof(segTEXT));
fo->write(&secTEXT, sizeof(secTEXT));
fo->write(&segLINK, sizeof(segLINK));
pack1_setup_threado(fo); pack1_setup_threado(fo);
memset(&uuid_cmd, 0, sizeof(uuid_cmd));
fo->write(&uuid_cmd, sizeof(uuid_cmd));
memset(&linkitem, 0, sizeof(linkitem));
fo->write(&linkitem, sizeof(linkitem));
} }
if (my_filetype==Mach_header::MH_DYLIB) { if (my_filetype==Mach_header::MH_DYLIB) {
fo->write(rawmseg, mhdri.sizeofcmds); fo->write(rawmseg, mhdri.sizeofcmds);
@@ -1073,7 +1258,11 @@ void PackMachBase<T>::unpack(OutputFile *fo)
fi->readx(&mhdri, sizeof(mhdri)); fi->readx(&mhdri, sizeof(mhdri));
rawmseg = (Mach_segment_command *)new char[(unsigned) mhdri.sizeofcmds]; rawmseg = (Mach_segment_command *)new char[(unsigned) mhdri.sizeofcmds];
fi->readx(rawmseg, mhdri.sizeofcmds); fi->readx(rawmseg, mhdri.sizeofcmds);
overlay_offset = sizeof(mhdri) + mhdri.sizeofcmds + sizeof(linfo);
// FIXME forgot space left for LC_CODE_SIGNATURE;
// but PackUnix::canUnpack() sets overlay_offset anyway.
//overlay_offset = sizeof(mhdri) + mhdri.sizeofcmds + sizeof(linfo);
fi->seek(overlay_offset, SEEK_SET); fi->seek(overlay_offset, SEEK_SET);
p_info hbuf; p_info hbuf;
fi->readx(&hbuf, sizeof(hbuf)); fi->readx(&hbuf, sizeof(hbuf));
@@ -1126,6 +1315,8 @@ void PackMachBase<T>::unpack(OutputFile *fo)
) { ) {
if (lc_seg==sc->cmd if (lc_seg==sc->cmd
&& 0!=sc->filesize ) { && 0!=sc->filesize ) {
if (fo)
fo->seek(sc->fileoff, SEEK_SET);
unsigned filesize = sc->filesize; unsigned filesize = sc->filesize;
unpackExtent(filesize, fo, total_in, total_out, unpackExtent(filesize, fo, total_in, total_out,
c_adler, u_adler, false, sizeof(bhdr)); c_adler, u_adler, false, sizeof(bhdr));
@@ -1147,11 +1338,13 @@ void PackMachBase<T>::unpack(OutputFile *fo)
if (lc_seg==rc->cmd if (lc_seg==rc->cmd
&& 0!=rc->filesize ) { && 0!=rc->filesize ) {
fi->seek(rc->fileoff, SEEK_SET); fi->seek(rc->fileoff, SEEK_SET);
fo->seek(sc->fileoff, SEEK_SET); if (fo)
fo->seek(sc->fileoff, SEEK_SET);
unsigned const len = rc->filesize; unsigned const len = rc->filesize;
MemBuffer data(len); MemBuffer data(len);
fi->readx(data, len); fi->readx(data, len);
fo->write(data, len); if (fo)
fo->write(data, len);
} }
} }
} }
@@ -1159,14 +1352,14 @@ void PackMachBase<T>::unpack(OutputFile *fo)
for (unsigned j = 0; j < ncmds; ++j) { for (unsigned j = 0; j < ncmds; ++j) {
unsigned const size = find_SEGMENT_gap(j); unsigned const size = find_SEGMENT_gap(j);
if (size) { if (size) {
unsigned const where = msegcmd[k].fileoff +msegcmd[k].filesize; unsigned const where = msegcmd[j].fileoff +msegcmd[j].filesize;
if (fo) if (fo)
fo->seek(where, SEEK_SET); fo->seek(where, SEEK_SET);
unpackExtent(size, fo, total_in, total_out, unpackExtent(size, fo, total_in, total_out,
c_adler, u_adler, false, sizeof(bhdr)); c_adler, u_adler, false, sizeof(bhdr));
} }
} }
delete mhdr; delete [] mhdr;
} }
@@ -1207,19 +1400,19 @@ bool PackMachBase<T>::canPack()
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr. // Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command); qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command);
// Check that LC_SEGMENTs form one contiguous chunk of the file. // Check alignment of non-null LC_SEGMENT.
for (unsigned j= 0; j < ncmds; ++j) { for (unsigned j= 0; j < ncmds; ++j) {
if (lc_seg==msegcmd[j].cmd) { if (lc_seg==msegcmd[j].cmd) {
if (~PAGE_MASK & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) { if (~PAGE_MASK & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) {
return false; return false;
} }
if (0 < j) { if (msegcmd[j].vmsize==0)
unsigned const sz = PAGE_MASK break; // was sorted last
& (~PAGE_MASK + msegcmd[j-1].filesize);
if ((sz + msegcmd[j-1].fileoff)!=msegcmd[j].fileoff) { // We used to check that LC_SEGMENTS were contiguous,
return false; // but apparently that is not needed anymore,
} // and Google compilers generate strange layouts.
}
++n_segment; ++n_segment;
sz_segment = msegcmd[j].filesize + msegcmd[j].fileoff - msegcmd[0].fileoff; sz_segment = msegcmd[j].filesize + msegcmd[j].fileoff - msegcmd[0].fileoff;
} }
+49 -5
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -269,6 +269,25 @@ __packed_struct(Mach_twolevel_hints_command)
#include "p_mach_enum.h" #include "p_mach_enum.h"
__packed_struct_end() __packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_linkedit_data_command)
typedef typename TMachITypes::Word Word;
Word cmd;
Word cmdsize;
Word dataoff; // file offset of data in __LINKEDIT segment
Word datasize; // file size of data in __LINKEDIT segment
__packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_uuid_command)
typedef typename TMachITypes::Word Word;
Word cmd;
Word cmdsize;
unsigned char uuid[16];
__packed_struct_end()
template <class TMachITypes> template <class TMachITypes>
__packed_struct(Mach_ppc_thread_state) __packed_struct(Mach_ppc_thread_state)
typedef typename TMachITypes::Addr Addr; typedef typename TMachITypes::Addr Addr;
@@ -392,6 +411,8 @@ struct MachClass_32
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command; typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
typedef N_Mach::Mach_routines_command<MachITypes> Mach_routines_command; typedef N_Mach::Mach_routines_command<MachITypes> Mach_routines_command;
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command; typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
typedef N_Mach::Mach_linkedit_data_command<MachITypes> Mach_linkedit_data_command;
typedef N_Mach::Mach_uuid_command<MachITypes> Mach_uuid_command;
typedef N_Mach::Mach_ppc_thread_state<MachITypes> Mach_ppc_thread_state; typedef N_Mach::Mach_ppc_thread_state<MachITypes> Mach_ppc_thread_state;
typedef N_Mach::Mach_i386_thread_state<MachITypes> Mach_i386_thread_state; typedef N_Mach::Mach_i386_thread_state<MachITypes> Mach_i386_thread_state;
typedef N_Mach::Mach_AMD64_thread_state<MachITypes> Mach_AMD64_thread_state; typedef N_Mach::Mach_AMD64_thread_state<MachITypes> Mach_AMD64_thread_state;
@@ -428,6 +449,8 @@ struct MachClass_64
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command; typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
typedef N_Mach::Mach_routines_command_64<MachITypes> Mach_routines_command; typedef N_Mach::Mach_routines_command_64<MachITypes> Mach_routines_command;
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command; typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
typedef N_Mach::Mach_linkedit_data_command<MachITypes> Mach_linkedit_data_command;
typedef N_Mach::Mach_uuid_command<MachITypes> Mach_uuid_command;
static void compileTimeAssertions() { static void compileTimeAssertions() {
BeLePolicy::compileTimeAssertions(); BeLePolicy::compileTimeAssertions();
@@ -452,6 +475,8 @@ typedef MachClass_Host32::Mach_dysymtab_command Mach32_dysymtab_command;
typedef MachClass_Host32::Mach_segsplit_info_command Mach32_segsplit_info_command; typedef MachClass_Host32::Mach_segsplit_info_command Mach32_segsplit_info_command;
typedef MachClass_Host32::Mach_routines_command Mach32_routines_command; typedef MachClass_Host32::Mach_routines_command Mach32_routines_command;
typedef MachClass_Host32::Mach_twolevel_hints_command Mach32_twolevel_hints_command; typedef MachClass_Host32::Mach_twolevel_hints_command Mach32_twolevel_hints_command;
typedef MachClass_Host32::Mach_linkedit_data_command Mach32_linkedit_data_command;
typedef MachClass_Host32::Mach_uuid_command Mach32_uuid_command;
typedef MachClass_Host64::Mach_segment_command Mach64_segment_command; typedef MachClass_Host64::Mach_segment_command Mach64_segment_command;
typedef MachClass_Host64::Mach_section_command Mach64_section_command; typedef MachClass_Host64::Mach_section_command Mach64_section_command;
@@ -460,6 +485,8 @@ typedef MachClass_Host64::Mach_dysymtab_command Mach64_dysymtab_command;
typedef MachClass_Host64::Mach_segsplit_info_command Mach64_segsplit_info_command; typedef MachClass_Host64::Mach_segsplit_info_command Mach64_segsplit_info_command;
typedef MachClass_Host64::Mach_routines_command Mach64_routines_command; typedef MachClass_Host64::Mach_routines_command Mach64_routines_command;
typedef MachClass_Host64::Mach_twolevel_hints_command Mach64_twolevel_hints_command; typedef MachClass_Host64::Mach_twolevel_hints_command Mach64_twolevel_hints_command;
typedef MachClass_Host64::Mach_linkedit_data_command Mach64_linkedit_data_command;
typedef MachClass_Host64::Mach_uuid_command Mach64_uuid_command;
typedef MachClass_BE32::Mach_segment_command MachBE32_segment_command; typedef MachClass_BE32::Mach_segment_command MachBE32_segment_command;
typedef MachClass_BE32::Mach_section_command MachBE32_section_command; typedef MachClass_BE32::Mach_section_command MachBE32_section_command;
@@ -468,6 +495,8 @@ typedef MachClass_BE32::Mach_dysymtab_command MachBE32_dysymtab_command;
typedef MachClass_BE32::Mach_segsplit_info_command MachBE32_segsplit_info_command; typedef MachClass_BE32::Mach_segsplit_info_command MachBE32_segsplit_info_command;
typedef MachClass_BE32::Mach_routines_command MachBE32_routines_command; typedef MachClass_BE32::Mach_routines_command MachBE32_routines_command;
typedef MachClass_BE32::Mach_twolevel_hints_command MachBE32_twolevel_hints_command; typedef MachClass_BE32::Mach_twolevel_hints_command MachBE32_twolevel_hints_command;
typedef MachClass_BE32::Mach_linkedit_data_command MachBE32_linkedit_data_command;
typedef MachClass_BE32::Mach_uuid_command MachBE32_uuid_command;
typedef MachClass_BE64::Mach_segment_command MachBE64_segment_command; typedef MachClass_BE64::Mach_segment_command MachBE64_segment_command;
typedef MachClass_BE64::Mach_section_command MachBE64_section_command; typedef MachClass_BE64::Mach_section_command MachBE64_section_command;
@@ -476,6 +505,8 @@ typedef MachClass_BE64::Mach_dysymtab_command MachBE64_dysymtab_command;
typedef MachClass_BE64::Mach_segsplit_info_command MachBE64_segsplit_info_command; typedef MachClass_BE64::Mach_segsplit_info_command MachBE64_segsplit_info_command;
typedef MachClass_BE64::Mach_routines_command MachBE64_routines_command; typedef MachClass_BE64::Mach_routines_command MachBE64_routines_command;
typedef MachClass_BE64::Mach_twolevel_hints_command MachBE64_twolevel_hints_command; typedef MachClass_BE64::Mach_twolevel_hints_command MachBE64_twolevel_hints_command;
typedef MachClass_BE64::Mach_linkedit_data_command MachBE64_linkedit_data_command;
typedef MachClass_BE64::Mach_uuid_command MachBE64_uuid_command;
typedef MachClass_LE32::Mach_segment_command MachLE32_segment_command; typedef MachClass_LE32::Mach_segment_command MachLE32_segment_command;
typedef MachClass_LE32::Mach_section_command MachLE32_section_command; typedef MachClass_LE32::Mach_section_command MachLE32_section_command;
@@ -484,6 +515,8 @@ typedef MachClass_LE32::Mach_dysymtab_command MachLE32_dysymtab_command;
typedef MachClass_LE32::Mach_segsplit_info_command MachLE32_segsplit_info_command; typedef MachClass_LE32::Mach_segsplit_info_command MachLE32_segsplit_info_command;
typedef MachClass_LE32::Mach_routines_command MachLE32_routines_command; typedef MachClass_LE32::Mach_routines_command MachLE32_routines_command;
typedef MachClass_LE32::Mach_twolevel_hints_command MachLE32_twolevel_hints_command; typedef MachClass_LE32::Mach_twolevel_hints_command MachLE32_twolevel_hints_command;
typedef MachClass_LE32::Mach_linkedit_data_command MachLE32_linkedit_data_command;
typedef MachClass_LE32::Mach_uuid_command MachLE32_uuid_command;
typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command; typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command;
typedef MachClass_LE64::Mach_section_command MachLE64_section_command; typedef MachClass_LE64::Mach_section_command MachLE64_section_command;
@@ -492,6 +525,8 @@ typedef MachClass_LE64::Mach_dysymtab_command MachLE64_dysymtab_command;
typedef MachClass_LE64::Mach_segsplit_info_command MachLE64_segsplit_info_command; typedef MachClass_LE64::Mach_segsplit_info_command MachLE64_segsplit_info_command;
typedef MachClass_LE64::Mach_routines_command MachLE64_routines_command; typedef MachClass_LE64::Mach_routines_command MachLE64_routines_command;
typedef MachClass_LE64::Mach_twolevel_hints_command MachLE64_twolevel_hints_command; typedef MachClass_LE64::Mach_twolevel_hints_command MachLE64_twolevel_hints_command;
typedef MachClass_LE64::Mach_linkedit_data_command MachLE64_linkedit_data_command;
typedef MachClass_LE64::Mach_uuid_command MachLE64_uuid_command;
typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state; typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state;
typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state; typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state;
@@ -522,6 +557,8 @@ protected:
typedef typename MachClass::Mach_segsplit_info_command Mach_segsplit_info_command; typedef typename MachClass::Mach_segsplit_info_command Mach_segsplit_info_command;
typedef typename MachClass::Mach_routines_command Mach_routines_command; typedef typename MachClass::Mach_routines_command Mach_routines_command;
typedef typename MachClass::Mach_twolevel_hints_command Mach_twolevel_hints_command; typedef typename MachClass::Mach_twolevel_hints_command Mach_twolevel_hints_command;
typedef typename MachClass::Mach_linkedit_data_command Mach_linkedit_data_command;
typedef typename MachClass::Mach_uuid_command Mach_uuid_command;
public: public:
PackMachBase(InputFile *, unsigned cpuid, unsigned filetype, PackMachBase(InputFile *, unsigned cpuid, unsigned filetype,
@@ -532,7 +569,7 @@ public:
// called by the generic pack() // called by the generic pack()
virtual void pack1(OutputFile *, Filter &); // generate executable header virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data virtual int pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &) = 0; // append loader virtual void pack3(OutputFile *, Filter &) = 0; // append loader
virtual void pack4(OutputFile *, Filter &) = 0; // append PackHeader virtual void pack4(OutputFile *, Filter &) = 0; // append PackHeader
@@ -571,11 +608,18 @@ protected:
Mach_segment_command *rawmseg; // as input, with sections Mach_segment_command *rawmseg; // as input, with sections
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
unsigned o_routines_cmd; // file offset to LC_ROUINTES unsigned o_routines_cmd; // file offset to LC_ROUINTES
acc_uint64l_t prev_init_address; upx_uint64_t prev_init_address;
Mach_header mhdri; Mach_header mhdri;
Mach_header mhdro; Mach_header mhdro;
Mach_segment_command segcmdo; Mach_segment_command segZERO;
Mach_segment_command segXHDR; // location to put eXtra headers
Mach_section_command secXHDR;
Mach_segment_command segTEXT;
Mach_section_command secTEXT;
Mach_segment_command segLINK;
Mach_linkedit_data_command linkitem;
Mach_uuid_command uuid_cmd;
__packed_struct(b_info) // 12-byte header before each compressed block __packed_struct(b_info) // 12-byte header before each compressed block
TE32 sz_unc; // uncompressed_size TE32 sz_unc; // uncompressed_size
+4 -3
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 2007-2011 John F. Reiser Copyright (C) 2007-2013 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
@@ -53,10 +53,11 @@
enum { // filetype enum { // filetype
MH_EXECUTE = 2, MH_EXECUTE = 2,
MH_DYLIB = 6, MH_DYLIB = 6,
MH_BUNDLE = 8 /* dynamically bound bundle file */ MH_BUNDLE = 8 /* dynamically bound bundle file */
}; };
enum { // flags enum { // flags
MH_NOUNDEFS = 1 MH_NOUNDEFS = 1,
MH_DYLDLINK = 4 /* code signing demands this */
}; };
#endif /*}*/ #endif /*}*/
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2002-2011 Jens Medoch Copyright (C) 2002-2013 Jens Medoch
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
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2002-2011 Jens Medoch Copyright (C) 2002-2013 Jens Medoch
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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+27 -14
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -130,7 +130,7 @@ int PackUnix::getStrategy(Filter &/*ft*/)
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2)); return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
} }
void PackUnix::pack2(OutputFile *fo, Filter &ft) int PackUnix::pack2(OutputFile *fo, Filter &ft)
{ {
// compress blocks // compress blocks
unsigned total_in = 0; unsigned total_in = 0;
@@ -142,6 +142,7 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
// ui_total_passes = 0; // ui_total_passes = 0;
unsigned remaining = file_size; unsigned remaining = file_size;
unsigned n_block = 0;
while (remaining > 0) while (remaining > 0)
{ {
// FIXME: disable filters if we have more than one block. // FIXME: disable filters if we have more than one block.
@@ -170,7 +171,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
// that is, AFTER filtering. We want BEFORE filtering, // that is, AFTER filtering. We want BEFORE filtering,
// so that decompression checks the end-to-end checksum. // so that decompression checks the end-to-end checksum.
unsigned const end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler); unsigned const end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler);
compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy); compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy,
!!n_block++); // check compression ratio only on first block
if (ph.c_len < ph.u_len) { if (ph.c_len < ph.u_len) {
const upx_bytep tbuf = NULL; const upx_bytep tbuf = NULL;
@@ -222,6 +224,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
if ((off_t)total_in != file_size) { if ((off_t)total_in != file_size) {
throwEOFException(); throwEOFException();
} }
return 1; // default: write end-of-compression bhdr next
} }
void void
@@ -283,12 +287,13 @@ void PackUnix::pack(OutputFile *fo)
set_te32(&hbuf.p_blocksize, blocksize); set_te32(&hbuf.p_blocksize, blocksize);
fo->write(&hbuf, sizeof(hbuf)); fo->write(&hbuf, sizeof(hbuf));
pack2(fo, ft); // append the compressed body // append the compressed body
if (pack2(fo, ft)) {
// write block end marker (uncompressed size 0) // write block end marker (uncompressed size 0)
b_info hdr; memset(&hdr, 0, sizeof(hdr)); b_info hdr; memset(&hdr, 0, sizeof(hdr));
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32); set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
fo->write(&hdr, sizeof(hdr)); fo->write(&hdr, sizeof(hdr));
}
pack3(fo, ft); // append loader pack3(fo, ft); // append loader
@@ -498,18 +503,26 @@ void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
int PackUnix::canUnpack() int PackUnix::canUnpack()
{ {
upx_byte buf[sizeof(overlay_offset) + 32]; int const small = 32 + sizeof(overlay_offset);
const int bufsize = sizeof(buf); // Allow zero-filled last page, for Mac OS X code signing.
int bufsize = 2*4096 + 2*small +1;
if (bufsize > fi->st_size())
bufsize = fi->st_size();
MemBuffer buf(bufsize);
fi->seek(-bufsize, SEEK_END); fi->seek(-bufsize, SEEK_END);
fi->readx(buf, bufsize); fi->readx(buf, bufsize);
if (!getPackHeader(buf, bufsize, true)) // allow incompressible extents int i = bufsize;
while (i > small && 0 == buf[--i]) { }
i -= small;
// allow incompressible extents
if (i < 0 || !getPackHeader(buf + i, bufsize - i, true))
return false; return false;
int l = ph.buf_offset + ph.getPackHeaderSize(); int l = ph.buf_offset + ph.getPackHeaderSize();
if (l < 0 || l + 4 > bufsize) if (l < 0 || l + 4 > bufsize)
throwCantUnpack("file corrupted"); throwCantUnpack("file corrupted");
overlay_offset = get_te32(buf+l); overlay_offset = get_te32(buf + i + l);
if ((off_t)overlay_offset >= file_size) if ((off_t)overlay_offset >= file_size)
throwCantUnpack("file corrupted"); throwCantUnpack("file corrupted");
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -54,7 +54,7 @@ public:
protected: protected:
// called by the generic pack() // called by the generic pack()
virtual void pack1(OutputFile *, Filter &); // generate executable header virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data virtual int pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &); // append loader virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append PackHeader virtual void pack4(OutputFile *, Filter &); // append PackHeader
+3 -3
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) 2004-2011 John Reiser Copyright (C) 2004-2013 John Reiser
Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+3 -3
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -591,7 +591,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
if (M_IS_LZMA(ph.method)) { if (M_IS_LZMA(ph.method)) {
const lzma_compress_result_t *res = &ph.compress_result.result_lzma; const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
acc_uint32e_t properties = // lc, lp, pb, dummy upx_uint32_t properties = // lc, lp, pb, dummy
(res->lit_context_bits << 0) | (res->lit_context_bits << 0) |
(res->lit_pos_bits << 8) | (res->lit_pos_bits << 8) |
(res->pos_bits << 16); (res->pos_bits << 16);
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
+5 -5
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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
@@ -834,7 +834,7 @@ void PackW32Pe::pack(OutputFile *fo)
throwCantPack("PE32/EFIROM files are not yet supported"); throwCantPack("PE32/EFIROM files are not yet supported");
break; break;
} }
case 14: //XBOX - will we ever see an XBOX file? case 14: //XBOX - will we ever see a XBOX file?
{ {
throwCantPack("PE32/xbox files are not yet supported"); throwCantPack("PE32/xbox files are not yet supported");
break; break;
@@ -917,7 +917,7 @@ void PackW32Pe::pack(OutputFile *fo)
if (!isrtm && ((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED)) if (!isrtm && ((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED))
== (PEFL_WRITE|PEFL_SHARED))) == (PEFL_WRITE|PEFL_SHARED)))
if (!opt->force) if (!opt->force)
throwCantPack("writeable shared sections not supported (try --force)"); throwCantPack("writable shared sections not supported (try --force)");
if (jc && isection[ic].rawdataptr - jc > ih.filealign) if (jc && isection[ic].rawdataptr - jc > ih.filealign)
throwCantPack("superfluous data between sections"); throwCantPack("superfluous data between sections");
fi->seek(isection[ic].rawdataptr,SEEK_SET); fi->seek(isection[ic].rawdataptr,SEEK_SET);
@@ -1092,7 +1092,7 @@ void PackW32Pe::pack(OutputFile *fo)
// still in a read only section by looking at the pe header of the // still in a read only section by looking at the pe header of the
// file. If this check fails the runtime does "interesting" things // file. If this check fails the runtime does "interesting" things
// like not running the floating point initialization code - the result // like not running the floating point initialization code - the result
// is an R6002 runtime error. // is a R6002 runtime error.
// These supposed to be read only addresses are covered by the sections // These supposed to be read only addresses are covered by the sections
// UPX0 & UPX1 in the compressed files, so we have to patch the PE header // UPX0 & UPX1 in the compressed files, so we have to patch the PE header
// in the memory. And the page on which the PE header is stored is read // in the memory. And the page on which the PE header is stored is read
+2 -2
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-2011 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2011 Laszlo Molnar 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

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