0

I am developing a paid application in Python. I do not want the users to see the source code or decompile it. How can I accomplish this task of hiding the source code from the user, but running the code perfectly with the same performance?

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Reverse engineering and disassembly are skills many people have. Plus there are tools to do this for them. If your product has enough value or is just interesting, someone will do this and publish their work. If your product value is only the source code, you are fighting a losing battle. Source code obfuscation just makes the task harder, but not by much. Back in the day, we would reverse engineer Windows, which is much harder than a Python program. Another tip, do not use any of the Python libraries, those are already open source and provide 90%+ of what someone needs to break your code. – John Hanley Dec 02 '22 at 01:19

3 Answers3

2

You may distribute the compiled .pyc files which is a byte code that the Python interpreter compiles your .py files to.

More info on this found here on stackoverflow. How to compile all your project files.

This will somewhat hide your actual code into bytecode, but it can be disassembled. To prevent from disassembling you need to use obfuscation. Pyarmor might be something you're looking for.

DiMithras
  • 605
  • 6
  • 14
1

The best way would be to turn your python code into an executable file.


When u take a look here, there is a nice Tutorial on how to do it:

  1. Install pyinstall via pip3 install pyinstaller
  2. Pack your excecutable with pyinstaller main.py

There is a lot of options to tweak the output of your application, the docs can be found under https://pyinstaller.org/en/stable/

noah
  • 312
  • 2
  • 13
  • If I remember it right, pyinstaller will zip python installation and the `.py` script into .exe, but the actual `.py` can be easily recovered. This is a solution to make your script portable and run on different machines that do not have python installed. It does not provide any code protection though. – DiMithras Dec 01 '22 at 10:36
  • @DiMithras that could be true, do you have any article on how to recover it? – noah Dec 01 '22 at 10:46
  • 1
    Not sure about the article. We once had a discussion at my workplace on how to protect Python scripts for Nuix, pyinstaller was one of the options. And if I remember it right, the resulting `.exe` could be opened with 7-zip. Let me try now. – DiMithras Dec 01 '22 at 10:50
  • well, probably I was using something different to pyinstaller, something like auto-py-to-exe, because I remember simply using 7-zip to extract the resulting file. Pyinstaller bundles everything in `.pyc` that makes it a bit more difficult but [doable](https://reverseengineering.stackexchange.com/questions/160/how-do-you-reverse-engineer-an-exe-compiled-with-pyinstaller) – DiMithras Dec 01 '22 at 11:02
0

You will definitely see the code if you're running it as a Python file. Maybe try using pyinstaller to make a executable binary for the respective Operating System that you're building for.