Is it possible to decompile a .dll/.pyd file to extract Python Source Code?

Youssef Imam picture Youssef Imam · Feb 24, 2016 · Viewed 32k times · Source

Are there any ways to decompile a dll and/or a .pyd file in order to extract source code written in Python?

Thanks in advance

Answer

Lav picture Lav · Feb 25, 2016

I assume the .pyd/.dll files were created in Cython, not Python?

Anyway, generally it's not possible, unless there's a decompiler designed specifically for the language the file was originally compiled from. And while I know about C, C++, Delphi, .NET and some other decompilers, I've yet to hear about Cython decompiler.

Of course, what Cython does is convert your Python[esque] code into C code first, which means you might have more luck finding a C decompiler and then divining the original Python code based on the decompiled C code. At the very least, this way you'll be dealing with translation from one (relatively) high-level language to another.

Worst-case scenario, you'll have to use a disassembler. However, recreating Python code from disassembler's output isn't going to be easy (pretty similar to divining the biological functions of a brain from chemical formulas of proteins that make up it's cells).

You might look at this question on ideas and suggestions regarding various decompilers and disassemblers, and proceed your investigation from there.