Obfuscating tool for Python3 code

筅森魡賤 提交于 2020-07-08 12:55:30

问题


Is there any existing python code obfuscating tool for Python3?

Please do not try to teach me that Python isn't the right choice if I want to hide/obfuscate my code. Or that correct licenses should protect the code instead of obfuscation...

Update: This question does not duplicate issue How do I protect Python code?: I simply ask if there is a tool to obfuscate Python. Nothing more and nothing less. (If there is none I wonder why I get so much feedback...)


回答1:


No matter what you do, at some point the Python interpreter is going to be reading in unobfuscated Python byte-code. From that it is dead easy to get back to your source code (minus comments and non-obvious layout). This is why everybody says it's pretty much impossible to obfuscate Python. The fact that it's pretty much impossible to obfuscate Python implies that there are no good tools for doing so. I'm afraid it's just wishful thinking to say "I know this can't be done very effectively, but are there any tools for doing it?"

Probably the best you can do will be to encrypt your code with standard encryption tools, and write a little wrapper program in some other language that just decrypts your Python and runs your program, then deletes the unencrypted code when it's done. If you want to put way too much effort in you could probably do something with the C API and embedding the Python interpreter in a C program to feed your unencrypted Python to the interpreter only in memory, rather than files on disk.

Note that these schemes will still be relatively easy to get around, and don't work at all if what you want is to provide importable Python modules (rather than whole programs). Which is why I wouldn't expect to find anyone's already written a tool for you to do it.




回答2:


I wouldn't go the obfuscating approach if I were you and rather investigate alternative ways to ship executable binary files instead of (byte)-code.

Tools that are known to me (there are probably a few others):

  • http://www.ohloh.net/p/py2c (converts Python into C code which you can then compile)
  • http://www.pyinstaller.org/
  • http://cx-freeze.sourceforge.net/
  • http://www.py2exe.org/ (Windows only)
  • http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html (Mac only)

I don't know how hack-proof any of those tools are, but I think it's worth taking a look.

Edit: Damnit, missed the Python 3 part. It's a little hard to help because you don't write anything about the product itself (OS, GUI, etc). If it can be also Python 2 code but you have written all your code in Python 3 already, I suggest 3to2.




回答3:


There is no way to obfuscate Python code in any useful manner, and no reason why you would want to. You seem to want to obfuscate the code to protect it. That is completely pointless, as you can instead ship only the .pyc files, meaning you don't ship the source code at all. Not that shipping only .pyc files will help you, as there are uncompilers for .pyc-files.

If your program is reasonably simple and well-coded, creating executables with cx-freeze, py2exe et al, means that the .pyc files end up inside the executable file, and hence are marginally harder to find, and it's also less obvious that you use Python, so that might be help. But more importantly, it might make installation simpler for your users. They like that.

If you really want to obfuscate your code in a useful way, convert all of it to use Cython, which will create C-files you can compile. This will also speed up the program. Cython is however not fully Python compatible, so you will probably have to make changes.

And I know you don't want to hear this, but I'll say it for the benefit of others:

All of this is of course stupid and misguided. Open source is good for you. Really. You shouldn't protect your code, you should get as many eyes and hands on it as possible.

Trust me on this: Your main worry should be about getting more users, not less pirates. And you get more users by making your software better, not worse. And open source will help in that.




回答4:


Pyminifier is a Python code minifier, obfuscator, and compressor.

This tool works on Python 3

Update: This project has been discontinued.




回答5:


The best way to hide your code is to not release it.

Advertise a service - you receive their data then return the processed data. Transmissions can be via the web, email, DHL, pigeon, telephone, graviton pulse, ...




回答6:


I'd recommend using pyarmor. It converts code to binary form. Only drawback would be, you need to obfuscate code for every OS separately.



来源:https://stackoverflow.com/questions/8076349/obfuscating-tool-for-python3-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!