栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

简单的Django项目代码混淆

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

简单的Django项目代码混淆

编写脚本

生成 pyc_create.py 文件

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("tpython compile_pyc.py clean PATHtt#To clean all pyc files")
    print("tpython compile_pyc.py compile PATHtt#To generate pyc files")

以此执行脚本命令 注!!!备份代码

C:Users周天震PycharmProjectsConfuse 为我的项目目录。

1、生成pyc文件
python pyc_create.py compile C:Users周天震PycharmProjectsConfuse
2、移动pyc文件
python pyc_create.py copy C:Users周天震PycharmProjectsConfuse
3、删除py文件
python pyc_create.py remove C:Users周天震PycharmProjectsConfuse
4、修改文件名称

生成的pyc文件样式为:manage.cpython-38.pyc 需要手动修改为 manage.pyc

python pyc_create.py cpython C:Users周天震PycharmProjectsConfuse
检查项目

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/928547.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号