Rearranged compression interface.

This commit is contained in:
Markus F.X.J. Oberhumer 2006-06-09 09:28:32 +02:00
parent 34ae413607
commit a9e4526a6d
16 changed files with 762 additions and 592 deletions

View File

@ -15,9 +15,10 @@ VPATH := . $(srcdir)
endif
ifeq ($(CXX),)
USE_GNUC = 1
CXX = g++
endif
ifeq ($(CXX),g++)
ifneq ($(USE_GNUC),)
CXXFLAGS += -O2 -MMD
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
endif
@ -33,6 +34,9 @@ ifneq ($(wildcard $(UCLDIR)/include/ucl/ucl.h),)
INCLUDES += -I$(UCLDIR)/include
LIBS += $(addprefix -L,$(dir $(wildcard $(UCLDIR)/libucl$(libext) $(UCLDIR)/src/.libs/libucl$(libext))))
endif
ifneq ($(wildcard $(LZMADIR)/include/ucl/ucl.h),)
INCLUDES += -I$(LZMADIR)
endif
LIBS += -lucl -lz
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
@ -48,6 +52,10 @@ upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
%.o : %.cpp
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
ifneq ($(USE_GNUC),)
compress.o : CXXFLAGS += -Wno-non-virtual-dtor
endif
mostlyclean clean distclean maintainer-clean:
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)

View File

