Big re-sync with UPX 1.2 branch.
committer: mfx <mfx> 1026835258 +0000
This commit is contained in:
+51
-24
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2001 Laszlo Molnar
|
||||
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2002 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@cdata.tvnet.hu
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -34,18 +34,18 @@
|
||||
// access memory in BigEndian and LittleEndian byte order
|
||||
**************************************************************************/
|
||||
|
||||
inline unsigned short get_be16(const void *bb)
|
||||
inline unsigned get_be16(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
|
||||
const upx_bytep b = reinterpret_cast<const upx_bytep>(bb);
|
||||
unsigned v;
|
||||
v = (unsigned) b[1] << 0;
|
||||
v |= (unsigned) b[0] << 8;
|
||||
return (unsigned short) v;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_be16(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
|
||||
upx_bytep b = reinterpret_cast<upx_bytep>(bb);
|
||||
b[1] = (unsigned char) (v >> 0);
|
||||
b[0] = (unsigned char) (v >> 8);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ inline void set_be16(void *bb, unsigned v)
|
||||
|
||||
inline unsigned get_be32(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
|
||||
const upx_bytep b = reinterpret_cast<const upx_bytep>(bb);
|
||||
unsigned v;
|
||||
v = (unsigned) b[3] << 0;
|
||||
v |= (unsigned) b[2] << 8;
|
||||
@@ -64,7 +64,7 @@ inline unsigned get_be32(const void *bb)
|
||||
|
||||
inline void set_be32(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
|
||||
upx_bytep b = reinterpret_cast<upx_bytep>(bb);
|
||||
b[3] = (unsigned char) (v >> 0);
|
||||
b[2] = (unsigned char) (v >> 8);
|
||||
b[1] = (unsigned char) (v >> 16);
|
||||
@@ -72,9 +72,9 @@ inline void set_be32(void *bb, unsigned v)
|
||||
}
|
||||
|
||||
|
||||
inline unsigned short get_le16(const void *bb)
|
||||
inline unsigned get_le16(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
|
||||
const upx_bytep b = reinterpret_cast<const upx_bytep>(bb);
|
||||
unsigned v;
|
||||
#if defined(__i386__)
|
||||
v = * (const unsigned short *) b;
|
||||
@@ -82,12 +82,12 @@ inline unsigned short get_le16(const void *bb)
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
#endif
|
||||
return (unsigned short) v;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline void set_le16(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
|
||||
upx_bytep b = reinterpret_cast<upx_bytep>(bb);
|
||||
#if defined(__i386__)
|
||||
(* (unsigned short *) b) = (unsigned short) v;
|
||||
#else
|
||||
@@ -99,7 +99,7 @@ inline void set_le16(void *bb, unsigned v)
|
||||
|
||||
inline unsigned get_le24(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
|
||||
const upx_bytep b = reinterpret_cast<const upx_bytep>(bb);
|
||||
unsigned v;
|
||||
v = (unsigned) b[0] << 0;
|
||||
v |= (unsigned) b[1] << 8;
|
||||
@@ -109,7 +109,7 @@ inline unsigned get_le24(const void *bb)
|
||||
|
||||
inline void set_le24(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
|
||||
upx_bytep b = reinterpret_cast<upx_bytep>(bb);
|
||||
b[0] = (unsigned char) (v >> 0);
|
||||
b[1] = (unsigned char) (v >> 8);
|
||||
b[2] = (unsigned char) (v >> 16);
|
||||
@@ -118,7 +118,7 @@ inline void set_le24(void *bb, unsigned v)
|
||||
|
||||
inline unsigned get_le32(const void *bb)
|
||||
{
|
||||
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
|
||||
const upx_bytep b = reinterpret_cast<const upx_bytep>(bb);
|
||||
unsigned v;
|
||||
#if defined(__i386__)
|
||||
v = * (const unsigned *) b;
|
||||
@@ -133,7 +133,7 @@ inline unsigned get_le32(const void *bb)
|
||||
|
||||
inline void set_le32(void *bb, unsigned v)
|
||||
{
|
||||
upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
|
||||
upx_bytep b = reinterpret_cast<upx_bytep>(bb);
|
||||
#if defined(__i386__)
|
||||
(* (unsigned *) b) = v;
|
||||
#else
|
||||
@@ -163,7 +163,8 @@ public:
|
||||
BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_be16(d); }
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
class BE32
|
||||
@@ -180,7 +181,8 @@ public:
|
||||
BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_be32(d); }
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
class LE16
|
||||
@@ -197,7 +199,8 @@ public:
|
||||
LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_le16(d); }
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
class LE32
|
||||
@@ -214,7 +217,8 @@ public:
|
||||
LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; }
|
||||
|
||||
operator const unsigned () const { return get_le32(d); }
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -242,6 +246,27 @@ inline bool operator < (const LE32& v1, const LE32& v2)
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const BE16& v) { return ptr + (const unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const BE16& v) { return ptr - (const unsigned) v; }
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const BE32& v) { return ptr + (const unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const BE32& v) { return ptr - (const unsigned) v; }
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const LE16& v) { return ptr + (const unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const LE16& v) { return ptr - (const unsigned) v; }
|
||||
|
||||
template <class T>
|
||||
inline T* operator + (T* ptr, const LE32& v) { return ptr + (const unsigned) v; }
|
||||
template <class T>
|
||||
inline T* operator - (T* ptr, const LE32& v) { return ptr - (const unsigned) v; }
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
@@ -255,10 +280,12 @@ int le32_compare(const void *e1, const void *e2);
|
||||
|
||||
// just for testing...
|
||||
#if 0 && defined(__i386__) && defined(__GNUC__)
|
||||
typedef unsigned short LE16_unaligned __attribute__((aligned(1)));
|
||||
typedef unsigned int LE32_unaligned __attribute__((aligned(1)));
|
||||
# if (__GNUC_VERSION_HEX__ >= 0x030100)
|
||||
typedef unsigned short LE16_unaligned __attribute__((__packed__,__aligned__(1)));
|
||||
typedef unsigned int LE32_unaligned __attribute__((__packed__,__aligned__(1)));
|
||||
# define LE16 LE16_unaligned
|
||||
# define LE32 LE32_unaligned
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user