1
0
mirror of https://github.com/upx/upx synced 2025-10-26 23:36:41 +08:00

clang-format more files.

"Gofmt's style is nobody's favourite, but gofmt is everybody's favourite."
    - Rob Pike
This commit is contained in:
Markus F.X.J. Oberhumer
2021-01-04 20:26:31 +01:00
parent 8236276a90
commit 2575eef3c0
14 changed files with 1590 additions and 1871 deletions

View File

@@ -187,12 +187,16 @@ endif
# automatically format some C++ source code files
ifeq ($(shell uname),Linux)
CLANG_FORMAT_FILES += bele.h bele_policy.h
CLANG_FORMAT_FILES += except.cpp except.h
CLANG_FORMAT_FILES += linker.cpp linker.h packhead.cpp packmast.cpp packmast.h
CLANG_FORMAT_FILES += main.cpp options.h packer.cpp packer.h
CLANG_FORMAT_FILES += p_tos.cpp p_tos.h
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
CLANG_FORMAT_FILES += snprintf.cpp
CLANG_FORMAT_FILES += ui.cpp ui.h util.cpp util.h work.cpp
clang-format:
$(top_srcdir)/src/stub/scripts/upx-clang-format -i $(addprefix $(top_srcdir)/src/,$(CLANG_FORMAT_FILES))
$(top_srcdir)/src/stub/scripts/upx-clang-format -i $(addprefix $(top_srcdir)/src/,$(sort $(CLANG_FORMAT_FILES)))
.PHONY: clang-format
endif

View File

