1.安装uncompyle库

  1. python -m pip install uncompyle

image.png

2.还原.pyc文件

  1. uncompyle6 0001_initial.cpython-37.pyc

image.png

pyc文件头

以Python2为例子:

  1. 03 F3 0D 0A DA 2A BA 59 63 00 00 00 00 00 00 00
  2. 00 05 00 00 00 40 00 00 00 73 3D 07 00 00 64 00
  3. 00 5A 00 00 64 01 00 64 02 00 6C 01 00 6D 02 00
  4. 5A 02 00 01 65 02 00 64 35 00 6B 05 00 72 3A 00

image.png
03 F3 0D 0A 为python文件头【前4个字节】 ,表示python版本
image.png
DA 2A BA 59 后面5-8个字节,表示pyc文件修改的时间

以Python3为例子:

  1. 42 0D 0D 0A 00 00 00 00 B6 9B 32 5B 07 25 00 00
  2. E3 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00
  3. 00 40 00 00 00 73 B8 00 00 00 64 00 64 01 6C 00
  4. 5A 00 64 00 64 01 6C 01 5A 01 64 00 64 01 6C 02

42 0D 0D 0A 为python3文件头【前4字节】,表示python版本
00 00 00 00 后面5-8个字节,表示pyc文件修改的时间