@ -1,473 +0,0 @@
/* compress.ch --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#if 1 && defined(UCL_USE_ASM)
# include <ucl/ucl_asm.h>
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
# define ucl_nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
# define ucl_nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
# define ucl_nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
# define ucl_nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
# define ucl_nrv2e_decompress_safe_8 ucl_nrv2e_decompress_asm_safe_8
# define ucl_nrv2e_decompress_safe_le16 ucl_nrv2e_decompress_asm_safe_le16
# define ucl_nrv2e_decompress_safe_le32 ucl_nrv2e_decompress_asm_safe_le32
#endif
/*************************************************************************
//
**************************************************************************/
#if defined(upx_adler32)
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
{
if (len == 0)
return adler;
assert(buf != NULL);
return ucl_adler32(adler, (const ucl_bytep)buf, len);
}
#endif
#if defined(upx_crc32)
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
{
if (len == 0)
return crc;
assert(buf != NULL);
return ucl_crc32(crc, (const ucl_bytep)buf, len);
}
#endif
/*************************************************************************
//
**************************************************************************/
#if defined(ALG_LZMA)
#undef MSDOS
#undef OS2
#undef _WIN32
#undef _WIN32_WCE
#include "lzma/MyInitGuid.h"
//#include "lzma/LZMADecoder.h"
#include "lzma/LZMAEncoder.h"
#undef RC_NORMALIZE
struct CInStreamRam: public ISequentialInStream, public CMyUnknownImp
{
MY_UNKNOWN_IMP
const Byte *Data; size_t Size; size_t Pos;
void Init(const Byte *data, size_t size) {
Data = data; Size = size; Pos = 0;
}
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 remain = Size - Pos;
if (size > remain) size = remain;
memmove(data, Data + Pos, size);
Pos += size;
if (processedSize != NULL) *processedSize = size;
return S_OK;
}
struct COutStreamRam : public ISequentialOutStream, public CMyUnknownImp
{
MY_UNKNOWN_IMP
Byte *Data; size_t Size; size_t Pos; bool Overflow;
void Init(Byte *data, size_t size) {
Data = data; Size = size; Pos = 0; Overflow = false;
}
HRESULT WriteByte(Byte b) {
if (Pos >= Size) { Overflow = true; return E_FAIL; }
Data[Pos++] = b;
return S_OK;
}
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 i;
for (i = 0; i < size && Pos < Size; i++)
Data[Pos++] = ((const Byte *)data)[i];
if (processedSize != NULL) *processedSize = i;
if (i != size) { Overflow = true; return E_FAIL; }
return S_OK;
}
static
int upx_lzma_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_progress_callback_t *cb,
int level,
const struct upx_compress_config_t *conf_parm,
upx_uintp result )
{
UNUSED(cb); UNUSED(level);
UNUSED(conf_parm); UNUSED(result);
int r = UPX_E_ERROR;
HRESULT rh;
CInStreamRam* isp = new CInStreamRam;
CInStreamRam& is = *isp;
COutStreamRam* osp = new COutStreamRam;
COutStreamRam& os = *osp;
is.Init(src, src_len);
// os.Init(dst, *dst_len);
os.Init(dst, src_len);
#ifndef _NO_EXCEPTIONS
try {
#endif
NCompress::NLZMA::CEncoder enc;
PROPID propIDs[] = {
NCoderPropID::kAlgorithm,
NCoderPropID::kDictionarySize,
NCoderPropID::kNumFastBytes,
};
const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
PROPVARIANT properties[kNumProps];
properties[0].vt = VT_UI4;
properties[1].vt = VT_UI4;
properties[2].vt = VT_UI4;
properties[0].ulVal = (UInt32)2;
// properties[1].ulVal = (UInt32)dictionarySize;
properties[1].ulVal = (UInt32)1024 * 1024; // FIXME
properties[2].ulVal = (UInt32)64;
if (enc.SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
goto error;
if (enc.WriteCoderProperties(&os) != S_OK)
goto error;
if (os.Pos != 5)
goto error;
rh = enc.Code(&is, &os, 0, 0, 0);
if (rh == E_OUTOFMEMORY)
r = UPX_E_OUT_OF_MEMORY;
#if 0
else if (os.Overflow)
r = UPX_E_OUPUT_OVERRUN; // FIXME - not compressible
#endif
else if (rh == S_OK)
r = UPX_E_OK;
error:
*dst_len = os.Pos;
return r;
#ifndef _NO_EXCEPTIONS
} catch(...) { return UPX_E_OUT_OF_MEMORY; }
#endif
}
#include "lzma/Alloc.cpp"
#include "lzma/CRC.cpp"
//#include "lzma/LZMADecoder.cpp"
#include "lzma/LZMAEncoder.cpp"
#include "lzma/LZInWindow.cpp"
#include "lzma/OutBuffer.cpp"
#include "lzma/RangeCoderBit.cpp"
#include "lzma/StreamUtils.cpp"
#undef _LZMA_IN_CB
#undef _LZMA_OUT_READ
#undef _LZMA_PROB32
#undef _LZMA_LOC_OPT
#include "lzma/LzmaDecode.cpp"
static
int upx_lzma_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len )
{
CLzmaDecoderState s;
SizeT src_out = 0, dst_out = 0;
int r;
s.Probs = NULL;
#if defined(LzmaDecoderInit)
LzmaDecoderInit(&s);
#endif
r = LzmaDecodeProperties(&s.Properties, src, src_len);
if (r != 0)
goto error;
src += LZMA_PROPERTIES_SIZE; src_len -= LZMA_PROPERTIES_SIZE;
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
if (!s.Probs)
r = UPX_E_OUT_OF_MEMORY;
else
r = LzmaDecode(&s, src, src_len, &src_out, dst, *dst_len, &dst_out);
error:
*dst_len = dst_out;
free(s.Probs);
return r;
}
#endif
/*************************************************************************
//
**************************************************************************/
#if defined(upx_compress)
int upx_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_progress_callback_t *cb,
int method, int level,
const struct upx_compress_config_t *conf_parm,
upx_uintp result )
{
struct upx_compress_config_t conf;
upx_uint result_buffer[16];
int r = UPX_E_ERROR;
assert(level > 0);
memset(&conf, 0xff, sizeof(conf));
if (conf_parm)
conf = *conf_parm; // struct copy
if (!result)
result = result_buffer;
// assume no info available - fill in worst case results
//result[0] = 1; // min_offset_found - NOT USED
result[1] = src_len - 1; // max_offset_found
//result[2] = 2; // min_match_found - NOT USED
result[3] = src_len - 1; // max_match_found
//result[4] = 1; // min_run_found - NOT USED
result[5] = src_len; // max_run_found
result[6] = 1; // first_offset_found
//result[7] = 999999; // same_match_offsets_found - NOT USED
// prepare bit-buffer settings
conf.bb_endian = 0;
conf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
{
static const unsigned char sizes[3]={32,8,16};
conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
}
else
throwInternalError("unknown compression method");
// optimize compression parms
if (level <= 3 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 8*1024-1;
else if (level == 4 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 32*1024-1;
if M_IS_NRV2B(method)
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
else if M_IS_NRV2D(method)
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#if defined(ALG_NRV2E)
else if M_IS_NRV2E(method)
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#endif
#if 0 /*{*/
else if M_IS_CL1B(method)
r = cl1b_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#endif /*}*/
#if defined(ALG_LZMA)
else if M_IS_LZMA(method)
r = upx_lzma_compress(src, src_len, dst, dst_len,
cb, level, &conf, result);
#endif
else
throwInternalError("unknown compression method");
return r;
}
#endif /* upx_compress */
/*************************************************************************
//
**************************************************************************/
#if defined(upx_decompress)
int upx_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method )
{
int r = UPX_E_ERROR;
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
#if defined(ALG_NRV2E)
case M_NRV2E_8:
r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
#endif
#if 0 /*{*/
case M_CL1B_8:
r = cl1b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_CL1B_LE16:
r = cl1b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_CL1B_LE32:
r = cl1b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
#endif /*}*/
#if defined(ALG_LZMA)
case M_LZMA:
r = upx_lzma_decompress(src,src_len,dst,dst_len);
break;
#endif
default:
throwInternalError("unknown decompression method");
break;
}
return r;
}
#endif /* upx_decompress */
/*************************************************************************
//
**************************************************************************/
#if defined(upx_test_overlap)
int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method )
{
int r = UPX_E_ERROR;
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
#if defined(ALG_NRV2E)
case M_NRV2E_8:
r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
#endif
#if 0 /*{*/
case M_CL1B_8:
r = cl1b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_CL1B_LE16:
r = cl1b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_CL1B_LE32:
r = cl1b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
#endif /*}*/
#if defined(ALG_LZMA)
case M_LZMA:
/* FIXME */
if (src_off >= 256)
r = UPX_E_OK;
break;
#endif
default:
throwInternalError("unknown decompression method");
break;
}
return r;
}
#endif /* upx_test_overlap */
/*
vi:ts=4:et:nowrap
*/

