Skip to content

Commit f57b801

Browse files
committed
Refine cross protection code
1 parent aacfa7f commit f57b801

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/protect_code.pt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ def protect_pytransform():
55
except ImportError:
66
from . import pytransform
77

8+
def assert_builtin(func):
9+
type = ''.__class__.__class__
10+
builtin_function = type(''.join)
11+
if type(func) is not builtin_function:
12+
raise RuntimeError('%s() is not a builtin' % func.__name__)
13+
814
def check_obfuscated_script():
915
CO_SIZES = 49, 46, 38, 36
1016
CO_NAMES = set(['pytransform', 'pyarmor_runtime', '__pyarmor__',
@@ -34,7 +40,8 @@ def protect_pytransform():
3440
'_pytransform.dll' if platname.startswith('win') else \
3541
'_pytransform.so'
3642
if getattr(pytransform.sys, 'frozen', False):
37-
filename = pytransform.os.path.join(pytransform.sys._MEIPASS, libname)
43+
filename = pytransform.os.path.join(
44+
pytransform.sys._MEIPASS, libname)
3845
else:
3946
filename = pytransform.os.path.join({rpath}, {spath}, libname)
4047

@@ -46,12 +53,17 @@ def protect_pytransform():
4653
checksum = sum(pytransform.struct.unpack(fmt, buf)) & 0xFFFFFFFF
4754
if checksum not in {checksum}:
4855
raise RuntimeError('unexpected %s' % filename)
56+
4957
try:
58+
assert_builtin(sum)
59+
assert_builtin(open)
60+
assert_builtin(len)
61+
5062
check_obfuscated_script()
5163
check_mod_pytransform()
5264
check_lib_pytransform()
5365
except Exception as e:
54-
print('Protection Fault: %s' % e)
55-
pytransform.sys.exit(1)
66+
raise RuntimeError("Protection Fault: %s" % e)
67+
5668

5769
protect_pytransform()

0 commit comments

Comments
 (0)