关于Python代码混淆和加密技术
import os
import sys
import shutil
from py_compile import compile
# print "argvs:",sys.argv
if len(sys.argv) == 3:
comd = sys.argv[1] # 输入的命令
path = sys.argv[2] # 文件的地址
if os.path.exists(path) and os.path.isdir(path):
for parent, dirname, filename in os.walk(path):
for cfile in filename:
fullname = os.path.join(parent, cfile)
if comd == 'clean' and cfile[-4:] == '.pyc':
try:
os.remove(fullname)
print("Success remove file:%s" % fullname)
except:
print("Can't remove file:%s" % fullname)
if comd == 'compile' and cfile[-3:] == '.py': # 在这里将找到的py文件进行编译成pyc,但是会指定到一个叫做__pycache__的文件夹中
try:
compile(fullname)
print("Success compile file:%s" % fullname)
except:
print("Can't compile file:%s" % fullname)
if comd == 'remove' and cfile[-3:] == '.py' and cfile != 'settings.py' and cfile != 'wsgi.py':
try:
os.remove(fullname)
print("Success remove file:%s" % fullname)
except:
print("Can't remove file:%s" % fullname)
if comd == 'copy' and cfile[-4:] == '.pyc':
parent_list = parent.split("\")[:-1]
parent_up_path = ''
for i in range(len(parent_list)):
parent_up_path += parent_list[i] + '\'
shutil.copy(fullname, parent_up_path)
print('update the dir of file successfully')
if comd == 'cpython' and cfile[-4:] == '.pyc':
cfile_name = ''
cfile_list = cfile.split('.')
for i in range(len(cfile_list)):
if cfile_list[i] == 'cpython-38':
continue
cfile_name += cfile_list[i]
if i == len(cfile_list) - 1:
continue
cfile_name += '.'
shutil.move(fullname, os.path.join(parent, cfile_name))
print('update the name of the file successfully')
else:
print("Not an directory or Direcotry doesn't exist!")
else:
print("Usage:")
print(" python compile_pyc.py clean PATH #To clean all pyc files")
print(" python compile_pyc.py compile PATH #To generate pyc files")
- .NET Core系列之MemoryCache 初识
- 007手机一键Root(安机网一键Root) v3.0 官方最新版 一键ROOT您的Android手机
- 12306密码被盗了怎么办?12306密码外泄解决方法
- 12个字的qq网名
- 150M迷你型无线路由器怎么设置?
- 192.168.1.1打不开怎么办?路由器192.168.1.1打不开的原因以及解决办法
- 2011年电子报合订本 电子报 编辑部 中文 PDF版 [84M]
- 2015年1月15日小米新旗舰发布会现场图文直播
- 2016.3.1vivo Xplay5新品发布会现场视频直播 优酷直播
- 2016华为P9发布会视频直播地址 4月15日华为P9国行发布会直播