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

Some portab fixes.

committer: mfx <mfx> 1058450658 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2003-07-17 14:04:18 +00:00
parent 9cb922425e
commit 66565f7238
14 changed files with 86 additions and 52 deletions

View File

@ -66,7 +66,8 @@ Prerequisites
Tools needed to build/modify the UPX sources
--------------------------------------------
- A C++ compiler supporting templates, exceptions and RTTI.
- A C++ compiler supporting inner classes, templates, exceptions
and RTTI.
- GNU make for Win32
http://upx.sourceforge.net/download/tools/

View File

@ -18,8 +18,8 @@ VPATH = $(srcdir)
# auto-detect the target unless given on the commandline
ifeq ($(strip $(target)),)
# try environment variable UPX_TARGET
target := $(UPX_TARGET)
# try environment variable UPX_MAKE_TARGET
target := $(UPX_MAKE_TARGET)
endif
ifeq ($(strip $(target)),)
ifneq ($(strip $(wildcard /usr/include/linux)),)
@ -329,7 +329,8 @@ ifeq ($(target),bc)
o = .obj
a = .lib
e = .exe
CC = bcc32 -q -3
CC = bcc32 -3
INCLUDES += -I$(srcdir)/acc
CFLAGS = -w -w-aus -w-inl -g1
CFLAGS_OUTPUT = -o$@
LDFLAGS = -ls

View File

