100-lzmaonly.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. --- a/src/compress.cpp
  2. +++ b/src/compress.cpp
  3. @@ -41,7 +41,7 @@ unsigned upx_adler32(const void *buf, un
  4. if (len == 0)
  5. return adler;
  6. assert(buf != NULL);
  7. -#if 0
  8. +#if !(WITH_UCL)
  9. return adler32(adler, (const Bytef *) buf, len); // zlib
  10. #elif (WITH_UCL)
  11. return ucl_adler32(adler, (const ucl_bytep) buf, len);
  12. --- a/src/conf.h
  13. +++ b/src/conf.h
  14. @@ -179,7 +179,7 @@
  15. # undef __unix
  16. #endif
  17. -#if !defined(WITH_UCL)
  18. +#if defined(WITH_UCL)
  19. # define WITH_UCL 1
  20. #endif
  21. #if 0 && !defined(WITH_LZMA)
  22. @@ -640,7 +640,11 @@ struct lzma_compress_config_t
  23. };
  24. +#if (WITH_UCL)
  25. struct ucl_compress_config_t : public REAL_ucl_compress_config_t
  26. +#else
  27. +struct ucl_compress_config_t
  28. +#endif
  29. {
  30. void reset() { memset(this, 0xff, sizeof(*this)); }
  31. };
  32. @@ -692,7 +696,9 @@ struct lzma_compress_result_t
  33. struct ucl_compress_result_t
  34. {
  35. +#if (WITH_UCL)
  36. ucl_uint result[16];
  37. +#endif
  38. void reset() { memset(this, 0, sizeof(*this)); }
  39. };
  40. --- a/src/main.cpp
  41. +++ b/src/main.cpp
  42. @@ -618,7 +618,9 @@ static int do_option(int optc, const cha
  43. opt->method = -1;
  44. opt->all_filters = true;
  45. opt->filter = -1;
  46. +#if (WITH_UCL)
  47. opt->crp.crp_ucl.m_size = 999999;
  48. +#endif
  49. /* fallthrough */
  50. case 900: // --best
  51. if (!set_method(-1, 10))
  52. @@ -709,6 +711,7 @@ static int do_option(int optc, const cha
  53. opt->exact = true;
  54. break;
  55. // compression runtime parameters
  56. +#if (WITH_UCL)
  57. case 801:
  58. getoptvar(&opt->crp.crp_ucl.c_flags, 0, 3, arg);
  59. break;
  60. @@ -730,6 +733,7 @@ static int do_option(int optc, const cha
  61. case 807:
  62. getoptvar(&opt->crp.crp_ucl.m_size, 10000u, 999999u, arg);
  63. break;
  64. +#endif
  65. case 811:
  66. getoptvar(&opt->crp.crp_lzma.pos_bits, arg);
  67. break;
  68. --- a/src/Makefile
  69. +++ b/src/Makefile
  70. @@ -57,7 +57,10 @@ ifneq ($(wildcard $(UPX_UCLDIR)/include/
  71. INCLUDES += -I$(UPX_UCLDIR)/include
  72. LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext))))
  73. endif
  74. -LIBS += -lucl -lz
  75. +ifeq ($(WITH_UCL),1)
  76. +LIBS += -lucl
  77. +endif
  78. +LIBS += -lz
  79. # you should set envvar UPX_LZMADIR to point to your unpacked LZMA SDK
  80. include $(top_srcdir)/src/stub/src/c/Makevars.lzma
  81. ifneq ($(UPX_LZMA_VERSION),)
  82. --- a/src/packer.cpp
  83. +++ b/src/packer.cpp
  84. @@ -199,6 +199,7 @@ bool Packer::compress(upx_bytep i_ptr, u
  85. if (cconf_parm)
  86. cconf = *cconf_parm;
  87. // cconf options
  88. +#if (WITH_UCL)
  89. if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
  90. {
  91. if (opt->crp.crp_ucl.c_flags != -1)
  92. @@ -216,6 +217,7 @@ bool Packer::compress(upx_bytep i_ptr, u
  93. step = 0;
  94. #endif
  95. }
  96. +#endif
  97. if (M_IS_LZMA(ph.method))
  98. {
  99. oassign(cconf.conf_lzma.pos_bits, opt->crp.crp_lzma.pos_bits);
  100. @@ -250,6 +252,7 @@ bool Packer::compress(upx_bytep i_ptr, u
  101. if (r != UPX_E_OK)
  102. throwInternalError("compression failed");
  103. +#if (WITH_UCL)
  104. if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
  105. {
  106. const ucl_uint *res = ph.compress_result.result_ucl.result;
  107. @@ -267,6 +270,7 @@ bool Packer::compress(upx_bytep i_ptr, u
  108. assert(cconf.conf_ucl.max_match == 0 || cconf.conf_ucl.max_match >= ph.max_match_found);
  109. }
  110. }
  111. +#endif
  112. //printf("\nPacker::compress: %d/%d: %7d -> %7d\n", ph.method, ph.level, ph.u_len, ph.c_len);
  113. if (!checkCompressionRatio(ph.u_len, ph.c_len))
  114. --- a/src/p_exe.cpp
  115. +++ b/src/p_exe.cpp
  116. @@ -506,7 +506,9 @@ void PackExe::pack(OutputFile *fo)
  117. Filter ft(ph.level);
  118. // compress (max_match = 8192)
  119. upx_compress_config_t cconf; cconf.reset();
  120. +#if (WITH_UCL)
  121. cconf.conf_ucl.max_match = MAXMATCH;
  122. +#endif
  123. cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
  124. compressWithFilters(&ft, 32, &cconf);
  125. --- a/src/p_ps1.cpp
  126. +++ b/src/p_ps1.cpp
  127. @@ -499,7 +499,9 @@ void PackPs1::pack(OutputFile *fo)
  128. // compress (max_match = 65535)
  129. upx_compress_config_t cconf; cconf.reset();
  130. +#if (WITH_UCL)
  131. cconf.conf_ucl.max_match = 65535;
  132. +#endif
  133. cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
  134. compressWithFilters(&ft, sa_cnt, &cconf);
  135. --- a/src/p_tos.cpp
  136. +++ b/src/p_tos.cpp
  137. @@ -506,7 +506,9 @@ void PackTos::pack(OutputFile *fo)
  138. Filter ft(ph.level);
  139. // compress (max_match = 65535)
  140. upx_compress_config_t cconf; cconf.reset();
  141. +#if (WITH_UCL)
  142. cconf.conf_ucl.max_match = 65535;
  143. +#endif
  144. cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
  145. compressWithFilters(&ft, 512, &cconf);