python (python3) replaces python2

https://github.com/upx/upx/issues/868
Thanks to 'tansy' for the patches to *.py .

	modified:   .github/workflows/ci.yml
	modified:   src/stub/scripts/bin2h.py
	modified:   src/stub/scripts/brandelf.py
	modified:   src/stub/scripts/gpp_inc.py
	modified:   src/stub/scripts/xstrip.py
	modified:   src/stub/src/arch/i086/cleanasm.py
	modified:   src/stub/src/arch/i086/wdis2gas.py
This commit is contained in:
John Reiser 2025-10-08 08:32:24 -07:00
parent 3c3caaa567
commit 36271c3244
7 changed files with 28 additions and 26 deletions

View File

@ -41,12 +41,14 @@ jobs:
apt-get update && apt-get upgrade -y apt-get update && apt-get upgrade -y
# install system packages # install system packages
apt-get install -y --no-install-recommends bash ca-certificates curl git libmpc3 make perl-base tar time xz-utils libc6:i386 zlib1g:i386 apt-get install -y --no-install-recommends bash ca-certificates curl git libmpc3 make perl-base tar time xz-utils libc6:i386 zlib1g:i386
# install python2-minimal packages from Debian-11 #
mkdir ../deps; cd ../deps; mkdir packages ### install python2-minimal packages from Debian-11
curl -sS -L -O https://ftp.debian.org/debian/pool/main/p/python2.7/libpython2.7-minimal_2.7.18-8+deb11u1_amd64.deb ## mkdir ../deps; cd ../deps; mkdir packages
curl -sS -L -O https://ftp.debian.org/debian/pool/main/p/python2.7/python2.7-minimal_2.7.18-8+deb11u1_amd64.deb ## curl -sS -L -O https://ftp.debian.org/debian/pool/main/p/python2.7/libpython2.7-minimal_2.7.18-8+deb11u1_amd64.deb
dpkg -i ./*python2*.deb && rm ./*python2*.deb && ldconfig ## curl -sS -L -O https://ftp.debian.org/debian/pool/main/p/python2.7/python2.7-minimal_2.7.18-8+deb11u1_amd64.deb
ln -s -v python2.7 /usr/bin/python2 ## dpkg -i ./*python2*.deb && rm ./*python2*.deb && ldconfig
## ln -s -v python2.7 /usr/bin/python2
#
# manually unpack and install compat libs from Ubuntu-16.04 # manually unpack and install compat libs from Ubuntu-16.04
curl -sS -L -O https://archive.kernel.org/ubuntu-archive/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.6-1_amd64.deb curl -sS -L -O https://archive.kernel.org/ubuntu-archive/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.6-1_amd64.deb
for f in ./*.deb; do dpkg -x $f ./packages; done for f in ./*.deb; do dpkg -x $f ./packages; done

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python2 #! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*- ## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
# #
# bin2h.py -- # bin2h.py --
@ -133,7 +133,7 @@ class _DataWriter_gas_u32(DataWriter):
w(",") w(",")
v = struct.unpack(self.DECODE, data[i:i+4]) v = struct.unpack(self.DECODE, data[i:i+4])
assert len(v) == 1, v assert len(v) == 1, v
w("0x%08x" % (v[0] & 0xffffffffL)) w("0x%08x" % (v[0] & 0xffffffff))
self.w_eol() self.w_eol()
class DataWriter_gas_be32(_DataWriter_gas_u32): class DataWriter_gas_be32(_DataWriter_gas_u32):
@ -170,8 +170,8 @@ class DataWriter_nasm(DataWriter):
def w_checksum_c(w, s, data): def w_checksum_c(w, s, data):
w("#define %s_SIZE %d\n" % (s, len(data))) w("#define %s_SIZE %d\n" % (s, len(data)))
w("#define %s_ADLER32 0x%08x\n" % (s, 0xffffffffL & zlib.adler32(data))) w("#define %s_ADLER32 0x%08x\n" % (s, 0xffffffff & zlib.adler32(data)))
w("#define %s_CRC32 0x%08x\n" % (s, 0xffffffffL & zlib.crc32(data))) w("#define %s_CRC32 0x%08x\n" % (s, 0xffffffff & zlib.crc32(data)))
w("\n") w("\n")
@ -293,10 +293,10 @@ def main(argv):
# check file size # check file size
st = os.stat(ifile) st = os.stat(ifile)
if 1 and st.st_size <= 0: if 1 and st.st_size <= 0:
print >> sys.stderr, "%s: ERROR: empty file" % (ifile) sys.stderr.write("%s: ERROR: empty file\n" % (ifile))
sys.exit(1) sys.exit(1)
if 1 and st.st_size > 128*1024: if 1 and st.st_size > 128*1024:
print >> sys.stderr, "%s: ERROR: file is too big (%d bytes)" % (ifile, st.st_size) sys.stderr.write("%s: ERROR: file is too big (%d bytes)\n" % (ifile, st.st_size))
sys.exit(1) sys.exit(1)
# read ifile # read ifile
@ -333,7 +333,7 @@ def main(argv):
mdata.append(method) mdata.append(method)
assert len(mdata) >= 1 assert len(mdata) >= 1
mdata.reverse() mdata.reverse()
##print opts.methods, [(i, len(mdata_odata[i])) for i in mdata] ##print (opts.methods, [(i, len(mdata_odata[i])) for i in mdata])
# write ofile # write ofile
if opts.dry_run: if opts.dry_run:

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python2 #! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*- ## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
# #
# brandelf.py -- # brandelf.py --

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python2 #! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*- ## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
# #
# gpp_inc.py -- Generic PreProcessor: include # gpp_inc.py -- Generic PreProcessor: include

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python2 #! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*- ## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
# #
# xstrip.py -- truncate ELF objects created by multiarch-objcopy-2.17 # xstrip.py -- truncate ELF objects created by multiarch-objcopy-2.17
@ -54,9 +54,9 @@ def strip_with_dump(dump_fn, eh, idata):
sh_size = int("0x" + f[2], 16) sh_size = int("0x" + f[2], 16)
if sh_offset + sh_size > new_len: if sh_offset + sh_size > new_len:
new_len = sh_offset + sh_size new_len = sh_offset + sh_size
##print sh_offset, sh_size, f ##print (sh_offset, sh_size, f)
if new_len > len(eh): if new_len > len(eh):
##print dump_fn, new_len ##print (dump_fn, new_len)
return eh, idata[:new_len-len(eh)] return eh, idata[:new_len-len(eh)]
return eh, idata return eh, idata
@ -91,7 +91,7 @@ def check_dump(dump_fn):
assert not section_names.has_key(e[0]), e assert not section_names.has_key(e[0]), e
assert not e[0].endswith(":"), ("bad section name", e) assert not e[0].endswith(":"), ("bad section name", e)
section_names[e[0]] = e section_names[e[0]] = e
##print sections ##print (sections)
# preprocessSymbols # preprocessSymbols
symbols = [] symbols = []
section = None section = None

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python2 #! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*- ## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
# #
# cleanasm.py -- # cleanasm.py --
@ -135,7 +135,7 @@ def main(argv):
pos += sgn(mlen) pos += sgn(mlen)
if mlen < 0: if mlen < 0:
mpos.reverse() mpos.reverse()
if debug and 1: print mlen, m, [olines[x] for x in mpos] if debug and 1: print (mlen, m, [olines[x] for x in mpos])
dpos = [] dpos = []
i = -abs(mlen) i = -abs(mlen)
while i < 0: while i < 0:
@ -404,7 +404,7 @@ def main(argv):
assert len(r) == len(dpos) assert len(r) == len(dpos)
pos = pos0 pos = pos0
for inst, args in r: for inst, args in r:
##print pos-pos0, inst, args ##print (pos-pos0, inst, args)
olines[pos][1] = inst olines[pos][1] = inst
olines[pos][2] = args olines[pos][2] = args
pos += 1 pos += 1
@ -438,7 +438,7 @@ def main(argv):
if v[:2] == [1, 2]: # external 2-byte if v[:2] == [1, 2]: # external 2-byte
x = inline_map.get(v[2]) x = inline_map.get(v[2])
if x and v[3] <= x[1]: # max. number of calls if x and v[3] <= x[1]: # max. number of calls
##print "inline", v, x ##print ("inline", v, x)
if x: if x:
olines[i][1] = x[0] olines[i][1] = x[0]
olines[i][2] = "/* inlined */" olines[i][2] = "/* inlined */"
@ -478,7 +478,7 @@ def main(argv):
l = "%8s%-7s %s" % ("", inst, args) l = "%8s%-7s %s" % ("", inst, args)
ofp.write(l.rstrip() + "\n") ofp.write(l.rstrip() + "\n")
ofp.close() ofp.close()
##print olines ##print (olines)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python2 #! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*- ## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
# #
# wdis2gas.py -- # wdis2gas.py --
@ -138,7 +138,7 @@ def main(argv):
for l in olines: for l in olines:
ofp.write(l.rstrip() + "\n") ofp.write(l.rstrip() + "\n")
ofp.close() ofp.close()
##print olines ##print (olines)
if __name__ == "__main__": if __name__ == "__main__":