View File

@ -27,24 +27,142 @@
#include "conf.h"
#include "compress.h"
#if defined(WITH_LZMA)
# define ALG_LZMA 1
#endif
#if defined(WITH_NRV)
# include "compress_nrv.ch"
#elif defined(WITH_UCL)
# define ALG_NRV2E 1
# define upx_adler32 upx_adler32
//# define upx_crc32 upx_crc32
# define upx_compress upx_compress
# define upx_decompress upx_decompress
# define upx_test_overlap upx_test_overlap
# include "compress.ch"
/*************************************************************************
//
**************************************************************************/
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
{
if (len == 0)
return adler;
assert(buf != NULL);
#if defined(WITH_UCL)
return ucl_adler32(adler, (const ucl_bytep)buf, len);
#else
# error
#endif
}
unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
{
if (len == 0)
return crc;
assert(buf != NULL);
#if defined(WITH_UCL)
return ucl_crc32(crc, (const ucl_bytep)buf, len);
#else
# error
#endif
}
/*************************************************************************
//
**************************************************************************/
int upx_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_callback_p cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result )
{
int r = UPX_E_ERROR;
upx_uint result_buffer[16];
assert(level > 0);
if (!result)
result = result_buffer;
// assume no info available - fill in worst case results
//result[0] = 1; // min_offset_found - NOT USED
result[1] = src_len - 1; // max_offset_found
//result[2] = 2; // min_match_found - NOT USED
result[3] = src_len - 1; // max_match_found
//result[4] = 1; // min_run_found - NOT USED
result[5] = src_len; // max_run_found
result[6] = 1; // first_offset_found
//result[7] = 999999; // same_match_offsets_found - NOT USED
#if defined(WITH_LZMA)
if (M_IS_LZMA(method))
return upx_lzma_compress(src, src_len, dst, dst_len,
cb, method, level, conf, result);
#endif
#if defined(WITH_NRV)
if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
return upx_nrv_compress(src, src_len, dst, dst_len,
cb, method, level, conf, result);
#endif
#if defined(WITH_UCL)
if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
return upx_ucl_compress(src, src_len, dst, dst_len,
cb, method, level, conf, result);
#endif
throwInternalError("unknown compression method");
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method )
{
int r = UPX_E_ERROR;
#if defined(WITH_LZMA)
if (M_IS_LZMA(method))
return upx_lzma_decompress(src, src_len, dst, dst_len, method);
#endif
#if defined(WITH_NRV)
if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
return upx_nrv_decompress(src, src_len, dst, dst_len, method);
#endif
#if defined(WITH_UCL)
if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
return upx_ucl_decompress(src, src_len, dst, dst_len, method);
#endif
throwInternalError("unknown decompression method");
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method )
{
int r = UPX_E_ERROR;
#if defined(WITH_LZMA)
if (M_IS_LZMA(method))
return upx_lzma_test_overlap(buf, src_off, src_len, dst_len, method);
#endif
#if defined(WITH_NRV)
if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
return upx_nrv_test_overlap(buf, src_off, src_len, dst_len, method);
#endif
#if defined(WITH_UCL)
if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
return upx_ucl_test_overlap(buf, src_off, src_len, dst_len, method);
#endif
throwInternalError("unknown decompression method");
return r;
}
/*

91
src/compress.h Normal file
View File

@ -0,0 +1,91 @@
/* compress.h --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#ifndef __UPX_COMPRESS_H
#define __UPX_COMPRESS_H
/*************************************************************************
//
**************************************************************************/
#if defined(WITH_LZMA)
int upx_lzma_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_callback_p cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result );
int upx_lzma_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method );
int upx_lzma_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method );
#endif
#if defined(WITH_NRV)
int upx_nrv_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_callback_p cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result );
int upx_nrv_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method );
int upx_nrv_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method );
#endif
#if defined(WITH_UCL)
int upx_ucl_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_callback_p cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result );
int upx_ucl_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method );
int upx_ucl_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method );
#endif
#endif /* already included */
/*
vi:ts=4:et
*/

225
src/compress_lzma.cpp Normal file
View File

