I'm experimenting with Cython and possibilities of code obfuscation (article). In that article especially noted:
When the compilation is done there’s no way to reverse compiled libraries back to readable Python source code!
I use this question info to compile my code in standalone executable. In my understanding and as mentioned in article 1, Cython translates Python code into C code, with correspond calls of Python library (is this correct?). In other wolds, we have only C file as output, and it can't be de-compiled back like .pyc files.
My test code is very simple:
def my_crashing_function():
x = "1"
y = 2
test = x + y # we will crash here
if __name__ == "__main__":
my_crashing_function()
But when I run this executable (after cython --embed -o test.c main.py
and gcc -Os -I /usr/include/python3.5m -o test test.c -lpython3.5m -lpthread -lm -lutil -ldl -s
)
I get error like this:
user@debian:~# ./hello
Traceback (most recent call last):
File "main.py", line 7, in init main
my_crashing_function()
File "main.py", line 4, in main.my_crashing_function
test = x + y # we will crash here
TypeError: Can't convert 'int' object to str implicitly
As you see, we have traceback with all method names, correct variable names and lines, even with original source code comments. If we rename variable or change comment - it will be also changed in traceback. I don't understand how traceback can display all this info. It can work that way only if the full source code is also stored in the executable file. Please explain me, where I'm wrong?
Update. Traceback in my situation was generated from original .py file. This file was in the same folder as compiled executable, and only because of this I got all source code and comments in traceback. After deletion of original .py file traceback will contain only exception type and line numbers, without other info.