Compare commits

..

208 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
Markus F.X.J. Oberhumer fed3ed9f9a Prepare release. 2011-12-12 11:55:45 +01:00
Markus F.X.J. Oberhumer 260138ba11 Silence some compilation warnings. 2011-12-12 11:30:02 +01:00
John Reiser 67f7e0089c NEWS summary in preparation for release 2011-12-06 08:22:44 -08:00
John Reiser d4a22c7851 Sync stub for amd64-darwin.macho-entry. 2011-12-06 07:03:53 -08:00
John Reiser 06cf986490 overlap unfolded stub on Mach-O amd64 [SourceForge upx-Bugs-3447184] 2011-12-02 22:01:13 -08:00
John Reiser adf9aa04ce overlap unfolded stub on Mach-O i386 [SourceForge upx-Bugs-3447184] 2011-12-02 20:51:13 -08:00
John Reiser 69f66fbe52 rebuild using broader dependencies of previous commit 2011-11-23 13:25:25 -08:00
John Reiser d061005c89 propagate dependency on i386-linux.elf-main.c by hand 2011-11-23 13:23:11 -08:00
John Reiser f6ee8b9f04 MSVC++ disallows zero-length array in struct 2011-11-23 13:05:00 -08:00
John Reiser 31af22c2ff ARM_is_QNX looks for PT_INTERP containing "ldqnx" 2011-10-16 15:04:18 -07:00
John Reiser c421e3f243 ARM stub: fix editing mistake 2011-10-16 13:40:21 -07:00
John Reiser 6e92902407 ARM_is_QNX() heuristic 2011-10-16 13:11:03 -07:00
John Reiser 6256381dc3 mmap_privanon() in stub for arm,i386,mips eases QNX 2011-10-16 11:39:46 -07:00
John Reiser b247b051ea QNX on armel (experimental) 2011-10-15 19:49:37 -07:00
Markus F.X.J. Oberhumer afbd553622 Silence some compilation warnings. 2011-08-30 03:40:53 +02:00
John Reiser 36bc14e884 fix PackMachFat::unpack for test mode ("-t"): fo==NULL 2011-07-11 14:37:40 -07:00
John Reiser 9c5d0ff2ff PeFile::processRelocs() defends itself against corrupt PE header 2011-06-08 10:06:42 -07:00
John Reiser cfa6c8ddf6 Fix ::pack3 for shared library. 2011-06-06 20:00:43 -07:00
John Reiser 21924bf022 move stub escape hatch for shared library to end of .text [glibc-2.13.90] 2011-06-02 07:18:50 -07:00
John Reiser eea33f6019 Document copy ONLY for old_dtinit, .e_shoff in compressed shared library. 2011-05-31 11:01:40 -07:00
John Reiser 66d48ae808 MH_BUNDLE enum 2011-05-30 07:22:31 -07:00
John Reiser de9b9fd0b1 more messages in PackLinuxElf32::canPack 2011-05-30 07:21:51 -07:00
John Reiser ece7384be4 fpad4 from st_size(), not from getBytesWritten() 2011-05-28 12:18:27 -07:00
John Reiser 0c052e4506 amd64 output PT_LOAD[0] ends after loader 2011-05-20 10:29:04 -07:00
John Reiser 1996a0a3d6 32-bit shared libraries on i386 only (SourceForge bug 3286178) 2011-04-14 09:39:55 -07:00
László Molnár 679ad9b8c6 fixed computing of tls data end (sf.net bug 3256788) 2011-03-29 15:49:20 +02:00
John Reiser d4983731e7 More l_info.l_lszie and .l_checksum TargetEndian. 2011-03-28 11:11:05 -07:00
John Reiser 4fec3c8f34 Merge. 2011-03-28 10:45:47 -07:00
John Reiser 836fd2565f Place loader immediately after compressed PT_LOADs, in "middle" of file.
This moves compressed gaps and debuginfo out of compressed PT_LOADs,
and fixes a bug where large debuginfo would cause first mmap
at runtime to erase the loader (SourceForge bug 3239079).
2011-03-28 10:44:23 -07:00
John Reiser 54618064a1 l_info.l_lsize and .l_checksum are TargetEndian 2011-03-28 10:14:06 -07:00
John Reiser 519e3e01ae OutputFile implements read() and readx(); beware --stdout. 2011-03-28 10:12:36 -07:00
László Molnár aec8f81358 fixed a warning (sf.net bug 3241423) 2011-03-25 12:02:22 +01:00
John Reiser c1d6bf4366 avoid .so with DT_TEXTREL; SourceForge bug 3190915 2011-02-24 09:38:17 -08:00
Markus F.X.J. Oberhumer 9bf2b79d9e Enter 2011. 2011-01-03 08:49:23 +01:00
Markus F.X.J. Oberhumer 4d98408995 Remove trailing whitespace. 2010-12-29 15:46:55 +01:00
Markus F.X.J. Oberhumer 7b466388f9 Detabify. 2010-12-29 15:46:34 +01:00
Markus F.X.J. Oberhumer b926fb3c66 Fix __cdecl syntax error. 2010-12-24 10:38:30 +01:00
László Molnár 6c8d5c0d0e replaced abort() with internal_error() (sf.net bug 3101319) 2010-12-21 10:28:36 +01:00
László Molnár 5a1d234260 merge 2010-12-21 09:40:16 +01:00
John Reiser fd6d42c297 i386-linux.shlib-init needs empty LEXECDYN (sourceforge 3101319) 2010-12-20 10:20:10 -08:00
László Molnár 7310ad6e92 align TLS callbacks to 4 byte boundary 2010-12-20 14:57:24 +01:00
László Molnár 7e47b1348d fixed a typo 2010-12-20 10:51:29 +01:00
László Molnár 1e3555a6b7 added some input validity checks (for sf.net bug 3122661) 2010-12-20 00:35:57 +01:00
László Molnár 9a67ce5968 do not skip dlls with no imports from the preprocessed import data (sf.net bug 3125753) 2010-12-19 23:22:58 +01:00
Markus F.X.J. Oberhumer 279d7955f8 Keep entries sorted in Makefiles. 2010-12-03 01:04:16 +01:00
Markus F.X.J. Oberhumer db977c0bf5 Add a .dump file to repo. 2010-11-29 15:28:35 +01:00
Markus F.X.J. Oberhumer ba6bc59818 Update .hgignore. 2010-11-29 15:28:10 +01:00
John Reiser 6e8be0578c improve PIC_STRING 2010-11-18 08:23:08 -08:00
John Reiser 92f7d16b5e more flexible labels on trace output 2010-11-18 08:22:36 -08:00
John Reiser 40bb3c2f5e better PIC_STRING for __mips__ 2010-11-17 20:45:39 -08:00
John Reiser 56a6096221 better PIC_STRING for __mips__ 2010-11-17 20:42:01 -08:00
John Reiser ee37b42a91 DEBUG for MIPS i386-linux.elf-main.c 2010-11-17 20:21:41 -08:00
John Reiser 0806e61df4 move DEBUG_STRCON adjacent to uses 2010-11-17 15:17:03 -08:00
John Reiser 279ffeeefa unify DEBUG STR_* into i386-linux.elf-main.c from *.elf-fold.S 2010-11-17 14:32:24 -08:00
John Reiser 80c5ee2479 use up4() 2010-11-17 14:28:00 -08:00
John Reiser 16208544e5 ELFOSABI_NETBSD 2010-11-17 14:27:00 -08:00
John Reiser 6afeb24fdb use brand_netbsd 2010-11-17 12:49:29 -08:00
John Reiser e6357b81eb NetBSD version 5 requires PT_NOTE for PaX. Also adjust other *BSD and PT_NOTE.
[Tested OK on FreeBSD 8.1, NetBSD 5.1, OpenBSD 4.8.  Cleanup needed.]
2010-11-16 21:13:42 -08:00
John Reiser dfc2efe8a6 make_hatch_arm() needs sys_munmap; also fix ARM div10. 2010-11-15 11:51:46 -08:00
John Reiser f28b96f431 Stand-alone tracing for ARM stub; "#define DEBUG 1" then re-compile.
https://sourceforge.net/tracker/?func=detail&atid=102331&aid=3105926&group_id=2331
2010-11-13 21:30:34 -08:00
John Reiser a10293f8f7 ARM copy .e_flags from input to output to preserve soft_FP flag, etc. 2010-11-09 11:05:55 -08:00
John Reiser b1f02f91d7 NetBSD 5.0 wants PT_NOTE and branded executables 2010-11-09 10:47:53 -08:00
Markus F.X.J. Oberhumer e76fa45d86 Small upx_sanity_check() update. 2010-11-08 23:59:34 +01:00
Markus F.X.J. Oberhumer 06f43892a5 Set sane abort() default behaviour when using msvcrt. 2010-11-08 20:48:50 +01:00
Markus F.X.J. Oberhumer a094332b0d Silence some compilation warnings. 2010-10-23 11:40:41 +02:00
Markus F.X.J. Oberhumer 7b8779f534 Portability updates. 2010-10-20 01:46:38 +02:00
Markus F.X.J. Oberhumer 371bf20d19 New ACC version. 2010-10-17 10:10:23 +02:00
Markus F.X.J. Oberhumer 0f633ddd15 Bump version for next release. 2010-09-08 18:04:39 +02:00
Markus F.X.J. Oberhumer 7886ca7f5f Add tag for RELEASE_307. 2010-09-08 15:07:00 +00:00
Markus F.X.J. Oberhumer 9b4c11954d Prepare release. 2010-09-08 16:56:49 +02:00
László Molnár a1b724f30a NEWS updated 2010-09-08 16:02:04 +02:00
László Molnár 7c3b2fb9cc relocation entry for TLS callbacks is only needed when we do have TLS callbacks 2010-09-08 15:06:56 +02:00
Markus F.X.J. Oberhumer acef68d67e Bump version for next release. 2010-09-04 20:23:02 +02:00
Markus F.X.J. Oberhumer 7e393d5f1e Add tag for RELEASE_306. 2010-09-04 15:06:00 +00:00
Markus F.X.J. Oberhumer 955c31b165 Prepare release. 2010-09-04 13:11:59 +02:00
László Molnár e307cd48ad merge 2010-09-02 12:30:16 +02:00
László Molnár 25f8b9e451 added Stefan to THANKS 2010-09-02 12:27:50 +02:00
Markus F.X.J. Oberhumer e8ba14a2c1 Silence some compilation warnings. 2010-09-01 14:49:26 +02:00
Markus F.X.J. Oberhumer 9670d3341c Makefiles: sort result from wildcard, needed for unwise GNU make 3.82 change. 2010-09-01 14:10:14 +02:00
László Molnár cec9778fd5 added a NEWS entry for the win32 TLS callback stuff 2010-08-31 14:35:59 +02:00
John Reiser 7451db4a68 merge 2010-08-17 11:32:02 -07:00
John Reiser e31777ec53 ARM ELF EABI version 5
https://sourceforge.net/tracker/?func=detail&atid=102331&aid=3040129&group_id=2331
2010-08-17 11:30:17 -07:00
László Molnár 7aa0b3dc7a merge 2010-08-16 13:49:54 +02:00
László Molnár e7b2d5dc01 coding style updates - only whitespace changes 2010-08-16 13:36:10 +02:00
László Molnár 47d728667d merge 2010-08-16 13:20:28 +02:00
László Molnár e1f8989d54 removed dosish file endings 2010-08-16 13:09:27 +02:00
Stefan Widmann 1d8cb47830 TLS handling updated to v2, ASLR fix in unpacking 2010-08-13 17:44:21 +02:00
Markus F.X.J. Oberhumer faaa7c37a9 Remove duplicate file. 2010-08-08 16:32:59 +02:00
Markus F.X.J. Oberhumer 0aff9d8df4 Use consistent syntax for boolean preprocessor expressions. 2010-08-08 16:20:16 +02:00
Markus F.X.J. Oberhumer 30c3f8c1ac New ACC version. 2010-08-08 16:10:30 +02:00
John Reiser bcd2469e01 merge 2010-08-06 13:31:54 -07:00
John Reiser 983c6ae73d amd64 stub: relocate ADRX and ADRU after copy 2010-08-06 13:29:32 -07:00
Markus F.X.J. Oberhumer 6d8e1fe776 Start using acc_getopt. 2010-08-05 15:08:06 +02:00
Markus F.X.J. Oberhumer 99b4921309 New ACC version. 2010-08-05 15:06:03 +02:00
John Reiser 3c231c3c9e FreeBSD 8.x got picky about MAP_ANONYMOUS 2010-07-21 10:19:11 -07:00
John Reiser 175c0a6236 --unmap-all-pages affects i386-*BSD, too 2010-07-20 12:47:33 -07:00
John Reiser 0031ceb06c propagate changes from auxv_find() in i386-linux.elf-main.c 2010-07-17 08:22:09 -07:00
John Reiser e3cc5a63df don't erase AT_SYSINFO* if no conflict with decompressed folded stub 2010-07-17 08:19:50 -07:00
John Reiser 3cb61402c2 merge 2010-07-16 21:01:45 -07:00
John Reiser 5336c51199 Fix conflict between VDSO and unfolded decompressor for ET_DYN
(-fPIE) with unlimited stack on Linux-2.6.34 et al.
2010-07-16 20:58:52 -07:00
Markus F.X.J. Oberhumer 52aa658aaa Silence some compilation warnings. 2010-07-14 20:03:09 +02:00
John Reiser d08a51d7e4 fix don't-care uninit from valgrind(memcheck) 2010-07-07 09:52:58 -07:00
John Reiser d97a557ac3 unpacking PackMachFat::CPU_TYPE_X86_64 2010-06-28 16:02:57 -07:00
John Reiser 8a68d9cded more MACH_SEGMENT_ENUM; no code yet 2010-06-15 09:22:59 -07:00
László Molnár b031f7e902 always initialize variable use_tls_callbacks 2010-06-15 15:04:48 +02:00
Markus F.X.J. Oberhumer 963ffecb96 Update upx-tools link in README.SRC. 2010-06-09 15:15:37 +02:00
Markus F.X.J. Oberhumer 8f8aaca818 Remove trailing whitespace. 2010-06-06 22:40:10 +02:00
László Molnár 801f92b7e7 merge 2010-06-04 17:56:52 +02:00
László Molnár 44db45700e new version of .dump file 2010-06-04 17:55:13 +02:00
Stefan Widmann 25902005f6 win32/pe TLS handling added 2010-06-01 19:21:52 +02:00
John Reiser ffec71e0d8 Fix vmlinux/ppc32 at compress time. Runtime needs work. 2010-04-28 20:43:50 -07:00
John Reiser 99a208110b Detect LC_SEGMENT beyond end-of-file in PackMachBase<T>::find_SEGMENT_gap. 2010-04-28 20:05:23 -07:00
Markus F.X.J. Oberhumer e56799c993 Bump version for next release. 2010-04-27 17:26:05 +02:00
Markus F.X.J. Oberhumer 957eb300f8 Add tag for RELEASE_305. 2010-04-27 15:05:00 +00:00
384 changed files with 31638 additions and 20251 deletions
+5 -1
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
@@ -42,7 +44,9 @@ src/*.ttp
stub/**MMakefile stub/**MMakefile
stub/**.*-stamp stub/**.*-stamp
stub/tmp*/* ##stub/tmp*/*
stub/tmp*/*.{bin,bin.bindump,bin.disasm,d,map,o,o.disasm}
stub/tmp*/mips{,el}.r3000-*.{i,s}
stub/**/tmp*/* stub/**/tmp*/*
stub/tools/armpe/armpe_tester{,.exe,.out} stub/tools/armpe/armpe_tester{,.exe,.out}
+5
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
@@ -7,6 +8,7 @@
396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291 396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291
46f3a6cca02603000fadc16637b02e30caddd909 RELEASE_302 46f3a6cca02603000fadc16637b02e30caddd909 RELEASE_302
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200 70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
7c6747c82b167368344a238b1a3a87c2a4fa6a18 RELEASE_306
95c558f81a0b8d5bb2bede4c8208bb84ae7d1e58 RELEASE_303 95c558f81a0b8d5bb2bede4c8208bb84ae7d1e58 RELEASE_303
a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292 a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292
a916a2fe22de45167d25abcb40008315f415221c RELEASE_201 a916a2fe22de45167d25abcb40008315f415221c RELEASE_201
@@ -14,8 +16,11 @@ a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
b0353253b0b3d062eb5adb50d4b665a96620da45 RELEASE_195 b0353253b0b3d062eb5adb50d4b665a96620da45 RELEASE_195
b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192 c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
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
efa52753e366300c0e0ebe20631adcb24ed3c15b RELEASE_293 efa52753e366300c0e0ebe20631adcb24ed3c15b RELEASE_293
fe7acf61147e7031fcc304aae47ca2352056815d RELEASE_307
+2 -2
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer # Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR MAKEFLAGS += -rR
+33
View File
@@ -2,6 +2,39 @@
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):
* 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].
* Attempt to support ELF on QNX 6.3.0 for armel (experimental).
* Better diagnostic when ELF -fPIC is needed.
* PT_NOTE improvements for *BSD.
* Preserve more ELF .e_flags on ARM.
* Minor code improvements for ELF stubs.
* Defend against another flavor of corrupt PE header.
* bug fixes
Changes in 3.07 (08 Sep 2010):
* win32/pe: fixed relocation handling for files with *no* TLS callbacks
[severe bug introduced in 3.06]
Changes in 3.06 (04 Sep 2010):
* win32/pe: TLS callback support contributed by Stefan Widmann. Thanks!
* bug fixes
Changes in 3.05 (27 Apr 2010): Changes in 3.05 (27 Apr 2010):
* i386-linux and amd64-linux support shared libraries (DT_INIT must * i386-linux and amd64-linux support shared libraries (DT_INIT must
exist, all info needed by runtime loader must be first in .text, etc.) exist, all info needed by runtime loader must be first in .text, etc.)
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2010 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-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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-2010 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
+8 -1
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
@@ -98,7 +105,7 @@ If you want to modify the stub sources you'll also need
- A number of cross-assemblers and cross-compilers - precompiled - A number of cross-assemblers and cross-compilers - precompiled
binaries for i386-linux hosts are available from binaries for i386-linux hosts are available from
http://sourceforge.net/project/showfiles.php?group_id=2331 http://sourceforge.net/projects/upx/files/upx-tools/20060823/
Misc. notes Misc. notes
+3 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -53,6 +53,8 @@ Ralph Roth <RalphRoth@gmx.net>
for reporting several bugs for reporting several bugs
Salvador Eduardo Tropea Salvador Eduardo Tropea
for beta testing for beta testing
Stefan Widmann
for the win32/pe TLS callback support
The WINE project (http://www.winehq.com/) The WINE project (http://www.winehq.com/)
for lots of useful information found in their PE loader sources for lots of useful information found in their PE loader sources
Natascha Natascha
+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-2010 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-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 John F. Reiser Copyright (C) 2000-2013 John F. Reiser
Copyright (C) 2002-2010 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.
+3 -3
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-2010 Markus Franz Xaver Johannes Oberhumer # Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR MAKEFLAGS += -rR
@@ -49,7 +49,7 @@ exeext ?= .out
libext ?= .a libext ?= .a
objext ?= .o objext ?= .o
upx_SOURCES := $(wildcard $(srcdir)/*.cpp) upx_SOURCES := $(sort $(wildcard $(srcdir)/*.cpp))
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext))) upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
# we need UCL and zlib - you can set envvar UPX_UCLDIR # we need UCL and zlib - you can set envvar UPX_UCLDIR
@@ -77,7 +77,7 @@ upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
%.o : %.cpp | .depend %.o : %.cpp | .depend
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<) $(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
.depend: $(wildcard $(srcdir)/*.cpp $(srcdir)/*.h) $(MAKEFILE_LIST) .depend: $(sort $(wildcard $(srcdir)/*.cpp $(srcdir)/*.h)) $(MAKEFILE_LIST)
@rm -f $@ @rm -f $@
ifeq ($(USE_GNUC),1) ifeq ($(USE_GNUC),1)
@echo "Updating $@" @echo "Updating $@"
+47 -47
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_BELE_H #ifndef __UPX_BELE_H
#define __UPX_BELE_H #define __UPX_BELE_H 1
/************************************************************************* /*************************************************************************
@@ -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()
@@ -543,10 +543,10 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
// just for testing... // just for testing...
#if !defined(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
+15 -15
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -39,7 +39,7 @@
// CTP - Compile-Time Polymorphism (templates) // CTP - Compile-Time Polymorphism (templates)
# define V static inline # define V static inline
# define S static int __acc_cdecl_qsort # define S static int __acc_cdecl_qsort
# define C # define C /*empty*/
#elif defined(BELE_RTP) #elif defined(BELE_RTP)
// RTP - Run-Time Polymorphism (virtual functions) // RTP - Run-Time Polymorphism (virtual functions)
# define V virtual # define V virtual
@@ -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)
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_BPTR_H #ifndef __UPX_BPTR_H
#define __UPX_BPTR_H #define __UPX_BPTR_H 1
/************************************************************************* /*************************************************************************
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +28,7 @@
#include "conf.h" #include "conf.h"
#if defined(USE_CONSOLE) #if (USE_CONSOLE)
/************************************************************************* /*************************************************************************
// //
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -30,7 +30,7 @@
FILE *con_term = NULL; FILE *con_term = NULL;
#if defined(USE_CONSOLE) #if (USE_CONSOLE)
/************************************************************************* /*************************************************************************
// //
@@ -84,14 +84,14 @@ static int do_init(FILE *f)
if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO)) if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO))
return con_mode; return con_mode;
#if defined(USE_ANSI) #if (USE_ANSI)
try_init(&console_ansi_mono,f); try_init(&console_ansi_mono,f);
try_init(&console_ansi_color,f); try_init(&console_ansi_color,f);
#endif #endif
#if defined(USE_SCREEN) #if (USE_SCREEN)
try_init(&console_screen,f); try_init(&console_screen,f);
#endif #endif
#if defined(USE_AALIB) #if (USE_AALIB)
try_init(&console_aalib,f); try_init(&console_aalib,f);
#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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +28,7 @@
#include "conf.h" #include "conf.h"
#if defined(USE_CONSOLE) #if (USE_CONSOLE)
/************************************************************************* /*************************************************************************
// //
+7 -7
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +28,7 @@
#include "conf.h" #include "conf.h"
#if defined(USE_SCREEN) #if (USE_SCREEN)
#include "screen.h" #include "screen.h"
@@ -130,15 +130,15 @@ static int init(FILE *f, int o, int now)
if (!screen) if (!screen)
screen = do_construct(screen_djgpp2_construct(),fd); screen = do_construct(screen_djgpp2_construct(),fd);
#endif #endif
#if defined(USE_SCREEN_WIN32) #if (USE_SCREEN_WIN32)
if (!screen) if (!screen)
screen = do_construct(screen_win32_construct(),fd); screen = do_construct(screen_win32_construct(),fd);
#endif #endif
#if defined(USE_SCREEN_VCSA) #if (USE_SCREEN_VCSA)
if (!screen) if (!screen)
screen = do_construct(screen_vcsa_construct(),fd); screen = do_construct(screen_vcsa_construct(),fd);
#endif #endif
#if defined(USE_SCREEN_CURSES) #if (USE_SCREEN_CURSES)
if (!screen && o == CON_SCREEN) if (!screen && o == CON_SCREEN)
screen = do_construct(screen_curses_construct(),fd); screen = do_construct(screen_curses_construct(),fd);
#endif #endif
@@ -298,7 +298,7 @@ static void print0(FILE *f, const char *ss)
static bool intro(FILE *f) static bool intro(FILE *f)
{ {
UNUSED(f); UNUSED(f);
#if defined(USE_FRAMES) #if (USE_FRAMES)
if (screen->intro) if (screen->intro)
return screen->intro(screen,screen_show_frames); return screen->intro(screen,screen_show_frames);
#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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -43,7 +43,7 @@ unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
assert(buf != NULL); assert(buf != NULL);
#if 0 #if 0
return adler32(adler, (const Bytef *) buf, len); // zlib return adler32(adler, (const Bytef *) buf, len); // zlib
#elif defined(WITH_UCL) #elif (WITH_UCL)
return ucl_adler32(adler, (const ucl_bytep) buf, len); return ucl_adler32(adler, (const ucl_bytep) buf, len);
#else #else
# error # error
@@ -59,7 +59,7 @@ unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
assert(buf != NULL); assert(buf != NULL);
#if 0 #if 0
return crc32(crc, (const Bytef *) buf, len); // zlib return crc32(crc, (const Bytef *) buf, len); // zlib
#elif defined(WITH_UCL) #elif (WITH_UCL)
return ucl_crc32(crc, (const ucl_bytep) buf, len); return ucl_crc32(crc, (const ucl_bytep) buf, len);
#else #else
# error # error
@@ -108,17 +108,17 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
if (0) { if (0) {
} }
#if defined(WITH_LZMA) #if (WITH_LZMA)
else if (M_IS_LZMA(method)) else if (M_IS_LZMA(method))
r = upx_lzma_compress(src, src_len, dst, dst_len, r = upx_lzma_compress(src, src_len, dst, dst_len,
cb, method, level, cconf, cresult); cb, method, level, cconf, cresult);
#endif #endif
#if defined(WITH_NRV) #if (WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_nrv_compress(src, src_len, dst, dst_len, r = upx_nrv_compress(src, src_len, dst, dst_len,
cb, method, level, cconf, cresult); cb, method, level, cconf, cresult);
#endif #endif
#if defined(WITH_UCL) #if (WITH_UCL)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_ucl_compress(src, src_len, dst, dst_len, r = upx_ucl_compress(src, src_len, dst, dst_len,
cb, method, level, cconf, cresult); cb, method, level, cconf, cresult);
@@ -154,19 +154,19 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
if (0) { if (0) {
} }
#if defined(WITH_LZMA) #if (WITH_LZMA)
else if (M_IS_LZMA(method)) else if (M_IS_LZMA(method))
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult); r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
#endif #endif
#if defined(WITH_NRV) #if (WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult); r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult);
#endif #endif
#if defined(WITH_UCL) #if (WITH_UCL)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_ucl_decompress(src, src_len, dst, dst_len, method, cresult); r = upx_ucl_decompress(src, src_len, dst, dst_len, method, cresult);
#endif #endif
#if defined(WITH_ZLIB) #if (WITH_ZLIB)
else if (M_IS_DEFLATE(method)) else if (M_IS_DEFLATE(method))
r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult); r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult);
#endif #endif
@@ -201,15 +201,15 @@ int upx_test_overlap ( const upx_bytep buf,
if (0) { if (0) {
} }
#if defined(WITH_LZMA) #if (WITH_LZMA)
else if (M_IS_LZMA(method)) else if (M_IS_LZMA(method))
r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult); r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif #endif
#if defined(WITH_NRV) #if (WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_nrv_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult); r = upx_nrv_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif #endif
#if defined(WITH_UCL) #if (WITH_UCL)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method)) else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult); r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
#endif #endif
+8 -7
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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 +27,14 @@
#ifndef __UPX_COMPRESS_H #ifndef __UPX_COMPRESS_H
#define __UPX_COMPRESS_H #define __UPX_COMPRESS_H 1
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
#if defined(WITH_LZMA) #if (WITH_LZMA)
const char *upx_lzma_version_string(void); const char *upx_lzma_version_string(void);
int upx_lzma_compress ( const upx_bytep src, unsigned src_len, int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -55,7 +55,7 @@ int upx_lzma_test_overlap ( const upx_bytep buf,
#endif #endif
#if defined(WITH_NRV) #if (WITH_NRV)
const char *upx_nrv_version_string(void); const char *upx_nrv_version_string(void);
int upx_nrv_compress ( const upx_bytep src, unsigned src_len, int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -76,7 +76,7 @@ int upx_nrv_test_overlap ( const upx_bytep buf,
#endif #endif
#if defined(WITH_UCL) #if (WITH_UCL)
const char *upx_ucl_version_string(void); const char *upx_ucl_version_string(void);
int upx_ucl_compress ( const upx_bytep src, unsigned src_len, int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -96,7 +96,8 @@ int upx_ucl_test_overlap ( const upx_bytep buf,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
#endif #endif
#if defined(WITH_ZLIB)
#if (WITH_ZLIB)
const char *upx_zlib_version_string(void); const char *upx_zlib_version_string(void);
int upx_zlib_compress ( const upx_bytep src, unsigned src_len, int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
+13 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +47,7 @@ void lzma_compress_config_t::reset()
} }
#if !defined(WITH_LZMA) #if !(WITH_LZMA)
extern int compress_lzma_dummy; extern int compress_lzma_dummy;
int compress_lzma_dummy = 0; int compress_lzma_dummy = 0;
#else #else
@@ -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"
@@ -291,7 +292,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
unsigned char props_buf[LZMA_PROPS_SIZE]; unsigned char props_buf[LZMA_PROPS_SIZE];
SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE; SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE;
#if defined(USE_LZMA_PROPERTIES) #if (USE_LZMA_PROPERTIES)
if (dst_avail < 1) if (dst_avail < 1)
goto error; goto error;
dst[0] = 0; // filled below dst[0] = 0; // filled below
@@ -312,7 +313,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
assert(x_len <= dst_avail); assert(x_len <= dst_avail);
*dst_len += x_len; *dst_len += x_len;
if (rh == SZ_OK) { if (rh == SZ_OK) {
#if defined(USE_LZMA_PROPERTIES) #if (USE_LZMA_PROPERTIES)
dst[-1] = props_buf[0]; dst[-1] = props_buf[0];
#endif #endif
r = UPX_E_OK; r = UPX_E_OK;
@@ -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
@@ -513,7 +517,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
goto error; goto error;
} }
assert(os.b_pos == 5); assert(os.b_pos == 5);
#if defined(USE_LZMA_PROPERTIES) #if (USE_LZMA_PROPERTIES)
os.b_pos = 1; os.b_pos = 1;
#else #else
os.b_pos = 0; os.b_pos = 0;
@@ -586,7 +590,7 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
SRes rh; SRes rh;
ELzmaStatus status; ELzmaStatus status;
#if defined(USE_LZMA_PROPERTIES) #if (USE_LZMA_PROPERTIES)
rh = LzmaProps_Decode(&s.Properties, src, src_len); rh = LzmaProps_Decode(&s.Properties, src, src_len);
if (rh != 0) if (rh != 0)
goto error; goto error;
@@ -684,7 +688,7 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
int r = UPX_E_ERROR; int r = UPX_E_ERROR;
int rh; int rh;
#if defined(USE_LZMA_PROPERTIES) #if (USE_LZMA_PROPERTIES)
if (src_len < 2) if (src_len < 2)
goto error; goto error;
rh = LzmaDecodeProperties(&s.Properties, src, src_len); rh = LzmaDecodeProperties(&s.Properties, src, src_len);
+9 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,23 +28,23 @@
#include "conf.h" #include "conf.h"
#include "compress.h" #include "compress.h"
#if !defined(WITH_UCL) #if !(WITH_UCL)
extern int compress_ucl_dummy; extern int compress_ucl_dummy;
int compress_ucl_dummy = 0; int compress_ucl_dummy = 0;
#else #else
#if 1 && !defined(UCL_USE_ASM) && (ACC_ARCH_I386) #if 1 && !(UCL_USE_ASM) && (ACC_ARCH_I386)
# if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC) # if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
# define UCL_USE_ASM # define UCL_USE_ASM 1
# endif # endif
#endif #endif
#if defined(UCL_NO_ASM) #if (UCL_NO_ASM)
# undef UCL_USE_ASM # undef UCL_USE_ASM
#endif #endif
#if defined(ACC_CFG_NO_UNALIGNED) #if (ACC_CFG_NO_UNALIGNED)
# undef UCL_USE_ASM # undef UCL_USE_ASM
#endif #endif
#if 1 && defined(UCL_USE_ASM) #if 1 && (UCL_USE_ASM)
# include <ucl/ucl_asm.h> # include <ucl/ucl_asm.h>
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8 # define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16 # define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -41,7 +41,7 @@ void zlib_compress_config_t::reset()
} }
#if !defined(WITH_ZLIB) #if !(WITH_ZLIB)
extern int compress_zlib_dummy; extern int compress_zlib_dummy;
int compress_zlib_dummy = 0; int compress_zlib_dummy = 0;
#else #else
+40 -31
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_CONF_H #ifndef __UPX_CONF_H
#define __UPX_CONF_H #define __UPX_CONF_H 1
#include "version.h" #include "version.h"
@@ -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
/************************************************************************* /*************************************************************************
// //
@@ -167,10 +184,10 @@
#undef linux #undef linux
#undef small #undef small
#undef tos #undef tos
#if defined(ACC_CC_DMC) #if (ACC_CC_DMC)
# undef tell # undef tell
#endif #endif
#if !defined(ACC_CC_PGI) #if !(ACC_CC_PGI)
# undef unix # undef unix
#endif #endif
#if defined(__DJGPP__) #if defined(__DJGPP__)
@@ -189,14 +206,14 @@
# undef WITH_LZMA # undef WITH_LZMA
#endif #endif
#if defined(UPX_OFFICIAL_BUILD) #if defined(UPX_OFFICIAL_BUILD)
# if !defined(WITH_LZMA) || !defined(WITH_NRV) || !defined(WITH_UCL) # if !(WITH_LZMA) || !(WITH_NRV) || !(WITH_UCL)
# error # error
# endif # endif
#endif #endif
#if defined(WITH_NRV) #if (WITH_NRV)
# include <nrv/nrvconf.h> # include <nrv/nrvconf.h>
#endif #endif
#if defined(WITH_UCL) #if (WITH_UCL)
# define ucl_compress_config_t REAL_ucl_compress_config_t # define ucl_compress_config_t REAL_ucl_compress_config_t
# include <ucl/uclconf.h> # include <ucl/uclconf.h>
# include <ucl/ucl.h> # include <ucl/ucl.h>
@@ -206,11 +223,6 @@
# undef ucl_compress_config_t # undef ucl_compress_config_t
# undef ucl_compress_config_p # undef ucl_compress_config_p
#endif #endif
#if !defined(__UPX_CHECKER)
# if defined(__UCL_CHECKER) || defined(__NRV_CHECKER)
# define __UPX_CHECKER
# endif
#endif
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL) #if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
# error "UINT_MAX" # error "UINT_MAX"
#endif #endif
@@ -224,22 +236,17 @@
**************************************************************************/ **************************************************************************/
// malloc debuggers // malloc debuggers
#if defined(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_MAKE_MEM_UNDEFINED)
#if !defined(VALGRIND_DISCARD) # define VALGRIND_MAKE_MEM_UNDEFINED(addr,len) 0
# define VALGRIND_DISCARD(handle) ((void)(&handle))
#endif #endif
@@ -263,10 +270,10 @@
#endif #endif
#if !defined(HAVE_STRCASECMP) && defined(HAVE_STRICMP) #if !(HAVE_STRCASECMP) && (HAVE_STRICMP)
# define strcasecmp stricmp # define strcasecmp stricmp
#endif #endif
#if !defined(HAVE_STRNCASECMP) && defined(HAVE_STRNICMP) #if !(HAVE_STRNCASECMP) && (HAVE_STRNICMP)
# define strncasecmp strnicmp # define strncasecmp strnicmp
#endif #endif
@@ -331,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_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)
@@ -497,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
@@ -757,7 +766,7 @@ typedef ElfLinker Linker;
// main.cpp // main.cpp
extern const char *progname; extern const char *progname;
bool set_ec(int ec); bool set_ec(int ec);
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE) #if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void e_exit(int ec) __attribute__((__noreturn__)); void e_exit(int ec) __attribute__((__noreturn__));
#else #else
void e_exit(int ec); void e_exit(int ec);
@@ -769,7 +778,7 @@ void printSetNl(int need_nl);
void printClearLine(FILE *f = NULL); void printClearLine(FILE *f = NULL);
void printErr(const char *iname, const Throwable *e); void printErr(const char *iname, const Throwable *e);
void printUnhandledException(const char *iname, const std::exception *e); void printUnhandledException(const char *iname, const std::exception *e);
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE) #if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void __acc_cdecl_va printErr(const char *iname, const char *format, ...) void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
__attribute__((__format__(__printf__,2,3))); __attribute__((__format__(__printf__,2,3)));
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...) void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
@@ -779,7 +788,7 @@ void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...); void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
#endif #endif
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE) #if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void __acc_cdecl_va infoWarning(const char *format, ...) void __acc_cdecl_va infoWarning(const char *format, ...)
__attribute__((__format__(__printf__,1,2))); __attribute__((__format__(__printf__,1,2)));
void __acc_cdecl_va infoHeader(const char *format, ...) void __acc_cdecl_va infoHeader(const char *format, ...)
+21 -21
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -39,41 +39,41 @@
#undef USE_SCREEN_WIN32 #undef USE_SCREEN_WIN32
#undef USE_FRAMES #undef USE_FRAMES
#if defined(WITH_GUI) && !defined(NO_CONSOLE) #if 1 && (WITH_GUI) && !defined(NO_CONSOLE)
# define NO_CONSOLE # define NO_CONSOLE 1
#endif #endif
#if 1 && defined(__linux__) #if 1 && defined(__linux__)
# define USE_SCREEN # define USE_SCREEN 1
# define USE_SCREEN_VCSA # define USE_SCREEN_VCSA 1
# if !defined(HAVE_LINUX_KD_H) # if !(HAVE_LINUX_KD_H)
# undef USE_SCREEN # undef USE_SCREEN
# undef USE_SCREEN_VCSA # undef USE_SCREEN_VCSA
# endif # endif
# if !defined(HAVE_LINUX_KDEV_T_H) || !defined(HAVE_LINUX_MAJOR_H) # if !(HAVE_LINUX_KDEV_T_H) || !(HAVE_LINUX_MAJOR_H)
# undef USE_SCREEN # undef USE_SCREEN
# undef USE_SCREEN_VCSA # undef USE_SCREEN_VCSA
# endif # endif
#endif #endif
#if 1 && defined(__DJGPP__) #if 1 && defined(__DJGPP__)
# define USE_SCREEN # define USE_SCREEN 1
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) #elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
# define USE_SCREEN # define USE_SCREEN 1
# define USE_SCREEN_WIN32 # define USE_SCREEN_WIN32 1
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__)) #elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
# define USE_SCREEN # define USE_SCREEN 1
# define USE_SCREEN_WIN32 # define USE_SCREEN_WIN32 1
#endif #endif
#if 0 || defined(NO_ANSI) #if 0 || (NO_ANSI)
# undef USE_ANSI # undef USE_ANSI
#endif #endif
#if 0 || defined(NO_SCREEN) #if 0 || (NO_SCREEN)
# undef USE_SCREEN # undef USE_SCREEN
#endif #endif
#if 0 || defined(NO_FRAMES) || !defined(USE_SCREEN) #if 0 || (NO_FRAMES) || !(USE_SCREEN)
# undef USE_FRAMES # undef USE_FRAMES
#endif #endif
#if 1 #if 1
@@ -81,11 +81,11 @@
#endif #endif
#if 0 || defined(USE_ANSI) || defined(USE_SCREEN) #if 0 || (USE_ANSI) || (USE_SCREEN)
# define USE_CONSOLE # define USE_CONSOLE 1
#endif #endif
#if 0 || defined(NO_CONSOLE) || !defined(USE_CONSOLE) #if 0 || (NO_CONSOLE) || !(USE_CONSOLE)
# undef USE_CONSOLE # undef USE_CONSOLE
# undef USE_ANSI # undef USE_ANSI
# undef USE_SCREEN # undef USE_SCREEN
@@ -110,7 +110,7 @@ enum {
}; };
#if defined(USE_CONSOLE) #if (USE_CONSOLE)
typedef struct typedef struct
{ {
@@ -165,7 +165,7 @@ void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
extern FILE *con_term; extern FILE *con_term;
#if defined(USE_CONSOLE) #if (USE_CONSOLE)
extern int con_mode; extern int con_mode;
extern console_t *con; extern console_t *con;
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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);
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_EXCEPT_H #ifndef __UPX_EXCEPT_H
#define __UPX_EXCEPT_H #define __UPX_EXCEPT_H 1
#ifdef __cplusplus #ifdef __cplusplus
@@ -62,7 +62,7 @@ private:
DISABLE_NEW_DELETE DISABLE_NEW_DELETE
private: private:
static long counter; // for debugging static unsigned long counter; // for debugging
}; };
@@ -204,7 +204,7 @@ public:
// (noreturn) is probably not the correct semantics for throwing exceptions // (noreturn) is probably not the correct semantics for throwing exceptions
#define NORET __attribute__((__noreturn__)) #define NORET __attribute__((__noreturn__))
#else #else
#define NORET #define NORET /*empty*/
#endif #endif
void throwCantPack(const char *msg) NORET; void throwCantPack(const char *msg) NORET;
+14 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -37,7 +37,7 @@
void File::chmod(const char *name, int mode) void File::chmod(const char *name, int mode)
{ {
#if defined(HAVE_CHMOD) #if (HAVE_CHMOD)
if (::chmod(name,mode) != 0) if (::chmod(name,mode) != 0)
throwIOException(name,errno); throwIOException(name,errno);
#else #else
@@ -410,6 +410,17 @@ void OutputFile::seek(off_t off, int whence)
super::seek(off,whence); super::seek(off,whence);
} }
// WARNING: fsync() does not exist in some Windows environments.
// This trick works only on UNIX-like systems.
//int OutputFile::read(void *buf, int len)
//{
// fsync(_fd);
// InputFile infile;
// infile.open(this->getName(), O_RDONLY);
// infile.seek(this->tell(), SEEK_SET);
// return infile.read(buf, len);
//}
void OutputFile::set_extent(off_t offset, off_t length) void OutputFile::set_extent(off_t offset, off_t length)
{ {
super::set_extent(offset, length); super::set_extent(offset, length);
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_FILE_H #ifndef __UPX_FILE_H
#define __UPX_FILE_H #define __UPX_FILE_H 1
class MemBuffer; class MemBuffer;
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_FILTER_H #ifndef __UPX_FILTER_H
#define __UPX_FILTER_H #define __UPX_FILTER_H 1
class Filter; class Filter;
class FilterImp; class FilterImp;
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2004-2010 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++;
@@ -108,6 +108,7 @@ static int F(Filter *f)
f->calls = calls; f->calls = calls;
f->noncalls = noncalls; f->noncalls = noncalls;
f->lastcall = lastcall; f->lastcall = lastcall;
ACC_UNUSED(lastnoncall);
#if 0 || defined(TESTING) #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d text_size=%x calltrickoffset=%x\n", printf("\ncalls=%d noncalls=%d text_size=%x calltrickoffset=%x\n",
@@ -132,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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
+20 -15
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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");
@@ -310,13 +315,13 @@ void show_help(int verbose)
// "\nUPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.\n" // "\nUPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.\n"
""); "");
#if defined(DEBUG) || defined(TESTING) #if (DEBUG) || (TESTING)
fg = con_fg(f,FG_RED); fg = con_fg(f,FG_RED);
con_fprintf(f,"\nWARNING: this version is compiled with" con_fprintf(f,"\nWARNING: this version is compiled with"
#if defined(DEBUG) #if (DEBUG)
" -DDEBUG" " -DDEBUG"
#endif #endif
#if defined(TESTING) #if (TESTING)
" -DTESTING" " -DTESTING"
#endif #endif
"\n"); "\n");
@@ -380,34 +385,34 @@ void show_version(int x)
UNUSED(v); UNUSED(v);
fprintf(fp, "upx %s\n", UPX_VERSION_STRING); fprintf(fp, "upx %s\n", UPX_VERSION_STRING);
#if defined(WITH_NRV) #if (WITH_NRV)
v = upx_nrv_version_string(); v = upx_nrv_version_string();
if (v != NULL && v[0]) if (v != NULL && v[0])
fprintf(fp, "NRV data compression library %s\n", v); fprintf(fp, "NRV data compression library %s\n", v);
#endif #endif
#if defined(WITH_UCL) #if (WITH_UCL)
v = upx_ucl_version_string(); v = upx_ucl_version_string();
if (v != NULL && v[0]) if (v != NULL && v[0])
fprintf(fp, "UCL data compression library %s\n", v); fprintf(fp, "UCL data compression library %s\n", v);
#endif #endif
#if defined(WITH_ZLIB) #if (WITH_ZLIB)
v = upx_zlib_version_string(); v = upx_zlib_version_string();
if (v != NULL && v[0]) if (v != NULL && v[0])
fprintf(fp, "zlib data compression library %s\n", v); fprintf(fp, "zlib data compression library %s\n", v);
#endif #endif
#if defined(WITH_LZMA) #if (WITH_LZMA)
v = upx_lzma_version_string(); v = upx_lzma_version_string();
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-2010 Markus Franz Xaver Johannes Oberhumer\n"); fprintf(fp, "Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(fp, "Copyright (C) 1996-2010 Laszlo Molnar\n"); fprintf(fp, "Copyright (C) 1996-2013 Laszlo Molnar\n");
fprintf(fp, "Copyright (C) 2000-2010 John F. Reiser\n"); fprintf(fp, "Copyright (C) 2000-2013 John F. Reiser\n");
fprintf(fp, "Copyright (C) 2002-2010 Jens Medoch\n"); fprintf(fp, "Copyright (C) 2002-2013 Jens Medoch\n");
#if defined(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
#if defined(WITH_LZMA) #if (WITH_LZMA)
fprintf(fp, "Copyright (C) 1999" "-2006 Igor Pavlov\n"); fprintf(fp, "Copyright (C) 1999" "-2006 Igor Pavlov\n");
#endif #endif
fprintf(fp, "UPX comes with ABSOLUTELY NO WARRANTY; for details type '%s -L'.\n", progname); fprintf(fp, "UPX comes with ABSOLUTELY NO WARRANTY; for details type '%s -L'.\n", progname);
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_LEFILE_H #ifndef __UPX_LEFILE_H
#define __UPX_LEFILE_H #define __UPX_LEFILE_H 1
class InputFile; class InputFile;
class OutputFile; class OutputFile;
+77 -89
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -45,6 +45,18 @@ static bool update_capacity(unsigned size, unsigned *capacity)
return true; return true;
} }
static void __acc_cdecl_va internal_error(const char *format, ...)
{
char buf[1024];
va_list ap;
va_start(ap, format);
vsnprintf(buf, sizeof(buf), format, ap);
va_end(ap);
throwInternalError(buf);
}
/************************************************************************* /*************************************************************************
// Section // Section
@@ -72,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);
@@ -91,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);
@@ -282,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;
@@ -317,10 +328,7 @@ ElfLinker::Section *ElfLinker::findSection(const char *name, bool fatal) const
if (strcmp(sections[ic]->name, name) == 0) if (strcmp(sections[ic]->name, name) == 0)
return sections[ic]; return sections[ic];
if (fatal) if (fatal)
{ internal_error("unknown section %s\n", name);
printf("unknown section %s\n", name);
abort();
}
return NULL; return NULL;
} }
@@ -330,10 +338,7 @@ ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const
if (strcmp(symbols[ic]->name, name) == 0) if (strcmp(symbols[ic]->name, name) == 0)
return symbols[ic]; return symbols[ic];
if (fatal) if (fatal)
{ internal_error("unknown symbol %s\n", name);
printf("unknown symbol %s\n", name);
abort();
}
return NULL; return NULL;
} }
@@ -351,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))
@@ -366,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 *)));
@@ -492,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; upx_uint64_t value = 0;
if (rel->section->output == NULL) if (rel->section->output == NULL)
continue; continue;
@@ -502,37 +507,28 @@ void ElfLinker::relocate()
} }
else if (strcmp(rel->value->section->name, "*UND*") == 0 && else if (strcmp(rel->value->section->name, "*UND*") == 0 &&
rel->value->offset == 0xdeaddead) rel->value->offset == 0xdeaddead)
{ internal_error("undefined symbol '%s' referenced\n", rel->value->name);
printf("undefined symbol '%s' referenced\n", rel->value->name);
abort();
}
else if (rel->value->section->output == NULL) else if (rel->value->section->output == NULL)
{ internal_error("can not apply reloc '%s:%x' without section '%s'\n",
printf("can not apply reloc '%s:%x' without section '%s'\n",
rel->section->name, rel->offset, rel->section->name, rel->offset,
rel->value->section->name); rel->value->section->name);
abort();
}
else else
{ {
value = rel->value->section->offset + value = rel->value->section->offset +
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)
{ internal_error("defineSymbol: symbol '%s' is *ABS*\n", name);
printf("defineSymbol: symbol '%s' is *ABS*\n", name);
abort();
}
else if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols else if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols
symbol->offset = value; symbol->offset = value;
else if (strcmp(symbol->section->name, name) == 0) // for sections else if (strcmp(symbol->section->name, name) == 0) // for sections
@@ -545,10 +541,7 @@ void ElfLinker::defineSymbol(const char *name, unsigned value)
} }
} }
else else
{ internal_error("defineSymbol: symbol '%s' already defined\n", name);
printf("defineSymbol: symbol '%s' already defined\n", name);
abort();
}
} }
// debugging support // debugging support
@@ -556,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
{ {
@@ -568,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];
@@ -585,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)
@@ -600,10 +598,9 @@ 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 *)
{ {
printf("unknown relocation type '%s\n", rel->type); internal_error("unknown relocation type '%s\n", rel->type);
abort();
} }
@@ -616,31 +613,29 @@ void ElfLinker::relocate1(const Relocation *rel, upx_byte *,
#if 0 // FIXME #if 0 // FIXME
static void check8(const Relocation *rel, const upx_byte *location, int v, int d) static void check8(const Relocation *rel, const upx_byte *location, int v, int d)
{ {
if (v < -128 || v > 127) { if (v < -128 || v > 127)
printf("value out of range (%d) in reloc %s:%x\n", internal_error("value out of range (%d) in reloc %s:%x\n",
v, rel->section->name, rel->offset); v, rel->section->name, rel->offset);
abort(); if (d < -128 || d > 127)
} internal_error("displacement target out of range (%d) in reloc %s:%x\n",
if (d < -128 || d > 127) {
printf("displacement target out of range (%d) in reloc %s:%x\n",
v, rel->section->name, rel->offset); v, rel->section->name, rel->offset);
abort();
}
} }
#endif #endif
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)
@@ -650,25 +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",
printf("target out of range (%d) in reloc %s:%x\n",
displ, rel->section->name, rel->offset); displ, rel->section->name, rel->offset);
abort();
}
*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)
{ {
@@ -703,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)
{ {
@@ -747,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);
@@ -773,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)
@@ -804,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)
@@ -835,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);
@@ -857,19 +851,15 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
// Note that original (*location).displ is ignored. // Note that original (*location).displ is ignored.
if (strcmp(type, "24") == 0) { if (strcmp(type, "24") == 0) {
if (3& value) { if (3& value)
printf("unaligned word diplacement"); internal_error("unaligned word diplacement");
abort();
}
// FIXME: displacment overflow? // FIXME: displacment overflow?
set_be32(location, (0xfc000003 & get_be32(location)) + set_be32(location, (0xfc000003 & get_be32(location)) +
(0x03fffffc & value)); (0x03fffffc & value));
} }
else if (strcmp(type, "14") == 0) { else if (strcmp(type, "14") == 0) {
if (3& value) { if (3& value)
printf("unaligned word diplacement"); internal_error("unaligned word diplacement");
abort();
}
// FIXME: displacment overflow? // FIXME: displacment overflow?
set_be32(location, (0xffff0003 & get_be32(location)) + set_be32(location, (0xffff0003 & get_be32(location)) +
(0x0000fffc & value)); (0x0000fffc & value));
@@ -880,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);
@@ -901,11 +891,9 @@ void ElfLinkerX86::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 (range_check && (displ < -128 || displ > 127)) { if (range_check && (displ < -128 || displ > 127))
printf("target out of range (%d,%d,%d) in reloc %s:%x\n", internal_error("target out of range (%d,%d,%d) in reloc %s:%x\n",
displ, *location, value, rel->section->name, rel->offset); displ, *location, value, rel->section->name, rel->offset);
abort();
}
*location += value; *location += value;
} }
else if (strcmp(type, "16") == 0) else if (strcmp(type, "16") == 0)
+24 -24
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_LINKER_H #ifndef __UPX_LINKER_H
#define __UPX_LINKER_H #define __UPX_LINKER_H 1
/************************************************************************* /*************************************************************************
@@ -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();
@@ -84,7 +84,7 @@ public:
//virtual void setLoaderAlignOffset(int phase); //virtual void setLoaderAlignOffset(int phase);
virtual int addLoader(const char *sname); virtual int addLoader(const char *sname);
void addLoader(const char *s, va_list ap); void addLoader(const char *s, va_list ap);
#if 1 && (ACC_CC_GNUC >= 0x040100) #if 1 && (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x040100))
void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__)); void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__));
#else #else
void __acc_cdecl_va addLoaderVA(const char *s, ...); void __acc_cdecl_va addLoaderVA(const char *s, ...);
@@ -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);
}; };
+46 -21
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,6 @@
#include "conf.h" #include "conf.h"
#include "mygetopt.h"
#include "file.h" #include "file.h"
#include "packer.h" #include "packer.h"
#include "p_elf.h" #include "p_elf.h"
@@ -63,7 +62,7 @@ void options_t::reset()
o->console = CON_FILE; o->console = CON_FILE;
#if defined(__DJGPP__) #if defined(__DJGPP__)
o->console = CON_INIT; o->console = CON_INIT;
#elif defined(USE_SCREEN_WIN32) #elif (USE_SCREEN_WIN32)
o->console = CON_INIT; o->console = CON_INIT;
#elif 1 && defined(__linux__) #elif 1 && defined(__linux__)
o->console = CON_INIT; o->console = CON_INIT;
@@ -90,6 +89,19 @@ static int done_script_name = 0;
const char *argv0 = ""; const char *argv0 = "";
const char *progname = ""; const char *progname = "";
static acc_getopt_t mfx_getopt;
#define mfx_optarg mfx_getopt.optarg
#define mfx_optind mfx_getopt.optind
#define mfx_option acc_getopt_longopt_t
static void handle_opterr(acc_getopt_p g, const char *f, void *v)
{
struct A { va_list ap; };
struct A *a = (struct A *) v;
fprintf( stderr, "%s: ", g->progname);
vfprintf(stderr, f, a->ap);
fprintf( stderr, "\n");
}
static int num_files = -1; static int num_files = -1;
static int exit_code = EXIT_OK; static int exit_code = EXIT_OK;
@@ -886,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;
@@ -1036,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
@@ -1061,13 +1077,14 @@ static const struct mfx_option longopts[] =
}; };
int optc, longind; int optc, longind;
char buf[256]; char shortopts[256];
prepare_shortopts(buf,"123456789hH?V",longopts), prepare_shortopts(shortopts, "123456789hH?V", longopts),
mfx_optind = 0; acc_getopt_init(&mfx_getopt, 1, argc, argv);
mfx_opterr = 1; mfx_getopt.progname = progname;
mfx_getopt.opterr = handle_opterr;
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX; opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;
while ((optc = mfx_getopt_long(argc, argv, buf, longopts, &longind)) >= 0) while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0)
{ {
if (do_option(optc, argv[mfx_optind-1]) != 0) if (do_option(optc, argv[mfx_optind-1]) != 0)
e_usage(); e_usage();
@@ -1153,7 +1170,7 @@ static const struct mfx_option longopts[] =
int targc; int targc;
char **targv = NULL; char **targv = NULL;
static const char sep[] = " \t"; static const char sep[] = " \t";
char buf[256]; char shortopts[256];
var = getenv(OPTIONS_VAR); var = getenv(OPTIONS_VAR);
if (var == NULL || !var[0]) if (var == NULL || !var[0])
@@ -1209,10 +1226,11 @@ static const struct mfx_option longopts[] =
e_envopt(targv[i]); e_envopt(targv[i]);
/* handle options */ /* handle options */
prepare_shortopts(buf,"123456789",longopts); prepare_shortopts(shortopts, "123456789", longopts);
mfx_optind = 0; acc_getopt_init(&mfx_getopt, 1, targc, targv);
mfx_opterr = 1; mfx_getopt.progname = progname;
while ((optc = mfx_getopt_long(targc, targv, buf, longopts, &longind)) >= 0) mfx_getopt.opterr = handle_opterr;
while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0)
{ {
if (do_option(optc, targv[mfx_optind-1]) != 0) if (do_option(optc, targv[mfx_optind-1]) != 0)
e_envopt(NULL); e_envopt(NULL);
@@ -1271,9 +1289,13 @@ static bool test(void)
COMPILE_TIME_ASSERT_ALIGNED1(test2_t) COMPILE_TIME_ASSERT_ALIGNED1(test2_t)
COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21*sizeof(T)) COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21*sizeof(T))
#if defined(__acc_alignof) #if defined(__acc_alignof)
#if (ACC_CC_CLANG && ACC_ARCH_AMD64)
// CBUG: clang-2.8 bug in 64-bit mode
#else
COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1) COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1)
COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1) COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1)
#endif #endif
#endif
#if 1 && (ACC_CC_WATCOMC) #if 1 && (ACC_CC_WATCOMC)
test1_t t11; COMPILE_TIME_ASSERT(sizeof(t11.a) <= sizeof(t11.b)) test1_t t11; COMPILE_TIME_ASSERT(sizeof(t11.a) <= sizeof(t11.b))
test2_t t22; COMPILE_TIME_ASSERT(sizeof(t22.a) <= sizeof(t22.b)) test2_t t22; COMPILE_TIME_ASSERT(sizeof(t22.a) <= sizeof(t22.b))
@@ -1352,7 +1374,7 @@ void upx_sanity_check(void)
assert(TestBELE<BE64>::test()); assert(TestBELE<BE64>::test());
{ {
static const unsigned char dd[32] static const unsigned char dd[32]
#if 1 && (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__) #if 1 && (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__)
__attribute__((__aligned__(16))) __attribute__((__aligned__(16)))
#endif #endif
= { 0, 0, 0, 0, 0, 0, 0, = { 0, 0, 0, 0, 0, 0, 0,
@@ -1386,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);
@@ -1395,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
} }
@@ -1405,7 +1427,7 @@ void upx_sanity_check(void)
// main entry point // main entry point
**************************************************************************/ **************************************************************************/
#if !defined(WITH_GUI) #if !(WITH_GUI)
#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__) #if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)
extern "C" { extern long _stksize; long _stksize = 256 * 1024L; } extern "C" { extern long _stksize; long _stksize = 256 * 1024L; }
@@ -1420,6 +1442,9 @@ int __acc_cdecl_main main(int argc, char *argv[])
#if 0 && defined(__DJGPP__) #if 0 && defined(__DJGPP__)
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME // LFN=n may cause problems with 2.03's _rename and mkdir under WinME
putenv("LFN=y"); putenv("LFN=y");
#endif
#if (ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_CC_MSC) && defined(_WRITE_ABORT_MSG) && defined(_CALL_REPORTFAULT)
_set_abort_behavior(_WRITE_ABORT_MSG, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif #endif
acc_wildargv(&argc, &argv); acc_wildargv(&argc, &argv);
@@ -1455,7 +1480,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
set_term(stderr); set_term(stderr);
#if defined(WITH_UCL) #if (WITH_UCL)
if (ucl_init() != UCL_E_OK) if (ucl_init() != UCL_E_OK)
{ {
show_head(); show_head();
@@ -1466,7 +1491,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
e_exit(EXIT_INIT); e_exit(EXIT_INIT);
} }
#endif #endif
#if defined(WITH_NRV) #if (WITH_NRV)
if (nrv_init() != NRV_E_OK || NRV_VERSION != nrv_version()) if (nrv_init() != NRV_E_OK || NRV_VERSION != nrv_version())
{ {
show_head(); show_head();
@@ -1559,7 +1584,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
return exit_code; return exit_code;
} }
#endif /* !defined(WITH_GUI) */ #endif /* !(WITH_GUI) */
/* /*
+4 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -41,7 +41,7 @@ static int mcheck_init()
if (use_mcheck < 0) if (use_mcheck < 0)
{ {
use_mcheck = 1; use_mcheck = 1;
#if defined(WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND) #if (WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
if (RUNNING_ON_VALGRIND) if (RUNNING_ON_VALGRIND)
{ {
//fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n"); //fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n");
@@ -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)
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_MEM_H #ifndef __UPX_MEM_H
#define __UPX_MEM_H #define __UPX_MEM_H 1
/************************************************************************* /*************************************************************************
+1890 -1489
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
-706
View File
@@ -1,706 +0,0 @@
/* Getopt for GNU.
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
before changing it!
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#undef PROGNAME
#if 0
#ifndef EOF
#include <stdio.h>
#include <string.h>
#endif
#define PROGNAME(x) (x)
#else
#include "conf.h"
static const char *my_progname(const char *argv0)
{
return progname ? progname : argv0;
}
#define PROGNAME(x) my_progname(x)
#endif
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
long-named option. Because this is not POSIX.2 compliant, it is
being phased out. */
/* #define GETOPT_COMPAT */
#undef GETOPT_COMPAT
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
to intersperse the options with the other arguments.
As `getopt' works, it permutes the elements of ARGV so that,
when it is done, all the options precede everything else. Thus
all application programs are extended to handle flexible argument order.
Setting the environment variable POSIXLY_CORRECT disables permutation.
Then the behavior is completely standard.
GNU application programs can use a third alternative mode in which
they can distinguish the relative order of options and other arguments. */
#include "mygetopt.h"
#define option mfx_option
#define optarg mfx_optarg
#define optind mfx_optind
#define opterr mfx_opterr
#define optopt mfx_optopt
#undef BAD_OPTION
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
char *optarg = NULL;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
/* XXX 1003.2 says this must be 1 before any call. */
int optind = 0;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
This allows us to pick up the scan where we left off.
If this is zero, or a null string, it means resume the scan
by advancing to the next ARGV-element. */
static char *nextchar;
/* Callers store zero here to inhibit the error message
for unrecognized options. */
int opterr = 1;
/* Set to an option character which was unrecognized.
This must be initialized on some systems to avoid linking in the
system's own getopt implementation. */
#define BAD_OPTION '\0'
int optopt = BAD_OPTION;
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters.
PERMUTE is the default. We permute the contents of ARGV as we scan,
so that eventually all the non-options are at the end. This allows options
to be given in any order, even with programs that were not written to
expect this.
RETURN_IN_ORDER is an option available to programs that were written
to expect options and other ARGV-elements in any order and that care about
the ordering of the two. We describe each non-option ARGV-element
as if it were the argument of an option with character code 1.
Using `-' as the first character of the list of option characters
selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
static enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
been skipped. `first_nonopt' is the index in ARGV of the first of them;
`last_nonopt' is the index after the last of them. */
static int first_nonopt;
static int last_nonopt;
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
which contains all the non-options that have been skipped so far.
The other is elements [last_nonopt,optind), which contains all
the options processed since those non-options were skipped.
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved.
To perform the swap, we first reverse the order of all elements. So
all options now come before all non options, but they are in the
wrong order. So we put back the options and non options in original
order by reversing them again. For example:
original input: a b c -x -y
reverse all: -y -x c b a
reverse options: -x -y c b a
reverse non options: -x -y a b c
*/
static void exchange (char **argv)
{
char *temp; char **first, **last;
/* Reverse all the elements [first_nonopt, optind) */
first = &argv[first_nonopt];
last = &argv[optind-1];
while (first < last) {
temp = *first; *first = *last; *last = temp; first++; last--;
}
/* Put back the options in order */
first = &argv[first_nonopt];
first_nonopt += (optind - last_nonopt);
last = &argv[first_nonopt - 1];
while (first < last) {
temp = *first; *first = *last; *last = temp; first++; last--;
}
/* Put back the non options in order */
first = &argv[first_nonopt];
last_nonopt = optind;
last = &argv[last_nonopt-1];
while (first < last) {
temp = *first; *first = *last; *last = temp; first++; last--;
}
}
/* Scan elements of ARGV (whose length is ARGC) for option characters
given in OPTSTRING.
If an element of ARGV starts with '-', and is not exactly "-" or "--",
then it is an option element. The characters of this element
(aside from the initial '-') are option characters. If `getopt'
is called repeatedly, it returns successively each of the option characters
from each of the option elements.
If `getopt' finds another option character, it returns that character,
updating `optind' and `nextchar' so that the next call to `getopt' can
resume the scan with the following option character or ARGV-element.
If there are no more option characters, `getopt' returns `EOF'.
Then `optind' is the index in ARGV of the first ARGV-element
that is not an option. (The ARGV-elements have been permuted
so that those that are not options now come last.)
OPTSTRING is a string containing the legitimate option characters.
If an option character is seen that is not listed in OPTSTRING,
return BAD_OPTION after printing an error message. If you set `opterr' to
zero, the error message is suppressed but we still return BAD_OPTION.
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
so the following text in the same ARGV-element, or the text of the following
ARGV-element, is returned in `optarg'. Two colons mean an option that
wants an optional arg; if there is text in the current ARGV-element,
it is returned in `optarg', otherwise `optarg' is set to zero.
If OPTSTRING starts with `-' or `+', it requests different methods of
handling the non-option ARGV-elements.
See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
Long-named options begin with `--' instead of `-'.
Their names may be abbreviated as long as the abbreviation is unique
or is an exact match for some defined option. If they have an
argument, it follows the option name in the same ARGV-element, separated
from the option name by a `=', or else the in next ARGV-element.
When `getopt' finds a long-named option, it returns 0 if that option's
`flag' field is nonzero, the value of the option's `val' field
if the `flag' field is zero.
LONGOPTS is a vector of `struct option' terminated by an
element containing a name which is zero.
LONGIND returns the index in LONGOPT of the long-named option found.
It is only valid when a long-named option has been found by the most
recent call.
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
long-named options. */
static int _getopt_internal (int argc, char **argv, const char *optstring,
const struct option *longopts, int *longind,
int long_only)
{
static char empty_string[1];
int option_index;
if (longind != NULL)
*longind = -1;
optarg = 0;
/* Initialize the internal data when the first call is made.
Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
if (optind == 0)
{
first_nonopt = last_nonopt = optind = 1;
nextchar = NULL;
/* Determine how to handle the ordering of options and nonoptions. */
if (optstring[0] == '-')
{
ordering = RETURN_IN_ORDER;
++optstring;
}
else if (optstring[0] == '+')
{
ordering = REQUIRE_ORDER;
++optstring;
}
#if 0
else if (getenv ("POSIXLY_CORRECT") != NULL)
ordering = REQUIRE_ORDER;
#endif
else
ordering = PERMUTE;
}
if (nextchar == NULL || *nextchar == '\0')
{
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange (argv);
else if (last_nonopt != optind)
first_nonopt = optind;
/* Now skip any additional non-options
and extend the range of non-options previously skipped. */
while (optind < argc
&& (argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
&& (longopts == NULL
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif /* GETOPT_COMPAT */
)
optind++;
last_nonopt = optind;
}
/* Special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
if (optind != argc && !strcmp (argv[optind], "--"))
{
optind++;
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange (argv);
else if (first_nonopt == last_nonopt)
first_nonopt = optind;
last_nonopt = argc;
optind = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
if (optind == argc)
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
return EOF;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
&& (longopts == NULL
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif /* GETOPT_COMPAT */
)
{
if (ordering == REQUIRE_ORDER)
return EOF;
optarg = argv[optind++];
return 1;
}
/* We have found another option-ARGV-element.
Start decoding its characters. */
nextchar = (argv[optind] + 1
+ (longopts != NULL && argv[optind][1] == '-'));
}
if (longopts != NULL
&& ((argv[optind][0] == '-'
&& (argv[optind][1] == '-' || long_only))
#ifdef GETOPT_COMPAT
|| argv[optind][0] == '+'
#endif /* GETOPT_COMPAT */
))
{
const struct option *p;
char *s = nextchar;
int exact = 0;
int ambig = 0;
const struct option *pfound = NULL;
int indfound = 0;
int needexact = 0;
/* allow `--option#value' because you cannout assign a '='
to an environment variable under DOS command.com */
while (*s && *s != '=' && * s != '#')
s++;
/* Test all options for either exact match or abbreviated matches. */
for (p = longopts, option_index = 0; p->name;
p++, option_index++)
if (!strncmp (p->name, nextchar, (unsigned) (s - nextchar)))
{
if (p->has_arg & 0x10)
needexact = 1;
if ((unsigned) (s - nextchar) == strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second nonexact match found. */
ambig = 1;
}
/* don't allow nonexact longoptions */
if (needexact && !exact)
{
if (opterr)
fprintf (stderr, "%s: unrecognized option `%s'\n",
PROGNAME(argv[0]), argv[optind]);
nextchar += strlen (nextchar);
optind++;
return BAD_OPTION;
}
if (ambig && !exact)
{
if (opterr)
fprintf (stderr, "%s: option `%s' is ambiguous\n",
PROGNAME(argv[0]), argv[optind]);
nextchar += strlen (nextchar);
optind++;
return BAD_OPTION;
}
if (pfound != NULL)
{
int have_arg = (s[0] != '\0');
if (have_arg && (pfound->has_arg & 0xf))
have_arg = (s[1] != '\0');
option_index = indfound;
optind++;
if (have_arg)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg & 0xf)
optarg = s + 1;
else
{
if (opterr)
{
if (argv[optind - 1][1] == '-')
/* --option */
fprintf (stderr,
"%s: option `--%s' doesn't allow an argument\n",
PROGNAME(argv[0]), pfound->name);
else
/* +option or -option */
fprintf (stderr,
"%s: option `%c%s' doesn't allow an argument\n",
PROGNAME(argv[0]), argv[optind - 1][0], pfound->name);
}
nextchar += strlen (nextchar);
return BAD_OPTION;
}
}
else if ((pfound->has_arg & 0xf) == 1)
{
#if 0
if (optind < argc)
#else
if (optind < argc && (pfound->has_arg & 0x20) == 0)
#endif
optarg = argv[optind++];
else
{
if (opterr)
fprintf (stderr, "%s: option `--%s%s' requires an argument\n",
PROGNAME(argv[0]), pfound->name,
(pfound->has_arg & 0x20) ? "=" : "");
nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : BAD_OPTION;
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
/* Can't find it as a long option. If this is not getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-'
#ifdef GETOPT_COMPAT
|| argv[optind][0] == '+'
#endif /* GETOPT_COMPAT */
|| strchr (optstring, *nextchar) == NULL)
{
if (opterr)
{
if (argv[optind][1] == '-')
/* --option */
fprintf (stderr, "%s: unrecognized option `--%s'\n",
PROGNAME(argv[0]), nextchar);
else
/* +option or -option */
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
PROGNAME(argv[0]), argv[optind][0], nextchar);
}
nextchar = empty_string;
optind++;
return BAD_OPTION;
}
(void) &ambig; /* UNUSED */
}
/* Look at and handle the next option-character. */
{
char c = *nextchar++;
const char *temp = strchr (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
++optind;
if (temp == NULL || c == ':')
{
if (opterr)
{
#if 0
if (c < 040 || c >= 0177)
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
PROGNAME(argv[0]), c);
else
fprintf (stderr, "%s: unrecognized option `-%c'\n", PROGNAME(argv[0]), c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: illegal option -- %c\n", PROGNAME(argv[0]), c);
#endif
}
optopt = c;
return BAD_OPTION;
}
if (temp[1] == ':')
{
if (temp[2] == ':')
{
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
optarg = nextchar;
optind++;
}
else
optarg = 0;
nextchar = NULL;
}
else
{
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
optind++;
}
else if (optind == argc)
{
if (opterr)
{
#if 0
fprintf (stderr, "%s: option `-%c' requires an argument\n",
PROGNAME(argv[0]), c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: option requires an argument -- %c\n",
PROGNAME(argv[0]), c);
#endif
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = BAD_OPTION;
}
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
optarg = argv[optind++];
nextchar = NULL;
}
}
return c;
}
}
int mfx_getopt(int argc, char **argv, const char *optstring)
{
return _getopt_internal (argc, argv, optstring,
(const struct option *) 0,
(int *) 0,
0);
}
int mfx_getopt_long(int argc, char **argv, const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
#ifdef TEST
/* Compile with -DTEST to make an executable for use in testing
the above definition of `getopt'. */
int
main (argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
c = getopt (argc, argv, "abc:d:0123456789");
if (c == EOF)
break;
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case BAD_OPTION:
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
#endif /* TEST */
/*
vi:ts=4:et:nowrap
*/
-102
View File
@@ -1,102 +0,0 @@
/* Declarations for getopt.
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __MFX_GETOPT_H
#define __MFX_GETOPT_H 1
#ifdef __cplusplus
/* extern "C" { */
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *mfx_optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int mfx_optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int mfx_opterr;
/* Set to an option character which was unrecognized. */
extern int mfx_optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct mfx_option
{
const char *name;
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
#define mfx_no_argument 0
#define mfx_required_argument 1
#define mfx_optional_argument 2
#define mfx_exact_argument 0x10 /* no abbrev. */
int mfx_getopt(int argc, char **argv, const char *shortopts);
int mfx_getopt_long(int argc, char **argv, const char *shortopts,
const struct mfx_option *longopts, int *longind);
#ifdef __cplusplus
/* } */
#endif
#endif /* __MFX_GETOPT_H */
+4 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_OPTIONS_H #ifndef __UPX_OPTIONS_H
#define __UPX_OPTIONS_H #define __UPX_OPTIONS_H 1
/************************************************************************* /*************************************************************************
@@ -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;
+14 -7
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -202,6 +202,7 @@ unsigned PackArmPe::processImports() // pass 1
unsigned iat; unsigned iat;
LE32 *lookupt; LE32 *lookupt;
unsigned npos; unsigned npos;
unsigned original_position;
bool isk32; bool isk32;
static int __acc_cdecl_qsort compare(const void *p1, const void *p2) static int __acc_cdecl_qsort compare(const void *p1, const void *p2)
@@ -210,6 +211,8 @@ unsigned PackArmPe::processImports() // pass 1
const udll *u2 = * (const udll * const *) p2; const udll *u2 = * (const udll * const *) p2;
if (u1->isk32) return -1; if (u1->isk32) return -1;
if (u2->isk32) return 1; if (u2->isk32) return 1;
if (!*u1->lookupt) return 1;
if (!*u2->lookupt) return -1;
int rc = strcasecmp(u1->name,u2->name); int rc = strcasecmp(u1->name,u2->name);
if (rc) return rc; if (rc) return rc;
if (u1->ordinal) return -1; if (u1->ordinal) return -1;
@@ -236,11 +239,12 @@ unsigned PackArmPe::processImports() // pass 1
dlls[ic].iat = im->iat; dlls[ic].iat = im->iat;
dlls[ic].lookupt = (LE32*) (ibuf + (im->oft ? im->oft : im->iat)); dlls[ic].lookupt = (LE32*) (ibuf + (im->oft ? im->oft : im->iat));
dlls[ic].npos = 0; dlls[ic].npos = 0;
dlls[ic].original_position = ic;
dlls[ic].isk32 = strcasecmp(kernel32dll,dlls[ic].name) == 0; dlls[ic].isk32 = strcasecmp(kernel32dll,dlls[ic].name) == 0;
soimport += strlen(dlls[ic].name) + 1 + 4; soimport += strlen(dlls[ic].name) + 1 + 4;
for (LE32 *tarr = dlls[ic].lookupt; *tarr; tarr++) for (IPTR_I(LE32, tarr, dlls[ic].lookupt); *tarr; tarr += 1)
{ {
if (*tarr & 0x80000000) if (*tarr & 0x80000000)
{ {
@@ -252,10 +256,11 @@ unsigned PackArmPe::processImports() // pass 1
} }
else else
{ {
unsigned len = strlen(ibuf + *tarr + 2); IPTR_I(const upx_byte, n, ibuf + *tarr + 2);
unsigned len = strlen(n);
soimport += len + 1; soimport += len + 1;
if (dlls[ic].shname == NULL || len < strlen (dlls[ic].shname)) if (dlls[ic].shname == NULL || len < strlen (dlls[ic].shname))
dlls[ic].shname = ibuf + *tarr + 2; dlls[ic].shname = n;
} }
soimport++; // separator soimport++; // separator
} }
@@ -343,8 +348,10 @@ unsigned PackArmPe::processImports() // pass 1
for (ic = 0; ic < dllnum; ic++) for (ic = 0; ic < dllnum; ic++)
{ {
LE32 *tarr = idlls[ic]->lookupt; LE32 *tarr = idlls[ic]->lookupt;
#if 0 && ENABLE_THIS_AND_UNCOMPRESSION_WILL_BREAK
if (!*tarr) // no imports from this dll if (!*tarr) // no imports from this dll
continue; continue;
#endif
set_le32(ppi,idlls[ic]->npos); set_le32(ppi,idlls[ic]->npos);
set_le32(ppi+4,idlls[ic]->iat - rvamin); set_le32(ppi+4,idlls[ic]->iat - rvamin);
ppi += 8; ppi += 8;
@@ -412,7 +419,7 @@ unsigned PackArmPe::processImports() // pass 1
for (ic = 0; ic < dllnum; ic++, im++) for (ic = 0; ic < dllnum; ic++, im++)
{ {
memset(im,FILLVAL,sizeof(*im)); memset(im,FILLVAL,sizeof(*im));
im->dllname = ptr_diff(idlls[ic]->name,ibuf); // I only need this info im->dllname = ptr_diff(dlls[idlls[ic]->original_position].name,ibuf);
} }
} }
else else
@@ -592,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);
+4 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,8 @@
#ifndef __UPX_P_ARMPE_H #ifndef __UPX_P_ARMPE_H
#define __UPX_P_ARMPE_H #define __UPX_P_ARMPE_H 1
/************************************************************************* /*************************************************************************
// arm/pe // arm/pe
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -36,7 +36,7 @@
static const static const
#include "stub/i086-dos16.com.h" #include "stub/i086-dos16.com.h"
//#define TESTING //#define TESTING 1
/************************************************************************* /*************************************************************************
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_COM_H #ifndef __UPX_P_COM_H
#define __UPX_P_COM_H #define __UPX_P_COM_H 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_DJGPP2_H #ifndef __UPX_P_DJGPP2_H
#define __UPX_P_DJGPP2_H #define __UPX_P_DJGPP2_H 1
/************************************************************************* /*************************************************************************
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_ELF_H #ifndef __UPX_P_ELF_H
#define __UPX_P_ELF_H #define __UPX_P_ELF_H 1
/************************************************************************* /*************************************************************************
+52 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -152,6 +152,7 @@
DT_RELENT = 19, /* Size of one Rel relocation */ DT_RELENT = 19, /* Size of one Rel relocation */
DT_STRSZ = 10, /* Sizeof string table */ DT_STRSZ = 10, /* Sizeof string table */
DT_PLTREL = 20, /* Type of reloc in PLT */ DT_PLTREL = 20, /* Type of reloc in PLT */
DT_TEXTREL = 22, /* Reloc might modify .text */
DT_JMPREL = 23, /* Address of PLT relocs */ DT_JMPREL = 23, /* Address of PLT relocs */
DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */ DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */
DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */ DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */
@@ -195,6 +196,55 @@
#endif #endif
#ifdef WANT_NHDR_ENUM
#undef WANT_NHDR_ENUM
enum { // ELF PT_NOTE types
#define ELF_NOTE_GNU_NAME "GNU\0"
NT_GNU_ABI_TAG = 1,
NT_GNU_HWCAP = 2,
NT_GNU_BUILD_ID = 3,
#define ELF_NOTE_OPENBSD_NAME "OpenBSD\0"
NHDR_OPENBSD_TAG = 1,
#define ELF_NOTE_NETBSD_NAME "NetBSD\0"
NHDR_NETBSD_TAG = 1,
NHDR_CHECKSUM_TAG = 2,
NHDR_PAX_TAG = 3
};
enum { // descsz descriptor sizes
GNU_ABI_DESCSZ = 16, // int GNU_OS, major, minor, subminor;
NETBSD_DESCSZ = 4, // major_ver * (10**8) + minor
OPENBSD_DESCSZ = 4, // 32-bit zero
// CHECKSUM_DESCSZ is 2*sizeof(short) + sizeof(checksum)
PAX_DESCSZ = 4 // 32-bit mask
};
enum { // GNU OS/version
GNU_OS_LINUX = 0,
GNU_OS_HURD = 1,
GNU_OS_SOLARIS = 2
};
enum { // NetBSD checksum methods
CHECKSUM_CRC32 = 1,
CHECKSUM_MD5 = 2,
CHECKSUM_SHA1 = 3,
CHECKSUM_SHA256 = 4
};
#define ELF_NOTE_PAX_NAME "PaX\0"
enum { // NetBSD PaX bit values
PAX_MPROTECT = (1<<0), /* force enable Mprotect */
PAX_NOMPROTECT = (1<<1), /* force disable Mprotect */
PAX_GUARD = (1<<2), /* force enable SEGVguard */
PAX_NOGUARD = (1<<3), /* force disable SEGVguard */
PAX_ASLR = (1<<4), /* force enable ASLR */
PAX_NOASLR = (1<<5) /* force disable ASLR */
};
#endif
/* /*
vi:ts=4:et vi:ts=4:et
*/ */
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
+4 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -514,7 +514,7 @@ void PackExe::pack(OutputFile *fo)
if (ph.max_run_found + ph.max_match_found > 0x8000) if (ph.max_run_found + ph.max_match_found > 0x8000)
throwCantPack("decompressor limit exceeded, send a bugreport"); throwCantPack("decompressor limit exceeded, send a bugreport");
#ifdef TESTING #if TESTING
if (opt->debug.debug_level) if (opt->debug.debug_level)
{ {
printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len); printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len);
@@ -631,7 +631,7 @@ void PackExe::pack(OutputFile *fo)
//fprintf(stderr,"\ne_len=%x d_len=%x c_len=%x oo=%x ulen=%x destp=%x copys=%x images=%x",e_len,d_len,packedsize,ph.overlap_overhead,ph.u_len,destpara,copysize,ih_imagesize); //fprintf(stderr,"\ne_len=%x d_len=%x c_len=%x oo=%x ulen=%x destp=%x copys=%x images=%x",e_len,d_len,packedsize,ph.overlap_overhead,ph.u_len,destpara,copysize,ih_imagesize);
// write header + write loader + compressed file // write header + write loader + compressed file
#ifdef TESTING #if TESTING
if (opt->debug.debug_level) if (opt->debug.debug_level)
printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len); printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len);
#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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_EXE_H #ifndef __UPX_P_EXE_H
#define __UPX_P_EXE_H #define __UPX_P_EXE_H 1
/************************************************************************* /*************************************************************************
+790 -215
View File
File diff suppressed because it is too large Load Diff
+75 -28
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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
@@ -31,7 +31,7 @@
#ifndef __UPX_P_LX_ELF_H //{ #ifndef __UPX_P_LX_ELF_H //{
#define __UPX_P_LX_ELF_H #define __UPX_P_LX_ELF_H 1
class PackLinuxElf : public PackUnix class PackLinuxElf : public PackUnix
@@ -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
@@ -63,9 +63,8 @@ protected:
virtual void addStubEntrySections(Filter const *); virtual void addStubEntrySections(Filter const *);
virtual void unpack(OutputFile *fo); virtual void unpack(OutputFile *fo);
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const = 0; //virtual void const *elf_find_dynamic(unsigned) const = 0;
virtual void const *elf_find_dynamic(unsigned) const = 0; virtual upx_uint64_t elf_unsigned_dynamic(unsigned) const = 0;
virtual acc_uint64l_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,18 +74,23 @@ protected:
unsigned sz_phdrs; // sizeof Phdr[] unsigned sz_phdrs; // sizeof Phdr[]
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 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
@@ -103,9 +107,10 @@ protected:
// but the class hierarchy splits after this class. // but the class hierarchy splits after this class.
virtual void ARM_defineSymbols(Filter const *ft); virtual void ARM_defineSymbols(Filter const *ft);
virtual void ARM_updateLoader(OutputFile *); virtual void ARM_updateLoader(OutputFile *);
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);
@@ -132,15 +137,18 @@ protected:
static unsigned elf_hash(char const *) /*const*/; static unsigned elf_hash(char const *) /*const*/;
static unsigned gnu_hash(char const *) /*const*/; static unsigned gnu_hash(char const *) /*const*/;
virtual Elf32_Sym const *elf_lookup(char const *) const; virtual Elf32_Sym const *elf_lookup(char const *) const;
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const; virtual unsigned elf_get_offset_from_address(unsigned) const;
Elf32_Shdr const *elf_find_section_name(char const *) const; Elf32_Shdr const *elf_find_section_name(char const *) const;
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;
acc_uint64l_t elf_unsigned_dynamic(unsigned) const; Elf32_Dyn const *elf_has_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
Elf32_Phdr *phdri; // for input file Elf32_Phdr *phdri; // for input file
unsigned char *note_body; // concatenated contents of PT_NOTEs, if any
unsigned note_size; // total size of PT_NOTEs
Elf32_Shdr const *shdri; // from input file Elf32_Shdr const *shdri; // from input file
unsigned page_mask; // AND clears the offset-within-page unsigned page_mask; // AND clears the offset-within-page
@@ -173,23 +181,36 @@ protected:
l_info linfo; l_info linfo;
__packed_struct_end() __packed_struct_end()
cprElfHdr3 elfout; __packed_struct(cprElfHdrNetBSD)
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[4];
unsigned char notes[512];
__packed_struct_end()
struct Elf32_Note { cprElfHdrNetBSD elfout;
unsigned namesz; // 8
unsigned descsz; // 4 __packed_struct(cprElfShdr3)
unsigned type; // 1 Elf32_Shdr shdr[3];
char text[0x18 - 4*4]; // "OpenBSD" __packed_struct_end()
unsigned end; // 0
} elfnote; cprElfShdr3 shdrout;
struct Elf32_Nhdr {
unsigned namesz;
unsigned descsz;
unsigned type;
//unsigned char body[0];
};
static void compileTimeAssertions() { static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12) COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12) COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12) COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdrNetBSD) == 52 + 4*32 + 512)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1) COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2) COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3) COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdrNetBSD)
} }
}; };
@@ -206,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);
@@ -229,17 +250,20 @@ 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 unsigned 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;
acc_uint64l_t elf_unsigned_dynamic(unsigned) const; Elf64_Dyn const *elf_has_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
Elf64_Phdr *phdri; // for input file Elf64_Phdr *phdri; // for input file
unsigned char *note_body; // concatenated contents of PT_NOTEs, if any
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
@@ -270,15 +294,29 @@ protected:
l_info linfo; l_info linfo;
__packed_struct_end() __packed_struct_end()
cprElfHdr3 elfout; __packed_struct(cprElfHdr4)
Elf64_Ehdr ehdr;
Elf64_Phdr phdr[4];
l_info linfo;
__packed_struct_end()
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)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 64 + 3*56 + 12) COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 64 + 3*56 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr4) == 64 + 4*56 + 12)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1) COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2) COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3) COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr4)
} }
}; };
@@ -406,13 +444,21 @@ public:
virtual const char *getFullName(const options_t *) const { return "i386-freebsd.elf"; } virtual const char *getFullName(const options_t *) const { return "i386-freebsd.elf"; }
}; };
class PackNetBSDElf32x86 : public PackBSDElf32x86 class PackNetBSDElf32x86 : public PackLinuxElf32x86
{ {
typedef PackBSDElf32x86 super; typedef PackLinuxElf32x86 super;
public: public:
PackNetBSDElf32x86(InputFile *f); PackNetBSDElf32x86(InputFile *f);
virtual ~PackNetBSDElf32x86(); virtual ~PackNetBSDElf32x86();
virtual const char *getName() const { return "netbsd/elf386"; }
virtual const char *getFullName(const options_t *) const { return "i386-netbsd.elf"; } virtual const char *getFullName(const options_t *) const { return "i386-netbsd.elf"; }
protected:
virtual void buildLoader(const Filter *ft);
virtual void generateElfHdr(
OutputFile *,
void const *proto,
unsigned const brka
);
}; };
class PackOpenBSDElf32x86 : public PackBSDElf32x86 class PackOpenBSDElf32x86 : public PackBSDElf32x86
@@ -421,6 +467,7 @@ class PackOpenBSDElf32x86 : public PackBSDElf32x86
public: public:
PackOpenBSDElf32x86(InputFile *f); PackOpenBSDElf32x86(InputFile *f);
virtual ~PackOpenBSDElf32x86(); virtual ~PackOpenBSDElf32x86();
virtual const char *getName() const { return "opnbsd/elf386"; }
virtual const char *getFullName(const options_t *) const { return "i386-openbsd.elf"; } virtual const char *getFullName(const options_t *) const { return "i386-openbsd.elf"; }
protected: protected:
+7 -7
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2001-2010 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;
@@ -601,11 +601,11 @@ void PackLinuxI386::patchLoaderChecksum()
// checksum for loader + p_info // checksum for loader + p_info
lp->l_checksum = 0; lp->l_checksum = 0;
lp->l_magic = UPX_ELF_MAGIC; lp->l_magic = UPX_ELF_MAGIC;
lp->l_lsize = (unsigned short) lsize; set_te16(&lp->l_lsize, (unsigned short) lsize);
lp->l_version = (unsigned char) ph.version; lp->l_version = (unsigned char) ph.version;
lp->l_format = (unsigned char) ph.format; lp->l_format = (unsigned char) ph.format;
// INFO: lp->l_checksum is currently unused // INFO: lp->l_checksum is currently unused
lp->l_checksum = upx_adler32(ptr, lsize); set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
} }
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -30,7 +30,7 @@
#ifndef __UPX_P_LX_EXC_H #ifndef __UPX_P_LX_EXC_H
#define __UPX_P_LX_EXC_H #define __UPX_P_LX_EXC_H 1
/************************************************************************* /*************************************************************************
+7 -7
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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
@@ -114,7 +114,7 @@ void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
h3.phdr[2].p_align = 1; h3.phdr[2].p_align = 1;
if (opt->o_unix.make_ptinterp) { // unusual "once per release" if (opt->o_unix.make_ptinterp) { // unusual "once per release"
elfout = h3; *(cprElfHdr3 *)(void *)&elfout = h3;
elfout.ehdr.e_phnum = 1; elfout.ehdr.e_phnum = 1;
fo->write(&elfout, elfout.ehdr.e_ehsize + elfout.ehdr.e_phentsize); fo->write(&elfout, elfout.ehdr.e_ehsize + elfout.ehdr.e_phentsize);
} }
@@ -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
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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
@@ -31,7 +31,7 @@
#ifndef __UPX_P_LX_INTERP_H //{ #ifndef __UPX_P_LX_INTERP_H //{
#define __UPX_P_LX_INTERP_H #define __UPX_P_LX_INTERP_H 1
/************************************************************************* /*************************************************************************
@@ -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2010 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
@@ -31,7 +31,7 @@
#ifndef __UPX_P_LX_SH_H //{ #ifndef __UPX_P_LX_SH_H //{
#define __UPX_P_LX_SH_H #define __UPX_P_LX_SH_H 1
/************************************************************************* /*************************************************************************
+299 -69
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-2010 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);
@@ -429,11 +429,11 @@ void PackMachBase<T>::patchLoaderChecksum()
// checksum for loader; also some PackHeader info // checksum for loader; also some PackHeader info
lp->l_checksum = 0; lp->l_checksum = 0;
lp->l_magic = UPX_MAGIC_LE32; // LE32 always lp->l_magic = UPX_MAGIC_LE32; // LE32 always
lp->l_lsize = (unsigned short) lsize; set_te16(&lp->l_lsize, (unsigned short) lsize);
lp->l_version = (unsigned char) ph.version; lp->l_version = (unsigned char) ph.version;
lp->l_format = (unsigned char) ph.format; lp->l_format = (unsigned char) ph.format;
// INFO: lp->l_checksum is currently unused // INFO: lp->l_checksum is currently unused
lp->l_checksum = upx_adler32(ptr, lsize); set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
} }
template <class T> template <class T>
@@ -447,76 +447,210 @@ 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;
// Beware 0==.vmsize (some MacOSX __DWARF debug info: a "comment")
if (a->vmsize!=0 && b->vmsize!=0) {
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr
if (a->vmaddr > b->vmaddr) return 1; 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)
super::pack4(fo, ft); + sizeof(segTEXT) + sizeof(secTEXT)
segcmdo.filesize = fo->getBytesWritten(); + sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
segcmdo.vmsize += segcmdo.filesize; if (my_filetype==Mach_header::MH_EXECUTE) {
fo->seek(sizeof(mhdro), SEEK_SET); overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
fo->rewrite(&segcmdo, sizeof(segcmdo));
fo->rewrite(&threado, sizeof(threado));
fo->rewrite(&linfo, sizeof(linfo));
} }
#undef PAGE_MASK super::pack4(fo, ft);
#undef PAGE_SIZE unsigned const t = fo->getBytesWritten();
#define PAGE_MASK (~0u<<12) segTEXT.filesize = t;
#define PAGE_SIZE -PAGE_MASK segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
secTEXT.offset = overlay_offset - sizeof(linfo);
#undef PAGE_MASK64 secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
#undef PAGE_SIZE64 secTEXT.size = segTEXT.vmsize - secTEXT.offset;
#define PAGE_MASK64 (~(acc_uint64l_t)0<<12) secXHDR.offset = overlay_offset - sizeof(linfo);
#define PAGE_SIZE64 -PAGE_MASK64 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->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));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo));
}
template <class T> template <class T>
void PackMachBase<T>::pack4dylib( // append PackHeader void PackMachBase<T>::pack4dylib( // append PackHeader
@@ -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);
} }
@@ -861,6 +995,8 @@ unsigned PackMachBase<T>::find_SEGMENT_gap(
} }
unsigned const hi = msegcmd[k].fileoff + msegcmd[k].filesize; unsigned const hi = msegcmd[k].fileoff + msegcmd[k].filesize;
unsigned lo = ph.u_file_size; unsigned lo = ph.u_file_size;
if (lo < hi)
throwCantPack("bad input: LC_SEGMENT beyond end-of-file");
unsigned j = k; unsigned j = k;
for (;;) { // circular search, optimize for adjacent ascending for (;;) { // circular search, optimize for adjacent ascending
++j; ++j;
@@ -897,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;
@@ -974,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)
@@ -1023,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);
@@ -1071,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));
@@ -1124,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));
@@ -1145,10 +1338,12 @@ 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);
if (fo)
fo->seek(sc->fileoff, SEEK_SET); 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);
if (fo)
fo->write(data, len); fo->write(data, len);
} }
} }
@@ -1157,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;
} }
@@ -1205,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;
} }
@@ -1349,15 +1544,19 @@ void PackMachFat::pack(OutputFile *fo)
void PackMachFat::unpack(OutputFile *fo) void PackMachFat::unpack(OutputFile *fo)
{ {
if (fo) { // test mode ("-t") sets fo = NULL
fo->seek(0, SEEK_SET); fo->seek(0, SEEK_SET);
fo->write(&fat_head, sizeof(fat_head.fat) + fo->write(&fat_head, sizeof(fat_head.fat) +
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0])); fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
}
unsigned length; unsigned length;
for (unsigned j=0; j < fat_head.fat.nfat_arch; ++j) { for (unsigned j=0; j < fat_head.fat.nfat_arch; ++j) {
unsigned base = fo->unset_extent(); // actual length unsigned base = (fo ? fo->unset_extent() : 0); // actual length
base += ~(~0u<<fat_head.arch[j].align) & (0-base); // align up base += ~(~0u<<fat_head.arch[j].align) & (0-base); // align up
if (fo) {
fo->seek(base, SEEK_SET); fo->seek(base, SEEK_SET);
fo->set_extent(base, ~0u); fo->set_extent(base, ~0u);
}
ph.u_file_size = fat_head.arch[j].size; ph.u_file_size = fat_head.arch[j].size;
fi->set_extent(fat_head.arch[j].offset, fat_head.arch[j].size); fi->set_extent(fat_head.arch[j].offset, fat_head.arch[j].size);
@@ -1380,6 +1579,23 @@ void PackMachFat::unpack(OutputFile *fo)
packer.unpack(fo); packer.unpack(fo);
} }
} break; } break;
case PackMachFat::CPU_TYPE_X86_64: {
N_Mach::Mach_header<MachClass_LE64::MachITypes> hdr;
typedef N_Mach::Mach_header<MachClass_LE64::MachITypes> Mach_header;
fi->readx(&hdr, sizeof(hdr));
if (hdr.filetype==Mach_header::MH_EXECUTE) {
PackMachAMD64 packer(fi);
packer.initPackHeader();
packer.canUnpack();
packer.unpack(fo);
}
else if (hdr.filetype==Mach_header::MH_DYLIB) {
PackDylibAMD64 packer(fi);
packer.initPackHeader();
packer.canUnpack();
packer.unpack(fo);
}
} break;
case PackMachFat::CPU_TYPE_POWERPC: { case PackMachFat::CPU_TYPE_POWERPC: {
N_Mach::Mach_header<MachClass_BE32::MachITypes> hdr; N_Mach::Mach_header<MachClass_BE32::MachITypes> hdr;
typedef N_Mach::Mach_header<MachClass_BE32::MachITypes> Mach_header; typedef N_Mach::Mach_header<MachClass_BE32::MachITypes> Mach_header;
@@ -1399,14 +1615,16 @@ void PackMachFat::unpack(OutputFile *fo)
} break; } break;
} // switch cputype } // switch cputype
fat_head.arch[j].offset = base; fat_head.arch[j].offset = base;
length = fo->unset_extent(); length = (fo ? fo->unset_extent() : 0);
fat_head.arch[j].size = length - base; fat_head.arch[j].size = length - base;
} }
if (fo) {
fo->unset_extent(); fo->unset_extent();
fo->seek(0, SEEK_SET); fo->seek(0, SEEK_SET);
fo->rewrite(&fat_head, sizeof(fat_head.fat) + fo->rewrite(&fat_head, sizeof(fat_head.fat) +
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0])); fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
} }
}
bool PackMachFat::canPack() bool PackMachFat::canPack()
{ {
@@ -1487,6 +1705,18 @@ int PackMachFat::canUnpack()
else else
ph.format = packer.getFormat(); // FIXME: copy entire PackHeader ph.format = packer.getFormat(); // FIXME: copy entire PackHeader
} break; } break;
case PackMachFat::CPU_TYPE_X86_64: {
PackMachAMD64 packer(fi);
if (!packer.canUnpack()) {
PackDylibAMD64 pack2r(fi);
if (!pack2r.canUnpack())
return 0;
else
ph.format = pack2r.getFormat(); // FIXME: copy entire PackHeader
}
else
ph.format = packer.getFormat(); // FIXME: copy entire PackHeader
} break;
case PackMachFat::CPU_TYPE_POWERPC: { case PackMachFat::CPU_TYPE_POWERPC: {
PackMachPPC32 packer(fi); PackMachPPC32 packer(fi);
if (!packer.canUnpack()) { if (!packer.canUnpack()) {
+55 -11
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_MACHO_H #ifndef __UPX_P_MACHO_H
#define __UPX_P_MACHO_H #define __UPX_P_MACHO_H 1
__packed_struct(Mach_fat_header) __packed_struct(Mach_fat_header)
@@ -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
@@ -640,7 +684,7 @@ protected:
BE32 flavor; BE32 flavor;
BE32 count; /* sizeof(following_thread_state)/4 */ BE32 count; /* sizeof(following_thread_state)/4 */
Mach_ppc_thread_state state; Mach_ppc_thread_state state;
#define WANT_MACH_THREAD_ENUM #define WANT_MACH_THREAD_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
__packed_struct_end() __packed_struct_end()
@@ -689,7 +733,7 @@ protected:
LE32 flavor; LE32 flavor;
LE32 count; /* sizeof(following_thread_state)/4 */ LE32 count; /* sizeof(following_thread_state)/4 */
Mach_i386_thread_state state; Mach_i386_thread_state state;
#define WANT_MACH_THREAD_ENUM #define WANT_MACH_THREAD_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
__packed_struct_end() __packed_struct_end()
@@ -738,7 +782,7 @@ protected:
LE32 flavor; LE32 flavor;
LE32 count; /* sizeof(following_thread_state)/4 */ LE32 count; /* sizeof(following_thread_state)/4 */
Mach_AMD64_thread_state state; Mach_AMD64_thread_state state;
#define WANT_MACH_THREAD_ENUM #define WANT_MACH_THREAD_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
__packed_struct_end() __packed_struct_end()
@@ -788,7 +832,7 @@ protected:
LE32 flavor; LE32 flavor;
LE32 count; /* sizeof(following_thread_state)/4 */ LE32 count; /* sizeof(following_thread_state)/4 */
Mach_ARM_thread_state state; Mach_ARM_thread_state state;
#define WANT_MACH_THREAD_ENUM #define WANT_MACH_THREAD_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
__packed_struct_end() __packed_struct_end()
@@ -841,7 +885,7 @@ protected:
// linker // linker
Linker *linker; Linker *linker;
#define WANT_MACH_HEADER_ENUM #define WANT_MACH_HEADER_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
}; };
+8 -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-2010 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
@@ -52,10 +52,12 @@
}; };
enum { // filetype enum { // filetype
MH_EXECUTE = 2, MH_EXECUTE = 2,
MH_DYLIB = 6 MH_DYLIB = 6,
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 /*}*/
@@ -79,6 +81,9 @@
LC_CODE_SIGNATURE = 0x1d, LC_CODE_SIGNATURE = 0x1d,
LC_SEGMENT_SPLIT_INFO = 0x1e, LC_SEGMENT_SPLIT_INFO = 0x1e,
LC_REEXPORT_DYLIB = 0x1f, LC_REEXPORT_DYLIB = 0x1f,
LC_LAZY_LOAD_DYLIB= 0X20,
LC_ENCRYPTION_INFO= 0X21,
LC_DYLD_INFO = 0X22, // compressed dyld information (10.6.x)
LC_REQ_DYLD = 0x80000000 // OR'ed ==> must not ignore LC_REQ_DYLD = 0x80000000 // OR'ed ==> must not ignore
}; };
enum { // maxprot enum { // maxprot
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2002-2010 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
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 Laszlo Molnar Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2002-2010 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
@@ -31,7 +31,7 @@
#ifndef __UPX_P_PS1_H #ifndef __UPX_P_PS1_H
#define __UPX_P_PS1_H #define __UPX_P_PS1_H 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_SYS_H #ifndef __UPX_P_SYS_H
#define __UPX_P_SYS_H #define __UPX_P_SYS_H 1
/************************************************************************* /*************************************************************************
+5 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -327,7 +327,9 @@ void PackTmt::unpack(OutputFile *fo)
{ {
Filter ft(ph.level); Filter ft(ph.level);
ft.init(ph.filter, 0); ft.init(ph.filter, 0);
ft.cto = (unsigned char) (ph.version < 11 ? (get_le32(obuf+ph.u_len-12) >> 24) : ph.filter_cto); ft.cto = (unsigned char) ph.filter_cto;
if (ph.version < 11)
ft.cto = (unsigned char) (get_le32(obuf+ph.u_len-12) >> 24);
ft.unfilter(obuf, ptr_diff(relocs, obuf)); ft.unfilter(obuf, ptr_diff(relocs, obuf));
} }
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_TMT_H #ifndef __UPX_P_TMT_H
#define __UPX_P_TMT_H #define __UPX_P_TMT_H 1
/************************************************************************* /*************************************************************************
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -446,7 +446,7 @@ void PackTos::pack(OutputFile *fo)
overlay = file_size - (FH_SIZE + i_text + i_data + i_sym); overlay = file_size - (FH_SIZE + i_text + i_data + i_sym);
fi->readx(ibuf+t,overlay); fi->readx(ibuf+t,overlay);
#if 0 || defined(TESTING) #if 0 || (TESTING)
printf("text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n", printf("text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
i_text, i_data, i_sym, i_bss, (int)ih.fh_flag); i_text, i_data, i_sym, i_bss, (int)ih.fh_flag);
printf("xx1 reloc: %d, overlay: %d, fixup: %d\n", relocsize, overlay, overlay >= 4 ? (int)get_be32(ibuf+t) : -1); printf("xx1 reloc: %d, overlay: %d, fixup: %d\n", relocsize, overlay, overlay >= 4 ? (int)get_be32(ibuf+t) : -1);
@@ -476,7 +476,7 @@ void PackTos::pack(OutputFile *fo)
symbols.need_reloc = true; symbols.need_reloc = true;
} }
#if 0 || defined(TESTING) #if 0 || (TESTING)
printf("xx2: %d relocs: %d, overlay: %d, t: %d\n", nrelocs, relocsize, overlay, t); printf("xx2: %d relocs: %d, overlay: %d, t: %d\n", nrelocs, relocsize, overlay, t);
#endif #endif
@@ -487,7 +487,7 @@ void PackTos::pack(OutputFile *fo)
ih.fh_sym = 0; // we stripped all symbols ih.fh_sym = 0; // we stripped all symbols
memcpy(ibuf+t, &ih, FH_SIZE); memcpy(ibuf+t, &ih, FH_SIZE);
t += FH_SIZE; t += FH_SIZE;
#if 0 || defined(TESTING) #if 0 || (TESTING)
printf("xx3 reloc: %d, overlay: %d, t: %d\n", relocsize, overlay, t); printf("xx3 reloc: %d, overlay: %d, t: %d\n", relocsize, overlay, t);
#endif #endif
assert(t <= isize); assert(t <= isize);
@@ -686,7 +686,7 @@ void PackTos::pack(OutputFile *fo)
// add an empty relocation fixup to workaround a bug in some TOS versions // add an empty relocation fixup to workaround a bug in some TOS versions
oh.fh_reloc = 0; oh.fh_reloc = 0;
#if 0 || defined(TESTING) #if 0 || (TESTING)
printf("old text: %6d, data: %6d, bss: %6d, reloc: %d, overlay: %d\n", printf("old text: %6d, data: %6d, bss: %6d, reloc: %d, overlay: %d\n",
i_text, i_data, i_bss, relocsize, overlay); i_text, i_data, i_bss, relocsize, overlay);
printf("new text: %6d, data: %6d, bss: %6d, flag=0x%x\n", printf("new text: %6d, data: %6d, bss: %6d, flag=0x%x\n",
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_TOS_H #ifndef __UPX_P_TOS_H
#define __UPX_P_TOS_H #define __UPX_P_TOS_H 1
/************************************************************************* /*************************************************************************
+25 -12
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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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
@@ -231,11 +235,11 @@ PackUnix::patchLoaderChecksum()
l_info *const lp = &linfo; l_info *const lp = &linfo;
// checksum for loader; also some PackHeader info // checksum for loader; also some PackHeader info
lp->l_magic = UPX_MAGIC_LE32; // LE32 always lp->l_magic = UPX_MAGIC_LE32; // LE32 always
lp->l_lsize = (unsigned short) lsize; set_te16(&lp->l_lsize, (unsigned short) lsize);
lp->l_version = (unsigned char) ph.version; lp->l_version = (unsigned char) ph.version;
lp->l_format = (unsigned char) ph.format; lp->l_format = (unsigned char) ph.format;
// INFO: lp->l_checksum is currently unused // INFO: lp->l_checksum is currently unused
lp->l_checksum = upx_adler32(ptr, lsize); set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
} }
void PackUnix::pack3(OutputFile *fo, Filter &/*ft*/) void PackUnix::pack3(OutputFile *fo, Filter &/*ft*/)
@@ -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[128]; 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");
+4 -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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_UNIX_H #ifndef __UPX_P_UNIX_H
#define __UPX_P_UNIX_H #define __UPX_P_UNIX_H 1
/************************************************************************* /*************************************************************************
@@ -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
+12 -8
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 2004-2010 John Reiser Copyright (C) 2004-2013 John Reiser
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,6 +322,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
unsigned const frag = (3& (0u-len_cpr)); unsigned const frag = (3& (0u-len_cpr));
ppc32_extra += sizeof(hdr_info) + len_cpr + frag; ppc32_extra += sizeof(hdr_info) + len_cpr + frag;
fo_off += len_cpr + frag; fo_off += len_cpr + frag;
memset(&cpr_hdr[len_cpr], 0, frag); // valgrind only
fo->write(cpr_hdr, len_cpr + frag); fo->write(cpr_hdr, len_cpr + frag);
// Partial filter: .text and following contiguous SHF_EXECINSTR // Partial filter: .text and following contiguous SHF_EXECINSTR
@@ -986,11 +987,14 @@ void PackVmlinuxPPC32::buildLoader(const Filter *ft)
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX030", NULL); addLoader("LINUX030", NULL);
if (ph.method == M_NRV2E_LE32) addLoader("NRV2E", NULL); if (ph.method == M_NRV2E_LE32) addLoader("NRV2E,NRV_TAIL", NULL);
else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B", NULL); else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B,NRV_TAIL", NULL);
else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D", NULL); else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D,NRV_TAIL", NULL);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL);
else throwBadLoader(); else throwBadLoader();
if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH");
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", NULL);
} }
@@ -1075,8 +1079,8 @@ void PackVmlinuxAMD64::defineDecompressorSymbols()
// We assume a 32-bit boot loader, so we use the 32-bit convention // We assume a 32-bit boot loader, so we use the 32-bit convention
// of "enter at the beginning" (startup_32). The 64-bit convention // of "enter at the beginning" (startup_32). The 64-bit convention
// would be to use ehdri.e_entry (startup_64). // would be to use ehdri.e_entry (startup_64).
linker->defineSymbol("ENTRY_POINT", phdri[0].p_paddr); linker->defineSymbol("ENTRY_POINT", (unsigned) phdri[0].p_paddr);
linker->defineSymbol("PHYSICAL_START", phdri[0].p_paddr); linker->defineSymbol("PHYSICAL_START", (unsigned) phdri[0].p_paddr);
} }
unsigned PackVmlinuxARMEL::write_vmlinux_head( unsigned PackVmlinuxARMEL::write_vmlinux_head(
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_VMLINX_H #ifndef __UPX_P_VMLINX_H
#define __UPX_P_VMLINX_H #define __UPX_P_VMLINX_H 1
#include "p_elf.h" #include "p_elf.h"
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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);
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_VMLINZ_H #ifndef __UPX_P_VMLINZ_H
#define __UPX_P_VMLINZ_H #define __UPX_P_VMLINZ_H 1
/************************************************************************* /*************************************************************************
+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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_VXD_H #ifndef __UPX_P_VXD_H
#define __UPX_P_VXD_H #define __UPX_P_VXD_H 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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-2010 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2010 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,7 +27,7 @@
#ifndef __UPX_P_W16NE_H #ifndef __UPX_P_W16NE_H
#define __UPX_P_W16NE_H #define __UPX_P_W16NE_H 1
/************************************************************************* /*************************************************************************

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