@ -0,0 +1,225 @@
/* compress_lzma.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "compress.h"
#if !defined(WITH_LZMA)
extern int compress_lzma_dummy;
int compress_lzma_dummy = 0;
#else
/*************************************************************************
// cruft because of pseudo-COM layer
**************************************************************************/
#undef MSDOS
#undef OS2
#undef _WIN32
#undef _WIN32_WCE
#include "lzma/MyInitGuid.h"
//#include "lzma/LZMADecoder.h"
#include "lzma/LZMAEncoder.h"
#undef RC_NORMALIZE
namespace MyLzma {
struct CInStreamRam: public ISequentialInStream, public CMyUnknownImp
{
MY_UNKNOWN_IMP
const Byte *Data; size_t Size; size_t Pos;
void Init(const Byte *data, size_t size) {
Data = data; Size = size; Pos = 0;
}
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 remain = Size - Pos;
if (size > remain) size = remain;
memmove(data, Data + Pos, size);
Pos += size;
if (processedSize != NULL) *processedSize = size;
return S_OK;
}
struct COutStreamRam : public ISequentialOutStream, public CMyUnknownImp
{
MY_UNKNOWN_IMP
Byte *Data; size_t Size; size_t Pos; bool Overflow;
void Init(Byte *data, size_t size) {
Data = data; Size = size; Pos = 0; Overflow = false;
}
HRESULT WriteByte(Byte b) {
if (Pos >= Size) { Overflow = true; return E_FAIL; }
Data[Pos++] = b;
return S_OK;
}
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 i;
for (i = 0; i < size && Pos < Size; i++)
Data[Pos++] = ((const Byte *)data)[i];
if (processedSize != NULL) *processedSize = i;
if (i != size) { Overflow = true; return E_FAIL; }
return S_OK;
}
} // namespace
int upx_lzma_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_callback_p cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result )
{
assert(method == M_LZMA);
UNUSED(cb); UNUSED(method); UNUSED(level);
UNUSED(conf_parm); UNUSED(result);
int r = UPX_E_ERROR;
HRESULT rh;
MyLzma::CInStreamRam* isp = new MyLzma::CInStreamRam;
MyLzma::CInStreamRam& is = *isp;
MyLzma::COutStreamRam* osp = new MyLzma::COutStreamRam;
MyLzma::COutStreamRam& os = *osp;
is.Init(src, src_len);
// os.Init(dst, *dst_len);
os.Init(dst, src_len);
#ifndef _NO_EXCEPTIONS
try {
#endif
NCompress::NLZMA::CEncoder enc;
PROPID propIDs[3] = {
NCoderPropID::kAlgorithm,
NCoderPropID::kDictionarySize,
NCoderPropID::kNumFastBytes
};
PROPVARIANT properties[3];
properties[0].vt = VT_UI4;
properties[1].vt = VT_UI4;
properties[2].vt = VT_UI4;
properties[0].ulVal = (UInt32) 2;
// properties[1].ulVal = (UInt32) dictionarySize;
properties[1].ulVal = (UInt32) 1024 * 1024; // FIXME
properties[2].ulVal = (UInt32) 64;
if (enc.SetCoderProperties(propIDs, properties, 3) != S_OK)
goto error;
if (enc.WriteCoderProperties(&os) != S_OK)
goto error;
if (os.Pos != 5)
goto error;
rh = enc.Code(&is, &os, 0, 0, 0);
if (rh == E_OUTOFMEMORY)
r = UPX_E_OUT_OF_MEMORY;
#if 0
else if (os.Overflow)
r = UPX_E_OUPUT_OVERRUN; // FIXME - not compressible
#endif
else if (rh == S_OK)
r = UPX_E_OK;
//result[8] = LzmaGetNumProbs(&s.Properties));
result[8] = 0; // FIXME
error:
*dst_len = os.Pos;
return r;
#ifndef _NO_EXCEPTIONS
} catch(...) { return UPX_E_OUT_OF_MEMORY; }
#endif
}
#include "lzma/Alloc.cpp"
#include "lzma/CRC.cpp"
//#include "lzma/LZMADecoder.cpp"
#include "lzma/LZMAEncoder.cpp"
#include "lzma/LZInWindow.cpp"
#include "lzma/OutBuffer.cpp"
#include "lzma/RangeCoderBit.cpp"
#include "lzma/StreamUtils.cpp"
/*************************************************************************
// LZMA decompress
**************************************************************************/
#undef _LZMA_IN_CB
#undef _LZMA_OUT_READ
#undef _LZMA_PROB32
#undef _LZMA_LOC_OPT
#include "lzma/LzmaDecode.cpp"
int upx_lzma_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method )
{
assert(method == M_LZMA);
CLzmaDecoderState s;
SizeT src_out = 0, dst_out = 0;
int r;
s.Probs = NULL;
#if defined(LzmaDecoderInit)
LzmaDecoderInit(&s);
#endif
r = LzmaDecodeProperties(&s.Properties, src, src_len);
if (r != 0)
goto error;
src += LZMA_PROPERTIES_SIZE; src_len -= LZMA_PROPERTIES_SIZE;
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
if (!s.Probs)
r = UPX_E_OUT_OF_MEMORY;
else
r = LzmaDecode(&s, src, src_len, &src_out, dst, *dst_len, &dst_out);
error:
*dst_len = dst_out;
free(s.Probs);
return r;
}
#endif /* WITH_LZMA */
/*
vi:ts=4:et:nowrap
*/

