Compare commits

...

697 Commits

Author SHA1 Message Date
Markus F.X.J. Oberhumer fcc22a0aa3 Added UPX_VERSION_DATE_ISO.
committer: mfx <mfx> 1142085195 +0000
2006-03-11 13:53:15 +00:00
Markus F.X.J. Oberhumer aabefff298 Prepared for release 1.94.
committer: mfx <mfx> 1142081862 +0000
2006-03-11 12:57:42 +00:00
Markus F.X.J. Oberhumer ed25c64e97 Updated.
committer: mfx <mfx> 1142081797 +0000
2006-03-11 12:56:37 +00:00
Markus F.X.J. Oberhumer b7dc870c2d Centered strings.
committer: mfx <mfx> 1142081776 +0000
2006-03-11 12:56:16 +00:00
Markus F.X.J. Oberhumer 9bea608843 Don't suppress errors with -qq.
committer: mfx <mfx> 1142081041 +0000
2006-03-11 12:44:01 +00:00
Markus F.X.J. Oberhumer 9db1732c36 Added a note that we should upgrade to gcc-4.1.0 on i386-linux.
committer: mfx <mfx> 1142074774 +0000
2006-03-11 10:59:34 +00:00
Markus F.X.J. Oberhumer 39f1a70174 Small update.
committer: mfx <mfx> 1142036155 +0000
2006-03-11 00:15:55 +00:00
Markus F.X.J. Oberhumer 1810440355 Added __attribute__((__sentinel__)) to Packer::addLoader(). This is
a new gcc-4.1 feature.

committer: mfx <mfx> 1142035833 +0000
2006-03-11 00:10:33 +00:00
Markus F.X.J. Oberhumer 37ac8f179e New ACC version.
committer: mfx <mfx> 1142035385 +0000
2006-03-11 00:03:05 +00:00
Markus F.X.J. Oberhumer 626a09328f Updated.
committer: mfx <mfx> 1141807336 +0000
2006-03-08 08:42:16 +00:00
Markus F.X.J. Oberhumer 8d489d0d77 New ACC version.
committer: mfx <mfx> 1141798968 +0000
2006-03-08 06:22:48 +00:00
Markus F.X.J. Oberhumer 776f3db0d7 Detabified.
committer: mfx <mfx> 1141795978 +0000
2006-03-08 05:32:58 +00:00
John Reiser 6046057b88 Commentary on SELinux and UPX.
committer: jreiser <jreiser> 1141686040 +0000
2006-03-06 23:00:40 +00:00
Markus F.X.J. Oberhumer 7e85d9e549 Updated.
committer: mfx <mfx> 1141679044 +0000
2006-03-06 21:04:04 +00:00
Markus F.X.J. Oberhumer 01c8a8b1c2 Disabled an expensive run-time assertion.
committer: mfx <mfx> 1141642878 +0000
2006-03-06 11:01:18 +00:00
Markus F.X.J. Oberhumer c9bf6ac9ae No need to preserve eax in clearstack.
committer: mfx <mfx> 1141642647 +0000
2006-03-06 10:57:27 +00:00
John Reiser 62e4d69be9 re-compile from changed m_lx_elfppc32.c
committer: jreiser <jreiser> 1141605710 +0000
2006-03-06 00:41:50 +00:00
John Reiser 62ac733b09 simplify and save a few bytes
committer: jreiser <jreiser> 1141488398 +0000
2006-03-04 16:06:38 +00:00
John Reiser c3b3e1b1b9 MAP_DENYWRITE
committer: jreiser <jreiser> 1141484579 +0000
2006-03-04 15:02:59 +00:00
John Reiser a791e96e00 Fix do_xmap() to work under SElinux. Also trim unneeded code.
committer: jreiser <jreiser> 1141413353 +0000
2006-03-03 19:15:53 +00:00
John Reiser e87f5521c1 conditionally compile debugging printf
committer: jreiser <jreiser> 1141365595 +0000
2006-03-03 05:59:55 +00:00
John Reiser 366a708f3a Generalize to more than 2 PT_LOAD using find_LOAD_gap; needed for linux/ElfAMD.
Also simplifies, and applies to both ::pack and ::unpack.
	p_lx_elf.cpp p_lx_elf.h

committer: jreiser <jreiser> 1141348876 +0000
2006-03-03 01:21:16 +00:00
John Reiser 70ba662574 Avoid overwrite of obuf when hdr_buf and non-first method.
committer: jreiser <jreiser> 1141327368 +0000
2006-03-02 19:22:48 +00:00
John Reiser b389abd99f PackLinuxElf64amd::getCompressionMethods allows both nrv2b and nrv2e
committer: jreiser <jreiser> 1141326792 +0000
2006-03-02 19:13:12 +00:00
John Reiser 4aa2d14fe3 acknowledge unused results to avoid compiler warnings treated as errors
committer: jreiser <jreiser> 1141326721 +0000
2006-03-02 19:12:01 +00:00
John Reiser af7de75ad4 Allow unfilter when verifyOverlappingDecompression, for convenience
in end-to-end checksum.
	packer.h packer.cpp p_unix.cpp

committer: jreiser <jreiser> 1141252960 +0000
2006-03-01 22:42:40 +00:00
John Reiser d461ebbda1 fix packExtent checksums and lengths (of uncompressed data) for 0!=hdr_ulen
committer: jreiser <jreiser> 1141241763 +0000
2006-03-01 19:36:03 +00:00
John Reiser 55ef94abcd 8-bit decompressors for ARM; minimize space aggressively
arm_nrv2b_d8.S arm_nrv2e_d8.S

committer: jreiser <jreiser> 1140993873 +0000
2006-02-26 22:44:33 +00:00
John Reiser afaf489d99 save space aggressively
committer: jreiser <jreiser> 1140713717 +0000
2006-02-23 16:55:17 +00:00
John Reiser 20e4cbfd13 passes first tests! Only untested feature: large offset which forces
minimum match length to be >=3.
	arm_nrv2b_d32.S arm_nrv2e_d32.S

committer: jreiser <jreiser> 1140677145 +0000
2006-02-23 06:45:45 +00:00
John Reiser f3b8c9f34e debugging
committer: jreiser <jreiser> 1140634679 +0000
2006-02-22 18:57:59 +00:00
John Reiser 45e8ff25a5 hand-tuned decompressors for 32-bit NRV on ARM
arm_nrv2b_d32.S arm_nrv2e_d32.S

committer: jreiser <jreiser> 1140535945 +0000
2006-02-21 15:32:25 +00:00
John Reiser 268e322e1c Extra parameter for compressWithFilters and packExtent,
to fix 2-pass problem with --brute on linux/elf386.
Only one decompression method is allowed, chosen by
smallest output for .text; but Elf headers come first.
	packer.cpp packer.h p_unix.cpp p_unix.h p_lx_elf.cpp

committer: jreiser <jreiser> 1140241030 +0000
2006-02-18 05:37:10 +00:00
Markus F.X.J. Oberhumer d3bcba6a05 Removed "volatile" from global var "opt" - this was only needed
a long time ago to work around problems with ancient C++ compilers.

committer: mfx <mfx> 1140002094 +0000
2006-02-15 11:14:54 +00:00
Markus F.X.J. Oberhumer cc4ef1944d Make sure we only touch exactly one page. Update comments.
committer: mfx <mfx> 1139928961 +0000
2006-02-14 14:56:01 +00:00
Markus F.X.J. Oberhumer 5aa8486265 Prefer restoring the original protection flags.
committer: mfx <mfx> 1139928517 +0000
2006-02-14 14:48:37 +00:00
László Molnár fd181673cd a little more comments on the DEP hack stuff
committer: ml1050 <ml1050> 1139927444 +0000
2006-02-14 14:30:44 +00:00
László Molnár 62c9547c4e added some comments on the DEP hack stuff
committer: ml1050 <ml1050> 1139918135 +0000
2006-02-14 11:55:35 +00:00
Markus F.X.J. Oberhumer cdd117bfb9 Rearranged debug options.
committer: mfx <mfx> 1139916141 +0000
2006-02-14 11:22:21 +00:00
Markus F.X.J. Oberhumer 304ba57dad Clear the dirty stack on win32/pe.
committer: mfx <mfx> 1139914965 +0000
2006-02-14 11:02:45 +00:00
Markus F.X.J. Oberhumer 69eaaa4177 Revert previous checkin.
committer: mfx <mfx> 1139914479 +0000
2006-02-14 10:54:39 +00:00
Markus F.X.J. Oberhumer 452ac52fcb Added an overloaded addLoader() method.
committer: mfx <mfx> 1139913550 +0000
2006-02-14 10:39:10 +00:00
Markus F.X.J. Oberhumer 40cf489290 Avoid possibly clobbering edx.
committer: mfx <mfx> 1139881592 +0000
2006-02-14 01:46:32 +00:00
Markus F.X.J. Oberhumer 891d6be4a6 Removed options_t::win32_pe::strip_loadconf.
For compatibility reasons the option is still accepted (but
ignored) during commandline parsing.

committer: mfx <mfx> 1139866279 +0000
2006-02-13 21:31:19 +00:00
Markus F.X.J. Oberhumer 5d45ce5cf7 Removed an already fixed item.
committer: mfx <mfx> 1139864523 +0000
2006-02-13 21:02:03 +00:00
Markus F.X.J. Oberhumer a0f2241f3a Added comment.
committer: mfx <mfx> 1139862668 +0000
2006-02-13 20:31:08 +00:00
Markus F.X.J. Oberhumer aa513bf7d3 Quick fix for the Win32 startup crash. Needs more testing.
committer: mfx <mfx> 1139861398 +0000
2006-02-13 20:09:58 +00:00
Markus F.X.J. Oberhumer b2d65febc8 Small update.
committer: mfx <mfx> 1139843847 +0000
2006-02-13 15:17:27 +00:00
Markus F.X.J. Oberhumer 23a6d326e8 Bump tentative release date. Update READMEs.
committer: mfx <mfx> 1139840129 +0000
2006-02-13 14:15:29 +00:00
Markus F.X.J. Oberhumer 5b2f1b6d8b Introduced UPX_VERSION_YEAR.
committer: mfx <mfx> 1139826163 +0000
2006-02-13 10:22:43 +00:00
Markus F.X.J. Oberhumer b4e9ad031b Break strings so that CVS does not try to expand keywords.
committer: mfx <mfx> 1139786765 +0000
2006-02-12 23:26:05 +00:00
Markus F.X.J. Oberhumer 8b7ebcf040 Enter 2006.
committer: mfx <mfx> 1139778883 +0000
2006-02-12 21:14:43 +00:00
Markus F.X.J. Oberhumer af05296631 Made ps1/exe work again.
committer: mfx <mfx> 1139776798 +0000
2006-02-12 20:39:58 +00:00
Markus F.X.J. Oberhumer 29d693de2d New ACC version.
committer: mfx <mfx> 1139772863 +0000
2006-02-12 19:34:23 +00:00
Markus F.X.J. Oberhumer 51ac5172f5 #undef PAGE_{MASK,SIZE} to fix build problems on some machines.
committer: mfx <mfx> 1139743226 +0000
2006-02-12 11:20:26 +00:00
Markus F.X.J. Oberhumer 24ce1ef5e7 Enter 2006.
committer: mfx <mfx> 1139742400 +0000
2006-02-12 11:06:40 +00:00
Markus F.X.J. Oberhumer f6d1e269d1 Prepare for new release.
committer: mfx <mfx> 1139742224 +0000
2006-02-12 11:03:44 +00:00
Markus F.X.J. Oberhumer 62c2f5228d Rebuilt stubs.
committer: mfx <mfx> 1139742130 +0000
2006-02-12 11:02:10 +00:00
Markus F.X.J. Oberhumer 9882d9683b Updated.
committer: mfx <mfx> 1139741935 +0000
2006-02-12 10:58:55 +00:00
Markus F.X.J. Oberhumer 45ce89ee1f Removed trailing whitespace.
committer: mfx <mfx> 1139741919 +0000
2006-02-12 10:58:39 +00:00
László Molnár bfb9df1553 win32/pe: R6002 runtime errors worked around
committer: ml1050 <ml1050> 1139505685 +0000
2006-02-09 17:21:25 +00:00
László Molnár a5f79204ce set use_dep_hack to true
committer: ml1050 <ml1050> 1139404812 +0000
2006-02-08 13:20:12 +00:00
László Molnár e322613d84 workaround added for a msvc runtime "protection"
committer: ml1050 <ml1050> 1139393823 +0000
2006-02-08 10:17:03 +00:00
Markus F.X.J. Oberhumer fbb60f5191 Refactored a new mem_replace() function.
committer: mfx <mfx> 1138984802 +0000
2006-02-03 16:40:02 +00:00
Markus F.X.J. Oberhumer 899e7d2f39 Added internal debugging options '--fake-stub-version=X.XX' and
'--fake-stub-year=XXXX'.

These might prove useful for building up a test suite which is able to
check binary identity of compressed executables between UPX releases
where the implementation of a specific format has not changed.

committer: mfx <mfx> 1138960010 +0000
2006-02-03 09:46:50 +00:00
László Molnár 8e2aa07747 load config support for win32/pe dlls
committer: ml1050 <ml1050> 1138878465 +0000
2006-02-02 11:07:45 +00:00
Markus F.X.J. Oberhumer a0d262cd76 New ACC version.
committer: mfx <mfx> 1138683583 +0000
2006-01-31 04:59:43 +00:00
Markus F.X.J. Oberhumer b43a7edee4 Preliminary bump some version information.
committer: mfx <mfx> 1138080865 +0000
2006-01-24 05:34:25 +00:00
Markus F.X.J. Oberhumer 7760bbd77c New ACC version.
committer: mfx <mfx> 1138080385 +0000
2006-01-24 05:26:25 +00:00
Markus F.X.J. Oberhumer 9c0f1b02a7 Small Makefile updates.
committer: mfx <mfx> 1138080320 +0000
2006-01-24 05:25:20 +00:00
Markus F.X.J. Oberhumer 4ecfff4d8d Print a #define for the _SIZE. Enter 2006. Add John's name.
committer: mfx <mfx> 1138080110 +0000
2006-01-24 05:21:50 +00:00
László Molnár ac03b89f38 docs updates for 1.94
committer: ml1050 <ml1050> 1137999714 +0000
2006-01-23 07:01:54 +00:00
László Molnár 620174aea9 copyright text added
committer: ml1050 <ml1050> 1137999649 +0000
2006-01-23 07:00:49 +00:00
Markus F.X.J. Oberhumer ab50d28bc4 New ACC version.
committer: mfx <mfx> 1134926345 +0000
2005-12-18 17:19:05 +00:00
Markus F.X.J. Oberhumer b5318602d1 Fixed compilation problem.
committer: mfx <mfx> 1134926052 +0000
2005-12-18 17:14:12 +00:00
John Reiser bff2a63ea2 prefetching does not help length of match
l_lx_elf64amd.S amd_d_nrv2b.S amd_d_nrv2e.S

committer: jreiser <jreiser> 1132290120 +0000
2005-11-18 05:02:00 +00:00
László Molnár aacfb8820e better load_conf directory support. still needs some work.
committer: ml1050 <ml1050> 1132077577 +0000
2005-11-15 17:59:37 +00:00
John Reiser 98e8c031d0 generated header files
fold_elf64amd.h l_lx_elf64amd.h

committer: jreiser <jreiser> 1131994505 +0000
2005-11-14 18:55:05 +00:00
John Reiser beb4319d1e tune for better branch prediction by avoiding more than 3 in a 16-byte block
amd_d_nrv2b.S amd_d_nrv2e.S l_lx_elf64amd.S

committer: jreiser <jreiser> 1131994471 +0000
2005-11-14 18:54:31 +00:00
John Reiser 2558243c83 de-tabify; also speculate 1-byte loads to save a cycle or two
amd_d_nrv2b.S amd_d_nrv2e.S l_lx_elf64amd.S

committer: jreiser <jreiser> 1131943590 +0000
2005-11-14 04:46:30 +00:00
John Reiser b670e8d1ac tuning
amd_bxx.S amd_d_nrv2b.S amd_d_nrv2e.S l_lx_elf64amd.S

committer: jreiser <jreiser> 1131939243 +0000
2005-11-14 03:34:03 +00:00
John Reiser 68f8358f06 tune: avoid MOVSB for literals; inline default case of NEXTB macros
committer: jreiser <jreiser> 1131923823 +0000
2005-11-13 23:17:03 +00:00
John Reiser db5a099097 CLD and documentation
amd_d_nrv2e.S l_lx_elf64amd.S fold_elf64amd.S

committer: jreiser <jreiser> 1131854052 +0000
2005-11-13 03:54:12 +00:00
John Reiser ce33ffb62a handle compressed executables larger than 3MB on Elf64amd
committer: jreiser <jreiser> 1131833508 +0000
2005-11-12 22:11:48 +00:00
John Reiser 59a2fb9cfd recompile generated .h after source changes
fold_elf64amd.h l_lx_elf64amd.h

committer: jreiser <jreiser> 1131824699 +0000
2005-11-12 19:44:59 +00:00
John Reiser 75bba319de tuning, and prepare for large executables (>3MB compressed)
p_lx_elf.cpp stub/a_lx_elf64.c stub/amd_d_nrv2e.S
	stub/fold_elf64amd.S stub/l_lx_elf64amd.S

committer: jreiser <jreiser> 1131824655 +0000
2005-11-12 19:44:15 +00:00
John Reiser f78e9261f3 Do initLoader() properly, instead of relying on the amount of stack space
that is in use when ::buildLinuxLoader is called.

committer: jreiser <jreiser> 1131597922 +0000
2005-11-10 04:45:22 +00:00
Markus F.X.J. Oberhumer 5f77562333 Cleanup.
committer: mfx <mfx> 1131596991 +0000
2005-11-10 04:29:51 +00:00
Markus F.X.J. Oberhumer 5c4f01a68d New ACC version.
committer: mfx <mfx> 1131596966 +0000
2005-11-10 04:29:26 +00:00
Markus F.X.J. Oberhumer 35f6f998e6 Avoid warnings. Detabified.
committer: mfx <mfx> 1131593815 +0000
2005-11-10 03:36:55 +00:00
John Reiser 6737a3ae09 PackLinuxElf64amd
p_lx_elf.h p_lx_elf.cpp packmast.cpp

committer: jreiser <jreiser> 1131570778 +0000
2005-11-09 21:12:58 +00:00
John Reiser 09559bee8c Elf64
p_unix.h p_elf.h

committer: jreiser <jreiser> 1131570530 +0000
2005-11-09 21:08:50 +00:00
John Reiser f487ea27a8 UPX_F_LINUX_ELF64_AMD
committer: jreiser <jreiser> 1131568333 +0000
2005-11-09 20:32:13 +00:00
John Reiser a3d95f239a Generated .h header files for AMD x86_64
fold_elf64amd.h l_lx_elf64amd.h

committer: jreiser <jreiser> 1131566912 +0000
2005-11-09 20:08:32 +00:00
John Reiser 023c06e178 Support for 64-bit AMD x86_64
Makefile
Added Files:
	a_lx_elf64.c amd_bxx.S amd_d_nrv2e.S amd_regs.h
	fold_elf64amd.S l_lx_elf64amd.S l_lx_elf64amd.lds

committer: jreiser <jreiser> 1131566835 +0000
2005-11-09 20:07:15 +00:00
John Reiser 414a6c1c9e Enhance to handle both Elf32 and Elf64, and little/big endian.
http://buildroot.uclibc.org/cgi-bin/viewcvs.cgi/trunk/buildroot/toolchain/sstrip/sstrip.c
Revision 11028 [Added Tue Aug 2 18:20:34 2005 PDT (3 months, 1 week ago) by mjn3]

committer: jreiser <jreiser> 1131566192 +0000
2005-11-09 19:56:32 +00:00
John Reiser 910e18fb22 b_method 5th argument to f_decompress
l_lx_exec.c l_lx_pti.c l_lx_sep.c l_lx_sh.c

committer: jreiser <jreiser> 1131565060 +0000
2005-11-09 19:37:40 +00:00
John Reiser ac441fd1cf definitions for Elf64_*
committer: jreiser <jreiser> 1131564732 +0000
2005-11-09 19:32:12 +00:00
John Reiser 0c328372b5 Allow __uClibc_main and __uClibc_start_main like __libc_start_main.
committer: jreiser <jreiser> 1127269046 +0000
2005-09-21 02:17:26 +00:00
Markus F.X.J. Oberhumer 55ef60a6d4 Rebuilt with gcc-3.4.4.
committer: mfx <mfx> 1127188101 +0000
2005-09-20 03:48:21 +00:00
Markus F.X.J. Oberhumer c33584e683 Detabified.
committer: mfx <mfx> 1126929315 +0000
2005-09-17 03:55:15 +00:00
Markus F.X.J. Oberhumer ee8c7453bd Small updates.
committer: mfx <mfx> 1126927283 +0000
2005-09-17 03:21:23 +00:00
John Reiser 0330369603 remove debugging strut
l_lx_elf86.asm l_lx_elf86.h

committer: jreiser <jreiser> 1126892616 +0000
2005-09-16 17:43:36 +00:00
John Reiser 3f7b642c7d Linux i386 allow compression of position-independent main executables (gcc -pie).
p_elf.h p_lx_elf.cpp p_lx_elf.h p_lx_exc.cpp
	stub/fold_elf86.asm stub/fold_elf86.h stub/l_lx_elf.c
	stub/l_lx_elf86.asm stub/l_lx_elf86.h stub/l_lx_elf86.lds
	stub/linux.hh

committer: jreiser <jreiser> 1126886896 +0000
2005-09-16 16:08:16 +00:00
László Molnár eb6c51426a fixed a nasty relocation handling error which could produce broken
compressed files

committer: ml1050 <ml1050> 1126865811 +0000
2005-09-16 10:16:51 +00:00
Markus F.X.J. Oberhumer 0337bdb9fd Added support for UCL_USE_ASM.
committer: mfx <mfx> 1126844111 +0000
2005-09-16 04:15:11 +00:00
Markus F.X.J. Oberhumer 7aedc62058 Removed some old and dead code.
committer: mfx <mfx> 1126744217 +0000
2005-09-15 00:30:17 +00:00
Markus F.X.J. Oberhumer bfc835cbbf Added some more tests to upx_sanity_check(). Disable these for production
builds - code bloat.

committer: mfx <mfx> 1126743964 +0000
2005-09-15 00:26:04 +00:00
Markus F.X.J. Oberhumer 5c6ba30c48 New ACC version.
committer: mfx <mfx> 1126741199 +0000
2005-09-14 23:39:59 +00:00
Markus F.X.J. Oberhumer 8fe4824ed2 Fix typo.
committer: mfx <mfx> 1126295791 +0000
2005-09-09 19:56:31 +00:00
Markus F.X.J. Oberhumer d40cb3bd55 Cosmetic cleanups.
committer: mfx <mfx> 1126295335 +0000
2005-09-09 19:48:55 +00:00
Markus F.X.J. Oberhumer 4bcd3ac5d7 Mention arm/pe.
committer: mfx <mfx> 1126294945 +0000
2005-09-09 19:42:25 +00:00
Markus F.X.J. Oberhumer e2b8e9dea9 Avoid some warnings about unused args.
committer: mfx <mfx> 1126294727 +0000
2005-09-09 19:38:47 +00:00
László Molnár 572314bf3f support for arm/WinCE ("arm/pe") exes
committer: ml1050 <ml1050> 1126255781 +0000
2005-09-09 08:49:41 +00:00
Markus F.X.J. Oberhumer 14d303d331 Small updates according to latest glibc headers.
committer: mfx <mfx> 1126184484 +0000
2005-09-08 13:01:24 +00:00
Markus F.X.J. Oberhumer 24ffaa0738 Added BE64 and LE64 types.
committer: mfx <mfx> 1126183138 +0000
2005-09-08 12:38:58 +00:00
Markus F.X.J. Oberhumer 5d9b6d056d Small updates.
committer: mfx <mfx> 1126029328 +0000
2005-09-06 17:55:28 +00:00
Markus F.X.J. Oberhumer 5c28ff15ba Changes for new ACC version.
committer: mfx <mfx> 1126029282 +0000
2005-09-06 17:54:42 +00:00
Markus F.X.J. Oberhumer 06ceb2f2a1 New ACC version.
committer: mfx <mfx> 1126029264 +0000
2005-09-06 17:54:24 +00:00
Markus F.X.J. Oberhumer 7373e1dd8b Updated.
committer: mfx <mfx> 1122416155 +0000
2005-07-26 22:15:55 +00:00
Markus F.X.J. Oberhumer 4b1a9e714d New ACC version.
committer: mfx <mfx> 1122416002 +0000
2005-07-26 22:13:22 +00:00
Markus F.X.J. Oberhumer 9d76136358 Use gcc-3.4.4 for Linux stubs.
committer: mfx <mfx> 1122415958 +0000
2005-07-26 22:12:38 +00:00
Markus F.X.J. Oberhumer b3502420ad Removed patches/patch-elfcode.h and the patches/ directory - these
fixes now are already in upstream binutils for quite some time.

committer: mfx <mfx> 1119797919 +0000
2005-06-26 14:58:39 +00:00
Markus F.X.J. Oberhumer dd7ac7cca9 Updated.
committer: mfx <mfx> 1119614331 +0000
2005-06-24 11:58:51 +00:00
Markus F.X.J. Oberhumer 31dfa18e9b Updated.
committer: mfx <mfx> 1119613913 +0000
2005-06-24 11:51:53 +00:00
Markus F.X.J. Oberhumer 3e785008d3 Avoid warnings.
committer: mfx <mfx> 1119613856 +0000
2005-06-24 11:50:56 +00:00
Markus F.X.J. Oberhumer 6b7c7f755c Avoid warnings about unused vars.
committer: mfx <mfx> 1119613814 +0000
2005-06-24 11:50:14 +00:00
Markus F.X.J. Oberhumer c55a8a8703 Added some more sanity checks.
committer: mfx <mfx> 1119613748 +0000
2005-06-24 11:49:08 +00:00
Markus F.X.J. Oberhumer 64c97308ac Portability fix for gcc -ftrapv option.
committer: mfx <mfx> 1119613504 +0000
2005-06-24 11:45:04 +00:00
Markus F.X.J. Oberhumer 3551b0b95a Updated.
committer: mfx <mfx> 1119613441 +0000
2005-06-24 11:44:01 +00:00
Markus F.X.J. Oberhumer 9f16b5c4af Recompiled stubs.
committer: mfx <mfx> 1119613249 +0000
2005-06-24 11:40:49 +00:00
Markus F.X.J. Oberhumer 9777e549cb New upstream version.
committer: mfx <mfx> 1119613222 +0000
2005-06-24 11:40:22 +00:00
Markus F.X.J. Oberhumer fbfced1b93 New ACC version.
committer: mfx <mfx> 1119613192 +0000
2005-06-24 11:39:52 +00:00
John Reiser 1a84b4681c fix sign-extend bug
committer: jreiser <jreiser> 1114311664 +0000
2005-04-24 03:01:04 +00:00
John Reiser 4bf81b8e1c propagate compiled changes due to ppc_bxx.S
stub/fold_elfppc32.h stub/fold_machppc32.h

committer: jreiser <jreiser> 1114229942 +0000
2005-04-23 04:19:02 +00:00
John Reiser c282e7fdb4 PPC branch+call trick: filter first 4MB only
filteri.cpp filter/ppcbxx.h stub/ppc_bxx.S

committer: jreiser <jreiser> 1114229877 +0000
2005-04-23 04:17:57 +00:00
John Reiser d339ee3135 PackLinuxElf32::unpack forgot several get_native32()
committer: jreiser <jreiser> 1114229735 +0000
2005-04-23 04:15:35 +00:00
Markus F.X.J. Oberhumer 1de95de299 Updated.
committer: mfx <mfx> 1111664629 +0000
2005-03-24 11:43:49 +00:00
Markus F.X.J. Oberhumer 96c998a1d7 Updated for current glibc.
committer: mfx <mfx> 1111664285 +0000
2005-03-24 11:38:05 +00:00
Markus F.X.J. Oberhumer b5413c0156 Added John to main banner.
committer: mfx <mfx> 1110936050 +0000
2005-03-16 01:20:50 +00:00
Markus F.X.J. Oberhumer 7371c195ff Allocate larger xtrasize based on ih.datasize.
committer: mfx <mfx> 1110936001 +0000
2005-03-16 01:20:01 +00:00
Markus F.X.J. Oberhumer 0866a1996b Added two checks for buffer overflows as suggested by Giovanni Bajo.
committer: mfx <mfx> 1110732210 +0000
2005-03-13 16:43:30 +00:00
Markus F.X.J. Oberhumer 41f44c4e78 Updated.
committer: mfx <mfx> 1110731666 +0000
2005-03-13 16:34:26 +00:00
Markus F.X.J. Oberhumer 131712c3bd New ACC version.
committer: mfx <mfx> 1110731645 +0000
2005-03-13 16:34:05 +00:00
Markus F.X.J. Oberhumer bae12aaab7 Added more global operators.
committer: mfx <mfx> 1110731448 +0000
2005-03-13 16:30:48 +00:00
Markus F.X.J. Oberhumer 74d5844d8c Tried to make 64-bit clean. John, please have a look!
committer: mfx <mfx> 1110731221 +0000
2005-03-13 16:27:01 +00:00
Markus F.X.J. Oberhumer c87908266a Fix a compilation problem with older compilers.
committer: mfx <mfx> 1110730245 +0000
2005-03-13 16:10:45 +00:00
Markus F.X.J. Oberhumer f788d76b8c Added several __attribute_packed.
committer: mfx <mfx> 1110730186 +0000
2005-03-13 16:09:46 +00:00
Markus F.X.J. Oberhumer 41031e572e Updated.
committer: mfx <mfx> 1110729509 +0000
2005-03-13 15:58:29 +00:00
Markus F.X.J. Oberhumer f8a0864c1b Final updates. Really.
committer: mfx <mfx> 1109817185 +0000
2005-03-03 02:33:05 +00:00
Markus F.X.J. Oberhumer 949587334c Updates.
committer: mfx <mfx> 1109816699 +0000
2005-03-03 02:24:59 +00:00
Markus F.X.J. Oberhumer 0bc6a1a7f1 Updated.
committer: mfx <mfx> 1109765803 +0000
2005-03-02 12:16:43 +00:00
Markus F.X.J. Oberhumer 0d9cbfe927 Updated.
committer: mfx <mfx> 1109756565 +0000
2005-03-02 09:42:45 +00:00
Markus F.X.J. Oberhumer 8742a524c3 Small updates.
committer: mfx <mfx> 1109750922 +0000
2005-03-02 08:08:42 +00:00
Markus F.X.J. Oberhumer 79bf2297b5 New simple and modern Makefile.
committer: mfx <mfx> 1109750619 +0000
2005-03-02 08:03:39 +00:00
Markus F.X.J. Oberhumer 32e9e23630 Removed old Makfiles (horrible cruft dating back from 1998).
committer: mfx <mfx> 1109750572 +0000
2005-03-02 08:02:52 +00:00
Markus F.X.J. Oberhumer 7f1cecba92 Got changed. We must sync our toolchains.
committer: mfx <mfx> 1109750498 +0000
2005-03-02 08:01:38 +00:00
Markus F.X.J. Oberhumer efd30c61c3 Use namespace.
committer: mfx <mfx> 1109750346 +0000
2005-03-02 07:59:06 +00:00
Markus F.X.J. Oberhumer 4c97b11207 Added OBJSTRIP_xxx variables.
committer: mfx <mfx> 1109734187 +0000
2005-03-02 03:29:47 +00:00
John Reiser 58ea0ab745 use "~0u" to force unsigned bitmasks
committer: jreiser <jreiser> 1109691309 +0000
2005-03-01 15:35:09 +00:00
Markus F.X.J. Oberhumer 3547c71ad5 New ACC version.
committer: mfx <mfx> 1109674986 +0000
2005-03-01 11:03:06 +00:00
Markus F.X.J. Oberhumer 044d6b2ce2 Updated some ELF constants.
committer: mfx <mfx> 1109674932 +0000
2005-03-01 11:02:12 +00:00
Markus F.X.J. Oberhumer a0b26b6c06 Added Elf32_Dyn.
committer: mfx <mfx> 1109671693 +0000
2005-03-01 10:08:13 +00:00
Markus F.X.J. Oberhumer 8e3bfde439 Use templates.
committer: mfx <mfx> 1109671197 +0000
2005-03-01 09:59:57 +00:00
Markus F.X.J. Oberhumer 6507de959b Remove "struct" keywords.
committer: mfx <mfx> 1109671153 +0000
2005-03-01 09:59:13 +00:00
Markus F.X.J. Oberhumer 56d09bf3b5 Avoid warning.
committer: mfx <mfx> 1109669763 +0000
2005-03-01 09:36:03 +00:00
Markus F.X.J. Oberhumer 232754b978 Removed trailing whitespace.
committer: mfx <mfx> 1109669261 +0000
2005-03-01 09:27:41 +00:00
Markus F.X.J. Oberhumer 75ef603308 Linker updates from Laszlo. Needs some testing.
committer: mfx <mfx> 1109669078 +0000
2005-03-01 09:24:38 +00:00
Markus F.X.J. Oberhumer a5a2fcee4d Avoid warning.
committer: mfx <mfx> 1109345414 +0000
2005-02-25 15:30:14 +00:00
John Reiser f86d57bfe3 mmap() needs in-range fd; b_method as arg5 to decompress
l_lx_elfppc32.S l_lx_elfppc32.h
	ppc_d_nrv2e.S
	ppc_d_nrv2b.S

committer: jreiser <jreiser> 1109217478 +0000
2005-02-24 03:57:58 +00:00
John Reiser 615615b1df Unmap the compressed program before running the uncompressed.
fold_elfppc32.S fold_elfppc32.h

committer: jreiser <jreiser> 1109129677 +0000
2005-02-23 03:34:37 +00:00
John Reiser aeba0ce170 add dependencies for ppc_bxx.S and ppc_d_nrv2e.S
Makefile fold_elfppc32.h l_mac_ppc32.h

committer: jreiser <jreiser> 1109093661 +0000
2005-02-22 17:34:21 +00:00
John Reiser 5ce60aad53 data cache prefetch
ppc_d_nrv2e.S l_lx_elfppc32.h

committer: jreiser <jreiser> 1109034808 +0000
2005-02-22 01:13:28 +00:00
John Reiser dbc01de9a0 remove debugg-only 'trap'
committer: jreiser <jreiser> 1109012788 +0000
2005-02-21 19:06:28 +00:00
John Reiser dfaf3f24fc fix bad merge
p_lx_elf.h p_lx_exc.cpp

committer: jreiser <jreiser> 1108944786 +0000
2005-02-21 00:13:06 +00:00
John Reiser 14b0527e79 fix compiler waring
committer: jreiser <jreiser> 1108941316 +0000
2005-02-20 23:15:16 +00:00
John Reiser f0148c3161 prepare for M_CL1B
committer: jreiser <jreiser> 1108940729 +0000
2005-02-20 23:05:29 +00:00
John Reiser 6a5e3d924d p_lx_interp, p_mach
committer: jreiser <jreiser> 1108940412 +0000
2005-02-20 23:00:12 +00:00
John Reiser 664a82e7c9 Start re-organizing the packing of Elf, by making Elf32 come first,
with Big endian and Little endian derived from it.
I386 still uses the old way, but PowerPC (both Linux and Darwin [Mac])
use the new way.
	p_elf.h p_lx_elf.cpp p_lx_elf.h p_lx_exc.cpp p_lx_exc.h
	p_unix.cpp p_unix.h p_vmlinx.cpp p_vmlinx.h p_vmlinz.cpp

committer: jreiser <jreiser> 1108940224 +0000
2005-02-20 22:57:04 +00:00
John Reiser e2763b4826 new packers PackMachPPC32 PackLinuxElf32ppc PackLinuxI386interp
packmast.cpp
	p_lx_interp.h

committer: jreiser <jreiser> 1108939957 +0000
2005-02-20 22:52:37 +00:00
John Reiser afb29b19c2 PowerPC branch [and call] trick
committer: jreiser <jreiser> 1108939726 +0000
2005-02-20 22:48:46 +00:00
John Reiser 8d60343940 allow better handling for no_filter option;
new options is_ptinterp, use_ptintep, make_ptinterp;
reserve codes for M_CL1B.
	compress.ch conf.h main.cpp options.h

committer: jreiser <jreiser> 1108939577 +0000
2005-02-20 22:46:17 +00:00
John Reiser 67a77f1880 Packer for Macintosh Darwin Mach-o PowerPC32
Added Files:
	p_mach.cpp p_mach.h

committer: jreiser <jreiser> 1108863998 +0000
2005-02-20 01:46:38 +00:00
John Reiser c933974174 branch trick for PowerPC32
committer: jreiser <jreiser> 1108863063 +0000
2005-02-20 01:31:03 +00:00
John Reiser 19715903fb New stubs pti86 (PT_INTERP for Linux x86), Linux Elf PowerPC-32,
Apple Macintosh Darwin PowerPC-32.

committer: jreiser <jreiser> 1108862148 +0000
2005-02-20 01:15:48 +00:00
John Reiser c88f72fd15 disinguish between __i386__ and generic
committer: jreiser <jreiser> 1108861387 +0000
2005-02-20 01:03:07 +00:00
John Reiser 7818596271 stub loader for Linux Elf PowerPC32
Added Files:
	m_lx_elfppc32.c l_lx_elfppc32.lds
	fold_elfppc32.S l_lx_elfppc32.S
	fold_elfppc32.h l_lx_elfppc32.h  [these two created by Makefile]

committer: jreiser <jreiser> 1108861182 +0000
2005-02-20 00:59:42 +00:00
John Reiser 9cb8d7bca6 stub loader for Macintosh (Darwin) Mach-o PowerPC32
Added Files:
	l_mac_ppc32.S fold_machppc32.S m_mac_mach32.c
	l_mac_ppc32.h fold_machppc32.h [these two created by Makefile]

committer: jreiser <jreiser> 1108860254 +0000
2005-02-20 00:44:14 +00:00
John Reiser 46f9256114 PowerPC unfilter, decompress, and register definitions
Added Files:
	ppc_bxx.S ppc_d_nrv2e.S ppc_regs.h

committer: jreiser <jreiser> 1108855959 +0000
2005-02-19 23:32:39 +00:00
John Reiser c26ef87202 Let the UPX loader be an Elf PT_INTERP /opt/upx/run
Added Files:
	p_lx_interp.cpp stub/l_lx_pti.c stub/fold_pti86.asm
	stub/fold_pti86.h stub/l_lx_pti86.asm stub/l_lx_pti86.h
	stub/l_lx_pti86.lds

committer: jreiser <jreiser> 1108855010 +0000
2005-02-19 23:16:50 +00:00
John Reiser 89fee5b835 allow more sections; print failing section on overflow
committer: jreiser <jreiser> 1108850756 +0000
2005-02-19 22:05:56 +00:00
John Reiser f5795eb01b make_hatch() is called from l_lx_sep86.asm, so cannot be 'static'
committer: jreiser <jreiser> 1108850437 +0000
2005-02-19 22:00:37 +00:00
László Molnár dbf0c9f016 msg.cpp: fixed possible sigsegv caused by a tricky filename
committer: ml1050 <ml1050> 1108382780 +0000
2005-02-14 12:06:20 +00:00
Markus F.X.J. Oberhumer 586b43048f Bump version.
committer: mfx <mfx> 1107807914 +0000
2005-02-07 20:25:14 +00:00
Markus F.X.J. Oberhumer 63b9ee61d2 Prepare UPX 1.93 release.
committer: mfx <mfx> 1107804731 +0000
2005-02-07 19:32:11 +00:00
Markus F.X.J. Oberhumer 3b9eff7f34 Enter 2005; added all needed stub files to CVS.
committer: mfx <mfx> 1107804447 +0000
2005-02-07 19:27:27 +00:00
John Reiser 59668c5fc1 ::pack3 to set .p_filesz; also set blocksize to allow giant scripts as input
p_lx_sh.cpp p_lx_sh.h

committer: jreiser <jreiser> 1105479043 +0000
2005-01-11 21:30:43 +00:00
Markus F.X.J. Oberhumer 3ed786fb5c Updated.
committer: mfx <mfx> 1103717402 +0000
2004-12-22 12:10:02 +00:00
Markus F.X.J. Oberhumer 0cd5eb5472 Use gcc-3.4.3 for Linux stubs.
committer: mfx <mfx> 1103717370 +0000
2004-12-22 12:09:30 +00:00
Markus F.X.J. Oberhumer ff571b96cb New ACC version.
committer: mfx <mfx> 1103717337 +0000
2004-12-22 12:08:57 +00:00
John Reiser 36b852e6bf %cs at entry to decompressor varies a _lot_ among Linux 2.4.x, 2.6.y kernels.
Decompressor must adapt; no universal constants exist for __BOOT_CS, _BOOT_DS.
	p_vmlinx.cpp stub/l_vmlinz.asm

committer: jreiser <jreiser> 1103605278 +0000
2004-12-21 05:01:18 +00:00
John Reiser f0c21c7203 Enhance documentation for process flow and testing.
Include some notes for compressing kernels from Linux 2.4.x.

committer: jreiser <jreiser> 1103513947 +0000
2004-12-20 03:39:07 +00:00
John Reiser 0516d8260c Fix stack synchronization bug at end of unfilter.
[The confusing fake "conditional compilation" strikes again!]

committer: jreiser <jreiser> 1103513713 +0000
2004-12-20 03:35:13 +00:00
John Reiser 1418f57b96 Fix bugs between Filter.addvalue and ckt32 macro call: [re-]compressed
Linux kernels were not booting.  Explain .addvalue better.
Set kernel stack pointer for boot-time decompression according to
Linux kernel documentation.
	     p_vmlinx.cpp      p_vmlinz.cpp
	stub/l_vmlinx.asm stub/l_vmlinz.asm
	filter/cto.h filter/ctoj.h filter/ctok.h

committer: jreiser <jreiser> 1103326936 +0000
2004-12-17 23:42:16 +00:00
Markus F.X.J. Oberhumer b24fb59c94 New upstream version.
committer: mfx <mfx> 1101602738 +0000
2004-11-28 00:45:38 +00:00
Markus F.X.J. Oberhumer 8fcf2bcd59 Fix bele.h to use strict PODs. This should fix build problems reported on ARM.
committer: mfx <mfx> 1098709362 +0000
2004-10-25 13:02:42 +00:00
Markus F.X.J. Oberhumer 079b808a56 Updated.
committer: mfx <mfx> 1098709263 +0000
2004-10-25 13:01:03 +00:00
Markus F.X.J. Oberhumer a4e01e28db New ACC version.
committer: mfx <mfx> 1098709116 +0000
2004-10-25 12:58:36 +00:00
Markus F.X.J. Oberhumer ec1ef9099f Updated.
committer: mfx <mfx> 1096637333 +0000
2004-10-01 13:28:53 +00:00
Markus F.X.J. Oberhumer ac724c7e6c New PS1 version from Jens.
committer: mfx <mfx> 1096637259 +0000
2004-10-01 13:27:39 +00:00
Markus F.X.J. Oberhumer ec25835525 New ACC version.
committer: mfx <mfx> 1096636709 +0000
2004-10-01 13:18:29 +00:00
Markus F.X.J. Oberhumer d4841a641c Updates.
committer: mfx <mfx> 1092135204 +0000
2004-08-10 10:53:24 +00:00
Markus F.X.J. Oberhumer 5612460720 New ACC version.
committer: mfx <mfx> 1092134926 +0000
2004-08-10 10:48:46 +00:00
John Reiser 465ea6429f "new []" requires matching "delete []"
committer: jreiser <jreiser> 1090882098 +0000
2004-07-26 22:48:18 +00:00
Markus F.X.J. Oberhumer ed9057ca83 Cleanups.
committer: mfx <mfx> 1090594763 +0000
2004-07-23 14:59:23 +00:00
Markus F.X.J. Oberhumer 14ced962db Cleanup.
committer: mfx <mfx> 1090583778 +0000
2004-07-23 11:56:18 +00:00
Markus F.X.J. Oberhumer 1aff6b862d Replaced ACC with miniACC.
committer: mfx <mfx> 1090583659 +0000
2004-07-23 11:54:19 +00:00
Markus F.X.J. Oberhumer ef490c4220 Updates.
committer: mfx <mfx> 1090577049 +0000
2004-07-23 10:04:09 +00:00
Markus F.X.J. Oberhumer 0dda83cbbc Updated.
committer: mfx <mfx> 1090577037 +0000
2004-07-23 10:03:57 +00:00
Markus F.X.J. Oberhumer fa4efec3b5 Bumped version numbers.
committer: mfx <mfx> 1090283329 +0000
2004-07-20 00:28:49 +00:00
Markus F.X.J. Oberhumer 814eabb88e Final updates for upx 1.92.
committer: mfx <mfx> 1090281040 +0000
2004-07-19 23:50:40 +00:00
John Reiser 95021e4977 mention vmlinux/i386
NEWS README README.1ST

committer: jreiser <jreiser> 1090261436 +0000
2004-07-19 18:23:56 +00:00
Markus F.X.J. Oberhumer d17fb7ebf0 Updated.
committer: mfx <mfx> 1090258607 +0000
2004-07-19 17:36:47 +00:00
Markus F.X.J. Oberhumer df9aa9ac32 Misc updates.
committer: mfx <mfx> 1090256162 +0000
2004-07-19 16:56:02 +00:00
Markus F.X.J. Oberhumer 9110517893 Check for .NET (win32/net) files.
committer: mfx <mfx> 1090256077 +0000
2004-07-19 16:54:37 +00:00
Markus F.X.J. Oberhumer 8204c7deb6 Small portability fixes.
committer: mfx <mfx> 1090256008 +0000
2004-07-19 16:53:28 +00:00
Markus F.X.J. Oberhumer 6662f8985e New ACC version.
committer: mfx <mfx> 1090253767 +0000
2004-07-19 16:16:07 +00:00
John Reiser a2b305ed3b Don't spend too much time compressing large symbol tables.
committer: jreiser <jreiser> 1090072585 +0000
2004-07-17 13:56:25 +00:00
John Reiser ce3d3a850c Allow any number of contiguous PT_LOAD.
p_vmlinx.cpp p_vmlinx.h

committer: jreiser <jreiser> 1090040793 +0000
2004-07-17 05:06:33 +00:00
Markus F.X.J. Oberhumer 212b674bc2 Portability fixes. Avoid some warnings.
committer: mfx <mfx> 1089734843 +0000
2004-07-13 16:07:23 +00:00
John Reiser 2980a6b4bb save 4 bytes
committer: jreiser <jreiser> 1089733580 +0000
2004-07-13 15:46:20 +00:00
Markus F.X.J. Oberhumer 435c0a9e82 New ACC version.
committer: mfx <mfx> 1089731989 +0000
2004-07-13 15:19:49 +00:00
Markus F.X.J. Oberhumer 4102cd7c91 Detabified.
committer: mfx <mfx> 1089731601 +0000
2004-07-13 15:13:21 +00:00
Markus F.X.J. Oberhumer b4b603819d Comment out cl1_d32.ash for now.
committer: mfx <mfx> 1089731343 +0000
2004-07-13 15:09:03 +00:00
Markus F.X.J. Oberhumer 20e3707e69 Updated some comments.
committer: mfx <mfx> 1089731255 +0000
2004-07-13 15:07:35 +00:00
John Reiser fc6eeaaea8 Decodes a format similar to nrv2b, except that a run of literals
is counted and phased instead of always 1-hot (no more 9/8 expansion).

committer: jreiser <jreiser> 1089692385 +0000
2004-07-13 04:19:45 +00:00
Markus F.X.J. Oberhumer 41799955ce Updated.
committer: mfx <mfx> 1089687731 +0000
2004-07-13 03:02:11 +00:00
Markus F.X.J. Oberhumer efb4ec9cb8 New ACC version.
committer: mfx <mfx> 1089687481 +0000
2004-07-13 02:58:01 +00:00
Markus F.X.J. Oberhumer 4dbda29f82 New upstream version.
committer: mfx <mfx> 1089687264 +0000
2004-07-13 02:54:24 +00:00
Markus F.X.J. Oberhumer befaa3c501 Detabified.
committer: mfx <mfx> 1089685145 +0000
2004-07-13 02:19:05 +00:00
John Reiser f41edf9e21 more Example twiddling
committer: jreiser <jreiser> 1089683530 +0000
2004-07-13 01:52:10 +00:00
John Reiser 754f10f0b0 update Example from linux kernel debuggin
committer: jreiser <jreiser> 1089674802 +0000
2004-07-12 23:26:42 +00:00
John Reiser 5d331fdf69 new file format vmlinux/i386
Modified Files:
	Makefile conf.h help.cpp linker.cpp p_elf.h packer.cpp
	packerf.cpp packmast.cpp stub/Makefile stub/l_vmlinz.asm
Added Files:
	p_vmlinx.h p_vmlinx.cpp stub/l_vmlinx.asm

committer: jreiser <jreiser> 1089652867 +0000
2004-07-12 17:21:07 +00:00
Markus F.X.J. Oberhumer cbf1dbe2cb Added new win32/pe option `--strip-loadconf'.
committer: mfx <mfx> 1089630382 +0000
2004-07-12 11:06:22 +00:00
Markus F.X.J. Oberhumer 3177de92fb New ACC version.
committer: mfx <mfx> 1089162904 +0000
2004-07-07 01:15:04 +00:00
Markus F.X.J. Oberhumer 3878890783 Prefer gcc-3.4.0 over gcc-3.4.1. Converted PF_TO_PROT into a macro (small size gain).
committer: mfx <mfx> 1088832985 +0000
2004-07-03 05:36:25 +00:00
Markus F.X.J. Oberhumer 61594f7873 Misc cleanups.
committer: mfx <mfx> 1088804669 +0000
2004-07-02 21:44:29 +00:00
Markus F.X.J. Oberhumer f412b5e0cd Fixed Win64 warnings.
committer: mfx <mfx> 1088804606 +0000
2004-07-02 21:43:26 +00:00
Markus F.X.J. Oberhumer f14d594a1a New ACC version.
committer: mfx <mfx> 1088804565 +0000
2004-07-02 21:42:45 +00:00
Markus F.X.J. Oberhumer f0279d23d3 Bumped version to start working on 1.92.
committer: mfx <mfx> 1088568203 +0000
2004-06-30 04:03:23 +00:00
Markus F.X.J. Oberhumer 18ef55ac14 Final updates for upx-1.91.
committer: mfx <mfx> 1088566877 +0000
2004-06-30 03:41:17 +00:00
Markus F.X.J. Oberhumer 0010c50de6 Updated.
committer: mfx <mfx> 1088552416 +0000
2004-06-29 23:40:16 +00:00
Markus F.X.J. Oberhumer 130699a33b Updated.
committer: mfx <mfx> 1088541938 +0000
2004-06-29 20:45:38 +00:00
Markus F.X.J. Oberhumer 5a8d60d3e0 Assorted fixes.
committer: mfx <mfx> 1088541880 +0000
2004-06-29 20:44:40 +00:00
Markus F.X.J. Oberhumer 603dc83c1a Fixed wrong n_mru storage in putPackHeader().
committer: mfx <mfx> 1088541728 +0000
2004-06-29 20:42:08 +00:00
Markus F.X.J. Oberhumer 51106e730b Updated.
committer: mfx <mfx> 1088532712 +0000
2004-06-29 18:11:52 +00:00
Markus F.X.J. Oberhumer 23ec864130 Removed trailing whitespace.
committer: mfx <mfx> 1088532664 +0000
2004-06-29 18:11:04 +00:00
Markus F.X.J. Oberhumer 5349bd0b2a Stricter check of some PE values.
committer: mfx <mfx> 1088532595 +0000
2004-06-29 18:09:55 +00:00
Markus F.X.J. Oberhumer 74d70fe1d9 New ACC version.
committer: mfx <mfx> 1088531787 +0000
2004-06-29 17:56:27 +00:00
Markus F.X.J. Oberhumer 041865c320 Misc cleanups.
committer: mfx <mfx> 1088103372 +0000
2004-06-24 18:56:12 +00:00
Markus F.X.J. Oberhumer 6a7d555ad7 Recompute tlsindex in buildLoader() as suggested by Laszlo.
committer: mfx <mfx> 1088101947 +0000
2004-06-24 18:32:27 +00:00
Markus F.X.J. Oberhumer 18262f79c7 New upstream version.
committer: mfx <mfx> 1087253885 +0000
2004-06-14 22:58:05 +00:00
John Reiser 9769599f1d Avoid "ASCII armor" area below 16MB (0x01000000) for exec-shield and
pre-linked PT_INTERP such as ld-linux.so.2
	l_lx_elf86.asm l_lx_elf86.lds l_lx_sh86.asm l_lx_sh86.lds

committer: jreiser <jreiser> 1084925700 +0000
2004-05-19 00:15:00 +00:00
John Reiser aee150474c Revamp do_xmap() to work under exec-shield and exec-shield-randomize,
and with pre-linked PT_INTERP such as ld-linux.so.2.
	l_lx_elf.c l_lx_sh.c

committer: jreiser <jreiser> 1084923593 +0000
2004-05-18 23:39:53 +00:00
Markus F.X.J. Oberhumer 0e45021a5a Bumped version-date.
committer: mfx <mfx> 1084324462 +0000
2004-05-12 01:14:22 +00:00
Markus F.X.J. Oberhumer 241abcc89c Whitespace changes.
committer: mfx <mfx> 1084324421 +0000
2004-05-12 01:13:41 +00:00
Markus F.X.J. Oberhumer 90fc32a56e Small cleanup.
committer: mfx <mfx> 1084324395 +0000
2004-05-12 01:13:15 +00:00
Markus F.X.J. Oberhumer 7ce85ab712 Fixes for gcc 3.4 (-funit-at-a-time). Reduced size of stubs a little bit.
committer: mfx <mfx> 1084323518 +0000
2004-05-12 00:58:38 +00:00
Markus F.X.J. Oberhumer 55cde23f10 Updated for gcc 3.4.0 release.
committer: mfx <mfx> 1084317169 +0000
2004-05-11 23:12:49 +00:00
Markus F.X.J. Oberhumer a19e6cd4f5 Detabified.
committer: mfx <mfx> 1084317075 +0000
2004-05-11 23:11:15 +00:00
Markus F.X.J. Oberhumer 06f8c55908 Fixed partial reads.
committer: mfx <mfx> 1084308720 +0000
2004-05-11 20:52:00 +00:00
Markus F.X.J. Oberhumer b10f68d20a New ACC version.
committer: mfx <mfx> 1084307588 +0000
2004-05-11 20:33:08 +00:00
John Reiser ed8a71bba1 recognize another variation of head.S: ljmp $0x10,...
committer: jreiser <jreiser> 1084136848 +0000
2004-05-09 21:07:28 +00:00
John Reiser fee6f17caf explicit PHDRS to control number of Elf32_Phdr: no PT_GNU_STACK
l_lx_elf86.lds l_lx_exec86.lds l_lx_sep86.lds l_lx_sh86.lds

committer: jreiser <jreiser> 1083997506 +0000
2004-05-08 06:25:06 +00:00
Markus F.X.J. Oberhumer 767e4e2ce6 New ps1/exe version from Jens.
committer: mfx <mfx> 1083813373 +0000
2004-05-06 03:16:13 +00:00
Markus F.X.J. Oberhumer 23f5370dcf Added cdecl.
committer: mfx <mfx> 1083812698 +0000
2004-05-06 03:04:58 +00:00
Markus F.X.J. Oberhumer 37ae689328 New PS1 version from Jens.
committer: mfx <mfx> 1081901413 +0000
2004-04-14 00:10:13 +00:00
Markus F.X.J. Oberhumer 123b33efd4 New upstream version.
committer: mfx <mfx> 1081448201 +0000
2004-04-08 18:16:41 +00:00
Markus F.X.J. Oberhumer 736ec9d9e5 Now requires djasm-2.04-mfx1.
committer: mfx <mfx> 1081387577 +0000
2004-04-08 01:26:17 +00:00
John Reiser 5a94136764 "python -c" works, so python is a shell. [However, scripts often use:
#!/usr/bin/env python
instead of
	#!/usr/bin/python
because for a long time python was not "blessed" by living in /usr/bin;
many users have python in /usr/local or some other place in $PATH.
And /usr/bin/env does not take "-c".]

committer: jreiser <jreiser> 1081041516 +0000
2004-04-04 01:18:36 +00:00
John Reiser 1555be40b7 fix alignment of loader after packing multiple blocks
p_lx_elf.h p_lx_elf.cpp

committer: jreiser <jreiser> 1080880623 +0000
2004-04-02 04:37:03 +00:00
Markus F.X.J. Oberhumer 60b7a3c33b Updated to gcc-3.4 20040314 prerelease.
committer: mfx <mfx> 1080195627 +0000
2004-03-25 06:20:27 +00:00
Markus F.X.J. Oberhumer a5d8e575bd Building the Linux stub is now completely freestanding of any libc/kernel headers.
committer: mfx <mfx> 1080194907 +0000
2004-03-25 06:08:27 +00:00
Markus F.X.J. Oberhumer 23db1d375c *** empty log message ***
committer: mfx <mfx> 1080194792 +0000
2004-03-25 06:06:32 +00:00
Markus F.X.J. Oberhumer e06722d121 Finally fixed long-standing reloc bug.
committer: mfx <mfx> 1080194776 +0000
2004-03-25 06:06:16 +00:00
John Reiser 81e77a8b2b linux-2.6.4 has different code in head.S
committer: jreiser <jreiser> 1079655854 +0000
2004-03-19 00:24:14 +00:00
Markus F.X.J. Oberhumer 5c567c5a76 Converted ctojr32 to use macro-local defines.
committer: mfx <mfx> 1075806803 +0000
2004-02-03 11:13:23 +00:00
Markus F.X.J. Oberhumer b8e698bde3 Added CPU instructions to all nasm source files.
FIXME: ctojr32 needs CPU 486 because it uses bswap.

committer: mfx <mfx> 1075806034 +0000
2004-02-03 11:00:34 +00:00
Markus F.X.J. Oberhumer 440b5b2608 Build updates.
committer: mfx <mfx> 1075804038 +0000
2004-02-03 10:27:18 +00:00
Markus F.X.J. Oberhumer 8b2e7ffe0b New ACC version.
committer: mfx <mfx> 1075803957 +0000
2004-02-03 10:25:57 +00:00
Markus F.X.J. Oberhumer 1018a96b31 Enter 2004.
committer: mfx <mfx> 1074624720 +0000
2004-01-20 18:52:00 +00:00
Markus F.X.J. Oberhumer 5f87e9891b Enter 2004.
committer: mfx <mfx> 1074623868 +0000
2004-01-20 18:37:48 +00:00
Markus F.X.J. Oberhumer 19564ed27e Cleanups.
committer: mfx <mfx> 1074623253 +0000
2004-01-20 18:27:33 +00:00
Markus F.X.J. Oberhumer f4022af48a Fixes for gcc 3.4 20040118.
committer: mfx <mfx> 1074619023 +0000
2004-01-20 17:17:03 +00:00
Markus F.X.J. Oberhumer 2d1de8b9e9 New ACC version.
committer: mfx <mfx> 1074109375 +0000
2004-01-14 19:42:55 +00:00
Markus F.X.J. Oberhumer cdbfdee725 Updates.
committer: mfx <mfx> 1071922490 +0000
2003-12-20 12:14:50 +00:00
Markus F.X.J. Oberhumer ac64126a66 Use gcc-3.4 20031206 (experimental) for smallest Linux stubs.
committer: mfx <mfx> 1071920621 +0000
2003-12-20 11:43:41 +00:00
Markus F.X.J. Oberhumer 97153e8e09 Compile fixes for PGI C++.
committer: mfx <mfx> 1071917829 +0000
2003-12-20 10:57:09 +00:00
Markus F.X.J. Oberhumer b9c976304a Avoid unused variables.
committer: mfx <mfx> 1071779657 +0000
2003-12-18 20:34:17 +00:00
Markus F.X.J. Oberhumer 670b67cc98 Updated.
committer: mfx <mfx> 1071754494 +0000
2003-12-18 13:34:54 +00:00
Markus F.X.J. Oberhumer ccecaa741c New ACC version.
committer: mfx <mfx> 1071754470 +0000
2003-12-18 13:34:30 +00:00
Markus F.X.J. Oberhumer 07230edec0 New ACC version.
committer: mfx <mfx> 1069787548 +0000
2003-11-25 19:12:28 +00:00
Markus F.X.J. Oberhumer de1a4b4da4 Cleanups.
committer: mfx <mfx> 1068991974 +0000
2003-11-16 14:12:54 +00:00
Markus F.X.J. Oberhumer aba5c40b17 New ACC version.
committer: mfx <mfx> 1068991888 +0000
2003-11-16 14:11:28 +00:00
Markus F.X.J. Oberhumer a55b3480ef Small updates.
committer: mfx <mfx> 1066732696 +0000
2003-10-21 10:38:16 +00:00
Markus F.X.J. Oberhumer bcb5e7d852 New ACC version.
committer: mfx <mfx> 1066732570 +0000
2003-10-21 10:36:10 +00:00
Markus F.X.J. Oberhumer e4f6378dfe Added support for amd64 (aka x86_64) cross compiler.
committer: mfx <mfx> 1064515134 +0000
2003-09-25 18:38:54 +00:00
Markus F.X.J. Oberhumer f616d2edf1 New upstream version.
committer: mfx <mfx> 1063623307 +0000
2003-09-15 10:55:07 +00:00
Markus F.X.J. Oberhumer bffb138b9c New ACC version.
committer: mfx <mfx> 1063544494 +0000
2003-09-14 13:01:34 +00:00
Markus F.X.J. Oberhumer b49fc6c081 Changed -O2 flag to -O15 for new nasm version.
committer: mfx <mfx> 1063502219 +0000
2003-09-14 01:16:59 +00:00
Markus F.X.J. Oberhumer 570b195ed6 Fixed cdecl.
committer: mfx <mfx> 1062472677 +0000
2003-09-02 03:17:57 +00:00
Markus F.X.J. Oberhumer b0e961b90b New ACC version.
committer: mfx <mfx> 1062472636 +0000
2003-09-02 03:17:16 +00:00
Markus F.X.J. Oberhumer 919a899c39 New ACC version.
committer: mfx <mfx> 1062077078 +0000
2003-08-28 13:24:38 +00:00
Markus F.X.J. Oberhumer 655094239c Cleanups.
committer: mfx <mfx> 1061224700 +0000
2003-08-18 16:38:20 +00:00
Markus F.X.J. Oberhumer 8eda698a9c New ACC version.
committer: mfx <mfx> 1061224659 +0000
2003-08-18 16:37:39 +00:00
Markus F.X.J. Oberhumer d1753c6df9 Misc cleanups.
committer: mfx <mfx> 1060699283 +0000
2003-08-12 14:41:23 +00:00
Markus F.X.J. Oberhumer 3db0b0e8fe New ACC version.
committer: mfx <mfx> 1060699213 +0000
2003-08-12 14:40:13 +00:00
Markus F.X.J. Oberhumer 8d5d6bd1a5 Updated TODO list.
committer: mfx <mfx> 1060091356 +0000
2003-08-05 13:49:16 +00:00
Markus F.X.J. Oberhumer 05f6f4d2ff Bump version date.
committer: mfx <mfx> 1060090111 +0000
2003-08-05 13:28:31 +00:00
Markus F.X.J. Oberhumer 9e154e33c3 Win64 updates.
committer: mfx <mfx> 1060086924 +0000
2003-08-05 12:35:24 +00:00
Markus F.X.J. Oberhumer 5125f4d4ac New ACC version.
committer: mfx <mfx> 1060086835 +0000
2003-08-05 12:33:55 +00:00
Markus F.X.J. Oberhumer 365a3c0432 Cleanups.
committer: mfx <mfx> 1059739807 +0000
2003-08-01 12:10:07 +00:00
Markus F.X.J. Oberhumer ab37b5ea0c New ACC version.
committer: mfx <mfx> 1059739715 +0000
2003-08-01 12:08:35 +00:00
Markus F.X.J. Oberhumer 20ddd8590d New ACC version.
committer: mfx <mfx> 1059549679 +0000
2003-07-30 07:21:19 +00:00
Markus F.X.J. Oberhumer 69d9aa6c69 Some fixes for latest gcc 3.4 snapshot.
committer: mfx <mfx> 1059510876 +0000
2003-07-29 20:34:36 +00:00
Markus F.X.J. Oberhumer 2163231401 New ACC version.
committer: mfx <mfx> 1059510824 +0000
2003-07-29 20:33:44 +00:00
Markus F.X.J. Oberhumer f513373693 Updated.
committer: mfx <mfx> 1058967901 +0000
2003-07-23 13:45:01 +00:00
Markus F.X.J. Oberhumer ed0e3b9af4 Small cleanups.
committer: mfx <mfx> 1058967699 +0000
2003-07-23 13:41:39 +00:00
Markus F.X.J. Oberhumer 4205c699ac Correct rounding issue when displaying the compression ratio.
committer: mfx <mfx> 1058789628 +0000
2003-07-21 12:13:48 +00:00
Markus F.X.J. Oberhumer 4e64cdac15 Final round of portab fixes - UPX should now compile on any halfway
modern C++ compiler.

committer: mfx <mfx> 1058789145 +0000
2003-07-21 12:05:45 +00:00
Markus F.X.J. Oberhumer bbbea34d74 New ACC version.
committer: mfx <mfx> 1058788892 +0000
2003-07-21 12:01:32 +00:00
Markus F.X.J. Oberhumer 66565f7238 Some portab fixes.
committer: mfx <mfx> 1058450658 +0000
2003-07-17 14:04:18 +00:00
Markus F.X.J. Oberhumer 9cb922425e Whitespace changes.
committer: mfx <mfx> 1058450247 +0000
2003-07-17 13:57:27 +00:00
Markus F.X.J. Oberhumer 268e13c572 New ACC version.
committer: mfx <mfx> 1058449640 +0000
2003-07-17 13:47:20 +00:00
John Reiser 03f1f615e5 filter 0x49 for [b]vmlinuz; 2nd parameter for ckt32 (addvalue)
p_vmlinz.cpp stub/macros.ash
	stub/l_lx_elf86.asm
	stub/l_lx_exec86.asm
	stub/l_vmlinz.asm

committer: jreiser <jreiser> 1058406408 +0000
2003-07-17 01:46:48 +00:00
John Reiser 94152391b1 patch ULEN for LZCKLLT1; filter 0x49 still not working
committer: jreiser <jreiser> 1058382714 +0000
2003-07-16 19:11:54 +00:00
John Reiser 2d403e07bb clear eflags; set cs; set ecx for LZCKLLT1; more documentation
committer: jreiser <jreiser> 1058382511 +0000
2003-07-16 19:08:31 +00:00
Markus F.X.J. Oberhumer 48ec581539 Renamed the options sub-structs for more consistency. Some portab fixes.
committer: mfx <mfx> 1058221575 +0000
2003-07-14 22:26:15 +00:00
Markus F.X.J. Oberhumer f9054529c1 New ACC version.
committer: mfx <mfx> 1058104401 +0000
2003-07-13 13:53:21 +00:00
Markus F.X.J. Oberhumer 67d9ff987c Updated.
committer: mfx <mfx> 1058050408 +0000
2003-07-12 22:53:28 +00:00
Markus F.X.J. Oberhumer a3bb8f00fd Updates for latest ACC changes.
committer: mfx <mfx> 1058050328 +0000
2003-07-12 22:52:08 +00:00
Markus F.X.J. Oberhumer 48846c7226 New ACC version.
committer: mfx <mfx> 1058045717 +0000
2003-07-12 21:35:17 +00:00
Markus F.X.J. Oberhumer ad8648f668 New ACC version.
committer: mfx <mfx> 1057743808 +0000
2003-07-09 09:43:28 +00:00
Markus F.X.J. Oberhumer c7224c7727 Added some important TODO entries.
committer: mfx <mfx> 1054071077 +0000
2003-05-27 21:31:17 +00:00
Markus F.X.J. Oberhumer b2949259c5 Portability updates.
committer: mfx <mfx> 1054071025 +0000
2003-05-27 21:30:25 +00:00
Markus F.X.J. Oberhumer 757bdd1264 New ACC version.
committer: mfx <mfx> 1054070133 +0000
2003-05-27 21:15:33 +00:00
Markus F.X.J. Oberhumer ec1e5849eb Remove debug output.
committer: mfx <mfx> 1054069636 +0000
2003-05-27 21:07:16 +00:00
Markus F.X.J. Oberhumer 1752fab911 New ACC version.
committer: mfx <mfx> 1054069577 +0000
2003-05-27 21:06:17 +00:00
Markus F.X.J. Oberhumer b0748388b2 New upstream version.
committer: mfx <mfx> 1052654076 +0000
2003-05-11 11:54:36 +00:00
Markus F.X.J. Oberhumer 175899013e Updated.
committer: mfx <mfx> 1051152491 +0000
2003-04-24 02:48:11 +00:00
Markus F.X.J. Oberhumer c448d15a8f New ACC version.
committer: mfx <mfx> 1051152474 +0000
2003-04-24 02:47:54 +00:00
Markus F.X.J. Oberhumer 5c7bca5b3e Updates.
committer: mfx <mfx> 1050612607 +0000
2003-04-17 20:50:07 +00:00
Markus F.X.J. Oberhumer 390cdbba2d New ACC version.
committer: mfx <mfx> 1050608556 +0000
2003-04-17 19:42:36 +00:00
Markus F.X.J. Oberhumer 256b8f066f New version from Jens.
committer: mfx <mfx> 1049938824 +0000
2003-04-10 01:40:24 +00:00
Markus F.X.J. Oberhumer 30915862cd New upstream version.
committer: mfx <mfx> 1049683526 +0000
2003-04-07 02:45:26 +00:00
Markus F.X.J. Oberhumer eeb1dfaf8f Updated.
committer: mfx <mfx> 1049676306 +0000
2003-04-07 00:45:06 +00:00
Markus F.X.J. Oberhumer 90161bc3a7 New ACC version.
committer: mfx <mfx> 1049665216 +0000
2003-04-06 21:40:16 +00:00
Markus F.X.J. Oberhumer a1064dc2cb New ps1/exe version from Jens.
committer: mfx <mfx> 1049665152 +0000
2003-04-06 21:39:12 +00:00
Markus F.X.J. Oberhumer b8a9b321fa Updated.
committer: mfx <mfx> 1049665135 +0000
2003-04-06 21:38:55 +00:00
Markus F.X.J. Oberhumer a3e80b1628 Fixed call to typeid().
committer: mfx <mfx> 1049380061 +0000
2003-04-03 14:27:41 +00:00
Markus F.X.J. Oberhumer 350ebfc47d *** empty log message ***
committer: mfx <mfx> 1049380046 +0000
2003-04-03 14:27:26 +00:00
Markus F.X.J. Oberhumer b9b75c536c *** empty log message ***
committer: mfx <mfx> 1049237553 +0000
2003-04-01 22:52:33 +00:00
Markus F.X.J. Oberhumer 8b74704bbf *** empty log message ***
committer: mfx <mfx> 1049203016 +0000
2003-04-01 13:16:56 +00:00
Markus F.X.J. Oberhumer bead894e49 Updated.
committer: mfx <mfx> 1049194128 +0000
2003-04-01 10:48:48 +00:00
John Reiser 502f9b5a00 better hadling of Linux AT_SYSINFO (32 <= a_type)
committer: jreiser <jreiser> 1048872136 +0000
2003-03-28 17:22:16 +00:00
Markus F.X.J. Oberhumer cd15b7d5af *** empty log message ***
committer: mfx <mfx> 1048717636 +0000
2003-03-26 22:27:16 +00:00
Markus F.X.J. Oberhumer 0c1d544e98 *** empty log message ***
committer: mfx <mfx> 1048663373 +0000
2003-03-26 07:22:53 +00:00
Markus F.X.J. Oberhumer 728be1867f *** empty log message ***
committer: mfx <mfx> 1048662806 +0000
2003-03-26 07:13:26 +00:00
Markus F.X.J. Oberhumer 09578df46b New ACC system.
committer: mfx <mfx> 1048662134 +0000
2003-03-26 07:02:14 +00:00
Markus F.X.J. Oberhumer b29f5b7c09 *** empty log message ***
committer: mfx <mfx> 1048661664 +0000
2003-03-26 06:54:24 +00:00
Markus F.X.J. Oberhumer 10f602fca7 *** empty log message ***
committer: mfx <mfx> 1048661243 +0000
2003-03-26 06:47:23 +00:00
Markus F.X.J. Oberhumer 2f8917f450 wc/le: Refuse to pack files without relocations. This should be fixed.
committer: mfx <mfx> 1048283863 +0000
2003-03-21 21:57:43 +00:00
Markus F.X.J. Oberhumer b57f48d543 Updated.
committer: mfx <mfx> 1046369903 +0000
2003-02-27 18:18:23 +00:00
Markus F.X.J. Oberhumer 87a4d8455d Updated.
committer: mfx <mfx> 1046366795 +0000
2003-02-27 17:26:35 +00:00
Markus F.X.J. Oberhumer b14df392fa Updated.
committer: mfx <mfx> 1045574984 +0000
2003-02-18 13:29:44 +00:00
Markus F.X.J. Oberhumer 437c34a68c Small cleanups.
committer: mfx <mfx> 1044946475 +0000
2003-02-11 06:54:35 +00:00
Markus F.X.J. Oberhumer b218cec3d7 Updated for VC7.
committer: mfx <mfx> 1044418804 +0000
2003-02-05 04:20:04 +00:00
Markus F.X.J. Oberhumer f19c91243a Cleanups.
committer: mfx <mfx> 1044346802 +0000
2003-02-04 08:20:02 +00:00
Markus F.X.J. Oberhumer 882e1be2db Cleanups.
committer: mfx <mfx> 1044346308 +0000
2003-02-04 08:11:48 +00:00
Markus F.X.J. Oberhumer 8e21c1e965 Updated.
committer: mfx <mfx> 1043776870 +0000
2003-01-28 18:01:10 +00:00
Markus F.X.J. Oberhumer f3970eaed9 Updated.
committer: mfx <mfx> 1043694056 +0000
2003-01-27 19:00:56 +00:00
Markus F.X.J. Oberhumer ac4b8f8617 Use MemBuffer.clear().
committer: mfx <mfx> 1043693892 +0000
2003-01-27 18:58:12 +00:00
Markus F.X.J. Oberhumer 51c28020de Use a MemBuffer instead of a pointer.
committer: mfx <mfx> 1043693800 +0000
2003-01-27 18:56:40 +00:00
Markus F.X.J. Oberhumer fd525ae7df Portability fixes.
committer: mfx <mfx> 1043693750 +0000
2003-01-27 18:55:50 +00:00
Markus F.X.J. Oberhumer a282171318 Rewritten.
committer: mfx <mfx> 1043693646 +0000
2003-01-27 18:54:06 +00:00
Markus F.X.J. Oberhumer c3040d1636 Updated.
committer: mfx <mfx> 1043693611 +0000
2003-01-27 18:53:31 +00:00
John Reiser c76c07aea0 prepare to allow multiple decompressors and multiple unfilters
committer: jreiser <jreiser> 1043441624 +0000
2003-01-24 20:53:44 +00:00
László Molnár 1282ed333a djgpp2/coff updates
committer: ml1050 <ml1050> 1043312061 +0000
2003-01-23 08:54:21 +00:00
Markus F.X.J. Oberhumer 32e76e88cf Updated.
committer: mfx <mfx> 1043211831 +0000
2003-01-22 05:03:51 +00:00
Markus F.X.J. Oberhumer fc0d3ff118 Updated.
committer: mfx <mfx> 1043101129 +0000
2003-01-20 22:18:49 +00:00
Markus F.X.J. Oberhumer 0bd05c0d67 Updated.
committer: mfx <mfx> 1042994191 +0000
2003-01-19 16:36:31 +00:00
Markus F.X.J. Oberhumer ff2c5300b8 New upstream version.
committer: mfx <mfx> 1042993977 +0000
2003-01-19 16:32:57 +00:00
Markus F.X.J. Oberhumer a38989dfbf Updated.
committer: mfx <mfx> 1042930217 +0000
2003-01-18 22:50:17 +00:00
Markus F.X.J. Oberhumer e387c6bc56 Portability updates.
committer: mfx <mfx> 1042930101 +0000
2003-01-18 22:48:21 +00:00
John Reiser 5eb81c0ec4 omit unfilter when .b_ftid==0
committer: jreiser <jreiser> 1042755704 +0000
2003-01-16 22:21:44 +00:00
Markus F.X.J. Oberhumer f92b617c43 Updated.
committer: mfx <mfx> 1042742278 +0000
2003-01-16 18:37:58 +00:00
Markus F.X.J. Oberhumer 8f25c72085 Consistently use const Class &' instead of Class const &'.
committer: mfx <mfx> 1042741665 +0000
2003-01-16 18:27:45 +00:00
Markus F.X.J. Oberhumer 7860e7a249 Updated.
committer: mfx <mfx> 1042741465 +0000
2003-01-16 18:24:25 +00:00
Markus F.X.J. Oberhumer a2e3ceb8c8 Portability updates.
committer: mfx <mfx> 1042738038 +0000
2003-01-16 17:27:18 +00:00
Markus F.X.J. Oberhumer e96ad21db1 Added support for Intel C++ 7.0.
committer: mfx <mfx> 1042686101 +0000
2003-01-16 03:01:41 +00:00
Markus F.X.J. Oberhumer 888ac8a220 Updated.
committer: mfx <mfx> 1042654719 +0000
2003-01-15 18:18:39 +00:00
Markus F.X.J. Oberhumer 29db8bca3a Major cleanup.
committer: mfx <mfx> 1042637889 +0000
2003-01-15 13:38:09 +00:00
Markus F.X.J. Oberhumer 63d49f0143 Updated.
committer: mfx <mfx> 1042637875 +0000
2003-01-15 13:37:55 +00:00
Markus F.X.J. Oberhumer 378224c6ba Updated.
committer: mfx <mfx> 1042634011 +0000
2003-01-15 12:33:31 +00:00
Markus F.X.J. Oberhumer 2f3e7a82b5 Detabified.
committer: mfx <mfx> 1042632555 +0000
2003-01-15 12:09:15 +00:00
Markus F.X.J. Oberhumer 960f020277 Fixed typos.
committer: mfx <mfx> 1042632460 +0000
2003-01-15 12:07:40 +00:00
Markus F.X.J. Oberhumer 6962da718c Added some calls to MemBuffer::checkState().
committer: mfx <mfx> 1042580584 +0000
2003-01-14 21:43:04 +00:00
Markus F.X.J. Oberhumer 42575d9f57 Use NULL instead of 0.
committer: mfx <mfx> 1042580552 +0000
2003-01-14 21:42:32 +00:00
Markus F.X.J. Oberhumer 03fb0d95c6 Rewrote MemBuffer to do some internal checks.
committer: mfx <mfx> 1042580463 +0000
2003-01-14 21:41:03 +00:00
Markus F.X.J. Oberhumer beb766b005 Major cleanup. Jens, please have a look.
committer: mfx <mfx> 1042576817 +0000
2003-01-14 20:40:17 +00:00
Markus F.X.J. Oberhumer 29c1f67057 Cleanup.
committer: mfx <mfx> 1042576530 +0000
2003-01-14 20:35:30 +00:00
Markus F.X.J. Oberhumer a709b38065 Use new file+MemBuffer methods.
committer: mfx <mfx> 1042576321 +0000
2003-01-14 20:32:01 +00:00
Markus F.X.J. Oberhumer ec5840fb2a Added overloaded write functions for MemBuffer.
committer: mfx <mfx> 1042576236 +0000
2003-01-14 20:30:36 +00:00
Markus F.X.J. Oberhumer 9511e3c9b1 Added ALIGN_GAP(a,b) marco.
committer: mfx <mfx> 1042576135 +0000
2003-01-14 20:28:55 +00:00
Markus F.X.J. Oberhumer 9190e7d51a Use new allocForCompression().
committer: mfx <mfx> 1042575473 +0000
2003-01-14 20:17:53 +00:00
Markus F.X.J. Oberhumer cff830c43b Cleanup.
committer: mfx <mfx> 1042575285 +0000
2003-01-14 20:14:45 +00:00
Markus F.X.J. Oberhumer e31c45dc10 Allow a number of extra bytes in the allocForXXX() methods.
committer: mfx <mfx> 1042575213 +0000
2003-01-14 20:13:33 +00:00
Markus F.X.J. Oberhumer e1da733810 Updated.
committer: mfx <mfx> 1042567596 +0000
2003-01-14 18:06:36 +00:00
Markus F.X.J. Oberhumer b8c34036a5 Cleanups.
committer: mfx <mfx> 1042565088 +0000
2003-01-14 17:24:48 +00:00
Markus F.X.J. Oberhumer d771f219f0 Bumped version.
committer: mfx <mfx> 1042565001 +0000
2003-01-14 17:23:21 +00:00
Markus F.X.J. Oberhumer d8280343f9 Makefiles updated.
committer: mfx <mfx> 1042564758 +0000
2003-01-14 17:19:18 +00:00
Markus F.X.J. Oberhumer c7b9395866 Detabified.
committer: mfx <mfx> 1042564671 +0000
2003-01-14 17:17:51 +00:00
Markus F.X.J. Oberhumer 992ceee52b CLeanups.
committer: mfx <mfx> 1042480204 +0000
2003-01-13 17:50:04 +00:00
Markus F.X.J. Oberhumer 2162a01848 Enter 2003.
committer: mfx <mfx> 1042478199 +0000
2003-01-13 17:16:39 +00:00
Markus F.X.J. Oberhumer 102e0f0a98 Re-worked the Makefiles.
committer: mfx <mfx> 1042477974 +0000
2003-01-13 17:12:54 +00:00
John Reiser 4e0967e0a1 Code to supply a "linking view" for /usr/bin/strip.
(Not used today because yet another bug is worse.)  See
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=81644

committer: jreiser <jreiser> 1042341933 +0000
2003-01-12 03:25:33 +00:00
John Reiser 73dc4eede0 Elf_LE32_Shdr; set_native16()
p_elf.h p_unix.h

committer: jreiser <jreiser> 1042341777 +0000
2003-01-12 03:22:57 +00:00
Markus F.X.J. Oberhumer 5e5ea9f6e4 Cleanups.
committer: mfx <mfx> 1041858220 +0000
2003-01-06 13:03:40 +00:00
Markus F.X.J. Oberhumer e537f25857 Default to `-cpu=i686'.
committer: mfx <mfx> 1041858189 +0000
2003-01-06 13:03:09 +00:00
Markus F.X.J. Oberhumer 47aea88c27 Whitespace changes.
committer: mfx <mfx> 1041858159 +0000
2003-01-06 13:02:39 +00:00
Markus F.X.J. Oberhumer 0237bf8915 Updated.
committer: mfx <mfx> 1041858132 +0000
2003-01-06 13:02:12 +00:00
Markus F.X.J. Oberhumer 3a7032f21c Updated.
committer: mfx <mfx> 1041162781 +0000
2002-12-29 11:53:01 +00:00
John Reiser 54d01790b5 Linux 2.5.53 has some Elf32_auxv_t.a_type >= 32
committer: jreiser <jreiser> 1040352519 +0000
2002-12-20 02:48:39 +00:00
John Reiser fb3375112e [B]VMLINUZ for 0x40 series filters
packerf.cpp p_vmlinz.cpp

committer: jreiser <jreiser> 1039144160 +0000
2002-12-06 03:09:20 +00:00
John Reiser 554f22a14f ckt32 for 0x40 series filters
committer: jreiser <jreiser> 1039144122 +0000
2002-12-06 03:08:42 +00:00
Markus F.X.J. Oberhumer eb6a6e3909 Cleanups.
committer: mfx <mfx> 1037132993 +0000
2002-11-12 20:29:53 +00:00
Markus F.X.J. Oberhumer 041947507f Small patch from Jens.
committer: mfx <mfx> 1037131376 +0000
2002-11-12 20:02:56 +00:00
Markus F.X.J. Oberhumer ff03ac17b2 Cosmetic changes.
committer: mfx <mfx> 1037106750 +0000
2002-11-12 13:12:30 +00:00
John Reiser 12c6cd8021 Comment on current state of stub/fold* vs decompress, and independent unfilter.
p_lx_elf.cpp p_lx_exc.cpp

committer: jreiser <jreiser> 1037072124 +0000
2002-11-12 03:35:24 +00:00
John Reiser de6e8c8020 upx_itoa() in assembler to enforce no relocation
Makefile l_lx_exec.c upx_itoa.asm

committer: jreiser <jreiser> 1037070863 +0000
2002-11-12 03:14:23 +00:00
Markus F.X.J. Oberhumer f3b64cfe78 Bumped version.
committer: mfx <mfx> 1037068905 +0000
2002-11-12 02:41:45 +00:00
Markus F.X.J. Oberhumer 1e8214cd3f Use `volatile' to make the division relocatible.
committer: mfx <mfx> 1037059592 +0000
2002-11-12 00:06:32 +00:00
Markus F.X.J. Oberhumer 7802257700 Portability fixes.
committer: mfx <mfx> 1037058393 +0000
2002-11-11 23:46:33 +00:00
Markus F.X.J. Oberhumer 60031bed47 Disable filters if we have more than one block.
committer: mfx <mfx> 1037024125 +0000
2002-11-11 14:15:25 +00:00
Markus F.X.J. Oberhumer d7e795a731 Set blocksize in canPack().
committer: mfx <mfx> 1036984678 +0000
2002-11-11 03:17:58 +00:00
Markus F.X.J. Oberhumer c0cccd6196 Whitespace changes.
committer: mfx <mfx> 1036984538 +0000
2002-11-11 03:15:38 +00:00
Markus F.X.J. Oberhumer 6cd0d5d779 Cleanups.
committer: mfx <mfx> 1036984522 +0000
2002-11-11 03:15:22 +00:00
Markus F.X.J. Oberhumer f66d8f98c9 Changed year to 2002.
committer: mfx <mfx> 1036971635 +0000
2002-11-10 23:40:35 +00:00
Markus F.X.J. Oberhumer a94a3e9741 If testOverlappingDecompression() fails, just treat the block as
non-compressible.

committer: mfx <mfx> 1036971145 +0000
2002-11-10 23:32:25 +00:00
Markus F.X.J. Oberhumer c798242bfe Updated.
committer: mfx <mfx> 1036969636 +0000
2002-11-10 23:07:16 +00:00
Markus F.X.J. Oberhumer 80622d4037 Removed misleading "FIXME".
committer: mfx <mfx> 1036968698 +0000
2002-11-10 22:51:38 +00:00
John Reiser 5ac2eed3d9 ::unpackExtent() honors per-block filter if newer 12-byte b_info
committer: jreiser <jreiser> 1036876078 +0000
2002-11-09 21:07:58 +00:00
John Reiser 33ec757c41 AT_NUMBER grew; also fix %edx clobbered during copy of auxv
committer: jreiser <jreiser> 1036866268 +0000
2002-11-09 18:24:28 +00:00
Markus F.X.J. Oberhumer b6c84d19ab Cleanups.
committer: mfx <mfx> 1036860405 +0000
2002-11-09 16:46:45 +00:00
Markus F.X.J. Oberhumer f91849ec4b New version from Jens.
committer: mfx <mfx> 1036855572 +0000
2002-11-09 15:26:12 +00:00
Markus F.X.J. Oberhumer 46ae6e1c2a Fixed typo in comment.
committer: mfx <mfx> 1036855554 +0000
2002-11-09 15:25:54 +00:00
John Reiser 7cbf7af6e8 cleanup ui pass count
committer: jreiser <jreiser> 1036816411 +0000
2002-11-09 04:33:31 +00:00
John Reiser 7f69f5937a be gentler, use throwAlreadyPackedByUPX()
committer: jreiser <jreiser> 1036784004 +0000
2002-11-08 19:33:24 +00:00
John Reiser e0ad859eef pack1() re-allocates ibuf after setting blocksize
committer: jreiser <jreiser> 1036733697 +0000
2002-11-08 05:34:57 +00:00
Markus F.X.J. Oberhumer f5a2641ea1 Changed version number and date.
committer: mfx <mfx> 1036688381 +0000
2002-11-07 16:59:41 +00:00
Markus F.X.J. Oberhumer ccaff85870 Updated.
committer: mfx <mfx> 1036688362 +0000
2002-11-07 16:59:22 +00:00
Markus F.X.J. Oberhumer af65e40986 Added some tests to sanity check.
committer: mfx <mfx> 1035667330 +0000
2002-10-26 21:22:10 +00:00
Markus F.X.J. Oberhumer f41e3c01f4 Added be24.
committer: mfx <mfx> 1035661372 +0000
2002-10-26 19:42:52 +00:00
Markus F.X.J. Oberhumer e8b97a12a9 Updated.
committer: mfx <mfx> 1035473217 +0000
2002-10-24 15:26:57 +00:00
Markus F.X.J. Oberhumer 8744f6bd7f Added a check for unsupported coff headers.
committer: mfx <mfx> 1035473178 +0000
2002-10-24 15:26:18 +00:00
Markus F.X.J. Oberhumer 204f4eefd8 Cleanup.
committer: mfx <mfx> 1035300869 +0000
2002-10-22 15:34:29 +00:00
Markus F.X.J. Oberhumer 7af193df77 Added read() functions that take a MemBuffer as arg.
committer: mfx <mfx> 1035297017 +0000
2002-10-22 14:30:17 +00:00
Markus F.X.J. Oberhumer b082a6f1da New version from Jens.
committer: mfx <mfx> 1035190264 +0000
2002-10-21 08:51:04 +00:00
Markus F.X.J. Oberhumer ce1e5b5ae1 Updated.
committer: mfx <mfx> 1035187919 +0000
2002-10-21 08:11:59 +00:00
Markus F.X.J. Oberhumer 565360a3f2 Cleanups.
committer: mfx <mfx> 1034942507 +0000
2002-10-18 12:01:47 +00:00
John Reiser 69cec874a1 checkPatch() resets
p_lx_elf.cpp p_lx_exc.cpp p_unix.cpp

committer: jreiser <jreiser> 1034906580 +0000
2002-10-18 02:03:00 +00:00
John Reiser 66206e8dd7 %include n2e_d32.ash
Makefile l_vmlinz.asm

committer: jreiser <jreiser> 1034906454 +0000
2002-10-18 02:00:54 +00:00
John Reiser 44c1879e27 use n2e_d32.ash, n2e_d32.asy
Makefile l_lx_elf86.asm l_lx_exec86.asm l_lx_sh86.asm

committer: jreiser <jreiser> 1034834452 +0000
2002-10-17 06:00:52 +00:00
John Reiser a9bb95fefd prefer filters 0x49,0x46 until problems with 0x2Y and 0x3Y are diagnosed
committer: jreiser <jreiser> 1034794465 +0000
2002-10-16 18:54:25 +00:00
John Reiser 4ad2242e96 half-way patch (don't abort upx) for filters 0x2Y and 0x3Y; needs work
committer: jreiser <jreiser> 1034794337 +0000
2002-10-16 18:52:17 +00:00
Markus F.X.J. Oberhumer 1e1e333d61 Cleanups.
committer: mfx <mfx> 1034748563 +0000
2002-10-16 06:09:23 +00:00
Markus F.X.J. Oberhumer 81efdd41f4 Updated.
committer: mfx <mfx> 1034748530 +0000
2002-10-16 06:08:50 +00:00
Markus F.X.J. Oberhumer ac245b39d5 Re-synced `identtiny' from 1.2 branch.
committer: mfx <mfx> 1034741770 +0000
2002-10-16 04:16:10 +00:00
Markus F.X.J. Oberhumer cecfaaf63e Cleanups.
committer: mfx <mfx> 1034741718 +0000
2002-10-16 04:15:18 +00:00
Markus F.X.J. Oberhumer 8d37bb4469 Cleanups.
committer: mfx <mfx> 1034719891 +0000
2002-10-15 22:11:31 +00:00
Markus F.X.J. Oberhumer b710f2d69f Set correct header.
committer: mfx <mfx> 1034719851 +0000
2002-10-15 22:10:51 +00:00
John Reiser d96646b0e0 save 3 bytes by not clearing [AT_NULL].a_un.a_ptr
committer: jreiser <jreiser> 1034698533 +0000
2002-10-15 16:15:33 +00:00
John Reiser c069efaa1b decompress upx-1.22 linux/386 by e_entry==+0x80
committer: jreiser <jreiser> 1034698283 +0000
2002-10-15 16:11:23 +00:00
Markus F.X.J. Oberhumer 25b12eb38a Updated.
committer: mfx <mfx> 1034649809 +0000
2002-10-15 02:43:29 +00:00
Markus F.X.J. Oberhumer 6779559ba2 Default to NRV2E instead of NRV2D.
committer: mfx <mfx> 1034649545 +0000
2002-10-15 02:39:05 +00:00
Markus F.X.J. Oberhumer 4e411eab59 Enabled ALG_NRV2E.
committer: mfx <mfx> 1034637236 +0000
2002-10-14 23:13:56 +00:00
Markus F.X.J. Oberhumer 1ba9ce283b Added largefile support under Linux.
committer: mfx <mfx> 1034637175 +0000
2002-10-14 23:12:55 +00:00
Markus F.X.J. Oberhumer bd191af41b Fixed canUnpackVersion().
committer: mfx <mfx> 1034637154 +0000
2002-10-14 23:12:34 +00:00
Markus F.X.J. Oberhumer 13f4f7ffdd Added.
committer: mfx <mfx> 1034628410 +0000
2002-10-14 20:46:50 +00:00
Markus F.X.J. Oberhumer db62588d47 Build updates.
committer: mfx <mfx> 1034620929 +0000
2002-10-14 18:42:09 +00:00
Markus F.X.J. Oberhumer 17325c7939 Updated.
committer: mfx <mfx> 1034619575 +0000
2002-10-14 18:19:35 +00:00
Markus F.X.J. Oberhumer e275e7614e Whitespace changes.
committer: mfx <mfx> 1034619052 +0000
2002-10-14 18:10:52 +00:00
Markus F.X.J. Oberhumer d383b1e1a3 Docs updates.
committer: mfx <mfx> 1034618834 +0000
2002-10-14 18:07:14 +00:00
Markus F.X.J. Oberhumer 973579f462 Upgraded to latest version.
committer: mfx <mfx> 1034618509 +0000
2002-10-14 18:01:49 +00:00
Markus F.X.J. Oberhumer 05db38225a Disabled the untested filters for now.
committer: mfx <mfx> 1034617837 +0000
2002-10-14 17:50:37 +00:00
Markus F.X.J. Oberhumer 3b771656bb Fixed typo.
committer: mfx <mfx> 1034617446 +0000
2002-10-14 17:44:06 +00:00
Markus F.X.J. Oberhumer fe531960ab New ps1/exe version from Jens. Needs new asm5900-mfx5.
committer: mfx <mfx> 1034617199 +0000
2002-10-14 17:39:59 +00:00
John Reiser accbc5d809 fix parameter type nit
committer: jreiser <jreiser> 1033096360 +0000
2002-09-27 03:12:40 +00:00
Markus F.X.J. Oberhumer fa5b74b763 Added some files to `clean' rule.
committer: mfx <mfx> 1033088856 +0000
2002-09-27 01:07:36 +00:00
John Reiser 124cdfda37 new option "--ptinterp" for linux/elf386 compressing PT_INTERP file
p_lx_elf.cpp options.h main.cpp

committer: jreiser <jreiser> 1032629299 +0000
2002-09-21 17:28:19 +00:00
John Reiser 8ad3d01d81 Prepare for ability to compress PT_INTERP program.
Also save 16 bytes at cost of incompatible with glibc-2.1.1 (1999-12-29).
	fold_elf86.asm l_lx_elf.c

committer: jreiser <jreiser> 1032625240 +0000
2002-09-21 16:20:40 +00:00
Markus F.X.J. Oberhumer 448baac0f4 Updated.
committer: mfx <mfx> 1031933579 +0000
2002-09-13 16:12:59 +00:00
Markus F.X.J. Oberhumer e225d77146 Bumped version in getVersion() for all formats.
committer: mfx <mfx> 1031846916 +0000
2002-09-12 16:08:36 +00:00
Markus F.X.J. Oberhumer 74a2d9486b Initial NRV2E support. Pretty much untested.
committer: mfx <mfx> 1031841557 +0000
2002-09-12 14:39:17 +00:00
Markus F.X.J. Oberhumer 6b74aa2673 Small updates.
committer: mfx <mfx> 1031793636 +0000
2002-09-12 01:20:36 +00:00
Markus F.X.J. Oberhumer 9f4a0fedbf Updated.
committer: mfx <mfx> 1031578030 +0000
2002-09-09 13:27:10 +00:00
Markus F.X.J. Oberhumer 9b079b371d Resynced with upx 1.2 branch.
committer: mfx <mfx> 1031577224 +0000
2002-09-09 13:13:44 +00:00
Markus F.X.J. Oberhumer 1439dace83 Put into the present ;-)
committer: mfx <mfx> 1031319643 +0000
2002-09-06 13:40:43 +00:00
Markus F.X.J. Oberhumer 44a6ac4c2a Minor editing.
committer: mfx <mfx> 1031319451 +0000
2002-09-06 13:37:31 +00:00
Markus F.X.J. Oberhumer 08826398af Fixed section names.
committer: mfx <mfx> 1030883709 +0000
2002-09-01 12:35:09 +00:00
Markus F.X.J. Oberhumer 5fccfc65ec Added some assertions.
committer: mfx <mfx> 1030883678 +0000
2002-09-01 12:34:38 +00:00
Markus F.X.J. Oberhumer 91d64a8871 Removed unupx.h.
committer: mfx <mfx> 1030786943 +0000
2002-08-31 09:42:23 +00:00
Markus F.X.J. Oberhumer b9e92ba9fa Cleanups.
committer: mfx <mfx> 1030605282 +0000
2002-08-29 07:14:42 +00:00
Markus F.X.J. Oberhumer d88078aa28 Added attribute_aligned.
committer: mfx <mfx> 1030604446 +0000
2002-08-29 07:00:46 +00:00
Markus F.X.J. Oberhumer 188b952621 The name of this format is "ps/exe".
committer: mfx <mfx> 1030604353 +0000
2002-08-29 06:59:13 +00:00
Markus F.X.J. Oberhumer 804a8bb853 Some ps/exe docs from Jens, somewhat edited by me.
committer: mfx <mfx> 1030604257 +0000
2002-08-29 06:57:37 +00:00
Markus F.X.J. Oberhumer ab229ac261 CVS test.
committer: mfx <mfx> 1028264330 +0000
2002-08-02 04:58:50 +00:00
Markus F.X.J. Oberhumer ff2bbb7a31 New version from Jens.
committer: mfx <mfx> 1028263994 +0000
2002-08-02 04:53:14 +00:00
Markus F.X.J. Oberhumer c8fb0994ed Removed unused variable.
committer: mfx <mfx> 1028139040 +0000
2002-07-31 18:10:40 +00:00
Markus F.X.J. Oberhumer fd13f41294 New version from Jens.
committer: mfx <mfx> 1028128175 +0000
2002-07-31 15:09:35 +00:00
Markus F.X.J. Oberhumer 4b15d30c2a Adapted for new asm5900-mfx4.
committer: mfx <mfx> 1027601835 +0000
2002-07-25 12:57:15 +00:00
Markus F.X.J. Oberhumer 076d862ee0 Fixed syntax error.
committer: mfx <mfx> 1027598532 +0000
2002-07-25 12:02:12 +00:00
Markus F.X.J. Oberhumer f7d66c8b50 Added a check for large file size.
committer: mfx <mfx> 1027598441 +0000
2002-07-25 12:00:41 +00:00
Markus F.X.J. Oberhumer 1ef25b356c Be quiet when using `-qqq'.
committer: mfx <mfx> 1027556040 +0000
2002-07-25 00:14:00 +00:00
Markus F.X.J. Oberhumer 7e06892ad7 Correctly set the exit code.
committer: mfx <mfx> 1027556018 +0000
2002-07-25 00:13:38 +00:00
John Reiser f1ccb85658 adapt to binutils-of-the-moment
committer: jreiser <jreiser> 1027548985 +0000
2002-07-24 22:16:25 +00:00
Markus F.X.J. Oberhumer a08b3ee882 Restored revision 1.10.
committer: mfx <mfx> 1027541786 +0000
2002-07-24 20:16:26 +00:00
Markus F.X.J. Oberhumer f0fafa3ba7 Temporarily commented out some code.
committer: mfx <mfx> 1027541308 +0000
2002-07-24 20:08:28 +00:00
Markus F.X.J. Oberhumer 9c1feb24e6 Added get_xxxx_signed() functions.
committer: mfx <mfx> 1027515231 +0000
2002-07-24 12:53:51 +00:00
Markus F.X.J. Oberhumer f4aa80e6b4 Big re-sync with UPX 1.2 branch.
committer: mfx <mfx> 1026839174 +0000
2002-07-16 17:06:14 +00:00
Markus F.X.J. Oberhumer 14d22d29b1 Big re-sync with UPX 1.2 branch.
committer: mfx <mfx> 1026836316 +0000
2002-07-16 16:18:36 +00:00
Markus F.X.J. Oberhumer 666e8c2f2f Big re-sync with UPX 1.2 branch.
committer: mfx <mfx> 1026835258 +0000
2002-07-16 16:00:58 +00:00
Markus F.X.J. Oberhumer 4a462f3c9a Updated.
committer: mfx <mfx> 1026820456 +0000
2002-07-16 11:54:16 +00:00
Markus F.X.J. Oberhumer 789cfea682 Checked in psx/exe patches from Jens.
committer: mfx <mfx> 1026820270 +0000
2002-07-16 11:51:10 +00:00
John Reiser ead8daf26c beware PT_LOAD.p_filesz==0
committer: jreiser <jreiser> 1009776680 +0000
2001-12-31 05:31:20 +00:00
John Reiser 2dfb82d5b9 Linux does not grow the stack below esp, so all accesses must be >= esp.
fold_elf86.asm fold_sh86.asm l_lx_sep86.asm

committer: jreiser <jreiser> 1006463120 +0000
2001-11-22 21:05:20 +00:00
John Reiser 83bcbb8299 internal calling sequences save 37 bytes (24 when compressed)
committer: jreiser <jreiser> 994972276 +0000
2001-07-12 21:11:16 +00:00
John Reiser d85f48fb97 save 2 bytes when compressed
committer: jreiser <jreiser> 994968843 +0000
2001-07-12 20:14:03 +00:00
John Reiser e4660b8608 need to search auxv for AT_PHDR
committer: jreiser <jreiser> 994946170 +0000
2001-07-12 13:56:10 +00:00
John Reiser 96141d82f4 Spend some bytes of code in stub to eliminate wasted stack space.
(Choose between this revision and previous, according to taste.)
	fold_elf86.asm l_lx_elf.c

committer: jreiser <jreiser> 994887023 +0000
2001-07-11 21:30:23 +00:00
John Reiser ef17dc10ca Fix Elf_auxv table. upx was duplicating AT_PHDR (and others)
because Linux 2.4.5 supplies many more AT_ entries than before.
First noticed by Sebastian <scut@nb.in-berlin.de>.
	fold_elf86.asm fold_sh86.asm l_lx_sep86.asm
	l_lx_elf.c     l_lx_sh.c     l_lx_sep.c

committer: jreiser <jreiser> 994871296 +0000
2001-07-11 17:08:16 +00:00
John Reiser caca5ffa12 keep zeroed stack as clean as possible (Sebastian <scut@nb.in-berlin.de>)
l_lx_sep86.asm fold_elf86.asm

committer: jreiser <jreiser> 994702928 +0000
2001-07-09 18:22:08 +00:00
Markus F.X.J. Oberhumer e08d3858be Upgraded to ELFkickers 2.0.
committer: mfx <mfx> 987374332 +0000
2001-04-15 22:38:52 +00:00
Markus F.X.J. Oberhumer 0e063b9759 Whitespace changes.
committer: mfx <mfx> 984629032 +0000
2001-03-15 04:03:52 +00:00
Markus F.X.J. Oberhumer 6dbdef9d57 Split some string constants to avoid possible RCS keyword expansions.
committer: mfx <mfx> 983457621 +0000
2001-03-01 14:40:21 +00:00
Markus F.X.J. Oberhumer 81c58d9727 New version.
committer: mfx <mfx> 983453010 +0000
2001-03-01 13:23:30 +00:00
Markus F.X.J. Oberhumer 54701e0c46 Updated.
committer: mfx <mfx> 983452964 +0000
2001-03-01 13:22:44 +00:00
Markus F.X.J. Oberhumer 069417499f Moved the Packer's filter handling into the new source file packerf.cpp.
committer: mfx <mfx> 983452951 +0000
2001-03-01 13:22:31 +00:00
Markus F.X.J. Oberhumer 5aec670621 Catch std::bad_alloc and print a better error message in this case.
committer: mfx <mfx> 983320394 +0000
2001-02-28 00:33:14 +00:00
Markus F.X.J. Oberhumer 16e9f168b9 Updated.
committer: mfx <mfx> 983320361 +0000
2001-02-28 00:32:41 +00:00
Markus F.X.J. Oberhumer 8897c3d4cb Added `const' to catched exception.
committer: mfx <mfx> 983114224 +0000
2001-02-25 15:17:04 +00:00
Markus F.X.J. Oberhumer 48a520708b New upstream version.
committer: mfx <mfx> 983109842 +0000
2001-02-25 14:04:02 +00:00
Markus F.X.J. Oberhumer 4a142f35f5 Renamed MemBuffer::free() to dealloc() in order to better support
malloc debugging libraries like mpatrol.

committer: mfx <mfx> 983109777 +0000
2001-02-25 14:02:57 +00:00
Markus F.X.J. Oberhumer a30bb7db20 Updated.
committer: mfx <mfx> 983109539 +0000
2001-02-25 13:58:59 +00:00
Markus F.X.J. Oberhumer 61842b4bcb Updated from UPX 1.07 release.
committer: mfx <mfx> 982688397 +0000
2001-02-20 16:59:57 +00:00
Markus F.X.J. Oberhumer 0cae01772c Updated from UPX 1.07 release.
committer: mfx <mfx> 982688016 +0000
2001-02-20 16:53:36 +00:00
Markus F.X.J. Oberhumer 6a95c11cf9 Updated from UPX 1.07 release.
committer: mfx <mfx> 982687495 +0000
2001-02-20 16:44:55 +00:00
Markus F.X.J. Oberhumer 401567f852 Removed the optional `off' parameter from the [gs]et_[bl]e{16,24,32} functions.
committer: mfx <mfx> 981982200 +0000
2001-02-12 12:50:00 +00:00
Markus F.X.J. Oberhumer 475326691d Added a call to verifyOverlappingDecompression().
committer: mfx <mfx> 981981688 +0000
2001-02-12 12:41:28 +00:00
John Reiser a63b02ab69 make "upx -d" decompression backward compatible to 8-byte b_info
p_lx_elf.h p_lx_elf.cpp p_unix.cpp

committer: jreiser <jreiser> 981752402 +0000
2001-02-09 21:00:02 +00:00
John Reiser 2ff824e631 get rid of PT_DYNAMIC: not worth the space; instead, use "upx -d" then ldd
p_lx_exc.h p_lx_elf.cpp p_lx_exc.cpp p_lx_sh.cpp
	stub/l_lx_elf.c stub/l_lx_elf86.lds stub/fold_elf86.asm

committer: jreiser <jreiser> 981747384 +0000
2001-02-09 19:36:24 +00:00
John Reiser e866b2231f move b_len from PackHeader to PackUnix
packer.h p_unix.h p_unix.cpp p_lx_elf.cpp p_lx_exc.cpp

committer: jreiser <jreiser> 981741734 +0000
2001-02-09 18:02:14 +00:00
Markus F.X.J. Oberhumer 451487ef80 Added an assertion.
committer: mfx <mfx> 981702739 +0000
2001-02-09 07:12:19 +00:00
Markus F.X.J. Oberhumer 4d64bd7e66 Added UPX_VERSION_STRING4, so that the size of the stubs is not affected
by versions like "x.yy.zz beta".

committer: mfx <mfx> 981702627 +0000
2001-02-09 07:10:27 +00:00
Markus F.X.J. Oberhumer 2e21de073d Updated.
committer: mfx <mfx> 981587564 +0000
2001-02-07 23:12:44 +00:00
Markus F.X.J. Oberhumer 8675f378b6 Small cleanups - no functional changes.
committer: mfx <mfx> 981586753 +0000
2001-02-07 22:59:13 +00:00
Markus F.X.J. Oberhumer 238a369948 Cleanups.
committer: mfx <mfx> 981586521 +0000
2001-02-07 22:55:21 +00:00
Markus F.X.J. Oberhumer 7db6c25c6a Updated.
committer: mfx <mfx> 981586509 +0000
2001-02-07 22:55:09 +00:00
Markus F.X.J. Oberhumer bcbc59f04e Updated some comments.
committer: mfx <mfx> 981586421 +0000
2001-02-07 22:53:41 +00:00
Markus F.X.J. Oberhumer 1f1f03eaf4 Removed trailing whitespace.
committer: mfx <mfx> 981586094 +0000
2001-02-07 22:48:14 +00:00
Markus F.X.J. Oberhumer c9a1173698 Detabified.
committer: mfx <mfx> 981585982 +0000
2001-02-07 22:46:22 +00:00
Markus F.X.J. Oberhumer 3ba4cd5919 Avoid a compiler warning.
committer: mfx <mfx> 981585719 +0000
2001-02-07 22:41:59 +00:00
Markus F.X.J. Oberhumer 2c9f6b28f7 Added some constants and options for win32/pe resource types.
committer: mfx <mfx> 981585673 +0000
2001-02-07 22:41:13 +00:00
László Molnár 79aff4c12d Corrected tls callback handling.
Fixed a rare bug in relocation handling.
Filters need an addvalue for this format.
Experimental fix for SizeOfHeaders > 0x1000.
Check for superfluous data between sections.

committer: ml1050 <ml1050> 981241024 +0000
2001-02-03 22:57:04 +00:00
John Reiser 40fddf1715 Put upx stub loader at high end of ELF output file on linux,
and allow for block-by-block specification of filter and parameters.
	linker.cpp linker.h mem.cpp mem.h p_elf.h
	p_lx_elf.cpp p_lx_elf.h
	p_lx_exc.cpp p_lx_exc.h
	p_lx_sh.cpp  p_lx_sh.h
	p_unix.cpp p_unix.h
	packer.cpp packer.h
	stub/fold_elf86.asm stub/fold_exec86.asm stub/fold_sh86.asm
	stub/l_lx_elf.c  stub/l_lx_elf86.asm  stub/l_lx_elf86.lds
	stub/l_lx_exec.c stub/l_lx_exec86.asm stub/l_lx_exec86.lds
	stub/l_lx_sh.c   stub/l_lx_sh86.asm   stub/l_lx_sh86.lds
	stub/linux.hh

committer: jreiser <jreiser> 981084316 +0000
2001-02-02 03:25:16 +00:00
Markus F.X.J. Oberhumer 9005e50049 Check upx_adler32() arguments.
committer: mfx <mfx> 980888983 +0000
2001-01-30 21:09:43 +00:00
Markus F.X.J. Oberhumer dc7493e283 Use the overloaded upx_adler32() function.
committer: mfx <mfx> 980851465 +0000
2001-01-30 10:44:25 +00:00
Markus F.X.J. Oberhumer 8f65fc1ab7 Changed an error message.
committer: mfx <mfx> 980616295 +0000
2001-01-27 17:24:55 +00:00
Markus F.X.J. Oberhumer 3d732625a7 Cleanups.
committer: mfx <mfx> 980615091 +0000
2001-01-27 17:04:51 +00:00
Markus F.X.J. Oberhumer 5f678d10cb Some DOS updates.
committer: mfx <mfx> 980615078 +0000
2001-01-27 17:04:38 +00:00
Markus F.X.J. Oberhumer 2a55ac04ce Disable TLS callback check for now.
committer: mfx <mfx> 980615053 +0000
2001-01-27 17:04:13 +00:00
Markus F.X.J. Oberhumer 2feb5a47ac Decrease decompressor stack size a little bit.
committer: mfx <mfx> 980615022 +0000
2001-01-27 17:03:42 +00:00
Markus F.X.J. Oberhumer 27deeccdb3 Updated from 1.06 release.
committer: mfx <mfx> 980614997 +0000
2001-01-27 17:03:17 +00:00
Markus F.X.J. Oberhumer c7f12f3a74 Compute an adler32 checksum.
committer: mfx <mfx> 980609412 +0000
2001-01-27 15:30:12 +00:00
Markus F.X.J. Oberhumer 99f0f0120b Updated.
committer: mfx <mfx> 980609373 +0000
2001-01-27 15:29:33 +00:00
Markus F.X.J. Oberhumer 34070f0b93 Make fn_has_ext() case insensitive by default.
committer: mfx <mfx> 980609337 +0000
2001-01-27 15:28:57 +00:00
Markus F.X.J. Oberhumer f300b31d8d Un-documented `--stdout' option.
committer: mfx <mfx> 980606702 +0000
2001-01-27 14:45:02 +00:00
Markus F.X.J. Oberhumer bc5f9fb0a3 Don't allow `--stdout' when compressing.
committer: mfx <mfx> 980433841 +0000
2001-01-25 14:44:01 +00:00
Markus F.X.J. Oberhumer 7371c219b1 Updated from 1.05 release.
committer: mfx <mfx> 980367939 +0000
2001-01-24 20:25:39 +00:00
László Molnár d5dd445a06 refuse compressing files which have tls callbacks
committer: ml1050 <ml1050> 980113870 +0000
2001-01-21 21:51:10 +00:00
Markus F.X.J. Oberhumer b7f0187e9c Added a define to use the UPX 1.02 "blessed" stub code to avoid
problems with braindead virus scanners...

committer: mfx <mfx> 979849303 +0000
2001-01-18 20:21:43 +00:00
Markus F.X.J. Oberhumer e982426885 Made upx_adler32() an overloaded function.
committer: mfx <mfx> 979849112 +0000
2001-01-18 20:18:32 +00:00
Markus F.X.J. Oberhumer 6447666284 Support VPATH builds.
committer: mfx <mfx> 979834754 +0000
2001-01-18 16:19:14 +00:00
Markus F.X.J. Oberhumer ea4fcebf33 Made tell() const.
committer: mfx <mfx> 979831609 +0000
2001-01-18 15:26:49 +00:00
Markus F.X.J. Oberhumer 94f7d49522 Make the stubs compile again.
committer: mfx <mfx> 979829197 +0000
2001-01-18 14:46:37 +00:00
Markus F.X.J. Oberhumer bbf2938719 Avoid an app.pl warning.
committer: mfx <mfx> 979828878 +0000
2001-01-18 14:41:18 +00:00
John Reiser df9db96bd1 filters for unix(linux)
Modified Files:
	filteri.cpp filter/ctojr.h linker.cpp linker.h mem.cpp mem.h
	p_lx_elf.cpp p_lx_elf.h
	p_lx_exc.cpp p_lx_exc.h
	p_lx_sh.cpp  p_lx_sh.h
	p_unix.cpp packer.cpp packer.h packhead.cpp
	stub/Makefile    stub/macros.ash
	stub/l_lx_elf.c  stub/l_lx_elf86.asm  stub/l_lx_elf86.lds
	stub/l_lx_exec.c stub/l_lx_exec86.asm stub/l_lx_exec86.lds
	                 stub/l_lx_sh86.asm   stub/l_lx_sh86.lds
Added Files:
	filter/ctok.h
	stub/fold_elf86.asm stub/fold_exec86.asm stub/fold_sh86.asm

committer: jreiser <jreiser> 979796725 +0000
2001-01-18 05:45:25 +00:00
Markus F.X.J. Oberhumer 4d45677160 Updated.
committer: mfx <mfx> 979756847 +0000
2001-01-17 18:40:47 +00:00
Markus F.X.J. Oberhumer 2981596fc3 Clarified a comment.
committer: mfx <mfx> 979756736 +0000
2001-01-17 18:38:56 +00:00
Markus F.X.J. Oberhumer ecce4d6578 Reset patch order in writePackHeader().
committer: mfx <mfx> 979756690 +0000
2001-01-17 18:38:10 +00:00
Markus F.X.J. Oberhumer bf52b5eb06 Small PackHeader update.
committer: mfx <mfx> 979756656 +0000
2001-01-17 18:37:36 +00:00
Markus F.X.J. Oberhumer d8baf6d1e8 Added PackUnix::writePackHeader().
committer: mfx <mfx> 979754833 +0000
2001-01-17 18:07:13 +00:00
Markus F.X.J. Oberhumer 4322931d97 Added UPX_MAGIC2_LE32 as an additional magic number for the original
packheader as stored in the stubs.

committer: mfx <mfx> 979754722 +0000
2001-01-17 18:05:22 +00:00
Markus F.X.J. Oberhumer ad4bf703f0 Added some comments.
committer: mfx <mfx> 979748824 +0000
2001-01-17 16:27:04 +00:00
Markus F.X.J. Oberhumer 342679b6d3 Small cleanups.
committer: mfx <mfx> 979748793 +0000
2001-01-17 16:26:33 +00:00
Markus F.X.J. Oberhumer 4a52be76fe Removed nop() macro.
committer: mfx <mfx> 979746778 +0000
2001-01-17 15:52:58 +00:00
Markus F.X.J. Oberhumer afc55d76e7 New version of the UNUSED() macro.
committer: mfx <mfx> 979744725 +0000
2001-01-17 15:18:45 +00:00
Markus F.X.J. Oberhumer 9e53f19b02 New upstream version.
committer: mfx <mfx> 979654847 +0000
2001-01-16 14:20:47 +00:00
Markus F.X.J. Oberhumer 8614bca405 Updated.
committer: mfx <mfx> 979237786 +0000
2001-01-11 18:29:46 +00:00
Markus F.X.J. Oberhumer 5f3bdaeebe Support VPATH builds.
committer: mfx <mfx> 979143860 +0000
2001-01-10 16:24:20 +00:00
Markus F.X.J. Oberhumer fd81cd2ae0 Support VPATH builds.
committer: mfx <mfx> 979143221 +0000
2001-01-10 16:13:41 +00:00
Markus F.X.J. Oberhumer bc6599ae51 Added a simple delta filter.
committer: mfx <mfx> 978980129 +0000
2001-01-08 18:55:29 +00:00
Markus F.X.J. Oberhumer 6c2c174926 Added a simple delta filter.
committer: mfx <mfx> 978979757 +0000
2001-01-08 18:49:17 +00:00
Markus F.X.J. Oberhumer 9205d0be65 New version.
committer: mfx <mfx> 978973564 +0000
2001-01-08 17:06:04 +00:00
Markus F.X.J. Oberhumer 199e274cac Added a simple delta filter.
committer: mfx <mfx> 978973515 +0000
2001-01-08 17:05:15 +00:00
John Reiser c9a36d51c4 refine pseudo-sections
committer: jreiser <jreiser> 978901287 +0000
2001-01-07 21:01:27 +00:00
John Reiser 7bffc86777 prepare for selective buildLoader
committer: jreiser <jreiser> 978897024 +0000
2001-01-07 19:50:24 +00:00
John Reiser ce1b58d293 filters for linux/elf386;
filter.cpp filter.h p_lx_elf.cpp p_lx_elf.h filter/ctojr.h
	stub/l_lx_elf.c stub/l_lx_elf86.asm

committer: jreiser <jreiser> 978846586 +0000
2001-01-07 05:49:46 +00:00
John Reiser 4d2b35c9ee debugging
committer: jreiser <jreiser> 978826747 +0000
2001-01-07 00:19:07 +00:00
Markus F.X.J. Oberhumer 47168972da Added class BeLinker.
committer: mfx <mfx> 978797683 +0000
2001-01-06 16:14:43 +00:00
Markus F.X.J. Oberhumer dee289e2d9 Comments updated.
committer: mfx <mfx> 978795901 +0000
2001-01-06 15:45:01 +00:00
Markus F.X.J. Oberhumer 1fc7c7898b Updated.
committer: mfx <mfx> 978795803 +0000
2001-01-06 15:43:23 +00:00
Markus F.X.J. Oberhumer dfc8a0d548 Renamed ctjo to ctoj, and ctjor to ctojr.
committer: mfx <mfx> 978792885 +0000
2001-01-06 14:54:45 +00:00
Markus F.X.J. Oberhumer daa0fe353b Added util function getcto().
committer: mfx <mfx> 978792675 +0000
2001-01-06 14:51:15 +00:00
John Reiser 766b3edeee Avoid static storage. Also keep as many destinations as possible,
and keep them together on the wheel during "cold cache" startup.

committer: jreiser <jreiser> 978729012 +0000
2001-01-05 21:10:12 +00:00
Markus F.X.J. Oberhumer 8e90fd0b63 Updated.
committer: mfx <mfx> 978721813 +0000
2001-01-05 19:10:13 +00:00
Markus F.X.J. Oberhumer 9a00a9027d Cleanups.
committer: mfx <mfx> 978706067 +0000
2001-01-05 14:47:47 +00:00
Markus F.X.J. Oberhumer e2a45c8f97 Added static bool Filter::isValidFilter(int).
committer: mfx <mfx> 978705885 +0000
2001-01-05 14:44:45 +00:00
Markus F.X.J. Oberhumer ee69861fb5 Added some comments.
committer: mfx <mfx> 978705469 +0000
2001-01-05 14:37:49 +00:00
John Reiser 5b97d3ee09 Filter for lru recoding of "call trick" destinations.
filteri.cpp filter/ctjor.h

committer: jreiser <jreiser> 978670287 +0000
2001-01-05 04:51:27 +00:00
Markus F.X.J. Oberhumer 38ab492030 Added preliminary unpacking support.
committer: mfx <mfx> 978638046 +0000
2001-01-04 19:54:06 +00:00
Markus F.X.J. Oberhumer 266d992017 Cleanups.
committer: mfx <mfx> 978636047 +0000
2001-01-04 19:20:47 +00:00
Markus F.X.J. Oberhumer 0979848bdc Added experimental app_68k.pl.
committer: mfx <mfx> 978635857 +0000
2001-01-04 19:17:37 +00:00
Markus F.X.J. Oberhumer 3d371be0e5 Updated.
committer: mfx <mfx> 978626197 +0000
2001-01-04 16:36:37 +00:00
Markus F.X.J. Oberhumer f96955b9f0 Updated my email address.
committer: mfx <mfx> 978625825 +0000
2001-01-04 16:30:25 +00:00
Markus F.X.J. Oberhumer 794d048bf2 Moved the actual filter implementations into the new filter directory.
committer: mfx <mfx> 978622245 +0000
2001-01-04 15:30:45 +00:00
Markus F.X.J. Oberhumer 595afd8964 Updated.
committer: mfx <mfx> 978564648 +0000
2001-01-03 23:30:48 +00:00
Markus F.X.J. Oberhumer da8fadb203 Updated.
committer: mfx <mfx> 978563845 +0000
2001-01-03 23:17:25 +00:00
Markus F.X.J. Oberhumer ca7c07e817 Added some debug print statements.
committer: mfx <mfx> 978563773 +0000
2001-01-03 23:16:13 +00:00
Markus F.X.J. Oberhumer bf95f93cad Added a number of filters. Some of them could be useful for dos/exe.
committer: mfx <mfx> 978563749 +0000
2001-01-03 23:15:49 +00:00
Markus F.X.J. Oberhumer 7766b08f08 Cleanups.
committer: mfx <mfx> 978563615 +0000
2001-01-03 23:13:35 +00:00
Markus F.X.J. Oberhumer 823ac11eb3 Added option `--no-filter'.
committer: mfx <mfx> 978559146 +0000
2001-01-03 21:59:06 +00:00
Markus F.X.J. Oberhumer c5e61413a4 Small cleanups.
committer: mfx <mfx> 978539758 +0000
2001-01-03 16:35:58 +00:00
Markus F.X.J. Oberhumer df4726eb95 Removed Packer::addSection().
committer: mfx <mfx> 978539327 +0000
2001-01-03 16:28:47 +00:00
Markus F.X.J. Oberhumer 25a6da5638 dos/com and dos/sys: only add the `sbb bp,bp' section to the stub
if it is needed.

committer: mfx <mfx> 978538864 +0000
2001-01-03 16:21:04 +00:00
Markus F.X.J. Oberhumer 5ddec963d0 Better kernel decompression.
committer: mfx <mfx> 978531885 +0000
2001-01-03 14:24:45 +00:00
Markus F.X.J. Oberhumer 597143df7f Added some more header checks.
committer: mfx <mfx> 978531825 +0000
2001-01-03 14:23:45 +00:00
Markus F.X.J. Oberhumer 572082ac2b Implemented Packer::verifyOverlappingDecompression().
committer: mfx <mfx> 978465508 +0000
2001-01-02 19:58:28 +00:00
Markus F.X.J. Oberhumer d328e834b1 Documentation updates.
committer: mfx <mfx> 978450814 +0000
2001-01-02 15:53:34 +00:00
Markus F.X.J. Oberhumer aa540f85fa Big merge of my working tree: Added options `--all-methods', new
Packer::getCompressionMethods(), improved Packer::compressWithFilters().

committer: mfx <mfx> 978449945 +0000
2001-01-02 15:39:05 +00:00
Markus F.X.J. Oberhumer 1084d86063 Some more cleanups.
committer: mfx <mfx> 978191791 +0000
2000-12-30 15:56:31 +00:00
Markus F.X.J. Oberhumer a43d93512d Updated.
committer: mfx <mfx> 978190991 +0000
2000-12-30 15:43:11 +00:00
Markus F.X.J. Oberhumer a8177201ef Added new field PackHeader::overlap_overhead.
committer: mfx <mfx> 978190533 +0000
2000-12-30 15:35:33 +00:00
Markus F.X.J. Oberhumer 85bebf0b43 Major rewrite: added buildLoader() and fillExeHeader().
committer: mfx <mfx> 978189850 +0000
2000-12-30 15:24:10 +00:00
Markus F.X.J. Oberhumer f36feee0dc Added a framework for the win16/ne format, so that it's easier for someone
to actually contribute that.

committer: mfx <mfx> 978183080 +0000
2000-12-30 13:31:20 +00:00
Markus F.X.J. Oberhumer c0bbc2216e Always call buildLoader() directly after compress().
committer: mfx <mfx> 978181874 +0000
2000-12-30 13:11:14 +00:00
Markus F.X.J. Oberhumer 8ce23f15e8 Updated.
committer: mfx <mfx> 978180979 +0000
2000-12-30 12:56:19 +00:00
Markus F.X.J. Oberhumer 0b01be7b29 Consistency cleanups.
committer: mfx <mfx> 978180862 +0000
2000-12-30 12:54:22 +00:00
Markus F.X.J. Oberhumer ceebd3518b Implemented buildLoader(), so that we can add compressWithFilters().
committer: mfx <mfx> 978180698 +0000
2000-12-30 12:51:38 +00:00
Markus F.X.J. Oberhumer a9249c6335 Implemented compressWithFilters().
committer: mfx <mfx> 978180632 +0000
2000-12-30 12:50:32 +00:00
Markus F.X.J. Oberhumer dc22e6f158 Changed a comment.
committer: mfx <mfx> 978108487 +0000
2000-12-29 16:48:07 +00:00
Markus F.X.J. Oberhumer 1c7a34b367 Updated.
committer: mfx <mfx> 978108464 +0000
2000-12-29 16:47:44 +00:00
Markus F.X.J. Oberhumer 526ae77b08 Whitespace changes.
committer: mfx <mfx> 978108441 +0000
2000-12-29 16:47:21 +00:00
Markus F.X.J. Oberhumer 82698fb4b0 Enabled compressWithFilters(). Added some assertions.
committer: mfx <mfx> 978108380 +0000
2000-12-29 16:46:20 +00:00
Markus F.X.J. Oberhumer 63ead04054 Documented `--all-filters'.
committer: mfx <mfx> 978108298 +0000
2000-12-29 16:44:58 +00:00
Markus F.X.J. Oberhumer 5727461522 Updated.
committer: mfx <mfx> 978101535 +0000
2000-12-29 14:52:15 +00:00
Markus F.X.J. Oberhumer cd4292dd55 Completely updated the TODO list.
committer: mfx <mfx> 978101036 +0000
2000-12-29 14:43:56 +00:00
Markus F.X.J. Oberhumer 11ee8627b8 Improved some ELF header checks.
committer: mfx <mfx> 978099239 +0000
2000-12-29 14:13:59 +00:00
Markus F.X.J. Oberhumer 65ad79d727 Updated.
committer: mfx <mfx> 978093031 +0000
2000-12-29 12:30:31 +00:00
Markus F.X.J. Oberhumer 85920ea8b1 Use the new macro COMPILE_TIME_ASSERT() instead of several assert().
committer: mfx <mfx> 978092937 +0000
2000-12-29 12:28:57 +00:00
Markus F.X.J. Oberhumer f4d2287e57 Added some experimental test code.
committer: mfx <mfx> 978092868 +0000
2000-12-29 12:27:48 +00:00
Markus F.X.J. Oberhumer 8a77a477df Do not use the screen code when running under Windows NT.
committer: mfx <mfx> 978092789 +0000
2000-12-29 12:26:29 +00:00
Markus F.X.J. Oberhumer 5a497e2dac Added a framework for the elks/8086 format. Completely non-functional at the moment.
committer: mfx <mfx> 978092698 +0000
2000-12-29 12:24:58 +00:00
Markus F.X.J. Oberhumer 7d5042012b Avoid a compiler warning.
committer: mfx <mfx> 978092515 +0000
2000-12-29 12:21:55 +00:00
Markus F.X.J. Oberhumer d2625d8607 *** empty log message ***
committer: mfx <mfx> 977924664 +0000
2000-12-27 13:44:24 +00:00
Markus F.X.J. Oberhumer c3ec6b73e5 Use UPX_MAGIC_LE32 instead of PackHeader::magic.
committer: mfx <mfx> 977922670 +0000
2000-12-27 13:11:10 +00:00
Markus F.X.J. Oberhumer 0ffe40c621 Updated.
committer: mfx <mfx> 977489915 +0000
2000-12-22 12:58:35 +00:00
Markus F.X.J. Oberhumer 537f9111ae Documented `--force-execve'.
committer: mfx <mfx> 977488831 +0000
2000-12-22 12:40:31 +00:00
Markus F.X.J. Oberhumer d168d85650 Some ELF related cleanups.
committer: mfx <mfx> 977488389 +0000
2000-12-22 12:33:09 +00:00
Markus F.X.J. Oberhumer dbbc47a334 Added option `--force-execve' which forces the use of the generic
linux/386 format.

committer: mfx <mfx> 977486503 +0000
2000-12-22 12:01:43 +00:00
Markus F.X.J. Oberhumer 47760c37fc Updated.
committer: mfx <mfx> 977431602 +0000
2000-12-21 20:46:42 +00:00
Markus F.X.J. Oberhumer 9fc785199a Only #include "version.h" in files that actually need it.
committer: mfx <mfx> 977430123 +0000
2000-12-21 20:22:03 +00:00
Markus F.X.J. Oberhumer f4f70634a1 Made PackHeader::magic a constant.
committer: mfx <mfx> 977428640 +0000
2000-12-21 19:57:20 +00:00
Markus F.X.J. Oberhumer 046df6da76 Added Packer::checkAlreadyPacked().
committer: mfx <mfx> 977427988 +0000
2000-12-21 19:46:28 +00:00
Markus F.X.J. Oberhumer facca7b891 Added test for alreadyPacked().
committer: mfx <mfx> 977426670 +0000
2000-12-21 19:24:30 +00:00
Markus F.X.J. Oberhumer a254e81ba9 Oops.
committer: mfx <mfx> 977426094 +0000
2000-12-21 19:14:54 +00:00
Markus F.X.J. Oberhumer 09eb201b76 *** empty log message ***
committer: mfx <mfx> 977425661 +0000
2000-12-21 19:07:41 +00:00
Markus F.X.J. Oberhumer b0226b54bd Finally we use automated dependencies.
committer: mfx <mfx> 977424557 +0000
2000-12-21 18:49:17 +00:00
Markus F.X.J. Oberhumer 1d948c839d Moved the generic linux/386 format into the new p_lx_exc.{h,cpp} files.
committer: mfx <mfx> 977423460 +0000
2000-12-21 18:31:00 +00:00
Markus F.X.J. Oberhumer 5d74b7252d Cleaned up the use of upx_compress(), use delete[] where needed.
committer: mfx <mfx> 977422374 +0000
2000-12-21 18:12:54 +00:00
Markus F.X.J. Oberhumer e787805b81 Extended gzip signature to 3 bytes.
committer: mfx <mfx> 977403238 +0000
2000-12-21 12:53:58 +00:00
Markus F.X.J. Oberhumer 166d91ac48 Added some assertions.
committer: mfx <mfx> 977395014 +0000
2000-12-21 10:36:54 +00:00
Markus F.X.J. Oberhumer 2bb2124356 readFileHeader() now returns 0 on error.
committer: mfx <mfx> 977394998 +0000
2000-12-21 10:36:38 +00:00
Markus F.X.J. Oberhumer 29ae1b7231 Updated.
committer: mfx <mfx> 977393157 +0000
2000-12-21 10:05:57 +00:00
Markus F.X.J. Oberhumer 06dc67da49 Added some more checks to canPack(), throw an exception in case
of crippled ELF headers.

committer: mfx <mfx> 977393134 +0000
2000-12-21 10:05:34 +00:00
Markus F.X.J. Oberhumer 42fe803a39 Cleaned up some canPack() checks.
committer: mfx <mfx> 977393067 +0000
2000-12-21 10:04:27 +00:00
John Reiser 1dcaedab30 sys_size is only 16 bits and can wrap around
committer: jreiser <jreiser> 977374512 +0000
2000-12-21 04:55:12 +00:00
251 changed files with 42454 additions and 9682 deletions
+12 -4
View File
@@ -1,5 +1,13 @@
.cvsignore
.mfxcvsup
ChangeLog.cvs*
build
.bzr*
.darcs*
.git*
.hg*
_darcs
B
build*
doxygen
maint
ChangeLog.cvs*
GNUmakefile
MMakefile
TODO.*
+2 -3
View File
@@ -8,9 +8,8 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
http://upx.tsx.org
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
Limitations and other things which are not (yet) supported:
+27 -11
View File
@@ -1,11 +1,18 @@
# Toplevel Makefile for UPX
all:
$(MAKE) -C src/stub
$(MAKE) -C src
$(MAKE) -C doc
MAKEFLAGS += -rR
.SUFFIXES:
export SHELL = /bin/sh
mostlyclean clean distclean maintainer-clean:
srcdir = .
top_srcdir = .
default:
@echo "UPX info: please choose a target for 'make'"
all mostlyclean clean distclean maintainer-clean:
$(MAKE) -C src/stub/util/sstrip $@
$(MAKE) -C src/stub $@
$(MAKE) -C src $@
$(MAKE) -C doc $@
@@ -13,15 +20,24 @@ mostlyclean clean distclean maintainer-clean:
dist: distclean
false
ifneq ($(wildcard CVS/R*),)
CVS_ROOT := $(shell cat CVS/Root)
CVS_REPO := $(shell cat CVS/Repository)
endif
cvs-info:
@echo 'CVS info: $(CVS_ROOT) $(CVS_REPO)'
cvs-admin-ko:
cvs admin -ko .
cvs update
cvs -q -z6 update -P -d
# automatically generate ChangeLog from CVS
ChangeLog ChangeLog.cvs:
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
ChangeLog:
perl scripts/cvs2cl.pl --utc -f ChangeLog.cvs
.PHONY: all mostlyclean clean distclean maintainer-clean
.PHONY: dist cvs-admin-ko ChangeLog
.NOEXPORT:
.PHONY: dist cvs-info cvs-admin-ko ChangeLog ChangeLog.cvs
+119 -4
View File
@@ -2,14 +2,129 @@
User visible changes for UPX
==================================================================
[ UNSTABLE BETA VERSION - please see README.1ST for some more info ]
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
* new format: added support for mach/ppc32 (Apple Mac OS X)
* win32/pe: hopefully working "load config" support
* win32/pe: R6002 runtime errors worked around
* win32/pe: the stub now clears the dirty stack
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: 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
Changes in 1.91 beta (30 Jun 2004):
* djgpp2/coff: added support for recent binutils versions
* linux/elf386, linux/sh386: lots of improvements
* 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'.
* source code: much improved portability using ACC, the
Automatic Compiler Configuration
* source code: compile fixes for strict ISO C++ compilers
* source code: compile fixes for Win64
* re-synced with upx 1.25 branch
Changes in 1.90 beta (11 Nov 2002):
* implemented several new options for finer compression control:
`--all-methods', `--all-filters' and `--brute'
* ps1/exe: new format - UPX now supports PlayStation One programs
* linux/386: added the option `--force-execve'
* vmlinuz/386: better kernel detection and sanity checks
* re-synced with upx 1.24 branch
* documentation updates
Changes in 1.11 beta (20 Dec 2000):
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING!!! REALLY.
* vmlinuz/386: new format - UPX now supports bootable linux kernels
* linux/386: added the new direct-to-memory executable formats - no
* linux/elf386: added the new ELF direct-to-memory executable format - no
more temp files are needed for decompression!
* linux/sh386: added the new shell direct-to-memory executable format - no
more temp files are needed for decompression!
* reduced overall memory requirements during packing
* quite a number of internal source code rearrangements
==================================================================
Changes in 1.25 (29 Jun 2004)
* INFO: http://upx.sourceforge.net is the permanent UPX home page
* watcom/le: don't crash on files without relocations
* win32/pe: stricter checks of some PE values
* source code: much improved portability using ACC, the
Automatic Compiler Configuration
* source code: compile fixes for strict ISO C++ compilers
* source code: compile fixes for Win64
Changes in 1.24 (07 Nov 2002)
* djgpp2/coff: stricter check of the COFF header to work around a
problem with certain binutils versions
Changes in 1.23 (05 Sep 2002)
* atari/tos: fixed an unpacking problem where a buffer was too
small (introduced in 1.22)
* linux/386: don't give up too early if a single block turns out
to be incompressible
* documentation: added some quick tips how to achieve the best
compression ratio for the final release of your application
* fixed a rare situation where the exit code was not set correctly
Changes in 1.22 (27 Jun 2002)
* atari/tos: the stub now flushes the CPU cache to avoid
problems on 68030+ machines
* source code: additional compiler support for Borland C++,
Digital Mars C++ and Watcom C++
Changes in 1.21 (01 Jun 2002)
* 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.
* source code: portability fixes
* source code: compile fixes for g++ 3.0 and g++ 3.1
Changes in 1.20 (23 May 2001)
* slightly faster compression
* work around a gcc problem in the latest djgpp2 distribution
* watcom/le: fixed detection of already compressed files
* win32/pe: do not compress RT_MANIFEST resource types
* win32/pe: improved the error message for empty resource sections
* [NOTE: the jump from 1.08 to 1.20 is to avoid confusion with
our unstable development releases 1.1x and 1.9x]
Changes in 1.08 (30 Apr 2001)
* new native port to atari/tos
* win32/pe: shortened the identstring
* source code: portability fixes - UPX now builds cleanly under m68k CPUs
Changes in 1.07 (20 Feb 2001)
* win32/pe: corrected the TLS callback check
* win32/pe: really fixed that rare bug in relocation handling
* win32/pe: experimental support for SizeOfHeaders > 0x1000
* win32/pe: check for superfluous data between sections
* win32/pe: compressing screensavers (.scr) should finally work
Changes in 1.06 (27 Jan 2001)
* win32/pe: the check for TLS callbacks introduced in 1.05
was too strict - disabled for now
* dos/com: decreased the decompressor stack size a little bit
Changes in 1.05 (24 Jan 2001)
* win32/pe: refuse to compress programs with TLS callbacks
* win32/pe: stub changes to avoid slowdowns with some virus monitors
* win32/pe: reverted the relocation handling changes in 1.04
* linux/386: dont try to compress Linux kernel images (have a look
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'
* win32/pe: fixed a rare bug in the relocation handling code
@@ -188,7 +303,7 @@ Changes in 0.60 (06 Mar 1999)
* fixed a bug which could make UPX hang when an exe header contained
an illegal value
* added some compression flags for the win32/pe format
* added support for Atari ST executables (atari/tos)
* added support for Atari ST/TT executables (atari/tos)
* improved compression ratio
* improved compression speed
@@ -206,7 +321,7 @@ Changes in 0.40 (05 Oct 1998)
* fixed a small but fatal bug in dos/sys introduced in 0.30
* fixed a rare bug in dos/exe
* worked around a bug in djgpp's strip 2.8
* Allegro packfile support should work now
* djgpp/coff: Allegro packfile support should work now
* added dos/exeh compression method (works on 386+)
Changes in 0.30 (27 Jul 1998)
+17 -14
View File
@@ -8,9 +8,8 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
http://upx.tsx.org
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
Here are some possible projects from which you can choose if you'd like to
@@ -31,8 +30,17 @@ User interface:
More formats:
-------------
- add more file formats / platforms (there were volunteers for FreeBSD,
BeOS, Windows CE, Amiga, C64, ...)
- Amiga
- BeOS
- C64
- elks/8086 (this is a 16-bit linux-8086 kernel)
See http://www.elks.ecs.soton.ac.uk/
- freebsd/386 (generic), freebsd/elf386 (specialized).
Probably could share most of the linux code.
- add support for self-extracting HTML pages using a Javascript stub
(like the AlgART HTML Packer "AHP")
@@ -41,23 +49,20 @@ More formats:
Existing formats:
-----------------
- dos/com: add support for very long files - convert to exe if necessary
- djgpp2/coff: add support for DLX dynamic loading
(see SEAL http://www.home.sk/public/seal/ )
- dos/sys: add support for sys/exe combos
- dos/com: add support for very long files - convert to exe if necessary
- dos/exe: implement filter support
- djgpp2/coff: add support for DLX dynamic loading
(see SEAL http://www.home.sk/public/seal/ )
- dos/sys: add support for sys/exe combos
- linux/i386:
- use the new assembly preprocessor stuff (ie. process the file
headers internally)
- UPX uncompressor daemon
- rewrite the stub in assembly (not sure if this is a good idea...)
- etc...
- linux/i386: add a special elf/i386 format that understands
ELF files and has filter support
- watcom/le: add support for per section compression, LX support, VXD
@@ -65,8 +70,6 @@ Existing formats:
of problems (like importing a DLL or function fails)
- win32/pe: finer control over resource compression, per section
compression
- win32/pe: compressing screensavers looses the description - probably
should not compress a special resource type
Compression ratio:
+28 -21
View File
@@ -8,34 +8,42 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
http://upx.tsx.org
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
WARNING - UNSTABLE BETA VERSION
===============================
All versions 1.1x are unstable beta releases - use them only for testing,
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.04, and the next stable release
will be called version 1.20.
The current stable release is 1.25, and the next stable release
will be called version 2.00.
The main news since 1.04 are support for bootable Linux kernels ("vmlinuz/386")
and direct Linux ELF-to-memory decompression ("linux/elf386"), so there's
no reason to use the unstable versions unless you want to try the new formats.
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
=======
Welcome to UPX 1.0x, the first production release after almost two years
of beta testing.
Welcome to UPX !
Please don't forget to read the new LICENSE - UPX is now distributed
Please don't forget to read the file LICENSE - UPX is distributed
under the GNU General Public License (GPL) with special exceptions
allowing the distribution of all compressed executables, including
commercial programs.
@@ -54,8 +62,8 @@ 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
Win95/98/ME/NT/2000 programs and DLLs, DOS programs, and Linux
executables and kernels.
Windows 95/98/ME/NT/2000/XP programs and DLLs, DOS programs,
and Linux executables and kernels.
UPX is free software distributed under the term of the GNU General
Public License. Full source code is available.
@@ -64,7 +72,7 @@ UPX may be distributed and used freely, even with commercial applications.
See the UPX License Agreement for details.
UPX is rated number one in the well known Archive Comparison Test. Visit
http://web.act.by.net/~act/act-exepack.html
http://compression.ca/ .
UPX aims to be Commercial Quality Freeware.
@@ -87,7 +95,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 almost 2 years since our first public beta.
actually it's more than 4 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.
@@ -114,8 +122,7 @@ THE FUTURE
This only gives people a false feeling of security because
by definition all protectors/compressors can be broken.
And don't trust any advertisment of authors of other executable
compressors about this topic - just do a websearch on something
like "procdump"...
compressors about this topic - just do a websearch on "unpackers"...
- Fix all remaining bugs - keep your reports coming ;-)
@@ -126,8 +133,8 @@ THE FUTURE
COPYRIGHT
=========
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
This program may be used freely, and you are welcome to
redistribute it under certain conditions.
@@ -146,7 +153,7 @@ Markus & Laszlo
Markus F.X.J. Oberhumer Laszlo Molnar
markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
markus@oberhumer.com ml1050@users.sourceforge.net
+18 -8
View File
@@ -8,21 +8,31 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
WARNING - UNSTABLE BETA VERSION
===============================
All versions 1.1x are unstable beta releases - use them only for testing,
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.04, and the next stable release
will be called version 1.20.
The main news since 1.04 are support for bootable Linux kernels ("vmlinuz/386")
and direct Linux ELF-to-memory decompression ("linux/elf386"), so there's
no reason to use the unstable versions unless you want to try the new formats.
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
+28 -22
View File
@@ -60,20 +60,20 @@ Prerequisites
-------------
- first of all you need to build the UCL compression library
http://wildsau.idv.uni-linz.ac.at/mfx/ucl.html
http://www.oberhumer.com/opensource/ucl/
Tools needed to build/modify the UPX sources
--------------------------------------------
- A modern C++ compiler like gcc 2.95.2 or Visual C++ 6
(egcs 1.1.x may work, half-baked implementations like Borland C++ 5.5 won't)
- A C++ compiler supporting inner classes, templates, exceptions
and RTTI.
- GNU make for Win32
http://wildsau.idv.uni-linz.ac.at/mfx/download/upx/tools/
- GNU make 3.80 for Win32
http://www.cygwin.com/
- GNU make for DOS
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/
- GNU make 3.80 for DOS
http://www.delorie.com/djgpp/
To compile the packer sources
@@ -81,35 +81,41 @@ To compile the packer sources
set the environment variable UCLDIR to point to your UCL installation, e.g.
set UCLDIR=c:\src\ucl-0.92 (DOS / Windows)
export UCLDIR=$HOME/local/src/ucl-0.92 (Unix)
set UCLDIR=c:\src\ucl-1.03 (DOS / Windows)
export UCLDIR=$HOME/local/src/ucl-1.03 (Unix)
then type
make target=linux # on linux
make target=djgpp2 # for djgpp2
make target=mingw32 # for mingw32
make target=no-cygwin # for mingw32 as included in cygwin
make target=msc # for Visual C++ 6.0
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
If you want to modify the stub sources you'll also need
-------------------------------------------------------
- Nasm - the Netwide Assembler
http://www.cryogen.com/Nasm
- Perl 5.004 or better
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/perl*b.zip
- Nasm 0.98.38 - the Netwide Assembler
http://upx.sourceforge.net/download/tools/
http://sourceforge.net/projects/nasm/
- A68K - a 68000 macro assembler
http://wildsau.idv.uni-linz.ac.at/mfx/download/upx/tools/
http://upx.sourceforge.net/download/tools/
- djasm - an assembler for the djgpp stub
http://wildsau.idv.uni-linz.ac.at/mfx/download/upx/tools/
http://upx.sourceforge.net/download/tools/
- Linux (for the linux/i386 stubs)
- 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
-----------
+2 -3
View File
@@ -8,9 +8,8 @@
The Ultimate Packer for eXecutables
Copyright (c) 1996-2000 Markus Oberhumer & Laszlo Molnar
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
http://upx.tsx.org
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
.___.. .
+108 -172
View File
@@ -1,187 +1,123 @@
NOTE: this TODO list is completely out of date (~ Dec 1999)
===================================================================
- Rearrange this TODO list, sort by categories, add a priority (1-5)
UPX TODO list. Last updated 2006-03-11.
For 0.95:
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
- FIXME: what do we want in 1.00 ???
- add NRV2D for dos/exe (use by default when >= 400 kB)
- implement switch `-m' for method: 1 NRV2B, 2 NRV2D
- DLL problem under NT ? is this fixed ???
- [None]
PE
==
OTHER:
- docs: convert docs from upx.pod to use AsciiDoc
- check all <const_cast> to make sure they are not invalid
- throwNotCompressible() is not a real error, so make the output nicer
(info: bla bla). Also ui.cpp (total_*).
-----------------------------------------------------------------------
IMPROVED COMPRESSION RATIO
==========================
- experiment with new filters
- implement filters for dos/exe
- filters: could we exploit a f->firstcall info field ?
- for small programs (e.g. < 64k), try an additional algorithm
to see if it gives better compression
ALL FORMATS
===========
- more thoroughly test the exe-header in canPack()
and throw exceptions when encountering bad values.
- 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
==================
- handle overlays
- fix default file extension handling when the --coff option is set
FORMAT DOS/EXE
==============
- implement filters
- add a check so that we don't pack djgpp1 binaries
FORMAT LINUX/386
================
- don't mmap() the temporary output file - this seems to improve
file io speed
FORMAT TMT/ADAM
===============
- the decompressors are already aligned, no need for an
extra alignment
FORMAT WATCOM/LE
================
- handle files without relocations
- the decompressors are already aligned, no need for an
extra alignment
- fix default file extension handling when the --le option is set
- handle holes in the file
- implement compressWithFilters()
- add a call to verifyOverlappingDecompression()
FORMAT WIN16/NE
===============
- implement readFileHeader() to correctly identify a win16/ne
executable, so that the call for contribution will get thrown
FORMAT WIN32/PE
===============
- fix the section alignment with the Intel compiler
- 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 - medium - ml) rebuild exports
3 - difficult) don't compress the BSS section and other holes.
4 - medium - ml) fix when objectalign < 0x1000
4 - easy - ml) put the original offset of moved resources somewhere into
the res.dir. (if it's safe to do)
4 - ??? - ml) fix FIXMEs
5 - medium - ml) try to put the preprocessed imports & relocs back to their
original section if possible this could save some virtual memory
address space
COM
===
EXE
===
LE
==
4 - easy - ml) the decompressors are already aligned, no need for an
extra alignment
4 - difficult - ml) handle holes in the file
TMT
===
4 - easy - ml) the decompressors are already aligned, no need for an
extra alignment
LINUX
=====
4 - ???)
- test with AOUT binaries
- test with Java binaries
- make a compressed program suid. what happens ?
5 - difficult) rewrite the whole stub in assembly
SPARC
=====
3 - easy - ml) finish support - should generate byte-identical versions
for all formats (except those which are using Packer::getRandomId())
DJGPP2
======
1 - ???) do we support overlays at all ???
5 - ???) fix file extension handling when the --coff option is set
FOR 0.95
========
- enable automatic dependency tracking
1 - mfx) determine when to use NRV2D, find best c_flags values for
NRV2B & NRV2D (see util/runtest.sh)
5 - boring - mfx) Finally fix all screen and UI problems. How boring...
Probably should think about the whole system (printf vs. fprintf vs.
con_fprintf...)
5 - policy - ml+mfx) Discuss a default C++ style (GNU indent 2.2.3)
with Laszlo and use it. Or maybe Artistic Style?
10) Examine why pod2text breaks lines within something like `B<--coff>'.
(pod sucks anyway. unfortunately all alternatives as well.)
MISC
====
3 - difficult ml) The first two sentences of the README look too much like
those from the aspack docs. Laszlo, could you rewrite this ?
1 - easy - mfx) Check whether the compressed size of the executable is
really smaller than the uncompressed
1 - ??? - mfx) Implement a more informational interface.
Probably add some global functions in msg.cpp.
Should think about the requirements first, i.e. should there be
some simple hierarchies (header1, header2, ...) etc. ?
Could use the `-v' switch for enabling this (or `-i' ??).
- Something like this would be fine: (with colors :-)
[Processing kernel32.dll]
[Import]
3 DLL.
Original size: 12345 bytes.
Preprocessed size: 6789 bytes.
[Relocations]
Original size: 50000 bytes.
Preprocessed size: 25000 bytes.
[Exports]
<warning> exports compressed (try --compress-export=0 if needed)
[TLS]
Added 56 bytes TLS data.
Added 5 fixup records.
[Resources]
Directory size: 1234 bytes.
Resource data size: 100000 bytes.
Compressed resources: 8 (99900 bytes).
Not compressed resources: 1 (100 bytes).
3 - ???) delete temporary files when something wrong happens
4 - easy - ml) Add a `--486' option to use bswap on the 32-bit formats.
4 - easy - ml) consider removing 'sbb bp,bp' or "or ebp,-1" when not needed
5 - ???) idea: --subfile=xx compress xx. subfile: we'd need a list_subfiles
for this...
FIXME: classify
GOALS FOR 0.90
==============
- Provide additional NRV2D stubs for all 32-bit formats. Try to do this
in a generic way so that we can possibly add more algorithms.
Start by adding a `--nrv2d' switch.
FOR 0.90
========
/ update the output of `--help'
- filters: implement the missing scan() function for f_cto32.
Maybe could use this to try to find an optimal filter (e.g.
if level >= 9) based on the counts.
- filters: could we have use for a f->firstcall info field ?
TODO
====
- all formats: more thoroughly test the exe-header in canPack()
and throw exceptions when encountering bad values.
- experiment with filters
- for small programs (e.g. < 64k) try an additional algorithm (like
the non yet finished NRV2C) to see if it gives better compression ?
/ make checkerg++ work -> test
- fix file extension handling when the --coff option is set
- set up an "official" test suite
- finish documentation
original section if possible. this could save some virtual memory
address space.
+3 -3
View File
@@ -3,14 +3,14 @@ SHELL = /bin/sh
top_srcdir = ..
PACKAGE = upx
VERSION_DATE = 20 Dec 2000
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING.*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
VERSION_DATE = 11 Mar 2006
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
TRIMSPACE = cat
TRIMSPACE = sed -e 's/ *$$//'
BUILT_SOURCES = upx.1 upx.doc upx.html upx.man upx.ps upx.tex
BUILT_SOURCES = upx.1 upx.doc upx.html upx.man
BUILT_SOURCES = upx.1 upx.doc upx.html
###
+2 -2
View File
@@ -1,4 +1,4 @@
This documentation was written for those brave souls who want to
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.
@@ -11,7 +11,7 @@ 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 (they are all 8 character length strings):
in the following way:
addLoader("PEMAIN20",
ih.entry ? "PEDOJUMP" : "PERETURN",
+43
View File
@@ -0,0 +1,43 @@
UPX and SELinux
March 6, 2006
When a program that has been compressed by UPX is run, the decompressor
must create and write new memory pages of executable instructions.
SELinux (Security Enhanced Linux) directly controls the conditions
under which generating and/or executing new instructions is allowed,
so the configuration settings of SELinux affect the running of programs
that have been compressed by UPX.
In SELinux "strict enforcing" mode (the most restrictive), generating
new instructions at runtime is not allowed at all: any page with
PROT_EXEC permission must be mapped from a file in a mounted filesystem
that has 'x' [eXecute] permission, and the generation of such files is
also tightly controlled. A program that was compressed by UPX will not
run in SELinux strict enforcing mode. Attempts will fail with exit
code 127, and a record will be added to the history file
/var/log/audit/audit.log.
In "targeted enforcing" mode, SELinux pays close attention mostly to
designated processes that run with elevated privileges: web server,
print server, login server, etc. Ordinary user excutables receive
much less scrutiny. However, one of the eventual goals of SELinux is to
eradicate runtime generation of instructions because of the possibility
for exploitation by malware (virus, trojan, key logger, privilege
elevation exploit, etc.) Thus targeted enforcing mode notices and
logs the use of "execmem" capability that is used by a program which
was compressed by UPX. In keeping with the goal of eventual prohibition,
SELinux ordinarily would deny execmem. However, most current SELinux
systems, including Fedora Core 5 [set for release March 15, 2006],
override this with "allow_exemem=1" in /etc/selinux/targeted/booleans.
Thus a program compressed by UPX will run in the default installed
configuration (targeted enforcing, allow_execmem=1) of SELinux under
Fedora Core 5. Each invocation will add a few lines to the log file
/var/log/audit/audit.log, one line for each use of execmem. If the
SELinux policy becomes more restrictive in the future, then a special
SELinux class or other mechanism must be created for compressed programs,
or else UPX-compressed executables will not run then.
In its "permissive" modes, SELinux just logs the potential problems,
but otherwise does not interfere. A program compressed by UPX will run
in any permissive mode.
+223 -86
View File
@@ -12,36 +12,30 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
=head1 ABSTRACT
The Ultimate Packer for eXecutables
Copyright (c) 1996, 1997, 1998, 1999, 2000
Markus F.X.J. Oberhumer, Laszlo Molnar & John F. Reiser
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
http://upx.tsx.org
The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer & Laszlo Molnar
http://upx.sourceforge.net
B<UPX> is a portable, extendable, high-performance executable packer for
several different executable formats. It achieves an excellent compression
ratio and offers I<*very*> fast decompression. Your executables suffer
no memory overhead or other drawbacks for most of the formats supported.
no memory overhead or other drawbacks for most of the formats supported,
because of in-place decompression.
While you may use UPX freely for both non-commercial and commercial
While you may use B<UPX> freely for both non-commercial and commercial
executables (for details see the file LICENSE), we would highly
appreciate if you credit UPX and ourselves in the documentation,
possibly including a reference to the UPX home page. Thanks.
appreciate if you credit B<UPX> and ourselves in the documentation,
possibly including a reference to the B<UPX> home page. Thanks.
[ Using UPX in non-OpenSource applications without proper credits
[ Using B<UPX> in non-OpenSource applications without proper credits
is considered not politically correct ;-) ]
=head1 DISCLAIMER
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 2 1/2 years since our first public beta.
B<UPX> comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
This is the first production quality release, and we plan that future 1.xx
releases will be backward compatible with this version.
@@ -57,7 +51,8 @@ B<UPX> is a versatile executable packer with the following features:
- excellent compression ratio: compresses better than zip/gzip,
use UPX to decrease the size of your distribution !
- very fast decompression: about 10 MB/sec even on my old Pentium 133
- very fast decompression: about 10 MB/sec on an ancient Pentium 133,
about 200 MB/sec on an Athlon XP 2000+.
- no memory overhead for your compressed executables for most of the
supported formats
@@ -76,11 +71,16 @@ B<UPX> is a versatile executable packer with the following features:
* linux/386
* linux/elf386
* linux/sh386
* ps1/exe
* rtm32/pe
* tmt/adam
* vmlinuz/386 [bootable Linux kernel]
* watcom/le (supporting DOS4G, PMODE/W, DOS32a and CauseWay)
* win32/pe
* arm/pe
* linux/elfamd64
* linux/elfppc32
* mach/elfppc32
- portable: UPX is written in portable endian-neutral C++
@@ -91,7 +91,7 @@ B<UPX> is a versatile executable packer with the following features:
the full source code of UPX is released under the GNU General Public
License (GPL) !
You probably understand now why we call UPX the "I<ultimate>"
You probably understand now why we call B<UPX> the "I<ultimate>"
executable packer.
@@ -105,7 +105,7 @@ specified on the command line.
=head2 Decompress
All UPX supported file formats can be unpacked using the B<-d> switch, eg.
All B<UPX> supported file formats can be unpacked using the B<-d> switch, eg.
B<upx -d yourfile.exe> will uncompress the file you've just compressed.
=head2 Test
@@ -135,9 +135,7 @@ B<-q -q -q> (or B<-qqq>): produce no output at all
B<--help>: prints the help
B<--version>: print the version of UPX
B<--stdout>: writes all output to stdout
B<--version>: print the version of B<UPX>
[ ...to be written... - type `B<upx --help>' for now ]
@@ -169,19 +167,43 @@ Compression level B<--best> may take a long time.
=back
Note that compression level B<-9> can be somewhat slow for large
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.
Since UPX 0.70 there is also an extra compression level B<--best> which
squeezes out even some more compression ratio. While it is usually fine
to use this option with your favorite .com file it may take a long time
to compress a multi-megabyte program. You have been warned.
Tips for even better compression:
Quick start for achieving the best compression ratio:
=over 4
Try B<upx --brute myfile.exe>.
=back
Details 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>>.
=item *
Try if B<--overlay=strip> works.
@@ -196,12 +218,15 @@ For win32/pe programs there's B<--strip-relocs=0>. See notes below.
=head1 OVERLAY HANDLING OPTIONS
Info: An "overlay" means auxillary data atached after the logical end of
an executable, and it often contains application specific data
(this is a common practice to avoid an extra data file, though
it would be better to use resource sections).
B<UPX> handles overlays like many other executable packers do: it simply
copies the overlay after the compressed image. This works with some
files, but doesn't work with others.
Since version 0.90 UPX defaults to B<--overlay=copy> for
all executable formats.
files, but doesn't work with others, depending on how an application
actually accesses this overlayed data.
--overlay=copy Copy any extra data attached to the file. [DEFAULT]
@@ -216,25 +241,22 @@ all executable formats.
=head1 ENVIRONMENT
The environment variable B<UPX> can hold a set of default
options for UPX. These options are interpreted first and
options for B<UPX>. These options are interpreted first and
can be overwritten by explicit command line parameters.
For example:
for DOS/Windows: set UPX=-9 --compress-icons#1
for sh/ksh/zsh: UPX="-9 --compress-icons=1"; export UPX
for csh/tcsh: setenv UPX "-9 --compress-icons=1"
for DOS/Windows: set UPX=-9 --compress-icons#0
for sh/ksh/zsh: UPX="-9 --compress-icons=0"; export UPX
for csh/tcsh: setenv UPX "-9 --compress-icons=0"
Under DOS/Windows you must use '#' instead of '=' when setting the
environment variable because of a COMMAND.COM limitation.
On Vax/VMS, the name of the environment variable is
UPX_OPT, to avoid a conflict with the symbol set for
invocation of the program.
Not all of the options are valid in the environment variable -
UPX will tell you.
B<UPX> will tell you.
You can use the B<--no-env> option to turn this support off.
You can explicitly use the B<--no-env> option to ignore the
environment variable.
@@ -242,17 +264,21 @@ You can use the B<--no-env> option to turn this support off.
=head2 NOTES FOR ATARI/TOS
This is the executable format used by the Atari ST/TT, a 68000 based
personal computer which was popular in the late '80s. Support
This is the executable format used by the Atari ST/TT, a Motorola 68000
based personal computer which was popular in the late '80s. Support
of this format is only because of nostalgic feelings of one of
the authors and serves no practical purpose :-).
See http://www.freemint.de for more info.
Packed programs will be byte-identical to the original after uncompression.
All debug information will be stripped, though.
Extra options available for this executable format:
(none)
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
@@ -264,7 +290,7 @@ Same as vmlinuz/i386.
=head2 NOTES FOR DOS/COM
Obviously UPX won't work with executables that want to read data from
Obviously B<UPX> won't work with executables that want to read data from
themselves (like some commandline utilities that ship with Win95/98/ME).
Compressed programs only work on a 286+.
@@ -277,13 +303,23 @@ Extra options available for this executable format:
--8086 Create an executable that works on any 8086 CPU.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
=head2 NOTES FOR DOS/EXE
dos/exe stands for all "normal" 16-bit DOS executables.
Obviously UPX won't work with executables that want to read data from
Obviously B<UPX> won't work with executables that want to read data from
themselves (like some command line utilities that ship with Win95/98/ME).
Compressed programs only work on a 286+.
@@ -294,6 +330,11 @@ Extra options available for this executable format:
--no-reloc Use no relocation records in the exe header.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
=head2 NOTES FOR DOS/SYS
@@ -311,33 +352,51 @@ Extra options available for this executable format:
--8086 Create an executable that works on any 8086 CPU.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
=head2 NOTES FOR DJGPP2/COFF
First of all, it is recommended to use UPX *instead* of B<strip>. strip has
First of all, it is recommended to use B<UPX> *instead* of B<strip>. strip has
the very bad habit of replacing your stub with its own (outdated) version.
Additionally UPX corrects a bug/feature in strip v2.8.x: it
Additionally B<UPX> corrects a bug/feature in strip v2.8.x: it
will fix the 4 KByte aligment of the stub.
UPX includes the full functionality of stubify. This means it will
B<UPX> includes the full functionality of stubify. This means it will
automatically stubify your COFF files. Use the option B<--coff> to
disable this behaviour (see below).
disable this functionality (see below).
UPX automatically handles Allegro packfiles.
B<UPX> automatically handles Allegro packfiles.
The DLM format (a rather exotic shared library extension) is not supported.
Packed programs will be byte-identical to the original after uncompression.
All debug information and trailing garbage will be stripped, though.
BTW, UPX is the successor of the DJP executable packer.
Extra options available for this executable format:
--coff Produce COFF output instead of EXE. By default
UPX keeps your current stub.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
=head2 NOTES FOR LINUX [general]
@@ -520,7 +579,7 @@ Extra options available for this executable format:
Please read the general Linux description first.
Shell scripts where the underling shell accepts a ``-c'' argument
can use the Linux/sh386 format. UPX decompresses the shell script
can use the Linux/sh386 format. B<UPX> decompresses the shell script
into low memory, then maps the shell and passes the entire text of the
script as an argument with a leading ``-c''.
It does not use space in /tmp, and does not use /proc.
@@ -566,8 +625,9 @@ Extra options available for this executable format:
Please read the general Linux description first.
The generic linux/386 format deompresses to /tmp
and needs /proc filesystem support.
The generic linux/386 format decompresses to /tmp and needs
/proc filesystem support. It starts the decompressed program
via the execve() syscall.
Linux/386 is only selected if the specialized linux/elf386
and linux/sh386 won't recognize a file.
@@ -577,7 +637,7 @@ Packed programs will be byte-identical to the original after uncompression.
How it works:
For files which are not ELF and not a script for a known "-c" shell,
UPX uses kernel exec(), which first requires decompressing to a
UPX uses kernel execve(), which first requires decompressing to a
temporary file in the filesystem. Interestingly -
because of the good memory management of the Linux kernel - this
often does not introduce a noticable delay, and in fact there
@@ -625,11 +685,56 @@ Specific drawbacks:
Extra options available for this executable format:
(none)
--force-execve Force the use of the generic linux/386 "execve"
format, i.e. do not try the linux/elf386 and
linux/sh386 formats.
=head2 NOTES FOR RTM32/PE
=head2 NOTES FOR PS1/EXE
This is the executable format used by the Sony PlayStation (PSone),
a Mips R3000 based gaming console which is popular since the late '90s.
Support of this format is very similar to the Atari one, because of
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.
Notes:
- UPX creates as default a 'CD-Rom only' PS1/PS2 compatible executable.
For transfer between client/target use options 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.
Extra options available for this executable format:
--all-methods Compress the program several times, using all
available compression methods. This may improve
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 !
--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 !
=head2 NOTES FOR RTM32/PE and ARM/PE
Same as win32/pe.
@@ -641,15 +746,23 @@ This format is used by the TMT Pascal compiler - see http://www.tmt.com/ .
Extra options available for this executable format:
(none)
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
=head2 NOTES FOR VMLINUZ/386
The vmlinuz/386 and bvmlinuz/386 formats take a gzip-compressed
bootable kernel image ("vmlinuz", "zImage", "bzImage"), gzip-decompress
it and re-compress it with the UPX compression method.
bootable Linux kernel image ("vmlinuz", "zImage", "bzImage"),
gzip-decompress it and re-compress it with the B<UPX> compression method.
vmlinuz/386 is completely unrelated to the other Linux executable
formats, and it does not share any of their drawbacks.
@@ -672,7 +785,8 @@ Benefits:
641073 bzImage [original]
560755 bzImage.upx [compressed by "upx -9"]
- Much faster decompression at kernel boot time.
- Much faster decompression at kernel boot time (but kernel
decompression speed is not really an issue these days).
Drawbacks:
@@ -680,22 +794,26 @@ Drawbacks:
Extra options available for this executable format:
(none)
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
=head2 NOTES FOR WATCOM/LE
UPX has been successfully tested with the following extenders:
B<UPX> has been successfully tested with the following extenders:
DOS4G, DOS4GW, PMODE/W, DOS32a, CauseWay.
The WDOS/X extender is partly supported (for details
see the file bugs BUGS).
Yes, you can use your compressed executables with DOS4GW.
The LX format is not yet supported.
DLLs are not supported.
DLLs and the LX format are not supported.
Extra options available for this executable format:
@@ -706,14 +824,15 @@ Extra options available for this executable format:
=head2 NOTES FOR WIN32/PE
The PE support in UPX is quite stable now, but probably there are
The PE support in B<UPX> is quite stable now, but probably there are
still some incompabilities with some files.
Because of the way UPX (and other packers for this format) works, you
can see increased memory usage of your compressed files. If you start
several instances of huge compressed programs you're wasting memory
because the common segements of the program won't get shared
across the instances.
Because of the way B<UPX> (and other packers for this format) works, you
can see increased memory usage of your compressed files because the whole
program is loaded into memory at startup.
If you start several instances of huge compressed programs you're
wasting memory because the common segements of the program won't
get shared across the instances.
On the other hand if you're compressing only smaller programs, or
running only one instance of larger programs, then this penalty is
smaller, but it's still there.
@@ -723,6 +842,10 @@ will load faster, and require less bandwidth during execution.
DLLs are supported.
Screensavers are supported, with the restriction that the filename
must end with ".scr" (as screensavers are handled slightly different
than normal exe files).
Extra options available for this executable format:
--compress-exports=0 Don't compress the export section.
@@ -752,10 +875,20 @@ Extra options available for this executable format:
address greater or equal to 0x400000. Usually the
compressed files becomes smaller, but some files
may become larger. Note that the resulting file will
not work under Win32s.
not work under Windows 3.x (Win32s).
UPX never strips relocations from a DLL
regardless of this option.
--all-methods Compress the program several times, using all
available compression methods. This may improve
the compression ratio in some cases, but usually
the default method gives the best results anyway.
--all-filters Compress the program several times, using all
available preprocessing filters. This may improve
the compression ratio in some cases, but usually
the default filter gives the best results anyway.
=head1 DIAGNOSTICS
@@ -775,22 +908,26 @@ Please report all bugs immediately to the authors.
=head1 AUTHORS
Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>
http://wildsau.idv.uni-linz.ac.at/mfx/
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com
Laszlo Molnar <ml1050@cdata.tvnet.hu>
Laszlo Molnar <ml1050@users.sourceforge.net>
John F. Reiser <jreiser@BitWagon.com>
Jens Medoch <jssg@users.sourceforge.net>
=head1 COPYRIGHT
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000 John Reiser
Copyright (C) 2000-2006 John F. Reiser
Copyright (C) 2002-2006 Jens Medoch
This program may be used freely, and you are welcome to
redistribute it under certain conditions.
@@ -798,7 +935,7 @@ redistribute it under certain conditions.
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
UPX License Agreement for more details.
B<UPX License Agreement> for more details.
You should have received a copy of the UPX License Agreement along
with this program; see the file LICENSE. If not, visit the UPX home page.
-101
View File
@@ -1,101 +0,0 @@
The GNU bfd binary file descriptor package, part of the GNU binutils package,
contains code to recognize an Elf file by looking at fields in the file header.
Many programs (such as gdb, size, objdump, objcopy, strip and others) use bfd.
Unfortunately, bfd has been overly strict. In releases
binutils-2.9.1.0.4, binutils-2.9.1.0.23, binutils-2.9.5.0.0,
binutils-2.10.1,
gdb-4.17, gdb-5.0,
and probably others,
bfd does not recognize a file with zero in Elf32_Ehdr.e_shoff, .e_shentsize,
or .e_shnum, even though the operating system kernel does not care, and many
bfd clients would work just fine in these cases.
Because of its desire to create small size compressed executables, UPX
generates and uses Elf files with zero in .e_shoff, .e_shentsizes, and .e_shnum.
As a result, many widely-distributed instances of gdb, size, objdump, etc.,
refuse to work on UPX-packed executables.
Here is a patch to bfd/elfcode.h which enables many bfd clients to work
with UPX-packed executables. The last two lines of the patch are
if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
return -1;
--- elfcode.h.orig Mon Jun 16 11:45:32 1997
+++ elfcode.h Sat Apr 22 10:18:56 2000
@@ -1,5 +1,5 @@
/* ELF executable support for BFD.
- Copyright 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+ Copyright 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
Written by Fred Fish @ Cygnus Support, from information published
in "UNIX System V Release 4, Programmers Guide: ANSI C and
@@ -517,14 +517,14 @@
elf_debug_file (i_ehdrp);
#endif
- /* If there is no section header table, we're hosed. */
- if (i_ehdrp->e_shoff == 0)
+ /* If there is no section header table, and relocatable, then we're hosed. */
+ if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
goto got_wrong_format_error;
/* As a simple sanity check, verify that the what BFD thinks is the
size of each section header table entry actually matches the size
- recorded in the file. */
- if (i_ehdrp->e_shentsize != sizeof (x_shdr))
+ recorded in the file, but only if there are any sections. */
+ if (i_ehdrp->e_shentsize != sizeof (x_shdr) && i_ehdrp->e_shnum != 0)
goto got_wrong_format_error;
ebd = get_elf_backend_data (abfd);
@@ -579,6 +579,7 @@
/* Allocate space for a copy of the section header table in
internal form, seek to the section header table in the file,
read it in, and convert it to internal form. */
+ if (i_ehdrp->e_shnum!=0) {
i_shdrp = ((Elf_Internal_Shdr *)
bfd_alloc (abfd, sizeof (*i_shdrp) * i_ehdrp->e_shnum));
elf_elfsections (abfd) = ((Elf_Internal_Shdr **)
@@ -609,6 +610,7 @@
if (! bfd_section_from_shdr (abfd, i_ehdrp->e_shstrndx))
goto got_no_match;
}
+ }
/* Read in the program headers. */
if (i_ehdrp->e_phnum == 0)
@@ -644,6 +646,7 @@
bfd_section_from_shdr with it (since this particular strtab is
used to find all of the ELF section names.) */
+ if (i_ehdrp->e_shstrndx != 0) {
shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
if (!shstrtab)
goto got_no_match;
@@ -657,6 +660,7 @@
if (! bfd_section_from_shdr (abfd, shindex))
goto got_no_match;
}
+ }
/* Let the backend double check the format and override global
information. */
@@ -930,7 +934,7 @@
{
Elf_Internal_Shdr *hdr;
Elf_Internal_Shdr *verhdr;
- long symcount; /* Number of external ELF symbols */
+ unsigned long symcount; /* Number of external ELF symbols */
elf_symbol_type *sym; /* Pointer to current bfd symbol */
elf_symbol_type *symbase; /* Buffer for generated bfd symbols */
Elf_Internal_Sym i_sym;
@@ -978,7 +982,7 @@
sym = symbase = NULL;
else
{
- long i;
+ unsigned long i;
if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
return -1;
+2679 -1206
View File
File diff suppressed because it is too large Load Diff
+12 -5
View File
@@ -1,12 +1,19 @@
*.0??
*.d
*.dat
*.idb
*.img
*.map
*.raw
*.rc
*.rel
*.res
*.pdb
*.out
*.upx
.gdbinit
.Attic
GNUmakefile
MMakefile
compress_nrv.*
upx
upx_nrv
upx_nrv.*
upx_ucl
upx_ucl.*
version1*.h
+37 -464
View File
@@ -1,482 +1,55 @@
# UPX Makefile (GNU make) - works with djgpp2/win32/unix
#
# usage:
# `make target=linux' # linux
# `make target=djggp2' # djggp2 2.03
# `make target=cygwin' # cygwin 1.1.x
# `make target=mingw32' # mingw32
# `make target=no-cygwin' # mingw32 as included in cygwin 1.1.x
# `make target=vc6' # Visual C++ 6.0
# UPX Makefile - needs GNU make 3.80 or better
#
# configuration section
ifeq ($(strip $(UCLDIR)),)
# change this to reflect where the UCL library is
UCLDIR = $(HOME)/local/src/ucl-0.92
endif
DEBUG = 0
# -------------------------------------------------------
# You should not have to change anything below this line.
# -------------------------------------------------------
SHELL = /bin/sh
MAKEFLAGS += -rR
.SUFFIXES:
.SUFFIXES: .a .c .cpp .exe .lib .o .obj
export SHELL = /bin/sh
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
srcdir = .
top_srcdir = ..
# auto-detect the target unless given on the commandline
target = djgpp2
ifneq ($(strip $(wildcard /usr/include/linux)),)
target = linux
endif
ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),)
target = sparc
endif
ifeq ($(target),msc)
override target = vc6
srcdir ?= $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
ifneq ($(srcdir),./)
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,')
##$(info Info: using VPATH . $(srcdir))
VPATH := . $(srcdir)
endif
# util var for use in the rules - basename of the current target
override T = $(basename $@)
# /***********************************************************************
# // object files
# ************************************************************************/
# these use exceptions & RTTI
OBJECTS1 = \
compress$o except$o file$o lefile$o \
filter$o mem$o msg$o stdcxx$o work$o ui$o \
packer$o packhead$o packmast$o \
p_com$o p_djgpp2$o p_exe$o p_lx_elf$o p_lx_sep$o p_lx_sh$o \
p_sys$o p_tmt$o p_tos$o \
p_unix$o p_vmlinz$o p_w32pe$o p_wcle$o
# no exceptions or RTTI
OBJECTS2 = \
filteri$o help$o main$o mygetopt$o util$o linker$o \
c_init$o c_file$o c_none$o c_screen$o \
s_object$o s_djgpp2$o s_vcsa$o s_win32$o
# pure C sources
OBJECTS3 =
OBJECTS = $(OBJECTS1) $(OBJECTS2) $(OBJECTS3)
# /***********************************************************************
# // compiler settings
# ************************************************************************/
# default to a gcc unix-type compiler
CC = gcc
CXX = $(CC)
DEFS =
INCLUDES = -I$(srcdir)
CFLAGS_OUTPUT = -o $@
CXXFLAGS_OUTPUT = $(CFLAGS_OUTPUT)
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LDLIBS)
STUBEDIT_EXE =
o = .o
a = .a
e = .exe
###
### gcc defaults
###
##CFLAGS_O = -Os
CFLAGS_O = -O2
##CFLAGS_WERROR = -Werror
CFLAGS_W = $(CFLAGS_WERROR)
CFLAGS_W += -Wall -W -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wwrite-strings
##CFLAGS_M = -fno-builtin
## CFLAGS_M += -malign-functions=0 -malign-jumps=0 -malign-loops=0
CFLAGS = $(CFLAGS_W) $(CFLAGS_O) $(CFLAGS_M)
CXXFLAGS = $(CFLAGS) -Wsynth -fconserve-space
CXXFLAGS1 = $(CXXFLAGS)
CXXFLAGS2 = $(CXXFLAGS) -fno-exceptions -fno-rtti
ifeq ($(DEBUG),1)
DEFS += -DDEBUG
## DEFS += -DTESTING
ifeq ($(CXX),)
CXX = g++
endif
ifeq ($(DEBUG),1)
LDFLAGS = -g
else
LDFLAGS = -s
ifeq ($(CXX),g++)
CXXFLAGS += -O2 -MMD
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
endif
LDFLAGS += -Wl,-Map,$T.map
LDLIBS =
LDLIBS = -lz
LIBDIRS =
DOS_LIBDIRS =
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
CXXLD ?= $(CXX)
exeext ?= .out
libext ?= .a
objext ?= .o
###
### compression library
###
UCLDIR:=$(strip $(subst \,/,$(UCLDIR)))
NRVDIR:=$(strip $(subst \,/,$(NRVDIR)))
u = ucl
U = UCL
upx_exe = upx$e
include $(srcdir)/Makefile.inc
ifneq ($(strip $(wildcard $(NRVDIR)/include/nrv)),)
u = nrv
U = NRV
upx_exe = upx_$u$e
include $(srcdir)/Makefile.inc
# 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
tmp := -Wl,--rpath,
LDRPATH := $(addprefix $(tmp),$(LIBDIRS))
LIBDIRS += .
LDLIBDIRS := $(addprefix -L,$(LIBDIRS))
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
##LDFLAGS += $(LDRPATH)
LDFLAGS += $(LDLIBDIRS)
all: upx$(exeext)
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
$($(notdir $@).PRE_LINK_STEP)
$(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS))
$($(notdir $@).POST_LINK_STEP)
###
### linux/i386
###
%.o : %.cpp
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
ifeq ($(target),linux)
e =
###CC = /usr/local/packages/gcc-cvs/bin/g++
DEFS += '-DUPX_CONFIG_H="config_h/linux.h"'
##CFLAGS_M += -mno-schedule-prologue
CFLAGS_M += -march=i386 -mcpu=pentium
CFLAGS_WERROR = -Werror
LDLIBS += -lmcheck
mostlyclean clean distclean maintainer-clean:
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)
ifeq (1,2) # checkergcc
CC = checkergcc
CXX = checkerg++
else
ifeq ($(DEBUG),1)
##CFLAGS += -O0 -gstabs+3
CFLAGS += -O0 -gdwarf-2
else
##LDFLAGS += -static
STUBEDIT_EXE = objcopy -S -R .comment -R .note $@ && perl $(srcdir)/stub/scripts/brandelf.pl $@ && chmod 755 $@
endif
endif
endif # linux
###
### djgpp2
###
ifeq ($(target),djgpp2)
CFLAGS_M += -mno-schedule-prologue
CFLAGS_M += -march=i386 -mcpu=pentium
CFLAGS_WERROR = -Werror
STUBEDIT_EXE = stubedit $@ bufsize=0xfc00
endif # djgpp2
###
### cygwin / mingw32
###
ifeq ($(target),cygwin)
CFLAGS_M += -mno-schedule-prologue
CFLAGS_M += -march=i386 -mcpu=pentium
CFLAGS_WERROR = -Werror
endif
ifeq ($(target),mingw32)
CFLAGS_M += -mno-schedule-prologue
CFLAGS_M += -march=i386 -mcpu=pentium
endif
# mingw32 as included in cygwin
ifeq ($(target),no-cygwin)
CC = gcc -mno-cygwin
CFLAGS_M += -mno-schedule-prologue
CFLAGS_M += -march=i386 -mcpu=pentium
CFLAGS_WERROR = -Werror
endif
###
### Microsoft 32-bit C/C++ Compiler 12.00 (aka Visual C++ 6)
###
ifeq ($(target),vc6)
o = .obj
a = .lib
CC = cl -nologo
CFLAGS = -W4 -WX
CXXFLAGS1 = $(CFLAGS) -GR -GX -EHa
CXXFLAGS2 = $(CFLAGS)
LDFLAGS =
LINK_LDFLAGS = /link /map:$T.map
ifneq ($(strip $(DOS_LIBDIRS)),)
LIB := $(DOS_LIBDIRS);$(LIB)
endif
export LIB
ifeq (1,2)
# statically link libc.lib
CC += -ML
##LDLIBS = $(u)_s.lib zlib_s.lib setargv.obj
LDLIBS = $(u)_s.lib setargv.obj
else
# link against msvcrt.dll
CC += -MD
LDLIBS = $(DOS_LDLIBS) zlib.lib setargv.obj
endif
ifeq ($(DEBUG),1)
CFLAGS += -Od -ZI
LINK_LDFLAGS += /debug
else
CFLAGS += -O2 -GF
LINK_LDFLAGS += /release
endif
##LINK_LDFLAGS += /verbose
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -Fe$@ $^ $(LDLIBS) $(LINK_LDFLAGS)
endif # vc6
###
### sparc
###
ifeq ($(target),sparc)
e =
DEFS += '-DUPX_CONFIG_H="config_h/sparc.h"'
INCLUDES += -I/home/ethmola/local/include
ifeq (1,2) # native compiler
CFLAGS = -O0 -g
CXXFLAGS1 =
CXXFLAGS2 =
CFLAGS_M =
DEFS += -DUSE_STDNAMESPACE
else # gcc
CFLAGS += -O0 -gstabs+
endif
ifeq (1,2) # purify
DEFS += -D__PURIFY__
LDFLAGS = -g -L/home/ethmola/local/lib
LINK_EXE = purify $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LDLIBS)
else
LDFLAGS += -g -L/home/ethmola/local/lib
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LDLIBS)
endif
endif # sparc
###
### Borland C++ 5.5 (DOES NOT WORK - INCOMPLETE C++ IMPLEMENTATION)
###
ifeq ($(target),bcc)
o = .obj
a = .lib
CC = bcc32
CFLAGS = -w -w-par
CXXFLAGS1 = $(CFLAGS)
CXXFLAGS2 = $(CFLAGS)
CFLAGS_OUTPUT = -o$@
LDFLAGS =
LDLIBS = $(DOS_LDLIBS) zlib.lib
ifneq ($(strip $(DOS_LIBDIRS)),)
LIB := $(DOS_LIBDIRS);$(LIB)
endif
export LIB
ifeq ($(DEBUG),1)
CFLAGS += -Od -d
else
CFLAGS += -O2 -d
endif
LINK_EXE = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -e$@ $^ $(LDLIBS)
endif # bcc
###
### malloc debuggers (Linux only)
###
ifeq (1,2)
LDLIBS += -lefence
endif
ifeq (1,2)
CFLAGS += -DWITH_DMALLOC
LDLIBS += -ldmalloc
endif
ifeq (1,2)
CFLAGS += -DWITH_GC -DLINUX_THREADS -D_REENTRANT
LDLIBS += -lgc -lpthread
# only needed when using -static:
##LDFLAGS += -Wl,-defsym,_DYNAMIC=0
endif
ifeq (1,2)
CFLAGS += -DWITH_MSS
LDLIBS += -lmss
endif
# /***********************************************************************
# // main targets
# ************************************************************************/
all: $(upx_exe)
.PHONY: all unupx mostlyclean clean distclean maintainer-clean untabify tags
$(upx_exe): $(OBJECTS) $(LIBS)
$(LINK_EXE)
$(STUBEDIT_EXE)
ifeq ($(target),djgpp2)
cwsbind: $(upx_exe)
-rm -f $T.cof
$(upx_exe) -1 --coff -o $T.cof $(upx_exe)
cat $(DJDIR)/bin/cwsdstub.exe $T.cof > $(upx_exe)
$(upx_exe) -d $(upx_exe)
$(upx_exe) --best $(upx_exe)
endif
unupx:
$(MAKE) target=vc6 unupx.dll
unupx.dll: $(OBJECTS) $(LIBS)
$(LINK_DLL)
mostlyclean:
-rm -f *.d *.err *.i *.log *.map *~ gdb-trans*
clean: mostlyclean
-rm -f *.a *.lib *.o *.obj tags TAGS ID
-rm -f *.idb *.pdb
-rm -f upx upx.exe upx_nrv upx_nrv.exe upx_ucl upx_ucl.exe
distclean: clean
maintainer-clean: distclean
untabify:
mfxtu -d4 -t *.h *.cpp *.ch
mfxtu -d8 -t stub/[ln]*.asm stub/*.ash stub/*.[cs]
tags TAGS:
ctags *.h *.cpp *.ch
ID:
mkid *.h *.cpp *.ch
# /***********************************************************************
# // rules
# ************************************************************************/
.c$o:
$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) $(CFLAGS_OUTPUT) -c $<
.cpp$o:
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS1) $(CXXFLAGS_OUTPUT) -c $<
$(OBJECTS1): %$o : %.cpp
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS1) $(CXXFLAGS_OUTPUT) -c $<
$(OBJECTS2): %$o : %.cpp
$(CXX) $(DEFS) $(INCLUDES) $(CXXFLAGS2) $(CXXFLAGS_OUTPUT) -c $<
ifneq ($(strip $(OBJECTS3)),)
$(OBJECTS3): %$o : %.c
$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) $(CFLAGS_OUTPUT) -c $<
endif
# /***********************************************************************
# // dependencies
# ************************************************************************/
# FIXME: use automated dependencies
main$o: mygetopt.h version.h
filter$o: filter.h
filteri$o: filter.h fcto_ml.ch fcto_ml2.ch fcto_ml3.ch
help$o: version.h
msg$o: ui.h
lefile$o: lefile.h
linker$o: linker.h
mygetopt$o: mygetopt.h
packer$o: packer.h filter.h linker.h ui.h version.h
packhead$o: packer.h
packmast$o: packmast.h packer.h lefile.h \
p_com.h p_djgpp2.h p_exe.h p_lx_elf.h p_lx_sep.h p_lx_sh.h \
p_sys.h p_tmt.h p_tos.h \
p_unix.h p_vmlinz.h p_vxd.h p_w32pe.h p_wcle.h
ui$o: packer.h ui.h
work$o: packer.h ui.h packmast.h
p_com$o: packer.h p_com.h \
stub/l_com.h
p_djgpp2$o: packer.h p_djgpp2.h stub/stubify.h \
stub/l_djgpp2.h
p_exe$o: packer.h p_exe.h \
stub/l_exe.h
p_lx_elf$o: packer.h p_lx_elf.h p_unix.h p_elf.h \
stub/l_le_n2b.h stub/l_le_n2d.h
p_lx_sep$o: packer.h p_lx_sep.h p_lx_elf.h p_unix.h p_elf.h
p_lx_sh$o: packer.h p_lx_sh.h p_lx_elf.h p_unix.h p_elf.h \
stub/l_sh_n2b.h stub/l_sh_n2d.h
p_sys$o: packer.h p_sys.h p_com.h \
stub/l_sys.h
p_tmt$o: packer.h p_tmt.h \
stub/l_tmt.h
p_tos$o: packer.h p_tos.h \
stub/l_t_n2b.h stub/l_t_n2bs.h \
stub/l_t_n2d.h stub/l_t_n2ds.h
p_unix$o: packer.h p_unix.h p_elf.h \
stub/l_lx_n2b.h stub/l_lx_n2d.h
p_vmlinz$o: packer.h p_vmlinz.h \
stub/l_vmlinz.h
p_w32pe$o: packer.h p_w32pe.h \
stub/l_w32pe.h
p_wcle$o: packer.h p_wcle.h lefile.h \
stub/l_wcle.h
# vi:nowrap
-include *.d
.PHONY: all mostlyclean clean distclean maintainer-clean
-37
View File
@@ -1,37 +0,0 @@
UDIR := $($(U)DIR)
DEFS += -DWITH_$(U)
ifneq ($(strip $(wildcard $(UDIR)/include)),)
INCLUDES += -I$(UDIR)/include
endif
ifneq ($(strip $(wildcard $(UDIR)/src/.libs)),)
LIBDIRS += $(UDIR)/src/.libs
endif
ifeq ($(DEBUG),1)
ifneq ($(strip $(wildcard $(UDIR)/build/debug/src/.libs)),)
LIBDIRS += $(UDIR)/build/debug/src/.libs
endif
endif
ifneq ($(strip $(wildcard $(UDIR)/build/release/src/.libs)),)
LIBDIRS += $(UDIR)/build/release/src/.libs
endif
ifneq ($(strip $(wildcard $(UDIR)/build/src/.libs)),)
LIBDIRS += $(UDIR)/build/src/.libs
endif
ifneq ($(strip $(wildcard $(UDIR))),)
LIBDIRS += $(UDIR)
DOS_LIBDIRS := $(DOS_LIBDIRS);$(UDIR)
endif
LDLIBS += -l$(u)
DOS_LDLIBS += $(u).lib
DEFS := $(DEFS)
INCLUDES := $(INCLUDES)
LIBDIRS := $(LIBDIRS)
LDLIBS := $(LDLIBS)
DOS_LDLIBS := $(DOS_LDLIBS)
+370 -165
View File
@@ -1,9 +1,9 @@
/* bele.h --
/* bele.h -- access memory in BigEndian and LittleEndian byte order
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -31,215 +31,372 @@
/*************************************************************************
// access memory in BigEndian and LittleEndian byte order
// core
**************************************************************************/
inline unsigned short get_be16(const void *bb, int off=0)
inline unsigned get_be16(const void *p)
{
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
unsigned v;
v = (unsigned) b[1] << 0;
v |= (unsigned) b[0] << 8;
return (unsigned short) v;
}
inline void set_be16(void *bb, unsigned v, int off=0)
{
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
b[1] = (unsigned char) (v >> 0);
b[0] = (unsigned char) (v >> 8);
}
inline unsigned get_be32(const void *bb, int off=0)
{
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
unsigned v;
v = (unsigned) b[3] << 0;
v |= (unsigned) b[2] << 8;
v |= (unsigned) b[1] << 16;
v |= (unsigned) b[0] << 24;
return v;
}
inline void set_be32(void *bb, unsigned v, int off=0)
{
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
b[3] = (unsigned char) (v >> 0);
b[2] = (unsigned char) (v >> 8);
b[1] = (unsigned char) (v >> 16);
b[0] = (unsigned char) (v >> 24);
}
inline unsigned short get_le16(const void *bb, int off=0)
{
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
unsigned v;
#if defined(__i386__)
v = * (const unsigned short *) b;
#if defined(ACC_UA_GET_BE16)
return ACC_UA_GET_BE16(p);
#else
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
#endif
return (unsigned short) v;
}
inline void set_le16(void *bb, unsigned v, int off=0)
{
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
#if defined(__i386__)
(* (unsigned short *) b) = (unsigned short) v;
#else
b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
return acc_ua_get_be16(p);
#endif
}
inline unsigned get_le24(const void *bb, int off=0)
inline void set_be16(void *p, unsigned v)
{
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
unsigned v;
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
v |= (unsigned) b[2] << 16;
return v;
}
inline void set_le24(void *bb, unsigned v, int off=0)
{
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
b[2] = (unsigned char) (v >> 16);
}
inline unsigned get_le32(const void *bb, int off=0)
{
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off;
unsigned v;
#if defined(__i386__)
v = * (const unsigned *) b;
#if defined(ACC_UA_SET_BE16)
ACC_UA_SET_BE16(p, v);
#else
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
v |= (unsigned) b[2] << 16;
v |= (unsigned) b[3] << 24;
acc_ua_set_be16(p, v);
#endif
return v;
}
inline void set_le32(void *bb, unsigned v, int off=0)
inline unsigned get_be24(const void *p)
{
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off;
#if defined(__i386__)
(* (unsigned *) b) = v;
#if defined(ACC_UA_GET_BE24)
return ACC_UA_GET_BE24(p);
#else
b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
b[2] = (unsigned char) (v >> 16);
b[3] = (unsigned char) (v >> 24);
return acc_ua_get_be24(p);
#endif
}
inline void set_be24(void *p, unsigned v)
{
#if defined(ACC_UA_SET_BE24)
ACC_UA_SET_BE24(p, v);
#else
acc_ua_set_be24(p, v);
#endif
}
inline unsigned get_be32(const void *p)
{
#if defined(ACC_UA_GET_BE32)
return ACC_UA_GET_BE32(p);
#else
return acc_ua_get_be32(p);
#endif
}
inline void set_be32(void *p, unsigned v)
{
#if defined(ACC_UA_SET_BE32)
ACC_UA_SET_BE32(p, v);
#else
acc_ua_set_be32(p, v);
#endif
}
inline acc_uint64l_t get_be64(const void *p)
{
#if defined(ACC_UA_GET_BE64)
return ACC_UA_GET_BE64(p);
#else
return acc_ua_get_be64(p);
#endif
}
inline void set_be64(void *p, acc_uint64l_t v)
{
#if defined(ACC_UA_SET_BE64)
ACC_UA_SET_BE64(p, v);
#else
acc_ua_set_be64(p, v);
#endif
}
inline unsigned get_le16(const void *p)
{
#if defined(ACC_UA_GET_LE16)
return ACC_UA_GET_LE16(p);
#else
return acc_ua_get_le16(p);
#endif
}
inline void set_le16(void *p, unsigned v)
{
#if defined(ACC_UA_SET_LE16)
ACC_UA_SET_LE16(p, v);
#else
acc_ua_set_le16(p, v);
#endif
}
inline unsigned get_le24(const void *p)
{
#if defined(ACC_UA_GET_LE24)
return ACC_UA_GET_LE24(p);
#else
return acc_ua_get_le24(p);
#endif
}
inline void set_le24(void *p, unsigned v)
{
#if defined(ACC_UA_SET_LE24)
ACC_UA_SET_LE24(p, v);
#else
acc_ua_set_le24(p, v);
#endif
}
inline unsigned get_le32(const void *p)
{
#if defined(ACC_UA_GET_LE32)
return ACC_UA_GET_LE32(p);
#else
return acc_ua_get_le32(p);
#endif
}
inline void set_le32(void *p, unsigned v)
{
#if defined(ACC_UA_SET_LE32)
ACC_UA_SET_LE32(p, v);
#else
acc_ua_set_le32(p, v);
#endif
}
inline acc_uint64l_t get_le64(const void *p)
{
#if defined(ACC_UA_GET_LE64)
return ACC_UA_GET_LE64(p);
#else
return acc_ua_get_le64(p);
#endif
}
inline void set_le64(void *p, acc_uint64l_t v)
{
#if defined(ACC_UA_SET_LE64)
ACC_UA_SET_LE64(p, v);
#else
acc_ua_set_le64(p, v);
#endif
}
/*************************************************************************
// classes for portable unaligned access
// get signed values, i.e. sign-extend
**************************************************************************/
class BE16
inline int sign_extend(int v, int bits)
{
const unsigned sign_bit = 1u << (bits - 1);
v |= 0u - (v & sign_bit);
return v;
}
inline acc_int64l_t sign_extend(acc_int64l_t v, int bits)
{
const acc_uint64l_t sign_bit = ACC_UINT64_C(1) << (bits - 1);
v |= ACC_UINT64_C(0) - (v & sign_bit);
return v;
}
inline int get_be16_signed(const void *p)
{
int v = get_be16(p);
return sign_extend(v, 16);
}
inline int get_be24_signed(const void *p)
{
int v = get_be24(p);
return sign_extend(v, 24);
}
inline int get_be32_signed(const void *p)
{
int 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);
return sign_extend(v, 64);
}
inline int get_le16_signed(const void *p)
{
int v = get_le16(p);
return sign_extend(v, 16);
}
inline int get_le24_signed(const void *p)
{
int v = get_le24(p);
return sign_extend(v, 24);
}
inline int get_le32_signed(const void *p)
{
int v = get_le32(p);
return sign_extend(v, 32);
}
inline int get_le64_signed(const void *p)
{
acc_int64l_t v = get_le64(p);
return sign_extend(v, 64);
}
/*************************************************************************
// 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(!).
**************************************************************************/
struct BE16
{
unsigned char d[2];
public:
BE16& operator = (const BE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
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, 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 const unsigned () const { return get_be16(d); }
};
operator unsigned () const { return get_be16(d); }
}
__attribute_packed;
class BE32
struct BE32
{
unsigned char d[4];
public:
BE32& operator = (const BE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
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, 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 const unsigned () const { return get_be32(d); }
};
operator unsigned () const { return get_be32(d); }
}
__attribute_packed;
class LE16
struct BE64
{
unsigned char d[8];
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; }
operator acc_uint64l_t () const { return get_be64(d); }
}
__attribute_packed;
struct LE16
{
unsigned char d[2];
public:
LE16& operator = (const LE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
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, 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 const unsigned () const { return get_le16(d); }
};
operator unsigned () const { return get_le16(d); }
}
__attribute_packed;
class LE32
struct LE32
{
unsigned char d[4];
public:
LE32& operator = (const LE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
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, 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); }
}
__attribute_packed;
operator const unsigned () const { return get_le32(d); }
};
struct LE64
{
unsigned char d[8];
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; }
operator acc_uint64l_t () const { return get_le64(d); }
}
__attribute_packed;
/*************************************************************************
// global operators
**************************************************************************/
inline bool operator < (const BE16& v1, const BE16& v2)
{
return (const unsigned)v1 < (const unsigned)v2;
}
template <class T>
inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }
template <class T>
inline T* operator + (const BE16& v, T* ptr) { return ptr + (unsigned) v; }
template <class T>
inline T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }
inline bool operator < (const BE32& v1, const BE32& v2)
{
return (const unsigned)v1 < (const unsigned)v2;
}
template <class T>
inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; }
template <class T>
inline T* operator + (const BE32& v, T* ptr) { return ptr + (unsigned) v; }
template <class T>
inline T* operator - (T* ptr, const BE32& v) { return ptr - (unsigned) v; }
inline bool operator < (const LE16& v1, const LE16& v2)
{
return (const unsigned)v1 < (const unsigned)v2;
}
// these are not implemented on purpose and will cause link-time errors
template <class T> T* operator + (T* ptr, const BE64& v);
template <class T> T* operator + (const BE64& v, T* ptr);
template <class T> T* operator - (T* ptr, const BE64& v);
inline bool operator < (const LE32& v1, const LE32& v2)
{
return (const unsigned)v1 < (const unsigned)v2;
}
template <class T>
inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; }
template <class T>
inline T* operator + (const LE16& v, T* ptr) { return ptr + (unsigned) v; }
template <class T>
inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }
template <class T>
inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; }
template <class T>
inline T* operator + (const LE32& v, T* ptr) { return ptr + (unsigned) v; }
template <class T>
inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }
// these are not implemented on purpose and will cause link-time errors
template <class T> T* operator + (T* ptr, const LE64& v);
template <class T> T* operator + (const LE64& v, T* ptr);
template <class T> T* operator - (T* ptr, const LE64& v);
/*************************************************************************
@@ -247,10 +404,58 @@ inline bool operator < (const LE32& v1, const LE32& v2)
**************************************************************************/
// for use with qsort()
int be16_compare(const void *e1, const void *e2);
int be32_compare(const void *e1, const void *e2);
int le16_compare(const void *e1, const void *e2);
int le32_compare(const void *e1, const void *e2);
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 *);
int __acc_cdecl_qsort be64_compare(const void *, const void *);
int __acc_cdecl_qsort le16_compare(const void *, const void *);
int __acc_cdecl_qsort le24_compare(const void *, const void *);
int __acc_cdecl_qsort le32_compare(const void *, const void *);
int __acc_cdecl_qsort le64_compare(const void *, const void *);
int __acc_cdecl_qsort be16_compare_signed(const void *, const void *);
int __acc_cdecl_qsort be24_compare_signed(const void *, const void *);
int __acc_cdecl_qsort be32_compare_signed(const void *, const void *);
int __acc_cdecl_qsort be64_compare_signed(const void *, const void *);
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 *);
// just for testing...
#if !defined(ACC_CFG_NO_UNALIGNED)
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200)
typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1)));
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
# ifndef LE16
# define LE16 LE16_unaligned
# endif
# ifndef LE16
# define LE32 LE32_unaligned
# endif
#endif
#if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC)
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
# ifndef LE16
# define LE16 LE16_unaligned
# endif
# ifndef LE16
# define LE32 LE32_unaligned
# endif
#endif
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
# ifndef LE16
# define LE16 LE16_unaligned
# endif
# ifndef LE16
# define LE32 LE32_unaligned
# endif
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data
#endif
#endif
#endif /* already included */
+115
View File
@@ -0,0 +1,115 @@
/* bptr.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
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_BPTR_H
#define __UPX_BPTR_H
/*************************************************************************
// BoundedPtr
**************************************************************************/
template <class T>
class BoundedPtr
{
// typedef BoundedPtr<T> Self;
public:
typedef T* StoredType;
typedef T* PointerType;
typedef T& ReferenceType;
~BoundedPtr() { }
explicit BoundedPtr(void* base, unsigned size, T* ptr=0)
: ptr_(ptr), base_(base), size_(size) { check(); }
BoundedPtr& operator= (const BoundedPtr& other) {
assert(base_ == other.base_); assert(size_ == other.size_);
ptr_ = other.ptr_; check(); return *this;
}
BoundedPtr& operator= (T* other) {
ptr_ = other; check(); return *this;
}
operator T* () { check(); return ptr_; }
operator const T* () const { check(); return ptr_; }
BoundedPtr& operator += (size_t n) {
checkStrict(); ptr_ += n; checkStrict(); return *this;
}
BoundedPtr& operator -= (size_t n) {
checkStrict(); ptr_ -= n; checkStrict(); return *this;
}
BoundedPtr& operator ++ (void) {
checkStrict(); ptr_ += 1; checkStrict(); return *this;
}
// T* operator ++ (int) {
// T* p = ptr_; checkStrict(); ptr_ += 1; checkStrict(); return p;
// }
// BoundedPtr& operator -- (void) {
// checkStrict(); ptr_ -= 1; checkStrict(); return *this;
// }
private:
void checkNULL() const {
if (!ptr_)
throwCantUnpack("unexpected NULL pointer; take care!");
}
void checkRange(size_t extra=0) const {
size_t off = (const char *) ptr_ - (const char *) base_;
if (off > size_ || off + extra > size_)
throwCantUnpack("pointer out of range; take care!");
}
void checkStrict(size_t extra=0) const {
checkNULL();
checkRange(extra);
}
void check(size_t extra=0) const {
if (ptr_) checkRange(extra);
}
T* ptr_;
void* base_;
size_t size_;
// disable copy
BoundedPtr(const BoundedPtr&); // {}
// BoundedPtr& operator= (const BoundedPtr&); // { return *this; }
// disable dynamic allocation
DISABLE_NEW_DELETE
};
#endif /* already included */
/*
vi:ts=4:et
*/
+5 -5
View File
@@ -1,9 +1,9 @@
/* c_file.cpp -- file console output
/* c_file.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
+9 -9
View File
@@ -1,9 +1,9 @@
/* c_init.cpp -- console initialization
/* c_init.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -81,7 +81,7 @@ static int do_init(FILE *f)
if (opt->console == CON_NONE || opt->to_stdout)
return con_mode;
try_init(&console_file,f);
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO) || !isatty(STDERR_FILENO))
if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO))
return con_mode;
#if defined(USE_ANSI)
@@ -142,13 +142,13 @@ console_t console_init =
};
void con_fprintf(FILE *f, const char *format, ...)
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
{
va_list args;
char buf[80*25];
va_start(args,format);
upx_vsnprintf(buf,sizeof(buf),format,args);
va_start(args, format);
upx_vsnprintf(buf, sizeof(buf), format,args);
va_end(args);
if (con == me)
+5 -5
View File
@@ -1,9 +1,9 @@
/* c_none.cpp -- dummy console output
/* c_none.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
+7 -7
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -88,7 +88,7 @@ static screen_t *do_construct(screen_t *s, int fd)
static screen_t *screen = NULL;
static void do_destroy(void)
static void __acc_cdecl_atexit do_destroy(void)
{
if (screen)
{
@@ -130,7 +130,7 @@ static int init(FILE *f, int o, int now)
if (!screen)
screen = do_construct(screen_djgpp2_construct(),fd);
#endif
#if defined(__MFX_WIN32)
#if defined(USE_SCREEN_WIN32)
if (!screen)
screen = do_construct(screen_win32_construct(),fd);
#endif
@@ -196,7 +196,7 @@ static void print0(FILE *f, const char *ss)
// Note:
// We use 2 passes to avoid unnecessary system calls because
// scrollUp() under Win95/98 is *extremely* slow.
// scrollUp() under Win32 is *extremely* slow.
UNUSED(f);
screen->getCursor(screen,&old_cx,&old_cy);
+278
View File
@@ -0,0 +1,278 @@
/* compress.ch --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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>
*/
#if 1 && defined(UCL_USE_ASM)
# include <ucl/ucl_asm.h>
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
# define ucl_nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
# define ucl_nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
# define ucl_nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
# define ucl_nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
# define ucl_nrv2e_decompress_safe_8 ucl_nrv2e_decompress_asm_safe_8
# define ucl_nrv2e_decompress_safe_le16 ucl_nrv2e_decompress_asm_safe_le16
# define ucl_nrv2e_decompress_safe_le32 ucl_nrv2e_decompress_asm_safe_le32
#endif
/*************************************************************************
//
**************************************************************************/
#if defined(upx_adler32)
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
{
if (len == 0)
return adler;
assert(buf != NULL);
return ucl_adler32(adler, (const ucl_bytep)buf, len);
}
#endif
#if defined(upx_crc32)
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
{
if (len == 0)
return crc;
assert(buf != NULL);
return ucl_crc32(crc, (const ucl_bytep)buf, len);
}
#endif
/*************************************************************************
//
**************************************************************************/
#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 method, int level,
const struct upx_compress_config_t *conf_parm,
upx_uintp result )
{
struct upx_compress_config_t conf;
upx_uint result_buffer[16];
int r = UPX_E_ERROR;
assert(level > 0);
memset(&conf, 0xff, sizeof(conf));
if (conf_parm)
conf = *conf_parm; // struct copy
if (!result)
result = result_buffer;
// 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
// prepare bit-buffer settings
conf.bb_endian = 0;
conf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
{
static const unsigned char sizes[3]={32,8,16};
conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
}
else
throwInternalError("unknown compression method");
// 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 M_IS_NRV2B(method)
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
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)
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
throwInternalError("unknown compression method");
return 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 r = UPX_E_ERROR;
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
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;
case M_NRV2E_LE16:
r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
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 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 r = UPX_E_ERROR;
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
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;
case M_NRV2E_LE16:
r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
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 r;
}
#endif /* upx_test_overlap */
/*
vi:ts=4:et:nowrap
*/
+16 -236
View File
@@ -1,9 +1,9 @@
/* compress.cpp -- interface to the compression library
/* compress.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,248 +21,28 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#if defined(WITH_UCL) && !defined(WITH_NRV)
# define nrv2b_99_compress_internal ucl_nrv2b_99_compress
# define nrv2d_99_compress_internal ucl_nrv2d_99_compress
# if 0 && defined(__i386__)
# include <ucl/ucl_asm.h>
# define nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
# define nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
# define nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
# define nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
# define nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
# define nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
# else
# define nrv2b_decompress_safe_8 ucl_nrv2b_decompress_safe_8
# define nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_safe_le16
# define nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_safe_le32
# define nrv2d_decompress_safe_8 ucl_nrv2d_decompress_safe_8
# define nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_safe_le16
# define nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_safe_le32
# endif
#endif
#if defined(WITH_NRV)
# include <nrv/nrv2b.h>
# include <nrv/nrv2d.h>
# if !defined(NRV_VERSION) || (NRV_VERSION < 0x007300L)
# error
# endif
# if 1 && defined(__i386__)
# define nrv2b_decompress_safe_8 nrv2b_decompress_asm_safe_8
# define nrv2b_decompress_safe_le16 nrv2b_decompress_asm_safe_le16
# define nrv2d_decompress_safe_8 nrv2d_decompress_asm_safe_8
# define nrv2d_decompress_safe_le16 nrv2d_decompress_asm_safe_le16
# if (NRV_VERSION < 0x008000L)
# define nrv2b_decompress_safe_le32 nrv2b_decompress_asm_safe
# define nrv2d_decompress_safe_le32 nrv2d_decompress_asm_safe
# else
# define nrv2b_decompress_safe_le32 nrv2b_decompress_asm_safe_le32
# define nrv2d_decompress_safe_le32 nrv2d_decompress_asm_safe_le32
# endif
# endif
NRV_EXTERN_CDECL(int) nrv2b_99_compress_internal(...);
NRV_EXTERN_CDECL(int) nrv2d_99_compress_internal(...);
NRV_EXTERN_CDECL(int) nrv2b_decompress_safe_8(...);
NRV_EXTERN_CDECL(int) nrv2b_decompress_safe_le16(...);
NRV_EXTERN_CDECL(int) nrv2b_decompress_safe_le32(...);
NRV_EXTERN_CDECL(int) nrv2d_decompress_safe_8(...);
NRV_EXTERN_CDECL(int) nrv2d_decompress_safe_le16(...);
NRV_EXTERN_CDECL(int) nrv2d_decompress_safe_le32(...);
# include "compress_nrv.ch"
#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"
#else
# error
#endif
#if 0 && defined(WITH_ZLIB) && defined(M_ZLIB)
# include <zlib.h>
#endif
/*************************************************************************
//
**************************************************************************/
int upx_compress ( const upx_byte *src, upx_uint src_len,
upx_byte *dst, upx_uint *dst_len,
upx_progress_callback_t *cb,
int method, int level,
const struct upx_compress_config_t *conf_parm,
upx_uintp result)
{
struct upx_compress_config_t conf;
upx_uint result_buffer[16];
int r = UPX_E_ERROR;
assert(level > 0);
memset(&conf, 0xff, sizeof(conf));
if (conf_parm)
conf = *conf_parm; // struct copy
if (!result)
result = result_buffer;
// 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
#if 0 && defined(WITH_ZLIB) && defined(M_ZLIB)
if (method == M_ZLIB)
{
uLong destLen = src_len + src_len / 8 + 256;
r = compress2(dst, &destLen, src, src_len, UPX_MIN(level, 9));
*dst_len = destLen;
if (r == Z_MEM_ERROR)
return UPX_E_OUT_OF_MEMORY;
if (r != Z_OK)
return UPX_E_ERROR;
return UPX_E_OK;
}
#endif
// prepare bit-buffer settings
conf.bb_endian = 0;
conf.bb_size = 0;
if (method == M_NRV2B_LE32 || method == M_NRV2D_LE32)
conf.bb_size = 32;
else if (method == M_NRV2B_8 || method == M_NRV2D_8)
conf.bb_size = 8;
else if (method == M_NRV2B_LE16 || method == M_NRV2D_LE16)
conf.bb_size = 16;
else
throwInternalError("unknown compression method");
#if 1 && defined(WITH_NRV)
if (level == 1 && conf.bb_size == 32 &&
conf.max_offset == UPX_UINT_MAX && conf.max_match == UPX_UINT_MAX)
{
if (method == M_NRV2B_LE32)
{
upx_byte wrkmem[NRV2B_1_16_MEM_COMPRESS];
#if defined(__UPX_CHECKER)
memset(wrkmem,0,NRV2B_1_16_MEM_COMPRESS);
#endif
r = nrv2b_1_16_compress(src, src_len, dst, dst_len, wrkmem);
}
else if (method == M_NRV2D_LE32)
{
upx_byte wrkmem[NRV2D_1_16_MEM_COMPRESS];
#if defined(__UPX_CHECKER)
memset(wrkmem,0,NRV2D_1_16_MEM_COMPRESS);
#endif
r = nrv2d_1_16_compress(src, src_len, dst, dst_len, wrkmem);
}
else
throwInternalError("unknown compression method");
return r;
}
#endif
// 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 defined(WITH_NRV)
else if (level <= 7 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 1024*1024-1;
else if (level <= 8 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 2048*1024-1;
else if (level <= 10 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 4096*1024-1;
#endif
if M_IS_NRV2B(method)
r = nrv2b_99_compress_internal(src, src_len, dst, dst_len,
cb, level, &conf, result);
else if M_IS_NRV2D(method)
r = nrv2d_99_compress_internal(src, src_len, dst, dst_len,
cb, level, &conf, result);
else
throwInternalError("unknown compression method");
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_decompress ( const upx_byte *src, upx_uint src_len,
upx_byte *dst, upx_uint *dst_len,
int method )
{
int r = UPX_E_ERROR;
#if 0 && defined(WITH_ZLIB) && defined(M_ZLIB)
if (method == M_ZLIB)
{
uLong destLen = *dst_len;
r = uncompress(dst, &destLen, src, src_len);
*dst_len = destLen;
if (r == Z_MEM_ERROR)
return UPX_E_OUT_OF_MEMORY;
if (r != Z_OK)
return UPX_E_ERROR;
return UPX_E_OK;
}
#endif
if (method == M_NRV2B_LE32)
r = nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
else if (method == M_NRV2B_8)
r = nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
else if (method == M_NRV2B_LE16)
r = nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
else if (method == M_NRV2D_LE32)
r = nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
else if (method == M_NRV2D_8)
r = nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL);
else if (method == M_NRV2D_LE16)
r = nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
else
throwInternalError("unknown decompression method");
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_test_overlap ( const upx_byte *buf, upx_uint src_off,
upx_uint src_len, upx_uint *dst_len,
int method )
{
int r = UPX_E_ERROR;
if (method == M_NRV2B_LE32)
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
else if (method == M_NRV2B_8)
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
else if (method == M_NRV2B_LE16)
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
else if (method == M_NRV2D_LE32)
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
else if (method == M_NRV2D_8)
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
else if (method == M_NRV2D_LE16)
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
else
throwInternalError("unknown decompression method");
return r;
}
/*
vi:ts=4:et:nowrap
+275 -332
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,31 +21,107 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#ifndef __UPX_CONF_H
#define __UPX_CONF_H
#if 0 && defined(__EMX__)
# include <sys/emx.h>
#endif
#if defined(UPX_CONFIG_H)
# include UPX_CONFIG_H
#endif
#include <limits.h>
#include "version.h"
#include "tailor.h"
#if !defined(__i386__)
# if defined(__386__) || defined(_M_IX86)
# define __i386__ 1
/*************************************************************************
// ACC
**************************************************************************/
#include "miniacc.h"
#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__)
# undef HAVE_UTIME_H /* this pulls in <windows.h> */
#endif
#if (ACC_CC_BORLANDC)
# if (__BORLANDC__ < 0x0500)
# error "need Borland C++ 5.0 or newer"
# endif
# pragma warn -aus // 8004: 'x' is assigned a value that is never used
# pragma warn -inl // 8026+8027: Function not expanded inline
// Borland compilers typically produce a number of bogus warnings, and
// the actual diagnostics vary from version to version...
# if (__BORLANDC__ < 0x0530)
# pragma warn -csu // 8012: Comparing signed and unsigned values
# endif
# if (__BORLANDC__ >= 0x0530 && __BORLANDC__ < 0x0560)
# pragma warn -osh // 8055: Possible overflow in shift operation
# endif
# if (__BORLANDC__ >= 0x0560)
# pragma warn -use // 8080: 'x' is declared but never used
# endif
#elif (ACC_CC_DMC)
# if (__DMC__ < 0x829)
# error "need Digital Mars C++ 8.29 or newer"
# endif
#elif (ACC_CC_INTELC)
# if (__INTEL_COMPILER < 450)
# error "need Intel C++ 4.5 or newer"
# endif
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
# elif defined(__linux__)
# pragma warning(error: 424) // #424: extra ";" ignored
# pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier
# pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits
# pragma warning(disable: 981) // #981: operands are evaluated in unspecified order
# pragma warning(disable: 1418) // #1418: external definition with no prior declaration
# else
# error "untested platform"
# endif
#elif (ACC_CC_MSC)
# if (_MSC_VER < 1100)
# error "need Visual C++ 5.0 or newer"
# endif
# pragma warning(error: 4096) // W2: '__cdecl' must be used with '...'
# pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B'
# pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated
# pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated
# pragma warning(disable: 4514) // W4: 'function': unreferenced inline function has been removed
# pragma warning(disable: 4710) // W4: 'function': function not inlined
# if (_MSC_VER >= 1300)
# pragma warning(disable: 4625) // W4: 'class' : copy constructor could not be generated because a base class copy constructor is inaccessible
# pragma warning(disable: 4626) // W4: 'class' : assignment operator could not be generated because a base class assignment operator is inaccessible
# pragma warning(disable: 4711) // W4: 'function' selected for automatic inline expansion
# pragma warning(disable: 4820) // W4: 'struct' : 'x' bytes padding added after member 'member'
# endif
# if (_MSC_VER >= 1400)
# pragma warning(disable: 4996) // W1: 'function': was declared deprecated
# endif
#elif (ACC_CC_WATCOMC)
# if (__WATCOMC__ < 1100)
# error "need Watcom C++ 11.0c or newer"
# endif
# if defined(__cplusplus)
# pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality)
# endif
#endif
#define ACC_WANT_ACC_INCD_H 1
#define ACC_WANT_ACC_INCE_H 1
#define ACC_WANT_ACC_LIB_H 1
#define ACC_WANT_ACC_CXX_H 1
#include "miniacc.h"
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
# error "something pulled in <windows.h>"
# endif
#endif
/*************************************************************************
//
**************************************************************************/
#if defined(__linux__) && !defined(__unix__)
# define __unix__ 1
#endif
@@ -56,12 +132,28 @@
#undef linux
#undef small
#undef tos
#undef unix
#if defined(ACC_CC_DMC)
# undef tell
#endif
#if !defined(ACC_CC_PGI)
# undef unix
#endif
#if defined(__DJGPP__)
# undef sopen
# undef __unix__
# 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
@@ -70,49 +162,24 @@
# 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_adler32 ucl_adler32
# 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_ENTRY __UCL_ENTRY
# define __UPX_CDECL __UCL_CDECL
# endif
#endif
#if defined(WITH_NRV)
# include <nrv/nrvconf.h>
# if !defined(UPX_UINT_MAX)
# define UPX_UINT_MAX NRV_UINT_MAX
# define upx_uint nrv_uint
# define upx_voidp nrv_voidp
# define upx_uintp nrv_uintp
# define upx_byte nrv_byte
# define upx_bytep nrv_bytep
# define upx_bool nrv_bool
# define upx_progress_callback_t nrv_progress_callback_t
# define upx_adler32 nrv_adler32
# define UPX_E_OK NRV_E_OK
# define UPX_E_ERROR NRV_E_ERROR
# define UPX_E_OUT_OF_MEMORY NRV_E_OUT_OF_MEMORY
# define __UPX_ENTRY __NRV_ENTRY
# endif
#endif
#if !defined(__UPX_CHECKER)
# if defined(__UCL_CHECKER) || defined(__NRV_CHECKER)
# define __UPX_CHECKER
# endif
#endif
#if !defined(UPX_UINT_MAX) || (UINT_MAX < 0xffffffffL)
# error "you lose"
#endif
#if !defined(WITH_UCL)
# error "you lose"
#endif
#if !defined(UCL_VERSION) || (UCL_VERSION < 0x009200L)
# error "please upgrade your UCL installation"
#endif
#ifndef WITH_ZLIB
# define WITH_ZLIB 1
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
# error "UINT_MAX"
#endif
@@ -120,64 +187,10 @@
// system includes
**************************************************************************/
#if !defined(NO_SYS_TYPES_H)
# include <sys/types.h>
#endif
#define NDEBUG
#undef NDEBUG
#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <errno.h>
#if !defined(NO_FCNTL_H)
# include <fcntl.h>
#endif
#if !defined(NO_SYS_STAT_H)
# include <sys/stat.h>
#endif
#if defined(HAVE_IO_H) && !defined(NO_IO_H)
# include <io.h>
#endif
#if defined(HAVE_DOS_H) && !defined(NO_DOS_H)
# include <dos.h>
#endif
#if defined(HAVE_MALLOC_H) && !defined(NO_MALLOC_H)
# include <malloc.h>
#endif
#if defined(HAVE_ALLOCA_H) && !defined(NO_ALLOCA_H)
# include <alloca.h>
#endif
#if defined(HAVE_SIGNAL_H)
# include <signal.h>
#endif
#if defined(HAVE_UNISTD_H)
# include <unistd.h>
#endif
#if defined(TIME_WITH_SYS_TIME)
# include <sys/time.h>
# include <time.h>
#else
# include <time.h>
#endif
#if defined(HAVE_UTIME_H)
# include <utime.h>
#elif defined(HAVE_SYS_UTIME_H)
# include <sys/utime.h>
#endif
#if defined(HAVE_SHARE_H)
# include <share.h>
#endif
// malloc debuggers
#if defined(WITH_DMALLOC)
#if defined(WITH_VALGRIND)
# include <valgrind/memcheck.h>
#elif defined(WITH_DMALLOC)
# define DMALLOC_FUNC_CHECK
# include <dmalloc.h>
#elif defined(WITH_GC)
@@ -189,60 +202,31 @@
# define malloc GC_MALLOC
# define realloc GC_REALLOC
# define free GC_FREE
#elif defined(WITH_MSS)
# define MSS
# include <mss.h>
#endif
#if !defined(VALGRIND_MAKE_WRITABLE)
# define VALGRIND_MAKE_WRITABLE(addr,len) 0
#endif
#if !defined(VALGRIND_MAKE_READABLE)
# if 0
# define VALGRIND_MAKE_READABLE(addr,len) (memset(addr,0,len), 0)
# else
# define VALGRIND_MAKE_READABLE(addr,len) 0
# endif
#endif
#if !defined(VALGRIND_DISCARD)
# define VALGRIND_DISCARD(handle) ((void)(&handle))
#endif
#undef NDEBUG
#include <assert.h>
/*************************************************************************
// portab
**************************************************************************/
#if defined(NO_BOOL)
typedef int bool;
enum { false, true };
#endif
#if !defined(PATH_MAX)
# define PATH_MAX 512
#elif (PATH_MAX < 512)
# undef PATH_MAX
# define PATH_MAX 512
#endif
#ifndef RETSIGTYPE
# define RETSIGTYPE void
#endif
#ifndef SIGTYPEENTRY
# define SIGTYPEENTRY
#endif
typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
#undef MODE_T
#if defined(HAVE_MODE_T)
# define MODE_T mode_t
#else
# define MODE_T int
#endif
#if !defined(HAVE_STRCASECMP)
# if defined(HAVE_STRICMP)
# define strcasecmp stricmp
# else
# define strcasecmp strcmp
# endif
#endif
#if !defined(HAVE_STRNCASECMP)
# if defined(HAVE_STRNICMP)
# define strncasecmp strnicmp
# else
# define strncasecmp strncmp
# endif
#endif
#ifndef STDIN_FILENO
# define STDIN_FILENO (fileno(stdin))
#endif
@@ -254,6 +238,14 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
#endif
#if !defined(HAVE_STRCASECMP) && defined(HAVE_STRICMP)
# define strcasecmp stricmp
#endif
#if !defined(HAVE_STRNCASECMP) && defined(HAVE_STRNICMP)
# define strncasecmp strnicmp
#endif
#if !defined(S_IWUSR) && defined(_S_IWUSR)
# define S_IWUSR _S_IWUSR
#elif !defined(S_IWUSR) && defined(_S_IWRITE)
@@ -277,14 +269,14 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
# if defined(S_IFMT) && defined(S_IFREG)
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
# else
# error S_ISREG
# error "S_ISREG"
# endif
#endif
#if !defined(S_ISDIR)
# if defined(S_IFMT) && defined(S_IFDIR)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# else
# error S_ISDIR
# error "S_ISDIR"
# endif
#endif
#if !defined(S_ISCHR)
@@ -295,53 +287,66 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
// avoid warnings about shadowing global functions
#undef index
#define basename upx_basename
#define index upx_index
#define outp upx_outp
// a dummy statement
#define nop ((void)0)
/*************************************************************************
// file io
**************************************************************************/
#if defined(HAVE_SETMODE)
# if !defined(O_BINARY)
# error "setmode without O_BINARY"
#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
# define USE_SETMODE 1
#else
# define __attribute_packed
#endif
#if !defined(O_BINARY)
# define O_BINARY 0
#endif
#if defined(__DJGPP__)
# undef sopen
# undef USE_SETMODE
#ifndef OPTIONS_VAR
# define OPTIONS_VAR "UPX"
#endif
/*************************************************************************
// memory util
//
**************************************************************************/
#undef FREE
#define FREE(ptr) if (ptr) { free(ptr); ptr = NULL; }
#define UNUSED(var) ACC_UNUSED(var)
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
#undef UNUSED
#if defined(__BORLANDC__)
#define UNUSED(parm) ((void)(parm))
#if 1
# 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)) \
}
#else
#define UNUSED(parm) (parm = parm)
# 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
#define HIGH(array) ((unsigned) (sizeof(array)/sizeof((array)[0])))
#if defined(__acc_alignof)
# 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) \
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
#endif
#define TABLESIZE(table) ((sizeof(table)/sizeof((table)[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))
#define UPX_MAX(a,b) ((a) >= (b) ? (a) : (b))
#define UPX_MIN(a,b) ((a) <= (b) ? (a) : (b))
@@ -349,56 +354,49 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int);
#define UPX_MIN3(a,b,c) ((a) <= (b) ? UPX_MIN(a,c) : UPX_MIN(b,c))
#if 0 && defined(__cplusplus)
#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);
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);
printf("new[] %6ld %p\n",(long)l,p);
fflush(stdout);
return p;
}
inline void operator delete(void *p)
{
printf("delete %p\n",p);
printf("delete %p\n",p);
fflush(stdout);
if (p) free(p);
}
inline void operator delete[](void *p)
{
printf("delete %p\n",p);
printf("delete[] %p\n",p);
fflush(stdout);
if (p) free(p);
}
#endif
// A autoheap_array allocates memory on the heap, but automatically
// An Array allocates memory on the heap, but automatically
// gets destructed when leaving scope or on exceptions.
// "var" is declared as a read-only reference to a pointer
// and behaves exactly like an array "var[]".
#if 0
# define autoheap_array(type, var, size) \
#define Array(type, var, size) \
assert((int)(size) > 0); \
vector<type> var ## _autoheap_vec((size)); \
type * const & var = & var ## _autoheap_vec[0]
#else
# define autoheap_array(type, var, size) \
assert((int)(size) > 0); \
MemBuffer var ## _autoheap_buf((size)*(sizeof(type))); \
type * const & var = (type *) (unsigned char *) var ## _autoheap_buf
#endif
MemBuffer var ## _membuf((size)*(sizeof(type))); \
type * const var = ((type *) var ## _membuf.getVoidPtr())
#define ByteArray(var, size) Array(unsigned char, var, size)
/*************************************************************************
//
// constants
**************************************************************************/
/* exit codes of this program: 0 ok, 1 error, 2 warning */
@@ -422,124 +420,77 @@ inline void operator delete[](void *p)
#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_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)
// Executable formats. Note: big endian types are >= 128.
#define UPX_F_DOS_COM 1
#define UPX_F_DOS_SYS 2
#define UPX_F_DOS_EXE 3
#define UPX_F_DJGPP2_COFF 4
#define UPX_F_WATCOM_LE 5
#define UPX_F_VXD_LE 6
#define UPX_F_DOS_EXEH 7 /* OBSOLETE */
#define UPX_F_TMT_ADAM 8
#define UPX_F_WIN32_PE 9
#define UPX_F_LINUX_i386 10
#define UPX_F_WIN16_NE 11
#define UPX_F_LINUX_ELF_i386 12
#define UPX_F_LINUX_SEP_i386 13
#define UPX_F_LINUX_SH_i386 14
#define UPX_F_VMLINUZ_i386 15
#define UPX_F_BVMLINUZ_i386 16
#define UPX_F_ELKS_8086 17
#define UPX_F_PS1_EXE 18
#define UPX_F_VMLINUX_i386 19
#define UPX_F_LINUX_ELFI_i386 20
#define UPX_F_WINCE_ARM_PE 21
#define UPX_F_LINUX_ELF64_AMD 22
#define UPX_F_PLAIN_TEXT 127
#define UPX_F_ATARI_TOS 129
#define UPX_F_SOLARIS_SPARC 130
#define UPX_F_MACH_PPC32 131
#define UPX_F_LINUX_ELFPPC32 132
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
#define UPX_MAGIC2_LE32 0xD5D0D8A1
/*************************************************************************
// globals
**************************************************************************/
#include "unupx.h"
#include "snprintf.h"
#if defined(__cplusplus)
#include "stdcxx.h"
#include "options.h"
#include "except.h"
#include "bele.h"
#include "util.h"
#include "console.h"
// options
enum {
CMD_NONE,
CMD_COMPRESS, CMD_DECOMPRESS, CMD_TEST, CMD_LIST, CMD_FILEINFO,
CMD_HELP, CMD_LICENSE, CMD_VERSION
};
struct options_t {
int cmd;
// compression options
int method;
int level; // compression level 1..10
int mem_level; // memory level 1..9
int filter; // preferred filter from Packer::getFilters()
bool all_filters; // try all filters ?
// other options
int backup;
int console;
int debug;
int force;
int info_mode;
bool ignorewarn;
bool no_env;
bool no_progress;
const char *output_name;
int small;
int verbose;
bool to_stdout;
// overlay handling
enum {
SKIP_OVERLAY = 0,
COPY_OVERLAY = 1,
STRIP_OVERLAY = 2
};
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;
// CPU
enum {
CPU_DEFAULT = 0,
CPU_8086 = 1,
CPU_286 = 2,
CPU_386 = 3,
CPU_486 = 4,
CPU_586 = 5,
CPU_686 = 6
};
int cpu;
// options for various executable formats
struct {
bool force_stub;
bool no_reloc;
} dos;
struct {
bool coff;
} djgpp2;
struct {
bool split_segments;
} tos;
struct {
unsigned blocksize;
enum { SCRIPT_MAX = 32 };
const char *script_name;
} unix;
struct {
bool le;
} wcle;
struct {
int compress_exports;
int compress_icons;
bool compress_resources;
int strip_relocs;
} w32pe;
};
extern struct options_t * volatile opt;
// main.cpp
extern const char *progname;
void init_options(struct options_t *o);
bool set_ec(int ec);
#if defined(__GNUC__)
void e_exit(int ec) __attribute__((noreturn));
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void e_exit(int ec) __attribute__((__noreturn__));
#else
void e_exit(int ec);
#endif
@@ -549,28 +500,28 @@ void e_exit(int ec);
void printSetNl(int need_nl);
void printClearLine(FILE *f = NULL);
void printErr(const char *iname, const Throwable *e);
void printUnhandledException(const char *iname, const exception *e);
#if defined(__GNUC__)
void printErr(const char *iname, const char *format, ...)
__attribute__((format(printf,2,3)));
void printWarn(const char *iname, const char *format, ...)
__attribute__((format(printf,2,3)));
void printUnhandledException(const char *iname, const std::exception *e);
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
__attribute__((__format__(__printf__,2,3)));
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
__attribute__((__format__(__printf__,2,3)));
#else
void printErr(const char *iname, const char *format, ...);
void printWarn(const char *iname, const char *format, ...);
void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
#endif
#if defined(__GNUC__)
void infoWarning(const char *format, ...)
__attribute__((format(printf,1,2)));
void infoHeader(const char *format, ...)
__attribute__((format(printf,1,2)));
void info(const char *format, ...)
__attribute__((format(printf,1,2)));
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void __acc_cdecl_va infoWarning(const char *format, ...)
__attribute__((__format__(__printf__,1,2)));
void __acc_cdecl_va infoHeader(const char *format, ...)
__attribute__((__format__(__printf__,1,2)));
void __acc_cdecl_va info(const char *format, ...)
__attribute__((__format__(__printf__,1,2)));
#else
void infoWarning(const char *format, ...);
void infoHeader(const char *format, ...);
void info(const char *format, ...);
void __acc_cdecl_va infoWarning(const char *format, ...);
void __acc_cdecl_va infoHeader(const char *format, ...);
void __acc_cdecl_va info(const char *format, ...);
#endif
void infoHeader();
void infoWriting(const char *what, long size);
@@ -590,41 +541,33 @@ void show_version(int);
// compress.cpp
#if defined(WITH_UCL)
#define upx_compress_config_t ucl_compress_config_t
#elif defined(WITH_NRV)
struct nrv_compress_config_t;
struct nrv_compress_config_t
{
int bb_endian;
int bb_size;
nrv_uint max_offset;
nrv_uint max_match;
int s_level;
int h_level;
int p_level;
int c_flags;
nrv_uint m_size;
};
#define upx_compress_config_t nrv_compress_config_t
#endif
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_byte *src, upx_uint src_len,
upx_byte *dst, upx_uint *dst_len,
int upx_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_progress_callback_t *cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result);
int upx_decompress ( const upx_byte *src, upx_uint src_len,
upx_byte *dst, upx_uint *dst_len,
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_byte *buf, upx_uint src_off,
upx_uint src_len, upx_uint *dst_len,
int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method );
#endif /* __cplusplus */
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
# error "something pulled in <windows.h>"
# endif
#endif
#endif /* already included */
-240
View File
@@ -1,240 +0,0 @@
/* pseudo <config.h> for Linux */
#ifndef __UPX_CONFIG_H
#define __UPX_CONFIG_H
/* $TOP$ */
/* Define to empty if the keyword does not work. */
/* #undef const */
/* Define if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */
/* Define as the return type of signal handlers (int or void). */
#define RETSIGTYPE void
/* Define to `unsigned' if <sys/types.h> doesn't define. */
/* #undef size_t */
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define if your memcmp is broken. */
/* #undef NO_MEMCMP */
/* Define to `long' if <stddef.h> doesn't define. */
/* #undef ptrdiff_t */
/* The number of bytes in a ptrdiff_t. */
#define SIZEOF_PTRDIFF_T 4
/* The number of bytes in a size_t. */
#define SIZEOF_SIZE_T 4
/* Define when using the dmalloc package. */
/* #undef WITH_DMALLOC */
/* Define if you have the access function. */
#define HAVE_ACCESS 1
/* Define if you have the atoi function. */
#define HAVE_ATOI 1
/* Define if you have the chmod function. */
#define HAVE_CHMOD 1
/* Define if you have the chown function. */
#define HAVE_CHOWN 1
/* Define if you have the ctime function. */
#define HAVE_CTIME 1
/* Define if you have the difftime function. */
#define HAVE_DIFFTIME 1
/* Define if you have the fchmod function. */
#define HAVE_FCHMOD 1
/* Define if you have the fileno function. */
#define HAVE_FILENO 1
/* Define if you have the fstat function. */
#define HAVE_FSTAT 1
/* Define if you have the XXX function. */
#define HAVE_GETPID 1
/* Define if you have the XXX function. */
#define HAVE_GETTIMEOFDAY 1
/* Define if you have the getumask function. */
/* #undef HAVE_GETUMASK */
/* Define if you have the gmtime function. */
#define HAVE_GMTIME 1
/* Define if you have the index function. */
#define HAVE_INDEX 1
/* Define if you have the isatty function. */
#define HAVE_ISATTY 1
/* Define if you have the lstat function. */
#define HAVE_LSTAT 1
/* Define if you have the localtime function. */
#define HAVE_LOCALTIME 1
/* Define if you have the memcmp function. */
#define HAVE_MEMCMP 1
/* Define if you have the memcpy function. */
#define HAVE_MEMCPY 1
/* Define if you have the memmove function. */
#define HAVE_MEMMOVE 1
/* Define if you have the memset function. */
#define HAVE_MEMSET 1
/* Define if you have the mktime function. */
#define HAVE_MKTIME 1
/* Define if you have the setmode function. */
/* #undef HAVE_SETMODE */
/* Define if you have the stat function. */
#define HAVE_STAT 1
/* Define if you have the strcasecmp function. */
#define HAVE_STRCASECMP 1
/* Define if you have the strchr function. */
#define HAVE_STRCHR 1
/* Define if you have the strdup function. */
#define HAVE_STRDUP 1
/* Define if you have the strftime function. */
#define HAVE_STRFTIME 1
/* Define if you have the stricmp function. */
/* #undef HAVE_STRICMP */
/* Define if you have the strncasecmp function. */
#define HAVE_STRNCASECMP 1
/* Define if you have the strnicmp function. */
/* #undef HAVE_STRNICMP */
/* Define if you have the strstr function. */
#define HAVE_STRSTR 1
/* Define if you have the tzset function. */
#define HAVE_TZSET 1
/* Define if you have the umask function. */
#define HAVE_UMASK 1
/* Define if you have the utime function. */
#define HAVE_UTIME 1
/* Define if you have the vsnprintf function. */
#define HAVE_VSNPRINTF 1
/* Define if you have the <assert.h> header file. */
#define HAVE_ASSERT_H 1
/* Define if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
/* Define if you have the <curses.h> header file. */
#define HAVE_CURSES_H 1
/* Define if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define if you have the <linux/kd.h> header file. */
#define HAVE_LINUX_KD_H 1
/* Define if you have the <linux/kdev_t.h> header file. */
#define HAVE_LINUX_KDEV_T_H 1
/* Define if you have the <linux/major.h> header file. */
#define HAVE_LINUX_MAJOR_H 1
/* Define if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define if you have the <ncurses.h> header file. */
#define HAVE_NCURSES_H 1
/* Define if you have the <signal.h> header file. */
#define HAVE_SIGNAL_H 1
/* Define if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define if you have the <sys/times.h> header file. */
#define HAVE_SYS_TIMES_H 1
/* Define if you have the <sys/utime.h> header file. */
/* #undef HAVE_SYS_UTIME_H */
/* Define if you have the <time.h> header file. */
#define HAVE_TIME_H 1
/* Define if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define if you have the <utime.h> header file. */
#define HAVE_UTIME_H 1
/* $BOTTOM$ */
#if defined(HAVE_GMTIME) && !defined(TIME_WITH_SYS_TIME)
# undef /**/ HAVE_GMTIME
#endif
#if defined(HAVE_LOCALTIME) && !defined(TIME_WITH_SYS_TIME)
# undef /**/ HAVE_LOCALTIME
#endif
#if defined(HAVE_STRFTIME) && !defined(TIME_WITH_SYS_TIME)
# undef /**/ HAVE_STRFTIME
#endif
#if defined(HAVE_SYS_RESOURCE_H) && !defined(TIME_WITH_SYS_TIME)
# undef /**/ HAVE_SYS_RESOURCE_H
#endif
#if defined(HAVE_SYS_TIMES_H) && !defined(TIME_WITH_SYS_TIME)
# undef /**/ HAVE_SYS_TIMES_H
#endif
#if (SIZEOF_PTRDIFF_T <= 0)
# undef /**/ SIZEOF_PTRDIFF_T
#endif
#if (SIZEOF_SIZE_T <= 0)
# undef /**/ SIZEOF_SIZE_T
#endif
#endif /* already included */
/*
vi:ts=4
*/
+14 -11
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -34,8 +34,9 @@
#undef USE_CONSOLE
#undef USE_ANSI
#undef USE_SCREEN
#undef USE_SCREEN_VCSA
#undef USE_SCREEN_CURSES
#undef USE_SCREEN_VCSA
#undef USE_SCREEN_WIN32
#undef USE_FRAMES
#if defined(WITH_GUI) && !defined(NO_CONSOLE)
@@ -57,10 +58,12 @@
#if 1 && defined(__DJGPP__)
# define USE_SCREEN
#endif
#if 1 && defined(__MFX_WIN32)
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
# define USE_SCREEN
# define USE_SCREEN_WIN32
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
# define USE_SCREEN
# define USE_SCREEN_WIN32
#endif
@@ -120,10 +123,10 @@ console_t;
#if defined(__GNUC__)
void con_fprintf(FILE *f, const char *format, ...)
__attribute__((format(printf,2,3)));
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...)
__attribute__((__format__(printf,2,3)));
#else
void con_fprintf(FILE *f, const char *format, ...);
void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
#endif
+59 -14
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,14 +21,55 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
/*************************************************************************
//
**************************************************************************/
long Throwable::counter = 0;
Throwable::Throwable(const char *m, int e, bool w) NOTHROW
: super(), msg(NULL), err(e), is_warning(w)
{
if (m)
msg = strdup(m);
#if 0
fprintf(stderr, "construct exception: %s %ld\n", msg, counter);
counter++;
#endif
}
Throwable::Throwable(const Throwable &other) NOTHROW
: super(other), msg(NULL), err(other.err), is_warning(other.is_warning)
{
if (other.msg)
msg = strdup(other.msg);
#if 0
fprintf(stderr, "copy exception: %s %ld\n", msg, counter);
counter++;
#endif
}
Throwable::~Throwable() NOTHROW
{
#if 0
counter--;
fprintf(stderr, "destruct exception: %s %ld\n", msg, counter);
#endif
if (msg)
free(msg);
}
/*************************************************************************
// compression
**************************************************************************/
@@ -133,20 +174,24 @@ void throwEOFException(const char *msg, int e)
//
**************************************************************************/
const char *prettyName(const char *n)
const char *prettyName(const char *n) NOTHROW
{
while (*n >= '0' && *n <= '9') // gcc / egcs
n++;
if (strncmp(n, "class ", 6) == 0) // Visual C++
n += 6;
if (n == NULL)
return "(null)";
while (*n)
{
if (*n >= '0' && *n <= '9') // Linux ABI
n++;
else if (*n == ' ')
n++;
else if (strncmp(n, "class ", 6) == 0) // Visual C++
n += 6;
else
break;
}
return n;
}
const char *prettyName(const type_info &ti)
{
return prettyName(ti.name());
}
/*
vi:ts=4:et
+46 -40
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -31,32 +31,38 @@
#ifdef __cplusplus
const char *prettyName(const char *n);
const char *prettyName(const type_info &ti);
const char *prettyName(const char *n) NOTHROW;
/*************************************************************************
// exceptions
**************************************************************************/
class Throwable : public exception
class Throwable : public std::exception
{
typedef std::exception super;
protected:
Throwable(const char *m = 0, int e = 0, bool w = false)
: msg(m), err(e), is_warning(w) { }
Throwable(const char *m = 0, int e = 0, bool w = false) NOTHROW;
public:
virtual ~Throwable() { }
const char *getMsg() const { return msg; }
int getErrno() const { return err; }
bool isWarning() const { return is_warning; }
Throwable(const Throwable &) NOTHROW;
virtual ~Throwable() NOTHROW;
const char *getMsg() const NOTHROW { return msg; }
int getErrno() const NOTHROW { return err; }
bool isWarning() const NOTHROW { return is_warning; }
private:
//Throwable(const Throwable &);
private:
// void * operator new(size_t); // ...
const char *msg;
char *msg;
int err;
protected:
bool is_warning; // can be set by subclasses
private:
// disable assignment
Throwable& operator= (const Throwable &);
// disable dynamic allocation
DISABLE_NEW_DELETE
private:
static long counter; // for debugging
};
@@ -65,7 +71,7 @@ class Exception : public Throwable
{
typedef Throwable super;
public:
Exception(const char *m = 0, int e = 0, bool w = false) : super(m,e,w) { }
Exception(const char *m = 0, int e = 0, bool w = false) NOTHROW : super(m,e,w) { }
};
@@ -74,7 +80,7 @@ class Error : public Throwable
{
typedef Throwable super;
public:
Error(const char *m = 0, int e = 0) : super(m,e) { }
Error(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
@@ -86,7 +92,7 @@ class OutOfMemoryException : public Exception
{
typedef Exception super;
public:
OutOfMemoryException(const char *m = 0, int e = 0) : super(m,e) { }
OutOfMemoryException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
@@ -94,7 +100,7 @@ class IOException : public Exception
{
typedef Exception super;
public:
IOException(const char *m = 0, int e = 0) : super(m,e) { }
IOException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
@@ -102,7 +108,7 @@ class EOFException : public IOException
{
typedef IOException super;
public:
EOFException(const char *m = 0, int e = 0) : super(m,e) { }
EOFException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
@@ -110,7 +116,7 @@ class FileNotFoundException : public IOException
{
typedef IOException super;
public:
FileNotFoundException(const char *m = 0, int e = 0) : super(m,e) { }
FileNotFoundException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
@@ -118,7 +124,7 @@ class FileAlreadyExistsException : public IOException
{
typedef IOException super;
public:
FileAlreadyExistsException(const char *m = 0, int e = 0) : super(m,e) { }
FileAlreadyExistsException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
};
@@ -130,35 +136,35 @@ class OverlayException : public Exception
{
typedef Exception super;
public:
OverlayException(const char *m = 0, bool w = false) : super(m,0,w) { }
OverlayException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
};
class CantPackException : public Exception
{
typedef Exception super;
public:
CantPackException(const char *m = 0, bool w = false) : super(m,0,w) { }
CantPackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
};
class UnknownExecutableFormatException : public CantPackException
{
typedef CantPackException super;
public:
UnknownExecutableFormatException(const char *m = 0, bool w = false) : super(m,w) { }
UnknownExecutableFormatException(const char *m = 0, bool w = false) NOTHROW : super(m,w) { }
};
class AlreadyPackedException : public CantPackException
{
typedef CantPackException super;
public:
AlreadyPackedException(const char *m = 0) : super(m) { is_warning = true; }
AlreadyPackedException(const char *m = 0) NOTHROW : super(m) { is_warning = true; }
};
class NotCompressibleException : public CantPackException
{
typedef CantPackException super;
public:
NotCompressibleException(const char *m = 0) : super(m) { }
NotCompressibleException(const char *m = 0) NOTHROW : super(m) { }
};
@@ -166,14 +172,14 @@ class CantUnpackException : public Exception
{
typedef Exception super;
public:
CantUnpackException(const char *m = 0, bool w = false) : super(m,0,w) { }
CantUnpackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
};
class NotPackedException : public CantUnpackException
{
typedef CantUnpackException super;
public:
NotPackedException(const char *m = 0) : super(m,true) { }
NotPackedException(const char *m = 0) NOTHROW : super(m,true) { }
};
@@ -185,7 +191,7 @@ class InternalError : public Error
{
typedef Error super;
public:
InternalError(const char *m = 0) : super(m,0) { }
InternalError(const char *m = 0) NOTHROW : super(m,0) { }
};
@@ -196,25 +202,25 @@ public:
#undef NORET
#if 0 && defined(__GNUC__)
// (noreturn) is probably not the correct semantics for throwing exceptions
#define NORET __attribute__((noreturn))
#define NORET __attribute__((__noreturn__))
#else
#define NORET
#endif
void throwCantPack(const char *msg) NORET;
void throwUnknownExecutableFormat(const char *msg = 0, bool warn = false) NORET;
void throwNotCompressible(const char *msg = 0) NORET;
void throwAlreadyPacked(const char *msg = 0) NORET;
void throwAlreadyPackedByUPX(const char *msg = 0) 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;
void throwAlreadyPackedByUPX(const char *msg = NULL) NORET;
void throwCantUnpack(const char *msg) NORET;
void throwNotPacked(const char *msg = 0) NORET;
void throwNotPacked(const char *msg = NULL) NORET;
void throwFilterException() NORET;
void throwBadLoader() NORET;
void throwChecksumError() NORET;
void throwCompressedDataViolation() NORET;
void throwInternalError(const char *msg) NORET;
void throwIOException(const char *msg = 0, int e = 0) NORET;
void throwEOFException(const char *msg = 0, int e = 0) NORET;
void throwIOException(const char *msg = NULL, int e = 0) NORET;
void throwEOFException(const char *msg = NULL, int e = 0) NORET;
#undef NORET
-125
View File
@@ -1,125 +0,0 @@
/* fctl_ml.ch -- filter CTO implementation
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
*/
/*************************************************************************
// these are not implemented here
**************************************************************************/
// filter: e8, e9, e8e9
#define f_cto32_e8 NULL
#define f_cto32_e9 NULL
#define f_cto32_e8e9 NULL
// unfilter: e8, e9, e8e9
#define u_cto32_e8 NULL
#define u_cto32_e9 NULL
#define u_cto32_e8e9 NULL
// scan: e8, e9, e8e9
#define s_cto32_e8 NULL
#define s_cto32_e9 NULL
#define s_cto32_e8e9 NULL
// filter: e8, e9, e8e9 with bswap be->le
#define f_cto32_e8_bswap_be NULL
#define f_cto32_e9_bswap_be NULL
#define f_cto32_e8e9_bswap_be NULL
// unfilter: e8, e9, e8e9 with bswap be->le
#define u_cto32_e8_bswap_be NULL
#define u_cto32_e9_bswap_be NULL
#define u_cto32_e8e9_bswap_be NULL
// scan: e8, e9, e8e9 with bswap be->le
#define s_cto32_e8_bswap_be NULL
#define s_cto32_e9_bswap_be NULL
#define s_cto32_e8e9_bswap_be NULL
/*************************************************************************
//
**************************************************************************/
#define COND(b,x) (b[x] == 0xe8)
#define F f_cto32_e8_bswap_le
#define U u_cto32_e8_bswap_le
#include "fcto_ml2.ch"
#undef U
#undef F
#define F s_cto32_e8_bswap_le
#include "fcto_ml2.ch"
#undef F
#undef COND
#define COND(b,x) (b[x] == 0xe9)
#define F f_cto32_e9_bswap_le
#define U u_cto32_e9_bswap_le
#include "fcto_ml2.ch"
#undef U
#undef F
#define F s_cto32_e9_bswap_le
#include "fcto_ml2.ch"
#undef F
#undef COND
#define COND(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
#define F f_cto32_e8e9_bswap_le
#define U u_cto32_e8e9_bswap_le
#include "fcto_ml2.ch"
#undef U
#undef F
#define F s_cto32_e8e9_bswap_le
#include "fcto_ml2.ch"
#undef F
#undef COND
/*************************************************************************
//
**************************************************************************/
#define COND(b,x,lastcall) (b[x] == 0xe8 || b[x] == 0xe9 \
|| (lastcall!=(x) && 0xf==b[(x)-1] \
&& 0x80<=b[x] && b[x]<=0x8f) )
#define F f_ctjo32_e8e9_bswap_le
#define U u_ctjo32_e8e9_bswap_le
#include "fcto_ml3.ch"
#undef U
#undef F
#define F s_ctjo32_e8e9_bswap_le
#include "fcto_ml3.ch"
#undef F
#undef COND
/*
vi:ts=4:et
*/
+105 -94
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,13 +21,14 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "file.h"
#include "mem.h"
/*************************************************************************
@@ -39,13 +40,15 @@ void File::chmod(const char *name, int mode)
#if defined(HAVE_CHMOD)
if (::chmod(name,mode) != 0)
throwIOException(name,errno);
#else
UNUSED(name); UNUSED(mode);
#endif
}
void File::rename(const char *old_, const char *new_)
{
#if 1 && defined(__DJGPP__)
#if defined(__DJGPP__)
if (::_rename(old_,new_) != 0)
#else
if (::rename(old_,new_) != 0)
@@ -85,6 +88,25 @@ FileBase::~FileBase()
}
void FileBase::sopen()
{
if (_shflags < 0)
_fd = ::open(_name, _flags, _mode);
else
{
#if defined(__DJGPP__)
_fd = ::open(_name,_flags | _shflags, _mode);
#elif defined(__MINT__)
_fd = ::open(_name,_flags | (_shflags & O_SHMODE), _mode);
#elif defined(SH_DENYRW)
_fd = ::sopen(_name, _flags, _shflags, _mode);
#else
assert(0);
#endif
}
}
bool FileBase::close()
{
bool ok = true;
@@ -108,35 +130,19 @@ void FileBase::closex()
int FileBase::read(void *buf, int len)
{
int l;
if (!isOpen() || len < 0)
throwIOException("bad read");
if (len == 0)
return 0;
for (;;)
{
#if 1 && defined(__DJGPP__)
l = ::_read(_fd,buf,len);
#else
l = ::read(_fd,buf,len);
#endif
if (l < 0)
{
#if defined(EINTR)
if (errno == EINTR)
continue;
#endif
throwIOException("read error",errno);
}
break;
}
return l;
errno = 0;
long l = acc_safe_hread(_fd, buf, len);
if (errno)
throwIOException("read error",errno);
return (int) l;
}
int FileBase::readx(void *buf, int len)
{
int l = this->read(buf,len);
int l = this->read(buf, len);
if (l != len)
throwEOFException();
return l;
@@ -145,43 +151,33 @@ int FileBase::readx(void *buf, int len)
void FileBase::write(const void *buf, int len)
{
int l;
if (!isOpen() || len < 0)
throwIOException("bad write");
if (len == 0)
return;
for (;;)
{
#if 1 && defined(__DJGPP__)
l = ::_write(_fd,buf,len);
#else
l = ::write(_fd,buf,len);
#endif
#if defined(EINTR)
if (l < 0 && errno == EINTR)
continue;
#endif
if (l != len)
throwIOException("write error",errno);
break;
}
errno = 0;
long l = acc_safe_hwrite(_fd, buf, len);
if (l != len)
throwIOException("write error",errno);
}
void FileBase::seek(off_t off, int whence)
{
if (!isOpen())
throwIOException("bad seek");
throwIOException("bad seek 1");
if (whence == SEEK_SET && off < 0)
throwIOException("bad seek 2");
if (whence == SEEK_END && off > 0)
throwIOException("bad seek 3");
if (::lseek(_fd,off,whence) < 0)
throwIOException("seek error",errno);
}
off_t FileBase::tell()
off_t FileBase::tell() const
{
if (!isOpen())
throwIOException("bad tell");
off_t l = ::lseek(_fd,0,SEEK_CUR);
off_t l = ::lseek(_fd, 0, SEEK_CUR);
if (l < 0)
throwIOException("tell error",errno);
return l;
@@ -209,37 +205,53 @@ void InputFile::sopen(const char *name, int flags, int shflags)
_flags = flags;
_shflags = shflags;
_mode = 0;
if (shflags < 0)
_fd = ::open(_name,_flags);
else
#if defined(__DJGPP__)
_fd = ::open(_name,_flags | _shflags);
#elif defined(SH_DENYRW)
_fd = ::sopen(_name,_flags,_shflags);
#else
assert(0);
#endif
FileBase::sopen();
if (!isOpen())
{
if (errno == ENOENT)
throw FileNotFoundException(_name,errno);
throw FileNotFoundException(_name, errno);
else if (errno == EEXIST)
throw FileAlreadyExistsException(_name,errno);
throw FileAlreadyExistsException(_name, errno);
else
throwIOException(_name,errno);
throwIOException(_name, errno);
}
}
int InputFile::read(void *buf, int len)
{
return super::read(buf,len);
return super::read(buf, len);
}
int InputFile::readx(void *buf, int len)
{
return super::readx(buf,len);
return super::readx(buf, len);
}
int InputFile::read(MemBuffer *buf, int len)
{
buf->checkState();
assert((unsigned)len <= buf->getSize());
return read(buf->getVoidPtr(), len);
}
int InputFile::readx(MemBuffer *buf, int len)
{
buf->checkState();
assert((unsigned)len <= buf->getSize());
return read(buf->getVoidPtr(), len);
}
int InputFile::read(MemBuffer &buf, int len)
{
return read(&buf, len);
}
int InputFile::readx(MemBuffer &buf, int len)
{
return readx(&buf, len);
}
@@ -249,7 +261,7 @@ void InputFile::seek(off_t off, int whence)
}
off_t InputFile::tell()
off_t InputFile::tell() const
{
return super::tell();
}
@@ -277,16 +289,7 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
_flags = flags;
_shflags = shflags;
_mode = mode;
if (shflags < 0)
_fd = ::open(_name,_flags,_mode);
else
#if defined(__DJGPP__)
_fd = ::open(_name,_flags | _shflags, _mode);
#elif defined(SH_DENYRW)
_fd = ::sopen(_name,_flags,_shflags,_mode);
#else
assert(0);
#endif
FileBase::sopen();
if (!isOpen())
{
#if 0
@@ -306,45 +309,48 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
bool OutputFile::openStdout(int flags, bool force)
{
close();
if (!force)
{
if (!isafile(STDOUT_FILENO))
return false;
}
_fd = STDOUT_FILENO;
int fd = STDOUT_FILENO;
if (!force && acc_isatty(fd))
return false;
_name = "<stdout>";
_flags = flags;
_shflags = -1;
_mode = 0;
if (flags != 0)
{
assert(flags == O_BINARY);
#if defined(HAVE_SETMODE) && defined(USE_SETMODE)
if (setmode(_fd, O_BINARY) == -1)
throwIOException(_name,errno);
#if defined(__DJGPP__)
__djgpp_set_ctrl_c(1);
#endif
#endif
}
if (flags && acc_set_binmode(fd, 1) == -1)
throwIOException(_name, errno);
_fd = fd;
return true;
}
void OutputFile::write(const void *buf, int len)
{
super::write(buf,len);
super::write(buf, len);
bytes_written += len;
}
void OutputFile::write(const MemBuffer *buf, int len)
{
buf->checkState();
assert((unsigned)len <= buf->getSize());
write(buf->getVoidPtr(), len);
}
void OutputFile::write(const MemBuffer &buf, int len)
{
write(&buf, len);
}
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
{
if (flags < 0)
flags = O_CREAT | O_BINARY | O_TRUNC;
flags |= O_WRONLY;
OutputFile f;
f.open(name, flags, 0666);
f.open(name, flags, 0600);
f.write(buf, len);
f.closex();
}
@@ -354,6 +360,8 @@ void OutputFile::dump(const char *name, const void *buf, int len, int flags)
//
**************************************************************************/
#if 0
MemoryOutputFile::MemoryOutputFile() :
b(NULL), b_size(0), b_pos(0), bytes_written(0)
{
@@ -374,6 +382,9 @@ void MemoryOutputFile::write(const void *buf, int len)
}
#endif /* if 0 */
/*
vi:ts=4:et
*/
+24 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,14 +21,16 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#ifndef __UPX_FILE_H
#define __UPX_FILE_H
class MemBuffer;
/*************************************************************************
//
@@ -36,6 +38,9 @@
class File
{
protected:
File() { }
virtual ~File() { }
public:
static void chmod(const char *name, int mode);
static void rename(const char *old_, const char *new_);
@@ -56,11 +61,12 @@ public:
const char *getName() const { return _name; }
protected:
void sopen();
virtual int read(void *buf, int len);
virtual int readx(void *buf, int len);
virtual void write(const void *buf, int len);
virtual void seek(off_t off, int whence);
virtual off_t tell();
virtual off_t tell() const;
int _fd;
int _flags;
@@ -89,11 +95,15 @@ public:
sopen(name, flags, -1);
}
virtual int read(void * buf, int len);
virtual int readx(void * buf, int len);
virtual int read(void *buf, int len);
virtual int readx(void *buf, int len);
virtual int read(MemBuffer *buf, int len);
virtual int readx(MemBuffer *buf, int len);
virtual int read(MemBuffer &buf, int len);
virtual int readx(MemBuffer &buf, int len);
virtual void seek(off_t off, int whence);
virtual off_t tell();
virtual off_t tell() const;
};
@@ -116,16 +126,20 @@ public:
virtual bool openStdout(int flags=0, bool force=false);
virtual void write(const void *buf, int len);
virtual void write(const MemBuffer *buf, int len);
virtual void write(const MemBuffer &buf, int len);
off_t getBytesWritten() const { return bytes_written; }
// FIXME - these won't work when using the `--stdout' option
virtual void seek(off_t off, int whence)
{
assert(!opt->to_stdout);
super::seek(off,whence);
}
virtual void rewrite(const void *buf, int len)
{
assert(!opt->to_stdout);
write(buf, len);
bytes_written -= len; // restore
}
@@ -142,6 +156,7 @@ protected:
//
**************************************************************************/
#if 0 /* NOT USED */
class MemoryOutputFile : public FileBase
{
typedef FileBase super;
@@ -164,6 +179,7 @@ protected:
unsigned b_pos;
off_t bytes_written;
};
#endif /* if 0 */
#endif /* already included */
+26 -22
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,13 +21,14 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "filter.h"
#include "file.h"
/*************************************************************************
@@ -40,7 +41,7 @@ void initFilter(Filter *f, upx_byte *buf, unsigned buf_len)
f->buf = buf;
f->buf_len = buf_len;
// clear output parameters
f->calls = f->wrongcalls = f->noncalls = f->lastcall = 0;
f->calls = f->wrongcalls = f->noncalls = f->firstcall = f->lastcall = 0;
}
@@ -78,6 +79,13 @@ const FilterImp::FilterEntry *FilterImp::getFilter(int id)
}
bool Filter::isValidFilter(int filter_id)
{
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(filter_id);
return fe != NULL;
}
/*************************************************************************
// high level API
**************************************************************************/
@@ -88,10 +96,10 @@ void Filter::init(int id_, unsigned addvalue_)
initFilter(this, NULL, 0);
// clear input parameters
this->addvalue = addvalue_;
this->forced_cto = -1;
this->preferred_ctos = NULL;
// clear input/output parameters
this->cto = 0;
this->n_mru = 0;
}
@@ -112,13 +120,12 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
throwInternalError("filter-2");
// save checksum
this->adler = 0;
if (clevel != 1)
{
this->adler = upx_adler32(0,NULL,0);
this->adler = upx_adler32(this->adler, this->buf, this->buf_len);
}
this->adler = upx_adler32(this->buf, this->buf_len);
//printf("filter: %02x %p %d\n", this->id, this->buf, this->buf_len);
//OutputFile::dump("filter.dat", buf, buf_len);
int r = (*fe->do_filter)(this);
//printf("filter: %02x %d\n", fe->id, r);
if (r > 0)
@@ -129,7 +136,7 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
}
bool Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
{
initFilter(this, buf_, buf_len_);
@@ -137,11 +144,11 @@ bool Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
if (fe == NULL)
throwInternalError("unfilter-1");
if (fe->id == 0)
return true;
return;
if (buf_len < fe->min_buf_len)
return false;
return;
if (fe->max_buf_len && buf_len > fe->max_buf_len)
return false;
return;
if (!fe->do_unfilter)
throwInternalError("unfilter-2");
@@ -150,20 +157,18 @@ bool Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
//printf("unfilter: %02x %d\n", fe->id, r);
if (r != 0)
throwInternalError("unfilter-3");
//OutputFile::dump("unfilter.dat", buf, buf_len);
// verify checksum
if (verify_checksum && clevel != 1)
{
unsigned a = upx_adler32(0,NULL,0);
if (this->adler != upx_adler32(a, this->buf, this->buf_len))
if (this->adler != upx_adler32(this->buf, this->buf_len))
throwInternalError("unfilter-4");
}
return true;
}
bool Filter::verifyUnfilter()
void Filter::verifyUnfilter()
{
// Note:
// This verify is just because of complete paranoia that there
@@ -175,9 +180,8 @@ bool Filter::verifyUnfilter()
// Packer::verifyOverlappingDecompression()
//printf("verifyUnfilter: %02x %p %d\n", this->id, this->buf, this->buf_len);
if (clevel == 1)
return true;
return unfilter(this->buf, this->buf_len, true);
if (clevel != 1)
unfilter(this->buf, this->buf_len, true);
}
+11 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -44,8 +44,7 @@ class FilterImp;
// call throwFilterException() - this will cause the compression
// to fail.
//
// The return value of unfilters can/should be ignored. They throw
// exceptions in case of errors.
// Unfilters throw exceptions in case of errors.
//
// The main idea behind filters is to convert relative jumps and calls
// to absolute addresses so that the buffer compresses better.
@@ -58,10 +57,12 @@ public:
void init(int id=0, unsigned addvalue=0);
bool filter(upx_byte *buf, unsigned buf_len);
bool unfilter(upx_byte *buf, unsigned buf_len, bool verify_checksum=false);
bool verifyUnfilter();
void unfilter(upx_byte *buf, unsigned buf_len, bool verify_checksum=false);
void verifyUnfilter();
bool scan(const upx_byte *buf, unsigned buf_len);
static bool isValidFilter(int filter_id);
public:
// Will be set by each call to filter()/unfilter().
// Read-only afterwards.
@@ -74,7 +75,6 @@ public:
// Input parameters used by various filters.
unsigned addvalue;
int forced_cto;
const int *preferred_ctos;
// Input/output parameters used by various filters
@@ -84,7 +84,9 @@ public:
unsigned calls;
unsigned noncalls;
unsigned wrongcalls;
unsigned firstcall;
unsigned lastcall;
unsigned n_mru; // ctojr only
// Read only.
int id;
+390
View File
@@ -0,0 +1,390 @@
/* ct.h -- calltrick filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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>
*/
/*************************************************************************
// 16-bit calltrick ("naive")
**************************************************************************/
#define CT16(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 3; \
do { \
if (cond) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 2 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 2; \
return 0;
// filter: e8, e9, e8e9
static int f_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16)
}
static int f_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_le16)
}
static int f_ct16_e8e9(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_le16)
}
// unfilter: e8, e9, e8e9
static int u_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16)
}
static int u_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
}
static int u_ct16_e8e9(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
}
// scan: e8, e9, e8e9
static int s_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e8e9(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
// filter: e8, e9, e8e9 with bswap le->be
static int f_ct16_e8_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
}
static int f_ct16_e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
}
static int f_ct16_e8e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_be16)
}
// unfilter: e8, e9, e8e9 with bswap le->be
static int u_ct16_e8_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
}
static int u_ct16_e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
}
static int u_ct16_e8e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
}
// scan: e8, e9, e8e9 with bswap le->be
static int s_ct16_e8_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_dummy)
}
static int s_ct16_e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_dummy)
}
static int s_ct16_e8e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_dummy)
}
// filter: e8, e9, e8e9 with bswap be->le
static int f_ct16_e8_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_le16)
}
static int f_ct16_e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_le16)
}
static int f_ct16_e8e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_le16)
}
// unfilter: e8, e9, e8e9 with bswap be->le
static int u_ct16_e8_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_be16)
}
static int u_ct16_e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
}
static int u_ct16_e8e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
}
// scan: e8, e9, e8e9 with bswap be->le
static int s_ct16_e8_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e8e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
#undef CT16
/*************************************************************************
// 32-bit calltrick ("naive")
**************************************************************************/
#define CT32(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 5; \
do { \
if (cond) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 4 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 4; \
return 0;
// filter: e8, e9, e8e9
static int f_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32)
}
static int f_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_le32)
}
static int f_ct32_e8e9(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_le32)
}
// unfilter: e8, e9, e8e9
static int u_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32)
}
static int u_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
}
static int u_ct32_e8e9(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
}
// scan: e8, e9, e8e9
static int s_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e8e9(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
// filter: e8, e9, e8e9 with bswap le->be
static int f_ct32_e8_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
}
static int f_ct32_e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
}
static int f_ct32_e8e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_be32)
}
// unfilter: e8, e9, e8e9 with bswap le->be
static int u_ct32_e8_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
}
static int u_ct32_e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
}
static int u_ct32_e8e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
}
// scan: e8, e9, e8e9 with bswap le->be
static int s_ct32_e8_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_dummy)
}
static int s_ct32_e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_dummy)
}
static int s_ct32_e8e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_dummy)
}
// filter: e8, e9, e8e9 with bswap be->le
static int f_ct32_e8_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_le32)
}
static int f_ct32_e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_le32)
}
static int f_ct32_e8e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_le32)
}
// unfilter: e8, e9, e8e9 with bswap be->le
static int u_ct32_e8_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_be32)
}
static int u_ct32_e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
}
static int u_ct32_e8e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
}
// scan: e8, e9, e8e9 with bswap be->le
static int s_ct32_e8_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e8e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
#undef CT32
/*
vi:ts=4:et:nowrap
*/
+29 -52
View File
@@ -1,9 +1,9 @@
/* fctl_ml2.ch -- filter CTO implementation
/* cto.h -- calltrick filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,14 +21,14 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
/*************************************************************************
//
// filter / scan
**************************************************************************/
static int F(Filter *f)
@@ -36,72 +36,40 @@ static int F(Filter *f)
#ifdef U
// filter
upx_byte *b = f->buf;
const unsigned addvalue = f->addvalue;
#else
// scan
const upx_byte *b = f->buf;
#endif
const unsigned addvalue = f->addvalue;
const unsigned size = f->buf_len;
unsigned ic, jc, kc;
unsigned cto;
unsigned char cto8;
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0;
// find a 16MB large empty address space
if (f->forced_cto >= 0 && f->forced_cto <= 255)
cto8 = (unsigned char) f->forced_cto;
else
{
unsigned char buf[256];
memset(buf,0,256);
#if 1
// A call to a destination that is inside the buffer
// will be rewritten and marked with cto8 as first byte.
// So, a call to a destination that is outside the buffer
// 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)
{
buf[b[ic+1]] |= 1;
}
#else
{
int i = size - 6;
do {
if (COND(b,i) && get_le32(b+i+1)+i+1 >= size)
buf[b[i+1]] |= 1;
} while (--i >= 0);
}
#endif
ic = 256;
if (f->preferred_ctos)
{
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
{
if (buf[*pc & 255] == 0)
{
ic = *pc & 255;
break;
}
}
}
#if 0
// just a test to see if certain ctos would improve compression
if (ic >= 256)
for (ic = 0; ic < 256; ic += 16)
if (buf[ic] == 0)
break;
#endif
if (ic >= 256)
for (ic = 0; ic < 256; ic++)
if (buf[ic] == 0)
break;
if (ic >= 256)
//throwCantPack("call trick problem");
if (getcto(f, buf) < 0)
return -1;
cto8 = (unsigned char) ic;
}
cto = (unsigned)cto8 << 24;
const unsigned char cto8 = f->cto;
#ifdef U
const unsigned cto = (unsigned)f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
@@ -111,6 +79,8 @@ 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
#ifdef U
set_be32(b+ic+1,jc+addvalue+cto);
#endif
@@ -145,7 +115,6 @@ static int F(Filter *f)
}
}
f->cto = cto8;
f->calls = calls;
f->noncalls = noncalls;
f->lastcall = lastcall;
@@ -157,13 +126,17 @@ static int F(Filter *f)
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned addvalue = f->addvalue;
const unsigned cto = f->cto << 24;
const unsigned cto = (unsigned)f->cto << 24;
unsigned ic, jc;
@@ -186,7 +159,11 @@ static int U(Filter *f)
#endif
#undef F
#undef U
/*
vi:ts=4:et
vi:ts=4:et:nowrap
*/
+30 -56
View File
@@ -1,10 +1,10 @@
/* fctl_ml3.ch -- filter CTO implementation
/* ctoj.h -- filter CTO implementation
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 2000 John F. Reiser
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
@@ -22,14 +22,17 @@
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@jk.uni-linz.ac.at 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>
*/
/*************************************************************************
//
// filter / scan
**************************************************************************/
static int F(Filter *f)
@@ -37,72 +40,35 @@ static int F(Filter *f)
#ifdef U
// filter
upx_byte *b = f->buf;
const unsigned addvalue = f->addvalue;
#else
// scan
const upx_byte *b = f->buf;
#endif
const unsigned addvalue = f->addvalue;
const unsigned size = f->buf_len;
unsigned ic, jc, kc;
unsigned cto;
unsigned char cto8;
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0;
// find a 16MB large empty address space
if (f->forced_cto >= 0 && f->forced_cto <= 255)
cto8 = (unsigned char) f->forced_cto;
else
{
unsigned char buf[256];
memset(buf,0,256);
#if 1
for (ic = 0; ic < size - 5; ic++)
if (COND(b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
{
buf[b[ic+1]] |= 1;
}
#else
{
int i = size - 6;
do {
if (COND(b,i,lastcall) && get_le32(b+i+1)+i+1 >= size)
buf[b[i+1]] |= 1;
} while (--i >= 0);
}
#endif
ic = 256;
if (f->preferred_ctos)
{
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
{
if (buf[*pc & 255] == 0)
{
ic = *pc & 255;
break;
}
}
}
#if 0
// just a test to see if certain ctos would improve compression
if (ic >= 256)
for (ic = 0; ic < 256; ic += 16)
if (buf[ic] == 0)
break;
#endif
if (ic >= 256)
for (ic = 0; ic < 256; ic++)
if (buf[ic] == 0)
break;
if (ic >= 256)
//throwCantPack("call trick problem");
if (getcto(f, buf) < 0)
return -1;
cto8 = (unsigned char) ic;
}
cto = (unsigned)cto8 << 24;
const unsigned char cto8 = f->cto;
#ifdef U
const unsigned cto = (unsigned)f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
@@ -112,6 +78,8 @@ 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
#ifdef U
set_be32(b+ic+1,jc+addvalue+cto);
#endif
@@ -146,7 +114,6 @@ static int F(Filter *f)
}
}
f->cto = cto8;
f->calls = calls;
f->noncalls = noncalls;
f->lastcall = lastcall;
@@ -158,15 +125,18 @@ static int F(Filter *f)
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned addvalue = f->addvalue;
const unsigned cto = f->cto << 24;
unsigned lastcall = 0;
const unsigned cto = (unsigned)f->cto << 24;
// unsigned lastcall = 0; // lastcall is not used in COND macro
unsigned ic, jc;
for (ic = 0; ic < size5; ic++)
@@ -178,7 +148,7 @@ static int U(Filter *f)
set_le32(b+ic+1,jc-ic-1-addvalue-cto);
f->calls++;
ic += 4;
f->lastcall = lastcall = ic+1;
f->lastcall = ic+1;
}
else
f->noncalls++;
@@ -188,7 +158,11 @@ static int U(Filter *f)
#endif
#undef F
#undef U
/*
vi:ts=4:et
vi:ts=4:et:nowrap
*/
+348
View File
@@ -0,0 +1,348 @@
/* ctojr.h -- filter CTO implementation; renumber destinations MRU
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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1300))
# pragma warning(disable: 4702) // W4: unreachable code
#endif
/*************************************************************************
// filter / scan
**************************************************************************/
#ifdef U //{
#define NOFILT 0 // no filter
#define FNOMRU 1 // filter, but not using mru
#define MRUFLT 2 // mru filter
static unsigned
f80_call(Filter const *f)
{
return (1+ (0x0f & f->id)) % 3;
}
static unsigned
f80_jmp1(Filter const *f)
{
return ((1+ (0x0f & f->id)) / 3) % 3;
}
static unsigned
f80_jcc2(Filter const *f)
{
return f80_jmp1(f);
}
static int const N_MRU = 32; // does not have to be a power of 2
// Adaptively remember recent destinations.
static void
update_mru(
unsigned const jc, // destination address
int const kh, // mru[kh] is slot where found
unsigned mru[N_MRU], // circular buffer of most recent destinations
int &hand, // mru[hand] is most recent destination
int &tail // mru[tail] is beyond oldest destination ("cold cache" startup)
)
{
if (0 > --hand) {
hand = N_MRU -1;
}
unsigned const t = mru[hand]; // entry which will be overwritten by jc
if (0!=t) { // have seen at least N_MRU destinations
mru[kh] = t;
}
else { // "cold cache": keep active region contiguous
if (0 > --tail) {
tail = N_MRU -1;
}
unsigned const t2 = mru[tail];
mru[tail] = 0;
mru[kh] = t2;
}
mru[hand] = jc;
}
#endif //}
static int F(Filter *f)
{
#ifdef U
// filter
upx_byte *const b = f->buf;
#else
// scan
const upx_byte *b = f->buf;
#endif
const unsigned size = f->buf_len;
unsigned ic, jc, kc;
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0;
unsigned wtally[3]; memset(wtally, 0, sizeof(wtally));
#ifdef U //{
unsigned const f_call = f80_call(f);
unsigned const f_jmp1 = f80_jmp1(f);
unsigned const f_jcc2 = f80_jcc2(f);
int hand = 0, tail = 0;
unsigned mru[N_MRU];
memset(&mru[0], 0, sizeof(mru));
assert(N_MRU<=256);
f->n_mru = (MRUFLT==f_call || MRUFLT==f_jmp1 || MRUFLT==f_jcc2) ?
N_MRU : 0;
#endif //}
// FIXME: We must fit into 8MB because we steal one bit.
// find a 16MB large empty address space
{
int which;
unsigned char buf[256];
memset(buf,0,256);
for (ic = 0; ic < size - 5; ic++)
if (CONDF(which,b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
{
buf[b[ic+1]] |= 1;
}
UNUSED(which);
if (getcto(f, buf) < 0)
return -1;
}
const unsigned char cto8 = f->cto;
#ifdef U
const unsigned cto = (unsigned)f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
int which;
int f_on = 0;
if (!CONDF(which,b,ic,lastcall))
continue;
++wtally[which];
jc = get_le32(b+ic+1)+ic+1;
// try to detect 'real' calls only
if (jc < size)
{
#ifdef U
if (2==which && NOFILT!=f_jcc2) { // 6-byte Jcc <disp32>
// Prefix 0x0f is constant, but opcode condition 0x80..0x8f
// varies. Because we store the destination (or its mru index)
// in be32 big endian format, the low-addressed bytes
// will tend to be constant. Swap prefix and opcode
// so that constants are together for better compression.
unsigned char const t =
b[ic-1];
b[ic-1] = b[ic];
b[ic] = t;
}
// FIXME [?]: Extend to 8 bytes if "ADD ESP, byte 4*n" follows CALL.
// This will require two related cto's (consecutive, or otherwise).
if ((0==which && MRUFLT==f_call)
|| (1==which && MRUFLT==f_jmp1)
|| (2==which && MRUFLT==f_jcc2) ) {
f_on = 1;
// Recode the destination: narrower mru indices
// should compress better than wider addresses.
// (But not when offset of match is unlimited?)
int k;
for (k = 0; k < N_MRU; ++k) {
int kh = hand + k;
if (N_MRU <= kh) {
kh -= N_MRU;
}
if (mru[kh] == jc) { // destination was seen recently
set_be32(b+ic+1,((k<<1)|0)+cto);
update_mru(jc, kh, mru, hand, tail);
break;
}
}
if (k == N_MRU) { // loop failed; jc is not in mru[]
set_be32(b+ic+1,((jc<<1)|1)+cto);
// Adaptively remember recent destinations.
if (0 > --hand) {
hand = N_MRU -1;
}
mru[hand] = jc;
}
} else
if ((0==which && NOFILT!=f_call)
|| (1==which && NOFILT!=f_jmp1)
|| (2==which && NOFILT!=f_jcc2) ) {
f_on = 1;
set_be32(b+ic+1, jc+cto);
}
#endif
if (f_on) {
if (ic - lastnoncall < 5)
{
// check the last 4 bytes before this call
for (kc = 4; kc; kc--)
if (CONDF(which,b,ic-kc,lastcall) && b[ic-kc+1] == cto8)
break;
if (kc)
{
#ifdef U
// restore original
if (2==which) {
// Unswap prefix and opcode for 6-byte Jcc <disp32>
unsigned char const t =
b[ic-1];
b[ic-1] = b[ic];
b[ic] = t;
}
set_le32(b+ic+1,jc-ic-1);
#endif
if (b[ic+1] == cto8)
return 1; // fail - buffer not restored
lastnoncall = ic;
noncalls2++;
continue;
}
}
calls++;
ic += 4;
lastcall = ic+1;
}
}
else
{
assert(b[ic+1] != cto8); // this should not happen
lastnoncall = ic;
noncalls++;
}
}
f->calls = calls;
f->noncalls = noncalls;
f->lastcall = lastcall;
/*#ifdef TESTING*/
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",
calls,noncalls,noncalls2,size,cto8);
printf("CALL/JMP/JCC %d %d %d\n",wtally[0],wtally[1],wtally[2]);
/*#endif*/
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
unsigned ic, jc;
upx_byte *const b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned cto = (unsigned)f->cto << 24;
unsigned lastcall = 0;
int hand = 0, tail = 0;
unsigned const f_call = f80_call(f);
unsigned const f_jmp1 = f80_jmp1(f);
unsigned const f_jcc2 = f80_jcc2(f);
unsigned mru[N_MRU];
memset(&mru[0], 0, sizeof(mru));
for (ic = 0; ic < size5; ic++) {
int which;
if (CONDU(which,b,ic,lastcall))
{
unsigned f_on = 0;
jc = get_be32(b+ic+1) - cto;
if (b[ic+1] == f->cto)
{
if ((0==which && MRUFLT==f_call)
|| (1==which && MRUFLT==f_jmp1)
|| (2==which && MRUFLT==f_jcc2) ) {
f_on = 1;
if (1&jc) { // 1st time at this destination
jc >>= 1;
if (0 > --hand) {
hand = N_MRU -1;
}
mru[hand] = jc;
}
else { // not 1st time at this destination
jc >>= 1;
int kh = jc + hand;
if (N_MRU <= kh) {
kh -= N_MRU;
}
jc = mru[kh];
update_mru(jc, kh, mru, hand, tail);
}
set_le32(b+ic+1,jc-ic-1);
} else
if ((0==which && NOFILT!=f_call)
|| (1==which && NOFILT!=f_jmp1)
|| (2==which && NOFILT!=f_jcc2) ) {
f_on = 1;
set_le32(b+ic+1,jc-ic-1);
}
if (2==which && NOFILT!=f_jcc2) {
// Unswap prefix and opcode for 6-byte Jcc <disp32>
unsigned char const t =
b[ic-1];
b[ic-1] = b[ic];
b[ic] = t;
}
if (f_on) {
f->calls++;
ic += 4;
f->lastcall = lastcall = ic+1;
}
}
else
f->noncalls++;
}
}
return 0;
}
#endif
#undef F
#undef U
/*
vi:ts=4:et:nowrap
*/
+171
View File
@@ -0,0 +1,171 @@
/* ctok.h -- filter CTO implementation
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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
/*************************************************************************
// filter / scan
**************************************************************************/
static int F(Filter *f)
{
#ifdef U
// filter
upx_byte *b = f->buf;
#else
// scan
const upx_byte *b = f->buf;
#endif
const unsigned addvalue = f->addvalue;
const unsigned size = f->buf_len;
unsigned const id = f->id;
unsigned ic, jc, kc;
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
unsigned lastnoncall = size, lastcall = 0;
// find a 16MB large empty address space
{
unsigned char buf[256];
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)
{
buf[b[ic+1]] |= 1;
}
if (getcto(f, buf) < 0)
return -1;
}
const unsigned char cto8 = f->cto;
#ifdef U
const unsigned cto = (unsigned)f->cto << 24;
#endif
for (ic = 0; ic < size - 5; ic++)
{
if (!COND(b,ic,lastcall,id))
continue;
jc = get_le32(b+ic+1)+ic+1;
// 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
#ifdef U
set_be32(b+ic+1,jc+addvalue+cto);
#endif
if (ic - lastnoncall < 5)
{
// check the last 4 bytes before this call
for (kc = 4; kc; kc--)
if (COND(b,ic-kc,lastcall,id) && b[ic-kc+1] == cto8)
break;
if (kc)
{
#ifdef U
// restore original
set_le32(b+ic+1,jc-ic-1);
#endif
if (b[ic+1] == cto8)
return 1; // fail - buffer not restored
lastnoncall = ic;
noncalls2++;
continue;
}
}
calls++;
ic += 4;
lastcall = ic+1;
}
else
{
assert(b[ic+1] != cto8); // this should not happen
lastnoncall = ic;
noncalls++;
}
}
f->calls = calls;
f->noncalls = noncalls;
f->lastcall = lastcall;
#ifdef TESTING
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
#endif
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
const unsigned size5 = f->buf_len - 5;
const unsigned addvalue = f->addvalue;
const unsigned cto = (unsigned)f->cto << 24;
unsigned const id = f->id;
unsigned lastcall = 0;
unsigned ic, jc;
for (ic = 0; ic < size5; ic++)
if (COND(b,ic,lastcall,id))
{
jc = get_be32(b+ic+1);
if (b[ic+1] == f->cto)
{
set_le32(b+ic+1,jc-ic-1-addvalue-cto);
f->calls++;
ic += 4;
f->lastcall = lastcall = ic+1;
}
else
f->noncalls++;
}
return 0;
}
#endif
#undef F
#undef U
/*
vi:ts=4:et:nowrap
*/
+173
View File
@@ -0,0 +1,173 @@
/* ctsw.h -- call-/swaptrick filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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>
*/
/*************************************************************************
// 16-bit call-/swaptrick ("naive")
**************************************************************************/
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 3; \
do { \
if (cond1) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 2 - 1; \
} \
else if (cond2) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b)); \
f->calls++; \
b += 2 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 2; \
return 0;
// filter
static int f_ctsw16_e8_e9(Filter *f)
{
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
}
static int f_ctsw16_e9_e8(Filter *f)
{
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
}
// unfilter
static int u_ctsw16_e8_e9(Filter *f)
{
CTSW16(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
}
static int u_ctsw16_e9_e8(Filter *f)
{
CTSW16(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
}
// scan
static int s_ctsw16_e8_e9(Filter *f)
{
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
static int s_ctsw16_e9_e8(Filter *f)
{
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
}
#undef CTSW16
/*************************************************************************
// 32-bit call-/swaptrick ("naive")
**************************************************************************/
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 5; \
do { \
if (cond1) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 4 - 1; \
} \
else if (cond2) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b)); \
f->calls++; \
b += 4 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 4; \
return 0;
// filter
static int f_ctsw32_e8_e9(Filter *f)
{
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
}
static int f_ctsw32_e9_e8(Filter *f)
{
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
}
// unfilter
static int u_ctsw32_e8_e9(Filter *f)
{
CTSW32(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
}
static int u_ctsw32_e9_e8(Filter *f)
{
CTSW32(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
}
// scan
static int s_ctsw32_e8_e9(Filter *f)
{
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
static int s_ctsw32_e9_e8(Filter *f)
{
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
}
#undef CTSW32
/*
vi:ts=4:et:nowrap
*/
+75
View File
@@ -0,0 +1,75 @@
/* getcto.h -- calltrick util
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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>
*/
/*************************************************************************
//
**************************************************************************/
static int getcto(Filter *f, const unsigned char *buf, const int n=256)
{
int ic = n;
if (f->preferred_ctos)
{
for (const int *pc = f->preferred_ctos; *pc >= 0; pc++)
{
if (*pc < n && buf[*pc] == 0)
{
ic = *pc;
break;
}
}
}
#if 0
// just a test to see if certain ctos would improve compression
if (ic >= n)
for (ic = 0; ic < n; ic += 16)
if (buf[ic] == 0)
break;
#endif
if (ic >= n)
for (ic = 0; ic < n; ic++)
if (buf[ic] == 0)
break;
if (ic >= n)
//throwCantPack("call trick problem");
return -1;
f->cto = (unsigned char) ic;
return ic;
}
/*
vi:ts=4:et:nowrap
*/
+155
View File
@@ -0,0 +1,155 @@
/* ppcbxx.h -- PowerPC Branch trick
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
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>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
/*************************************************************************
// filter / scan
**************************************************************************/
#define W_CTO 4 /* width of cto; must match stub/ppc_bxx.S */
static int F(Filter *f)
{
#ifdef U
// filter
upx_byte *b = f->buf;
const unsigned addvalue = f->addvalue;
#else
// scan
const upx_byte *b = f->buf;
#endif
const unsigned size = umin(f->buf_len, -(~0u<<(32 - (6+ W_CTO))));
const unsigned size4 = size -4;
unsigned ic;
unsigned calls = 0, noncalls = 0;
unsigned lastnoncall = size, lastcall = 0;
// find 26-2-W_CTO bits of displacements that contain no targets
{
unsigned char buf[256];
unsigned short wbuf[256];
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);
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
unsigned const off = (int)(get_be32(b+ic)<<6) >>6;
if (size <= (off & (~0u<<2))+ic) {
buf[(~(~0u<<W_CTO)) & (off>>(26 - W_CTO))] |= 1;
++wbuf[0xff&(off>>18)];
}
}
if (getcto(f, buf) < 0) {
if (0!=W_CTO) // FIXME: what is this ???
return -1;
f->cto = 0;
}
}
const unsigned char cto8 = f->cto;
#ifdef U
const unsigned cto = (unsigned)f->cto << (24+2 - W_CTO);
#endif
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
unsigned const word = get_be32(b+ic);
unsigned const off = (int)(word<<6) >>6;
unsigned const jc = (off & (~0u<<2))+ic;
// try to detect 'real' calls only
if (jc < size) {
#ifdef U
set_be32(b+ic,(0xfc000003&word) | (jc+addvalue+cto));
#endif
calls++;
lastcall = ic;
}
else {
assert(0==W_CTO // FIXME: what is this ???
|| (~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
lastnoncall = ic;
noncalls++;
}
}
f->calls = calls;
f->noncalls = noncalls;
f->lastcall = lastcall;
#if 0
printf("\ncalls=%d noncalls=%d text_size=%x calltrickoffset=%x\n",
calls,noncalls,size,cto8);
#endif
return 0;
}
/*************************************************************************
// unfilter
**************************************************************************/
#ifdef U
static int U(Filter *f)
{
upx_byte *b = f->buf;
const unsigned size4 = umin(f->buf_len - 4, -(~0u<<(32 - (6+ W_CTO))));
const unsigned addvalue = f->addvalue;
unsigned ic;
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
unsigned const word = get_be32(b+ic);
if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == f->cto) {
unsigned const jc = word & (~(~0u<<(26 - W_CTO)) & (~0u<<2));
set_be32(b+ic, (0xfc000003&word)|(0x03fffffc&(jc-ic-addvalue)));
f->calls++;
f->lastcall = ic;
}
else {
f->noncalls++;
}
}
return 0;
}
#endif
#undef F
#undef U
#undef W_CTO
/*
vi:ts=4:et:nowrap
*/
+87
View File
@@ -0,0 +1,87 @@
/* sub.hh -- simple delta filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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>
*/
/*************************************************************************
//
**************************************************************************/
#define SUB(f, N, T, get, set) \
upx_byte *b = f->buf; \
unsigned l = f->buf_len / sizeof(T); \
int i; \
T d[N]; \
\
i = N - 1; do d[i] = 0; while (--i >= 0); \
\
i = N - 1; \
do { \
T delta = (T) (get(b) - d[i]); \
set(b, delta); \
d[i] = (T) (d[i] + delta); \
b += sizeof(T); \
if (--i < 0) \
i = N - 1; \
} while (--l > 0); \
f->calls = (f->buf_len / sizeof(T)) - N; \
assert((int)f->calls > 0); \
return 0;
#define ADD(f, N, T, get, set) \
upx_byte *b = f->buf; \
unsigned l = f->buf_len / sizeof(T); \
int i; \
T d[N]; \
\
i = N - 1; do d[i] = 0; while (--i >= 0); \
\
i = N - 1; \
do { \
d[i] = (T) (d[i] + get(b)); \
set(b, d[i]); \
b += sizeof(T); \
if (--i < 0) \
i = N - 1; \
} while (--l > 0); \
f->calls = (f->buf_len / sizeof(T)) - N; \
assert((int)f->calls > 0); \
return 0;
#define SCAN(f, N, T, get, set) \
f->calls = (f->buf_len / sizeof(T)) - N; \
assert((int)f->calls > 0); \
return 0;
/*
vi:ts=4:et:nowrap
*/
+122
View File
@@ -0,0 +1,122 @@
/* sub16.h -- simple delta filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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 "sub.hh"
#define SUB16(f, N) SUB(f, N, unsigned short, get_le16, set_le16)
#define ADD16(f, N) ADD(f, N, unsigned short, get_le16, set_le16)
#define SCAN16(f, N) SCAN(f, N, unsigned short, get_le16, set_le16)
/*************************************************************************
//
**************************************************************************/
// filter
static int f_sub16_1(Filter *f)
{
SUB16(f, 1)
}
static int f_sub16_2(Filter *f)
{
SUB16(f, 2)
}
static int f_sub16_3(Filter *f)
{
SUB16(f, 3)
}
static int f_sub16_4(Filter *f)
{
SUB16(f, 4)
}
// unfilter
static int u_sub16_1(Filter *f)
{
ADD16(f, 1)
}
static int u_sub16_2(Filter *f)
{
ADD16(f, 2)
}
static int u_sub16_3(Filter *f)
{
ADD16(f, 3)
}
static int u_sub16_4(Filter *f)
{
ADD16(f, 4)
}
// scan
static int s_sub16_1(Filter *f)
{
SCAN16(f, 1)
}
static int s_sub16_2(Filter *f)
{
SCAN16(f, 2)
}
static int s_sub16_3(Filter *f)
{
SCAN16(f, 3)
}
static int s_sub16_4(Filter *f)
{
SCAN16(f, 4)
}
#undef SUB
#undef ADD
#undef SCAN
#undef SUB16
#undef ADD16
#undef SCAN16
/*
vi:ts=4:et:nowrap
*/
+122
View File
@@ -0,0 +1,122 @@
/* sub32.h -- simple delta filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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 "sub.hh"
#define SUB32(f, N) SUB(f, N, unsigned int, get_le32, set_le32)
#define ADD32(f, N) ADD(f, N, unsigned int, get_le32, set_le32)
#define SCAN32(f, N) SCAN(f, N, unsigned int, get_le32, set_le32)
/*************************************************************************
//
**************************************************************************/
// filter
static int f_sub32_1(Filter *f)
{
SUB32(f, 1)
}
static int f_sub32_2(Filter *f)
{
SUB32(f, 2)
}
static int f_sub32_3(Filter *f)
{
SUB32(f, 3)
}
static int f_sub32_4(Filter *f)
{
SUB32(f, 4)
}
// unfilter
static int u_sub32_1(Filter *f)
{
ADD32(f, 1)
}
static int u_sub32_2(Filter *f)
{
ADD32(f, 2)
}
static int u_sub32_3(Filter *f)
{
ADD32(f, 3)
}
static int u_sub32_4(Filter *f)
{
ADD32(f, 4)
}
// scan
static int s_sub32_1(Filter *f)
{
SCAN32(f, 1)
}
static int s_sub32_2(Filter *f)
{
SCAN32(f, 2)
}
static int s_sub32_3(Filter *f)
{
SCAN32(f, 3)
}
static int s_sub32_4(Filter *f)
{
SCAN32(f, 4)
}
#undef SUB
#undef ADD
#undef SCAN
#undef SUB32
#undef ADD32
#undef SCAN32
/*
vi:ts=4:et:nowrap
*/
+122
View File
@@ -0,0 +1,122 @@
/* sub8.h -- simple delta filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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 "sub.hh"
#define SUB8(f, N) SUB(f, N, unsigned char, get_8, set_8)
#define ADD8(f, N) ADD(f, N, unsigned char, get_8, set_8)
#define SCAN8(f, N) SCAN(f, N, unsigned char, get_8, set_8)
/*************************************************************************
//
**************************************************************************/
// filter
static int f_sub8_1(Filter *f)
{
SUB8(f, 1)
}
static int f_sub8_2(Filter *f)
{
SUB8(f, 2)
}
static int f_sub8_3(Filter *f)
{
SUB8(f, 3)
}
static int f_sub8_4(Filter *f)
{
SUB8(f, 4)
}
// unfilter
static int u_sub8_1(Filter *f)
{
ADD8(f, 1)
}
static int u_sub8_2(Filter *f)
{
ADD8(f, 2)
}
static int u_sub8_3(Filter *f)
{
ADD8(f, 3)
}
static int u_sub8_4(Filter *f)
{
ADD8(f, 4)
}
// scan
static int s_sub8_1(Filter *f)
{
SCAN8(f, 1)
}
static int s_sub8_2(Filter *f)
{
SCAN8(f, 2)
}
static int s_sub8_3(Filter *f)
{
SCAN8(f, 3)
}
static int s_sub8_4(Filter *f)
{
SCAN8(f, 4)
}
#undef SUB
#undef ADD
#undef SCAN
#undef SUB8
#undef ADD8
#undef SCAN8
/*
vi:ts=4:et:nowrap
*/
+188
View File
@@ -0,0 +1,188 @@
/* sw.h -- swaptrick filter
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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>
*/
/*************************************************************************
// 16-bit swaptrick ("naive")
**************************************************************************/
#define SW16(f, cond, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 3; \
do { \
if (cond) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b)); \
f->calls++; \
b += 2 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 2; \
return 0;
// filter
static int f_sw16_e8(Filter *f)
{
SW16(f, (*b == 0xe8), get_le16, set_be16)
}
static int f_sw16_e9(Filter *f)
{
SW16(f, (*b == 0xe9), get_le16, set_be16)
}
static int f_sw16_e8e9(Filter *f)
{
SW16(f, (*b == 0xe8 || *b == 0xe9), get_le16, set_be16)
}
// unfilter
static int u_sw16_e8(Filter *f)
{
SW16(f, (*b == 0xe8), get_be16, set_le16)
}
static int u_sw16_e9(Filter *f)
{
SW16(f, (*b == 0xe9), get_be16, set_le16)
}
static int u_sw16_e8e9(Filter *f)
{
SW16(f, (*b == 0xe8 || *b == 0xe9), get_be16, set_le16)
}
// scan
static int s_sw16_e8(Filter *f)
{
SW16(f, (*b == 0xe8), get_le16, set_dummy)
}
static int s_sw16_e9(Filter *f)
{
SW16(f, (*b == 0xe9), get_le16, set_dummy)
}
static int s_sw16_e8e9(Filter *f)
{
SW16(f, (*b == 0xe8 || *b == 0xe9), get_le16, set_dummy)
}
#undef SW16
/*************************************************************************
// 32-bit swaptrick ("naive")
**************************************************************************/
#define SW32(f, cond, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 5; \
do { \
if (cond) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b)); \
f->calls++; \
b += 4 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 4; \
return 0;
// filter
static int f_sw32_e8(Filter *f)
{
SW32(f, (*b == 0xe8), get_le32, set_be32)
}
static int f_sw32_e9(Filter *f)
{
SW32(f, (*b == 0xe9), get_le32, set_be32)
}
static int f_sw32_e8e9(Filter *f)
{
SW32(f, (*b == 0xe8 || *b == 0xe9), get_le32, set_be32)
}
// unfilter
static int u_sw32_e8(Filter *f)
{
SW32(f, (*b == 0xe8), get_be32, set_le32)
}
static int u_sw32_e9(Filter *f)
{
SW32(f, (*b == 0xe9), get_be32, set_le32)
}
static int u_sw32_e8e9(Filter *f)
{
SW32(f, (*b == 0xe8 || *b == 0xe9), get_be32, set_le32)
}
// scan
static int s_sw32_e8(Filter *f)
{
SW32(f, (*b == 0xe8), get_le32, set_dummy)
}
static int s_sw32_e9(Filter *f)
{
SW32(f, (*b == 0xe9), get_le32, set_dummy)
}
static int s_sw32_e8e9(Filter *f)
{
SW32(f, (*b == 0xe8 || *b == 0xe9), get_le32, set_dummy)
}
#undef SW32
/*
vi:ts=4:et:nowrap
*/
+178 -367
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,385 +21,147 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
#include "conf.h"
#include "filter.h"
static unsigned
umin(unsigned const a, unsigned const b)
{
return (a<=b) ? a : b;
}
#define set_dummy(p, v) ((void)0)
#define get_8(p) (*(p))
#define set_8(p, v) (*(p) = (v))
/*************************************************************************
// 16-bit calltrick ("naive")
// util
**************************************************************************/
#define CT16(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 3; \
do { \
if (cond) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 2 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 2; \
return 0;
// filter: e8, e9, e8e9
static int f_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_le16)
}
static int f_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_le16)
}
static int f_ct16_e8e9(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_le16)
}
// unfilter: e8, e9, e8e9
static int u_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_le16)
}
static int u_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
}
static int u_ct16_e8e9(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_le16)
}
// scan: e8, e9, e8e9
static int s_ct16_e8(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e9(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e8e9(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
// filter: e8, e9, e8e9 with bswap le->be
static int f_ct16_e8_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
}
static int f_ct16_e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
}
static int f_ct16_e8e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_be16)
}
// unfilter: e8, e9, e8e9 with bswap le->be
static int u_ct16_e8_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
}
static int u_ct16_e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
}
static int u_ct16_e8e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
}
// scan: e8, e9, e8e9 with bswap le->be
static int s_ct16_e8_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_dummy)
}
static int s_ct16_e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_dummy)
}
static int s_ct16_e8e9_bswap_le(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_dummy)
}
// filter: e8, e9, e8e9 with bswap be->le
static int f_ct16_e8_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_be16, set_le16)
}
static int f_ct16_e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_be16, set_le16)
}
static int f_ct16_e8e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be16, set_le16)
}
// unfilter: e8, e9, e8e9 with bswap be->le
static int u_ct16_e8_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8), 0 - a - f->addvalue, get_le16, set_be16)
}
static int u_ct16_e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
}
static int u_ct16_e8e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le16, set_be16)
}
// scan: e8, e9, e8e9 with bswap be->le
static int s_ct16_e8_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
static int s_ct16_e8e9_bswap_be(Filter *f)
{
CT16(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le16, set_dummy)
}
#undef CT16
#include "filter/getcto.h"
/*************************************************************************
// 32-bit calltrick ("naive")
// simple filters: calltrick / swaptrick / delta / ...
**************************************************************************/
#define CT32(f, cond, addvalue, get, set) \
upx_byte *b = f->buf; \
upx_byte *b_end = b + f->buf_len - 5; \
do { \
if (cond) \
{ \
b += 1; \
unsigned a = (unsigned) (b - f->buf); \
f->lastcall = a; \
set(b, get(b) + (addvalue)); \
f->calls++; \
b += 4 - 1; \
} \
} while (++b < b_end); \
if (f->lastcall) f->lastcall += 4; \
return 0;
#include "filter/ct.h"
#include "filter/sw.h"
#include "filter/ctsw.h"
// filter: e8, e9, e8e9
static int f_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_le32)
}
static int f_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_le32)
}
static int f_ct32_e8e9(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_le32)
}
// unfilter: e8, e9, e8e9
static int u_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_le32)
}
static int u_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
}
static int u_ct32_e8e9(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_le32)
}
// scan: e8, e9, e8e9
static int s_ct32_e8(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e9(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e8e9(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
// filter: e8, e9, e8e9 with bswap le->be
static int f_ct32_e8_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
}
static int f_ct32_e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
}
static int f_ct32_e8e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_be32)
}
// unfilter: e8, e9, e8e9 with bswap le->be
static int u_ct32_e8_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
}
static int u_ct32_e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
}
static int u_ct32_e8e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
}
// scan: e8, e9, e8e9 with bswap le->be
static int s_ct32_e8_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_dummy)
}
static int s_ct32_e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_dummy)
}
static int s_ct32_e8e9_bswap_le(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_dummy)
}
// filter: e8, e9, e8e9 with bswap be->le
static int f_ct32_e8_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_be32, set_le32)
}
static int f_ct32_e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_be32, set_le32)
}
static int f_ct32_e8e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_be32, set_le32)
}
// unfilter: e8, e9, e8e9 with bswap be->le
static int u_ct32_e8_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8), 0 - a - f->addvalue, get_le32, set_be32)
}
static int u_ct32_e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
}
static int u_ct32_e8e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), 0 - a - f->addvalue, get_le32, set_be32)
}
// scan: e8, e9, e8e9 with bswap be->le
static int s_ct32_e8_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
static int s_ct32_e8e9_bswap_be(Filter *f)
{
CT32(f, (*b == 0xe8 || *b == 0xe9), a + f->addvalue, get_le32, set_dummy)
}
#undef CT32
#undef set_dummy
#include "filter/sub8.h"
#include "filter/sub16.h"
#include "filter/sub32.h"
/*************************************************************************
// 32-bit calltrick with cto ("clever")
//
// This version is more sophisticated because it only
// tries to change actual calls and/or jumps.
// cto calltrick
**************************************************************************/
#include "fcto_ml.ch"
#define COND(b,x) (b[x] == 0xe8)
#define F f_cto32_e8_bswap_le
#define U u_cto32_e8_bswap_le
#include "filter/cto.h"
#define F s_cto32_e8_bswap_le
#include "filter/cto.h"
#undef COND
#define COND(b,x) (b[x] == 0xe9)
#define F f_cto32_e9_bswap_le
#define U u_cto32_e9_bswap_le
#include "filter/cto.h"
#define F s_cto32_e9_bswap_le
#include "filter/cto.h"
#undef COND
#define COND(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
#define F f_cto32_e8e9_bswap_le
#define U u_cto32_e8e9_bswap_le
#include "filter/cto.h"
#define F s_cto32_e8e9_bswap_le
#include "filter/cto.h"
#undef COND
/*************************************************************************
// cto calltrick with jmp
**************************************************************************/
#define COND(b,x,lastcall) (b[x] == 0xe8 || b[x] == 0xe9)
#define F f_ctoj32_e8e9_bswap_le
#define U u_ctoj32_e8e9_bswap_le
#include "filter/ctoj.h"
#define F s_ctoj32_e8e9_bswap_le
#include "filter/ctoj.h"
#undef COND
/*************************************************************************
// cto calltrick with jmp, optional jcc
**************************************************************************/
#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 F f_ctok32_e8e9_bswap_le
#define U u_ctok32_e8e9_bswap_le
#include "filter/ctok.h"
#define F s_ctok32_e8e9_bswap_le
#include "filter/ctok.h"
#undef COND
#undef COND2
#undef COND1
/*************************************************************************
// cto calltrick with jmp and jcc and relative renumbering
**************************************************************************/
#define COND_CALL(which,b,x) ((which = 0), b[x] == 0xe8)
#define COND_JMP( which,b,x) ((which = 1), b[x] == 0xe9)
#define COND_JCC( which,b,lastcall,x,y,z) ((which = 2), \
(lastcall!=(x) && 0xf==b[y] && 0x80<=b[z] && b[z]<=0x8f))
#define COND1(which,b,x) (COND_CALL(which,b,x) || COND_JMP(which,b,x))
#define COND2(which,b,lastcall,x,y,z) COND_JCC(which,b,lastcall,x,y,z)
#define CONDF(which,b,x,lastcall) \
(COND1(which,b,x) || COND2(which,b,lastcall,x,(x)-1, x ))
#define CONDU(which,b,x,lastcall) \
(COND1(which,b,x) || COND2(which,b,lastcall,x, x ,(x)-1))
#define F f_ctojr32_e8e9_bswap_le
#define U u_ctojr32_e8e9_bswap_le
#include "filter/ctojr.h"
#define F s_ctojr32_e8e9_bswap_le
#include "filter/ctojr.h"
#undef CONDU
#undef CONDF
#undef COND2
#undef COND1
#undef COND_JCC
#undef COND_JMP
#undef COND_CALL
/*************************************************************************
// PowerPC branch [incl. call] trick
**************************************************************************/
#define COND(b,x) (18==(get_be32(b+x)>>26))
#define F f_ppcbxx
#define U u_ppcbxx
#include "filter/ppcbxx.h"
#define F s_ppcbxx
#include "filter/ppcbxx.h"
#undef COND
/*************************************************************************
@@ -409,8 +171,9 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
const FilterImp::FilterEntry FilterImp::filters[] = {
// no filter
{ 0x00, 0, 0, NULL, NULL, NULL },
// 16-bit calltrick
{ 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8,},
{ 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8 },
{ 0x02, 4, 0, f_ct16_e9, u_ct16_e9, s_ct16_e9 },
{ 0x03, 4, 0, f_ct16_e8e9, u_ct16_e8e9, s_ct16_e8e9 },
{ 0x04, 4, 0, f_ct16_e8_bswap_le, u_ct16_e8_bswap_le, s_ct16_e8_bswap_le },
@@ -419,6 +182,16 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
{ 0x07, 4, 0, f_ct16_e8_bswap_be, u_ct16_e8_bswap_be, s_ct16_e8_bswap_be },
{ 0x08, 4, 0, f_ct16_e9_bswap_be, u_ct16_e9_bswap_be, s_ct16_e9_bswap_be },
{ 0x09, 4, 0, f_ct16_e8e9_bswap_be, u_ct16_e8e9_bswap_be, s_ct16_e8e9_bswap_be },
// 16-bit swaptrick
{ 0x0a, 4, 0, f_sw16_e8, u_sw16_e8, s_sw16_e8 },
{ 0x0b, 4, 0, f_sw16_e9, u_sw16_e9, s_sw16_e9 },
{ 0x0c, 4, 0, f_sw16_e8e9, u_sw16_e8e9, s_sw16_e8e9 },
// 16-bit call-/swaptrick
{ 0x0d, 4, 0, f_ctsw16_e8_e9, u_ctsw16_e8_e9, s_ctsw16_e8_e9 },
{ 0x0e, 4, 0, f_ctsw16_e9_e8, u_ctsw16_e9_e8, s_ctsw16_e9_e8 },
// 32-bit calltrick
{ 0x11, 6, 0, f_ct32_e8, u_ct32_e8, s_ct32_e8 },
{ 0x12, 6, 0, f_ct32_e9, u_ct32_e9, s_ct32_e9 },
@@ -429,21 +202,59 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
{ 0x17, 6, 0, f_ct32_e8_bswap_be, u_ct32_e8_bswap_be, s_ct32_e8_bswap_be },
{ 0x18, 6, 0, f_ct32_e9_bswap_be, u_ct32_e9_bswap_be, s_ct32_e9_bswap_be },
{ 0x19, 6, 0, f_ct32_e8e9_bswap_be, u_ct32_e8e9_bswap_be, s_ct32_e8e9_bswap_be },
// 32-bit swaptrick
{ 0x1a, 6, 0, f_sw32_e8, u_sw32_e8, s_sw32_e8 },
{ 0x1b, 6, 0, f_sw32_e9, u_sw32_e9, s_sw32_e9 },
{ 0x1c, 6, 0, f_sw32_e8e9, u_sw32_e8e9, s_sw32_e8e9 },
// 32-bit call-/swaptrick
{ 0x1d, 6, 0, f_ctsw32_e8_e9, u_ctsw32_e8_e9, s_ctsw32_e8_e9 },
{ 0x1e, 6, 0, f_ctsw32_e9_e8, u_ctsw32_e9_e8, s_ctsw32_e9_e8 },
// 32-bit cto calltrick
{ 0x21, 6, 0x00ffffff, f_cto32_e8, u_cto32_e8, s_cto32_e8 },
{ 0x22, 6, 0x00ffffff, f_cto32_e9, u_cto32_e9, s_cto32_e9 },
{ 0x23, 6, 0x00ffffff, f_cto32_e8e9, u_cto32_e8e9, s_cto32_e8e9 },
{ 0x24, 6, 0x00ffffff, f_cto32_e8_bswap_le, u_cto32_e8_bswap_le, s_cto32_e8_bswap_le },
{ 0x25, 6, 0x00ffffff, f_cto32_e9_bswap_le, u_cto32_e9_bswap_le, s_cto32_e9_bswap_le },
{ 0x26, 6, 0x00ffffff, f_cto32_e8e9_bswap_le, u_cto32_e8e9_bswap_le, s_cto32_e8e9_bswap_le },
{ 0x27, 6, 0x00ffffff, f_cto32_e8_bswap_be, u_cto32_e8_bswap_be, s_cto32_e8_bswap_be },
{ 0x28, 6, 0x00ffffff, f_cto32_e9_bswap_be, u_cto32_e9_bswap_be, s_cto32_e9_bswap_be },
{ 0x29, 6, 0x00ffffff, f_cto32_e8e9_bswap_be, u_cto32_e8e9_bswap_be, s_cto32_e8e9_bswap_be },
// 32-bit cto calltrick + jmp
{ 0x36, 6, 0x00ffffff, f_ctjo32_e8e9_bswap_le, u_ctjo32_e8e9_bswap_le, s_ctjo32_e8e9_bswap_le },
// 32-bit cto calltrick with jmp
{ 0x36, 6, 0x00ffffff, f_ctoj32_e8e9_bswap_le, u_ctoj32_e8e9_bswap_le, s_ctoj32_e8e9_bswap_le },
// 32-bit calltrick with jmp, optional jcc; runtime can unfilter more than one block
{ 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 },
// 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 },
{ 0x82, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
{ 0x83, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
{ 0x84, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
{ 0x85, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
{ 0x86, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
{ 0x87, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },
// simple delta filter
{ 0x90, 2, 0, f_sub8_1, u_sub8_1, s_sub8_1 },
{ 0x91, 3, 0, f_sub8_2, u_sub8_2, s_sub8_2 },
{ 0x92, 4, 0, f_sub8_3, u_sub8_3, s_sub8_3 },
{ 0x93, 5, 0, f_sub8_4, u_sub8_4, s_sub8_4 },
{ 0xa0,99, 0, f_sub16_1, u_sub16_1, s_sub16_1 },
{ 0xa1,99, 0, f_sub16_2, u_sub16_2, s_sub16_2 },
{ 0xa2,99, 0, f_sub16_3, u_sub16_3, s_sub16_3 },
{ 0xa3,99, 0, f_sub16_4, u_sub16_4, s_sub16_4 },
{ 0xb0,99, 0, f_sub32_1, u_sub32_1, s_sub32_1 },
{ 0xb1,99, 0, f_sub32_2, u_sub32_2, s_sub32_2 },
{ 0xb2,99, 0, f_sub32_3, u_sub32_3, s_sub32_3 },
{ 0xb3,99, 0, f_sub32_4, u_sub32_4, s_sub32_4 },
// PowerPC branch+call trick
{ 0xd0, 8, 0, f_ppcbxx, u_ppcbxx, s_ppcbxx },
};
const int FilterImp::n_filters = HIGH(filters);
const int FilterImp::n_filters = TABLESIZE(filters);
/*
+124 -51
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -44,13 +44,26 @@ void show_head(void)
return;
head_done = 1;
#define V(x) (strcmp(UPX_VERSION_STRING, UPX_VERSION_STRING4) ? UPX_VERSION_STRING : UPX_VERSION_STRING x)
fg = con_fg(f,FG_GREEN);
con_fprintf(f,
" Ultimate Packer for eXecutables\n"
" Copyright (C) 1996, 1997, 1998, 1999, 2000\n"
"UPX v%-12sMarkus F.X.J. Oberhumer & Laszlo Molnar%21s\n\n",
UPX_VERSION_STRING, UPX_VERSION_DATE);
" Ultimate Packer for eXecutables\n"
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006\n"
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
V("d"),
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
V("w"),
#elif 0 && defined(__linux__)
V("l"),
#else
UPX_VERSION_STRING,
#endif
UPX_VERSION_DATE);
fg = con_fg(f,fg);
#undef V
UNUSED(fg);
}
@@ -62,7 +75,7 @@ void show_usage(void)
{
FILE *f = con_term;
con_fprintf(f,"Usage: %s [-123456788dlthVL] [-qvfk] [-o file] %sfile..\n", progname,
con_fprintf(f,"Usage: %s [-123456789dlthVL] [-qvfk] [-o file] %sfile..\n", progname,
#if defined(__DJGPP__) || defined(__EMX__)
"[@]");
#else
@@ -92,7 +105,7 @@ 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 very slow for big files)\n",
x == 0 ? "" : " --best compress best (can be slow for big files)\n",
x == 0 ? "more" : "this", x == 0 ? "" : "\n");
fg = con_fg(f,FG_YELLOW);
@@ -101,7 +114,6 @@ void show_help(int x)
con_fprintf(f,
" -q be quiet -v be verbose\n"
//" -oFILE write output to `FILE' -c write output to stdout\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"
@@ -128,20 +140,30 @@ void show_help(int x)
fg = con_fg(f,fg);
con_fprintf(f,
" --overlay=copy copy any extra data attached to the file [default]\n"
" --overlay=strip strip any extra data attached to the file [dangerous]\n"
" --overlay=strip strip any extra data attached to the file [DANGEROUS]\n"
" --overlay=skip don't compress a file with an overlay\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for atari/tos:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --all-methods try all available compression methods\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for djgpp2/coff:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --coff produce COFF output [default: EXE]\n"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for dos/com:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --8086 make compressed com work on any 8086\n"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for dos/exe:\n");
@@ -149,12 +171,47 @@ void show_help(int x)
con_fprintf(f,
" --8086 make compressed exe work on any 8086\n"
" --no-reloc put no relocations in to the exe header\n"
" --all-methods try all available compression methods\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for dos/sys:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --8086 make compressed sys work on any 8086\n"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
#if 0
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for linux/386\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --script use /usr/local/lib/upx/upx[bd] as decompressor\n"
" --script=/path/upxX use path/upxX as decompressor\n"
"\n");
#endif
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for ps1/exe:\n");
fg = con_fg(f,fg);
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"
" --no-align don't align to 2048 bytes [enables: --console-run]\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for tmt/adam:\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for vmlinuz/386\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for watcom/le:\n");
@@ -174,38 +231,45 @@ void show_help(int x)
" --compress-resources=0 do not compress any resources at all\n"
" --strip-relocs=0 do not strip relocations\n"
" --strip-relocs=1 strip relocations [default]\n"
" --all-methods try all available compression methods\n"
" --all-filters try all available preprocessing filters\n"
"\n");
#if 0
fg = con_fg(f,FG_YELLOW);
con_fprintf(f,"Options for linux/386\n");
fg = con_fg(f,fg);
con_fprintf(f,
" --script use /usr/local/lib/upx/upx[bd] as decompressor\n"
" --script=/path/upxX use path/upxX as decompressor\n"
"\n");
#endif
}
con_fprintf(f,
" file.. executables to (de)compress\n"
"\n"
"This version supports:\n "
"atari/tos, "
"bvmlinuz/386, "
"djgpp2/coff, "
"dos/com, "
"dos/exe, "
"dos/sys,\n "
"linux/386, "
"linux/elf386, "
"linux/sh386, "
"rtm32/pe, "
"tmt/adam, "
"vmlinuz/386,\n "
"watcom/le, "
"win32/pe"
"\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.tsx.org\n"
//"\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details type `upx -L'.\n"
"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"
"");
@@ -221,6 +285,8 @@ void show_help(int x)
"\n");
fg = con_fg(f,fg);
#endif
UNUSED(fg);
}
@@ -234,7 +300,7 @@ void show_license(void)
show_head();
con_fprintf(f,
con_fprintf(f,
" This program may be used freely, and you are welcome to\n"
" redistribute it under certain conditions.\n"
"\n"
@@ -249,17 +315,19 @@ con_fprintf(f,
"\n"
);
int fg = con_fg(f,FG_CYAN);
con_fprintf(f,
" http://upx.tsx.org\n"
" http://wildsau.idv.uni-linz.ac.at/mfx/upx.html\n"
con_fprintf(f,
" http://upx.sourceforge.net\n"
" http://www.oberhumer.com/opensource/upx/\n"
);
(void)con_fg(f,FG_ORANGE);
con_fprintf(f,
con_fprintf(f,
"\n"
" Markus F.X.J. Oberhumer Laszlo Molnar\n"
" markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu\n"
" Markus F.X.J. Oberhumer Laszlo Molnar\n"
" <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>\n"
);
fg = con_fg(f,fg);
UNUSED(fg);
}
@@ -272,16 +340,21 @@ void show_version(int x)
FILE *f = stdout;
UNUSED(x);
fprintf(f,"upx %s\n",UPX_VERSION_STRING);
#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
#if defined(WITH_NRV)
fprintf(f,"NRV data compression library %s\n", nrv_version_string());
#endif
#if defined(WITH_UCL)
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
#endif
fprintf(f,"Copyright (C) 1996,1997,1998,1999,2000 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(f,"Copyright (C) 1996,1997,1998,1999,2000 Laszlo Molnar\n");
fprintf(f,"Copyright (C) 2000 John F. Reiser\n");
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);
}
+29 -12
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -32,8 +32,13 @@
#include "lefile.h"
LeFile::LeFile(InputFile *f) : fif(f)
LeFile::LeFile(InputFile *f) :
fif(f), fof(NULL),
le_offset(0), exe_offset(0)
{
COMPILE_TIME_ASSERT(sizeof(le_header_t) == 196);
COMPILE_TIME_ASSERT(sizeof(le_object_table_entry_t) == 24);
COMPILE_TIME_ASSERT(sizeof(le_pagemap_entry_t) == 4);
memset(&ih,0,sizeof ih);
memset(&oh,0,sizeof oh);
iobject_table = oobject_table = NULL;
@@ -43,7 +48,6 @@ LeFile::LeFile(InputFile *f) : fif(f)
ifixups = ofixups = NULL;
inonres_names = ononres_names = NULL;
ientries = oentries = NULL;
le_offset = exe_offset = 0;
}
@@ -168,6 +172,18 @@ void LeFile::writeFixups()
}
unsigned LeFile::getImageSize() const
{
unsigned n = 0;
if (ih.memory_pages > 0)
{
n = (ih.memory_pages - 1) * ih.memory_page_size;
n += ih.bytes_on_last_page;
}
return n;
}
void LeFile::readImage()
{
soimage = pages*mps;
@@ -295,7 +311,8 @@ void LeFile::writeFile(OutputFile *f, bool le)
void LeFile::countFixups(unsigned *counts) const
{
memset(counts,0,sizeof(unsigned)*(objects+2));
const unsigned o = objects;
memset(counts,0,sizeof(unsigned)*(o+2));
// counts[0..objects-1] - # of 32-bit offset relocations in for that objects
// counts[objects] - # of selector fixups
// counts[objects+1] - # of self-relative fixups
@@ -311,7 +328,7 @@ void LeFile::countFixups(unsigned *counts) const
switch (*fix)
{
case 2: // selector fixup
counts[objects] += 9;
counts[o] += 9;
fix += 5;
break;
case 0x12: // alias selector
@@ -320,7 +337,7 @@ void LeFile::countFixups(unsigned *counts) const
fix += (fix[1] & 0x10) ? 9 : 7;
break;
case 6: // 16:32 pointer
counts[objects] += 9;
counts[o] += 9;
case 7: // 32-bit offset
counts[fix[4]-1] += 4;
fix += (fix[1] & 0x10) ? 9 : 7;
@@ -332,15 +349,15 @@ void LeFile::countFixups(unsigned *counts) const
fix += ll*2;
break;
case 8: // 32-bit self relative fixup
counts[objects+1] += 4;
counts[o+1] += 4;
fix += (fix[1] & 0x10) ? 9 : 7;
break;
default:
throwCantPack("unsupported fixup record");
}
}
counts[objects]++; // extra space for 'ret'
counts[objects+1] += 4; // extra space for 0xFFFFFFFF
counts[o]++; // extra space for 'ret'
counts[o+1] += 4; // extra space for 0xFFFFFFFF
}
+17 -13
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -117,7 +117,8 @@ protected:
LE16 device_id;
LE16 ddk_version;
#endif
};
}
__attribute_packed;
struct le_object_table_entry_t
{
@@ -127,15 +128,17 @@ protected:
LE32 pagemap_index;
LE32 npages;
LE32 reserved;
};
}
__attribute_packed;
struct le_pagemap_entry_t
{
upx_byte h;
upx_byte m;
upx_byte l;
upx_byte type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
};
unsigned char h;
unsigned char m;
unsigned char l;
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
}
__attribute_packed;
virtual void readObjectTable();
virtual void writeObjectTable();
@@ -178,6 +181,7 @@ protected:
//virtual void decodeImage(){encodeImage();}
void countFixups(unsigned *) const;
unsigned getImageSize() const;
InputFile *fif;
OutputFile *fof;
@@ -215,8 +219,8 @@ protected:
private:
// disable copy and assignment
LeFile(LeFile const &); // {}
LeFile& operator= (LeFile const &); // { return *this; }
LeFile(const LeFile &); // {}
LeFile& operator= (const LeFile &); // { return *this; }
};
+82 -44
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,66 +21,81 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
#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;
char name[8];
int istart;
int ostart;
int len;
LinkerLabel name;
};
struct Linker::jump
{
int pos;
int len;
char tsect[8];
int toffs;
int pos;
int len;
int toffs;
LinkerLabel tsect;
};
Linker::Linker(const void *pdata, int plen, int pinfo)
{
iloader = new char[(ilen = plen) + 4096];
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];
sections = new section[200];
#define NSECTIONS 550
sections = new section[NSECTIONS];
char *p = iloader + info;
while (get_le32(p) != (unsigned)(-1))
while (get32(p) != (unsigned)(-1))
{
if (get_le32(p))
if (get32(p))
{
memcpy(sections[nsections].name,p,8);
sections[nsections].istart = get_le32(p+8);
p += sections[nsections].name.set(p);
sections[nsections].istart = get32(p);
sections[nsections++].ostart = -1;
p += 12;
assert(nsections < 200);
p += 4;
assert(nsections < NSECTIONS);
}
else
{
int l;
for (l = get_le32(p+4) - 1; iloader[l] == 0; l--)
for (l = get32(p+4) - 1; iloader[l] == 0; l--)
;
jumps[njumps].pos = l+1;
jumps[njumps].len = get_le32(p+4)-jumps[njumps].pos;
memcpy(jumps[njumps].tsect,p+8,8);
jumps[njumps++].toffs = get_le32(p+16);
p += 20;
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);
}
}
@@ -101,50 +116,73 @@ Linker::~Linker()
}
void Linker::addSection(const char *sect)
void Linker::setLoaderAlignOffset(int offset)
{
int ic;
while (*sect)
align_offset = offset;
}
static int hex(char c)
{
return (c & 0xf) + (c > '9' ? 9 : 0);
}
int Linker::addSection(const char *psect)
{
if (psect[0] == 0)
return olen;
char *begin = strdup(psect);
char *end = begin + strlen(begin);
for (char *sect = begin; sect < end; )
{
for (char *tokend = sect; *tokend; tokend++)
if (*tokend == ' ' || *tokend == ',')
{
*tokend = 0;
break;
}
if (*sect == '+') // alignment
{
if (sect[1] == '0')
align_hack = olen;
align_hack = olen + align_offset;
else
{
ic = (sect[1] & 0xf) + (sect[1] > '9' ? 9 : 0);
ic = (ic + (sect[2] & 0xf) + (sect[2] > '9' ? 9 : 0)
- (olen - align_hack) % ic) % ic;
memset(oloader+olen,sect[3] == 'C' ? 0x90 : 0,ic);
olen += ic;
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;
}
}
else
{
int ic;
for (ic = 0; ic < nsections; ic++)
if (memcmp(sect,sections[ic].name,8) == 0)
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;
}
//printf("%8.8s",section);
assert(ic!=nsections);
if (ic == nsections)
printf("%s", sect);
assert(ic != nsections);
}
sect += 8;
sect += strlen(sect) + 1;
}
free(begin);
return olen;
}
void Linker::addSection(const char *sname, const void *sdata, unsigned len)
{
// add a new section - can be used for adding stuff like ident or header
memcpy(sections[nsections].name,sname,8);
sections[nsections].name.set(sname);
sections[nsections].istart = ilen;
sections[nsections].len = len;
sections[nsections++].ostart = olen;
assert(nsections < 200);
assert(nsections < NSECTIONS);
memcpy(iloader+ilen,sdata,len);
ilen += len;
}
@@ -166,7 +204,7 @@ const char *Linker::getLoader(int *llen)
continue;
for (kc = 0; kc < nsections-1; kc++)
if (memcmp(jumps[ic].tsect,sections[kc].name,8) == 0)
if (strcmp(jumps[ic].tsect,sections[kc].name) == 0)
break;
assert(kc!=nsections-1);
@@ -177,7 +215,7 @@ const char *Linker::getLoader(int *llen)
if (jumps[ic].len == 1)
assert(-128 <= offs && offs <= 127);
set_le32(&offs,offs);
set32(&offs,offs);
memcpy(oloader+sections[jc].ostart+jumps[ic].pos-sections[jc].istart,&offs,jumps[ic].len);
}
frozen=1;
@@ -192,7 +230,7 @@ int Linker::getSection(const char *name, int *slen) const
if (!frozen)
return -1;
for (int ic = 0; ic < nsections; ic++)
if (memcmp(name,sections[ic].name,8) == 0)
if (strcmp(name, sections[ic].name) == 0)
{
if (slen)
*slen = sections[ic].len;
+34 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -34,11 +34,18 @@ class Linker
{
public:
Linker(const void *pdata, int plen, int pinfo);
~Linker();
void addSection(const char *sect);
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);
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); }
private:
struct section;
@@ -53,14 +60,33 @@ private:
int nsections;
int frozen;
int align_hack;
int align_offset;
private:
// disable copy and assignment
Linker(Linker const &); // {}
Linker& operator= (Linker const &); // { return *this; }
Linker(const Linker &); // {}
Linker& operator= (const Linker &); // { return *this; }
};
class BeLinker : public Linker
{
typedef Linker super;
public:
BeLinker(const void *pdata, int plen, int pinfo) :
super(pdata, plen, pinfo) { }
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; }
};
#endif /* already included */
+320 -148
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,14 +21,21 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "mygetopt.h"
#include "file.h"
#include "packer.h"
#if 1 && defined(__DJGPP__)
#include <crt0.h>
int _crt0_startup_flags = _CRT0_FLAG_UNIX_SBRK;
#endif
/*************************************************************************
@@ -43,28 +50,32 @@ void init_options(struct options_t *o)
o->cmd = CMD_NONE;
o->method = -1;
o->level = -1;
o->mem_level = -1;
o->filter = -1;
o->backup = -1;
o->overlay = -1;
o->console = CON_FILE;
#if defined(__MFX_DOS) || defined(__MFX_WIN)
#if defined(__DJGPP__)
o->console = CON_INIT;
#elif defined(USE_SCREEN_WIN32)
o->console = CON_INIT;
#elif 1 && defined(__linux__)
o->console = CON_INIT;
#endif
o->verbose = 2;
o->w32pe.compress_exports = 1;
o->w32pe.compress_icons = 2;
o->w32pe.compress_resources = true;
o->w32pe.strip_relocs = -1;
o->win32_pe.compress_exports = 1;
o->win32_pe.compress_icons = 2;
o->win32_pe.compress_resources = -1;
for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++)
o->win32_pe.compress_rt[i] = -1;
o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
o->win32_pe.strip_relocs = -1;
}
static struct options_t global_options;
struct options_t * volatile opt = &global_options;
struct options_t *opt = &global_options;
static int done_output_name = 0;
static int done_script_name = 0;
@@ -83,7 +94,7 @@ static int exit_code = EXIT_OK;
**************************************************************************/
#if defined(__GNUC__)
static void do_exit(void) __attribute__((noreturn));
static void do_exit(void) __attribute__((__noreturn__));
#endif
static void do_exit(void)
{
@@ -174,6 +185,14 @@ 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);
e_exit(EXIT_USAGE);
}
#if defined(OPTIONS_VAR)
void e_envopt(const char *n)
{
@@ -189,7 +208,7 @@ void e_envopt(const char *n)
#endif /* defined(OPTIONS_VAR) */
RETSIGTYPE SIGTYPEENTRY e_sighandler(int signum)
void __acc_cdecl_sighandler e_sighandler(int signum)
{
UNUSED(signum);
e_exit(EXIT_FATAL);
@@ -228,6 +247,11 @@ void check_options(int i, int argc)
opt->backup = 1;
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);
e_usage();
}
if (opt->to_stdout || opt->output_name)
{
if (i + 1 != argc)
@@ -256,7 +280,7 @@ static void set_term(FILE *f)
if (f)
con_term = f;
else
con_term = isafile(STDIN_FILENO) ? stderr : stdout;
con_term = acc_isatty(STDIN_FILENO) ? stderr : stdout;
}
@@ -270,7 +294,12 @@ static void set_cmd(int cmd)
static bool set_method(int m, int l)
{
if (m > 0)
{
if (!Packer::isValidCompressionMethod(m))
return false;
opt->method = m;
opt->all_methods = false;
}
if (l > 0)
opt->level = l;
set_cmd(CMD_COMPRESS);
@@ -292,7 +321,7 @@ static void set_output_name(const char *n, bool allow_m)
fprintf(stderr,"%s: missing output name\n",argv0);
e_usage();
}
if (strlen(n) >= PATH_MAX - 4)
if (strlen(n) >= ACC_FN_PATH_MAX - 4)
{
fprintf(stderr,"%s: output name too long\n",argv0);
e_usage();
@@ -315,12 +344,12 @@ static void set_script_name(const char *n, bool allow_m)
fprintf(stderr,"%s: missing script name\n",argv0);
e_usage();
}
if (strlen(n) >= opt->unix.SCRIPT_MAX - 3)
if (strlen(n) >= (size_t)opt->o_unix.SCRIPT_MAX - 3)
{
fprintf(stderr,"%s: script name too long\n",argv0);
e_usage();
}
opt->unix.script_name = n;
opt->o_unix.script_name = n;
done_script_name++;
}
@@ -374,7 +403,7 @@ char* prepare_shortopts(char *buf, const char *n,
template <class T>
int getoptvar(T *var, T minval, T maxval)
int getoptvar(T *var, const T minval, const T maxval)
{
const char *p = mfx_optarg;
char *endptr;
@@ -403,20 +432,23 @@ static int do_option(int optc, const char *arg)
switch (optc)
{
#if 0
// FIXME: to_stdout doesn't work because of console code mess
//case 'c':
case 517:
opt->to_stdout = true;
break;
#endif
case 'd':
set_cmd(CMD_DECOMPRESS);
break;
case 'D':
opt->debug++;
opt->debug.debug_level++;
break;
case 'f':
opt->force++;
break;
case 901:
case 902:
set_cmd(CMD_FILEINFO);
break;
case 'h':
@@ -425,9 +457,11 @@ 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;
#endif
show_help(1);
e_exit(EXIT_OK);
break;
@@ -472,6 +506,10 @@ static int do_option(int optc, const char *arg)
if (!set_method(M_NRV2D_LE32, -1))
e_method(M_NRV2D_LE32, opt->level);
break;
case 705:
if (!set_method(M_NRV2E_LE32, -1))
e_method(M_NRV2E_LE32, opt->level);
break;
// compression level
case '1':
@@ -486,14 +524,34 @@ static int do_option(int optc, const char *arg)
if (!set_method(-1, optc - '0'))
e_method(opt->method, optc);
break;
case 900:
case 901: // --brute
opt->all_methods = true;
opt->method = -1;
opt->all_filters = true;
opt->filter = -1;
opt->crp.m_size = 999999;
/* fallthrough */
case 900: // --best
if (!set_method(-1, 10))
e_method(opt->method, 10);
break;
// compression memory level
case 902:
getoptvar(&opt->mem_level, 1, 9);
// debug
case 542:
if (!mfx_optarg || strlen(mfx_optarg) != 4)
e_optarg(arg);
memcpy(opt->debug.fake_stub_version, mfx_optarg, 4);
break;
case 543:
if (!mfx_optarg || strlen(mfx_optarg) != 4)
e_optarg(arg);
memcpy(opt->debug.fake_stub_year, mfx_optarg, 4);
break;
case 544:
if (!mfx_optarg || !mfx_optarg[0])
e_optarg(arg);
opt->debug.dump_stub_loader = mfx_optarg;
break;
// misc
@@ -513,17 +571,28 @@ static int do_option(int optc, const char *arg)
opt->no_env = true;
break;
// compression settings
case 525:
opt->small = 1;
case 520: // --small
if (opt->small < 0)
opt->small = 0;
opt->small++;
break;
case 526:
case 521: // --filter=
getoptvar(&opt->filter, 0, 255);
opt->all_filters = false;
break;
case 527:
case 522: // --no-filter
opt->filter = 0;
opt->all_filters = false;
opt->no_filter = true;
break;
case 523: // --all-filters
opt->all_filters = true;
opt->filter = -1;
break;
case 524: // --all-methods
opt->all_methods = true;
opt->method = -1;
break;
// compression parms
case 531:
getoptvar(&opt->crp.c_flags, 0, 3);
@@ -544,7 +613,8 @@ static int do_option(int optc, const char *arg)
getoptvar(&opt->crp.max_match, 16u, ~0u);
break;
case 537:
getoptvar(&opt->crp.m_size, 1024u, 512*1024u);
if (getoptvar(&opt->crp.m_size, 10000u, 999999u) != 0)
e_optval("--crp-ms=");
break;
// backup
case 'k':
@@ -596,50 +666,75 @@ static int do_option(int optc, const char *arg)
break;
//
case 600:
opt->dos.force_stub = true;
opt->dos_exe.force_stub = true;
break;
case 601:
opt->dos.no_reloc = true;
opt->dos_exe.no_reloc = true;
break;
case 610:
opt->djgpp2.coff = true;
opt->djgpp2_coff.coff = true;
break;
case 620:
opt->wcle.le = true;
opt->watcom_le.le = true;
break;
case 630:
opt->w32pe.compress_exports = 1;
getoptvar(&opt->w32pe.compress_exports, 0, 1);
//printf("compress_exports: %d\n", opt->w32pe.compress_exports);
opt->win32_pe.compress_exports = 1;
getoptvar(&opt->win32_pe.compress_exports, 0, 1);
//printf("compress_exports: %d\n", opt->win32_pe.compress_exports);
break;
case 631:
opt->w32pe.compress_icons = 1;
getoptvar(&opt->w32pe.compress_icons, 0, 2);
//printf("compress_icons: %d\n", opt->w32pe.compress_icons);
opt->win32_pe.compress_icons = 1;
getoptvar(&opt->win32_pe.compress_icons, 0, 2);
//printf("compress_icons: %d\n", opt->win32_pe.compress_icons);
break;
case 632:
opt->w32pe.compress_resources = true;
opt->win32_pe.compress_resources = true;
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
opt->w32pe.compress_resources = false;
//printf("compress_resources: %d\n", opt->w32pe.compress_resources);
opt->win32_pe.compress_resources = false;
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
break;
case 633:
opt->w32pe.strip_relocs = 1;
// opt->win32_pe.strip_loadconf - OBSOLETE - IGNORED
break;
case 634:
opt->win32_pe.strip_relocs = 1;
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
opt->w32pe.strip_relocs = 0;
//printf("strip_relocs: %d\n", opt->w32pe.strip_relocs);
opt->win32_pe.strip_relocs = 0;
//printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
break;
case 650:
opt->tos.split_segments = true;
opt->atari_tos.split_segments = true;
break;
case 660:
getoptvar(&opt->unix.blocksize, 8192u, ~0u);
getoptvar(&opt->o_unix.blocksize, 8192u, ~0u);
break;
case 661:
opt->unix.script_name = "/usr/local/lib/upx/upxX";
opt->o_unix.force_execve = true;
break;
case 662:
opt->o_unix.script_name = "/usr/local/lib/upx/upxX";
if (mfx_optarg && mfx_optarg[0])
set_script_name(mfx_optarg,1);
break;
case 663:
opt->o_unix.is_ptinterp = true;
break;
case 664:
opt->o_unix.use_ptinterp = true;
break;
case 665:
opt->o_unix.make_ptinterp = true;
break;
case 670:
opt->ps1_exe.boot_only = true;
break;
case 671:
opt->ps1_exe.no_align = true;
opt->ps1_exe.boot_only = false;
break;
case 672:
opt->ps1_exe.do_8bit = true;
break;
case '\0':
return -1;
@@ -661,10 +756,12 @@ static int get_options(int argc, char **argv)
static const struct mfx_option longopts[] =
{
// commands
{"best", 0, 0, 900}, // compress best
{"best", 0x10, 0, 900}, // compress best
{"brute", 0x10, 0, 901}, // compress best, brute force
{"decompress", 0, 0, 'd'}, // decompress
{"fast", 0, 0, '1'}, // compress faster
{"fileinfo", 0x10, 0, 901}, // display info about file
{"fast", 0x10, 0, '1'}, // compress faster
{"fileinfo", 0x10, 0, 902}, // display info about file
{"file-info", 0x10, 0, 902}, // 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
@@ -673,7 +770,6 @@ static const struct mfx_option longopts[] =
{"version", 0, 0, 'V'+256}, // display version number
// options
{"debug", 0x10, 0, 'D'},
{"force", 0, 0, 'f'}, // force overwrite of output files
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files
{"info", 0, 0, 'i'}, // info mode
@@ -682,10 +778,19 @@ static const struct mfx_option longopts[] =
{"output", 0x21, 0, 'o'},
{"quiet", 0, 0, 'q'}, // quiet mode
{"silent", 0, 0, 'q'}, // quiet mode
#if 0
// FIXME: to_stdout doesn't work because of console code mess
{"stdout", 0x10, 0, 517}, // write output on standard output
{"to-stdout", 0x10, 0, 517}, // write output on standard output
#endif
{"verbose", 0, 0, 'v'}, // verbose mode
// debug options
{"debug", 0x10, 0, 'D'},
{"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
// backup options
{"backup", 0, 0, 'k'},
{"keep", 0, 0, 'k'},
@@ -710,17 +815,15 @@ static const struct mfx_option longopts[] =
{"color", 0, 0, 514},
// compression method
{"2b", 0x10, 0, 702}, // --2b
{"n2b", 0x10, 0, 702}, // --n2b
{"nrv2b", 0x10, 0, 702}, // --nrv2b
{"2d", 0x10, 0, 704}, // --2d
{"n2d", 0x10, 0, 704}, // --n2d
{"nrv2d", 0x10, 0, 704}, // --nrv2d
{"nrv2e", 0x10, 0, 705}, // --nrv2e
// compression settings
{"all-filters", 0x10, 0, 527},
{"filter", 0x31, 0, 526}, // --filter=
{"mem", 0x31, 0, 902}, // --mem=
{"small", 0x10, 0, 525},
{"all-filters", 0x10, 0, 523},
{"all-methods", 0x10, 0, 524},
{"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},
@@ -741,18 +844,27 @@ static const struct mfx_option longopts[] =
// dos/sys
// unix
{"blocksize", 0x31, 0, 660}, // --blocksize=
{"force-execve", 0x10, 0, 661}, // force linux/386 execve format
#if 0
{"script", 0x31, 0, 661}, // --script=
{"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
// watcom/le
{"le", 0, 0, 620}, // produce LE output
// win32/pe
{"compress-exports", 2, 0, 630},
{"compress-icons", 2, 0, 631},
{"compress-resources", 2, 0, 632},
{"strip-relocs", 2, 0, 633},
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634},
// ps1/exe
{"boot-only", 0x10, 0, 670},
{"no-align", 0x10, 0, 671},
{"8-bit", 0x10, 0, 672},
{ 0, 0, 0, 0 }
{ NULL, 0, NULL, 0 }
};
int optc, longind;
@@ -780,8 +892,9 @@ static void get_envoptions(int argc, char **argv)
static const struct mfx_option longopts[] =
{
// commands
{"best", 0, 0, 900}, // compress best
{"fast", 0, 0, '1'}, // compress faster
{"best", 0x10, 0, 900}, // compress best
{"brute", 0x10, 0, 901}, // compress best, brute force
{"fast", 0x10, 0, '1'}, // compress faster
// options
{"info", 0, 0, 'i'}, // info mode
@@ -813,13 +926,23 @@ static const struct mfx_option longopts[] =
{"mono", 0, 0, 513},
{"color", 0, 0, 514},
// 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},
{"compress-icons", 2, 0, 631},
{"compress-resources", 2, 0, 632},
{"strip-relocs", 2, 0, 633},
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634},
{ 0, 0, 0, 0 }
{ NULL, 0, NULL, 0 }
};
char *env, *p;
@@ -907,14 +1030,22 @@ static const struct mfx_option longopts[] =
static void first_options(int argc, char **argv)
{
int i;
int n = argc;
for (i = 1; i < argc; i++)
for (i = 1; i < n; i++)
{
if (strcmp(argv[i],"--") == 0)
{
n = i;
break;
}
if (strcmp(argv[i],"--version") == 0)
do_option('V'+256, argv[i]);
for (i = 1; i < argc; i++)
}
for (i = 1; i < n; i++)
if (strcmp(argv[i],"--help") == 0)
do_option('h'+256, argv[i]);
for (i = 1; i < argc; i++)
for (i = 1; i < n; i++)
if (strcmp(argv[i],"--no-env") == 0)
do_option(519, argv[i]);
}
@@ -924,59 +1055,110 @@ static void first_options(int argc, char **argv)
// assert a sane architecture and compiler
**************************************************************************/
template <class T> struct TestBELE {
static int test(void)
{
T allbits; allbits = 0; allbits -= 1;
T v1; v1 = 1; v1 *= 2; v1 -= 1;
T v2; v2 = 1;
assert( (v1 == v2)); assert(!(v1 != v2));
assert( (v1 <= v2)); assert( (v1 >= v2));
assert(!(v1 < v2)); assert(!(v1 > v2));
v2 ^= allbits;
assert(!(v1 == v2)); assert( (v1 != v2));
assert( (v1 <= v2)); assert(!(v1 >= v2));
assert( (v1 < v2)); assert(!(v1 > v2));
v2 += 2;
assert(v1 == 1); assert(v2 == 0);
return (v1 ^ v2) == 1;
}};
#define ACC_WANT_ACC_CHK_CH 1
#undef ACCCHK_ASSERT
#include "miniacc.h"
void upx_sanity_check(void)
{
assert(sizeof(char) == 1);
assert(sizeof(short) == 2);
assert(sizeof(int) == 4);
assert(sizeof(long) >= 4);
assert(sizeof(void *) >= 4);
assert(sizeof(long) >= sizeof(void *));
assert(((size_t) -1) > 0);
assert(((ptrdiff_t) -1) < 0);
assert(((off_t) -1) < 0);
#define ACC_WANT_ACC_CHK_CH 1
#undef ACCCHK_ASSERT
#define ACCCHK_ASSERT(expr) ACC_COMPILE_TIME_ASSERT(expr)
#include "miniacc.h"
#undef ACCCHK_ASSERT
assert(sizeof(BE16) == 2);
assert(sizeof(BE32) == 4);
assert(sizeof(LE16) == 2);
assert(sizeof(LE32) == 4);
COMPILE_TIME_ASSERT(sizeof(char) == 1)
COMPILE_TIME_ASSERT(sizeof(short) == 2)
COMPILE_TIME_ASSERT(sizeof(int) == 4)
COMPILE_TIME_ASSERT(sizeof(long) >= 4)
COMPILE_TIME_ASSERT(sizeof(void *) >= 4)
struct align_assertion_1a_t
COMPILE_TIME_ASSERT(sizeof(off_t) >= sizeof(long))
COMPILE_TIME_ASSERT(((off_t) -1) < 0)
COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
COMPILE_TIME_ASSERT(sizeof(BE64) == 8)
COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
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(sizeof(UPX_VERSION_STRING4) == 4 + 1)
assert(strlen(UPX_VERSION_STRING4) == 4);
assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0);
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_YEAR) == 4 + 1)
assert(strlen(UPX_VERSION_YEAR) == 4);
assert(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0);
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
{
struct foo_t {
char c1;
LE16 v[4];
} d[3];
};
struct align_assertion_1b_t
{
struct foo_t {
char c1;
char v[4*2];
} d[3];
};
struct align_assertion_2a_t
{
struct foo_t {
char c1;
LE32 v[4];
} d[3];
};
struct align_assertion_2b_t
{
struct foo_t {
char c1;
char v[4*4];
} d[3];
};
//printf("%d\n", (int) sizeof(align_assertion_1a_t));
//printf("%d\n", (int) sizeof(align_assertion_1b_t));
//printf("%d\n", (int) sizeof(align_assertion_2a_t));
//printf("%d\n", (int) sizeof(align_assertion_2b_t));
assert(sizeof(align_assertion_1a_t) == sizeof(align_assertion_1b_t));
assert(sizeof(align_assertion_2a_t) == sizeof(align_assertion_2b_t));
assert(sizeof(align_assertion_1a_t) == 3*9);
assert(sizeof(align_assertion_2a_t) == 3*17);
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
0, 0, 0, 0,
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
0, 0, 0, 0, 0 };
const unsigned char *d;
d = dd + 7;
assert(upx_adler32(d, 4) == 0x09f003f7);
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
assert(get_be16(d) == 0xfffe);
assert(get_be16_signed(d) == -2);
assert(get_be24(d) == 0xfffefd);
assert(get_be24_signed(d) == -259);
assert(get_be32(d) == 0xfffefdfc);
assert(get_be32_signed(d) == -66052);
assert(get_le16(d) == 0xfeff);
assert(get_le16_signed(d) == -257);
assert(get_le24(d) == 0xfdfeff);
assert(get_le24_signed(d) == -131329);
assert(get_le32(d) == 0xfcfdfeff);
assert(get_le32_signed(d) == -50462977);
assert(find_be16(d, 2, 0xfffe) == 0);
assert(find_le16(d, 2, 0xfeff) == 0);
assert(find_be32(d, 4, 0xfffefdfc) == 0);
assert(find_le32(d, 4, 0xfcfdfeff) == 0);
d += 12;
assert(get_be16_signed(d) == 32638);
assert(get_be24_signed(d) == 8355453);
assert(get_be32_signed(d) == 2138996092);
}
#endif
}
@@ -986,40 +1168,37 @@ void upx_sanity_check(void)
#if !defined(WITH_GUI)
int main(int argc, char *argv[])
int __acc_cdecl_main main(int argc, char *argv[])
{
int i;
static char default_argv0[] = "upx";
int cmdline_cmd = CMD_NONE;
// int cmdline_cmd = CMD_NONE;
#if 0 && defined(__DJGPP__)
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
putenv("LFN=y");
#endif
acc_wildargv(&argc, &argv);
upx_sanity_check();
init_options(opt);
#if defined(WITH_MSS)
MSS_DISABLE_LOG_OUTPUT;
#endif
#if defined(__EMX__)
_response(&argc,&argv);
_wildcard(&argc,&argv);
#endif
if (!argv[0] || !argv[0][0])
argv[0] = default_argv0;
argv0 = argv[0];
#if defined(DOSISH)
#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
{
char *prog = fn_basename(argv0);
char *p;
bool allupper = 1;
bool allupper = true;
for (p = prog; *p; p++)
if (islower((unsigned char)*p))
allupper = 0;
allupper = false;
if (allupper)
fn_strlwr(prog);
if (strlen(prog) > 4)
if (p - prog > 4)
{
p = prog + strlen(prog) - 4;
p -= 4;
if (fn_strcmp(p, ".exe") == 0 || fn_strcmp(p, ".ttp") == 0)
*p = 0;
}
@@ -1028,6 +1207,8 @@ int main(int argc, char *argv[])
#else
progname = fn_basename(argv0);
#endif
while (progname[0] == '.' && progname[1] == '/' && progname[2])
progname += 2;
set_term(stderr);
@@ -1043,7 +1224,7 @@ int main(int argc, char *argv[])
}
#endif
#if defined(WITH_NRV)
if (nrv_init() != NRV_E_OK)
if (nrv_init() != NRV_E_OK || NRV_VERSION != nrv_version())
{
show_head();
fprintf(stderr,"nrv_init() failed - check your NRV installation !\n");
@@ -1066,8 +1247,8 @@ int main(int argc, char *argv[])
i = get_options(argc,argv);
assert(i <= argc);
set_term(0);
cmdline_cmd = opt->cmd;
set_term(NULL);
// cmdline_cmd = opt->cmd;
switch (opt->cmd)
{
case CMD_NONE:
@@ -1106,7 +1287,6 @@ int main(int argc, char *argv[])
// invalidate compression options
opt->method = 0;
opt->level = 0;
opt->mem_level = 0;
memset(&opt->crp, 0xff, sizeof(opt->crp));
}
@@ -1128,27 +1308,19 @@ int main(int argc, char *argv[])
set_term(stdout);
do_files(i,argc,argv);
#if 1 && (UPX_VERSION < 0x012000)
#if 0 && (UPX_VERSION_HEX < 0x020000)
{
FILE *f = stdout;
int fg = con_fg(f,FG_RED);
con_fprintf(f,"\nWARNING: this is an unstable beta version - use for testing only! Really.\n");
fg = con_fg(f,fg);
}
#endif
#if 1 && !defined(WITH_NRV)
{
FILE *f = stdout;
int fg = con_fg(f,FG_GREEN);
con_fprintf(f,"\nINFO: this version does not use the NRV library - compression ratio is worse\n");
fg = con_fg(f,fg);
UNUSED(fg);
}
#endif
#if 0 && defined(__GLIBC__)
//malloc_stats();
#endif
do_exit();
return exit_code;
}
+146 -64
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -34,84 +34,166 @@
//
**************************************************************************/
MemBuffer::MemBuffer(unsigned size) :
ptr(NULL), alloc_ptr(NULL), alloc_size(0)
static int use_mcheck = -1;
static int mcheck_init()
{
if (size > 0)
alloc(size, 0);
if (use_mcheck < 0)
{
use_mcheck = 1;
#if defined(WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
if (RUNNING_ON_VALGRIND)
{
//fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n");
use_mcheck = 0;
}
#endif
}
return use_mcheck;
}
/*************************************************************************
//
**************************************************************************/
MemBuffer::MemBuffer() :
b(NULL), b_size(0)
{
}
MemBuffer::MemBuffer(unsigned size) :
b(NULL), b_size(0)
{
alloc(size);
}
MemBuffer::~MemBuffer()
{
this->free();
this->dealloc();
}
void MemBuffer::free()
void MemBuffer::dealloc()
{
if (alloc_ptr)
::free(alloc_ptr);
alloc_ptr = ptr = NULL;
alloc_size = 0;
}
unsigned MemBuffer::getSize() const
{
if (!alloc_ptr)
return 0;
unsigned size = alloc_size - (ptr - alloc_ptr);
assert((int)size > 0);
return size;
}
void MemBuffer::alloc(unsigned size, unsigned base_offset)
{
#if 0
this->free();
#else
// don't automaticlly free a used buffer
#endif
assert(alloc_ptr == NULL);
assert((int)size > 0);
size = base_offset + size;
alloc_ptr = (unsigned char *) malloc(size);
if (!alloc_ptr)
if (b)
{
throwCantPack("out of memory");
//exit(1);
checkState();
if (use_mcheck)
{
// remove magic constants
set_be32(b - 8, 0);
set_be32(b - 4, 0);
set_be32(b + b_size, 0);
set_be32(b + b_size + 4, 0);
//
::free(b - 8);
}
else
::free(b);
b = NULL;
b_size = 0;
}
alloc_size = size;
ptr = alloc_ptr + base_offset;
else
assert(b_size == 0);
}
void MemBuffer::allocForCompression(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);
}
void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra)
{
assert((int)uncompressed_size > 0);
assert((int)extra >= 0);
unsigned size = uncompressed_size + extra;
// size += 512; // 512 safety bytes
// INFO: 3 bytes are the allowed overrun for the i386 asm_fast decompressors
#if (ACC_ARCH_I386)
size += 3;
#endif
alloc(size);
}
void MemBuffer::fill(unsigned off, unsigned len, int value)
{
checkState();
assert((int)off >= 0);
assert((int)len >= 0);
assert(off <= b_size);
assert(len <= b_size);
assert(off + len <= b_size);
if (len > 0)
memset(b + off, value, len);
}
/*************************************************************************
//
**************************************************************************/
#define PTR(p) ((unsigned) ((acc_uintptr_t)(p) & 0xffffffff))
#define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb)
#define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001)
unsigned MemBuffer::global_alloc_counter = 0;
void MemBuffer::checkState() const
{
if (!b)
throwInternalError("block not allocated");
if (use_mcheck)
{
if (get_be32(b - 4) != MAGIC1(b))
throwInternalError("memory clobbered before allocated block 1");
if (get_be32(b - 8) != b_size)
throwInternalError("memory clobbered before allocated block 2");
if (get_be32(b + b_size) != MAGIC2(b))
throwInternalError("memory clobbered past end of allocated block");
}
assert((int)b_size > 0);
}
void MemBuffer::alloc(unsigned size)
{
alloc(size, 0);
}
if (use_mcheck < 0)
mcheck_init();
void MemBuffer::allocForCompression(unsigned uncompressed_size)
{
// Idea:
// We allocate the buffer at an offset of 4096 so
// that we could do an in-place decompression for
// verifying our overlap_overhead at the end
// of packing.
// NOTE: we don't automatically free a used buffer
assert(b == NULL);
assert(b_size == 0);
//
// See Packer::verifyOverlappingDecompression().
alloc(uncompressed_size + uncompressed_size/8 + 256, MAX_OVERLAP_OVERHEAD);
}
void MemBuffer::allocForUncompression(unsigned uncompressed_size)
{
//alloc(uncompressed_size + 3 + 512, 0); // 512 safety bytes
alloc(uncompressed_size + 3, 0); // 3 bytes for asm_fast decompresion
assert((int)size > 0);
unsigned total = use_mcheck ? size + 16 : size;
assert((int)total > 0);
unsigned char *p = (unsigned char *) malloc(total);
if (!p)
{
//throw bad_alloc();
throw OutOfMemoryException("out of memory");
//exit(1);
}
b_size = size;
if (use_mcheck)
{
b = p + 8;
// store magic constants to detect buffer overruns
set_be32(b - 8, b_size);
set_be32(b - 4, MAGIC1(b));
set_be32(b + b_size, MAGIC2(b));
set_be32(b + b_size + 4, global_alloc_counter++);
}
else
b = p ;
}
+25 -25
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -37,43 +37,43 @@
class MemBuffer
{
public:
MemBuffer(unsigned size=0);
MemBuffer();
MemBuffer(unsigned size);
~MemBuffer();
void alloc(unsigned size);
void allocForCompression(unsigned uncompressed_size);
void allocForUncompression(unsigned uncompressed_size);
void allocForCompression(unsigned uncompressed_size, unsigned extra=0);
void allocForUncompression(unsigned uncompressed_size, unsigned extra=0);
void free();
void dealloc();
const unsigned char *getBuf() const { return ptr; }
unsigned getSize() const ;
void checkState() const;
operator unsigned char * () { return ptr; }
//operator const unsigned char * () const { return ptr; }
unsigned getSize() const { return b_size; }
enum { MAX_OVERLAP_OVERHEAD = 4096 };
operator unsigned char * () { return b; }
//operator const unsigned char * () const { return b; }
void *getVoidPtr() { return (void *) b; }
const void *getVoidPtr() const { return (const void *) b; }
void fill(unsigned off, unsigned len, int value);
void clear(unsigned off, unsigned len) { fill(off, len, 0); }
void clear() { fill(0, b_size, 0); }
private:
void alloc(unsigned size, unsigned base_offset);
unsigned char *b;
unsigned b_size;
unsigned char *ptr;
unsigned char *alloc_ptr;
unsigned alloc_size;
static unsigned global_alloc_counter;
private:
// disable copy and assignment
MemBuffer(MemBuffer const &); // {}
MemBuffer& operator= (MemBuffer const &); // { return *this; }
MemBuffer(const MemBuffer &); // {}
MemBuffer& operator= (const MemBuffer &); // { return *this; }
// disable dynamic allocation
static void *operator new (size_t); // {}
static void *operator new[] (size_t); // {}
//static void operator delete (void *) {}
//static void operator delete[] (void *) {}
DISABLE_NEW_DELETE
};
#endif /* already included */
+6280
View File
File diff suppressed because it is too large Load Diff
+30 -19
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -66,14 +66,13 @@ void printClearLine(FILE *f)
static void pr_print(bool c, const char *msg)
{
if (c && !opt->to_stdout)
con_fprintf(stderr,msg);
con_fprintf(stderr, "%s", msg);
else
fprintf(stderr,msg);
fprintf(stderr, "%s", msg);
}
static void pr_error(const char *iname, const char *msg, bool is_warning)
{
set_ec(EXIT_ERROR);
fflush(stdout); fflush(stderr);
char buf[1024];
buf[0] = 0;
@@ -89,7 +88,7 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
// This hack is needed, otherwise error messages may get lost
// when the cursor is not yet at the bottom of the screen.
// At least I can use some colors then...
bool c = isatty(STDERR_FILENO) ? 1 : 0;
bool c = acc_isatty(STDERR_FILENO) ? 1 : 0;
int fg = con_fg(stderr,FG_BRTRED);
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"%s: ", progname);
@@ -104,23 +103,35 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
fg = con_fg(stderr,fg);
UNUSED(is_warning);
UNUSED(fg);
}
void printErr(const char *iname, const Throwable *e)
{
char buf[1024];
size_t l;
upx_snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e)));
if (e->getMsg())
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),": %s", e->getMsg());
if (e->getErrno())
upx_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),": %s", strerror(e->getErrno()));
upx_snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e).name()));
l = strlen(buf);
if (l < sizeof(buf) && e->getMsg())
upx_snprintf(buf+l, sizeof(buf)-l, ": %s", e->getMsg());
l = strlen(buf);
if (l < sizeof(buf) && e->getErrno()) {
upx_snprintf(buf+l, sizeof(buf)-l, ": %s", strerror(e->getErrno()));
#if 1
// some compilers (e.g. Borland C++) put a trailing '\n'
// into strerror() result
l = strlen(buf);
while (l-- > 0 && (buf[l] == '\n' || buf[l] == ' '))
buf[l] = 0;
#endif
}
pr_error(iname,buf,e->isWarning());
}
void printErr(const char *iname, const char *format, ...)
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
{
va_list args;
char buf[1024];
@@ -133,7 +144,7 @@ void printErr(const char *iname, const char *format, ...)
}
void printWarn(const char *iname, const char *format, ...)
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
{
va_list args;
char buf[1024];
@@ -146,7 +157,7 @@ void printWarn(const char *iname, const char *format, ...)
}
void printUnhandledException(const char *iname, const exception *e)
void printUnhandledException(const char *iname, const std::exception *e)
{
if (e)
printErr(iname,"unhandled exception: %s\n", prettyName(e->what()));
@@ -190,7 +201,7 @@ void infoHeader()
info_header = 0;
}
void infoHeader(const char *format, ...)
void __acc_cdecl_va infoHeader(const char *format, ...)
{
if (opt->info_mode <= 0)
return;
@@ -204,7 +215,7 @@ void infoHeader(const char *format, ...)
}
void info(const char *format, ...)
void __acc_cdecl_va info(const char *format, ...)
{
if (opt->info_mode <= 0)
return;
@@ -219,7 +230,7 @@ void info(const char *format, ...)
}
void infoWarning(const char *format, ...)
void __acc_cdecl_va infoWarning(const char *format, ...)
{
if (opt->info_mode <= 0)
{
+40 -30
View File
@@ -21,11 +21,22 @@
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "tailor.h"
#undef PROGNAME
#if 0
#ifndef EOF
#include <stdio.h>
#include <string.h>
#endif
#define PROGNAME(x) (x)
#else
#include "conf.h"
static const char *my_progname(const char *argv0)
{
return progname ? progname : argv0;
}
#define PROGNAME(x) my_progname(x)
#endif
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
@@ -54,8 +65,6 @@
#define optind mfx_optind
#define opterr mfx_opterr
#define optopt mfx_optopt
#define my_index strchr
#define my_strlen strlen
#undef BAD_OPTION
/* For communication from `getopt' to the caller.
@@ -167,7 +176,7 @@ static int last_nonopt;
static void exchange (char **argv)
{
char *temp, **first, **last;
char *temp; char **first, **last;
/* Reverse all the elements [first_nonopt, optind) */
first = &argv[first_nonopt];
@@ -382,15 +391,10 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
int indfound = 0;
int needexact = 0;
#if defined(DOSISH)
/* allow `--option#value' because you cannout assign a '='
to an environment variable under DOS command.com */
while (*s && *s != '=' && * s != '#')
s++;
#else
while (*s && *s != '=')
s++;
#endif
/* Test all options for either exact match or abbreviated matches. */
for (p = longopts, option_index = 0; p->name;
@@ -399,7 +403,7 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
{
if (p->has_arg & 0x10)
needexact = 1;
if ((unsigned) (s - nextchar) == my_strlen (p->name))
if ((unsigned) (s - nextchar) == strlen (p->name))
{
/* Exact match found. */
pfound = p;
@@ -423,8 +427,8 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
{
if (opterr)
fprintf (stderr, "%s: unrecognized option `%s'\n",
argv[0], argv[optind]);
nextchar += my_strlen (nextchar);
PROGNAME(argv[0]), argv[optind]);
nextchar += strlen (nextchar);
optind++;
return BAD_OPTION;
}
@@ -432,8 +436,8 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
{
if (opterr)
fprintf (stderr, "%s: option `%s' is ambiguous\n",
argv[0], argv[optind]);
nextchar += my_strlen (nextchar);
PROGNAME(argv[0]), argv[optind]);
nextchar += strlen (nextchar);
optind++;
return BAD_OPTION;
}
@@ -459,14 +463,14 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
/* --option */
fprintf (stderr,
"%s: option `--%s' doesn't allow an argument\n",
argv[0], pfound->name);
PROGNAME(argv[0]), pfound->name);
else
/* +option or -option */
fprintf (stderr,
"%s: option `%c%s' doesn't allow an argument\n",
argv[0], argv[optind - 1][0], pfound->name);
PROGNAME(argv[0]), argv[optind - 1][0], pfound->name);
}
nextchar += my_strlen (nextchar);
nextchar += strlen (nextchar);
return BAD_OPTION;
}
}
@@ -482,13 +486,13 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
{
if (opterr)
fprintf (stderr, "%s: option `--%s%s' requires an argument\n",
argv[0], pfound->name,
PROGNAME(argv[0]), pfound->name,
(pfound->has_arg & 0x20) ? "=" : "");
nextchar += my_strlen (nextchar);
nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : BAD_OPTION;
}
}
nextchar += my_strlen (nextchar);
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
@@ -506,31 +510,31 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
#ifdef GETOPT_COMPAT
|| argv[optind][0] == '+'
#endif /* GETOPT_COMPAT */
|| my_index (optstring, *nextchar) == NULL)
|| strchr (optstring, *nextchar) == NULL)
{
if (opterr)
{
if (argv[optind][1] == '-')
/* --option */
fprintf (stderr, "%s: unrecognized option `--%s'\n",
argv[0], nextchar);
PROGNAME(argv[0]), nextchar);
else
/* +option or -option */
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
argv[0], argv[optind][0], nextchar);
PROGNAME(argv[0]), argv[optind][0], nextchar);
}
nextchar = empty_string;
optind++;
return BAD_OPTION;
}
ambig = ambig;
(void) &ambig; /* UNUSED */
}
/* Look at and handle the next option-character. */
{
char c = *nextchar++;
const char *temp = my_index (optstring, c);
const char *temp = strchr (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
@@ -543,12 +547,12 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
#if 0
if (c < 040 || c >= 0177)
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
argv[0], c);
PROGNAME(argv[0]), c);
else
fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
fprintf (stderr, "%s: unrecognized option `-%c'\n", PROGNAME(argv[0]), c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
fprintf (stderr, "%s: illegal option -- %c\n", PROGNAME(argv[0]), c);
#endif
}
optopt = c;
@@ -584,11 +588,11 @@ static int _getopt_internal (int argc, char **argv, const char *optstring,
{
#if 0
fprintf (stderr, "%s: option `-%c' requires an argument\n",
argv[0], c);
PROGNAME(argv[0]), c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: option requires an argument -- %c\n",
argv[0], c);
PROGNAME(argv[0]), c);
#endif
}
optopt = c;
@@ -694,3 +698,9 @@ main (argc, argv)
}
#endif /* TEST */
/*
vi:ts=4:et:nowrap
*/
+3 -3
View File
@@ -19,7 +19,7 @@
#define __MFX_GETOPT_H 1
#ifdef __cplusplus
//extern "C" {
/* extern "C" { */
#endif
/* For communication from `getopt' to the caller.
@@ -96,7 +96,7 @@ int mfx_getopt_long(int argc, char **argv, const char *shortopts,
const struct mfx_option *longopts, int *longind);
#ifdef __cplusplus
//}
/* } */
#endif
#endif /* _GETOPT_H */
#endif /* __MFX_GETOPT_H */
+154
View File
@@ -0,0 +1,154 @@
/* options.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
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_OPTIONS_H
#define __UPX_OPTIONS_H
/*************************************************************************
// globals
**************************************************************************/
// options - command
enum {
CMD_NONE,
CMD_COMPRESS, CMD_DECOMPRESS, CMD_TEST, CMD_LIST, CMD_FILEINFO,
CMD_HELP, CMD_LICENSE, CMD_VERSION
};
struct options_t {
int cmd;
// 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
// other options
int backup;
int console;
int force;
int info_mode;
bool ignorewarn;
bool no_env;
bool no_progress;
const char *output_name;
int small;
int verbose;
bool to_stdout;
// debug options
struct {
int debug_level;
const char *dump_stub_loader;
char fake_stub_version[4+1]; // for internal debugging
char fake_stub_year[4+1]; // for internal debugging
} debug;
// overlay handling
enum {
SKIP_OVERLAY = 0,
COPY_OVERLAY = 1,
STRIP_OVERLAY = 2
};
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;
// CPU
enum {
CPU_DEFAULT = 0,
CPU_8086 = 1,
CPU_286 = 2,
CPU_386 = 3,
CPU_486 = 4,
CPU_586 = 5,
CPU_686 = 6
};
int cpu;
// options for various executable formats
struct {
bool split_segments;
} atari_tos;
struct {
bool coff;
} djgpp2_coff;
struct {
bool force_stub;
bool no_reloc;
} dos_exe;
struct {
bool boot_only;
bool no_align;
bool do_8bit;
} ps1_exe;
struct {
unsigned blocksize;
bool force_execve; // force the linux/386 execve format
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!]
enum { SCRIPT_MAX = 32 };
const char *script_name;
} o_unix;
struct {
bool le;
} watcom_le;
struct {
int compress_exports;
int compress_icons;
int compress_resources;
signed char compress_rt[25]; // 25 == RT_LAST
int strip_relocs;
} win32_pe;
};
extern struct options_t *opt;
#endif /* already included */
/*
vi:ts=4:et
*/
+2042
View File
File diff suppressed because it is too large Load Diff
+251
View File
@@ -0,0 +1,251 @@
/* p_armpe.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
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
*/
#ifndef __UPX_P_ARMPE_H
#define __UPX_P_ARMPE_H
class PackArmPe_Interval;
class PackArmPe_Reloc;
class PackArmPe_Resource;
class PackArmPe_Export;
/*************************************************************************
// w32/pe
**************************************************************************/
class PackArmPe : public Packer
{
typedef Packer super;
public:
PackArmPe(InputFile *f);
~PackArmPe();
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_WINCE_ARM_PE; }
virtual const char *getName() const { return "arm/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 int buildLoader(const Filter *ft);
unsigned pe_offset;
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
};
};
#endif /* already included */
/*
vi:ts=4:et
*/
+46 -50
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -35,8 +35,6 @@
static const
#include "stub/l_com.h"
#define STACKSIZE 0x60
//#define TESTING
@@ -44,22 +42,27 @@ static const
//
**************************************************************************/
int PackCom::getCompressionMethod() const
const int *PackCom::getCompressionMethods(int method, int level) const
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_LE16;
static const int m_nrv2b[] = { M_NRV2B_LE16, -1 };
if (M_IS_NRV2B(method))
return m_nrv2b;
#if 0
// NOT IMPLEMENTED
if (M_IS_NRV2D(opt->method))
return M_NRV2D_LE16;
static const int m_nrv2d[] = { M_NRV2D_LE16, -1 };
if (M_IS_NRV2D(method))
return m_nrv2d;
#endif
return M_NRV2B_LE16;
UNUSED(level);
return m_nrv2b;
}
const int *PackCom::getFilters() const
{
static const int filters[] = { 0x06, 0x03, 0x04, 0x01, 0x05, 0x02, -1 };
static const int filters[] = {
0x06, 0x03, 0x04, 0x01, 0x05, 0x02,
-1 };
return filters;
}
@@ -72,14 +75,13 @@ bool PackCom::canPack()
{
unsigned char buf[128];
fi->readx(buf,128);
fi->readx(buf, sizeof(buf));
if (memcmp(buf,"MZ",2) == 0 || memcmp(buf,"ZM",2) == 0 // .exe
|| memcmp (buf,"\xff\xff\xff\xff",4) == 0) // .sys
return false;
if (!fn_has_ext(fi->getName(),"com"))
return false;
if (find_le32(buf,128,UPX_MAGIC_LE32) >= 0)
throwAlreadyPacked();
checkAlreadyPacked(buf, sizeof(buf));
if (file_size < 1024)
throwCantPack("file is too small");
if (file_size > 0xFF00)
@@ -94,7 +96,7 @@ bool PackCom::canPack()
void PackCom::patchLoader(OutputFile *fo,
upx_byte *loader, int lsize,
unsigned calls, unsigned overlapoh)
unsigned calls)
{
const int filter_id = ph.filter;
const int e_len = getLoaderSectionStart("COMCUTPO");
@@ -102,9 +104,12 @@ void PackCom::patchLoader(OutputFile *fo,
assert(e_len > 0 && e_len < 256);
assert(d_len > 0 && d_len < 256);
const unsigned upper_end = ph.u_len + overlapoh + d_len + 0x100;
if (upper_end + STACKSIZE > 0xfffe)
throwNotCompressible();
const unsigned upper_end = ph.u_len + ph.overlap_overhead + d_len + 0x100;
unsigned stacksize = 0x60;
if (upper_end + stacksize > 0xfffe)
stacksize = 0x56;
if (upper_end + stacksize > 0xfffe)
throwCantPack("file is too big for dos/com");
if (filter_id)
{
@@ -116,11 +121,11 @@ void PackCom::patchLoader(OutputFile *fo,
// NOTE: Depends on: decompr_start == cutpoint+1 !!!
patch_le16(loader,e_len,"JM",upper_end - 0xff - d_len - getLoaderSection("UPX1HEAD"));
loader[getLoaderSection("COMSUBSI") - 1] = (upx_byte) -e_len;
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);
patch_le16(loader,e_len,"SP",upper_end + stacksize);
// write loader + compressed file
fo->write(loader,e_len); // entry
@@ -136,19 +141,23 @@ void PackCom::patchLoader(OutputFile *fo,
int PackCom::buildLoader(const Filter *ft)
{
const int filter_id = ft->id;
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
addLoader("COMMAIN1""COMSUBSI",
filter_id ? "COMCALLT" : "",
"COMMAIN2""UPX1HEAD""COMCUTPO""NRV2B160",
filter_id ? "NRVDDONE" : "NRVDRETU",
addLoader("COMMAIN1,COMSUBSI",
ph.first_offset_found == 1 ? "COMSBBBP" : "",
"COMPSHDI",
ft->id ? "COMCALLT" : "",
"COMMAIN2,UPX1HEAD,COMCUTPO,NRV2B160",
ft->id ? "NRVDDONE" : "NRVDRETU",
"NRVDECO1",
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
"NRVDECO2""NRV2B169",
"NRVDECO2,NRV2B169",
NULL
);
if (filter_id)
addFilter16(filter_id);
if (ft->id)
{
assert(ft->calls > 0);
addFilter16(ft->id);
}
return getLoaderSize();
}
@@ -161,7 +170,7 @@ void PackCom::addFilter16(int filter_id)
if (filter_id % 3 == 0)
addLoader("CALLTR16",
filter_id < 4 ? "CT16SUB0" : "",
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286""CT16SUB0"),
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286,CT16SUB0"),
"CALLTRI2",
getFormat() == UPX_F_DOS_COM ? "CORETURN" : "",
NULL
@@ -171,7 +180,7 @@ void PackCom::addFilter16(int filter_id)
"CALLTRI5",
getFormat() == UPX_F_DOS_COM ? "CT16JEND" : "CT16JUL2",
filter_id < 4 ? "CT16SUB1" : "",
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287""CT16SUB1"),
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287,CT16SUB1"),
"CALLTRI6",
NULL
);
@@ -192,35 +201,22 @@ void PackCom::pack(OutputFile *fo)
// prepare packheader
ph.u_len = file_size;
ph.filter = 0;
// prepare filter
Filter ft(opt->level);
Filter ft(ph.level);
ft.addvalue = getCallTrickOffset();
// prepare other settings
// compress
const unsigned overlap_range = ph.u_len < 0xFE00 - ft.addvalue ? 32 : 0;
unsigned overlapoh;
int strategy = -1; // try the first working filter
if (opt->filter >= 0 && isValidFilter(opt->filter))
// try opt->filter or 0 if that fails
strategy = -2;
else if (opt->all_filters || opt->level > 9)
// choose best from all available filters
strategy = 0;
else if (opt->level == 9)
// choose best from the first 4 filters
strategy = 4;
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
compressWithFilters(&ft, overlap_range);
const int lsize = getLoaderSize();
MemBuffer loader(lsize);
memcpy(loader,getLoader(),lsize);
const unsigned calls = ft.id % 3 ? ft.lastcall - 2 * ft.calls : ft.calls;
patchLoader(fo, loader, lsize, calls, overlapoh);
patchLoader(fo, loader, lsize, calls);
// verify
verifyOverlappingDecompression(&obuf, overlapoh);
verifyOverlappingDecompression();
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
+8 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -39,10 +39,10 @@ class PackCom : public Packer
typedef Packer super;
public:
PackCom(InputFile *f) : super(f) { }
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_DOS_COM; }
virtual const char *getName() const { return "dos/com"; }
virtual int getCompressionMethod() const;
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo);
@@ -52,11 +52,11 @@ public:
virtual int canUnpack();
protected:
virtual const unsigned getCallTrickOffset() const { return 0x100; }
virtual unsigned getCallTrickOffset() const { return 0x100; }
protected:
virtual int buildLoader(const Filter *ft);
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned, unsigned);
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
virtual void addFilter16(int filter_id);
};
+153 -138
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,21 +21,21 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
#include "conf.h"
#include "file.h"
#include "filter.h"
#include "packer.h"
#include "p_djgpp2.h"
static const
#include "stub/stubify.h"
static const
#include "stub/l_djgpp2.h"
static const
#include "stub/stubify.h"
/*************************************************************************
@@ -45,33 +45,48 @@ static const
PackDjgpp2::PackDjgpp2(InputFile *f) :
super(f), coff_offset(0)
{
assert(sizeof(coff_hdr) == 0xa8);
assert(sizeof(stubify_stub) == 2048);
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);
//printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub)));
//assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
}
int PackDjgpp2::getCompressionMethod() const
const int *PackDjgpp2::getCompressionMethods(int method, int level) const
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_LE32;
if (M_IS_NRV2D(opt->method))
return M_NRV2D_LE32;
return opt->level > 1 && file_size >= 512*1024 ? M_NRV2D_LE32 : M_NRV2B_LE32;
return Packer::getDefaultCompressionMethods_le32(method, level);
}
const int *PackDjgpp2::getFilters() const
{
static const int filters[] = { 0x26, 0x24, 0x11, 0x14, 0x13, 0x16,
0x25, 0x15, 0x12, -1 };
static const int filters[] = {
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
-1 };
return filters;
}
unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf,
unsigned range,
unsigned upper_limit) const
{
unsigned o = super::findOverlapOverhead(buf, range, upper_limit);
o = (o + 0x3ff) &~ 0x1ff;
return o;
}
int PackDjgpp2::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("IDENTSTR""DJ2MAIN1",
initLoader(nrv_loader, sizeof(nrv_loader));
addLoader("IDENTSTR,DJ2MAIN1",
ft->id ? "DJCALLT1" : "",
"DJ2MAIN2",
getDecompressor(),
@@ -81,10 +96,10 @@ int PackDjgpp2::buildLoader(const Filter *ft)
if (ft->id)
{
assert(ft->calls > 0);
addLoader("DJCALLT2",NULL);
addLoader("DJCALLT2", NULL);
addFilter32(ft->id);
}
addLoader("DJRETURN+40DXXXXUPX1HEAD",NULL);
addLoader("DJRETURN,+40DXXXX,UPX1HEAD", NULL);
return getLoaderSize();
}
@@ -95,18 +110,18 @@ int PackDjgpp2::buildLoader(const Filter *ft)
void PackDjgpp2::handleStub(OutputFile *fo)
{
if (fo && !opt->djgpp2.coff)
if (fo && !opt->djgpp2_coff.coff)
{
if (coff_offset > 0)
{
// copy stub from exe
Packer::handleStub(fi,fo,coff_offset);
Packer::handleStub(fi, fo, coff_offset);
}
else
{
// "stubify" stub
info("Adding stub: %ld bytes", (long)sizeof(stubify_stub));
fo->write(stubify_stub,sizeof(stubify_stub));
fo->write(stubify_stub, sizeof(stubify_stub));
}
}
}
@@ -118,16 +133,16 @@ static bool is_dlm(InputFile *fi, long coff_offset)
long off;
try {
fi->seek(coff_offset,SEEK_SET);
fi->readx(buf,4);
fi->seek(coff_offset, SEEK_SET);
fi->readx(buf, 4);
off = get_le32(buf);
if (off < 0 || off > coff_offset + 4)
return false;
fi->seek(off,SEEK_SET);
fi->readx(buf,4);
if (memcmp(buf,"DLMF",4) == 0)
fi->seek(off, SEEK_SET);
fi->readx(buf, 4);
if (memcmp(buf, "DLMF", 4) == 0)
return true;
} catch (IOException&) {
} catch (const IOException&) {
}
return false;
}
@@ -136,65 +151,67 @@ static bool is_dlm(InputFile *fi, long coff_offset)
static void handle_allegropak(InputFile *fi, OutputFile *fo)
{
unsigned char buf[0x4000];
unsigned pfsize=0, ic;
int pfsize = 0;
try {
fi->seek(-8,SEEK_END);
fi->readx(buf,8);
if (memcmp(buf,"slh+",4) != 0)
fi->seek(-8, SEEK_END);
fi->readx(buf, 8);
if (memcmp(buf, "slh+", 4) != 0)
return;
pfsize = get_be32(buf+4);
fi->seek(-(off_t)pfsize,SEEK_END);
} catch (IOException&) {
pfsize = get_be32_signed(buf+4);
if (pfsize <= 8 || (off_t) pfsize >= (off_t) fi->st.st_size)
return;
fi->seek(-pfsize, SEEK_END);
} catch (const IOException&) {
return;
}
while (pfsize)
while (pfsize > 0)
{
ic = pfsize < sizeof(buf) ? pfsize : sizeof(buf);
fi->readx(buf,ic);
fo->write(buf,ic);
pfsize -= ic;
const int len = UPX_MIN(pfsize, (int)sizeof(buf));
fi->readx(buf, len);
fo->write(buf, len);
pfsize -= len;
}
}
bool PackDjgpp2::readFileHeader()
int PackDjgpp2::readFileHeader()
{
unsigned char hdr[0x1c];
unsigned char magic[8];
fi->seek(0,SEEK_SET);
fi->readx(hdr,sizeof(hdr));
fi->seek(0, SEEK_SET);
fi->readx(hdr, sizeof(hdr));
if (get_le16(hdr) == 0x5a4d) // MZ exe signature, stubbed?
{
coff_offset = 512 * get_le16(hdr+4);
if (get_le16(hdr+2) != 0)
coff_offset += get_le16(hdr+2) - 512;
fi->seek(512,SEEK_SET);
fi->readx(magic,8);
if (memcmp("go32stub",magic,8) != 0)
return false; // not V2 image
fi->seek(coff_offset,SEEK_SET);
if (fi->read(&coff_hdr,sizeof(coff_hdr)) != sizeof(coff_hdr))
fi->seek(512, SEEK_SET);
fi->readx(magic, 8);
if (memcmp("go32stub", magic, 8) != 0)
return 0; // not V2 image
fi->seek(coff_offset, SEEK_SET);
if (fi->read(&coff_hdr, sizeof(coff_hdr)) != sizeof(coff_hdr))
throwCantPack("skipping djgpp symlink");
}
else
{
fi->seek(coff_offset,SEEK_SET);
fi->readx(&coff_hdr,0xa8);
fi->seek(coff_offset, SEEK_SET);
fi->readx(&coff_hdr, 0xa8);
}
if (coff_hdr.f_magic != 0x014c) // I386MAGIC
return false;
return 0;
if ((coff_hdr.f_flags & 2) == 0) // F_EXEC - COFF executable
return false;
return 0;
if (coff_hdr.a_magic != 0413) // ZMAGIC - demand load format
return false;
return 0;
// FIXME: check for Linux etc.
text = coff_hdr.sh;
data = text + 1;
bss = data + 1;
return true;
return UPX_F_DJGPP2_COFF;
}
@@ -204,7 +221,7 @@ void PackDjgpp2::stripDebug()
coff_hdr.f_symptr = 0;
coff_hdr.f_nsyms = 0;
coff_hdr.f_flags = 0x10f; // 0x100: "32 bit machine: LSB first"
memset(text->misc,0,12);
memset(text->misc, 0, 12);
}
@@ -216,7 +233,7 @@ bool PackDjgpp2::canPack()
{
if (!readFileHeader())
return false;
if (is_dlm(fi,coff_offset))
if (is_dlm(fi, coff_offset))
throwCantPack("can't handle DLM");
if (opt->force == 0)
@@ -253,102 +270,73 @@ void PackDjgpp2::pack(OutputFile *fo)
// read file
const unsigned size = text->size + data->size;
const unsigned tpos = text->scnptr;
const unsigned usize = size + (tpos & 0x1ff);
const unsigned hdrsize = 20 + 28 + (40 * coff_hdr.f_nscns);
const unsigned hdrsize = 20 + 28 + sizeof(external_scnhdr_t) * coff_hdr.f_nscns;
const unsigned usize = size + hdrsize;
if (hdrsize < sizeof(coff_hdr) || hdrsize > tpos)
throwCantPack("coff header error");
ibuf.alloc(usize);
obuf.allocForCompression(usize);
fi->seek(coff_offset,SEEK_SET);
fi->readx(ibuf,hdrsize); // orig. coff header
memset(ibuf + hdrsize, 0, tpos - hdrsize);
fi->seek(coff_offset+tpos,SEEK_SET);
fi->readx(ibuf + (tpos & 0x1ff),size);
#if 0
// filter
Filter ft(opt->level);
tryFilters(&ft, ibuf, usize - data->size, text->vaddr & ~0x1ff);
// compress
ph.filter = ft.id;
ph.filter_cto = ft.cto;
ph.u_len = usize;
if (!compress(ibuf,obuf))
throwNotCompressible();
unsigned overlapoh = findOverlapOverhead(obuf,ibuf,512);
overlapoh = (overlapoh + 0x3ff) & ~0x1ff;
// verify filter
ft.verifyUnfilter();
#else
// new version using compressWithFilters()
fi->seek(coff_offset, SEEK_SET);
fi->readx(ibuf, hdrsize); // orig. coff header
fi->seek(coff_offset + tpos, SEEK_SET);
fi->readx(ibuf + hdrsize, size);
// prepare packheader
ph.u_len = usize;
ph.filter = 0;
// prepare filter
Filter ft(opt->level);
Filter ft(ph.level);
ft.buf_len = usize - data->size;
ft.addvalue = text->vaddr & ~0x1ff;
// prepare other settings
const unsigned overlap_range = 512;
unsigned overlapoh;
int strategy = -1; // try the first working filter
if (opt->filter >= 0 && isValidFilter(opt->filter))
// try opt->filter or 0 if that fails
strategy = -2;
else if (opt->all_filters)
// choose best from all available filters
strategy = 0;
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
overlapoh = (overlapoh + 0x3ff) & ~0x1ff;
#endif
ft.addvalue = text->vaddr - hdrsize;
// compress
compressWithFilters(&ft, 512);
// patch coff header #2
const unsigned lsize = getLoaderSize();
text->size = lsize; // new size of .text
data->size = ph.c_len; // new size of .data
if (bss->size < overlapoh) // give it a .bss
bss->size = overlapoh;
if (bss->size < ph.overlap_overhead) // give it a .bss
bss->size = ph.overlap_overhead;
text->scnptr = sizeof(coff_hdr);
data->scnptr = text->scnptr + text->size;
data->vaddr = bss->vaddr + ((data->scnptr + data->size) & 0x1ff) - data->size + overlapoh - 0x200;
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);
memcpy(loader, getLoader(), lsize);
// patch loader
patchPackHeader(loader,lsize);
patch_le32(loader,lsize,"ENTR",coff_hdr.a_entry);
patchPackHeader(loader, lsize);
patch_le32(loader, lsize, "ENTR", coff_hdr.a_entry);
patchFilter32(loader, lsize, &ft);
patch_le32(loader,lsize,"BSSL",overlapoh/4);
patch_le32(loader, lsize, "BSSL", ph.overlap_overhead / 4);
assert(bss->vaddr == ((size + 0x1ff) &~ 0x1ff) + (text->vaddr &~ 0x1ff));
patch_le32(loader,lsize,"OUTP",text->vaddr &~ 0x1ff);
patch_le32(loader,lsize,"INPP",data->vaddr);
patch_le32(loader, lsize, "OUTP", text->vaddr - hdrsize);
patch_le32(loader, lsize, "INPP", data->vaddr);
// we should not overwrite our decompressor during unpacking
// the original coff header (which is put just before the
// beginning of the original .text section)
assert(text->vaddr > hdrsize + lsize + sizeof(coff_hdr));
// patch coff header #3
text->vaddr = sizeof(coff_hdr);
coff_hdr.a_entry = sizeof(coff_hdr) + getLoaderSection("DJ2MAIN1");
bss->vaddr += overlapoh;
bss->size -= overlapoh;
bss->vaddr += ph.overlap_overhead;
bss->size -= ph.overlap_overhead;
// because of a feature (bug?) in stub.asm we need some padding
memcpy(obuf+data->size,"UPX",3);
data->size = ALIGN_UP(data->size,4);
memcpy(obuf+data->size, "UPX", 3);
data->size = ALIGN_UP(data->size, 4);
// write coff header, loader and compressed file
fo->write(&coff_hdr,sizeof(coff_hdr));
fo->write(loader,lsize);
fo->write(obuf,data->size);
fo->write(&coff_hdr, sizeof(coff_hdr));
fo->write(loader, lsize);
fo->write(obuf, data->size);
#if 0
printf("%-13s: coff hdr : %8ld bytes\n", getName(), (long) sizeof(coff_hdr));
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
@@ -356,11 +344,11 @@ void PackDjgpp2::pack(OutputFile *fo)
#endif
// verify
verifyOverlappingDecompression(&obuf, overlapoh);
verifyOverlappingDecompression();
// handle overlay
// FIXME: only Allegro pakfiles are supported
handle_allegropak(fi,fo);
handle_allegropak(fi, fo);
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
@@ -376,7 +364,7 @@ int PackDjgpp2::canUnpack()
{
if (!readFileHeader())
return false;
if (is_dlm(fi,coff_offset))
if (is_dlm(fi, coff_offset))
throwCantUnpack("can't handle DLM");
fi->seek(coff_offset, SEEK_SET);
return readPackHeader(1024) ? 1 : -1;
@@ -394,19 +382,30 @@ void PackDjgpp2::unpack(OutputFile *fo)
ibuf.alloc(ph.c_len);
obuf.allocForUncompression(ph.u_len);
fi->seek(coff_offset + ph.buf_offset + ph.getPackHeaderSize(),SEEK_SET);
fi->readx(ibuf,ph.c_len);
fi->seek(coff_offset + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
fi->readx(ibuf, ph.c_len);
// decompress
decompress(ibuf,obuf);
decompress(ibuf, obuf);
coff_header_t *chdr = (coff_header_t*) obuf.getVoidPtr();
text = chdr->sh;
data = text + 1;
const unsigned hdrsize = 20 + 28
+ sizeof(external_scnhdr_t) * chdr->f_nscns;
unsigned addvalue;
if (ph.version >= 14)
addvalue = text->vaddr - hdrsize;
else
addvalue = text->vaddr &~ 0x1ff; // for old versions
// unfilter
if (ph.filter)
{
memcpy(&coff_hdr,obuf,sizeof(coff_hdr));
Filter ft(ph.level);
ft.init(ph.filter, text->vaddr &~ 0x1ff);
ft.init(ph.filter, addvalue);
ft.cto = (unsigned char) ph.filter_cto;
if (ph.version < 11)
{
@@ -417,18 +416,34 @@ void PackDjgpp2::unpack(OutputFile *fo)
ft.unfilter(obuf, ph.u_len - data->size);
}
// fixup for the aligning bug in strip 2.8+
text = ((coff_header_t*) (unsigned char *) obuf)->sh;
data = text + 1;
text->scnptr &= 0x1ff;
data->scnptr = text->scnptr + text->size;
// write decompressed file
if (fo)
if (ph.version < 14)
{
fo->write(obuf,ph.u_len);
handle_allegropak(fi,fo);
// fixup for the aligning bug in strip 2.8+
text->scnptr &= 0x1ff;
data->scnptr = text->scnptr + text->size;
// write decompressed file
if (fo)
fo->write(obuf, ph.u_len);
}
else
{
// write the header
// some padding might be required between the end
// of the header and the start of the .text section
const unsigned padding = text->scnptr - hdrsize;
ibuf.clear(0, padding);
if (fo)
{
fo->write(obuf, hdrsize);
fo->write(ibuf, padding);
fo->write(obuf + hdrsize, ph.u_len - hdrsize);
}
}
if (fo)
handle_allegropak(fi, fo);
}
+17 -10
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -40,10 +40,10 @@ class PackDjgpp2 : public Packer
public:
PackDjgpp2(InputFile *f);
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 14; }
virtual int getFormat() const { return UPX_F_DJGPP2_COFF; }
virtual const char *getName() const { return "djgpp2/coff"; }
virtual int getCompressionMethod() const;
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo);
@@ -53,8 +53,13 @@ public:
virtual int canUnpack();
protected:
virtual int buildLoader(const Filter *ft);
virtual void handleStub(OutputFile *fo);
virtual int readFileHeader();
virtual unsigned findOverlapOverhead(const upx_bytep buf,
unsigned range = 0,
unsigned upper_limit = ~0u) const;
virtual int buildLoader(const Filter *ft);
long coff_offset;
@@ -66,7 +71,8 @@ protected:
LE32 scnptr;
char misc[12]; // relptr, lnnoptr, nreloc, nlnno
char __[4]; // flags
};
}
__attribute_packed;
struct coff_header_t
{
@@ -90,11 +96,12 @@ protected:
// section headers
external_scnhdr_t sh[3];
} coff_hdr;
}
__attribute_packed;
coff_header_t coff_hdr;
external_scnhdr_t *text,*data,*bss;
bool readFileHeader();
void stripDebug();
};
+323 -35
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -34,50 +34,338 @@
// Some ELF type definitinons
**************************************************************************/
namespace TT_Elf {
// The ELF file header. This appears at the start of every ELF file.
struct Elf_LE32_Ehdr
template <class Word, class Addr, class Off, class Half>
struct Ehdr
{
unsigned char e_ident[16]; /* Magic number and other info */
LE16 e_type; /* Object file type */
LE16 e_machine; /* Architecture */
LE32 e_version; /* Object file version */
LE32 e_entry; /* Entry point virtual address */
LE32 e_phoff; /* Program header table file offset */
LE32 e_shoff; /* Section header table file offset */
LE32 e_flags; /* Processor-specific flags */
LE16 e_ehsize; /* ELF header size in bytes */
LE16 e_phentsize; /* Program header table entry size */
LE16 e_phnum; /* Program header table entry count */
LE16 e_shentsize; /* Section header table entry size */
LE16 e_shnum; /* Section header table entry count */
LE16 e_shstrndx; /* Section header string table index */
};
Half e_type; /* Object file type */
Half e_machine; /* Architecture */
Word e_version; /* Object file version */
Addr e_entry; /* Entry point virtual address */
Off e_phoff; /* Program header table file offset */
Off e_shoff; /* Section header table file offset */
Word e_flags; /* Processor-specific flags */
Half e_ehsize; /* ELF header size in bytes */
Half e_phentsize; /* Program header table entry size */
Half e_phnum; /* Program header table entry count */
Half e_shentsize; /* Section header table entry size */
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,
};
}
__attribute_packed;
template <class Word, class Addr>
struct Dyn
{
Word 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 */
};
}
__attribute_packed;
} // namespace TT_Elf
namespace TT_Elf32 {
// Program segment header.
struct Elf_LE32_Phdr
template <class Word, class Addr, class Off>
struct Phdr
{
LE32 p_type; /* Segment type */
LE32 p_offset; /* Segment file offset */
LE32 p_vaddr; /* Segment virtual address */
LE32 p_paddr; /* Segment physical address */
LE32 p_filesz; /* Segment size in file */
LE32 p_memsz; /* Segment size in memory */
LE32 p_flags; /* Segment flags */
LE32 p_align; /* Segment alignment */
};
Word p_type; /* Segment type */
Off p_offset; /* Segment file offset */
Addr p_vaddr; /* Segment virtual address */
Addr p_paddr; /* Segment physical address */
Word p_filesz; /* Segment size in file */
Word p_memsz; /* Segment size in memory */
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 */
};
}
__attribute_packed;
template <class Word, class Addr, class Off>
struct Shdr
{
Word sh_name; /* Section name (string tbl index) */
Word sh_type; /* Section type */
Word sh_flags; /* Section flags */
Addr sh_addr; /* Section virtual addr at execution */
Off sh_offset; /* Section file offset */
Word sh_size; /* Section size in bytes */
Word sh_link; /* Link to another section */
Word sh_info; /* Additional section information */
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 */
};
}
__attribute_packed;
template <class TT16, class TT32, class TT64>
struct Sym
{
TT32 st_name; /* symbol name (index into string table) */
TT32 st_value; /* symbol value */
TT32 st_size; /* symbol size */
unsigned char st_info; /* symbol type and binding */
unsigned char st_other; /* symbol visibility */
TT16 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); }
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 */
};
}
__attribute_packed;
} // namespace TT_Elf32
namespace TT_Elf64 {
// Program segment header.
template <class Word, class Xword, class Addr, class Off>
struct Phdr
{
Word p_type; /* Segment type */
Word p_flags; /* Segment flags */
Off p_offset; /* Segment file offset */
Addr p_vaddr; /* Segment virtual address */
Addr p_paddr; /* Segment physical address */
Xword p_filesz; /* Segment size in file */
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 */
};
}
__attribute_packed;
template <class Word, class Xword, class Addr, class Off>
struct Shdr
{
Word sh_name; /* Section name (string tbl index) */
Word sh_type; /* Section type */
Xword sh_flags; /* Section flags */
Addr sh_addr; /* Section virtual addr at execution */
Off sh_offset; /* Section file offset */
Xword sh_size; /* Section size in bytes */
Word sh_link; /* Link to another section */
Word sh_info; /* Additional section information */
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 */
};
}
__attribute_packed;
} // namespace TT_Elf64
/*************************************************************************
// now for the actual types
**************************************************************************/
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;
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;
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)
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)
// Values for p_type
#define PT_LOAD 1 /* Loadable program segment */
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;
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;
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)
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)
// Values for p_flags
#define PF_X (1 << 0) /* Segment is executable */
#define PF_W (1 << 1) /* Segment is writable */
#define PF_R (1 << 2) /* Segment is readable */
#endif /* already included */
/*
vi:ts=4:et
*/
+179
View File
@@ -0,0 +1,179 @@
/* p_elks.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
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@cdata.tvnet.hu
*/
#include "conf.h"
#if 0
#include "file.h"
#include "filter.h"
#include "packer.h"
#include "p_vmlinz.h"
// FIXME
static const
#include "stub/l_vmlinz.h"
// from elks-0.0.83/Documentation/boot.txt
static const unsigned kernel_entry = 0x100000;
static const unsigned stack_during_uncompression = 0x90000;
static const unsigned zimage_offset = 0x1000;
/*************************************************************************
//
**************************************************************************/
const int *PackElks8086::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_8(method, level);
}
const int *PackElks8086::getFilters() const
{
return NULL;
}
/*************************************************************************
// common util routines
**************************************************************************/
int PackElks8086::decompressKernel()
{
// not used
return 0;
}
void PackElks8086::readKernel()
{
int klen = file_size - setup_size;
fi->seek(0, SEEK_SET);
setup_buf.alloc(setup_size);
fi->readx(setup_buf, setup_size);
ibuf.alloc(klen);
fi->readx(ibuf, klen);
obuf.allocForCompression(klen);
ph.u_len = klen;
ph.filter = 0;
}
/*************************************************************************
//
**************************************************************************/
int PackElks8086::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader, sizeof(nrv_loader));
// FIXME
UNUSED(ft);
return getLoaderSize();
}
void PackElks8086::pack(OutputFile *fo)
{
readKernel();
// prepare filter
Filter ft(ph.level);
ft.buf_len = ph.u_len;
ft.addvalue = kernel_entry;
// compress
compressWithFilters(&ft, overlap_range);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
memcpy(loader, getLoader(), lsize);
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);
#endif
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16) / 16;
fo->write(setup_buf, setup_buf.getSize());
fo->write(loader, lsize);
fo->write(obuf, ph.c_len);
#if 0
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
#endif
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
throwNotCompressible();
}
/*************************************************************************
// unpack
**************************************************************************/
int PackElks8086::canUnpack()
{
if (readFileHeader() != getFormat())
return false;
fi->seek(setup_size, SEEK_SET);
return readPackHeader(1024) ? 1 : -1;
}
void PackElks8086::unpack(OutputFile *)
{
// no uncompression support for this format yet
// FIXME: but we could write the uncompressed "Image" image
throwCantUnpack("build a new kernel instead :-)");
}
#endif /* if 0 */
/*
vi:ts=4:et
*/
+204 -168
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -39,6 +39,8 @@ static const
#define MAXMATCH 0x2000
#define MAXRELOCS (0x8000-MAXMATCH)
#define DI_LIMIT 0xff00 // see the assembly why
/*************************************************************************
//
@@ -47,18 +49,15 @@ static const
PackExe::PackExe(InputFile *f) :
super(f)
{
assert(sizeof(exe_header_t) == 32);
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32);
ih_exesize = ih_imagesize = ih_overlay = 0;
}
int PackExe::getCompressionMethod() const
const int *PackExe::getCompressionMethods(int method, int level) const
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_8;
if (M_IS_NRV2D(opt->method))
return M_NRV2D_8;
return opt->level > 1 && ih_imagesize >= 300000 ? M_NRV2D_8 : M_NRV2B_8;
bool small = ih_imagesize <= 256*1024;
return Packer::getDefaultCompressionMethods_8(method, level, small);
}
@@ -68,16 +67,125 @@ const int *PackExe::getFilters() const
}
int PackExe::fillExeHeader(struct exe_header_t *eh) const
{
#define oh (*eh)
// fill new exe header
int flag = 0;
if (!opt->dos_exe.no_reloc)
flag |= USEJUMP;
if (ih.relocs == 0)
flag |= NORELOC;
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;
unsigned destpara = (ph.u_len + ph.overlap_overhead - ph.c_len + 31) / 16;
oh.ss = ph.c_len/16 + destpara;
if (ih.ss*16 + ih.sp < 0x100000 && ih.ss > oh.ss && ih.sp > 0x200)
oh.ss = ih.ss;
if (oh.ss*16 + 0x50 < ih.ss*16 + ih.sp
&& oh.ss*16 + 0x200 > ih.ss*16 + ih.sp)
oh.ss += 0x20;
if (oh.ss != ih.ss)
flag |= SS;
if (oh.sp != ih.sp)
flag |= SP;
return flag;
#undef oh
}
int PackExe::buildLoader(const Filter *)
{
struct exe_header_t tmp_oh;
int flag = fillExeHeader(&tmp_oh);
// prepare loader
initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("EXEENTRY",
relocsize ? "EXERELPU" : "",
"EXEMAIN4,+G5DXXXX,UPX1HEAD,EXECUTPO",
NULL
);
if (ph.method == M_NRV2B_8)
addLoader("NRV2B16S", // decompressor
ph.u_len > DI_LIMIT ? "N2B64K01" : "",
"NRV2BEX1",
opt->cpu == opt->CPU_8086 ? "N2BX8601" : "N2B28601",
"NRV2BEX2",
opt->cpu == opt->CPU_8086 ? "N2BX8602" : "N2B28602",
"NRV2BEX3",
ph.c_len > 0xffff ? "N2B64K02" : "",
"NRV2BEX9,NRV2B16E",
NULL
);
else if (ph.method == M_NRV2D_8)
addLoader("NRV2D16S",
ph.u_len > DI_LIMIT ? "N2D64K01" : "",
"NRV2DEX1",
opt->cpu == opt->CPU_8086 ? "N2DX8601" : "N2D28601",
"NRV2DEX2",
opt->cpu == opt->CPU_8086 ? "N2DX8602" : "N2D28602",
"NRV2DEX3",
ph.c_len > 0xffff ? "N2D64K02" : "",
"NRV2DEX9,NRV2D16E",
NULL
);
else if (ph.method == M_NRV2E_8)
addLoader("NRV2E16S",
ph.u_len > DI_LIMIT ? "N2E64K01" : "",
"NRV2EEX1",
opt->cpu == opt->CPU_8086 ? "N2EX8601" : "N2E28601",
"NRV2EEX2",
opt->cpu == opt->CPU_8086 ? "N2EX8602" : "N2E28602",
"NRV2EEX3",
ph.c_len > 0xffff ? "N2E64K02" : "",
"NRV2EEX9,NRV2E16E",
NULL
);
else
throwInternalError("unknown compression method");
addLoader("EXEMAIN5", NULL);
if (relocsize)
addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS",
"EXERELO1",
has_9a ? "EXEREL9A" : "",
"EXERELO2",
ih_exesize > 0xFE00 ? "EXEREBIG" : "",
"EXERELO3",
NULL
);
addLoader("EXEMAIN8",
(flag & SS) ? "EXESTACK" : "",
(flag & SP) ? "EXESTASP" : "",
(flag & USEJUMP) ? "EXEJUMPF" : "",
NULL
);
if (!(flag & USEJUMP))
addLoader(ih.cs ? "EXERCSPO" : "",
"EXERETIP",
NULL
);
return getLoaderSize();
}
/*************************************************************************
//
**************************************************************************/
bool PackExe::readFileHeader()
int PackExe::readFileHeader()
{
ih_exesize = ih_imagesize = ih_overlay = 0;
fi->readx(&ih,sizeof(ih));
if (ih.ident != 'M' + 'Z'*256 && ih.ident != 'Z' + 'M'*256)
return false;
return 0;
ih_exesize = ih.m512 + ih.p512*512 - (ih.m512 ? 512 : 0);
ih_imagesize = ih_exesize - ih.headsize16*16;
ih_overlay = file_size - ih_exesize;
@@ -88,7 +196,7 @@ bool PackExe::readFileHeader()
#if 0
printf("dos/exe header: %d %d %d\n", ih_exesize, ih_imagesize, ih_overlay);
#endif
return true;
return UPX_F_DOS_EXE;
}
@@ -105,7 +213,7 @@ bool PackExe::canPack()
fi->readx(&offs,sizeof (offs));
if (ih.relocoffs >= 0x40 && offs)
{
if (opt->dos.force_stub)
if (opt->dos_exe.force_stub)
opt->overlay = opt->COPY_OVERLAY;
else
throwCantPack("can't pack new-exe");
@@ -123,7 +231,7 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
const upx_byte *relocs, const unsigned nrelocs,
upx_byte *crel, bool *has_9a)
{
upx_byte *crel_save = crel;
upx_byte * const crel_save = crel;
unsigned i;
unsigned seg_high = 0;
#if 0
@@ -185,7 +293,9 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
{
addr = get_le32(relocs+4*i);
//printf ("%x\n",es*16+di);
if (addr - es*16 > 0xfffe)
if ((addr - es*16 > 0xfffe)
|| (i == nrelocs - 1 && addr - es * 16 > 0xff00)
)
{
// segment change
t = 1+(0xffff-di)/254;
@@ -230,7 +340,7 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
set_le16 (crel_save+2,seg_high);
//OutputFile::dump("x.rel", crel_save, crel - crel_save);
return crel - crel_save;
return (unsigned) (crel - crel_save);
}
@@ -241,35 +351,25 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
void PackExe::pack(OutputFile *fo)
{
unsigned ic;
unsigned char flag = 0;
unsigned char extra_info[32];
unsigned eisize = 0;
//
const unsigned exesize = ih_exesize;
const unsigned imagesize = ih_imagesize;
const unsigned overlay = ih_overlay;
if (ih.relocs > MAXRELOCS)
throwCantPack("too many relocations");
checkOverlay(overlay);
checkOverlay(ih_overlay);
// alloc buffers
unsigned relocsize = RSFCRI + 4*ih.relocs;
ibuf.alloc(imagesize+16+relocsize+2);
obuf.allocForCompression(imagesize+16+relocsize+2);
relocsize = RSFCRI + 4*ih.relocs;
ibuf.alloc(ih_imagesize+16+relocsize+2);
obuf.allocForCompression(ih_imagesize+16+relocsize+2);
// read image
fi->seek(ih.headsize16*16,SEEK_SET);
fi->readx(ibuf,imagesize);
fi->readx(ibuf,ih_imagesize);
if (find_le32(ibuf, UPX_MIN(imagesize, 127u), UPX_MAGIC_LE32) >= 0)
throwAlreadyPacked();
checkAlreadyPacked(ibuf, UPX_MIN(ih_imagesize, 127u));
// relocations
has_9a = false;
upx_byte *w = ibuf + imagesize;
upx_byte *w = ibuf + ih_imagesize;
if (ih.relocs)
{
upx_byte *wr = w + RSFCRI;
@@ -283,7 +383,7 @@ void PackExe::pack(OutputFile *fo)
set_le32(wr+4*ic, (jc>>16)*16+(jc&0xffff));
}
qsort(wr,ih.relocs,4,le32_compare);
relocsize = optimize_relocs(ibuf, imagesize, wr, ih.relocs, w, &has_9a);
relocsize = optimize_relocs(ibuf, ih_imagesize, wr, ih.relocs, w, &has_9a);
set_le16(w+relocsize, relocsize+2);
relocsize += 2;
if (relocsize > MAXRELOCS)
@@ -298,121 +398,38 @@ void PackExe::pack(OutputFile *fo)
}
else
{
flag |= NORELOC;
relocsize = 0;
}
ph.u_len = imagesize + relocsize;
if (!compress(ibuf,obuf,0,MAXMATCH))
throwNotCompressible();
const unsigned overlapoh = findOverlapOverhead(obuf,32);
// prepare packheader
ph.u_len = ih_imagesize + relocsize;
// prepare filter
Filter ft(ph.level);
// compress
compressWithFilters(&ft, 32, 0, NULL, 0, MAXMATCH);
if (ph.max_run_found + ph.max_match_found > 0x8000)
throwCantPack("decompressor limit exceeded, send a bugreport");
#ifdef TESTING
if (opt->debug)
if (opt->debug.debug_level)
{
printf("image+relocs %d -> %d\n",imagesize+relocsize,ph.c_len);
printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len);
printf("offsets: %d - %d\nmatches: %d - %d\nruns: %d - %d\n",
0/*ph.min_offset_found*/,ph.max_offset_found,
0/*ph.min_match_found*/,ph.max_match_found,
0/*ph.min_run_found*/,ph.max_run_found);
}
#endif
const unsigned packedsize = ph.c_len;
if (!opt->dos.no_reloc)
flag |= USEJUMP;
int flag = fillExeHeader(&oh);
// fill new exe header
memset(&oh,0,sizeof(oh));
oh.ident = 'M' + 'Z' * 256;
unsigned destpara = (ph.u_len+overlapoh-packedsize+31)/16;
oh.ss = packedsize/16 + destpara;
if (ih.ss*16 + ih.sp < 0x100000 && ih.ss > oh.ss && ih.sp > 0x200)
oh.ss = ih.ss;
oh.sp = ih.sp > 0x200 ? ih.sp : 0x200;
if (oh.ss*16u + 0x50 < ih.ss*16u + ih.sp
&& oh.ss*16u + 0x200 > ih.ss*16u + ih.sp)
oh.ss += 0x20;
destpara = oh.ss - packedsize/16;
if (oh.ss != ih.ss)
{
set_le16(extra_info+eisize,ih.ss);
eisize += 2;
flag |= SS;
}
if (oh.sp != ih.sp)
{
set_le16(extra_info+eisize,ih.sp);
eisize += 2;
flag |= SP;
}
#define DI_LIMIT 0xff00 // see the assembly why
// prepare loader
initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("EXEENTRY",
relocsize ? "EXERELPU" : "",
"EXEMAIN4""+G5DXXXX""UPX1HEAD""EXECUTPO",
NULL
);
if (ph.method == M_NRV2B_8)
addLoader("NRV2B16S", // decompressor
ph.u_len > DI_LIMIT ? "NDIGT64K" : "",
"NRV2BEX1",
opt->cpu == opt->CPU_8086 ? "N2BX8601" : "N2B28601",
"NRV2BEX2",
opt->cpu == opt->CPU_8086 ? "N2BX8602" : "N2B28602",
"NRV2BEX3",
packedsize > 0xffff ? "NSIGT64K" : "",
"NRV2BEX9""NRV2B16E",
NULL
);
else if (ph.method == M_NRV2D_8)
addLoader("NRV2D16S",
ph.u_len > DI_LIMIT ? "NDIGT64D" : "",
"NRV2DEX1",
opt->cpu == opt->CPU_8086 ? "N2DX8601" : "N2D28601",
"NRV2DEX2",
opt->cpu == opt->CPU_8086 ? "N2DX8602" : "N2D28602",
"NRV2DEX3",
packedsize > 0xffff ? "NSIGT64D" : "",
"NRV2DEX9""NRV2D16E",
NULL
);
else
throwInternalError("unknown compression method");
addLoader("EXEMAIN5", NULL);
if (relocsize)
addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS",
"EXERELO1",
has_9a ? "EXEREL9A" : "",
"EXERELO2",
exesize > 0xFE00 ? "EXEREBIG" : "",
"EXERELO3",
NULL
);
addLoader("EXEMAIN8",
(flag & SS) ? "EXESTACK" : "",
(flag & SP) ? "EXESTASP" : "",
(flag & USEJUMP) ? "EXEJUMPF" : "",
NULL
);
if (!(flag & USEJUMP))
addLoader(ih.cs ? "EXERCSPO" : "",
"EXERETIP",
NULL
);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
memcpy(loader,getLoader(),lsize);
//OutputFile::dump("xxloader.dat", loader, lsize);
// patch loader
const unsigned packedsize = ph.c_len;
const unsigned e_len = getLoaderSectionStart("EXECUTPO");
const unsigned d_len = lsize - e_len;
assert((e_len&15) == 0);
@@ -420,17 +437,29 @@ void PackExe::pack(OutputFile *fo)
const unsigned copysize = (1+packedsize+d_len) & ~1;
const unsigned firstcopy = copysize%0x10000 ? copysize%0x10000 : 0x10000;
oh.headsize16 = 2;
oh.ip = 0;
ic = ih.min*16+imagesize;
// set oh.min & oh.max
ic = ih.min*16 + ih_imagesize;
if (ic < oh.ss*16u + oh.sp)
ic = oh.ss*16u + oh.sp;
oh.min = (ic - (packedsize + lsize)) / 16;
ic = ((unsigned) oh.min) + (ih.max - ih.min);
ic = oh.min + (ih.max - ih.min);
oh.max = ic < 0xffff && ih.max != 0xffff ? ic : 0xffff;
// set extra info
unsigned char extra_info[9];
unsigned eisize = 0;
if (oh.ss != ih.ss)
{
set_le16(extra_info+eisize,ih.ss);
eisize += 2;
assert((flag & SS) != 0); // set in fillExeHeader()
}
if (oh.sp != ih.sp)
{
set_le16(extra_info+eisize,ih.sp);
eisize += 2;
assert((flag & SP) != 0); // set in fillExeHeader()
}
if (ih.min != oh.min)
{
set_le16(extra_info+eisize,ih.min);
@@ -443,7 +472,9 @@ void PackExe::pack(OutputFile *fo)
eisize += 2;
flag |= MAXMEM;
}
extra_info[eisize++] = (unsigned char) flag;
// patch loader
if (flag & USEJUMP)
{
// I use a relocation entry to set the original cs
@@ -461,7 +492,10 @@ void PackExe::pack(OutputFile *fo)
oh.relocs = 0;
oh.firstreloc = ih.cs*0x10000 + ih.ip;
}
oh.relocoffs = offsetof(exe_header_t, firstreloc);
// 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);
@@ -475,6 +509,7 @@ void PackExe::pack(OutputFile *fo)
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);
@@ -484,16 +519,15 @@ void PackExe::pack(OutputFile *fo)
//if (ih.relocoffs >= 0x40 && memcmp(&ih.relocoffs,">TIPPACH",8))
// throwCantPack("FIXME");
extra_info[eisize++] = flag;
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,overlapoh,ph.u_len,destpara,copysize,imagesize);
//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);
// write header + write loader + compressed file
#ifdef TESTING
if (opt->debug)
if (opt->debug.debug_level)
printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len);
#endif
fo->write(&oh,sizeof(oh));
@@ -511,10 +545,10 @@ void PackExe::pack(OutputFile *fo)
#endif
// verify
verifyOverlappingDecompression(&obuf, overlapoh);
verifyOverlappingDecompression();
// copy the overlay
copyOverlay(fo, overlay, &obuf);
copyOverlay(fo, ih_overlay, &obuf);
//fprintf (stderr,"%x %x\n",relocsize,ph.u_len);
// finally check the compression ratio
@@ -548,23 +582,22 @@ void PackExe::unpack(OutputFile *fo)
obuf.allocForUncompression(ph.u_len);
// read the file
unsigned imagesize = ih_imagesize;
const unsigned overlay = ih_overlay;
fi->seek(ih.headsize16*16,SEEK_SET);
fi->readx(ibuf,imagesize);
fi->readx(ibuf,ih_imagesize);
// get compressed data offset
unsigned e_len = ph.buf_offset + ph.getPackHeaderSize();
if (imagesize <= e_len + ph.c_len)
if (ih_imagesize <= e_len + ph.c_len)
throwCantUnpack("file damaged");
checkOverlay(overlay);
checkOverlay(ih_overlay);
// decompress
decompress(ibuf+e_len,obuf);
const unsigned char flag = ibuf[imagesize-1];
unsigned imagesize = ih_imagesize;
imagesize--;
const unsigned char flag = ibuf[imagesize];
unsigned relocn = 0;
upx_byte *relocs = obuf + ph.u_len;
@@ -574,12 +607,11 @@ void PackExe::unpack(OutputFile *fo)
{
relocs -= get_le16(obuf+ph.u_len-2);
ph.u_len -= 2;
upx_byte *p;
wrkmem.alloc(4*MAXRELOCS);
unsigned es = 0,ones = get_le16(relocs);
unsigned seghi = get_le16(relocs+2);
p = relocs + 4;
unsigned es = 0, ones = get_le16(relocs);
const unsigned seghi = get_le16(relocs+2);
const upx_byte *p = relocs + 4;
while (ones)
{
@@ -597,10 +629,10 @@ void PackExe::unpack(OutputFile *fo)
dorel = true;
if (*p == 0)
{
upx_byte *q;
const upx_byte *q;
for (q = obuf+es*16+di; !(*q == 0x9a && get_le16(q+3) <= seghi); q++)
;
di = q - (obuf+es*16) + 3;
di = ptr_diff(q, obuf+es*16) + 3;
}
else if (*p == 1)
{
@@ -614,35 +646,38 @@ void PackExe::unpack(OutputFile *fo)
}
}
}
// fill new exe header
memset(&oh,0,sizeof(oh));
oh.ident = 'M' + 'Z'*256;
oh.relocs = relocn;
while (relocn&3)
set_le32(wrkmem+4*relocn++,0);
if (relocn)
{
oh.relocs = relocn;
while (relocn & 3)
set_le32(wrkmem+4*relocn++,0);
}
unsigned outputlen = sizeof(oh)+relocn*4+relocs-obuf;
unsigned outputlen = ptr_diff(relocs, obuf) + sizeof(oh) + relocn*4;
oh.m512 = outputlen & 511;
oh.p512 = (outputlen + 511) >> 9;
oh.headsize16 = 2+relocn/4;
imagesize--;
oh.max = ih.max;
oh.min = ih.min;
oh.sp = ih.sp;
oh.ss = ih.ss;
if (flag & MAXMEM)
imagesize -= 2, oh.max = get_le16(ibuf+imagesize);
{ imagesize -= 2; oh.max = get_le16(ibuf+imagesize); }
if (flag & MINMEM)
imagesize -= 2, oh.min = get_le16(ibuf+imagesize);
{ imagesize -= 2; oh.min = get_le16(ibuf+imagesize); }
if (flag & SP)
imagesize -= 2, oh.sp = get_le16(ibuf+imagesize);
{ imagesize -= 2; oh.sp = get_le16(ibuf+imagesize); }
if (flag & SS)
imagesize -= 2, oh.ss = get_le16(ibuf+imagesize);
{ imagesize -= 2; oh.ss = get_le16(ibuf+imagesize); }
unsigned ip = (flag & USEJUMP) ? get_le32(ibuf+imagesize-4) : ih.firstreloc;
unsigned ip = (flag & USEJUMP) ? get_le32(ibuf+imagesize-4) : (unsigned) ih.firstreloc;
oh.ip = ip & 0xffff;
oh.cs = ip >> 16;
@@ -653,11 +688,12 @@ void PackExe::unpack(OutputFile *fo)
// write header + relocations + uncompressed file
fo->write(&oh,sizeof(oh));
fo->write(wrkmem,relocn*4);
fo->write(obuf,relocs-obuf);
if (relocn)
fo->write(wrkmem,relocn*4);
fo->write(obuf, ptr_diff(relocs, obuf));
// copy the overlay
copyOverlay(fo, overlay, &obuf);
copyOverlay(fo, ih_overlay, &obuf);
}
+17 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -39,10 +39,10 @@ class PackExe : public Packer
typedef Packer super;
public:
PackExe(InputFile *f);
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_DOS_EXE; }
virtual const char *getName() const { return "dos/exe"; }
virtual int getCompressionMethod() const;
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo);
@@ -63,7 +63,12 @@ public:
}
protected:
virtual bool readFileHeader(void);
struct exe_header_t;
virtual int readFileHeader(void);
virtual int fillExeHeader(struct exe_header_t *) const;
virtual int buildLoader(const Filter *ft);
struct exe_header_t
{
@@ -82,11 +87,15 @@ protected:
LE16 relocoffs;
char __[2]; // overlnum
LE32 firstreloc;
} ih, oh;
}
__attribute_packed;
exe_header_t ih, oh;
unsigned ih_exesize;
unsigned ih_imagesize;
unsigned ih_overlay;
unsigned relocsize;
bool has_9a;
+1616 -339
View File
File diff suppressed because it is too large Load Diff
+278 -27
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 2000 John F. Reiser
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
@@ -22,11 +22,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
John F. Reiser
jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
*/
@@ -34,6 +31,256 @@
#define __UPX_P_LX_ELF_H
class PackLinuxElf : public PackUnix
{
typedef PackUnix super;
public:
PackLinuxElf(InputFile *f);
virtual ~PackLinuxElf();
/*virtual int buildLoader(const Filter *);*/
virtual bool canUnpackVersion(int version) const { return (version >= 11); }
protected:
virtual const int *getCompressionMethods(int method, int level) const;
// All other virtual functions in this class must be pure virtual
// because they depend on Elf32 or Elf64 data structures, which differ.
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 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 unpack(OutputFile *fo) = 0;
protected:
unsigned sz_phdrs; // sizeof Phdr[]
unsigned sz_elf_hdrs; // all Elf headers
};
class PackLinuxElf32 : public PackLinuxElf
{
typedef PackLinuxElf super;
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 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 unpack(OutputFile *fo);
virtual void generateElfHdr(
OutputFile *,
void const *proto,
unsigned const brka
);
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);
protected:
Elf32_Ehdr ehdri; // from input file
Elf32_Phdr *phdri; // for input file
struct cprElfHdr1 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[1];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr2 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[2];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr3 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[3];
l_info linfo;
}
__attribute_packed;
cprElfHdr3 elfout;
};
class PackLinuxElf64 : public PackLinuxElf
{
typedef PackLinuxElf super;
public:
PackLinuxElf64(InputFile *f);
virtual ~PackLinuxElf64();
/*virtual int 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 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 unpack(OutputFile *fo);
virtual void generateElfHdr(
OutputFile *,
void const *proto,
unsigned const brka
);
virtual off_t getbrk(const Elf64_Phdr *phdr, int e_phnum) const;
virtual void patchLoader();
virtual void updateLoader(OutputFile *fo);
virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k,
unsigned const e_phnum);
protected:
Elf64_Ehdr ehdri; // from input file
Elf64_Phdr *phdri; // for input file
struct cprElfHdr1 {
Elf64_Ehdr ehdr;
Elf64_Phdr phdr[1];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr2 {
Elf64_Ehdr ehdr;
Elf64_Phdr phdr[2];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr3 {
Elf64_Ehdr ehdr;
Elf64_Phdr phdr[3];
l_info linfo;
}
__attribute_packed;
cprElfHdr3 elfout;
};
class PackLinuxElf32Be : public PackLinuxElf32
{
typedef PackLinuxElf32 super;
protected:
PackLinuxElf32Be(InputFile *f) : super(f) { }
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
};
class PackLinuxElf64Le : public PackLinuxElf64
{
typedef PackLinuxElf64 super;
protected:
PackLinuxElf64Le(InputFile *f) : super(f) { }
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
};
/*************************************************************************
// linux/elf64amd
**************************************************************************/
class PackLinuxElf64amd : public PackLinuxElf64Le
{
typedef PackLinuxElf64Le super;
public:
PackLinuxElf64amd(InputFile *f);
virtual ~PackLinuxElf64amd();
virtual int getFormat() const { return UPX_F_LINUX_ELF64_AMD; }
virtual const char *getName() const { return "linux/ElfAMD"; }
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
);
};
/*************************************************************************
// linux/elf32ppc
**************************************************************************/
class PackLinuxElf32ppc : public PackLinuxElf32Be
{
typedef PackLinuxElf32Be super;
public:
PackLinuxElf32ppc(InputFile *f);
virtual ~PackLinuxElf32ppc();
virtual int getFormat() const { return UPX_F_LINUX_ELFPPC32; }
virtual const char *getName() const { return "linux/ElfPPC"; }
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
);
};
/*************************************************************************
// linux/elf386
**************************************************************************/
@@ -44,12 +291,12 @@ class PackLinuxI386elf : public PackLinuxI386
public:
PackLinuxI386elf(InputFile *f);
virtual ~PackLinuxI386elf();
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_LINUX_ELF_i386; }
virtual const char *getName() const { return "linux/elf386"; }
virtual const int *getFilters() const { return NULL; }
virtual const int *getFilters() const;
virtual int buildLoader(const Filter *);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
virtual bool canPack();
@@ -57,25 +304,29 @@ public:
{ return (version >= 11); }
protected:
struct Extent {
off_t offset;
off_t size;
};
virtual void packExtent(Extent const &x, OutputFile *fo,
unsigned &total_in, unsigned &total_out);
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
unsigned &total_in, unsigned &total_out,
unsigned &c_adler, unsigned &u_adler);
protected:
virtual const upx_byte *getLoader() const;
virtual int getLoaderSize() 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();
virtual void updateLoader(OutputFile *);
Elf_LE32_Ehdr ehdri; // from input file
Elf_LE32_Phdr *phdri; // for input file
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);
};
+558
View File
@@ -0,0 +1,558 @@
/* p_lx_exc.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) 2001-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 "filter.h"
#include "linker.h"
#include "packer.h"
#include "p_elf.h"
#include "p_unix.h"
#include "p_lx_exc.h"
#define PT_LOAD Elf32_Phdr::PT_LOAD
#define PT_DYNAMIC Elf32_Phdr::PT_DYNAMIC
#if 0 // UNUSED
#define DT_NULL Elf32_Dyn::DT_NULL
#define DT_NEEDED Elf32_Dyn::DT_NEEDED
#define DT_STRTAB Elf32_Dyn::DT_STRTAB
#define DT_STRSZ Elf32_Dyn::DT_STRSZ
#endif
/*************************************************************************
// linux/386 (generic "execve" format)
**************************************************************************/
static const
#include "stub/l_lx_exec86.h"
static const
#include "stub/fold_exec86.h"
const int *PackLinuxI386::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_le32(method, level);
}
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
0x83, 0x86, 0x80, 0x84, 0x87, 0x81, 0x82, 0x85,
0x24, 0x16, 0x13, 0x14, 0x11, 0x25, 0x15, 0x12,
#endif
-1 };
return filters;
}
void
PackLinuxI386::generateElfHdr(
OutputFile *fo,
void const *proto,
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
assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
assert(h2->ehdr.e_shoff == 0);
assert(h2->ehdr.e_ehsize == sizeof(Elf32_Ehdr));
assert(h2->ehdr.e_phentsize == sizeof(Elf32_Phdr));
assert(h2->ehdr.e_shnum == 0);
#if 0 //{
unsigned identsize;
char const *const ident = getIdentstr(&identsize);
#endif //}
h2->phdr[0].p_filesz = sizeof(*h2); // + identsize;
h2->phdr[0].p_memsz = h2->phdr[0].p_filesz;
// 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;
}
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) {
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));
fo->write(h3, sizeof(*h3));
}
else {
assert(false); // unknown ph.format, PackUnix::generateElfHdr
}
}
void
PackLinuxI386::pack1(OutputFile *fo, Filter &)
{
// create a pseudo-unique program id for our paranoid stub
progid = getRandomId();
generateElfHdr(fo, linux_i386exec_fold, 0);
}
void
PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
{
overlay_offset = sizeof(elfout.ehdr) +
(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);
super::pack4(fo, ft); // write PackHeader and overlay_offset
#if 0 // {
// /usr/bin/strip from RedHat 8.0 (binutils-2.13.90.0.2-2)
// generates a 92-byte [only] output, because the "linking view"
// is empty. This code supplies a "linking view".
// However, 'strip' then generates _plausible_ junk that gets
// "Illegal instruction" because 'strip' changes p_hdr[1].p_align,
// .p_offset, and .p_vaddr incorrectly. So the "cure" is worse than
// the disease. It is obvious that a 92-byte file is bad,
// but it is not obvious that the changed .p_align is bad.
// Also, having a totally empty "linking view" is easier for 'strip'
// to fix: just detect that, and do nothing.
// So, we don't use this code for now [2003-01-11].
// Supply a "linking view" that covers everything,
// so that 'strip' does not omit everything.
Elf32_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);
// An empty Elf32_Shdr for space as a null index.
memset(&shdr, 0, sizeof(shdr));
set_native32(&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);
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));
fo->write(&shdr, sizeof(shdr));
fo->write(shstrtab, sizeof(shstrtab));
#endif // }
#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
// rewrite Elf header
fo->seek(0, SEEK_SET);
fo->rewrite(&elfout, overlay_offset);
}
static unsigned
umax(unsigned a, unsigned b)
{
if (a <= b) {
return b;
}
return a;
}
int
PackLinuxI386::buildLinuxLoader(
upx_byte const *const proto,
unsigned const szproto,
upx_byte const *const fold,
unsigned const szfold,
Filter const *ft
)
{
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;
}
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;
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
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);
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
if (0x80==(ft->id & 0xF0)) {
addLoader("LEXEC110", NULL);
if (n_mru) {
addLoader("LEXEC100", NULL);
}
// bug in APP: jmp and label must be in same .asx/.asy
addLoader("LEXEC016", NULL);
}
}
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
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
}
// PackHeader and overlay_offset at the end of the output file,
// after the compressed data.
return getLoaderSize();
}
int
PackLinuxI386::buildLoader(Filter const *ft)
{
unsigned const sz_fold = sizeof(linux_i386exec_fold);
MemBuffer buf(sz_fold);
memcpy(buf, linux_i386exec_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);
// 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),
buf, sz_fold, ft );
}
int PackLinuxI386::getLoaderPrefixSize() const
{
return 116;
}
/*************************************************************************
// some ELF utitlity functions
**************************************************************************/
// basic check of an Linux ELF Ehdr
int PackLinuxI386::checkEhdr(const Elf32_Ehdr *ehdr) const
{
const unsigned char * const buf = ehdr->e_ident;
if (memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB
return -1;
// now check the ELF header
if (!memcmp(buf+8, "FreeBSD", 7)) // branded
return 1;
if (ehdr->e_type != Elf32_Ehdr::ET_EXEC
&& ehdr->e_type != Elf32_Ehdr::ET_DYN ) // executable
return 2;
if (ehdr->e_machine != Elf32_Ehdr::EM_386) // Intel 80386
return 3;
if (ehdr->e_version != Elf32_Ehdr::EV_CURRENT) // version
return 4;
if (ehdr->e_phnum < 1)
return 5;
if (ehdr->e_phentsize != sizeof(Elf32_Phdr))
return 6;
// check for Linux kernels
if (ehdr->e_entry == 0xC0100000) // uncompressed vmlinux
return 1000;
if (ehdr->e_entry == 0x00001000) // compressed vmlinux
return 1001;
if (ehdr->e_entry == 0x00100000) // compressed bvmlinux
return 1002;
// FIXME: add more checks for kernels
// FIXME: add special checks for other ELF i386 formats, like
// NetBSD, OpenBSD, Solaris, ....
// success
return 0;
}
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;
}
/*************************************************************************
//
**************************************************************************/
bool PackLinuxI386::canPack()
{
if (exetype != 0)
return super::canPack();
Elf32_Ehdr ehdr;
unsigned char *buf = ehdr.e_ident;
fi->readx(&ehdr, sizeof(ehdr));
fi->seek(0, SEEK_SET);
exetype = 0;
const unsigned l = get_le32(buf);
int elf = checkEhdr(&ehdr);
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)
exetype = 1;
}
else if (l == 0x00640107 || l == 0x00640108 || l == 0x0064010b || l == 0x006400cc)
{
// OMAGIC / NMAGIC / ZMAGIC / QMAGIC
exetype = 2;
// 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
return super::canPack();
}
void PackLinuxI386::patchLoader() { }
void PackLinuxI386::patchLoaderChecksum()
{
unsigned char *const ptr = const_cast<unsigned char *>(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
lp->l_checksum = 0;
lp->l_magic = UPX_ELF_MAGIC;
lp->l_lsize = (unsigned short) lsize;
lp->l_version = (unsigned char) ph.version;
lp->l_format = (unsigned char) ph.format;
// INFO: lp->l_checksum is currently unused
lp->l_checksum = upx_adler32(ptr, lsize);
}
void PackLinuxI386::updateLoader(OutputFile *fo)
{
elfout.ehdr.e_entry = fo->getBytesWritten() + elfout.phdr[0].p_vaddr;
}
/*
vi:ts=4:et
*/
+119
View File
@@ -0,0 +1,119 @@
/* p_lx_exc.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
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@cdata.tvnet.hu
*/
#ifndef __UPX_P_LX_EXC_H
#define __UPX_P_LX_EXC_H
/*************************************************************************
// linux/386 (generic "execve" format)
**************************************************************************/
class PackLinuxI386 : public PackUnixLe32
{
typedef PackUnixLe32 super;
public:
PackLinuxI386(InputFile *f) : super(f) { }
virtual void generateElfHdr(
OutputFile *,
void const *proto,
unsigned const brka
);
virtual int getFormat() const { return UPX_F_LINUX_i386; }
virtual const char *getName() const { return "linux/386"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int buildLoader(const Filter *);
virtual bool canPack();
protected:
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 PackHeader
// loader util
virtual int getLoaderPrefixSize() 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
);
// patch util
virtual void patchLoader();
virtual void patchLoaderChecksum();
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;
enum {
UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
};
unsigned n_mru;
struct cprElfHdr1 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[1];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr2 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[2];
l_info linfo;
}
__attribute_packed;
struct cprElfHdr3 {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr[3];
l_info linfo;
}
__attribute_packed;
cprElfHdr3 elfout;
};
#endif /* already included */
/*
vi:ts=4:et
*/
+307
View File
@@ -0,0 +1,307 @@
/* p_lx_interp.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 "filter.h"
#include "linker.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_interp.h"
#define PT_LOAD Elf32_Phdr::PT_LOAD
#define PT_INTERP Elf32_Phdr::PT_INTERP
/*************************************************************************
//
**************************************************************************/
static const
#include "stub/l_lx_pti86.h"
static const
#include "stub/fold_pti86.h"
PackLinuxI386interp::PackLinuxI386interp(InputFile *f) :
super(f)
{
}
PackLinuxI386interp::~PackLinuxI386interp()
{
}
bool PackLinuxI386interp::canPack()
{
if (opt->o_unix.make_ptinterp) {
return true;
}
if (!opt->o_unix.use_ptinterp) {
return false;
}
return super::canPack();
}
void PackLinuxI386interp::pack1(OutputFile *fo, Filter &)
{
fi->seek(0, SEEK_SET);
fi->readx(&ehdri, sizeof(ehdri));
assert(ehdri.e_phoff == sizeof(Elf32_Ehdr)); // checked by canPack()
sz_phdrs = ehdri.e_phnum * ehdri.e_phentsize;
phdri = new Elf32_Phdr[(unsigned)ehdri.e_phnum];
fi->seek(ehdri.e_phoff, SEEK_SET);
fi->readx(phdri, sz_phdrs);
#define E Elf32_Ehdr
cprElfHdr3 h3;
memset(&h3, 0, sizeof(h3));
memcpy(h3.ehdr.e_ident, "\177ELF", 4);
h3.ehdr.e_ident[E::EI_CLASS] = E::ELFCLASS32;
h3.ehdr.e_ident[E::EI_DATA] = E::ELFDATA2LSB;
h3.ehdr.e_ident[E::EI_VERSION] = E::EV_CURRENT;
h3.ehdr.e_ident[E::EI_OSABI] = E::ELFOSABI_LINUX;
h3.ehdr.e_ident[E::EI_ABIVERSION] = E::EV_CURRENT;
h3.ehdr.e_type = E::ET_EXEC;
h3.ehdr.e_machine = E::EM_386;
h3.ehdr.e_version = 1;
h3.ehdr.e_phoff = sizeof(Elf32_Ehdr);
h3.ehdr.e_ehsize = sizeof(Elf32_Ehdr);
h3.ehdr.e_phentsize = sizeof(Elf32_Phdr);
h3.ehdr.e_phnum = 3;
h3.phdr[0].p_type = PT_LOAD;
h3.phdr[0].p_flags = Elf32_Phdr::PF_X | Elf32_Phdr::PF_R;
h3.phdr[0].p_align = 0x1000;
h3.phdr[1].p_type = PT_LOAD;
h3.phdr[1].p_flags = Elf32_Phdr::PF_W | Elf32_Phdr::PF_R;
h3.phdr[1].p_align = 1;
h3.phdr[2].p_type = PT_INTERP;
h3.phdr[2].p_offset = (char *)&h3.phdr[2].p_vaddr - (char *)&h3;
memcpy(&h3.phdr[2].p_vaddr, "/upxrun", h3.phdr[2].p_filesz = 8);
h3.phdr[2].p_align = 1;
if (opt->o_unix.make_ptinterp) { // unusual "once per release"
elfout = h3;
elfout.ehdr.e_phnum = 1;
fo->write(&elfout, elfout.ehdr.e_ehsize + elfout.ehdr.e_phentsize);
}
else { // usual case
generateElfHdr(fo, &h3, getbrk(phdri, ehdri.e_phnum));
}
#undef E
}
void PackLinuxI386interp::pack2(OutputFile *fo, Filter &ft)
{
if (opt->o_unix.make_ptinterp) {
return; // ignore current input file!
}
super::pack2(fo, ft);
}
#undef PAGE_MASK
#define PAGE_MASK (~0u<<12)
void PackLinuxI386interp::pack3(OutputFile *fo, Filter &/*ft*/)
{
unsigned base = getbase(phdri, ehdri.e_phnum);
unsigned sz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
if (base < (0x11000 + sz)) {
base = 0x11000 + sz;
}
if (opt->o_unix.make_ptinterp) {
base = 0x10000;
}
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));
addLoader("LXPTI000", NULL);
addLoader("LXPTI040", NULL);
ph.method = M_NRV2B_LE32; addLoader(getDecompressor(), NULL);
addLoader("LXPTI090", NULL);
addLoader("LXPTI041", NULL);
ph.method = M_NRV2D_LE32; addLoader(getDecompressor(), NULL);
addLoader("LXPTI090", NULL);
addLoader("LXPTI042", NULL);
ph.method = M_NRV2E_LE32; addLoader(getDecompressor(), NULL);
addLoader("LXPTI090", NULL);
addLoader("LXPTI043", NULL);
ph.method = M_CL1B_LE32; addLoader(getDecompressor(), NULL);
addLoader("LXPTI090", NULL);
addLoader("LXPTI091", NULL);
addLoader("LXPTI140", NULL);
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL);
addFilter32(0x46);
addLoader("LXUNF042,LXUNF035", NULL);
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL);
addFilter32(0x49);
addLoader("LXUNF042,LXUNF035", NULL);
addLoader("LXPTI200", NULL);
addLoader("FOLDEXEC", NULL);
upx_byte const *p = getLoader();
lsize = getLoaderSize();
updateLoader(fo);
fo->write(p, lsize);
elfout.phdr[0].p_filesz = fo->getBytesWritten();
}
else {
updateLoader(fo);
}
}
void PackLinuxI386interp::unpack(OutputFile *fo)
{
#define MAX_INTERP_HDR 512
char bufehdr[MAX_INTERP_HDR];
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)bufehdr;
Elf32_Phdr const *phdr = (Elf32_Phdr *)(1+ehdr);
unsigned szb_info = sizeof(b_info);
{
fi->seek(0, SEEK_SET);
fi->readx(bufehdr, MAX_INTERP_HDR);
unsigned const e_entry = get_native32(&ehdr->e_entry);
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
szb_info = 2*sizeof(unsigned);
}
}
fi->seek(overlay_offset, SEEK_SET);
p_info hbuf;
fi->readx(&hbuf, sizeof(hbuf));
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
blocksize = get_native32(&hbuf.p_blocksize);
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
throwCantUnpack("file header corrupted");
ibuf.alloc(blocksize + OVERHEAD);
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
fi->readx(&bhdr, szb_info);
ph.u_len = get_native32(&bhdr.sz_unc);
ph.c_len = get_native32(&bhdr.sz_cpr);
ph.filter_cto = bhdr.b_cto8;
// Uncompress Ehdr and Phdrs.
fi->readx(ibuf, ph.c_len);
decompress(ibuf, (upx_byte *)ehdr, false);
unsigned total_in = 0;
unsigned total_out = 0;
unsigned c_adler = upx_adler32(NULL, 0);
unsigned u_adler = upx_adler32(NULL, 0);
off_t ptload0hi=0, ptload1lo=0, ptload1sz=0;
// decompress PT_LOAD
bool first_PF_X = true;
fi->seek(- (off_t) (szb_info + ph.c_len), SEEK_CUR);
for (unsigned j=0; j < ehdr->e_phnum; ++phdr, ++j) {
if (PT_LOAD==phdr->p_type) {
if (0==ptload0hi) {
ptload0hi = phdr->p_filesz + phdr->p_offset;
}
else if (0==ptload1lo) {
ptload1lo = phdr->p_offset;
ptload1sz = phdr->p_filesz;
}
if (fo)
fo->seek(phdr->p_offset, SEEK_SET);
if (Elf32_Phdr::PF_X & phdr->p_flags) {
unpackExtent(phdr->p_filesz, fo, total_in, total_out,
c_adler, u_adler, first_PF_X, szb_info);
first_PF_X = false;
}
else {
unpackExtent(phdr->p_filesz, fo, total_in, total_out,
c_adler, u_adler, false, szb_info);
}
}
}
if (0!=ptload1sz && ptload0hi < ptload1lo) { // alignment hole?
if (fo)
fo->seek(ptload0hi, SEEK_SET);
unpackExtent(ptload1lo - ptload0hi, fo, total_in, total_out,
c_adler, u_adler, false, szb_info);
}
if (total_out != orig_file_size) { // non-PT_LOAD stuff
if (fo)
fo->seek(0, SEEK_END);
unpackExtent(orig_file_size - total_out, fo, total_in, total_out,
c_adler, u_adler, false, szb_info);
}
// check for end-of-file
fi->readx(&bhdr, szb_info);
unsigned const sz_unc = ph.u_len = get_native32(&bhdr.sz_unc);
if (sz_unc == 0) { // uncompressed size 0 -> EOF
// note: magic is always stored le32
unsigned const sz_cpr = get_le32(&bhdr.sz_cpr);
if (sz_cpr != UPX_MAGIC_LE32) // sz_cpr must be h->magic
throwCompressedDataViolation();
}
else { // extra bytes after end?
throwCompressedDataViolation();
}
// update header with totals
ph.c_len = total_in;
ph.u_len = total_out;
// all bytes must be written
if (total_out != orig_file_size)
throwEOFException();
// finally test the checksums
if (ph.c_adler != c_adler || ph.u_adler != u_adler)
throwChecksumError();
#undef MAX_INTERP_HDR
}
/*
vi:ts=4:et
*/
+64
View File
@@ -0,0 +1,64 @@
/* p_lx_interp.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_INTERP_H //{
#define __UPX_P_LX_INTERP_H
/*************************************************************************
// linux/interp386
**************************************************************************/
class PackLinuxI386interp : public PackLinuxI386elf
{
typedef PackLinuxI386elf super;
public:
PackLinuxI386interp(InputFile *f);
virtual ~PackLinuxI386interp();
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 bool canPack();
virtual void unpack(OutputFile *fo);
protected:
virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &); // build loader
};
#endif /*} already included */
/*
vi:ts=4:et
*/
+15 -16
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 2000 John F. Reiser
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
@@ -22,11 +22,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
John F. Reiser
jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
*/
@@ -36,6 +33,7 @@
#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"
@@ -44,23 +42,24 @@
//
**************************************************************************/
#define SCRIPT_SIZE (opt->unix.SCRIPT_MAX + sizeof(l_info))
//#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->unix.script_name;
char const *name = opt->o_unix.script_name;
if (0==name) {
name = "/usr/local/lib/upxX";
}
sprintf(script, "#!%s\n", name);
if (M_IS_NRV2B(opt->method)) {
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(opt->method)) {
if (M_IS_NRV2D(ph.method)) {
script[strlen(script)-2] = 'd';
return (upx_byte const *)script;
}
@@ -69,16 +68,16 @@ const upx_byte *PackLinuxI386sep::getLoader() const
int PackLinuxI386sep::getLoaderSize() const
{
if (M_IS_NRV2B(opt->method))
if (M_IS_NRV2B(ph.method))
return SCRIPT_SIZE;
if (M_IS_NRV2D(opt->method))
if (M_IS_NRV2D(ph.method))
return SCRIPT_SIZE;
return 0;
}
int PackLinuxI386sep::getLoaderPrefixSize() const
{
return opt->unix.SCRIPT_MAX;
return opt->o_unix.SCRIPT_MAX;
}
void PackLinuxI386sep::patchLoader()
+5 -5
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 2000 John F. Reiser
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
@@ -22,8 +22,8 @@
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
John F. Reiser
jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
*/
+71 -137
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 2000 John F. Reiser
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
@@ -22,145 +22,93 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
John F. Reiser
jreiser@BitWagon.com
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 "filter.h"
#include "packer.h"
#include "p_elf.h"
#include "p_unix.h"
#include "p_lx_exc.h"
#include "p_lx_sh.h"
#define PT_LOAD Elf_LE32_Phdr::PT_LOAD
/*************************************************************************
//
**************************************************************************/
static const
#include "stub/l_sh_n2b.h"
#include "stub/l_lx_sh86.h"
static const
#include "stub/l_sh_n2d.h"
#include "stub/fold_sh86.h"
PackLinuxI386sh::PackLinuxI386sh(InputFile *f) :
super(f), o_shname(0), l_shname(0)
{
}
PackLinuxI386sh::~PackLinuxI386sh()
{
}
PackLinuxI386sh::PackLinuxI386sh(InputFile *f)
:super(f)
,o_shname(0)
,l_shname(0)
int
PackLinuxI386sh::buildLoader(Filter const *ft)
{
unsigned const sz_fold = sizeof(linux_i386sh_fold);
MemBuffer buf(sz_fold);
memcpy(buf, linux_i386sh_fold, sz_fold);
checkPatch(NULL, 0, 0, 0); // reset
patch_le32(buf,sz_fold,"UPX3",l_shname);
patch_le32(buf,sz_fold,"UPX2",o_shname);
// 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));
UNUSED(success);
return buildLinuxLoader(
linux_i386sh_loader, sizeof(linux_i386sh_loader),
buf, sz_fold, ft );
}
const upx_byte *PackLinuxI386sh::getLoader() const
{
if (M_IS_NRV2B(opt->method))
return linux_i386sh_nrv2b_loader;
if (M_IS_NRV2D(opt->method))
return linux_i386sh_nrv2d_loader;
return NULL;
}
int PackLinuxI386sh::getLoaderSize() const
{
if (0 != lsize) {
return lsize;
}
if (M_IS_NRV2B(opt->method))
return sizeof(linux_i386sh_nrv2b_loader);
if (M_IS_NRV2D(opt->method))
return sizeof(linux_i386sh_nrv2d_loader);
return 0;
}
static inline off_t max_off_t(off_t a, off_t b)
{
return a > b ? a : b;
}
static off_t getbrk(Elf_LE32_Phdr const *phdr, int e_phnum)
{
off_t brka = 0;
for (int j = 0; j < e_phnum; ++phdr, ++j) if (PT_LOAD==phdr->p_type) {
brka = max_off_t(brka, phdr->p_vaddr + phdr->p_memsz);
}
return brka;
}
void PackLinuxI386sh::patchLoader()
{
lsize = getLoaderSize();
ehdri = (Elf_LE32_Ehdr *)(void *)loader;
Elf_LE32_Phdr *const phdri = (Elf_LE32_Phdr *)(1+ehdri);
patch_le32(loader,lsize,"UPX3",l_shname);
patch_le32(loader,lsize,"UPX2",o_shname);
// stub/scripts/setfold.pl puts address of 'fold_begin' in phdr[1].p_offset
off_t const fold_begin = phdri[1].p_offset;
assert(fold_begin > 0);
assert(fold_begin < (off_t)lsize);
MemBuffer cprLoader(lsize);
// compress compiled C-code portion of loader
upx_compress_config_t conf; memset(&conf, 0xff, sizeof(conf));
conf.c_flags = 0;
upx_uint result_buffer[16];
upx_uint cprLsize;
upx_compress(
loader + fold_begin, lsize - fold_begin,
cprLoader, &cprLsize,
0, // progress_callback_t ??
getCompressionMethod(), 9,
&conf,
result_buffer
);
set_le32(0+fold_begin+loader, lsize - fold_begin);
set_le32(4+fold_begin+loader, cprLsize);
memcpy( 8+fold_begin+loader, cprLoader, cprLsize);
lsize = 8 + fold_begin + cprLsize;
patchVersion(loader,lsize);
unsigned const brka = getbrk(phdri, ehdri->e_phnum);
phdri[1].p_offset = 0xfff&brka;
phdri[1].p_vaddr = brka;
phdri[1].p_paddr = brka;
phdri[1].p_filesz = 0;
phdri[1].p_memsz = 0;
// The beginning of our loader consists of a elf_hdr (52 bytes) and
// two sections elf_phdr (2 * 32 byte), so we have 12 free bytes
// from offset 116 to the program start at offset 128.
assert(ehdri->e_phoff == sizeof(Elf_LE32_Ehdr));
assert(ehdri->e_ehsize == sizeof(Elf_LE32_Ehdr));
assert(ehdri->e_phentsize == sizeof(Elf_LE32_Phdr));
assert(ehdri->e_phnum == 2);
assert(ehdri->e_shnum == 0);
assert(lsize > 128 && lsize < 4096);
patchLoaderChecksum();
}
void PackLinuxI386sh::patchLoader() { }
bool PackLinuxI386sh::getShellName(char *buf)
{
exetype = -1;
l_shname = strcspn(buf, " \t\n\v\f\r");
l_shname = (int) strcspn(buf, " \t\n\v\f\r");
buf[l_shname] = 0;
char const *const basename = 1+strrchr(buf, '/');
static char const *const shname[] = { // known shells that accept "-c" arg
"sh", "ash", "bsh", "csh", "ksh", "bash", "tcsh", "pdksh",
//"python", // FIXME: does python work ???
"ash", "bash", "bsh", "csh", "ksh", "pdksh", "sh", "tcsh", "zsh",
"python",
NULL
};
for (int j=0; 0 != shname[j]; ++j) {
if (0==strcmp(shname[j], basename)) {
o_shname += 3; // space for "-c\x00"
return super::canPack();
const char *bname = strrchr(buf, '/');
if (bname == NULL)
return false;
for (int j = 0; NULL != shname[j]; ++j) {
if (0 == strcmp(shname[j], bname + 1)) {
bool const s = super::canPack();
if (s) {
opt->o_unix.blocksize = blocksize = file_size;
}
return s;
}
}
return false;
@@ -173,9 +121,9 @@ bool PackLinuxI386sh::canPack()
// only compress i386sh scripts when running under Linux
char buf[512];
fi->readx(buf, 512);
fi->readx(buf, sizeof(buf));
fi->seek(0, SEEK_SET);
buf[511] = 0;
buf[sizeof(buf) - 1] = 0;
if (!memcmp(buf, "#!/", 3)) { // #!/bin/sh
o_shname = 2;
return getShellName(&buf[o_shname]);
@@ -189,32 +137,18 @@ bool PackLinuxI386sh::canPack()
}
void PackLinuxI386sh::pack(OutputFile *fo)
void
PackLinuxI386sh::pack1(OutputFile *fo, Filter &)
{
#define PAGE_MASK (~0<<12)
opt->unix.blocksize = blocksize = file_size;
PackUnix::pack(fo);
// update loader
Elf_LE32_Phdr *const phdro = (Elf_LE32_Phdr *)(sizeof(Elf_LE32_Ehdr)+loader);
off_t const totlen = fo->getBytesWritten();
phdro[0].p_filesz = totlen;
phdro[0].p_memsz = PAGE_MASK & (~PAGE_MASK + totlen);
// Try to make brk() work by faking it for exec().
unsigned const brka = 0x08048000;
phdro[1].p_offset = 0xfff&brka;
phdro[1].p_vaddr = brka;
phdro[1].p_paddr = brka;
phdro[1].p_filesz = 0;
phdro[1].p_memsz = 0;
patchLoaderChecksum();
fo->seek(0, SEEK_SET);
fo->rewrite(loader, 0x80);
#undef PAGE_MASK
generateElfHdr(fo, linux_i386sh_fold, 0x08048000);
}
void
PackLinuxI386sh::pack3(OutputFile *fo, Filter &ft)
{
super::pack3(fo,ft);
elfout.phdr[0].p_filesz = fo->getBytesWritten();
}
/*
vi:ts=4:et
+10 -14
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 2000 John F. Reiser
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
@@ -22,11 +22,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
John F. Reiser
jreiser@BitWagon.com
Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser
markus@oberhumer.com ml1050@cdata.tvnet.hu jreiser@BitWagon.com
*/
@@ -44,26 +41,25 @@ class PackLinuxI386sh : public PackLinuxI386
public:
PackLinuxI386sh(InputFile *f);
virtual ~PackLinuxI386sh();
virtual int getVersion() const { return 11; }
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 int *getFilters() const { return NULL; }
virtual int buildLoader(const Filter *);
virtual void pack1(OutputFile *fo, Filter &ft);
virtual void pack3(OutputFile *fo, Filter &ft);
virtual bool canPack();
virtual void pack(OutputFile *fo);
// virtual void unpack(OutputFile *fo) { super::unpack(fo); }
virtual bool canUnpackVersion(int version) const
{ return (version >= 11); }
protected:
virtual const upx_byte *getLoader() const;
virtual int getLoaderSize() const;
virtual bool getShellName(char *buf);
virtual void patchLoader();
Elf_LE32_Ehdr *ehdri; // from input file
int o_shname; // offset to name_of_shell
int l_shname; // length of name_of_shell
};
+378
View File
@@ -0,0 +1,378 @@
/* p_mach.cpp -- pack Mach Object executable
This file is part of the UPX executable compressor.
Copyright (C) 2004 John 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.
John Reiser
jreiser@users.sourceforge.net
*/
#include "conf.h"
#include "file.h"
#include "filter.h"
#include "linker.h"
#include "packer.h"
#include "p_mach.h"
static const
#include "stub/l_mac_ppc32.h"
static const
#include "stub/fold_machppc32.h"
PackMachPPC32::PackMachPPC32(InputFile *f) :
super(f), n_segment(0), rawmseg(0), msegcmd(0)
{
}
PackMachPPC32::~PackMachPPC32()
{
delete [] msegcmd;
delete [] rawmseg;
}
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 };
return m_nrv2e;
}
const int *PackMachPPC32::getFilters() const
{
static const int filters[] = { 0xd0, -1 };
return filters;
}
int
PackMachPPC32::buildMachLoader(
upx_byte const *const proto,
unsigned const szproto,
upx_byte const *const fold,
unsigned const szfold,
Filter const */*ft*/
)
{
int eof_empty = -1;
initLoader(&eof_empty, 4096, 0, 0);
struct b_info h; memset(&h, 0, sizeof(h));
unsigned fold_hdrlen = 0;
if (0 < szfold) {
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;
}
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;
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);
addLoader("MACOS000", NULL);
addLoader("FOLDEXEC", NULL);
return getLoaderSize();
}
int
PackMachPPC32::buildLoader(const Filter *ft)
{
return buildMachLoader(
l_mac_ppc32_loader, sizeof(l_mac_ppc32_loader),
fold_machppc32, sizeof(fold_machppc32), ft );
}
void PackMachPPC32::patchLoader() { }
void PackMachPPC32::updateLoader(OutputFile *) {}
void
PackMachPPC32::patchLoaderChecksum()
{
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
l_info *const lp = &linfo;
// checksum for loader; also some PackHeader info
lp->l_checksum = 0;
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
lp->l_lsize = (unsigned short) lsize;
lp->l_version = (unsigned char) ph.version;
lp->l_format = (unsigned char) ph.format;
// INFO: lp->l_checksum is currently unused
lp->l_checksum = upx_adler32(ptr, lsize);
}
static int __acc_cdecl_qsort
compare_segment_command(void const *const aa, void const *const bb)
{
Mach_segment_command const *const a = (Mach_segment_command const *)aa;
Mach_segment_command const *const b = (Mach_segment_command const *)bb;
unsigned const xa = a->cmd - Mach_segment_command::LC_SEGMENT;
unsigned const xb = b->cmd - Mach_segment_command::LC_SEGMENT;
if (xa < xb) return -1; // LC_SEGMENT first
if (xa > xb) return 1;
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr
if (a->vmaddr > b->vmaddr) return 1;
return 0;
}
void
PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{
// offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
super::pack4(fo, ft);
segcmdo.filesize = fo->getBytesWritten();
segcmdo.vmsize += segcmdo.filesize;
fo->seek(sizeof(mhdro), SEEK_SET);
fo->write(&segcmdo, sizeof(segcmdo));
fo->write(&threado, sizeof(threado));
fo->write(&linfo, sizeof(linfo));
}
void
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);
set_be32(&disp, 4+ len - sz_mach_headers); // 4: sizeof(instruction)
fo->write(&disp, sizeof(disp));
threado.state.srr0 = len + segcmdo.vmaddr; /* entry address */
super::pack3(fo, ft);
}
void
PackMachPPC32::pack2(OutputFile *fo, Filter &ft) // append compressed body
{
Extent x;
unsigned k;
ui_total_passes = n_segment;
// 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;
}
ui_pass = 0;
ft.addvalue = 0;
int nx = 0;
for (k = 0; k < n_segment; ++k)
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd
&& 0!=msegcmd[k].filesize ) {
x.offset = msegcmd[k].fileoff;
x.size = msegcmd[k].filesize;
if (0 == nx) { // 1st LC_SEGMENT must cover Mach_header at 0==fileoffset
unsigned const delta = mhdri.sizeofcmds;
x.offset += delta;
x.size -= delta;
}
packExtent(x, total_in, total_out,
((Mach_segment_command::VM_PROT_EXECUTE & msegcmd[k].initprot)
? &ft : 0 ), fo );
++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);
}
if ((off_t)total_in != file_size)
throwEOFException();
segcmdo.filesize = fo->getBytesWritten();
}
#undef PAGE_MASK
#undef PAGE_SIZE
#define PAGE_MASK (~0u<<12)
#define PAGE_SIZE -PAGE_MASK
void
PackMachPPC32::pack1(OutputFile *fo, Filter &/*ft*/) // generate executable header
{
mhdro = mhdri;
mhdro.ncmds = 2;
mhdro.sizeofcmds = sizeof(segcmdo) + sizeof(threado);
mhdro.flags = Mach_header::MH_NOUNDEFS;
fo->write(&mhdro, sizeof(mhdro));
segcmdo.cmd = Mach_segment_command::LC_SEGMENT;
segcmdo.cmdsize = sizeof(segcmdo);
strncpy((char *)&segcmdo.segname, "__TEXT", sizeof(segcmdo.segname));
segcmdo.vmaddr = PAGE_MASK & (~PAGE_MASK +
msegcmd[n_segment -1].vmsize + msegcmd[n_segment -1].vmaddr );
segcmdo.vmsize = 0; // adjust later
segcmdo.fileoff = 0;
segcmdo.filesize = 0; // adjust later
segcmdo.initprot = segcmdo.maxprot =
Mach_segment_command::VM_PROT_READ |
Mach_segment_command::VM_PROT_WRITE |
Mach_segment_command::VM_PROT_EXECUTE;
segcmdo.nsects = 0;
segcmdo.flags = 0;
fo->write(&segcmdo, sizeof(segcmdo));
threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
threado.cmdsize = sizeof(threado);
threado.flavor = Mach_thread_command::PPC_THREAD_STATE;
threado.count = Mach_thread_command::PPC_THREAD_STATE_COUNT;
memset(&threado.state, 0, sizeof(threado.state));
fo->write(&threado, sizeof(threado));
sz_mach_headers = fo->getBytesWritten();
memset((char *)&linfo, 0, sizeof(linfo));
fo->write(&linfo, sizeof(linfo));
return;
}
void
PackMachPPC32::unpack(OutputFile *fo)
{
fi->seek(overlay_offset, SEEK_SET);
p_info hbuf;
fi->readx(&hbuf, sizeof(hbuf));
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
blocksize = get_native32(&hbuf.p_blocksize);
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
throwCantUnpack("file header corrupted");
ibuf.alloc(blocksize + OVERHEAD);
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
fi->readx(&bhdr, sizeof(bhdr));
ph.u_len = get_native32(&bhdr.sz_unc);
ph.c_len = get_native32(&bhdr.sz_cpr);
ph.filter_cto = bhdr.b_cto8;
// Uncompress Macho headers
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 total_in = 0;
unsigned total_out = 0;
unsigned c_adler = upx_adler32(NULL, 0);
unsigned u_adler = upx_adler32(NULL, 0);
Mach_segment_command const *sc = (Mach_segment_command const *)(1+ mhdr);
unsigned k;
fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR);
for (
k = 0;
k < mhdr->ncmds;
(++k), (sc = (Mach_segment_command const *)(sc->cmdsize + (char const *)sc))
) {
if (Mach_segment_command::LC_SEGMENT==sc->cmd
&& 0!=sc->filesize ) {
unsigned filesize = get_be32(&sc->filesize);
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));
}
}
bool
PackMachPPC32::canPack()
{
fi->seek(0, SEEK_SET);
fi->readx(&mhdri, sizeof(mhdri));
if (Mach_header::MH_MAGIC !=mhdri.magic
|| Mach_header::CPU_TYPE_POWERPC !=mhdri.cputype
|| Mach_header::MH_EXECUTE !=mhdri.filetype
)
return false;
rawmseg = (Mach_segment_command *)new char[mhdri.sizeofcmds];
fi->readx(rawmseg, mhdri.sizeofcmds);
msegcmd = new Mach_segment_command[mhdri.ncmds];
unsigned char *ptr = (unsigned char *)rawmseg;
for (unsigned j= 0; j < mhdri.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, mhdri.ncmds, sizeof(*msegcmd), compare_segment_command);
// Check that LC_SEGMENTs form one contiguous chunk of the file.
for (unsigned j= 0; j < mhdri.ncmds; ++j) {
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd) {
if (0xfff & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) {
return false;
}
if (0 < j) {
unsigned const sz = ~0xfff
& (0xfff + msegcmd[j-1].filesize);
if ((sz + msegcmd[j-1].fileoff)!=msegcmd[j].fileoff) {
return false;
}
}
++n_segment;
sz_segment = msegcmd[j].filesize + msegcmd[j].fileoff - msegcmd[0].fileoff;
}
}
// set options
opt->o_unix.blocksize = file_size;
return 0 < n_segment;
}
/*
vi:ts=4:et
*/
+213
View File
@@ -0,0 +1,213 @@
/* p_mach.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
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@cdata.tvnet.hu
*/
#ifndef __UPX_P_MACHO_H
#define __UPX_P_MACHO_H
/*************************************************************************
// Mach Mach Object executable
**************************************************************************/
struct Mach_header {
BE32 magic;
enum {
MH_MAGIC = 0xfeedface
};
BE32 cputype;
enum {
CPU_TYPE_POWERPC = 18
};
BE32 cpysubtype;
BE32 filetype;
enum {
MH_EXECUTE = 2
};
BE32 ncmds;
BE32 sizeofcmds;
BE32 flags;
enum {
MH_NOUNDEFS = 1
};
}
__attribute_packed;
struct Mach_segment_command {
BE32 cmd;
enum {
LC_SEGMENT = 0x1,
LC_THREAD = 0x4,
LC_UNIXTHREAD = 0x5,
LC_LOAD_DYLINKER = 0xe
};
BE32 cmdsize;
char segname[16];
BE32 vmaddr;
BE32 vmsize;
BE32 fileoff;
BE32 filesize;
BE32 maxprot;
enum {
VM_PROT_READ = 1,
VM_PROT_WRITE = 2,
VM_PROT_EXECUTE = 4
};
BE32 initprot;
BE32 nsects;
BE32 flags;
}
__attribute_packed;
struct Mach_section {
char sectname[16];
char segname[16];
BE32 addr; /* memory address */
BE32 size; /* size in bytes */
BE32 offset; /* file offset */
BE32 align; /* power of 2 */
BE32 reloff; /* file offset of relocation entries */
BE32 nreloc; /* number of relocation entries */
BE32 flags; /* section type and attributes */
enum {
S_REGULAR = 0,
S_ZEROFILL,
S_CSTRING_LITERALS,
S_4BYTE_LITERALS,
S_8BYTE_LITERALS,
S_LITERAL_POINTERS,
S_NON_LAZY_SYMBOL_POINTERS,
S_LAZY_SYMBOL_POINTERS,
S_SYMBOL_STUBS,
S_MOD_INIT_FUNC_POINTERS,
S_MOD_TERM_FNC_POINTERS,
S_COALESCED
};
enum {
S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
S_ATTR_NO_TOC = 0x40000000,
S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
S_ATTR_EXT_RELOC = 0x00000200,
S_ATTR_LOC_RELOC = 0x00000100
};
BE32 reserved1;
BE32 reserved2;
}
__attribute_packed;
struct Mach_ppc_thread_state {
BE32 srr0; /* Instruction address register (PC; entry addr) */
BE32 srr1; /* Machine state register (supervisor) */
BE32 r0, r1, r2, r3, r4, r5, r6, r7;
BE32 r8, r9,r10,r11,r12,r13,r14,r15;
BE32 r16,r17,r18,r19,r20,r21,r22,r23;
BE32 r24,r25,r26,r27,r28,r29,r30,r31;
BE32 cr; /* Condition register */
BE32 xer; /* User's integer exception register */
BE32 lr; /* Link register */
BE32 ctr; /* Count register */
BE32 mq; /* MQ register (601 only) */
BE32 vrsave; /* Vector Save Register */
};
struct Mach_thread_command {
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
BE32 cmdsize; /* total size of this command */
BE32 flavor;
enum {
PPC_THREAD_STATE = 1
};
BE32 count; /* sizeof(following_thread_state)/4 */
enum {
PPC_THREAD_STATE_COUNT = sizeof(struct Mach_ppc_thread_state)/4
};
struct Mach_ppc_thread_state state;
}
__attribute_packed;
#include "p_unix.h"
class PackMachPPC32 : public PackUnixBe32
{
typedef PackUnixBe32 super;
public:
PackMachPPC32(InputFile *f);
virtual ~PackMachPPC32();
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 int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
// called by the generic pack()
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 PackHeader
virtual void unpack(OutputFile *fo);
virtual bool canPack();
protected:
virtual int buildLoader(const Filter *ft);
virtual void patchLoader();
virtual void patchLoaderChecksum();
virtual void updateLoader(OutputFile *);
virtual int buildMachLoader(
upx_byte const *const proto,
unsigned const szproto,
upx_byte const *const fold,
unsigned const szfold,
Filter const *ft );
unsigned n_segment;
unsigned sz_segment;
unsigned sz_mach_headers;
Mach_segment_command *rawmseg; // as input, with sections
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
Mach_header mhdri;
Mach_header mhdro;
Mach_segment_command segcmdo;
Mach_thread_command threado;
struct l_info linfo;
};
#endif /* already included */
/*
vi:ts=4:et
*/
+508
View File
@@ -0,0 +1,508 @@
/* p_ps1.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) 2002-2006 Jens Medoch
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>
Jens Medoch
<jssg@users.sourceforge.net>
*/
#include "conf.h"
#include "file.h"
#include "filter.h"
#include "packer.h"
#include "p_ps1.h"
static const
#include "stub/l_ps1b.h"
static const
#include "stub/l_ps1c.h"
#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 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 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)
/*************************************************************************
// ps1 exe looks like this:
// 1. <header> 2048 bytes
// 2. <body> plain binary
//
// header: contains the ps1_exe_t structure 188 bytes at offset zero
// rest is filled with zeros to reach the required
// cd mode 2 data sector size of 2048 bytes
// body: contains the binary data / code of the executable
// reqiures: executable code must be aligned to 4
// must be aligned to 2048 to run from a CD
// optional: not aligned to 2048 (for console run only)
**************************************************************************/
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)
{
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;
}
const int *PackPs1::getCompressionMethods(int method, int level) const
{
if (is32Bit)
return Packer::getDefaultCompressionMethods_le32(method, level);
else
return Packer::getDefaultCompressionMethods_8(method, level);
}
const int *PackPs1::getFilters() const
{
return NULL;
}
/*************************************************************************
// util
// readFileHeader() reads ih and checks for illegal values
// checkFileHeader() checks ih for legal but unsupported values
**************************************************************************/
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)
return 0;
if (ih.text != 0 || ih.data != 0)
return 0;
return UPX_F_PS1_EXE;
}
bool PackPs1::checkFileHeader()
{
if (fdata_size != ih.tx_len || (ih.tx_len & 3))
{
if (!opt->force)
throwCantPack("file size entry damaged (try --force)");
else
{
opt->info_mode += !opt->info_mode ? 1 : 0;
infoWarning("fixing damaged header, keeping backup file");
opt->backup = 1;
ih.tx_len = fdata_size;
}
}
if (!opt->force &&
(ih.da_ptr != 0 || ih.da_len != 0 ||
ih.bs_ptr != 0 || ih.bs_len != 0))
{
infoWarning("unsupported header field entry");
return false;
}
if (!opt->force && ih.is_ptr == 0)
{
infoWarning("stack pointer field empty");
return false;
}
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];
if (!readFileHeader())
return false;
fi->readx(buf, sizeof(buf));
checkAlreadyPacked(buf, sizeof(buf));
for (unsigned i = 0; i < sizeof(buf); i++)
if (buf[i] != 0)
if (!opt->force)
throwCantPack("unknown data in header (try --force)");
else
{
opt->info_mode += !opt->info_mode ? 1 : 0;
infoWarning("clearing header, keeping backup file");
opt->backup = 1;
break;
}
if (!checkFileHeader())
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)
throwCantPack("file is too big (try --force)");
return true;
}
/*************************************************************************
//
**************************************************************************/
int 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);
if (ph.method == M_NRV2B_8)
addLoader("PS1N2B08", NULL);
else if (ph.method == M_NRV2D_8)
addLoader("PS1N2D08", NULL);
else if (ph.method == M_NRV2E_8)
addLoader("PS1N2E08", NULL);
else if (ph.method == M_NRV2B_LE32)
addLoader("PS1N2B32", NULL);
else if (ph.method == M_NRV2D_LE32)
addLoader("PS1N2D32", NULL);
else if (ph.method == M_NRV2E_LE32)
addLoader("PS1N2E32", NULL);
else
throwInternalError("unknown compression method");
if (sa_cnt)
addLoader(sa_cnt > (0x10000 << 2) ? "PS1MSETB" : "PS1MSETS",
ih.tx_len & 3 ? "PS1MSETU" : "PS1MSETA",
NULL);
addLoader("PS1EXITC", "IDENTSTR", "PS1PAHDR",
isCon ? "PS1SREGS" : "",
NULL);
return getLoaderSize();
}
/*************************************************************************
//
**************************************************************************/
void PackPs1::pack(OutputFile *fo)
{
ibuf.alloc(fdata_size);
obuf.allocForCompression(fdata_size);
const upx_byte *p_scan = ibuf+fdata_size;
// read file
fi->seek(PS_HDR_SIZE,SEEK_SET);
fi->readx(ibuf,fdata_size);
// 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; }
if (sa_cnt > (0x10000<<2))
sa_cnt = ALIGN_DOWN(sa_cnt,32);
else
sa_cnt = ALIGN_DOWN(sa_cnt,4);
// prepare packheader
ph.u_len = (fdata_size - sa_cnt);
ph.filter = 0;
Filter ft(ph.level);
// compress (max_match = 65535)
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
if (ph.overlap_overhead > sa_cnt)
{
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);
}
}
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;
if (ih.da_ptr != 0 || ih.da_len != 0 ||
ih.bs_ptr != 0 || ih.bs_len != 0)
oh.da_ptr = oh.da_len =
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 int h_len = lsize - getLoaderSectionStart("IDENTSTR");
const int c_len = lsize - h_len;
int d_len = 0;
int e_len = 0;
if (isCon)
{
e_len = lsize - h_len;
d_len = e_len - getLoaderSectionStart("PS1ENTRY");
}
else
{
d_len = (lsize - h_len) - getLoaderSectionStart("PS1ENTRY");
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));
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 (!opt->ps1_exe.no_align)
{
pad = oh.tx_len;
oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC);
pad = oh.tx_len - pad;
oh.tx_ptr -= pad;
}
ibuf.clear(0,fdata_size);
upx_bytep paddata = ibuf;
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);
}
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);
}
// header size is 2048 bytes
fo->write(paddata, PS_HDR_SIZE - fo->getBytesWritten());
// sector alignment
if (pad)
fo->write(paddata, pad);
// entry
fo->write(loader, e_len);
// code must be aligned to 4!
if (pad_code)
fo->write(paddata, pad_code);
// compressed binary / data
fo->write(obuf, ph.c_len);
verifyOverlappingDecompression();
if (!checkFinalCompressionRatio(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);
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);
#endif
}
/*************************************************************************
//
**************************************************************************/
int PackPs1::canUnpack()
{
if (!readFileHeader())
return false;
if (!readPackHeader(1024))
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))
throwCantUnpack("header damaged");
// generic check
if (!checkFileHeader())
throwCantUnpack("unsupported header flags");
return true;
}
/*************************************************************************
//
**************************************************************************/
void PackPs1::unpack(OutputFile *fo)
{
// restore orig exec hdr
memcpy(&oh, &ih, sizeof(ih));
memcpy(&oh.epc, &ih.ih_bkup, SZ_IH_BKUP);
// check for removed sector alignment
assert(oh.tx_len >= ph.u_len);
const unsigned pad = oh.tx_len - ph.u_len;
ibuf.alloc(fdata_size > PS_HDR_SIZE ? fdata_size : PS_HDR_SIZE);
obuf.allocForUncompression(ph.u_len, pad);
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);
// write decompressed file
if (fo)
{
// write header
fo->write(&oh, sizeof(oh));
// align the ps exe header (mode 2 sector data size)
ibuf.clear();
// 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
*/
+117
View File
@@ -0,0 +1,117 @@
/* p_ps1.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) 2002-2004 Jens Medoch
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>
Jens Medoch
<jssg@users.sourceforge.net>
*/
#ifndef __UPX_P_PS1_H
#define __UPX_P_PS1_H
/*************************************************************************
// ps1/exe
**************************************************************************/
class PackPs1 : public Packer
{
typedef Packer super;
public:
PackPs1(InputFile *f);
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 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();
protected:
virtual void patch_mips_le(void *b, int blen, const void *old, unsigned new_);
virtual int buildLoader(const Filter *ft);
virtual int readFileHeader();
virtual bool checkFileHeader();
struct ps1_exe_t
{
// ident string
char id[8];
// is NULL
LE32 text;
// is NULL
LE32 data;
// initial program counter
LE32 epc;
// initial gp register value
LE32 gp;
// load offset of binary data
LE32 tx_ptr, tx_len;
LE32 da_ptr, da_len;
LE32 bs_ptr, bs_len;
// initial stack params
LE32 is_ptr, is_len;
// saved regs on execution
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)
LE32 ih_bkup[10];
// plus checksum for the backup
LE32 ih_csum;
// id & the upx header.
}
__attribute_packed;
ps1_exe_t ih, oh;
bool isCon;
bool is32Bit;
unsigned overlap;
unsigned sa_cnt;
// filesize-PS_HDR_SIZE
unsigned fdata_size;
};
#endif /* already included */
/*
vi:ts=4:et
*/
+21 -19
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -45,13 +45,12 @@ bool PackSys::canPack()
{
unsigned char buf[128];
fi->readx(buf,128);
fi->readx(buf, sizeof(buf));
if (memcmp (buf,"\xff\xff\xff\xff",4) != 0)
return false;
if (!fn_has_ext(fi->getName(),"sys"))
return false;
if (find_le32(buf,128,UPX_MAGIC_LE32) >= 0)
throwAlreadyPacked();
checkAlreadyPacked(buf, sizeof(buf));
if (file_size < 1024)
throwCantPack("file is too small");
if (file_size > 0x10000)
@@ -66,7 +65,7 @@ bool PackSys::canPack()
void PackSys::patchLoader(OutputFile *fo,
upx_byte *loader, int lsize,
unsigned calls, unsigned overlapoh)
unsigned calls)
{
const int filter_id = ph.filter;
const int e_len = getLoaderSectionStart("SYSCUTPO");
@@ -74,13 +73,13 @@ void PackSys::patchLoader(OutputFile *fo,
assert(e_len > 0 && e_len < 256);
assert(d_len > 0 && d_len < 256);
if (ph.u_len + d_len + overlapoh > 0xfffe)
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
unsigned copy_to = ph.u_len + d_len + overlapoh;
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)
@@ -91,8 +90,8 @@ void PackSys::patchLoader(OutputFile *fo,
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+overlapoh+2-jmp_pos-2);
loader[getLoaderSection("SYSSUBSI") - 1] = (upx_byte) -e_len;
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);
@@ -105,19 +104,22 @@ void PackSys::patchLoader(OutputFile *fo,
int PackSys::buildLoader(const Filter *ft)
{
const int filter_id = ft->id;
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
addLoader("SYSMAIN1",
opt->cpu == opt->CPU_8086 ? "SYSI0861" : "SYSI2861",
"SYSMAIN2""SYSSUBSI",
filter_id ? "SYSCALLT" : "",
"SYSMAIN3""UPX1HEAD""SYSCUTPO""NRV2B160""NRVDDONE""NRVDECO1",
"SYSMAIN2,SYSSUBSI",
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,NRV2B169",
NULL
);
if (filter_id)
addFilter16(filter_id);
if (ft->id)
{
assert(ft->calls > 0);
addFilter16(ft->id);
}
addLoader("SYSMAIN5",
opt->cpu == opt->CPU_8086 ? "SYSI0862" : "SYSI2862",
"SYSJUMP1",
+7 -7
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -39,18 +39,18 @@ class PackSys : public PackCom
typedef PackCom super;
public:
PackSys(InputFile *f) : super(f) { }
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_DOS_SYS; }
virtual const char *getName() const { return "dos/sys"; }
virtual bool canPack();
protected:
virtual const unsigned getCallTrickOffset() const { return 0; }
virtual unsigned getCallTrickOffset() const { return 0; }
protected:
virtual int buildLoader(const Filter *ft);
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned, unsigned);
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
};
+82 -65
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,10 +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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
#include "conf.h"
#include "file.h"
#include "filter.h"
@@ -41,32 +42,72 @@ static const
//
**************************************************************************/
int PackTmt::getCompressionMethod() const
PackTmt::PackTmt(InputFile *f) : super(f)
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_LE32;
if (M_IS_NRV2D(opt->method))
return M_NRV2D_LE32;
return opt->level > 1 && file_size >= 512*1024 ? M_NRV2D_LE32 : M_NRV2B_LE32;
COMPILE_TIME_ASSERT(sizeof(tmt_header_t) == 44);
}
const int *PackTmt::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_le32(method, level);
}
const int *PackTmt::getFilters() const
{
static const int filters[] = { 0x26, 0x24, 0x11, 0x14, 0x13, 0x16,
0x25, 0x12, 0x15, -1 };
static const int filters[] = {
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x12, 0x15,
-1 };
return filters;
}
unsigned PackTmt::findOverlapOverhead(const upx_bytep buf,
unsigned range,
unsigned upper_limit) const
{
// make sure the decompressor will be paragraph aligned
unsigned o = super::findOverlapOverhead(buf, range, upper_limit);
o = ((o + 0x20) &~ 0xf) - (ph.u_len & 0xf);
return o;
}
int PackTmt::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("IDENTSTR,TMTMAIN1",
ft->id ? "TMTCALT1" : "",
"TMTMAIN2,UPX1HEAD,TMTCUTPO,+0XXXXXX",
getDecompressor(),
"TMTMAIN5",
NULL
);
if (ft->id)
{
assert(ft->calls > 0);
addLoader("TMTCALT2",NULL);
addFilter32(ft->id);
}
addLoader("TMTRELOC,RELOC320",
big_relocs ? "REL32BIG" : "",
"RELOC32J,TMTJUMP1",
NULL
);
return getLoaderSize();
}
/*************************************************************************
// util
//
**************************************************************************/
bool PackTmt::readFileHeader()
int PackTmt::readFileHeader()
{
#define H(x) get_le16(h,2*(x))
#define H4(x) get_le32(h,x)
#define H(x) get_le16(h+2*(x))
#define H4(x) get_le32(h+(x))
unsigned char h[0x40];
int ic;
unsigned exe_offset = 0;
@@ -111,14 +152,16 @@ bool PackTmt::readFileHeader()
else if (memcmp(h,"Adam",4) == 0)
break;
else
return false;
return 0;
}
if (ic == 20)
return false;
return 0;
fi->seek(adam_offset,SEEK_SET);
fi->readx(&ih,sizeof(ih));
// FIXME: should add some checks for the values in `ih'
return true;
return UPX_F_TMT_ADAM;
#undef H4
#undef H
}
@@ -126,7 +169,9 @@ bool PackTmt::readFileHeader()
bool PackTmt::canPack()
{
return readFileHeader();
if (!readFileHeader())
return false;
return true;
}
@@ -136,6 +181,8 @@ bool PackTmt::canPack()
void PackTmt::pack(OutputFile *fo)
{
big_relocs = 0;
Packer::handleStub(fi,fo,adam_offset);
const unsigned usize = ih.imagesize;
@@ -160,18 +207,13 @@ void PackTmt::pack(OutputFile *fo)
checkOverlay(overlay);
unsigned relocsize = 0;
int big;
//if (rsize)
{
for (unsigned ic=4; ic<=rsize; ic+=4)
set_le32(wrkmem+ic,get_le32(wrkmem+ic)-4);
relocsize = optimizeReloc32(wrkmem+4,rsize/4,wrkmem,ibuf,1,&big)-wrkmem;
relocsize = ptr_diff(optimizeReloc32(wrkmem+4,rsize/4,wrkmem,ibuf,1,&big_relocs), wrkmem);
}
// filter
Filter ft(opt->level);
tryFilters(&ft, ibuf, usize);
wrkmem[relocsize++] = 0;
set_le32(wrkmem+relocsize,ih.entry); // save original entry point
relocsize += 4;
@@ -179,38 +221,13 @@ void PackTmt::pack(OutputFile *fo)
relocsize += 4;
memcpy(ibuf+usize,wrkmem,relocsize);
ph.filter = ft.id;
ph.filter_cto = ft.cto;
ph.u_len = usize+relocsize;
if (!compress(ibuf,obuf))
throwNotCompressible();
// make sure the decompressor will be paragraph aligned
const unsigned overlapoh = ((findOverlapOverhead(obuf,512)+0x20)
&~ 0xf) - (ph.u_len & 0xf);
// verify filter
ft.verifyUnfilter();
// prepare loader
initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("IDENTSTR""TMTMAIN1",
ft.id ? "TMTCALT1" : "",
"TMTMAIN2""UPX1HEAD""TMTCUTPO""+0XXXXXX",
getDecompressor(),
"TMTMAIN5",
NULL
);
if (ft.id)
{
assert(ft.calls > 0);
addLoader("TMTCALT2",NULL);
addFilter32(ft.id);
}
addLoader("TMTRELOC""RELOC320",
big ? "REL32BIG" : "",
"RELOC32J""TMTJUMP1",
NULL
);
// prepare packheader
ph.u_len = usize + relocsize;
// prepare filter
Filter ft(ph.level);
ft.buf_len = usize;
// compress
compressWithFilters(&ft, 512);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
@@ -222,18 +239,18 @@ void PackTmt::pack(OutputFile *fo)
assert(e_len > 0 && s_point > 0);
// patch loader
patch_le32(loader,lsize,"JMPO",ih.entry-(ph.u_len+overlapoh+d_len));
patch_le32(loader,lsize,"JMPO",ih.entry-(ph.u_len+ph.overlap_overhead+d_len));
patchFilter32(loader, lsize, &ft);
patchPackHeader(loader,e_len);
const unsigned jmp_pos = find_le32(loader,e_len,get_le32("JMPD"));
patch_le32(loader,e_len,"JMPD",ph.u_len+overlapoh-jmp_pos-4);
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+overlapoh+d_len-1);
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",
// e_len,d_len,copy_len,copy_to,overlapoh,jmp_pos,ph.u_len,ph.c_len);
// e_len,d_len,copy_len,copy_to,ph.overlap_overhead,jmp_pos,ph.u_len,ph.c_len);
memcpy(&oh,&ih,sizeof(oh));
oh.imagesize = ph.c_len+e_len+d_len; // new size
@@ -250,7 +267,7 @@ void PackTmt::pack(OutputFile *fo)
fo->write(rel_entry,sizeof (rel_entry));
// verify
verifyOverlappingDecompression(&obuf, overlapoh);
verifyOverlappingDecompression();
// copy the overlay
copyOverlay(fo, overlay, &obuf);
@@ -263,7 +280,7 @@ void PackTmt::pack(OutputFile *fo)
int PackTmt::canUnpack()
{
if (!PackTmt::readFileHeader())
if (!readFileHeader())
return false;
fi->seek(adam_offset, SEEK_SET);
return readPackHeader(512) ? 1 : -1;
@@ -294,7 +311,7 @@ void PackTmt::unpack(OutputFile *fo)
Filter ft(ph.level);
ft.init(ph.filter, 0);
ft.cto = (unsigned char) (ph.version < 11 ? (get_le32(obuf+ph.u_len-12) >> 24) : ph.filter_cto);
ft.unfilter(obuf, relocs-obuf);
ft.unfilter(obuf, ptr_diff(relocs, obuf));
}
// decode relocations
+15 -9
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -38,11 +38,11 @@ class PackTmt : public Packer
{
typedef Packer super;
public:
PackTmt(InputFile *f) : super(f) { assert(sizeof(tmt_header_t) == 44); }
virtual int getVersion() const { return 11; }
PackTmt(InputFile *f);
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_TMT_ADAM; }
virtual const char *getName() const { return "tmt/adam"; }
virtual int getCompressionMethod() const;
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo);
@@ -52,9 +52,15 @@ public:
virtual int canUnpack();
protected:
bool readFileHeader();
virtual int readFileHeader();
virtual unsigned findOverlapOverhead(const upx_bytep buf,
unsigned range = 0,
unsigned upper_limit = ~0u) const;
virtual int buildLoader(const Filter *ft);
unsigned adam_offset;
int big_relocs;
struct tmt_header_t
{
@@ -64,7 +70,7 @@ protected:
LE32 entry;
char ___[12]; // esp,numfixups,flags
LE32 relocsize;
} ih,oh;
} ih, oh;
};
+165 -85
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,14 +21,15 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "file.h"
#include "filter.h"
#include "packer.h"
#include "p_tos.h"
@@ -40,6 +41,10 @@ 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"
// #define TESTING
@@ -53,17 +58,14 @@ static const
PackTos::PackTos(InputFile *f) :
super(f)
{
assert(FH_SIZE == 28);
COMPILE_TIME_ASSERT(FH_SIZE == 28);
}
int PackTos::getCompressionMethod() const
const int *PackTos::getCompressionMethods(int method, int level) const
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_8;
if (M_IS_NRV2D(opt->method))
return M_NRV2D_8;
return opt->level > 1 && file_size >= 512*1024 ? M_NRV2D_8 : M_NRV2B_8;
bool small = ih.fh_text + ih.fh_data <= 256*1024;
return Packer::getDefaultCompressionMethods_8(method, level, small);
}
@@ -75,20 +77,24 @@ const int *PackTos::getFilters() const
const upx_byte *PackTos::getLoader() const
{
if (M_IS_NRV2B(opt->method))
if (M_IS_NRV2B(ph.method))
return opt->small ? nrv2b_loader_small : nrv2b_loader;
if (M_IS_NRV2D(opt->method))
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;
}
int PackTos::getLoaderSize() const
{
if (M_IS_NRV2B(opt->method))
if (M_IS_NRV2B(ph.method))
return opt->small ? sizeof(nrv2b_loader_small) : sizeof(nrv2b_loader);
if (M_IS_NRV2D(opt->method))
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);
return 0;
}
@@ -130,17 +136,19 @@ int PackTos::getLoaderSize() const
/*************************************************************************
// util
// readFileHeader() reads ih and checks for illegal values
// checkFileHeader() checks ih for legal but unsupported values
**************************************************************************/
bool PackTos::readFileHeader()
int PackTos::readFileHeader()
{
fi->seek(0,SEEK_SET);
fi->readx(&ih, FH_SIZE);
if (ih.fh_magic != 0x601a)
return false;
return 0;
if (FH_SIZE + ih.fh_text + ih.fh_data + ih.fh_sym > (unsigned) file_size)
return false;
return true;
return 0;
return UPX_F_ATARI_TOS;
}
@@ -176,65 +184,120 @@ bool PackTos::checkFileHeader()
}
/*************************************************************************
// 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_d0_subq(void *b, int blen, unsigned d0,
const char *subq_marker)
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((int)d0 > 0);
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
assert((int)d_value > 0);
int boff = find_be16(b, blen, get_be16(subq_marker));
int boff = find_be16(b, blen, get_be16(subq_marker));
if (boff < 0)
throwBadLoader();
unsigned char *p = (unsigned char *)b + boff;
if (p[2] == 0x66) // bne.b XXX
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 (d0 > 65536)
if (d_value > 65536)
{
set_be16(p, 0x5380); // subq.l #1,d0
set_be16(p, OP_SUBQ_L(1, d_reg)); // subq.l #1,d0
}
else
{
if (p[2] == 0x66) // bne.b XXX
if (p[2] == 0x66) // bne.b XXX
{
set_be16(p, 0x51c8); // dbra d0,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
d0 -= 1;
d_value -= 1;
}
else
{
set_be16(p, 0x5340); // subq.w #1,d0
set_be16(p, OP_SUBQ_W(1, d_reg)); // subq.w #1,d0
}
d0 &= 0xffff;
d_value &= 0xffff;
}
return d0;
return d_value;
}
unsigned PackTos::patch_d0_loop(void *b, int blen, unsigned d0,
const char *d0_marker, const char *subq_marker)
unsigned PackTos::patch_d_loop(void *b, int blen,
int d_reg, unsigned d_value,
const char *d_marker, const char *subq_marker)
{
d0 = patch_d0_subq(b, blen, d0, subq_marker);
d_value = patch_d_subq(b, blen, d_reg, d_value, subq_marker);
int boff = find_be32(b, blen, get_be32(d0_marker));
int boff = find_be32(b, blen, get_be32(d_marker));
checkPatch(b, blen, boff, 4);
unsigned char *p = (unsigned char *)b + boff;
assert(get_be16(p - 2) == 0x203c); // move.l #XXXXXXXX,d0
set_be32(p, d0);
return d0;
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;
}
@@ -262,7 +325,7 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
return -1;
if (i >= rsize) // premature EOF in relocs
return -1;
int c = relocs[i++];
unsigned c = relocs[i++];
if (c == 0) // end marker
break;
else if (c == 1) // increase fixup, no reloc
@@ -291,18 +354,30 @@ 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;
unsigned char buf[512];
fi->readx(buf,sizeof(buf));
if (find_le32(buf,sizeof(buf),UPX_MAGIC_LE32) >= 0)
throwAlreadyPacked();
unsigned char buf[768];
fi->readx(buf, sizeof(buf));
checkAlreadyPacked(buf, sizeof(buf));
if (!checkFileHeader())
throwCantPack("unsupported header flags");
if (file_size < 256)
throwCantPack("program too small");
if (file_size < 1024)
throwCantPack("program is too small");
return true;
}
@@ -329,13 +404,6 @@ void PackTos::pack(OutputFile *fo)
unsigned relocsize = 0;
unsigned overlay = 0;
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);
const unsigned i_text = ih.fh_text;
const unsigned i_data = ih.fh_data;
const unsigned i_sym = ih.fh_sym;
@@ -360,7 +428,7 @@ void PackTos::pack(OutputFile *fo)
printf("xx1 reloc: %d, overlay: %d, fixup: %d\n", relocsize, overlay, overlay >= 4 ? (int)get_be32(ibuf+t) : -1);
#endif
// Check relocs (see load_and_reloc() in mint/src/mem.c).
// 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)
@@ -404,17 +472,26 @@ 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
obuf.allocForCompression(t + d_len + 512);
// alloc buffer (2048 is for decompressor and the various alignments)
obuf.allocForCompression(t, 2048);
// compress (max_match = 65535)
// prepare packheader
ph.u_len = t;
if (!compress(ibuf,obuf,0,65535))
throwNotCompressible();
// prepare filter
Filter ft(ph.level);
// compress (max_match = 65535)
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
// 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);
// The decompressed data will now get placed at this offset:
const unsigned overlapoh = findOverlapOverhead(obuf, 512);
unsigned offset = (ph.u_len + overlapoh) - ph.c_len;
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
// compute addresses
unsigned o_text, o_data, o_bss;
@@ -456,8 +533,8 @@ void PackTos::pack(OutputFile *fo)
while (dirty_bss & (dirty_bss_align - 1))
dirty_bss++;
// adjust bss, assert room for some stack
if (dirty_bss + 256 > o_bss)
o_bss = dirty_bss + 256;
if (dirty_bss + 512 > o_bss)
o_bss = dirty_bss + 512;
// dword align the len of the final bss segment
while (o_bss & 3)
@@ -465,18 +542,20 @@ void PackTos::pack(OutputFile *fo)
// prepare loader
MemBuffer loader(o_text);
memcpy(loader,getLoader(),o_text);
memcpy(loader, getLoader(), o_text);
// patch loader
patchPackHeader(loader,o_text);
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,d0" or "subq.w #1,d0" - see "up41" below
const unsigned dirty_bss_d0 =
patch_d0_subq(loader, o_text, dirty_bss / dirty_bss_align, "u4");
patch_be32(loader,o_text,"up31",d_off + offset + decomp_offset);
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_d0_loop(loader,o_text,o_data/4,"up22","u1");
patch_d_loop(loader, o_text, REG_D0, o_data/4, "up22", "u1");
else
{
if (o_data <= 160)
@@ -488,8 +567,8 @@ void PackTos::pack(OutputFile *fo)
loop1--;
loop2 = 160;
}
patch_be16(loader,o_text,"u2", 0x7000 + loop2/4-1); // moveq.l #X,d0
patch_d0_loop(loader,o_text,loop1,"up22","u1");
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
@@ -498,13 +577,13 @@ void PackTos::pack(OutputFile *fo)
// patch decompressor
upx_byte *p = obuf + d_off;
// patch "moveq.l #1,d3" or "jmp (a5)"
patch_be16(p,d_len,"u3", (nrelocs > 0) ? 0x7601 : 0x4ed5);
patch_be32(p,d_len,"up41", dirty_bss_d0);
// 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);
// set new file_hdr
memcpy(&oh, &ih, FH_SIZE);
if (opt->tos.split_segments)
if (opt->atari_tos.split_segments)
{
oh.fh_text = o_text;
oh.fh_data = o_data;
@@ -539,7 +618,7 @@ void PackTos::pack(OutputFile *fo)
fo->write("\x00\x00\x00\x00",4);
// verify
verifyOverlappingDecompression(&obuf, overlapoh);
verifyOverlappingDecompression();
// copy the overlay
copyOverlay(fo, overlay, &obuf);
@@ -558,12 +637,13 @@ int PackTos::canUnpack()
{
if (!readFileHeader())
return false;
if (!readPackHeader(512))
if (!readPackHeader(768))
return false;
// check header as set by packer
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0
|| ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1)
throwCantUnpack("program header damaged");
// generic check
if (!checkFileHeader())
throwCantUnpack("unsupported header flags");
return true;
@@ -579,8 +659,8 @@ void PackTos::unpack(OutputFile *fo)
ibuf.alloc(ph.c_len);
obuf.allocForUncompression(ph.u_len);
fi->seek(ph.buf_offset + ph.getPackHeaderSize(),SEEK_SET);
fi->readx(ibuf,ph.c_len);
fi->seek(FH_SIZE + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
fi->readx(ibuf, ph.c_len);
// decompress
decompress(ibuf,obuf);
+14 -11
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -39,10 +39,10 @@ class PackTos : public Packer
typedef Packer super;
public:
PackTos(InputFile *f);
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_ATARI_TOS; }
virtual const char *getName() const { return "atari/tos"; }
virtual int getCompressionMethod() const;
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo);
@@ -57,8 +57,8 @@ protected:
virtual const upx_byte *getLoader() const;
virtual int getLoaderSize() const;
bool readFileHeader();
bool checkFileHeader();
virtual int readFileHeader();
virtual bool checkFileHeader();
struct tos_header_t
{
@@ -70,11 +70,14 @@ protected:
BE32 fh_reserved;
BE32 fh_flag;
BE16 fh_reloc;
} ih, oh;
}
__attribute_packed;
tos_header_t ih, oh;
protected:
unsigned patch_d0_subq(void *b, int blen, unsigned, const char*);
unsigned patch_d0_loop(void *b, int blen, unsigned, const char*, const char*);
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*);
};
+411 -295
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,14 +21,15 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
#include "conf.h"
#include "file.h"
#include "filter.h"
#include "packer.h"
#include "p_unix.h"
#include "p_elf.h"
@@ -44,10 +45,11 @@
PackUnix::PackUnix(InputFile *f) :
super(f), exetype(0), blocksize(0), overlay_offset(0), lsize(0)
{
assert(sizeof(Elf_LE32_Ehdr) == 52);
assert(sizeof(Elf_LE32_Phdr) == 32);
assert(sizeof(l_info) == 12);
assert(sizeof(p_info) == 12);
COMPILE_TIME_ASSERT(sizeof(Elf32_Ehdr) == 52);
COMPILE_TIME_ASSERT(sizeof(Elf32_Phdr) == 32);
COMPILE_TIME_ASSERT(sizeof(b_info) == 12);
COMPILE_TIME_ASSERT(sizeof(l_info) == 12);
COMPILE_TIME_ASSERT(sizeof(p_info) == 12);
}
@@ -67,15 +69,34 @@ bool PackUnix::canPack()
// info: currently the header is 36 (32+4) bytes before EOF
unsigned char buf[256];
fi->seek(-(long)sizeof(buf), SEEK_END);
fi->readx(buf,sizeof(buf));
if (find_le32(buf,sizeof(buf),UPX_MAGIC_LE32) >= 0) // note: always le32
throwAlreadyPacked();
fi->seek(-(off_t)sizeof(buf), SEEK_END);
fi->readx(buf, sizeof(buf));
checkAlreadyPacked(buf, sizeof(buf));
return true;
}
void PackUnix::writePackHeader(OutputFile *fo)
{
unsigned char buf[32];
memset(buf, 0, sizeof(buf));
const int hsize = ph.getPackHeaderSize();
assert((unsigned)hsize <= sizeof(buf));
// note: magic constants are always le32
set_le32(buf+0, UPX_MAGIC_LE32);
set_le32(buf+4, UPX_MAGIC2_LE32);
checkPatch(NULL, 0, 0, 0); // reset
patchPackHeader(buf, hsize);
checkPatch(NULL, 0, 0, 0); // reset
fo->write(buf, hsize);
}
/*************************************************************************
// Generic Unix pack(). Subclasses must provide patchLoader().
//
@@ -94,107 +115,183 @@ bool PackUnix::checkCompressionRatio(unsigned, unsigned) const
return true;
}
void PackUnix::pack(OutputFile *fo)
void PackUnix::pack1(OutputFile * /*fo*/, Filter & /*ft*/)
{
// set options
blocksize = opt->unix.blocksize;
if (blocksize <= 0)
blocksize = BLOCKSIZE;
if ((off_t)blocksize > file_size)
blocksize = file_size;
// create a pseudo-unique program id for our paranoid stub
progid = getRandomId();
// derived class usually provides this
}
// prepare loader
lsize = getLoaderSize();
loader.alloc(lsize + sizeof(p_info));
memcpy(loader,getLoader(),lsize);
int PackUnix::getStrategy(Filter &/*ft*/)
{
// Called just before reading and compressing each block.
// Might want to adjust blocksize, etc.
// patch loader, prepare header info
patchLoader(); // can change lsize by packing C-code of upx_main etc.
p_info *const hbuf = (p_info *)(loader + lsize);
set_native32(&hbuf->p_progid, progid);
set_native32(&hbuf->p_filesize, file_size);
set_native32(&hbuf->p_blocksize, blocksize);
fo->write(loader, lsize + sizeof(p_info));
// init compression buffers
ibuf.alloc(blocksize);
obuf.allocForCompression(blocksize);
// If user specified the filter, then use it (-2==strategy).
// Else try the first two filters, and pick the better (2==strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
}
void PackUnix::pack2(OutputFile *fo, Filter &ft)
{
// compress blocks
unsigned total_in = 0;
unsigned total_out = 0;
ui_total_passes = (file_size + blocksize - 1) / blocksize;
if (ui_total_passes == 1)
ui_total_passes = 0;
fi->seek(0, SEEK_SET);
for (;;)
// FIXME: ui_total_passes is not correct with multiple blocks...
// ui_total_passes = (file_size + blocksize - 1) / blocksize;
// if (ui_total_passes == 1)
// ui_total_passes = 0;
unsigned remaining = file_size;
while (remaining > 0)
{
int l = fi->read(ibuf, blocksize);
if (l == 0)
break;
// FIXME: disable filters if we have more than one block.
// FIXME: There is only 1 un-filter in the stub [as of 2002-11-10].
// So the next block really has no choice!
// This merely prevents an assert() in compressWithFilters(),
// 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);
if (file_size > (off_t)blocksize)
strategy = -3; // no filters
int l = fi->readx(ibuf, UPX_MIN(blocksize, remaining));
remaining -= l;
// Note: compression for a block can fail if the
// file is e.g. blocksize + 1 bytes long
// compress
ph.u_len = l;
(void) compress(ibuf, obuf); // ignore return value
ph.overlap_overhead = 0;
ph.c_len = ph.u_len = l;
ft.buf_len = l;
if (ph.c_len < ph.u_len)
{
if (!testOverlappingDecompression(obuf, OVERHEAD))
throwNotCompressible();
// compressWithFilters() updates u_adler _inside_ compress();
// 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);
if (ph.c_len < ph.u_len) {
ph.overlap_overhead = OVERHEAD;
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
// not in-place compressible
ph.c_len = ph.u_len;
}
}
else
{
if (ph.c_len >= ph.u_len) {
// block is not compressible
ph.c_len = ph.u_len;
// must manually update checksum of compressed data
ph.c_adler = upx_adler32(ph.c_adler, ibuf, ph.u_len);
ph.c_adler = upx_adler32(ibuf, ph.u_len, ph.saved_c_adler);
}
// write block sizes
unsigned char size[8];
set_native32(size+0, ph.u_len);
set_native32(size+4, ph.c_len);
fo->write(size, 8);
// write block header
b_info blk_info;
memset(&blk_info, 0, sizeof(blk_info));
set_native32(&blk_info.sz_unc, ph.u_len);
set_native32(&blk_info.sz_cpr, ph.c_len);
if (ph.c_len < ph.u_len) {
blk_info.b_method = (unsigned char) ph.method;
blk_info.b_ftid = (unsigned char) ph.filter;
blk_info.b_cto8 = (unsigned char) ph.filter_cto;
}
fo->write(&blk_info, sizeof(blk_info));
b_len += sizeof(b_info);
// write compressed data
if (ph.c_len < ph.u_len)
{
if (ph.c_len < ph.u_len) {
fo->write(obuf, ph.c_len);
verifyOverlappingDecompression(&obuf, OVERHEAD);
verifyOverlappingDecompression(); // uses ph.u_adler
}
else
else {
fo->write(ibuf, ph.u_len);
}
ph.u_adler = end_u_adler;
total_in += ph.u_len;
total_out += ph.c_len;
}
if ((off_t)total_in != file_size)
throwEOFException();
// write block end marker (uncompressed size 0)
fo->write("\x00\x00\x00\x00", 4);
// update header with totals
ph.u_len = total_in;
ph.c_len = total_out;
// write packheader
const int hsize = ph.getPackHeaderSize();
set_le32(obuf, ph.magic); // note: always le32
patchPackHeader(obuf, hsize);
fo->write(obuf, hsize);
if ((off_t)total_in != file_size) {
throwEOFException();
}
}
// write overlay offset (needed for decompression)
set_native32(obuf, lsize);
fo->write(obuf, 4);
void
PackUnix::patchLoaderChecksum()
{
unsigned char *const ptr = const_cast<unsigned char *>(getLoader());
l_info *const lp = &linfo;
// checksum for loader; also some PackHeader info
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
lp->l_lsize = (unsigned short) lsize;
lp->l_version = (unsigned char) ph.version;
lp->l_format = (unsigned char) ph.format;
// INFO: lp->l_checksum is currently unused
lp->l_checksum = upx_adler32(ptr, lsize);
}
void PackUnix::pack3(OutputFile *fo, Filter &ft)
{
upx_byte const *p = getLoader();
lsize = getLoaderSize();
patchFilter32(const_cast<upx_byte *>(p), lsize, &ft);
updateLoader(fo);
patchLoaderChecksum();
fo->write(p, lsize);
}
void PackUnix::pack4(OutputFile *fo, Filter &)
{
writePackHeader(fo);
unsigned tmp;
set_native32(&tmp, overlay_offset);
fo->write(&tmp, sizeof(tmp));
}
void PackUnix::pack(OutputFile *fo)
{
Filter ft(ph.level);
ft.addvalue = 0;
b_len = 0;
progid = 0;
// set options
blocksize = opt->o_unix.blocksize;
if (blocksize <= 0)
blocksize = BLOCKSIZE;
if ((off_t)blocksize > file_size)
blocksize = file_size;
// init compression buffers
ibuf.alloc(blocksize);
obuf.allocForCompression(blocksize);
fi->seek(0, SEEK_SET);
pack1(fo, ft); // generate Elf header, etc.
p_info hbuf;
set_native32(&hbuf.p_progid, progid);
set_native32(&hbuf.p_filesize, file_size);
set_native32(&hbuf.p_blocksize, blocksize);
fo->write(&hbuf, sizeof(hbuf));
pack2(fo, ft); // append the compressed body
// write block end marker (uncompressed size 0)
b_info hdr; memset(&hdr, 0, sizeof(hdr));
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
fo->write(&hdr, sizeof(hdr));
pack3(fo, ft); // append loader
pack4(fo, ft); // append PackHeader and overlay_offset; update Elf header
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
@@ -202,6 +299,197 @@ void PackUnix::pack(OutputFile *fo)
}
void PackUnix::packExtent(
const Extent &x,
unsigned &total_in,
unsigned &total_out,
Filter *ft,
OutputFile *fo,
unsigned hdr_ulen
)
{
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);
fi->seek(0, SEEK_SET);
int l = fi->readx(hdr_ibuf, hdr_ulen);
(void)l;
}
fi->seek(x.offset, SEEK_SET);
for (off_t rest = x.size; 0 != rest; ) {
int const strategy = getStrategy(*ft);
int l = fi->readx(ibuf, UPX_MIN(rest, (off_t)blocksize));
if (l == 0) {
break;
}
rest -= l;
// Note: compression for a block can fail if the
// file is e.g. blocksize + 1 bytes long
// compress
ph.c_len = ph.u_len = l;
ph.overlap_overhead = 0;
unsigned end_u_adler = 0;
if (ft) {
// compressWithFilters() updates u_adler _inside_ compress();
// that is, AFTER filtering. We want BEFORE filtering,
// so that decompression checks the end-to-end checksum.
end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler);
ft->buf_len = l;
// compressWithFilters() requirements?
ph.filter = 0;
ph.filter_cto = 0;
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);
}
else {
(void) compress(ibuf, obuf); // ignore return value
}
if (ph.c_len < ph.u_len) {
ph.overlap_overhead = OVERHEAD;
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
// not in-place compressible
ph.c_len = ph.u_len;
}
}
if (ph.c_len >= ph.u_len) {
// block is not compressible
ph.c_len = ph.u_len;
memcpy(obuf, ibuf, ph.c_len);
// must update checksum of compressed data
ph.c_adler = upx_adler32(ibuf, ph.u_len, ph.saved_c_adler);
}
// write block sizes
b_info tmp;
if (hdr_ulen) {
unsigned hdr_clen;
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);
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);
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
}
memset(&tmp, 0, sizeof(tmp));
set_native32(&tmp.sz_unc, ph.u_len);
set_native32(&tmp.sz_cpr, ph.c_len);
if (ph.c_len < ph.u_len) {
tmp.b_method = (unsigned char) ph.method;
if (ft) {
tmp.b_ftid = (unsigned char) ft->id;
tmp.b_cto8 = ft->cto;
}
}
fo->write(&tmp, sizeof(tmp));
b_len += sizeof(b_info);
// write compressed data
if (ph.c_len < ph.u_len) {
fo->write(obuf, ph.c_len);
// Checks ph.u_adler after decompression, after unfiltering
verifyOverlappingDecompression(ft);
}
else {
fo->write(ibuf, ph.u_len);
}
if (ft) {
ph.u_adler = end_u_adler;
}
total_in += ph.u_len;
total_out += ph.c_len;
}
}
void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
unsigned &total_in, unsigned &total_out,
unsigned &c_adler, unsigned &u_adler,
bool first_PF_X, unsigned szb_info
)
{
b_info hdr; memset(&hdr, 0, sizeof(hdr));
while (wanted) {
fi->readx(&hdr, szb_info);
int const sz_unc = ph.u_len = get_native32(&hdr.sz_unc);
int const sz_cpr = ph.c_len = get_native32(&hdr.sz_cpr);
ph.filter_cto = hdr.b_cto8;
if (sz_unc == 0) { // must never happen while 0!=wanted
throwCompressedDataViolation();
break;
}
if (sz_unc <= 0 || sz_cpr <= 0)
throwCompressedDataViolation();
if (sz_cpr > sz_unc || sz_unc > (int)blocksize)
throwCompressedDataViolation();
int j = blocksize + OVERHEAD - sz_cpr;
fi->readx(ibuf+j, sz_cpr);
// update checksum of compressed data
c_adler = upx_adler32(ibuf + j, sz_cpr, c_adler);
// decompress
if (sz_cpr < sz_unc)
{
decompress(ibuf+j, ibuf, false);
if (12==szb_info) { // modern per-block filter
if (hdr.b_ftid) {
Filter ft(ph.level); // FIXME: ph.level for b_info?
ft.init(hdr.b_ftid, 0);
ft.cto = hdr.b_cto8;
ft.unfilter(ibuf, sz_unc);
}
}
else { // ancient per-file filter
if (first_PF_X) { // Elf32_Ehdr is never filtered
first_PF_X = false; // but everything else might be
}
else if (ph.filter) {
Filter ft(ph.level);
ft.init(ph.filter, 0);
ft.cto = (unsigned char) ph.filter_cto;
ft.unfilter(ibuf, sz_unc);
}
}
j = 0;
}
// update checksum of uncompressed data
u_adler = upx_adler32(ibuf + j, sz_unc, u_adler);
total_in += sz_cpr;
total_out += sz_unc;
// write block
if (fo)
fo->write(ibuf + j, sz_unc);
wanted -= sz_unc;
}
}
/*************************************************************************
// Generic Unix canUnpack().
**************************************************************************/
@@ -236,8 +524,28 @@ int PackUnix::canUnpack()
void PackUnix::unpack(OutputFile *fo)
{
unsigned c_adler = upx_adler32(0, NULL, 0);
unsigned u_adler = upx_adler32(0, NULL, 0);
unsigned szb_info = sizeof(b_info);
{
Elf32_Ehdr ehdr;
fi->seek(0, SEEK_SET);
fi->readx(&ehdr, sizeof(ehdr));
unsigned const e_entry = get_native32(&ehdr.e_entry);
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
szb_info = 2*sizeof(unsigned);
}
else {
Elf32_Phdr phdr;
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
fi->readx(&phdr, sizeof(phdr));
unsigned const p_vaddr = get_native32(&phdr.p_vaddr);
if (0x80==(e_entry - p_vaddr)) { /* 1.22 old style */
szb_info = 2*sizeof(unsigned);
}
}
}
unsigned c_adler = upx_adler32(NULL, 0);
unsigned u_adler = upx_adler32(NULL, 0);
// defaults for ph.version == 8
unsigned orig_file_size = 0;
@@ -265,46 +573,52 @@ void PackUnix::unpack(OutputFile *fo)
// decompress blocks
unsigned total_in = 0;
unsigned total_out = 0;
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
for (;;)
{
#define buf ibuf
int i;
int size[2];
unsigned sz_unc, sz_cpr;
fi->readx(buf, 8);
ph.u_len = size[0] = get_native32(buf+0);
ph.c_len = size[1] = get_native32(buf+4);
fi->readx(&bhdr, szb_info);
ph.u_len = sz_unc = get_native32(&bhdr.sz_unc);
ph.c_len = sz_cpr = get_native32(&bhdr.sz_cpr);
if (size[0] == 0) // uncompressed size 0 -> EOF
if (sz_unc == 0) // uncompressed size 0 -> EOF
{
// note: must reload size[1] as magic is always stored le32
size[1] = get_le32(buf+4);
if (size[1] != UPX_MAGIC_LE32) // size[1] must be h->magic
// note: must reload sz_cpr as magic is always stored le32
sz_cpr = get_le32(&bhdr.sz_cpr);
if (sz_cpr != UPX_MAGIC_LE32) // sz_cpr must be h->magic
throwCompressedDataViolation();
break;
}
if (size[0] <= 0 || size[1] <= 0)
if (sz_unc <= 0 || sz_cpr <= 0)
throwCompressedDataViolation();
if (size[1] > size[0] || size[0] > (int)blocksize)
if (sz_cpr > sz_unc || sz_unc > blocksize)
throwCompressedDataViolation();
i = blocksize + OVERHEAD - size[1];
fi->readx(buf+i, size[1]);
i = blocksize + OVERHEAD - sz_cpr;
fi->readx(buf+i, sz_cpr);
// update checksum of compressed data
c_adler = upx_adler32(c_adler, buf + i, size[1]);
c_adler = upx_adler32(buf + i, sz_cpr, c_adler);
// decompress
if (size[1] < size[0])
{
if (sz_cpr < sz_unc) {
decompress(buf+i, buf, false);
if (0!=bhdr.b_ftid) {
Filter ft(ph.level);
ft.init(bhdr.b_ftid);
ft.cto = bhdr.b_cto8;
ft.unfilter(buf, sz_unc);
}
i = 0;
}
// update checksum of uncompressed data
u_adler = upx_adler32(u_adler, buf + i, size[0]);
total_in += size[1];
total_out += size[0];
u_adler = upx_adler32(buf + i, sz_unc, u_adler);
total_in += sz_cpr;
total_out += sz_unc;
// write block
if (fo)
fo->write(buf + i, size[0]);
fo->write(buf + i, sz_unc);
#undef buf
}
@@ -322,204 +636,6 @@ void PackUnix::unpack(OutputFile *fo)
}
/*************************************************************************
// linux/i386 (generic "execve" format)
**************************************************************************/
static const
#include "stub/l_lx_n2b.h"
static const
#include "stub/l_lx_n2d.h"
int PackLinuxI386::getCompressionMethod() const
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_LE32;
if (M_IS_NRV2D(opt->method))
return M_NRV2D_LE32;
return opt->level > 1 && file_size >= 512*1024 ? M_NRV2D_LE32 : M_NRV2B_LE32;
}
const upx_byte *PackLinuxI386::getLoader() const
{
if (M_IS_NRV2B(opt->method))
return linux_i386exec_nrv2b_loader;
if (M_IS_NRV2D(opt->method))
return linux_i386exec_nrv2d_loader;
return NULL;
}
int PackLinuxI386::getLoaderSize() const
{
if (0!=lsize) {
return lsize;
}
if (M_IS_NRV2B(opt->method))
return sizeof(linux_i386exec_nrv2b_loader);
if (M_IS_NRV2D(opt->method))
return sizeof(linux_i386exec_nrv2d_loader);
return 0;
}
int PackLinuxI386::getLoaderPrefixSize() const
{
return 116;
}
bool PackLinuxI386::canPack()
{
if (exetype != 0)
return super::canPack();
Elf_LE32_Ehdr ehdr;
unsigned char *buf = ehdr.e_ident;
fi->readx(&ehdr, sizeof(ehdr));
fi->seek(0, SEEK_SET);
exetype = 0;
const unsigned l = get_le32(buf);
#if 0
// NOTE: ELF executables are now handled by p_lx_elf.cpp.
if (!memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB
{
// FIXME: add special checks for uncompresed "vmlinux" kernel
exetype = 1;
// now check the ELF header
if (!memcmp(buf+8, "FreeBSD", 7)) // branded
exetype = 0;
if (ehdr.e_type != 2) // executable
exetype = 0;
if (ehdr.e_machine != 3 && ehdr.e_machine != 6) // Intel 80[34]86
exetype = 0;
if (ehdr.e_version != 1) // version
exetype = 0;
}
else
#endif
if (l == 0x00640107 || l == 0x00640108 || l == 0x0064010b || l == 0x006400cc)
{
// OMAGIC / NMAGIC / ZMAGIC / QMAGIC
exetype = 2;
// 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
return super::canPack();
}
void PackLinuxI386::patchLoader()
{
lsize = getLoaderSize();
// patch loader
// note: we only can use /proc/<pid>/fd when exetype > 0.
// also, we sleep much longer when compressing a script.
patch_le32(loader,lsize,"UPX4",exetype > 0 ? 3 : 15); // sleep time
patch_le32(loader,lsize,"UPX3",exetype > 0 ? 0 : 0x7fffffff);
patch_le32(loader,lsize,"UPX2",progid);
patchVersion(loader,lsize);
Elf_LE32_Ehdr *const ehdr = (Elf_LE32_Ehdr *)(void *)loader;
Elf_LE32_Phdr *const phdr = (Elf_LE32_Phdr *)(1+ehdr);
// stub/scripts/setfold.pl puts address of 'fold_begin' in phdr[1].p_offset
off_t const fold_begin = phdr[1].p_offset;
assert(fold_begin > 0);
assert(fold_begin < (off_t)lsize);
MemBuffer cprLoader(lsize);
// compress compiled C-code portion of loader
upx_compress_config_t conf; memset(&conf, 0xff, sizeof(conf));
conf.c_flags = 0;
upx_uint result_buffer[16];
upx_uint const uncLsize = lsize - fold_begin;
upx_uint cprLsize;
upx_compress(
loader + fold_begin, uncLsize,
cprLoader, &cprLsize,
0, // progress_callback_t ??
getCompressionMethod(), 9,
&conf,
result_buffer
);
memcpy(fold_begin+loader, cprLoader, cprLsize);
lsize = fold_begin + cprLsize;
phdr->p_filesz = lsize;
// phdr->p_memsz is the decompressed size
// The beginning of our loader consists of a elf_hdr (52 bytes) and
// one section elf_phdr (32 byte) now,
// another section elf_phdr (32 byte) later, so we have 12 free bytes
// from offset 116 to the program start at offset 128.
// These 12 bytes are used for l_info by ::patchLoaderChecksum().
assert(get_le32(loader + 28) == 52); // e_phoff
assert(get_le32(loader + 32) == 0); // e_shoff
assert(get_le16(loader + 40) == 52); // e_ehsize
assert(get_le16(loader + 42) == 32); // e_phentsize
assert(get_le16(loader + 44) == 1); // e_phnum
assert(get_le16(loader + 48) == 0); // e_shnum
assert(lsize > 128 && lsize < 4096);
patchLoaderChecksum();
}
void PackLinuxI386::patchLoaderChecksum()
{
l_info *const lp = (l_info *)(loader + getLoaderPrefixSize());
// checksum for loader + p_info
lp->l_checksum = 0; // (this checksum is currently unused)
lp->l_magic = UPX_ELF_MAGIC;
lp->l_lsize = (unsigned short) lsize;
lp->l_version = (unsigned char) ph.version;
lp->l_format = (unsigned char) ph.format;
unsigned adler = upx_adler32(0,NULL,0);
adler = upx_adler32(adler, loader, lsize + sizeof(p_info));
lp->l_checksum = adler;
}
void PackLinuxI386::updateLoader(OutputFile *fo)
{
#define PAGE_MASK (~0<<12)
Elf_LE32_Ehdr *ehdr = (Elf_LE32_Ehdr *)(unsigned char *)loader;
ehdr->e_phnum = 2;
// The first Phdr maps the stub (instructions, data, bss) rwx.
// The second Phdr maps the overlay r--,
// to defend against /usr/bin/strip removing the overlay.
Elf_LE32_Phdr *const phdro = 1+(Elf_LE32_Phdr *)(1+ehdr);
phdro->p_type = PT_LOAD;
phdro->p_offset = lsize;
phdro->p_paddr = phdro->p_vaddr = 0x00400000 + (lsize &~ PAGE_MASK);
phdro->p_memsz = phdro->p_filesz = fo->getBytesWritten() - lsize;
phdro->p_flags = PF_R;
phdro->p_align = -PAGE_MASK;
patchLoaderChecksum();
fo->seek(0, SEEK_SET);
fo->rewrite(loader, 0x80);
#undef PAGE_MASK
}
/*
vi:ts=4:et
*/
+115 -52
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
@@ -41,8 +41,9 @@ class PackUnix : public Packer
protected:
PackUnix(InputFile *f);
public:
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 13; }
virtual const int *getFilters() const { return NULL; }
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
@@ -52,17 +53,41 @@ public:
protected:
// called by the generic pack()
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 PackHeader
virtual void patchLoader() = 0;
virtual void patchLoaderChecksum() {}
virtual void patchLoaderChecksum();
virtual void updateLoader(OutputFile *) = 0;
virtual void writePackHeader(OutputFile *fo);
// in order too share as much code as possible we introduce
// an endian abstraction here
virtual unsigned get_native32(const void *, int off=0) = 0;
virtual void set_native32(void *, unsigned, int off=0) = 0;
virtual acc_uint64l_t get_native64(const void *) const = 0;
virtual unsigned get_native32(const void *) const = 0;
virtual unsigned get_native16(const void *) const = 0;
virtual void set_native64(void *, acc_uint64l_t) const = 0;
virtual void set_native32(void *, unsigned) const = 0;
virtual void set_native16(void *, unsigned) const = 0;
virtual bool checkCompressionRatio(unsigned, unsigned) const;
protected:
struct Extent {
off_t offset;
off_t size;
};
virtual void packExtent(const Extent &x,
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *,
unsigned hdr_len = 0);
virtual void unpackExtent(unsigned wanted, OutputFile *fo,
unsigned &total_in, unsigned &total_out,
unsigned &c_adler, unsigned &u_adler,
bool first_PF_X, unsigned szb_info );
int exetype;
unsigned blocksize;
unsigned progid; // program id
@@ -70,19 +95,38 @@ protected:
MemBuffer loader;
int lsize;
MemBuffer pt_dynamic;
int sz_dynamic;
unsigned b_len; // total length of b_info blocks
// must agree with stub/linux.hh
struct b_info { // 12-byte header before each compressed block
unsigned sz_unc; // uncompressed_size
unsigned sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter
unsigned char b_unused;
}
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader
unsigned l_checksum;
unsigned l_magic;
unsigned short l_lsize;
unsigned char l_version;
unsigned char l_format;
};
}
__attribute_packed;
struct p_info { // 12-byte packed program header
unsigned p_progid;
unsigned p_filesize;
unsigned p_blocksize;
};
}
__attribute_packed;
struct l_info linfo;
// do not change !!!
enum { OVERHEAD = 2048 };
@@ -93,20 +137,44 @@ protected:
// abstract classes encapsulating endian issues
// note: UPX_MAGIC is always stored in le32 format
**************************************************************************/
class PackUnixBe32 : public PackUnix
{
typedef PackUnix super;
protected:
PackUnixBe32(InputFile *f) : super(f) { }
virtual unsigned get_native32(const void * b, int off=0)
{
return get_be32(b, off);
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
// must agree with stub/linux.hh
struct b_info { // 12-byte header before each compressed block
BE32 sz_unc; // uncompressed_size
BE32 sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter
unsigned char b_unused;
}
virtual void set_native32(void * b, unsigned v, int off=0)
{
set_be32(b, v, off);
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader
BE32 l_checksum;
BE32 l_magic;
BE16 l_lsize;
unsigned char l_version;
unsigned char l_format;
}
__attribute_packed;
struct p_info { // 12-byte packed program header
BE32 p_progid;
BE32 p_filesize;
BE32 p_blocksize;
}
__attribute_packed;
};
@@ -115,44 +183,39 @@ class PackUnixLe32 : public PackUnix
typedef PackUnix super;
protected:
PackUnixLe32(InputFile *f) : super(f) { }
virtual unsigned get_native32(const void * b, int off=0)
{
return get_le32(b, off);
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
// must agree with stub/linux.hh
struct b_info { // 12-byte header before each compressed block
LE32 sz_unc; // uncompressed_size
LE32 sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter
unsigned char b_unused;
}
virtual void set_native32(void * b, unsigned v, int off=0)
{
set_le32(b, v, off);
__attribute_packed;
struct l_info { // 12-byte trailer in header for loader
LE32 l_checksum;
LE32 l_magic;
LE16 l_lsize;
unsigned char l_version;
unsigned char l_format;
}
};
__attribute_packed;
struct p_info { // 12-byte packed program header
LE32 p_progid;
LE32 p_filesize;
LE32 p_blocksize;
}
__attribute_packed;
/*************************************************************************
// linux/i386 (generic "execve" format)
**************************************************************************/
class PackLinuxI386 : public PackUnixLe32
{
typedef PackUnixLe32 super;
public:
PackLinuxI386(InputFile *f) : super(f) { }
virtual int getFormat() const { return UPX_F_LINUX_i386; }
virtual const char *getName() const { return "linux/386"; }
virtual int getCompressionMethod() const;
virtual bool canPack();
protected:
virtual const upx_byte *getLoader() const;
virtual int getLoaderSize() const;
virtual int getLoaderPrefixSize() const;
virtual void patchLoader();
virtual void patchLoaderChecksum();
virtual void updateLoader(OutputFile *);
enum {
UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
};
};
@@ -177,7 +240,7 @@ protected:
virtual void patchLoader();
};
#endif
#endif /* #if 0 */
#endif /* already included */
+622
View File
@@ -0,0 +1,622 @@
/* p_vmlinx.cpp -- pack vmlinux ET_EXEC file (before bootsect or setup)
This file is part of the UPX executable compressor.
Copyright (C) 2004 John Reiser
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 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
John Reiser
jreiser@users.sourceforge.net
*/
#include "conf.h"
#include "file.h"
#include "filter.h"
#include "packer.h"
#include "p_vmlinx.h"
static const
#include "stub/l_vmlinx.h"
/*************************************************************************
//
**************************************************************************/
PackVmlinuxI386::PackVmlinuxI386(InputFile *f) :
super(f), n_ptload(0), phdri(NULL), shdri(NULL)
{
}
PackVmlinuxI386::~PackVmlinuxI386()
{
delete [] phdri;
delete [] shdri;
}
const int *PackVmlinuxI386::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_le32(method, level);
}
const int *PackVmlinuxI386::getFilters() const
{
static const int filters[] = {
0x49,
-1 };
return filters;
}
static int __acc_cdecl_qsort
compare_Phdr(void const *aa, void const *bb)
{
Elf32_Phdr const *const a = (Elf32_Phdr const *)aa;
Elf32_Phdr const *const b = (Elf32_Phdr const *)bb;
unsigned const xa = a->p_type - Elf32_Phdr::PT_LOAD;
unsigned const xb = b->p_type - Elf32_Phdr::PT_LOAD;
if (xa < xb) return -1; // PT_LOAD first
if (xa > xb) return 1;
if (a->p_paddr < b->p_paddr) return -1; // ascending by .p_paddr
if (a->p_paddr > b->p_paddr) return 1;
return 0;
}
//
// Examples as of 2004-07-16 [readelf --segments vmlinux # before fiddling]:
//
//----- kernel-2.6.7 plain [defconfig?]
//Program Headers(2):
// Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
// LOAD 0x001000 0x00100000 0x00100000 0x1c7e61 0x1c7e61 R E 0x1000
// LOAD 0x1c8e64 0x002c8e64 0x002c8e64 0x00000 0x00000 RW 0x1000
//
//----- kernel-2.6.7-1.488 Fedora Core 3 test 1
//Program Headers(5):
// Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
// LOAD 0x001000 0x02100000 0x02100000 0x202246 0x202246 R E 0x1000
// LOAD 0x204000 0xffff3000 0x02303000 0x00664 0x00664 R E 0x1000
// LOAD 0x205000 0x02304000 0x02304000 0x43562 0x43562 R 0x1000
// LOAD 0x249000 0x02348000 0x02348000 0x81800 0xcb0fc RWE 0x1000
// STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
//
bool PackVmlinuxI386::canPack()
{
fi->seek(0, SEEK_SET);
fi->readx(&ehdri, sizeof(ehdri));
// now check the ELF header
if (memcmp(&ehdri, "\x7f\x45\x4c\x46\x01\x01\x01", 7) // ELF 32-bit LSB
|| !memcmp(&ehdri.e_ident[8], "FreeBSD", 7) // branded
|| ehdri.e_machine != 3 // Intel 80386
|| ehdri.e_version != 1 // version
)
return false;
// additional requirements for vmlinux
if (ehdri.e_ehsize != sizeof(ehdri) // different <elf.h> ?
|| ehdri.e_phoff != sizeof(ehdri) // Phdrs not contiguous with Ehdr
|| ehdri.e_phentsize!=sizeof(Elf32_Phdr)
|| ehdri.e_type!=Elf32_Ehdr::ET_EXEC
|| 0x00100000!=(0x001fffff & ehdri.e_entry) // entry not an odd 1MB
) {
return false;
}
phdri = new Elf32_Phdr[(unsigned) ehdri.e_phnum];
fi->seek(ehdri.e_phoff, SEEK_SET);
fi->readx(phdri, ehdri.e_phnum * sizeof(*phdri));
// Put PT_LOAD together at the beginning, ascending by .p_paddr.
qsort(phdri, ehdri.e_phnum, sizeof(*phdri), compare_Phdr);
// Check that PT_LOADs form one contiguous chunk of the file.
for (unsigned j = 0; j < ehdri.e_phnum; ++j) {
if (Elf32_Phdr::PT_LOAD==phdri[j].p_type) {
if (0xfff & (phdri[j].p_offset | phdri[j].p_paddr
| phdri[j].p_align | phdri[j].p_vaddr) ) {
return false;
}
if (0 < j) {
unsigned const sz = (0u - phdri[j-1].p_align)
& (phdri[j-1].p_align -1 + phdri[j-1].p_filesz);
if ((sz + phdri[j-1].p_offset)!=phdri[j].p_offset) {
return false;
}
}
++n_ptload;
sz_ptload = phdri[j].p_filesz + phdri[j].p_offset - phdri[0].p_offset;
}
}
return 0 < n_ptload;
}
int PackVmlinuxI386::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader, sizeof(nrv_loader));
addLoader("LINUX000",
(0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""),
"LXMOVEUP",
getDecompressor(),
NULL
);
if (ft->id)
{
assert(ft->calls > 0);
if (0x40==(0xf0 & ft->id)) {
addLoader("LXCKLLT9", NULL);
}
else {
addLoader("LXCALLT9", NULL);
}
addFilter32(ft->id);
}
addLoader("LINUX990,IDENTSTR,UPX1HEAD", NULL);
return getLoaderSize();
}
void PackVmlinuxI386::pack(OutputFile *fo)
{
unsigned fo_off = 0;
Elf32_Ehdr ehdro;
LE32 tmp_le32;
// NULL
// .text(PT_LOADs) .note(1st page) .note(rest)
// .shstrtab /* .symtab .strtab */
Elf32_Shdr shdro[1+3+1/*+2*/];
memset(shdro, 0, sizeof(shdro));
char const shstrtab[]= "\0.text\0.note\0.shstrtab\0.symtab\0.strtab";
char const *p = shstrtab;
ibuf.alloc(file_size);
obuf.allocForCompression(file_size);
// .e_ident, .e_machine, .e_version, .e_flags
memcpy(&ehdro, &ehdri, sizeof(ehdro));
ehdro.e_type = Elf32_Ehdr::ET_REL;
ehdro.e_entry = 0;
ehdro.e_phoff = 0;
ehdro.e_shoff = 0; // later
ehdro.e_phentsize = 0;
ehdro.e_phnum = 0;
ehdro.e_shnum = 1+3+1/*+2*/;
ehdro.e_shstrndx = 4;
fo->write(&ehdro, sizeof(ehdro)); fo_off+= sizeof(ehdro);
ph.u_len = sz_ptload;
fi->seek(phdri[0].p_offset, SEEK_SET);
fi->readx(ibuf, ph.u_len);
checkAlreadyPacked(ibuf + ph.u_len - 1024, 1024);
// prepare filter
ph.filter = 0;
Filter ft(ph.level);
ft.buf_len = ph.u_len;
ft.addvalue = 0; // we are independent of actual runtime address; see ckt32
compressWithFilters(&ft, 1 << 20);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
memcpy(loader, getLoader(), lsize);
patchPackHeader(loader, lsize);
patch_le32(loader, lsize, "ULEN", ph.u_len);
patchFilter32(loader, lsize, &ft);
while (0!=*p++) ;
shdro[1].sh_name = ptr_diff(p, shstrtab);
shdro[1].sh_type = Elf32_Shdr::SHT_PROGBITS;
shdro[1].sh_flags = Elf32_Shdr::SHF_ALLOC | Elf32_Shdr::SHF_EXECINSTR;
shdro[1].sh_offset = fo_off;
shdro[1].sh_size = 1+ 4+ ph.c_len + lsize;
shdro[1].sh_addralign = 1;
unsigned char const call = 0xE8; // opcode for CALL d32
fo->write(&call, 1); fo_off+=1;
tmp_le32 = ph.c_len; fo->write(&tmp_le32, 4); fo_off += 4;
fo->write(obuf, ph.c_len); fo_off += ph.c_len;
fo->write(loader, lsize); fo_off += lsize;
#if 0
printf("%-13s: compressed : %8u bytes\n", getName(), ph.c_len);
printf("%-13s: decompressor : %8u bytes\n", getName(), lsize);
#endif
verifyOverlappingDecompression();
// .note with 1st page --------------------------------
ph.u_len = phdri[0].p_offset;
fi->seek(0, SEEK_SET);
fi->readx(ibuf, ph.u_len);
compress(ibuf, obuf);
while (0!=*p++) ;
shdro[2].sh_name = ptr_diff(p, shstrtab);
shdro[2].sh_type = Elf32_Shdr::SHT_NOTE;
shdro[2].sh_offset = fo_off;
shdro[2].sh_size = sizeof(ph.u_len) + ph.c_len;
shdro[2].sh_addralign = 1;
tmp_le32 = ph.u_len; fo->write(&tmp_le32, 4);
fo->write(obuf, ph.c_len); fo_off += shdro[2].sh_size;
// .note with rest --------------------------------
ph.u_len = file_size - (sz_ptload + phdri[0].p_offset);
fi->seek(sz_ptload + phdri[0].p_offset, SEEK_SET);
fi->readx(ibuf, ph.u_len);
// Temporarily decrease ph.level by about (1+ log2(sz_rest / sz_ptload))
// to avoid spending unreasonable effort compressing large symbol tables
// that are discarded 99.9% of the time anyway.
int const old_level = ph.level;
for (unsigned v = ((ph.u_len>>3) + ph.u_len) / sz_ptload; 0 < v; v>>=1) {
if (0== --ph.level) {
ph.level = 1;
}
}
compress(ibuf, obuf);
ph.level = old_level;
// while (0!=*p++) ; // name is the same
shdro[3].sh_name = ptr_diff(p, shstrtab);
shdro[3].sh_type = Elf32_Shdr::SHT_NOTE;
shdro[3].sh_offset = fo_off;
shdro[3].sh_size = sizeof(ph.u_len) + ph.c_len;
shdro[3].sh_addralign = 1;
tmp_le32 = ph.u_len; fo->write(&tmp_le32, 4);
fo->write(obuf, ph.c_len); fo_off += shdro[3].sh_size;
while (0!=*p++) ;
shdro[4].sh_name = ptr_diff(p, shstrtab);
shdro[4].sh_type = Elf32_Shdr::SHT_STRTAB;
shdro[4].sh_offset = fo_off;
shdro[4].sh_size = 1+ sizeof(shstrtab); // 1+: terminating '\0'
shdro[4].sh_addralign = 1;
fo->write(shstrtab, shdro[4].sh_size); fo_off += shdro[4].sh_size;
#if 0 /*{ no symbols! */
while (0!=*p++) ;
fo_off = ~3 & (3+ fo_off);
shdro[5].sh_name = ptr_diff(p, shstrtab);
shdro[5].sh_type = Elf32_Shdr::SHT_SYMTAB;
shdro[5].sh_offset = fo_off;
shdro[5].sh_size = 16; // XXX ?
shdro[5].sh_link = 6; // to .strtab for symbols
shdro[5].sh_addralign = 4;
shdro[5].sh_entsize = 16; // XXX Elf32_Sym
fo->seek(fo_off, SEEK_SET);
fo->write("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16); fo_off += 16;
while (0!=*p++) ;
shdro[6].sh_name = ptr_diff(p, shstrtab);
shdro[6].sh_type = Elf32_Shdr::SHT_STRTAB;
shdro[6].sh_offset = fo_off;
shdro[6].sh_size = 1; // XXX ?
shdro[6].sh_addralign = 1;
fo->write("", 1); fo_off += 1;
#endif /*}*/
fo_off = ~3 & (3+ fo_off);
fo->seek(fo_off, SEEK_SET);
ehdro.e_shoff = fo_off;
fo->write(shdro, sizeof(shdro));
fo->seek(0, SEEK_SET);
fo->write(&ehdro, sizeof(ehdro));
if (!checkFinalCompressionRatio(fo))
throwNotCompressible();
}
/*************************************************************************
// unpack
**************************************************************************/
int PackVmlinuxI386::canUnpack()
{
fi->seek(0, SEEK_SET);
fi->readx(&ehdri, sizeof(ehdri));
// now check the ELF header
if (memcmp(&ehdri, "\x7f\x45\x4c\x46\x01\x01\x01", 7) // ELF 32-bit LSB
|| !memcmp(&ehdri.e_ident[8], "FreeBSD", 7) // branded
|| ehdri.e_machine != 3 // Intel 80386
|| ehdri.e_version != 1 // version
|| ehdri.e_type != Elf32_Ehdr::ET_REL
|| ehdri.e_shnum < 4
|| (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf32_Shdr) + ehdri.e_shoff)
)
return false;
// find the .shstrtab section
char shstrtab[40];
Elf32_Shdr *p, *p_shstrtab=0;
shdri = new Elf32_Shdr[(unsigned) ehdri.e_shnum];
fi->seek(ehdri.e_shoff, SEEK_SET);
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
int j;
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if (Elf32_Shdr::SHT_STRTAB==p->sh_type
&& p->sh_size <= sizeof(shstrtab)
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
) {
fi->seek(p->sh_offset, SEEK_SET);
fi->readx(shstrtab, p->sh_size);
if (0==strcmp(".shstrtab", shstrtab + p->sh_name)) {
p_shstrtab = p;
break;
}
}
}
if (0==p_shstrtab) {
return false;
}
// check for .text .note .note and sane (.sh_size + .sh_offset)
p_note0 = p_note1 = p_text = 0;
for (p= shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if ((unsigned)file_size < (p->sh_size + p->sh_offset)
|| p_shstrtab->sh_size < (5+ p->sh_name) ) {
continue;
}
if (0==strcmp(".text", shstrtab + p->sh_name)) {
p_text = p;
}
if (0==strcmp(".note", shstrtab + p->sh_name)) {
if (0==p_note0) {
p_note0 = p;
} else
if (0==p_note1) {
p_note1 = p;
}
}
}
if (0==p_text || 0==p_note0 || 0==p_note1) {
return false;
}
char buf[1024];
fi->seek(p_text->sh_offset + p_text->sh_size - sizeof(buf), SEEK_SET);
fi->readx(buf, sizeof(buf));
if (!getPackHeader(buf, sizeof(buf)))
return false;
return true;
}
void PackVmlinuxI386::unpack(OutputFile *fo)
{
unsigned char buf[5];
PackHeader const ph_tmp(ph);
fi->seek(p_note0->sh_offset, SEEK_SET);
fi->readx(&buf[0], 4);
ph.u_len = get_le32(buf);
ph.c_len = p_note0->sh_size - 4;
ibuf.alloc(ph.c_len);
fi->readx(ibuf, ph.c_len);
obuf.allocForUncompression(ph.u_len);
decompress(ibuf, obuf, false);
fo->write(obuf, ph.u_len);
obuf.dealloc();
ibuf.dealloc();
ph = ph_tmp;
fi->seek(p_text->sh_offset, SEEK_SET);
fi->readx(&buf[0], 5);
if (0xE8!=buf[0] || get_le32(&buf[1]) != ph.c_len)
{
throwCantUnpack(".text corrupted");
}
ibuf.alloc(ph.c_len);
fi->readx(ibuf, ph.c_len);
obuf.allocForUncompression(ph.u_len);
decompress(ibuf, obuf);
Filter ft(ph.level);
ft.init(ph.filter, 0);
ft.cto = (unsigned char) ph.filter_cto;
ft.unfilter(obuf, ph.u_len);
fo->write(obuf, ph.u_len);
obuf.dealloc();
ibuf.dealloc();
fi->seek(p_note1->sh_offset, SEEK_SET);
fi->readx(&buf[0], 4);
ph.u_len = get_le32(buf);
ph.c_len = p_note1->sh_size - 4;
ibuf.alloc(ph.c_len);
fi->readx(ibuf, p_note1->sh_size - sizeof(ph.u_len));
obuf.allocForUncompression(ph.u_len);
decompress(ibuf, obuf, false);
fo->write(obuf, ph.u_len);
obuf.dealloc();
ibuf.dealloc();
ph = ph_tmp;
}
//
// Example usage within build system of Linux kernel-2.6.7:
//
//----- arch/i386/boot/compressed/Makefile
//#
//# linux/arch/i386/boot/compressed/Makefile
//#
//# create a compressed vmlinux image from the original vmlinux
//#
//
//targets := vmlinux upx-head.o upx-piggy.o
//
//LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32
//
//$(obj)/vmlinux: $(obj)/upx-head.o $(obj)/upx-piggy.o FORCE
// $(call if_changed,ld)
// @:
//
//$(obj)/upx-piggy.o: vmlinux FORCE
// rm -f $@
// upx --best -o $@ $<
//-----
//
//----- arch/i386/boot/compressed/upx-head.S
// .text
//startup_32: .globl startup_32 # In: %esi=0x90000 setup data "real_mode pointer"
// #cli # this must be true already
//
// /* The only facts about segments here, that are true for all kernels:
// * %cs is a valid "flat" code segment; no other segment reg is valid;
// * the next segment after %cs is a valid "flat" data segment, but
// * no segment register designates it yet.
// */
// movl %cs,%eax; addl $1<<3,%eax # the next segment after %cs
// movl %eax,%ds
// movl %eax,%es
// leal 0x9000(%esi),%ecx # 0x99000 typical
// movl %ecx,-8(%ecx) # 32-bit offset for stack pointer
// movl %eax,-4(%ecx) # segment for stack pointer
// lss -8(%ecx),%esp # %ss:%esp= %ds:0x99000
// /* Linux Documentation/i386/boot.txt "SAMPLE BOOT CONFIGURATION" says
// 0x8000-0x8FFF Stack and heap [inside the "real mode segment",
// just below the command line at offset 0x9000].
//
// arch/i386/boot/compressed/head.S "Do the decompression ..." says
// %esi contains the "real mode pointer" [as a 32-bit addr].
//
// In any case, avoid EBDA (Extended BIOS Data Area) below 0xA0000.
// boot.txt says 0x9A000 is the limit. LILO goes up to 0x9B000.
// */
//
// pushl $0; popf # subsumes "cli; cld"; also clears NT for buggy BIOS
//
// movl $ 0x100000,%eax # destination of uncompression (and entry point)
// push %cs
/* Fall into .text of upx-compressed vmlinux. */
//-----
// Approximate translation for Linux 2.4.x:
// - - -
// arch/i386/Makefile: LD_FLAGS=-e startup_32
//----- arch/i386/boot/compressed/Makefile
//# linux/arch/i386/boot/compressed/Makefile
//#
//# create a compressed vmlinux image from the original vmlinux
//#
//
//HEAD = upx-head.o
//SYSTEM = $(TOPDIR)/vmlinux
//
//OBJECTS = $(HEAD)
//
//ZLDFLAGS = -e startup_32
//
//#
//# ZIMAGE_OFFSET is the load offset of the compression loader
//# BZIMAGE_OFFSET is the load offset of the high loaded compression loader
//#
//ZIMAGE_OFFSET = 0x1000
//BZIMAGE_OFFSET = 0x100000
//
//ZLINKFLAGS = -Ttext $(ZIMAGE_OFFSET) $(ZLDFLAGS)
//BZLINKFLAGS = -Ttext $(BZIMAGE_OFFSET) $(ZLDFLAGS)
//
//all: vmlinux
//
//vmlinux: upx-piggy.o $(OBJECTS)
// $(LD) $(ZLINKFLAGS) -o vmlinux $(OBJECTS) upx-piggy.o
//
//bvmlinux: upx-piggy.o $(OBJECTS)
// $(LD) $(BZLINKFLAGS) -o bvmlinux $(OBJECTS) upx-piggy.o
//
//upx-piggy.o: $(SYSTEM)
// $(RM) -f $@
// upx --best -o $@ $<
//
//clean:
// rm -f vmlinux bvmlinux _tmp_*
//-----
//
// Example test jig:
// $ gcc -o test-piggy -nostartfiles -nostdlib test-piggy.o piggy.o
// $ gdb test-piggy
// (gdb) run >dumped
// (gdb) /* Execute [single step, etc.; the decompressor+unfilter moves!]
// * until reaching the 'lret' at the end of unfilter.
// */
// (gdb) set $pc= &dump
// (gdb) stepi
// (gdb) set $edx=<actual_uncompressed_length>
// (gdb) continue
// (gdb) q
// $ # Compare file 'dumped' with the portion of vmlinux that made piggy.o.
// $ dd if=vmlinux bs=<leader_size> skip=1 | cmp - dumped
// cmp: EOF on dumped
// $
//----- test-piggy.S
//#include <asm/mman.h>
//#include <asm/unistd.h>
//
//dump:
// movl $0x456789,%edx # length MODIFY THIS VALUE TO SUIT YOUR CASE
// movl $0x100000,%ecx # base
// movl $1,%ebx # stdout
// movl $ __NR_write,%eax
// int $0x80
// nop
// hlt
//mmap:
// pushl %ebx
// leal 2*4(%esp),%ebx
// pushl $ __NR_mmap; popl %eax
// int $0x80
// popl %ebx
// ret $6*4
//
//_start: .globl _start
// nop
// int3 # enter debugger!
// pushl $0
// pushl $0
// pushl $ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED
// pushl $ PROT_EXEC | PROT_WRITE | PROT_READ
// pushl $0x600000 # 6MB length
// pushl $0x100000 # 1MB address
// call mmap
// leal -0x9000(%esp),%esi # expect "lea 0x9000(%esi),%esp" later
// push %cs
///* Fall into .text of upx-compressed vmlinux. */
//-----
/*
vi:ts=4:et
*/
+78
View File
@@ -0,0 +1,78 @@
/* p_vmlinx.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
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@cdata.tvnet.hu
*/
#ifndef __UPX_P_VMLINX_H
#define __UPX_P_VMLINX_H
#include "p_elf.h"
/*************************************************************************
// vmlinx/i386 (bare binary Linux kernel image)
**************************************************************************/
class PackVmlinuxI386 : public Packer
{
typedef Packer super;
public:
PackVmlinuxI386(InputFile *f);
virtual ~PackVmlinuxI386();
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUX_i386; }
virtual const char *getName() const { return "vmlinux/386"; }
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();
protected:
virtual int buildLoader(const Filter *ft);
// virtual const upx_byte *getLoader() const;
// virtual int getLoaderSize() const;
int n_ptload;
unsigned sz_ptload;
Elf32_Phdr *phdri; // from input file
Elf32_Shdr *shdri; // from input file
Elf32_Shdr *p_text;
Elf32_Shdr *p_note0;
Elf32_Shdr *p_note1;
Elf32_Ehdr ehdri; // from input file
};
#endif /* already included */
/*
vi:ts=4:et
*/
+173 -81
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@users.sourceforge.net
*/
@@ -38,7 +38,8 @@ static const
#include "stub/l_vmlinz.h"
static const unsigned kernel_entry = 0x100000;
static const unsigned stack_during_uncompression = 0x90000;
static const unsigned stack_offset_during_uncompression = 0x9000;
// add to "real mode pointer" in %esi; total 0x99000 is typical
// from /usr/src/linux/arch/i386/boot/compressed/Makefile
static const unsigned zimage_offset = 0x1000;
@@ -52,24 +53,22 @@ static const unsigned bzimage_offset = 0x100000;
PackVmlinuzI386::PackVmlinuzI386(InputFile *f) :
super(f)
{
assert(sizeof(boot_sect_t) == 0x218);
COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x218);
}
int PackVmlinuzI386::getCompressionMethod() const
const int *PackVmlinuzI386::getCompressionMethods(int method, int level) const
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_LE32;
if (M_IS_NRV2D(opt->method))
return M_NRV2D_LE32;
return opt->level > 1 ? M_NRV2D_LE32 : M_NRV2B_LE32;
return Packer::getDefaultCompressionMethods_le32(method, level);
}
const int *PackVmlinuzI386::getFilters() const
{
static const int filters[] = { 0x26, 0x24, 0x11, 0x14, 0x13, 0x16,
0x25, 0x15, 0x12, -1 };
static const int filters[] = {
0x49,
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
-1 };
return filters;
}
@@ -88,51 +87,135 @@ int PackVmlinuzI386::readFileHeader()
{
boot_sect_t h;
setup_size = 0;
fi->readx(&h, sizeof(h));
if (h.boot_flag != 0xAA55)
return -1;
return 0;
const bool hdrs = (memcmp(h.hdrs, "HdrS", 4) == 0);
setup_size = (1 + (h.setup_sects ? h.setup_sects : 4)) * 0x200;
if (setup_size <= 0 || setup_size >= file_size)
return -1;
if (setup_size + 16 * h.sys_size != (unsigned) ALIGN_UP(file_size, 16))
return -1;
return 0;
int format = UPX_F_VMLINUZ_i386;
unsigned sys_size = ALIGN_UP(file_size, 16) - setup_size;
const unsigned char *p = (const unsigned char *) &h + 0x1e3;
if (hdrs && memcmp(p, "\x0d\x0a\x07""ELKS", 7) == 0)
{
format = UPX_F_ELKS_8086;
}
else if (hdrs && (h.load_flags & 1) != 0)
{
format = UPX_F_BVMLINUZ_i386;
// account for 16-bit h.sys_size, wrap around at 20 bits
sys_size &= (1 << 20) - 1;
}
if (16u * h.sys_size != sys_size)
return 0;
// FIXME: add more checks for a valid kernel
if (memcmp(h.hdrs, "HdrS", 4) == 0 && (h.load_flags & 1) != 0)
return UPX_F_BVMLINUZ_i386;
return UPX_F_VMLINUZ_i386;
return format;
}
// read full kernel into obuf, gzip-uncompress into ibuf,
// return uncompressed size
int PackVmlinuzI386::uncompressKernel()
// read full kernel into obuf[], gzip-decompress into ibuf[],
// return decompressed size
int PackVmlinuzI386::decompressKernel()
{
// read whole kernel image
obuf.alloc(file_size);
fi->seek(0, SEEK_SET);
fi->readx(obuf, file_size);
// estimate gzip-uncompressed kernel size & alloc buffer
ibuf.alloc((file_size - setup_size) * 3);
checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, 1024));
// find gzip/zlib header
for (int gzoff = setup_size; gzoff < file_size; gzoff++)
{
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B", 2);
// find gzip header (2 bytes magic + 1 byte method "deflated")
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3);
if (off < 0)
break;
gzoff += off;
fi->seek(gzoff, SEEK_SET);
gzFile zf = gzdopen(fi->getFd(), "r");
if (zf == 0)
const int gzlen = file_size - gzoff;
if (gzlen < 256)
break;
int klen = gzread(zf, ibuf, ibuf.getSize());
if (klen >= file_size)
// check gzip flag byte
unsigned char flags = obuf[gzoff + 3];
if ((flags & 0xe0) != 0) // reserved bits set
continue;
//printf("found gzip header at offset %d\n", gzoff);
// try to decompress
int klen;
int fd;
off_t fd_pos;
for (;;)
{
klen = -1;
fd = -1;
fd_pos = -1;
// open
fi->seek(gzoff, SEEK_SET);
fd = dup(fi->getFd());
if (fd < 0)
break;
gzFile zf = gzdopen(fd, "r");
if (zf == NULL)
break;
// estimate gzip-decompressed kernel size & alloc buffer
if (ibuf.getSize() == 0)
ibuf.alloc(gzlen * 3);
// decompress
klen = gzread(zf, ibuf, ibuf.getSize());
fd_pos = lseek(fd, 0, SEEK_CUR);
gzclose(zf);
fd = -1;
if (klen != (int)ibuf.getSize())
break;
// realloc and try again
unsigned s = ibuf.getSize();
ibuf.dealloc();
ibuf.alloc(3 * s / 2);
}
if (fd >= 0)
(void) close(fd);
if (klen <= 0)
continue;
if (klen <= gzlen)
continue;
if (opt->force > 0)
return klen;
// some checks
if (fd_pos != file_size)
{
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
throwCantPack("trailing bytes after kernel image; use option `-f' to force packing");
}
// see /usr/src/linux/arch/i386/kernel/head.S
// 2.4.x: cld; mov $...,%eax
if (memcmp(ibuf, "\xFC\xB8", 2) == 0) goto head_ok;
// 2.6.x: cld; lgdt ...
if (memcmp(ibuf, "\xFC\x0F\x01", 3) == 0) goto head_ok;
// 2.6.x+grsecurity+strongswan+openwall+trustix: ljmp $0x10,...
if (ibuf[0] == 0xEA && memcmp(ibuf+5, "\x10\x00", 2) == 0) goto head_ok;
throwCantPack("unrecognized kernel architecture; use option `-f' to force packing");
head_ok:
// FIXME: more checks for special magic bytes in ibuf ???
// FIXME: more checks for kernel architecture ???
return klen;
}
return 0;
@@ -141,19 +224,17 @@ int PackVmlinuzI386::uncompressKernel()
void PackVmlinuzI386::readKernel()
{
int klen = uncompressKernel();
int klen = decompressKernel();
if (klen <= 0)
throwCantPack("kernel decompression failed");
if (klen >= (int) ibuf.getSize())
throwCantPack("kernel decompression failed -- too big");
//OutputFile::dump("kernel.img", ibuf, klen);
// copy the setup boot code
setup_buf.alloc(setup_size);
memcpy(setup_buf, obuf, setup_size);
//OutputFile::dump("setup.img", setup_buf, setup_size);
obuf.free();
obuf.dealloc();
obuf.allocForCompression(klen);
ph.u_len = klen;
@@ -181,7 +262,7 @@ int PackVmlinuzI386::buildLoader(const Filter *ft)
addLoader("LZCALLT9", NULL);
addFilter32(ft->id);
}
addLoader("LINUZ990""IDENTSTR""UPX1HEAD", NULL);
addLoader("LINUZ990,IDENTSTR,UPX1HEAD", NULL);
return getLoaderSize();
}
@@ -191,21 +272,11 @@ void PackVmlinuzI386::pack(OutputFile *fo)
readKernel();
// prepare filter
Filter ft(opt->level);
Filter ft(ph.level);
ft.buf_len = ph.u_len;
ft.addvalue = kernel_entry;
// prepare other settings
const unsigned overlap_range = 1 << 20;
unsigned overlapoh;
int strategy = -1; // try the first working filter
if (opt->filter >= 0 && isValidFilter(opt->filter))
// try opt->filter or 0 if that fails
strategy = -2;
else if (opt->all_filters)
// choose best from all available filters
strategy = 0;
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
ft.addvalue = kernel_entry; // saves 4 bytes in unfilter code
// compress
compressWithFilters(&ft, 1 << 20);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
@@ -215,9 +286,9 @@ void PackVmlinuzI386::pack(OutputFile *fo)
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);
patch_le32(loader, lsize, "STAK", stack_offset_during_uncompression);
boot_sect_t *bs = (boot_sect_t *) ((unsigned char *) setup_buf);
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16) / 16;
fo->write(setup_buf, setup_buf.getSize());
@@ -229,6 +300,9 @@ void PackVmlinuzI386::pack(OutputFile *fo)
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
#endif
// verify
verifyOverlappingDecompression();
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
throwNotCompressible();
@@ -244,18 +318,23 @@ int PackBvmlinuzI386::buildLoader(const Filter *ft)
// prepare loader
initLoader(nrv_loader, sizeof(nrv_loader));
addLoader("LINUZ000",
ft->id ? "LZCALLT1" : "",
"LBZIMAGE""IDENTSTR",
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
"LBZIMAGE,IDENTSTR",
"+40D++++", // align the stuff to 4 byte boundary
"UPX1HEAD", // 32 byte
"LZCUTPOI""+0000000",
"LZCUTPOI,+0000000",
getDecompressor(),
NULL
);
if (ft->id)
{
assert(ft->calls > 0);
addLoader("LZCALLT9", NULL);
if (0x40==(0xf0 & ft->id)) {
addLoader("LZCKLLT9", NULL);
}
else {
addLoader("LZCALLT9", NULL);
}
addFilter32(ft->id);
}
addLoader("LINUZ990", NULL);
@@ -268,21 +347,11 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
readKernel();
// prepare filter
Filter ft(opt->level);
Filter ft(ph.level);
ft.buf_len = ph.u_len;
ft.addvalue = kernel_entry;
// prepare other settings
const unsigned overlap_range = 512;
unsigned overlapoh;
int strategy = -1; // try the first working filter
if (opt->filter >= 0 && isValidFilter(opt->filter))
// try opt->filter or 0 if that fails
strategy = -2;
else if (opt->all_filters)
// choose best from all available filters
strategy = 0;
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
ft.addvalue = kernel_entry; // saves 4 bytes in unfilter code
// compress
compressWithFilters(&ft, 512);
// align everything to dword boundary - it is easier to handle
unsigned clen = ph.c_len;
@@ -300,7 +369,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
assert(e_len > 0);
const unsigned d_len4 = ALIGN_UP(lsize - e_len, 4);
const unsigned decompr_pos = ALIGN_UP(ph.u_len + overlapoh, 16);
const unsigned decompr_pos = ALIGN_UP(ph.u_len + ph.overlap_overhead, 16);
const unsigned copy_size = clen + d_len4;
const unsigned edi = decompr_pos + d_len4 - 4; // copy to
const unsigned esi = ALIGN_UP(clen + lsize, 4) - 4; // copy from
@@ -313,11 +382,14 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
patch_le32(loader, e_len, "EDI0", bzimage_offset + edi);
patch_le32(loader, e_len, "ESI0", bzimage_offset + esi);
if (0x40==(0xf0 & ft.id)) {
patch_le32(loader, e_len, "ULEN", ph.u_len);
}
patch_le32(loader, e_len, "KEIP", kernel_entry);
patch_le32(loader, e_len, "STAK", stack_during_uncompression);
patch_le32(loader, e_len, "STAK", stack_offset_during_uncompression);
boot_sect_t *bs = (boot_sect_t *) ((unsigned char *) setup_buf);
bs->sys_size = ALIGN_UP(lsize + clen, 16) / 16;
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
bs->sys_size = (ALIGN_UP(lsize + clen, 16) / 16) & 0xffff;
fo->write(setup_buf, setup_buf.getSize());
fo->write(loader, e_len);
@@ -331,7 +403,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
#endif
// verify
verifyOverlappingDecompression(&obuf, overlapoh);
verifyOverlappingDecompression();
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
@@ -352,14 +424,34 @@ int PackVmlinuzI386::canUnpack()
}
void PackVmlinuzI386::unpack(OutputFile *)
void PackVmlinuzI386::unpack(OutputFile *fo)
{
// no uncompression support for this format, so that
// it is possible to remove the original deflate code (>10KB)
// FIXME: but we could write the uncompressed "vmlinux" image
throwCantUnpack("build a new kernel instead :-)");
ibuf.alloc(ph.c_len);
obuf.allocForUncompression(ph.u_len);
fi->seek(setup_size + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
fi->readx(ibuf, ph.c_len);
// decompress
decompress(ibuf, obuf);
// unfilter
Filter ft(ph.level);
ft.init(ph.filter, kernel_entry);
ft.cto = (unsigned char) ph.filter_cto;
ft.unfilter(obuf, ph.u_len);
// write decompressed file
if (fo)
{
throwCantUnpack("build a new kernel instead :-)");
//fo->write(obuf, ph.u_len);
}
}
+36 -8
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@@ -21,8 +21,8 @@
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@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu
*/
@@ -39,10 +39,10 @@ class PackVmlinuzI386 : public Packer
typedef Packer super;
public:
PackVmlinuzI386(InputFile *f);
virtual int getVersion() const { return 11; }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUZ_i386; }
virtual const char *getName() const { return "vmlinuz/386"; }
virtual int getCompressionMethod() const;
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual void pack(OutputFile *fo);
@@ -53,7 +53,7 @@ public:
protected:
virtual int readFileHeader();
virtual int uncompressKernel();
virtual int decompressKernel();
virtual void readKernel();
virtual int buildLoader(const Filter *ft);
@@ -79,7 +79,8 @@ protected:
// some more uninteresting fields here ...
// see /usr/src/linux/Documentation/i386/zero-page.txt
};
}
__attribute_packed;
MemBuffer setup_buf;
int setup_size;
@@ -105,6 +106,33 @@ protected:
};
/*************************************************************************
// elks/8086 (linux-8086 uncompressed kernel image)
**************************************************************************/
class PackElks8086 : public PackVmlinuzI386
{
typedef PackVmlinuzI386 super;
public:
PackElks8086(InputFile *f) : super(f) { }
virtual int getFormat() const { return UPX_F_ELKS_8086; }
virtual const char *getName() const { return "elks/8086"; }
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 int canUnpack();
protected:
virtual int decompressKernel();
virtual void readKernel();
virtual int buildLoader(const Filter *ft);
};
#endif /* already included */

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