diff --git a/README.SRC b/README.SRC index 3a2db9bb..af7bcd1f 100644 --- a/README.SRC +++ b/README.SRC @@ -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/ diff --git a/src/Makefile.bld b/src/Makefile.bld index 1baacf56..757bade2 100644 --- a/src/Makefile.bld +++ b/src/Makefile.bld @@ -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 diff --git a/src/bele.h b/src/bele.h index 26965486..7b8ab4ec 100644 --- a/src/bele.h +++ b/src/bele.h @@ -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 */ diff --git a/src/conf.h b/src/conf.h index f7d25c7b..9dd57c12 100644 --- a/src/conf.h +++ b/src/conf.h @@ -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 " +#if (ACC_OS_WIN32 || ACC_OS_WIN64) +# if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR) +# error "something pulled in " +# 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 " +# endif +#endif + + #endif /* already included */ diff --git a/src/filter/ctojr.h b/src/filter/ctojr.h index 275c1564..486395eb 100644 --- a/src/filter/ctojr.h +++ b/src/filter/ctojr.h @@ -30,6 +30,10 @@ */ +#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200)) +# pragma warning(disable: 4702) // W4: unreachable code +#endif + /************************************************************************* // filter / scan diff --git a/src/main.cpp b/src/main.cpp index 4a6df6e3..46630971 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(); diff --git a/src/p_exe.cpp b/src/p_exe.cpp index f3028e88..85cf180b 100644 --- a/src/p_exe.cpp +++ b/src/p_exe.cpp @@ -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; diff --git a/src/p_lx_exc.cpp b/src/p_lx_exc.cpp index 02faa395..9fc83f45 100644 --- a/src/p_lx_exc.cpp +++ b/src/p_lx_exc.cpp @@ -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 diff --git a/src/p_ps1.cpp b/src/p_ps1.cpp index 8bd2a3c6..bf10ef0f 100644 --- a/src/p_ps1.cpp +++ b/src/p_ps1.cpp @@ -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"); diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 08fed486..08a008c4 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -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) diff --git a/src/s_win32.cpp b/src/s_win32.cpp index e75c1aed..b6d2458a 100644 --- a/src/s_win32.cpp +++ b/src/s_win32.cpp @@ -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 */ # pragma warning(disable: 4032) /* avoid -W4 warnings in */ diff --git a/src/stdcxx.h b/src/stdcxx.h index 1e659e63..136b6dc5 100644 --- a/src/stdcxx.h +++ b/src/stdcxx.h @@ -104,6 +104,15 @@ public: }; } +#elif defined(__BORLANDC__) && (__BORLANDC__ < 0x0530) + +#include +#undef RWSTD_MULTI_THREAD +#include +#include +#include +namespace std { class bad_alloc { }; } + #else #include diff --git a/src/util.cpp b/src/util.cpp index d1dd98ee..f3870006 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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 */ # pragma warning(disable: 4032) /* avoid -W4 warnings in */ diff --git a/src/work.cpp b/src/work.cpp index 49d79237..b89b1c89 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -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);