1

I have decompiled a pyinstaller exe and then decompiled the .pyc source inside it. only problem is the source is this

import secretmodule
secretmodule.main()

Annoying, I know. i found secretmodule but it is a .pyd and the decompiler I use only decompiles pyo or pyc. I searched how to decompile a pyd but it said it was almost impossible and I assumed pyinstaller makes pyd's differently so I continued.

How do I decompile a pyd file made specifically by pyinstaller

1 Answer 1

2

This could prove to be much harder than converting pyc to equivalent python code

According to python docs

Yes, .pyd files are dll’s, but there are a few differences. If you have a DLL named foo.pyd, then it must have a function PyInit_foo(). You can then write Python “import foo”, and Python will search for foo.pyd (as well as foo.py, foo.pyc) and if it finds it, will attempt to call PyInit_foo() to initialize it. You do not link your .exe with foo.lib, as that would cause Windows to require the DLL to be present.

Note that the search path for foo.pyd is PYTHONPATH, not the same as the path that Windows uses to search for foo.dll. Also, foo.pyd need not be present to run your program, whereas if you linked your program with a dll, the dll is required. Of course, foo.pyd is required if you want to say import foo. In a DLL, linkage is declared in the source code with __declspec(dllexport). In a .pyd, linkage is defined in a list of available functions.

So you now have to reverse the native code in the pyd file assuming its a DLL and start from the exports.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.