PE: Add position independent decompressor stub for i386

This commit is contained in:
Kornel Pal 2021-12-22 02:58:09 +01:00 committed by Markus F.X.J. Oberhumer
parent 7f1f29b0d8
commit 76ddf6b8da
5 changed files with 21 additions and 6 deletions

View File

@ -110,14 +110,17 @@ void PackW32Pe::buildLoader(const Filter *ft)
// prepare loader
initLoader(stub_i386_win32_pe, sizeof(stub_i386_win32_pe), 2);
addLoader(isdll ? "PEISDLL1" : "",
"PEMAIN01",
if (isdll)
addLoader("PEISDLL1");
addLoader("PEMAIN01",
use_stub_relocs ? "PESOCREL" : "PESOCPIC",
"PESOUNC0",
icondir_count > 1 ? (icondir_count == 2 ? "PEICONS1" : "PEICONS2") : "",
tmp_tlsindex ? "PETLSHAK" : "",
"PEMAIN02",
ph.first_offset_found == 1 ? "PEMAIN03" : "",
getDecompressorSections(),
/*multipass ? "PEMULTIP" : */ "",
//multipass ? "PEMULTIP" : "",
"PEMAIN10",
nullptr
);
@ -255,7 +258,7 @@ void PackW32Pe::defineSymbols(unsigned ncsection, unsigned upxsection,
const unsigned esi0 = s1addr + ic;
linker->defineSymbol("start_of_uncompressed", 0u - esi0 + rvamin);
linker->defineSymbol("start_of_compressed", esi0 + ih.imagebase);
linker->defineSymbol("start_of_compressed", use_stub_relocs ? esi0 + ih.imagebase : esi0);
if (use_tls_callbacks)
{
@ -270,7 +273,8 @@ void PackW32Pe::defineSymbols(unsigned ncsection, unsigned upxsection,
void PackW32Pe::addNewRelocations(Reloc &rel, unsigned base)
{
rel.add(base + linker->getSymbolOffset("PEMAIN01") + 2, 3);
if (use_stub_relocs)
rel.add(base + linker->getSymbolOffset("PESOCREL") + 1, 3);
}
void PackW32Pe::setOhDataBase(const pe_section_t *osection)

View File

@ -47,7 +47,9 @@ static const
**************************************************************************/
PackW64Pep::PackW64Pep(InputFile *f) : super(f)
{}
{
use_stub_relocs = false;
}
PackW64Pep::~PackW64Pep()

View File

@ -117,6 +117,7 @@ PeFile::PeFile(InputFile *f) : super(f)
use_dep_hack = true;
use_clear_dirty_stack = true;
use_stub_relocs = true;
isrtm = false;
}

View File

@ -214,6 +214,7 @@ protected:
bool isrtm;
bool use_dep_hack;
bool use_clear_dirty_stack;
bool use_stub_relocs;
static unsigned virta2objnum (unsigned, pe_section_t *, unsigned);

View File

@ -40,7 +40,14 @@ section PEISDLL1
jnz reloc_end_jmp
section PEMAIN01
pusha
section PESOCREL
mov esi, offset start_of_compressed // relocated
section PESOCPIC
call get_eip
get_eip:
pop eax
lea esi, [eax + start_of_compressed - get_eip]
section PESOUNC0
lea edi, [esi + start_of_uncompressed]
section PEICONS1
incw [edi + icon_offset]