Compare commits

..

257 Commits

Author SHA1 Message Date
Markus F.X.J. Oberhumer 08c0796719 Avoid warnings when building for m68k.
committer: mfx <mfx> 1144523702 +0000
2006-04-08 19:15:02 +00:00
Markus F.X.J. Oberhumer edc7994ce5 Prepared 1.95 release.
committer: mfx <mfx> 1144522884 +0000
2006-04-08 19:01:24 +00:00
Markus F.X.J. Oberhumer bcfcfbd064 Added some more operators.
committer: mfx <mfx> 1144522838 +0000
2006-04-08 19:00:38 +00:00
Markus F.X.J. Oberhumer 9e79b3258d Make const-correct to avoid warning.
committer: mfx <mfx> 1144522792 +0000
2006-04-08 18:59:52 +00:00
John Reiser 243873cd2d Workaround inconsistent SIZEOF_HEADERS in stub/*.lds.
Test with --force-execve and --no-filter.
	p_lx_exc.cpp p_lx_sh.cpp stub/l_lx_sh86.asm stub/l_lx_sh86.h

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

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

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

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

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

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

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

committer: jreiser <jreiser> 1142305438 +0000
2006-03-14 03:03:58 +00:00
Markus F.X.J. Oberhumer a3097d5e25 Added a dependency.
committer: mfx <mfx> 1142303569 +0000
2006-03-14 02:32:49 +00:00
Markus F.X.J. Oberhumer fd78148558 Fixed typo in disabled code.
committer: mfx <mfx> 1142302679 +0000
2006-03-14 02:17:59 +00:00
Markus F.X.J. Oberhumer a4d79d7375 Small cosmetic changes.
committer: mfx <mfx> 1142302586 +0000
2006-03-14 02:16:26 +00:00
Markus F.X.J. Oberhumer df04e8183d Filter parameters should be called "ft" instead of "fp".
committer: mfx <mfx> 1142301730 +0000
2006-03-14 02:02:10 +00:00
Markus F.X.J. Oberhumer c43c484a62 Re-synced both files a little bit.
committer: mfx <mfx> 1142301586 +0000
2006-03-14 01:59:46 +00:00
Markus F.X.J. Oberhumer 0608c35669 Added some more OBJSTRIP. Small cleanups.
committer: mfx <mfx> 1142298790 +0000
2006-03-14 01:13:10 +00:00
Markus F.X.J. Oberhumer 7dd4d06e26 Added some more calls to $(OBJSTRIP_LINUX_I386) after $(NASM) invocations.
committer: mfx <mfx> 1142288478 +0000
2006-03-13 22:21:18 +00:00
John Reiser 1ee0310b86 silence complaint from ld "cannot find entry symbol _start; defaulting to 10000000"
committer: jreiser <jreiser> 1142285749 +0000
2006-03-13 21:35:49 +00:00
Markus F.X.J. Oberhumer cc0a52038f Rebuilt i386-linux stubs with gcc-4.1.0 for small size decrease.
committer: mfx <mfx> 1142248018 +0000
2006-03-13 11:06:58 +00:00
Markus F.X.J. Oberhumer 6aed1fe231 Updated.
committer: mfx <mfx> 1142247976 +0000
2006-03-13 11:06:16 +00:00
Markus F.X.J. Oberhumer 680608fe18 Portability fix.
committer: mfx <mfx> 1142247872 +0000
2006-03-13 11:04:32 +00:00
Markus F.X.J. Oberhumer ec6acbc602 Small fix to make valid ANSI C again.
committer: mfx <mfx> 1142247837 +0000
2006-03-13 11:03:57 +00:00
John Reiser cb7ee4c5d2 _syscall1nr() for _exit; [still wastes 4 bytes]
committer: jreiser <jreiser> 1142210712 +0000
2006-03-13 00:45:12 +00:00
Markus F.X.J. Oberhumer 88d5798f45 Bumped versions for starting 1.95 development.
committer: mfx <mfx> 1142090576 +0000
2006-03-11 15:22:56 +00:00
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
180 changed files with 20098 additions and 5981 deletions
+9 -3
View File
@@ -1,7 +1,13 @@
.bzr*
.darcs*
.git*
.hg*
_darcs _darcs
B B
ChangeLog.cvs* build*
TODO.*
build
doxygen doxygen
maint maint
ChangeLog.cvs*
GNUmakefile
MMakefile
TODO.*
+13
View File
@@ -0,0 +1,13 @@
.bzr*
.darcs*
.git*
.hg*
_darcs
B
build*
doxygen
maint
ChangeLog.cvs*
GNUmakefile
MMakefile
TODO.*
+1 -1
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
+15 -11
View File
@@ -1,6 +1,8 @@
# Toplevel Makefile for UPX # Toplevel Makefile for UPX
SHELL = /bin/sh MAKEFLAGS += -rR
.SUFFIXES:
export SHELL = /bin/sh
srcdir = . srcdir = .
top_srcdir = . top_srcdir = .
@@ -18,22 +20,24 @@ all mostlyclean clean distclean maintainer-clean:
dist: distclean dist: distclean
false false
zip:
cd .. && rm -f upx-current.zip && zip -r upx-current.zip upx 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 admin -ko . cvs admin -ko .
cvs update -P -d cvs -q -z6 update -P -d
ChangeLog: # automatically generate ChangeLog from CVS
ChangeLog ChangeLog.cvs:
perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs perl $(srcdir)/scripts/cvs2cl.pl --utc -f ChangeLog.cvs
ChangeLog.cvsps:
cvsps > $@
.PHONY: all mostlyclean clean distclean maintainer-clean .PHONY: all mostlyclean clean distclean maintainer-clean
.PHONY: dist cvs-admin-ko ChangeLog .PHONY: dist cvs-info cvs-admin-ko ChangeLog ChangeLog.cvs
.NOEXPORT:
+15 -4
View File
@@ -2,10 +2,22 @@
User visible changes for UPX User visible changes for UPX
================================================================== ==================================================================
[ UNSTABLE BETA VERSION - please see README.1ST for some more info ] Changes in 1.95 beta (09 Apr 2006):
* arm/pe: added DLL support
* arm/pe: added thumb mode stub support
* arm/pe: added unpacking support
* win32/pe: really worked around R6002 runtime errors
Changes in 1.94 beta (11 Mar 2006):
* 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): Changes in 1.93 beta (07 Feb 2005):
* UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING
* vmlinuz/386: fixes to support more kernels * vmlinuz/386: fixes to support more kernels
Changes in 1.92 beta (20 Jul 2004): Changes in 1.92 beta (20 Jul 2004):
@@ -93,7 +105,6 @@ Changes in 1.20 (23 May 2001)
our unstable development releases 1.1x and 1.9x] our unstable development releases 1.1x and 1.9x]
Changes in 1.08 (30 Apr 2001) Changes in 1.08 (30 Apr 2001)
* INFO: http://upx.sourceforge.net now is the new permanent UPX home page
* new native port to atari/tos * new native port to atari/tos
* win32/pe: shortened the identstring * win32/pe: shortened the identstring
* source code: portability fixes - UPX now builds cleanly under m68k CPUs * source code: portability fixes - UPX now builds cleanly under m68k CPUs
@@ -313,7 +324,7 @@ Changes in 0.40 (05 Oct 1998)
* fixed a small but fatal bug in dos/sys introduced in 0.30 * fixed a small but fatal bug in dos/sys introduced in 0.30
* fixed a rare bug in dos/exe * fixed a rare bug in dos/exe
* worked around a bug in djgpp's strip 2.8 * 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+) * added dos/exeh compression method (works on 386+)
Changes in 0.30 (27 Jul 1998) Changes in 0.30 (27 Jul 1998)
+1 -3
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -42,8 +42,6 @@ More formats:
- freebsd/386 (generic), freebsd/elf386 (specialized). - freebsd/386 (generic), freebsd/elf386 (specialized).
Probably could share most of the linux code. Probably could share most of the linux code.
- Windows CE
- add support for self-extracting HTML pages using a Javascript stub - add support for self-extracting HTML pages using a Javascript stub
(like the AlgART HTML Packer "AHP") (like the AlgART HTML Packer "AHP")
+10 -5
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -25,11 +25,15 @@ will be called version 2.00.
The main news since 1.25 are: The main news since 1.25 are:
- slightly better compression using the new NRV2E algorithm - slightly better compression using the new NRV2E algorithm
- new options for compression tuining (e.g. `--brute') - new options for compression tuning (e.g. `--brute')
- support for bootable Linux kernels ("vmlinuz/386") - support for bootable Linux kernels ("vmlinuz/386")
- support for Linux kernel building ("vmlinux/386") - support for Linux kernel building ("vmlinux/386")
- direct Linux ELF-to-memory decompression ("linux/elf386") and - direct Linux ELF-to-memory decompression ("linux/elf386") and
shell-to-memory decompression ("linux/sh386") 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") - support for playstation exes ("ps1/exe")
- lots of new bugs ;-) take care - lots of new bugs ;-) take care
@@ -129,8 +133,9 @@ THE FUTURE
COPYRIGHT COPYRIGHT
========= =========
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
This program may be used freely, and you are welcome to This program may be used freely, and you are welcome to
redistribute it under certain conditions. redistribute it under certain conditions.
@@ -149,7 +154,7 @@ Markus & Laszlo
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
+7 -6
View File
@@ -8,26 +8,27 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net
WARNING - UNSTABLE BETA VERSION WARNING - UNSTABLE BETA VERSION
=============================== ===============================
All versions 1.9x are unstable beta releases - use them only for testing,
and never distribute a program that is packed with them !
There will be hidden bugs. Really.
The current stable release is 1.25, and the next stable release The current stable release is 1.25, and the next stable release
will be called version 2.00. will be called version 2.00.
The main news since 1.25 are: The main news since 1.25 are:
- slightly better compression using the new NRV2E algorithm - slightly better compression using the new NRV2E algorithm
- new options for compression tuining (e.g. `--brute') - new options for compression tuning (e.g. `--brute')
- support for bootable Linux kernels ("vmlinuz/386") - support for bootable Linux kernels ("vmlinuz/386")
- support for Linux kernel building ("vmlinux/386") - support for Linux kernel building ("vmlinux/386")
- direct Linux ELF-to-memory decompression ("linux/elf386") and - direct Linux ELF-to-memory decompression ("linux/elf386") and
shell-to-memory decompression ("linux/sh386") shell-to-memory decompression ("linux/sh386")
- support for arm/WinCE ("arm/pe") exes
- support for Linux elf/amd64
- support for Linux elf/ppc32
- support for mach/ppc32
- support for playstation exes ("ps1/exe") - support for playstation exes ("ps1/exe")
- lots of new bugs ;-) take care
+6
View File
@@ -110,6 +110,12 @@ If you want to modify the stub sources you'll also need
- Linux (for the linux/386 stubs) - 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 Misc. notes
----------- -----------
+1 -3
View File
@@ -8,7 +8,7 @@
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -39,8 +39,6 @@ Ice
for debugging the PE headersize problem down for debugging the PE headersize problem down
Joergen Ibsen <jibz@hotmail.com> and d'b Joergen Ibsen <jibz@hotmail.com> and d'b
for the relocation & address optimization ideas for the relocation & address optimization ideas
John F. Reiser <jreiser@BitWagon.com>
for the new Linux executable formats
John S. Fine <johnfine@erols.com> John S. Fine <johnfine@erols.com>
for the new version of the dos/exe decompressor for the new version of the dos/exe decompressor
Lukundoo <Lukundoo@softhome.net> Lukundoo <Lukundoo@softhome.net>
+3 -5
View File
@@ -1,14 +1,14 @@
UPX TODO list. Last updated 2005-01-08. UPX TODO list. Last updated 2006-03-11.
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON: IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
- stub ctojr32 needs CPU 486 because of bswap - [None]
OTHER: OTHER:
- rewrite linker.cpp to allow arbitrary length section names - docs: convert docs from upx.pod to use AsciiDoc
- check all <const_cast> to make sure they are not invalid - check all <const_cast> to make sure they are not invalid
@@ -108,8 +108,6 @@ FORMAT WIN32/PE
2 - easy - mfx + ml) new switch(es) : do not compress resource types x,y,z 2 - easy - mfx + ml) new switch(es) : do not compress resource types x,y,z
or resource names a,b,c or resource names a,b,c
3 - medium - ml) rebuild exports
3 - difficult) don't compress the BSS section and other holes. 3 - difficult) don't compress the BSS section and other holes.
4 - medium - ml) fix when objectalign < 0x1000 4 - medium - ml) fix when objectalign < 0x1000
+6
View File
@@ -0,0 +1,6 @@
upx.1
upx.doc
upx.html
upx.man
upx.ps
upx.tex
+4 -4
View File
@@ -1,9 +1,11 @@
MAKEFLAGS += -rR
.SUFFIXES:
SHELL = /bin/sh SHELL = /bin/sh
top_srcdir = .. top_srcdir = ..
PACKAGE = upx PACKAGE = upx
VERSION_DATE = 07 Feb 2005 VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h) VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
TRIMSPACE = cat TRIMSPACE = cat
@@ -62,7 +64,5 @@ maintainer-clean: distclean
### dependencies ### dependencies
### ###
$(BUILT_SOURCES): $(top_srcdir)/src/version.h Makefile $(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
.NOEXPORT:
+1 -1
View File
@@ -11,7 +11,7 @@ loads of cryptic comments like `__PERELOC2__'.
If you look at the C++ source files, however you can notice that these If you look at the C++ source files, however you can notice that these
comment strings (without the leading and trailing underscores) are used 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", addLoader("PEMAIN20",
ih.entry ? "PEDOJUMP" : "PERETURN", 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.
+10 -9
View File
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
=head1 ABSTRACT =head1 ABSTRACT
The Ultimate Packer for eXecutables The Ultimate Packer for eXecutables
Copyright (c) 1996-2005 Markus Oberhumer & Laszlo Molnar Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
http://upx.sourceforge.net http://upx.sourceforge.net
@@ -77,6 +77,10 @@ B<UPX> is a versatile executable packer with the following features:
* vmlinuz/386 [bootable Linux kernel] * vmlinuz/386 [bootable Linux kernel]
* watcom/le (supporting DOS4G, PMODE/W, DOS32a and CauseWay) * watcom/le (supporting DOS4G, PMODE/W, DOS32a and CauseWay)
* win32/pe * win32/pe
* arm/pe
* linux/elfamd64
* linux/elfppc32
* mach/elfppc32
- portable: UPX is written in portable endian-neutral C++ - portable: UPX is written in portable endian-neutral C++
@@ -730,7 +734,7 @@ Extra options available for this executable format:
=head2 NOTES FOR RTM32/PE =head2 NOTES FOR RTM32/PE and ARM/PE
Same as win32/pe. Same as win32/pe.
@@ -865,9 +869,6 @@ Extra options available for this executable format:
unexpected value in a header field. unexpected value in a header field.
Use with care. Use with care.
--strip-loadconf=0 Don't strip Structured Exception Handling load config [DEFAULT].
--strip-loadconf=1 Strip Structured Exception Handling load config.
--strip-relocs=0 Don't strip relocation records. --strip-relocs=0 Don't strip relocation records.
--strip-relocs=1 Strip relocation records. [DEFAULT] --strip-relocs=1 Strip relocation records. [DEFAULT]
This option only works on executables with base This option only works on executables with base
@@ -920,13 +921,13 @@ Please report all bugs immediately to the authors.
=head1 COPYRIGHT =head1 COPYRIGHT
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2005 John F. Reiser Copyright (C) 2000-2006 John F. Reiser
Copyright (C) 2002-2005 Jens Medoch Copyright (C) 2002-2006 Jens Medoch
This program may be used freely, and you are welcome to This program may be used freely, and you are welcome to
redistribute it under certain conditions. redistribute it under certain conditions.
View File
-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;
View File
+8 -8
View File
@@ -1,4 +1,4 @@
#! /usr/bin/perl -w #! /usr/bin/perl
############################################################## ##############################################################
@@ -7,9 +7,9 @@
### ### ### ###
############################################################## ##############################################################
## $Revision: 2.58 $ ## $Revision: 2.59 $
## $Date: 2004/11/07 15:28:35 $ ## $Date: 2005/05/18 05:34:34 $
## $Author: fluffy $ ## $Author: kfogel $
## ##
use strict; use strict;
@@ -141,7 +141,7 @@ use User::pwent qw( getpwnam );
# Globals -------------------------------------------------------------------- # Globals --------------------------------------------------------------------
# In case we have to print it out: # In case we have to print it out:
my $VERSION = '$Revision: 2.58 $'; my $VERSION = '$Revision: 2.59 $';
$VERSION =~ s/\S+\s+(\S+)\s+\S+/$1/; $VERSION =~ s/\S+\s+(\S+)\s+\S+/$1/;
## Vars set by options: ## Vars set by options:
@@ -1317,9 +1317,9 @@ my $self = shift; my $class = ref $self;
while (<OLD_LOG>) { while (<OLD_LOG>) {
if ( ! $passed_first_entry ) { if ( ! $passed_first_entry ) {
if ( ( ! $started_first_entry ) if ( ( ! $started_first_entry )
and /^(\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)/ ) { and /^(\d\d\d\d-\d\d-\d\d\s+(\w+\s+)?\d\d:\d\d)/ ) {
$started_first_entry = 1; $started_first_entry = 1;
} elsif ( /^(\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)/ ) { } elsif ( /^(\d\d\d\d-\d\d-\d\d\s+(\w+\s+)?\d\d:\d\d)/ ) {
$passed_first_entry = 1; $passed_first_entry = 1;
print NEW_LOG $_; print NEW_LOG $_;
} }
@@ -2391,7 +2391,7 @@ sub maybe_grab_accumulation_date {
my $boundary_date; my $boundary_date;
while (<LOG>) while (<LOG>)
{ {
if (/^(\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)/) if (/^(\d\d\d\d-\d\d-\d\d\s+(\w+\s+)?\d\d:\d\d)/)
{ {
$boundary_date = "$1"; $boundary_date = "$1";
last; last;
+3 -8
View File
@@ -1,4 +1,3 @@
GNUmakefile
*.0?? *.0??
*.d *.d
*.dat *.dat
@@ -10,15 +9,11 @@ GNUmakefile
*.rel *.rel
*.res *.res
*.pdb *.pdb
*.out
*.upx *.upx
.gdbinit .gdbinit
.Attic GNUmakefile
.deps MMakefile
B
compress_nrv.* compress_nrv.*
upx upx
upx_nrv
upx_nrv.*
upx_ucl
upx_ucl.*
version1*.h version1*.h
+19
View File
@@ -0,0 +1,19 @@
*.0??
*.d
*.dat
*.idb
*.img
*.map
*.raw
*.rc
*.rel
*.res
*.pdb
*.out
*.upx
.gdbinit
GNUmakefile
MMakefile
compress_nrv.*
upx
version1*.h
-42
View File
@@ -1,42 +0,0 @@
ifeq ($(DEPS_DONE),)
DEPS_DONE := 1
# /***********************************************************************
# // automated dependencies
# ************************************************************************/
ifeq ($(DEPMODE),gcc)
EXTRA_CFLAGS += -Wp,-MMD,.deps/$(*F).d
EXTRA_CXXFLAGS += -Wp,-MMD,.deps/$(*F).d
HAVE_DEPS := 1
endif
ifeq ($(DEPMODE),linux-intelc)
EXTRA_CFLAGS += -MMD -MF.deps/$(*F).d
EXTRA_CXXFLAGS += -MMD -MF.deps/$(*F).d
HAVE_DEPS := 1
endif
ifeq ($(DEPMODE),linux-pgi)
## NOTE: -MMD does not work...
EXTRA_CFLAGS += -MD.deps/$(*F).d
EXTRA_CXXFLAGS += -MD.deps/$(*F).d
HAVE_DEPS := 1
endif
ifeq ($(HAVE_DEPS),1)
ifeq ($(strip $(wildcard .deps)),)
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
else
DEPS_FILES := $(wildcard .deps/*.d)
ifneq ($(strip $(DEPS_FILES)),)
include $(DEPS_FILES)
endif
endif
endif
endif # DEPS_DONE
-71
View File
@@ -1,71 +0,0 @@
DEPMODE := gcc
# /***********************************************************************
# // defaults for gcc
# ************************************************************************/
CC = gcc
CXX = g++
CFLAGS_OUTPUT = -o $@
LINK_EXE_OUTPUT = -o $@
CFLAGS_W =
CFLAGS_M =
CFLAGS_O =
CXXFLAGS_W =
CXXFLAGS_M =
CXXFLAGS_O =
CFLAGS = $(call __mkflags,CFLAGS_W) $(call __mkflags,CFLAGS_M) $(call __mkflags,CFLAGS_O)
CXXFLAGS = $(call __mkflags,CXXFLAGS_W) $(call __mkflags,CXXFLAGS_M) $(call __mkflags,CXXFLAGS_O)
#
# cflags
#
##CFLAGS_WERROR = -Werror
CFLAGS_WERROR =
CFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wbad-function-cast -Wcast-align -Wcast-qual -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wwrite-strings
CXXFLAGS_W = $(CFLAGS_WERROR) -Wall -W -Wcast-align -Wcast-qual -Winline -Woverloaded-virtual -Wpointer-arith -Wshadow -Wsign-promo -Wwrite-strings
##CFLAGS_M += -fno-builtin
##CFLAGS_M += -malign-functions=0 -malign-jumps=0 -malign-loops=0
CXXFLAGS_M = $(CFLAGS_M)
ifeq ($(DEBUG),1)
CFLAGS_O = -g -O0
else
##CFLAGS_O = -Os -fstrict-aliasing
CFLAGS_O = -O2 -fstrict-aliasing
##CFLAGS_O = -O2 -fno-strict-aliasing
endif
CXXFLAGS_O = $(CFLAGS_O) -fconserve-space
##CXXFLAGS += -fasynchronous-exceptions
#
# cxxflags for g++ 3.2 or better
##CXXFLAGS_W += -Wdisabled-optimization -Wpacked
#
# ldflags
#
ifeq ($(DEBUG),1)
LDFLAGS += -g
else
LDFLAGS += -s
endif
LDFLAGS += -Wl,-Map,$T.map
ifeq ($(WITH_ZLIB),1)
LDLIBS += -lz
endif
# vi:nowrap
-48
View File
@@ -1,48 +0,0 @@
UDIR := $($(U)DIR)
ifneq ($(strip $(wildcard $(UDIR)/include)),) # { include
DEFS += -DWITH_$(U)
INCLUDES += -I$(UDIR)/include
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
else
ifneq ($(strip $(wildcard $(UDIR)/build/$(target)/src/.libs)),)
LIBDIRS += $(UDIR)/build/$(target)/src/.libs
else
ifneq ($(strip $(wildcard $(UDIR)/src/.libs)),)
LIBDIRS += $(UDIR)/src/.libs
else
ifneq ($(strip $(wildcard $(UDIR)/build/release/src/.libs)),)
LIBDIRS += $(UDIR)/build/release/src/.libs
else
ifneq ($(strip $(wildcard $(UDIR)/build/src/.libs)),)
LIBDIRS += $(UDIR)/build/src/.libs
else
ifneq ($(strip $(wildcard $(UDIR))),)
LIBDIRS += $(UDIR)
DOS_LIBDIRS := $(DOS_LIBDIRS);$(UDIR)
endif
endif
endif
endif
endif
endif
LDLIBS += -l$(u)
DOS_LDLIBS += $(u).lib
DEFS := $(DEFS)
INCLUDES := $(INCLUDES)
LIBDIRS := $(LIBDIRS)
LDLIBS := $(LDLIBS)
DOS_LDLIBS := $(DOS_LDLIBS)
endif # } include
+41 -74
View File
@@ -1,88 +1,55 @@
# #
# UPX Makefile (GNU make) - works with unix/win32/djgpp2 # UPX Makefile - needs GNU make 3.80 or better
#
# usage:
# `make target=linux' # linux
# `make target=dos32-djggp2' # dos32 - djggp2
# `make target=win32-cygwin' # win32 - cygwin
# `make target=win32-mingw32' # win32 - mingw32
# `make target=win32-rsxnt' # win32 - rsxnt
# `make target=win32-bc' # win32 - Borland C++
# `make target=win32-dm' # win32 - Digital Mars C++
# `make target=win32-ic' # win32 - Intel C++
# `make target=win32-vc' # win32 - Visual C++
# `make target=win32-wc' # win32 - Watcom C++
# `make target=cross-amd64-linux' # x86_64-linux cross compiler
# `make target=cross-mingw32' # i586-mingw32msvc cross compiler
# `make target=cross-mint' # m68k-atari-mint cross compiler
# `make target=gcc' # generic gcc
#
# you can also set the `UPX_MAKE_TARGET' environment variable.
# #
MAKEFLAGS += -rR
.SUFFIXES:
export SHELL = /bin/sh
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
# configuration section srcdir ?= $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
ifneq ($(srcdir),./)
ifeq ($(strip $(UCLDIR)),) srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,')
# change this to reflect where the UCL library is ##$(info Info: using VPATH . $(srcdir))
UCLDIR = $(HOME)/local/src/ucl-1.03 VPATH := . $(srcdir)
endif endif
## you can set the default target here ifeq ($(CXX),)
##target = CXX = g++
endif
ifeq ($(CXX),g++)
CXXFLAGS += -O2 -MMD
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
endif
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
CXXLD ?= $(CXX)
DEBUG = 0 exeext ?= .out
libext ?= .a
objext ?= .o
srcdir = . # we need UCL and zlib - you can set envvar UCLDIR
top_srcdir = .. ifneq ($(wildcard $(UCLDIR)/include/ucl/ucl.h),)
INCLUDES += -I$(UCLDIR)/include
LIBS += $(addprefix -L,$(dir $(wildcard $(UCLDIR)/libucl$(libext) $(UCLDIR)/src/.libs/libucl$(libext))))
endif
LIBS += -lucl -lz
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
##### You should not have to change anything below this line. ##### 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)
# /*********************************************************************** %.o : %.cpp
# // object files $(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
# ************************************************************************/
# these use exceptions & RTTI mostlyclean clean distclean maintainer-clean:
OBJECTS1 = \ rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)
compress$o except$o file$o lefile$o \
filter$o linker$o mem$o msg$o stdcxx$o work$o ui$o \
packer$o packerf$o packhead$o packmast$o \
p_com$o p_djgpp2$o p_elks$o p_exe$o \
p_lx_elf$o p_lx_exc$o p_lx_sep$o p_lx_sh$o \
p_ps1$o p_sys$o p_tmt$o p_tos$o \
p_unix$o p_vmlinz$o p_vmlinx$o p_w16ne$o p_w32pe$o p_wcle$o
# no exceptions or RTTI -include *.d
OBJECTS2 = \ .PHONY: all mostlyclean clean distclean maintainer-clean
filteri$o help$o main$o mygetopt$o snprintf$o util$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)
LIBS =
RESOURCES =
# /***********************************************************************
# // main
# ************************************************************************/
override WITH_ZLIB = 1
include $(srcdir)/Makefile.bld
# /***********************************************************************
# // dependencies
# ************************************************************************/
include $(srcdir)/Makedefs.dep
$(OBJECTS): miniacc.h
# vi:nowrap
-720
View File
@@ -1,720 +0,0 @@
# /***********************************************************************
# // prepare setup
# ************************************************************************/
SHELL = /bin/sh
.SUFFIXES:
.SUFFIXES: .a .c .cpp .exe .lib .o .obj .rc .res .ttp
ifeq ($(srcdir),)
srcdir = .
endif
VPATH = $(srcdir)
# auto-detect the target unless given on the commandline
ifeq ($(strip $(target)),)
# try environment variable UPX_MAKE_TARGET
target := $(UPX_MAKE_TARGET)
endif
ifeq ($(strip $(target)),)
ifneq ($(strip $(wildcard /usr/include/linux)),)
target = linux
endif
##ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),)
##target = sparc-sun-solaris
##endif
endif
ifeq ($(strip $(target)),)
include please_specify_a_target
endif
# util var for use in the rules - basename of the current target
override T = $(basename $@)
# expand "VAR" into "$(VAR) $(EXTRA_VAR) $(UPX_EXTRA_VAR)"
override __mkflags = $(strip $($(1)) $(EXTRA_$(1)) $(UPX_EXTRA_$(1)))
# /***********************************************************************
# // compiler defaults
# ************************************************************************/
CC_SRC = $<
CXX_SRC = $<
CC_COMPILE = $(CC) $(CCARCH) $(call __mkflags,DEFS) $(call __mkflags,INCLUDES) $(call __mkflags,CFLAGS) $(CFLAGS_OUTPUT) -c $(CC_SRC)
CXX_COMPILE = $(CXX) $(CXXARCH) $(call __mkflags,DEFS) $(call __mkflags,INCLUDES) $(call __mkflags,CXXFLAGS) $(CXXFLAGS_OUTPUT) -c $(CXX_SRC)
CXX_LINK_EXE = $(CXXLD) $(CXXLDARCH) $(call __mkflags,LDFLAGS) $(LINK_EXE_OUTPUT) $^ $(call __mkflags,LDLIBS)
STUBEDIT_EXE =
STUBIFY_EXE =
CHMOD_EXE =
o = .o
a = .a
e =
DEFS =
INCLUDES =
LIBDIRS =
DOS_LDLIBS =
DOS_LIBDIRS =
# CC defaults
CC = INVALID_TARGET_CC
CCARCH =
CFLAGS =
CFLAGS_OUTPUT =
# CXX defaults
CXX = $(CC)
CXXARCH = $(CCARCH)
CXXFLAGS = $(CFLAGS)
CXXFLAGS_OUTPUT = $(CFLAGS_OUTPUT)
# CXXLD defaults
CXXLD = $(CXX)
CXXLDARCH = $(CXXARCH)
LDFLAGS =
LINK_EXE_OUTPUT =
LDLIBS =
LINK_EXE_LDFLAGS =
ifeq ($(DEBUG),1)
DEFS += -DDEBUG
## DEFS += -DTESTING
endif
# /***********************************************************************
# // compression libraries
# ************************************************************************/
ifeq ($(WITH_ZLIB),1)
DOS_LDLIBS += zlib.lib
ZLIBDIR:=$(strip $(subst \,/,$(ZLIBDIR)))
ifneq ($(strip $(wildcard $(ZLIBDIR))),)
ifneq ($(strip $(wildcard $(ZLIBDIR)/include/zlib.h)),)
INCLUDES += -I$(ZLIBDIR)/include
else
ifneq ($(strip $(wildcard $(ZLIBDIR)/src/zlib.h)),)
INCLUDES += -I$(ZLIBDIR)/src
else
ifneq ($(strip $(wildcard $(ZLIBDIR)/zlib.h)),)
INCLUDES += -I$(ZLIBDIR)
endif
endif
endif
endif
endif
UCLDIR:=$(strip $(subst \,/,$(UCLDIR)))
NRVDIR:=$(strip $(subst \,/,$(NRVDIR)))
u = ucl
U = UCL
upx_exe_tail =
include $(srcdir)/Makedefs.inc
ifneq ($(strip $(wildcard $(NRVDIR)/include/nrv)),)
u = nrv
U = NRV
upx_exe_tail := _$(u)
include $(srcdir)/Makedefs.inc
endif
upx_exe = upx$(upx_exe_tail)$(e)
override tmp := -Wl,--rpath,
LDRPATH := $(addprefix $(tmp),$(LIBDIRS))
LIBDIRS += .
LDLIBDIRS := $(addprefix -L,$(LIBDIRS))
##LDFLAGS += $(LDRPATH)
LDFLAGS += $(LDLIBDIRS)
# /***********************************************************************
# // compiler settings
# ************************************************************************/
###
### generic gcc
###
ifeq ($(target),gcc)
include $(srcdir)/Makedefs.gcc
endif
###
### linux - gcc
###
ifeq ($(target),linux)
include $(srcdir)/Makedefs.gcc
override arch := $(shell uname -m | sed -e 's/^i[3456789]86$$/i386/')
ifeq ($(arch),i386)
CCARCH += -march=i386 -mcpu=i686
endif
DEFS += -D_FILE_OFFSET_BITS=64
LDLIBS += -lmcheck
##CFLAGS_WERROR = -Werror
ifeq ($(DEBUG),1)
else
##LDFLAGS += -static
STUBEDIT_EXE = objcopy -S -R .comment -R .note $@
ifeq ($(arch),i386)
## STUBIFY_EXE = perl $(srcdir)/stub/scripts/brandelf.pl $@
endif
endif
CHMOD_EXE = chmod 755 $@
endif # linux
###
### linux/i386 - Borland C++ 5.7 (Kylix 3)
###
ifeq ($(target),linux-bc57)
##DEPMODE := linux-XXX ## FIXME
CC = bc++ -q -3
CFLAGS = -w '-w!'
CFLAGS_OUTPUT = -o$@
LDFLAGS += -ls
LINK_EXE_OUTPUT = -e$@
ifeq ($(WITH_ZLIB),1)
LDLIBS += -lz
endif
# warning: do not use option `-d' --> incorrect string merging will happen
ifeq ($(DEBUG),1)
CFLAGS += -Od -dc
else
CFLAGS += -O2 -dc
endif
# transform `-lxx -lyy' into `libxx.a libyy.a'
LDLIBS := $(shell echo "$(LDLIBS)" | perl -pe 's/-l(.+?)\b/lib\1.a/g')
endif
###
### linux/i386 - Intel C++
###
ifeq ($(target),linux-intelc)
DEPMODE := linux-intelc
CC = icc
CXX = icpc
CCARCH += -march=i386 -mcpu=i686 -nolib_inline
DEFS += -D_FILE_OFFSET_BITS=64
CFLAGS_OUTPUT = -o $@
LINK_EXE_OUTPUT = -o $@
ifeq ($(WITH_ZLIB),1)
LDLIBS += -lz
endif
CFLAGS = $(CFLAGS_WERROR)
ifeq ($(DEBUG),1)
CFLAGS += -g -O0
else
CFLAGS += -O2
endif
LDFLAGS += -Wl,-Map,$T.map
endif
###
### linux/i386 - Portland Group PGI C++ 5.x
###
ifeq ($(target),linux-pgi)
DEPMODE := linux-pgi
CC = pgcc
CXX = pgCC
CCARCH += -tp=p6
DEFS += -D_FILE_OFFSET_BITS=64
CFLAGS_OUTPUT = -o $@
LINK_EXE_OUTPUT = -o $@
ifeq ($(WITH_ZLIB),1)
LDLIBS += -lz
endif
##CFLAGS += -Minform=info
CXXFLAGS = $(CFLAGS) -tused
ifeq ($(DEBUG),1)
else
CFLAGS += -O2
endif
endif
###
### Linux cross compilers
###
ifeq ($(target),cross-amd64-linux)
include $(srcdir)/Makedefs.gcc
CC = x86_64-linux-gcc
CXX = x86_64-linux-g++
LDLIBS += -lmcheck
endif # cross-amd64-linux
ifeq ($(target),cross-m68k-linux)
include $(srcdir)/Makedefs.gcc
CC = m68k-linux-gcc
CXX = m68k-linux-g++
##LDLIBS += -lmcheck
endif # cross-m68k-linux
###
### sparc-sun-solaris2.8
###
ifeq ($(target),sparc-sun-solaris)
include $(srcdir)/Makedefs.gcc
endif
###
### Atari cross compilers
###
ifeq ($(target),cross-mint)
include $(srcdir)/Makedefs.gcc
e = .ttp
CC = m68k-atari-mint-gcc
CXX = m68k-atari-mint-g++
CCARCH += -m68000
endif
ifeq ($(target),cross-mint-m68040)
include $(srcdir)/Makedefs.gcc
e = .ttp
CC = m68k-atari-mint-gcc
CXX = m68k-atari-mint-g++
CCARCH += -m68040
endif
ifeq ($(target),cross-mint-m68020-60)
include $(srcdir)/Makedefs.gcc
e = .ttp
CC = m68k-atari-mint-gcc
CXX = m68k-atari-mint-g++
CCARCH += -m68020-60 -m68881
endif
###
### dos32 - djgpp2 / emx
###
ifeq ($(target),dos32-djgpp2)
include $(srcdir)/Makedefs.gcc
e = .exe
CXX = gxx
CCARCH += -march=i386 -mcpu=i686
CFLAGS_WERROR = -Werror
STUBEDIT_EXE = stubedit $@ bufsize=0xfc00
ifneq ($(strip $(wildcard $(DJDIR)/bin/mfxdjstubify.ex[eE])),)
ifneq ($(strip $(wildcard $(DJDIR)/bin/cwsdstub.ex[eE])),)
STUBIFY_EXE = mfxdjstubify -v -s $(DJDIR)/bin/cwsdstub.exe $@
endif
endif
endif
ifeq ($(target),dos32-emx)
include $(srcdir)/Makedefs.gcc
e = .exe
CXX = gcc
CFLAGS_O = -O2
CCARCH += -mno-probe
LDFLAGS = -L. -s
endif
###
### win32 - cygwin / mingw32 / rsxnt
###
ifeq ($(target),win32-cygwin)
include $(srcdir)/Makedefs.gcc
##CXX = g++-2
e = .exe
CCARCH += -march=i386 -mcpu=i686
LDLIBS += -lwinmm
endif
ifeq ($(target),win32-mingw32)
include $(srcdir)/Makedefs.gcc
e = .exe
CCARCH += -march=i386 -mcpu=i686
LDLIBS += -lwinmm
endif
# mingw32 cross compiler
ifeq ($(target),cross-mingw32)
include $(srcdir)/Makedefs.gcc
e = .exe
CC = i586-mingw32msvc-gcc
CXX = i586-mingw32msvc-g++
CCARCH += -march=i386 -mcpu=i686
LDLIBS += -lwinmm
endif
# rsxnt (g++ 2.8.1)
ifeq ($(target),win32-rsxnt)
include $(srcdir)/Makedefs.gcc
e = .exe
CXX = gcc
CFLAGS_O = -O2
CCARCH += -Zwin32 -Zsys -mno-probe
LDFLAGS = -L. -s
STUBEDIT_EXE = pestack -s1024 -c1024 $@
endif
###
### win32 - Borland C++
###
ifeq ($(target),win32-bc)
o = .obj
a = .lib
e = .exe
CC = bcc32 -3
ifeq ($(UPX_BROKEN_INCLUDES),1)
ifneq ($(srcdir),.)
INCLUDES += -I$(srcdir)
endif
INCLUDES += -I$(srcdir)/acc
ifneq ($(strip $(wildcard $(srcdir)/filter)),)
INCLUDES += -I$(srcdir)/filter
endif
endif
CFLAGS = -w -w-inl -g1
CFLAGS_OUTPUT = -o$@
LDFLAGS = -ls
LINK_EXE_OUTPUT = -e$@
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -Od -d
else
CFLAGS += -O2 -d
endif
endif # win32-bc
###
### win32 - Digital Mars C++
###
ifeq ($(target),win32-dm)
o = .obj
a = .lib
e = .exe
CC = dmc -mn
CFLAGS = -w- -wx
CXXFLAGS = $(CFLAGS) -Aa -Ab -Ae -Ar
CFLAGS_OUTPUT = -o$@
LDFLAGS = -L/map
LINK_EXE_OUTPUT = -o$@
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -o- -g -s
else
CFLAGS += -o
endif
endif # win32-dm
###
### win32 - Intel C++
###
ifeq ($(target),win32-ic)
o = .obj
a = .lib
e = .exe
CC = icl -nologo
CFLAGS = -W3 -WX
CXXFLAGS = $(CFLAGS) -EHac -GR
LDFLAGS =
LINK_EXE_OUTPUT = -Fe$@
LINK_EXE_LDFLAGS = /link /map:$T.map
##LINK_EXE_LDFLAGS += /verbose
ifeq (1,2)
# statically link libcmt.lib
CC += -MT
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
else
# link against msvcrt.dll
CC += -MD
endif
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -Od -ZI
LINK_EXE_LDFLAGS += /debug
else
CFLAGS += -O1 -GF
LINK_EXE_LDFLAGS += /release
endif
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
endif # win32-ic
###
### win32 - Metrowerks C++
###
ifeq ($(target),win32-mwerks)
o = .obj
a = .lib
e = .exe
CC = mwcc -gccinc
CFLAGS = -w on
CXXFLAGS = $(CFLAGS)
CFLAGS_OUTPUT = -o $@
LDFLAGS = -lwinmm.lib -map $T.map
LINK_EXE_OUTPUT = -o $@
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -opt full
else
CFLAGS +=
endif
endif # win32-mwerks
###
### win32 - Symantec C++
###
ifeq ($(target),win32-sc)
o = .obj
a = .lib
e = .exe
CC = sc -mn
CFLAGS = -w- -wx
CXXFLAGS = $(CFLAGS) -EH -ER
CFLAGS_OUTPUT = -o$@
LDFLAGS = -L/map
LINK_EXE_OUTPUT = -o$@
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -o- -g -s
else
CFLAGS += -o
endif
endif # win32-sc
###
### win32 - Visual C++
###
ifeq ($(target),win32-vc)
o = .obj
a = .lib
e = .exe
CC = cl -nologo
CFLAGS = -W4 -WX
CXXFLAGS = $(CFLAGS) -EHac -GR
LDFLAGS =
LINK_EXE_OUTPUT = -Fe$@
LINK_EXE_LDFLAGS = /link /map:$T.map
##LINK_EXE_LDFLAGS += /verbose
ifeq (1,1)
# statically link libcmt.lib
CC += -MT
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
else
# link against msvcrt.dll
CC += -MD
endif
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -Od -ZI
LINK_EXE_LDFLAGS += /debug
else
CFLAGS += -O1 -GF
LINK_EXE_LDFLAGS += /release
##LINK_EXE_LDFLAGS += /opt:nowin98
endif
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
endif # win32-vc
###
### win32 - Watcom C++
###
ifeq ($(target),win32-wc)
o = .obj
a = .lib
e = .exe
CC = wcl386 -zq -bt=nt -mf -5r
##CC = wcl386 -zq -bt=dos -l=CauseWay -mf -5r
CFLAGS = -zc -w5 -we
CXXFLAGS = $(CFLAGS) -xs -xr
CFLAGS_OUTPUT = -fo=$@
LDFLAGS = -k0x100000 -fm
LINK_EXE_OUTPUT = -fe=$@
LDLIBS = $(DOS_LDLIBS)
CC_SRC = $(subst /,\\,$<)
CXX_SRC = $(subst /,\\,$<)
INCLUDES := $(strip $(subst /,\\,$(INCLUDES)))
ifeq (1,2)
WCL386 := $(INCLUDES)
export WCL386
INCLUDES :=
endif
ifeq ($(DEBUG),1)
CFLAGS +=
else
# note: it seems that the optimizer is generating bad code with `-ox'
CFLAGS += -olr
endif
endif # win32-wc
###
### win64 - Intel C++ [Itanium]
###
ifeq ($(target),win64-ic)
o = .obj
a = .lib
e = .exe
CC = ecl -nologo
CFLAGS = -W3
CXXFLAGS = $(CFLAGS) -EHac -GR
LDFLAGS =
LINK_EXE_OUTPUT = -Fe$@
LINK_EXE_LDFLAGS = /link /map:$T.map
##LINK_EXE_LDFLAGS += /verbose
ifeq (1,2)
# statically link libcmt.lib
CC += -MT
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
else
# link against msvcrt.dll
CC += -MD
endif
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -Od -ZI
LINK_EXE_LDFLAGS += /debug
else
CFLAGS += -O1 -GF
LINK_EXE_LDFLAGS += /release
endif
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
endif # win64-ic
###
### win64 - Visual C++ [AMD64 or Itanium]
###
ifeq ($(target),win64-vc)
o = .obj
a = .lib
e = .exe
CC = cl -nologo
CFLAGS = -W4 -Wall
CXXFLAGS = $(CFLAGS) -EHac -GR
LDFLAGS =
LINK_EXE_OUTPUT = -Fe$@
LINK_EXE_LDFLAGS = /link /map:$T.map
##LINK_EXE_LDFLAGS += /verbose
ifeq (1,1)
# statically link libcmt.lib
CC += -MT
## DOS_LDLIBS := $(DOS_LDLIBS:.lib=_ml.lib)
else
# link against msvcrt.dll
CC += -MD
endif
LDLIBS = $(DOS_LDLIBS)
ifeq ($(DEBUG),1)
CFLAGS += -Od -ZI
LINK_EXE_LDFLAGS += /debug
else
CFLAGS += -O1 -GF
LINK_EXE_LDFLAGS += /release
endif
RESOURCES := $(subst .rc,.res,$(notdir $(wildcard $(srcdir)/*.rc)))
endif # win64-vc
# /***********************************************************************
# // malloc debuggers and memory checkers - obsolete, use valgrind
# ************************************************************************/
ifeq (1,2)
# compile in extra valgrind support
DEFS += -DWITH_VALGRIND
endif
ifeq (1,2)
LDLIBS += -lefence
endif
ifeq (1,2)
DEFS += -DWITH_DMALLOC
LDLIBS += -ldmalloc
endif
ifeq (1,2)
DEFS += -DWITH_GC -DLINUX_THREADS -D_REENTRANT
LDLIBS += -lgc -lpthread
# only needed when using -static:
##LDFLAGS += -Wl,-defsym,_DYNAMIC=0
endif
# /***********************************************************************
# // main targets
# ************************************************************************/
-include ./Makefile.local
all: $(upx_exe)
$(upx_exe): $(OBJECTS) $(LIBS) $(RESOURCES)
$(strip $(CXX_LINK_EXE))
$(strip $(STUBEDIT_EXE))
$(strip $(STUBIFY_EXE))
$(strip $(CHMOD_EXE))
mostlyclean:
-rm -f *.d *.err *.i *.log *.map gdb-trans*
clean: mostlyclean
-rm -f *.a *.lib *.o *.obj *.res *.tds tags TAGS ID
-rm -f *.idb *.pdb
-rm -f $(upx_exe) upx upx.exe upx.ttp upx_nrv upx_nrv.exe upx_nrv.ttp upx_ucl upx_ucl.exe upx_ucl.ttp
-rm -rf .deps _deps
distclean: clean
maintainer-clean: distclean
.PHONY: all mostlyclean clean distclean maintainer-clean
# /***********************************************************************
# // rules
# ************************************************************************/
%$o : %.c
$(strip $(CC_COMPILE))
%$o : %.cpp
$(strip $(CXX_COMPILE))
%.res : %.rc
rc -l 0x409 -fo$@ $<
# vi:nowrap
+273 -164
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2005 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -34,132 +34,147 @@
// core // core
**************************************************************************/ **************************************************************************/
inline unsigned get_be16(const void *bb) inline unsigned get_be16(const void *p)
{ {
const unsigned char* b = (const unsigned char*) bb; #if defined(ACC_UA_GET_BE16)
unsigned v; return ACC_UA_GET_BE16(p);
v = (unsigned) b[1] << 0;
v |= (unsigned) b[0] << 8;
return v;
}
inline void set_be16(void *bb, unsigned v)
{
unsigned char* b = (unsigned char*) bb;
b[1] = (unsigned char) (v >> 0);
b[0] = (unsigned char) (v >> 8);
}
inline unsigned get_be24(const void *bb)
{
const unsigned char* b = (const unsigned char*) bb;
unsigned v;
v = (unsigned) b[2] << 0;
v |= (unsigned) b[1] << 8;
v |= (unsigned) b[0] << 16;
return v;
}
inline void set_be24(void *bb, unsigned v)
{
unsigned char* b = (unsigned char*) bb;
b[2] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
b[0] = (unsigned char) (v >> 16);
}
inline unsigned get_be32(const void *bb)
{
const unsigned char* b = (const unsigned char*) bb;
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)
{
unsigned char* b = (unsigned char*) bb;
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 get_le16(const void *bb)
{
#if defined(ACC_GET_LE16)
return ACC_GET_LE16(bb);
#else #else
const unsigned char* b = (const unsigned char*) bb; return acc_ua_get_be16(p);
unsigned v;
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
return v;
#endif #endif
} }
inline void set_le16(void *bb, unsigned v) inline void set_be16(void *p, unsigned v)
{ {
#if defined(ACC_SET_LE16) #if defined(ACC_UA_SET_BE16)
ACC_SET_LE16(bb, v); ACC_UA_SET_BE16(p, v);
#else #else
unsigned char* b = (unsigned char*) bb; acc_ua_set_be16(p, v);
b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
#endif #endif
} }
inline unsigned get_be24(const void *p)
inline unsigned get_le24(const void *bb)
{ {
const unsigned char* b = (const unsigned char*) bb; #if defined(ACC_UA_GET_BE24)
unsigned v; return ACC_UA_GET_BE24(p);
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)
{
unsigned char* b = (unsigned char*) bb;
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)
{
#if defined(ACC_GET_LE32)
return ACC_GET_LE32(bb);
#else #else
const unsigned char* b = (const unsigned char*) bb; return acc_ua_get_be24(p);
unsigned v;
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
v |= (unsigned) b[2] << 16;
v |= (unsigned) b[3] << 24;
return v;
#endif #endif
} }
inline void set_le32(void *bb, unsigned v) inline void set_be24(void *p, unsigned v)
{ {
#if defined(ACC_SET_LE32) #if defined(ACC_UA_SET_BE24)
ACC_SET_LE32(bb, v); ACC_UA_SET_BE24(p, v);
#else #else
unsigned char* b = (unsigned char*) bb; acc_ua_set_be24(p, v);
b[0] = (unsigned char) (v >> 0); #endif
b[1] = (unsigned char) (v >> 8); }
b[2] = (unsigned char) (v >> 16);
b[3] = (unsigned char) (v >> 24); 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 #endif
} }
@@ -170,47 +185,66 @@ inline void set_le32(void *bb, unsigned v)
inline int sign_extend(int v, int bits) inline int sign_extend(int v, int bits)
{ {
const int sign_bit = 1 << (bits - 1); const unsigned sign_bit = 1u << (bits - 1);
v |= -(v & sign_bit); v |= 0u - (v & sign_bit);
return v; return v;
} }
inline int get_be16_signed(const void *bb) inline acc_int64l_t sign_extend(acc_int64l_t v, int bits)
{ {
int v = get_be16(bb); 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); return sign_extend(v, 16);
} }
inline int get_be24_signed(const void *bb) inline int get_be24_signed(const void *p)
{ {
int v = get_be24(bb); int v = get_be24(p);
return sign_extend(v, 24); return sign_extend(v, 24);
} }
inline int get_be32_signed(const void *bb) inline int get_be32_signed(const void *p)
{ {
int v = get_be32(bb); int v = get_be32(p);
return sign_extend(v, 32); return sign_extend(v, 32);
} }
inline int get_le16_signed(const void *bb) inline acc_int64l_t get_be64_signed(const void *p)
{ {
int v = get_le16(bb); 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); return sign_extend(v, 16);
} }
inline int get_le24_signed(const void *bb) inline int get_le24_signed(const void *p)
{ {
int v = get_le24(bb); int v = get_le24(p);
return sign_extend(v, 24); return sign_extend(v, 24);
} }
inline int get_le32_signed(const void *bb) inline int get_le32_signed(const void *p)
{ {
int v = get_le32(bb); int v = get_le32(p);
return sign_extend(v, 32); 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 // classes for portable unaligned access
@@ -227,8 +261,13 @@ struct BE16
BE16& operator = (unsigned v) { set_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; }
BE16& operator *= (unsigned v) { set_be16(d, get_be16(d) * v); return *this; }
BE16& operator /= (unsigned v) { set_be16(d, get_be16(d) / v); return *this; }
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; } BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; } BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
BE16& operator ^= (unsigned v) { set_be16(d, get_be16(d) ^ v); return *this; }
BE16& operator <<= (unsigned v) { set_be16(d, get_be16(d) << v); return *this; }
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
operator unsigned () const { return get_be16(d); } operator unsigned () const { return get_be16(d); }
} }
@@ -242,14 +281,39 @@ struct BE32
BE32& operator = (unsigned v) { set_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; }
BE32& operator *= (unsigned v) { set_be32(d, get_be32(d) * v); return *this; }
BE32& operator /= (unsigned v) { set_be32(d, get_be32(d) / v); return *this; }
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; } BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; } BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
BE32& operator ^= (unsigned v) { set_be32(d, get_be32(d) ^ v); return *this; }
BE32& operator <<= (unsigned v) { set_be32(d, get_be32(d) << v); return *this; }
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
operator unsigned () const { return get_be32(d); } operator unsigned () const { return get_be32(d); }
} }
__attribute_packed; __attribute_packed;
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; }
BE64& operator ^= (acc_uint64l_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; }
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
operator acc_uint64l_t () const { return get_be64(d); }
}
__attribute_packed;
struct LE16 struct LE16
{ {
unsigned char d[2]; unsigned char d[2];
@@ -257,8 +321,13 @@ struct LE16
LE16& operator = (unsigned v) { set_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; }
LE16& operator *= (unsigned v) { set_le16(d, get_le16(d) * v); return *this; }
LE16& operator /= (unsigned v) { set_le16(d, get_le16(d) / v); return *this; }
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; } LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; } LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
LE16& operator ^= (unsigned v) { set_le16(d, get_le16(d) ^ v); return *this; }
LE16& operator <<= (unsigned v) { set_le16(d, get_le16(d) << v); return *this; }
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
operator unsigned () const { return get_le16(d); } operator unsigned () const { return get_le16(d); }
} }
@@ -272,99 +341,139 @@ struct LE32
LE32& operator = (unsigned v) { set_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; }
LE32& operator *= (unsigned v) { set_le32(d, get_le32(d) * v); return *this; }
LE32& operator /= (unsigned v) { set_le32(d, get_le32(d) / v); return *this; }
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; } LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; } LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
LE32& operator ^= (unsigned v) { set_le32(d, get_le32(d) ^ v); return *this; }
LE32& operator <<= (unsigned v) { set_le32(d, get_le32(d) << v); return *this; }
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
operator unsigned () const { return get_le32(d); } operator unsigned () const { return get_le32(d); }
} }
__attribute_packed; __attribute_packed;
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; }
LE64& operator ^= (acc_uint64l_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; }
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
operator acc_uint64l_t () const { return get_le64(d); }
}
__attribute_packed;
/************************************************************************* /*************************************************************************
// global operators // global operators
**************************************************************************/ **************************************************************************/
inline bool operator < (const BE16& v1, const BE16& v2)
{
return (unsigned)v1 < (unsigned)v2;
}
inline bool operator < (const BE32& v1, const BE32& v2)
{
return (unsigned)v1 < (unsigned)v2;
}
inline bool operator < (const LE16& v1, const LE16& v2)
{
return (unsigned)v1 < (unsigned)v2;
}
inline bool operator < (const LE32& v1, const LE32& v2)
{
return (unsigned)v1 < (unsigned)v2;
}
template <class T> template <class T>
inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; } inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }
template <class T> 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 T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }
template <class T> template <class T>
inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; } inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; }
template <class T> 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 T* operator - (T* ptr, const BE32& 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 BE64& v);
template <class T> T* operator + (const BE64& v, T* ptr);
template <class T> T* operator - (T* ptr, const BE64& v);
template <class T> template <class T>
inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; } inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; }
template <class T> 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; } inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }
template <class T> template <class T>
inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; } inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; }
template <class T> 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; } 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);
/************************************************************************* /*************************************************************************
// misc // misc
**************************************************************************/ **************************************************************************/
// for use with qsort() // for use with qsort()
int __acc_cdecl_qsort be16_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 *e1, const void *e2); int __acc_cdecl_qsort be24_compare(const void *, const void *);
int __acc_cdecl_qsort be32_compare(const void *e1, const void *e2); int __acc_cdecl_qsort be32_compare(const void *, const void *);
int __acc_cdecl_qsort le16_compare(const void *e1, const void *e2); int __acc_cdecl_qsort be64_compare(const void *, const void *);
int __acc_cdecl_qsort le24_compare(const void *e1, const void *e2); int __acc_cdecl_qsort le16_compare(const void *, const void *);
int __acc_cdecl_qsort le32_compare(const void *e1, const void *e2); int __acc_cdecl_qsort le24_compare(const void *, const void *);
int __acc_cdecl_qsort be16_compare_signed(const void *e1, const void *e2); int __acc_cdecl_qsort le32_compare(const void *, const void *);
int __acc_cdecl_qsort be24_compare_signed(const void *e1, const void *e2); int __acc_cdecl_qsort le64_compare(const void *, const void *);
int __acc_cdecl_qsort be32_compare_signed(const void *e1, const void *e2); int __acc_cdecl_qsort be16_compare_signed(const void *, const void *);
int __acc_cdecl_qsort le16_compare_signed(const void *e1, const void *e2); int __acc_cdecl_qsort be24_compare_signed(const void *, const void *);
int __acc_cdecl_qsort le24_compare_signed(const void *e1, const void *e2); int __acc_cdecl_qsort be32_compare_signed(const void *, const void *);
int __acc_cdecl_qsort le32_compare_signed(const void *e1, const void *e2); 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... // just for testing...
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_GNUC >= 0x030200) #if !defined(ACC_CFG_NO_UNALIGNED)
typedef unsigned short LE16_unaligned __attribute__((__aligned__(1))); #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))); typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
# ifndef LE16
# define LE16 LE16_unaligned # define LE16 LE16_unaligned
# endif
# ifndef LE32
# define LE32 LE32_unaligned # define LE32 LE32_unaligned
# endif # endif
#if 0 && (ACC_ARCH_IA32) && (ACC_CC_INTELC) #endif
typedef __declspec(align(1)) unsigned short LE16_unaligned; #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; typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
# ifndef LE16
# define LE16 LE16_unaligned # define LE16 LE16_unaligned
# endif
# ifndef LE32
# define LE32 LE32_unaligned # define LE32 LE32_unaligned
# endif # endif
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_IA32) && (ACC_CC_MSC) && (_MSC_VER >= 1200) #endif
typedef __declspec(align(1)) unsigned short LE16_unaligned; #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; typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
# ifndef LE16
# define LE16 LE16_unaligned # define LE16 LE16_unaligned
# endif
# ifndef LE32
# define LE32 LE32_unaligned # define LE32 LE32_unaligned
# endif
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data # pragma warning(disable: 4244) // Wx: conversion, possible loss of data
#endif #endif
#endif
#endif /* already included */ #endif /* already included */
+44 -8
View File
@@ -26,6 +26,20 @@
*/ */
#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
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -89,15 +103,10 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
// prepare bit-buffer settings // prepare bit-buffer settings
conf.bb_endian = 0; conf.bb_endian = 0;
conf.bb_size = 0; conf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16) if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
{ {
int n = (method - M_NRV2B_LE32) % 3; static const unsigned char sizes[3]={32,8,16};
if (n == 0) conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
conf.bb_size = 32;
else if (n == 1)
conf.bb_size = 8;
else
conf.bb_size = 16;
} }
else else
throwInternalError("unknown compression method"); throwInternalError("unknown compression method");
@@ -119,6 +128,11 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len, r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result); cb, level, &conf, result);
#endif #endif
#if 0 /*{*/
else if M_IS_CL1B(method)
r = cl1b_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#endif /*}*/
else else
throwInternalError("unknown compression method"); throwInternalError("unknown compression method");
@@ -171,6 +185,17 @@ int upx_decompress ( const upx_bytep src, upx_uint src_len,
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL); r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break; break;
#endif #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: default:
throwInternalError("unknown decompression method"); throwInternalError("unknown decompression method");
break; break;
@@ -225,6 +250,17 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break; break;
#endif #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: default:
throwInternalError("unknown decompression method"); throwInternalError("unknown decompression method");
break; break;
+1 -3
View File
@@ -32,14 +32,12 @@
#if defined(WITH_NRV) #if defined(WITH_NRV)
# include "compress_nrv.ch" # include "compress_nrv.ch"
#elif defined(WITH_UCL) #elif defined(WITH_UCL)
# define ALG_NRV2E
# define upx_adler32 upx_adler32 # define upx_adler32 upx_adler32
//# define upx_crc32 upx_crc32 //# define upx_crc32 upx_crc32
# define upx_compress upx_compress # define upx_compress upx_compress
# define upx_decompress upx_decompress # define upx_decompress upx_decompress
# if (UPX_VERSION_HEX >= 0x019000)
# define ALG_NRV2E
# define upx_test_overlap upx_test_overlap # define upx_test_overlap upx_test_overlap
# endif
# include "compress.ch" # include "compress.ch"
#else #else
# error # error
+27 -12
View File
@@ -146,7 +146,7 @@
#if !defined(WITH_UCL) #if !defined(WITH_UCL)
# error "please set UCLDIR in the Makefile" # define WITH_UCL 1
#endif #endif
#if defined(WITH_UCL) #if defined(WITH_UCL)
# include <ucl/uclconf.h> # include <ucl/uclconf.h>
@@ -292,10 +292,13 @@
#define index upx_index #define index upx_index
#define outp upx_outp #define outp upx_outp
#undef PAGE_MASK
#undef PAGE_SIZE
#undef __attribute_packed #undef __attribute_packed
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) #if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
# if (1 && (ACC_ARCH_IA32)) # if (1 && (ACC_ARCH_I386))
# define __attribute_packed # define __attribute_packed
# else # else
# define __attribute_packed __attribute__((__packed__,__aligned__(1))) # define __attribute_packed __attribute__((__packed__,__aligned__(1)))
@@ -333,10 +336,10 @@
} }
#endif #endif
#if defined(acc_alignof) #if defined(__acc_alignof)
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \ # define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \ __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \
COMPILE_TIME_ASSERT(acc_alignof(a) == sizeof(b)) COMPILE_TIME_ASSERT(__acc_alignof(a) == sizeof(b))
#else #else
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \ # define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
@@ -423,10 +426,14 @@ inline void operator delete[](void *p)
#define M_NRV2E_LE32 8 #define M_NRV2E_LE32 8
#define M_NRV2E_8 9 #define M_NRV2E_8 9
#define M_NRV2E_LE16 10 #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_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_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_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. // Executable formats. Note: big endian types are >= 128.
@@ -449,8 +456,16 @@ inline void operator delete[](void *p)
#define UPX_F_ELKS_8086 17 #define UPX_F_ELKS_8086 17
#define UPX_F_PS1_EXE 18 #define UPX_F_PS1_EXE 18
#define UPX_F_VMLINUX_i386 19 #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_ATARI_TOS 129
#define UPX_F_SOLARIS_SPARC 130 #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_MAGIC_LE32 0x21585055 /* "UPX!" */
@@ -477,7 +492,7 @@ inline void operator delete[](void *p)
extern const char *progname; extern const char *progname;
void init_options(struct options_t *o); void init_options(struct options_t *o);
bool set_ec(int ec); bool set_ec(int ec);
#if defined(__GNUC__) #if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void e_exit(int ec) __attribute__((__noreturn__)); void e_exit(int ec) __attribute__((__noreturn__));
#else #else
void e_exit(int ec); void e_exit(int ec);
@@ -489,23 +504,23 @@ void printSetNl(int need_nl);
void printClearLine(FILE *f = NULL); void printClearLine(FILE *f = NULL);
void printErr(const char *iname, const Throwable *e); void printErr(const char *iname, const Throwable *e);
void printUnhandledException(const char *iname, const std::exception *e); void printUnhandledException(const char *iname, const std::exception *e);
#if defined(__GNUC__) #if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void __acc_cdecl_va printErr(const char *iname, const char *format, ...) void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
__attribute__((__format__(printf,2,3))); __attribute__((__format__(__printf__,2,3)));
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...) void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
__attribute__((__format__(printf,2,3))); __attribute__((__format__(__printf__,2,3)));
#else #else
void __acc_cdecl_va printErr(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, ...); void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
#endif #endif
#if defined(__GNUC__) #if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
void __acc_cdecl_va infoWarning(const char *format, ...) void __acc_cdecl_va infoWarning(const char *format, ...)
__attribute__((__format__(printf,1,2))); __attribute__((__format__(__printf__,1,2)));
void __acc_cdecl_va infoHeader(const char *format, ...) void __acc_cdecl_va infoHeader(const char *format, ...)
__attribute__((__format__(printf,1,2))); __attribute__((__format__(__printf__,1,2)));
void __acc_cdecl_va info(const char *format, ...) void __acc_cdecl_va info(const char *format, ...)
__attribute__((__format__(printf,1,2))); __attribute__((__format__(__printf__,1,2)));
#else #else
void __acc_cdecl_va infoWarning(const char *format, ...); void __acc_cdecl_va infoWarning(const char *format, ...);
void __acc_cdecl_va infoHeader(const char *format, ...); void __acc_cdecl_va infoHeader(const char *format, ...);
+2
View File
@@ -40,6 +40,8 @@ void File::chmod(const char *name, int mode)
#if defined(HAVE_CHMOD) #if defined(HAVE_CHMOD)
if (::chmod(name,mode) != 0) if (::chmod(name,mode) != 0)
throwIOException(name,errno); throwIOException(name,errno);
#else
UNUSED(name); UNUSED(mode);
#endif #endif
} }
-2
View File
@@ -131,7 +131,6 @@ public:
off_t getBytesWritten() const { return bytes_written; } off_t getBytesWritten() const { return bytes_written; }
#if (UPX_VERSION_HEX >= 0x019000)
// FIXME - these won't work when using the `--stdout' option // FIXME - these won't work when using the `--stdout' option
virtual void seek(off_t off, int whence) virtual void seek(off_t off, int whence)
{ {
@@ -144,7 +143,6 @@ public:
write(buf, len); write(buf, len);
bytes_written -= len; // restore bytes_written -= len; // restore
} }
#endif
// util // util
static void dump(const char *name, const void *buf, int len, int flags=-1); static void dump(const char *name, const void *buf, int len, int flags=-1);
+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
*/
+22
View File
@@ -29,6 +29,12 @@
#include "conf.h" #include "conf.h"
#include "filter.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 set_dummy(p, v) ((void)0)
#define get_8(p) (*(p)) #define get_8(p) (*(p))
@@ -145,6 +151,19 @@
#undef COND_CALL #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
/************************************************************************* /*************************************************************************
// database for use in class Filter // database for use in class Filter
**************************************************************************/ **************************************************************************/
@@ -230,6 +249,9 @@ const FilterImp::FilterEntry FilterImp::filters[] = {
{ 0xb1,99, 0, f_sub32_2, u_sub32_2, s_sub32_2 }, { 0xb1,99, 0, f_sub32_2, u_sub32_2, s_sub32_2 },
{ 0xb2,99, 0, f_sub32_3, u_sub32_3, s_sub32_3 }, { 0xb2,99, 0, f_sub32_3, u_sub32_3, s_sub32_3 },
{ 0xb3,99, 0, f_sub32_4, u_sub32_4, s_sub32_4 }, { 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 = TABLESIZE(filters); const int FilterImp::n_filters = TABLESIZE(filters);
+18 -14
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -48,8 +48,8 @@ void show_head(void)
fg = con_fg(f,FG_GREEN); fg = con_fg(f,FG_GREEN);
con_fprintf(f, con_fprintf(f,
" Ultimate Packer for eXecutables\n" " Ultimate Packer for eXecutables\n"
" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005\n" " Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006\n"
"UPX %-12s Markus F.X.J. Oberhumer & Laszlo Molnar %20s\n\n", "UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
#if (ACC_OS_DOS16 || ACC_OS_DOS32) #if (ACC_OS_DOS16 || ACC_OS_DOS32)
V("d"), V("d"),
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64) #elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
@@ -229,8 +229,6 @@ void show_help(int x)
" --compress-icons=1 compress all but the first icon\n" " --compress-icons=1 compress all but the first icon\n"
" --compress-icons=2 compress all but the first icon directory [default]\n" " --compress-icons=2 compress all but the first icon directory [default]\n"
" --compress-resources=0 do not compress any resources at all\n" " --compress-resources=0 do not compress any resources at all\n"
" --strip-loadconf=0 do not strip SEH load config [default]\n"
" --strip-loadconf=1 strip SEH load config [DANGEROUS]\n"
" --strip-relocs=0 do not strip relocations\n" " --strip-relocs=0 do not strip relocations\n"
" --strip-relocs=1 strip relocations [default]\n" " --strip-relocs=1 strip relocations [default]\n"
" --all-methods try all available compression methods\n" " --all-methods try all available compression methods\n"
@@ -245,6 +243,11 @@ void show_help(int x)
con_fprintf(f,"This version supports:\n"); con_fprintf(f,"This version supports:\n");
fg = con_fg(f,fg); fg = con_fg(f,fg);
con_fprintf(f," " con_fprintf(f," "
// TODO:
// support for mach/ppc32
// support for linux elf/ppc32
// support for linux elf/amd64
" arm/pe,"
" atari/tos," " atari/tos,"
" bvmlinuz/386," " bvmlinuz/386,"
" djgpp2/coff," " djgpp2/coff,"
@@ -253,13 +256,14 @@ void show_help(int x)
" dos/sys," " dos/sys,"
"\n " "\n "
//" elks/8086," //" elks/8086,"
" linux/386," " linux/amd64,"
" linux/elf386," " linux/i386,"
" linux/sh386," " linux/ppc32,"
" mach/ppc32,"
" ps1/exe," " ps1/exe,"
" rtm32/pe," " rtm32/pe,"
" tmt/adam,"
"\n " "\n "
" tmt/adam,"
" vmlinux/386," " vmlinux/386,"
" vmlinuz/386," " vmlinuz/386,"
" watcom/le," " watcom/le,"
@@ -348,10 +352,10 @@ void show_version(int x)
#if defined(WITH_UCL) #if defined(WITH_UCL)
fprintf(f,"UCL data compression library %s\n", ucl_version_string()); fprintf(f,"UCL data compression library %s\n", ucl_version_string());
#endif #endif
fprintf(f,"Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer\n"); fprintf(f,"Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer\n");
fprintf(f,"Copyright (C) 1996-2005 Laszlo Molnar\n"); fprintf(f,"Copyright (C) 1996-2006 Laszlo Molnar\n");
fprintf(f,"Copyright (C) 2000-2005 John F. Reiser\n"); fprintf(f,"Copyright (C) 2000-2006 John F. Reiser\n");
fprintf(f,"Copyright (C) 2002-2005 Jens Medoch\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); fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
} }
+49 -22
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2005 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,33 +22,47 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
#include "conf.h" #include "conf.h"
#include "linker.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 struct Linker::section
{ {
int istart; int istart;
int ostart; int ostart;
int len; int len;
char name[8]; LinkerLabel name;
}; };
struct Linker::jump struct Linker::jump
{ {
int pos; int pos;
int len; int len;
char tsect[8];
int toffs; int toffs;
LinkerLabel tsect;
}; };
Linker::Linker(const void *pdata, int plen, int pinfo) 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); memcpy(iloader,pdata,plen);
oloader = new char[plen]; oloader = new char[plen];
olen = 0; olen = 0;
@@ -57,7 +71,7 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
info = pinfo; info = pinfo;
njumps = nsections = frozen = 0; njumps = nsections = frozen = 0;
jumps = new jump[200]; jumps = new jump[200];
#define NSECTIONS 350 #define NSECTIONS 550
sections = new section[NSECTIONS]; sections = new section[NSECTIONS];
char *p = iloader + info; char *p = iloader + info;
@@ -65,10 +79,10 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
{ {
if (get32(p)) if (get32(p))
{ {
memcpy(sections[nsections].name,p,8); p += sections[nsections].name.set(p);
sections[nsections].istart = get32(p+8); sections[nsections].istart = get32(p);
sections[nsections++].ostart = -1; sections[nsections++].ostart = -1;
p += 12; p += 4;
assert(nsections < NSECTIONS); assert(nsections < NSECTIONS);
} }
else else
@@ -79,9 +93,9 @@ Linker::Linker(const void *pdata, int plen, int pinfo)
jumps[njumps].pos = l+1; jumps[njumps].pos = l+1;
jumps[njumps].len = get32(p+4)-jumps[njumps].pos; jumps[njumps].len = get32(p+4)-jumps[njumps].pos;
memcpy(jumps[njumps].tsect,p+8,8); p += 8 + jumps[njumps].tsect.set(p + 8);
jumps[njumps++].toffs = get32(p+16); jumps[njumps++].toffs = get32(p);
p += 20; p += 4;
assert(njumps < 200); assert(njumps < 200);
} }
} }
@@ -112,11 +126,21 @@ static int hex(char c)
return (c & 0xf) + (c > '9' ? 9 : 0); return (c & 0xf) + (c > '9' ? 9 : 0);
} }
int Linker::addSection(const char *sect) int Linker::addSection(const char *psect)
{ {
int ic; if (psect[0] == 0)
while (*sect) 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 == '+') // alignment
{ {
if (sect[1] == '0') if (sect[1] == '0')
@@ -131,19 +155,22 @@ int Linker::addSection(const char *sect)
} }
else else
{ {
int ic;
for (ic = 0; ic < nsections; 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); memcpy(oloader+olen,iloader+sections[ic].istart,sections[ic].len);
sections[ic].ostart = olen; sections[ic].ostart = olen;
olen += sections[ic].len; olen += sections[ic].len;
break; break;
} }
//printf("%8.8s",sect); if (ic == nsections)
printf("%s", sect);
assert(ic != nsections); assert(ic != nsections);
} }
sect += 8; sect += strlen(sect) + 1;
} }
free(begin);
return olen; return olen;
} }
@@ -151,7 +178,7 @@ int Linker::addSection(const char *sect)
void Linker::addSection(const char *sname, const void *sdata, unsigned len) 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 // 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].istart = ilen;
sections[nsections].len = len; sections[nsections].len = len;
sections[nsections++].ostart = olen; sections[nsections++].ostart = olen;
@@ -177,7 +204,7 @@ const char *Linker::getLoader(int *llen)
continue; continue;
for (kc = 0; kc < nsections-1; kc++) 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; break;
assert(kc!=nsections-1); assert(kc!=nsections-1);
@@ -203,7 +230,7 @@ int Linker::getSection(const char *name, int *slen) const
if (!frozen) if (!frozen)
return -1; return -1;
for (int ic = 0; ic < nsections; ic++) for (int ic = 0; ic < nsections; ic++)
if (memcmp(name,sections[ic].name,8) == 0) if (strcmp(name, sections[ic].name) == 0)
{ {
if (slen) if (slen)
*slen = sections[ic].len; *slen = sections[ic].len;
+110 -40
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -71,12 +71,11 @@ void init_options(struct options_t *o)
for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++) for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++)
o->win32_pe.compress_rt[i] = -1; o->win32_pe.compress_rt[i] = -1;
o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST
o->win32_pe.strip_loadconf = -1;
o->win32_pe.strip_relocs = -1; o->win32_pe.strip_relocs = -1;
} }
static struct options_t global_options; 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_output_name = 0;
static int done_script_name = 0; static int done_script_name = 0;
@@ -444,7 +443,7 @@ static int do_option(int optc, const char *arg)
set_cmd(CMD_DECOMPRESS); set_cmd(CMD_DECOMPRESS);
break; break;
case 'D': case 'D':
opt->debug++; opt->debug.debug_level++;
break; break;
case 'f': case 'f':
opt->force++; opt->force++;
@@ -538,6 +537,23 @@ static int do_option(int optc, const char *arg)
e_method(opt->method, 10); e_method(opt->method, 10);
break; break;
// 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 // misc
case 512: case 512:
opt->console = CON_FILE; opt->console = CON_FILE;
@@ -567,6 +583,7 @@ static int do_option(int optc, const char *arg)
case 522: // --no-filter case 522: // --no-filter
opt->filter = 0; opt->filter = 0;
opt->all_filters = false; opt->all_filters = false;
opt->no_filter = true;
break; break;
case 523: // --all-filters case 523: // --all-filters
opt->all_filters = true; opt->all_filters = true;
@@ -677,10 +694,7 @@ static int do_option(int optc, const char *arg)
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources); //printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
break; break;
case 633: case 633:
opt->win32_pe.strip_loadconf = 1; // opt->win32_pe.strip_loadconf - OBSOLETE - IGNORED
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
opt->win32_pe.strip_loadconf = 0;
//printf("strip_loadconf: %d\n", opt->win32_pe.strip_loadconf);
break; break;
case 634: case 634:
opt->win32_pe.strip_relocs = 1; opt->win32_pe.strip_relocs = 1;
@@ -703,7 +717,13 @@ static int do_option(int optc, const char *arg)
set_script_name(mfx_optarg,1); set_script_name(mfx_optarg,1);
break; break;
case 663: case 663:
opt->o_unix.ptinterp = true; 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; break;
case 670: case 670:
opt->ps1_exe.boot_only = true; opt->ps1_exe.boot_only = true;
@@ -750,7 +770,6 @@ static const struct mfx_option longopts[] =
{"version", 0, 0, 'V'+256}, // display version number {"version", 0, 0, 'V'+256}, // display version number
// options // options
{"debug", 0x10, 0, 'D'},
{"force", 0, 0, 'f'}, // force overwrite of output files {"force", 0, 0, 'f'}, // force overwrite of output files
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files {"force-compress", 0, 0, 'f'}, // and compression of suspicious files
{"info", 0, 0, 'i'}, // info mode {"info", 0, 0, 'i'}, // info mode
@@ -766,6 +785,12 @@ static const struct mfx_option longopts[] =
#endif #endif
{"verbose", 0, 0, 'v'}, // verbose mode {"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 options
{"backup", 0, 0, 'k'}, {"backup", 0, 0, 'k'},
{"keep", 0, 0, 'k'}, {"keep", 0, 0, 'k'},
@@ -823,14 +848,16 @@ static const struct mfx_option longopts[] =
#if 0 #if 0
{"script", 0x31, 0, 662}, // --script= {"script", 0x31, 0, 662}, // --script=
#endif #endif
{"ptinterp", 0, 0, 663}, // linux/elf386 PT_INTERP program {"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 // watcom/le
{"le", 0, 0, 620}, // produce LE output {"le", 0, 0, 620}, // produce LE output
// win32/pe // win32/pe
{"compress-exports", 2, 0, 630}, {"compress-exports", 2, 0, 630},
{"compress-icons", 2, 0, 631}, {"compress-icons", 2, 0, 631},
{"compress-resources", 2, 0, 632}, {"compress-resources", 2, 0, 632},
{"strip-loadconf", 0x12, 0, 633}, {"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634}, {"strip-relocs", 0x12, 0, 634},
// ps1/exe // ps1/exe
{"boot-only", 0x10, 0, 670}, {"boot-only", 0x10, 0, 670},
@@ -912,7 +939,7 @@ static const struct mfx_option longopts[] =
{"compress-exports", 2, 0, 630}, {"compress-exports", 2, 0, 630},
{"compress-icons", 2, 0, 631}, {"compress-icons", 2, 0, 631},
{"compress-resources", 2, 0, 632}, {"compress-resources", 2, 0, 632},
{"strip-loadconf", 0x12, 0, 633}, {"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634}, {"strip-relocs", 0x12, 0, 634},
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
@@ -1028,6 +1055,27 @@ static void first_options(int argc, char **argv)
// assert a sane architecture and compiler // 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);
v1 <<= 1; v1 |= v2; v1 >>= 1; v2 &= v1; v2 /= v1; v2 *= v1;
assert(v1 == 1); assert(v2 == 0);
return (v1 ^ v2) == 1;
}};
#define ACC_WANT_ACC_CHK_CH 1 #define ACC_WANT_ACC_CHK_CH 1
#undef ACCCHK_ASSERT #undef ACCCHK_ASSERT
#include "miniacc.h" #include "miniacc.h"
@@ -1051,40 +1099,67 @@ void upx_sanity_check(void)
COMPILE_TIME_ASSERT(sizeof(BE16) == 2) COMPILE_TIME_ASSERT(sizeof(BE16) == 2)
COMPILE_TIME_ASSERT(sizeof(BE32) == 4) COMPILE_TIME_ASSERT(sizeof(BE32) == 4)
COMPILE_TIME_ASSERT(sizeof(BE64) == 8)
COMPILE_TIME_ASSERT(sizeof(LE16) == 2) COMPILE_TIME_ASSERT(sizeof(LE16) == 2)
COMPILE_TIME_ASSERT(sizeof(LE32) == 4) COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
COMPILE_TIME_ASSERT(sizeof(LE64) == 8)
COMPILE_TIME_ASSERT_ALIGNOF(BE16, char) COMPILE_TIME_ASSERT_ALIGNOF(BE16, char)
COMPILE_TIME_ASSERT_ALIGNOF(BE32, char) COMPILE_TIME_ASSERT_ALIGNOF(BE32, char)
COMPILE_TIME_ASSERT_ALIGNOF(BE64, char)
COMPILE_TIME_ASSERT_ALIGNOF(LE16, char) COMPILE_TIME_ASSERT_ALIGNOF(LE16, char)
COMPILE_TIME_ASSERT_ALIGNOF(LE32, char) COMPILE_TIME_ASSERT_ALIGNOF(LE32, char)
COMPILE_TIME_ASSERT_ALIGNOF(LE64, char)
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1) COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
assert(strlen(UPX_VERSION_STRING4) == 4); assert(strlen(UPX_VERSION_STRING4) == 4);
assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0); 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
const unsigned char dd[4] = { 0xff, 0xfe, 0xfd, 0xfc }; # if 1
assert(upx_adler32(dd, 4) == 0x09f003f7); assert(TestBELE<LE16>::test());
assert(upx_adler32(dd, 4, 0) == 0x09ec03f6); assert(TestBELE<LE32>::test());
assert(upx_adler32(dd, 4, 1) == 0x09f003f7); assert(TestBELE<LE64>::test());
assert(TestBELE<BE16>::test());
assert(get_be16(dd) == 0xfffe); assert(TestBELE<BE32>::test());
assert(get_be16_signed(dd) == -2); assert(TestBELE<BE64>::test());
assert(get_be24(dd) == 0xfffefd); # endif
assert(get_be24_signed(dd) == -259); {
assert(get_be32(dd) == 0xfffefdfc); static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
assert(get_be32_signed(dd) == -66052); 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
assert(get_le16(dd) == 0xfeff); 0, 0, 0, 0,
assert(get_le16_signed(dd) == -257); 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
assert(get_le24(dd) == 0xfdfeff); 0, 0, 0, 0, 0 };
assert(get_le24_signed(dd) == -131329); const unsigned char *d;
assert(get_le32(dd) == 0xfcfdfeff); d = dd + 7;
assert(get_le32_signed(dd) == -50462977); assert(upx_adler32(d, 4) == 0x09f003f7);
assert(find_be16(dd, sizeof(dd), 0xfffe) == 0); assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
assert(find_le16(dd, sizeof(dd), 0xfeff) == 0); assert(upx_adler32(d, 4, 1) == 0x09f003f7);
assert(find_be32(dd, sizeof(dd), 0xfffefdfc) == 0); assert(get_be16(d) == 0xfffe);
assert(find_le32(dd, sizeof(dd), 0xfcfdfeff) == 0); 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 #endif
} }
@@ -1104,11 +1179,6 @@ int __acc_cdecl_main main(int argc, char *argv[])
#if 0 && defined(__DJGPP__) #if 0 && defined(__DJGPP__)
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME // LFN=n may cause problems with 2.03's _rename and mkdir under WinME
putenv("LFN=y"); putenv("LFN=y");
#endif
#if defined(__MINT__)
__binmode(1);
__set_binmode(stdout, 0);
__set_binmode(stderr, 0);
#endif #endif
acc_wildargv(&argc, &argv); acc_wildargv(&argc, &argv);
+6 -4
View File
@@ -60,6 +60,8 @@ static int mcheck_init()
MemBuffer::MemBuffer() : MemBuffer::MemBuffer() :
b(NULL), b_size(0) b(NULL), b_size(0)
{ {
if (use_mcheck < 0)
mcheck_init();
} }
MemBuffer::MemBuffer(unsigned size) : MemBuffer::MemBuffer(unsigned size) :
@@ -87,7 +89,7 @@ void MemBuffer::dealloc()
set_be32(b + b_size, 0); set_be32(b + b_size, 0);
set_be32(b + b_size + 4, 0); set_be32(b + b_size + 4, 0);
// //
::free(b - 8); ::free(b - 16);
} }
else else
::free(b); ::free(b);
@@ -115,7 +117,7 @@ void MemBuffer::allocForUncompression(unsigned uncompressed_size, unsigned extra
unsigned size = uncompressed_size + extra; unsigned size = uncompressed_size + extra;
// size += 512; // 512 safety bytes // size += 512; // 512 safety bytes
// INFO: 3 bytes are the allowed overrun for the i386 asm_fast decompressors // INFO: 3 bytes are the allowed overrun for the i386 asm_fast decompressors
#if (ACC_ARCH_IA32) #if (ACC_ARCH_I386)
size += 3; size += 3;
#endif #endif
alloc(size); alloc(size);
@@ -173,7 +175,7 @@ void MemBuffer::alloc(unsigned size)
assert(b_size == 0); assert(b_size == 0);
// //
assert((int)size > 0); assert((int)size > 0);
unsigned total = use_mcheck ? size + 16 : size; unsigned total = use_mcheck ? size + 32 : size;
assert((int)total > 0); assert((int)total > 0);
unsigned char *p = (unsigned char *) malloc(total); unsigned char *p = (unsigned char *) malloc(total);
if (!p) if (!p)
@@ -185,7 +187,7 @@ void MemBuffer::alloc(unsigned size)
b_size = size; b_size = size;
if (use_mcheck) if (use_mcheck)
{ {
b = p + 8; b = p + 16;
// store magic constants to detect buffer overruns // store magic constants to detect buffer overruns
set_be32(b - 8, b_size); set_be32(b - 8, b_size);
set_be32(b - 4, MAGIC1(b)); set_be32(b - 4, MAGIC1(b));
+2612 -1029
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -66,9 +66,9 @@ void printClearLine(FILE *f)
static void pr_print(bool c, const char *msg) static void pr_print(bool c, const char *msg)
{ {
if (c && !opt->to_stdout) if (c && !opt->to_stdout)
con_fprintf(stderr,msg); con_fprintf(stderr, "%s", msg);
else else
fprintf(stderr,msg); fprintf(stderr, "%s", msg);
} }
static void pr_error(const char *iname, const char *msg, bool is_warning) static void pr_error(const char *iname, const char *msg, bool is_warning)
+13 -4
View File
@@ -51,11 +51,11 @@ struct options_t {
int filter; // preferred filter from Packer::getFilters() int filter; // preferred filter from Packer::getFilters()
bool all_methods; // try all available compression methods ? bool all_methods; // try all available compression methods ?
bool all_filters; // try all available filters ? bool all_filters; // try all available filters ?
bool no_filter; // force no filter
// other options // other options
int backup; int backup;
int console; int console;
int debug;
int force; int force;
int info_mode; int info_mode;
bool ignorewarn; bool ignorewarn;
@@ -66,6 +66,14 @@ struct options_t {
int verbose; int verbose;
bool to_stdout; 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 // overlay handling
enum { enum {
SKIP_OVERLAY = 0, SKIP_OVERLAY = 0,
@@ -116,7 +124,9 @@ struct options_t {
struct { struct {
unsigned blocksize; unsigned blocksize;
bool force_execve; // force the linux/386 execve format bool force_execve; // force the linux/386 execve format
bool ptinterp; // is PT_INTERP, so don't adjust auxv_t bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
bool use_ptinterp; // use PT_INTERP /opt/upx/run
bool make_ptinterp; // make PT_INTERP [ignore current file!]
enum { SCRIPT_MAX = 32 }; enum { SCRIPT_MAX = 32 };
const char *script_name; const char *script_name;
} o_unix; } o_unix;
@@ -128,12 +138,11 @@ struct options_t {
int compress_icons; int compress_icons;
int compress_resources; int compress_resources;
signed char compress_rt[25]; // 25 == RT_LAST signed char compress_rt[25]; // 25 == RT_LAST
int strip_loadconf;
int strip_relocs; int strip_relocs;
} win32_pe; } win32_pe;
}; };
extern struct options_t * volatile opt; extern struct options_t *opt;
#endif /* already included */ #endif /* already included */
+2447
View File
File diff suppressed because it is too large Load Diff
+253
View File
@@ -0,0 +1,253 @@
/* 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;
/*************************************************************************
// arm/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
{ return version == 13; }
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;
bool use_thumb_stub;
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
*/
+6 -6
View File
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -142,15 +142,15 @@ void PackCom::patchLoader(OutputFile *fo,
int PackCom::buildLoader(const Filter *ft) int PackCom::buildLoader(const Filter *ft)
{ {
initLoader(nrv2b_loader,sizeof(nrv2b_loader)); initLoader(nrv2b_loader,sizeof(nrv2b_loader));
addLoader("COMMAIN1""COMSUBSI", addLoader("COMMAIN1,COMSUBSI",
ph.first_offset_found == 1 ? "COMSBBBP" : "", ph.first_offset_found == 1 ? "COMSBBBP" : "",
"COMPSHDI", "COMPSHDI",
ft->id ? "COMCALLT" : "", ft->id ? "COMCALLT" : "",
"COMMAIN2""UPX1HEAD""COMCUTPO""NRV2B160", "COMMAIN2,UPX1HEAD,COMCUTPO,NRV2B160",
ft->id ? "NRVDDONE" : "NRVDRETU", ft->id ? "NRVDDONE" : "NRVDRETU",
"NRVDECO1", "NRVDECO1",
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00", ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
"NRVDECO2""NRV2B169", "NRVDECO2,NRV2B169",
NULL NULL
); );
if (ft->id) if (ft->id)
@@ -170,7 +170,7 @@ void PackCom::addFilter16(int filter_id)
if (filter_id % 3 == 0) if (filter_id % 3 == 0)
addLoader("CALLTR16", addLoader("CALLTR16",
filter_id < 4 ? "CT16SUB0" : "", 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", "CALLTRI2",
getFormat() == UPX_F_DOS_COM ? "CORETURN" : "", getFormat() == UPX_F_DOS_COM ? "CORETURN" : "",
NULL NULL
@@ -180,7 +180,7 @@ void PackCom::addFilter16(int filter_id)
"CALLTRI5", "CALLTRI5",
getFormat() == UPX_F_DOS_COM ? "CT16JEND" : "CT16JUL2", getFormat() == UPX_F_DOS_COM ? "CT16JEND" : "CT16JUL2",
filter_id < 4 ? "CT16SUB1" : "", 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", "CALLTRI6",
NULL NULL
); );
+5 -5
View File
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -53,7 +53,7 @@ PackDjgpp2::PackDjgpp2(InputFile *f) :
COMPILE_TIME_ASSERT(STUBIFY_STUB_ADLER32 == 0xbf689ba8); COMPILE_TIME_ASSERT(STUBIFY_STUB_ADLER32 == 0xbf689ba8);
COMPILE_TIME_ASSERT(STUBIFY_STUB_CRC32 == 0x2ae982b2); COMPILE_TIME_ASSERT(STUBIFY_STUB_CRC32 == 0x2ae982b2);
//printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub))); //printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub)));
assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32); //assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
} }
@@ -86,7 +86,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(nrv_loader, sizeof(nrv_loader)); initLoader(nrv_loader, sizeof(nrv_loader));
addLoader("IDENTSTR""DJ2MAIN1", addLoader("IDENTSTR,DJ2MAIN1",
ft->id ? "DJCALLT1" : "", ft->id ? "DJCALLT1" : "",
"DJ2MAIN2", "DJ2MAIN2",
getDecompressor(), getDecompressor(),
@@ -99,7 +99,7 @@ int PackDjgpp2::buildLoader(const Filter *ft)
addLoader("DJCALLT2", NULL); addLoader("DJCALLT2", NULL);
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("DJRETURN+40DXXXXUPX1HEAD", NULL); addLoader("DJRETURN,+40DXXXX,UPX1HEAD", NULL);
return getLoaderSize(); return getLoaderSize();
} }
@@ -159,7 +159,7 @@ static void handle_allegropak(InputFile *fi, OutputFile *fo)
if (memcmp(buf, "slh+", 4) != 0) if (memcmp(buf, "slh+", 4) != 0)
return; return;
pfsize = get_be32_signed(buf+4); pfsize = get_be32_signed(buf+4);
if (pfsize <= 8 || pfsize >= fi->st.st_size) if (pfsize <= 8 || (off_t) pfsize >= (off_t) fi->st.st_size)
return; return;
fi->seek(-pfsize, SEEK_END); fi->seek(-pfsize, SEEK_END);
} catch (const IOException&) { } catch (const IOException&) {
+267 -56
View File
@@ -34,77 +34,131 @@
// Some ELF type definitinons // Some ELF type definitinons
**************************************************************************/ **************************************************************************/
namespace TT_Elf {
// The ELF file header. This appears at the start of every ELF file. // The ELF file header. This appears at the start of every ELF file.
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 */ unsigned char e_ident[16]; /* Magic number and other info */
LE16 e_type; /* Object file type */ Half e_type; /* Object file type */
LE16 e_machine; /* Architecture */ Half e_machine; /* Architecture */
LE32 e_version; /* Object file version */ Word e_version; /* Object file version */
LE32 e_entry; /* Entry point virtual address */ Addr e_entry; /* Entry point virtual address */
LE32 e_phoff; /* Program header table file offset */ Off e_phoff; /* Program header table file offset */
LE32 e_shoff; /* Section header table file offset */ Off e_shoff; /* Section header table file offset */
LE32 e_flags; /* Processor-specific flags */ Word e_flags; /* Processor-specific flags */
LE16 e_ehsize; /* ELF header size in bytes */ Half e_ehsize; /* ELF header size in bytes */
LE16 e_phentsize; /* Program header table entry size */ Half e_phentsize; /* Program header table entry size */
LE16 e_phnum; /* Program header table entry count */ Half e_phnum; /* Program header table entry count */
LE16 e_shentsize; /* Section header table entry size */ Half e_shentsize; /* Section header table entry size */
LE16 e_shnum; /* Section header table entry count */ Half e_shnum; /* Section header table entry count */
LE16 e_shstrndx; /* Section header string table index */ Half e_shstrndx; /* Section header string table index */
// Values for e_type enum { // e_ident[]
enum { 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_NONE = 0, /* No file type */
ET_REL = 1, /* Relocatable file */ ET_REL = 1, /* Relocatable file */
ET_EXEC = 2, /* Executable file */ ET_EXEC = 2, /* Executable file */
ET_DYN = 3, /* Shared object file */ ET_DYN = 3, /* Shared object file */
ET_CORE = 4 /* Core 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; __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. // Program segment header.
struct Elf_LE32_Phdr template <class Word, class Addr, class Off>
struct Phdr
{ {
LE32 p_type; /* Segment type */ Word p_type; /* Segment type */
LE32 p_offset; /* Segment file offset */ Off p_offset; /* Segment file offset */
LE32 p_vaddr; /* Segment virtual address */ Addr p_vaddr; /* Segment virtual address */
LE32 p_paddr; /* Segment physical address */ Addr p_paddr; /* Segment physical address */
LE32 p_filesz; /* Segment size in file */ Word p_filesz; /* Segment size in file */
LE32 p_memsz; /* Segment size in memory */ Word p_memsz; /* Segment size in memory */
LE32 p_flags; /* Segment flags */ Word p_flags; /* Segment flags */
LE32 p_align; /* Segment alignment */ Word p_align; /* Segment alignment */
// Values for p_type enum { // p_type
enum {
PT_LOAD = 1, /* Loadable program segment */ PT_LOAD = 1, /* Loadable program segment */
PT_DYNAMIC = 2, /* Dynamic linking information */ PT_DYNAMIC = 2, /* Dynamic linking information */
PT_PHDR = 6 /* Entry for header table itself */ PT_INTERP = 3, /* Name of program interpreter */
PT_PHDR = 6, /* Entry for header table itself */
}; };
// Values for p_flags enum { // p_flags
enum { PF_X = (1 << 0) }; /* Segment is executable */ PF_X = 1, /* Segment is executable */
enum { PF_W = (1 << 1) }; /* Segment is writable */ PF_W = 2, /* Segment is writable */
enum { PF_R = (1 << 2) }; /* Segment is readable */ PF_R = 4, /* Segment is readable */
};
} }
__attribute_packed; __attribute_packed;
template <class Word, class Addr, class Off>
struct Elf_LE32_Shdr struct Shdr
{ {
LE32 sh_name; /* Section name (string tbl index) */ Word sh_name; /* Section name (string tbl index) */
LE32 sh_type; /* Section type */ Word sh_type; /* Section type */
LE32 sh_flags; /* Section flags */ Word sh_flags; /* Section flags */
LE32 sh_addr; /* Section virtual addr at execution */ Addr sh_addr; /* Section virtual addr at execution */
LE32 sh_offset; /* Section file offset */ Off sh_offset; /* Section file offset */
LE32 sh_size; /* Section size in bytes */ Word sh_size; /* Section size in bytes */
LE32 sh_link; /* Link to another section */ Word sh_link; /* Link to another section */
LE32 sh_info; /* Additional section information */ Word sh_info; /* Additional section information */
LE32 sh_addralign; /* Section alignment */ Word sh_addralign; /* Section alignment */
LE32 sh_entsize; /* Entry size if section holds table */ Word sh_entsize; /* Entry size if section holds table */
enum { // values for sh_type enum { // sh_type
SHT_NULL = 0, /* Section header table entry unused */ SHT_NULL = 0, /* Section header table entry unused */
SHT_PROGBITS = 1, /* Program data */ SHT_PROGBITS = 1, /* Program data */
SHT_SYMTAB = 2, /* Symbol table */ SHT_SYMTAB = 2, /* Symbol table */
@@ -123,10 +177,10 @@ struct Elf_LE32_Shdr
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */ SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
SHT_GROUP = 17, /* Section group */ SHT_GROUP = 17, /* Section group */
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */ SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
SHT_NUM = 19 /* Number of defined types. */ SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
}; };
enum { // values for sh_flags enum { // sh_flags
SHF_WRITE = (1 << 0), /* Writable */ SHF_WRITE = (1 << 0), /* Writable */
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */ SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
SHF_EXECINSTR = (1 << 2), /* Executable */ SHF_EXECINSTR = (1 << 2), /* Executable */
@@ -138,20 +192,177 @@ struct Elf_LE32_Shdr
} }
__attribute_packed; __attribute_packed;
struct Elf_LE32_Dyn template <class TT16, class TT32, class TT64>
struct Sym
{ {
LE32 d_tag; TT32 st_name; /* symbol name (index into string table) */
LE32 d_val; 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 */
enum { // tags unsigned int st_bind(unsigned int x) const { return 0xf & (x>>4); }
DT_NULL = 0, /* End flag */ unsigned int st_type(unsigned int x) const { return 0xf & x ; }
DT_NEEDED = 1, /* Name of needed library */ unsigned char St_info(unsigned bind, unsigned type) const { return (bind<<4) + (0xf & type); }
DT_STRTAB = 5, /* String table */
DT_STRSZ = 10 /* Sizeof string table */ 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; __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)
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)
#endif /* already included */ #endif /* already included */
+10 -8
View File
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -110,7 +110,7 @@ int PackExe::buildLoader(const Filter *)
initLoader(nrv_loader,sizeof(nrv_loader)); initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("EXEENTRY", addLoader("EXEENTRY",
relocsize ? "EXERELPU" : "", relocsize ? "EXERELPU" : "",
"EXEMAIN4""+G5DXXXX""UPX1HEAD""EXECUTPO", "EXEMAIN4,+G5DXXXX,UPX1HEAD,EXECUTPO",
NULL NULL
); );
if (ph.method == M_NRV2B_8) if (ph.method == M_NRV2B_8)
@@ -122,7 +122,7 @@ int PackExe::buildLoader(const Filter *)
opt->cpu == opt->CPU_8086 ? "N2BX8602" : "N2B28602", opt->cpu == opt->CPU_8086 ? "N2BX8602" : "N2B28602",
"NRV2BEX3", "NRV2BEX3",
ph.c_len > 0xffff ? "N2B64K02" : "", ph.c_len > 0xffff ? "N2B64K02" : "",
"NRV2BEX9""NRV2B16E", "NRV2BEX9,NRV2B16E",
NULL NULL
); );
else if (ph.method == M_NRV2D_8) else if (ph.method == M_NRV2D_8)
@@ -134,7 +134,7 @@ int PackExe::buildLoader(const Filter *)
opt->cpu == opt->CPU_8086 ? "N2DX8602" : "N2D28602", opt->cpu == opt->CPU_8086 ? "N2DX8602" : "N2D28602",
"NRV2DEX3", "NRV2DEX3",
ph.c_len > 0xffff ? "N2D64K02" : "", ph.c_len > 0xffff ? "N2D64K02" : "",
"NRV2DEX9""NRV2D16E", "NRV2DEX9,NRV2D16E",
NULL NULL
); );
else if (ph.method == M_NRV2E_8) else if (ph.method == M_NRV2E_8)
@@ -146,7 +146,7 @@ int PackExe::buildLoader(const Filter *)
opt->cpu == opt->CPU_8086 ? "N2EX8602" : "N2E28602", opt->cpu == opt->CPU_8086 ? "N2EX8602" : "N2E28602",
"NRV2EEX3", "NRV2EEX3",
ph.c_len > 0xffff ? "N2E64K02" : "", ph.c_len > 0xffff ? "N2E64K02" : "",
"NRV2EEX9""NRV2E16E", "NRV2EEX9,NRV2E16E",
NULL NULL
); );
else else
@@ -293,7 +293,9 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
{ {
addr = get_le32(relocs+4*i); addr = get_le32(relocs+4*i);
//printf ("%x\n",es*16+di); //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 // segment change
t = 1+(0xffff-di)/254; t = 1+(0xffff-di)/254;
@@ -409,7 +411,7 @@ void PackExe::pack(OutputFile *fo)
throwCantPack("decompressor limit exceeded, send a bugreport"); throwCantPack("decompressor limit exceeded, send a bugreport");
#ifdef TESTING #ifdef TESTING
if (opt->debug) if (opt->debug.debug_level)
{ {
printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len); printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len);
printf("offsets: %d - %d\nmatches: %d - %d\nruns: %d - %d\n", printf("offsets: %d - %d\nmatches: %d - %d\nruns: %d - %d\n",
@@ -525,7 +527,7 @@ void PackExe::pack(OutputFile *fo)
// write header + write loader + compressed file // write header + write loader + compressed file
#ifdef TESTING #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); printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len);
#endif #endif
fo->write(&oh,sizeof(oh)); fo->write(&oh,sizeof(oh));
+1451 -208
View File
File diff suppressed because it is too large Load Diff
+265 -14
View File
@@ -31,6 +31,256 @@
#define __UPX_P_LX_ELF_H #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 // linux/elf386
**************************************************************************/ **************************************************************************/
@@ -53,29 +303,30 @@ public:
virtual bool canUnpackVersion(int version) const virtual bool canUnpackVersion(int version) const
{ return (version >= 11); } { return (version >= 11); }
protected:
struct Extent {
off_t offset;
off_t size;
};
virtual void packExtent(const Extent &x,
unsigned &total_in, unsigned &total_out, Filter *, OutputFile *);
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 );
protected: protected:
virtual void pack1(OutputFile *, Filter &); // generate executable header virtual void pack1(OutputFile *, Filter &); // generate executable header
virtual void pack2(OutputFile *, Filter &); // append compressed data virtual void pack2(OutputFile *, Filter &); // append compressed data
virtual void pack3(OutputFile *, Filter &); // append loader virtual void pack3(OutputFile *, Filter &); // append loader
virtual void pack4(OutputFile *, Filter &); // append pack header
virtual void patchLoader(); virtual void patchLoader();
Elf_LE32_Ehdr ehdri; // from input file Elf32_Ehdr ehdri; // from input file
Elf_LE32_Phdr *phdri; // for input file Elf32_Phdr *phdri; // for input file
unsigned sz_phdrs; // sizeof Phdr[] 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);
}; };
+119 -63
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2001-2004 John F. Reiser Copyright (C) 2001-2006 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -37,12 +37,14 @@
#include "p_unix.h" #include "p_unix.h"
#include "p_lx_exc.h" #include "p_lx_exc.h"
#define PT_LOAD Elf_LE32_Phdr::PT_LOAD #define PT_LOAD Elf32_Phdr::PT_LOAD
#define PT_DYNAMIC Elf_LE32_Phdr::PT_DYNAMIC #define PT_DYNAMIC Elf32_Phdr::PT_DYNAMIC
#define DT_NULL Elf_LE32_Dyn::DT_NULL #if 0 // UNUSED
#define DT_NEEDED Elf_LE32_Dyn::DT_NEEDED #define DT_NULL Elf32_Dyn::DT_NULL
#define DT_STRTAB Elf_LE32_Dyn::DT_STRTAB #define DT_NEEDED Elf32_Dyn::DT_NEEDED
#define DT_STRSZ Elf_LE32_Dyn::DT_STRSZ #define DT_STRTAB Elf32_Dyn::DT_STRTAB
#define DT_STRSZ Elf32_Dyn::DT_STRSZ
#endif
/************************************************************************* /*************************************************************************
@@ -88,12 +90,13 @@ PackLinuxI386::generateElfHdr(
{ {
cprElfHdr1 *const h1 = (cprElfHdr1 *)&elfout; cprElfHdr1 *const h1 = (cprElfHdr1 *)&elfout;
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout; cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout;
memcpy(h2, proto, sizeof(*h2)); cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout;
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
assert(h2->ehdr.e_phoff == sizeof(Elf_LE32_Ehdr)); assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
assert(h2->ehdr.e_shoff == 0); assert(h2->ehdr.e_shoff == 0);
assert(h2->ehdr.e_ehsize == sizeof(Elf_LE32_Ehdr)); assert(h2->ehdr.e_ehsize == sizeof(Elf32_Ehdr));
assert(h2->ehdr.e_phentsize == sizeof(Elf_LE32_Phdr)); assert(h2->ehdr.e_phentsize == sizeof(Elf32_Phdr));
assert(h2->ehdr.e_shnum == 0); assert(h2->ehdr.e_shnum == 0);
#if 0 //{ #if 0 //{
@@ -105,12 +108,22 @@ PackLinuxI386::generateElfHdr(
// Info for OS kernel to set the brk() // Info for OS kernel to set the brk()
if (brka) { if (brka) {
#define PAGE_MASK (~0ul<<12)
// linux-2.6.14 binfmt_elf.c: SIGKILL if (0==.p_memsz) on a page boundary
unsigned const brkb = brka | ((0==(~PAGE_MASK & brka)) ? 0x20 : 0);
h2->phdr[1].p_type = PT_LOAD; // be sure h2->phdr[1].p_type = PT_LOAD; // be sure
h2->phdr[1].p_offset = 0xfff&brka; h2->phdr[1].p_offset = ~PAGE_MASK & brkb;
h2->phdr[1].p_vaddr = brka; h2->phdr[1].p_vaddr = brkb;
h2->phdr[1].p_paddr = brka; h2->phdr[1].p_paddr = brkb;
h2->phdr[1].p_filesz = 0; h2->phdr[1].p_filesz = 0;
h2->phdr[1].p_memsz = 0; h2->phdr[1].p_memsz = 0;
if (0==h2->phdr[1].p_flags) {
h2->phdr[1].p_flags = Elf32_Phdr::PF_R|Elf32_Phdr::PF_W;
}
if (0==h2->phdr[1].p_align) {
h2->phdr[1].p_align = 0x1000;
}
#undef PAGE_MASK
} }
if (ph.format==UPX_F_LINUX_i386 ) { if (ph.format==UPX_F_LINUX_i386 ) {
@@ -125,10 +138,15 @@ PackLinuxI386::generateElfHdr(
} }
else if (ph.format==UPX_F_LINUX_SH_i386) { else if (ph.format==UPX_F_LINUX_SH_i386) {
assert(h2->ehdr.e_phnum==1); assert(h2->ehdr.e_phnum==1);
h2->ehdr.e_phnum = 2; h2->ehdr.e_phnum = 1;
memset(&h2->linfo, 0, sizeof(h2->linfo)); memset(&h2->linfo, 0, sizeof(h2->linfo));
fo->write(h2, sizeof(*h2)); 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 { else {
assert(false); // unknown ph.format, PackUnix::generateElfHdr assert(false); // unknown ph.format, PackUnix::generateElfHdr
} }
@@ -150,10 +168,10 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) + (elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
sizeof(l_info) + sizeof(l_info) +
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ; ((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 super::pack4(fo, ft); // write PackHeader and overlay_offset
unsigned eod = fo->getBytesWritten();
elfout.phdr[0].p_filesz = eod;
#if 0 // { #if 0 // {
// /usr/bin/strip from RedHat 8.0 (binutils-2.13.90.0.2-2) // /usr/bin/strip from RedHat 8.0 (binutils-2.13.90.0.2-2)
@@ -170,10 +188,11 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
// Supply a "linking view" that covers everything, // Supply a "linking view" that covers everything,
// so that 'strip' does not omit everything. // so that 'strip' does not omit everything.
Elf_LE32_Shdr shdr; Elf32_Shdr shdr;
// The section header string table. // The section header string table.
char const shstrtab[] = "\0.\0.shstrtab"; char const shstrtab[] = "\0.\0.shstrtab";
unsigned eod = elfout.phdr[0].p_filesz;
set_native32(&elfout.ehdr.e_shoff, eod); set_native32(&elfout.ehdr.e_shoff, eod);
set_native16(&elfout.ehdr.e_shentsize, sizeof(shdr)); set_native16(&elfout.ehdr.e_shentsize, sizeof(shdr));
set_native16(&elfout.ehdr.e_shnum, 3); set_native16(&elfout.ehdr.e_shnum, 3);
@@ -181,14 +200,14 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
// An empty Elf32_Shdr for space as a null index. // An empty Elf32_Shdr for space as a null index.
memset(&shdr, 0, sizeof(shdr)); memset(&shdr, 0, sizeof(shdr));
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_NULL); set_native32(&shdr.sh_type, Elf32_Shdr::SHT_NULL);
fo->write(&shdr, sizeof(shdr)); fo->write(&shdr, sizeof(shdr));
// Cover all the bits we need at runtime. // Cover all the bits we need at runtime.
memset(&shdr, 0, sizeof(shdr)); memset(&shdr, 0, sizeof(shdr));
set_native32(&shdr.sh_name, 1); set_native32(&shdr.sh_name, 1);
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_PROGBITS); set_native32(&shdr.sh_type, Elf32_Shdr::SHT_PROGBITS);
set_native32(&shdr.sh_flags, Elf_LE32_Shdr::SHF_ALLOC); set_native32(&shdr.sh_flags, Elf32_Shdr::SHF_ALLOC);
set_native32(&shdr.sh_addr, elfout.phdr[0].p_vaddr); set_native32(&shdr.sh_addr, elfout.phdr[0].p_vaddr);
set_native32(&shdr.sh_offset, overlay_offset); set_native32(&shdr.sh_offset, overlay_offset);
set_native32(&shdr.sh_size, eod - overlay_offset); set_native32(&shdr.sh_size, eod - overlay_offset);
@@ -198,7 +217,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
// A section header for the section header string table. // A section header for the section header string table.
memset(&shdr, 0, sizeof(shdr)); memset(&shdr, 0, sizeof(shdr));
set_native32(&shdr.sh_name, 3); set_native32(&shdr.sh_name, 3);
set_native32(&shdr.sh_type, Elf_LE32_Shdr::SHT_STRTAB); set_native32(&shdr.sh_type, Elf32_Shdr::SHT_STRTAB);
set_native32(&shdr.sh_offset, 3*sizeof(shdr) + eod); set_native32(&shdr.sh_offset, 3*sizeof(shdr) + eod);
set_native32(&shdr.sh_size, sizeof(shstrtab)); set_native32(&shdr.sh_size, sizeof(shstrtab));
fo->write(&shdr, sizeof(shdr)); fo->write(&shdr, sizeof(shdr));
@@ -206,6 +225,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
fo->write(shstrtab, sizeof(shstrtab)); fo->write(shstrtab, sizeof(shstrtab));
#endif // } #endif // }
#undef PAGE_MASK
#define PAGE_MASK (~0u<<12) #define PAGE_MASK (~0u<<12)
// pre-calculate for benefit of runtime disappearing act via munmap() // pre-calculate for benefit of runtime disappearing act via munmap()
elfout.phdr[0].p_memsz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz); elfout.phdr[0].p_memsz = PAGE_MASK & (~PAGE_MASK + elfout.phdr[0].p_filesz);
@@ -213,9 +233,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
// rewrite Elf header // rewrite Elf header
fo->seek(0, SEEK_SET); fo->seek(0, SEEK_SET);
fo->rewrite(&elfout, sizeof(elfout.ehdr) + fo->rewrite(&elfout, overlay_offset);
elfout.ehdr.e_phnum * sizeof(elfout.phdr[0]) +
sizeof(l_info) );
} }
static unsigned static unsigned
@@ -238,21 +256,32 @@ PackLinuxI386::buildLinuxLoader(
{ {
initLoader(proto, szproto); initLoader(proto, szproto);
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
unsigned const fold_hdrlen = umax(0x80, sizeof(hf->ehdr) +
hf->ehdr.e_phentsize * hf->ehdr.e_phnum + sizeof(l_info) );
struct b_info h; memset(&h, 0, sizeof(h)); struct b_info h; memset(&h, 0, sizeof(h));
h.sz_unc = szfold - fold_hdrlen; unsigned fold_hdrlen = 0;
if (0 < szfold) {
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
fold_hdrlen = sizeof(hf->ehdr) + hf->ehdr.e_phentsize * hf->ehdr.e_phnum +
sizeof(l_info);
if (0 == get_le32(fold_hdrlen + fold)) {
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
fold_hdrlen = umax(0x80, fold_hdrlen);
}
h.sz_unc = (szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen);
h.b_method = (unsigned char) ph.method; h.b_method = (unsigned char) ph.method;
h.b_ftid = (unsigned char) ph.filter; h.b_ftid = (unsigned char) ph.filter;
h.b_cto8 = (unsigned char) ph.filter_cto; h.b_cto8 = (unsigned char) ph.filter_cto;
}
unsigned char const *const uncLoader = fold_hdrlen + fold; unsigned char const *const uncLoader = fold_hdrlen + fold;
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc]; unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h.sz_cpr, 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 ); NULL, ph.method, 10, NULL, NULL );
h.sz_cpr = sz_cpr;
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc) if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
throwInternalError("loader compression failed"); throwInternalError("loader compression failed");
}
memcpy(cprLoader, &h, sizeof(h)); memcpy(cprLoader, &h, sizeof(h));
// This adds the definition to the "library", to be used later. // This adds the definition to the "library", to be used later.
@@ -276,71 +305,74 @@ PackLinuxI386::buildLinuxLoader(
// compressed data // compressed data
b_len + ph.c_len ); b_len + ph.c_len );
// entry to stub // entry to stub
addLoader("LEXEC000", 0); addLoader("LEXEC000", NULL);
if (ft->id) { if (ft->id) {
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
addLoader("LXUNF000", 0); addLoader("LXUNF000", NULL);
addLoader("LXUNF002", 0); addLoader("LXUNF002", NULL);
if (0x80==(ft->id & 0xF0)) { if (0x80==(ft->id & 0xF0)) {
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE0", 0); addLoader("MRUBYTE0", NULL);
} }
else if (n_mru) { else if (n_mru) {
addLoader("LXMRU005", 0); addLoader("LXMRU005", NULL);
} }
if (n_mru) { if (n_mru) {
addLoader("LXMRU006", 0); addLoader("LXMRU006", NULL);
} }
else { else {
addLoader("LXMRU007", 0); addLoader("LXMRU007", NULL);
} }
} }
else if (0x40==(ft->id & 0xF0)) { else if (0x40==(ft->id & 0xF0)) {
addLoader("LXUNF008", 0); addLoader("LXUNF008", NULL);
} }
addLoader("LXUNF010", 0); addLoader("LXUNF010", NULL);
} }
if (n_mru) { if (n_mru) {
addLoader("LEXEC009", 0); addLoader("LEXEC009", NULL);
} }
} }
addLoader("LEXEC010", 0); addLoader("LEXEC010", NULL);
addLoader(getDecompressor(), 0); addLoader(getDecompressor(), NULL);
addLoader("LEXEC015", 0); addLoader("LEXEC015", NULL);
if (ft->id) { if (ft->id) {
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
if (0x80!=(ft->id & 0xF0)) { if (0x80!=(ft->id & 0xF0)) {
addLoader("LXUNF042", 0); addLoader("LXUNF042", NULL);
} }
} }
else { // decompr, unfilter not separate else { // decompr, unfilter not separate
if (0x80==(ft->id & 0xF0)) { if (0x80==(ft->id & 0xF0)) {
addLoader("LEXEC110", 0); addLoader("LEXEC110", NULL);
if (n_mru) { if (n_mru) {
addLoader("LEXEC100", 0); addLoader("LEXEC100", NULL);
} }
// bug in APP: jmp and label must be in same .asx/.asy // bug in APP: jmp and label must be in same .asx/.asy
addLoader("LEXEC016", 0); addLoader("LEXEC016", NULL);
} }
} }
addFilter32(ft->id); addFilter32(ft->id);
if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate if (ph.format==UPX_F_LINUX_ELF_i386) { // decompr, unfilter are separate
if (0x80==(ft->id & 0xF0)) { if (0x80==(ft->id & 0xF0)) {
if (0==n_mru) { if (0==n_mru) {
addLoader("LXMRU058", 0); addLoader("LXMRU058", NULL);
} }
} }
addLoader("LXUNF035", 0); addLoader("LXUNF035", NULL);
} }
else { // decompr always unfilters else { // decompr always unfilters
addLoader("LEXEC017", 0); addLoader("LEXEC017", NULL);
} }
} }
else {
addLoader("LEXEC017", NULL);
}
addLoader("IDENTSTR", 0); addLoader("IDENTSTR", NULL);
addLoader("LEXEC020", 0); addLoader("LEXEC020", NULL);
addLoader("FOLDEXEC", 0); addLoader("FOLDEXEC", NULL);
char *ptr_cto = (char *)const_cast<unsigned char *>(getLoader()); char *ptr_cto = (char *)const_cast<unsigned char *>(getLoader());
int sz_cto = getLoaderSize(); int sz_cto = getLoaderSize();
@@ -377,7 +409,14 @@ PackLinuxI386::buildLoader(Filter const *ft)
// filter // filter
optimizeFilter(&fold_ft, buf, sz_fold); optimizeFilter(&fold_ft, buf, sz_fold);
bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2));
unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) +
sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
if (0 == get_le32(fold_hdrlen + buf)) {
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
fold_hdrlen = umax(0x80, fold_hdrlen);
}
bool success = fold_ft.filter(buf + fold_hdrlen, sz_fold - fold_hdrlen);
(void)success; (void)success;
return buildLinuxLoader( return buildLinuxLoader(
@@ -385,6 +424,7 @@ PackLinuxI386::buildLoader(Filter const *ft)
buf, sz_fold, ft ); buf, sz_fold, ft );
} }
// FIXME: getLoaderPrefixSize is unused?
int PackLinuxI386::getLoaderPrefixSize() const int PackLinuxI386::getLoaderPrefixSize() const
{ {
return 116; return 116;
@@ -396,7 +436,7 @@ int PackLinuxI386::getLoaderPrefixSize() const
**************************************************************************/ **************************************************************************/
// basic check of an Linux ELF Ehdr // basic check of an Linux ELF Ehdr
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const int PackLinuxI386::checkEhdr(const Elf32_Ehdr *ehdr) const
{ {
const unsigned char * const buf = ehdr->e_ident; const unsigned char * const buf = ehdr->e_ident;
@@ -406,15 +446,16 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
// now check the ELF header // now check the ELF header
if (!memcmp(buf+8, "FreeBSD", 7)) // branded if (!memcmp(buf+8, "FreeBSD", 7)) // branded
return 1; return 1;
if (ehdr->e_type != 2) // executable if (ehdr->e_type != Elf32_Ehdr::ET_EXEC
&& ehdr->e_type != Elf32_Ehdr::ET_DYN ) // executable
return 2; return 2;
if (ehdr->e_machine != 3) // Intel 80386 if (ehdr->e_machine != Elf32_Ehdr::EM_386) // Intel 80386
return 3; return 3;
if (ehdr->e_version != 1) // version if (ehdr->e_version != Elf32_Ehdr::EV_CURRENT) // version
return 4; return 4;
if (ehdr->e_phnum < 1) if (ehdr->e_phnum < 1)
return 5; return 5;
if (ehdr->e_phentsize != sizeof(Elf_LE32_Phdr)) if (ehdr->e_phentsize != sizeof(Elf32_Phdr))
return 6; return 6;
// check for Linux kernels // check for Linux kernels
@@ -435,7 +476,7 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
} }
off_t PackLinuxI386::getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) const off_t PackLinuxI386::getbrk(const Elf32_Phdr *phdr, int e_phnum) const
{ {
off_t brka = 0; off_t brka = 0;
for (int j = 0; j < e_phnum; ++phdr, ++j) { for (int j = 0; j < e_phnum; ++phdr, ++j) {
@@ -448,6 +489,21 @@ off_t PackLinuxI386::getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) const
return brka; 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;
}
/************************************************************************* /*************************************************************************
// //
@@ -458,7 +514,7 @@ bool PackLinuxI386::canPack()
if (exetype != 0) if (exetype != 0)
return super::canPack(); return super::canPack();
Elf_LE32_Ehdr ehdr; Elf32_Ehdr ehdr;
unsigned char *buf = ehdr.e_ident; unsigned char *buf = ehdr.e_ident;
fi->readx(&ehdr, sizeof(ehdr)); fi->readx(&ehdr, sizeof(ehdr));
+13 -12
View File
@@ -74,8 +74,9 @@ protected:
virtual void updateLoader(OutputFile *); virtual void updateLoader(OutputFile *);
// ELF util // ELF util
virtual int checkEhdr(const Elf_LE32_Ehdr *ehdr) const; virtual int checkEhdr(const Elf32_Ehdr *ehdr) const;
virtual off_t getbrk(const Elf_LE32_Phdr *phdr, int e_phnum) 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 { enum {
UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX" UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
@@ -84,27 +85,27 @@ protected:
unsigned n_mru; unsigned n_mru;
struct cprElfHdr1 { struct cprElfHdr1 {
struct Elf_LE32_Ehdr ehdr; Elf32_Ehdr ehdr;
struct Elf_LE32_Phdr phdr[1]; Elf32_Phdr phdr[1];
struct l_info linfo; l_info linfo;
} }
__attribute_packed; __attribute_packed;
struct cprElfHdr2 { struct cprElfHdr2 {
struct Elf_LE32_Ehdr ehdr; Elf32_Ehdr ehdr;
struct Elf_LE32_Phdr phdr[2]; Elf32_Phdr phdr[2];
struct l_info linfo; l_info linfo;
} }
__attribute_packed; __attribute_packed;
struct cprElfHdr3 { struct cprElfHdr3 {
struct Elf_LE32_Ehdr ehdr; Elf32_Ehdr ehdr;
struct Elf_LE32_Phdr phdr[3]; Elf32_Phdr phdr[3];
struct l_info linfo; l_info linfo;
} }
__attribute_packed; __attribute_packed;
struct cprElfHdr3 elfout; cprElfHdr3 elfout;
}; };
+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
*/
+3 -3
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser Copyright (C) 2000-2006 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
+19 -4
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2004 John F. Reiser Copyright (C) 2000-2006 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -59,6 +59,15 @@ PackLinuxI386sh::~PackLinuxI386sh()
{ {
} }
static unsigned
umax(unsigned a, unsigned b)
{
if (a <= b) {
return b;
}
return a;
}
int int
PackLinuxI386sh::buildLoader(Filter const *ft) PackLinuxI386sh::buildLoader(Filter const *ft)
{ {
@@ -78,7 +87,13 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
// filter // filter
optimizeFilter(&fold_ft, buf, sz_fold); optimizeFilter(&fold_ft, buf, sz_fold);
bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2)); unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) +
sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
if (0 == get_le32(fold_hdrlen + buf)) {
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
fold_hdrlen = umax(0x80, fold_hdrlen);
}
bool success = fold_ft.filter(buf + fold_hdrlen, sz_fold - fold_hdrlen);
UNUSED(success); UNUSED(success);
return buildLinuxLoader( return buildLinuxLoader(
+443
View File
@@ -0,0 +1,443 @@
/* 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);
}
// Determine length of gap between PT_LOAD phdri[k] and closest PT_LOAD
// which follows in the file (or end-of-file). Optimize for common case
// where the PT_LOAD are adjacent ascending by .p_offset. Assume no overlap.
unsigned PackMachPPC32::find_SEGMENT_gap(
unsigned const k
)
{
if (Mach_segment_command::LC_SEGMENT!=msegcmd[k].cmd
|| 0==msegcmd[k].filesize ) {
return 0;
}
unsigned const hi = get_native32(&msegcmd[k].fileoff) +
get_native32(&msegcmd[k].filesize);
unsigned lo = ph.u_file_size;
unsigned j = k;
for (;;) { // circular search, optimize for adjacent ascending
++j;
if (n_segment==j) {
j = 0;
}
if (k==j) {
break;
}
if (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd
&& 0!=msegcmd[j].filesize ) {
unsigned const t = get_native32(&msegcmd[j].fileoff);
if ((t - hi) < (lo - hi)) {
lo = t;
if (hi==lo) {
break;
}
}
}
}
return lo - hi;
}
void
PackMachPPC32::pack2(OutputFile *fo, Filter &ft) // append compressed body
{
Extent x;
unsigned k;
// count passes, set ptload vars
ui_total_passes = 0;
for (k = 0; k < n_segment; ++k) {
if (Mach_segment_command::LC_SEGMENT==msegcmd[k].cmd
&& 0!=msegcmd[k].filesize ) {
ui_total_passes++;
if (find_SEGMENT_gap(k)) {
ui_total_passes++;
}
}
}
// compress extents
unsigned total_in = 0;
unsigned total_out = 0;
unsigned hdr_ulen = mhdri.sizeofcmds;
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, hdr_ulen );
hdr_ulen = 0;
++nx;
}
for (k = 0; k < n_segment; ++k) {
x.size = find_SEGMENT_gap(k);
if (x.size) {
x.offset = get_native32(&msegcmd[k].fileoff) +
get_native32(&msegcmd[k].filesize);
packExtent(x, total_in, total_out, 0, fo);
}
}
if ((off_t)total_in != file_size)
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 const ncmds = mhdr->ncmds;
msegcmd = new Mach_segment_command[ncmds];
unsigned char *ptr = (unsigned char *)(1+mhdr);
for (unsigned j= 0; j < ncmds; ++j) {
msegcmd[j] = *(Mach_segment_command *)ptr;
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize;
}
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command);
n_segment = 0;
for (unsigned j= 0; j < ncmds; ++j) {
n_segment += (Mach_segment_command::LC_SEGMENT==msegcmd[j].cmd);
}
unsigned total_in = 0;
unsigned total_out = 0;
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 < 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));
}
}
for (unsigned j = 0; j < ncmds; ++j) {
unsigned const size = find_SEGMENT_gap(j);
if (size) {
unsigned const where = get_native32(&msegcmd[k].fileoff) +
get_native32(&msegcmd[k].filesize);
if (fo)
fo->seek(where, SEEK_SET);
unpackExtent(size, fo, total_in, total_out,
c_adler, u_adler, false, sizeof(bhdr));
}
}
}
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
*/
+214
View File
@@ -0,0 +1,214 @@
/* 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();
virtual unsigned find_SEGMENT_gap(unsigned const k);
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
*/
+8 -8
View File
@@ -2,9 +2,9 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2002-2004 Jens Medoch Copyright (C) 2002-2006 Jens Medoch
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -77,17 +77,17 @@ static const
PackPs1::PackPs1(InputFile *f) : PackPs1::PackPs1(InputFile *f) :
super(f), super(f),
isCon(true^opt->ps1_exe.boot_only), is32Bit(true^opt->ps1_exe.do_8bit), isCon(!opt->ps1_exe.boot_only), is32Bit(!opt->ps1_exe.do_8bit),
overlap(0), sa_cnt(0) overlap(0), sa_cnt(0)
{ {
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 188); COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 188);
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t)); COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t));
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40); COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40);
#if 1 || defined(WITH_NRV) #if 1 || defined(WITH_NRV)
COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3918); COMPILE_TIME_ASSERT(sizeof(nrv_boot_loader) == 3935);
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0xdf0cbd9e); COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0x0ac25782);
COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2810); COMPILE_TIME_ASSERT(sizeof(nrv_con_loader) == 2829);
COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x31747f8b); COMPILE_TIME_ASSERT(NRV_CON_LOADER_CRC32 == 0x923b55c4);
#endif #endif
fdata_size = file_size - PS_HDR_SIZE; fdata_size = file_size - PS_HDR_SIZE;
} }
+4 -4
View File
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -107,12 +107,12 @@ int PackSys::buildLoader(const Filter *ft)
initLoader(nrv2b_loader,sizeof(nrv2b_loader)); initLoader(nrv2b_loader,sizeof(nrv2b_loader));
addLoader("SYSMAIN1", addLoader("SYSMAIN1",
opt->cpu == opt->CPU_8086 ? "SYSI0861" : "SYSI2861", opt->cpu == opt->CPU_8086 ? "SYSI0861" : "SYSI2861",
"SYSMAIN2""SYSSUBSI", "SYSMAIN2,SYSSUBSI",
ph.first_offset_found == 1 ? "SYSSBBBP" : "", ph.first_offset_found == 1 ? "SYSSBBBP" : "",
ft->id ? "SYSCALLT" : "", ft->id ? "SYSCALLT" : "",
"SYSMAIN3""UPX1HEAD""SYSCUTPO""NRV2B160""NRVDDONE""NRVDECO1", "SYSMAIN3,UPX1HEAD,SYSCUTPO,NRV2B160,NRVDDONE,NRVDECO1",
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00", ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
"NRVDECO2""NRV2B169", "NRVDECO2,NRV2B169",
NULL NULL
); );
if (ft->id) if (ft->id)
+5 -5
View File
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -78,9 +78,9 @@ int PackTmt::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(nrv_loader,sizeof(nrv_loader)); initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("IDENTSTR""TMTMAIN1", addLoader("IDENTSTR,TMTMAIN1",
ft->id ? "TMTCALT1" : "", ft->id ? "TMTCALT1" : "",
"TMTMAIN2""UPX1HEAD""TMTCUTPO""+0XXXXXX", "TMTMAIN2,UPX1HEAD,TMTCUTPO,+0XXXXXX",
getDecompressor(), getDecompressor(),
"TMTMAIN5", "TMTMAIN5",
NULL NULL
@@ -91,9 +91,9 @@ int PackTmt::buildLoader(const Filter *ft)
addLoader("TMTCALT2",NULL); addLoader("TMTCALT2",NULL);
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("TMTRELOC""RELOC320", addLoader("TMTRELOC,RELOC320",
big_relocs ? "REL32BIG" : "", big_relocs ? "REL32BIG" : "",
"RELOC32J""TMTJUMP1", "RELOC32J,TMTJUMP1",
NULL NULL
); );
return getLoaderSize(); return getLoaderSize();
+1
View File
@@ -547,6 +547,7 @@ void PackTos::pack(OutputFile *fo)
// patch loader // patch loader
int tmp = patchPackHeader(loader, o_text); int tmp = patchPackHeader(loader, o_text);
assert(tmp + 32 == (int)o_text); UNUSED(tmp); assert(tmp + 32 == (int)o_text); UNUSED(tmp);
patchVersionYear(loader, o_text);
if (!opt->small) if (!opt->small)
patchVersion(loader, o_text); patchVersion(loader, o_text);
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below // patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
+210 -5
View File
@@ -45,8 +45,8 @@
PackUnix::PackUnix(InputFile *f) : PackUnix::PackUnix(InputFile *f) :
super(f), exetype(0), blocksize(0), overlay_offset(0), lsize(0) super(f), exetype(0), blocksize(0), overlay_offset(0), lsize(0)
{ {
COMPILE_TIME_ASSERT(sizeof(Elf_LE32_Ehdr) == 52); COMPILE_TIME_ASSERT(sizeof(Elf32_Ehdr) == 52);
COMPILE_TIME_ASSERT(sizeof(Elf_LE32_Phdr) == 32); COMPILE_TIME_ASSERT(sizeof(Elf32_Phdr) == 32);
COMPILE_TIME_ASSERT(sizeof(b_info) == 12); COMPILE_TIME_ASSERT(sizeof(b_info) == 12);
COMPILE_TIME_ASSERT(sizeof(l_info) == 12); COMPILE_TIME_ASSERT(sizeof(l_info) == 12);
COMPILE_TIME_ASSERT(sizeof(p_info) == 12); COMPILE_TIME_ASSERT(sizeof(p_info) == 12);
@@ -127,7 +127,7 @@ int PackUnix::getStrategy(Filter &/*ft*/)
// If user specified the filter, then use it (-2==strategy). // If user specified the filter, then use it (-2==strategy).
// Else try the first two filters, and pick the better (2==strategy). // Else try the first two filters, and pick the better (2==strategy).
return ((opt->filter > 0) ? -2 : 2); return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
} }
void PackUnix::pack2(OutputFile *fo, Filter &ft) void PackUnix::pack2(OutputFile *fo, Filter &ft)
@@ -222,6 +222,20 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
} }
} }
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) void PackUnix::pack3(OutputFile *fo, Filter &ft)
{ {
upx_byte const *p = getLoader(); upx_byte const *p = getLoader();
@@ -285,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(). // Generic Unix canUnpack().
**************************************************************************/ **************************************************************************/
@@ -321,7 +526,7 @@ void PackUnix::unpack(OutputFile *fo)
{ {
unsigned szb_info = sizeof(b_info); unsigned szb_info = sizeof(b_info);
{ {
Elf_LE32_Ehdr ehdr; Elf32_Ehdr ehdr;
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
fi->readx(&ehdr, sizeof(ehdr)); fi->readx(&ehdr, sizeof(ehdr));
unsigned const e_entry = get_native32(&ehdr.e_entry); unsigned const e_entry = get_native32(&ehdr.e_entry);
@@ -329,7 +534,7 @@ void PackUnix::unpack(OutputFile *fo)
szb_info = 2*sizeof(unsigned); szb_info = 2*sizeof(unsigned);
} }
else { else {
Elf_LE32_Phdr phdr; Elf32_Phdr phdr;
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET); fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
fi->readx(&phdr, sizeof(phdr)); fi->readx(&phdr, sizeof(phdr));
unsigned const p_vaddr = get_native32(&phdr.p_vaddr); unsigned const p_vaddr = get_native32(&phdr.p_vaddr);
+82 -24
View File
@@ -59,19 +59,35 @@ protected:
virtual void pack4(OutputFile *, Filter &); // append PackHeader virtual void pack4(OutputFile *, Filter &); // append PackHeader
virtual void patchLoader() = 0; virtual void patchLoader() = 0;
virtual void patchLoaderChecksum() {} virtual void patchLoaderChecksum();
virtual void updateLoader(OutputFile *) = 0; virtual void updateLoader(OutputFile *) = 0;
virtual void writePackHeader(OutputFile *fo); virtual void writePackHeader(OutputFile *fo);
// in order too share as much code as possible we introduce // in order too share as much code as possible we introduce
// an endian abstraction here // an endian abstraction here
virtual unsigned get_native32(const void *) = 0; virtual acc_uint64l_t get_native64(const void *) const = 0;
virtual void set_native32(void *, unsigned) = 0; virtual unsigned get_native32(const void *) const = 0;
virtual void set_native16(void *, unsigned) = 0; virtual unsigned get_native16(const void *) const = 0;
virtual void set_native64(void *, acc_uint64l_t) const = 0;
virtual void set_native32(void *, unsigned) const = 0;
virtual void set_native16(void *, unsigned) const = 0;
virtual bool checkCompressionRatio(unsigned, unsigned) const; virtual bool checkCompressionRatio(unsigned, unsigned) const;
protected:
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; int exetype;
unsigned blocksize; unsigned blocksize;
unsigned progid; // program id unsigned progid; // program id
@@ -94,7 +110,6 @@ protected:
unsigned char b_unused; unsigned char b_unused;
} }
__attribute_packed; __attribute_packed;
struct l_info { // 12-byte trailer in header for loader struct l_info { // 12-byte trailer in header for loader
unsigned l_checksum; unsigned l_checksum;
unsigned l_magic; unsigned l_magic;
@@ -111,6 +126,8 @@ protected:
} }
__attribute_packed; __attribute_packed;
struct l_info linfo;
// do not change !!! // do not change !!!
enum { OVERHEAD = 2048 }; enum { OVERHEAD = 2048 };
}; };
@@ -120,24 +137,44 @@ protected:
// abstract classes encapsulating endian issues // abstract classes encapsulating endian issues
// note: UPX_MAGIC is always stored in le32 format // note: UPX_MAGIC is always stored in le32 format
**************************************************************************/ **************************************************************************/
class PackUnixBe32 : public PackUnix class PackUnixBe32 : public PackUnix
{ {
typedef PackUnix super; typedef PackUnix super;
protected: protected:
PackUnixBe32(InputFile *f) : super(f) { } PackUnixBe32(InputFile *f) : super(f) { }
virtual unsigned get_native32(const void *b) 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); }
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) __attribute_packed;
{ struct l_info { // 12-byte trailer in header for loader
set_be32(b, v); BE32 l_checksum;
BE32 l_magic;
BE16 l_lsize;
unsigned char l_version;
unsigned char l_format;
} }
virtual void set_native16(void *b, unsigned v) __attribute_packed;
{
set_be16(b, v); struct p_info { // 12-byte packed program header
BE32 p_progid;
BE32 p_filesize;
BE32 p_blocksize;
} }
__attribute_packed;
}; };
@@ -146,18 +183,39 @@ class PackUnixLe32 : public PackUnix
typedef PackUnix super; typedef PackUnix super;
protected: protected:
PackUnixLe32(InputFile *f) : super(f) { } PackUnixLe32(InputFile *f) : super(f) { }
virtual unsigned get_native32(const void *b) 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); }
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) __attribute_packed;
{ struct l_info { // 12-byte trailer in header for loader
set_le32(b, v); LE32 l_checksum;
LE32 l_magic;
LE16 l_lsize;
unsigned char l_version;
unsigned char l_format;
} }
virtual void set_native16(void *b, unsigned v) __attribute_packed;
{
set_le16(b, v); struct p_info { // 12-byte packed program header
LE32 p_progid;
LE32 p_filesize;
LE32 p_blocksize;
} }
__attribute_packed;
}; };
+25 -25
View File
@@ -23,7 +23,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
John Reiser John Reiser
jreiser@users.sourceforge.net jreiser@users.sourceforge.net
@@ -72,10 +72,10 @@ const int *PackVmlinuxI386::getFilters() const
static int __acc_cdecl_qsort static int __acc_cdecl_qsort
compare_Phdr(void const *aa, void const *bb) compare_Phdr(void const *aa, void const *bb)
{ {
Elf_LE32_Phdr const *const a = (Elf_LE32_Phdr const *)aa; Elf32_Phdr const *const a = (Elf32_Phdr const *)aa;
Elf_LE32_Phdr const *const b = (Elf_LE32_Phdr const *)bb; Elf32_Phdr const *const b = (Elf32_Phdr const *)bb;
unsigned const xa = a->p_type - Elf_LE32_Phdr::PT_LOAD; unsigned const xa = a->p_type - Elf32_Phdr::PT_LOAD;
unsigned const xb = b->p_type - Elf_LE32_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; // PT_LOAD first
if (xa > xb) return 1; 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; // ascending by .p_paddr
@@ -118,14 +118,14 @@ bool PackVmlinuxI386::canPack()
// additional requirements for vmlinux // additional requirements for vmlinux
if (ehdri.e_ehsize != sizeof(ehdri) // different <elf.h> ? if (ehdri.e_ehsize != sizeof(ehdri) // different <elf.h> ?
|| ehdri.e_phoff != sizeof(ehdri) // Phdrs not contiguous with Ehdr || ehdri.e_phoff != sizeof(ehdri) // Phdrs not contiguous with Ehdr
|| ehdri.e_phentsize!=sizeof(Elf_LE32_Phdr) || ehdri.e_phentsize!=sizeof(Elf32_Phdr)
|| ehdri.e_type!=Elf_LE32_Ehdr::ET_EXEC || ehdri.e_type!=Elf32_Ehdr::ET_EXEC
|| 0x00100000!=(0x001fffff & ehdri.e_entry) // entry not an odd 1MB || 0x00100000!=(0x001fffff & ehdri.e_entry) // entry not an odd 1MB
) { ) {
return false; return false;
} }
phdri = new Elf_LE32_Phdr[(unsigned) ehdri.e_phnum]; phdri = new Elf32_Phdr[(unsigned) ehdri.e_phnum];
fi->seek(ehdri.e_phoff, SEEK_SET); fi->seek(ehdri.e_phoff, SEEK_SET);
fi->readx(phdri, ehdri.e_phnum * sizeof(*phdri)); fi->readx(phdri, ehdri.e_phnum * sizeof(*phdri));
@@ -134,7 +134,7 @@ bool PackVmlinuxI386::canPack()
// Check that PT_LOADs form one contiguous chunk of the file. // Check that PT_LOADs form one contiguous chunk of the file.
for (unsigned j = 0; j < ehdri.e_phnum; ++j) { for (unsigned j = 0; j < ehdri.e_phnum; ++j) {
if (Elf_LE32_Phdr::PT_LOAD==phdri[j].p_type) { if (Elf32_Phdr::PT_LOAD==phdri[j].p_type) {
if (0xfff & (phdri[j].p_offset | phdri[j].p_paddr if (0xfff & (phdri[j].p_offset | phdri[j].p_paddr
| phdri[j].p_align | phdri[j].p_vaddr) ) { | phdri[j].p_align | phdri[j].p_vaddr) ) {
return false; return false;
@@ -174,7 +174,7 @@ int PackVmlinuxI386::buildLoader(const Filter *ft)
} }
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX990""IDENTSTR""UPX1HEAD", NULL); addLoader("LINUX990,IDENTSTR,UPX1HEAD", NULL);
return getLoaderSize(); return getLoaderSize();
} }
@@ -182,13 +182,13 @@ int PackVmlinuxI386::buildLoader(const Filter *ft)
void PackVmlinuxI386::pack(OutputFile *fo) void PackVmlinuxI386::pack(OutputFile *fo)
{ {
unsigned fo_off = 0; unsigned fo_off = 0;
Elf_LE32_Ehdr ehdro; Elf32_Ehdr ehdro;
LE32 tmp_le32; LE32 tmp_le32;
// NULL // NULL
// .text(PT_LOADs) .note(1st page) .note(rest) // .text(PT_LOADs) .note(1st page) .note(rest)
// .shstrtab /* .symtab .strtab */ // .shstrtab /* .symtab .strtab */
Elf_LE32_Shdr shdro[1+3+1/*+2*/]; Elf32_Shdr shdro[1+3+1/*+2*/];
memset(shdro, 0, sizeof(shdro)); memset(shdro, 0, sizeof(shdro));
char const shstrtab[]= "\0.text\0.note\0.shstrtab\0.symtab\0.strtab"; char const shstrtab[]= "\0.text\0.note\0.shstrtab\0.symtab\0.strtab";
char const *p = shstrtab; char const *p = shstrtab;
@@ -198,7 +198,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
// .e_ident, .e_machine, .e_version, .e_flags // .e_ident, .e_machine, .e_version, .e_flags
memcpy(&ehdro, &ehdri, sizeof(ehdro)); memcpy(&ehdro, &ehdri, sizeof(ehdro));
ehdro.e_type = Elf_LE32_Ehdr::ET_REL; ehdro.e_type = Elf32_Ehdr::ET_REL;
ehdro.e_entry = 0; ehdro.e_entry = 0;
ehdro.e_phoff = 0; ehdro.e_phoff = 0;
ehdro.e_shoff = 0; // later ehdro.e_shoff = 0; // later
@@ -231,8 +231,8 @@ void PackVmlinuxI386::pack(OutputFile *fo)
while (0!=*p++) ; while (0!=*p++) ;
shdro[1].sh_name = ptr_diff(p, shstrtab); shdro[1].sh_name = ptr_diff(p, shstrtab);
shdro[1].sh_type = Elf_LE32_Shdr::SHT_PROGBITS; shdro[1].sh_type = Elf32_Shdr::SHT_PROGBITS;
shdro[1].sh_flags = Elf_LE32_Shdr::SHF_ALLOC | Elf_LE32_Shdr::SHF_EXECINSTR; shdro[1].sh_flags = Elf32_Shdr::SHF_ALLOC | Elf32_Shdr::SHF_EXECINSTR;
shdro[1].sh_offset = fo_off; shdro[1].sh_offset = fo_off;
shdro[1].sh_size = 1+ 4+ ph.c_len + lsize; shdro[1].sh_size = 1+ 4+ ph.c_len + lsize;
shdro[1].sh_addralign = 1; shdro[1].sh_addralign = 1;
@@ -257,7 +257,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
while (0!=*p++) ; while (0!=*p++) ;
shdro[2].sh_name = ptr_diff(p, shstrtab); shdro[2].sh_name = ptr_diff(p, shstrtab);
shdro[2].sh_type = Elf_LE32_Shdr::SHT_NOTE; shdro[2].sh_type = Elf32_Shdr::SHT_NOTE;
shdro[2].sh_offset = fo_off; shdro[2].sh_offset = fo_off;
shdro[2].sh_size = sizeof(ph.u_len) + ph.c_len; shdro[2].sh_size = sizeof(ph.u_len) + ph.c_len;
shdro[2].sh_addralign = 1; shdro[2].sh_addralign = 1;
@@ -283,7 +283,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
// while (0!=*p++) ; // name is the same // while (0!=*p++) ; // name is the same
shdro[3].sh_name = ptr_diff(p, shstrtab); shdro[3].sh_name = ptr_diff(p, shstrtab);
shdro[3].sh_type = Elf_LE32_Shdr::SHT_NOTE; shdro[3].sh_type = Elf32_Shdr::SHT_NOTE;
shdro[3].sh_offset = fo_off; shdro[3].sh_offset = fo_off;
shdro[3].sh_size = sizeof(ph.u_len) + ph.c_len; shdro[3].sh_size = sizeof(ph.u_len) + ph.c_len;
shdro[3].sh_addralign = 1; shdro[3].sh_addralign = 1;
@@ -292,7 +292,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
while (0!=*p++) ; while (0!=*p++) ;
shdro[4].sh_name = ptr_diff(p, shstrtab); shdro[4].sh_name = ptr_diff(p, shstrtab);
shdro[4].sh_type = Elf_LE32_Shdr::SHT_STRTAB; shdro[4].sh_type = Elf32_Shdr::SHT_STRTAB;
shdro[4].sh_offset = fo_off; shdro[4].sh_offset = fo_off;
shdro[4].sh_size = 1+ sizeof(shstrtab); // 1+: terminating '\0' shdro[4].sh_size = 1+ sizeof(shstrtab); // 1+: terminating '\0'
shdro[4].sh_addralign = 1; shdro[4].sh_addralign = 1;
@@ -302,7 +302,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
while (0!=*p++) ; while (0!=*p++) ;
fo_off = ~3 & (3+ fo_off); fo_off = ~3 & (3+ fo_off);
shdro[5].sh_name = ptr_diff(p, shstrtab); shdro[5].sh_name = ptr_diff(p, shstrtab);
shdro[5].sh_type = Elf_LE32_Shdr::SHT_SYMTAB; shdro[5].sh_type = Elf32_Shdr::SHT_SYMTAB;
shdro[5].sh_offset = fo_off; shdro[5].sh_offset = fo_off;
shdro[5].sh_size = 16; // XXX ? shdro[5].sh_size = 16; // XXX ?
shdro[5].sh_link = 6; // to .strtab for symbols shdro[5].sh_link = 6; // to .strtab for symbols
@@ -313,7 +313,7 @@ void PackVmlinuxI386::pack(OutputFile *fo)
while (0!=*p++) ; while (0!=*p++) ;
shdro[6].sh_name = ptr_diff(p, shstrtab); shdro[6].sh_name = ptr_diff(p, shstrtab);
shdro[6].sh_type = Elf_LE32_Shdr::SHT_STRTAB; shdro[6].sh_type = Elf32_Shdr::SHT_STRTAB;
shdro[6].sh_offset = fo_off; shdro[6].sh_offset = fo_off;
shdro[6].sh_size = 1; // XXX ? shdro[6].sh_size = 1; // XXX ?
shdro[6].sh_addralign = 1; shdro[6].sh_addralign = 1;
@@ -347,21 +347,21 @@ int PackVmlinuxI386::canUnpack()
|| !memcmp(&ehdri.e_ident[8], "FreeBSD", 7) // branded || !memcmp(&ehdri.e_ident[8], "FreeBSD", 7) // branded
|| ehdri.e_machine != 3 // Intel 80386 || ehdri.e_machine != 3 // Intel 80386
|| ehdri.e_version != 1 // version || ehdri.e_version != 1 // version
|| ehdri.e_type != Elf_LE32_Ehdr::ET_REL || ehdri.e_type != Elf32_Ehdr::ET_REL
|| ehdri.e_shnum < 4 || ehdri.e_shnum < 4
|| (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf_LE32_Shdr) + ehdri.e_shoff) || (unsigned)file_size < (ehdri.e_shnum * sizeof(Elf32_Shdr) + ehdri.e_shoff)
) )
return false; return false;
// find the .shstrtab section // find the .shstrtab section
char shstrtab[40]; char shstrtab[40];
Elf_LE32_Shdr *p, *p_shstrtab=0; Elf32_Shdr *p, *p_shstrtab=0;
shdri = new Elf_LE32_Shdr[(unsigned) ehdri.e_shnum]; shdri = new Elf32_Shdr[(unsigned) ehdri.e_shnum];
fi->seek(ehdri.e_shoff, SEEK_SET); fi->seek(ehdri.e_shoff, SEEK_SET);
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri)); fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
int j; int j;
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) { for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if (Elf_LE32_Shdr::SHT_STRTAB==p->sh_type if (Elf32_Shdr::SHT_STRTAB==p->sh_type
&& p->sh_size <= sizeof(shstrtab) && p->sh_size <= sizeof(shstrtab)
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size && (p->sh_size + p->sh_offset) <= (unsigned) file_size
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab") && (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
+6 -6
View File
@@ -60,12 +60,12 @@ protected:
int n_ptload; int n_ptload;
unsigned sz_ptload; unsigned sz_ptload;
Elf_LE32_Phdr *phdri; // from input file Elf32_Phdr *phdri; // from input file
Elf_LE32_Shdr *shdri; // from input file Elf32_Shdr *shdri; // from input file
Elf_LE32_Shdr *p_text; Elf32_Shdr *p_text;
Elf_LE32_Shdr *p_note0; Elf32_Shdr *p_note0;
Elf_LE32_Shdr *p_note1; Elf32_Shdr *p_note1;
Elf_LE32_Ehdr ehdri; // from input file Elf32_Ehdr ehdri; // from input file
}; };
+4 -4
View File
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -262,7 +262,7 @@ int PackVmlinuzI386::buildLoader(const Filter *ft)
addLoader("LZCALLT9", NULL); addLoader("LZCALLT9", NULL);
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUZ990""IDENTSTR""UPX1HEAD", NULL); addLoader("LINUZ990,IDENTSTR,UPX1HEAD", NULL);
return getLoaderSize(); return getLoaderSize();
} }
@@ -319,10 +319,10 @@ int PackBvmlinuzI386::buildLoader(const Filter *ft)
initLoader(nrv_loader, sizeof(nrv_loader)); initLoader(nrv_loader, sizeof(nrv_loader));
addLoader("LINUZ000", addLoader("LINUZ000",
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""), (0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
"LBZIMAGE""IDENTSTR", "LBZIMAGE,IDENTSTR",
"+40D++++", // align the stuff to 4 byte boundary "+40D++++", // align the stuff to 4 byte boundary
"UPX1HEAD", // 32 byte "UPX1HEAD", // 32 byte
"LZCUTPOI""+0000000", "LZCUTPOI,+0000000",
getDecompressor(), getDecompressor(),
NULL NULL
); );
+140 -35
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -152,12 +152,18 @@ PackW32Pe::PackW32Pe(InputFile *f) : super(f)
otls = NULL; otls = NULL;
oresources = NULL; oresources = NULL;
oxrelocs = NULL; oxrelocs = NULL;
oloadconf = NULL;
icondir_offset = 0; icondir_offset = 0;
icondir_count = 0; icondir_count = 0;
importbyordinal = false; importbyordinal = false;
kernel32ordinal = false; kernel32ordinal = false;
tlsindex = 0; tlsindex = 0;
big_relocs = 0; big_relocs = 0;
sorelocs = 0;
soxrelocs = 0;
soloadconf = 0;
use_dep_hack = true;
use_clear_dirty_stack = true;
} }
@@ -171,6 +177,7 @@ PackW32Pe::~PackW32Pe()
delete [] otls; delete [] otls;
delete [] oresources; delete [] oresources;
delete [] oxrelocs; delete [] oxrelocs;
delete [] oloadconf;
//delete res; //delete res;
} }
@@ -544,7 +551,9 @@ void PackW32Pe::processImports(unsigned myimport) // pass 2
unsigned PackW32Pe::processImports() // pass 1 unsigned PackW32Pe::processImports() // pass 1
{ {
static const unsigned char kernel32dll[] = "KERNEL32.DLL"; static const unsigned char kernel32dll[] = "KERNEL32.DLL";
static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0""GetProcAddress\x0\x0"; static const char llgpa[] = "\x0\x0""LoadLibraryA\x0\x0"
"GetProcAddress\x0\x0"
"VirtualProtect\x0\x0";
static const char exitp[] = "ExitProcess\x0\x0\x0"; static const char exitp[] = "ExitProcess\x0\x0\x0";
unsigned dllnum = 0; unsigned dllnum = 0;
@@ -566,7 +575,6 @@ unsigned PackW32Pe::processImports() // pass 1
LE32 *lookupt; LE32 *lookupt;
unsigned npos; unsigned npos;
bool isk32; bool isk32;
unsigned _; // padding to 32
static int __acc_cdecl_qsort compare(const void *p1, const void *p2) static int __acc_cdecl_qsort compare(const void *p1, const void *p2)
{ {
@@ -582,8 +590,7 @@ unsigned PackW32Pe::processImports() // pass 1
if (!u2->shname) return -1; if (!u2->shname) return -1;
return strlen(u1->shname) - strlen(u2->shname); return strlen(u1->shname) - strlen(u2->shname);
} }
} };
__attribute_packed;
// +1 for dllnum=0 // +1 for dllnum=0
Array(struct udll, dlls, dllnum+1); Array(struct udll, dlls, dllnum+1);
@@ -648,7 +655,7 @@ unsigned PackW32Pe::processImports() // pass 1
im = (import_desc*) oimpdlls; im = (import_desc*) oimpdlls;
LE32 *ordinals = (LE32*) (oimpdlls + (dllnum2 + 1) * sizeof(import_desc)); LE32 *ordinals = (LE32*) (oimpdlls + (dllnum2 + 1) * sizeof(import_desc));
LE32 *lookuptable = ordinals + 3 + k32o + (isdll ? 0 : 1); LE32 *lookuptable = ordinals + 4 + k32o + (isdll ? 0 : 1);
upx_byte *dllnames = ((upx_byte*) lookuptable) + (dllnum2 - 1) * 8; upx_byte *dllnames = ((upx_byte*) lookuptable) + (dllnum2 - 1) * 8;
upx_byte *importednames = dllnames + (dllnamelen &~ 1); upx_byte *importednames = dllnames + (dllnamelen &~ 1);
@@ -660,10 +667,11 @@ unsigned PackW32Pe::processImports() // pass 1
strcpy(dllnames,kernel32dll); strcpy(dllnames,kernel32dll);
im->dllname = k32namepos; im->dllname = k32namepos;
im->iat = ptr_diff(ordinals,oimpdlls); im->iat = ptr_diff(ordinals,oimpdlls);
*ordinals++ = ptr_diff(importednames,oimpdlls); *ordinals++ = ptr_diff(importednames,oimpdlls); // LoadLibraryA
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14; *ordinals++ = ptr_diff(importednames,oimpdlls) + 14; // GetProcAddress
*ordinals++ = ptr_diff(importednames,oimpdlls) + 14 + 16; // VirtualProtect
if (!isdll) if (!isdll)
*ordinals++ = ptr_diff(importednames,oimpdlls) + sizeof(llgpa) - 3; *ordinals++ = ptr_diff(importednames,oimpdlls) + sizeof(llgpa) - 3; // ExitProcess
dllnames += sizeof(kernel32dll); dllnames += sizeof(kernel32dll);
importednames += sizeof(llgpa) - 2 + (isdll ? 0 : sizeof(exitp) - 1); importednames += sizeof(llgpa) - 2 + (isdll ? 0 : sizeof(exitp) - 1);
@@ -758,7 +766,7 @@ unsigned PackW32Pe::processImports() // pass 1
soimport = 0; soimport = 0;
//OutputFile::dump("x0.imp", oimport, soimport); //OutputFile::dump("x0.imp", oimport, soimport);
//OutputFile::dump("x1.imp", oimpdlls, soimpdlss); //OutputFile::dump("x1.imp", oimpdlls, soimpdlls);
unsigned ilen = 0; unsigned ilen = 0;
names.flatten(); names.flatten();
@@ -1476,6 +1484,53 @@ void PackW32Pe::processResources(Resource *res)
} }
/*************************************************************************
// Load Configuration handling
**************************************************************************/
void PackW32Pe::processLoadConf(Interval *iv) // pass 1
{
if (IDSIZE(PEDIR_LOADCONF) == 0)
return;
const unsigned lcaddr = IDADDR(PEDIR_LOADCONF);
const upx_byte * const loadconf = ibuf + lcaddr;
soloadconf = get_le32(loadconf);
if (soloadconf == 0)
return;
if (soloadconf > 256)
throwCantPack("size of Load Configuration directory unexpected");
// if there were relocation entries referring to the load config table
// then we need them for the copy of the table too
unsigned pos,type;
Reloc rel(ibuf + IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC));
while (rel.next(pos, type))
if (pos >= lcaddr && pos < lcaddr + soloadconf)
{
iv->add(pos - lcaddr, type);
// printf("loadconf reloc detected: %x\n", pos);
}
oloadconf = new upx_byte[soloadconf];
memcpy(oloadconf, loadconf, soloadconf);
}
void PackW32Pe::processLoadConf(Reloc *rel, const Interval *iv,
unsigned newaddr) // pass2
{
// now we have the address of the new load config table
// so we can create the new relocation entries
for (unsigned ic = 0; ic < iv->ivnum; ic++)
{
rel->add(iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
//printf("loadconf reloc added: %x %d\n",
// iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
}
}
//
unsigned PackW32Pe::virta2objnum(unsigned addr,pe_section_t *sect,unsigned objs) unsigned PackW32Pe::virta2objnum(unsigned addr,pe_section_t *sect,unsigned objs)
{ {
unsigned ic; unsigned ic;
@@ -1579,7 +1634,7 @@ int PackW32Pe::buildLoader(const Filter *ft)
if (sorelocs) if (sorelocs)
{ {
addLoader(soimport == 0 || soimport + cimports != crelocs ? "PERELOC1" : "PERELOC2", addLoader(soimport == 0 || soimport + cimports != crelocs ? "PERELOC1" : "PERELOC2",
"PERELOC3""RELOC320", "PERELOC3,RELOC320",
big_relocs ? "REL32BIG" : "", big_relocs ? "REL32BIG" : "",
"RELOC32J", "RELOC32J",
NULL NULL
@@ -1591,9 +1646,14 @@ int PackW32Pe::buildLoader(const Filter *ft)
NULL NULL
); );
} }
addLoader("PEMAIN20", if (use_dep_hack)
ih.entry ? "PEDOJUMP" : "PERETURN", addLoader("PEDEPHAK", NULL);
"IDENTSTR""UPX1HEAD", addLoader("PEMAIN20", NULL);
if (use_clear_dirty_stack)
addLoader(ih.entry ? "PEDOJUMP_CLEARSTACK" : "PERETURN_CLEARSTACK", NULL);
addLoader("PEMAIN21", NULL);
addLoader(ih.entry ? "PEDOJUMP" : "PERETURN",
"IDENTSTR,UPX1HEAD",
NULL NULL
); );
return getLoaderSize(); return getLoaderSize();
@@ -1602,9 +1662,6 @@ int PackW32Pe::buildLoader(const Filter *ft)
void PackW32Pe::pack(OutputFile *fo) void PackW32Pe::pack(OutputFile *fo)
{ {
if (opt->win32_pe.strip_loadconf < 0)
opt->win32_pe.strip_loadconf = false;
const unsigned objs = ih.objects; const unsigned objs = ih.objects;
isection = new pe_section_t[objs]; isection = new pe_section_t[objs];
fi->seek(pe_offset+sizeof(ih),SEEK_SET); fi->seek(pe_offset+sizeof(ih),SEEK_SET);
@@ -1617,12 +1674,12 @@ void PackW32Pe::pack(OutputFile *fo)
// check the PE header // check the PE header
// FIXME: add more checks // FIXME: add more checks
if (!opt->force && ( if (!opt->force && (
ih.cpu < 0x14c || ih.cpu > 0x150 (ih.cpu < 0x14c || ih.cpu > 0x150)
|| ih.opthdrsize != 0xE0 || (ih.opthdrsize != 0xe0)
|| (ih.flags & EXECUTABLE) == 0 || ((ih.flags & EXECUTABLE) == 0)
|| (ih.subsystem != 2 && ih.subsystem != 3 && ih.subsystem != 1) || (ih.subsystem != 2 && ih.subsystem != 3 && ih.subsystem != 1)
|| (ih.entry == 0 && !isdll) || (ih.entry == 0 && !isdll)
|| ih.ddirsentries != 16 || (ih.ddirsentries != 16)
|| IDSIZE(PEDIR_EXCEPTION) // is this used on i386? || IDSIZE(PEDIR_EXCEPTION) // is this used on i386?
// || IDSIZE(PEDIR_COPYRIGHT) // || IDSIZE(PEDIR_COPYRIGHT)
)) ))
@@ -1633,10 +1690,6 @@ void PackW32Pe::pack(OutputFile *fo)
if (IDSIZE(PEDIR_COMRT)) if (IDSIZE(PEDIR_COMRT))
throwCantPack(".NET files (win32/net) are not yet supported"); throwCantPack(".NET files (win32/net) are not yet supported");
// Structured Exception Handling
if (!opt->win32_pe.strip_loadconf && IDSIZE(PEDIR_LOADCONF))
throwCantPack("Structured Exception Handling present (try --strip-loadconf)");
if (isdll) if (isdll)
opt->win32_pe.strip_relocs = false; opt->win32_pe.strip_relocs = false;
else if (opt->win32_pe.strip_relocs < 0) else if (opt->win32_pe.strip_relocs < 0)
@@ -1660,7 +1713,7 @@ void PackW32Pe::pack(OutputFile *fo)
handleStub(fi,fo,pe_offset); handleStub(fi,fo,pe_offset);
const unsigned usize = ih.imagesize; const unsigned usize = ih.imagesize;
const unsigned xtrasize = 65536+IDSIZE(PEDIR_IMPORT)+IDSIZE(PEDIR_BOUNDIM)+IDSIZE(PEDIR_IAT)+IDSIZE(PEDIR_DELAYIMP)+IDSIZE(PEDIR_RELOC); const unsigned xtrasize = UPX_MAX(ih.datasize, 65536u) + IDSIZE(PEDIR_IMPORT) + IDSIZE(PEDIR_BOUNDIM) + IDSIZE(PEDIR_IAT) + IDSIZE(PEDIR_DELAYIMP) + IDSIZE(PEDIR_RELOC);
ibuf.alloc(usize + xtrasize); ibuf.alloc(usize + xtrasize);
// BOUND IMPORT support. FIXME: is this ok? // BOUND IMPORT support. FIXME: is this ok?
@@ -1697,6 +1750,8 @@ void PackW32Pe::pack(OutputFile *fo)
jc = isection[ic].vsize; jc = isection[ic].vsize;
if (isection[ic].vsize == 0) // hack for some tricky programs - may this break other progs? if (isection[ic].vsize == 0) // hack for some tricky programs - may this break other progs?
jc = isection[ic].vsize = isection[ic].size; jc = isection[ic].vsize = isection[ic].size;
if (isection[ic].vaddr + jc > ibuf.getSize())
throwInternalError("buffer too small 1");
fi->readx(ibuf + isection[ic].vaddr,jc); fi->readx(ibuf + isection[ic].vaddr,jc);
jc += isection[ic].rawdataptr; jc += isection[ic].rawdataptr;
} }
@@ -1720,12 +1775,14 @@ void PackW32Pe::pack(OutputFile *fo)
Resource res; Resource res;
Interval tlsiv(ibuf); Interval tlsiv(ibuf);
Interval loadconfiv(ibuf);
Export xport((char*)(unsigned char*)ibuf); Export xport((char*)(unsigned char*)ibuf);
const unsigned dllstrings = processImports(); const unsigned dllstrings = processImports();
processTls(&tlsiv); // call before processRelocs!! processTls(&tlsiv); // call before processRelocs!!
processResources(&res); processResources(&res);
processExports(&xport); processExports(&xport);
processLoadConf(&loadconfiv);
processRelocs(); processRelocs();
//OutputFile::dump("x1", ibuf, usize); //OutputFile::dump("x1", ibuf, usize);
@@ -1748,6 +1805,8 @@ void PackW32Pe::pack(OutputFile *fo)
unsigned newvsize = (isection[objs-1].vaddr + isection[objs-1].vsize + oam1) &~ oam1; unsigned newvsize = (isection[objs-1].vaddr + isection[objs-1].vsize + oam1) &~ oam1;
//fprintf(stderr,"newvsize=%x objs=%d\n",newvsize,objs); //fprintf(stderr,"newvsize=%x objs=%d\n",newvsize,objs);
if (newvsize + soimport + sorelocs > ibuf.getSize())
throwInternalError("buffer too small 2");
memcpy(ibuf+newvsize,oimport,soimport); memcpy(ibuf+newvsize,oimport,soimport);
memcpy(ibuf+newvsize+soimport,orelocs,sorelocs); memcpy(ibuf+newvsize+soimport,orelocs,sorelocs);
@@ -1846,6 +1905,45 @@ void PackW32Pe::pack(OutputFile *fo)
unsigned jmp_pos = find_le32(loader,codesize + 4,get_le32("JMPO")); unsigned jmp_pos = find_le32(loader,codesize + 4,get_le32("JMPO"));
patch_le32(loader,codesize + 4,"JMPO",ih.entry - upxsection - jmp_pos - 4); patch_le32(loader,codesize + 4,"JMPO",ih.entry - upxsection - jmp_pos - 4);
} }
if (use_dep_hack)
{
// This works around a "protection" introduced in MSVCRT80, which
// works like this:
// When the compiler detects that it would link in some code from its
// C runtime library which references some data in a read only
// section then it compiles in a runtime check whether that data is
// still in a read only section by looking at the pe header of the
// file. If this check fails the runtime does "interesting" things
// like not running the floating point initialization code - the result
// is an R6002 runtime error.
// These supposed to be read only addresses are covered by the sections
// UPX0 & UPX1 in the compressed files, so we have to patch the PE header
// in the memory. And the page on which the PE header is stored is read
// only so we must make it rw, fix the flags (i.e. clear
// PEFL_WRITE of osection[x].flags), and make it ro again.
// rva of the most significant byte of member "flags" in section "UPX0"
const unsigned swri = pe_offset + sizeof(oh) + sizeof(pe_section_t) - 1;
#if 0
if (swri >= 0x1000)
throwCantPack("swri >= 0x1000! Send a bug report please!");
patch_le32(loader, codesize, "SWRI", swri);
patch_le32(loader, codesize, "IMGL", 0x1000); // one page
patch_le32(loader, codesize, "IMGB", 0u - rvamin);
#else
// make sure we only touch the minimum number of pages
const unsigned addr = 0u - rvamin + swri;
patch_le32(loader, codesize, "SWRI", addr & 0xfff); // page offset
// check whether osection[0].flags and osection[1].flags
// are on the same page
if ((addr & 0xfff) + 0x28 >= 0x1000)
patch_le32(loader, codesize, "IMGL", 0x2000); // two pages
else
patch_le32(loader, codesize, "IMGL", 0x1000); // one page
patch_le32(loader, codesize, "IMGB", addr &~ 0xfff); // page mask
#endif
patch_le32(loader, codesize, "VPRO", myimport + get_le32(oimpdlls + 16) + 8);
}
if (big_relocs & 6) if (big_relocs & 6)
patch_le32(loader,codesize,"DELT", 0u - (unsigned) ih.imagebase - rvamin); patch_le32(loader,codesize,"DELT", 0u - (unsigned) ih.imagebase - rvamin);
if (sorelocs && (soimport == 0 || soimport + cimports != crelocs)) if (sorelocs && (soimport == 0 || soimport + cimports != crelocs))
@@ -1853,7 +1951,7 @@ void PackW32Pe::pack(OutputFile *fo)
if (soimport) if (soimport)
{ {
if (!isdll) if (!isdll)
patch_le32(loader,codesize,"EXIT",myimport + get_le32(oimpdlls + 16) + 8); patch_le32(loader,codesize,"EXIT",myimport + get_le32(oimpdlls + 16) + 12);
patch_le32(loader,codesize,"GETP",myimport + get_le32(oimpdlls + 16) + 4); patch_le32(loader,codesize,"GETP",myimport + get_le32(oimpdlls + 16) + 4);
if (kernel32ordinal) if (kernel32ordinal)
patch_le32(loader,codesize,"K32O",myimport); patch_le32(loader,codesize,"K32O",myimport);
@@ -1911,12 +2009,6 @@ void PackW32Pe::pack(OutputFile *fo)
ODADDR(PEDIR_BOUNDIM) = 0; ODADDR(PEDIR_BOUNDIM) = 0;
ODSIZE(PEDIR_BOUNDIM) = 0; ODSIZE(PEDIR_BOUNDIM) = 0;
if (opt->win32_pe.strip_loadconf)
{
ODADDR(PEDIR_LOADCONF) = 0;
ODSIZE(PEDIR_LOADCONF) = 0;
}
// tls is put into section 1 // tls is put into section 1
ic = s1addr + s1size - sotls; ic = s1addr + s1size - sotls;
@@ -1933,10 +2025,12 @@ void PackW32Pe::pack(OutputFile *fo)
ODADDR(PEDIR_RESOURCE) = soresources ? ic : 0; ODADDR(PEDIR_RESOURCE) = soresources ? ic : 0;
ODSIZE(PEDIR_RESOURCE) = soresources; ODSIZE(PEDIR_RESOURCE) = soresources;
ic += soresources; ic += soresources;
processImports(ic); processImports(ic);
ODADDR(PEDIR_IMPORT) = ic; ODADDR(PEDIR_IMPORT) = ic;
ODSIZE(PEDIR_IMPORT) = soimpdlls; ODSIZE(PEDIR_IMPORT) = soimpdlls;
ic += soimpdlls; ic += soimpdlls;
processExports(&xport,ic); processExports(&xport,ic);
ODADDR(PEDIR_EXPORT) = soexport ? ic : 0; ODADDR(PEDIR_EXPORT) = soexport ? ic : 0;
ODSIZE(PEDIR_EXPORT) = soexport; ODSIZE(PEDIR_EXPORT) = soexport;
@@ -1946,13 +2040,20 @@ void PackW32Pe::pack(OutputFile *fo)
ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT); ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT);
} }
ic += soexport; ic += soexport;
processLoadConf(&rel, &loadconfiv, ic);
ODADDR(PEDIR_LOADCONF) = soloadconf ? ic : 0;
ODSIZE(PEDIR_LOADCONF) = soloadconf;
ic += soloadconf;
processRelocs(&rel); processRelocs(&rel);
ODADDR(PEDIR_RELOC) = soxrelocs ? ic : 0; ODADDR(PEDIR_RELOC) = soxrelocs ? ic : 0;
ODSIZE(PEDIR_RELOC) = soxrelocs; ODSIZE(PEDIR_RELOC) = soxrelocs;
ic += soxrelocs; ic += soxrelocs;
// this is computed here, because soxrelocs changes some lines above // this is computed here, because soxrelocs changes some lines above
const unsigned ncsize = soresources + soimpdlls + soexport + soxrelocs; const unsigned ncsize = soresources + soimpdlls + soexport + soloadconf
+ soxrelocs;
ic = oh.filealign - 1; ic = oh.filealign - 1;
// this one is tricky: it seems windoze touches 4 bytes after // this one is tricky: it seems windoze touches 4 bytes after
@@ -2026,6 +2127,8 @@ void PackW32Pe::pack(OutputFile *fo)
fo->write(obuf,clen); fo->write(obuf,clen);
infoWriting("compressed data", clen); infoWriting("compressed data", clen);
fo->write(loader,codesize); fo->write(loader,codesize);
if (opt->debug.dump_stub_loader)
OutputFile::dump(opt->debug.dump_stub_loader, loader, codesize);
if ((ic = fo->getBytesWritten() & 3) != 0) if ((ic = fo->getBytesWritten() & 3) != 0)
fo->write(ibuf,4 - ic); fo->write(ibuf,4 - ic);
fo->write(otls,sotls); fo->write(otls,sotls);
@@ -2034,6 +2137,7 @@ void PackW32Pe::pack(OutputFile *fo)
fo->write(oresources,soresources); fo->write(oresources,soresources);
fo->write(oimpdlls,soimpdlls); fo->write(oimpdlls,soimpdlls);
fo->write(oexport,soexport); fo->write(oexport,soexport);
fo->write(oloadconf, soloadconf);
fo->write(oxrelocs,soxrelocs); fo->write(oxrelocs,soxrelocs);
if ((ic = fo->getBytesWritten() & (oh.filealign-1)) != 0) if ((ic = fo->getBytesWritten() & (oh.filealign-1)) != 0)
@@ -2050,6 +2154,7 @@ void PackW32Pe::pack(OutputFile *fo)
printf("%-13s: imports : %8ld bytes\n", getName(), (long) soimpdlls); printf("%-13s: imports : %8ld bytes\n", getName(), (long) soimpdlls);
printf("%-13s: exports : %8ld bytes\n", getName(), (long) soexport); printf("%-13s: exports : %8ld bytes\n", getName(), (long) soexport);
printf("%-13s: relocs : %8ld bytes\n", getName(), (long) soxrelocs); printf("%-13s: relocs : %8ld bytes\n", getName(), (long) soxrelocs);
printf("%-13s: loadconf : %8ld bytes\n", getName(), (long) soloadconf);
#endif #endif
// verify // verify
+10 -2
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -119,6 +119,14 @@ protected:
unsigned crelocs; // rva of preprocessed fixups unsigned crelocs; // rva of preprocessed fixups
int big_relocs; int big_relocs;
void processLoadConf(PackW32Pe_Reloc *, const PackW32Pe_Interval *, unsigned);
void processLoadConf(PackW32Pe_Interval *);
upx_byte *oloadconf;
unsigned soloadconf;
bool use_dep_hack;
bool use_clear_dirty_stack;
struct pe_header_t struct pe_header_t
{ {
// 0x0 // 0x0
+4 -4
View File
@@ -48,8 +48,8 @@ static const
#define LE_STUB_EDI (1) #define LE_STUB_EDI (1)
#ifdef TESTING #ifdef TESTING
# define dputc(x,y) do { if (opt->debug) putc(x,y); } while (0) # define dputc(x,y) do { if (opt->debug.debug_level) putc(x,y); } while (0)
# define Opt_debug opt->debug # define Opt_debug opt->debug.debug_level
#else #else
# define dputc(x,y) ((void)0) # define dputc(x,y) ((void)0)
# define Opt_debug 0 # define Opt_debug 0
@@ -85,7 +85,7 @@ int PackWcle::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(nrv_loader,sizeof(nrv_loader)); initLoader(nrv_loader,sizeof(nrv_loader));
addLoader("IDENTSTR""WCLEMAIN""UPX1HEAD""WCLECUTP""+0000000", addLoader("IDENTSTR,WCLEMAIN,UPX1HEAD,WCLECUTP,+0000000",
getDecompressor(), getDecompressor(),
"WCLEMAI2", "WCLEMAI2",
NULL NULL
@@ -99,7 +99,7 @@ int PackWcle::buildLoader(const Filter *ft)
#if 1 #if 1
// FIXME: if (has_relocation) // FIXME: if (has_relocation)
{ {
addLoader("WCRELOC1""RELOC320", addLoader("WCRELOC1,RELOC320",
big_relocs ? "REL32BIG" : "", big_relocs ? "REL32BIG" : "",
"RELOC32J", "RELOC32J",
NULL NULL
+190 -44
View File
@@ -2,8 +2,8 @@
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -295,7 +295,7 @@ bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const
**************************************************************************/ **************************************************************************/
void Packer::decompress(const upx_bytep in, upx_bytep out, void Packer::decompress(const upx_bytep in, upx_bytep out,
bool verify_checksum) bool verify_checksum, Filter *ft)
{ {
unsigned adler; unsigned adler;
@@ -316,6 +316,9 @@ void Packer::decompress(const upx_bytep in, upx_bytep out,
// verify checksum of decompressed data // verify checksum of decompressed data
if (verify_checksum) if (verify_checksum)
{ {
if (ft) {
ft->unfilter(out, ph.u_len);
}
adler = upx_adler32(out, ph.u_len, ph.saved_u_adler); adler = upx_adler32(out, ph.u_len, ph.saved_u_adler);
if (adler != ph.u_adler) if (adler != ph.u_adler)
throwChecksumError(); throwChecksumError();
@@ -339,9 +342,9 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
return false; return false;
assert((int)overlap_overhead >= 0); assert((int)overlap_overhead >= 0);
// Because we are not using the asm_fast decompressor here // Because upx_test_overlap() does not use the asm_fast decompressor
// we must account for extra 3 bytes or else we may fail // we must account for extra 3 bytes that asm_fast does use,
// at runtime decompression. // or else we may fail at runtime decompression.
if (overlap_overhead <= 4 + 3) // don't waste time here if (overlap_overhead <= 4 + 3) // don't waste time here
return false; return false;
overlap_overhead -= 3; overlap_overhead -= 3;
@@ -355,7 +358,7 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
} }
void Packer::verifyOverlappingDecompression() void Packer::verifyOverlappingDecompression(Filter *ft)
{ {
assert(ph.c_len < ph.u_len); assert(ph.c_len < ph.u_len);
assert((int)ph.overlap_overhead > 0); assert((int)ph.overlap_overhead > 0);
@@ -381,7 +384,7 @@ void Packer::verifyOverlappingDecompression()
if (offset + ph.c_len > obuf.getSize()) if (offset + ph.c_len > obuf.getSize())
return; return;
memmove(obuf + offset, obuf, ph.c_len); memmove(obuf + offset, obuf, ph.c_len);
decompress(obuf + offset, obuf, true); decompress(obuf + offset, obuf, true, ft);
obuf.checkState(); obuf.checkState();
#endif /* !UNUPX */ #endif /* !UNUPX */
} }
@@ -812,12 +815,31 @@ int Packer::patchVersion(void *b, int blen)
checkPatch(b, blen, boff, 14); checkPatch(b, blen, boff, 14);
unsigned char *p = (unsigned char *)b + boff + 9; unsigned char *p = (unsigned char *)b + boff + 9;
if (opt->debug.fake_stub_version[0])
memcpy(p, opt->debug.fake_stub_version, 4);
else
memcpy(p, UPX_VERSION_STRING4, 4); memcpy(p, UPX_VERSION_STRING4, 4);
return boff; return boff;
} }
// patch year into stub/ident_[ns].ash
int Packer::patchVersionYear(void *b, int blen)
{
int boff = find(b, blen, " 1996-UPXY ", 11);
checkPatch(b, blen, boff, 11);
unsigned char *p = (unsigned char *)b + boff + 6;
if (opt->debug.fake_stub_year[0])
memcpy(p, opt->debug.fake_stub_year, 4);
else
memcpy(p, UPX_VERSION_YEAR, 4);
return boff;
}
/************************************************************************* /*************************************************************************
// relocation util // relocation util
**************************************************************************/ **************************************************************************/
@@ -920,7 +942,7 @@ unsigned Packer::unoptimizeReloc32(upx_byte **in, upx_byte *image,
bool Packer::isValidCompressionMethod(int method) bool Packer::isValidCompressionMethod(int method)
{ {
return (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16); return (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16);
} }
@@ -929,6 +951,7 @@ const int *Packer::getDefaultCompressionMethods_8(int method, int level, int sma
static const int m_nrv2b[] = { M_NRV2B_8, M_NRV2D_8, M_NRV2E_8, -1 }; static const int m_nrv2b[] = { M_NRV2B_8, M_NRV2D_8, M_NRV2E_8, -1 };
static const int m_nrv2d[] = { M_NRV2D_8, M_NRV2B_8, M_NRV2E_8, -1 }; static const int m_nrv2d[] = { M_NRV2D_8, M_NRV2B_8, M_NRV2E_8, -1 };
static const int m_nrv2e[] = { M_NRV2E_8, M_NRV2B_8, M_NRV2D_8, -1 }; static const int m_nrv2e[] = { M_NRV2E_8, M_NRV2B_8, M_NRV2D_8, -1 };
static const int m_cl1b[] = { M_CL1B_8, -1 };
if (small < 0) if (small < 0)
small = file_size <= 512*1024; small = file_size <= 512*1024;
@@ -938,6 +961,8 @@ const int *Packer::getDefaultCompressionMethods_8(int method, int level, int sma
return m_nrv2d; return m_nrv2d;
if (M_IS_NRV2E(method)) if (M_IS_NRV2E(method))
return m_nrv2e; return m_nrv2e;
if (M_IS_CL1B(method))
return m_cl1b;
if (level == 1 || small) if (level == 1 || small)
return m_nrv2b; return m_nrv2b;
return m_nrv2e; return m_nrv2e;
@@ -949,6 +974,7 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
static const int m_nrv2b[] = { M_NRV2B_LE32, M_NRV2D_LE32, M_NRV2E_LE32, -1 }; static const int m_nrv2b[] = { M_NRV2B_LE32, M_NRV2D_LE32, M_NRV2E_LE32, -1 };
static const int m_nrv2d[] = { M_NRV2D_LE32, M_NRV2B_LE32, M_NRV2E_LE32, -1 }; static const int m_nrv2d[] = { M_NRV2D_LE32, M_NRV2B_LE32, M_NRV2E_LE32, -1 };
static const int m_nrv2e[] = { M_NRV2E_LE32, M_NRV2B_LE32, M_NRV2D_LE32, -1 }; static const int m_nrv2e[] = { M_NRV2E_LE32, M_NRV2B_LE32, M_NRV2D_LE32, -1 };
static const int m_cl1b[] = { M_CL1B_LE32, -1 };
if (small < 0) if (small < 0)
small = file_size <= 512*1024; small = file_size <= 512*1024;
@@ -958,6 +984,8 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
return m_nrv2d; return m_nrv2d;
if (M_IS_NRV2E(method)) if (M_IS_NRV2E(method))
return m_nrv2e; return m_nrv2e;
if (M_IS_CL1B(method))
return m_cl1b;
if (level == 1 || small) if (level == 1 || small)
return m_nrv2b; return m_nrv2b;
return m_nrv2e; return m_nrv2e;
@@ -970,21 +998,43 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
char const *Packer::getIdentstr(unsigned *size, int small) char const *Packer::getIdentstr(unsigned *size, int small)
{ {
static const char identbig[] = static char identbig[] =
"\n\0" "\n\0"
"$Info: " "$Info: "
"This file is packed with the UPX executable packer http://upx.sf.net $" "This file is packed with the UPX executable packer http://upx.sf.net $"
"\n\0" "\n\0"
"$Id: UPX " "$Id: UPX "
UPX_VERSION_STRING4 UPX_VERSION_STRING4
" Copyright (C) 1996-2005 the UPX Team. All Rights Reserved. $" " Copyright (C) 1996-" UPX_VERSION_YEAR " the UPX Team. All Rights Reserved. $"
"\n"; "\n";
static const char identsmall[] = static char identsmall[] =
"\n" "\n"
"$Id: UPX " "$Id: UPX "
"(C) 1996-2005 the UPX Team. All Rights Reserved. http://upx.sf.net $" "(C) 1996-" UPX_VERSION_YEAR " the UPX Team. All Rights Reserved. http://upx.sf.net $"
"\n"; "\n";
static const char identtiny[] = UPX_VERSION_STRING4; static char identtiny[] = UPX_VERSION_STRING4;
static int done;
if (!done && (opt->debug.fake_stub_version[0] || opt->debug.fake_stub_year[0]))
{
struct strinfo_t { char *s; int size; };
static const strinfo_t strlist[] = {
{ identbig, (int)sizeof(identbig) },
{ identsmall, (int)sizeof(identsmall) },
{ identtiny, (int)sizeof(identtiny) },
{ NULL, 0 } };
const strinfo_t* iter;
for (iter = strlist; iter->s; ++iter)
{
if (opt->debug.fake_stub_version[0])
mem_replace(iter->s, iter->size, UPX_VERSION_STRING4, 4, opt->debug.fake_stub_version);
if (opt->debug.fake_stub_year[0])
mem_replace(iter->s, iter->size, UPX_VERSION_YEAR, 4, opt->debug.fake_stub_year);
}
done = 1;
}
if (small < 0) if (small < 0)
small = opt->small; small = opt->small;
@@ -1027,13 +1077,15 @@ void Packer::initLoader(const void *pdata, int plen, int pinfo, int small)
void __acc_cdecl_va Packer::addLoader(const char *s, ...) void __acc_cdecl_va Packer::addLoader(const char *s, ...)
{ {
const char *p;
va_list ap; va_list ap;
va_start(ap, s); va_start(ap, s);
while (s != NULL)
{
if (*s)
linker->addSection(s); linker->addSection(s);
while((p = va_arg(ap, const char *)) != NULL) s = va_arg(ap, const char *);
linker->addSection(p); }
va_end(ap); va_end(ap);
} }
@@ -1086,29 +1138,87 @@ int Packer::getLoaderSize() const
const char *Packer::getDecompressor() const const char *Packer::getDecompressor() const
{ {
static const char nrv2b_le32_small[] = static const char nrv2b_le32_small[] =
"N2BSMA10""N2BDEC10""N2BSMA20""N2BDEC20""N2BSMA30" "N2BSMA10,N2BDEC10,N2BSMA20,N2BDEC20,N2BSMA30,"
"N2BDEC30""N2BSMA40""N2BSMA50""N2BDEC50""N2BSMA60" "N2BDEC30,N2BSMA40,N2BSMA50,N2BDEC50,N2BSMA60,"
"N2BDEC60"; "N2BDEC60";
static const char nrv2b_le32_fast[] = static const char nrv2b_le32_fast[] =
"N2BFAS10""+80CXXXX""N2BFAS11""N2BDEC10""N2BFAS20" "N2BFAS10,+80CXXXX,N2BFAS11,N2BDEC10,N2BFAS20,"
"N2BDEC20""N2BFAS30""N2BDEC30""N2BFAS40""N2BFAS50" "N2BDEC20,N2BFAS30,N2BDEC30,N2BFAS40,N2BFAS50,"
"N2BDEC50""N2BFAS60""+40CXXXX""N2BFAS61""N2BDEC60"; "N2BDEC50,N2BFAS60,+40CXXXX,N2BFAS61,N2BDEC60";
static const char nrv2d_le32_small[] = static const char nrv2d_le32_small[] =
"N2DSMA10""N2DDEC10""N2DSMA20""N2DDEC20""N2DSMA30" "N2DSMA10,N2DDEC10,N2DSMA20,N2DDEC20,N2DSMA30,"
"N2DDEC30""N2DSMA40""N2DSMA50""N2DDEC50""N2DSMA60" "N2DDEC30,N2DSMA40,N2DSMA50,N2DDEC50,N2DSMA60,"
"N2DDEC60"; "N2DDEC60";
static const char nrv2d_le32_fast[] = static const char nrv2d_le32_fast[] =
"N2DFAS10""+80CXXXX""N2DFAS11""N2DDEC10""N2DFAS20" "N2DFAS10,+80CXXXX,N2DFAS11,N2DDEC10,N2DFAS20,"
"N2DDEC20""N2DFAS30""N2DDEC30""N2DFAS40""N2DFAS50" "N2DDEC20,N2DFAS30,N2DDEC30,N2DFAS40,N2DFAS50,"
"N2DDEC50""N2DFAS60""+40CXXXX""N2DFAS61""N2DDEC60"; "N2DDEC50,N2DFAS60,+40CXXXX,N2DFAS61,N2DDEC60";
static const char nrv2e_le32_small[] = static const char nrv2e_le32_small[] =
"N2ESMA10""N2EDEC10""N2ESMA20""N2EDEC20""N2ESMA30" "N2ESMA10,N2EDEC10,N2ESMA20,N2EDEC20,N2ESMA30,"
"N2EDEC30""N2ESMA40""N2ESMA50""N2EDEC50""N2ESMA60" "N2EDEC30,N2ESMA40,N2ESMA50,N2EDEC50,N2ESMA60,"
"N2EDEC60"; "N2EDEC60";
static const char nrv2e_le32_fast[] = static const char nrv2e_le32_fast[] =
"N2EFAS10""+80CXXXX""N2EFAS11""N2EDEC10""N2EFAS20" "N2EFAS10,+80CXXXX,N2EFAS11,N2EDEC10,N2EFAS20,"
"N2EDEC20""N2EFAS30""N2EDEC30""N2EFAS40""N2EFAS50" "N2EDEC20,N2EFAS30,N2EDEC30,N2EFAS40,N2EFAS50,"
"N2EDEC50""N2EFAS60""+40CXXXX""N2EFAS61""N2EDEC60"; "N2EDEC50,N2EFAS60,+40CXXXX,N2EFAS61,N2EDEC60";
static const char cl1b_le32_small[] =
"CL1ENTER,CL1SMA10,CL1RLOAD,"
"CL1WID01,CL1SMA1B,"
"CL1WID02,CL1SMA1B,"
"CL1WID03,CL1SMA1B,"
"CL1WID04,CL1SMA1B,"
"CL1WID05,CL1SMA1B,"
"CL1WID06,CL1SMA1B,"
"CL1WID07,CL1SMA1B,"
"CL1WID08,CL1SMA1B,"
"CL1WID09,CL1SMA1B,"
"CL1WID10,"
"CL1START,"
"CL1TOP00,CL1SMA1B,"
"CL1TOP01,CL1SMA1B,"
"CL1TOP02,CL1SMA1B,"
"CL1TOP03,CL1SMA1B,"
"CL1TOP04,CL1SMA1B,"
"CL1TOP05,CL1SMA1B,"
"CL1TOP06,CL1SMA1B,"
"CL1TOP07,CL1SMA1B,"
"CL1OFF01,CL1SMA1B,"
"CL1OFF02,CL1SMA1B,"
"CL1OFF03,CL1SMA1B,"
"CL1OFF04,"
"CL1LEN00,CL1SMA1B,"
"CL1LEN01,CL1SMA1B,"
"CL1LEN02,"
"CL1COPY0";
static const char cl1b_le32_fast[] =
"CL1ENTER," "CL1RLOAD,"
"CL1WID01,CL1FAS1B,"
"CL1WID02,CL1FAS1B,"
"CL1WID03,CL1FAS1B,"
"CL1WID04,CL1FAS1B,"
"CL1WID05,CL1FAS1B,"
"CL1WID06,CL1FAS1B,"
"CL1WID07,CL1FAS1B,"
"CL1WID08,CL1FAS1B,"
"CL1WID09,CL1FAS1B,"
"CL1WID10,"
"CL1START,"
"CL1TOP00,CL1FAS1B,"
"CL1TOP01,CL1FAS1B,"
"CL1TOP02,CL1FAS1B,"
"CL1TOP03,CL1FAS1B,"
"CL1TOP04,CL1FAS1B,"
"CL1TOP05,CL1FAS1B,"
"CL1TOP06,CL1FAS1B,"
"CL1TOP07,CL1FAS1B,"
"CL1OFF01,CL1FAS1B,"
"CL1OFF02,CL1FAS1B,"
"CL1OFF03,CL1FAS1B,"
"CL1OFF04,"
"CL1LEN00,CL1FAS1B,"
"CL1LEN01,CL1FAS1B,"
"CL1LEN02,"
"CL1COPY0";
if (ph.method == M_NRV2B_LE32) if (ph.method == M_NRV2B_LE32)
return opt->small ? nrv2b_le32_small : nrv2b_le32_fast; return opt->small ? nrv2b_le32_small : nrv2b_le32_fast;
@@ -1116,6 +1226,8 @@ const char *Packer::getDecompressor() const
return opt->small ? nrv2d_le32_small : nrv2d_le32_fast; return opt->small ? nrv2d_le32_small : nrv2d_le32_fast;
if (ph.method == M_NRV2E_LE32) if (ph.method == M_NRV2E_LE32)
return opt->small ? nrv2e_le32_small : nrv2e_le32_fast; return opt->small ? nrv2e_le32_small : nrv2e_le32_fast;
if (ph.method == M_CL1B_LE32)
return opt->small ? cl1b_le32_small : cl1b_le32_fast;
throwInternalError("bad decompressor"); throwInternalError("bad decompressor");
return NULL; return NULL;
} }
@@ -1149,13 +1261,32 @@ const char *Packer::getDecompressor() const
// executable formats. // executable formats.
// //
// It will replace the tryFilters() / compress() call sequence. // It will replace the tryFilters() / compress() call sequence.
// 2006-02-15: hdr_buf and hdr_u_len are default empty input "header" array
// to fix a 2-pass problem with Elf headers. As of today there can be
// only one decompression method per executable output file, and that method
// is the one that gives best compression for .text and loader. However,
// the Elf headers precede .text in the output file, and are written first.
// "--brute" compression often compressed the Elf headers using nrv2b
// but the .text (and loader) with nrv2e. This often resulted in SIGSEGV
// during decompression.
// The workaround is for hdr_buf and hdr_u_len to describe the Elf headers
// (typically less than 512 bytes) when .text is passed in, and include
// them in the calculation of shortest output. Then the result
// this->ph.method will say which [single] method to use for everthing.
// The Elf headers are never filtered. They are short enough (< 512 bytes)
// that compressing them more than once per method (once here when choosing,
// once again just before writing [because compressWithFilters discards])
// is OK because of the simplicity of not having two output arrays.
**************************************************************************/ **************************************************************************/
void Packer::compressWithFilters(Filter *parm_ft, void Packer::compressWithFilters(Filter *parm_ft,
const unsigned overlap_range, const unsigned overlap_range,
int strategy, const int *parm_filters, int strategy, const int *parm_filters,
unsigned max_offset, unsigned max_match, unsigned max_offset, unsigned max_match,
unsigned filter_off, unsigned compress_buf_off) unsigned filter_off, unsigned compress_buf_off,
unsigned char *hdr_buf,
unsigned hdr_u_len)
{ {
const int *f; const int *f;
// //
@@ -1171,6 +1302,7 @@ void Packer::compressWithFilters(Filter *parm_ft,
best_ph.c_len = orig_ph.u_len; best_ph.c_len = orig_ph.u_len;
best_ph.overlap_overhead = 0; best_ph.overlap_overhead = 0;
unsigned best_ph_lsize = 0; unsigned best_ph_lsize = 0;
unsigned best_hdr_clen = 0;
// preconditions // preconditions
assert(orig_ph.filter == 0); assert(orig_ph.filter == 0);
@@ -1250,11 +1382,11 @@ void Packer::compressWithFilters(Filter *parm_ft,
} }
assert(nmethods > 0); assert(nmethods > 0);
// update total_passes // update total_passes; previous (0 < ui_total_passes) means incremental
if (strategy < 0) if (strategy < 0)
ui_total_passes += 1 * nmethods; ui_total_passes += 1 * nmethods - (0 < ui_total_passes);
else else
ui_total_passes += nfilters * nmethods; ui_total_passes += nfilters * nmethods - (0 < ui_total_passes);
// Working buffer for compressed data. Don't waste memory. // Working buffer for compressed data. Don't waste memory.
MemBuffer *otemp = &obuf; MemBuffer *otemp = &obuf;
@@ -1264,6 +1396,19 @@ void Packer::compressWithFilters(Filter *parm_ft,
int nfilters_success = 0; int nfilters_success = 0;
for (int m = 0; m < nmethods; m++) // for all methods for (int m = 0; m < nmethods; m++) // for all methods
{ {
unsigned hdr_clen = 0;
if (hdr_buf && hdr_u_len) {
unsigned result[16];
upx_compress_config_t conf;
memset(&conf, 0xff, sizeof(conf));
if (0 < m && otemp == &obuf) { // do not overwrite obuf
otemp_buf.allocForCompression(compress_buf_len);
otemp = &otemp_buf;
}
int r = upx_compress(hdr_buf, hdr_u_len, *otemp, &hdr_clen,
0, methods[m], 10, &conf, result);
(void)r;
}
for (int i = 0; i < nfilters; i++) // for all filters for (int i = 0; i < nfilters; i++) // for all filters
{ {
ibuf.checkState(); ibuf.checkState();
@@ -1319,19 +1464,19 @@ void Packer::compressWithFilters(Filter *parm_ft,
lsize = buildLoader(&ft); lsize = buildLoader(&ft);
} }
#if 0 #if 0
printf("\n%2d %02x: %d +%4d = %d (best: %d +%4d = %d)\n", ph.method, ph.filter, printf("\n%2d %02x: %d +%4d +%3d = %d (best: %d +%4d +%3d = %d)\n", ph.method, ph.filter,
ph.c_len, lsize, ph.c_len + lsize, ph.c_len, lsize, hdr_clen, ph.c_len + lsize + hdr_clen,
best_ph.c_len, best_ph_lsize, best_ph.c_len + best_ph_lsize); best_ph.c_len, best_ph_lsize, best_hdr_clen, best_ph.c_len + best_ph_lsize + best_hdr_clen);
#endif #endif
bool update = false; bool update = false;
if (ph.c_len + lsize < best_ph.c_len + best_ph_lsize) if (ph.c_len + lsize + hdr_clen < best_ph.c_len + best_ph_lsize + best_hdr_clen)
update = true; update = true;
else if (ph.c_len + lsize == best_ph.c_len + best_ph_lsize) else if (ph.c_len + lsize + hdr_clen == best_ph.c_len + best_ph_lsize + best_hdr_clen)
{ {
// prefer smaller loaders // prefer smaller loaders
if (lsize < best_ph_lsize) if (lsize + hdr_clen < best_ph_lsize + best_hdr_clen)
update = true; update = true;
else if (lsize == best_ph_lsize) else if (lsize + hdr_clen == best_ph_lsize + best_hdr_clen)
{ {
// prefer less overlap_overhead // prefer less overlap_overhead
if (ph.overlap_overhead < best_ph.overlap_overhead) if (ph.overlap_overhead < best_ph.overlap_overhead)
@@ -1346,6 +1491,7 @@ void Packer::compressWithFilters(Filter *parm_ft,
// save compression results // save compression results
best_ph = ph; best_ph = ph;
best_ph_lsize = lsize; best_ph_lsize = lsize;
best_hdr_clen = hdr_clen;
best_ft = ft; best_ft = ft;
} }
} }
+11 -4
View File
@@ -160,8 +160,8 @@ protected:
// main compression drivers // main compression drivers
virtual bool compress(upx_bytep in, upx_bytep out, virtual bool compress(upx_bytep in, upx_bytep out,
unsigned max_offset = 0, unsigned max_match = 0); unsigned max_offset = 0, unsigned max_match = 0);
virtual void decompress(const upx_bytep in, virtual void decompress(const upx_bytep in, upx_bytep out,
upx_bytep out, bool verify_checksum=true); bool verify_checksum = true, Filter *ft = NULL);
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const; virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const; virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
@@ -172,7 +172,9 @@ protected:
const int *filters = NULL, const int *filters = NULL,
unsigned max_offset = 0, unsigned max_match = 0, unsigned max_offset = 0, unsigned max_match = 0,
unsigned filter_buf_off = 0, unsigned filter_buf_off = 0,
unsigned compress_buf_off = 0); unsigned compress_buf_off = 0,
unsigned char *header_buffer = 0,
unsigned header_length = 0);
// util for verifying overlapping decompresion // util for verifying overlapping decompresion
// non-destructive test // non-destructive test
@@ -183,7 +185,7 @@ protected:
unsigned range = 0, unsigned range = 0,
unsigned upper_limit = ~0u) const; unsigned upper_limit = ~0u) const;
// destructive decompress + verify // destructive decompress + verify
virtual void verifyOverlappingDecompression(); virtual void verifyOverlappingDecompression(Filter *ft = NULL);
// packheader handling // packheader handling
@@ -208,7 +210,11 @@ protected:
virtual const upx_byte *getLoader() const; virtual const upx_byte *getLoader() const;
virtual int getLoaderSize() const; virtual int getLoaderSize() const;
virtual void initLoader(const void *pdata, int plen, int pinfo=-1, int small=-1); virtual void initLoader(const void *pdata, int plen, int pinfo=-1, int small=-1);
#if 1 && (ACC_CC_GNUC >= 0x040100)
virtual void __acc_cdecl_va addLoader(const char *s, ...) __attribute__((__sentinel__));
#else
virtual void __acc_cdecl_va addLoader(const char *s, ...); virtual void __acc_cdecl_va addLoader(const char *s, ...);
#endif
virtual int getLoaderSection(const char *name, int *slen=NULL) const; virtual int getLoaderSection(const char *name, int *slen=NULL) const;
virtual int getLoaderSectionStart(const char *name, int *slen=NULL) const; virtual int getLoaderSectionStart(const char *name, int *slen=NULL) const;
virtual const char *getDecompressor() const; virtual const char *getDecompressor() const;
@@ -233,6 +239,7 @@ protected:
int patch_le32(void *b, int blen, unsigned old, unsigned new_); int patch_le32(void *b, int blen, unsigned old, unsigned new_);
int patch_le32(void *b, int blen, const void * old, unsigned new_); int patch_le32(void *b, int blen, const void * old, unsigned new_);
int patchVersion(void *b, int blen); int patchVersion(void *b, int blen);
int patchVersionYear(void *b, int blen);
void checkPatch(void *b, int blen, int boff, int size); void checkPatch(void *b, int blen, int boff, int size);
// relocation util // relocation util
+75 -75
View File
@@ -22,7 +22,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar Markus F.X.J. Oberhumer Laszlo Molnar
markus@oberhumer.com ml1050@cdata.tvnet.hu markus@oberhumer.com ml1050@users.sourceforge.net
*/ */
@@ -133,21 +133,21 @@ void Packer::addFilter32(int filter_id)
addLoader("CALLTR00", addLoader("CALLTR00",
(filter_id > 0x20) ? "CTCLEVE1" : "", (filter_id > 0x20) ? "CTCLEVE1" : "",
"CALLTR01", "CALLTR01",
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01""CTBSWA01" : "CTBROR01""CTBSWA01") : "", (filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01,CTBSWA01" : "CTBROR01,CTBSWA01") : "",
"CALLTR02", "CALLTR02",
NULL NULL
); );
} }
else if (0x40==(0xF0 & filter_id)) { else if (0x40==(0xF0 & filter_id)) {
addLoader("CKLLTR00", 0); addLoader("CKLLTR00", NULL);
if (9<=(0xf & filter_id)) { if (9<=(0xf & filter_id)) {
addLoader("CKLLTR10", 0); addLoader("CKLLTR10", NULL);
} }
addLoader("CKLLTR20", 0); addLoader("CKLLTR20", NULL);
if (9<=(0xf & filter_id)) { if (9<=(0xf & filter_id)) {
addLoader("CKLLTR30", 0); addLoader("CKLLTR30", NULL);
} }
addLoader("CKLLTR40", 0); addLoader("CKLLTR40", NULL);
} }
} }
else else
@@ -156,7 +156,7 @@ void Packer::addFilter32(int filter_id)
"CALLTR11", "CALLTR11",
(filter_id > 0x20) ? "CTCLEVE2" : "", (filter_id > 0x20) ? "CTCLEVE2" : "",
"CALLTR12", "CALLTR12",
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11""CTBSWA11" : "CTBROR11""CTBSWA11") : "", (filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11,CTBSWA11" : "CTBROR11,CTBSWA11") : "",
"CALLTR13", "CALLTR13",
NULL NULL
); );
@@ -170,187 +170,187 @@ void Packer::addFilter32(int filter_id)
unsigned const f_jcc2 = f80_jcc2(filter_id); unsigned const f_jcc2 = f80_jcc2(filter_id);
if (NOFILT!=f_jcc2) { if (NOFILT!=f_jcc2) {
addLoader("LXJCC010", 0); addLoader("LXJCC010", NULL);
if (n_mru) { if (n_mru) {
addLoader("LXMRU045", 0); addLoader("LXMRU045", NULL);
} }
else { else {
addLoader("LXMRU046", 0); addLoader("LXMRU046", NULL);
} }
if (0==n_mru || MRUFLT!=f_jcc2) { if (0==n_mru || MRUFLT!=f_jcc2) {
addLoader("LXJCC020", 0); addLoader("LXJCC020", NULL);
} }
else { // 0!=n_mru else { // 0!=n_mru
addLoader("LXJCC021", 0); addLoader("LXJCC021", NULL);
} }
if (NOFILT!=f_jcc2) { if (NOFILT!=f_jcc2) {
addLoader("LXJCC023", 0); addLoader("LXJCC023", NULL);
} }
} }
addLoader("LXUNF037", 0); addLoader("LXUNF037", NULL);
if (x386) { if (x386) {
if (n_mru) { if (n_mru) {
addLoader("LXUNF386", 0); addLoader("LXUNF386", NULL);
} }
addLoader("LXUNF387", 0); addLoader("LXUNF387", NULL);
if (n_mru) { if (n_mru) {
addLoader("LXUNF388", 0); addLoader("LXUNF388", NULL);
} }
} }
else { else {
addLoader("LXUNF486", 0); addLoader("LXUNF486", NULL);
if (n_mru) { if (n_mru) {
addLoader("LXUNF487", 0); addLoader("LXUNF487", NULL);
} }
} }
if (n_mru) { if (n_mru) {
addLoader("LXMRU065", 0); addLoader("LXMRU065", NULL);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE3", 0); addLoader("MRUBYTE3", NULL);
} }
else { else {
addLoader("MRUARB30", 0); addLoader("MRUARB30", NULL);
if (mrupwr2) { if (mrupwr2) {
addLoader("MRUBITS3", 0); addLoader("MRUBITS3", NULL);
} }
else { else {
addLoader("MRUARB40", 0); addLoader("MRUARB40", NULL);
} }
} }
addLoader("LXMRU070", 0); addLoader("LXMRU070", NULL);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE4", 0); addLoader("MRUBYTE4", NULL);
} }
else if (mrupwr2) { else if (mrupwr2) {
addLoader("MRUBITS4", 0); addLoader("MRUBITS4", NULL);
} }
else { else {
addLoader("MRUARB50", 0); addLoader("MRUARB50", NULL);
} }
addLoader("LXMRU080", 0); addLoader("LXMRU080", NULL);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE5", 0); addLoader("MRUBYTE5", NULL);
} }
else { else {
addLoader("MRUARB60", 0); addLoader("MRUARB60", NULL);
if (mrupwr2) { if (mrupwr2) {
addLoader("MRUBITS5", 0); addLoader("MRUBITS5", NULL);
} }
else { else {
addLoader("MRUARB70", 0); addLoader("MRUARB70", NULL);
} }
} }
addLoader("LXMRU090", 0); addLoader("LXMRU090", NULL);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE6", 0); addLoader("MRUBYTE6", NULL);
} }
else { else {
addLoader("MRUARB80", 0); addLoader("MRUARB80", NULL);
if (mrupwr2) { if (mrupwr2) {
addLoader("MRUBITS6", 0); addLoader("MRUBITS6", NULL);
} }
else { else {
addLoader("MRUARB90", 0); addLoader("MRUARB90", NULL);
} }
} }
addLoader("LXMRU100", 0); addLoader("LXMRU100", NULL);
} }
addLoader("LXUNF040", 0); addLoader("LXUNF040", NULL);
if (n_mru) { if (n_mru) {
addLoader("LXMRU110", 0); addLoader("LXMRU110", NULL);
} }
else { else {
addLoader("LXMRU111", 0); addLoader("LXMRU111", NULL);
} }
addLoader("LXUNF041", 0); addLoader("LXUNF041", NULL);
addLoader("LXUNF042", 0); addLoader("LXUNF042", NULL);
if (n_mru) { if (n_mru) {
addLoader("LXMRU010", 0); addLoader("LXMRU010", NULL);
if (NOFILT!=f_jmp1 && NOFILT==f_call) { if (NOFILT!=f_jmp1 && NOFILT==f_call) {
addLoader("LXJMPA00", 0); addLoader("LXJMPA00", NULL);
} }
else { else {
addLoader("LXCALLB0", 0); addLoader("LXCALLB0", NULL);
} }
addLoader("LXUNF021", 0); addLoader("LXUNF021", NULL);
} }
else { else {
addLoader("LXMRU022", 0); addLoader("LXMRU022", NULL);
if (NOFILT!=f_jmp1 && NOFILT==f_call) { if (NOFILT!=f_jmp1 && NOFILT==f_call) {
addLoader("LXJMPA01", 0); addLoader("LXJMPA01", NULL);
} }
else { else {
addLoader("LXCALLB1", 0); addLoader("LXCALLB1", NULL);
} }
} }
if (n_mru) { if (n_mru) {
if (256!=n_mru && mrupwr2) { if (256!=n_mru && mrupwr2) {
addLoader("MRUBITS1", 0); addLoader("MRUBITS1", NULL);
} }
addLoader("LXMRU030", 0); addLoader("LXMRU030", NULL);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE1", 0); addLoader("MRUBYTE1", NULL);
} }
else { else {
addLoader("MRUARB10", 0); addLoader("MRUARB10", NULL);
} }
addLoader("LXMRU040", 0); addLoader("LXMRU040", NULL);
} }
addLoader("LXUNF030", 0); addLoader("LXUNF030", NULL);
if (NOFILT!=f_jcc2) { if (NOFILT!=f_jcc2) {
addLoader("LXJCC000", 0); addLoader("LXJCC000", NULL);
} }
if (NOFILT!=f_call || NOFILT!=f_jmp1) { // at least one is filtered if (NOFILT!=f_call || NOFILT!=f_jmp1) { // at least one is filtered
// shift opcode origin to zero // shift opcode origin to zero
if (0==n_mru) { if (0==n_mru) {
addLoader("LXCJ0MRU", 0); addLoader("LXCJ0MRU", NULL);
} }
else { else {
addLoader("LXCJ1MRU", 0); addLoader("LXCJ1MRU", NULL);
} }
// determine if in range // determine if in range
if ((NOFILT!=f_call) && (NOFILT!=f_jmp1)) { // unfilter both if ((NOFILT!=f_call) && (NOFILT!=f_jmp1)) { // unfilter both
addLoader("LXCALJMP", 0); addLoader("LXCALJMP", NULL);
} }
if ((NOFILT==f_call) ^ (NOFILT==f_jmp1)) { // unfilter just one if ((NOFILT==f_call) ^ (NOFILT==f_jmp1)) { // unfilter just one
if (0==n_mru) { if (0==n_mru) {
addLoader("LXCALL00", 0); addLoader("LXCALL00", NULL);
} }
else { else {
addLoader("LXCALL01", 0); addLoader("LXCALL01", NULL);
} }
} }
// determine if mru applies // determine if mru applies
if (0==n_mru || ! ((FNOMRU==f_call) || (FNOMRU==f_jmp1)) ) { if (0==n_mru || ! ((FNOMRU==f_call) || (FNOMRU==f_jmp1)) ) {
addLoader("LXCJ2MRU", 0); // no mru, or no exceptions addLoader("LXCJ2MRU", NULL); // no mru, or no exceptions
} }
else { // mru on one, but not the other else { // mru on one, but not the other
addLoader("LXCJ4MRU", 0); addLoader("LXCJ4MRU", NULL);
if (MRUFLT==f_jmp1) { // JMP only if (MRUFLT==f_jmp1) { // JMP only
addLoader("LXCJ6MRU", 0); addLoader("LXCJ6MRU", NULL);
} else } else
if (MRUFLT==f_call) { // CALL only if (MRUFLT==f_call) { // CALL only
addLoader("LXCJ7MRU", 0); addLoader("LXCJ7MRU", NULL);
} }
addLoader("LXCJ8MRU", 0); addLoader("LXCJ8MRU", NULL);
} }
} }
addLoader("LXUNF034", 0); addLoader("LXUNF034", NULL);
if (n_mru) { if (n_mru) {
addLoader("LXMRU055", 0); addLoader("LXMRU055", NULL);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE2", 0); addLoader("MRUBYTE2", NULL);
} }
else if (mrupwr2) { else if (mrupwr2) {
addLoader("MRUBITS2", 0); addLoader("MRUBITS2", NULL);
} }
else if (n_mru) { else if (n_mru) {
addLoader("MRUARB20", 0); addLoader("MRUARB20", NULL);
} }
addLoader("LXMRU057", 0); addLoader("LXMRU057", NULL);
} }
} }
} }
+17
View File
@@ -41,6 +41,7 @@
#include "p_lx_elf.h" #include "p_lx_elf.h"
#include "p_lx_sep.h" #include "p_lx_sep.h"
#include "p_lx_sh.h" #include "p_lx_sh.h"
#include "p_lx_interp.h"
#include "p_sys.h" #include "p_sys.h"
#include "p_tos.h" #include "p_tos.h"
#include "p_wcle.h" #include "p_wcle.h"
@@ -51,6 +52,8 @@
#include "p_vmlinz.h" #include "p_vmlinz.h"
#include "p_vmlinx.h" #include "p_vmlinx.h"
#include "p_ps1.h" #include "p_ps1.h"
#include "p_mach.h"
#include "p_armpe.h"
/************************************************************************* /*************************************************************************
@@ -168,6 +171,8 @@ static Packer* try_packers(InputFile *f, try_function func)
#endif #endif
if ((p = func(new PackW16Ne(f),f)) != NULL) if ((p = func(new PackW16Ne(f),f)) != NULL)
return p; return p;
if ((p = func(new PackArmPe(f),f)) != NULL)
return p;
if ((p = func(new PackW32Pe(f),f)) != NULL) if ((p = func(new PackW32Pe(f),f)) != NULL)
return p; return p;
} }
@@ -206,6 +211,14 @@ static Packer* try_packers(InputFile *f, try_function func)
return p; return p;
} }
#endif #endif
if (opt->o_unix.use_ptinterp) {
if ((p = func(new PackLinuxI386interp(f),f)) != NULL)
return p;
}
if ((p = func(new PackLinuxElf64amd(f),f)) != NULL)
return p;
if ((p = func(new PackLinuxElf32ppc(f),f)) != NULL)
return p;
if ((p = func(new PackLinuxI386elf(f),f)) != NULL) if ((p = func(new PackLinuxI386elf(f),f)) != NULL)
return p; return p;
if ((p = func(new PackLinuxI386sh(f),f)) != NULL) if ((p = func(new PackLinuxI386sh(f),f)) != NULL)
@@ -228,6 +241,10 @@ static Packer* try_packers(InputFile *f, try_function func)
if ((p = func(new PackCom(f),f)) != NULL) if ((p = func(new PackCom(f),f)) != NULL)
return p; return p;
// Mach (MacOS X PowerPC)
if ((p = func(new PackMachPPC32(f), f)) != NULL)
return p;
return NULL; return NULL;
} }
+5 -22
View File
@@ -1,3 +1,5 @@
.*-stamp
*.ah
*.asx *.asx
*.asy *.asy
*.bin *.bin
@@ -6,30 +8,11 @@
*.lst *.lst
*.map *.map
*.o *.o
*.out
*.tmp
GNUmakefile GNUmakefile
fold_elf86.h MMakefile
fold_exec86.h
fold_sh86.h
l_com.h
l_djgpp2.h
l_exe.h
l_lx_elf86.h
l_lx_exec86.h
l_lx_sh86.h
l_sys.h
l_t_n2b.h
l_t_n2bs.h
l_t_n2d.h
l_t_n2ds.h
l_t_n2e.h
l_t_n2es.h
l_tmt.h
l_vmlinx.h
l_vmlinz.h
l_w32pe.h
l_wcle.h
stamp-h stamp-h
stubify.exe stubify.exe
stubify.h
upxb upxb
upxd upxd
+18
View File
@@ -0,0 +1,18 @@
.*-stamp
*.ah
*.asx
*.asy
*.bin
*.d
*.i
*.lst
*.map
*.o
*.out
*.tmp
GNUmakefile
MMakefile
stamp-h
stubify.exe
upxb
upxd
+255 -48
View File
@@ -5,24 +5,34 @@
# for required build tools # for required build tools
# #
MAKEFLAGS += -rR
SHELL = /bin/sh
ifeq ($(strip $(UCLDIR)),) ifeq ($(strip $(UCLDIR)),)
# change this to reflect where the UCL library is # change this to reflect where the UCL library is
UCLDIR = $(HOME)/local/src/ucl-1.03 UCLDIR = $(HOME)/local/src/ucl-1.03
endif endif
ifeq ($(wildcard $(UCLDIR)/upx),)
$(error Please set UCLDIR in Makefile or environment)
endif
# update path for our special stub build tools
ifneq ($(wildcard $(HOME)/local/bin/bin-upx),)
export PATH := $(HOME)/local/bin/bin-upx:$(PATH)
endif
# ------------------------------------------------------- # -------------------------------------------------------
# You should not have to change anything below this line. # You should not have to change anything below this line.
# ------------------------------------------------------- # -------------------------------------------------------
SHELL = /bin/sh
srcdir = . srcdir = .
top_srcdir = ../.. top_srcdir = ../..
# These are the files we want to create. # These are the files we want to create.
STUBS = \ STUBS = \
l_armpe.h \
l_com.h \ l_com.h \
l_djgpp2.h stubify.h \ l_djgpp2.h stubify.h \
l_exe.h \ l_exe.h \
@@ -35,6 +45,10 @@ STUBS = \
l_lx_exec86.h fold_exec86.h \ l_lx_exec86.h fold_exec86.h \
l_lx_elf86.h fold_elf86.h \ l_lx_elf86.h fold_elf86.h \
l_lx_sh86.h fold_sh86.h \ l_lx_sh86.h fold_sh86.h \
l_lx_pti86.h fold_pti86.h \
l_lx_elfppc32.h fold_elfppc32.h \
l_lx_elf64amd.h fold_elf64amd.h \
l_mac_ppc32.h fold_machppc32.h \
l_vmlinz.h l_vmlinx.h l_vmlinz.h l_vmlinx.h
# experimental: # experimental:
@@ -46,6 +60,10 @@ endif
# util var for use in the rules - basename of the current target # util var for use in the rules - basename of the current target
override T = $(basename $@) override T = $(basename $@)
ifneq ($(strip $(USE_MAKEFILE_DEPS)),)
MAKEFILE_DEPS = $(MAKEFILE_LIST)
endif
# /*********************************************************************** # /***********************************************************************
# // source directories # // source directories
@@ -68,7 +86,7 @@ vpath %.ash $(UCL_MR3K)
# // tools # // tools
# ************************************************************************/ # ************************************************************************/
NASM = nasm -O15 -w+macro-params -w+macro-selfref -w+number-overflow -w+orphan-labels NASM = nasm -O99 -w+macro-params -w+macro-selfref -w+number-overflow -w+orphan-labels
NASM += -I$(srcdir)/ NASM += -I$(srcdir)/
APP_I386 = perl -w $(srcdir)/scripts/app_i386.pl APP_I386 = perl -w $(srcdir)/scripts/app_i386.pl
@@ -77,29 +95,29 @@ BIN2H = perl -w $(srcdir)/scripts/bin2h.pl
BRANDELF = perl -w $(srcdir)/scripts/brandelf.pl BRANDELF = perl -w $(srcdir)/scripts/brandelf.pl
O2BIN = perl -w $(srcdir)/scripts/o2bin.pl O2BIN = perl -w $(srcdir)/scripts/o2bin.pl
##STRIPELF = perl -w $(srcdir)/scripts/stripelf.pl ##STRIPELF = perl -w $(srcdir)/scripts/stripelf.pl
STRIPELF = ./util/sstrip/sstrip
### ###
### linux/i386 ### i386-linux
### ###
LD_LINUX_I386 = ld-2.13.2 LD_LINUX_I386 = ld -m elf_i386
LD_LINUX_I386 = ld OBJCOPY_LINUX_I386 = objcopy -F elf32-i386
OBJCOPY_LINUX_I386 = objcopy OBJSTRIP_LINUX_I386 = $(OBJCOPY_LINUX_I386) -R .comment -R .note
STRIPELF_LINUX_I386 = ./util/sstrip/i386-linux-sstrip
# gcc 2.7.2.3 (fold_*.bin: 1839 / 1011 / 1390) # gcc 2.7.2.3 (fold_*86.bin: 1900 / 1011 / 1786 / 1401)
CC_LINUX_I386_GCC272 = gcc-2.72 -m386 -O2 -MMD CC_LINUX_I386_GCC272 = gcc-2.72 -m386 -O2 -MMD
CC_LINUX_I386_GCC272 += -malign-functions=0 -malign-jumps=0 -malign-loops=0 CC_LINUX_I386_GCC272 += -malign-functions=0 -malign-jumps=0 -malign-loops=0
# gcc 2.95.3 (fold_*.bin: 1721 / 995 / 1321) # gcc 2.95.3 (fold_*86.bin: 1770 / 995 / 1661 / 1314)
CC_LINUX_I386_GCC295 = gcc-2.95.3 -march=i386 -mcpu=k6 -fno-exceptions -MMD CC_LINUX_I386_GCC295 = gcc-2.95.3 -march=i386 -mcpu=k6 -fno-exceptions -MMD
CC_LINUX_I386_GCC295 += -Os -fno-omit-frame-pointer CC_LINUX_I386_GCC295 += -Os -fno-omit-frame-pointer
CC_LINUX_I386_GCC295 += -malign-functions=0 -malign-jumps=0 -malign-loops=0 CC_LINUX_I386_GCC295 += -malign-functions=0 -malign-jumps=0 -malign-loops=0
CC_LINUX_I386_GCC295 += -Werror CC_LINUX_I386_GCC295 += -Werror
# gcc 3.4.3 (fold_*.bin: 1624 / 931 / 1207) # gcc 3.4.6 (fold_*86.bin: 1651 / 947 / 1537 / 1190)
CC_LINUX_I386_GCC34 = gcc-3.4.3 CC_LINUX_I386_GCC34 = gcc-3.4.6
CC_LINUX_I386_GCC34 += -m32 -march=i386 -mtune=k6 -fno-exceptions -MMD CC_LINUX_I386_GCC34 += -m32 -march=i386 -mtune=k6 -fno-exceptions -MMD
CC_LINUX_I386_GCC34 += -Os -fno-omit-frame-pointer CC_LINUX_I386_GCC34 += -Os -fno-omit-frame-pointer
CC_LINUX_I386_GCC34 += -momit-leaf-frame-pointer CC_LINUX_I386_GCC34 += -momit-leaf-frame-pointer
@@ -108,8 +126,20 @@ CC_LINUX_I386_GCC34 += -mpreferred-stack-boundary=2
CC_LINUX_I386_GCC34 += -fweb CC_LINUX_I386_GCC34 += -fweb
CC_LINUX_I386_GCC34 += -Werror CC_LINUX_I386_GCC34 += -Werror
# gcc 4.1.0 (fold_*86.bin: 1725 / 963 / 1620 / 1202)
# gcc 4.0.3 (fold_*86.bin: 1731 / 995 / 1625 / 1195)
CC_LINUX_I386_GCC41 = gcc-4.1.0
CC_LINUX_I386_GCC41 += -m32 -march=i386 -mtune=k6 -fno-exceptions -MMD
CC_LINUX_I386_GCC41 += -Os -fno-omit-frame-pointer
CC_LINUX_I386_GCC41 += -momit-leaf-frame-pointer
CC_LINUX_I386_GCC41 += -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops
CC_LINUX_I386_GCC41 += -mpreferred-stack-boundary=2
CC_LINUX_I386_GCC41 += -fweb
CC_LINUX_I386_GCC41 += -Werror
CC_LINUX_I386 = $(CC_LINUX_I386_GCC272) CC_LINUX_I386 = $(CC_LINUX_I386_GCC272)
CC_LINUX_I386 = $(CC_LINUX_I386_GCC295) CC_LINUX_I386 = $(CC_LINUX_I386_GCC295)
CC_LINUX_I386 = $(CC_LINUX_I386_GCC41)
CC_LINUX_I386 = $(CC_LINUX_I386_GCC34) CC_LINUX_I386 = $(CC_LINUX_I386_GCC34)
CC_LINUX_I386 += -nostdinc CC_LINUX_I386 += -nostdinc
CC_LINUX_I386 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings CC_LINUX_I386 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings
@@ -142,6 +172,66 @@ else
endif endif
###
### PowerPC 32
###
GCC_PPC32 := false
LD_PPC32 := false
OBJCOPY_PPC32 := false
OBJSTRIP_PPC32 = $(OBJCOPY_PPC32) -R .comment -R .note
d = /home2/crosstool/powerpc-750-linux-gnu/gcc-3.4.1-glibc-20040827/bin
ifneq ($(wildcard $d),)
GCC_PPC32 := $d/powerpc-750-linux-gnu-gcc -m32 -nostdinc -MMD
LD_PPC32 := $d/powerpc-750-linux-gnu-ld
OBJCOPY_PPC32 := $d/powerpc-750-linux-gnu-objcopy
endif
d = /opt/cc-i386-linux/crosstool/powerpc-750-linux-gnu/gcc-3.4.3.20050210-glibc-2.2.5/bin
ifneq ($(wildcard $d),)
GCC_PPC32 := $d/powerpc-750-linux-gnu-gcc -m32 -nostdinc -MMD
LD_PPC32 := $d/powerpc-750-linux-gnu-ld
OBJCOPY_PPC32 := $d/powerpc-750-linux-gnu-objcopy
endif
GCC_PPC32 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
###
### AMD x86_64
###
GCC_AMD64 := false
LD_AMD64 := false
OBJCOPY_AMD64 := false
OBJSTRIP_AMD64 = $(OBJCOPY_AMD64) -R .comment -R .note
d = /home2/crosstool/gcc-4.0.1-glibc-2.3.5/x86_64-unknown-linux-gnu/bin
ifneq ($(wildcard $d),)
GCC_AMD64 := $d/x86_64-unknown-linux-gnu-gcc -m64 -nostdinc -MMD
LD_AMD64 := $d/x86_64-unknown-linux-gnu-ld -m elf_x86_64
OBJCOPY_AMD64 := $d/x86_64-unknown-linux-gnu-objcopy -F elf64-x86-64
endif
d = /opt/cc-i386-linux/crosstool/x86_64-unknown-linux-gnu/gcc-3.4.3.20050507-glibc-2.3.5/bin
ifneq ($(wildcard $d),)
GCC_AMD64 := $d/x86_64-unknown-linux-gnu-gcc -m64 -nostdinc -MMD
LD_AMD64 := $d/x86_64-unknown-linux-gnu-ld -m elf_x86_64
OBJCOPY_AMD64 := $d/x86_64-unknown-linux-gnu-objcopy -F elf64-x86-64
endif
GCC_AMD64 += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
###
### ARM-PE-WINCE
###
GCC_ARM := arm-9tdmi-linux-gnu-gcc -march=armv4 -nostdinc -MMD
GCC_ARM += -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings -Werror
GCC_ARM_T := $(GCC_ARM) -march=armv4t -mthumb-interwork -mthumb
LD_ARM := arm-9tdmi-linux-gnu-ld
OBJCOPY_ARM := arm-9tdmi-linux-gnu-objcopy
BIN2H_WINCE := perl -ne 'print "db\t", join(",", map { sprintf "%\#02x", $$_ } unpack("C*", $$_)), "\n"'
# /*********************************************************************** # /***********************************************************************
# // main targets # // main targets
# ************************************************************************/ # ************************************************************************/
@@ -159,7 +249,7 @@ stubs: $(STUBS)
mostlyclean: mostlyclean:
-rm -f *.bin *.bkp *.d *.i *.lst *.map stubify.exe -rm -f *.bin *.bkp *.d *.i *.lst *.map stubify.exe
-rm -f *.o *.asx *.asy -rm -f *.ah *.asx *.asy *.o *.out
clean: mostlyclean clean: mostlyclean
ifneq ($(strip $(wildcard stamp-h)),) ifneq ($(strip $(wildcard stamp-h)),)
@@ -185,10 +275,10 @@ strings: all
# // rules # // rules
# ************************************************************************/ # ************************************************************************/
%.asx : %.asm %.asx : %.asm $(srcdir)/scripts/app_i386.pl
$(APP_I386) $< $@ $(APP_I386) $< $@
%.asy : %.ash %.asy : %.ash $(srcdir)/scripts/app_i386.pl
$(APP_I386) $< $@ $(APP_I386) $< $@
@@ -305,7 +395,7 @@ l_ps1c.h: l_ps1.asm
upx_itoa.o: upx_itoa.asm upx_itoa.o: upx_itoa.asm
$(NASM) -f elf -o $@ $< $(NASM) -f elf -o $@ $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(OBJSTRIP_LINUX_I386) $@
l_lx_elf86.h: l_lx_elf86.asx l_lx_elf86.h: l_lx_elf86.asx
$(NASM) -f bin -o $T.bin $< $(NASM) -f bin -o $T.bin $<
@@ -319,88 +409,197 @@ l_lx_sh86.h: l_lx_sh86.asx
$(NASM) -f bin -o $T.bin $< $(NASM) -f bin -o $T.bin $<
$(BIN2H) $T.bin linux_i386sh_loader $@ $(BIN2H) $T.bin linux_i386sh_loader $@
l_lx_elf.o: l_lx_elf.c linux.hh l_lx_pti86.h: l_lx_pti86.asx
$(CC_LINUX_I386) -c $< $(NASM) -f bin -o $T.bin $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(BIN2H) $T.bin linux_i386pti_loader $@
l_lx_exec.o: l_lx_exec.c linux.hh l_mac_ppc32.h: l_mac_ppc32.S ppc_d_nrv2e.S
$(CC_LINUX_I386) -c $< $(GCC_PPC32) -c $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(OBJSTRIP_PPC32) $T.o
$(LD_PPC32) -o $T.bin --oformat binary $T.o
$(BIN2H) $T.bin l_mac_ppc32_loader $@
l_lx_sep.o: l_lx_sep.c linux.hh l_lx_elfppc32.h: l_lx_elfppc32.S ppc_d_nrv2e.S
$(CC_LINUX_I386) -c $< $(GCC_PPC32) -c $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(OBJSTRIP_PPC32) $T.o
$(LD_PPC32) -o $T.bin --oformat binary $T.o
$(BIN2H) $T.bin linux_elfppc32_loader $@
l_lx_sh.o: l_lx_sh.c linux.hh l_lx_elf64amd.h: l_lx_elf64amd.S amd_d_nrv2e.S
$(GCC_AMD64) -c $<
$(OBJSTRIP_AMD64) $T.o
$(LD_AMD64) -o $T.bin --oformat binary $T.o
$(BIN2H) $T.bin linux_elf64amd_loader $@
l_lx_elf.o: l_lx_elf.c linux.hh $(MAKEFILE_DEPS)
$(CC_LINUX_I386) -c $< $(CC_LINUX_I386) -c $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(OBJSTRIP_LINUX_I386) $@
l_lx_exec.o: l_lx_exec.c linux.hh $(MAKEFILE_DEPS)
$(CC_LINUX_I386) -c $<
$(OBJSTRIP_LINUX_I386) $@
l_lx_sep.o: l_lx_sep.c linux.hh $(MAKEFILE_DEPS)
$(CC_LINUX_I386) -c $<
$(OBJSTRIP_LINUX_I386) $@
l_lx_sh.o: l_lx_sh.c linux.hh $(MAKEFILE_DEPS)
$(CC_LINUX_I386) -c $<
$(OBJSTRIP_LINUX_I386) $@
l_lx_pti.o: l_lx_pti.c linux.hh $(MAKEFILE_DEPS)
$(CC_LINUX_I386) -c $<
$(OBJSTRIP_LINUX_I386) $@
fold_elf86.o: fold_elf86.asm fold_elf86.o: fold_elf86.asm
$(NASM) -f elf -o $@ $< $(NASM) -f elf -o $@ $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(OBJSTRIP_LINUX_I386) $@
fold_elf86.h: l_lx_elf.o fold_elf86.o l_lx_elf86.lds fold_elf86.h: l_lx_elf.o fold_elf86.o l_lx_elf86.lds
$(LD_LINUX_I386) -T $(srcdir)/l_lx_elf86.lds -Map $T.map -o $T.bin $T.o l_lx_elf.o $(LD_LINUX_I386) -T $(srcdir)/l_lx_elf86.lds -Map $T.map -o $T.bin $T.o l_lx_elf.o
chmod a-x $T.bin chmod a-x $T.bin
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin $(OBJSTRIP_LINUX_I386) $T.bin
$(STRIPELF) $T.bin $(STRIPELF_LINUX_I386) $T.bin
$(BRANDELF) $T.bin $(BRANDELF) $T.bin
$(BIN2H) $T.bin linux_i386elf_fold $@ $(BIN2H) $T.bin linux_i386elf_fold $@
m_lx_elfppc32.o: m_lx_elfppc32.c $(MAKEFILE_DEPS)
$(GCC_PPC32) -c -Os $<
$(OBJSTRIP_PPC32) $@
a_lx_elf64amd.o: a_lx_elf64.c $(MAKEFILE_DEPS)
$(GCC_AMD64) -c -Os -o $@ $<
$(OBJSTRIP_AMD64) $@
fold_elfppc32.o: fold_elfppc32.S ppc_bxx.S $(MAKEFILE_DEPS)
$(GCC_PPC32) -c $<
$(OBJSTRIP_PPC32) $@
fold_elf64amd.o: fold_elf64amd.S amd_bxx.S $(MAKEFILE_DEPS)
$(GCC_AMD64) -c $<
$(OBJSTRIP_AMD64) $@
fold_elfppc32.h: m_lx_elfppc32.o fold_elfppc32.o l_lx_elfppc32.lds
$(LD_PPC32) -T $(srcdir)/l_lx_elfppc32.lds -Map $T.map -o $T.bin --strip-all \
fold_elfppc32.o m_lx_elfppc32.o
$(BIN2H) $T.bin linux_elfppc32_fold $@
fold_elf64amd.h: a_lx_elf64amd.o fold_elf64amd.o l_lx_elf64amd.lds amd_bxx.S
$(LD_AMD64) -T $(srcdir)/l_lx_elf64amd.lds -Map $T.map -o $T.bin --strip-all \
fold_elf64amd.o a_lx_elf64amd.o
$(STRIPELF_LINUX_I386) $T.bin
$(BIN2H) $T.bin linux_elf64amd_fold $@
fold_exec86.o: fold_exec86.asm fold_exec86.o: fold_exec86.asm
$(NASM) -f elf -o $@ $< $(NASM) -f elf -o $@ $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(OBJSTRIP_LINUX_I386) $@
fold_exec86.h: l_lx_exec.o upx_itoa.o fold_exec86.o l_lx_exec86.lds fold_exec86.h: l_lx_exec.o upx_itoa.o fold_exec86.o l_lx_exec86.lds
$(LD_LINUX_I386) -T $(srcdir)/l_lx_exec86.lds -Map $T.map -o $T.bin $T.o l_lx_exec.o upx_itoa.o $(LD_LINUX_I386) -T $(srcdir)/l_lx_exec86.lds -Map $T.map -o $T.bin $T.o l_lx_exec.o upx_itoa.o
chmod a-x $T.bin chmod a-x $T.bin
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin $(OBJSTRIP_LINUX_I386) $T.bin
$(STRIPELF) $T.bin $(STRIPELF_LINUX_I386) $T.bin
$(BRANDELF) $T.bin $(BRANDELF) $T.bin
$(BIN2H) $T.bin linux_i386exec_fold $@ $(BIN2H) $T.bin linux_i386exec_fold $@
fold_sh86.o: fold_sh86.asm fold_sh86.o: fold_sh86.asm
$(NASM) -f elf -o $@ $< $(NASM) -f elf -o $@ $<
$(OBJCOPY_LINUX_I386) -R .comment -R .note $@ $(OBJSTRIP_LINUX_I386) $@
fold_sh86.h: l_lx_sh.o fold_sh86.o l_lx_sh86.lds fold_sh86.h: l_lx_sh.o fold_sh86.o l_lx_sh86.lds
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sh86.lds -Map $T.map -o $T.bin $T.o l_lx_sh.o $(LD_LINUX_I386) -T $(srcdir)/l_lx_sh86.lds -Map $T.map -o $T.bin $T.o l_lx_sh.o
chmod a-x $T.bin chmod a-x $T.bin
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $T.bin $(OBJSTRIP_LINUX_I386) $T.bin
$(STRIPELF) $T.bin $(STRIPELF_LINUX_I386) $T.bin
$(BRANDELF) $T.bin $(BRANDELF) $T.bin
$(BIN2H) $T.bin linux_i386sh_fold $@ $(BIN2H) $T.bin linux_i386sh_fold $@
fold_pti86.o: fold_pti86.asm
$(NASM) -f elf -i$(UCL_I386)/ -o $@ $<
$(OBJSTRIP_LINUX_I386) $@
fold_pti86.h: l_lx_pti.o fold_pti86.o l_lx_pti86.lds
$(LD_LINUX_I386) -T $(srcdir)/l_lx_pti86.lds -Map $T.map -o $T.bin $T.o l_lx_pti.o
chmod a-x $T.bin
$(OBJSTRIP_LINUX_I386) $T.bin
$(STRIPELF_LINUX_I386) $T.bin
$(BRANDELF) $T.bin
$(BIN2H) $T.bin linux_i386pti_fold $@
fold_machppc32.h: m_mac_mach32.o fold_machppc32.o
$(LD_PPC32) -Map $T.map -o $T.bin --oformat binary fold_machppc32.o m_mac_mach32.o
chmod a-x $T.bin
$(BIN2H) $T.bin fold_machppc32 $@
m_mac_mach32.o: m_mac_mach32.c $(MAKEFILE_DEPS)
$(GCC_PPC32) -Os -c $<
$(OBJSTRIP_PPC32) $@
fold_machppc32.o: fold_machppc32.S ppc_bxx.S $(MAKEFILE_DEPS)
$(GCC_PPC32) -c $<
$(OBJSTRIP_PPC32) $@
upxb: l_lx_sep.o l_lx_sep86.asm upxb: l_lx_sep.o l_lx_sep86.asm
$(NASM) -i$(UCL_I386)/ -f elf -dNRV2B -o $T.o l_lx_sep86.asm $(NASM) -f elf -i$(UCL_I386)/ -dNRV2B -o $T.o l_lx_sep86.asm
$(OBJSTRIP_LINUX_I386) $T.o
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o $(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $@ $(OBJSTRIP_LINUX_I386) $@
$(STRIPELF) $@ $(STRIPELF_LINUX_I386) $@
$(BRANDELF) $@ $(BRANDELF) $@
upxd: l_lx_sep.o l_lx_sep86.asm upxd: l_lx_sep.o l_lx_sep86.asm
$(NASM) -i$(UCL_I386)/ -f elf -dNRV2D -o $T.o l_lx_sep86.asm $(NASM) -f elf -i$(UCL_I386)/ -dNRV2D -o $T.o l_lx_sep86.asm
$(OBJSTRIP_LINUX_I386) $T.o
$(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o $(LD_LINUX_I386) -T $(srcdir)/l_lx_sep86.lds -Map $T.map -o $@ $T.o l_lx_sep.o
$(OBJCOPY_LINUX_I386) -S -R .comment -R .note $@ $(OBJSTRIP_LINUX_I386) $@
$(STRIPELF) $@ $(STRIPELF_LINUX_I386) $@
$(BRANDELF) $@ $(BRANDELF) $@
l_armpe.h: l_armpe.asx l_armpe_s.S l_armpe_c.c arm_nrv2e_d8.S arm_nrv2b_d8.S armv4_n2e_d8.S $(MAKEFILE_LIST)
$(GCC_ARM_T) -c l_armpe_s.S arm_nrv2e_d8.S arm_nrv2b_d8.S
$(GCC_ARM_T) -Os -c l_armpe_c.c -DUCL_DECOMPRESS=thumb_nrv2e_d8
$(LD_ARM) -o l_armpe_txe.out l_armpe_s.o l_armpe_c.o arm_nrv2e_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe_txe.out l_armpe_txe.bin
$(BIN2H_WINCE) <l_armpe_txe.bin >l_armpe_txe.ah
$(GCC_ARM_T) -Os -c l_armpe_c.c -DUCL_DECOMPRESS=go_thumb_n2b
$(LD_ARM) -o l_armpe_txb.out l_armpe_s.o l_armpe_c.o arm_nrv2b_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe_txb.out l_armpe_txb.bin
$(BIN2H_WINCE) <l_armpe_txb.bin >l_armpe_txb.ah
$(GCC_ARM_T) -DSTUB_FOR_DLL -c l_armpe_s.S
$(GCC_ARM_T) -DSTUB_FOR_DLL -Os -c l_armpe_c.c -DUCL_DECOMPRESS=thumb_nrv2e_d8
$(LD_ARM) -o l_armpe_tde.out l_armpe_s.o l_armpe_c.o arm_nrv2e_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe_tde.out l_armpe_tde.bin
$(BIN2H_WINCE) <l_armpe_tde.bin >l_armpe_tde.ah
$(GCC_ARM_T) -DSTUB_FOR_DLL -Os -c l_armpe_c.c -DUCL_DECOMPRESS=go_thumb_n2b
$(LD_ARM) -o l_armpe_tdb.out l_armpe_s.o l_armpe_c.o arm_nrv2b_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe_tdb.out l_armpe_tdb.bin
$(BIN2H_WINCE) <l_armpe_tdb.bin >l_armpe_tdb.ah
$(GCC_ARM) -Os -c l_armpe_c.c -DUCL_DECOMPRESS=ucl_nrv2e_decompress_8
$(GCC_ARM) -c armv4_n2e_d8.S l_armpe_s.S
$(LD_ARM) -o l_armpe_axe.out l_armpe_s.o l_armpe_c.o armv4_n2e_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe_axe.out l_armpe_axe.bin
$(BIN2H_WINCE) <l_armpe_axe.bin >l_armpe_axe.ah
$(GCC_ARM) -DSTUB_FOR_DLL -Os -c l_armpe_c.c -DUCL_DECOMPRESS=ucl_nrv2e_decompress_8
$(GCC_ARM) -DSTUB_FOR_DLL -c l_armpe_s.S
$(LD_ARM) -o l_armpe_ade.out l_armpe_s.o l_armpe_c.o armv4_n2e_d8.o
$(OBJCOPY_ARM) --only-section .text -O binary l_armpe_ade.out l_armpe_ade.bin
$(BIN2H_WINCE) <l_armpe_ade.bin >l_armpe_ade.ah
$(NASM) -f bin -o $T.bin $<
$(BIN2H) $T.bin nrv_loader $@
# /*********************************************************************** # /***********************************************************************
# // dependencies # // dependencies
# ************************************************************************/ # ************************************************************************/
DEPS_FILES := $(wildcard *.d) -include *.d
ifneq ($(strip $(DEPS_FILES)),)
include $(DEPS_FILES)
endif
DEPS1 = header.ash macros.ash ident.ash ident_n.ash ident_s.ash DEPS1 = header.ash macros.ash ident.ash ident_n.ash ident_s.ash
DEPS2 = header.asy macros.asy DEPS2 = header.asy macros.asy
DEPS3 = n2b_d32.asy n2d_d32.asy n2e_d32.asy DEPS3 = n2b_d32.asy n2d_d32.asy n2e_d32.asy cl1_d32.asy
$(STUBS): $(srcdir)/scripts/bin2h.pl $(STUBS): $(srcdir)/scripts/bin2h.pl
l_armpe.h: $(DEPS2) $(DEPS3)
l_com.h: n2b_d16.asy $(DEPS2) l_com.h: n2b_d16.asy $(DEPS2)
l_djgpp2.h: $(DEPS2) $(DEPS3) l_djgpp2.h: $(DEPS2) $(DEPS3)
l_exe.h: n2b_d8e.asy n2d_d8e.asy n2e_d8e.asy $(DEPS2) l_exe.h: n2b_d8e.asy n2d_d8e.asy n2e_d8e.asy $(DEPS2)
@@ -420,8 +619,16 @@ l_w32pe.h: $(DEPS2) $(DEPS3)
l_lx_elf86.h: l_lx_elf86.asm macros.ash macros.asy $(DEPS3) l_lx_elf86.h: l_lx_elf86.asm macros.ash macros.asy $(DEPS3)
l_lx_exec86.h: l_lx_exec86.asm macros.ash macros.asy $(DEPS3) l_lx_exec86.h: l_lx_exec86.asm macros.ash macros.asy $(DEPS3)
l_lx_pti86.h: l_lx_pti86.asm macros.ash macros.asy $(DEPS3)
l_lx_sh86.h: l_lx_sh86.asm macros.ash macros.asy $(DEPS3) l_lx_sh86.h: l_lx_sh86.asm macros.ash macros.asy $(DEPS3)
.NOEXPORT:
# FIXME: what is this ???
upxrun: start-interp.o interp.o
gcc -nostartfiles -nostdlib -o $@ -Ttext=0x10000 $^
start-interp.o: start-interp.S
gcc -c $<
interp.o: interp.c
gcc -c -g $<
# vi:nowrap # vi:nowrap
+361
View File
@@ -0,0 +1,361 @@
/* a_lx_elf64.c -- stub loader for Linux 64-bit ELF executable
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-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>
*/
#include "linux.hh"
extern void exit(int);
/*************************************************************************
// configuration section
**************************************************************************/
// In order to make it much easier to move this code at runtime and execute
// it at an address different from it load address: there must be no
// static data, and no string constants.
#define MAX_ELF_HDR 1024 // Elf64_Ehdr + n*Elf64_Phdr must fit in this
/*************************************************************************
// "file" util
**************************************************************************/
typedef struct {
size_t size; // must be first to match size[0] uncompressed size
char *buf;
} Extent;
static void
xread(Extent *x, char *buf, size_t count)
{
char *p=x->buf, *q=buf;
size_t j;
if (x->size < count) {
exit(127);
}
for (j = count; 0!=j--; ++p, ++q) {
*q = *p;
}
x->buf += count;
x->size -= count;
}
/*************************************************************************
// util
**************************************************************************/
#if 1 //{ save space
#define ERR_LAB error: exit(127);
#define err_exit(a) goto error
#else //}{ save debugging time
#define ERR_LAB
static void
err_exit(int a)
{
(void)a; // debugging convenience
exit(127);
}
#endif //}
/*************************************************************************
// UPX & NRV stuff
**************************************************************************/
typedef void f_unfilter(
nrv_byte *, // also addvalue
nrv_uint,
unsigned cto8, // junk in high 24 bits
unsigned ftid
);
typedef int f_expand(
const nrv_byte *, nrv_uint,
nrv_byte *, nrv_uint *, unsigned );
static void
unpackExtent(
Extent *const xi, // input
Extent *const xo, // output
f_expand *const f_decompress,
f_unfilter *f_unf
)
{
while (xo->size) {
struct b_info h;
// Note: if h.sz_unc == h.sz_cpr then the block was not
// compressible and is stored in its uncompressed form.
// Read and check block sizes.
xread(xi, (char *)&h, sizeof(h));
if (h.sz_unc == 0) { // uncompressed size 0 -> EOF
if (h.sz_cpr != UPX_MAGIC_LE32) // h.sz_cpr must be h->magic
err_exit(2);
if (xi->size != 0) // all bytes must be written
err_exit(3);
break;
}
if (h.sz_cpr <= 0) {
err_exit(4);
ERR_LAB
}
if (h.sz_cpr > h.sz_unc
|| h.sz_unc > xo->size ) {
err_exit(5);
}
// Now we have:
// assert(h.sz_cpr <= h.sz_unc);
// assert(h.sz_unc > 0 && h.sz_unc <= blocksize);
// assert(h.sz_cpr > 0 && h.sz_cpr <= blocksize);
if (h.sz_cpr < h.sz_unc) { // Decompress block
nrv_uint out_len;
int const j = (*f_decompress)((unsigned char *)xi->buf, h.sz_cpr,
(unsigned char *)xo->buf, &out_len, h.b_method );
if (j != 0 || out_len != (nrv_uint)h.sz_unc)
err_exit(7);
// Skip Ehdr+Phdrs: separate 1st block, not filtered
if (h.b_ftid!=0 && f_unf // have filter
&& ((512 < out_len) // this block is longer than Ehdr+Phdrs
|| (xo->size==(unsigned)h.sz_unc) ) // block is last in Extent
) {
(*f_unf)((unsigned char *)xo->buf, out_len, h.b_cto8, h.b_ftid);
}
xi->buf += h.sz_cpr;
xi->size -= h.sz_cpr;
}
else { // copy literal block
xread(xi, xo->buf, h.sz_cpr);
}
xo->buf += h.sz_unc;
xo->size -= h.sz_unc;
}
}
#if 0 /*{*/
static void
upx_bzero(char *p, size_t len)
{
if (len) do {
*p++= 0;
} while (--len);
}
#define bzero upx_bzero
#else
#define bzero(a,b) __builtin_memset(a,0,b)
#endif /*}*/
static void
auxv_up(Elf64_auxv_t *av, unsigned const type, uint64_t const value)
{
if (av)
for (;; ++av) {
if (av->a_type==type || (av->a_type==AT_IGNORE && type!=AT_NULL)) {
av->a_type = type;
av->a_un.a_val = value;
return;
}
}
}
// The PF_* and PROT_* bits are {1,2,4}; the conversion table fits in 32 bits.
#define REP8(x) \
((x)|((x)<<4)|((x)<<8)|((x)<<12)|((x)<<16)|((x)<<20)|((x)<<24)|((x)<<28))
#define EXP8(y) \
((1&(y)) ? 0xf0f0f0f0 : (2&(y)) ? 0xff00ff00 : (4&(y)) ? 0xffff0000 : 0)
#define PF_TO_PROT(pf) \
((PROT_READ|PROT_WRITE|PROT_EXEC) & ( \
( (REP8(PROT_EXEC ) & EXP8(PF_X)) \
|(REP8(PROT_READ ) & EXP8(PF_R)) \
|(REP8(PROT_WRITE) & EXP8(PF_W)) \
) >> ((pf & (PF_R|PF_W|PF_X))<<2) ))
// Find convex hull of PT_LOAD (the minimal interval which covers all PT_LOAD),
// and mmap that much, to be sure that a kernel using exec-shield-randomize
// won't place the first piece in a way that leaves no room for the rest.
static unsigned long // returns relocation constant
xfind_pages(unsigned mflags, Elf64_Phdr const *phdr, int phnum,
char **const p_brk
)
{
size_t lo= ~0, hi= 0, szlo= 0;
char *addr;
mflags += MAP_PRIVATE | MAP_ANONYMOUS; // '+' can optimize better than '|'
for (; --phnum>=0; ++phdr) if (PT_LOAD==phdr->p_type) {
if (phdr->p_vaddr < lo) {
lo = phdr->p_vaddr;
szlo = phdr->p_filesz;
}
if (hi < (phdr->p_memsz + phdr->p_vaddr)) {
hi = phdr->p_memsz + phdr->p_vaddr;
}
}
szlo += ~PAGE_MASK & lo; // page fragment on lo edge
lo -= ~PAGE_MASK & lo; // round down to page boundary
hi = PAGE_MASK & (hi - lo - PAGE_MASK -1); // page length
szlo = PAGE_MASK & (szlo - PAGE_MASK -1); // page length
addr = mmap((void *)lo, hi, PROT_READ|PROT_WRITE|PROT_EXEC, mflags, 0, 0);
*p_brk = hi + addr; // the logical value of brk(0)
munmap(szlo + addr, hi - szlo); // desirable if PT_LOAD non-contiguous
return (unsigned long)addr - lo;
}
static Elf64_Addr // entry address
do_xmap(
Elf64_Ehdr const *const ehdr,
Extent *const xi,
int const fdi,
Elf64_auxv_t *const av,
f_expand *const f_decompress,
f_unfilter *const f_unf
)
{
Elf64_Phdr const *phdr = (Elf64_Phdr const *) (ehdr->e_phoff +
(char const *)ehdr);
char *v_brk;
unsigned long const reloc = xfind_pages(
((ET_DYN!=ehdr->e_type) ? MAP_FIXED : 0), phdr, ehdr->e_phnum, &v_brk);
int j;
for (j=0; j < ehdr->e_phnum; ++phdr, ++j)
if (xi && PT_PHDR==phdr->p_type) {
auxv_up(av, AT_PHDR, phdr->p_vaddr + reloc);
} else
if (PT_LOAD==phdr->p_type) {
unsigned const prot = PF_TO_PROT(phdr->p_flags);
Extent xo;
size_t mlen = xo.size = phdr->p_filesz;
char *addr = xo.buf = reloc + (char *)phdr->p_vaddr;
char *haddr = phdr->p_memsz + addr;
size_t frag = (long)addr &~ PAGE_MASK;
mlen += frag;
addr -= frag;
if (addr != mmap(addr, mlen, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | (xi ? MAP_ANONYMOUS : 0),
fdi, phdr->p_offset - frag) ) {
err_exit(8);
}
if (xi) {
unpackExtent(xi, &xo, f_decompress, f_unf);
}
bzero(addr, frag); // fragment at lo end
frag = (-mlen) &~ PAGE_MASK; // distance to next page boundary
bzero(mlen+addr, frag); // fragment at hi end
if (xi && 0==phdr->p_offset) {
Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)addr;
*(int *)&ehdr->e_ident[12] = 0x90c3050f; // syscall; ret; nop
}
if (0!=mprotect(addr, mlen, prot)) {
err_exit(10);
ERR_LAB
}
addr += mlen + frag; /* page boundary on hi end */
if (addr < haddr) { // need pages for .bss
if (addr != mmap(addr, haddr - addr, prot,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0 ) ) {
err_exit(9);
}
}
}
if (xi) { // 1st call (main); also have (0!=av) here
if (ET_DYN!=ehdr->e_type) {
// Needed only if compressed shell script invokes compressed shell.
brk(v_brk);
}
}
return ehdr->e_entry + reloc;
}
/*************************************************************************
// upx_main - called by our entry code
//
// This function is optimized for size.
**************************************************************************/
void *
upx_main( // returns entry address
struct b_info const *const bi, // 1st block header
size_t const sz_compressed, // total length
Elf64_Ehdr *const ehdr, // temp char[sz_ehdr] for decompressing
Elf64_auxv_t *const av,
f_expand *const f_decompress,
f_unfilter *const f_unf
)
{
Elf64_Phdr const *phdr = (Elf64_Phdr const *)(1+ ehdr);
Elf64_Addr entry;
Extent xo, xi1, xi2;
xo.buf = (char *)ehdr;
xo.size = bi->sz_unc;
xi2.buf = CONST_CAST(char *, bi); xi2.size = sz_compressed;
xi1.buf = CONST_CAST(char *, bi); xi1.size = sz_compressed;
// ehdr = Uncompress Ehdr and Phdrs
unpackExtent(&xi2, &xo, f_decompress, 0); // never filtered?
// AT_PHDR.a_un.a_val is set again by do_xmap if PT_PHDR is present.
auxv_up(av, AT_PHDR , (unsigned long)(1+(Elf64_Ehdr *)phdr->p_vaddr));
auxv_up(av, AT_PHNUM , ehdr->e_phnum);
auxv_up(av, AT_ENTRY , (unsigned long)ehdr->e_entry);
//auxv_up(av, AT_PHENT , ehdr->e_phentsize); /* this can never change */
//auxv_up(av, AT_PAGESZ, PAGE_SIZE); /* ld-linux.so.2 does not need this */
entry = do_xmap(ehdr, &xi1, 0, av, f_decompress, f_unf); // "rewind"
{ // Map PT_INTERP program interpreter
int j;
for (j=0; j < ehdr->e_phnum; ++phdr, ++j) if (PT_INTERP==phdr->p_type) {
char const *const iname = (char const *)phdr->p_vaddr;
int const fdi = open(iname, O_RDONLY, 0);
if (0 > fdi) {
err_exit(18);
}
if (MAX_ELF_HDR!=read(fdi, (void *)ehdr, MAX_ELF_HDR)) {
ERR_LAB
err_exit(19);
}
entry = do_xmap(ehdr, 0, fdi, 0, 0, 0);
close(fdi);
}
}
return (void *)entry;
}
/*
vi:ts=4:et:nowrap
*/
+64
View File
@@ -0,0 +1,64 @@
/* amd_bxx.S -- AMD x86_64 Call/Branch Trick unfilter
This file is part of the UPX executable compressor.
Copyright (C) 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.
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#include "amd_regs.h"
amdbxx: # (*f_unf)(xo->buf, out_len, h.b_cto8, h.b_ftid);
#define ptr %arg1 /* known to be %rdi */
#define len %arg2
#define cto8 %arg3l /* known to be "%dl" */
#define ftid %arg4l
cmpl $0x49,ftid; jne ckend # filter: JMP, CALL, 6-byte Jxx
movq len,%rcx # byte count
movq ptr,%rsi # remember start of buffer
jmp ckstart
ckloop3:
movb (%rdi),%al; addq $1,%rdi
cmpb $0x80,%al; jb ckloop2 # lo of 6-byte Jcc
cmpb $0x8F,%al; ja ckloop2 # hi of 6-byte Jcc
cmpb $0x0F,-2(%rdi); je ckmark # prefix of 6-byte Jcc
ckloop2:
subb $ 0xE8,%al
cmpb $0xE9-0xE8,%al; ja ckcount # not JMP, not CALL
ckmark:
cmpb %dl,(%rdi); jne ckcount # not marked with cto8
movl (%rdi),%eax # the marked, bswapped 32-bit displacement
andl $~0<<8,%eax # clear the mark
bswap %eax
subl %edi,%eax
addl %esi,%eax
stosl # *%rdi++ = %eax;
ckstart:
subq $4,%rcx
movb (%rdi),%al; addq $1,%rdi
decq %rcx; jnz ckloop2 # prefix cannot overlap previous displacement
jmp ckend
ckcount:
decq %rcx; jnz ckloop3
ckend:
ret
+68
View File
@@ -0,0 +1,68 @@
/* amd_d_nrv2b.S -- AMD64 decompressor for NRV2B
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-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>
*/
ALIGN(1<<3)
lit_n2b:
incq %rsi; movb %dl,(%rdi)
incq %rdi
top_n2b:
movb (%rsi),%dl # speculate: literal, or bottom 8 bits of offset
jnextb1yp lit_n2b
lea 1(lenq),off # [len= 0] off= 1
offmore_n2b:
getnextbp(off)
jnextb0np offmore_n2b
subl $ 3,off; jc len_n2b # use previous offset
shll $ 8,off; movzbl %dl,%edx
orl %edx,off; incq %rsi
xorl $~0,off; jz eof
movslq off,disp # XXX: 2GB
len_n2b:
lea 1(lenq),off # [len= 0] off= 1
getnextb(len); getnextb(len) # two bits; cc set on result
jnz gotlen_n2b # raw 1,2,3 ==> 2,3,4
movl off,len # len= 1, the msb
addl $3-1,off # raw 2.. ==> 5..
lenmore_n2b:
getnextb(len)
jnextb0n lenmore_n2b
gotlen_n2b:
cmpq $-0xd00,disp
adcl off,len # len += off + (disp < -0xd00)
call copy
bot_n2b: # In: 0==len
jmp top_n2b
/*
vi:ts=8:et:nowrap
*/
+81
View File
@@ -0,0 +1,81 @@
/* amd_d_nrv2e.S -- AMD64 decompressor for NRV2E
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-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>
*/
ALIGN(1<<3)
lit_n2e:
incq %rsi; movb %dl,(%rdi)
incq %rdi
top_n2e:
movb (%rsi),%dl # speculate: literal, or bottom 8 bits of offset
jnextb1yp lit_n2e
lea 1(lenq),off # [len= 0] off= 1
jmp getoff_n2e
off_n2e:
dec off
getnextbp(off)
getoff_n2e:
getnextbp(off)
jnextb0np off_n2e
subl $ 3,off; jc offprev_n2e
shll $ 8,off; movzbl %dl,%edx
orl %edx,off; incq %rsi
xorl $~0,off; jz eof
sarl off # Carry= original low bit
movslq off,disp # XXX: 2GB
jc lenlast_n2e
jmp lenmore_n2e
offprev_n2e:
jnextb1y lenlast_n2e
lenmore_n2e:
incl len # len= 1
jnextb1y lenlast_n2e
len_n2e:
getnextb(len)
jnextb0n len_n2e
addl $6-2-2,len
jmp gotlen_n2e
lenlast_n2e:
getnextb(len) # 0,1,2,3
gotlen_n2e:
cmpq $-0x500,disp
adcl $2,len # len += 2+ (disp < -0x500);
call copy
bot_n2e: # In: 0==len
jmp top_n2e
/*
vi:ts=8:et:nowrap
*/
+15
View File
@@ -0,0 +1,15 @@
/* NOTE: THE FIRST ARGUMENT IS arg1, NOT arg0. */
#define arg1 rdi
#define arg1l edi
#define arg2 rsi
#define arg2l esi
#define arg3 rdx
#define arg3l edx
#define arg4 rcx
#define arg4l ecx
#define sys4 r10 # 4th arg to syscall is not in %rcx
#define sys4l r10d
#define arg5 r8
#define arg5l r8d
#define arg6 r9
#define arg6l r9d
+129
View File
@@ -0,0 +1,129 @@
/* arm_nrv2b_d32.S -- ARM decompressor for NRV2B
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-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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#define src r0
#define len r1
#define dst r2
#define tmp r3
#define bits r4
#define off r5
#define g1b r6
#define wrnk r7 /* 0xd00 M2_MAX_OFFSET before "wrinkle" */
/* r12 ("ip") is assumed to be a scratch register. */
#define GETBIT blx g1b
#define getnextb(reg) GETBIT; adc reg,reg
#define jnextb0 GETBIT; bcc
#define jnextb1 GETBIT; bcs
ucl_nrv2b_decompress_32: .globl ucl_nrv2b_decompress_32 @ ARM mode
.type ucl_nrv2b_decompress_32, %function
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst) */
adr r12,1+go_thumb_n2b @ load pc-relative address
bx r12 @ enter THUMB mode
.code 16 @ THUMB mode
go_thumb_n2b:
add r1,len,src @ r1= eof_src;
push {r1,r2,r3, r4,r5,r6,r7, lr}
mov bits,#1; neg off,bits @ off= -1 initial condition
lsl bits,#31 @ 1<<31: refill next time
mov wrnk,#0xd
lsl wrnk,#8 @ 0xd00
adr g1b,get1b @ load pc-relative address
b top_n2b
eof_n2b:
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
sub src,r1 @ 0 if actual src length equals expected length
sub dst,r3 @ actual dst length
str dst,[r4]
pop {r4,r5,r6,r7, pc} @ return
lit_n2b:
ldrb tmp,[src]; add src,#1
strb tmp,[dst]; add dst,#1
top_n2b:
jnextb1 lit_n2b
mov len,#1 @ the msb
getoff_n2b: @ ss11 len= [2..)
getnextb(len)
jnextb0 getoff_n2b
sub tmp,len,#3 @ set Carry
mov len,#0 @ Carry unaffected
blo offprev_n2b @ ss11 returned 2
lsl tmp,#8
ldrb off,[src]; add src,#1 @ low 8 bits
orr off,tmp
mvn off,off; beq eof_n2b @ off= ~off
offprev_n2b: @ In: 0==len
getnextb(len); getnextb(len); bne plus1_n2b @ two bits; 1,2,3 ==> 2,3,4
mov len,#1 @ the msb
getlen_n2b: @ ss11 len= [2..)
getnextb(len)
jnextb0 getlen_n2b
add len,#2 @ [2..) ==> [4..);
plus1_n2b:
add len,#1 @ 1,2,3 ==> 2,3,4; [4..) ==> [5..)
/* 'cmn': add the inputs, set condition codes, discard the sum */
cmn off,wrnk; bcs near_n2b @ within M2_MAX_OFFSET
add len,#1 @ too far away, so minimum match length is 3
near_n2b:
ldrb tmp,[dst] @ force cacheline allocate
copy_n2b:
ldrb tmp,[dst,off]
strb tmp,[dst]; add dst,#1
sub len,#1; bne copy_n2b
b top_n2b
.code 32 @ ARM mode
get1b: @ Out: Carry= next_bit
adds bits,bits,bits @ shift up, set Carry
bxne lr @ return if reload is not needed
/* In: Carry set (unchanged until final adcs) */
ldrb bits,[src],#1
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #1*8
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #2*8
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #3*8
adcs bits,bits,bits @ Carry= next_bit; set bit0 flag from CarryIn
bx lr
.size ucl_nrv2b_decompress_32, .-ucl_nrv2b_decompress_32
/*
vi:ts=8:et:nowrap
*/
+124
View File
@@ -0,0 +1,124 @@
/* arm_nrv2b_d8.S -- ARM decompressor for NRV2B
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-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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#define src r0
#define len r1
#define dst r2
#define tmp r3
#define bits r4
#define off r5
/* r6 UNUSED */
#define wrnk r7 /* 0xd00 M2_MAX_OFFSET before "wrinkle" */
/* r12 ("ip") is assumed to be a scratch register. */
#define GETBIT add bits,bits; mov lr,pc; beq get1_n2b
#define getnextb(reg) GETBIT; adc reg,reg
#define jnextb0 GETBIT; bcc
#define jnextb1 GETBIT; bcs
ucl_nrv2b_decompress_8: .globl ucl_nrv2b_decompress_8 @ ARM mode
.type ucl_nrv2b_decompress_8, %function
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst) */
adr r12,1+go_thumb_n2b @ load pc-relative address
bx r12 @ enter THUMB mode
.code 16 @ THUMB mode
.thumb_func
go_thumb_n2b: .globl go_thumb_n2b
add r1,len,src @ r1= eof_src;
push {r1,r2,r3, r4,r5,r6,r7, lr}
mov bits,#1; neg off,bits @ off= -1 initial condition
lsl bits,#31 @ 1<<31: refill next time
mov wrnk,#0xd
lsl wrnk,#8 @ 0xd00
b top_n2b
eof_n2b:
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
sub src,r1 @ 0 if actual src length equals expected length
sub dst,r3 @ actual dst length
str dst,[r4]
pop {r4,r5,r6,r7 /*,pc*/}
pop {r1}; bx r1 @ "pop {,pc}" fails return to ARM mode on ARMv4T
get1_n2b:
ldrb bits,[src] @ zero-extend next byte
adc bits,bits @ double and insert CarryIn as low bit
add src,#1
lsl bits,#24 @ move to top byte, and set CarryOut from old bit 8
mov pc,lr
lit_n2b:
ldrb tmp,[src]; add src,#1
strb tmp,[dst]; add dst,#1
top_n2b:
jnextb1 lit_n2b
mov len,#1 @ the msb
getoff_n2b: @ ss11 len= [2..)
getnextb(len)
jnextb0 getoff_n2b
sub tmp,len,#3 @ set Carry
mov len,#0 @ Carry unaffected
blo offprev_n2b @ ss11 returned 2
lsl tmp,#8
ldrb off,[src]; add src,#1 @ low 8 bits
orr off,tmp
mvn off,off; beq eof_n2b @ off= ~off
offprev_n2b: @ In: 0==len
getnextb(len); getnextb(len); bne plus1_n2b @ two bits; 1,2,3 ==> 2,3,4
mov len,#1 @ the msb
getlen_n2b: @ ss11 len= [2..)
getnextb(len)
jnextb0 getlen_n2b
add len,#2 @ [2..) ==> [4..);
plus1_n2b:
add len,#1 @ 1,2,3 ==> 2,3,4; [4..) ==> [5..)
/* 'cmn': add the inputs, set condition codes, discard the sum */
cmn off,wrnk; bcs near_n2b @ within M2_MAX_OFFSET
add len,#1 @ too far away, so minimum match length is 3
near_n2b:
ldrb tmp,[dst] @ force cacheline allocate
copy_n2b:
ldrb tmp,[dst,off]
strb tmp,[dst]; add dst,#1
sub len,#1; bne copy_n2b
b top_n2b
.size ucl_nrv2b_decompress_8, .-ucl_nrv2b_decompress_8
/*
vi:ts=8:et:nowrap
*/
+138
View File
@@ -0,0 +1,138 @@
/* arm_nrv2e_d32.S -- ARM decompressor for NRV2E
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-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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#define src r0
#define len r1 /* overlaps 'cnt' */
#define dst r2
#define tmp r3
#define bits r4
#define off r5
#define g32 r6
#define wrnk r7 /* 0x500 M2_MAX_OFFSET before "wrinkle" */
#define cnt r1 /* overlaps 'len' while reading an offset */
#define GETBIT \
add bits,bits; beq 1f; 0: \
.subsection 1; \
1: blx g32; b 0b; \
.subsection 0
#define getnextb(reg) GETBIT; adc reg,reg
#define jnextb0 GETBIT; bcc
#define jnextb1 GETBIT; bcs
ucl_nrv2e_decompress_32: .globl ucl_nrv2e_decompress_32 @ ARM mode
.type ucl_nrv2e_decompress_32, %function
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst) */
adr r12,1+thumb_nrv2e_d32; bx r12 @ enter THUMB mode
.code 16 @ THUMB mode
thumb_nrv2e_d32:
add r1,len,src @ r1= eof_src;
push {r1,r2,r3, r4,r5,r6,r7, lr}
mov bits,#1; neg off,bits @ off= -1 initial condition
lsl bits,#31 @ 1<<31; refill next time
mov wrnk,#5
lsl wrnk,#8 @ 0x500
adr g32,get32 @ load pc-relative address
b top_n2e
eof_n2e:
pop {r1,r3,r4} @ r1= eof_src; r3= orig_dst; r4= plen_dst
sub src,r1 @ 0 if actual src length equals expected length
sub dst,r3 @ actual dst length
str dst,[r4]
pop {r4,r5,r6,r7, pc} @ return
lit_n2e:
ldrb tmp,[src]; add src,#1
strb tmp,[dst]; add dst,#1
top_n2e:
jnextb1 lit_n2e
mov cnt,#1; b getoff_n2e
off_n2e:
sub cnt,#1
getnextb(cnt)
getoff_n2e:
getnextb(cnt)
jnextb0 off_n2e
sub tmp,cnt,#3 @ set Carry
mov len,#0 @ Carry unaffected
blo offprev_n2e @ cnt was 2; tests Carry only
lsl tmp,#8
ldrb off,[src]; add src,#1 @ low 7+1 bits
orr off,tmp
mvn off,off; beq eof_n2e @ off= ~off
asr off,#1; bcs lenlast_n2e
b lenmore_n2e
offprev_n2e:
jnextb1 lenlast_n2e
lenmore_n2e:
mov len,#1
jnextb1 lenlast_n2e
len_n2e:
getnextb(len)
jnextb0 len_n2e
add len,#6-2
b gotlen_n2e
lenlast_n2e:
getnextb(len) @ 0,1,2,3
add len,#2
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
cmn off,wrnk; bcs near_n2e @ within M2_MAX_OFFSET
add len,#1 @ too far away, so minimum match length is 3
near_n2e:
ldrb tmp,[dst] @ force cacheline allocate
copy_n2e:
ldrb tmp,[dst,off]
strb tmp,[dst]; add dst,#1
sub len,#1; bne copy_n2e
b top_n2e
.code 32 @ ARM mode for ease of Carry manipulation
get32: @ In: Carry set (unchanged until final adcs)
ldrb bits,[src],#1
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #1*8
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #2*8
ldrb tmp, [src],#1; orr bits,bits,tmp,lsl #3*8
adcs bits,bits,bits @ Set Carry out
bx lr
.size ucl_nrv2e_decompress_32, .-ucl_nrv2e_decompress_32
/*
vi:ts=8:et:nowrap
*/
+182
View File
@@ -0,0 +1,182 @@
/* arm_nrv2e_d8.S -- ARM decompressor for NRV2E
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-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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#define SAFE 0 /* 1 for src+dst bounds checking: cost 40 bytes */
#define src r0
#define len r1 /* overlaps 'cnt' */
#define dst r2
#define tmp r3
#define bits r4
#define off r5
#define wrnk r6 /* 0x500 M2_MAX_OFFSET before "wrinkle" */
#define srclim r7
#if 1==SAFE /*{*/
#define dstlim r12
#endif /*}*/
#define cnt r1 /* overlaps 'len' while reading an offset */
#if 1==SAFE /*{*/
#define CHECK_SRC cmp src,srclim; bhs bad_src_n2e
#define CHECK_DST cmp dst,dstlim; bhs bad_dst_n2e
#else /*}{*/
#define CHECK_SRC /*empty*/
#define CHECK_DST /*empty*/
#endif /*}*/
#if 0 /*{ DEBUG only: check newly-decompressed against original dst */
#define CHECK_BYTE \
push {wrnk}; \
ldrb wrnk,[dst]; \
cmp wrnk,tmp; beq 0f; bkpt; \
0: pop {wrnk}
#else /*}{*/
#define CHECK_BYTE /*empty*/
#endif /*}*/
/* "mov lr,pc; bxx ..." implements conditional subroutine call */
#define GETBIT add bits,bits; mov lr,pc; beq get1_n2e
#define getnextb(reg) GETBIT; adc reg,reg
#define jnextb0 GETBIT; bcc
#define jnextb1 GETBIT; bcs
ucl_nrv2e_decompress_8: .globl ucl_nrv2e_decompress_8 @ ARM mode
.type ucl_nrv2e_decompress_8, %function
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst)
Actual decompressed length is stored through plen_dst.
For SAFE mode: at call, *plen_dst must be allowed length of output buffer.
*/
adr r12,1+thumb_nrv2e_d8; bx r12 @ enter THUMB mode
.code 16 @ THUMB mode
.globl thumb_nrv2e_d8
.thumb_func
thumb_nrv2e_d8:
push {r2,r3, r4,r5,r6,r7, lr}
#define sp_DST0 0 /* stack offset of original dst */
add srclim,len,src @ srclim= eof_src;
#if 1==SAFE /*{*/
ldr tmp,[r3] @ len_dst
add tmp,dst
mov dstlim,tmp
#endif /*}*/
mov bits,#1; neg off,bits @ off= -1 initial condition
lsl bits,#31 @ 1<<31; refill next time
mov wrnk,#5
lsl wrnk,#8 @ 0x500 @ nrv2e M2_MAX_OFFSET
b top_n2e
#if 1==SAFE /*{*/
bad_dst_n2e: # return value will be 2
add src,srclim,#1
bad_src_n2e: # return value will be 1
add src,#1
#endif /*}*/
eof_n2e:
pop {r3,r4} @ r3= orig_dst; r4= plen_dst
sub src,srclim @ 0 if actual src length equals expected length
sub dst,r3 @ actual dst length
str dst,[r4]
pop {r4,r5,r6,r7 /*,pc*/}
pop {r1}; bx r1 @ "pop {,pc}" fails return to ARM mode on ARMv4T
get1_n2e: @ In: Carry set [from adding 0x80000000 (1<<31) to itself]
ldrb bits,[src] @ zero-extend next byte
adc bits,bits @ double and insert CarryIn as low bit
CHECK_SRC
add src,#1
lsl bits,#24 @ move to top byte, and set CarryOut from old bit 8
mov pc,lr @ return, stay in current (THUMB) mode
lit_n2e:
CHECK_SRC; ldrb tmp,[src]; add src,#1
CHECK_BYTE
CHECK_DST; strb tmp,[dst]; add dst,#1
top_n2e:
jnextb1 lit_n2e
mov cnt,#1; b getoff_n2e
off_n2e:
sub cnt,#1
getnextb(cnt)
getoff_n2e:
getnextb(cnt)
jnextb0 off_n2e
sub tmp,cnt,#3 @ set Carry
mov len,#0 @ Carry unaffected
blo offprev_n2e @ cnt was 2; tests Carry only
lsl tmp,#8
CHECK_SRC; ldrb off,[src]; add src,#1 @ low 7+1 bits
orr off,tmp
mvn off,off; beq eof_n2e @ off= ~off
asr off,#1; bcs lenlast_n2e
b lenmore_n2e
offprev_n2e:
jnextb1 lenlast_n2e
lenmore_n2e:
mov len,#1
jnextb1 lenlast_n2e
len_n2e:
getnextb(len)
jnextb0 len_n2e
add len,#6-2
b gotlen_n2e
lenlast_n2e:
getnextb(len) @ 0,1,2,3
add len,#2
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
cmn wrnk,off; bcs near_n2e @ within M2_MAX_OFFSET
add len,#1 @ too far away, so minimum match length is 3
near_n2e:
#if 1==SAFE /*{*/
ldr tmp,[sp,#sp_DST0]
sub tmp,dst
sub tmp,off; bhi bad_dst_n2e @ reaching back too far
add tmp,dst,cnt
cmp tmp,dstlim; bhi bad_dst_n2e @ too much output
#endif /*}*/
ldrb tmp,[dst] @ force cacheline allocate
copy_n2e:
ldrb tmp,[dst,off]
CHECK_BYTE
strb tmp,[dst]; add dst,#1
sub len,#1; bne copy_n2e
b top_n2e
.size ucl_nrv2e_decompress_8, .-ucl_nrv2e_decompress_8
/*
vi:ts=8:et:nowrap
*/
+181
View File
@@ -0,0 +1,181 @@
/* armv4_n2e_d8.S -- ARM decompressor for NRV2E
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-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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#define SAFE 0 /* 1 for src+dst bounds checking: cost 76 bytes */
#define src r0
#define len r1 /* overlaps 'cnt' */
#define dst r2
#define tmp r3
#define bits r4
#define off r5
/* r6 UNUSED in ARM code unless DEBUG mode */
#define srclim r7
#if 1==SAFE /*{*/
#define dstlim r12
#endif /*}*/
#define cnt r1 /* overlaps 'len' while reading an offset */
/* macros reduce "noise" when comparing this ARM code to corresponding THUMB code */
#define PUSH stmdb sp!,
#define POP ldmia sp!,
#define ADD2( dst,src) add dst,dst,src
#define ADD2S(dst,src) adds dst,dst,src
#define ADC2( dst,src) adc dst,dst,src
#define ADC2S(dst,src) adcs dst,dst,src
#define SUB2( dst,src) sub dst,dst,src
#define SUB2S(dst,src) subs dst,dst,src
#define LDRB3(reg,psrc,incr) ldrb reg,psrc,incr
#define STRB3(reg,pdst,incr) strb reg,pdst,incr
#if 1==SAFE /*{*/
#define CHECK_SRC cmp srclim,src; bls bad_src_n2e /* Out: 1==Carry for get8_n2e */
#define CHECK_DST cmp dst,dstlim; bhs bad_dst_n2e
#else /*}{*/
#define CHECK_SRC /*empty*/
#define CHECK_DST /*empty*/
#endif /*}*/
#if 0 /*{ DEBUG only: check newly-decompressed against original dst */
#define CHECK_BYTE \
ldrb r6,[dst]; \
cmp r6,tmp; beq 0f; bkpt; 0:
#else /*}{*/
#define CHECK_BYTE /*empty*/
#endif /*}*/
#define GETBIT ADD2S(bits,bits); bleq get8_n2e
#define getnextb(reg) GETBIT; ADC2(reg,reg) /* Out: condition code not changed */
#define jnextb0 GETBIT; bcc
#define jnextb1 GETBIT; bcs
ucl_nrv2e_decompress_8: .globl ucl_nrv2e_decompress_8 @ ARM mode
.type ucl_nrv2e_decompress_8, %function
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst)
Actual decompressed length is stored through plen_dst.
For SAFE mode: at call, *plen_dst must be allowed length of output buffer.
*/
PUSH {r2,r3, r4,r5,r6,r7, lr}
#define sp_DST0 0 /* stack offset of original dst */
add srclim,len,src @ srclim= eof_src;
#if 1==SAFE /*{*/
ldr tmp,[r3] @ len_dst
add dstlim,tmp,dst
#endif /*}*/
mvn off,#~-1 @ off= -1 initial condition
mov bits,#1<<31 @ refill next time
b top_n2e
#if 1==SAFE /*{*/
bad_dst_n2e: # return value will be 2
bkpt
add src,srclim,#1
bad_src_n2e: # return value will be 1
ADD2(src,#1)
#endif /*}*/
eof_n2e:
POP {r3,r4} @ r3= orig_dst; r4= plen_dst
SUB2(src,srclim) @ 0 if actual src length equals expected length
SUB2(dst,r3) @ actual dst length
str dst,[r4]
POP {r4,r5,r6,r7 ,pc}
get8_n2e: @ In: Carry set [from adding 0x80000000 (1<<31) to itself]
CHECK_SRC; LDRB3(bits,[src],#1) @ zero-extend next byte
adc bits,bits,bits @ double and insert CarryIn as low bit
movs bits,bits,lsl #24 @ move to top byte, and set CarryOut from old bit 8
mov pc,lr
lit_n2e:
CHECK_SRC; LDRB3(tmp,[src],#1)
CHECK_BYTE
CHECK_DST; STRB3(tmp,[dst],#1)
top_n2e:
jnextb1 lit_n2e
mov cnt,#1; b getoff_n2e
off_n2e:
SUB2(cnt,#1)
getnextb(cnt)
getoff_n2e:
getnextb(cnt)
jnextb0 off_n2e
subs tmp,cnt,#3 @ set Carry
mov len,#0 @ Carry unaffected
blo offprev_n2e @ cnt was 2; tests Carry only
CHECK_SRC; LDRB3(off,[src],#1) @ low 7+1 bits
orr off,off,tmp,lsl #8
mvns off,off; beq eof_n2e @ off= ~off
movs off,off,asr #1; bcs lenlast_n2e
b lenmore_n2e
offprev_n2e:
jnextb1 lenlast_n2e
lenmore_n2e:
mov len,#1
jnextb1 lenlast_n2e
len_n2e:
getnextb(len)
jnextb0 len_n2e
ADD2(len,#6-2)
b gotlen_n2e
lenlast_n2e:
getnextb(len) @ 0,1,2,3
ADD2(len,#2)
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
cmn off,#5<<8; bcs near_n2e @ within M2_MAX_OFFSET
ADD2(len,#1) @ too far away, so minimum match length is 3
near_n2e:
#if 1==SAFE /*{*/
ldr tmp,[sp,#sp_DST0]
SUB2( tmp,dst)
SUB2S(tmp,off); bhi bad_dst_n2e @ reaching back too far
add tmp,dst,cnt
cmp tmp,dstlim; bhi bad_dst_n2e @ too much output
#endif /*}*/
ldrb tmp,[dst] @ force cacheline allocate
copy_n2e:
ldrb tmp,[dst,off]
CHECK_BYTE
STRB3(tmp,[dst],#1)
SUB2S(len,#1); bne copy_n2e
b top_n2e
.size ucl_nrv2e_decompress_8, .-ucl_nrv2e_decompress_8
/*
vi:ts=8:et:nowrap
*/
+120
View File
@@ -0,0 +1,120 @@
/* fold_elf64amd.S -- linkage to C code to process Elf binary
*
* This file is part of the UPX executable compressor.
*
* Copyright (C) 2000-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>
*/
#include "amd_regs.h"
PAGE_SHIFT= 12
PAGE_MASK= 0xffffffffffffffff<<PAGE_SHIFT
sz_b_info= 12
sz_unc= 0
sz_cpr= 4
sz_l_info= 12
sz_p_info= 12
OVERHEAD=2048
MAX_ELF_HDR=1024
/* 64-bit mode only! */
__NR_read= 0
__NR_open= 2
__NR_close= 3
__NR_mmap= 9
__NR_mprotect= 10
__NR_munmap= 11
__NR_brk= 12
__NR_exit= 60
/* In:
cld
%rbp= &decompress
%rsp= &{LENX,ADRX,LENU,ADRU,JMPU,argc,argv...,0,env...,0,auxv...,0...,strings}
*/
fold_begin:
call L90 # push &f_unfilter
#include "amd_bxx.S"
L90:
lea (1+5+1)*8(%rsp),%rsi # &argv[0]
0:
lodsq; testq %rax,%rax; jnz 0b # %rsi= &env;
0:
lodsq; testq %rax,%rax; jnz 0b # %rsi= &Elf64_auxv
pop %arg6 # &amdbxx: f_unfilter
movq %rsi,%arg4 # &Elf64_auxv
pop %arg2 # LENX
pop %arg1 # ADRX
subq $ OVERHEAD,%rsp
movq %rsp,%arg3 # &ELf64_Ehdr temporary space
movq %rbp,%arg5 # &decompress: f_expand
call upx_main # Out: %rax= entry
/* entry= upx_main(b_info *arg1, total_size arg2, Elf64_Ehdr *arg3,
Elf32_Auxv_t *arg4, f_decompr arg5, f_unfilter arg6 )
*/
addq $OVERHEAD,%rsp
pop %arg2 # LENU
pop %arg1 # ADRU
pop %rcx # JMPU
push %rax # &entry
push $ __NR_munmap; pop %rax
jmp *%rcx # goto: syscall; ret
munmap: .globl munmap
movb $ __NR_munmap,%al; jmp sysgo
mprotect: .globl mprotect
movb $ __NR_mprotect,%al; jmp sysgo
brk: .globl brk
movb $ __NR_brk,%al; jmp sysgo
mmap: .globl mmap
movb $ __NR_mmap,%al
sysarg4:
movq %arg4,%sys4
sysgo: # NOTE: kernel demands 4th arg in %sys4, NOT %arg4
movzbl %al,%eax
syscall
cmpq $ PAGE_MASK,%rax; jc no_fail
orq $~0,%rax # failure; IGNORE errno
no_fail:
ret
read: .globl read
movb $ __NR_read,%al; jmp sysgo
open: .globl open
movb $ __NR_open,%al; jmp sysgo
close: .globl close
movb $ __NR_close,%al; jmp sysgo
exit: .globl exit
movb $ __NR_exit,%al; jmp sysgo
# vi:ts=8:et:nowrap
+158
View File
@@ -0,0 +1,158 @@
/* fold_elf64amd.h -- created from fold_elf64amd.bin, 1964 (0x7ac) bytes
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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#define LINUX_ELF64AMD_FOLD_SIZE 1964
#define LINUX_ELF64AMD_FOLD_ADLER32 0xbcebb18a
#define LINUX_ELF64AMD_FOLD_CRC32 0x2dba754c
unsigned char linux_elf64amd_fold[1964] = {
127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */
2, 0, 62, 0, 1, 0, 0, 0,188, 0, 16, 0, 0, 0, 0, 0, /* 0x 10 */
64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 20 */
0, 0, 0, 0, 64, 0, 56, 0, 2, 0, 0, 0, 0, 0, 0, 0, /* 0x 30 */
1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 40 */
0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, /* 0x 50 */
172, 6, 0, 0, 0, 0, 0, 0,172, 6, 0, 0, 0, 0, 0, 0, /* 0x 60 */
0, 0, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, /* 0x 70 */
172, 6, 0, 0, 0, 0, 0, 0,172, 6, 16, 0, 0, 0, 0, 0, /* 0x 80 */
172, 6, 16, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, /* 0x 90 */
4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, /* 0x a0 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,232, 80, 0, 0, /* 0x b0 */
0,131,249, 73,117, 74, 72,137,241, 72,137,254,235, 44,138, 7, /* 0x c0 */
72,131,199, 1, 60,128,114, 10, 60,143,119, 6,128,127,254, 15, /* 0x d0 */
116, 6, 44,232, 60, 1,119, 35, 56, 23,117, 31,139, 7, 37, 0, /* 0x e0 */
255,255,255, 15,200, 41,248, 1,240,171, 72,131,233, 4,138, 7, /* 0x f0 */
72,131,199, 1, 72,255,201,117,217,235, 5, 72,255,201,117,190, /* 0x 100 */
195, 72,141,116, 36, 56, 72,173, 72,133,192,117,249, 72,173, 72, /* 0x 110 */
133,192,117,249, 65, 89, 72,137,241, 94, 95, 72,129,236, 0, 8, /* 0x 120 */
0, 0, 72,137,226, 73,137,232,232, 77, 4, 0, 0, 72,129,196, /* 0x 130 */
0, 8, 0, 0, 94, 95, 89, 80,106, 11, 88,255,225,176, 11,235, /* 0x 140 */
13,176, 10,235, 9,176, 12,235, 5,176, 9, 73,137,202, 15,182, /* 0x 150 */
192, 15, 5, 72, 61, 0,240,255,255,114, 4, 72,131,200,255,195, /* 0x 160 */
176, 0,235,234,176, 2,235,230,176, 3,235,226,176, 60,235,222, /* 0x 170 */
81, 72, 57, 23, 76,139, 71, 8, 72,141, 74,255,115, 10,191,127, /* 0x 180 */
0, 0, 0,232,228,255,255,255, 72,131,249,255,116, 17, 65, 15, /* 0x 190 */
182, 0, 72,255,201, 73,255,192,136, 6, 72,255,198,235,233, 72, /* 0x 1a0 */
1, 87, 8, 72, 41, 23, 88,195, 65, 85, 73,137,213, 65, 84, 73, /* 0x 1b0 */
137,204, 85, 72,137,253, 83, 72,137,243, 72,131,236, 40, 72,131, /* 0x 1c0 */
62, 0, 15,132,223, 0, 0, 0, 72,141,116, 36, 16,186, 12, 0, /* 0x 1d0 */
0, 0, 72,137,239,232,150,255,255,255,139, 84, 36, 16,139,116, /* 0x 1e0 */
36, 20,133,210,117, 21,129,254, 85, 80, 88, 33,117, 17, 72,131, /* 0x 1f0 */
125, 0, 0, 15,132,174, 0, 0, 0,235, 4,133,246,117, 10,191, /* 0x 200 */
127, 0, 0, 0,232, 99,255,255,255, 57,214,119,242,137,208, 72, /* 0x 210 */
59, 3,119,235, 57,214, 72,139, 67, 8,115,101, 68, 15,182, 68, /* 0x 220 */
36, 24, 72,139,125, 8, 72,141, 76, 36, 12, 72,137,194, 65,255, /* 0x 230 */
213,133,192,117,202,139,116, 36, 12, 59,116, 36, 16,117,192, 15, /* 0x 240 */
182, 76, 36, 25,132,201, 15,149,194, 49,192, 77,133,228, 15,149, /* 0x 250 */
192,133,194,116, 30,129,254, 0, 2, 0, 0,119, 7,137,240, 72, /* 0x 260 */
57, 3,117, 15, 15,182, 84, 36, 26, 15,182,201, 72,139,123, 8, /* 0x 270 */
65,255,212,139, 68, 36, 20, 72, 1, 69, 8, 72, 41, 69, 0,235, /* 0x 280 */
13,137,242, 72,137,239, 72,137,198,232,226,254,255,255,139, 84, /* 0x 290 */
36, 16, 72,139, 3, 72, 1, 83, 8, 72, 41,208, 72,133,192, 72, /* 0x 2a0 */
137, 3,233, 27,255,255,255, 72,131,196, 40, 91, 93, 65, 92, 65, /* 0x 2b0 */
93,195, 72,133,255, 73,137,208,116, 41, 72,139, 7,137,241, 72, /* 0x 2c0 */
57,200,116, 17, 72,255,200, 15,148,194, 49,192,133,246, 15,149, /* 0x 2d0 */
192,133,194,116, 8, 72,137, 15, 76,137, 71, 8,195, 72,131,199, /* 0x 2e0 */
16,235,215,195, 65, 87,184, 0, 0, 0, 0, 73,137,255, 65, 86, /* 0x 2f0 */
73,137,254, 65, 85, 65, 84, 85, 83, 72,131,236, 88, 76, 3,119, /* 0x 300 */
32,102,131,127, 16, 3, 72,137,116, 36, 48, 15,183,119, 56, 72, /* 0x 310 */
137, 76, 36, 32,185, 16, 0, 0, 0,137, 84, 36, 44, 76,137, 68, /* 0x 320 */
36, 24, 76,137, 76, 36, 16, 15, 68,200, 76,137,242, 73,131,205, /* 0x 330 */
255, 49,237, 69, 49,228,131,193, 34,255,206,120, 38,131, 58, 1, /* 0x 340 */
117, 27, 72,139, 66, 16, 76, 57,232,115, 7, 76,139, 98, 32, 73, /* 0x 350 */
137,197, 72, 3, 66, 40, 72, 57,197, 72, 15, 66,232, 72,131,194, /* 0x 360 */
56,235,214, 76,137,232, 73,129,229, 0,240,255,255, 69, 49,201, /* 0x 370 */
76, 41,237, 37,255, 15, 0, 0, 69, 49,192, 72,129,197,255, 15, /* 0x 380 */
0, 0, 77,141,164, 4,255, 15, 0, 0,186, 7, 0, 0, 0, 72, /* 0x 390 */
129,229, 0,240,255,255, 76,137,239, 72,137,238, 73,129,228, 0, /* 0x 3a0 */
240,255,255,232,161,253,255,255, 72,137,195, 72,141, 4, 40, 76, /* 0x 3b0 */
41,229, 74,141, 60, 35, 72,137,238, 76, 41,235, 72,137, 68, 36, /* 0x 3c0 */
56,232,119,253,255,255,102, 65,131,127, 56, 0, 72,137, 92, 36, /* 0x 3d0 */
8,199, 68, 36, 4, 0, 0, 0, 0, 15,132,100, 1, 0, 0, 72, /* 0x 3e0 */
131,124, 36, 48, 0,116, 35, 65,131, 62, 6,117, 29, 72,139, 84, /* 0x 3f0 */
36, 8, 73, 3, 86, 16,190, 3, 0, 0, 0, 72,139,124, 36, 32, /* 0x 400 */
232,173,254,255,255,233, 34, 1, 0, 0, 65,131, 62, 1, 15,133, /* 0x 410 */
24, 1, 0, 0, 72,139,124, 36, 8, 73, 3,126, 16,186, 3, 0, /* 0x 420 */
0, 0, 65,139, 78, 4,199, 4, 36, 64, 98, 81,115, 73,139, 70, /* 0x 430 */
32, 77,139, 78, 8, 68,139, 68, 36, 44,131,225, 7, 72,137,253, /* 0x 440 */
72,137,251,129,229,255, 15, 0, 0,193,225, 2,211, 44, 36, 72, /* 0x 450 */
41,235,131, 36, 36, 7, 73,137,253, 77, 3,110, 40, 72,131,124, /* 0x 460 */
36, 48, 1, 76,141, 36, 40, 72,137,124, 36, 72, 72,137,223, 76, /* 0x 470 */
137,230, 72,137, 68, 36, 64, 25,201, 73, 41,233,131,225,224,131, /* 0x 480 */
193, 50,232,194,252,255,255, 72, 57,195,117,105, 72,131,124, 36, /* 0x 490 */
48, 0,116, 25, 72,139, 76, 36, 16, 72,139, 84, 36, 24, 72,141, /* 0x 4a0 */
116, 36, 64, 72,139,124, 36, 48,232,251,252,255,255, 72,137,233, /* 0x 4b0 */
76,137,229, 49,192, 72,247,221, 72,137,223,252,129,229,255, 15, /* 0x 4c0 */
0, 0, 72,131,124, 36, 48, 0,243,170, 74,141, 60, 35, 72,137, /* 0x 4d0 */
233,243,170,116, 14, 73,131,126, 8, 0,117, 7,199, 67, 12, 15, /* 0x 4e0 */
5,195,144,139, 20, 36, 76,137,230, 72,137,223,232, 80,252,255, /* 0x 4f0 */
255,133,192,116, 10,191,127, 0, 0, 0,232,109,252,255,255, 73, /* 0x 500 */
141, 4, 44, 72, 1,195, 76, 57,235,115, 33,139, 20, 36, 73, 41, /* 0x 510 */
221, 69, 49,201, 69, 49,192,185, 50, 0, 0, 0, 76,137,238, 72, /* 0x 520 */
137,223,232, 34,252,255,255, 72, 57,195,117,201,255, 68, 36, 4, /* 0x 530 */
65, 15,183, 71, 56, 73,131,198, 56, 57, 68, 36, 4, 15,140,156, /* 0x 540 */
254,255,255, 72,131,124, 36, 48, 0,116, 18,102, 65,131,127, 16, /* 0x 550 */
3,116, 10, 72,139,124, 36, 56,232,232,251,255,255, 73,139, 71, /* 0x 560 */
24, 72, 1, 68, 36, 8, 72,139, 68, 36, 8, 72,131,196, 88, 91, /* 0x 570 */
93, 65, 92, 65, 93, 65, 94, 65, 95,195, 65, 86, 76,141,114, 64, /* 0x 580 */
65, 85, 77,137,205, 65, 84, 77,137,196, 85, 72,137,213, 83, 72, /* 0x 590 */
137,203, 49,201, 72,131,236, 48,139, 7, 72,137, 52, 36, 72,137, /* 0x 5a0 */
116, 36, 16, 72,141,116, 36, 32, 72,137, 84, 36, 40, 72,137,124, /* 0x 5b0 */
36, 8, 76,137,194, 72,137,124, 36, 24, 72,137,231, 72,137, 68, /* 0x 5c0 */
36, 32,232,225,251,255,255, 73,139, 86, 16,190, 3, 0, 0, 0, /* 0x 5d0 */
72,137,223, 72,131,194, 64,232,214,252,255,255, 72, 15,183, 85, /* 0x 5e0 */
56,190, 5, 0, 0, 0, 72,137,223,232,196,252,255,255, 72,139, /* 0x 5f0 */
85, 24,190, 9, 0, 0, 0, 72,137,223,232,179,252,255,255, 72, /* 0x 600 */
141,116, 36, 16, 77,137,233, 77,137,224, 49,210, 72,137,217, 72, /* 0x 610 */
137,239,232,205,252,255,255, 69, 49,237,102,131,125, 56, 0, 73, /* 0x 620 */
137,196,116,104, 65,131, 62, 3,117, 82, 73,139,126, 16, 49,210, /* 0x 630 */
49,246,232, 45,251,255,255,133,192,137,195,120, 23,186, 0, 4, /* 0x 640 */
0, 0, 72,137,238,137,199,232, 20,251,255,255, 72, 61, 0, 4, /* 0x 650 */
0, 0,116, 10,191,127, 0, 0, 0,232, 14,251,255,255, 72,137, /* 0x 660 */
239, 69, 49,201, 69, 49,192, 49,201,137,218, 49,246,232,114,252, /* 0x 670 */
255,255,137,223, 73,137,196,232,236,250,255,255, 15,183, 69, 56, /* 0x 680 */
65,255,197, 73,131,198, 56, 65, 57,197,124,152, 72,131,196, 48, /* 0x 690 */
76,137,224, 91, 93, 65, 92, 65, 93, 65, 94,195, 0, 0, 0, 0, /* 0x 6a0 */
20, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,120, 16, 12, 7, 8, /* 0x 6b0 */
144, 1, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 28, 0, 0, 0, /* 0x 6c0 */
128, 1, 16, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, /* 0x 6d0 */
65, 14, 16, 46, 8, 87, 14, 8, 46, 0, 95, 14, 0, 0, 0, 0, /* 0x 6e0 */
44, 0, 0, 0, 68, 0, 0, 0,184, 1, 16, 0, 0, 0, 0, 0, /* 0x 6f0 */
10, 1, 0, 0, 0, 0, 0, 0, 66, 14, 16,141, 2, 69, 14, 24, /* 0x 700 */
140, 3, 68, 14, 32,134, 4, 68, 14, 40,131, 5, 71, 14, 80, 0, /* 0x 710 */
20, 0, 0, 0,116, 0, 0, 0,194, 2, 16, 0, 0, 0, 0, 0, /* 0x 720 */
50, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0,140, 0, 0, 0, /* 0x 730 */
244, 2, 16, 0, 0, 0, 0, 0,150, 2, 0, 0, 0, 0, 0, 0, /* 0x 740 */
66, 14, 16,143, 2, 74, 14, 24,142, 3, 69, 14, 32, 66, 14, 40, /* 0x 750 */
65, 14, 48, 65, 14, 56, 68, 14,144, 1,131, 7,134, 6,140, 5, /* 0x 760 */
141, 4, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0,204, 0, 0, 0, /* 0x 770 */
138, 5, 16, 0, 0, 0, 0, 0, 34, 1, 0, 0, 0, 0, 0, 0, /* 0x 780 */
66, 14, 16,142, 2, 70, 14, 24,141, 3, 69, 14, 32,140, 4, 68, /* 0x 790 */
14, 40,134, 5, 68, 14, 48,131, 6, 73, 14, 96 /* 0x 7a0 */
};
+35 -15
View File
@@ -35,6 +35,7 @@
%define PAGE_SIZE ( 1<<12) %define PAGE_SIZE ( 1<<12)
%define szElf32_Ehdr 0x34 %define szElf32_Ehdr 0x34
%define szElf32_Phdr 8*4 %define szElf32_Phdr 8*4
%define e_type 16
%define e_entry (16 + 2*2 + 4) %define e_entry (16 + 2*2 + 4)
%define p_memsz 5*4 %define p_memsz 5*4
%define szb_info 12 %define szb_info 12
@@ -54,9 +55,6 @@ fold_begin: ; enter: %ebx= &Elf32_Ehdr of this program
; dword sz_uncompressed, sz_compressed ; dword sz_uncompressed, sz_compressed
; byte compressed_data... ; byte compressed_data...
pop eax ; discard &sz_uncompressed
pop eax ; discard sz_uncompressed
; ld-linux.so.2 depends on AT_PHDR and AT_ENTRY, for instance. ; ld-linux.so.2 depends on AT_PHDR and AT_ENTRY, for instance.
; Move argc,argv,envp down to make room for Elf_auxv table. ; Move argc,argv,envp down to make room for Elf_auxv table.
; Linux kernel 2.4.2 and earlier give only AT_HWCAP and AT_PLATFORM ; Linux kernel 2.4.2 and earlier give only AT_HWCAP and AT_PLATFORM
@@ -75,6 +73,8 @@ fold_begin: ; enter: %ebx= &Elf32_Ehdr of this program
%define AT_PAGESZ 6 %define AT_PAGESZ 6
%define AT_ENTRY 9 %define AT_ENTRY 9
%define ET_DYN 3
sub ecx, ecx sub ecx, ecx
mov edx, (1<<AT_PHDR) | (1<<AT_PHENT) | (1<<AT_PHNUM) | (1<<AT_PAGESZ) | (1<<AT_ENTRY) mov edx, (1<<AT_PHDR) | (1<<AT_PHENT) | (1<<AT_PHNUM) | (1<<AT_PAGESZ) | (1<<AT_ENTRY)
mov esi, esp mov esi, esp
@@ -96,21 +96,34 @@ L50:
%define OVERHEAD 2048 %define OVERHEAD 2048
%define MAX_ELF_HDR 512 %define MAX_ELF_HDR 512
sub esp, dword MAX_ELF_HDR + OVERHEAD ; alloca
mov edx, esp ; %edx= &tmp
push ebx ; save &Elf32_Ehdr of this stub push ebx ; save &Elf32_Ehdr of this stub
sub esp, dword MAX_ELF_HDR + OVERHEAD xor ecx, ecx ; 0
push ecx ; assume not ET_DYN
lea eax, [szElf32_Ehdr + 2*szElf32_Phdr + szl_info + szp_info + ebx] ; 1st &b_info lea eax, [szElf32_Ehdr + 2*szElf32_Phdr + szl_info + szp_info + ebx] ; 1st &b_info
mov esi, [e_entry + ebx] ; beyond compressed data mov esi, [e_entry + ebx] ; beyond compressed data
cmp word [e_type + ebx], byte ET_DYN
jne L53
pop ecx ; is ET_DYN: discard false assumption
add esi, ebx ; relocate e_entry
mov ch, PAGE_SIZE>>8 ; %ecx= PAGE_SIZE
add ebx, [p_memsz + szElf32_Ehdr + ebx]
add ebx, ecx
push ebx ; dynbase
L53:
sub esi, eax ; length of compressed data sub esi, eax ; length of compressed data
mov ebx, [ eax] ; length of uncompressed ELF headers mov ebx, [ eax] ; length of uncompressed ELF headers
mov edx, esp ;
mov ecx, [4+ eax] ; length of compressed ELF headers mov ecx, [4+ eax] ; length of compressed ELF headers
add ecx, byte szb_info add ecx, byte szb_info
pusha ; (AT_table, sz_cpr, f_expand, &tmp_ehdr, {sz_unc, &tmp}, {sz_cpr, &b1st_info} ) pusha ; (AT_table, sz_cpr, f_expand, &tmp_ehdr, {sz_unc, &tmp}, {sz_cpr, &b1st_info} )
inc edi ; swap with above 'pusha' to inhibit auxv_up for PT_INTERP inc edi ; swap with above 'pusha' to inhibit auxv_up for PT_INTERP
EXTERN upx_main EXTERN upx_main
call upx_main ; returns entry address call upx_main ; returns entry address
add esp, dword 8*4 + MAX_ELF_HDR + OVERHEAD ; remove 8 params, temp space add esp, byte 8*4 ; remove 8 params from pusha
pop ecx ; dynbase
pop ebx ; &Elf32_Ehdr of this stub pop ebx ; &Elf32_Ehdr of this stub
add esp, dword MAX_ELF_HDR + OVERHEAD ; un-alloca
push eax ; save entry address push eax ; save entry address
dec edi ; auxv table dec edi ; auxv table
@@ -127,9 +140,9 @@ L60:
; See bug libc/1165 at http://bugs.gnu.org/cgi-bin/gnatsweb.pl ; See bug libc/1165 at http://bugs.gnu.org/cgi-bin/gnatsweb.pl
; Found 1999-06-16 glibc-2.1.1 ; Found 1999-06-16 glibc-2.1.1
; Fixed 1999-12-29 glibc-2.1.2 ; Fixed 1999-12-29 glibc-2.1.2
;
%define N_STKCLR (0x100 + MAX_ELF_HDR + OVERHEAD)/4 ;%define N_STKCLR (0x100 + MAX_ELF_HDR + OVERHEAD)/4
%define N_STKCLR 8 ;%define N_STKCLR 8
; lea edi, [esp - 4*N_STKCLR] ; lea edi, [esp - 4*N_STKCLR]
; pusha ; values will be zeroed ; pusha ; values will be zeroed
; mov esi,esp ; save ; mov esi,esp ; save
@@ -138,7 +151,6 @@ L60:
; ; xor eax,eax ; eax already 0 from L60 ; ; xor eax,eax ; eax already 0 from L60
; rep stosd ; rep stosd
; mov esp,esi ; restore ; mov esp,esi ; restore
; xor ecx, ecx ; ecx already 0 from "rep stosd"
push eax push eax
push eax push eax
@@ -148,13 +160,9 @@ L60:
push eax push eax
push eax push eax
push eax ; 32 bytes of zeroes now on stack push eax ; 32 bytes of zeroes now on stack
push eax
pop ecx ; 0
sub ecx, ebx ; length to unmap
mov al, __NR_munmap ; eax was 0 from L60 mov al, __NR_munmap ; eax was 0 from L60
mov ch, PAGE_SIZE>>8 ; 0x1000
add ecx, [p_memsz + szElf32_Ehdr + ebx] ; length to unmap
mov bh, 0 ; from 0x401000 to 0x400000
jmp [edi] ; unmap ourselves via escape hatch, then goto entry jmp [edi] ; unmap ourselves via escape hatch, then goto entry
; called twice: ; called twice:
@@ -201,5 +209,17 @@ L32:
pop edi ; &auxtab pop edi ; &auxtab
ret ret
%define __NR_mmap 90
global mmap
mmap:
push ebx
lea ebx, [2*4 + esp]
push byte __NR_mmap
pop eax
int 0x80
pop ebx
ret
; vi:ts=8:et:nowrap ; vi:ts=8:et:nowrap
+109 -105
View File
@@ -1,9 +1,10 @@
/* fold_elf86.h -- created from fold_elf86.bin, 1624 (0x658) bytes /* fold_elf86.h -- created from fold_elf86.bin, 1651 (0x673) bytes
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -26,110 +27,113 @@
*/ */
#define LINUX_I386ELF_FOLD_ADLER32 0x9b9ac310 #define LINUX_I386ELF_FOLD_SIZE 1651
#define LINUX_I386ELF_FOLD_CRC32 0xc9a476f9 #define LINUX_I386ELF_FOLD_ADLER32 0x3a4ad069
#define LINUX_I386ELF_FOLD_CRC32 0xd4e0324c
unsigned char linux_i386elf_fold[1624] = { unsigned char linux_i386elf_fold[1651] = {
127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */ 127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */
2, 0, 3, 0, 1, 0, 0, 0,128, 16, 0, 1, 52, 0, 0, 0, /* 0x 10 */ 2, 0, 3, 0, 1, 0, 0, 0,128, 0,192, 0, 52, 0, 0, 0, /* 0x 10 */
0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 0, 0, /* 0x 20 */ 0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 0, 0, /* 0x 20 */
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 1, /* 0x 30 */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,192, 0, /* 0x 30 */
0, 16, 0, 1, 88, 6, 0, 0, 88, 6, 0, 0, 5, 0, 0, 0, /* 0x 40 */ 0, 0,192, 0,115, 6, 0, 0,116, 6, 0, 0, 5, 0, 0, 0, /* 0x 40 */
0, 16, 0, 0, 1, 0, 0, 0, 88, 6, 0, 0, 88, 22, 0, 1, /* 0x 50 */ 0, 16, 0, 0, 1, 0, 0, 0,115, 6, 0, 0,116, 6,192, 0, /* 0x 50 */
88, 22, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */ 116, 6,192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */
0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */ 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */
88, 88, 41,201,186,120, 2, 0, 0,137,230,137,231,232, 94, 0, /* 0x 80 */ 41,201,186,120, 2, 0, 0,137,230,137,231,232,112, 0, 0, 0, /* 0x 80 */
0, 0,137,230,209,234, 25,192, 41,193,141, 36,196,133,210,117, /* 0x 90 */ 137,230,209,234, 25,192, 41,193,141, 36,196,133,210,117,243,137, /* 0x 90 */
243,137,231,232, 72, 0, 0, 0, 83,129,236, 0, 10, 0, 0,141, /* 0x a0 */ 231,232, 90, 0, 0, 0,129,236, 0, 10, 0, 0,137,226, 83, 49, /* 0x a0 */
131,140, 0, 0, 0,139,115, 24, 41,198,139, 24,137,226,139, 72, /* 0x b0 */ 201, 81,141,131,140, 0, 0, 0,139,115, 24,102,131,123, 16, 3, /* 0x b0 */
4,131,193, 12, 96, 71,232,149, 4, 0, 0,129,196, 32, 10, 0, /* 0x c0 */ 117, 11, 89, 1,222,181, 16, 3, 91, 72, 1,203, 83, 41,198,139, /* 0x c0 */
0, 91, 80, 79, 41,192, 60,175,175,117,252, 80, 80, 80, 80, 80, /* 0x d0 */ 24,139, 72, 4,131,193, 12, 96, 71,232,144, 4, 0, 0,131,196, /* 0x d0 */
80, 80, 80, 80, 89,176, 91,181, 16, 3, 75, 72,183, 0,255, 39, /* 0x e0 */ 32, 89, 91,129,196, 0, 10, 0, 0, 80, 79, 41,192, 60,175,175, /* 0x e0 */
173,171,133,192,117,250,173,171,133,192,117,250, 87,173,171,131, /* 0x f0 */ 117,252, 80, 80, 80, 80, 80, 80, 80, 80, 41,217,176, 91,255, 39, /* 0x f0 */
248, 32,115, 3, 15,179,194,133,192,173,171,117,240,131,239, 8, /* 0x 100 */ 173,171,133,192,117,250,173,171,133,192,117,250, 87,173,171,131, /* 0x 100 */
1,201, 64,243,171, 72,171,171, 95,195, 0, 0, 85, 87,137,207, /* 0x 110 */ 248, 32,115, 3, 15,179,194,133,192,173,171,117,240,131,239, 8, /* 0x 110 */
86,137,198, 83, 57, 8,139,104, 4,115, 8,106,127, 91,106, 1, /* 0x 120 */ 1,201, 64,243,171, 72,171,171, 95,195, 83,141, 92, 36, 8,106, /* 0x 120 */
88,205,128,133,255,116, 11,137,249,138, 69, 0, 69,136, 2, 66, /* 0x 130 */ 90, 88,205,128, 91,195, 0, 0, 87, 86,137,206, 83,137,195, 57, /* 0x 130 */
226,247, 91, 1,126, 4, 41, 62, 94, 95, 93,195, 83,141, 92, 36, /* 0x 140 */ 8,139,120, 4,115, 10,106,127, 91,106, 1, 88,205,128,235,254, /* 0x 140 */
8,106, 90, 88,205,128, 91,195, 85,137,229, 87, 86,137,199, 83, /* 0x 150 */ 133,201,116, 8,138, 7, 71,136, 2, 66,226,248, 1,115, 4, 41, /* 0x 150 */
137,214,131,236, 24,139, 69, 8,131, 58, 0,137, 69,220, 15,132, /* 0x 160 */ 51, 91, 94, 95,195, 85,137,229, 87, 86,137,198, 83,137,211,131, /* 0x 160 */
189, 0, 0, 0,141, 85,228,137,248,185, 12, 0, 0, 0,232,153, /* 0x 170 */ 236, 24,139, 69, 8,139,125, 12,137, 69,220,131, 58, 0, 15,132, /* 0x 170 */
255,255,255,131,125,228, 0,139, 69,232,117, 18, 61, 85, 80, 88, /* 0x 180 */ 184, 0, 0, 0,141, 85,228,185, 12, 0, 0, 0,137,240,232,165, /* 0x 180 */
33,117, 15,131, 63, 0, 15,132,149, 0, 0, 0,235, 4,133,192, /* 0x 190 */ 255,255,255,139, 69,228,139, 77,232,133,192,117, 19,129,249, 85, /* 0x 190 */
117, 8,106,127, 91,106, 1, 88,205,128,139, 77,232,139, 69,228, /* 0x 1a0 */ 80, 88, 33,117, 15,131, 62, 0, 15,132,142, 0, 0, 0,235, 4, /* 0x 1a0 */
57,193,119,238, 59, 6,119,234, 57,193,115, 88, 15,182, 69,236, /* 0x 1b0 */ 133,201,117, 10,106,127, 91,106, 1, 88,205,128,235,254, 57,193, /* 0x 1b0 */
80,141, 69,224, 80,255,118, 4, 81,255,119, 4,255, 85,220,131, /* 0x 1c0 */ 119,242, 59, 3,119,238, 57,193,115, 85, 15,182, 69,236, 80,141, /* 0x 1c0 */
196, 20,133,192,117,204,139, 85,224, 59, 85,228,117,196,138, 69, /* 0x 1d0 */ 69,224, 80,255,115, 4, 81,255,118, 4,255, 85,220,131,196, 20, /* 0x 1d0 */
237,132,192,116, 37,131,125, 12, 0,116, 31,129,250, 0, 2, 0, /* 0x 1e0 */ 133,192,117,208,139, 85,224, 59, 85,228,117,200,138, 69,237,132, /* 0x 1e0 */
0,119, 4, 57, 22,117, 19, 15,182,192, 80, 15,182, 69,238, 80, /* 0x 1f0 */ 192,116, 34,133,255,116, 30,129,250, 0, 2, 0, 0,119, 4, 57, /* 0x 1f0 */
82,255,118, 4,255, 85, 12,131,196, 16,139, 69,232, 1, 71, 4, /* 0x 200 */ 19,117, 18, 15,182,192, 80, 15,182, 69,238, 80, 82,255,115, 4, /* 0x 200 */
41, 7,235, 10,139, 86, 4,137,248,232,254,254,255,255,139, 85, /* 0x 210 */ 255,215,131,196, 16,139, 69,232, 1, 70, 4, 41, 6,235, 10,139, /* 0x 210 */
228,139, 6, 1, 86, 4, 41,208,133,192,137, 6,233, 61,255,255, /* 0x 220 */ 83, 4,137,240,232, 15,255,255,255,139, 85,228,139, 3, 1, 83, /* 0x 220 */
255,141,101,244, 91, 94, 95,201,195,133,210,137,209,116, 6,198, /* 0x 230 */ 4, 41,208,133,192,137, 3,233, 66,255,255,255,141,101,244, 91, /* 0x 230 */
0, 0, 64,226,250,195,133,192, 83,137,211,116, 29,168, 1,117, /* 0x 240 */ 94, 95,201,195,133,210,137,209,116, 6,198, 0, 0, 64,226,250, /* 0x 240 */
25,139, 16, 57,218,116, 7, 74,117, 11,133,219,116, 7,137, 24, /* 0x 250 */ 195,133,192, 83,137,211,116, 29,168, 1,117, 25,139, 16, 57,218, /* 0x 250 */
137, 72, 4,235, 5,131,192, 8,235,231, 91,195, 85,137,229, 87, /* 0x 260 */ 116, 7, 74,117, 11,133,219,116, 7,137, 24,137, 72, 4,235, 5, /* 0x 260 */
86, 83,131,236, 72,137, 85,224,139, 77,224,137, 69,228,139, 93, /* 0x 270 */ 131,192, 8,235,231, 91,195, 85,137,229, 87, 86, 83,131,236, 72, /* 0x 270 */
224,199, 69,208, 0, 0, 0, 0, 3, 73, 28,139, 69, 8,139, 85, /* 0x 280 */ 137, 85,224,139, 77,224,137, 69,228,139, 93,224,199, 69,204, 0, /* 0x 280 */
12,137, 69,220, 49,192,102,131,123, 16, 3,137, 85,216,137, 77, /* 0x 290 */ 0, 0, 0, 3, 73, 28,139, 69, 8,139, 85, 12,137, 69,220, 49, /* 0x 290 */
212,137,202, 15,183, 75, 44, 15,149,192,131,206,255,193,224, 4, /* 0x 2a0 */ 192,102,131,123, 16, 2,137, 85,216,137, 77,212,137,202, 15,183, /* 0x 2a0 */
137,207,131,192, 34, 49,219, 79,137, 69,188,120, 34,131, 58, 1, /* 0x 2b0 */ 75, 44, 15,148,192,131,206,255,193,224, 4,137,207,131,192, 34, /* 0x 2b0 */
117, 24,139, 66, 8, 57,240,115, 8,139,122, 16,137,198,137,125, /* 0x 2c0 */ 49,219, 79,137, 69,184,120, 34,131, 58, 1,117, 24,139, 66, 8, /* 0x 2c0 */
208, 3, 66, 20, 57,195,115, 2,137,195,131,194, 32,226,222,137, /* 0x 2d0 */ 57,240,115, 8,139,122, 16,137,198,137,125,204, 3, 66, 20, 57, /* 0x 2d0 */
247,106, 0,129,231, 0,240,255,255,106, 0, 41,251,255,117,188, /* 0x 2e0 */ 195,115, 2,137,195,131,194, 32,226,222,137,247,106, 0,129,231, /* 0x 2e0 */
129,195,255, 15, 0, 0,106, 7,129,227, 0,240,255,255,139, 85, /* 0x 2f0 */ 0,240,255,255,106, 0, 41,251,255,117,184,129,195,255, 15, 0, /* 0x 2f0 */
208, 83,137,240, 37,255, 15, 0, 0, 87,141,180, 2,255, 15, 0, /* 0x 300 */ 0,106, 7,129,227, 0,240,255,255,139, 85,204, 83,137,240, 37, /* 0x 300 */
0,232, 54,254,255,255,137,194,131,196, 24, 1,218,129,230, 0, /* 0x 310 */ 255, 15, 0, 0, 87,137, 93,172,141,180, 2,255, 15, 0, 0,232, /* 0x 310 */
240,255,255,137, 85,240,137,194, 41,243, 1,242,137,217,137, 69, /* 0x 320 */ 6,254,255,255,137,194,131,196, 24, 1,218,129,230, 0,240,255, /* 0x 320 */
176,137,211,106, 91, 88,205,128,139,117,176,139, 69,224, 41,254, /* 0x 330 */ 255,137, 85,240,137,194, 41,243, 1,242,137,217,137, 69,176,137, /* 0x 330 */
49,255,102,131,120, 44, 0, 15,132,218, 1, 0, 0,139, 85,212, /* 0x 340 */ 211,106, 91, 88,205,128,139, 69,176,199, 69,196, 0, 0, 0, 0, /* 0x 340 */
139, 2,131,248, 6,117, 23,139, 74, 8,186, 3, 0, 0, 0,139, /* 0x 350 */ 139, 85,224, 41,248,102,131,122, 44, 0,137, 69,208, 15,132,195, /* 0x 350 */
69,216, 1,241,232,221,254,255,255,233,165, 1, 0, 0, 72, 15, /* 0x 360 */ 1, 0, 0,139, 77,212,139, 1,131,248, 6,117, 27,139, 93,212, /* 0x 360 */
133,158, 1, 0, 0,139, 93,212,199, 69,200, 64, 98, 81,115,139, /* 0x 370 */ 186, 3, 0, 0, 0,139, 77,208, 3, 75, 8,139, 69,216,232,206, /* 0x 370 */
75, 24,139, 67, 8,131,225, 7,139, 83, 16,193,225, 2,137, 69, /* 0x 380 */ 254,255,255,233,135, 1, 0, 0, 72, 15,133,128, 1, 0, 0,139, /* 0x 380 */
236,211,109,200,137,193, 3, 75, 20,137,195,129,227,255, 15, 0, /* 0x 390 */ 125,212,199, 69,192, 64, 98, 81,115,139, 69,208,139, 79, 24, 3, /* 0x 390 */
0,137, 85,232, 1,218, 41,216,137, 85,196,139, 85,212, 1,240, /* 0x 3a0 */ 71, 8,131,225, 7,139, 87, 16,193,225, 2,211,109,192,137,195, /* 0x 3a0 */
1,241,137, 69,184,139, 66, 4,131,101,200, 7, 41,216,131,125, /* 0x 3b0 */ 139, 79, 20,137,199,129,231,255, 15, 0, 0,137, 85,232,141, 52, /* 0x 3b0 */
220, 1, 80,255,117,228, 25,192,137, 93,192,131,224,224,137, 77, /* 0x 3c0 */ 58,139, 85,212, 1,193,137, 69,236,139, 66, 4, 41,251,131,101, /* 0x 3c0 */
180,131,192, 50,131,125,220, 0, 80,139, 69,196,106, 3,116, 3, /* 0x 3d0 */ 192, 7, 41,248,131,125,220, 1, 80,255,117,228, 25,192,137, 77, /* 0x 3d0 */
131,192, 3, 80,255,117,184,232, 96,253,255,255,131,196, 24, 57, /* 0x 3e0 */ 188,131,224,224,131,192, 50,131,125,220, 0, 80,137,240,106, 3, /* 0x 3e0 */
69,184, 15,133,193, 0, 0, 0,131,125,220, 0,116, 34,139, 77, /* 0x 3f0 */ 116, 3,141, 70, 3, 80, 83,232, 46,253,255,255,131,196, 24, 57, /* 0x 3f0 */
212, 49,192,246, 65, 24, 1,116, 6,139, 69,228,131,192, 2, 80, /* 0x 400 */ 195, 15,133,186, 0, 0, 0,131,125,220, 0,116, 34,139, 77,212, /* 0x 400 */
139, 69,220,255,117,228,141, 85,232,232, 58,253,255,255, 88, 90, /* 0x 410 */ 49,192,246, 65, 24, 1,116, 6,139, 69,228,131,192, 2, 80,139, /* 0x 410 */
139, 85,192,139, 69,184,232, 14,254,255,255,139, 93,196,139, 69, /* 0x 420 */ 69,220,255,117,228,141, 85,232,232, 56,253,255,255, 88, 90,137, /* 0x 420 */
184,247,219, 3, 69,196,129,227,255, 15, 0, 0,137,218,137, 93, /* 0x 430 */ 250,137,247,137,216,247,223,232, 8,254,255,255,129,231,255, 15, /* 0x 430 */
192,232,243,253,255,255,131,125,220, 0,116, 91,139, 69,212,131, /* 0x 440 */ 0, 0,141, 4, 51,137,250,137,125,180,232,245,253,255,255,131, /* 0x 440 */
56, 1,117, 83,246, 64, 24, 1,116, 77,139, 93,212,137,194,139, /* 0x 450 */ 125,220, 0,116, 94,139, 69,212,131, 56, 1,117, 86,246, 64, 24, /* 0x 450 */
64, 20, 59, 67, 16,139, 82, 8,141, 12, 16,117, 14,137,200,247, /* 0x 460 */ 1,116, 80,139, 80, 20,139,120, 8,141, 12, 58, 3, 77,208, 59, /* 0x 460 */
216, 37,255, 15, 0, 0,131,248, 3,119, 12,139, 69,212,141, 74, /* 0x 470 */ 80, 16,117, 14,137,200,247,216, 37,255, 15, 0, 0,131,248, 3, /* 0x 470 */
12,131,120, 4, 0,117, 15,139, 1, 61,205,128, 97,195,116, 6, /* 0x 480 */ 119, 17,139, 85,212,107, 69,208, 52,131,122, 4, 0,141, 76, 7, /* 0x 480 */
199, 1,205,128, 97,195,133,201,116, 13,139, 69,216, 49,210,131, /* 0x 490 */ 12,117, 15,139, 1, 61,205,128, 97,195,116, 6,199, 1,205,128, /* 0x 490 */
224,254,232,159,253,255,255,139, 93,184,139, 77,196,139, 85,200, /* 0x 4a0 */ 97,195,133,201,116, 13,139, 69,216, 49,210,131,224,254,232,158, /* 0x 4a0 */
106,125, 88,205,128,133,192,116, 8,106,127, 91,106, 1, 88,205, /* 0x 4b0 */ 253,255,255,137,241,139, 85,192,106,125, 88,205,128,133,192,116, /* 0x 4b0 */
128,139, 69,196, 3, 69,192, 1, 69,184,139, 69,180, 57, 69,184, /* 0x 4c0 */ 10,106,127, 91,106, 1, 88,205,128,235,254,139,125,180,141, 4, /* 0x 4c0 */
115, 31,106, 0, 43, 69,184,106, 0,106, 50,255,117,200, 80,255, /* 0x 4d0 */ 62, 1,195, 59, 93,188,115, 30,106, 0,106, 0,106, 50,255,117, /* 0x 4d0 */
117,184,232,101,252,255,255,131,196, 24, 57, 69,184,116, 36,235, /* 0x 4e0 */ 192, 41, 93,188,255,117,188, 83,232, 61,252,255,255,131,196, 24, /* 0x 4e0 */
200,131,125,220, 0,116, 28,131, 69,196, 3,129,101,196,255, 15, /* 0x 4f0 */ 57,195,116, 27,235,203,131,125,220, 0,116, 19,141, 78, 3,129, /* 0x 4f0 */
0, 0,131,125,196, 3,119, 11,139, 93,184,139, 77,196,106, 91, /* 0x 500 */ 225,255, 15, 0, 0,131,249, 3,119, 5,106, 91, 88,205,128,139, /* 0x 500 */
88,205,128,139, 85,224, 71,131, 69,212, 32, 15,183, 66, 44, 57, /* 0x 510 */ 85,224,255, 69,196, 15,183, 66, 44,131, 69,212, 32, 57, 69,196, /* 0x 510 */
199, 15,140, 38,254,255,255,131,125,220, 0,117, 17,139, 93,228, /* 0x 520 */ 15,140, 61,254,255,255,131,125,220, 0,117, 14,139, 93,228,106, /* 0x 520 */
106, 6, 88,205,128,133,192,116, 23,233,123,255,255,255,139,125, /* 0x 530 */ 6, 88,205,128,133,192,116, 20,235,135,139,125,224,102,131,127, /* 0x 530 */
224,102,131,127, 16, 3,116, 8,139, 93,240,106, 45, 88,205,128, /* 0x 540 */ 16, 3,116, 8,139, 93,240,106, 45, 88,205,128,131,125, 16, 0, /* 0x 540 */
139, 69,224, 3,112, 24,141,101,244, 91,137,240, 94, 95,201,195, /* 0x 550 */ 116, 8,139, 85,208,139, 69, 16,137, 16,139, 77,224,139, 73, 24, /* 0x 550 */
85,137,229, 87, 86, 83, 87, 87,139,125, 20,106, 0,139, 69, 16, /* 0x 560 */ 1, 77,208,139, 69,208,141,101,244, 91, 94, 95,201,195, 85,137, /* 0x 560 */
141, 87, 52,139, 93, 8, 80,139,117, 32,137, 69,240,137, 85,236, /* 0x 570 */ 229, 87, 86, 83,131,236, 12,139,125, 28,106, 0,139, 69, 16,141, /* 0x 570 */
141, 69, 32,141, 85, 24,232,205,251,255,255,139, 69, 12,186, 3, /* 0x 580 */ 87, 52,139,117, 8, 80,139, 93, 32,137, 69,236,137, 85,232,141, /* 0x 580 */
0, 0, 0, 41,117, 36,137, 69, 32,139, 69,236,139, 72, 8,137, /* 0x 590 */ 69, 32,141, 85, 24,232,203,251,255,255,139, 69, 12, 15,183, 79, /* 0x 590 */
216,131,193, 52,232,157,252,255,255, 15,183, 79, 42,137,216,186, /* 0x 5a0 */ 44,186, 5, 0, 0, 0,137, 69, 32,137,240, 41, 93, 36,232,158, /* 0x 5a0 */
4, 0, 0, 0,232,141,252,255,255, 15,183, 79, 44,137,216,186, /* 0x 5b0 */ 252,255,255, 15,183, 79, 42,186, 4, 0, 0, 0,137,240,232,142, /* 0x 5b0 */
5, 0, 0, 0,232,125,252,255,255,139, 79, 24,137,216,186, 9, /* 0x 5c0 */ 252,255,255,139, 93,232,139, 77, 40,186, 3, 0, 0, 0, 3, 75, /* 0x 5c0 */
0, 0, 0,232,110,252,255,255,141, 69, 32, 83,137,250, 80,139, /* 0x 5d0 */ 8,137,240,131,193, 52,232,118,252,255,255,141, 69,240,137,250, /* 0x 5d0 */
69,240,232,133,252,255,255,102,139, 79, 44,131,196, 16, 49,210, /* 0x 5e0 */ 80,141, 69, 32, 86, 80,139, 69,236,232,137,252,255,255,186, 9, /* 0x 5e0 */
102,133,201,137,195,116, 87,139, 69,236,131, 56, 3,117, 67, 49, /* 0x 5f0 */ 0, 0, 0,137,193,137,195,137,240,232, 83,252,255,255,102,139, /* 0x 5f0 */
201,139, 88, 8,137,202,106, 5, 88,205,128,133,192,137,198,120, /* 0x 600 */ 79, 44,131,196, 20, 49,210,102,133,201,116, 93,139, 69,232,131, /* 0x 600 */
20,102,186, 0, 2,137,195,137,249,106, 3, 88,205,128, 61, 0, /* 0x 610 */ 56, 3,117, 73,139, 93,240, 49,201, 3, 88, 8,137,202,106, 5, /* 0x 610 */
2, 0, 0,116, 10,106,127, 91,106, 1, 88,205,128,235,246,106, /* 0x 620 */ 88,205,128,133,192,137,198,120, 20,102,186, 0, 2,137,195,137, /* 0x 620 */
0,137,240,106, 0,137,250,232, 48,252,255,255, 89, 94,137,195, /* 0x 630 */ 249,106, 3, 88,205,128, 61, 0, 2, 0, 0,116, 10,106,127, 91, /* 0x 630 */
235, 12, 66, 15,183,193,131, 69,236, 32, 57,194,124,169,141,101, /* 0x 640 */ 106, 1, 88,205,128,235,254,106, 0,137,250,106, 0,137,240,106, /* 0x 640 */
244,137,216, 91, 94, 95,201,195 /* 0x 650 */ 0,232, 33,252,255,255,131,196, 12,137,195,235, 12, 66, 15,183, /* 0x 650 */
193,131, 69,232, 32, 57,194,124,163,141,101,244,137,216, 91, 94, /* 0x 660 */
95,201,195 /* 0x 670 */
}; };
+97
View File
@@ -0,0 +1,97 @@
#include "ppc_regs.h"
sz_b_info= 12
sz_unc= 0
sz_cpr= 4
sz_l_info= 12
sz_p_info= 12
OVERHEAD= 2048
LINKAREA= 4*4 # SysV C linkage area: (sp, lr); but 16-byte align
/* In:
r31= &decompress; also 8+ (char *)&(offset to {l_info; p_info; b_info})
*/
fold_begin:
call L90
#include "ppc_bxx.S"
/* The SysV convention for argument registers after execve is nice:
a0= argc
a1= argv
a2= envp
a3= auxvp
a4= fini
sp= ~0xf & (-2*4 + (void *)&argc) # 0(sp): old_sp, pc
Instead, Linux gives only
sp= &{argc,argv...,0,env...,0,auxv...,strings} # 16-byte aligned?
We must figure out the rest, particularly auxvp.
*/
zfind:
lwz t0,0(a6); addi a6,a6,4
cmpi cr7,t0,0; bne+ cr7,zfind
ret
L90:
mflr a5 # &ppcbxx: f_unfilter
lwz a6,0(sp) # sp at execve
call zfind # a6= &env
call zfind # a6= &Elf32_auxv
lwz a1,-8(r31) # total size = offset to {l_info; p_info; b_info}
rlwinm r30,a5,0,0,31-12 # r30= &this_page
la a2,-OVERHEAD(sp) # &Elf32_Ehdr temporary space
mr a4,r31 # &decompress: f_expand
subf a0,a1,r31 # &l_info
addi sp,sp,-(LINKAREA+OVERHEAD)
rlwinm r29,a0,0,0,31-12 # r29= &our_Elf32_Ehdr
lwz a3,sz_unc+sz_p_info+sz_l_info(a0) # sz_elf_headers
call upx_main # Out: a0= entry
/* entry= upx_main(l_info *a0, total_size a1, Elf32_Ehdr *a2, sz_ehdr a3,
f_decomp a4, f_unf a5, Elf32_auxv_t *a6)
*/
mr r31,a0 # save &entry
mr a0,r29 # &our_Elf32_Ehdr
subf a1,r29,r30 # size
call munmap # unmap compressed program; /proc/self/exe disappears
mtlr r31 # entry address
lmw r2,4+LINKAREA+OVERHEAD(sp) # restore registers r2 thru r31
lwz r1, LINKAREA+OVERHEAD(sp) # restore r1; deallocate space
ret # enter /lib/ld.so.1
SYS_exit= 1
SYS_fork= 2
SYS_read= 3
SYS_write= 4
SYS_open= 5
SYS_close= 6
SYS_brk= 45
SYS_mmap= 90
SYS_munmap= 91
SYS_mprotect= 125
mmap: .globl mmap
li 0,SYS_mmap
sysgo:
sc
bns+ no_fail # 'bns': branch if No Summary[Overflow]
li a0,-1 # failure; IGNORE errno
no_fail:
ret
exit: .globl exit
li 0,SYS_exit; b sysgo
read: .globl read
li 0,SYS_read; b sysgo
open: .globl open
li 0,SYS_open; b sysgo
close: .globl close
li 0,SYS_close; b sysgo
mprotect: .globl mprotect
li 0,SYS_mprotect; b sysgo
munmap: .globl munmap
li 0,SYS_munmap; b sysgo
brk: .globl brk
li 0,SYS_brk; b sysgo
+181
View File
@@ -0,0 +1,181 @@
/* fold_elfppc32.h -- created from fold_elfppc32.bin, 2324 (0x914) bytes
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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#define LINUX_ELFPPC32_FOLD_SIZE 2324
#define LINUX_ELFPPC32_FOLD_ADLER32 0x0789a535
#define LINUX_ELFPPC32_FOLD_CRC32 0x665028e2
unsigned char linux_elfppc32_fold[2324] = {
127, 69, 76, 70, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */
0, 2, 0, 20, 0, 0, 0, 1, 0, 16, 0,128, 0, 0, 0, 52, /* 0x 10 */
0, 0, 7,252, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 40, /* 0x 20 */
0, 7, 0, 6, 0, 0, 0, 1, 0, 0, 0, 0, 0, 16, 0, 0, /* 0x 30 */
0, 16, 0, 0, 0, 0, 7,196, 0, 0, 7,196, 0, 0, 0, 5, /* 0x 40 */
0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 7,196, 0, 16, 7,196, /* 0x 50 */
0, 16, 7,196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, /* 0x 60 */
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */
72, 0, 0,125, 40, 6, 0,208, 76,130, 0, 32, 84,132,240,191, /* 0x 80 */
77,130, 0, 32, 60, 0, 0, 16,124, 4, 0, 64, 65,128, 0, 8, /* 0x 90 */
124, 4, 3,120, 56,165, 1, 32,124,103, 27,120, 56, 99,255,252, /* 0x a0 */
124,137, 3,166, 72, 0, 0, 28, 84, 75, 2,186,125, 99, 88, 80, /* 0x b0 */
125,107, 58, 20, 81, 98, 1,186,144, 67, 0, 0, 78, 64, 0, 32, /* 0x c0 */
132, 67, 0, 4, 84, 75, 85,190,124, 11, 40, 64, 65,162,255,220, /* 0x d0 */
66, 0,255,240, 78,128, 0, 32,128, 73, 0, 0, 57, 41, 0, 4, /* 0x e0 */
47,130, 0, 0, 64,158,255,244, 78,128, 0, 32,125, 8, 2,166, /* 0x f0 */
129, 33, 0, 0, 75,255,255,229, 75,255,255,225,128,159,255,248, /* 0x 100 */
85, 30, 0, 38, 56,161,248, 0,127,231,251,120,124,100,248, 80, /* 0x 110 */
56, 33,247,240, 84,125, 0, 38,128,195, 0, 24, 72, 0, 5, 73, /* 0x 120 */
124,127, 27,120,127,163,235,120,124,157,240, 80, 72, 0, 0, 81, /* 0x 130 */
127,232, 3,166,184, 65, 8, 20,128, 33, 8, 16, 78,128, 0, 32, /* 0x 140 */
56, 0, 0, 90, 68, 0, 0, 2, 64,163, 0, 8, 56, 96,255,255, /* 0x 150 */
78,128, 0, 32, 56, 0, 0, 1, 75,255,255,236, 56, 0, 0, 3, /* 0x 160 */
75,255,255,228, 56, 0, 0, 5, 75,255,255,220, 56, 0, 0, 6, /* 0x 170 */
75,255,255,212, 56, 0, 0,125, 75,255,255,204, 56, 0, 0, 91, /* 0x 180 */
75,255,255,196, 56, 0, 0, 45, 75,255,255,188,124, 8, 2,166, /* 0x 190 */
148, 33,255,240,144, 1, 0, 20,128, 3, 0, 0,129, 35, 0, 4, /* 0x 1a0 */
127,128, 40, 64, 64,188, 0, 12, 56, 96, 0,127, 75,255,255,169, /* 0x 1b0 */
47,133, 0, 0, 65,158, 0, 28,124,169, 3,166,136, 9, 0, 0, /* 0x 1c0 */
57, 41, 0, 1,152, 4, 0, 0, 56,132, 0, 1, 66, 0,255,240, /* 0x 1d0 */
128, 3, 0, 0,129, 35, 0, 4,124, 5, 0, 80,144, 3, 0, 0, /* 0x 1e0 */
125, 41, 42, 20,128, 1, 0, 20, 56, 33, 0, 16,145, 35, 0, 4, /* 0x 1f0 */
124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166,148, 33,255,192, /* 0x 200 */
191,129, 0, 48,124,159, 35,120,124,126, 27,120,124,188, 43,120, /* 0x 210 */
144, 1, 0, 68,124,221, 51,120,128, 4, 0, 0, 47,128, 0, 0, /* 0x 220 */
65,158, 1, 32, 56,160, 0, 12,127,195,243,120, 56,129, 0, 16, /* 0x 230 */
75,255,255, 93,129, 33, 0, 16,128,161, 0, 20, 47,137, 0, 0, /* 0x 240 */
64,190, 0, 36, 60, 0, 33, 88, 96, 0, 80, 85,127,133, 0, 0, /* 0x 250 */
64,190, 0, 28,128, 30, 0, 0, 47,128, 0, 0, 65,190, 0,228, /* 0x 260 */
72, 0, 0, 12, 47,133, 0, 0, 64,190, 0, 12, 56, 96, 0,127, /* 0x 270 */
75,255,254,229,127, 5, 72, 64, 65,185,255,244,128, 31, 0, 0, /* 0x 280 */
127,137, 0, 64, 65,189,255,232,128, 31, 0, 4, 64,152, 0,132, /* 0x 290 */
124,164, 43,120,128,126, 0, 4,124, 5, 3,120, 56,193, 0, 32, /* 0x 2a0 */
136,225, 0, 24,127,136, 3,166, 78,128, 0, 33, 47,131, 0, 0, /* 0x 2b0 */
64,190,255,188,128,129, 0, 32,128, 1, 0, 16,127,132, 0, 0, /* 0x 2c0 */
64,190,255,172,136,193, 0, 25, 49, 61,255,255,124, 9,233, 16, /* 0x 2d0 */
125, 38, 0,208, 85, 41, 15,254,125, 43, 0, 57, 65,162, 0, 20, /* 0x 2e0 */
128,127, 0, 4,127,168, 3,166,136,161, 0, 26, 78,128, 0, 33, /* 0x 2f0 */
128, 30, 0, 4,129, 97, 0, 20,129, 62, 0, 0,124, 0, 90, 20, /* 0x 300 */
125, 43, 72, 80,144, 30, 0, 4,145, 62, 0, 0, 72, 0, 0, 16, /* 0x 310 */
124, 4, 3,120,127,195,243,120, 75,255,254,117,129, 97, 0, 16, /* 0x 320 */
129, 63, 0, 0,128, 31, 0, 4,125, 43, 72, 80, 47,137, 0, 0, /* 0x 330 */
124, 0, 90, 20,144, 31, 0, 4,145, 63, 0, 0, 75,255,254,228, /* 0x 340 */
128, 1, 0, 68,187,129, 0, 48, 56, 33, 0, 64,124, 8, 3,166, /* 0x 350 */
78,128, 0, 32,124,128, 35,121,124, 9, 3,166, 77,130, 0, 32, /* 0x 360 */
56, 0, 0, 0,152, 3, 0, 0, 56, 99, 0, 1, 66, 0,255,248, /* 0x 370 */
78,128, 0, 32, 44, 3, 0, 0, 77,130, 0, 32, 48, 4,255,255, /* 0x 380 */
125, 96, 33, 16,128, 3, 0, 0,127,128, 32, 0,104, 9, 0, 1, /* 0x 390 */
33, 73, 0, 0,125, 42, 73, 20,125, 42, 88, 57, 65,158, 0, 8, /* 0x 3a0 */
65,162, 0, 16,144,163, 0, 4,144,131, 0, 0, 78,128, 0, 32, /* 0x 3b0 */
56, 99, 0, 8, 75,255,255,208,124, 8, 2,166,148, 33,255,160, /* 0x 3c0 */
125,128, 0, 38,190, 65, 0, 40,124,121, 27,120,124,151, 35,120, /* 0x 3d0 */
144, 1, 0,100,124,181, 43,120,161, 67, 0, 44,124,210, 51,120, /* 0x 3e0 */
160, 3, 0, 16,124,243, 59,120, 53, 74,255,255,129, 35, 0, 28, /* 0x 3f0 */
104, 0, 0, 3,145,129, 0, 36,124, 0, 0,208,127, 99, 74, 20, /* 0x 400 */
84, 3, 46,246,125, 20, 67,120, 56, 99, 8, 34,127,107,219,120, /* 0x 410 */
59,128,255,255, 59,192, 0, 0, 59,224, 0, 0, 65,128, 0, 72, /* 0x 420 */
57, 74, 0, 1,125, 73, 3,166,128, 11, 0, 0, 47,128, 0, 1, /* 0x 430 */
64,190, 0, 44,129, 43, 0, 8,127,137,224, 64, 64,156, 0, 12, /* 0x 440 */
131,235, 0, 16,125, 60, 75,120,128, 11, 0, 20,124, 0, 74, 20, /* 0x 450 */
127,158, 0, 64, 64,156, 0, 8,124, 30, 3,120, 57,107, 0, 32, /* 0x 460 */
66, 0,255,200, 87,128, 5, 62, 87,156, 0, 38,125, 60,240, 80, /* 0x 470 */
127,255, 2, 20, 57, 41, 15,255, 56, 31, 15,255, 85, 62, 0, 38, /* 0x 480 */
84, 31, 0, 38,124,102, 27,120,127,196,243,120, 56,160, 0, 7, /* 0x 490 */
126,167,171,120, 57, 0, 0, 0,127,131,227,120, 75,255,252,165, /* 0x 4a0 */
124,159,240, 80,124, 3,242, 20,124,125, 27,120, 56,160, 0, 0, /* 0x 4b0 */
124, 99,250, 20,144, 1, 0, 8, 75,255,252,189,160, 25, 0, 44, /* 0x 4c0 */
58,192, 0, 0,127, 28,232, 80,127,150, 0, 0, 64,156, 1,116, /* 0x 4d0 */
45,151, 0, 0, 65,142, 0, 40,128, 27, 0, 0, 47,128, 0, 6, /* 0x 4e0 */
64,190, 0, 28,128,187, 0, 8,126, 67,147,120, 56,128, 0, 3, /* 0x 4f0 */
124,165,194, 20, 75,255,254,129, 72, 0, 1, 52,128, 27, 0, 0, /* 0x 500 */
47,128, 0, 1, 64,190, 1, 40,128, 27, 0, 24, 61, 32,115, 81, /* 0x 510 */
129, 91, 0, 8, 97, 41, 98, 64, 84, 0, 22,250,129,123, 0, 20, /* 0x 520 */
125, 41, 4, 48, 85, 94, 5, 62, 48, 23,255,255,124,160,185, 16, /* 0x 530 */
128, 27, 0, 16, 85, 58, 7,126,127,170, 90, 20, 84,165, 8, 60, /* 0x 540 */
127,254, 80, 80,144, 1, 0, 16,127,128,242, 20,145, 65, 0, 20, /* 0x 550 */
127,255,194, 20,127,189,194, 20,124,165,211,120, 65,142, 0, 12, /* 0x 560 */
56,192, 0, 50, 72, 0, 0, 8, 56,192, 0, 18,129, 27, 0, 4, /* 0x 570 */
127,227,251,120,127,132,227,120,126,167,171,120,125, 30, 64, 80, /* 0x 580 */
75,255,251,193,127,159, 24, 0, 64,158, 0,104, 65,174, 0, 24, /* 0x 590 */
126,227,187,120, 56,129, 0, 16,126,101,155,120,126,134,163,120, /* 0x 5a0 */
75,255,252, 89, 87, 64,255,254, 46, 0, 0, 0, 65,178, 0, 16, /* 0x 5b0 */
127,196,243,120,127,227,251,120, 75,255,253,157,124, 28, 0,208, /* 0x 5c0 */
84, 30, 5, 62, 65,178, 0, 16,124,127,226, 20,127,196,243,120, /* 0x 5d0 */
75,255,253,133, 65,174, 0, 36,127,227,251,120,127,132,227,120, /* 0x 5e0 */
127, 69,211,120, 75,255,251,145, 47,131, 0, 0, 65,190, 0, 12, /* 0x 5f0 */
56, 96, 0,127, 75,255,251, 97,124, 28,242, 20,127,255, 2, 20, /* 0x 600 */
127,159,232, 64, 64,188, 0, 40,124,159,232, 80,127, 69,211,120, /* 0x 610 */
127,227,251,120, 56,192, 0, 50, 56,224, 0, 0, 57, 0, 0, 0, /* 0x 620 */
75,255,251, 33,127,159, 24, 0, 64,190,255,200,160, 25, 0, 44, /* 0x 630 */
58,214, 0, 1, 59,123, 0, 32,127,150, 0, 0, 75,255,254,144, /* 0x 640 */
128,121, 0, 24,128, 1, 0,100,129,129, 0, 36,124, 99,194, 20, /* 0x 650 */
124, 8, 3,166,186, 65, 0, 40,125,129,129, 32, 56, 33, 0, 96, /* 0x 660 */
78,128, 0, 32,124, 8, 2,166,148, 33,255,192, 56,132,255,232, /* 0x 670 */
191, 97, 0, 44,144,129, 0, 8,124,191, 43,120,144, 1, 0, 68, /* 0x 680 */
56, 3, 0, 24,144, 1, 0, 12,124,229, 59,120,128, 3, 0, 24, /* 0x 690 */
56,192, 0, 0,200, 1, 0, 8, 56, 97, 0, 8, 56,129, 0, 16, /* 0x 6a0 */
59,223, 0, 52,125, 61, 75,120,124,251, 59,120,144, 1, 0, 16, /* 0x 6b0 */
125, 28, 67,120,216, 1, 0, 24,147,225, 0, 20, 75,255,251, 61, /* 0x 6c0 */
128,190, 0, 8,127,163,235,120, 56,128, 0, 3, 56,165, 0, 52, /* 0x 6d0 */
75,255,252,165,160,191, 0, 44,127,163,235,120, 56,128, 0, 5, /* 0x 6e0 */
75,255,252,149,128,191, 0, 24,127,163,235,120, 56,128, 0, 9, /* 0x 6f0 */
75,255,252,133,127,103,219,120,127,136,227,120,127,227,251,120, /* 0x 700 */
127,166,235,120, 56,129, 0, 24, 56,160, 0, 0, 59, 96, 0, 0, /* 0x 710 */
75,255,252,169,160, 31, 0, 44,124,124, 27,120,127,155, 0, 0, /* 0x 720 */
64,156, 0,124,128, 30, 0, 0, 59,123, 0, 1, 56,128, 0, 0, /* 0x 730 */
56,160, 0, 0, 47,128, 0, 3, 64,190, 0, 88,128,126, 0, 8, /* 0x 740 */
75,255,250, 37,127,228,251,120,124,125, 27,121, 56,160, 2, 0, /* 0x 750 */
65,128, 0, 40, 75,255,250, 9, 56,128, 0, 0, 47,131, 2, 0, /* 0x 760 */
127,165,235,120,127,227,251,120, 56,192, 0, 0, 56,224, 0, 0, /* 0x 770 */
57, 0, 0, 0, 65,190, 0, 12, 56, 96, 0,127, 75,255,249,217, /* 0x 780 */
75,255,252, 57,124,124, 27,120,127,163,235,120, 75,255,249,225, /* 0x 790 */
160, 31, 0, 44, 59,222, 0, 32, 75,255,255,132,128, 1, 0, 68, /* 0x 7a0 */
127,131,227,120,187, 97, 0, 44, 56, 33, 0, 64,124, 8, 3,166, /* 0x 7b0 */
78,128, 0, 32, 0, 46,115,104,115,116,114,116, 97, 98, 0, 46, /* 0x 7c0 */
116,101,120,116, 0, 46, 98,115,115, 0, 46,115,100, 97,116, 97, /* 0x 7d0 */
0, 46,115,100, 97,116, 97, 50, 0, 46,110,111,116,101, 46, 71, /* 0x 7e0 */
78, 85, 45,115,116, 97, 99,107, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 7f0 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 800 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 810 */
0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 1, 0, 0, 0, 6, /* 0x 820 */
0, 16, 0,128, 0, 0, 0,128, 0, 0, 7, 68, 0, 0, 0, 0, /* 0x 830 */
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 17, /* 0x 840 */
0, 0, 0, 8, 0, 0, 0, 3, 0, 16, 7,196, 0, 0, 7,196, /* 0x 850 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0x 860 */
0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 1, 0, 0, 0, 3, /* 0x 870 */
0, 16, 7,196, 0, 0, 7,196, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 880 */
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 29, /* 0x 890 */
0, 0, 0, 1, 0, 0, 0, 2, 0, 16, 7,196, 0, 0, 7,196, /* 0x 8a0 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, /* 0x 8b0 */
0, 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 7, 0, 0, 0, 0, /* 0x 8c0 */
0, 0, 0, 0, 0, 0, 7,196, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 8d0 */
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, /* 0x 8e0 */
0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,196, /* 0x 8f0 */
0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0x 900 */
0, 0, 0, 0 /* 0x 910 */
};
+12
View File
@@ -59,4 +59,16 @@ EXTERN upx_main
call upx_main ; Call the UPX main function call upx_main ; Call the UPX main function
hlt ; Crash if somehow upx_main does return hlt ; Crash if somehow upx_main does return
%define __NR_mmap 90
global mmap
mmap:
push ebx
lea ebx, [2*4 + esp]
push byte __NR_mmap
pop eax
int 0x80
pop ebx
ret
; vi:ts=8:et:nowrap ; vi:ts=8:et:nowrap
+44 -41
View File
@@ -1,9 +1,10 @@
/* fold_exec86.h -- created from fold_exec86.bin, 931 (0x3a3) bytes /* fold_exec86.h -- created from fold_exec86.bin, 947 (0x3b3) bytes
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
All Rights Reserved. All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them UPX and the UCL library are free software; you can redistribute them
@@ -26,26 +27,27 @@
*/ */
#define LINUX_I386EXEC_FOLD_ADLER32 0x598e8b17 #define LINUX_I386EXEC_FOLD_SIZE 947
#define LINUX_I386EXEC_FOLD_CRC32 0xe031336e #define LINUX_I386EXEC_FOLD_ADLER32 0x14ec8f58
#define LINUX_I386EXEC_FOLD_CRC32 0x81e80623
unsigned char linux_i386exec_fold[931] = { unsigned char linux_i386exec_fold[947] = {
127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */ 127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */
2, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, /* 0x 10 */ 2, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, /* 0x 10 */
0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 1, 0, 0, 0, /* 0x 20 */ 0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 1, 0, 0, 0, /* 0x 20 */
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 64, 0, /* 0x 30 */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 64, 0, /* 0x 30 */
0, 16, 64, 0,163, 3, 0, 0,164, 3, 0, 0, 7, 0, 0, 0, /* 0x 40 */ 0, 16, 64, 0,179, 3, 0, 0,180, 3, 0, 0, 7, 0, 0, 0, /* 0x 40 */
0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 50 */ 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 50 */
88, 88, 88,137,225,141, 84,132, 4,139,115, 24,131,195, 96, 41, /* 0x 60 */ 88, 88, 88,137,225,141, 84,132, 4,139,115, 24,131,195, 96, 41, /* 0x 60 */
222,141,125, 2, 96,232,197, 0, 0, 0,244, 0, 83,137,195,139, /* 0x 70 */ 222,141,125, 2, 96,232,197, 0, 0, 0,244, 83,141, 92, 36, 8, /* 0x 70 */
76, 36, 8,136,208,131,224, 31, 60, 25,118, 3,131,232, 43,131, /* 0x 80 */ 106, 90, 88,205,128, 91,195, 0, 83,137,195,139, 76, 36, 8,136, /* 0x 80 */
192, 65, 75,136, 3,137,208,193,232, 5,137,194,226,229, 91,195, /* 0x 90 */ 208,131,224, 31, 60, 25,118, 3,131,232, 43,131,192, 65, 75,136, /* 0x 90 */
83,141, 92, 36, 8,106, 90, 88,205,128, 91,195, 85, 49,201,137, /* 0x a0 */ 3,137,208,193,232, 5,137,194,226,229, 91,195, 85, 49,201,137, /* 0x a0 */
229, 87, 86,137,202, 83,131,236, 32,139, 93, 8,106, 5, 88,205, /* 0x b0 */ 229, 87, 86,137,202, 83,131,236, 32,139, 93, 8,106, 5, 88,205, /* 0x b0 */
128,133,192,137,199,120,108,199, 69,212, 47,112,114,111,199, 69, /* 0x c0 */ 128,133,192,137,199,120,108,199, 69,212, 47,112,114,111,199, 69, /* 0x c0 */
216, 99, 47, 0, 0,106, 20, 88,205,128,141, 85,218,141,117,212, /* 0x d0 */ 216, 99, 47, 0, 0,106, 20, 88,205,128,141, 85,218,141,117,212, /* 0x d0 */
232,155, 2, 0, 0,141, 80, 4,137,243,199, 0, 47,102,100, 47, /* 0x e0 */ 232,171, 2, 0, 0,141, 80, 4,137,243,199, 0, 47,102,100, 47, /* 0x e0 */
137,248,232,137, 2, 0, 0,186, 1, 0, 0, 0,106, 33, 88,106, /* 0x f0 */ 137,248,232,153, 2, 0, 0,186, 1, 0, 0, 0,106, 33, 88,106, /* 0x f0 */
5, 89,205,128, 61, 85, 80, 88, 50,117, 33,139, 93, 8,106, 10, /* 0x 100 */ 5, 89,205,128, 61, 85, 80, 88, 50,117, 33,139, 93, 8,106, 10, /* 0x 100 */
88,205,128,185, 2, 0, 0, 0,137,251,106, 55, 88,205,128,137, /* 0x 110 */ 88,205,128,185, 2, 0, 0, 0,137,251,106, 55, 88,205,128,137, /* 0x 110 */
243,139, 77, 12,139, 85, 16,106, 11, 88,205,128,137,251,106, 6, /* 0x 120 */ 243,139, 77, 12,139, 85, 16,106, 11, 88,205,128,137,251,106, 6, /* 0x 120 */
@@ -53,40 +55,41 @@ unsigned char linux_i386exec_fold[931] = {
137,229, 87, 86, 83,131,236,112,141,125,228,139, 77, 24,139, 69, /* 0x 140 */ 137,229, 87, 86, 83,131,236,112,141,125,228,139, 77, 24,139, 69, /* 0x 140 */
16,139, 85, 12,137,203,129,227, 0,240,255,255,137, 69,156,137, /* 0x 150 */ 16,139, 85, 12,137,203,129,227, 0,240,255,255,137, 69,156,137, /* 0x 150 */
85,148,137,206,137, 77,152,137, 93,144,165,165,165,131,109,148, /* 0x 160 */ 85,148,137,206,137, 77,152,137, 93,144,165,165,165,131,109,148, /* 0x 160 */
12,129,125,228, 85, 80, 88, 51,137,117,152, 15,133, 95, 1, 0, /* 0x 170 */ 12,129,125,228, 85, 80, 88, 51,137,117,152, 15,133,100, 1, 0, /* 0x 170 */
0,199, 69,196, 47,116,109,112,199, 69,200, 47,117,112,120,141, /* 0x 180 */ 0,199, 69,196, 47,116,109,112,199, 69,200, 47,117,112,120,141, /* 0x 180 */
77,215,106, 20, 88,205,128,137,194,106, 4,137,200,141,117,211, /* 0x 190 */ 77,215,106, 20, 88,205,128,137,194,106, 4,137,200,141,117,211, /* 0x 190 */
232,215,254,255,255,141, 93,172,137,199,198, 69,215, 0, 51,125, /* 0x 1a0 */ 232,227,254,255,255,141, 93,172,137,199,198, 69,215, 0, 51,125, /* 0x 1a0 */
228, 49,201,106, 78, 88,205,128, 51,125,172,139, 85,176,137,240, /* 0x 1b0 */ 228, 49,201,106, 78, 88,205,128, 51,125,172,139, 85,176,137,240, /* 0x 1b0 */
199, 4, 36, 7, 0, 0, 0,193,226, 12,141, 93,196, 49,250,232, /* 0x 1c0 */ 199, 4, 36, 7, 0, 0, 0,193,226, 12,141, 93,196, 49,250,232, /* 0x 1c0 */
168,254,255,255, 88,106, 10, 88,205,128,131,248,254,116, 8,133, /* 0x 1d0 */ 180,254,255,255, 88,106, 10, 88,205,128,131,248,254,116, 8,133, /* 0x 1d0 */
192, 15,133,249, 0, 0, 0,185,194, 0, 0, 0,186,192, 1, 0, /* 0x 1e0 */ 192, 15,133,254, 0, 0, 0,185,194, 0, 0, 0,186,192, 1, 0, /* 0x 1e0 */
0,141, 93,196,106, 5, 88,205,128,137, 69,136,139, 77,232,137, /* 0x 1f0 */ 0,141, 93,196,106, 5, 88,205,128,137, 69,136,139, 77,232,137, /* 0x 1f0 */
195,106, 93, 88,205,128,133,192, 15,133,202, 0, 0, 0,106, 0, /* 0x 200 */ 195,106, 93, 88,205,128,133,192, 15,133,207, 0, 0, 0,106, 0, /* 0x 200 */
83,106, 1,106, 3, 81,106, 0,232,131,254,255,255,131,196, 24, /* 0x 210 */ 83,106, 1,106, 3, 81,106, 0,232, 94,254,255,255,131,196, 24, /* 0x 210 */
61, 0,240,255,255,137, 69,132, 15,135,170, 0, 0, 0,139, 69, /* 0x 220 */ 61, 0,240,255,255,137, 69,132, 15,135,175, 0, 0, 0,139, 69, /* 0x 220 */
232,106, 0,106, 0, 5,255, 15, 0, 0,106, 50, 37, 0,240,255, /* 0x 230 */ 232,106, 0,106, 0, 5,255, 15, 0, 0,106, 50, 37, 0,240,255, /* 0x 230 */
255,106, 3, 3, 69,132,104, 0, 16, 0, 0, 80,232, 79,254,255, /* 0x 240 */ 255,106, 3, 3, 69,132,104, 0, 16, 0, 0, 80,232, 42,254,255, /* 0x 240 */
255,131,196, 24,141,125,180,139,117,152,165,165,165,139, 77,180, /* 0x 250 */ 255,131,196, 24,141,125,180,139,117,152,165,165,165,139, 77,180, /* 0x 250 */
131,109,148, 12,133,201,137,117,152,139, 85,184,117, 20,129,250, /* 0x 260 */ 131,109,148, 12,133,201,137,117,152,139, 85,184,117, 20,129,250, /* 0x 260 */
85, 80, 88, 33,117, 98,131,125,232, 0, 15,132,136, 0, 0, 0, /* 0x 270 */ 85, 80, 88, 33,117,103,131,125,232, 0, 15,132,141, 0, 0, 0, /* 0x 270 */
235, 86, 57,202,119, 82, 59, 85,236,119, 77, 57,202,115, 31,141, /* 0x 280 */ 235, 91, 57,202,119, 87, 59, 85,236,119, 82, 57,202,115, 36, 15, /* 0x 280 */
69,168, 80,255,117,132, 82,255,117,152,255, 85,156,131,196, 16, /* 0x 290 */ 182, 69,188, 80,141, 69,168, 80,255,117,132, 82,255,117,152,255, /* 0x 290 */
133,192,117, 52,139, 69,180, 57, 69,168,117, 44,235, 8,139,125, /* 0x 2a0 */ 85,156,131,196, 20,133,192,117, 52,139, 69,180, 57, 69,168,117, /* 0x 2a0 */
132,139,117,152,243,164,139, 77,180,139, 93,132,106, 91, 88,205, /* 0x 2b0 */ 44,235, 8,139,125,132,139,117,152,243,164,139, 77,180,139, 93, /* 0x 2b0 */
128,139, 69,184, 1,203, 41, 69,148, 41, 77,232, 1, 69,152,131, /* 0x 2c0 */ 132,106, 91, 88,205,128,139, 69,184, 1,203, 41, 69,148, 41, 77, /* 0x 2c0 */
125,148, 0,137, 93,132,121, 18,141, 93,196,106, 10, 88,205,128, /* 0x 2d0 */ 232, 1, 69,152,131,125,148, 0,137, 93,132,121, 18,141, 93,196, /* 0x 2d0 */
106,127, 91,106, 1, 88,205,128,235,246,139, 77,152,139, 93,144, /* 0x 2e0 */ 106, 10, 88,205,128,106,127, 91,106, 1, 88,205,128,235,254,139, /* 0x 2e0 */
129,225, 0,240,255,255, 43, 77,144,106, 91, 88,205,128, 1,203, /* 0x 2f0 */ 77,152,139, 93,144,129,225, 0,240,255,255, 43, 77,144,106, 91, /* 0x 2f0 */
137, 93,144,233, 76,255,255,255,139, 93,136,106, 6, 88,205,128, /* 0x 300 */ 88,205,128, 1,203,137, 93,144,233, 71,255,255,255,139, 93,136, /* 0x 300 */
133,192,117,196,255,117, 28,255,117, 32,141,117,196, 86,232,137, /* 0x 310 */ 106, 6, 88,205,128,133,192,117,196,255,117, 28,255,117, 32,141, /* 0x 310 */
253,255,255,133,192,120,177,106, 2, 88,205,128,133,192,117, 49, /* 0x 320 */ 117,196, 86,232,132,253,255,255,133,192,120,177,106, 2, 88,205, /* 0x 320 */
106, 2, 88,205,128,133,192,137,193,117, 31,199, 69,160, 85, 80, /* 0x 330 */ 128,133,192,117, 51,106, 2, 88,205,128,133,192,137,193,117, 31, /* 0x 330 */
88, 52,184,162, 0, 0, 0,141, 93,160,199, 69,164, 0, 0, 0, /* 0x 340 */ 199, 69,160, 85, 80, 88, 52,184,162, 0, 0, 0,141, 93,160,199, /* 0x 340 */
0,205,128,137,243,106, 10, 88,205,128, 49,219,106, 1, 88,205, /* 0x 350 */ 69,164, 0, 0, 0, 0,205,128,137,243,106, 10, 88,205,128, 49, /* 0x 350 */
128, 49,201,131,203,255,137,202,106, 7, 88,205,128,141, 93,196, /* 0x 360 */ 219,106, 1, 88,205,128,235,254, 49,201,131,203,255,137,202,106, /* 0x 360 */
139, 77, 32,139, 85, 28,106, 11, 88,205,128,233, 88,255,255,255, /* 0x 370 */ 7, 88,205,128,141, 93,196,139, 77, 32,139, 85, 28,106, 11, 88, /* 0x 370 */
87,137,215,106, 10,252, 89,232, 5, 0, 0, 0,136, 39,151, 95, /* 0x 380 */ 205,128,233, 86,255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 380 */
195,153,247,241, 82,133,192,116, 5,232,243,255,255,255, 88, 4, /* 0x 390 */ 87,137,215,106, 10,252, 89,232, 5, 0, 0, 0,136, 39,151, 95, /* 0x 390 */
48,170,195 /* 0x 3a0 */ 195,153,247,241, 82,133,192,116, 5,232,243,255,255,255, 88, 4, /* 0x 3a0 */
48,170,195 /* 0x 3b0 */
}; };
+124
View File
@@ -0,0 +1,124 @@
/* fold_machppc32.S -- linkage to C code to process Mach-o binary
*
* 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-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>
*/
#include "ppc_regs.h"
sz_b_info= 12
sz_unc= 0
sz_cpr= 4
sz_l_info= 12
sz_p_info= 12
/* Mach_ppc_thread_state */
srr0 = 0*4
srr1 = 1*4
reg0 = 2*4
reg_cr = 34*4
reg_xer = 35*4
reg_lr = 36*4
reg_ctr = 37*4
reg_mq = 38*4
reg_vrsave = 39*4
_start: .globl _start # ignored, but silence "cannot find entry symbol _start" from ld
/* In:
r31= &decompress; also 8+ (char *)&(offset to {l_info; p_info; b_info})
*/
fold_begin:
call L90
#include "ppc_bxx.S"
L90:
li a6,0
stwu a6,-4(sp) # default value
movr a6,sp # &mhdrp
mflr a5 # &ppcbxx: f_unfilter
lwz a1,-8(r31) # offset to {l_info; p_info; b_info}
subf a0,a1,r31 # &l_info
lwz a3,sz_unc+sz_p_info+sz_l_info(a0) # sz_mach_headers
cmpli 0,a3,2048; bgt L100; li a3,2048 # at least 2KB for /usr/bin/dyld
L100:
movr r29,sp # remember for restoring later
subf sp,a3,sp # alloca
movr a2,sp # &temp char[sz_mach_headers]
addi sp,sp,-4*6 # linkage area assumed by C code (sp,cr,lr, xx,yy,zz)
movr a4,r31 # f_decompress
call upx_main # Out: a0= &Mach_ppc_thread_state of dyld
movr sp,r29 # restore stack pointer
lwz t0, srr0(a0); mtctr t0 # entry address
/* Next 3 lines probably are not needed, but ... */
lwz t0, reg_cr(a0); mtcr t0 # condition code
lwz t0,reg_xer(a0); mtxer t0 # extended error reg (CArry, etc.)
lwz t0, reg_lr(a0); mtlr t0 # link register
lmw 4,4*4+reg0(3) # reg 4 thru 31
lwz 0,0*4+reg0(3)
lwz 2,2*4+reg0(3)
lwz 3,3*4+reg0(3)
bctr # goto dyld
SYS_exit =1
SYS_fork =2
SYS_read =3
SYS_write =4
SYS_open =5
SYS_close =6
SYS_mmap =197
SYS_mprotect= 74
/* SYS_mmap takes a 64-bit off_t, but gcc-3.4.1-20040827 passes long long
in wrong registers. So change C interface to use size_t (32-bits) instead
of off_t (64 bits), and convert here.
*/
mmap: .globl mmap
movr a6,a5; li a5,0 # zero extend 6th arg size_t to off_t
li 0,SYS_mmap
sysgo:
sc
li a0,-1 # failure return
ret
exit: .globl exit
li 0,SYS_exit; b sysgo
read: .globl read
li 0,SYS_read; b sysgo
open: .globl open
li 0,SYS_open; b sysgo
close: .globl close
li 0,SYS_close; b sysgo
mprotect: .globl mprotect
li 0,SYS_mprotect; b sysgo
+131
View File
@@ -0,0 +1,131 @@
/* fold_machppc32.h -- created from fold_machppc32.bin, 1528 (0x5f8) bytes
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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#define FOLD_MACHPPC32_SIZE 1528
#define FOLD_MACHPPC32_ADLER32 0xb665fdb7
#define FOLD_MACHPPC32_CRC32 0x0feee296
unsigned char fold_machppc32[1528] = {
72, 0, 0,105, 40, 6, 0,208, 76,130, 0, 32, 84,132,240,191, /* 0x 0 */
77,130, 0, 32, 60, 0, 0, 16,124, 4, 0, 64, 65,128, 0, 8, /* 0x 10 */
124, 4, 3,120, 56,165, 1, 32,124,103, 27,120, 56, 99,255,252, /* 0x 20 */
124,137, 3,166, 72, 0, 0, 28, 84, 75, 2,186,125, 99, 88, 80, /* 0x 30 */
125,107, 58, 20, 81, 98, 1,186,144, 67, 0, 0, 78, 64, 0, 32, /* 0x 40 */
132, 67, 0, 4, 84, 75, 85,190,124, 11, 40, 64, 65,162,255,220, /* 0x 50 */
66, 0,255,240, 78,128, 0, 32, 57, 32, 0, 0,149, 33,255,252, /* 0x 60 */
124, 41, 11,120,125, 8, 2,166,128,159,255,248,124,100,248, 80, /* 0x 70 */
128,195, 0, 24, 40, 6, 8, 0, 65,129, 0, 8, 56,192, 8, 0, /* 0x 80 */
124, 61, 11,120,124, 38, 8, 80,124, 37, 11,120, 56, 33,255,232, /* 0x 90 */
127,231,251,120, 72, 0, 4, 33,127,161,235,120,128, 67, 0, 0, /* 0x a0 */
124, 73, 3,166,128, 67, 0,136,124, 79,241, 32,128, 67, 0,140, /* 0x b0 */
124, 65, 3,166,128, 67, 0,144,124, 72, 3,166,184,131, 0, 24, /* 0x c0 */
128, 3, 0, 8,128, 67, 0, 16,128, 99, 0, 20, 78,128, 4, 32, /* 0x d0 */
125, 9, 67,120, 57, 0, 0, 0, 56, 0, 0,197, 68, 0, 0, 2, /* 0x e0 */
56, 96,255,255, 78,128, 0, 32, 56, 0, 0, 1, 75,255,255,240, /* 0x f0 */
56, 0, 0, 3, 75,255,255,232, 56, 0, 0, 5, 75,255,255,224, /* 0x 100 */
56, 0, 0, 6, 75,255,255,216, 56, 0, 0, 74, 75,255,255,208, /* 0x 110 */
124, 8, 2,166,148, 33,255,240,144, 1, 0, 20,128, 3, 0, 0, /* 0x 120 */
129, 35, 0, 4,127,128, 40, 64, 64,188, 0, 12, 56, 96, 0,127, /* 0x 130 */
75,255,255,185, 47,133, 0, 0, 65,158, 0, 28,124,169, 3,166, /* 0x 140 */
136, 9, 0, 0, 57, 41, 0, 1,152, 4, 0, 0, 56,132, 0, 1, /* 0x 150 */
66, 0,255,240,128, 3, 0, 0,129, 35, 0, 4,124, 5, 0, 80, /* 0x 160 */
144, 3, 0, 0,125, 41, 42, 20,128, 1, 0, 20, 56, 33, 0, 16, /* 0x 170 */
145, 35, 0, 4,124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166, /* 0x 180 */
148, 33,255,192,191,129, 0, 48,124,159, 35,120,124,126, 27,120, /* 0x 190 */
124,188, 43,120,144, 1, 0, 68,124,221, 51,120,128, 4, 0, 0, /* 0x 1a0 */
47,128, 0, 0, 65,158, 1, 32, 56,160, 0, 12,127,195,243,120, /* 0x 1b0 */
56,129, 0, 16, 75,255,255, 93,129, 33, 0, 16,128,161, 0, 20, /* 0x 1c0 */
47,137, 0, 0, 64,190, 0, 36, 60, 0, 33, 88, 96, 0, 80, 85, /* 0x 1d0 */
127,133, 0, 0, 64,190, 0, 28,128, 30, 0, 0, 47,128, 0, 0, /* 0x 1e0 */
65,190, 0,228, 72, 0, 0, 12, 47,133, 0, 0, 64,190, 0, 12, /* 0x 1f0 */
56, 96, 0,127, 75,255,254,245,127, 5, 72, 64, 65,185,255,244, /* 0x 200 */
128, 31, 0, 0,127,137, 0, 64, 65,189,255,232,128, 31, 0, 4, /* 0x 210 */
64,152, 0,132,124,164, 43,120,128,126, 0, 4,124, 5, 3,120, /* 0x 220 */
56,193, 0, 32,136,225, 0, 24,127,136, 3,166, 78,128, 0, 33, /* 0x 230 */
47,131, 0, 0, 64,190,255,188,128,129, 0, 32,128, 1, 0, 16, /* 0x 240 */
127,132, 0, 0, 64,190,255,172,136,193, 0, 25, 49, 61,255,255, /* 0x 250 */
124, 9,233, 16,125, 38, 0,208, 85, 41, 15,254,125, 43, 0, 57, /* 0x 260 */
65,162, 0, 20,128,127, 0, 4,127,168, 3,166,136,161, 0, 26, /* 0x 270 */
78,128, 0, 33,128, 30, 0, 4,129, 97, 0, 20,129, 62, 0, 0, /* 0x 280 */
124, 0, 90, 20,125, 43, 72, 80,144, 30, 0, 4,145, 62, 0, 0, /* 0x 290 */
72, 0, 0, 16,124, 4, 3,120,127,195,243,120, 75,255,254,117, /* 0x 2a0 */
129, 97, 0, 16,129, 63, 0, 0,128, 31, 0, 4,125, 43, 72, 80, /* 0x 2b0 */
47,137, 0, 0,124, 0, 90, 20,144, 31, 0, 4,145, 63, 0, 0, /* 0x 2c0 */
75,255,254,228,128, 1, 0, 68,187,129, 0, 48, 56, 33, 0, 64, /* 0x 2d0 */
124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166,148, 33,255,176, /* 0x 2e0 */
190, 97, 0, 28,125,128, 0, 38, 58,224, 0, 0,124,122, 27,120, /* 0x 2f0 */
144, 1, 0, 84,124,155, 35,120,128, 3, 0, 16,124,179, 43,120, /* 0x 300 */
145,129, 0, 24,124,212, 51,120,127,151, 0, 64,124,245, 59,120, /* 0x 310 */
125, 22, 67,120, 59,195, 0, 28, 59, 0, 0, 0, 64,156, 1,120, /* 0x 320 */
129, 62, 0, 0, 47,137, 0, 1, 64,190, 1, 44,129, 62, 0, 24, /* 0x 330 */
129,126, 0, 36, 85, 61, 5, 62,128, 30, 0, 28,127,139,234, 20, /* 0x 340 */
145, 97, 0, 8, 46, 28, 0, 0,127, 41, 2, 20,145, 33, 0, 12, /* 0x 350 */
127,253, 72, 80, 65,146, 0, 72, 47,155, 0, 0, 64,190, 0, 16, /* 0x 360 */
47,139, 0, 0, 56,192, 0, 18, 64,158, 0, 8, 56,192, 16, 18, /* 0x 370 */
47,139, 0, 0,126,103,155,120, 64,158, 0, 8, 56,224,255,255, /* 0x 380 */
129, 30, 0, 32,127,227,251,120,127,132,227,120, 56,160, 0, 3, /* 0x 390 */
75,255,253, 65,127,159, 24, 0, 64,158, 0,124, 47,155, 0, 0, /* 0x 3a0 */
65,158, 0, 52,128, 30, 0, 36, 47,128, 0, 0, 65,158, 0, 40, /* 0x 3b0 */
128, 30, 0, 32, 47,128, 0, 0, 64,158, 0, 8,147,244, 0, 0, /* 0x 3c0 */
127, 99,219,120, 56,129, 0, 8,126,165,171,120,126,198,179,120, /* 0x 3d0 */
75,255,253,173,124, 28, 0,208,125, 63,226, 20,112, 29, 15,255, /* 0x 3e0 */
65,130, 0, 24,127,169, 3,166, 56, 0, 0, 0,152, 9, 0, 0, /* 0x 3f0 */
57, 41, 0, 1, 66, 0,255,248, 65,178, 0, 36,128,190, 0, 44, /* 0x 400 */
127,227,251,120,127,132,227,120, 75,255,253, 1, 47,131, 0, 0, /* 0x 410 */
65,190, 0, 12, 56, 96, 0,127, 75,255,252,209,124, 28,234, 20, /* 0x 420 */
127,255, 2, 20,127,159,200, 64, 64,188, 0, 84,128,190, 0, 44, /* 0x 430 */
124,159,200, 80,127,227,251,120, 56,192, 16, 18, 56,224,255,255, /* 0x 440 */
57, 0, 0, 0, 75,255,252,141,127,159, 24, 0, 65,190, 0, 48, /* 0x 450 */
75,255,255,196, 56, 9,255,252, 43,128, 0, 1, 65,157, 0, 32, /* 0x 460 */
128, 30, 0, 8, 47,128, 0, 1, 64,190, 0, 20,128, 30, 0, 12, /* 0x 470 */
47,128, 0, 40, 64,190, 0, 8, 58,254, 0, 16,128, 26, 0, 16, /* 0x 480 */
59, 24, 0, 1,127,152, 0, 64,128, 30, 0, 4,127,222, 2, 20, /* 0x 490 */
75,255,254,140,128, 1, 0, 84,126,227,187,120,129,129, 0, 24, /* 0x 4a0 */
186, 97, 0, 28,124, 8, 3,166, 56, 33, 0, 80,125,128,129, 32, /* 0x 4b0 */
78,128, 0, 32,148, 33,255,192,124, 8, 2,166,144,129, 0, 8, /* 0x 4c0 */
191, 65, 0, 40,129, 97, 0, 8,124,191, 43,120,144, 1, 0, 68, /* 0x 4d0 */
56, 3, 0, 24, 57,107,255,232,144, 1, 0, 20,145, 97, 0, 16, /* 0x 4e0 */
124,253, 59,120,128, 3, 0, 24,125, 60, 75,120,200, 1, 0, 16, /* 0x 4f0 */
125, 27, 67,120,124,229, 59,120, 56, 97, 0, 16, 56,129, 0, 24, /* 0x 500 */
124,218, 51,120, 56,192, 0, 0,144, 1, 0, 24,216, 1, 0, 32, /* 0x 510 */
59,192, 0, 0,147,225, 0, 28, 75,255,252,101,127,167,235,120, /* 0x 520 */
127,104,219,120,127,227,251,120,127,134,227,120, 56,129, 0, 32, /* 0x 530 */
56,160,255,255, 75,255,253,165,128, 31, 0, 16,124,123, 27,120, /* 0x 540 */
59,191, 0, 28,127,158, 0, 64, 64,156, 0,136,128, 29, 0, 0, /* 0x 550 */
59,222, 0, 1, 56,128, 0, 0, 56,160, 0, 0, 47,128, 0, 14, /* 0x 560 */
64,190, 0, 92,128,125, 0, 8,124,125, 26, 20, 75,255,251,141, /* 0x 570 */
127,228,251,120,124,124, 27,121,127, 69,211,120, 65,128, 0, 40, /* 0x 580 */
75,255,251,113, 56,128, 0, 0,127,154, 24, 0,127,133,227,120, /* 0x 590 */
127,227,251,120, 56,192, 0, 0, 56,224, 0, 0, 57, 0, 0, 0, /* 0x 5a0 */
65,190, 0, 12, 56, 96, 0,127, 75,255,251, 65, 75,255,253, 45, /* 0x 5b0 */
124,123, 27,120,127,131,227,120, 75,255,251, 73,128, 31, 0, 16, /* 0x 5c0 */
129, 61, 0, 4,127,158, 0, 64,127,189, 74, 20, 75,255,255,124, /* 0x 5d0 */
128, 1, 0, 68,127, 99,219,120,187, 65, 0, 40, 56, 33, 0, 64, /* 0x 5e0 */
124, 8, 3,166, 78,128, 0, 32 /* 0x 5f0 */
};
+131
View File
@@ -0,0 +1,131 @@
; fold_pti86.asm -- linkage to C code to act as ELF PT_INTERP
;
; This file is part of the UPX executable compressor.
;
; 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>
;
BITS 32
SECTION .text
CPU 386
%define PAGE_SIZE ( 1<<12)
%define AT_NULL 0
%define AT_PHDR 3
%define szElf32_Ehdr 0x34
%define szElf32_Phdr 8*4
%define e_entry (16 + 2*2 + 4)
%define p_vaddr 2*4
%define p_memsz 5*4
%define szb_info 12
%define szl_info 12
%define szp_info 12
%define a_type 0
%define a_val 4
%define sz_auxv 8
%define MAP_FIXED 0x10
%define MAP_PRIVATE 0x02
%define MAP_ANONYMOUS 0x20
%define PROT_READ 1
%define PROT_WRITE 2
%define PROT_EXEC 4
%define __NR_mmap 90
%define __NR_munmap 91
%define OVERHEAD 2048
%define MAX_ELF_HDR 512
pop ebp ; get_fexp
pop ecx ; get_funf
pop eax ; argc
lea edi, [4+ 4*eax + esp] ; &environ
push eax ; argc
sub eax,eax ; 0
L310:
scasd
jne L310
scasd ; edi= &Elf32_auxv_t
mov esi,edi
L320:
mov eax,[esi] ; a_type
cmp eax, byte AT_PHDR
je L330
add esi, byte sz_auxv
cmp eax, byte AT_NULL
jne L320
L330:
mov ebx,[a_val + esi]
push ebx ; save &Elf32_Phdr of compressed data
sub esp, dword MAX_ELF_HDR + OVERHEAD ; working storage
mov edx, esp
push ecx ; get_funf 9th param to pti_main
lea eax, [2*szElf32_Phdr + szl_info + szp_info + ebx] ; 1st &b_info
mov esi, [e_entry + ebx] ; beyond compressed data
sub esi, eax ; length of compressed data
mov ebx, [ eax] ; length of uncompressed ELF headers
mov ecx, [4+ eax] ; length of compressed ELF headers
add ecx, byte szb_info
pusha ; (AT_table, sz_cpr, get_fexp, &tmp_ehdr, {sz_unc, &tmp}, {sz_cpr, &b1st_info} )
EXTERN pti_main
call pti_main ; returns entry address
add esp, dword 9*4 + MAX_ELF_HDR + OVERHEAD ; remove 9 params, temp space
pop ebx ; &Elf32_Phdr
push eax ; save entry address
mov ecx,[p_memsz + ebx]
mov ebx,[p_vaddr + ebx]
mov eax,__NR_munmap
int 0x80 ; unmap compressed data
sub eax,eax
sub ecx,ecx
sub edx,edx
sub ebx,ebx
sub ebp,ebp
sub esi,esi
sub edi,edi
ret ; goto entry point
%define __NR_mmap 90
global mmap
mmap:
push ebx
lea ebx, [2*4 + esp]
push byte __NR_mmap
pop eax
int 0x80
pop ebx
ret
; vi:ts=8:et:nowrap
+132
View File
@@ -0,0 +1,132 @@
/* fold_pti86.h -- created from fold_pti86.bin, 1537 (0x601) bytes
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
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#define LINUX_I386PTI_FOLD_SIZE 1537
#define LINUX_I386PTI_FOLD_ADLER32 0xf6d697b8
#define LINUX_I386PTI_FOLD_CRC32 0xcce6fcb1
unsigned char linux_i386pti_fold[1537] = {
127, 69, 76, 70, 1, 1, 1, 0, 76,105,110,117,120, 0, 0, 0, /* 0x 0 */
2, 0, 3, 0, 1, 0, 0, 0,128, 0, 1, 0, 52, 0, 0, 0, /* 0x 10 */
0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 0, 0, /* 0x 20 */
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, /* 0x 30 */
0, 0, 1, 0, 1, 6, 0, 0, 4, 6, 0, 0, 5, 0, 0, 0, /* 0x 40 */
0, 16, 0, 0, 1, 0, 0, 0, 1, 6, 0, 0, 4, 6, 1, 0, /* 0x 50 */
4, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, /* 0x 60 */
0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */
93, 89, 88,141,124,132, 4, 80, 41,192,175,117,253,175,137,254, /* 0x 80 */
139, 6,131,248, 3,116, 8,131,198, 8,131,248, 0,117,241,139, /* 0x 90 */
94, 4, 83,129,236, 0, 10, 0, 0,137,226, 81,141, 67, 88,139, /* 0x a0 */
115, 24, 41,198,139, 24,139, 72, 4,131,193, 12, 96,232, 71, 4, /* 0x b0 */
0, 0,129,196, 36, 10, 0, 0, 91, 80,139, 75, 20,139, 91, 8, /* 0x c0 */
184, 91, 0, 0, 0,205,128, 41,192, 41,201, 41,210, 41,219, 41, /* 0x d0 */
237, 41,246, 41,255,195, 83,141, 92, 36, 8,106, 90, 88,205,128, /* 0x e0 */
91,195, 0, 0, 87, 86,137,206, 83,137,195, 57, 8,139,120, 4, /* 0x f0 */
115, 10,106,127, 91,106, 1, 88,205,128,235,254,133,201,116, 8, /* 0x 100 */
138, 7, 71,136, 2, 66,226,248, 1,115, 4, 41, 51, 91, 94, 95, /* 0x 110 */
195, 85,137,229, 87, 86,137,198, 83,137,211,131,236, 20,139,125, /* 0x 120 */
12,131, 58, 0, 15,132,185, 0, 0, 0,141, 85,228,185, 12, 0, /* 0x 130 */
0, 0,137,240,232,171,255,255,255,139, 69,228,139, 77,232,133, /* 0x 140 */
192,117, 19,129,249, 85, 80, 88, 33,117, 15,131, 62, 0, 15,132, /* 0x 150 */
143, 0, 0, 0,235, 4,133,201,117, 10,106,127, 91,106, 1, 88, /* 0x 160 */
205,128,235,254, 57,193,119,242, 59, 3,119,238, 57,193,115, 86, /* 0x 170 */
15,182, 69,236, 80,255, 85, 8, 15,182, 85,236,137, 20, 36,141, /* 0x 180 */
85,224, 82,255,115, 4,255,117,232,255,118, 4,255, 16,131,196, /* 0x 190 */
20,133,192,117,197,139, 69,228, 57, 69,224,117,189,138, 69,237, /* 0x 1a0 */
132,192,116, 24, 15,182,192, 80,255,215, 15,182, 85,238,137, 20, /* 0x 1b0 */
36,255,117,224,255,115, 4,255, 16,131,196, 12,139, 69,232, 1, /* 0x 1c0 */
70, 4, 41, 6,235, 10,139, 83, 4,137,240,232, 20,255,255,255, /* 0x 1d0 */
139, 85,228,139, 3, 1, 83, 4, 41,208,133,192,137, 3,233, 65, /* 0x 1e0 */
255,255,255,141,101,244, 91, 94, 95,201,195,133,210,137,209,116, /* 0x 1f0 */
6,198, 0, 0, 64,226,250,195,133,192, 83,137,211,116, 29,168, /* 0x 200 */
1,117, 25,139, 16, 57,218,116, 7, 74,117, 11,133,219,116, 7, /* 0x 210 */
137, 24,137, 72, 4,235, 5,131,192, 8,235,231, 91,195, 85,137, /* 0x 220 */
229, 87, 86, 83,131,236, 80,137, 69,228,139, 69, 8,137, 85,224, /* 0x 230 */
139, 77, 16,199, 69,200, 0, 0, 0, 0,137, 69,220, 3, 64, 28, /* 0x 240 */
139, 93,220,137, 77,212,139, 85, 12,137, 69,208, 49,192,102,131, /* 0x 250 */
123, 16, 3,137, 85,216, 15,183, 75, 44,139, 85,208, 15,149,192, /* 0x 260 */
131,206,255,193,224, 4,137,207,131,192, 34, 49,219, 79,137, 69, /* 0x 270 */
184,120, 34,131, 58, 1,117, 24,139, 66, 8, 57,240,115, 8,139, /* 0x 280 */
122, 16,137,198,137,125,200, 3, 66, 20, 57,195,115, 2,137,195, /* 0x 290 */
131,194, 32,226,222,137,247,106, 0,129,231, 0,240,255,255,106, /* 0x 2a0 */
0, 41,251,255,117,184,129,195,255, 15, 0, 0,106, 7,129,227, /* 0x 2b0 */
0,240,255,255,139, 85,200, 83,137,240, 37,255, 15, 0, 0, 87, /* 0x 2c0 */
137, 93,172,141,180, 2,255, 15, 0, 0,232, 7,254,255,255,137, /* 0x 2d0 */
194,131,196, 24, 1,218,129,230, 0,240,255,255,137, 85,240,137, /* 0x 2e0 */
194, 41,243, 1,242,137,217,137, 69,176,137,211,106, 91, 88,205, /* 0x 2f0 */
128,139, 69,176,199, 69,192, 0, 0, 0, 0,139, 85,220, 41,248, /* 0x 300 */
102,131,122, 44, 0,137, 69,204, 15,132,177, 1, 0, 0,139, 77, /* 0x 310 */
208,139, 1,131,248, 6,117, 27,139, 93,208,186, 3, 0, 0, 0, /* 0x 320 */
139, 77,204, 3, 75, 8,139, 69,212,232,202,254,255,255,233,117, /* 0x 330 */
1, 0, 0, 72, 15,133,110, 1, 0, 0,139,125,208,199, 69,188, /* 0x 340 */
64, 98, 81,115,139, 79, 24,139, 71, 8,131,225, 7,139, 87, 16, /* 0x 350 */
193,225, 2,137, 69,236,211,109,188,137,193, 3, 79, 20,137,199, /* 0x 360 */
129,231,255, 15, 0, 0,137, 85,232,141, 52, 58,139, 85,204, 41, /* 0x 370 */
248,131,101,188, 7, 1,209,141, 28, 16,137, 77,180,139, 77,208, /* 0x 380 */
139, 65, 4, 41,248,131,125,216, 1, 80,255,117,228, 25,192,131, /* 0x 390 */
224,224,131,192, 50,131,125,216, 0, 80,137,240,106, 3,116, 3, /* 0x 3a0 */
141, 70, 3, 80, 83,232, 44,253,255,255,131,196, 24, 57,195, 15, /* 0x 3b0 */
133,168, 0, 0, 0,131,125,216, 0,116, 19,255,117,224,255,117, /* 0x 3c0 */
228,141, 85,232,139, 69,216,232, 69,253,255,255, 88, 90,137,250, /* 0x 3d0 */
137,247,137,216,247,223,232, 16,254,255,255,129,231,255, 15, 0, /* 0x 3e0 */
0,141, 4, 51,137,250,232, 0,254,255,255,131,125,216, 0,116, /* 0x 3f0 */
94,139, 69,208,131, 56, 1,117, 86,246, 64, 24, 1,116, 80,139, /* 0x 400 */
80, 20,139, 72, 8,137, 77,164,137,209, 3, 77,164, 59, 80, 16, /* 0x 410 */
117, 14,137,200,247,216, 37,255, 15, 0, 0,131,248, 3,119, 15, /* 0x 420 */
139, 77,164,139, 69,208,131,193, 12,131,120, 4, 0,117, 15,139, /* 0x 430 */
1, 61,205,128, 97,195,116, 6,199, 1,205,128, 97,195,133,201, /* 0x 440 */
116, 13,139, 69,212, 49,210,131,224,254,232,169,253,255,255,137, /* 0x 450 */
241,139, 85,188,106,125, 88,205,128,133,192,116, 10,106,127, 91, /* 0x 460 */
106, 1, 88,205,128,235,254,141, 4, 62, 1,195, 59, 93,180,115, /* 0x 470 */
30,106, 0,106, 0,106, 50,255,117,188, 41, 93,180,255,117,180, /* 0x 480 */
83,232, 80,252,255,255,131,196, 24, 57,195,116, 27,235,206,131, /* 0x 490 */
125,216, 0,116, 19,141, 78, 3,129,225,255, 15, 0, 0,131,249, /* 0x 4a0 */
3,119, 5,106, 91, 88,205,128,139, 93,220,255, 69,192, 15,183, /* 0x 4b0 */
67, 44,131, 69,208, 32, 57, 69,192, 15,140, 79,254,255,255,131, /* 0x 4c0 */
125,216, 0,117, 14,139, 93,228,106, 6, 88,205,128,133,192,116, /* 0x 4d0 */
20,235,138,139,125,220,102,131,127, 16, 3,116, 8,139, 93,240, /* 0x 4e0 */
106, 45, 88,205,128,139, 69,220,139, 64, 24, 1, 69,204,139, 69, /* 0x 4f0 */
204,141,101,244, 91, 94, 95,201,195, 85,137,229, 87, 86, 83, 81, /* 0x 500 */
139,125, 20,141, 85, 24,255,117, 40,141, 71, 52,139, 93, 8,255, /* 0x 510 */
117, 16,137, 69,240,139,117, 32,141, 69, 32,232,241,251,255,255, /* 0x 520 */
139, 85,240,139, 69, 12,139, 74, 8,186, 3, 0, 0, 0,137, 69, /* 0x 530 */
32,137,216,131,193, 52, 41,117, 36,232,186,252,255,255, 15,183, /* 0x 540 */
79, 42,137,216,186, 4, 0, 0, 0,232,170,252,255,255, 15,183, /* 0x 550 */
79, 44,137,216,186, 5, 0, 0, 0,232,154,252,255,255,139, 79, /* 0x 560 */
24,137,216,186, 9, 0, 0, 0,232,139,252,255,255,141, 69, 32, /* 0x 570 */
83,139, 85, 40, 80,139, 69, 16, 87,232,160,252,255,255,102,139, /* 0x 580 */
79, 44,131,196, 20, 49,210,102,133,201,137,195,116, 89,139, 69, /* 0x 590 */
240,131, 56, 3,117, 69, 49,201,139, 88, 8,137,202,106, 5, 88, /* 0x 5a0 */
205,128,133,192,137,198,120, 20,102,186, 0, 2,137,195,137,249, /* 0x 5b0 */
106, 3, 88,205,128, 61, 0, 2, 0, 0,116, 10,106,127, 91,106, /* 0x 5c0 */
1, 88,205,128,235,254,106, 0, 49,210,106, 0,137,240, 87,232, /* 0x 5d0 */
74,252,255,255,131,196, 12,137,195,235, 12, 66, 15,183,193,131, /* 0x 5e0 */
69,240, 32, 57,194,124,167,141,101,244,137,216, 91, 94, 95,201, /* 0x 5f0 */
195 /* 0x 600 */
};
+13 -1
View File
@@ -159,10 +159,22 @@ EXTERN upx_main
; ourselves the stub. We would need a place to put the escape hatch ; ourselves the stub. We would need a place to put the escape hatch
; "int $0x80; popa; ret", and some kernels do not allow execution ; "int $0x80; popa; ret", and some kernels do not allow execution
; on the stack. So, we would have to dirty a page of the shell ; on the stack. So, we would have to dirty a page of the shell
; or of /lib/ld-linux.so. It's simpler just to omit the unapping. ; or of /lib/ld-linux.so. It's simpler just to omit the unmapping.
popa popa
ret ret
%define __NR_mmap 90
global mmap
mmap:
push ebx
lea ebx, [2*4 + esp]
push byte __NR_mmap
pop eax
int 0x80
pop ebx
ret
; vi:ts=8:et:nowrap ; vi:ts=8:et:nowrap

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