当前位置: 首页 > news >正文

销售网站平台搭建易语言做网站

销售网站平台搭建,易语言做网站,软文广告有哪些,泉州网站设计制作文章目录代码混淆打包exe编译为字节码源码加密项目发布部署时,为防止python源码泄漏,可以通过几种方式进行处理代码混淆 修改函数、变量名 打包exe 通过pyinstaller 将项目打包为exe可执行程序,不过容易被反编译。 编译为字节码 py_comp…

文章目录

  • 代码混淆
  • 打包exe
  • 编译为字节码
  • 源码加密

项目发布部署时,为防止python源码泄漏,可以通过几种方式进行处理

代码混淆

修改函数、变量名

打包exe

通过pyinstaller 将项目打包为exe可执行程序,不过容易被反编译。

编译为字节码

py_compile
compileall
模块
容易被反编译

源码加密

  1. pyarmor 加密
    官网
    官方文档
  • 源码加密
  • 设置程序的许可方式,如设置使用期限、绑定环境设备(磁盘、mac/ip、网卡)等;

安装

pip install pyarmor

加密单个py文件

# 终端命令
# 加密一个文件
pyarmor obfuscate index.py  

加密后的文件:
dist / index.py 加密文件,内部的函数、类等仍可以像python源码一样导入,前提是要记得里面都有哪些类。
dist / pytransform包 后续需要放入python搜索路径或者能被搜索找到
 
加密整个项目的py文件
在这里插入图片描述

# 递归地加密,项目中的每个包都会进行加密
pyarmor obfuscate --recursive index.py 

加密结果:
在这里插入图片描述
加密后的py文件能像正常源码一样使用,前提是pytransform包可以被搜索到。
试用版加密整个项目时,有最大字节限制(32768)!!

 
生成许可文件,并使用:

# 生成许可, 放入licenses目录
pyarmor licenses --expired "2025-01-01" --bind-disk "100304xxxx" --bind-mac "70:f1:a1:23:f0:94" --bind-ipv4 "200.10.139.23"# 使用许可 加密
pyarmor obfuscate --with-license licenses/regcode-01/license.lic index.py

在这里插入图片描述

 
默认安装的pyarmor是试用版,有些限制,如单次加密最多32768字节。
购买地址
 
 
2. Nuitka 将python转为C,再编译为二进制文件(操作系统的动态链接库),反编译难度大
linux- .so
win- dll/pyd
方法实现:
在这里插入图片描述

在这里插入图片描述
jmpy3 库
在这里插入图片描述

参考

