PE: Add position independent decompressor stub for i386
This commit is contained in:
committed by
Markus F.X.J. Oberhumer
parent
7f1f29b0d8
commit
76ddf6b8da
+9
-5
@@ -110,14 +110,17 @@ void PackW32Pe::buildLoader(const Filter *ft)
|
|||||||
|
|
||||||
// prepare loader
|
// prepare loader
|
||||||
initLoader(stub_i386_win32_pe, sizeof(stub_i386_win32_pe), 2);
|
initLoader(stub_i386_win32_pe, sizeof(stub_i386_win32_pe), 2);
|
||||||
addLoader(isdll ? "PEISDLL1" : "",
|
if (isdll)
|
||||||
"PEMAIN01",
|
addLoader("PEISDLL1");
|
||||||
|
addLoader("PEMAIN01",
|
||||||
|
use_stub_relocs ? "PESOCREL" : "PESOCPIC",
|
||||||
|
"PESOUNC0",
|
||||||
icondir_count > 1 ? (icondir_count == 2 ? "PEICONS1" : "PEICONS2") : "",
|
icondir_count > 1 ? (icondir_count == 2 ? "PEICONS1" : "PEICONS2") : "",
|
||||||
tmp_tlsindex ? "PETLSHAK" : "",
|
tmp_tlsindex ? "PETLSHAK" : "",
|
||||||
"PEMAIN02",
|
"PEMAIN02",
|
||||||
ph.first_offset_found == 1 ? "PEMAIN03" : "",
|
ph.first_offset_found == 1 ? "PEMAIN03" : "",
|
||||||
getDecompressorSections(),
|
getDecompressorSections(),
|
||||||
/*multipass ? "PEMULTIP" : */ "",
|
//multipass ? "PEMULTIP" : "",
|
||||||
"PEMAIN10",
|
"PEMAIN10",
|
||||||
nullptr
|
nullptr
|
||||||
);
|
);
|
||||||
@@ -255,7 +258,7 @@ void PackW32Pe::defineSymbols(unsigned ncsection, unsigned upxsection,
|
|||||||
|
|
||||||
const unsigned esi0 = s1addr + ic;
|
const unsigned esi0 = s1addr + ic;
|
||||||
linker->defineSymbol("start_of_uncompressed", 0u - esi0 + rvamin);
|
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)
|
if (use_tls_callbacks)
|
||||||
{
|
{
|
||||||
@@ -270,7 +273,8 @@ void PackW32Pe::defineSymbols(unsigned ncsection, unsigned upxsection,
|
|||||||
|
|
||||||
void PackW32Pe::addNewRelocations(Reloc &rel, unsigned base)
|
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)
|
void PackW32Pe::setOhDataBase(const pe_section_t *osection)
|
||||||
|
|||||||
+3
-1
@@ -47,7 +47,9 @@ static const
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
PackW64Pep::PackW64Pep(InputFile *f) : super(f)
|
PackW64Pep::PackW64Pep(InputFile *f) : super(f)
|
||||||
{}
|
{
|
||||||
|
use_stub_relocs = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PackW64Pep::~PackW64Pep()
|
PackW64Pep::~PackW64Pep()
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ PeFile::PeFile(InputFile *f) : super(f)
|
|||||||
|
|
||||||
use_dep_hack = true;
|
use_dep_hack = true;
|
||||||
use_clear_dirty_stack = true;
|
use_clear_dirty_stack = true;
|
||||||
|
use_stub_relocs = true;
|
||||||
isrtm = false;
|
isrtm = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ protected:
|
|||||||
bool isrtm;
|
bool isrtm;
|
||||||
bool use_dep_hack;
|
bool use_dep_hack;
|
||||||
bool use_clear_dirty_stack;
|
bool use_clear_dirty_stack;
|
||||||
|
bool use_stub_relocs;
|
||||||
|
|
||||||
|
|
||||||
static unsigned virta2objnum (unsigned, pe_section_t *, unsigned);
|
static unsigned virta2objnum (unsigned, pe_section_t *, unsigned);
|
||||||
|
|||||||
@@ -40,7 +40,14 @@ section PEISDLL1
|
|||||||
jnz reloc_end_jmp
|
jnz reloc_end_jmp
|
||||||
section PEMAIN01
|
section PEMAIN01
|
||||||
pusha
|
pusha
|
||||||
|
section PESOCREL
|
||||||
mov esi, offset start_of_compressed // relocated
|
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]
|
lea edi, [esi + start_of_uncompressed]
|
||||||
section PEICONS1
|
section PEICONS1
|
||||||
incw [edi + icon_offset]
|
incw [edi + icon_offset]
|
||||||
|
|||||||
Reference in New Issue
Block a user