- 🔭 A salted 🐟.... (
)
- 📫 Email: [email protected]
zhaoqi99 / pyencrypt-pye Goto Github PK
View Code? Open in Web Editor NEW加密Python代码&动态导入(encrypt Python source code and import dynamically).
License: GNU General Public License v3.0
加密Python代码&动态导入(encrypt Python source code and import dynamically).
License: GNU General Public License v3.0
显示当前机器的硬件信息,例如硬盘序列号,网卡Mac地址等。
用于使用指定AES密钥在不同Python版本环境下生成loader.so文件
需要把加密、解密函数封装到Class里,防止dir(loader)
时看到函数名
~$ pyencrypt license -k xxx
Traceback (most recent call last):
File "/Users/zhaoqi219/.pyenv/versions/3.10.2/bin/pyencrypt", line 8, in <module>
sys.exit(cli())
File "/Users/zhaoqi219/.pyenv/versions/3.10.2/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/Users/zhaoqi219/.pyenv/versions/3.10.2/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/Users/zhaoqi219/.pyenv/versions/3.10.2/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/zhaoqi219/.pyenv/versions/3.10.2/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/zhaoqi219/.pyenv/versions/3.10.2/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/Users/zhaoqi219/.pyenv/versions/3.10.2/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
TypeError: generate_license() got an unexpected keyword argument 'bind_mac'
pyencrypt-pye/pyencrypt/loader.py
Line 16 in b6c7d18
依据cpython/Lib/importlib/_bootstrap_external.py ,生成.pyc
文件的行为是Python原生的loader控制的...
所以使用自定义的loader时本身不会生成.pyc
文件
decrypt
时需要校验dont_write_bytecode
的值似乎有一个新库 https://pypi.org/project/pyminifier3/, 不确定能否解决问题
Related to #18
报错如下
Traceback (most recent call last):
File "a.py", line 3, in <module>
from test.test2.abc import *
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 894, in _find_spec
File "/Users/zhaoqi219/Code/python_encrypt/encrypted/loader.py", line 411, in find_spec
file_path = Path(path[0]) / f'{fullname.rsplit(".",1)[-1]}.pye'
TypeError: '_NamespacePath' object does not support indexing
目录结构是
test
├── __init__.py
└── test2
└── abc.py
代码是
import loader
from test.test2.abc import *
inspired by #5
可以再自定义一个Finder
,走一遍EncryptFileFinder
类find_spec
函数中获取file_path
的逻辑
class KeyParamType(ParamType):
name = '🔑'
def convert(self, value, param, ctx):
if not _check_key(value):
self.fail(INVALID_KEY_MSG, param, ctx)
return value
Close #1
setup(
ext_modules=cythonize([file_name], quiet=True, language_level=3),
script_args=["build_ext", "-t", td, "--inplace"],
)
今天看到的一段代码...
似乎可以不使用subprocss
pyencrypt-pye/pyencrypt/loader.py
Lines 32 to 37 in 96f7d5e
如题, intensio_obfuscator对混淆类名的支持更好一点
File "main.pye", line 2, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 894, in _find_spec
File "encrypted/loader.py", line 280, in loader.QospGExaJCABDzhRFNSt.find_spec
File "<frozen importlib._bootstrap>", line 441, in spec_from_loader
File "<frozen importlib._bootstrap_external>", line 574, in spec_from_file_location
File "<frozen importlib._bootstrap_external>", line 664, in is_package
File "<frozen importlib._bootstrap_external>", line 66, in _path_split
AttributeError: 'PosixPath' object has no attribute 'rpartition'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/tokenize.py", line 390, in find_cookie
line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xad in position 1: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.6/multiprocessing/spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "/usr/local/lib/python3.6/multiprocessing/spawn.py", line 118, in _main
return self._bootstrap()
File "/usr/local/lib/python3.6/multiprocessing/process.py", line 274, in _bootstrap
traceback.print_exc()
File "/usr/local/lib/python3.6/traceback.py", line 163, in print_exc
print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
File "/usr/local/lib/python3.6/traceback.py", line 104, in print_exception
type(value), value, tb, limit=limit).format(chain=chain):
File "/usr/local/lib/python3.6/traceback.py", line 509, in __init__
capture_locals=capture_locals)
File "/usr/local/lib/python3.6/traceback.py", line 364, in extract
f.line
File "/usr/local/lib/python3.6/traceback.py", line 286, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "/usr/local/lib/python3.6/linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "/usr/local/lib/python3.6/linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "/usr/local/lib/python3.6/linecache.py", line 136, in updatecache
with tokenize.open(fullname) as fp:
File "/usr/local/lib/python3.6/tokenize.py", line 454, in open
encoding, lines = detect_encoding(buffer.readline)
File "/usr/local/lib/python3.6/tokenize.py", line 431, in detect_encoding
encoding = find_cookie(first)
File "/usr/local/lib/python3.6/tokenize.py", line 395, in find_cookie
raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for 'main.pye'
Encryption completed successfully.
Please copy encrypted/loader.cpython-39m-darwin.so into your encrypted directory.
And then remove `encrypted` directory.
Finally, add `import loader` at the top of your entry file.
加密后提示生成的loader文件在encrypted/loader.cpython-39m-darwin.so
但是实际上loader
文件的路径是encrypted/loader.cpython-39-darwin.so
,没有m了
Python版本
~ $ python -V
Python 3.9.6
看起来 with-license 参数没有传递到 generate_so_file ,导致:--width-license 失效。
我简单添加了一下,
encrypt_command::generate_so_file(..., license=with_license)
简单从测试了一下,通过
rt
涉及:
大佬,写了一个多进程py代码,加密后执行一直停留在Process ForkPoolWorker这里,后面的代码都不继续执行了。
有没有解决的办法呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.