Python 技术篇 - 通过pyminifier库实现源码压缩、混淆、加密保护实例演示,pyminifier的使用方法

简介: Python 技术篇 - 通过pyminifier库实现源码压缩、混淆、加密保护实例演示,pyminifier的使用方法

   

源代码如下:

image.png

参数 -O :混淆所有函数/方法名、变量和类。默认是不要混淆。

我这里使用参数 -O 进行源码混淆。

image.png

如果运行时报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 54: illegal multibyte sequence

可以查看解决方法:

Python 技术篇 - 修改 pyminifier 库源码解决编码不一致导致的报错问题

转换后生成新文件,minified 文件夹里也是转化后的内容,这个是默认生成的,通过参数 -d 可以进行指定。

image.png

可以看到方法和变量名都被改了,而且注释也被默认去掉了,这样就一定程度上提高了我们源代码的安全性。

当然默认会被编码为 gbk ,如需调整可以自行转化一下文件编码。

image.png

pyminifier 详细命令方法如下:

pyminifier -h
Usage: pyminifier [options] "<input file>"
Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -o <file path>, --outfile=<file path>
                        Save output to the given file.
  -d <file path>, --destdir=<file path>
                        Save output to the given directory. This option is
                        required when handling multiple files. Defaults to
                        './minified' and will be created if not present.
                        将输出保存到给定的目录。当处理多个文件时,此选项是必需的。默认为'./minified',如果不存在,将被创建。
  --nominify            Don't bother minifying (only used with --pyz).
  --use-tabs            Use tabs for indentation instead of spaces.
              使用制表符代替空格来缩进。
  --bzip2               bzip2-compress the result into a self-executing python
                        script.  Only works on stand-alone scripts without
                        implicit imports.
                        以bzip2方式压缩将结果到一个自动执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。
  --gzip                gzip-compress the result into a self-executing python
                        script.  Only works on stand-alone scripts without
                        implicit imports.
                        以gzip方式压缩结果到一个自执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。
  --lzma                lzma-compress the result into a self-executing python
                        script.  Only works on stand-alone scripts without
                        implicit imports.
            以lzma方式压缩将结果到一个自动执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。
  --pyz=<name of archive>.pyz
                        zip-compress the result into a self-executing python
                        script. This will create a new file that includes any
                        necessary implicit (local to the script) modules.
                        Will include/process all files given as arguments to
                        pyminifier.py on the command line.
  -O, --obfuscate       Obfuscate all function/method names, variables, and
                        classes.  Default is to NOT obfuscate.
  --obfuscate-classes   Obfuscate class names.
  --obfuscate-functions
                        Obfuscate function and method names.
  --obfuscate-variables
                        Obfuscate variable names.
  --obfuscate-import-methods
                        Obfuscate globally-imported mouled methods (e.g.
                        'Ag=re.compile').
  --obfuscate-builtins  Obfuscate built-ins (i.e. True, False, object,
                        Exception, etc).
  --replacement-length=1
                        The length of the random names that will be used when
                        obfuscating identifiers.
  --nonlatin            Use non-latin (unicode) characters in obfuscation
                        (Python 3 only).  WARNING: This results in some
                        SERIOUSLY hard-to-read code.
  --prepend=<file path>
                        Prepend the text in this file to the top of our
                        output.  e.g. A copyright notice.

喜欢的点个赞❤吧!

           

目录
相关文章
|
7月前
|
监控 数据可视化 数据挖掘
Python Rich库使用指南:打造更美观的命令行应用
Rich库是Python的终端美化利器,支持彩色文本、智能表格、动态进度条和语法高亮,大幅提升命令行应用的可视化效果与用户体验。
668 0
|
6月前
|
数据可视化 关系型数据库 MySQL
【可视化大屏】全流程讲解用python的pyecharts库实现拖拽可视化大屏的背后原理,简单粗暴!
本文详解基于Python的电影TOP250数据可视化大屏开发全流程,涵盖爬虫、数据存储、分析及可视化。使用requests+BeautifulSoup爬取数据,pandas存入MySQL,pyecharts实现柱状图、饼图、词云图、散点图等多种图表,并通过Page组件拖拽布局组合成大屏,支持多种主题切换,附完整源码与视频讲解。
633 4
【可视化大屏】全流程讲解用python的pyecharts库实现拖拽可视化大屏的背后原理,简单粗暴!
|
6月前
|
传感器 运维 前端开发
Python离群值检测实战:使用distfit库实现基于分布拟合的异常检测
本文解析异常(anomaly)与新颖性(novelty)检测的本质差异,结合distfit库演示基于概率密度拟合的单变量无监督异常检测方法,涵盖全局、上下文与集体离群值识别,助力构建高可解释性模型。
514 10
Python离群值检测实战:使用distfit库实现基于分布拟合的异常检测
|
Web App开发 数据安全/隐私保护 Python
|
Python
技术| Python的从零开始系列连载(三十一)
大家好,上次我们实验了爬取了糗事百科的段子,那么这次我们来尝试一下爬取百度贴吧的帖子。与上一篇不同的是,这次我们需要用到文件的相关操作。
1546 0
|
Web App开发 JSON 大数据
技术 | Python从零开始系列连载(二十八)
之前我水平有限,对于淘宝评论这种动态网页,由于数据在网页源码中是找不到的,所以无法抓取数据,只能使用selenium模仿人操控浏览器来抓数据, 优点是可见容易且不宜被淘宝公司封锁;缺点是速度太慢。 经过今天一天的钻研,终于学会分析数据包,而且淘宝评论的数据包都是以json格式传输的。
1985 0

推荐镜像

更多
下一篇
开通oss服务