clang-format more files.
"Gofmt's style is nobody's favourite, but gofmt is everybody's favourite."
- Rob Pike
This commit is contained in:
parent
8236276a90
commit
2575eef3c0
@ -1,4 +1,5 @@
|
|||||||
# for clang-format-10.0.1
|
# for clang-format-10.0.1
|
||||||
|
# "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite." Rob Pike
|
||||||
---
|
---
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
@ -8,5 +9,19 @@ ColumnLimit: 100
|
|||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
SortIncludes: false
|
SortIncludes: false
|
||||||
SpaceAfterCStyleCast: true
|
SpaceAfterCStyleCast: true
|
||||||
|
StatementMacros: [
|
||||||
|
ACCCHK_ASSERT,
|
||||||
|
ACCCHK_ASSERT_IS_SIGNED_T,
|
||||||
|
ACCCHK_ASSERT_IS_UNSIGNED_T,
|
||||||
|
ACCCHK_ASSERT_SIGN_T,
|
||||||
|
ACC_COMPILE_TIME_ASSERT,
|
||||||
|
ACC_COMPILE_TIME_ASSERT_HEADER,
|
||||||
|
ACC_CXX_DISABLE_NEW_DELETE,
|
||||||
|
ACC_CXX_TRIGGER_FUNCTION,
|
||||||
|
ACC_CXX_TRIGGER_FUNCTION_IMPL,
|
||||||
|
CLANG_FORMAT_DUMMY_STATEMENT,
|
||||||
|
COMPILE_TIME_ASSERT,
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1,
|
||||||
|
]
|
||||||
Standard: Cpp03
|
Standard: Cpp03
|
||||||
...
|
...
|
||||||
|
|||||||
@ -187,12 +187,16 @@ endif
|
|||||||
|
|
||||||
# automatically format some C++ source code files
|
# automatically format some C++ source code files
|
||||||
ifeq ($(shell uname),Linux)
|
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 += 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 += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
|
||||||
CLANG_FORMAT_FILES += snprintf.cpp
|
CLANG_FORMAT_FILES += snprintf.cpp
|
||||||
CLANG_FORMAT_FILES += ui.cpp ui.h util.cpp util.h work.cpp
|
CLANG_FORMAT_FILES += ui.cpp ui.h util.cpp util.h work.cpp
|
||||||
clang-format:
|
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
|
.PHONY: clang-format
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
692
src/bele.h
692
src/bele.h
@ -25,7 +25,6 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __UPX_BELE_H
|
#ifndef __UPX_BELE_H
|
||||||
#define __UPX_BELE_H 1
|
#define __UPX_BELE_H 1
|
||||||
|
|
||||||
@ -38,46 +37,39 @@
|
|||||||
// core - NE
|
// 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_uint16_t v = 0;
|
||||||
upx_memcpy_inline(&v, p, sizeof(v));
|
upx_memcpy_inline(&v, p, sizeof(v));
|
||||||
return 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_uint32_t v = 0;
|
||||||
upx_memcpy_inline(&v, p, sizeof(v));
|
upx_memcpy_inline(&v, p, sizeof(v));
|
||||||
return 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_uint64_t v = 0;
|
||||||
upx_memcpy_inline(&v, p, sizeof(v));
|
upx_memcpy_inline(&v, p, sizeof(v));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline void set_ne16(void *p, unsigned vv)
|
__acc_static_forceinline void set_ne16(void *p, unsigned vv) {
|
||||||
{
|
upx_uint16_t v = (upx_uint16_t)(vv & 0xffff);
|
||||||
upx_uint16_t v = (upx_uint16_t) (vv & 0xffff);
|
|
||||||
upx_memcpy_inline(p, &v, sizeof(v));
|
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_uint32_t v = vv;
|
||||||
upx_memcpy_inline(p, &v, sizeof(v));
|
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_uint64_t v = vv;
|
||||||
upx_memcpy_inline(p, &v, sizeof(v));
|
upx_memcpy_inline(p, &v, sizeof(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// core - bswap
|
// 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_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);
|
return (unsigned) _byteswap_ulong(v << 16);
|
||||||
}
|
}
|
||||||
__acc_static_forceinline unsigned bswap32(unsigned 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); }
|
||||||
return (unsigned) _byteswap_ulong(v);
|
|
||||||
}
|
|
||||||
__acc_static_forceinline upx_uint64_t bswap64(upx_uint64_t v)
|
|
||||||
{
|
|
||||||
return _byteswap_uint64(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
__acc_static_forceinline constexpr unsigned bswap16(unsigned v)
|
__acc_static_forceinline constexpr unsigned bswap16(unsigned v) {
|
||||||
{
|
// return __builtin_bswap16((upx_uint16_t) (v & 0xffff));
|
||||||
//return __builtin_bswap16((upx_uint16_t) (v & 0xffff));
|
// return (unsigned) __builtin_bswap64((upx_uint64_t) v << 48);
|
||||||
//return (unsigned) __builtin_bswap64((upx_uint64_t) v << 48);
|
|
||||||
return __builtin_bswap32(v << 16);
|
return __builtin_bswap32(v << 16);
|
||||||
}
|
}
|
||||||
__acc_static_forceinline constexpr unsigned bswap32(unsigned v)
|
__acc_static_forceinline constexpr unsigned bswap32(unsigned v) {
|
||||||
{
|
// return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
|
||||||
//return (unsigned) __builtin_bswap64((upx_uint64_t) v << 32);
|
|
||||||
return __builtin_bswap32(v);
|
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);
|
return __builtin_bswap64(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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
|
return v & 0xffff; // needed so that this is equivalent to bswap16() above
|
||||||
}
|
}
|
||||||
|
|
||||||
__acc_static_forceinline constexpr unsigned no_bswap32(unsigned v)
|
__acc_static_forceinline constexpr unsigned no_bswap32(unsigned v) { return v; }
|
||||||
{
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
__acc_static_forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v)
|
|
||||||
{
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
__acc_static_forceinline constexpr upx_uint64_t no_bswap64(upx_uint64_t v) { return v; }
|
||||||
|
|
||||||
#if (ACC_ABI_BIG_ENDIAN)
|
#if (ACC_ABI_BIG_ENDIAN)
|
||||||
# define ne16_to_be16(v) no_bswap16(v)
|
#define ne16_to_be16(v) no_bswap16(v)
|
||||||
# define ne32_to_be32(v) no_bswap32(v)
|
#define ne32_to_be32(v) no_bswap32(v)
|
||||||
# define ne64_to_be64(v) no_bswap64(v)
|
#define ne64_to_be64(v) no_bswap64(v)
|
||||||
# define ne16_to_le16(v) bswap16(v)
|
#define ne16_to_le16(v) bswap16(v)
|
||||||
# define ne32_to_le32(v) bswap32(v)
|
#define ne32_to_le32(v) bswap32(v)
|
||||||
# define ne64_to_le64(v) bswap64(v)
|
#define ne64_to_le64(v) bswap64(v)
|
||||||
#else
|
#else
|
||||||
# define ne16_to_be16(v) bswap16(v)
|
#define ne16_to_be16(v) bswap16(v)
|
||||||
# define ne32_to_be32(v) bswap32(v)
|
#define ne32_to_be32(v) bswap32(v)
|
||||||
# define ne64_to_be64(v) bswap64(v)
|
#define ne64_to_be64(v) bswap64(v)
|
||||||
# define ne16_to_le16(v) no_bswap16(v)
|
#define ne16_to_le16(v) no_bswap16(v)
|
||||||
# define ne32_to_le32(v) no_bswap32(v)
|
#define ne32_to_le32(v) no_bswap32(v)
|
||||||
# define ne64_to_le64(v) no_bswap64(v)
|
#define ne64_to_le64(v) no_bswap64(v)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// get/set 16/32/64
|
// get/set 16/32/64
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
inline unsigned get_be16(const void *p)
|
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)); }
|
||||||
return ne16_to_be16(get_ne16(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 unsigned get_be32(const void *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)); }
|
||||||
return ne32_to_be32(get_ne32(p));
|
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 upx_uint64_t get_be64(const void *p)
|
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)); }
|
||||||
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
|
// 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);
|
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
|
||||||
return (b[0] << 16) | (b[1] << 8) | (b[2] << 0);
|
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);
|
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
|
||||||
return (b[0] << 0) | (b[1] << 8) | (b[2] << 16);
|
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);
|
unsigned char *b = ACC_PCAST(unsigned char *, p);
|
||||||
b[0] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
|
b[0] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
|
||||||
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
||||||
b[2] = ACC_ICONV(unsigned char, (v >> 0) & 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);
|
unsigned char *b = ACC_PCAST(unsigned char *, p);
|
||||||
b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
|
b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
|
||||||
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
||||||
b[2] = ACC_ICONV(unsigned char, (v >> 16) & 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)
|
inline void set_le26(void *p, unsigned v) {
|
||||||
{
|
|
||||||
return get_le32(p) & 0x03ffffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_le26(void *p, unsigned v)
|
|
||||||
{
|
|
||||||
// preserve the top 6 bits
|
// 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
|
// 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
|
// 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);
|
const unsigned sign_bit = 1u << (bits - 1);
|
||||||
v &= sign_bit | (sign_bit - 1);
|
v &= sign_bit | (sign_bit - 1);
|
||||||
v |= 0 - (v & sign_bit);
|
v |= 0 - (v & sign_bit);
|
||||||
return ACC_ICAST(int, v);
|
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);
|
const upx_uint64_t sign_bit = UPX_UINT64_C(1) << (bits - 1);
|
||||||
v &= sign_bit | (sign_bit - 1);
|
v &= sign_bit | (sign_bit - 1);
|
||||||
v |= 0 - (v & sign_bit);
|
v |= 0 - (v & sign_bit);
|
||||||
return ACC_ICAST(upx_int64_t, v);
|
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);
|
unsigned v = get_be16(p);
|
||||||
return sign_extend(v, 16);
|
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);
|
unsigned v = get_be24(p);
|
||||||
return sign_extend(v, 24);
|
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);
|
unsigned v = get_be32(p);
|
||||||
return sign_extend(v, 32);
|
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);
|
upx_uint64_t v = get_be64(p);
|
||||||
return sign_extend(v, 64);
|
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);
|
unsigned v = get_le16(p);
|
||||||
return sign_extend(v, 16);
|
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);
|
unsigned v = get_le24(p);
|
||||||
return sign_extend(v, 24);
|
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);
|
unsigned v = get_le32(p);
|
||||||
return sign_extend(v, 32);
|
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);
|
upx_uint64_t v = get_le64(p);
|
||||||
return sign_extend(v, 64);
|
return sign_extend(v, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// classes for portable unaligned access
|
// 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 ]
|
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
__packed_struct(BE16)
|
struct alignas(1) BE16 {
|
||||||
unsigned char d[2];
|
unsigned char d[2];
|
||||||
|
|
||||||
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
|
BE16 &operator=(unsigned v) {
|
||||||
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
|
set_be16(d, v);
|
||||||
BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; }
|
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) {
|
||||||
BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; }
|
set_be16(d, get_be16(d) + v);
|
||||||
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
|
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) {
|
||||||
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
|
set_be16(d, get_be16(d) - v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE16 &operator*=(unsigned v) {
|
||||||
|
set_be16(d, get_be16(d) * v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE16 &operator/=(unsigned v) {
|
||||||
|
set_be16(d, get_be16(d) / v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE16 &operator&=(unsigned v) {
|
||||||
|
set_be16(d, get_be16(d) & v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE16 &operator|=(unsigned v) {
|
||||||
|
set_be16(d, get_be16(d) | v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE16 &operator^=(unsigned v) {
|
||||||
|
set_be16(d, get_be16(d) ^ v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE16 &operator<<=(unsigned v) {
|
||||||
|
set_be16(d, get_be16(d) << v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE16 &operator>>=(unsigned v) {
|
||||||
|
set_be16(d, get_be16(d) >> v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
operator unsigned () const { return get_be16(d); }
|
operator unsigned() const { return get_be16(d); }
|
||||||
__packed_struct_end()
|
};
|
||||||
|
|
||||||
|
struct alignas(1) BE32 {
|
||||||
__packed_struct(BE32)
|
|
||||||
unsigned char d[4];
|
unsigned char d[4];
|
||||||
|
|
||||||
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
|
BE32 &operator=(unsigned v) {
|
||||||
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
|
set_be32(d, v);
|
||||||
BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; }
|
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) {
|
||||||
BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; }
|
set_be32(d, get_be32(d) + v);
|
||||||
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
|
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) {
|
||||||
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
|
set_be32(d, get_be32(d) - v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE32 &operator*=(unsigned v) {
|
||||||
|
set_be32(d, get_be32(d) * v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE32 &operator/=(unsigned v) {
|
||||||
|
set_be32(d, get_be32(d) / v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE32 &operator&=(unsigned v) {
|
||||||
|
set_be32(d, get_be32(d) & v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE32 &operator|=(unsigned v) {
|
||||||
|
set_be32(d, get_be32(d) | v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE32 &operator^=(unsigned v) {
|
||||||
|
set_be32(d, get_be32(d) ^ v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE32 &operator<<=(unsigned v) {
|
||||||
|
set_be32(d, get_be32(d) << v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
BE32 &operator>>=(unsigned v) {
|
||||||
|
set_be32(d, get_be32(d) >> v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
operator unsigned () const { return get_be32(d); }
|
operator unsigned() const { return get_be32(d); }
|
||||||
__packed_struct_end()
|
};
|
||||||
|
|
||||||
|
struct alignas(1) BE64 {
|
||||||
__packed_struct(BE64)
|
|
||||||
unsigned char d[8];
|
unsigned char d[8];
|
||||||
|
|
||||||
BE64& operator = (upx_uint64_t v) { set_be64(d, v); return *this; }
|
BE64 &operator=(upx_uint64_t v) {
|
||||||
BE64& operator += (upx_uint64_t v) { set_be64(d, get_be64(d) + v); return *this; }
|
set_be64(d, v);
|
||||||
BE64& operator -= (upx_uint64_t v) { set_be64(d, get_be64(d) - v); return *this; }
|
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) {
|
||||||
BE64& operator &= (upx_uint64_t v) { set_be64(d, get_be64(d) & v); return *this; }
|
set_be64(d, get_be64(d) + v);
|
||||||
BE64& operator |= (upx_uint64_t v) { set_be64(d, get_be64(d) | v); return *this; }
|
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-=(upx_uint64_t v) {
|
||||||
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
|
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); }
|
operator upx_uint64_t() const { return get_be64(d); }
|
||||||
__packed_struct_end()
|
};
|
||||||
|
|
||||||
|
struct alignas(1) LE16 {
|
||||||
__packed_struct(LE16)
|
|
||||||
unsigned char d[2];
|
unsigned char d[2];
|
||||||
|
|
||||||
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
|
LE16 &operator=(unsigned v) {
|
||||||
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
|
set_le16(d, v);
|
||||||
LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; }
|
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) {
|
||||||
LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; }
|
set_le16(d, get_le16(d) + v);
|
||||||
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
|
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) {
|
||||||
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
|
set_le16(d, get_le16(d) - v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE16 &operator*=(unsigned v) {
|
||||||
|
set_le16(d, get_le16(d) * v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE16 &operator/=(unsigned v) {
|
||||||
|
set_le16(d, get_le16(d) / v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE16 &operator&=(unsigned v) {
|
||||||
|
set_le16(d, get_le16(d) & v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE16 &operator|=(unsigned v) {
|
||||||
|
set_le16(d, get_le16(d) | v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE16 &operator^=(unsigned v) {
|
||||||
|
set_le16(d, get_le16(d) ^ v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE16 &operator<<=(unsigned v) {
|
||||||
|
set_le16(d, get_le16(d) << v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE16 &operator>>=(unsigned v) {
|
||||||
|
set_le16(d, get_le16(d) >> v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
operator unsigned () const { return get_le16(d); }
|
operator unsigned() const { return get_le16(d); }
|
||||||
__packed_struct_end()
|
};
|
||||||
|
|
||||||
|
struct alignas(1) LE32 {
|
||||||
__packed_struct(LE32)
|
|
||||||
unsigned char d[4];
|
unsigned char d[4];
|
||||||
|
|
||||||
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
|
LE32 &operator=(unsigned v) {
|
||||||
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
|
set_le32(d, v);
|
||||||
LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; }
|
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) {
|
||||||
LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; }
|
set_le32(d, get_le32(d) + v);
|
||||||
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
|
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) {
|
||||||
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
|
set_le32(d, get_le32(d) - v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE32 &operator*=(unsigned v) {
|
||||||
|
set_le32(d, get_le32(d) * v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE32 &operator/=(unsigned v) {
|
||||||
|
set_le32(d, get_le32(d) / v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE32 &operator&=(unsigned v) {
|
||||||
|
set_le32(d, get_le32(d) & v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE32 &operator|=(unsigned v) {
|
||||||
|
set_le32(d, get_le32(d) | v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE32 &operator^=(unsigned v) {
|
||||||
|
set_le32(d, get_le32(d) ^ v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE32 &operator<<=(unsigned v) {
|
||||||
|
set_le32(d, get_le32(d) << v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
LE32 &operator>>=(unsigned v) {
|
||||||
|
set_le32(d, get_le32(d) >> v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
operator unsigned () const { return get_le32(d); }
|
operator unsigned() const { return get_le32(d); }
|
||||||
__packed_struct_end()
|
};
|
||||||
|
|
||||||
|
struct alignas(1) LE64 {
|
||||||
__packed_struct(LE64)
|
|
||||||
unsigned char d[8];
|
unsigned char d[8];
|
||||||
|
|
||||||
LE64& operator = (upx_uint64_t v) { set_le64(d, v); return *this; }
|
LE64 &operator=(upx_uint64_t v) {
|
||||||
LE64& operator += (upx_uint64_t v) { set_le64(d, get_le64(d) + v); return *this; }
|
set_le64(d, v);
|
||||||
LE64& operator -= (upx_uint64_t v) { set_le64(d, get_le64(d) - v); return *this; }
|
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) {
|
||||||
LE64& operator &= (upx_uint64_t v) { set_le64(d, get_le64(d) & v); return *this; }
|
set_le64(d, get_le64(d) + v);
|
||||||
LE64& operator |= (upx_uint64_t v) { set_le64(d, get_le64(d) | v); return *this; }
|
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-=(upx_uint64_t v) {
|
||||||
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
|
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, 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
|
// native types
|
||||||
#if (ACC_ABI_BIG_ENDIAN)
|
#if (ACC_ABI_BIG_ENDIAN)
|
||||||
@ -463,66 +542,91 @@ typedef LE32 NE32;
|
|||||||
typedef LE64 NE64;
|
typedef LE64 NE64;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// global operators (pointer addition/subtraction)
|
// global operators (pointer addition/subtraction)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
template <class T> inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }
|
template <class T>
|
||||||
template <class T> inline T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }
|
inline T *operator+(T *ptr, const BE16 &v) {
|
||||||
|
return ptr + (unsigned) v;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
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>
|
||||||
template <class T> inline T* operator - (T* ptr, const BE32& v) { return ptr - (unsigned) v; }
|
inline T *operator+(T *ptr, const BE32 &v) {
|
||||||
|
return ptr + (unsigned) v;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
inline T *operator-(T *ptr, const BE32 &v) {
|
||||||
|
return ptr - (unsigned) v;
|
||||||
|
}
|
||||||
|
|
||||||
// these are not implemented on purpose and will cause link-time errors
|
// 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>
|
||||||
template <class T> T* operator - (T* ptr, const BE64& v);
|
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>
|
||||||
template <class T> inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }
|
inline T *operator+(T *ptr, const LE16 &v) {
|
||||||
|
return ptr + (unsigned) v;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
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>
|
||||||
template <class T> inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }
|
inline T *operator+(T *ptr, const LE32 &v) {
|
||||||
|
return ptr + (unsigned) v;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
inline T *operator-(T *ptr, const LE32 &v) {
|
||||||
|
return ptr - (unsigned) v;
|
||||||
|
}
|
||||||
|
|
||||||
// these are not implemented on purpose and will cause link-time errors
|
// 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>
|
||||||
template <class T> T* operator - (T* ptr, const LE64& v);
|
T *operator+(T *ptr, const LE64 &v);
|
||||||
|
template <class T>
|
||||||
|
T *operator-(T *ptr, const LE64 &v);
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// global overloads
|
// global overloads
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
inline unsigned ALIGN_DOWN(unsigned a, const BE32& b) { return ALIGN_DOWN(a, (unsigned) 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_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(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_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(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_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(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_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(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_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(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_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(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_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(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_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(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_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(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_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 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
|
// 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 *);
|
int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// Provide namespaces and classes to abstract endianness policies.
|
// Provide namespaces and classes to abstract endianness policies.
|
||||||
//
|
//
|
||||||
@ -562,35 +665,36 @@ struct BEPolicy;
|
|||||||
struct LEPolicy;
|
struct LEPolicy;
|
||||||
extern const BEPolicy be_policy;
|
extern const BEPolicy be_policy;
|
||||||
extern const LEPolicy le_policy;
|
extern const LEPolicy le_policy;
|
||||||
}
|
} // namespace N_BELE_CTP
|
||||||
namespace N_BELE_RTP {
|
namespace N_BELE_RTP {
|
||||||
struct AbstractPolicy;
|
struct AbstractPolicy;
|
||||||
struct BEPolicy;
|
struct BEPolicy;
|
||||||
struct LEPolicy;
|
struct LEPolicy;
|
||||||
extern const BEPolicy be_policy;
|
extern const BEPolicy be_policy;
|
||||||
extern const LEPolicy le_policy;
|
extern const LEPolicy le_policy;
|
||||||
}
|
} // namespace N_BELE_RTP
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
namespace N_BELE_CTP {
|
namespace N_BELE_CTP {
|
||||||
#define BELE_CTP 1
|
#define BELE_CTP 1
|
||||||
#include "bele_policy.h"
|
#include "bele_policy.h"
|
||||||
#undef BELE_CTP
|
#undef BELE_CTP
|
||||||
}
|
} // namespace N_BELE_CTP
|
||||||
namespace N_BELE_RTP {
|
namespace N_BELE_RTP {
|
||||||
#define BELE_RTP 1
|
#define BELE_RTP 1
|
||||||
#include "bele_policy.h"
|
#include "bele_policy.h"
|
||||||
#undef BELE_RTP
|
#undef BELE_RTP
|
||||||
}
|
} // namespace N_BELE_RTP
|
||||||
|
|
||||||
// util
|
// util
|
||||||
namespace N_BELE_CTP {
|
namespace N_BELE_CTP {
|
||||||
inline const N_BELE_RTP::AbstractPolicy* getRTP(const BEPolicy * /*dummy*/)
|
inline const N_BELE_RTP::AbstractPolicy *getRTP(const BEPolicy * /*dummy*/) {
|
||||||
{ return &N_BELE_RTP::be_policy; }
|
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 LEPolicy * /*dummy*/) {
|
||||||
|
return &N_BELE_RTP::le_policy;
|
||||||
|
}
|
||||||
|
} // namespace N_BELE_CTP
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|
||||||
|
|||||||
@ -25,36 +25,32 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __UPX_BELE_H
|
#ifndef __UPX_BELE_H
|
||||||
# error "this is an internal include file"
|
#error "this is an internal include file"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if defined(BELE_CTP)
|
#if defined(BELE_CTP)
|
||||||
// CTP - Compile-Time Polymorphism (templates)
|
// CTP - Compile-Time Polymorphism (templates)
|
||||||
# define V static inline
|
#define V static inline
|
||||||
# define S static int __acc_cdecl_qsort
|
#define S static int __acc_cdecl_qsort
|
||||||
# define C /*empty*/
|
#define C /*empty*/
|
||||||
#elif defined(BELE_RTP)
|
#elif defined(BELE_RTP)
|
||||||
// RTP - Run-Time Polymorphism (virtual functions)
|
// RTP - Run-Time Polymorphism (virtual functions)
|
||||||
# define V virtual
|
#define V virtual
|
||||||
# define S virtual int
|
#define S virtual int
|
||||||
# define C const
|
#define C const
|
||||||
#else
|
#else
|
||||||
# error
|
#error
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(BELE_RTP)
|
#if defined(BELE_RTP)
|
||||||
struct AbstractPolicy
|
struct AbstractPolicy {
|
||||||
{
|
inline AbstractPolicy() {}
|
||||||
inline AbstractPolicy() { }
|
virtual inline ~AbstractPolicy() {}
|
||||||
virtual inline ~AbstractPolicy() { }
|
|
||||||
V bool isBE() C = 0;
|
V bool isBE() C = 0;
|
||||||
V bool isLE() C = 0;
|
V bool isLE() C = 0;
|
||||||
|
|
||||||
@ -88,13 +84,12 @@ struct AbstractPolicy
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct BEPolicy
|
struct BEPolicy
|
||||||
#if defined(BELE_RTP)
|
#if defined(BELE_RTP)
|
||||||
: public AbstractPolicy
|
: public AbstractPolicy
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
inline BEPolicy() { }
|
inline BEPolicy() {}
|
||||||
#if defined(BELE_CTP)
|
#if defined(BELE_CTP)
|
||||||
typedef N_BELE_RTP::BEPolicy RTP_Policy;
|
typedef N_BELE_RTP::BEPolicy RTP_Policy;
|
||||||
#elif defined(BELE_RTP)
|
#elif defined(BELE_RTP)
|
||||||
@ -107,50 +102,30 @@ struct BEPolicy
|
|||||||
typedef BE32 U32;
|
typedef BE32 U32;
|
||||||
typedef BE64 U64;
|
typedef BE64 U64;
|
||||||
|
|
||||||
V unsigned get16(const void *p) C
|
V unsigned get16(const void *p) C { return get_be16(p); }
|
||||||
{ return get_be16(p); }
|
V unsigned get24(const void *p) C { return get_be24(p); }
|
||||||
V unsigned get24(const void *p) C
|
V unsigned get32(const void *p) C { return get_be32(p); }
|
||||||
{ return get_be24(p); }
|
V upx_uint64_t get64(const void *p) C { return get_be64(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
|
V void set16(void *p, unsigned v) C { set_be16(p, v); }
|
||||||
{ set_be16(p, v); }
|
V void set24(void *p, unsigned v) C { set_be24(p, v); }
|
||||||
V void set24(void *p, unsigned v) C
|
V void set32(void *p, unsigned v) C { set_be32(p, v); }
|
||||||
{ set_be24(p, v); }
|
V void set64(void *p, upx_uint64_t v) C { set_be64(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
|
V int get16_signed(const void *p) C { return get_be16_signed(p); }
|
||||||
{ return get_be16_signed(p); }
|
V int get24_signed(const void *p) C { return get_be24_signed(p); }
|
||||||
V int get24_signed(const void *p) C
|
V int get32_signed(const void *p) C { return get_be32_signed(p); }
|
||||||
{ return get_be24_signed(p); }
|
V upx_int64_t get64_signed(const void *p) C { return get_be64_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
|
S u16_compare(const void *a, const void *b) C { return be16_compare(a, b); }
|
||||||
{ return be16_compare(a, b); }
|
S u24_compare(const void *a, const void *b) C { return be24_compare(a, b); }
|
||||||
S u24_compare(const void *a, const void *b) C
|
S u32_compare(const void *a, const void *b) C { return be32_compare(a, b); }
|
||||||
{ return be24_compare(a, b); }
|
S u64_compare(const void *a, const void *b) C { return be64_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
|
S u16_compare_signed(const void *a, const void *b) C { return be16_compare_signed(a, b); }
|
||||||
{ return be16_compare_signed(a, b); }
|
S u24_compare_signed(const void *a, const void *b) C { return be24_compare_signed(a, b); }
|
||||||
S u24_compare_signed(const void *a, const void *b) C
|
S u32_compare_signed(const void *a, const void *b) C { return be32_compare_signed(a, b); }
|
||||||
{ return be24_compare_signed(a, b); }
|
S u64_compare_signed(const void *a, const void *b) C { return be64_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() {
|
static void compileTimeAssertions() {
|
||||||
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
||||||
@ -165,13 +140,12 @@ struct BEPolicy
|
|||||||
ACC_CXX_DISABLE_NEW_DELETE
|
ACC_CXX_DISABLE_NEW_DELETE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct LEPolicy
|
struct LEPolicy
|
||||||
#if defined(BELE_RTP)
|
#if defined(BELE_RTP)
|
||||||
: public AbstractPolicy
|
: public AbstractPolicy
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
inline LEPolicy() { }
|
inline LEPolicy() {}
|
||||||
#if defined(BELE_CTP)
|
#if defined(BELE_CTP)
|
||||||
typedef N_BELE_RTP::LEPolicy RTP_Policy;
|
typedef N_BELE_RTP::LEPolicy RTP_Policy;
|
||||||
#elif defined(BELE_RTP)
|
#elif defined(BELE_RTP)
|
||||||
@ -184,50 +158,30 @@ struct LEPolicy
|
|||||||
typedef LE32 U32;
|
typedef LE32 U32;
|
||||||
typedef LE64 U64;
|
typedef LE64 U64;
|
||||||
|
|
||||||
V unsigned get16(const void *p) C
|
V unsigned get16(const void *p) C { return get_le16(p); }
|
||||||
{ return get_le16(p); }
|
V unsigned get24(const void *p) C { return get_le24(p); }
|
||||||
V unsigned get24(const void *p) C
|
V unsigned get32(const void *p) C { return get_le32(p); }
|
||||||
{ return get_le24(p); }
|
V upx_uint64_t get64(const void *p) C { return get_le64(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
|
V void set16(void *p, unsigned v) C { set_le16(p, v); }
|
||||||
{ set_le16(p, v); }
|
V void set24(void *p, unsigned v) C { set_le24(p, v); }
|
||||||
V void set24(void *p, unsigned v) C
|
V void set32(void *p, unsigned v) C { set_le32(p, v); }
|
||||||
{ set_le24(p, v); }
|
V void set64(void *p, upx_uint64_t v) C { set_le64(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
|
V int get16_signed(const void *p) C { return get_le16_signed(p); }
|
||||||
{ return get_le16_signed(p); }
|
V int get24_signed(const void *p) C { return get_le24_signed(p); }
|
||||||
V int get24_signed(const void *p) C
|
V int get32_signed(const void *p) C { return get_le32_signed(p); }
|
||||||
{ return get_le24_signed(p); }
|
V upx_int64_t get64_signed(const void *p) C { return get_le64_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
|
S u16_compare(const void *a, const void *b) C { return le16_compare(a, b); }
|
||||||
{ return le16_compare(a, b); }
|
S u24_compare(const void *a, const void *b) C { return le24_compare(a, b); }
|
||||||
S u24_compare(const void *a, const void *b) C
|
S u32_compare(const void *a, const void *b) C { return le32_compare(a, b); }
|
||||||
{ return le24_compare(a, b); }
|
S u64_compare(const void *a, const void *b) C { return le64_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
|
S u16_compare_signed(const void *a, const void *b) C { return le16_compare_signed(a, b); }
|
||||||
{ return le16_compare_signed(a, b); }
|
S u24_compare_signed(const void *a, const void *b) C { return le24_compare_signed(a, b); }
|
||||||
S u24_compare_signed(const void *a, const void *b) C
|
S u32_compare_signed(const void *a, const void *b) C { return le32_compare_signed(a, b); }
|
||||||
{ return le24_compare_signed(a, b); }
|
S u64_compare_signed(const void *a, const void *b) C { return le64_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() {
|
static void compileTimeAssertions() {
|
||||||
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
||||||
@ -242,20 +196,17 @@ struct LEPolicy
|
|||||||
ACC_CXX_DISABLE_NEW_DELETE
|
ACC_CXX_DISABLE_NEW_DELETE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// native policy (aka host policy)
|
// native policy (aka host policy)
|
||||||
#if (ACC_ABI_BIG_ENDIAN)
|
#if (ACC_ABI_BIG_ENDIAN)
|
||||||
typedef BEPolicy HostPolicy;
|
typedef BEPolicy HostPolicy;
|
||||||
#elif (ACC_ABI_LITTLE_ENDIAN)
|
#elif (ACC_ABI_LITTLE_ENDIAN)
|
||||||
typedef LEPolicy HostPolicy;
|
typedef LEPolicy HostPolicy;
|
||||||
#else
|
#else
|
||||||
# error "ACC_ABI_ENDIAN"
|
#error "ACC_ABI_ENDIAN"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if 0 /* UNUSED */
|
#if 0 /* UNUSED */
|
||||||
struct HostAlignedPolicy
|
struct HostAlignedPolicy {
|
||||||
{
|
|
||||||
#if defined(BELE_CTP)
|
#if defined(BELE_CTP)
|
||||||
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
|
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
|
||||||
#endif
|
#endif
|
||||||
@ -272,7 +223,6 @@ struct HostAlignedPolicy
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#undef V
|
#undef V
|
||||||
#undef S
|
#undef S
|
||||||
#undef C
|
#undef C
|
||||||
|
|||||||
@ -269,6 +269,8 @@ typedef size_t upx_rsize_t;
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
#define CLANG_FORMAT_DUMMY_STATEMENT /*empty*/
|
||||||
|
|
||||||
#if !defined(__has_builtin)
|
#if !defined(__has_builtin)
|
||||||
# define __has_builtin(x) 0
|
# define __has_builtin(x) 0
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
104
src/except.cpp
104
src/except.cpp
@ -25,19 +25,18 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
unsigned long Throwable::counter = 0;
|
unsigned long Throwable::counter = 0;
|
||||||
|
|
||||||
Throwable::Throwable(const char *m, int e, bool w) noexcept
|
Throwable::Throwable(const char *m, int e, bool w) noexcept : super(),
|
||||||
: super(), msg(nullptr), err(e), is_warning(w)
|
msg(nullptr),
|
||||||
{
|
err(e),
|
||||||
|
is_warning(w) {
|
||||||
if (m)
|
if (m)
|
||||||
msg = strdup(m);
|
msg = strdup(m);
|
||||||
#if 0
|
#if 0
|
||||||
@ -46,10 +45,10 @@ Throwable::Throwable(const char *m, int e, bool w) noexcept
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Throwable::Throwable(const Throwable &other) noexcept : super(other),
|
||||||
Throwable::Throwable(const Throwable &other) noexcept
|
msg(nullptr),
|
||||||
: super(other), msg(nullptr), err(other.err), is_warning(other.is_warning)
|
err(other.err),
|
||||||
{
|
is_warning(other.is_warning) {
|
||||||
if (other.msg)
|
if (other.msg)
|
||||||
msg = strdup(other.msg);
|
msg = strdup(other.msg);
|
||||||
#if 0
|
#if 0
|
||||||
@ -58,9 +57,7 @@ Throwable::Throwable(const Throwable &other) noexcept
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Throwable::~Throwable() noexcept {
|
||||||
Throwable::~Throwable() noexcept
|
|
||||||
{
|
|
||||||
#if 0
|
#if 0
|
||||||
counter--;
|
counter--;
|
||||||
fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
|
fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
|
||||||
@ -69,13 +66,11 @@ Throwable::~Throwable() noexcept
|
|||||||
free(msg);
|
free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// compression
|
// compression
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void throwCantPack(const char *msg)
|
void throwCantPack(const char *msg) {
|
||||||
{
|
|
||||||
// UGLY, but makes things easier
|
// UGLY, but makes things easier
|
||||||
if (opt->cmd == CMD_COMPRESS)
|
if (opt->cmd == CMD_COMPRESS)
|
||||||
throw CantPackException(msg);
|
throw CantPackException(msg);
|
||||||
@ -85,119 +80,78 @@ void throwCantPack(const char *msg)
|
|||||||
throw CantUnpackException(msg);
|
throw CantUnpackException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void throwCantPackExact()
|
void throwCantPackExact() { throwCantPack("option '--exact' does not work with this file"); }
|
||||||
{
|
|
||||||
throwCantPack("option '--exact' does not work with this file");
|
|
||||||
}
|
|
||||||
|
|
||||||
void throwFilterException()
|
void throwFilterException() { throwCantPack("filter problem"); }
|
||||||
{
|
|
||||||
throwCantPack("filter problem");
|
|
||||||
}
|
|
||||||
|
|
||||||
void throwUnknownExecutableFormat(const char *msg, bool warn)
|
void throwUnknownExecutableFormat(const char *msg, bool warn) {
|
||||||
{
|
|
||||||
throw UnknownExecutableFormatException(msg, warn);
|
throw UnknownExecutableFormatException(msg, warn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void throwNotCompressible(const char *msg)
|
void throwNotCompressible(const char *msg) { throw NotCompressibleException(msg); }
|
||||||
{
|
|
||||||
throw NotCompressibleException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void throwAlreadyPacked(const char *msg)
|
void throwAlreadyPacked(const char *msg) { throw AlreadyPackedException(msg); }
|
||||||
{
|
|
||||||
throw AlreadyPackedException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void throwAlreadyPackedByUPX(const char *msg)
|
void throwAlreadyPackedByUPX(const char *msg) {
|
||||||
{
|
|
||||||
if (msg == nullptr)
|
if (msg == nullptr)
|
||||||
msg = "already packed by UPX";
|
msg = "already packed by UPX";
|
||||||
throwAlreadyPacked(msg);
|
throwAlreadyPacked(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// decompression
|
// decompression
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void throwCantUnpack(const char *msg)
|
void throwCantUnpack(const char *msg) {
|
||||||
{
|
|
||||||
// UGLY, but makes things easier
|
// UGLY, but makes things easier
|
||||||
throwCantPack(msg);
|
throwCantPack(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void throwNotPacked(const char *msg)
|
void throwNotPacked(const char *msg) {
|
||||||
{
|
|
||||||
if (msg == nullptr)
|
if (msg == nullptr)
|
||||||
msg = "not packed by UPX";
|
msg = "not packed by UPX";
|
||||||
throw NotPackedException(msg);
|
throw NotPackedException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void throwChecksumError()
|
void throwChecksumError() { throw Exception("checksum error"); }
|
||||||
{
|
|
||||||
throw Exception("checksum error");
|
|
||||||
}
|
|
||||||
|
|
||||||
void throwCompressedDataViolation()
|
|
||||||
{
|
|
||||||
throw Exception("compressed data violation");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void throwCompressedDataViolation() { throw Exception("compressed data violation"); }
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// other
|
// other
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void throwInternalError(const char *msg)
|
void throwInternalError(const char *msg) { throw InternalError(msg); }
|
||||||
{
|
|
||||||
throw InternalError(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void throwBadLoader()
|
void throwBadLoader() { throwInternalError("bad loader"); }
|
||||||
{
|
|
||||||
throwInternalError("bad loader");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void throwOutOfMemoryException(const char *msg) {
|
||||||
void throwOutOfMemoryException(const char *msg)
|
|
||||||
{
|
|
||||||
if (msg == nullptr)
|
if (msg == nullptr)
|
||||||
msg = "out of memory";
|
msg = "out of memory";
|
||||||
throw OutOfMemoryException(msg);
|
throw OutOfMemoryException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void throwIOException(const char *msg, int e) { throw IOException(msg, e); }
|
||||||
|
|
||||||
void throwIOException(const char *msg, int e)
|
void throwEOFException(const char *msg, int e) {
|
||||||
{
|
|
||||||
throw IOException(msg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void throwEOFException(const char *msg, int e)
|
|
||||||
{
|
|
||||||
if (msg == nullptr && e == 0)
|
if (msg == nullptr && e == 0)
|
||||||
msg = "premature end of file";
|
msg = "premature end of file";
|
||||||
throw EOFException(msg, e);
|
throw EOFException(msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
const char *prettyName(const char *n) noexcept
|
const char *prettyName(const char *n) noexcept {
|
||||||
{
|
|
||||||
if (n == nullptr)
|
if (n == nullptr)
|
||||||
return "(null)";
|
return "(null)";
|
||||||
while (*n)
|
while (*n) {
|
||||||
{
|
if (*n >= '0' && *n <= '9') // Linux ABI
|
||||||
if (*n >= '0' && *n <= '9') // Linux ABI
|
|
||||||
n++;
|
n++;
|
||||||
else if (*n == ' ')
|
else if (*n == ' ')
|
||||||
n++;
|
n++;
|
||||||
else if (strncmp(n, "class ", 6) == 0) // Visual C++
|
else if (strncmp(n, "class ", 6) == 0) // Visual C++
|
||||||
n += 6;
|
n += 6;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|||||||
126
src/except.h
126
src/except.h
@ -25,7 +25,6 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __UPX_EXCEPT_H
|
#ifndef __UPX_EXCEPT_H
|
||||||
#define __UPX_EXCEPT_H 1
|
#define __UPX_EXCEPT_H 1
|
||||||
|
|
||||||
@ -33,167 +32,159 @@
|
|||||||
|
|
||||||
const char *prettyName(const char *n) noexcept;
|
const char *prettyName(const char *n) noexcept;
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// exceptions
|
// exceptions
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class Throwable : public std::exception
|
class Throwable : public std::exception {
|
||||||
{
|
|
||||||
typedef std::exception super;
|
typedef std::exception super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
|
Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Throwable(const Throwable &) noexcept;
|
Throwable(const Throwable &) noexcept;
|
||||||
virtual ~Throwable() noexcept;
|
virtual ~Throwable() noexcept;
|
||||||
const char *getMsg() const noexcept { return msg; }
|
const char *getMsg() const noexcept { return msg; }
|
||||||
int getErrno() const noexcept { return err; }
|
int getErrno() const noexcept { return err; }
|
||||||
bool isWarning() const noexcept { return is_warning; }
|
bool isWarning() const noexcept { return is_warning; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *msg;
|
char *msg;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool is_warning; // can be set by subclasses
|
bool is_warning; // can be set by subclasses
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disable assignment
|
// disable assignment
|
||||||
Throwable& operator= (const Throwable &);
|
Throwable &operator=(const Throwable &);
|
||||||
// disable dynamic allocation
|
// disable dynamic allocation
|
||||||
ACC_CXX_DISABLE_NEW_DELETE
|
ACC_CXX_DISABLE_NEW_DELETE
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static unsigned long counter; // for debugging
|
static unsigned long counter; // for debugging
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Exceptions can/should be caught
|
// Exceptions can/should be caught
|
||||||
class Exception : public Throwable
|
class Exception : public Throwable {
|
||||||
{
|
|
||||||
typedef Throwable super;
|
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)
|
// Errors should not be caught (or re-thrown)
|
||||||
class Error : public Throwable
|
class Error : public Throwable {
|
||||||
{
|
|
||||||
typedef Throwable super;
|
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
|
// system exception
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class OutOfMemoryException : public Exception
|
class OutOfMemoryException : public Exception {
|
||||||
{
|
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef IOException super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef IOException super;
|
||||||
|
|
||||||
public:
|
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;
|
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
|
// application exceptions
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class OverlayException : public Exception
|
class OverlayException : public Exception {
|
||||||
{
|
|
||||||
typedef Exception super;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef CantPackException super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef CantPackException super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
|
AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotCompressibleException : public CantPackException
|
class NotCompressibleException : public CantPackException {
|
||||||
{
|
|
||||||
typedef CantPackException super;
|
typedef CantPackException super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef Exception super;
|
||||||
|
|
||||||
public:
|
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;
|
typedef CantUnpackException super;
|
||||||
public:
|
|
||||||
NotPackedException(const char *m = nullptr) noexcept : super(m,true) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
NotPackedException(const char *m = nullptr) noexcept : super(m, true) {}
|
||||||
|
};
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// errors
|
// errors
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class InternalError : public Error
|
class InternalError : public Error {
|
||||||
{
|
|
||||||
typedef Error super;
|
typedef Error super;
|
||||||
public:
|
|
||||||
InternalError(const char *m = nullptr) noexcept : super(m,0) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
InternalError(const char *m = nullptr) noexcept : super(m, 0) {}
|
||||||
|
};
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
@ -225,7 +216,6 @@ void throwEOFException(const char *msg = nullptr, int e = 0) NORET;
|
|||||||
|
|
||||||
#undef NORET
|
#undef NORET
|
||||||
|
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|||||||
1064
src/main.cpp
1064
src/main.cpp
File diff suppressed because it is too large
Load Diff
@ -25,11 +25,9 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __UPX_OPTIONS_H
|
#ifndef __UPX_OPTIONS_H
|
||||||
#define __UPX_OPTIONS_H 1
|
#define __UPX_OPTIONS_H 1
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// globals
|
// globals
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@ -37,11 +35,16 @@
|
|||||||
// options - command
|
// options - command
|
||||||
enum {
|
enum {
|
||||||
CMD_NONE,
|
CMD_NONE,
|
||||||
CMD_COMPRESS, CMD_DECOMPRESS, CMD_TEST, CMD_LIST, CMD_FILEINFO,
|
CMD_COMPRESS,
|
||||||
CMD_HELP, CMD_LICENSE, CMD_VERSION
|
CMD_DECOMPRESS,
|
||||||
|
CMD_TEST,
|
||||||
|
CMD_LIST,
|
||||||
|
CMD_FILEINFO,
|
||||||
|
CMD_HELP,
|
||||||
|
CMD_LICENSE,
|
||||||
|
CMD_VERSION
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct options_t {
|
struct options_t {
|
||||||
int cmd;
|
int cmd;
|
||||||
|
|
||||||
@ -56,15 +59,15 @@ struct options_t {
|
|||||||
bool method_nrv2b_seen;
|
bool method_nrv2b_seen;
|
||||||
bool method_nrv2d_seen;
|
bool method_nrv2d_seen;
|
||||||
bool method_nrv2e_seen;
|
bool method_nrv2e_seen;
|
||||||
int level; // compression level 1..10
|
int level; // compression level 1..10
|
||||||
int filter; // preferred filter from Packer::getFilters()
|
int filter; // preferred filter from Packer::getFilters()
|
||||||
bool ultra_brute;
|
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_methods_use_lzma;
|
||||||
bool all_filters; // try all available filters ?
|
bool all_filters; // try all available filters ?
|
||||||
bool no_filter; // force no filter
|
bool no_filter; // force no filter
|
||||||
bool prefer_ucl; // prefer UCL
|
bool prefer_ucl; // prefer UCL
|
||||||
bool exact; // user requires byte-identical decompression
|
bool exact; // user requires byte-identical decompression
|
||||||
|
|
||||||
// other options
|
// other options
|
||||||
int backup;
|
int backup;
|
||||||
@ -85,38 +88,38 @@ struct options_t {
|
|||||||
// debug options
|
// debug options
|
||||||
struct {
|
struct {
|
||||||
int debug_level;
|
int debug_level;
|
||||||
bool disable_random_id; // for Packer::getRandomId()
|
bool disable_random_id; // for Packer::getRandomId()
|
||||||
const char *dump_stub_loader;
|
const char *dump_stub_loader;
|
||||||
char fake_stub_version[4+1]; // for internal debugging
|
char fake_stub_version[4 + 1]; // for internal debugging
|
||||||
char fake_stub_year[4+1]; // for internal debugging
|
char fake_stub_year[4 + 1]; // for internal debugging
|
||||||
} debug;
|
} debug;
|
||||||
|
|
||||||
// overlay handling
|
// overlay handling
|
||||||
enum {
|
enum { SKIP_OVERLAY = 0, COPY_OVERLAY = 1, STRIP_OVERLAY = 2 };
|
||||||
SKIP_OVERLAY = 0,
|
|
||||||
COPY_OVERLAY = 1,
|
|
||||||
STRIP_OVERLAY = 2
|
|
||||||
};
|
|
||||||
int overlay;
|
int overlay;
|
||||||
|
|
||||||
// compression runtime parameters - see struct XXX_compress_config_t
|
// compression runtime parameters - see struct XXX_compress_config_t
|
||||||
struct crp_t {
|
struct crp_t {
|
||||||
lzma_compress_config_t crp_lzma;
|
lzma_compress_config_t crp_lzma;
|
||||||
ucl_compress_config_t crp_ucl;
|
ucl_compress_config_t crp_ucl;
|
||||||
zlib_compress_config_t crp_zlib;
|
zlib_compress_config_t crp_zlib;
|
||||||
void reset() { crp_lzma.reset(); crp_ucl.reset(); crp_zlib.reset(); }
|
void reset() {
|
||||||
|
crp_lzma.reset();
|
||||||
|
crp_ucl.reset();
|
||||||
|
crp_zlib.reset();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
crp_t crp;
|
crp_t crp;
|
||||||
|
|
||||||
// CPU
|
// CPU
|
||||||
enum {
|
enum {
|
||||||
CPU_DEFAULT = 0,
|
CPU_DEFAULT = 0,
|
||||||
CPU_8086 = 1,
|
CPU_8086 = 1,
|
||||||
CPU_286 = 2,
|
CPU_286 = 2,
|
||||||
CPU_386 = 3,
|
CPU_386 = 3,
|
||||||
CPU_486 = 4,
|
CPU_486 = 4,
|
||||||
CPU_586 = 5,
|
CPU_586 = 5,
|
||||||
CPU_686 = 6
|
CPU_686 = 6
|
||||||
};
|
};
|
||||||
int cpu;
|
int cpu;
|
||||||
|
|
||||||
@ -139,15 +142,15 @@ struct options_t {
|
|||||||
} ps1_exe;
|
} ps1_exe;
|
||||||
struct {
|
struct {
|
||||||
unsigned blocksize;
|
unsigned blocksize;
|
||||||
bool force_execve; // force the linux/386 execve format
|
bool force_execve; // force the linux/386 execve format
|
||||||
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||||
bool use_ptinterp; // use PT_INTERP /opt/upx/run
|
bool use_ptinterp; // use PT_INTERP /opt/upx/run
|
||||||
bool make_ptinterp; // make PT_INTERP [ignore current file!]
|
bool make_ptinterp; // make PT_INTERP [ignore current file!]
|
||||||
bool unmap_all_pages; // thus /proc/self/exe vanishes
|
bool unmap_all_pages; // thus /proc/self/exe vanishes
|
||||||
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
|
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
|
||||||
bool preserve_build_id; // copy the build-id to the compressed binary
|
bool preserve_build_id; // copy the build-id to the compressed binary
|
||||||
bool android_shlib; // keep some ElfXX_Shdr for dlopen()
|
bool android_shlib; // keep some ElfXX_Shdr for dlopen()
|
||||||
bool force_pie; // choose DF_1_PIE instead of is_shlib
|
bool force_pie; // choose DF_1_PIE instead of is_shlib
|
||||||
} o_unix;
|
} o_unix;
|
||||||
struct {
|
struct {
|
||||||
bool le;
|
bool le;
|
||||||
@ -156,7 +159,7 @@ struct options_t {
|
|||||||
int compress_exports;
|
int compress_exports;
|
||||||
int compress_icons;
|
int compress_icons;
|
||||||
int compress_resources;
|
int compress_resources;
|
||||||
signed char compress_rt[25]; // 25 == RT_LAST
|
signed char compress_rt[25]; // 25 == RT_LAST
|
||||||
int strip_relocs;
|
int strip_relocs;
|
||||||
const char *keep_resource;
|
const char *keep_resource;
|
||||||
} win32_pe;
|
} win32_pe;
|
||||||
@ -166,7 +169,6 @@ struct options_t {
|
|||||||
|
|
||||||
extern struct options_t *opt;
|
extern struct options_t *opt;
|
||||||
|
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
254
src/p_tos.cpp
254
src/p_tos.cpp
@ -25,7 +25,6 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
@ -34,75 +33,55 @@
|
|||||||
#include "p_tos.h"
|
#include "p_tos.h"
|
||||||
#include "linker.h"
|
#include "linker.h"
|
||||||
|
|
||||||
static const
|
static const CLANG_FORMAT_DUMMY_STATEMENT
|
||||||
#include "stub/m68k-atari.tos.h"
|
#include "stub/m68k-atari.tos.h"
|
||||||
|
|
||||||
//#define TESTING 1
|
//#define TESTING 1
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define FH_SIZE sizeof(tos_header_t)
|
#define FH_SIZE sizeof(tos_header_t)
|
||||||
|
|
||||||
PackTos::PackTos(InputFile *f) :
|
PackTos::PackTos(InputFile *f) : super(f) {
|
||||||
super(f)
|
|
||||||
{
|
|
||||||
bele = &N_BELE_RTP::be_policy;
|
bele = &N_BELE_RTP::be_policy;
|
||||||
COMPILE_TIME_ASSERT(FH_SIZE == 28);
|
COMPILE_TIME_ASSERT(FH_SIZE == 28);
|
||||||
|
COMPILE_TIME_ASSERT_ALIGNED1(tos_header_t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int *PackTos::getCompressionMethods(int method, int level) const {
|
||||||
const int *PackTos::getCompressionMethods(int method, int level) const
|
bool small = ih.fh_text + ih.fh_data <= 256 * 1024;
|
||||||
{
|
|
||||||
bool small = ih.fh_text + ih.fh_data <= 256*1024;
|
|
||||||
return Packer::getDefaultCompressionMethods_8(method, level, small);
|
return Packer::getDefaultCompressionMethods_8(method, level, small);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int *PackTos::getFilters() const { return nullptr; }
|
||||||
|
|
||||||
const int *PackTos::getFilters() const
|
Linker *PackTos::newLinker() const { return new ElfLinkerM68k; }
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void PackTos::LinkerSymbols::LoopInfo::init(unsigned count_, bool allow_dbra) {
|
||||||
Linker* PackTos::newLinker() const
|
|
||||||
{
|
|
||||||
return new ElfLinkerM68k;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PackTos::LinkerSymbols::LoopInfo::init(unsigned count_, bool allow_dbra)
|
|
||||||
{
|
|
||||||
count = value = count_;
|
count = value = count_;
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
mode = LOOP_NONE;
|
mode = LOOP_NONE;
|
||||||
else if (count <= 65536 && allow_dbra)
|
else if (count <= 65536 && allow_dbra) {
|
||||||
{
|
|
||||||
mode = LOOP_DBRA;
|
mode = LOOP_DBRA;
|
||||||
value -= 1;
|
value -= 1;
|
||||||
value &= 0xffff;
|
value &= 0xffff;
|
||||||
}
|
} else if (count <= 65536) {
|
||||||
else if (count <= 65536)
|
|
||||||
{
|
|
||||||
mode = LOOP_SUBQ_W;
|
mode = LOOP_SUBQ_W;
|
||||||
value &= 0xffff;
|
value &= 0xffff;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
mode = LOOP_SUBQ_L;
|
mode = LOOP_SUBQ_L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned PackTos::getDecomprOffset(int method, int small) const {
|
||||||
unsigned PackTos::getDecomprOffset(int method, int small) const
|
|
||||||
{
|
|
||||||
UNUSED(small);
|
UNUSED(small);
|
||||||
if (M_IS_NRV2B(method))
|
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))
|
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))
|
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))
|
else if (M_IS_LZMA(method))
|
||||||
return linker->getSectionSize("__mulsi3");
|
return linker->getSectionSize("__mulsi3");
|
||||||
else
|
else
|
||||||
@ -110,13 +89,11 @@ unsigned PackTos::getDecomprOffset(int method, int small) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PackTos::buildLoader(const Filter *ft) {
|
||||||
void PackTos::buildLoader(const Filter *ft)
|
|
||||||
{
|
|
||||||
assert(ft->id == 0);
|
assert(ft->id == 0);
|
||||||
|
|
||||||
initLoader(stub_m68k_atari_tos, sizeof(stub_m68k_atari_tos));
|
initLoader(stub_m68k_atari_tos, sizeof(stub_m68k_atari_tos));
|
||||||
//linker->dumpSymbols();
|
// linker->dumpSymbols();
|
||||||
|
|
||||||
//
|
//
|
||||||
// part 1a
|
// part 1a
|
||||||
@ -132,8 +109,7 @@ void PackTos::buildLoader(const Filter *ft)
|
|||||||
addLoader("set_up21_d4.l");
|
addLoader("set_up21_d4.l");
|
||||||
|
|
||||||
assert(symbols.loop1.count || symbols.loop2.count);
|
assert(symbols.loop1.count || symbols.loop2.count);
|
||||||
if (symbols.loop1.count)
|
if (symbols.loop1.count) {
|
||||||
{
|
|
||||||
if (symbols.loop1.value <= 127)
|
if (symbols.loop1.value <= 127)
|
||||||
addLoader("loop1_set_count.b");
|
addLoader("loop1_set_count.b");
|
||||||
else if (symbols.loop1.value <= 65535)
|
else if (symbols.loop1.value <= 65535)
|
||||||
@ -151,8 +127,7 @@ void PackTos::buildLoader(const Filter *ft)
|
|||||||
else
|
else
|
||||||
throwBadLoader();
|
throwBadLoader();
|
||||||
}
|
}
|
||||||
if (symbols.loop2.count)
|
if (symbols.loop2.count) {
|
||||||
{
|
|
||||||
assert(symbols.loop2.mode == symbols.LOOP_DBRA);
|
assert(symbols.loop2.mode == symbols.LOOP_DBRA);
|
||||||
addLoader(opt->small ? "loop2.small" : "loop2.fast");
|
addLoader(opt->small ? "loop2.small" : "loop2.fast");
|
||||||
}
|
}
|
||||||
@ -222,8 +197,7 @@ void PackTos::buildLoader(const Filter *ft)
|
|||||||
addLoader("__mulsi3");
|
addLoader("__mulsi3");
|
||||||
addLoader(opt->small ? "lzma.small" : "lzma.fast");
|
addLoader(opt->small ? "lzma.small" : "lzma.fast");
|
||||||
addLoader("lzma.finish");
|
addLoader("lzma.finish");
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
throwBadLoader();
|
throwBadLoader();
|
||||||
|
|
||||||
if (symbols.need_reloc)
|
if (symbols.need_reloc)
|
||||||
@ -240,41 +214,40 @@ void PackTos::buildLoader(const Filter *ft)
|
|||||||
addLoader("jmp_stack");
|
addLoader("jmp_stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
/* flags for curproc->memflags */
|
/* flags for curproc->memflags */
|
||||||
/* also used for program headers fh_flag */
|
/* also used for program headers fh_flag */
|
||||||
#define F_FASTLOAD 0x01 // don't zero heap
|
#define F_FASTLOAD 0x01 // don't zero heap
|
||||||
#define F_ALTLOAD 0x02 // OK to load in alternate ram
|
#define F_ALTLOAD 0x02 // OK to load in alternate ram
|
||||||
#define F_ALTALLOC 0x04 // OK to malloc from alt. ram
|
#define F_ALTALLOC 0x04 // OK to malloc from alt. ram
|
||||||
#define F_SMALLTPA 0x08 // used in MagiC: TPA can be allocated
|
#define F_SMALLTPA \
|
||||||
// as specified in the program header
|
0x08 // used in MagiC: TPA can be allocated
|
||||||
// rather than the biggest free memory
|
// as specified in the program header
|
||||||
// block
|
// rather than the biggest free memory
|
||||||
#define F_MEMFLAGS 0xf0 // reserved for future use
|
// block
|
||||||
#define F_SHTEXT 0x800 // program's text may be shared
|
#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" */
|
/* 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. */
|
/* 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) */
|
/* (Actually, when users call Mxalloc, they add 0x10 to what you see here) */
|
||||||
#define F_PROTMODE 0xf0 // protection mode bits
|
#define F_PROTMODE 0xf0 // protection mode bits
|
||||||
#define F_PROT_P 0x00 // no read or write
|
#define F_PROT_P 0x00 // no read or write
|
||||||
#define F_PROT_G 0x10 // any access OK
|
#define F_PROT_G 0x10 // any access OK
|
||||||
#define F_PROT_S 0x20 // any super access OK
|
#define F_PROT_S 0x20 // any super access OK
|
||||||
#define F_PROT_PR 0x30 // any read OK, no write
|
#define F_PROT_PR 0x30 // any read OK, no write
|
||||||
#define F_PROT_I 0x40 // invalid page
|
#define F_PROT_I 0x40 // invalid page
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
@ -282,9 +255,8 @@ void PackTos::buildLoader(const Filter *ft)
|
|||||||
// checkFileHeader() checks ih for legal but unsupported values
|
// checkFileHeader() checks ih for legal but unsupported values
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int PackTos::readFileHeader()
|
int PackTos::readFileHeader() {
|
||||||
{
|
fi->seek(0, SEEK_SET);
|
||||||
fi->seek(0,SEEK_SET);
|
|
||||||
fi->readx(&ih, FH_SIZE);
|
fi->readx(&ih, FH_SIZE);
|
||||||
if (ih.fh_magic != 0x601a)
|
if (ih.fh_magic != 0x601a)
|
||||||
return 0;
|
return 0;
|
||||||
@ -293,31 +265,27 @@ int PackTos::readFileHeader()
|
|||||||
return UPX_F_ATARI_TOS;
|
return UPX_F_ATARI_TOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PackTos::checkFileHeader() {
|
||||||
bool PackTos::checkFileHeader()
|
|
||||||
{
|
|
||||||
const unsigned f = ih.fh_flag;
|
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))
|
if ((ih.fh_text & 1) || (ih.fh_data & 1))
|
||||||
throwCantPack("odd size values in text/data");
|
throwCantPack("odd size values in text/data");
|
||||||
if (f & F_OS_SPECIAL)
|
if (f & F_OS_SPECIAL)
|
||||||
throwCantPack("I won't pack F_OS_SPECIAL programs");
|
throwCantPack("I won't pack F_OS_SPECIAL programs");
|
||||||
if ((f & F_PROTMODE) > F_PROT_I)
|
if ((f & F_PROTMODE) > F_PROT_I)
|
||||||
throwCantPack("invalid protection mode");
|
throwCantPack("invalid protection mode");
|
||||||
if ((f & F_PROTMODE) != F_PROT_P)
|
if ((f & F_PROTMODE) != F_PROT_P) {
|
||||||
{
|
|
||||||
if (opt->force < 1)
|
if (opt->force < 1)
|
||||||
throwCantPack("no private memory protection; use option '-f' to force packing");
|
throwCantPack("no private memory protection; use option '-f' to force packing");
|
||||||
}
|
}
|
||||||
if (f & F_SHTEXT)
|
if (f & F_SHTEXT) {
|
||||||
{
|
|
||||||
if (opt->force < 1)
|
if (opt->force < 1)
|
||||||
throwCantPack("shared text segment; use option '-f' to force packing");
|
throwCantPack("shared text segment; use option '-f' to force packing");
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
// fh_reserved seems to be unused
|
// fh_reserved seems to be unused
|
||||||
if (ih.fh_reserved != 0)
|
if (ih.fh_reserved != 0) {
|
||||||
{
|
|
||||||
if (opt->force < 1)
|
if (opt->force < 1)
|
||||||
throwCantPack("reserved header field set; use option '-f' to force packing");
|
throwCantPack("reserved header field set; use option '-f' to force packing");
|
||||||
}
|
}
|
||||||
@ -325,15 +293,13 @@ bool PackTos::checkFileHeader()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// relocs
|
// relocs
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
// Check relocation for errors to make sure our loader can handle it.
|
// Check relocation for errors to make sure our loader can handle it.
|
||||||
static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
|
static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize, unsigned *nrelocs,
|
||||||
unsigned *nrelocs, unsigned *relocsize, unsigned *overlay)
|
unsigned *relocsize, unsigned *overlay) {
|
||||||
{
|
|
||||||
unsigned fixup = get_be32(relocs);
|
unsigned fixup = get_be32(relocs);
|
||||||
unsigned last_fixup = fixup;
|
unsigned last_fixup = fixup;
|
||||||
unsigned i = 4;
|
unsigned i = 4;
|
||||||
@ -342,25 +308,24 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
|
|||||||
assert(fixup > 0);
|
assert(fixup > 0);
|
||||||
|
|
||||||
*nrelocs = 1;
|
*nrelocs = 1;
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
if (fixup & 1) // must be word-aligned
|
||||||
if (fixup & 1) // must be word-aligned
|
|
||||||
return -1;
|
return -1;
|
||||||
if (fixup + 4 > isize) // too far
|
if (fixup + 4 > isize) // too far
|
||||||
return -1;
|
return -1;
|
||||||
if (i >= rsize) // premature EOF in relocs
|
if (i >= rsize) // premature EOF in relocs
|
||||||
return -1;
|
return -1;
|
||||||
unsigned c = relocs[i++];
|
unsigned c = relocs[i++];
|
||||||
if (c == 0) // end marker
|
if (c == 0) // end marker
|
||||||
break;
|
break;
|
||||||
else if (c == 1) // increase fixup, no reloc
|
else if (c == 1) // increase fixup, no reloc
|
||||||
fixup += 254;
|
fixup += 254;
|
||||||
else if (c & 1) // must be word-aligned
|
else if (c & 1) // must be word-aligned
|
||||||
return -1;
|
return -1;
|
||||||
else // next reloc is here
|
else // next reloc is here
|
||||||
{
|
{
|
||||||
fixup += c;
|
fixup += c;
|
||||||
if (fixup - last_fixup < 4) // overlapping relocation
|
if (fixup - last_fixup < 4) // overlapping relocation
|
||||||
return -1;
|
return -1;
|
||||||
last_fixup = fixup;
|
last_fixup = fixup;
|
||||||
*nrelocs += 1;
|
*nrelocs += 1;
|
||||||
@ -372,13 +337,11 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool PackTos::canPack()
|
bool PackTos::canPack() {
|
||||||
{
|
|
||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -394,22 +357,18 @@ bool PackTos::canPack()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PackTos::fileInfo() {
|
||||||
void PackTos::fileInfo()
|
|
||||||
{
|
|
||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return;
|
return;
|
||||||
con_fprintf(stdout, " text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
|
con_fprintf(stdout, " text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n", (int) ih.fh_text,
|
||||||
(int)ih.fh_text, (int)ih.fh_data, (int)ih.fh_sym, (int)ih.fh_bss, (int)ih.fh_flag);
|
(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 t;
|
||||||
unsigned nrelocs = 0;
|
unsigned nrelocs = 0;
|
||||||
unsigned relocsize = 0;
|
unsigned relocsize = 0;
|
||||||
@ -437,14 +396,14 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
fi->seek(FH_SIZE, SEEK_SET);
|
fi->seek(FH_SIZE, SEEK_SET);
|
||||||
// read text + data
|
// read text + data
|
||||||
t = i_text + i_data;
|
t = i_text + i_data;
|
||||||
fi->readx(ibuf,t);
|
fi->readx(ibuf, t);
|
||||||
// skip symbols
|
// skip symbols
|
||||||
if (i_sym && opt->exact)
|
if (i_sym && opt->exact)
|
||||||
throwCantPackExact();
|
throwCantPackExact();
|
||||||
fi->seek(i_sym,SEEK_CUR);
|
fi->seek(i_sym, SEEK_CUR);
|
||||||
// read relocations + overlay
|
// read relocations + overlay
|
||||||
overlay = file_size - (FH_SIZE + i_text + i_data + i_sym);
|
overlay = file_size - (FH_SIZE + i_text + i_data + i_sym);
|
||||||
fi->readx(ibuf+t,overlay);
|
fi->readx(ibuf + t, overlay);
|
||||||
|
|
||||||
#if 0 || (TESTING)
|
#if 0 || (TESTING)
|
||||||
printf("text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
|
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).
|
// Check relocs (see load_and_reloc() in freemint/sys/memory.c).
|
||||||
// Must work around TOS bugs and lots of broken programs.
|
// 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
|
// Bug workaround: Whatever this is, silently keep it in
|
||||||
// the (unused) relocations for byte-identical unpacking.
|
// the (unused) relocations for byte-identical unpacking.
|
||||||
relocsize = overlay;
|
relocsize = overlay;
|
||||||
overlay = 0;
|
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.
|
// Bug workaround - check the empty fixup before testing fh_reloc.
|
||||||
relocsize = 4;
|
relocsize = 4;
|
||||||
overlay -= 4;
|
overlay -= 4;
|
||||||
}
|
} else if (ih.fh_reloc != 0)
|
||||||
else if (ih.fh_reloc != 0)
|
|
||||||
relocsize = 0;
|
relocsize = 0;
|
||||||
else {
|
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)
|
if (r != 0)
|
||||||
throwCantPack("bad relocation table");
|
throwCantPack("bad relocation table");
|
||||||
symbols.need_reloc = true;
|
symbols.need_reloc = true;
|
||||||
@ -484,8 +439,8 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// Append original fileheader.
|
// Append original fileheader.
|
||||||
t += relocsize;
|
t += relocsize;
|
||||||
ih.fh_sym = 0; // we stripped all symbols
|
ih.fh_sym = 0; // we stripped all symbols
|
||||||
memcpy(ibuf+t, &ih, FH_SIZE);
|
memcpy(ibuf + t, &ih, FH_SIZE);
|
||||||
t += FH_SIZE;
|
t += FH_SIZE;
|
||||||
#if 0 || (TESTING)
|
#if 0 || (TESTING)
|
||||||
printf("xx3 reloc: %d, overlay: %d, t: %d\n", relocsize, overlay, t);
|
printf("xx3 reloc: %d, overlay: %d, t: %d\n", relocsize, overlay, t);
|
||||||
@ -505,7 +460,8 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
// prepare filter
|
// prepare filter
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
// compress (max_match = 65535)
|
// 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_ucl.max_match = 65535;
|
||||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||||
compressWithFilters(&ft, 512, &cconf);
|
compressWithFilters(&ft, 512, &cconf);
|
||||||
@ -522,8 +478,7 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
unsigned o_text, o_data, o_bss;
|
unsigned o_text, o_data, o_bss;
|
||||||
unsigned e_len, d_len, d_off;
|
unsigned e_len, d_len, d_off;
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// The decompressed data will now get placed at this offset:
|
// The decompressed data will now get placed at this offset:
|
||||||
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
||||||
|
|
||||||
@ -539,8 +494,7 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
o_bss = i_bss;
|
o_bss = i_bss;
|
||||||
|
|
||||||
// word align len of compressed data
|
// word align len of compressed data
|
||||||
while (o_data & 1)
|
while (o_data & 1) {
|
||||||
{
|
|
||||||
obuf[o_data++] = 0;
|
obuf[o_data++] = 0;
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
@ -551,8 +505,7 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
o_data += d_len;
|
o_data += d_len;
|
||||||
|
|
||||||
// dword align the len of the final data segment
|
// dword align the len of the final data segment
|
||||||
while (o_data & 3)
|
while (o_data & 3) {
|
||||||
{
|
|
||||||
obuf[o_data++] = 0;
|
obuf[o_data++] = 0;
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
@ -566,7 +519,7 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// dirty bss
|
// dirty bss
|
||||||
unsigned dirty_bss = (o_data + offset) - (i_text + i_data);
|
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)
|
// dword align (or 16 - for speedup when clearing the dirty bss)
|
||||||
const unsigned dirty_bss_align = opt->small ? 4 : 16;
|
const unsigned dirty_bss_align = opt->small ? 4 : 16;
|
||||||
while (dirty_bss & (dirty_bss_align - 1))
|
while (dirty_bss & (dirty_bss_align - 1))
|
||||||
@ -581,13 +534,10 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
o_bss++;
|
o_bss++;
|
||||||
|
|
||||||
// update symbols for buildLoader()
|
// update symbols for buildLoader()
|
||||||
if (opt->small)
|
if (opt->small) {
|
||||||
{
|
|
||||||
symbols.loop1.init(o_data / 4);
|
symbols.loop1.init(o_data / 4);
|
||||||
symbols.loop2.init(0);
|
symbols.loop2.init(0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
symbols.loop1.init(o_data / 160);
|
symbols.loop1.init(o_data / 160);
|
||||||
symbols.loop2.init((o_data % 160) / 4);
|
symbols.loop2.init((o_data % 160) / 4);
|
||||||
}
|
}
|
||||||
@ -597,8 +547,8 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
symbols.up31_base_d4 = d_off + offset;
|
symbols.up31_base_d4 = d_off + offset;
|
||||||
symbols.up21_a6 = symbols.up21_d4 - (i_text + i_data);
|
symbols.up21_a6 = symbols.up21_d4 - (i_text + i_data);
|
||||||
symbols.up31_base_a6 = symbols.up31_base_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.up21_a6 > 0);
|
||||||
assert((int)symbols.up31_base_a6 > 0);
|
assert((int) symbols.up31_base_a6 > 0);
|
||||||
|
|
||||||
const unsigned c = linker->getSymbolOffset("code_on_stack");
|
const unsigned c = linker->getSymbolOffset("code_on_stack");
|
||||||
unsigned d;
|
unsigned d;
|
||||||
@ -612,7 +562,7 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
// now re-build loader
|
// now re-build loader
|
||||||
buildLoader(&ft);
|
buildLoader(&ft);
|
||||||
unsigned new_lsize = getLoaderSize();
|
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);
|
assert(new_lsize <= initial_lsize);
|
||||||
if (new_lsize == last_lsize && memcmp(getLoader(), last_loader, last_lsize) == 0)
|
if (new_lsize == last_lsize && memcmp(getLoader(), last_loader, last_lsize) == 0)
|
||||||
break;
|
break;
|
||||||
@ -667,13 +617,10 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// set new file_hdr
|
// set new file_hdr
|
||||||
memcpy(&oh, &ih, FH_SIZE);
|
memcpy(&oh, &ih, FH_SIZE);
|
||||||
if (opt->atari_tos.split_segments)
|
if (opt->atari_tos.split_segments) {
|
||||||
{
|
|
||||||
oh.fh_text = o_text;
|
oh.fh_text = o_text;
|
||||||
oh.fh_data = o_data;
|
oh.fh_data = o_data;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// put everything into the text segment
|
// put everything into the text segment
|
||||||
oh.fh_text = o_text + o_data;
|
oh.fh_text = o_text + o_data;
|
||||||
oh.fh_data = 0;
|
oh.fh_data = 0;
|
||||||
@ -701,11 +648,11 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// write new file header, loader and compressed file
|
// write new file header, loader and compressed file
|
||||||
fo->write(&oh, FH_SIZE);
|
fo->write(&oh, FH_SIZE);
|
||||||
fo->write(loader, o_text); // entry
|
fo->write(loader, o_text); // entry
|
||||||
if (opt->debug.dump_stub_loader)
|
if (opt->debug.dump_stub_loader)
|
||||||
OutputFile::dump(opt->debug.dump_stub_loader, loader, o_text);
|
OutputFile::dump(opt->debug.dump_stub_loader, loader, o_text);
|
||||||
memcpy(obuf + d_off, getLoader() + e_len, d_len); // copy decompressor
|
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
|
// write empty relocation fixup
|
||||||
fo->write("\x00\x00\x00\x00", 4);
|
fo->write("\x00\x00\x00\x00", 4);
|
||||||
@ -721,20 +668,18 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
throwNotCompressible();
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int PackTos::canUnpack()
|
int PackTos::canUnpack() {
|
||||||
{
|
|
||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
if (!readPackHeader(768))
|
if (!readPackHeader(768))
|
||||||
return false;
|
return false;
|
||||||
// check header as set by packer
|
// check header as set by packer
|
||||||
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0
|
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0 || ih.fh_sym != 0 ||
|
||||||
|| ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1)
|
ih.fh_reserved != 0 || ih.fh_reloc > 1)
|
||||||
throwCantUnpack("program header damaged");
|
throwCantUnpack("program header damaged");
|
||||||
// generic check
|
// generic check
|
||||||
if (!checkFileHeader())
|
if (!checkFileHeader())
|
||||||
@ -742,13 +687,11 @@ int PackTos::canUnpack()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void PackTos::unpack(OutputFile *fo)
|
void PackTos::unpack(OutputFile *fo) {
|
||||||
{
|
|
||||||
ibuf.alloc(ph.c_len);
|
ibuf.alloc(ph.c_len);
|
||||||
obuf.allocForUncompression(ph.u_len);
|
obuf.allocForUncompression(ph.u_len);
|
||||||
|
|
||||||
@ -756,18 +699,17 @@ void PackTos::unpack(OutputFile *fo)
|
|||||||
fi->readx(ibuf, ph.c_len);
|
fi->readx(ibuf, ph.c_len);
|
||||||
|
|
||||||
// decompress
|
// decompress
|
||||||
decompress(ibuf,obuf);
|
decompress(ibuf, obuf);
|
||||||
|
|
||||||
// write original header & decompressed file
|
// write original header & decompressed file
|
||||||
if (fo)
|
if (fo) {
|
||||||
{
|
|
||||||
unsigned overlay = file_size - (FH_SIZE + ih.fh_text + ih.fh_data);
|
unsigned overlay = file_size - (FH_SIZE + ih.fh_text + ih.fh_data);
|
||||||
if (ih.fh_reloc == 0 && overlay >= 4)
|
if (ih.fh_reloc == 0 && overlay >= 4)
|
||||||
overlay -= 4; // this is our empty fixup
|
overlay -= 4; // this is our empty fixup
|
||||||
checkOverlay(overlay);
|
checkOverlay(overlay);
|
||||||
|
|
||||||
fo->write(obuf+ph.u_len-FH_SIZE, FH_SIZE); // orig. file_hdr
|
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); // orig. text+data+relocs
|
||||||
|
|
||||||
// copy any overlay
|
// copy any overlay
|
||||||
copyOverlay(fo, overlay, &obuf);
|
copyOverlay(fo, overlay, &obuf);
|
||||||
|
|||||||
22
src/p_tos.h
22
src/p_tos.h
@ -25,18 +25,16 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __UPX_P_TOS_H
|
#ifndef __UPX_P_TOS_H
|
||||||
#define __UPX_P_TOS_H 1
|
#define __UPX_P_TOS_H 1
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// atari/tos
|
// atari/tos
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class PackTos : public Packer
|
class PackTos : public Packer {
|
||||||
{
|
|
||||||
typedef Packer super;
|
typedef Packer super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PackTos(InputFile *f);
|
PackTos(InputFile *f);
|
||||||
virtual int getVersion() const { return 13; }
|
virtual int getVersion() const { return 13; }
|
||||||
@ -55,14 +53,14 @@ public:
|
|||||||
virtual void fileInfo();
|
virtual void fileInfo();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Linker* newLinker() const;
|
virtual Linker *newLinker() const;
|
||||||
virtual void buildLoader(const Filter *ft);
|
virtual void buildLoader(const Filter *ft);
|
||||||
unsigned getDecomprOffset(int method, int small) const;
|
unsigned getDecomprOffset(int method, int small) const;
|
||||||
|
|
||||||
virtual int readFileHeader();
|
virtual int readFileHeader();
|
||||||
virtual bool checkFileHeader();
|
virtual bool checkFileHeader();
|
||||||
|
|
||||||
__packed_struct(tos_header_t)
|
struct alignas(1) tos_header_t {
|
||||||
BE16 fh_magic;
|
BE16 fh_magic;
|
||||||
BE32 fh_text;
|
BE32 fh_text;
|
||||||
BE32 fh_data;
|
BE32 fh_data;
|
||||||
@ -71,17 +69,18 @@ protected:
|
|||||||
BE32 fh_reserved;
|
BE32 fh_reserved;
|
||||||
BE32 fh_flag;
|
BE32 fh_flag;
|
||||||
BE16 fh_reloc;
|
BE16 fh_reloc;
|
||||||
__packed_struct_end()
|
};
|
||||||
|
|
||||||
tos_header_t ih, oh;
|
tos_header_t ih, oh;
|
||||||
|
|
||||||
// symbols for buildLoader()
|
// symbols for buildLoader()
|
||||||
struct LinkerSymbols
|
struct LinkerSymbols {
|
||||||
{
|
|
||||||
enum { LOOP_NONE, LOOP_SUBQ_L, LOOP_SUBQ_W, LOOP_DBRA };
|
enum { LOOP_NONE, LOOP_SUBQ_L, LOOP_SUBQ_W, LOOP_DBRA };
|
||||||
struct LoopInfo {
|
struct LoopInfo {
|
||||||
unsigned mode; unsigned count; unsigned value;
|
unsigned mode;
|
||||||
void init(unsigned count, bool allow_dbra=true);
|
unsigned count;
|
||||||
|
unsigned value;
|
||||||
|
void init(unsigned count, bool allow_dbra = true);
|
||||||
};
|
};
|
||||||
// buildLoader() input
|
// buildLoader() input
|
||||||
bool need_reloc;
|
bool need_reloc;
|
||||||
@ -105,7 +104,6 @@ protected:
|
|||||||
LinkerSymbols symbols;
|
LinkerSymbols symbols;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
756
src/packer.cpp
756
src/packer.cpp
File diff suppressed because it is too large
Load Diff
168
src/packer.h
168
src/packer.h
@ -25,7 +25,6 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __UPX_PACKER_H
|
#ifndef __UPX_PACKER_H
|
||||||
#define __UPX_PACKER_H 1
|
#define __UPX_PACKER_H 1
|
||||||
|
|
||||||
@ -38,14 +37,12 @@ class PackMaster;
|
|||||||
class UiPacker;
|
class UiPacker;
|
||||||
class Filter;
|
class Filter;
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
// see stub/src/include/header.S
|
// see stub/src/include/header.S
|
||||||
class PackHeader
|
class PackHeader {
|
||||||
{
|
|
||||||
friend class Packer;
|
friend class Packer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -60,11 +57,11 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// fields stored in compressed file
|
// fields stored in compressed file
|
||||||
//enum { magic = UPX_MAGIC_LE32 };
|
// enum { magic = UPX_MAGIC_LE32 };
|
||||||
int version;
|
int version;
|
||||||
int format; // executable format
|
int format; // executable format
|
||||||
int method; // compresison method
|
int method; // compresison method
|
||||||
int level; // compresison level 1..10
|
int level; // compresison level 1..10
|
||||||
unsigned u_len;
|
unsigned u_len;
|
||||||
unsigned c_len;
|
unsigned c_len;
|
||||||
unsigned u_adler;
|
unsigned u_adler;
|
||||||
@ -72,7 +69,7 @@ public:
|
|||||||
off_t u_file_size;
|
off_t u_file_size;
|
||||||
int filter;
|
int filter;
|
||||||
int filter_cto;
|
int filter_cto;
|
||||||
int n_mru; // FIXME: rename to filter_misc
|
int n_mru; // FIXME: rename to filter_misc
|
||||||
int header_checksum;
|
int header_checksum;
|
||||||
|
|
||||||
// support fields for verifying decompression
|
// support fields for verifying decompression
|
||||||
@ -84,39 +81,38 @@ public:
|
|||||||
|
|
||||||
// info fields set by Packer::compress()
|
// info fields set by Packer::compress()
|
||||||
upx_compress_result_t compress_result;
|
upx_compress_result_t compress_result;
|
||||||
//unsigned min_offset_found;
|
// unsigned min_offset_found;
|
||||||
unsigned max_offset_found;
|
unsigned max_offset_found;
|
||||||
//unsigned min_match_found;
|
// unsigned min_match_found;
|
||||||
unsigned max_match_found;
|
unsigned max_match_found;
|
||||||
//unsigned min_run_found;
|
// unsigned min_run_found;
|
||||||
unsigned max_run_found;
|
unsigned max_run_found;
|
||||||
unsigned first_offset_found;
|
unsigned first_offset_found;
|
||||||
//unsigned same_match_offsets_found;
|
// unsigned same_match_offsets_found;
|
||||||
|
|
||||||
// info fields set by Packer::compressWithFilters()
|
// info fields set by Packer::compressWithFilters()
|
||||||
unsigned overlap_overhead;
|
unsigned overlap_overhead;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool ph_skipVerify(const PackHeader &ph);
|
bool ph_skipVerify(const PackHeader &ph);
|
||||||
void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out,
|
void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out, bool verify_checksum,
|
||||||
bool verify_checksum, Filter *ft);
|
Filter *ft);
|
||||||
bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_bytep buf,
|
bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_bytep buf,
|
||||||
unsigned overlap_overhead);
|
unsigned overlap_overhead);
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// abstract base class for packers
|
// abstract base class for packers
|
||||||
//
|
//
|
||||||
// FIXME: this class is way too fat and badly needs a decomposition
|
// FIXME: this class is way too fat and badly needs a decomposition
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
class Packer
|
class Packer {
|
||||||
{
|
// friend class PackMaster;
|
||||||
//friend class PackMaster;
|
|
||||||
friend class UiPacker;
|
friend class UiPacker;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Packer(InputFile *f);
|
Packer(InputFile *f);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Packer();
|
virtual ~Packer();
|
||||||
virtual void assertPacker() const;
|
virtual void assertPacker() const;
|
||||||
@ -139,10 +135,8 @@ public:
|
|||||||
void doFileInfo();
|
void doFileInfo();
|
||||||
|
|
||||||
// unpacker capabilities
|
// unpacker capabilities
|
||||||
virtual bool canUnpackVersion(int version) const
|
virtual bool canUnpackVersion(int version) const { return (version >= 8); }
|
||||||
{ return (version >= 8); }
|
virtual bool canUnpackFormat(int format) const { return (format == getFormat()); }
|
||||||
virtual bool canUnpackFormat(int format) const
|
|
||||||
{ return (format == getFormat()); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// unpacker tests - these may throw exceptions
|
// unpacker tests - these may throw exceptions
|
||||||
@ -171,72 +165,63 @@ protected:
|
|||||||
// main compression drivers
|
// main compression drivers
|
||||||
virtual bool compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr,
|
virtual bool compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr,
|
||||||
const upx_compress_config_t *cconf = nullptr);
|
const upx_compress_config_t *cconf = nullptr);
|
||||||
virtual void decompress(const upx_bytep in, upx_bytep out,
|
virtual void decompress(const upx_bytep in, upx_bytep out, bool verify_checksum = true,
|
||||||
bool verify_checksum = true, Filter *ft = nullptr);
|
Filter *ft = nullptr);
|
||||||
virtual bool checkDefaultCompressionRatio(unsigned u_len, unsigned c_len) const;
|
virtual bool checkDefaultCompressionRatio(unsigned u_len, unsigned c_len) const;
|
||||||
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
|
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
|
||||||
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
|
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
|
||||||
|
|
||||||
// high-level compression drivers
|
// high-level compression drivers
|
||||||
void compressWithFilters(Filter *ft,
|
void compressWithFilters(Filter *ft, const unsigned overlap_range,
|
||||||
const unsigned overlap_range,
|
const upx_compress_config_t *cconf, int filter_strategy = 0,
|
||||||
const upx_compress_config_t *cconf,
|
|
||||||
int filter_strategy = 0,
|
|
||||||
bool inhibit_compression_check = false);
|
bool inhibit_compression_check = false);
|
||||||
void compressWithFilters(Filter *ft,
|
void compressWithFilters(Filter *ft, const unsigned overlap_range,
|
||||||
const unsigned overlap_range,
|
const upx_compress_config_t *cconf, int filter_strategy,
|
||||||
const upx_compress_config_t *cconf,
|
unsigned filter_buf_off, unsigned compress_ibuf_off,
|
||||||
int filter_strategy,
|
unsigned compress_obuf_off, const upx_bytep hdr_ptr, unsigned hdr_len,
|
||||||
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);
|
bool inhibit_compression_check = false);
|
||||||
// real compression driver
|
// real compression driver
|
||||||
void compressWithFilters(upx_bytep i_ptr, unsigned i_len,
|
void compressWithFilters(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr, upx_bytep f_ptr,
|
||||||
upx_bytep o_ptr,
|
unsigned f_len, const upx_bytep hdr_ptr, unsigned hdr_len, Filter *ft,
|
||||||
upx_bytep f_ptr, unsigned f_len,
|
const unsigned overlap_range, const upx_compress_config_t *cconf,
|
||||||
const upx_bytep hdr_ptr, unsigned hdr_len,
|
int filter_strategy, bool inhibit_compression_check = false);
|
||||||
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
|
// util for verifying overlapping decompresion
|
||||||
// non-destructive test
|
// non-destructive test
|
||||||
virtual bool testOverlappingDecompression(const upx_bytep buf,
|
virtual bool testOverlappingDecompression(const upx_bytep buf, const upx_bytep tbuf,
|
||||||
const upx_bytep tbuf,
|
|
||||||
unsigned overlap_overhead) const;
|
unsigned overlap_overhead) const;
|
||||||
// non-destructive find
|
// non-destructive find
|
||||||
virtual unsigned findOverlapOverhead(const upx_bytep buf,
|
virtual unsigned findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf,
|
||||||
const upx_bytep tbuf,
|
unsigned range = 0, unsigned upper_limit = ~0u) const;
|
||||||
unsigned range = 0,
|
|
||||||
unsigned upper_limit = ~0u) const;
|
|
||||||
// destructive decompress + verify
|
// destructive decompress + verify
|
||||||
void verifyOverlappingDecompression(Filter *ft = nullptr);
|
void verifyOverlappingDecompression(Filter *ft = nullptr);
|
||||||
void verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Filter *ft = nullptr);
|
void verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Filter *ft = nullptr);
|
||||||
|
|
||||||
// packheader handling
|
// packheader handling
|
||||||
virtual int patchPackHeader(void *b, int blen);
|
virtual int patchPackHeader(void *b, int blen);
|
||||||
virtual bool getPackHeader(void *b, int blen, 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 bool readPackHeader(int len, bool allow_incompressible = false);
|
||||||
virtual void checkAlreadyPacked(const void *b, int blen);
|
virtual void checkAlreadyPacked(const void *b, int blen);
|
||||||
|
|
||||||
// loader core
|
// loader core
|
||||||
virtual void buildLoader(const Filter *ft) = 0;
|
virtual void buildLoader(const Filter *ft) = 0;
|
||||||
virtual Linker* newLinker() const = 0;
|
virtual Linker *newLinker() const = 0;
|
||||||
virtual void relocateLoader();
|
virtual void relocateLoader();
|
||||||
// loader util for linker
|
// loader util for linker
|
||||||
virtual upx_byte *getLoader() const;
|
virtual upx_byte *getLoader() const;
|
||||||
virtual int getLoaderSize() 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 *
|
#define C const char *
|
||||||
void addLoader(C); void addLoader(C,C); void addLoader(C,C,C);
|
void addLoader(C);
|
||||||
void addLoader(C,C,C,C); void addLoader(C,C,C,C,C);
|
void addLoader(C, C);
|
||||||
void addLoader(C,C,C,C,C,C); void addLoader(C,C,C,C,C,C,C);
|
void addLoader(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);
|
||||||
void addLoader(C,C,C,C,C,C,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
|
#undef C
|
||||||
#if 1 && (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x040100))
|
#if 1 && (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x040100))
|
||||||
void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__));
|
void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__));
|
||||||
@ -244,72 +229,76 @@ protected:
|
|||||||
void __acc_cdecl_va addLoaderVA(const char *s, ...);
|
void __acc_cdecl_va addLoaderVA(const char *s, ...);
|
||||||
#endif
|
#endif
|
||||||
virtual bool hasLoaderSection(const char *name) const;
|
virtual bool hasLoaderSection(const char *name) const;
|
||||||
virtual int getLoaderSection(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;
|
virtual int getLoaderSectionStart(const char *name, int *slen = nullptr) const;
|
||||||
|
|
||||||
// compression handling [see packer_c.cpp]
|
// compression handling [see packer_c.cpp]
|
||||||
public:
|
public:
|
||||||
static bool isValidCompressionMethod(int method);
|
static bool isValidCompressionMethod(int method);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const int *getDefaultCompressionMethods_8(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;
|
const int *getDefaultCompressionMethods_le32(int method, int level, int small = -1) const;
|
||||||
virtual const char *getDecompressorSections() const;
|
virtual const char *getDecompressorSections() const;
|
||||||
virtual unsigned getDecompressorWrkmemSize() const;
|
virtual unsigned getDecompressorWrkmemSize() const;
|
||||||
virtual void defineDecompressorSymbols();
|
virtual void defineDecompressorSymbols();
|
||||||
|
|
||||||
// filter handling [see packer_f.cpp]
|
// filter handling [see packer_f.cpp]
|
||||||
virtual bool isValidFilter(int filter_id) const;
|
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 addFilter32(int filter_id);
|
||||||
virtual void defineFilterSymbols(const Filter *ft);
|
virtual void defineFilterSymbols(const Filter *ft);
|
||||||
|
|
||||||
// stub and overlay util
|
// stub and overlay util
|
||||||
static void handleStub(InputFile *fi, OutputFile *fo, unsigned size);
|
static void handleStub(InputFile *fi, OutputFile *fo, unsigned size);
|
||||||
virtual void checkOverlay(unsigned overlay);
|
virtual void checkOverlay(unsigned overlay);
|
||||||
virtual void copyOverlay(OutputFile *fo, unsigned overlay,
|
virtual void copyOverlay(OutputFile *fo, unsigned overlay, MemBuffer *buf, bool do_seek = true);
|
||||||
MemBuffer *buf, bool do_seek=true);
|
|
||||||
|
|
||||||
// misc util
|
// misc util
|
||||||
virtual unsigned getRandomId() const;
|
virtual unsigned getRandomId() const;
|
||||||
|
|
||||||
// patch util
|
// patch util
|
||||||
int patch_be16(void *b, int blen, unsigned old, unsigned new_);
|
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, 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, 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, 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);
|
void checkPatch(void *b, int blen, int boff, int size);
|
||||||
|
|
||||||
// relocation util
|
// relocation util
|
||||||
static upx_byte *optimizeReloc(upx_byte *in,unsigned relocnum,upx_byte *out,upx_byte *image,int bs,int *big, int bits);
|
static upx_byte *optimizeReloc(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image,
|
||||||
static unsigned unoptimizeReloc(upx_byte **in,upx_byte *image,MemBuffer *out,int bs, int bits);
|
int bs, int *big, int bits);
|
||||||
static upx_byte *optimizeReloc32(upx_byte *in,unsigned relocnum,upx_byte *out,upx_byte *image,int bs,int *big);
|
static unsigned unoptimizeReloc(upx_byte **in, upx_byte *image, MemBuffer *out, int bs,
|
||||||
static unsigned unoptimizeReloc32(upx_byte **in,upx_byte *image,MemBuffer *out,int bs);
|
int bits);
|
||||||
static upx_byte *optimizeReloc64(upx_byte *in,unsigned relocnum,upx_byte *out,upx_byte *image,int bs,int *big);
|
static upx_byte *optimizeReloc32(upx_byte *in, unsigned relocnum, upx_byte *out,
|
||||||
static unsigned unoptimizeReloc64(upx_byte **in,upx_byte *image,MemBuffer *out,int bs);
|
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
|
// target endianness abstraction
|
||||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||||
unsigned get_te32(const void *p) const { return bele->get32(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); }
|
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_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
||||||
void set_te32(void *p, unsigned v) const { bele->set32(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); }
|
void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const N_BELE_RTP::AbstractPolicy *bele; // target endianness
|
const N_BELE_RTP::AbstractPolicy *bele; // target endianness
|
||||||
InputFile *fi;
|
InputFile *fi;
|
||||||
off_t file_size; // will get set by constructor
|
off_t file_size; // will get set by constructor
|
||||||
PackHeader ph; // must be filled by canUnpack()
|
PackHeader ph; // must be filled by canUnpack()
|
||||||
int ph_format;
|
int ph_format;
|
||||||
int ph_version;
|
int ph_version;
|
||||||
|
|
||||||
// compression buffers
|
// compression buffers
|
||||||
MemBuffer ibuf; // input
|
MemBuffer ibuf; // input
|
||||||
MemBuffer obuf; // output
|
MemBuffer obuf; // output
|
||||||
|
|
||||||
// UI handler
|
// UI handler
|
||||||
UiPacker *uip;
|
UiPacker *uip;
|
||||||
@ -326,10 +315,9 @@ private:
|
|||||||
private:
|
private:
|
||||||
// disable copy and assignment
|
// disable copy and assignment
|
||||||
Packer(const Packer &) = delete;
|
Packer(const Packer &) = delete;
|
||||||
Packer& operator= (const Packer &) = delete;
|
Packer &operator=(const Packer &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
## vim:set ts=4 sw=4 et:
|
## vim:set ts=4 sw=4 et:
|
||||||
set -e; set -o pipefail
|
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
|
# NOTE: we are using clang-format-10.0.1 from upx-stubtools
|
||||||
# see https://github.com/upx/upx-stubtools/releases
|
# see https://github.com/upx/upx-stubtools/releases
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user