230
src/compress_ucl.cpp Normal file
View File

@ -0,0 +1,230 @@
/* compress_ucl.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2004 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
*/
#include "conf.h"
#include "compress.h"
#if !defined(WITH_UCL)
extern int compress_ucl_dummy;
int compress_ucl_dummy = 0;
#else
#if 1 && !defined(UCL_USE_ASM) && (ACC_ARCH_I386)
# if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
# define UCL_USE_ASM
# endif
#endif
#if defined(UCL_NO_ASM)
# undef UCL_USE_ASM
#endif
#if defined(ACC_CFG_NO_UNALIGNED)
# undef UCL_USE_ASM
#endif
#if 1 && defined(UCL_USE_ASM)
# include <ucl/ucl_asm.h>
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
# define ucl_nrv2b_decompress_safe_le32 ucl_nrv2b_decompress_asm_safe_le32
# define ucl_nrv2d_decompress_safe_8 ucl_nrv2d_decompress_asm_safe_8
# define ucl_nrv2d_decompress_safe_le16 ucl_nrv2d_decompress_asm_safe_le16
# define ucl_nrv2d_decompress_safe_le32 ucl_nrv2d_decompress_asm_safe_le32
# define ucl_nrv2e_decompress_safe_8 ucl_nrv2e_decompress_asm_safe_8
# define ucl_nrv2e_decompress_safe_le16 ucl_nrv2e_decompress_asm_safe_le16
# define ucl_nrv2e_decompress_safe_le32 ucl_nrv2e_decompress_asm_safe_le32
#endif
/*************************************************************************
//
**************************************************************************/
static void wrap_ucl_nprogress(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
{
if (state != -1 && state != 3) return;
upx_callback_p cb = (upx_callback_p) user;
if (cb && cb->nprogress)
cb->nprogress(cb, a, b, state);
}
int upx_ucl_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_callback_p cb_parm,
int method, int level,
const struct upx_compress_config_t *conf_parm,
upx_uintp result )
{
int r = UPX_E_ERROR;
assert(level > 0); assert(result != NULL);
ucl_progress_callback_t cb;
cb.callback = 0;
cb.user = NULL;
if (cb_parm && cb_parm->nprogress) {
cb.callback = wrap_ucl_nprogress;
cb.user = cb_parm;
}
ucl_compress_config_t conf;
memset(&conf, 0xff, sizeof(conf));
if (conf_parm)
conf = conf_parm->conf_ucl; // struct copy
// prepare bit-buffer settings
conf.bb_endian = 0;
conf.bb_size = 0;
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
{
static const unsigned char sizes[3]={32,8,16};
conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
}
else
throwInternalError("unknown compression method");
// optimize compression parms
if (level <= 3 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 8*1024-1;
else if (level == 4 && conf.max_offset == UPX_UINT_MAX)
conf.max_offset = 32*1024-1;
if M_IS_NRV2B(method)
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
&cb, level, &conf, result);
else if M_IS_NRV2D(method)
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
&cb, level, &conf, result);
else if M_IS_NRV2E(method)
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
&cb, level, &conf, result);
else
throwInternalError("unknown compression method");
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_decompress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
int method )
{
int r = UPX_E_ERROR;
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_8:
r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,NULL);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL);
break;
default:
throwInternalError("unknown decompression method");
break;
}
return r;
}
/*************************************************************************
//
**************************************************************************/
int upx_ucl_test_overlap ( const upx_bytep buf, upx_uint src_off,
upx_uint src_len, upx_uintp dst_len,
int method )
{
int r = UPX_E_ERROR;
switch (method)
{
case M_NRV2B_8:
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE16:
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2B_LE32:
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_8:
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_LE16:
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2D_LE32:
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_8:
r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_LE16:
r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,NULL);
break;
case M_NRV2E_LE32:
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL);
break;
default:
throwInternalError("unknown decompression method");
break;
}
return r;
}
#endif /* WITH_UCL */
/*
vi:ts=4:et:nowrap
*/

View File

