diff --git a/src/conf.h b/src/conf.h index a67e7c0a..df2e71d5 100644 --- a/src/conf.h +++ b/src/conf.h @@ -31,6 +31,10 @@ #include "version.h" +#if !defined(_FILE_OFFSET_BITS) +# define _FILE_OFFSET_BITS 64 +#endif + /************************************************************************* // ACC diff --git a/src/main.cpp b/src/main.cpp index 58eef024..08ffef5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1331,6 +1331,9 @@ __acc_static_noinline void upx_sanity_check(void) COMPILE_TIME_ASSERT(sizeof(off_t) >= sizeof(long)) COMPILE_TIME_ASSERT(((off_t) -1) < 0) +#if (ACC_OS_POSIX_DARWIN || ACC_OS_POSIX_LINUX) + COMPILE_TIME_ASSERT(sizeof(off_t) >= 8) +#endif COMPILE_TIME_ASSERT(sizeof(BE16) == 2) COMPILE_TIME_ASSERT(sizeof(BE32) == 4) diff --git a/src/p_lx_elf.h b/src/p_lx_elf.h index 943a51bd..230cd7df 100644 --- a/src/p_lx_elf.h +++ b/src/p_lx_elf.h @@ -502,7 +502,7 @@ class PackOpenBSDElf32x86 : public PackBSDElf32x86 public: PackOpenBSDElf32x86(InputFile *f); virtual ~PackOpenBSDElf32x86(); - virtual const char *getName() const { return "opnbsd/i386"; } + virtual const char *getName() const { return "openbsd/i386"; } virtual const char *getFullName(const options_t *) const { return "i386-openbsd.elf"; } protected: diff --git a/src/snprintf.cpp b/src/snprintf.cpp index cab3ce99..e25db8b2 100644 --- a/src/snprintf.cpp +++ b/src/snprintf.cpp @@ -71,13 +71,8 @@ #undef LLONG #undef ULLONG -#if 1 #define LLONG upx_int64_t #define ULLONG upx_uint64_t -#else -#define LLONG long int -#define ULLONG unsigned long int -#endif #undef NO_FLOAT #undef LDOUBLE @@ -615,7 +610,7 @@ static size_t dopr(char *buffer, size_t maxsize, const char *format, va_list arg else if (cflags == DP_C_LONG) value = (long) va_arg(args, unsigned long int); else if (cflags == DP_C_LLONG) - value = (long) va_arg(args, ULLONG); + value = (LLONG) va_arg(args, ULLONG); else value = (long) va_arg(args, unsigned int); fmtint(buffer, &currsize, maxsize, value, 8, min, max, flags); diff --git a/src/ui.cpp b/src/ui.cpp index 37e628b4..42e458c3 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -76,16 +76,16 @@ struct UiPacker::State { #endif }; -long UiPacker::total_files = 0; -long UiPacker::total_files_done = 0; -long UiPacker::total_c_len = 0; -long UiPacker::total_u_len = 0; -long UiPacker::total_fc_len = 0; -long UiPacker::total_fu_len = 0; -long UiPacker::update_c_len = 0; -long UiPacker::update_u_len = 0; -long UiPacker::update_fc_len = 0; -long UiPacker::update_fu_len = 0; +unsigned UiPacker::total_files = 0; +unsigned UiPacker::total_files_done = 0; +upx_uint64_t UiPacker::total_c_len = 0; +upx_uint64_t UiPacker::total_u_len = 0; +upx_uint64_t UiPacker::total_fc_len = 0; +upx_uint64_t UiPacker::total_fu_len = 0; +unsigned UiPacker::update_c_len = 0; +unsigned UiPacker::update_u_len = 0; +unsigned UiPacker::update_fc_len = 0; +unsigned UiPacker::update_fu_len = 0; /************************************************************************* // constants @@ -126,33 +126,28 @@ static void init_global_constants(void) { // **************************************************************************/ -static const char *mkline(unsigned long fu_len, unsigned long fc_len, unsigned long u_len, - unsigned long c_len, const char *format_name, const char *filename, +static const char *mkline(upx_uint64_t fu_len, upx_uint64_t fc_len, upx_uint64_t u_len, + upx_uint64_t c_len, const char *format_name, const char *filename, bool decompress = false) { static char buf[2048]; char r[7 + 1]; - char fn[13 + 1]; + char fn[15 + 1]; const char *f; // Large ratios can happen because of overlays that are // appended after a program is packed. - unsigned ratio = get_ratio(fu_len, fc_len) + 50; -#if 1 + unsigned ratio = get_ratio(fu_len, fc_len); if (ratio >= 1000 * 1000) strcpy(r, "overlay"); -#else - if (ratio >= 10 * 1000 * 1000) // >= "1000%" - strcpy(r, "999.99%"); -#endif else upx_snprintf(r, sizeof(r), "%3u.%02u%%", ratio / 10000, (ratio % 10000) / 100); if (decompress) - f = "%10ld <-%10ld %7s %13s %s"; + f = "%10lld <-%10lld %7s %15s %s"; else - f = "%10ld ->%10ld %7s %13s %s"; + f = "%10lld ->%10lld %7s %15s %s"; center_string(fn, sizeof(fn), format_name); - assert(strlen(fn) == 13); - upx_snprintf(buf, sizeof(buf), f, fu_len, fc_len, r, fn, filename); + assert(strlen(fn) == 15); + upx_snprintf(buf, sizeof(buf), f, (long long) fu_len, (long long) fc_len, r, fn, filename); UNUSED(u_len); UNUSED(c_len); return buf; @@ -517,12 +512,10 @@ void UiPacker::uiUnpackTotal() { void UiPacker::uiListStart() { total_files++; } -void UiPacker::uiList(long fu_len) { - if (fu_len < 0) - fu_len = p->ph.u_file_size; +void UiPacker::uiList() { const char *name = p->fi->getName(); - con_fprintf(stdout, "%s\n", - mkline(fu_len, p->file_size, p->ph.u_len, p->ph.c_len, p->getName(), name)); + con_fprintf(stdout, "%s\n", mkline(p->ph.u_file_size, p->file_size, p->ph.u_len, p->ph.c_len, + p->getName(), name)); printSetNl(0); } @@ -531,7 +524,7 @@ void UiPacker::uiListEnd() { uiUpdate(); } void UiPacker::uiListTotal(bool decompress) { if (opt->verbose >= 1 && total_files >= 2) { char name[32]; - upx_snprintf(name, sizeof(name), "[ %ld file%s ]", total_files_done, + upx_snprintf(name, sizeof(name), "[ %u file%s ]", total_files_done, total_files_done == 1 ? "" : "s"); con_fprintf(stdout, "%s%s\n", header_line2, mkline(total_fu_len, total_fc_len, total_u_len, total_c_len, "", name, decompress)); @@ -569,6 +562,11 @@ void UiPacker::uiTestTotal() { uiFooter("Tested"); } **************************************************************************/ bool UiPacker::uiFileInfoStart() { +#if defined(_WIN32) // msvcrt +#define PRLLD "I64d" +#else +#define PRLLD "lld" +#endif total_files++; int fg = con_fg(stdout, FG_CYAN); @@ -576,15 +574,16 @@ bool UiPacker::uiFileInfoStart() { fg = con_fg(stdout, fg); UNUSED(fg); if (p->ph.c_len > 0) { - con_fprintf(stdout, " %8ld bytes", (long) p->file_size); + con_fprintf(stdout, " %8" PRLLD " bytes", (long long) p->file_size); con_fprintf(stdout, ", compressed by UPX %d, method %d, level %d, filter 0x%02x/0x%02x\n", p->ph.version, p->ph.method, p->ph.level, p->ph.filter, p->ph.filter_cto); return false; } else { - con_fprintf(stdout, " %8ld bytes", (long) p->file_size); + con_fprintf(stdout, " %8" PRLLD " bytes", (long long) p->file_size); con_fprintf(stdout, ", not compressed by UPX\n"); return true; } +#undef PRLLD } void UiPacker::uiFileInfoEnd() { uiUpdate(); } @@ -613,18 +612,19 @@ void UiPacker::uiFooter(const char *t) { return; done = true; if (opt->verbose >= 1) { - long n1 = total_files; - long n2 = total_files_done; - long n3 = total_files - total_files_done; + assert(total_files >= total_files_done); + unsigned n1 = total_files; + unsigned n2 = total_files_done; + unsigned n3 = total_files - total_files_done; if (n3 == 0) - con_fprintf(stdout, "\n%s %ld file%s.\n", t, n1, n1 == 1 ? "" : "s"); + con_fprintf(stdout, "\n%s %u file%s.\n", t, n1, n1 == 1 ? "" : "s"); else - con_fprintf(stdout, "\n%s %ld file%s: %ld ok, %ld error%s.\n", t, n1, - n1 == 1 ? "" : "s", n2, n3, n3 == 1 ? "" : "s"); + con_fprintf(stdout, "\n%s %u file%s: %u ok, %u error%s.\n", t, n1, n1 == 1 ? "" : "s", + n2, n3, n3 == 1 ? "" : "s"); } } -void UiPacker::uiUpdate(long fc_len, long fu_len) { +void UiPacker::uiUpdate(off_t fc_len, off_t fu_len) { update_fc_len = (fc_len >= 0) ? fc_len : p->file_size; update_fu_len = (fu_len >= 0) ? fu_len : p->ph.u_file_size; update_c_len = p->ph.c_len; diff --git a/src/ui.h b/src/ui.h index 4b487a6b..7fd364e5 100644 --- a/src/ui.h +++ b/src/ui.h @@ -57,7 +57,7 @@ public: virtual void uiUnpackStart(const OutputFile *fo); virtual void uiUnpackEnd(const OutputFile *fo); virtual void uiListStart(); - virtual void uiList(long fu = -1); + virtual void uiList(); virtual void uiListEnd(); virtual void uiTestStart(); virtual void uiTestEnd(); @@ -77,7 +77,7 @@ protected: virtual void doCallback(unsigned isize, unsigned osize); protected: - virtual void uiUpdate(long fc = -1, long fu = -1); + virtual void uiUpdate(off_t fc_len = -1, off_t fu_len = -1); public: static void uiHeader(); @@ -98,16 +98,16 @@ protected: State *s; // totals - static long total_files; - static long total_files_done; - static long total_c_len; - static long total_u_len; - static long total_fc_len; - static long total_fu_len; - static long update_c_len; - static long update_u_len; - static long update_fc_len; - static long update_fu_len; + static unsigned total_files; + static unsigned total_files_done; + static upx_uint64_t total_c_len; + static upx_uint64_t total_u_len; + static upx_uint64_t total_fc_len; + static upx_uint64_t total_fu_len; + static unsigned update_c_len; + static unsigned update_u_len; + static unsigned update_fc_len; + static unsigned update_fu_len; }; #endif /* already included */ diff --git a/src/util.cpp b/src/util.cpp index 557111fd..96f3cfeb 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -270,7 +270,7 @@ int mem_replace(void *bb, int blen, const void *what, int wlen, const void *r) /************************************************************************* -// filename util +// fn - FileName util **************************************************************************/ #if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS16 || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64) @@ -300,7 +300,7 @@ char *fn_basename(const char *name) for (nn = n = name; *nn; nn++) if (fn_is_sep(*nn)) n = nn + 1; - return const_cast(n); + return ACC_UNCONST_CAST(char *, n); } @@ -319,25 +319,6 @@ bool fn_has_ext(const char *name, const char *ext, bool ignore_case) } -#if 0 // UNUSED -void fn_addslash(char *name, bool slash) -{ - char *p; - - name = fn_skip_drive(name); - p = name + strlen(name); - while (p > name && fn_is_sep(p[-1])) - *p-- = 0; - if (p > name) - { - if (slash) - *p++ = dir_sep[0]; - *p = 0; - } -} -#endif // UNUSED - - char *fn_strlwr(char *n) { char *p; @@ -364,53 +345,6 @@ int fn_strcmp(const char *n1, const char *n2) } -#if 0 // UNUSED -bool fn_is_same_file(const char *n1, const char *n2) -{ - /* very simple... */ - if (fn_strcmp(n1, n2) == 0) - return 1; - return 0; -} -#endif // UNUSED - - -/************************************************************************* -// time util -**************************************************************************/ - -#if 0 // not used - -#if (HAVE_LOCALTIME) -void tm2str(char *s, size_t size, const struct tm *tmp) -{ - upx_snprintf(s, size, "%04d-%02d-%02d %02d:%02d:%02d", - (int) tmp->tm_year + 1900, (int) tmp->tm_mon + 1, - (int) tmp->tm_mday, - (int) tmp->tm_hour, (int) tmp->tm_min, (int) tmp->tm_sec); -} -#endif - - -void time2str(char *s, size_t size, const time_t *t) -{ - assert(size >= 18); -#if (HAVE_LOCALTIME) - tm2str(s, size, localtime(t)); -#elif (HAVE_CTIME) - const char *p = ctime(t); - memset(s, ' ', 16); - memcpy(s + 2, p + 4, 6); - memcpy(s + 11, p + 11, 5); - s[16] = 0; -#else - s[0] = 0; -#endif -} - -#endif - - /************************************************************************* // misc. **************************************************************************/ @@ -561,12 +495,18 @@ bool makebakname(char *ofilename, size_t size, // return compression ratio, where 100% == 1000*1000 == 1e6 **************************************************************************/ -unsigned get_ratio(unsigned u_len, unsigned c_len) +unsigned get_ratio(upx_uint64_t u_len, upx_uint64_t c_len) { - const unsigned n = 1000000; - if (u_len <= 0) - return c_len <= 0 ? 0 : n; - return (unsigned) ((c_len * (upx_uint64_t)n) / u_len); + const unsigned n = 1000 * 1000; + if (u_len == 0) + return c_len == 0 ? 0 : n; + upx_uint64_t x = c_len * n; + assert(x / n == c_len); + x /= u_len; + x += 50; // rounding + if (x >= 10 * n) // >= "1000%" + x = 10 * n - 1; + return ACC_ICONV(unsigned, x); } diff --git a/src/util.h b/src/util.h index df171dde..356dca9e 100644 --- a/src/util.h +++ b/src/util.h @@ -42,7 +42,7 @@ bool maketempname(char *ofilename, size_t size, const char *ifilename, const cha bool force = true); bool makebakname(char *ofilename, size_t size, const char *ifilename, bool force = true); -unsigned get_ratio(unsigned u_len, unsigned c_len); +unsigned get_ratio(upx_uint64_t u_len, upx_uint64_t c_len); bool set_method_name(char *buf, size_t size, int method, int level); void center_string(char *buf, size_t size, const char *s);