Compare commits
163 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6766b14415 | |||
| 9d0f9e967f | |||
| d7609088e5 | |||
| b2643b6926 | |||
| 07b65ca069 | |||
| 25727f7f99 | |||
| 880ae89307 | |||
| 1496df1989 | |||
| 7d8ae6b4b1 | |||
| 312d4cccaf | |||
| ce5f9f95ea | |||
| d9bf8a76d9 | |||
| f7a35fb9fe | |||
| 3ba691ded5 | |||
| 7a7277d56f | |||
| 76be5dd1d3 | |||
| 53dc63f3bc | |||
| 80da0bc9d5 | |||
| bce7af4e11 | |||
| 9da09b51ed | |||
| 86392f197f | |||
| 1c13046297 | |||
| fbc756b531 | |||
| 6c64b06453 | |||
| 241834029a | |||
| 5b8a9c0b47 | |||
| 037c29d24a | |||
| 893f26ac9a | |||
| d43f8e3100 | |||
| 2b42acf7b8 | |||
| f65b80ed42 | |||
| e84abbdc82 | |||
| 66269eabe9 | |||
| 36c0928483 | |||
| 9237e15adc | |||
| 0d3a2072b2 | |||
| aa2ee5dfc2 | |||
| b515fa39ec | |||
| 76e3f4eb92 | |||
| 4959e5c6c2 | |||
| 7082594bbc | |||
| 36dd35f238 | |||
| 9c9fb6a485 | |||
| 5438a4837b | |||
| 84996e8cb6 | |||
| 87a368a857 | |||
| 21412d93dd | |||
| 0b11ff22b4 | |||
| 8fafa78796 | |||
| c43158f8a2 | |||
| 92ad524947 | |||
| b362a61863 | |||
| 468fec38d7 | |||
| 89830a5ae0 | |||
| 5977c296bd | |||
| 47d5792d97 | |||
| 25d706a913 | |||
| 048236aaaa | |||
| d442c58fd1 | |||
| f890f6bb09 | |||
| 036d466790 | |||
| dee47ba2d8 | |||
| be96c28b77 | |||
| ad1c0f578e | |||
| c8f7b1b72c | |||
| c89702ae84 | |||
| 2d29a82250 | |||
| b36c65e654 | |||
| 09b072b908 | |||
| 0ae9fee350 | |||
| 1579182ed9 | |||
| 074671aa71 | |||
| 36b7c47247 | |||
| 424d5b3025 | |||
| 8a5d352733 | |||
| f383629282 | |||
| a6d717cb04 | |||
| 84a5753301 | |||
| 5d2d9c7e81 | |||
| 82801d1411 | |||
| 340c3963d8 | |||
| ef15cf9847 | |||
| 4d613ccfa7 | |||
| 43ce34d547 | |||
| eda074cd80 | |||
| a2396d82f6 | |||
| a38721db93 | |||
| a06e811717 | |||
| 86e534ff75 | |||
| 640d5b2dec | |||
| 57e9b27085 | |||
| c56eefc739 | |||
| cf28306997 | |||
| 10acf3ddd1 | |||
| fed3ed9f9a | |||
| 260138ba11 | |||
| 67f7e0089c | |||
| d4a22c7851 | |||
| 06cf986490 | |||
| adf9aa04ce | |||
| 69f66fbe52 | |||
| d061005c89 | |||
| f6ee8b9f04 | |||
| 31af22c2ff | |||
| c421e3f243 | |||
| 6e92902407 | |||
| 6256381dc3 | |||
| b247b051ea | |||
| afbd553622 | |||
| 36bc14e884 | |||
| 9c5d0ff2ff | |||
| cfa6c8ddf6 | |||
| 21924bf022 | |||
| eea33f6019 | |||
| 66d48ae808 | |||
| de9b9fd0b1 | |||
| ece7384be4 | |||
| 0c052e4506 | |||
| 1996a0a3d6 | |||
| 679ad9b8c6 | |||
| d4983731e7 | |||
| 4fec3c8f34 | |||
| 836fd2565f | |||
| 54618064a1 | |||
| 519e3e01ae | |||
| aec8f81358 | |||
| c1d6bf4366 | |||
| 9bf2b79d9e | |||
| 4d98408995 | |||
| 7b466388f9 | |||
| b926fb3c66 | |||
| 6c8d5c0d0e | |||
| 5a1d234260 | |||
| fd6d42c297 | |||
| 7310ad6e92 | |||
| 7e47b1348d | |||
| 1e3555a6b7 | |||
| 9a67ce5968 | |||
| 279d7955f8 | |||
| db977c0bf5 | |||
| ba6bc59818 | |||
| 6e8be0578c | |||
| 92f7d16b5e | |||
| 40bb3c2f5e | |||
| 56a6096221 | |||
| ee37b42a91 | |||
| 0806e61df4 | |||
| 279ffeeefa | |||
| 80c5ee2479 | |||
| 16208544e5 | |||
| 6afeb24fdb | |||
| e6357b81eb | |||
| dfc2efe8a6 | |||
| f28b96f431 | |||
| a10293f8f7 | |||
| b1f02f91d7 | |||
| e76fa45d86 | |||
| 06f43892a5 | |||
| a094332b0d | |||
| 7b8779f534 | |||
| 371bf20d19 | |||
| 0f633ddd15 | |||
| 7886ca7f5f |
@@ -9,6 +9,8 @@ syntax: regexp
|
||||
syntax: glob
|
||||
|
||||
.depend
|
||||
*.qtcreator.{config,creator,creator.user,files,includes}
|
||||
*.sublime-{project,workspace}
|
||||
Makevars.local
|
||||
|
||||
*.a
|
||||
@@ -42,7 +44,9 @@ src/*.ttp
|
||||
|
||||
stub/**MMakefile
|
||||
stub/**.*-stamp
|
||||
stub/tmp*/*
|
||||
##stub/tmp*/*
|
||||
stub/tmp*/*.{bin,bin.bindump,bin.disasm,d,map,o,o.disasm}
|
||||
stub/tmp*/mips{,el}.r3000-*.{i,s}
|
||||
stub/**/tmp*/*
|
||||
|
||||
stub/tools/armpe/armpe_tester{,.exe,.out}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
087cafe682c014863b4aa8a6ea21431251a6ad3c RELEASE_308
|
||||
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
|
||||
155618b5b7930f97bd84b82befa7a4fd6672efb3 RELEASE_304
|
||||
1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301
|
||||
@@ -17,7 +18,9 @@ b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg
|
||||
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
|
||||
c9a983b7da9d4a2311f74366478348412cac2986 RELEASE_305
|
||||
d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290
|
||||
d3989a12c70b0921ff0f7e5e485b398eb12a73b3 RELEASE_309
|
||||
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
|
||||
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
|
||||
ef9c7f2c9658d73a9b5ab2ed291483d2bbcd8bc7 RELEASE_300
|
||||
efa52753e366300c0e0ebe20631adcb24ed3c15b RELEASE_293
|
||||
fe7acf61147e7031fcc304aae47ca2352056815d RELEASE_307
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ test file.
|
||||
|
||||
win32/pe
|
||||
--------
|
||||
* writeable shared sections (`--force' *may* work)
|
||||
* writable shared sections (`--force' *may* work)
|
||||
* certificates in the image
|
||||
* compressing files which contain a big BSS requires lots of memory
|
||||
during compression
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# UPX toplevel Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
|
||||
@@ -2,6 +2,31 @@
|
||||
User visible changes for UPX
|
||||
==================================================================
|
||||
|
||||
Changes in 3.91 (30 Sep 2013):
|
||||
* Added experimental support for Windows 64-bit PE files, based on
|
||||
work by Stefan Widmann. Please use for testing only!
|
||||
* bug fixes
|
||||
|
||||
==================================================================
|
||||
|
||||
Changes in 3.09 (18 Feb 2013):
|
||||
* New option --preserve-build-id for GNU ELF.
|
||||
* Allow for code signing and LC_UUID on Mac OS X executables.
|
||||
* Allow non-contiguous LC_SEGMENTs and 0==.vmsize for Mach-O.
|
||||
* Allow zero-filled final page in PackUnix::canUnpack().
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.08 (12 Dec 2011):
|
||||
* Fix allocation in runtime stub for darwin.macho-entry (i386 and amd64).
|
||||
* Compress shared library on ELF i386 only [ld.so threatens even this case].
|
||||
* Attempt to support ELF on QNX 6.3.0 for armel (experimental).
|
||||
* Better diagnostic when ELF -fPIC is needed.
|
||||
* PT_NOTE improvements for *BSD.
|
||||
* Preserve more ELF .e_flags on ARM.
|
||||
* Minor code improvements for ELF stubs.
|
||||
* Defend against another flavor of corrupt PE header.
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.07 (08 Sep 2010):
|
||||
* win32/pe: fixed relocation handling for files with *no* TLS callbacks
|
||||
[severe bug introduced in 3.06]
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -108,9 +108,9 @@ THE FUTURE
|
||||
COPYRIGHT
|
||||
=========
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +71,12 @@ Tools needed to build/modify the UPX sources
|
||||
|
||||
- GNU make 3.81 or better
|
||||
|
||||
- zlib and zlib-devel [or zlib-dev] software packages for your
|
||||
host environment, or via http://www.cygwin.org/setup.exe
|
||||
|
||||
- lzma SDK, such as from https://sourceforge.net/projects/sevenzip/
|
||||
files/LZMA%20SDK/4.43/
|
||||
|
||||
|
||||
To compile the packer sources
|
||||
-----------------------------
|
||||
@@ -85,6 +91,7 @@ To compile the packer sources
|
||||
to your unpacked lzma443.tar.bz2 source directory, e.g.
|
||||
|
||||
export UPX_LZMADIR=$HOME/local/src/lzma-4.43 (Unix)
|
||||
export UPX_LZMA_VERSION=0x443 # perhaps 0x459,0x458,0x457,0x449,0x442
|
||||
|
||||
Finally type
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
+16
-1
@@ -1,5 +1,5 @@
|
||||
Decompressing ELF Directly to Memory on Linux/x86
|
||||
Copyright (C) 2000-2010 John F. Reiser jreiser@BitWagon.com
|
||||
Copyright (C) 2000-2013 John F. Reiser jreiser@BitWagon.com
|
||||
|
||||
References:
|
||||
<elf.h> definitions for the ELF file format
|
||||
@@ -76,6 +76,21 @@ and previous versions did this by default with no option. However,
|
||||
too much other software erroneously assumes that /proc/self/exe
|
||||
always exists.
|
||||
|
||||
On arm*-linux-elf there is no good address at which to retain one
|
||||
page of the compressed executable. Pages below the usual .p_vaddr
|
||||
0x8000 (32KiB) are rejected by the kernel. Using a page above the
|
||||
original uncompressed brk(0) would require placing the entire initial
|
||||
compressed program above uncompressed brk(0), which would significantly
|
||||
increase the running brk(0); but too many programs break if brk(0)
|
||||
moves. Thus on arm*-linux-elf the compressed executable begins
|
||||
with 0x8000==.p_vaddr, all pages mapped by execve() that are also
|
||||
occupied by decompressed bytes are removed before overwriting, and
|
||||
/proc/self/exe becomes a "(deleted)" symlink. It might be possible
|
||||
to preserve /proc/self/exe if the original uncompressed executable
|
||||
were created with 0x9000==.p_vaddr (one page higher than the usual
|
||||
0x8000) so that the compressed page mapped at 0x8000 would linger.
|
||||
[This has not been tested.]
|
||||
|
||||
Linux stores the pathname argument that was specified to execve()
|
||||
immediately after the '\0' which terminates the character string of the
|
||||
last environment variable [as of execve()]. This is true for at least
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ code 127, and a record will be added to the history file
|
||||
|
||||
In "targeted enforcing" mode, SELinux pays close attention mostly to
|
||||
designated processes that run with elevated privileges: web server,
|
||||
print server, login server, etc. Ordinary user excutables receive
|
||||
print server, login server, etc. Ordinary user executables receive
|
||||
much less scrutiny. However, one of the eventual goals of SELinux is to
|
||||
eradicate runtime generation of instructions because of the possibility
|
||||
for exploitation by malware (virus, trojan, key logger, privilege
|
||||
|
||||
+5
-5
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
||||
=head1 ABSTRACT
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -933,13 +933,13 @@ Please report all bugs immediately to the authors.
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
Copyright (C) 2002-2013 Jens Medoch
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# UPX Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
|
||||
+45
-45
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -88,7 +88,7 @@ inline void set_be32(void *p, unsigned v)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_be64(const void *p)
|
||||
inline upx_uint64_t get_be64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_BE64)
|
||||
return ACC_UA_GET_BE64(p);
|
||||
@@ -97,7 +97,7 @@ inline acc_uint64l_t get_be64(const void *p)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_be64(void *p, acc_uint64l_t v)
|
||||
inline void set_be64(void *p, upx_uint64_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_BE64)
|
||||
ACC_UA_SET_BE64(p, v);
|
||||
@@ -160,7 +160,7 @@ inline void set_le32(void *p, unsigned v)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_le64(const void *p)
|
||||
inline upx_uint64_t get_le64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE64)
|
||||
return ACC_UA_GET_LE64(p);
|
||||
@@ -169,7 +169,7 @@ inline acc_uint64l_t get_le64(const void *p)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le64(void *p, acc_uint64l_t v)
|
||||
inline void set_le64(void *p, upx_uint64_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE64)
|
||||
ACC_UA_SET_LE64(p, v);
|
||||
@@ -192,13 +192,13 @@ inline int sign_extend(unsigned v, unsigned bits)
|
||||
return (int) v;
|
||||
}
|
||||
|
||||
inline acc_int64l_t sign_extend(acc_uint64l_t v, unsigned bits)
|
||||
inline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits)
|
||||
{
|
||||
const acc_uint64l_t sign_bit = ACC_UINT64_C(1) << (bits - 1);
|
||||
const upx_uint64_t sign_bit = UPX_UINT64_C(1) << (bits - 1);
|
||||
v &= sign_bit | (sign_bit - 1);
|
||||
//v = (v ^ sign_bit) - sign_bit;
|
||||
v |= 0 - (v & sign_bit);
|
||||
return (acc_int64l_t) v;
|
||||
return (upx_int64_t) v;
|
||||
}
|
||||
|
||||
inline int get_be16_signed(const void *p)
|
||||
@@ -219,9 +219,9 @@ inline int get_be32_signed(const void *p)
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline acc_int64l_t get_be64_signed(const void *p)
|
||||
inline upx_int64_t get_be64_signed(const void *p)
|
||||
{
|
||||
acc_uint64l_t v = get_be64(p);
|
||||
upx_uint64_t v = get_be64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
@@ -243,9 +243,9 @@ inline int get_le32_signed(const void *p)
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline acc_int64l_t get_le64_signed(const void *p)
|
||||
inline upx_int64_t get_le64_signed(const void *p)
|
||||
{
|
||||
acc_uint64l_t v = get_le64(p);
|
||||
upx_uint64_t v = get_le64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
@@ -269,25 +269,25 @@ inline unsigned acc_swab32(unsigned v)
|
||||
}
|
||||
|
||||
|
||||
inline unsigned acc_swab16p(const acc_uint16e_t *p)
|
||||
inline unsigned acc_swab16p(const upx_uint16_t *p)
|
||||
{
|
||||
return acc_swab16(*p);
|
||||
}
|
||||
|
||||
inline unsigned acc_swap32p(const acc_uint32e_t *p)
|
||||
inline unsigned acc_swap32p(const upx_uint32_t *p)
|
||||
{
|
||||
return acc_swab32(*p);
|
||||
}
|
||||
|
||||
|
||||
inline void acc_swab16s(acc_uint16e_t *p)
|
||||
inline void acc_swab16s(upx_uint16_t *p)
|
||||
{
|
||||
*p = (acc_uint16e_t) acc_swab16(*p);
|
||||
*p = (upx_uint16_t) acc_swab16(*p);
|
||||
}
|
||||
|
||||
inline void acc_swab32s(acc_uint32e_t *p)
|
||||
inline void acc_swab32s(upx_uint32_t *p)
|
||||
{
|
||||
*p = (acc_uint32e_t) acc_swab32(*p);
|
||||
*p = (upx_uint32_t) acc_swab32(*p);
|
||||
}
|
||||
|
||||
|
||||
@@ -359,20 +359,20 @@ __packed_struct(BE64)
|
||||
unsigned char d[8];
|
||||
|
||||
//inline BE64() { }
|
||||
//BE64(acc_uint64l_t v) { set_be64(d, v); }
|
||||
//BE64(upx_uint64_t v) { set_be64(d, v); }
|
||||
|
||||
BE64& operator = (acc_uint64l_t v) { set_be64(d, v); return *this; }
|
||||
BE64& operator += (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 = (upx_uint64_t v) { set_be64(d, v); return *this; }
|
||||
BE64& operator += (upx_uint64_t v) { set_be64(d, get_be64(d) + v); return *this; }
|
||||
BE64& operator -= (upx_uint64_t v) { set_be64(d, get_be64(d) - v); return *this; }
|
||||
BE64& operator *= (upx_uint64_t v) { set_be64(d, get_be64(d) * v); return *this; }
|
||||
BE64& operator /= (upx_uint64_t v) { set_be64(d, get_be64(d) / v); return *this; }
|
||||
BE64& operator &= (upx_uint64_t v) { set_be64(d, get_be64(d) & v); return *this; }
|
||||
BE64& operator |= (upx_uint64_t v) { set_be64(d, get_be64(d) | v); return *this; }
|
||||
BE64& operator ^= (upx_uint64_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
|
||||
BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; }
|
||||
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_be64(d); }
|
||||
operator upx_uint64_t () const { return get_be64(d); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
@@ -422,20 +422,20 @@ __packed_struct(LE64)
|
||||
unsigned char d[8];
|
||||
|
||||
//inline LE64() { }
|
||||
//LE64(acc_uint64l_t v) { set_le64(d, v); }
|
||||
//LE64(upx_uint64_t v) { set_le64(d, v); }
|
||||
|
||||
LE64& operator = (acc_uint64l_t v) { set_le64(d, v); return *this; }
|
||||
LE64& operator += (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 = (upx_uint64_t v) { set_le64(d, v); return *this; }
|
||||
LE64& operator += (upx_uint64_t v) { set_le64(d, get_le64(d) + v); return *this; }
|
||||
LE64& operator -= (upx_uint64_t v) { set_le64(d, get_le64(d) - v); return *this; }
|
||||
LE64& operator *= (upx_uint64_t v) { set_le64(d, get_le64(d) * v); return *this; }
|
||||
LE64& operator /= (upx_uint64_t v) { set_le64(d, get_le64(d) / v); return *this; }
|
||||
LE64& operator &= (upx_uint64_t v) { set_le64(d, get_le64(d) & v); return *this; }
|
||||
LE64& operator |= (upx_uint64_t v) { set_le64(d, get_le64(d) | v); return *this; }
|
||||
LE64& operator ^= (upx_uint64_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
|
||||
LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; }
|
||||
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_le64(d); }
|
||||
operator upx_uint64_t () const { return get_le64(d); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
@@ -545,8 +545,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
// just for testing...
|
||||
#if !(ACC_CFG_NO_UNALIGNED)
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200)
|
||||
typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
typedef upx_uint16_t LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef upx_uint32_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
@@ -555,8 +555,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint16_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint32_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
@@ -565,8 +565,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint16_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint32_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
|
||||
+14
-14
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -61,17 +61,17 @@ struct AbstractPolicy
|
||||
V unsigned get16(const void *p) C = 0;
|
||||
V unsigned get24(const void *p) C = 0;
|
||||
V unsigned get32(const void *p) C = 0;
|
||||
V acc_uint64l_t get64(const void *p) C = 0;
|
||||
V upx_uint64_t get64(const void *p) C = 0;
|
||||
|
||||
V void set16(void *p, unsigned v) C = 0;
|
||||
V void set24(void *p, unsigned v) C = 0;
|
||||
V void set32(void *p, unsigned v) C = 0;
|
||||
V void set64(void *p, acc_uint64l_t v) C = 0;
|
||||
V void set64(void *p, upx_uint64_t v) C = 0;
|
||||
|
||||
V unsigned get16_signed(const void *p) C = 0;
|
||||
V unsigned get24_signed(const void *p) C = 0;
|
||||
V unsigned get32_signed(const void *p) C = 0;
|
||||
V acc_uint64l_t get64_signed(const void *p) C = 0;
|
||||
V upx_uint64_t get64_signed(const void *p) C = 0;
|
||||
|
||||
S u16_compare(const void *a, const void *b) C = 0;
|
||||
S u24_compare(const void *a, const void *b) C = 0;
|
||||
@@ -113,7 +113,7 @@ struct BEPolicy
|
||||
{ return get_be24(p); }
|
||||
V unsigned get32(const void *p) C
|
||||
{ return get_be32(p); }
|
||||
V acc_uint64l_t get64(const void *p) C
|
||||
V upx_uint64_t get64(const void *p) C
|
||||
{ return get_be64(p); }
|
||||
|
||||
V void set16(void *p, unsigned v) C
|
||||
@@ -122,7 +122,7 @@ struct BEPolicy
|
||||
{ set_be24(p, v); }
|
||||
V void set32(void *p, unsigned v) C
|
||||
{ set_be32(p, v); }
|
||||
V void set64(void *p, acc_uint64l_t v) C
|
||||
V void set64(void *p, upx_uint64_t v) C
|
||||
{ set_be64(p, v); }
|
||||
|
||||
V unsigned get16_signed(const void *p) C
|
||||
@@ -131,7 +131,7 @@ struct BEPolicy
|
||||
{ return get_be24_signed(p); }
|
||||
V unsigned get32_signed(const void *p) C
|
||||
{ return get_be32_signed(p); }
|
||||
V acc_uint64l_t get64_signed(const void *p) C
|
||||
V upx_uint64_t get64_signed(const void *p) C
|
||||
{ return get_be64_signed(p); }
|
||||
|
||||
S u16_compare(const void *a, const void *b) C
|
||||
@@ -190,7 +190,7 @@ struct LEPolicy
|
||||
{ return get_le24(p); }
|
||||
V unsigned get32(const void *p) C
|
||||
{ return get_le32(p); }
|
||||
V acc_uint64l_t get64(const void *p) C
|
||||
V upx_uint64_t get64(const void *p) C
|
||||
{ return get_le64(p); }
|
||||
|
||||
V void set16(void *p, unsigned v) C
|
||||
@@ -199,7 +199,7 @@ struct LEPolicy
|
||||
{ set_le24(p, v); }
|
||||
V void set32(void *p, unsigned v) C
|
||||
{ set_le32(p, v); }
|
||||
V void set64(void *p, acc_uint64l_t v) C
|
||||
V void set64(void *p, upx_uint64_t v) C
|
||||
{ set_le64(p, v); }
|
||||
|
||||
V unsigned get16_signed(const void *p) C
|
||||
@@ -208,7 +208,7 @@ struct LEPolicy
|
||||
{ return get_le24_signed(p); }
|
||||
V unsigned get32_signed(const void *p) C
|
||||
{ return get_le32_signed(p); }
|
||||
V acc_uint64l_t get64_signed(const void *p) C
|
||||
V upx_uint64_t get64_signed(const void *p) C
|
||||
{ return get_le64_signed(p); }
|
||||
|
||||
S u16_compare(const void *a, const void *b) C
|
||||
@@ -259,9 +259,9 @@ struct HostAlignedPolicy
|
||||
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
|
||||
#endif
|
||||
|
||||
typedef acc_uint16e_t U16;
|
||||
typedef acc_uint32e_t U32;
|
||||
typedef acc_uint64l_t U64;
|
||||
typedef upx_uint16_t U16;
|
||||
typedef upx_uint32_t U32;
|
||||
typedef upx_uint64_t U64;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -230,6 +230,7 @@ error:
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#define _7ZIP_ST 1
|
||||
#define kLiteralNextStates kLiteralNextStates_enc
|
||||
#include "C/LzmaEnc.h"
|
||||
#include "C/LzmaEnc.c"
|
||||
@@ -352,6 +353,7 @@ namespace MyLzma {
|
||||
|
||||
struct InStream: public ISequentialInStream, public CMyUnknownImp
|
||||
{
|
||||
virtual ~InStream() { }
|
||||
MY_UNKNOWN_IMP
|
||||
const Byte *b_buf; size_t b_size; size_t b_pos;
|
||||
void Init(const Byte *data, size_t size) {
|
||||
@@ -372,6 +374,7 @@ STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
|
||||
struct OutStream : public ISequentialOutStream, public CMyUnknownImp
|
||||
{
|
||||
virtual ~OutStream() { }
|
||||
MY_UNKNOWN_IMP
|
||||
Byte *b_buf; size_t b_size; size_t b_pos; bool overflow;
|
||||
void Init(Byte *data, size_t size) {
|
||||
@@ -397,6 +400,7 @@ STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSi
|
||||
|
||||
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
|
||||
{
|
||||
virtual ~ProgressInfo() { }
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
|
||||
upx_callback_p cb;
|
||||
@@ -412,7 +416,7 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
|
||||
} // namespace
|
||||
|
||||
|
||||
#if (ACC_CC_INTELC) && defined(__linux__)
|
||||
#if (ACC_CC_INTELC_GNUC)
|
||||
# pragma warning(disable: 424) // #424: extra ";" ignored
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -34,7 +34,7 @@ int compress_ucl_dummy = 0;
|
||||
#else
|
||||
|
||||
#if 1 && !(UCL_USE_ASM) && (ACC_ARCH_I386)
|
||||
# if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
|
||||
# if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
|
||||
# define UCL_USE_ASM 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+31
-17
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -149,6 +149,23 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* intergral types */
|
||||
typedef acc_int8_t upx_int8_t;
|
||||
typedef acc_uint8_t upx_uint8_t;
|
||||
typedef acc_int16_t upx_int16_t;
|
||||
typedef acc_uint16_t upx_uint16_t;
|
||||
typedef acc_int32_t upx_int32_t;
|
||||
typedef acc_uint32_t upx_uint32_t;
|
||||
typedef acc_int64_t upx_int64_t;
|
||||
typedef acc_uint64_t upx_uint64_t;
|
||||
typedef acc_uintptr_t upx_uintptr_t;
|
||||
#define UPX_INT16_C ACC_INT16_C
|
||||
#define UPX_UINT16_C ACC_UINT16_C
|
||||
#define UPX_INT32_C ACC_INT32_C
|
||||
#define UPX_UINT32_C ACC_UINT32_C
|
||||
#define UPX_INT64_C ACC_INT64_C
|
||||
#define UPX_UINT64_C ACC_UINT64_C
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
@@ -222,19 +239,14 @@
|
||||
#if (WITH_VALGRIND)
|
||||
# include <valgrind/memcheck.h>
|
||||
#endif
|
||||
|
||||
#if !defined(VALGRIND_MAKE_WRITABLE)
|
||||
# define VALGRIND_MAKE_WRITABLE(addr,len) 0
|
||||
#if !defined(VALGRIND_MAKE_MEM_DEFINED)
|
||||
# define VALGRIND_MAKE_MEM_DEFINED(addr,len) 0
|
||||
#endif
|
||||
#if !defined(VALGRIND_MAKE_READABLE)
|
||||
# if 0
|
||||
# define VALGRIND_MAKE_READABLE(addr,len) (memset(addr,0,len), 0)
|
||||
# else
|
||||
# define VALGRIND_MAKE_READABLE(addr,len) 0
|
||||
# endif
|
||||
#if !defined(VALGRIND_MAKE_MEM_NOACCESS)
|
||||
# define VALGRIND_MAKE_MEM_NOACCESS(addr,len) 0
|
||||
#endif
|
||||
#if !defined(VALGRIND_DISCARD)
|
||||
# define VALGRIND_DISCARD(handle) ((void)(&handle))
|
||||
#if !defined(VALGRIND_MAKE_MEM_UNDEFINED)
|
||||
# define VALGRIND_MAKE_MEM_UNDEFINED(addr,len) 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -326,7 +338,7 @@
|
||||
|
||||
#if (ACC_CC_INTELC && (__INTEL_COMPILER < 800))
|
||||
#elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
|
||||
#elif (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||
#elif (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC_GNUC || ACC_CC_PATHSCALE)
|
||||
# define __packed_struct(s) struct s {
|
||||
# define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
@@ -492,6 +504,8 @@ private:
|
||||
#define UPX_F_MACH_AMD64 34
|
||||
#define UPX_F_DYLIB_AMD64 35
|
||||
|
||||
#define UPX_F_WIN64_PEP 36
|
||||
|
||||
#define UPX_F_PLAIN_TEXT 127
|
||||
|
||||
#define UPX_F_ATARI_TOS 129
|
||||
@@ -752,7 +766,7 @@ typedef ElfLinker Linker;
|
||||
// main.cpp
|
||||
extern const char *progname;
|
||||
bool set_ec(int ec);
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
#if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void e_exit(int ec) __attribute__((__noreturn__));
|
||||
#else
|
||||
void e_exit(int ec);
|
||||
@@ -764,7 +778,7 @@ void printSetNl(int need_nl);
|
||||
void printClearLine(FILE *f = NULL);
|
||||
void printErr(const char *iname, const Throwable *e);
|
||||
void printUnhandledException(const char *iname, const std::exception *e);
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
#if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(__printf__,2,3)));
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||
@@ -774,7 +788,7 @@ void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
#if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+6
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -33,7 +33,7 @@
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
long Throwable::counter = 0;
|
||||
unsigned long Throwable::counter = 0;
|
||||
|
||||
Throwable::Throwable(const char *m, int e, bool w) NOTHROW
|
||||
: super(), msg(NULL), err(e), is_warning(w)
|
||||
@@ -41,7 +41,7 @@ Throwable::Throwable(const char *m, int e, bool w) NOTHROW
|
||||
if (m)
|
||||
msg = strdup(m);
|
||||
#if 0
|
||||
fprintf(stderr, "construct exception: %s %ld\n", msg, counter);
|
||||
fprintf(stderr, "construct exception: %s %lu\n", msg, counter);
|
||||
counter++;
|
||||
#endif
|
||||
}
|
||||
@@ -53,7 +53,7 @@ Throwable::Throwable(const Throwable &other) NOTHROW
|
||||
if (other.msg)
|
||||
msg = strdup(other.msg);
|
||||
#if 0
|
||||
fprintf(stderr, "copy exception: %s %ld\n", msg, counter);
|
||||
fprintf(stderr, "copy exception: %s %lu\n", msg, counter);
|
||||
counter++;
|
||||
#endif
|
||||
}
|
||||
@@ -63,7 +63,7 @@ Throwable::~Throwable() NOTHROW
|
||||
{
|
||||
#if 0
|
||||
counter--;
|
||||
fprintf(stderr, "destruct exception: %s %ld\n", msg, counter);
|
||||
fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
|
||||
#endif
|
||||
if (msg)
|
||||
free(msg);
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
DISABLE_NEW_DELETE
|
||||
|
||||
private:
|
||||
static long counter; // for debugging
|
||||
static unsigned long counter; // for debugging
|
||||
};
|
||||
|
||||
|
||||
|
||||
+13
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -410,6 +410,17 @@ void OutputFile::seek(off_t off, int whence)
|
||||
super::seek(off,whence);
|
||||
}
|
||||
|
||||
// WARNING: fsync() does not exist in some Windows environments.
|
||||
// This trick works only on UNIX-like systems.
|
||||
//int OutputFile::read(void *buf, int len)
|
||||
//{
|
||||
// fsync(_fd);
|
||||
// InputFile infile;
|
||||
// infile.open(this->getName(), O_RDONLY);
|
||||
// infile.seek(this->tell(), SEEK_SET);
|
||||
// return infile.read(buf, len);
|
||||
//}
|
||||
|
||||
void OutputFile::set_extent(off_t offset, off_t length)
|
||||
{
|
||||
super::set_extent(offset, length);
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2004-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2004-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -98,7 +98,7 @@ static int F(Filter *f)
|
||||
}
|
||||
else {
|
||||
#if (W_CTO != 0)
|
||||
assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != (unsigned) cto8); // this should not happen
|
||||
#endif
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
@@ -133,7 +133,7 @@ static int U(Filter *f)
|
||||
|
||||
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) {
|
||||
if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == (unsigned) f->cto) {
|
||||
unsigned const jc = word & (~(~0u<<(26 - W_CTO)) & (~0u<<2));
|
||||
set_be32(b+ic, (0xfc000003&word)|(0x03fffffc&(jc-ic-addvalue)));
|
||||
f->calls++;
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+11
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -290,6 +290,11 @@ void show_help(int verbose)
|
||||
" --strip-relocs=0 do not strip relocations\n"
|
||||
" --strip-relocs=1 strip relocations [default]\n"
|
||||
"\n");
|
||||
con_fprintf(f,"Options for linux/elf:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --preserve-build-id copy .gnu.note.build-id to compressed output\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
con_fprintf(f, "file.. executables to (de)compress\n");
|
||||
@@ -400,10 +405,10 @@ void show_version(int x)
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "LZMA SDK version %s\n", v);
|
||||
#endif
|
||||
fprintf(fp, "Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(fp, "Copyright (C) 1996-2010 Laszlo Molnar\n");
|
||||
fprintf(fp, "Copyright (C) 2000-2010 John F. Reiser\n");
|
||||
fprintf(fp, "Copyright (C) 2002-2010 Jens Medoch\n");
|
||||
fprintf(fp, "Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(fp, "Copyright (C) 1996-2013 Laszlo Molnar\n");
|
||||
fprintf(fp, "Copyright (C) 2000-2013 John F. Reiser\n");
|
||||
fprintf(fp, "Copyright (C) 2002-2013 Jens Medoch\n");
|
||||
#if (WITH_ZLIB)
|
||||
fprintf(fp, "Copyright (C) 1995" "-2005 Jean-loup Gailly and Mark Adler\n");
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+83
-95
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -45,6 +45,18 @@ static bool update_capacity(unsigned size, unsigned *capacity)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __acc_cdecl_va internal_error(const char *format, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, sizeof(buf), format, ap);
|
||||
va_end(ap);
|
||||
|
||||
throwInternalError(buf);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Section
|
||||
@@ -72,7 +84,7 @@ ElfLinker::Section::~Section()
|
||||
// Symbol
|
||||
**************************************************************************/
|
||||
|
||||
ElfLinker::Symbol::Symbol(const char *n, Section *s, unsigned o) :
|
||||
ElfLinker::Symbol::Symbol(const char *n, Section *s, upx_uint64_t o) :
|
||||
name(NULL), section(s), offset(o)
|
||||
{
|
||||
name = strdup(n);
|
||||
@@ -91,7 +103,7 @@ ElfLinker::Symbol::~Symbol()
|
||||
**************************************************************************/
|
||||
|
||||
ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t,
|
||||
const Symbol *v, unsigned a) :
|
||||
const Symbol *v, upx_uint64_t a) :
|
||||
section(s), offset(o), type(t), value(v), add(a)
|
||||
{
|
||||
assert(section != NULL);
|
||||
@@ -282,29 +294,28 @@ void ElfLinker::preprocessRelocations(char *start, char *end)
|
||||
char *t = strstr(start, type);
|
||||
t[strlen(type)] = 0;
|
||||
|
||||
unsigned add = 0;
|
||||
if (char *p = strstr(symbol, "+0x"))
|
||||
upx_uint64_t add = 0;
|
||||
char *p = strstr(symbol, "+0x");
|
||||
if (p == NULL)
|
||||
p = strstr(symbol, "-0x");
|
||||
if (p)
|
||||
{
|
||||
char sign = *p;
|
||||
*p = 0; // terminate the symbol name
|
||||
p += 3;
|
||||
|
||||
if (strlen(p) == 16) {
|
||||
// skip 8 leading chars if sign of char 9 matches
|
||||
if (memcmp(p, "000000000", 9))
|
||||
p += 8;
|
||||
else if (memcmp(p, "fffffffff", 9))
|
||||
p += 8;
|
||||
}
|
||||
assert(strlen(p) == 8);
|
||||
assert(strlen(p) == 8 || strlen(p) == 16);
|
||||
char *endptr = NULL;
|
||||
unsigned long ul = strtoul(p, &endptr, 16);
|
||||
add = (unsigned) ul;
|
||||
assert(add == ul);
|
||||
upx_uint64_t ull = strtoull(p, &endptr, 16);
|
||||
add = (upx_uint64_t) ull;
|
||||
assert(add == ull);
|
||||
assert(endptr && *endptr == '\0');
|
||||
if (sign == '-')
|
||||
add = -add;
|
||||
}
|
||||
|
||||
addRelocation(section->name, offset, t, symbol, add);
|
||||
//printf("relocation %s %s %x %d preprocessed\n", section->name, symbol, offset, add);
|
||||
//printf("relocation %s %s %x %llu preprocessed\n", section->name, symbol, offset, (unsigned long long) add);
|
||||
}
|
||||
|
||||
start = nextl + 1;
|
||||
@@ -317,10 +328,7 @@ ElfLinker::Section *ElfLinker::findSection(const char *name, bool fatal) const
|
||||
if (strcmp(sections[ic]->name, name) == 0)
|
||||
return sections[ic];
|
||||
if (fatal)
|
||||
{
|
||||
printf("unknown section %s\n", name);
|
||||
abort();
|
||||
}
|
||||
internal_error("unknown section %s\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -330,10 +338,7 @@ ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const
|
||||
if (strcmp(symbols[ic]->name, name) == 0)
|
||||
return symbols[ic];
|
||||
if (fatal)
|
||||
{
|
||||
printf("unknown symbol %s\n", name);
|
||||
abort();
|
||||
}
|
||||
internal_error("unknown symbol %s\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -351,7 +356,7 @@ ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata,
|
||||
}
|
||||
|
||||
ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
|
||||
unsigned offset)
|
||||
upx_uint64_t offset)
|
||||
{
|
||||
//printf("addSymbol: %s %s 0x%x\n", name, section, offset);
|
||||
if (update_capacity(nsymbols, &nsymbols_capacity))
|
||||
@@ -366,7 +371,7 @@ ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
|
||||
|
||||
ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned off,
|
||||
const char *type, const char *symbol,
|
||||
unsigned add)
|
||||
upx_uint64_t add)
|
||||
{
|
||||
if (update_capacity(nrelocations, &nrelocations_capacity))
|
||||
relocations = static_cast<Relocation **>(realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *)));
|
||||
@@ -492,7 +497,7 @@ void ElfLinker::relocate()
|
||||
for (unsigned ic = 0; ic < nrelocations; ic++)
|
||||
{
|
||||
const Relocation *rel = relocations[ic];
|
||||
unsigned value;
|
||||
upx_uint64_t value = 0;
|
||||
|
||||
if (rel->section->output == NULL)
|
||||
continue;
|
||||
@@ -502,37 +507,28 @@ void ElfLinker::relocate()
|
||||
}
|
||||
else if (strcmp(rel->value->section->name, "*UND*") == 0 &&
|
||||
rel->value->offset == 0xdeaddead)
|
||||
{
|
||||
printf("undefined symbol '%s' referenced\n", rel->value->name);
|
||||
abort();
|
||||
}
|
||||
internal_error("undefined symbol '%s' referenced\n", rel->value->name);
|
||||
else if (rel->value->section->output == NULL)
|
||||
{
|
||||
printf("can not apply reloc '%s:%x' without section '%s'\n",
|
||||
rel->section->name, rel->offset,
|
||||
rel->value->section->name);
|
||||
abort();
|
||||
}
|
||||
internal_error("can not apply reloc '%s:%x' without section '%s'\n",
|
||||
rel->section->name, rel->offset,
|
||||
rel->value->section->name);
|
||||
else
|
||||
{
|
||||
value = rel->value->section->offset +
|
||||
rel->value->offset + rel->add;
|
||||
}
|
||||
upx_byte *location = rel->section->output + rel->offset;
|
||||
//printf("%-28s %-28s %-10s 0x%08x 0x%08x\n", rel->section->name, rel->value->name, rel->type, value, value - rel->section->offset - rel->offset);
|
||||
//printf(" %d %d %d %d %d : %d\n", value, rel->value->section->offset, rel->value->offset, rel->offset, rel->add, *location);
|
||||
//printf("%-28s %-28s %-10s 0x%16llx 0x%16llx\n", rel->section->name, rel->value->name, rel->type, (long long) value, (long long) value - rel->section->offset - rel->offset);
|
||||
//printf(" %llx %d %llx %d %llx : %d\n", (long long) value, rel->value->section->offset, rel->value->offset, rel->offset, (long long) rel->add, *location);
|
||||
relocate1(rel, location, value, rel->type);
|
||||
}
|
||||
}
|
||||
|
||||
void ElfLinker::defineSymbol(const char *name, unsigned value)
|
||||
void ElfLinker::defineSymbol(const char *name, upx_uint64_t value)
|
||||
{
|
||||
Symbol *symbol = findSymbol(name);
|
||||
if (strcmp(symbol->section->name, "*ABS*") == 0)
|
||||
{
|
||||
printf("defineSymbol: symbol '%s' is *ABS*\n", name);
|
||||
abort();
|
||||
}
|
||||
internal_error("defineSymbol: symbol '%s' is *ABS*\n", name);
|
||||
else if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols
|
||||
symbol->offset = value;
|
||||
else if (strcmp(symbol->section->name, name) == 0) // for sections
|
||||
@@ -545,10 +541,7 @@ void ElfLinker::defineSymbol(const char *name, unsigned value)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("defineSymbol: symbol '%s' already defined\n", name);
|
||||
abort();
|
||||
}
|
||||
internal_error("defineSymbol: symbol '%s' already defined\n", name);
|
||||
}
|
||||
|
||||
// debugging support
|
||||
@@ -556,8 +549,11 @@ void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const
|
||||
{
|
||||
if ((flags & 1) && symbol->section->output == NULL)
|
||||
return;
|
||||
fprintf(fp, "%-28s 0x%08x | %-28s 0x%08x\n",
|
||||
symbol->name, symbol->offset, symbol->section->name, symbol->section->offset);
|
||||
char d0[16+1], d1[16+1];
|
||||
upx_snprintf(d0, sizeof(d0), "%016llx", (upx_uint64_t) symbol->offset);
|
||||
upx_snprintf(d1, sizeof(d1), "%016llx", (upx_uint64_t) symbol->section->offset);
|
||||
fprintf(fp, "%-28s 0x%-16s | %-28s 0x%-16s\n",
|
||||
symbol->name, d0, symbol->section->name, d1);
|
||||
}
|
||||
void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
|
||||
{
|
||||
@@ -568,7 +564,9 @@ void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
|
||||
// default: dump symbols in used section order
|
||||
for (const Section *section = head; section; section = section->next)
|
||||
{
|
||||
fprintf(fp, "%-42s%-28s 0x%08x\n", "", section->name, section->offset);
|
||||
char d1[16+1];
|
||||
upx_snprintf(d1, sizeof(d1), "%016llx", (upx_uint64_t) section->offset);
|
||||
fprintf(fp, "%-42s%-28s 0x%-16s\n", "", section->name, d1);
|
||||
for (unsigned ic = 0; ic < nsymbols; ic++)
|
||||
{
|
||||
const Symbol *symbol = symbols[ic];
|
||||
@@ -585,7 +583,7 @@ void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
|
||||
}
|
||||
}
|
||||
|
||||
unsigned ElfLinker::getSymbolOffset(const char *name) const
|
||||
upx_uint64_t ElfLinker::getSymbolOffset(const char *name) const
|
||||
{
|
||||
const Symbol *symbol = findSymbol(name);
|
||||
if (symbol->section->output == NULL)
|
||||
@@ -600,10 +598,9 @@ void ElfLinker::alignWithByte(unsigned len, unsigned char b)
|
||||
}
|
||||
|
||||
void ElfLinker::relocate1(const Relocation *rel, upx_byte *,
|
||||
unsigned, const char *)
|
||||
upx_uint64_t, const char *)
|
||||
{
|
||||
printf("unknown relocation type '%s\n", rel->type);
|
||||
abort();
|
||||
internal_error("unknown relocation type '%s\n", rel->type);
|
||||
}
|
||||
|
||||
|
||||
@@ -616,31 +613,29 @@ void ElfLinker::relocate1(const Relocation *rel, upx_byte *,
|
||||
#if 0 // FIXME
|
||||
static void check8(const Relocation *rel, const upx_byte *location, int v, int d)
|
||||
{
|
||||
if (v < -128 || v > 127) {
|
||||
printf("value out of range (%d) in reloc %s:%x\n",
|
||||
v, rel->section->name, rel->offset);
|
||||
abort();
|
||||
}
|
||||
if (d < -128 || d > 127) {
|
||||
printf("displacement target out of range (%d) in reloc %s:%x\n",
|
||||
v, rel->section->name, rel->offset);
|
||||
abort();
|
||||
}
|
||||
if (v < -128 || v > 127)
|
||||
internal_error("value out of range (%d) in reloc %s:%x\n",
|
||||
v, rel->section->name, rel->offset);
|
||||
if (d < -128 || d > 127)
|
||||
internal_error("displacement target out of range (%d) in reloc %s:%x\n",
|
||||
v, rel->section->name, rel->offset);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_X86_64_", 9))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
type += 9;
|
||||
|
||||
bool range_check = false;
|
||||
if (strncmp(type, "PC", 2) == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
type += 2;
|
||||
range_check = true;
|
||||
}
|
||||
|
||||
if (strcmp(type, "8") == 0)
|
||||
@@ -650,25 +645,24 @@ void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location,
|
||||
#else
|
||||
int displ = (signed char) *location + (int) value;
|
||||
#endif
|
||||
if (displ < -128 || displ > 127)
|
||||
{
|
||||
printf("target out of range (%d) in reloc %s:%x\n",
|
||||
displ, rel->section->name, rel->offset);
|
||||
abort();
|
||||
}
|
||||
if (range_check && (displ < -128 || displ > 127))
|
||||
internal_error("target out of range (%d) in reloc %s:%x\n",
|
||||
displ, rel->section->name, rel->offset);
|
||||
*location += value;
|
||||
}
|
||||
else if (strcmp(type, "16") == 0)
|
||||
set_le16(location, get_le16(location) + value);
|
||||
else if (strcmp(type, "32") == 0)
|
||||
else if (strncmp(type, "32", 2) == 0) // for "32" and "32S"
|
||||
set_le32(location, get_le32(location) + value);
|
||||
else if (strcmp(type, "64") == 0)
|
||||
set_le64(location, get_le64(location) + value);
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strcmp(type, "R_ARM_PC24") == 0)
|
||||
{
|
||||
@@ -703,7 +697,7 @@ void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
|
||||
void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strcmp(type, "R_ARM_PC24") == 0)
|
||||
{
|
||||
@@ -747,7 +741,7 @@ void ElfLinkerM68k::alignCode(unsigned len)
|
||||
}
|
||||
|
||||
void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_68K_", 6))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
@@ -773,7 +767,7 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
|
||||
void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
|
||||
#define MIPS_LO(a) ((a) & 0xffff)
|
||||
@@ -804,7 +798,7 @@ void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
|
||||
void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
|
||||
#define MIPS_LO(a) ((a) & 0xffff)
|
||||
@@ -835,7 +829,7 @@ void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
|
||||
void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_PPC_", 6))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
@@ -857,19 +851,15 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
// Note that original (*location).displ is ignored.
|
||||
if (strcmp(type, "24") == 0) {
|
||||
if (3& value) {
|
||||
printf("unaligned word diplacement");
|
||||
abort();
|
||||
}
|
||||
if (3& value)
|
||||
internal_error("unaligned word diplacement");
|
||||
// FIXME: displacment overflow?
|
||||
set_be32(location, (0xfc000003 & get_be32(location)) +
|
||||
(0x03fffffc & value));
|
||||
}
|
||||
else if (strcmp(type, "14") == 0) {
|
||||
if (3& value) {
|
||||
printf("unaligned word diplacement");
|
||||
abort();
|
||||
}
|
||||
if (3& value)
|
||||
internal_error("unaligned word diplacement");
|
||||
// FIXME: displacment overflow?
|
||||
set_be32(location, (0xffff0003 & get_be32(location)) +
|
||||
(0x0000fffc & value));
|
||||
@@ -880,7 +870,7 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
|
||||
void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_386_", 6))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
@@ -901,11 +891,9 @@ void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location,
|
||||
#else
|
||||
int displ = (signed char) *location + (int) value;
|
||||
#endif
|
||||
if (range_check && (displ < -128 || displ > 127)) {
|
||||
printf("target out of range (%d,%d,%d) in reloc %s:%x\n",
|
||||
displ, *location, value, rel->section->name, rel->offset);
|
||||
abort();
|
||||
}
|
||||
if (range_check && (displ < -128 || displ > 127))
|
||||
internal_error("target out of range (%d,%d,%d) in reloc %s:%x\n",
|
||||
displ, *location, value, rel->section->name, rel->offset);
|
||||
*location += value;
|
||||
}
|
||||
else if (strcmp(type, "16") == 0)
|
||||
|
||||
+27
-27
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -72,9 +72,9 @@ protected:
|
||||
Section *findSection(const char *name, bool fatal=true) const;
|
||||
Symbol *findSymbol(const char *name, bool fatal=true) const;
|
||||
|
||||
Symbol *addSymbol(const char *name, const char *section, unsigned offset);
|
||||
Symbol *addSymbol(const char *name, const char *section, upx_uint64_t offset);
|
||||
Relocation *addRelocation(const char *section, unsigned off, const char *type,
|
||||
const char *symbol, unsigned add);
|
||||
const char *symbol, upx_uint64_t add);
|
||||
|
||||
public:
|
||||
ElfLinker();
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
//virtual void setLoaderAlignOffset(int phase);
|
||||
virtual int addLoader(const char *sname);
|
||||
void addLoader(const char *s, va_list ap);
|
||||
#if 1 && (ACC_CC_GNUC >= 0x040100)
|
||||
#if 1 && (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x040100))
|
||||
void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__));
|
||||
#else
|
||||
void __acc_cdecl_va addLoaderVA(const char *s, ...);
|
||||
@@ -93,8 +93,8 @@ public:
|
||||
virtual int getSection(const char *sname, int *slen=NULL) const;
|
||||
virtual int getSectionSize(const char *sname) const;
|
||||
virtual upx_byte *getLoader(int *llen=NULL) const;
|
||||
virtual void defineSymbol(const char *name, unsigned value);
|
||||
virtual unsigned getSymbolOffset(const char *) const;
|
||||
virtual void defineSymbol(const char *name, upx_uint64_t value);
|
||||
virtual upx_uint64_t getSymbolOffset(const char *) const;
|
||||
|
||||
virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const;
|
||||
virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const;
|
||||
@@ -106,15 +106,15 @@ public:
|
||||
protected:
|
||||
virtual void relocate();
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
|
||||
// target endianness abstraction
|
||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||
unsigned get_te32(const void *p) const { return bele->get32(p); }
|
||||
acc_uint64l_t get_te64(const void *p) const { return bele->get64(p); }
|
||||
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
||||
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
|
||||
void set_te64(void *p, acc_uint64l_t v) const { bele->set64(p, v); }
|
||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||
unsigned get_te32(const void *p) const { return bele->get32(p); }
|
||||
upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
|
||||
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
||||
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
|
||||
void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
|
||||
};
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ struct ElfLinker::Section : private noncopyable
|
||||
void *input;
|
||||
upx_byte *output;
|
||||
unsigned size;
|
||||
unsigned offset;
|
||||
upx_uint64_t offset;
|
||||
unsigned p2align; // log2
|
||||
Section *next;
|
||||
|
||||
@@ -137,9 +137,9 @@ struct ElfLinker::Symbol : private noncopyable
|
||||
{
|
||||
char *name;
|
||||
Section *section;
|
||||
unsigned offset;
|
||||
upx_uint64_t offset;
|
||||
|
||||
Symbol(const char *n, Section *s, unsigned o);
|
||||
Symbol(const char *n, Section *s, upx_uint64_t o);
|
||||
~Symbol();
|
||||
};
|
||||
|
||||
@@ -150,10 +150,10 @@ struct ElfLinker::Relocation : private noncopyable
|
||||
unsigned offset;
|
||||
const char *type;
|
||||
const Symbol *value;
|
||||
unsigned add; // used in .rela relocations
|
||||
upx_uint64_t add; // used in .rela relocations
|
||||
|
||||
Relocation(const Section *s, unsigned o, const char *t,
|
||||
const Symbol *v, unsigned a);
|
||||
const Symbol *v, upx_uint64_t a);
|
||||
};
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ class ElfLinkerAMD64 : public ElfLinker
|
||||
protected:
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ public:
|
||||
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ class ElfLinkerArmLE : public ElfLinker
|
||||
typedef ElfLinker super;
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
protected:
|
||||
virtual void alignCode(unsigned len);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ public:
|
||||
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ class ElfLinkerMipsLE : public ElfLinker
|
||||
typedef ElfLinker super;
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ public:
|
||||
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ class ElfLinkerX86 : public ElfLinker
|
||||
protected:
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+16
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -898,6 +898,9 @@ static int do_option(int optc, const char *arg)
|
||||
case 674:
|
||||
opt->o_unix.unmap_all_pages = true; // val ?
|
||||
break;
|
||||
case 675:
|
||||
opt->o_unix.preserve_build_id = true;
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
return -1;
|
||||
@@ -1048,6 +1051,7 @@ static const struct mfx_option longopts[] =
|
||||
{"OpenBSD", 0x10, 0, 669},
|
||||
{"openbsd", 0x10, 0, 669},
|
||||
{"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes
|
||||
{"preserve-build-id", 0, 0, 675},
|
||||
// watcom/le
|
||||
{"le", 0x10, 0, 620}, // produce LE output
|
||||
// win32/pe
|
||||
@@ -1285,9 +1289,13 @@ static bool test(void)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(test2_t)
|
||||
COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21*sizeof(T))
|
||||
#if defined(__acc_alignof)
|
||||
#if (ACC_CC_CLANG && ACC_ARCH_AMD64)
|
||||
// CBUG: clang-2.8 bug in 64-bit mode
|
||||
#else
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1)
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1)
|
||||
#endif
|
||||
#endif
|
||||
#if 1 && (ACC_CC_WATCOMC)
|
||||
test1_t t11; COMPILE_TIME_ASSERT(sizeof(t11.a) <= sizeof(t11.b))
|
||||
test2_t t22; COMPILE_TIME_ASSERT(sizeof(t22.a) <= sizeof(t22.b))
|
||||
@@ -1366,7 +1374,7 @@ void upx_sanity_check(void)
|
||||
assert(TestBELE<BE64>::test());
|
||||
{
|
||||
static const unsigned char dd[32]
|
||||
#if 1 && (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__)
|
||||
#if 1 && (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__)
|
||||
__attribute__((__aligned__(16)))
|
||||
#endif
|
||||
= { 0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -1400,7 +1408,7 @@ void upx_sanity_check(void)
|
||||
assert(get_le32(d) == 0xfcfdfeff);
|
||||
assert(bele->get32(d) == 0xfcfdfeff);
|
||||
assert(get_le32_signed(d) == -50462977);
|
||||
assert(get_le64_signed(d) == ACC_INT64_C(-506097522914230529));
|
||||
assert(get_le64_signed(d) == UPX_INT64_C(-506097522914230529));
|
||||
assert(find_be16(d, 2, 0xfffe) == 0);
|
||||
assert(find_le16(d, 2, 0xfeff) == 0);
|
||||
assert(find_be32(d, 4, 0xfffefdfc) == 0);
|
||||
@@ -1409,7 +1417,7 @@ void upx_sanity_check(void)
|
||||
assert(get_be16_signed(d) == 32638);
|
||||
assert(get_be24_signed(d) == 8355453);
|
||||
assert(get_be32_signed(d) == 2138996092);
|
||||
assert(get_be64_signed(d) == ACC_INT64_C(9186918263483431288));
|
||||
assert(get_be64_signed(d) == UPX_INT64_C(9186918263483431288));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1434,6 +1442,9 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
#if 0 && defined(__DJGPP__)
|
||||
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
|
||||
putenv("LFN=y");
|
||||
#endif
|
||||
#if (ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_CC_MSC) && defined(_WRITE_ABORT_MSG) && defined(_CALL_REPORTFAULT)
|
||||
_set_abort_behavior(_WRITE_ABORT_MSG, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||
#endif
|
||||
acc_wildargv(&argc, &argv);
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -154,7 +154,7 @@ void MemBuffer::fill(unsigned off, unsigned len, int value)
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#define PTR(p) ((unsigned) ((acc_uintptr_t)(p) & 0xffffffff))
|
||||
#define PTR(p) ((unsigned) ((upx_uintptr_t)(p) & 0xffffffff))
|
||||
#define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb)
|
||||
#define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001)
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+1737
-1541
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+3
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -146,6 +146,7 @@ struct options_t {
|
||||
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
bool preserve_build_id; // copy the build-id to the compressed binary
|
||||
} o_unix;
|
||||
struct {
|
||||
bool le;
|
||||
|
||||
+14
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -202,6 +202,7 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
unsigned iat;
|
||||
LE32 *lookupt;
|
||||
unsigned npos;
|
||||
unsigned original_position;
|
||||
bool isk32;
|
||||
|
||||
static int __acc_cdecl_qsort compare(const void *p1, const void *p2)
|
||||
@@ -210,6 +211,8 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
const udll *u2 = * (const udll * const *) p2;
|
||||
if (u1->isk32) return -1;
|
||||
if (u2->isk32) return 1;
|
||||
if (!*u1->lookupt) return 1;
|
||||
if (!*u2->lookupt) return -1;
|
||||
int rc = strcasecmp(u1->name,u2->name);
|
||||
if (rc) return rc;
|
||||
if (u1->ordinal) return -1;
|
||||
@@ -236,11 +239,12 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
dlls[ic].iat = im->iat;
|
||||
dlls[ic].lookupt = (LE32*) (ibuf + (im->oft ? im->oft : im->iat));
|
||||
dlls[ic].npos = 0;
|
||||
dlls[ic].original_position = ic;
|
||||
dlls[ic].isk32 = strcasecmp(kernel32dll,dlls[ic].name) == 0;
|
||||
|
||||
soimport += strlen(dlls[ic].name) + 1 + 4;
|
||||
|
||||
for (LE32 *tarr = dlls[ic].lookupt; *tarr; tarr++)
|
||||
for (IPTR_I(LE32, tarr, dlls[ic].lookupt); *tarr; tarr += 1)
|
||||
{
|
||||
if (*tarr & 0x80000000)
|
||||
{
|
||||
@@ -252,10 +256,11 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned len = strlen(ibuf + *tarr + 2);
|
||||
IPTR_I(const upx_byte, n, ibuf + *tarr + 2);
|
||||
unsigned len = strlen(n);
|
||||
soimport += len + 1;
|
||||
if (dlls[ic].shname == NULL || len < strlen (dlls[ic].shname))
|
||||
dlls[ic].shname = ibuf + *tarr + 2;
|
||||
dlls[ic].shname = n;
|
||||
}
|
||||
soimport++; // separator
|
||||
}
|
||||
@@ -343,8 +348,10 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
for (ic = 0; ic < dllnum; ic++)
|
||||
{
|
||||
LE32 *tarr = idlls[ic]->lookupt;
|
||||
#if 0 && ENABLE_THIS_AND_UNCOMPRESSION_WILL_BREAK
|
||||
if (!*tarr) // no imports from this dll
|
||||
continue;
|
||||
#endif
|
||||
set_le32(ppi,idlls[ic]->npos);
|
||||
set_le32(ppi+4,idlls[ic]->iat - rvamin);
|
||||
ppi += 8;
|
||||
@@ -412,7 +419,7 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
for (ic = 0; ic < dllnum; ic++, im++)
|
||||
{
|
||||
memset(im,FILLVAL,sizeof(*im));
|
||||
im->dllname = ptr_diff(idlls[ic]->name,ibuf); // I only need this info
|
||||
im->dllname = ptr_diff(dlls[idlls[ic]->original_position].name,ibuf);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -592,7 +599,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
if (((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED))
|
||||
== (PEFL_WRITE|PEFL_SHARED)))
|
||||
if (!opt->force)
|
||||
throwCantPack("writeable shared sections not supported (try --force)");
|
||||
throwCantPack("writable shared sections not supported (try --force)");
|
||||
if (jc && isection[ic].rawdataptr - jc > ih.filealign)
|
||||
throwCantPack("superfluous data between sections");
|
||||
fi->seek(isection[ic].rawdataptr,SEEK_SET);
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+52
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -152,6 +152,7 @@
|
||||
DT_RELENT = 19, /* Size of one Rel relocation */
|
||||
DT_STRSZ = 10, /* Sizeof string table */
|
||||
DT_PLTREL = 20, /* Type of reloc in PLT */
|
||||
DT_TEXTREL = 22, /* Reloc might modify .text */
|
||||
DT_JMPREL = 23, /* Address of PLT relocs */
|
||||
DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */
|
||||
DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */
|
||||
@@ -195,6 +196,55 @@
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WANT_NHDR_ENUM
|
||||
#undef WANT_NHDR_ENUM
|
||||
enum { // ELF PT_NOTE types
|
||||
#define ELF_NOTE_GNU_NAME "GNU\0"
|
||||
NT_GNU_ABI_TAG = 1,
|
||||
NT_GNU_HWCAP = 2,
|
||||
NT_GNU_BUILD_ID = 3,
|
||||
|
||||
#define ELF_NOTE_OPENBSD_NAME "OpenBSD\0"
|
||||
NHDR_OPENBSD_TAG = 1,
|
||||
|
||||
#define ELF_NOTE_NETBSD_NAME "NetBSD\0"
|
||||
NHDR_NETBSD_TAG = 1,
|
||||
NHDR_CHECKSUM_TAG = 2,
|
||||
NHDR_PAX_TAG = 3
|
||||
};
|
||||
|
||||
enum { // descsz descriptor sizes
|
||||
GNU_ABI_DESCSZ = 16, // int GNU_OS, major, minor, subminor;
|
||||
NETBSD_DESCSZ = 4, // major_ver * (10**8) + minor
|
||||
OPENBSD_DESCSZ = 4, // 32-bit zero
|
||||
// CHECKSUM_DESCSZ is 2*sizeof(short) + sizeof(checksum)
|
||||
PAX_DESCSZ = 4 // 32-bit mask
|
||||
};
|
||||
|
||||
enum { // GNU OS/version
|
||||
GNU_OS_LINUX = 0,
|
||||
GNU_OS_HURD = 1,
|
||||
GNU_OS_SOLARIS = 2
|
||||
};
|
||||
|
||||
enum { // NetBSD checksum methods
|
||||
CHECKSUM_CRC32 = 1,
|
||||
CHECKSUM_MD5 = 2,
|
||||
CHECKSUM_SHA1 = 3,
|
||||
CHECKSUM_SHA256 = 4
|
||||
};
|
||||
|
||||
#define ELF_NOTE_PAX_NAME "PaX\0"
|
||||
enum { // NetBSD PaX bit values
|
||||
PAX_MPROTECT = (1<<0), /* force enable Mprotect */
|
||||
PAX_NOMPROTECT = (1<<1), /* force disable Mprotect */
|
||||
PAX_GUARD = (1<<2), /* force enable SEGVguard */
|
||||
PAX_NOGUARD = (1<<3), /* force disable SEGVguard */
|
||||
PAX_ASLR = (1<<4), /* force enable ASLR */
|
||||
PAX_NOASLR = (1<<5) /* force disable ASLR */
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+784
-222
File diff suppressed because it is too large
Load Diff
+74
-27
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -50,7 +50,7 @@ protected:
|
||||
// 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 int pack2(OutputFile *, Filter &) = 0; // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &) = 0; // append loader
|
||||
//virtual void pack4(OutputFile *, Filter &) = 0; // append pack header
|
||||
|
||||
@@ -63,9 +63,8 @@ protected:
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const = 0;
|
||||
virtual void const *elf_find_dynamic(unsigned) const = 0;
|
||||
virtual acc_uint64l_t elf_unsigned_dynamic(unsigned) const = 0;
|
||||
//virtual void const *elf_find_dynamic(unsigned) const = 0;
|
||||
virtual upx_uint64_t elf_unsigned_dynamic(unsigned) const = 0;
|
||||
|
||||
protected:
|
||||
unsigned e_phnum; /* Program header table entry count */
|
||||
@@ -75,18 +74,23 @@ protected:
|
||||
unsigned sz_phdrs; // sizeof Phdr[]
|
||||
unsigned sz_elf_hdrs; // all Elf headers
|
||||
unsigned sz_pack2; // after pack2(), before loader
|
||||
unsigned sz_pack2a; // after pack2() of all PT_LOAD
|
||||
unsigned lg2_page; // log2(PAGE_SIZE)
|
||||
unsigned page_size; // 1u<<lg2_page
|
||||
unsigned xct_off; // shared library: file offset of SHT_EXECINSTR
|
||||
unsigned hatch_off; // file offset of escape hatch
|
||||
acc_uint64l_t load_va; // PT_LOAD[0].p_vaddr
|
||||
acc_uint64l_t xct_va; // minimum SHT_EXECINSTR virtual address
|
||||
upx_uint64_t load_va; // PT_LOAD[0].p_vaddr
|
||||
upx_uint64_t xct_va; // minimum SHT_EXECINSTR virtual address
|
||||
|
||||
unsigned short e_machine;
|
||||
unsigned char ei_class;
|
||||
unsigned char ei_data;
|
||||
unsigned char ei_osabi;
|
||||
char const *osabi_note;
|
||||
|
||||
unsigned char const *buildid_data;
|
||||
int o_elf_shnum; // num output Shdrs
|
||||
static unsigned char o_shstrtab[];
|
||||
};
|
||||
|
||||
class PackLinuxElf32 : public PackLinuxElf
|
||||
@@ -103,9 +107,10 @@ protected:
|
||||
// but the class hierarchy splits after this class.
|
||||
virtual void ARM_defineSymbols(Filter const *ft);
|
||||
virtual void ARM_updateLoader(OutputFile *);
|
||||
virtual int ARM_is_QNX(void);
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
virtual void unpack(OutputFile *fo);
|
||||
@@ -132,15 +137,18 @@ protected:
|
||||
static unsigned elf_hash(char const *) /*const*/;
|
||||
static unsigned gnu_hash(char const *) /*const*/;
|
||||
virtual Elf32_Sym const *elf_lookup(char const *) const;
|
||||
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const;
|
||||
virtual unsigned elf_get_offset_from_address(unsigned) const;
|
||||
Elf32_Shdr const *elf_find_section_name(char const *) const;
|
||||
Elf32_Shdr const *elf_find_section_type(unsigned) const;
|
||||
void const *elf_find_dynamic(unsigned) const;
|
||||
acc_uint64l_t elf_unsigned_dynamic(unsigned) const;
|
||||
Elf32_Dyn const *elf_has_dynamic(unsigned) const;
|
||||
upx_uint64_t elf_unsigned_dynamic(unsigned) const;
|
||||
|
||||
protected:
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // for input file
|
||||
unsigned char *note_body; // concatenated contents of PT_NOTEs, if any
|
||||
unsigned note_size; // total size of PT_NOTEs
|
||||
Elf32_Shdr const *shdri; // from input file
|
||||
unsigned page_mask; // AND clears the offset-within-page
|
||||
|
||||
@@ -173,23 +181,36 @@ protected:
|
||||
l_info linfo;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
__packed_struct(cprElfHdrNetBSD)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[4];
|
||||
unsigned char notes[512];
|
||||
__packed_struct_end()
|
||||
|
||||
struct Elf32_Note {
|
||||
unsigned namesz; // 8
|
||||
unsigned descsz; // 4
|
||||
unsigned type; // 1
|
||||
char text[0x18 - 4*4]; // "OpenBSD"
|
||||
unsigned end; // 0
|
||||
} elfnote;
|
||||
cprElfHdrNetBSD elfout;
|
||||
|
||||
__packed_struct(cprElfShdr3)
|
||||
Elf32_Shdr shdr[3];
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfShdr3 shdrout;
|
||||
|
||||
struct Elf32_Nhdr {
|
||||
unsigned namesz;
|
||||
unsigned descsz;
|
||||
unsigned type;
|
||||
//unsigned char body[0];
|
||||
};
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdrNetBSD) == 52 + 4*32 + 512)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdrNetBSD)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -206,7 +227,7 @@ protected:
|
||||
virtual int checkEhdr(Elf64_Ehdr const *ehdr) const;
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int 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);
|
||||
@@ -229,17 +250,20 @@ protected:
|
||||
virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
|
||||
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) const;
|
||||
virtual upx_uint64_t elf_get_offset_from_address(upx_uint64_t) const;
|
||||
Elf64_Shdr const *elf_find_section_name(char const *) const;
|
||||
Elf64_Shdr const *elf_find_section_type(unsigned) const;
|
||||
void const *elf_find_dynamic(unsigned) const;
|
||||
acc_uint64l_t elf_unsigned_dynamic(unsigned) const;
|
||||
Elf64_Dyn const *elf_has_dynamic(unsigned) const;
|
||||
upx_uint64_t elf_unsigned_dynamic(unsigned) const;
|
||||
|
||||
protected:
|
||||
Elf64_Ehdr ehdri; // from input file
|
||||
Elf64_Phdr *phdri; // for input file
|
||||
unsigned char *note_body; // concatenated contents of PT_NOTEs, if any
|
||||
unsigned note_size; // total size of PT_NOTEs
|
||||
Elf64_Shdr const *shdri; // from input file
|
||||
acc_uint64l_t page_mask; // AND clears the offset-within-page
|
||||
upx_uint64_t page_mask; // AND clears the offset-within-page
|
||||
|
||||
Elf64_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
@@ -270,15 +294,29 @@ protected:
|
||||
l_info linfo;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
__packed_struct(cprElfHdr4)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[4];
|
||||
l_info linfo;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr4 elfout;
|
||||
|
||||
__packed_struct(cprElfShdr3)
|
||||
Elf64_Shdr shdr[3];
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfShdr3 shdrout;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 64 + 1*56 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 64 + 2*56 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 64 + 3*56 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr4) == 64 + 4*56 + 12)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr4)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -406,13 +444,21 @@ public:
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-freebsd.elf"; }
|
||||
};
|
||||
|
||||
class PackNetBSDElf32x86 : public PackBSDElf32x86
|
||||
class PackNetBSDElf32x86 : public PackLinuxElf32x86
|
||||
{
|
||||
typedef PackBSDElf32x86 super;
|
||||
typedef PackLinuxElf32x86 super;
|
||||
public:
|
||||
PackNetBSDElf32x86(InputFile *f);
|
||||
virtual ~PackNetBSDElf32x86();
|
||||
virtual const char *getName() const { return "netbsd/elf386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-netbsd.elf"; }
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
};
|
||||
|
||||
class PackOpenBSDElf32x86 : public PackBSDElf32x86
|
||||
@@ -421,6 +467,7 @@ class PackOpenBSDElf32x86 : public PackBSDElf32x86
|
||||
public:
|
||||
PackOpenBSDElf32x86(InputFile *f);
|
||||
virtual ~PackOpenBSDElf32x86();
|
||||
virtual const char *getName() const { return "opnbsd/elf386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-openbsd.elf"; }
|
||||
|
||||
protected:
|
||||
|
||||
+7
-7
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2001-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2001-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -375,7 +375,7 @@ PackLinuxI386::buildLinuxLoader(
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
if (M_IS_LZMA(ph.method)) {
|
||||
const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
|
||||
acc_uint32e_t properties = // lc, lp, pb, dummy
|
||||
upx_uint32_t properties = // lc, lp, pb, dummy
|
||||
(res->lit_context_bits << 0) |
|
||||
(res->lit_pos_bits << 8) |
|
||||
(res->pos_bits << 16);
|
||||
@@ -449,7 +449,7 @@ int PackLinuxI386::getLoaderPrefixSize() const
|
||||
// some ELF utitlity functions
|
||||
**************************************************************************/
|
||||
|
||||
// basic check of an Linux ELF Ehdr
|
||||
// basic check of a Linux ELF Ehdr
|
||||
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
{
|
||||
const unsigned char * const buf = ehdr->e_ident;
|
||||
@@ -601,11 +601,11 @@ void PackLinuxI386::patchLoaderChecksum()
|
||||
// checksum for loader + p_info
|
||||
lp->l_checksum = 0;
|
||||
lp->l_magic = UPX_ELF_MAGIC;
|
||||
lp->l_lsize = (unsigned short) lsize;
|
||||
set_te16(&lp->l_lsize, (unsigned short) lsize);
|
||||
lp->l_version = (unsigned char) ph.version;
|
||||
lp->l_format = (unsigned char) ph.format;
|
||||
// INFO: lp->l_checksum is currently unused
|
||||
lp->l_checksum = upx_adler32(ptr, lsize);
|
||||
set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+7
-7
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -114,7 +114,7 @@ void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
|
||||
h3.phdr[2].p_align = 1;
|
||||
|
||||
if (opt->o_unix.make_ptinterp) { // unusual "once per release"
|
||||
elfout = h3;
|
||||
*(cprElfHdr3 *)(void *)&elfout = h3;
|
||||
elfout.ehdr.e_phnum = 1;
|
||||
fo->write(&elfout, elfout.ehdr.e_ehsize + elfout.ehdr.e_phentsize);
|
||||
}
|
||||
@@ -124,12 +124,12 @@ void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
|
||||
#undef E
|
||||
}
|
||||
|
||||
void PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft)
|
||||
int PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
return; // ignore current input file!
|
||||
return 1; // ignore current input file!
|
||||
}
|
||||
super::pack2(fo, ft);
|
||||
return super::pack2(fo, ft);
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
|
||||
+4
-4
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // build loader
|
||||
};
|
||||
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+277
-78
@@ -2,7 +2,7 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2004-2010 John Reiser
|
||||
Copyright (C) 2004-2013 John Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -351,7 +351,7 @@ PackMachBase<T>::buildMachLoader(
|
||||
|
||||
int const GAP = 128; // must match stub/l_mac_ppc.S
|
||||
int const NO_LAP = 64; // must match stub/src/*darwin*.S
|
||||
segcmdo.vmsize += h.sz_unc - h.sz_cpr + GAP + NO_LAP;
|
||||
segTEXT.vmsize = h.sz_unc - h.sz_cpr + GAP + NO_LAP;
|
||||
|
||||
addStubEntrySections(ft);
|
||||
|
||||
@@ -429,11 +429,11 @@ void PackMachBase<T>::patchLoaderChecksum()
|
||||
// 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;
|
||||
set_te16(&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);
|
||||
set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -447,77 +447,211 @@ PackMachBase<T>::compare_segment_command(void const *const aa, void const *const
|
||||
unsigned const xb = b->cmd - lc_seg;
|
||||
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;
|
||||
// Beware 0==.vmsize (some MacOSX __DWARF debug info: a "comment")
|
||||
if (a->vmsize!=0 && b->vmsize!=0) {
|
||||
if (a->vmaddr < b->vmaddr) return -1; // ascending by .vmaddr
|
||||
if (a->vmaddr > b->vmaddr) return 1;
|
||||
}
|
||||
else { // 0==.vmsize goes last, except ordered by fileoff
|
||||
if (a->vmsize) return -1; // 'a' is first
|
||||
if (b->vmsize) return 1; // 'a' is last
|
||||
if (a->fileoff < b->fileoff)
|
||||
return -1;
|
||||
if (a->fileoff > b->fileoff)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
#undef PAGE_SIZE
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
#define PAGE_SIZE (0u-PAGE_MASK)
|
||||
|
||||
#undef PAGE_MASK64
|
||||
#undef PAGE_SIZE64
|
||||
#define PAGE_MASK64 (~(upx_uint64_t)0<<12)
|
||||
#define PAGE_SIZE64 ((upx_uint64_t)0-PAGE_MASK64)
|
||||
|
||||
// At 2013-02-03 part of the source for codesign was
|
||||
// http://opensource.apple.com/source/cctools/cctools-836/libstuff/ofile.c
|
||||
|
||||
void PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
|
||||
{
|
||||
// offset of p_info in compressed file
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
|
||||
+ sizeof(segXHDR) + sizeof(secXHDR)
|
||||
+ sizeof(segTEXT) + sizeof(secTEXT)
|
||||
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
|
||||
super::pack4(fo, ft);
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
segcmdo.vmsize += segcmdo.filesize;
|
||||
unsigned const t = fo->getBytesWritten();
|
||||
segTEXT.filesize = t;
|
||||
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
|
||||
secTEXT.offset = overlay_offset - sizeof(linfo);
|
||||
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
|
||||
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
|
||||
secXHDR.offset = overlay_offset - sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
secXHDR.addr += secXHDR.offset;
|
||||
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
|
||||
if (foff1 < segTEXT.vmsize)
|
||||
foff1 += PAGE_SIZE; // codesign disallows overhang
|
||||
segLINK.fileoff = foff1;
|
||||
segLINK.vmaddr = segTEXT.vmaddr + foff1;
|
||||
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
|
||||
fo->seek(sizeof(mhdro), SEEK_SET);
|
||||
fo->rewrite(&segcmdo, sizeof(segcmdo));
|
||||
fo->rewrite(&segZERO, sizeof(segZERO));
|
||||
fo->rewrite(&segXHDR, sizeof(segXHDR));
|
||||
fo->rewrite(&secXHDR, sizeof(secXHDR));
|
||||
fo->rewrite(&segTEXT, sizeof(segTEXT));
|
||||
fo->rewrite(&secTEXT, sizeof(secTEXT));
|
||||
fo->rewrite(&segLINK, sizeof(segLINK));
|
||||
fo->rewrite(&threado, sizeof(threado));
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
|
||||
fo->rewrite(&linkitem, sizeof(linkitem));
|
||||
}
|
||||
fo->rewrite(&linfo, sizeof(linfo));
|
||||
}
|
||||
|
||||
void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
|
||||
{
|
||||
// offset of p_info in compressed file
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
|
||||
+ sizeof(segXHDR) + sizeof(secXHDR)
|
||||
+ sizeof(segTEXT) + sizeof(secTEXT)
|
||||
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
|
||||
super::pack4(fo, ft);
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
segcmdo.vmsize += segcmdo.filesize;
|
||||
unsigned const t = fo->getBytesWritten();
|
||||
segTEXT.filesize = t;
|
||||
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
|
||||
secTEXT.offset = overlay_offset - sizeof(linfo);
|
||||
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
|
||||
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
|
||||
secXHDR.offset = overlay_offset - sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
secXHDR.addr += secXHDR.offset;
|
||||
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
|
||||
if (foff1 < segTEXT.vmsize)
|
||||
foff1 += PAGE_SIZE; // codesign disallows overhang
|
||||
segLINK.fileoff = foff1;
|
||||
segLINK.vmaddr = segTEXT.vmaddr + foff1;
|
||||
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
|
||||
fo->seek(sizeof(mhdro), SEEK_SET);
|
||||
fo->rewrite(&segcmdo, sizeof(segcmdo));
|
||||
fo->rewrite(&segZERO, sizeof(segZERO));
|
||||
fo->rewrite(&segXHDR, sizeof(segXHDR));
|
||||
fo->rewrite(&secXHDR, sizeof(secXHDR));
|
||||
fo->rewrite(&segTEXT, sizeof(segTEXT));
|
||||
fo->rewrite(&secTEXT, sizeof(secTEXT));
|
||||
fo->rewrite(&segLINK, sizeof(segLINK));
|
||||
fo->rewrite(&threado, sizeof(threado));
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
|
||||
fo->rewrite(&linkitem, sizeof(linkitem));
|
||||
}
|
||||
fo->rewrite(&linfo, sizeof(linfo));
|
||||
}
|
||||
|
||||
void PackMachAMD64::pack4(OutputFile *fo, Filter &ft) // append PackHeader
|
||||
{
|
||||
// offset of p_info in compressed file
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
|
||||
+ sizeof(segXHDR) + sizeof(secXHDR)
|
||||
+ sizeof(segTEXT) + sizeof(secTEXT)
|
||||
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
|
||||
super::pack4(fo, ft);
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
segcmdo.vmsize += segcmdo.filesize;
|
||||
unsigned const t = fo->getBytesWritten();
|
||||
segTEXT.filesize = t;
|
||||
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
|
||||
secTEXT.offset = overlay_offset - sizeof(linfo);
|
||||
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
|
||||
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
|
||||
secXHDR.offset = overlay_offset - sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
secXHDR.addr += secXHDR.offset;
|
||||
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
|
||||
if (foff1 < segTEXT.vmsize)
|
||||
foff1 += PAGE_SIZE; // codesign disallows overhang
|
||||
segLINK.fileoff = foff1;
|
||||
segLINK.vmaddr = segTEXT.vmaddr + foff1;
|
||||
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
|
||||
fo->seek(sizeof(mhdro), SEEK_SET);
|
||||
fo->rewrite(&segcmdo, sizeof(segcmdo));
|
||||
fo->rewrite(&segZERO, sizeof(segZERO));
|
||||
fo->rewrite(&segXHDR, sizeof(segXHDR));
|
||||
fo->rewrite(&secXHDR, sizeof(secXHDR));
|
||||
fo->rewrite(&segTEXT, sizeof(segTEXT));
|
||||
fo->rewrite(&secTEXT, sizeof(secTEXT));
|
||||
fo->rewrite(&segLINK, sizeof(segLINK));
|
||||
fo->rewrite(&threado, sizeof(threado));
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
|
||||
fo->rewrite(&linkitem, sizeof(linkitem));
|
||||
}
|
||||
fo->rewrite(&linfo, sizeof(linfo));
|
||||
}
|
||||
|
||||
void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
|
||||
{
|
||||
// offset of p_info in compressed file
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segcmdo) + sizeof(threado) + sizeof(linfo);
|
||||
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
|
||||
+ sizeof(segXHDR) + sizeof(secXHDR)
|
||||
+ sizeof(segTEXT) + sizeof(secTEXT)
|
||||
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
|
||||
super::pack4(fo, ft);
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
segcmdo.vmsize += segcmdo.filesize;
|
||||
unsigned const t = fo->getBytesWritten();
|
||||
segTEXT.filesize = t;
|
||||
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
|
||||
secTEXT.offset = overlay_offset - sizeof(linfo);
|
||||
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
|
||||
secTEXT.size = segTEXT.vmsize - secTEXT.offset;
|
||||
secXHDR.offset = overlay_offset - sizeof(linfo);
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
|
||||
}
|
||||
secXHDR.addr += secXHDR.offset;
|
||||
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
|
||||
if (foff1 < segTEXT.vmsize)
|
||||
foff1 += PAGE_SIZE; // codesign disallows overhang
|
||||
segLINK.fileoff = foff1;
|
||||
segLINK.vmaddr = segTEXT.vmaddr + foff1;
|
||||
fo->seek(foff1 - 1, SEEK_SET); fo->write("", 1);
|
||||
fo->seek(sizeof(mhdro), SEEK_SET);
|
||||
fo->rewrite(&segcmdo, sizeof(segcmdo));
|
||||
fo->rewrite(&segZERO, sizeof(segZERO));
|
||||
fo->rewrite(&segXHDR, sizeof(segXHDR));
|
||||
fo->rewrite(&secXHDR, sizeof(secXHDR));
|
||||
fo->rewrite(&segTEXT, sizeof(segTEXT));
|
||||
fo->rewrite(&secTEXT, sizeof(secTEXT));
|
||||
fo->rewrite(&segLINK, sizeof(segLINK));
|
||||
fo->rewrite(&threado, sizeof(threado));
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
|
||||
fo->rewrite(&linkitem, sizeof(linkitem));
|
||||
}
|
||||
fo->rewrite(&linfo, sizeof(linfo));
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
#undef PAGE_SIZE
|
||||
#define PAGE_MASK (~0u<<12)
|
||||
#define PAGE_SIZE -PAGE_MASK
|
||||
|
||||
#undef PAGE_MASK64
|
||||
#undef PAGE_SIZE64
|
||||
#define PAGE_MASK64 (~(acc_uint64l_t)0<<12)
|
||||
#define PAGE_SIZE64 -PAGE_MASK64
|
||||
|
||||
template <class T>
|
||||
void PackMachBase<T>::pack4dylib( // append PackHeader
|
||||
OutputFile *const fo,
|
||||
@@ -726,7 +860,7 @@ void PackMachPPC32::pack3(OutputFile *fo, Filter &ft) // append loader
|
||||
disp = 4+ len - sz_mach_headers; // 4: sizeof(instruction)
|
||||
fo->write(&disp, sizeof(disp));
|
||||
|
||||
threado.state.srr0 = len + segcmdo.vmaddr; /* entry address */
|
||||
threado.state.srr0 = len + segTEXT.vmaddr; /* entry address */
|
||||
super::pack3(fo, ft);
|
||||
}
|
||||
|
||||
@@ -740,7 +874,7 @@ void PackMachI386::pack3(OutputFile *fo, Filter &ft) // append loader
|
||||
disp = len - sz_mach_headers;
|
||||
fo->write(&disp, sizeof(disp));
|
||||
|
||||
threado.state.eip = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */
|
||||
threado.state.eip = len + sizeof(disp) + segTEXT.vmaddr; /* entry address */
|
||||
super::pack3(fo, ft);
|
||||
}
|
||||
|
||||
@@ -754,7 +888,7 @@ void PackMachAMD64::pack3(OutputFile *fo, Filter &ft) // append loader
|
||||
disp = len - sz_mach_headers;
|
||||
fo->write(&disp, sizeof(disp));
|
||||
|
||||
threado.state.rip = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */
|
||||
threado.state.rip = len + sizeof(disp) + segTEXT.vmaddr; /* entry address */
|
||||
super::pack3(fo, ft);
|
||||
}
|
||||
|
||||
@@ -768,7 +902,7 @@ void PackMachARMEL::pack3(OutputFile *fo, Filter &ft) // append loader
|
||||
disp = len - sz_mach_headers;
|
||||
fo->write(&disp, sizeof(disp));
|
||||
|
||||
threado.state.pc = len + sizeof(disp) + segcmdo.vmaddr; /* entry address */
|
||||
threado.state.pc = len + sizeof(disp) + segTEXT.vmaddr; /* entry address */
|
||||
super::pack3(fo, ft);
|
||||
}
|
||||
|
||||
@@ -899,7 +1033,7 @@ void PackMachBase<T>::pack3(OutputFile *fo, Filter &ft)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed body
|
||||
int PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed body
|
||||
{
|
||||
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
|
||||
Extent x;
|
||||
@@ -976,7 +1110,10 @@ void PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
|
||||
if (my_filetype!=Mach_header::MH_DYLIB)
|
||||
if ((off_t)total_in != file_size)
|
||||
throwEOFException();
|
||||
segcmdo.filesize = fo->getBytesWritten();
|
||||
segTEXT.filesize = fo->getBytesWritten();
|
||||
secTEXT.size = segTEXT.filesize - overlay_offset + sizeof(linfo);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void PackMachPPC32::pack1_setup_threado(OutputFile *const fo)
|
||||
@@ -1025,34 +1162,82 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
|
||||
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
|
||||
mhdro = mhdri;
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
mhdro.ncmds = 2;
|
||||
mhdro.sizeofcmds = sizeof(segcmdo) + my_thread_command_size;
|
||||
mhdro.flags = Mach_header::MH_NOUNDEFS;
|
||||
mhdro.ncmds = 5; // __ZERO, __XHDR, __TEXT, __LINKEDIT, THREAD_STATE
|
||||
mhdro.sizeofcmds = sizeof(segZERO)
|
||||
+ sizeof(segXHDR) + sizeof(secXHDR)
|
||||
+ sizeof(segTEXT) + sizeof(secTEXT) + sizeof(segLINK) +
|
||||
my_thread_command_size /* + sizeof(uuid_cmd) + sizeof(linkitem) */ ;
|
||||
mhdro.flags = Mach_header::MH_NOUNDEFS | Mach_header::MH_DYLDLINK;
|
||||
}
|
||||
fo->write(&mhdro, sizeof(mhdro));
|
||||
|
||||
segcmdo.cmd = lc_seg;
|
||||
segcmdo.cmdsize = sizeof(segcmdo);
|
||||
strncpy((char *)segcmdo.segname, "__TEXT", sizeof(segcmdo.segname));
|
||||
memset(&segZERO, 0, sizeof(segZERO));
|
||||
segZERO.cmd = lc_seg;
|
||||
segZERO.cmdsize = sizeof(segZERO);
|
||||
strncpy((char *)segZERO.segname, "__PAGEZERO", sizeof(segZERO.segname));
|
||||
segZERO.vmsize = PAGE_SIZE;
|
||||
|
||||
segTEXT.cmd = lc_seg;
|
||||
segTEXT.cmdsize = sizeof(segTEXT) + sizeof(secTEXT);
|
||||
strncpy((char *)segTEXT.segname, "__TEXT", sizeof(segTEXT.segname));
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
segcmdo.vmaddr = PAGE_MASK64 & (~PAGE_MASK64 +
|
||||
msegcmd[n_segment -1].vmsize + msegcmd[n_segment -1].vmaddr );
|
||||
int k; // must ignore zero-length segments, which sort last
|
||||
for (k=n_segment; --k>=0; )
|
||||
if (msegcmd[k].vmsize!=0)
|
||||
break;
|
||||
segTEXT.vmaddr = PAGE_MASK64 & (~PAGE_MASK64 +
|
||||
msegcmd[k].vmsize + msegcmd[k].vmaddr );
|
||||
}
|
||||
if (my_filetype==Mach_header::MH_DYLIB) {
|
||||
segcmdo.vmaddr = 0;
|
||||
segTEXT.vmaddr = 0;
|
||||
}
|
||||
segcmdo.vmsize = 0; // adjust later
|
||||
segcmdo.fileoff = 0;
|
||||
segcmdo.filesize = 0; // adjust later
|
||||
segcmdo.initprot = segcmdo.maxprot =
|
||||
segTEXT.vmsize = 0; // adjust later
|
||||
segTEXT.fileoff = 0;
|
||||
segTEXT.filesize = 0; // adjust later
|
||||
segTEXT.initprot = segTEXT.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;
|
||||
segTEXT.nsects = 1; // secTEXT
|
||||
segTEXT.flags = 0;
|
||||
|
||||
memset(&secTEXT, 0, sizeof(secTEXT));
|
||||
strncpy((char *)secTEXT.sectname, "__text", sizeof(secTEXT.sectname));
|
||||
memcpy(secTEXT.segname, segTEXT.segname, sizeof(secTEXT.segname));
|
||||
secTEXT.align = 2; // (1<<2) ==> 4
|
||||
|
||||
segXHDR = segTEXT;
|
||||
segXHDR.vmaddr = PAGE_SIZE;
|
||||
segXHDR.vmsize = PAGE_SIZE;
|
||||
segXHDR.filesize = PAGE_SIZE;
|
||||
strncpy((char *)segXHDR.segname, "__XHDR", sizeof(segXHDR.segname));
|
||||
|
||||
memset(&secXHDR, 0, sizeof(secXHDR));
|
||||
strncpy((char *)secXHDR.sectname, "__xhdr", sizeof(secXHDR.sectname));
|
||||
memcpy(secXHDR.segname, segXHDR.segname, sizeof(secXHDR.segname));
|
||||
secXHDR.addr = PAGE_SIZE;
|
||||
secXHDR.size = 0; // empty so far
|
||||
secXHDR.align = 2; // (1<<2) ==> 4
|
||||
|
||||
segLINK = segTEXT;
|
||||
segLINK.cmdsize = sizeof(segLINK);
|
||||
strncpy((char *)segLINK.segname, "__LINKEDIT", sizeof(segLINK.segname));
|
||||
segLINK.nsects = 0;
|
||||
segLINK.initprot = Mach_segment_command::VM_PROT_READ;
|
||||
// Adjust later: .vmaddr .vmsize .fileoff .filesize
|
||||
|
||||
if (my_filetype==Mach_header::MH_EXECUTE) {
|
||||
fo->write(&segcmdo, sizeof(segcmdo));
|
||||
fo->write(&segZERO, sizeof(segZERO));
|
||||
fo->write(&segXHDR, sizeof(segXHDR));
|
||||
fo->write(&secXHDR, sizeof(secXHDR));
|
||||
fo->write(&segTEXT, sizeof(segTEXT));
|
||||
fo->write(&secTEXT, sizeof(secTEXT));
|
||||
fo->write(&segLINK, sizeof(segLINK));
|
||||
pack1_setup_threado(fo);
|
||||
memset(&uuid_cmd, 0, sizeof(uuid_cmd));
|
||||
fo->write(&uuid_cmd, sizeof(uuid_cmd));
|
||||
memset(&linkitem, 0, sizeof(linkitem));
|
||||
fo->write(&linkitem, sizeof(linkitem));
|
||||
}
|
||||
if (my_filetype==Mach_header::MH_DYLIB) {
|
||||
fo->write(rawmseg, mhdri.sizeofcmds);
|
||||
@@ -1073,7 +1258,11 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|
||||
fi->readx(&mhdri, sizeof(mhdri));
|
||||
rawmseg = (Mach_segment_command *)new char[(unsigned) mhdri.sizeofcmds];
|
||||
fi->readx(rawmseg, mhdri.sizeofcmds);
|
||||
overlay_offset = sizeof(mhdri) + mhdri.sizeofcmds + sizeof(linfo);
|
||||
|
||||
// FIXME forgot space left for LC_CODE_SIGNATURE;
|
||||
// but PackUnix::canUnpack() sets overlay_offset anyway.
|
||||
//overlay_offset = sizeof(mhdri) + mhdri.sizeofcmds + sizeof(linfo);
|
||||
|
||||
fi->seek(overlay_offset, SEEK_SET);
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
@@ -1126,6 +1315,8 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|
||||
) {
|
||||
if (lc_seg==sc->cmd
|
||||
&& 0!=sc->filesize ) {
|
||||
if (fo)
|
||||
fo->seek(sc->fileoff, SEEK_SET);
|
||||
unsigned filesize = sc->filesize;
|
||||
unpackExtent(filesize, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, sizeof(bhdr));
|
||||
@@ -1147,11 +1338,13 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|
||||
if (lc_seg==rc->cmd
|
||||
&& 0!=rc->filesize ) {
|
||||
fi->seek(rc->fileoff, SEEK_SET);
|
||||
fo->seek(sc->fileoff, SEEK_SET);
|
||||
if (fo)
|
||||
fo->seek(sc->fileoff, SEEK_SET);
|
||||
unsigned const len = rc->filesize;
|
||||
MemBuffer data(len);
|
||||
fi->readx(data, len);
|
||||
fo->write(data, len);
|
||||
if (fo)
|
||||
fo->write(data, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1159,14 +1352,14 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|
||||
for (unsigned j = 0; j < ncmds; ++j) {
|
||||
unsigned const size = find_SEGMENT_gap(j);
|
||||
if (size) {
|
||||
unsigned const where = msegcmd[k].fileoff +msegcmd[k].filesize;
|
||||
unsigned const where = msegcmd[j].fileoff +msegcmd[j].filesize;
|
||||
if (fo)
|
||||
fo->seek(where, SEEK_SET);
|
||||
unpackExtent(size, fo, total_in, total_out,
|
||||
c_adler, u_adler, false, sizeof(bhdr));
|
||||
}
|
||||
}
|
||||
delete mhdr;
|
||||
delete [] mhdr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1207,19 +1400,19 @@ bool PackMachBase<T>::canPack()
|
||||
// Put LC_SEGMENT together at the beginning, ascending by .vmaddr.
|
||||
qsort(msegcmd, ncmds, sizeof(*msegcmd), compare_segment_command);
|
||||
|
||||
// Check that LC_SEGMENTs form one contiguous chunk of the file.
|
||||
// Check alignment of non-null LC_SEGMENT.
|
||||
for (unsigned j= 0; j < ncmds; ++j) {
|
||||
if (lc_seg==msegcmd[j].cmd) {
|
||||
if (~PAGE_MASK & (msegcmd[j].fileoff | msegcmd[j].vmaddr)) {
|
||||
return false;
|
||||
}
|
||||
if (0 < j) {
|
||||
unsigned const sz = PAGE_MASK
|
||||
& (~PAGE_MASK + msegcmd[j-1].filesize);
|
||||
if ((sz + msegcmd[j-1].fileoff)!=msegcmd[j].fileoff) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (msegcmd[j].vmsize==0)
|
||||
break; // was sorted last
|
||||
|
||||
// We used to check that LC_SEGMENTS were contiguous,
|
||||
// but apparently that is not needed anymore,
|
||||
// and Google compilers generate strange layouts.
|
||||
|
||||
++n_segment;
|
||||
sz_segment = msegcmd[j].filesize + msegcmd[j].fileoff - msegcmd[0].fileoff;
|
||||
}
|
||||
@@ -1351,15 +1544,19 @@ void PackMachFat::pack(OutputFile *fo)
|
||||
|
||||
void PackMachFat::unpack(OutputFile *fo)
|
||||
{
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->write(&fat_head, sizeof(fat_head.fat) +
|
||||
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
|
||||
if (fo) { // test mode ("-t") sets fo = NULL
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->write(&fat_head, sizeof(fat_head.fat) +
|
||||
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
|
||||
}
|
||||
unsigned length;
|
||||
for (unsigned j=0; j < fat_head.fat.nfat_arch; ++j) {
|
||||
unsigned base = fo->unset_extent(); // actual length
|
||||
unsigned base = (fo ? fo->unset_extent() : 0); // actual length
|
||||
base += ~(~0u<<fat_head.arch[j].align) & (0-base); // align up
|
||||
fo->seek(base, SEEK_SET);
|
||||
fo->set_extent(base, ~0u);
|
||||
if (fo) {
|
||||
fo->seek(base, SEEK_SET);
|
||||
fo->set_extent(base, ~0u);
|
||||
}
|
||||
|
||||
ph.u_file_size = fat_head.arch[j].size;
|
||||
fi->set_extent(fat_head.arch[j].offset, fat_head.arch[j].size);
|
||||
@@ -1418,13 +1615,15 @@ void PackMachFat::unpack(OutputFile *fo)
|
||||
} break;
|
||||
} // switch cputype
|
||||
fat_head.arch[j].offset = base;
|
||||
length = fo->unset_extent();
|
||||
length = (fo ? fo->unset_extent() : 0);
|
||||
fat_head.arch[j].size = length - base;
|
||||
}
|
||||
fo->unset_extent();
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->rewrite(&fat_head, sizeof(fat_head.fat) +
|
||||
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
|
||||
if (fo) {
|
||||
fo->unset_extent();
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->rewrite(&fat_head, sizeof(fat_head.fat) +
|
||||
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
|
||||
}
|
||||
}
|
||||
|
||||
bool PackMachFat::canPack()
|
||||
|
||||
+49
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -269,6 +269,25 @@ __packed_struct(Mach_twolevel_hints_command)
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_linkedit_data_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
Word dataoff; // file offset of data in __LINKEDIT segment
|
||||
Word datasize; // file size of data in __LINKEDIT segment
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_uuid_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
unsigned char uuid[16];
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_ppc_thread_state)
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
@@ -392,6 +411,8 @@ struct MachClass_32
|
||||
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
|
||||
typedef N_Mach::Mach_routines_command<MachITypes> Mach_routines_command;
|
||||
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
|
||||
typedef N_Mach::Mach_linkedit_data_command<MachITypes> Mach_linkedit_data_command;
|
||||
typedef N_Mach::Mach_uuid_command<MachITypes> Mach_uuid_command;
|
||||
typedef N_Mach::Mach_ppc_thread_state<MachITypes> Mach_ppc_thread_state;
|
||||
typedef N_Mach::Mach_i386_thread_state<MachITypes> Mach_i386_thread_state;
|
||||
typedef N_Mach::Mach_AMD64_thread_state<MachITypes> Mach_AMD64_thread_state;
|
||||
@@ -428,6 +449,8 @@ struct MachClass_64
|
||||
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
|
||||
typedef N_Mach::Mach_routines_command_64<MachITypes> Mach_routines_command;
|
||||
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
|
||||
typedef N_Mach::Mach_linkedit_data_command<MachITypes> Mach_linkedit_data_command;
|
||||
typedef N_Mach::Mach_uuid_command<MachITypes> Mach_uuid_command;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
BeLePolicy::compileTimeAssertions();
|
||||
@@ -452,6 +475,8 @@ typedef MachClass_Host32::Mach_dysymtab_command Mach32_dysymtab_command;
|
||||
typedef MachClass_Host32::Mach_segsplit_info_command Mach32_segsplit_info_command;
|
||||
typedef MachClass_Host32::Mach_routines_command Mach32_routines_command;
|
||||
typedef MachClass_Host32::Mach_twolevel_hints_command Mach32_twolevel_hints_command;
|
||||
typedef MachClass_Host32::Mach_linkedit_data_command Mach32_linkedit_data_command;
|
||||
typedef MachClass_Host32::Mach_uuid_command Mach32_uuid_command;
|
||||
|
||||
typedef MachClass_Host64::Mach_segment_command Mach64_segment_command;
|
||||
typedef MachClass_Host64::Mach_section_command Mach64_section_command;
|
||||
@@ -460,6 +485,8 @@ typedef MachClass_Host64::Mach_dysymtab_command Mach64_dysymtab_command;
|
||||
typedef MachClass_Host64::Mach_segsplit_info_command Mach64_segsplit_info_command;
|
||||
typedef MachClass_Host64::Mach_routines_command Mach64_routines_command;
|
||||
typedef MachClass_Host64::Mach_twolevel_hints_command Mach64_twolevel_hints_command;
|
||||
typedef MachClass_Host64::Mach_linkedit_data_command Mach64_linkedit_data_command;
|
||||
typedef MachClass_Host64::Mach_uuid_command Mach64_uuid_command;
|
||||
|
||||
typedef MachClass_BE32::Mach_segment_command MachBE32_segment_command;
|
||||
typedef MachClass_BE32::Mach_section_command MachBE32_section_command;
|
||||
@@ -468,6 +495,8 @@ typedef MachClass_BE32::Mach_dysymtab_command MachBE32_dysymtab_command;
|
||||
typedef MachClass_BE32::Mach_segsplit_info_command MachBE32_segsplit_info_command;
|
||||
typedef MachClass_BE32::Mach_routines_command MachBE32_routines_command;
|
||||
typedef MachClass_BE32::Mach_twolevel_hints_command MachBE32_twolevel_hints_command;
|
||||
typedef MachClass_BE32::Mach_linkedit_data_command MachBE32_linkedit_data_command;
|
||||
typedef MachClass_BE32::Mach_uuid_command MachBE32_uuid_command;
|
||||
|
||||
typedef MachClass_BE64::Mach_segment_command MachBE64_segment_command;
|
||||
typedef MachClass_BE64::Mach_section_command MachBE64_section_command;
|
||||
@@ -476,6 +505,8 @@ typedef MachClass_BE64::Mach_dysymtab_command MachBE64_dysymtab_command;
|
||||
typedef MachClass_BE64::Mach_segsplit_info_command MachBE64_segsplit_info_command;
|
||||
typedef MachClass_BE64::Mach_routines_command MachBE64_routines_command;
|
||||
typedef MachClass_BE64::Mach_twolevel_hints_command MachBE64_twolevel_hints_command;
|
||||
typedef MachClass_BE64::Mach_linkedit_data_command MachBE64_linkedit_data_command;
|
||||
typedef MachClass_BE64::Mach_uuid_command MachBE64_uuid_command;
|
||||
|
||||
typedef MachClass_LE32::Mach_segment_command MachLE32_segment_command;
|
||||
typedef MachClass_LE32::Mach_section_command MachLE32_section_command;
|
||||
@@ -484,6 +515,8 @@ typedef MachClass_LE32::Mach_dysymtab_command MachLE32_dysymtab_command;
|
||||
typedef MachClass_LE32::Mach_segsplit_info_command MachLE32_segsplit_info_command;
|
||||
typedef MachClass_LE32::Mach_routines_command MachLE32_routines_command;
|
||||
typedef MachClass_LE32::Mach_twolevel_hints_command MachLE32_twolevel_hints_command;
|
||||
typedef MachClass_LE32::Mach_linkedit_data_command MachLE32_linkedit_data_command;
|
||||
typedef MachClass_LE32::Mach_uuid_command MachLE32_uuid_command;
|
||||
|
||||
typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command;
|
||||
typedef MachClass_LE64::Mach_section_command MachLE64_section_command;
|
||||
@@ -492,6 +525,8 @@ typedef MachClass_LE64::Mach_dysymtab_command MachLE64_dysymtab_command;
|
||||
typedef MachClass_LE64::Mach_segsplit_info_command MachLE64_segsplit_info_command;
|
||||
typedef MachClass_LE64::Mach_routines_command MachLE64_routines_command;
|
||||
typedef MachClass_LE64::Mach_twolevel_hints_command MachLE64_twolevel_hints_command;
|
||||
typedef MachClass_LE64::Mach_linkedit_data_command MachLE64_linkedit_data_command;
|
||||
typedef MachClass_LE64::Mach_uuid_command MachLE64_uuid_command;
|
||||
|
||||
typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state;
|
||||
typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state;
|
||||
@@ -522,6 +557,8 @@ protected:
|
||||
typedef typename MachClass::Mach_segsplit_info_command Mach_segsplit_info_command;
|
||||
typedef typename MachClass::Mach_routines_command Mach_routines_command;
|
||||
typedef typename MachClass::Mach_twolevel_hints_command Mach_twolevel_hints_command;
|
||||
typedef typename MachClass::Mach_linkedit_data_command Mach_linkedit_data_command;
|
||||
typedef typename MachClass::Mach_uuid_command Mach_uuid_command;
|
||||
|
||||
public:
|
||||
PackMachBase(InputFile *, unsigned cpuid, unsigned filetype,
|
||||
@@ -532,7 +569,7 @@ public:
|
||||
|
||||
// called by the generic pack()
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &) = 0; // append loader
|
||||
virtual void pack4(OutputFile *, Filter &) = 0; // append PackHeader
|
||||
|
||||
@@ -571,11 +608,18 @@ protected:
|
||||
Mach_segment_command *rawmseg; // as input, with sections
|
||||
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
|
||||
unsigned o_routines_cmd; // file offset to LC_ROUINTES
|
||||
acc_uint64l_t prev_init_address;
|
||||
upx_uint64_t prev_init_address;
|
||||
Mach_header mhdri;
|
||||
|
||||
Mach_header mhdro;
|
||||
Mach_segment_command segcmdo;
|
||||
Mach_segment_command segZERO;
|
||||
Mach_segment_command segXHDR; // location to put eXtra headers
|
||||
Mach_section_command secXHDR;
|
||||
Mach_segment_command segTEXT;
|
||||
Mach_section_command secTEXT;
|
||||
Mach_segment_command segLINK;
|
||||
Mach_linkedit_data_command linkitem;
|
||||
Mach_uuid_command uuid_cmd;
|
||||
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
TE32 sz_unc; // uncompressed_size
|
||||
|
||||
+5
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2007-2010 John F. Reiser
|
||||
Copyright (C) 2007-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -52,10 +52,12 @@
|
||||
};
|
||||
enum { // filetype
|
||||
MH_EXECUTE = 2,
|
||||
MH_DYLIB = 6
|
||||
MH_DYLIB = 6,
|
||||
MH_BUNDLE = 8 /* dynamically bound bundle file */
|
||||
};
|
||||
enum { // flags
|
||||
MH_NOUNDEFS = 1
|
||||
MH_NOUNDEFS = 1,
|
||||
MH_DYLDLINK = 4 /* code signing demands this */
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2002-2013 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2002-2013 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+5
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -327,7 +327,9 @@ void PackTmt::unpack(OutputFile *fo)
|
||||
{
|
||||
Filter ft(ph.level);
|
||||
ft.init(ph.filter, 0);
|
||||
ft.cto = (unsigned char) (ph.version < 11 ? (get_le32(obuf+ph.u_len-12) >> 24) : ph.filter_cto);
|
||||
ft.cto = (unsigned char) ph.filter_cto;
|
||||
if (ph.version < 11)
|
||||
ft.cto = (unsigned char) (get_le32(obuf+ph.u_len-12) >> 24);
|
||||
ft.unfilter(obuf, ptr_diff(relocs, obuf));
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+29
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -130,7 +130,7 @@ int PackUnix::getStrategy(Filter &/*ft*/)
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
int PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
// compress blocks
|
||||
unsigned total_in = 0;
|
||||
@@ -142,6 +142,7 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
// ui_total_passes = 0;
|
||||
|
||||
unsigned remaining = file_size;
|
||||
unsigned n_block = 0;
|
||||
while (remaining > 0)
|
||||
{
|
||||
// FIXME: disable filters if we have more than one block.
|
||||
@@ -170,7 +171,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
// that is, AFTER filtering. We want BEFORE filtering,
|
||||
// so that decompression checks the end-to-end checksum.
|
||||
unsigned const end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler);
|
||||
compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy);
|
||||
compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy,
|
||||
!!n_block++); // check compression ratio only on first block
|
||||
|
||||
if (ph.c_len < ph.u_len) {
|
||||
const upx_bytep tbuf = NULL;
|
||||
@@ -222,6 +224,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
if ((off_t)total_in != file_size) {
|
||||
throwEOFException();
|
||||
}
|
||||
|
||||
return 1; // default: write end-of-compression bhdr next
|
||||
}
|
||||
|
||||
void
|
||||
@@ -231,11 +235,11 @@ PackUnix::patchLoaderChecksum()
|
||||
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;
|
||||
set_te16(&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);
|
||||
set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
|
||||
}
|
||||
|
||||
void PackUnix::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
@@ -283,12 +287,13 @@ void PackUnix::pack(OutputFile *fo)
|
||||
set_te32(&hbuf.p_blocksize, blocksize);
|
||||
fo->write(&hbuf, sizeof(hbuf));
|
||||
|
||||
pack2(fo, ft); // append the compressed body
|
||||
|
||||
// write block end marker (uncompressed size 0)
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
|
||||
fo->write(&hdr, sizeof(hdr));
|
||||
// append the compressed body
|
||||
if (pack2(fo, ft)) {
|
||||
// write block end marker (uncompressed size 0)
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
|
||||
fo->write(&hdr, sizeof(hdr));
|
||||
}
|
||||
|
||||
pack3(fo, ft); // append loader
|
||||
|
||||
@@ -498,18 +503,26 @@ void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
|
||||
int PackUnix::canUnpack()
|
||||
{
|
||||
upx_byte buf[128];
|
||||
const int bufsize = sizeof(buf);
|
||||
int const small = 32 + sizeof(overlay_offset);
|
||||
// Allow zero-filled last page, for Mac OS X code signing.
|
||||
int bufsize = 2*4096 + 2*small +1;
|
||||
if (bufsize > fi->st_size())
|
||||
bufsize = fi->st_size();
|
||||
MemBuffer buf(bufsize);
|
||||
|
||||
fi->seek(-bufsize, SEEK_END);
|
||||
fi->readx(buf, bufsize);
|
||||
if (!getPackHeader(buf, bufsize, true)) // allow incompressible extents
|
||||
int i = bufsize;
|
||||
while (i > small && 0 == buf[--i]) { }
|
||||
i -= small;
|
||||
// allow incompressible extents
|
||||
if (i < 0 || !getPackHeader(buf + i, bufsize - i, true))
|
||||
return false;
|
||||
|
||||
int l = ph.buf_offset + ph.getPackHeaderSize();
|
||||
if (l < 0 || l + 4 > bufsize)
|
||||
throwCantUnpack("file corrupted");
|
||||
overlay_offset = get_te32(buf+l);
|
||||
overlay_offset = get_te32(buf + i + l);
|
||||
if ((off_t)overlay_offset >= file_size)
|
||||
throwCantUnpack("file corrupted");
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
protected:
|
||||
// called by the generic pack()
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
|
||||
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2004-2010 John Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2004-2013 John Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -1079,8 +1079,8 @@ void PackVmlinuxAMD64::defineDecompressorSymbols()
|
||||
// We assume a 32-bit boot loader, so we use the 32-bit convention
|
||||
// of "enter at the beginning" (startup_32). The 64-bit convention
|
||||
// would be to use ehdri.e_entry (startup_64).
|
||||
linker->defineSymbol("ENTRY_POINT", phdri[0].p_paddr);
|
||||
linker->defineSymbol("PHYSICAL_START", phdri[0].p_paddr);
|
||||
linker->defineSymbol("ENTRY_POINT", (unsigned) phdri[0].p_paddr);
|
||||
linker->defineSymbol("PHYSICAL_START", (unsigned) phdri[0].p_paddr);
|
||||
}
|
||||
|
||||
unsigned PackVmlinuxARMEL::write_vmlinux_head(
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -591,7 +591,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
||||
|
||||
if (M_IS_LZMA(ph.method)) {
|
||||
const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
|
||||
acc_uint32e_t properties = // lc, lp, pb, dummy
|
||||
upx_uint32_t properties = // lc, lp, pb, dummy
|
||||
(res->lit_context_bits << 0) |
|
||||
(res->lit_pos_bits << 8) |
|
||||
(res->pos_bits << 16);
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+26
-21
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -183,6 +183,8 @@ int PackW32Pe::readFileHeader()
|
||||
// the virtual memory manager only for pages which are not yet loaded.
|
||||
// of course it was impossible to debug this ;-)
|
||||
|
||||
#define TLS_CB_ALIGNMENT 4u // alignment of tls callbacks
|
||||
|
||||
__packed_struct(tls)
|
||||
LE32 datastart; // VA tls init data start
|
||||
LE32 dataend; // VA tls init data end
|
||||
@@ -211,13 +213,6 @@ void PackW32Pe::processTls(Interval *iv) // pass 1
|
||||
unsigned v = get_le32(ibuf + tlsp->callbacks - ih.imagebase);
|
||||
|
||||
//NEW: TLS callback support - Stefan Widmann
|
||||
#if 0
|
||||
if (v != 0)
|
||||
{
|
||||
//fprintf(stderr, "TLS callbacks: 0x%0x -> 0x%0x\n", (int)tlsp->callbacks, v);
|
||||
throwCantPack("TLS callbacks are not supported");
|
||||
}
|
||||
#endif
|
||||
if(v != 0)
|
||||
{
|
||||
//count number of callbacks, just for information string - Stefan Widmann
|
||||
@@ -248,13 +243,16 @@ void PackW32Pe::processTls(Interval *iv) // pass 1
|
||||
if (pos >= tlsdatastart && pos < tlsdataend)
|
||||
iv->add(pos,type);
|
||||
|
||||
//NEW: if TLS callbacks are used, we need two more DWORDS at the end of the TLS
|
||||
sotls = sizeof(tls) + tlsdataend - tlsdatastart + (use_tls_callbacks ? 8 : 0);
|
||||
sotls = sizeof(tls) + tlsdataend - tlsdatastart;
|
||||
// if TLS callbacks are used, we need two more DWORDS at the end of the TLS
|
||||
// ... and those dwords should be correctly aligned
|
||||
if (use_tls_callbacks)
|
||||
sotls = ALIGN_UP(sotls, TLS_CB_ALIGNMENT) + 8;
|
||||
|
||||
// the PE loader wants this stuff uncompressed
|
||||
otls = new upx_byte[sotls];
|
||||
memset(otls,0,sotls);
|
||||
memcpy(otls,ibuf + IDADDR(PEDIR_TLS),0x18);
|
||||
memcpy(otls,ibuf + IDADDR(PEDIR_TLS),sizeof(tls));
|
||||
// WARNING: this can acces data in BSS
|
||||
memcpy(otls + sizeof(tls),ibuf + tlsdatastart,sotls - sizeof(tls));
|
||||
tlsindex = tlsp->tlsindex - ih.imagebase;
|
||||
@@ -292,9 +290,9 @@ void PackW32Pe::processTls(Reloc *rel,const Interval *iv,unsigned newaddr) // pa
|
||||
rel->add(kc - ih.imagebase,iv->ivarr[ic].len);
|
||||
}
|
||||
|
||||
const unsigned tls_data_size = tlsp->dataend - tlsp->datastart;
|
||||
tlsp->datastart = newaddr + sizeof(tls) + ih.imagebase;
|
||||
//NEW: subtract the size of the callback chain from dataend - Stefan Widmann
|
||||
tlsp->dataend = newaddr + sotls + ih.imagebase - (use_tls_callbacks ? 8 : 0);
|
||||
tlsp->dataend = tlsp->datastart + tls_data_size;
|
||||
|
||||
//NEW: if we have TLS callbacks to handle, we create a pointer to the new callback chain - Stefan Widmann
|
||||
tlsp->callbacks = (use_tls_callbacks ? newaddr + sotls + ih.imagebase - 8 : 0);
|
||||
@@ -365,6 +363,7 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
unsigned iat;
|
||||
LE32 *lookupt;
|
||||
unsigned npos;
|
||||
unsigned original_position;
|
||||
bool isk32;
|
||||
|
||||
static int __acc_cdecl_qsort compare(const void *p1, const void *p2)
|
||||
@@ -373,6 +372,8 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
const udll *u2 = * (const udll * const *) p2;
|
||||
if (u1->isk32) return -1;
|
||||
if (u2->isk32) return 1;
|
||||
if (!*u1->lookupt) return 1;
|
||||
if (!*u2->lookupt) return -1;
|
||||
int rc = strcasecmp(u1->name,u2->name);
|
||||
if (rc) return rc;
|
||||
if (u1->ordinal) return -1;
|
||||
@@ -399,11 +400,12 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
dlls[ic].iat = im->iat;
|
||||
dlls[ic].lookupt = (LE32*) (ibuf + (im->oft ? im->oft : im->iat));
|
||||
dlls[ic].npos = 0;
|
||||
dlls[ic].original_position = ic;
|
||||
dlls[ic].isk32 = strcasecmp(kernel32dll,dlls[ic].name) == 0;
|
||||
|
||||
soimport += strlen(dlls[ic].name) + 1 + 4;
|
||||
|
||||
for (LE32 *tarr = dlls[ic].lookupt; *tarr; tarr++)
|
||||
for (IPTR_I(LE32, tarr, dlls[ic].lookupt); *tarr; tarr += 1)
|
||||
{
|
||||
if (*tarr & 0x80000000)
|
||||
{
|
||||
@@ -415,10 +417,11 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned len = strlen(ibuf + *tarr + 2);
|
||||
IPTR_I(const upx_byte, n, ibuf + *tarr + 2);
|
||||
unsigned len = strlen(n);
|
||||
soimport += len + 1;
|
||||
if (dlls[ic].shname == NULL || len < strlen (dlls[ic].shname))
|
||||
dlls[ic].shname = ibuf + *tarr + 2;
|
||||
dlls[ic].shname = n;
|
||||
}
|
||||
soimport++; // separator
|
||||
}
|
||||
@@ -510,8 +513,10 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
for (ic = 0; ic < dllnum; ic++)
|
||||
{
|
||||
LE32 *tarr = idlls[ic]->lookupt;
|
||||
#if 0 && ENABLE_THIS_AND_UNCOMPRESSION_WILL_BREAK
|
||||
if (!*tarr) // no imports from this dll
|
||||
continue;
|
||||
#endif
|
||||
set_le32(ppi,idlls[ic]->npos);
|
||||
set_le32(ppi+4,idlls[ic]->iat - rvamin);
|
||||
ppi += 8;
|
||||
@@ -579,7 +584,7 @@ unsigned PackW32Pe::processImports() // pass 1
|
||||
for (ic = 0; ic < dllnum; ic++, im++)
|
||||
{
|
||||
memset(im,FILLVAL,sizeof(*im));
|
||||
im->dllname = ptr_diff(idlls[ic]->name,ibuf); // I only need this info
|
||||
im->dllname = ptr_diff(dlls[idlls[ic]->original_position].name,ibuf);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -829,7 +834,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
throwCantPack("PE32/EFIROM files are not yet supported");
|
||||
break;
|
||||
}
|
||||
case 14: //XBOX - will we ever see an XBOX file?
|
||||
case 14: //XBOX - will we ever see a XBOX file?
|
||||
{
|
||||
throwCantPack("PE32/xbox files are not yet supported");
|
||||
break;
|
||||
@@ -912,7 +917,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
if (!isrtm && ((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED))
|
||||
== (PEFL_WRITE|PEFL_SHARED)))
|
||||
if (!opt->force)
|
||||
throwCantPack("writeable shared sections not supported (try --force)");
|
||||
throwCantPack("writable shared sections not supported (try --force)");
|
||||
if (jc && isection[ic].rawdataptr - jc > ih.filealign)
|
||||
throwCantPack("superfluous data between sections");
|
||||
fi->seek(isection[ic].rawdataptr,SEEK_SET);
|
||||
@@ -1087,7 +1092,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
// 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.
|
||||
// is a 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
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user