Compare commits

...

274 Commits

Author SHA1 Message Date
Markus F.X.J. Oberhumer fc57390242 Bump release date. 2009-09-27 20:06:01 +02:00
Markus F.X.J. Oberhumer bd15ef0a0c Bump tentative 3.04 release date. 2009-09-21 05:44:19 +02:00
Markus F.X.J. Oberhumer 967ecafc33 Small compatibility updates. 2009-09-21 05:41:49 +02:00
John Reiser 29576da985 catch up to bugfix for arm-darwin stub 2009-09-01 07:33:08 -07:00
John Reiser 200a2556ef New format Mach/AMD64 for 64-bit x86 programs on Apple Macintosh 2009-09-01 07:30:37 -07:00
John Reiser ae0ab5025e fix debug mixup 2009-09-01 07:21:18 -07:00
John Reiser aa74276b25 gcc-4.4.1 is more strict about 'const' 2009-08-30 19:44:45 -07:00
Markus F.X.J. Oberhumer b03112a5dd Silence some compilation warnings. 2009-06-09 13:11:21 +02:00
Markus F.X.J. Oberhumer a3f49df62d Remove trailing whitespace. 2009-06-09 09:43:00 +02:00
Markus F.X.J. Oberhumer aa2af3f6dd Add missing stub to repo. 2009-06-09 09:40:25 +02:00
John Reiser 20dcbc593c PackMachFat for MH_DYLIB, too. 2009-06-01 16:23:13 -07:00
John Reiser 472ba8c1fd UPX_F_DYLIB_PPC32 is big endian, so move to >=128 2009-06-01 12:38:20 -07:00
John Reiser d8345a44a4 Dylib/ppc32 format works. 2009-05-31 12:57:10 -07:00
John Reiser a187cb6c9c work on stub for powerpc-darwin.dylib-entry.S 2009-05-29 22:08:08 -07:00
John Reiser b89c0b35d1 bugfix: PackMachBase::pack2 first extent is Mach_header plus Mach_segment_commands 2009-05-29 13:38:43 -07:00
John Reiser 7ffcc0a5e7 powerpc-darwin.dylib 2009-05-27 10:19:50 -07:00
John Reiser bde43fbdfb PackMachBase<T>::pack4dylib to prepare for more architectures 2009-05-23 21:13:44 -07:00
John Reiser 3728b2208f Cleanup declaration of PackDylibI386. 2009-05-22 08:37:44 -07:00
John Reiser dc52a756ee i386-darwin.dylib-entry.bin.dump 2009-05-21 22:06:26 -07:00
John Reiser 98dc886841 i386-darwin kernel expects 64-bit off_t; we always use 0 for top 32 bits. 2009-05-21 21:50:17 -07:00
John Reiser d0cf104e43 Announce Dylib/i386 format in NEWS. 2009-05-20 08:11:04 -07:00
John Reiser d7ed2412f6 386-darwin.dylib decompressor chains to user .init_address 2009-05-20 07:10:14 -07:00
John Reiser 7d38f0e234 i386-darwin.dylib ::unpack 2009-05-19 15:57:18 -07:00
John Reiser 3e8d072d24 i386-darwin.dylib requires existing LC_ROUINTES command;
decompressor must not overwrite Mach_headers.
2009-05-19 09:43:05 -07:00
John Reiser 84ac771893 Decompression part for Mach dylib i386. 2009-05-18 11:59:11 -07:00
John Reiser 3a9e0b5be6 Compression part for Mach dylib i386. 2009-05-13 10:40:21 -07:00
Markus F.X.J. Oberhumer 9694ff433f Fix grammar in version date. 2009-04-19 20:14:24 +02:00
Markus F.X.J. Oberhumer 2e82e78b98 Bump tentative release date. 2009-04-19 18:46:31 +02:00
Markus F.X.J. Oberhumer aaef4bee27 Prefer memcpy() over struct-copy. 2009-04-19 18:44:17 +02:00
Markus F.X.J. Oberhumer 4ca8569488 Remove trailing whitespace. 2009-04-19 18:36:42 +02:00
John Reiser 8377ada3e0 catch up stubs for arm 2009-03-01 11:19:05 -08:00
John Reiser 8a034d59ed arm linux kernel --small: hand assembly for LzmaDecode 2009-02-26 13:07:11 -08:00
John Reiser 8e492d8798 arm linux kernel: decompress_kernel() returns length, not pointer 2009-02-25 13:50:55 -08:00
John Reiser 7974ef80d7 branch merge 2009-02-12 12:42:57 -08:00
John Reiser 3664d86430 i386-linux.elf-fold fix compressed size for ET_DYN 2009-02-12 12:41:10 -08:00
Markus F.X.J. Oberhumer 9adef80d6b Replace all __attribute_packed by new __packed_struct macros. 2009-02-12 05:20:23 +01:00
Markus F.X.J. Oberhumer be57adaee7 Update tools/armpe_tester. 2009-02-12 03:33:14 +01:00
Markus F.X.J. Oberhumer d117e442a4 Silence a compiler warning. 2009-01-27 19:05:18 +01:00
Markus F.X.J. Oberhumer 8820bc0796 Add support for LZMA SDK 4.62. Compiles, but pretty much untested. 2009-01-03 23:33:25 +01:00
Markus F.X.J. Oberhumer 57a64de023 Small conf.h update. 2009-01-01 13:40:52 +01:00
Markus F.X.J. Oberhumer 5ed689ceb0 Enter 2009. 2008-12-31 17:07:18 +01:00
Markus F.X.J. Oberhumer 25f1765f36 Support building with OpenWatcom 1.8. Silence some compiler warnings. 2008-12-31 16:56:38 +01:00
Markus F.X.J. Oberhumer 063bd58802 Silence gcc's -Wstrict-aliasing=1 warnings. 2008-12-29 23:15:56 +01:00
Markus F.X.J. Oberhumer 901c6b34fa New ACC version. 2008-12-29 23:14:54 +01:00
Markus F.X.J. Oberhumer 5b2d6488a2 Silence some compilation warnings. 2008-12-29 22:22:28 +01:00
László Molnár f6f35415d1 check processor type in PackW32Pe::canUnpack 2008-12-20 14:48:13 +01:00
Markus F.X.J. Oberhumer 6c6069e963 New ACC version. 2008-12-16 23:59:37 +01:00
Markus F.X.J. Oberhumer 6219d82560 Detabified some sources. 2008-11-16 19:03:40 +01:00
John Reiser 1dcd7a16ab add missing source file 2008-11-16 08:01:40 -08:00
John Reiser b60caeb9dd source files for arm-darwin.macho-*.S 2008-11-16 07:35:53 -08:00
John Reiser 4c4768aaf3 derived .h fles for arm-darwin.macho 2008-11-15 14:46:03 -08:00
John Reiser 2f4ac0a663 format UPX_F_MACH_ARMEL, class PackMachARMEL: iPhone 2008-11-15 14:44:19 -08:00
John Reiser 23a446f852 unshare armel-linux.elf-main.o vs. arm-linux.elf-main.o (for comiler flags) 2008-11-15 14:09:06 -08:00
John Reiser ec48334a1a propagate changes into stub/amd64-linux.elf-fold.h 2008-11-15 08:52:02 -08:00
John Reiser f4c061d412 amd64-linux.elf: workaround for SIGSEGV on Centos 5.2
https://sourceforge.net/tracker/?func=detail&atid=102331&aid=2136491&group_id=2331
2008-11-15 08:49:13 -08:00
John Reiser 31a076d7b3 PackVmlinuzARMEL: only 8-bit control words for compression 2008-11-15 08:44:50 -08:00
John Reiser 6bd43d986c sync stub for armel-linux.kernel.vmlinuz.h 2008-09-15 13:51:55 -07:00
John Reiser dd32a2f15a forgot source for armel-linux.kernel.vmlinuz stubs 2008-09-15 10:35:53 -07:00
John Reiser c88c20820f new format vmlinuz/armel for Debian NSLU2 (etc.) linux kernel 2008-09-15 10:18:19 -07:00
John Reiser 86de510731 bvmlinuz boot protocol 2.08 (not yet complete?) 2008-08-04 17:30:44 -07:00
John Reiser 0b31fbf827 armel-eabi sets Elf32_Ehdr::EI_ABIVERSION = 4 2008-08-04 17:29:59 -07:00
John Reiser 34ad1450eb boot protocol 2.08 for bvmlinuz; Extended ABI version 4 for armel-eabi 2008-08-04 17:28:23 -07:00
John Reiser e6ba71390d armel-eabi choose proper decompressor 2008-07-20 15:35:19 -07:00
John Reiser f0c8dbe0ec armel-eabi-linux.elf (Debian) new protocol for system calls 2008-07-20 05:41:51 -07:00
John Reiser bf046a8ccb more checking when treating ELF as .bin 2008-07-20 05:40:00 -07:00
John Reiser b05ba7683e bvmlinuz/386 boot protocol 2.08 has gzipped ELF [needs more work] 2008-07-18 15:02:28 -07:00
John Reiser aedf8dad15 amd64 argc can be zero 2008-07-16 14:56:44 -07:00
John Reiser 74ebb7c722 more get_te32(&...) needed for endian neutrality 2008-07-16 13:49:28 -07:00
John Reiser 1307f66494 stub/i386-*.*-fold.S: allow 0==argc 2008-05-15 09:05:20 -07:00
John Reiser 448a24cb36 PackVmlinuzI386::getStrategy(), and Bvmlinuz guesses 60% .text;
stack for Bvmlinuz uses vacant Vmlinuz low memory (512 KiB)
2008-05-02 04:59:39 -07:00
Markus F.X.J. Oberhumer 7266f23450 New ACC version. 2008-04-30 02:45:13 +02:00
Markus F.X.J. Oberhumer c0ad31acfc Bump version for next release. 2008-04-27 18:46:52 +02:00
Markus F.X.J. Oberhumer 25d3a0de27 Added tag for RELEASE_303. 2008-04-27 11:38:15 +02:00
John Reiser 1e38bbfbc1 merge 2008-04-26 13:08:13 -07:00
John Reiser 1c62e95812 Bvmlinuz fix filters 2008-04-26 13:04:13 -07:00
Markus F.X.J. Oberhumer d453cc27a3 Style: start using correct IEC binary prefix (KiB, MiB, ...) - see
http://en.wikipedia.org/wiki/Binary_prefix for more details.
2008-04-26 08:48:13 +02:00
Markus F.X.J. Oberhumer 2c3e841d8a Fix comment. 2008-04-26 08:23:05 +02:00
John Reiser 50668c462f Bvmlinuz h.sys_size, and more heuristics 2008-04-25 12:07:38 -07:00
John Reiser 8d1192e832 Bvmlinuz,Vmlinuz make room for largest possible decompression stack
by moving kernel command line up, and real mode area down
2008-04-24 12:15:07 -07:00
John Reiser 4a8e2e9ed4 grub-0.97-33.fc9 does not leave enough room for lzma 2008-04-23 16:37:16 -07:00
Markus F.X.J. Oberhumer 12fc45220a Shorten --help text. 2008-04-17 14:07:03 +02:00
Markus F.X.J. Oberhumer 6bce68fbe7 Bump tentative release date. 2008-04-17 12:16:23 +02:00
Markus F.X.J. Oberhumer d54f947c98 Add Packer::hasLoaderSection() to handle missing CFLUSH sections. 2008-04-07 18:44:00 +02:00
Markus F.X.J. Oberhumer 6c8bb3a22e Rebuild all stubs with new formatting - no binary changes. 2008-04-04 17:21:24 +02:00
Markus F.X.J. Oberhumer ed29ce5183 bin2h.py: improve formatting. 2008-04-04 17:20:17 +02:00
Markus F.X.J. Oberhumer a51d269b7c Use new bin2h.py mode. 2008-04-04 16:37:12 +02:00
Markus F.X.J. Oberhumer 8283e4e6d6 bin2h.py: add support for --mode=gas-be32 and --mode=gas-le32. 2008-04-04 16:35:58 +02:00
John Reiser 23ce91eb55 MIPS big-endian lzma build rules 2008-04-03 09:01:55 -07:00
John Reiser 545ac7fcfa Merge 2008-04-02 19:10:39 -07:00
John Reiser 3926ccccad MIPS-linux.elf flush icache after moving decompressor 2008-04-02 19:09:31 -07:00
Markus F.X.J. Oberhumer f431307ef2 Silence some compilation warnings. 2008-04-02 19:24:05 +02:00
Markus F.X.J. Oberhumer ca368e0f9b Add a note about broken scanf() implementations. 2008-04-02 16:34:31 +02:00
John Reiser 8afeb56c11 Big-endian MIPS NRV nested subroutine must save+restore register ra. 2008-04-01 22:09:14 -07:00
John Reiser 2a6f90c5f3 Big-endian MIPS must fetch NRV 32-bit "control" words as little endian. 2008-04-01 20:06:27 -07:00
John Reiser 271031128e Fix ElfLinkerMipsBE::relocate1. Create CFLUSH section in
mipsel.r3000-linux.elf-entry.S and powerpc-darwin.macho-entry.S .
2008-03-31 08:55:35 -07:00
John Reiser b991f954d0 Fix "Failure with Ubuntu 7.10" SourceForge Bug tracker 1825006
when --force-execve with kernel 2.6.22-14-generic et al.
2008-03-27 15:51:19 -07:00
John Reiser f12bb3f80d bvmlinuz must preserve register esi 2008-03-04 15:41:42 -08:00
Markus F.X.J. Oberhumer 6dc978e8d8 Remove trailing whitespace. 2008-02-28 00:04:32 +01:00
John Reiser 9f05a873bc Merge 2008-02-26 12:17:21 -08:00
John Reiser 703d498772 Implement cache flush for PowerPC. 2008-02-26 12:15:09 -08:00
Markus F.X.J. Oberhumer ed3b9543bb Cosmetic Makefile update. 2008-02-26 02:59:00 +01:00
Markus F.X.J. Oberhumer fc7efba7d8 Silence some compilation warnings. 2008-02-26 02:55:39 +01:00
Markus F.X.J. Oberhumer b3178fe8f4 stub/Makefile: cosmetic updates. 2008-01-30 16:39:45 +01:00
Markus F.X.J. Oberhumer e36798a993 Remove unused stub/amd64-linux.kernel.vmlinuz. 2008-01-30 16:19:46 +01:00
Markus F.X.J. Oberhumer a143605465 Remove trailing whitespace. 2008-01-30 07:22:32 +01:00
Markus F.X.J. Oberhumer d3ad35b21e Rebuild stubs. 2008-01-30 07:20:45 +01:00
Markus F.X.J. Oberhumer 68134941bf Small Makefile update. 2008-01-30 07:20:19 +01:00
John Reiser 54d0fef559 BvmlinuzI386 runtime-relocatable kernels 2008-01-29 10:33:45 -08:00
Markus F.X.J. Oberhumer 7f9c47176a Introduce target endianness accessors get_teXX() and set_teXX() in packer.h to
replace all [gs]et_nativeXX() member functions.
2008-01-09 13:57:47 +01:00
Markus F.X.J. Oberhumer 9060ac7897 Rename template integral types from U32 to TE32 to emphasize on target
endianness.
2008-01-09 12:45:44 +01:00
John Reiser d9073e4a17 PackVmlinuzI386 detects non-relocated kernel 2008-01-08 09:03:21 -08:00
Markus F.X.J. Oberhumer de1c1d7cc2 Update help header message. 2008-01-02 11:40:16 +01:00
Markus F.X.J. Oberhumer 6ff1bd5917 Update my email address. 2008-01-02 10:12:42 +01:00
Markus F.X.J. Oberhumer a6b04f426e Bump version year. 2008-01-02 09:47:52 +01:00
Markus F.X.J. Oberhumer fa49dbe2cb Enter 2008. 2008-01-02 09:42:31 +01:00
Markus F.X.J. Oberhumer 682eb04a52 New ACC version. 2008-01-02 09:34:45 +01:00
Markus F.X.J. Oberhumer 77064fb09e Makefile update. 2008-01-02 09:32:32 +01:00
Markus F.X.J. Oberhumer be8d93563a Introduce first --mp-xxx options. 2007-12-20 06:39:31 +01:00
Markus F.X.J. Oberhumer d4a6a5216d Makefile updates. 2007-12-18 22:37:30 +01:00
Markus F.X.J. Oberhumer 1cb1427050 Detabify. 2007-12-17 06:00:33 +01:00
Markus F.X.J. Oberhumer e4f4eace1c Added support for LZMA SDK 4.57. Compiles, but pretty much untested. 2007-12-17 05:54:08 +01:00
Markus F.X.J. Oberhumer 30a98b7e8c Remove trailing whitespace. 2007-12-17 05:49:34 +01:00
Markus F.X.J. Oberhumer d36c8d95ad Bump version for next release. 2007-12-16 15:10:44 +01:00
Markus F.X.J. Oberhumer 506bd0abcf Add tag for RELEASE_302. 2007-12-16 15:08:32 +01:00
Markus F.X.J. Oberhumer 8dd810c41d Bump release date. 2007-12-16 15:07:05 +01:00
John Reiser d9d0dc5201 get_native(&Elf32_Phdr.p_align) 2007-12-15 10:07:09 -08:00
Markus F.X.J. Oberhumer 72880d9e03 Disable leftover debug printf statements. 2007-12-12 08:36:03 +01:00
Markus F.X.J. Oberhumer 6c7ec6eb1b Update brandelf.py. 2007-12-12 05:25:15 +01:00
Markus F.X.J. Oberhumer 705fc5d116 Rebuild stubs. 2007-11-27 01:12:45 +01:00
Markus F.X.J. Oberhumer d20b575b9b Merge. 2007-11-27 01:12:09 +01:00
John Reiser c949beab9c mipsel.r3000-linux.elf-entry.S syscall clobbers t8 2007-11-26 14:56:23 -08:00
Markus F.X.J. Oberhumer 3fb857c435 Cleanup brandelf.py. 2007-11-26 19:57:00 +01:00
Markus F.X.J. Oberhumer 0a4f999ade Fix missing rebuild from previous commit. 2007-11-25 08:59:52 +01:00
John Reiser f0b7147881 mips*.r3000-linux.elf clear stack to workaround suspected bug in glibc-2.3.2 2007-11-24 15:24:10 -08:00
John Reiser b36a42cd0a PackVmlinuzI386 detects relocatable kernel (cannot handle yet) 2007-11-20 12:01:50 -08:00
Markus F.X.J. Oberhumer 000309b47f stub: remove filename from dumps in order reduce diff noise when renaming files. 2007-11-20 06:34:48 +01:00
Markus F.X.J. Oberhumer 5cb12988f0 Merge. 2007-11-20 06:31:16 +01:00
John Reiser 50c4b749ec PackVmlinuxBase<T>::pack always defineFilterSymbols(), esp. for PackVmlinuxAMD64 2007-11-19 18:39:25 -08:00
Markus F.X.J. Oberhumer 5db2734e6f Small Makefile updates. 2007-11-19 09:48:27 +01:00
Markus F.X.J. Oberhumer e9e5507483 stub: rename "mipseb" to "mips". 2007-11-14 04:54:33 +01:00
Markus F.X.J. Oberhumer d63dc7adfb stub: we can reuse our existing mipsel-* tools for mips (big endian). 2007-11-14 04:40:40 +01:00
John Reiser 27db44a8db generated headers for mipseb.r3000-linux.elf 2007-11-13 17:54:05 -08:00
John Reiser 1a035e2866 PackLinuxElf32::canPack must use explicit get_native32 2007-11-13 11:11:31 -08:00
John Reiser 887aa20116 ElfLinkerMipsBE is big endian 2007-11-13 11:09:15 -08:00
John Reiser 5e03d86695 new PackLinuxElf32mipseb 2007-11-13 11:08:48 -08:00
John Reiser 95075aa28e MIPSEB implementation [still broken because no big-endian tools] 2007-11-12 09:23:45 -08:00
John Reiser 0260f0790a mipseb.r3000-linux.elf [broken because no big-endian tool chain] 2007-11-12 09:12:51 -08:00
John Reiser 34d65ba292 ET_DYN -fPIE position-independent executables 2007-11-12 09:11:16 -08:00
John Reiser 27a77a15ed prepare to deal with DT_GNU_HASH instead of DT_HASH 2007-11-12 09:05:36 -08:00
John Reiser 76025bfae1 _NR_link 2007-11-12 08:54:34 -08:00
John Reiser 4957faf482 DT_GNU_HASH, DT_JMPREL, etc. 2007-11-12 08:54:02 -08:00
Markus F.X.J. Oberhumer 0d8e16d5c8 Rename nocopy to noncopyable. 2007-11-07 23:13:20 +01:00
Markus F.X.J. Oberhumer 07baed1581 Improved IO error checking. 2007-11-06 03:21:32 +01:00
Markus F.X.J. Oberhumer eab5da075a And yet some more dos/exe size reduction. 2007-09-14 16:59:19 +02:00
Markus F.X.J. Oberhumer 0d1bbb19ce Small Makefile cleanup. 2007-09-14 16:31:17 +02:00
Markus F.X.J. Oberhumer 58d6cbc6ac More dos/exe lzma size reduction. 2007-09-14 16:03:51 +02:00
Markus F.X.J. Oberhumer 4d3b627839 Save some more bytes in dos/exe lzma stub. 2007-09-14 15:47:18 +02:00
Markus F.X.J. Oberhumer 49455c99ad Save 1 byte in dos/exe stub. 2007-09-14 13:48:00 +02:00
Markus F.X.J. Oberhumer 31bb6bedbd stub i086: use decimal constants. 2007-09-13 22:52:43 +02:00
Markus F.X.J. Oberhumer 8d54678ea1 Switch back to using binutils-multiarch-2.17. 2007-09-13 20:14:29 +02:00
Markus F.X.J. Oberhumer 590767c299 Make stub files compatible with binutils-multiarch-2.18. 2007-09-13 19:59:41 +02:00
John Reiser ec1bd342b8 fix error checking in mmap for i386-linux.elf [triggered by -fPIE] 2007-09-08 06:55:47 -07:00
John Reiser b031c9e7f6 fix unmapping on arm-linux.elf 2007-08-30 11:55:58 -07:00
John Reiser ea0dfe83b7 arm-linux.elf-entry.S clobbered ADRU with sz_unc of fold 2007-08-30 11:53:16 -07:00
Markus F.X.J. Oberhumer bdd90f2c57 Allow setting the compression method in the environment variable (popular
request from our users).
2007-08-04 12:13:09 +02:00
Markus F.X.J. Oberhumer 288dac5d70 Bump version for next release. 2007-07-31 22:50:23 +02:00
Markus F.X.J. Oberhumer 9d22e1c35e Added tag for RELEASE_301. 2007-07-31 22:42:40 +02:00
Markus F.X.J. Oberhumer ace2359e7b Bump tentative release date. 2007-07-31 15:06:53 +02:00
Markus F.X.J. Oberhumer 617e6510a5 docs: mention a workaround for --exact option. 2007-07-31 15:00:38 +02:00
Markus F.X.J. Oberhumer 26024770b8 For the moment we always throwCantPack() for arm/pe and win32/pe. 2007-07-30 17:47:42 +02:00
Markus F.X.J. Oberhumer d556f58e34 Fix screen problems by not relying on pass number in startCallback(). 2007-07-30 17:27:43 +02:00
Markus F.X.J. Oberhumer b6f302dfc0 Makefile: use /bin/echo for better portability. 2007-07-30 12:56:35 +02:00
Markus F.X.J. Oberhumer 8e9b5f14af Small Makefile updates. 2007-07-11 07:03:05 +02:00
Markus F.X.J. Oberhumer 3635c00143 Added support for LZMA SDK 4.49. Compiles, but pretty much untested. 2007-07-08 13:58:08 +02:00
Markus F.X.J. Oberhumer abc71baaa6 Avoid some warnings. 2007-07-08 11:42:45 +02:00
John Reiser 959aaebede bvmlinuz piggy.o need not be last in bzImage 2007-07-02 14:27:31 -07:00
John Reiser d17f8c5049 linux-2.6.21.5 CONFIG_PARAVIRT 2007-07-02 12:48:14 -07:00
Markus F.X.J. Oberhumer 42a7201a70 Updated README.1ST. 2007-06-19 15:26:02 +02:00
Markus F.X.J. Oberhumer 1f1744a49a Added new options --no-mode, --no-owner and --no-time. 2007-06-19 15:14:12 +02:00
Markus F.X.J. Oberhumer fd7dbe5bd9 Update docs of --exact option. 2007-06-19 14:49:53 +02:00
Markus F.X.J. Oberhumer 984549400d Clean up various names in getFullName(). 2007-06-12 14:25:00 +02:00
Markus F.X.J. Oberhumer cf0c49277e Add processing instructions to gpp_inc.py. 2007-06-12 13:40:35 +02:00
Markus F.X.J. Oberhumer 16c3f9fa9c Small Makefile updates. 2007-06-12 12:46:56 +02:00
John Reiser 2f2539cf34 workaround weak python script gpp_inc.py 2007-06-10 06:54:10 -07:00
John Reiser e66823d017 mipsel.r3000-linux: flush cache for NRV, fix stub copying when big 2007-06-09 17:13:50 -07:00
John Reiser 881c32a3df fix NRV_HEAD and NRV_TAIL in stub for mipsel.r3000-linux 2007-06-09 13:52:56 -07:00
John Reiser ea0a361c35 fix argv[0] on PowerPC with --lzma 2007-06-04 10:13:14 -07:00
László Molnár dc60f8bb7b merge 2007-05-18 16:11:11 +02:00
László Molnár 9e92c9ea12 pe: added a check for too small object alignment 2007-05-17 18:02:50 +02:00
John Reiser a503a54240 mipsel remember /proc/self/exe in environment 2007-05-16 15:37:22 -07:00
John Reiser 265957712a merge 2007-05-16 13:56:37 -07:00
John Reiser c26962bb71 fix build glitch 2007-05-16 13:53:17 -07:00
John Reiser a428eddf93 catch up automatically-generated files 2007-05-16 13:51:44 -07:00
John Reiser dc4f7eb2f9 mipsel close() 2007-05-16 13:51:00 -07:00
John Reiser d54ac1ba91 use register $25 for trampoline 2007-05-16 13:50:16 -07:00
John Reiser a3d46b18ac cacheflush 2007-05-16 13:49:54 -07:00
John Reiser e81dd05666 bug in make_hatch_*(); simplify xfind_pages() when MAP_FIXED; update AT_BASE 2007-05-16 13:48:44 -07:00
Markus F.X.J. Oberhumer 29394935e3 Use -Wstrict-prototypes CFLAGS in stub/Makefile. 2007-05-16 04:34:30 +02:00
Markus F.X.J. Oberhumer df8acc4ed7 Added .NOTPARALLEL to stub/Makefile. 2007-05-14 11:30:40 +02:00
John Reiser 81928d4ab1 mipsel stub escape hatch for munmap 2007-05-10 13:13:11 -07:00
John Reiser 3ebf93e03d mipsel syscall read+write of same register 2007-05-09 22:17:09 -07:00
John Reiser 59e4032f1f mipsel stub syscall registers 2007-05-08 13:33:00 -07:00
John Reiser 8f15777427 merge 2007-05-08 10:43:50 -07:00
John Reiser 748c4bf780 mipsel stub system calls 2007-05-08 10:41:13 -07:00
László Molnár befcf6d2b3 merge 2007-05-08 18:25:00 +02:00
László Molnár 48236ecd3c fixed an incorrect error message caused by a bug in relocation handling 2007-05-08 18:23:41 +02:00
Markus F.X.J. Oberhumer f340f84de7 Avoid warnings. 2007-05-08 16:12:42 +02:00
Markus F.X.J. Oberhumer 40e19293f9 Added throwOutOfMemoryException(). 2007-05-08 15:28:35 +02:00
John Reiser f252f824a4 mipsel conditional stub/src/i386-linux.elf-main.c 2007-05-08 05:48:15 -07:00
John Reiser 1d7e5a8130 typedef struct Extent 2007-05-08 05:18:41 -07:00
John Reiser cb2ff92c2f mipsel hack stub 2007-05-07 21:03:58 -07:00
John Reiser ef373ab54f mipsel hacking 2007-05-07 19:20:25 -07:00
John Reiser 9141a78c29 mipsel stub for mmap on Linux (not NetBSD); and subroutine arg[4..6]
in t0..t2 instead of on stack, to match LMZA_DEC20
2007-05-07 07:02:16 -07:00
John Reiser 10a6370738 hacking UPX_F_LINUX_ELF32_MIPSEL 2007-05-06 14:21:25 -07:00
John Reiser 573009eeb6 new format UPX_F_LINUX_ELF32_MIPSEL [work in progress] 2007-05-06 06:17:49 -07:00
John Reiser c3363712d9 PackVmlinuxBase<T>::pack() EM_PPC filter only contiguous instruction sections 2007-05-01 19:12:55 -07:00
John Reiser faa33d89a2 Documentation: UPX_F_VMLINUX_PPC32 changes to arch/powerpc/boot/main.c 2007-04-30 13:48:50 -07:00
John Reiser f347458c53 new format UPX_F_VMLINUX_PPC32 Linux kernel for PowerPC (32-bit) 2007-04-30 13:34:06 -07:00
Markus F.X.J. Oberhumer 530e6d9196 Bump version for next release. 2007-04-30 19:34:26 +02:00
Markus F.X.J. Oberhumer b398e18e12 Added tag for RELEASE_300. 2007-04-30 19:32:35 +02:00
Markus F.X.J. Oberhumer 747e8370e0 Remove debug leftover. 2007-04-26 16:20:01 +02:00
Markus F.X.J. Oberhumer 2c67875781 Pass and verify original data in all xxx_test_overlap() functions. 2007-04-26 16:15:49 +02:00
Markus F.X.J. Oberhumer c96e8a8c19 Better underflow and overflow handling in Packer::findOverlapOverhead(). 2007-04-26 13:59:01 +02:00
Markus F.X.J. Oberhumer 5f203fc082 Avoid warnings. 2007-04-26 13:13:26 +02:00
John Reiser b943c9b471 fix upx_zlib_test_overlap 2007-04-25 20:24:30 -07:00
John Reiser 1a90a1daa8 Implement upx_zlib_test_overlap() following upx_lzma_test_overlap() 2007-04-25 20:19:40 -07:00
John Reiser 72dfc743fd upx_lzma_test_overlap cleanup 2007-04-25 20:11:04 -07:00
John Reiser 465307655b Implement real upx_lzma_test_overlap().
Also make Packer::findOverlapOverhead() more pessimistic in worst case.
2007-04-25 16:11:33 -07:00
John Reiser 6ce71e6694 upx_lzma_test_overlap revert to 256 [FIXME] 2007-04-25 10:54:00 -07:00
John Reiser 7f01b3b92a upx_lzma_test_overlap() heuristic overlap_overhead up to 0xA00 2007-04-25 09:19:29 -07:00
John Reiser 76950d56b9 PackUnix::canPack allow incompressible extents in getPackHeader() 2007-04-25 09:18:31 -07:00
Markus F.X.J. Oberhumer c11e0d02b3 Added parm "allow_incompressible" to Packer::{get,read}PackHeader(). 2007-04-25 17:33:39 +02:00
Markus F.X.J. Oberhumer 4c798c1718 Use official name "armeb" instead of "armbe". 2007-04-25 16:50:51 +02:00
Markus F.X.J. Oberhumer 450d7e9ad4 Merge. 2007-04-25 16:42:41 +02:00
Markus F.X.J. Oberhumer b8ab79c83e Use offical name "arm" instead of "armel". 2007-04-25 16:42:08 +02:00
John Reiser 6934bdd533 allow unpack of incompressible extents, such as
http://www.equi4.com/pub/tk/8.4.13/tclkit-linux-x86.gz
2007-04-25 07:34:24 -07:00
John Reiser 84dedb73a5 propagate changes arm*-linux.elf-fold.h 2007-04-24 16:08:34 -07:00
John Reiser 8964aa5221 fix endian issue with .b_method (arm-linux.elf-entry.S) 2007-04-24 12:05:53 -07:00
Markus F.X.J. Oberhumer 3481ae236c Added missing armeb generated files. 2007-04-23 18:11:24 +02:00
John Reiser 46adc5f8a4 armeb-linux.kernel.vmlinux.S 2007-04-23 09:00:28 -07:00
John Reiser 5296df5899 add armeb-linux.kernel.vmlinux-head.S 2007-04-23 08:53:53 -07:00
John Reiser 13dad4be16 merge 2007-04-23 07:22:36 -07:00
John Reiser b5d0c343b4 sync src/Makefile with Markus bfb3d24c1fe7 2007-04-23 07:15:42 -07:00
Markus F.X.J. Oberhumer b00b945264 src/Makefile: avoid rebuilding .depend file on clean targets 2007-04-23 08:23:01 +02:00
John Reiser 3bda09e105 more cleanup armel etc 2007-04-22 20:04:13 -07:00
John Reiser 32d32c4e4a cleanup ARMEL etc. 2007-04-22 19:52:23 -07:00
John Reiser 497441b54e merge 2007-04-22 16:19:13 -07:00
John Reiser 9c564fd4c7 Add file formst UPX_F_LINUX_ELF32_ARMEB and normalize spelling
of ARMEL, ARMEB, armel, armeb.
2007-04-22 16:09:18 -07:00
John Reiser 0c2263d0e9 fix O_INP etc because cto8 is not pushed.
This change should have paralleled 1382:367eb149f29c
(Sun Aug 20 11:19:37 2006 -0700)
2007-04-22 15:50:24 -07:00
John Reiser 3d4d30766d merge 2007-04-22 15:24:17 -07:00
John Reiser 99d84d44fc propagate change to O_INP 2007-04-22 14:50:58 -07:00
John Reiser 41ba7077ad propagate change to O_INP 2007-04-22 14:50:58 -07:00
John Reiser 8a929a91c3 Fix O_INP etc because calling sequence changed to omit cto8.
This parallel change was forgotten at:
   changeset:   1382:367eb149f29c
   date:        Sun Aug 20 11:19:37 2006 -0700
   summary:     i386-linux.elf decompress does not need cto8
2007-04-22 14:47:08 -07:00
Markus F.X.J. Oberhumer 0604f06841 Backed out changeset 1b7b0715e0ab0d3b2e8afc96ac95d46d44bf3618 2007-04-23 07:36:46 +02:00
John Reiser 229924adf9 Fix O_INP etc because calling sequence changed to omit cto8.
This parallel change was forgotten at:
   changeset:   1382:367eb149f29c
   date:        Sun Aug 20 11:19:37 2006 -0700
   summary:     i386-linux.elf decompress does not need cto8
2007-04-22 14:47:08 -07:00
Markus F.X.J. Oberhumer df988b7c69 Bump tentative release date. 2007-04-22 16:55:41 +02:00
John Reiser e8106e2e34 propagate change to 'loadcon8' macro 2007-04-18 09:55:15 -07:00
John Reiser c21d3e24f8 fix 'loadcon8'; was bad for big-endian vmlinux ARM 2007-04-18 09:52:52 -07:00
Markus F.X.J. Oberhumer 2d87aa0753 Better ctok32 fix. 2007-04-02 18:57:42 +02:00
László Molnár b2ad4dc9a0 another fix for ctok32 2007-04-02 14:12:16 +02:00
László Molnár 370f2ea98f tmt/adam: fixed a ctok32 related bug 2007-04-01 17:31:48 +02:00
László Molnár a05ca565ff fixed a bug in ctok32 2007-04-01 17:07:43 +02:00
László Molnár 52255637f2 give an error for x86/wince files 2007-03-22 13:45:03 +01:00
Markus F.X.J. Oberhumer 0fcaa3a2f5 Work around broken scanf() implementations. 2007-03-22 07:30:16 +01:00
László Molnár 0e2fa6eb9d no need to warn for x86 wince files 2007-03-20 09:30:30 +01:00
Markus F.X.J. Oberhumer 1aac462c83 Remove trailing whitespace. 2007-03-15 07:36:58 +01:00
Markus F.X.J. Oberhumer 2a0edfd8f7 Small update from Jens. 2007-03-15 01:41:07 +01:00
László Molnár 1f59a9f846 more PS1 updates from Jens 2007-03-12 12:11:17 +01:00
László Molnár 80c20a90ea PS1 updates from Jens 2007-03-12 11:56:16 +01:00
Markus F.X.J. Oberhumer 56a35649fe Update Makefiles. 2007-03-09 07:59:50 +01:00
Markus F.X.J. Oberhumer f07cea0b79 Update help string. 2007-03-09 07:59:36 +01:00
Markus F.X.J. Oberhumer 4c1b08a281 Bump version for next release. 2007-03-08 08:26:28 +01:00
Markus F.X.J. Oberhumer 117f9eddcd src/Makefile: use an explicit .depend file. 2007-03-08 08:19:27 +01:00
Markus F.X.J. Oberhumer 7bbbfce482 Added tag for RELEASE_293. 2007-03-08 06:16:24 +01:00
410 changed files with 67061 additions and 49395 deletions
+2 -1
View File
@@ -8,6 +8,7 @@ syntax: regexp
syntax: glob syntax: glob
.depend
Makevars.local Makevars.local
*.a *.a
@@ -44,7 +45,7 @@ stub/**.*-stamp
stub/tmp*/* stub/tmp*/*
stub/**/tmp*/* stub/**/tmp*/*
stub/tools/armpe/armpe_tester stub/tools/armpe/armpe_tester{,.exe,.out}
stub/tools/sstrip/amd64-linux-sstrip stub/tools/sstrip/amd64-linux-sstrip
stub/tools/sstrip/i386-linux-sstrip stub/tools/sstrip/i386-linux-sstrip
+5
View File
@@ -1,9 +1,12 @@
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111 140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301
223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190 223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190
2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194 2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194
2ee65b77f9117651e2e5517b2edede23698d73ca RELEASE_196 2ee65b77f9117651e2e5517b2edede23698d73ca RELEASE_196
396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291 396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291
46f3a6cca02603000fadc16637b02e30caddd909 RELEASE_302
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200 70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
95c558f81a0b8d5bb2bede4c8208bb84ae7d1e58 RELEASE_303
a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292 a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292
a916a2fe22de45167d25abcb40008315f415221c RELEASE_201 a916a2fe22de45167d25abcb40008315f415221c RELEASE_201
a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193 a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
@@ -13,3 +16,5 @@ c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290 d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110 eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191 ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
ef9c7f2c9658d73a9b5ab2ed291483d2bbcd8bc7 RELEASE_300
efa52753e366300c0e0ebe20631adcb24ed3c15b RELEASE_293
+2 -2
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2009 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -28,7 +28,7 @@ dos/exe
watcom/le watcom/le
--------- ---------
* 16-bit selector alias fixups * 16-bit selector alias fixups
* 16-bit offset relocation for objects larger than 4 kB * 16-bit offset relocation for objects larger than 4 KiB
* 16:16 fixups * 16:16 fixups
If you need any of the above (they're very rare), send us an URL of a If you need any of the above (they're very rare), send us an URL of a
+10 -7
View File
@@ -1,17 +1,23 @@
# #
# UPX toplevel Makefile - needs GNU make 3.80 or better # UPX toplevel Makefile - needs GNU make 3.81 or better
#
# Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR MAKEFLAGS += -rR
.SUFFIXES: .SUFFIXES:
export SHELL = /bin/sh export SHELL = /bin/sh
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),)
$(error GNU make 3.81 or better is required)
endif
srcdir = . srcdir = .
top_srcdir = . top_srcdir = .
-include $(top_srcdir)/Makevars.global ./Makevars.local include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local)
# info: src/stub needs GNU make 3.81 and special build tools # info: src/stub needs special build tools
BUILD_STUB = 0 BUILD_STUB = 0
ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),) ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
BUILD_STUB = 1 BUILD_STUB = 1
@@ -19,9 +25,6 @@ endif
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),) ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
BUILD_STUB = 1 BUILD_STUB = 1
endif endif
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.79 3.79.1 3.80),)
BUILD_STUB = 0
endif
default: default:
@@ -35,7 +38,7 @@ endif
$(MAKE) -C doc $@ $(MAKE) -C doc $@
ifneq ($(wildcard .hg/data/.),) ifneq ($(wildcard .hg/.),)
# automatically generate ChangeLog from local Mercurial repo # automatically generate ChangeLog from local Mercurial repo
ChangeLog: ChangeLog:
hg log --style=changelog > $@ hg log --style=changelog > $@
+33
View File
@@ -2,6 +2,39 @@
User visible changes for UPX User visible changes for UPX
================================================================== ==================================================================
Changes in 3.04 (27 Sep 2009):
* new format Mach/AMD64 supports 64-bit programs on Apple Macintosh.
* new formats Dylib/i386 and Dylib/ppc32 support shared libraries
[such as browser plugins] on Darwin (Apple Macintosh). An existing
-init function (LC_ROUTINES command) is required.
* new format vmlinuz/armel for Debian NSLU2 (etc.) linux kernel
* bvmlinuz boot protocol 2.08 for 386 Linux kernel
* Extended ABI version 4 for armel-eabi ARM Linux ELF
* bug fixes
Changes in 3.03 (27 Apr 2008):
* implement cache flushing for PowerPC (esp. model 440)
* fix cache flushing on MIPS (>3 MiB compressed, or with holes)
* fix MIPS big-endian
* bug fixes
Changes in 3.02 (16 Dec 2007):
* fix unmapping on arm-linux.elf
* fix error checking in mmap for i386-linux.elf [triggered by -fPIE]
* bug fixes
Changes in 3.01 (31 Jul 2007):
* new options --no-mode, --no-owner and --no-time to disable preservation
of mode (file permissions), file ownership and timestamps.
* dos/exe: fixed an incorrect error message caused by a bug in
relocation handling
* new format linux/mipsel supports ELF on [32-bit] R3000
* fix argv[0] on PowerPC with --lzma
* bug fixes
Changes in 3.00 (27 Apr 2007):
* watcom/le & tmt/adam: fixed a problem when using certain filters
Changes in 2.93 beta (08 Mar 2007): Changes in 2.93 beta (08 Mar 2007):
* new formats Mach/i386 and Mach/fat support Mac OS X i686 and * new formats Mach/i386 and Mach/fat support Mac OS X i686 and
Universal binaries [i686 and PowerPC only] Universal binaries [i686 and PowerPC only]
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2009 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
+5 -5
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2009 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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 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.
@@ -129,7 +129,7 @@ Markus & Laszlo
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
+1 -9
View File
@@ -8,18 +8,10 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2009 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
WARNING - UNSTABLE BETA VERSION
===============================
The current stable release is 2.02, and the next stable release
will be called version 3.00.
MAJOR NEWS IN UPX 3 MAJOR NEWS IN UPX 3
=================== ===================
+1 -4
View File
@@ -69,7 +69,7 @@ Tools needed to build/modify the UPX sources
- A C++ compiler supporting inner classes, templates, exceptions - A C++ compiler supporting inner classes, templates, exceptions
and RTTI. and RTTI.
- GNU make 3.80 or better (GNU make 3.81 recommened). - GNU make 3.81 or better
To compile the packer sources To compile the packer sources
@@ -94,9 +94,6 @@ To compile the packer sources
If you want to modify the stub sources you'll also need If you want to modify the stub sources you'll also need
------------------------------------------------------- -------------------------------------------------------
- GNU make 3.81 or better
http://savannah.gnu.org/projects/make/
- Perl & Python - Perl & Python
- A number of cross-assemblers and cross-compilers - precompiled - A number of cross-assemblers and cross-compilers - precompiled
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2009 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
+3 -3
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-2007 John F. Reiser jreiser@BitWagon.com Copyright (C) 2000-2009 John F. Reiser jreiser@BitWagon.com
References: References:
<elf.h> definitions for the ELF file format <elf.h> definitions for the ELF file format
@@ -46,8 +46,8 @@ may not be used to take the address of a function.
The address 0x00400000 was chosen to be out of the way of the usual The address 0x00400000 was chosen to be out of the way of the usual
load address 0x08048000, and to minimize fragmentation in kernel load address 0x08048000, and to minimize fragmentation in kernel
page tables; one page of page tables covers 4MB. The address page tables; one page of page tables covers 4 MiB. The address
0x00401000 was chosen as 1 page up from a 64KB boundary, to 0x00401000 was chosen as 1 page up from a 64 KiB boundary, to
make the startup code and its constants smaller. make the startup code and its constants smaller.
Decompression of the executable begins by decompressing the Elf32_Ehdr Decompression of the executable begins by decompressing the Elf32_Ehdr
+2 -2
View File
@@ -108,14 +108,14 @@ then skip another one - the unfiltering process needs some information
to be able to reverse the filtering. to be able to reverse the filtering.
UPX uses the following idea, which works nicely. First we assume that UPX uses the following idea, which works nicely. First we assume that
the size of the area that should be filtered is less than 16MB. Then the size of the area that should be filtered is less than 16 MiB. Then
UPX scans over this area and keeps a record of the bytes that are UPX scans over this area and keeps a record of the bytes that are
following the 0xE8 bytes. If we are lucky, there will be bytes that following the 0xE8 bytes. If we are lucky, there will be bytes that
were not found following 0xE8. These bytes are our candidates to be were not found following 0xE8. These bytes are our candidates to be
used as markers. used as markers.
Do you still remember that we assumed that the size of scanned area is Do you still remember that we assumed that the size of scanned area is
less than 16MB? Well, this means that when we process a real call, the less than 16 MiB? Well, this means that when we process a real call, the
resulting offset will be less than 0x00FFFFFF too. So the MSB is always resulting offset will be less than 0x00FFFFFF too. So the MSB is always
0x00. Which is a nice place to store our marker. Of course we should 0x00. Which is a nice place to store our marker. Of course we should
reverse the byte order in the resulting offset - so this marker will reverse the byte order in the resulting offset - so this marker will
+22 -15
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-2007 Markus Oberhumer, Laszlo Molnar & John Reiser Copyright (c) 1996-2009 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -51,8 +51,8 @@ B<UPX> is a versatile executable packer with the following features:
- excellent compression ratio: compresses better than zip/gzip, - excellent compression ratio: compresses better than zip/gzip,
use UPX to decrease the size of your distribution ! use UPX to decrease the size of your distribution !
- very fast decompression: about 10 MB/sec on an ancient Pentium 133, - very fast decompression: about 10 MiB/sec on an ancient Pentium 133,
about 200 MB/sec on an Athlon XP 2000+. about 200 MiB/sec on an Athlon XP 2000+.
- no memory overhead for your compressed executables for most of the - no memory overhead for your compressed executables for most of the
supported formats supported formats
@@ -139,7 +139,11 @@ B<--help>: prints the help
B<--version>: print the version of B<UPX> B<--version>: print the version of B<UPX>
B<--exact>: when compressing, require to be able to get a byte-identical file B<--exact>: when compressing, require to be able to get a byte-identical file
after decompression with option B<-d> after decompression with option B<-d>. [NOTE: this is work in progress and is
not supported for all formats yet. If you do care, as a workaround you can
compress and then decompress your program a first time - any further
compress-decompress steps should then yield byte-identical results
as compared to the first decompressed version.]
[ ...to be written... - type `B<upx --help>' for now ] [ ...to be written... - type `B<upx --help>' for now ]
@@ -149,7 +153,7 @@ after decompression with option B<-d>
B<UPX> offers ten different compression levels from B<-1> to B<-9>, B<UPX> offers ten different compression levels from B<-1> to B<-9>,
and B<--best>. The default compression level is B<-8> for files and B<--best>. The default compression level is B<-8> for files
smaller than 512 kB, and B<-7> otherwise. smaller than 512 KiB, and B<-7> otherwise.
=over 4 =over 4
@@ -345,7 +349,7 @@ Extra options available for this executable format:
First of all, it is recommended to use B<UPX> *instead* of B<strip>. strip has First of all, it is recommended to use B<UPX> *instead* of B<strip>. strip has
the very bad habit of replacing your stub with its own (outdated) version. the very bad habit of replacing your stub with its own (outdated) version.
Additionally B<UPX> corrects a bug/feature in strip v2.8.x: it Additionally B<UPX> corrects a bug/feature in strip v2.8.x: it
will fix the 4 KByte alignment of the stub. will fix the 4 KiB alignment of the stub.
B<UPX> includes the full functionality of stubify. This means it will B<UPX> includes the full functionality of stubify. This means it will
automatically stubify your COFF files. Use the option B<--coff> to automatically stubify your COFF files. Use the option B<--coff> to
@@ -656,8 +660,8 @@ Specific drawbacks:
- Because of temporary decompression to disk the decompression speed - Because of temporary decompression to disk the decompression speed
is not as fast as with the other executable formats. Still, I can see is not as fast as with the other executable formats. Still, I can see
no noticeable delay when starting programs like my ~3 MB emacs (which no noticeable delay when starting programs like my ~3 MiB emacs (which
is less than 1 MB when compressed :-). is less than 1 MiB when compressed :-).
Extra options available for this executable format: Extra options available for this executable format:
@@ -677,13 +681,16 @@ nostalgic feelings of one of the authors.
Packed programs will be byte-identical to the original after uncompression, Packed programs will be byte-identical to the original after uncompression,
until further notice. until further notice.
Maximum uncompressed size: ~1.89 / ~7.60 Mbytes. Maximum uncompressed size: ~1.89 / ~7.60 MiB.
Notes: Notes:
- UPX creates as default a suitable executable for CD-Mastering - UPX creates as default a suitable executable for CD-Mastering
and console transfer. For a CD-Master main executable you could also try and console transfer. For a CD-Master main executable you could also try
the special option "--boot-only" as described below. the special option "--boot-only" as described below.
It has been reported that upx packed executables are fully compatible with
the Sony PlayStation 2 (PS2, PStwo) and Sony PlayStation Portable (PSP) in
Sony PlayStation (PSone) emulation mode.
- Normally the packed files use the same memory areas like the uncompressed - Normally the packed files use the same memory areas like the uncompressed
versions, so they will not override other memory areas while unpacking. versions, so they will not override other memory areas while unpacking.
@@ -701,7 +708,7 @@ Extra options available for this executable format:
--8-bit Uses 8 bit size compression [default: 32 bit] --8-bit Uses 8 bit size compression [default: 32 bit]
--8mb-ram PSone has 8 MB ram available [default: 2 MB] --8mib-ram PSone has 8 MiB ram available [default: 2 MiB]
--boot-only This format is for main exes and CD-Mastering only ! --boot-only This format is for main exes and CD-Mastering only !
It may slightly improve the compression ratio, It may slightly improve the compression ratio,
@@ -831,7 +838,7 @@ must end with ".scr" (as screensavers are handled slightly different
than normal exe files). than normal exe files).
UPX compressed PE files have some minor memory overhead (usually in the UPX compressed PE files have some minor memory overhead (usually in the
10 - 30 kbytes range) which can be seen by specifying the "-i" command 10 - 30 KiB range) which can be seen by specifying the "-i" command
line switch during compression. line switch during compression.
Extra options available for this executable format: Extra options available for this executable format:
@@ -926,13 +933,13 @@ Please report all bugs immediately to the authors.
=head1 COPYRIGHT =head1 COPYRIGHT
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
Copyright (C) 2002-2007 Jens Medoch Copyright (C) 2002-2009 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.
+38 -13
View File
@@ -1,5 +1,7 @@
# #
# UPX Makefile - needs GNU make 3.80 or better # UPX Makefile - needs GNU make 3.81 or better
#
# Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
# #
MAKEFLAGS += -rR MAKEFLAGS += -rR
@@ -7,6 +9,10 @@ MAKEFLAGS += -rR
export SHELL = /bin/sh export SHELL = /bin/sh
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1) override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),)
$(error GNU make 3.81 or better is required)
endif
ifndef srcdir ifndef srcdir
srcdir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) srcdir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,') srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,')
@@ -14,7 +20,7 @@ endif
ifndef top_srcdir ifndef top_srcdir
top_srcdir := $(srcdir)/.. top_srcdir := $(srcdir)/..
endif endif
-include $(top_srcdir)/Makevars.global ./Makevars.local include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local)
ifneq ($(srcdir),.) ifneq ($(srcdir),.)
##$(info Info: using VPATH . $(srcdir)) ##$(info Info: using VPATH . $(srcdir))
VPATH := . $(srcdir) VPATH := . $(srcdir)
@@ -27,7 +33,6 @@ ifneq ($(findstring $(firstword $(CXX)),g++),)
USE_GNUC ?= 1 USE_GNUC ?= 1
endif endif
ifeq ($(USE_GNUC),1) ifeq ($(USE_GNUC),1)
CXXFLAGS += -MMD
ifeq ($(DEBUG),1) ifeq ($(DEBUG),1)
CXXFLAGS += -O0 -g CXXFLAGS += -O0 -g
else else
@@ -52,37 +57,57 @@ INCLUDES += -I$(UPX_UCLDIR)/include
LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext)))) LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext))))
endif endif
LIBS += -lucl -lz LIBS += -lucl -lz
# you should set envvar UPX_LZMADIR to point to your unpacked lzma443.tar.bz2 # you should set envvar UPX_LZMADIR to point to your unpacked LZMA SDK
ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),) include $(top_srcdir)/src/stub/src/c/Makevars.lzma
DEFS += -DWITH_LZMA=1 ifneq ($(UPX_LZMA_VERSION),)
DEFS += -DWITH_LZMA=$(UPX_LZMA_VERSION)
INCLUDES += -I$(UPX_LZMADIR) INCLUDES += -I$(UPX_LZMADIR)
endif endif
all: upx$(exeext) all: upx$(exeext) | .depend
.DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS) .DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS) .depend
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES) upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
$($(notdir $@).PRE_LINK_STEP) $($(notdir $@).PRE_LINK_STEP)
$(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS)) $(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS))
$($(notdir $@).POST_LINK_STEP) $($(notdir $@).POST_LINK_STEP)
%.o : %.cpp %.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)
@rm -f $@
ifeq ($(USE_GNUC),1)
@echo "Updating $@"
@$(strip $(CXX) $(call e,CPPFLAGS) -MM) $(filter %.cpp,$^) > $@
else
touch $@
endif
ifeq ($(USE_GNUC),1) ifeq ($(USE_GNUC),1)
##compress_lzma$(objext) : CXXFLAGS += -O3 -fomit-frame-pointer ##compress_lzma$(objext) : CXXFLAGS += -O3 -fomit-frame-pointer
compress_lzma$(objext) : CXXFLAGS += -Wno-cast-qual compress_lzma$(objext) : CXXFLAGS += -Wno-cast-qual
compress_lzma$(objext) : CXXFLAGS += -Wno-non-virtual-dtor
compress_lzma$(objext) : CXXFLAGS += -Wno-shadow compress_lzma$(objext) : CXXFLAGS += -Wno-shadow
ifeq ($(UPX_LZMA_VERSION),0x443)
compress_lzma$(objext) : CXXFLAGS += -Wno-non-virtual-dtor
compress_lzma$(objext) : CXXFLAGS += -Wno-unused compress_lzma$(objext) : CXXFLAGS += -Wno-unused
##compress_lzma$(objext) : CXXFLAGS += -Wno-error endif
# needed for gcc-4.3:
compress_lzma$(objext) : CXXFLAGS += -Wno-error
endif endif
mostlyclean clean distclean maintainer-clean: mostlyclean clean distclean maintainer-clean:
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext) rm -f *.d *.map *.o *.obj *.res .depend upx.exe upx.out upx.ttp upx$(exeext)
-include *.d
.PHONY: all mostlyclean clean distclean maintainer-clean .PHONY: all mostlyclean clean distclean maintainer-clean
ifeq ($(MAKECMDGOALS),mostlyclean)
else ifeq ($(MAKECMDGOALS),clean)
else ifeq ($(MAKECMDGOALS),distclean)
else ifeq ($(MAKECMDGOALS),maintainer-clean)
else
-include .depend
endif
+20 -38
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -282,12 +282,12 @@ inline unsigned acc_swap32p(const acc_uint32e_t *p)
inline void acc_swab16s(acc_uint16e_t *p) inline void acc_swab16s(acc_uint16e_t *p)
{ {
*p = acc_swab16(*p); *p = (acc_uint16e_t) acc_swab16(*p);
} }
inline void acc_swab32s(acc_uint32e_t *p) inline void acc_swab32s(acc_uint32e_t *p)
{ {
*p = acc_swab32(*p); *p = (acc_uint32e_t) acc_swab32(*p);
} }
@@ -313,8 +313,7 @@ inline void acc_ua_swab32s(void *p)
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ] // to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
**************************************************************************/ **************************************************************************/
struct BE16 __packed_struct(BE16)
{
unsigned char d[2]; unsigned char d[2];
//inline BE16() { } //inline BE16() { }
@@ -332,12 +331,10 @@ struct BE16
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; } BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
operator unsigned () const { return get_be16(d); } operator unsigned () const { return get_be16(d); }
} __packed_struct_end()
__attribute_packed;
struct BE32 __packed_struct(BE32)
{
unsigned char d[4]; unsigned char d[4];
//inline BE32() { } //inline BE32() { }
@@ -355,12 +352,10 @@ struct BE32
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; } BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
operator unsigned () const { return get_be32(d); } operator unsigned () const { return get_be32(d); }
} __packed_struct_end()
__attribute_packed;
struct BE64 __packed_struct(BE64)
{
unsigned char d[8]; unsigned char d[8];
//inline BE64() { } //inline BE64() { }
@@ -378,12 +373,10 @@ struct BE64
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 acc_uint64l_t () const { return get_be64(d); }
} __packed_struct_end()
__attribute_packed;
struct LE16 __packed_struct(LE16)
{
unsigned char d[2]; unsigned char d[2];
//inline LE16() { } //inline LE16() { }
@@ -401,12 +394,10 @@ struct LE16
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; } LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
operator unsigned () const { return get_le16(d); } operator unsigned () const { return get_le16(d); }
} __packed_struct_end()
__attribute_packed;
struct LE32 __packed_struct(LE32)
{
unsigned char d[4]; unsigned char d[4];
//inline LE32() { } //inline LE32() { }
@@ -424,12 +415,10 @@ struct LE32
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; } LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
operator unsigned () const { return get_le32(d); } operator unsigned () const { return get_le32(d); }
} __packed_struct_end()
__attribute_packed;
struct LE64 __packed_struct(LE64)
{
unsigned char d[8]; unsigned char d[8];
//inline LE64() { } //inline LE64() { }
@@ -447,8 +436,7 @@ struct LE64
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 acc_uint64l_t () const { return get_le64(d); }
} __packed_struct_end()
__attribute_packed;
/************************************************************************* /*************************************************************************
@@ -591,7 +579,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
/************************************************************************* /*************************************************************************
// Provide namespaces and classes to abtract endianness policies. // Provide namespaces and classes to abstract endianness policies.
// //
// CTP - Compile-Time Polymorphism (templates) // CTP - Compile-Time Polymorphism (templates)
// RTP - Run-Time Polymorphism (virtual functions) // RTP - Run-Time Polymorphism (virtual functions)
@@ -623,16 +611,10 @@ namespace N_BELE_RTP {
} }
namespace N_BELE_CTP { namespace N_BELE_CTP {
inline const N_BELE_RTP::AbstractPolicy* getRTP(const BEPolicy*)
template <class T>
inline const N_BELE_RTP::AbstractPolicy* getRTP();
template <>
inline const N_BELE_RTP::AbstractPolicy* getRTP<BEPolicy>()
{ return &N_BELE_RTP::be_policy; } { return &N_BELE_RTP::be_policy; }
template <> inline const N_BELE_RTP::AbstractPolicy* getRTP(const LEPolicy*)
inline const N_BELE_RTP::AbstractPolicy* getRTP<LEPolicy>()
{ return &N_BELE_RTP::le_policy; } { return &N_BELE_RTP::le_policy; }
} }
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+10 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -182,8 +182,10 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
// //
**************************************************************************/ **************************************************************************/
int upx_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ) const upx_compress_result_t *cresult )
{ {
@@ -201,15 +203,15 @@ int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
} }
#if defined(WITH_LZMA) #if defined(WITH_LZMA)
else if (M_IS_LZMA(method)) else if (M_IS_LZMA(method))
r = upx_lzma_test_overlap(buf, 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 defined(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, 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 defined(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, 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
else { else {
throwInternalError("unknown decompression method"); throwInternalError("unknown decompression method");
+19 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -46,8 +46,10 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_lzma_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
#endif #endif
@@ -65,8 +67,10 @@ int upx_nrv_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
int upx_nrv_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_nrv_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
#endif #endif
@@ -84,8 +88,10 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_ucl_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
#endif #endif
@@ -102,8 +108,10 @@ int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
int upx_zlib_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_zlib_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
#endif #endif
+427 -156
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,12 +22,13 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#include "conf.h" #include "conf.h"
#include "compress.h" #include "compress.h"
#include "mem.h"
void lzma_compress_config_t::reset() void lzma_compress_config_t::reset()
@@ -51,6 +52,8 @@ extern int compress_lzma_dummy;
int compress_lzma_dummy = 0; int compress_lzma_dummy = 0;
#else #else
#undef USE_LZMA_PROPERTIES
// INFO: the LZMA SDK is covered by a permissive license which allows // INFO: the LZMA SDK is covered by a permissive license which allows
// using unmodified LZMA source code in UPX and the UPX stubs. // using unmodified LZMA source code in UPX and the UPX stubs.
@@ -89,11 +92,244 @@ int compress_lzma_dummy = 0;
// while you keep LZMA SDK code unmodified. // while you keep LZMA SDK code unmodified.
#if (WITH_LZMA >= 0x461)
#include "C/7zVersion.h"
#if (WITH_LZMA != (0x100 * MY_VER_MAJOR) + (0x10 * (MY_VER_MINOR / 10)) + (MY_VER_MINOR % 10))
# error "WITH_LZMA version mismatch"
#endif
#include "C/Types.h"
static void *cb_alloc(void *, size_t size) {
return malloc(size);
}
static void cb_free(void *, void *ptr) {
free(ptr);
}
#endif
/************************************************************************* /*************************************************************************
// cruft because of pseudo-COM layer // compress defaults
**************************************************************************/ **************************************************************************/
#undef USE_LZMA_PROPERTIES static int prepare(lzma_compress_result_t *res,
unsigned src_len, int method, int level,
const lzma_compress_config_t *lcconf)
{
// setup defaults
res->pos_bits = 2; // 0 .. 4
res->lit_pos_bits = 0; // 0 .. 4
res->lit_context_bits = 3; // 0 .. 8
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
res->fast_mode = 2;
res->num_fast_bytes = 64; // 5 .. 273
res->match_finder_cycles = 0;
#if 1
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value_c;
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value_c;
res->dict_size = lzma_compress_config_t::dict_size_t::default_value_c;
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
#endif
// method overrides
if (method >= 0x100) {
res->pos_bits = (method >> 16) & 15;
res->lit_pos_bits = (method >> 12) & 15;
res->lit_context_bits = (method >> 8) & 15;
}
#if 0
// DEBUG - set sizes so that we use a maxmimum amount of stack.
// These settings cause res->num_probs == 3147574, i.e. we will
// need about 6 MiB of stack during runtime decompression.
res->lit_pos_bits = 4;
res->lit_context_bits = 8;
#endif
// FIXME: tune these settings according to level
switch (level)
{
case 1:
res->dict_size = 256 * 1024;
res->fast_mode = 0;
res->num_fast_bytes = 8;
break;
case 2:
res->dict_size = 256 * 1024;
res->fast_mode = 0;
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
res->dict_size = 8 * 1024 * 1024;
break;
case 10:
res->dict_size = src_len;
break;
default:
goto error;
}
// cconf overrides
if (lcconf)
{
oassign(res->pos_bits, lcconf->pos_bits);
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
oassign(res->lit_context_bits, lcconf->lit_context_bits);
oassign(res->dict_size, lcconf->dict_size);
oassign(res->num_fast_bytes, lcconf->num_fast_bytes);
}
// limit dictionary size
if (res->dict_size > src_len)
res->dict_size = src_len;
// limit num_probs
if (lcconf && lcconf->max_num_probs)
{
for (;;)
{
unsigned n = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
if (n <= lcconf->max_num_probs)
break;
if (res->lit_pos_bits > res->lit_context_bits)
{
if (res->lit_pos_bits == 0)
goto error;
res->lit_pos_bits -= 1;
}
else
{
if (res->lit_context_bits == 0)
goto error;
res->lit_context_bits -= 1;
}
}
}
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
return 0;
error:
return -1;
}
/*************************************************************************
// compress
**************************************************************************/
#if (WITH_LZMA >= 0x461)
#define kLiteralNextStates kLiteralNextStates_enc
#include "C/LzmaEnc.h"
#include "C/LzmaEnc.c"
#include "C/LzFind.c"
#undef kLiteralNextStates
#undef kNumFullDistances
struct upx_ICompressProgress {
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
upx_callback_p cb;
};
static SRes cb_progress(void *p, UInt64 inSize, UInt64 outSize) {
upx_callback_p cb = ((upx_ICompressProgress *) p)->cb;
if (cb && cb->nprogress)
cb->nprogress(cb, (unsigned) inSize, (unsigned) outSize);
return SZ_OK;
}
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
assert(level > 0); assert(cresult != NULL);
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
int r = UPX_E_ERROR;
int rh;
unsigned dst_avail = *dst_len;
*dst_len = 0;
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
upx_ICompressProgress progress;
progress.Progress = cb_progress; progress.cb = cb;
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
lzma_compress_result_t *res = &cresult->result_lzma;
if (prepare(res, src_len, method, level, lcconf) != 0)
goto error;
CLzmaEncProps props; memset(&props, 0, sizeof(props));
props.level = level;
LzmaEncProps_Init(&props);
props.pb = res->pos_bits;
props.lp = res->lit_pos_bits;
props.lc = res->lit_context_bits;
props.dictSize = res->dict_size;
props.algo = res->fast_mode ? 1 : 0;
props.fb = res->num_fast_bytes;
props.mc = res->match_finder_cycles;
unsigned char props_buf[LZMA_PROPS_SIZE];
SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE;
#if defined(USE_LZMA_PROPERTIES)
if (dst_avail < 1)
goto error;
dst[0] = 0; // filled below
dst += 1; *dst_len += 1; dst_avail -= 1;
#else
if (dst_avail < 2)
goto error;
// extra stuff in first byte: 5 high bits convenience for stub decompressor
unsigned tt; tt = res->lit_context_bits + res->lit_pos_bits;
dst[0] = ((tt << 3) | res->pos_bits);
dst[1] = ((res->lit_pos_bits << 4) | (res->lit_context_bits));
dst += 2; *dst_len += 2; dst_avail -= 2;
#endif
SizeT x_len; x_len = dst_avail;
rh = LzmaEncode(dst, &x_len, src, src_len,
&props, props_buf, &props_buf_size, 0,
(ICompressProgress *) (void *) &progress, &cba, &cba);
assert(x_len <= dst_avail);
*dst_len += x_len;
if (rh == SZ_OK) {
#if defined(USE_LZMA_PROPERTIES)
dst[-1] = probs_buf[0];
#endif
r = UPX_E_OK;
}
error:
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
return r;
}
#endif /* (WITH_LZMA >= 0x461) */
/*************************************************************************
// compress - cruft because of pseudo-COM layer
**************************************************************************/
#if (WITH_LZMA < 0x461)
#undef MSDOS #undef MSDOS
#undef OS2 #undef OS2
@@ -101,9 +337,15 @@ int compress_lzma_dummy = 0;
#undef _WIN32_WCE #undef _WIN32_WCE
#undef COMPRESS_MF_MT #undef COMPRESS_MF_MT
#undef _NO_EXCEPTIONS #undef _NO_EXCEPTIONS
#include "C/Common/MyInitGuid.h" #if (WITH_LZMA >= 0x449)
//#include "C/7zip/Compress/LZMA/LZMADecoder.h" # define INITGUID 1
#include "C/7zip/Compress/LZMA/LZMAEncoder.h" //# include "CPP/7zip/Compress/LZMA/LZMADecoder.h"
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.h"
#else
# include "C/Common/MyInitGuid.h"
//# include "C/7zip/Compress/LZMA/LZMADecoder.h"
# include "C/7zip/Compress/LZMA/LZMAEncoder.h"
#endif
namespace MyLzma { namespace MyLzma {
@@ -173,16 +415,29 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
# pragma warning(disable: 424) // #424: extra ";" ignored # pragma warning(disable: 424) // #424: extra ";" ignored
#endif #endif
#include "C/Common/Alloc.cpp" #if (WITH_LZMA >= 0x449)
#include "C/Common/CRC.cpp" # include "C/Alloc.c"
//#include "C/7zip/Common/InBuffer.cpp" # include "C/7zCrc.c"
#include "C/7zip/Common/OutBuffer.cpp" # include "C/Compress/Lz/MatchFinder.c"
#include "C/7zip/Common/StreamUtils.cpp" //# include "CPP/7zip/Common/InBuffer.cpp"
#include "C/7zip/Compress/LZ/LZInWindow.cpp" # include "CPP/7zip/Common/OutBuffer.cpp"
//#include "C/7zip/Compress/LZ/LZOutWindow.cpp" # include "CPP/7zip/Common/StreamUtils.cpp"
//#include "C/7zip/Compress/LZMA/LZMADecoder.cpp" //# include "CPP/7zip/Compress/LZ/LZOutWindow.cpp"
#include "C/7zip/Compress/LZMA/LZMAEncoder.cpp" //# include "CPP/7zip/Compress/LZMA/LZMADecoder.cpp"
#include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp" # include "CPP/7zip/Compress/LZMA/LZMAEncoder.cpp"
# include "CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
#else
# include "C/Common/Alloc.cpp"
# include "C/Common/CRC.cpp"
//# include "C/7zip/Common/InBuffer.cpp"
# include "C/7zip/Common/OutBuffer.cpp"
# include "C/7zip/Common/StreamUtils.cpp"
# include "C/7zip/Compress/LZ/LZInWindow.cpp"
//# include "C/7zip/Compress/LZ/LZOutWindow.cpp"
//# include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
# include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
# include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
#endif
#undef RC_NORMALIZE #undef RC_NORMALIZE
@@ -221,126 +476,25 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
NCoderPropID::kMatchFinder // 7 mf NCoderPropID::kMatchFinder // 7 mf
}; };
PROPVARIANT pr[8]; PROPVARIANT pr[8];
#ifdef COMPRESS_MF_BT4
const unsigned nprops = 8;
static wchar_t matchfinder[] = L"BT4";
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
pr[7].vt = VT_BSTR; pr[7].bstrVal = matchfinder;
#else
const unsigned nprops = 7;
#endif
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4; pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4;
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4; pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
pr[7].vt = VT_BSTR; if (prepare(res, src_len, method, level, lcconf) != 0)
// setup defaults
pr[0].uintVal = 2; // 0 .. 4
pr[1].uintVal = 0; // 0 .. 4
pr[2].uintVal = 3; // 0 .. 8
pr[3].uintVal = 4 * 1024 * 1024; // 1 .. 2**30
pr[4].uintVal = 2;
pr[5].uintVal = 64; // 5 .. 273
pr[6].uintVal = 0;
#ifdef COMPRESS_MF_BT4
static wchar_t matchfinder[] = L"BT4";
#endif
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
pr[7].bstrVal = matchfinder;
#if 1
pr[0].uintVal = lzma_compress_config_t::pos_bits_t::default_value_c;
pr[1].uintVal = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
pr[2].uintVal = lzma_compress_config_t::lit_context_bits_t::default_value_c;
pr[3].uintVal = lzma_compress_config_t::dict_size_t::default_value_c;
pr[5].uintVal = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
#endif
// method overrides
if (method >= 0x100) {
pr[0].uintVal = (method >> 16) & 15;
pr[1].uintVal = (method >> 12) & 15;
pr[2].uintVal = (method >> 8) & 15;
}
#if 0
// DEBUG - set sizes so that we use a maxmimum amount of stack.
// These settings cause res->num_probs == 3147574, i.e. we will
// need about 6 MB of stack during runtime decompression.
pr[1].uintVal = 4;
pr[2].uintVal = 8;
#endif
// FIXME: tune these settings according to level
switch (level)
{
case 1:
pr[3].uintVal = 256 * 1024;
pr[4].uintVal = 0;
pr[5].uintVal = 8;
break;
case 2:
pr[3].uintVal = 256 * 1024;
pr[4].uintVal = 0;
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
pr[3].uintVal = 8 * 1024 * 1024;
break;
case 10:
pr[3].uintVal = src_len;
break;
default:
goto error; goto error;
} pr[0].uintVal = res->pos_bits;
pr[1].uintVal = res->lit_pos_bits;
// cconf overrides pr[2].uintVal = res->lit_context_bits;
if (lcconf) pr[3].uintVal = res->dict_size;
{ pr[4].uintVal = res->fast_mode;
oassign(pr[0].uintVal, lcconf->pos_bits); pr[5].uintVal = res->num_fast_bytes;
oassign(pr[1].uintVal, lcconf->lit_pos_bits); pr[6].uintVal = res->match_finder_cycles;
oassign(pr[2].uintVal, lcconf->lit_context_bits);
oassign(pr[3].uintVal, lcconf->dict_size);
oassign(pr[5].uintVal, lcconf->num_fast_bytes);
}
// limit dictionary size
if (pr[3].uintVal > src_len)
pr[3].uintVal = src_len;
// limit num_probs
if (lcconf && lcconf->max_num_probs)
{
for (;;)
{
unsigned n = 1846 + (768 << (pr[2].uintVal + pr[1].uintVal));
if (n <= lcconf->max_num_probs)
break;
if (pr[1].uintVal > pr[2].uintVal)
{
if (pr[1].uintVal == 0)
goto error;
pr[1].uintVal -= 1;
}
else
{
if (pr[2].uintVal == 0)
goto error;
pr[2].uintVal -= 1;
}
}
}
res->pos_bits = pr[0].uintVal;
res->lit_pos_bits = pr[1].uintVal;
res->lit_context_bits = pr[2].uintVal;
res->dict_size = pr[3].uintVal;
res->fast_mode = pr[4].uintVal;
res->num_fast_bytes = pr[5].uintVal;
res->match_finder_cycles = pr[6].uintVal;
//res->num_probs = LzmaGetNumProbs(&s.Properties));
//res->num_probs = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
#ifndef _NO_EXCEPTIONS #ifndef _NO_EXCEPTIONS
try { try {
@@ -348,7 +502,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
# error # error
#endif #endif
if (enc.SetCoderProperties(propIDs, pr, 8) != S_OK) if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
goto error; goto error;
if (enc.WriteCoderProperties(&os) != S_OK) if (enc.WriteCoderProperties(&os) != S_OK)
goto error; goto error;
@@ -397,17 +551,121 @@ error:
return r; return r;
} }
#endif /* (WITH_LZMA < 0x461) */
/************************************************************************* /*************************************************************************
// decompress // decompress
**************************************************************************/ **************************************************************************/
#if (WITH_LZMA >= 0x461)
#undef _LZMA_PROB32
#include "C/LzmaDec.h"
#include "C/LzmaDec.c"
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
#define Properties prop
assert(M_IS_LZMA(method));
// see res->num_probs above
COMPILE_TIME_ASSERT(sizeof(CLzmaProb) == 2)
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
CLzmaDec s; memset(&s, 0, sizeof(s));
SizeT srcLen = 0;
int r = UPX_E_ERROR;
SRes rh;
ELzmaStatus status;
#if defined(USE_LZMA_PROPERTIES)
rh = LzmaProps_Decode(&s.Properties, src, src_len);
if (rh != 0)
goto error;
src += 1; src_len -= 1;
#else
if (src_len < 3)
goto error;
s.Properties.pb = src[0] & 7;
s.Properties.lp = (src[1] >> 4);
s.Properties.lc = src[1] & 15;
if (s.Properties.pb >= 5) goto error;
if (s.Properties.lp >= 5) goto error;
if (s.Properties.lc >= 9) goto error;
// extra
if ((src[0] >> 3) != (int)(s.Properties.lc + s.Properties.lp)) goto error;
src += 2; src_len -= 2;
#endif
s.Properties.dicSize = 0;
if (cresult)
{
assert(cresult->method == method);
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
assert(cresult->result_lzma.num_probs == (unsigned) LzmaProps_GetNumProbs(&s.Properties));
const lzma_compress_result_t *res = &cresult->result_lzma;
UNUSED(res);
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
}
rh = LzmaDec_AllocateProbs2(&s, &s.Properties, &cba);
if (rh != SZ_OK)
{
r = UPX_E_OUT_OF_MEMORY;
goto error;
}
s.dic = dst; s.dicPos = 0; s.dicBufSize = *dst_len;
LzmaDec_Init(&s);
srcLen = src_len;
rh = LzmaDec_DecodeToDic(&s, *dst_len, src, &srcLen, LZMA_FINISH_ANY, &status);
assert(srcLen <= src_len);
assert(s.dicPos <= *dst_len);
if (rh == SZ_OK && status == LZMA_STATUS_NEEDS_MORE_INPUT)
rh = SZ_ERROR_INPUT_EOF;
if (rh == SZ_OK && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
{
r = UPX_E_OK;
if (srcLen != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
}
error:
*dst_len = s.dicPos;
// LzmaDec_Free(&s, &cba); // FIXME - why does this crash ???
return r;
#undef Properties
}
#endif /* (WITH_LZMA >= 0x461) */
/*************************************************************************
// decompress
**************************************************************************/
#if (WITH_LZMA < 0x461)
#undef _LZMA_IN_CB #undef _LZMA_IN_CB
#undef _LZMA_OUT_READ #undef _LZMA_OUT_READ
#undef _LZMA_PROB32 #undef _LZMA_PROB32
#undef _LZMA_LOC_OPT #undef _LZMA_LOC_OPT
#include "C/7zip/Compress/LZMA_C/LzmaDecode.h" #if (WITH_LZMA >= 0x449)
#include "C/7zip/Compress/LZMA_C/LzmaDecode.c" # include "C/Compress/Lzma/LzmaDecode.h"
# include "C/Compress/Lzma/LzmaDecode.c"
#else
# include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
# include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
#endif
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len, int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
@@ -476,35 +734,39 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
error: error:
*dst_len = dst_out; *dst_len = dst_out;
free(s.Probs); free(s.Probs);
UNUSED(cresult);
return r; return r;
} }
#endif /* (WITH_LZMA < 0x461) */
/************************************************************************* /*************************************************************************
// test_overlap // test_overlap - see <ucl/ucl.h> for semantics
**************************************************************************/ **************************************************************************/
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_lzma_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ) const upx_compress_result_t *cresult )
{ {
assert(M_IS_LZMA(method)); assert(M_IS_LZMA(method));
// FIXME - implement this MemBuffer b(src_off + src_len);
// Note that Packer::verifyOverlappingDecompression() will memcpy(b + src_off, buf + src_off, src_len);
// verify the final result in any case. unsigned saved_dst_len = *dst_len;
UNUSED(buf); int r = upx_lzma_decompress(b + src_off, src_len, b, dst_len, method, cresult);
if (r != UPX_E_OK)
unsigned overlap_overhead = src_off + src_len - *dst_len; return r;
//printf("upx_lzma_test_overlap: %d\n", overlap_overhead); if (*dst_len != saved_dst_len)
if ((int)overlap_overhead >= 256)
return UPX_E_OK;
UNUSED(cresult);
return UPX_E_ERROR; return UPX_E_ERROR;
// NOTE: there is a very tiny possibility that decompression has
// succeeded but the data is not restored correctly because of
// in-place buffer overlapping.
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
return UPX_E_ERROR;
return UPX_E_OK;
} }
@@ -514,9 +776,18 @@ int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
const char *upx_lzma_version_string(void) const char *upx_lzma_version_string(void)
{ {
// FIXME #if (WITH_LZMA >= 0x461)
// return NULL; return MY_VERSION;
#elif (WITH_LZMA + 0 == 0x457)
return "4.57";
#elif (WITH_LZMA + 0 == 0x449)
return "4.49";
#elif (WITH_LZMA + 0 == 0x443)
return "4.43"; return "4.43";
#else
# error "unknown WITH_LZMA version"
return NULL;
#endif
} }
+10 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -85,7 +85,7 @@ static int convert_errno_from_ucl(int r)
extern "C" { extern "C" {
static void wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user) static void __UCL_CDECL wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
{ {
if (state != -1 && state != 3) return; if (state != -1 && state != 3) return;
upx_callback_p cb = (upx_callback_p) user; upx_callback_p cb = (upx_callback_p) user;
@@ -120,7 +120,7 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
ucl_compress_config_t cconf; cconf.reset(); ucl_compress_config_t cconf; cconf.reset();
if (cconf_parm) if (cconf_parm)
cconf = cconf_parm->conf_ucl; // struct copy memcpy(&cconf, &cconf_parm->conf_ucl, sizeof(cconf)); // cconf = cconf_parm->conf_ucl; // struct copy
ucl_uint *res = cresult->result_ucl.result; ucl_uint *res = cresult->result_ucl.result;
// assume no info available - fill in worst case results // assume no info available - fill in worst case results
@@ -228,12 +228,15 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
// //
**************************************************************************/ **************************************************************************/
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_ucl_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ) const upx_compress_result_t *cresult )
{ {
int r; int r;
UNUSED(tbuf); // not needed for UCL
switch (method) switch (method)
{ {
+22 -17
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,12 +22,13 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#include "conf.h" #include "conf.h"
#include "compress.h" #include "compress.h"
#include "mem.h"
void zlib_compress_config_t::reset() void zlib_compress_config_t::reset()
@@ -188,28 +189,32 @@ done:
/************************************************************************* /*************************************************************************
// test_overlap // test_overlap - see <ucl/ucl.h> for semantics
**************************************************************************/ **************************************************************************/
int upx_zlib_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_zlib_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ) const upx_compress_result_t *cresult )
{ {
assert(method == M_DEFLATE); assert(method == M_DEFLATE);
// FIXME - implement this MemBuffer b(src_off + src_len);
// Note that Packer::verifyOverlappingDecompression() will memcpy(b + src_off, buf + src_off, src_len);
// verify the final result in any case. unsigned saved_dst_len = *dst_len;
UNUSED(buf); int r = upx_zlib_decompress(b + src_off, src_len, b, dst_len, method, cresult);
if (r != UPX_E_OK)
unsigned overlap_overhead = src_off + src_len - *dst_len; return r;
//printf("upx_zlib_test_overlap: %d\n", overlap_overhead); if (*dst_len != saved_dst_len)
if ((int)overlap_overhead >= 256)
return UPX_E_OK;
UNUSED(cresult);
return UPX_E_ERROR; return UPX_E_ERROR;
// NOTE: there is a very tiny possibility that decompression has
// succeeded but the data is not restored correctly because of
// in-place buffer overlapping.
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
return UPX_E_ERROR;
return UPX_E_OK;
} }
+52 -25
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -78,10 +78,13 @@
# if (ACC_OS_WIN32 || ACC_OS_WIN64) # if (ACC_OS_WIN32 || ACC_OS_WIN64)
# elif defined(__linux__) # elif defined(__linux__)
# pragma warning(error: 424) // #424: extra ";" ignored # pragma warning(error: 424) // #424: extra ";" ignored
//# pragma warning(disable: 128) // #128: loop is not reachable from preceding code
//# pragma warning(disable: 181) // #181: argument is incompatible with corresponding format string conversion
# pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier # pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier
# pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits # pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits
# pragma warning(disable: 981) // #981: operands are evaluated in unspecified order # pragma warning(disable: 981) // #981: operands are evaluated in unspecified order
# pragma warning(disable: 1418) // #1418: external definition with no prior declaration # pragma warning(disable: 1418) // #1418: external function definition with no prior declaration
//# pragma warning(disable: 1419) // #1419: external declaration in primary source file
# else # else
# error "untested platform" # error "untested platform"
# endif # endif
@@ -107,10 +110,13 @@
#elif (ACC_CC_SUNPROC) #elif (ACC_CC_SUNPROC)
//# pragma error_messages(off,"badargtype2w") // FIXME //# pragma error_messages(off,"badargtype2w") // FIXME
#elif (ACC_CC_WATCOMC) #elif (ACC_CC_WATCOMC)
# if (__WATCOMC__ < 1100) # if (__WATCOMC__ < 1280)
# error "need Watcom C++ 11.0c or newer" # error "need Open Watcom C++ 1.8 or newer" // because earlier versions do not support nested classes
# endif # endif
# if defined(__cplusplus) # if defined(__cplusplus)
# pragma warning 367 9 // w3: conditional expression in if statement is always true
# pragma warning 368 9 // w3: conditional expression in if statement is always false
# pragma warning 389 9 // w3: integral value may be truncated
# pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality) # pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality)
# endif # endif
#endif #endif
@@ -160,6 +166,9 @@
#if 0 && !defined(WITH_LZMA) #if 0 && !defined(WITH_LZMA)
# define WITH_LZMA 1 # define WITH_LZMA 1
#endif #endif
#if 1 && (ACC_CC_WATCOMC)
# undef WITH_LZMA
#endif
#if defined(UPX_OFFICIAL_BUILD) #if defined(UPX_OFFICIAL_BUILD)
# if !defined(WITH_LZMA) || !defined(WITH_NRV) || !defined(WITH_UCL) # if !defined(WITH_LZMA) || !defined(WITH_NRV) || !defined(WITH_UCL)
# error # error
@@ -301,16 +310,18 @@
#endif #endif
#undef __attribute_packed #if (ACC_CC_INTELC && (__INTEL_COMPILER < 800))
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) #elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
# if (ACC_ARCH_I386) && (ACC_CC_INTELC && (__INTEL_COMPILER < 800)) #elif (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
# elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386)) # define __packed_struct(s) struct s {
# else # define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
# define __attribute_packed __attribute__((__packed__,__aligned__(1))) #elif (ACC_CC_WATCOMC)
# endif # define __packed_struct(s) _Packed struct s {
# define __packed_struct_end() };
#endif #endif
#if !defined(__attribute_packed) #if !defined(__packed_struct)
# define __attribute_packed # define __packed_struct(s) struct s {
# define __packed_struct_end() };
#endif #endif
@@ -323,8 +334,9 @@
#define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \ #define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \ typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; } __attribute_packed; \ __packed_struct(acc_tmp_t) acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; __packed_struct_end() \
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2*sizeof(b)+sizeof(a)) \ COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2*sizeof(b)+sizeof(a)) \
COMPILE_TIME_ASSERT(sizeof(((acc_tmp_t*)0)->x)+sizeof(((acc_tmp_t*)0)->y)+sizeof(((acc_tmp_t*)0)->z) == 2*sizeof(b)+sizeof(a)) \
} }
#if defined(__acc_alignof) #if defined(__acc_alignof)
# define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \ # define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
@@ -379,12 +391,14 @@ inline unsigned UPX_MIN(unsigned a, unsigned b) { return a < b ? a : b; }
#define ByteArray(var, size) Array(unsigned char, var, size) #define ByteArray(var, size) Array(unsigned char, var, size)
struct nocopy struct noncopyable
{ {
inline nocopy() {} protected:
inline noncopyable() {}
inline ~noncopyable() {}
private: private:
nocopy(const nocopy &); // undefined noncopyable(const noncopyable &); // undefined
nocopy& operator=(const nocopy &); // undefined const noncopyable& operator=(const noncopyable &); // undefined
}; };
@@ -448,14 +462,21 @@ private:
#define UPX_F_LINUX_ELFI_i386 20 #define UPX_F_LINUX_ELFI_i386 20
#define UPX_F_WINCE_ARM_PE 21 #define UPX_F_WINCE_ARM_PE 21
#define UPX_F_LINUX_ELF64_AMD 22 #define UPX_F_LINUX_ELF64_AMD 22
#define UPX_F_LINUX_ELF32_ARMLE 23 #define UPX_F_LINUX_ELF32_ARMEL 23
#define UPX_F_BSD_i386 24 #define UPX_F_BSD_i386 24
#define UPX_F_BSD_ELF_i386 25 #define UPX_F_BSD_ELF_i386 25
#define UPX_F_BSD_SH_i386 26 #define UPX_F_BSD_SH_i386 26
#define UPX_F_VMLINUX_AMD64 27 #define UPX_F_VMLINUX_AMD64 27
#define UPX_F_VMLINUX_ARM 28 #define UPX_F_VMLINUX_ARMEL 28
#define UPX_F_MACH_i386 29 #define UPX_F_MACH_i386 29
#define UPX_F_LINUX_ELF32_MIPSEL 30
#define UPX_F_VMLINUZ_ARMEL 31
#define UPX_F_MACH_ARMEL 32
#define UPX_F_DYLIB_i386 33
#define UPX_F_MACH_AMD64 34
#define UPX_F_DYLIB_AMD64 35
#define UPX_F_PLAIN_TEXT 127 #define UPX_F_PLAIN_TEXT 127
@@ -463,8 +484,12 @@ private:
#define UPX_F_SOLARIS_SPARC 130 #define UPX_F_SOLARIS_SPARC 130
#define UPX_F_MACH_PPC32 131 #define UPX_F_MACH_PPC32 131
#define UPX_F_LINUX_ELFPPC32 132 #define UPX_F_LINUX_ELFPPC32 132
#define UPX_F_LINUX_ELF32_ARMBE 133 #define UPX_F_LINUX_ELF32_ARMEB 133
#define UPX_F_MACH_FAT 134 #define UPX_F_MACH_FAT 134
#define UPX_F_VMLINUX_ARMEB 135
#define UPX_F_VMLINUX_PPC32 136
#define UPX_F_LINUX_ELF32_MIPSEB 137
#define UPX_F_DYLIB_PPC32 138
// compression methods // compression methods
@@ -778,8 +803,10 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len, upx_bytep dst, unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
int upx_test_overlap ( const upx_bytep buf, unsigned src_off, int upx_test_overlap ( const upx_bytep buf,
unsigned src_len, unsigned* dst_len, const upx_bytep tbuf,
unsigned src_off, unsigned src_len,
unsigned* dst_len,
int method, int method,
const upx_compress_result_t *cresult ); const upx_compress_result_t *cresult );
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+11 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -161,6 +161,14 @@ void throwBadLoader()
} }
void throwOutOfMemoryException(const char *msg)
{
if (msg == NULL)
msg = "out of memory";
throw OutOfMemoryException(msg);
}
void throwIOException(const char *msg, int e) void throwIOException(const char *msg, int e)
{ {
throw IOException(msg, e); throw IOException(msg, e);
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -220,6 +220,7 @@ void throwBadLoader() NORET;
void throwChecksumError() NORET; void throwChecksumError() NORET;
void throwCompressedDataViolation() NORET; void throwCompressedDataViolation() NORET;
void throwInternalError(const char *msg) NORET; void throwInternalError(const char *msg) NORET;
void throwOutOfMemoryException(const char *msg = NULL) NORET;
void throwIOException(const char *msg = NULL, int e = 0) NORET; void throwIOException(const char *msg = NULL, int e = 0) NORET;
void throwEOFException(const char *msg = NULL, int e = 0) NORET; void throwEOFException(const char *msg = NULL, int e = 0) NORET;
+21 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -88,7 +88,7 @@ FileBase::~FileBase()
} }
void FileBase::sopen() bool FileBase::do_sopen()
{ {
if (_shflags < 0) if (_shflags < 0)
_fd = ::open(_name, _flags, _mode); _fd = ::open(_name, _flags, _mode);
@@ -101,13 +101,15 @@ void FileBase::sopen()
#elif defined(SH_DENYRW) #elif defined(SH_DENYRW)
_fd = ::sopen(_name, _flags, _shflags, _mode); _fd = ::sopen(_name, _flags, _shflags, _mode);
#else #else
assert(0); throwInternalError("bad usage of do_sopen()");
#endif #endif
} }
if (!(_fd < 0)) { if (_fd < 0)
::fstat(_fd, &st); return false;
if (::fstat(_fd, &st) != 0)
throwIOException(_name, errno);
_length = st.st_size; _length = st.st_size;
} return true;
} }
@@ -232,8 +234,7 @@ void InputFile::sopen(const char *name, int flags, int shflags)
_mode = 0; _mode = 0;
_offset = 0; _offset = 0;
_length = 0; _length = 0;
FileBase::sopen(); if (!FileBase::do_sopen())
if (!isOpen())
{ {
if (errno == ENOENT) if (errno == ENOENT)
throw FileNotFoundException(_name, errno); throw FileNotFoundException(_name, errno);
@@ -318,8 +319,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
_mode = mode; _mode = mode;
_offset = 0; _offset = 0;
_length = 0; _length = 0;
FileBase::sopen(); if (!FileBase::do_sopen())
if (!isOpen())
{ {
#if 0 #if 0
// don't throw FileNotFound here -- this is confusing // don't throw FileNotFound here -- this is confusing
@@ -366,7 +366,9 @@ off_t OutputFile::st_size() const
return bytes_written; // too big if seek()+write() instead of rewrite() return bytes_written; // too big if seek()+write() instead of rewrite()
} }
struct stat my_st; struct stat my_st;
::fstat(_fd, &my_st); my_st.st_size = 0;
if (::fstat(_fd, &my_st) != 0)
throwIOException(_name, errno);
return my_st.st_size; return my_st.st_size;
} }
@@ -402,15 +404,19 @@ void OutputFile::set_extent(off_t offset, off_t length)
super::set_extent(offset, length); super::set_extent(offset, length);
bytes_written = 0; bytes_written = 0;
if (0==offset && (off_t)~0u==length) { if (0==offset && (off_t)~0u==length) {
::fstat(_fd, &st); if (::fstat(_fd, &st) != 0)
throwIOException(_name, errno);
_length = st.st_size - offset; _length = st.st_size - offset;
} }
} }
off_t OutputFile::unset_extent() off_t OutputFile::unset_extent()
{ {
off_t l = ::lseek(_fd, 0, SEEK_END);
if (l < 0)
throwIOException("lseek error", errno);
_offset = 0; _offset = 0;
_length = ::lseek(_fd, 0, SEEK_END); _length = l;
bytes_written = _length; bytes_written = _length;
return _length; return _length;
} }
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -63,7 +63,7 @@ public:
virtual void set_extent(off_t offset, off_t length); virtual void set_extent(off_t offset, off_t length);
protected: protected:
void sopen(); bool do_sopen();
virtual int read(void *buf, int len); virtual int read(void *buf, int len);
virtual int readx(void *buf, int len); virtual int readx(void *buf, int len);
virtual void write(const void *buf, int len); virtual void write(const void *buf, int len);
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -47,7 +47,7 @@ static int F(Filter *f)
unsigned calls = 0, noncalls = 0, noncalls2 = 0; unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0; unsigned lastnoncall = size, lastcall = 0;
// find a 16MB large empty address space // find a 16 MiB large empty address space
{ {
unsigned char buf[256]; unsigned char buf[256];
memset(buf,0,256); memset(buf,0,256);
@@ -126,7 +126,7 @@ static int F(Filter *f)
f->noncalls = noncalls; f->noncalls = noncalls;
f->lastcall = lastcall; f->lastcall = lastcall;
#ifdef TESTING #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto); printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
#endif #endif
return 0; return 0;
+6 -6
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -51,7 +51,7 @@ static int F(Filter *f)
unsigned calls = 0, noncalls = 0, noncalls2 = 0; unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0; unsigned lastnoncall = size, lastcall = 0;
// find a 16MB large empty address space // find a 16 MiB large empty address space
{ {
unsigned char buf[256]; unsigned char buf[256];
memset(buf,0,256); memset(buf,0,256);
@@ -125,7 +125,7 @@ static int F(Filter *f)
f->noncalls = noncalls; f->noncalls = noncalls;
f->lastcall = lastcall; f->lastcall = lastcall;
#ifdef TESTING #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto); printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
#endif #endif
return 0; return 0;
+8 -8
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -123,8 +123,8 @@ static int F(Filter *f)
N_MRU : 0; N_MRU : 0;
#endif //} #endif //}
// FIXME: We must fit into 8MB because we steal one bit. // FIXME: We must fit into 8 MiB because we steal one bit.
// find a 16MB large empty address space // find a 16 MiB large empty address space
{ {
int which; int which;
unsigned char buf[256]; unsigned char buf[256];
@@ -249,11 +249,11 @@ static int F(Filter *f)
f->noncalls = noncalls; f->noncalls = noncalls;
f->lastcall = lastcall; f->lastcall = lastcall;
/*#ifdef TESTING*/ #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n", printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",
calls,noncalls,noncalls2,size,cto8); calls,noncalls,noncalls2,size,cto8);
printf("CALL/JMP/JCC %d %d %d\n",wtally[0],wtally[1],wtally[2]); printf("CALL/JMP/JCC %d %d %d\n",wtally[0],wtally[1],wtally[2]);
/*#endif*/ #endif
return 0; return 0;
} }
+6 -6
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -52,7 +52,7 @@ static int F(Filter *f)
unsigned calls = 0, noncalls = 0, noncalls2 = 0; unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0; unsigned lastnoncall = size, lastcall = 0;
// find a 16MB large empty address space // find a 16 MiB large empty address space
{ {
unsigned char buf[256]; unsigned char buf[256];
memset(buf,0,256); memset(buf,0,256);
@@ -126,7 +126,7 @@ static int F(Filter *f)
f->noncalls = noncalls; f->noncalls = noncalls;
f->lastcall = lastcall; f->lastcall = lastcall;
#ifdef TESTING #if 0 || defined(TESTING)
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto); printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
#endif #endif
return 0; return 0;
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+13 -10
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2004-2007 John F. Reiser Copyright (C) 2004-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -47,7 +47,7 @@ static int F(Filter *f)
// scan // scan
const upx_byte *b = f->buf; const upx_byte *b = f->buf;
#endif #endif
const unsigned size = umin(f->buf_len, -(~0u<<(32 - (6+ W_CTO)))); const unsigned size = umin(f->buf_len, 0u - (~0u<<(32 - (6+ W_CTO))));
const unsigned size4 = size -4; const unsigned size4 = size -4;
unsigned ic; unsigned ic;
@@ -72,9 +72,11 @@ static int F(Filter *f)
} }
if (getcto(f, buf) < 0) { if (getcto(f, buf) < 0) {
if (0!=W_CTO) // FIXME: what is this ??? #if (W_CTO != 0)
return -1; return -1;
#else
f->cto = 0; f->cto = 0;
#endif
} }
} }
const unsigned char cto8 = f->cto; const unsigned char cto8 = f->cto;
@@ -95,8 +97,9 @@ static int F(Filter *f)
lastcall = ic; lastcall = ic;
} }
else { else {
assert(0==W_CTO // FIXME: what is this ??? #if (W_CTO != 0)
|| (~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
#endif
lastnoncall = ic; lastnoncall = ic;
noncalls++; noncalls++;
} }
@@ -106,7 +109,7 @@ static int F(Filter *f)
f->noncalls = noncalls; f->noncalls = noncalls;
f->lastcall = lastcall; f->lastcall = lastcall;
#if 0 #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",
calls,noncalls,size,cto8); calls,noncalls,size,cto8);
#endif #endif
@@ -122,7 +125,7 @@ static int F(Filter *f)
static int U(Filter *f) static int U(Filter *f)
{ {
upx_byte *b = f->buf; upx_byte *b = f->buf;
const unsigned size4 = umin(f->buf_len - 4, -(~0u<<(32 - (6+ W_CTO)))); const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u<<(32 - (6+ W_CTO))));
const unsigned addvalue = f->addvalue; const unsigned addvalue = f->addvalue;
unsigned ic; unsigned ic;
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+19 -48
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -51,7 +51,7 @@ void show_head(void)
fg = con_fg(f,FG_GREEN); fg = con_fg(f,FG_GREEN);
con_fprintf(f, con_fprintf(f,
" Ultimate Packer for eXecutables\n" " Ultimate Packer for eXecutables\n"
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007\n" " Copyright (C) 1996 - 2009\n"
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n", "UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
#if (ACC_OS_DOS16 || ACC_OS_DOS32) #if (ACC_OS_DOS16 || ACC_OS_DOS32)
V("d"), V("d"),
@@ -97,14 +97,14 @@ struct PackerNames
const char* fname; const char* fname;
const char* sname; const char* sname;
}; };
Entry names[32]; Entry names[64];
size_t names_count; size_t names_count;
const options_t *o; const options_t *o;
PackerNames() : names_count(0), o(NULL) { } PackerNames() : names_count(0), o(NULL) { }
void add(const Packer *p) void add(const Packer *p)
{ {
p->assertPacker(); p->assertPacker();
assert(names_count < 32); assert(names_count < 64);
names[names_count].fname = p->getFullName(o); names[names_count].fname = p->getFullName(o);
names[names_count].sname = p->getName(); names[names_count].sname = p->getName();
names_count++; names_count++;
@@ -140,15 +140,16 @@ static void show_all_packers(FILE *f, int verbose)
} }
else else
{ {
size_t fl = strlen(fn);
if (pos == 0) { if (pos == 0) {
con_fprintf(f, " %s", fn); con_fprintf(f, " %s", fn);
pos = 2 + strlen(fn); pos = 2 + fl;
} else if (pos + 1 + strlen(fn) > 80) { } else if (pos + 1 + fl > 80) {
con_fprintf(f, "\n %s", fn); con_fprintf(f, "\n %s", fn);
pos = 2 + strlen(fn); pos = 2 + fl;
} else { } else {
con_fprintf(f, " %s", fn); con_fprintf(f, " %s", fn);
pos += 1 + strlen(fn); pos += 1 + fl;
} }
} }
} }
@@ -205,8 +206,8 @@ void show_help(int verbose)
con_fprintf(f,"\nCompression tuning options:\n"); con_fprintf(f,"\nCompression tuning options:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
" --brute try all available compression methods & filters\n" " --brute try all available compression methods & filters [slow]\n"
" --ultra-brute try even more compression variants\n" " --ultra-brute try even more compression variants [very slow]\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Backup options:\n"); con_fprintf(f,"Backup options:\n");
@@ -224,26 +225,16 @@ void show_help(int verbose)
" --overlay=skip don't compress a file with an overlay\n" " --overlay=skip don't compress a file with an overlay\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for atari/tos:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --all-methods try all available compression methods\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for djgpp2/coff:\n"); con_fprintf(f,"Options for djgpp2/coff:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
" --coff produce COFF output [default: EXE]\n" " --coff produce COFF output [default: EXE]\n"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for dos/com:\n"); con_fprintf(f,"Options for dos/com:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
" --8086 make compressed com work on any 8086\n" " --8086 make compressed com work on any 8086\n"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for dos/exe:\n"); con_fprintf(f,"Options for dos/exe:\n");
@@ -251,15 +242,12 @@ void show_help(int verbose)
con_fprintf(f, con_fprintf(f,
" --8086 make compressed exe work on any 8086\n" " --8086 make compressed exe work on any 8086\n"
" --no-reloc put no relocations in to the exe header\n" " --no-reloc put no relocations in to the exe header\n"
" --all-methods try all available compression methods\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for dos/sys:\n"); con_fprintf(f,"Options for dos/sys:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
" --8086 make compressed sys work on any 8086\n" " --8086 make compressed sys work on any 8086\n"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n"); "\n");
#if 0 #if 0
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
@@ -274,27 +262,12 @@ void show_help(int verbose)
con_fprintf(f,"Options for ps1/exe:\n"); con_fprintf(f,"Options for ps1/exe:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
" --all-methods try all available compression methods\n"
" --8-bit uses 8 bit size compression [default: 32 bit]\n" " --8-bit uses 8 bit size compression [default: 32 bit]\n"
" --8mb-ram 8 megabyte memory limit [default: 2 mb]\n" " --8mib-ram 8 megabyte memory limit [default: 2 MiB]\n"
" --boot-only disables client/host transfer compatibility\n" " --boot-only disables client/host transfer compatibility\n"
" --no-align don't align to 2048 bytes [enables: --console-run]\n" " --no-align don't align to 2048 bytes [enables: --console-run]\n"
"\n"); "\n");
fg = con_fg(f,FG_YELLOW); fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for tmt/adam:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for vmlinuz/386\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for watcom/le:\n"); con_fprintf(f,"Options for watcom/le:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f, con_fprintf(f,
@@ -314,8 +287,6 @@ void show_help(int verbose)
" --keep-resource=list do not compress resources specified by list\n" " --keep-resource=list do not compress resources specified by list\n"
" --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"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n"); "\n");
} }
@@ -387,7 +358,7 @@ void show_license(void)
con_fprintf(f, con_fprintf(f,
"\n" "\n"
" Markus F.X.J. Oberhumer Laszlo Molnar\n" " Markus F.X.J. Oberhumer Laszlo Molnar\n"
" <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>\n" " <markus@oberhumer.com> <ml1050@users.sourceforge.net>\n"
); );
fg = con_fg(f,fg); fg = con_fg(f,fg);
@@ -427,10 +398,10 @@ void show_version(int x)
if (v != NULL && v[0]) if (v != NULL && v[0])
fprintf(fp, "LZMA SDK version %s\n", v); fprintf(fp, "LZMA SDK version %s\n", v);
#endif #endif
fprintf(fp, "Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer\n"); fprintf(fp, "Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(fp, "Copyright (C) 1996-2007 Laszlo Molnar\n"); fprintf(fp, "Copyright (C) 1996-2009 Laszlo Molnar\n");
fprintf(fp, "Copyright (C) 2000-2007 John F. Reiser\n"); fprintf(fp, "Copyright (C) 2000-2009 John F. Reiser\n");
fprintf(fp, "Copyright (C) 2002-2007 Jens Medoch\n"); fprintf(fp, "Copyright (C) 2002-2009 Jens Medoch\n");
#if defined(WITH_ZLIB) #if defined(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
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+10 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -49,8 +49,8 @@ public:
protected: protected:
enum { FIXUP_EXTRA = 3 }; enum { FIXUP_EXTRA = 3 };
struct le_header_t __packed_struct(le_header_t)
{ // 0x00 // 0x00
char _[2]; // signature: 'LE' || 'LX' char _[2]; // signature: 'LE' || 'LX'
char byte_order; // 0 little endian char byte_order; // 0 little endian
char word_order; // 0 little endian char word_order; // 0 little endian
@@ -117,28 +117,23 @@ protected:
LE16 device_id; LE16 device_id;
LE16 ddk_version; LE16 ddk_version;
#endif #endif
} __packed_struct_end()
__attribute_packed;
struct le_object_table_entry_t __packed_struct(le_object_table_entry_t)
{
LE32 virtual_size; LE32 virtual_size;
LE32 base_address; LE32 base_address;
LE32 flags; LE32 flags;
LE32 pagemap_index; LE32 pagemap_index;
LE32 npages; LE32 npages;
LE32 reserved; LE32 reserved;
} __packed_struct_end()
__attribute_packed;
struct le_pagemap_entry_t __packed_struct(le_pagemap_entry_t)
{
unsigned char h; unsigned char h;
unsigned char m; unsigned char m;
unsigned char l; unsigned char l;
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
} __packed_struct_end()
__attribute_packed;
virtual void readObjectTable(); virtual void readObjectTable();
virtual void writeObjectTable(); virtual void writeObjectTable();
+49 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -159,7 +159,9 @@ void ElfLinker::init(const void *pdata_v, int plen)
input = new upx_byte[inputlen + 1]; input = new upx_byte[inputlen + 1];
unsigned new_len = u_len; unsigned new_len = u_len;
int r = upx_decompress(pdata, c_len, input, &new_len, method, NULL); int r = upx_decompress(pdata, c_len, input, &new_len, method, NULL);
if (r != 0 || new_len != u_len) if (r == UPX_E_OUT_OF_MEMORY)
throwOutOfMemoryException();
if (r != UPX_E_OK || new_len != u_len)
throwBadLoader(); throwBadLoader();
} }
else else
@@ -235,7 +237,13 @@ void ElfLinker::preprocessSymbols(char *start, char *end)
addSymbol(s, "*ABS*", value); addSymbol(s, "*ABS*", value);
assert(offset == 0); assert(offset == 0);
} }
#if 0
else if (sscanf(start, "%x%*8c %1023s %*x %1023s", else if (sscanf(start, "%x%*8c %1023s %*x %1023s",
#else
// work around broken scanf() implementations
// http://bugs.winehq.org/show_bug.cgi?id=10401 (fixed in Wine 0.9.58)
else if (sscanf(start, "%x%*c%*c%*c%*c%*c%*c%*c%*c %1023s %*x %1023s",
#endif
&offset, section, symbol) == 3) &offset, section, symbol) == 3)
{ {
char *s = strstr(start, symbol); char *s = strstr(start, symbol);
@@ -758,6 +766,37 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
} }
void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type)
{
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
#define MIPS_LO(a) ((a) & 0xffff)
#define MIPS_PC16(a) ((a) >> 2)
#define MIPS_PC26(a) (((a) & 0x0fffffff) >> 2)
if (strcmp(type, "R_MIPS_HI16") == 0)
set_be16(2+location, get_be16(2+location) + MIPS_HI(value));
else if (strcmp(type, "R_MIPS_LO16") == 0)
set_be16(2+location, get_be16(2+location) + MIPS_LO(value));
else if (strcmp(type, "R_MIPS_PC16") == 0)
{
value -= rel->section->offset + rel->offset;
set_be16(2+location, get_be16(2+location) + MIPS_PC16(value));
}
else if (strcmp(type, "R_MIPS_26") == 0)
set_be32(location, get_be32(location) + MIPS_PC26(value));
else if (strcmp(type, "R_MIPS_32") == 0)
set_be32(location, get_be32(location) + value);
else
super::relocate1(rel, location, value, type);
#undef MIPS_HI
#undef MIPS_LO
#undef MIPS_PC16
#undef MIPS_PC26
}
void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location, void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type) unsigned value, const char *type)
{ {
@@ -796,6 +835,12 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
return super::relocate1(rel, location, value, type); return super::relocate1(rel, location, value, type);
type += 6; type += 6;
if (strcmp(type, "ADDR32") == 0)
{
set_be32(location, get_be32(location) + value);
return;
}
if (strncmp(type, "REL", 3) == 0) if (strncmp(type, "REL", 3) == 0)
{ {
value -= rel->section->offset + rel->offset; value -= rel->section->offset + rel->offset;
+27 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -34,11 +34,11 @@
// ElfLinker // ElfLinker
**************************************************************************/ **************************************************************************/
class ElfLinker : private nocopy class ElfLinker : private noncopyable
{ {
friend class Packer; friend class Packer;
public: public:
const N_BELE_RTP::AbstractPolicy *bele; const N_BELE_RTP::AbstractPolicy *bele; // target endianness
protected: protected:
struct Section; struct Section;
struct Symbol; struct Symbol;
@@ -107,10 +107,18 @@ 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); unsigned value, const char *type);
// target endianness abstraction
unsigned get_te16(const void *p) const { return bele->get16(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); }
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_te64(void *p, acc_uint64l_t v) const { bele->set64(p, v); }
}; };
struct ElfLinker::Section : private nocopy struct ElfLinker::Section : private noncopyable
{ {
char *name; char *name;
void *input; void *input;
@@ -125,7 +133,7 @@ struct ElfLinker::Section : private nocopy
}; };
struct ElfLinker::Symbol : private nocopy struct ElfLinker::Symbol : private noncopyable
{ {
char *name; char *name;
Section *section; Section *section;
@@ -136,7 +144,7 @@ struct ElfLinker::Symbol : private nocopy
}; };
struct ElfLinker::Relocation : private nocopy struct ElfLinker::Relocation : private noncopyable
{ {
const Section *section; const Section *section;
unsigned offset; unsigned offset;
@@ -195,6 +203,17 @@ protected:
}; };
class ElfLinkerMipsBE : public ElfLinker
{
typedef ElfLinker super;
public:
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
protected:
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class ElfLinkerMipsLE : public ElfLinker class ElfLinkerMipsLE : public ElfLinker
{ {
typedef ElfLinker super; typedef ElfLinker super;
+50 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -56,6 +56,9 @@ void options_t::reset()
o->backup = -1; o->backup = -1;
o->overlay = -1; o->overlay = -1;
o->preserve_mode = true;
o->preserve_ownership = true;
o->preserve_timestamp = true;
o->console = CON_FILE; o->console = CON_FILE;
#if defined(__DJGPP__) #if defined(__DJGPP__)
@@ -630,6 +633,17 @@ static int do_option(int optc, const char *arg)
opt->debug.disable_random_id = true; opt->debug.disable_random_id = true;
break; break;
// mp (meta)
case 501:
getoptvar(&opt->mp_compress_task, 1, 999999, arg);
break;
case 502:
opt->mp_query_format = true;
break;
case 503:
opt->mp_query_num_tasks = true;
break;
// misc // misc
case 512: case 512:
opt->console = CON_FILE; opt->console = CON_FILE;
@@ -646,6 +660,15 @@ static int do_option(int optc, const char *arg)
case 519: case 519:
opt->no_env = true; opt->no_env = true;
break; break;
case 526:
opt->preserve_mode = false;
break;
case 527:
opt->preserve_ownership = false;
break;
case 528:
opt->preserve_timestamp = false;
break;
// compression settings // compression settings
case 520: // --small case 520: // --small
if (opt->small < 0) if (opt->small < 0)
@@ -858,7 +881,7 @@ static int do_option(int optc, const char *arg)
opt->ps1_exe.do_8bit = true; opt->ps1_exe.do_8bit = true;
break; break;
case 673: case 673:
opt->ps1_exe.do_8mb = false; opt->ps1_exe.do_8mib = false;
break; break;
case '\0': case '\0':
@@ -900,7 +923,10 @@ static const struct mfx_option longopts[] =
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files {"force-compress", 0, 0, 'f'}, // and compression of suspicious files
{"info", 0, 0, 'i'}, // info mode {"info", 0, 0, 'i'}, // info mode
{"no-env", 0x10, 0, 519}, // no environment var {"no-env", 0x10, 0, 519}, // no environment var
{"no-mode", 0x10, 0, 526}, // do not preserve mode (permissions)
{"no-owner", 0x10, 0, 527}, // do not preserve ownership
{"no-progress", 0, 0, 516}, // no progress bar {"no-progress", 0, 0, 516}, // no progress bar
{"no-time", 0x10, 0, 528}, // do not preserve timestamp
{"output", 0x21, 0, 'o'}, {"output", 0x21, 0, 'o'},
{"quiet", 0, 0, 'q'}, // quiet mode {"quiet", 0, 0, 'q'}, // quiet mode
{"silent", 0, 0, 'q'}, // quiet mode {"silent", 0, 0, 'q'}, // quiet mode
@@ -1019,8 +1045,14 @@ static const struct mfx_option longopts[] =
{"boot-only", 0x10, 0, 670}, {"boot-only", 0x10, 0, 670},
{"no-align", 0x10, 0, 671}, {"no-align", 0x10, 0, 671},
{"8-bit", 0x10, 0, 672}, {"8-bit", 0x10, 0, 672},
{"8mib-ram", 0x10, 0, 673},
{"8mb-ram", 0x10, 0, 673}, {"8mb-ram", 0x10, 0, 673},
// mp (meta) options
{"mp-compress-task", 0x31, 0, 501},
{"mp-query-format", 0x10, 0, 502},
{"mp-query-num-tasks", 0x10, 0, 503},
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@@ -1091,6 +1123,13 @@ static const struct mfx_option longopts[] =
// compression settings // compression settings
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression {"exact", 0x10, 0, 525}, // user requires byte-identical decompression
// compression method
{"nrv2b", 0x10, 0, 702}, // --nrv2b
{"nrv2d", 0x10, 0, 704}, // --nrv2d
{"nrv2e", 0x10, 0, 705}, // --nrv2e
{"lzma", 0x10, 0, 721}, // --lzma
{"no-lzma", 0x10, 0, 722}, // (disable all_methods_use_lzma)
// compression settings
// compression runtime parameters // compression runtime parameters
// win32/pe // win32/pe
@@ -1218,8 +1257,8 @@ template <class T> struct TestBELE {
static bool test(void) static bool test(void)
{ {
COMPILE_TIME_ASSERT_ALIGNED1(T) COMPILE_TIME_ASSERT_ALIGNED1(T)
struct test1_t { char a; T b; } __attribute_packed; __packed_struct(test1_t) char a; T b; __packed_struct_end()
struct test2_t { char a; T b[3]; } __attribute_packed; __packed_struct(test2_t) char a; T b[3]; __packed_struct_end()
test1_t t1[7]; UNUSED(t1); test2_t t2[7]; UNUSED(t2); test1_t t1[7]; UNUSED(t1); test2_t t2[7]; UNUSED(t2);
COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T)) COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T))
COMPILE_TIME_ASSERT_ALIGNED1(test1_t) COMPILE_TIME_ASSERT_ALIGNED1(test1_t)
@@ -1231,7 +1270,11 @@ static bool test(void)
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
#if 1 && !defined(xUPX_OFFICIAL_BUILD) #if 1 && (ACC_CC_WATCOMC)
test1_t t11; COMPILE_TIME_ASSERT(sizeof(t11.a) <= sizeof(t11.b))
test2_t t22; COMPILE_TIME_ASSERT(sizeof(t22.a) <= sizeof(t22.b))
#endif
#if 1 && !defined(UPX_OFFICIAL_BUILD)
T allbits; allbits = 0; allbits -= 1; T allbits; allbits = 0; allbits -= 1;
//++allbits; allbits++; --allbits; allbits--; //++allbits; allbits++; --allbits; allbits--;
T v1; v1 = 1; v1 *= 2; v1 -= 1; T v1; v1 = 1; v1 *= 2; v1 -= 1;
+4 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -192,11 +192,7 @@ void MemBuffer::alloc(unsigned size)
assert((int)total > 0); assert((int)total > 0);
unsigned char *p = (unsigned char *) malloc(total); unsigned char *p = (unsigned char *) malloc(total);
if (!p) if (!p)
{ throwOutOfMemoryException();
//throw bad_alloc();
throw OutOfMemoryException("out of memory");
//exit(1);
}
b_size = size; b_size = size;
if (use_mcheck) if (use_mcheck)
{ {
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+89 -238
View File
@@ -1,7 +1,8 @@
/* ACC -- Automatic Compiler Configuration /* ACC --- Automatic Compiler Configuration
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
@@ -38,7 +39,7 @@
#ifndef __ACC_H_INCLUDED #ifndef __ACC_H_INCLUDED
#define __ACC_H_INCLUDED 1 #define __ACC_H_INCLUDED 1
#define ACC_VERSION 20070113L #define ACC_VERSION 20081229L
#if defined(__CYGWIN32__) && !defined(__CYGWIN__) #if defined(__CYGWIN32__) && !defined(__CYGWIN__)
# define __CYGWIN__ __CYGWIN32__ # define __CYGWIN__ __CYGWIN32__
#endif #endif
@@ -419,6 +420,9 @@
# elif defined(__NT__) && (__WATCOMC__ < 1100) # elif defined(__NT__) && (__WATCOMC__ < 1100)
# define ACC_OS_WIN32 1 # define ACC_OS_WIN32 1
# define ACC_INFO_OS "win32" # define ACC_INFO_OS "win32"
# elif defined(__linux__) || defined(__LINUX__)
# define ACC_OS_POSIX 1
# define ACC_INFO_OS "posix"
# else # else
# error "please specify a target using the -bt compiler option" # error "please specify a target using the -bt compiler option"
# endif # endif
@@ -464,7 +468,7 @@
# elif defined(__IRIX__) || defined(__irix__) # elif defined(__IRIX__) || defined(__irix__)
# define ACC_OS_POSIX_IRIX 1 # define ACC_OS_POSIX_IRIX 1
# define ACC_INFO_OS_POSIX "irix" # define ACC_INFO_OS_POSIX "irix"
# elif defined(__linux__) || defined(__linux) # elif defined(__linux__) || defined(__linux) || defined(__LINUX__)
# define ACC_OS_POSIX_LINUX 1 # define ACC_OS_POSIX_LINUX 1
# define ACC_INFO_OS_POSIX "linux" # define ACC_INFO_OS_POSIX "linux"
# elif defined(__APPLE__) || defined(__MACOS__) # elif defined(__APPLE__) || defined(__MACOS__)
@@ -573,6 +577,10 @@
# define ACC_CC_AZTECC 1 # define ACC_CC_AZTECC 1
# define ACC_INFO_CC "Aztec C" # define ACC_INFO_CC "Aztec C"
# define ACC_INFO_CCVER ACC_PP_MACRO_EXPAND(__AZTEC_C__) # define ACC_INFO_CCVER ACC_PP_MACRO_EXPAND(__AZTEC_C__)
#elif defined(__CODEGEARC__)
# define ACC_CC_CODEGEARC 1
# define ACC_INFO_CC "CodeGear C"
# define ACC_INFO_CCVER ACC_PP_MACRO_EXPAND(__CODEGEARC__)
#elif defined(__BORLANDC__) #elif defined(__BORLANDC__)
# define ACC_CC_BORLANDC 1 # define ACC_CC_BORLANDC 1
# define ACC_INFO_CC "Borland C" # define ACC_INFO_CC "Borland C"
@@ -896,7 +904,7 @@
# endif # endif
#endif #endif
#if !defined(__ACC_MM_OVERRIDE) #if !defined(__ACC_MM_OVERRIDE)
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16) #if (ACC_ARCH_I086)
#if (UINT_MAX != ACC_0xffffL) #if (UINT_MAX != ACC_0xffffL)
# error "this should not happen" # error "this should not happen"
#endif #endif
@@ -927,6 +935,7 @@
#else #else
# error "unknown memory model" # error "unknown memory model"
#endif #endif
#if (ACC_OS_DOS16 || ACC_OS_OS216 || ACC_OS_WIN16)
#define ACC_HAVE_MM_HUGE_PTR 1 #define ACC_HAVE_MM_HUGE_PTR 1
#define ACC_HAVE_MM_HUGE_ARRAY 1 #define ACC_HAVE_MM_HUGE_ARRAY 1
#if (ACC_MM_TINY) #if (ACC_MM_TINY)
@@ -979,6 +988,7 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif
#elif (ACC_ARCH_C166) #elif (ACC_ARCH_C166)
#if !defined(__MODEL__) #if !defined(__MODEL__)
# error "FIXME - C166 __MODEL__" # error "FIXME - C166 __MODEL__"
@@ -1148,6 +1158,8 @@ extern "C" {
# if (ACC_CC_GNUC >= 0x030300ul) # if (ACC_CC_GNUC >= 0x030300ul)
# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) # if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0)
# define ACC_SIZEOF_LONG_LONG ACC_SIZEOF_LONG # define ACC_SIZEOF_LONG_LONG ACC_SIZEOF_LONG
# elif (__ACC_LSR(__LONG_LONG_MAX__,30) == 1)
# define ACC_SIZEOF_LONG_LONG 4
# endif # endif
# endif # endif
# endif # endif
@@ -1396,6 +1408,7 @@ extern "C" {
# define ACC_INFO_LIBC "default" # define ACC_INFO_LIBC "default"
#endif #endif
#endif #endif
#if !defined(__acc_gnuc_extension__)
#if (ACC_CC_GNUC >= 0x020800ul) #if (ACC_CC_GNUC >= 0x020800ul)
# define __acc_gnuc_extension__ __extension__ # define __acc_gnuc_extension__ __extension__
#elif (ACC_CC_LLVM || ACC_CC_PATHSCALE) #elif (ACC_CC_LLVM || ACC_CC_PATHSCALE)
@@ -1403,6 +1416,7 @@ extern "C" {
#else #else
# define __acc_gnuc_extension__ # define __acc_gnuc_extension__
#endif #endif
#endif
#if !defined(__acc_ua_volatile) #if !defined(__acc_ua_volatile)
# define __acc_ua_volatile volatile # define __acc_ua_volatile volatile
#endif #endif
@@ -1413,6 +1427,8 @@ extern "C" {
# define __acc_alignof(e) __alignof__(e) # define __acc_alignof(e) __alignof__(e)
#elif (ACC_CC_MSC && (_MSC_VER >= 1300)) #elif (ACC_CC_MSC && (_MSC_VER >= 1300))
# define __acc_alignof(e) __alignof(e) # define __acc_alignof(e) __alignof(e)
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
# define __acc_alignof(e) __alignof__(e)
#endif #endif
#endif #endif
#if defined(__acc_alignof) #if defined(__acc_alignof)
@@ -1461,6 +1477,8 @@ extern "C" {
# define __acc_inline __inline # define __acc_inline __inline
#elif (ACC_CC_MSC && (_MSC_VER >= 900)) #elif (ACC_CC_MSC && (_MSC_VER >= 900))
# define __acc_inline __inline # define __acc_inline __inline
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
# define __acc_inline __inline__
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define __acc_inline inline # define __acc_inline inline
#endif #endif
@@ -1481,6 +1499,8 @@ extern "C" {
# define __acc_forceinline __inline__ __attribute__((__always_inline__)) # define __acc_forceinline __inline__ __attribute__((__always_inline__))
#elif (ACC_CC_MSC && (_MSC_VER >= 1200)) #elif (ACC_CC_MSC && (_MSC_VER >= 1200))
# define __acc_forceinline __forceinline # define __acc_forceinline __forceinline
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
# define __acc_forceinline __inline__ __attribute__((__always_inline__))
#endif #endif
#endif #endif
#if defined(__acc_forceinline) #if defined(__acc_forceinline)
@@ -1506,6 +1526,8 @@ extern "C" {
# else # else
# define __acc_noinline __declspec(noinline) # define __acc_noinline __declspec(noinline)
# endif # endif
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
# define __acc_noinline __attribute__((__noinline__))
#endif #endif
#endif #endif
#if defined(__acc_noinline) #if defined(__acc_noinline)
@@ -1707,6 +1729,8 @@ extern "C" {
# else # else
# define __acc_cdecl_sighandler __cdecl # define __acc_cdecl_sighandler __cdecl
# endif # endif
#elif (ACC_ARCH_I386) && (ACC_CC_WATCOMC)
# define __acc_cdecl __cdecl
#elif (ACC_ARCH_M68K && ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC)) #elif (ACC_ARCH_M68K && ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
# define __acc_cdecl cdecl # define __acc_cdecl cdecl
#endif #endif
@@ -1728,6 +1752,7 @@ extern "C" {
#if !defined(__acc_cdecl_va) #if !defined(__acc_cdecl_va)
# define __acc_cdecl_va __acc_cdecl # define __acc_cdecl_va __acc_cdecl
#endif #endif
#if !defined(ACC_CFG_NO_WINDOWS_H)
#if (ACC_OS_CYGWIN || (ACC_OS_EMX && defined(__RSXNT__)) || ACC_OS_WIN32 || ACC_OS_WIN64) #if (ACC_OS_CYGWIN || (ACC_OS_EMX && defined(__RSXNT__)) || ACC_OS_WIN32 || ACC_OS_WIN64)
# if (ACC_CC_WATCOMC && (__WATCOMC__ < 1000)) # if (ACC_CC_WATCOMC && (__WATCOMC__ < 1000))
# elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__) # elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
@@ -1736,6 +1761,7 @@ extern "C" {
# define ACC_HAVE_WINDOWS_H 1 # define ACC_HAVE_WINDOWS_H 1
# endif # endif
#endif #endif
#endif
#if (ACC_ARCH_ALPHA) #if (ACC_ARCH_ALPHA)
# define ACC_OPT_AVOID_UINT_INDEX 1 # define ACC_OPT_AVOID_UINT_INDEX 1
# define ACC_OPT_AVOID_SHORT 1 # define ACC_OPT_AVOID_SHORT 1
@@ -2143,6 +2169,7 @@ extern "C" {
#define HAVE_DIFFTIME 1 #define HAVE_DIFFTIME 1
#define HAVE_FILENO 1 #define HAVE_FILENO 1
#define HAVE_FSTAT 1 #define HAVE_FSTAT 1
#define HAVE_GETENV 1
#define HAVE_GETTIMEOFDAY 1 #define HAVE_GETTIMEOFDAY 1
#define HAVE_GMTIME 1 #define HAVE_GMTIME 1
#define HAVE_ISATTY 1 #define HAVE_ISATTY 1
@@ -2172,7 +2199,7 @@ extern "C" {
#define HAVE_UMASK 1 #define HAVE_UMASK 1
#define HAVE_UTIME 1 #define HAVE_UTIME 1
#define HAVE_VSNPRINTF 1 #define HAVE_VSNPRINTF 1
#if (ACC_OS_BEOS || ACC_OS_CYGWIN || ACC_OS_POSIX || ACC_OS_QNX) #if (ACC_OS_BEOS || ACC_OS_CYGWIN || ACC_OS_POSIX || ACC_OS_QNX || ACC_OS_VMS)
# define HAVE_STRCASECMP 1 # define HAVE_STRCASECMP 1
# define HAVE_STRNCASECMP 1 # define HAVE_STRNCASECMP 1
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__) #elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
@@ -2285,7 +2312,7 @@ extern "C" {
# if (_MSC_VER < 700) # if (_MSC_VER < 700)
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF # undef HAVE_VSNPRINTF
# else # elif (_MSC_VER < 1500)
# define snprintf _snprintf # define snprintf _snprintf
# define vsnprintf _vsnprintf # define vsnprintf _vsnprintf
# endif # endif
@@ -2609,7 +2636,7 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
# define acc_intptr_t acc_intptr_t # define acc_intptr_t acc_intptr_t
# define acc_uintptr_t acc_uintptr_t # define acc_uintptr_t acc_uintptr_t
# define ACC_SIZEOF_ACC_INTPTR_T ACC_SIZEOF_VOID_P # define ACC_SIZEOF_ACC_INTPTR_T ACC_SIZEOF_VOID_P
#elif (ACC_ARCH_I386 && ACC_CC_MSC && (_MSC_VER >= 1300)) #elif (ACC_CC_MSC && (_MSC_VER >= 1300) && (ACC_SIZEOF_VOID_P == 4) && (ACC_SIZEOF_INT == 4))
typedef __w64 int acc_intptr_t; typedef __w64 int acc_intptr_t;
typedef __w64 unsigned int acc_uintptr_t; typedef __w64 unsigned int acc_uintptr_t;
# define acc_intptr_t acc_intptr_t # define acc_intptr_t acc_intptr_t
@@ -2704,6 +2731,9 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
# elif (ACC_SIZEOF_LONG >= 4) # elif (ACC_SIZEOF_LONG >= 4)
# define ACC_INT32_C(c) c##L # define ACC_INT32_C(c) c##L
# define ACC_UINT32_C(c) c##UL # define ACC_UINT32_C(c) c##UL
# elif (ACC_SIZEOF_LONG_LONG >= 4)
# define ACC_INT32_C(c) c##LL
# define ACC_UINT32_C(c) c##ULL
# else # else
# error "ACC_INT32_C" # error "ACC_INT32_C"
# endif # endif
@@ -2791,7 +2821,7 @@ typedef void (__acc_cdecl_sighandler *acc_sighandler_t)(acc_signo_t);
#endif #endif
#if (ACC_OPT_UNALIGNED16) && defined(acc_int16e_t) #if (ACC_OPT_UNALIGNED16) && defined(acc_int16e_t)
#define ACC_UA_GET16(p) (* (__acc_ua_volatile const acc_uint16e_t*) (__acc_ua_volatile const void*) (p)) #define ACC_UA_GET16(p) (* (__acc_ua_volatile const acc_uint16e_t*) (__acc_ua_volatile const void*) (p))
#define ACC_UA_SET16(p,v) (* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p) = (acc_uint16e_t) (v)) #define ACC_UA_SET16(p,v) ((* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint16e_t) (v))
#if (ACC_ABI_BIG_ENDIAN) #if (ACC_ABI_BIG_ENDIAN)
# define ACC_UA_GET_BE16(p) ACC_UA_GET16(p) # define ACC_UA_GET_BE16(p) ACC_UA_GET16(p)
# define ACC_UA_SET_BE16(p,v) ACC_UA_SET16(p,v) # define ACC_UA_SET_BE16(p,v) ACC_UA_SET16(p,v)
@@ -2799,7 +2829,7 @@ typedef void (__acc_cdecl_sighandler *acc_sighandler_t)(acc_signo_t);
# define ACC_UA_GET_LE16(p) ACC_UA_GET16(p) # define ACC_UA_GET_LE16(p) ACC_UA_GET16(p)
# define ACC_UA_SET_LE16(p,v) ACC_UA_SET16(p,v) # define ACC_UA_SET_LE16(p,v) ACC_UA_SET16(p,v)
#endif #endif
#if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_forceinline) #if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_HAVE_forceinline)
#if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC) #if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC)
#if !defined(ACC_UA_GET_LE16) #if !defined(ACC_UA_GET_LE16)
extern __acc_forceinline unsigned long __ACC_UA_GET_LE16(__acc_ua_volatile const void* pp); extern __acc_forceinline unsigned long __ACC_UA_GET_LE16(__acc_ua_volatile const void* pp);
@@ -2827,7 +2857,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE16(__acc_ua_volatile void* pp, unsi
#endif #endif
#if (ACC_OPT_UNALIGNED32) && defined(acc_int32e_t) #if (ACC_OPT_UNALIGNED32) && defined(acc_int32e_t)
#define ACC_UA_GET32(p) (* (__acc_ua_volatile const acc_uint32e_t*) (__acc_ua_volatile const void*) (p)) #define ACC_UA_GET32(p) (* (__acc_ua_volatile const acc_uint32e_t*) (__acc_ua_volatile const void*) (p))
#define ACC_UA_SET32(p,v) (* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p) = (acc_uint32e_t) (v)) #define ACC_UA_SET32(p,v) ((* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint32e_t) (v))
#if (ACC_ABI_BIG_ENDIAN) #if (ACC_ABI_BIG_ENDIAN)
# define ACC_UA_GET_BE32(p) ACC_UA_GET32(p) # define ACC_UA_GET_BE32(p) ACC_UA_GET32(p)
# define ACC_UA_SET_BE32(p,v) ACC_UA_SET32(p,v) # define ACC_UA_SET_BE32(p,v) ACC_UA_SET32(p,v)
@@ -2835,7 +2865,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE16(__acc_ua_volatile void* pp, unsi
# define ACC_UA_GET_LE32(p) ACC_UA_GET32(p) # define ACC_UA_GET_LE32(p) ACC_UA_GET32(p)
# define ACC_UA_SET_LE32(p,v) ACC_UA_SET32(p,v) # define ACC_UA_SET_LE32(p,v) ACC_UA_SET32(p,v)
#endif #endif
#if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_forceinline) #if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_HAVE_forceinline)
#if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC) #if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC)
#if !defined(ACC_UA_GET_LE32) #if !defined(ACC_UA_GET_LE32)
extern __acc_forceinline unsigned long __ACC_UA_GET_LE32(__acc_ua_volatile const void* pp); extern __acc_forceinline unsigned long __ACC_UA_GET_LE32(__acc_ua_volatile const void* pp);
@@ -2863,7 +2893,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE32(__acc_ua_volatile void* pp, unsi
#endif #endif
#if (ACC_OPT_UNALIGNED64) && defined(acc_int64l_t) #if (ACC_OPT_UNALIGNED64) && defined(acc_int64l_t)
#define ACC_UA_GET64(p) (* (__acc_ua_volatile const acc_uint64l_t*) (__acc_ua_volatile const void*) (p)) #define ACC_UA_GET64(p) (* (__acc_ua_volatile const acc_uint64l_t*) (__acc_ua_volatile const void*) (p))
#define ACC_UA_SET64(p,v) (* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p) = (acc_uint64l_t) (v)) #define ACC_UA_SET64(p,v) ((* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p)) = (acc_uint64l_t) (v))
#if (ACC_ABI_BIG_ENDIAN) #if (ACC_ABI_BIG_ENDIAN)
# define ACC_UA_GET_BE64(p) ACC_UA_GET64(p) # define ACC_UA_GET_BE64(p) ACC_UA_GET64(p)
# define ACC_UA_SET_BE64(p,v) ACC_UA_SET64(p,v) # define ACC_UA_SET_BE64(p,v) ACC_UA_SET64(p,v)
@@ -3034,7 +3064,7 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
# define acc_intptr_t acc_intptr_t # define acc_intptr_t acc_intptr_t
# define acc_uintptr_t acc_uintptr_t # define acc_uintptr_t acc_uintptr_t
# define ACC_SIZEOF_ACC_INTPTR_T ACC_SIZEOF_VOID_P # define ACC_SIZEOF_ACC_INTPTR_T ACC_SIZEOF_VOID_P
#elif (ACC_ARCH_I386 && ACC_CC_MSC && (_MSC_VER >= 1300)) #elif (ACC_CC_MSC && (_MSC_VER >= 1300) && (ACC_SIZEOF_VOID_P == 4) && (ACC_SIZEOF_INT == 4))
typedef __w64 int acc_intptr_t; typedef __w64 int acc_intptr_t;
typedef __w64 unsigned int acc_uintptr_t; typedef __w64 unsigned int acc_uintptr_t;
# define acc_intptr_t acc_intptr_t # define acc_intptr_t acc_intptr_t
@@ -3129,6 +3159,9 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
# elif (ACC_SIZEOF_LONG >= 4) # elif (ACC_SIZEOF_LONG >= 4)
# define ACC_INT32_C(c) c##L # define ACC_INT32_C(c) c##L
# define ACC_UINT32_C(c) c##UL # define ACC_UINT32_C(c) c##UL
# elif (ACC_SIZEOF_LONG_LONG >= 4)
# define ACC_INT32_C(c) c##LL
# define ACC_UINT32_C(c) c##ULL
# else # else
# error "ACC_INT32_C" # error "ACC_INT32_C"
# endif # endif
@@ -3215,7 +3248,7 @@ typedef void (__acc_cdecl_sighandler *acc_sighandler_t)(acc_signo_t);
#endif #endif
#if (ACC_OPT_UNALIGNED16) && defined(acc_int16e_t) #if (ACC_OPT_UNALIGNED16) && defined(acc_int16e_t)
#define ACC_UA_GET16(p) (* (__acc_ua_volatile const acc_uint16e_t*) (__acc_ua_volatile const void*) (p)) #define ACC_UA_GET16(p) (* (__acc_ua_volatile const acc_uint16e_t*) (__acc_ua_volatile const void*) (p))
#define ACC_UA_SET16(p,v) (* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p) = (acc_uint16e_t) (v)) #define ACC_UA_SET16(p,v) ((* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint16e_t) (v))
#if (ACC_ABI_BIG_ENDIAN) #if (ACC_ABI_BIG_ENDIAN)
# define ACC_UA_GET_BE16(p) ACC_UA_GET16(p) # define ACC_UA_GET_BE16(p) ACC_UA_GET16(p)
# define ACC_UA_SET_BE16(p,v) ACC_UA_SET16(p,v) # define ACC_UA_SET_BE16(p,v) ACC_UA_SET16(p,v)
@@ -3223,7 +3256,7 @@ typedef void (__acc_cdecl_sighandler *acc_sighandler_t)(acc_signo_t);
# define ACC_UA_GET_LE16(p) ACC_UA_GET16(p) # define ACC_UA_GET_LE16(p) ACC_UA_GET16(p)
# define ACC_UA_SET_LE16(p,v) ACC_UA_SET16(p,v) # define ACC_UA_SET_LE16(p,v) ACC_UA_SET16(p,v)
#endif #endif
#if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_forceinline) #if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_HAVE_forceinline)
#if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC) #if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC)
#if !defined(ACC_UA_GET_LE16) #if !defined(ACC_UA_GET_LE16)
extern __acc_forceinline unsigned long __ACC_UA_GET_LE16(__acc_ua_volatile const void* pp); extern __acc_forceinline unsigned long __ACC_UA_GET_LE16(__acc_ua_volatile const void* pp);
@@ -3251,7 +3284,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE16(__acc_ua_volatile void* pp, unsi
#endif #endif
#if (ACC_OPT_UNALIGNED32) && defined(acc_int32e_t) #if (ACC_OPT_UNALIGNED32) && defined(acc_int32e_t)
#define ACC_UA_GET32(p) (* (__acc_ua_volatile const acc_uint32e_t*) (__acc_ua_volatile const void*) (p)) #define ACC_UA_GET32(p) (* (__acc_ua_volatile const acc_uint32e_t*) (__acc_ua_volatile const void*) (p))
#define ACC_UA_SET32(p,v) (* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p) = (acc_uint32e_t) (v)) #define ACC_UA_SET32(p,v) ((* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint32e_t) (v))
#if (ACC_ABI_BIG_ENDIAN) #if (ACC_ABI_BIG_ENDIAN)
# define ACC_UA_GET_BE32(p) ACC_UA_GET32(p) # define ACC_UA_GET_BE32(p) ACC_UA_GET32(p)
# define ACC_UA_SET_BE32(p,v) ACC_UA_SET32(p,v) # define ACC_UA_SET_BE32(p,v) ACC_UA_SET32(p,v)
@@ -3259,7 +3292,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE16(__acc_ua_volatile void* pp, unsi
# define ACC_UA_GET_LE32(p) ACC_UA_GET32(p) # define ACC_UA_GET_LE32(p) ACC_UA_GET32(p)
# define ACC_UA_SET_LE32(p,v) ACC_UA_SET32(p,v) # define ACC_UA_SET_LE32(p,v) ACC_UA_SET32(p,v)
#endif #endif
#if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_forceinline) #if !defined(ACC_CFG_NO_INLINE_ASM) && defined(__acc_HAVE_forceinline)
#if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC) #if (ACC_ARCH_POWERPC && ACC_ABI_BIG_ENDIAN) && (ACC_CC_GNUC)
#if !defined(ACC_UA_GET_LE32) #if !defined(ACC_UA_GET_LE32)
extern __acc_forceinline unsigned long __ACC_UA_GET_LE32(__acc_ua_volatile const void* pp); extern __acc_forceinline unsigned long __ACC_UA_GET_LE32(__acc_ua_volatile const void* pp);
@@ -3287,7 +3320,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE32(__acc_ua_volatile void* pp, unsi
#endif #endif
#if (ACC_OPT_UNALIGNED64) && defined(acc_int64l_t) #if (ACC_OPT_UNALIGNED64) && defined(acc_int64l_t)
#define ACC_UA_GET64(p) (* (__acc_ua_volatile const acc_uint64l_t*) (__acc_ua_volatile const void*) (p)) #define ACC_UA_GET64(p) (* (__acc_ua_volatile const acc_uint64l_t*) (__acc_ua_volatile const void*) (p))
#define ACC_UA_SET64(p,v) (* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p) = (acc_uint64l_t) (v)) #define ACC_UA_SET64(p,v) ((* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p)) = (acc_uint64l_t) (v))
#if (ACC_ABI_BIG_ENDIAN) #if (ACC_ABI_BIG_ENDIAN)
# define ACC_UA_GET_BE64(p) ACC_UA_GET64(p) # define ACC_UA_GET_BE64(p) ACC_UA_GET64(p)
# define ACC_UA_SET_BE64(p,v) ACC_UA_SET64(p,v) # define ACC_UA_SET_BE64(p,v) ACC_UA_SET64(p,v)
@@ -3835,6 +3868,7 @@ ACCLIB_EXTERN(int, acc_closedir) (acc_dir_p);
# define acc_stackavail() _chkstack() # define acc_stackavail() _chkstack()
#endif #endif
ACCLIB_EXTERN(acclib_handle_t, acc_get_osfhandle) (int); ACCLIB_EXTERN(acclib_handle_t, acc_get_osfhandle) (int);
ACCLIB_EXTERN(const char *, acc_getenv) (const char *);
ACCLIB_EXTERN(int, acc_isatty) (int); ACCLIB_EXTERN(int, acc_isatty) (int);
ACCLIB_EXTERN(int, acc_mkdir) (const char*, unsigned); ACCLIB_EXTERN(int, acc_mkdir) (const char*, unsigned);
ACCLIB_EXTERN(int, acc_rmdir) (const char*); ACCLIB_EXTERN(int, acc_rmdir) (const char*);
@@ -3849,7 +3883,8 @@ ACCLIB_EXTERN_NOINLINE(void, acc_debug_break) (void);
ACCLIB_EXTERN_NOINLINE(void, acc_debug_nop) (void); ACCLIB_EXTERN_NOINLINE(void, acc_debug_nop) (void);
ACCLIB_EXTERN_NOINLINE(int, acc_debug_align_check_query) (void); ACCLIB_EXTERN_NOINLINE(int, acc_debug_align_check_query) (void);
ACCLIB_EXTERN_NOINLINE(int, acc_debug_align_check_enable) (int); ACCLIB_EXTERN_NOINLINE(int, acc_debug_align_check_enable) (int);
ACCLIB_EXTERN_NOINLINE(int, acc_debug_running_on_valgrind) (void); ACCLIB_EXTERN_NOINLINE(unsigned, acc_debug_running_on_qemu) (void);
ACCLIB_EXTERN_NOINLINE(unsigned, acc_debug_running_on_valgrind) (void);
#if !defined(acc_int64l_t) || defined(ACC_CFG_NO_DOUBLE) #if !defined(acc_int64l_t) || defined(ACC_CFG_NO_DOUBLE)
# undef __ACCLIB_PCLOCK_USE_RDTSC # undef __ACCLIB_PCLOCK_USE_RDTSC
# undef __ACCLIB_PCLOCK_USE_PERFCTR # undef __ACCLIB_PCLOCK_USE_PERFCTR
@@ -4603,10 +4638,6 @@ ACCLIB_EXTERN(int, acc_spawnve) (int mode, const char* fn, const char* const * a
ACCCHK_ASSERT(sizeof(size_t) == 4) ACCCHK_ASSERT(sizeof(size_t) == 4)
ACCCHK_ASSERT(sizeof(ptrdiff_t) == 4) ACCCHK_ASSERT(sizeof(ptrdiff_t) == 4)
ACCCHK_ASSERT(sizeof(acc_intptr_t) == sizeof(void *)) ACCCHK_ASSERT(sizeof(acc_intptr_t) == sizeof(void *))
#elif (ACC_ARCH_AMD64)
ACCCHK_ASSERT(sizeof(size_t) == 8)
ACCCHK_ASSERT(sizeof(ptrdiff_t) == 8)
ACCCHK_ASSERT(sizeof(acc_intptr_t) == sizeof(void *))
#endif #endif
#if (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_WIN32) #if (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_WIN32)
ACCCHK_ASSERT(sizeof(size_t) == 4) ACCCHK_ASSERT(sizeof(size_t) == 4)
@@ -5277,213 +5308,6 @@ ACCLIB_PUBLIC(int, acc_dos_free) (void __far* p)
} }
#endif #endif
#endif #endif
#if defined(ACC_WANT_ACCLIB_GETOPT)
# undef ACC_WANT_ACCLIB_GETOPT
#define __ACCLIB_GETOPT_CH_INCLUDED 1
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
ACCLIB_PUBLIC(void, acc_getopt_init) (acc_getopt_p g,
int start_argc, int argc, char** argv)
{
memset(g, 0, sizeof(*g));
g->argc = argc;
g->argv = argv;
g->pending_rotate_first = g->pending_rotate_middle = g->optind = start_argc;
}
static int __ACCLIB_FUNCNAME(acc_getopt_rotate) (char **p, int first, int middle, int last)
{
char** a; char** b;
if (first >= middle || middle >= last) return 0;
for (a = p + first, b = p + middle - 1; a < b; ++a, --b) {
char* t = *a; *a = *b; *b = t;
}
for (a = p + middle, b = p + last - 1; a < b; ++a, --b) {
char* t = *a; *a = *b; *b = t;
}
for (a = p + first, b = p + last - 1; a < b; ++a, --b) {
char* t = *a; *a = *b; *b = t;
}
return middle - first;
}
static int __acc_getopt_x(acc_getopt_p g, int ret, int oo, int flags, const char *f, ...)
{
if (oo >= 0)
g->optopt = oo;
if (flags & 1)
{
if (g->shortpos == 0)
g->optind++;
else if (!g->argv[g->optind][++g->shortpos])
g->optind++, g->shortpos = 0;
}
if (f == NULL)
return ret;
if (g->opterr)
{
#if !defined(HAVE_STDARG_H)
g->opterr(g, f, NULL);
#else
va_list ap;
va_start(ap, f);
g->opterr(g, f, &ap);
va_end(ap);
#endif
}
g->errcount++;
return ret;
}
ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g,
const char* shortopts,
const acc_getopt_longopt_p longopts,
int* longind)
{
int ordering = ACC_GETOPT_PERMUTE;
char *a;
int has_arg = 0;
char *arg;
unsigned char sc;
int i;
if (shortopts && (*shortopts == '-' || *shortopts == '+'))
ordering = *shortopts++ == '-' ? ACC_GETOPT_RETURN_IN_ORDER : ACC_GETOPT_REQUIRE_ORDER;
g->optarg = NULL;
g->optopt = '?';
if (longind != NULL)
*longind = -1;
if (g->eof || g->optind >= g->argc || g->argv == NULL)
goto acc_label_eof;
if (g->shortpos)
goto acc_label_next_shortopt;
g->optind -= __ACCLIB_FUNCNAME(acc_getopt_rotate)(g->argv, g->pending_rotate_first, g->pending_rotate_middle, g->optind);
g->pending_rotate_first = g->pending_rotate_middle = g->optind;
if (ordering == ACC_GETOPT_PERMUTE)
{
while (g->optind < g->argc && !(g->argv[g->optind][0] == '-' && g->argv[g->optind][1]))
g->optind++;
g->pending_rotate_middle = g->optind;
}
if (g->optind >= g->argc)
{
g->optind = g->pending_rotate_first;
acc_label_eof:
g->optind -= __ACCLIB_FUNCNAME(acc_getopt_rotate)(g->argv, g->pending_rotate_first, g->pending_rotate_middle, g->optind);
g->pending_rotate_first = g->pending_rotate_middle = g->optind;
g->eof = 1;
return -1;
}
a = g->argv[g->optind];
if (strcmp(a, "--") == 0)
{
g->optind++;
goto acc_label_eof;
}
if (!(a[0] == '-' && a[1]))
{
if (ordering == ACC_GETOPT_REQUIRE_ORDER)
goto acc_label_eof;
if (ordering == ACC_GETOPT_RETURN_IN_ORDER)
{
g->optarg = a;
g->optind++;
return 1;
}
__acc_getopt_x(g, -1, -1, 0, "invalid ordering %d", ordering);
goto acc_label_eof;
}
if (a[1] == '-')
{
const acc_getopt_longopt_p lo = NULL;
size_t match_chars;
for (arg = a + 2; *arg && *arg != '=' && *arg != '#'; )
++arg;
match_chars = (size_t) (arg - (a + 2));
for (i = 0; longopts && longopts[i].name; ++i)
{
size_t n = match_chars;
size_t l = strlen(longopts[i].name);
if (longopts[i].has_arg & ACC_GETOPT_EXACT_ARG) n = l;
if (strncmp(a, longopts[i].name, n) != 0)
continue;
if (match_chars == l)
{
lo = &longopts[i];
break;
}
else if (lo == NULL)
lo = &longopts[i];
else
return __acc_getopt_x(g, '?', 0, 1, "option '%s' is ambiguous (could be '--%s' or '--%s')",
a, lo->name, longopts[i].name);
}
if (lo == NULL)
return __acc_getopt_x(g, '?', 0, 1, "unrecognized option '%s'", a);
switch (lo->has_arg & 0x2f)
{
case ACC_GETOPT_OPTIONAL_ARG:
break;
case ACC_GETOPT_REQUIRED_ARG:
if (*arg)
g->optarg = arg + 1;
else if (g->optind + 1 < g->argc)
g->optarg = g->argv[++g->optind];
else
return __acc_getopt_x(g, '?', 0, 1, "option '%s' requires an argument", lo->name);
g->optind++;
break;
case ACC_GETOPT_REQUIRED_ARG | 0x20:
break;
default:
if (*arg)
return __acc_getopt_x(g, '?', lo->val, 1, "option '%s' doesn't allow an argument", lo->name);
g->optind++;
break;
}
if (longind != NULL)
*longind = (int) (lo - longopts);
if (lo->flag != NULL)
{
*lo->flag = lo->val;
return 0;
}
return lo->val;
}
else
{
const char *sp;
g->shortpos = 1;
acc_label_next_shortopt:
a = g->argv[g->optind] + g->shortpos;
sp = NULL; sc = (unsigned char) *a;
if (shortopts)
sp = strchr(shortopts, sc);
if (!sp)
return __acc_getopt_x(g, '?', sc, 1, "invalid option '-%c'", sc);
if (sp[1] == ':') { has_arg++; if (sp[2] == ':') has_arg++; }
arg = a + 1;
switch (has_arg)
{
case ACC_GETOPT_OPTIONAL_ARG:
if (*arg)
g->optarg = arg + 1;
g->optind++, g->shortpos = 0;
break;
case ACC_GETOPT_REQUIRED_ARG:
if (*arg)
g->optarg = arg + 1;
else if (g->optind + 1 < g->argc)
g->optarg = g->argv[++g->optind];
else
return __acc_getopt_x(g, '?', 0, 1, "option '-%c' requires an argument", sc);
g->optind++, g->shortpos = 0;
break;
default:
__acc_getopt_x(g, 0, -1, 1, NULL);
break;
}
return sc;
}
}
#endif
#if defined(ACC_WANT_ACCLIB_HALLOC) #if defined(ACC_WANT_ACCLIB_HALLOC)
# undef ACC_WANT_ACCLIB_HALLOC # undef ACC_WANT_ACCLIB_HALLOC
#define __ACCLIB_HALLOC_CH_INCLUDED 1 #define __ACCLIB_HALLOC_CH_INCLUDED 1
@@ -6374,6 +6198,18 @@ ACCLIB_PUBLIC(int, acc_uclock_flush_cpu_cache) (acc_uclock_handle_p h, unsigned
# define ACCLIB_PUBLIC_NOINLINE(r,f) __acc_noinline r __ACCLIB_FUNCNAME(f) # define ACCLIB_PUBLIC_NOINLINE(r,f) __acc_noinline r __ACCLIB_FUNCNAME(f)
# endif # endif
#endif #endif
#if (ACC_OS_WIN32 && ACC_CC_PELLESC && (__POCC__ >= 290))
# pragma warn(push)
# pragma warn(disable:2007)
#endif
ACCLIB_PUBLIC(const char *, acc_getenv) (const char *s)
{
#if defined(HAVE_GETENV)
return getenv(s);
#else
ACC_UNUSED(s); return (const char *) 0;
#endif
}
ACCLIB_PUBLIC(acclib_handle_t, acc_get_osfhandle) (int fd) ACCLIB_PUBLIC(acclib_handle_t, acc_get_osfhandle) (int fd)
{ {
if (fd < 0) if (fd < 0)
@@ -6561,9 +6397,10 @@ ACCLIB_PUBLIC(acc_uint32e_t, acc_muldiv32u) (acc_uint32e_t a, acc_uint32e_t b, a
return r; return r;
} }
#endif #endif
#if (ACC_OS_WIN32 && ACC_CC_PELLESC && (__POCC__ >= 290)) #if 0
# pragma warn(push) ACCLIB_PUBLIC_NOINLINE(int, acc_syscall_clock_gettime) (int c)
# pragma warn(disable:2007) {
}
#endif #endif
#if (ACC_OS_WIN16) #if (ACC_OS_WIN16)
ACC_EXTERN_C void __far __pascal DebugBreak(void); ACC_EXTERN_C void __far __pascal DebugBreak(void);
@@ -6593,11 +6430,11 @@ ACCLIB_PUBLIC_NOINLINE(void, acc_debug_nop) (void)
ACCLIB_PUBLIC_NOINLINE(int, acc_debug_align_check_query) (void) ACCLIB_PUBLIC_NOINLINE(int, acc_debug_align_check_query) (void)
{ {
#if (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_ASM_SYNTAX_GNUC) #if (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_ASM_SYNTAX_GNUC)
long r; size_t r;
__asm__ __volatile__("pushf\n pop %0\n" : "=a" (r) : : __ACC_ASM_CLOBBER); __asm__ __volatile__("pushf\n pop %0\n" : "=a" (r) : : __ACC_ASM_CLOBBER);
return (int)(r >> 18) & 1; return (int)(r >> 18) & 1;
#elif (ACC_ARCH_I386) && (ACC_ASM_SYNTAX_MSC) #elif (ACC_ARCH_I386) && (ACC_ASM_SYNTAX_MSC)
long r; unsigned long r;
__asm { __asm {
pushf pushf
pop eax pop eax
@@ -6641,13 +6478,27 @@ ACCLIB_PUBLIC_NOINLINE(int, acc_debug_align_check_enable) (int v)
#endif #endif
ACC_UNUSED(v); return r; ACC_UNUSED(v); return r;
} }
ACCLIB_PUBLIC_NOINLINE(int, acc_debug_running_on_valgrind) (void) ACCLIB_PUBLIC_NOINLINE(unsigned, acc_debug_running_on_qemu) (void)
{
unsigned r = 0;
#if (ACC_OS_POSIX_LINUX || ACC_OS_WIN32 || ACC_OS_WIN64)
const char* p;
p = acc_getenv("ACC_ENV_RUNNING_ON_QEMU");
if (p) {
if (p[0] == 0) r = 0;
else if ((p[0] >= '0' && p[0] <= '9') && p[1] == 0) r = p[0] - '0';
else r = 1;
}
#endif
return r;
}
ACCLIB_PUBLIC_NOINLINE(unsigned, acc_debug_running_on_valgrind) (void)
{ {
#if (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_ASM_SYNTAX_GNUC) #if (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_ASM_SYNTAX_GNUC)
volatile unsigned long args[5] = { 0x1001, 0, 0, 0, 0 }; volatile unsigned long args[5] = { 0x1001, 0, 0, 0, 0 };
long r = 0; unsigned long r = 0;
__asm__ __volatile__(".byte 0xc1,0xc0,0x1d,0xc1,0xc0,0x03,0xc1,0xc8,0x1b,0xc1,0xc8,0x05,0xc1,0xc0,0x0d,0xc1,0xc0,0x13\n" : "=d" (r) : "a" (&args[0]), "d" (r) : __ACC_ASM_CLOBBER); __asm__ __volatile__(".byte 0xc1,0xc0,0x1d,0xc1,0xc0,0x03,0xc1,0xc8,0x1b,0xc1,0xc8,0x05,0xc1,0xc0,0x0d,0xc1,0xc0,0x13\n" : "=d" (r) : "a" (&args[0]), "d" (r) : __ACC_ASM_CLOBBER);
return (int) r; return (unsigned) r;
#else #else
return 0; return 0;
#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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+12 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -45,6 +45,11 @@ enum {
struct options_t { struct options_t {
int cmd; int cmd;
// mp (meta) options
int mp_compress_task;
bool mp_query_format;
bool mp_query_num_tasks;
// compression options // compression options
int method; int method;
bool method_lzma_seen; bool method_lzma_seen;
@@ -69,6 +74,9 @@ struct options_t {
bool no_env; bool no_env;
bool no_progress; bool no_progress;
const char *output_name; const char *output_name;
bool preserve_mode;
bool preserve_ownership;
bool preserve_timestamp;
int small; int small;
int verbose; int verbose;
bool to_stdout; bool to_stdout;
@@ -126,7 +134,7 @@ struct options_t {
bool boot_only; bool boot_only;
bool no_align; bool no_align;
bool do_8bit; bool do_8bit;
bool do_8mb; bool do_8mib;
} ps1_exe; } ps1_exe;
struct { struct {
unsigned blocksize; unsigned blocksize;
+15 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -148,14 +148,12 @@ Linker* PackArmPe::newLinker() const
// import handling // import handling
**************************************************************************/ **************************************************************************/
struct import_desc __packed_struct(import_desc)
{
LE32 oft; // orig first thunk LE32 oft; // orig first thunk
char _[8]; char _[8];
LE32 dllname; LE32 dllname;
LE32 iat; // import address table LE32 iat; // import address table
} __packed_struct_end()
__attribute_packed;
void PackArmPe::processImports(unsigned myimport, unsigned iat_off) // pass 2 void PackArmPe::processImports(unsigned myimport, unsigned iat_off) // pass 2
{ {
@@ -507,6 +505,10 @@ void PackArmPe::buildLoader(const Filter *ft)
void PackArmPe::pack(OutputFile *fo) void PackArmPe::pack(OutputFile *fo)
{ {
// FIXME: we need to think about better support for --exact
if (opt->exact)
throwCantPackExact();
const unsigned objs = ih.objects; const unsigned objs = ih.objects;
isection = new pe_section_t[objs]; isection = new pe_section_t[objs];
fi->seek(pe_offset+sizeof(ih),SEEK_SET); fi->seek(pe_offset+sizeof(ih),SEEK_SET);
@@ -542,10 +544,12 @@ void PackArmPe::pack(OutputFile *fo)
else if (opt->win32_pe.strip_relocs < 0) else if (opt->win32_pe.strip_relocs < 0)
opt->win32_pe.strip_relocs = (ih.imagebase >= 0x10000); opt->win32_pe.strip_relocs = (ih.imagebase >= 0x10000);
if (opt->win32_pe.strip_relocs) if (opt->win32_pe.strip_relocs)
{
if (ih.imagebase < 0x10000) if (ih.imagebase < 0x10000)
throwCantPack("--strip-relocs is not allowed when imagebase < 0x10000"); throwCantPack("--strip-relocs is not allowed when imagebase < 0x10000");
else else
ih.flags |= RELOCS_STRIPPED; ih.flags |= RELOCS_STRIPPED;
}
if (memcmp(isection[0].name,"UPX",3) == 0) if (memcmp(isection[0].name,"UPX",3) == 0)
throwAlreadyPackedByUPX(); throwAlreadyPackedByUPX();
@@ -708,7 +712,7 @@ void PackArmPe::pack(OutputFile *fo)
// limit stack size needed for runtime decompression // limit stack size needed for runtime decompression
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 2048, &cconf, filter_strategy, compressWithFilters(&ft, 2048, &cconf, filter_strategy,
ih.codebase, rvamin, 0, NULL, 0); ih.codebase, rvamin, 0, NULL, 0);
// info: see buildLoader() // info: see buildLoader()
@@ -882,6 +886,8 @@ void PackArmPe::pack(OutputFile *fo)
oh.codesize = osection[1].vsize; oh.codesize = osection[1].vsize;
oh.codebase = osection[1].vaddr; oh.codebase = osection[1].vaddr;
oh.headersize = osection[1].rawdataptr; oh.headersize = osection[1].rawdataptr;
if (rvamin < osection[0].rawdataptr)
throwCantPack("object alignment too small");
if (opt->win32_pe.strip_relocs && !isdll) if (opt->win32_pe.strip_relocs && !isdll)
oh.flags |= RELOCS_STRIPPED; oh.flags |= RELOCS_STRIPPED;
@@ -890,7 +896,7 @@ void PackArmPe::pack(OutputFile *fo)
// set_le32(ibuf + ic,get_le32("UPX ")); // set_le32(ibuf + ic,get_le32("UPX "));
ibuf.clear(0, oh.filealign); ibuf.clear(0, oh.filealign);
info("Image size change: %u -> %u kBytes", info("Image size change: %u -> %u KiB",
ih.imagesize / 1024, oh.imagesize / 1024); ih.imagesize / 1024, oh.imagesize / 1024);
infoHeader("[Writing compressed file]"); infoHeader("[Writing compressed file]");
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+5 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -42,7 +42,8 @@ public:
virtual int getVersion() const { return 13; } virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_DOS_COM; } virtual int getFormat() const { return UPX_F_DOS_COM; }
virtual const char *getName() const { return "dos/com"; } virtual const char *getName() const { return "dos/com"; }
virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.com" : "i286-dos16.com"; } //virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.com" : "i286-dos16.com"; }
virtual const char *getFullName(const options_t *) const { return "i086-dos16.com"; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const; virtual const int *getFilters() const;
+6 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -76,10 +76,11 @@ const int *PackDjgpp2::getFilters() const
unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf, unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf,
const upx_bytep tbuf,
unsigned range, unsigned range,
unsigned upper_limit) const unsigned upper_limit) const
{ {
unsigned o = super::findOverlapOverhead(buf, range, upper_limit); unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
o = (o + 0x3ff) &~ 0x1ff; o = (o + 0x3ff) &~ 0x1ff;
return o; return o;
} }
@@ -302,7 +303,7 @@ void PackDjgpp2::pack(OutputFile *fo)
// compress // compress
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression // limit stack size needed for runtime decompression
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 512, &cconf); compressWithFilters(&ft, 512, &cconf);
// patch coff header #2 // patch coff header #2
+9 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -43,7 +43,7 @@ public:
virtual int getVersion() const { return 14; } virtual int getVersion() const { return 14; }
virtual int getFormat() const { return UPX_F_DJGPP2_COFF; } virtual int getFormat() const { return UPX_F_DJGPP2_COFF; }
virtual const char *getName() const { return "djgpp2/coff"; } virtual const char *getName() const { return "djgpp2/coff"; }
virtual const char *getFullName(const options_t *) const { return "i386-dos32.djgpp2"; } virtual const char *getFullName(const options_t *) const { return "i386-dos32.djgpp2.coff"; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const; virtual const int *getFilters() const;
@@ -58,6 +58,7 @@ protected:
virtual int readFileHeader(); virtual int readFileHeader();
virtual unsigned findOverlapOverhead(const upx_bytep buf, virtual unsigned findOverlapOverhead(const upx_bytep buf,
const upx_bytep tbuf,
unsigned range = 0, unsigned range = 0,
unsigned upper_limit = ~0u) const; unsigned upper_limit = ~0u) const;
virtual void buildLoader(const Filter *ft); virtual void buildLoader(const Filter *ft);
@@ -65,19 +66,16 @@ protected:
long coff_offset; long coff_offset;
struct external_scnhdr_t __packed_struct(external_scnhdr_t)
{
char _[12]; // name, paddr char _[12]; // name, paddr
LE32 vaddr; LE32 vaddr;
LE32 size; LE32 size;
LE32 scnptr; LE32 scnptr;
char misc[12]; // relptr, lnnoptr, nreloc, nlnno char misc[12]; // relptr, lnnoptr, nreloc, nlnno
char __[4]; // flags char __[4]; // flags
} __packed_struct_end()
__attribute_packed;
struct coff_header_t __packed_struct(coff_header_t)
{
// ext_file_hdr // ext_file_hdr
LE16 f_magic; LE16 f_magic;
LE16 f_nscns; LE16 f_nscns;
@@ -98,8 +96,7 @@ protected:
// section headers // section headers
external_scnhdr_t sh[3]; external_scnhdr_t sh[3];
} __packed_struct_end()
__attribute_packed;
coff_header_t coff_hdr; coff_header_t coff_hdr;
external_scnhdr_t *text,*data,*bss; external_scnhdr_t *text,*data,*bss;
+31 -49
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -52,8 +52,7 @@ struct ElfITypes
// The ELF file header. This appears at the start of every ELF file. // The ELF file header. This appears at the start of every ELF file.
template <class TElfITypes> template <class TElfITypes>
struct Ehdr __packed_struct(Ehdr)
{
typedef typename TElfITypes::Half Half; typedef typename TElfITypes::Half Half;
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
@@ -76,13 +75,11 @@ struct Ehdr
# define WANT_EHDR_ENUM 1 # define WANT_EHDR_ENUM 1
# include "p_elf_enum.h" # include "p_elf_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TElfITypes> template <class TElfITypes>
struct Dyn __packed_struct(Dyn)
{
typedef typename TElfITypes::Xword Xword; typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
@@ -91,13 +88,11 @@ struct Dyn
# define WANT_DYN_ENUM 1 # define WANT_DYN_ENUM 1
# include "p_elf_enum.h" # include "p_elf_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TElfITypes> template <class TElfITypes>
struct External_Note __packed_struct(External_Note)
{
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
Word xn_namesz; // includes terminating '\0' Word xn_namesz; // includes terminating '\0'
@@ -105,8 +100,7 @@ struct External_Note
Word xn_type; Word xn_type;
//char xn_name[N]; // terminate with '\0' //char xn_name[N]; // terminate with '\0'
//char xn_data[M]; // aligned to 0 mod 4 //char xn_data[M]; // aligned to 0 mod 4
} __packed_struct_end()
__attribute_packed;
} // namespace N_Elf } // namespace N_Elf
@@ -119,8 +113,7 @@ __attribute_packed;
namespace N_Elf32 { namespace N_Elf32 {
template <class TElfITypes> template <class TElfITypes>
struct Phdr __packed_struct(Phdr)
{
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Off Off; typedef typename TElfITypes::Off Off;
@@ -136,13 +129,11 @@ struct Phdr
# define WANT_PHDR_ENUM 1 # define WANT_PHDR_ENUM 1
# include "p_elf_enum.h" # include "p_elf_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TElfITypes> template <class TElfITypes>
struct Shdr __packed_struct(Shdr)
{
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Off Off; typedef typename TElfITypes::Off Off;
@@ -160,13 +151,11 @@ struct Shdr
# define WANT_SHDR_ENUM 1 # define WANT_SHDR_ENUM 1
# include "p_elf_enum.h" # include "p_elf_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TElfITypes> template <class TElfITypes>
struct Sym __packed_struct(Sym)
{
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Section Section; typedef typename TElfITypes::Section Section;
@@ -184,8 +173,7 @@ struct Sym
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); } static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
static unsigned int get_st_type(unsigned x) { return 0xf & x ; } static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); } static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
} __packed_struct_end()
__attribute_packed;
} // namespace N_Elf32 } // namespace N_Elf32
@@ -198,8 +186,7 @@ __attribute_packed;
namespace N_Elf64 { namespace N_Elf64 {
template <class TElfITypes> template <class TElfITypes>
struct Phdr __packed_struct(Phdr)
{
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Xword Xword; typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
@@ -216,13 +203,11 @@ struct Phdr
# define WANT_PHDR_ENUM 1 # define WANT_PHDR_ENUM 1
# include "p_elf_enum.h" # include "p_elf_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TElfITypes> template <class TElfITypes>
struct Shdr __packed_struct(Shdr)
{
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Xword Xword; typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
@@ -241,13 +226,11 @@ struct Shdr
# define WANT_SHDR_ENUM 1 # define WANT_SHDR_ENUM 1
# include "p_elf_enum.h" # include "p_elf_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TElfITypes> template <class TElfITypes>
struct Sym __packed_struct(Sym)
{
typedef typename TElfITypes::Word Word; typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Xword Xword; typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr; typedef typename TElfITypes::Addr Addr;
@@ -266,8 +249,7 @@ struct Sym
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); } static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
static unsigned int get_st_type(unsigned x) { return 0xf & x ; } static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); } static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
} __packed_struct_end()
__attribute_packed;
} // namespace N_Elf64 } // namespace N_Elf64
@@ -284,11 +266,11 @@ struct ElfClass_32
{ {
typedef TP BeLePolicy; typedef TP BeLePolicy;
// integral types // integral types (target endianness)
typedef typename TP::U16 U16; typedef typename TP::U16 TE16;
typedef typename TP::U32 U32; typedef typename TP::U32 TE32;
typedef typename TP::U64 U64; typedef typename TP::U64 TE64;
typedef N_Elf::ElfITypes<U16, U32, U32, U32, U32> ElfITypes; typedef N_Elf::ElfITypes<TE16, TE32, TE32, TE32, TE32> ElfITypes;
// ELF types // ELF types
typedef N_Elf ::Ehdr<ElfITypes> Ehdr; typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
@@ -319,11 +301,11 @@ struct ElfClass_64
{ {
typedef TP BeLePolicy; typedef TP BeLePolicy;
// integral types // integral types (target endianness)
typedef typename TP::U16 U16; typedef typename TP::U16 TE16;
typedef typename TP::U32 U32; typedef typename TP::U32 TE32;
typedef typename TP::U64 U64; typedef typename TP::U64 TE64;
typedef N_Elf::ElfITypes<U16, U32, U64, U64, U64> ElfITypes; typedef N_Elf::ElfITypes<TE16, TE32, TE64, TE64, TE64> ElfITypes;
// ELF types // ELF types
typedef N_Elf ::Ehdr<ElfITypes> Ehdr; typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
+11 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -68,10 +68,13 @@
}; };
enum { // e_machine enum { // e_machine
EM_386 = 3, EM_386 = 3,
EM_MIPS = 8,
EM_MIPS_RS3_LE = 10, /* MIPS R3000 little-endian */
EM_PPC = 20, EM_PPC = 20,
EM_PPC64 = 21, EM_PPC64 = 21,
EM_ARM = 40, EM_ARM = 40,
EM_X86_64 = 62 EM_X86_64 = 62
}; };
enum { // e_version enum { // e_version
EV_CURRENT = 1 EV_CURRENT = 1
@@ -138,10 +141,14 @@
enum { // d_tag enum { // d_tag
DT_NULL = 0, /* End flag */ DT_NULL = 0, /* End flag */
DT_NEEDED = 1, /* Name of needed library */ DT_NEEDED = 1, /* Name of needed library */
DT_PLTRELSZ = 2, /* Size in bytes of PLT relocs */
DT_HASH = 4, /* Hash table of symbol names */ DT_HASH = 4, /* Hash table of symbol names */
DT_STRTAB = 5, /* String table */ DT_STRTAB = 5, /* String table */
DT_SYMTAB = 6, /* Symbol table */ DT_SYMTAB = 6, /* Symbol table */
DT_STRSZ = 10 /* Sizeof string table */ DT_STRSZ = 10, /* Sizeof string table */
DT_PLTREL = 20, /* Type of reloc in PLT */
DT_JMPREL = 23, /* Address of PLT relocs */
DT_GNU_HASH = 0x6ffffef5 /* GNU-style hash table */
}; };
#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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+7 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -51,7 +51,8 @@ PackExe::PackExe(InputFile *f) :
super(f) super(f)
{ {
bele = &N_BELE_RTP::le_policy; bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32); COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32)
COMPILE_TIME_ASSERT_ALIGNED1(exe_header_t)
ih_exesize = ih_imagesize = ih_overlay = 0; ih_exesize = ih_imagesize = ih_overlay = 0;
stack_for_lzma = 0; stack_for_lzma = 0;
use_clear_dirty_stack = false; use_clear_dirty_stack = false;
@@ -478,7 +479,7 @@ void PackExe::pack(OutputFile *fo)
for (ic = 0; ic < ih.relocs; ic++) for (ic = 0; ic < ih.relocs; ic++)
{ {
unsigned jc = get_le32(wr+4*ic); unsigned jc = get_le32(wr+4*ic);
set_le32(wr+4*ic, (jc>>16)*16+(jc&0xffff)); set_le32(wr+4*ic, ((jc>>16)*16+(jc&0xffff)) & 0xfffff);
} }
qsort(wr,ih.relocs,4,le32_compare); qsort(wr,ih.relocs,4,le32_compare);
relocsize = optimize_relocs(ibuf, ih_imagesize, wr, ih.relocs, w, &has_9a); relocsize = optimize_relocs(ibuf, ih_imagesize, wr, ih.relocs, w, &has_9a);
@@ -506,7 +507,7 @@ void PackExe::pack(OutputFile *fo)
// compress (max_match = 8192) // compress (max_match = 8192)
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
cconf.conf_ucl.max_match = MAXMATCH; cconf.conf_ucl.max_match = MAXMATCH;
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 32, &cconf); compressWithFilters(&ft, 32, &cconf);
if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method)) if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
+7 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -42,7 +42,8 @@ public:
virtual int getVersion() const { return 13; } virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_DOS_EXE; } virtual int getFormat() const { return UPX_F_DOS_EXE; }
virtual const char *getName() const { return "dos/exe"; } virtual const char *getName() const { return "dos/exe"; }
virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.exe" : "i286-dos16.exe"; } //virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.exe" : "i286-dos16.exe"; }
virtual const char *getFullName(const options_t *) const { return "i086-dos16.exe"; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const; virtual const int *getFilters() const;
@@ -73,8 +74,7 @@ protected:
virtual Linker* newLinker() const; virtual Linker* newLinker() const;
void addLoaderEpilogue(int flag); void addLoaderEpilogue(int flag);
struct exe_header_t __packed_struct(exe_header_t)
{
LE16 ident; LE16 ident;
LE16 m512; LE16 m512;
LE16 p512; LE16 p512;
@@ -90,8 +90,7 @@ protected:
LE16 relocoffs; LE16 relocoffs;
char __[2]; // overlnum char __[2]; // overlnum
LE32 firstreloc; LE32 firstreloc;
} __packed_struct_end()
__attribute_packed;
exe_header_t ih, oh; exe_header_t ih, oh;
+710 -301
View File
File diff suppressed because it is too large Load Diff
+78 -47
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -70,6 +70,8 @@ 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 lg2_page; // log2(PAGE_SIZE)
unsigned page_size; // 1u<<lg2_page
unsigned short e_machine; unsigned short e_machine;
unsigned char ei_class; unsigned char ei_class;
@@ -119,38 +121,47 @@ protected:
virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const; virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const;
static unsigned elf_hash(char const *) /*const*/; static unsigned elf_hash(char const *) /*const*/;
static unsigned gnu_hash(char const *) /*const*/;
virtual void const *elf_find_dynamic(unsigned) const; virtual void const *elf_find_dynamic(unsigned) 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(unsigned) 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_type(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
Elf32_Shdr const *shdri; // from input file
unsigned page_mask; // AND clears the offset-within-page
Elf32_Dyn const *dynseg; // from PT_DYNAMIC Elf32_Dyn const *dynseg; // from PT_DYNAMIC
unsigned int const *hashtab; // from DT_HASH unsigned int const *hashtab; // from DT_HASH
unsigned int const *gashtab; // from DT_GNU_HASH
Elf32_Sym const *dynsym; // from DT_SYMTAB Elf32_Sym const *dynsym; // from DT_SYMTAB
char const *shstrtab; // via Elf32_Shdr
int n_elf_shnum; // via e_shnum
struct cprElfHdr1 { Elf32_Shdr const *sec_strndx;
Elf32_Shdr const *sec_dynsym;
Elf32_Shdr const *sec_dynstr;
__packed_struct(cprElfHdr1)
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
Elf32_Phdr phdr[1]; Elf32_Phdr phdr[1];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
struct cprElfHdr2 { __packed_struct(cprElfHdr2)
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
Elf32_Phdr phdr[2]; Elf32_Phdr phdr[2];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
struct cprElfHdr3 { __packed_struct(cprElfHdr3)
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
Elf32_Phdr phdr[3]; Elf32_Phdr phdr[3];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
cprElfHdr3 elfout; cprElfHdr3 elfout;
@@ -211,27 +222,25 @@ protected:
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
acc_uint64l_t page_mask; // AND clears the offset-within-page
struct cprElfHdr1 { __packed_struct(cprElfHdr1)
Elf64_Ehdr ehdr; Elf64_Ehdr ehdr;
Elf64_Phdr phdr[1]; Elf64_Phdr phdr[1];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
struct cprElfHdr2 { __packed_struct(cprElfHdr2)
Elf64_Ehdr ehdr; Elf64_Ehdr ehdr;
Elf64_Phdr phdr[2]; Elf64_Phdr phdr[2];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
struct cprElfHdr3 { __packed_struct(cprElfHdr3)
Elf64_Ehdr ehdr; Elf64_Ehdr ehdr;
Elf64_Phdr phdr[3]; Elf64_Phdr phdr[3];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
cprElfHdr3 elfout; cprElfHdr3 elfout;
@@ -250,13 +259,6 @@ class PackLinuxElf32Be : public PackLinuxElf32
typedef PackLinuxElf32 super; typedef PackLinuxElf32 super;
protected: protected:
PackLinuxElf32Be(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; } PackLinuxElf32Be(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; }
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
}; };
class PackLinuxElf32Le : public PackLinuxElf32 class PackLinuxElf32Le : public PackLinuxElf32
@@ -264,13 +266,6 @@ class PackLinuxElf32Le : public PackLinuxElf32
typedef PackLinuxElf32 super; typedef PackLinuxElf32 super;
protected: protected:
PackLinuxElf32Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; } PackLinuxElf32Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
}; };
class PackLinuxElf64Le : public PackLinuxElf64 class PackLinuxElf64Le : public PackLinuxElf64
@@ -278,15 +273,9 @@ class PackLinuxElf64Le : public PackLinuxElf64
typedef PackLinuxElf64 super; typedef PackLinuxElf64 super;
protected: protected:
PackLinuxElf64Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; } PackLinuxElf64Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
}; };
/************************************************************************* /*************************************************************************
// linux/elf64amd // linux/elf64amd
**************************************************************************/ **************************************************************************/
@@ -310,6 +299,7 @@ protected:
virtual void defineSymbols(Filter const *); virtual void defineSymbols(Filter const *);
}; };
/************************************************************************* /*************************************************************************
// linux/elf32ppc // linux/elf32ppc
**************************************************************************/ **************************************************************************/
@@ -330,6 +320,7 @@ protected:
virtual Linker* newLinker() const; virtual Linker* newLinker() const;
}; };
/************************************************************************* /*************************************************************************
// linux/elf386 // linux/elf386
**************************************************************************/ **************************************************************************/
@@ -406,6 +397,7 @@ protected:
); );
}; };
/************************************************************************* /*************************************************************************
// linux/elfarm // linux/elfarm
**************************************************************************/ **************************************************************************/
@@ -416,8 +408,8 @@ class PackLinuxElf32armLe : public PackLinuxElf32Le
public: public:
PackLinuxElf32armLe(InputFile *f); PackLinuxElf32armLe(InputFile *f);
virtual ~PackLinuxElf32armLe(); virtual ~PackLinuxElf32armLe();
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMLE; } virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMEL; }
virtual const char *getName() const { return "linux/armLE"; } virtual const char *getName() const { return "linux/armel"; }
virtual const char *getFullName(const options_t *) const { return "arm-linux.elf"; } virtual const char *getFullName(const options_t *) const { return "arm-linux.elf"; }
virtual const int *getFilters() const; virtual const int *getFilters() const;
@@ -436,8 +428,8 @@ class PackLinuxElf32armBe : public PackLinuxElf32Be
public: public:
PackLinuxElf32armBe(InputFile *f); PackLinuxElf32armBe(InputFile *f);
virtual ~PackLinuxElf32armBe(); virtual ~PackLinuxElf32armBe();
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMBE; } virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMEB; }
virtual const char *getName() const { return "linux/armBE"; } virtual const char *getName() const { return "linux/armeb"; }
virtual const char *getFullName(const options_t *) const { return "armeb-linux.elf"; } virtual const char *getFullName(const options_t *) const { return "armeb-linux.elf"; }
virtual const int *getFilters() const; virtual const int *getFilters() const;
@@ -450,6 +442,45 @@ protected:
virtual void defineSymbols(Filter const *); virtual void defineSymbols(Filter const *);
}; };
class PackLinuxElf32mipseb : public PackLinuxElf32Be
{
typedef PackLinuxElf32Be super;
public:
PackLinuxElf32mipseb(InputFile *f);
virtual ~PackLinuxElf32mipseb();
virtual int getFormat() const { return UPX_F_LINUX_ELF32_MIPSEB; }
virtual const char *getName() const { return "linux/mipseb"; }
virtual const char *getFullName(const options_t *) const { return "mips-linux.elf"; }
virtual const int *getFilters() const;
protected:
virtual Linker* newLinker() const;
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void buildLoader(const Filter *);
virtual void updateLoader(OutputFile *);
virtual void defineSymbols(Filter const *);
};
class PackLinuxElf32mipsel : public PackLinuxElf32Le
{
typedef PackLinuxElf32Le super;
public:
PackLinuxElf32mipsel(InputFile *f);
virtual ~PackLinuxElf32mipsel();
virtual int getFormat() const { return UPX_F_LINUX_ELF32_MIPSEL; }
virtual const char *getName() const { return "linux/mipsel"; }
virtual const char *getFullName(const options_t *) const { return "mipsel-linux.elf"; }
virtual const int *getFilters() const;
protected:
virtual Linker* newLinker() const;
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void buildLoader(const Filter *);
virtual void updateLoader(OutputFile *);
virtual void defineSymbols(Filter const *);
};
#endif /*} already included */ #endif /*} already included */
+20 -17
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2001-2007 John F. Reiser Copyright (C) 2001-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -132,8 +132,8 @@ PackLinuxI386::generateElfHdr(
unsigned const brka unsigned const brka
) )
{ {
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout; cprElfHdr2 *const h2 = (cprElfHdr2 *)(void *)&elfout;
cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout; cprElfHdr3 *const h3 = (cprElfHdr3 *)(void *)&elfout;
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr)); assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
@@ -526,28 +526,31 @@ bool PackLinuxI386::canPack()
ei_osabi = osabi0; // Proudly declares its osabi in Ehdr. ei_osabi = osabi0; // Proudly declares its osabi in Ehdr.
break; break;
default: default:
unsigned const e_phnum = get_native16(&ehdr.e_phnum); unsigned const e_phnum = get_te16(&ehdr.e_phnum);
if (e_phnum<=(512/sizeof(Elf32_Phdr))) { if (e_phnum<=(512/sizeof(Elf32_Phdr))) {
char buf2[512]; union {
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET); unsigned char buf2[512];
fi->readx(buf2, sizeof(buf2)); //Elf32_Phdr phdr;
} u;
fi->seek(get_te32(&ehdr.e_phoff), SEEK_SET);
fi->readx(u.buf2, sizeof(u.buf2));
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
Elf32_Phdr const *phdr = (Elf32_Phdr const *)buf2; Elf32_Phdr const *phdr = (Elf32_Phdr *) u.buf2;
for (unsigned j=0; j < e_phnum; ++phdr, ++j) { for (unsigned j=0; j < e_phnum; ++phdr, ++j) {
if (phdr->PT_NOTE == get_native32(&phdr->p_type)) { if (phdr->PT_NOTE == get_te32(&phdr->p_type)) {
unsigned const offset = get_native32(&phdr->p_offset); unsigned const offset = get_te32(&phdr->p_offset);
struct Elf32_Note note; memset(&note, 0, sizeof(note)); struct Elf32_Note note; memset(&note, 0, sizeof(note));
fi->seek(offset, SEEK_SET); fi->seek(offset, SEEK_SET);
fi->readx(&note, sizeof(note)); fi->readx(&note, sizeof(note));
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
if (4==get_native32(&note.descsz) if (4==get_te32(&note.descsz)
&& 1==get_native32(&note.type) && 1==get_te32(&note.type)
&& 0==note.end ) { && 0==note.end ) {
if (0==strcmp("NetBSD", (char const *)&note.text)) { if (0==strcmp("NetBSD", (char const *)note.text)) {
ei_osabi = Elf32_Ehdr::ELFOSABI_NETBSD; ei_osabi = Elf32_Ehdr::ELFOSABI_NETBSD;
break; break;
} }
if (0==strcmp("OpenBSD", (char const *)&note.text)) { if (0==strcmp("OpenBSD", (char const *)note.text)) {
ei_osabi = Elf32_Ehdr::ELFOSABI_OPENBSD; ei_osabi = Elf32_Ehdr::ELFOSABI_OPENBSD;
break; break;
} }
+10 -13
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -87,26 +87,23 @@ protected:
unsigned n_mru; unsigned n_mru;
struct cprElfHdr1 { __packed_struct(cprElfHdr1)
Elf_LE32_Ehdr ehdr; Elf_LE32_Ehdr ehdr;
Elf_LE32_Phdr phdr[1]; Elf_LE32_Phdr phdr[1];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
struct cprElfHdr2 { __packed_struct(cprElfHdr2)
Elf_LE32_Ehdr ehdr; Elf_LE32_Ehdr ehdr;
Elf_LE32_Phdr phdr[2]; Elf_LE32_Phdr phdr[2];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
struct cprElfHdr3 { __packed_struct(cprElfHdr3)
Elf_LE32_Ehdr ehdr; Elf_LE32_Ehdr ehdr;
Elf_LE32_Phdr phdr[3]; Elf_LE32_Phdr phdr[3];
l_info linfo; l_info linfo;
} __packed_struct_end()
__attribute_packed;
cprElfHdr3 elfout; cprElfHdr3 elfout;
@@ -138,7 +135,7 @@ class PackBSDI386 : public PackLinuxI386
public: public:
PackBSDI386(InputFile *f); PackBSDI386(InputFile *f);
virtual int getFormat() const { return UPX_F_BSD_i386; } virtual int getFormat() const { return UPX_F_BSD_i386; }
virtual const char *getName() const { return "*BSD/386"; } virtual const char *getName() const { return "BSD/386"; }
virtual const char *getFullName(const options_t *) const { return "i386-bsd.elf.execve"; } virtual const char *getFullName(const options_t *) const { return "i386-bsd.elf.execve"; }
protected: protected:
+17 -14
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -197,15 +197,18 @@ void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
void PackLinuxElf32x86interp::unpack(OutputFile *fo) void PackLinuxElf32x86interp::unpack(OutputFile *fo)
{ {
#define MAX_INTERP_HDR 512 #define MAX_INTERP_HDR 512
char bufehdr[MAX_INTERP_HDR]; union {
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)bufehdr; unsigned char buf[MAX_INTERP_HDR];
Elf32_Phdr const *phdr = (Elf32_Phdr *)(1+ehdr); //struct { Elf32_Ehdr ehdr; Elf32_Phdr phdr; } e;
} u;
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *) u.buf;
Elf32_Phdr const *phdr = (Elf32_Phdr *) (u.buf + sizeof(*ehdr));
unsigned szb_info = sizeof(b_info); unsigned szb_info = sizeof(b_info);
{ {
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
fi->readx(bufehdr, MAX_INTERP_HDR); fi->readx(u.buf, MAX_INTERP_HDR);
unsigned const e_entry = get_native32(&ehdr->e_entry); unsigned const e_entry = get_te32(&ehdr->e_entry);
if (e_entry < 0x401180) { /* old style, 8-byte b_info */ if (e_entry < 0x401180) { /* old style, 8-byte b_info */
szb_info = 2*sizeof(unsigned); szb_info = 2*sizeof(unsigned);
} }
@@ -214,16 +217,16 @@ void PackLinuxElf32x86interp::unpack(OutputFile *fo)
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));
unsigned orig_file_size = get_native32(&hbuf.p_filesize); unsigned orig_file_size = get_te32(&hbuf.p_filesize);
blocksize = get_native32(&hbuf.p_blocksize); blocksize = get_te32(&hbuf.p_blocksize);
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size) if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
throwCantUnpack("file header corrupted"); throwCantUnpack("file header corrupted");
ibuf.alloc(blocksize + OVERHEAD); ibuf.alloc(blocksize + OVERHEAD);
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr)); b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
fi->readx(&bhdr, szb_info); fi->readx(&bhdr, szb_info);
ph.u_len = get_native32(&bhdr.sz_unc); ph.u_len = get_te32(&bhdr.sz_unc);
ph.c_len = get_native32(&bhdr.sz_cpr); ph.c_len = get_te32(&bhdr.sz_cpr);
ph.filter_cto = bhdr.b_cto8; ph.filter_cto = bhdr.b_cto8;
// Uncompress Ehdr and Phdrs. // Uncompress Ehdr and Phdrs.
@@ -277,7 +280,7 @@ void PackLinuxElf32x86interp::unpack(OutputFile *fo)
// check for end-of-file // check for end-of-file
fi->readx(&bhdr, szb_info); fi->readx(&bhdr, szb_info);
unsigned const sz_unc = ph.u_len = get_native32(&bhdr.sz_unc); unsigned const sz_unc = ph.u_len = get_te32(&bhdr.sz_unc);
if (sz_unc == 0) { // uncompressed size 0 -> EOF if (sz_unc == 0) { // uncompressed size 0 -> EOF
// note: magic is always stored le32 // note: magic is always stored le32
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
@@ -91,7 +91,7 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
// filter // filter
optimizeFilter(&fold_ft, buf, sz_fold); optimizeFilter(&fold_ft, buf, sz_fold);
unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) + unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) +
sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum); sizeof(Elf32_Phdr) * get_te32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
if (0 == get_le32(fold_hdrlen + buf)) { if (0 == get_le32(fold_hdrlen + buf)) {
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils) // inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
fold_hdrlen = umax(0x80, fold_hdrlen); fold_hdrlen = umax(0x80, fold_hdrlen);
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser Copyright (C) 2000-2009 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser John F. Reiser
<jreiser@users.sourceforge.net> <jreiser@users.sourceforge.net>
+611 -57
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-2007 John Reiser Copyright (C) 2004-2009 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
@@ -21,7 +21,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
John Reiser John Reiser
jreiser@users.sourceforge.net <jreiser@users.sourceforge.net>
*/ */
@@ -44,15 +44,49 @@ static const
static const static const
#include "stub/i386-darwin.macho-fold.h" #include "stub/i386-darwin.macho-fold.h"
static const
#include "stub/amd64-darwin.macho-entry.h"
static const
#include "stub/amd64-darwin.macho-fold.h"
static const
#include "stub/arm-darwin.macho-entry.h"
static const
#include "stub/arm-darwin.macho-fold.h"
// Packing a Darwin (Mach-o) Mac OS X dylib (dynamic shared library)
// is restricted. UPX gets control as the -init function, at the very
// end of processing by dyld. Relocation, loading of dependent libraries,
// etc., already have taken place before decompression. So the Mach-o
// headers, the __IMPORT segment, the __LINKEDIT segment, anything
// that is modifed by relocation, etc., cannot be compressed.
// We simplify arbitrarily by compressing only the __TEXT segment,
// which must be the first segment.
static const
#include "stub/i386-darwin.dylib-entry.h"
// The runtime stub for the dyld -init routine does not use "fold"ed code.
//#include "stub/i386-darwin.dylib-fold.h"
static const
#include "stub/powerpc-darwin.dylib-entry.h"
static const unsigned lc_segment[2] = {
0x1, 0x19
//Mach_segment_command::LC_SEGMENT,
//Mach_segment_command::LC_SEGMENT_64
};
template <class T> template <class T>
PackMachBase<T>::PackMachBase(InputFile *f, unsigned cputype, unsigned flavor, PackMachBase<T>::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype,
unsigned count, unsigned size) : unsigned flavor, unsigned count, unsigned size) :
super(f), my_cputype(cputype), my_thread_flavor(flavor), super(f), my_cputype(cputype), my_filetype(filetype), my_thread_flavor(flavor),
my_thread_state_word_count(count), my_thread_command_size(size), my_thread_state_word_count(count), my_thread_command_size(size),
n_segment(0), rawmseg(NULL), msegcmd(NULL) n_segment(0), rawmseg(NULL), msegcmd(NULL), o_routines_cmd(0),
prev_init_address(0)
{ {
MachClass::compileTimeAssertions(); MachClass::compileTimeAssertions();
bele = N_BELE_CTP::getRTP<BeLePolicy>(); bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL);
} }
template <class T> template <class T>
@@ -62,6 +96,16 @@ PackMachBase<T>::~PackMachBase()
delete [] msegcmd; delete [] msegcmd;
} }
PackDylibI386::PackDylibI386(InputFile *f) : super(f)
{
my_filetype = Mach_header::MH_DYLIB;
}
PackDylibPPC32::PackDylibPPC32(InputFile *f) : super(f)
{
my_filetype = Mach_header::MH_DYLIB;
}
template <class T> template <class T>
const int *PackMachBase<T>::getCompressionMethods(int method, int level) const const int *PackMachBase<T>::getCompressionMethods(int method, int level) const
{ {
@@ -69,6 +113,16 @@ const int *PackMachBase<T>::getCompressionMethods(int method, int level) const
return Packer::getDefaultCompressionMethods_le32(method, level); return Packer::getDefaultCompressionMethods_le32(method, level);
} }
const int *PackMachARMEL::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_8(method, level);
}
PackMachPPC32::PackMachPPC32(InputFile *f) : super(f, Mach_header::CPU_TYPE_POWERPC,
Mach_header::MH_EXECUTE, Mach_thread_command::PPC_THREAD_STATE,
sizeof(Mach_ppc_thread_state)>>2, sizeof(threado))
{ }
const int *PackMachPPC32::getFilters() const const int *PackMachPPC32::getFilters() const
{ {
@@ -76,12 +130,39 @@ const int *PackMachPPC32::getFilters() const
return filters; return filters;
} }
PackMachI386::PackMachI386(InputFile *f) : super(f, Mach_header::CPU_TYPE_I386,
Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::x86_THREAD_STATE32,
sizeof(Mach_i386_thread_state)>>2, sizeof(threado))
{ }
int const *PackMachI386::getFilters() const int const *PackMachI386::getFilters() const
{ {
static const int filters[] = { 0x49, FT_END }; static const int filters[] = { 0x49, FT_END };
return filters; return filters;
} }
PackMachAMD64::PackMachAMD64(InputFile *f) : super(f, Mach_header::CPU_TYPE_X86_64,
Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::x86_THREAD_STATE64,
sizeof(Mach_AMD64_thread_state)>>2, sizeof(threado))
{ }
int const *PackMachAMD64::getFilters() const
{
static const int filters[] = { 0x49, FT_END };
return filters;
}
PackMachARMEL::PackMachARMEL(InputFile *f) : super(f, Mach_header::CPU_TYPE_ARM,
Mach_header::MH_EXECUTE, (unsigned)Mach_thread_command::ARM_THREAD_STATE,
sizeof(Mach_ARM_thread_state)>>2, sizeof(threado))
{ }
int const *PackMachARMEL::getFilters() const
{
static const int filters[] = { 0x50, FT_END };
return filters;
}
Linker *PackMachPPC32::newLinker() const Linker *PackMachPPC32::newLinker() const
{ {
return new ElfLinkerPpc32; return new ElfLinkerPpc32;
@@ -92,6 +173,16 @@ Linker *PackMachI386::newLinker() const
return new ElfLinkerX86; return new ElfLinkerX86;
} }
Linker *PackMachAMD64::newLinker() const
{
return new ElfLinkerAMD64;
}
Linker *PackMachARMEL::newLinker() const
{
return new ElfLinkerArmLE;
}
template <class T> template <class T>
void void
PackMachBase<T>::addStubEntrySections(Filter const *) PackMachBase<T>::addStubEntrySections(Filter const *)
@@ -104,6 +195,8 @@ PackMachBase<T>::addStubEntrySections(Filter const *)
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : NULL), NULL);
if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH");
addLoader("ELFMAINY,IDENTSTR,+40,ELFMAINZ,FOLDEXEC", NULL); addLoader("ELFMAINY,IDENTSTR,+40,ELFMAINZ,FOLDEXEC", NULL);
} }
@@ -169,6 +262,35 @@ void PackMachI386::addStubEntrySections(Filter const *ft)
addLoader("FOLDEXEC", NULL); addLoader("FOLDEXEC", NULL);
} }
void PackMachAMD64::addStubEntrySections(Filter const */*ft*/)
{
addLoader("MACHMAINX", NULL);
//addLoader(getDecompressorSections(), NULL);
addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,+80C,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL);
if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", NULL);
}
void PackMachARMEL::addStubEntrySections(Filter const */*ft*/)
{
addLoader("MACHMAINX", NULL);
//addLoader(getDecompressorSections(), NULL);
addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,+80C,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL);
if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", NULL);
}
template <class T> template <class T>
void PackMachBase<T>::defineSymbols(Filter const *) void PackMachBase<T>::defineSymbols(Filter const *)
@@ -215,7 +337,8 @@ PackMachBase<T>::buildMachLoader(
delete [] cprLoader; delete [] cprLoader;
int const GAP = 128; // must match stub/l_mac_ppc.S int const GAP = 128; // must match stub/l_mac_ppc.S
segcmdo.vmsize += h.sz_unc - h.sz_cpr + GAP + 64; int const NO_LAP = 64; // must match stub/src/*darwin*.S
segcmdo.vmsize += h.sz_unc - h.sz_cpr + GAP + NO_LAP;
addStubEntrySections(ft); addStubEntrySections(ft);
@@ -239,6 +362,38 @@ PackMachI386::buildLoader(const Filter *ft)
stub_i386_darwin_macho_fold, sizeof(stub_i386_darwin_macho_fold), ft ); stub_i386_darwin_macho_fold, sizeof(stub_i386_darwin_macho_fold), ft );
} }
void
PackMachAMD64::buildLoader(const Filter *ft)
{
buildMachLoader(
stub_amd64_darwin_macho_entry, sizeof(stub_amd64_darwin_macho_entry),
stub_amd64_darwin_macho_fold, sizeof(stub_amd64_darwin_macho_fold), ft );
}
void
PackMachARMEL::buildLoader(const Filter *ft)
{
buildMachLoader(
stub_arm_darwin_macho_entry, sizeof(stub_arm_darwin_macho_entry),
stub_arm_darwin_macho_fold, sizeof(stub_arm_darwin_macho_fold), ft );
}
void
PackDylibI386::buildLoader(const Filter *ft)
{
buildMachLoader(
stub_i386_darwin_dylib_entry, sizeof(stub_i386_darwin_dylib_entry),
0, 0, ft );
}
void
PackDylibPPC32::buildLoader(const Filter *ft)
{
buildMachLoader(
stub_powerpc_darwin_dylib_entry, sizeof(stub_powerpc_darwin_dylib_entry),
0, 0, ft );
}
template <class T> template <class T>
void PackMachBase<T>::patchLoader() { } void PackMachBase<T>::patchLoader() { }
@@ -266,8 +421,9 @@ PackMachBase<T>::compare_segment_command(void const *const aa, void const *const
{ {
Mach_segment_command const *const a = (Mach_segment_command const *)aa; Mach_segment_command const *const a = (Mach_segment_command const *)aa;
Mach_segment_command const *const b = (Mach_segment_command const *)bb; Mach_segment_command const *const b = (Mach_segment_command const *)bb;
unsigned const xa = a->cmd - Mach_segment_command::LC_SEGMENT; unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
unsigned const xb = b->cmd - Mach_segment_command::LC_SEGMENT; unsigned const xa = a->cmd - lc_seg;
unsigned const xb = b->cmd - lc_seg;
if (xa < xb) return -1; // LC_SEGMENT first if (xa < xb) return -1; // LC_SEGMENT first
if (xa > xb) return 1; if (xa > xb) return 1;
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr
@@ -303,9 +459,190 @@ void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
fo->rewrite(&linfo, sizeof(linfo)); fo->rewrite(&linfo, sizeof(linfo));
} }
void PackMachAMD64::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{
// offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
super::pack4(fo, ft);
segcmdo.filesize = fo->getBytesWritten();
segcmdo.vmsize += segcmdo.filesize;
fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segcmdo, sizeof(segcmdo));
fo->rewrite(&threado, sizeof(threado));
fo->rewrite(&linfo, sizeof(linfo));
}
void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{
// offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
super::pack4(fo, ft);
segcmdo.filesize = fo->getBytesWritten();
segcmdo.vmsize += segcmdo.filesize;
fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segcmdo, sizeof(segcmdo));
fo->rewrite(&threado, sizeof(threado));
fo->rewrite(&linfo, sizeof(linfo));
}
#undef PAGE_MASK
#undef PAGE_SIZE
#define PAGE_MASK (~0u<<12)
#define PAGE_SIZE -PAGE_MASK
#undef PAGE_MASK64
#undef PAGE_SIZE64
#define PAGE_MASK64 (~(acc_uint64l_t)0<<12)
#define PAGE_SIZE64 -PAGE_MASK64
template <class T>
void PackMachBase<T>::pack4dylib( // append PackHeader
OutputFile *const fo,
Filter &ft,
Addr init_address
)
{
unsigned opos = sizeof(mhdro);
fo->seek(opos, SEEK_SET);
// Append each non-__TEXT segment, page aligned.
int slide = 0;
unsigned o_end_txt = 0;
unsigned hdrpos = sizeof(mhdro);
Mach_segment_command const *seg = rawmseg;
Mach_segment_command const *const endseg =
(Mach_segment_command const *)(mhdri.sizeofcmds + (char const *)seg);
for ( ; seg < endseg; seg = (Mach_segment_command const *)(
seg->cmdsize + (char const *)seg )
) switch (~Mach_segment_command::LC_REQ_DYLD & seg->cmd) {
default: // unknown if any file offset field must slide
printf("Unrecognized Macho cmd offset=0x%lx cmd=0x%lx size=0x%lx\n", (unsigned long)((const char *)seg - (const char *)rawmseg), (unsigned long)seg->cmd, (unsigned long)seg->cmdsize);
// fall through
case Mach_segment_command::LC_THREAD:
case Mach_segment_command::LC_UNIXTHREAD:
case Mach_segment_command::LC_LOAD_DYLIB:
case Mach_segment_command::LC_ID_DYLIB:
case Mach_segment_command::LC_LOAD_DYLINKER:
case Mach_segment_command::LC_UUID:
case Mach_segment_command::LC_RPATH:
case Mach_segment_command::LC_CODE_SIGNATURE:
case Mach_segment_command::LC_REEXPORT_DYLIB:
hdrpos += seg->cmdsize;
break; // contain no file offset fields
case Mach_segment_command::LC_TWOLEVEL_HINTS: {
Mach_twolevel_hints_command cmd; memcpy(&cmd, seg, sizeof(cmd));
if (o_end_txt <= cmd.offset) { cmd.offset += slide; }
fo->seek(hdrpos, SEEK_SET);
fo->rewrite(&cmd, sizeof(cmd));
hdrpos += sizeof(cmd);
} break;
case Mach_segment_command::LC_ROUTINES_64:
case Mach_segment_command::LC_ROUTINES: {
Mach_routines_command cmd; memcpy(&cmd, seg, sizeof(cmd));
cmd.reserved1 = cmd.init_address;
cmd.init_address = init_address;
fo->seek(hdrpos, SEEK_SET);
fo->rewrite(&cmd, sizeof(cmd));
hdrpos += sizeof(cmd);
} break;
case Mach_segment_command::LC_SEGMENT_64:
case Mach_segment_command::LC_SEGMENT: {
// non-__TEXT might be observed and relocated by dyld before us.
Mach_segment_command segcmdtmp = *seg;
bool const is_text = 0==strncmp(&seg->segname[0], "__TEXT", 1+ 6);
{
if (is_text) {
slide = 0;
segcmdtmp.filesize = fo->getBytesWritten();
segcmdtmp.maxprot |= Mach_segment_command::VM_PROT_WRITE;
segcmdtmp.initprot |= Mach_segment_command::VM_PROT_WRITE;
opos = o_end_txt = segcmdtmp.filesize + segcmdtmp.fileoff;
}
else {
opos += ~PAGE_MASK & (0u - opos); // advance to PAGE_SIZE boundary
slide = opos - segcmdtmp.fileoff;
segcmdtmp.fileoff = opos;
}
fo->seek(hdrpos, SEEK_SET);
fo->rewrite(&segcmdtmp, sizeof(segcmdtmp));
hdrpos += sizeof(segcmdtmp);
// Update the sections.
Mach_section_command const *secp = (Mach_section_command const *)(const void*)(const char*)(1+ seg);
unsigned const nsects = segcmdtmp.nsects;
Mach_section_command seccmdtmp;
for (unsigned j = 0; j < nsects; ++secp, ++j) {
seccmdtmp = *secp;
seccmdtmp.offset += slide;
if (seccmdtmp.nreloc) {
seccmdtmp.reloff += slide;
}
fo->rewrite(&seccmdtmp, sizeof(seccmdtmp));
hdrpos += sizeof(seccmdtmp);
}
if (!is_text) {
fo->seek(opos, SEEK_SET);
fi->seek(seg->fileoff, SEEK_SET);
unsigned const len = seg->filesize;
MemBuffer data(len);
fi->readx(data, len);
fo->write(data, len);
opos += len;
}
}
} break;
case Mach_segment_command::LC_SYMTAB: {
Mach_symtab_command cmd; memcpy(&cmd, seg, sizeof(cmd));
if (o_end_txt <= cmd.symoff) { cmd.symoff += slide; }
if (o_end_txt <= cmd.stroff) { cmd.stroff += slide; }
fo->seek(hdrpos, SEEK_SET);
fo->rewrite(&cmd, sizeof(cmd));
hdrpos += sizeof(cmd);
} break;
case Mach_segment_command::LC_DYSYMTAB: {
Mach_dysymtab_command cmd; memcpy(&cmd, seg, sizeof(cmd));
if (o_end_txt <= cmd.tocoff) { cmd.tocoff += slide; }
if (o_end_txt <= cmd.modtaboff) { cmd.modtaboff += slide; }
if (o_end_txt <= cmd.extrefsymoff) { cmd.extrefsymoff += slide; }
if (o_end_txt <= cmd.indirectsymoff) { cmd.indirectsymoff += slide; }
if (o_end_txt <= cmd.extreloff) { cmd.extreloff += slide; }
if (o_end_txt <= cmd.locreloff) { cmd.locreloff += slide; }
fo->seek(hdrpos, SEEK_SET);
fo->rewrite(&cmd, sizeof(cmd));
hdrpos += sizeof(cmd);
} break;
case Mach_segment_command::LC_SEGMENT_SPLIT_INFO: {
Mach_segsplit_info_command cmd; memcpy(&cmd, seg, sizeof(cmd));
if (o_end_txt <= cmd.dataoff) { cmd.dataoff += slide; }
fo->seek(hdrpos, SEEK_SET);
fo->rewrite(&cmd, sizeof(cmd));
hdrpos += sizeof(cmd);
} break;
} // end 'switch'
fo->seek(opos, SEEK_SET); // BUG: "fo->seek(0, SEEK_END);" is broken
// offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + mhdro.sizeofcmds + sizeof(linfo);
PackMachBase<T>::pack4(fo, ft);
}
void PackDylibI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{
pack4dylib(fo, ft, threado.state.eip);
}
void PackDylibPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{
pack4dylib(fo, ft, threado.state.srr0);
}
void PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader void PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
{ {
BE32 disp; TE32 disp;
unsigned const zero = 0; unsigned const zero = 0;
unsigned len = fo->getBytesWritten(); unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& (0u-len)); fo->write(&zero, 3& (0u-len));
@@ -319,7 +656,7 @@ void PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
void PackMachI386::pack3(OutputFile *fo, Filter &ft) // append loader void PackMachI386::pack3(OutputFile *fo, Filter &ft) // append loader
{ {
LE32 disp; TE32 disp;
unsigned const zero = 0; unsigned const zero = 0;
unsigned len = fo->getBytesWritten(); unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& (0u-len)); fo->write(&zero, 3& (0u-len));
@@ -331,6 +668,80 @@ void PackMachI386::pack3(OutputFile *fo, Filter &ft) // append loader
super::pack3(fo, ft); super::pack3(fo, ft);
} }
void PackMachAMD64::pack3(OutputFile *fo, Filter &ft) // append loader
{
TE32 disp;
unsigned const zero = 0;
unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& (0u-len));
len += (3& (0u-len));
disp = len - sz_mach_headers;
fo->write(&disp, sizeof(disp));
threado.state.rip = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */
super::pack3(fo, ft);
}
void PackMachARMEL::pack3(OutputFile *fo, Filter &ft) // append loader
{
TE32 disp;
unsigned const zero = 0;
unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& (0u-len));
len += (3& (0u-len));
disp = len - sz_mach_headers;
fo->write(&disp, sizeof(disp));
threado.state.pc = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */
super::pack3(fo, ft);
}
void PackDylibI386::pack3(OutputFile *fo, Filter &ft) // append loader
{
TE32 disp;
unsigned const zero = 0;
unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& (0u-len));
len += (3& (0u-len)) + 4*sizeof(disp);
disp = prev_init_address;
fo->write(&disp, sizeof(disp)); // user .init_address
disp = sizeof(mhdro) + mhdro.sizeofcmds + sizeof(l_info) + sizeof(p_info);
fo->write(&disp, sizeof(disp)); // src offset(compressed __TEXT)
disp = len - disp - 3*sizeof(disp);
fo->write(&disp, sizeof(disp)); // length(compressed __TEXT)
unsigned const save_sz_mach_headers(sz_mach_headers);
sz_mach_headers = 0;
super::pack3(fo, ft);
sz_mach_headers = save_sz_mach_headers;
}
void PackDylibPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
{
TE32 disp;
unsigned const zero = 0;
unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& (0u-len));
len += (3& (0u-len)) + 4*sizeof(disp);
disp = prev_init_address;
fo->write(&disp, sizeof(disp)); // user .init_address
disp = sizeof(mhdro) + mhdro.sizeofcmds + sizeof(l_info) + sizeof(p_info);
fo->write(&disp, sizeof(disp)); // src offset(compressed __TEXT)
disp = len - disp - 3*sizeof(disp);
fo->write(&disp, sizeof(disp)); // length(compressed __TEXT)
unsigned const save_sz_mach_headers(sz_mach_headers);
sz_mach_headers = 0;
super::pack3(fo, ft);
sz_mach_headers = save_sz_mach_headers;
}
// Determine length of gap between PT_LOAD phdri[k] and closest PT_LOAD // Determine length of gap between PT_LOAD phdri[k] and closest PT_LOAD
// which follows in the file (or end-of-file). Optimize for common case // which follows in the file (or end-of-file). Optimize for common case
// where the PT_LOAD are adjacent ascending by .p_offset. Assume no overlap. // where the PT_LOAD are adjacent ascending by .p_offset. Assume no overlap.
@@ -340,7 +751,8 @@ unsigned PackMachBase<T>::find_SEGMENT_gap(
unsigned const k unsigned const k
) )
{ {
if (Mach_segment_command::LC_SEGMENT!=msegcmd[k].cmd unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
if (lc_seg!=msegcmd[k].cmd
|| 0==msegcmd[k].filesize ) { || 0==msegcmd[k].filesize ) {
return 0; return 0;
} }
@@ -355,7 +767,7 @@ unsigned PackMachBase<T>::find_SEGMENT_gap(
if (k==j) { if (k==j) {
break; break;
} }
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd if (lc_seg==msegcmd[j].cmd
&& 0!=msegcmd[j].filesize ) { && 0!=msegcmd[j].filesize ) {
unsigned const t = msegcmd[j].fileoff; unsigned const t = msegcmd[j].fileoff;
if ((t - hi) < (lo - hi)) { if ((t - hi) < (lo - hi)) {
@@ -384,15 +796,19 @@ 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 void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed body
{ {
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
Extent x; Extent x;
unsigned k; unsigned k;
// count passes, set ptload vars // count passes, set ptload vars
uip->ui_total_passes = 0; uip->ui_total_passes = 0;
for (k = 0; k < n_segment; ++k) { for (k = 0; k < n_segment; ++k) {
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd if (lc_seg==msegcmd[k].cmd
&& 0!=msegcmd[k].filesize ) { && 0!=msegcmd[k].filesize ) {
uip->ui_total_passes++; uip->ui_total_passes++;
if (my_filetype==Mach_header::MH_DYLIB) {
break;
}
if (find_SEGMENT_gap(k)) { if (find_SEGMENT_gap(k)) {
uip->ui_total_passes++; uip->ui_total_passes++;
} }
@@ -403,7 +819,7 @@ void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
unsigned total_in = 0; unsigned total_in = 0;
unsigned total_out = 0; unsigned total_out = 0;
unsigned hdr_u_len = mhdri.sizeofcmds; unsigned hdr_u_len = mhdri.sizeofcmds + sizeof(mhdri);
uip->ui_pass = 0; uip->ui_pass = 0;
ft.addvalue = 0; ft.addvalue = 0;
@@ -413,7 +829,7 @@ void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
// instructions. So filter only the largest executable segment. // instructions. So filter only the largest executable segment.
unsigned exe_filesize_max = 0; unsigned exe_filesize_max = 0;
for (k = 0; k < n_segment; ++k) for (k = 0; k < n_segment; ++k)
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd if (lc_seg==msegcmd[k].cmd
&& 0!=(Mach_segment_command::VM_PROT_EXECUTE & msegcmd[k].initprot) && 0!=(Mach_segment_command::VM_PROT_EXECUTE & msegcmd[k].initprot)
&& exe_filesize_max < msegcmd[k].filesize) { && exe_filesize_max < msegcmd[k].filesize) {
exe_filesize_max = msegcmd[k].filesize; exe_filesize_max = msegcmd[k].filesize;
@@ -421,12 +837,12 @@ void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
int nx = 0; int nx = 0;
for (k = 0; k < n_segment; ++k) for (k = 0; k < n_segment; ++k)
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd if (lc_seg==msegcmd[k].cmd
&& 0!=msegcmd[k].filesize ) { && 0!=msegcmd[k].filesize ) {
x.offset = msegcmd[k].fileoff; x.offset = msegcmd[k].fileoff;
x.size = msegcmd[k].filesize; x.size = msegcmd[k].filesize;
if (0 == nx) { // 1st LC_SEGMENT must cover Mach_header at 0==fileoffset if (0 == nx) { // 1st LC_SEGMENT must cover Mach_header at 0==fileoffset
unsigned const delta = mhdri.sizeofcmds; unsigned const delta = mhdri.sizeofcmds + sizeof(mhdri);
x.offset += delta; x.offset += delta;
x.size -= delta; x.size -= delta;
} }
@@ -439,7 +855,11 @@ void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
} }
hdr_u_len = 0; hdr_u_len = 0;
++nx; ++nx;
if (my_filetype==Mach_header::MH_DYLIB) {
break;
} }
}
if (my_filetype!=Mach_header::MH_DYLIB)
for (k = 0; k < n_segment; ++k) { for (k = 0; k < n_segment; ++k) {
x.size = find_SEGMENT_gap(k); x.size = find_SEGMENT_gap(k);
if (x.size) { if (x.size) {
@@ -448,16 +868,12 @@ void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
} }
} }
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(); segcmdo.filesize = fo->getBytesWritten();
} }
#undef PAGE_MASK
#undef PAGE_SIZE
#define PAGE_MASK (~0u<<12)
#define PAGE_SIZE -PAGE_MASK
void PackMachPPC32::pack1_setup_threado(OutputFile *const fo) void PackMachPPC32::pack1_setup_threado(OutputFile *const fo)
{ {
threado.cmd = Mach_segment_command::LC_UNIXTHREAD; threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
@@ -478,20 +894,48 @@ void PackMachI386::pack1_setup_threado(OutputFile *const fo)
fo->write(&threado, sizeof(threado)); fo->write(&threado, sizeof(threado));
} }
void PackMachAMD64::pack1_setup_threado(OutputFile *const fo)
{
threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
threado.cmdsize = sizeof(threado);
threado.flavor = my_thread_flavor;
threado.count = my_thread_state_word_count;
memset(&threado.state, 0, sizeof(threado.state));
fo->write(&threado, sizeof(threado));
}
void PackMachARMEL::pack1_setup_threado(OutputFile *const fo)
{
threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
threado.cmdsize = sizeof(threado);
threado.flavor = my_thread_flavor;
threado.count = my_thread_state_word_count;
memset(&threado.state, 0, sizeof(threado.state));
fo->write(&threado, sizeof(threado));
}
template <class T> template <class T>
void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate executable header void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate executable header
{ {
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
mhdro = mhdri; mhdro = mhdri;
if (my_filetype==Mach_header::MH_EXECUTE) {
mhdro.ncmds = 2; mhdro.ncmds = 2;
mhdro.sizeofcmds = sizeof(segcmdo) + my_thread_command_size; mhdro.sizeofcmds = sizeof(segcmdo) + my_thread_command_size;
mhdro.flags = Mach_header::MH_NOUNDEFS; mhdro.flags = Mach_header::MH_NOUNDEFS;
}
fo->write(&mhdro, sizeof(mhdro)); fo->write(&mhdro, sizeof(mhdro));
segcmdo.cmd = Mach_segment_command::LC_SEGMENT; segcmdo.cmd = lc_seg;
segcmdo.cmdsize = sizeof(segcmdo); segcmdo.cmdsize = sizeof(segcmdo);
strncpy((char *)&segcmdo.segname, "__TEXT", sizeof(segcmdo.segname)); strncpy((char *)segcmdo.segname, "__TEXT", sizeof(segcmdo.segname));
segcmdo.vmaddr = PAGE_MASK & (~PAGE_MASK + if (my_filetype==Mach_header::MH_EXECUTE) {
segcmdo.vmaddr = PAGE_MASK64 & (~PAGE_MASK64 +
msegcmd[n_segment -1].vmsize + msegcmd[n_segment -1].vmaddr ); msegcmd[n_segment -1].vmsize + msegcmd[n_segment -1].vmaddr );
}
if (my_filetype==Mach_header::MH_DYLIB) {
segcmdo.vmaddr = 0;
}
segcmdo.vmsize = 0; // adjust later segcmdo.vmsize = 0; // adjust later
segcmdo.fileoff = 0; segcmdo.fileoff = 0;
segcmdo.filesize = 0; // adjust later segcmdo.filesize = 0; // adjust later
@@ -501,9 +945,13 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
Mach_segment_command::VM_PROT_EXECUTE; Mach_segment_command::VM_PROT_EXECUTE;
segcmdo.nsects = 0; segcmdo.nsects = 0;
segcmdo.flags = 0; segcmdo.flags = 0;
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->write(&segcmdo, sizeof(segcmdo)); fo->write(&segcmdo, sizeof(segcmdo));
pack1_setup_threado(fo); pack1_setup_threado(fo);
}
if (my_filetype==Mach_header::MH_DYLIB) {
fo->write(rawmseg, mhdri.sizeofcmds);
}
sz_mach_headers = fo->getBytesWritten(); sz_mach_headers = fo->getBytesWritten();
memset((char *)&linfo, 0, sizeof(linfo)); memset((char *)&linfo, 0, sizeof(linfo));
@@ -515,21 +963,25 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
template <class T> template <class T>
void PackMachBase<T>::unpack(OutputFile *fo) void PackMachBase<T>::unpack(OutputFile *fo)
{ {
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
my_thread_command_size + sizeof(linfo); fi->seek(0, SEEK_SET);
fi->readx(&mhdri, sizeof(mhdri));
rawmseg = (Mach_segment_command *)new char[(unsigned) mhdri.sizeofcmds];
fi->readx(rawmseg, mhdri.sizeofcmds);
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));
unsigned orig_file_size = get_native32(&hbuf.p_filesize); unsigned orig_file_size = get_te32(&hbuf.p_filesize);
blocksize = get_native32(&hbuf.p_blocksize); blocksize = get_te32(&hbuf.p_blocksize);
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size) if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
throwCantUnpack("file header corrupted"); throwCantUnpack("file header corrupted");
ibuf.alloc(blocksize + OVERHEAD); ibuf.alloc(blocksize + OVERHEAD);
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr)); b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
fi->readx(&bhdr, sizeof(bhdr)); fi->readx(&bhdr, sizeof(bhdr));
ph.u_len = get_native32(&bhdr.sz_unc); ph.u_len = get_te32(&bhdr.sz_unc);
ph.c_len = get_native32(&bhdr.sz_cpr); ph.c_len = get_te32(&bhdr.sz_cpr);
ph.method = bhdr.b_method; ph.method = bhdr.b_method;
ph.filter = bhdr.b_ftid; ph.filter = bhdr.b_ftid;
ph.filter_cto = bhdr.b_cto8; ph.filter_cto = bhdr.b_cto8;
@@ -551,14 +1003,14 @@ void PackMachBase<T>::unpack(OutputFile *fo)
qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command); qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command);
n_segment = 0; n_segment = 0;
for (unsigned j= 0; j < ncmds; ++j) { for (unsigned j= 0; j < ncmds; ++j) {
n_segment += (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd); n_segment += (lc_seg==msegcmd[j].cmd);
} }
unsigned total_in = 0; unsigned total_in = 0;
unsigned total_out = 0; unsigned total_out = 0;
unsigned c_adler = upx_adler32(NULL, 0); unsigned c_adler = upx_adler32(NULL, 0);
unsigned u_adler = upx_adler32(NULL, 0); unsigned u_adler = upx_adler32(NULL, 0);
Mach_segment_command const *sc = (Mach_segment_command const *)(1+ mhdr); Mach_segment_command const *sc = (Mach_segment_command const *)(void *)(1+ mhdr);
unsigned k; unsigned k;
fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR); fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR);
@@ -567,12 +1019,38 @@ void PackMachBase<T>::unpack(OutputFile *fo)
k < ncmds; k < ncmds;
(++k), (sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc)) (++k), (sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc))
) { ) {
if (Mach_segment_command::LC_SEGMENT==sc->cmd if (lc_seg==sc->cmd
&& 0!=sc->filesize ) { && 0!=sc->filesize ) {
unsigned filesize = sc->filesize; unsigned filesize = sc->filesize;
unpackExtent(filesize, fo, total_in, total_out, c_adler, u_adler, false, sizeof(bhdr)); unpackExtent(filesize, fo, total_in, total_out,
c_adler, u_adler, false, sizeof(bhdr));
if (my_filetype==Mach_header::MH_DYLIB) {
break;
} }
} }
}
if (my_filetype==Mach_header::MH_DYLIB) {
Mach_segment_command const *rc = rawmseg;
rc = (Mach_segment_command const *)(rc->cmdsize + (char const *)rc);
sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc);
for (
k=1;
k < ncmds;
(++k), (sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc)),
(rc = (Mach_segment_command const *)(rc->cmdsize + (char const *)rc))
) {
if (lc_seg==rc->cmd
&& 0!=rc->filesize ) {
fi->seek(rc->fileoff, SEEK_SET);
fo->seek(sc->fileoff, SEEK_SET);
unsigned const len = rc->filesize;
MemBuffer data(len);
fi->readx(data, len);
fo->write(data, len);
}
}
}
else
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) {
@@ -583,44 +1061,55 @@ void PackMachBase<T>::unpack(OutputFile *fo)
c_adler, u_adler, false, sizeof(bhdr)); c_adler, u_adler, false, sizeof(bhdr));
} }
} }
delete mhdr;
} }
template <class T> template <class T>
bool PackMachBase<T>::canPack() bool PackMachBase<T>::canPack()
{ {
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
fi->readx(&mhdri, sizeof(mhdri)); fi->readx(&mhdri, sizeof(mhdri));
if (Mach_header::MH_MAGIC !=mhdri.magic if ((Mach_header::MH_MAGIC + (sizeof(Addr)>>3)) !=mhdri.magic
|| my_cputype !=mhdri.cputype || my_cputype !=mhdri.cputype
|| Mach_header::MH_EXECUTE !=mhdri.filetype || my_filetype !=mhdri.filetype
) )
return false; return false;
rawmseg = (Mach_segment_command *)new char[mhdri.sizeofcmds]; rawmseg = (Mach_segment_command *)new char[(unsigned) mhdri.sizeofcmds];
fi->readx(rawmseg, mhdri.sizeofcmds); fi->readx(rawmseg, mhdri.sizeofcmds);
msegcmd = new Mach_segment_command[mhdri.ncmds]; unsigned const ncmds = mhdri.ncmds;
unsigned char *ptr = (unsigned char *)rawmseg; msegcmd = new Mach_segment_command[ncmds];
for (unsigned j= 0; j < mhdri.ncmds; ++j) { unsigned char const *ptr = (unsigned char const *)rawmseg;
msegcmd[j] = *(Mach_segment_command *)ptr; for (unsigned j= 0; j < ncmds; ++j) {
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize; msegcmd[j] = *(Mach_segment_command const *)ptr;
if (((Mach_segment_command const *)ptr)->cmd ==
Mach_segment_command::LC_ROUTINES) {
o_routines_cmd = (const char *)ptr - (const char *)rawmseg;
prev_init_address = ((Mach_routines_command const *)ptr)->init_address;
}
ptr += (unsigned) ((const Mach_segment_command *)ptr)->cmdsize;
}
if (Mach_header::MH_DYLIB==my_filetype && 0==o_routines_cmd) {
infoWarning("missing -init function");
return false;
} }
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr. // Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
qsort(msegcmd, mhdri.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 that LC_SEGMENTs form one contiguous chunk of the file.
for (unsigned j= 0; j < mhdri.ncmds; ++j) { for (unsigned j= 0; j < ncmds; ++j) {
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd) { if (lc_seg==msegcmd[j].cmd) {
if (0xfff & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) { if (~PAGE_MASK & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) {
return false; return false;
} }
if (0 < j) { if (0 < j) {
unsigned const sz = ~0xfff unsigned const sz = PAGE_MASK
& (0xfff + msegcmd[j-1].filesize); & (~PAGE_MASK + msegcmd[j-1].filesize);
if ((sz + msegcmd[j-1].fileoff)!=msegcmd[j].fileoff) { if ((sz + msegcmd[j-1].fileoff)!=msegcmd[j].fileoff) {
return false; return false;
} }
@@ -643,6 +1132,7 @@ bool PackMachBase<T>::canPack()
template class PackMachBase<MachClass_BE32>; template class PackMachBase<MachClass_BE32>;
template class PackMachBase<MachClass_LE32>; template class PackMachBase<MachClass_LE32>;
template class PackMachBase<MachClass_LE64>;
PackMachFat::PackMachFat(InputFile *f) : super(f) PackMachFat::PackMachFat(InputFile *f) : super(f)
@@ -682,18 +1172,42 @@ void PackMachFat::pack(OutputFile *fo)
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);
switch (fat_head.arch[j].cputype) { switch (fat_head.arch[j].cputype) {
case PackMachFat::CPU_TYPE_I386: { case PackMachFat::CPU_TYPE_I386: {
typedef N_Mach::Mach_header<MachClass_LE32::MachITypes> Mach_header;
Mach_header hdr;
fi->readx(&hdr, sizeof(hdr));
if (hdr.filetype==Mach_header::MH_EXECUTE) {
PackMachI386 packer(fi); PackMachI386 packer(fi);
packer.initPackHeader(); packer.initPackHeader();
packer.canPack(); packer.canPack();
packer.updatePackHeader(); packer.updatePackHeader();
packer.pack(fo); packer.pack(fo);
}
else if (hdr.filetype==Mach_header::MH_DYLIB) {
PackDylibI386 packer(fi);
packer.initPackHeader();
packer.canPack();
packer.updatePackHeader();
packer.pack(fo);
}
} break; } break;
case PackMachFat::CPU_TYPE_POWERPC: { case PackMachFat::CPU_TYPE_POWERPC: {
typedef N_Mach::Mach_header<MachClass_BE32::MachITypes> Mach_header;
Mach_header hdr;
fi->readx(&hdr, sizeof(hdr));
if (hdr.filetype==Mach_header::MH_EXECUTE) {
PackMachPPC32 packer(fi); PackMachPPC32 packer(fi);
packer.initPackHeader(); packer.initPackHeader();
packer.canPack(); packer.canPack();
packer.updatePackHeader(); packer.updatePackHeader();
packer.pack(fo); packer.pack(fo);
}
else if (hdr.filetype==Mach_header::MH_DYLIB) {
PackDylibPPC32 packer(fi);
packer.initPackHeader();
packer.canPack();
packer.updatePackHeader();
packer.pack(fo);
}
} break; } break;
} // switch cputype } // switch cputype
fat_head.arch[j].offset = base; fat_head.arch[j].offset = base;
@@ -725,16 +1239,38 @@ void PackMachFat::unpack(OutputFile *fo)
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);
switch (fat_head.arch[j].cputype) { switch (fat_head.arch[j].cputype) {
case PackMachFat::CPU_TYPE_I386: { case PackMachFat::CPU_TYPE_I386: {
N_Mach::Mach_header<MachClass_LE32::MachITypes> hdr;
typedef N_Mach::Mach_header<MachClass_LE32::MachITypes> Mach_header;
fi->readx(&hdr, sizeof(hdr));
if (hdr.filetype==Mach_header::MH_EXECUTE) {
PackMachI386 packer(fi); PackMachI386 packer(fi);
packer.initPackHeader(); packer.initPackHeader();
packer.canUnpack(); packer.canUnpack();
packer.unpack(fo); packer.unpack(fo);
}
else if (hdr.filetype==Mach_header::MH_DYLIB) {
PackDylibI386 packer(fi);
packer.initPackHeader();
packer.canUnpack();
packer.unpack(fo);
}
} break; } break;
case PackMachFat::CPU_TYPE_POWERPC: { case PackMachFat::CPU_TYPE_POWERPC: {
N_Mach::Mach_header<MachClass_BE32::MachITypes> hdr;
typedef N_Mach::Mach_header<MachClass_BE32::MachITypes> Mach_header;
fi->readx(&hdr, sizeof(hdr));
if (hdr.filetype==Mach_header::MH_EXECUTE) {
PackMachPPC32 packer(fi); PackMachPPC32 packer(fi);
packer.initPackHeader(); packer.initPackHeader();
packer.canUnpack(); packer.canUnpack();
packer.unpack(fo); packer.unpack(fo);
}
else if (hdr.filetype==Mach_header::MH_DYLIB) {
PackDylibPPC32 packer(fi);
packer.initPackHeader();
packer.canUnpack();
packer.unpack(fo);
}
} break; } break;
} // switch cputype } // switch cputype
fat_head.arch[j].offset = base; fat_head.arch[j].offset = base;
@@ -762,13 +1298,19 @@ bool PackMachFat::canPack()
default: return false; default: return false;
case PackMachFat::CPU_TYPE_I386: { case PackMachFat::CPU_TYPE_I386: {
PackMachI386 packer(fi); PackMachI386 packer(fi);
if (!packer.canPack()) if (!packer.canPack()) {
PackDylibI386 pack2r(fi);
if (!pack2r.canPack())
return false; return false;
}
} break; } break;
case PackMachFat::CPU_TYPE_POWERPC: { case PackMachFat::CPU_TYPE_POWERPC: {
PackMachPPC32 packer(fi); PackMachPPC32 packer(fi);
if (!packer.canPack()) if (!packer.canPack()) {
PackDylibPPC32 pack2r(fi);
if (!pack2r.canPack())
return false; return false;
}
} break; } break;
} // switch cputype } // switch cputype
} }
@@ -797,14 +1339,26 @@ int PackMachFat::canUnpack()
default: return false; default: return false;
case PackMachFat::CPU_TYPE_I386: { case PackMachFat::CPU_TYPE_I386: {
PackMachI386 packer(fi); PackMachI386 packer(fi);
if (!packer.canUnpack()) if (!packer.canUnpack()) {
PackDylibI386 pack2r(fi);
if (!pack2r.canUnpack())
return 0; return 0;
else
ph.format = pack2r.getFormat(); // FIXME: copy entire PackHeader
}
else
ph.format = packer.getFormat(); // FIXME: copy entire PackHeader ph.format = packer.getFormat(); // FIXME: copy entire PackHeader
} break; } break;
case PackMachFat::CPU_TYPE_POWERPC: { case PackMachFat::CPU_TYPE_POWERPC: {
PackMachPPC32 packer(fi); PackMachPPC32 packer(fi);
if (!packer.canUnpack()) if (!packer.canUnpack()) {
PackDylibPPC32 pack2r(fi);
if (!pack2r.canUnpack())
return 0; return 0;
else
ph.format = pack2r.getFormat(); // FIXME: copy entire PackHeader
}
else
ph.format = packer.getFormat(); // FIXME: copy entire PackHeader ph.format = packer.getFormat(); // FIXME: copy entire PackHeader
} break; } break;
} // switch cputype } // switch cputype
+363 -104
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -30,24 +30,22 @@
#define __UPX_P_MACHO_H #define __UPX_P_MACHO_H
struct Mach_fat_header { __packed_struct(Mach_fat_header)
BE32 magic; BE32 magic;
enum { // note conflict with java bytecode PackLinuxI386 enum { // note conflict with java bytecode PackLinuxI386
FAT_MAGIC = 0xcafebabe, FAT_MAGIC = 0xcafebabe,
FAT_MAGIC_SWAB = 0xbebafeca FAT_MAGIC_SWAB = 0xbebafeca
}; };
BE32 nfat_arch; // Number of Mach_fat_arch which follow. BE32 nfat_arch; // Number of Mach_fat_arch which follow.
} __packed_struct_end()
__attribute_packed;
struct Mach_fat_arch { __packed_struct(Mach_fat_arch)
BE32 cputype; BE32 cputype;
BE32 cpusubtype; BE32 cpusubtype;
BE32 offset; BE32 offset;
BE32 size; BE32 size;
BE32 align; /* shift count; log base 2 */ BE32 align; /* shift count; log base 2 */
} __packed_struct_end()
__attribute_packed;
/************************************************************************* /*************************************************************************
@@ -68,8 +66,7 @@ struct MachITypes
}; };
template <class TMachITypes> template <class TMachITypes>
struct Mach_header __packed_struct(Mach_header)
{
typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Word Word;
Word magic; Word magic;
@@ -81,12 +78,11 @@ struct Mach_header
Word flags; Word flags;
#define WANT_MACH_HEADER_ENUM 1 #define WANT_MACH_HEADER_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes> template <class TMachITypes>
struct Mach_header64 __packed_struct(Mach_header64)
{ // only difference is padding to 0 mod 8 // only difference is padding to 0 mod 8
typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Word Word;
Word magic; Word magic;
@@ -99,12 +95,10 @@ struct Mach_header64
Word reserved; // pad to 0 mod 8 Word reserved; // pad to 0 mod 8
#define WANT_MACH_HEADER_ENUM 1 #define WANT_MACH_HEADER_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes> template <class TMachITypes>
struct Mach_segment_command __packed_struct(Mach_segment_command)
{
typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Addr Addr; typedef typename TMachITypes::Addr Addr;
typedef typename TMachITypes::Off Off; typedef typename TMachITypes::Off Off;
@@ -122,12 +116,10 @@ struct Mach_segment_command
Word flags; Word flags;
#define WANT_MACH_SEGMENT_ENUM 1 #define WANT_MACH_SEGMENT_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes> template <class TMachITypes>
struct Mach_section_command __packed_struct(Mach_section_command)
{
typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Addr Addr; typedef typename TMachITypes::Addr Addr;
typedef typename TMachITypes::Off Off; typedef typename TMachITypes::Off Off;
@@ -145,12 +137,95 @@ struct Mach_section_command
Word reserved2; Word reserved2;
#define WANT_MACH_SECTION_ENUM 1 #define WANT_MACH_SECTION_ENUM 1
#include "p_mach_enum.h" #include "p_mach_enum.h"
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes> template <class TMachITypes>
struct Mach_ppc_thread_state __packed_struct(Mach_symtab_command)
{ typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Off Off;
Word cmd; /* LC_SYMTAB */
Word cmdsize; /* sizeof(struct Mach_symtab_command) */
Off symoff; /* symbol table offset */
Word nsyms; /* number of symbol table entries */
Off stroff; /* string table offset */
Word strsize; /* string table size in bytes */
__packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_dysymtab_command)
typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Off Off;
Word cmd; /* LC_DYSYMTAB */
Word cmdsize; /* sizeof(struct Mach_dysymtab_command) */
Word ilocalsym; /* index to local symbols */
Word nlocalsym; /* number of local symbols */
Word iextdefsym; /* index to externally defined symbols */
Word nextdefsym; /* number of externally defined symbols */
Word iundefsym; /* index to undefined symbols */
Word nundefsym; /* number of undefined symbols */
Off tocoff; /* file offset to table of contents */
Word ntoc; /* number of entries in table of contents */
Off modtaboff; /* file offset to module table */
Word nmodtab; /* number of module table entries */
Off extrefsymoff; /* offset to referenced symbol table */
Word nextrefsymoff; /* number of referenced symbol table entries */
Off indirectsymoff; /* file offset to the indirect symbol table */
Word nindirectsyms; /* number of indirect symbol table entries */
Off extreloff; /* offset to external relocation entries */
Word nextrel; /* number of external relocation entries */
Off locreloff; /* offset to local relocation entries */
Word nlocrel; /* number of local relocation entries */
__packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_segsplit_info_command)
typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Off Off;
Word cmd; /* LC_SEGMENT_SPLIT_INFO */
Word cmdsize; /* sizeof(struct Mach_segsplit_info_command) */
Off dataoff;
Word datasize;
__packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_routines_command)
typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Addr Addr;
typedef typename TMachITypes::Off Off;
Word cmd;
Word cmdsize;
Addr init_address;
Word init_module;
Word reserved1;
Word reserved2;
Word reserved3;
Word reserved4;
Word reserved5;
Word reserved6;
#define WANT_MACH_SEGMENT_ENUM 1
#include "p_mach_enum.h"
__packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_twolevel_hints_command)
typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Addr Addr;
typedef typename TMachITypes::Off Off;
Word cmd;
Word cmdsize;
Off offset; /* offset to the hint table */
Word nhints; /* number of hints */
#define WANT_MACH_SEGMENT_ENUM 1
#include "p_mach_enum.h"
__packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_ppc_thread_state)
typedef typename TMachITypes::Addr Addr; typedef typename TMachITypes::Addr Addr;
Addr srr0; /* Instruction address register (PC; entry addr) */ Addr srr0; /* Instruction address register (PC; entry addr) */
@@ -167,12 +242,10 @@ struct Mach_ppc_thread_state
Addr mq; /* MQ register (601 only) */ Addr mq; /* MQ register (601 only) */
Addr vrsave; /* Vector Save Register */ Addr vrsave; /* Vector Save Register */
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes> template <class TMachITypes>
struct Mach_i386_thread_state __packed_struct(Mach_i386_thread_state)
{
typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Word Word;
Word eax, ebx, ecx, edx; Word eax, ebx, ecx, edx;
@@ -181,12 +254,22 @@ struct Mach_i386_thread_state
Word eflags; Word eflags;
Word eip, cs; Word eip, cs;
Word ds, es, fs, gs; Word ds, es, fs, gs;
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes> template <class TMachITypes>
struct Mach_i386_new_thread_state __packed_struct(Mach_AMD64_thread_state)
{ typedef typename TMachITypes::Xword Xword;
Xword rax, rbx, rcx, rdx;
Xword rdi, rsi, rbp, rsp;
Xword r8, r9, r10, r11;
Xword r12, r13, r14, r15;
Xword rip, rflags;
Xword cs, fs, gs;
__packed_struct_end()
template <class TMachITypes>
__packed_struct(Mach_i386_new_thread_state)
typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Word Word;
Word gs, fs, es, ds; Word gs, fs, es, ds;
@@ -194,8 +277,18 @@ struct Mach_i386_new_thread_state
Word ebx, edx, ecx, eax; Word ebx, edx, ecx, eax;
Word eip, cs, efl; Word eip, cs, efl;
Word uesp, ss; Word uesp, ss;
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes>
__packed_struct(Mach_ARM_thread_state)
typedef typename TMachITypes::Word Word;
Word r[13]; // r0-r12
Word sp; // r13
Word lr; // r14
Word pc; // r15
Word cpsr;
__packed_struct_end()
} // namespace N_Mach } // namespace N_Mach
@@ -206,8 +299,7 @@ namespace N_Mach32 {
namespace N_Mach64 { namespace N_Mach64 {
template <class TMachITypes> template <class TMachITypes>
struct Mach_ppc_thread_state64 __packed_struct(Mach_ppc_thread_state64)
{
typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Xword Xword; typedef typename TMachITypes::Xword Xword;
@@ -224,8 +316,27 @@ struct Mach_ppc_thread_state64
Xword ctr; /* Count register */ Xword ctr; /* Count register */
Word vrsave; /* Vector Save Register */ Word vrsave; /* Vector Save Register */
} __packed_struct_end()
__attribute_packed;
template <class TMachITypes>
__packed_struct(Mach_routines_command_64)
typedef typename TMachITypes::Word Word;
typedef typename TMachITypes::Addr Addr;
typedef typename TMachITypes::Xword Xword;
Word cmd;
Word cmdsize;
Addr init_address;
Xword init_module;
Xword reserved1;
Xword reserved2;
Xword reserved3;
Xword reserved4;
Xword reserved5;
Xword reserved6;
#define WANT_MACH_SEGMENT_ENUM 1
#include "p_mach_enum.h"
__packed_struct_end()
} // namespace N_Mach64 } // namespace N_Mach64
@@ -236,13 +347,13 @@ struct MachClass_32
{ {
typedef TP BeLePolicy; typedef TP BeLePolicy;
// integral types // integral types (target endianness)
typedef typename TP::U16 U16; typedef typename TP::U16 TE16;
typedef typename TP::U32 U32; typedef typename TP::U32 TE32;
typedef typename TP::U64 U64; typedef typename TP::U64 TE64;
typedef N_Mach::MachITypes<U32, U64, U32, U32> MachITypes; typedef N_Mach::MachITypes<TE32, TE64, TE32, TE32> MachITypes;
#if (ACC_CC_BORLANDC) #if (ACC_CC_BORLANDC)
typedef U32 Addr; typedef TE32 Addr;
#else #else
typedef typename MachITypes::Addr Addr; typedef typename MachITypes::Addr Addr;
#endif #endif
@@ -251,8 +362,15 @@ struct MachClass_32
typedef N_Mach::Mach_header<MachITypes> Mach_header; typedef N_Mach::Mach_header<MachITypes> Mach_header;
typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command; typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command; typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command;
typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_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_twolevel_hints_command<MachITypes> Mach_twolevel_hints_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_ARM_thread_state<MachITypes> Mach_ARM_thread_state;
static void compileTimeAssertions() { static void compileTimeAssertions() {
BeLePolicy::compileTimeAssertions(); BeLePolicy::compileTimeAssertions();
@@ -265,19 +383,30 @@ struct MachClass_64
{ {
typedef TP BeLePolicy; typedef TP BeLePolicy;
// integral types // integral types (target endianness)
typedef typename TP::U16 U16; typedef typename TP::U16 TE16;
typedef typename TP::U32 U32; typedef typename TP::U32 TE32;
typedef typename TP::U64 U64; typedef typename TP::U64 TE64;
typedef N_Mach::MachITypes<U32, U64, U64, U64> MachITypes; typedef N_Mach::MachITypes<TE32, TE64, TE64, TE64> MachITypes;
#if (ACC_CC_BORLANDC)
typedef TE64 Addr;
#else
typedef typename MachITypes::Addr Addr;
#endif
// Mach types // Mach types
typedef N_Mach::Mach_header64<MachITypes> Mach_header; typedef N_Mach::Mach_header64<MachITypes> Mach_header;
typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command; typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command; typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command;
typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_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_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
static void compileTimeAssertions() { static void compileTimeAssertions() {
BeLePolicy::compileTimeAssertions(); BeLePolicy::compileTimeAssertions();
COMPILE_TIME_ASSERT(sizeof(Addr) == 8)
} }
}; };
@@ -293,24 +422,56 @@ typedef N_Mach::MachClass_64<N_BELE_CTP::LEPolicy> MachClass_LE64;
// shortcuts // shortcuts
typedef MachClass_Host32::Mach_segment_command Mach32_segment_command; typedef MachClass_Host32::Mach_segment_command Mach32_segment_command;
typedef MachClass_Host32::Mach_section_command Mach32_section_command; typedef MachClass_Host32::Mach_section_command Mach32_section_command;
typedef MachClass_Host32::Mach_symtab_command Mach32_symtab_command;
typedef MachClass_Host32::Mach_dysymtab_command Mach32_dysymtab_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_twolevel_hints_command Mach32_twolevel_hints_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;
typedef MachClass_Host64::Mach_symtab_command Mach64_symtab_command;
typedef MachClass_Host64::Mach_dysymtab_command Mach64_dysymtab_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_twolevel_hints_command Mach64_twolevel_hints_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;
typedef MachClass_BE32::Mach_symtab_command MachBE32_symtab_command;
typedef MachClass_BE32::Mach_dysymtab_command MachBE32_dysymtab_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_twolevel_hints_command MachBE32_twolevel_hints_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;
typedef MachClass_BE64::Mach_symtab_command MachBE64_symtab_command;
typedef MachClass_BE64::Mach_dysymtab_command MachBE64_dysymtab_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_twolevel_hints_command MachBE64_twolevel_hints_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;
typedef MachClass_LE32::Mach_symtab_command MachLE32_symtab_command;
typedef MachClass_LE32::Mach_dysymtab_command MachLE32_dysymtab_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_twolevel_hints_command MachLE32_twolevel_hints_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;
typedef MachClass_LE64::Mach_symtab_command MachLE64_symtab_command;
typedef MachClass_LE64::Mach_dysymtab_command MachLE64_dysymtab_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_twolevel_hints_command MachLE64_twolevel_hints_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;
typedef MachClass_LE32::Mach_AMD64_thread_state Mach_AMD64_thread_state; // FIXME LE32 vs AMD64
typedef MachClass_LE32::Mach_ARM_thread_state Mach_ARM_thread_state;
#include "p_unix.h" #include "p_unix.h"
@@ -322,18 +483,24 @@ protected:
typedef TMachClass MachClass; typedef TMachClass MachClass;
typedef typename MachClass::BeLePolicy BeLePolicy; typedef typename MachClass::BeLePolicy BeLePolicy;
typedef typename MachClass::MachITypes MachITypes; typedef typename MachClass::MachITypes MachITypes;
// integral types // integral types (target endianness)
typedef typename MachClass::U16 U16; typedef typename MachClass::TE16 TE16;
typedef typename MachClass::U32 U32; typedef typename MachClass::TE32 TE32;
typedef typename MachClass::U64 U64; typedef typename MachClass::TE64 TE64;
typedef typename MachClass::Addr Addr; typedef typename MachClass::Addr Addr;
// Mach types // Mach types
typedef typename MachClass::Mach_header Mach_header; typedef typename MachClass::Mach_header Mach_header;
typedef typename MachClass::Mach_segment_command Mach_segment_command; typedef typename MachClass::Mach_segment_command Mach_segment_command;
typedef typename MachClass::Mach_section_command Mach_section_command; typedef typename MachClass::Mach_section_command Mach_section_command;
typedef typename MachClass::Mach_symtab_command Mach_symtab_command;
typedef typename MachClass::Mach_dysymtab_command Mach_dysymtab_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_twolevel_hints_command Mach_twolevel_hints_command;
public: public:
PackMachBase(InputFile *, unsigned cpuid, unsigned t_flavor, unsigned ts_word_cnt, unsigned tc_size); PackMachBase(InputFile *, unsigned cpuid, unsigned filetype,
unsigned t_flavor, unsigned ts_word_cnt, unsigned tc_size);
virtual ~PackMachBase(); virtual ~PackMachBase();
virtual int getVersion() const { return 13; } virtual int getVersion() const { return 13; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
@@ -344,6 +511,8 @@ public:
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
virtual void pack4dylib(OutputFile *, Filter &, Addr init_address);
virtual void pack1_setup_threado(OutputFile *const fo) = 0; virtual void pack1_setup_threado(OutputFile *const fo) = 0;
virtual void unpack(OutputFile *fo); virtual void unpack(OutputFile *fo);
@@ -366,6 +535,7 @@ protected:
static int __acc_cdecl_qsort compare_segment_command(void const *aa, void const *bb); static int __acc_cdecl_qsort compare_segment_command(void const *aa, void const *bb);
unsigned my_cputype; unsigned my_cputype;
unsigned my_filetype;
unsigned my_thread_flavor; unsigned my_thread_flavor;
unsigned my_thread_state_word_count; unsigned my_thread_state_word_count;
unsigned my_thread_command_size; unsigned my_thread_command_size;
@@ -375,37 +545,47 @@ protected:
unsigned sz_mach_headers; unsigned sz_mach_headers;
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 prev_init_address;
Mach_header mhdri; Mach_header mhdri;
Mach_header mhdro; Mach_header mhdro;
Mach_segment_command segcmdo; Mach_segment_command segcmdo;
struct b_info { // 12-byte header before each compressed block __packed_struct(b_info) // 12-byte header before each compressed block
U32 sz_unc; // uncompressed_size TE32 sz_unc; // uncompressed_size
U32 sz_cpr; // compressed_size TE32 sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter unsigned char b_cto8; // filter parameter
unsigned char b_unused; unsigned char b_unused;
} __packed_struct_end()
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader __packed_struct(l_info) // 12-byte trailer in header for loader
U32 l_checksum; TE32 l_checksum;
LE32 l_magic; LE32 l_magic;
U16 l_lsize; TE16 l_lsize;
unsigned char l_version; unsigned char l_version;
unsigned char l_format; unsigned char l_format;
} __packed_struct_end()
__attribute_packed;
struct p_info { // 12-byte packed program header __packed_struct(p_info) // 12-byte packed program header
U32 p_progid; TE32 p_progid;
U32 p_filesize; TE32 p_filesize;
U32 p_blocksize; TE32 p_blocksize;
} __packed_struct_end()
__attribute_packed;
struct l_info linfo; struct l_info linfo;
static void compileTimeAssertions() {
MachClass::compileTimeAssertions();
COMPILE_TIME_ASSERT(sizeof(b_info) == 12)
COMPILE_TIME_ASSERT(sizeof(l_info) == 12)
COMPILE_TIME_ASSERT(sizeof(p_info) == 12)
COMPILE_TIME_ASSERT_ALIGNED1(b_info)
COMPILE_TIME_ASSERT_ALIGNED1(l_info)
COMPILE_TIME_ASSERT_ALIGNED1(p_info)
}
}; };
@@ -414,21 +594,12 @@ class PackMachPPC32 : public PackMachBase<MachClass_BE32>
typedef PackMachBase<MachClass_BE32> super; typedef PackMachBase<MachClass_BE32> super;
public: public:
PackMachPPC32(InputFile *f) : super(f, Mach_header::CPU_TYPE_POWERPC, PackMachPPC32(InputFile *f);
Mach_thread_command::PPC_THREAD_STATE,
sizeof(Mach_ppc_thread_state)>>2, sizeof(threado)) { }
virtual int getFormat() const { return UPX_F_MACH_PPC32; } virtual int getFormat() const { return UPX_F_MACH_PPC32; }
virtual const char *getName() const { return "Mach/ppc32"; } virtual const char *getName() const { return "Mach/ppc32"; }
virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.macho"; } virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.macho"; }
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
protected: protected:
virtual const int *getFilters() const; virtual const int *getFilters() const;
@@ -438,8 +609,7 @@ protected:
virtual Linker* newLinker() const; virtual Linker* newLinker() const;
virtual void buildLoader(const Filter *ft); virtual void buildLoader(const Filter *ft);
struct Mach_thread_command __packed_struct(Mach_thread_command)
{
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */ BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
BE32 cmdsize; /* total size of this command */ BE32 cmdsize; /* total size of this command */
BE32 flavor; BE32 flavor;
@@ -447,19 +617,33 @@ protected:
Mach_ppc_thread_state state; Mach_ppc_thread_state state;
#define WANT_MACH_THREAD_ENUM #define WANT_MACH_THREAD_ENUM
#include "p_mach_enum.h" #include "p_mach_enum.h"
} __packed_struct_end()
__attribute_packed;
Mach_thread_command threado; Mach_thread_command threado;
}; };
class PackDylibPPC32 : public PackMachPPC32
{
typedef PackMachPPC32 super;
public:
PackDylibPPC32(InputFile *f);
virtual int getFormat() const { return UPX_F_DYLIB_PPC32; }
virtual const char *getName() const { return "Dylib/ppc32"; }
virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.dylib"; }
protected:
virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append PackHeader
virtual void buildLoader(const Filter *ft);
};
class PackMachI386 : public PackMachBase<MachClass_LE32> class PackMachI386 : public PackMachBase<MachClass_LE32>
{ {
typedef PackMachBase<MachClass_LE32> super; typedef PackMachBase<MachClass_LE32> super;
public: public:
PackMachI386(InputFile *f) : super(f, Mach_header::CPU_TYPE_I386, PackMachI386(InputFile *f);
(unsigned)Mach_thread_command::i386_THREAD_STATE,
sizeof(Mach_i386_thread_state)>>2, sizeof(threado)) { }
virtual int getFormat() const { return UPX_F_MACH_i386; } virtual int getFormat() const { return UPX_F_MACH_i386; }
virtual const char *getName() const { return "Mach/i386"; } virtual const char *getName() const { return "Mach/i386"; }
@@ -467,13 +651,6 @@ public:
protected: protected:
virtual const int *getFilters() const; virtual const int *getFilters() const;
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
virtual void pack1_setup_threado(OutputFile *const fo); virtual void pack1_setup_threado(OutputFile *const fo);
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
@@ -481,8 +658,7 @@ protected:
virtual void buildLoader(const Filter *ft); virtual void buildLoader(const Filter *ft);
virtual void addStubEntrySections(Filter const *); virtual void addStubEntrySections(Filter const *);
struct Mach_thread_command __packed_struct(Mach_thread_command)
{
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */ LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
LE32 cmdsize; /* total size of this command */ LE32 cmdsize; /* total size of this command */
LE32 flavor; LE32 flavor;
@@ -490,8 +666,91 @@ protected:
Mach_i386_thread_state state; Mach_i386_thread_state state;
#define WANT_MACH_THREAD_ENUM #define WANT_MACH_THREAD_ENUM
#include "p_mach_enum.h" #include "p_mach_enum.h"
} __packed_struct_end()
__attribute_packed;
Mach_thread_command threado;
};
class PackDylibI386 : public PackMachI386
{
typedef PackMachI386 super;
public:
PackDylibI386(InputFile *f);
virtual int getFormat() const { return UPX_F_DYLIB_i386; }
virtual const char *getName() const { return "Dylib/i386"; }
virtual const char *getFullName(const options_t *) const { return "i386-darwin.dylib"; }
protected:
virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append PackHeader
virtual void buildLoader(const Filter *ft);
};
class PackMachAMD64 : public PackMachBase<MachClass_LE64>
{
typedef PackMachBase<MachClass_LE64> super;
public:
PackMachAMD64(InputFile *f);
virtual int getFormat() const { return UPX_F_MACH_AMD64; }
virtual const char *getName() const { return "Mach/AMD64"; }
virtual const char *getFullName(const options_t *) const { return "AMD64-darwin.macho"; }
protected:
virtual const int *getFilters() const;
virtual void pack1_setup_threado(OutputFile *const fo);
virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append PackHeader
virtual Linker* newLinker() const;
virtual void buildLoader(const Filter *ft);
virtual void addStubEntrySections(Filter const *);
__packed_struct(Mach_thread_command)
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
LE32 cmdsize; /* total size of this command */
LE32 flavor;
LE32 count; /* sizeof(following_thread_state)/4 */
Mach_AMD64_thread_state state;
#define WANT_MACH_THREAD_ENUM
#include "p_mach_enum.h"
__packed_struct_end()
Mach_thread_command threado;
};
class PackMachARMEL : public PackMachBase<MachClass_LE32>
{
typedef PackMachBase<MachClass_LE32> super;
public:
PackMachARMEL(InputFile *f);
virtual int getFormat() const { return UPX_F_MACH_ARMEL; }
virtual const char *getName() const { return "Mach/ARMEL"; }
virtual const char *getFullName(const options_t *) const { return "ARMEL-darwin.macho"; }
protected:
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack1_setup_threado(OutputFile *const fo);
virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append PackHeader
virtual Linker* newLinker() const;
virtual void buildLoader(const Filter *ft);
virtual void addStubEntrySections(Filter const *);
__packed_struct(Mach_thread_command)
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
LE32 cmdsize; /* total size of this command */
LE32 flavor;
LE32 count; /* sizeof(following_thread_state)/4 */
Mach_ARM_thread_state state;
#define WANT_MACH_THREAD_ENUM
#include "p_mach_enum.h"
__packed_struct_end()
Mach_thread_command threado; Mach_thread_command threado;
}; };
@@ -529,11 +788,11 @@ public:
#endif #endif
enum { N_FAT_ARCH = 5 }; enum { N_FAT_ARCH = 5 };
protected: protected:
struct Fat_head { __packed_struct(Fat_head)
struct Mach_fat_header fat; struct Mach_fat_header fat;
struct Mach_fat_arch arch[N_FAT_ARCH]; struct Mach_fat_arch arch[N_FAT_ARCH];
} __packed_struct_end()
__attribute_packed;
Fat_head fat_head; Fat_head fat_head;
// UI handler // UI handler
+29 -5
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 John F. Reiser Copyright (C) 2007-2009 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
@@ -40,11 +40,19 @@
}; };
enum { // cputype enum { // cputype
CPU_TYPE_I386 = 7, CPU_TYPE_I386 = 7,
CPU_TYPE_X86_64 = 0x01000007,
CPU_TYPE_ARM = 12,
CPU_TYPE_POWERPC = 0x00000012, CPU_TYPE_POWERPC = 0x00000012,
CPU_TYPE_POWERPC64 = 0x01000012 CPU_TYPE_POWERPC64 = 0x01000012
}; };
enum { // cpusubtype
CPU_SUBTYPE_ARM_ALL = 0,
CPU_SUBTYPE_ARM_V4T = 5,
CPU_SUBTYPE_ARM_V6 = 6
};
enum { // filetype enum { // filetype
MH_EXECUTE = 2 MH_EXECUTE = 2,
MH_DYLIB = 6
}; };
enum { // flags enum { // flags
MH_NOUNDEFS = 1 MH_NOUNDEFS = 1
@@ -55,10 +63,23 @@
#undef WANT_MACH_SEGMENT_ENUM #undef WANT_MACH_SEGMENT_ENUM
enum { // cmd enum { // cmd
LC_SEGMENT = 0x1, LC_SEGMENT = 0x1,
LC_SYMTAB = 0x2,
LC_THREAD = 0x4, LC_THREAD = 0x4,
LC_UNIXTHREAD = 0x5, LC_UNIXTHREAD = 0x5,
LC_DYSYMTAB = 0xb,
LC_LOAD_DYLIB = 0xc,
LC_ID_DYLIB = 0xd,
LC_LOAD_DYLINKER = 0xe, LC_LOAD_DYLINKER = 0xe,
LC_SEGMENT_64 = 0x19 LC_ROUTINES = 0x11,
LC_TWOLEVEL_HINTS= 0x16,
LC_SEGMENT_64 = 0x19,
LC_ROUTINES_64 = 0x1a,
LC_UUID = 0x1b,
LC_RPATH = 0x1c,
LC_CODE_SIGNATURE = 0x1d,
LC_SEGMENT_SPLIT_INFO = 0x1e,
LC_REEXPORT_DYLIB = 0x1f,
LC_REQ_DYLD = 0x80000000 // OR'ed ==> must not ignore
}; };
enum { // maxprot enum { // maxprot
VM_PROT_READ = 1, VM_PROT_READ = 1,
@@ -97,8 +118,11 @@
#undef WANT_MACH_THREAD_ENUM #undef WANT_MACH_THREAD_ENUM
enum { // thread flavor enum { // thread flavor
PPC_THREAD_STATE = 1, PPC_THREAD_STATE = 1,
i386_THREAD_STATE = 1, PPC_THREAD_STATE64 = 5,
i386_OLD_THREAD_STATE = -1 x86_THREAD_STATE32 = 1,
x86_THREAD_STATE64 = 4,
i386_OLD_THREAD_STATE = -1,
ARM_THREAD_STATE = 1
}; };
#endif /*}*/ #endif /*}*/
+34 -17
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2002-2007 Jens Medoch Copyright (C) 2002-2009 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
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
Jens Medoch Jens Medoch
<jssg@users.sourceforge.net> <jssg@users.sourceforge.net>
@@ -95,7 +95,7 @@ PackPs1::PackPs1(InputFile *f) :
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40) COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40)
fdata_size = file_size - PS_HDR_SIZE; fdata_size = file_size - PS_HDR_SIZE;
ram_size = !opt->ps1_exe.do_8mb ? 0x200000 : 0x800000; ram_size = !opt->ps1_exe.do_8mib ? 0x200000 : 0x800000;
} }
const int *PackPs1::getCompressionMethods(int method, int level) const const int *PackPs1::getCompressionMethods(int method, int level) const
@@ -127,8 +127,8 @@ int PackPs1::readFileHeader()
{ {
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
fi->readx(&ih, sizeof(ih)); fi->readx(&ih, sizeof(ih));
if (memcmp(&ih.id, "PS-X EXE", 8) != 0 && if (memcmp(&ih.id[0], "PS-X EXE", 8) != 0 &&
memcmp(&ih.id, "EXE X-SP", 8) != 0) memcmp(&ih.id[0], "EXE X-SP", 8) != 0)
return 0; return 0;
if (ih.text != 0 || ih.data != 0) if (ih.text != 0 || ih.data != 0)
return 0; return 0;
@@ -194,6 +194,8 @@ bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst)
unsigned sz_bh = SZ_IH_BKUP; unsigned sz_bh = SZ_IH_BKUP;
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len, int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
unc_bh, &sz_bh, M_NRV2E_8, NULL ); unc_bh, &sz_bh, M_NRV2E_8, NULL );
if (r == UPX_E_OUT_OF_MEMORY)
throwOutOfMemoryException();
if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP) if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP)
throwInternalError("header decompression failed"); throwInternalError("header decompression failed");
unsigned ad = upx_adler32(unc_bh, SZ_IH_BKUP); unsigned ad = upx_adler32(unc_bh, SZ_IH_BKUP);
@@ -254,8 +256,9 @@ bool PackPs1::canPack()
fi->readx(buf, sizeof(buf)); fi->readx(buf, sizeof(buf));
checkAlreadyPacked(buf, sizeof(buf)); checkAlreadyPacked(buf, sizeof(buf));
for (unsigned i = 0; i < sizeof(buf); i++) for (size_t i = 0; i < sizeof(buf); i++)
if (buf[i] != 0) if (buf[i] != 0)
{
if (!opt->force) if (!opt->force)
throwCantPack("unknown data in header (try --force)"); throwCantPack("unknown data in header (try --force)");
else else
@@ -265,6 +268,7 @@ bool PackPs1::canPack()
opt->backup = 1; opt->backup = 1;
break; break;
} }
}
if (!checkFileHeader()) if (!checkFileHeader())
throwCantPack("unsupported header flags (try --force)"); throwCantPack("unsupported header flags (try --force)");
if (!opt->force && file_size < PS_MIN_SIZE) if (!opt->force && file_size < PS_MIN_SIZE)
@@ -318,6 +322,7 @@ void PackPs1::buildLoader(const Filter *)
sa_tmp += overlap = ALIGN_UP((ph.overlap_overhead - sa_tmp), 4u); sa_tmp += overlap = ALIGN_UP((ph.overlap_overhead - sa_tmp), 4u);
} }
if (isCon || M_IS_LZMA(ph.method))
foundBss = findBssSection(); foundBss = findBssSection();
if (M_IS_LZMA(ph.method) && !buildPart2) if (M_IS_LZMA(ph.method) && !buildPart2)
@@ -370,16 +375,20 @@ void PackPs1::buildLoader(const Filter *)
else else
{ {
if (M_IS_LZMA(ph.method)) if (M_IS_LZMA(ph.method))
addLoader("cdb.start.lzma", "pad.code", "cdb.entry.lzma", method, "cdb.lzma.cpr", addLoader(!foundBss ? "cdb.start.lzma" : "bss.cdb.start.lzma", "pad.code",
!foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma",
method, "cdb.lzma.cpr",
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi", ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
"lzma.exec", NULL); "lzma.exec", NULL);
else else
{
assert(foundBss != true);
addLoader("cdb.start", "pad.code", "cdb.entry", addLoader("cdb.start", "pad.code", "cdb.entry",
ih.tx_ptr & 0xffff ? "cdb.dec.ptr" : "cdb.dec.ptr.hi", ih.tx_ptr & 0xffff ? "cdb.dec.ptr" : "cdb.dec.ptr.hi",
method, method,
sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "", sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "",
!foundBss ? "cdb.exit" : "bss.exit", "cdb.exit", NULL);
"pad.code", NULL); }
} }
addLoader("UPX1HEAD", "IDENTSTR", NULL); addLoader("UPX1HEAD", "IDENTSTR", NULL);
} }
@@ -424,7 +433,7 @@ bool PackPs1::findBssSection()
reg = REG1(op); reg = REG1(op);
for (; i >= 0; i--) for (; i >= 0; i--)
{ {
bss_nfo *p = (bss_nfo *)&p1[i]; bss_nfo *p = (bss_nfo *)(void *)&p1[i];
unsigned short op1 = p->op1, op2 = p->op2; unsigned short op1 = p->op1, op2 = p->op2;
// check for la (x),bss_start // check for la (x),bss_start
@@ -491,7 +500,7 @@ void PackPs1::pack(OutputFile *fo)
// compress (max_match = 65535) // compress (max_match = 65535)
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
cconf.conf_ucl.max_match = 65535; cconf.conf_ucl.max_match = 65535;
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, sa_cnt, &cconf); compressWithFilters(&ft, sa_cnt, &cconf);
if (overlap) if (overlap)
@@ -554,7 +563,9 @@ void PackPs1::pack(OutputFile *fo)
} }
else else
{ {
d_len = (lsize - h_len) - getLoaderSectionStart(M_IS_LZMA(ph.method) ? "cdb.entry.lzma" : "cdb.entry"); const char* entry_lzma = !foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma";
d_len = (lsize - h_len) - getLoaderSectionStart(M_IS_LZMA(ph.method) ? entry_lzma : "cdb.entry");
e_len = (lsize - d_len) - h_len; e_len = (lsize - d_len) - h_len;
} }
@@ -565,11 +576,13 @@ void PackPs1::pack(OutputFile *fo)
linker->defineSymbol("ldr_sz", M_IS_LZMA(ph.method) ? sz_lunc + 16 : (d_len-pad_code)); linker->defineSymbol("ldr_sz", M_IS_LZMA(ph.method) ? sz_lunc + 16 : (d_len-pad_code));
if (foundBss) if (foundBss)
{
if (M_IS_LZMA(ph.method)) if (M_IS_LZMA(ph.method))
linker->defineSymbol("wrkmem", bss_end - 160 - getDecompressorWrkmemSize() linker->defineSymbol("wrkmem", bss_end - 160 - getDecompressorWrkmemSize()
- (sz_lunc + 16)); - (sz_lunc + 16));
else else
linker->defineSymbol("wrkmem", bss_end - 16 - (d_len - pad_code)); linker->defineSymbol("wrkmem", bss_end - 16 - (d_len - pad_code));
}
const unsigned entry = comp_data_start - e_len; const unsigned entry = comp_data_start - e_len;
@@ -578,7 +591,7 @@ void PackPs1::pack(OutputFile *fo)
unsigned pad = 0; unsigned pad = 0;
if (!opt->ps1_exe.no_align) if (!opt->ps1_exe.no_align || !isCon)
{ {
pad = oh.tx_len; pad = oh.tx_len;
oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC); oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC);
@@ -611,8 +624,12 @@ void PackPs1::pack(OutputFile *fo)
linker->defineSymbol("PSVR", FIX_PSVR); linker->defineSymbol("PSVR", FIX_PSVR);
linker->defineSymbol("CPDO", comp_data_start); linker->defineSymbol("CPDO", comp_data_start);
if (M_IS_LZMA(ph.method)) if (M_IS_LZMA(ph.method))
linker->defineSymbol("lzma_cpr", getLoaderSectionStart("lzma.exec") {
- getLoaderSectionStart("cdb.entry.lzma")); unsigned entry_lzma = getLoaderSectionStart( !foundBss ? "cdb.entry.lzma" :
"bss.cdb.entry.lzma");
linker->defineSymbol("lzma_cpr", getLoaderSectionStart("lzma.exec") - entry_lzma);
}
} }
relocateLoader(); relocateLoader();
+12 -20
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
Copyright (C) 2002-2007 Jens Medoch Copyright (C) 2002-2009 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
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
Jens Medoch Jens Medoch
<jssg@users.sourceforge.net> <jssg@users.sourceforge.net>
@@ -67,8 +67,7 @@ protected:
virtual int readFileHeader(); virtual int readFileHeader();
virtual bool checkFileHeader(); virtual bool checkFileHeader();
struct ps1_exe_t __packed_struct(ps1_exe_t)
{
// ident string // ident string
char id[8]; char id[8];
// is NULL // is NULL
@@ -91,33 +90,26 @@ protected:
char origin[60]; char origin[60];
// backup of the original header (epc - is_len) // backup of the original header (epc - is_len)
// id & the upx header ... // id & the upx header ...
} __packed_struct_end()
__attribute_packed;
// for unpack // for unpack
struct ps1_exe_hb_t __packed_struct(ps1_exe_hb_t)
{
LE32 ih_bkup[10]; LE32 ih_bkup[10];
// plus checksum for the backup // plus checksum for the backup
LE32 ih_csum; LE32 ih_csum;
} __packed_struct_end()
__attribute_packed;
struct ps1_exe_chb_t __packed_struct(ps1_exe_chb_t)
{
unsigned char id; unsigned char id;
unsigned char len; unsigned char len;
LE16 ih_csum; LE16 ih_csum;
unsigned char ih_bkup; unsigned char ih_bkup;
} __packed_struct_end()
__attribute_packed;
struct bss_nfo __packed_struct(bss_nfo)
{
LE16 hi1, op1, lo1, op2; LE16 hi1, op1, lo1, op2;
LE16 hi2, op3, lo2, op4; LE16 hi2, op3, lo2, op4;
} __packed_struct_end()
__attribute_packed;
ps1_exe_t ih, oh; ps1_exe_t ih, oh;
ps1_exe_hb_t bh; ps1_exe_hb_t bh;
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+5 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -42,7 +42,8 @@ public:
virtual int getVersion() const { return 13; } virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_DOS_SYS; } virtual int getFormat() const { return UPX_F_DOS_SYS; }
virtual const char *getName() const { return "dos/sys"; } virtual const char *getName() const { return "dos/sys"; }
virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.sys" : "i286-dos16.sys"; } //virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.sys" : "i286-dos16.sys"; }
virtual const char *getFullName(const options_t *) const { return "i086-dos16.sys"; }
virtual bool canPack(); virtual bool canPack();
+6 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -67,11 +67,12 @@ const int *PackTmt::getFilters() const
unsigned PackTmt::findOverlapOverhead(const upx_bytep buf, unsigned PackTmt::findOverlapOverhead(const upx_bytep buf,
const upx_bytep tbuf,
unsigned range, unsigned range,
unsigned upper_limit) const unsigned upper_limit) const
{ {
// make sure the decompressor will be paragraph aligned // make sure the decompressor will be paragraph aligned
unsigned o = super::findOverlapOverhead(buf, range, upper_limit); unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
o = ((o + 0x20) &~ 0xf) - (ph.u_len & 0xf); o = ((o + 0x20) &~ 0xf) - (ph.u_len & 0xf);
return o; return o;
} }
@@ -241,7 +242,7 @@ void PackTmt::pack(OutputFile *fo)
// compress // compress
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression // limit stack size needed for runtime decompression
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 512, &cconf); compressWithFilters(&ft, 512, &cconf);
const unsigned lsize = getLoaderSize(); const unsigned lsize = getLoaderSize();
+5 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -42,7 +42,7 @@ public:
virtual int getVersion() const { return 13; } virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_TMT_ADAM; } virtual int getFormat() const { return UPX_F_TMT_ADAM; }
virtual const char *getName() const { return "tmt/adam"; } virtual const char *getName() const { return "tmt/adam"; }
virtual const char *getFullName(const options_t *) const { return "i386-dos32.tmt"; } virtual const char *getFullName(const options_t *) const { return "i386-dos32.tmt.adam"; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const; virtual const int *getFilters() const;
@@ -56,6 +56,7 @@ protected:
virtual int readFileHeader(); virtual int readFileHeader();
virtual unsigned findOverlapOverhead(const upx_bytep buf, virtual unsigned findOverlapOverhead(const upx_bytep buf,
const upx_bytep tbuf,
unsigned range = 0, unsigned range = 0,
unsigned upper_limit = ~0u) const; unsigned upper_limit = ~0u) const;
virtual void buildLoader(const Filter *ft); virtual void buildLoader(const Filter *ft);
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -507,7 +507,7 @@ void PackTos::pack(OutputFile *fo)
// compress (max_match = 65535) // compress (max_match = 65535)
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
cconf.conf_ucl.max_match = 65535; cconf.conf_ucl.max_match = 65535;
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 512, &cconf); compressWithFilters(&ft, 512, &cconf);
// //
+5 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -62,8 +62,7 @@ protected:
virtual int readFileHeader(); virtual int readFileHeader();
virtual bool checkFileHeader(); virtual bool checkFileHeader();
struct tos_header_t __packed_struct(tos_header_t)
{
BE16 fh_magic; BE16 fh_magic;
BE32 fh_text; BE32 fh_text;
BE32 fh_data; BE32 fh_data;
@@ -72,8 +71,7 @@ protected:
BE32 fh_reserved; BE32 fh_reserved;
BE32 fh_flag; BE32 fh_flag;
BE16 fh_reloc; BE16 fh_reloc;
} __packed_struct_end()
__attribute_packed;
tos_header_t ih, oh; tos_header_t ih, oh;
+30 -26
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -173,8 +173,10 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy); compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy);
if (ph.c_len < ph.u_len) { if (ph.c_len < ph.u_len) {
const upx_bytep tbuf = NULL;
if (ft.id == 0) tbuf = ibuf;
ph.overlap_overhead = OVERHEAD; ph.overlap_overhead = OVERHEAD;
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) { if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
// not in-place compressible // not in-place compressible
ph.c_len = ph.u_len; ph.c_len = ph.u_len;
} }
@@ -189,8 +191,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
// write block header // write block header
b_info blk_info; b_info blk_info;
memset(&blk_info, 0, sizeof(blk_info)); memset(&blk_info, 0, sizeof(blk_info));
set_native32(&blk_info.sz_unc, ph.u_len); set_te32(&blk_info.sz_unc, ph.u_len);
set_native32(&blk_info.sz_cpr, ph.c_len); set_te32(&blk_info.sz_cpr, ph.c_len);
if (ph.c_len < ph.u_len) { if (ph.c_len < ph.u_len) {
blk_info.b_method = (unsigned char) ph.method; blk_info.b_method = (unsigned char) ph.method;
blk_info.b_ftid = (unsigned char) ph.filter; blk_info.b_ftid = (unsigned char) ph.filter;
@@ -250,7 +252,7 @@ void PackUnix::pack4(OutputFile *fo, Filter &)
writePackHeader(fo); writePackHeader(fo);
unsigned tmp; unsigned tmp;
set_native32(&tmp, overlay_offset); set_te32(&tmp, overlay_offset);
fo->write(&tmp, sizeof(tmp)); fo->write(&tmp, sizeof(tmp));
} }
@@ -276,9 +278,9 @@ void PackUnix::pack(OutputFile *fo)
pack1(fo, ft); // generate Elf header, etc. pack1(fo, ft); // generate Elf header, etc.
p_info hbuf; p_info hbuf;
set_native32(&hbuf.p_progid, progid); set_te32(&hbuf.p_progid, progid);
set_native32(&hbuf.p_filesize, file_size); set_te32(&hbuf.p_filesize, file_size);
set_native32(&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 pack2(fo, ft); // append the compressed body
@@ -353,8 +355,10 @@ void PackUnix::packExtent(
} }
if (ph.c_len < ph.u_len) { if (ph.c_len < ph.u_len) {
const upx_bytep tbuf = NULL;
if (ft == NULL || ft->id == 0) tbuf = ibuf;
ph.overlap_overhead = OVERHEAD; ph.overlap_overhead = OVERHEAD;
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) { if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
// not in-place compressible // not in-place compressible
ph.c_len = ph.u_len; ph.c_len = ph.u_len;
} }
@@ -385,8 +389,8 @@ void PackUnix::packExtent(
ph.c_adler = upx_adler32(obuf, ph.c_len, ph.saved_c_adler); ph.c_adler = upx_adler32(obuf, ph.c_len, ph.saved_c_adler);
end_u_adler = ph.u_adler; end_u_adler = ph.u_adler;
memset(&tmp, 0, sizeof(tmp)); memset(&tmp, 0, sizeof(tmp));
set_native32(&tmp.sz_unc, hdr_u_len); set_te32(&tmp.sz_unc, hdr_u_len);
set_native32(&tmp.sz_cpr, hdr_c_len); set_te32(&tmp.sz_cpr, hdr_c_len);
tmp.b_method = (unsigned char) ph.method; tmp.b_method = (unsigned char) ph.method;
fo->write(&tmp, sizeof(tmp)); fo->write(&tmp, sizeof(tmp));
b_len += sizeof(b_info); b_len += sizeof(b_info);
@@ -396,8 +400,8 @@ void PackUnix::packExtent(
hdr_u_len = 0; // compress hdr one time only hdr_u_len = 0; // compress hdr one time only
} }
memset(&tmp, 0, sizeof(tmp)); memset(&tmp, 0, sizeof(tmp));
set_native32(&tmp.sz_unc, ph.u_len); set_te32(&tmp.sz_unc, ph.u_len);
set_native32(&tmp.sz_cpr, ph.c_len); set_te32(&tmp.sz_cpr, ph.c_len);
if (ph.c_len < ph.u_len) { if (ph.c_len < ph.u_len) {
tmp.b_method = (unsigned char) ph.method; tmp.b_method = (unsigned char) ph.method;
if (ft) { if (ft) {
@@ -435,8 +439,8 @@ void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
b_info hdr; memset(&hdr, 0, sizeof(hdr)); b_info hdr; memset(&hdr, 0, sizeof(hdr));
while (wanted) { while (wanted) {
fi->readx(&hdr, szb_info); fi->readx(&hdr, szb_info);
int const sz_unc = ph.u_len = get_native32(&hdr.sz_unc); int const sz_unc = ph.u_len = get_te32(&hdr.sz_unc);
int const sz_cpr = ph.c_len = get_native32(&hdr.sz_cpr); int const sz_cpr = ph.c_len = get_te32(&hdr.sz_cpr);
ph.filter_cto = hdr.b_cto8; ph.filter_cto = hdr.b_cto8;
if (sz_unc == 0) { // must never happen while 0!=wanted if (sz_unc == 0) { // must never happen while 0!=wanted
@@ -499,13 +503,13 @@ int PackUnix::canUnpack()
fi->seek(-bufsize, SEEK_END); fi->seek(-bufsize, SEEK_END);
fi->readx(buf, bufsize); fi->readx(buf, bufsize);
if (!getPackHeader(buf, bufsize)) if (!getPackHeader(buf, bufsize, true)) // allow incompressible extents
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_native32(buf+l); overlay_offset = get_te32(buf+l);
if ((off_t)overlay_offset >= file_size) if ((off_t)overlay_offset >= file_size)
throwCantUnpack("file corrupted"); throwCantUnpack("file corrupted");
@@ -527,15 +531,15 @@ void PackUnix::unpack(OutputFile *fo)
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
fi->readx(&ehdr, sizeof(ehdr)); fi->readx(&ehdr, sizeof(ehdr));
unsigned const e_entry = get_native32(&ehdr.e_entry); unsigned const e_entry = get_te32(&ehdr.e_entry);
if (e_entry < 0x401180) { /* old style, 8-byte b_info */ if (e_entry < 0x401180) { /* old style, 8-byte b_info */
szb_info = 2*sizeof(unsigned); szb_info = 2*sizeof(unsigned);
} }
else { else {
Elf32_Phdr phdr; Elf32_Phdr phdr;
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET); fi->seek(get_te32(&ehdr.e_phoff), SEEK_SET);
fi->readx(&phdr, sizeof(phdr)); fi->readx(&phdr, sizeof(phdr));
unsigned const p_vaddr = get_native32(&phdr.p_vaddr); unsigned const p_vaddr = get_te32(&phdr.p_vaddr);
if (0x80==(e_entry - p_vaddr)) { /* 1.22 old style */ if (0x80==(e_entry - p_vaddr)) { /* 1.22 old style */
szb_info = 2*sizeof(unsigned); szb_info = 2*sizeof(unsigned);
} }
@@ -554,8 +558,8 @@ void PackUnix::unpack(OutputFile *fo)
{ {
p_info hbuf; p_info hbuf;
fi->readx(&hbuf, sizeof(hbuf)); fi->readx(&hbuf, sizeof(hbuf));
orig_file_size = get_native32(&hbuf.p_filesize); orig_file_size = get_te32(&hbuf.p_filesize);
blocksize = get_native32(&hbuf.p_blocksize); blocksize = get_te32(&hbuf.p_blocksize);
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size) if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
throwCantUnpack("file header corrupted"); throwCantUnpack("file header corrupted");
@@ -579,8 +583,8 @@ void PackUnix::unpack(OutputFile *fo)
unsigned sz_unc, sz_cpr; unsigned sz_unc, sz_cpr;
fi->readx(&bhdr, szb_info); fi->readx(&bhdr, szb_info);
ph.u_len = sz_unc = get_native32(&bhdr.sz_unc); ph.u_len = sz_unc = get_te32(&bhdr.sz_unc);
ph.c_len = sz_cpr = get_native32(&bhdr.sz_cpr); ph.c_len = sz_cpr = get_te32(&bhdr.sz_cpr);
if (sz_unc == 0) // uncompressed size 0 -> EOF if (sz_unc == 0) // uncompressed size 0 -> EOF
{ {
+24 -53
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -64,15 +64,6 @@ protected:
virtual void writePackHeader(OutputFile *fo); virtual void writePackHeader(OutputFile *fo);
// in order too share as much code as possible we introduce
// an endian abstraction here
virtual acc_uint64l_t get_native64(const void *) const = 0;
virtual unsigned get_native32(const void *) const = 0;
virtual unsigned get_native16(const void *) const = 0;
virtual void set_native64(void *, acc_uint64l_t) const = 0;
virtual void set_native32(void *, unsigned) const = 0;
virtual void set_native16(void *, unsigned) const = 0;
virtual bool checkCompressionRatio(unsigned, unsigned) const; virtual bool checkCompressionRatio(unsigned, unsigned) const;
protected: protected:
@@ -101,30 +92,28 @@ protected:
unsigned b_len; // total length of b_info blocks unsigned b_len; // total length of b_info blocks
// must agree with stub/linux.hh // must agree with stub/linux.hh
struct b_info { // 12-byte header before each compressed block __packed_struct(b_info) // 12-byte header before each compressed block
unsigned sz_unc; // uncompressed_size unsigned sz_unc; // uncompressed_size
unsigned sz_cpr; // compressed_size unsigned sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter unsigned char b_cto8; // filter parameter
unsigned char b_unused; unsigned char b_unused;
} __packed_struct_end()
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader __packed_struct(l_info) // 12-byte trailer in header for loader
LE32 l_checksum; LE32 l_checksum;
LE32 l_magic; LE32 l_magic;
LE16 l_lsize; LE16 l_lsize;
unsigned char l_version; unsigned char l_version;
unsigned char l_format; unsigned char l_format;
} __packed_struct_end()
__attribute_packed;
struct p_info { // 12-byte packed program header __packed_struct(p_info) // 12-byte packed program header
unsigned p_progid; unsigned p_progid;
unsigned p_filesize; unsigned p_filesize;
unsigned p_blocksize; unsigned p_blocksize;
} __packed_struct_end()
__attribute_packed;
struct l_info linfo; struct l_info linfo;
@@ -142,39 +131,30 @@ class PackUnixBe32 : public PackUnix
typedef PackUnix super; typedef PackUnix super;
protected: protected:
PackUnixBe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; } PackUnixBe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; }
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
// must agree with stub/linux.hh // must agree with stub/linux.hh
struct b_info { // 12-byte header before each compressed block __packed_struct(b_info) // 12-byte header before each compressed block
BE32 sz_unc; // uncompressed_size BE32 sz_unc; // uncompressed_size
BE32 sz_cpr; // compressed_size BE32 sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter unsigned char b_cto8; // filter parameter
unsigned char b_unused; unsigned char b_unused;
} __packed_struct_end()
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader __packed_struct(l_info) // 12-byte trailer in header for loader
BE32 l_checksum; BE32 l_checksum;
BE32 l_magic; BE32 l_magic;
BE16 l_lsize; BE16 l_lsize;
unsigned char l_version; unsigned char l_version;
unsigned char l_format; unsigned char l_format;
} __packed_struct_end()
__attribute_packed;
struct p_info { // 12-byte packed program header __packed_struct(p_info) // 12-byte packed program header
BE32 p_progid; BE32 p_progid;
BE32 p_filesize; BE32 p_filesize;
BE32 p_blocksize; BE32 p_blocksize;
} __packed_struct_end()
__attribute_packed;
}; };
@@ -183,39 +163,30 @@ class PackUnixLe32 : public PackUnix
typedef PackUnix super; typedef PackUnix super;
protected: protected:
PackUnixLe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; } PackUnixLe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
// must agree with stub/linux.hh // must agree with stub/linux.hh
struct b_info { // 12-byte header before each compressed block __packed_struct(b_info) // 12-byte header before each compressed block
LE32 sz_unc; // uncompressed_size LE32 sz_unc; // uncompressed_size
LE32 sz_cpr; // compressed_size LE32 sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter unsigned char b_cto8; // filter parameter
unsigned char b_unused; unsigned char b_unused;
} __packed_struct_end()
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader __packed_struct(l_info) // 12-byte trailer in header for loader
LE32 l_checksum; LE32 l_checksum;
LE32 l_magic; LE32 l_magic;
LE16 l_lsize; LE16 l_lsize;
unsigned char l_version; unsigned char l_version;
unsigned char l_format; unsigned char l_format;
} __packed_struct_end()
__attribute_packed;
struct p_info { // 12-byte packed program header __packed_struct(p_info) // 12-byte packed program header
LE32 p_progid; LE32 p_progid;
LE32 p_filesize; LE32 p_filesize;
LE32 p_blocksize; LE32 p_blocksize;
} __packed_struct_end()
__attribute_packed;
}; };
+427 -33
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-2007 John Reiser Copyright (C) 2004-2009 John Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 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
@@ -23,10 +23,10 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
John Reiser John Reiser
jreiser@users.sourceforge.net <jreiser@users.sourceforge.net>
*/ */
@@ -44,6 +44,10 @@ static const
#include "stub/amd64-linux.kernel.vmlinux.h" #include "stub/amd64-linux.kernel.vmlinux.h"
static const static const
#include "stub/arm-linux.kernel.vmlinux.h" #include "stub/arm-linux.kernel.vmlinux.h"
static const
#include "stub/armeb-linux.kernel.vmlinux.h"
static const
#include "stub/powerpc-linux.kernel.vmlinux.h"
/************************************************************************* /*************************************************************************
@@ -60,7 +64,7 @@ PackVmlinuxBase<T>::PackVmlinuxBase(InputFile *f,
n_ptload(0), phdri(NULL), shdri(NULL), shstrtab(NULL) n_ptload(0), phdri(NULL), shdri(NULL), shstrtab(NULL)
{ {
ElfClass::compileTimeAssertions(); ElfClass::compileTimeAssertions();
bele = N_BELE_CTP::getRTP<BeLePolicy>(); bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL);
} }
template <class T> template <class T>
@@ -201,13 +205,14 @@ bool PackVmlinuxBase<T>::canPack()
return 0 < n_ptload; return 0 < n_ptload;
} }
#include "p_elf.h"
template <class T> template <class T>
void PackVmlinuxBase<T>::pack(OutputFile *fo) void PackVmlinuxBase<T>::pack(OutputFile *fo)
{ {
unsigned fo_off = 0; unsigned fo_off = 0;
Ehdr ehdro; Ehdr ehdro;
U32 tmp_u32; TE32 tmp_u32;
// NULL // NULL
// .text(PT_LOADs) .note(1st page) .note(rest) // .text(PT_LOADs) .note(1st page) .note(rest)
@@ -264,8 +269,216 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression // limit stack size needed for runtime decompression
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
unsigned ppc32_extra = 0;
if (Ehdr::EM_PPC==my_e_machine) {
// output layout:
// .long UPX_MAGIC_LE32
// .long L20 - L10
// L10:
// b_info for Ehdr; compressed Ehdr; .balign 4 // one block only
// b_info for LOAD; compressed LOAD; .balign 4 // possibly many blocks
// // This allows per-block filters!
// L20:
// b f_decompress
// +4: f_unfilter(char *buf, unsigned len, unsigned cto8, unsigned ftid)
// // Code for multiple filters can "daisy chain" on ftid.
// f_decompress(char const *src, unsigned src_len,
// char *dst, unsigned *dst_len, int method)
unsigned tmp;
tmp = UPX_MAGIC_LE32; fo->write(&tmp, sizeof(tmp)); fo_off += sizeof(tmp);
tmp = 0; fo->write(&tmp, sizeof(tmp)); fo_off += sizeof(tmp);
ppc32_extra += 2*sizeof(tmp);
unsigned const len_unc = sizeof(ehdri) + sizeof(Phdr) * ehdri.e_phnum;
MemBuffer unc_hdr(len_unc);
MemBuffer cpr_hdr; cpr_hdr.allocForCompression(len_unc);
memcpy(&unc_hdr[0], &ehdri, sizeof(ehdri));
memcpy(&unc_hdr[sizeof(ehdri)], phdri, sizeof(Phdr) * ehdri.e_phnum);
unsigned len_cpr = 0;
int const r = upx_compress(unc_hdr, len_unc, cpr_hdr, &len_cpr,
NULL, ph.method, 10, NULL, NULL );
if (UPX_E_OK!=r || len_unc<=len_cpr) // FIXME: allow no compression
throwInternalError("Ehdr compression failed");
__packed_struct(b_info) // 12-byte header before each compressed block
unsigned sz_unc; // uncompressed_size
unsigned sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter
unsigned char b_unused; // FIXME: !=0 for partial-block unfilter
// unsigned f_offset, f_len; // only if partial-block unfilter
__packed_struct_end()
struct b_info hdr_info;
set_be32(&hdr_info.sz_unc, len_unc);
set_be32(&hdr_info.sz_cpr, len_cpr);
hdr_info.b_method = ph.method;
hdr_info.b_ftid = 0;
hdr_info.b_cto8 = 0;
hdr_info.b_unused = 0;
fo->write(&hdr_info, sizeof(hdr_info)); fo_off += sizeof(hdr_info);
unsigned const frag = (3& (0u-len_cpr));
ppc32_extra += sizeof(hdr_info) + len_cpr + frag;
fo_off += len_cpr + frag;
fo->write(cpr_hdr, len_cpr + frag);
// Partial filter: .text and following contiguous SHF_EXECINSTR
upx_bytep f_ptr = ibuf;
unsigned f_len = 0;
Shdr const *shdr = 1+ shdri; // skip empty shdr[0]
if (ft.buf_len==0 // not specified yet FIXME: was set near construction
&& (Shdr::SHF_ALLOC & shdr->sh_flags)
&& (Shdr::SHF_EXECINSTR & shdr->sh_flags)) {
// shdr[1] is instructions (probably .text)
f_ptr = ibuf + (unsigned) (shdr->sh_offset - phdri[0].p_offset);
f_len = shdr->sh_size;
++shdr;
for (int j= ehdri.e_shnum - 2; --j>=0; ++shdr) {
unsigned prev_end = shdr[-1].sh_size + shdr[-1].sh_offset;
prev_end += ~(0u-shdr[0].sh_addralign) & (0u-prev_end); // align_up
if ((Shdr::SHF_ALLOC & shdr->sh_flags)
&& (Shdr::SHF_EXECINSTR & shdr->sh_flags)
&& shdr[0].sh_offset==prev_end) {
f_len += shdr->sh_size;
}
else {
break;
}
}
}
else { // ft.buf_len already specified, or Shdr[1] not instructions
f_ptr = ibuf;
f_len = ph.u_len;
}
compressWithFilters(ibuf, ph.u_len, obuf,
f_ptr, f_len, // filter range
NULL, 0, // hdr_ptr, hdr_len
&ft, 512, &cconf, getStrategy(ft));
set_be32(&hdr_info.sz_unc, ph.u_len);
set_be32(&hdr_info.sz_cpr, ph.c_len);
hdr_info.b_ftid = ft.id;
hdr_info.b_cto8 = ft.cto;
if (ph.u_len!=f_len) {
hdr_info.b_unused = 1; // flag for partial filter
}
fo->write(&hdr_info, sizeof(hdr_info)); fo_off += sizeof(hdr_info);
ppc32_extra += sizeof(hdr_info);
if (ph.u_len!=f_len) {
set_be32(&hdr_info.sz_unc, f_ptr - (upx_bytep) ibuf);
set_be32(&hdr_info.sz_cpr, f_len);
fo->write(&hdr_info, 2*sizeof(unsigned)); fo_off += 2*sizeof(unsigned);
ppc32_extra += 2*sizeof(unsigned);
}
#if 0 /*{ Documentation: changes to arch/powerpc/boot/main.c */
struct b_info {
unsigned sz_unc;
unsigned sz_cpr;
unsigned char b_method;
unsigned char b_ftid;
unsigned char b_cto8;
unsigned char b_unused;
};
typedef int (*upx_f_unc)( /* uncompress */
unsigned char const *src, unsigned src_len,
unsigned char *dst, unsigned *dst_len,
int method
);
typedef int (*upx_f_unf)( /* unfilter */
unsigned char *buf,
unsigned len,
unsigned cto8,
unsigned ftid
);
unsigned char const *upx_expand( // return updated src [aligned, too]
unsigned char const *src,
unsigned char *dst,
unsigned *const dst_len,
upx_f_unc const f_unc
)
{
if (0==*dst_len) {
*dst_len = ((struct b_info const *)src)->sz_unc;
}
upx_f_unf const f_unf = (upx_f_unf)(sizeof(int) + (char *)f_unc);
unsigned total_len = 0;
unsigned need = *dst_len;
while (0 < need) {
struct b_info const *const b_hdr = (struct b_info const *)src;
src = (unsigned char const *)(1+ b_hdr);
unsigned blk_len = b_hdr->sz_unc;
int const rv = (*f_unc)(src, b_hdr->sz_cpr, dst, &blk_len, b_hdr->b_method);
if (0!=rv) {
printf("decompress error %d\n\r", rv);
exit();
}
if (b_hdr->b_ftid) {
(*f_unf)(dst, b_hdr->sz_unc, b_hdr->b_cto8, b_hdr->b_ftid);
}
src += b_hdr->sz_cpr;
src += (3& -(int)src); // 4-byte align
dst += b_hdr->sz_unc;
total_len += b_hdr->sz_unc;
need -= b_hdr->sz_unc;
}
*dst_len = total_len;
return src;
}
void prep_kernel(unsigned long a1, unsigned long a2)
{
upx_f_unc f_unc = (upx_f_unc)0;
vmlinuz.addr = (unsigned long)_vmlinux_start;
vmlinuz.size = (unsigned long)(_vmlinux_end - _vmlinux_start);
if (0x55505821 == *(unsigned *)vmlinuz.addr) {
/* was compressed by upx */
/* Uncompress elfheader */
unsigned const *const fwa = (unsigned *)vmlinuz.addr;
f_unc = (upx_f_unc)((char *)&fwa[2] + fwa[1]);
unsigned dst_len = 0;
unsigned char const *src = (unsigned char const *)&fwa[2];
src = upx_expand(src, (unsigned char *)elfheader, &dst_len, f_unc);
unsigned const src_len = src - (unsigned char const *)&fwa[0];
vmlinuz.addr += src_len;
vmlinuz.size -= src_len;
} else {
memcpy(elfheader, (const void *)vmlinuz.addr,
sizeof(elfheader));
}
=====
/* Eventually gunzip the kernel */
if (f_unc) {
/* was compressed by upx */
printf("upx_expand (0x%lx <- 0x%lx:0x%0lx)...",
vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size);
unsigned dst_len = vmlinux.size - elfoffset;
upx_expand((unsigned char const *)vmlinuz.addr,
(unsigned char *)vmlinux.addr, &dst_len, f_unc);
printf("done 0x%lx bytes\n\r", len);
} else {
memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,
vmlinuz.size);
/* Skip over the ELF header */
#ifdef DEBUG
printf("... skipping 0x%lx bytes of ELF header\n\r",
elfoffset);
#endif
vmlinux.addr += elfoffset;
}
=====
}
#endif /*}*/
}
else {
compressWithFilters(&ft, 512, &cconf, getStrategy(ft)); compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
}
unsigned const txt_c_len = ph.c_len; unsigned const txt_c_len = ph.c_len;
const unsigned lsize = getLoaderSize(); const unsigned lsize = getLoaderSize();
@@ -285,13 +498,13 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
shdro[1].sh_name = ptr_diff(p, shstrtab); shdro[1].sh_name = ptr_diff(p, shstrtab);
shdro[1].sh_type = Shdr::SHT_PROGBITS; shdro[1].sh_type = Shdr::SHT_PROGBITS;
shdro[1].sh_flags = Shdr::SHF_ALLOC | Shdr::SHF_EXECINSTR; shdro[1].sh_flags = Shdr::SHF_ALLOC | Shdr::SHF_EXECINSTR;
shdro[1].sh_offset = fo_off; shdro[1].sh_offset = fo_off - ppc32_extra;
shdro[1].sh_size = txt_c_len + lsize; // plus more ... shdro[1].sh_size = ppc32_extra + txt_c_len + lsize; // plus more ...
shdro[1].sh_addralign = 1; // default shdro[1].sh_addralign = 1; // default
fo_off += write_vmlinux_head(fo, &shdro[1]); fo_off += write_vmlinux_head(fo, &shdro[1]);
fo->write(obuf, txt_c_len); fo_off += txt_c_len; fo->write(obuf, txt_c_len); fo_off += txt_c_len;
unsigned const a = (shdro[1].sh_addralign -1) & (0u-txt_c_len); unsigned const a = (shdro[1].sh_addralign -1) & (0u-(ppc32_extra + txt_c_len));
if (0!=a) { // align if (0!=a) { // align
fo_off += a; fo_off += a;
shdro[1].sh_size += a; shdro[1].sh_size += a;
@@ -359,7 +572,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
shdro[5].sh_name = ptr_diff(p, shstrtab); shdro[5].sh_name = ptr_diff(p, shstrtab);
shdro[5].sh_type = Shdr::SHT_SYMTAB; shdro[5].sh_type = Shdr::SHT_SYMTAB;
shdro[5].sh_offset = fo_off; shdro[5].sh_offset = fo_off;
shdro[5].sh_size = 5*sizeof(Sym); shdro[5].sh_size = ((Ehdr::EM_PPC==my_e_machine) + 5)*sizeof(Sym);
//shdro[5].sh_flags = Shdr::SHF_INFO_LINK; //shdro[5].sh_flags = Shdr::SHF_INFO_LINK;
shdro[5].sh_link = 6; // to .strtab for symbols shdro[5].sh_link = 6; // to .strtab for symbols
shdro[5].sh_info = 1+3; // number of non-global symbols [binutils/bfd/elf.c] shdro[5].sh_info = 1+3; // number of non-global symbols [binutils/bfd/elf.c]
@@ -386,26 +599,40 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
Sym unc_ker; Sym unc_ker;
unc_ker.st_name = 1; // 1 byte into strtab unc_ker.st_name = 1; // 1 byte into strtab
unc_ker.st_value = 0; unc_ker.st_value = 0;
unc_ker.st_size = txt_c_len; unc_ker.st_size = ppc32_extra + txt_c_len;
unc_ker.st_info = unc_ker.make_st_info(Sym::STB_GLOBAL, Sym::STT_FUNC); unc_ker.st_info = unc_ker.make_st_info(Sym::STB_GLOBAL, Sym::STT_FUNC);
unc_ker.st_other = Sym::STV_DEFAULT; unc_ker.st_other = Sym::STV_DEFAULT;
unc_ker.st_shndx = 1; // .text unc_ker.st_shndx = 1; // .text
fo->write(&unc_ker, sizeof(unc_ker)); fo_off += sizeof(unc_ker); fo->write(&unc_ker, sizeof(unc_ker)); fo_off += sizeof(unc_ker);
unsigned const lablen = strlen(my_boot_label); unsigned const lablen = strlen(my_boot_label);
if (Ehdr::EM_PPC==my_e_machine) {
unc_ker.st_name += 1+ lablen;
unc_ker.st_value = unc_ker.st_size;
unc_ker.st_size = 0;
fo->write(&unc_ker, sizeof(unc_ker)); fo_off += sizeof(unc_ker);
}
while (0!=*p++) ; while (0!=*p++) ;
shdro[6].sh_name = ptr_diff(p, shstrtab); shdro[6].sh_name = ptr_diff(p, shstrtab);
shdro[6].sh_type = Shdr::SHT_STRTAB; shdro[6].sh_type = Shdr::SHT_STRTAB;
shdro[6].sh_offset = fo_off; shdro[6].sh_offset = fo_off;
shdro[6].sh_size = 2+ lablen; // '\0' before and after shdro[6].sh_size = 2+ lablen + (Ehdr::EM_PPC==my_e_machine)*(1+ 12); // '\0' before and after
shdro[6].sh_addralign = 1; shdro[6].sh_addralign = 1;
fo->seek(1, SEEK_CUR); // the '\0' before fo->seek(1, SEEK_CUR); // the '\0' before
fo->write(my_boot_label, 1+ lablen); // include the '\0' terminator fo->write(my_boot_label, 1+ lablen); // include the '\0' terminator
if (Ehdr::EM_PPC==my_e_machine) {
fo->write("_vmlinux_end", 1+ 12); fo_off += 1+ 12;
}
fo_off += 2+ lablen; fo_off += 2+ lablen;
fo->seek(0, SEEK_SET); fo->seek(0, SEEK_SET);
fo->write(&ehdro, sizeof(ehdro)); fo->write(&ehdro, sizeof(ehdro));
fo->write(&shdro, sizeof(shdro)); fo->write(&shdro[0], sizeof(shdro));
if (Ehdr::EM_PPC==my_e_machine) {
fo->seek(sizeof(unsigned), SEEK_CUR);
set_be32(&ppc32_extra, ppc32_extra - 2*sizeof(unsigned) + txt_c_len);
fo->write(&ppc32_extra, sizeof(ppc32_extra));
}
if (!checkFinalCompressionRatio(fo)) if (!checkFinalCompressionRatio(fo))
throwNotCompressible(); throwNotCompressible();
@@ -481,7 +708,7 @@ int PackVmlinuxBase<T>::canUnpack()
template <class T> template <class T>
void PackVmlinuxBase<T>::unpack(OutputFile *fo) void PackVmlinuxBase<T>::unpack(OutputFile *fo)
{ {
U32 word; TE32 word;
PackHeader const ph_tmp(ph); PackHeader const ph_tmp(ph);
fi->seek(p_note0->sh_offset, SEEK_SET); fi->seek(p_note0->sh_offset, SEEK_SET);
@@ -547,18 +774,41 @@ const int *PackVmlinuxI386::getFilters() const
return filters; return filters;
} }
const int *PackVmlinuxARM::getCompressionMethods(int method, int level) const const int *PackVmlinuxARMEL::getCompressionMethods(int method, int level) const
{ {
return Packer::getDefaultCompressionMethods_8(method, level); return Packer::getDefaultCompressionMethods_8(method, level);
} }
const int *PackVmlinuxARMEB::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_8(method, level);
}
const int *PackVmlinuxARM::getFilters() const const int *PackVmlinuxPPC32::getCompressionMethods(int method, int level) const
{
// No real dependency on LE32.
return Packer::getDefaultCompressionMethods_le32(method, level);
}
const int *PackVmlinuxARMEL::getFilters() const
{ {
static const int f50[] = { 0x50, FT_END }; static const int f50[] = { 0x50, FT_END };
return f50; return f50;
} }
const int *PackVmlinuxARMEB::getFilters() const
{
static const int f51[] = { 0x51, FT_END };
return f51;
}
const int *PackVmlinuxPPC32::getFilters() const
{
static const int fd0[] = { 0xd0, FT_END };
return fd0;
}
// //
// Examples as of 2004-07-16 [readelf --segments vmlinux # before fiddling]: // Examples as of 2004-07-16 [readelf --segments vmlinux # before fiddling]:
// //
@@ -586,7 +836,7 @@ const int *PackVmlinuxARM::getFilters() const
bool PackVmlinuxI386::is_valid_e_entry(Addr e_entry) bool PackVmlinuxI386::is_valid_e_entry(Addr e_entry)
{ {
return 0==(0x000fffff & e_entry); // entry on whole 1MB return 0==(0x000fffff & e_entry); // entry on whole 1 MiB
} }
@@ -646,18 +896,39 @@ void PackVmlinuxAMD64::buildLoader(const Filter *ft)
"LINUX992,IDENTSTR,UPX1HEAD", NULL); "LINUX992,IDENTSTR,UPX1HEAD", NULL);
} }
bool PackVmlinuxARM::is_valid_e_entry(Addr e_entry) bool PackVmlinuxARMEL::is_valid_e_entry(Addr e_entry)
{ {
return 0xc0008000==e_entry; return 0xc0008000==e_entry;
} }
Linker* PackVmlinuxARM::newLinker() const bool PackVmlinuxARMEB::is_valid_e_entry(Addr e_entry)
{
return 0xc0008000==e_entry;
}
bool PackVmlinuxPPC32::is_valid_e_entry(Addr e_entry)
{
return 0xc0000000==e_entry;
}
Linker* PackVmlinuxARMEL::newLinker() const
{ {
return new ElfLinkerArmLE; return new ElfLinkerArmLE;
} }
Linker* PackVmlinuxARMEB::newLinker() const
{
return new ElfLinkerArmBE;
}
void PackVmlinuxARM::buildLoader(const Filter *ft) Linker* PackVmlinuxPPC32::newLinker() const
{
return new ElfLinkerPpc32;
}
void PackVmlinuxARMEL::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(stub_arm_linux_kernel_vmlinux, sizeof(stub_arm_linux_kernel_vmlinux)); initLoader(stub_arm_linux_kernel_vmlinux, sizeof(stub_arm_linux_kernel_vmlinux));
@@ -679,6 +950,50 @@ void PackVmlinuxARM::buildLoader(const Filter *ft)
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", NULL);
} }
void PackVmlinuxARMEB::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(stub_armeb_linux_kernel_vmlinux, sizeof(stub_armeb_linux_kernel_vmlinux));
addLoader("LINUX000", NULL);
if (ft->id) {
assert(ft->calls > 0);
addLoader("LINUX010", NULL);
}
addLoader("LINUX020", NULL);
if (ft->id) {
addFilter32(ft->id);
}
addLoader("LINUX030", NULL);
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL);
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL);
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL);
else throwBadLoader();
addLoader("IDENTSTR,UPX1HEAD", NULL);
}
void PackVmlinuxPPC32::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(stub_powerpc_linux_kernel_vmlinux, sizeof(stub_powerpc_linux_kernel_vmlinux));
addLoader("LINUX000", NULL);
if (ft->id) {
assert(ft->calls > 0);
addLoader("LINUX010", NULL);
}
addLoader("LINUX020", NULL);
if (ft->id) {
addFilter32(ft->id);
}
addLoader("LINUX030", NULL);
if (ph.method == M_NRV2E_LE32) addLoader("NRV2E", NULL);
else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B", NULL);
else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D", NULL);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL);
else throwBadLoader();
addLoader("IDENTSTR,UPX1HEAD", NULL);
}
static const static const
#include "stub/i386-linux.kernel.vmlinux-head.h" #include "stub/i386-linux.kernel.vmlinux-head.h"
@@ -686,6 +1001,10 @@ static const
#include "stub/amd64-linux.kernel.vmlinux-head.h" #include "stub/amd64-linux.kernel.vmlinux-head.h"
static const static const
#include "stub/arm-linux.kernel.vmlinux-head.h" #include "stub/arm-linux.kernel.vmlinux-head.h"
static const
#include "stub/armeb-linux.kernel.vmlinux-head.h"
static const
#include "stub/powerpc-linux.kernel.vmlinux-head.h"
unsigned PackVmlinuxI386::write_vmlinux_head( unsigned PackVmlinuxI386::write_vmlinux_head(
OutputFile *const fo, OutputFile *const fo,
@@ -695,7 +1014,7 @@ unsigned PackVmlinuxI386::write_vmlinux_head(
// COMPRESSED_LENGTH // COMPRESSED_LENGTH
fo->write(&stub_i386_linux_kernel_vmlinux_head[0], fo->write(&stub_i386_linux_kernel_vmlinux_head[0],
sizeof(stub_i386_linux_kernel_vmlinux_head)-(1+ 4) +1); sizeof(stub_i386_linux_kernel_vmlinux_head)-(1+ 4) +1);
U32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4); TE32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4);
stxt->sh_size += sizeof(stub_i386_linux_kernel_vmlinux_head); stxt->sh_size += sizeof(stub_i386_linux_kernel_vmlinux_head);
@@ -710,7 +1029,7 @@ unsigned PackVmlinuxAMD64::write_vmlinux_head(
// COMPRESSED_LENGTH // COMPRESSED_LENGTH
fo->write(&stub_amd64_linux_kernel_vmlinux_head[0], fo->write(&stub_amd64_linux_kernel_vmlinux_head[0],
sizeof(stub_amd64_linux_kernel_vmlinux_head)-(1+ 4) +1); sizeof(stub_amd64_linux_kernel_vmlinux_head)-(1+ 4) +1);
U32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4); TE32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4);
printf(" Compressed length=0x%x\n", ph.c_len); printf(" Compressed length=0x%x\n", ph.c_len);
printf("UnCompressed length=0x%x\n", ph.u_len); printf("UnCompressed length=0x%x\n", ph.u_len);
@@ -719,7 +1038,7 @@ printf("UnCompressed length=0x%x\n", ph.u_len);
return sizeof(stub_amd64_linux_kernel_vmlinux_head); return sizeof(stub_amd64_linux_kernel_vmlinux_head);
} }
void PackVmlinuxARM::defineDecompressorSymbols() void PackVmlinuxARMEL::defineDecompressorSymbols()
{ {
super::defineDecompressorSymbols(); super::defineDecompressorSymbols();
linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len); linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
@@ -727,6 +1046,22 @@ void PackVmlinuxARM::defineDecompressorSymbols()
linker->defineSymbol("METHOD", ph.method); linker->defineSymbol("METHOD", ph.method);
} }
void PackVmlinuxARMEB::defineDecompressorSymbols()
{
super::defineDecompressorSymbols();
linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len);
linker->defineSymbol("METHOD", ph.method);
}
void PackVmlinuxPPC32::defineDecompressorSymbols()
{
super::defineDecompressorSymbols();
// linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
// linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len);
// linker->defineSymbol("METHOD", ph.method);
}
void PackVmlinuxI386::defineDecompressorSymbols() void PackVmlinuxI386::defineDecompressorSymbols()
{ {
super::defineDecompressorSymbols(); super::defineDecompressorSymbols();
@@ -744,7 +1079,7 @@ void PackVmlinuxAMD64::defineDecompressorSymbols()
linker->defineSymbol("PHYSICAL_START", phdri[0].p_paddr); linker->defineSymbol("PHYSICAL_START", phdri[0].p_paddr);
} }
unsigned PackVmlinuxARM::write_vmlinux_head( unsigned PackVmlinuxARMEL::write_vmlinux_head(
OutputFile *const fo, OutputFile *const fo,
Shdr *const stxt Shdr *const stxt
) )
@@ -753,7 +1088,7 @@ unsigned PackVmlinuxARM::write_vmlinux_head(
fo->write(&stub_arm_linux_kernel_vmlinux_head[0], 4); fo->write(&stub_arm_linux_kernel_vmlinux_head[0], 4);
// Second word // Second word
U32 tmp_u32; TE32 tmp_u32;
unsigned const t = (0xff000000 & unsigned const t = (0xff000000 &
BeLePolicy::get32(&stub_arm_linux_kernel_vmlinux_head[4])) BeLePolicy::get32(&stub_arm_linux_kernel_vmlinux_head[4]))
| (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2))); | (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
@@ -766,10 +1101,40 @@ unsigned PackVmlinuxARM::write_vmlinux_head(
return sizeof(stub_arm_linux_kernel_vmlinux_head); return sizeof(stub_arm_linux_kernel_vmlinux_head);
} }
unsigned PackVmlinuxARMEB::write_vmlinux_head(
bool PackVmlinuxARM::has_valid_vmlinux_head() OutputFile *const fo,
Shdr *const stxt
)
{ {
U32 buf[2]; // First word from vmlinux-head.S
fo->write(&stub_armeb_linux_kernel_vmlinux_head[0], 4);
// Second word
TE32 tmp_u32;
unsigned const t = (0xff000000 &
BeLePolicy::get32(&stub_armeb_linux_kernel_vmlinux_head[4]))
| (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
tmp_u32 = t;
fo->write(&tmp_u32, 4);
stxt->sh_addralign = 4;
stxt->sh_size += sizeof(stub_armeb_linux_kernel_vmlinux_head);
return sizeof(stub_armeb_linux_kernel_vmlinux_head);
}
unsigned PackVmlinuxPPC32::write_vmlinux_head(
OutputFile * /*const fo*/,
Shdr * /*const stxt*/
)
{
return 0;
}
bool PackVmlinuxARMEL::has_valid_vmlinux_head()
{
TE32 buf[2];
fi->seek(p_text->sh_offset + sizeof(stub_arm_linux_kernel_vmlinux_head) -8, SEEK_SET); fi->seek(p_text->sh_offset + sizeof(stub_arm_linux_kernel_vmlinux_head) -8, SEEK_SET);
fi->readx(buf, sizeof(buf)); fi->readx(buf, sizeof(buf));
//unsigned const word0 = buf[0]; //unsigned const word0 = buf[0];
@@ -781,6 +1146,34 @@ bool PackVmlinuxARM::has_valid_vmlinux_head()
return false; return false;
} }
bool PackVmlinuxARMEB::has_valid_vmlinux_head()
{
TE32 buf[2];
fi->seek(p_text->sh_offset + sizeof(stub_armeb_linux_kernel_vmlinux_head) -8, SEEK_SET);
fi->readx(buf, sizeof(buf));
//unsigned const word0 = buf[0];
unsigned const word1 = buf[1];
if (0xeb==(word1>>24)
&& (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) {
return true;
}
return false;
}
bool PackVmlinuxPPC32::has_valid_vmlinux_head()
{
TE32 buf[2];
fi->seek(p_text->sh_offset + sizeof(stub_powerpc_linux_kernel_vmlinux_head) -8, SEEK_SET);
fi->readx(buf, sizeof(buf));
//unsigned const word0 = buf[0];
unsigned const word1 = buf[1];
if (0xeb==(word1>>24)
&& (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) {
return true;
}
return false;
}
bool PackVmlinuxI386::has_valid_vmlinux_head() bool PackVmlinuxI386::has_valid_vmlinux_head()
{ {
unsigned char buf[5]; unsigned char buf[5];
@@ -996,8 +1389,8 @@ bool PackVmlinuxAMD64::has_valid_vmlinux_head()
// pushl $0 // pushl $0
// pushl $ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED // pushl $ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED
// pushl $ PROT_EXEC | PROT_WRITE | PROT_READ // pushl $ PROT_EXEC | PROT_WRITE | PROT_READ
// pushl $0x600000 # 6MB length // pushl $0x600000 # 6 MiB length
// pushl $0x100000 # 1MB address // pushl $0x100000 # 1 MiB address
// call mmap // call mmap
// leal -0x9000(%esp),%esi # expect "lea 0x9000(%esi),%esp" later // leal -0x9000(%esp),%esi # expect "lea 0x9000(%esi),%esp" later
///* Fall into .text of upx-compressed vmlinux. */ ///* Fall into .text of upx-compressed vmlinux. */
@@ -1046,7 +1439,7 @@ const int *PackVmlinuxAMD64::getFilters() const
bool PackVmlinuxAMD64::is_valid_e_entry(Addr e_entry) bool PackVmlinuxAMD64::is_valid_e_entry(Addr e_entry)
{ {
return 0x200000<=e_entry; // 2MB return 0x200000<=e_entry; // 2 MiB
} }
Linker* PackVmlinuxAMD64::newLinker() const Linker* PackVmlinuxAMD64::newLinker() const
@@ -1058,6 +1451,7 @@ Linker* PackVmlinuxAMD64::newLinker() const
// instantiate instances // instantiate instances
template class PackVmlinuxBase<ElfClass_LE32>; template class PackVmlinuxBase<ElfClass_LE32>;
template class PackVmlinuxBase<ElfClass_BE32>;
template class PackVmlinuxBase<ElfClass_LE64>; template class PackVmlinuxBase<ElfClass_LE64>;
+58 -10
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -45,9 +45,9 @@ protected:
typedef typename ElfClass::BeLePolicy BeLePolicy; typedef typename ElfClass::BeLePolicy BeLePolicy;
typedef typename ElfClass::ElfITypes ElfITypes; typedef typename ElfClass::ElfITypes ElfITypes;
// integral types // integral types
typedef typename ElfClass::U16 U16; typedef typename ElfClass::TE16 TE16;
typedef typename ElfClass::U32 U32; typedef typename ElfClass::TE32 TE32;
typedef typename ElfClass::U64 U64; typedef typename ElfClass::TE64 TE64;
typedef typename ElfITypes::Addr Addr; typedef typename ElfITypes::Addr Addr;
// ELF types // ELF types
typedef typename ElfClass::Ehdr Ehdr; typedef typename ElfClass::Ehdr Ehdr;
@@ -119,14 +119,14 @@ protected:
}; };
class PackVmlinuxARM : public PackVmlinuxBase<ElfClass_LE32> class PackVmlinuxARMEL : public PackVmlinuxBase<ElfClass_LE32>
{ {
typedef PackVmlinuxBase<ElfClass_LE32> super; typedef PackVmlinuxBase<ElfClass_LE32> super;
public: public:
PackVmlinuxARM(InputFile *f) : super(f, Ehdr::EM_ARM, PackVmlinuxARMEL(InputFile *f) : super(f, Ehdr::EM_ARM,
Ehdr::ELFCLASS32, Ehdr::ELFDATA2LSB, "decompress_kernel") { } Ehdr::ELFCLASS32, Ehdr::ELFDATA2LSB, "decompress_kernel") { }
virtual int getFormat() const { return UPX_F_VMLINUX_ARM; } virtual int getFormat() const { return UPX_F_VMLINUX_ARMEL; }
virtual const char *getName() const { return "vmlinux/ARM"; } virtual const char *getName() const { return "vmlinux/armel"; }
virtual const char *getFullName(const options_t *) const { return "arm-linux.kernel.vmlinux"; } virtual const char *getFullName(const options_t *) const { return "arm-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const; virtual const int *getFilters() const;
@@ -143,6 +143,54 @@ protected:
); );
}; };
class PackVmlinuxARMEB : public PackVmlinuxBase<ElfClass_BE32>
{
typedef PackVmlinuxBase<ElfClass_BE32> super;
public:
PackVmlinuxARMEB(InputFile *f) : super(f, Ehdr::EM_ARM,
Ehdr::ELFCLASS32, Ehdr::ELFDATA2MSB, "decompress_kernel") { }
virtual int getFormat() const { return UPX_F_VMLINUX_ARMEB; }
virtual const char *getName() const { return "vmlinux/armeb"; }
virtual const char *getFullName(const options_t *) const { return "armeb-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
protected:
virtual void buildLoader(const Filter *ft);
virtual void defineDecompressorSymbols();
virtual Linker* newLinker() const;
virtual bool is_valid_e_entry(Addr);
virtual bool has_valid_vmlinux_head();
virtual unsigned write_vmlinux_head(
OutputFile *const fo,
Shdr *const stxt
);
};
class PackVmlinuxPPC32 : public PackVmlinuxBase<ElfClass_BE32>
{
typedef PackVmlinuxBase<ElfClass_BE32> super;
public:
PackVmlinuxPPC32(InputFile *f) : super(f, Ehdr::EM_PPC,
Ehdr::ELFCLASS32, Ehdr::ELFDATA2MSB, "_vmlinux_start") { }
virtual int getFormat() const { return UPX_F_VMLINUX_PPC32; }
virtual const char *getName() const { return "vmlinux/ppc32"; }
virtual const char *getFullName(const options_t *) const { return "powerpc-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
protected:
virtual void buildLoader(const Filter *ft);
virtual void defineDecompressorSymbols();
virtual Linker* newLinker() const;
virtual bool is_valid_e_entry(Addr);
virtual bool has_valid_vmlinux_head();
virtual unsigned write_vmlinux_head(
OutputFile *const fo,
Shdr *const stxt
);
};
class PackVmlinuxAMD64 : public PackVmlinuxBase<ElfClass_LE64> class PackVmlinuxAMD64 : public PackVmlinuxBase<ElfClass_LE64>
{ {
+599 -38
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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,12 +22,13 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#include "conf.h" #include "conf.h"
#include "p_elf.h"
#include "file.h" #include "file.h"
#include "filter.h" #include "filter.h"
#include "packer.h" #include "packer.h"
@@ -51,10 +52,11 @@ static const unsigned bzimage_offset = 0x100000;
**************************************************************************/ **************************************************************************/
PackVmlinuzI386::PackVmlinuzI386(InputFile *f) : PackVmlinuzI386::PackVmlinuzI386(InputFile *f) :
super(f), physical_start(0x100000) super(f), physical_start(0x100000), page_offset(0), config_physical_align(0)
, filter_len(0)
{ {
bele = &N_BELE_RTP::le_policy; bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x218); COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x250);
} }
@@ -73,6 +75,22 @@ const int *PackVmlinuzI386::getFilters() const
return filters; return filters;
} }
const int *PackBvmlinuzI386::getFilters() const
{
// The destination buffer might be relocated at runtime.
static const int filters[] = {
0x49, 0x46,
FT_END };
return filters;
}
int PackVmlinuzI386::getStrategy(Filter &/*ft*/)
{
// If user specified the filter, then use it (-2==filter_strategy).
// Else try the first two filters, and pick the better (2==filter_strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
}
bool PackVmlinuzI386::canPack() bool PackVmlinuzI386::canPack()
{ {
@@ -86,8 +104,6 @@ bool PackVmlinuzI386::canPack()
int PackVmlinuzI386::readFileHeader() int PackVmlinuzI386::readFileHeader()
{ {
boot_sect_t h;
setup_size = 0; setup_size = 0;
fi->readx(&h, sizeof(h)); fi->readx(&h, sizeof(h));
@@ -111,12 +127,16 @@ int PackVmlinuzI386::readFileHeader()
else if (hdrs && (h.load_flags & 1) != 0) else if (hdrs && (h.load_flags & 1) != 0)
{ {
format = UPX_F_BVMLINUZ_i386; format = UPX_F_BVMLINUZ_i386;
// account for 16-bit h.sys_size, wrap around at 20 bits
sys_size &= (1 << 20) - 1;
} }
if (16u * h.sys_size != sys_size) if (0x204<=h.version) {
if ((16u * h.sys_size) != sys_size)
return 0; return 0;
}
else { // h.sys_size is only 2 bytes
if ((16u * (0xffff & h.sys_size)) != (~(~0u<<20) & sys_size))
return 0;
}
// FIXME: add more checks for a valid kernel // FIXME: add more checks for a valid kernel
@@ -124,6 +144,11 @@ int PackVmlinuzI386::readFileHeader()
} }
static int is_pow2(unsigned const x)
{
return !(x & (x - 1));
}
// read full kernel into obuf[], gzip-decompress into ibuf[], // read full kernel into obuf[], gzip-decompress into ibuf[],
// return decompressed size // return decompressed size
int PackVmlinuzI386::decompressKernel() int PackVmlinuzI386::decompressKernel()
@@ -133,26 +158,96 @@ int PackVmlinuzI386::decompressKernel()
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
fi->readx(obuf, file_size); fi->readx(obuf, file_size);
// Find "ljmp $__BOOT_CS,$__PHYSICAL_START" if any. {
const upx_byte *base = NULL;
unsigned relocated = 0;
// See startup_32: in linux/arch/i386/boot/compressed/head.S // See startup_32: in linux/arch/i386/boot/compressed/head.S
char const *p = (char const *)&obuf[setup_size]; const upx_byte *p = &obuf[setup_size];
for (int j= 0; j < 0x200; ++j, ++p) unsigned cpa_0 = 0;
if (0==memcmp("\xEA\x00\x00", p, 3) && 0==(0xf & p[3]) && 0==p[4]) { unsigned cpa_1 = 0;
/* whole megabyte < 16MB */ int j;
physical_start = get_le32(1+ p); if (0x205<=h.version) {
cpa_0 = h.kernel_alignment;
cpa_1 = 0u - cpa_0;
} else
for ((p = &obuf[setup_size]), (j= 0); j < 0x200; ++j, ++p) {
if (0==memcmp("\x89\xeb\x81\xc3", p, 4)
&& 0==memcmp("\x81\xe3", 8+ p, 2)) {
// movl %ebp,%ebx
// addl $imm.w,%ebx
// andl $imm.w,%ebx
cpa_0 = 1+ get_te32( 4+ p);
cpa_1 = get_te32(10+ p);
break; break;
} }
}
for ((p = &obuf[setup_size]), (j= 0); j < 0x200; ++j, ++p) {
if (0==memcmp("\x8d\x83", p, 2) // leal d32(%ebx),%eax
&& 0==memcmp("\xff\xe0", 6+ p, 2) // jmp *%eax
) {
relocated = get_te32(2+ p);
}
if (0==memcmp("\xE8\x00\x00\x00\x00\x5D", p, 6)) {
// "call 1f; 1f: pop %ebp" determines actual execution address.
// linux-2.6.21 (spring 2007) and later; upx stub needs work
// unless LOAD_PHYSICAL_ADDR is known.
// Allowed code is: linux-2.6.23/arch/x86/head_32.S 2008-01-01
// call 1f
// 1: popl %ebp
// subl $1b, %ebp # 32-bit immediate
// movl $LOAD_PHYSICAL_ADDR, %ebx
//
if (0==memcmp("\x81\xed", 6+ p, 2) // subl $imm.w,%ebp
&& 0==memcmp("\xbb", 12+ p, 1) ) { // movl $imm.w,%ebx
physical_start = get_te32(13+ p);
} else
if (0==memcmp("\x81\xed", 6+ p, 2) // subl $imm.w,%ebp
&& is_pow2(cpa_0) && (0u-cpa_0)==cpa_1) {
base = (5+ p) - get_te32(8+ p);
config_physical_align = cpa_0;
}
else {
throwCantPack("Unrecognized relocatable kernel");
}
}
// Find "ljmp $__BOOT_CS,$__PHYSICAL_START" if any.
if (0==memcmp("\xEA\x00\x00", p, 3) && 0==(0xf & p[3]) && 0==p[4]) {
/* whole megabyte < 16 MiB */
physical_start = get_te32(1+ p);
break;
}
}
if (base && relocated) {
p = base + relocated;
for (j = 0; j < 0x200; ++j, ++p) {
if (0==memcmp("\x01\x9c\x0b", p, 3) // addl %ebx,d32(%ebx,%ecx)
) {
page_offset = 0u - get_te32(3+ p);
}
if (0==memcmp("\x89\xeb", p, 2) // movl %ebp,%ebx
&& 0==memcmp("\x81\xeb", 2+ p, 2) // subl $imm32,%ebx
) {
physical_start = get_te32(4+ p);
}
}
}
}
checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, (off_t)1024)); checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, (off_t)1024));
for (int gzoff = setup_size; gzoff < file_size; gzoff++) int gzoff = setup_size;
if (0x208<=h.version) {
gzoff += h.payload_offset;
}
for (; gzoff < file_size; gzoff++)
{ {
// find gzip header (2 bytes magic + 1 byte method "deflated") // find gzip header (2 bytes magic + 1 byte method "deflated")
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3); int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3);
if (off < 0) if (off < 0)
break; break;
gzoff += off; gzoff += off;
const int gzlen = file_size - gzoff; const int gzlen = (h.version < 0x208) ? (file_size - gzoff) : h.payload_length;
if (gzlen < 256) if (gzlen < 256)
break; break;
// check gzip flag byte // check gzip flag byte
@@ -201,6 +296,49 @@ int PackVmlinuzI386::decompressKernel()
if (klen <= gzlen) if (klen <= gzlen)
continue; continue;
if (0x208<=h.version && 0==memcmp("\177ELF", ibuf, 4)) {
// Full ELF in theory; for now, try to handle as .bin at physical_start.
// Check for PT_LOAD.p_paddr being ascending and adjacent.
Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)(void const *)ibuf;
Elf_LE32_Phdr const *phdr = (Elf_LE32_Phdr const *)(ehdr->e_phoff + (char const *)ehdr);
Elf_LE32_Shdr const *shdr = (Elf_LE32_Shdr const *)(ehdr->e_shoff + (char const *)ehdr);
unsigned hi_paddr = 0, lo_paddr = 0;
unsigned delta_off = 0;
for (unsigned j=0; j < ehdr->e_phnum; ++j, ++phdr) {
if (phdr->PT_LOAD==phdr->p_type) {
unsigned step = (hi_paddr + phdr->p_align - 1) & ~(phdr->p_align - 1);
if (0==hi_paddr) { // first PT_LOAD
if (physical_start!=phdr->p_paddr) {
return 0;
}
delta_off = phdr->p_paddr - phdr->p_offset;
lo_paddr = phdr->p_paddr;
hi_paddr = phdr->p_filesz + phdr->p_paddr;
}
else if (step==phdr->p_paddr
&& delta_off==(phdr->p_paddr - phdr->p_offset)) {
hi_paddr = phdr->p_filesz + phdr->p_paddr;
}
else {
return 0; // Not equivalent to a .bin. Too complex for now.
}
}
}
// FIXME: ascending order is only a convention; might need sorting.
for (unsigned j=1; j < ehdr->e_shnum; ++j) {
if (shdr->SHT_PROGBITS==shdr->sh_type) { // SHT_REL might be intermixed
if (shdr->SHF_EXECINSTR & shdr[j].sh_flags) {
filter_len += shdr[j].sh_size; // FIXME: include sh_addralign
}
else {
break;
}
}
}
memmove(ibuf, (lo_paddr - delta_off) + ibuf, hi_paddr - lo_paddr); // FIXME: set_size
// FIXME: .bss ? Apparently handled by head.S
}
if (opt->force > 0) if (opt->force > 0)
return klen; return klen;
@@ -208,15 +346,24 @@ int PackVmlinuzI386::decompressKernel()
if (fd_pos != file_size) if (fd_pos != file_size)
{ {
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size); //printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
throwCantPack("trailing bytes after kernel image; use option '-f' to force packing");
// linux-2.6.21.5/arch/i386/boot/compressed/vmlinux.lds
// puts .data.compressed ahead of .text, .rodata, etc;
// so piggy.o need not be last in bzImage. Alas.
//throwCantPack("trailing bytes after kernel image; use option '-f' to force packing");
} }
// see /usr/src/linux/arch/i386/kernel/head.S // see /usr/src/linux/arch/i386/kernel/head.S
// 2.4.x: cld; mov $...,%eax // 2.4.x: [cli;] cld; mov $...,%eax
if (memcmp(ibuf, "\xFC\xB8", 2) == 0) goto head_ok; if (memcmp(ibuf, "\xFC\xB8", 2) == 0) goto head_ok;
// 2.6.x: cld; lgdt ... if (memcmp(ibuf, "\xFA\xFC\xB8", 3) == 0) goto head_ok;
// 2.6.21.5 CONFIG_PARAVIRT mov %cs,%eax; test $3,%eax; jne ...;
if (memcmp(ibuf, "\x8c\xc8\xa9\x03\x00\x00\x00\x0f\x85", 9) == 0) goto head_ok;
if (memcmp(ibuf, "\x8c\xc8\xa8\x03\x0f\x85", 6) == 0) goto head_ok;
// 2.6.x: [cli;] cld; lgdt ...
if (memcmp(ibuf, "\xFC\x0F\x01", 3) == 0) goto head_ok; if (memcmp(ibuf, "\xFC\x0F\x01", 3) == 0) goto head_ok;
if (memcmp(ibuf, "\xFA\xFC\x0F\x01", 4) == 0) goto head_ok;
// 2.6.x+grsecurity+strongswan+openwall+trustix: ljmp $0x10,... // 2.6.x+grsecurity+strongswan+openwall+trustix: ljmp $0x10,...
if (ibuf[0] == 0xEA && memcmp(ibuf+5, "\x10\x00", 2) == 0) goto head_ok; if (ibuf[0] == 0xEA && memcmp(ibuf+5, "\x10\x00", 2) == 0) goto head_ok;
// x86_64 2.6.x // x86_64 2.6.x
@@ -227,6 +374,15 @@ int PackVmlinuzI386::decompressKernel()
&& 0x0F==ibuf[19] && 0xA2==ibuf[20] // cpuid && 0x0F==ibuf[19] && 0xA2==ibuf[20] // cpuid
) goto head_ok; ) goto head_ok;
// cmpw $0x207,0x206(%esi) Debian vmlinuz-2.6.24-12-generic
if (0==memcmp("\x66\x81\xbe\x06\x02\x00\x00\x07\x02", ibuf, 9)) goto head_ok;
// testb $0x40,0x211(%esi) Fedora vmlinuz-2.6.25-0.218.rc8.git7.fc9.i686
if (0==memcmp("\xf6\x86\x11\x02\x00\x00\x40", ibuf, 7)) goto head_ok;
// rex.W prefix for x86_64
if (0x48==ibuf[0]) throwCantPack("x86_64 bzImage is not yet supported");
throwCantPack("unrecognized kernel architecture; use option '-f' to force packing"); throwCantPack("unrecognized kernel architecture; use option '-f' to force packing");
head_ok: head_ok:
@@ -275,7 +431,7 @@ void PackVmlinuzI386::buildLoader(const Filter *ft)
// prepare loader // prepare loader
initLoader(stub_i386_linux_kernel_vmlinuz, sizeof(stub_i386_linux_kernel_vmlinuz)); initLoader(stub_i386_linux_kernel_vmlinuz, sizeof(stub_i386_linux_kernel_vmlinuz));
addLoader("LINUZ000", addLoader("LINUZ000",
ph.first_offset_found == 1 ? "LINUZ001" : "", ph.first_offset_found == 1 ? "LINUZ010" : "",
ft->id ? "LZCALLT1" : "", ft->id ? "LZCALLT1" : "",
"LZIMAGE0", "LZIMAGE0",
getDecompressorSections(), getDecompressorSections(),
@@ -303,8 +459,8 @@ void PackVmlinuzI386::pack(OutputFile *fo)
// compress // compress
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression // limit stack size needed for runtime decompression
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 512, &cconf); compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
const unsigned lsize = getLoaderSize(); const unsigned lsize = getLoaderSize();
@@ -321,6 +477,7 @@ void PackVmlinuzI386::pack(OutputFile *fo)
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf); boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16u) / 16; bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16u) / 16;
bs->payload_length = ph.c_len;
fo->write(setup_buf, setup_buf.getSize()); fo->write(setup_buf, setup_buf.getSize());
fo->write(loader, lsize); fo->write(loader, lsize);
@@ -348,21 +505,30 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(stub_i386_linux_kernel_vmlinuz, sizeof(stub_i386_linux_kernel_vmlinuz)); initLoader(stub_i386_linux_kernel_vmlinuz, sizeof(stub_i386_linux_kernel_vmlinuz));
addLoader("LINUZ000", if (0!=page_offset) { // relocatable kernel
ph.first_offset_found == 1 ? "LINUZ001" : "", assert(0==ft->id || 0x40==(0xf0 & ft->id)); // others assume fixed buffer address
addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ101,LINUZ110",
((0!=config_physical_align) ? "LINUZ120" : "LINUZ130"),
"LINUZ140,LZCUTPOI,LINUZ141",
(ft->id ? "LINUZ145" : ""),
(ph.first_offset_found == 1 ? "LINUZ010" : ""),
NULL);
}
else {
addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ005",
ph.first_offset_found == 1 ? "LINUZ010" : "",
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""), (0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
"LBZIMAGE,IDENTSTR", "LBZIMAGE,IDENTSTR",
"+40", // align the stuff to 4 byte boundary "+40", // align the stuff to 4 byte boundary
"UPX1HEAD", // 32 byte "UPX1HEAD", // 32 byte
"LZCUTPOI", "LZCUTPOI",
NULL); NULL);
// fake alignment for the start of the decompressor // fake alignment for the start of the decompressor
linker->defineSymbol("LZCUTPOI", 0x1000); //linker->defineSymbol("LZCUTPOI", 0x1000);
}
addLoader(getDecompressorSections(), NULL);
addLoader(getDecompressorSections(),
NULL
);
if (ft->id) if (ft->id)
{ {
assert(ft->calls > 0); assert(ft->calls > 0);
@@ -374,7 +540,27 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
} }
addFilter32(ft->id); addFilter32(ft->id);
} }
if (0!=page_offset) {
addLoader("LINUZ150,IDENTSTR,+40,UPX1HEAD", NULL);
unsigned const l_len = getLoaderSize();
unsigned const c_len = ALIGN_UP(ph.c_len, 4u);
unsigned const e_len = getLoaderSectionStart("LINUZ141") -
getLoaderSectionStart("LINUZ110");
linker->defineSymbol("compressed_length", c_len);
linker->defineSymbol("load_physical_address", physical_start); // FIXME
if (0!=config_physical_align) {
linker->defineSymbol("neg_config_physical_align", 0u - config_physical_align);
}
linker->defineSymbol("neg_length_mov", 0u - ALIGN_UP(c_len + l_len, 4u));
linker->defineSymbol("neg_page_offset", 0u - page_offset);
//linker->defineSymbol("physical_start", physical_start);
linker->defineSymbol("unc_length", ph.u_len);
linker->defineSymbol("dec_offset", ph.overlap_overhead + e_len);
linker->defineSymbol("unc_offset", ph.overlap_overhead + ph.u_len - c_len);
}
else {
addLoader("LINUZ990", NULL); addLoader("LINUZ990", NULL);
}
} }
@@ -384,13 +570,17 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
// prepare filter // prepare filter
Filter ft(ph.level); Filter ft(ph.level);
ft.buf_len = ph.u_len; ft.buf_len = (filter_len ? filter_len : (ph.u_len * 3)/5);
ft.addvalue = physical_start; // saves 4 bytes in unfilter code // May 2008: 3/5 is heuristic to cover most .text but avoid non-instructions.
// Otherwise "call trick" filter cannot find a free marker byte,
// especially when it searches over tables of data.
ft.addvalue = 0; // The destination buffer might be relocated at runtime.
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression // LINUZ001 allows most of low memory as stack for Bvmlinuz
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack cconf.conf_lzma.max_num_probs = (0x90000 - 0x10000)>>1; // ushort: 512 KiB stack
compressWithFilters(&ft, 512, &cconf);
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
// align everything to dword boundary - it is easier to handle // align everything to dword boundary - it is easier to handle
unsigned c_len = ph.c_len; unsigned c_len = ph.c_len;
@@ -418,6 +608,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
const int e_len = getLoaderSectionStart("LZCUTPOI"); const int e_len = getLoaderSectionStart("LZCUTPOI");
assert(e_len > 0); assert(e_len > 0);
if (0==page_offset) { // not relocatable kernel
const unsigned d_len4 = ALIGN_UP(lsize - e_len, 4u); const unsigned d_len4 = ALIGN_UP(lsize - e_len, 4u);
const unsigned decompr_pos = ALIGN_UP(ph.u_len + ph.overlap_overhead, 16u); const unsigned decompr_pos = ALIGN_UP(ph.u_len + ph.overlap_overhead, 16u);
const unsigned copy_size = c_len + d_len4; const unsigned copy_size = c_len + d_len4;
@@ -429,10 +620,13 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
linker->defineSymbol("words_to_copy", copy_size / 4); linker->defineSymbol("words_to_copy", copy_size / 4);
linker->defineSymbol("copy_dest", physical_start + edi); linker->defineSymbol("copy_dest", physical_start + edi);
linker->defineSymbol("copy_source", bzimage_offset + esi); linker->defineSymbol("copy_source", bzimage_offset + esi);
}
defineFilterSymbols(&ft); defineFilterSymbols(&ft);
defineDecompressorSymbols(); defineDecompressorSymbols();
if (0==page_offset) {
linker->defineSymbol("original_entry", physical_start); linker->defineSymbol("original_entry", physical_start);
}
linker->defineSymbol("stack_offset", stack_offset_during_uncompression); linker->defineSymbol("stack_offset", stack_offset_during_uncompression);
relocateLoader(); relocateLoader();
@@ -441,11 +635,21 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
patchPackHeader(loader, lsize); patchPackHeader(loader, lsize);
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf); boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
bs->sys_size = (ALIGN_UP(lsize + c_len, 16u) / 16) & 0xffff; bs->sys_size = (ALIGN_UP(lsize + c_len, 16u) / 16);
fo->write(setup_buf, setup_buf.getSize()); fo->write(setup_buf, setup_buf.getSize());
unsigned const e_pfx = (0==page_offset) ? 0 : getLoaderSectionStart("LINUZ110");
if (0!=page_offset) {
fo->write(loader, e_pfx);
}
else {
fo->write(loader, e_len); fo->write(loader, e_len);
}
fo->write(obuf, c_len); fo->write(obuf, c_len);
if (0!=page_offset) {
fo->write(loader + e_pfx, e_len - e_pfx);
}
fo->write(loader + e_len, lsize - e_len); fo->write(loader + e_len, lsize - e_len);
#if 0 #if 0
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize()); printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
@@ -479,7 +683,7 @@ int PackVmlinuzI386::canUnpack()
void PackVmlinuzI386::unpack(OutputFile *fo) void PackVmlinuzI386::unpack(OutputFile *fo)
{ {
// no uncompression support for this format, so that // no uncompression support for this format, so that
// it is possible to remove the original deflate code (>10KB) // it is possible to remove the original deflate code (>10 KiB)
// FIXME: but we could write the uncompressed "vmlinux" image // FIXME: but we could write the uncompressed "vmlinux" image
@@ -507,6 +711,363 @@ void PackVmlinuzI386::unpack(OutputFile *fo)
} }
PackVmlinuzARMEL::PackVmlinuzARMEL(InputFile *f) :
super(f), setup_size(0), filter_len(0)
{
bele = &N_BELE_RTP::le_policy;
}
const int *PackVmlinuzARMEL::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_8(method, level);
}
const int *PackVmlinuzARMEL::getFilters() const
{
static const int f50[] = { 0x50, FT_END };
return f50;
}
int PackVmlinuzARMEL::getStrategy(Filter &/*ft*/)
{
// If user specified the filter, then use it (-2==filter_strategy).
// Else try the first two filters, and pick the better (2==filter_strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
}
bool PackVmlinuzARMEL::canPack()
{
return readFileHeader() == getFormat();
}
int PackVmlinuzARMEL::readFileHeader()
{
unsigned int hdr[8];
fi->readx(hdr, sizeof(hdr));
for (int j=0; j < 8; ++j) {
if (0xe1a00000!=get_te32(&hdr[j])) {
return 0;
}
}
return UPX_F_VMLINUZ_ARMEL;
}
int PackVmlinuzARMEL::decompressKernel()
{
// read whole kernel image
obuf.alloc(file_size);
fi->seek(0, SEEK_SET);
fi->readx(obuf, file_size);
//checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, (off_t)1024));
// Find head.S:
// bl decompress_kernel # 0xeb......
// b call_kernel # 0xea......
//LC0: .word LC0 # self!
unsigned decompress_kernel = 0;
unsigned caller1 = 0;
unsigned caller2 = 0;
unsigned got_start = 0;
unsigned got_end = 0;
for (unsigned j = 0; j < 0x400; j+=4) {
unsigned w;
if (j!=get_te32(j + obuf)) {
continue;
}
if (0xea000000!=(0xff000000& get_te32(j - 4 + obuf))
|| 0xeb000000!=(0xff000000&(w= get_te32(j - 8 + obuf))) ) {
continue;
}
caller1 = j - 8;
decompress_kernel = ((0x00ffffff & w)<<2) + 8+ caller1;
for (unsigned k = 12; k<=128; k+=4) {
w = get_te32(j - k + obuf);
if (0xeb000000==(0xff000000 & w)
&& decompress_kernel==(((0x00ffffff & w)<<2) + 8+ j - k) ) {
caller2 = j - k;
break;
}
}
got_start = get_te32(5*4 + j + obuf);
got_end = get_te32(6*4 + j + obuf);
#if 0 /*{*/
printf("decompress_kernel=0x%x got_start=0x%x got_end=0x%x\n",
decompress_kernel, got_start, got_end);
#endif /*}*/
break;
}
if (0==decompress_kernel) {
return 0;
}
// Find first subroutine that is called by decompress_kernel,
// which we will consider to be the start of the gunzip module
// and the end of the non-gunzip modules.
for (unsigned j = decompress_kernel; j < (unsigned)file_size; j+=4) {
unsigned w = get_te32(j + obuf);
if (0xeb800000==(0xff800000 & w)) {
setup_size = 8+ ((0xff000000 | w)<<2) + j;
// Move the GlobalOffsetTable.
for (unsigned k = got_start; k < got_end; k+=4) {
w = get_te32(k + obuf);
// FIXME: must relocate w
set_te32(k - got_start + setup_size + obuf, w);
}
setup_size += got_end - got_start;
set_te32(&obuf[caller1], 0xeb000000 |
(0x00ffffff & ((setup_size - (8+ caller1))>>2)) );
set_te32(&obuf[caller2], 0xeb000000 |
(0x00ffffff & ((setup_size - (8+ caller2))>>2)) );
break;
}
}
for (int gzoff = 0; gzoff < 0x4000; gzoff+=4) {
// find gzip header (2 bytes magic + 1 byte method "deflated")
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3);
if (off < 0 || 0!=(3u & off))
break; // not found, or not word-aligned
gzoff += off;
const int gzlen = file_size - gzoff;
if (gzlen < 256)
break;
// check gzip flag byte
unsigned char flags = obuf[gzoff + 3];
if ((flags & 0xe0) != 0) // reserved bits set
continue;
//printf("found gzip header at offset %d\n", gzoff);
// try to decompress
int klen;
int fd;
off_t fd_pos;
for (;;)
{
klen = -1;
fd = -1;
fd_pos = -1;
// open
fi->seek(gzoff, SEEK_SET);
fd = dup(fi->getFd());
if (fd < 0)
break;
gzFile zf = gzdopen(fd, "rb");
if (zf == NULL)
break;
// estimate gzip-decompressed kernel size & alloc buffer
if (ibuf.getSize() == 0)
ibuf.alloc(gzlen * 3);
// decompress
klen = gzread(zf, ibuf, ibuf.getSize());
fd_pos = lseek(fd, 0, SEEK_CUR);
gzclose(zf);
fd = -1;
if (klen != (int)ibuf.getSize())
break;
// realloc and try again
unsigned const s = ibuf.getSize();
ibuf.dealloc();
ibuf.alloc(3 * s / 2);
}
if (fd >= 0)
(void) close(fd);
if (klen <= 0)
continue;
if (klen <= gzlen)
continue;
if (opt->force > 0)
return klen;
// some checks
if (fd_pos != file_size) {
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
}
//head_ok:
// FIXME: more checks for special magic bytes in ibuf ???
// FIXME: more checks for kernel architecture ???
return klen;
}
return 0;
}
void PackVmlinuzARMEL::readKernel()
{
int klen = decompressKernel();
if (klen <= 0)
throwCantPack("kernel decompression failed");
//OutputFile::dump("kernel.img", ibuf, klen);
// copy the setup boot code
setup_buf.alloc(setup_size);
memcpy(setup_buf, obuf, setup_size);
//OutputFile::dump("setup.img", setup_buf, setup_size);
obuf.dealloc();
obuf.allocForCompression(klen);
ph.u_len = klen;
ph.filter = 0;
}
Linker* PackVmlinuzARMEL::newLinker() const
{
return new ElfLinkerArmLE;
}
static const
#include "stub/arm-linux.kernel.vmlinux.h"
static const
#include "stub/armel-linux.kernel.vmlinuz-head.h"
void PackVmlinuzARMEL::buildLoader(const Filter *ft)
{
// prepare loader; same as vmlinux (with 'x')
initLoader(stub_arm_linux_kernel_vmlinux, sizeof(stub_arm_linux_kernel_vmlinux));
addLoader("LINUX000", NULL);
if (ft->id) {
assert(ft->calls > 0);
addLoader("LINUX010", NULL);
}
addLoader("LINUX020", NULL);
if (ft->id) {
addFilter32(ft->id);
}
addLoader("LINUX030", NULL);
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL);
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL);
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00",
(opt->small ? "LZMA_DEC10" : "LZMA_DEC20"), "LZMA_DEC30", NULL);
else throwBadLoader();
addLoader("IDENTSTR,UPX1HEAD", NULL);
// To debug (2008-09-14):
// Build gdb-6.8-21.fc9.src.rpm; ./configure --target=arm-none-elf; make
// Contains the fix for http://bugzilla.redhat.com/show_bug.cgi?id=436037
// Install qemu-0.9.1-6.fc9.i386.rpm
// qemu-system-arm -s -S -kernel <file> -nographic
// (gdb) target remote localhost:1234
// A very small boot loader runs at pc=0x0; the kernel is at 0x10000 (64KiB).
}
void PackVmlinuzARMEL::defineDecompressorSymbols()
{
super::defineDecompressorSymbols();
linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len);
linker->defineSymbol("METHOD", ph.method);
}
unsigned PackVmlinuzARMEL::write_vmlinuz_head(OutputFile *const fo)
{ // First word from vmlinuz-head.S
fo->write(&stub_armel_linux_kernel_vmlinuz_head[0], 4);
// Second word
LE32 tmp_u32;
unsigned const t = (0xff000000 &
get_te32(&stub_armel_linux_kernel_vmlinuz_head[4]))
| (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
tmp_u32 = t;
fo->write((void const *)&tmp_u32, 4);
return sizeof(stub_armel_linux_kernel_vmlinuz_head);
}
void PackVmlinuzARMEL::pack(OutputFile *fo)
{
readKernel();
// prepare filter
Filter ft(ph.level);
ft.buf_len = ph.u_len;
ft.addvalue = 0;
// compress
upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression
cconf.conf_lzma.max_num_probs = 1846 + (768 << 5); // ushort: 52,844 byte stack
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
const unsigned lsize = getLoaderSize();
defineDecompressorSymbols();
defineFilterSymbols(&ft);
relocateLoader();
MemBuffer loader(lsize);
memcpy(loader, getLoader(), lsize);
patchPackHeader(loader, lsize);
// boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
// bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16u) / 16;
// bs->payload_length = ph.c_len;
fo->write(setup_buf, setup_buf.getSize());
write_vmlinuz_head(fo);
fo->write(obuf, ph.c_len);
unsigned const zero = 0;
fo->write((void const *)&zero, 3u & (0u - ph.c_len));
fo->write(loader, lsize);
#if 0
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
#endif
// verify
verifyOverlappingDecompression();
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
throwNotCompressible();
}
int PackVmlinuzARMEL::canUnpack()
{
if (readFileHeader() != getFormat())
return false;
fi->seek(setup_size, SEEK_SET);
return readPackHeader(1024) ? 1 : -1;
}
void PackVmlinuzARMEL::unpack(OutputFile *fo)
{
// no uncompression support for this format, so that
// it is possible to remove the original deflate code (>10 KiB)
// FIXME: but we could write the uncompressed "vmlinux" image
ibuf.alloc(ph.c_len);
obuf.allocForUncompression(ph.u_len);
fi->seek(setup_size + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
fi->readx(ibuf, ph.c_len);
// decompress
decompress(ibuf, obuf);
// unfilter
Filter ft(ph.level);
ft.init(ph.filter, 0);
ft.cto = (unsigned char) ph.filter_cto;
ft.unfilter(obuf, ph.u_len);
// write decompressed file
if (fo)
{
throwCantUnpack("build a new kernel instead :-)");
//fo->write(obuf, ph.u_len);
}
}
/* /*
vi:ts=4:et vi:ts=4:et
*/ */
+67 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -45,6 +45,7 @@ public:
virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.vmlinuz"; } virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.vmlinuz"; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const; virtual const int *getFilters() const;
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo); virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo); virtual void unpack(OutputFile *fo);
@@ -63,13 +64,12 @@ protected:
// virtual upx_byte *getLoader() const; // virtual upx_byte *getLoader() const;
// virtual int getLoaderSize() const; // virtual int getLoaderSize() const;
struct boot_sect_t __packed_struct(boot_sect_t)
{
char _[0x1f1]; char _[0x1f1];
unsigned char setup_sects; unsigned char setup_sects;
char __[2]; char __[2];
LE16 sys_size; LE32 sys_size;
char ___[8]; char ___[6];
LE16 boot_flag; // 0xAA55 LE16 boot_flag; // 0xAA55
// 0x200 // 0x200
char ____[2]; char ____[2];
@@ -79,15 +79,24 @@ protected:
unsigned char load_flags; unsigned char load_flags;
char ______[2]; char ______[2];
LE32 code32_start; LE32 code32_start;
char _7[0x230 - (0x214 + 4)];
LE32 kernel_alignment;
char relocatable_kernel;
char _8[0x248 - (0x234 + 1)];
LE32 payload_offset;
LE32 payload_length;
// some more uninteresting fields here ... // some more uninteresting fields here ...
// see /usr/src/linux/Documentation/i386/zero-page.txt // see /usr/src/linux/Documentation/i386/boot.txt
} __packed_struct_end()
__attribute_packed;
boot_sect_t h;
MemBuffer setup_buf; MemBuffer setup_buf;
int setup_size; int setup_size;
unsigned physical_start; unsigned physical_start;
unsigned page_offset;
unsigned config_physical_align;
unsigned filter_len;
}; };
@@ -103,6 +112,7 @@ public:
virtual int getFormat() const { return UPX_F_BVMLINUZ_i386; } virtual int getFormat() const { return UPX_F_BVMLINUZ_i386; }
virtual const char *getName() const { return "bvmlinuz/386"; } virtual const char *getName() const { return "bvmlinuz/386"; }
virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.bvmlinuz"; } virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.bvmlinuz"; }
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo); virtual void pack(OutputFile *fo);
@@ -139,6 +149,52 @@ protected:
}; };
/*************************************************************************
// vmlinuz/armel (gzip compressed Linux kernel image)
**************************************************************************/
class PackVmlinuzARMEL : public Packer
{
typedef Packer super;
public:
PackVmlinuzARMEL(InputFile *f);
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUZ_ARMEL; }
virtual const char *getName() const { return "vmlinuz/armel"; }
virtual const char *getFullName(const options_t *) const { return "armel-linux.kernel.vmlinuz"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
virtual bool canPack();
virtual int canUnpack();
protected:
virtual int readFileHeader();
virtual int decompressKernel();
virtual void readKernel();
virtual void buildLoader(const Filter *ft);
virtual unsigned write_vmlinuz_head(OutputFile *const fo);
virtual void defineDecompressorSymbols();
virtual Linker* newLinker() const;
// virtual upx_byte *getLoader() const;
// virtual int getLoaderSize() const;
MemBuffer setup_buf;
int setup_size;
// unsigned physical_start;
// unsigned page_offset;
// unsigned config_physical_align;
unsigned filter_len;
};
#endif /* already included */ #endif /* already included */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
+5 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -42,7 +42,8 @@ public:
virtual int getVersion() const { return 13; } virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_WIN16_NE; } virtual int getFormat() const { return UPX_F_WIN16_NE; }
virtual const char *getName() const { return "win16/ne"; } virtual const char *getName() const { return "win16/ne"; }
virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_286 ? "i286-win16.ne" : "i386-win16.ne"; } //virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_286 ? "i286-win16.ne" : "i386-win16.ne"; }
virtual const char *getFullName(const options_t *) const { return "i286-win16.ne"; }
virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const; virtual const int *getFilters() const;
+21 -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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
@@ -164,7 +164,7 @@ int PackW32Pe::readFileHeader()
char buf[6]; char buf[6];
fi->seek(0x200, SEEK_SET); fi->seek(0x200, SEEK_SET);
fi->readx(buf, 6); fi->readx(buf, 6);
isrtm = memcmp(&buf, "32STUB" ,6) == 0; isrtm = memcmp(buf, "32STUB" ,6) == 0;
return super::readFileHeader(); return super::readFileHeader();
} }
@@ -173,14 +173,12 @@ int PackW32Pe::readFileHeader()
// import handling // import handling
**************************************************************************/ **************************************************************************/
struct import_desc __packed_struct(import_desc)
{
LE32 oft; // orig first thunk LE32 oft; // orig first thunk
char _[8]; char _[8];
LE32 dllname; LE32 dllname;
LE32 iat; // import address table LE32 iat; // import address table
} __packed_struct_end()
__attribute_packed;
void PackW32Pe::processImports(unsigned myimport, unsigned) // pass 2 void PackW32Pe::processImports(unsigned myimport, unsigned) // pass 2
{ {
@@ -592,6 +590,10 @@ void PackW32Pe::buildLoader(const Filter *ft)
void PackW32Pe::pack(OutputFile *fo) void PackW32Pe::pack(OutputFile *fo)
{ {
// FIXME: we need to think about better support for --exact
if (opt->exact)
throwCantPackExact();
const unsigned objs = ih.objects; const unsigned objs = ih.objects;
isection = new pe_section_t[objs]; isection = new pe_section_t[objs];
fi->seek(pe_offset+sizeof(ih),SEEK_SET); fi->seek(pe_offset+sizeof(ih),SEEK_SET);
@@ -607,7 +609,8 @@ void PackW32Pe::pack(OutputFile *fo)
(ih.cpu < 0x14c || ih.cpu > 0x150) (ih.cpu < 0x14c || ih.cpu > 0x150)
|| (ih.opthdrsize != 0xe0) || (ih.opthdrsize != 0xe0)
|| ((ih.flags & EXECUTABLE) == 0) || ((ih.flags & EXECUTABLE) == 0)
|| (ih.subsystem != 2 && ih.subsystem != 3 && ih.subsystem != 1) || (ih.subsystem != 2 && ih.subsystem != 3
&& ih.subsystem != 1 && ih.subsystem != 9)
|| (ih.entry == 0 && !isdll) || (ih.entry == 0 && !isdll)
|| (ih.ddirsentries != 16) || (ih.ddirsentries != 16)
|| IDSIZE(PEDIR_EXCEPTION) // is this used on i386? || IDSIZE(PEDIR_EXCEPTION) // is this used on i386?
@@ -615,6 +618,9 @@ void PackW32Pe::pack(OutputFile *fo)
)) ))
throwCantPack("unexpected value in PE header (try --force)"); throwCantPack("unexpected value in PE header (try --force)");
if (ih.subsystem == 9)
throwCantPack("x86/wince files are not yet supported");
if (IDSIZE(PEDIR_SEC)) if (IDSIZE(PEDIR_SEC))
IDSIZE(PEDIR_SEC) = IDADDR(PEDIR_SEC) = 0; IDSIZE(PEDIR_SEC) = IDADDR(PEDIR_SEC) = 0;
if (IDSIZE(PEDIR_COMRT)) if (IDSIZE(PEDIR_COMRT))
@@ -625,10 +631,12 @@ void PackW32Pe::pack(OutputFile *fo)
else if (opt->win32_pe.strip_relocs < 0) else if (opt->win32_pe.strip_relocs < 0)
opt->win32_pe.strip_relocs = (ih.imagebase >= 0x400000); opt->win32_pe.strip_relocs = (ih.imagebase >= 0x400000);
if (opt->win32_pe.strip_relocs) if (opt->win32_pe.strip_relocs)
{
if (ih.imagebase < 0x400000) if (ih.imagebase < 0x400000)
throwCantPack("--strip-relocs is not allowed when imagebase < 0x400000"); throwCantPack("--strip-relocs is not allowed when imagebase < 0x400000");
else else
ih.flags |= RELOCS_STRIPPED; ih.flags |= RELOCS_STRIPPED;
}
if (memcmp(isection[0].name,"UPX",3) == 0) if (memcmp(isection[0].name,"UPX",3) == 0)
throwAlreadyPackedByUPX(); throwAlreadyPackedByUPX();
@@ -1017,6 +1025,8 @@ void PackW32Pe::pack(OutputFile *fo)
oh.codebase = osection[1].vaddr; oh.codebase = osection[1].vaddr;
// oh.headersize = osection[0].rawdataptr; // oh.headersize = osection[0].rawdataptr;
oh.headersize = rvamin; oh.headersize = rvamin;
if (rvamin < osection[0].rawdataptr)
throwCantPack("object alignment too small");
if (opt->win32_pe.strip_relocs && !isdll) if (opt->win32_pe.strip_relocs && !isdll)
oh.flags |= RELOCS_STRIPPED; oh.flags |= RELOCS_STRIPPED;
@@ -1025,7 +1035,7 @@ void PackW32Pe::pack(OutputFile *fo)
// set_le32(ibuf + ic,get_le32("UPX ")); // set_le32(ibuf + ic,get_le32("UPX "));
ibuf.clear(0, oh.filealign); ibuf.clear(0, oh.filealign);
info("Image size change: %u -> %u kBytes", info("Image size change: %u -> %u KiB",
ih.imagesize / 1024, oh.imagesize / 1024); ih.imagesize / 1024, oh.imagesize / 1024);
infoHeader("[Writing compressed file]"); infoHeader("[Writing compressed file]");
@@ -1093,7 +1103,7 @@ void PackW32Pe::pack(OutputFile *fo)
int PackW32Pe::canUnpack() int PackW32Pe::canUnpack()
{ {
if (!readFileHeader()) if (!readFileHeader() || ih.cpu < 0x14c || ih.cpu > 0x150)
return false; return false;
unsigned objs = ih.objects; unsigned objs = ih.objects;
+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-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2009 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar Copyright (C) 1996-2009 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */

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