开发者

How does Dropbox use Python on Windows and OS X?

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).

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.


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.

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.

(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.)


For WINDOWS, Dropbox have employed a module similar to py2exe to 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.

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 here for more explanation.

PS: the number of files in the distribution can be controlled using the options parameter as shown in the above example.


These guys reverse engineered Dropbox client code

http://www.openwall.com/presentations/WOOT13-Security-Analysis-of-Dropbox/ https://github.com/kholia/dedrop


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.

I'm no authority on this, but it seems it is exactly as you suggest in the OP:

My guess is they are using a common library they have written then just have to use different hooks for the different platforms


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.

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.

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.


Recently I published an article on reversing the dropbox client on windows. It is available on slideshare.

In short,
On Windows dropbox uses py2exe. py2exe embeds the python dll as a resource within 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).

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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