mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
tmp/adam using nrv2e converted to ElfLinker
This commit is contained in:
parent
6d2058c3b7
commit
fa9573436a
|
@ -31,6 +31,7 @@
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "packer.h"
|
#include "packer.h"
|
||||||
#include "p_tmt.h"
|
#include "p_tmt.h"
|
||||||
|
#include "linker.h"
|
||||||
|
|
||||||
static const
|
static const
|
||||||
#include "stub/i386-dos32.tmt.h"
|
#include "stub/i386-dos32.tmt.h"
|
||||||
|
@ -74,17 +75,25 @@ unsigned PackTmt::findOverlapOverhead(const upx_bytep buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Linker* PackTmt::newLinker() const
|
||||||
|
{
|
||||||
|
return new ElfLinkerX86;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int PackTmt::buildLoader(const Filter *ft)
|
int PackTmt::buildLoader(const Filter *ft)
|
||||||
{
|
{
|
||||||
// prepare loader
|
// prepare loader
|
||||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||||
addLoader("IDENTSTR,TMTMAIN1",
|
addLoader("IDENTSTR,TMTMAIN1",
|
||||||
ft->id ? "TMTCALT1" : "",
|
ft->id ? "TMTCALT1" : "",
|
||||||
"TMTMAIN2,UPX1HEAD,TMTCUTPO,+0XXXXXX",
|
"TMTMAIN2,UPX1HEAD,TMTCUTPO",
|
||||||
getDecompressorSections(),
|
NULL);
|
||||||
"TMTMAIN5",
|
|
||||||
NULL
|
// fake alignment for the start of the decompressor
|
||||||
);
|
linker->defineSymbol("TMTCUTPO", 0x1000);
|
||||||
|
|
||||||
|
addLoader(getDecompressorSections(), "TMTMAIN5", NULL);
|
||||||
if (ft->id)
|
if (ft->id)
|
||||||
{
|
{
|
||||||
assert(ft->calls > 0);
|
assert(ft->calls > 0);
|
||||||
|
@ -176,6 +185,19 @@ bool PackTmt::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;
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
@ -231,31 +253,31 @@ void PackTmt::pack(OutputFile *fo)
|
||||||
compressWithFilters(&ft, 512);
|
compressWithFilters(&ft, 512);
|
||||||
|
|
||||||
const unsigned lsize = getLoaderSize();
|
const unsigned lsize = getLoaderSize();
|
||||||
MemBuffer loader(lsize);
|
|
||||||
memcpy(loader,getLoader(),lsize);
|
|
||||||
|
|
||||||
const unsigned s_point = getLoaderSection("TMTMAIN1");
|
const unsigned s_point = getLoaderSection("TMTMAIN1");
|
||||||
int e_len = getLoaderSectionStart("TMTCUTPO");
|
int e_len = getLoaderSectionStart("TMTCUTPO");
|
||||||
const unsigned d_len = lsize - e_len;
|
const unsigned d_len = lsize - e_len;
|
||||||
assert(e_len > 0 && s_point > 0);
|
assert(e_len > 0 && s_point > 0);
|
||||||
|
|
||||||
// patch loader
|
// patch loader
|
||||||
patch_le32(loader,lsize,"JMPO",ih.entry-(ph.u_len+ph.overlap_overhead+d_len));
|
linker->defineSymbol("original_entry", ih.entry);
|
||||||
patchFilter32(loader, lsize, &ft);
|
defineFilterSymbols(linker, &ft);
|
||||||
patchDecompressor(loader, lsize);
|
// FIXME patchDecompressor(loader, lsize);
|
||||||
patchPackHeader(loader,e_len);
|
|
||||||
|
|
||||||
const unsigned jmp_pos = find_le32(loader,e_len,get_le32("JMPD"));
|
linker->defineSymbol("bytes_to_copy", ph.c_len + d_len);
|
||||||
patch_le32(loader,e_len,"JMPD",ph.u_len+ph.overlap_overhead-jmp_pos-4);
|
linker->defineSymbol("copy_dest", ph.u_len + ph.overlap_overhead + d_len - 1);
|
||||||
|
linker->defineSymbol("copy_source", ph.c_len + lsize - 1);
|
||||||
patch_le32(loader,e_len,"ECX0",ph.c_len+d_len);
|
|
||||||
patch_le32(loader,e_len,"EDI0",ph.u_len+ph.overlap_overhead+d_len-1);
|
|
||||||
patch_le32(loader,e_len,"ESI0",ph.c_len+e_len+d_len-1);
|
|
||||||
//fprintf(stderr,"\nelen=%x dlen=%x copy_len=%x copy_to=%x oo=%x jmp_pos=%x ulen=%x c_len=%x \n\n",
|
//fprintf(stderr,"\nelen=%x dlen=%x copy_len=%x copy_to=%x oo=%x jmp_pos=%x ulen=%x c_len=%x \n\n",
|
||||||
// e_len,d_len,copy_len,copy_to,ph.overlap_overhead,jmp_pos,ph.u_len,ph.c_len);
|
// e_len,d_len,copy_len,copy_to,ph.overlap_overhead,jmp_pos,ph.u_len,ph.c_len);
|
||||||
|
|
||||||
|
linker->defineSymbol("TMTCUTPO", ph.u_len + ph.overlap_overhead);
|
||||||
|
linker->relocate();
|
||||||
|
|
||||||
|
MemBuffer loader(lsize);
|
||||||
|
memcpy(loader,getLoader(),lsize);
|
||||||
|
patchPackHeader(loader,e_len);
|
||||||
|
|
||||||
memcpy(&oh,&ih,sizeof(oh));
|
memcpy(&oh,&ih,sizeof(oh));
|
||||||
oh.imagesize = ph.c_len+e_len+d_len; // new size
|
oh.imagesize = ph.c_len + lsize; // new size
|
||||||
oh.entry = s_point; // new entry point
|
oh.entry = s_point; // new entry point
|
||||||
oh.relocsize = 4;
|
oh.relocsize = 4;
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ protected:
|
||||||
unsigned range = 0,
|
unsigned range = 0,
|
||||||
unsigned upper_limit = ~0u) const;
|
unsigned upper_limit = ~0u) const;
|
||||||
virtual int buildLoader(const Filter *ft);
|
virtual int buildLoader(const Filter *ft);
|
||||||
|
virtual Linker* newLinker() const;
|
||||||
|
|
||||||
unsigned adam_offset;
|
unsigned adam_offset;
|
||||||
int big_relocs;
|
int big_relocs;
|
||||||
|
|
|
@ -332,9 +332,11 @@ i386-dos32.djgpp2-stubify.h : $(srcdir)/src/$$T.asm
|
||||||
i386-dos32.tmt% : tc_list = arch-i386 default
|
i386-dos32.tmt% : tc_list = arch-i386 default
|
||||||
|
|
||||||
i386-dos32.tmt.h : $(srcdir)/src/$$T.asm
|
i386-dos32.tmt.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 $@
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,4 @@
|
||||||
|
/*
|
||||||
; l_tmt.asm -- loader & decompressor for the tmt/adam format
|
; l_tmt.asm -- loader & decompressor for the tmt/adam format
|
||||||
;
|
;
|
||||||
; This file is part of the UPX executable compressor.
|
; This file is part of the UPX executable compressor.
|
||||||
|
@ -24,28 +25,23 @@
|
||||||
; 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
|
||||||
|
|
||||||
; =============
|
// =============
|
||||||
; ============= ENTRY POINT
|
// ============= ENTRY POINT
|
||||||
; =============
|
// =============
|
||||||
|
|
||||||
start:
|
start:
|
||||||
; __TMTMAIN1__
|
section TMTMAIN1
|
||||||
mov edi, 0 ; relocation offset
|
mov edi, 0 // relocated
|
||||||
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 bytes_to_copy
|
||||||
|
|
||||||
std
|
std
|
||||||
rep
|
rep
|
||||||
|
@ -54,57 +50,49 @@ start:
|
||||||
|
|
||||||
lea esi, [edi + 1]
|
lea esi, [edi + 1]
|
||||||
pop edi
|
pop edi
|
||||||
or ebp, byte -1
|
or ebp, -1
|
||||||
push edi
|
push edi
|
||||||
%ifdef __TMTCALT1__
|
section TMTCALT1
|
||||||
push edi
|
push edi
|
||||||
%endif; __TMTMAIN2__
|
section TMTMAIN2
|
||||||
jmpn .1+'JMPD'
|
jmp decompressor
|
||||||
.1:
|
|
||||||
%include "include/header.ash"
|
|
||||||
|
|
||||||
cutpoint:
|
#include "include/header2.ash"
|
||||||
; __TMTCUTPO__
|
|
||||||
|
|
||||||
; =============
|
section TMTCUTPO
|
||||||
; ============= 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"
|
|
||||||
|
|
||||||
; __TMTMAIN5__
|
//#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"
|
||||||
|
|
||||||
|
section TMTMAIN5
|
||||||
pop ebp
|
pop ebp
|
||||||
mov esi, edi
|
mov esi, edi
|
||||||
sub esi, [edi - 4]
|
sub esi, [edi - 4]
|
||||||
|
|
||||||
; =============
|
// =============
|
||||||
; ============= CALLTRICK
|
// ============= CALLTRICK
|
||||||
; =============
|
// =============
|
||||||
|
|
||||||
%ifdef __TMTCALT2__
|
section TMTCALT2
|
||||||
pop edi
|
pop edi
|
||||||
cjt32 ebp
|
cjt32 ebp
|
||||||
%endif; __TMTRELOC__
|
|
||||||
|
|
||||||
; =============
|
// =============
|
||||||
; ============= RELOCATION
|
// ============= RELOCATION
|
||||||
; =============
|
// =============
|
||||||
|
|
||||||
|
section TMTRELOC
|
||||||
lea edi, [ebp - 4]
|
lea edi, [ebp - 4]
|
||||||
reloc32 esi, edi, ebp
|
reloc32 esi, edi, ebp
|
||||||
|
|
||||||
; =============
|
section TMTJUMP1
|
||||||
; __TMTJUMP1__
|
jmp original_entry
|
||||||
jmpn .1+'JMPO'
|
|
||||||
.1:
|
|
||||||
eof:
|
|
||||||
; __TMTHEEND__
|
|
||||||
section .data
|
|
||||||
dd -1
|
|
||||||
dw eof
|
|
||||||
|
|
||||||
|
// vi:ts=8:et:nowrap
|
||||||
; vi:ts=8:et:nowrap
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user