gpt4 book ai didi

python - 编译后的独立 Cython 可执行文件是否仍包含所有原始源代码?

转载 作者:太空宇宙 更新时间:2023-11-04 00:08:11 24 4
gpt4 key购买 nike

<分区>

我正在试验 Cython 和代码混淆的可能性 (article)。在那篇文章中特别指出:

When the compilation is done there’s no way to reverse compiled libraries back to readable Python source code!

我用这个question信息以在独立可执行文件中编译我的代码。据我了解,如文章 1 中所述, Cython 将 Python 代码翻译成 C 代码,并相应调用 Python 库(这是正确的吗?)。在其他地方,我们只有 C 文件作为输出,它不能像 .pyc 文件一样反编译回来。

我的测试代码很简单:

def my_crashing_function():
x = "1"
y = 2
test = x + y # we will crash here

if __name__ == "__main__":
my_crashing_function()

但是当我运行这个可执行文件时(在 cython --embed -o test.c main.pygcc -Os -I/usr/include/python3.5m -o test 之后test.c -lpython3.5m -lpthread -lm -lutil -ldl -s)我收到这样的错误:

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

如您所见,我们有所有方法名称、正确的变量名称和行的回溯,甚至还有原始源代码注释。如果我们重命名变量或更改注释 - 它也会在回溯中更改。我不明白回溯如何显示所有这些信息。只有当完整的源代码也存储在可执行文件中时,它才能那样工作。请解释一下,我哪里错了?

更新。在我的情况下,回溯是从原始 .py 文件生成的。该文件与已编译的可执行文件位于同一文件夹中,因此我在回溯中获得了所有源代码和注释。删除原始.py文件后的回溯将只包含异常类型和行号,没有其他信息。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com