1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Introduced Packer::patchDecompressorGetExtraStacksize().

This commit is contained in:
Markus F.X.J. Oberhumer 2006-06-22 15:35:38 +02:00
parent 8020c52c48
commit bcd738ebbb
3 changed files with 21 additions and 6 deletions

View File

@ -300,10 +300,11 @@ void PackDjgpp2::pack(OutputFile *fo)
text->size = lsize; // new size of .text
data->size = ph.c_len; // new size of .data
if (bss->size < ph.overlap_overhead) // give it a .bss
bss->size = ph.overlap_overhead;
if (ph.method == M_LZMA && bss->size < 0x4000)
bss->size = 0x4000;
unsigned stack = 1024 + ph.overlap_overhead +
patchDecompressorGetExtraStacksize();
stack = ALIGN_UP(stack, 16);
if (bss->size < stack) // give it a .bss
bss->size = stack;
text->scnptr = sizeof(coff_hdr);
data->scnptr = text->scnptr + text->size;

View File

@ -225,6 +225,7 @@ protected:
const int *getDefaultCompressionMethods_le32(int method, int level, int small=-1) const;
virtual const char *getDecompressorSections() const;
virtual void patchDecompressor(void *, int);
virtual unsigned patchDecompressorGetExtraStacksize();
// filter handling [see packer_f.cpp]
virtual bool isValidFilter(int filter_id) const;

View File

@ -208,6 +208,20 @@ const char *Packer::getDecompressorSections() const
}
unsigned Packer::patchDecompressorGetExtraStacksize()
{
unsigned stack = 0;
if (ph.method == M_LZMA)
{
const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
// FIXME - this is for i386 only
stack = 8 + 4 + ALIGN_UP(2 * res->num_probs, 4);
stack = ALIGN_UP(stack, 16);
}
return stack;
}
void Packer::patchDecompressor(void *loader, int lsize)
{
if (ph.method == M_LZMA)
@ -221,8 +235,7 @@ void Packer::patchDecompressor(void *loader, int lsize)
patch_le32(loader, lsize, "UPXd", properties);
patch_le32(loader, lsize, "UPXc", ph.c_len - 1);
patch_le32(loader, lsize, "UPXb", ph.u_len);
unsigned stack = 8 + 4 + ALIGN_UP(2 * res->num_probs, 4);
stack = ALIGN_UP(stack, 16);
unsigned stack = patchDecompressorGetExtraStacksize();
patch_le32(loader, lsize, "UPXa", 0u - stack);
}
}