mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
sfx: py3.12 support
This commit is contained in:
parent
8709d4dba0
commit
bba4b1c663
|
@ -15,9 +15,10 @@ there's zero binaries! just plaintext python scripts all the way down
|
||||||
so you can easily unpack the archive and inspect it for shady stuff
|
so you can easily unpack the archive and inspect it for shady stuff
|
||||||
|
|
||||||
the archive data is attached after the b"\n# eof\n" archive marker,
|
the archive data is attached after the b"\n# eof\n" archive marker,
|
||||||
b"\n#n" decodes to b"\n"
|
b"?0" decodes to b"\x00"
|
||||||
b"\n#r" decodes to b"\r"
|
b"?n" decodes to b"\n"
|
||||||
b"\n# " decodes to b""
|
b"?r" decodes to b"\r"
|
||||||
|
b"??" decodes to b"?"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,12 +188,28 @@ def encode(data, size, cksum, ver, ts):
|
||||||
unpk = unpk.replace("\t ", "\t\t")
|
unpk = unpk.replace("\t ", "\t\t")
|
||||||
|
|
||||||
with open("sfx.out", "wb") as f:
|
with open("sfx.out", "wb") as f:
|
||||||
f.write(unpk.encode("utf-8").rstrip(b"\n") + b"\n\n\n# eof\n# ")
|
f.write(unpk.encode("utf-8").rstrip(b"\n") + b"\n\n\n# eof")
|
||||||
for buf in data:
|
for buf in data:
|
||||||
ebuf = buf.replace(b"\n", b"\n#n").replace(b"\r", b"\n#r")
|
ebuf = (
|
||||||
f.write(ebuf)
|
buf.replace(b"?", b"??")
|
||||||
|
.replace(b"\x00", b"?0")
|
||||||
|
.replace(b"\r", b"?r")
|
||||||
|
.replace(b"\n", b"?n")
|
||||||
|
)
|
||||||
nin += len(buf)
|
nin += len(buf)
|
||||||
nout += len(ebuf)
|
nout += len(ebuf)
|
||||||
|
while ebuf:
|
||||||
|
ep = 4090
|
||||||
|
while True:
|
||||||
|
a = ebuf.rfind(b"?", 0, ep)
|
||||||
|
if a < 0 or ep - a > 2:
|
||||||
|
break
|
||||||
|
ep = a
|
||||||
|
buf = ebuf[:ep]
|
||||||
|
ebuf = ebuf[ep:]
|
||||||
|
f.write(b"\n#" + buf)
|
||||||
|
|
||||||
|
f.write(b"\n\n")
|
||||||
|
|
||||||
msg("wrote {:x}H bytes ({:x}H after encode)".format(nin, nout))
|
msg("wrote {:x}H bytes ({:x}H after encode)".format(nin, nout))
|
||||||
|
|
||||||
|
@ -324,48 +341,27 @@ def unpack():
|
||||||
def get_payload():
|
def get_payload():
|
||||||
"""yields the binary data attached to script"""
|
"""yields the binary data attached to script"""
|
||||||
with open(me, "rb") as f:
|
with open(me, "rb") as f:
|
||||||
ptn = b"\n# eof\n# "
|
buf = f.read().rstrip(b"\r\n")
|
||||||
buf = b""
|
|
||||||
for n in range(64):
|
|
||||||
buf += f.read(4096)
|
|
||||||
ofs = buf.find(ptn)
|
|
||||||
if ofs >= 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
if ofs < 0:
|
ptn = b"\n# eof\n#"
|
||||||
raise Exception("could not find archive marker")
|
a = buf.find(ptn)
|
||||||
|
if a < 0:
|
||||||
|
raise Exception("could not find archive marker")
|
||||||
|
|
||||||
# start at final b"\n"
|
esc = {b"??": b"?", b"?r": b"\r", b"?n": b"\n", b"?0": b"\x00"}
|
||||||
fpos = ofs + len(ptn) - 3
|
buf = buf[a + len(ptn) :].replace(b"\n#", b"")
|
||||||
f.seek(fpos)
|
p = 0
|
||||||
dpos = 0
|
while buf:
|
||||||
rem = b""
|
a = buf.find(b"?", p)
|
||||||
while True:
|
if a < 0:
|
||||||
rbuf = f.read(1024 * 32)
|
yield buf[p:]
|
||||||
if rbuf:
|
break
|
||||||
buf = rem + rbuf
|
elif a == p:
|
||||||
ofs = buf.rfind(b"\n")
|
yield esc[buf[p : p + 2]]
|
||||||
if len(buf) <= 4:
|
p += 2
|
||||||
rem = buf
|
else:
|
||||||
continue
|
yield buf[p:a]
|
||||||
|
p = a
|
||||||
if ofs >= len(buf) - 4:
|
|
||||||
rem = buf[ofs:]
|
|
||||||
buf = buf[:ofs]
|
|
||||||
else:
|
|
||||||
rem = b"\n# "
|
|
||||||
else:
|
|
||||||
buf = rem
|
|
||||||
|
|
||||||
fpos += len(buf) + 1
|
|
||||||
for a, b in [[b"\n# ", b""], [b"\n#r", b"\r"], [b"\n#n", b"\n"]]:
|
|
||||||
buf = buf.replace(a, b)
|
|
||||||
|
|
||||||
dpos += len(buf) - 1
|
|
||||||
yield buf
|
|
||||||
|
|
||||||
if not rbuf:
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def utime(top):
|
def utime(top):
|
||||||
|
|
Loading…
Reference in a new issue