Packer::defineDecompressorSymbols added

This commit is contained in:
László Molnár 2006-07-17 17:34:03 +02:00
parent 3fbbaa5130
commit b83698ebf5
2 changed files with 31 additions and 0 deletions

View File

@ -230,6 +230,7 @@ protected:
virtual const char *getDecompressorSections() const;
virtual unsigned getDecompressorWrkmemSize() const;
virtual void patchDecompressor(void *, int);
virtual void defineDecompressorSymbols();
// filter handling [see packer_f.cpp]
virtual bool isValidFilter(int filter_id) const;

View File

@ -28,6 +28,7 @@
#include "conf.h"
#include "packer.h"
#include "linker.h"
//#include "filter.h"
@ -264,6 +265,35 @@ void Packer::patchDecompressor(void *loader, int lsize)
}
}
void Packer::defineDecompressorSymbols()
{
if (UPX_F_LINUX_ELF_i386 ==ph.format
|| UPX_F_LINUX_ELFI_i386 ==ph.format
|| UPX_F_LINUX_ELF64_AMD ==ph.format
|| UPX_F_LINUX_ELF32_ARMLE==ph.format
|| UPX_F_LINUX_ELFPPC32 ==ph.format
|| UPX_F_LINUX_ELF32_ARMBE==ph.format ) {
// ELF calls the decompressor many times; the parameters change!
return;
}
if (ph.method == M_LZMA)
{
const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
// FIXME - this is for i386 only
unsigned properties = // lc, lp, pb, dummy
(res->lit_context_bits << 0) |
(res->lit_pos_bits << 8) |
(res->pos_bits << 16);
linker->defineSymbol("UPXd", properties);
// -2 for properties
linker->defineSymbol("UPXc", ph.c_len - 2);
linker->defineSymbol("UPXb", ph.u_len);
unsigned stack = getDecompressorWrkmemSize();
linker->defineSymbol("UPXa", 0u - stack);
}
}
/*
vi:ts=4:et:nowrap