@ -36,7 +36,7 @@
inline unsigned get_be16(const void *bb)
{
const upx_bytep b = (const upx_bytep) bb;
const unsigned char* b = (const unsigned char*) bb;
unsigned v;
v = (unsigned) b[1] << 0;
v |= (unsigned) b[0] << 8;
@ -45,7 +45,7 @@ inline unsigned get_be16(const void *bb)
inline void set_be16(void *bb, unsigned v)
{
upx_bytep b = (upx_bytep) bb;
unsigned char* b = (unsigned char*) 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_be24(const void *bb)
{
const upx_bytep b = (const upx_bytep) bb;
const unsigned char* b = (const unsigned char*) bb;
unsigned v;
v = (unsigned) b[2] << 0;
v |= (unsigned) b[1] << 8;
@ -63,7 +63,7 @@ inline unsigned get_be24(const void *bb)
inline void set_be24(void *bb, unsigned v)
{
upx_bytep b = (upx_bytep) bb;
unsigned char* b = (unsigned char*) bb;
b[2] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
b[0] = (unsigned char) (v >> 16);
@ -72,7 +72,7 @@ inline void set_be24(void *bb, unsigned v)
inline unsigned get_be32(const void *bb)
{
const upx_bytep b = (const upx_bytep) bb;
const unsigned char* b = (const unsigned char*) bb;
unsigned v;
v = (unsigned) b[3] << 0;
v |= (unsigned) b[2] << 8;
@ -83,7 +83,7 @@ inline unsigned get_be32(const void *bb)
inline void set_be32(void *bb, unsigned v)
{
upx_bytep b = (upx_bytep) bb;
unsigned char* b = (unsigned char*) bb;
b[3] = (unsigned char) (v >> 0);
b[2] = (unsigned char) (v >> 8);
b[1] = (unsigned char) (v >> 16);
@ -96,7 +96,7 @@ inline unsigned get_le16(const void *bb)
#if (ACC_ARCH_IA32)
return * (const unsigned short *) bb;
#else
const upx_bytep b = (const upx_bytep) bb;
const unsigned char* b = (const unsigned char*) bb;
unsigned v;
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
@ -109,7 +109,7 @@ inline void set_le16(void *bb, unsigned v)
#if (ACC_ARCH_IA32)
(* (unsigned short *) bb) = (unsigned short) (v & 0xffff);
#else
upx_bytep b = (upx_bytep) bb;
unsigned char* b = (unsigned char*) bb;
b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
#endif
@ -118,7 +118,7 @@ inline void set_le16(void *bb, unsigned v)
inline unsigned get_le24(const void *bb)
{
const upx_bytep b = (const upx_bytep) bb;
const unsigned char* b = (const unsigned char*) bb;
unsigned v;
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
@ -128,7 +128,7 @@ inline unsigned get_le24(const void *bb)
inline void set_le24(void *bb, unsigned v)
{
upx_bytep b = (upx_bytep) bb;
unsigned char* b = (unsigned char*) bb;
b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
b[2] = (unsigned char) (v >> 16);
@ -140,7 +140,7 @@ inline unsigned get_le32(const void *bb)
#if (ACC_ARCH_IA32)
return * (const unsigned *) bb;
#else
const upx_bytep b = (const upx_bytep) bb;
const unsigned char* b = (const unsigned char*) bb;
unsigned v;
v = (unsigned) b[0] << 0;
v |= (unsigned) b[1] << 8;
@ -155,7 +155,7 @@ inline void set_le32(void *bb, unsigned v)
#if (ACC_ARCH_IA32)
(* (unsigned *) bb) = v;
#else
upx_bytep b = (upx_bytep) bb;
unsigned char* b = (unsigned char*) bb;
b[0] = (unsigned char) (v >> 0);
b[1] = (unsigned char) (v >> 8);
b[2] = (unsigned char) (v >> 16);
@ -260,7 +260,14 @@ class LE16
public:
LE16() { }
LE16& operator = (const LE16 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
LE16& operator = (const LE16 &v) {
#if (ACC_ARCH_IA32)
* (unsigned short *) d = * (const unsigned short *) v.d;
#else
memcpy(d, v.d, sizeof(d));
#endif
return *this;
}
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
@ -279,7 +286,14 @@ class LE32
public:
LE32() { }
LE32& operator = (const LE32 &v) { memcpy(d, v.d, sizeof(d)); return *this; }
LE32& operator = (const LE32 &v) {
#if (ACC_ARCH_IA32)
* (unsigned int *) d = * (const unsigned int *) v.d;
#else
memcpy(d, v.d, sizeof(d));
#endif
return *this;
}
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
@ -364,6 +378,13 @@ int __acc_cdecl_qsort le32_compare_signed(const void *e1, const void *e2);
# define LE16 LE16_unaligned
# define LE32 LE32_unaligned
#endif
#if (0 && ACC_ARCH_IA32 && ACC_CC_MSC)
typedef unsigned short LE16_unaligned;
typedef unsigned int LE32_unaligned;
# define LE16 LE16_unaligned
# define LE32 LE32_unaligned
# pragma warning(disable: 4244) // Wx: conversion, possible loss of data
#endif
#endif /* already included */

View File

@ -44,16 +44,21 @@
#if !defined(acc_int64l_t) || !defined(acc_uint64l_t)
# error "need a 64-bit integer type"
#endif
#if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
# error "something pulled in <windows.h>"
#if (ACC_OS_WIN32 || ACC_OS_WIN64)
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
# error "something pulled in <windows.h>"
# endif
#endif
#if (ACC_CC_BORLANDC)
# if (__BORLANDC__ < 0x550)
# error "need Borland C++ 5.5 or newer"
# if (__BORLANDC__ < 0x0520)
# error "need Borland C++ 5.02 or newer"
# endif
# if (__BORLANDC__ >= 0x560)
# if (__BORLANDC__ < 0x0530)
# pragma warn -csu // 8012: comparing signed and unsigned values
# endif
# if (__BORLANDC__ >= 0x0560)
# pragma warn -use
# endif
#elif (ACC_CC_DMC)
@ -509,6 +514,13 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
#endif /* __cplusplus */
#if (ACC_OS_WIN32 || ACC_OS_WIN64)
# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
# error "something pulled in <windows.h>"
# endif
#endif
#endif /* already included */

View File

@ -30,6 +30,10 @@
*/
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200))
# pragma warning(disable: 4702) // W4: unreachable code
#endif
/*************************************************************************
// filter / scan

View File

@ -1011,6 +1011,8 @@ static void first_options(int argc, char **argv)
void upx_sanity_check(void)
{
#include "acc/acc_chk.ch"
COMPILE_TIME_ASSERT(sizeof(char) == 1);
COMPILE_TIME_ASSERT(sizeof(short) == 2);
COMPILE_TIME_ASSERT(sizeof(int) == 4);
@ -1018,16 +1020,8 @@ void upx_sanity_check(void)
COMPILE_TIME_ASSERT(sizeof(void *) >= 4);
COMPILE_TIME_ASSERT(sizeof(long) >= sizeof(void *));
COMPILE_TIME_ASSERT(sizeof(acc_int64l_t) >= 8);
COMPILE_TIME_ASSERT(sizeof(acc_int64l_t) >= sizeof(long));
COMPILE_TIME_ASSERT(sizeof(acc_int64l_t) == sizeof(acc_uint64l_t));
COMPILE_TIME_ASSERT(sizeof(off_t) >= sizeof(long));
COMPILE_TIME_ASSERT(((off_t) -1) < 0);
COMPILE_TIME_ASSERT(sizeof(ptrdiff_t) >= sizeof(int));
COMPILE_TIME_ASSERT(((ptrdiff_t) -1) < 0);
COMPILE_TIME_ASSERT(sizeof(size_t) >= sizeof(int));
COMPILE_TIME_ASSERT(((size_t) -1) > 0);
COMPILE_TIME_ASSERT(sizeof(BE16) == 2);
COMPILE_TIME_ASSERT(sizeof(BE32) == 4);
@ -1041,9 +1035,6 @@ void upx_sanity_check(void)
COMPILE_TIME_ASSERT(__alignof__(LE32) == 1);
#endif
COMPILE_TIME_ASSERT(((((unsigned)1 << 31) + 1) >> 31) == 1);
COMPILE_TIME_ASSERT(((((acc_uint64l_t)1 << 63) + 1) >> 63) == 1);
#if !defined(ACC_CC_WATCOMC)
struct foo1a_t { char c1; LE16 v[4]; } __attribute_packed;
struct align_assertion_1a_t { foo1a_t d[3]; } __attribute_packed;
@ -1253,14 +1244,6 @@ int __acc_cdecl_main main(int argc, char *argv[])
fg = con_fg(f,fg);
}
#endif
#if 0 && !defined(WITH_NRV)
{
FILE *f = stdout;
int fg = con_fg(f,FG_GREEN);
con_fprintf(f,"\nINFO: this version does not use the NRV library - compression ratio is worse\n");
fg = con_fg(f,fg);
}
#endif
#if 0 && defined(__GLIBC__)
//malloc_stats();

View File

@ -82,7 +82,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
oh.headsize16 = 2;
oh.ip = 0;
oh.sp = ih.sp > 0x200 ? ih.sp : 0x200;
oh.sp = ih.sp > 0x200 ? (unsigned) ih.sp : 0x200;
unsigned destpara = (ph.u_len + ph.overlap_overhead - ph.c_len + 31) / 16;
oh.ss = ph.c_len/16 + destpara;
@ -676,7 +676,7 @@ void PackExe::unpack(OutputFile *fo)
if (flag & SS)
imagesize -= 2, oh.ss = get_le16(ibuf+imagesize);
unsigned ip = (flag & USEJUMP) ? get_le32(ibuf+imagesize-4) : ih.firstreloc;
unsigned ip = (flag & USEJUMP) ? get_le32(ibuf+imagesize-4) : (unsigned) ih.firstreloc;
oh.ip = ip & 0xffff;
oh.cs = ip >> 16;

View File

@ -149,7 +149,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
overlay_offset = sizeof(elfout.ehdr) +
(elfout.ehdr.e_phentsize * elfout.ehdr.e_phnum) +
sizeof(l_info) +
((elfout.ehdr.e_phnum==3) ? elfout.phdr[2].p_memsz : 0) ;
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ;
super::pack4(fo, ft); // write PackHeader and overlay_offset
unsigned eod = fo->getBytesWritten();
@ -270,7 +270,7 @@ PackLinuxI386::buildLinuxLoader(
// checksum UPX! lsize version format
sizeof(l_info) +
// PT_DYNAMIC with DT_NEEDED "forwarded" from original file
((elfout.ehdr.e_phnum==3) ? elfout.phdr[2].p_memsz : 0) +
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) +
// p_progid, p_filesize, p_blocksize
sizeof(p_info) +
// compressed data

View File

@ -288,7 +288,7 @@ void PackPs1::pack(OutputFile *fo)
memcpy(loader,getLoader(),lsize);
unsigned pad = 0;
unsigned filelen = ALIGN_UP((cfile_size ? cfile_size : ih.tx_len), 4);
unsigned filelen = ALIGN_UP((cfile_size ? cfile_size : (unsigned) ih.tx_len), 4);
unsigned pad_code = TIL_ALIGNED(ph.c_len, 4);
const int h_len = lsize-getLoaderSectionStart("IDENTSTR");

View File

@ -1779,7 +1779,7 @@ void PackW32Pe::pack(OutputFile *fo)
patch_le32(loader,codesize + 4,"JMPO",ih.entry - upxsection - jmp_pos - 4);
}
if (big_relocs & 6)
patch_le32(loader,codesize,"DELT", 0u -ih.imagebase - rvamin);
patch_le32(loader,codesize,"DELT", rvamin - ih.imagebase);
if (sorelocs && (soimport == 0 || soimport + cimports != crelocs))
patch_le32(loader,codesize,"BREL",crelocs);
if (soimport)

View File

@ -42,7 +42,7 @@
// direct screen access
**************************************************************************/
#if (ACC_CC_MSC && _MSC_VER >= 1000 && _MSC_VER < 1200)
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200))
/* avoid -W4 warnings in <conio.h> */
# pragma warning(disable: 4032)
/* avoid -W4 warnings in <windows.h> */

View File

@ -104,6 +104,15 @@ public:
};
}
#elif defined(__BORLANDC__) && (__BORLANDC__ < 0x0530)
#include <stdcomp.h>
#undef RWSTD_MULTI_THREAD
#include <stdexcep.h>
#include <new.h>
#include <typeinfo.h>
namespace std { class bad_alloc { }; }
#else
#include <exception>

View File

@ -29,7 +29,7 @@
#include "conf.h"
#include "util.h"
#if (ACC_CC_MSC && _MSC_VER >= 1000 && _MSC_VER < 1200)
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200))
/* avoid -W4 warnings in <conio.h> */
# pragma warning(disable: 4032)
/* avoid -W4 warnings in <windows.h> */

View File

@ -33,10 +33,13 @@
#include "ui.h"
#define ALWAYS_CHMOD 1
#if defined(__DJGPP__)
# define USE_FTIME
#elif defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64))
# undef ALWAYS_CHMOD
#elif ((ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_CC_INTELC || ACC_CC_MSC))
# define USE__FUTIME
# undef ALWAYS_CHMOD
#elif defined(HAVE_UTIME)
# define USE_UTIME
#endif
@ -135,7 +138,7 @@ void do_one_file(const char *iname, char *oname)
flags |= O_TRUNC;
shmode = O_DENYRW;
#endif
#if defined(__DJGPP__) || defined(_MSC_VER)
#if !defined(ALWAYS_CHMOD)
// we can avoid the chmod() call below
int omode = st.st_mode;
fo.sopen(tname,flags,shmode,omode);