python代码小型化器、混淆器和压缩器

pyminifier的Python项目详细描述


pyminifier是一个python代码迷你器、混淆器和压缩器。

概述

安装pyminifier时,它应该自动添加一个“pyminifier” 可执行到您的$PATH。这个可执行文件有许多命令行 参数:

$ pyminifier --help
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.
--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.
--gzip                gzip-compress the result into a self-executing python
                        script.  Only works on stand-alone scripts without
                        implicit imports.
--lzma                lzma-compress the result into a self-executing python
                        script.  Only works on stand-alone scripts without
                        implicit imports.
--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.

对于下面的示例,我们将缩小、模糊和压缩 下面是完全虚构的python脚本(保存到/tmp/tumult.py):

#!/usr/bin/env python
"""
tumult.py - Because everyone needs a little chaos every now and again.
"""

try:
    import demiurgic
except ImportError:
    print("Warning: You're not demiurgic. Actually, I think that's normal.")
try:
    import mystificate
except ImportError:
    print("Warning: Dark voodoo may be unreliable.")

# Globals
ATLAS = False # Nothing holds up the world by default

class Foo(object):
    """
    The Foo class is an abstract flabbergaster that when instantiated
    represents a discrete dextrogyratory inversion of a cattywompus
    octothorp.
    """
    def __init__(self, *args, **kwargs):
        """
        The initialization vector whereby the ineffably obstreperous
        becomes paramount.
        """
        # TODO.  BTW: What happens if we remove that docstring? :)

    def demiurgic_mystificator(self, dactyl):
        """
        A vainglorious implementation of bedizenment.
        """
        inception = demiurgic.palpitation(dactyl) # Note the imported call
        demarcation = mystificate.dark_voodoo(inception)
        return demarcation

    def test(self, whatever):
        """
        This test method tests the test by testing your patience.
        """
        print(whatever)

if __name__ == "__main__":
    print("Forming...")
    f = Foo("epicaricacy", "perseverate")
    f.test("Codswallop")

默认情况下,pyminifier将执行基本的缩小并打印结果 标准输出代码:

注意

py脚本是1358字节。记住这一点。

#!/usr/bin/env python
=ImportError
=print
=False
=object
try:
 import demiurgic
except ﵛ:
ࡅ("Warning: You're not demiurgic. Actually, I think that's normal.")
try:
 import mystificate
except ﵛ:
ࡅ("Warning: Dark voodoo may be unreliable.")=㮀
class רּ():
 def __init__(self,*args,**kwargs):
  pass
 def ?(self,dactyl):
  =demiurgic.palpitation(dactyl)=mystificate.dark_voodoo()return ꁁ
 def ?(self,whatever):
  ࡅ(whatever)if__name__=="__main__":
 ࡅ("Forming...")=("epicaricacy","perseverate")
 녂.?("Codswallop")# Created by pyminifier.py (https://github.com/liftoff/pyminifier)

这将tumult.py的大小从1358字节减少到640字节。不错!

缩小本身可以大大减少代码大小,但pyminifier可以 更进一步的是混淆代码。这意味着它将取代 尽可能小的变量和函数的名称。

要查看pyminifier的更多实际示例(例如压缩特性),请参见 full documentation

特制酱汁

所以让我们暂时假装你的意图并不纯粹;你 完全想和那些看你的代码的人打交道。你所做的 需要python 3和--nonlatin选项…

#!/usr/bin/env python3
ܗ=ImportError
ܡ=print
ܪ=False
ٽ=object
try:
 import demiurgic
except ܗ:
ܡ("Warning: You're not demiurgic. Actually, I think that's normal.")
try:
 import mystificate
except ܗ:
ܡ("Warning: Dark voodoo may be unreliable.")ܬ=ܪ
class ظ(ٽ):
 def __init__(self,*args,**kwargs):
  pass
 def ط(self,dactyl):
ټ=demiurgic.palpitation(dactyl)=mystificate.dark_voodoo(ټ)return ⶹ
 def ܘ(self,whatever):
ܡ(whatever)if__name__=="__main__":
ܡ("Forming...")f=ظ("epicaricacy","perseverate")
 f.test("Codswallop")# Created by pyminifier.py (https://github.com/liftoff/pyminifier)

是的,该代码实际上可以工作,但仅使用python 3。这是因为Python 3支持使用非拉丁字符集的语言进行编码。

注意

大多数文本编辑器/IDE在使用 --nonlatin选项,因为它将是从左到右的随机混合 以及从右到左的字符。通常结果是一些代码出现在 屏幕的左边和一些代码出现在右边。就这样 really很难找出缩进级别之类的东西!

有更多的方法可以和 full documentation

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Android深度链接的java模式匹配   jstl在JSP中添加外部资源(CSS/JavaScript/images等)   Java开关环路中断故障   java Appengine通道API开发服务器vs生产   java断言等于Junit中的两个列表   java用“真实数据”建立测试系统   Java中使用番石榴BiMap的词典   java试图在圆周上绘制位图,在实现中找到一些偏移   json Java curl响应   java使用hibernate或JPA获取过程输出的列名   java从Android移动应用程序获取电话号码   java访问嵌套的JsonNode元素,并用逗号分隔   未使用注释的java未经检查或不安全操作   控制台中的java输出为空   java使用Android应用程序的自定义适配器将项目动态添加到列表视图   java如何解决对接口中静态方法的需求?   尝试从其他活动调用数组字符串时发生java错误   仅设备上的java Android NDK致命信号11(SIGSEGV)