forked from dashingsoft/pyarmor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotect_code2.pt
More file actions
47 lines (40 loc) · 1.56 KB
/
protect_code2.pt
File metadata and controls
47 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def protect_pytransform():
def assert_builtin(func):
type = ''.__class__.__class__
builtin_function = type(''.join)
if type(func) is not builtin_function:
raise RuntimeError('%s() is not a builtin' % func.__name__)
def check_obfuscated_script():
from sys import _getframe
CO_SIZES = 30, 39
CO_NAMES = set(['pytransform{suffix}', 'pyarmor',
'__name__', '__file__'])
co = _getframe(3).f_code
if not ((set(co.co_names) <= CO_NAMES)
and (len(co.co_code) in CO_SIZES)):
raise RuntimeError('unexpected obfuscated script')
def check_lib_pytransform():
from sys import platform
if platform == 'darwin':
return
{relative}import pytransform{suffix} as pytransform
filename = pytransform.__file__
with open(filename, 'rb') as f:
buf = bytearray(f.read())
value = sum(buf)
sys = __import__('sys')
if hasattr(sys, 'frozen') and sys.platform == 'darwin':
major, minor = sys.version_info[:2]
if '{suffix}':
value += 886 - sum(b'{suffix}') + (
1151 if major == 2 else (1161 + minor))
else:
value += 2069 if major == 2 else (2079 + minor)
if value not in {checklist}:
raise RuntimeError('unexpected %s' % filename)
assert_builtin(sum)
assert_builtin(open)
assert_builtin(len)
check_obfuscated_script()
check_lib_pytransform()
protect_pytransform()