@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef __UPX_BELE_H
#define __UPX_BELE_H 1
@@ -38,46 +37,39 @@
// core - NE
**************************************************************************/
__acc_static_forceinline unsigned get_ne16(const void *p)
{
__acc_static_forceinline unsigned get_ne16(const void *p) {
upx_uint16_t v = 0;
upx_memcpy_inline(&v, p, sizeof(v));
return v;
}
__acc_static_forceinline unsigned get_ne32(const void *p)
{
__acc_static_forceinline unsigned get_ne32(const void *p) {
upx_uint32_t v = 0;
upx_memcpy_inline(&v, p, sizeof(v));
return v;
}
__acc_static_forceinline upx_uint64_t get_ne64(const void *p)
{
__acc_static_forceinline upx_uint64_t get_ne64(const void *p) {
upx_uint64_t v = 0;
upx_memcpy_inline(&v, p, sizeof(v));
return v;
}
__acc_static_forceinline void set_ne16(void *p, unsigned vv)
{
upx_uint16_t v = (upx_uint16_t) (vv & 0xffff);
__acc_static_forceinline void set_ne16(void *p, unsigned vv) {
upx_uint16_t v = (upx_uint16_t)(vv & 0xffff);
upx_memcpy_inline(p, &v, sizeof(v));
}
__acc_static_forceinline void set_ne32(void *p, unsigned vv)
{
__acc_static_forceinline void set_ne32(void *p, unsigned vv) {
upx_uint32_t v = vv;
upx_memcpy_inline(p, &v, sizeof(v));
}
__acc_static_forceinline void set_ne64(void *p, upx_uint64_t vv)
{
__acc_static_forceinline void set_ne64(void *p, upx_uint64_t vv) {
upx_uint64_t v = vv;
upx_memcpy_inline(p, &v, sizeof(v));
}
/*************************************************************************
// core - bswap
**************************************************************************/
@@ -86,253 +78,166 @@ __acc_static_forceinline void set_ne64(void *p, upx_uint64_t vv)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4)
__acc_static_forceinline unsigned bswap16(unsigned v)
{
__acc_static_forceinline unsigned bswap16(unsigned v) {
return (unsigned) _byteswap_ulong(v << 16);
}
__acc_static_forceinline unsigned bswap32(unsigned v)
{
return (unsigned) _byteswap_ulong(v);
}
__acc_static_forceinline upx_uint64_t bswap64(upx_uint64_t v)
{
return _byteswap_uint64(v);
}
__acc_static_forceinline unsigned bswap32(unsigned v) { return (unsigned) _byteswap_ulong(v); }
__acc_static_forceinline upx_uint64_t bswap64(upx_uint64_t v) { return _byteswap_uint64(v); }
#else
__acc_static_forceinline constexpr unsigned bswap16(unsigned v)
{
//return __builtin_bswap16((upx_uint16_t) (v & 0xffff));
//return (unsigned) __builtin_bswap64((upx_uint64_t) v << 48);
__acc_static_forceinline constexpr unsigned bswap16(unsigned v) {
// return __builtin_bswap16((upx_uint16_t) (v & 0xffff));
// return (unsigned) __builtin_bswap64((upx_uint64_t) v << 48);
return __builtin_bswap32(v << 16);
}
__acc_static_forceinline constexpr unsigned bswap32(unsigned v)
{
//return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
__acc_static_forceinline constexpr unsigned bswap32(unsigned v) {
// return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
return __builtin_bswap32(v);
}
__acc_static_forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v)
{
__acc_static_forceinline constexpr upx_uint64_t bswap64(upx_uint64_t v) {
return __builtin_bswap64(v);
}
#endif
__acc_static_forceinline constexpr unsigned no_bswap16(unsigned v)
{
__acc_static_forceinline constexpr unsigned no_bswap16(unsigned v) {
return v & 0xffff; // needed so that this is equivalent to bswap16() above
}
__acc_static_forceinline constexpr unsigned no_bswap32(unsigned v)
{
return v;
}
__acc_static_forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v)
{
return v;
}
__acc_static_forceinline constexpr unsigned no_bswap32(unsigned v) { return v; }
__acc_static_forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) { return v; }
#if (ACC_ABI_BIG_ENDIAN)
# define ne16_to_be16(v) no_bswap16(v)
# define ne32_to_be32(v) no_bswap32(v)
# define ne64_to_be64(v) no_bswap64(v)
# define ne16_to_le16(v) bswap16(v)
# define ne32_to_le32(v) bswap32(v)
# define ne64_to_le64(v) bswap64(v)
#define ne16_to_be16(v) no_bswap16(v)
#define ne32_to_be32(v) no_bswap32(v)
#define ne64_to_be64(v) no_bswap64(v)
#define ne16_to_le16(v) bswap16(v)
#define ne32_to_le32(v) bswap32(v)
#define ne64_to_le64(v) bswap64(v)
#else
# define ne16_to_be16(v) bswap16(v)
# define ne32_to_be32(v) bswap32(v)
# define ne64_to_be64(v) bswap64(v)
# define ne16_to_le16(v) no_bswap16(v)
# define ne32_to_le32(v) no_bswap32(v)
# define ne64_to_le64(v) no_bswap64(v)
#define ne16_to_be16(v) bswap16(v)
#define ne32_to_be32(v) bswap32(v)
#define ne64_to_be64(v) bswap64(v)
#define ne16_to_le16(v) no_bswap16(v)
#define ne32_to_le32(v) no_bswap32(v)
#define ne64_to_le64(v) no_bswap64(v)
#endif
/*************************************************************************
// get/set 16/32/64
**************************************************************************/
inline unsigned get_be16(const void *p)
{
return ne16_to_be16(get_ne16(p));
}
inline unsigned get_be32(const void *p)
{
return ne32_to_be32(get_ne32(p));
}
inline upx_uint64_t get_be64(const void *p)
{
return ne64_to_be64(get_ne64(p));
}
inline unsigned get_le16(const void *p)
{
return ne16_to_le16(get_ne16(p));
}
inline unsigned get_le32(const void *p)
{
return ne32_to_le32(get_ne32(p));
}
inline upx_uint64_t get_le64(const void *p)
{
return ne64_to_le64(get_ne64(p));
}
inline void set_be16(void *p, unsigned v)
{
set_ne16(p, ne16_to_be16(v));
}
inline void set_be32(void *p, unsigned v)
{
set_ne32(p, ne32_to_be32(v));
}
inline void set_be64(void *p, upx_uint64_t v)
{
set_ne64(p, ne64_to_be64(v));
}
inline void set_le16(void *p, unsigned v)
{
set_ne16(p, ne16_to_le16(v));
}
inline void set_le32(void *p, unsigned v)
{
set_ne32(p, ne32_to_le32(v));
}
inline void set_le64(void *p, upx_uint64_t v)
{
set_ne64(p, ne64_to_le64(v));
}
inline unsigned get_be16(const void *p) { return ne16_to_be16(get_ne16(p)); }
inline unsigned get_be32(const void *p) { return ne32_to_be32(get_ne32(p)); }
inline upx_uint64_t get_be64(const void *p) { return ne64_to_be64(get_ne64(p)); }
inline unsigned get_le16(const void *p) { return ne16_to_le16(get_ne16(p)); }
inline unsigned get_le32(const void *p) { return ne32_to_le32(get_ne32(p)); }
inline upx_uint64_t get_le64(const void *p) { return ne64_to_le64(get_ne64(p)); }
inline void set_be16(void *p, unsigned v) { set_ne16(p, ne16_to_be16(v)); }
inline void set_be32(void *p, unsigned v) { set_ne32(p, ne32_to_be32(v)); }
inline void set_be64(void *p, upx_uint64_t v) { set_ne64(p, ne64_to_be64(v)); }
inline void set_le16(void *p, unsigned v) { set_ne16(p, ne16_to_le16(v)); }
inline void set_le32(void *p, unsigned v) { set_ne32(p, ne32_to_le32(v)); }
inline void set_le64(void *p, upx_uint64_t v) { set_ne64(p, ne64_to_le64(v)); }
/*************************************************************************
// get/set 24/26
**************************************************************************/
inline unsigned get_be24(const void *p)
{
inline unsigned get_be24(const void *p) {
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
return (b[0] << 16) | (b[1] << 8) | (b[2] << 0);
}
inline unsigned get_le24(const void *p)
{
inline unsigned get_le24(const void *p) {
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
return (b[0] << 0) | (b[1] << 8) | (b[2] << 16);
}
inline void set_be24(void *p, unsigned v)
{
inline void set_be24(void *p, unsigned v) {
unsigned char *b = ACC_PCAST(unsigned char *, p);
b[0] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
b[2] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
b[2] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
}
inline void set_le24(void *p, unsigned v)
{
inline void set_le24(void *p, unsigned v) {
unsigned char *b = ACC_PCAST(unsigned char *, p);
b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
b[2] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
}
inline unsigned get_le26(const void *p) { return get_le32(p) & 0x03ffffff; }
inline unsigned get_le26(const void *p)
{
return get_le32(p) & 0x03ffffff;
}
inline void set_le26(void *p, unsigned v)
{
inline void set_le26(void *p, unsigned v) {
// preserve the top 6 bits
//set_le32(p, (get_le32(p) & 0xfc000000) | (v & 0x03ffffff));
// set_le32(p, (get_le32(p) & 0xfc000000) | (v & 0x03ffffff));
// optimized version, saving a runtime bswap32
set_ne32(p, (get_ne32(p) & ne32_to_le32(0xfc000000)) | (ne32_to_le32(v) & ne32_to_le32(0x03ffffff)));
set_ne32(p, (get_ne32(p) & ne32_to_le32(0xfc000000)) |
(ne32_to_le32(v) & ne32_to_le32(0x03ffffff)));
}
/*************************************************************************
// get signed values
**************************************************************************/
__acc_static_forceinline int sign_extend(unsigned v, unsigned bits)
{
__acc_static_forceinline int sign_extend(unsigned v, unsigned bits) {
const unsigned sign_bit = 1u << (bits - 1);
v &= sign_bit | (sign_bit - 1);
v |= 0 - (v & sign_bit);
return ACC_ICAST(int, v);
}
__acc_static_forceinline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits)
{
__acc_static_forceinline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits) {
const upx_uint64_t sign_bit = UPX_UINT64_C(1) << (bits - 1);
v &= sign_bit | (sign_bit - 1);
v |= 0 - (v & sign_bit);
return ACC_ICAST(upx_int64_t, v);
}
inline int get_be16_signed(const void *p)
{
inline int get_be16_signed(const void *p) {
unsigned v = get_be16(p);
return sign_extend(v, 16);
}
inline int get_be24_signed(const void *p)
{
inline int get_be24_signed(const void *p) {
unsigned v = get_be24(p);
return sign_extend(v, 24);
}
inline int get_be32_signed(const void *p)
{
inline int get_be32_signed(const void *p) {
unsigned v = get_be32(p);
return sign_extend(v, 32);
}
inline upx_int64_t get_be64_signed(const void *p)
{
inline upx_int64_t get_be64_signed(const void *p) {
upx_uint64_t v = get_be64(p);
return sign_extend(v, 64);
}
inline int get_le16_signed(const void *p)
{
inline int get_le16_signed(const void *p) {
unsigned v = get_le16(p);
return sign_extend(v, 16);
}
inline int get_le24_signed(const void *p)
{
inline int get_le24_signed(const void *p) {
unsigned v = get_le24(p);
return sign_extend(v, 24);
}
inline int get_le32_signed(const void *p)
{
inline int get_le32_signed(const void *p) {
unsigned v = get_le32(p);
return sign_extend(v, 32);
}
inline upx_int64_t get_le64_signed(const void *p)
{
inline upx_int64_t get_le64_signed(const void *p) {
upx_uint64_t v = get_le64(p);
return sign_extend(v, 64);
}
/*************************************************************************
// classes for portable unaligned access
//
@@ -344,113 +249,287 @@ inline upx_int64_t get_le64_signed(const void *p)
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
**************************************************************************/
__packed_struct(BE16)
struct alignas(1) BE16 {
unsigned char d[2];
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; }
BE16& operator *= (unsigned v) { set_be16(d, get_be16(d) * v); return *this; }
BE16& operator /= (unsigned v) { set_be16(d, get_be16(d) / v); return *this; }
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
BE16& operator ^= (unsigned v) { set_be16(d, get_be16(d) ^ v); return *this; }
BE16& operator <<= (unsigned v) { set_be16(d, get_be16(d) << v); return *this; }
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
BE16 &operator=(unsigned v) {
set_be16(d, v);
return *this;
}
BE16 &operator+=(unsigned v) {
set_be16(d, get_be16(d) + v);
return *this;
}
BE16 &operator-=(unsigned v) {
set_be16(d, get_be16(d) - v);
return *this;
}
BE16 &operator*=(unsigned v) {
set_be16(d, get_be16(d) * v);
return *this;
}
BE16 &operator/=(unsigned v) {
set_be16(d, get_be16(d) / v);
return *this;
}
BE16 &operator&=(unsigned v) {
set_be16(d, get_be16(d) & v);
return *this;
}
BE16 &operator|=(unsigned v) {
set_be16(d, get_be16(d) | v);
return *this;
}
BE16 &operator^=(unsigned v) {
set_be16(d, get_be16(d) ^ v);
return *this;
}
BE16 &operator<<=(unsigned v) {
set_be16(d, get_be16(d) << v);
return *this;
}
BE16 &operator>>=(unsigned v) {
set_be16(d, get_be16(d) >> v);
return *this;
}
operator unsigned () const { return get_be16(d); }
__packed_struct_end()
operator unsigned() const { return get_be16(d); }
};
__packed_struct(BE32)
struct alignas(1) BE32 {
unsigned char d[4];
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; }
BE32& operator *= (unsigned v) { set_be32(d, get_be32(d) * v); return *this; }
BE32& operator /= (unsigned v) { set_be32(d, get_be32(d) / v); return *this; }
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
BE32& operator ^= (unsigned v) { set_be32(d, get_be32(d) ^ v); return *this; }
BE32& operator <<= (unsigned v) { set_be32(d, get_be32(d) << v); return *this; }
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
BE32 &operator=(unsigned v) {
set_be32(d, v);
return *this;
}
BE32 &operator+=(unsigned v) {
set_be32(d, get_be32(d) + v);
return *this;
}
BE32 &operator-=(unsigned v) {
set_be32(d, get_be32(d) - v);
return *this;
}
BE32 &operator*=(unsigned v) {
set_be32(d, get_be32(d) * v);
return *this;
}
BE32 &operator/=(unsigned v) {
set_be32(d, get_be32(d) / v);
return *this;
}
BE32 &operator&=(unsigned v) {
set_be32(d, get_be32(d) & v);
return *this;
}
BE32 &operator|=(unsigned v) {
set_be32(d, get_be32(d) | v);
return *this;
}
BE32 &operator^=(unsigned v) {
set_be32(d, get_be32(d) ^ v);
return *this;
}
BE32 &operator<<=(unsigned v) {
set_be32(d, get_be32(d) << v);
return *this;
}
BE32 &operator>>=(unsigned v) {
set_be32(d, get_be32(d) >> v);
return *this;
}
operator unsigned () const { return get_be32(d); }
__packed_struct_end()
operator unsigned() const { return get_be32(d); }
};
__packed_struct(BE64)
struct alignas(1) BE64 {
unsigned char d[8];
BE64& operator = (upx_uint64_t v) { set_be64(d, v); return *this; }
BE64& operator += (upx_uint64_t v) { set_be64(d, get_be64(d) + v); return *this; }
BE64& operator -= (upx_uint64_t v) { set_be64(d, get_be64(d) - v); return *this; }
BE64& operator *= (upx_uint64_t v) { set_be64(d, get_be64(d) * v); return *this; }
BE64& operator /= (upx_uint64_t v) { set_be64(d, get_be64(d) / v); return *this; }
BE64& operator &= (upx_uint64_t v) { set_be64(d, get_be64(d) & v); return *this; }
BE64& operator |= (upx_uint64_t v) { set_be64(d, get_be64(d) | v); return *this; }
BE64& operator ^= (upx_uint64_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; }
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
BE64 &operator=(upx_uint64_t v) {
set_be64(d, v);
return *this;
}
BE64 &operator+=(upx_uint64_t v) {
set_be64(d, get_be64(d) + v);
return *this;
}
BE64 &operator-=(upx_uint64_t v) {
set_be64(d, get_be64(d) - v);
return *this;
}
BE64 &operator*=(upx_uint64_t v) {
set_be64(d, get_be64(d) * v);
return *this;
}
BE64 &operator/=(upx_uint64_t v) {
set_be64(d, get_be64(d) / v);
return *this;
}
BE64 &operator&=(upx_uint64_t v) {
set_be64(d, get_be64(d) & v);
return *this;
}
BE64 &operator|=(upx_uint64_t v) {
set_be64(d, get_be64(d) | v);
return *this;
}
BE64 &operator^=(upx_uint64_t v) {
set_be64(d, get_be64(d) ^ v);
return *this;
}
BE64 &operator<<=(unsigned v) {
set_be64(d, get_be64(d) << v);
return *this;
}
BE64 &operator>>=(unsigned v) {
set_be64(d, get_be64(d) >> v);
return *this;
}
operator upx_uint64_t () const { return get_be64(d); }
__packed_struct_end()
operator upx_uint64_t() const { return get_be64(d); }
};
__packed_struct(LE16)
struct alignas(1) LE16 {
unsigned char d[2];
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; }
LE16& operator *= (unsigned v) { set_le16(d, get_le16(d) * v); return *this; }
LE16& operator /= (unsigned v) { set_le16(d, get_le16(d) / v); return *this; }
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
LE16& operator ^= (unsigned v) { set_le16(d, get_le16(d) ^ v); return *this; }
LE16& operator <<= (unsigned v) { set_le16(d, get_le16(d) << v); return *this; }
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
LE16 &operator=(unsigned v) {
set_le16(d, v);
return *this;
}
LE16 &operator+=(unsigned v) {
set_le16(d, get_le16(d) + v);
return *this;
}
LE16 &operator-=(unsigned v) {
set_le16(d, get_le16(d) - v);
return *this;
}
LE16 &operator*=(unsigned v) {
set_le16(d, get_le16(d) * v);
return *this;
}
LE16 &operator/=(unsigned v) {
set_le16(d, get_le16(d) / v);
return *this;
}
LE16 &operator&=(unsigned v) {
set_le16(d, get_le16(d) & v);
return *this;
}
LE16 &operator|=(unsigned v) {
set_le16(d, get_le16(d) | v);
return *this;
}
LE16 &operator^=(unsigned v) {
set_le16(d, get_le16(d) ^ v);
return *this;
}
LE16 &operator<<=(unsigned v) {
set_le16(d, get_le16(d) << v);
return *this;
}
LE16 &operator>>=(unsigned v) {
set_le16(d, get_le16(d) >> v);
return *this;
}
operator unsigned () const { return get_le16(d); }
__packed_struct_end()
operator unsigned() const { return get_le16(d); }
};
__packed_struct(LE32)
struct alignas(1) LE32 {
unsigned char d[4];
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; }
LE32& operator *= (unsigned v) { set_le32(d, get_le32(d) * v); return *this; }
LE32& operator /= (unsigned v) { set_le32(d, get_le32(d) / v); return *this; }
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
LE32& operator ^= (unsigned v) { set_le32(d, get_le32(d) ^ v); return *this; }
LE32& operator <<= (unsigned v) { set_le32(d, get_le32(d) << v); return *this; }
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
LE32 &operator=(unsigned v) {
set_le32(d, v);
return *this;
}
LE32 &operator+=(unsigned v) {
set_le32(d, get_le32(d) + v);
return *this;
}
LE32 &operator-=(unsigned v) {
set_le32(d, get_le32(d) - v);
return *this;
}
LE32 &operator*=(unsigned v) {
set_le32(d, get_le32(d) * v);
return *this;
}
LE32 &operator/=(unsigned v) {
set_le32(d, get_le32(d) / v);
return *this;
}
LE32 &operator&=(unsigned v) {
set_le32(d, get_le32(d) & v);
return *this;
}
LE32 &operator|=(unsigned v) {
set_le32(d, get_le32(d) | v);
return *this;
}
LE32 &operator^=(unsigned v) {
set_le32(d, get_le32(d) ^ v);
return *this;
}
LE32 &operator<<=(unsigned v) {
set_le32(d, get_le32(d) << v);
return *this;
}
LE32 &operator>>=(unsigned v) {
set_le32(d, get_le32(d) >> v);
return *this;
}
operator unsigned () const { return get_le32(d); }
__packed_struct_end()
operator unsigned() const { return get_le32(d); }
};
__packed_struct(LE64)
struct alignas(1) LE64 {
unsigned char d[8];
LE64& operator = (upx_uint64_t v) { set_le64(d, v); return *this; }
LE64& operator += (upx_uint64_t v) { set_le64(d, get_le64(d) + v); return *this; }
LE64& operator -= (upx_uint64_t v) { set_le64(d, get_le64(d) - v); return *this; }
LE64& operator *= (upx_uint64_t v) { set_le64(d, get_le64(d) * v); return *this; }
LE64& operator /= (upx_uint64_t v) { set_le64(d, get_le64(d) / v); return *this; }
LE64& operator &= (upx_uint64_t v) { set_le64(d, get_le64(d) & v); return *this; }
LE64& operator |= (upx_uint64_t v) { set_le64(d, get_le64(d) | v); return *this; }
LE64& operator ^= (upx_uint64_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; }
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
operator upx_uint64_t () const { return get_le64(d); }
__packed_struct_end()
LE64 &operator=(upx_uint64_t v) {
set_le64(d, v);
return *this;
}
LE64 &operator+=(upx_uint64_t v) {
set_le64(d, get_le64(d) + v);
return *this;
}
LE64 &operator-=(upx_uint64_t v) {
set_le64(d, get_le64(d) - v);
return *this;
}
LE64 &operator*=(upx_uint64_t v) {
set_le64(d, get_le64(d) * v);
return *this;
}
LE64 &operator/=(upx_uint64_t v) {
set_le64(d, get_le64(d) / v);
return *this;
}
LE64 &operator&=(upx_uint64_t v) {
set_le64(d, get_le64(d) & v);
return *this;
}
LE64 &operator|=(upx_uint64_t v) {
set_le64(d, get_le64(d) | v);
return *this;
}
LE64 &operator^=(upx_uint64_t v) {
set_le64(d, get_le64(d) ^ v);
return *this;
}
LE64 &operator<<=(unsigned v) {
set_le64(d, get_le64(d) << v);
return *this;
}
LE64 &operator>>=(unsigned v) {
set_le64(d, get_le64(d) >> v);
return *this;
}
operator upx_uint64_t() const { return get_le64(d); }
};
// native types
#if (ACC_ABI_BIG_ENDIAN)
@@ -463,66 +542,91 @@ typedef LE32 NE32;
typedef LE64 NE64;
#endif
/*************************************************************************
// global operators (pointer addition/subtraction)
**************************************************************************/
template <class T> inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }
template <class T> inline T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }
template <class T>
inline T *operator+(T *ptr, const BE16 &v) {
return ptr + (unsigned) v;
}
template <class T>
inline T *operator-(T *ptr, const BE16 &v) {
return ptr - (unsigned) v;
}
template <class T> inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; }
template <class T> inline T* operator - (T* ptr, const BE32& v) { return ptr - (unsigned) v; }
template <class T>
inline T *operator+(T *ptr, const BE32 &v) {
return ptr + (unsigned) v;
}
template <class T>
inline T *operator-(T *ptr, const BE32 &v) {
return ptr - (unsigned) v;
}
// these are not implemented on purpose and will cause link-time errors
template <class T> T* operator + (T* ptr, const BE64& v);
template <class T> T* operator - (T* ptr, const BE64& v);
template <class T>
T *operator+(T *ptr, const BE64 &v);
template <class T>
T *operator-(T *ptr, const BE64 &v);
template <class T> inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; }
template <class T> inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }
template <class T>
inline T *operator+(T *ptr, const LE16 &v) {
return ptr + (unsigned) v;
}
template <class T>
inline T *operator-(T *ptr, const LE16 &v) {
return ptr - (unsigned) v;
}
template <class T> inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; }
template <class T> inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }
template <class T>
inline T *operator+(T *ptr, const LE32 &v) {
return ptr + (unsigned) v;
}
template <class T>
inline T *operator-(T *ptr, const LE32 &v) {
return ptr - (unsigned) v;
}
// these are not implemented on purpose and will cause link-time errors
template <class T> T* operator + (T* ptr, const LE64& v);
template <class T> T* operator - (T* ptr, const LE64& v);
template <class T>
T *operator+(T *ptr, const LE64 &v);
template <class T>
T *operator-(T *ptr, const LE64 &v);
/*************************************************************************
// global overloads
**************************************************************************/
inline unsigned ALIGN_DOWN(unsigned a, const BE32& b) { return ALIGN_DOWN(a, (unsigned) b); }
inline unsigned ALIGN_DOWN(const BE32& a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }
inline unsigned ALIGN_UP (unsigned a, const BE32& b) { return ALIGN_UP (a, (unsigned) b); }
inline unsigned ALIGN_UP (const BE32& a, unsigned b) { return ALIGN_UP ((unsigned) a, b); }
inline unsigned ALIGN_DOWN(unsigned a, const BE32 &b) { return ALIGN_DOWN(a, (unsigned) b); }
inline unsigned ALIGN_DOWN(const BE32 &a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }
inline unsigned ALIGN_UP(unsigned a, const BE32 &b) { return ALIGN_UP(a, (unsigned) b); }
inline unsigned ALIGN_UP(const BE32 &a, unsigned b) { return ALIGN_UP((unsigned) a, b); }
inline unsigned ALIGN_DOWN(unsigned a, const LE32& b) { return ALIGN_DOWN(a, (unsigned) b); }
inline unsigned ALIGN_DOWN(const LE32& a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }
inline unsigned ALIGN_UP (unsigned a, const LE32& b) { return ALIGN_UP (a, (unsigned) b); }
inline unsigned ALIGN_UP (const LE32& a, unsigned b) { return ALIGN_UP ((unsigned) a, b); }
inline unsigned ALIGN_DOWN(unsigned a, const LE32 &b) { return ALIGN_DOWN(a, (unsigned) b); }
inline unsigned ALIGN_DOWN(const LE32 &a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }
inline unsigned ALIGN_UP(unsigned a, const LE32 &b) { return ALIGN_UP(a, (unsigned) b); }
inline unsigned ALIGN_UP(const LE32 &a, unsigned b) { return ALIGN_UP((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const BE16& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const BE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const BE16& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const BE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const BE16 &b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const BE16 &a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const BE16 &b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const BE16 &a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const BE32& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const BE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const BE32& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const BE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const BE32 &b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const BE32 &a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const BE32 &b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const BE32 &a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const LE16& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const LE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const LE16& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const LE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const LE32& b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const LE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const LE32& b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const LE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const LE16 &b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const LE16 &a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const LE16 &b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const LE16 &a, unsigned b) { return UPX_MIN((unsigned) a, b); }
inline unsigned UPX_MAX(unsigned a, const LE32 &b) { return UPX_MAX(a, (unsigned) b); }
inline unsigned UPX_MAX(const LE32 &a, unsigned b) { return UPX_MAX((unsigned) a, b); }
inline unsigned UPX_MIN(unsigned a, const LE32 &b) { return UPX_MIN(a, (unsigned) b); }
inline unsigned UPX_MIN(const LE32 &a, unsigned b) { return UPX_MIN((unsigned) a, b); }
/*************************************************************************
// misc support
@@ -548,7 +652,6 @@ int __acc_cdecl_qsort le32_compare_signed(const void *, const void *);
int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
} // extern "C"
/*************************************************************************
// Provide namespaces and classes to abstract endianness policies.
//
@@ -562,35 +665,36 @@ struct BEPolicy;
struct LEPolicy;
extern const BEPolicy be_policy;
extern const LEPolicy le_policy;
}
} // namespace N_BELE_CTP
namespace N_BELE_RTP {
struct AbstractPolicy;
struct BEPolicy;
struct LEPolicy;
extern const BEPolicy be_policy;
extern const LEPolicy le_policy;
}
} // namespace N_BELE_RTP
// implementation
namespace N_BELE_CTP {
#define BELE_CTP 1
#include "bele_policy.h"
#undef BELE_CTP
}
} // namespace N_BELE_CTP
namespace N_BELE_RTP {
#define BELE_RTP 1
#include "bele_policy.h"
#undef BELE_RTP
}
} // namespace N_BELE_RTP
// util
namespace N_BELE_CTP {
inline const N_BELE_RTP::AbstractPolicy* getRTP(const BEPolicy * /*dummy*/)
{ return &N_BELE_RTP::be_policy; }
inline const N_BELE_RTP::AbstractPolicy* getRTP(const LEPolicy * /*dummy*/)
{ return &N_BELE_RTP::le_policy; }
inline const N_BELE_RTP::AbstractPolicy *getRTP(const BEPolicy * /*dummy*/) {
return &N_BELE_RTP::be_policy;
}
inline const N_BELE_RTP::AbstractPolicy *getRTP(const LEPolicy * /*dummy*/) {
return &N_BELE_RTP::le_policy;
}
} // namespace N_BELE_CTP
#endif /* already included */

View File

@@ -25,36 +25,32 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef __UPX_BELE_H
# error "this is an internal include file"
#error "this is an internal include file"
#endif
/*************************************************************************
//
**************************************************************************/
#if defined(BELE_CTP)
// CTP - Compile-Time Polymorphism (templates)
# define V static inline
# define S static int __acc_cdecl_qsort
# define C /*empty*/
// CTP - Compile-Time Polymorphism (templates)
#define V static inline
#define S static int __acc_cdecl_qsort
#define C /*empty*/
#elif defined(BELE_RTP)
// RTP - Run-Time Polymorphism (virtual functions)
# define V virtual
# define S virtual int
# define C const
// RTP - Run-Time Polymorphism (virtual functions)
#define V virtual
#define S virtual int
#define C const
#else
# error
#error
#endif
#if defined(BELE_RTP)
struct AbstractPolicy
{
inline AbstractPolicy() { }
virtual inline ~AbstractPolicy() { }
struct AbstractPolicy {
inline AbstractPolicy() {}
virtual inline ~AbstractPolicy() {}
V bool isBE() C = 0;
V bool isLE() C = 0;
@@ -88,13 +84,12 @@ struct AbstractPolicy
};
#endif
struct BEPolicy
#if defined(BELE_RTP)
: public AbstractPolicy
#endif
{
inline BEPolicy() { }
inline BEPolicy() {}
#if defined(BELE_CTP)
typedef N_BELE_RTP::BEPolicy RTP_Policy;
#elif defined(BELE_RTP)
@@ -107,50 +102,30 @@ struct BEPolicy
typedef BE32 U32;
typedef BE64 U64;
V unsigned get16(const void *p) C
{ return get_be16(p); }
V unsigned get24(const void *p) C
{ return get_be24(p); }
V unsigned get32(const void *p) C
{ return get_be32(p); }
V upx_uint64_t get64(const void *p) C
{ return get_be64(p); }
V unsigned get16(const void *p) C { return get_be16(p); }
V unsigned get24(const void *p) C { return get_be24(p); }
V unsigned get32(const void *p) C { return get_be32(p); }
V upx_uint64_t get64(const void *p) C { return get_be64(p); }
V void set16(void *p, unsigned v) C
{ set_be16(p, v); }
V void set24(void *p, unsigned v) C
{ set_be24(p, v); }
V void set32(void *p, unsigned v) C
{ set_be32(p, v); }
V void set64(void *p, upx_uint64_t v) C
{ set_be64(p, v); }
V void set16(void *p, unsigned v) C { set_be16(p, v); }
V void set24(void *p, unsigned v) C { set_be24(p, v); }
V void set32(void *p, unsigned v) C { set_be32(p, v); }
V void set64(void *p, upx_uint64_t v) C { set_be64(p, v); }
V int get16_signed(const void *p) C
{ return get_be16_signed(p); }
V int get24_signed(const void *p) C
{ return get_be24_signed(p); }
V int get32_signed(const void *p) C
{ return get_be32_signed(p); }
V upx_int64_t get64_signed(const void *p) C
{ return get_be64_signed(p); }
V int get16_signed(const void *p) C { return get_be16_signed(p); }
V int get24_signed(const void *p) C { return get_be24_signed(p); }
V int get32_signed(const void *p) C { return get_be32_signed(p); }
V upx_int64_t get64_signed(const void *p) C { return get_be64_signed(p); }
S u16_compare(const void *a, const void *b) C
{ return be16_compare(a, b); }
S u24_compare(const void *a, const void *b) C
{ return be24_compare(a, b); }
S u32_compare(const void *a, const void *b) C
{ return be32_compare(a, b); }
S u64_compare(const void *a, const void *b) C
{ return be64_compare(a, b); }
S u16_compare(const void *a, const void *b) C { return be16_compare(a, b); }
S u24_compare(const void *a, const void *b) C { return be24_compare(a, b); }
S u32_compare(const void *a, const void *b) C { return be32_compare(a, b); }
S u64_compare(const void *a, const void *b) C { return be64_compare(a, b); }
S u16_compare_signed(const void *a, const void *b) C
{ return be16_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C
{ return be24_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C
{ return be32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C
{ return be64_compare_signed(a, b); }
S u16_compare_signed(const void *a, const void *b) C { return be16_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C { return be24_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C { return be32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C { return be64_compare_signed(a, b); }
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
@@ -165,13 +140,12 @@ struct BEPolicy
ACC_CXX_DISABLE_NEW_DELETE
};
struct LEPolicy
#if defined(BELE_RTP)
: public AbstractPolicy
#endif
{
inline LEPolicy() { }
inline LEPolicy() {}
#if defined(BELE_CTP)
typedef N_BELE_RTP::LEPolicy RTP_Policy;
#elif defined(BELE_RTP)
@@ -184,50 +158,30 @@ struct LEPolicy
typedef LE32 U32;
typedef LE64 U64;
V unsigned get16(const void *p) C
{ return get_le16(p); }
V unsigned get24(const void *p) C
{ return get_le24(p); }
V unsigned get32(const void *p) C
{ return get_le32(p); }
V upx_uint64_t get64(const void *p) C
{ return get_le64(p); }
V unsigned get16(const void *p) C { return get_le16(p); }
V unsigned get24(const void *p) C { return get_le24(p); }
V unsigned get32(const void *p) C { return get_le32(p); }
V upx_uint64_t get64(const void *p) C { return get_le64(p); }
V void set16(void *p, unsigned v) C
{ set_le16(p, v); }
V void set24(void *p, unsigned v) C
{ set_le24(p, v); }
V void set32(void *p, unsigned v) C
{ set_le32(p, v); }
V void set64(void *p, upx_uint64_t v) C
{ set_le64(p, v); }
V void set16(void *p, unsigned v) C { set_le16(p, v); }
V void set24(void *p, unsigned v) C { set_le24(p, v); }
V void set32(void *p, unsigned v) C { set_le32(p, v); }
V void set64(void *p, upx_uint64_t v) C { set_le64(p, v); }
V int get16_signed(const void *p) C
{ return get_le16_signed(p); }
V int get24_signed(const void *p) C
{ return get_le24_signed(p); }
V int get32_signed(const void *p) C
{ return get_le32_signed(p); }
V upx_int64_t get64_signed(const void *p) C
{ return get_le64_signed(p); }
V int get16_signed(const void *p) C { return get_le16_signed(p); }
V int get24_signed(const void *p) C { return get_le24_signed(p); }
V int get32_signed(const void *p) C { return get_le32_signed(p); }
V upx_int64_t get64_signed(const void *p) C { return get_le64_signed(p); }
S u16_compare(const void *a, const void *b) C
{ return le16_compare(a, b); }
S u24_compare(const void *a, const void *b) C
{ return le24_compare(a, b); }
S u32_compare(const void *a, const void *b) C
{ return le32_compare(a, b); }
S u64_compare(const void *a, const void *b) C
{ return le64_compare(a, b); }
S u16_compare(const void *a, const void *b) C { return le16_compare(a, b); }
S u24_compare(const void *a, const void *b) C { return le24_compare(a, b); }
S u32_compare(const void *a, const void *b) C { return le32_compare(a, b); }
S u64_compare(const void *a, const void *b) C { return le64_compare(a, b); }
S u16_compare_signed(const void *a, const void *b) C
{ return le16_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C
{ return le24_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C
{ return le32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C
{ return le64_compare_signed(a, b); }
S u16_compare_signed(const void *a, const void *b) C { return le16_compare_signed(a, b); }
S u24_compare_signed(const void *a, const void *b) C { return le24_compare_signed(a, b); }
S u32_compare_signed(const void *a, const void *b) C { return le32_compare_signed(a, b); }
S u64_compare_signed(const void *a, const void *b) C { return le64_compare_signed(a, b); }
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
@@ -242,20 +196,17 @@ struct LEPolicy
ACC_CXX_DISABLE_NEW_DELETE
};
// native policy (aka host policy)
#if (ACC_ABI_BIG_ENDIAN)
typedef BEPolicy HostPolicy;
#elif (ACC_ABI_LITTLE_ENDIAN)
typedef LEPolicy HostPolicy;
#else
# error "ACC_ABI_ENDIAN"
#error "ACC_ABI_ENDIAN"
#endif
#if 0 /* UNUSED */
struct HostAlignedPolicy
{
struct HostAlignedPolicy {
#if defined(BELE_CTP)
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
#endif
@@ -272,7 +223,6 @@ struct HostAlignedPolicy
};
#endif
#undef V
#undef S
#undef C

View File

@@ -269,6 +269,8 @@ typedef size_t upx_rsize_t;
//
**************************************************************************/
#define CLANG_FORMAT_DUMMY_STATEMENT /*empty*/
#if !defined(__has_builtin)
# define __has_builtin(x) 0
#endif

View File

@@ -25,19 +25,18 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#include "conf.h"
/*************************************************************************
//
**************************************************************************/
unsigned long Throwable::counter = 0;
Throwable::Throwable(const char *m, int e, bool w) noexcept
: super(), msg(nullptr), err(e), is_warning(w)
{
Throwable::Throwable(const char *m, int e, bool w) noexcept : super(),
msg(nullptr),
err(e),
is_warning(w) {
if (m)
msg = strdup(m);
#if 0
@@ -46,10 +45,10 @@ Throwable::Throwable(const char *m, int e, bool w) noexcept
#endif
}
Throwable::Throwable(const Throwable &other) noexcept
: super(other), msg(nullptr), err(other.err), is_warning(other.is_warning)
{
Throwable::Throwable(const Throwable &other) noexcept : super(other),
msg(nullptr),
err(other.err),
is_warning(other.is_warning) {
if (other.msg)
msg = strdup(other.msg);
#if 0
@@ -58,9 +57,7 @@ Throwable::Throwable(const Throwable &other) noexcept
#endif
}
Throwable::~Throwable() noexcept
{
Throwable::~Throwable() noexcept {
#if 0
counter--;
fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
@@ -69,13 +66,11 @@ Throwable::~Throwable() noexcept
free(msg);
}
/*************************************************************************
// compression
**************************************************************************/
void throwCantPack(const char *msg)
{
void throwCantPack(const char *msg) {
// UGLY, but makes things easier
if (opt->cmd == CMD_COMPRESS)
throw CantPackException(msg);
@@ -85,119 +80,78 @@ void throwCantPack(const char *msg)
throw CantUnpackException(msg);
}
void throwCantPackExact()
{
throwCantPack("option '--exact' does not work with this file");
}
void throwCantPackExact() { throwCantPack("option '--exact' does not work with this file"); }
void throwFilterException()
{
throwCantPack("filter problem");
}
void throwFilterException() { throwCantPack("filter problem"); }
void throwUnknownExecutableFormat(const char *msg, bool warn)
{
void throwUnknownExecutableFormat(const char *msg, bool warn) {
throw UnknownExecutableFormatException(msg, warn);
}
void throwNotCompressible(const char *msg)
{
throw NotCompressibleException(msg);
}
void throwNotCompressible(const char *msg) { throw NotCompressibleException(msg); }
void throwAlreadyPacked(const char *msg)
{
throw AlreadyPackedException(msg);
}
void throwAlreadyPacked(const char *msg) { throw AlreadyPackedException(msg); }
void throwAlreadyPackedByUPX(const char *msg)
{
void throwAlreadyPackedByUPX(const char *msg) {
if (msg == nullptr)
msg = "already packed by UPX";
throwAlreadyPacked(msg);
}
/*************************************************************************
// decompression
**************************************************************************/
void throwCantUnpack(const char *msg)
{
void throwCantUnpack(const char *msg) {
// UGLY, but makes things easier
throwCantPack(msg);
}
void throwNotPacked(const char *msg)
{
void throwNotPacked(const char *msg) {
if (msg == nullptr)
msg = "not packed by UPX";
throw NotPackedException(msg);
}
void throwChecksumError()
{
throw Exception("checksum error");
}
void throwCompressedDataViolation()
{
throw Exception("compressed data violation");
}
void throwChecksumError() { throw Exception("checksum error"); }
void throwCompressedDataViolation() { throw Exception("compressed data violation"); }
/*************************************************************************
// other
**************************************************************************/
void throwInternalError(const char *msg)
{
throw InternalError(msg);
}
void throwInternalError(const char *msg) { throw InternalError(msg); }
void throwBadLoader()
{
throwInternalError("bad loader");
}
void throwBadLoader() { throwInternalError("bad loader"); }
void throwOutOfMemoryException(const char *msg)
{
void throwOutOfMemoryException(const char *msg) {
if (msg == nullptr)
msg = "out of memory";
throw OutOfMemoryException(msg);
}
void throwIOException(const char *msg, int e) { throw IOException(msg, e); }
void throwIOException(const char *msg, int e)
{
throw IOException(msg, e);
}
void throwEOFException(const char *msg, int e)
{
void throwEOFException(const char *msg, int e) {
if (msg == nullptr && e == 0)
msg = "premature end of file";
throw EOFException(msg, e);
}
/*************************************************************************
//
**************************************************************************/
const char *prettyName(const char *n) noexcept
{
const char *prettyName(const char *n) noexcept {
if (n == nullptr)
return "(null)";
while (*n)
{
if (*n >= '0' && *n <= '9') // Linux ABI
while (*n) {
if (*n >= '0' && *n <= '9') // Linux ABI
n++;
else if (*n == ' ')
n++;
else if (strncmp(n, "class ", 6) == 0) // Visual C++
else if (strncmp(n, "class ", 6) == 0) // Visual C++
n += 6;
else
break;

View File

@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef __UPX_EXCEPT_H
#define __UPX_EXCEPT_H 1
@@ -33,167 +32,159 @@
const char *prettyName(const char *n) noexcept;
/*************************************************************************
// exceptions
**************************************************************************/
class Throwable : public std::exception
{
class Throwable : public std::exception {
typedef std::exception super;
protected:
Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
public:
Throwable(const Throwable &) noexcept;
virtual ~Throwable() noexcept;
const char *getMsg() const noexcept { return msg; }
int getErrno() const noexcept { return err; }
bool isWarning() const noexcept { return is_warning; }
private:
char *msg;
int err;
protected:
bool is_warning; // can be set by subclasses
bool is_warning; // can be set by subclasses
private:
// disable assignment
Throwable& operator= (const Throwable &);
Throwable &operator=(const Throwable &);
// disable dynamic allocation
ACC_CXX_DISABLE_NEW_DELETE
private:
static unsigned long counter; // for debugging
static unsigned long counter; // for debugging
};
// Exceptions can/should be caught
class Exception : public Throwable
{
class Exception : public Throwable {
typedef Throwable super;
public:
Exception(const char *m = nullptr, int e = 0, bool w = false) noexcept : super(m,e,w) { }
};
public:
Exception(const char *m = nullptr, int e = 0, bool w = false) noexcept : super(m, e, w) {}
};
// Errors should not be caught (or re-thrown)
class Error : public Throwable
{
class Error : public Throwable {
typedef Throwable super;
public:
Error(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
};
public:
Error(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
/*************************************************************************
// system exception
**************************************************************************/
class OutOfMemoryException : public Exception
{
class OutOfMemoryException : public Exception {
typedef Exception super;
public:
OutOfMemoryException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
OutOfMemoryException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
class IOException : public Exception
{
class IOException : public Exception {
typedef Exception super;
public:
IOException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
IOException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
class EOFException : public IOException
{
class EOFException : public IOException {
typedef IOException super;
public:
EOFException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
EOFException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
class FileNotFoundException : public IOException
{
class FileNotFoundException : public IOException {
typedef IOException super;
public:
FileNotFoundException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
FileNotFoundException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
class FileAlreadyExistsException : public IOException
{
class FileAlreadyExistsException : public IOException {
typedef IOException super;
public:
FileAlreadyExistsException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
};
public:
FileAlreadyExistsException(const char *m = nullptr, int e = 0) noexcept : super(m, e) {}
};
/*************************************************************************
// application exceptions
**************************************************************************/
class OverlayException : public Exception
{
class OverlayException : public Exception {
typedef Exception super;
public:
OverlayException(const char *m = nullptr, bool w = false) noexcept : super(m,0,w) { }
OverlayException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
};
class CantPackException : public Exception
{
class CantPackException : public Exception {
typedef Exception super;
public:
CantPackException(const char *m = nullptr, bool w = false) noexcept : super(m,0,w) { }
CantPackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
};
class UnknownExecutableFormatException : public CantPackException
{
class UnknownExecutableFormatException : public CantPackException {
typedef CantPackException super;
public:
UnknownExecutableFormatException(const char *m = nullptr, bool w = false) noexcept : super(m,w) { }
UnknownExecutableFormatException(const char *m = nullptr, bool w = false) noexcept
: super(m, w) {}
};
class AlreadyPackedException : public CantPackException
{
class AlreadyPackedException : public CantPackException {
typedef CantPackException super;
public:
AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
};
class NotCompressibleException : public CantPackException
{
class NotCompressibleException : public CantPackException {
typedef CantPackException super;
public:
NotCompressibleException(const char *m = nullptr) noexcept : super(m) { }
NotCompressibleException(const char *m = nullptr) noexcept : super(m) {}
};
class CantUnpackException : public Exception
{
class CantUnpackException : public Exception {
typedef Exception super;
public:
CantUnpackException(const char *m = nullptr, bool w = false) noexcept : super(m,0,w) { }
CantUnpackException(const char *m = nullptr, bool w = false) noexcept : super(m, 0, w) {}
};
class NotPackedException : public CantUnpackException
{
class NotPackedException : public CantUnpackException {
typedef CantUnpackException super;
public:
NotPackedException(const char *m = nullptr) noexcept : super(m,true) { }
};
public:
NotPackedException(const char *m = nullptr) noexcept : super(m, true) {}
};
/*************************************************************************
// errors
**************************************************************************/
class InternalError : public Error
{
class InternalError : public Error {
typedef Error super;
public:
InternalError(const char *m = nullptr) noexcept : super(m,0) { }
};
public:
InternalError(const char *m = nullptr) noexcept : super(m, 0) {}
};
/*************************************************************************
// util
@@ -225,7 +216,6 @@ void throwEOFException(const char *msg = nullptr, int e = 0) NORET;
#undef NORET
#endif /* __cplusplus */
#endif /* already included */

File diff suppressed because it is too large Load Diff

View File

@@ -25,11 +25,9 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef __UPX_OPTIONS_H
#define __UPX_OPTIONS_H 1
/*************************************************************************
// globals
**************************************************************************/
@@ -37,11 +35,16 @@
// options - command
enum {
CMD_NONE,
CMD_COMPRESS, CMD_DECOMPRESS, CMD_TEST, CMD_LIST, CMD_FILEINFO,
CMD_HELP, CMD_LICENSE, CMD_VERSION
CMD_COMPRESS,
CMD_DECOMPRESS,
CMD_TEST,
CMD_LIST,
CMD_FILEINFO,
CMD_HELP,
CMD_LICENSE,
CMD_VERSION
};
struct options_t {
int cmd;
@@ -56,15 +59,15 @@ struct options_t {
bool method_nrv2b_seen;
bool method_nrv2d_seen;
bool method_nrv2e_seen;
int level; // compression level 1..10
int filter; // preferred filter from Packer::getFilters()
int level; // compression level 1..10
int filter; // preferred filter from Packer::getFilters()
bool ultra_brute;
bool all_methods; // try all available compression methods ?
bool all_methods; // try all available compression methods ?
bool all_methods_use_lzma;
bool all_filters; // try all available filters ?
bool no_filter; // force no filter
bool prefer_ucl; // prefer UCL
bool exact; // user requires byte-identical decompression
bool all_filters; // try all available filters ?
bool no_filter; // force no filter
bool prefer_ucl; // prefer UCL
bool exact; // user requires byte-identical decompression
// other options
int backup;
@@ -85,38 +88,38 @@ struct options_t {
// debug options
struct {
int debug_level;
bool disable_random_id; // for Packer::getRandomId()
bool disable_random_id; // for Packer::getRandomId()
const char *dump_stub_loader;
char fake_stub_version[4+1]; // for internal debugging
char fake_stub_year[4+1]; // for internal debugging
char fake_stub_version[4 + 1]; // for internal debugging
char fake_stub_year[4 + 1]; // for internal debugging
} debug;
// overlay handling
enum {
SKIP_OVERLAY = 0,
COPY_OVERLAY = 1,
STRIP_OVERLAY = 2
};
enum { SKIP_OVERLAY = 0, COPY_OVERLAY = 1, STRIP_OVERLAY = 2 };
int overlay;
// compression runtime parameters - see struct XXX_compress_config_t
struct crp_t {
lzma_compress_config_t crp_lzma;
ucl_compress_config_t crp_ucl;
zlib_compress_config_t crp_zlib;
void reset() { crp_lzma.reset(); crp_ucl.reset(); crp_zlib.reset(); }
lzma_compress_config_t crp_lzma;
ucl_compress_config_t crp_ucl;
zlib_compress_config_t crp_zlib;
void reset() {
crp_lzma.reset();
crp_ucl.reset();
crp_zlib.reset();
}
};
crp_t crp;
// CPU
enum {
CPU_DEFAULT = 0,
CPU_8086 = 1,
CPU_286 = 2,
CPU_386 = 3,
CPU_486 = 4,
CPU_586 = 5,
CPU_686 = 6
CPU_8086 = 1,
CPU_286 = 2,
CPU_386 = 3,
CPU_486 = 4,
CPU_586 = 5,
CPU_686 = 6
};
int cpu;
@@ -139,15 +142,15 @@ struct options_t {
} ps1_exe;
struct {
unsigned blocksize;
bool force_execve; // force the linux/386 execve format
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
bool use_ptinterp; // use PT_INTERP /opt/upx/run
bool make_ptinterp; // make PT_INTERP [ignore current file!]
bool unmap_all_pages; // thus /proc/self/exe vanishes
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
bool preserve_build_id; // copy the build-id to the compressed binary
bool android_shlib; // keep some ElfXX_Shdr for dlopen()
bool force_pie; // choose DF_1_PIE instead of is_shlib
bool force_execve; // force the linux/386 execve format
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
bool use_ptinterp; // use PT_INTERP /opt/upx/run
bool make_ptinterp; // make PT_INTERP [ignore current file!]
bool unmap_all_pages; // thus /proc/self/exe vanishes
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
bool preserve_build_id; // copy the build-id to the compressed binary
bool android_shlib; // keep some ElfXX_Shdr for dlopen()
bool force_pie; // choose DF_1_PIE instead of is_shlib
} o_unix;
struct {
bool le;
@@ -156,7 +159,7 @@ struct options_t {
int compress_exports;
int compress_icons;
int compress_resources;
signed char compress_rt[25]; // 25 == RT_LAST
signed char compress_rt[25]; // 25 == RT_LAST
int strip_relocs;
const char *keep_resource;
} win32_pe;
@@ -166,7 +169,6 @@ struct options_t {
extern struct options_t *opt;
#endif /* already included */
/* vim:set ts=4 sw=4 et: */

View File

@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#include "conf.h"
#include "file.h"
@@ -34,75 +33,55 @@
#include "p_tos.h"
#include "linker.h"
static const
static const CLANG_FORMAT_DUMMY_STATEMENT
#include "stub/m68k-atari.tos.h"
//#define TESTING 1
/*************************************************************************
//
**************************************************************************/
#define FH_SIZE sizeof(tos_header_t)
#define FH_SIZE sizeof(tos_header_t)
PackTos::PackTos(InputFile *f) :
super(f)
{
PackTos::PackTos(InputFile *f) : super(f) {
bele = &N_BELE_RTP::be_policy;
COMPILE_TIME_ASSERT(FH_SIZE == 28);
COMPILE_TIME_ASSERT_ALIGNED1(tos_header_t)
}
const int *PackTos::getCompressionMethods(int method, int level) const
{
bool small = ih.fh_text + ih.fh_data <= 256*1024;
const int *PackTos::getCompressionMethods(int method, int level) const {
bool small = ih.fh_text + ih.fh_data <= 256 * 1024;
return Packer::getDefaultCompressionMethods_8(method, level, small);
}
const int *PackTos::getFilters() const { return nullptr; }
const int *PackTos::getFilters() const
{
return nullptr;
}
Linker *PackTos::newLinker() const { return new ElfLinkerM68k; }
Linker* PackTos::newLinker() const
{
return new ElfLinkerM68k;
}
void PackTos::LinkerSymbols::LoopInfo::init(unsigned count_, bool allow_dbra)
{
void PackTos::LinkerSymbols::LoopInfo::init(unsigned count_, bool allow_dbra) {
count = value = count_;
if (count == 0)
mode = LOOP_NONE;
else if (count <= 65536 && allow_dbra)
{
else if (count <= 65536 && allow_dbra) {
mode = LOOP_DBRA;
value -= 1;
value &= 0xffff;
}
else if (count <= 65536)
{
} else if (count <= 65536) {
mode = LOOP_SUBQ_W;
value &= 0xffff;
}
else
} else
mode = LOOP_SUBQ_L;
}
unsigned PackTos::getDecomprOffset(int method, int small) const
{
unsigned PackTos::getDecomprOffset(int method, int small) const {
UNUSED(small);
if (M_IS_NRV2B(method))
return 2; // FIXME: do not hardcode this value
return 2; // FIXME: do not hardcode this value
else if (M_IS_NRV2D(method))
return 2; // FIXME: do not hardcode this value
return 2; // FIXME: do not hardcode this value
else if (M_IS_NRV2E(method))
return 2; // FIXME: do not hardcode this value
return 2; // FIXME: do not hardcode this value
else if (M_IS_LZMA(method))
return linker->getSectionSize("__mulsi3");
else
@@ -110,13 +89,11 @@ unsigned PackTos::getDecomprOffset(int method, int small) const
return 0;
}
void PackTos::buildLoader(const Filter *ft)
{
void PackTos::buildLoader(const Filter *ft) {
assert(ft->id == 0);
initLoader(stub_m68k_atari_tos, sizeof(stub_m68k_atari_tos));
//linker->dumpSymbols();
// linker->dumpSymbols();
//
// part 1a
@@ -132,8 +109,7 @@ void PackTos::buildLoader(const Filter *ft)
addLoader("set_up21_d4.l");
assert(symbols.loop1.count || symbols.loop2.count);
if (symbols.loop1.count)
{
if (symbols.loop1.count) {
if (symbols.loop1.value <= 127)
addLoader("loop1_set_count.b");
else if (symbols.loop1.value <= 65535)
@@ -151,8 +127,7 @@ void PackTos::buildLoader(const Filter *ft)
else
throwBadLoader();
}
if (symbols.loop2.count)
{
if (symbols.loop2.count) {
assert(symbols.loop2.mode == symbols.LOOP_DBRA);
addLoader(opt->small ? "loop2.small" : "loop2.fast");
}
@@ -222,8 +197,7 @@ void PackTos::buildLoader(const Filter *ft)
addLoader("__mulsi3");
addLoader(opt->small ? "lzma.small" : "lzma.fast");
addLoader("lzma.finish");
}
else
} else
throwBadLoader();
if (symbols.need_reloc)
@@ -240,41 +214,40 @@ void PackTos::buildLoader(const Filter *ft)
addLoader("jmp_stack");
}
/*************************************************************************
//
**************************************************************************/
/* flags for curproc->memflags */
/* also used for program headers fh_flag */
#define F_FASTLOAD 0x01 // don't zero heap
#define F_ALTLOAD 0x02 // OK to load in alternate ram
#define F_ALTALLOC 0x04 // OK to malloc from alt. ram
#define F_SMALLTPA 0x08 // used in MagiC: TPA can be allocated
// as specified in the program header
// rather than the biggest free memory
// block
#define F_MEMFLAGS 0xf0 // reserved for future use
#define F_SHTEXT 0x800 // program's text may be shared
#define F_FASTLOAD 0x01 // don't zero heap
#define F_ALTLOAD 0x02 // OK to load in alternate ram
#define F_ALTALLOC 0x04 // OK to malloc from alt. ram
#define F_SMALLTPA \
0x08 // used in MagiC: TPA can be allocated
// as specified in the program header
// rather than the biggest free memory
// block
#define F_MEMFLAGS 0xf0 // reserved for future use
#define F_SHTEXT 0x800 // program's text may be shared
#define F_MINALT 0xf0000000 // used to decide which type of RAM to load in
#define F_MINALT 0xf0000000 // used to decide which type of RAM to load in
#define F_ALLOCZERO 0x2000 // zero mem, for bugged (GEM...) programs
#define F_ALLOCZERO 0x2000 // zero mem, for bugged (GEM...) programs
/* Bit in Mxalloc's arg for "don't auto-free this memory" */
#define F_KEEP 0x4000
#define F_KEEP 0x4000
#define F_OS_SPECIAL 0x8000 // mark as a special process
#define F_OS_SPECIAL 0x8000 // mark as a special process
/* flags for curproc->memflags (that is, fh_flag) and also Mxalloc mode. */
/* (Actually, when users call Mxalloc, they add 0x10 to what you see here) */
#define F_PROTMODE 0xf0 // protection mode bits
#define F_PROT_P 0x00 // no read or write
#define F_PROT_G 0x10 // any access OK
#define F_PROT_S 0x20 // any super access OK
#define F_PROT_PR 0x30 // any read OK, no write
#define F_PROT_I 0x40 // invalid page
#define F_PROTMODE 0xf0 // protection mode bits
#define F_PROT_P 0x00 // no read or write
#define F_PROT_G 0x10 // any access OK
#define F_PROT_S 0x20 // any super access OK
#define F_PROT_PR 0x30 // any read OK, no write
#define F_PROT_I 0x40 // invalid page
/*************************************************************************
// util
@@ -282,9 +255,8 @@ void PackTos::buildLoader(const Filter *ft)
// checkFileHeader() checks ih for legal but unsupported values
**************************************************************************/
int PackTos::readFileHeader()
{
fi->seek(0,SEEK_SET);
int PackTos::readFileHeader() {
fi->seek(0, SEEK_SET);
fi->readx(&ih, FH_SIZE);
if (ih.fh_magic != 0x601a)
return 0;
@@ -293,31 +265,27 @@ int PackTos::readFileHeader()
return UPX_F_ATARI_TOS;
}
bool PackTos::checkFileHeader()
{
bool PackTos::checkFileHeader() {
const unsigned f = ih.fh_flag;
//printf("flags: 0x%x, text: %d, data: %d, bss: %d, sym: %d\n", f, (int)ih.fh_text, (int)ih.fh_data, (int)ih.fh_bss, (int)ih.fh_sym);
// printf("flags: 0x%x, text: %d, data: %d, bss: %d, sym: %d\n", f, (int) ih.fh_text,
// (int) ih.fh_data, (int) ih.fh_bss, (int) ih.fh_sym);
if ((ih.fh_text & 1) || (ih.fh_data & 1))
throwCantPack("odd size values in text/data");
if (f & F_OS_SPECIAL)
throwCantPack("I won't pack F_OS_SPECIAL programs");
if ((f & F_PROTMODE) > F_PROT_I)
throwCantPack("invalid protection mode");
if ((f & F_PROTMODE) != F_PROT_P)
{
if ((f & F_PROTMODE) != F_PROT_P) {
if (opt->force < 1)
throwCantPack("no private memory protection; use option '-f' to force packing");
}
if (f & F_SHTEXT)
{
if (f & F_SHTEXT) {
if (opt->force < 1)
throwCantPack("shared text segment; use option '-f' to force packing");
}
#if 0
// fh_reserved seems to be unused
if (ih.fh_reserved != 0)
{
if (ih.fh_reserved != 0) {
if (opt->force < 1)
throwCantPack("reserved header field set; use option '-f' to force packing");
}
@@ -325,15 +293,13 @@ bool PackTos::checkFileHeader()
return true;
}
/*************************************************************************
// relocs
**************************************************************************/
// Check relocation for errors to make sure our loader can handle it.
static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
unsigned *nrelocs, unsigned *relocsize, unsigned *overlay)
{
static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize, unsigned *nrelocs,
unsigned *relocsize, unsigned *overlay) {
unsigned fixup = get_be32(relocs);
unsigned last_fixup = fixup;
unsigned i = 4;
@@ -342,25 +308,24 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
assert(fixup > 0);
*nrelocs = 1;
for (;;)
{
if (fixup & 1) // must be word-aligned
for (;;) {
if (fixup & 1) // must be word-aligned
return -1;
if (fixup + 4 > isize) // too far
if (fixup + 4 > isize) // too far
return -1;
if (i >= rsize) // premature EOF in relocs
if (i >= rsize) // premature EOF in relocs
return -1;
unsigned c = relocs[i++];
if (c == 0) // end marker
if (c == 0) // end marker
break;
else if (c == 1) // increase fixup, no reloc
else if (c == 1) // increase fixup, no reloc
fixup += 254;
else if (c & 1) // must be word-aligned
else if (c & 1) // must be word-aligned
return -1;
else // next reloc is here
else // next reloc is here
{
fixup += c;
if (fixup - last_fixup < 4) // overlapping relocation
if (fixup - last_fixup < 4) // overlapping relocation
return -1;
last_fixup = fixup;
*nrelocs += 1;
@@ -372,13 +337,11 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
return 0;
}
/*************************************************************************
//
**************************************************************************/
bool PackTos::canPack()
{
bool PackTos::canPack() {
if (!readFileHeader())
return false;
@@ -394,22 +357,18 @@ bool PackTos::canPack()
return true;
}
void PackTos::fileInfo()
{
void PackTos::fileInfo() {
if (!readFileHeader())
return;
con_fprintf(stdout, " text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
(int)ih.fh_text, (int)ih.fh_data, (int)ih.fh_sym, (int)ih.fh_bss, (int)ih.fh_flag);
con_fprintf(stdout, " text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n", (int) ih.fh_text,
(int) ih.fh_data, (int) ih.fh_sym, (int) ih.fh_bss, (int) ih.fh_flag);
}
/*************************************************************************
//
**************************************************************************/
void PackTos::pack(OutputFile *fo)
{
void PackTos::pack(OutputFile *fo) {
unsigned t;
unsigned nrelocs = 0;
unsigned relocsize = 0;
@@ -437,14 +396,14 @@ void PackTos::pack(OutputFile *fo)
fi->seek(FH_SIZE, SEEK_SET);
// read text + data
t = i_text + i_data;
fi->readx(ibuf,t);
fi->readx(ibuf, t);
// skip symbols
if (i_sym && opt->exact)
throwCantPackExact();
fi->seek(i_sym,SEEK_CUR);
fi->seek(i_sym, SEEK_CUR);
// read relocations + overlay
overlay = file_size - (FH_SIZE + i_text + i_data + i_sym);
fi->readx(ibuf+t,overlay);
fi->readx(ibuf + t, overlay);
#if 0 || (TESTING)
printf("text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
@@ -454,23 +413,19 @@ void PackTos::pack(OutputFile *fo)
// Check relocs (see load_and_reloc() in freemint/sys/memory.c).
// Must work around TOS bugs and lots of broken programs.
if (overlay < 4)
{
if (overlay < 4) {
// Bug workaround: Whatever this is, silently keep it in
// the (unused) relocations for byte-identical unpacking.
relocsize = overlay;
overlay = 0;
}
else if (get_be32(ibuf+t) == 0)
{
} else if (get_be32(ibuf + t) == 0) {
// Bug workaround - check the empty fixup before testing fh_reloc.
relocsize = 4;
overlay -= 4;
}
else if (ih.fh_reloc != 0)
} else if (ih.fh_reloc != 0)
relocsize = 0;
else {
int r = check_relocs(ibuf+t, overlay, t, &nrelocs, &relocsize, &overlay);
int r = check_relocs(ibuf + t, overlay, t, &nrelocs, &relocsize, &overlay);
if (r != 0)
throwCantPack("bad relocation table");
symbols.need_reloc = true;
@@ -484,8 +439,8 @@ void PackTos::pack(OutputFile *fo)
// Append original fileheader.
t += relocsize;
ih.fh_sym = 0; // we stripped all symbols
memcpy(ibuf+t, &ih, FH_SIZE);
ih.fh_sym = 0; // we stripped all symbols
memcpy(ibuf + t, &ih, FH_SIZE);
t += FH_SIZE;
#if 0 || (TESTING)
printf("xx3 reloc: %d, overlay: %d, t: %d\n", relocsize, overlay, t);
@@ -505,7 +460,8 @@ void PackTos::pack(OutputFile *fo)
// prepare filter
Filter ft(ph.level);
// compress (max_match = 65535)
upx_compress_config_t cconf; cconf.reset();
upx_compress_config_t cconf;
cconf.reset();
cconf.conf_ucl.max_match = 65535;
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 512, &cconf);
@@ -522,8 +478,7 @@ void PackTos::pack(OutputFile *fo)
unsigned o_text, o_data, o_bss;
unsigned e_len, d_len, d_off;
for (;;)
{
for (;;) {
// The decompressed data will now get placed at this offset:
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
@@ -539,8 +494,7 @@ void PackTos::pack(OutputFile *fo)
o_bss = i_bss;
// word align len of compressed data
while (o_data & 1)
{
while (o_data & 1) {
obuf[o_data++] = 0;
offset++;
}
@@ -551,8 +505,7 @@ void PackTos::pack(OutputFile *fo)
o_data += d_len;
// dword align the len of the final data segment
while (o_data & 3)
{
while (o_data & 3) {
obuf[o_data++] = 0;
offset++;
}
@@ -566,7 +519,7 @@ void PackTos::pack(OutputFile *fo)
// dirty bss
unsigned dirty_bss = (o_data + offset) - (i_text + i_data);
//printf("real dirty_bss: %d\n", dirty_bss);
// printf("real dirty_bss: %d\n", dirty_bss);
// dword align (or 16 - for speedup when clearing the dirty bss)
const unsigned dirty_bss_align = opt->small ? 4 : 16;
while (dirty_bss & (dirty_bss_align - 1))
@@ -581,13 +534,10 @@ void PackTos::pack(OutputFile *fo)
o_bss++;
// update symbols for buildLoader()
if (opt->small)
{
if (opt->small) {
symbols.loop1.init(o_data / 4);
symbols.loop2.init(0);
}
else
{
} else {
symbols.loop1.init(o_data / 160);
symbols.loop2.init((o_data % 160) / 4);
}
@@ -597,8 +547,8 @@ void PackTos::pack(OutputFile *fo)
symbols.up31_base_d4 = d_off + offset;
symbols.up21_a6 = symbols.up21_d4 - (i_text + i_data);
symbols.up31_base_a6 = symbols.up31_base_d4 - (i_text + i_data);
assert((int)symbols.up21_a6 > 0);
assert((int)symbols.up31_base_a6 > 0);
assert((int) symbols.up21_a6 > 0);
assert((int) symbols.up31_base_a6 > 0);
const unsigned c = linker->getSymbolOffset("code_on_stack");
unsigned d;
@@ -612,7 +562,7 @@ void PackTos::pack(OutputFile *fo)
// now re-build loader
buildLoader(&ft);
unsigned new_lsize = getLoaderSize();
//printf("buildLoader %d %d\n", new_lsize, initial_lsize);
// printf("buildLoader %d %d\n", new_lsize, initial_lsize);
assert(new_lsize <= initial_lsize);
if (new_lsize == last_lsize && memcmp(getLoader(), last_loader, last_lsize) == 0)
break;
@@ -667,13 +617,10 @@ void PackTos::pack(OutputFile *fo)
// set new file_hdr
memcpy(&oh, &ih, FH_SIZE);
if (opt->atari_tos.split_segments)
{
if (opt->atari_tos.split_segments) {
oh.fh_text = o_text;
oh.fh_data = o_data;
}
else
{
} else {
// put everything into the text segment
oh.fh_text = o_text + o_data;
oh.fh_data = 0;
@@ -701,11 +648,11 @@ void PackTos::pack(OutputFile *fo)
// write new file header, loader and compressed file
fo->write(&oh, FH_SIZE);
fo->write(loader, o_text); // entry
fo->write(loader, o_text); // entry
if (opt->debug.dump_stub_loader)
OutputFile::dump(opt->debug.dump_stub_loader, loader, o_text);
memcpy(obuf + d_off, getLoader() + e_len, d_len); // copy decompressor
fo->write(obuf, o_data); // compressed + decompressor
fo->write(obuf, o_data); // compressed + decompressor
// write empty relocation fixup
fo->write("\x00\x00\x00\x00", 4);
@@ -721,20 +668,18 @@ void PackTos::pack(OutputFile *fo)
throwNotCompressible();
}
/*************************************************************************
//
**************************************************************************/
int PackTos::canUnpack()
{
int PackTos::canUnpack() {
if (!readFileHeader())
return false;
if (!readPackHeader(768))
return false;
// check header as set by packer
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0
|| ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1)
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0 || ih.fh_sym != 0 ||
ih.fh_reserved != 0 || ih.fh_reloc > 1)
throwCantUnpack("program header damaged");
// generic check
if (!checkFileHeader())
@@ -742,13 +687,11 @@ int PackTos::canUnpack()
return true;
}
/*************************************************************************
//
**************************************************************************/
void PackTos::unpack(OutputFile *fo)
{
void PackTos::unpack(OutputFile *fo) {
ibuf.alloc(ph.c_len);
obuf.allocForUncompression(ph.u_len);
@@ -756,18 +699,17 @@ void PackTos::unpack(OutputFile *fo)
fi->readx(ibuf, ph.c_len);
// decompress
decompress(ibuf,obuf);
decompress(ibuf, obuf);
// write original header & decompressed file
if (fo)
{
if (fo) {
unsigned overlay = file_size - (FH_SIZE + ih.fh_text + ih.fh_data);
if (ih.fh_reloc == 0 && overlay >= 4)
overlay -= 4; // this is our empty fixup
overlay -= 4; // this is our empty fixup
checkOverlay(overlay);
fo->write(obuf+ph.u_len-FH_SIZE, FH_SIZE); // orig. file_hdr
fo->write(obuf, ph.u_len-FH_SIZE); // orig. text+data+relocs
fo->write(obuf + ph.u_len - FH_SIZE, FH_SIZE); // orig. file_hdr
fo->write(obuf, ph.u_len - FH_SIZE); // orig. text+data+relocs
// copy any overlay
copyOverlay(fo, overlay, &obuf);

View File

@@ -25,18 +25,16 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef __UPX_P_TOS_H
#define __UPX_P_TOS_H 1
/*************************************************************************
// atari/tos
**************************************************************************/
class PackTos : public Packer
{
class PackTos : public Packer {
typedef Packer super;
public:
PackTos(InputFile *f);
virtual int getVersion() const { return 13; }
@@ -55,14 +53,14 @@ public:
virtual void fileInfo();
protected:
virtual Linker* newLinker() const;
virtual Linker *newLinker() const;
virtual void buildLoader(const Filter *ft);
unsigned getDecomprOffset(int method, int small) const;
virtual int readFileHeader();
virtual bool checkFileHeader();
__packed_struct(tos_header_t)
struct alignas(1) tos_header_t {
BE16 fh_magic;
BE32 fh_text;
BE32 fh_data;
@@ -71,17 +69,18 @@ protected:
BE32 fh_reserved;
BE32 fh_flag;
BE16 fh_reloc;
__packed_struct_end()
};
tos_header_t ih, oh;
// symbols for buildLoader()
struct LinkerSymbols
{
struct LinkerSymbols {
enum { LOOP_NONE, LOOP_SUBQ_L, LOOP_SUBQ_W, LOOP_DBRA };
struct LoopInfo {
unsigned mode; unsigned count; unsigned value;
void init(unsigned count, bool allow_dbra=true);
unsigned mode;
unsigned count;
unsigned value;
void init(unsigned count, bool allow_dbra = true);
};
// buildLoader() input
bool need_reloc;
@@ -105,7 +104,6 @@ protected:
LinkerSymbols symbols;
};
#endif /* already included */
/* vim:set ts=4 sw=4 et: */

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef __UPX_PACKER_H
#define __UPX_PACKER_H 1
@@ -38,14 +37,12 @@ class PackMaster;
class UiPacker;
class Filter;
/*************************************************************************
//
**************************************************************************/
// see stub/src/include/header.S
class PackHeader
{
class PackHeader {
friend class Packer;
private:
@@ -60,11 +57,11 @@ public:
public:
// fields stored in compressed file
//enum { magic = UPX_MAGIC_LE32 };
// enum { magic = UPX_MAGIC_LE32 };
int version;
int format; // executable format
int method; // compresison method
int level; // compresison level 1..10
int format; // executable format
int method; // compresison method
int level; // compresison level 1..10
unsigned u_len;
unsigned c_len;
unsigned u_adler;
@@ -72,7 +69,7 @@ public:
off_t u_file_size;
int filter;
int filter_cto;
int n_mru; // FIXME: rename to filter_misc
int n_mru; // FIXME: rename to filter_misc
int header_checksum;
// support fields for verifying decompression
@@ -84,39 +81,38 @@ public:
// info fields set by Packer::compress()
upx_compress_result_t compress_result;
//unsigned min_offset_found;
// unsigned min_offset_found;
unsigned max_offset_found;
//unsigned min_match_found;
// unsigned min_match_found;
unsigned max_match_found;
//unsigned min_run_found;
// unsigned min_run_found;
unsigned max_run_found;
unsigned first_offset_found;
//unsigned same_match_offsets_found;
// unsigned same_match_offsets_found;
// info fields set by Packer::compressWithFilters()
unsigned overlap_overhead;
};
bool ph_skipVerify(const PackHeader &ph);
void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out,
bool verify_checksum, Filter *ft);
void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out, bool verify_checksum,
Filter *ft);
bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_bytep buf,
unsigned overlap_overhead);
/*************************************************************************
// abstract base class for packers
//
// FIXME: this class is way too fat and badly needs a decomposition
**************************************************************************/
class Packer
{
//friend class PackMaster;
class Packer {
// friend class PackMaster;
friend class UiPacker;
protected:
Packer(InputFile *f);
public:
virtual ~Packer();
virtual void assertPacker() const;
@@ -139,10 +135,8 @@ public:
void doFileInfo();
// unpacker capabilities
virtual bool canUnpackVersion(int version) const
{ return (version >= 8); }
virtual bool canUnpackFormat(int format) const
{ return (format == getFormat()); }
virtual bool canUnpackVersion(int version) const { return (version >= 8); }
virtual bool canUnpackFormat(int format) const { return (format == getFormat()); }
protected:
// unpacker tests - these may throw exceptions
@@ -171,72 +165,63 @@ protected:
// main compression drivers
virtual bool compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr,
const upx_compress_config_t *cconf = nullptr);
virtual void decompress(const upx_bytep in, upx_bytep out,
bool verify_checksum = true, Filter *ft = nullptr);
virtual void decompress(const upx_bytep in, upx_bytep out, bool verify_checksum = true,
Filter *ft = nullptr);
virtual bool checkDefaultCompressionRatio(unsigned u_len, unsigned c_len) const;
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
// high-level compression drivers
void compressWithFilters(Filter *ft,
const unsigned overlap_range,
const upx_compress_config_t *cconf,
int filter_strategy = 0,
void compressWithFilters(Filter *ft, const unsigned overlap_range,
const upx_compress_config_t *cconf, int filter_strategy = 0,
bool inhibit_compression_check = false);
void compressWithFilters(Filter *ft,
const unsigned overlap_range,
const upx_compress_config_t *cconf,
int filter_strategy,
unsigned filter_buf_off,
unsigned compress_ibuf_off,
unsigned compress_obuf_off,
const upx_bytep hdr_ptr, unsigned hdr_len,
void compressWithFilters(Filter *ft, const unsigned overlap_range,
const upx_compress_config_t *cconf, int filter_strategy,
unsigned filter_buf_off, unsigned compress_ibuf_off,
unsigned compress_obuf_off, const upx_bytep hdr_ptr, unsigned hdr_len,
bool inhibit_compression_check = false);
// real compression driver
void compressWithFilters(upx_bytep i_ptr, unsigned i_len,
upx_bytep o_ptr,
upx_bytep f_ptr, unsigned f_len,
const upx_bytep hdr_ptr, unsigned hdr_len,
Filter *ft,
const unsigned overlap_range,
const upx_compress_config_t *cconf,
int filter_strategy,
bool inhibit_compression_check = false);
void compressWithFilters(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr, upx_bytep f_ptr,
unsigned f_len, const upx_bytep hdr_ptr, unsigned hdr_len, Filter *ft,
const unsigned overlap_range, const upx_compress_config_t *cconf,
int filter_strategy, bool inhibit_compression_check = false);
// util for verifying overlapping decompresion
// non-destructive test
virtual bool testOverlappingDecompression(const upx_bytep buf,
const upx_bytep tbuf,
virtual bool testOverlappingDecompression(const upx_bytep buf, const upx_bytep tbuf,
unsigned overlap_overhead) const;
// non-destructive find
virtual unsigned findOverlapOverhead(const upx_bytep buf,
const upx_bytep tbuf,
unsigned range = 0,
unsigned upper_limit = ~0u) const;
virtual unsigned findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf,
unsigned range = 0, unsigned upper_limit = ~0u) const;
// destructive decompress + verify
void verifyOverlappingDecompression(Filter *ft = nullptr);
void verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Filter *ft = nullptr);
// packheader handling
virtual int patchPackHeader(void *b, int blen);
virtual bool getPackHeader(void *b, int blen, bool allow_incompressible=false);
virtual bool readPackHeader(int len, bool allow_incompressible=false);
virtual bool getPackHeader(void *b, int blen, bool allow_incompressible = false);
virtual bool readPackHeader(int len, bool allow_incompressible = false);
virtual void checkAlreadyPacked(const void *b, int blen);
// loader core
virtual void buildLoader(const Filter *ft) = 0;
virtual Linker* newLinker() const = 0;
virtual Linker *newLinker() const = 0;
virtual void relocateLoader();
// loader util for linker
virtual upx_byte *getLoader() const;
virtual int getLoaderSize() const;
virtual void initLoader(const void *pdata, int plen, int small=-1);
virtual void initLoader(const void *pdata, int plen, int small = -1);
#define C const char *
void addLoader(C); void addLoader(C,C); void addLoader(C,C,C);
void addLoader(C,C,C,C); void addLoader(C,C,C,C,C);
void addLoader(C,C,C,C,C,C); void addLoader(C,C,C,C,C,C,C);
void addLoader(C,C,C,C,C,C,C,C); void addLoader(C,C,C,C,C,C,C,C,C);
void addLoader(C,C,C,C,C,C,C,C,C,C);
void addLoader(C);
void addLoader(C, C);
void addLoader(C, C, C);
void addLoader(C, C, C, C);
void addLoader(C, C, C, C, C);
void addLoader(C, C, C, C, C, C);
void addLoader(C, C, C, C, C, C, C);
void addLoader(C, C, C, C, C, C, C, C);
void addLoader(C, C, C, C, C, C, C, C, C);
void addLoader(C, C, C, C, C, C, C, C, C, C);
#undef C
#if 1 && (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x040100))
void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__));
@@ -244,72 +229,76 @@ protected:
void __acc_cdecl_va addLoaderVA(const char *s, ...);
#endif
virtual bool hasLoaderSection(const char *name) const;
virtual int getLoaderSection(const char *name, int *slen=nullptr) const;
virtual int getLoaderSectionStart(const char *name, int *slen=nullptr) const;
virtual int getLoaderSection(const char *name, int *slen = nullptr) const;
virtual int getLoaderSectionStart(const char *name, int *slen = nullptr) const;
// compression handling [see packer_c.cpp]
public:
static bool isValidCompressionMethod(int method);
protected:
const int *getDefaultCompressionMethods_8(int method, int level, int small=-1) const;
const int *getDefaultCompressionMethods_le32(int method, int level, int small=-1) const;
const int *getDefaultCompressionMethods_8(int method, int level, int small = -1) const;
const int *getDefaultCompressionMethods_le32(int method, int level, int small = -1) const;
virtual const char *getDecompressorSections() const;
virtual unsigned getDecompressorWrkmemSize() const;
virtual void defineDecompressorSymbols();
// filter handling [see packer_f.cpp]
virtual bool isValidFilter(int filter_id) const;
virtual void optimizeFilter(Filter *, const upx_byte *, unsigned) const { }
virtual void optimizeFilter(Filter *, const upx_byte *, unsigned) const {}
virtual void addFilter32(int filter_id);
virtual void defineFilterSymbols(const Filter *ft);
// stub and overlay util
static void handleStub(InputFile *fi, OutputFile *fo, unsigned size);
virtual void checkOverlay(unsigned overlay);
virtual void copyOverlay(OutputFile *fo, unsigned overlay,
MemBuffer *buf, bool do_seek=true);
virtual void copyOverlay(OutputFile *fo, unsigned overlay, MemBuffer *buf, bool do_seek = true);
// misc util
virtual unsigned getRandomId() const;
// patch util
int patch_be16(void *b, int blen, unsigned old, unsigned new_);
int patch_be16(void *b, int blen, const void * old, unsigned new_);
int patch_be16(void *b, int blen, const void *old, unsigned new_);
int patch_be32(void *b, int blen, unsigned old, unsigned new_);
int patch_be32(void *b, int blen, const void * old, unsigned new_);
int patch_be32(void *b, int blen, const void *old, unsigned new_);
int patch_le16(void *b, int blen, unsigned old, unsigned new_);
int patch_le16(void *b, int blen, const void * old, unsigned new_);
int patch_le16(void *b, int blen, const void *old, unsigned new_);
int patch_le32(void *b, int blen, unsigned old, unsigned new_);
int patch_le32(void *b, int blen, const void * old, unsigned new_);
int patch_le32(void *b, int blen, const void *old, unsigned new_);
void checkPatch(void *b, int blen, int boff, int size);
// relocation util
static upx_byte *optimizeReloc(upx_byte *in,unsigned relocnum,upx_byte *out,upx_byte *image,int bs,int *big, int bits);
static unsigned unoptimizeReloc(upx_byte **in,upx_byte *image,MemBuffer *out,int bs, int bits);
static upx_byte *optimizeReloc32(upx_byte *in,unsigned relocnum,upx_byte *out,upx_byte *image,int bs,int *big);
static unsigned unoptimizeReloc32(upx_byte **in,upx_byte *image,MemBuffer *out,int bs);
static upx_byte *optimizeReloc64(upx_byte *in,unsigned relocnum,upx_byte *out,upx_byte *image,int bs,int *big);
static unsigned unoptimizeReloc64(upx_byte **in,upx_byte *image,MemBuffer *out,int bs);
static upx_byte *optimizeReloc(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image,
int bs, int *big, int bits);
static unsigned unoptimizeReloc(upx_byte **in, upx_byte *image, MemBuffer *out, int bs,
int bits);
static upx_byte *optimizeReloc32(upx_byte *in, unsigned relocnum, upx_byte *out,
upx_byte *image, int bs, int *big);
static unsigned unoptimizeReloc32(upx_byte **in, upx_byte *image, MemBuffer *out, int bs);
static upx_byte *optimizeReloc64(upx_byte *in, unsigned relocnum, upx_byte *out,
upx_byte *image, int bs, int *big);
static unsigned unoptimizeReloc64(upx_byte **in, upx_byte *image, MemBuffer *out, int bs);
// target endianness abstraction
unsigned get_te16(const void *p) const { return bele->get16(p); }
unsigned get_te32(const void *p) const { return bele->get32(p); }
upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
unsigned get_te16(const void *p) const { return bele->get16(p); }
unsigned get_te32(const void *p) const { return bele->get32(p); }
upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
protected:
const N_BELE_RTP::AbstractPolicy *bele; // target endianness
InputFile *fi;
off_t file_size; // will get set by constructor
PackHeader ph; // must be filled by canUnpack()
off_t file_size; // will get set by constructor
PackHeader ph; // must be filled by canUnpack()
int ph_format;
int ph_version;
// compression buffers
MemBuffer ibuf; // input
MemBuffer obuf; // output
MemBuffer ibuf; // input
MemBuffer obuf; // output
// UI handler
UiPacker *uip;
@@ -326,10 +315,9 @@ private:
private:
// disable copy and assignment
Packer(const Packer &) = delete;
Packer& operator= (const Packer &) = delete;
Packer &operator=(const Packer &) = delete;
};
#endif /* already included */
/* vim:set ts=4 sw=4 et: */

View File

@@ -2,6 +2,8 @@
## vim:set ts=4 sw=4 et:
set -e; set -o pipefail
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." Rob Pike
# NOTE: we are using clang-format-10.0.1 from upx-stubtools
# see https://github.com/upx/upx-stubtools/releases