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

stub i086: use decimal constants.

This commit is contained in:
Markus F.X.J. Oberhumer 2007-09-13 22:52:43 +02:00
parent 8d54678ea1
commit 31bb6bedbd
4 changed files with 415 additions and 404 deletions

View File

@ -160,10 +160,18 @@ endif
ifneq ($(UPX_LZMA_VERSION),) ifneq ($(UPX_LZMA_VERSION),)
ifneq ($(wildcard $(WATCOM)/binl/wcl),) ifneq ($(wildcard $(WATCOM)/binl/wcl),)
# step 3: clean asm
lzma_d_c%.S : tmp/lzma_d_c%.i cleanasm.py $(MAKEFILE_LIST) lzma_d_c%.S : tmp/lzma_d_c%.i cleanasm.py $(MAKEFILE_LIST)
$(PYTHON) cleanasm.py --label-prefix=$(LABEL_PREFIX) $< $@ $(PYTHON) cleanasm.py --label-prefix=$(LABEL_PREFIX) $< $@
tmp/lzma_d_c%.i : lzma_d_c.c wdis2gas.py $(MAKEFILE_LIST) $(TMP_DEPS) # step 2: compile, strip and disasm
tmp/lzma_d_c%.i : tmp/lzma_d_c%.S $(MAKEFILE_LIST)
$(call tc,gcc) -x assembler-with-cpp -c -o tmp/$T.o $<
$(call tc,f-objstrip,tmp/$T.o)
$(call tc,objdump) -b elf32-i386 -m i8086 -M intel -dr -j .text.LzmaDecode --no-show -w tmp/$T.o | $(RTRIM) | $(PERL) -pe 's/\bDWORD\b/dword/g; s/\bWORD\b/word/g; s/\bBYTE\b/byte/g; s/\bPTR\b/ptr/g;' > $@
# step 1: compile, disasm and convert to gas syntax
tmp/lzma_d_c%.S : lzma_d_c.c wdis2gas.py $(MAKEFILE_LIST) $(TMP_DEPS)
rm -f tmp/$T*.i tmp/$T*.o tmp/$T*.obj tmp/$T*.S rm -f tmp/$T*.i tmp/$T*.o tmp/$T*.obj tmp/$T*.S
# compile # compile
ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),) ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),)
@ -183,12 +191,9 @@ ifneq ($(wildcard $(WATCOM)/binl/wcl),)
$(call tc,wdis) tmp/$T_wc.obj | $(RTRIM) > tmp/$T_wc.obj.disasm $(call tc,wdis) tmp/$T_wc.obj | $(RTRIM) > tmp/$T_wc.obj.disasm
endif endif
# convert # convert
$(PYTHON) wdis2gas.py tmp/$T_wc.obj.disasm tmp/$T.S $(PYTHON) wdis2gas.py tmp/$T_wc.obj.disasm $@
$(call tc,gcc) -c -o tmp/$T.o tmp/$T.S
$(call tc,f-objstrip,tmp/$T.o)
$(call tc,objdump) -b elf32-i386 -m i8086 -M intel -dr -j .text.LzmaDecode --no-show -w tmp/$T.o | $(RTRIM) | $(PERL) -pe 's/\bDWORD\b/dword/g; s/\bWORD\b/word/g; s/\bBYTE\b/byte/g; s/\bPTR\b/ptr/g;' > $@
.PRECIOUS: lzma_d_c%.i tmp/lzma_d_c%.i .PRECIOUS: tmp/lzma_d_c%.i tmp/lzma_d_c%.S
endif endif
endif endif

View File