@ -144,37 +144,18 @@
# undef __unix
#endif
#if !defined(WITH_UCL)
# define WITH_UCL 1
#endif
#if defined(WITH_UCL)
# include <ucl/uclconf.h>
# include <ucl/ucl.h>
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010200L)
# error "please upgrade your UCL installation"
# endif
# if !defined(UPX_UINT_MAX)
# define UPX_UINT_MAX UCL_UINT_MAX
# define upx_uint ucl_uint
# define upx_voidp ucl_voidp
# define upx_uintp ucl_uintp
# define upx_byte ucl_byte
# define upx_bytep ucl_bytep
# define upx_bool ucl_bool
# define upx_compress_config_t ucl_compress_config_t
# define upx_progress_callback_t ucl_progress_callback_t
# define UPX_E_OK UCL_E_OK
# define UPX_E_ERROR UCL_E_ERROR
# define UPX_E_OUT_OF_MEMORY UCL_E_OUT_OF_MEMORY
# define __UPX_CDECL __UCL_CDECL
# endif
#endif
#if defined(WITH_NRV)
# include <nrv/nrvconf.h>
#endif
#if 1 && !defined(WITH_LZMA)
# define WITH_LZMA 1
#if defined(WITH_UCL)
# include <ucl/uclconf.h>
# include <ucl/ucl.h>
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010300L)
# error "please upgrade your UCL installation"
# endif
#endif
#if !defined(__UPX_CHECKER)
# if defined(__UCL_CHECKER) || defined(__NRV_CHECKER)
@ -185,6 +166,46 @@
# error "UINT_MAX"
#endif
#if !defined(UPX_UINT_MAX)
# define UPX_UINT_MAX UCL_UINT_MAX
# define upx_uint ucl_uint
# define upx_voidp ucl_voidp
# define upx_uintp ucl_uintp
# define upx_byte ucl_byte
# define upx_bytep ucl_bytep
# define upx_bool ucl_bool
# define UPX_E_OK UCL_E_OK
# define UPX_E_ERROR UCL_E_ERROR
# define UPX_E_OUT_OF_MEMORY UCL_E_OUT_OF_MEMORY
# define __UPX_CDECL __UCL_CDECL
#endif
struct upx_callback_t;
typedef struct upx_callback_t upx_callback_t;
#define upx_callback_p upx_callback_t *
typedef upx_voidp (__UPX_CDECL *upx_alloc_func_t)
(upx_callback_p self, upx_uint items, upx_uint size);
typedef void (__UPX_CDECL *upx_free_func_t)
(upx_callback_p self, upx_voidp ptr);
typedef void (__UPX_CDECL *upx_progress_func_t)
(upx_callback_p, upx_uint, upx_uint, int);
struct upx_callback_t
{
upx_alloc_func_t nalloc;
upx_free_func_t nfree;
upx_progress_func_t nprogress;
upx_voidp user1;
upx_uint user2;
upx_uint user3;
};
#define upx_compress_config_p upx_compress_config_t *
struct upx_compress_config_t
{
ucl_compress_config_t conf_ucl;
};
/*************************************************************************
// system includes
@ -555,7 +576,7 @@ unsigned upx_crc32(const void *buf, unsigned len, unsigned crc=0);
int upx_compress ( const upx_bytep src, upx_uint src_len,
upx_bytep dst, upx_uintp dst_len,
upx_progress_callback_t *cb,
upx_callback_p cb,
int method, int level,
const struct upx_compress_config_t *conf,
upx_uintp result );

View File

@ -386,10 +386,8 @@ void PackTos::fileInfo()
{
if (!readFileHeader())
return;
#if !defined(WITH_GUI)
con_fprintf(stdout, " text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
(int)ih.fh_text, (int)ih.fh_data, (int)ih.fh_sym, (int)ih.fh_bss, (int)ih.fh_flag);
#endif /* !defined(WITH_GUI) */
}

View File

