Skip to content

Commit 9d6a0eb

Browse files
committed
Fix protection code bugs
1 parent 2d17d62 commit 9d6a0eb

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/protect_code.pt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ def protect_pytransform():
3636
if getattr(pytransform.sys, 'frozen', False):
3737
filename = pytransform.os.path.join(pytransform.sys._MEIPASS, libname)
3838
else:
39-
filename = pytransform.os.path.join({rpath}, libname)
40-
size = {size}
39+
filename = pytransform.os.path.join({rpath}, {spath}, libname)
40+
41+
size = pytransform.os.path.getsize(filename) & 0xFFFFFFF0
4142
n = size >> 2
4243
with open(filename, 'rb') as f:
4344
buf = f.read(size)

src/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@ def _make_protect_pytransform(template, filenames=None, rpath=None):
547547
keylist = _build_pytransform_keylist(pytransform, code, closure)
548548
rpath = 'pytransform.os.path.dirname(pytransform.__file__)' \
549549
if rpath is None else repr(rpath)
550-
return buf.format(code=code, closure=closure, size=size, rpath=rpath,
550+
spath = 'pytransform.os.path.join(pytransform.plat_path, ' \
551+
'pytransform.format_platform())' if len(filenames) > 1 else repr('')
552+
return buf.format(code=code, closure=closure, rpath=rpath, spath=spath,
551553
checksum=str(checksums), keylist=keylist)
552554

553555

@@ -620,6 +622,7 @@ def _build_platforms(platforms):
620622
# plat, mach, x = p.split('.')
621623
results.append(_get_platform_library(p))
622624
logging.info('Target dynamic library: %s', results)
625+
return results
623626

624627

625628
def encrypt_script(pubkey, filename, destname, wrap_mode=1, obf_code=1,
@@ -674,7 +677,9 @@ def encrypt_script(pubkey, filename, destname, wrap_mode=1, obf_code=1,
674677
n += 1
675678

676679
if sys.flags.debug and (protection or plugins):
677-
with open(filename + '.pyarmor-patched', 'w') as f:
680+
patched_script = filename + '.pyarmor-patched'
681+
logging.info('Write patched script for debugging: %s', patched_script)
682+
with open(patched_script, 'w') as f:
678683
f.write(''.join(lines))
679684

680685
modname = _frozen_modname(filename, destname)

0 commit comments

Comments
 (0)