diff --git a/CMakeLists.txt b/CMakeLists.txt index e66d0d13..e2d40edd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ upx_cache_bool_vars(OFF UPX_CONFIG_DISABLE_C_STANDARD UPX_CONFIG_DISABLE_CXX_STANDARD UPX_CONFIG_EXPECT_THREADS UPX_CONFIG_REQUIRE_THREADS ) +upx_print_env_var(CC CXX) # determine Git revision set(GITREV_SHORT "") @@ -502,6 +503,7 @@ endif() upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_APPLE_SILICON_PROCESSOR) upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_SYSTEM_PROCESSOR CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR) upx_print_var(CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT) +upx_print_var(CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_AR CMAKE_RANLIB) upx_print_var(CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_C_COMPILER_ARCHITECTURE_ID CMAKE_C_PLATFORM_ID CMAKE_C_COMPILER_ABI) upx_print_var(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_CXX_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_ARCHITECTURE_ID CMAKE_CXX_PLATFORM_ID CMAKE_CXX_COMPILER_ABI) upx_print_var(CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_POSITION_INDEPENDENT_CODE CMAKE_TRY_COMPILE_CONFIGURATION) diff --git a/Makefile b/Makefile index 54d92609..db840c2f 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ build/release: PHONY debug: build/debug PHONY release: build/release PHONY all build/all: build/debug build/release PHONY -build/%/all: $$(dir $$@)debug $$(dir $$@)release PHONY; +build/%/all: $$(dir $$@)debug $$(dir $$@)release PHONY ; # # END of Makefile diff --git a/misc/analyze/clang-tidy/clang-tidy-bzip2.yml b/misc/analyze/clang-tidy/clang-tidy-bzip2.yml index 316d8136..6f85229a 100644 --- a/misc/analyze/clang-tidy/clang-tidy-bzip2.yml +++ b/misc/analyze/clang-tidy/clang-tidy-bzip2.yml @@ -1,4 +1,4 @@ -# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/ +# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/ --- Checks: > -*, diff --git a/misc/analyze/clang-tidy/clang-tidy-ucl.yml b/misc/analyze/clang-tidy/clang-tidy-ucl.yml index c4975689..142b9b29 100644 --- a/misc/analyze/clang-tidy/clang-tidy-ucl.yml +++ b/misc/analyze/clang-tidy/clang-tidy-ucl.yml @@ -1,4 +1,4 @@ -# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/ +# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/ --- Checks: > -*, diff --git a/misc/analyze/clang-tidy/clang-tidy-zlib.yml b/misc/analyze/clang-tidy/clang-tidy-zlib.yml index a87c6a73..61556761 100644 --- a/misc/analyze/clang-tidy/clang-tidy-zlib.yml +++ b/misc/analyze/clang-tidy/clang-tidy-zlib.yml @@ -1,4 +1,4 @@ -# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/ +# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/ --- Checks: > -*, diff --git a/misc/analyze/clang-tidy/clang-tidy-zstd.yml b/misc/analyze/clang-tidy/clang-tidy-zstd.yml index 894190c4..c55e1aee 100644 --- a/misc/analyze/clang-tidy/clang-tidy-zstd.yml +++ b/misc/analyze/clang-tidy/clang-tidy-zstd.yml @@ -1,4 +1,4 @@ -# for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/ +# for clang-tidy from https://clang.llvm.org/extra/clang-tidy/ --- Checks: > -*, diff --git a/misc/cmake/functions.cmake b/misc/cmake/functions.cmake index 9c89e15f..1e6b47dc 100644 --- a/misc/cmake/functions.cmake +++ b/misc/cmake/functions.cmake @@ -72,6 +72,16 @@ function(upx_print_var) # ARGV endforeach() endfunction() +function(upx_print_env_var) # ARGV + foreach(var_name ${ARGV}) + if(DEFINED ENV{${var_name}}) + if(NOT ",$ENV{${var_name}}," STREQUAL ",,") + message(STATUS "ENV{${var_name}} = $ENV{${var_name}}") + endif() + endif() + endforeach() +endfunction() + function(upx_print_have_symbol) # ARGV; needs include(CheckSymbolExists) foreach(symbol ${ARGV}) set(cache_var_name "HAVE_symbol_${symbol}") diff --git a/misc/make/Makefile-extra.mk b/misc/make/Makefile-extra.mk index 78c23de6..ce7b956a 100644 --- a/misc/make/Makefile-extra.mk +++ b/misc/make/Makefile-extra.mk @@ -260,6 +260,9 @@ build/$(UPX_XTARGET)/%: export CXX := $(CXX) xtarget/all: xtarget/debug xtarget/release PHONY xtarget/debug: build/$(UPX_XTARGET)/debug PHONY xtarget/release: build/$(UPX_XTARGET)/release PHONY +xtarget/all+test: xtarget/debug+test xtarget/release+test PHONY +xtarget/debug+test: build/$(UPX_XTARGET)/debug+test PHONY +xtarget/release+test: build/$(UPX_XTARGET)/release+test PHONY # set new default .DEFAULT_GOAL := build/$(UPX_XTARGET)/release @@ -269,14 +272,16 @@ endif #*********************************************************************** # assemble cmake config flags; useful for CI jobs +# +# info: by default CMake only honors the CC and CXX environment variables; make +# it easy to set other variables like CMAKE_AR or CMAKE_RANLIB #*********************************************************************** ifneq ($(origin UPX_CMAKE_CONFIG_FLAGS),command line) # GNU make bug work-around # GNU make bug, see https://savannah.gnu.org/bugs/index.php?64822 # and commit https://git.savannah.gnu.org/cgit/make.git/commit/?id=07187db947ba25e6c59b55f10660a04f8e9c5229 -# info: by default CMake only honors the CC and CXX environment variables; make -# it easy to set other variables like CMAKE_AR or CMAKE_RANLIB +$(call check_undefined,__add_cmake_config) __add_cmake_config = $(and $($1),-D$1="$($1)") # pass common CMake settings from environment/make to cmake build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_VERBOSE_MAKEFILE) diff --git a/src/Makefile b/src/Makefile index a8eb0541..189be688 100644 --- a/src/Makefile +++ b/src/Makefile @@ -33,7 +33,7 @@ debug+test release+test all+test: PHONY; $(MAKE) -C $(top_srcd test:: build/all+test PHONY -# OLD names [deprecated] +# OLD target names [deprecated] $(top_srcdir)/build/debug: build/debug PHONY $(top_srcdir)/build/release: build/release PHONY @@ -42,8 +42,7 @@ $(top_srcdir)/build/release: build/release PHONY # git clone https://github.com/upx/upx-testsuite.git #*********************************************************************** -# search for the UPX testsuite -# you also can override upx_testsuite_SRCDIR +# search for the UPX testsuite; you can override by setting "upx_testsuite_SRCDIR" ifndef upx_testsuite_SRCDIR # search standard locations below $(top_srcdir) ifneq ($(wildcard $(top_srcdir)/../upx--upx-testsuite.git/files/packed/.),) @@ -61,7 +60,7 @@ endif ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),) ifneq ($(wildcard $(top_srcdir)/misc/testsuite/upx_testsuite_1.sh),) run-testsuite: run-testsuite-release PHONY -run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR) +run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR) run-testsuite-debug: export upx_testsuite_BUILDDIR := ./tmp-upx-testsuite-debug run-testsuite-debug: export upx_exe := $(top_srcdir)/build/debug/upx run-testsuite-debug: build/debug PHONY @@ -101,7 +100,7 @@ CLANG_FORMAT_EXCLUDE_FILES += p_lx_% p_mach% p_unix% p_vmlin% CLANG_FORMAT_FILES := $(sort $(wildcard *.[ch]* ../maint/src/*.[ch]* */*.[ch]*)) CLANG_FORMAT_FILES += $(sort $(wildcard stub/tools/*/*.[ch]*)) CLANG_FORMAT_FILES += $(sort $(wildcard ../misc/cmake/try_compile/*.[ch]*)) -CLANG_FORMAT_FILES := $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES)) +CLANG_FORMAT_FILES := $(sort $(filter-out $(CLANG_FORMAT_EXCLUDE_FILES),$(CLANG_FORMAT_FILES))) clang-format: $(CLANG_FORMAT_FILES) PHONY @echo "running upx-clang-format" @bash $(top_srcdir)/misc/scripts/upx-clang-format.sh -i $(CLANG_FORMAT_FILES) diff --git a/src/bele.h b/src/bele.h index 17143999..0e97a241 100644 --- a/src/bele.h +++ b/src/bele.h @@ -47,8 +47,9 @@ // try to detect XX16 vs XX32 vs XX64 size mismatches **************************************************************************/ -#if 0 // permissive version using "void *" +#if !(DEBUG) +// permissive version using "void *" #define REQUIRE_XE16 /*empty*/ #define REQUIRE_XE24 /*empty*/ #define REQUIRE_XE32 /*empty*/ @@ -748,6 +749,7 @@ T *operator+(const LE64 &v, T *ptr) noexcept DELETED_FUNCTION; // global overloads **************************************************************************/ +// TODO later: move these to upx namespace in util/cxxlib.h; see conf.h inline unsigned ALIGN_DOWN(unsigned a, const BE32 &b) { return ALIGN_DOWN(a, unsigned(b)); } inline unsigned ALIGN_DOWN(const BE32 &a, unsigned b) { return ALIGN_DOWN(unsigned(a), b); } inline unsigned ALIGN_UP(unsigned a, const BE32 &b) { return ALIGN_UP(a, unsigned(b)); } @@ -758,7 +760,7 @@ inline unsigned ALIGN_DOWN(const LE32 &a, unsigned b) { return ALIGN_DOWN(unsign inline unsigned ALIGN_UP(unsigned a, const LE32 &b) { return ALIGN_UP(a, unsigned(b)); } inline unsigned ALIGN_UP(const LE32 &a, unsigned b) { return ALIGN_UP(unsigned(a), b); } -// TODO: introduce upx::umax() and upx::umin() +// TODO later: introduce upx::umax() and upx::umin() inline unsigned UPX_MAX(unsigned a, const BE16 &b) { return UPX_MAX(a, unsigned(b)); } inline unsigned UPX_MAX(const BE16 &a, unsigned b) { return UPX_MAX(unsigned(a), b); } inline unsigned UPX_MIN(unsigned a, const BE16 &b) { return UPX_MIN(a, unsigned(b)); } diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index c7a13570..b80c3d95 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -741,6 +741,12 @@ TEST_CASE("libc snprintf") { CHECK_EQ(strcmp(buf, "-6.0.0.0.0.0.0.0.6.ffffffffffffffff"), 0); snprintf(buf, sizeof(buf), "%d.%d.%d.%d.%d.%d.%d.%d.%d.%#jx", -7, 0, 0, 0, 0, 0, 0, 0, 7, um); CHECK_EQ(strcmp(buf, "-7.0.0.0.0.0.0.0.7.0xffffffffffffffff"), 0); + snprintf(buf, sizeof(buf), "%#x %#lx %#llx", 17u, 18ul, 19ull); + CHECK_EQ(strcmp(buf, "0x11 0x12 0x13"), 0); + snprintf(buf, sizeof(buf), "%#X %#lX %#llX", 20u, 21ul, 22ull); + CHECK_EQ(strcmp(buf, "0X14 0X15 0X16"), 0); + snprintf(buf, sizeof(buf), "%#06x %#06lx %#06llx", 23u, 24ul, 25ull); + CHECK_EQ(strcmp(buf, "0x0017 0x0018 0x0019"), 0); } #if 0 diff --git a/src/conf.h b/src/conf.h index a12fceb8..70f3422a 100644 --- a/src/conf.h +++ b/src/conf.h @@ -70,7 +70,7 @@ ACC_COMPILE_TIME_ASSERT_HEADER((char) (-1) == 255) #pragma GCC diagnostic error "-Wsuggest-override" #endif #if (ACC_CC_CLANG >= 0x080000) -// don't enable before clang-8 because of stddef.h issues +// don't enable before clang-8 because of issues #pragma clang diagnostic error "-Wzero-as-null-pointer-constant" #elif (ACC_CC_GNUC >= 0x040700) && defined(__GLIBC__) // Some non-GLIBC toolchains do not use 'nullptr' everywhere when C++: @@ -154,6 +154,7 @@ typedef unsigned char uchar; // UPX convention: use "charptr" when dealing with abstract pointer arithmetics #define charptr upx_charptr_unit_type * // upx_charptr_unit_type is some opaque type with sizeof(type) == 1 +//// typedef char upx_charptr_unit_type; // also works struct alignas(1) upx_charptr_unit_type final { char hidden__; }; ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(upx_charptr_unit_type) == 1) @@ -399,7 +400,7 @@ inline void NO_fprintf(FILE *, const char *, ...) noexcept {} #define TABLESIZE(table) ((sizeof(table) / sizeof((table)[0]))) -// TODO later: move these to upx namespace in util/cxxlib.h +// TODO later: move these to upx namespace in util/cxxlib.h; also see bele.h template inline T ALIGN_DOWN(const T &a, const T &b) { T r; @@ -594,8 +595,8 @@ using upx::tribool; // #define M_CL1B_LE16 13 #define M_LZMA 14 #define M_DEFLATE 15 // zlib -#define M_ZSTD 16 -#define M_BZIP2 17 +#define M_ZSTD 16 // NOT YET USED +#define M_BZIP2 17 // NOT YET USED // compression methods internal usage #define M_ALL (-1) #define M_END (-2) diff --git a/src/packer.h b/src/packer.h index a02ef29c..fef568be 100644 --- a/src/packer.h +++ b/src/packer.h @@ -245,7 +245,7 @@ protected: unsigned image_size, int bits, bool bswap); // TE - Target Endianness abstraction -#if 0 +#if !(DEBUG) // permissive version using "void *" inline unsigned get_te16(const void *p) const noexcept { return bele->get16(p); } inline unsigned get_te32(const void *p) const noexcept { return bele->get32(p); } diff --git a/src/packer_r.cpp b/src/packer_r.cpp index f727f5a1..5672f019 100644 --- a/src/packer_r.cpp +++ b/src/packer_r.cpp @@ -30,7 +30,7 @@ /************************************************************************* // sort and delta-compress relocations with optional bswap within image -// returns number of bytes written to 'out' +// returns number of **bytes** written to 'out' **************************************************************************/ /*static*/ @@ -102,7 +102,7 @@ unsigned Packer::optimizeReloc(unsigned relocnum, SPAN_P(byte) relocs, SPAN_S(by /************************************************************************* // delta-decompress relocations // advances 'in' -// allocates 'out' and returns number of relocs written to 'out' +// allocates 'out' and returns number of **relocs** written to 'out' **************************************************************************/ /*static*/ @@ -132,7 +132,7 @@ unsigned Packer::unoptimizeReloc(SPAN_S(const byte) & in, MemBuffer &out, SPAN_P upx_adler32(image, image_size)); } - out.alloc(4 * (relocnum + 1)); // one extra entry + out.alloc(mem_size(4, relocnum + 1)); // one extra entry SPAN_S_VAR(LE32, relocs, out); fix = in; diff --git a/src/pefile.cpp b/src/pefile.cpp index 4497b893..0144a88f 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -298,7 +298,7 @@ static constexpr size_t RELOC_INPLACE_OFFSET = 64 * 1024; static constexpr size_t RELOC_ENTRY_SIZE = 5; // encoded size in bytes; actual encoding is private static void reloc_entry_encode(SPAN_P(byte) buf, unsigned pos, unsigned reloc_type) { if (reloc_type == 0 || reloc_type >= 16) - throwCantPack("bad reloc_type %u %u", pos, reloc_type); + throwCantPack("bad reloc_type %#x %u", pos, reloc_type); set_ne32(buf, pos); buf[4] = (upx_uint8_t) reloc_type; } @@ -383,7 +383,7 @@ bool PeFile::Reloc::readFromRelocationBlock(byte *next_rb) { // set rb return true; } -bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_type) { +bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_reloc_type) { assert(!start_did_alloc); for (;;) { // search current block @@ -391,9 +391,9 @@ bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_type) { rb.count -= 1; const unsigned value = *rb.rel1++; result_pos = rb.rel->virtual_address + (value & 0xfff); - result_type = (value >> 12) & 0xf; - NO_printf("%x %d\n", result_pos, result_type); - if (result_type != IMAGE_REL_BASED_IGNORE) + result_reloc_type = (value >> 12) & 0xf; + NO_printf("Reloc::next %#x %d\n", result_pos, result_reloc_type); + if (result_reloc_type != IMAGE_REL_BASED_IGNORE) return true; // success } // advance to next block @@ -407,9 +407,10 @@ bool PeFile::Reloc::next(unsigned &result_pos, unsigned &result_type) { void PeFile::Reloc::add_reloc(unsigned pos, unsigned reloc_type) { assert(start_did_alloc); + // assert(reloc_type != IMAGE_REL_BASED_IGNORE); if (reloc_type == IMAGE_REL_BASED_IGNORE) return; - auto entry_ptr = start_buf + (RELOC_INPLACE_OFFSET + RELOC_ENTRY_SIZE * counts[0]); + auto entry_ptr = start_buf + mem_size(RELOC_ENTRY_SIZE, counts[0], RELOC_INPLACE_OFFSET); reloc_entry_encode(entry_ptr, pos, reloc_type); counts[0] += 1; } @@ -436,7 +437,7 @@ void PeFile::Reloc::finish(byte *(&result_ptr), unsigned &result_size) { unsigned prev_pos = 0; unsigned current_page = 0; for (unsigned ic = 0; ic < counts[0]; ic++) { - const auto entry_ptr = start_buf + (RELOC_INPLACE_OFFSET + RELOC_ENTRY_SIZE * ic); + const auto entry_ptr = start_buf + mem_size(RELOC_ENTRY_SIZE, ic, RELOC_INPLACE_OFFSET); unsigned pos, reloc_type; reloc_entry_decode(entry_ptr, &pos, &reloc_type); if (ic > 0 && pos == prev_pos) @@ -457,7 +458,7 @@ void PeFile::Reloc::finish(byte *(&result_ptr), unsigned &result_size) { // info: if this is indeed a valid file we must increase RELOC_INPLACE_OFFSET throwCantPack("too many inplace relocs"); } - // write IMAGE_BASE_RELOCATION relocation + // write LE16 IMAGE_BASE_RELOCATION relocation *rb.rel1++ = (reloc_type << 12) | (pos & 0xfff); rb.rel->size_of_block += 2; } @@ -469,7 +470,7 @@ void PeFile::Reloc::finish(byte *(&result_ptr), unsigned &result_size) { assert(start_did_alloc); result_ptr = start; start_did_alloc = false; -#if 1 // safety, as we are really finished +#if DEBUG || 1 // safety, as we are really finished ptr_invalidate_and_poison(start); start_size_in_bytes = 0; SPAN_INVALIDATE(start_buf); @@ -489,10 +490,9 @@ void PeFile32::processRelocs() // pass1 const unsigned *const counts = rel.getcounts(); unsigned relocnum = 0; - unsigned ic; - for (ic = 1; ic < 16; ic++) + for (unsigned ic = 1; ic < 16; ic++) relocnum += counts[ic]; - for (ic = 0; ic < 16; ic++) + for (unsigned ic = 0; ic < 16; ic++) NO_printf("reloc counts[%u] %u\n", ic, counts[ic]); if (opt->win32_pe.strip_relocs || relocnum == 0) { @@ -507,13 +507,13 @@ void PeFile32::processRelocs() // pass1 return; } - for (ic = IMAGE_REL_BASED_HIGHADJ; ic < 16; ic++) + for (unsigned ic = IMAGE_REL_BASED_HIGHADJ; ic < 16; ic++) if (counts[ic]) infoWarning("skipping unsupported relocation type %d (%d)", ic, counts[ic]); LE32 *fix[4]; upx::ArrayDeleter fixdel{fix, 0}; // don't leak memory - for (ic = 0; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) { + for (unsigned ic = 0; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) { fix[ic] = New(LE32, counts[ic]); fixdel.count += 1; } @@ -533,7 +533,7 @@ void PeFile32::processRelocs() // pass1 } // remove duplicated records - for (ic = 1; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) { + for (unsigned ic = 1; ic <= IMAGE_REL_BASED_HIGHLOW; ic++) { upx_qsort(fix[ic], xcounts[ic], 4, le32_compare); unsigned prev = ~0u; unsigned jc = 0; @@ -546,7 +546,7 @@ void PeFile32::processRelocs() // pass1 } // preprocess "type 3" relocation records - for (ic = 0; ic < xcounts[IMAGE_REL_BASED_HIGHLOW]; ic++) { + for (unsigned ic = 0; ic < xcounts[IMAGE_REL_BASED_HIGHLOW]; ic++) { pos = fix[3][ic] + rvamin; unsigned w = get_le32(ibuf.subref("bad reloc type 3 %#x", pos, sizeof(LE32))); set_le32(ibuf + pos, w - ih.imagebase - rvamin); @@ -567,7 +567,7 @@ void PeFile32::processRelocs() // pass1 throwCantUnpack("Invalid relocs"); // append relocs type "LOW" then "HIGH" - for (ic = IMAGE_REL_BASED_LOW; ic >= IMAGE_REL_BASED_HIGH; ic--) { + for (unsigned ic = IMAGE_REL_BASED_LOW; ic >= IMAGE_REL_BASED_HIGH; ic--) { memcpy(orelocs + sorelocs, fix[ic], 4 * xcounts[ic]); sorelocs += 4 * xcounts[ic]; set_le32(orelocs + sorelocs, 0); @@ -592,10 +592,9 @@ void PeFile64::processRelocs() // pass1 const unsigned *const counts = rel.getcounts(); unsigned relocnum = 0; - unsigned ic; - for (ic = 1; ic < 16; ic++) + for (unsigned ic = 1; ic < 16; ic++) relocnum += counts[ic]; - for (ic = 0; ic < 16; ic++) + for (unsigned ic = 0; ic < 16; ic++) NO_printf("reloc counts[%u] %u\n", ic, counts[ic]); if (opt->win32_pe.strip_relocs || relocnum == 0) { @@ -610,13 +609,13 @@ void PeFile64::processRelocs() // pass1 return; } - for (ic = 0; ic < 16; ic++) + for (unsigned ic = 0; ic < 16; ic++) if (ic != IMAGE_REL_BASED_DIR64 && counts[ic]) infoWarning("skipping unsupported relocation type %d (%d)", ic, counts[ic]); LE32 *fix[16]; upx::ArrayDeleter fixdel{fix, 0}; // don't leak memory - for (ic = 0; ic < 16; ic++) { + for (unsigned ic = 0; ic < 16; ic++) { fix[ic] = New(LE32, counts[ic]); fixdel.count += 1; } @@ -636,7 +635,7 @@ void PeFile64::processRelocs() // pass1 } // remove duplicated records - for (ic = 1; ic < 16; ic++) { + for (unsigned ic = 1; ic < 16; ic++) { upx_qsort(fix[ic], xcounts[ic], 4, le32_compare); unsigned prev = ~0u; unsigned jc = 0; @@ -649,7 +648,7 @@ void PeFile64::processRelocs() // pass1 } // preprocess "type 10" relocation records - for (ic = 0; ic < xcounts[IMAGE_REL_BASED_DIR64]; ic++) { + for (unsigned ic = 0; ic < xcounts[IMAGE_REL_BASED_DIR64]; ic++) { pos = fix[IMAGE_REL_BASED_DIR64][ic] + rvamin; upx_uint64_t w = get_le64(ibuf.subref("bad reloc 10 %#x", pos, sizeof(LE64))); set_le64(ibuf + pos, w - ih.imagebase - rvamin); diff --git a/src/pefile.h b/src/pefile.h index 7bb188cf..453fb479 100644 --- a/src/pefile.h +++ b/src/pefile.h @@ -426,10 +426,10 @@ protected: explicit Reloc(unsigned relocnum); ~Reloc() noexcept; // - bool next(unsigned &result_pos, unsigned &result_type); + bool next(unsigned &result_pos, unsigned &result_reloc_type); const unsigned *getcounts() const { return counts; } // - void add_reloc(unsigned pos, unsigned type); + void add_reloc(unsigned pos, unsigned reloc_type); void finish(byte *(&result_ptr), unsigned &result_size); // => transfer ownership };