1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Python 技术篇 - 通过pyminifier库实现源码压缩 混淆 加密保护实例演示 pyminifier的使用方法

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

时间:2020-10-23 02:24:18

相关推荐

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

源代码如下:

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

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

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

可以查看解决方法:

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

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

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

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

pyminifier详细命令方法如下:

pyminifier -hUsage: 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 isrequired 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.使用制表符代替空格来缩进。--bzip2bzip2-compress the result into a self-executing pythonscript. Only works on stand-alone scripts withoutimplicit imports.以bzip2方式压缩将结果到一个自动执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。--gzipgzip-compress the result into a self-executing pythonscript. Only works on stand-alone scripts withoutimplicit imports.以gzip方式压缩结果到一个自执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。--lzmalzma-compress the result into a self-executing pythonscript. Only works on stand-alone scripts withoutimplicit imports.以lzma方式压缩将结果到一个自动执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。--pyz=<name of archive>.pyzzip-compress the result into a self-executing pythonscript. This will create a new file that includes anynecessary implicit (local to the script) modules.Will include/process all files given as arguments topyminifier.py on the command line.-O, --obfuscate Obfuscate all function/method names, variables, andclasses. Default is to NOT obfuscate.--obfuscate-classes Obfuscate class names.--obfuscate-functionsObfuscate function and method names.--obfuscate-variablesObfuscate variable names.--obfuscate-import-methodsObfuscate globally-imported mouled methods (e.g.'Ag=pile').--obfuscate-builtins Obfuscate built-ins (i.e. True, False, object,Exception, etc).--replacement-length=1The length of the random names that will be used whenobfuscating identifiers.--nonlatin Use non-latin (unicode) characters in obfuscation(Python 3 only). WARNING: This results in someSERIOUSLY hard-to-read code.--prepend=<file path>Prepend the text in this file to the top of ouroutput. e.g. A copyright notice.

喜欢的点个赞❤吧!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。