Compare commits
165 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 626025d539 | |||
| 9e8a0a020f | |||
| 40f592eade | |||
| 5e899f0be4 | |||
| f2748284b1 | |||
| a15ce00934 | |||
| 9e3e80261b | |||
| c72c685434 | |||
| 0177a8d277 | |||
| b6a9b0a4c9 | |||
| f4f8bd8d42 | |||
| 6e4aeffc0c | |||
| dba256d384 | |||
| 910008e9e7 | |||
| 8cb9545c41 | |||
| 59c16da6fb | |||
| 630df5bbd2 | |||
| f550111400 | |||
| 77377195aa | |||
| 7e2e72bd40 | |||
| aa7a13bd02 | |||
| 5895058a17 | |||
| ffb60d5149 | |||
| 1e2cb279b0 | |||
| e7f766f5ba | |||
| 8de5aa9409 | |||
| bf28a4df49 | |||
| fe1a0ab371 | |||
| 01daccfaf7 | |||
| 94e861e298 | |||
| d36af2ed5c | |||
| 7104b33214 | |||
| 32998e5377 | |||
| af0c9ef092 | |||
| 3bc3b3d10e | |||
| f03f42ca4d | |||
| 79783abeb1 | |||
| 895b0bd602 | |||
| 2ee5ee92f8 | |||
| 3e619423b1 | |||
| b524e18bdf | |||
| 6aa4579db8 | |||
| 17fb86c0f1 | |||
| 62ecfe4873 | |||
| 04e55e6b9a | |||
| f432aa1090 | |||
| 7add104313 | |||
| 36de249066 | |||
| b7a54dcffd | |||
| 6bb28deab2 | |||
| 7f88d15c86 | |||
| 94c5014e23 | |||
| c5a8256500 | |||
| 5f39884bf7 | |||
| d96825a242 | |||
| 443a938091 | |||
| 6bc3197721 | |||
| 269cc91fd5 | |||
| c1ddea479d | |||
| 5f3a95962c | |||
| ee1a8e6a32 | |||
| eeae73296e | |||
| 4ca8357af4 | |||
| 8a5b8c87fb | |||
| 6ab04d7bbc | |||
| a5a1380636 | |||
| eeab1aef64 | |||
| 4e1c342e55 | |||
| d8ed259bce | |||
| 9f6cb5de4c | |||
| ba634118d7 | |||
| 63da091d36 | |||
| ad0dc88a33 | |||
| 147acf4b57 | |||
| 5085f3a15e | |||
| 22a95ad8ea | |||
| df4bd6a60c | |||
| 813e7b05e4 | |||
| ab8b486b4a | |||
| 590f666ec9 | |||
| 9adaee915b | |||
| bce0f06fe9 | |||
| 856ecb84a0 | |||
| 90ddc06c98 | |||
| 405abc4e95 | |||
| 549c59ecf5 | |||
| 0a485eafcb | |||
| e0c11956a6 | |||
| da6a9bf3eb | |||
| dacd11e1cc | |||
| fc854b4c77 | |||
| 4dcc1f0374 | |||
| fc57390242 | |||
| bd15ef0a0c | |||
| 967ecafc33 | |||
| 29576da985 | |||
| 200a2556ef | |||
| ae0ab5025e | |||
| aa74276b25 | |||
| b03112a5dd | |||
| a3f49df62d | |||
| aa2af3f6dd | |||
| 20dcbc593c | |||
| 472ba8c1fd | |||
| d8345a44a4 | |||
| a187cb6c9c | |||
| b89c0b35d1 | |||
| 7ffcc0a5e7 | |||
| bde43fbdfb | |||
| 3728b2208f | |||
| dc52a756ee | |||
| 98dc886841 | |||
| d0cf104e43 | |||
| d7ed2412f6 | |||
| 7d38f0e234 | |||
| 3e8d072d24 | |||
| 84ac771893 | |||
| 3a9e0b5be6 | |||
| 9694ff433f | |||
| 2e82e78b98 | |||
| aaef4bee27 | |||
| 4ca8569488 | |||
| 8377ada3e0 | |||
| 8a034d59ed | |||
| 8e492d8798 | |||
| 7974ef80d7 | |||
| 3664d86430 | |||
| 9adef80d6b | |||
| be57adaee7 | |||
| d117e442a4 | |||
| 8820bc0796 | |||
| 57a64de023 | |||
| 5ed689ceb0 | |||
| 25f1765f36 | |||
| 063bd58802 | |||
| 901c6b34fa | |||
| 5b2d6488a2 | |||
| f6f35415d1 | |||
| 6c6069e963 | |||
| 6219d82560 | |||
| 1dcd7a16ab | |||
| b60caeb9dd | |||
| 4c4768aaf3 | |||
| 2f4ac0a663 | |||
| 23a446f852 | |||
| ec48334a1a | |||
| f4c061d412 | |||
| 31a076d7b3 | |||
| 6bd43d986c | |||
| dd32a2f15a | |||
| c88c20820f | |||
| 86de510731 | |||
| 0b31fbf827 | |||
| 34ad1450eb | |||
| e6ba71390d | |||
| f0c8dbe0ec | |||
| bf046a8ccb | |||
| b05ba7683e | |||
| aedf8dad15 | |||
| 74ebb7c722 | |||
| 1307f66494 | |||
| 448a24cb36 | |||
| 7266f23450 | |||
| c0ad31acfc | |||
| 25d3a0de27 |
@@ -45,7 +45,7 @@ stub/**.*-stamp
|
||||
stub/tmp*/*
|
||||
stub/**/tmp*/*
|
||||
|
||||
stub/tools/armpe/armpe_tester
|
||||
stub/tools/armpe/armpe_tester{,.exe,.out}
|
||||
|
||||
stub/tools/sstrip/amd64-linux-sstrip
|
||||
stub/tools/sstrip/i386-linux-sstrip
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
|
||||
155618b5b7930f97bd84b82befa7a4fd6672efb3 RELEASE_304
|
||||
1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301
|
||||
223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190
|
||||
2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194
|
||||
@@ -6,6 +7,7 @@
|
||||
396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291
|
||||
46f3a6cca02603000fadc16637b02e30caddd909 RELEASE_302
|
||||
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
|
||||
95c558f81a0b8d5bb2bede4c8208bb84ae7d1e58 RELEASE_303
|
||||
a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292
|
||||
a916a2fe22de45167d25abcb40008315f415221c RELEASE_201
|
||||
a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2008 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#
|
||||
# UPX toplevel Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
@@ -36,13 +38,5 @@ endif
|
||||
$(MAKE) -C doc $@
|
||||
|
||||
|
||||
ifneq ($(wildcard .hg/.),)
|
||||
# automatically generate ChangeLog from local Mercurial repo
|
||||
ChangeLog:
|
||||
hg log --style=changelog > $@
|
||||
.PHONY: ChangeLog
|
||||
endif
|
||||
|
||||
|
||||
.PHONY: default all mostlyclean clean distclean maintainer-clean
|
||||
|
||||
|
||||
@@ -2,6 +2,25 @@
|
||||
User visible changes for UPX
|
||||
==================================================================
|
||||
|
||||
Changes in 3.05 (27 Apr 2010):
|
||||
* i386-linux and amd64-linux support shared libraries (DT_INIT must
|
||||
exist, all info needed by runtime loader must be first in .text, etc.)
|
||||
* Linux /proc/self/exe now is preserved by default, by leaving behind
|
||||
one page. New compress-time option --unmap-all-pages is available.
|
||||
* Withdraw support for shared libraries on Darwin (Apple Mac OS X)
|
||||
because upx does not understand enough about .dylib.
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.04 (27 Sep 2009):
|
||||
* new format Mach/AMD64 supports 64-bit programs on Apple Macintosh.
|
||||
* new formats Dylib/i386 and Dylib/ppc32 support shared libraries
|
||||
[such as browser plugins] on Darwin (Apple Macintosh). An existing
|
||||
-init function (LC_ROUTINES command) is required.
|
||||
* new format vmlinuz/armel for Debian NSLU2 (etc.) linux kernel
|
||||
* bvmlinuz boot protocol 2.08 for 386 Linux kernel
|
||||
* Extended ABI version 4 for armel-eabi ARM Linux ELF
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.03 (27 Apr 2008):
|
||||
* implement cache flushing for PowerPC (esp. model 440)
|
||||
* fix cache flushing on MIPS (>3 MiB compressed, or with holes)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2008 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2008 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -108,9 +108,9 @@ THE FUTURE
|
||||
COPYRIGHT
|
||||
=========
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 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-2008 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2008 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
+22
-11
@@ -1,5 +1,5 @@
|
||||
Decompressing ELF Directly to Memory on Linux/x86
|
||||
Copyright (C) 2000-2008 John F. Reiser jreiser@BitWagon.com
|
||||
Copyright (C) 2000-2010 John F. Reiser jreiser@BitWagon.com
|
||||
|
||||
References:
|
||||
<elf.h> definitions for the ELF file format
|
||||
@@ -64,16 +64,27 @@ assuming that its automatic stack variables are initialized to zero),
|
||||
and remove (all but 4 bytes of) the decompression program (and
|
||||
compressed executable) from the address space.
|
||||
|
||||
Because the UPX runtime stub removes all traces of the compressed file
|
||||
from the address space, then the Linux kernel erases the symlink
|
||||
/proc/self/exe. Linux stores the pathname argument that was specified
|
||||
to execve() immediately after the '\0' which terminates the character
|
||||
string of the last environment variable [as of execve()]. This is true
|
||||
for at least all Linux 2.6, 2.4, and 2.2 kernels. The pathname is not
|
||||
"bound" to the file as strongly as /proc/self/exe (the file may be changed
|
||||
without affecting the pathname), but the pathname does provide some
|
||||
information. The pathname may be relative to the working directory,
|
||||
so look before any chdir().
|
||||
As of upx-3.05, by default on Linux, upon decompression then one page
|
||||
of the compressed executable remains mapped into the address space
|
||||
of the process. If all of the pages of the compressed executable are
|
||||
unmapped, then the Linux kernel erases the symlink /proc/self/exe,
|
||||
and this can cause trouble for the runtime shared library loader
|
||||
expanding $ORIGIN in -rpath, or for application code that relies on
|
||||
/proc/self/exe. Use the compress-time command-line option
|
||||
--unmap-all-pages to achieve that effect at run time. Upx-3.04
|
||||
and previous versions did this by default with no option. However,
|
||||
too much other software erroneously assumes that /proc/self/exe
|
||||
always exists.
|
||||
|
||||
Linux stores the pathname argument that was specified to execve()
|
||||
immediately after the '\0' which terminates the character string of the
|
||||
last environment variable [as of execve()]. This is true for at least
|
||||
all Linux 2.6, 2.4, and 2.2 kernels. Linux kernel 2.6.29 and later
|
||||
records a pointer to that character string in Elf32_auxv[AT_EXECFN].
|
||||
The pathname is not "bound" to the file as strongly as /proc/self/exe
|
||||
(the file may be changed without affecting the pathname), but the
|
||||
pathname does provide some information. The pathname may be relative
|
||||
to the working directory, so look before any chdir().
|
||||
|
||||
The Elf formats for Linux add an environment variable named " " [three
|
||||
spaces] which saves the results of readlink("/proc/self/exe",,) before
|
||||
|
||||
+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-2008 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
|
||||
Copyright (C) 2002-2008 Jens Medoch
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
|
||||
+5
-2
@@ -1,6 +1,8 @@
|
||||
#
|
||||
# UPX Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
@@ -36,8 +38,9 @@ CXXFLAGS += -O0 -g
|
||||
else
|
||||
CXXFLAGS += -O2
|
||||
endif
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
|
||||
##CXXFLAGS += -Wshadow
|
||||
CXXFLAGS_WERROR = -Werror
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wshadow -Wwrite-strings
|
||||
CXXFLAGS += $(CXXFLAGS_WERROR)
|
||||
endif
|
||||
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
|
||||
CXXLD ?= $(CXX)
|
||||
|
||||
+23
-41
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -282,12 +282,12 @@ inline unsigned acc_swap32p(const acc_uint32e_t *p)
|
||||
|
||||
inline void acc_swab16s(acc_uint16e_t *p)
|
||||
{
|
||||
*p = acc_swab16(*p);
|
||||
*p = (acc_uint16e_t) acc_swab16(*p);
|
||||
}
|
||||
|
||||
inline void acc_swab32s(acc_uint32e_t *p)
|
||||
{
|
||||
*p = acc_swab32(*p);
|
||||
*p = (acc_uint32e_t) acc_swab32(*p);
|
||||
}
|
||||
|
||||
|
||||
@@ -313,8 +313,7 @@ inline void acc_ua_swab32s(void *p)
|
||||
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
|
||||
**************************************************************************/
|
||||
|
||||
struct BE16
|
||||
{
|
||||
__packed_struct(BE16)
|
||||
unsigned char d[2];
|
||||
|
||||
//inline BE16() { }
|
||||
@@ -332,12 +331,10 @@ struct BE16
|
||||
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct BE32
|
||||
{
|
||||
__packed_struct(BE32)
|
||||
unsigned char d[4];
|
||||
|
||||
//inline BE32() { }
|
||||
@@ -355,12 +352,10 @@ struct BE32
|
||||
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct BE64
|
||||
{
|
||||
__packed_struct(BE64)
|
||||
unsigned char d[8];
|
||||
|
||||
//inline BE64() { }
|
||||
@@ -378,12 +373,10 @@ struct BE64
|
||||
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_be64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE16
|
||||
{
|
||||
__packed_struct(LE16)
|
||||
unsigned char d[2];
|
||||
|
||||
//inline LE16() { }
|
||||
@@ -401,12 +394,10 @@ struct LE16
|
||||
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE32
|
||||
{
|
||||
__packed_struct(LE32)
|
||||
unsigned char d[4];
|
||||
|
||||
//inline LE32() { }
|
||||
@@ -424,12 +415,10 @@ struct LE32
|
||||
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE64
|
||||
{
|
||||
__packed_struct(LE64)
|
||||
unsigned char d[8];
|
||||
|
||||
//inline LE64() { }
|
||||
@@ -447,8 +436,7 @@ struct LE64
|
||||
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_le64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -599,13 +587,13 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
// forward declarations
|
||||
namespace N_BELE_CTP {
|
||||
class BEPolicy; class LEPolicy;
|
||||
struct BEPolicy; struct LEPolicy;
|
||||
extern const BEPolicy be_policy;
|
||||
extern const LEPolicy le_policy;
|
||||
}
|
||||
namespace N_BELE_RTP {
|
||||
class AbstractPolicy;
|
||||
class BEPolicy; class LEPolicy;
|
||||
struct AbstractPolicy;
|
||||
struct BEPolicy; struct LEPolicy;
|
||||
extern const BEPolicy be_policy;
|
||||
extern const LEPolicy le_policy;
|
||||
}
|
||||
@@ -623,16 +611,10 @@ namespace N_BELE_RTP {
|
||||
}
|
||||
|
||||
namespace N_BELE_CTP {
|
||||
|
||||
template <class T>
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP();
|
||||
template <>
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP<BEPolicy>()
|
||||
{ return &N_BELE_RTP::be_policy; }
|
||||
template <>
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP<LEPolicy>()
|
||||
{ return &N_BELE_RTP::le_policy; }
|
||||
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP(const BEPolicy*)
|
||||
{ return &N_BELE_RTP::be_policy; }
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP(const LEPolicy*)
|
||||
{ return &N_BELE_RTP::le_policy; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+360
-126
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -51,6 +51,9 @@ void lzma_compress_config_t::reset()
|
||||
extern int compress_lzma_dummy;
|
||||
int compress_lzma_dummy = 0;
|
||||
#else
|
||||
#define opt compress_lzma_opt
|
||||
|
||||
#undef USE_LZMA_PROPERTIES
|
||||
|
||||
|
||||
// INFO: the LZMA SDK is covered by a permissive license which allows
|
||||
@@ -90,11 +93,244 @@ int compress_lzma_dummy = 0;
|
||||
// while you keep LZMA SDK code unmodified.
|
||||
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#include "C/7zVersion.h"
|
||||
#if (WITH_LZMA != (0x100 * MY_VER_MAJOR) + (0x10 * (MY_VER_MINOR / 10)) + (MY_VER_MINOR % 10))
|
||||
# error "WITH_LZMA version mismatch"
|
||||
#endif
|
||||
#include "C/Types.h"
|
||||
static void *cb_alloc(void *, size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
static void cb_free(void *, void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// cruft because of pseudo-COM layer
|
||||
// compress defaults
|
||||
**************************************************************************/
|
||||
|
||||
#undef USE_LZMA_PROPERTIES
|
||||
static int prepare(lzma_compress_result_t *res,
|
||||
unsigned src_len, int method, int level,
|
||||
const lzma_compress_config_t *lcconf)
|
||||
{
|
||||
// setup defaults
|
||||
res->pos_bits = 2; // 0 .. 4
|
||||
res->lit_pos_bits = 0; // 0 .. 4
|
||||
res->lit_context_bits = 3; // 0 .. 8
|
||||
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
|
||||
res->fast_mode = 2;
|
||||
res->num_fast_bytes = 64; // 5 .. 273
|
||||
res->match_finder_cycles = 0;
|
||||
#if 1
|
||||
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value_c;
|
||||
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
|
||||
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value_c;
|
||||
res->dict_size = lzma_compress_config_t::dict_size_t::default_value_c;
|
||||
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
|
||||
#endif
|
||||
// method overrides
|
||||
if (method >= 0x100) {
|
||||
res->pos_bits = (method >> 16) & 15;
|
||||
res->lit_pos_bits = (method >> 12) & 15;
|
||||
res->lit_context_bits = (method >> 8) & 15;
|
||||
}
|
||||
#if 0
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MiB of stack during runtime decompression.
|
||||
res->lit_pos_bits = 4;
|
||||
res->lit_context_bits = 8;
|
||||
#endif
|
||||
|
||||
// FIXME: tune these settings according to level
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
res->dict_size = 256 * 1024;
|
||||
res->fast_mode = 0;
|
||||
res->num_fast_bytes = 8;
|
||||
break;
|
||||
case 2:
|
||||
res->dict_size = 256 * 1024;
|
||||
res->fast_mode = 0;
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
case 8:
|
||||
break;
|
||||
case 9:
|
||||
res->dict_size = 8 * 1024 * 1024;
|
||||
break;
|
||||
case 10:
|
||||
res->dict_size = src_len;
|
||||
break;
|
||||
default:
|
||||
goto error;
|
||||
}
|
||||
|
||||
// cconf overrides
|
||||
if (lcconf)
|
||||
{
|
||||
oassign(res->pos_bits, lcconf->pos_bits);
|
||||
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
|
||||
oassign(res->lit_context_bits, lcconf->lit_context_bits);
|
||||
oassign(res->dict_size, lcconf->dict_size);
|
||||
oassign(res->num_fast_bytes, lcconf->num_fast_bytes);
|
||||
}
|
||||
|
||||
// limit dictionary size
|
||||
if (res->dict_size > src_len)
|
||||
res->dict_size = src_len;
|
||||
|
||||
// limit num_probs
|
||||
if (lcconf && lcconf->max_num_probs)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned n = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
if (n <= lcconf->max_num_probs)
|
||||
break;
|
||||
if (res->lit_pos_bits > res->lit_context_bits)
|
||||
{
|
||||
if (res->lit_pos_bits == 0)
|
||||
goto error;
|
||||
res->lit_pos_bits -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (res->lit_context_bits == 0)
|
||||
goto error;
|
||||
res->lit_context_bits -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#define kLiteralNextStates kLiteralNextStates_enc
|
||||
#include "C/LzmaEnc.h"
|
||||
#include "C/LzmaEnc.c"
|
||||
#include "C/LzFind.c"
|
||||
#undef kLiteralNextStates
|
||||
#undef kNumFullDistances
|
||||
|
||||
|
||||
struct upx_ICompressProgress {
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
upx_callback_p cb;
|
||||
};
|
||||
|
||||
static SRes cb_progress(void *p, UInt64 inSize, UInt64 outSize) {
|
||||
upx_callback_p cb = ((upx_ICompressProgress *) p)->cb;
|
||||
if (cb && cb->nprogress)
|
||||
cb->nprogress(cb, (unsigned) inSize, (unsigned) outSize);
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(M_IS_LZMA(method));
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
|
||||
int r = UPX_E_ERROR;
|
||||
int rh;
|
||||
|
||||
unsigned dst_avail = *dst_len;
|
||||
*dst_len = 0;
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
upx_ICompressProgress progress;
|
||||
progress.Progress = cb_progress; progress.cb = cb;
|
||||
|
||||
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
|
||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
goto error;
|
||||
|
||||
CLzmaEncProps props; memset(&props, 0, sizeof(props));
|
||||
props.level = level;
|
||||
LzmaEncProps_Init(&props);
|
||||
props.pb = res->pos_bits;
|
||||
props.lp = res->lit_pos_bits;
|
||||
props.lc = res->lit_context_bits;
|
||||
props.dictSize = res->dict_size;
|
||||
props.algo = res->fast_mode ? 1 : 0;
|
||||
props.fb = res->num_fast_bytes;
|
||||
props.mc = res->match_finder_cycles;
|
||||
|
||||
unsigned char props_buf[LZMA_PROPS_SIZE];
|
||||
SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE;
|
||||
|
||||
#if defined(USE_LZMA_PROPERTIES)
|
||||
if (dst_avail < 1)
|
||||
goto error;
|
||||
dst[0] = 0; // filled below
|
||||
dst += 1; *dst_len += 1; dst_avail -= 1;
|
||||
#else
|
||||
if (dst_avail < 2)
|
||||
goto error;
|
||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||
unsigned tt; tt = res->lit_context_bits + res->lit_pos_bits;
|
||||
dst[0] = ((tt << 3) | res->pos_bits);
|
||||
dst[1] = ((res->lit_pos_bits << 4) | (res->lit_context_bits));
|
||||
dst += 2; *dst_len += 2; dst_avail -= 2;
|
||||
#endif
|
||||
SizeT x_len; x_len = dst_avail;
|
||||
rh = LzmaEncode(dst, &x_len, src, src_len,
|
||||
&props, props_buf, &props_buf_size, 0,
|
||||
(ICompressProgress *) (void *) &progress, &cba, &cba);
|
||||
assert(x_len <= dst_avail);
|
||||
*dst_len += x_len;
|
||||
if (rh == SZ_OK) {
|
||||
#if defined(USE_LZMA_PROPERTIES)
|
||||
dst[-1] = props_buf[0];
|
||||
#endif
|
||||
r = UPX_E_OK;
|
||||
}
|
||||
|
||||
error:
|
||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress - cruft because of pseudo-COM layer
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef MSDOS
|
||||
#undef OS2
|
||||
@@ -241,128 +477,25 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
NCoderPropID::kMatchFinder // 7 mf
|
||||
};
|
||||
PROPVARIANT pr[8];
|
||||
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4;
|
||||
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
|
||||
unsigned nprops = 7;
|
||||
|
||||
// setup defaults
|
||||
pr[0].uintVal = 2; // 0 .. 4
|
||||
pr[1].uintVal = 0; // 0 .. 4
|
||||
pr[2].uintVal = 3; // 0 .. 8
|
||||
pr[3].uintVal = 4 * 1024 * 1024; // 1 .. 2**30
|
||||
pr[4].uintVal = 2;
|
||||
pr[5].uintVal = 64; // 5 .. 273
|
||||
pr[6].uintVal = 0;
|
||||
#ifdef COMPRESS_MF_BT4
|
||||
const unsigned nprops = 8;
|
||||
static wchar_t matchfinder[] = L"BT4";
|
||||
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
|
||||
pr[nprops].vt = VT_BSTR;
|
||||
pr[nprops].bstrVal = matchfinder;
|
||||
nprops++;
|
||||
pr[7].vt = VT_BSTR; pr[7].bstrVal = matchfinder;
|
||||
#else
|
||||
const unsigned nprops = 7;
|
||||
#endif
|
||||
#if 1
|
||||
pr[0].uintVal = lzma_compress_config_t::pos_bits_t::default_value_c;
|
||||
pr[1].uintVal = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
|
||||
pr[2].uintVal = lzma_compress_config_t::lit_context_bits_t::default_value_c;
|
||||
pr[3].uintVal = lzma_compress_config_t::dict_size_t::default_value_c;
|
||||
pr[5].uintVal = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
|
||||
#endif
|
||||
// method overrides
|
||||
if (method >= 0x100) {
|
||||
pr[0].uintVal = (method >> 16) & 15;
|
||||
pr[1].uintVal = (method >> 12) & 15;
|
||||
pr[2].uintVal = (method >> 8) & 15;
|
||||
}
|
||||
#if 0
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MiB of stack during runtime decompression.
|
||||
pr[1].uintVal = 4;
|
||||
pr[2].uintVal = 8;
|
||||
#endif
|
||||
|
||||
// FIXME: tune these settings according to level
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
pr[3].uintVal = 256 * 1024;
|
||||
pr[4].uintVal = 0;
|
||||
pr[5].uintVal = 8;
|
||||
break;
|
||||
case 2:
|
||||
pr[3].uintVal = 256 * 1024;
|
||||
pr[4].uintVal = 0;
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
case 8:
|
||||
break;
|
||||
case 9:
|
||||
pr[3].uintVal = 8 * 1024 * 1024;
|
||||
break;
|
||||
case 10:
|
||||
pr[3].uintVal = src_len;
|
||||
break;
|
||||
default:
|
||||
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4;
|
||||
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
// cconf overrides
|
||||
if (lcconf)
|
||||
{
|
||||
oassign(pr[0].uintVal, lcconf->pos_bits);
|
||||
oassign(pr[1].uintVal, lcconf->lit_pos_bits);
|
||||
oassign(pr[2].uintVal, lcconf->lit_context_bits);
|
||||
oassign(pr[3].uintVal, lcconf->dict_size);
|
||||
oassign(pr[5].uintVal, lcconf->num_fast_bytes);
|
||||
}
|
||||
|
||||
// limit dictionary size
|
||||
if (pr[3].uintVal > src_len)
|
||||
pr[3].uintVal = src_len;
|
||||
|
||||
// limit num_probs
|
||||
if (lcconf && lcconf->max_num_probs)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned n = 1846 + (768 << (pr[2].uintVal + pr[1].uintVal));
|
||||
if (n <= lcconf->max_num_probs)
|
||||
break;
|
||||
if (pr[1].uintVal > pr[2].uintVal)
|
||||
{
|
||||
if (pr[1].uintVal == 0)
|
||||
goto error;
|
||||
pr[1].uintVal -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pr[2].uintVal == 0)
|
||||
goto error;
|
||||
pr[2].uintVal -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res->pos_bits = pr[0].uintVal;
|
||||
res->lit_pos_bits = pr[1].uintVal;
|
||||
res->lit_context_bits = pr[2].uintVal;
|
||||
res->dict_size = pr[3].uintVal;
|
||||
res->fast_mode = pr[4].uintVal;
|
||||
res->num_fast_bytes = pr[5].uintVal;
|
||||
res->match_finder_cycles = pr[6].uintVal;
|
||||
//res->num_probs = LzmaGetNumProbs(&s.Properties));
|
||||
//res->num_probs = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
|
||||
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
pr[0].uintVal = res->pos_bits;
|
||||
pr[1].uintVal = res->lit_pos_bits;
|
||||
pr[2].uintVal = res->lit_context_bits;
|
||||
pr[3].uintVal = res->dict_size;
|
||||
pr[4].uintVal = res->fast_mode;
|
||||
pr[5].uintVal = res->num_fast_bytes;
|
||||
pr[6].uintVal = res->match_finder_cycles;
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
try {
|
||||
@@ -413,17 +546,116 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
}
|
||||
|
||||
error:
|
||||
*dst_len = os.b_pos;
|
||||
*dst_len = (unsigned) os.b_pos;
|
||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||
//printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
|
||||
#undef _LZMA_PROB32
|
||||
#include "C/LzmaDec.h"
|
||||
#include "C/LzmaDec.c"
|
||||
|
||||
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
#define Properties prop
|
||||
assert(M_IS_LZMA(method));
|
||||
// see res->num_probs above
|
||||
COMPILE_TIME_ASSERT(sizeof(CLzmaProb) == 2)
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
|
||||
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
CLzmaDec s; memset(&s, 0, sizeof(s));
|
||||
SizeT srcLen = 0;
|
||||
int r = UPX_E_ERROR;
|
||||
SRes rh;
|
||||
ELzmaStatus status;
|
||||
|
||||
#if defined(USE_LZMA_PROPERTIES)
|
||||
rh = LzmaProps_Decode(&s.Properties, src, src_len);
|
||||
if (rh != 0)
|
||||
goto error;
|
||||
src += 1; src_len -= 1;
|
||||
#else
|
||||
if (src_len < 3)
|
||||
goto error;
|
||||
s.Properties.pb = src[0] & 7;
|
||||
s.Properties.lp = (src[1] >> 4);
|
||||
s.Properties.lc = src[1] & 15;
|
||||
if (s.Properties.pb >= 5) goto error;
|
||||
if (s.Properties.lp >= 5) goto error;
|
||||
if (s.Properties.lc >= 9) goto error;
|
||||
// extra
|
||||
if ((src[0] >> 3) != (int)(s.Properties.lc + s.Properties.lp)) goto error;
|
||||
src += 2; src_len -= 2;
|
||||
#endif
|
||||
s.Properties.dicSize = 0;
|
||||
|
||||
if (cresult)
|
||||
{
|
||||
assert(cresult->method == method);
|
||||
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
|
||||
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
|
||||
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
||||
assert(cresult->result_lzma.num_probs == (unsigned) LzmaProps_GetNumProbs(&s.Properties));
|
||||
const lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
UNUSED(res);
|
||||
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
}
|
||||
|
||||
rh = LzmaDec_AllocateProbs2(&s, &s.Properties, &cba);
|
||||
if (rh != SZ_OK)
|
||||
{
|
||||
r = UPX_E_OUT_OF_MEMORY;
|
||||
goto error;
|
||||
}
|
||||
|
||||
s.dic = dst; s.dicPos = 0; s.dicBufSize = *dst_len;
|
||||
LzmaDec_Init(&s);
|
||||
srcLen = src_len;
|
||||
rh = LzmaDec_DecodeToDic(&s, *dst_len, src, &srcLen, LZMA_FINISH_ANY, &status);
|
||||
assert(srcLen <= src_len);
|
||||
assert(s.dicPos <= *dst_len);
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
rh = SZ_ERROR_INPUT_EOF;
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
|
||||
{
|
||||
r = UPX_E_OK;
|
||||
if (srcLen != src_len)
|
||||
r = UPX_E_INPUT_NOT_CONSUMED;
|
||||
}
|
||||
error:
|
||||
*dst_len = s.dicPos;
|
||||
LzmaDec_FreeProbs(&s, &cba);
|
||||
return r;
|
||||
#undef Properties
|
||||
}
|
||||
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef _LZMA_IN_CB
|
||||
#undef _LZMA_OUT_READ
|
||||
#undef _LZMA_PROB32
|
||||
@@ -503,11 +735,11 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
error:
|
||||
*dst_len = dst_out;
|
||||
free(s.Probs);
|
||||
|
||||
UNUSED(cresult);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// test_overlap - see <ucl/ucl.h> for semantics
|
||||
@@ -545,14 +777,16 @@ int upx_lzma_test_overlap ( const upx_bytep buf,
|
||||
|
||||
const char *upx_lzma_version_string(void)
|
||||
{
|
||||
#if (WITH_LZMA + 0 == 0x457)
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
return MY_VERSION;
|
||||
#elif (WITH_LZMA + 0 == 0x457)
|
||||
return "4.57";
|
||||
#elif (WITH_LZMA + 0 == 0x449)
|
||||
return "4.49";
|
||||
#elif (WITH_LZMA + 0 == 0x443)
|
||||
return "4.43";
|
||||
#else
|
||||
# error "unknown WITH_LZMA version"
|
||||
# error "unknown WITH_LZMA version"
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -85,7 +85,7 @@ static int convert_errno_from_ucl(int r)
|
||||
|
||||
|
||||
extern "C" {
|
||||
static void wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
|
||||
static void __UCL_CDECL wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
|
||||
{
|
||||
if (state != -1 && state != 3) return;
|
||||
upx_callback_p cb = (upx_callback_p) user;
|
||||
@@ -120,7 +120,7 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
|
||||
ucl_compress_config_t cconf; cconf.reset();
|
||||
if (cconf_parm)
|
||||
cconf = cconf_parm->conf_ucl; // struct copy
|
||||
memcpy(&cconf, &cconf_parm->conf_ucl, sizeof(cconf)); // cconf = cconf_parm->conf_ucl; // struct copy
|
||||
|
||||
ucl_uint *res = cresult->result_ucl.result;
|
||||
// assume no info available - fill in worst case results
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+53
-15
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -36,6 +36,21 @@
|
||||
// ACC
|
||||
**************************************************************************/
|
||||
|
||||
#if (defined(_WIN32) || defined(_WIN64)) && defined(_MSC_VER)
|
||||
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE 1
|
||||
#endif
|
||||
#ifndef _CRT_NONSTDC_NO_WARNINGS
|
||||
#define _CRT_NONSTDC_NO_WARNINGS 1
|
||||
#endif
|
||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "miniacc.h"
|
||||
#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
# undef HAVE_UTIME_H /* this pulls in <windows.h> */
|
||||
@@ -78,10 +93,13 @@
|
||||
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# elif defined(__linux__)
|
||||
# pragma warning(error: 424) // #424: extra ";" ignored
|
||||
//# pragma warning(disable: 128) // #128: loop is not reachable from preceding code
|
||||
//# pragma warning(disable: 181) // #181: argument is incompatible with corresponding format string conversion
|
||||
# pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier
|
||||
# pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits
|
||||
# pragma warning(disable: 981) // #981: operands are evaluated in unspecified order
|
||||
# pragma warning(disable: 1418) // #1418: external definition with no prior declaration
|
||||
# pragma warning(disable: 1418) // #1418: external function definition with no prior declaration
|
||||
//# pragma warning(disable: 1419) // #1419: external declaration in primary source file
|
||||
# else
|
||||
# error "untested platform"
|
||||
# endif
|
||||
@@ -90,6 +108,7 @@
|
||||
# error "need Visual C++ 5.0 or newer"
|
||||
# endif
|
||||
# pragma warning(error: 4096) // W2: '__cdecl' must be used with '...'
|
||||
# pragma warning(error: 4138) // Wx: '*/' found outside of comment
|
||||
# pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B'
|
||||
# pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated
|
||||
# pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated
|
||||
@@ -107,10 +126,13 @@
|
||||
#elif (ACC_CC_SUNPROC)
|
||||
//# pragma error_messages(off,"badargtype2w") // FIXME
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# if (__WATCOMC__ < 1100)
|
||||
# error "need Watcom C++ 11.0c or newer"
|
||||
# if (__WATCOMC__ < 1280)
|
||||
# error "need Open Watcom C++ 1.8 or newer" // because earlier versions do not support nested classes
|
||||
# endif
|
||||
# if defined(__cplusplus)
|
||||
# pragma warning 367 9 // w3: conditional expression in if statement is always true
|
||||
# pragma warning 368 9 // w3: conditional expression in if statement is always false
|
||||
# pragma warning 389 9 // w3: integral value may be truncated
|
||||
# pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality)
|
||||
# endif
|
||||
#endif
|
||||
@@ -137,6 +159,9 @@
|
||||
#endif
|
||||
|
||||
// just in case
|
||||
#undef _
|
||||
#undef __
|
||||
#undef ___
|
||||
#undef NDEBUG
|
||||
#undef dos
|
||||
#undef linux
|
||||
@@ -160,6 +185,9 @@
|
||||
#if 0 && !defined(WITH_LZMA)
|
||||
# define WITH_LZMA 1
|
||||
#endif
|
||||
#if 1 && (ACC_CC_WATCOMC)
|
||||
# undef WITH_LZMA
|
||||
#endif
|
||||
#if defined(UPX_OFFICIAL_BUILD)
|
||||
# if !defined(WITH_LZMA) || !defined(WITH_NRV) || !defined(WITH_UCL)
|
||||
# error
|
||||
@@ -301,16 +329,18 @@
|
||||
#endif
|
||||
|
||||
|
||||
#undef __attribute_packed
|
||||
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||
# if (ACC_ARCH_I386) && (ACC_CC_INTELC && (__INTEL_COMPILER < 800))
|
||||
# elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
|
||||
# else
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# endif
|
||||
#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)
|
||||
# define __packed_struct(s) struct s {
|
||||
# define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# define __packed_struct(s) _Packed struct s {
|
||||
# define __packed_struct_end() };
|
||||
#endif
|
||||
#if !defined(__attribute_packed)
|
||||
# define __attribute_packed
|
||||
#if !defined(__packed_struct)
|
||||
# define __packed_struct(s) struct s {
|
||||
# define __packed_struct_end() };
|
||||
#endif
|
||||
|
||||
|
||||
@@ -323,8 +353,9 @@
|
||||
|
||||
#define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
|
||||
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; } __attribute_packed; \
|
||||
__packed_struct(acc_tmp_t) acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; __packed_struct_end() \
|
||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2*sizeof(b)+sizeof(a)) \
|
||||
COMPILE_TIME_ASSERT(sizeof(((acc_tmp_t*)0)->x)+sizeof(((acc_tmp_t*)0)->y)+sizeof(((acc_tmp_t*)0)->z) == 2*sizeof(b)+sizeof(a)) \
|
||||
}
|
||||
#if defined(__acc_alignof)
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
@@ -459,6 +490,12 @@ private:
|
||||
#define UPX_F_VMLINUX_ARMEL 28
|
||||
#define UPX_F_MACH_i386 29
|
||||
#define UPX_F_LINUX_ELF32_MIPSEL 30
|
||||
#define UPX_F_VMLINUZ_ARMEL 31
|
||||
#define UPX_F_MACH_ARMEL 32
|
||||
|
||||
#define UPX_F_DYLIB_i386 33
|
||||
#define UPX_F_MACH_AMD64 34
|
||||
#define UPX_F_DYLIB_AMD64 35
|
||||
|
||||
#define UPX_F_PLAIN_TEXT 127
|
||||
|
||||
@@ -471,6 +508,7 @@ private:
|
||||
#define UPX_F_VMLINUX_ARMEB 135
|
||||
#define UPX_F_VMLINUX_PPC32 136
|
||||
#define UPX_F_LINUX_ELF32_MIPSEB 137
|
||||
#define UPX_F_DYLIB_PPC32 138
|
||||
|
||||
|
||||
// compression methods
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+14
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -366,6 +366,7 @@ off_t OutputFile::st_size() const
|
||||
return bytes_written; // too big if seek()+write() instead of rewrite()
|
||||
}
|
||||
struct stat my_st;
|
||||
my_st.st_size = 0;
|
||||
if (::fstat(_fd, &my_st) != 0)
|
||||
throwIOException(_name, errno);
|
||||
return my_st.st_size;
|
||||
@@ -395,6 +396,17 @@ void OutputFile::rewrite(const void *buf, int len)
|
||||
void OutputFile::seek(off_t off, int whence)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
switch (whence) {
|
||||
case SEEK_SET: {
|
||||
if (bytes_written < off) {
|
||||
bytes_written = off;
|
||||
}
|
||||
_length = bytes_written; // cheap, lazy update; needed?
|
||||
} break;
|
||||
case SEEK_END: {
|
||||
_length = bytes_written; // necessary
|
||||
} break;
|
||||
}
|
||||
super::seek(off,whence);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+12
-9
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2004-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2004-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -47,7 +47,7 @@ static int F(Filter *f)
|
||||
// scan
|
||||
const upx_byte *b = f->buf;
|
||||
#endif
|
||||
const unsigned size = umin(f->buf_len, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size = umin(f->buf_len, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = size -4;
|
||||
|
||||
unsigned ic;
|
||||
@@ -72,9 +72,11 @@ static int F(Filter *f)
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0) {
|
||||
if (0!=W_CTO) // FIXME: what is this ???
|
||||
return -1;
|
||||
#if (W_CTO != 0)
|
||||
return -1;
|
||||
#else
|
||||
f->cto = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
const unsigned char cto8 = f->cto;
|
||||
@@ -95,8 +97,9 @@ static int F(Filter *f)
|
||||
lastcall = ic;
|
||||
}
|
||||
else {
|
||||
assert(0==W_CTO // FIXME: what is this ???
|
||||
|| (~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
#if (W_CTO != 0)
|
||||
assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
#endif
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
}
|
||||
@@ -122,7 +125,7 @@ static int F(Filter *f)
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size4 = umin(f->buf_len - 4, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned addvalue = f->addvalue;
|
||||
|
||||
unsigned ic;
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+9
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -51,8 +51,9 @@ void show_head(void)
|
||||
fg = con_fg(f,FG_GREEN);
|
||||
con_fprintf(f,
|
||||
" Ultimate Packer for eXecutables\n"
|
||||
" Copyright (C) 1996 - 2008\n"
|
||||
" Copyright (C) 1996 - %s\n"
|
||||
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
|
||||
UPX_VERSION_YEAR,
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||
V("d"),
|
||||
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
@@ -113,6 +114,7 @@ struct PackerNames
|
||||
{
|
||||
PackerNames *self = (PackerNames *) user;
|
||||
self->add(p);
|
||||
delete p; p = NULL;
|
||||
return NULL;
|
||||
}
|
||||
static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) {
|
||||
@@ -398,10 +400,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-2008 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(fp, "Copyright (C) 1996-2008 Laszlo Molnar\n");
|
||||
fprintf(fp, "Copyright (C) 2000-2008 John F. Reiser\n");
|
||||
fprintf(fp, "Copyright (C) 2002-2008 Jens Medoch\n");
|
||||
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");
|
||||
#if defined(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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+9
-14
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -49,8 +49,8 @@ public:
|
||||
protected:
|
||||
enum { FIXUP_EXTRA = 3 };
|
||||
|
||||
struct le_header_t
|
||||
{ // 0x00
|
||||
__packed_struct(le_header_t)
|
||||
// 0x00
|
||||
char _[2]; // signature: 'LE' || 'LX'
|
||||
char byte_order; // 0 little endian
|
||||
char word_order; // 0 little endian
|
||||
@@ -117,28 +117,23 @@ protected:
|
||||
LE16 device_id;
|
||||
LE16 ddk_version;
|
||||
#endif
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct le_object_table_entry_t
|
||||
{
|
||||
__packed_struct(le_object_table_entry_t)
|
||||
LE32 virtual_size;
|
||||
LE32 base_address;
|
||||
LE32 flags;
|
||||
LE32 pagemap_index;
|
||||
LE32 npages;
|
||||
LE32 reserved;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct le_pagemap_entry_t
|
||||
{
|
||||
__packed_struct(le_pagemap_entry_t)
|
||||
unsigned char h;
|
||||
unsigned char m;
|
||||
unsigned char l;
|
||||
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
virtual void readObjectTable();
|
||||
virtual void writeObjectTable();
|
||||
|
||||
+11
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -469,7 +469,7 @@ int ElfLinker::getSection(const char *sname, int *slen) const
|
||||
const Section *section = findSection(sname);
|
||||
if (slen)
|
||||
*slen = section->size;
|
||||
return section->output - output;
|
||||
return (int) (section->output - output);
|
||||
}
|
||||
|
||||
int ElfLinker::getSectionSize(const char *sname) const
|
||||
@@ -679,7 +679,10 @@ void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
{
|
||||
set_be32(location, get_be32(location) + value);
|
||||
}
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0
|
||||
|| strcmp(type, "R_ARM_THM_XPC22") == 0
|
||||
|| strcmp(type, "R_ARM_THM_PC22") == 0
|
||||
)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
value += ((get_be16(location) & 0x7ff) << 12);
|
||||
@@ -711,7 +714,10 @@ void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
{
|
||||
set_le32(location, get_le32(location) + value);
|
||||
}
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0
|
||||
|| strcmp(type, "R_ARM_THM_XPC22") == 0
|
||||
|| strcmp(type, "R_ARM_THM_PC22") == 0
|
||||
)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
value += ((get_le16(location) & 0x7ff) << 12);
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+30
-9
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -883,6 +883,9 @@ static int do_option(int optc, const char *arg)
|
||||
case 673:
|
||||
opt->ps1_exe.do_8mib = false;
|
||||
break;
|
||||
case 674:
|
||||
opt->o_unix.unmap_all_pages = true; // val ?
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
return -1;
|
||||
@@ -1032,6 +1035,7 @@ static const struct mfx_option longopts[] =
|
||||
{"netbsd", 0x10, 0, 668},
|
||||
{"OpenBSD", 0x10, 0, 669},
|
||||
{"openbsd", 0x10, 0, 669},
|
||||
{"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes
|
||||
// watcom/le
|
||||
{"le", 0x10, 0, 620}, // produce LE output
|
||||
// win32/pe
|
||||
@@ -1257,8 +1261,8 @@ template <class T> struct TestBELE {
|
||||
static bool test(void)
|
||||
{
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(T)
|
||||
struct test1_t { char a; T b; } __attribute_packed;
|
||||
struct test2_t { char a; T b[3]; } __attribute_packed;
|
||||
__packed_struct(test1_t) char a; T b; __packed_struct_end()
|
||||
__packed_struct(test2_t) char a; T b[3]; __packed_struct_end()
|
||||
test1_t t1[7]; UNUSED(t1); test2_t t2[7]; UNUSED(t2);
|
||||
COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T))
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(test1_t)
|
||||
@@ -1270,7 +1274,11 @@ static bool test(void)
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1)
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1)
|
||||
#endif
|
||||
#if 1 && !defined(xUPX_OFFICIAL_BUILD)
|
||||
#if 1 && (ACC_CC_WATCOMC)
|
||||
test1_t t11; COMPILE_TIME_ASSERT(sizeof(t11.a) <= sizeof(t11.b))
|
||||
test2_t t22; COMPILE_TIME_ASSERT(sizeof(t22.a) <= sizeof(t22.b))
|
||||
#endif
|
||||
#if 1 && !defined(UPX_OFFICIAL_BUILD)
|
||||
T allbits; allbits = 0; allbits -= 1;
|
||||
//++allbits; allbits++; --allbits; allbits--;
|
||||
T v1; v1 = 1; v1 *= 2; v1 -= 1;
|
||||
@@ -1343,27 +1351,40 @@ void upx_sanity_check(void)
|
||||
assert(TestBELE<BE32>::test());
|
||||
assert(TestBELE<BE64>::test());
|
||||
{
|
||||
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
static const unsigned char dd[32]
|
||||
#if 1 && (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__)
|
||||
__attribute__((__aligned__(16)))
|
||||
#endif
|
||||
= { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
0, 0, 0, 0, 0 };
|
||||
const unsigned char *d;
|
||||
const N_BELE_RTP::AbstractPolicy *bele;
|
||||
d = dd + 7;
|
||||
assert(upx_adler32(d, 4) == 0x09f003f7);
|
||||
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
|
||||
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
|
||||
bele = &N_BELE_RTP::be_policy;
|
||||
assert(get_be16(d) == 0xfffe);
|
||||
assert(bele->get16(d) == 0xfffe);
|
||||
assert(get_be16_signed(d) == -2);
|
||||
assert(get_be24(d) == 0xfffefd);
|
||||
assert(bele->get24(d) == 0xfffefd);
|
||||
assert(get_be24_signed(d) == -259);
|
||||
assert(get_be32(d) == 0xfffefdfc);
|
||||
assert(bele->get32(d) == 0xfffefdfc);
|
||||
assert(get_be32_signed(d) == -66052);
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
assert(get_le16(d) == 0xfeff);
|
||||
assert(bele->get16(d) == 0xfeff);
|
||||
assert(get_le16_signed(d) == -257);
|
||||
assert(get_le24(d) == 0xfdfeff);
|
||||
assert(bele->get24(d) == 0xfdfeff);
|
||||
assert(get_le24_signed(d) == -131329);
|
||||
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(find_be16(d, 2, 0xfffe) == 0);
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+205
-54
@@ -1,7 +1,9 @@
|
||||
/* ACC -- Automatic Compiler Configuration
|
||||
/* ACC --- Automatic Compiler Configuration
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
||||
@@ -39,7 +41,7 @@
|
||||
|
||||
#ifndef __ACC_H_INCLUDED
|
||||
#define __ACC_H_INCLUDED 1
|
||||
#define ACC_VERSION 20080102L
|
||||
#define ACC_VERSION 20100419L
|
||||
#if defined(__CYGWIN32__) && !defined(__CYGWIN__)
|
||||
# define __CYGWIN__ __CYGWIN32__
|
||||
#endif
|
||||
@@ -577,6 +579,10 @@
|
||||
# define ACC_CC_AZTECC 1
|
||||
# define ACC_INFO_CC "Aztec C"
|
||||
# define ACC_INFO_CCVER ACC_PP_MACRO_EXPAND(__AZTEC_C__)
|
||||
#elif defined(__CODEGEARC__)
|
||||
# define ACC_CC_CODEGEARC 1
|
||||
# define ACC_INFO_CC "CodeGear C"
|
||||
# define ACC_INFO_CCVER ACC_PP_MACRO_EXPAND(__CODEGEARC__)
|
||||
#elif defined(__BORLANDC__)
|
||||
# define ACC_CC_BORLANDC 1
|
||||
# define ACC_INFO_CC "Borland C"
|
||||
@@ -752,6 +758,9 @@
|
||||
#elif (UINT_MAX <= ACC_0xffffL) && defined(__AVR__)
|
||||
# define ACC_ARCH_AVR 1
|
||||
# define ACC_INFO_ARCH "avr"
|
||||
#elif defined(__avr32__) || defined(__AVR32__)
|
||||
# define ACC_ARCH_AVR32 1
|
||||
# define ACC_INFO_ARCH "avr32"
|
||||
#elif defined(__bfin__)
|
||||
# define ACC_ARCH_BLACKFIN 1
|
||||
# define ACC_INFO_ARCH "blackfin"
|
||||
@@ -1310,9 +1319,11 @@ extern "C" {
|
||||
#elif !defined(ACC_ABI_BIG_ENDIAN) && !defined(ACC_ABI_LITTLE_ENDIAN)
|
||||
#if (ACC_ARCH_ALPHA) && (ACC_ARCH_CRAY_MPP)
|
||||
# define ACC_ABI_BIG_ENDIAN 1
|
||||
#elif (ACC_ARCH_IA64) && (ACC_OS_POSIX_LINUX || ACC_OS_WIN64)
|
||||
# define ACC_ABI_LITTLE_ENDIAN 1
|
||||
#elif (ACC_ARCH_ALPHA || ACC_ARCH_AMD64 || ACC_ARCH_BLACKFIN || ACC_ARCH_CRIS || ACC_ARCH_I086 || ACC_ARCH_I386 || ACC_ARCH_MSP430)
|
||||
# define ACC_ABI_LITTLE_ENDIAN 1
|
||||
#elif (ACC_ARCH_M68K || ACC_ARCH_S390)
|
||||
#elif (ACC_ARCH_AVR32 || ACC_ARCH_M68K || ACC_ARCH_S390)
|
||||
# define ACC_ABI_BIG_ENDIAN 1
|
||||
#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__)
|
||||
# if (__LITTLE_ENDIAN__ == 1)
|
||||
@@ -1423,6 +1434,8 @@ extern "C" {
|
||||
# define __acc_alignof(e) __alignof__(e)
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 1300))
|
||||
# define __acc_alignof(e) __alignof(e)
|
||||
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
|
||||
# define __acc_alignof(e) __alignof__(e)
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__acc_alignof)
|
||||
@@ -1471,6 +1484,8 @@ extern "C" {
|
||||
# define __acc_inline __inline
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 900))
|
||||
# define __acc_inline __inline
|
||||
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
|
||||
# define __acc_inline __inline__
|
||||
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||
# define __acc_inline inline
|
||||
#endif
|
||||
@@ -1491,6 +1506,8 @@ extern "C" {
|
||||
# define __acc_forceinline __inline__ __attribute__((__always_inline__))
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 1200))
|
||||
# define __acc_forceinline __forceinline
|
||||
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
|
||||
# define __acc_forceinline __inline__ __attribute__((__always_inline__))
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__acc_forceinline)
|
||||
@@ -1516,6 +1533,8 @@ extern "C" {
|
||||
# else
|
||||
# define __acc_noinline __declspec(noinline)
|
||||
# endif
|
||||
#elif (ACC_CC_SUNPROC && (ACC_CC_SUNPROC >= 0x5100))
|
||||
# define __acc_noinline __attribute__((__noinline__))
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__acc_noinline)
|
||||
@@ -1549,7 +1568,7 @@ extern "C" {
|
||||
# define __acc_nothrow __attribute__((__nothrow__))
|
||||
#elif (ACC_CC_INTELC && (__INTEL_COMPILER >= 450) && ACC_CC_SYNTAX_MSC) && defined(__cplusplus)
|
||||
# define __acc_nothrow __declspec(nothrow)
|
||||
#elif (ACC_CC_INTELC && (__INTEL_COMPILER >= 800) && ACC_CC_SYNTAX_GNUC)
|
||||
#elif (ACC_CC_INTELC && (__INTEL_COMPILER >= 900) && ACC_CC_SYNTAX_GNUC)
|
||||
# define __acc_nothrow __attribute__((__nothrow__))
|
||||
#elif (ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
# define __acc_nothrow __attribute__((__nothrow__))
|
||||
@@ -1654,6 +1673,15 @@ extern "C" {
|
||||
# define ACC_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(ACC_UNCONST_CAST)
|
||||
# if 0 && defined(__cplusplus)
|
||||
# define ACC_UNCONST_CAST(t,e) (const_cast<t> (e))
|
||||
# elif (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
# define ACC_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((acc_uintptr_t) ((const void *) (e))))))
|
||||
# else
|
||||
# define ACC_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e)))))
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(ACC_COMPILE_TIME_ASSERT_HEADER)
|
||||
# if (ACC_CC_AZTECC || ACC_CC_ZORTECHC)
|
||||
# define ACC_COMPILE_TIME_ASSERT_HEADER(e) extern int __acc_cta[1-!(e)];
|
||||
@@ -2187,7 +2215,7 @@ extern "C" {
|
||||
#define HAVE_UMASK 1
|
||||
#define HAVE_UTIME 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#if (ACC_OS_BEOS || ACC_OS_CYGWIN || ACC_OS_POSIX || ACC_OS_QNX)
|
||||
#if (ACC_OS_BEOS || ACC_OS_CYGWIN || ACC_OS_POSIX || ACC_OS_QNX || ACC_OS_VMS)
|
||||
# define HAVE_STRCASECMP 1
|
||||
# define HAVE_STRNCASECMP 1
|
||||
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
|
||||
@@ -2289,8 +2317,12 @@ extern "C" {
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
#elif (ACC_CC_INTELC)
|
||||
# ifndef snprintf
|
||||
# define snprintf _snprintf
|
||||
# endif
|
||||
# ifndef vsnprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
#elif (ACC_CC_LCCWIN32)
|
||||
# define utime _utime
|
||||
#elif (ACC_CC_MSC)
|
||||
@@ -2301,8 +2333,16 @@ extern "C" {
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
# elif (_MSC_VER < 1500)
|
||||
# ifndef snprintf
|
||||
# define snprintf _snprintf
|
||||
# endif
|
||||
# ifndef vsnprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# else
|
||||
# ifndef snprintf
|
||||
# define snprintf _snprintf
|
||||
# endif
|
||||
# endif
|
||||
# if ((_MSC_VER < 800) && ACC_OS_WIN16)
|
||||
# undef HAVE_ALLOCA
|
||||
@@ -2624,7 +2664,7 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
|
||||
# define acc_intptr_t acc_intptr_t
|
||||
# define acc_uintptr_t acc_uintptr_t
|
||||
# define ACC_SIZEOF_ACC_INTPTR_T ACC_SIZEOF_VOID_P
|
||||
#elif (ACC_ARCH_I386 && ACC_CC_MSC && (_MSC_VER >= 1300))
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 1300) && (ACC_SIZEOF_VOID_P == 4) && (ACC_SIZEOF_INT == 4))
|
||||
typedef __w64 int acc_intptr_t;
|
||||
typedef __w64 unsigned int acc_uintptr_t;
|
||||
# define acc_intptr_t acc_intptr_t
|
||||
@@ -2809,7 +2849,7 @@ typedef void (__acc_cdecl_sighandler *acc_sighandler_t)(acc_signo_t);
|
||||
#endif
|
||||
#if (ACC_OPT_UNALIGNED16) && defined(acc_int16e_t)
|
||||
#define ACC_UA_GET16(p) (* (__acc_ua_volatile const acc_uint16e_t*) (__acc_ua_volatile const void*) (p))
|
||||
#define ACC_UA_SET16(p,v) (* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p) = (acc_uint16e_t) (v))
|
||||
#define ACC_UA_SET16(p,v) ((* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint16e_t) (v))
|
||||
#if (ACC_ABI_BIG_ENDIAN)
|
||||
# define ACC_UA_GET_BE16(p) ACC_UA_GET16(p)
|
||||
# define ACC_UA_SET_BE16(p,v) ACC_UA_SET16(p,v)
|
||||
@@ -2845,7 +2885,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE16(__acc_ua_volatile void* pp, unsi
|
||||
#endif
|
||||
#if (ACC_OPT_UNALIGNED32) && defined(acc_int32e_t)
|
||||
#define ACC_UA_GET32(p) (* (__acc_ua_volatile const acc_uint32e_t*) (__acc_ua_volatile const void*) (p))
|
||||
#define ACC_UA_SET32(p,v) (* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p) = (acc_uint32e_t) (v))
|
||||
#define ACC_UA_SET32(p,v) ((* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint32e_t) (v))
|
||||
#if (ACC_ABI_BIG_ENDIAN)
|
||||
# define ACC_UA_GET_BE32(p) ACC_UA_GET32(p)
|
||||
# define ACC_UA_SET_BE32(p,v) ACC_UA_SET32(p,v)
|
||||
@@ -2881,7 +2921,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE32(__acc_ua_volatile void* pp, unsi
|
||||
#endif
|
||||
#if (ACC_OPT_UNALIGNED64) && defined(acc_int64l_t)
|
||||
#define ACC_UA_GET64(p) (* (__acc_ua_volatile const acc_uint64l_t*) (__acc_ua_volatile const void*) (p))
|
||||
#define ACC_UA_SET64(p,v) (* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p) = (acc_uint64l_t) (v))
|
||||
#define ACC_UA_SET64(p,v) ((* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p)) = (acc_uint64l_t) (v))
|
||||
#if (ACC_ABI_BIG_ENDIAN)
|
||||
# define ACC_UA_GET_BE64(p) ACC_UA_GET64(p)
|
||||
# define ACC_UA_SET_BE64(p,v) ACC_UA_SET64(p,v)
|
||||
@@ -3052,7 +3092,7 @@ __acc_gnuc_extension__ typedef unsigned long long acc_ullong_t;
|
||||
# define acc_intptr_t acc_intptr_t
|
||||
# define acc_uintptr_t acc_uintptr_t
|
||||
# define ACC_SIZEOF_ACC_INTPTR_T ACC_SIZEOF_VOID_P
|
||||
#elif (ACC_ARCH_I386 && ACC_CC_MSC && (_MSC_VER >= 1300))
|
||||
#elif (ACC_CC_MSC && (_MSC_VER >= 1300) && (ACC_SIZEOF_VOID_P == 4) && (ACC_SIZEOF_INT == 4))
|
||||
typedef __w64 int acc_intptr_t;
|
||||
typedef __w64 unsigned int acc_uintptr_t;
|
||||
# define acc_intptr_t acc_intptr_t
|
||||
@@ -3236,7 +3276,7 @@ typedef void (__acc_cdecl_sighandler *acc_sighandler_t)(acc_signo_t);
|
||||
#endif
|
||||
#if (ACC_OPT_UNALIGNED16) && defined(acc_int16e_t)
|
||||
#define ACC_UA_GET16(p) (* (__acc_ua_volatile const acc_uint16e_t*) (__acc_ua_volatile const void*) (p))
|
||||
#define ACC_UA_SET16(p,v) (* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p) = (acc_uint16e_t) (v))
|
||||
#define ACC_UA_SET16(p,v) ((* (__acc_ua_volatile acc_uint16e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint16e_t) (v))
|
||||
#if (ACC_ABI_BIG_ENDIAN)
|
||||
# define ACC_UA_GET_BE16(p) ACC_UA_GET16(p)
|
||||
# define ACC_UA_SET_BE16(p,v) ACC_UA_SET16(p,v)
|
||||
@@ -3272,7 +3312,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE16(__acc_ua_volatile void* pp, unsi
|
||||
#endif
|
||||
#if (ACC_OPT_UNALIGNED32) && defined(acc_int32e_t)
|
||||
#define ACC_UA_GET32(p) (* (__acc_ua_volatile const acc_uint32e_t*) (__acc_ua_volatile const void*) (p))
|
||||
#define ACC_UA_SET32(p,v) (* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p) = (acc_uint32e_t) (v))
|
||||
#define ACC_UA_SET32(p,v) ((* (__acc_ua_volatile acc_uint32e_t*) (__acc_ua_volatile void*) (p)) = (acc_uint32e_t) (v))
|
||||
#if (ACC_ABI_BIG_ENDIAN)
|
||||
# define ACC_UA_GET_BE32(p) ACC_UA_GET32(p)
|
||||
# define ACC_UA_SET_BE32(p,v) ACC_UA_SET32(p,v)
|
||||
@@ -3308,7 +3348,7 @@ extern __acc_forceinline void __ACC_UA_SET_LE32(__acc_ua_volatile void* pp, unsi
|
||||
#endif
|
||||
#if (ACC_OPT_UNALIGNED64) && defined(acc_int64l_t)
|
||||
#define ACC_UA_GET64(p) (* (__acc_ua_volatile const acc_uint64l_t*) (__acc_ua_volatile const void*) (p))
|
||||
#define ACC_UA_SET64(p,v) (* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p) = (acc_uint64l_t) (v))
|
||||
#define ACC_UA_SET64(p,v) ((* (__acc_ua_volatile acc_uint64l_t*) (__acc_ua_volatile void*) (p)) = (acc_uint64l_t) (v))
|
||||
#if (ACC_ABI_BIG_ENDIAN)
|
||||
# define ACC_UA_GET_BE64(p) ACC_UA_GET64(p)
|
||||
# define ACC_UA_SET_BE64(p,v) ACC_UA_SET64(p,v)
|
||||
@@ -3929,11 +3969,10 @@ typedef struct acc_pclock_t acc_pclock_t;
|
||||
#define ACC_PCLOCK_MONOTONIC 1
|
||||
#define ACC_PCLOCK_PROCESS_CPUTIME_ID 2
|
||||
#define ACC_PCLOCK_THREAD_CPUTIME_ID 3
|
||||
#define ACC_PCLOCK_REALTIME_HR 4
|
||||
#define ACC_PCLOCK_MONOTONIC_HR 5
|
||||
struct acc_pclock_handle_t {
|
||||
acclib_handle_t h;
|
||||
int mode;
|
||||
int read_error;
|
||||
const char* name;
|
||||
int (*gettime) (acc_pclock_handle_p, acc_pclock_p);
|
||||
#if defined(acc_int64l_t)
|
||||
@@ -3970,6 +4009,7 @@ ACCLIB_EXTERN(int, acc_pclock_flush_cpu_cache) (acc_pclock_handle_p, unsigned);
|
||||
typedef struct {
|
||||
acclib_handle_t h;
|
||||
int mode;
|
||||
int read_error;
|
||||
const char* name;
|
||||
#if defined(__ACCLIB_UCLOCK_USE_PERFCTR)
|
||||
acc_perfctr_handle_t pch;
|
||||
@@ -5586,6 +5626,42 @@ ACCLIB_PUBLIC(long, acc_safe_hwrite) (int fd, const acc_hvoid_p buf, long size)
|
||||
#if !defined(ACCLIB_PUBLIC)
|
||||
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
|
||||
#endif
|
||||
#if 0 && (ACC_OS_POSIX_LINUX && ACC_ARCH_AMD64 && ACC_ASM_SYNTAX_GNUC)
|
||||
#ifndef acc_pclock_syscall_clock_gettime
|
||||
#define acc_pclock_syscall_clock_gettime acc_pclock_syscall_clock_gettime
|
||||
#endif
|
||||
static __acc_noinline long acc_pclock_syscall_clock_gettime(long clockid, struct timespec *ts)
|
||||
{
|
||||
long r;
|
||||
__asm__ __volatile__("syscall\n" : "=a" (r) : "0" (228), "D" (clockid), "S" (ts) : __ACC_ASM_CLOBBER);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
#if 0 && (ACC_OS_POSIX_LINUX && ACC_ARCH_I386 && ACC_ASM_SYNTAX_GNUC)
|
||||
#ifndef acc_pclock_syscall_clock_gettime
|
||||
#define acc_pclock_syscall_clock_gettime acc_pclock_syscall_clock_gettime
|
||||
#endif
|
||||
static __acc_noinline long acc_pclock_syscall_clock_gettime(long clockid, struct timespec *ts)
|
||||
{
|
||||
long r;
|
||||
__asm__ __volatile__("int $0x80\n" : "=a" (r) : "0" (265), "b" (clockid), "c" (ts) : __ACC_ASM_CLOBBER);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
#if 0 && defined(acc_pclock_syscall_clock_gettime)
|
||||
#ifndef acc_pclock_read_clock_gettime_r_syscall
|
||||
#define acc_pclock_read_clock_gettime_r_syscall acc_pclock_read_clock_gettime_r_syscall
|
||||
#endif
|
||||
static int acc_pclock_read_clock_gettime_r_syscall(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (acc_pclock_syscall_clock_gettime(0, &ts) != 0)
|
||||
return -1;
|
||||
c->tv_sec = ts.tv_sec;
|
||||
c->tv_nsec = ts.tv_nsec;
|
||||
ACC_UNUSED(h); return 0;
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_GETTIMEOFDAY)
|
||||
#ifndef acc_pclock_read_gettimeofday
|
||||
#define acc_pclock_read_gettimeofday acc_pclock_read_gettimeofday
|
||||
@@ -5630,6 +5706,20 @@ static int acc_pclock_read_clock(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
ACC_UNUSED(h); return 0;
|
||||
}
|
||||
#endif
|
||||
#if 1 && defined(acc_pclock_syscall_clock_gettime)
|
||||
#ifndef acc_pclock_read_clock_gettime_m_syscall
|
||||
#define acc_pclock_read_clock_gettime_m_syscall acc_pclock_read_clock_gettime_m_syscall
|
||||
#endif
|
||||
static int acc_pclock_read_clock_gettime_m_syscall(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (acc_pclock_syscall_clock_gettime(1, &ts) != 0)
|
||||
return -1;
|
||||
c->tv_sec = ts.tv_sec;
|
||||
c->tv_nsec = ts.tv_nsec;
|
||||
ACC_UNUSED(h); return 0;
|
||||
}
|
||||
#endif
|
||||
#if (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__) && defined(UCLOCKS_PER_SEC)
|
||||
#ifndef acc_pclock_read_uclock
|
||||
#define acc_pclock_read_uclock acc_pclock_read_uclock
|
||||
@@ -5648,10 +5738,10 @@ static int acc_pclock_read_uclock(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
}
|
||||
#endif
|
||||
#if 0 && defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) && defined(acc_int64l_t)
|
||||
#ifndef acc_pclock_read_clock_gettime_p
|
||||
#define acc_pclock_read_clock_gettime_p acc_pclock_read_clock_gettime_p
|
||||
#ifndef acc_pclock_read_clock_gettime_p_libc
|
||||
#define acc_pclock_read_clock_gettime_p_libc acc_pclock_read_clock_gettime_p_libc
|
||||
#endif
|
||||
static int acc_pclock_read_clock_gettime_p(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
static int acc_pclock_read_clock_gettime_p_libc(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) != 0)
|
||||
@@ -5661,6 +5751,20 @@ static int acc_pclock_read_clock_gettime_p(acc_pclock_handle_p h, acc_pclock_p c
|
||||
ACC_UNUSED(h); return 0;
|
||||
}
|
||||
#endif
|
||||
#if 1 && defined(acc_pclock_syscall_clock_gettime)
|
||||
#ifndef acc_pclock_read_clock_gettime_p_syscall
|
||||
#define acc_pclock_read_clock_gettime_p_syscall acc_pclock_read_clock_gettime_p_syscall
|
||||
#endif
|
||||
static int acc_pclock_read_clock_gettime_p_syscall(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (acc_pclock_syscall_clock_gettime(2, &ts) != 0)
|
||||
return -1;
|
||||
c->tv_sec = ts.tv_sec;
|
||||
c->tv_nsec = ts.tv_nsec;
|
||||
ACC_UNUSED(h); return 0;
|
||||
}
|
||||
#endif
|
||||
#if (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_HAVE_WINDOWS_H) && defined(acc_int64l_t)
|
||||
#ifndef acc_pclock_read_getprocesstimes
|
||||
#define acc_pclock_read_getprocesstimes acc_pclock_read_getprocesstimes
|
||||
@@ -5722,10 +5826,10 @@ static int acc_pclock_read_perfctr(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
}
|
||||
#endif
|
||||
#if 0 && defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(acc_int64l_t)
|
||||
#ifndef acc_pclock_read_clock_gettime_t
|
||||
#define acc_pclock_read_clock_gettime_t acc_pclock_read_clock_gettime_t
|
||||
#ifndef acc_pclock_read_clock_gettime_t_libc
|
||||
#define acc_pclock_read_clock_gettime_t_libc acc_pclock_read_clock_gettime_t_libc
|
||||
#endif
|
||||
static int acc_pclock_read_clock_gettime_t(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
static int acc_pclock_read_clock_gettime_t_libc(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0)
|
||||
@@ -5735,6 +5839,20 @@ static int acc_pclock_read_clock_gettime_t(acc_pclock_handle_p h, acc_pclock_p c
|
||||
ACC_UNUSED(h); return 0;
|
||||
}
|
||||
#endif
|
||||
#if 1 && defined(acc_pclock_syscall_clock_gettime)
|
||||
#ifndef acc_pclock_read_clock_gettime_t_syscall
|
||||
#define acc_pclock_read_clock_gettime_t_syscall acc_pclock_read_clock_gettime_t_syscall
|
||||
#endif
|
||||
static int acc_pclock_read_clock_gettime_t_syscall(acc_pclock_handle_p h, acc_pclock_p c)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (acc_pclock_syscall_clock_gettime(3, &ts) != 0)
|
||||
return -1;
|
||||
c->tv_sec = ts.tv_sec;
|
||||
c->tv_nsec = ts.tv_nsec;
|
||||
ACC_UNUSED(h); return 0;
|
||||
}
|
||||
#endif
|
||||
#if (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_HAVE_WINDOWS_H) && defined(acc_int64l_t)
|
||||
#ifndef acc_pclock_read_getthreadtimes
|
||||
#define acc_pclock_read_getthreadtimes acc_pclock_read_getthreadtimes
|
||||
@@ -5761,6 +5879,7 @@ ACCLIB_PUBLIC(int, acc_pclock_open) (acc_pclock_handle_p h, int mode)
|
||||
int i;
|
||||
h->h = (acclib_handle_t) 0;
|
||||
h->mode = -1;
|
||||
h->read_error = 2;
|
||||
h->name = NULL;
|
||||
h->gettime = 0;
|
||||
#if defined(acc_int64l_t)
|
||||
@@ -5768,29 +5887,42 @@ ACCLIB_PUBLIC(int, acc_pclock_open) (acc_pclock_handle_p h, int mode)
|
||||
#endif
|
||||
switch (mode)
|
||||
{
|
||||
case ACC_PCLOCK_REALTIME_HR:
|
||||
# if defined(acc_pclock_read_gettimeofday)
|
||||
h->gettime = acc_pclock_read_gettimeofday;
|
||||
h->name = "gettimeofday";
|
||||
# endif
|
||||
break;
|
||||
case ACC_PCLOCK_REALTIME:
|
||||
# if defined(acc_pclock_read_gettimeofday)
|
||||
h->gettime = acc_pclock_read_gettimeofday;
|
||||
h->name = "gettimeofday";
|
||||
# if defined(acc_pclock_read_clock_gettime_r_syscall)
|
||||
if (acc_pclock_read_clock_gettime_r_syscall(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_r_syscall;
|
||||
h->name = "CLOCK_REALTIME/syscall";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
break;
|
||||
case ACC_PCLOCK_MONOTONIC_HR:
|
||||
# if defined(acc_pclock_read_uclock)
|
||||
h->gettime = acc_pclock_read_uclock;
|
||||
h->name = "uclock";
|
||||
# if defined(acc_pclock_read_gettimeofday)
|
||||
if (acc_pclock_read_gettimeofday(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_gettimeofday;
|
||||
h->name = "gettimeofday";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
break;
|
||||
case ACC_PCLOCK_MONOTONIC:
|
||||
# if defined(acc_pclock_read_clock_gettime_m_syscall)
|
||||
if (acc_pclock_read_clock_gettime_m_syscall(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_m_syscall;
|
||||
h->name = "CLOCK_MONOTONIC/syscall";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_uclock)
|
||||
if (acc_pclock_read_uclock(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_uclock;
|
||||
h->name = "uclock";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_clock)
|
||||
if (!h->gettime) {
|
||||
if (acc_pclock_read_clock(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock;
|
||||
h->name = "clock";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
break;
|
||||
@@ -5803,35 +5935,52 @@ ACCLIB_PUBLIC(int, acc_pclock_open) (acc_pclock_handle_p h, int mode)
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_getprocesstimes)
|
||||
if (!h->gettime && acc_pclock_read_getprocesstimes(h, &c) == 0) {
|
||||
if (acc_pclock_read_getprocesstimes(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_getprocesstimes;
|
||||
h->name = "GetProcessTimes";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_clock_gettime_p)
|
||||
if (!h->gettime && acc_pclock_read_clock_gettime_p(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_p;
|
||||
h->name = "CLOCK_PROCESS_CPUTIME_ID";
|
||||
# if defined(acc_pclock_read_clock_gettime_p_syscall)
|
||||
if (acc_pclock_read_clock_gettime_p_syscall(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_p_syscall;
|
||||
h->name = "CLOCK_PROCESS_CPUTIME_ID/syscall";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_clock_gettime_p_libc)
|
||||
if (acc_pclock_read_clock_gettime_p_libc(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_p_libc;
|
||||
h->name = "CLOCK_PROCESS_CPUTIME_ID/libc";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_getrusage)
|
||||
h->gettime = acc_pclock_read_getrusage;
|
||||
h->name = "getrusage";
|
||||
if (acc_pclock_read_getrusage(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_getrusage;
|
||||
h->name = "getrusage";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
break;
|
||||
case ACC_PCLOCK_THREAD_CPUTIME_ID:
|
||||
# if defined(acc_pclock_read_getthreadtimes)
|
||||
if (!h->gettime && acc_pclock_read_getthreadtimes(h, &c) == 0) {
|
||||
if (acc_pclock_read_getthreadtimes(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_getthreadtimes;
|
||||
h->name = "GetThreadTimes";
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_clock_gettime_t)
|
||||
if (!h->gettime && acc_pclock_read_clock_gettime_t(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_t;
|
||||
h->name = "CLOCK_THREAD_CPUTIME_ID";
|
||||
# if defined(acc_pclock_read_clock_gettime_t_syscall)
|
||||
if (acc_pclock_read_clock_gettime_t_syscall(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_t_syscall;
|
||||
h->name = "CLOCK_THREAD_CPUTIME_ID/syscall";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
# if defined(acc_pclock_read_clock_gettime_t_libc)
|
||||
if (acc_pclock_read_clock_gettime_t_libc(h, &c) == 0) {
|
||||
h->gettime = acc_pclock_read_clock_gettime_t_libc;
|
||||
h->name = "CLOCK_THREAD_CPUTIME_ID/libc";
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
@@ -5842,6 +5991,7 @@ ACCLIB_PUBLIC(int, acc_pclock_open) (acc_pclock_handle_p h, int mode)
|
||||
if (!h->h)
|
||||
h->h = (acclib_handle_t) 1;
|
||||
h->mode = mode;
|
||||
h->read_error = 0;
|
||||
if (!h->name)
|
||||
h->name = "unknown";
|
||||
for (i = 0; i < 10; i++) {
|
||||
@@ -5853,10 +6003,6 @@ ACCLIB_PUBLIC(int, acc_pclock_open_default) (acc_pclock_handle_p h)
|
||||
{
|
||||
if (acc_pclock_open(h, ACC_PCLOCK_PROCESS_CPUTIME_ID) == 0)
|
||||
return 0;
|
||||
if (acc_pclock_open(h, ACC_PCLOCK_MONOTONIC_HR) == 0)
|
||||
return 0;
|
||||
if (acc_pclock_open(h, ACC_PCLOCK_REALTIME_HR) == 0)
|
||||
return 0;
|
||||
if (acc_pclock_open(h, ACC_PCLOCK_MONOTONIC) == 0)
|
||||
return 0;
|
||||
if (acc_pclock_open(h, ACC_PCLOCK_REALTIME) == 0)
|
||||
@@ -5882,6 +6028,7 @@ ACCLIB_PUBLIC(void, acc_pclock_read) (acc_pclock_handle_p h, acc_pclock_p c)
|
||||
if (h->gettime(h, c) == 0)
|
||||
return;
|
||||
}
|
||||
h->read_error = 1;
|
||||
#if defined(acc_int64l_t)
|
||||
c->tv_sec = 0;
|
||||
#else
|
||||
@@ -5997,6 +6144,7 @@ ACCLIB_PUBLIC(int, acc_uclock_open) (acc_uclock_handle_p h)
|
||||
#endif
|
||||
h->h = (acclib_handle_t) 1;
|
||||
h->mode = 0;
|
||||
h->read_error = 0;
|
||||
h->name = NULL;
|
||||
#if (__ACCLIB_UCLOCK_USE_PERFCTR)
|
||||
h->pch.h = 0;
|
||||
@@ -6050,6 +6198,7 @@ ACCLIB_PUBLIC(void, acc_uclock_read) (acc_uclock_handle_p h, acc_uclock_p c)
|
||||
return;
|
||||
} else {
|
||||
h->mode = 0; h->qpf = 0.0; c->qpc = 0;
|
||||
h->read_error = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -6342,6 +6491,8 @@ ACCLIB_PUBLIC(int, acc_mkdir) (const char* name, unsigned mode)
|
||||
# else
|
||||
return mkdir(name);
|
||||
# endif
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
return mkdir(name, (mode_t) mode);
|
||||
#else
|
||||
return mkdir(name, mode);
|
||||
#endif
|
||||
@@ -6418,11 +6569,11 @@ ACCLIB_PUBLIC_NOINLINE(void, acc_debug_nop) (void)
|
||||
ACCLIB_PUBLIC_NOINLINE(int, acc_debug_align_check_query) (void)
|
||||
{
|
||||
#if (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_ASM_SYNTAX_GNUC)
|
||||
long r;
|
||||
size_t r;
|
||||
__asm__ __volatile__("pushf\n pop %0\n" : "=a" (r) : : __ACC_ASM_CLOBBER);
|
||||
return (int)(r >> 18) & 1;
|
||||
#elif (ACC_ARCH_I386) && (ACC_ASM_SYNTAX_MSC)
|
||||
long r;
|
||||
unsigned long r;
|
||||
__asm {
|
||||
pushf
|
||||
pop eax
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -57,7 +57,7 @@ void printClearLine(FILE *f)
|
||||
fflush(stdout); fflush(stderr);
|
||||
if (f == NULL)
|
||||
f = stdout;
|
||||
con_fprintf(f,clear_line_msg);
|
||||
con_fprintf(f, "%s", clear_line_msg);
|
||||
fflush(f);
|
||||
printSetNl(0);
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -142,6 +142,7 @@ struct options_t {
|
||||
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
bool use_ptinterp; // use PT_INTERP /opt/upx/run
|
||||
bool make_ptinterp; // make PT_INTERP [ignore current file!]
|
||||
bool unmap_all_pages; // thus /proc/self/exe vanishes
|
||||
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
|
||||
+4
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -148,14 +148,12 @@ Linker* PackArmPe::newLinker() const
|
||||
// import handling
|
||||
**************************************************************************/
|
||||
|
||||
struct import_desc
|
||||
{
|
||||
__packed_struct(import_desc)
|
||||
LE32 oft; // orig first thunk
|
||||
char _[8];
|
||||
LE32 dllname;
|
||||
LE32 iat; // import address table
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
void PackArmPe::processImports(unsigned myimport, unsigned iat_off) // pass 2
|
||||
{
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+6
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -66,19 +66,16 @@ protected:
|
||||
|
||||
long coff_offset;
|
||||
|
||||
struct external_scnhdr_t
|
||||
{
|
||||
__packed_struct(external_scnhdr_t)
|
||||
char _[12]; // name, paddr
|
||||
LE32 vaddr;
|
||||
LE32 size;
|
||||
LE32 scnptr;
|
||||
char misc[12]; // relptr, lnnoptr, nreloc, nlnno
|
||||
char __[4]; // flags
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct coff_header_t
|
||||
{
|
||||
__packed_struct(coff_header_t)
|
||||
// ext_file_hdr
|
||||
LE16 f_magic;
|
||||
LE16 f_nscns;
|
||||
@@ -99,8 +96,7 @@ protected:
|
||||
|
||||
// section headers
|
||||
external_scnhdr_t sh[3];
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
coff_header_t coff_hdr;
|
||||
external_scnhdr_t *text,*data,*bss;
|
||||
|
||||
+69
-40
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -52,8 +52,7 @@ struct ElfITypes
|
||||
|
||||
// The ELF file header. This appears at the start of every ELF file.
|
||||
template <class TElfITypes>
|
||||
struct Ehdr
|
||||
{
|
||||
__packed_struct(Ehdr)
|
||||
typedef typename TElfITypes::Half Half;
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -76,13 +75,11 @@ struct Ehdr
|
||||
|
||||
# define WANT_EHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Dyn
|
||||
{
|
||||
__packed_struct(Dyn)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
@@ -91,13 +88,32 @@ struct Dyn
|
||||
|
||||
# define WANT_DYN_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct External_Note
|
||||
{
|
||||
__packed_struct(Rel)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
Addr r_offset;
|
||||
Xword r_info;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Rela)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
Addr r_offset;
|
||||
Xword r_info;
|
||||
Xword r_addend;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(External_Note)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
|
||||
Word xn_namesz; // includes terminating '\0'
|
||||
@@ -105,8 +121,7 @@ struct External_Note
|
||||
Word xn_type;
|
||||
//char xn_name[N]; // terminate with '\0'
|
||||
//char xn_data[M]; // aligned to 0 mod 4
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf
|
||||
@@ -119,8 +134,7 @@ __attribute_packed;
|
||||
namespace N_Elf32 {
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Phdr
|
||||
{
|
||||
__packed_struct(Phdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
@@ -136,13 +150,11 @@ struct Phdr
|
||||
|
||||
# define WANT_PHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Shdr
|
||||
{
|
||||
__packed_struct(Shdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
@@ -160,13 +172,11 @@ struct Shdr
|
||||
|
||||
# define WANT_SHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Sym
|
||||
{
|
||||
__packed_struct(Sym)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Section Section;
|
||||
@@ -183,9 +193,9 @@ struct Sym
|
||||
|
||||
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
|
||||
static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
|
||||
}
|
||||
__attribute_packed;
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type)
|
||||
{ return (unsigned char) (((bind<<4) + (0xf & type)) & 0xff); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf32
|
||||
@@ -198,8 +208,7 @@ __attribute_packed;
|
||||
namespace N_Elf64 {
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Phdr
|
||||
{
|
||||
__packed_struct(Phdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -216,13 +225,11 @@ struct Phdr
|
||||
|
||||
# define WANT_PHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Shdr
|
||||
{
|
||||
__packed_struct(Shdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -241,13 +248,11 @@ struct Shdr
|
||||
|
||||
# define WANT_SHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
struct Sym
|
||||
{
|
||||
__packed_struct(Sym)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
@@ -265,9 +270,9 @@ struct Sym
|
||||
|
||||
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
|
||||
static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type) { return (bind<<4) + (0xf & type); }
|
||||
}
|
||||
__attribute_packed;
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type)
|
||||
{ return (unsigned char) (((bind<<4) + (0xf & type)) & 0xff); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf64
|
||||
@@ -295,6 +300,8 @@ struct ElfClass_32
|
||||
typedef N_Elf32::Phdr<ElfITypes> Phdr;
|
||||
typedef N_Elf32::Shdr<ElfITypes> Shdr;
|
||||
typedef N_Elf ::Dyn <ElfITypes> Dyn;
|
||||
typedef N_Elf ::Rel <ElfITypes> Rel;
|
||||
typedef N_Elf ::Rela<ElfITypes> Rela;
|
||||
typedef N_Elf32::Sym <ElfITypes> Sym;
|
||||
typedef N_Elf ::External_Note<ElfITypes> External_Note;
|
||||
|
||||
@@ -304,11 +311,15 @@ struct ElfClass_32
|
||||
COMPILE_TIME_ASSERT(sizeof(Phdr) == 32)
|
||||
COMPILE_TIME_ASSERT(sizeof(Shdr) == 40)
|
||||
COMPILE_TIME_ASSERT(sizeof(Dyn) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rel) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rela) == 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(Sym) == 16)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rel)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rela)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
|
||||
}
|
||||
};
|
||||
@@ -330,6 +341,8 @@ struct ElfClass_64
|
||||
typedef N_Elf64::Phdr<ElfITypes> Phdr;
|
||||
typedef N_Elf64::Shdr<ElfITypes> Shdr;
|
||||
typedef N_Elf ::Dyn <ElfITypes> Dyn;
|
||||
typedef N_Elf ::Rel <ElfITypes> Rel;
|
||||
typedef N_Elf ::Rela<ElfITypes> Rela;
|
||||
typedef N_Elf64::Sym <ElfITypes> Sym;
|
||||
typedef N_Elf ::External_Note<ElfITypes> External_Note;
|
||||
|
||||
@@ -339,11 +352,15 @@ struct ElfClass_64
|
||||
COMPILE_TIME_ASSERT(sizeof(Phdr) == 56)
|
||||
COMPILE_TIME_ASSERT(sizeof(Shdr) == 64)
|
||||
COMPILE_TIME_ASSERT(sizeof(Dyn) == 16)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rel) == 16)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rela) == 24)
|
||||
COMPILE_TIME_ASSERT(sizeof(Sym) == 24)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rel)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rela)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
|
||||
}
|
||||
};
|
||||
@@ -368,6 +385,8 @@ typedef ElfClass_Host32::Ehdr Elf32_Ehdr;
|
||||
typedef ElfClass_Host32::Phdr Elf32_Phdr;
|
||||
typedef ElfClass_Host32::Shdr Elf32_Shdr;
|
||||
typedef ElfClass_Host32::Dyn Elf32_Dyn;
|
||||
typedef ElfClass_Host32::Rel Elf32_Rel;
|
||||
typedef ElfClass_Host32::Rela Elf32_Rela;
|
||||
typedef ElfClass_Host32::Sym Elf32_Sym;
|
||||
typedef ElfClass_Host32::External_Note Elf32_External_Note;
|
||||
|
||||
@@ -375,6 +394,8 @@ typedef ElfClass_Host64::Ehdr Elf64_Ehdr;
|
||||
typedef ElfClass_Host64::Phdr Elf64_Phdr;
|
||||
typedef ElfClass_Host64::Shdr Elf64_Shdr;
|
||||
typedef ElfClass_Host64::Dyn Elf64_Dyn;
|
||||
typedef ElfClass_Host64::Rel Elf64_Rel;
|
||||
typedef ElfClass_Host64::Rela Elf64_Rela;
|
||||
typedef ElfClass_Host64::Sym Elf64_Sym;
|
||||
typedef ElfClass_Host64::External_Note Elf64_External_Note;
|
||||
|
||||
@@ -382,6 +403,8 @@ typedef ElfClass_BE32::Ehdr Elf_BE32_Ehdr;
|
||||
typedef ElfClass_BE32::Phdr Elf_BE32_Phdr;
|
||||
typedef ElfClass_BE32::Shdr Elf_BE32_Shdr;
|
||||
typedef ElfClass_BE32::Dyn Elf_BE32_Dyn;
|
||||
typedef ElfClass_BE32::Rel Elf_BE32_Rel;
|
||||
typedef ElfClass_BE32::Rela Elf_BE32_Rela;
|
||||
typedef ElfClass_BE32::Sym Elf_BE32_Sym;
|
||||
typedef ElfClass_BE32::External_Note Elf_BE32_External_Note;
|
||||
|
||||
@@ -389,6 +412,8 @@ typedef ElfClass_BE64::Ehdr Elf_BE64_Ehdr;
|
||||
typedef ElfClass_BE64::Phdr Elf_BE64_Phdr;
|
||||
typedef ElfClass_BE64::Shdr Elf_BE64_Shdr;
|
||||
typedef ElfClass_BE64::Dyn Elf_BE64_Dyn;
|
||||
typedef ElfClass_BE64::Rel Elf_BE64_Rel;
|
||||
typedef ElfClass_BE64::Rela Elf_BE64_Rela;
|
||||
typedef ElfClass_BE64::Sym Elf_BE64_Sym;
|
||||
typedef ElfClass_BE64::External_Note Elf_BE64_External_Note;
|
||||
|
||||
@@ -396,6 +421,8 @@ typedef ElfClass_LE32::Ehdr Elf_LE32_Ehdr;
|
||||
typedef ElfClass_LE32::Phdr Elf_LE32_Phdr;
|
||||
typedef ElfClass_LE32::Shdr Elf_LE32_Shdr;
|
||||
typedef ElfClass_LE32::Dyn Elf_LE32_Dyn;
|
||||
typedef ElfClass_LE32::Rel Elf_LE32_Rel;
|
||||
typedef ElfClass_LE32::Rela Elf_LE32_Rela;
|
||||
typedef ElfClass_LE32::Sym Elf_LE32_Sym;
|
||||
typedef ElfClass_LE32::External_Note Elf_LE32_External_Note;
|
||||
|
||||
@@ -403,6 +430,8 @@ typedef ElfClass_LE64::Ehdr Elf_LE64_Ehdr;
|
||||
typedef ElfClass_LE64::Phdr Elf_LE64_Phdr;
|
||||
typedef ElfClass_LE64::Shdr Elf_LE64_Shdr;
|
||||
typedef ElfClass_LE64::Dyn Elf_LE64_Dyn;
|
||||
typedef ElfClass_LE64::Rel Elf_LE64_Rel;
|
||||
typedef ElfClass_LE64::Rela Elf_LE64_Rela;
|
||||
typedef ElfClass_LE64::Sym Elf_LE64_Sym;
|
||||
typedef ElfClass_LE64::External_Note Elf_LE64_External_Note;
|
||||
|
||||
|
||||
+12
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -145,10 +145,19 @@
|
||||
DT_HASH = 4, /* Hash table of symbol names */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_SYMTAB = 6, /* Symbol table */
|
||||
DT_RELA = 7, /* Relocations which do contain an addend */
|
||||
DT_RELAENT = 9, /* Size of one RELA relocation */
|
||||
DT_INIT = 12, /* Address of init function */
|
||||
DT_REL = 17, /* Relocations which contain no addend */
|
||||
DT_RELENT = 19, /* Size of one Rel relocation */
|
||||
DT_STRSZ = 10, /* Sizeof string table */
|
||||
DT_PLTREL = 20, /* Type of reloc in PLT */
|
||||
DT_JMPREL = 23, /* Address of PLT relocs */
|
||||
DT_GNU_HASH = 0x6ffffef5 /* GNU-style hash table */
|
||||
DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */
|
||||
DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */
|
||||
DT_VERSYM = 0x6ffffff0, /* version[] for each symbol */
|
||||
DT_VERDEF = 0x6ffffffc, /* version definitions[] */
|
||||
DT_VERNEEDED= 0x6ffffffe /* version[] needed */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+8
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -51,20 +51,21 @@ PackExe::PackExe(InputFile *f) :
|
||||
super(f)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32);
|
||||
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(exe_header_t)
|
||||
ih_exesize = ih_imagesize = ih_overlay = 0;
|
||||
stack_for_lzma = 0;
|
||||
use_clear_dirty_stack = false;
|
||||
|
||||
// disable lzma for "--brute" unless explicitly given "--lzma"
|
||||
if (opt->all_methods_use_lzma && !opt->method_lzma_seen)
|
||||
opt->all_methods_use_lzma = false;
|
||||
}
|
||||
|
||||
|
||||
const int *PackExe::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
bool small = ih_imagesize <= 256*1024;
|
||||
// disable lzma for "--brute" unless explicitly given "--lzma"
|
||||
// WARNING: this side effect persists for later files!
|
||||
if (opt->all_methods_use_lzma && !opt->method_lzma_seen)
|
||||
opt->all_methods_use_lzma = false;
|
||||
return Packer::getDefaultCompressionMethods_8(method, level, small);
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -74,8 +74,7 @@ protected:
|
||||
virtual Linker* newLinker() const;
|
||||
void addLoaderEpilogue(int flag);
|
||||
|
||||
struct exe_header_t
|
||||
{
|
||||
__packed_struct(exe_header_t)
|
||||
LE16 ident;
|
||||
LE16 m512;
|
||||
LE16 p512;
|
||||
@@ -91,8 +90,7 @@ protected:
|
||||
LE16 relocoffs;
|
||||
char __[2]; // overlnum
|
||||
LE32 firstreloc;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
exe_header_t ih, oh;
|
||||
|
||||
|
||||
+926
-347
File diff suppressed because it is too large
Load Diff
+58
-29
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -61,9 +61,14 @@ protected:
|
||||
) = 0;
|
||||
virtual void defineSymbols(Filter const *);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
virtual void unpack(OutputFile *fo) = 0;
|
||||
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;
|
||||
|
||||
protected:
|
||||
unsigned e_phnum; /* Program header table entry count */
|
||||
char *file_image; // if ET_DYN investigation
|
||||
char const *dynstr; // from DT_STRTAB
|
||||
|
||||
@@ -72,6 +77,10 @@ protected:
|
||||
unsigned sz_pack2; // after pack2(), before loader
|
||||
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
|
||||
|
||||
unsigned short e_machine;
|
||||
unsigned char ei_class;
|
||||
@@ -122,11 +131,12 @@ protected:
|
||||
|
||||
static unsigned elf_hash(char const *) /*const*/;
|
||||
static unsigned gnu_hash(char const *) /*const*/;
|
||||
virtual void const *elf_find_dynamic(unsigned) const;
|
||||
virtual Elf32_Sym const *elf_lookup(char const *) const;
|
||||
virtual unsigned elf_get_offset_from_address(unsigned) const;
|
||||
virtual unsigned elf_get_offset_from_address(acc_uint64l_t) 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;
|
||||
|
||||
protected:
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
@@ -145,26 +155,23 @@ protected:
|
||||
Elf32_Shdr const *sec_dynsym;
|
||||
Elf32_Shdr const *sec_dynstr;
|
||||
|
||||
struct cprElfHdr1 {
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
@@ -222,31 +229,46 @@ 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;
|
||||
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;
|
||||
|
||||
protected:
|
||||
Elf64_Ehdr ehdri; // from input file
|
||||
Elf64_Phdr *phdri; // for input file
|
||||
Elf64_Shdr const *shdri; // from input file
|
||||
acc_uint64l_t page_mask; // AND clears the offset-within-page
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf64_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
unsigned int const *gashtab; // from DT_GNU_HASH
|
||||
Elf64_Sym const *dynsym; // from DT_SYMTAB
|
||||
char const *shstrtab; // via Elf64_Shdr
|
||||
int n_elf_shnum; // via e_shnum
|
||||
|
||||
Elf64_Shdr const *sec_strndx;
|
||||
Elf64_Shdr const *sec_dynsym;
|
||||
Elf64_Shdr const *sec_dynstr;
|
||||
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
@@ -264,21 +286,30 @@ class PackLinuxElf32Be : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; }
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::be_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
class PackLinuxElf32Le : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
PackLinuxElf32Le(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
class PackLinuxElf64Le : public PackLinuxElf64
|
||||
{
|
||||
typedef PackLinuxElf64 super;
|
||||
protected:
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -342,8 +373,6 @@ public:
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
|
||||
|
||||
+13
-10
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2001-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2001-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -132,8 +132,8 @@ PackLinuxI386::generateElfHdr(
|
||||
unsigned const brka
|
||||
)
|
||||
{
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout;
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout;
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)(void *)&elfout;
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)(void *)&elfout;
|
||||
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
|
||||
|
||||
assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
|
||||
@@ -528,11 +528,14 @@ bool PackLinuxI386::canPack()
|
||||
default:
|
||||
unsigned const e_phnum = get_te16(&ehdr.e_phnum);
|
||||
if (e_phnum<=(512/sizeof(Elf32_Phdr))) {
|
||||
char buf2[512];
|
||||
union {
|
||||
unsigned char buf2[512];
|
||||
//Elf32_Phdr phdr;
|
||||
} u;
|
||||
fi->seek(get_te32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(buf2, sizeof(buf2));
|
||||
fi->readx(u.buf2, sizeof(u.buf2));
|
||||
fi->seek(0, SEEK_SET);
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr const *)buf2;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *) u.buf2;
|
||||
for (unsigned j=0; j < e_phnum; ++phdr, ++j) {
|
||||
if (phdr->PT_NOTE == get_te32(&phdr->p_type)) {
|
||||
unsigned const offset = get_te32(&phdr->p_offset);
|
||||
@@ -543,11 +546,11 @@ bool PackLinuxI386::canPack()
|
||||
if (4==get_te32(¬e.descsz)
|
||||
&& 1==get_te32(¬e.type)
|
||||
&& 0==note.end ) {
|
||||
if (0==strcmp("NetBSD", (char const *)¬e.text)) {
|
||||
if (0==strcmp("NetBSD", (char const *)note.text)) {
|
||||
ei_osabi = Elf32_Ehdr::ELFOSABI_NETBSD;
|
||||
break;
|
||||
}
|
||||
if (0==strcmp("OpenBSD", (char const *)¬e.text)) {
|
||||
if (0==strcmp("OpenBSD", (char const *)note.text)) {
|
||||
ei_osabi = Elf32_Ehdr::ELFOSABI_OPENBSD;
|
||||
break;
|
||||
}
|
||||
|
||||
+8
-11
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -87,26 +87,23 @@ protected:
|
||||
|
||||
unsigned n_mru;
|
||||
|
||||
struct cprElfHdr1 {
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
|
||||
+10
-7
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -197,14 +197,17 @@ void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
{
|
||||
#define MAX_INTERP_HDR 512
|
||||
char bufehdr[MAX_INTERP_HDR];
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)bufehdr;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *)(1+ehdr);
|
||||
union {
|
||||
unsigned char buf[MAX_INTERP_HDR];
|
||||
//struct { Elf32_Ehdr ehdr; Elf32_Phdr phdr; } e;
|
||||
} u;
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *) u.buf;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *) (u.buf + sizeof(*ehdr));
|
||||
|
||||
unsigned szb_info = sizeof(b_info);
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(bufehdr, MAX_INTERP_HDR);
|
||||
fi->readx(u.buf, MAX_INTERP_HDR);
|
||||
unsigned const e_entry = get_te32(&ehdr->e_entry);
|
||||
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2000-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+777
-87
File diff suppressed because it is too large
Load Diff
+378
-74
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -30,24 +30,22 @@
|
||||
#define __UPX_P_MACHO_H
|
||||
|
||||
|
||||
struct Mach_fat_header {
|
||||
__packed_struct(Mach_fat_header)
|
||||
BE32 magic;
|
||||
enum { // note conflict with java bytecode PackLinuxI386
|
||||
FAT_MAGIC = 0xcafebabe,
|
||||
FAT_MAGIC_SWAB = 0xbebafeca
|
||||
};
|
||||
BE32 nfat_arch; // Number of Mach_fat_arch which follow.
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct Mach_fat_arch {
|
||||
__packed_struct(Mach_fat_arch)
|
||||
BE32 cputype;
|
||||
BE32 cpusubtype;
|
||||
BE32 offset;
|
||||
BE32 size;
|
||||
BE32 align; /* shift count; log base 2 */
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -68,8 +66,7 @@ struct MachITypes
|
||||
};
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_header
|
||||
{
|
||||
__packed_struct(Mach_header)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word magic;
|
||||
@@ -81,12 +78,11 @@ struct Mach_header
|
||||
Word flags;
|
||||
#define WANT_MACH_HEADER_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_header64
|
||||
{ // only difference is padding to 0 mod 8
|
||||
__packed_struct(Mach_header64)
|
||||
// only difference is padding to 0 mod 8
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word magic;
|
||||
@@ -99,12 +95,10 @@ struct Mach_header64
|
||||
Word reserved; // pad to 0 mod 8
|
||||
#define WANT_MACH_HEADER_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_segment_command
|
||||
{
|
||||
__packed_struct(Mach_segment_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
@@ -122,12 +116,10 @@ struct Mach_segment_command
|
||||
Word flags;
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_section_command
|
||||
{
|
||||
__packed_struct(Mach_section_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
@@ -136,21 +128,149 @@ struct Mach_section_command
|
||||
char segname[16];
|
||||
Addr addr; /* memory address */
|
||||
Addr size; /* size in bytes */
|
||||
Word offset; /* file offset */ // FIXME: 64 bit?
|
||||
Word offset; /* file offset */
|
||||
Word align; /* power of 2 */
|
||||
Word reloff; /* file offset of relocation entries */
|
||||
Word nreloc; /* number of relocation entries */
|
||||
Word flags; /* section type and attributes */
|
||||
Word reserved1;
|
||||
Word reserved2;
|
||||
Word reserved1; /* for offset or index */
|
||||
Word reserved2; /* for count or sizeof */
|
||||
#define WANT_MACH_SECTION_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_ppc_thread_state
|
||||
{
|
||||
__packed_struct(Mach_section_command_64)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
typedef typename TMachITypes::Word Off32;
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
char sectname[16];
|
||||
char segname[16];
|
||||
Addr addr; /* memory address */
|
||||
Addr size; /* size in bytes */
|
||||
Off32 offset; /* file offset */
|
||||
Word align; /* power of 2 */
|
||||
Word reloff; /* file offset of relocation entries */
|
||||
Word nreloc; /* number of relocation entries */
|
||||
Word flags; /* section type and attributes */
|
||||
Word reserved1; /* for offset or index */
|
||||
Word reserved2; /* for count or sizeof */
|
||||
Word reserved3; /* NOT IN 32-bit VERSION!! */
|
||||
#define WANT_MACH_SECTION_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_symtab_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
typedef typename TMachITypes::Word Off32;
|
||||
|
||||
Word cmd; /* LC_SYMTAB */
|
||||
Word cmdsize; /* sizeof(struct Mach_symtab_command) */
|
||||
Off32 symoff; /* symbol table offset */
|
||||
Word nsyms; /* number of symbol table entries */
|
||||
Off32 stroff; /* string table offset */
|
||||
Word strsize; /* string table size in bytes */
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_dysymtab_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
typedef typename TMachITypes::Word Off32;
|
||||
|
||||
Word cmd; /* LC_DYSYMTAB */
|
||||
Word cmdsize; /* sizeof(struct Mach_dysymtab_command) */
|
||||
Word ilocalsym; /* index to local symbols */
|
||||
Word nlocalsym; /* number of local symbols */
|
||||
Word iextdefsym; /* index to externally defined symbols */
|
||||
Word nextdefsym; /* number of externally defined symbols */
|
||||
Word iundefsym; /* index to undefined symbols */
|
||||
Word nundefsym; /* number of undefined symbols */
|
||||
Off32 tocoff; /* file offset to table of contents */
|
||||
Word ntoc; /* number of entries in table of contents */
|
||||
Off32 modtaboff; /* file offset to module table */
|
||||
Word nmodtab; /* number of module table entries */
|
||||
Off32 extrefsymoff; /* offset to referenced symbol table */
|
||||
Word nextrefsymoff; /* number of referenced symbol table entries */
|
||||
Off32 indirectsymoff; /* file offset to the indirect symbol table */
|
||||
Word nindirectsyms; /* number of indirect symbol table entries */
|
||||
Off32 extreloff; /* offset to external relocation entries */
|
||||
Word nextrel; /* number of external relocation entries */
|
||||
Off32 locreloff; /* offset to local relocation entries */
|
||||
Word nlocrel; /* number of local relocation entries */
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_segsplit_info_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
|
||||
Word cmd; /* LC_SEGMENT_SPLIT_INFO */
|
||||
Word cmdsize; /* sizeof(struct Mach_segsplit_info_command) */
|
||||
Off dataoff;
|
||||
Word datasize;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_routines_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
Addr init_address;
|
||||
Word init_module;
|
||||
Word reserved1;
|
||||
Word reserved2;
|
||||
Word reserved3;
|
||||
Word reserved4;
|
||||
Word reserved5;
|
||||
Word reserved6;
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_routines_command_64)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
Addr init_address;
|
||||
Xword init_module;
|
||||
Xword reserved1;
|
||||
Xword reserved2;
|
||||
Xword reserved3;
|
||||
Xword reserved4;
|
||||
Xword reserved5;
|
||||
Xword reserved6;
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_twolevel_hints_command)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
typedef typename TMachITypes::Off Off;
|
||||
|
||||
Word cmd;
|
||||
Word cmdsize;
|
||||
Off offset; /* offset to the hint table */
|
||||
Word nhints; /* number of hints */
|
||||
#define WANT_MACH_SEGMENT_ENUM 1
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_ppc_thread_state)
|
||||
typedef typename TMachITypes::Addr Addr;
|
||||
|
||||
Addr srr0; /* Instruction address register (PC; entry addr) */
|
||||
@@ -167,12 +287,10 @@ struct Mach_ppc_thread_state
|
||||
Addr mq; /* MQ register (601 only) */
|
||||
|
||||
Addr vrsave; /* Vector Save Register */
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_i386_thread_state
|
||||
{
|
||||
__packed_struct(Mach_i386_thread_state)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word eax, ebx, ecx, edx;
|
||||
@@ -181,12 +299,22 @@ struct Mach_i386_thread_state
|
||||
Word eflags;
|
||||
Word eip, cs;
|
||||
Word ds, es, fs, gs;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_i386_new_thread_state
|
||||
{
|
||||
__packed_struct(Mach_AMD64_thread_state)
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
Xword rax, rbx, rcx, rdx;
|
||||
Xword rdi, rsi, rbp, rsp;
|
||||
Xword r8, r9, r10, r11;
|
||||
Xword r12, r13, r14, r15;
|
||||
Xword rip, rflags;
|
||||
Xword cs, fs, gs;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_i386_new_thread_state)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word gs, fs, es, ds;
|
||||
@@ -194,8 +322,18 @@ struct Mach_i386_new_thread_state
|
||||
Word ebx, edx, ecx, eax;
|
||||
Word eip, cs, efl;
|
||||
Word uesp, ss;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
template <class TMachITypes>
|
||||
__packed_struct(Mach_ARM_thread_state)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
|
||||
Word r[13]; // r0-r12
|
||||
Word sp; // r13
|
||||
Word lr; // r14
|
||||
Word pc; // r15
|
||||
Word cpsr;
|
||||
__packed_struct_end()
|
||||
|
||||
} // namespace N_Mach
|
||||
|
||||
@@ -206,8 +344,7 @@ namespace N_Mach32 {
|
||||
namespace N_Mach64 {
|
||||
|
||||
template <class TMachITypes>
|
||||
struct Mach_ppc_thread_state64
|
||||
{
|
||||
__packed_struct(Mach_ppc_thread_state64)
|
||||
typedef typename TMachITypes::Word Word;
|
||||
typedef typename TMachITypes::Xword Xword;
|
||||
|
||||
@@ -224,8 +361,7 @@ struct Mach_ppc_thread_state64
|
||||
Xword ctr; /* Count register */
|
||||
|
||||
Word vrsave; /* Vector Save Register */
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
} // namespace N_Mach64
|
||||
|
||||
@@ -251,8 +387,15 @@ struct MachClass_32
|
||||
typedef N_Mach::Mach_header<MachITypes> Mach_header;
|
||||
typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
|
||||
typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command;
|
||||
typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
|
||||
typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_command;
|
||||
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
|
||||
typedef N_Mach::Mach_routines_command<MachITypes> Mach_routines_command;
|
||||
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
|
||||
typedef N_Mach::Mach_ppc_thread_state<MachITypes> Mach_ppc_thread_state;
|
||||
typedef N_Mach::Mach_i386_thread_state<MachITypes> Mach_i386_thread_state;
|
||||
typedef N_Mach::Mach_AMD64_thread_state<MachITypes> Mach_AMD64_thread_state;
|
||||
typedef N_Mach::Mach_ARM_thread_state<MachITypes> Mach_ARM_thread_state;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
BeLePolicy::compileTimeAssertions();
|
||||
@@ -270,14 +413,25 @@ struct MachClass_64
|
||||
typedef typename TP::U32 TE32;
|
||||
typedef typename TP::U64 TE64;
|
||||
typedef N_Mach::MachITypes<TE32, TE64, TE64, TE64> MachITypes;
|
||||
#if (ACC_CC_BORLANDC)
|
||||
typedef TE64 Addr;
|
||||
#else
|
||||
typedef typename MachITypes::Addr Addr;
|
||||
#endif
|
||||
|
||||
// Mach types
|
||||
typedef N_Mach::Mach_header64<MachITypes> Mach_header;
|
||||
typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
|
||||
typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command;
|
||||
typedef N_Mach::Mach_section_command_64<MachITypes> Mach_section_command;
|
||||
typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
|
||||
typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_command;
|
||||
typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
|
||||
typedef N_Mach::Mach_routines_command_64<MachITypes> Mach_routines_command;
|
||||
typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
BeLePolicy::compileTimeAssertions();
|
||||
COMPILE_TIME_ASSERT(sizeof(Addr) == 8)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -293,24 +447,56 @@ typedef N_Mach::MachClass_64<N_BELE_CTP::LEPolicy> MachClass_LE64;
|
||||
// shortcuts
|
||||
typedef MachClass_Host32::Mach_segment_command Mach32_segment_command;
|
||||
typedef MachClass_Host32::Mach_section_command Mach32_section_command;
|
||||
typedef MachClass_Host32::Mach_symtab_command Mach32_symtab_command;
|
||||
typedef MachClass_Host32::Mach_dysymtab_command Mach32_dysymtab_command;
|
||||
typedef MachClass_Host32::Mach_segsplit_info_command Mach32_segsplit_info_command;
|
||||
typedef MachClass_Host32::Mach_routines_command Mach32_routines_command;
|
||||
typedef MachClass_Host32::Mach_twolevel_hints_command Mach32_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_Host64::Mach_segment_command Mach64_segment_command;
|
||||
typedef MachClass_Host64::Mach_section_command Mach64_section_command;
|
||||
typedef MachClass_Host64::Mach_symtab_command Mach64_symtab_command;
|
||||
typedef MachClass_Host64::Mach_dysymtab_command Mach64_dysymtab_command;
|
||||
typedef MachClass_Host64::Mach_segsplit_info_command Mach64_segsplit_info_command;
|
||||
typedef MachClass_Host64::Mach_routines_command Mach64_routines_command;
|
||||
typedef MachClass_Host64::Mach_twolevel_hints_command Mach64_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_BE32::Mach_segment_command MachBE32_segment_command;
|
||||
typedef MachClass_BE32::Mach_section_command MachBE32_section_command;
|
||||
typedef MachClass_BE32::Mach_symtab_command MachBE32_symtab_command;
|
||||
typedef MachClass_BE32::Mach_dysymtab_command MachBE32_dysymtab_command;
|
||||
typedef MachClass_BE32::Mach_segsplit_info_command MachBE32_segsplit_info_command;
|
||||
typedef MachClass_BE32::Mach_routines_command MachBE32_routines_command;
|
||||
typedef MachClass_BE32::Mach_twolevel_hints_command MachBE32_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_BE64::Mach_segment_command MachBE64_segment_command;
|
||||
typedef MachClass_BE64::Mach_section_command MachBE64_section_command;
|
||||
typedef MachClass_BE64::Mach_symtab_command MachBE64_symtab_command;
|
||||
typedef MachClass_BE64::Mach_dysymtab_command MachBE64_dysymtab_command;
|
||||
typedef MachClass_BE64::Mach_segsplit_info_command MachBE64_segsplit_info_command;
|
||||
typedef MachClass_BE64::Mach_routines_command MachBE64_routines_command;
|
||||
typedef MachClass_BE64::Mach_twolevel_hints_command MachBE64_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_LE32::Mach_segment_command MachLE32_segment_command;
|
||||
typedef MachClass_LE32::Mach_section_command MachLE32_section_command;
|
||||
typedef MachClass_LE32::Mach_symtab_command MachLE32_symtab_command;
|
||||
typedef MachClass_LE32::Mach_dysymtab_command MachLE32_dysymtab_command;
|
||||
typedef MachClass_LE32::Mach_segsplit_info_command MachLE32_segsplit_info_command;
|
||||
typedef MachClass_LE32::Mach_routines_command MachLE32_routines_command;
|
||||
typedef MachClass_LE32::Mach_twolevel_hints_command MachLE32_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command;
|
||||
typedef MachClass_LE64::Mach_section_command MachLE64_section_command;
|
||||
typedef MachClass_LE64::Mach_symtab_command MachLE64_symtab_command;
|
||||
typedef MachClass_LE64::Mach_dysymtab_command MachLE64_dysymtab_command;
|
||||
typedef MachClass_LE64::Mach_segsplit_info_command MachLE64_segsplit_info_command;
|
||||
typedef MachClass_LE64::Mach_routines_command MachLE64_routines_command;
|
||||
typedef MachClass_LE64::Mach_twolevel_hints_command MachLE64_twolevel_hints_command;
|
||||
|
||||
typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state;
|
||||
typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state;
|
||||
typedef MachClass_LE32::Mach_AMD64_thread_state Mach_AMD64_thread_state; // FIXME LE32 vs AMD64
|
||||
typedef MachClass_LE32::Mach_ARM_thread_state Mach_ARM_thread_state;
|
||||
#include "p_unix.h"
|
||||
|
||||
|
||||
@@ -331,9 +517,15 @@ protected:
|
||||
typedef typename MachClass::Mach_header Mach_header;
|
||||
typedef typename MachClass::Mach_segment_command Mach_segment_command;
|
||||
typedef typename MachClass::Mach_section_command Mach_section_command;
|
||||
typedef typename MachClass::Mach_symtab_command Mach_symtab_command;
|
||||
typedef typename MachClass::Mach_dysymtab_command Mach_dysymtab_command;
|
||||
typedef typename MachClass::Mach_segsplit_info_command Mach_segsplit_info_command;
|
||||
typedef typename MachClass::Mach_routines_command Mach_routines_command;
|
||||
typedef typename MachClass::Mach_twolevel_hints_command Mach_twolevel_hints_command;
|
||||
|
||||
public:
|
||||
PackMachBase(InputFile *, unsigned cpuid, unsigned t_flavor, unsigned ts_word_cnt, unsigned tc_size);
|
||||
PackMachBase(InputFile *, unsigned cpuid, unsigned filetype,
|
||||
unsigned t_flavor, unsigned ts_word_cnt, unsigned tc_size);
|
||||
virtual ~PackMachBase();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
@@ -344,6 +536,8 @@ public:
|
||||
virtual void pack3(OutputFile *, Filter &) = 0; // append loader
|
||||
virtual void pack4(OutputFile *, Filter &) = 0; // append PackHeader
|
||||
|
||||
virtual void pack4dylib(OutputFile *, Filter &, Addr init_address);
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo) = 0;
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
@@ -366,6 +560,7 @@ protected:
|
||||
static int __acc_cdecl_qsort compare_segment_command(void const *aa, void const *bb);
|
||||
|
||||
unsigned my_cputype;
|
||||
unsigned my_filetype;
|
||||
unsigned my_thread_flavor;
|
||||
unsigned my_thread_state_word_count;
|
||||
unsigned my_thread_command_size;
|
||||
@@ -375,35 +570,35 @@ protected:
|
||||
unsigned sz_mach_headers;
|
||||
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;
|
||||
Mach_header mhdri;
|
||||
|
||||
Mach_header mhdro;
|
||||
Mach_segment_command segcmdo;
|
||||
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
TE32 sz_unc; // uncompressed_size
|
||||
TE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
TE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
TE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
TE32 p_progid;
|
||||
TE32 p_filesize;
|
||||
TE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct l_info linfo;
|
||||
|
||||
@@ -424,9 +619,7 @@ class PackMachPPC32 : public PackMachBase<MachClass_BE32>
|
||||
typedef PackMachBase<MachClass_BE32> super;
|
||||
|
||||
public:
|
||||
PackMachPPC32(InputFile *f) : super(f, Mach_header::CPU_TYPE_POWERPC,
|
||||
Mach_thread_command::PPC_THREAD_STATE,
|
||||
sizeof(Mach_ppc_thread_state)>>2, sizeof(threado)) { }
|
||||
PackMachPPC32(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_PPC32; }
|
||||
virtual const char *getName() const { return "Mach/ppc32"; }
|
||||
@@ -441,8 +634,7 @@ protected:
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
|
||||
struct Mach_thread_command
|
||||
{
|
||||
__packed_struct(Mach_thread_command)
|
||||
BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
BE32 cmdsize; /* total size of this command */
|
||||
BE32 flavor;
|
||||
@@ -450,19 +642,33 @@ protected:
|
||||
Mach_ppc_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM
|
||||
#include "p_mach_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
class PackDylibPPC32 : public PackMachPPC32
|
||||
{
|
||||
typedef PackMachPPC32 super;
|
||||
|
||||
public:
|
||||
PackDylibPPC32(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_DYLIB_PPC32; }
|
||||
virtual const char *getName() const { return "Dylib/ppc32"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.dylib"; }
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
};
|
||||
|
||||
class PackMachI386 : public PackMachBase<MachClass_LE32>
|
||||
{
|
||||
typedef PackMachBase<MachClass_LE32> super;
|
||||
|
||||
public:
|
||||
PackMachI386(InputFile *f) : super(f, Mach_header::CPU_TYPE_I386,
|
||||
(unsigned)Mach_thread_command::i386_THREAD_STATE,
|
||||
sizeof(Mach_i386_thread_state)>>2, sizeof(threado)) { }
|
||||
PackMachI386(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_i386; }
|
||||
virtual const char *getName() const { return "Mach/i386"; }
|
||||
@@ -477,8 +683,7 @@ protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
|
||||
struct Mach_thread_command
|
||||
{
|
||||
__packed_struct(Mach_thread_command)
|
||||
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
LE32 cmdsize; /* total size of this command */
|
||||
LE32 flavor;
|
||||
@@ -486,8 +691,107 @@ protected:
|
||||
Mach_i386_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM
|
||||
#include "p_mach_enum.h"
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
class PackDylibI386 : public PackMachI386
|
||||
{
|
||||
typedef PackMachI386 super;
|
||||
|
||||
public:
|
||||
PackDylibI386(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_DYLIB_i386; }
|
||||
virtual const char *getName() const { return "Dylib/i386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-darwin.dylib"; }
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
};
|
||||
|
||||
class PackMachAMD64 : public PackMachBase<MachClass_LE64>
|
||||
{
|
||||
typedef PackMachBase<MachClass_LE64> super;
|
||||
|
||||
public:
|
||||
PackMachAMD64(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_AMD64; }
|
||||
virtual const char *getName() const { return "Mach/AMD64"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "AMD64-darwin.macho"; }
|
||||
protected:
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo);
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
|
||||
__packed_struct(Mach_thread_command)
|
||||
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
LE32 cmdsize; /* total size of this command */
|
||||
LE32 flavor;
|
||||
LE32 count; /* sizeof(following_thread_state)/4 */
|
||||
Mach_AMD64_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
class PackDylibAMD64 : public PackMachAMD64
|
||||
{
|
||||
typedef PackMachAMD64 super;
|
||||
|
||||
public:
|
||||
PackDylibAMD64(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_DYLIB_AMD64; }
|
||||
virtual const char *getName() const { return "Dylib/AMD64"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "AMD64-darwin.dylib"; }
|
||||
protected:
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
};
|
||||
|
||||
class PackMachARMEL : public PackMachBase<MachClass_LE32>
|
||||
{
|
||||
typedef PackMachBase<MachClass_LE32> super;
|
||||
|
||||
public:
|
||||
PackMachARMEL(InputFile *f);
|
||||
|
||||
virtual int getFormat() const { return UPX_F_MACH_ARMEL; }
|
||||
virtual const char *getName() const { return "Mach/ARMEL"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "ARMEL-darwin.macho"; }
|
||||
protected:
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack1_setup_threado(OutputFile *const fo);
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
|
||||
__packed_struct(Mach_thread_command)
|
||||
LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */
|
||||
LE32 cmdsize; /* total size of this command */
|
||||
LE32 flavor;
|
||||
LE32 count; /* sizeof(following_thread_state)/4 */
|
||||
Mach_ARM_thread_state state;
|
||||
#define WANT_MACH_THREAD_ENUM
|
||||
#include "p_mach_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
Mach_thread_command threado;
|
||||
};
|
||||
|
||||
@@ -525,11 +829,11 @@ public:
|
||||
#endif
|
||||
enum { N_FAT_ARCH = 5 };
|
||||
protected:
|
||||
struct Fat_head {
|
||||
__packed_struct(Fat_head)
|
||||
struct Mach_fat_header fat;
|
||||
struct Mach_fat_arch arch[N_FAT_ARCH];
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
Fat_head fat_head;
|
||||
|
||||
// UI handler
|
||||
|
||||
+44
-12
@@ -2,7 +2,7 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2007 John F. Reiser
|
||||
Copyright (C) 2007-2010 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -40,11 +40,19 @@
|
||||
};
|
||||
enum { // cputype
|
||||
CPU_TYPE_I386 = 7,
|
||||
CPU_TYPE_X86_64 = 0x01000007,
|
||||
CPU_TYPE_ARM = 12,
|
||||
CPU_TYPE_POWERPC = 0x00000012,
|
||||
CPU_TYPE_POWERPC64 = 0x01000012
|
||||
};
|
||||
enum { // cpusubtype
|
||||
CPU_SUBTYPE_ARM_ALL = 0,
|
||||
CPU_SUBTYPE_ARM_V4T = 5,
|
||||
CPU_SUBTYPE_ARM_V6 = 6
|
||||
};
|
||||
enum { // filetype
|
||||
MH_EXECUTE = 2
|
||||
MH_EXECUTE = 2,
|
||||
MH_DYLIB = 6
|
||||
};
|
||||
enum { // flags
|
||||
MH_NOUNDEFS = 1
|
||||
@@ -55,10 +63,23 @@
|
||||
#undef WANT_MACH_SEGMENT_ENUM
|
||||
enum { // cmd
|
||||
LC_SEGMENT = 0x1,
|
||||
LC_SYMTAB = 0x2,
|
||||
LC_THREAD = 0x4,
|
||||
LC_UNIXTHREAD = 0x5,
|
||||
LC_DYSYMTAB = 0xb,
|
||||
LC_LOAD_DYLIB = 0xc,
|
||||
LC_ID_DYLIB = 0xd,
|
||||
LC_LOAD_DYLINKER = 0xe,
|
||||
LC_SEGMENT_64 = 0x19
|
||||
LC_ROUTINES = 0x11,
|
||||
LC_TWOLEVEL_HINTS= 0x16,
|
||||
LC_SEGMENT_64 = 0x19,
|
||||
LC_ROUTINES_64 = 0x1a,
|
||||
LC_UUID = 0x1b,
|
||||
LC_RPATH = 0x1c,
|
||||
LC_CODE_SIGNATURE = 0x1d,
|
||||
LC_SEGMENT_SPLIT_INFO = 0x1e,
|
||||
LC_REEXPORT_DYLIB = 0x1f,
|
||||
LC_REQ_DYLD = 0x80000000 // OR'ed ==> must not ignore
|
||||
};
|
||||
enum { // maxprot
|
||||
VM_PROT_READ = 1,
|
||||
@@ -69,24 +90,32 @@
|
||||
|
||||
#ifdef WANT_MACH_SECTION_ENUM /*{*/
|
||||
#undef WANT_MACH_SECTION_ENUM
|
||||
enum { // section flags
|
||||
enum { // section type (low byte only)
|
||||
S_REGULAR = 0,
|
||||
S_ZEROFILL,
|
||||
S_CSTRING_LITERALS,
|
||||
S_4BYTE_LITERALS,
|
||||
S_8BYTE_LITERALS,
|
||||
S_LITERAL_POINTERS,
|
||||
S_NON_LAZY_SYMBOL_POINTERS,
|
||||
S_LAZY_SYMBOL_POINTERS,
|
||||
S_NON_LAZY_SYMBOL_POINTERS, // sectname __nl_symbol_ptr
|
||||
S_LAZY_SYMBOL_POINTERS, // sectname __la_symbol_ptr
|
||||
S_SYMBOL_STUBS,
|
||||
S_MOD_INIT_FUNC_POINTERS,
|
||||
S_MOD_TERM_FNC_POINTERS,
|
||||
S_COALESCED
|
||||
S_MOD_INIT_FUNC_POINTERS, // sectname __mod_init_func
|
||||
S_MOD_TERM_FUNC_POINTERS,
|
||||
S_COALESCED,
|
||||
S_GB_ZEROFILL,
|
||||
S_INTERPOSING,
|
||||
S_16BYTE_LITERALS,
|
||||
S_DTRACE_DOF
|
||||
};
|
||||
enum {
|
||||
enum { // section flags (high 24 bits)
|
||||
S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
|
||||
S_ATTR_NO_TOC = 0x40000000,
|
||||
S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
|
||||
S_ATTR_NO_DEAD_STRIP = 0x10000000,
|
||||
S_ATTR_LIVE_SUPPORT = 0x08000000,
|
||||
S_ATTR_SELF_MODIFYING_CODE = 0x04000000,
|
||||
S_ATTR_DEBUG = 0x02000000,
|
||||
S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
|
||||
S_ATTR_EXT_RELOC = 0x00000200,
|
||||
S_ATTR_LOC_RELOC = 0x00000100
|
||||
@@ -97,8 +126,11 @@
|
||||
#undef WANT_MACH_THREAD_ENUM
|
||||
enum { // thread flavor
|
||||
PPC_THREAD_STATE = 1,
|
||||
i386_THREAD_STATE = 1,
|
||||
i386_OLD_THREAD_STATE = -1
|
||||
PPC_THREAD_STATE64 = 5,
|
||||
x86_THREAD_STATE32 = 1,
|
||||
x86_THREAD_STATE64 = 4,
|
||||
i386_OLD_THREAD_STATE = -1,
|
||||
ARM_THREAD_STATE = 1
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
|
||||
+6
-6
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2002-2008 Jens Medoch
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -127,8 +127,8 @@ int PackPs1::readFileHeader()
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ih, sizeof(ih));
|
||||
if (memcmp(&ih.id, "PS-X EXE", 8) != 0 &&
|
||||
memcmp(&ih.id, "EXE X-SP", 8) != 0)
|
||||
if (memcmp(&ih.id[0], "PS-X EXE", 8) != 0 &&
|
||||
memcmp(&ih.id[0], "EXE X-SP", 8) != 0)
|
||||
return 0;
|
||||
if (ih.text != 0 || ih.data != 0)
|
||||
return 0;
|
||||
@@ -433,7 +433,7 @@ bool PackPs1::findBssSection()
|
||||
reg = REG1(op);
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
bss_nfo *p = (bss_nfo *)&p1[i];
|
||||
bss_nfo *p = (bss_nfo *)(void *)&p1[i];
|
||||
unsigned short op1 = p->op1, op2 = p->op2;
|
||||
|
||||
// check for la (x),bss_start
|
||||
|
||||
+11
-19
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2002-2008 Jens Medoch
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
Copyright (C) 2002-2010 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -67,8 +67,7 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
virtual bool checkFileHeader();
|
||||
|
||||
struct ps1_exe_t
|
||||
{
|
||||
__packed_struct(ps1_exe_t)
|
||||
// ident string
|
||||
char id[8];
|
||||
// is NULL
|
||||
@@ -91,33 +90,26 @@ protected:
|
||||
char origin[60];
|
||||
// backup of the original header (epc - is_len)
|
||||
// id & the upx header ...
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
// for unpack
|
||||
struct ps1_exe_hb_t
|
||||
{
|
||||
__packed_struct(ps1_exe_hb_t)
|
||||
LE32 ih_bkup[10];
|
||||
// plus checksum for the backup
|
||||
LE32 ih_csum;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct ps1_exe_chb_t
|
||||
{
|
||||
__packed_struct(ps1_exe_chb_t)
|
||||
unsigned char id;
|
||||
unsigned char len;
|
||||
LE16 ih_csum;
|
||||
unsigned char ih_bkup;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct bss_nfo
|
||||
{
|
||||
__packed_struct(bss_nfo)
|
||||
LE16 hi1, op1, lo1, op2;
|
||||
LE16 hi2, op3, lo2, op4;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
ps1_exe_t ih, oh;
|
||||
ps1_exe_hb_t bh;
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+4
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -62,8 +62,7 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
virtual bool checkFileHeader();
|
||||
|
||||
struct tos_header_t
|
||||
{
|
||||
__packed_struct(tos_header_t)
|
||||
BE16 fh_magic;
|
||||
BE32 fh_text;
|
||||
BE32 fh_data;
|
||||
@@ -72,8 +71,7 @@ protected:
|
||||
BE32 fh_reserved;
|
||||
BE32 fh_flag;
|
||||
BE16 fh_reloc;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
tos_header_t ih, oh;
|
||||
|
||||
|
||||
+5
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -412,6 +412,9 @@ void PackUnix::packExtent(
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
// write compressed data
|
||||
if (ph.c_len < ph.u_len) {
|
||||
fo->write(obuf, ph.c_len);
|
||||
@@ -422,9 +425,6 @@ void PackUnix::packExtent(
|
||||
fo->write(ibuf, ph.u_len);
|
||||
}
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
total_in += ph.u_len;
|
||||
total_out += ph.c_len;
|
||||
}
|
||||
|
||||
+23
-31
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -92,30 +92,28 @@ protected:
|
||||
unsigned b_len; // total length of b_info blocks
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
unsigned sz_unc; // uncompressed_size
|
||||
unsigned sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
unsigned p_progid;
|
||||
unsigned p_filesize;
|
||||
unsigned p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct l_info linfo;
|
||||
|
||||
@@ -135,31 +133,28 @@ protected:
|
||||
PackUnixBe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
BE32 sz_unc; // uncompressed_size
|
||||
BE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
BE32 l_checksum;
|
||||
BE32 l_magic;
|
||||
BE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
BE32 p_progid;
|
||||
BE32 p_filesize;
|
||||
BE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
__packed_struct_end()
|
||||
};
|
||||
|
||||
|
||||
@@ -170,31 +165,28 @@ protected:
|
||||
PackUnixLe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
LE32 sz_unc; // uncompressed_size
|
||||
LE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
LE32 p_progid;
|
||||
LE32 p_filesize;
|
||||
LE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
__packed_struct_end()
|
||||
};
|
||||
|
||||
|
||||
|
||||
+7
-8
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2004-2008 John Reiser
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2004-2010 John Reiser
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -64,7 +64,7 @@ PackVmlinuxBase<T>::PackVmlinuxBase(InputFile *f,
|
||||
n_ptload(0), phdri(NULL), shdri(NULL), shstrtab(NULL)
|
||||
{
|
||||
ElfClass::compileTimeAssertions();
|
||||
bele = N_BELE_CTP::getRTP<BeLePolicy>();
|
||||
bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -301,7 +301,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
|
||||
if (UPX_E_OK!=r || len_unc<=len_cpr) // FIXME: allow no compression
|
||||
throwInternalError("Ehdr compression failed");
|
||||
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
unsigned sz_unc; // uncompressed_size
|
||||
unsigned sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
@@ -309,8 +309,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused; // FIXME: !=0 for partial-block unfilter
|
||||
// unsigned f_offset, f_len; // only if partial-block unfilter
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct b_info hdr_info;
|
||||
set_be32(&hdr_info.sz_unc, len_unc);
|
||||
@@ -628,7 +627,7 @@ void prep_kernel(unsigned long a1, unsigned long a2)
|
||||
|
||||
fo->seek(0, SEEK_SET);
|
||||
fo->write(&ehdro, sizeof(ehdro));
|
||||
fo->write(&shdro, sizeof(shdro));
|
||||
fo->write(&shdro[0], sizeof(shdro));
|
||||
if (Ehdr::EM_PPC==my_e_machine) {
|
||||
fo->seek(sizeof(unsigned), SEEK_CUR);
|
||||
set_be32(&ppc32_extra, ppc32_extra - 2*sizeof(unsigned) + txt_c_len);
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+433
-17
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#include "p_elf.h"
|
||||
#include "file.h"
|
||||
#include "filter.h"
|
||||
#include "packer.h"
|
||||
@@ -52,9 +53,10 @@ static const unsigned bzimage_offset = 0x100000;
|
||||
|
||||
PackVmlinuzI386::PackVmlinuzI386(InputFile *f) :
|
||||
super(f), physical_start(0x100000), page_offset(0), config_physical_align(0)
|
||||
, filter_len(0)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x218);
|
||||
COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x250);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +84,13 @@ const int *PackBvmlinuzI386::getFilters() const
|
||||
return filters;
|
||||
}
|
||||
|
||||
int PackVmlinuzI386::getStrategy(Filter &/*ft*/)
|
||||
{
|
||||
// If user specified the filter, then use it (-2==filter_strategy).
|
||||
// Else try the first two filters, and pick the better (2==filter_strategy).
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
|
||||
bool PackVmlinuzI386::canPack()
|
||||
{
|
||||
@@ -95,8 +104,6 @@ bool PackVmlinuzI386::canPack()
|
||||
|
||||
int PackVmlinuzI386::readFileHeader()
|
||||
{
|
||||
boot_sect_t h;
|
||||
|
||||
setup_size = 0;
|
||||
|
||||
fi->readx(&h, sizeof(h));
|
||||
@@ -160,6 +167,10 @@ int PackVmlinuzI386::decompressKernel()
|
||||
unsigned cpa_0 = 0;
|
||||
unsigned cpa_1 = 0;
|
||||
int j;
|
||||
if (0x205<=h.version) {
|
||||
cpa_0 = h.kernel_alignment;
|
||||
cpa_1 = 0u - cpa_0;
|
||||
} else
|
||||
for ((p = &obuf[setup_size]), (j= 0); j < 0x200; ++j, ++p) {
|
||||
if (0==memcmp("\x89\xeb\x81\xc3", p, 4)
|
||||
&& 0==memcmp("\x81\xe3", 8+ p, 2)) {
|
||||
@@ -225,14 +236,18 @@ int PackVmlinuzI386::decompressKernel()
|
||||
|
||||
checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, (off_t)1024));
|
||||
|
||||
for (int gzoff = setup_size; gzoff < file_size; gzoff++)
|
||||
int gzoff = setup_size;
|
||||
if (0x208<=h.version) {
|
||||
gzoff += h.payload_offset;
|
||||
}
|
||||
for (; gzoff < file_size; gzoff++)
|
||||
{
|
||||
// find gzip header (2 bytes magic + 1 byte method "deflated")
|
||||
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3);
|
||||
if (off < 0)
|
||||
break;
|
||||
gzoff += off;
|
||||
const int gzlen = file_size - gzoff;
|
||||
const int gzlen = (h.version < 0x208) ? (file_size - gzoff) : h.payload_length;
|
||||
if (gzlen < 256)
|
||||
break;
|
||||
// check gzip flag byte
|
||||
@@ -281,6 +296,49 @@ int PackVmlinuzI386::decompressKernel()
|
||||
if (klen <= gzlen)
|
||||
continue;
|
||||
|
||||
if (0x208<=h.version && 0==memcmp("\177ELF", ibuf, 4)) {
|
||||
// Full ELF in theory; for now, try to handle as .bin at physical_start.
|
||||
// Check for PT_LOAD.p_paddr being ascending and adjacent.
|
||||
Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)(void const *)ibuf;
|
||||
Elf_LE32_Phdr const *phdr = (Elf_LE32_Phdr const *)(ehdr->e_phoff + (char const *)ehdr);
|
||||
Elf_LE32_Shdr const *shdr = (Elf_LE32_Shdr const *)(ehdr->e_shoff + (char const *)ehdr);
|
||||
unsigned hi_paddr = 0, lo_paddr = 0;
|
||||
unsigned delta_off = 0;
|
||||
for (unsigned j=0; j < ehdr->e_phnum; ++j, ++phdr) {
|
||||
if (phdr->PT_LOAD==phdr->p_type) {
|
||||
unsigned step = (hi_paddr + phdr->p_align - 1) & ~(phdr->p_align - 1);
|
||||
if (0==hi_paddr) { // first PT_LOAD
|
||||
if (physical_start!=phdr->p_paddr) {
|
||||
return 0;
|
||||
}
|
||||
delta_off = phdr->p_paddr - phdr->p_offset;
|
||||
lo_paddr = phdr->p_paddr;
|
||||
hi_paddr = phdr->p_filesz + phdr->p_paddr;
|
||||
}
|
||||
else if (step==phdr->p_paddr
|
||||
&& delta_off==(phdr->p_paddr - phdr->p_offset)) {
|
||||
hi_paddr = phdr->p_filesz + phdr->p_paddr;
|
||||
}
|
||||
else {
|
||||
return 0; // Not equivalent to a .bin. Too complex for now.
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME: ascending order is only a convention; might need sorting.
|
||||
for (unsigned j=1; j < ehdr->e_shnum; ++j) {
|
||||
if (shdr->SHT_PROGBITS==shdr->sh_type) { // SHT_REL might be intermixed
|
||||
if (shdr->SHF_EXECINSTR & shdr[j].sh_flags) {
|
||||
filter_len += shdr[j].sh_size; // FIXME: include sh_addralign
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
memmove(ibuf, (lo_paddr - delta_off) + ibuf, hi_paddr - lo_paddr); // FIXME: set_size
|
||||
// FIXME: .bss ? Apparently handled by head.S
|
||||
}
|
||||
|
||||
if (opt->force > 0)
|
||||
return klen;
|
||||
|
||||
@@ -402,7 +460,7 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
|
||||
@@ -419,6 +477,7 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
||||
|
||||
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16u) / 16;
|
||||
bs->payload_length = ph.c_len;
|
||||
|
||||
fo->write(setup_buf, setup_buf.getSize());
|
||||
fo->write(loader, lsize);
|
||||
@@ -448,7 +507,7 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
|
||||
initLoader(stub_i386_linux_kernel_vmlinuz, sizeof(stub_i386_linux_kernel_vmlinuz));
|
||||
if (0!=page_offset) { // relocatable kernel
|
||||
assert(0==ft->id || 0x40==(0xf0 & ft->id)); // others assume fixed buffer address
|
||||
addLoader("LINUZ000,LINUZVGA,LINUZ101,LINUZ110",
|
||||
addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ101,LINUZ110",
|
||||
((0!=config_physical_align) ? "LINUZ120" : "LINUZ130"),
|
||||
"LINUZ140,LZCUTPOI,LINUZ141",
|
||||
(ft->id ? "LINUZ145" : ""),
|
||||
@@ -456,7 +515,7 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
|
||||
NULL);
|
||||
}
|
||||
else {
|
||||
addLoader("LINUZ000,LINUZVGA,LINUZ001",
|
||||
addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ005",
|
||||
ph.first_offset_found == 1 ? "LINUZ010" : "",
|
||||
(0x40==(0xf0 & ft->id)) ? "LZCKLLT1" : (ft->id ? "LZCALLT1" : ""),
|
||||
"LBZIMAGE,IDENTSTR",
|
||||
@@ -511,17 +570,17 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
||||
|
||||
// prepare filter
|
||||
Filter ft(ph.level);
|
||||
ft.buf_len = ph.u_len;
|
||||
ft.buf_len = (filter_len ? filter_len : (ph.u_len * 3)/5);
|
||||
// May 2008: 3/5 is heuristic to cover most .text but avoid non-instructions.
|
||||
// Otherwise "call trick" filter cannot find a free marker byte,
|
||||
// especially when it searches over tables of data.
|
||||
ft.addvalue = 0; // The destination buffer might be relocated at runtime.
|
||||
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
// LINUZ001 allows most of low memory as stack for Bvmlinuz
|
||||
cconf.conf_lzma.max_num_probs = (0x90000 - 0x10000)>>1; // ushort: 512 KiB stack
|
||||
|
||||
// FIXME: new stub allows most of low memory as stack for Bvmlinuz ?
|
||||
//cconf.conf_lzma.max_num_probs = (0x99000 - 0x10250)>>1; // ushort: 560560 stack
|
||||
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
|
||||
// align everything to dword boundary - it is easier to handle
|
||||
unsigned c_len = ph.c_len;
|
||||
@@ -652,6 +711,363 @@ void PackVmlinuzI386::unpack(OutputFile *fo)
|
||||
}
|
||||
|
||||
|
||||
PackVmlinuzARMEL::PackVmlinuzARMEL(InputFile *f) :
|
||||
super(f), setup_size(0), filter_len(0)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
}
|
||||
|
||||
const int *PackVmlinuzARMEL::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
return Packer::getDefaultCompressionMethods_8(method, level);
|
||||
}
|
||||
|
||||
const int *PackVmlinuzARMEL::getFilters() const
|
||||
{
|
||||
static const int f50[] = { 0x50, FT_END };
|
||||
return f50;
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::getStrategy(Filter &/*ft*/)
|
||||
{
|
||||
// If user specified the filter, then use it (-2==filter_strategy).
|
||||
// Else try the first two filters, and pick the better (2==filter_strategy).
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
bool PackVmlinuzARMEL::canPack()
|
||||
{
|
||||
return readFileHeader() == getFormat();
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::readFileHeader()
|
||||
{
|
||||
unsigned int hdr[8];
|
||||
|
||||
fi->readx(hdr, sizeof(hdr));
|
||||
for (int j=0; j < 8; ++j) {
|
||||
if (0xe1a00000!=get_te32(&hdr[j])) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return UPX_F_VMLINUZ_ARMEL;
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::decompressKernel()
|
||||
{
|
||||
// read whole kernel image
|
||||
obuf.alloc(file_size);
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(obuf, file_size);
|
||||
|
||||
//checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, (off_t)1024));
|
||||
|
||||
// Find head.S:
|
||||
// bl decompress_kernel # 0xeb......
|
||||
// b call_kernel # 0xea......
|
||||
//LC0: .word LC0 # self!
|
||||
unsigned decompress_kernel = 0;
|
||||
unsigned caller1 = 0;
|
||||
unsigned caller2 = 0;
|
||||
unsigned got_start = 0;
|
||||
unsigned got_end = 0;
|
||||
for (unsigned j = 0; j < 0x400; j+=4) {
|
||||
unsigned w;
|
||||
if (j!=get_te32(j + obuf)) {
|
||||
continue;
|
||||
}
|
||||
if (0xea000000!=(0xff000000& get_te32(j - 4 + obuf))
|
||||
|| 0xeb000000!=(0xff000000&(w= get_te32(j - 8 + obuf))) ) {
|
||||
continue;
|
||||
}
|
||||
caller1 = j - 8;
|
||||
decompress_kernel = ((0x00ffffff & w)<<2) + 8+ caller1;
|
||||
for (unsigned k = 12; k<=128; k+=4) {
|
||||
w = get_te32(j - k + obuf);
|
||||
if (0xeb000000==(0xff000000 & w)
|
||||
&& decompress_kernel==(((0x00ffffff & w)<<2) + 8+ j - k) ) {
|
||||
caller2 = j - k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
got_start = get_te32(5*4 + j + obuf);
|
||||
got_end = get_te32(6*4 + j + obuf);
|
||||
#if 0 /*{*/
|
||||
printf("decompress_kernel=0x%x got_start=0x%x got_end=0x%x\n",
|
||||
decompress_kernel, got_start, got_end);
|
||||
#endif /*}*/
|
||||
break;
|
||||
}
|
||||
if (0==decompress_kernel) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Find first subroutine that is called by decompress_kernel,
|
||||
// which we will consider to be the start of the gunzip module
|
||||
// and the end of the non-gunzip modules.
|
||||
for (unsigned j = decompress_kernel; j < (unsigned)file_size; j+=4) {
|
||||
unsigned w = get_te32(j + obuf);
|
||||
if (0xeb800000==(0xff800000 & w)) {
|
||||
setup_size = 8+ ((0xff000000 | w)<<2) + j;
|
||||
// Move the GlobalOffsetTable.
|
||||
for (unsigned k = got_start; k < got_end; k+=4) {
|
||||
w = get_te32(k + obuf);
|
||||
// FIXME: must relocate w
|
||||
set_te32(k - got_start + setup_size + obuf, w);
|
||||
}
|
||||
setup_size += got_end - got_start;
|
||||
set_te32(&obuf[caller1], 0xeb000000 |
|
||||
(0x00ffffff & ((setup_size - (8+ caller1))>>2)) );
|
||||
set_te32(&obuf[caller2], 0xeb000000 |
|
||||
(0x00ffffff & ((setup_size - (8+ caller2))>>2)) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int gzoff = 0; gzoff < 0x4000; gzoff+=4) {
|
||||
// find gzip header (2 bytes magic + 1 byte method "deflated")
|
||||
int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3);
|
||||
if (off < 0 || 0!=(3u & off))
|
||||
break; // not found, or not word-aligned
|
||||
gzoff += off;
|
||||
const int gzlen = file_size - gzoff;
|
||||
if (gzlen < 256)
|
||||
break;
|
||||
// check gzip flag byte
|
||||
unsigned char flags = obuf[gzoff + 3];
|
||||
if ((flags & 0xe0) != 0) // reserved bits set
|
||||
continue;
|
||||
//printf("found gzip header at offset %d\n", gzoff);
|
||||
|
||||
// try to decompress
|
||||
int klen;
|
||||
int fd;
|
||||
off_t fd_pos;
|
||||
for (;;)
|
||||
{
|
||||
klen = -1;
|
||||
fd = -1;
|
||||
fd_pos = -1;
|
||||
// open
|
||||
fi->seek(gzoff, SEEK_SET);
|
||||
fd = dup(fi->getFd());
|
||||
if (fd < 0)
|
||||
break;
|
||||
gzFile zf = gzdopen(fd, "rb");
|
||||
if (zf == NULL)
|
||||
break;
|
||||
// estimate gzip-decompressed kernel size & alloc buffer
|
||||
if (ibuf.getSize() == 0)
|
||||
ibuf.alloc(gzlen * 3);
|
||||
// decompress
|
||||
klen = gzread(zf, ibuf, ibuf.getSize());
|
||||
fd_pos = lseek(fd, 0, SEEK_CUR);
|
||||
gzclose(zf);
|
||||
fd = -1;
|
||||
if (klen != (int)ibuf.getSize())
|
||||
break;
|
||||
// realloc and try again
|
||||
unsigned const s = ibuf.getSize();
|
||||
ibuf.dealloc();
|
||||
ibuf.alloc(3 * s / 2);
|
||||
}
|
||||
if (fd >= 0)
|
||||
(void) close(fd);
|
||||
if (klen <= 0)
|
||||
continue;
|
||||
|
||||
if (klen <= gzlen)
|
||||
continue;
|
||||
|
||||
if (opt->force > 0)
|
||||
return klen;
|
||||
|
||||
// some checks
|
||||
if (fd_pos != file_size) {
|
||||
//printf("fd_pos: %ld, file_size: %ld\n", (long)fd_pos, (long)file_size);
|
||||
}
|
||||
|
||||
//head_ok:
|
||||
|
||||
// FIXME: more checks for special magic bytes in ibuf ???
|
||||
// FIXME: more checks for kernel architecture ???
|
||||
|
||||
return klen;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::readKernel()
|
||||
{
|
||||
int klen = decompressKernel();
|
||||
if (klen <= 0)
|
||||
throwCantPack("kernel decompression failed");
|
||||
//OutputFile::dump("kernel.img", ibuf, klen);
|
||||
|
||||
// copy the setup boot code
|
||||
setup_buf.alloc(setup_size);
|
||||
memcpy(setup_buf, obuf, setup_size);
|
||||
//OutputFile::dump("setup.img", setup_buf, setup_size);
|
||||
|
||||
obuf.dealloc();
|
||||
obuf.allocForCompression(klen);
|
||||
|
||||
ph.u_len = klen;
|
||||
ph.filter = 0;
|
||||
}
|
||||
|
||||
Linker* PackVmlinuzARMEL::newLinker() const
|
||||
{
|
||||
return new ElfLinkerArmLE;
|
||||
}
|
||||
|
||||
static const
|
||||
#include "stub/arm-linux.kernel.vmlinux.h"
|
||||
static const
|
||||
#include "stub/armel-linux.kernel.vmlinuz-head.h"
|
||||
|
||||
void PackVmlinuzARMEL::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader; same as vmlinux (with 'x')
|
||||
initLoader(stub_arm_linux_kernel_vmlinux, sizeof(stub_arm_linux_kernel_vmlinux));
|
||||
addLoader("LINUX000", NULL);
|
||||
if (ft->id) {
|
||||
assert(ft->calls > 0);
|
||||
addLoader("LINUX010", NULL);
|
||||
}
|
||||
addLoader("LINUX020", NULL);
|
||||
if (ft->id) {
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("LINUX030", NULL);
|
||||
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL);
|
||||
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL);
|
||||
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL);
|
||||
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00",
|
||||
(opt->small ? "LZMA_DEC10" : "LZMA_DEC20"), "LZMA_DEC30", NULL);
|
||||
else throwBadLoader();
|
||||
addLoader("IDENTSTR,UPX1HEAD", NULL);
|
||||
|
||||
// To debug (2008-09-14):
|
||||
// Build gdb-6.8-21.fc9.src.rpm; ./configure --target=arm-none-elf; make
|
||||
// Contains the fix for http://bugzilla.redhat.com/show_bug.cgi?id=436037
|
||||
// Install qemu-0.9.1-6.fc9.i386.rpm
|
||||
// qemu-system-arm -s -S -kernel <file> -nographic
|
||||
// (gdb) target remote localhost:1234
|
||||
// A very small boot loader runs at pc=0x0; the kernel is at 0x10000 (64KiB).
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::defineDecompressorSymbols()
|
||||
{
|
||||
super::defineDecompressorSymbols();
|
||||
linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len);
|
||||
linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len);
|
||||
linker->defineSymbol("METHOD", ph.method);
|
||||
}
|
||||
|
||||
unsigned PackVmlinuzARMEL::write_vmlinuz_head(OutputFile *const fo)
|
||||
{ // First word from vmlinuz-head.S
|
||||
fo->write(&stub_armel_linux_kernel_vmlinuz_head[0], 4);
|
||||
|
||||
// Second word
|
||||
LE32 tmp_u32;
|
||||
unsigned const t = (0xff000000 &
|
||||
get_te32(&stub_armel_linux_kernel_vmlinuz_head[4]))
|
||||
| (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2)));
|
||||
tmp_u32 = t;
|
||||
fo->write((void const *)&tmp_u32, 4);
|
||||
|
||||
return sizeof(stub_armel_linux_kernel_vmlinuz_head);
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::pack(OutputFile *fo)
|
||||
{
|
||||
readKernel();
|
||||
|
||||
// prepare filter
|
||||
Filter ft(ph.level);
|
||||
ft.buf_len = ph.u_len;
|
||||
ft.addvalue = 0;
|
||||
|
||||
// compress
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 5); // ushort: 52,844 byte stack
|
||||
compressWithFilters(&ft, 512, &cconf, getStrategy(ft));
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
|
||||
defineDecompressorSymbols();
|
||||
defineFilterSymbols(&ft);
|
||||
relocateLoader();
|
||||
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
patchPackHeader(loader, lsize);
|
||||
|
||||
// boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||
// bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16u) / 16;
|
||||
// bs->payload_length = ph.c_len;
|
||||
|
||||
fo->write(setup_buf, setup_buf.getSize());
|
||||
write_vmlinuz_head(fo);
|
||||
fo->write(obuf, ph.c_len);
|
||||
unsigned const zero = 0;
|
||||
fo->write((void const *)&zero, 3u & (0u - ph.c_len));
|
||||
fo->write(loader, lsize);
|
||||
#if 0
|
||||
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
|
||||
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
|
||||
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
|
||||
#endif
|
||||
|
||||
// verify
|
||||
verifyOverlappingDecompression();
|
||||
|
||||
// finally check the compression ratio
|
||||
if (!checkFinalCompressionRatio(fo))
|
||||
throwNotCompressible();
|
||||
}
|
||||
|
||||
int PackVmlinuzARMEL::canUnpack()
|
||||
{
|
||||
if (readFileHeader() != getFormat())
|
||||
return false;
|
||||
fi->seek(setup_size, SEEK_SET);
|
||||
return readPackHeader(1024) ? 1 : -1;
|
||||
}
|
||||
|
||||
void PackVmlinuzARMEL::unpack(OutputFile *fo)
|
||||
{
|
||||
// no uncompression support for this format, so that
|
||||
// it is possible to remove the original deflate code (>10 KiB)
|
||||
|
||||
// FIXME: but we could write the uncompressed "vmlinux" image
|
||||
|
||||
ibuf.alloc(ph.c_len);
|
||||
obuf.allocForUncompression(ph.u_len);
|
||||
|
||||
fi->seek(setup_size + ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
|
||||
fi->readx(ibuf, ph.c_len);
|
||||
|
||||
// decompress
|
||||
decompress(ibuf, obuf);
|
||||
|
||||
// unfilter
|
||||
Filter ft(ph.level);
|
||||
ft.init(ph.filter, 0);
|
||||
ft.cto = (unsigned char) ph.filter_cto;
|
||||
ft.unfilter(obuf, ph.u_len);
|
||||
|
||||
// write decompressed file
|
||||
if (fo)
|
||||
{
|
||||
throwCantUnpack("build a new kernel instead :-)");
|
||||
//fo->write(obuf, ph.u_len);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+61
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.vmlinuz"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
virtual int getStrategy(Filter &);
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
@@ -63,8 +64,7 @@ protected:
|
||||
// virtual upx_byte *getLoader() const;
|
||||
// virtual int getLoaderSize() const;
|
||||
|
||||
struct boot_sect_t
|
||||
{
|
||||
__packed_struct(boot_sect_t)
|
||||
char _[0x1f1];
|
||||
unsigned char setup_sects;
|
||||
char __[2];
|
||||
@@ -79,17 +79,24 @@ protected:
|
||||
unsigned char load_flags;
|
||||
char ______[2];
|
||||
LE32 code32_start;
|
||||
|
||||
char _7[0x230 - (0x214 + 4)];
|
||||
LE32 kernel_alignment;
|
||||
char relocatable_kernel;
|
||||
char _8[0x248 - (0x234 + 1)];
|
||||
LE32 payload_offset;
|
||||
LE32 payload_length;
|
||||
// some more uninteresting fields here ...
|
||||
// see /usr/src/linux/Documentation/i386/zero-page.txt
|
||||
}
|
||||
__attribute_packed;
|
||||
// see /usr/src/linux/Documentation/i386/boot.txt
|
||||
__packed_struct_end()
|
||||
|
||||
boot_sect_t h;
|
||||
|
||||
MemBuffer setup_buf;
|
||||
int setup_size;
|
||||
unsigned physical_start;
|
||||
unsigned page_offset;
|
||||
unsigned config_physical_align;
|
||||
unsigned filter_len;
|
||||
};
|
||||
|
||||
|
||||
@@ -142,6 +149,52 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// vmlinuz/armel (gzip compressed Linux kernel image)
|
||||
**************************************************************************/
|
||||
|
||||
class PackVmlinuzARMEL : public Packer
|
||||
{
|
||||
typedef Packer super;
|
||||
public:
|
||||
PackVmlinuzARMEL(InputFile *f);
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUZ_ARMEL; }
|
||||
virtual const char *getName() const { return "vmlinuz/armel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "armel-linux.kernel.vmlinuz"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
virtual int getStrategy(Filter &);
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
virtual int canUnpack();
|
||||
|
||||
protected:
|
||||
virtual int readFileHeader();
|
||||
virtual int decompressKernel();
|
||||
virtual void readKernel();
|
||||
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual unsigned write_vmlinuz_head(OutputFile *const fo);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
// virtual upx_byte *getLoader() const;
|
||||
// virtual int getLoaderSize() const;
|
||||
|
||||
|
||||
MemBuffer setup_buf;
|
||||
int setup_size;
|
||||
// unsigned physical_start;
|
||||
// unsigned page_offset;
|
||||
// unsigned config_physical_align;
|
||||
unsigned filter_len;
|
||||
};
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
|
||||
+6
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -164,7 +164,7 @@ int PackW32Pe::readFileHeader()
|
||||
char buf[6];
|
||||
fi->seek(0x200, SEEK_SET);
|
||||
fi->readx(buf, 6);
|
||||
isrtm = memcmp(&buf, "32STUB" ,6) == 0;
|
||||
isrtm = memcmp(buf, "32STUB" ,6) == 0;
|
||||
return super::readFileHeader();
|
||||
}
|
||||
|
||||
@@ -173,14 +173,12 @@ int PackW32Pe::readFileHeader()
|
||||
// import handling
|
||||
**************************************************************************/
|
||||
|
||||
struct import_desc
|
||||
{
|
||||
__packed_struct(import_desc)
|
||||
LE32 oft; // orig first thunk
|
||||
char _[8];
|
||||
LE32 dllname;
|
||||
LE32 iat; // import address table
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
void PackW32Pe::processImports(unsigned myimport, unsigned) // pass 2
|
||||
{
|
||||
@@ -1105,7 +1103,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||
|
||||
int PackW32Pe::canUnpack()
|
||||
{
|
||||
if (!readFileHeader())
|
||||
if (!readFileHeader() || ih.cpu < 0x14c || ih.cpu > 0x150)
|
||||
return false;
|
||||
|
||||
unsigned objs = ih.objects;
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -485,7 +485,7 @@ void PackWcle::pack(OutputFile *fo)
|
||||
const unsigned text_vaddr = IOT(ih.init_cs_object-1,my_base_address);
|
||||
|
||||
// attach some useful data at the end of preprocessed fixups
|
||||
ifixups[sofixups++] = (unsigned char) ih.automatic_data_object;
|
||||
ifixups[sofixups++] = (unsigned char) (ih.automatic_data_object & 0xff);
|
||||
unsigned ic = objects*sizeof(*iobject_table);
|
||||
memcpy(ifixups+sofixups,iobject_desc,ic);
|
||||
iobject_desc.dealloc();
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2010 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