@ -76,6 +76,11 @@ def main(argv):
lines = filter(None, map(string.rstrip, lines)) lines = filter(None, map(string.rstrip, lines))
# #
# #
def inst_has_label(inst):
return inst in [
"call", "ja", "jae", "jb", "jbe", "jcxz", "je",
"jg", "jge", "jl", "jle", "jmp", "jne", "loop",
]
labels = {} labels = {}
def parse_label(inst, args): def parse_label(inst, args):
k = v = None k = v = None
@ -174,12 +179,16 @@ def main(argv):
label = m.group(1).strip() label = m.group(1).strip()
inst = m.group(2).strip() inst = m.group(2).strip()
args = "" args = ""
if m.group(3): args = m.group(3).strip() if m.group(3):
args = m.group(3).strip()
if not inst_has_label(inst):
def hex2int(m): return str(int(m.group(0), 16))
args = re.sub(r"\b0x[0-9a-fA-F]+\b", hex2int, args)
# #
if 1 and inst in ["movl",] and re.search(r"\b[de]s\b", args): if 1 and inst in ["movl",] and re.search(r"\b[de]s\b", args):
# work around a bug in objdump 2.17 (fixed in binutils 2.18) # work around a bug in objdump 2.17 (fixed in binutils 2.18)
inst = "mov" inst = "mov"
m = re.search(r"^(.+?)\b0x0\s+(\w+):\s+(1|2|R_386_16|R_386_PC16)\s+(__\w+)$", args) m = re.search(r"^(.+?)\b0\s+(\w+):\s+(1|2|R_386_16|R_386_PC16)\s+(__\w+)$", args)
if m: if m:
# 1 or 2 byte reloc # 1 or 2 byte reloc
args = m.group(1) + m.group(4) args = m.group(1) + m.group(4)
@ -197,10 +206,10 @@ def main(argv):
if v[:2] == [1, 2]: # external 2-byte if v[:2] == [1, 2]: # external 2-byte
if k == "__aNahdiff": if k == "__aNahdiff":
s = [ s = [
["push", "word ptr [bp+(8|0x8)]"], ["push", "word ptr [bp+8]"],
["push", "word ptr [bp+(6|0x6)]"], ["push", "word ptr [bp+6]"],
["push", r"word ptr \[bp([+-](\d+|0x\w+))\]$"], ["push", r"word ptr \[bp([+-](\d+))\]$"],
["push", r"word ptr \[bp([+-](\d+|0x\w+))\]$"], ["push", r"word ptr \[bp([+-](\d+))\]$"],
] ]
dpos = omatch(i-1, -4, s) dpos = omatch(i-1, -4, s)
if dpos: if dpos:
@ -208,7 +217,7 @@ def main(argv):
continue continue
if k in ["__LMUL", "__U4M",]: if k in ["__LMUL", "__U4M",]:
s1 = [ s1 = [
["mov", "bx,0x300"], ["mov", "bx,768"], # 0x300
["xor", "cx,cx"], ["xor", "cx,cx"],
] ]
s2 = [ s2 = [
@ -234,7 +243,7 @@ def main(argv):
continue continue
if k == "__PIA": if k == "__PIA":
s = [ s = [
["mov", "bx,0x1"], ["mov", "bx,1"],
["xor", "cx,cx"], ["xor", "cx,cx"],
] ]
dpos = omatch(i-1, -2, s) dpos = omatch(i-1, -2, s)
@ -253,7 +262,7 @@ def main(argv):
continue continue
if opts.loop_rewrite and inst in ["loop"]: if opts.loop_rewrite and inst in ["loop"]:
s = [ s = [
["mov", r"^c[lx],0xb$"], ["mov", r"^c[lx],11$"],
["shr", "dx,1"], ["shr", "dx,1"],
["rcr", "ax,1"], ["rcr", "ax,1"],
] ]
@ -262,7 +271,7 @@ def main(argv):
orewrite_inst(i, "M_shrd_11", "", dpos) orewrite_inst(i, "M_shrd_11", "", dpos)
continue continue
s = [ s = [
["mov", r"^c[lx],0x8$"], ["mov", r"^c[lx],8$"],
["shl", "ax,1"], ["shl", "ax,1"],
["rcl", "dx,1"], ["rcl", "dx,1"],
] ]
@ -271,12 +280,12 @@ def main(argv):
orewrite_inst(i, "M_shld_8", "", dpos) orewrite_inst(i, "M_shld_8", "", dpos)
continue continue
s1 = [ s1 = [
["mov", r"^c[lx],0x8$"], ["mov", r"^c[lx],8$"],
["shl", "si,1"], ["shl", "si,1"],
["rcl", "di,1"], ["rcl", "di,1"],
] ]
s2 = [ s2 = [
["les", r"^bx,dword ptr \[bp([+-](\d+|0x\w+))\]$"], ["les", r"^bx,dword ptr \[bp([+-](\d+))\]$"],
] ]
dpos1 = omatch(i-1, -3, s1) dpos1 = omatch(i-1, -3, s1)
dpos2 = omatch(i+1, 1, s2) dpos2 = omatch(i+1, 1, s2)
@ -286,13 +295,13 @@ def main(argv):
continue continue
s1 = [ s1 = [
["mov", "ax,si"], ["mov", "ax,si"],
["mov", r"^c[lx],0x8$"], ["mov", r"^c[lx],8$"],
["shl", "ax,1"], ["shl", "ax,1"],
["rcl", "di,1"], ["rcl", "di,1"],
] ]
s2 = [ s2 = [
["mov", "si,ax"], ["mov", "si,ax"],
["les", r"^bx,dword ptr \[bp([+-](\d+|0x\w+))\]$"], ["les", r"^bx,dword ptr \[bp([+-](\d+))\]$"],
] ]
dpos1 = omatch(i-1, -4, s1) dpos1 = omatch(i-1, -4, s1)
dpos2 = omatch(i+1, 2, s2) dpos2 = omatch(i+1, 2, s2)
@ -301,9 +310,9 @@ def main(argv):
orewrite_inst(i, "M_shld_diax_8_bxcx", "", dpos1[-3:]) orewrite_inst(i, "M_shld_diax_8_bxcx", "", dpos1[-3:])
continue continue
s1 = [ s1 = [
["mov", r"^c[lx],0x8$"], ["mov", r"^c[lx],8$"],
["shl", r"^word ptr \[bp([+-](\d+|0x\w+))\],1$"], ["shl", r"^word ptr \[bp([+-](\d+))\],1$"],
["rcl", r"^word ptr \[bp([+-](\d+|0x\w+))\],1$"], ["rcl", r"^word ptr \[bp([+-](\d+))\],1$"],
] ]
s2 = [ s2 = [
["mov", r"^dx,word ptr"], ["mov", r"^dx,word ptr"],
@ -322,17 +331,17 @@ def main(argv):
orewrite_inst(i, m, "", dpos1) orewrite_inst(i, m, "", dpos1)
continue continue
s1 = [ s1 = [
["mov", r"^word ptr \[bp([+-](\d+|0x\w+))\],si$"], ["mov", r"^word ptr \[bp([+-](\d+))\],si$"],
["mov", r"^word ptr \[bp([+-](\d+|0x\w+))\],di$"], ["mov", r"^word ptr \[bp([+-](\d+))\],di$"],
["mov", r"^c[lx],0xb$"], ["mov", r"^c[lx],11$"],
["shr", r"^word ptr \[bp([+-](\d+|0x\w+))\],1$"], ["shr", r"^word ptr \[bp([+-](\d+))\],1$"],
["rcr", r"^word ptr \[bp([+-](\d+|0x\w+))\],1$"], ["rcr", r"^word ptr \[bp([+-](\d+))\],1$"],
] ]
s2 = [ s2 = [
["mov", r"^bx,word ptr"], ["mov", r"^bx,word ptr"],
["mov", r"^bx,word ptr"], ["mov", r"^bx,word ptr"],
["mov", r"^ax,word ptr \[bp([+-](\d+|0x\w+))\]$"], ["mov", r"^ax,word ptr \[bp([+-](\d+))\]$"],
["mov", r"^dx,word ptr \[bp([+-](\d+|0x\w+))\]$"], ["mov", r"^dx,word ptr \[bp([+-](\d+))\]$"],
] ]
dpos1 = omatch(i-1, -5, s1) dpos1 = omatch(i-1, -5, s1)
dpos2 = omatch(i+1, 4, s2) dpos2 = omatch(i+1, 4, s2)
@ -347,10 +356,7 @@ def main(argv):
orewrite_inst(i, m, "", dpos1 + dpos2[-2:]) orewrite_inst(i, m, "", dpos1 + dpos2[-2:])
continue continue
# #
if inst in [ if inst_has_label(inst):
"call", "ja", "jae", "jb", "jbe", "jcxz", "je",
"jg", "jge", "jl", "jle", "jmp", "jne", "loop",
]:
k, v = parse_label(inst, args) k, v = parse_label(inst, args)
olines[i][2] = None olines[i][2] = None
olines[i][3] = add_label(k, v) olines[i][3] = add_label(k, v)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff