Is it easy to fully decompile python compiled(*.pyc) files?
Asked Answered
C

4

7

I wanted to know that how much easy is to decompile python byte code. I have made an application in python whose source I want to be secure. I am using py2exe which basically relies on python compiled files.

Does that secure the code?

Coss answered 12/8, 2010 at 2:20 Comment(2)
possible duplicate of How do I protect python code?Bookcase
Ah... After 3 years, I realize how absurd code protection is. In fact, among the widespread languages like C/C++ no other language exist which cant be decompiled.Coss
M
8

Depends on your definition of "fully" (in "fully decompile")...;-). You won't easily get back the original Python source -- but getting the bytecode is easy, and standard library module dis exists exactly to make bytecode easily readable (though it's still bytecode, not full Python source code;-).

Mirepoix answered 12/8, 2010 at 2:29 Comment(3)
Well there are C++ decompilers too but they are just useless. They dont get the original source code but just some assembly level instructions. SO by full decompiable i mean which actually generate the actual source code.Coss
You won't get the "actual source code". Comments will be gone. But variable names, method names, constants, strings, and all the logic that you apply to them, will be readable by someone interested enough.Inordinate
@Shubham, yep, @Ned is right: Python bytecode is much closer to Python source, than assembly language is to the C++ source it was made from. Any Python expert worth his or her salt will be able to reconstruct the source's logic precisely from the bytecode, and without taking forever about it either (not that doing it from assembly code is that much harder -- look how long it takes for every new silly "copy protection" scheme for a game to be disassembled, understood and broken...;-).Mirepoix
I
6

Compiling .pyc does not secure the code. They are easily read. See How do I protect Python code?

Inordinate answered 12/8, 2010 at 2:23 Comment(0)
A
1

If you search online you can find decompilers for Python bytecode: there's a free version for downloading but which only handles bytecode up to Python 2.3, and an online service which will decompile up to version 2.6.

There don't appear to be any decompilers yet for more recent versions of Python bytecode, but that's almost certainly just because nobody has felt the need to write one rather than any fundamental difficulty with the bytecode itself.

Some people have tried to protect Python bytecode by modifying the interpreter: there's no particular reason why you can't compile your own interpreter with the different values used for the bytecode: that will prevent simple examination of the code with import dis, but won't stand up long to any determined attack and it all costs money that code be better put into improving the program itself.

In short, if you want to protect your program then use the law to do it: use an appropriate software license and prosecute those who ignore it. Code is expensive to write, but the end result is rarely the valuable part of a software package: data is much more valuable.

Amphoteric answered 12/8, 2010 at 8:14 Comment(0)
B
0

Now we can say: VERY EASY decompile, and NOT secure.

For I have use uncompyle6 to decompile my (latest 3.8.0) Python code:

uncompyle6 utils.cpython-38.pyc > utils.py

and decompile effect is NEARLY PERFECT.

  • origin python vs decompiled python:

    • pyc uncompile utils

      • -> ALMOST same py code except no comments

Not forget, other can use unpy2exe to

Extract .pyc files from executables created with py2exe

so your method not secure.

Boaten answered 6/1, 2020 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.