watcom/le using nrv2e converted to ElfLinker
This commit is contained in:
+49
-27
@@ -32,6 +32,7 @@
|
|||||||
#include "packer.h"
|
#include "packer.h"
|
||||||
#include "lefile.h"
|
#include "lefile.h"
|
||||||
#include "p_wcle.h"
|
#include "p_wcle.h"
|
||||||
|
#include "linker.h"
|
||||||
|
|
||||||
static const
|
static const
|
||||||
#include "stub/i386-dos32.watcom.le.h"
|
#include "stub/i386-dos32.watcom.le.h"
|
||||||
@@ -81,15 +82,22 @@ const int *PackWcle::getFilters() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Linker* PackWcle::newLinker() const
|
||||||
|
{
|
||||||
|
return new ElfLinkerX86;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int PackWcle::buildLoader(const Filter *ft)
|
int PackWcle::buildLoader(const Filter *ft)
|
||||||
{
|
{
|
||||||
// prepare loader
|
// prepare loader
|
||||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||||
addLoader("IDENTSTR,WCLEMAIN,UPX1HEAD,WCLECUTP,+0000000",
|
addLoader("IDENTSTR,WCLEMAIN,UPX1HEAD,WCLECUTP", NULL);
|
||||||
getDecompressorSections(),
|
|
||||||
"WCLEMAI2",
|
// fake alignment for the start of the decompressor
|
||||||
NULL
|
linker->defineSymbol("WCLECUTP", 0x1000);
|
||||||
);
|
|
||||||
|
addLoader(getDecompressorSections(), "WCLEMAI2", NULL);
|
||||||
if (ft->id)
|
if (ft->id)
|
||||||
{
|
{
|
||||||
assert(ft->calls > 0);
|
assert(ft->calls > 0);
|
||||||
@@ -134,6 +142,20 @@ bool PackWcle::canPack()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool defineFilterSymbols(Linker *linker, const Filter *ft)
|
||||||
|
{
|
||||||
|
if (ft->id == 0)
|
||||||
|
return false;
|
||||||
|
assert(ft->calls > 0);
|
||||||
|
|
||||||
|
linker->defineSymbol("filter_cto", ft->cto);
|
||||||
|
linker->defineSymbol("filter_length",
|
||||||
|
(ft->id & 0xf) % 3 == 0 ? ft->calls :
|
||||||
|
ft->lastcall - ft->calls * 4);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -497,16 +519,10 @@ void PackWcle::pack(OutputFile *fo)
|
|||||||
neweip = getLoaderSection("WCLEMAIN");
|
neweip = getLoaderSection("WCLEMAIN");
|
||||||
int e_len = getLoaderSectionStart("WCLECUTP");
|
int e_len = getLoaderSectionStart("WCLECUTP");
|
||||||
const unsigned d_len = lsize - e_len;
|
const unsigned d_len = lsize - e_len;
|
||||||
assert(e_len > 0);
|
assert(e_len > 0 && e_len < RESERVED);
|
||||||
|
|
||||||
getLoader();
|
|
||||||
|
|
||||||
memcpy(oimage,getLoader(),e_len);
|
|
||||||
memmove(oimage+e_len,oimage+RESERVED,soimage);
|
memmove(oimage+e_len,oimage+RESERVED,soimage);
|
||||||
soimage = (soimage + e_len);
|
soimage += lsize;
|
||||||
|
|
||||||
memcpy(oimage+soimage,getLoader() + e_len,d_len);
|
|
||||||
soimage += d_len;
|
|
||||||
|
|
||||||
opages = (soimage+mps-1)/mps;
|
opages = (soimage+mps-1)/mps;
|
||||||
oh.bytes_on_last_page = soimage%mps;
|
oh.bytes_on_last_page = soimage%mps;
|
||||||
@@ -524,23 +540,29 @@ void PackWcle::pack(OutputFile *fo)
|
|||||||
ic = (OOT(0,virtual_size) - d_len) &~ 15;
|
ic = (OOT(0,virtual_size) - d_len) &~ 15;
|
||||||
assert(ic > ((ph.u_len + ph.overlap_overhead + 31) &~ 15));
|
assert(ic > ((ph.u_len + ph.overlap_overhead + 31) &~ 15));
|
||||||
|
|
||||||
upx_byte * const p = oimage + soimage - d_len;
|
linker->defineSymbol("WCLECUTP", ic);
|
||||||
patch_le32(p,d_len,"JMPO",ih.init_eip_offset+text_vaddr-(ic+d_len));
|
|
||||||
patch_le32(p,d_len,"ESP0",ih.init_esp_offset+IOT(ih.init_ss_object-1,my_base_address));
|
|
||||||
if (patchFilter32(p, d_len, &ft) && text_vaddr)
|
|
||||||
patch_le32(p, d_len, "TEXV", text_vaddr);
|
|
||||||
patch_le32(p,d_len,"RELO",mps*pages);
|
|
||||||
|
|
||||||
patchDecompressor(p, d_len);
|
linker->defineSymbol("original_entry", ih.init_eip_offset + text_vaddr);
|
||||||
patchPackHeader(oimage,e_len);
|
linker->defineSymbol("original_stack", ih.init_esp_offset +
|
||||||
|
IOT(ih.init_ss_object - 1, my_base_address));
|
||||||
|
linker->defineSymbol("start_of_relocs", mps*pages);
|
||||||
|
defineFilterSymbols(linker, &ft);
|
||||||
|
linker->defineSymbol("filter_buffer_start", text_vaddr);
|
||||||
|
// FIXME patchDecompressor(loader, lsize);
|
||||||
|
|
||||||
unsigned jpos = find_le32(oimage,e_len,get_le32("JMPD"));
|
unsigned jpos = (((ph.c_len + 3) &~ 3) + d_len + 3) / 4;
|
||||||
patch_le32(oimage,e_len,"JMPD",ic-jpos-4);
|
linker->defineSymbol("words_to_copy", jpos);
|
||||||
|
linker->defineSymbol("copy_dest", ((ic + d_len + 3) &~ 3) - 4);
|
||||||
|
linker->defineSymbol("copy_source", e_len + jpos * 4 - 4);
|
||||||
|
|
||||||
jpos = (((ph.c_len+3)&~3) + d_len+3)/4;
|
linker->relocate();
|
||||||
patch_le32(oimage,e_len,"ECX0",jpos);
|
|
||||||
patch_le32(oimage,e_len,"EDI0",((ic+d_len+3)&~3)-4);
|
MemBuffer loader(lsize);
|
||||||
patch_le32(oimage,e_len,"ESI0",e_len+jpos*4-4);
|
memcpy(loader, getLoader(), lsize);
|
||||||
|
patchPackHeader(loader, lsize);
|
||||||
|
|
||||||
|
memcpy(oimage, loader, e_len);
|
||||||
|
memcpy(oimage + soimage - d_len, loader + e_len, d_len);
|
||||||
|
|
||||||
writeFile(fo, opt->watcom_le.le);
|
writeFile(fo, opt->watcom_le.le);
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ protected:
|
|||||||
virtual void handleStub(OutputFile *fo);
|
virtual void handleStub(OutputFile *fo);
|
||||||
|
|
||||||
virtual int buildLoader(const Filter *ft);
|
virtual int buildLoader(const Filter *ft);
|
||||||
|
virtual Linker* newLinker() const;
|
||||||
|
|
||||||
virtual void readObjectTable();
|
virtual void readObjectTable();
|
||||||
virtual void encodeObjectTable();
|
virtual void encodeObjectTable();
|
||||||
|
|||||||
+5
-3
@@ -347,9 +347,11 @@ i386-dos32.tmt.h : $(srcdir)/src/$$T.asm
|
|||||||
i386-dos32.watcom.le% : tc_list = arch-i386 default
|
i386-dos32.watcom.le% : tc_list = arch-i386 default
|
||||||
|
|
||||||
i386-dos32.watcom.le.h : $(srcdir)/src/$$T.asm
|
i386-dos32.watcom.le.h : $(srcdir)/src/$$T.asm
|
||||||
$(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1
|
$(call tc,gcc) -c -x assembler-with-cpp $< -o tmp/$T.bin
|
||||||
$(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2
|
$(call tc,m-objcopy) --strip-unneeded tmp/$T.bin
|
||||||
$(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin
|
$(call tc,m-objcopy) -R .text -R .data -R .bss tmp/$T.bin
|
||||||
|
$(call tc,m-objcopy) -R .note -R .comment tmp/$T.bin
|
||||||
|
$(call tc,m-objdump) -trwh tmp/$T.bin >> tmp/$T.bin
|
||||||
$(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@
|
$(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1023
-579
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
|||||||
|
/*
|
||||||
; l_wcle.asm -- loader & decompressor for the watcom/le format
|
; l_wcle.asm -- loader & decompressor for the watcom/le format
|
||||||
;
|
;
|
||||||
; This file is part of the UPX executable compressor.
|
; This file is part of the UPX executable compressor.
|
||||||
@@ -24,39 +25,31 @@
|
|||||||
; Markus F.X.J. Oberhumer Laszlo Molnar
|
; Markus F.X.J. Oberhumer Laszlo Molnar
|
||||||
; <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
; <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||||
;
|
;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "arch/i386/macros2.ash"
|
||||||
|
|
||||||
%define jmps jmp short
|
|
||||||
%define jmpn jmp near
|
|
||||||
%include "arch/i386/macros.ash"
|
|
||||||
|
|
||||||
BITS 32
|
|
||||||
SECTION .text
|
|
||||||
ORG 0
|
|
||||||
CPU 386
|
CPU 386
|
||||||
|
|
||||||
; =============
|
section WCLEMAIN
|
||||||
; ============= ENTRY POINT
|
.byte 0xbf // mov edi, 'alib'
|
||||||
; =============
|
.ascii "alib" // address of obj#1:0 (filled by a fixup record)
|
||||||
|
/*
|
||||||
start:
|
|
||||||
; __WCLEMAIN__
|
|
||||||
mov edi, 'alib' ; address of obj#1:0 (filled by a fixup record)
|
|
||||||
|
|
||||||
; The following hack fools the lame protection of dos4g/w, which expects the
|
; The following hack fools the lame protection of dos4g/w, which expects the
|
||||||
; 'WATCOM' string somewhere in the first 18 bytes after the entry point
|
; 'WATCOM' string somewhere in the first 18 bytes after the entry point
|
||||||
; I use this imul thingy, because it's 1 byte shorter than a jump ;-)
|
; I use this imul thingy, because it's 1 byte shorter than a jump ;-)
|
||||||
; ... and "alibiWATCOM" looks cool
|
; ... and "alibiWATCOM" looks cool
|
||||||
db 'iWATCOM' ; imul edx,[edi+0x41],'TCOM'
|
*/
|
||||||
|
.ascii "iWATCOM" // imul edx,[edi+0x41],'TCOM'
|
||||||
|
|
||||||
push es
|
push es
|
||||||
push ds
|
push ds
|
||||||
pop es
|
pop es
|
||||||
push edi
|
push edi
|
||||||
|
|
||||||
lea esi, [edi + 'ESI0']
|
lea esi, [edi + copy_source]
|
||||||
lea edi, [edi + 'EDI0']
|
lea edi, [edi + copy_dest]
|
||||||
mov ecx, 'ECX0'
|
mov ecx, offset words_to_copy
|
||||||
|
|
||||||
std
|
std
|
||||||
rep
|
rep
|
||||||
@@ -65,80 +58,65 @@ start:
|
|||||||
|
|
||||||
lea esi, [edi + 4]
|
lea esi, [edi + 4]
|
||||||
pop edi
|
pop edi
|
||||||
or ebp, byte -1
|
or ebp, -1
|
||||||
push edi
|
push edi
|
||||||
jmpn .1+'JMPD'
|
jmp decompressor
|
||||||
.1:
|
|
||||||
%include "include/header.ash"
|
|
||||||
|
|
||||||
cutpoint:
|
#include "include/header2.ash"
|
||||||
; __WCLECUTP__
|
|
||||||
|
|
||||||
; =============
|
section WCLECUTP
|
||||||
; ============= DECOMPRESSION
|
decompressor:
|
||||||
; =============
|
|
||||||
|
|
||||||
%include "arch/i386/nrv2b_d32.ash"
|
// =============
|
||||||
%include "arch/i386/nrv2d_d32.ash"
|
// ============= DECOMPRESSION
|
||||||
%include "arch/i386/nrv2e_d32.ash"
|
// =============
|
||||||
%include "arch/i386/lzma_d.ash"
|
|
||||||
|
|
||||||
; =============
|
//#include "arch/i386/nrv2b_d32.ash"
|
||||||
|
//#include "arch/i386/nrv2d_d32.ash"
|
||||||
|
#include "arch/i386/nrv2e_d32_2.ash"
|
||||||
|
//#include "arch/i386/lzma_d.ash"
|
||||||
|
|
||||||
; __WCLEMAI2__
|
// =============
|
||||||
|
|
||||||
|
section WCLEMAI2
|
||||||
pop ebp
|
pop ebp
|
||||||
push esi
|
push esi
|
||||||
lea esi, [ebp + 'RELO']
|
lea esi, [ebp + start_of_relocs]
|
||||||
push esi
|
push esi
|
||||||
|
|
||||||
; =============
|
// =============
|
||||||
; ============= CALLTRICK
|
// ============= CALLTRICK
|
||||||
; =============
|
// =============
|
||||||
|
|
||||||
%ifdef __WCALLTRI__
|
section WCCTTPOS
|
||||||
%ifdef __WCCTTPOS__
|
lea edi, [ebp + filter_buffer_start]
|
||||||
lea edi, [ebp + 'TEXV']
|
section WCCTTNUL
|
||||||
%else; __WCCTTNUL__
|
|
||||||
mov edi, ebp
|
mov edi, ebp
|
||||||
%endif; __WCALLTR1__
|
section WCALLTR1
|
||||||
cjt32 ebp
|
cjt32 ebp
|
||||||
%endif; __WCDUMMY1__
|
|
||||||
|
|
||||||
; =============
|
// =============
|
||||||
; ============= RELOCATION
|
// ============= RELOCATION
|
||||||
; =============
|
// =============
|
||||||
|
|
||||||
%ifdef __WCRELOC1__
|
section WCRELOC1
|
||||||
lea edi, [ebp - 4]
|
lea edi, [ebp - 4]
|
||||||
reloc32 esi, edi, ebp
|
reloc32 esi, edi, ebp
|
||||||
; eax = 0
|
// eax = 0
|
||||||
%endif; __WCDUMMY2__
|
|
||||||
|
|
||||||
%ifdef __WCRELSEL__
|
section WCRELSEL
|
||||||
call esi ; selector fixup code (modifies bx)
|
call esi // selector fixup code (modifies bx)
|
||||||
%endif; __WCLEMAI4__
|
|
||||||
|
|
||||||
; =============
|
|
||||||
|
|
||||||
|
section WCLEMAI4
|
||||||
pop edi
|
pop edi
|
||||||
pop ecx
|
pop ecx
|
||||||
sub ecx, edi
|
sub ecx, edi
|
||||||
shr ecx, 2
|
shr ecx, 2
|
||||||
rep
|
rep
|
||||||
stosd ; clear dirty memory
|
stosd // clear dirty memory
|
||||||
pop es
|
pop es
|
||||||
lea esp, [ebp + 'ESP0']
|
lea esp, [ebp + original_stack]
|
||||||
|
|
||||||
jmpn .1+'JMPO'
|
jmp original_entry
|
||||||
.1:
|
|
||||||
|
|
||||||
; =============
|
// vi:ts=8:et:nowrap
|
||||||
|
|
||||||
eof:
|
|
||||||
; __WCTHEEND__
|
|
||||||
section .data
|
|
||||||
dd -1
|
|
||||||
dw eof
|
|
||||||
|
|
||||||
|
|
||||||
; vi:ts=8:et:nowrap
|
|
||||||
|
|||||||
Reference in New Issue
Block a user