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

Added lzma for dos/exe. Glue code and integration is still missing.

This commit is contained in:
Markus F.X.J. Oberhumer 2007-02-11 07:54:16 +01:00
parent d008c834be
commit 44ed84f5cf
9 changed files with 5623 additions and 904 deletions

View File

@ -179,6 +179,7 @@ tc.default.sstrip = sstrip
tc.default.xstrip = python $(top_srcdir)/src/stub/scripts/xstrip.py
# default multiarch-binutils
tc.default.m-ar = multiarch-ar-2.17
tc.default.m-ld = multiarch-ld-2.17 $(if $(tc_bfdname),-b $(tc_bfdname))
tc.default.m-nm = multiarch-nm-2.17 $(if $(tc_bfdname),--target=$(tc_bfdname))
tc.default.m-objcopy = multiarch-objcopy-2.17 $(if $(tc_bfdname),-F $(tc_bfdname))

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,9 @@ vpath %.c $(top_srcdir)/src/stub/src/c
STUBS =
ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),)
ifneq ($(wildcard $(WATCOM)/binl/.),)
STUBS += lzma_d_cf.S ##lzma_d_cs.S
ifneq ($(wildcard $(VCLINK.exe)),)
STUBS += lzma_d_cf.S lzma_d_cs.S
endif
endif
endif
@ -98,22 +100,18 @@ tc.method-lzma.dmpobj = $(WATCOM)/binl/dmpobj
tc.method-lzma.wdis = $(WATCOM)/binl/wdis
tc.method-lzma.wdump = $(WATCOM)/binl/wdump
lzma_d_c%.S : lzma_d_c.c $(MAKEFILE_LIST)
lzma_d_c%.S : lzma_d_c.c cleanasm.py $(MAKEFILE_LIST)
$(call tc,wcc) $(PP_FLAGS) -fo=tmp/$T.obj $<
$(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
## $(call tc,dmc) $(PP_FLAGS) -c -otmp/$T.obj $<
## $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
## $(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T.obj $<
## $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
## $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T.obj $<
## $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
FIXME:
$(call tc,f-objstrip,tmp/$T.o)
$(call tc,objcopy) -O binary --only-section .text.LzmaDecode tmp/$T.o tmp/$T.bin
head -c-1 tmp/$T.bin > tmp/$T.out
$(call tc,objdump) -b binary -m i386 -D tmp/$T.out | $(RTRIM) > tmp/$T.out.disasm
$(call tc,bin2h) --mode=gas tmp/$T.out $@
## $(call tc,dmc) $(PP_FLAGS) -c -otmp/$T.obj $<
## $(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T.obj $<
$(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm
cp tmp/$T.obj tmp/$T.o
rm -f tmp/$T.lib
cd tmp && $(WINEENV) wine $(VCLINK.exe) -lib -nologo -out:$T.lib $T.o
cd tmp && $(call tc,m-ar) x $T.lib
$(call tc,objdump) -b coff-i386 -m i8086 -M intel -Dr --no-show -w tmp/$T.o | $(RTRIM) > tmp/$T.o.disasm
python cleanasm.py --label-prefix=$(LABEL_PREFIX) tmp/$T.o.disasm $@
lzma_d_cf.% : PP_FLAGS = -DFAST
lzma_d_cs.% : PP_FLAGS = -DSMALL

View File

@ -0,0 +1,119 @@
#! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
#
# cleanasm.py --
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
import getopt, os, re, string, sys
class opts:
label_prefix = ".L"
verbose = 0
# /***********************************************************************
# // main
# ************************************************************************/
def main(argv):
shortopts, longopts = "qv", [
"label-prefix=", "quiet", "verbose"
]
xopts, args = getopt.gnu_getopt(argv[1:], shortopts, longopts)
for opt, optarg in xopts:
if 0: pass
elif opt in ["-q", "--quiet"]: opts.verbose = opts.verbose - 1
elif opt in ["-v", "--verbose"]: opts.verbose = opts.verbose + 1
elif opt in ["--label-prefix"]: opts.label_prefix = optarg
else: assert 0, ("getopt problem:", opt, optarg, xopts, args)
#
assert len(args) == 2
ifile = args[0]
ofile = args[1]
# read ifile
lines = open(ifile, "rb").readlines()
lines = filter(None, map(string.rstrip, lines))
#
olines = []
labels = {}
for i in range(len(lines)):
l = lines[i]
m = re.search("^(\s*[0-9a-z]+):\s+(\w+)(.*)", l)
if not m:
continue
label = m.group(1).strip()
inst = m.group(2).strip()
args = ""
if m.group(3): args = m.group(3).strip()
args_label = None
if label == "0" and olines: # start of next function
break
if inst in ["call",]:
args = re.sub(r"^(.*?)2\s+(__\w+)$", "\g<2>", args)
elif inst in [
"ja", "jae", "jb", "jbe", "jcxz", "je", "jge", "jl", "jmp", "jne", "loop",
]:
m = re.search("^([0-9a-z]+)\s+<", args)
assert m, l
if m:
labels[m.group(1)] = ""
args_label = m.group(1)
args = None
elif inst in ["movl",]:
assert re.search(r"\b[de]s\b", args), args
inst = "movw"
olines.append((label, inst, args, args_label))
#
digits, i = 1, len(labels)
while i >= 10:
digits += 1
i /= 10
format = "%s0%dd" % ("%", digits)
i = 0
for label, inst, args, args_label in olines:
if labels.has_key(label):
labels[label] = opts.label_prefix + format % i
i += 1
# write ofile
ofp = open(ofile, "wb")
for label, inst, args, args_label in olines:
if labels.has_key(label):
ofp.write(labels[label] + ":\n")
if args_label: args = labels[args_label]
l = "%8s%-7s %s" % ("", inst, args)
ofp.write(l.rstrip() + "\n")
ofp.close()
##print olines
if __name__ == "__main__":
sys.exit(main(sys.argv))

View File

@ -0,0 +1,58 @@
/*
; lzma_d.ash -- 16-bit assembly
;
; This file is part of the UPX executable compressor.
;
; Copyright (C) 2006-2007 Markus Franz Xaver Johannes Oberhumer
; All Rights Reserved.
;
; UPX and the UCL library are free software; you can redistribute them
; and/or modify them under the terms of the GNU General Public License as
; published by the Free Software Foundation; either version 2 of
; the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; see the file COPYING.
; If not, write to the Free Software Foundation, Inc.,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;
; Markus F.X.J. Oberhumer
; <markus@oberhumer.com>
; http://www.oberhumer.com/opensource/upx/
;
; ------------- DECOMPRESSION -------------
; Input:
; si - source
; di - dest
; cld
; Output:
*/
// init
section LZMA_DEC00
section LZMA_DEC10
.arch i8086, nojumps
#include "lzma_d_cs.S"
section LZMA_DEC20
.arch i8086, nojumps
#include "lzma_d_cf.S"
.arch i8086, jumps
// cleanup
section LZMA_DEC30
// vi:ts=8:et

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -117,7 +117,7 @@ section EXECUTPO
#include "arch/i086/nrv2b_d8.S"
#include "arch/i086/nrv2d_d8.S"
#include "arch/i086/nrv2e_d8.S"
//#include "arch/i086/lzma_d.S"
#include "arch/i086/lzma_d.S"
section EXEMAIN5
pop bp
@ -219,29 +219,19 @@ section EXERETIP
lret
section wcc_pia_086
section __PIA
M_WCC_PIA_086
ret
section wcc_pia_286
CPU 286
M_WCC_PIA_286
CPU 8086
ret
section wcc_pis_086
M_WCC_PIS_086
ret
section wcc_pis_286
CPU 286
M_WCC_PIS_286
CPU 8086
ret
section wcc_pts
//section __PIS
// M_WCC_PIS_086
// ret
section __PTS
M_WCC_PTS
ret
section wcc_ptc
section __PTC
M_WCC_PTC
ret
section wcc_u4m
section __U4M
M_WCC_U4M
ret

View File

@ -44,28 +44,29 @@ Idx Name Size VMA LMA File off Algn Flags
39 NRV2EEX3 00000015 00000000 00000000 0000027b 2**0 CONTENTS, RELOC, READONLY
40 N2E64K02 0000000b 00000000 00000000 00000290 2**0 CONTENTS, READONLY
41 NRV2EEX9 00000004 00000000 00000000 0000029b 2**0 CONTENTS, READONLY
42 EXEMAIN5 00000001 00000000 00000000 0000029f 2**0 CONTENTS, READONLY
43 EXEADJUS 00000007 00000000 00000000 000002a0 2**0 CONTENTS, READONLY
44 EXENOADJ 00000002 00000000 00000000 000002a7 2**0 CONTENTS, READONLY
45 EXERELO1 0000001e 00000000 00000000 000002a9 2**0 CONTENTS, RELOC, READONLY
46 EXEREL9A 00000012 00000000 00000000 000002c7 2**0 CONTENTS, RELOC, READONLY
47 EXERELO2 00000004 00000000 00000000 000002d9 2**0 CONTENTS, READONLY
48 EXEREBIG 00000002 00000000 00000000 000002dd 2**0 CONTENTS, RELOC, READONLY
49 EXERELO3 00000002 00000000 00000000 000002df 2**0 CONTENTS, RELOC, READONLY
50 EXEMAIN8 00000003 00000000 00000000 000002e1 2**0 CONTENTS, READONLY
51 DEVICEEND 00000013 00000000 00000000 000002e4 2**0 CONTENTS, READONLY
52 EXESTACK 00000006 00000000 00000000 000002f7 2**0 CONTENTS, RELOC, READONLY
53 EXESTASP 00000003 00000000 00000000 000002fd 2**0 CONTENTS, RELOC, READONLY
54 EXEJUMPF 00000005 00000000 00000000 00000300 2**0 CONTENTS, RELOC, READONLY
55 EXERCSPO 00000004 00000000 00000000 00000305 2**0 CONTENTS, RELOC, READONLY
56 EXERETIP 00000006 00000000 00000000 00000309 2**0 CONTENTS, RELOC, READONLY
57 wcc_pia_086 0000000e 00000000 00000000 0000030f 2**0 CONTENTS, READONLY
58 wcc_pia_286 0000000b 00000000 00000000 0000031d 2**0 CONTENTS, READONLY
59 wcc_pis_086 0000000e 00000000 00000000 00000328 2**0 CONTENTS, READONLY
60 wcc_pis_286 0000000b 00000000 00000000 00000336 2**0 CONTENTS, READONLY
61 wcc_pts 00000005 00000000 00000000 00000341 2**0 CONTENTS, READONLY
62 wcc_ptc 00000007 00000000 00000000 00000346 2**0 CONTENTS, READONLY
63 wcc_u4m 00000003 00000000 00000000 0000034d 2**0 CONTENTS, READONLY
42 LZMA_DEC00 00000000 00000000 00000000 0000029f 2**0 CONTENTS, READONLY
43 LZMA_DEC10 00001191 00000000 00000000 0000029f 2**0 CONTENTS, RELOC, READONLY
44 LZMA_DEC20 00001191 00000000 00000000 00001430 2**0 CONTENTS, RELOC, READONLY
45 LZMA_DEC30 00000000 00000000 00000000 000025c1 2**0 CONTENTS, READONLY
46 EXEMAIN5 00000001 00000000 00000000 000025c1 2**0 CONTENTS, READONLY
47 EXEADJUS 00000007 00000000 00000000 000025c2 2**0 CONTENTS, READONLY
48 EXENOADJ 00000002 00000000 00000000 000025c9 2**0 CONTENTS, READONLY
49 EXERELO1 0000001e 00000000 00000000 000025cb 2**0 CONTENTS, RELOC, READONLY
50 EXEREL9A 00000012 00000000 00000000 000025e9 2**0 CONTENTS, RELOC, READONLY
51 EXERELO2 00000004 00000000 00000000 000025fb 2**0 CONTENTS, READONLY
52 EXEREBIG 00000002 00000000 00000000 000025ff 2**0 CONTENTS, RELOC, READONLY
53 EXERELO3 00000002 00000000 00000000 00002601 2**0 CONTENTS, RELOC, READONLY
54 EXEMAIN8 00000003 00000000 00000000 00002603 2**0 CONTENTS, READONLY
55 DEVICEEND 00000013 00000000 00000000 00002606 2**0 CONTENTS, READONLY
56 EXESTACK 00000006 00000000 00000000 00002619 2**0 CONTENTS, RELOC, READONLY
57 EXESTASP 00000003 00000000 00000000 0000261f 2**0 CONTENTS, RELOC, READONLY
58 EXEJUMPF 00000005 00000000 00000000 00002622 2**0 CONTENTS, RELOC, READONLY
59 EXERCSPO 00000004 00000000 00000000 00002627 2**0 CONTENTS, RELOC, READONLY
60 EXERETIP 00000006 00000000 00000000 0000262b 2**0 CONTENTS, RELOC, READONLY
61 __PIA 0000000e 00000000 00000000 00002631 2**0 CONTENTS, READONLY
62 __PTS 00000005 00000000 00000000 0000263f 2**0 CONTENTS, READONLY
63 __PTC 00000007 00000000 00000000 00002644 2**0 CONTENTS, READONLY
64 __U4M 00000003 00000000 00000000 0000264b 2**0 CONTENTS, READONLY
SYMBOL TABLE:
00000000 l d DEVICEENTRY 00000000 DEVICEENTRY
00000000 l d EXEENTRY 00000000 EXEENTRY
@ -81,6 +82,10 @@ SYMBOL TABLE:
00000000 l d NRV2EEX2 00000000 NRV2EEX2
00000000 l d NRV2EEX3 00000000 NRV2EEX3
00000000 l d NRV2EEX9 00000000 NRV2EEX9
00000000 l d __PIA 00000000 __PIA
00000000 l d __PTC 00000000 __PTC
00000000 l d __U4M 00000000 __U4M
00000000 l d __PTS 00000000 __PTS
00000000 l d EXERELO1 00000000 EXERELO1
00000000 l d EXERELO2 00000000 EXERELO2
00000000 l d DEVICESUB 00000000 DEVICESUB
@ -111,6 +116,10 @@ SYMBOL TABLE:
00000000 l d N2EX8602 00000000 N2EX8602
00000000 l d N2E28602 00000000 N2E28602
00000000 l d N2E64K02 00000000 N2E64K02
00000000 l d LZMA_DEC00 00000000 LZMA_DEC00
00000000 l d LZMA_DEC10 00000000 LZMA_DEC10
00000000 l d LZMA_DEC20 00000000 LZMA_DEC20
00000000 l d LZMA_DEC30 00000000 LZMA_DEC30
00000000 l d EXEMAIN5 00000000 EXEMAIN5
00000000 l d EXEADJUS 00000000 EXEADJUS
00000000 l d EXENOADJ 00000000 EXENOADJ
@ -124,13 +133,6 @@ SYMBOL TABLE:
00000000 l d EXEJUMPF 00000000 EXEJUMPF
00000000 l d EXERCSPO 00000000 EXERCSPO
00000000 l d EXERETIP 00000000 EXERETIP
00000000 l d wcc_pia_086 00000000 wcc_pia_086
00000000 l d wcc_pia_286 00000000 wcc_pia_286
00000000 l d wcc_pis_086 00000000 wcc_pis_086
00000000 l d wcc_pis_286 00000000 wcc_pis_286
00000000 l d wcc_pts 00000000 wcc_pts
00000000 l d wcc_ptc 00000000 wcc_ptc
00000000 l d wcc_u4m 00000000 wcc_u4m
00000000 *UND* 00000000 attribute
00000000 *UND* 00000000 interrupt
00000000 *UND* 00000000 orig_strategy
@ -246,6 +248,118 @@ OFFSET TYPE VALUE
00000005 R_386_PC8 NRV2EEX2
00000012 R_386_PC8 NRV2EEX9
RELOCATION RECORDS FOR [LZMA_DEC10]:
OFFSET TYPE VALUE
000000ec R_386_PC16 __PIA
00000137 R_386_PC16 __PIA
00000153 R_386_PC16 __PTC
000001a7 R_386_PC16 __PTC
000001e5 R_386_PC16 __PIA
0000020c R_386_PC16 __U4M
00000277 R_386_PC16 __U4M
000002ab R_386_PC16 __PIA
000002f2 R_386_PC16 __PTC
00000333 R_386_PC16 __PIA
0000035a R_386_PC16 __U4M
000003f1 R_386_PC16 __PTC
00000432 R_386_PC16 __PIA
00000459 R_386_PC16 __U4M
000004cf R_386_PC16 __PIA
00000542 R_386_PC16 __PTC
00000583 R_386_PC16 __PIA
000005aa R_386_PC16 __U4M
0000065f R_386_PC16 __PTC
000006a0 R_386_PC16 __PIA
000006c7 R_386_PC16 __U4M
000006da R_386_PC16 __PIA
0000073d R_386_PC16 __PTC
000007a0 R_386_PC16 __U4M
000007ff R_386_PC16 __PIA
00000820 R_386_PC16 __PIA
00000894 R_386_PC16 __PTC
000008f3 R_386_PC16 __U4M
0000096e R_386_PC16 __PTC
000009af R_386_PC16 __PIA
000009d6 R_386_PC16 __U4M
00000a96 R_386_PC16 __PTC
00000ad7 R_386_PC16 __PIA
00000b01 R_386_PC16 __U4M
00000b8f R_386_PC16 __PTC
00000bd0 R_386_PC16 __PIA
00000bfa R_386_PC16 __U4M
00000caa R_386_PC16 __PTC
00000ceb R_386_PC16 __PIA
00000d12 R_386_PC16 __U4M
00000ddc R_386_PC16 __PTC
00000e1d R_386_PC16 __PIA
00000e44 R_386_PC16 __U4M
00000f13 R_386_PC16 __PTC
00000f54 R_386_PC16 __PIA
00000fd0 R_386_PC16 __PTC
00001011 R_386_PC16 __PIA
00001038 R_386_PC16 __U4M
000010eb R_386_PC16 __PIA
0000110f R_386_PC16 __PIA
0000114a R_386_PC16 __PTC
0000115c R_386_PC16 __PIA
0000116f R_386_PC16 __PTS
RELOCATION RECORDS FOR [LZMA_DEC20]:
OFFSET TYPE VALUE
000000ec R_386_PC16 __PIA
00000137 R_386_PC16 __PIA
00000153 R_386_PC16 __PTC
000001a7 R_386_PC16 __PTC
000001e5 R_386_PC16 __PIA
0000020c R_386_PC16 __U4M
00000277 R_386_PC16 __U4M
000002ab R_386_PC16 __PIA
000002f2 R_386_PC16 __PTC
00000333 R_386_PC16 __PIA
0000035a R_386_PC16 __U4M
000003f1 R_386_PC16 __PTC
00000432 R_386_PC16 __PIA
00000459 R_386_PC16 __U4M
000004cf R_386_PC16 __PIA
00000542 R_386_PC16 __PTC
00000583 R_386_PC16 __PIA
000005aa R_386_PC16 __U4M
0000065f R_386_PC16 __PTC
000006a0 R_386_PC16 __PIA
000006c7 R_386_PC16 __U4M
000006da R_386_PC16 __PIA
0000073d R_386_PC16 __PTC
000007a0 R_386_PC16 __U4M
000007ff R_386_PC16 __PIA
00000820 R_386_PC16 __PIA
00000894 R_386_PC16 __PTC
000008f3 R_386_PC16 __U4M
0000096e R_386_PC16 __PTC
000009af R_386_PC16 __PIA
000009d6 R_386_PC16 __U4M
00000a96 R_386_PC16 __PTC
00000ad7 R_386_PC16 __PIA
00000b01 R_386_PC16 __U4M
00000b8f R_386_PC16 __PTC
00000bd0 R_386_PC16 __PIA
00000bfa R_386_PC16 __U4M
00000caa R_386_PC16 __PTC
00000ceb R_386_PC16 __PIA
00000d12 R_386_PC16 __U4M
00000ddc R_386_PC16 __PTC
00000e1d R_386_PC16 __PIA
00000e44 R_386_PC16 __U4M
00000f13 R_386_PC16 __PTC
00000f54 R_386_PC16 __PIA
00000fd0 R_386_PC16 __PTC
00001011 R_386_PC16 __PIA
00001038 R_386_PC16 __U4M
000010eb R_386_PC16 __PIA
0000110f R_386_PC16 __PIA
0000114a R_386_PC16 __PTC
0000115c R_386_PC16 __PIA
0000116f R_386_PC16 __PTS
RELOCATION RECORDS FOR [EXERELO1]:
OFFSET TYPE VALUE
00000002 R_386_16 reloc_size