Dropbox 如何在 Windows 和 OS X 上使用 Python?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2678180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does Dropbox use Python on Windows and OS X?
提问by robotshapes
In Windows the Dropbox client uses python25.dll and the MS C runtime libraries (msvcp71.dll, etc). On OS X the Python code is compiled bytecode (pyc).
在 Windows 中,Dropbox 客户端使用 python25.dll 和 MS C 运行时库(msvcp71.dll 等)。在 OS X 上,Python 代码被编译为字节码 (pyc)。
My guess is they are using a common library they have written then just have to use different hooks for the different platforms.
我的猜测是他们正在使用他们编写的公共库,然后只需要为不同的平台使用不同的钩子。
What method of development is this? It clearly isn't IronPython or PyObjC. This paradigm is so appealing to me, but my CS foo and Google foo are failing me.
这是什么开发方式?它显然不是 IronPython 或 PyObjC。这种范式对我很有吸引力,但我的 CS foo 和 Google foo 令我失望。
采纳答案by Nicholas Riley
Dropbox uses a combination of wxPython and PyObjC on the Mac (less wxPython in the 0.8 series). It looks like they've built a bit of a UI abstraction layer but nothing overwhelming—i.e., they're doing their cross-platform app the right way.
Dropbox 在 Mac 上使用 wxPython 和 PyObjC 的组合(在 0.8 系列中较少使用 wxPython)。看起来他们已经构建了一些 UI 抽象层,但没有什么压倒性的——也就是说,他们正在以正确的方式开发他们的跨平台应用程序。
They include their own Python mainly because the versions of Python included on the Mac vary by OS version (and Dropbox supports back to 10.4 IIRC); also, they've customized the Python interpreter a bit to improve threading and I/O behavior.
它们包含自己的 Python,主要是因为 Mac 上包含的 Python 版本因操作系统版本而异(Dropbox 支持回 10.4 IIRC);此外,他们还对 Python 解释器进行了一些自定义,以改进线程和 I/O 行为。
(I do not work for Dropbox or have any inside knowledge; all I did was read their forums and examine the filenames in site-packages.zip
in the Dropbox app bundle.)
(我不为 Dropbox 工作,也没有任何内部知识;我所做的只是阅读他们的论坛并检查site-packages.zip
Dropbox 应用程序包中的文件名。)
回答by Philar
For WINDOWS, Dropbox have employed a module similar to py2exeto package all their .py scripts, required libraries, resources etc into the distribution that you have mentioned above (.exe
, library.zip
, MS C runtime library
and python25.dll
) so that they can be run without requiring Python installation. Here's a sample code of how you can achieve this with py2exe.
对于WINDOWS,Dropbox的都采用了模块类似py2exe打包他们的所有的.py脚本,需要的库,资源等成你所提到的分布(.exe
,library.zip
,MS C runtime library
和python25.dll
),以便它们可以运行,而不需要Python安装。这是一个示例代码,说明如何使用 py2exe 实现此目的。
from distutils.core import setup
import py2exe
options = {'py2exe': {
'compressed':1,
'bundle_files': 2,
'dll_excludes': ['w9xpopen.exe']
}}
setup(console=['myapp.py'],options=options)
Please see the tutorial herefor more explanation.
请参阅此处的教程以获取更多说明。
PS: the number of files in the distribution can be controlled using the options parameter as shown in the above example.
PS:分发中的文件数量可以使用选项参数来控制,如上例所示。
回答by DevC
These guys reverse engineered Dropbox client code
这些家伙逆向了 Dropbox 客户端代码
http://www.openwall.com/presentations/WOOT13-Security-Analysis-of-Dropbox/https://github.com/kholia/dedrop
http://www.openwall.com/presentations/WOOT13-Security-Analysis-of-Dropbox/ https://github.com/kholia/dedrop
回答by jathanism
Indeed they do bundle their own Python 2.5.4 interpreter found at /Applications/Dropbox.app/Contents/MacOS/python
. Poking around in /Applications/Dropbox.app/Contents/Resources/lib/python2.5/lib-dynload
it looks to be bundled by PyObjC.
事实上,他们确实捆绑了自己的 Python 2.5.4 解释器,可以在/Applications/Dropbox.app/Contents/MacOS/python
. 在/Applications/Dropbox.app/Contents/Resources/lib/python2.5/lib-dynload
里面闲逛看起来是由 PyObjC 捆绑的。
I'm no authority on this, but it seems it is exactly as you suggest in the OP:
我对此没有权威,但似乎正如您在 OP 中所建议的那样:
My guess is they are using a common library they have written then just have to use different hooks for the different platforms
我的猜测是他们正在使用他们编写的公共库然后只需要为不同的平台使用不同的钩子
回答by mikerobi
Python25.dll is probably not their application code, it is a dll containing a copy of the python interpreter which can be called from within a windows application. Those pyc files are probably there in some form on windows, but they might be in an archive or obfuscated.
Python25.dll 可能不是他们的应用程序代码,它是一个包含 python 解释器副本的 dll,可以从 Windows 应用程序中调用它。这些 pyc 文件可能以某种形式存在于 Windows 中,但它们可能位于存档中或被混淆。
Python is included in OS/X, so it would be possible for them to execute those pyc file without shipping a python, but would not be surprised if they have there own python version lurking in the app bundle.
Python 包含在 OS/X 中,因此他们可以在不传送 Python 的情况下执行这些 pyc 文件,但如果他们有自己的 Python 版本潜伏在应用程序包中,也不会感到惊讶。
I don't know how dropbox builds there distributions, but there are several tools to bundle python apps into executable packages. Take a look at py2exe, py2app, and or cx_freeze.
我不知道 dropbox 是如何构建发行版的,但是有几种工具可以将 python 应用程序捆绑到可执行包中。看看 py2exe、py2app 或 cx_freeze。
回答by Extreme Coders
Recently I published an article on reversing the dropbox client on windows. It is available on slideshare.
最近我发表了一篇关于在 Windows 上反转 Dropbox 客户端的文章。它在幻灯片共享上可用。
In short,
On Windows dropbox uses py2exe. py2exe embeds the python dll as a resourcewithin the executable. The compiled python source files aka pyc files are stored as a zip archive appended to the end of the executable (which is called an overlay).
简而言之,
在 Windows dropbox 上使用py2exe。py2exe 将 python dll 作为资源嵌入到可执行文件中。编译后的 python 源文件,也就是 pyc 文件存储为一个 zip 存档,附加到可执行文件的末尾(称为覆盖)。
Extracting the zip archive will give you the pyc files, but that is not the end of the story. The pyc files are encrypted and not decompilable. They are decrypted only when they are loaded by the embedded python interpreter.
解压缩 zip 存档将为您提供 pyc 文件,但这并不是故事的结尾。pyc 文件已加密且不可反编译。只有当它们被嵌入式 python 解释器加载时才会被解密。
However there is a way to not bother too much about the encryption algorithm used. We can directly grab decrypted code objects from memory letting dropbox do the decryption for us.
但是,有一种方法可以避免过多关注所使用的加密算法。我们可以直接从内存中获取解密的代码对象,让 dropbox 为我们进行解密。