@ -145,10 +145,6 @@ bool Packer::testUnpackFormat(int format) const
bool Packer::compress(upx_bytep in, upx_bytep out,
unsigned max_offset, unsigned max_match)
{
#if defined(UNUPX)
throwInternalError("compression failed");
return false;
#else
ph.c_len = 0;
assert(ph.level >= 1); assert(ph.level <= 10);
@ -160,28 +156,28 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
// set compression paramters
upx_compress_config_t conf;
memset(&conf, 0xff, sizeof(conf));
memset(&conf.conf_ucl, 0xff, sizeof(conf.conf_ucl));
// arguments
if (max_offset != 0)
conf.max_offset = max_offset;
conf.conf_ucl.max_offset = max_offset;
if (max_match != 0)
conf.max_match = max_match;
conf.conf_ucl.max_match = max_match;
// options
if (opt->crp.c_flags != -1)
conf.c_flags = opt->crp.c_flags;
conf.conf_ucl.c_flags = opt->crp.c_flags;
#if 0
else
// this is based on experimentation
conf.c_flags = (ph.level >= 7) ? 0 : 1 | 2;
conf.conf_ucl.c_flags = (ph.level >= 7) ? 0 : 1 | 2;
#endif
if (opt->crp.p_level != -1)
conf.p_level = opt->crp.p_level;
conf.conf_ucl.p_level = opt->crp.p_level;
if (opt->crp.h_level != -1)
conf.h_level = opt->crp.h_level;
if (opt->crp.max_offset != UPX_UINT_MAX && opt->crp.max_offset < conf.max_offset)
conf.max_offset = opt->crp.max_offset;
if (opt->crp.max_match != UPX_UINT_MAX && opt->crp.max_match < conf.max_match)
conf.max_match = opt->crp.max_match;
conf.conf_ucl.h_level = opt->crp.h_level;
if (opt->crp.max_offset != UPX_UINT_MAX && opt->crp.max_offset < conf.conf_ucl.max_offset)
conf.conf_ucl.max_offset = opt->crp.max_offset;
if (opt->crp.max_match != UPX_UINT_MAX && opt->crp.max_match < conf.conf_ucl.max_match)
conf.conf_ucl.max_match = opt->crp.max_match;
// Avoid too many progress bar updates. 64 is s->bar_len in ui.cpp.
unsigned step = (ph.u_len < 64*1024) ? 0 : ph.u_len / 64;
@ -248,7 +244,6 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
throwInternalError("decompression failed (checksum error)");
}
return true;
#endif /* UNUPX */
}
@ -333,11 +328,6 @@ void Packer::decompress(const upx_bytep in, upx_bytep out,
bool Packer::testOverlappingDecompression(const upx_bytep buf,
unsigned overlap_overhead) const
{
#if defined(UNUPX)
UNUSED(buf);
UNUSED(overlap_overhead);
return false;
#else
if (ph.c_len >= ph.u_len)
return false;
@ -354,7 +344,6 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
int r = upx_test_overlap(buf - src_off, src_off,
ph.c_len, &new_len, ph.method);
return (r == UPX_E_OK && new_len == ph.u_len);
#endif /* UNUPX */
}
@ -362,7 +351,6 @@ void Packer::verifyOverlappingDecompression(Filter *ft)
{
assert(ph.c_len < ph.u_len);
assert((int)ph.overlap_overhead > 0);
#if 1 && !defined(UNUPX)
// Idea:
// obuf[] was allocated with MemBuffer::allocForCompression(), and
// its contents are no longer needed, i.e. the compressed data
@ -386,7 +374,6 @@ void Packer::verifyOverlappingDecompression(Filter *ft)
memmove(obuf + offset, obuf, ph.c_len);
decompress(obuf + offset, obuf, true, ft);
obuf.checkState();
#endif /* !UNUPX */
}
@ -404,10 +391,6 @@ unsigned Packer::findOverlapOverhead(const upx_bytep buf,
unsigned range,
unsigned upper_limit) const
{
#if defined(UNUPX)
throwInternalError("not implemented");
return 0;
#else
assert((int) range >= 0);
// prepare to deal with very pessimistic values
@ -445,7 +428,6 @@ unsigned Packer::findOverlapOverhead(const upx_bytep buf,
UNUSED(nr);
return overhead;
#endif /* UNUPX */
}
@ -657,7 +639,7 @@ bool Packer::readPackHeader(int len)
}
void Packer::checkAlreadyPacked(void *b, int blen)
void Packer::checkAlreadyPacked(const void *b, int blen)
{
int boff = find_le32(b, blen, UPX_MAGIC_LE32);
if (boff < 0)
@ -848,9 +830,6 @@ upx_byte *Packer::optimizeReloc32(upx_byte *in, unsigned relocnum,
upx_byte *out, upx_byte *image,
int bswap, int *big)
{
#if defined(UNUPX)
return out;
#else
*big = 0;
if (relocnum == 0)
return out;
@ -890,7 +869,6 @@ upx_byte *Packer::optimizeReloc32(upx_byte *in, unsigned relocnum,
}
*fix++ = 0;
return fix;
#endif /* UNUPX */
}
@ -1416,15 +1394,12 @@ void Packer::compressWithFilters(Filter *parm_ft,
unsigned hdr_c_len = 0;
if (hdr_buf && hdr_u_len)
{
unsigned result[16];
upx_compress_config_t conf;
memset(&conf, 0xff, sizeof(conf));
if (0 < m && otemp == &obuf) { // do not overwrite obuf
otemp_buf.allocForCompression(compress_buf_len);
otemp = &otemp_buf;
}
int r = upx_compress(hdr_buf, hdr_u_len, *otemp, &hdr_c_len,
0, methods[m], 10, &conf, result);
NULL, methods[m], 10, NULL, NULL);
if (r != UPX_E_OK)
throwInternalError("header compression failed");
if (hdr_c_len >= hdr_u_len)

View File

@ -192,7 +192,7 @@ protected:
virtual int patchPackHeader(void *b, int blen);
virtual bool getPackHeader(void *b, int blen);
virtual bool readPackHeader(int len);
virtual void checkAlreadyPacked(void *b, int blen);
virtual void checkAlreadyPacked(const void *b, int blen);
// filter handling [see packerf.cpp]
virtual bool isValidFilter(int filter_id) const;

View File

@ -104,9 +104,6 @@ int PackHeader::getPackHeaderSize() const
void PackHeader::putPackHeader(upx_bytep p)
{
#if defined(UNUPX)
throwBadLoader();
#else
assert(get_le32(p) == UPX_MAGIC_LE32);
if (get_le32(p+4) != UPX_MAGIC2_LE32)
{
@ -189,7 +186,6 @@ void PackHeader::putPackHeader(upx_bytep p)
}
// store new header_checksum
p[size - 1] = get_packheader_checksum(p, size - 1);
#endif /* UNUPX */
}

View File

@ -94,7 +94,6 @@ static Packer* try_pack(Packer *p, InputFile *f)
{
if (p == NULL)
return NULL;
#if !defined(UNUPX)
try {
p->initPackHeader();
f->seek(0,SEEK_SET);
@ -110,7 +109,6 @@ static Packer* try_pack(Packer *p, InputFile *f)
delete p;
throw;
}
#endif /* UNUPX */
delete p;
return NULL;
}

View File

@ -265,11 +265,11 @@ void UiPacker::startCallback(unsigned u_len, unsigned step,
}
#if (ACC_CC_MSC && (_MSC_VER == 1300))
cb.callback = &UiPacker::callback;
cb.nprogress = &UiPacker::progress_callback;
#else
cb.callback = callback;
cb.nprogress = progress_callback;
#endif
cb.user = this;
cb.user1 = this;
if (s->mode == M_CB_TERM)
{
@ -398,15 +398,12 @@ void UiPacker::endCallback()
// the callback
**************************************************************************/
void __UPX_CDECL UiPacker::callback(upx_uint isize, upx_uint osize, int state, void *user)
void __UPX_CDECL UiPacker::progress_callback(upx_callback_p cb, upx_uint isize, upx_uint osize, int state)
{
//printf("%6d %6d %d\n", isize, osize, state);
if (state != -1 && state != 3) return;
if (user)
{
UiPacker *uip = (UiPacker *) user;
uip->doCallback(isize, osize);
}
UiPacker *uip = (UiPacker *) cb->user1;
uip->doCallback(isize, osize);
UNUSED(state);
}

View File

@ -34,10 +34,6 @@ class OutputFile;
class Packer;
class UiPacker;
#if defined(WITH_GUI)
class CMainDlg;
#endif
/*************************************************************************
//
@ -73,16 +69,14 @@ public:
virtual void uiFileInfoEnd();
// callback
typedef upx_progress_callback_t cb_t;
virtual void startCallback(unsigned u_len, unsigned step,
int pass, int total_passes);
virtual void firstCallback();
virtual void finalCallback(unsigned u_len, unsigned c_len);
virtual void endCallback();
virtual cb_t *getCallback() { return &cb; }
virtual upx_callback_t *getCallback() { return &cb; }
protected:
static void __UPX_CDECL callback(upx_uint isize, upx_uint osize,
int, void *);
static void __UPX_CDECL progress_callback(upx_callback_p cb, upx_uint, upx_uint, int);
virtual void doCallback(unsigned isize, unsigned osize);
protected:
@ -97,7 +91,7 @@ protected:
const Packer *p;
// callback
cb_t cb;
upx_callback_t cb;
// internal state
UiPacker__State *s;
@ -113,10 +107,6 @@ protected:
static long update_u_len;
static long update_fc_len;
static long update_fu_len;
#if defined(WITH_GUI)
CMainDlg* pMain;
#endif
};

View File

@ -1,6 +1,6 @@
#define UPX_VERSION_HEX 0x020100 /* 02.01.00 */
#define UPX_VERSION_STRING "2.01"
#define UPX_VERSION_STRING4 "2.01"
#define UPX_VERSION_DATE "Jun 06th 2006"
#define UPX_VERSION_DATE_ISO "2006-06-06"
#define UPX_VERSION_HEX 0x029000 /* 02.90.00 */
#define UPX_VERSION_STRING "2.90"
#define UPX_VERSION_STRING4 "2.90"
#define UPX_VERSION_DATE "Jun 09th 2006"
#define UPX_VERSION_DATE_ISO "2006-06-09"
#define UPX_VERSION_YEAR "2006"

View File

@ -231,8 +231,6 @@ void do_one_file(const char *iname, char *oname)
// process all files from the commandline
**************************************************************************/
#if !defined(WITH_GUI)
static void unlink_ofile(char *oname)
{
if (oname && oname[0])
@ -310,8 +308,6 @@ void do_files(int i, int argc, char *argv[])
UiPacker::uiFileInfoTotal();
}
#endif /* !defined(WITH_GUI) */
/*
vi:ts=4:et