# -*- coding: utf-8 -*-
"""
@summary: 加密python代码为pyd/so
"""
import os
import re
import shutil
import tempfile
from distutils.command.build_py import build_py
from distutils.core import setup
from typing import Union, Listfrom Cython.Build import cythonizefrom jmpy.log import loggerdef get_package_dir(*args, **kwargs):return ""# 重写get_package_dir, 否者生成的so文件路径有问题
build_py.get_package_dir = get_package_dirclass TemporaryDirectory(object):def __enter__(self):self.name = tempfile.mkdtemp()return self.namedef __exit__(self, exc_type, exc_value, traceback):shutil.rmtree(self.name)def search(content, regexs):if isinstance(regexs, str):return re.search(regexs, content)for regex in regexs:if re.search(regex, content):return Truedef walk_file(file_path):if os.path.isdir(file_path):for current_path, sub_folders, files_name in os.walk(file_path):for file in files_name:file_path = os.path.join(current_path, file)yield file_pathelse:yield file_pathdef copy_files(src_path, dst_path):if os.path.isdir(src_path):if os.path.exists(dst_path):shutil.rmtree(dst_path)def callable(src, names: list):if search(src, dst_path):return namesreturn ["dist", ".git", "venv", ".idea", "__pycache__"]shutil.copytree(src_path, dst_path, ignore=callable)else:if not os.path.exists(dst_path):os.makedirs(dst_path)shutil.copyfile(src_path, os.path.join(dst_path, os.path.basename(src_path)))def get_py_files(files, ignore_files: Union[List, str, None] = None):"""@summary:---------@param files: 文件列表#param ignore_files: 忽略的文件,支持正则---------@result:"""for file in files:if file.endswith(".py"):if ignore_files and search(file, regexs=ignore_files):  # 该文件是忽略的文件passelse:yield filedef filter_cannot_encrypted_py(files, except_main_file):"""过滤掉不能加密的文件,如 log.py __main__.py 以及包含 if __name__ == "__main__": 的文件Args:files:Returns:"""_files = []for file in files:if search(file, regexs="__.*?.py"):continueif except_main_file:with open(file, "r", encoding="utf-8") as f:content = f.read()if search(content, regexs="__main__"):continue_files.append(file)return _filesdef encrypt_py(py_files: list):encrypted_py = []with TemporaryDirectory() as td:total_count = len(py_files)for i, py_file in enumerate(py_files):try:dir_name = os.path.dirname(py_file)file_name = os.path.basename(py_file)os.chdir(dir_name)logger.debug("正在加密 {}/{},  {}".format(i + 1, total_count, file_name))setup(ext_modules=cythonize([file_name], quiet=True, language_level=3),script_args=["build_ext", "-t", td, "--inplace"],)encrypted_py.append(py_file)logger.debug("加密成功 {}".format(file_name))except Exception as e:logger.exception("加密失败 {} , error {}".format(py_file, e))temp_c = py_file.replace(".py", ".c")if os.path.exists(temp_c):os.remove(temp_c)return encrypted_pydef delete_files(files_path):"""@summary: 删除文件---------@param files_path: 文件路径 py 及 c 文件---------@result:"""try:# 删除python文件及c文件for file in files_path:os.remove(file)  # py文件os.remove(file.replace(".py", ".c"))  # c文件except Exception as e:passdef rename_excrypted_file(output_file_path):files = walk_file(output_file_path)for file in files:if file.endswith(".pyd") or file.endswith(".so"):new_filename = re.sub("(.*)\..*\.(.*)", r"\1.\2", file)os.rename(file, new_filename)def start_encrypt(input_file_path,output_file_path: str = None,ignore_files: Union[List, str, None] = None,except_main_file: int = 1,
):assert input_file_path, "input_file_path cannot be null"assert (input_file_path != output_file_path), "output_file_path must be diffent with input_file_path"if output_file_path and os.path.isfile(output_file_path):raise ValueError("output_file_path need a dir path")input_file_path = os.path.abspath(input_file_path)if not output_file_path:  # 无输出路径if os.path.isdir(input_file_path):  # 如果输入路径是文件夹 则输出路径为input_file_path/dist/project_nameoutput_file_path = os.path.join(input_file_path, "dist", os.path.basename(input_file_path))else:output_file_path = os.path.join(os.path.dirname(input_file_path), "dist")else:output_file_path = os.path.abspath(output_file_path)# 拷贝原文件到目标文件copy_files(input_file_path, output_file_path)files = walk_file(output_file_path)py_files = get_py_files(files, ignore_files)# 过滤掉不需要加密的文件need_encrypted_py = filter_cannot_encrypted_py(py_files, except_main_file)encrypted_py = encrypt_py(need_encrypted_py)delete_files(encrypted_py)rename_excrypted_file(output_file_path)logger.debug("加密完成 total_count={}, success_count={}, 生成到 {}".format(len(need_encrypted_py), len(encrypted_py), output_file_path))
http://www.yayakq.cn/news/906345/

相关文章:

  • vip域名做网站好不好桂林北站图片
  • 嘉兴中小企业网站建设网站主机域名
  • 厦门高端网站建设公wordpress 导入失败
  • 做网站底部不显示中文怎么回事网站二次开发是什么
  • 合肥网站建设新手企业网站建设经济效益分析
  • 佛山网站建设格式有哪些iis7.0配置网站
  • 网站建设需求信息做个医院网站多少钱
  • 宁波网站建设招聘网wordpress添加addthis
  • 做直播导航网站好景德镇市建设局网站
  • pycharm 做网站哪个好什么网站的页面做的比较好看
  • 有关网站建设的外文参考文献广告设计与制作专业属于什么大类
  • 长春站建筑深圳做网站案例
  • 网站前台后台网站建设课程设计
  • 西安优惠电商平台网站成都建站优化
  • 网页设计与网站建设试卷sem跟seo的区别
  • 做网站推广有哪些公司建设部网站危房鉴定标准规定
  • 免费做网站公司哪家好公司团建拓展训练
  • 企业网站建设完整教程韩国flash网站
  • wordpress建站 评测wordpress固定链接打不开
  • 网站本科广东深圳市宝安区
  • 自己本地可以做网站服务器吗文学投稿网站平台建设
  • 外贸推广网站佛山外贸网站建设方案
  • 一 建设网站前的市场分析网页设计实训心得体会300字
  • 学做美食饮品网站搜索网页
  • 高新区网站开发海曙网站制作
  • 嘉兴 网站 制作学生网站建设首页
  • 网站开发的主题wordpress报名表单
  • 石家庄外贸做网站凡科快图登录入口
  • 好的销售网站邯郸ui设计师招聘
  • 网站建设维护报价中国网站有哪些公司