1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Removed the optional `off' parameter from the [gs]et_[bl]e{16,24,32} functions.

committer: mfx <mfx> 981982200 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2001-02-12 12:50:00 +00:00
parent 475326691d
commit 401567f852
4 changed files with 36 additions and 33 deletions

View File

@ -34,26 +34,26 @@
// access memory in BigEndian and LittleEndian byte order // access memory in BigEndian and LittleEndian byte order
**************************************************************************/ **************************************************************************/
inline unsigned short get_be16(const void *bb, int off=0) inline unsigned short get_be16(const void *bb)
{ {
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off; const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
unsigned v; unsigned v;
v = (unsigned) b[1] << 0; v = (unsigned) b[1] << 0;
v |= (unsigned) b[0] << 8; v |= (unsigned) b[0] << 8;
return (unsigned short) v; return (unsigned short) v;
} }
inline void set_be16(void *bb, unsigned v, int off=0) inline void set_be16(void *bb, unsigned v)
{ {
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off; upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
b[1] = (unsigned char) (v >> 0); b[1] = (unsigned char) (v >> 0);
b[0] = (unsigned char) (v >> 8); b[0] = (unsigned char) (v >> 8);
} }
inline unsigned get_be32(const void *bb, int off=0) inline unsigned get_be32(const void *bb)
{ {
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off; const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
unsigned v; unsigned v;
v = (unsigned) b[3] << 0; v = (unsigned) b[3] << 0;
v |= (unsigned) b[2] << 8; v |= (unsigned) b[2] << 8;
@ -62,9 +62,9 @@ inline unsigned get_be32(const void *bb, int off=0)
return v; return v;
} }
inline void set_be32(void *bb, unsigned v, int off=0) inline void set_be32(void *bb, unsigned v)
{ {
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off; upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
b[3] = (unsigned char) (v >> 0); b[3] = (unsigned char) (v >> 0);
b[2] = (unsigned char) (v >> 8); b[2] = (unsigned char) (v >> 8);
b[1] = (unsigned char) (v >> 16); b[1] = (unsigned char) (v >> 16);
@ -72,9 +72,9 @@ inline void set_be32(void *bb, unsigned v, int off=0)
} }
inline unsigned short get_le16(const void *bb, int off=0) inline unsigned short get_le16(const void *bb)
{ {
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off; const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
unsigned v; unsigned v;
#if defined(__i386__) #if defined(__i386__)
v = * (const unsigned short *) b; v = * (const unsigned short *) b;
@ -85,9 +85,9 @@ inline unsigned short get_le16(const void *bb, int off=0)
return (unsigned short) v; return (unsigned short) v;
} }
inline void set_le16(void *bb, unsigned v, int off=0) inline void set_le16(void *bb, unsigned v)
{ {
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off; upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
#if defined(__i386__) #if defined(__i386__)
(* (unsigned short *) b) = (unsigned short) v; (* (unsigned short *) b) = (unsigned short) v;
#else #else
@ -97,9 +97,9 @@ inline void set_le16(void *bb, unsigned v, int off=0)
} }
inline unsigned get_le24(const void *bb, int off=0) inline unsigned get_le24(const void *bb)
{ {
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off; const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
unsigned v; unsigned v;
v = (unsigned) b[0] << 0; v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8; v |= (unsigned) b[1] << 8;
@ -107,18 +107,18 @@ inline unsigned get_le24(const void *bb, int off=0)
return v; return v;
} }
inline void set_le24(void *bb, unsigned v, int off=0) inline void set_le24(void *bb, unsigned v)
{ {
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off; upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
b[0] = (unsigned char) (v >> 0); b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8); b[1] = (unsigned char) (v >> 8);
b[2] = (unsigned char) (v >> 16); b[2] = (unsigned char) (v >> 16);
} }
inline unsigned get_le32(const void *bb, int off=0) inline unsigned get_le32(const void *bb)
{ {
const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb) + off; const upx_bytep const b = reinterpret_cast<const upx_bytep>(bb);
unsigned v; unsigned v;
#if defined(__i386__) #if defined(__i386__)
v = * (const unsigned *) b; v = * (const unsigned *) b;
@ -131,9 +131,9 @@ inline unsigned get_le32(const void *bb, int off=0)
return v; return v;
} }
inline void set_le32(void *bb, unsigned v, int off=0) inline void set_le32(void *bb, unsigned v)
{ {
upx_bytep const b = reinterpret_cast<upx_bytep>(bb) + off; upx_bytep const b = reinterpret_cast<upx_bytep>(bb);
#if defined(__i386__) #if defined(__i386__)
(* (unsigned *) b) = v; (* (unsigned *) b) = v;
#else #else

View File

@ -115,8 +115,8 @@ int PackTmt::buildLoader(const Filter *ft)
int PackTmt::readFileHeader() int PackTmt::readFileHeader()
{ {
#define H(x) get_le16(h,2*(x)) #define H(x) get_le16(h+2*(x))
#define H4(x) get_le32(h,x) #define H4(x) get_le32(h+(x))
unsigned char h[0x40]; unsigned char h[0x40];
int ic; int ic;
unsigned exe_offset = 0; unsigned exe_offset = 0;

View File

@ -66,8 +66,8 @@ protected:
// in order too share as much code as possible we introduce // in order too share as much code as possible we introduce
// an endian abstraction here // an endian abstraction here
virtual unsigned get_native32(const void *, int off=0) = 0; virtual unsigned get_native32(const void *) = 0;
virtual void set_native32(void *, unsigned, int off=0) = 0; virtual void set_native32(void *, unsigned) = 0;
virtual bool checkCompressionRatio(unsigned, unsigned) const; virtual bool checkCompressionRatio(unsigned, unsigned) const;
@ -121,13 +121,13 @@ class PackUnixBe32 : public PackUnix
typedef PackUnix super; typedef PackUnix super;
protected: protected:
PackUnixBe32(InputFile *f) : super(f) { } PackUnixBe32(InputFile *f) : super(f) { }
virtual unsigned get_native32(const void * b, int off=0) virtual unsigned get_native32(const void *b)
{ {
return get_be32(b, off); return get_be32(b);
} }
virtual void set_native32(void * b, unsigned v, int off=0) virtual void set_native32(void *b, unsigned v)
{ {
set_be32(b, v, off); set_be32(b, v);
} }
}; };
@ -137,13 +137,13 @@ class PackUnixLe32 : public PackUnix
typedef PackUnix super; typedef PackUnix super;
protected: protected:
PackUnixLe32(InputFile *f) : super(f) { } PackUnixLe32(InputFile *f) : super(f) { }
virtual unsigned get_native32(const void * b, int off=0) virtual unsigned get_native32(const void *b)
{ {
return get_le32(b, off); return get_le32(b);
} }
virtual void set_native32(void * b, unsigned v, int off=0) virtual void set_native32(void *b, unsigned v)
{ {
set_le32(b, v, off); set_le32(b, v);
} }
}; };

View File

@ -949,7 +949,10 @@ char const *Packer::identstr(unsigned &size)
void Packer::initLoader(const void *pdata, int plen, int pinfo) void Packer::initLoader(const void *pdata, int plen, int pinfo)
{ {
if (pinfo < 0) if (pinfo < 0)
pinfo = ~3 & (3 + get_le16(pdata, plen - 2)); {
pinfo = get_le16((const unsigned char *)pdata + plen - 2);
pinfo = (pinfo + 3) &~ 3;
}
delete linker; delete linker;
if (getFormat() < 128) if (getFormat() < 128)