python 的逆向工程
什么是pyc文件
pyc是一种二进制文件,是由py文件经过编译后,生成的文件,是一种byte code,py文件变成pyc文件后,加载的速度有所提高,而且pyc是一种跨平台的字节码,是由python的虚拟机来执行的,这个是类似于JAVA或者.NET的虚拟机的概念。pyc的内容,是跟python的版本相关的,不同版本编译后的pyc文件是不同的,2.5编译的pyc文件,2.4版本的 python是无法执行的。
什么是pyo文件
pyo是优化编译后的程序 python -O 源文件即可将源程序编译为pyo文件
什么是pyd文件
pyd是python的动态链接库。
这里的pyo 优化后的字节码?这种优化怎么理解,还有就是pyd 这个编译的动态链接库如何理解?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1. 关于
pyo
优化:参考链接
-O
flag, optimized code is generated and stored in.pyo
files. The optimizer currently doesn't help much; it only removes assert statements. When-O
is used, all bytecode is optimized;.pyc
files are ignored and.py
files are compiled to optimized bytecode.-O
flags to the Python interpreter (-OO
) will cause the bytecode compiler to perform optimizations that could in some rare cases result in malfunctioning programs. Currently only__doc__
strings are removed from the bytecode, resulting in more compact.pyo
files. Since some programs may rely on having these available, you should only use this option if you know what you're doing..pyc
or.pyo
file than when it is read from a.py
file; the only thing that's faster about.pyc
or.pyo
files is the speed with which they are loaded..pyc
or.pyo
file. Thus, the startup time of a script may be reduced by moving most of its code to a module and having a small bootstrap script that imports that module. It is also possible to name a.pyc
or.pyo
file directly on the command line.2. 关于
pyd
:pyd
可以理解为Windows DLL
文件。参考链接
.pyd
files are dll’s, but there are a few differences. If you have aDLL
namedfoo.pyd
, then it must have a functionPyInit_foo()
. You can then write Python"import foo"
, and Python will search forfoo.pyd
(as well asfoo.py
,foo.pyc
) and if it finds it, will attempt to callPyInit_foo()
to initialize it. You do not link your.exe
withfoo.lib
, as that would cause Windows to require theDLL
to be present.foo.pyd
isPYTHONPATH
, not the same as the path that Windows uses to search forfoo.dll
. Also,foo.pyd
need not be present to run your program, whereas if you linked your program with adll
, thedll
is required. Of course,foo.pyd
is required if you want to sayimport foo
. In aDLL
, linkage is declared in the source code with__declspec(dllexport)
. In a.pyd
, linkage is defined in a list of available functions.