Compare commits

..

802 Commits

Author SHA1 Message Date
Markus F.X.J. Oberhumer 70632e5541 Bump release date. 2007-01-23 22:11:23 +01:00
John Reiser 0bba700105 merge 2007-01-23 10:35:20 -08:00
John Reiser b71aaccff3 fix amd64-linux.elf-entry.S invoking large programs (>3MB compressed) 2007-01-23 10:34:33 -08:00
Markus F.X.J. Oberhumer 7271ae9611 Small updates. 2007-01-23 13:50:39 +01:00
László Molnár 6e32dff2ad armpe_tester.c updated to work with files containing 4 sections 2007-01-17 21:53:18 +01:00
László Molnár 8f7c898c08 use an exception instead of assert() for overlay checking (bug #1624840) 2007-01-16 12:58:35 +01:00
Markus F.X.J. Oberhumer f4a9815f48 Keep entries sorted in stub/Makefile. 2007-01-15 07:46:22 +01:00
John Reiser 0f8d5c7e98 arm-linux.kernel.vmlinux.S remove unused sections 2007-01-14 13:40:50 -08:00
Markus F.X.J. Oberhumer 5e83596a1b Enter 2007. 2007-01-14 13:08:58 +01:00
Markus F.X.J. Oberhumer 6361213e07 More portability fixes. 2007-01-14 12:47:38 +01:00
John Reiser 9c59a5d9b6 p_vmlinx test jig for ARM 2007-01-13 17:30:03 -08:00
John Reiser bb04844bd5 Decompressor for UPX_F_VMLINUX_ARM follows ELF convention 2007-01-13 15:26:05 -08:00
Markus F.X.J. Oberhumer 0b988176fa Portability fixes. 2007-01-10 17:16:59 +01:00
Markus F.X.J. Oberhumer a354f18a2d Consistently use .arch nojumps on i086 and i386. 2007-01-09 22:40:01 +01:00
Markus F.X.J. Oberhumer a7ca0fec88 Merge. 2007-01-09 18:31:13 +01:00
Markus F.X.J. Oberhumer 06eec508df Cosmetic macros.S cleanups. 2007-01-09 18:27:53 +01:00
John Reiser 10dc580a3a tweak i386-linux.kernel.vmlinux-head.S 2007-01-08 13:56:47 -08:00
John Reiser 2f6ae3ef01 merge 2007-01-07 16:33:04 -08:00
John Reiser 392e803905 vmlinux/AMD64 works 2007-01-07 16:31:46 -08:00
John Reiser 83a5fb585b ELF External_Note 2007-01-03 06:54:48 -08:00
László Molnár c6205ffbe0 tls index should be zero after decompression 2007-01-02 18:16:16 +01:00
Markus F.X.J. Oberhumer c04737ce20 Cosmetic cleanup. 2006-12-31 15:51:17 +01:00
John Reiser 11b92172fe PackVmlinuxBase my_boot_label; kernel Makefiles 2006-12-25 13:55:28 -08:00
László Molnár 3a6c574376 pe: correctly handle import table with 0 entries during decompression (#1620733) 2006-12-24 16:25:36 +01:00
Markus F.X.J. Oberhumer b21ce925fb Factor out a common Packer::defineFilterSymbols(). Enable filters
0x49 and 0x49 for all i386-dos32.* formats. Needs testing.
2006-12-22 16:39:42 +01:00
Markus F.X.J. Oberhumer de9dcc4ed6 Enable filters 0x49 and 0x46 for win32/pe. This needs some more testing. 2006-12-22 15:28:14 +01:00
Markus F.X.J. Oberhumer 9e77dbfe20 Added an assertion to make sure I've really understood the semantics
of the ctok32 filter length.
2006-12-22 15:19:51 +01:00
Markus F.X.J. Oberhumer 4cee0676a4 Consistently rename section names of ctok32 filter. 2006-12-22 14:22:45 +01:00
Markus F.X.J. Oberhumer 8ad9d21db3 Also add ICHECK() calls to p_armpe.cpp. 2006-12-22 13:37:19 +01:00
Markus F.X.J. Oberhumer 8ba8317eea sf.net bug #1620733: As a very first step, added two calls to
ICHECK(dname,1). Of course we still need a proper fix for this.
2006-12-22 13:35:39 +01:00
Markus F.X.J. Oberhumer d221187f24 Misc cosmetical cleanups. 2006-12-22 12:36:55 +01:00
Markus F.X.J. Oberhumer db54ec294f Added some missing stub/tmp/*.bin.dump files. 2006-12-20 10:50:49 +01:00
John Reiser 1d39796e3f PackVmlinuxBase::canPack bug for AMD64 with holes between PT_LOAD 2006-12-19 18:18:47 -08:00
John Reiser cd6a318903 cleanup merge 2006-12-19 16:19:19 -08:00
John Reiser 73090b98ab merge 2006-12-19 16:16:20 -08:00
John Reiser 745de1abab refactor PackVmlinuxBase::pack() 2006-12-19 16:12:59 -08:00
John Reiser 961031efc1 make_st_info() 2006-12-19 16:12:15 -08:00
Markus F.X.J. Oberhumer 2487595778 vmlinux: U32 already has target-endian representation, so there is no need
to call BeLePolicy::get32() here.
2006-12-19 22:39:37 +01:00
John Reiser 5c4863d504 refactor PackVmlinuxBase ::canUnpack(), ::unpack() 2006-12-19 10:58:20 -08:00
Markus F.X.J. Oberhumer 5e3a658932 Made a method pure virtual. 2006-12-19 16:21:57 +01:00
Markus F.X.J. Oberhumer cb4704c821 Cosmetic cleanups. 2006-12-19 15:22:50 +01:00
Markus F.X.J. Oberhumer cc0b7d1492 Use the preprocessor to make sure that the ELF types are PODs. 2006-12-19 14:43:14 +01:00
Markus F.X.J. Oberhumer f8ebbf8b08 Rework p_elf.h. 2006-12-19 14:24:35 +01:00
Markus F.X.J. Oberhumer 8795f60bf1 vmlinux: use template types throughout. 2006-12-19 11:06:58 +01:00
Markus F.X.J. Oberhumer f00c0a9436 Fix typo. 2006-12-19 11:04:47 +01:00
Markus F.X.J. Oberhumer 767bc71870 Expose integral types in p_elf.h. 2006-12-19 10:49:13 +01:00
John Reiser 4c068e3e00 PackVmlinuxBase::canPack(); templates are fun! 2006-12-18 22:55:38 -08:00
John Reiser 277d862172 PackVmlinuxBase try template definitions in .cpp file 2006-12-18 20:17:10 -08:00
John Reiser dbed6a47bb PackVmlinuxBase use simple templates 2006-12-18 20:08:24 -08:00
Markus F.X.J. Oberhumer 94f3749784 vmlinux refactoring: move destructor into PackVmlinuxBase. 2006-12-19 00:48:38 +01:00
Markus F.X.J. Oberhumer 728e6d851e Introduce ElfClass and PackVmlinuxBase for refactoring elf based packers. 2006-12-19 00:37:35 +01:00
Markus F.X.J. Oberhumer 11e863545f Strip trailing whitespace. 2006-12-18 16:56:14 +01:00
Markus F.X.J. Oberhumer dde49f0bb4 Try to avoid fatal filter failures by better scanning during the setup phase. 2006-12-18 16:54:14 +01:00
Markus F.X.J. Oberhumer a37a75aecc First step for preprocessing dumps with xstrip.py. Not working yet. 2006-12-18 16:39:57 +01:00
John Reiser e43e3aeb1c arm-linux.kernel documentation update for Debian on nslu2 2006-12-17 18:49:38 -08:00
John Reiser a8fe529814 arm-linux.kernel preserve .e_flags 2006-12-17 17:39:47 -08:00
John Reiser d9f5e2bb08 arm-linux.kernel alignment fix 2006-12-17 16:34:21 -08:00
John Reiser dfa83b0ac8 arm-linux.kernel methods 2006-12-17 15:34:13 -08:00
John Reiser bd5cef1411 unfilter for arm-linux.kernel 2006-12-17 14:53:10 -08:00
John Reiser cd70b48831 src/stub/src/arch/arm/v5a directory 2006-12-17 13:24:14 -08:00
John Reiser 50ebf8088a R_ARM_ABS8 2006-12-17 13:19:37 -08:00
John Reiser c5cfb7eb40 more arm-linux.kernel work 2006-12-16 22:02:51 -08:00
John Reiser bccaafda6d arm-linux stub interfacing for lzma 2006-12-16 17:16:32 -08:00
John Reiser bf0086d7b5 arm-linux.kernel decompressor 2006-12-16 14:52:22 -08:00
John Reiser 7e65938ca6 fix filename in initial comment 2006-12-16 08:40:41 -08:00
John Reiser 112eff2509 add UPX_F_VMLINUX_AMD64, UPX_F_VMLINUX_ARM 2006-12-16 08:13:34 -08:00
Markus F.X.J. Oberhumer d7837d9179 Use FT_ULTRA_BRUTE. 2006-12-12 10:06:24 +01:00
Markus F.X.J. Oberhumer 6cdd057f80 Coding style cleanups. 2006-12-12 10:05:57 +01:00
Markus F.X.J. Oberhumer 5a03b213fb More stricter check in xstrip.py. 2006-12-12 07:50:05 +01:00
Markus F.X.J. Oberhumer f270213246 Make sure ph.first_offset_found is set. 2006-12-12 07:49:50 +01:00
László Molnár 2e1795c5ba win32/pe: loadconf data should not be put into section 2 2006-12-10 23:42:27 +01:00
Markus F.X.J. Oberhumer 732d6710d3 Remove misleading "const" from Linker::preprocessXX(). 2006-12-10 00:38:28 +01:00
Markus F.X.J. Oberhumer edf384d2ee Micro-optimization: save 1 byte in tmt/adam stub. 2006-12-09 13:56:47 +01:00
László Molnár c307640826 use memcmp instead of strncmp when searching for ljmp 2006-12-08 19:20:35 +01:00
Markus F.X.J. Oberhumer a77b598f82 Implement a micro-optimization which has been on our TODO list for ages:
remove "or ebp,-1" when not needed
2006-12-08 09:20:14 +01:00
Markus F.X.J. Oberhumer 217420cfa5 Also verifyOverlappingDecompression() for watcom/le. 2006-12-06 12:20:22 +01:00
Markus F.X.J. Oberhumer f2b9dff596 More work so that watom/le now uses compressWithFilters(). 2006-12-06 11:08:32 +01:00
Markus F.X.J. Oberhumer ae945ed315 Clean up help and avoid using backticks as quoting chars. 2006-12-06 08:11:55 +01:00
Markus F.X.J. Oberhumer 770c153c76 Start using FT_ULTRA_BRUTE. 2006-12-06 07:42:43 +01:00
Markus F.X.J. Oberhumer 29c4a7e606 Remove debugging leftover. 2006-12-06 07:34:57 +01:00
Markus F.X.J. Oberhumer 8875470b37 Refactored compressWithFilters(). 2006-12-06 07:27:23 +01:00
Markus F.X.J. Oberhumer 6e52364bcb Minor cleanup of callback code. 2006-12-05 17:09:18 +01:00
Markus F.X.J. Oberhumer 7015d616b4 Whitespace changes. 2006-12-05 17:06:37 +01:00
László Molnár 92e6da3260 use the current version of http://www.gnu.org/licenses/gpl.txt 2006-12-05 12:16:42 +01:00
László Molnár 9220b6f1d5 win32/pe should only handle ix86 files 2006-12-03 10:46:14 +01:00
Markus F.X.J. Oberhumer 1d0d538d0c Added new option '--ultra-brute'. 2006-12-01 02:47:46 +01:00
Markus F.X.J. Oberhumer 83052eafae Minor cleanups. 2006-12-01 00:57:03 +01:00
Markus F.X.J. Oberhumer fa95c3c4a2 Display full format name with --fileinfo. 2006-11-30 23:34:19 +01:00
Markus F.X.J. Oberhumer 665dcf221b Cosmetic cleanup. 2006-11-30 23:21:47 +01:00
Markus F.X.J. Oberhumer 8f73dbd253 Mention --compress-icons=3. 2006-11-30 23:18:21 +01:00
Markus F.X.J. Oberhumer 826312cbad Show all supported formats in show_help(). 2006-11-30 23:17:22 +01:00
Markus F.X.J. Oberhumer 72a18f2b3f Added Packer::getFullName() method. 2006-11-29 06:44:48 +01:00
Markus F.X.J. Oberhumer a6b5e3d0ae Bump version for next release. 2006-11-29 05:41:39 +01:00
Markus F.X.J. Oberhumer 1b321f4fa3 Added tag for RELEASE_291. 2006-11-29 05:14:25 +01:00
Markus F.X.J. Oberhumer fbde0b9f35 Bump release date. 2006-11-29 03:43:29 +01:00
Markus F.X.J. Oberhumer 0e5f5e54cc Initalize isrtm member. 2006-11-27 17:35:16 +01:00
Markus F.X.J. Oberhumer cbb5902066 Improve xstrip.py. 2006-11-25 15:36:56 +01:00
Markus F.X.J. Oberhumer 92ec1b0598 Add and use stub/scripts/xstrip.py. 2006-11-23 05:27:40 +01:00
Markus F.X.J. Oberhumer a62fc3abff Try to remove .shstrtab, .strtab and .symtab sections. This does not seem to
work with objcopy.
2006-11-23 03:31:43 +01:00
Markus F.X.J. Oberhumer 08f8e55446 More updates on bin2h.py. 2006-11-23 03:11:53 +01:00
Markus F.X.J. Oberhumer 68f54a3247 Updated bin2h.py. 2006-11-23 02:23:39 +01:00
Markus F.X.J. Oberhumer 29c099fe56 Disallow --exact with --overlay=strip. 2006-11-22 19:29:07 +01:00
Markus F.X.J. Oberhumer 76b81c7b35 More stricter check for arm-wince Debian. 2006-11-22 18:52:57 +01:00
László Molnár d6b33ffd6b pe: --compress-icons=3 option added to compress all icons 2006-11-22 15:28:35 +01:00
Markus F.X.J. Oberhumer 16b9873fa8 Quick workaround for arm-wince build with Debian cross-compiler packages. 2006-11-22 01:56:59 +01:00
Markus F.X.J. Oberhumer ba4a686d1c Fix endian issue in execve formats. 2006-11-21 18:42:38 +01:00
László Molnár 4be3d79e12 arm/pe: fix "missing" icon & version info resource problem for wince 5 2006-11-21 18:25:23 +01:00
Markus F.X.J. Oberhumer 2569b09dbe Added debugging option --disable-random-id. 2006-11-21 18:17:51 +01:00
Markus F.X.J. Oberhumer 5d71e69941 Added two checks for throwCantPackExact. 2006-11-21 18:01:16 +01:00
Markus F.X.J. Oberhumer 16163bf20b Initial support for option '--exact'. 2006-11-21 17:53:11 +01:00
Markus F.X.J. Oberhumer f1a97fecbd Minor cleanups. 2006-11-21 17:35:22 +01:00
Markus F.X.J. Oberhumer a050f82f0e Implemented the remaining missing pieces of compress_zlib. 2006-11-21 17:19:24 +01:00
Markus F.X.J. Oberhumer ef7beea334 Cosmetic cleanups. 2006-11-21 16:17:47 +01:00
Markus F.X.J. Oberhumer 3f4acb33f9 First step for possibly using ElfLinker with linux execve/interp/shell stubs
as well.
2006-11-21 16:00:25 +01:00
Markus F.X.J. Oberhumer 14822e6395 Now that it seems to work, disable usage of pre-compressed stubs again. 2006-11-21 07:14:07 +01:00
Markus F.X.J. Oberhumer e82db4ed38 Use proper const_cast. 2006-11-21 06:32:13 +01:00
Markus F.X.J. Oberhumer 87b7ea9cf3 Add LZMA support for pre-compressed stubs. 2006-11-21 06:09:04 +01:00
Markus F.X.J. Oberhumer 787b1fceff Actually generate and use pre-compressed stubs. Currently this is mainly
for testing as the self-packed upx binary does get _larger_ this way.
2006-11-21 05:29:29 +01:00
Markus F.X.J. Oberhumer 140d6ad839 Avoid compiler warning. 2006-11-21 05:09:01 +01:00
Markus F.X.J. Oberhumer 46e8e22236 Prepare generating pre-compressed stubs. 2006-11-21 05:03:25 +01:00
Markus F.X.J. Oberhumer c386db2b33 Small cosmetic changes. 2006-11-21 05:01:54 +01:00
Markus F.X.J. Oberhumer 8dad091c6b Decompress pre-compressed stubs in Linker::init(). 2006-11-21 05:01:00 +01:00
Markus F.X.J. Oberhumer 3365ccbb9c Implemented upx_zlib_decompress(). 2006-11-21 04:42:47 +01:00
Markus F.X.J. Oberhumer 2ced230965 Updated packers to use new stub names. 2006-11-21 03:40:11 +01:00
Markus F.X.J. Oberhumer 989d10a3e1 Rebuilt all stubs with new bin2h.py and --ident=auto-stub. 2006-11-21 03:36:48 +01:00
Markus F.X.J. Oberhumer 62d8c69774 Enhanced bin2h.py: added --ident=auto, added --compress=XXX. 2006-11-21 03:34:08 +01:00
Markus F.X.J. Oberhumer cf704257b0 Remove some traces of patch_le32. 2006-11-20 18:19:37 +01:00
Markus F.X.J. Oberhumer a6cb6f57d3 Introduce Packer::relocateLoader(). This is the first step of finally getting
rid of all Packer::patchXXX() methods.
2006-11-20 18:10:23 +01:00
Markus F.X.J. Oberhumer 141c703ed5 Use ld option --no-warn-mismatch when generating binary output. 2006-11-20 17:36:04 +01:00
John Reiser 796d58867b use separate stub/armeb-linux.elf-entry and fold 2006-11-20 08:02:28 -08:00
Markus F.X.J. Oberhumer 2f483ec8e8 Fix compression ratio check. 2006-11-20 13:48:34 +01:00
Markus F.X.J. Oberhumer e338918773 Disable new/delete for bele policies. 2006-11-20 12:57:49 +01:00
Markus F.X.J. Oberhumer d9effc58cf Added initial version of armeb-linux.elf stubs. Completely untested. 2006-11-20 12:40:57 +01:00
Markus F.X.J. Oberhumer 05d03f97fc Introduce Packer::bele. 2006-11-20 12:01:59 +01:00
Markus F.X.J. Oberhumer 03e891c0e8 Remove implicit magic from OptVar copy operator and introduce oassign()
function instead.
2006-11-20 11:04:31 +01:00
Markus F.X.J. Oberhumer 4dfe9d52e9 Don't be too strict when checking the compression ratio (sf.net
feature request #1596111).
2006-11-20 09:40:46 +01:00
John Reiser 9e65692b69 Merge 2006-11-19 14:32:28 -08:00
John Reiser 0687c9a57a PackLinuxElf32::ARM_buildLoader endianness bugs 2006-11-19 14:28:15 -08:00
Markus F.X.J. Oberhumer ffe1287016 Added option '--cpr-lzma-ds=XX'. 2006-11-19 18:50:35 +01:00
Markus F.X.J. Oberhumer 75b7e7260f Merge. 2006-11-19 05:16:12 +01:00
Markus F.X.J. Oberhumer d631e081bc arm-linux.elf: make two symbols global. 2006-11-19 05:09:01 +01:00
John Reiser db5843d904 branch merge 2006-11-18 19:57:56 -08:00
John Reiser 5ec16153f7 PackLinuxElf64amd::defineSymbols forgot a get_native64() 2006-11-18 19:52:55 -08:00
Markus F.X.J. Oberhumer 8c873ccdc8 watcom/le: initialize memory when aligning. 2006-11-18 21:59:59 +01:00
Markus F.X.J. Oberhumer c95088f8d5 Merge. 2006-11-18 20:55:07 +01:00
Markus F.X.J. Oberhumer 519fa55df7 ps1/exe: fill pad.code section with zeros. 2006-11-18 20:54:10 +01:00
John Reiser b8dda033ed branch merge 2006-11-18 11:51:23 -08:00
John Reiser 0359e9c5c7 members of struct l_info loader header must be little endian 2006-11-18 11:42:08 -08:00
Markus F.X.J. Oberhumer d822b4a62a Store shentsize in target byte-order. 2006-11-18 18:25:11 +01:00
Markus F.X.J. Oberhumer d9e8c953b1 Fixed some ElfLinker endian issues. 2006-11-18 17:43:29 +01:00
Markus F.X.J. Oberhumer 9eca502026 Make upx build with gcc-2.95 again. 2006-11-18 14:37:22 +01:00
Markus F.X.J. Oberhumer cd0efe3edb Some atari/tos cleanups. 2006-11-18 02:39:11 +01:00
Markus F.X.J. Oberhumer 8146e9cbcd Implemented some small atari/tos optimizations. 2006-11-17 18:47:33 +01:00
Markus F.X.J. Oberhumer 5d95275024 Add some more calls to f-objstrip. 2006-11-17 14:50:59 +01:00
Markus F.X.J. Oberhumer 49a97eea4b More brandelf.py updates. 2006-11-17 14:50:42 +01:00
Markus F.X.J. Oberhumer 36e9c27e9c Updated brandelf.py. 2006-11-16 22:23:01 +01:00
Markus F.X.J. Oberhumer 6e5153cd07 Minor Makefile updates. 2006-11-16 21:14:58 +01:00
Markus F.X.J. Oberhumer c73da864c8 Avoid -Wshadow warnings. 2006-11-16 20:14:14 +01:00
Markus F.X.J. Oberhumer 071bb75700 Use new addLoader() method. 2006-11-16 20:12:53 +01:00
Markus F.X.J. Oberhumer 99374de340 Clean up stub sources. 2006-11-16 19:36:13 +01:00
Markus F.X.J. Oberhumer db7ae4ed5d Improve Packer:addLoader(). We're still somewhat limited because of gcc-bug
#29823 (see http://gcc.gnu.org/PR29823).
2006-11-16 18:52:20 +01:00
Markus F.X.J. Oberhumer e61f481881 Added .DELETE_ON_ERROR rules. 2006-11-16 18:49:34 +01:00
Markus F.X.J. Oberhumer 396a3ad2fc Small atari cleanups. 2006-11-13 10:51:45 +01:00
Markus F.X.J. Oberhumer be235ddc38 Removed unused Packer::freezeLoader(). Changed return type of
buildLoader() from "int" to "void".
2006-11-12 20:57:08 +01:00
Markus F.X.J. Oberhumer 9e72ecd93d Fix version date. 2006-11-12 18:49:48 +01:00
Markus F.X.J. Oberhumer 8e0bd936eb atari/tos now seems to work again. 2006-11-12 18:25:46 +01:00
Markus F.X.J. Oberhumer 9d0270dcd6 We have to bswap32 lzma_properties on big-endian machines. 2006-11-12 18:10:42 +01:00
Markus F.X.J. Oberhumer 713415c354 Fix broken "glibc sscanf bug workaround". 2006-11-12 14:47:50 +01:00
Markus F.X.J. Oberhumer 786550572e More work on atari/tos. 2006-11-12 13:46:38 +01:00
Markus F.X.J. Oberhumer 46caeddc81 Added some more debugging support to Linker. 2006-11-12 13:45:27 +01:00
Markus F.X.J. Oberhumer 71bfde2bfe Bump tentative release date. 2006-11-12 10:59:27 +01:00
Markus F.X.J. Oberhumer 76771b845a Started work on atari/tos. 2006-11-12 10:58:04 +01:00
Markus F.X.J. Oberhumer a74e239e28 Major cleanup of ElfLinker. 2006-11-12 10:57:18 +01:00
Markus F.X.J. Oberhumer 6e763b0b42 Updated options. 2006-11-12 10:56:17 +01:00
Markus F.X.J. Oberhumer 2f41ece017 Minor cleanups. 2006-11-10 13:49:22 +01:00
Markus F.X.J. Oberhumer 01cd5fe0d5 Added tag BRANCHPOINT_FOR_upx2.hg . 2006-11-08 21:09:50 +01:00
Markus F.X.J. Oberhumer ed12ff7bb3 Updated NEWS from 2.03 release. 2006-11-07 19:56:15 +01:00
Markus F.X.J. Oberhumer f1386bb60d Update NEWS. 2006-11-07 14:07:43 +01:00
Markus F.X.J. Oberhumer 417bd06e76 Fixed --brute and --lzma for dos/exe. 2006-11-07 13:58:32 +01:00
Markus F.X.J. Oberhumer 91e46e3cf8 Small cleanups. 2006-11-07 13:43:43 +01:00
Markus F.X.J. Oberhumer deb5139c4d Re-enable --crp-ms= option. 2006-11-07 13:37:46 +01:00
Markus F.X.J. Oberhumer 862ac5d014 Update options_t::crp_t to directly use the XXX_compress_config_t types. 2006-11-07 13:11:36 +01:00
Markus F.X.J. Oberhumer 028235d421 Keep variable names sorted. 2006-11-07 10:24:54 +01:00
Markus F.X.J. Oberhumer 143d399849 Updated two "xchg" commands to produce byte-identical results with UPX 2.02. 2006-11-07 09:35:00 +01:00
László Molnár 375f171e47 dos/com&sys: correctly set carry bit by using "sub si,-xx" instead of "add si,xx" 2006-11-06 17:54:37 +01:00
László Molnár 387edcf4b2 dos/com: fix fatal bug #1589758 2006-11-03 15:52:20 +01:00
Markus F.X.J. Oberhumer 011cd37cfb Small cleanup of arm sources. 2006-10-30 14:10:51 +01:00
Markus F.X.J. Oberhumer 0d4254f319 Added tc_objdump_disasm_options. 2006-10-30 13:21:48 +01:00
Markus F.X.J. Oberhumer 4c407c2850 Rebuild all stubs. Minor Makefile cleanup. 2006-10-25 04:08:59 +02:00
John Reiser 829e2d6c5d set e_shentsize to work around bug in binutils [mostly cosmetic] 2006-10-24 09:43:50 -07:00
John Reiser a31c4bd474 more renaming for i386-linux.kernel.vmlinux-head.h 2006-10-24 09:29:01 -07:00
John Reiser 17f24dc377 PackBvmlinuzI386 allow x86_64 2006-10-18 08:35:25 -07:00
John Reiser de3e9f2809 vmlinuz/386 fix for physical_start not at bzimage_offset 2006-10-16 17:18:19 -07:00
John Reiser 4442a282e1 fix filename in #includ 2006-10-16 10:52:57 -07:00
John Reiser 261010f23d fix comment 2006-10-16 06:12:58 -07:00
John Reiser ede44ca6ee vmlinux/386 naming convention for source files 2006-10-16 06:11:49 -07:00
John Reiser 452a953234 vmlinux/386 check for __ksymtab; fix unpack 2006-10-15 14:51:02 -07:00
John Reiser 2b122562ad new file i386-linux.kernel.head-vmlinux.S 2006-10-14 14:55:10 -07:00
John Reiser 6891bc3da3 vmlinux/i386: fix filters, 0x400000 start, integration with kernel build 2006-10-14 14:52:30 -07:00
Markus F.X.J. Oberhumer b31b8cd7f0 Added option '--crp-lzma-fb='. Started tuning lzma compression
levels '-1' and '-2'.
2006-10-12 14:23:22 +02:00
Markus F.X.J. Oberhumer e1379ac5ce Removed debugging leftover. 2006-10-12 13:48:07 +02:00
Markus F.X.J. Oberhumer 0ef3f75d7a Introduced class OptVar for tracking optionally set options. Also
added three new options for finetuning lzma compression.
2006-10-12 13:47:15 +02:00
Markus F.X.J. Oberhumer 407a9e5be0 Clean up NEWS. 2006-10-11 13:47:12 +02:00
Markus F.X.J. Oberhumer 892bb9bf30 Re-add "beta" string to versions. 2006-10-11 13:06:17 +02:00
Markus F.X.J. Oberhumer 47ac871a12 Added version_string() functions for the compression algorithms. Also
reserved M_DEFLATE and added a mostly empty compress_zlib.cpp.
2006-10-11 12:56:28 +02:00
László Molnár a38c3e7f6d ps1: initialize an uninitialized variable 2006-10-10 15:44:02 +02:00
Markus F.X.J. Oberhumer 08818355d1 Updated README.SRC. 2006-10-10 11:23:32 +02:00
Markus F.X.J. Oberhumer 0a68afef00 Bump version for next release. 2006-10-08 22:38:57 +02:00
Markus F.X.J. Oberhumer 2c0783e327 Added tag for RELEASE_290. 2006-10-08 22:35:47 +02:00
Markus F.X.J. Oberhumer c2e5e45c84 Fix UINT64_MAX. 2006-10-06 08:42:12 +02:00
John Reiser 014236c861 amd64 stub: fix length of move for non-small programs 2006-10-04 08:38:06 -07:00
Markus F.X.J. Oberhumer 610fd7561b Bump tentative release date. Update NEWS. 2006-10-04 09:26:34 +02:00
Markus F.X.J. Oberhumer d6f4480a4f Removed debugging leftover. 2006-10-04 09:17:59 +02:00
Markus F.X.J. Oberhumer 28a6ac09ad Initialize a field in constructor. 2006-10-04 09:14:13 +02:00
John Reiser 86e4d24476 avoid circularity of sz_pack2 in PackLinuxElf64amd::defineSymbols() 2006-10-03 20:21:36 -07:00
John Reiser 913a697ab2 Remove dead code and uses of sz_pack2 from PackLinuxElf32::ARM_defineSymbols() 2006-10-03 19:28:08 -07:00
Markus F.X.J. Oberhumer ebef2b1e44 Avoid a printf warning. 2006-10-04 00:16:55 +02:00
Markus F.X.J. Oberhumer a61457b422 Added some debugging support via Linker::dumpSymbols(). 2006-10-03 23:48:19 +02:00
László Molnár 8f7f1135df win32/pe: size of tls_value should be 32 bits 2006-10-03 17:01:47 +02:00
John Reiser 89612c10c9 NEWS and document /proc/self/exe 2006-10-03 07:20:59 -07:00
John Reiser d55bfb32f1 merge 2006-10-03 07:01:55 -07:00
John Reiser d2b72cf496 sync 2006-10-03 06:59:10 -07:00
László Molnár 8d90fffd46 NEWS updates for 2.90 2006-10-03 15:56:39 +02:00
John Reiser b84af27a86 typo "pop %eax" [not caught by assembler?] 2006-10-01 16:19:17 -07:00
John Reiser b45f28f3e9 propagate changes from *.S to *.h 2006-10-01 14:42:39 -07:00
John Reiser bfa1b5656a preserve readlink("/proc/self/exe",,) in environment " =" 2006-10-01 14:41:09 -07:00
John Reiser 47f946cd65 fix the comments 2006-10-01 14:25:14 -07:00
John Reiser 970e7bfcda CPU_TYPE_I386 2006-10-01 14:24:20 -07:00
John Reiser a81c7a7cd6 PackBSDI386 clarify osabi issues. 2006-09-27 14:38:42 -07:00
John Reiser b0e1bd239f Pack shell scripts for Linux only (and not *BSD, for example [no stub!]) 2006-09-26 16:21:28 -07:00
John Reiser 53ca41717a Document /proc/self/exe and workaround. 2006-09-25 13:02:07 -07:00
Markus F.X.J. Oberhumer 6a5bee0cdd Updated test-stub-compression. 2006-09-09 13:03:04 +02:00
Markus F.X.J. Oberhumer fd3ae51f83 Remove trailing whitespace. 2006-09-09 11:00:33 +02:00
Markus F.X.J. Oberhumer 5e5954a808 Use gcc-4.1.1 again for mipsel. 2006-09-09 10:57:13 +02:00
John Reiser add8540909 Integrate upx-2.90beta1-ps1-20060908.bz2 from Jens. 2006-09-08 14:09:30 -07:00
John Reiser 06a302aed0 Integrate upx-2.90beta1-ps1-20060907 from Jens. 2006-09-07 10:44:19 -07:00
John Reiser 147432d38d list fastest possible inline expansion (saves 3 cycles) 2006-09-06 11:19:18 -07:00
John Reiser 2a003ff72b merge 2006-09-06 10:55:37 -07:00
John Reiser 8660d3324d "revert -r eae1090d512738ac64c783be70258ababc8b6513" to sync with Markus 2006-09-06 10:52:06 -07:00
John Reiser 6c59b73ae5 PackLinuxElf64::generateElfHdr() .p_flags are only 32 bits 2006-09-06 10:36:50 -07:00
Markus F.X.J. Oberhumer 80218c1eca Atari/tos is currently broken, so throw an InternalError. 2006-09-06 14:31:30 +02:00
John Reiser f24d96d59f document alternate getbit 2006-09-04 20:09:03 -07:00
Markus F.X.J. Oberhumer d14bd49f46 Updated mips Makefile. 2006-09-04 14:23:21 +02:00
Markus F.X.J. Oberhumer 1a692a0873 Tuned mips compiler flags. 2006-09-03 19:14:49 +02:00
Markus F.X.J. Oberhumer 631a1a4ddc Cosmetic changes. 2006-09-03 19:13:35 +02:00
Markus F.X.J. Oberhumer 57df7601d9 mipsel: use -mtune=r4000 and -fno-sched-spec for small size reduction. 2006-09-02 14:53:31 +02:00
Markus F.X.J. Oberhumer f7650000aa Enable -fwrapv for mipsel. 2006-09-02 14:16:46 +02:00
Markus F.X.J. Oberhumer 6f93c2d9b2 Updated Makefiles. 2006-09-02 14:14:15 +02:00
Markus F.X.J. Oberhumer 1654764968 Disable lua for now. 2006-09-01 02:38:35 +02:00
Markus F.X.J. Oberhumer 1a1b8416e2 Use f-embed_objinfo for arm-linux. 2006-09-01 02:36:24 +02:00
Markus F.X.J. Oberhumer 36c66d52a6 Added SQUEEZE macro to better canonicalize the dumps. 2006-09-01 02:09:16 +02:00
Markus F.X.J. Oberhumer 68fe43d488 Strip trailing whitespace. 2006-09-01 01:35:51 +02:00
Markus F.X.J. Oberhumer 877b9ee23b Stub: provide debugging disassembly for arm. 2006-09-01 01:34:20 +02:00
Markus F.X.J. Oberhumer 80ff93beeb Explicitly strip section .note.GNU-stack from objects. 2006-08-30 20:15:07 +02:00
Markus F.X.J. Oberhumer b9ddd2812b Create disassembly for i386-dos32.djgpp2-stubify.h. 2006-08-30 19:38:39 +02:00
László Molnár ba54b56de4 another update for ps1/exe from Jens 2006-08-30 12:42:49 +02:00
Markus F.X.J. Oberhumer 85be67bc2d Removed some temporary tags. Info: you can use the file .hg/localtags
to define per-repository local tags which are not shared.
2006-08-30 00:21:13 +02:00
Markus F.X.J. Oberhumer ae20e01d2c Started renaming some loader symbols - now that we have a real
linker we really should improve readability and avoid those
old cryptic names.
2006-08-30 00:11:40 +02:00
Markus F.X.J. Oberhumer d094e8c3fc Added stub/tmp/*.dump files to the Mercurial repository.
These .dump files are embedded in the .h stubs anyway, but we
really want to see some diffs to better understand what has
changed in a commit.
2006-08-30 00:06:47 +02:00
Markus F.X.J. Oberhumer f009fe1f63 Start work on updating p_tos. 2006-08-29 23:46:21 +02:00
Markus F.X.J. Oberhumer 2007fe5f49 More small Makefile changes. 2006-08-29 23:08:26 +02:00
László Molnár 84989ffa04 merge 2006-08-29 17:11:03 +02:00
László Molnár 31b629a19c ps1/exe updated from jens 2006-08-29 16:25:59 +02:00
Markus F.X.J. Oberhumer e762d9e274 Yet another minor Makfile update. 2006-08-29 16:05:17 +02:00
Markus F.X.J. Oberhumer 6833267b19 Cleanups in stub Makefiles. 2006-08-29 14:37:06 +02:00
Markus F.X.J. Oberhumer 05f2833388 Detabified. 2006-08-29 13:43:06 +02:00
Markus F.X.J. Oberhumer 0d026ef18d Removed trailing whitespace. 2006-08-29 13:41:13 +02:00
Markus F.X.J. Oberhumer b756d93891 Use absolute symbols to store offsets in m68k stub. 2006-08-28 09:48:01 +02:00
Markus F.X.J. Oberhumer f54513586d Implemented alignCode() for m68k. 2006-08-28 09:09:29 +02:00
Markus F.X.J. Oberhumer 6c519c237e Renamed Linker::align() to alignCode(). We still have to add
some way to express alignData().
2006-08-28 08:58:43 +02:00
John Reiser 4ffde4db98 8-byte align LZMA_DEC20 2006-08-27 10:03:12 -07:00
Markus F.X.J. Oberhumer 41847d31e7 More m68k rearrangments. 2006-08-26 13:25:37 +02:00
Markus F.X.J. Oberhumer 24ce25bb5c Updated READMEs. 2006-08-26 13:25:04 +02:00
Markus F.X.J. Oberhumer e051b69e80 Use -fwrapv for m68k stubs. 2006-08-26 12:57:21 +02:00
Markus F.X.J. Oberhumer 59283d1164 More work on m68k. 2006-08-24 20:48:09 +02:00
Markus F.X.J. Oberhumer 0de32a5edc Small Makefile cleanup. 2006-08-24 14:07:53 +02:00
Markus F.X.J. Oberhumer 4f80066dcb New ACC version. 2006-08-24 12:39:45 +02:00
Markus F.X.J. Oberhumer 04ddc8003f Started work on m68k. 2006-08-24 03:56:11 +02:00
Markus F.X.J. Oberhumer 3213f98d66 Added recursive targes extra-all and extra-clean. 2006-08-24 01:34:57 +02:00
Markus F.X.J. Oberhumer 1f16f85c51 Reorganized Makefile.extra. 2006-08-24 01:34:24 +02:00
Markus F.X.J. Oberhumer c03cb3a11c All stubs now depend on Makefile and thus will get rebuilt more often. 2006-08-24 01:34:06 +02:00
László Molnár 62e29a6546 let us see the relocation info in the disassembled stubs 2006-08-23 14:43:37 +02:00
László Molnár 3574b065d6 fixed prototype of ElfLinkerMipsLE::relocate1 2006-08-23 14:35:28 +02:00
Markus F.X.J. Oberhumer c0c47f41be Added initial lzma support for m68k. 2006-08-23 13:58:16 +02:00
Markus F.X.J. Oberhumer 37761d580f Updated for bin-upx-20060823. 2006-08-23 13:11:01 +02:00
Markus F.X.J. Oberhumer e075c8e691 Updated unused code. 2006-08-23 11:30:42 +02:00
Markus F.X.J. Oberhumer 0c61ca1a6b Renamed addLinkerSymbols() to defineSymbols(). 2006-08-23 11:20:06 +02:00
John Reiser 1846fa1f54 PackLinuxElf start loader at 0 mod 8 2006-08-22 21:22:49 -07:00
John Reiser 579ce20cad remove patchFilter32() 2006-08-22 20:49:28 -07:00
John Reiser 12e4bcba5d Elf64 sets .p_flags for 0-length .bss 2006-08-22 11:23:55 -07:00
László Molnár b4f57dee3b arm.v4t-wince.pe: minor cleanups 2006-08-22 14:16:46 +02:00
Markus F.X.J. Oberhumer f11673ae3f Removed Packer::patchDecompressor(). 2006-08-22 11:05:18 +02:00
Markus F.X.J. Oberhumer a27af7dd7e Small update. 2006-08-22 11:02:54 +02:00
Markus F.X.J. Oberhumer 2b26a3cc14 Updated .hgignore. 2006-08-22 10:59:16 +02:00
Markus F.X.J. Oberhumer 47c4849694 Added support for debug.dump_stub_loader. 2006-08-22 10:48:04 +02:00
John Reiser 30a4adf331 Reduce usage of patchDecompressor() 2006-08-21 21:19:48 -07:00
John Reiser 117a721166 ElfLinker::addSection ==> addLoader 2006-08-21 19:52:09 -07:00
John Reiser 1a219e62ba Bvmlinuz: linker->defineSymbol() instead of patchDecompressor() 2006-08-21 14:26:42 -07:00
John Reiser c8d54b324b Only PC-relative relocations get range checked. 2006-08-21 14:26:08 -07:00
John Reiser 0ac2971fc1 add UPX_F_BSD_ELF_i386 to the exceptions for patchDecompressor() 2006-08-21 12:09:46 -07:00
Markus F.X.J. Oberhumer 348a40201b Introduce $(tc_bfdarch) and generate disassemblies to verify code quality. 2006-08-21 20:55:37 +02:00
Markus F.X.J. Oberhumer 9f20ddc800 Removed Packer::patchVersion() and Packer::patchVersionYear(). 2006-08-21 20:28:14 +02:00
Markus F.X.J. Oberhumer 6f1cc2c1e5 Renamed ElfLinker::addSection(sname) to addLoader(). 2006-08-21 20:07:42 +02:00
Markus F.X.J. Oberhumer 601cd95277 Removed Packer::getIdentstr(). 2006-08-21 19:57:43 +02:00
Markus F.X.J. Oberhumer 8e9ce59ef2 Minor Makefile cleanups. 2006-08-21 16:40:20 +02:00
László Molnár d76ef8e3cf arm/pe: use embed_objinfo in the Makefile
made some symbols globals in arm.v4a-wince.pe.S & arm.v4t-wince.pe.S
2006-08-21 15:20:20 +02:00
John Reiser c19ffafd8d i386-linux.elf decompress does not need cto8 2006-08-20 11:19:37 -07:00
Markus F.X.J. Oberhumer 996a99ad75 Some linker.cpp cleanups. 2006-08-20 11:15:36 +02:00
Markus F.X.J. Oberhumer affb926d44 Whitespace cleanups. 2006-08-20 11:08:38 +02:00
John Reiser c506e534aa propagate to .h in stub/ 2006-08-19 18:41:45 -07:00
John Reiser 9994315070 un-debug 2006-08-19 18:40:49 -07:00
John Reiser 4f0d89ef8b convert PackMachPPC32 to new Linker 2006-08-19 15:28:16 -07:00
Markus F.X.J. Oberhumer aab984618d Fix newLinker() for mach/ppc32. 2006-08-19 14:29:40 +02:00
Markus F.X.J. Oberhumer 8b662bc6b5 Removed trailing whitespace. 2006-08-19 14:01:39 +02:00
Markus F.X.J. Oberhumer 03ce7a8db3 Removed all old linker classes - we exclusively use ElfLinker now. 2006-08-19 14:00:22 +02:00
Markus F.X.J. Oberhumer 033e7928b5 Minor Makefile updates. 2006-08-19 13:05:16 +02:00
Markus F.X.J. Oberhumer b095f2a158 Strip trailing whitespace from objdump info. 2006-08-18 13:22:38 +02:00
Markus F.X.J. Oberhumer 196c0e0ebc Added embed_objinfo macro. 2006-08-18 13:18:10 +02:00
Markus F.X.J. Oberhumer 8ab309630b Keep old alloca() code around. 2006-08-18 12:26:41 +02:00
Markus F.X.J. Oberhumer 42bac47a71 Improve automatic dependency information by using '-MT'. 2006-08-18 12:26:06 +02:00
Markus F.X.J. Oberhumer 3bc4de2236 Added missing stubs to hg repo. 2006-08-18 12:25:34 +02:00
John Reiser a6e4b45a38 --force-execve for *BSD/386 2006-08-17 17:35:33 -07:00
John Reiser 28e97ccaf2 avoid symbol 'byte' 2006-08-17 17:18:37 -07:00
Markus F.X.J. Oberhumer 255781c029 Minor cleanups. 2006-08-17 13:09:51 +02:00
John Reiser 7f5635ea8c Section LZMA_ELF00 saves time (but no space) by not clearing CProb[]. 2006-08-16 19:49:09 -07:00
Markus F.X.J. Oberhumer 4f18ec726c Rebuilt with bin-upx-20060816 (untested mipsel changes). 2006-08-16 19:40:33 +02:00
Markus F.X.J. Oberhumer 263622d628 Updated for bin-upx-20060816. 2006-08-16 19:37:25 +02:00
László Molnár 1dfd2443ac name of file comments fixed 2006-08-16 15:29:11 +02:00
Markus F.X.J. Oberhumer 881bd53f60 Small Makefile cleanups. 2006-08-16 09:50:00 +02:00
Markus F.X.J. Oberhumer ec4404b1ba We have to use "dword ptr" instead of "dword" ! 2006-08-16 09:38:49 +02:00
Markus F.X.J. Oberhumer badaeac81f Use "jmps" macro instead of #define. 2006-08-16 09:34:27 +02:00
Markus F.X.J. Oberhumer 618d5ddaff More renaming. 2006-08-16 09:24:31 +02:00
Markus F.X.J. Oberhumer 4ed74af868 More renaming. 2006-08-16 09:07:00 +02:00
Markus F.X.J. Oberhumer 123d9af7d0 More renaming in arch/i386. 2006-08-16 08:39:58 +02:00
Markus F.X.J. Oberhumer 4f17b30915 Started renaming .asm files to .S. 2006-08-16 08:13:36 +02:00
Markus F.X.J. Oberhumer 1fc265b0aa Use symbolic stride again. 2006-08-16 07:59:21 +02:00
John Reiser afae9b8d17 merge 2006-08-15 14:01:53 -07:00
John Reiser 481be44879 Work around assembler bug: double-indexing by symbolic stride fails. 2006-08-15 14:00:35 -07:00
Markus F.X.J. Oberhumer b8530b0f0b Whitespace cleanups. 2006-08-15 22:48:04 +02:00
Markus F.X.J. Oberhumer 69de79684f Removed some unused files. 2006-08-15 22:41:05 +02:00
Markus F.X.J. Oberhumer 6e6fd057b5 Cleaned up stub/Makefile. 2006-08-15 22:38:40 +02:00
John Reiser 4b0ebf2b80 merge 2006-08-15 12:11:36 -07:00
John Reiser ee82c32119 'dword' is a symbol to libexec/gcc/i686-unknown-linux-gnu/3.4.6/cc1 2006-08-15 12:10:54 -07:00
Markus F.X.J. Oberhumer 3fe6731035 Disable WITH_LUA for now. 2006-08-15 19:23:03 +02:00
Markus F.X.J. Oberhumer 1c3f3b5705 Removed last dependency on nasm assembler. 2006-08-15 18:50:41 +02:00
Markus F.X.J. Oberhumer def1ccffc4 Rebuilt with bin-upx-20060815. 2006-08-15 18:39:05 +02:00
Markus F.X.J. Oberhumer fa2e531343 Updated for bin-upx-20060815. 2006-08-15 18:38:38 +02:00
Markus F.X.J. Oberhumer 814ddbc6cc Remove duplicate inclusion. 2006-08-15 17:20:23 +02:00
John Reiser 267e8dcfb6 Omit double include of macros2.ash. 2006-08-15 07:22:52 -07:00
John Reiser 49ec1561f8 merge 2006-08-15 07:11:06 -07:00
John Reiser e2dc612153 Add cl1_d32_2.ash. 2006-08-15 07:08:50 -07:00
Markus F.X.J. Oberhumer 8f225431fe Minor updates to Makefile and stubs. 2006-08-15 10:23:45 +02:00
Markus F.X.J. Oberhumer 194be5e0b7 Moved o2bin.pl to UNUSED. 2006-08-15 09:21:39 +02:00
John Reiser 6788a05dd1 convert powerpc-darwin.macho-entry.h to new linker 2006-08-14 21:20:30 -07:00
John Reiser 6a7066ac2f Avoid linker->setLoaderAlignOffset(). 2006-08-14 19:21:15 -07:00
John Reiser ec5ff4e973 merge 2006-08-14 13:06:53 -07:00
John Reiser fe6d460531 rebuild: arm-unknown-linux-gnu-gcc-4.1.0, i386-linux-gcc-3.4.6;
powerpc/32/ppc_regs.h
2006-08-14 12:30:33 -07:00
John Reiser 9cb97af10f begin conversion to new linker 2006-08-14 12:10:34 -07:00
John Reiser 1c784eea3d typo for i386-bsd.elf-main.o 2006-08-14 12:09:42 -07:00
László Molnár 59dd33a461 ps1/exe updates from Jens 2006-08-14 17:15:26 +02:00
László Molnár 97ebd912dc rebuilt arm.v4t-wince.pe.h 2006-08-14 14:26:40 +02:00
Markus F.X.J. Oberhumer 742fcc060c Update NEWS. 2006-08-14 08:46:55 +02:00
Markus F.X.J. Oberhumer 3ad5cb8a23 Merge. 2006-08-14 08:44:58 +02:00
John Reiser 0d1f12e31a Use better name osabi_note. 2006-08-13 20:14:14 -07:00
John Reiser a8ddf8f66d Detect PT_NOTE for NetBSD, OpenBSD. 2006-08-13 20:00:44 -07:00
John Reiser f7a9c0a248 Mention lzma, *BSD, linux workaround [needs clarification.] 2006-08-13 12:44:40 -07:00
John Reiser 190badb395 arm-unknown-linux-gnu-gcc-4.1.0 2006-08-13 12:32:42 -07:00
Markus F.X.J. Oberhumer 3d91ab6c31 Introduced bele_policy.h. 2006-08-13 15:30:26 +02:00
Markus F.X.J. Oberhumer c15b8d71bc Removed trailing whitespace. 2006-08-13 14:47:24 +02:00
John Reiser 5a707dba8a fix NRV_TAIL, ELFMAINY 2006-08-11 20:45:43 -07:00
John Reiser ffd2fcde6b sections NRV_HEAD, NRV_TAIL replace NRV_COMMON 2006-08-11 20:29:51 -07:00
László Molnár 8e4056c1e4 vmlinuz/386: fixed zlib uncompression problem on dos 2006-08-11 17:59:12 +02:00
László Molnár 1554e2b135 lzma support for ps1 from Jens 2006-08-11 11:18:01 +02:00
John Reiser 4715cbb70d PackLinuxI386::newLinker() is a new ElfLinkerX86;
re-generate i386-linux.elf.execve-entry.h after lzma_d_cs.S
2006-08-10 18:48:32 -07:00
John Reiser fd1611079a auto-define symbol *ABS* in section *ABS*
(for i386-linux.elf.execve-entry.h  R_386_PC  *ABS*)
2006-08-10 17:02:36 -07:00
John Reiser 8edc03df64 PackLinuxI386::newLinker(); also use arm-unknown-linux-gnu-gcc-4.1.0
to re-compile stub/src/arch/arm/v4t/lzma_d_cf.S, lzma_d_cs.S .
2006-08-10 16:52:20 -07:00
László Molnár 9f5c0af5b8 step 0 of refactoring arm/pe & win32/pe ready 2006-07-26 14:00:36 +02:00
László Molnár 6d6eeba5d5 refactoring of arm/pe and win32/pe started 2006-07-25 18:30:12 +02:00
László Molnár 5dfb64ef71 arm.v4a-wince.pe.h rebuilt 2006-07-25 12:31:45 +02:00
John Reiser e5bda7add7 save 28 bytes (> 10%) in arch/arm/v4a/nrv2b_d8.S 2006-07-24 14:48:06 -07:00
John Reiser 77f9b336bd ARM lzma_d_cf.S use .Lf labels to save space in arm-linux.elf-entry.h 2006-07-24 06:26:04 -07:00
László Molnár cf930d0dde merge 2006-07-24 11:06:06 +02:00
László Molnár f01c94e8bc arm/pe: nrv2b support for v4a mode 2006-07-23 21:50:51 +02:00
László Molnár 0d774527b4 merge. arm/pe lzma updates 2006-07-23 21:08:27 +02:00
John Reiser 58ba9496d0 arm-linux lzma_d.c omit -fPIC enables using r10 2006-07-23 09:13:47 -07:00
John Reiser 1993e94e53 ARM lzma bug in cacheflush 2006-07-23 07:19:35 -07:00
László Molnár 3bcc06ed09 arm/pe: lzma works for v4t too
minor changes in v4a code
2006-07-23 16:13:10 +02:00
John Reiser 2f6ce88e28 ARM Linux lzma work 2006-07-22 20:53:15 -07:00
John Reiser cd1dec9fc7 PackLinuxElf32arm lzma cache flush; 5th arg to f_decompress is on stack 2006-07-22 11:39:29 -07:00
John Reiser 05872d7650 arm-linux nrv2b works: conditon code bug, cache flush, cache lookahead 2006-07-22 08:48:04 -07:00
László Molnár 1dcee2ffa2 lzma for arm/pe v4a works 2006-07-22 17:30:09 +02:00
John Reiser 5f622efb77 nrv2e PackLinuxElf32armLe works 2006-07-21 19:10:48 -07:00
John Reiser 52e8326d54 work on PackLinuxElf32arm; add nrv2b_d8.S 2006-07-21 13:11:02 -07:00
László Molnár 436532bed7 arm/pe: lzma support for v4a (untested) 2006-07-21 15:08:29 +02:00
László Molnár d15e789200 nrv2d support for arm/pe v4a mode 2006-07-20 18:11:14 +02:00
John Reiser 98942f5528 work on PackLinuxElf32arm, including nrv2d and lzma 2006-07-19 17:29:17 -07:00
László Molnár c7c21dc122 rebuilt some i386 stubs 2006-07-18 13:45:22 +02:00
László Molnár 4500c1d1a4 lzma should be working again for most of the i386 formats 2006-07-18 13:44:44 +02:00
John Reiser b8b983dded nrv2d decompressor for PackLinuxElf64amd 2006-07-17 15:02:37 -07:00
John Reiser d6a6673971 nrv2d decompressor for PackLinuxElf32ppc 2006-07-17 13:23:49 -07:00
László Molnár 0580fe8db8 merge 2006-07-17 17:39:45 +02:00
László Molnár c727e24138 win32/pe works with lzma again 2006-07-17 17:38:44 +02:00
László Molnár b83698ebf5 Packer::defineDecompressorSymbols added 2006-07-17 17:34:03 +02:00
László Molnár 3fbbaa5130 really fixed i386 lzma stub 2006-07-17 17:33:03 +02:00
John Reiser 2f48b840ae merge 2006-07-17 08:06:06 -07:00
John Reiser efdee11d5a lzma PackLinuxElf32ppc works! 2006-07-17 08:05:31 -07:00
László Molnár 4c87e11aeb 8 bit relocation overflow detection added to ElfLinker 2006-07-17 16:58:24 +02:00
László Molnár e881e008b8 fixes for the i386 nrv2b & nrv2d stubs 2006-07-17 16:56:17 +02:00
László Molnár 1b2837915d small conversion related fix to the lzma stub 2006-07-17 16:54:41 +02:00
László Molnár d076a6724f merge 2006-07-17 12:13:08 +02:00
John Reiser 386af71c39 add lzma_d.S for PackLinuxElf32ppc 2006-07-16 22:35:35 -07:00
John Reiser 49f277192c hacking lzma PackLinuxElf32ppc 2006-07-16 22:32:55 -07:00
John Reiser 5974a6276b undebug powerpc-linux.elf-entry.S 2006-07-16 19:06:04 -07:00
John Reiser e06a390771 PackLinuxElf32ppc works (except lzma) 2006-07-16 19:01:17 -07:00
John Reiser b34e204676 PackLinuxElf32ppc conversion; alignment in *::Section 2006-07-16 15:04:16 -07:00
John Reiser 755d990dfd unify buildLinuxLoader using addStubEntrySections and addLinkerSymbols 2006-07-16 09:48:22 -07:00
John Reiser 7185358b98 lzma PackLinuxElf64amd works! 2006-07-15 20:05:41 -07:00
John Reiser 3843ec1e02 lzma for PackLinuxElf64amd 2006-07-15 16:01:53 -07:00
John Reiser cfc5631d5d PackLinuxElf64amd works (except for lzma) 2006-07-15 13:46:37 -07:00
John Reiser e64555aca0 hacking PackLinuxElf64amd 2006-07-14 19:43:38 -07:00
John Reiser ef52ebb529 workaround i386 assembler misfeature 2006-07-14 06:33:40 -07:00
John Reiser c98136ca4f fix error in assembler conversion 2006-07-13 21:10:42 -07:00
László Molnár 65f44d24ca miniacc support for arm-wince-pe 2006-07-13 16:50:26 +02:00
John Reiser 44f20782fd cleanup after merge; AMD64 ElfLinker 2006-07-12 11:42:03 -07:00
John Reiser 9b1d76a5d0 Added tag main-2006-07-12 for changeset 72fe9925b247073cd8342d8bff07adc47b72173f 2006-07-12 11:26:15 -07:00
John Reiser 21b5074ce8 Added tag jfr-2006-07-12 for changeset 8afead5e7182950592970330c218913fecfbe390 2006-07-12 11:24:52 -07:00
John Reiser 0b8825fecb i386 conversion stub conversion; nrv2b_d32_2.ash etc. 2006-07-12 11:15:14 -07:00
László Molnár 3d3c20e507 ElfLinker improvements
Sections/symbols/relocations are allocated dynamically
Sections use an internal copy of their input data
2006-07-11 14:40:58 +02:00
László Molnár 67a282f19f class nocopy introduced 2006-07-11 13:58:13 +02:00
John Reiser 92023b533a merge 2006-07-10 13:26:39 -07:00
John Reiser c1d14c150e How to debug i386-linux.kernel.vmlinu[xz] under qemu 2006-07-10 13:25:39 -07:00
László Molnár aa656c74d5 merge 2006-07-10 13:30:04 +02:00
László Molnár e39b7ffe30 ps1/exe updates from Jens Medoch 2006-07-10 13:28:27 +02:00
John Reiser 1897148abc convert i386-bsd.elf-entry.asm 2006-07-09 20:07:37 -07:00
John Reiser b76118802a ElfLinkerPpc32 2006-07-09 19:52:23 -07:00
John Reiser 8266aa3343 i386/nrv2d_d32_2.ash 2006-07-09 19:15:03 -07:00
John Reiser ab0c349261 workaround ElfLinker not handling addSection(,,) from dynamic block 2006-07-09 17:29:22 -07:00
John Reiser d5e0e66426 PackLinuxElf32x86::newLinker() 2006-07-09 16:59:41 -07:00
John Reiser c5b3107f83 start converting PackLinuxElf32x86 to ElfLinker 2006-07-09 10:17:52 -07:00
John Reiser 1a0a64e4de ::addStubEntrySections() with default ELFMAINX 2006-07-09 08:48:06 -07:00
John Reiser 6bd9805bcc start converting PackLinuxElf64amd to ElfLinker 2006-07-09 08:14:04 -07:00
László Molnár f74c2af65c conversion of atari/tos to ElfLinker finished 2006-07-07 17:49:30 +02:00
László Molnár 9531bdf674 fixed a bug in ElfLinker 2006-07-07 16:57:15 +02:00
László Molnár 76e705e7ee more atari/tos work 2006-07-07 09:20:43 +02:00
László Molnár d35211328e ElfLinker: rela support added 2006-07-07 08:51:48 +02:00
László Molnár b7bbd81dda conversion of atari/tos to ElfLinker started 2006-07-06 18:30:34 +02:00
László Molnár 9836dd5d10 merge 2006-07-06 10:27:31 +02:00
László Molnár 2109ad320d ps1: nrv2b & nrv2d converted to gas
updated README.SRC
removed app-asm5900.pl
2006-07-06 09:20:05 +02:00
László Molnár c026121c0e mips conversion to ElfLinker almost ready 2006-07-06 00:54:14 +02:00
László Molnár ee0c87f7b1 mips conversion started 2006-07-05 18:32:52 +02:00
John Reiser 709fb93a22 sizeof(shstrtab) already includes terminating '\0' 2006-07-05 05:40:24 -07:00
László Molnár b38cd0a48d merge 2006-07-05 13:02:14 +02:00
László Molnár 264435c32d rebuilt the stubs 2006-07-05 13:00:42 +02:00
László Molnár c285929ad3 i386/macros2.ash: ctojr32 fixes 2006-07-04 23:30:50 +02:00
John Reiser 1cbea8157d merge 2006-07-04 08:59:29 -07:00
John Reiser 0a10334f1b more *BSD, especially do_xmap() for OpenBSD 2006-07-04 08:59:00 -07:00
László Molnár f0d5a6ebac vmlinu[xz] using nrv2e converted to ElfLinker 2006-07-04 17:36:54 +02:00
László Molnár db7086b5e6 pe: ignore duplicated relocation records 2006-07-04 14:11:56 +02:00
John Reiser 0e92280b33 *BSD elf-fold escape hatch differs from Linux 2006-07-03 19:35:56 -07:00
John Reiser 0d7255158a OpenBSD "pro-active security" causes headaches 2006-07-03 16:35:21 -07:00
László Molnár 33564b68dd loader.txt updated 2006-07-03 15:13:53 +02:00
Markus F.X.J. Oberhumer ba942b952a Merge. 2006-07-03 14:56:45 +02:00
Markus F.X.J. Oberhumer bd7f28896e Minor cleanups. 2006-07-03 14:54:50 +02:00
John Reiser 18fe124696 ::generateElfHdr() sets .e_ident[Elf32_Ehdr::EI_OSABI] 2006-07-03 05:51:45 -07:00
John Reiser ea3a3b6e1c Elf32_Ehdr::ELFOSABI_LINUX 2006-07-03 05:47:01 -07:00
Markus F.X.J. Oberhumer e6c06aacff New brandelf.py script. 2006-07-03 13:00:53 +02:00
Markus F.X.J. Oberhumer 1aee92cd5c Introduced $(tc_bfdname). 2006-07-03 12:19:20 +02:00
Markus F.X.J. Oberhumer 40c4cad491 Rebuilt. 2006-07-03 12:07:34 +02:00
László Molnár 013d46fb02 merge 2006-07-03 10:46:32 +02:00
László Molnár f0f465411f win32/pe using nrv2e converted to ElfLinker 2006-07-03 09:21:51 +02:00
John Reiser 32ce83475d more *BSD arrangements 2006-07-02 21:54:44 -07:00
John Reiser ec0d3f5b5d merge 2006-07-02 19:28:19 -07:00
John Reiser 75294b9146 FreeBSD, NetBSD, OpenBSD on equal footing 2006-07-02 19:27:08 -07:00
Markus F.X.J. Oberhumer 26a0eb68ef Merge. 2006-07-03 01:42:12 +02:00
Markus F.X.J. Oberhumer b983e29fb0 Fix compilation on big endian machines. Remove trailing whitespace. 2006-07-03 01:40:59 +02:00
John Reiser 68dadabc29 BSD/elf386 2006-07-02 16:25:31 -07:00
László Molnár ed9fd3f0e0 watcom/le using nrv2e converted to ElfLinker 2006-07-02 23:21:15 +02:00
László Molnár fa9573436a tmp/adam using nrv2e converted to ElfLinker 2006-07-02 22:39:53 +02:00
László Molnár 6d2058c3b7 reloc32 uncommented 2006-07-02 22:32:12 +02:00
John Reiser 0d7f93b877 unused: getrusage personality msync getcwd 2006-07-02 12:04:12 -07:00
László Molnár f022c9d510 dos/djgpp2 using nrv2e converted to ElfLinker 2006-07-01 17:29:41 +02:00
László Molnár 5964a06386 arm/pe works with ElfLinker 2006-07-01 12:36:07 +02:00
László Molnár f14dc4a4e9 ElfLinkerArmLe fixes 2006-07-01 12:25:26 +02:00
László Molnár fd56e2534c fixed alignment handling typo 2006-07-01 09:40:12 +02:00
László Molnár 08962a74ab started the arm/pe conversion to ElfLinker 2006-07-01 00:21:53 +02:00
László Molnár f850d36c52 dos/com & dos/sys: use the new ElfLinker features 2006-07-01 00:21:06 +02:00
László Molnár c5fb161477 ElfLinker updates
commented out the debugging printfs
now it's possible to set the offset of sections
aligment handling simplified
ElfLinkerArmPE introduced
2006-07-01 00:10:02 +02:00
László Molnár bfc2fab33f use "//" instead of "#" for comments 2006-07-01 00:01:35 +02:00
John Reiser ec9d6c4fd2 workaround linux bug which demands writeable PT_LOAD for .bss 2006-06-29 19:07:02 -07:00
John Reiser 6135d61e3d *-fold.h depends on *.lds 2006-06-29 17:01:38 -07:00
John Reiser a677242a2c Bvmlinuz remember to patchDecompressor() 2006-06-29 13:58:41 -07:00
John Reiser 6602f30112 true==checkCompressionRatio() means success 2006-06-29 12:07:01 -07:00
Markus F.X.J. Oberhumer a4b8dc18c1 Strip unneeded symbols and sections from i086-* stubs. 2006-06-29 19:09:16 +02:00
Markus F.X.J. Oberhumer c0d4741f88 Merge. 2006-06-29 18:43:36 +02:00
László Molnár b33718180c ElfLinkerX86 introduced.
Simple alignment handling added to ElfLinker.
dos/exe device drivers can be compressed again.
2006-06-29 18:21:01 +02:00
John Reiser 3872393b29 call freezeLoader 2006-06-29 06:08:57 -07:00
John Reiser 1d72a7df99 propagate IMAGE_OFFSET from commandline 2006-06-29 05:57:28 -07:00
Markus F.X.J. Oberhumer 5455908772 Merge. 2006-06-29 14:39:42 +02:00
Markus F.X.J. Oberhumer 8882192fac Minor cleanups. 2006-06-29 14:38:18 +02:00
Markus F.X.J. Oberhumer 7b77491c06 Refactoring: move fields ui_pass and ui_total_passes from class
Packer into class UiPacker.
2006-06-29 14:37:01 +02:00
László Molnár 20bf214d6e dos/com & dos/sys: xchg si,di vs. xchg di,si difference fixed. i086-dos16.com.h rebuilt 2006-06-29 14:27:25 +02:00
Markus F.X.J. Oberhumer 8ab3e63aeb First start of refactoring field ph out of class Packer. 2006-06-29 14:26:49 +02:00
László Molnár 0dc03214c5 merge 2006-06-29 11:51:47 +02:00
John Reiser 362e98b43d lzma: limit stack to ~28KB for decompressing kernel 2006-06-28 22:34:12 -07:00
John Reiser 193e085cf0 limit stack to ~28KB for decompressing kernel 2006-06-28 22:30:05 -07:00
John Reiser e0df2a342b merge 2006-06-28 22:20:24 -07:00
John Reiser ba19ccac43 tabify the commented Makefile 2006-06-28 22:18:48 -07:00
Markus F.X.J. Oberhumer d7261b7a78 Remove debugging code. 2006-06-29 07:00:06 +02:00
Markus F.X.J. Oberhumer 0d80173efd Update some structs for future features. 2006-06-29 06:42:17 +02:00
Markus F.X.J. Oberhumer 930f07d15e Move upx_compress_result_t handling into right place. 2006-06-29 06:24:24 +02:00
Markus F.X.J. Oberhumer 66df7389d2 Refactoring: pass upx_compress_config_t to Packer::compressWithFilters()
so that formats can set conf_lzma.max_num_probs.

Also renamed compression parameters to use cconf & cresult.
2006-06-29 06:15:28 +02:00
Markus F.X.J. Oberhumer c7bf0b6ddd Removed trailing whitespace. 2006-06-29 05:12:39 +02:00
Markus F.X.J. Oberhumer 0bc361adeb Introduced conf_lzma.max_num_probs to limit stack size for decompression. 2006-06-29 05:12:01 +02:00
John Reiser 4fff523a6d Merge 2006-06-28 19:45:58 -07:00
John Reiser 67e09fb342 kernel Makefile; fix cross-platform endian trouble 2006-06-28 19:44:02 -07:00
Markus F.X.J. Oberhumer c360806f47 Small Makefile updates. 2006-06-29 04:16:58 +02:00
Markus F.X.J. Oberhumer 7b74b73b08 Start using binutils-multiarch-2.17. 2006-06-29 01:52:05 +02:00
László Molnár e9a851c0d4 dos/exe: migrated to ElfLinker 2006-06-29 00:44:12 +02:00
Markus F.X.J. Oberhumer b13b169149 Fixed assembly for binutils-2.16.91. 2006-06-29 00:38:12 +02:00
László Molnár 455329a745 dos/sys: got rid of the "next" symbol 2006-06-29 00:28:47 +02:00
László Molnár a68b76c8b4 undefined symbols are initialized to "0xdeaddead" 2006-06-29 00:22:45 +02:00
László Molnár 96e3899216 increased the maximum number of symbols 2006-06-29 00:22:03 +02:00
Markus F.X.J. Oberhumer 771ab5ea9a Added notes about binutils-multiarch-2.17. 2006-06-29 00:11:06 +02:00
László Molnár 3c87e6b270 merge 2006-06-28 15:10:01 +02:00
László Molnár 6d8afec510 ElfLinker started. Dos/com & dos/sys formats converted 2006-06-28 14:45:58 +02:00
John Reiser 89e25657d8 fix cross-platform endian trouble with ELF headers 2006-06-27 13:07:31 -07:00
John Reiser 29387f1fcf lzma Elf i386 minor tuning 2006-06-27 09:53:28 -07:00
John Reiser 58e885c052 un-debug 2006-06-26 17:21:45 -07:00
John Reiser 984dfcd7e1 adapt to new 2-byte replacement for LzmaDecodeProperties() 2006-06-26 17:16:45 -07:00
Markus F.X.J. Oberhumer 3785479086 Use custom encoding for LZMA properties. 2006-06-26 17:28:46 +02:00
Markus F.X.J. Oberhumer 8ed280907c Merge. 2006-06-26 14:36:29 +02:00
Markus F.X.J. Oberhumer d742671205 Update comment. 2006-06-26 14:36:10 +02:00
John Reiser 87e72c28a4 no PROT_WRITE for .text on i386-linux.elf.shell 2006-06-25 06:05:53 -07:00
John Reiser 4dee357362 optimize PackLinuxI386::buildLinuxLoader 2006-06-25 05:56:36 -07:00
John Reiser 431f4b9b0d fix i386-linux.elf.shell 2006-06-25 05:44:39 -07:00
John Reiser dd5b7825d5 save 4 bytes in __LZMA_ELF00__ 2006-06-24 16:48:43 -07:00
John Reiser 02bc48925a lzma ELF minimal CLzmaDecoderState each time 2006-06-24 14:44:40 -07:00
John Reiser 4eb505755e lzma for ELF 2006-06-24 14:00:41 -07:00
Markus F.X.J. Oberhumer 83e94a70ea Narrow try/catch. 2006-06-24 17:53:26 +02:00
Markus F.X.J. Oberhumer 8a150b27c3 Update comment. 2006-06-24 17:39:10 +02:00
John Reiser 1a51451ec2 ELF stub uses getSizeForCompression() 2006-06-23 19:32:29 -07:00
Markus F.X.J. Oberhumer 41e51bfb77 Assert dst_len buffer size in upx_compress(). 2006-06-23 17:50:39 +02:00
Markus F.X.J. Oberhumer 7e1d9bc768 Split options_t::crp into multiple structs. 2006-06-23 16:23:31 +02:00
Markus F.X.J. Oberhumer ba065ec1d8 Improve error code reporting in compression wrappers. 2006-06-23 15:52:10 +02:00
Markus F.X.J. Oberhumer fe057a91c8 Cleanup: removed upx_bool and upx_uint types. 2006-06-23 15:00:33 +02:00
László Molnár d2c36eefc9 pe: fixed unpack problem in rebuildImports() 2006-06-23 11:17:26 +02:00
John Reiser 28d56bab04 Merge 2006-06-22 21:30:59 -07:00
John Reiser 2500eff90d more LZMA debugging for Linux i386 ELF 2006-06-22 21:25:18 -07:00
Markus F.X.J. Oberhumer 153446b3a1 Fixed debugging code. 2006-06-23 05:40:35 +02:00
Markus F.X.J. Oberhumer 391f5caaa2 Added precondition assertions to upx_decompress(). 2006-06-23 05:27:42 +02:00
Markus F.X.J. Oberhumer cc0df92444 Added some more checks. 2006-06-23 04:02:06 +02:00
John Reiser 03910d67c3 M_LZMA bug tracking: decompress fails but says OK 2006-06-22 17:18:17 -07:00
Markus F.X.J. Oberhumer fec5cc864e Update Makefile. 2006-06-23 01:02:47 +02:00
Markus F.X.J. Oberhumer cb78362713 Use inner class UiPacker::State. 2006-06-22 19:40:43 +02:00
Markus F.X.J. Oberhumer 4c5b1a6ff4 Added some assertions to track down a win32/pe unpack problem which
shows up on 64-bit machines.
2006-06-22 16:47:10 +02:00
László Molnár 83c5727698 merge 2006-06-22 16:17:09 +02:00
László Molnár 80838ff1e9 watcom/le: lzma seems to work 2006-06-22 16:15:32 +02:00
Markus F.X.J. Oberhumer 29e8d072b7 Simplify C++ style in Linker. 2006-06-22 16:12:48 +02:00
Markus F.X.J. Oberhumer d7592f01e1 Renamed method. 2006-06-22 16:00:03 +02:00
László Molnár 392f283d9e added some comments 2006-06-22 15:54:25 +02:00
Markus F.X.J. Oberhumer bcd738ebbb Introduced Packer::patchDecompressorGetExtraStacksize(). 2006-06-22 15:35:38 +02:00
László Molnár 8020c52c48 merge 2006-06-22 15:04:39 +02:00
László Molnár 3f566e541d djgpp2: lzma seems to work 2006-06-22 15:00:15 +02:00
Markus F.X.J. Oberhumer be4a631dc8 Bump version. 2006-06-22 14:50:09 +02:00
Markus F.X.J. Oberhumer 0bfdf908c1 Fixed typo. 2006-06-22 14:20:05 +02:00
Markus F.X.J. Oberhumer 6f2fc23f77 Added LZMA license information. 2006-06-22 14:11:58 +02:00
Markus F.X.J. Oberhumer f3a47c7e70 Add more lzma_d.ash includes. 2006-06-22 14:07:23 +02:00
Markus F.X.J. Oberhumer 36349ffabb Removed trailing whitespace. 2006-06-22 14:06:21 +02:00
John Reiser b13f7366cf freezeLoader() sooner in PackLinuxElf32x86::buildLinuxLoader() 2006-06-21 17:08:58 -07:00
John Reiser 9181bcd9a7 CT24ARM needs big+little endian versions 2006-06-21 13:57:12 -07:00
Markus F.X.J. Oberhumer 7dbc1d894b Add default defines like -Dstub_i386_dos32_djgpp2=1 to nasm. 2006-06-21 21:31:20 +02:00
Markus F.X.J. Oberhumer 5720445d15 Use ebx for state pointer. Decrease local stack size. 2006-06-21 14:34:23 +02:00
Markus F.X.J. Oberhumer a90027521d Prepare Makefile for integrating lua-5.1.1 into upx. 2006-06-20 15:35:23 +02:00
Markus F.X.J. Oberhumer e02d400bf6 Avoid djgpp2 link error. 2006-06-20 15:25:38 +02:00
Markus F.X.J. Oberhumer efadb8fd31 More lzma stubs. 2006-06-19 23:19:34 +02:00
Markus F.X.J. Oberhumer a19d06561b Added amd64 implementations of lzma. 2006-06-19 22:33:18 +02:00
Markus F.X.J. Oberhumer 0b685d11c9 More lzma updates - win32/pe + lzma seems to work. 2006-06-19 22:08:06 +02:00
Markus F.X.J. Oberhumer 28f019d672 Merge. 2006-06-19 19:21:23 +02:00
Markus F.X.J. Oberhumer bf5cbfffc2 Start major refactoring. 2006-06-19 19:20:50 +02:00
László Molnár fe021e7c51 w32/pe: added Virtualloc and VirtualFree to the import list 2006-06-19 15:05:28 +02:00
Markus F.X.J. Oberhumer c42fb54bc6 Assorted cleanups. 2006-06-17 18:54:11 +02:00
Markus F.X.J. Oberhumer 9382b68781 Fix srcdir for VPATH build. 2006-06-16 20:08:21 +02:00
Markus F.X.J. Oberhumer 178198a417 Merge. 2006-06-16 17:52:50 +02:00
John Reiser 7068e90771 Merge 2006-06-16 06:53:56 -07:00
Markus F.X.J. Oberhumer 1c762f23d0 Simplify stub/Makefile. 2006-06-16 15:51:59 +02:00
John Reiser fd2b9a6e21 filter 0x51 (ARM call trick, big-endian at compress time) 2006-06-16 06:49:37 -07:00
Markus F.X.J. Oberhumer db43910288 Enter 2006. 2006-06-16 15:17:29 +02:00
Markus F.X.J. Oberhumer f248c0460e Use -mcpu=405 for powerpc stubs. Also run sstrip on powerpc-linux.elf-fold. 2006-06-16 14:36:13 +02:00
Markus F.X.J. Oberhumer b8e3c0ceb4 Allow ~/bin/bin-upx in addition to ~/local/bin/bin-upx. 2006-06-16 14:11:11 +02:00
Markus F.X.J. Oberhumer b5053d889e Updated toplevel Makefile. 2006-06-16 14:09:22 +02:00
Markus F.X.J. Oberhumer 12ba7776b3 Comment out unused upx_crc32(). 2006-06-16 14:08:56 +02:00
Markus F.X.J. Oberhumer 7817e88d03 Updated stub/Makefile. 2006-06-16 13:26:36 +02:00
Markus F.X.J. Oberhumer 8dec65853d Fixed another bad merge issue. 2006-06-16 12:34:37 +02:00
Markus F.X.J. Oberhumer 88e3cb3be1 Stub: remove files again which seem to have been brought back by some merge. 2006-06-16 12:31:14 +02:00
John Reiser fa702b48e3 unify PackLinuxElf32arm...::pack1() 2006-06-15 15:41:00 -07:00
John Reiser 299dcf6686 Merge 2006-06-15 12:21:01 -07:00
Markus F.X.J. Oberhumer 27f9ae5bbb Small cleanups. 2006-06-15 19:59:30 +02:00
Markus F.X.J. Oberhumer 9cb3a853f1 Added option --MMD= to gpp_inc.py for automated dependencies. 2006-06-15 19:03:18 +02:00
Markus F.X.J. Oberhumer 95c8ef4148 Added a number of convenience Makefiles. 2006-06-15 18:07:23 +02:00
Markus F.X.J. Oberhumer a41bb52014 Updated comments. 2006-06-15 18:03:24 +02:00
Markus F.X.J. Oberhumer 914cd7221e Updated. 2006-06-15 17:57:22 +02:00
Markus F.X.J. Oberhumer 2dfc0a58ab Renamed src/stub/util/ to src/stub/tools/ . 2006-06-15 17:56:57 +02:00
Markus F.X.J. Oberhumer 0c9f3c638a Explicitly list all required files for ~/local/bin/bin-upx/. 2006-06-15 17:52:30 +02:00
Markus F.X.J. Oberhumer a966d6acf1 Mention GNU make 3.81. 2006-06-15 17:27:04 +02:00
Markus F.X.J. Oberhumer 1e0c38b5f9 Renamed i386-linux-sstrip to sstrip. 2006-06-15 08:41:33 +02:00
Markus F.X.J. Oberhumer d3323d6550 Major refactoring of src/stub directory. 2006-06-15 08:17:50 +02:00
John Reiser ebed0b9f20 allow brev() in-place 2006-06-14 20:21:39 -07:00
John Reiser f654a453dc ARM_pack3() unifies big/little endian and HostPolicy 2006-06-14 16:06:50 -07:00
John Reiser 10decf94cc fix delete[] file_image 2006-06-14 11:41:49 -07:00
John Reiser 96dd4817f1 unify PackLinuxElf32...::canPack(); also ARM buildLinuxLoader() 2006-06-14 11:33:16 -07:00
Markus F.X.J. Oberhumer 72906cdc6a Removed all files from src/stub directory. 2006-06-14 17:37:59 +02:00
Markus F.X.J. Oberhumer fba4375be0 Cleanups. 2006-06-14 17:06:33 +02:00
Markus F.X.J. Oberhumer 75120676ad Introduced BEPolicy and LEPolicy. 2006-06-14 14:45:49 +02:00
Markus F.X.J. Oberhumer 7daf63fd3f Merge. 2006-06-14 11:48:44 +02:00
Markus F.X.J. Oberhumer 014de25f6f Disable lzma by default for now. 2006-06-14 11:42:24 +02:00
John Reiser 3fc6535012 un-debug Makefile 2006-06-13 19:02:21 -07:00
John Reiser 4fc0a32572 Do not brev() strings in stub for PackLinuxEl32armBe. 2006-06-13 18:55:26 -07:00
John Reiser dcc704a357 debug PackLinuxElf32armBe. Also unify subroutines. 2006-06-13 15:51:29 -07:00
John Reiser bd8acbde97 PackLinuxElf32armBe (Linux ARM big-endian) 2006-06-13 11:48:54 -07:00
John Reiser 112b10c19d avoid randomness for progid in Elf 2006-06-13 08:53:41 -07:00
John Reiser d89e561a85 PackLinuxElf32armLe, PackLinuxElf32armBe 2006-06-13 08:51:02 -07:00
John Reiser 49c1da79c8 PackLinuxElf32arm ==> PackLinuxElf32armLe 2006-06-13 08:27:14 -07:00
John Reiser 0a72f00175 Elf_BE32_* 2006-06-13 08:25:30 -07:00
John Reiser 1af5820db0 hack printf() 2006-06-13 08:24:38 -07:00
John Reiser c117491549 arm-9tdmi-linux-gnu-gcc is gcc-3.4.5-glibc-2.3.6; old was gcc-3.4.1-glibc-2.3.3 2006-06-12 11:05:52 -07:00
Markus F.X.J. Oberhumer d8748f4270 Introduced MemBuffer::getSizeForCompression(). 2006-06-12 13:18:55 +02:00
Markus F.X.J. Oberhumer c0ba6e13e4 Check for .hg directory when generating ChangeLog. 2006-06-11 13:05:57 +02:00
Markus F.X.J. Oberhumer c34daf1a35 Make code -Wshadow warning free. 2006-06-11 12:25:19 +02:00
Markus F.X.J. Oberhumer d461b53235 Renamed variable clen to c_len and ulen to u_len. 2006-06-11 12:13:37 +02:00
Markus F.X.J. Oberhumer c3ee14eb67 Introduced upx_compress_result_t. 2006-06-11 12:09:25 +02:00
Markus F.X.J. Oberhumer 869fb8e327 Merge. 2006-06-11 00:01:56 +02:00
John Reiser fbbc3024d6 Linux ARM cacheflush 2006-06-10 14:41:50 -07:00
Markus F.X.J. Oberhumer f1ba0c0aa7 More lzma stuff. 2006-06-09 18:36:53 +02:00
Markus F.X.J. Oberhumer 54340ab4bf Renamed environment variable UCLDIR to UPX_UCLDIR. 2006-06-09 15:22:42 +02:00
Markus F.X.J. Oberhumer 39732eee5e Merge. 2006-06-09 09:30:42 +02:00
Markus F.X.J. Oberhumer a9e4526a6d Rearranged compression interface. 2006-06-09 09:28:32 +02:00
John Reiser 57a6d2abf9 Merge 2006-06-08 20:51:59 -07:00
John Reiser d6246941ac fix f_unfilter 0x50 2006-06-08 20:48:43 -07:00
László Molnár 2eb91f9b91 do not assume osection[0].rawdataptr > 0 during decompression 2006-06-08 16:52:54 +02:00
Markus F.X.J. Oberhumer 34ae413607 Initial lzma support. 2006-06-07 04:42:15 +02:00
Markus F.X.J. Oberhumer ee9f8c184b Small updates. 2006-06-06 19:07:38 +02:00
Markus F.X.J. Oberhumer 7a84afcbdb Sort .hgtags. 2006-06-06 17:42:43 +02:00
Markus F.X.J. Oberhumer b8a16ea99d Merge. 2006-06-06 17:38:39 +02:00
Markus F.X.J. Oberhumer 095466d5c7 Added tag RELEASE_201 for changeset a916a2fe22de45167d25abcb40008315f415221c 2006-06-06 17:36:52 +02:00
Markus F.X.J. Oberhumer 89cfa22c3f Final cleanups for 2.01. 2006-06-06 17:36:34 +02:00
John Reiser 1f18050930 elf32arm escape hatch: avoid Elf32_Ehdr if possible 2006-06-02 08:51:02 -07:00
John Reiser 537b78d564 fix elf32arm unmapping hatch 2006-06-01 22:48:52 -07:00
John Reiser 717fd57ce1 remember b_info for Elf headers; also: escape hatch 2006-06-01 12:00:05 -07:00
John Reiser 3fb7786868 [re-]comment-out debugging 'int3' 2006-06-01 11:12:30 -07:00
John Reiser 17ecfc9765 new class PackLinuxElf32arm : PackLinuxElf32Le;
Unify some functions in leaf classes by moving to parent class.
2006-06-01 06:37:44 -07:00
John Reiser 5326260a76 new elf32arm; small effects in elf86, linux.hh 2006-06-01 06:32:33 -07:00
John Reiser e7522f4bdf branch merge 2006-05-24 13:59:43 -07:00
John Reiser 504deeff42 ET_DYN cannot be old format for decompression 2006-05-24 13:15:39 -07:00
Markus F.X.J. Oberhumer b7785b64cf Small cleanups to keep p_armpe & p_w32pe in sync. 2006-05-24 19:21:26 +02:00
László Molnár f914cb6858 pe: added support for empty resource section 2006-05-24 17:14:09 +02:00
John Reiser 91051d2521 Try to merge with mainline. 2006-05-23 17:52:05 -07:00
John Reiser 51536a7acd decompression PackLinuxElf32x86.ET_DYN 2006-05-23 17:42:35 -07:00
Markus F.X.J. Oberhumer 263ccab6e3 Updated NEWS for --brute bugfix. 2006-05-23 13:25:19 +02:00
John Reiser 9f87755dcb Note fix to --force-execve for PaX, grSecurity, strict SELinux. 2006-05-22 15:15:21 -07:00
John Reiser 60b4cca5e5 use powerpc-750-linux-gnu/gcc-3.4.3.20050210-glibc-2.2.5 2006-05-22 13:14:54 -07:00
John Reiser d2718e99a4 Change class PackLinuxI386elf : public PackLinuxI386
into   class PackLinuxElf32x86 : public PackLinuxElf32Le : public PackLinuxElf32
which makes the code for compressing ELF (for direct-to-memory decompression)
cleaner because ELF has some of the class tree to itself.
This assumes PROT_EXEC|PROT_WRITE ought to work.
This is checked at runtime, and if it fails then
give a message on stderr and exit(127).

Modify --force-execve so that runtime avoids PROT_EXEC|PROT_WRITE.
Then executables compressed with --force-execve will run under
PaX, grSecurity, and strict SELinux.
2006-05-21 13:58:24 -07:00
John Reiser 69a00c0ab3 *BSD requires -1==fd for MAP_ANONYMOUS
stub/l_lx_exec.c stub/l_lx_sh.c stub/l_lx_sh86.asm
2006-05-21 13:45:57 -07:00
Markus F.X.J. Oberhumer 3272d23917 Renamed variable hdr_clen to hdr_c_len. 2006-05-20 13:44:36 +02:00
Markus F.X.J. Oberhumer 7f0545cae7 Check result of hdr compression. 2006-05-20 13:37:34 +02:00
Markus F.X.J. Oberhumer 68f35deb86 Fixed a rare boundary problem in Packer::compressWithFilters().
The comparision if an update might be possible later was using
"<" instead of "<=" which resulted in missing calls to
findOverlapOverhead() and buildLoader().

Also, the comparision had not been updated for the newly added
hdr_clen fields.

This fixes sf.net bug #1477825.
2006-05-20 13:29:01 +02:00
Markus F.X.J. Oberhumer c4f4035072 Updated NEWS. 2006-05-18 19:01:03 +02:00
László Molnár a7d8845952 mention --keep-resource in NEWS and help.cpp 2006-05-18 15:54:35 +02:00
Markus F.X.J. Oberhumer a3378393b0 Removed scripts/. 2006-05-18 15:35:35 +02:00
László Molnár 3dfe0ad478 pe: fined grain control over resource compression 2006-05-18 15:20:37 +02:00
László Molnár 9a3b7a4f3f arm/pe: really fix the memory leak 2006-05-18 15:20:11 +02:00
László Molnár 78579b1103 pe: do not crash on out of bounds bogus relocation records 2006-05-18 15:19:55 +02:00
László Molnár 7d50344512 pe: fixed a memory leak in the resource handling code 2006-05-18 15:19:13 +02:00
László Molnár 7a00c12065 arm/pe: minor cleanup in the thumb mode stub 2006-05-18 15:18:50 +02:00
László Molnár af71e67681 arm/pe: saved 4 bytes in the arm mode stub 2006-05-18 15:18:36 +02:00
László Molnár b3e20fc324 arm/pe: no need to try to precompute the size of relocations 2006-05-18 15:18:13 +02:00
László Molnár bd1014abb6 dos/exe: saved some bytes in device driver mode 2006-05-18 15:17:53 +02:00
László Molnár 7f76664a5d Merged with mainline 2006-05-18 13:10:15 +02:00
Markus F.X.J. Oberhumer 0a5a80b05d Updated .hgignore. 2006-05-18 10:48:06 +02:00
Markus F.X.J. Oberhumer 2d63da0660 Support automatic ChangeLog generation. 2006-05-18 10:16:59 +02:00
Markus F.X.J. Oberhumer 8387527d2e Updated .hgignore. 2006-05-18 09:37:18 +02:00
Markus F.X.J. Oberhumer 5d03ba7d63 Added .hgignore. 2006-05-18 09:08:38 +02:00
Markus F.X.J. Oberhumer 0ece50c122 Removed .cvsignore and .gitignore files. 2006-05-18 09:02:00 +02:00
Markus F.X.J. Oberhumer f2ac297252 Updated tags. 2006-05-18 08:27:19 +02:00
László Molnár 0ca8ae17d4 updated my email address 2006-05-17 21:05:46 +02:00
convert-repo 88ca87cf9e update tags 2006-05-11 10:41:33 +00:00
László Molnár 0d69d228e4 arm/pe: no need to allocate extra memory in the import table
committer: ml1050 <ml1050> 1147090379 +0000
2006-05-08 12:12:59 +00:00
Markus F.X.J. Oberhumer a3afe95306 Updated NEWS.
committer: mfx <mfx> 1147081195 +0000
2006-05-08 09:39:55 +00:00
Markus F.X.J. Oberhumer 9fb4af8658 Updated Makefile.
committer: mfx <mfx> 1147081156 +0000
2006-05-08 09:39:16 +00:00
László Molnár 9bb6ba9311 dos/exe: device driver support added (thanks Michael Devore)
committer: ml1050 <ml1050> 1147078121 +0000
2006-05-08 08:48:41 +00:00
Markus F.X.J. Oberhumer faa42ba341 Updated the master Makefile
to be more friendly to people without the special stub build tools.

committer: mfx <mfx> 1146764116 +0000
2006-05-04 17:35:16 +00:00
László Molnár 596827a912 remove obsolete files: l_armpe.asm l_armpe.h l_armpe_c.c l_armpe_s.S
committer: ml1050 <ml1050> 1146763209 +0000
2006-05-04 17:20:09 +00:00
László Molnár 89b4292445 saved 2 bytes
committer: ml1050 <ml1050> 1146763076 +0000
2006-05-04 17:17:56 +00:00
László Molnár dd88737414 it works on wince now (only with dlls)
committer: ml1050 <ml1050> 1146763013 +0000
2006-05-04 17:16:53 +00:00
László Molnár 5456cfc304 arm/pe: use the new linker friendly stubs
two linkers: one for arm mode, one for thumb mode
the import address table is moved to the stubs area of compressed files
changed the alignment of some header fields
the command line option "--8086" can be used to force thumb mode on

committer: ml1050 <ml1050> 1146647520 +0000
2006-05-03 09:12:00 +00:00
László Molnár 1e66096ea7 arm/pe stubs: the import address table is moved to the stub
committer: ml1050 <ml1050> 1146646915 +0000
2006-05-03 09:01:55 +00:00
John Reiser 2b6ae3908c /usr/bin/dyld can be a "fat binary" [how stupid!]
m_mac_mach32.c fold_machppc32.S fold_machppc32.h

committer: jreiser <jreiser> 1146434013 +0000
2006-04-30 21:53:33 +00:00
László Molnár 1924612479 a small fix for the thumb stub
committer: ml1050 <ml1050> 1146224685 +0000
2006-04-28 11:44:45 +00:00
László Molnár 2af5bdeaab added some debugging code
committer: ml1050 <ml1050> 1146154452 +0000
2006-04-27 16:14:12 +00:00
László Molnár b28565b38d new files: l_armpea.h l_armpet.h
committer: ml1050 <ml1050> 1146154411 +0000
2006-04-27 16:13:31 +00:00
László Molnár fec602362b added new virtual function createLinker()
committer: ml1050 <ml1050> 1146153290 +0000
2006-04-27 15:54:50 +00:00
László Molnár 6753c5f45a trying to implement the user space loader on native wince
committer: ml1050 <ml1050> 1146152386 +0000
2006-04-27 15:39:46 +00:00
Markus F.X.J. Oberhumer 2f3c108d42 Next version will be 2.01.
committer: mfx <mfx> 1146140843 +0000
2006-04-27 12:27:23 +00:00
Markus F.X.J. Oberhumer ce6d99bdb4 More README updates.
committer: mfx <mfx> 1146086335 +0000
2006-04-26 21:18:55 +00:00
Markus F.X.J. Oberhumer 86d4125893 Updates.
committer: mfx <mfx> 1146086189 +0000
2006-04-26 21:16:29 +00:00
Markus F.X.J. Oberhumer 3a18f00379 Prepared 2.00 release notes.
committer: mfx <mfx> 1146085621 +0000
2006-04-26 21:07:01 +00:00
Markus F.X.J. Oberhumer e6274904a7 Rebuilt using i386-linux-ld-2.16.1 and i386-linux-objcopy-2.16.1.
committer: mfx <mfx> 1146079399 +0000
2006-04-26 19:23:19 +00:00
Markus F.X.J. Oberhumer 3677395444 Add version suffix to the binutils we use. Prefix all linux/386 tools
with i386-linux-.

committer: mfx <mfx> 1146079325 +0000
2006-04-26 19:22:05 +00:00
László Molnár 22ba35b3b5 new arm/pe assembly with UPX linker support
committer: ml1050 <ml1050> 1145955479 +0000
2006-04-25 08:57:59 +00:00
Markus F.X.J. Oberhumer 9c1ab9979b Split "$Id" strings so that CVS does not interfere. Explicitlty
use ".p2align" and ".balign" instead of ".align".

committer: mfx <mfx> 1145864788 +0000
2006-04-24 07:46:28 +00:00
John Reiser eaa463e1c9 Insert copyright notice (equivalent to ident_s.ash) into stub by hand
because buildLoader is not fully working yet
	l_lx_elf64amd.S l_lx_elfppc32.S l_mac_ppc32.S

committer: jreiser <jreiser> 1145825498 +0000
2006-04-23 20:51:38 +00:00
John Reiser 6984be48c3 build sync: compile using crosstool gcc-3.4.3.20050507-glibc-2.3.5
committer: jreiser <jreiser> 1145820281 +0000
2006-04-23 19:24:41 +00:00
John Reiser b739bd3d79 Work better with SELinux. We still require allow_execmem.
p_lx_elf.cpp
	stub/fold_elfppc32.h
	stub/l_lx_elfppc32.h
	stub/l_lx_elfppc32.S
	stub/m_lx_elfppc32.c

committer: jreiser <jreiser> 1145666524 +0000
2006-04-22 00:42:04 +00:00
John Reiser 23f3e4396c For elf64and and elfppc32: -fno-exceptions -fno-asynchronous-unwind-tables
committer: jreiser <jreiser> 1145666377 +0000
2006-04-22 00:39:37 +00:00
John Reiser c264750924 Adapt better to SELinux. We still need allow_execmem.
p_lx_elf.cpp
	stub/a_lx_elf64.c
	stub/l_lx_elf64amd.h
	stub/l_lx_elf64amd.lds
	stub/l_lx_elf64amd.S
	stub/fold_elf64amd.h

committer: jreiser <jreiser> 1145657332 +0000
2006-04-21 22:08:52 +00:00
John Reiser c155f0a5d5 Better fit with SELinux. Now requires only execmem, which Fedora Core 5
enables as default for non-confined [ordinary] executables.
	l_lx_elf.c
	l_lx_elf86.asm
	l_lx_elf86.h
	l_lx_elf86.lds
	fold_elf86.asm
	fold_elf86.h

committer: jreiser <jreiser> 1145634453 +0000
2006-04-21 15:47:33 +00:00
László Molnár 76734f086d added an arm/linux based loader/tester for arm/pe files
committer: ml1050 <ml1050> 1145605029 +0000
2006-04-21 07:37:09 +00:00
Markus F.X.J. Oberhumer 4f2d1172dd Added a note about --force-execve. Converted quoting from using
backticks to single-quotes.

committer: mfx <mfx> 1145444708 +0000
2006-04-19 11:05:08 +00:00
Markus F.X.J. Oberhumer 75caf4e297 Fix spelling in NEWS.
committer: mfx <mfx> 1145436378 +0000
2006-04-19 08:46:18 +00:00
Markus F.X.J. Oberhumer 509ab8261f Avoid code bloat in the official builds.
committer: mfx <mfx> 1145436321 +0000
2006-04-19 08:45:21 +00:00
Markus F.X.J. Oberhumer 1e05b40d4f Whitespace changes.
committer: mfx <mfx> 1145436164 +0000
2006-04-19 08:42:44 +00:00
Markus F.X.J. Oberhumer 451390f835 Updated NEWS.
committer: mfx <mfx> 1145435924 +0000
2006-04-19 08:38:44 +00:00
John Reiser 58cce9d2f8 Give message on stderr when SELinux enforcing mode inhibits execution.
l_lx_elf.c fold_elf86.asm fold_elf86.h

committer: jreiser <jreiser> 1145393418 +0000
2006-04-18 20:50:18 +00:00
László Molnár 2eb6e3b0ea arm/pe & w32/pe: disable filters for files with broken headers
committer: ml1050 <ml1050> 1145356307 +0000
2006-04-18 10:31:47 +00:00
John Reiser fb1181ed26 Allow executables >=3MB on elf64amd; -r1.69 on 2005-11-12 forgot to remove check.
committer: jreiser <jreiser> 1145139994 +0000
2006-04-15 22:26:34 +00:00
Markus F.X.J. Oberhumer 6d5e1d529d Updated NEWS.
committer: mfx <mfx> 1144968512 +0000
2006-04-13 22:48:32 +00:00
John Reiser 0e0ca08924 Propagate changes from linux.hh.
fold_elf86.h fold_pti86.h fold_sh86.h

committer: jreiser <jreiser> 1144967510 +0000
2006-04-13 22:31:50 +00:00
John Reiser 5d948a67a8 Propagate changes from linux.hh.
Also adjust calling segquence of upx_main() to shave a few bytes.
	l_lx_exec.c fold_exec86.asm fold_exec86.h

committer: jreiser <jreiser> 1144967447 +0000
2006-04-13 22:30:47 +00:00
John Reiser 6a4db2ecab Linux syscalls can clobber any input register, thanks to gcc and
the lack of a Linux kernel ABI.
	linux.hh

committer: jreiser <jreiser> 1144967342 +0000
2006-04-13 22:29:02 +00:00
Markus F.X.J. Oberhumer f700273624 Really bump the release date.
committer: mfx <mfx> 1144944628 +0000
2006-04-13 16:10:28 +00:00
Markus F.X.J. Oberhumer 0c198e0ccc Set tentative release date.
committer: mfx <mfx> 1144944070 +0000
2006-04-13 16:01:10 +00:00
Markus F.X.J. Oberhumer 71ffbbc420 Prepared 1.96 release.
committer: mfx <mfx> 1144943500 +0000
2006-04-13 15:51:40 +00:00
Markus F.X.J. Oberhumer 4fd09b889d Updated .cvsignore.
committer: mfx <mfx> 1144943334 +0000
2006-04-13 15:48:54 +00:00
László Molnár 4cb2a3eebe show image size change in info mode
committer: ml1050 <ml1050> 1144941392 +0000
2006-04-13 15:16:32 +00:00
László Molnár c25186b1f6 minor documentation updates
committer: ml1050 <ml1050> 1144941274 +0000
2006-04-13 15:14:34 +00:00
László Molnár 779033d0bc added filter (id: 0x50) support to the stub
the data cache is written back before the stub jumps to the uncompressed code

committer: ml1050 <ml1050> 1144931349 +0000
2006-04-13 12:29:09 +00:00
László Molnár 3e31560e7d added a new filter for ARM 24-bit naive calltrick
committer: ml1050 <ml1050> 1144931022 +0000
2006-04-13 12:23:42 +00:00
László Molnár d23d7e8775 removed unneeded entry point address check
committer: ml1050 <ml1050> 1144745835 +0000
2006-04-11 08:57:15 +00:00
László Molnár f6fdf5cb7f show image size change in info mode
committer: ml1050 <ml1050> 1144671675 +0000
2006-04-10 12:21:15 +00:00
Markus F.X.J. Oberhumer 1879ccd27d Next version will be 2.00.
committer: mfx <mfx> 1144586292 +0000
2006-04-09 12:38:12 +00:00
Markus F.X.J. Oberhumer 08c0796719 Avoid warnings when building for m68k.
committer: mfx <mfx> 1144523702 +0000
2006-04-08 19:15:02 +00:00
Markus F.X.J. Oberhumer edc7994ce5 Prepared 1.95 release.
committer: mfx <mfx> 1144522884 +0000
2006-04-08 19:01:24 +00:00
Markus F.X.J. Oberhumer bcfcfbd064 Added some more operators.
committer: mfx <mfx> 1144522838 +0000
2006-04-08 19:00:38 +00:00
Markus F.X.J. Oberhumer 9e79b3258d Make const-correct to avoid warning.
committer: mfx <mfx> 1144522792 +0000
2006-04-08 18:59:52 +00:00
John Reiser 243873cd2d Workaround inconsistent SIZEOF_HEADERS in stub/*.lds.
Test with --force-execve and --no-filter.
	p_lx_exc.cpp p_lx_sh.cpp stub/l_lx_sh86.asm stub/l_lx_sh86.h

committer: jreiser <jreiser> 1144381286 +0000
2006-04-07 03:41:26 +00:00
Markus F.X.J. Oberhumer c7b8a4b0c1 Updated.
committer: mfx <mfx> 1144320028 +0000
2006-04-06 10:40:28 +00:00
Markus F.X.J. Oberhumer e39e0c7140 Added .gitignore files.
committer: mfx <mfx> 1144319429 +0000
2006-04-06 10:30:29 +00:00
Markus F.X.J. Oberhumer d4a3f11dbb Whitespace changes.
committer: mfx <mfx> 1144318755 +0000
2006-04-06 10:19:15 +00:00
Markus F.X.J. Oberhumer 0962f266b3 Whitespace changes.
committer: mfx <mfx> 1144314053 +0000
2006-04-06 09:00:53 +00:00
Markus F.X.J. Oberhumer 69e4d3fdad Bumped tentative release date.
committer: mfx <mfx> 1144313563 +0000
2006-04-06 08:52:43 +00:00
Markus F.X.J. Oberhumer c0908f463a Added files to "clean" target.
committer: mfx <mfx> 1144313493 +0000
2006-04-06 08:51:33 +00:00
Markus F.X.J. Oberhumer b00a61a17b Updated.
committer: mfx <mfx> 1144313468 +0000
2006-04-06 08:51:08 +00:00
László Molnár 553c2f886a arm/pe: thumb mode dll support added
committer: ml1050 <ml1050> 1144312217 +0000
2006-04-06 08:30:17 +00:00
László Molnár 4fd9c5772a arm/pe:
v4 ARM mode stub support with assembly decompressor by John
dll support for v4 ARM mode
unpacking support

committer: ml1050 <ml1050> 1144249762 +0000
2006-04-05 15:09:22 +00:00
Markus F.X.J. Oberhumer 04e0e06d85 Whitespace changes.
committer: mfx <mfx> 1144235344 +0000
2006-04-05 11:09:04 +00:00
Markus F.X.J. Oberhumer 4d7829d72b New ACC version.
committer: mfx <mfx> 1144235271 +0000
2006-04-05 11:07:51 +00:00
John Reiser 6b751aac57 Fix return from THUMB to ARM mode on ARMv4T. Document r6 unused.
committer: jreiser <jreiser> 1143650112 +0000
2006-03-29 16:35:12 +00:00
László Molnár 813349fd23 arm/pe: support for nrv2b, support for cpu = 0x1c2, certificate info now removed
committer: ml1050 <ml1050> 1143614738 +0000
2006-03-29 06:45:38 +00:00
John Reiser 16a2744782 find_SEGMENT_gap() like find_LOAD_gap(). Use it to avoid checksum trouble.
p_mach.cpp p_mach.h

committer: jreiser <jreiser> 1143576015 +0000
2006-03-28 20:00:15 +00:00
John Reiser 7b6870db22 Fix bug: bad test for reaching back too far in SAFE mode. (Thank you, Laszlo.)
committer: jreiser <jreiser> 1143564998 +0000
2006-03-28 16:56:38 +00:00
Markus F.X.J. Oberhumer 3e38e7d52c Small cleanups.
committer: mfx <mfx> 1143474969 +0000
2006-03-27 15:56:09 +00:00
László Molnár 8142d3474d get_le32 reimplemented in assembly
committer: ml1050 <ml1050> 1143473260 +0000
2006-03-27 15:27:40 +00:00
Markus F.X.J. Oberhumer 8773649de6 Make code warning-free.
committer: mfx <mfx> 1143464312 +0000
2006-03-27 12:58:32 +00:00
Markus F.X.J. Oberhumer c117920ff9 Add -Wall -Werror to cross-compiler flags.
committer: mfx <mfx> 1143463128 +0000
2006-03-27 12:38:48 +00:00
László Molnár c8dd2a3eb8 arm/pe: use -march=armv4t instead of v5
committer: ml1050 <ml1050> 1143462067 +0000
2006-03-27 12:21:07 +00:00
Markus F.X.J. Oberhumer 90b1817e92 Undef PAGE_{MASK,SIZE} in conf.h.
committer: mfx <mfx> 1143454717 +0000
2006-03-27 10:18:37 +00:00
Markus F.X.J. Oberhumer d6c3ff5997 Cleanups.
committer: mfx <mfx> 1143454663 +0000
2006-03-27 10:17:43 +00:00
László Molnár 984ec25132 arm/pe: the assembly thumb mode decompressor is used in the stub
arm/pe: the C part of the stub is compiled as thumb

committer: ml1050 <ml1050> 1143449862 +0000
2006-03-27 08:57:42 +00:00
John Reiser a7bff34784 Fix THUMB mode return to ARM mode on ARMv4T. Spend 18 bytes to inline
most of get1b via conditional subroutine call idiom.

committer: jreiser <jreiser> 1143302120 +0000
2006-03-25 15:55:20 +00:00
John Reiser a6e7afbc91 Fix bug: first 'add' instead of 'adc' at get1_n2b. (Thank you, Laszlo.)
committer: jreiser <jreiser> 1143228535 +0000
2006-03-24 19:28:55 +00:00
John Reiser 33f1d63b64 Fix bug: first 'add' at get1_n2e instead of 'adc'.
Also conditionally assemble SAFE mode for buffer checking (default off).

committer: jreiser <jreiser> 1143228361 +0000
2006-03-24 19:26:01 +00:00
John Reiser f95e171e11 Workaround linux-2.6.14 binfmt_elf.c: SIGKILL if (0==.p_memsz) on a page boundary.
p_lx_elf.cpp p_lx_exc.cpp

committer: jreiser <jreiser> 1143057770 +0000
2006-03-22 20:02:50 +00:00
Markus F.X.J. Oberhumer c82b50b212 Bumped tentative release date.
committer: mfx <mfx> 1142610024 +0000
2006-03-17 15:40:24 +00:00
Markus F.X.J. Oberhumer 2b402b77f1 Updated short-list of supported executable formats.
committer: mfx <mfx> 1142609852 +0000
2006-03-17 15:37:32 +00:00
Markus F.X.J. Oberhumer adcb551020 Increase alignment to 16.
committer: mfx <mfx> 1142608657 +0000
2006-03-17 15:17:37 +00:00
Markus F.X.J. Oberhumer 2680aabe06 Removed bogus __attribute_packed from struct udll.
committer: mfx <mfx> 1142607440 +0000
2006-03-17 14:57:20 +00:00
Markus F.X.J. Oberhumer d5c0533b74 Allow the PE sections to cross a page boundary.
committer: mfx <mfx> 1142603590 +0000
2006-03-17 13:53:10 +00:00
Markus F.X.J. Oberhumer 609307668b Use $(MAKEFILE_LIST) for dependencies.
committer: mfx <mfx> 1142527291 +0000
2006-03-16 16:41:31 +00:00
Markus F.X.J. Oberhumer cdaf36572a Use UPX_VERSION_DATE_ISO from src/version.h.
committer: mfx <mfx> 1142527194 +0000
2006-03-16 16:39:54 +00:00
Markus F.X.J. Oberhumer 033c8d5d51 Updated.
committer: mfx <mfx> 1142523608 +0000
2006-03-16 15:40:08 +00:00
Markus F.X.J. Oberhumer 6216ec1d6a Mention John as a main author.
committer: mfx <mfx> 1142522272 +0000
2006-03-16 15:17:52 +00:00
László Molnár 6c9c67f6c5 DEP hack: it seems we need to patch the flags of section "UPX1" too
committer: ml1050 <ml1050> 1142508181 +0000
2006-03-16 11:23:01 +00:00
Markus F.X.J. Oberhumer 5bd32b5521 Commented out "int3" debugging leftovers.
committer: mfx <mfx> 1142312678 +0000
2006-03-14 05:04:38 +00:00
Markus F.X.J. Oberhumer 549336f75b Use boolean instead of bitwise logic.
committer: mfx <mfx> 1142311485 +0000
2006-03-14 04:44:45 +00:00
Markus F.X.J. Oberhumer f0e75f30b3 Fixed typo in comment.
committer: mfx <mfx> 1142310885 +0000
2006-03-14 04:34:45 +00:00
Markus F.X.J. Oberhumer 144c09f175 Rebuilt i386-linux stubs by gcc-3.4.6.
committer: mfx <mfx> 1142310823 +0000
2006-03-14 04:33:43 +00:00
Markus F.X.J. Oberhumer ee50c0f97c Corrected app_*.pl dependency.
committer: mfx <mfx> 1142309988 +0000
2006-03-14 04:19:48 +00:00
John Reiser ade921bf02 %.asy and %.asx depend onf $(APP_I386)
committer: jreiser <jreiser> 1142306625 +0000
2006-03-14 03:23:45 +00:00
John Reiser 676cacff04 gcc-4.1.0 vs. mmap()
linux.hh
	fold_elf86.asm  l_lx_elf.c
	fold_exec86.asm l_lx_exec.c
	fold_pti86.asm  l_lx_pti.c
	fold_sh86.asm   l_lx_sh.c    l_lx_sh86.asm
	l_lx_sep.c

committer: jreiser <jreiser> 1142305438 +0000
2006-03-14 03:03:58 +00:00
Markus F.X.J. Oberhumer a3097d5e25 Added a dependency.
committer: mfx <mfx> 1142303569 +0000
2006-03-14 02:32:49 +00:00
Markus F.X.J. Oberhumer fd78148558 Fixed typo in disabled code.
committer: mfx <mfx> 1142302679 +0000
2006-03-14 02:17:59 +00:00
Markus F.X.J. Oberhumer a4d79d7375 Small cosmetic changes.
committer: mfx <mfx> 1142302586 +0000
2006-03-14 02:16:26 +00:00
Markus F.X.J. Oberhumer df04e8183d Filter parameters should be called "ft" instead of "fp".
committer: mfx <mfx> 1142301730 +0000
2006-03-14 02:02:10 +00:00
Markus F.X.J. Oberhumer c43c484a62 Re-synced both files a little bit.
committer: mfx <mfx> 1142301586 +0000
2006-03-14 01:59:46 +00:00
Markus F.X.J. Oberhumer 0608c35669 Added some more OBJSTRIP. Small cleanups.
committer: mfx <mfx> 1142298790 +0000
2006-03-14 01:13:10 +00:00
Markus F.X.J. Oberhumer 7dd4d06e26 Added some more calls to $(OBJSTRIP_LINUX_I386) after $(NASM) invocations.
committer: mfx <mfx> 1142288478 +0000
2006-03-13 22:21:18 +00:00
John Reiser 1ee0310b86 silence complaint from ld "cannot find entry symbol _start; defaulting to 10000000"
committer: jreiser <jreiser> 1142285749 +0000
2006-03-13 21:35:49 +00:00
Markus F.X.J. Oberhumer cc0a52038f Rebuilt i386-linux stubs with gcc-4.1.0 for small size decrease.
committer: mfx <mfx> 1142248018 +0000
2006-03-13 11:06:58 +00:00
Markus F.X.J. Oberhumer 6aed1fe231 Updated.
committer: mfx <mfx> 1142247976 +0000
2006-03-13 11:06:16 +00:00
Markus F.X.J. Oberhumer 680608fe18 Portability fix.
committer: mfx <mfx> 1142247872 +0000
2006-03-13 11:04:32 +00:00
Markus F.X.J. Oberhumer ec6acbc602 Small fix to make valid ANSI C again.
committer: mfx <mfx> 1142247837 +0000
2006-03-13 11:03:57 +00:00
John Reiser cb7ee4c5d2 _syscall1nr() for _exit; [still wastes 4 bytes]
committer: jreiser <jreiser> 1142210712 +0000
2006-03-13 00:45:12 +00:00
Markus F.X.J. Oberhumer 88d5798f45 Bumped versions for starting 1.95 development.
committer: mfx <mfx> 1142090576 +0000
2006-03-11 15:22:56 +00:00
454 changed files with 88467 additions and 23714 deletions
-13
View File
@@ -1,13 +0,0 @@
.bzr*
.darcs*
.git*
.hg*
_darcs
B
build*
doxygen
maint
ChangeLog.cvs*
GNUmakefile
MMakefile
TODO.*
+48
View File
@@ -0,0 +1,48 @@
syntax: regexp
^\.bzr
^ChangeLog
^build
^maint
syntax: glob
*.a
*.dll
*.lib
*.py[cdo]
*.so
*.swp
doc/*.1
doc/*.doc
doc/*.html
doc/*.man
doc/*.ps
doc/*.tex
src/GNUmakefile
src/MMakefile
src/compress_nrv*
src/*.mft
src/*.rc
src/*.d
src/*.exe
src/*.map
src/*.o
src/*.obj
src/*.out
src/*.res
src/*.ttp
stub/**MMakefile
stub/**.*-stamp
stub/tmp*/*
stub/**/tmp*/*
stub/tools/armpe/armpe_tester
stub/tools/sstrip/amd64-linux-sstrip
stub/tools/sstrip/i386-linux-sstrip
stub/tools/sstrip/sstrip
+14
View File
@@ -0,0 +1,14 @@
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190
2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194
2ee65b77f9117651e2e5517b2edede23698d73ca RELEASE_196
396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
a916a2fe22de45167d25abcb40008315f415221c RELEASE_201
a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
b0353253b0b3d062eb5adb50d4b665a96620da45 RELEASE_195
b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
+2 -2
View File
@@ -8,8 +8,8 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
Limitations and other things which are not (yet) supported:
+14 -15
View File
@@ -1,8 +1,8 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
@@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
@@ -225,7 +225,7 @@ impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
@@ -278,7 +278,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
@@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -303,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
+26 -22
View File
@@ -1,4 +1,6 @@
# Toplevel Makefile for UPX
#
# UPX toplevel Makefile - needs GNU make 3.80 or better
#
MAKEFLAGS += -rR
.SUFFIXES:
@@ -8,36 +10,38 @@ srcdir = .
top_srcdir = .
# info: src/stub needs GNU make 3.81 and special build tools
BUILD_STUB = 0
ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
BUILD_STUB = 1
endif
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
BUILD_STUB = 1
endif
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.79 3.79.1 3.80),)
BUILD_STUB = 0
endif
default:
@echo "UPX info: please choose a target for 'make'"
all mostlyclean clean distclean maintainer-clean:
$(MAKE) -C src/stub/util/sstrip $@
ifeq ($(BUILD_STUB),1)
$(MAKE) -C src/stub $@
endif
$(MAKE) -C src $@
$(MAKE) -C doc $@
dist: distclean
false
ifneq ($(wildcard CVS/R*),)
CVS_ROOT := $(shell cat CVS/Root)
CVS_REPO := $(shell cat CVS/Repository)
# automatically generate ChangeLog from Mercurial repo
ChangeLog:
ifneq ($(wildcard .hg/data/.),)
hg log --style=changelog > $@
else
@echo "UPX info: no hg repo found"
endif
cvs-info:
@echo 'CVS info: $(CVS_ROOT) $(CVS_REPO)'
cvs-admin-ko:
cvs admin -ko .
cvs -q -z6 update -P -d
# automatically generate ChangeLog from CVS
ChangeLog ChangeLog.cvs:
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
.PHONY: all mostlyclean clean distclean maintainer-clean
.PHONY: dist cvs-info cvs-admin-ko ChangeLog ChangeLog.cvs
.PHONY: default all mostlyclean clean distclean maintainer-clean
.PHONY: ChangeLog
+85 -27
View File
@@ -2,10 +2,68 @@
User visible changes for UPX
==================================================================
[ UNSTABLE BETA VERSION - please see README.1ST for some more info ]
Changes in 2.92 beta (23 Jan 2007):
* new option '--ultra-brute' which tries even more variants
* slightly improved compression ratio for some files when
using '--brute' or '--ultra-brute'
* bug fixes
Changes in 2.91 beta (29 Nov 2006):
* assorted bug fixes
* arm/pe: fix "missing" icon & version info resource problem for wince 5
* win32/pe & arm/pe: added option --compress-icons=3 to compress all icons
Changes in 2.90 beta (08 Oct 2006):
* LZMA algorithm support for most of the 32-bit and 64-bit file formats;
use new option '--lzma' to enable
* new format: BSD/elf386 supporting FreeBSD, NetBSD and OpenBSD
via auto-detection of PT_NOTE or EI_OSABI
* arm/pe: all the NRV compression methods are now supported
(only NRV2D is missing in thumb mode)
* linux/elf386, linux/ElfAMD: remember /proc/self/exe in environment
* major source code changes: the runtime decompression stubs are now
built from internal ELF objects
==================================================================
Changes in 2.03 (07 Nov 2006):
* bvmlinuz/386: fix for kernels not at 0x100000; also allow x86_64
* linux/elf386: work around Linux kernel bug (0-length .bss needs PF_W)
Changes in 2.02 (13 Aug 2006):
* linux/386: work around Linux kernel bug (".bss" requires PF_W)
* linux/ppc32, mach/ppc32: compressed programs now work on a 405 CPU
* vmlinuz/386: fixed zlib uncompression problem on DOS
Changes in 2.01 (06 Jun 2006):
* arm/pe: better DLL support
* dos/exe: device driver support added
* linux/386: Fix --force-execve for PaX, grSecurity, and strict SELinux.
/tmp must support execve(); therefore /tmp cannot be mounted 'noexec'.
* win32/pe & arm/pe: added new option '--keep-resource=' for
excluding selected resources from compression
Changes in 2.00 (27 Apr 2006):
* linux/386: the stub now prints an error message if some strict
SELinux mode does prevent runtime decompression and execution
(for a fully SELinux-compatible but otherwise inferior compression
format you can use the '--force-execve' option)
* linux/386: worked around a problem where certain Linux kernels
clobber the %ebx register during a syscall
* win32/pe: disable filters for files with broken PE headers
Changes in 1.96 beta (13 Apr 2006):
* arm/pe: added filter support
* win32/pe: removed an unnecessary check so that Delphi 2006 and
Digital Mars C++ programs finally are supported
Changes in 1.95 beta (09 Apr 2006):
* arm/pe: added DLL support
* arm/pe: added thumb mode stub support
* arm/pe: added unpacking support
* win32/pe: really worked around R6002 runtime errors
Changes in 1.94 beta (11 Mar 2006):
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
* new format: added support for arm/pe (ARM executables running on WinCE)
* new format: added support for linux elf/amd64
* new format: added support for linux elf/ppc32
@@ -18,8 +76,8 @@ Changes in 1.93 beta (07 Feb 2005):
* vmlinuz/386: fixes to support more kernels
Changes in 1.92 beta (20 Jul 2004):
* win32/pe: added option `--strip-loadconf' to strip the SEH
load config section
* win32/pe: added option '--strip-loadconf' to strip the SEH load
config section [NOTE: this option is obsolete since UPX 1.94]
* win32/pe: try to detect .NET (win32/net) files [not yet supported by UPX]
* vmlinux/386: new format that directly supports building Linux kernels
* source code: now compiles cleanly under Win64
@@ -30,7 +88,7 @@ Changes in 1.91 beta (30 Jun 2004):
* vmlinuz/386: added support for recent kernels
* watcom/le: don't crash on files without relocations
* win32/pe: stricter checks of some PE values
* option `--brute' now implies `--crp-ms=999999'.
* option '--brute' now implies '--crp-ms=999999'.
* source code: much improved portability using ACC, the
Automatic Compiler Configuration
* source code: compile fixes for strict ISO C++ compilers
@@ -39,9 +97,9 @@ Changes in 1.91 beta (30 Jun 2004):
Changes in 1.90 beta (11 Nov 2002):
* implemented several new options for finer compression control:
`--all-methods', `--all-filters' and `--brute'
'--all-methods', '--all-filters' and '--brute'
* ps1/exe: new format - UPX now supports PlayStation One programs
* linux/386: added the option `--force-execve'
* linux/386: added the option '--force-execve'
* vmlinuz/386: better kernel detection and sanity checks
* re-synced with upx 1.24 branch
* documentation updates
@@ -86,9 +144,9 @@ Changes in 1.22 (27 Jun 2002)
Digital Mars C++ and Watcom C++
Changes in 1.21 (01 Jun 2002)
* New option `--crp-ms=' for slightly better compression at the cost
* New option '--crp-ms=' for slightly better compression at the cost
of higher memory requirements during compression.
Try `upx --best --crp-ms=100000'. See the docs for more info.
Try 'upx --best --crp-ms=100000'. See the docs for more info.
* source code: portability fixes
* source code: compile fixes for g++ 3.0 and g++ 3.1
@@ -126,7 +184,7 @@ Changes in 1.05 (24 Jan 2001)
at the unstable UPX 1.1x beta versions for that)
Changes in 1.04 (19 Dec 2000)
* dos/exe: fixed an internal error when using `--no-reloc'
* dos/exe: fixed an internal error when using '--no-reloc'
* win32/pe: fixed a rare bug in the relocation handling code
* some tunings for the default compression level
@@ -134,7 +192,7 @@ Changes in 1.03 (30 Nov 2000)
* linked with a new version of the NRV compression library:
- improved compression ratio a little bit
- overall significantly faster compression
- much faster when using high compression levels like `-9' or `--best'
- much faster when using high compression levels like '-9' or '--best'
- much faster with large files
* atari/tos: added support for FreeMiNT
* the 32-bit DOS version now uses the new CWSDSTUB extender
@@ -142,7 +200,7 @@ Changes in 1.03 (30 Nov 2000)
Changes in 1.02 (13 Sep 2000)
* watcom/le: fixed a problem with the Causeway extender
* win32/pe: don't automatically strip relocs if they seem needed
* support multiple backup generations when using `-k'
* support multiple backup generations when using '-k'
* updated the console screen driver
Changes in 1.01 (09 Apr 2000)
@@ -170,7 +228,7 @@ Changes in 0.99.1 (29 Feb 2000)
Changes in 0.99 (25 Feb 2000)
* FULL SOURCE CODE RELEASED UNDER THE TERMS OF THE GNU GPL
* win32/pe: changed default to `--strip-relocs=1'
* win32/pe: changed default to '--strip-relocs=1'
* dos/com and dos/sys: fixed a bad decompressor problem
* linux/386: the counter for the progress indicator was off by one
@@ -193,7 +251,7 @@ Changes in 0.91 (13 Nov 1999)
* dos/exe: correctly restore cs when uncompressing
Changes in 0.90 (10 Nov 1999)
* all formats: `--overlay=copy' now is the default overlay mode
* all formats: '--overlay=copy' now is the default overlay mode
* improved compression ratio for most files
* win32/pe: uncompression is finally supported
* win32/pe: never compress REGISTRY resources
@@ -203,7 +261,7 @@ Changes in 0.90 (10 Nov 1999)
* win32/pe: somewhat less memory is required during compression
* linux/386: fixed compression of scripts which was broken since 0.71
* linux/386: more FreeBSD compatibility issues
* changed option: `-i' now prints some more details during compression
* changed option: '-i' now prints some more details during compression
(not finished yet)
Changes in 0.84 (04 Oct 1999)
@@ -219,7 +277,7 @@ Changes in 0.83 (17 Sep 1999)
Changes in 0.82 (16 Aug 1999)
* dos/exe: fixed a decompressor bug which could cause crash on some files
* linux/386: section headers are now stripped from the stub so that
`strip' won't ruin a compressed file any longer
'strip' won't ruin a compressed file any longer
* wc/le: support for stack not in the last object disabled again
* win32/pe: removed some unneeded data
@@ -228,32 +286,32 @@ Changes in 0.81 (04 Aug 1999)
* dos/com: fixed an internal error that could happen with very small files
Changes in 0.80 (03 Aug 1999)
* you can set some default options in the environment var `UPX'
* you can set some default options in the environment var 'UPX'
* dos/com: the decompressor stub now checks for enough free memory
* dos/exe: decompressor rewritten, some bugs are fixed
* dos/exe: new option `--no-reloc': no relocation data is put into
* dos/exe: new option '--no-reloc': no relocation data is put into
the DOS header
* tmt/adam: added support for more stubs, detect already packed files
* tmt/adam: new option `--copy-overlay'
* tmt/adam: new option '--copy-overlay'
* wc/le: reduced memory requirement during uncompression
* wc/le: support files which do not contain their stack in the last object
* wc/le: fixed a bug which could cause a crash, improved relocation
handling
* wc/le: new option `--copy-overlay'
* win32/pe: `--compress-icons=2' is now the default
* wc/le: new option '--copy-overlay'
* win32/pe: '--compress-icons=2' is now the default
* win32/pe: even better TLS support
* win32/pe: versioninfo works on NT
* win32/pe: import by ordinal from kernel32.dll works
* win32/pe: other import improvements: importing a nonexistant DLL
results in a usual Windows message, importing a nonexistant function
results in program exit (instead of crash ;-)
* win32/pe: new option: `--compress-resources=0'
* win32/pe: new option: '--compress-resources=0'
* win32/pe: reduced memory requirement during uncompression, some
files might even require LESS memory when they're compressed
* win32/pe: TYPELIBs should work now
* win32/pe: improved relocation handling, 16-bit relocations should work
* win32/pe: new option `--strip-relocs' (only if you know what you are doing)
* win32/pe: new option `--copy-overlay'
* win32/pe: new option '--strip-relocs' (only if you know what you are doing)
* win32/pe: new option '--copy-overlay'
* important internal changes: now the stubs are built at runtime
Changes in 0.72 (12 May 1999)
@@ -267,20 +325,20 @@ Changes in 0.72 (12 May 1999)
* linux/386: minor decompressor stub updates, nicer progress bar
Changes in 0.71 (19 Apr 1999)
* dos/exe: added option `--no-overlay'
* dos/exe: added option '--no-overlay'
* linux/386: various improvements in the stub, most notably the
overhead for an extra cleanup process has been removed
* win32/pe: added support for export forwarders
* win32/pe: added support for DLLs without entry point or imports
* win32/pe: yet another .bss fix
* win32/pe: new option `--compress-icons=2': compress all icons
* win32/pe: new option '--compress-icons=2': compress all icons
which are not in the first icon directory
* win32/pe: rearranged stub to avoid false alerts from some virus scanners
Changes in 0.70 (30 Mar 1999)
* added support for linux/386 executables
* improved compression ratio quite a bit
* added new compression level `--best' to squeeze out even some more bytes
* added new compression level '--best' to squeeze out even some more bytes
* win32/pe: TLS support is much better now
* win32/pe: --compress-icons=0 should now work as well
* the usual minor fixes for win32/pe
+3 -6
View File
@@ -8,8 +8,8 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
Here are some possible projects from which you can choose if you'd like to
@@ -56,8 +56,6 @@ Existing formats:
- dos/exe: implement filter support
- dos/sys: add support for sys/exe combos
- linux/i386:
- use the new assembly preprocessor stuff (ie. process the file
headers internally)
@@ -68,8 +66,7 @@ Existing formats:
- win32/pe: display a nice dialog box in the stub in case
of problems (like importing a DLL or function fails)
- win32/pe: finer control over resource compression, per section
compression
- win32/pe: per section compression
Compression ratio:
+9 -33
View File
@@ -8,36 +8,11 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
WARNING - UNSTABLE BETA VERSION
===============================
All versions 1.9x are unstable beta releases - use them only for testing,
and never distribute a program that is packed with them !
There will be hidden bugs. Really.
The current stable release is 1.25, and the next stable release
will be called version 2.00.
The main news since 1.25 are:
- slightly better compression using the new NRV2E algorithm
- new options for compression tuning (e.g. `--brute')
- support for bootable Linux kernels ("vmlinuz/386")
- support for Linux kernel building ("vmlinux/386")
- direct Linux ELF-to-memory decompression ("linux/elf386") and
shell-to-memory decompression ("linux/sh386")
- support for arm/WinCE ("arm/pe") exes
- support for mach/ppc32
- support for Linux elf/ppc32
- support for Linux elf/amd64
- support for playstation exes ("ps1/exe")
- lots of new bugs ;-) take care
WELCOME
=======
@@ -62,7 +37,7 @@ and run exactly as before, with no runtime or memory penalty for most
of the supported formats.
UPX supports a number of different executable formats, including
Windows 95/98/ME/NT/2000/XP programs and DLLs, DOS programs,
Windows 95/98/ME/NT/2000/XP/CE programs and DLLs, DOS programs,
and Linux executables and kernels.
UPX is free software distributed under the term of the GNU General
@@ -80,8 +55,8 @@ UPX aims to be Commercial Quality Freeware.
SHORT DOCUMENTATION
===================
`upx program.exe' will compress a program or DLL. For best compression
results try `upx --best program.exe'.
'upx program.exe' will compress a program or DLL. For best compression
results try 'upx --brute program.exe'.
Please see the file UPX.DOC for the full documentation. The files
NEWS and BUGS also contain various tidbits of information.
@@ -95,7 +70,7 @@ UPX comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
Having said that, we think that UPX is quite stable now. Indeed we
have compressed lots of files without any problems. Also, the
current version has undergone several months of beta testing -
actually it's more than 4 years since our first public beta.
actually it's almost 8 years since our first public beta.
This is the first production quality release, and we plan that future
releases will be backward compatible with this version.
@@ -133,8 +108,9 @@ THE FUTURE
COPYRIGHT
=========
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
This program may be used freely, and you are welcome to
redistribute it under certain conditions.
+13 -20
View File
@@ -8,31 +8,24 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
WARNING - UNSTABLE BETA VERSION
===============================
All versions 1.9x are unstable beta releases - use them only for testing,
and never distribute a program that is packed with them !
There will be hidden bugs. Really.
The current stable release is 2.02, and the next stable release
will be called version 3.00.
The current stable release is 1.25, and the next stable release
will be called version 2.00.
The main news since 1.25 are:
- slightly better compression using the new NRV2E algorithm
- new options for compression tuning (e.g. `--brute')
- support for bootable Linux kernels ("vmlinuz/386")
- support for Linux kernel building ("vmlinux/386")
- direct Linux ELF-to-memory decompression ("linux/elf386") and
shell-to-memory decompression ("linux/sh386")
- support for arm/WinCE ("arm/pe") exes
- support for mach/ppc32
- support for Linux elf/ppc32
- support for Linux elf/amd64
- support for playstation exes ("ps1/exe")
- lots of new bugs ;-) take care
MAJOR NEWS IN UPX 3
===================
The main news since UPX 2 are:
* new format: added support for linux elf/arm
* better compression using the LZMA algorithm (option '--lzma')
+20 -34
View File
@@ -69,53 +69,40 @@ Tools needed to build/modify the UPX sources
- A C++ compiler supporting inner classes, templates, exceptions
and RTTI.
- GNU make 3.80 for Win32
http://www.cygwin.com/
- GNU make 3.80 for DOS
http://www.delorie.com/djgpp/
- GNU make 3.80 or better (GNU make 3.81 recommened).
To compile the packer sources
-----------------------------
set the environment variable UCLDIR to point to your UCL installation, e.g.
Set the environment variable UPX_UCLDIR to point to your
UCL build directory, e.g.
set UCLDIR=c:\src\ucl-1.03 (DOS / Windows)
export UCLDIR=$HOME/local/src/ucl-1.03 (Unix)
set UPX_UCLDIR=c:\src\ucl-1.03 (DOS / Windows)
export UPX_UCLDIR=$HOME/local/src/ucl-1.03 (Unix)
then type
Set the environment variable UPX_LZMADIR to point to your
to your unpacked lzma443.tar.bz2 source directory, e.g.
make target=linux # linux
make target=djgpp2 # dos32 - djgpp2
make target=cygwin # win32 - cygwin 1.3.x
make target=mingw32 # win32 - mingw32
make target=no-cygwin # win32 - mingw32 as included in cygwin
export UPX_LZMADIR=$HOME/local/src/lzma-4.43 (Unix)
Finally type
make
If you want to modify the stub sources you'll also need
-------------------------------------------------------
- Nasm 0.98.38 - the Netwide Assembler
http://upx.sourceforge.net/download/tools/
http://sourceforge.net/projects/nasm/
- GNU make 3.81 or better
http://savannah.gnu.org/projects/make/
- A68K - a 68000 macro assembler
http://upx.sourceforge.net/download/tools/
- Perl & Python
- djasm - an assembler for the djgpp stub
http://upx.sourceforge.net/download/tools/
- A number of cross-assemblers and cross-compilers - precompiled
binaries for i386-linux hosts are available from
http://sourceforge.net/project/showfiles.php?group_id=2331
- Perl 5.6 or better
- Linux (for the linux/386 stubs)
- Other cross compilers targeted at the following architectures:
- powerpc-750-linux-gnu
- x86_64-unknown-linux-gnu
- arm-wince-pe
- ASM5900 - a MIPS R3000 assembler
Misc. notes
-----------
@@ -129,9 +116,6 @@ Misc. notes
stream.
- Use gcc extensions and other compiler specific stuff only through
macros.
- Keep in mind that it should be possible to build UPX on braindead
file systems (FAT). Don't use long file names or other things
that break building under plain DOS.
***
@@ -156,3 +140,5 @@ Patches/Contributions
diff -uNr olddirectory newdirectory
# vi:ts=4:et
+4 -4
View File
@@ -8,8 +8,8 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
.___.. .
@@ -39,12 +39,12 @@ Ice
for debugging the PE headersize problem down
Joergen Ibsen <jibz@hotmail.com> and d'b
for the relocation & address optimization ideas
John F. Reiser <jreiser@BitWagon.com>
for the new Linux executable formats
John S. Fine <johnfine@erols.com>
for the new version of the dos/exe decompressor
Lukundoo <Lukundoo@softhome.net>
for beta testing
Michael Devore
for initial dos/exe device driver support
Oleg V. Volkov <rover@lglobus.ru>
for various FreeBSD specific informations
The Owl & G-RoM
+1 -10
View File
@@ -1,4 +1,4 @@
UPX TODO list. Last updated 2006-03-11.
UPX TODO list. Last updated 2006-12-08.
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
@@ -41,8 +41,6 @@ ALL FORMATS
- implement `--cpu=486' option to use bswap on the 32-bit formats
(if cpu >= 486)
- consider removing "or ebp,-1" when not needed
FORMAT DJGPP2/COFF
==================
@@ -86,10 +84,6 @@ FORMAT WATCOM/LE
- handle holes in the file
- implement compressWithFilters()
- add a call to verifyOverlappingDecompression()
FORMAT WIN16/NE
===============
@@ -105,9 +99,6 @@ FORMAT WIN32/PE
- decrease runtime memory overhead
2 - easy - mfx + ml) new switch(es) : do not compress resource types x,y,z
or resource names a,b,c
3 - difficult) don't compress the BSS section and other holes.
4 - medium - ml) fix when objectalign < 0x1000
-6
View File
@@ -1,6 +0,0 @@
upx.1
upx.doc
upx.html
upx.man
upx.ps
upx.tex
+53 -36
View File
@@ -1,34 +1,51 @@
#
# UPX doc Makefile - needs GNU make 3.80 or better
#
MAKEFLAGS += -rR
.SUFFIXES:
SHELL = /bin/sh
top_srcdir = ..
# internal make variables
comma := ,
empty :=
space := $(empty) $(empty)
tab := $(empty) $(empty)
PACKAGE = upx
VERSION_DATE = 11 Mar 2006
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
# update $PATH for our special stub build tools
ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
export PATH := $(HOME)/local/bin/bin-upx:$(PATH)
endif
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
export PATH := $(HOME)/bin/bin-upx:$(PATH)
endif
TRIMSPACE = cat
TRIMSPACE = sed -e 's/ *$$//'
# /***********************************************************************
# //
# ************************************************************************/
top_srcdir ?= ..
PACKAGE = upx
VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
RTRIM := sed -e 's/[ $(tab)]*$$//'
DETAB2 := sed -e 's/$(tab)/ /g'
BUILT_SOURCES = upx.1 upx.doc upx.html upx.man upx.ps upx.tex
BUILT_SOURCES = upx.1 upx.doc upx.html
###
###
### targets
###
all: $(BUILT_SOURCES)
mostlyclean:
-rm -f $(BUILT_SOURCES) pod2htm*
clean: mostlyclean
distclean: clean
maintainer-clean: distclean
.SUFFIXES: .1 .doc .html .man .pod .ps .tex .texi
mostlyclean clean distclean maintainer-clean:
rm -f $(BUILT_SOURCES) pod2htm*
.PHONY: all mostlyclean clean distclean maintainer-clean
@@ -37,32 +54,32 @@ maintainer-clean: distclean
### rules
###
.pod.1:
pod2man --center=" " --release="$(PACKAGE) $(VERSION)" --date="$(VERSION_DATE)" $< | $(TRIMSPACE) > $@
.SUFFIXES: .1 .doc .html .man .pod .ps .tex
.pod.html:
### pod2html $< | $(TRIMSPACE) > $@
pod2html --noindex $< | $(TRIMSPACE) > $@
@-rm -f pod2htm*
%.1 : %.pod
pod2man --center=" " --release="$(PACKAGE) $(VERSION)" --date="$(VERSION_DATE)" $< | $(RTRIM) > $@
.pod.tex:
%.doc : %.pod
pod2text < $< | $(RTRIM) > $@
%.html : %.pod
pod2html --noindex $< | $(RTRIM) | $(DETAB2) > $@
@rm -f pod2htm*
%.man : %.1
nroff -man $< | $(RTRIM) > $@
%.ps : %.1
groff -man $< | $(RTRIM) > $@
%.tex : %.pod
pod2latex $<
.pod.doc:
pod2text < $< | $(TRIMSPACE) > $@
.1.man:
nroff -man $< | $(TRIMSPACE) > $@
.1.ps:
groff -man $< | $(TRIMSPACE) > $@
###
### dependencies
###
$(BUILT_SOURCES): $(top_srcdir)/src/version.h Makefile
.NOEXPORT:
$(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
.DELETE_ON_ERROR: $(BUILT_SOURCES)
+18 -2
View File
@@ -1,5 +1,5 @@
Decompressing ELF Directly to Memory on Linux/x86
Copyright 2000 John F. Reiser jreiser@BitWagon.com
Copyright (C) 2000-2007 John F. Reiser jreiser@BitWagon.com
References:
<elf.h> definitions for the ELF file format
@@ -17,7 +17,7 @@ program itself. So, the decompressor program (which contains the
compressed version of the original executable) must have the same
brk() as the original executable. So, the second PT_LOAD
ELF "segment" of the compressed program is used only to set the brk(0).
See src/p_lx_elf.cpp, function PackLinuxI386elf::patchLoader().
See src/p_lx_elf.cpp, function PackLinuxElf32::generateElfHdr.
All of the decompressor's code, and all of the compressed image
of the original executable, reside in the first PT_LOAD of the
decompressor program.
@@ -63,3 +63,19 @@ clear the free portion of the stack (to compensate for ld-linux.so.2
assuming that its automatic stack variables are initialized to zero),
and remove (all but 4 bytes of) the decompression program (and
compressed executable) from the address space.
Because the UPX runtime stub removes all traces of the compressed file
from the address space, then the Linux kernel erases the symlink
/proc/self/exe. Linux stores the pathname argument that was specified
to execve() immediately after the '\0' which terminates the character
string of the last environment variable [as of execve()]. This is true
for at least all Linux 2.6, 2.4, and 2.2 kernels. The pathname is not
"bound" to the file as strongly as /proc/self/exe (the file may be changed
without affecting the pathname), but the pathname does provide some
information. The pathname may be relative to the working directory,
so look before any chdir().
The Elf formats for Linux add an environment variable named " " [three
spaces] which saves the results of readlink("/proc/self/exe",,) before
the runtime stub unmaps all its pages. As of 2006-10-03 this works
for linux/elf386 and linux/ElfAMD.
+26 -65
View File
@@ -2,16 +2,8 @@ This documentation is written for those brave souls who want to
understand and/or modify the UPX assembly stubs - the small snippets
that do the runtime decompression when a compressed program is started.
So, how the runtime stub/loader generation works?
You might have already noticed that for some file formats the loaders
are quite simple (linux/i386 & tos) while in the other cases the
loaders look very suspicious: they're full of `%ifdef's and contain
loads of cryptic comments like `__PERELOC2__'.
If you look at the C++ source files, however you can notice that these
comment strings (without the leading and trailing underscores) are used
in the following way:
If you look at the C++ source files, you can find code fragments like
this:
addLoader("PEMAIN20",
ih.entry ? "PEDOJUMP" : "PERETURN",
@@ -19,71 +11,40 @@ in the following way:
NULL
);
Basically that's all you have to know: when you want to add a section
of assembly code to the runtime loader, you just write
linker->defineSymbol("original_entry", ih.entry);
l_foo.asm
---------
;__FOOBAR00__
and in the assembly files fragments like this:
xor eax, eax
label1:
jmps label1
section PEISDLL1
cmpb [esp + 8], 1
jnz reloc_end_jmp
;__FOOBARZZ__
section PEMAIN21
reloc_end_jmp:
p_foo.cpp
---------
section PERETURN
xor eax, eax
inc eax
ret 0x0C
section PEDOJUMP
jmp original_entry
addLoader("FOOBAR00", NULL);
This will add the assembly section starting from __FOOBAR00__ and ending
before __FOOBARZZ__ to the loader. You can add an %ifdef - %endif pair
before these comments if you wish - but these conditionals will NOT be
seen by the assembler, they are just syntactic sugar to make the code a
little bit more readable and understandable. (Note however, that only
%ifdefs which are started on the 1st column are removed by the upx
assembly preprocessor program, so you can still use preprocessor
conditionals if you wish - just write them starting from the 2nd
column.)
Everything works as you would expect. If you want to add the code
fragment which is in `section PERETURN' to the runtime stub, then
simply use `addLoader("PERETURN")' in the C++ source.
That's nice, you could say, but how cross section jumps and calls are
handled? Well, that is the nicest part of this stuff - they are handled
automatically. All you have to do is to add the required sections to the
loader using `addLoader()' and the rest is done by upx. It will resolve
every conditional or unconditional jumps or subrutine calls for you.
every conditional or unconditional jumps or subroutine calls for you.
This functionality (we could say it's a simple linker) is achived by the
assembly preprocessor (src/stub/scripts/app.pl) and a little C++ module
(src/linker.cpp). And of course NASM - the Netwide Assembler. You can
see what's going on behind the scenes - just do:
You can also use (undefined) symbols in the assembly for values that
can only be computed during compression time (like `original_entry').
These symbols can be defined later in C++ using
cd src/stubs
make maintainer-clean
make all
linker->defineSymbol("xx", yy)
This will rebuild all the loaders - and keep the temporary files (*.as[xy])
which are seen by the assembler.
Currently this loader/stub building method only works with ix86
assembly - both app.pl and linker.cpp heavily rely on this when dealing
with cross section references.
And finally some important features/requirements you should be aware of:
- as previously stated - preprocessor conditionals starting on the 1st
column are removed by app.pl
- sections are separated by comments in the form `;__X1234567__'
- jumps are recognized by searching for a word which starts with `j'
and followed by a label - this also means that `jmp short label1'
will NOT be recognized (but you can use a macro called `jmps' for it
by adding `%define jmps jmp short' to the beginning of the file)
- at the end of the file you need something like this
eof:
; __XTHEENDX__
section .data
dd -1
dw eof
That's all for now.
This functionality (we could say it's a simple linker) is achived by
compiling the assembly into an ELF object file which a little C++
module (src/linker.cpp) can interpret and work with.
+56 -51
View File
@@ -12,9 +12,9 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
=head1 ABSTRACT
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
The Ultimate Packer for eXecutables
Copyright (c) 1996-2007 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
B<UPX> is a portable, extendable, high-performance executable packer for
@@ -75,9 +75,10 @@ B<UPX> is a versatile executable packer with the following features:
* rtm32/pe
* tmt/adam
* vmlinuz/386 [bootable Linux kernel]
* vmlinux/386
* watcom/le (supporting DOS4G, PMODE/W, DOS32a and CauseWay)
* win32/pe
* arm/pe
* win32/pe (exe and dll)
* arm/pe (exe and dll)
* linux/elfamd64
* linux/elfppc32
* mach/elfppc32
@@ -137,6 +138,9 @@ B<--help>: prints the help
B<--version>: print the version of B<UPX>
B<--exact>: when compressing, require to be able to get a byte-identical file
after decompression with option B<-d>
[ ...to be written... - type `B<upx --help>' for now ]
@@ -171,38 +175,13 @@ Note that compression level B<--best> can be somewhat slow for large
files, but you definitely should use it when releasing a final version
of your program.
Quick start for achieving the best compression ratio:
=over 4
Try B<upx --brute myfile.exe>.
=back
Details for achieving the best compression ratio:
Quick info for achieving the best compression ratio:
=over 4
=item *
Use the compression level B<--best>.
=item *
Try one or both of the options B<--all-methods> and B<--all-filters>.
=item *
Try the option B<--crp-ms=NUMBER>. This uses more memory during compression
to achieve a (slightly) better compression ratio.
NUMBER must be a decimal value from 10000 to 999999, inclusive.
The default value is 10000 (ten thousand).
=item *
Info: the option B<--brute> is an abbrevation for the options
B<S<--best> S<--all-methods> S<--all-filters> S<--crp-ms=999999>>.
Try B<upx --brute myfile.exe> or even B<upx --ultra-brute myfile.exe>.
=item *
@@ -339,9 +318,6 @@ Extra options available for this executable format:
=head2 NOTES FOR DOS/SYS
You can only compress plain sys files, sys/exe (two in one)
combos are not supported.
Compressed programs only work on a 286+.
Packed programs will be byte-identical to the original after uncompression.
@@ -701,19 +677,20 @@ nostalgic feelings of one of the authors.
Packed programs will be byte-identical to the original after uncompression,
until further notice.
Maximum uncompressed size: ~1998848 bytes.
Maximum uncompressed size: ~1.89 / ~7.60 Mbytes.
Notes:
- UPX creates as default a 'CD-Rom only' PS1/PS2 compatible executable.
For transfer between client/target use options below.
- UPX creates as default a suitable executable for CD-Mastering
and console transfer. For a CD-Master main executable you could also try
the special option "--boot-only" as descriped below.
- Normally the packed files use the same memory areas like the uncompressed
versions, so they will not override other memory areas while unpacking.
If this isn't possible UPX will abort showing a 'packed data overlap'
error. With the "--force" option UPX will set a few 'bytes higher' loading
offset for the packed file, but this isn't a real problem if it is a
single or boot-only executable.
error. With the "--force" option UPX will relocate the loading address
for the packed file, but this isn't a real problem if it is a single or
the main executable.
Extra options available for this executable format:
@@ -722,15 +699,19 @@ Extra options available for this executable format:
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--boot-only The format will only run from a CD and may slightly
improves the compression ratio. The decompression
routines are faster than default ones.
But it cannot be used for host/client transfer !
--8-bit Uses 8 bit size compression [default: 32 bit]
--8mb-ram PSone has 8 MB ram available [default: 2 MB]
--boot-only This format is for main exes and CD-Mastering only !
It may slightly improve the compression ratio,
decompression routines are faster than default ones.
But it cannot be used for console transfer !
--no-align This option disables CD mode 2 data sector format
alignment. May slightly improves the compression ratio,
but the compressed executable will not boot from a CD.
Use it for client/target transfer only !
Use it for console transfer only !
@@ -840,12 +821,19 @@ smaller, but it's still there.
If you're running executables from network, then compressed programs
will load faster, and require less bandwidth during execution.
DLLs are supported.
DLLs are supported. But UPX compressed DLLs can not share common data and
code when they got used by multiple applications. So compressing msvcrt.dll
is a waste of memory, but compressing the dll plugins of a particular
application may be a better idea.
Screensavers are supported, with the restriction that the filename
must end with ".scr" (as screensavers are handled slightly different
than normal exe files).
UPX compressed PE files have some minor memory overhead (usually in the
10 - 30 kbytes range) which can be seen by specifying the "-i" command
line switch during compression.
Extra options available for this executable format:
--compress-exports=0 Don't compress the export section.
@@ -862,9 +850,26 @@ Extra options available for this executable format:
--compress-icons=1 Compress all but the first icon.
--compress-icons=2 Compress all icons which are not in the
first icon directory. [DEFAULT]
--compress-icons=3 Compress all icons.
--compress-resources=0 Don't compress any resources at all.
--keep-resource=list Don't compress resources specified by the list.
The members of the list are separated by commas.
A list member has the following format: I<type[/name]>.
I<Type> is the type of the resource. Standard types
must be specified as decimal numbers, user types can be
specified by decimal IDs or strings. I<Name> is the
identifier of the resource. It can be a decimal number
or a string. For example:
--keep-resource=2/MYBITMAP,5,6/12345
UPX won't compress the named bitmap resource "MYBITMAP",
it leaves every dialog (5) resource uncompressed, and
it won't touch the string table resource with identifier
12345.
--force Force compression even when there is an
unexpected value in a header field.
Use with care.
@@ -921,13 +926,13 @@ Please report all bugs immediately to the authors.
=head1 COPYRIGHT
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
Copyright (C) 2000-2007 John F. Reiser
Copyright (C) 2002-2006 Jens Medoch
Copyright (C) 2002-2007 Jens Medoch
This program may be used freely, and you are welcome to
redistribute it under certain conditions.
View File
-3220
View File
File diff suppressed because it is too large Load Diff
-19
View File
@@ -1,19 +0,0 @@
*.0??
*.d
*.dat
*.idb
*.img
*.map
*.raw
*.rc
*.rel
*.res
*.pdb
*.out
*.upx
.gdbinit
GNUmakefile
MMakefile
compress_nrv.*
upx
version1*.h
+36 -9
View File
@@ -17,9 +17,18 @@ endif
ifeq ($(CXX),)
CXX = g++
endif
ifeq ($(CXX),g++)
CXXFLAGS += -O2 -MMD
ifeq ($(firstword $(CXX)),g++)
USE_GNUC ?= 1
endif
ifeq ($(USE_GNUC),1)
CXXFLAGS += -MMD
ifeq ($(DEBUG),1)
CXXFLAGS += -O0 -g
else
CXXFLAGS += -O2
endif
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
##CXXFLAGS += -Wshadow
endif
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
CXXLD ?= $(CXX)
@@ -28,17 +37,24 @@ exeext ?= .out
libext ?= .a
objext ?= .o
# we need UCL and zlib - you can set envvar UCLDIR
ifneq ($(wildcard $(UCLDIR)/include/ucl/ucl.h),)
INCLUDES += -I$(UCLDIR)/include
LIBS += $(addprefix -L,$(dir $(wildcard $(UCLDIR)/libucl$(libext) $(UCLDIR)/src/.libs/libucl$(libext))))
endif
LIBS += -lucl -lz
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
# we need UCL and zlib - you can set envvar UPX_UCLDIR
ifneq ($(wildcard $(UPX_UCLDIR)/include/ucl/ucl.h),)
INCLUDES += -I$(UPX_UCLDIR)/include
LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext))))
endif
LIBS += -lucl -lz
# you should set envvar UPX_LZMADIR to point to your unpacked lzma443.tar.bz2
ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),)
DEFS += -DWITH_LZMA
INCLUDES += -I$(UPX_LZMADIR)
endif
all: upx$(exeext)
.DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS)
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
$($(notdir $@).PRE_LINK_STEP)
@@ -48,6 +64,17 @@ upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
%.o : %.cpp
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
ifeq ($(USE_GNUC),1)
##compress_lzma$(objext) : CXXFLAGS += -O3 -fomit-frame-pointer
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-unused
##compress_lzma$(objext) : CXXFLAGS += -Wno-error
endif
mostlyclean clean distclean maintainer-clean:
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)
+198 -20
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -183,88 +183,153 @@ inline void set_le64(void *p, acc_uint64l_t v)
// get signed values, i.e. sign-extend
**************************************************************************/
inline int sign_extend(int v, int bits)
inline int sign_extend(unsigned v, unsigned bits)
{
const unsigned sign_bit = 1u << (bits - 1);
v |= 0u - (v & sign_bit);
return v;
v &= sign_bit | (sign_bit - 1);
//v = (v ^ sign_bit) - sign_bit;
v |= 0 - (v & sign_bit);
return (int) v;
}
inline acc_int64l_t sign_extend(acc_int64l_t v, int bits)
inline acc_int64l_t sign_extend(acc_uint64l_t v, unsigned bits)
{
const acc_uint64l_t sign_bit = ACC_UINT64_C(1) << (bits - 1);
v |= ACC_UINT64_C(0) - (v & sign_bit);
return v;
v &= sign_bit | (sign_bit - 1);
//v = (v ^ sign_bit) - sign_bit;
v |= 0 - (v & sign_bit);
return (acc_int64l_t) v;
}
inline int get_be16_signed(const void *p)
{
int v = get_be16(p);
unsigned v = get_be16(p);
return sign_extend(v, 16);
}
inline int get_be24_signed(const void *p)
{
int v = get_be24(p);
unsigned v = get_be24(p);
return sign_extend(v, 24);
}
inline int get_be32_signed(const void *p)
{
int v = get_be32(p);
unsigned v = get_be32(p);
return sign_extend(v, 32);
}
inline acc_int64l_t get_be64_signed(const void *p)
{
acc_int64l_t v = get_be64(p);
acc_uint64l_t v = get_be64(p);
return sign_extend(v, 64);
}
inline int get_le16_signed(const void *p)
{
int v = get_le16(p);
unsigned v = get_le16(p);
return sign_extend(v, 16);
}
inline int get_le24_signed(const void *p)
{
int v = get_le24(p);
unsigned v = get_le24(p);
return sign_extend(v, 24);
}
inline int get_le32_signed(const void *p)
{
int v = get_le32(p);
unsigned v = get_le32(p);
return sign_extend(v, 32);
}
inline int get_le64_signed(const void *p)
inline acc_int64l_t get_le64_signed(const void *p)
{
acc_int64l_t v = get_le64(p);
acc_uint64l_t v = get_le64(p);
return sign_extend(v, 64);
}
/*************************************************************************
// swab (bswap)
**************************************************************************/
inline unsigned acc_swab16(unsigned v)
{
return ((v & 0x00ff) << 8) |
((v & 0xff00) >> 8);
}
inline unsigned acc_swab32(unsigned v)
{
return ((v & 0x000000ff) << 24) |
((v & 0x0000ff00) << 8) |
((v & 0x00ff0000) >> 8) |
((v & 0xff000000) >> 24);
}
inline unsigned acc_swab16p(const acc_uint16e_t *p)
{
return acc_swab16(*p);
}
inline unsigned acc_swap32p(const acc_uint32e_t *p)
{
return acc_swab32(*p);
}
inline void acc_swab16s(acc_uint16e_t *p)
{
*p = acc_swab16(*p);
}
inline void acc_swab32s(acc_uint32e_t *p)
{
*p = acc_swab32(*p);
}
inline void acc_ua_swab16s(void *p)
{
set_be16(p, get_le16(p));
}
inline void acc_ua_swab32s(void *p)
{
set_be32(p, get_le32(p));
}
/*************************************************************************
// classes for portable unaligned access
//
// Important: these classes must be PODs (Plain Old Data), i.e. no
// constructor, no destructor, no virtual functions and no default
// assignment operator, and all fields must be public(!).
//
// [Actually we _can_ use a safe non-POD subset, but for this we need
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
**************************************************************************/
struct BE16
{
unsigned char d[2];
//inline BE16() { }
//BE16(unsigned v) { set_be16(d, v); }
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
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; }
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; }
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; }
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; }
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
operator unsigned () const { return get_be16(d); }
}
@@ -275,13 +340,19 @@ struct BE32
{
unsigned char d[4];
//inline BE32() { }
//BE32(unsigned v) { set_be32(d, v); }
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
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; }
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; }
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; }
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; }
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
operator unsigned () const { return get_be32(d); }
}
@@ -292,13 +363,19 @@ struct BE64
{
unsigned char d[8];
//inline BE64() { }
//BE64(acc_uint64l_t v) { set_be64(d, v); }
BE64& operator = (acc_uint64l_t v) { set_be64(d, v); return *this; }
BE64& operator += (acc_uint64l_t v) { set_be64(d, get_be64(d) + v); return *this; }
BE64& operator -= (acc_uint64l_t v) { set_be64(d, get_be64(d) - v); return *this; }
BE64& operator *= (acc_uint64l_t v) { set_be64(d, get_be64(d) * v); return *this; }
BE64& operator /= (acc_uint64l_t v) { set_be64(d, get_be64(d) / v); return *this; }
BE64& operator &= (acc_uint64l_t v) { set_be64(d, get_be64(d) & v); return *this; }
BE64& operator |= (acc_uint64l_t v) { set_be64(d, get_be64(d) | v); return *this; }
BE64& operator ^= (acc_uint64l_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
BE64& operator <<= (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); }
}
@@ -309,13 +386,19 @@ struct LE16
{
unsigned char d[2];
//inline LE16() { }
//LE16(unsigned v) { set_le16(d, v); }
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
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; }
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; }
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; }
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; }
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
operator unsigned () const { return get_le16(d); }
}
@@ -326,13 +409,19 @@ struct LE32
{
unsigned char d[4];
//inline LE32() { }
//LE32(unsigned v) { set_le32(d, v); }
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
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; }
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; }
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; }
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; }
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
operator unsigned () const { return get_le32(d); }
}
@@ -343,13 +432,19 @@ struct LE64
{
unsigned char d[8];
//inline LE64() { }
//LE64(acc_uint64l_t v) { set_le64(d, v); }
LE64& operator = (acc_uint64l_t v) { set_le64(d, v); return *this; }
LE64& operator += (acc_uint64l_t v) { set_le64(d, get_le64(d) + v); return *this; }
LE64& operator -= (acc_uint64l_t v) { set_le64(d, get_le64(d) - v); return *this; }
LE64& operator *= (acc_uint64l_t v) { set_le64(d, get_le64(d) * v); return *this; }
LE64& operator /= (acc_uint64l_t v) { set_le64(d, get_le64(d) / v); return *this; }
LE64& operator &= (acc_uint64l_t v) { set_le64(d, get_le64(d) & v); return *this; }
LE64& operator |= (acc_uint64l_t v) { set_le64(d, get_le64(d) | v); return *this; }
LE64& operator ^= (acc_uint64l_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
LE64& operator <<= (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); }
}
@@ -399,11 +494,47 @@ template <class T> T* operator + (const LE64& v, T* ptr);
template <class T> T* operator - (T* ptr, const LE64& v);
/*************************************************************************
// global overloads
**************************************************************************/
#if 1 && !defined(ALIGN_DOWN)
inline unsigned ALIGN_DOWN(unsigned a, const LE32& b) { return ALIGN_DOWN(a, (unsigned) b); }
inline unsigned ALIGN_DOWN(const LE32& a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }
inline unsigned ALIGN_UP (unsigned a, const LE32& b) { return ALIGN_UP (a, (unsigned) b); }
inline unsigned ALIGN_UP (const LE32& a, unsigned b) { return ALIGN_UP ((unsigned) a, b); }
#endif
#if !defined(UPX_MAX)
inline unsigned UPX_MAX(unsigned a, const BE16& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const BE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const BE16& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const BE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const BE32& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const BE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const BE32& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const BE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const LE16& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const LE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const LE16& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const LE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const LE32& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const LE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const LE32& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const LE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
#endif
/*************************************************************************
// misc
**************************************************************************/
// for use with qsort()
extern "C" {
int __acc_cdecl_qsort be16_compare(const void *, const void *);
int __acc_cdecl_qsort be24_compare(const void *, const void *);
int __acc_cdecl_qsort be32_compare(const void *, const void *);
@@ -420,6 +551,7 @@ int __acc_cdecl_qsort le16_compare_signed(const void *, const void *);
int __acc_cdecl_qsort le24_compare_signed(const void *, const void *);
int __acc_cdecl_qsort le32_compare_signed(const void *, const void *);
int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
} // extern "C"
// just for testing...
@@ -430,7 +562,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
# ifndef LE16
# define LE16 LE16_unaligned
# endif
# ifndef LE16
# ifndef LE32
# define LE32 LE32_unaligned
# endif
#endif
@@ -440,7 +572,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
# ifndef LE16
# define LE16 LE16_unaligned
# endif
# ifndef LE16
# ifndef LE32
# define LE32 LE32_unaligned
# endif
#endif
@@ -450,7 +582,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
# ifndef LE16
# define LE16 LE16_unaligned
# endif
# ifndef LE16
# ifndef LE32
# define LE32 LE32_unaligned
# endif
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data
@@ -458,6 +590,52 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
#endif
/*************************************************************************
// Provide namespaces and classes to abtract endianness policies.
//
// CTP - Compile-Time Polymorphism (templates)
// RTP - Run-Time Polymorphism (virtual functions)
**************************************************************************/
// forward declarations
namespace N_BELE_CTP {
class BEPolicy; class LEPolicy;
extern const BEPolicy be_policy;
extern const LEPolicy le_policy;
}
namespace N_BELE_RTP {
class AbstractPolicy;
class BEPolicy; class LEPolicy;
extern const BEPolicy be_policy;
extern const LEPolicy le_policy;
}
namespace N_BELE_CTP {
#define BELE_CTP 1
#include "bele_policy.h"
#undef BELE_CTP
}
namespace N_BELE_RTP {
#define BELE_RTP 1
#include "bele_policy.h"
#undef BELE_RTP
}
namespace N_BELE_CTP {
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; }
template <>
inline const N_BELE_RTP::AbstractPolicy* getRTP<LEPolicy>()
{ return &N_BELE_RTP::le_policy; }
}
#endif /* already included */
+283
View File
@@ -0,0 +1,283 @@
/* bele_policy.h -- access memory in BigEndian and LittleEndian byte order
This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#ifndef __UPX_BELE_H
# error "this is an internal include file"
#endif
/*************************************************************************
//
**************************************************************************/
#if defined(BELE_CTP)
// CTP - Compile-Time Polymorphism (templates)
# define V static inline
# define S static int __acc_cdecl_qsort
# define C
#elif defined(BELE_RTP)
// RTP - Run-Time Polymorphism (virtual functions)
# define V virtual
# define S virtual int
# define C const
#else
# error
#endif
#if defined(BELE_RTP)
struct AbstractPolicy
{
inline AbstractPolicy() { }
virtual inline ~AbstractPolicy() { }
V bool isBE() C = 0;
V bool isLE() C = 0;
V unsigned get16(const void *p) C = 0;
V unsigned get24(const void *p) C = 0;
V unsigned get32(const void *p) C = 0;
V acc_uint64l_t get64(const void *p) C = 0;
V void set16(void *p, unsigned v) C = 0;
V void set24(void *p, unsigned v) C = 0;
V void set32(void *p, unsigned v) C = 0;
V void set64(void *p, acc_uint64l_t v) C = 0;
V unsigned get16_signed(const void *p) C = 0;
V unsigned get24_signed(const void *p) C = 0;
V unsigned get32_signed(const void *p) C = 0;
V acc_uint64l_t get64_signed(const void *p) C = 0;
S u16_compare(const void *a, const void *b) C = 0;
S u24_compare(const void *a, const void *b) C = 0;
S u32_compare(const void *a, const void *b) C = 0;
S u64_compare(const void *a, const void *b) C = 0;
S u16_compare_signed(const void *a, const void *b) C = 0;
S u24_compare_signed(const void *a, const void *b) C = 0;
S u32_compare_signed(const void *a, const void *b) C = 0;
S u64_compare_signed(const void *a, const void *b) C = 0;
// disable dynamic allocation
DISABLE_NEW_DELETE
};
#endif
struct BEPolicy
#if defined(BELE_RTP)
: public AbstractPolicy
#endif
{
inline BEPolicy() { }
#if defined(BELE_CTP)
typedef N_BELE_RTP::BEPolicy RTP_Policy;
#elif defined(BELE_RTP)
typedef N_BELE_CTP::BEPolicy CTP_Policy;
#endif
V bool isBE() C { return true; }
V bool isLE() C { return false; }
typedef BE16 U16;
typedef BE32 U32;
typedef BE64 U64;
V unsigned get16(const void *p) C
{ return get_be16(p); }
V unsigned get24(const void *p) C
{ return get_be24(p); }
V unsigned get32(const void *p) C
{ return get_be32(p); }
V acc_uint64l_t get64(const void *p) C
{ return get_be64(p); }
V void set16(void *p, unsigned v) C
{ set_be16(p, v); }
V void set24(void *p, unsigned v) C
{ set_be24(p, v); }
V void set32(void *p, unsigned v) C
{ set_be32(p, v); }
V void set64(void *p, acc_uint64l_t v) C
{ set_be64(p, v); }
V unsigned get16_signed(const void *p) C
{ return get_be16_signed(p); }
V unsigned get24_signed(const void *p) C
{ return get_be24_signed(p); }
V unsigned get32_signed(const void *p) C
{ return get_be32_signed(p); }
V acc_uint64l_t get64_signed(const void *p) C
{ return get_be64_signed(p); }
S u16_compare(const void *a, const void *b) C
{ return be16_compare(a, b); }
S u24_compare(const void *a, const void *b) C
{ return be24_compare(a, b); }
S u32_compare(const void *a, const void *b) C
{ return be32_compare(a, b); }
S u64_compare(const void *a, const void *b) C
{ return be64_compare(a, b); }
S u16_compare_signed(const void *a, const void *b) C
{ return be16_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C
{ return be24_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C
{ return be32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C
{ return be64_compare_signed(a, b); }
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
COMPILE_TIME_ASSERT_ALIGNED1(U16)
COMPILE_TIME_ASSERT_ALIGNED1(U32)
COMPILE_TIME_ASSERT_ALIGNED1(U64)
}
// disable dynamic allocation
DISABLE_NEW_DELETE
};
struct LEPolicy
#if defined(BELE_RTP)
: public AbstractPolicy
#endif
{
inline LEPolicy() { }
#if defined(BELE_CTP)
typedef N_BELE_RTP::LEPolicy RTP_Policy;
#elif defined(BELE_RTP)
typedef N_BELE_CTP::LEPolicy CTP_Policy;
#endif
V bool isBE() C { return false; }
V bool isLE() C { return true; }
typedef LE16 U16;
typedef LE32 U32;
typedef LE64 U64;
V unsigned get16(const void *p) C
{ return get_le16(p); }
V unsigned get24(const void *p) C
{ return get_le24(p); }
V unsigned get32(const void *p) C
{ return get_le32(p); }
V acc_uint64l_t get64(const void *p) C
{ return get_le64(p); }
V void set16(void *p, unsigned v) C
{ set_le16(p, v); }
V void set24(void *p, unsigned v) C
{ set_le24(p, v); }
V void set32(void *p, unsigned v) C
{ set_le32(p, v); }
V void set64(void *p, acc_uint64l_t v) C
{ set_le64(p, v); }
V unsigned get16_signed(const void *p) C
{ return get_le16_signed(p); }
V unsigned get24_signed(const void *p) C
{ return get_le24_signed(p); }
V unsigned get32_signed(const void *p) C
{ return get_le32_signed(p); }
V acc_uint64l_t get64_signed(const void *p) C
{ return get_le64_signed(p); }
S u16_compare(const void *a, const void *b) C
{ return le16_compare(a, b); }
S u24_compare(const void *a, const void *b) C
{ return le24_compare(a, b); }
S u32_compare(const void *a, const void *b) C
{ return le32_compare(a, b); }
S u64_compare(const void *a, const void *b) C
{ return le64_compare(a, b); }
S u16_compare_signed(const void *a, const void *b) C
{ return le16_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C
{ return le24_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C
{ return le32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C
{ return le64_compare_signed(a, b); }
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
COMPILE_TIME_ASSERT_ALIGNED1(U16)
COMPILE_TIME_ASSERT_ALIGNED1(U32)
COMPILE_TIME_ASSERT_ALIGNED1(U64)
}
// disable dynamic allocation
DISABLE_NEW_DELETE
};
#if (ACC_ABI_BIG_ENDIAN)
typedef BEPolicy HostPolicy;
#elif (ACC_ABI_LITTLE_ENDIAN)
typedef LEPolicy HostPolicy;
#else
# error "ACC_ABI_ENDIAN"
#endif
#if 0 /* UNUSED */
struct HostAlignedPolicy
{
#if defined(BELE_CTP)
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
#endif
typedef acc_uint16e_t U16;
typedef acc_uint32e_t U32;
typedef acc_uint64l_t U64;
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
}
};
#endif
#undef V
#undef S
#undef C
/*
vi:ts=4:et:nowrap
*/
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+3 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -72,7 +72,7 @@ static void print0(FILE *f, const char *s)
}
static upx_bool intro(FILE *f)
static bool intro(FILE *f)
{
UNUSED(f);
return 0;
+3 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -124,7 +124,7 @@ static int set_fg(FILE *f, int fg)
}
static upx_bool intro(FILE *f)
static bool intro(FILE *f)
{
if (con == me)
init(f,-1,-1);
+3 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -58,7 +58,7 @@ static void print0(FILE *f, const char *s)
}
static upx_bool intro(FILE *f)
static bool intro(FILE *f)
{
UNUSED(f);
return 0;
+3 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -295,7 +295,7 @@ static void print0(FILE *f, const char *ss)
}
static upx_bool intro(FILE *f)
static bool intro(FILE *f)
{
UNUSED(f);
#if defined(USE_FRAMES)
+186 -11
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -27,21 +27,196 @@
#include "conf.h"
#include "compress.h"
#include "mem.h"
#include <zlib.h>
#if defined(WITH_NRV)
# include "compress_nrv.ch"
/*************************************************************************
//
**************************************************************************/
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
{
if (len == 0)
return adler;
assert(buf != NULL);
#if 0
return adler32(adler, (const Bytef *) buf, len); // zlib
#elif defined(WITH_UCL)
# define ALG_NRV2E
# define upx_adler32 upx_adler32
//# define upx_crc32 upx_crc32
# define upx_compress upx_compress
# define upx_decompress upx_decompress
# define upx_test_overlap upx_test_overlap
# include "compress.ch"
return ucl_adler32(adler, (const ucl_bytep) buf, len);
#else
# error
#endif
}
#if 0 /* UNUSED */
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
{
if (len == 0)
return crc;
assert(buf != NULL);
#if 0
return crc32(crc, (const Bytef *) buf, len); // zlib
#elif defined(WITH_UCL)
return ucl_crc32(crc, (const ucl_bytep) buf, len);
#else
# error
#endif
}
#endif /* UNUSED */
/*************************************************************************
//
**************************************************************************/
int upx_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR;
upx_compress_result_t cresult_buffer;
assert(method > 0); assert(level > 0);
#if 1
// set available bytes in dst
if (*dst_len == 0)
*dst_len = MemBuffer::getSizeForCompression(src_len);
#else
// force users to provide *dst_len
assert(*dst_len != 0);
#endif
// for UPX, we always require a reasonably sized outbut buffer
assert(*dst_len >= MemBuffer::getSizeForCompression(src_len));
if (!cresult)
cresult = &cresult_buffer;
memset(cresult, 0, sizeof(*cresult));
#if 1
// debug
cresult->method = method;
cresult->level = level;
cresult->u_len = src_len;
cresult->c_len = 0;
#endif
if (0) {
}
#if defined(WITH_LZMA)
else if (M_IS_LZMA(method))
r = upx_lzma_compress(src, src_len, dst, dst_len,
cb, method, level, cconf, cresult);
#endif
#if defined(WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_nrv_compress(src, src_len, dst, dst_len,
cb, method, level, cconf, cresult);
#endif
#if defined(WITH_UCL)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_ucl_compress(src, src_len, dst, dst_len,
cb, method, level, cconf, cresult);
#endif
else {
throwInternalError("unknown compression method");
}
#if 1
// debug
cresult->c_len = *dst_len;
#endif
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR;
assert(*dst_len > 0);
assert(src_len < *dst_len); // must be compressed
if (cresult && cresult->method == 0)
cresult = NULL;
if (0) {
}
#if defined(WITH_LZMA)
else if (M_IS_LZMA(method))
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
#endif
#if defined(WITH_NRV)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult);
#endif
#if defined(WITH_UCL)
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
r = upx_ucl_decompress(src, src_len, dst, dst_len, method, cresult);
#endif
#if defined(WITH_ZLIB)
else if (M_IS_DEFLATE(method))
r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult);
#endif
else {
throwInternalError("unknown decompression method");
}
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR;
if (cresult && cresult->method == 0)
cresult = NULL;
assert(*dst_len > 0);
assert(src_len < *dst_len); // must be compressed
unsigned overlap_overhead = src_off + src_len - *dst_len;
assert((int)overlap_overhead > 0);
if (0) {
}
#if defined(WITH_LZMA)
else if (M_IS_LZMA(method))
r = upx_lzma_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
#endif
#if defined(WITH_NRV)
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);
#endif
#if defined(WITH_UCL)
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);
#endif
else {
throwInternalError("unknown decompression method");
}
return r;
}
/*
+118
View File
@@ -0,0 +1,118 @@
/* compress.h --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#ifndef __UPX_COMPRESS_H
#define __UPX_COMPRESS_H
/*************************************************************************
//
**************************************************************************/
#if defined(WITH_LZMA)
const char *upx_lzma_version_string(void);
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,
upx_compress_result_t *cresult );
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 );
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
#endif
#if defined(WITH_NRV)
const char *upx_nrv_version_string(void);
int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
int upx_nrv_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
int upx_nrv_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
#endif
#if defined(WITH_UCL)
const char *upx_ucl_version_string(void);
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
#endif
#if defined(WITH_ZLIB)
const char *upx_zlib_version_string(void);
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
int upx_zlib_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
#endif
#endif /* already included */
/*
vi:ts=4:et
*/
+527
View File
@@ -0,0 +1,527 @@
/* compress_lzma.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "compress.h"
void lzma_compress_config_t::reset()
{
memset(this, 0, sizeof(*this));
pos_bits.reset();
lit_pos_bits.reset();
lit_context_bits.reset();
dict_size.reset();
fast_mode = 2;
num_fast_bytes.reset();
match_finder_cycles = 0;
max_num_probs = 0;
}
#if !defined(WITH_LZMA)
extern int compress_lzma_dummy;
int compress_lzma_dummy = 0;
#else
// INFO: the LZMA SDK is covered by a permissive license which allows
// using unmodified LZMA source code in UPX and the UPX stubs.
// See SPECIAL EXCEPTION below.
//
// Quoting from lzma-4.43/lzma.txt:
//
// LICENSE
// -------
//
// LZMA SDK is available under any of the following licenses:
//
// 1) GNU Lesser General Public License (GNU LGPL)
// 2) Common Public License (CPL)
// 3) Simplified license for unmodified code (read SPECIAL EXCEPTION)
// 4) Proprietary license
//
// It means that you can select one of these four options and follow rules
// of that license.
//
// 1,2) GNU LGPL and CPL licenses are pretty similar and both these
// licenses are classified as
// - "Free software licenses" at http://www.gnu.org/
// - "OSI-approved" at http://www.opensource.org/
//
// 3) SPECIAL EXCEPTION
//
// Igor Pavlov, as the author of this code, expressly permits you
// to statically or dynamically link your code (or bind by name)
// to the files from LZMA SDK without subjecting your linked
// code to the terms of the CPL or GNU LGPL.
// Any modifications or additions to files from LZMA SDK, however,
// are subject to the GNU LGPL or CPL terms.
//
// SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
// while you keep LZMA SDK code unmodified.
/*************************************************************************
// cruft because of pseudo-COM layer
**************************************************************************/
#undef USE_LZMA_PROPERTIES
#undef MSDOS
#undef OS2
#undef _WIN32
#undef _WIN32_WCE
#undef COMPRESS_MF_MT
#undef _NO_EXCEPTIONS
#include "C/Common/MyInitGuid.h"
//#include "C/7zip/Compress/LZMA/LZMADecoder.h"
#include "C/7zip/Compress/LZMA/LZMAEncoder.h"
namespace MyLzma {
struct InStream: public ISequentialInStream, public CMyUnknownImp
{
MY_UNKNOWN_IMP
const Byte *b_buf; size_t b_size; size_t b_pos;
void Init(const Byte *data, size_t size) {
b_buf = data; b_size = size; b_pos = 0;
}
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
size_t remain = b_size - b_pos;
if (size > remain) size = (UInt32) remain;
memcpy(data, b_buf + b_pos, size);
b_pos += size;
if (processedSize != NULL) *processedSize = size;
return S_OK;
}
struct OutStream : public ISequentialOutStream, public CMyUnknownImp
{
MY_UNKNOWN_IMP
Byte *b_buf; size_t b_size; size_t b_pos; bool overflow;
void Init(Byte *data, size_t size) {
b_buf = data; b_size = size; b_pos = 0; overflow = false;
}
HRESULT WriteByte(Byte c) {
if (b_pos >= b_size) { overflow = true; return E_FAIL; }
b_buf[b_pos++] = c;
return S_OK;
}
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
size_t remain = b_size - b_pos;
if (size > remain) size = (UInt32) remain, overflow = true;
memcpy(b_buf + b_pos, data, size);
b_pos += size;
if (processedSize != NULL) *processedSize = size;
return overflow ? E_FAIL : S_OK;
}
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
{
MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
upx_callback_p cb;
};
STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
{
if (cb && cb->nprogress)
cb->nprogress(cb, (unsigned) *inSize, (unsigned) *outSize);
return S_OK;
}
} // namespace
#if (ACC_CC_INTELC) && defined(__linux__)
# pragma warning(disable: 424) // #424: extra ";" ignored
#endif
#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"
#undef RC_NORMALIZE
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
assert(level > 0); assert(cresult != NULL);
int r = UPX_E_ERROR;
HRESULT rh;
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
lzma_compress_result_t *res = &cresult->result_lzma;
MyLzma::InStream is; is.AddRef();
MyLzma::OutStream os; os.AddRef();
is.Init(src, src_len);
os.Init(dst, *dst_len);
MyLzma::ProgressInfo progress; progress.AddRef();
progress.cb = cb;
NCompress::NLZMA::CEncoder enc;
const PROPID propIDs[8] = {
NCoderPropID::kPosStateBits, // 0 pb _posStateBits(2)
NCoderPropID::kLitPosBits, // 1 lp _numLiteralPosStateBits(0)
NCoderPropID::kLitContextBits, // 2 lc _numLiteralContextBits(3)
NCoderPropID::kDictionarySize, // 3 ds
NCoderPropID::kAlgorithm, // 4 fm _fastmode
NCoderPropID::kNumFastBytes, // 5 fb
NCoderPropID::kMatchFinderCycles, // 6 mfc _matchFinderCycles, _cutValue
NCoderPropID::kMatchFinder // 7 mf
};
PROPVARIANT pr[8];
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[7].vt = VT_BSTR;
// 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;
}
// cconf overrides
if (lcconf)
{
oassign(pr[0].uintVal, lcconf->pos_bits);
oassign(pr[1].uintVal, lcconf->lit_pos_bits);
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
try {
#else
# error
#endif
if (enc.SetCoderProperties(propIDs, pr, 8) != S_OK)
goto error;
if (enc.WriteCoderProperties(&os) != S_OK)
goto error;
if (os.overflow) {
//r = UPX_E_OUTPUT_OVERRUN;
r = UPX_E_NOT_COMPRESSIBLE;
goto error;
}
assert(os.b_pos == 5);
#if defined(USE_LZMA_PROPERTIES)
os.b_pos = 1;
#else
os.b_pos = 0;
// extra stuff in first byte: 5 high bits convenience for stub decompressor
unsigned t = res->lit_context_bits + res->lit_pos_bits;
os.WriteByte((t << 3) | res->pos_bits);
os.WriteByte((res->lit_pos_bits << 4) | (res->lit_context_bits));
#endif
rh = enc.Code(&is, &os, NULL, NULL, &progress);
#ifndef _NO_EXCEPTIONS
} catch (...) { rh = E_OUTOFMEMORY; }
#endif
assert(is.b_pos <= src_len);
assert(os.b_pos <= *dst_len);
if (rh == E_OUTOFMEMORY)
r = UPX_E_OUT_OF_MEMORY;
else if (os.overflow)
{
assert(os.b_pos == *dst_len);
//r = UPX_E_OUTPUT_OVERRUN;
r = UPX_E_NOT_COMPRESSIBLE;
}
else if (rh == S_OK)
{
assert(is.b_pos == src_len);
r = UPX_E_OK;
}
error:
*dst_len = os.b_pos;
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
//printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
return r;
}
/*************************************************************************
// decompress
**************************************************************************/
#undef _LZMA_IN_CB
#undef _LZMA_OUT_READ
#undef _LZMA_PROB32
#undef _LZMA_LOC_OPT
#include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
#include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
// see res->num_probs above
COMPILE_TIME_ASSERT(sizeof(CProb) == 2)
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
CLzmaDecoderState s; memset(&s, 0, sizeof(s));
SizeT src_out = 0, dst_out = 0;
int r = UPX_E_ERROR;
int rh;
#if defined(USE_LZMA_PROPERTIES)
if (src_len < 2)
goto error;
rh = LzmaDecodeProperties(&s.Properties, src, src_len);
if (rh != 0)
goto error;
src += 1; src_len -= 1;
#else
if (src_len < 3)
goto error;
s.Properties.pb = src[0] & 7;
s.Properties.lp = (src[1] >> 4);
s.Properties.lc = src[1] & 15;
if (s.Properties.pb >= 5) goto error;
if (s.Properties.lp >= 5) goto error;
if (s.Properties.lc >= 9) goto error;
// extra
if ((src[0] >> 3) != s.Properties.lc + s.Properties.lp) goto error;
src += 2; src_len -= 2;
#endif
if (cresult)
{
assert(cresult->method == method);
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
assert(cresult->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
const lzma_compress_result_t *res = &cresult->result_lzma;
UNUSED(res);
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
}
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
if (!s.Probs)
{
r = UPX_E_OUT_OF_MEMORY;
goto error;
}
rh = LzmaDecode(&s, src, src_len, &src_out, dst, *dst_len, &dst_out);
assert(src_out <= src_len);
assert(dst_out <= *dst_len);
if (rh == 0)
{
r = UPX_E_OK;
if (src_out != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
}
error:
*dst_len = dst_out;
free(s.Probs);
UNUSED(cresult);
return r;
}
/*************************************************************************
// test_overlap
**************************************************************************/
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(M_IS_LZMA(method));
// FIXME - implement this
// Note that Packer::verifyOverlappingDecompression() will
// verify the final result in any case.
UNUSED(buf);
unsigned overlap_overhead = src_off + src_len - *dst_len;
//printf("upx_lzma_test_overlap: %d\n", overlap_overhead);
if ((int)overlap_overhead >= 256)
return UPX_E_OK;
UNUSED(cresult);
return UPX_E_ERROR;
}
/*************************************************************************
// misc
**************************************************************************/
const char *upx_lzma_version_string(void)
{
// FIXME
// return NULL;
return "4.43";
}
#endif /* WITH_LZMA */
/*
vi:ts=4:et:nowrap
*/
+124 -111
View File
@@ -1,9 +1,9 @@
/* compress.ch --
/* compress_ucl.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -26,6 +26,24 @@
*/
#include "conf.h"
#include "compress.h"
#if !defined(WITH_UCL)
extern int compress_ucl_dummy;
int compress_ucl_dummy = 0;
#else
#if 1 && !defined(UCL_USE_ASM) && (ACC_ARCH_I386)
# if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
# define UCL_USE_ASM
# endif
#endif
#if defined(UCL_NO_ASM)
# undef UCL_USE_ASM
#endif
#if defined(ACC_CFG_NO_UNALIGNED)
# undef UCL_USE_ASM
#endif
#if 1 && defined(UCL_USE_ASM)
# include <ucl/ucl_asm.h>
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
@@ -44,115 +62,128 @@
//
**************************************************************************/
#if defined(upx_adler32)
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
static int convert_errno_from_ucl(int r)
{
if (len == 0)
return adler;
assert(buf != NULL);
return ucl_adler32(adler, (const ucl_bytep)buf, len);
switch (r)
{
case UCL_E_OK: return UPX_E_OK;
case UCL_E_ERROR: return UPX_E_ERROR;
case UCL_E_OUT_OF_MEMORY: return UPX_E_OUT_OF_MEMORY;
case UCL_E_NOT_COMPRESSIBLE: return UPX_E_NOT_COMPRESSIBLE;
case UCL_E_INPUT_OVERRUN: return UPX_E_INPUT_OVERRUN;
case UCL_E_OUTPUT_OVERRUN: return UPX_E_OUTPUT_OVERRUN;
case UCL_E_LOOKBEHIND_OVERRUN: return UPX_E_LOOKBEHIND_OVERRUN;
case UCL_E_EOF_NOT_FOUND: return UPX_E_EOF_NOT_FOUND;
case UCL_E_INPUT_NOT_CONSUMED: return UPX_E_INPUT_NOT_CONSUMED;
// case UCL_E_NOT_YET_IMPLEMENTED: return UPX_E_NOT_YET_IMPLEMENTED;
case UCL_E_INVALID_ARGUMENT: return UPX_E_INVALID_ARGUMENT;
// UCL extra:
case UCL_E_OVERLAP_OVERRUN: return UPX_E_ERROR;
}
return UPX_E_ERROR;
}
#endif
#if defined(upx_crc32)
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
extern "C" {
static void wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
{
if (len == 0)
return crc;
assert(buf != NULL);
return ucl_crc32(crc, (const ucl_bytep)buf, len);
}
#endif
if (state != -1 && state != 3) return;
upx_callback_p cb = (upx_callback_p) user;
if (cb && cb->nprogress)
cb->nprogress(cb, a, b);
}}
/*************************************************************************
//
**************************************************************************/
#if defined(upx_compress)
int upx_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_progress_callback_t *cb,
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb_parm,
int method, int level,
const struct upx_compress_config_t *conf_parm,
upx_uintp result )
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
struct upx_compress_config_t conf;
upx_uint result_buffer[16];
int r = UPX_E_ERROR;
int r;
assert(level > 0); assert(cresult != NULL);
assert(level > 0);
memset(&conf, 0xff, sizeof(conf));
if (conf_parm)
conf = *conf_parm; // struct copy
if (!result)
result = result_buffer;
COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))
ucl_progress_callback_t cb;
cb.callback = 0;
cb.user = NULL;
if (cb_parm && cb_parm->nprogress) {
cb.callback = wrap_nprogress_ucl;
cb.user = cb_parm;
}
ucl_compress_config_t cconf; cconf.reset();
if (cconf_parm)
cconf = cconf_parm->conf_ucl; // struct copy
ucl_uint *res = cresult->result_ucl.result;
// assume no info available - fill in worst case results
//result[0] = 1; // min_offset_found - NOT USED
result[1] = src_len - 1; // max_offset_found
//result[2] = 2; // min_match_found - NOT USED
result[3] = src_len - 1; // max_match_found
//result[4] = 1; // min_run_found - NOT USED
result[5] = src_len; // max_run_found
result[6] = 1; // first_offset_found
//result[7] = 999999; // same_match_offsets_found - NOT USED
//res[0] = 1; // min_offset_found - NOT USED
res[1] = src_len - 1; // max_offset_found
//res[2] = 2; // min_match_found - NOT USED
res[3] = src_len - 1; // max_match_found
//res[4] = 1; // min_run_found - NOT USED
res[5] = src_len; // max_run_found
res[6] = 1; // first_offset_found
//res[7] = 999999; // same_match_offsets_found - NOT USED
// prepare bit-buffer settings
conf.bb_endian = 0;
conf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
cconf.bb_endian = 0;
cconf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16)
{
static const unsigned char sizes[3]={32,8,16};
conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
static const unsigned char sizes[3] = {32, 8, 16};
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
}
else
else {
throwInternalError("unknown compression method");
return UPX_E_ERROR;
}
// optimize compression parms
if (level <= 3 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 8*1024-1;
else if (level == 4 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 32*1024-1;
if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
cconf.max_offset = 8*1024-1;
else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
cconf.max_offset = 32*1024-1;
if M_IS_NRV2B(method)
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
&cb, level, &cconf, res);
else if M_IS_NRV2D(method)
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#if defined(ALG_NRV2E)
&cb, level, &cconf, res);
else if M_IS_NRV2E(method)
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#endif
#if 0 /*{*/
else if M_IS_CL1B(method)
r = cl1b_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#endif /*}*/
else
&cb, level, &cconf, res);
else {
throwInternalError("unknown compression method");
return UPX_E_ERROR;
}
return r;
// make sure first_offset_found is set
if (res[6] == 0)
res[6] = 1;
return convert_errno_from_ucl(r);
}
#endif /* upx_compress */
/*************************************************************************
//
**************************************************************************/
#if defined(upx_decompress)
int upx_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method )
int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR;
int r;
switch (method)
{
@@ -174,7 +205,6 @@ int upx_decompress ( const upx_bytep src, upx_uint src_len,
case M_NRV2D_LE32:
r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
#if defined(ALG_NRV2E)
case M_NRV2E_8:
r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
@@ -184,40 +214,26 @@ int upx_decompress ( const upx_bytep src, upx_uint src_len,
case M_NRV2E_LE32:
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
#endif
#if 0 /*{*/
case M_CL1B_8:
r = cl1b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_CL1B_LE16:
r = cl1b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_CL1B_LE32:
r = cl1b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
#endif /*}*/
default:
throwInternalError("unknown decompression method");
break;
return UPX_E_ERROR;
}
return r;
UNUSED(cresult);
return convert_errno_from_ucl(r);
}
#endif /* upx_decompress */
/*************************************************************************
//
**************************************************************************/
#if defined(upx_test_overlap)
int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method )
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
int r = UPX_E_ERROR;
int r;
switch (method)
{
@@ -239,7 +255,6 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
case M_NRV2D_LE32:
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
#if defined(ALG_NRV2E)
case M_NRV2E_8:
r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
@@ -249,29 +264,27 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
case M_NRV2E_LE32:
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
#endif
#if 0 /*{*/
case M_CL1B_8:
r = cl1b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_CL1B_LE16:
r = cl1b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_CL1B_LE32:
r = cl1b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
#endif /*}*/
default:
throwInternalError("unknown decompression method");
break;
return UPX_E_ERROR;
}
return r;
UNUSED(cresult);
return convert_errno_from_ucl(r);
}
#endif /* upx_test_overlap */
/*************************************************************************
// misc
**************************************************************************/
const char *upx_ucl_version_string(void)
{
return ucl_version_string();
}
#endif /* WITH_UCL */
/*
vi:ts=4:et:nowrap
*/
+230
View File
@@ -0,0 +1,230 @@
/* compress_zlib.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "compress.h"
void zlib_compress_config_t::reset()
{
memset(this, 0, sizeof(*this));
mem_level.reset();
window_bits.reset();
strategy.reset();
}
#if !defined(WITH_ZLIB)
extern int compress_zlib_dummy;
int compress_zlib_dummy = 0;
#else
#include <zlib.h>
static int convert_errno_from_zlib(int zr)
{
switch (zr)
{
case Z_OK: return UPX_E_OK;
case Z_DATA_ERROR: return UPX_E_ERROR;
case Z_NEED_DICT: return UPX_E_ERROR;
}
return UPX_E_ERROR;
}
/*************************************************************************
//
**************************************************************************/
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb_parm,
int method, int level,
const upx_compress_config_t *cconf_parm,
upx_compress_result_t *cresult )
{
assert(method == M_DEFLATE);
assert(level > 0); assert(cresult != NULL);
UNUSED(cb_parm);
int r = UPX_E_ERROR;
int zr;
const zlib_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_zlib : NULL;
zlib_compress_result_t *res = &cresult->result_zlib;
if (level == 10)
level = 9;
zlib_compress_config_t::mem_level_t mem_level;
zlib_compress_config_t::window_bits_t window_bits;
zlib_compress_config_t::strategy_t strategy;
// cconf overrides
if (lcconf)
{
oassign(mem_level, lcconf->mem_level);
oassign(window_bits, lcconf->window_bits);
oassign(strategy, lcconf->strategy);
}
res->dummy = 0;
z_stream s;
s.zalloc = (alloc_func) 0;
s.zfree = (free_func) 0;
s.next_in = const_cast<upx_bytep>(src); // UNCONST
s.avail_in = src_len;
s.next_out = dst;
s.avail_out = *dst_len;
s.total_in = s.total_out = 0;
zr = deflateInit2(&s, level, Z_DEFLATED, 0 - (int)window_bits,
mem_level, strategy);
if (zr != Z_OK)
goto error;
zr = deflate(&s, Z_FINISH);
if (zr != Z_STREAM_END)
goto error;
zr = deflateEnd(&s);
if (zr != Z_OK)
goto error;
r = UPX_E_OK;
goto done;
error:
(void) deflateEnd(&s);
r = convert_errno_from_zlib(zr);
if (r == UPX_E_OK)
r = UPX_E_ERROR;
done:
if (r == UPX_E_OK)
{
if (s.avail_in != 0 || s.total_in != src_len)
r = UPX_E_ERROR;
}
assert(s.total_in <= src_len);
assert(s.total_out <= *dst_len);
*dst_len = s.total_out;
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(method == M_DEFLATE);
UNUSED(method);
UNUSED(cresult);
int r = UPX_E_ERROR;
int zr;
z_stream s;
s.zalloc = (alloc_func) 0;
s.zfree = (free_func) 0;
s.next_in = const_cast<upx_bytep>(src); // UNCONST
s.avail_in = src_len;
s.next_out = dst;
s.avail_out = *dst_len;
s.total_in = s.total_out = 0;
zr = inflateInit2(&s, -15);
if (zr != Z_OK)
goto error;
zr = inflate(&s, Z_FINISH);
if (zr != Z_STREAM_END)
goto error;
zr = inflateEnd(&s);
if (zr != Z_OK)
goto error;
r = UPX_E_OK;
goto done;
error:
(void) inflateEnd(&s);
r = convert_errno_from_zlib(zr);
if (r == UPX_E_OK)
r = UPX_E_ERROR;
done:
if (r == UPX_E_OK)
{
if (s.avail_in != 0 || s.total_in != src_len)
r = UPX_E_INPUT_NOT_CONSUMED;
}
assert(s.total_in <= src_len);
assert(s.total_out <= *dst_len);
*dst_len = s.total_out;
return r;
}
/*************************************************************************
// test_overlap
**************************************************************************/
int upx_zlib_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult )
{
assert(method == M_DEFLATE);
// FIXME - implement this
// Note that Packer::verifyOverlappingDecompression() will
// verify the final result in any case.
UNUSED(buf);
unsigned overlap_overhead = src_off + src_len - *dst_len;
//printf("upx_zlib_test_overlap: %d\n", overlap_overhead);
if ((int)overlap_overhead >= 256)
return UPX_E_OK;
UNUSED(cresult);
return UPX_E_ERROR;
}
/*************************************************************************
// misc
**************************************************************************/
const char *upx_zlib_version_string(void)
{
return zlibVersion();
}
#endif /* WITH_ZLIB */
/*
vi:ts=4:et:nowrap
*/
+347 -123
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -40,8 +40,16 @@
#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__)
# undef HAVE_UTIME_H /* this pulls in <windows.h> */
#endif
// FIXME - quick hack for arm-wince-gcc-3.4 (Debian pocketpc-*.deb packages)
#if 1 && (ACC_ARCH_ARM) && defined(__pe__) && !defined(_WIN32)
# undef HAVE_CHMOD
# undef HAVE_CHOWN
# undef HAVE_LSTAT
# undef HAVE_UTIME
#endif
// pragmas
#if (ACC_CC_BORLANDC)
# if (__BORLANDC__ < 0x0500)
# error "need Borland C++ 5.0 or newer"
@@ -96,6 +104,8 @@
# if (_MSC_VER >= 1400)
# pragma warning(disable: 4996) // W1: 'function': was declared deprecated
# endif
#elif (ACC_CC_SUNPROC)
//# pragma error_messages(off,"badargtype2w") // FIXME
#elif (ACC_CC_WATCOMC)
# if (__WATCOMC__ < 1100)
# error "need Watcom C++ 11.0c or newer"
@@ -144,35 +154,30 @@
# undef __unix
#endif
#if !defined(WITH_UCL)
# define WITH_UCL 1
#endif
#if defined(WITH_UCL)
# include <ucl/uclconf.h>
# include <ucl/ucl.h>
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010200L)
# error "please upgrade your UCL installation"
# endif
# if !defined(UPX_UINT_MAX)
# define UPX_UINT_MAX UCL_UINT_MAX
# define upx_uint ucl_uint
# define upx_voidp ucl_voidp
# define upx_uintp ucl_uintp
# define upx_byte ucl_byte
# define upx_bytep ucl_bytep
# define upx_bool ucl_bool
# define upx_compress_config_t ucl_compress_config_t
# define upx_progress_callback_t ucl_progress_callback_t
# define UPX_E_OK UCL_E_OK
# define UPX_E_ERROR UCL_E_ERROR
# define UPX_E_OUT_OF_MEMORY UCL_E_OUT_OF_MEMORY
# define __UPX_CDECL __UCL_CDECL
#if 0 && !defined(WITH_LZMA)
# define WITH_LZMA 1
#endif
#if defined(UPX_OFFICIAL_BUILD)
# if !defined(WITH_LZMA) || !defined(WITH_NRV) || !defined(WITH_UCL)
# error
# endif
#endif
#if defined(WITH_NRV)
# include <nrv/nrvconf.h>
#endif
#if defined(WITH_UCL)
# define ucl_compress_config_t REAL_ucl_compress_config_t
# include <ucl/uclconf.h>
# include <ucl/ucl.h>
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010300L)
# error "please upgrade your UCL installation"
# endif
# undef ucl_compress_config_t
# undef ucl_compress_config_p
#endif
#if !defined(__UPX_CHECKER)
# if defined(__UCL_CHECKER) || defined(__NRV_CHECKER)
# define __UPX_CHECKER
@@ -182,6 +187,9 @@
# error "UINT_MAX"
#endif
#define upx_byte unsigned char
#define upx_bytep upx_byte *
/*************************************************************************
// system includes
@@ -190,18 +198,6 @@
// malloc debuggers
#if defined(WITH_VALGRIND)
# include <valgrind/memcheck.h>
#elif defined(WITH_DMALLOC)
# define DMALLOC_FUNC_CHECK
# include <dmalloc.h>
#elif defined(WITH_GC)
# define GC_DEBUG
# include <gc/gc.h>
# undef malloc
# undef realloc
# undef free
# define malloc GC_MALLOC
# define realloc GC_REALLOC
# define free GC_FREE
#endif
#if !defined(VALGRIND_MAKE_WRITABLE)
@@ -219,6 +215,7 @@
#endif
// unconditionally turn on assertions
#undef NDEBUG
#include <assert.h>
@@ -292,17 +289,8 @@
#define index upx_index
#define outp upx_outp
#undef __attribute_packed
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
# if (1 && (ACC_ARCH_I386))
# define __attribute_packed
# else
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
# endif
#else
# define __attribute_packed
#endif
#undef PAGE_MASK
#undef PAGE_SIZE
#if !defined(O_BINARY)
# define O_BINARY 0
@@ -313,6 +301,19 @@
#endif
#undef __attribute_packed
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
# if (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
# define __attribute_packed
# else
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
# endif
#endif
#if !defined(__attribute_packed)
# define __attribute_packed
#endif
/*************************************************************************
//
**************************************************************************/
@@ -320,68 +321,52 @@
#define UNUSED(var) ACC_UNUSED(var)
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
#if 1
# 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; \
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z[7]; } __attribute_packed; \
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; } __attribute_packed; \
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2*sizeof(b)+sizeof(a)) \
}
#else
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
struct acc_tmp_t { b x; a y; b z[7]; } __attribute_packed; \
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
}
#endif
#if defined(__acc_alignof)
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
# define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \
COMPILE_TIME_ASSERT(__acc_alignof(a) == sizeof(b))
#else
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
# define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
#endif
#define COMPILE_TIME_ASSERT_ALIGNED1(a) __COMPILE_TIME_ASSERT_ALIGNOF(a,char)
#define TABLESIZE(table) ((sizeof(table)/sizeof((table)[0])))
#if 0
#define ALIGN_DOWN(a,b) (((a) / (b)) * (b))
#define ALIGN_UP(a,b) ALIGN_DOWN((a) + ((b) - 1), b)
#define ALIGN_GAP(a,b) (ALIGN_UP(a,b) - (a))
#elif 1
template <class T>
inline T ALIGN_DOWN(const T& a, const T& b) { T r; r = (a / b) * b; return r; }
template <class T>
inline T ALIGN_UP (const T& a, const T& b) { T r; r = ((a + b - 1) / b) * b; return r; }
template <class T>
inline T ALIGN_GAP (const T& a, const T& b) { T r; r = ALIGN_UP(a, b) - a; return r; }
#else
inline unsigned ALIGN_DOWN(unsigned a, unsigned b) { return (a / b) * b; }
inline unsigned ALIGN_UP (unsigned a, unsigned b) { return ((a + b - 1) / b) * b; }
inline unsigned ALIGN_GAP (unsigned a, unsigned b) { return ALIGN_UP(a, b) - a; }
#endif
#if 0
#define UPX_MAX(a,b) ((a) >= (b) ? (a) : (b))
#define UPX_MIN(a,b) ((a) <= (b) ? (a) : (b))
#define UPX_MAX3(a,b,c) ((a) >= (b) ? UPX_MAX(a,c) : UPX_MAX(b,c))
#define UPX_MIN3(a,b,c) ((a) <= (b) ? UPX_MIN(a,c) : UPX_MIN(b,c))
#if 0 && defined(__cplusplus) && !defined(new) && !defined(delete)
// global operators - debug
inline void *operator new(size_t l)
{
void *p = malloc(l);
printf("new %6ld %p\n",(long)l,p);
fflush(stdout);
return p;
}
inline void *operator new[](size_t l)
{
void *p = malloc(l);
printf("new[] %6ld %p\n",(long)l,p);
fflush(stdout);
return p;
}
inline void operator delete(void *p)
{
printf("delete %p\n",p);
fflush(stdout);
if (p) free(p);
}
inline void operator delete[](void *p)
{
printf("delete[] %p\n",p);
fflush(stdout);
if (p) free(p);
}
#elif 1
template <class T>
inline const T& UPX_MAX(const T& a, const T& b) { if (a < b) return b; return a; }
template <class T>
inline const T& UPX_MIN(const T& a, const T& b) { if (a < b) return a; return b; }
#else
inline unsigned UPX_MAX(unsigned a, unsigned b) { return a < b ? b : a; }
inline unsigned UPX_MIN(unsigned a, unsigned b) { return a < b ? a : b; }
#endif
@@ -394,6 +379,14 @@ inline void operator delete[](void *p)
#define ByteArray(var, size) Array(unsigned char, var, size)
struct nocopy
{
inline nocopy() {}
private:
nocopy(const nocopy &); // undefined
nocopy& operator=(const nocopy &); // undefined
};
/*************************************************************************
// constants
@@ -413,24 +406,23 @@ inline void operator delete[](void *p)
#define EXIT_INTERNAL 1
// compression methods - DO NOT CHANGE
#define M_NRV2B_LE32 2
#define M_NRV2B_8 3
#define M_NRV2B_LE16 4
#define M_NRV2D_LE32 5
#define M_NRV2D_8 6
#define M_NRV2D_LE16 7
#define M_NRV2E_LE32 8
#define M_NRV2E_8 9
#define M_NRV2E_LE16 10
#define M_CL1B_LE32 11
#define M_CL1B_8 12
#define M_CL1B_LE16 13
// magic constants for patching
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
#define UPX_MAGIC2_LE32 0xD5D0D8A1
#define M_IS_NRV2B(x) ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)
#define M_IS_NRV2D(x) ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)
#define M_IS_NRV2E(x) ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)
#define M_IS_CL1B(x) ((x) >= M_CL1B_LE32 && (x) <= M_CL1B_LE16)
// upx_compress() error codes
#define UPX_E_OK (0)
#define UPX_E_ERROR (-1)
#define UPX_E_OUT_OF_MEMORY (-2)
#define UPX_E_NOT_COMPRESSIBLE (-3)
#define UPX_E_INPUT_OVERRUN (-4)
#define UPX_E_OUTPUT_OVERRUN (-5)
#define UPX_E_LOOKBEHIND_OVERRUN (-6)
#define UPX_E_EOF_NOT_FOUND (-7)
#define UPX_E_INPUT_NOT_CONSUMED (-8)
#define UPX_E_NOT_YET_IMPLEMENTED (-9)
#define UPX_E_INVALID_ARGUMENT (-10)
// Executable formats. Note: big endian types are >= 128.
@@ -456,6 +448,13 @@ inline void operator delete[](void *p)
#define UPX_F_LINUX_ELFI_i386 20
#define UPX_F_WINCE_ARM_PE 21
#define UPX_F_LINUX_ELF64_AMD 22
#define UPX_F_LINUX_ELF32_ARMLE 23
#define UPX_F_BSD_i386 24
#define UPX_F_BSD_ELF_i386 25
#define UPX_F_BSD_SH_i386 26
#define UPX_F_VMLINUX_AMD64 27
#define UPX_F_VMLINUX_ARM 28
#define UPX_F_PLAIN_TEXT 127
@@ -463,10 +462,229 @@ inline void operator delete[](void *p)
#define UPX_F_SOLARIS_SPARC 130
#define UPX_F_MACH_PPC32 131
#define UPX_F_LINUX_ELFPPC32 132
#define UPX_F_LINUX_ELF32_ARMBE 133
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
#define UPX_MAGIC2_LE32 0xD5D0D8A1
// compression methods
#define M_ALL (-1)
#define M_END (-2)
#define M_NONE (-3)
#define M_SKIP (-4)
#define M_ULTRA_BRUTE (-5)
// compression methods - DO NOT CHANGE
#define M_NRV2B_LE32 2
#define M_NRV2B_8 3
#define M_NRV2B_LE16 4
#define M_NRV2D_LE32 5
#define M_NRV2D_8 6
#define M_NRV2D_LE16 7
#define M_NRV2E_LE32 8
#define M_NRV2E_8 9
#define M_NRV2E_LE16 10
//#define M_CL1B_LE32 11
//#define M_CL1B_8 12
//#define M_CL1B_LE16 13
#define M_LZMA 14
#define M_DEFLATE 15 /* zlib */
#define M_IS_NRV2B(x) ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)
#define M_IS_NRV2D(x) ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)
#define M_IS_NRV2E(x) ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)
//#define M_IS_CL1B(x) ((x) >= M_CL1B_LE32 && (x) <= M_CL1B_LE16)
#define M_IS_LZMA(x) (((x) & 255) == M_LZMA)
#define M_IS_DEFLATE(x) ((x) == M_DEFLATE)
// filters
#define FT_END (-1)
#define FT_NONE (-2)
#define FT_SKIP (-3)
#define FT_ULTRA_BRUTE (-4)
/*************************************************************************
// compression - callback_t
**************************************************************************/
struct upx_callback_t;
#define upx_callback_p upx_callback_t *
#if 0
typedef void* (__acc_cdecl *upx_alloc_func_t)
(upx_callback_p self, unsigned items, unsigned size);
typedef void (__acc_cdecl *upx_free_func_t)
(upx_callback_p self, void* ptr);
#endif
typedef void (__acc_cdecl *upx_progress_func_t)
(upx_callback_p, unsigned, unsigned);
struct upx_callback_t
{
upx_progress_func_t nprogress;
void *user;
void reset() { memset(this, 0, sizeof(*this)); }
};
/*************************************************************************
// compression - config_t
**************************************************************************/
template <class T, T default_value, T min_value, T max_value>
struct OptVar
{
typedef T Type;
static const T default_value_c = default_value;
static const T min_value_c = min_value;
static const T max_value_c = max_value;
void assertValue() {
// FIXME: this generates annoying warnings "unsigned >= 0 is always true"
//assert((v >= min_value) && (v <= max_value));
}
OptVar() : v(default_value), is_set(0) { }
OptVar& operator= (const T other) {
v = other; is_set += 1;
assertValue();
return *this;
}
#if 0
#error
// there is too much implicit magic in this copy operator;
// better introduce an explicit "oassign" function.
OptVar& operator= (const OptVar& other) {
if (other.is_set) { v = other.v; is_set += 1; }
assertValue(); return *this;
}
#endif
void reset() { v = default_value; is_set = 0; }
operator T () const { return v; }
T v;
unsigned is_set;
};
// optional assignments
template <class T> inline void oassign(T& self, const T& other) {
if (other.is_set) { self.v = other.v; self.is_set += 1; }
}
#if 0
template <class V, class T> inline void oassign(V& v, const T& other) {
if (other.is_set) { v = other.v; }
}
#else
template <class T> inline void oassign(unsigned& v, const T& other) {
if (other.is_set) { v = other.v; }
}
#endif
struct lzma_compress_config_t
{
typedef OptVar<unsigned, 2u, 0u, 4u> pos_bits_t; // pb
typedef OptVar<unsigned, 0u, 0u, 4u> lit_pos_bits_t; // lb
typedef OptVar<unsigned, 3u, 0u, 8u> lit_context_bits_t; // lc
typedef OptVar<unsigned, (1u<<22), 1u, (1u<<30) > dict_size_t;
typedef OptVar<unsigned, 64u, 5u, 273u> num_fast_bytes_t;
pos_bits_t pos_bits; // pb
lit_pos_bits_t lit_pos_bits; // lp
lit_context_bits_t lit_context_bits; // lc
dict_size_t dict_size;
unsigned fast_mode;
num_fast_bytes_t num_fast_bytes;
unsigned match_finder_cycles;
unsigned max_num_probs;
void reset();
};
struct ucl_compress_config_t : public REAL_ucl_compress_config_t
{
void reset() { memset(this, 0xff, sizeof(*this)); }
};
struct zlib_compress_config_t
{
typedef OptVar<unsigned, 8u, 1u, 9u> mem_level_t; // ml
typedef OptVar<unsigned, 15u, 9u, 15u> window_bits_t; // wb
typedef OptVar<unsigned, 0u, 0u, 4u> strategy_t; // st
mem_level_t mem_level; // ml
window_bits_t window_bits; // wb
strategy_t strategy; // st
void reset();
};
struct upx_compress_config_t
{
lzma_compress_config_t conf_lzma;
ucl_compress_config_t conf_ucl;
zlib_compress_config_t conf_zlib;
void reset() { conf_lzma.reset(); conf_ucl.reset(); conf_zlib.reset(); }
};
#define NULL_cconf ((upx_compress_config_t *) NULL)
/*************************************************************************
// compression - result_t
**************************************************************************/
struct lzma_compress_result_t
{
unsigned pos_bits; // pb
unsigned lit_pos_bits; // lp
unsigned lit_context_bits; // lc
unsigned dict_size;
unsigned fast_mode;
unsigned num_fast_bytes;
unsigned match_finder_cycles;
unsigned num_probs; // (computed result)
void reset() { memset(this, 0, sizeof(*this)); }
};
struct ucl_compress_result_t
{
ucl_uint result[16];
void reset() { memset(this, 0, sizeof(*this)); }
};
struct zlib_compress_result_t
{
unsigned dummy;
void reset() { memset(this, 0, sizeof(*this)); }
};
struct upx_compress_result_t
{
// debug
int method, level;
unsigned u_len, c_len;
lzma_compress_result_t result_lzma;
ucl_compress_result_t result_ucl;
zlib_compress_result_t result_zlib;
void reset() {
memset(this, 0, sizeof(*this));
result_lzma.reset(); result_ucl.reset(); result_zlib.reset();
}
};
/*************************************************************************
@@ -485,9 +703,13 @@ inline void operator delete[](void *p)
#include "console.h"
// classes
class ElfLinker;
typedef ElfLinker Linker;
// main.cpp
extern const char *progname;
void init_options(struct options_t *o);
bool set_ec(int ec);
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void e_exit(int ec) __attribute__((__noreturn__));
@@ -534,7 +756,7 @@ void do_files(int i, int argc, char *argv[]);
// help.cpp
void show_head(void);
void show_help(int x = 0);
void show_help(int verbose=0);
void show_license(void);
void show_usage(void);
void show_version(int);
@@ -544,18 +766,20 @@ void show_version(int);
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler=1);
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc=0);
int upx_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_progress_callback_t *cb,
int upx_compress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
upx_callback_p cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result );
int upx_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method );
int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method );
const upx_compress_config_t *cconf,
upx_compress_result_t *cresult );
int upx_decompress ( const upx_bytep src, unsigned src_len,
upx_bytep dst, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
unsigned src_len, unsigned* dst_len,
int method,
const upx_compress_result_t *cresult );
#endif /* __cplusplus */
+3 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -117,7 +117,7 @@ typedef struct
int (*init)(FILE *f, int, int);
int (*set_fg)(FILE *f, int fg);
void (*print0)(FILE *f, const char *s);
upx_bool (*intro)(FILE *f);
bool (*intro)(FILE *f);
}
console_t;
+7 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -85,6 +85,11 @@ void throwCantPack(const char *msg)
throw CantUnpackException(msg);
}
void throwCantPackExact()
{
throwCantPack("option '--exact' does not work with this file");
}
void throwFilterException()
{
throwCantPack("filter problem");
+3 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -208,6 +208,7 @@ public:
#endif
void throwCantPack(const char *msg) NORET;
void throwCantPackExact() NORET;
void throwUnknownExecutableFormat(const char *msg = NULL, bool warn = false) NORET;
void throwNotCompressible(const char *msg = NULL) NORET;
void throwAlreadyPacked(const char *msg = NULL) NORET;
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+3 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -131,7 +131,7 @@ public:
off_t getBytesWritten() const { return bytes_written; }
// FIXME - these won't work when using the `--stdout' option
// FIXME - these won't work when using the '--stdout' option
virtual void seek(off_t off, int whence)
{
assert(!opt->to_stdout);
+20 -6
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -61,10 +61,10 @@ const FilterImp::FilterEntry *FilterImp::getFilter(int id)
memset(filter_map, 0xff, sizeof(filter_map));
for (int i = 0; i < n_filters; i++)
{
int fid = filters[i].id;
assert(fid >= 0 && fid <= 255);
assert(filter_map[fid] == 0xff);
filter_map[fid] = (unsigned char) i;
int filter_id = filters[i].id;
assert(filter_id >= 0 && filter_id <= 255);
assert(filter_map[filter_id] == 0xff);
filter_map[filter_id] = (unsigned char) i;
}
done = true;
}
@@ -85,6 +85,20 @@ bool Filter::isValidFilter(int filter_id)
return fe != NULL;
}
bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
{
if (!isValidFilter(filter_id))
return false;
if (filter_id == 0)
return true;
if (allowed_filters == NULL)
return false;
while (*allowed_filters != FT_END)
if (*allowed_filters++ == filter_id)
return true;
return false;
}
/*************************************************************************
// high level API
+4 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -62,6 +62,7 @@ public:
bool scan(const upx_byte *buf, unsigned buf_len);
static bool isValidFilter(int filter_id);
static bool isValidFilter(int filter_id, const int *allowed_filters);
public:
// Will be set by each call to filter()/unfilter().
+77 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -383,6 +383,81 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
#undef CT32
/*************************************************************************
// 24-bit ARM calltrick ("naive")
**************************************************************************/
#define CT24ARM_LE(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 4; \
do { \
if (cond) \
{ \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
} \
b += 4; \
} while (b < b_end); \
if (f->lastcall) f->lastcall += 4; \
return 0;
#define ARMCT_COND_le (((b[3] & 0x0f) == 0x0b))
static int f_ct24arm_le(Filter *f)
{
CT24ARM_LE(f, ARMCT_COND_le, a / 4 + f->addvalue, get_le24, set_le24)
}
static int u_ct24arm_le(Filter *f)
{
CT24ARM_LE(f, ARMCT_COND_le, 0 - a / 4 - f->addvalue, get_le24, set_le24)
}
static int s_ct24arm_le(Filter *f)
{
CT24ARM_LE(f, ARMCT_COND_le, a + f->addvalue, get_le24, set_dummy)
}
#undef CT24ARM_LE
#define CT24ARM_BE(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 4; \
do { \
if (cond) \
{ \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(1+b, get(1+b) + (addvalue)); \
f->calls++; \
} \
b += 4; \
} while (b < b_end); \
if (f->lastcall) f->lastcall += 4; \
return 0;
#define ARMCT_COND_be (((b[0] & 0x0f) == 0x0b))
static int f_ct24arm_be(Filter *f)
{
CT24ARM_BE(f, ARMCT_COND_be, a / 4 + f->addvalue, get_be24, set_be24)
}
static int u_ct24arm_be(Filter *f)
{
CT24ARM_BE(f, ARMCT_COND_be, 0 - a / 4 - f->addvalue, get_be24, set_be24)
}
static int s_ct24arm_be(Filter *f)
{
CT24ARM_BE(f, ARMCT_COND_be, a + f->addvalue, get_be24, set_dummy)
}
#undef CT24ARM_BE
#undef ARMCT_COND
/*
vi:ts=4:et:nowrap
+13 -6
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -58,10 +58,18 @@ static int F(Filter *f)
// must not conflict with the mark.
// Note that unsigned comparison checks both edges of buffer.
for (ic = 0; ic < size - 5; ic++)
if (COND(b,ic) && get_le32(b+ic+1)+ic+1 >= size)
{
if (!COND(b,ic))
continue;
jc = get_le32(b+ic+1)+ic+1;
if (jc < size)
{
buf[b[ic+1]] |= 1;
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
return -1;
}
else
buf[b[ic+1]] |= 1;
}
if (getcto(f, buf) < 0)
return -1;
@@ -79,8 +87,7 @@ static int F(Filter *f)
// try to detect 'real' calls only
if (jc < size)
{
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
return 1; // fail - buffer not restored
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
#ifdef U
set_be32(b+ic+1,jc+addvalue+cto);
#endif
+14 -7
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -57,10 +57,18 @@ static int F(Filter *f)
memset(buf,0,256);
for (ic = 0; ic < size - 5; ic++)
if (COND(b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
{
if (!COND(b,ic,lastcall))
continue;
jc = get_le32(b+ic+1)+ic+1;
if (jc < size)
{
buf[b[ic+1]] |= 1;
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
return -1;
}
else
buf[b[ic+1]] |= 1;
}
if (getcto(f, buf) < 0)
return -1;
@@ -78,8 +86,7 @@ static int F(Filter *f)
// try to detect 'real' calls only
if (jc < size)
{
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
return 1; // fail - buffer not restored
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
#ifdef U
set_be32(b+ic+1,jc+addvalue+cto);
#endif
+3 -3
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+14 -7
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -58,10 +58,18 @@ static int F(Filter *f)
memset(buf,0,256);
for (ic = 0; ic < size - 5; ic++)
if (COND(b,ic,lastcall,id) && get_le32(b+ic+1)+ic+1 >= size)
{
if (!COND(b,ic,lastcall,id))
continue;
jc = get_le32(b+ic+1)+ic+1;
if (jc < size)
{
buf[b[ic+1]] |= 1;
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
return -1;
}
else
buf[b[ic+1]] |= 1;
}
if (getcto(f, buf) < 0)
return -1;
@@ -79,8 +87,7 @@ static int F(Filter *f)
// try to detect 'real' calls only
if (jc < size)
{
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
return 1; // fail - buffer not restored
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
#ifdef U
set_be32(b+ic+1,jc+addvalue+cto);
#endif
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+4 -4
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2004-2005 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2004-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -58,7 +58,7 @@ static int F(Filter *f)
{
unsigned char buf[256];
unsigned short wbuf[256];
const size_t WW = (size_t)0 - (~(size_t)0) << W_CTO; // ???
const size_t WW = (size_t)0 - ((~(size_t)0) << W_CTO); // ???
memset(wbuf, 0, sizeof(wbuf));
memset(buf , 0, WW);
memset(buf + WW, 1, 256 - WW);
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+8 -4
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -109,7 +109,7 @@ umin(unsigned const a, unsigned const b)
#define COND1(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
#define COND2(b,x,lc) (lc!=(x) && 0xf==b[(x)-1] && 0x80<=b[x] && b[x]<=0x8f)
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
#define F f_ctok32_e8e9_bswap_le
#define U u_ctok32_e8e9_bswap_le
#include "filter/ctok.h"
@@ -224,6 +224,10 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
{ 0x46, 6, 0x00ffffff, f_ctok32_e8e9_bswap_le, u_ctok32_e8e9_bswap_le, s_ctok32_e8e9_bswap_le },
{ 0x49, 6, 0x00ffffff, f_ctok32_e8e9_bswap_le, u_ctok32_e8e9_bswap_le, s_ctok32_e8e9_bswap_le },
// 24-bit calltrick for arm
{ 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le },
{ 0x51, 8, 0x01ffffff, f_ct24arm_be, u_ct24arm_be, s_ct24arm_be },
// 32-bit cto calltrick with jmp and jcc(swap 0x0f/0x8Y) and relative renumbering
{ 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
{ 0x81, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
+143 -61
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -27,6 +27,9 @@
#include "conf.h"
#include "compress.h"
#include "packmast.h"
#include "packer.h"
/*************************************************************************
@@ -48,7 +51,7 @@ void show_head(void)
fg = con_fg(f,FG_GREEN);
con_fprintf(f,
" Ultimate Packer for eXecutables\n"
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006\n"
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007\n"
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
V("d"),
@@ -88,7 +91,77 @@ void show_usage(void)
//
**************************************************************************/
void show_help(int x)
struct PackerNames
{
struct Entry {
const char* fname;
const char* sname;
};
Entry names[32];
size_t names_count;
const options_t *o;
PackerNames() : names_count(0), o(NULL) { }
void add(const Packer *p)
{
p->assertPacker();
assert(names_count < 32);
names[names_count].fname = p->getFullName(o);
names[names_count].sname = p->getName();
names_count++;
}
static Packer* visit(Packer *p, void *user)
{
PackerNames *self = (PackerNames *) user;
self->add(p);
return NULL;
}
static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) {
return strcmp(((const Entry *) a)->fname, ((const Entry *) b)->fname);
}
static int __acc_cdecl_qsort cmp_sname(const void *a, const void *b) {
return strcmp(((const Entry *) a)->sname, ((const Entry *) b)->sname);
}
};
static void show_all_packers(FILE *f, int verbose)
{
options_t o; o.reset();
PackerNames pn; pn.o = &o;
PackMaster::visitAllPackers(pn.visit, NULL, &o, &pn);
qsort(pn.names, pn.names_count, sizeof(PackerNames::Entry), pn.cmp_fname);
size_t pos = 0;
for (size_t i = 0; i < pn.names_count; ++i)
{
const char *fn = pn.names[i].fname;
const char *sn = pn.names[i].sname;
if (verbose)
{
con_fprintf(f, " %-32s %s\n", fn, sn);
}
else
{
if (pos == 0) {
con_fprintf(f, " %s", fn);
pos = 2 + strlen(fn);
} else if (pos + 1 + strlen(fn) > 80) {
con_fprintf(f, "\n %s", fn);
pos = 2 + strlen(fn);
} else {
con_fprintf(f, " %s", fn);
pos += 1 + strlen(fn);
}
}
}
if (!verbose && pn.names_count)
con_fprintf(f, "\n");
}
/*************************************************************************
//
**************************************************************************/
void show_help(int verbose)
{
FILE *f = con_term;
int fg;
@@ -105,8 +178,8 @@ void show_help(int x)
" -d decompress -l list compressed file\n"
" -t test compressed file -V display version number\n"
" -h give %s help -L display software license\n%s",
x == 0 ? "" : " --best compress best (can be slow for big files)\n",
x == 0 ? "more" : "this", x == 0 ? "" : "\n");
verbose == 0 ? "" : " --best compress best (can be slow for big files)\n",
verbose == 0 ? "more" : "this", verbose == 0 ? "" : "\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options:\n");
@@ -114,22 +187,29 @@ void show_help(int x)
con_fprintf(f,
" -q be quiet -v be verbose\n"
" -oFILE write output to `FILE'\n"
" -oFILE write output to 'FILE'\n"
//" -f force overwrite of output files and compression of suspicious files\n"
" -f force compression of suspicious files\n"
"%s%s"
, (x == 0) ? " -k keep backup files\n" : ""
, (verbose == 0) ? " -k keep backup files\n" : ""
#if 1
, (x > 0) ? " --no-color, --mono, --color, --no-progress change look\n" : ""
, (verbose > 0) ? " --no-color, --mono, --color, --no-progress change look\n" : ""
#else
, ""
#endif
);
if (x > 0)
if (verbose > 0)
{
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"\nBackup options:\n");
con_fprintf(f,"\nCompression tuning options:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --brute try all available compression methods & filters\n"
" --ultra-brute try even more compression variants\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Backup options:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" -k, --backup keep backup files\n"
@@ -196,7 +276,8 @@ void show_help(int x)
con_fprintf(f,
" --all-methods try all available compression methods\n"
" --8-bit uses 8 bit size compression [default: 32 bit]\n"
" --console-run enables client/host transfer compatibility\n"
" --8mb-ram 8 megabyte memory limit [default: 2 mb]\n"
" --boot-only disables client/host transfer compatibility\n"
" --no-align don't align to 2048 bytes [enables: --console-run]\n"
"\n");
fg = con_fg(f,FG_YELLOW);
@@ -220,7 +301,7 @@ void show_help(int x)
" --le produce LE output [default: EXE]\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for win32/pe & rtm32/pe:\n");
con_fprintf(f,"Options for win32/pe, rtm32/pe & arm/pe:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --compress-exports=0 do not compress the export section\n"
@@ -228,7 +309,9 @@ void show_help(int x)
" --compress-icons=0 do not compress any icons\n"
" --compress-icons=1 compress all but the first icon\n"
" --compress-icons=2 compress all but the first icon directory [default]\n"
" --compress-icons=3 compress all icons\n"
" --compress-resources=0 do not compress any resources at all\n"
" --keep-resource=list do not compress resources specified by list\n"
" --strip-relocs=0 do not strip relocations\n"
" --strip-relocs=1 strip relocations [default]\n"
" --all-methods try all available compression methods\n"
@@ -236,42 +319,23 @@ void show_help(int x)
"\n");
}
con_fprintf(f,
"file.. executables to (de)compress\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"This version supports:\n");
fg = con_fg(f,fg);
con_fprintf(f," "
// TODO:
// support for mach/ppc32
// support for linux elf/ppc32
// support for linux elf/amd64
" arm/pe,"
" atari/tos,"
" bvmlinuz/386,"
" djgpp2/coff,"
" dos/com,"
" dos/exe,"
" dos/sys,"
"\n "
//" elks/8086,"
" linux/386,"
" linux/elf386,"
" linux/sh386,"
" ps1/exe,"
" rtm32/pe,"
" tmt/adam,"
"\n "
" vmlinux/386,"
" vmlinuz/386,"
" watcom/le,"
//" win16/ne,"
" win32/pe"
"\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net\n"
// "\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details type `upx -L'.\n"
"");
con_fprintf(f, "file.. executables to (de)compress\n");
if (verbose > 0)
{
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"\nThis version supports:\n");
fg = con_fg(f,fg);
show_all_packers(f, verbose);
}
else
{
con_fprintf(f,"\nType '%s --help' for more detailed help.\n", progname);
}
con_fprintf(f,"\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net\n"
// "\nUPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.\n"
"");
#if defined(DEBUG) || defined(TESTING)
fg = con_fg(f,FG_RED);
@@ -337,25 +401,43 @@ void show_license(void)
void show_version(int x)
{
FILE *f = stdout;
FILE *fp = stdout;
const char *v;
UNUSED(x);
UNUSED(v);
#if (0 && ACC_CC_GNUC)
fprintf(f,"upx %s (gcc 0x%06lx)\n", UPX_VERSION_STRING, ACC_CC_GNUC);
#else
fprintf(f,"upx %s\n", UPX_VERSION_STRING);
#endif
fprintf(fp, "upx %s\n", UPX_VERSION_STRING);
#if defined(WITH_NRV)
fprintf(f,"NRV data compression library %s\n", nrv_version_string());
v = upx_nrv_version_string();
if (v != NULL && v[0])
fprintf(fp, "NRV data compression library %s\n", v);
#endif
#if defined(WITH_UCL)
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
v = upx_ucl_version_string();
if (v != NULL && v[0])
fprintf(fp, "UCL data compression library %s\n", v);
#endif
fprintf(f,"Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(f,"Copyright (C) 1996-2006 Laszlo Molnar\n");
fprintf(f,"Copyright (C) 2000-2006 John F. Reiser\n");
fprintf(f,"Copyright (C) 2002-2006 Jens Medoch\n");
fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
#if defined(WITH_ZLIB)
v = upx_zlib_version_string();
if (v != NULL && v[0])
fprintf(fp, "zlib data compression library %s\n", v);
#endif
#if defined(WITH_LZMA)
v = upx_lzma_version_string();
if (v != NULL && v[0])
fprintf(fp, "LZMA SDK version %s\n", v);
#endif
fprintf(fp, "Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(fp, "Copyright (C) 1996-2007 Laszlo Molnar\n");
fprintf(fp, "Copyright (C) 2000-2007 John F. Reiser\n");
fprintf(fp, "Copyright (C) 2002-2007 Jens Medoch\n");
#if defined(WITH_ZLIB)
fprintf(fp, "Copyright (C) 1995" "-2005 Jean-loup Gailly and Mark Adler\n");
#endif
#if defined(WITH_LZMA)
fprintf(fp, "Copyright (C) 1999" "-2006 Igor Pavlov\n");
#endif
fprintf(fp, "UPX comes with ABSOLUTELY NO WARRANTY; for details type '%s -L'.\n", progname);
}
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+776 -168
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -29,108 +29,361 @@
#include "conf.h"
#include "linker.h"
class LinkerLabel
{
enum { LINKER_MAX_LABEL_LEN = 32 };
char label[LINKER_MAX_LABEL_LEN + 1];
public:
unsigned set(const char *l)
{
strncpy(label, l, sizeof(label));
return strlen(label) + 1;
}
operator const char *() const { return label; }
};
struct Linker::section
{
int istart;
int ostart;
int len;
LinkerLabel name;
};
struct Linker::jump
{
int pos;
int len;
int toffs;
LinkerLabel tsect;
};
Linker::Linker(const void *pdata, int plen, int pinfo)
{
iloader = new char[(ilen = plen) + 8192];
memcpy(iloader,pdata,plen);
oloader = new char[plen];
olen = 0;
align_hack = 0;
align_offset = 0;
info = pinfo;
njumps = nsections = frozen = 0;
jumps = new jump[200];
#define NSECTIONS 550
sections = new section[NSECTIONS];
char *p = iloader + info;
while (get32(p) != (unsigned)(-1))
{
if (get32(p))
{
p += sections[nsections].name.set(p);
sections[nsections].istart = get32(p);
sections[nsections++].ostart = -1;
p += 4;
assert(nsections < NSECTIONS);
}
else
{
int l;
for (l = get32(p+4) - 1; iloader[l] == 0; l--)
;
jumps[njumps].pos = l+1;
jumps[njumps].len = get32(p+4)-jumps[njumps].pos;
p += 8 + jumps[njumps].tsect.set(p + 8);
jumps[njumps++].toffs = get32(p);
p += 4;
assert(njumps < 200);
}
}
int ic;
for (ic = 0; ic < nsections - 1; ic++)
sections[ic].len = sections[ic+1].istart - sections[ic].istart;
sections[ic].len = 0;
}
Linker::~Linker()
{
delete [] iloader;
delete [] oloader;
delete [] jumps;
delete [] sections;
}
void Linker::setLoaderAlignOffset(int offset)
{
align_offset = offset;
}
static int hex(char c)
static unsigned hex(unsigned char c)
{
return (c & 0xf) + (c > '9' ? 9 : 0);
}
int Linker::addSection(const char *psect)
static bool update_capacity(unsigned size, unsigned *capacity)
{
if (psect[0] == 0)
return olen;
char *begin = strdup(psect);
if (size < *capacity)
return false;
if (*capacity == 0)
*capacity = 16;
while (size >= *capacity)
*capacity *= 2;
return true;
}
/*************************************************************************
// Section
**************************************************************************/
ElfLinker::Section::Section(const char *n, const void *i, unsigned s, unsigned a) :
name(NULL), output(NULL), size(s), offset(0), p2align(a), next(NULL)
{
name = strdup(n);
assert(name != NULL);
input = malloc(s + 1);
assert(input != NULL);
memcpy(input, i, s);
((char *)input)[s] = 0;
}
ElfLinker::Section::~Section()
{
free(name);
free(input);
}
/*************************************************************************
// Symbol
**************************************************************************/
ElfLinker::Symbol::Symbol(const char *n, Section *s, unsigned o) :
name(NULL), section(s), offset(o)
{
name = strdup(n);
assert(name != NULL);
assert(section != NULL);
}
ElfLinker::Symbol::~Symbol()
{
free(name);
}
/*************************************************************************
// Relocation
**************************************************************************/
ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t,
const Symbol *v, unsigned a) :
section(s), offset(o), type(t), value(v), add(a)
{
assert(section != NULL);
}
/*************************************************************************
// ElfLinker
**************************************************************************/
ElfLinker::ElfLinker() :
bele(&N_BELE_RTP::le_policy),
input(NULL), output(NULL), head(NULL), tail(NULL),
sections(NULL), symbols(NULL), relocations(NULL),
nsections(0), nsections_capacity(0),
nsymbols(0), nsymbols_capacity(0),
nrelocations(0), nrelocations_capacity(0),
reloc_done(false)
{
}
ElfLinker::~ElfLinker()
{
delete [] input;
delete [] output;
unsigned ic;
for (ic = 0; ic < nsections; ic++)
delete sections[ic];
free(sections);
for (ic = 0; ic < nsymbols; ic++)
delete symbols[ic];
free(symbols);
for (ic = 0; ic < nrelocations; ic++)
delete relocations[ic];
free(relocations);
}
void ElfLinker::init(const void *pdata_v, int plen)
{
const upx_byte *pdata = (const upx_byte *) pdata_v;
if (plen >= 16 && memcmp(pdata, "UPX#", 4) == 0)
{
// decompress pre-compressed stub-loader
int method;
unsigned u_len, c_len;
if (pdata[4])
{
method = pdata[4];
u_len = get_le16(pdata + 5);
c_len = get_le16(pdata + 7);
pdata += 9;
assert(9 + c_len == (unsigned) plen);
}
else
{
method = pdata[5];
u_len = get_le32(pdata + 6);
c_len = get_le32(pdata + 10);
pdata += 14;
assert(14 + c_len == (unsigned) plen);
}
assert((unsigned) plen < u_len);
inputlen = u_len;
input = new upx_byte[inputlen + 1];
unsigned new_len = u_len;
int r = upx_decompress(pdata, c_len, input, &new_len, method, NULL);
if (r != 0 || new_len != u_len)
throwBadLoader();
}
else
{
inputlen = plen;
input = new upx_byte[inputlen + 1];
memcpy(input, pdata, inputlen);
}
input[inputlen] = 0; // NUL terminate
output = new upx_byte[inputlen];
outputlen = 0;
int pos = find(input, inputlen, "Sections:\n", 10);
assert(pos != -1);
char *psections = (char *) input + pos;
char *psymbols = strstr(psections, "SYMBOL TABLE:\n");
assert(psymbols != NULL);
char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR ");
assert(prelocs != NULL);
preprocessSections(psections, psymbols);
preprocessSymbols(psymbols, prelocs);
preprocessRelocations(prelocs, (char*) input + inputlen);
addLoader("*UND*");
}
void ElfLinker::preprocessSections(char *start, char *end)
{
nsections = 0;
while (start < end)
{
char name[1024];
unsigned offset, size, align;
char *nextl = strchr(start, '\n');
assert(nextl != NULL);
if (sscanf(start, "%*d %1023s %x %*d %*d %x 2**%d",
name, &size, &offset, &align) == 4)
{
char *n = strstr(start, name);
n[strlen(name)] = 0;
addSection(n, input + offset, size, align);
//printf("section %s preprocessed\n", n);
}
start = nextl + 1;
}
addSection("*ABS*", NULL, 0, 0);
addSection("*UND*", NULL, 0, 0);
}
void ElfLinker::preprocessSymbols(char *start, char *end)
{
nsymbols = 0;
while (start < end)
{
char section[1024];
char symbol[1024];
unsigned value, offset;
char *nextl = strchr(start, '\n');
assert(nextl != NULL);
if (sscanf(start, "%x g *ABS* %x %1023s",
&value, &offset, symbol) == 3)
{
char *s = strstr(start, symbol);
s[strlen(symbol)] = 0;
addSymbol(s, "*ABS*", value);
assert(offset == 0);
}
else if (sscanf(start, "%x%*8c %1023s %*x %1023s",
&offset, section, symbol) == 3)
{
char *s = strstr(start, symbol);
s[strlen(symbol)] = 0;
if (strcmp(section, "*UND*") == 0)
offset = 0xdeaddead;
assert(strcmp(section, "*ABS*") != 0);
addSymbol(s, section, offset);
}
start = nextl + 1;
}
}
void ElfLinker::preprocessRelocations(char *start, char *end)
{
char sect[1024];
Section *section = NULL;
nrelocations = 0;
while (start < end)
{
if (sscanf(start, "RELOCATION RECORDS FOR [%[^]]", sect) == 1)
section = findSection(sect);
unsigned offset;
char type[100];
char symbol[1024];
char *nextl = strchr(start, '\n');
assert(nextl != NULL);
if (sscanf(start, "%x %99s %1023s",
&offset, type, symbol) == 3)
{
char *t = strstr(start, type);
t[strlen(type)] = 0;
unsigned add = 0;
if (char *p = strstr(symbol, "+0x"))
{
*p = 0; // terminate the symbol name
p += 3;
if (strlen(p) == 16) {
// skip 8 leading chars if sign of char 9 matches
if (memcmp(p, "000000000", 9))
p += 8;
else if (memcmp(p, "fffffffff", 9))
p += 8;
}
assert(strlen(p) == 8);
char *endptr = NULL;
unsigned long ul = strtoul(p, &endptr, 16);
add = (unsigned) ul;
assert(add == ul);
assert(endptr && *endptr == '\0');
}
addRelocation(section->name, offset, t, symbol, add);
//printf("relocation %s %s %x %d preprocessed\n", section->name, symbol, offset, add);
}
start = nextl + 1;
}
}
ElfLinker::Section *ElfLinker::findSection(const char *name, bool fatal) const
{
for (unsigned ic = 0; ic < nsections; ic++)
if (strcmp(sections[ic]->name, name) == 0)
return sections[ic];
if (fatal)
{
printf("unknown section %s\n", name);
abort();
}
return NULL;
}
ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const
{
for (unsigned ic = 0; ic < nsymbols; ic++)
if (strcmp(symbols[ic]->name, name) == 0)
return symbols[ic];
if (fatal)
{
printf("unknown symbol %s\n", name);
abort();
}
return NULL;
}
ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata, int slen, unsigned p2align)
{
//printf("addSection: %s len=%d align=%d\n", sname, slen, p2align);
if (update_capacity(nsections, &nsections_capacity))
sections = static_cast<Section **>(realloc(sections, nsections_capacity * sizeof(Section *)));
assert(sections);
assert(sname); assert(sname[0]); assert(sname[strlen(sname)-1] != ':');
assert(findSection(sname, false) == NULL);
Section *sec = new Section(sname, sdata, slen, p2align);
sections[nsections++] = sec;
return sec;
}
ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
unsigned offset)
{
//printf("addSymbol: %s %s 0x%x\n", name, section, offset);
if (update_capacity(nsymbols, &nsymbols_capacity))
symbols = static_cast<Symbol **>(realloc(symbols, nsymbols_capacity * sizeof(Symbol *)));
assert(symbols != NULL);
assert(name); assert(name[0]); assert(name[strlen(name)-1] != ':');
assert(findSymbol(name, false) == NULL);
Symbol *sym = new Symbol(name, findSection(section), offset);
symbols[nsymbols++] = sym;
return sym;
}
ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned off,
const char *type, const char *symbol,
unsigned add)
{
if (update_capacity(nrelocations, &nrelocations_capacity))
relocations = static_cast<Relocation **>(realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *)));
assert(relocations != NULL);
Relocation *rel = new Relocation(findSection(section), off,
type, findSymbol(symbol), add);
relocations[nrelocations++] = rel;
return rel;
}
#if 0
void ElfLinker::setLoaderAlignOffset(int phase)
{
//assert(phase & 0);
printf("\nFIXME: ElfLinker::setLoaderAlignOffset %d\n", phase);
}
#endif
int ElfLinker::addLoader(const char *sname)
{
assert(sname != NULL);
if (!sname[0])
return outputlen;
char *begin = strdup(sname);
char *end = begin + strlen(begin);
for (char *sect = begin; sect < end; )
{
@@ -141,102 +394,457 @@ int Linker::addSection(const char *psect)
break;
}
if (*sect == '+') // alignment
if (sect[0] == '+') // alignment
{
if (sect[1] == '0')
align_hack = olen + align_offset;
else
assert(tail);
unsigned l = (hex(sect[2]) - tail->offset - tail->size) % hex(sect[1]);
if (l)
{
unsigned j = hex(sect[1]);
j = (hex(sect[2]) - ((olen + align_offset) - align_hack) ) % j;
memset(oloader+olen, (sect[3] == 'C' ? 0x90 : 0), j);
olen += j;
if (sect[3] == 'D')
alignData(l);
else
alignCode(l);
tail->size += l;
}
}
else
{
int ic;
for (ic = 0; ic < nsections; ic++)
if (strcmp(sect, sections[ic].name) == 0)
{
memcpy(oloader+olen,iloader+sections[ic].istart,sections[ic].len);
sections[ic].ostart = olen;
olen += sections[ic].len;
break;
Section *section = findSection(sect);
if (section->p2align) {
assert(tail);
assert(tail != section);
unsigned const v = ~0u << section->p2align;
if (unsigned const l = ~v & (0u-(tail->offset + tail->size))) {
alignCode(l);
tail->size += l;
}
if (ic == nsections)
printf("%s", sect);
assert(ic != nsections);
}
memcpy(output + outputlen, section->input, section->size);
section->output = output + outputlen;
//printf("section added: 0x%04x %3d %s\n", outputlen, section->size, section->name);
outputlen += section->size;
if (head)
{
tail->next = section;
section->offset = tail->offset + tail->size;
}
else
head = section;
tail = section;
}
sect += strlen(sect) + 1;
}
free(begin);
return olen;
return outputlen;
}
void Linker::addSection(const char *sname, const void *sdata, unsigned len)
int ElfLinker::getSection(const char *sname, int *slen) const
{
// add a new section - can be used for adding stuff like ident or header
sections[nsections].name.set(sname);
sections[nsections].istart = ilen;
sections[nsections].len = len;
sections[nsections++].ostart = olen;
assert(nsections < NSECTIONS);
memcpy(iloader+ilen,sdata,len);
ilen += len;
const Section *section = findSection(sname);
if (slen)
*slen = section->size;
return section->output - output;
}
const char *Linker::getLoader(int *llen)
int ElfLinker::getSectionSize(const char *sname) const
{
if (!frozen)
const Section *section = findSection(sname);
return section->size;
}
upx_byte *ElfLinker::getLoader(int *llen) const
{
if (llen)
*llen = outputlen;
return output;
}
void ElfLinker::relocate()
{
assert(!reloc_done);
reloc_done = true;
for (unsigned ic = 0; ic < nrelocations; ic++)
{
int ic,jc,kc;
for (ic = 0; ic < njumps; ic++)
const Relocation *rel = relocations[ic];
unsigned value;
if (rel->section->output == NULL)
continue;
if (strcmp(rel->value->section->name, "*ABS*") == 0)
{
for (jc = 0; jc < nsections-1; jc++)
if (jumps[ic].pos >= sections[jc].istart
&& jumps[ic].pos < sections[jc+1].istart)
break;
assert(jc!=nsections-1);
if (sections[jc].ostart < 0)
continue;
for (kc = 0; kc < nsections-1; kc++)
if (strcmp(jumps[ic].tsect,sections[kc].name) == 0)
break;
assert(kc!=nsections-1);
int offs = sections[kc].ostart+jumps[ic].toffs -
(jumps[ic].pos+jumps[ic].len -
sections[jc].istart+sections[jc].ostart);
if (jumps[ic].len == 1)
assert(-128 <= offs && offs <= 127);
set32(&offs,offs);
memcpy(oloader+sections[jc].ostart+jumps[ic].pos-sections[jc].istart,&offs,jumps[ic].len);
value = rel->value->offset;
}
frozen=1;
else if (strcmp(rel->value->section->name, "*UND*") == 0 &&
rel->value->offset == 0xdeaddead)
{
printf("undefined symbol '%s' referenced\n", rel->value->name);
abort();
}
else if (rel->value->section->output == NULL)
{
printf("can not apply reloc '%s:%x' without section '%s'\n",
rel->section->name, rel->offset,
rel->value->section->name);
abort();
}
else
{
value = rel->value->section->offset +
rel->value->offset + rel->add;
}
upx_byte *location = rel->section->output + rel->offset;
//printf("%-28s %-28s %-10s 0x%08x 0x%08x\n", rel->section->name, rel->value->name, rel->type, value, value - rel->section->offset - rel->offset);
//printf(" %d %d %d %d %d : %d\n", value, rel->value->section->offset, rel->value->offset, rel->offset, rel->add, *location);
relocate1(rel, location, value, rel->type);
}
if (llen) *llen = olen;
return oloader;
}
void ElfLinker::defineSymbol(const char *name, unsigned value)
{
Symbol *symbol = findSymbol(name);
if (strcmp(symbol->section->name, "*ABS*") == 0)
{
printf("defineSymbol: symbol '%s' is *ABS*\n", name);
abort();
}
else if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols
symbol->offset = value;
else if (strcmp(symbol->section->name, name) == 0) // for sections
{
for (Section *section = symbol->section; section; section = section->next)
{
assert(section->offset < value);
section->offset = value;
value += section->size;
}
}
else
{
printf("defineSymbol: symbol '%s' already defined\n", name);
abort();
}
}
// debugging support
void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const
{
if ((flags & 1) && symbol->section->output == NULL)
return;
fprintf(fp, "%-28s 0x%08x | %-28s 0x%08x\n",
symbol->name, symbol->offset, symbol->section->name, symbol->section->offset);
}
void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
{
if (fp == NULL)
fp = stdout;
if ((flags & 2) == 0)
{
// default: dump symbols in used section order
for (const Section *section = head; section; section = section->next)
{
fprintf(fp, "%-42s%-28s 0x%08x\n", "", section->name, section->offset);
for (unsigned ic = 0; ic < nsymbols; ic++)
{
const Symbol *symbol = symbols[ic];
if (symbol->section == section && strcmp(symbol->name, section->name) != 0)
dumpSymbol(symbol, flags, fp);
}
}
}
else
{
// dump all symbols
for (unsigned ic = 0; ic < nsymbols; ic++)
dumpSymbol(symbols[ic], flags, fp);
}
}
unsigned ElfLinker::getSymbolOffset(const char *name) const
{
const Symbol *symbol = findSymbol(name);
if (symbol->section->output == NULL)
return 0xdeaddead;
return symbol->section->offset + symbol->offset;
}
void ElfLinker::alignWithByte(unsigned len, unsigned char b)
{
memset(output + outputlen, b, len);
outputlen += len;
}
void ElfLinker::relocate1(const Relocation *rel, upx_byte *,
unsigned, const char *)
{
printf("unknown relocation type '%s\n", rel->type);
abort();
}
int Linker::getSection(const char *name, int *slen) const
/*************************************************************************
// ElfLinker arch subclasses
// FIXME: add more displacment overflow checks
**************************************************************************/
#if 0 // FIXME
static void check8(const Relocation *rel, const upx_byte *location, int v, int d)
{
if (!frozen)
return -1;
for (int ic = 0; ic < nsections; ic++)
if (strcmp(name, sections[ic].name) == 0)
if (v < -128 || v > 127) {
printf("value out of range (%d) in reloc %s:%x\n",
v, rel->section->name, rel->offset);
abort();
}
if (d < -128 || d > 127) {
printf("displacement target out of range (%d) in reloc %s:%x\n",
v, rel->section->name, rel->offset);
abort();
}
}
#endif
void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type)
{
if (strncmp(type, "R_X86_64_", 9))
return super::relocate1(rel, location, value, type);
type += 9;
if (strncmp(type, "PC", 2) == 0)
{
value -= rel->section->offset + rel->offset;
type += 2;
}
if (strcmp(type, "8") == 0)
{
#if (ACC_CC_PGI)
int displ = * (signed char *) location + (int) value; // CBUG
#else
int displ = (signed char) *location + (int) value;
#endif
if (displ < -128 || displ > 127)
{
if (slen)
*slen = sections[ic].len;
return sections[ic].ostart;
printf("target out of range (%d) in reloc %s:%x\n",
displ, rel->section->name, rel->offset);
abort();
}
return -1;
*location += value;
}
else if (strcmp(type, "16") == 0)
set_le16(location, get_le16(location) + value);
else if (strcmp(type, "32") == 0)
set_le32(location, get_le32(location) + value);
else
super::relocate1(rel, location, value, type);
}
void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type)
{
if (strcmp(type, "R_ARM_PC24") == 0)
{
value -= rel->section->offset + rel->offset;
set_be24(1+ location, get_be24(1+ location) + value / 4);
}
else if (strcmp(type, "R_ARM_ABS32") == 0)
{
set_be32(location, get_be32(location) + value);
}
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
{
value -= rel->section->offset + rel->offset;
value += ((get_be16(location) & 0x7ff) << 12);
value += (get_be16(location + 2) & 0x7ff) << 1;
set_be16(location, 0xf000 + ((value >> 12) & 0x7ff));
set_be16(location + 2, 0xf800 + ((value >> 1) & 0x7ff));
//(b, 0xF000 + ((v - 1) / 2) * 0x10000);
//set_be32(location, get_be32(location) + value / 4);
}
else if (0==strcmp("R_ARM_ABS8", type)) {
*location += value;
}
else
super::relocate1(rel, location, value, type);
}
void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type)
{
if (strcmp(type, "R_ARM_PC24") == 0)
{
value -= rel->section->offset + rel->offset;
set_le24(location, get_le24(location) + value / 4);
}
else if (strcmp(type, "R_ARM_ABS32") == 0)
{
set_le32(location, get_le32(location) + value);
}
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
{
value -= rel->section->offset + rel->offset;
value += ((get_le16(location) & 0x7ff) << 12);
value += (get_le16(location + 2) & 0x7ff) << 1;
set_le16(location, 0xf000 + ((value >> 12) & 0x7ff));
set_le16(location + 2, 0xf800 + ((value >> 1) & 0x7ff));
//(b, 0xF000 + ((v - 1) / 2) * 0x10000);
//set_le32(location, get_le32(location) + value / 4);
}
else if (0==strcmp("R_ARM_ABS8", type)) {
*location += value;
}
else
super::relocate1(rel, location, value, type);
}
void ElfLinkerM68k::alignCode(unsigned len)
{
assert((len & 1) == 0);
assert((outputlen & 1) == 0);
for (unsigned i = 0; i < len; i += 2)
set_be16(output + outputlen + i, 0x4e71); // "nop"
outputlen += len;
}
void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type)
{
if (strncmp(type, "R_68K_", 6))
return super::relocate1(rel, location, value, type);
type += 6;
if (strncmp(type, "PC", 2) == 0)
{
value -= rel->section->offset + rel->offset;
type += 2;
}
if (strcmp(type, "8") == 0) {
*location += value;
}
else if (strcmp(type, "16") == 0) {
set_be16(location, get_be16(location) + value);
}
else if (strcmp(type, "32") == 0) {
set_be32(location, get_be32(location) + value);
}
else
super::relocate1(rel, location, value, type);
}
void ElfLinkerMipsLE::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_le16(location, get_le16(location) + MIPS_HI(value));
else if (strcmp(type, "R_MIPS_LO16") == 0)
set_le16(location, get_le16(location) + MIPS_LO(value));
else if (strcmp(type, "R_MIPS_PC16") == 0)
{
value -= rel->section->offset + rel->offset;
set_le16(location, get_le16(location) + MIPS_PC16(value));
}
else if (strcmp(type, "R_MIPS_26") == 0)
set_le32(location, get_le32(location) + MIPS_PC26(value));
else if (strcmp(type, "R_MIPS_32") == 0)
set_le32(location, get_le32(location) + value);
else
super::relocate1(rel, location, value, type);
#undef MIPS_HI
#undef MIPS_LO
#undef MIPS_PC16
#undef MIPS_PC26
}
void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type)
{
if (strncmp(type, "R_PPC_", 6))
return super::relocate1(rel, location, value, type);
type += 6;
if (strncmp(type, "REL", 3) == 0)
{
value -= rel->section->offset + rel->offset;
type += 3;
}
// FIXME: more relocs
// Note that original (*location).displ is ignored.
if (strcmp(type, "24") == 0) {
if (3& value) {
printf("unaligned word diplacement");
abort();
}
// FIXME: displacment overflow?
set_be32(location, (0xfc000003 & get_be32(location)) +
(0x03fffffc & value));
}
else if (strcmp(type, "14") == 0) {
if (3& value) {
printf("unaligned word diplacement");
abort();
}
// FIXME: displacment overflow?
set_be32(location, (0xffff0003 & get_be32(location)) +
(0x0000fffc & value));
}
else
super::relocate1(rel, location, value, type);
}
void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location,
unsigned value, const char *type)
{
if (strncmp(type, "R_386_", 6))
return super::relocate1(rel, location, value, type);
type += 6;
bool range_check = false;
if (strncmp(type, "PC", 2) == 0)
{
value -= rel->section->offset + rel->offset;
type += 2;
range_check = true;
}
if (strcmp(type, "8") == 0)
{
#if (ACC_CC_PGI)
int displ = * (signed char *) location + (int) value; // CBUG
#else
int displ = (signed char) *location + (int) value;
#endif
if (range_check && (displ < -128 || displ > 127)) {
printf("target out of range (%d,%d,%d) in reloc %s:%x\n",
displ, *location, value, rel->section->name, rel->offset);
abort();
}
*location += value;
}
else if (strcmp(type, "16") == 0)
set_le16(location, get_le16(location) + value);
else if (strcmp(type, "32") == 0)
set_le32(location, get_le32(location) + value);
else
super::relocate1(rel, location, value, type);
}
+178 -46
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -30,64 +30,196 @@
#define __UPX_LINKER_H
class Linker
/*************************************************************************
// ElfLinker
**************************************************************************/
class ElfLinker : private nocopy
{
friend class Packer;
public:
Linker(const void *pdata, int plen, int pinfo);
virtual ~Linker();
int addSection(const char *sect);
void addSection(const char *sname, const void *sdata, unsigned len);
const char *getLoader(int *llen);
int getSection(const char *name, int *slen) const;
int getLoaderSize() const { return olen; }
void setLoaderAlignOffset(int phase);
const N_BELE_RTP::AbstractPolicy *bele;
protected:
struct Section;
struct Symbol;
struct Relocation;
upx_byte *input;
int inputlen;
upx_byte *output;
int outputlen;
Section *head;
Section *tail;
Section **sections;
Symbol **symbols;
Relocation **relocations;
unsigned nsections;
unsigned nsections_capacity;
unsigned nsymbols;
unsigned nsymbols_capacity;
unsigned nrelocations;
unsigned nrelocations_capacity;
bool reloc_done;
protected:
// little endian
virtual unsigned get32(const void *b) const { return get_le32(b); }
virtual void set32(void *b, unsigned v) const { set_le32(b, v); }
void preprocessSections(char *start, char *end);
void preprocessSymbols(char *start, char *end);
void preprocessRelocations(char *start, char *end);
Section *findSection(const char *name, bool fatal=true) const;
Symbol *findSymbol(const char *name, bool fatal=true) const;
private:
struct section;
struct jump;
Symbol *addSymbol(const char *name, const char *section, unsigned offset);
Relocation *addRelocation(const char *section, unsigned off, const char *type,
const char *symbol, unsigned add);
char *iloader, *oloader;
int ilen, olen;
int info;
jump *jumps;
int njumps;
section *sections;
int nsections;
int frozen;
int align_hack;
int align_offset;
public:
ElfLinker();
virtual ~ElfLinker();
private:
// disable copy and assignment
Linker(const Linker &); // {}
Linker& operator= (const Linker &); // { return *this; }
virtual void init(const void *pdata, int plen);
//virtual void setLoaderAlignOffset(int phase);
virtual int addLoader(const char *sname);
virtual Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align);
virtual int getSection(const char *sname, int *slen=NULL) const;
virtual int getSectionSize(const char *sname) const;
virtual upx_byte *getLoader(int *llen=NULL) const;
virtual void defineSymbol(const char *name, unsigned value);
virtual unsigned getSymbolOffset(const char *) const;
virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const;
virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const;
void alignWithByte(unsigned len, unsigned char b);
virtual void alignCode(unsigned len) { alignWithByte(len, 0); }
virtual void alignData(unsigned len) { alignWithByte(len, 0); }
protected:
virtual void relocate();
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class BeLinker : public Linker
struct ElfLinker::Section : private nocopy
{
typedef Linker super;
public:
BeLinker(const void *pdata, int plen, int pinfo) :
super(pdata, plen, pinfo) { }
char *name;
void *input;
upx_byte *output;
unsigned size;
unsigned offset;
unsigned p2align; // log2
Section *next;
protected:
// big endian
virtual unsigned get32(const void *b) const { return get_be32(b); }
virtual void set32(void *b, unsigned v) const { set_be32(b, v); }
private:
// disable copy and assignment
BeLinker(const BeLinker &); // {}
BeLinker& operator= (const BeLinker &); // { return *this; }
Section(const char *n, const void *i, unsigned s, unsigned a=0);
~Section();
};
struct ElfLinker::Symbol : private nocopy
{
char *name;
Section *section;
unsigned offset;
Symbol(const char *n, Section *s, unsigned o);
~Symbol();
};
struct ElfLinker::Relocation : private nocopy
{
const Section *section;
unsigned offset;
const char *type;
const Symbol *value;
unsigned add; // used in .rela relocations
Relocation(const Section *s, unsigned o, const char *t,
const Symbol *v, unsigned a);
};
/*************************************************************************
// ElfLinker arch subclasses
**************************************************************************/
class ElfLinkerAMD64 : public ElfLinker
{
typedef ElfLinker super;
protected:
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class ElfLinkerArmBE : public ElfLinker
{
typedef ElfLinker super;
public:
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
protected:
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class ElfLinkerArmLE : public ElfLinker
{
typedef ElfLinker super;
protected:
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class ElfLinkerM68k : public ElfLinker
{
typedef ElfLinker super;
public:
ElfLinkerM68k() { bele = &N_BELE_RTP::be_policy; }
protected:
virtual void alignCode(unsigned len);
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class ElfLinkerMipsLE : public ElfLinker
{
typedef ElfLinker super;
protected:
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class ElfLinkerPpc32 : public ElfLinker
{
typedef ElfLinker super;
public:
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
protected:
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
class ElfLinkerX86 : public ElfLinker
{
typedef ElfLinker super;
protected:
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
virtual void relocate1(const Relocation *, upx_byte *location,
unsigned value, const char *type);
};
#endif /* already included */
+293 -123
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -30,6 +30,7 @@
#include "mygetopt.h"
#include "file.h"
#include "packer.h"
#include "p_elf.h"
#if 1 && defined(__DJGPP__)
@@ -42,15 +43,16 @@ int _crt0_startup_flags = _CRT0_FLAG_UNIX_SBRK;
// options
**************************************************************************/
void init_options(struct options_t *o)
void options_t::reset()
{
options_t *o = this;
memset(o, 0, sizeof(*o));
memset(&o->crp, 0xff, sizeof(o->crp));
o->crp.reset();
o->cmd = CMD_NONE;
o->method = -1;
o->method = M_NONE;
o->level = -1;
o->filter = -1;
o->filter = FT_NONE;
o->backup = -1;
o->overlay = -1;
@@ -72,10 +74,11 @@ void init_options(struct options_t *o)
o->win32_pe.compress_rt[i] = -1;
o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
o->win32_pe.strip_relocs = -1;
o->win32_pe.keep_resource = "";
}
static struct options_t global_options;
struct options_t *opt = &global_options;
static options_t global_options;
options_t *opt = &global_options;
static int done_output_name = 0;
static int done_script_name = 0;
@@ -180,7 +183,7 @@ static void e_method(int m, int l)
static void e_optarg(const char *n)
{
fflush(con_term);
fprintf(stderr,"%s: invalid argument in option `%s'\n", argv0, n);
fprintf(stderr,"%s: invalid argument in option '%s'\n", argv0, n);
e_exit(EXIT_USAGE);
}
@@ -188,7 +191,7 @@ static void e_optarg(const char *n)
static void e_optval(const char *n)
{
fflush(con_term);
fprintf(stderr,"%s: invalid value for option `%s'\n", argv0, n);
fprintf(stderr,"%s: invalid value for option '%s'\n", argv0, n);
e_exit(EXIT_USAGE);
}
@@ -198,10 +201,10 @@ void e_envopt(const char *n)
{
fflush(con_term);
if (n)
fprintf(stderr,"%s: invalid string `%s' in environment variable `%s'\n",
fprintf(stderr,"%s: invalid string '%s' in environment variable '%s'\n",
argv0, n, OPTIONS_VAR);
else
fprintf(stderr,"%s: illegal option in environment variable `%s'\n",
fprintf(stderr,"%s: illegal option in environment variable '%s'\n",
argv0, OPTIONS_VAR);
e_exit(EXIT_USAGE);
}
@@ -224,7 +227,7 @@ void check_not_both(bool e1, bool e2, const char *c1, const char *c2)
if (e1 && e2)
{
fprintf(stderr,"%s: ",argv0);
fprintf(stderr,"cannot use both `%s' and `%s'\n", c1, c2);
fprintf(stderr,"cannot use both '%s' and '%s'\n", c1, c2);
e_usage();
}
}
@@ -234,12 +237,24 @@ void check_options(int i, int argc)
{
assert(i <= argc);
if (opt->cmd != CMD_COMPRESS)
{
// invalidate compression options
opt->method = 0;
opt->level = 0;
opt->exact = 0;
opt->small = 0;
opt->crp.reset();
}
// set default overlay action
if (!(opt->cmd == CMD_COMPRESS || opt->cmd == CMD_DECOMPRESS))
opt->overlay = opt->COPY_OVERLAY;
else if (opt->overlay < 0)
opt->overlay = opt->COPY_OVERLAY;
check_not_both(opt->exact, opt->overlay == opt->STRIP_OVERLAY, "--exact", "--overlay=strip");
// set default backup option
if (opt->backup < 0)
opt->backup = 0;
@@ -249,14 +264,14 @@ void check_options(int i, int argc)
check_not_both(opt->to_stdout, opt->output_name != NULL, "--stdout", "-o");
if (opt->to_stdout && opt->cmd == CMD_COMPRESS)
{
fprintf(stderr,"%s: cannot use `--stdout' when compressing\n", argv0);
fprintf(stderr,"%s: cannot use '--stdout' when compressing\n", argv0);
e_usage();
}
if (opt->to_stdout || opt->output_name)
{
if (i + 1 != argc)
{
fprintf(stderr,"%s: need exactly one argument when using `%s'\n",
fprintf(stderr,"%s: need exactly one argument when using '%s'\n",
argv0, opt->to_stdout ? "--stdout" : "-o");
e_usage();
}
@@ -297,8 +312,14 @@ static bool set_method(int m, int l)
{
if (!Packer::isValidCompressionMethod(m))
return false;
opt->method = m;
opt->all_methods = false;
#if 1
// something like "--brute --lzma" should not disable "--brute"
if (!opt->all_methods)
#endif
{
opt->method = m;
opt->all_methods = false;
}
}
if (l > 0)
opt->level = l;
@@ -312,7 +333,7 @@ static void set_output_name(const char *n, bool allow_m)
#if 1
if (done_output_name > 0)
{
fprintf(stderr,"%s: option `-o' more than once given\n",argv0);
fprintf(stderr,"%s: option '-o' more than once given\n",argv0);
e_usage();
}
#endif
@@ -335,7 +356,7 @@ static void set_script_name(const char *n, bool allow_m)
#if 1
if (done_script_name > 0)
{
fprintf(stderr,"%s: option `--script' more than once given\n",argv0);
fprintf(stderr,"%s: option '--script' more than once given\n",argv0);
e_usage();
}
#endif
@@ -403,28 +424,58 @@ char* prepare_shortopts(char *buf, const char *n,
template <class T>
int getoptvar(T *var, const T minval, const T maxval)
int getoptvar(T *var, const T min_value, const T max_value, const char *arg_fatal)
{
const char *p = mfx_optarg;
char *endptr;
int r = 0;
long n;
T v;
if (!p || !p[0])
return -1;
{ r = -1; goto error; }
// avoid interpretation as octal value
while (p[0] == '0' && isdigit(p[1]))
p++;
long n = strtol(p, &endptr, 0);
n = strtol(p, &endptr, 0);
if (*endptr != '\0')
return -2;
T v = (T) n;
if (v < minval)
return -3;
if (v > maxval)
return -4;
{ r = -2; goto error; }
v = (T) n;
if (v < min_value)
{ r = -3; goto error; }
if (v > max_value)
{ r = -4; goto error; }
*var = v;
return 0;
goto done;
error:
if (arg_fatal != NULL)
e_optval(arg_fatal);
done:
return r;
}
#if 1 && (ACC_CC_GNUC >= 0x030300)
template <class T, T default_value, T min_value, T max_value>
int getoptvar(OptVar<T,default_value,min_value,max_value> *var, const char *arg_fatal)
{
T v = default_value;
int r = getoptvar(&v, min_value, max_value, arg_fatal);
if (r == 0)
*var = v;
return r;
}
#else
template <class T>
int getoptvar(T *var, const char *arg_fatal)
{
typename T::Type v = T::default_value_c;
int r = getoptvar(&v, T::min_value_c, T::max_value_c, arg_fatal);
if (r == 0)
*var = v;
return r;
}
#endif
static int do_option(int optc, const char *arg)
{
@@ -448,7 +499,7 @@ static int do_option(int optc, const char *arg)
case 'f':
opt->force++;
break;
case 902:
case 909:
set_cmd(CMD_FILEINFO);
break;
case 'h':
@@ -457,10 +508,13 @@ static int do_option(int optc, const char *arg)
set_cmd(CMD_HELP);
break;
case 'h'+256:
#if 0
/* according to GNU standards */
set_term(stdout);
opt->console = CON_FILE;
#if 1
if (!acc_isatty(STDOUT_FILENO))
{
/* according to GNU standards */
set_term(stdout);
opt->console = CON_FILE;
}
#endif
show_help(1);
e_exit(EXIT_OK);
@@ -510,6 +564,16 @@ static int do_option(int optc, const char *arg)
if (!set_method(M_NRV2E_LE32, -1))
e_method(M_NRV2E_LE32, opt->level);
break;
case 721:
opt->all_methods_use_lzma = true;
if (!set_method(M_LZMA, -1))
e_method(M_LZMA, opt->level);
break;
case 722:
opt->all_methods_use_lzma = false;
if (M_IS_LZMA(opt->method))
opt->method = -1;
break;
// compression level
case '1':
@@ -525,12 +589,16 @@ static int do_option(int optc, const char *arg)
e_method(opt->method, optc);
break;
case 902: // --ultra-brute
opt->ultra_brute = true;
/* fallthrough */
case 901: // --brute
opt->all_methods = true;
opt->all_methods_use_lzma = true;
opt->method = -1;
opt->all_filters = true;
opt->filter = -1;
opt->crp.m_size = 999999;
opt->crp.crp_ucl.m_size = 999999;
/* fallthrough */
case 900: // --best
if (!set_method(-1, 10))
@@ -553,6 +621,9 @@ static int do_option(int optc, const char *arg)
e_optarg(arg);
opt->debug.dump_stub_loader = mfx_optarg;
break;
case 545:
opt->debug.disable_random_id = true;
break;
// misc
case 512:
@@ -577,7 +648,7 @@ static int do_option(int optc, const char *arg)
opt->small++;
break;
case 521: // --filter=
getoptvar(&opt->filter, 0, 255);
getoptvar(&opt->filter, 0, 255, arg);
opt->all_filters = false;
break;
case 522: // --no-filter
@@ -591,37 +662,64 @@ static int do_option(int optc, const char *arg)
break;
case 524: // --all-methods
opt->all_methods = true;
opt->all_methods_use_lzma = true;
opt->method = -1;
break;
// compression parms
case 531:
getoptvar(&opt->crp.c_flags, 0, 3);
case 525: // --exact
opt->exact = true;
break;
case 532:
getoptvar(&opt->crp.s_level, 0, 2);
// compression runtime parameters
case 801:
getoptvar(&opt->crp.crp_ucl.c_flags, 0, 3, arg);
break;
case 533:
getoptvar(&opt->crp.h_level, 0, 1);
case 802:
getoptvar(&opt->crp.crp_ucl.s_level, 0, 2, arg);
break;
case 534:
getoptvar(&opt->crp.p_level, 0, 7);
case 803:
getoptvar(&opt->crp.crp_ucl.h_level, 0, 1, arg);
break;
case 535:
getoptvar(&opt->crp.max_offset, 256u, ~0u);
case 804:
getoptvar(&opt->crp.crp_ucl.p_level, 0, 7, arg);
break;
case 536:
getoptvar(&opt->crp.max_match, 16u, ~0u);
case 805:
getoptvar(&opt->crp.crp_ucl.max_offset, 256u, ~0u, arg);
break;
case 537:
if (getoptvar(&opt->crp.m_size, 10000u, 999999u) != 0)
e_optval("--crp-ms=");
case 806:
getoptvar(&opt->crp.crp_ucl.max_match, 16u, ~0u, arg);
break;
case 807:
getoptvar(&opt->crp.crp_ucl.m_size, 10000u, 999999u, arg);
break;
case 811:
getoptvar(&opt->crp.crp_lzma.pos_bits, arg);
break;
case 812:
getoptvar(&opt->crp.crp_lzma.lit_pos_bits, arg);
break;
case 813:
getoptvar(&opt->crp.crp_lzma.lit_context_bits, arg);
break;
case 814:
getoptvar(&opt->crp.crp_lzma.dict_size, arg);
break;
case 816:
getoptvar(&opt->crp.crp_lzma.num_fast_bytes, arg);
break;
case 821:
getoptvar(&opt->crp.crp_zlib.mem_level, arg);
break;
case 822:
getoptvar(&opt->crp.crp_zlib.window_bits, arg);
break;
case 823:
getoptvar(&opt->crp.crp_zlib.strategy, arg);
break;
// backup
case 'k':
opt->backup = 1;
break;
case 541:
if (opt->backup != 1) // do not overide `--backup'
if (opt->backup != 1) // do not overide '--backup'
opt->backup = 0;
break;
// overlay
@@ -679,18 +777,20 @@ static int do_option(int optc, const char *arg)
break;
case 630:
opt->win32_pe.compress_exports = 1;
getoptvar(&opt->win32_pe.compress_exports, 0, 1);
if (mfx_optarg && mfx_optarg[0])
getoptvar(&opt->win32_pe.compress_exports, 0, 1, arg);
//printf("compress_exports: %d\n", opt->win32_pe.compress_exports);
break;
case 631:
opt->win32_pe.compress_icons = 1;
getoptvar(&opt->win32_pe.compress_icons, 0, 2);
if (mfx_optarg && mfx_optarg[0])
getoptvar(&opt->win32_pe.compress_icons, 0, 3, arg);
//printf("compress_icons: %d\n", opt->win32_pe.compress_icons);
break;
case 632:
opt->win32_pe.compress_resources = true;
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
opt->win32_pe.compress_resources = false;
opt->win32_pe.compress_resources = 1;
if (mfx_optarg && mfx_optarg[0])
getoptvar(&opt->win32_pe.compress_resources, 0, 1, arg);
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
break;
case 633:
@@ -698,15 +798,20 @@ static int do_option(int optc, const char *arg)
break;
case 634:
opt->win32_pe.strip_relocs = 1;
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
opt->win32_pe.strip_relocs = 0;
if (mfx_optarg && mfx_optarg[0])
getoptvar(&opt->win32_pe.strip_relocs, 0, 1, arg);
//printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
break;
case 635:
if (!mfx_optarg || !mfx_optarg[0])
e_optarg(arg);
opt->win32_pe.keep_resource = mfx_optarg;
break;
case 650:
opt->atari_tos.split_segments = true;
break;
case 660:
getoptvar(&opt->o_unix.blocksize, 8192u, ~0u);
getoptvar(&opt->o_unix.blocksize, 8192u, ~0u, arg);
break;
case 661:
opt->o_unix.force_execve = true;
@@ -714,7 +819,7 @@ static int do_option(int optc, const char *arg)
case 662:
opt->o_unix.script_name = "/usr/local/lib/upx/upxX";
if (mfx_optarg && mfx_optarg[0])
set_script_name(mfx_optarg,1);
set_script_name(mfx_optarg, 1);
break;
case 663:
opt->o_unix.is_ptinterp = true;
@@ -725,6 +830,18 @@ static int do_option(int optc, const char *arg)
case 665:
opt->o_unix.make_ptinterp = true;
break;
case 666: // Linux
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;
break;
case 667: // FreeBSD
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_FREEBSD;
break;
case 668: // NetBSD
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_NETBSD;
break;
case 669: // OpenBSD
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_OPENBSD;
break;
case 670:
opt->ps1_exe.boot_only = true;
break;
@@ -735,13 +852,16 @@ static int do_option(int optc, const char *arg)
case 672:
opt->ps1_exe.do_8bit = true;
break;
case 673:
opt->ps1_exe.do_8mb = false;
break;
case '\0':
return -1;
case ':':
return -2;
default:
fprintf(stderr,"%s: internal error in getopt (%d)\n",argv0,optc);
fprintf(stderr,"%s: internal error in getopt (%d)\n", argv0, optc);
return -3;
}
@@ -758,10 +878,11 @@ static const struct mfx_option longopts[] =
// commands
{"best", 0x10, 0, 900}, // compress best
{"brute", 0x10, 0, 901}, // compress best, brute force
{"ultra-brute", 0x10, 0, 902}, // compress best, brute force
{"decompress", 0, 0, 'd'}, // decompress
{"fast", 0x10, 0, '1'}, // compress faster
{"fileinfo", 0x10, 0, 902}, // display info about file
{"file-info", 0x10, 0, 902}, // display info about file
{"fileinfo", 0x10, 0, 909}, // display info about file
{"file-info", 0x10, 0, 909}, // display info about file
{"help", 0, 0, 'h'+256}, // give help
{"license", 0, 0, 'L'}, // display software license
{"list", 0, 0, 'l'}, // list compressed exe
@@ -790,18 +911,19 @@ static const struct mfx_option longopts[] =
{"dump-stub-loader" ,0x31, 0, 544}, // for internal debugging
{"fake-stub-version",0x31, 0, 542}, // for internal debugging
{"fake-stub-year" ,0x31, 0, 543}, // for internal debugging
{"disable-random-id",0x10, 0, 545}, // for internal debugging
// backup options
{"backup", 0, 0, 'k'},
{"keep", 0, 0, 'k'},
{"no-backup", 0, 0, 541},
{"backup", 0x10, 0, 'k'},
{"keep", 0x10, 0, 'k'},
{"no-backup", 0x10, 0, 541},
// overlay options
{"overlay", 0x31, 0, 551}, // --overlay=
{"skip-overlay", 0, 0, 552},
{"no-overlay", 0, 0, 552}, // old name
{"copy-overlay", 0, 0, 553},
{"strip-overlay", 0, 0, 554},
{"skip-overlay", 0x10, 0, 552},
{"no-overlay", 0x10, 0, 552}, // old name
{"copy-overlay", 0x10, 0, 553},
{"strip-overlay", 0x10, 0, 554},
// CPU options
{"cpu", 0x31, 0, 560}, // --cpu=
@@ -810,33 +932,53 @@ static const struct mfx_option longopts[] =
{"486", 0x10, 0, 564},
// color options
{"no-color", 0, 0, 512},
{"mono", 0, 0, 513},
{"color", 0, 0, 514},
{"no-color", 0x10, 0, 512},
{"mono", 0x10, 0, 513},
{"color", 0x10, 0, 514},
// 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
{"all-filters", 0x10, 0, 523},
{"all-methods", 0x10, 0, 524},
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression
{"filter", 0x31, 0, 521}, // --filter=
{"no-filter", 0x10, 0, 522},
{"small", 0x10, 0, 520},
// compression runtime parameters
{"crp-cf", 0x31, 0, 531},
{"crp-sl", 0x31, 0, 532},
{"crp-hl", 0x31, 0, 533},
{"crp-pl", 0x31, 0, 534},
{"crp-mo", 0x31, 0, 535},
{"crp-mm", 0x31, 0, 536},
{"crp-ms", 0x31, 0, 537},
{"crp-nrv-cf", 0x31, 0, 801},
{"crp-nrv-sl", 0x31, 0, 802},
{"crp-nrv-hl", 0x31, 0, 803},
{"crp-nrv-pl", 0x31, 0, 804},
{"crp-nrv-mo", 0x31, 0, 805},
{"crp-nrv-mm", 0x31, 0, 806},
{"crp-nrv-ms", 0x31, 0, 807},
{"crp-ucl-cf", 0x31, 0, 801},
{"crp-ucl-sl", 0x31, 0, 802},
{"crp-ucl-hl", 0x31, 0, 803},
{"crp-ucl-pl", 0x31, 0, 804},
{"crp-ucl-mo", 0x31, 0, 805},
{"crp-ucl-mm", 0x31, 0, 806},
{"crp-ucl-ms", 0x31, 0, 807},
{"crp-lzma-pb", 0x31, 0, 811},
{"crp-lzma-lp", 0x31, 0, 812},
{"crp-lzma-lc", 0x31, 0, 813},
{"crp-lzma-ds", 0x31, 0, 814},
{"crp-lzma-fb", 0x31, 0, 816},
{"crp-zlib-ml", 0x31, 0, 821},
{"crp-zlib-wb", 0x31, 0, 822},
{"crp-zlib-st", 0x31, 0, 823},
// [deprecated - only for compatibility with UPX 2.0x]
{"crp-ms", 0x31, 0, 807},
// atari/tos
{"split-segments", 0x10, 0, 650},
// djgpp2/coff
{"coff", 0, 0, 610}, // produce COFF output
{"coff", 0x10, 0, 610}, // produce COFF output
// dos/com
// dos/exe
//{"force-stub", 0x10, 0, 600},
@@ -848,21 +990,31 @@ static const struct mfx_option longopts[] =
#if 0
{"script", 0x31, 0, 662}, // --script=
#endif
{"is_ptinterp", 0, 0, 663}, // linux/elf386 PT_INTERP program
{"use_ptinterp", 0, 0, 664}, // linux/elf386 PT_INTERP program
{"make_ptinterp", 0, 0, 665}, // linux/elf386 PT_INTERP program
{"is_ptinterp", 0x10, 0, 663}, // linux/elf386 PT_INTERP program
{"use_ptinterp", 0x10, 0, 664}, // linux/elf386 PT_INTERP program
{"make_ptinterp", 0x10, 0, 665}, // linux/elf386 PT_INTERP program
{"Linux", 0x10, 0, 666},
{"linux", 0x10, 0, 666},
{"FreeBSD", 0x10, 0, 667},
{"freebsd", 0x10, 0, 667},
{"NetBSD", 0x10, 0, 668},
{"netbsd", 0x10, 0, 668},
{"OpenBSD", 0x10, 0, 669},
{"openbsd", 0x10, 0, 669},
// watcom/le
{"le", 0, 0, 620}, // produce LE output
{"le", 0x10, 0, 620}, // produce LE output
// win32/pe
{"compress-exports", 2, 0, 630},
{"compress-icons", 2, 0, 631},
{"compress-resources", 2, 0, 632},
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634},
{"keep-resource", 0x31, 0, 635},
// ps1/exe
{"boot-only", 0x10, 0, 670},
{"no-align", 0x10, 0, 671},
{"8-bit", 0x10, 0, 672},
{"8mb-ram", 0x10, 0, 673},
{ NULL, 0, NULL, 0 }
};
@@ -873,6 +1025,7 @@ static const struct mfx_option longopts[] =
prepare_shortopts(buf,"123456789hH?V",longopts),
mfx_optind = 0;
mfx_opterr = 1;
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;
while ((optc = mfx_getopt_long(argc, argv, buf, longopts, &longind)) >= 0)
{
if (do_option(optc, argv[mfx_optind-1]) != 0)
@@ -894,6 +1047,7 @@ static const struct mfx_option longopts[] =
// commands
{"best", 0x10, 0, 900}, // compress best
{"brute", 0x10, 0, 901}, // compress best, brute force
{"ultra-brute", 0x10, 0, 902}, // compress best, brute force
{"fast", 0x10, 0, '1'}, // compress faster
// options
@@ -903,17 +1057,20 @@ static const struct mfx_option longopts[] =
{"silent", 0, 0, 'q'}, // quiet mode
{"verbose", 0, 0, 'v'}, // verbose mode
// debug options
{"disable-random-id",0x10, 0, 545}, // for internal debugging
// backup options
{"backup", 0, 0, 'k'},
{"keep", 0, 0, 'k'},
{"backup", 0x10, 0, 'k'},
{"keep", 0x10, 0, 'k'},
{"no-backup", 0x10, 0, 541},
// overlay options
{"overlay", 0x31, 0, 551}, // --overlay=
{"skip-overlay", 0, 0, 552},
{"no-overlay", 0, 0, 552}, // old name
{"copy-overlay", 0, 0, 553},
{"strip-overlay", 0, 0, 554},
{"skip-overlay", 0x10, 0, 552},
{"no-overlay", 0x10, 0, 552}, // old name
{"copy-overlay", 0x10, 0, 553},
{"strip-overlay", 0x10, 0, 554},
// CPU options
{"cpu", 0x31, 0, 560}, // --cpu=
@@ -922,18 +1079,14 @@ static const struct mfx_option longopts[] =
{"486", 0x10, 0, 564},
// color options
{"no-color", 0, 0, 512},
{"mono", 0, 0, 513},
{"color", 0, 0, 514},
{"no-color", 0x10, 0, 512},
{"mono", 0x10, 0, 513},
{"color", 0x10, 0, 514},
// compression settings
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression
// compression runtime parameters
{"crp-cf", 0x31, 0, 531},
{"crp-sl", 0x31, 0, 532},
{"crp-hl", 0x31, 0, 533},
{"crp-pl", 0x31, 0, 534},
{"crp-mo", 0x31, 0, 535},
{"crp-mm", 0x31, 0, 536},
{"crp-ms", 0x31, 0, 537},
// win32/pe
{"compress-exports", 2, 0, 630},
@@ -941,6 +1094,7 @@ static const struct mfx_option longopts[] =
{"compress-resources", 2, 0, 632},
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634},
{"keep-resource", 0x31, 0, 635},
{ NULL, 0, NULL, 0 }
};
@@ -1056,9 +1210,25 @@ static void first_options(int argc, char **argv)
**************************************************************************/
template <class T> struct TestBELE {
static int test(void)
static bool test(void)
{
COMPILE_TIME_ASSERT_ALIGNED1(T)
struct test1_t { char a; T b; } __attribute_packed;
struct test2_t { char a; T b[3]; } __attribute_packed;
test1_t t1[7]; UNUSED(t1); test2_t t2[7]; UNUSED(t2);
COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T))
COMPILE_TIME_ASSERT_ALIGNED1(test1_t)
COMPILE_TIME_ASSERT(sizeof(t1) == 7 + 7*sizeof(T))
COMPILE_TIME_ASSERT(sizeof(test2_t) == 1 + 3*sizeof(T))
COMPILE_TIME_ASSERT_ALIGNED1(test2_t)
COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21*sizeof(T))
#if defined(__acc_alignof)
COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1)
COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1)
#endif
#if 1 && !defined(xUPX_OFFICIAL_BUILD)
T allbits; allbits = 0; allbits -= 1;
//++allbits; allbits++; --allbits; allbits--;
T v1; v1 = 1; v1 *= 2; v1 -= 1;
T v2; v2 = 1;
assert( (v1 == v2)); assert(!(v1 != v2));
@@ -1070,7 +1240,11 @@ static int test(void)
assert( (v1 < v2)); assert(!(v1 > v2));
v2 += 2;
assert(v1 == 1); assert(v2 == 0);
return (v1 ^ v2) == 1;
v1 <<= 1; v1 |= v2; v1 >>= 1; v2 &= v1; v2 /= v1; v2 *= v1;
assert(v1 == 1); assert(v2 == 0);
if ((v1 ^ v2) != 1) return false;
#endif
return true;
}};
@@ -1102,12 +1276,12 @@ void upx_sanity_check(void)
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
COMPILE_TIME_ASSERT(sizeof(LE64) == 8)
COMPILE_TIME_ASSERT_ALIGNOF(BE16, char)
COMPILE_TIME_ASSERT_ALIGNOF(BE32, char)
COMPILE_TIME_ASSERT_ALIGNOF(BE64, char)
COMPILE_TIME_ASSERT_ALIGNOF(LE16, char)
COMPILE_TIME_ASSERT_ALIGNOF(LE32, char)
COMPILE_TIME_ASSERT_ALIGNOF(LE64, char)
COMPILE_TIME_ASSERT_ALIGNED1(BE16)
COMPILE_TIME_ASSERT_ALIGNED1(BE32)
COMPILE_TIME_ASSERT_ALIGNED1(BE64)
COMPILE_TIME_ASSERT_ALIGNED1(LE16)
COMPILE_TIME_ASSERT_ALIGNED1(LE32)
COMPILE_TIME_ASSERT_ALIGNED1(LE64)
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
assert(strlen(UPX_VERSION_STRING4) == 4);
@@ -1118,14 +1292,12 @@ void upx_sanity_check(void)
assert(memcmp(UPX_VERSION_DATE + strlen(UPX_VERSION_DATE) - 4, UPX_VERSION_YEAR, 4) == 0);
#if 1
# if 1
assert(TestBELE<LE16>::test());
assert(TestBELE<LE32>::test());
assert(TestBELE<LE64>::test());
assert(TestBELE<BE16>::test());
assert(TestBELE<BE32>::test());
assert(TestBELE<BE64>::test());
# endif
{
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
@@ -1149,6 +1321,7 @@ void upx_sanity_check(void)
assert(get_le24_signed(d) == -131329);
assert(get_le32(d) == 0xfcfdfeff);
assert(get_le32_signed(d) == -50462977);
assert(get_le64_signed(d) == ACC_INT64_C(-506097522914230529));
assert(find_be16(d, 2, 0xfffe) == 0);
assert(find_le16(d, 2, 0xfeff) == 0);
assert(find_be32(d, 4, 0xfffefdfc) == 0);
@@ -1157,6 +1330,7 @@ void upx_sanity_check(void)
assert(get_be16_signed(d) == 32638);
assert(get_be24_signed(d) == 8355453);
assert(get_be32_signed(d) == 2138996092);
assert(get_be64_signed(d) == ACC_INT64_C(9186918263483431288));
}
#endif
}
@@ -1168,6 +1342,10 @@ void upx_sanity_check(void)
#if !defined(WITH_GUI)
#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)
extern "C" { extern long _stksize; long _stksize = 256 * 1024L; }
#endif
int __acc_cdecl_main main(int argc, char *argv[])
{
int i;
@@ -1181,7 +1359,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
acc_wildargv(&argc, &argv);
upx_sanity_check();
init_options(opt);
opt->reset();
if (!argv[0] || !argv[0][0])
argv[0] = default_argv0;
@@ -1282,14 +1460,6 @@ int __acc_cdecl_main main(int argc, char *argv[])
break;
}
if (opt->cmd != CMD_COMPRESS)
{
// invalidate compression options
opt->method = 0;
opt->level = 0;
memset(&opt->crp, 0xff, sizeof(opt->crp));
}
/* check options */
if (argc == 1)
e_help();
@@ -1308,7 +1478,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
set_term(stdout);
do_files(i,argc,argv);
#if 0 && (UPX_VERSION_HEX < 0x020000)
#if 0 && (UPX_VERSION_HEX < 0x030000)
{
FILE *f = stdout;
int fg = con_fg(f,FG_RED);
+26 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -60,6 +60,8 @@ static int mcheck_init()
MemBuffer::MemBuffer() :
b(NULL), b_size(0)
{
if (use_mcheck < 0)
mcheck_init();
}
MemBuffer::MemBuffer(unsigned size) :
@@ -87,7 +89,7 @@ void MemBuffer::dealloc()
set_be32(b + b_size, 0);
set_be32(b + b_size + 4, 0);
//
::free(b - 8);
::free(b - 16);
}
else
::free(b);
@@ -99,16 +101,15 @@ void MemBuffer::dealloc()
}
void MemBuffer::allocForCompression(unsigned uncompressed_size, unsigned extra)
unsigned MemBuffer::getSizeForCompression(unsigned uncompressed_size, unsigned extra)
{
assert((int)uncompressed_size > 0);
assert((int)extra >= 0);
unsigned size = uncompressed_size + uncompressed_size/8 + 256 + extra;
alloc(size);
return size;
}
void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra)
unsigned MemBuffer::getSizeForUncompression(unsigned uncompressed_size, unsigned extra)
{
assert((int)uncompressed_size > 0);
assert((int)extra >= 0);
@@ -118,6 +119,20 @@ void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra
#if (ACC_ARCH_I386)
size += 3;
#endif
return size;
}
void MemBuffer::allocForCompression(unsigned uncompressed_size, unsigned extra)
{
unsigned size = getSizeForCompression(uncompressed_size, extra);
alloc(size);
}
void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra)
{
unsigned size = getSizeForUncompression(uncompressed_size, extra);
alloc(size);
}
@@ -173,7 +188,7 @@ void MemBuffer::alloc(unsigned size)
assert(b_size == 0);
//
assert((int)size > 0);
unsigned total = use_mcheck ? size + 16 : size;
unsigned total = use_mcheck ? size + 32 : size;
assert((int)total > 0);
unsigned char *p = (unsigned char *) malloc(total);
if (!p)
@@ -185,7 +200,7 @@ void MemBuffer::alloc(unsigned size)
b_size = size;
if (use_mcheck)
{
b = p + 8;
b = p + 16;
// store magic constants to detect buffer overruns
set_be32(b - 8, b_size);
set_be32(b - 4, MAGIC1(b));
@@ -194,6 +209,8 @@ void MemBuffer::alloc(unsigned size)
}
else
b = p ;
//fill(0, b_size, (rand() & 0xff) | 1); // debug
}
+6 -3
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -38,9 +38,12 @@ class MemBuffer
{
public:
MemBuffer();
MemBuffer(unsigned size);
explicit MemBuffer(unsigned size);
~MemBuffer();
static unsigned getSizeForCompression(unsigned uncompressed_size, unsigned extra=0);
static unsigned getSizeForUncompression(unsigned uncompressed_size, unsigned extra=0);
void alloc(unsigned size);
void allocForCompression(unsigned uncompressed_size, unsigned extra=0);
void allocForUncompression(unsigned uncompressed_size, unsigned extra=0);
+612 -179
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
+24 -17
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -47,11 +47,14 @@ struct options_t {
// compression options
int method;
int level; // compression level 1..10
int filter; // preferred filter from Packer::getFilters()
bool all_methods; // try all available compression methods ?
bool all_filters; // try all available filters ?
bool no_filter; // force no filter
int level; // compression level 1..10
int filter; // preferred filter from Packer::getFilters()
bool ultra_brute;
bool all_methods; // try all available compression methods ?
bool all_methods_use_lzma;
bool all_filters; // try all available filters ?
bool no_filter; // force no filter
bool exact; // user requires byte-identical decompression
// other options
int backup;
@@ -69,6 +72,7 @@ struct options_t {
// debug options
struct {
int debug_level;
bool disable_random_id; // for Packer::getRandomId()
const char *dump_stub_loader;
char fake_stub_version[4+1]; // for internal debugging
char fake_stub_year[4+1]; // for internal debugging
@@ -82,16 +86,14 @@ struct options_t {
};
int overlay;
// compression runtime parameters - see struct ucl_compress_config_t
struct {
upx_uint max_offset;
upx_uint max_match;
int s_level;
int h_level;
int p_level;
int c_flags;
upx_uint m_size;
} crp;
// compression runtime parameters - see struct XXX_compress_config_t
struct crp_t {
lzma_compress_config_t crp_lzma;
ucl_compress_config_t crp_ucl;
zlib_compress_config_t crp_zlib;
void reset() { crp_lzma.reset(); crp_ucl.reset(); crp_zlib.reset(); }
};
crp_t crp;
// CPU
enum {
@@ -120,6 +122,7 @@ struct options_t {
bool boot_only;
bool no_align;
bool do_8bit;
bool do_8mb;
} ps1_exe;
struct {
unsigned blocksize;
@@ -127,6 +130,7 @@ struct options_t {
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
bool use_ptinterp; // use PT_INTERP /opt/upx/run
bool make_ptinterp; // make PT_INTERP [ignore current file!]
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
enum { SCRIPT_MAX = 32 };
const char *script_name;
} o_unix;
@@ -139,7 +143,10 @@ struct options_t {
int compress_resources;
signed char compress_rt[25]; // 25 == RT_LAST
int strip_relocs;
const char *keep_resource;
} win32_pe;
void reset();
};
extern struct options_t *opt;
+381 -1282
View File
File diff suppressed because it is too large Load Diff
+14 -192
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -29,217 +29,39 @@
#ifndef __UPX_P_ARMPE_H
#define __UPX_P_ARMPE_H
class PackArmPe_Interval;
class PackArmPe_Reloc;
class PackArmPe_Resource;
class PackArmPe_Export;
/*************************************************************************
// w32/pe
// arm/pe
**************************************************************************/
class PackArmPe : public Packer
class PackArmPe : public PeFile
{
typedef Packer super;
typedef PeFile super;
public:
PackArmPe(InputFile *f);
~PackArmPe();
virtual int getVersion() const { return 13; }
virtual ~PackArmPe();
virtual int getFormat() const { return UPX_F_WINCE_ARM_PE; }
virtual const char *getName() const { return "arm/pe"; }
virtual const char *getFullName(const options_t *) const { return "arm-wince.pe"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
virtual bool canPack();
virtual int canUnpack();
// unpacker capabilities
virtual bool canUnpackVersion(int version) const
{ UNUSED(version); return false; }
protected:
virtual int readFileHeader();
virtual bool testUnpackVersion(int version) const;
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
virtual int buildLoader(const Filter *ft);
virtual unsigned processImports();
virtual void processImports(unsigned, unsigned);
virtual void rebuildImports(upx_byte *&);
unsigned pe_offset;
virtual void processTls(Interval *);
unsigned processImports();
void processImports(unsigned);
void rebuildImports(upx_byte *&);
upx_byte *oimport;
unsigned soimport;
upx_byte *oimpdlls;
unsigned soimpdlls;
void processRelocs();
void processRelocs(PackArmPe_Reloc *);
void rebuildRelocs(upx_byte *&);
upx_byte *orelocs;
unsigned sorelocs;
upx_byte *oxrelocs;
unsigned soxrelocs;
void processExports(PackArmPe_Export *);
void processExports(PackArmPe_Export *,unsigned);
void rebuildExports();
upx_byte *oexport;
unsigned soexport;
void processResources(PackArmPe_Resource *);
void processResources(PackArmPe_Resource *, unsigned);
void rebuildResources(upx_byte *&);
upx_byte *oresources;
unsigned soresources;
void processTls(PackArmPe_Interval *);
void processTls(PackArmPe_Reloc *,const PackArmPe_Interval *,unsigned);
void rebuildTls();
upx_byte *otls;
unsigned sotls;
unsigned stripDebug(unsigned);
unsigned icondir_offset;
int icondir_count;
bool importbyordinal;
bool kernel32ordinal;
unsigned tlsindex;
unsigned rvamin;
unsigned cimports; // rva of preprocessed imports
unsigned crelocs; // rva of preprocessed fixups
int big_relocs;
struct pe_header_t
{
// 0x0
char _[4]; // pemagic
LE16 cpu;
LE16 objects;
char __[12]; // timestamp + reserved
LE16 opthdrsize;
LE16 flags;
// optional header
char ___[4]; // coffmagic + linkerversion
LE32 codesize;
// 0x20
LE32 datasize;
LE32 bsssize;
LE32 entry;
LE32 codebase;
// 0x30
LE32 database;
// nt specific fields
LE32 imagebase;
LE32 objectalign;
LE32 filealign; // should set to 0x200 ?
// 0x40
char ____[16]; // versions
// 0x50
LE32 imagesize;
LE32 headersize;
LE32 chksum; // should set to 0
LE16 subsystem;
LE16 dllflags;
// 0x60
char _____[20]; // stack + heap sizes
// 0x74
LE32 ddirsentries; // usually 16
struct ddirs_t
{
LE32 vaddr;
LE32 size;
}
__attribute_packed;
struct ddirs_t ddirs[16];
}
__attribute_packed;
struct pe_section_t
{
char name[8];
LE32 vsize;
LE32 vaddr;
LE32 size;
LE32 rawdataptr;
char _[12];
LE32 flags;
}
__attribute_packed;
pe_header_t ih, oh;
pe_section_t *isection;
static unsigned virta2objnum (unsigned, pe_section_t *, unsigned);
unsigned tryremove (unsigned, unsigned);
enum {
PEDIR_EXPORT = 0,
PEDIR_IMPORT = 1,
PEDIR_RESOURCE = 2,
PEDIR_EXCEPTION = 3, // Exception table
PEDIR_SEC = 4, // Certificate table (file pointer)
PEDIR_RELOC = 5,
PEDIR_DEBUG = 6,
PEDIR_COPYRIGHT = 7, // Architecture-specific data
PEDIR_GLOBALPTR = 8, // Global pointer
PEDIR_TLS = 9,
PEDIR_LOADCONF = 10, // Load Config Table
PEDIR_BOUNDIM = 11,
PEDIR_IAT = 12,
PEDIR_DELAYIMP = 13, // Delay Import Descriptor
PEDIR_COMRT = 14 // Com+ Runtime Header
};
enum {
PEFL_CODE = 0x20,
PEFL_DATA = 0x40,
PEFL_BSS = 0x80,
PEFL_INFO = 0x200,
PEFL_EXTRELS = 0x01000000, // extended relocations
PEFL_DISCARD = 0x02000000,
PEFL_NOCACHE = 0x04000000,
PEFL_NOPAGE = 0x08000000,
PEFL_SHARED = 0x10000000,
PEFL_EXEC = 0x20000000,
PEFL_READ = 0x40000000,
PEFL_WRITE = 0x80000000
};
enum {
RELOCS_STRIPPED = 0x0001,
EXECUTABLE = 0x0002,
LNUM_STRIPPED = 0x0004,
LSYMS_STRIPPED = 0x0008,
AGGRESSIVE_TRIM = 0x0010,
TWO_GIGS_AWARE = 0x0020,
FLITTLE_ENDIAN = 0x0080,
BITS_32_MACHINE = 0x0100,
DEBUG_STRIPPED = 0x0200,
REMOVABLE_SWAP = 0x0400,
SYSTEM_PROGRAM = 0x1000,
DLL_FLAG = 0x2000,
FBIG_ENDIAN = 0x8000
};
// predefined resource types
enum {
RT_CURSOR = 1, RT_BITMAP, RT_ICON, RT_MENU, RT_DIALOG, RT_STRING,
RT_FONTDIR, RT_FONT, RT_ACCELERATOR, RT_RCDATA, RT_MESSAGETABLE,
RT_GROUP_CURSOR, RT_GROUP_ICON = 14, RT_VERSION = 16, RT_DLGINCLUDE,
RT_PLUGPLAY = 19, RT_VXD, RT_ANICURSOR, RT_ANIICON, RT_HTML,
RT_MANIFEST, RT_LAST
};
bool use_thumb_stub;
};
+31 -34
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -31,9 +31,10 @@
#include "filter.h"
#include "packer.h"
#include "p_com.h"
#include "linker.h"
static const
#include "stub/l_com.h"
#include "stub/i086-dos16.com.h"
//#define TESTING
@@ -44,16 +45,11 @@ static const
const int *PackCom::getCompressionMethods(int method, int level) const
{
static const int m_nrv2b[] = { M_NRV2B_LE16, -1 };
if (M_IS_NRV2B(method))
return m_nrv2b;
static const int m_nrv2b[] = { M_NRV2B_LE16, M_END };
#if 0
// NOT IMPLEMENTED
static const int m_nrv2d[] = { M_NRV2D_LE16, -1 };
if (M_IS_NRV2D(method))
return m_nrv2d;
static const int m_nrv2d[] = { M_NRV2D_LE16, M_END };
#endif
UNUSED(level);
UNUSED(method); UNUSED(level);
return m_nrv2b;
}
@@ -62,7 +58,7 @@ const int *PackCom::getFilters() const
{
static const int filters[] = {
0x06, 0x03, 0x04, 0x01, 0x05, 0x02,
-1 };
FT_END };
return filters;
}
@@ -98,10 +94,9 @@ void PackCom::patchLoader(OutputFile *fo,
upx_byte *loader, int lsize,
unsigned calls)
{
const int filter_id = ph.filter;
const int e_len = getLoaderSectionStart("COMCUTPO");
const int d_len = lsize - e_len;
assert(e_len > 0 && e_len < 256);
assert(e_len > 0 && e_len < 128);
assert(d_len > 0 && d_len < 256);
const unsigned upper_end = ph.u_len + ph.overlap_overhead + d_len + 0x100;
@@ -111,22 +106,19 @@ void PackCom::patchLoader(OutputFile *fo,
if (upper_end + stacksize > 0xfffe)
throwCantPack("file is too big for dos/com");
if (filter_id)
{
assert(calls > 0);
patch_le16(loader,lsize,"CT",calls);
}
linker->defineSymbol("calltrick_calls", calls);
linker->defineSymbol("sp_limit", upper_end + stacksize);
linker->defineSymbol("bytes_to_copy", ph.c_len + lsize);
linker->defineSymbol("copy_source", ph.c_len + lsize + 0x100);
linker->defineSymbol("copy_destination", upper_end);
linker->defineSymbol("neg_e_len", 0 - e_len);
linker->defineSymbol("NRV2B160", ph.u_len + ph.overlap_overhead);
relocateLoader();
loader = getLoader();
// some day we could use the relocation stuff for patchPackHeader too
patchPackHeader(loader,e_len);
// NOTE: Depends on: decompr_start == cutpoint+1 !!!
patch_le16(loader,e_len,"JM",upper_end - 0xff - d_len - getLoaderSection("UPX1HEAD"));
loader[getLoaderSectionStart("COMSUBSI") - 1] = (upx_byte) -e_len;
patch_le16(loader,e_len,"DI",upper_end);
patch_le16(loader,e_len,"SI",ph.c_len + lsize + 0x100);
patch_le16(loader,e_len,"CX",ph.c_len + lsize);
patch_le16(loader,e_len,"SP",upper_end + stacksize);
// write loader + compressed file
fo->write(loader,e_len); // entry
fo->write(obuf,ph.c_len);
@@ -139,10 +131,10 @@ void PackCom::patchLoader(OutputFile *fo,
}
int PackCom::buildLoader(const Filter *ft)
void PackCom::buildLoader(const Filter *ft)
{
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
addLoader("COMMAIN1,COMSUBSI",
initLoader(stub_i086_dos16_com, sizeof(stub_i086_dos16_com));
addLoader("COMMAIN1",
ph.first_offset_found == 1 ? "COMSBBBP" : "",
"COMPSHDI",
ft->id ? "COMCALLT" : "",
@@ -150,7 +142,7 @@ int PackCom::buildLoader(const Filter *ft)
ft->id ? "NRVDDONE" : "NRVDRETU",
"NRVDECO1",
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
"NRVDECO2,NRV2B169",
"NRVDECO2",
NULL
);
if (ft->id)
@@ -158,7 +150,6 @@ int PackCom::buildLoader(const Filter *ft)
assert(ft->calls > 0);
addFilter16(ft->id);
}
return getLoaderSize();
}
@@ -206,7 +197,7 @@ void PackCom::pack(OutputFile *fo)
ft.addvalue = getCallTrickOffset();
// compress
const unsigned overlap_range = ph.u_len < 0xFE00 - ft.addvalue ? 32 : 0;
compressWithFilters(&ft, overlap_range);
compressWithFilters(&ft, overlap_range, NULL_cconf);
const int lsize = getLoaderSize();
MemBuffer loader(lsize);
@@ -270,6 +261,12 @@ void PackCom::unpack(OutputFile *fo)
}
Linker* PackCom::newLinker() const
{
return new ElfLinkerX86();
}
/*
vi:ts=4:et
*/
+7 -5
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -38,10 +38,11 @@ class PackCom : public Packer
{
typedef Packer super;
public:
PackCom(InputFile *f) : super(f) { }
PackCom(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_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 int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
@@ -53,9 +54,10 @@ public:
protected:
virtual unsigned getCallTrickOffset() const { return 0x100; }
virtual Linker* newLinker() const;
protected:
virtual int buildLoader(const Filter *ft);
virtual void buildLoader(const Filter *ft);
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
virtual void addFilter16(int filter_id);
};
+58 -36
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -31,11 +31,12 @@
#include "filter.h"
#include "packer.h"
#include "p_djgpp2.h"
#include "linker.h"
static const
#include "stub/l_djgpp2.h"
#include "stub/i386-dos32.djgpp2.h"
static const
#include "stub/stubify.h"
#include "stub/i386-dos32.djgpp2-stubify.h"
/*************************************************************************
@@ -45,13 +46,14 @@ static const
PackDjgpp2::PackDjgpp2(InputFile *f) :
super(f), coff_offset(0)
{
COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40);
COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8);
COMPILE_TIME_ASSERT(sizeof(stubify_stub) == 2048);
COMPILE_TIME_ASSERT_ALIGNOF(external_scnhdr_t, char)
COMPILE_TIME_ASSERT_ALIGNOF(coff_header_t, char)
COMPILE_TIME_ASSERT(STUBIFY_STUB_ADLER32 == 0xbf689ba8);
COMPILE_TIME_ASSERT(STUBIFY_STUB_CRC32 == 0x2ae982b2);
bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40)
COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8)
COMPILE_TIME_ASSERT_ALIGNED1(external_scnhdr_t)
COMPILE_TIME_ASSERT_ALIGNED1(coff_header_t)
COMPILE_TIME_ASSERT(sizeof(stub_i386_dos32_djgpp2_stubify) == 2048)
COMPILE_TIME_ASSERT(STUB_I386_DOS32_DJGPP2_STUBIFY_ADLER32 == 0xbf689ba8)
COMPILE_TIME_ASSERT(STUB_I386_DOS32_DJGPP2_STUBIFY_CRC32 == 0x2ae982b2)
//printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub)));
//assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
}
@@ -66,8 +68,9 @@ const int *PackDjgpp2::getCompressionMethods(int method, int level) const
const int *PackDjgpp2::getFilters() const
{
static const int filters[] = {
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
-1 };
0x26, 0x24, 0x49, 0x46, 0x16, 0x13, 0x14, 0x11,
FT_ULTRA_BRUTE, 0x25, 0x15, 0x12,
FT_END };
return filters;
}
@@ -82,14 +85,22 @@ unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf,
}
int PackDjgpp2::buildLoader(const Filter *ft)
Linker* PackDjgpp2::newLinker() const
{
return new ElfLinkerX86;
}
void PackDjgpp2::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader, sizeof(nrv_loader));
initLoader(stub_i386_dos32_djgpp2, sizeof(stub_i386_dos32_djgpp2));
addLoader("IDENTSTR,DJ2MAIN1",
ft->id ? "DJCALLT1" : "",
"DJ2MAIN2",
getDecompressor(),
ph.first_offset_found == 1 ? "DJ2MAIN2" : "",
M_IS_LZMA(ph.method) ? "LZMA_INIT_STACK" : "",
getDecompressorSections(),
M_IS_LZMA(ph.method) ? "LZMA_DONE_STACK" : "",
"DJ2BSS00",
NULL
);
@@ -99,8 +110,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
addLoader("DJCALLT2", NULL);
addFilter32(ft->id);
}
addLoader("DJRETURN,+40DXXXX,UPX1HEAD", NULL);
return getLoaderSize();
addLoader("DJRETURN,+40C,UPX1HEAD", NULL);
}
@@ -120,8 +130,8 @@ void PackDjgpp2::handleStub(OutputFile *fo)
else
{
// "stubify" stub
info("Adding stub: %ld bytes", (long)sizeof(stubify_stub));
fo->write(stubify_stub, sizeof(stubify_stub));
info("Adding stub: %ld bytes", (long)sizeof(stub_i386_dos32_djgpp2_stubify));
fo->write(stub_i386_dos32_djgpp2_stubify, sizeof(stub_i386_dos32_djgpp2_stubify));
}
}
}
@@ -290,33 +300,35 @@ void PackDjgpp2::pack(OutputFile *fo)
ft.buf_len = usize - data->size;
ft.addvalue = text->vaddr - hdrsize;
// compress
compressWithFilters(&ft, 512);
upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
compressWithFilters(&ft, 512, &cconf);
// patch coff header #2
const unsigned lsize = getLoaderSize();
assert(lsize % 4 == 0);
text->size = lsize; // new size of .text
data->size = ph.c_len; // new size of .data
if (bss->size < ph.overlap_overhead) // give it a .bss
bss->size = ph.overlap_overhead;
unsigned stack = 1024 + ph.overlap_overhead + getDecompressorWrkmemSize();
stack = ALIGN_UP(stack, 16u);
if (bss->size < stack) // give it a .bss
bss->size = stack;
text->scnptr = sizeof(coff_hdr);
data->scnptr = text->scnptr + text->size;
data->vaddr = bss->vaddr + ((data->scnptr + data->size) & 0x1ff) - data->size + ph.overlap_overhead - 0x200;
coff_hdr.f_nscns = 3;
// prepare loader
MemBuffer loader(lsize);
memcpy(loader, getLoader(), lsize);
// patch loader
patchPackHeader(loader, lsize);
patch_le32(loader, lsize, "ENTR", coff_hdr.a_entry);
patchFilter32(loader, lsize, &ft);
patch_le32(loader, lsize, "BSSL", ph.overlap_overhead / 4);
linker->defineSymbol("original_entry", coff_hdr.a_entry);
linker->defineSymbol("length_of_bss", ph.overlap_overhead / 4);
defineDecompressorSymbols();
assert(bss->vaddr == ((size + 0x1ff) &~ 0x1ff) + (text->vaddr &~ 0x1ff));
patch_le32(loader, lsize, "OUTP", text->vaddr - hdrsize);
patch_le32(loader, lsize, "INPP", data->vaddr);
linker->defineSymbol("stack_for_lzma", bss->vaddr + bss->size);
linker->defineSymbol("start_of_uncompressed", text->vaddr - hdrsize);
linker->defineSymbol("start_of_compressed", data->vaddr);
defineFilterSymbols(&ft);
// we should not overwrite our decompressor during unpacking
// the original coff header (which is put just before the
@@ -333,9 +345,19 @@ void PackDjgpp2::pack(OutputFile *fo)
memcpy(obuf+data->size, "UPX", 3);
data->size = ALIGN_UP(data->size, 4);
linker->defineSymbol("DJ2MAIN1", coff_hdr.a_entry);
relocateLoader();
// prepare loader
MemBuffer loader(lsize);
memcpy(loader, getLoader(), lsize);
patchPackHeader(loader, lsize);
// write coff header, loader and compressed file
fo->write(&coff_hdr, sizeof(coff_hdr));
fo->write(loader, lsize);
if (opt->debug.dump_stub_loader)
OutputFile::dump(opt->debug.dump_stub_loader, loader, lsize);
fo->write(obuf, data->size);
#if 0
printf("%-13s: coff hdr : %8ld bytes\n", getName(), (long) sizeof(coff_hdr));
@@ -367,7 +389,7 @@ int PackDjgpp2::canUnpack()
if (is_dlm(fi, coff_offset))
throwCantUnpack("can't handle DLM");
fi->seek(coff_offset, SEEK_SET);
return readPackHeader(1024) ? 1 : -1;
return readPackHeader(4096) ? 1 : -1;
}
+6 -4
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -43,6 +43,7 @@ public:
virtual int getVersion() const { return 14; }
virtual int getFormat() const { return UPX_F_DJGPP2_COFF; }
virtual const char *getName() const { return "djgpp2/coff"; }
virtual const char *getFullName(const options_t *) const { return "i386-dos32.djgpp2"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
@@ -59,7 +60,8 @@ protected:
virtual unsigned findOverlapOverhead(const upx_bytep buf,
unsigned range = 0,
unsigned upper_limit = ~0u) const;
virtual int buildLoader(const Filter *ft);
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
long coff_offset;
+258 -214
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -31,15 +31,34 @@
/*************************************************************************
// Some ELF type definitinons
// N_Elf
**************************************************************************/
namespace TT_Elf {
namespace N_Elf {
// integral types
template <class THalf, class TWord, class TXword, class TAddr, class TOff>
struct ElfITypes
{
typedef THalf Half;
typedef TWord Word;
typedef TXword Xword;
typedef TAddr Addr;
typedef TOff Off;
typedef THalf Section;
typedef THalf Versym;
};
// The ELF file header. This appears at the start of every ELF file.
template <class Word, class Addr, class Off, class Half>
template <class TElfITypes>
struct Ehdr
{
typedef typename TElfITypes::Half Half;
typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Off Off;
unsigned char e_ident[16]; /* Magic number and other info */
Half e_type; /* Object file type */
Half e_machine; /* Architecture */
@@ -55,71 +74,57 @@ struct Ehdr
Half e_shnum; /* Section header table entry count */
Half e_shstrndx; /* Section header string table index */
enum { // e_ident[]
EI_CLASS = 4,
EI_DATA = 5, /* Data encoding */
EI_VERSION = 6,
EI_OSABI = 7,
EI_ABIVERSION = 8,
};
enum { // e_ident[EI_CLASS]
ELFCLASS32 = 1, /* 32-bit objects */
ELFCLASS64 = 2, /* 64-bit objects */
};
enum { // e_ident[EI_DATA]
ELFDATA2LSB = 1, /* 2's complement, little endian */
ELFDATA2MSB = 2 /* 2's complement, big endian */
};
enum { // e_ident[EI_OSABI]
ELFOSABI_LINUX = 3
};
enum { // e_type
ET_NONE = 0, /* No file type */
ET_REL = 1, /* Relocatable file */
ET_EXEC = 2, /* Executable file */
ET_DYN = 3, /* Shared object file */
ET_CORE = 4, /* Core file */
};
enum { // e_machine
EM_386 = 3,
EM_PPC = 20,
EM_PPC64 = 21,
EM_ARM = 40,
EM_X86_64 = 62,
};
enum { // e_version
EV_CURRENT = 1,
};
# define WANT_EHDR_ENUM 1
# include "p_elf_enum.h"
}
__attribute_packed;
template <class Word, class Addr>
template <class TElfITypes>
struct Dyn
{
Word d_tag;
typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr;
Xword d_tag;
Addr d_val;
enum { // d_tag
DT_NULL = 0, /* End flag */
DT_NEEDED = 1, /* Name of needed library */
DT_HASH = 4, /* Hash table of symbol names */
DT_STRTAB = 5, /* String table */
DT_SYMTAB = 6, /* Symbol table */
DT_STRSZ = 10, /* Sizeof string table */
};
# define WANT_DYN_ENUM 1
# include "p_elf_enum.h"
}
__attribute_packed;
} // namespace TT_Elf
template <class TElfITypes>
struct External_Note
{
typedef typename TElfITypes::Word Word;
Word xn_namesz; // includes terminating '\0'
Word xn_datasz;
Word xn_type;
//char xn_name[N]; // terminate with '\0'
//char xn_data[M]; // aligned to 0 mod 4
}
__attribute_packed;
namespace TT_Elf32 {
} // namespace N_Elf
// Program segment header.
template <class Word, class Addr, class Off>
/*************************************************************************
// N_Elf32
**************************************************************************/
namespace N_Elf32 {
template <class TElfITypes>
struct Phdr
{
typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Off Off;
Word p_type; /* Segment type */
Off p_offset; /* Segment file offset */
Addr p_vaddr; /* Segment virtual address */
@@ -129,24 +134,19 @@ struct Phdr
Word p_flags; /* Segment flags */
Word p_align; /* Segment alignment */
enum { // p_type
PT_LOAD = 1, /* Loadable program segment */
PT_DYNAMIC = 2, /* Dynamic linking information */
PT_INTERP = 3, /* Name of program interpreter */
PT_PHDR = 6, /* Entry for header table itself */
};
enum { // p_flags
PF_X = 1, /* Segment is executable */
PF_W = 2, /* Segment is writable */
PF_R = 4, /* Segment is readable */
};
# define WANT_PHDR_ENUM 1
# include "p_elf_enum.h"
}
__attribute_packed;
template <class Word, class Addr, class Off>
template <class TElfITypes>
struct Shdr
{
typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Off Off;
Word sh_name; /* Section name (string tbl index) */
Word sh_type; /* Section type */
Word sh_flags; /* Section flags */
@@ -158,93 +158,53 @@ struct Shdr
Word sh_addralign; /* Section alignment */
Word sh_entsize; /* Entry size if section holds table */
enum { // sh_type
SHT_NULL = 0, /* Section header table entry unused */
SHT_PROGBITS = 1, /* Program data */
SHT_SYMTAB = 2, /* Symbol table */
SHT_STRTAB = 3, /* String table */
SHT_RELA = 4, /* Relocation entries with addends */
SHT_HASH = 5, /* Symbol hash table */
SHT_DYNAMIC = 6, /* Dynamic linking information */
SHT_NOTE = 7, /* Notes */
SHT_NOBITS = 8, /* Program space with no data (bss) */
SHT_REL = 9, /* Relocation entries, no addends */
SHT_SHLIB = 10, /* Reserved */
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
/* 12, 13 hole */
SHT_INIT_ARRAY = 14, /* Array of constructors */
SHT_FINI_ARRAY = 15, /* Array of destructors */
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
SHT_GROUP = 17, /* Section group */
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
};
enum { // sh_flags
SHF_WRITE = (1 << 0), /* Writable */
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
SHF_EXECINSTR = (1 << 2), /* Executable */
SHF_MERGE = (1 << 4), /* Might be merged */
SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */
SHF_INFO_LINK = (1 << 6), /* `sh_info' contains SHT index */
SHF_LINK_ORDER = (1 << 7), /* Preserve order after combining */
};
# define WANT_SHDR_ENUM 1
# include "p_elf_enum.h"
}
__attribute_packed;
template <class TT16, class TT32, class TT64>
template <class TElfITypes>
struct Sym
{
TT32 st_name; /* symbol name (index into string table) */
TT32 st_value; /* symbol value */
TT32 st_size; /* symbol size */
typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Section Section;
Word st_name; /* symbol name (index into string table) */
Addr st_value; /* symbol value */
Word st_size; /* symbol size */
unsigned char st_info; /* symbol type and binding */
unsigned char st_other; /* symbol visibility */
TT16 st_shndx; /* section index */
Section st_shndx; /* section index */
unsigned int st_bind(unsigned int x) const { return 0xf & (x>>4); }
unsigned int st_type(unsigned int x) const { return 0xf & x ; }
unsigned char St_info(unsigned bind, unsigned type) const { return (bind<<4) + (0xf & type); }
# define WANT_SYM_ENUM 1
# include "p_elf_enum.h"
enum { // st_bind (high 4 bits of st_info)
STB_LOCAL = 0, /* Local symbol */
STB_GLOBAL = 1, /* Global symbol */
STB_WEAK = 2, /* Weak symbol */
};
enum { // st_type (low 4 bits of st_info)
STT_NOTYPE = 0, /* Symbol type is unspecified */
STT_OBJECT = 1, /* Symbol is a data object */
STT_FUNC = 2, /* Symbol is a code object */
STT_SECTION = 3, /* Symbol associated with a section */
STT_FILE = 4, /* Symbol's name is file name */
STT_COMMON = 5, /* Symbol is a common data object */
STT_TLS = 6, /* Symbol is thread-local data object*/
};
enum { // st_other (visibility)
STV_DEFAULT = 0, /* Default symbol visibility rules */
STV_INTERNAL = 1, /* Processor specific hidden class */
STV_HIDDEN = 2, /* Sym unavailable in other modules */
STV_PROTECTED= 3, /* Not preemptible, not exported */
};
enum { // st_shndx
SHN_UNDEF = 0, /* Undefined section */
SHN_ABS = 0xfff1, /* Associated symbol is absolute */
SHN_COMMON = 0xfff2, /* Associated symbol is common */
};
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 char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
}
__attribute_packed;
} // namespace TT_Elf32
namespace TT_Elf64 {
} // namespace N_Elf32
// Program segment header.
template <class Word, class Xword, class Addr, class Off>
/*************************************************************************
// N_Elf64
**************************************************************************/
namespace N_Elf64 {
template <class TElfITypes>
struct Phdr
{
typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Off Off;
Word p_type; /* Segment type */
Word p_flags; /* Segment flags */
Off p_offset; /* Segment file offset */
@@ -254,24 +214,20 @@ struct Phdr
Xword p_memsz; /* Segment size in memory */
Xword p_align; /* Segment alignment */
enum { // p_type
PT_LOAD = 1, /* Loadable program segment */
PT_DYNAMIC = 2, /* Dynamic linking information */
PT_INTERP = 3, /* Name of program interpreter */
PT_PHDR = 6, /* Entry for header table itself */
};
enum { // p_flags
PF_X = 1, /* Segment is executable */
PF_W = 2, /* Segment is writable */
PF_R = 4, /* Segment is readable */
};
# define WANT_PHDR_ENUM 1
# include "p_elf_enum.h"
}
__attribute_packed;
template <class Word, class Xword, class Addr, class Off>
template <class TElfITypes>
struct Shdr
{
typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Off Off;
Word sh_name; /* Section name (string tbl index) */
Word sh_type; /* Section type */
Xword sh_flags; /* Section flags */
@@ -283,84 +239,172 @@ struct Shdr
Xword sh_addralign; /* Section alignment */
Xword sh_entsize; /* Entry size if section holds table */
enum { // sh_type
SHT_NULL = 0, /* Section header table entry unused */
SHT_PROGBITS = 1, /* Program data */
SHT_SYMTAB = 2, /* Symbol table */
SHT_STRTAB = 3, /* String table */
SHT_RELA = 4, /* Relocation entries with addends */
SHT_HASH = 5, /* Symbol hash table */
SHT_DYNAMIC = 6, /* Dynamic linking information */
SHT_NOTE = 7, /* Notes */
SHT_NOBITS = 8, /* Program space with no data (bss) */
SHT_REL = 9, /* Relocation entries, no addends */
SHT_SHLIB = 10, /* Reserved */
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
/* 12, 13 hole */
SHT_INIT_ARRAY = 14, /* Array of constructors */
SHT_FINI_ARRAY = 15, /* Array of destructors */
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
SHT_GROUP = 17, /* Section group */
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
};
# define WANT_SHDR_ENUM 1
# include "p_elf_enum.h"
}
__attribute_packed;
} // namespace TT_Elf64
template <class TElfITypes>
struct Sym
{
typedef typename TElfITypes::Word Word;
typedef typename TElfITypes::Xword Xword;
typedef typename TElfITypes::Addr Addr;
typedef typename TElfITypes::Section Section;
Word st_name; /* symbol name (index into string table) */
unsigned char st_info; /* symbol type and binding */
unsigned char st_other; /* symbol visibility */
Section st_shndx; /* section index */
Addr st_value; /* symbol value */
Xword st_size; /* symbol size */
# define WANT_SYM_ENUM 1
# include "p_elf_enum.h"
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 char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
}
__attribute_packed;
} // namespace N_Elf64
/*************************************************************************
// now for the actual types
// aggregate types into an ElfClass
**************************************************************************/
typedef TT_Elf ::Ehdr<LE32,LE32,LE32,LE16> Elf_LE32_Ehdr;
typedef TT_Elf32::Phdr<LE32,LE32,LE32> Elf_LE32_Phdr;
typedef TT_Elf32::Shdr<LE32,LE32,LE32> Elf_LE32_Shdr;
typedef TT_Elf ::Dyn <LE32,LE32> Elf_LE32_Dyn;
typedef TT_Elf32::Sym <LE16,LE32,void> Elf_LE32_Sym;
namespace N_Elf {
typedef TT_Elf ::Ehdr<unsigned int,unsigned int,unsigned int,unsigned short> Elf32_Ehdr;
typedef TT_Elf32::Phdr<unsigned int,unsigned int,unsigned int> Elf32_Phdr;
typedef TT_Elf32::Shdr<unsigned int,unsigned int,unsigned int> Elf32_Shdr;
typedef TT_Elf ::Dyn <unsigned int,unsigned int> Elf32_Dyn;
typedef TT_Elf32::Sym <unsigned short,unsigned int,void> Elf32_Sym;
template <class TP>
struct ElfClass_32
{
typedef TP BeLePolicy;
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Ehdr) == 52)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Phdr) == 32)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Shdr) == 40)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Dyn) == 8)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Sym) == 16)
// integral types
typedef typename TP::U16 U16;
typedef typename TP::U32 U32;
typedef typename TP::U64 U64;
typedef N_Elf::ElfITypes<U16, U32, U32, U32, U32> ElfITypes;
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Ehdr) == 52)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Phdr) == 32)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Shdr) == 40)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Dyn) == 8)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Sym) == 16)
// ELF types
typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
typedef N_Elf32::Phdr<ElfITypes> Phdr;
typedef N_Elf32::Shdr<ElfITypes> Shdr;
typedef N_Elf ::Dyn <ElfITypes> Dyn;
typedef N_Elf32::Sym <ElfITypes> Sym;
typedef N_Elf ::External_Note<ElfITypes> External_Note;
static void compileTimeAssertions() {
BeLePolicy::compileTimeAssertions();
COMPILE_TIME_ASSERT(sizeof(Ehdr) == 52)
COMPILE_TIME_ASSERT(sizeof(Phdr) == 32)
COMPILE_TIME_ASSERT(sizeof(Shdr) == 40)
COMPILE_TIME_ASSERT(sizeof(Dyn) == 8)
COMPILE_TIME_ASSERT(sizeof(Sym) == 16)
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
}
};
typedef TT_Elf ::Ehdr<LE32,LE64,LE64,LE16> Elf_LE64_Ehdr;
typedef TT_Elf64::Phdr<LE32,LE64,LE64,LE64> Elf_LE64_Phdr;
typedef TT_Elf64::Shdr<LE32,LE64,LE64,LE64> Elf_LE64_Shdr;
typedef TT_Elf ::Dyn <LE64,LE64> Elf_LE64_Dyn;
template <class TP>
struct ElfClass_64
{
typedef TP BeLePolicy;
typedef TT_Elf ::Ehdr<unsigned int,unsigned long long,
unsigned long long,unsigned short> Elf64_Ehdr;
typedef TT_Elf64::Phdr<unsigned int,unsigned long long,
unsigned long long,unsigned long long> Elf64_Phdr;
typedef TT_Elf64::Shdr<unsigned int,unsigned long long,
unsigned long long,unsigned long long> Elf64_Shdr;
typedef TT_Elf ::Dyn <unsigned long long,unsigned long long> Elf64_Dyn;
// integral types
typedef typename TP::U16 U16;
typedef typename TP::U32 U32;
typedef typename TP::U64 U64;
typedef N_Elf::ElfITypes<U16, U32, U64, U64, U64> ElfITypes;
// ELF types
typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
typedef N_Elf64::Phdr<ElfITypes> Phdr;
typedef N_Elf64::Shdr<ElfITypes> Shdr;
typedef N_Elf ::Dyn <ElfITypes> Dyn;
typedef N_Elf64::Sym <ElfITypes> Sym;
typedef N_Elf ::External_Note<ElfITypes> External_Note;
static void compileTimeAssertions() {
BeLePolicy::compileTimeAssertions();
COMPILE_TIME_ASSERT(sizeof(Ehdr) == 64)
COMPILE_TIME_ASSERT(sizeof(Phdr) == 56)
COMPILE_TIME_ASSERT(sizeof(Shdr) == 64)
COMPILE_TIME_ASSERT(sizeof(Dyn) == 16)
COMPILE_TIME_ASSERT(sizeof(Sym) == 24)
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
}
};
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Ehdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Phdr) == 56)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Shdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Dyn) == 16)
} // namespace N_Elf
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Ehdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Phdr) == 56)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Shdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Dyn) == 16)
typedef N_Elf::ElfClass_32<N_BELE_CTP::HostPolicy> ElfClass_Host32;
typedef N_Elf::ElfClass_64<N_BELE_CTP::HostPolicy> ElfClass_Host64;
typedef N_Elf::ElfClass_32<N_BELE_CTP::BEPolicy> ElfClass_BE32;
typedef N_Elf::ElfClass_64<N_BELE_CTP::BEPolicy> ElfClass_BE64;
typedef N_Elf::ElfClass_32<N_BELE_CTP::LEPolicy> ElfClass_LE32;
typedef N_Elf::ElfClass_64<N_BELE_CTP::LEPolicy> ElfClass_LE64;
/*************************************************************************
// shortcuts
**************************************************************************/
typedef ElfClass_Host32::Ehdr Elf32_Ehdr;
typedef ElfClass_Host32::Phdr Elf32_Phdr;
typedef ElfClass_Host32::Shdr Elf32_Shdr;
typedef ElfClass_Host32::Dyn Elf32_Dyn;
typedef ElfClass_Host32::Sym Elf32_Sym;
typedef ElfClass_Host32::External_Note Elf32_External_Note;
typedef ElfClass_Host64::Ehdr Elf64_Ehdr;
typedef ElfClass_Host64::Phdr Elf64_Phdr;
typedef ElfClass_Host64::Shdr Elf64_Shdr;
typedef ElfClass_Host64::Dyn Elf64_Dyn;
typedef ElfClass_Host64::Sym Elf64_Sym;
typedef ElfClass_Host64::External_Note Elf64_External_Note;
typedef ElfClass_BE32::Ehdr Elf_BE32_Ehdr;
typedef ElfClass_BE32::Phdr Elf_BE32_Phdr;
typedef ElfClass_BE32::Shdr Elf_BE32_Shdr;
typedef ElfClass_BE32::Dyn Elf_BE32_Dyn;
typedef ElfClass_BE32::Sym Elf_BE32_Sym;
typedef ElfClass_BE32::External_Note Elf_BE32_External_Note;
typedef ElfClass_BE64::Ehdr Elf_BE64_Ehdr;
typedef ElfClass_BE64::Phdr Elf_BE64_Phdr;
typedef ElfClass_BE64::Shdr Elf_BE64_Shdr;
typedef ElfClass_BE64::Dyn Elf_BE64_Dyn;
typedef ElfClass_BE64::Sym Elf_BE64_Sym;
typedef ElfClass_BE64::External_Note Elf_BE64_External_Note;
typedef ElfClass_LE32::Ehdr Elf_LE32_Ehdr;
typedef ElfClass_LE32::Phdr Elf_LE32_Phdr;
typedef ElfClass_LE32::Shdr Elf_LE32_Shdr;
typedef ElfClass_LE32::Dyn Elf_LE32_Dyn;
typedef ElfClass_LE32::Sym Elf_LE32_Sym;
typedef ElfClass_LE32::External_Note Elf_LE32_External_Note;
typedef ElfClass_LE64::Ehdr Elf_LE64_Ehdr;
typedef ElfClass_LE64::Phdr Elf_LE64_Phdr;
typedef ElfClass_LE64::Shdr Elf_LE64_Shdr;
typedef ElfClass_LE64::Dyn Elf_LE64_Dyn;
typedef ElfClass_LE64::Sym Elf_LE64_Sym;
typedef ElfClass_LE64::External_Note Elf_LE64_External_Note;
#endif /* already included */
+185
View File
@@ -0,0 +1,185 @@
/* p_elf_enum.h --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
/*************************************************************************
// Use the preprocessor to work around
// - that the types embedding these enums have to be PODs, and
// deriving from an empty base class (which is the ususal C++ way
// of "importing" enums) does not yield a POD any more
// - that older compilers do not correctly perform EBCO
**************************************************************************/
#ifdef WANT_EHDR_ENUM
#undef WANT_EHDR_ENUM
enum { // e_ident[]
EI_CLASS = 4,
EI_DATA = 5, /* Data encoding */
EI_VERSION = 6,
EI_OSABI = 7,
EI_ABIVERSION = 8
};
enum { // e_ident[EI_CLASS]
ELFCLASS32 = 1, /* 32-bit objects */
ELFCLASS64 = 2 /* 64-bit objects */
};
enum { // e_ident[EI_DATA]
ELFDATA2LSB = 1, /* 2's complement, little endian */
ELFDATA2MSB = 2 /* 2's complement, big endian */
};
enum { // e_ident[EI_OSABI]
ELFOSABI_NONE = 0, // == ELFOSABI_SYSV
ELFOSABI_NETBSD = 2,
ELFOSABI_LINUX = 3,
ELFOSABI_FREEBSD = 9,
ELFOSABI_OPENBSD = 12,
ELFOSABI_ARM = 97
};
enum { // e_type
ET_NONE = 0, /* No file type */
ET_REL = 1, /* Relocatable file */
ET_EXEC = 2, /* Executable file */
ET_DYN = 3, /* Shared object file */
ET_CORE = 4 /* Core file */
};
enum { // e_machine
EM_386 = 3,
EM_PPC = 20,
EM_PPC64 = 21,
EM_ARM = 40,
EM_X86_64 = 62
};
enum { // e_version
EV_CURRENT = 1
};
#endif
#ifdef WANT_PHDR_ENUM
#undef WANT_PHDR_ENUM
enum { // p_type
PT_LOAD = 1, /* Loadable program segment */
PT_DYNAMIC = 2, /* Dynamic linking information */
PT_INTERP = 3, /* Name of program interpreter */
PT_NOTE = 4, /* Auxiliary information (esp. OpenBSD) */
PT_PHDR = 6 /* Entry for header table itself */
};
enum { // p_flags
PF_X = 1, /* Segment is executable */
PF_W = 2, /* Segment is writable */
PF_R = 4 /* Segment is readable */
};
#endif
#ifdef WANT_SHDR_ENUM
#undef WANT_SHDR_ENUM
enum { // sh_type
SHT_NULL = 0, /* Section header table entry unused */
SHT_PROGBITS = 1, /* Program data */
SHT_SYMTAB = 2, /* Symbol table */
SHT_STRTAB = 3, /* String table */
SHT_RELA = 4, /* Relocation entries with addends */
SHT_HASH = 5, /* Symbol hash table */
SHT_DYNAMIC = 6, /* Dynamic linking information */
SHT_NOTE = 7, /* Notes */
SHT_NOBITS = 8, /* Program space with no data (bss) */
SHT_REL = 9, /* Relocation entries, no addends */
SHT_SHLIB = 10, /* Reserved */
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
/* 12, 13 hole */
SHT_INIT_ARRAY = 14, /* Array of constructors */
SHT_FINI_ARRAY = 15, /* Array of destructors */
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
SHT_GROUP = 17, /* Section group */
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
SHT_GNU_LIBLIST = 0x6ffffff7 /* Prelink library list */
};
enum { // sh_flags
SHF_WRITE = (1 << 0), /* Writable */
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
SHF_EXECINSTR = (1 << 2), /* Executable */
SHF_MERGE = (1 << 4), /* Might be merged */
SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */
SHF_INFO_LINK = (1 << 6), /* 'sh_info' contains SHT index */
SHF_LINK_ORDER = (1 << 7) /* Preserve order after combining */
};
#endif
#ifdef WANT_DYN_ENUM
#undef WANT_DYN_ENUM
enum { // d_tag
DT_NULL = 0, /* End flag */
DT_NEEDED = 1, /* Name of needed library */
DT_HASH = 4, /* Hash table of symbol names */
DT_STRTAB = 5, /* String table */
DT_SYMTAB = 6, /* Symbol table */
DT_STRSZ = 10 /* Sizeof string table */
};
#endif
#ifdef WANT_SYM_ENUM
#undef WANT_SYM_ENUM
enum { // st_bind (high 4 bits of st_info)
STB_LOCAL = 0, /* Local symbol */
STB_GLOBAL = 1, /* Global symbol */
STB_WEAK = 2 /* Weak symbol */
};
enum { // st_type (low 4 bits of st_info)
STT_NOTYPE = 0, /* Symbol type is unspecified */
STT_OBJECT = 1, /* Symbol is a data object */
STT_FUNC = 2, /* Symbol is a code object */
STT_SECTION = 3, /* Symbol associated with a section */
STT_FILE = 4, /* Symbol's name is file name */
STT_COMMON = 5, /* Symbol is a common data object */
STT_TLS = 6 /* Symbol is thread-local data object*/
};
enum { // st_other (visibility)
STV_DEFAULT = 0, /* Default symbol visibility rules */
STV_INTERNAL = 1, /* Processor specific hidden class */
STV_HIDDEN = 2, /* Sym unavailable in other modules */
STV_PROTECTED= 3 /* Not preemptible, not exported */
};
enum { // st_shndx
SHN_UNDEF = 0, /* Undefined section */
SHN_ABS = 0xfff1, /* Associated symbol is absolute */
SHN_COMMON = 0xfff2 /* Associated symbol is common */
};
#endif
/*
vi:ts=4:et
*/
+10 -10
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -94,13 +94,12 @@ void PackElks8086::readKernel()
//
**************************************************************************/
int PackElks8086::buildLoader(const Filter *ft)
void PackElks8086::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader, sizeof(nrv_loader));
// FIXME
UNUSED(ft);
return getLoaderSize();
}
@@ -113,7 +112,7 @@ void PackElks8086::pack(OutputFile *fo)
ft.buf_len = ph.u_len;
ft.addvalue = kernel_entry;
// compress
compressWithFilters(&ft, overlap_range);
compressWithFilters(&ft, overlap_range, NULL_cconf);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
@@ -122,10 +121,11 @@ void PackElks8086::pack(OutputFile *fo)
patchPackHeader(loader, lsize);
#if 0
// FIXME
patchFilter32(loader, lsize, &ft);
patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
patch_le32(loader, lsize, "KEIP", kernel_entry);
patch_le32(loader, lsize, "STAK", stack_during_uncompression);
defineFilterSymbols(&ft);
defineDecompressorSymbols();
//patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
//patch_le32(loader, lsize, "KEIP", kernel_entry);
//patch_le32(loader, lsize, "STAK", stack_during_uncompression);
#endif
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
+72 -42
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -31,9 +31,10 @@
#include "filter.h"
#include "packer.h"
#include "p_exe.h"
#include "linker.h"
static const
#include "stub/l_exe.h"
#include "stub/i086-dos16.exe.h"
#define RSFCRI 4096 // Reserved Space For Compressed Relocation Info
#define MAXMATCH 0x2000
@@ -49,6 +50,7 @@ static const
PackExe::PackExe(InputFile *f) :
super(f)
{
bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32);
ih_exesize = ih_imagesize = ih_overlay = 0;
}
@@ -56,8 +58,19 @@ PackExe::PackExe(InputFile *f) :
const int *PackExe::getCompressionMethods(int method, int level) const
{
static const int m_all[] = { M_NRV2B_8, M_NRV2D_8, M_NRV2E_8, M_END };
static const int m_nrv2b[] = { M_NRV2B_8, M_END };
static const int m_nrv2d[] = { M_NRV2D_8, M_END };
static const int m_nrv2e[] = { M_NRV2E_8, M_END };
if (method == M_ALL) return m_all;
if (M_IS_NRV2B(method)) return m_nrv2b;
if (M_IS_NRV2D(method)) return m_nrv2d;
if (M_IS_NRV2E(method)) return m_nrv2e;
bool small = ih_imagesize <= 256*1024;
return Packer::getDefaultCompressionMethods_8(method, level, small);
if (level == 1 || small)
return m_nrv2b;
return m_nrv2e;
}
@@ -80,7 +93,6 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
memset(&oh,0,sizeof(oh));
oh.ident = 'M' + 'Z' * 256;
oh.headsize16 = 2;
oh.ip = 0;
oh.sp = ih.sp > 0x200 ? (unsigned) ih.sp : 0x200;
@@ -101,14 +113,18 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
}
int PackExe::buildLoader(const Filter *)
void PackExe::buildLoader(const Filter *)
{
struct exe_header_t tmp_oh;
int flag = fillExeHeader(&tmp_oh);
// prepare loader
initLoader(nrv_loader,sizeof(nrv_loader));
initLoader(stub_i086_dos16_exe, sizeof(stub_i086_dos16_exe));
if (device_driver)
addLoader("DEVICEENTRY", NULL);
addLoader("EXEENTRY",
device_driver ? "DEVICESUB" : "EXESUB",
"JNCDOCOPY",
relocsize ? "EXERELPU" : "",
"EXEMAIN4,+G5DXXXX,UPX1HEAD,EXECUTPO",
NULL
@@ -122,7 +138,7 @@ int PackExe::buildLoader(const Filter *)
opt->cpu == opt->CPU_8086 ? "N2BX8602" : "N2B28602",
"NRV2BEX3",
ph.c_len > 0xffff ? "N2B64K02" : "",
"NRV2BEX9,NRV2B16E",
"NRV2BEX9",
NULL
);
else if (ph.method == M_NRV2D_8)
@@ -134,7 +150,7 @@ int PackExe::buildLoader(const Filter *)
opt->cpu == opt->CPU_8086 ? "N2DX8602" : "N2D28602",
"NRV2DEX3",
ph.c_len > 0xffff ? "N2D64K02" : "",
"NRV2DEX9,NRV2D16E",
"NRV2DEX9",
NULL
);
else if (ph.method == M_NRV2E_8)
@@ -146,7 +162,7 @@ int PackExe::buildLoader(const Filter *)
opt->cpu == opt->CPU_8086 ? "N2EX8602" : "N2E28602",
"NRV2EEX3",
ph.c_len > 0xffff ? "N2E64K02" : "",
"NRV2EEX9,NRV2E16E",
"NRV2EEX9",
NULL
);
else
@@ -162,6 +178,7 @@ int PackExe::buildLoader(const Filter *)
NULL
);
addLoader("EXEMAIN8",
device_driver ? "DEVICEEND" : "",
(flag & SS) ? "EXESTACK" : "",
(flag & SP) ? "EXESTASP" : "",
(flag & USEJUMP) ? "EXEJUMPF" : "",
@@ -172,7 +189,6 @@ int PackExe::buildLoader(const Filter *)
"EXERETIP",
NULL
);
return getLoaderSize();
}
@@ -231,6 +247,9 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
const upx_byte *relocs, const unsigned nrelocs,
upx_byte *crel, bool *has_9a)
{
if (opt->exact)
throwCantPackExact();
upx_byte * const crel_save = crel;
unsigned i;
unsigned seg_high = 0;
@@ -367,6 +386,8 @@ void PackExe::pack(OutputFile *fo)
checkAlreadyPacked(ibuf, UPX_MIN(ih_imagesize, 127u));
device_driver = get_le32(ibuf) == 0xffffffffu;
// relocations
has_9a = false;
upx_byte *w = ibuf + ih_imagesize;
@@ -405,8 +426,10 @@ void PackExe::pack(OutputFile *fo)
ph.u_len = ih_imagesize + relocsize;
// prepare filter
Filter ft(ph.level);
// compress
compressWithFilters(&ft, 32, 0, NULL, 0, MAXMATCH);
// compress (max_match = 8192)
upx_compress_config_t cconf; cconf.reset();
cconf.conf_ucl.max_match = MAXMATCH;
compressWithFilters(&ft, 32, &cconf);
if (ph.max_run_found + ph.max_match_found > 0x8000)
throwCantPack("decompressor limit exceeded, send a bugreport");
@@ -474,56 +497,57 @@ void PackExe::pack(OutputFile *fo)
}
extra_info[eisize++] = (unsigned char) flag;
linker->defineSymbol("original_cs", ih.cs);
linker->defineSymbol("original_ip", ih.ip);
linker->defineSymbol("original_sp", ih.sp);
linker->defineSymbol("original_ss", ih.ss);
linker->defineSymbol("reloc_size",
(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff)
>= relocsize ? 0 : MAXRELOCS) - relocsize);
linker->defineSymbol("bx_magic", 0x7FFF + 0x10 * ((packedsize & 15) + 1));
linker->defineSymbol("decompressor_entry", (packedsize & 15) + 1);
// patch loader
if (flag & USEJUMP)
{
// I use a relocation entry to set the original cs
unsigned n = find_le32(loader,lsize,get_le32("IPCS"));
patch_le32(loader,lsize,get_le32("IPCS"), ih.cs*0x10000 + ih.ip);
unsigned n = getLoaderSectionStart("EXEJUMPF") + 1;
n += packedsize + 2;
oh.relocs = 1;
oh.firstreloc = (n&0xf) + ((n>>4)<<16);
oh.firstreloc = (n & 0xf) + ((n >> 4) << 16);
}
else
{
patch_le16(loader,lsize,"IP",ih.ip);
if (ih.cs)
patch_le16(loader,lsize,"CS",ih.cs);
oh.relocs = 0;
oh.firstreloc = ih.cs*0x10000 + ih.ip;
oh.firstreloc = ih.cs * 0x10000 + ih.ip;
}
// g++ 3.1 does not like the following line...
// oh.relocoffs = offsetof(exe_header_t, firstreloc);
oh.relocoffs = ptr_diff(&oh.firstreloc, &oh);
if (flag & SP)
patch_le16(loader,lsize,"SP",ih.sp);
if (flag & SS)
patch_le16(loader,lsize,"SS",ih.ss);
if (relocsize)
patch_le16(loader,lsize,"RS",(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? 0 : MAXRELOCS) - relocsize);
linker->defineSymbol("destination_segment", oh.ss - ph.c_len / 16 - e_len / 16);
linker->defineSymbol("source_segment", e_len / 16 + (copysize - firstcopy) / 16);
linker->defineSymbol("copy_offset", firstcopy - 2);
linker->defineSymbol("words_to_copy",firstcopy / 2);
patchPackHeader(loader,e_len);
patch_le16(loader,e_len,"BX",0x800F + 0x10*((packedsize&15)+1) - 0x10);
patch_le16(loader,e_len,"BP",(packedsize&15)+1);
unsigned destpara = oh.ss - ph.c_len/16;
patch_le16(loader,e_len,"ES",destpara-e_len/16);
patch_le16(loader,e_len,"DS",e_len/16+(copysize-firstcopy)/16);
patch_le16(loader,e_len,"SI",firstcopy-2);
patch_le16(loader,e_len,"CX",firstcopy/2);
// finish --stub support
//if (ih.relocoffs >= 0x40 && memcmp(&ih.relocoffs,">TIPPACH",8))
// throwCantPack("FIXME");
linker->defineSymbol("exe_stack_sp", oh.sp);
linker->defineSymbol("exe_stack_ss", oh.ss);
linker->defineSymbol("interrupt", get_le16(ibuf + 8));
linker->defineSymbol("attribute", get_le16(ibuf + 4));
linker->defineSymbol("orig_strategy", get_le16(ibuf + 6));
const unsigned outputlen = sizeof(oh)+lsize+packedsize+eisize;
oh.m512 = outputlen & 511;
oh.p512 = (outputlen + 511) >> 9;
//fprintf(stderr,"\ne_len=%x d_len=%x clen=%x oo=%x ulen=%x destp=%x copys=%x images=%x",e_len,d_len,packedsize,ph.overlap_overhead,ph.u_len,destpara,copysize,ih_imagesize);
oh.ip = device_driver ? getLoaderSection("EXEENTRY") - 2 : 0;
relocateLoader();
memcpy(loader, getLoader(), lsize);
patchPackHeader(loader,e_len);
//fprintf(stderr,"\ne_len=%x d_len=%x c_len=%x oo=%x ulen=%x destp=%x copys=%x images=%x",e_len,d_len,packedsize,ph.overlap_overhead,ph.u_len,destpara,copysize,ih_imagesize);
// write header + write loader + compressed file
#ifdef TESTING
@@ -567,7 +591,7 @@ int PackExe::canUnpack()
return false;
const off_t off = ih.headsize16 * 16;
fi->seek(off, SEEK_SET);
bool b = readPackHeader(128);
bool b = readPackHeader(256);
return b && (off + (off_t) ph.c_len <= file_size);
}
@@ -697,6 +721,12 @@ void PackExe::unpack(OutputFile *fo)
}
Linker* PackExe::newLinker() const
{
return new ElfLinkerX86();
}
/*
vi:ts=4:et
*/
+7 -4
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -42,6 +42,7 @@ public:
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_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 int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
@@ -68,7 +69,8 @@ protected:
virtual int readFileHeader(void);
virtual int fillExeHeader(struct exe_header_t *) const;
virtual int buildLoader(const Filter *ft);
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
struct exe_header_t
{
@@ -98,6 +100,7 @@ protected:
unsigned relocsize;
bool has_9a;
bool device_driver;
enum {
NORELOC = 1,
+916 -626
View File
File diff suppressed because it is too large Load Diff
+213 -93
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -22,8 +22,11 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
@@ -37,7 +40,7 @@ class PackLinuxElf : public PackUnix
public:
PackLinuxElf(InputFile *f);
virtual ~PackLinuxElf();
/*virtual int buildLoader(const Filter *);*/
/*virtual void buildLoader(const Filter *);*/
virtual bool canUnpackVersion(int version) const { return (version >= 11); }
protected:
@@ -48,26 +51,31 @@ protected:
virtual void pack1(OutputFile *, Filter &) = 0; // generate executable header
virtual void pack2(OutputFile *, Filter &) = 0; // append compressed data
//virtual void pack3(OutputFile *, Filter &) = 0; // append loader
virtual void pack4(OutputFile *, Filter &) = 0; // append pack header
virtual void pack3(OutputFile *, Filter &) = 0; // append loader
//virtual void pack4(OutputFile *, Filter &) = 0; // append pack header
virtual void generateElfHdr(
OutputFile *,
void const *proto,
unsigned const brka
) = 0;
virtual int buildLinuxLoader(
upx_byte const *const proto, // assembly-only sections
unsigned const szproto,
upx_byte const *const fold, // linked assembly + C section
unsigned const szfold,
Filter const *ft
) = 0;
virtual void defineSymbols(Filter const *);
virtual void addStubEntrySections(Filter const *);
virtual void unpack(OutputFile *fo) = 0;
protected:
char *file_image; // if ET_DYN investigation
char const *dynstr; // from DT_STRTAB
unsigned sz_phdrs; // sizeof Phdr[]
unsigned sz_elf_hdrs; // all Elf headers
unsigned sz_pack2; // after pack2(), before loader
unsigned short e_machine;
unsigned char ei_class;
unsigned char ei_data;
unsigned char ei_osabi;
char const *osabi_note;
};
class PackLinuxElf32 : public PackLinuxElf
@@ -77,15 +85,17 @@ public:
PackLinuxElf32(InputFile *f);
virtual ~PackLinuxElf32();
protected:
virtual int checkEhdr(
Elf32_Ehdr const *ehdr,
unsigned char e_machine,
unsigned char ei_class,
unsigned char ei_data) const;
virtual int checkEhdr(Elf32_Ehdr const *ehdr) const;
virtual bool canPack();
// These ARM routines are essentially common to big/little endian,
// but the class hierarchy splits after this class.
virtual void ARM_defineSymbols(Filter const *ft);
virtual void ARM_updateLoader(OutputFile *);
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data
//virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append pack header
virtual void unpack(OutputFile *fo);
@@ -94,16 +104,33 @@ protected:
void const *proto,
unsigned const brka
);
virtual void buildLinuxLoader(
upx_byte const *const proto, // assembly-only sections
unsigned const szproto,
upx_byte const *const fold, // linked assembly + C section
unsigned const szfold,
Filter const *ft
);
virtual off_t getbrk(const Elf32_Phdr *phdr, int e_phnum) const;
virtual void patchLoader();
virtual void updateLoader(OutputFile *fo);
virtual unsigned find_LOAD_gap(Elf32_Phdr const *const phdri, unsigned const k,
unsigned const e_phnum);
virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const;
static unsigned elf_hash(char const *) /*const*/;
virtual void const *elf_find_dynamic(unsigned) const;
virtual Elf32_Sym const *elf_lookup(char const *) const;
virtual unsigned elf_get_offset_from_address(unsigned) const;
protected:
Elf32_Ehdr ehdri; // from input file
Elf32_Phdr *phdri; // for input file
Elf32_Dyn const *dynseg; // from PT_DYNAMIC
unsigned int const *hashtab; // from DT_HASH
Elf32_Sym const *dynsym; // from DT_SYMTAB
struct cprElfHdr1 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[1];
@@ -126,6 +153,23 @@ protected:
__attribute_packed;
cprElfHdr3 elfout;
struct Elf32_Note {
unsigned namesz; // 8
unsigned descsz; // 4
unsigned type; // 1
char text[0x18 - 4*4]; // "OpenBSD"
unsigned end; // 0
} elfnote;
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
}
};
@@ -135,18 +179,14 @@ class PackLinuxElf64 : public PackLinuxElf
public:
PackLinuxElf64(InputFile *f);
virtual ~PackLinuxElf64();
/*virtual int buildLoader(const Filter *);*/
/*virtual void buildLoader(const Filter *);*/
protected:
virtual int checkEhdr(
Elf64_Ehdr const *ehdr,
unsigned char e_machine,
unsigned char ei_class,
unsigned char ei_data) const;
virtual int checkEhdr(Elf64_Ehdr const *ehdr) const;
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data
//virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append pack header
virtual void unpack(OutputFile *fo);
@@ -155,6 +195,13 @@ protected:
void const *proto,
unsigned const brka
);
virtual void buildLinuxLoader(
upx_byte const *const proto, // assembly-only sections
unsigned const szproto,
upx_byte const *const fold, // linked assembly + C section
unsigned const szfold,
Filter const *ft
);
virtual off_t getbrk(const Elf64_Phdr *phdr, int e_phnum) const;
virtual void patchLoader();
virtual void updateLoader(OutputFile *fo);
@@ -187,13 +234,22 @@ protected:
__attribute_packed;
cprElfHdr3 elfout;
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 64 + 1*56 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 64 + 2*56 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 64 + 3*56 + 12)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
}
};
class PackLinuxElf32Be : public PackLinuxElf32
{
typedef PackLinuxElf32 super;
protected:
PackLinuxElf32Be(InputFile *f) : super(f) { }
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); }
@@ -203,11 +259,25 @@ protected:
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
};
class PackLinuxElf32Le : public PackLinuxElf32
{
typedef PackLinuxElf32 super;
protected:
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
{
typedef PackLinuxElf64 super;
protected:
PackLinuxElf64Le(InputFile *f) : super(f) { }
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); }
@@ -229,24 +299,15 @@ public:
virtual ~PackLinuxElf64amd();
virtual int getFormat() const { return UPX_F_LINUX_ELF64_AMD; }
virtual const char *getName() const { return "linux/ElfAMD"; }
virtual const char *getFullName(const options_t *) const { return "amd64-linux.elf"; }
virtual const int *getFilters() const;
virtual bool canPack();
protected:
virtual void pack3(OutputFile *, Filter &); // append loader
virtual const int *getCompressionMethods(int method, int level) const;
virtual int buildLinuxLoader(
upx_byte const *const proto, // assembly-only sections
unsigned const szproto,
upx_byte const *const fold, // linked assembly + C section
unsigned const szfold,
Filter const *ft
);
virtual int buildLoader(const Filter *);
virtual void generateElfHdr(
OutputFile *,
void const *proto,
unsigned const brka
);
virtual void pack1(OutputFile *, Filter &); // generate executable header
//virtual void pack3(OutputFile *, Filter &); // append loader
virtual void buildLoader(const Filter *);
virtual Linker* newLinker() const;
virtual void defineSymbols(Filter const *);
};
/*************************************************************************
@@ -261,19 +322,83 @@ public:
virtual ~PackLinuxElf32ppc();
virtual int getFormat() const { return UPX_F_LINUX_ELFPPC32; }
virtual const char *getName() const { return "linux/ElfPPC"; }
virtual const char *getFullName(const options_t *) const { return "powerpc-linux.elf"; }
virtual const int *getFilters() const;
virtual bool canPack();
protected:
virtual void pack3(OutputFile *, Filter &); // append loader
virtual const int *getCompressionMethods(int method, int level) const;
virtual int buildLinuxLoader(
upx_byte const *const proto, // assembly-only sections
unsigned const szproto,
upx_byte const *const fold, // linked assembly + C section
unsigned const szfold,
Filter const *ft
);
virtual int buildLoader(const Filter *);
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void buildLoader(const Filter *);
virtual Linker* newLinker() const;
};
/*************************************************************************
// linux/elf386
**************************************************************************/
class PackLinuxElf32x86 : public PackLinuxElf32Le
{
typedef PackLinuxElf32Le super;
public:
PackLinuxElf32x86(InputFile *f);
virtual ~PackLinuxElf32x86();
virtual int getFormat() const { return UPX_F_LINUX_ELF_i386; }
virtual const char *getName() const { return "linux/elf386"; }
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf"; }
virtual const int *getFilters() const;
virtual void unpack(OutputFile *fo);
protected:
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void buildLoader(const Filter *);
virtual void addStubEntrySections(Filter const *);
virtual Linker* newLinker() const;
virtual void defineSymbols(Filter const *);
};
class PackBSDElf32x86 : public PackLinuxElf32x86
{
typedef PackLinuxElf32x86 super;
public:
PackBSDElf32x86(InputFile *f);
virtual ~PackBSDElf32x86();
virtual int getFormat() const { return UPX_F_BSD_ELF_i386; }
virtual const char *getName() const { return "BSD/elf386"; }
protected:
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void buildLoader(const Filter *);
};
class PackFreeBSDElf32x86 : public PackBSDElf32x86
{
typedef PackBSDElf32x86 super;
public:
PackFreeBSDElf32x86(InputFile *f);
virtual ~PackFreeBSDElf32x86();
virtual const char *getFullName(const options_t *) const { return "i386-freebsd.elf"; }
};
class PackNetBSDElf32x86 : public PackBSDElf32x86
{
typedef PackBSDElf32x86 super;
public:
PackNetBSDElf32x86(InputFile *f);
virtual ~PackNetBSDElf32x86();
virtual const char *getFullName(const options_t *) const { return "i386-netbsd.elf"; }
};
class PackOpenBSDElf32x86 : public PackBSDElf32x86
{
typedef PackBSDElf32x86 super;
public:
PackOpenBSDElf32x86(InputFile *f);
virtual ~PackOpenBSDElf32x86();
virtual const char *getFullName(const options_t *) const { return "i386-openbsd.elf"; }
protected:
virtual void buildLoader(const Filter *ft);
virtual void generateElfHdr(
OutputFile *,
void const *proto,
@@ -282,53 +407,48 @@ protected:
};
/*************************************************************************
// linux/elf386
// linux/elfarm
**************************************************************************/
class PackLinuxI386elf : public PackLinuxI386
class PackLinuxElf32armLe : public PackLinuxElf32Le
{
typedef PackLinuxI386 super;
typedef PackLinuxElf32Le super;
public:
PackLinuxI386elf(InputFile *f);
virtual ~PackLinuxI386elf();
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_LINUX_ELF_i386; }
virtual const char *getName() const { return "linux/elf386"; }
PackLinuxElf32armLe(InputFile *f);
virtual ~PackLinuxElf32armLe();
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMLE; }
virtual const char *getName() const { return "linux/armLE"; }
virtual const char *getFullName(const options_t *) const { return "arm-linux.elf"; }
virtual const int *getFilters() const;
virtual int buildLoader(const Filter *);
virtual void unpack(OutputFile *fo);
virtual bool canPack();
virtual bool canUnpackVersion(int version) const
{ return (version >= 11); }
protected:
virtual const int *getCompressionMethods(int method, int level) const;
virtual Linker* newLinker() const;
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append pack header
virtual void patchLoader();
Elf32_Ehdr ehdri; // from input file
Elf32_Phdr *phdri; // for input file
unsigned sz_phdrs; // sizeof Phdr[]
char *file_image; // if ET_DYN investigation
Elf32_Dyn const *dynseg; // from PT_DYNAMIC
unsigned int const *hashtab; // from DT_HASH
char const *dynstr; // from DT_STRTAB
Elf32_Sym const *dynsym; // from DT_SYMTAB
static unsigned elf_hash(char const *) /*const*/;
virtual void const *elf_find_dynamic(unsigned) const;
virtual Elf32_Sym const *elf_lookup(char const *) const;
virtual unsigned elf_get_offset_from_address(unsigned) const;
virtual unsigned find_LOAD_gap(Elf32_Phdr const *const phdri, unsigned const k,
unsigned const e_phnum);
virtual void buildLoader(const Filter *);
virtual void updateLoader(OutputFile *);
virtual void defineSymbols(Filter const *);
};
class PackLinuxElf32armBe : public PackLinuxElf32Be
{
typedef PackLinuxElf32Be super;
public:
PackLinuxElf32armBe(InputFile *f);
virtual ~PackLinuxElf32armBe();
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMBE; }
virtual const char *getName() const { return "linux/armBE"; }
virtual const char *getFullName(const options_t *) const { return "armeb-linux.elf"; }
virtual const int *getFilters() const;
protected:
virtual const int *getCompressionMethods(int method, int level) const;
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 */
+259 -199
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2001-2006 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2001-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -22,8 +22,11 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
@@ -51,10 +54,35 @@
// linux/386 (generic "execve" format)
**************************************************************************/
PackLinuxI386::PackLinuxI386(InputFile *f) : super(f),
ei_osabi(Elf32_Ehdr::ELFOSABI_LINUX), osabi_note(NULL)
{
bele = &N_BELE_RTP::le_policy;
}
PackBSDI386::PackBSDI386(InputFile *f) : super(f)
{
// Shell scripts need help specifying the target operating system.
// Elf input will override this with .e_ident[EI_OSABI] or PT_NOTE.
// [2006-09-27: Today's only runtime stub for shell is for linux.]
if (Elf32_Ehdr::ELFOSABI_LINUX==opt->o_unix.osabi0) {
// Disallow an incompatibility.
ei_osabi = Elf32_Ehdr::ELFOSABI_NONE;
}
else {
ei_osabi = opt->o_unix.osabi0; // might be ELFOSABI_NONE
}
}
static const
#include "stub/l_lx_exec86.h"
#include "stub/i386-linux.elf.execve-entry.h"
static const
#include "stub/fold_exec86.h"
#include "stub/i386-linux.elf.execve-fold.h"
static const
#include "stub/i386-bsd.elf.execve-entry.h"
static const
#include "stub/i386-bsd.elf.execve-fold.h"
const int *PackLinuxI386::getCompressionMethods(int method, int level) const
@@ -66,21 +94,37 @@ const int *PackLinuxI386::getFilters() const
{
static const int filters[] = {
0x49, 0x46,
// FIXME 2002-11-11: We use stub/fold_exec86.asm, which calls the
// decompressor multiple times, and unfilter is independent of decompress.
// Currently only filters 0x49, 0x46, 0x80..0x87 can handle this;
// and 0x80..0x87 are regarded as "untested".
#if 0
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
#endif
#if 0
// 0x80..0x87 are regarded as "untested".
0x83, 0x86, 0x80, 0x84, 0x87, 0x81, 0x82, 0x85,
0x24, 0x16, 0x13, 0x14, 0x11, 0x25, 0x15, 0x12,
#endif
-1 };
FT_END };
return filters;
}
static void
set_stub_brk(Elf_LE32_Phdr *const phdr1, unsigned brka)
{
#define PAGE_MASK (~0ul<<12)
// linux-2.6.14 binfmt_elf.c: SIGKILL if (0==.p_memsz) on a page boundary
unsigned const brkb = brka | ((0==(~PAGE_MASK & brka)) ? 0x20 : 0);
phdr1->p_type = PT_LOAD; // be sure
phdr1->p_offset = ~PAGE_MASK & brkb;
phdr1->p_vaddr = brkb;
phdr1->p_paddr = brkb;
phdr1->p_filesz = 0;
phdr1->p_memsz = 0;
if (0==phdr1->p_flags) {
phdr1->p_flags = Elf32_Phdr::PF_R|Elf32_Phdr::PF_W;
}
if (0==phdr1->p_align) {
phdr1->p_align = 0x1000;
}
#undef PAGE_MASK
}
void
PackLinuxI386::generateElfHdr(
OutputFile *fo,
@@ -88,7 +132,6 @@ PackLinuxI386::generateElfHdr(
unsigned const brka
)
{
cprElfHdr1 *const h1 = (cprElfHdr1 *)&elfout;
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout;
cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout;
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
@@ -108,30 +151,22 @@ PackLinuxI386::generateElfHdr(
// Info for OS kernel to set the brk()
if (brka) {
h2->phdr[1].p_type = PT_LOAD; // be sure
h2->phdr[1].p_offset = 0xfff&brka;
h2->phdr[1].p_vaddr = brka;
h2->phdr[1].p_paddr = brka;
h2->phdr[1].p_filesz = 0;
h2->phdr[1].p_memsz = 0;
set_stub_brk(&h2->phdr[1], brka);
}
if (ph.format==UPX_F_LINUX_i386 ) {
assert(h1->ehdr.e_phnum==1);
memset(&h1->linfo, 0, sizeof(h1->linfo));
fo->write(h1, sizeof(*h1));
}
else if (ph.format==UPX_F_LINUX_ELF_i386) {
if (ph.format==UPX_F_LINUX_i386
|| ph.format==UPX_F_LINUX_SH_i386
|| ph.format==UPX_F_BSD_i386
) {
// SELinux, PAx, grSecurity demand no PF_W if PF_X.
// kernel-2.6.12-2.3.legacy_FC3 has a bug which demands
// a PT_LOAD with PF_W, else SIGSEGV when clearing page fragment
// on low page of ".bss", which is the high page of .text.
// So the minimum number of PT_LOAD is 2.
assert(h2->ehdr.e_phnum==2);
memset(&h2->linfo, 0, sizeof(h2->linfo));
fo->write(h2, sizeof(*h2));
}
else if (ph.format==UPX_F_LINUX_SH_i386) {
assert(h2->ehdr.e_phnum==1);
h2->ehdr.e_phnum = 2;
memset(&h2->linfo, 0, sizeof(h2->linfo));
fo->write(h2, sizeof(*h2));
}
else if (ph.format==UPX_F_LINUX_ELFI_i386) {
assert(h3->ehdr.e_phnum==3);
memset(&h3->linfo, 0, sizeof(h3->linfo));
@@ -148,7 +183,16 @@ PackLinuxI386::pack1(OutputFile *fo, Filter &)
// create a pseudo-unique program id for our paranoid stub
progid = getRandomId();
generateElfHdr(fo, linux_i386exec_fold, 0);
generateElfHdr(fo, stub_i386_linux_elf_execve_fold, 0);
}
void
PackBSDI386::pack1(OutputFile *fo, Filter &)
{
// create a pseudo-unique program id for our paranoid stub
progid = getRandomId();
generateElfHdr(fo, stub_i386_bsd_elf_execve_fold, 0);
}
void
@@ -158,10 +202,11 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
sizeof(l_info) +
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ;
unsigned len = fo->getBytesWritten();
set_native32(&elfout.phdr[0].p_filesz, len);
unsigned nw = fo->getBytesWritten();
elfout.phdr[0].p_filesz = nw;
nw = 0u-((0u-elfout.phdr[0].p_align) & (0u-nw)); // ALIGN_UP
super::pack4(fo, ft); // write PackHeader and overlay_offset
set_stub_brk(&elfout.phdr[1], nw + elfout.phdr[0].p_vaddr);
#if 0 // {
// /usr/bin/strip from RedHat 8.0 (binutils-2.13.90.0.2-2)
@@ -178,48 +223,56 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
// Supply a "linking view" that covers everything,
// so that 'strip' does not omit everything.
Elf32_Shdr shdr;
Elf_LE32_Shdr shdr;
// The section header string table.
char const shstrtab[] = "\0.\0.shstrtab";
unsigned eod = elfout.phdr[0].p_filesz;
set_native32(&elfout.ehdr.e_shoff, eod);
set_native16(&elfout.ehdr.e_shentsize, sizeof(shdr));
set_native16(&elfout.ehdr.e_shnum, 3);
set_native16(&elfout.ehdr.e_shstrndx, 2);
elfout.ehdr.e_shoff = eod;
elfout.ehdr.e_shentsize = sizeof(shdr);
elfout.ehdr.e_shnum = 3;
elfout.ehdr.e_shstrndx = 2;
// An empty Elf32_Shdr for space as a null index.
memset(&shdr, 0, sizeof(shdr));
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_NULL);
shdr.sh_type = Elf32_Shdr::SHT_NULL;
fo->write(&shdr, sizeof(shdr));
// Cover all the bits we need at runtime.
memset(&shdr, 0, sizeof(shdr));
set_native32(&shdr.sh_name, 1);
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_PROGBITS);
set_native32(&shdr.sh_flags, Elf32_Shdr::SHF_ALLOC);
set_native32(&shdr.sh_addr, elfout.phdr[0].p_vaddr);
set_native32(&shdr.sh_offset, overlay_offset);
set_native32(&shdr.sh_size, eod - overlay_offset);
set_native32(&shdr.sh_addralign, 4096);
shdr.sh_name = 1;
shdr.sh_type = Elf32_Shdr::SHT_PROGBITS;
shdr.sh_flags = Elf32_Shdr::SHF_ALLOC;
shdr.sh_addr = elfout.phdr[0].p_vaddr;
shdr.sh_offset = overlay_offset;
shdr.sh_size = eod - overlay_offset;
shdr.sh_addralign = 4096;
fo->write(&shdr, sizeof(shdr));
// A section header for the section header string table.
memset(&shdr, 0, sizeof(shdr));
set_native32(&shdr.sh_name, 3);
set_native32(&shdr.sh_type, Elf32_Shdr::SHT_STRTAB);
set_native32(&shdr.sh_offset, 3*sizeof(shdr) + eod);
set_native32(&shdr.sh_size, sizeof(shstrtab));
shdr.sh_name = 3;
shdr.sh_type = Elf32_Shdr::SHT_STRTAB;
shdr.sh_offset = 3*sizeof(shdr) + eod;
shdr.sh_size = sizeof(shstrtab);
fo->write(&shdr, sizeof(shdr));
fo->write(shstrtab, sizeof(shstrtab));
#endif // }
// Cannot pre-round .p_memsz. If .p_filesz < .p_memsz, then kernel
// tries to make .bss, which requires PF_W.
// But strict SELinux (or PaX, grSecurity) disallows PF_W with PF_X.
#if 0 /*{*/
#undef PAGE_MASK
#define PAGE_MASK (~0u<<12)
// pre-calculate for benefit of runtime disappearing act via munmap()
elfout.phdr[0].p_memsz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
#undef PAGE_MASK
#else /*}{*/
elfout.phdr[0].p_memsz = elfout.phdr[0].p_filesz;
#endif /*}*/
// rewrite Elf header
fo->seek(0, SEEK_SET);
@@ -235,7 +288,12 @@ umax(unsigned a, unsigned b)
return a;
}
int
Linker *PackLinuxI386::newLinker() const
{
return new ElfLinkerX86;
}
void
PackLinuxI386::buildLinuxLoader(
upx_byte const *const proto,
unsigned const szproto,
@@ -246,90 +304,54 @@ PackLinuxI386::buildLinuxLoader(
{
initLoader(proto, szproto);
struct b_info h; memset(&h, 0, sizeof(h));
unsigned fold_hdrlen = 0;
if (0 < szfold) {
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
fold_hdrlen = umax(0x80, sizeof(hf->ehdr) +
hf->ehdr.e_phentsize * hf->ehdr.e_phnum + sizeof(l_info) );
h.sz_unc = (szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen);
h.b_method = (unsigned char) ph.method;
h.b_ftid = (unsigned char) ph.filter;
h.b_cto8 = (unsigned char) ph.filter_cto;
fold_hdrlen = sizeof(hf->ehdr) + hf->ehdr.e_phentsize * hf->ehdr.e_phnum +
sizeof(l_info);
if (0 == get_le32(fold_hdrlen + fold)) {
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
fold_hdrlen = umax(0x80, fold_hdrlen);
}
}
unsigned char const *const uncLoader = fold_hdrlen + fold;
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
if (0 < szfold) {
unsigned sz_cpr;
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
NULL, ph.method, 10, NULL, NULL );
h.sz_cpr = sz_cpr;
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
throwInternalError("loader compression failed");
}
memcpy(cprLoader, &h, sizeof(h));
// This adds the definition to the "library", to be used later.
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr);
delete [] cprLoader;
// NOTE: the stub is NOT compressed! The savings is not worth it.
linker->addSection("FOLDEXEC", fold + fold_hdrlen, szfold - fold_hdrlen, 0);
n_mru = ft->n_mru;
// Here is a quick summary of the format of the output file:
linker->setLoaderAlignOffset(
// Elf32_Edhr
sizeof(elfout.ehdr) +
// Elf32_Phdr: 1 for exec86, 2 for sh86, 3 for elf86
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
// checksum UPX! lsize version format
sizeof(l_info) +
// PT_DYNAMIC with DT_NEEDED "forwarded" from original file
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) +
// p_progid, p_filesize, p_blocksize
sizeof(p_info) +
// compressed data
b_len + ph.c_len );
// entry to stub
// Rely on "+80CXXXX" [etc] in getDecompressorSections() packer_c.cpp */
// // Here is a quick summary of the format of the output file:
// linker->setLoaderAlignOffset(
// // Elf32_Edhr
// sizeof(elfout.ehdr) +
// // Elf32_Phdr: 1 for exec86, 2 for sh86, 3 for elf86
// (elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
// // checksum UPX! lsize version format
// sizeof(l_info) +
// // PT_DYNAMIC with DT_NEEDED "forwarded" from original file
// ((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) +
// // p_progid, p_filesize, p_blocksize
// sizeof(p_info) +
// // compressed data
// b_len + ph.c_len );
// // entry to stub
addLoader("LEXEC000", NULL);
if (ft->id) {
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
addLoader("LXUNF000", NULL);
addLoader("LXUNF002", NULL);
if (0x80==(ft->id & 0xF0)) {
if (256==n_mru) {
addLoader("MRUBYTE0", NULL);
}
else if (n_mru) {
addLoader("LXMRU005", NULL);
}
if (n_mru) {
addLoader("LXMRU006", NULL);
}
else {
addLoader("LXMRU007", NULL);
}
}
else if (0x40==(ft->id & 0xF0)) {
addLoader("LXUNF008", NULL);
}
addLoader("LXUNF010", NULL);
}
if (n_mru) {
addLoader("LEXEC009", NULL);
}
}
addLoader("LEXEC010", NULL);
addLoader(getDecompressor(), NULL);
linker->defineSymbol("filter_cto", ft->cto);
linker->defineSymbol("filter_length",
(ft->id & 0xf) % 3 == 0 ? ft->calls :
ft->lastcall - ft->calls * 4);
addLoader(getDecompressorSections(), NULL);
addLoader("LEXEC015", NULL);
if (ft->id) {
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
if (0x80!=(ft->id & 0xF0)) {
addLoader("LXUNF042", NULL);
}
}
else { // decompr, unfilter not separate
{ // decompr, unfilter not separate
if (0x80==(ft->id & 0xF0)) {
addLoader("LEXEC110", NULL);
if (n_mru) {
@@ -340,41 +362,48 @@ PackLinuxI386::buildLinuxLoader(
}
}
addFilter32(ft->id);
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
if (0x80==(ft->id & 0xF0)) {
if (0==n_mru) {
addLoader("LXMRU058", NULL);
}
}
addLoader("LXUNF035", NULL);
}
else { // decompr always unfilters
{ // decompr always unfilters
addLoader("LEXEC017", NULL);
}
}
else {
addLoader("LEXEC017", NULL);
}
addLoader("IDENTSTR", NULL);
addLoader("LEXEC020", NULL);
addLoader("FOLDEXEC", NULL);
char *ptr_cto = (char *)const_cast<unsigned char *>(getLoader());
int sz_cto = getLoaderSize();
if (0x20==(ft->id & 0xF0) || 0x30==(ft->id & 0xF0)) { // push byte '?' ; cto8
patch_le16(ptr_cto, sz_cto, "\x6a?", 0x6a + (ft->cto << 8));
checkPatch(NULL, 0, 0, 0); // reset
if (M_IS_LZMA(ph.method)) {
const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
acc_uint32e_t properties = // lc, lp, pb, dummy
(res->lit_context_bits << 0) |
(res->lit_pos_bits << 8) |
(res->pos_bits << 16);
if (linker->bele->isBE()) // big endian - bswap32
acc_swab32s(&properties);
linker->defineSymbol("lzma_properties", properties);
// -2 for properties
linker->defineSymbol("lzma_c_len", ph.c_len - 2);
linker->defineSymbol("lzma_u_len", ph.u_len);
unsigned const stack = getDecompressorWrkmemSize();
linker->defineSymbol("lzma_stack_adjust", 0u - stack);
}
// PackHeader and overlay_offset at the end of the output file,
// after the compressed data.
return getLoaderSize();
if (0x80==(ft->id & 0xF0)) {
int const mru = ft->n_mru ? 1+ ft->n_mru : 0;
if (mru && mru!=256) {
unsigned const is_pwr2 = (0==((mru -1) & mru));
linker->defineSymbol("NMRU", mru - is_pwr2);
}
}
relocateLoader();
}
int
void
PackLinuxI386::buildLoader(Filter const *ft)
{
unsigned const sz_fold = sizeof(linux_i386exec_fold);
unsigned const sz_fold = sizeof(stub_i386_linux_elf_execve_fold);
MemBuffer buf(sz_fold);
memcpy(buf, linux_i386exec_fold, sz_fold);
memcpy(buf, stub_i386_linux_elf_execve_fold, sz_fold);
// patch loader
// note: we only can use /proc/<pid>/fd when exetype > 0.
@@ -384,22 +413,32 @@ PackLinuxI386::buildLoader(Filter const *ft)
patch_le32(buf,sz_fold,"UPX3",progid);
patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff);
// get fresh filter
Filter fold_ft = *ft;
fold_ft.init(ft->id, ft->addvalue);
int preferred_ctos[2] = {ft->cto, -1};
fold_ft.preferred_ctos = preferred_ctos;
// filter
optimizeFilter(&fold_ft, buf, sz_fold);
bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2));
(void)success;
return buildLinuxLoader(
linux_i386exec_loader, sizeof(linux_i386exec_loader),
buildLinuxLoader(
stub_i386_linux_elf_execve_entry, sizeof(stub_i386_linux_elf_execve_entry),
buf, sz_fold, ft );
}
void
PackBSDI386::buildLoader(Filter const *ft)
{
unsigned const sz_fold = sizeof(stub_i386_bsd_elf_execve_fold);
MemBuffer buf(sz_fold);
memcpy(buf, stub_i386_bsd_elf_execve_fold, sz_fold);
// patch loader
// note: we only can use /proc/<pid>/fd when exetype > 0.
// also, we sleep much longer when compressing a script.
checkPatch(NULL, 0, 0, 0); // reset
patch_le32(buf,sz_fold,"UPX4",exetype > 0 ? 3 : 15); // sleep time
patch_le32(buf,sz_fold,"UPX3",progid);
patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff);
buildLinuxLoader(
stub_i386_bsd_elf_execve_entry, sizeof(stub_i386_bsd_elf_execve_entry),
buf, sz_fold, ft );
}
// FIXME: getLoaderPrefixSize is unused?
int PackLinuxI386::getLoaderPrefixSize() const
{
return 116;
@@ -411,7 +450,7 @@ int PackLinuxI386::getLoaderPrefixSize() const
**************************************************************************/
// basic check of an Linux ELF Ehdr
int PackLinuxI386::checkEhdr(const Elf32_Ehdr *ehdr) const
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
{
const unsigned char * const buf = ehdr->e_ident;
@@ -451,34 +490,6 @@ int PackLinuxI386::checkEhdr(const Elf32_Ehdr *ehdr) const
}
off_t PackLinuxI386::getbrk(const Elf32_Phdr *phdr, int e_phnum) const
{
off_t brka = 0;
for (int j = 0; j < e_phnum; ++phdr, ++j) {
if (phdr->PT_LOAD == phdr->p_type) {
off_t b = phdr->p_vaddr + phdr->p_memsz;
if (b > brka)
brka = b;
}
}
return brka;
}
off_t PackLinuxI386::getbase(const Elf32_Phdr *phdr, int e_phnum) const
{
off_t base = ~0u;
for (int j = 0; j < e_phnum; ++phdr, ++j) {
if (phdr->PT_LOAD == phdr->p_type) {
if (phdr->p_vaddr < (unsigned) base)
base = phdr->p_vaddr;
}
}
if (0!=base) {
return base;
}
return 0x12000;
}
/*************************************************************************
//
@@ -489,9 +500,10 @@ bool PackLinuxI386::canPack()
if (exetype != 0)
return super::canPack();
Elf32_Ehdr ehdr;
Elf_LE32_Ehdr ehdr;
unsigned char *buf = ehdr.e_ident;
fi->seek(0, SEEK_SET);
fi->readx(&ehdr, sizeof(ehdr));
fi->seek(0, SEEK_SET);
@@ -499,12 +511,58 @@ bool PackLinuxI386::canPack()
const unsigned l = get_le32(buf);
int elf = checkEhdr(&ehdr);
if (elf >= 0)
{
if (elf >= 0) {
// NOTE: ELF executables are now handled by p_lx_elf.cpp,
// so we only handle them here if force_execve
if (elf == 0 && opt->o_unix.force_execve)
if (elf == 0 && opt->o_unix.force_execve) {
exetype = 1;
unsigned osabi0 = ehdr.e_ident[Elf32_Ehdr::EI_OSABI];
switch (osabi0) {
case Elf32_Ehdr::ELFOSABI_LINUX:
case Elf32_Ehdr::ELFOSABI_FREEBSD:
case Elf32_Ehdr::ELFOSABI_NETBSD:
case Elf32_Ehdr::ELFOSABI_OPENBSD:
ei_osabi = osabi0; // Proudly declares its osabi in Ehdr.
break;
default:
unsigned const e_phnum = get_native16(&ehdr.e_phnum);
if (e_phnum<=(512/sizeof(Elf32_Phdr))) {
char buf2[512];
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
fi->readx(buf2, sizeof(buf2));
fi->seek(0, SEEK_SET);
Elf32_Phdr const *phdr = (Elf32_Phdr const *)buf2;
for (unsigned j=0; j < e_phnum; ++phdr, ++j) {
if (phdr->PT_NOTE == get_native32(&phdr->p_type)) {
unsigned const offset = get_native32(&phdr->p_offset);
struct Elf32_Note note; memset(&note, 0, sizeof(note));
fi->seek(offset, SEEK_SET);
fi->readx(&note, sizeof(note));
fi->seek(0, SEEK_SET);
if (4==get_native32(&note.descsz)
&& 1==get_native32(&note.type)
&& 0==note.end ) {
if (0==strcmp("NetBSD", (char const *)&note.text)) {
ei_osabi = Elf32_Ehdr::ELFOSABI_NETBSD;
break;
}
if (0==strcmp("OpenBSD", (char const *)&note.text)) {
ei_osabi = Elf32_Ehdr::ELFOSABI_OPENBSD;
break;
}
}
}
}
}
}
}
if (UPX_F_BSD_i386==getFormat()
&& !(Elf32_Ehdr::ELFOSABI_FREEBSD==ei_osabi
|| Elf32_Ehdr::ELFOSABI_NETBSD ==ei_osabi
|| Elf32_Ehdr::ELFOSABI_OPENBSD==ei_osabi )) {
return false;
}
}
else if (l == 0x00640107 || l == 0x00640108 || l == 0x0064010b || l == 0x006400cc)
{
@@ -513,15 +571,17 @@ bool PackLinuxI386::canPack()
// FIXME: N_TRSIZE, N_DRSIZE
// FIXME: check for aout shared libraries
}
#if defined(__linux__)
// only compress scripts when running under Linux
else if (!memcmp(buf, "#!/", 3)) // #!/bin/sh
exetype = -1;
else if (!memcmp(buf, "#! /", 4)) // #! /bin/sh
exetype = -1;
else if (!memcmp(buf, "\xca\xfe\xba\xbe", 4)) // Java bytecode
exetype = -2;
#endif
else { // shell scripts and other interpreters
if (Elf32_Ehdr::ELFOSABI_LINUX!=ei_osabi) {
return false; // so far, only Linux has runtime stub for shell
}
else if (!memcmp(buf, "#!/", 3)) // #!/bin/sh
exetype = -1;
else if (!memcmp(buf, "#! /", 4)) // #! /bin/sh
exetype = -1;
else if (!memcmp(buf, "\xca\xfe\xba\xbe", 4)) // Java bytecode
exetype = -2;
}
return super::canPack();
}
@@ -532,7 +592,7 @@ void PackLinuxI386::patchLoader() { }
void PackLinuxI386::patchLoaderChecksum()
{
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
unsigned char *const ptr = getLoader();
l_info *const lp = (l_info *)(sizeof(elfout.ehdr) +
(elfout.ehdr.e_phnum * elfout.ehdr.e_phentsize) + (char *)&elfout );
// checksum for loader + p_info
+52 -16
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,11 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
@@ -38,7 +41,7 @@ class PackLinuxI386 : public PackUnixLe32
{
typedef PackUnixLe32 super;
public:
PackLinuxI386(InputFile *f) : super(f) { }
PackLinuxI386(InputFile *f);
virtual void generateElfHdr(
OutputFile *,
void const *proto,
@@ -46,9 +49,10 @@ public:
);
virtual int getFormat() const { return UPX_F_LINUX_i386; }
virtual const char *getName() const { return "linux/386"; }
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.execve"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int buildLoader(const Filter *);
virtual void buildLoader(const Filter *);
virtual bool canPack();
@@ -59,8 +63,9 @@ protected:
virtual void pack4(OutputFile *, Filter &); // append PackHeader
// loader util
virtual Linker* newLinker() const;
virtual int getLoaderPrefixSize() const;
virtual int buildLinuxLoader(
virtual void buildLinuxLoader(
upx_byte const *const proto, // assembly-only sections
unsigned const szproto,
upx_byte const *const fold, // linked assembly + C section
@@ -74,9 +79,7 @@ protected:
virtual void updateLoader(OutputFile *);
// ELF util
virtual int checkEhdr(const Elf32_Ehdr *ehdr) const;
virtual off_t getbrk(const Elf32_Phdr *phdr, int e_phnum) const;
virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const;
virtual int checkEhdr(const Elf_LE32_Ehdr *ehdr) const;
enum {
UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
@@ -85,31 +88,64 @@ protected:
unsigned n_mru;
struct cprElfHdr1 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[1];
Elf_LE32_Ehdr ehdr;
Elf_LE32_Phdr phdr[1];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr2 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[2];
Elf_LE32_Ehdr ehdr;
Elf_LE32_Phdr phdr[2];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr3 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[3];
Elf_LE32_Ehdr ehdr;
Elf_LE32_Phdr phdr[3];
l_info linfo;
}
__attribute_packed;
cprElfHdr3 elfout;
struct Elf32_Note {
unsigned namesz; // 8
unsigned descsz; // 4
unsigned type; // 1
char text[0x18 - 4*4]; // "OpenBSD"
unsigned end; // 0
} elfnote;
unsigned char ei_osabi;
char const *osabi_note;
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12)
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
}
};
class PackBSDI386 : public PackLinuxI386
{
typedef PackLinuxI386 super;
public:
PackBSDI386(InputFile *f);
virtual int getFormat() const { return UPX_F_BSD_i386; }
virtual const char *getName() const { return "*BSD/386"; }
virtual const char *getFullName(const options_t *) const { return "i386-bsd.elf.execve"; }
protected:
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void buildLoader(const Filter *);
};
#endif /* already included */
+25 -22
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -22,8 +22,11 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
@@ -48,20 +51,20 @@
**************************************************************************/
static const
#include "stub/l_lx_pti86.h"
#include "stub/i386-linux.elf.interp-entry.h"
static const
#include "stub/fold_pti86.h"
#include "stub/i386-linux.elf.interp-fold.h"
PackLinuxI386interp::PackLinuxI386interp(InputFile *f) :
PackLinuxElf32x86interp::PackLinuxElf32x86interp(InputFile *f) :
super(f)
{
}
PackLinuxI386interp::~PackLinuxI386interp()
PackLinuxElf32x86interp::~PackLinuxElf32x86interp()
{
}
bool PackLinuxI386interp::canPack()
bool PackLinuxElf32x86interp::canPack()
{
if (opt->o_unix.make_ptinterp) {
return true;
@@ -72,7 +75,7 @@ bool PackLinuxI386interp::canPack()
return super::canPack();
}
void PackLinuxI386interp::pack1(OutputFile *fo, Filter &)
void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
{
fi->seek(0, SEEK_SET);
fi->readx(&ehdri, sizeof(ehdri));
@@ -121,7 +124,7 @@ void PackLinuxI386interp::pack1(OutputFile *fo, Filter &)
#undef E
}
void PackLinuxI386interp::pack2(OutputFile *fo, Filter &ft)
void PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft)
{
if (opt->o_unix.make_ptinterp) {
return; // ignore current input file!
@@ -132,7 +135,7 @@ void PackLinuxI386interp::pack2(OutputFile *fo, Filter &ft)
#undef PAGE_MASK
#define PAGE_MASK (~0u<<12)
void PackLinuxI386interp::pack3(OutputFile *fo, Filter &/*ft*/)
void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
{
unsigned base = getbase(phdri, ehdri.e_phnum);
unsigned sz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
@@ -144,26 +147,26 @@ void PackLinuxI386interp::pack3(OutputFile *fo, Filter &/*ft*/)
}
elfout.phdr[0].p_paddr = elfout.phdr[0].p_vaddr = base - sz;
if (opt->o_unix.make_ptinterp) {
initLoader(linux_i386pti_loader, sizeof(linux_i386pti_loader));
linker->addSection("FOLDEXEC", linux_i386pti_fold, sizeof(linux_i386pti_fold));
initLoader(stub_i386_linux_elf_interp_entry, sizeof(stub_i386_linux_elf_interp_entry));
linker->addSection("FOLDEXEC", stub_i386_linux_elf_interp_fold, sizeof(stub_i386_linux_elf_interp_fold), 0);
addLoader("LXPTI000", NULL);
addLoader("LXPTI040", NULL);
ph.method = M_NRV2B_LE32; addLoader(getDecompressor(), NULL);
ph.method = M_NRV2B_LE32; addLoader(getDecompressorSections(), NULL);
addLoader("LXPTI090", NULL);
addLoader("LXPTI041", NULL);
ph.method = M_NRV2D_LE32; addLoader(getDecompressor(), NULL);
ph.method = M_NRV2D_LE32; addLoader(getDecompressorSections(), NULL);
addLoader("LXPTI090", NULL);
addLoader("LXPTI042", NULL);
ph.method = M_NRV2E_LE32; addLoader(getDecompressor(), NULL);
ph.method = M_NRV2E_LE32; addLoader(getDecompressorSections(), NULL);
addLoader("LXPTI090", NULL);
addLoader("LXPTI043", NULL);
ph.method = M_CL1B_LE32; addLoader(getDecompressor(), NULL);
addLoader("LXPTI090", NULL);
//addLoader("LXPTI043", NULL);
//ph.method = M_CL1B_LE32; addLoader(getDecompressorSections(), NULL);
//addLoader("LXPTI090", NULL);
addLoader("LXPTI091", NULL);
@@ -191,7 +194,7 @@ void PackLinuxI386interp::pack3(OutputFile *fo, Filter &/*ft*/)
}
void PackLinuxI386interp::unpack(OutputFile *fo)
void PackLinuxElf32x86interp::unpack(OutputFile *fo)
{
#define MAX_INTERP_HDR 512
char bufehdr[MAX_INTERP_HDR];
+13 -9
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -22,8 +22,11 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
@@ -35,15 +38,16 @@
// linux/interp386
**************************************************************************/
class PackLinuxI386interp : public PackLinuxI386elf
class PackLinuxElf32x86interp : public PackLinuxElf32x86
{
typedef PackLinuxI386elf super;
typedef PackLinuxElf32x86 super;
public:
PackLinuxI386interp(InputFile *f);
virtual ~PackLinuxI386interp();
PackLinuxElf32x86interp(InputFile *f);
virtual ~PackLinuxElf32x86interp();
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_LINUX_ELFI_i386; }
virtual const char *getName() const { return "linux/elfi386"; }
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.interp"; }
virtual bool canPack();
virtual void unpack(OutputFile *fo);
-91
View File
@@ -1,91 +0,0 @@
/* p_lx_sep.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
*/
#include "conf.h"
#include "file.h"
#include "packer.h"
#include "p_elf.h"
#include "p_unix.h"
#include "p_lx_exc.h"
#include "p_lx_elf.h"
#include "p_lx_sep.h"
/*************************************************************************
//
**************************************************************************/
//#define SCRIPT_SIZE (opt->o_unix.SCRIPT_MAX + sizeof(l_info))
#define SCRIPT_SIZE (32 + sizeof(l_info))
const upx_byte *PackLinuxI386sep::getLoader() const
{
static char script[SCRIPT_SIZE];
memset(script, 0, sizeof(script));
char const *name = opt->o_unix.script_name;
if (0==name) {
name = "/usr/local/lib/upxX";
}
upx_snprintf(script, sizeof(script), "#!%s\n", name);
if (M_IS_NRV2B(ph.method)) {
script[strlen(script)-2] = 'b';
return (upx_byte const *)script;
}
if (M_IS_NRV2D(ph.method)) {
script[strlen(script)-2] = 'd';
return (upx_byte const *)script;
}
return NULL;
}
int PackLinuxI386sep::getLoaderSize() const
{
if (M_IS_NRV2B(ph.method))
return SCRIPT_SIZE;
if (M_IS_NRV2D(ph.method))
return SCRIPT_SIZE;
return 0;
}
int PackLinuxI386sep::getLoaderPrefixSize() const
{
return opt->o_unix.SCRIPT_MAX;
}
void PackLinuxI386sep::patchLoader()
{
patchLoaderChecksum();
}
/*
vi:ts=4:et
*/
-61
View File
@@ -1,61 +0,0 @@
/* p_lx_sep.h --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
*/
#ifndef __UPX_P_LX_SEP_H //{
#define __UPX_P_LX_SEP_H
/*************************************************************************
// linux/sep386
**************************************************************************/
class PackLinuxI386sep : public PackLinuxI386elf
{
typedef PackLinuxI386elf super;
public:
PackLinuxI386sep(InputFile *f) : super(f) { }
virtual int getFormat() const { return UPX_F_LINUX_SEP_i386; }
virtual const char *getName() const { return "linux/sep386"; }
protected:
virtual const upx_byte *getLoader() const;
virtual int getLoaderSize() const;
virtual int getLoaderPrefixSize() const;
virtual void patchLoader();
virtual void updateLoader(OutputFile *) {}
};
#endif /*} already included */
/*
vi:ts=4:et
*/
+33 -15
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -22,8 +22,11 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
@@ -45,9 +48,9 @@
**************************************************************************/
static const
#include "stub/l_lx_sh86.h"
#include "stub/i386-linux.elf.shell-entry.h"
static const
#include "stub/fold_sh86.h"
#include "stub/i386-linux.elf.shell-fold.h"
PackLinuxI386sh::PackLinuxI386sh(InputFile *f) :
@@ -59,12 +62,21 @@ PackLinuxI386sh::~PackLinuxI386sh()
{
}
int
static unsigned
umax(unsigned a, unsigned b)
{
if (a <= b) {
return b;
}
return a;
}
void
PackLinuxI386sh::buildLoader(Filter const *ft)
{
unsigned const sz_fold = sizeof(linux_i386sh_fold);
unsigned const sz_fold = sizeof(stub_i386_linux_elf_shell_fold);
MemBuffer buf(sz_fold);
memcpy(buf, linux_i386sh_fold, sz_fold);
memcpy(buf, stub_i386_linux_elf_shell_fold, sz_fold);
checkPatch(NULL, 0, 0, 0); // reset
patch_le32(buf,sz_fold,"UPX3",l_shname);
@@ -73,16 +85,22 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
// get fresh filter
Filter fold_ft = *ft;
fold_ft.init(ft->id, ft->addvalue);
int preferred_ctos[2] = {ft->cto, -1};
int preferred_ctos[2] = { ft->cto, -1 };
fold_ft.preferred_ctos = preferred_ctos;
// filter
optimizeFilter(&fold_ft, buf, sz_fold);
bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2));
unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) +
sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
if (0 == get_le32(fold_hdrlen + buf)) {
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
fold_hdrlen = umax(0x80, fold_hdrlen);
}
bool success = fold_ft.filter(buf + fold_hdrlen, sz_fold - fold_hdrlen);
UNUSED(success);
return buildLinuxLoader(
linux_i386sh_loader, sizeof(linux_i386sh_loader),
buildLinuxLoader(
stub_i386_linux_elf_shell_entry, sizeof(stub_i386_linux_elf_shell_entry),
buf, sz_fold, ft );
}
@@ -140,7 +158,7 @@ bool PackLinuxI386sh::canPack()
void
PackLinuxI386sh::pack1(OutputFile *fo, Filter &)
{
generateElfHdr(fo, linux_i386sh_fold, 0x08048000);
generateElfHdr(fo, stub_i386_linux_elf_shell_fold, 0x08048000);
}
void
+10 -6
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2000-2007 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -22,8 +22,11 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
@@ -44,8 +47,9 @@ public:
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_LINUX_SH_i386; }
virtual const char *getName() const { return "linux/sh386"; }
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.shell"; }
virtual const int *getFilters() const { return NULL; }
virtual int buildLoader(const Filter *);
virtual void buildLoader(const Filter *);
virtual void pack1(OutputFile *fo, Filter &ft);
virtual void pack3(OutputFile *fo, Filter &ft);
+133 -44
View File
@@ -2,7 +2,7 @@
This file is part of the UPX executable compressor.
Copyright (C) 2004 John Reiser
Copyright (C) 2004-2007 John Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -32,12 +32,12 @@
#include "linker.h"
#include "packer.h"
#include "p_mach.h"
#include "ui.h"
static const
#include "stub/l_mac_ppc32.h"
#include "stub/powerpc-darwin.macho-entry.h"
static const
#include "stub/fold_machppc32.h"
#include "stub/powerpc-darwin.macho-fold.h"
PackMachPPC32::PackMachPPC32(InputFile *f) :
super(f), n_segment(0), rawmseg(0), msegcmd(0)
@@ -53,28 +53,53 @@ PackMachPPC32::~PackMachPPC32()
const int *PackMachPPC32::getCompressionMethods(int /*method*/, int /*level*/) const
{
// There really is no LE bias in M_NRV2E_LE32.
static const int m_nrv2e[] = { M_NRV2E_LE32, -1 };
static const int m_nrv2e[] = { M_NRV2E_LE32, M_END };
return m_nrv2e;
}
const int *PackMachPPC32::getFilters() const
{
static const int filters[] = { 0xd0, -1 };
static const int filters[] = { 0xd0, FT_END };
return filters;
}
int
Linker *PackMachPPC32::newLinker() const
{
return new ElfLinkerPpc32;
}
void
PackMachPPC32::addStubEntrySections(Filter const *)
{
addLoader("MACOS000", 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,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL);
addLoader("ELFMAINY,IDENTSTR,+40,ELFMAINZ,FOLDEXEC", NULL);
}
void PackMachPPC32::defineSymbols(Filter const *)
{
// empty
}
void
PackMachPPC32::buildMachLoader(
upx_byte const *const proto,
unsigned const szproto,
upx_byte const *const fold,
unsigned const szfold,
Filter const */*ft*/
Filter const *ft
)
{
int eof_empty = -1;
initLoader(&eof_empty, 4096, 0, 0);
initLoader(proto, szproto);
struct b_info h; memset(&h, 0, sizeof(h));
unsigned fold_hdrlen = 0;
@@ -88,7 +113,7 @@ PackMachPPC32::buildMachLoader(
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
if (0 < szfold) {
unsigned sz_cpr;
unsigned sz_cpr = 0;
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
NULL, ph.method, 10, NULL, NULL );
h.sz_cpr = sz_cpr;
@@ -98,25 +123,24 @@ PackMachPPC32::buildMachLoader(
memcpy(cprLoader, &h, sizeof(h));
// This adds the definition to the "library", to be used later.
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr);
linker->addSection("FOLDEXEC", cprLoader, sizeof(h) + h.sz_cpr, 0);
delete [] cprLoader;
int const GAP = 128; // must match stub/l_mac_ppc.S
segcmdo.vmsize += h.sz_unc - h.sz_cpr + GAP + 64;
linker->addSection("MACOS000", proto, szproto);
addStubEntrySections(ft);
addLoader("MACOS000", NULL);
addLoader("FOLDEXEC", NULL);
return getLoaderSize();
defineSymbols(ft);
relocateLoader();
}
int
void
PackMachPPC32::buildLoader(const Filter *ft)
{
return buildMachLoader(
l_mac_ppc32_loader, sizeof(l_mac_ppc32_loader),
fold_machppc32, sizeof(fold_machppc32), ft );
buildMachLoader(
stub_powerpc_darwin_macho_entry, sizeof(stub_powerpc_darwin_macho_entry),
stub_powerpc_darwin_macho_fold, sizeof(stub_powerpc_darwin_macho_fold), ft );
}
void PackMachPPC32::patchLoader() { }
void PackMachPPC32::updateLoader(OutputFile *) {}
@@ -124,7 +148,7 @@ void PackMachPPC32::updateLoader(OutputFile *) {}
void
PackMachPPC32::patchLoaderChecksum()
{
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
unsigned char *const ptr = getLoader();
l_info *const lp = &linfo;
// checksum for loader; also some PackHeader info
lp->l_checksum = 0;
@@ -171,8 +195,8 @@ PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
BE32 disp;
unsigned const zero = 0;
unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& -len);
len += (3& -len) + sizeof(disp);
fo->write(&zero, 3& (0u-len));
len += (3& (0u-len)) + sizeof(disp);
set_be32(&disp, 4+ len - sz_mach_headers); // 4: sizeof(instruction)
fo->write(&disp, sizeof(disp));
@@ -180,28 +204,69 @@ PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
super::pack3(fo, ft);
}
// 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
// where the PT_LOAD are adjacent ascending by .p_offset. Assume no overlap.
unsigned PackMachPPC32::find_SEGMENT_gap(
unsigned const k
)
{
if (Mach_segment_command::LC_SEGMENT!=msegcmd[k].cmd
|| 0==msegcmd[k].filesize ) {
return 0;
}
unsigned const hi = get_native32(&msegcmd[k].fileoff) +
get_native32(&msegcmd[k].filesize);
unsigned lo = ph.u_file_size;
unsigned j = k;
for (;;) { // circular search, optimize for adjacent ascending
++j;
if (n_segment==j) {
j = 0;
}
if (k==j) {
break;
}
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd
&& 0!=msegcmd[j].filesize ) {
unsigned const t = get_native32(&msegcmd[j].fileoff);
if ((t - hi) < (lo - hi)) {
lo = t;
if (hi==lo) {
break;
}
}
}
}
return lo - hi;
}
void
PackMachPPC32::pack2(OutputFile *fo, Filter &ft) // append compressed body
{
Extent x;
unsigned k;
ui_total_passes = n_segment;
// count passes, set ptload vars
uip->ui_total_passes = 0;
for (k = 0; k < n_segment; ++k) {
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd
&& 0!=msegcmd[k].filesize ) {
uip->ui_total_passes++;
if (find_SEGMENT_gap(k)) {
uip->ui_total_passes++;
}
}
}
// compress extents
unsigned total_in = 0;
unsigned total_out = 0;
ui_pass = -1; // Compressing Mach headers is invisible to UI.
x.offset = 0;
x.size = mhdri.sizeofcmds;
{
int const old_level = ph.level; ph.level = 10;
packExtent(x, total_in, total_out, 0, fo);
ph.level = old_level;
}
unsigned hdr_u_len = mhdri.sizeofcmds;
ui_pass = 0;
uip->ui_pass = 0;
ft.addvalue = 0;
int nx = 0;
@@ -217,13 +282,17 @@ PackMachPPC32::pack2(OutputFile *fo, Filter &ft) // append compressed body
}
packExtent(x, total_in, total_out,
((Mach_segment_command::VM_PROT_EXECUTE & msegcmd[k].initprot)
? &ft : 0 ), fo );
? &ft : 0 ), fo, hdr_u_len );
hdr_u_len = 0;
++nx;
}
if ((off_t)total_in < file_size) { // non-LC_SEGMENT stuff
x.offset = total_in;
x.size = file_size - total_in;
packExtent(x, total_in, total_out, 0, fo);
for (k = 0; k < n_segment; ++k) {
x.size = find_SEGMENT_gap(k);
if (x.size) {
x.offset = get_native32(&msegcmd[k].fileoff) +
get_native32(&msegcmd[k].filesize);
packExtent(x, total_in, total_out, 0, fo);
}
}
if ((off_t)total_in != file_size)
@@ -296,6 +365,21 @@ PackMachPPC32::unpack(OutputFile *fo)
fi->readx(ibuf, ph.c_len);
Mach_header *const mhdr = (Mach_header *)new upx_byte[ph.u_len];
decompress(ibuf, (upx_byte *)mhdr, false);
unsigned const ncmds = mhdr->ncmds;
msegcmd = new Mach_segment_command[ncmds];
unsigned char *ptr = (unsigned char *)(1+mhdr);
for (unsigned j= 0; j < ncmds; ++j) {
msegcmd[j] = *(Mach_segment_command *)ptr;
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize;
}
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command);
n_segment = 0;
for (unsigned j= 0; j < ncmds; ++j) {
n_segment += (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd);
}
unsigned total_in = 0;
unsigned total_out = 0;
@@ -307,7 +391,7 @@ PackMachPPC32::unpack(OutputFile *fo)
fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR);
for (
k = 0;
k < mhdr->ncmds;
k < ncmds;
(++k), (sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc))
) {
if (Mach_segment_command::LC_SEGMENT==sc->cmd
@@ -316,11 +400,16 @@ PackMachPPC32::unpack(OutputFile *fo)
unpackExtent(filesize, fo, total_in, total_out, c_adler, u_adler, false, sizeof(bhdr));
}
}
unsigned const rest = orig_file_size - total_out;
if (0!=rest) { // non-LC_SEGMENT stuff
if (fo)
fo->seek(0, SEEK_END);
unpackExtent(rest, fo, total_in, total_out, c_adler, u_adler, false, sizeof(bhdr));
for (unsigned j = 0; j < ncmds; ++j) {
unsigned const size = find_SEGMENT_gap(j);
if (size) {
unsigned const where = get_native32(&msegcmd[k].fileoff) +
get_native32(&msegcmd[k].filesize);
if (fo)
fo->seek(where, SEEK_SET);
unpackExtent(size, fo, total_in, total_out,
c_adler, u_adler, false, sizeof(bhdr));
}
}
}
+12 -6
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -135,7 +135,8 @@ struct Mach_ppc_thread_state {
BE32 mq; /* MQ register (601 only) */
BE32 vrsave; /* Vector Save Register */
};
}
__attribute_packed;
struct Mach_thread_command {
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
@@ -165,6 +166,7 @@ public:
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_MACH_PPC32; }
virtual const char *getName() const { return "Mach/ppc32"; }
virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.macho"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
@@ -177,18 +179,22 @@ public:
virtual void unpack(OutputFile *fo);
virtual bool canPack();
virtual unsigned find_SEGMENT_gap(unsigned const k);
protected:
virtual int buildLoader(const Filter *ft);
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
virtual void patchLoader();
virtual void patchLoaderChecksum();
virtual void updateLoader(OutputFile *);
virtual int buildMachLoader(
virtual void buildMachLoader(
upx_byte const *const proto,
unsigned const szproto,
upx_byte const *const fold,
unsigned const szfold,
Filter const *ft );
virtual void defineSymbols(Filter const *);
virtual void addStubEntrySections(Filter const *);
unsigned n_segment;
unsigned sz_segment;
+411 -192
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2002-2006 Jens Medoch
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2002-2007 Jens Medoch
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -35,30 +35,31 @@
#include "filter.h"
#include "packer.h"
#include "p_ps1.h"
#include "linker.h"
static const
#include "stub/l_ps1b.h"
static const
#include "stub/l_ps1c.h"
#include "stub/mipsel.r3000-ps1.h"
#define CD_SEC 2048
#define PS_HDR_SIZE CD_SEC
#define PS_RAM_SIZE ram_size
#define PS_MIN_SIZE (PS_HDR_SIZE*3)
#define PS_MAX_SIZE ((PS_RAM_SIZE*95) / 100)
#define PS_STACK_SIZE (PS_RAM_SIZE / 256)
#define MIPS_HI(a) ((a) >> 16)
#define MIPS_LO(a) ((a) & 0xffff)
#define MIPS_JP(a) ((0x08 << 24) | (((a) & 0x0fffffff) >> 2))
#define TIL_ALIGNED(a,b) (((b) - ((a) & ((b) - 1))) & (b) - 1)
#define SZ_IH_BKUP (10 * sizeof(LE32))
#define HD_CODE_OFS (sizeof(ps1_exe_t) + sz_cbh)
#define CD_SEC 2048
#define PS_HDR_SIZE CD_SEC
#define PS_RAM_SIZE 0x200000
#define PS_MIN_SIZE (PS_HDR_SIZE*3)
#define PS_MAX_SIZE 0x1e8000
#define K0_BS (0x80000000)
#define K1_BS (0xa0000000)
#define EXE_BS (ih.epc & K0_BS)
#define FIX_PSVR ((K1_BS - EXE_BS) + (PS_HDR_SIZE - HD_CODE_OFS))
#define SZ_IH_BKUP (10 * sizeof(LE32))
#define HD_CODE_OFS (sizeof(ps1_exe_t))
#define K0_BS (0x80000000)
#define K1_BS (0xa0000000)
#define FIX_PSVR (K1_BS - (ih.epc & K0_BS)) + (PS_HDR_SIZE - HD_CODE_OFS)
// lui / addiu
#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)
/*************************************************************************
@@ -77,21 +78,25 @@ static const
PackPs1::PackPs1(InputFile *f) :
super(f),
isCon(true^opt->ps1_exe.boot_only), is32Bit(true^opt->ps1_exe.do_8bit),
overlap(0), sa_cnt(0)
isCon(!opt->ps1_exe.boot_only), is32Bit(!opt->ps1_exe.do_8bit),
buildPart2(0), foundBss(0), sa_cnt(0), overlap(0), sz_lunc(0), sz_lcpr(0),
pad_code(0), bss_start(0), bss_end(0)
{
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 188);
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t));
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40);
#if 1 || defined(WITH_NRV)
COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3935);
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0x0ac25782);
COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2829);
COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x923b55c4);
#endif
fdata_size = file_size - PS_HDR_SIZE;
}
bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 136)
COMPILE_TIME_ASSERT(sizeof(ps1_exe_hb_t) == 44)
COMPILE_TIME_ASSERT(sizeof(ps1_exe_chb_t) == 5)
COMPILE_TIME_ASSERT_ALIGNED1(ps1_exe_t)
COMPILE_TIME_ASSERT_ALIGNED1(ps1_exe_hb_t)
COMPILE_TIME_ASSERT_ALIGNED1(ps1_exe_chb_t)
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t))
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40)
fdata_size = file_size - PS_HDR_SIZE;
ram_size = !opt->ps1_exe.do_8mb ? 0x200000 : 0x800000;
}
const int *PackPs1::getCompressionMethods(int method, int level) const
{
@@ -101,12 +106,16 @@ const int *PackPs1::getCompressionMethods(int method, int level) const
return Packer::getDefaultCompressionMethods_8(method, level);
}
const int *PackPs1::getFilters() const
{
return NULL;
}
Linker* PackPs1::newLinker() const
{
return new ElfLinkerMipsLE;
}
/*************************************************************************
// util
@@ -118,14 +127,86 @@ int PackPs1::readFileHeader()
{
fi->seek(0, SEEK_SET);
fi->readx(&ih, sizeof(ih));
if (memcmp(&ih.id,"PS-X EXE",8) != 0 &&
memcmp(&ih.id,"EXE X-SP",8) != 0)
if (memcmp(&ih.id, "PS-X EXE", 8) != 0 &&
memcmp(&ih.id, "EXE X-SP", 8) != 0)
return 0;
if (ih.text != 0 || ih.data != 0)
return 0;
return UPX_F_PS1_EXE;
}
bool PackPs1::readBkupHeader()
{
fi->seek(sizeof(ps1_exe_t)+8, SEEK_SET);
fi->readx(&bh, sizeof(bh));
if (bh.ih_csum != upx_adler32(&bh, SZ_IH_BKUP))
{
unsigned char buf[sizeof(bh)];
fi->seek(sizeof(ps1_exe_t), SEEK_SET);
fi->readx(buf, sizeof(bh));
if (!getBkupHeader(buf, (unsigned char *)&bh))
return false;
}
return true;
}
#define INIT_BH_BKUP(p, l) {(p)->id = '1'; (p)->len = l;}
#define ADLER16(a) (((a) >> 16) ^ ((a) & 0xffff))
void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len)
{
unsigned sz_cbh = MemBuffer::getSizeForCompression(SZ_IH_BKUP);
if (src && dst)
{
unsigned char *cpr_bh = new unsigned char[sz_cbh];
memset(cpr_bh, 0, sizeof(bh));
ps1_exe_chb_t * p = (ps1_exe_chb_t * )cpr_bh;
int r = upx_compress(src, SZ_IH_BKUP,
&p->ih_bkup, &sz_cbh, NULL, M_NRV2E_8, 10, NULL, NULL );
if (r != UPX_E_OK || sz_cbh >= SZ_IH_BKUP)
throwInternalError("header compression failed");
INIT_BH_BKUP(p, sz_cbh);
*len = ALIGN_UP(sz_cbh + (unsigned) sizeof(ps1_exe_chb_t) - 1, 4u);
p->ih_csum = ADLER16(upx_adler32(&ih.epc, SZ_IH_BKUP));
memcpy(dst, cpr_bh, SZ_IH_BKUP);
delete [] cpr_bh;
}
else
throwInternalError("header compression failed");
}
#define ADLER16_HI(a, b) ((((a) & 0xffff) ^ (b)) << 16)
#define ADLER16_LO(a, b) (((a) >> 16) ^ (b))
#define RE_ADLER16(a, b) (ADLER16_HI(a,b) | ADLER16_LO(a,b))
bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst)
{
ps1_exe_chb_t *src = (ps1_exe_chb_t*)p;
if (src && (src->id == '1' && src->len < SZ_IH_BKUP) && dst)
{
unsigned char *unc_bh = new unsigned char[MemBuffer::getSizeForUncompression(SZ_IH_BKUP)];
unsigned sz_bh = SZ_IH_BKUP;
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
unc_bh, &sz_bh, M_NRV2E_8, NULL );
if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP)
throwInternalError("header decompression failed");
unsigned ad = upx_adler32(unc_bh, SZ_IH_BKUP);
unsigned ch = src->ih_csum;
if (ad != RE_ADLER16(ad,ch))
throwInternalError("backup header damaged");
memcpy(dst, unc_bh, SZ_IH_BKUP);
delete [] unc_bh;
}
else
return false;
return true;
}
bool PackPs1::checkFileHeader()
{
@@ -148,57 +229,24 @@ bool PackPs1::checkFileHeader()
infoWarning("unsupported header field entry");
return false;
}
if (!opt->force && ih.is_ptr == 0)
if (ih.is_ptr < (EXE_BS | (PS_RAM_SIZE - PS_STACK_SIZE)))
{
infoWarning("stack pointer field empty");
return false;
if (!opt->force)
return false;
else
infoWarning("%s: stack pointer offset low", fi->getName());
}
return true;
}
/*************************************************************************
// patch util
**************************************************************************/
void PackPs1::patch_mips_le(void *b, int blen, const void *old, unsigned new_)
{
size_t patch_len = strlen((const char*)old);
if (patch_len == 2)
{
unsigned char w[2];
set_le16(w, get_be16(old));
patch_le16(b, blen, w, MIPS_LO(new_));
}
else if (patch_len == 4)
{
unsigned char w[4];
set_le32(w, get_be32(old));
int boff = find(b, blen, w, 4);
if (boff == -1)
{
patch_le16(b, blen, &w[0], MIPS_LO(new_));
patch_le16(b, blen, &w[2], MIPS_HI(new_));
}
else
patch_le32((unsigned char *)b + boff, (blen-boff), &w, new_);
}
else
throwInternalError("bad marker length");
}
/*************************************************************************
//
**************************************************************************/
bool PackPs1::canPack()
{
unsigned char buf[PS_HDR_SIZE-HD_CODE_OFS];
unsigned char buf[PS_HDR_SIZE - sizeof(ps1_exe_t)];
if (!readFileHeader())
return false;
@@ -221,7 +269,7 @@ bool PackPs1::canPack()
throwCantPack("unsupported header flags (try --force)");
if (!opt->force && file_size < PS_MIN_SIZE)
throwCantPack("file is too small (try --force)");
if (!opt->force && file_size > PS_MAX_SIZE)
if (!opt->force && file_size > (off_t) PS_MAX_SIZE)
throwCantPack("file is too big (try --force)");
return true;
}
@@ -231,44 +279,184 @@ bool PackPs1::canPack()
//
**************************************************************************/
int PackPs1::buildLoader(const Filter *)
void PackPs1::buildLoader(const Filter *)
{
if (isCon)
initLoader(nrv_con_loader,sizeof(nrv_con_loader));
else
initLoader(nrv_boot_loader,sizeof(nrv_boot_loader));
addLoader("PS1START",
isCon ? ph.c_len & 3 ? "PS1PADCD" : "" : "PS1ENTRY",
ih.tx_ptr & 0xffff ? "PS1CONHL" : "PS1CONHI",
isCon ? "PS1ENTRY" : "",
NULL);
const char *method = NULL;
if (ph.method == M_NRV2B_8)
addLoader("PS1N2B08", NULL);
method = isCon ? "nrv2b.small,8bit.sub,nrv.done" :
"nrv2b.8bit,nrv.done";
else if (ph.method == M_NRV2D_8)
addLoader("PS1N2D08", NULL);
method = isCon ? "nrv2d.small,8bit.sub,nrv.done" :
"nrv2d.8bit,nrv.done";
else if (ph.method == M_NRV2E_8)
addLoader("PS1N2E08", NULL);
method = isCon ? "nrv2e.small,8bit.sub,nrv.done" :
"nrv2e.8bit,nrv.done";
else if (ph.method == M_NRV2B_LE32)
addLoader("PS1N2B32", NULL);
method = isCon ? "nrv2b.small,32bit.sub,nrv.done" :
"nrv2b.32bit,nrv.done";
else if (ph.method == M_NRV2D_LE32)
addLoader("PS1N2D32", NULL);
method = isCon ? "nrv2d.small,32bit.sub,nrv.done" :
"nrv2d.32bit,nrv.done";
else if (ph.method == M_NRV2E_LE32)
addLoader("PS1N2E32", NULL);
method = isCon ? "nrv2e.small,32bit.sub,nrv.done" :
"nrv2e.32bit,nrv.done";
else if (M_IS_LZMA(ph.method))
method = "nrv2b.small,8bit.sub,nrv.done,lzma.prep";
else
throwInternalError("unknown compression method");
if (sa_cnt)
addLoader(sa_cnt > (0x10000 << 2) ? "PS1MSETB" : "PS1MSETS",
ih.tx_len & 3 ? "PS1MSETU" : "PS1MSETA",
NULL);
unsigned sa_tmp = sa_cnt;
if (ph.overlap_overhead > sa_cnt)
{
if (!opt->force)
{
infoWarning("not in-place decompressible");
throwCantPack("packed data overlap (try --force)");
}
else
sa_tmp += overlap = ALIGN_UP((ph.overlap_overhead - sa_tmp), 4u);
}
addLoader("PS1EXITC", "IDENTSTR", "PS1PAHDR",
isCon ? "PS1SREGS" : "",
NULL);
foundBss = findBssSection();
return getLoaderSize();
if (M_IS_LZMA(ph.method) && !buildPart2)
{
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1));
addLoader("decompressor.start",
isCon ? "LZMA_DEC20" : "LZMA_DEC10", "lzma.init", NULL);
addLoader(sa_tmp > (0x10000 << 2) ? "memset.long" : "memset.short",
!foundBss ? "con.exit" : "bss.exit", NULL);
}
else
{
if (M_IS_LZMA(ph.method) && buildPart2)
{
sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc);
unsigned char *cprLoader = new unsigned char[sz_lcpr];
int r = upx_compress(getLoader(), sz_lunc, cprLoader, &sz_lcpr,
NULL, M_NRV2B_8, 10, NULL, NULL );
if (r != UPX_E_OK || sz_lcpr >= sz_lunc)
throwInternalError("loader compression failed");
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1),
isCon || !M_IS_LZMA(ph.method) ? 0 : 1);
linker->addSection("lzma.exec", cprLoader, sz_lcpr, 0);
delete [] cprLoader;
}
else
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1));
pad_code = ALIGN_GAP((ph.c_len + (isCon ? sz_lcpr : 0)), 4u);
assert(pad_code < 4);
static const unsigned char pad_buffer[4] = { 0, 0, 0, 0 };
linker->addSection("pad.code", pad_buffer, pad_code, 0);
if (isCon)
{
if (M_IS_LZMA(ph.method))
addLoader(!foundBss ? "con.start" : "bss.con.start",
method,
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
"con.entry", "pad.code", "lzma.exec", NULL);
else
addLoader(!foundBss ? "con.start" : "bss.con.start", "con.mcpy",
ph.c_len & 3 ? "con.padcd" : "",
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
"con.entry", method,
sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "",
!foundBss ? "con.exit" : "bss.exit",
"pad.code", NULL);
}
else
{
if (M_IS_LZMA(ph.method))
addLoader("cdb.start.lzma", "pad.code", "cdb.entry.lzma", method, "cdb.lzma.cpr",
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
"lzma.exec", NULL);
else
addLoader("cdb.start", "pad.code", "cdb.entry",
ih.tx_ptr & 0xffff ? "cdb.dec.ptr" : "cdb.dec.ptr.hi",
method,
sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "",
!foundBss ? "cdb.exit" : "bss.exit",
"pad.code", NULL);
}
addLoader("UPX1HEAD", "IDENTSTR", NULL);
}
}
#define OPTYPE(x) (((x) >> 13) & 0x7)
#define OPCODE(x) (((x) >> 10) & 0x7)
#define REG1(x) (((x) >> 5) & 0x1f)
#define REG2(x) ((x) & 0x1f)
#define MIPS_IMM(a,b) ((((a) - (((b) & 0x8000) >> 15)) << 16) | (b))
// Type
#define REGIMM 1
#define STORE 5
// Op
#define LUI 7
#define ADDIU 1
#define SW 3
#define IS_LUI(a) ((OPTYPE(a) == REGIMM && OPCODE(a) == LUI))
#define IS_ADDIU(a) ((OPTYPE(a) == REGIMM && OPCODE(a) == ADDIU))
#define IS_SW_ZERO(a) ((OPTYPE(a) == STORE && OPCODE(a) == SW) && REG2(a) == 0)
#define BSS_CHK_LIMIT (18)
bool PackPs1::findBssSection()
{
unsigned char reg;
LE32 *p1 = (LE32 *)(ibuf + (ih.epc - ih.tx_ptr));
if ((ih.epc - ih.tx_ptr + (BSS_CHK_LIMIT * 4)) > fdata_size)
return false;
// check 18 opcodes for sw zero,0(x)
for (signed i = BSS_CHK_LIMIT; i >= 0; i--)
{
unsigned short op = p1[i] >> 16;
if (IS_SW_ZERO(op))
{
// found! get reg (x) for bss_start
reg = REG1(op);
for (; i >= 0; i--)
{
bss_nfo *p = (bss_nfo *)&p1[i];
unsigned short op1 = p->op1, op2 = p->op2;
// check for la (x),bss_start
if ((IS_LUI(op1) && REG2(op1) == reg) &&
(IS_ADDIU(op2) && REG1(op2) == reg))
{
op1 = p->op3, op2 = p->op4;
// check for la (y),bss_end
if (IS_LUI(op1) && IS_ADDIU(op2))
{
// bss section info found!
bss_start = MIPS_IMM(p->hi1, p->lo1);
bss_end = MIPS_IMM(p->hi2, p->lo2);
if (0 < ALIGN_DOWN(bss_end - bss_start, 4u))
{
unsigned wkmem_sz = M_IS_LZMA(ph.method) ? 32768 : 800;
unsigned end_offs = ih.tx_ptr + fdata_size + overlap;
if (bss_end > (end_offs + wkmem_sz))
return isCon || (!isCon && M_IS_LZMA(ph.method));
else
return false;
}
}
else
return false;
}
}
}
}
return false;
}
@@ -280,7 +468,7 @@ void PackPs1::pack(OutputFile *fo)
{
ibuf.alloc(fdata_size);
obuf.allocForCompression(fdata_size);
const upx_byte *p_scan = ibuf+fdata_size;
const upx_byte *p_scan = ibuf + fdata_size;
// read file
fi->seek(PS_HDR_SIZE,SEEK_SET);
@@ -288,12 +476,12 @@ void PackPs1::pack(OutputFile *fo)
// scan EOF for 2048 bytes sector alignment
// the removed space will secure in-place decompression
while (!(*--p_scan)) { if (sa_cnt++ > (0x10000<<5) || sa_cnt >= fdata_size-1024) break; }
while (!(*--p_scan)) { if (sa_cnt++ > (0x10000 << 5) || sa_cnt >= fdata_size - 1024) break; }
if (sa_cnt > (0x10000<<2))
sa_cnt = ALIGN_DOWN(sa_cnt,32);
if (sa_cnt > (0x10000 << 2))
sa_cnt = ALIGN_DOWN(sa_cnt, 32u);
else
sa_cnt = ALIGN_DOWN(sa_cnt,4);
sa_cnt = ALIGN_DOWN(sa_cnt, 4u);
// prepare packheader
ph.u_len = (fdata_size - sa_cnt);
@@ -301,29 +489,47 @@ void PackPs1::pack(OutputFile *fo)
Filter ft(ph.level);
// compress (max_match = 65535)
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
upx_compress_config_t cconf; cconf.reset();
cconf.conf_ucl.max_match = 65535;
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
compressWithFilters(&ft, sa_cnt, &cconf);
if (ph.overlap_overhead > sa_cnt)
if (overlap)
{
if (!opt->force)
{
infoWarning("not in-place decompressible");
throwCantPack("packed data overlap (try --force)");
}
else
{
overlap = ALIGN_UP((ph.overlap_overhead-sa_cnt),4);
opt->info_mode += !opt->info_mode ? 1 : 0;
infoWarning("%s: memory overlap %d bytes",fi->getName(),overlap);
}
opt->info_mode += !opt->info_mode ? 1 : 0;
infoWarning("overlap - relocating load address (+%d bytes)", overlap);
sa_cnt += overlap;
}
/*
if (bss_start && bss_end && !foundBss)
infoWarning("%s: .bss section too small - use stack", fi->getName());
*/
unsigned lzma_init = 0;
if (M_IS_LZMA(ph.method))
{
sz_lunc = getLoaderSize();
lzma_init = 0u - (sz_lunc - linker->getSymbolOffset("lzma.init"));
defineDecompressorSymbols();
linker->defineSymbol("entry", ih.epc);
linker->defineSymbol("SC",
sa_cnt > (0x10000 << 2) ? sa_cnt >> 5 : sa_cnt >> 2);
relocateLoader();
buildPart2 = true;
buildLoader(&ft);
}
memcpy(&oh, &ih, sizeof(ih));
memcpy(&oh.ih_bkup, &ih.epc, SZ_IH_BKUP);
oh.ih_csum = upx_adler32(&ih.epc, SZ_IH_BKUP);
if (ih.is_ptr == 0)
oh.is_ptr = PS_RAM_SIZE-0x10;
unsigned sz_cbh;
putBkupHeader((const unsigned char *)&ih.epc, (unsigned char *)&bh, &sz_cbh);
if (ih.is_ptr < (EXE_BS | (PS_RAM_SIZE - PS_STACK_SIZE)))
oh.is_ptr = (EXE_BS | (PS_RAM_SIZE - 16));
if (ih.da_ptr != 0 || ih.da_len != 0 ||
ih.bs_ptr != 0 || ih.bs_len != 0)
@@ -331,47 +537,46 @@ void PackPs1::pack(OutputFile *fo)
oh.bs_ptr = oh.bs_len = 0;
const int lsize = getLoaderSize();
MemBuffer loader(lsize);
memcpy(loader, getLoader(), lsize);
patchPackHeader(loader,lsize);
unsigned pad = 0;
unsigned filelen = ALIGN_UP(ih.tx_len, 4);
unsigned pad_code = TIL_ALIGNED(ph.c_len, 4);
const unsigned decomp_data_start = ih.tx_ptr;
const unsigned comp_data_start = ((decomp_data_start + filelen + overlap) - ph.c_len);
const unsigned comp_data_start = (decomp_data_start + filelen + overlap) - ph.c_len;
const int h_len = lsize - getLoaderSectionStart("IDENTSTR");
const int c_len = lsize - h_len;
const int h_len = lsize - getLoaderSectionStart("UPX1HEAD");
int d_len = 0;
int e_len = 0;
if (isCon)
{
e_len = lsize - h_len;
d_len = e_len - getLoaderSectionStart("PS1ENTRY");
d_len = e_len - getLoaderSectionStart("con.entry");
}
else
{
d_len = (lsize - h_len) - getLoaderSectionStart("PS1ENTRY");
d_len = (lsize - h_len) - getLoaderSectionStart(M_IS_LZMA(ph.method) ? "cdb.entry.lzma" : "cdb.entry");
e_len = (lsize - d_len) - h_len;
}
patch_mips_le(loader,c_len,"JPEP",MIPS_JP(ih.epc));
if (sa_cnt)
patch_mips_le(loader,c_len,"SC",
MIPS_LO(sa_cnt > (0x10000 << 2) ? sa_cnt >> 5 : sa_cnt >> 2));
if (ih.tx_ptr & 0xffff)
patch_mips_le(loader,c_len,"DECO",decomp_data_start);
else
patch_mips_le(loader,c_len,"DE",MIPS_HI(decomp_data_start));
linker->defineSymbol("entry", ih.epc);
linker->defineSymbol("SC", MIPS_LO(sa_cnt > (0x10000 << 2) ?
sa_cnt >> 5 : sa_cnt >> 2));
linker->defineSymbol("DECO", decomp_data_start);
linker->defineSymbol("ldr_sz", M_IS_LZMA(ph.method) ? sz_lunc + 16 : (d_len-pad_code));
const unsigned entry = comp_data_start - e_len - pad_code;
oh.tx_ptr = entry;
oh.tx_len = ph.c_len + e_len + pad_code;
oh.epc = comp_data_start - e_len - pad_code;
if (foundBss)
if (M_IS_LZMA(ph.method))
linker->defineSymbol("wrkmem", bss_end - 160 - getDecompressorWrkmemSize()
- (sz_lunc + 16));
else
linker->defineSymbol("wrkmem", bss_end - 16 - (d_len - pad_code));
const unsigned entry = comp_data_start - e_len;
oh.epc = oh.tx_ptr = entry;
oh.tx_len = ph.c_len + e_len;
unsigned pad = 0;
if (!opt->ps1_exe.no_align)
{
@@ -384,43 +589,53 @@ void PackPs1::pack(OutputFile *fo)
ibuf.clear(0,fdata_size);
upx_bytep paddata = ibuf;
if (M_IS_LZMA(ph.method))
{
linker->defineSymbol("lzma_init_off", lzma_init);
linker->defineSymbol("gb_e", linker->getSymbolOffset("gb8_e"));
}
else
if (isCon)
linker->defineSymbol("gb_e", linker->getSymbolOffset(is32Bit ? "gb32_e" : "gb8_e"));
if (isCon)
{
if (pad_code)
patch_mips_le(loader, c_len, "PC", pad_code);
patch_mips_le(loader, c_len, "DCRT", entry + (e_len - d_len));
patch_mips_le(loader, c_len, "LS",
d_len + get_le32(&loader[getLoaderSectionStart("PS1SREGS")]));
// ps1_exe_t structure 188 bytes
fo->write(&oh,sizeof(oh));
// id & upx header
fo->write(loader + e_len,h_len);
linker->defineSymbol("PAD", pad_code);
if (M_IS_LZMA(ph.method))
linker->defineSymbol("DCRT", (entry + getLoaderSectionStart("lzma.exec")));
else
linker->defineSymbol("DCRT", (entry + (e_len - d_len)));
}
else
{
patch_mips_le(loader, c_len, "CPDO", comp_data_start);
patch_mips_le(loader, e_len, "PSVR", FIX_PSVR);
// ps1_exe_t structure 188 bytes
fo->write(&oh,sizeof(oh));
// decompressor
fo->write(loader + e_len, d_len);
// id & upx header
fo->write(loader + e_len + d_len, h_len);
linker->defineSymbol("PSVR", FIX_PSVR);
linker->defineSymbol("CPDO", comp_data_start);
if (M_IS_LZMA(ph.method))
linker->defineSymbol("lzma_cpr", getLoaderSectionStart("lzma.exec")
- getLoaderSectionStart("cdb.entry.lzma"));
}
// header size is 2048 bytes
fo->write(paddata, PS_HDR_SIZE - fo->getBytesWritten());
// sector alignment
if (pad)
fo->write(paddata, pad);
relocateLoader();
//linker->dumpSymbols();
MemBuffer loader(lsize);
assert(lsize == getLoaderSize());
memcpy(loader, getLoader(), lsize);
patchPackHeader(loader, lsize);
if (!isCon && M_IS_LZMA(ph.method) && (HD_CODE_OFS + d_len + h_len) > CD_SEC)
throwInternalError("lzma --boot-only loader > 2048");
// ps1_exe_t structure
fo->write(&oh, sizeof(oh));
fo->write(&bh, sz_cbh);
// decompressor
fo->write(loader + e_len, isCon ? h_len : (d_len + h_len));
// header size is 2048 bytes + sector alignment
fo->write(paddata, (pad + PS_HDR_SIZE) - fo->getBytesWritten());
// entry
fo->write(loader, e_len);
// code must be aligned to 4!
if (pad_code)
fo->write(paddata, pad_code);
// compressed binary / data
// compressed body
fo->write(obuf, ph.c_len);
verifyOverlappingDecompression();
@@ -428,15 +643,23 @@ void PackPs1::pack(OutputFile *fo)
throwNotCompressible();
#if 0
printf("%-13s: uncompressed : %8ld bytes\n", getName(), (long) ph.u_len);
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
printf("%-13s: decompressor : %8ld bytes\n", getName(), (long) lsize - h_len);
printf("%-13s: code entry : %08X bytes\n", getName(), (unsigned int) oh.epc);
printf("%-13s: load address : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr);
printf("%-13s: eof in mem IF: %08X bytes\n", getName(), (unsigned int) ih.tx_ptr+ih.tx_len);
printf("%-13s: eof in mem OF: %08X bytes\n", getName(), (unsigned int) oh.tx_ptr+oh.tx_len);
printf("%-13s: uncompressed : %8ld bytes\n", getName(), (long) ph.u_len);
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
printf("%-13s: decompressor : %8ld bytes\n", getName(), (long) lsize - h_len - pad_code);
printf("%-13s: header comp : %8ld bytes\n", getName(), (long) sz_cbh);
printf("%-13s: overlap : %8ld bytes\n", getName(), (long) overlap);
printf("%-13s: load address : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr);
printf("%-13s: code entry : %08X bytes\n", getName(), (unsigned int) oh.epc);
printf("%-13s: bbs start : %08X bytes\n", getName(), (unsigned int) bss_start);
printf("%-13s: bbs end : %08X bytes\n", getName(), (unsigned int) bss_end);
printf("%-13s: eof in mem IF : %08X bytes\n", getName(), (unsigned int) ih.tx_ptr + ih.tx_len);
printf("%-13s: eof in mem OF : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr + oh.tx_len);
unsigned char i = 0;
if (isCon) { if (foundBss) i = 1; }
else { i = 2; if (M_IS_LZMA(ph.method)) { if (!foundBss) i = 3; else i = 4; } }
const char *loader_method[] = { "con/stack", "con/bss", "cdb", "cdb/stack", "cdb/bss" };
char method_name[32+1]; set_method_name(method_name, sizeof(method_name), ph.method, ph.level);
printf("%-13s: compressor : %s\n", getName(), method_name);
printf("%-13s: methods : %s, %s\n", getName(), method_name, loader_method[i]);
#endif
}
@@ -449,11 +672,10 @@ int PackPs1::canUnpack()
{
if (!readFileHeader())
return false;
if (!readPackHeader(1024))
if (!readPackHeader(CD_SEC))
return false;
// check header as set by packer
if (ih.ih_csum != upx_adler32(&ih.ih_bkup, SZ_IH_BKUP) &&
(ph.c_len >= fdata_size))
if (!readBkupHeader() || ph.c_len >= fdata_size)
throwCantUnpack("header damaged");
// generic check
if (!checkFileHeader())
@@ -470,7 +692,7 @@ void PackPs1::unpack(OutputFile *fo)
{
// restore orig exec hdr
memcpy(&oh, &ih, sizeof(ih));
memcpy(&oh.epc, &ih.ih_bkup, SZ_IH_BKUP);
memcpy(&oh.epc, &bh, SZ_IH_BKUP);
// check for removed sector alignment
assert(oh.tx_len >= ph.u_len);
@@ -482,9 +704,6 @@ void PackPs1::unpack(OutputFile *fo)
fi->seek(PS_HDR_SIZE, SEEK_SET);
fi->readx(ibuf, fdata_size);
// clear backup and checksum of header
memset(&oh.ih_bkup, 0, SZ_IH_BKUP+4);
// decompress
decompress(ibuf + (fdata_size - ph.c_len), obuf);
@@ -495,14 +714,14 @@ void PackPs1::unpack(OutputFile *fo)
fo->write(&oh, sizeof(oh));
// align the ps exe header (mode 2 sector data size)
ibuf.clear();
fo->write(ibuf, PS_HDR_SIZE - fo->getBytesWritten());
// write uncompressed data + pad
fo->write(ibuf, PS_HDR_SIZE - sizeof(oh));
obuf.clear(ph.u_len, pad);
fo->write(obuf, ph.u_len + pad);
}
}
/*
vi:ts=4:et:nowrap
*/
+41 -14
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 2002-2004 Jens Medoch
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
Copyright (C) 2002-2007 Jens Medoch
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -46,6 +46,7 @@ public:
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_PS1_EXE; }
virtual const char *getName() const { return "ps1/exe"; }
virtual const char *getFullName(const options_t *) const { return "mipsel.r3000-ps1"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
@@ -56,8 +57,12 @@ public:
virtual int canUnpack();
protected:
virtual void patch_mips_le(void *b, int blen, const void *old, unsigned new_);
virtual int buildLoader(const Filter *ft);
virtual void putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len);
virtual bool getBkupHeader(unsigned char *src, unsigned char * dst);
virtual bool readBkupHeader();
virtual void buildLoader(const Filter *ft);
virtual bool findBssSection();
virtual Linker* newLinker() const;
virtual int readFileHeader();
virtual bool checkFileHeader();
@@ -84,24 +89,48 @@ protected:
LE32 sp, fp, gp0, ra, k0;
// origin Jap/USA/Europe
char origin[60];
// some safety space after that
char pad[8];
// backup of the original header (epc - is_len)
// id & the upx header ...
}
__attribute_packed;
// for unpack
struct ps1_exe_hb_t
{
LE32 ih_bkup[10];
// plus checksum for the backup
LE32 ih_csum;
// id & the upx header.
}
__attribute_packed;
struct ps1_exe_chb_t
{
unsigned char id;
unsigned char len;
LE16 ih_csum;
unsigned char ih_bkup;
}
__attribute_packed;
struct bss_nfo
{
LE16 hi1, op1, lo1, op2;
LE16 hi2, op3, lo2, op4;
}
__attribute_packed;
ps1_exe_t ih, oh;
ps1_exe_hb_t bh;
bool isCon;
bool is32Bit;
unsigned overlap;
unsigned sa_cnt;
bool buildPart2;
bool foundBss;
unsigned ram_size;
unsigned sa_cnt, overlap;
unsigned sz_lunc, sz_lcpr;
unsigned pad_code;
unsigned bss_start, bss_end;
// filesize-PS_HDR_SIZE
unsigned fdata_size;
};
@@ -113,5 +142,3 @@ protected:
/*
vi:ts=4:et
*/
+22 -25
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -32,9 +32,10 @@
#include "packer.h"
#include "p_com.h"
#include "p_sys.h"
#include "linker.h"
static const
#include "stub/l_sys.h"
#include "stub/i086-dos16.sys.h"
/*************************************************************************
@@ -67,34 +68,31 @@ void PackSys::patchLoader(OutputFile *fo,
upx_byte *loader, int lsize,
unsigned calls)
{
const int filter_id = ph.filter;
const int e_len = getLoaderSectionStart("SYSCUTPO");
const int d_len = lsize - e_len;
assert(e_len > 0 && e_len < 256);
assert(e_len > 0 && e_len < 128);
assert(d_len > 0 && d_len < 256);
if (ph.u_len + d_len + ph.overlap_overhead > 0xfffe)
throwNotCompressible();
memcpy(loader,ibuf,6); // copy from orig. header
memcpy(loader+8,ibuf+8,2); // opendos wants this word too
// use some fields of the original file
linker->defineSymbol("attribute", get_le16(ibuf + 4));
linker->defineSymbol("interrupt", get_le16(ibuf + 8));
unsigned copy_to = ph.u_len + d_len + ph.overlap_overhead;
patch_le16(loader,lsize,"JO",get_le16(ibuf+6)-copy_to-1);
if (filter_id)
{
assert(calls > 0);
patch_le16(loader,lsize,"CT",calls);
}
linker->defineSymbol("calltrick_calls", calls);
linker->defineSymbol("copy_source", ph.c_len + lsize - 1);
linker->defineSymbol("copy_destination", copy_to);
linker->defineSymbol("neg_e_len", 0 - e_len);
linker->defineSymbol("NRV2B160", ph.u_len + ph.overlap_overhead + 1);
linker->defineSymbol("original_strategy", get_le16(ibuf + 6));
relocateLoader();
loader = getLoader();
patchPackHeader(loader,e_len);
const unsigned jmp_pos = find_le16(loader,e_len,get_le16("JM"));
patch_le16(loader,e_len,"JM",ph.u_len+ph.overlap_overhead+2-jmp_pos-2);
loader[getLoaderSectionStart("SYSSUBSI") - 1] = (upx_byte) -e_len;
patch_le16(loader,e_len,"DI",copy_to);
patch_le16(loader,e_len,"SI",ph.c_len+e_len+d_len-1);
// write loader + compressed file
fo->write(loader,e_len); // entry
fo->write(obuf,ph.c_len);
@@ -102,17 +100,17 @@ void PackSys::patchLoader(OutputFile *fo,
}
int PackSys::buildLoader(const Filter *ft)
void PackSys::buildLoader(const Filter *ft)
{
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
initLoader(stub_i086_dos16_sys, sizeof(stub_i086_dos16_sys));
addLoader("SYSMAIN1",
opt->cpu == opt->CPU_8086 ? "SYSI0861" : "SYSI2861",
"SYSMAIN2,SYSSUBSI",
"SYSMAIN2",
ph.first_offset_found == 1 ? "SYSSBBBP" : "",
ft->id ? "SYSCALLT" : "",
"SYSMAIN3,UPX1HEAD,SYSCUTPO,NRV2B160,NRVDDONE,NRVDECO1",
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
"NRVDECO2,NRV2B169",
"NRVDECO2",
NULL
);
if (ft->id)
@@ -125,7 +123,6 @@ int PackSys::buildLoader(const Filter *ft)
"SYSJUMP1",
NULL
);
return getLoaderSize();
}
+5 -4
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -42,6 +42,7 @@ public:
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_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 bool canPack();
@@ -49,7 +50,7 @@ protected:
virtual unsigned getCallTrickOffset() const { return 0; }
protected:
virtual int buildLoader(const Filter *ft);
virtual void buildLoader(const Filter *ft);
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
};
+45 -29
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -31,9 +31,10 @@
#include "filter.h"
#include "packer.h"
#include "p_tmt.h"
#include "linker.h"
static const
#include "stub/l_tmt.h"
#include "stub/i386-dos32.tmt.h"
#define EXTRA_INFO 4 // original entry point
@@ -44,6 +45,7 @@ static const
PackTmt::PackTmt(InputFile *f) : super(f)
{
bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(tmt_header_t) == 44);
}
@@ -57,8 +59,9 @@ const int *PackTmt::getCompressionMethods(int method, int level) const
const int *PackTmt::getFilters() const
{
static const int filters[] = {
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x12, 0x15,
-1 };
0x26, 0x24, 0x49, 0x46, 0x16, 0x13, 0x14, 0x11,
FT_ULTRA_BRUTE, 0x25, 0x15, 0x12,
FT_END };
return filters;
}
@@ -74,17 +77,27 @@ unsigned PackTmt::findOverlapOverhead(const upx_bytep buf,
}
int PackTmt::buildLoader(const Filter *ft)
Linker* PackTmt::newLinker() const
{
return new ElfLinkerX86;
}
void PackTmt::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader,sizeof(nrv_loader));
initLoader(stub_i386_dos32_tmt, sizeof(stub_i386_dos32_tmt));
addLoader("IDENTSTR,TMTMAIN1",
ph.first_offset_found == 1 ? "TMTMAIN1A" : "",
"TMTMAIN1B",
ft->id ? "TMTCALT1" : "",
"TMTMAIN2,UPX1HEAD,TMTCUTPO,+0XXXXXX",
getDecompressor(),
"TMTMAIN5",
NULL
);
"TMTMAIN2,UPX1HEAD,TMTCUTPO",
NULL);
// fake alignment for the start of the decompressor
linker->defineSymbol("TMTCUTPO", 0x1000);
addLoader(getDecompressorSections(), "TMTMAIN5", NULL);
if (ft->id)
{
assert(ft->calls > 0);
@@ -96,7 +109,6 @@ int PackTmt::buildLoader(const Filter *ft)
"RELOC32J,TMTJUMP1",
NULL
);
return getLoaderSize();
}
@@ -159,7 +171,7 @@ int PackTmt::readFileHeader()
fi->seek(adam_offset,SEEK_SET);
fi->readx(&ih,sizeof(ih));
// FIXME: should add some checks for the values in `ih'
// FIXME: should add some checks for the values in 'ih'
return UPX_F_TMT_ADAM;
#undef H4
@@ -227,33 +239,37 @@ void PackTmt::pack(OutputFile *fo)
Filter ft(ph.level);
ft.buf_len = usize;
// compress
compressWithFilters(&ft, 512);
upx_compress_config_t cconf; cconf.reset();
// limit stack size needed for runtime decompression
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
compressWithFilters(&ft, 512, &cconf);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
memcpy(loader,getLoader(),lsize);
const unsigned s_point = getLoaderSection("TMTMAIN1");
int e_len = getLoaderSectionStart("TMTCUTPO");
const unsigned d_len = lsize - e_len;
assert(e_len > 0 && s_point > 0);
// patch loader
patch_le32(loader,lsize,"JMPO",ih.entry-(ph.u_len+ph.overlap_overhead+d_len));
patchFilter32(loader, lsize, &ft);
patchPackHeader(loader,e_len);
linker->defineSymbol("original_entry", ih.entry);
defineDecompressorSymbols();
defineFilterSymbols(&ft);
const unsigned jmp_pos = find_le32(loader,e_len,get_le32("JMPD"));
patch_le32(loader,e_len,"JMPD",ph.u_len+ph.overlap_overhead-jmp_pos-4);
patch_le32(loader,e_len,"ECX0",ph.c_len+d_len);
patch_le32(loader,e_len,"EDI0",ph.u_len+ph.overlap_overhead+d_len-1);
patch_le32(loader,e_len,"ESI0",ph.c_len+e_len+d_len-1);
//fprintf(stderr,"\nelen=%x dlen=%x copy_len=%x copy_to=%x oo=%x jmp_pos=%x ulen=%x clen=%x \n\n",
linker->defineSymbol("bytes_to_copy", ph.c_len + d_len);
linker->defineSymbol("copy_dest", 0u - (ph.u_len + ph.overlap_overhead + d_len - 1));
linker->defineSymbol("copy_source", ph.c_len + lsize - 1);
//fprintf(stderr,"\nelen=%x dlen=%x copy_len=%x copy_to=%x oo=%x jmp_pos=%x ulen=%x c_len=%x \n\n",
// e_len,d_len,copy_len,copy_to,ph.overlap_overhead,jmp_pos,ph.u_len,ph.c_len);
linker->defineSymbol("TMTCUTPO", ph.u_len + ph.overlap_overhead);
relocateLoader();
MemBuffer loader(lsize);
memcpy(loader,getLoader(),lsize);
patchPackHeader(loader,e_len);
memcpy(&oh,&ih,sizeof(oh));
oh.imagesize = ph.c_len+e_len+d_len; // new size
oh.imagesize = ph.c_len + lsize; // new size
oh.entry = s_point; // new entry point
oh.relocsize = 4;
+6 -4
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -42,6 +42,7 @@ public:
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_TMT_ADAM; }
virtual const char *getName() const { return "tmt/adam"; }
virtual const char *getFullName(const options_t *) const { return "i386-dos32.tmt"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
@@ -57,7 +58,8 @@ protected:
virtual unsigned findOverlapOverhead(const upx_bytep buf,
unsigned range = 0,
unsigned upper_limit = ~0u) const;
virtual int buildLoader(const Filter *ft);
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
unsigned adam_offset;
int big_relocs;
+355 -262
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -32,21 +32,12 @@
#include "filter.h"
#include "packer.h"
#include "p_tos.h"
#include "linker.h"
static const
#include "stub/l_t_n2b.h"
static const
#include "stub/l_t_n2bs.h"
static const
#include "stub/l_t_n2d.h"
static const
#include "stub/l_t_n2ds.h"
static const
#include "stub/l_t_n2e.h"
static const
#include "stub/l_t_n2es.h"
#include "stub/m68k-atari.tos.h"
// #define TESTING
//#define TESTING 1
/*************************************************************************
@@ -58,6 +49,7 @@ static const
PackTos::PackTos(InputFile *f) :
super(f)
{
bele = &N_BELE_RTP::be_policy;
COMPILE_TIME_ASSERT(FH_SIZE == 28);
}
@@ -75,30 +67,180 @@ const int *PackTos::getFilters() const
}
const upx_byte *PackTos::getLoader() const
Linker* PackTos::newLinker() const
{
if (M_IS_NRV2B(ph.method))
return opt->small ? nrv2b_loader_small : nrv2b_loader;
if (M_IS_NRV2D(ph.method))
return opt->small ? nrv2d_loader_small : nrv2d_loader;
if (M_IS_NRV2E(ph.method))
return opt->small ? nrv2e_loader_small : nrv2e_loader;
return NULL;
return new ElfLinkerM68k;
}
int PackTos::getLoaderSize() const
void PackTos::LinkerSymbols::LoopInfo::init(unsigned count_, bool allow_dbra)
{
if (M_IS_NRV2B(ph.method))
return opt->small ? sizeof(nrv2b_loader_small) : sizeof(nrv2b_loader);
if (M_IS_NRV2D(ph.method))
return opt->small ? sizeof(nrv2d_loader_small) : sizeof(nrv2d_loader);
if (M_IS_NRV2E(ph.method))
return opt->small ? sizeof(nrv2e_loader_small) : sizeof(nrv2e_loader);
count = value = count_;
if (count == 0)
mode = LOOP_NONE;
else if (count <= 65536 && allow_dbra)
{
mode = LOOP_DBRA;
value -= 1;
value &= 0xffff;
}
else if (count <= 65536)
{
mode = LOOP_SUBQ_W;
value &= 0xffff;
}
else
mode = LOOP_SUBQ_L;
}
unsigned PackTos::getDecomprOffset(int method, int small) const
{
UNUSED(small);
if (M_IS_NRV2B(method))
return 2; // FIXME: do not hardcode this value
else if (M_IS_NRV2D(method))
return 2; // FIXME: do not hardcode this value
else if (M_IS_NRV2E(method))
return 2; // FIXME: do not hardcode this value
else if (M_IS_LZMA(method))
return linker->getSectionSize("__mulsi3");
else
throwBadLoader();
return 0;
}
void PackTos::buildLoader(const Filter *ft)
{
assert(ft->id == 0);
initLoader(stub_m68k_atari_tos, sizeof(stub_m68k_atari_tos));
//linker->dumpSymbols();
//
// part 1a
//
addLoader("entry");
if (symbols.up21_a6 <= 32767)
addLoader("set_up21_a6.w");
else if (symbols.up21_d4 <= 32767)
addLoader("set_up21_d4.w");
else
addLoader("set_up21_d4.l");
assert(symbols.loop1.count || symbols.loop2.count);
if (symbols.loop1.count)
{
if (symbols.loop1.value <= 127)
addLoader("loop1_set_count.b");
else if (symbols.loop1.value <= 65535)
addLoader("loop1_set_count.w");
else
addLoader("loop1_set_count.l");
addLoader("loop1_label");
addLoader(opt->small ? "loop1.small" : "loop1.fast");
if (symbols.loop1.mode == symbols.LOOP_SUBQ_L)
addLoader("loop1_subql");
else if (symbols.loop1.mode == symbols.LOOP_SUBQ_W)
addLoader("loop1_subqw");
else if (symbols.loop1.mode == symbols.LOOP_DBRA)
addLoader("loop1_dbra");
else
throwBadLoader();
}
if (symbols.loop2.count)
{
assert(symbols.loop2.mode == symbols.LOOP_DBRA);
addLoader(opt->small ? "loop2.small" : "loop2.fast");
}
addLoader("copy_to_stack");
if (M_IS_NRV2B(ph.method))
addLoader("nrv2b.init");
else if (M_IS_NRV2D(ph.method))
addLoader("nrv2d.init");
else if (M_IS_NRV2E(ph.method))
addLoader("nrv2e.init");
else if (M_IS_LZMA(ph.method))
addLoader("lzma.init");
else
throwBadLoader();
symbols.up31_d4 = symbols.up31_base_d4 + getDecomprOffset(ph.method, opt->small);
symbols.up31_a6 = symbols.up31_base_a6 + getDecomprOffset(ph.method, opt->small);
if (symbols.up31_a6 <= 32767)
addLoader("jmp_decompressor_a6.w");
else if (symbols.up31_d4 <= 32767)
addLoader("jmp_decompressor_d4.w");
else if (symbols.up31_a6 <= 65534)
addLoader("jmp_decompressor_a6.w2");
else
addLoader("jmp_decompressor_d4.l");
//
// part 1b
//
addLoader("code_on_stack");
addLoader("clear_dirty_bss");
addLoader("loop3_label");
addLoader(opt->small ? "loop3.small" : "loop3.fast");
if (symbols.loop3.mode == symbols.LOOP_SUBQ_L)
addLoader("loop3_subql");
else if (symbols.loop3.mode == symbols.LOOP_SUBQ_W)
addLoader("loop3_subqw");
else if (symbols.loop3.mode == symbols.LOOP_DBRA)
addLoader("loop3_dbra");
else
throwBadLoader();
addLoader("flush_cache");
addLoader("restore_stack");
#if 0
addLoader("clear_dirty_stack");
#endif
addLoader("start_program");
addLoader("IDENTSTR,+40D,UPX1HEAD,CUTPOINT");
//
// part 2
//
if (M_IS_NRV2B(ph.method)) {
addLoader(opt->small ? "nrv2b_8.small" : "nrv2b_8.fast");
} else if (M_IS_NRV2D(ph.method)) {
addLoader(opt->small ? "nrv2d_8.small" : "nrv2d_8.fast");
} else if (M_IS_NRV2E(ph.method)) {
addLoader(opt->small ? "nrv2e_8.small" : "nrv2e_8.fast");
} else if (M_IS_LZMA(ph.method)) {
addLoader("__mulsi3");
addLoader(opt->small ? "lzma.small" : "lzma.fast");
addLoader("lzma.finish");
}
else
throwBadLoader();
if (symbols.need_reloc)
addLoader("reloc");
assert(symbols.loop3.count);
if (symbols.loop3.value <= 127)
addLoader("loop3_set_count.b");
else if (symbols.loop3.value <= 65535)
addLoader("loop3_set_count.w");
else
addLoader("loop3_set_count.l");
addLoader("jmp_stack");
}
/*************************************************************************
//
**************************************************************************/
@@ -165,142 +307,25 @@ bool PackTos::checkFileHeader()
if ((f & F_PROTMODE) != F_PROT_P)
{
if (opt->force < 1)
throwCantPack("no private memory protection; use option `-f' to force packing");
throwCantPack("no private memory protection; use option '-f' to force packing");
}
if (f & F_SHTEXT)
{
if (opt->force < 1)
throwCantPack("shared text segment; use option `-f' to force packing");
throwCantPack("shared text segment; use option '-f' to force packing");
}
#if 0
// fh_reserved seems to be unused
if (ih.fh_reserved != 0)
{
if (opt->force < 1)
throwCantPack("reserved header field set; use option `-f' to force packing");
throwCantPack("reserved header field set; use option '-f' to force packing");
}
#endif
return true;
}
/*************************************************************************
// some 68000 opcodes for patching
**************************************************************************/
enum m68k_reg_t {
REG_D0, REG_D1, REG_D2, REG_D3, REG_D4, REG_D5, REG_D6, REG_D7,
REG_A0, REG_A1, REG_A2, REG_A3, REG_A4, REG_A5, REG_A6, REG_A7
};
static unsigned OP_DBRA(int d_reg)
{
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
return 0x51c8 | (d_reg & 7);
}
static unsigned OP_JMP(int a_reg)
{
// jmp (a0)
assert(a_reg >= REG_A0 && a_reg <= REG_A7);
return 0x4ed0 | (a_reg & 7);
}
static unsigned OP_MOVEI_L(int d_reg)
{
// movei.l #XXXXXXXX,d0
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
return 0x203c | ((d_reg & 7) << 9);
}
static unsigned OP_MOVEQ(int value, int d_reg)
{
// moveq.l #0,d0
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
assert(value >= -128 && value <= 127);
return 0x7000 | ((d_reg & 7) << 9) | (value & 0xff);
}
static unsigned OP_SUBQ_L(int value, int d_reg)
{
// subq.l #X,d0
assert(value >= 1 && value <= 8);
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
return 0x5180 | ((value & 7) << 9) | (d_reg & 7);
}
static unsigned OP_SUBQ_W(int value, int d_reg)
{
// subq.w #X,d0
assert(value >= 1 && value <= 8);
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
return 0x5140 | ((value & 7) << 9) | (d_reg & 7);
}
/*************************************************************************
//
**************************************************************************/
unsigned PackTos::patch_d_subq(void *b, int blen,
int d_reg, unsigned d_value,
const char *subq_marker)
{
// patch a "subq.l #1,d0" or "subq.w #1,d0".
// also convert into "dbra" if possible
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
assert((int)d_value > 0);
int boff = find_be16(b, blen, get_be16(subq_marker));
if (boff < 0)
throwBadLoader();
upx_byte *p = (upx_byte *)b + boff;
if (p[2] == 0x66) // bne.b XXX
checkPatch(b, blen, boff, 4);
else
checkPatch(b, blen, boff, 2);
if (d_value > 65536)
{
set_be16(p, OP_SUBQ_L(1, d_reg)); // subq.l #1,d0
}
else
{
if (p[2] == 0x66) // bne.b XXX
{
set_be16(p, OP_DBRA(d_reg)); // dbra d0,XXX
// adjust and extend branch from 8 to 16 bits
int branch = (signed char) p[3];
set_be16(p+2, branch+2);
// adjust d0
d_value -= 1;
}
else
{
set_be16(p, OP_SUBQ_W(1, d_reg)); // subq.w #1,d0
}
d_value &= 0xffff;
}
return d_value;
}
unsigned PackTos::patch_d_loop(void *b, int blen,
int d_reg, unsigned d_value,
const char *d_marker, const char *subq_marker)
{
d_value = patch_d_subq(b, blen, d_reg, d_value, subq_marker);
int boff = find_be32(b, blen, get_be32(d_marker));
checkPatch(b, blen, boff, 4);
upx_byte *p = (upx_byte *)b + boff;
assert(get_be16(p - 2) == OP_MOVEI_L(d_reg)); // move.l #XXXXXXXX,d0
set_be32(p, d_value);
return d_value;
}
/*************************************************************************
// relocs
**************************************************************************/
@@ -354,18 +379,6 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
bool PackTos::canPack()
{
#if 0 // debug
# define p(x) printf("%-30s 0x%04x\n", #x, x)
p(OP_DBRA(REG_D0));
p(OP_MOVEI_L(REG_D0));
p(OP_MOVEQ(-1, REG_D0));
p(OP_MOVEQ(1, REG_D2));
p(OP_MOVEQ(1, REG_D3));
p(OP_SUBQ_W(1, REG_D0));
p(OP_SUBQ_L(1, REG_D0));
# undef p
#endif
if (!readFileHeader())
return false;
@@ -386,10 +399,8 @@ void PackTos::fileInfo()
{
if (!readFileHeader())
return;
#if !defined(WITH_GUI)
con_fprintf(stdout, " text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
(int)ih.fh_text, (int)ih.fh_data, (int)ih.fh_sym, (int)ih.fh_bss, (int)ih.fh_flag);
#endif /* !defined(WITH_GUI) */
}
@@ -409,6 +420,17 @@ void PackTos::pack(OutputFile *fo)
const unsigned i_sym = ih.fh_sym;
const unsigned i_bss = ih.fh_bss;
symbols.reset();
symbols.need_reloc = false;
// prepare symbols for buildLoader() - worst case
symbols.loop1.init(65536 + 1);
symbols.loop2.init((160 - 1) / 4);
symbols.loop3.init(65536 + 1);
symbols.up21_d4 = 65536 + 1;
symbols.up21_a6 = 65536 + 1;
symbols.up31_base_d4 = 65536 + 1;
symbols.up31_base_a6 = 65536 + 1;
// read file
const unsigned isize = file_size - i_sym;
ibuf.alloc(isize);
@@ -417,6 +439,8 @@ void PackTos::pack(OutputFile *fo)
t = i_text + i_data;
fi->readx(ibuf,t);
// skip symbols
if (i_sym && opt->exact)
throwCantPackExact();
fi->seek(i_sym,SEEK_CUR);
// read relocations + overlay
overlay = file_size - (FH_SIZE + i_text + i_data + i_sym);
@@ -430,7 +454,6 @@ void PackTos::pack(OutputFile *fo)
// Check relocs (see load_and_reloc() in freemint/sys/memory.c).
// Must work around TOS bugs and lots of broken programs.
int r = 0;
if (overlay < 4)
{
// Bug workaround: Whatever this is, silently keep it in
@@ -446,15 +469,17 @@ void PackTos::pack(OutputFile *fo)
}
else if (ih.fh_reloc != 0)
relocsize = 0;
else
r = check_relocs(ibuf+t, overlay, t, &nrelocs, &relocsize, &overlay);
else {
int r = check_relocs(ibuf+t, overlay, t, &nrelocs, &relocsize, &overlay);
if (r != 0)
throwCantPack("bad relocation table");
symbols.need_reloc = true;
}
#if 0 || defined(TESTING)
printf("xx2: %d relocs: %d, overlay: %d, t: %d\n", nrelocs, relocsize, overlay, t);
#endif
if (r != 0)
throwCantPack("bad relocation table");
checkOverlay(overlay);
// Append original fileheader.
@@ -472,114 +497,173 @@ void PackTos::pack(OutputFile *fo)
// After compression this will become the first part of the
// data segement. The second part will be the decompressor.
// alloc buffer (2048 is for decompressor and the various alignments)
obuf.allocForCompression(t, 2048);
// alloc buffer (4096 is for decompressor and the various alignments)
obuf.allocForCompression(t, 4096);
// prepare packheader
ph.u_len = t;
// prepare filter
Filter ft(ph.level);
// compress (max_match = 65535)
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
upx_compress_config_t cconf; cconf.reset();
cconf.conf_ucl.max_match = 65535;
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
compressWithFilters(&ft, 512, &cconf);
// get loader
const unsigned lsize = getLoaderSize();
const unsigned e_len = get_be16(getLoader()+lsize-6);
const unsigned d_len = get_be16(getLoader()+lsize-4);
const unsigned decomp_offset = get_be16(getLoader()+lsize-2);
assert(e_len + d_len == lsize - 6);
assert((e_len & 3) == 0 && (d_len & 1) == 0);
//
// multipass buildLoader()
//
// The decompressed data will now get placed at this offset:
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
// save initial loader
const unsigned initial_lsize = getLoaderSize();
unsigned last_lsize = initial_lsize;
MemBuffer last_loader(last_lsize);
memcpy(last_loader, getLoader(), last_lsize);
// compute addresses
unsigned o_text, o_data, o_bss;
o_text = e_len;
o_data = ph.c_len;
o_bss = i_bss;
// word align len of compressed data
while (o_data & 1)
unsigned e_len, d_len, d_off;
for (;;)
{
obuf[o_data++] = 0;
offset++;
}
// The decompressed data will now get placed at this offset:
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
// append decompressor (part 2 of loader)
const unsigned d_off = o_data;
memcpy(obuf+d_off, getLoader()+e_len, d_len);
o_data += d_len;
// get loader
const unsigned lsize = getLoaderSize();
e_len = getLoaderSectionStart("CUTPOINT");
d_len = lsize - e_len;
assert((e_len & 3) == 0 && (d_len & 1) == 0);
// dword align the len of the final data segment
while (o_data & 3)
{
obuf[o_data++] = 0;
offset++;
}
// dword align offset
while (offset & 3)
offset++;
// compute section sizes
o_text = e_len;
o_data = ph.c_len;
o_bss = i_bss;
// new bss
if (i_text + i_data + i_bss > o_text + o_data + o_bss)
o_bss = (i_text + i_data + i_bss) - (o_text + o_data);
// dirty bss
unsigned dirty_bss = (o_data + offset) - (i_text + i_data);
//printf("real dirty_bss: %d\n", dirty_bss);
// dword align (or 16 - for speedup when clearing the dirty bss)
const unsigned dirty_bss_align = opt->small ? 4 : 16;
while (dirty_bss & (dirty_bss_align - 1))
dirty_bss++;
// adjust bss, assert room for some stack
if (dirty_bss + 512 > o_bss)
o_bss = dirty_bss + 512;
// dword align the len of the final bss segment
while (o_bss & 3)
o_bss++;
// prepare loader
MemBuffer loader(o_text);
memcpy(loader, getLoader(), o_text);
// patch loader
int tmp = patchPackHeader(loader, o_text);
assert(tmp + 32 == (int)o_text); UNUSED(tmp);
patchVersionYear(loader, o_text);
if (!opt->small)
patchVersion(loader, o_text);
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
const unsigned dirty_bss_d6 =
patch_d_subq(loader, o_text, REG_D6, dirty_bss / dirty_bss_align, "u4");
patch_be32(loader, o_text, "up31", d_off + offset + decomp_offset);
if (opt->small)
patch_d_loop(loader, o_text, REG_D0, o_data/4, "up22", "u1");
else
{
if (o_data <= 160)
throwNotCompressible();
unsigned loop1 = o_data / 160;
unsigned loop2 = o_data % 160;
if (loop2 == 0)
// word align len of compressed data
while (o_data & 1)
{
loop1--;
loop2 = 160;
obuf[o_data++] = 0;
offset++;
}
patch_be16(loader, o_text, "u2", OP_MOVEQ(loop2/4-1, REG_D0)); // moveq.l #X,d0
patch_d_loop(loader, o_text, REG_D0, loop1, "up22", "u1");
}
patch_be32(loader,o_text,"up21",o_data + offset);
patch_be32(loader,o_text,"up13",i_bss); // p_blen
patch_be32(loader,o_text,"up12",i_data); // p_dlen
patch_be32(loader,o_text,"up11",i_text); // p_tlen
// patch decompressor
upx_byte *p = obuf + d_off;
// patch "moveq.l #1,d5" or "jmp (ASTACK)"
patch_be16(p, d_len, "u3", (nrelocs > 0) ? OP_MOVEQ(1, REG_D5) : OP_JMP(REG_A7));
patch_be32(p, d_len, "up41", dirty_bss_d6);
// append decompressor (part 2 of loader)
d_off = o_data;
////memcpy(obuf + d_off, getLoader() + e_len, d_len); // must be done after relocation
o_data += d_len;
// dword align the len of the final data segment
while (o_data & 3)
{
obuf[o_data++] = 0;
offset++;
}
// dword align offset
while (offset & 3)
offset++;
// new bss
if (i_text + i_data + i_bss > o_text + o_data + o_bss)
o_bss = (i_text + i_data + i_bss) - (o_text + o_data);
// dirty bss
unsigned dirty_bss = (o_data + offset) - (i_text + i_data);
//printf("real dirty_bss: %d\n", dirty_bss);
// dword align (or 16 - for speedup when clearing the dirty bss)
const unsigned dirty_bss_align = opt->small ? 4 : 16;
while (dirty_bss & (dirty_bss_align - 1))
dirty_bss++;
// adjust bss, assert room for some stack
unsigned stack = 512 + getDecompressorWrkmemSize();
if (dirty_bss + stack > o_bss)
o_bss = dirty_bss + stack;
// dword align the len of the final bss segment
while (o_bss & 3)
o_bss++;
// update symbols for buildLoader()
if (opt->small)
{
symbols.loop1.init(o_data / 4);
symbols.loop2.init(0);
}
else
{
symbols.loop1.init(o_data / 160);
symbols.loop2.init((o_data % 160) / 4);
}
symbols.loop3.init(dirty_bss / dirty_bss_align);
symbols.up21_d4 = o_data + offset;
symbols.up31_base_d4 = d_off + offset;
symbols.up21_a6 = symbols.up21_d4 - (i_text + i_data);
symbols.up31_base_a6 = symbols.up31_base_d4 - (i_text + i_data);
assert((int)symbols.up21_a6 > 0);
assert((int)symbols.up31_base_a6 > 0);
const unsigned c = linker->getSymbolOffset("code_on_stack");
unsigned d;
d = linker->getSymbolOffset("flush_cache_rts") - c;
symbols.flush_cache_rts_offset = d;
d = linker->getSymbolOffset("clear_dirty_stack_loop") - c;
symbols.clear_dirty_stack_len = (d + 3) / 4 + 32 - 1;
d = linker->getSymbolOffset("code_on_stack_end") - c;
symbols.copy_to_stack_len = d / 2 - 1;
// now re-build loader
buildLoader(&ft);
unsigned new_lsize = getLoaderSize();
//printf("buildLoader %d %d\n", new_lsize, initial_lsize);
assert(new_lsize <= initial_lsize);
if (new_lsize == last_lsize && memcmp(getLoader(), last_loader, last_lsize) == 0)
break;
last_lsize = new_lsize;
memcpy(last_loader, getLoader(), last_lsize);
}
//
// define symbols and reloc
//
defineDecompressorSymbols();
linker->defineSymbol("loop1_count", symbols.loop1.value);
linker->defineSymbol("loop2_count", symbols.loop2.value);
linker->defineSymbol("loop3_count", symbols.loop3.value);
linker->defineSymbol("orig_p_tlen", i_text);
linker->defineSymbol("orig_p_dlen", i_data);
linker->defineSymbol("orig_p_blen", i_bss);
if (symbols.up21_a6 <= 32767)
linker->defineSymbol("up21_a6", symbols.up21_a6);
else
linker->defineSymbol("up21_d4", symbols.up21_d4);
if (symbols.up31_a6 <= 32767)
linker->defineSymbol("up31_a6", symbols.up31_a6);
else if (symbols.up31_d4 <= 32767)
linker->defineSymbol("up31_d4", symbols.up31_d4);
else if (symbols.up31_a6 <= 65534)
linker->defineSymbol("up31_a6", symbols.up31_a6 - 32767);
else
linker->defineSymbol("up31_d4", symbols.up31_d4);
#if 0
printf("relocsize = %d\n", relocsize);
printf("upx21(d4) = %d\n", symbols.up21_d4);
printf("upx21(a6) = %d\n", symbols.up21_a6);
printf("upx31(d4) = %d\n", symbols.up31_d4);
printf("upx31(a6) = %d\n", symbols.up31_a6);
#endif
linker->defineSymbol("flush_cache_rts_offset", symbols.flush_cache_rts_offset);
linker->defineSymbol("copy_to_stack_len", symbols.copy_to_stack_len);
linker->defineSymbol("clear_dirty_stack_len", symbols.clear_dirty_stack_len);
relocateLoader();
//
// write
//
// set new file_hdr
memcpy(&oh, &ih, FH_SIZE);
@@ -605,17 +689,26 @@ void PackTos::pack(OutputFile *fo)
#if 0 || defined(TESTING)
printf("old text: %6d, data: %6d, bss: %6d, reloc: %d, overlay: %d\n",
i_text, i_data, i_bss, relocsize, overlay);
printf("new text: %6d, data: %6d, bss: %6d, dirty_bss: %d, flag=0x%x\n",
o_text, o_data, o_bss, dirty_bss, (int)oh.fh_flag);
printf("new text: %6d, data: %6d, bss: %6d, flag=0x%x\n",
o_text, o_data, o_bss, (int)oh.fh_flag);
linker->dumpSymbols();
#endif
// prepare loader
MemBuffer loader(o_text);
memcpy(loader, getLoader(), o_text);
patchPackHeader(loader, o_text);
// write new file header, loader and compressed file
fo->write(&oh, FH_SIZE);
fo->write(loader, o_text); // entry
if (opt->debug.dump_stub_loader)
OutputFile::dump(opt->debug.dump_stub_loader, loader, o_text);
memcpy(obuf + d_off, getLoader() + e_len, d_len); // copy decompressor
fo->write(obuf, o_data); // compressed + decompressor
// write empty relocation fixup
fo->write("\x00\x00\x00\x00",4);
fo->write("\x00\x00\x00\x00", 4);
// verify
verifyOverlappingDecompression();
+34 -7
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -42,6 +42,7 @@ public:
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_ATARI_TOS; }
virtual const char *getName() const { return "atari/tos"; }
virtual const char *getFullName(const options_t *) const { return "m68k-atari.tos"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
@@ -54,8 +55,9 @@ public:
virtual void fileInfo();
protected:
virtual const upx_byte *getLoader() const;
virtual int getLoaderSize() const;
virtual Linker* newLinker() const;
virtual void buildLoader(const Filter *ft);
unsigned getDecomprOffset(int method, int small) const;
virtual int readFileHeader();
virtual bool checkFileHeader();
@@ -75,9 +77,34 @@ protected:
tos_header_t ih, oh;
protected:
unsigned patch_d_subq(void *l, int llen, int, unsigned, const char*);
unsigned patch_d_loop(void *l, int llen, int, unsigned, const char*, const char*);
// symbols for buildLoader()
struct LinkerSymbols
{
enum { LOOP_NONE, LOOP_SUBQ_L, LOOP_SUBQ_W, LOOP_DBRA };
struct LoopInfo {
unsigned mode; unsigned count; unsigned value;
void init(unsigned count, bool allow_dbra=true);
};
// buildLoader() input
bool need_reloc;
LoopInfo loop1;
LoopInfo loop2;
LoopInfo loop3;
unsigned up21_d4;
unsigned up21_a6;
unsigned up31_base_d4;
unsigned up31_base_a6;
// buildLoader() output
unsigned up31_d4;
unsigned up31_a6;
// currently not used by buildLoader()
unsigned flush_cache_rts_offset;
unsigned clear_dirty_stack_len;
unsigned copy_to_stack_len;
void reset() { memset(this, 0, sizeof(*this)); }
};
LinkerSymbols symbols;
};
+37 -39
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
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.
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -62,7 +62,7 @@ bool PackUnix::canPack()
#if defined(__unix__)
// must be executable by owner
if ((fi->st.st_mode & S_IXUSR) == 0)
throwCantPack("file not executable; try `chmod +x'");
throwCantPack("file not executable; try 'chmod +x'");
#endif
if (file_size < 4096)
throwCantPack("file is too small");
@@ -125,8 +125,8 @@ int PackUnix::getStrategy(Filter &/*ft*/)
// Called just before reading and compressing each block.
// Might want to adjust blocksize, etc.
// If user specified the filter, then use it (-2==strategy).
// Else try the first two filters, and pick the better (2==strategy).
// 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));
}
@@ -151,9 +151,9 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
// which assumes it has free choice on each call [block].
// And if the choices aren't the same on each block,
// then un-filtering will give incorrect results.
int strategy = getStrategy(ft);
int filter_strategy = getStrategy(ft);
if (file_size > (off_t)blocksize)
strategy = -3; // no filters
filter_strategy = -3; // no filters
int l = fi->readx(ibuf, UPX_MIN(blocksize, remaining));
remaining -= l;
@@ -170,7 +170,7 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
// that is, AFTER filtering. We want BEFORE filtering,
// so that decompression checks the end-to-end checksum.
unsigned const end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler);
compressWithFilters(&ft, OVERHEAD, strategy);
compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy);
if (ph.c_len < ph.u_len) {
ph.overlap_overhead = OVERHEAD;
@@ -225,7 +225,7 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
void
PackUnix::patchLoaderChecksum()
{
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
unsigned char *const ptr = getLoader();
l_info *const lp = &linfo;
// checksum for loader; also some PackHeader info
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
@@ -236,11 +236,10 @@ PackUnix::patchLoaderChecksum()
lp->l_checksum = upx_adler32(ptr, lsize);
}
void PackUnix::pack3(OutputFile *fo, Filter &ft)
void PackUnix::pack3(OutputFile *fo, Filter &/*ft*/)
{
upx_byte const *p = getLoader();
upx_byte *p = getLoader();
lsize = getLoaderSize();
patchFilter32(const_cast<upx_byte *>(p), lsize, &ft);
updateLoader(fo);
patchLoaderChecksum();
fo->write(p, lsize);
@@ -305,21 +304,21 @@ void PackUnix::packExtent(
unsigned &total_out,
Filter *ft,
OutputFile *fo,
unsigned hdr_ulen
unsigned hdr_u_len
)
{
unsigned const init_u_adler = ph.u_adler;
unsigned const init_c_adler = ph.c_adler;
MemBuffer hdr_ibuf;
if (hdr_ulen) {
hdr_ibuf.alloc(hdr_ulen);
if (hdr_u_len) {
hdr_ibuf.alloc(hdr_u_len);
fi->seek(0, SEEK_SET);
int l = fi->readx(hdr_ibuf, hdr_ulen);
int l = fi->readx(hdr_ibuf, hdr_u_len);
(void)l;
}
fi->seek(x.offset, SEEK_SET);
for (off_t rest = x.size; 0 != rest; ) {
int const strategy = getStrategy(*ft);
int const filter_strategy = getStrategy(*ft);
int l = fi->readx(ibuf, UPX_MIN(rest, (off_t)blocksize));
if (l == 0) {
break;
@@ -346,12 +345,11 @@ void PackUnix::packExtent(
ft->id = 0;
ft->cto = 0;
compressWithFilters(ft, OVERHEAD, strategy,
NULL, 0, 0, 0, 0, // those 5 args are the defaults
hdr_ibuf, hdr_ulen);
compressWithFilters(ft, OVERHEAD, NULL_cconf, filter_strategy,
0, 0, 0, hdr_ibuf, hdr_u_len);
}
else {
(void) compress(ibuf, obuf); // ignore return value
(void) compress(ibuf, ph.u_len, obuf); // ignore return value
}
if (ph.c_len < ph.u_len) {
@@ -371,31 +369,31 @@ void PackUnix::packExtent(
// write block sizes
b_info tmp;
if (hdr_ulen) {
unsigned hdr_clen;
if (hdr_u_len) {
unsigned hdr_c_len = 0;
MemBuffer hdr_obuf;
unsigned result[16];
upx_compress_config_t conf;
memset(&conf, 0xff, sizeof(conf));
hdr_obuf.allocForCompression(hdr_ulen);
int r = upx_compress(hdr_ibuf, hdr_ulen, hdr_obuf, &hdr_clen, 0,
ph.method, 10, &conf, result);
(void)r;
ph.saved_u_adler = upx_adler32(hdr_ibuf, hdr_ulen, init_u_adler);
ph.saved_c_adler = upx_adler32(hdr_obuf, hdr_clen, init_c_adler);
hdr_obuf.allocForCompression(hdr_u_len);
int r = upx_compress(hdr_ibuf, hdr_u_len, hdr_obuf, &hdr_c_len, 0,
ph.method, 10, NULL, NULL);
if (r != UPX_E_OK)
throwInternalError("header compression failed");
if (hdr_c_len >= hdr_u_len)
throwInternalError("header compression size increase");
ph.saved_u_adler = upx_adler32(hdr_ibuf, hdr_u_len, init_u_adler);
ph.saved_c_adler = upx_adler32(hdr_obuf, hdr_c_len, init_c_adler);
ph.u_adler = upx_adler32(ibuf, ph.u_len, ph.saved_u_adler);
ph.c_adler = upx_adler32(obuf, ph.c_len, ph.saved_c_adler);
end_u_adler = ph.u_adler;
memset(&tmp, 0, sizeof(tmp));
set_native32(&tmp.sz_unc, hdr_ulen);
set_native32(&tmp.sz_cpr, hdr_clen);
set_native32(&tmp.sz_unc, hdr_u_len);
set_native32(&tmp.sz_cpr, hdr_c_len);
tmp.b_method = (unsigned char) ph.method;
fo->write(&tmp, sizeof(tmp));
b_len += sizeof(b_info);
fo->write(hdr_obuf, hdr_clen);
total_out += hdr_clen;
total_in += hdr_ulen;
hdr_ulen = 0; // compress hdr one time only
fo->write(hdr_obuf, hdr_c_len);
total_out += hdr_c_len;
total_in += hdr_u_len;
hdr_u_len = 0; // compress hdr one time only
}
memset(&tmp, 0, sizeof(tmp));
set_native32(&tmp.sz_unc, ph.u_len);
+7 -7
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2007 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -111,9 +111,9 @@ protected:
}
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader
unsigned l_checksum;
unsigned l_magic;
unsigned short l_lsize;
LE32 l_checksum;
LE32 l_magic;
LE16 l_lsize;
unsigned char l_version;
unsigned char l_format;
}
@@ -141,7 +141,7 @@ class PackUnixBe32 : public PackUnix
{
typedef PackUnix super;
protected:
PackUnixBe32(InputFile *f) : super(f) { }
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); }
@@ -182,7 +182,7 @@ class PackUnixLe32 : public PackUnix
{
typedef PackUnix super;
protected:
PackUnixLe32(InputFile *f) : super(f) { }
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); }

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