I recently tried to understand how sockets module works in python, I opened the source code and by tracing socket class I found out it uses something like _socket.socket
. When i scroll up and find import _socket
i traced it down and found out that the module is located in another folder named DLLs(i have no idea how but i do know that you can import files from python install location no matter where your file is located, but how?cool if you could answer this doubt too)so opening the file with notepad(it had no default extension association)tells me that it has an awkward encoding. Here's the first few lines in _socket.pyd
:
MZ ÿÿ ¸ @ º ´ Í!¸LÍ!This program cannot be run in DOS mode.
$ jâò.ƒã¡.ƒã¡.ƒã¡'ûp¡(ƒã¡B÷â ,ƒã¡B÷æ "ƒã¡B÷ç &ƒã¡B÷à -ƒã¡÷÷â ,ƒã¡uëâ )ƒã¡.ƒâ¡”ƒã¡÷÷î /ƒã¡÷÷ã /ƒã¡÷÷¡/ƒã¡÷÷á /ƒã¡Rich.ƒã¡ PE d† ;3` ð " z ¤ ¨( € ` ð= ` põ P Àõ ´ @ 0 €
° P ¸ ô¡ T P¢ 8 .text ny z `.rdata ¬y z ~ @ @.data ( ø @ À.pdata €
0 @ @.rsrc @
@ @.reloc ¸ P @ B H‰\$H‰t$UWATAVAWH¬$ÿÿÿHìð H‹àÿ H3ÄH‰…è ¹ HT$ ÿf …À…>, H
ÿ9„ 3ÿƒ=è ÿDg…„ 3ÒÇD$ A¸ H‰|$,HL$4è5( 3Àf‰}6A°‰E8W3Éÿ0€ A°A‹ÔH‹Èÿ!€ A°W H‹Èÿ€ W#ÇD$$ L‹ÀD‰d$(HL$ fD‰e4ÿß ‹Ï…À•Á‰
Z H‹£ƒ H
anyone have any idea how do i decode this to simple python code(i only know that .pyd
files are DLL files but in python format)? I also found out from hours of googling that DLL and EXE files have same encoding, so it would be cool if anyone could give me the link for a decoding tool or at least give me a table of this encoding's characters so i can decode it on my own.
Python itself is a program, and it runs on your computer. Python code is read and interpreted, and ultimately executed by executing code in your computer's native instruction set. Well, Python is set up so that it can import and run code that is already in the form of "native" instructions (in this case, written in C and compiled to machine code).
To get a feel for how this works, take a look at the official python.org documentation: Extending Python with C or C++. Enjoy!